From 5db0ea9ee0d40eddce343810b9c047fed24d6a2a Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 20:54:36 +0100 Subject: [PATCH] Debugged --- code/code.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/code/code.py b/code/code.py index a313740..4b33018 100644 --- a/code/code.py +++ b/code/code.py @@ -39,13 +39,18 @@ async def setup(ctx, channel: discord.TextChannel, api_key): return #check if the guild is already in the database bi checking if there is a key for the guild c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) - if c.fetchone()[2] is not None: - await ctx.respond("This guild is already setup", ephemeral=True) - return - #add the guild to the database - c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 150, 1, 0, 0.6, 0, 5)) - conn.commit() - await ctx.respond("Setup complete", ephemeral=True) + if c.fetchone() is not None: + #in this case, the guild is already in the database, so we update the channel id and the api key + c.execute("UPDATE data SET channel_id = ?, api_key = ? WHERE guild_id = ?", (channel.id, api_key, ctx.guild.id)) + #we will also set the advanced settings to their default values + c.execute("UPDATE data SET is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, uses_count_today = ?, prompt_size = ? WHERE guild_id = ?", (False, 64, 0.9, 0.0, 0.0, 0, 5, ctx.guild.id)) + conn.commit() + await ctx.respond("The channel id and the api key have been updated", ephemeral=True) + else: + #in this case, the guild is not in the database, so we add it + c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 64, 0.9, 0.0, 0.0, 0, 5)) + conn.commit() + await ctx.respond("The channel id and the api key have been added", ephemeral=True) #create a command called "enable" taht only admins can use @bot.command() ##@discord.commands.permissions(administrator=True)