add exec command
This commit is contained in:
parent
22e897ff67
commit
24574002d5
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ class Utility(commands.Cog):
|
|||||||
|
|
||||||
@commands.command(name='eval', hidden=True)
|
@commands.command(name='eval', hidden=True)
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def eval_cmd(self, ctx, *, body: str):
|
async def eval_cmd(self, ctx: commands.Context, *, body: str):
|
||||||
env = {
|
env = {
|
||||||
'bot': self.bot,
|
'bot': self.bot,
|
||||||
'ctx': ctx,
|
'ctx': ctx,
|
||||||
@ -51,6 +52,38 @@ class Utility(commands.Cog):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.send(f'```{e.__class__.__name__}: {e}\n```')
|
await ctx.send(f'```{e.__class__.__name__}: {e}\n```')
|
||||||
|
|
||||||
|
@commands.command(name='exec', hidden=True)
|
||||||
|
@commands.is_owner()
|
||||||
|
async def exec_cmd(self, ctx: commands.Context, *, body: str):
|
||||||
|
env = {
|
||||||
|
'bot': self.bot,
|
||||||
|
'ctx': ctx,
|
||||||
|
'assets': self.bot.assets,
|
||||||
|
'asset_filters': self.bot.asset_filters,
|
||||||
|
**globals(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if body and body[:9] == '```python' and body[-3:] == '```':
|
||||||
|
body = body[9:-3]
|
||||||
|
if body and body[:3] == '```' and body[-3:] == '```':
|
||||||
|
body = body[3:-3]
|
||||||
|
if body and body[:1] == '`' and body[-1:] == '`':
|
||||||
|
body = body[1:-1]
|
||||||
|
|
||||||
|
body = 'async def f():\n' + textwrap.indent(body, ' ')
|
||||||
|
l = locals()
|
||||||
|
exec(body, env, l)
|
||||||
|
f = l['f']
|
||||||
|
|
||||||
|
try:
|
||||||
|
value = await f()
|
||||||
|
if value:
|
||||||
|
await ctx.send(str(value))
|
||||||
|
else:
|
||||||
|
await ctx.send('Done')
|
||||||
|
except Exception as e:
|
||||||
|
await ctx.send(f'```{e.__class__.__name__}: {e}\n```')
|
||||||
|
|
||||||
@commands.command(name='invite',
|
@commands.command(name='invite',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
description='Sends the bot invite.',
|
description='Sends the bot invite.',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user