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 :)
This commit is contained in:
parent
d2939b8dee
commit
83cbd44204
1 changed files with 5 additions and 7 deletions
10
bot.py
10
bot.py
|
@ -15,12 +15,10 @@ class Bot(commands.Bot):
|
||||||
self.db_con = sqlite3.connect(DB_PATH)
|
self.db_con = sqlite3.connect(DB_PATH)
|
||||||
self.db_cur = self.db_con.cursor()
|
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 IF NOT EXISTS custom_commands(command TEXT, output_text TEXT, author TEXT)")
|
||||||
self.db_cur.execute("CREATE TABLE custom_commands(command, output_text)")
|
|
||||||
print("Created database table")
|
print("Created database table")
|
||||||
else:
|
commands = self.db_cur.execute("SELECT count(*) FROM custom_commands").fetchone()
|
||||||
commands = self.db_cur.execute("SELECT * FROM custom_commands").fetchall()
|
print(f"{commands[0]} custom commands available")
|
||||||
print(f"{len(commands)} custom commands available")
|
|
||||||
|
|
||||||
async def event_ready(self):
|
async def event_ready(self):
|
||||||
print(f"Logged in as | {self.nick}")
|
print(f"Logged in as | {self.nick}")
|
||||||
|
@ -82,7 +80,7 @@ class Bot(commands.Bot):
|
||||||
await ctx.send("lmao that command already exists")
|
await ctx.send("lmao that command already exists")
|
||||||
return
|
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()
|
self.db_con.commit()
|
||||||
await ctx.send(f"Adding command: \"{PREFIX}{command_name}\" -> \"{command_text}\"")
|
await ctx.send(f"Adding command: \"{PREFIX}{command_name}\" -> \"{command_text}\"")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue