Compare commits
3 Commits
784fd08f58
...
f2a18207de
Author | SHA1 | Date |
---|---|---|
Anorak_1 | f2a18207de | |
Anorak_1 | 3688334de7 | |
Anorak_1 | 692541718a |
48
bot.py
48
bot.py
|
@ -383,7 +383,11 @@ class ActionAcceptEditorView(discord.ui.View):
|
|||
actions = GuildAppDB.get_actions(str(interaction.guild.id), self.application_name, action_type=ActionInteraction.ACCEPT)
|
||||
options.set_action_type(ActionInteraction.ACCEPT)
|
||||
for i, que in enumerate(actions):
|
||||
options.add_option(label=f"{str(i+1)}. {que}", value=str(i))
|
||||
if que["action_type"] == "add_role":
|
||||
role = interaction.guild.get_role(que["data"]["role_id"]).name
|
||||
options.add_option(label=f"{str(i+1)}. {que['display_type']}: {role}", value=str(i))
|
||||
else:
|
||||
options.add_option(label=f"{str(i+1)}. {que['display_type']}", value=str(i))
|
||||
view.add_item(options)
|
||||
await interaction.response.edit_message(view=view)
|
||||
|
||||
|
@ -422,7 +426,11 @@ class ActionDeclineEditorView(discord.ui.View):
|
|||
actions = GuildAppDB.get_actions(str(interaction.guild.id), self.application_name, action_type=ActionInteraction.DECLINE)
|
||||
options.set_action_type(ActionInteraction.DECLINE)
|
||||
for i, que in enumerate(actions):
|
||||
options.add_option(label=f"{str(i+1)}. {que}", value=str(i))
|
||||
if que["action_type"] == "add_role":
|
||||
role = interaction.guild.get_role(que["data"]["role_id"]).name
|
||||
options.add_option(label=f"{str(i+1)}. {que['display_type']}: {role}", value=str(i))
|
||||
else:
|
||||
options.add_option(label=f"{str(i+1)}. {que['display_type']}", value=str(i))
|
||||
view.add_item(options)
|
||||
await interaction.response.edit_message(view=view)
|
||||
|
||||
|
@ -474,7 +482,7 @@ class RemoveActionSelect(discord.ui.Select):
|
|||
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
self.disabled = True
|
||||
GuildAppDB.remove_action(str(interaction.guild.id), self.app_name, int(self.values[0])+1)
|
||||
GuildAppDB.remove_action(str(interaction.guild.id), self.app_name, self.action_type, int(self.values[0])+1)
|
||||
if self.action_type == ActionInteraction.ACCEPT:
|
||||
editor = ActionAcceptEditorView(str(interaction.guild.id), self.app_name)
|
||||
embed = get_actions_embed(str(interaction.guild.id), self.app_name, ActionInteraction.ACCEPT)
|
||||
|
@ -580,7 +588,7 @@ class ApplicationStartButtonView(discord.ui.View):
|
|||
|
||||
msg = await channel.send(embed=embed, view=appView)
|
||||
|
||||
MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.id)
|
||||
MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.id, app_name)
|
||||
|
||||
await user.send('Thank you for applying!')
|
||||
|
||||
|
@ -598,7 +606,7 @@ class ApplicationButtonsView(discord.ui.View):
|
|||
async def accept(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||
msg_id = str(interaction.message.id)
|
||||
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_id)
|
||||
user_id, guild_id, app_name = MessageDB.get_application_msg(msg_id)
|
||||
|
||||
modal = ApplicationModal(title=f"Accepting: {bot.get_user(user_id).display_name}")
|
||||
modal.set_action("acc")
|
||||
|
@ -613,7 +621,7 @@ class ApplicationButtonsView(discord.ui.View):
|
|||
async def decline(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||
msg_id = str(interaction.message.id)
|
||||
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_id)
|
||||
user_id, guild_id, app_name = MessageDB.get_application_msg(msg_id)
|
||||
|
||||
modal = ApplicationModal(title=f"Declining: {bot.get_user(user_id).display_name}")
|
||||
modal.set_action("dec")
|
||||
|
@ -629,13 +637,26 @@ class ApplicationModal(discord.ui.Modal):
|
|||
async def callback(self, interaction: discord.Interaction):
|
||||
reason = self.children[0].value
|
||||
msg_id = str(interaction.message.id)
|
||||
user_id, guild_id = MessageDB.get_application_msg(msg_id)
|
||||
user_id, guild_id, app_name = MessageDB.get_application_msg(msg_id)
|
||||
if self.action == "acc":
|
||||
user = await bot.get_user(user_id).create_dm()
|
||||
await user.send(f"Your application has been accepted!")
|
||||
await user.send(f"Reason: {reason}")
|
||||
await interaction.response.send_message(content="Application accepted", ephemeral=True)
|
||||
|
||||
role = get(interaction.message.guild.roles, name="CreatTopian")
|
||||
|
||||
actions = GuildAppDB.get_actions(str(guild_id), app_name, ActionInteraction.ACCEPT)
|
||||
for i in actions:
|
||||
if i["action_type"] == "add_role":
|
||||
role = interaction.message.guild.get_role(int(i["data"]["role_id"]))
|
||||
user = interaction.message.guild.get_member(int(user_id))
|
||||
await user.add_roles(role)
|
||||
else:
|
||||
print("unknown action")
|
||||
|
||||
|
||||
|
||||
#await discord.utils.get(interaction.message.guild.members, id=int(user_id)).add_roles(role)
|
||||
emb = interaction.message.embeds[0]
|
||||
emb.colour = discord.Colour.green()
|
||||
|
@ -646,11 +667,24 @@ class ApplicationModal(discord.ui.Modal):
|
|||
view = discord.ui.View.from_message(interaction.message)
|
||||
view.disable_all_items()
|
||||
await interaction.followup.edit_message(message_id = interaction.message.id, view = view)
|
||||
|
||||
|
||||
if self.action == "dec":
|
||||
user = await bot.get_user(user_id).create_dm()
|
||||
await user.send(f"Your application has been declined.")
|
||||
await user.send(f"Reason: {reason}")
|
||||
await interaction.response.send_message(content="Application declined", ephemeral=True)
|
||||
|
||||
actions = GuildAppDB.get_actions(str(guild_id), app_name, ActionInteraction.DECLINE)
|
||||
for i in actions:
|
||||
if i["action_type"] == "add_role":
|
||||
role = interaction.message.guild.get_role(int(i["data"]["role_id"]))
|
||||
user = interaction.message.guild.get_member(int(user_id))
|
||||
await user.add_roles(role)
|
||||
else:
|
||||
print("unknown action")
|
||||
|
||||
|
||||
emb = interaction.message.embeds[0]
|
||||
emb.colour = discord.Colour.red()
|
||||
embed = discord.Embed(title='Declined')
|
||||
|
|
32
dbutil.py
32
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()
|
||||
|
|
5
setup.py
5
setup.py
|
@ -2,6 +2,7 @@ import sqlite3
|
|||
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute("CREATE TABLE app_msg_db(msg_id, user_id, guild_id)")
|
||||
cur.execute("CREATE TABLE app_guildapp_db(guild_id, guild_name, application_blob)")
|
||||
cur.execute("CREATE TABLE app_msg_db(msg_id, user_id, guild_id, app_name)")
|
||||
cur.execute("CREATE TABLE app_guildapp_db(guild_id, guild_name, applications_blob)")
|
||||
cur.execute("CREATE TABLE app_start_db(msg_id, app_name, guild_id)")
|
||||
con.commit()
|
Loading…
Reference in New Issue