mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 06:37:29 +00:00
Added exec/eval commands and contextlib.redirect_stdout shortcut
This commit is contained in:
parent
172ae8f082
commit
1ccc1a10cc
1 changed files with 23 additions and 8 deletions
|
@ -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
|
||||||
|
@ -189,19 +189,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