Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit 0775aec

Browse files
authored
Merge pull request #2 from verixx/rewrite
Update 2
2 parents ea10ca6 + 23e8be7 commit 0775aec

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

cogs/community/clashroyale.py

Lines changed: 12 additions & 22 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
@@ -48,46 +44,40 @@ async def profile(self, ctx, tag=None):
4844
'''Fetch a Clash Royale Profile!'''
4945
em = discord.Embed(title="Profile")
5046
em.color = await ctx.get_dominant_color(ctx.author.avatar_url)
51-
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:
5251
tag = self.tag
53-
if tag == None:
54-
em.description = "Please add `CR_TAG` to your options. Do `{p}options edit cr_tag <tag>`"
55-
return await ctx.send(embed=em)
52+
5653
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-
63-
trophies = str(profile.current_trophies)
64-
pb = str(profile.highest_trophies)
65-
xp = str(profile.level)
66-
experience = str(profile.experience[0]) + '/' + str(profile.experience[1])
67-
59+
6860
em.title = profile.name
6961
em.set_thumbnail(url=profile.arena.image_url)
7062
em.description = f"#{tag}"
7163
em.url = f"http://cr-api.com/profile/{tag}"
72-
em.add_field(name='Current Trophies', value=trophies)
73-
em.add_field(name='Highest Trophies',value=pb)
64+
em.add_field(name='Current Trophies', value=profile.current_trophies)
65+
em.add_field(name='Highest Trophies', value=profile.highest_trophies)
7466
em.add_field(name='Legend Trophies', value=f'{profile.legend_trophies}')
75-
em.add_field(name='Level', value=xp)
76-
em.add_field(name='Experience', value=experience)
67+
em.add_field(name='Level', value=profile.level)
68+
em.add_field(name='Experience', value=f"{profile.experience[0]}/{profile.experience[1]}")
7769
em.add_field(name='Wins/Losses/Draws', value=f'{profile.wins}/{profile.losses}/{profile.draws}')
7870
em.add_field(name='Global Rank', value=f'{profile.global_rank}')
79-
em.add_field(name='Clan Info', value=f'{profile.clan_name}' + '\n' + '#' + f'{profile.clan_tag}' + '\n' + f'{profile.clan_role}')
71+
em.add_field(name='Clan Info', value=f'{profile.clan_name}\n#{profile.clan_tag}\n{profile.clan_role}')
8072
em.add_field(name='Win Streak', value=f'{profile.win_streak}')
8173
em.set_footer(text="Powered By cr-api.com", icon_url="http://cr-api.com/static/img/branding/cr-api-logo.png")
8274

8375
try:
8476
em.set_author(name="Profile", icon_url=profile.clan_badge_url)
8577
except:
8678
em.set_author(name='Profile')
87-
88-
8979
await ctx.send(embed=em)
9080

9181

9282
def setup(bot):
93-
bot.add_cog(ClashRoyale(bot))
83+
bot.add_cog(ClashRoyale(bot))

cogs/utils.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ async def _eval(self, ctx, *, body: str, edit=True):
903903
else:
904904
await ctx.message.add_reaction('\u2705')
905905

906-
async def edit_to_codeblock(self, ctx, body, pycc=False):
907-
if not pycc:
906+
async def edit_to_codeblock(self, ctx, body, pycc='blank'):
907+
if pycc == 'blank':
908908
msg = f'{ctx.prefix}eval\n```py\n{body}\n```'
909909
else:
910910
msg = f'{ctx.prefix}cc make {pycc}\n```py\n{body}\n```'
@@ -1066,9 +1066,9 @@ async def make(self, ctx, name, *, content):
10661066
commands['pycc'][name]
10671067
except KeyError:
10681068
if '{pycc}' in content:
1069-
commands['pycc'].update({name: content})
1069+
commands['pycc'].update({name: content.strip('{pycc}')})
10701070
cmdtype = 'pycc'
1071-
await self.edit_to_codeblock(ctx, content, pycc=True)
1071+
await self.edit_to_codeblock(ctx, content.strip('{pycc}'), pycc=name)
10721072
else:
10731073
commands['textcc'].update({name: content})
10741074
cmdtype = 'text'
@@ -1145,27 +1145,51 @@ async def _list(self, ctx, option:str = 'all'):
11451145
else:
11461146
await ctx.send('Invalid option. Available options: `text`, `pycc`, `all`')
11471147

1148+
def agreecheck(self, message):
1149+
return message.content.lower() == 'yes' and message.author == self.bot.user
1150+
1151+
@cc.command()
1152+
async def wipe(self, ctx):
1153+
"""Wipes all your custom commands!"""
1154+
message1 = await ctx.send('Are you sure you want to delete all your custom commands?')
1155+
try:
1156+
message2 = await self.bot.wait_for('message', check=self.agreecheck, timeout=5)
1157+
except asyncio.TimeoutError:
1158+
await message1.delete()
1159+
return
1160+
else:
1161+
await message1.delete()
1162+
await message2.delete()
1163+
await ctx.send('Wiping...', delete_after=2)
1164+
if await ctx.updatedata('data/cc.json', json.dumps({"pycc":{},"textcc":{}}, indent=4), f'Wipe custom commands'):
1165+
await ctx.send('Wiped all commands.', delete_after=2)
11481166

11491167
#reading cc
11501168
async def on_message(self, message):
11511169
if message.author != self.bot.user: return
1152-
if message.content.startswith(await self.bot.get_pre(self.bot, message)):
1170+
prefix = await self.bot.get_pre(self.bot, message)
1171+
if message.content.startswith(prefix):
11531172
with open('data/cc.json') as f:
11541173
commands = json.load(f)
11551174
try:
1156-
await message.channel.send(commands['textcc'][message.content.strip(await self.bot.get_pre(self.bot, message))])
1175+
commands['textcc'][message.content.strip(prefix)]
11571176
except KeyError:
11581177
try:
1159-
utils = self.bot.get_cog('Utility')
1160-
await (await self.bot.get_context(message)).invoke(utils._eval, body=commands['pycc'][message.content.strip(await self.bot.get_pre(self.bot, message))], edit=False)
1178+
commands['pycc'][message.content.strip(prefix)]
11611179
except KeyError:
11621180
pass
1181+
else:
1182+
utils = self.bot.get_cog('Utility')
1183+
await (await self.bot.get_context(message)).invoke(utils._eval, body=str(commands['pycc'][message.content.strip(prefix)]), edit=False)
1184+
else:
1185+
await message.channel.send(commands['textcc'][message.content.strip(prefix)])
11631186

11641187
@commands.group(invoke_without_command=True)
11651188
async def options(self, ctx):
11661189
pass
11671190
@options.command()
11681191
async def edit(self, ctx, name, *, value):
1192+
"""Edits an option"""
11691193
name = name.upper()
11701194
with open('data/options.json') as f:
11711195
options = json.load(f)
@@ -1180,6 +1204,7 @@ async def edit(self, ctx, name, *, value):
11801204

11811205
@options.command(name='list')
11821206
async def __list(self, ctx):
1207+
"""Lists all options"""
11831208
with open ('data/options.json') as f:
11841209
await ctx.send('```json\n' + json.dumps(json.load(f), indent=4) + '\n```')
11851210

data/community_cogs.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
nsfw
21
clashroyale

selfbot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(self, **attrs):
6666
self.add_command(self.ping)
6767
self.load_extensions()
6868
self.add_command(self.load)
69+
self.add_command(self.reloadcog)
6970
self.load_community_extensions()
7071

7172
def load_extensions(self, cogs=None, path='cogs.'):

0 commit comments

Comments
 (0)