mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 06:37:29 +00:00
Merge branch 'dev'
This commit is contained in:
commit
4d7c6592be
2 changed files with 49 additions and 38 deletions
|
@ -681,10 +681,8 @@ class MsG:
|
||||||
|
|
||||||
while not self.bot.is_closed():
|
while not self.bot.is_closed():
|
||||||
try:
|
try:
|
||||||
done, pending = await asyncio.wait([self.bot.wait_for('reaction_add', check=on_reaction, timeout=10 * 60),
|
await asyncio.gather(*[self.bot.wait_for('reaction_add', check=on_reaction, timeout=10 * 60),
|
||||||
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=10 * 60)], return_when=asyncio.FIRST_COMPLETED)
|
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=10 * 60)])
|
||||||
for future in done:
|
|
||||||
future.result()
|
|
||||||
|
|
||||||
except exc.Save:
|
except exc.Save:
|
||||||
if values[c - 1]['url'] not in hearted:
|
if values[c - 1]['url'] not in hearted:
|
||||||
|
@ -824,10 +822,8 @@ class MsG:
|
||||||
|
|
||||||
while not self.bot.is_closed():
|
while not self.bot.is_closed():
|
||||||
try:
|
try:
|
||||||
done, pending = await asyncio.wait([self.bot.wait_for('reaction_add', check=on_reaction, timeout=10 * 60),
|
await asyncio.gather(*[self.bot.wait_for('reaction_add', check=on_reaction, timeout=10 * 60),
|
||||||
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=10 * 60)], return_when=asyncio.FIRST_COMPLETED)
|
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=10 * 60)])
|
||||||
for future in done:
|
|
||||||
future.result()
|
|
||||||
|
|
||||||
except exc.Save:
|
except exc.Save:
|
||||||
if values[c - 1]['url'] not in hearted:
|
if values[c - 1]['url'] not in hearted:
|
||||||
|
@ -990,10 +986,8 @@ class MsG:
|
||||||
|
|
||||||
while not self.bot.is_closed():
|
while not self.bot.is_closed():
|
||||||
try:
|
try:
|
||||||
done, pending = await asyncio.wait([self.bot.wait_for('reaction_add', check=on_reaction, timeout=10 * 60),
|
await asyncio.gather(*[self.bot.wait_for('reaction_add', check=on_reaction, timeout=10 * 60),
|
||||||
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=10 * 60)], return_when=asyncio.FIRST_COMPLETED)
|
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=10 * 60)])
|
||||||
for future in done:
|
|
||||||
future.result()
|
|
||||||
|
|
||||||
except exc.Save:
|
except exc.Save:
|
||||||
if values[c - 1]['url'] not in hearted:
|
if values[c - 1]['url'] not in hearted:
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import traceback as tb
|
import traceback as tb
|
||||||
from contextlib import suppress
|
from contextlib import redirect_stdout, suppress
|
||||||
|
|
||||||
import discord as d
|
import discord as d
|
||||||
import pyrasite as pyr
|
import pyrasite as pyr
|
||||||
|
@ -120,20 +120,19 @@ 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.startswith('exe') and msg.author is ctx.author and msg.channel is ctx.channel:
|
if msg.content.lower().startswith('exec ') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
results.cancel()
|
msg.content = msg.content[5:]
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def evaluate(msg):
|
def evaluate(msg):
|
||||||
if msg.content.startswith('eval') and msg.author is ctx.author and msg.channel is ctx.channel:
|
if msg.content.lower().startswith('eval ') and msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
results.cancel()
|
msg.content = msg.content[5:]
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def exit(reaction, user):
|
def exit(reaction, user):
|
||||||
if reaction.emoji == '\N{LEFTWARDS ARROW WITH HOOK}' and user is ctx.author and reaction.message.id == ctx.message.id:
|
if reaction.emoji == '\N{OCTAGONAL SIGN}' and user is ctx.author and reaction.message.id == ctx.message.id:
|
||||||
results.cancel()
|
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -141,43 +140,46 @@ class Tools:
|
||||||
console = await self.generate(ctx)
|
console = await self.generate(ctx)
|
||||||
exception = await self.generate_err(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():
|
while not self.bot.is_closed():
|
||||||
try:
|
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)
|
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)
|
||||||
print(results)
|
|
||||||
|
message = done.pop().result()
|
||||||
|
print(message.content)
|
||||||
|
|
||||||
except exc.Execute:
|
except exc.Execute:
|
||||||
try:
|
try:
|
||||||
sys.stdout = io.StringIO()
|
sys.stdout = io.StringIO()
|
||||||
sys.stderr = io.StringIO()
|
sys.stderr = io.StringIO()
|
||||||
exec(exe.content)
|
exec(message.content)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
await self.refresh_err(exception, tb.format_exc(limit=1))
|
await self.refresh_err(exception, tb.format_exc(limit=1))
|
||||||
|
|
||||||
finally:
|
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.stdout = sys.__stdout__
|
||||||
sys.stderr = sys.__stderr__
|
sys.stderr = sys.__stderr__
|
||||||
|
with suppress(d.NotFound):
|
||||||
|
await message.delete()
|
||||||
|
|
||||||
except exc.Evaluate:
|
except exc.Evaluate:
|
||||||
try:
|
try:
|
||||||
sys.stdout = io.StringIO()
|
sys.stdout = io.StringIO()
|
||||||
sys.stderr = io.StringIO()
|
sys.stderr = io.StringIO()
|
||||||
eval(exe.content)
|
eval(message.content)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
await self.refresh_err(exception, tb.format_exc(limit=1))
|
await self.refresh_err(exception, tb.format_exc(limit=1))
|
||||||
|
|
||||||
finally:
|
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.stdout = sys.__stdout__
|
||||||
sys.stderr = sys.__stderr__
|
sys.stderr = sys.__stderr__
|
||||||
|
|
||||||
finally:
|
|
||||||
with suppress(d.NotFound):
|
with suppress(d.NotFound):
|
||||||
await exe.delete()
|
await message.delete()
|
||||||
|
|
||||||
except exc.Abort:
|
except exc.Abort:
|
||||||
pass
|
pass
|
||||||
|
@ -189,19 +191,34 @@ class Tools:
|
||||||
|
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
@commands.command(name='arbitrary', aliases=[',arbit', ',ar'], hidden=True)
|
@commands.command(name=',execute', aliases=[',exec'], hidden=True)
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def arbitrary(self, ctx, *, exe):
|
async def execute(self, ctx, *, exe):
|
||||||
try:
|
try:
|
||||||
sys.stdout = io.StringIO()
|
with io.StringIO() as buff, redirect_stdout(buff):
|
||||||
exec(exe)
|
exec(exe)
|
||||||
await self.generate(ctx, exe, sys.stdout.getvalue())
|
await self.generate(ctx, exe, buff.getvalue())
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
await ctx.send('```\n{}```'.format(tb.format_exc(limit=1)))
|
await ctx.send('```\n{}```'.format(tb.format_exc()))
|
||||||
|
|
||||||
|
finally:
|
||||||
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
|
@commands.command(name=',evaluate', aliases=[',eval'], hidden=True)
|
||||||
|
@commands.is_owner()
|
||||||
|
@checks.del_ctx()
|
||||||
|
async def evaluate(self, ctx, *, evl):
|
||||||
|
try:
|
||||||
|
with io.StringIO() as buff, redirect_stdout(buff):
|
||||||
|
eval(evl)
|
||||||
|
await self.generate(ctx, evl, buff.getvalue())
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
await ctx.send('```\n{}```'.format(tb.format_exc()))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = sys.__stdout__
|
|
||||||
print('Reset stdout.')
|
|
||||||
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
||||||
|
|
||||||
@commands.group(aliases=[',db'], hidden=True)
|
@commands.group(aliases=[',db'], hidden=True)
|
||||||
|
|
Loading…
Reference in a new issue