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

Added changing game status, removed prefix for exit, cleaned try/except

This commit is contained in:
Myned 2017-10-13 21:53:44 -04:00
parent 48b17e3ab2
commit 80050b9541

View file

@ -62,6 +62,18 @@ class Bot:
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(self.config['client_id'], self.config['permissions']), delete_after=10)
@commands.command(aliases=['presence', 'game'], hidden=True)
@commands.is_owner()
@checks.del_ctx()
async def status(self, ctx, game):
try:
if game is not None:
await self.bot.change_presence(game=d.Game(name=game))
else:
raise exc.NotFound
except exc.NotFound:
await ctx.send('❌ **No game given.**', delete_after=10)
class Tools: class Tools:
@ -96,8 +108,8 @@ class Tools:
@checks.del_ctx() @checks.del_ctx()
async def console(self, ctx): async def console(self, ctx):
def execute(msg): def execute(msg):
if msg.content == ',exit' and msg.author is ctx.message.author: if msg.content == 'exit' and msg.author is ctx.message.author:
raise exc.CheckFail raise exc.Abort
elif msg.author is ctx.message.author and msg.channel is ctx.message.channel: elif msg.author is ctx.message.author and msg.channel is ctx.message.channel:
return True return True
else: else:
@ -107,20 +119,23 @@ class Tools:
console = await self.generate(ctx) console = await self.generate(ctx)
exception = await self.generate_err(ctx) exception = await self.generate_err(ctx)
while not self.bot.is_closed(): while not self.bot.is_closed():
try:
exe = await self.bot.wait_for('message', check=execute) exe = await self.bot.wait_for('message', check=execute)
except exc.Abort:
raise exc.Abort
finally:
await exe.delete() await exe.delete()
try:
sys.stdout = io.StringIO() sys.stdout = io.StringIO()
sys.stderr = io.StringIO() sys.stderr = io.StringIO()
try:
exec(exe.content) exec(exe.content)
except Exception: except Exception:
tb.print_exc(limit=1) await self.refresh_err(exception, tb.format_exc(limit=1))
finally:
await self.refresh(console, exe.content, sys.stdout.getvalue()) await self.refresh(console, exe.content, sys.stdout.getvalue())
await self.refresh_err(exception, sys.stderr.getvalue())
await ctx.send(console.content[10:-3])
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__
except exc.CheckFail: except exc.Abort:
await ctx.send('↩️ **Exited console.**') await ctx.send('↩️ **Exited console.**')
finally: finally:
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__