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

Commit

Permalink
Merge pull request #2 from verixx/rewrite
Browse files Browse the repository at this point in the history
Update 2
  • Loading branch information
SharpBit authored Nov 15, 2017
2 parents ea10ca6 + 23e8be7 commit 0775aec
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
34 changes: 12 additions & 22 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 Down Expand Up @@ -48,46 +44,40 @@ 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 options. Do `{p}options edit cr_tag <tag>`"
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)

trophies = str(profile.current_trophies)
pb = str(profile.highest_trophies)
xp = str(profile.level)
experience = str(profile.experience[0]) + '/' + str(profile.experience[1])


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=trophies)
em.add_field(name='Highest Trophies',value=pb)
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=xp)
em.add_field(name='Experience', value=experience)
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' + '#' + f'{profile.clan_tag}' + '\n' + f'{profile.clan_role}')
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))
41 changes: 33 additions & 8 deletions cogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ async def _eval(self, ctx, *, body: str, edit=True):
else:
await ctx.message.add_reaction('\u2705')

async def edit_to_codeblock(self, ctx, body, pycc=False):
if not pycc:
async def edit_to_codeblock(self, ctx, body, pycc='blank'):
if pycc == 'blank':
msg = f'{ctx.prefix}eval\n```py\n{body}\n```'
else:
msg = f'{ctx.prefix}cc make {pycc}\n```py\n{body}\n```'
Expand Down Expand Up @@ -1066,9 +1066,9 @@ async def make(self, ctx, name, *, content):
commands['pycc'][name]
except KeyError:
if '{pycc}' in content:
commands['pycc'].update({name: content})
commands['pycc'].update({name: content.strip('{pycc}')})
cmdtype = 'pycc'
await self.edit_to_codeblock(ctx, content, pycc=True)
await self.edit_to_codeblock(ctx, content.strip('{pycc}'), pycc=name)
else:
commands['textcc'].update({name: content})
cmdtype = 'text'
Expand Down Expand Up @@ -1145,27 +1145,51 @@ async def _list(self, ctx, option:str = 'all'):
else:
await ctx.send('Invalid option. Available options: `text`, `pycc`, `all`')

def agreecheck(self, message):
return message.content.lower() == 'yes' and message.author == self.bot.user

@cc.command()
async def wipe(self, ctx):
"""Wipes all your custom commands!"""
message1 = await ctx.send('Are you sure you want to delete all your custom commands?')
try:
message2 = await self.bot.wait_for('message', check=self.agreecheck, timeout=5)
except asyncio.TimeoutError:
await message1.delete()
return
else:
await message1.delete()
await message2.delete()
await ctx.send('Wiping...', delete_after=2)
if await ctx.updatedata('data/cc.json', json.dumps({"pycc":{},"textcc":{}}, indent=4), f'Wipe custom commands'):
await ctx.send('Wiped all commands.', delete_after=2)

#reading cc
async def on_message(self, message):
if message.author != self.bot.user: return
if message.content.startswith(await self.bot.get_pre(self.bot, message)):
prefix = await self.bot.get_pre(self.bot, message)
if message.content.startswith(prefix):
with open('data/cc.json') as f:
commands = json.load(f)
try:
await message.channel.send(commands['textcc'][message.content.strip(await self.bot.get_pre(self.bot, message))])
commands['textcc'][message.content.strip(prefix)]
except KeyError:
try:
utils = self.bot.get_cog('Utility')
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)
commands['pycc'][message.content.strip(prefix)]
except KeyError:
pass
else:
utils = self.bot.get_cog('Utility')
await (await self.bot.get_context(message)).invoke(utils._eval, body=str(commands['pycc'][message.content.strip(prefix)]), edit=False)
else:
await message.channel.send(commands['textcc'][message.content.strip(prefix)])

@commands.group(invoke_without_command=True)
async def options(self, ctx):
pass
@options.command()
async def edit(self, ctx, name, *, value):
"""Edits an option"""
name = name.upper()
with open('data/options.json') as f:
options = json.load(f)
Expand All @@ -1180,6 +1204,7 @@ async def edit(self, ctx, name, *, value):

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

Expand Down
1 change: 0 additions & 1 deletion data/community_cogs.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
nsfw
clashroyale
1 change: 1 addition & 0 deletions selfbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, **attrs):
self.add_command(self.ping)
self.load_extensions()
self.add_command(self.load)
self.add_command(self.reloadcog)
self.load_community_extensions()

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

0 comments on commit 0775aec

Please sign in to comment.