From c4fdf3d17a9ebcdcd39d1d0d5de2fd209dc61457 Mon Sep 17 00:00:00 2001 From: osmarks Date: Wed, 25 Nov 2020 19:04:10 +0000 Subject: [PATCH] config reload command --- src/debug.py | 7 ++++++- src/util.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/debug.py b/src/debug.py index 7b03d87..a479932 100644 --- a/src/debug.py +++ b/src/debug.py @@ -46,4 +46,9 @@ def setup(bot): await ctx.send(util.gen_codeblock(out)) await bot.database.commit() except Exception as e: - await ctx.send(embed=util.error_embed(util.gen_codeblock(traceback.format_exc()))) \ No newline at end of file + await ctx.send(embed=util.error_embed(util.gen_codeblock(traceback.format_exc()))) + + @magic.command() + async def reload_config(ctx): + util.load_config() + ctx.send("Done!") \ No newline at end of file diff --git a/src/util.py b/src/util.py index 4affd65..e0a6f5d 100644 --- a/src/util.py +++ b/src/util.py @@ -12,7 +12,13 @@ import os.path from discord.ext import commands import hashlib -config = toml.load(open("config.toml", "r")) +config = {} + +# update in place for runtime config reload +def load_config(): + for k, v in toml.load(open("config.toml", "r")).items(): config[k] = v + +load_config() def timestamp(): return int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())