Skip to content

Commit

Permalink
Merge pull request #2 from verixx/rewrite
Browse files Browse the repository at this point in the history
update
  • Loading branch information
EliteDaMyth1337 authored Nov 16, 2017
2 parents 6e9a606 + 7484753 commit a295011
Show file tree
Hide file tree
Showing 13 changed files with 560 additions and 80 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ __pycache__/
*.py[cod]
*$py.class
*.DS_Store
*.json
cogs/testsplit.py
data/community_cogs.txt
data/community_cogs.txt
44 changes: 26 additions & 18 deletions cogs/community/clashroyale.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
'''
MIT License
Copyright (c) 2017 Grok
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -34,42 +30,54 @@ class ClashRoyale:

def __init__(self, bot):
self.bot = bot
with open('data/config.json') as f:
config = json.load(f)
if 'CR_TAG' not in config:
tag = None
with open('data/options.json') as f:
options = json.load(f)
if 'CR_TAG' not in options:
self.tag = None
else:
tag = config['CR_TAG']
self.tag = os.environ.get('CR_TAG') or tag
self.tag = options['CR_TAG']
self.client = crasync.Client()


@commands.command()
async def profile(self, ctx, tag=None):
'''Fetch a Clash Royale Profile!'''
em = discord.Embed(title="Profile")
em.color = await ctx.get_dominant_color(ctx.author.avatar_url)
if tag == None:
if tag is None and self.tag is None:
em.description = "Please add `CR_TAG` to your options. Do `{p}options edit cr_tag <tag>`"
return await ctx.send(embed=em)
elif self.tag is not None:
tag = self.tag
if tag == None:
em.description = "Please add `CR_TAG` to your config."
return await ctx.send(embed=em)

tag = tag.strip('#').replace('O', '0')
try:
profile = await self.client.get_profile(tag)
except:
em.description = "Either API is down or that's an invalid tag."
return await ctx.send(embed=em)

em.title = profile.name
em.set_thumbnail(url=profile.arena.image_url)
em.description = f"#{tag}"
em.url = f"http://cr-api.com/profile/{tag}"
em.add_field(name='Current Trophies', value=profile.current_trophies)
em.add_field(name='Highest Trophies', value=profile.highest_trophies)
em.add_field(name='Legend Trophies', value=f'{profile.legend_trophies}')
em.add_field(name='Level', value=profile.level)
em.add_field(name='Experience', value=f"{profile.experience[0]}/{profile.experience[1]}")
em.add_field(name='Wins/Losses/Draws', value=f'{profile.wins}/{profile.losses}/{profile.draws}')
em.add_field(name='Global Rank', value=f'{profile.global_rank}')
em.add_field(name='Clan Info', value=f'{profile.clan_name}\n#{profile.clan_tag}\n{profile.clan_role}')
em.add_field(name='Win Streak', value=f'{profile.win_streak}')
em.set_footer(text="Powered By cr-api.com", icon_url="http://cr-api.com/static/img/branding/cr-api-logo.png")

try:
em.set_author(name="Profile", icon_url=profile.clan_badge_url)
except:
em.set_author(name='Profile')

await ctx.send(embed=em)


def setup(bot):
bot.add_cog(ClashRoyale(bot))
bot.add_cog(ClashRoyale(bot))
147 changes: 147 additions & 0 deletions cogs/community/nsfw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
"""
MIT License
Copyright (c) 2017 Grok's naughty dev XAOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import discord
from discord.ext import commands
import bs4 as bs
import urllib.request
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import json
import io
import safygiphy
from ext import embed2box

class Nsfw:
""" Nsfw commands """
def __init__(self, bot):
self.bot = bot

async def __local_check(self, ctx):
if not ctx.channel.is_nsfw():
return False
git = self.bot.get_cog('Git')
if not await git.starred('verixx/selfbot.py'):
return False
return True

@commands.group(invoke_without_command=True)
async def nsfw(self, ctx):
""" Get random lewds from the web """
pass

@nsfw.command()
async def xbooru(self, ctx):
""" Random image from Xbooru """
try:
try:
await ctx.message.delete()
except discord.Forbidden:
pass
await ctx.channel.trigger_typing()
query = urllib.request.urlopen("http://xbooru.com/index.php?page=post&s=random").read()
soup = bs.BeautifulSoup(query, 'html.parser')
image = soup.find(id="image").get("src")
last = str(image.split('?')[-2]).replace('//', '/').replace(':/', '://')
em = discord.Embed(colour=discord.Colour(0xed791d))
em.description = f'[Full Size Link*]({last})'
em.set_image(url=last)
em.set_footer(text='* click link at your own risk!')
try:
await ctx.send(embed=em)
except discord.HTTPException:
await ctx.send('Unable to send embeds here!')
try:
async with ctx.session.get(image) as resp:
image = await resp.read()
with io.BytesIO(image) as file:
await ctx.send(file=discord.File(file, 'xbooru.png'))
except discord.HTTPException:
await ctx.send(image)

except Exception as e:
await ctx.send(f'```{e}```')

@commands.command(aliases=['gelbooru'])
async def gel(self, ctx):
""" Random image from Gelbooru """
try:
try:
await ctx.message.delete()
except discord.Forbidden:
pass

await ctx.channel.trigger_typing()
query = urllib.request.urlopen("http://www.gelbooru.com/index.php?page=post&s=random").read()
soup = bs.BeautifulSoup(query, 'html.parser')
sans = soup.find_all('div', {'class': 'highres-show'})
partial = soup.find(id="image").get("src")
image = partial.replace('//', '/').replace(':/', '://')

em = discord.Embed(colour=discord.Colour(0xed791d))
em.description = f'[Full Size Link*]({image})'
em.set_image(url=image)
em.set_footer(text='* click link at your own risk!')
try:
await ctx.send(embed=em)
except discord.HTTPException:
# em_list = await embedtobox.etb(em)
# for page in em_list:
# await ctx.send(page)
await ctx.send('Unable to send embeds here!')
try:
async with ctx.session.get(image) as resp:
image = await resp.read()
with io.BytesIO(image) as file:
await ctx.send(file=discord.File(file, 'gelbooru.png'))
except discord.HTTPException:
await ctx.send(image)

except Exception as e:
await ctx.send(f'```{e}```')

@nsfw.command()
async def gif(self, ctx, *, tag):
""" Get a random lewd gif
Usage: gif <tag>
Available tags: rule34, nsfw, hentai, tits... """
try:
await ctx.message.delete()
except discord.Forbidden:
pass
g = safygiphy.Giphy()
gif = g.random(tag=tag)
color = await ctx.get_dominant_color(ctx.author.avatar_url)
em = discord.Embed(color=color)
em.set_image(url=str(gif.get('data', {}).get('image_original_url')))
try:
await ctx.send(embed=em)
except discord.HTTPException:
em_list = await embedtobox.etb(em)
for page in em_list:
await ctx.send(page)


def setup(bot):
bot.add_cog(Nsfw(bot))
2 changes: 1 addition & 1 deletion cogs/gitcog.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def issue(self, ctx, repo, issueid):

@commands.command()
async def makeissue(self, ctx, repo, title, *, body):
'''Create an issue! `{}makeissue <title> | <body>`'''.format(ctx.prefix)
'''Create an issue! `{p}makeissue <title> | <body>`'''
async with ctx.session.post(f'https://api.github.com/repos/{repo}/issues', json={"title": title, "body": body}, headers={'Authorization': f'Bearer {self.githubtoken}'}) as resp:
if resp.status == 200 or resp.status == 201:
issueinfo = await resp.json()
Expand Down
24 changes: 24 additions & 0 deletions cogs/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
from urllib.request import urlopen
from sympy import solve
from PIL import Image
import safygiphy
from ext import embedtobox


class NumericStringParserForPython3(object):
Expand Down Expand Up @@ -152,6 +154,28 @@ def __init__(self, bot):
self.bot = bot
self.emoji_converter = commands.EmojiConverter()
self.nsp=NumericStringParserForPython3()

@commands.command()
async def gif(self, ctx, *, tag):
''' Get a random gif. Usage: gif <tag>
this command is sfw, to use nsfw gifs
load community.nsfw '''
g = safygiphy.Giphy()
tag = tag.lower()
with open('data/nsfw.json')as f:
nsfwgif = json.load(f)
if tag in nsfwgif:
return await ctx.send('`Please use the nsfw commands to see content like this.`', delete_after=5)
gif = g.random(tag=tag)
color = await ctx.get_dominant_color(ctx.author.avatar_url)
em = discord.Embed(color=color)
em.set_image(url=str(gif.get('data', {}).get('image_original_url')))
try:
await ctx.send(embed=em)
except discord.HTTPException:
em_list = await embedtobox.etb(em)
for page in em_list:
await ctx.send(page)

@commands.command()
async def embedsay(self, ctx, *, message):
Expand Down
Loading

0 comments on commit a295011

Please sign in to comment.