From 83cbd44204376507ec685b03e672cf534223ec31 Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Mon, 19 Sep 2022 00:04:55 -0400 Subject: [PATCH] Store author when creating command NOTE: This is not compatible with the previous db schema since I've added a new column. I don't feel like adding in any compatibility code (yet) so you gotta update that yourself for now :) --- bot.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 6ebfdb0..c0885dd 100644 --- a/bot.py +++ b/bot.py @@ -15,12 +15,10 @@ class Bot(commands.Bot): self.db_con = sqlite3.connect(DB_PATH) self.db_cur = self.db_con.cursor() - if self.db_cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='custom_commands'").fetchone() == None: - self.db_cur.execute("CREATE TABLE custom_commands(command, output_text)") - print("Created database table") - else: - commands = self.db_cur.execute("SELECT * FROM custom_commands").fetchall() - print(f"{len(commands)} custom commands available") + self.db_cur.execute("CREATE TABLE IF NOT EXISTS custom_commands(command TEXT, output_text TEXT, author TEXT)") + print("Created database table") + commands = self.db_cur.execute("SELECT count(*) FROM custom_commands").fetchone() + print(f"{commands[0]} custom commands available") async def event_ready(self): print(f"Logged in as | {self.nick}") @@ -82,7 +80,7 @@ class Bot(commands.Bot): await ctx.send("lmao that command already exists") return - self.db_cur.execute("INSERT INTO custom_commands VALUES (?, ?)", [command_name, command_text]) + self.db_cur.execute("INSERT INTO custom_commands VALUES (?, ?, ?)", [command_name, command_text, ctx.author.name]) self.db_con.commit() await ctx.send(f"Adding command: \"{PREFIX}{command_name}\" -> \"{command_text}\"")