From 7fab14a81f269a7e4d096c54014236c6bcbbb094 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 24 Aug 2023 13:31:56 +1000 Subject: [PATCH] bot: Added optional free mode and parse list workers --- discord-bot/bot.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index ea841b5..6214cd2 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -12,6 +12,10 @@ Master_Port = os.getenv('MASTER_PORT') if Master_Port == None: Master_Port = "5000" +FREE_LICENCE = os.getenv('FREE_LICENCE') +if FREE_LICENCE == None: + FREE_LICENCE = False + intents = discord.Intents.default() client = discord.Client(intents=intents) tree = app_commands.CommandTree(client) @@ -32,6 +36,11 @@ async def listworkers(ctx): if ctx.user.id == ADMINID: r = requests.get(f"http://{Master_IP}:{Master_Port}/list-workers",headers={"key":os.getenv('WORKER_KEY')}) if r.status_code == 200: + json = r.json() + if json['success'] == "true": + await ctx.response.send_message(json['workers'],ephemeral=True) + else: + await ctx.response.send_message(f"Error listing workers\n" + json['error'],ephemeral=True) await ctx.response.send_message(r.text,ephemeral=True) else: await ctx.response.send_message(f"Error listing workers\n" + r.text,ephemeral=True) @@ -40,10 +49,11 @@ async def listworkers(ctx): @tree.command(name="licence", description="Gets a licence key") async def license(ctx): - if ctx.user.id != ADMINID: - await ctx.response.send_message("You do not have permission to use this command",ephemeral=True) - return - + if ctx.user.id != ADMINID: + if FREE_LICENCE == False: # If free licences are enabled then anyone can get a licence + await ctx.response.send_message("You do not have permission to use this command",ephemeral=True) + return + r = requests.get(f"http://{Master_IP}:{Master_Port}/add-licence",headers={"key":os.getenv('LICENCE_KEY')}) if r.status_code == 200: await ctx.response.send_message(r.text,ephemeral=True)