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:
parent
48b17e3ab2
commit
80050b9541
1 changed files with 28 additions and 13 deletions
|
@ -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():
|
||||||
exe = await self.bot.wait_for('message', check=execute)
|
|
||||||
await exe.delete()
|
|
||||||
sys.stdout = io.StringIO()
|
|
||||||
sys.stderr = io.StringIO()
|
|
||||||
try:
|
try:
|
||||||
|
exe = await self.bot.wait_for('message', check=execute)
|
||||||
|
except exc.Abort:
|
||||||
|
raise exc.Abort
|
||||||
|
finally:
|
||||||
|
await exe.delete()
|
||||||
|
try:
|
||||||
|
sys.stdout = io.StringIO()
|
||||||
|
sys.stderr = io.StringIO()
|
||||||
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))
|
||||||
await self.refresh(console, exe.content, sys.stdout.getvalue())
|
finally:
|
||||||
await self.refresh_err(exception, sys.stderr.getvalue())
|
await self.refresh(console, exe.content, sys.stdout.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.Abort:
|
||||||
except exc.CheckFail:
|
|
||||||
await ctx.send('↩️ **Exited console.**')
|
await ctx.send('↩️ **Exited console.**')
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
|
|
Loading…
Reference in a new issue