updated add application, fixed delete action
parent
692541718a
commit
3688334de7
32
dbutil.py
32
dbutil.py
|
@ -7,19 +7,19 @@ from action import Action, ActionInteraction
|
||||||
|
|
||||||
|
|
||||||
class MessageDB():
|
class MessageDB():
|
||||||
def add_application_msg(msg_id: str, author_id: str, guild_id: str) -> None:
|
def add_application_msg(msg_id: str, author_id: str, guild_id: str, app_name: str) -> None:
|
||||||
data = (msg_id, author_id, guild_id)
|
data = (msg_id, author_id, guild_id, app_name)
|
||||||
con = sqlite3.connect("applications.db")
|
con = sqlite3.connect("applications.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("INSERT INTO app_msg_db VALUES (?, ?, ?)", data)
|
cur.execute("INSERT INTO app_msg_db VALUES (?, ?, ?, ?)", data)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
def get_application_msg(msg_id: str) -> tuple[str, str]:
|
def get_application_msg(msg_id: str) -> tuple[str, str]:
|
||||||
con = sqlite3.connect("applications.db")
|
con = sqlite3.connect("applications.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute(f"SELECT user_id, guild_id FROM app_msg_db WHERE msg_id={msg_id}")
|
cur.execute(f"SELECT user_id, guild_id, app_name FROM app_msg_db WHERE msg_id={msg_id}")
|
||||||
user_id, guild_id = cur.fetchone()
|
user_id, guild_id, app_name = cur.fetchone()
|
||||||
return user_id, guild_id
|
return user_id, guild_id, app_name
|
||||||
|
|
||||||
def remove_application_msg(msg_id: str) -> None:
|
def remove_application_msg(msg_id: str) -> None:
|
||||||
con = sqlite3.connect("applications.db")
|
con = sqlite3.connect("applications.db")
|
||||||
|
@ -278,7 +278,7 @@ class GuildAppDB():
|
||||||
else:
|
else:
|
||||||
return "error on get actions: application not found"
|
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")
|
con = sqlite3.connect("applications.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("SELECT applications_blob FROM app_guildapp_db WHERE guild_id=(?)", (guild_id, ))
|
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])
|
applications = pickle.loads(application_blob[0])
|
||||||
if application_name in applications.keys():
|
if application_name in applications.keys():
|
||||||
actions = applications[application_name]["actions"]
|
actions = applications[application_name]["actions"]
|
||||||
if action_index <= len(actions):
|
actedit = []
|
||||||
actions.pop(action_index-1)
|
actnoedit = []
|
||||||
applications[application_name]["actions"] = actions
|
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)
|
application_blob2 = pickle.dumps(applications)
|
||||||
cur.execute("UPDATE app_guildapp_db SET applications_blob = (?) WHERE guild_id= (?)", (application_blob2, guild_id))
|
cur.execute("UPDATE app_guildapp_db SET applications_blob = (?) WHERE guild_id= (?)", (application_blob2, guild_id))
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
Loading…
Reference in New Issue