Compare commits
No commits in common. "ae6a9053e366518b8a67ea2158406c85afaa2dad" and "4429753729f91e2bea6601508ed93b9552847db0" have entirely different histories.
ae6a9053e3
...
4429753729
23
action.py
23
action.py
|
@ -1,23 +0,0 @@
|
||||||
from typing import Any, TypeVar, NewType
|
|
||||||
from enum import Enum
|
|
||||||
import discord
|
|
||||||
|
|
||||||
AT = TypeVar("AT", bound="Action")
|
|
||||||
|
|
||||||
class ActionInteraction(Enum):
|
|
||||||
ACCEPT = "accept"
|
|
||||||
DECLINE = "decline"
|
|
||||||
|
|
||||||
class Action():
|
|
||||||
def __init__(self, action: ActionInteraction):
|
|
||||||
self.set_type = None
|
|
||||||
self.app_result = action
|
|
||||||
|
|
||||||
def add_role(self, role: discord.Role):
|
|
||||||
if self.set_type is None:
|
|
||||||
self.set_type = "add_role"
|
|
||||||
self.add_role_value = role
|
|
||||||
else:
|
|
||||||
raise ValueError("Action object already set type")
|
|
||||||
|
|
||||||
|
|
3
bot.py
3
bot.py
|
@ -12,9 +12,6 @@ from dbutil import MessageDB
|
||||||
from dbutil import StartButtonDB
|
from dbutil import StartButtonDB
|
||||||
from dbutil import GuildAppDB
|
from dbutil import GuildAppDB
|
||||||
|
|
||||||
from action import Action, ActionInteraction
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
TOKEN = os.getenv("TOKEN")
|
TOKEN = os.getenv("TOKEN")
|
||||||
|
|
59
dbutil.py
59
dbutil.py
|
@ -3,8 +3,6 @@ import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
from action import Action
|
|
||||||
|
|
||||||
|
|
||||||
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) -> None:
|
||||||
|
@ -83,8 +81,7 @@ class GuildAppDB():
|
||||||
applications[application_name] = {
|
applications[application_name] = {
|
||||||
"app_id": "",
|
"app_id": "",
|
||||||
"resp_channel": "",
|
"resp_channel": "",
|
||||||
"questions": [],
|
"questions": []
|
||||||
"actions": []
|
|
||||||
}
|
}
|
||||||
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))
|
||||||
|
@ -242,56 +239,4 @@ class GuildAppDB():
|
||||||
else:
|
else:
|
||||||
return "error on remove question: question index not found"
|
return "error on remove question: question index not found"
|
||||||
else:
|
else:
|
||||||
return "error on remove question: application not found"
|
return "error on remove question: application not found"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_action(guild_id: str, application_name: str, action: Action) -> str:
|
|
||||||
con = sqlite3.connect("applications.db")
|
|
||||||
cur = con.cursor()
|
|
||||||
cur.execute("SELECT applications_blob FROM app_guildapp_db WHERE guild_id=(?)", (guild_id, ))
|
|
||||||
application_blob = cur.fetchone()
|
|
||||||
applications = pickle.loads(application_blob[0])
|
|
||||||
if application_name in applications.keys():
|
|
||||||
action_index = int(len(applications[application_name]["actions"]))
|
|
||||||
applications[application_name]["actions"].append(action)
|
|
||||||
application_blob2 = pickle.dumps(applications)
|
|
||||||
cur.execute("UPDATE app_guildapp_db SET applications_blob = (?) WHERE guild_id= (?)", (application_blob2, guild_id))
|
|
||||||
con.commit()
|
|
||||||
return "success"
|
|
||||||
else:
|
|
||||||
return "error on add action: application not found"
|
|
||||||
|
|
||||||
def get_actions(guild_id: str, application_name: str):
|
|
||||||
con = sqlite3.connect("applications.db")
|
|
||||||
cur = con.cursor()
|
|
||||||
cur.execute("SELECT applications_blob FROM app_guildapp_db WHERE guild_id=(?)", (guild_id, ))
|
|
||||||
application_blob = cur.fetchone()
|
|
||||||
applications = pickle.loads(application_blob[0])
|
|
||||||
if application_name in applications.keys():
|
|
||||||
actions = applications[application_name]["actions"]
|
|
||||||
return actions
|
|
||||||
else:
|
|
||||||
return "error on get actions: application not found"
|
|
||||||
|
|
||||||
def remove_action(guild_id: str, application_name: str, 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, ))
|
|
||||||
application_blob = cur.fetchone()
|
|
||||||
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
|
|
||||||
application_blob2 = pickle.dumps(applications)
|
|
||||||
cur.execute("UPDATE app_guildapp_db SET applications_blob = (?) WHERE guild_id= (?)", (application_blob2, guild_id))
|
|
||||||
con.commit()
|
|
||||||
return "success"
|
|
||||||
else:
|
|
||||||
return "error on remove action: action index not found"
|
|
||||||
else:
|
|
||||||
return "error on remove action: application not found"
|
|
||||||
|
|
27
scheme.py
27
scheme.py
|
@ -1,27 +0,0 @@
|
||||||
#applications.db -> app_guildapp_db -> applications_blob
|
|
||||||
from action import Action, ActionInteraction
|
|
||||||
|
|
||||||
application_name: {
|
|
||||||
"app_id": "", # basically useless but hey its there
|
|
||||||
"resp_channel": "",
|
|
||||||
"questions": [],
|
|
||||||
"actions": {
|
|
||||||
"action_name": Action(ActionInteraction.ACCEPT).add_role(),
|
|
||||||
"action_name2": Action(ActionInteraction.DECLINE),
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
application_name: {
|
|
||||||
"app_id": "", # basically useless but hey its there
|
|
||||||
"resp_channel": "",
|
|
||||||
"questions": [],
|
|
||||||
"actions": {
|
|
||||||
"action_name": {
|
|
||||||
"action_type": "action_type",
|
|
||||||
},
|
|
||||||
"action_name2": Action()
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue