implement sql eval command
This commit is contained in:
parent
a5a6312403
commit
8eee98aa13
1 changed files with 29 additions and 5 deletions
|
@ -7,7 +7,7 @@ import textwrap
|
|||
import traceback
|
||||
from contextlib import redirect_stdout
|
||||
|
||||
from disnake import Embed, Guild, Intents, Message
|
||||
from disnake import Embed, Guild, Intents, Message, Thread
|
||||
from disnake.ext import commands
|
||||
from disnake.ext.commands import Bot, Paginator
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
|
@ -199,16 +199,40 @@ async def echo(ctx, arg):
|
|||
@commands.is_owner()
|
||||
async def sql(ctx, *, query):
|
||||
params = {
|
||||
"guild_id": ctx.guild.id,
|
||||
"author": ctx.author.id,
|
||||
"channel": ctx.channel.id,
|
||||
"category": ctx.channel.category_id,
|
||||
"guild": ctx.guild.id,
|
||||
"parent": 0,
|
||||
}
|
||||
|
||||
if isinstance(ctx.channel, Thread) and ctx.channel.parent:
|
||||
params["parent"] = ctx.channel.parent.id
|
||||
|
||||
query = cleanup_code(query)
|
||||
|
||||
cur = await ctx.bot.db.execute(query)
|
||||
try:
|
||||
ret = await ctx.bot.db.execute_fetchall(query, params)
|
||||
except Exception:
|
||||
ret = traceback.format_exc()
|
||||
try:
|
||||
await ctx.message.add_reaction("\u2705")
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
await ctx.message.add_reaction("\u2705")
|
||||
except:
|
||||
pass
|
||||
|
||||
result = await cur.fetchall()
|
||||
paginator = Paginator(prefix="```py", suffix="```")
|
||||
if ret:
|
||||
for line in pprint.pformat(ret).split("\n"):
|
||||
paginator.add_line(line)
|
||||
paginator.close_page()
|
||||
|
||||
# TODO: Finish SQL evaluation command
|
||||
for page in paginator.pages:
|
||||
await ctx.send(page)
|
||||
|
||||
|
||||
@bot.command(hidden=True, name="eval")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue