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)
|
actions = GuildAppDB.get_actions(str(interaction.guild.id), self.application_name, action_type=ActionInteraction.ACCEPT)
|
||||||
options.set_action_type(ActionInteraction.ACCEPT)
|
options.set_action_type(ActionInteraction.ACCEPT)
|
||||||
for i, que in enumerate(actions):
|
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)
|
view.add_item(options)
|
||||||
await interaction.response.edit_message(view=view)
|
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)
|
actions = GuildAppDB.get_actions(str(interaction.guild.id), self.application_name, action_type=ActionInteraction.DECLINE)
|
||||||
options.set_action_type(ActionInteraction.DECLINE)
|
options.set_action_type(ActionInteraction.DECLINE)
|
||||||
for i, que in enumerate(actions):
|
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)
|
view.add_item(options)
|
||||||
await interaction.response.edit_message(view=view)
|
await interaction.response.edit_message(view=view)
|
||||||
|
|
||||||
|
@ -474,7 +482,7 @@ class RemoveActionSelect(discord.ui.Select):
|
||||||
|
|
||||||
async def callback(self, interaction: discord.Interaction):
|
async def callback(self, interaction: discord.Interaction):
|
||||||
self.disabled = True
|
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:
|
if self.action_type == ActionInteraction.ACCEPT:
|
||||||
editor = ActionAcceptEditorView(str(interaction.guild.id), self.app_name)
|
editor = ActionAcceptEditorView(str(interaction.guild.id), self.app_name)
|
||||||
embed = get_actions_embed(str(interaction.guild.id), self.app_name, ActionInteraction.ACCEPT)
|
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)
|
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!')
|
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):
|
async def accept(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||||
msg_id = str(interaction.message.id)
|
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 = ApplicationModal(title=f"Accepting: {bot.get_user(user_id).display_name}")
|
||||||
modal.set_action("acc")
|
modal.set_action("acc")
|
||||||
|
@ -613,7 +621,7 @@ class ApplicationButtonsView(discord.ui.View):
|
||||||
async def decline(self, button: discord.ui.Button, interaction: discord.Interaction):
|
async def decline(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||||
msg_id = str(interaction.message.id)
|
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 = ApplicationModal(title=f"Declining: {bot.get_user(user_id).display_name}")
|
||||||
modal.set_action("dec")
|
modal.set_action("dec")
|
||||||
|
@ -629,13 +637,26 @@ class ApplicationModal(discord.ui.Modal):
|
||||||
async def callback(self, interaction: discord.Interaction):
|
async def callback(self, interaction: discord.Interaction):
|
||||||
reason = self.children[0].value
|
reason = self.children[0].value
|
||||||
msg_id = str(interaction.message.id)
|
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":
|
if self.action == "acc":
|
||||||
user = await bot.get_user(user_id).create_dm()
|
user = await bot.get_user(user_id).create_dm()
|
||||||
await user.send(f"Your application has been accepted!")
|
await user.send(f"Your application has been accepted!")
|
||||||
await user.send(f"Reason: {reason}")
|
await user.send(f"Reason: {reason}")
|
||||||
await interaction.response.send_message(content="Application accepted", ephemeral=True)
|
await interaction.response.send_message(content="Application accepted", ephemeral=True)
|
||||||
|
|
||||||
role = get(interaction.message.guild.roles, name="CreatTopian")
|
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)
|
#await discord.utils.get(interaction.message.guild.members, id=int(user_id)).add_roles(role)
|
||||||
emb = interaction.message.embeds[0]
|
emb = interaction.message.embeds[0]
|
||||||
emb.colour = discord.Colour.green()
|
emb.colour = discord.Colour.green()
|
||||||
|
@ -646,11 +667,24 @@ class ApplicationModal(discord.ui.Modal):
|
||||||
view = discord.ui.View.from_message(interaction.message)
|
view = discord.ui.View.from_message(interaction.message)
|
||||||
view.disable_all_items()
|
view.disable_all_items()
|
||||||
await interaction.followup.edit_message(message_id = interaction.message.id, view = view)
|
await interaction.followup.edit_message(message_id = interaction.message.id, view = view)
|
||||||
|
|
||||||
|
|
||||||
if self.action == "dec":
|
if self.action == "dec":
|
||||||
user = await bot.get_user(user_id).create_dm()
|
user = await bot.get_user(user_id).create_dm()
|
||||||
await user.send(f"Your application has been declined.")
|
await user.send(f"Your application has been declined.")
|
||||||
await user.send(f"Reason: {reason}")
|
await user.send(f"Reason: {reason}")
|
||||||
await interaction.response.send_message(content="Application declined", ephemeral=True)
|
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 = interaction.message.embeds[0]
|
||||||
emb.colour = discord.Colour.red()
|
emb.colour = discord.Colour.red()
|
||||||
embed = discord.Embed(title='Declined')
|
embed = discord.Embed(title='Declined')
|
||||||
|
|
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()
|
||||||
|
|
5
setup.py
5
setup.py
|
@ -2,6 +2,7 @@ import sqlite3
|
||||||
|
|
||||||
con = sqlite3.connect("applications.db")
|
con = sqlite3.connect("applications.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("CREATE TABLE app_msg_db(msg_id, user_id, guild_id)")
|
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, application_blob)")
|
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()
|
con.commit()
|
Loading…
Reference in New Issue