mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
WIP fixes for console command
This commit is contained in:
parent
1ccc1a10cc
commit
e550c7b14e
1 changed files with 20 additions and 18 deletions
|
@ -120,20 +120,19 @@ class Tools:
|
|||
@checks.del_ctx()
|
||||
async def console(self, ctx):
|
||||
def execute(msg):
|
||||
if msg.content.startswith('exe') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||
results.cancel()
|
||||
if msg.content.lower().startswith('exec ') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||
msg.content = msg.content[5:]
|
||||
return True
|
||||
return False
|
||||
|
||||
def evaluate(msg):
|
||||
if msg.content.startswith('eval') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||
results.cancel()
|
||||
if msg.content.lower().startswith('eval ') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||
msg.content = msg.content[5:]
|
||||
return True
|
||||
return False
|
||||
|
||||
def exit(reaction, user):
|
||||
if reaction.emoji == '\N{LEFTWARDS ARROW WITH HOOK}' and user is ctx.author and reaction.message.id == ctx.message.id:
|
||||
results.cancel()
|
||||
if reaction.emoji == '\N{OCTAGONAL SIGN}' and user is ctx.author and reaction.message.id == ctx.message.id:
|
||||
raise exc.Abort
|
||||
return False
|
||||
|
||||
|
@ -141,43 +140,46 @@ class Tools:
|
|||
console = await self.generate(ctx)
|
||||
exception = await self.generate_err(ctx)
|
||||
|
||||
await ctx.message.add_reaction('\N{LEFTWARDS ARROW WITH HOOK}')
|
||||
await ctx.message.add_reaction('\N{OCTAGONAL SIGN}')
|
||||
|
||||
while not self.bot.is_closed():
|
||||
try:
|
||||
results = await asyncio.gather([self.bot.wait_for('message', check=execute), self.bot.wait_for('message', check=evaluate), self.bot.wait_for('reaction_add', check=exit)], return_exceptions=True)
|
||||
print(results)
|
||||
done, pending = await asyncio.wait([self.bot.wait_for('message', check=execute), self.bot.wait_for('message', check=evaluate), self.bot.wait_for('reaction_add', check=exit)], return_when=asyncio.FIRST_COMPLETED)
|
||||
|
||||
message = done.pop().result()
|
||||
print(message.content)
|
||||
|
||||
except exc.Execute:
|
||||
try:
|
||||
sys.stdout = io.StringIO()
|
||||
sys.stderr = io.StringIO()
|
||||
exec(exe.content)
|
||||
exec(message.content)
|
||||
|
||||
except Exception:
|
||||
await self.refresh_err(exception, tb.format_exc(limit=1))
|
||||
|
||||
finally:
|
||||
await self.refresh(console, exe.content, sys.stdout.getvalue() if sys.stdout.getvalue() != console.content else None)
|
||||
await self.refresh(console, message.content, sys.stdout.getvalue() if sys.stdout.getvalue() != console.content else None)
|
||||
sys.stdout = sys.__stdout__
|
||||
sys.stderr = sys.__stderr__
|
||||
with suppress(d.NotFound):
|
||||
await message.delete()
|
||||
|
||||
except exc.Evaluate:
|
||||
try:
|
||||
sys.stdout = io.StringIO()
|
||||
sys.stderr = io.StringIO()
|
||||
eval(exe.content)
|
||||
eval(message.content)
|
||||
|
||||
except Exception:
|
||||
await self.refresh_err(exception, tb.format_exc(limit=1))
|
||||
|
||||
finally:
|
||||
await self.refresh(console, exe.content, sys.stdout.getvalue() if sys.stdout.getvalue() != console.content else None)
|
||||
await self.refresh(console, message.content, sys.stdout.getvalue() if sys.stdout.getvalue() != console.content else None)
|
||||
sys.stdout = sys.__stdout__
|
||||
sys.stderr = sys.__stderr__
|
||||
|
||||
finally:
|
||||
with suppress(d.NotFound):
|
||||
await exe.delete()
|
||||
with suppress(d.NotFound):
|
||||
await message.delete()
|
||||
|
||||
except exc.Abort:
|
||||
pass
|
||||
|
@ -195,7 +197,7 @@ class Tools:
|
|||
async def execute(self, ctx, *, exe):
|
||||
try:
|
||||
with io.StringIO() as buff, redirect_stdout(buff):
|
||||
exec(exe)
|
||||
exec(exe)
|
||||
await self.generate(ctx, exe, buff.getvalue())
|
||||
|
||||
except Exception:
|
||||
|
|
Loading…
Reference in a new issue