From 21b4eee3dc78ea72bc8ac003b68e70238d8052dd Mon Sep 17 00:00:00 2001 From: Marco Loewe Date: Tue, 14 Nov 2023 12:28:05 +0100 Subject: [PATCH] Update mechanism should return appropriate messages now --- bot.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index df0debc..b727cda 100644 --- a/bot.py +++ b/bot.py @@ -26,6 +26,10 @@ async def on_ready(): await tree.sync(guild=discord.Object(id='745287426402156555')) print(f'Logged in as {client.user}') print('------') + if data['update'] & data['update'] == 'pending': + client.get_channel(1173561093579362305).send('Update done') + write_json('update', 'none') + @tree.command(name = 'cool', description = 'Check how cool you are!', guild=discord.Object(id='745287426402156555')) async def cool(ctx: discord.Interaction): @@ -36,8 +40,8 @@ async def cool(ctx: discord.Interaction): @app_commands.checks.has_role(745295653651087381) async def update(ctx: discord.Interaction): await ctx.response.send_message('Updating, see you on the other side') + write_json('update', 'pending') subprocess.run('./update.sh') - await ctx.response.send_message('Done') @update.error async def update_error(ctx: discord.Interaction, error): @@ -45,4 +49,14 @@ async def update_error(ctx: discord.Interaction, error): text = "Sorry {}, you do not have permissions to do that!".format(ctx.user) await ctx.response.send_message(text) +def write_json(key: str, value: any): + data[key] = value + + if exists('config.local.json'): + with open('config.local.json') as f: + f.write(json.dumps(data)) + elif exists('config.json'): + with open('config.json') as f: + f.write(json.dumps(data)) + client.run(data['token']) \ No newline at end of file