Skip to content

Commit a295011

Browse files
Merge pull request #2 from verixx/rewrite
update
2 parents 6e9a606 + 7484753 commit a295011

File tree

13 files changed

+560
-80
lines changed

13 files changed

+560
-80
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ __pycache__/
22
*.py[cod]
33
*$py.class
44
*.DS_Store
5-
*.json
6-
cogs/testsplit.py
7-
data/community_cogs.txt
5+
data/community_cogs.txt

cogs/community/clashroyale.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
'''
22
MIT License
3-
43
Copyright (c) 2017 Grok
5-
64
Permission is hereby granted, free of charge, to any person obtaining a copy
75
of this software and associated documentation files (the "Software"), to deal
86
in the Software without restriction, including without limitation the rights
97
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
108
copies of the Software, and to permit persons to whom the Software is
119
furnished to do so, subject to the following conditions:
12-
1310
The above copyright notice and this permission notice shall be included in all
1411
copies or substantial portions of the Software.
15-
1612
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1713
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1814
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -34,42 +30,54 @@ class ClashRoyale:
3430

3531
def __init__(self, bot):
3632
self.bot = bot
37-
with open('data/config.json') as f:
38-
config = json.load(f)
39-
if 'CR_TAG' not in config:
40-
tag = None
33+
with open('data/options.json') as f:
34+
options = json.load(f)
35+
if 'CR_TAG' not in options:
36+
self.tag = None
4137
else:
42-
tag = config['CR_TAG']
43-
self.tag = os.environ.get('CR_TAG') or tag
38+
self.tag = options['CR_TAG']
4439
self.client = crasync.Client()
45-
40+
4641

4742
@commands.command()
4843
async def profile(self, ctx, tag=None):
4944
'''Fetch a Clash Royale Profile!'''
5045
em = discord.Embed(title="Profile")
5146
em.color = await ctx.get_dominant_color(ctx.author.avatar_url)
52-
if tag == None:
47+
if tag is None and self.tag is None:
48+
em.description = "Please add `CR_TAG` to your options. Do `{p}options edit cr_tag <tag>`"
49+
return await ctx.send(embed=em)
50+
elif self.tag is not None:
5351
tag = self.tag
54-
if tag == None:
55-
em.description = "Please add `CR_TAG` to your config."
56-
return await ctx.send(embed=em)
52+
53+
tag = tag.strip('#').replace('O', '0')
5754
try:
5855
profile = await self.client.get_profile(tag)
5956
except:
6057
em.description = "Either API is down or that's an invalid tag."
6158
return await ctx.send(embed=em)
62-
59+
6360
em.title = profile.name
61+
em.set_thumbnail(url=profile.arena.image_url)
6462
em.description = f"#{tag}"
6563
em.url = f"http://cr-api.com/profile/{tag}"
64+
em.add_field(name='Current Trophies', value=profile.current_trophies)
65+
em.add_field(name='Highest Trophies', value=profile.highest_trophies)
66+
em.add_field(name='Legend Trophies', value=f'{profile.legend_trophies}')
67+
em.add_field(name='Level', value=profile.level)
68+
em.add_field(name='Experience', value=f"{profile.experience[0]}/{profile.experience[1]}")
69+
em.add_field(name='Wins/Losses/Draws', value=f'{profile.wins}/{profile.losses}/{profile.draws}')
70+
em.add_field(name='Global Rank', value=f'{profile.global_rank}')
71+
em.add_field(name='Clan Info', value=f'{profile.clan_name}\n#{profile.clan_tag}\n{profile.clan_role}')
72+
em.add_field(name='Win Streak', value=f'{profile.win_streak}')
73+
em.set_footer(text="Powered By cr-api.com", icon_url="http://cr-api.com/static/img/branding/cr-api-logo.png")
74+
6675
try:
6776
em.set_author(name="Profile", icon_url=profile.clan_badge_url)
6877
except:
6978
em.set_author(name='Profile')
70-
7179
await ctx.send(embed=em)
7280

7381

7482
def setup(bot):
75-
bot.add_cog(ClashRoyale(bot))
83+
bot.add_cog(ClashRoyale(bot))

cogs/community/nsfw.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""
2+
MIT License
3+
4+
Copyright (c) 2017 Grok's naughty dev XAOS
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
"""
24+
25+
import discord
26+
from discord.ext import commands
27+
import bs4 as bs
28+
import urllib.request
29+
from bs4 import BeautifulSoup
30+
from urllib.request import Request, urlopen
31+
import json
32+
import io
33+
import safygiphy
34+
from ext import embed2box
35+
36+
class Nsfw:
37+
""" Nsfw commands """
38+
def __init__(self, bot):
39+
self.bot = bot
40+
41+
async def __local_check(self, ctx):
42+
if not ctx.channel.is_nsfw():
43+
return False
44+
git = self.bot.get_cog('Git')
45+
if not await git.starred('verixx/selfbot.py'):
46+
return False
47+
return True
48+
49+
@commands.group(invoke_without_command=True)
50+
async def nsfw(self, ctx):
51+
""" Get random lewds from the web """
52+
pass
53+
54+
@nsfw.command()
55+
async def xbooru(self, ctx):
56+
""" Random image from Xbooru """
57+
try:
58+
try:
59+
await ctx.message.delete()
60+
except discord.Forbidden:
61+
pass
62+
await ctx.channel.trigger_typing()
63+
query = urllib.request.urlopen("http://xbooru.com/index.php?page=post&s=random").read()
64+
soup = bs.BeautifulSoup(query, 'html.parser')
65+
image = soup.find(id="image").get("src")
66+
last = str(image.split('?')[-2]).replace('//', '/').replace(':/', '://')
67+
em = discord.Embed(colour=discord.Colour(0xed791d))
68+
em.description = f'[Full Size Link*]({last})'
69+
em.set_image(url=last)
70+
em.set_footer(text='* click link at your own risk!')
71+
try:
72+
await ctx.send(embed=em)
73+
except discord.HTTPException:
74+
await ctx.send('Unable to send embeds here!')
75+
try:
76+
async with ctx.session.get(image) as resp:
77+
image = await resp.read()
78+
with io.BytesIO(image) as file:
79+
await ctx.send(file=discord.File(file, 'xbooru.png'))
80+
except discord.HTTPException:
81+
await ctx.send(image)
82+
83+
except Exception as e:
84+
await ctx.send(f'```{e}```')
85+
86+
@commands.command(aliases=['gelbooru'])
87+
async def gel(self, ctx):
88+
""" Random image from Gelbooru """
89+
try:
90+
try:
91+
await ctx.message.delete()
92+
except discord.Forbidden:
93+
pass
94+
95+
await ctx.channel.trigger_typing()
96+
query = urllib.request.urlopen("http://www.gelbooru.com/index.php?page=post&s=random").read()
97+
soup = bs.BeautifulSoup(query, 'html.parser')
98+
sans = soup.find_all('div', {'class': 'highres-show'})
99+
partial = soup.find(id="image").get("src")
100+
image = partial.replace('//', '/').replace(':/', '://')
101+
102+
em = discord.Embed(colour=discord.Colour(0xed791d))
103+
em.description = f'[Full Size Link*]({image})'
104+
em.set_image(url=image)
105+
em.set_footer(text='* click link at your own risk!')
106+
try:
107+
await ctx.send(embed=em)
108+
except discord.HTTPException:
109+
# em_list = await embedtobox.etb(em)
110+
# for page in em_list:
111+
# await ctx.send(page)
112+
await ctx.send('Unable to send embeds here!')
113+
try:
114+
async with ctx.session.get(image) as resp:
115+
image = await resp.read()
116+
with io.BytesIO(image) as file:
117+
await ctx.send(file=discord.File(file, 'gelbooru.png'))
118+
except discord.HTTPException:
119+
await ctx.send(image)
120+
121+
except Exception as e:
122+
await ctx.send(f'```{e}```')
123+
124+
@nsfw.command()
125+
async def gif(self, ctx, *, tag):
126+
""" Get a random lewd gif
127+
Usage: gif <tag>
128+
Available tags: rule34, nsfw, hentai, tits... """
129+
try:
130+
await ctx.message.delete()
131+
except discord.Forbidden:
132+
pass
133+
g = safygiphy.Giphy()
134+
gif = g.random(tag=tag)
135+
color = await ctx.get_dominant_color(ctx.author.avatar_url)
136+
em = discord.Embed(color=color)
137+
em.set_image(url=str(gif.get('data', {}).get('image_original_url')))
138+
try:
139+
await ctx.send(embed=em)
140+
except discord.HTTPException:
141+
em_list = await embedtobox.etb(em)
142+
for page in em_list:
143+
await ctx.send(page)
144+
145+
146+
def setup(bot):
147+
bot.add_cog(Nsfw(bot))

cogs/gitcog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def issue(self, ctx, repo, issueid):
6868

6969
@commands.command()
7070
async def makeissue(self, ctx, repo, title, *, body):
71-
'''Create an issue! `{}makeissue <title> | <body>`'''.format(ctx.prefix)
71+
'''Create an issue! `{p}makeissue <title> | <body>`'''
7272
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:
7373
if resp.status == 200 or resp.status == 201:
7474
issueinfo = await resp.json()

cogs/misc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
from urllib.request import urlopen
5656
from sympy import solve
5757
from PIL import Image
58+
import safygiphy
59+
from ext import embedtobox
5860

5961

6062
class NumericStringParserForPython3(object):
@@ -152,6 +154,28 @@ def __init__(self, bot):
152154
self.bot = bot
153155
self.emoji_converter = commands.EmojiConverter()
154156
self.nsp=NumericStringParserForPython3()
157+
158+
@commands.command()
159+
async def gif(self, ctx, *, tag):
160+
''' Get a random gif. Usage: gif <tag>
161+
this command is sfw, to use nsfw gifs
162+
load community.nsfw '''
163+
g = safygiphy.Giphy()
164+
tag = tag.lower()
165+
with open('data/nsfw.json')as f:
166+
nsfwgif = json.load(f)
167+
if tag in nsfwgif:
168+
return await ctx.send('`Please use the nsfw commands to see content like this.`', delete_after=5)
169+
gif = g.random(tag=tag)
170+
color = await ctx.get_dominant_color(ctx.author.avatar_url)
171+
em = discord.Embed(color=color)
172+
em.set_image(url=str(gif.get('data', {}).get('image_original_url')))
173+
try:
174+
await ctx.send(embed=em)
175+
except discord.HTTPException:
176+
em_list = await embedtobox.etb(em)
177+
for page in em_list:
178+
await ctx.send(page)
155179

156180
@commands.command()
157181
async def embedsay(self, ctx, *, message):

0 commit comments

Comments
 (0)