From 3688334de786377f4e6534af60fbf6a3640b5a02 Mon Sep 17 00:00:00 2001 From: Anorak_1 Date: Sun, 20 Aug 2023 12:55:37 +0200 Subject: [PATCH] updated add application, fixed delete action --- dbutil.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/dbutil.py b/dbutil.py index 9c14703..3776184 100644 --- a/dbutil.py +++ b/dbutil.py @@ -7,19 +7,19 @@ from action import Action, ActionInteraction class MessageDB(): - def add_application_msg(msg_id: str, author_id: str, guild_id: str) -> None: - data = (msg_id, author_id, guild_id) + def add_application_msg(msg_id: str, author_id: str, guild_id: str, app_name: str) -> None: + data = (msg_id, author_id, guild_id, app_name) con = sqlite3.connect("applications.db") cur = con.cursor() - cur.execute("INSERT INTO app_msg_db VALUES (?, ?, ?)", data) + cur.execute("INSERT INTO app_msg_db VALUES (?, ?, ?, ?)", data) con.commit() def get_application_msg(msg_id: str) -> tuple[str, str]: con = sqlite3.connect("applications.db") cur = con.cursor() - cur.execute(f"SELECT user_id, guild_id FROM app_msg_db WHERE msg_id={msg_id}") - user_id, guild_id = cur.fetchone() - return user_id, guild_id + cur.execute(f"SELECT user_id, guild_id, app_name FROM app_msg_db WHERE msg_id={msg_id}") + user_id, guild_id, app_name = cur.fetchone() + return user_id, guild_id, app_name def remove_application_msg(msg_id: str) -> None: con = sqlite3.connect("applications.db") @@ -278,7 +278,7 @@ class GuildAppDB(): else: return "error on get actions: application not found" - def remove_action(guild_id: str, application_name: str, action_index: int): + def remove_action(guild_id: str, application_name: str, action_type: ActionInteraction, action_index: int): con = sqlite3.connect("applications.db") cur = con.cursor() cur.execute("SELECT applications_blob FROM app_guildapp_db WHERE guild_id=(?)", (guild_id, )) @@ -286,9 +286,21 @@ class GuildAppDB(): applications = pickle.loads(application_blob[0]) if application_name in applications.keys(): actions = applications[application_name]["actions"] - if action_index <= len(actions): - actions.pop(action_index-1) - applications[application_name]["actions"] = actions + actedit = [] + actnoedit = [] + for i in actions: + if i["result"] == action_type: + actedit.append(i) + else: + actnoedit.append(i) + actedit + if action_index <= len(actedit): + actedit.pop(action_index-1) + + for x in actedit: + actnoedit.append(x) + + applications[application_name]["actions"] = actnoedit application_blob2 = pickle.dumps(applications) cur.execute("UPDATE app_guildapp_db SET applications_blob = (?) WHERE guild_id= (?)", (application_blob2, guild_id)) con.commit()