From e72e0ae24f76c0a50b2c266d41eef6cdc3b9b04c Mon Sep 17 00:00:00 2001 From: Myned Date: Fri, 13 Oct 2017 23:39:48 -0400 Subject: [PATCH] Converting string concatenation to .format --- src/main/cogs/owner.py | 13 ++++++------- src/main/cogs/tools.py | 18 ++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index 05d186d..fa9de64 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -19,17 +19,16 @@ nl = re.compile('\n') class Bot: - def __init__(self, bot, config): + def __init__(self, bot): self.bot = bot - self.config = config # Close connection to Discord - immediate offline @commands.command(name=',die', aliases=[',d'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True) @commands.is_owner() @checks.del_ctx() async def die(self, ctx): - if isinstance(self.bot.get_channel(self.config['startup_channel']), d.TextChannel): - await self.bot.get_channel(self.config['shutdown_channel']).send('**Shutting down...** 🌙') + if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel): + await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down...** 🌙') # loop = self.bot.loop.all_tasks() # for task in loop: # task.cancel() @@ -45,8 +44,8 @@ class Bot: async def restart(self, ctx): print('RESTARTING') print('-------') - if isinstance(self.bot.get_channel(self.config['startup_channel']), d.TextChannel): - await self.bot.get_channel(self.config['shutdown_channel']).send('**Restarting...** 💤') + if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel): + await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting...** 💤') # loop = self.bot.loop.all_tasks() # for task in loop: # task.cancel() @@ -60,7 +59,7 @@ class Bot: @commands.is_owner() @checks.del_ctx() async def invite(self, ctx): - await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(self.config['client_id'], self.config['permissions']), delete_after=10) + await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(u.config['client_id'], u.config['permissions']), delete_after=10) @commands.command(aliases=['presence', 'game'], hidden=True) @commands.is_owner() diff --git a/src/main/cogs/tools.py b/src/main/cogs/tools.py index 2f7f7a2..19c8c74 100644 --- a/src/main/cogs/tools.py +++ b/src/main/cogs/tools.py @@ -35,21 +35,19 @@ class Utils: @commands.command(name='last', aliases=['l', ','], brief='Reinvokes last command', description='Reinvokes previous command executed', hidden=True) async def last_command(self, ctx): - global command_dict - if command_dict.get(str(ctx.message.author.id), {}).get('args', None) is not None: args = command_dict.get(str(ctx.message.author.id), {})['args'] print(command_dict) + await ctx.invoke(command_dict.get(str(ctx.message.author.id), {}).get('command', None), args) # [prefix]ping -> Pong! @commands.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user') @checks.del_ctx() async def ping(self, ctx): - global command_dict + user = ctx.message.author - await ctx.send(ctx.message.author.mention + ' 🏓 `' + str(round(self.bot.latency * 1000)) + 'ms`', delete_after=5) - command_dict.setdefault(str(ctx.message.author.id), {}).update({'command': ctx.command}) + await ctx.send('{} 🏓 `{}ms`'.format(round(self.bot.latency * 1000)), delete_after=5) @commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes') @checks.del_ctx() @@ -70,7 +68,7 @@ class Utils: async def send_user(self, ctx, user, *message): await discord.utils.get(self.bot.get_all_members(), id=int(user)).send(formatter.tostring(message)) - @commands.command(aliases=['authenticateupload', 'authupload', 'authup', 'auth']) + @commands.command(aliases=['authupload', 'auth']) async def authenticate_upload(self, ctx): global youtube flow = flow_from_clientsecrets('client_secrets.json', scope='https://www.googleapis.com/auth/youtube.upload', @@ -97,12 +95,12 @@ class Utils: await attachments[0].save(temp) else: raise exc.InvalidVideoFile(mime) - print('https://www.youtube.com/watch?v=' + youtube.videos().insert(part='snippet', - body={'categoryId': '24', 'title': 'Test'}, media_body=http.MediaFileUpload(temp.name, chunksize=-1))) + print('https://www.youtube.com/watch?v={}'.format(youtube.videos().insert(part='snippet', + body={'categoryId': '24', 'title': 'Test'}, media_body=http.MediaFileUpload(temp.name, chunksize=-1)))) except exc.InvalidVideoFile as e: - await ctx.send('❌ `' + str(e) + '` **not valid video type.**', delete_after=10) + await ctx.send('❌ `{}` **not valid video type.**'.format(e), delete_after=10) except exc.TooManyAttachments as e: - await ctx.send('❌ `' + str(e) + '` **too many attachments.** Only one attachment is permitted to upload.', delete_after=10) + await ctx.send('❌ `{}` **too many attachments.** Only one attachment is permitted to upload.'.format(e), delete_after=10) except exc.MissingAttachment: await ctx.send('❌ **Missing attachment.**', delete_after=10)