refactoring, userdata module

This commit is contained in:
2021-02-09 17:17:19 +00:00
parent 8f25254204
commit 7b11e95542
6 changed files with 282 additions and 166 deletions
+12 -7
View File
@@ -6,14 +6,15 @@ from discord.ext import commands
import util
def setup(bot):
@bot.group()
@bot.group(help="Debug/random messing around utilities. Owner-only.")
@commands.check(util.admin_check)
async def magic(ctx):
if ctx.invoked_subcommand == None:
return await ctx.send("Invalid magic command.")
@magic.command(rest_is_raw=True)
@magic.command(rest_is_raw=True, brief="Execute Python.")
async def py(ctx, *, code):
"Executes Python. You may supply a codeblock. Comments in the form #timeout:([0-9]+) will be used as a timeout specifier. React with :x: to stop, probably."
timeout = 5.0
timeout_match = re.search("#timeout:([0-9]+)", code, re.IGNORECASE)
if timeout_match:
@@ -49,8 +50,9 @@ def setup(bot):
except BaseException as e:
await ctx.send(embed=util.error_embed(util.gen_codeblock(traceback.format_exc())))
@magic.command(rest_is_raw=True)
@magic.command(rest_is_raw=True, help="Execute SQL code against the database.")
async def sql(ctx, *, code):
"Executes SQL (and commits). You may use a codeblock, similarly to with py."
code = util.extract_codeblock(code)
try:
csr = bot.database.execute(code)
@@ -63,11 +65,14 @@ def setup(bot):
except Exception as e:
await ctx.send(embed=util.error_embed(util.gen_codeblock(traceback.format_exc())))
@magic.command()
@magic.command(help="Reload configuration file.")
async def reload_config(ctx):
util.load_config()
ctx.send("Done!")
@magic.command()
async def reload_ext(ctx):
for ext in util.extensions: bot.reload_extension(ext)
@magic.command(help="Reload extensions (all or the specified one).")
async def reload_ext(ctx, ext="all"):
if ext == "all":
for ext in util.extensions: bot.reload_extension(ext)
else: bot.reload_extension(ext)
await ctx.send("Done!")