1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-24 14:27:27 +00:00

Converting string concatenation to .format

This commit is contained in:
Myned 2017-10-13 23:39:48 -04:00
parent ada3aac86a
commit e72e0ae24f
2 changed files with 14 additions and 17 deletions

View file

@ -19,17 +19,16 @@ nl = re.compile('\n')
class Bot: class Bot:
def __init__(self, bot, config): def __init__(self, bot):
self.bot = bot self.bot = bot
self.config = config
# Close connection to Discord - immediate offline # 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.command(name=',die', aliases=[',d'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx() @checks.del_ctx()
async def die(self, ctx): async def die(self, ctx):
if isinstance(self.bot.get_channel(self.config['startup_channel']), d.TextChannel): if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel):
await self.bot.get_channel(self.config['shutdown_channel']).send('**Shutting down...** 🌙') await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down...** 🌙')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()
# for task in loop: # for task in loop:
# task.cancel() # task.cancel()
@ -45,8 +44,8 @@ class Bot:
async def restart(self, ctx): async def restart(self, ctx):
print('RESTARTING') print('RESTARTING')
print('-------') print('-------')
if isinstance(self.bot.get_channel(self.config['startup_channel']), d.TextChannel): if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel):
await self.bot.get_channel(self.config['shutdown_channel']).send('**Restarting...** 💤') await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting...** 💤')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()
# for task in loop: # for task in loop:
# task.cancel() # task.cancel()
@ -60,7 +59,7 @@ class Bot:
@commands.is_owner() @commands.is_owner()
@checks.del_ctx() @checks.del_ctx()
async def invite(self, 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.command(aliases=['presence', 'game'], hidden=True)
@commands.is_owner() @commands.is_owner()

View file

@ -35,21 +35,19 @@ class Utils:
@commands.command(name='last', aliases=['l', ','], brief='Reinvokes last command', description='Reinvokes previous command executed', hidden=True) @commands.command(name='last', aliases=['l', ','], brief='Reinvokes last command', description='Reinvokes previous command executed', hidden=True)
async def last_command(self, ctx): async def last_command(self, ctx):
global command_dict
if command_dict.get(str(ctx.message.author.id), {}).get('args', None) is not None: 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'] args = command_dict.get(str(ctx.message.author.id), {})['args']
print(command_dict) print(command_dict)
await ctx.invoke(command_dict.get(str(ctx.message.author.id), {}).get('command', None), args) await ctx.invoke(command_dict.get(str(ctx.message.author.id), {}).get('command', None), args)
# [prefix]ping -> Pong! # [prefix]ping -> Pong!
@commands.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user') @commands.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user')
@checks.del_ctx() @checks.del_ctx()
async def ping(self, 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) await ctx.send('{} 🏓 `{}ms`'.format(round(self.bot.latency * 1000)), delete_after=5)
command_dict.setdefault(str(ctx.message.author.id), {}).update({'command': ctx.command})
@commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes') @commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
@checks.del_ctx() @checks.del_ctx()
@ -70,7 +68,7 @@ class Utils:
async def send_user(self, ctx, user, *message): async def send_user(self, ctx, user, *message):
await discord.utils.get(self.bot.get_all_members(), id=int(user)).send(formatter.tostring(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): async def authenticate_upload(self, ctx):
global youtube global youtube
flow = flow_from_clientsecrets('client_secrets.json', scope='https://www.googleapis.com/auth/youtube.upload', 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) await attachments[0].save(temp)
else: else:
raise exc.InvalidVideoFile(mime) raise exc.InvalidVideoFile(mime)
print('https://www.youtube.com/watch?v=' + youtube.videos().insert(part='snippet', 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))) body={'categoryId': '24', 'title': 'Test'}, media_body=http.MediaFileUpload(temp.name, chunksize=-1))))
except exc.InvalidVideoFile as e: 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: 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: except exc.MissingAttachment:
await ctx.send('❌ **Missing attachment.**', delete_after=10) await ctx.send('❌ **Missing attachment.**', delete_after=10)