Compare commits
2 Commits
83142e6633
...
4429753729
Author | SHA1 | Date |
---|---|---|
Anorak_1 | 4429753729 | |
Anorak_1 | c578dccefb |
42
bot.py
42
bot.py
|
@ -29,7 +29,7 @@ async def on_ready():
|
||||||
for i in bot.guilds:
|
for i in bot.guilds:
|
||||||
if str(i.id) not in GuildAppDB.get_all_guilds():
|
if str(i.id) not in GuildAppDB.get_all_guilds():
|
||||||
GuildAppDB.create_guild(str(i.id), i.name)
|
GuildAppDB.create_guild(str(i.id), i.name)
|
||||||
print(f"entry for {i.id} created")
|
print(f"Entry for {i.id} created")
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_guild_join(guild):
|
async def on_guild_join(guild):
|
||||||
|
@ -69,9 +69,7 @@ async def create(ctx, application):
|
||||||
if len(application) < 40:
|
if len(application) < 40:
|
||||||
result = GuildAppDB.add_application_entry(str(ctx.guild.id), application)
|
result = GuildAppDB.add_application_entry(str(ctx.guild.id), application)
|
||||||
if result == "success":
|
if result == "success":
|
||||||
await ctx.response.send_message(f"Successfully created application: {application}", ephemeral=True) # create a new application, modal with name ask
|
await ctx.response.send_message(f"Successfully created application: {application}\n\nDon't forget to set the response channel!", ephemeral=True) # create a new application, modal with name ask
|
||||||
else:
|
|
||||||
print(result)
|
|
||||||
else:
|
else:
|
||||||
await ctx.response.send_message(f"please choose shorter name", ephemeral=True)
|
await ctx.response.send_message(f"please choose shorter name", ephemeral=True)
|
||||||
|
|
||||||
|
@ -82,17 +80,17 @@ async def remove(ctx, application):
|
||||||
if result == "success":
|
if result == "success":
|
||||||
await ctx.response.send_message(f"Successfully removed application: {application}", ephemeral=True)
|
await ctx.response.send_message(f"Successfully removed application: {application}", ephemeral=True)
|
||||||
else:
|
else:
|
||||||
await ctx.response.send_message(f"Application {application} not found")
|
await ctx.response.send_message(f"Application {application} not found", ephemeral=True)
|
||||||
|
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
@application.command(description="List all applications")
|
@application.command(description="List all applications")
|
||||||
async def list(ctx):
|
async def list(ctx):
|
||||||
applications = GuildAppDB.get_applications(str(ctx.guild.id))
|
applications = GuildAppDB.get_applications(str(ctx.guild.id))
|
||||||
print(applications)
|
embed = discord.Embed(title="**List of applications**")
|
||||||
embed = discord.Embed()
|
embed.set_footer(text="Made by @anorak01", icon_url="https://cdn.discordapp.com/avatars/269164865480949760/a1af9962da20d5ddaa136043cf45d015?size=1024")
|
||||||
for i in applications:
|
for i, app in enumerate(applications):
|
||||||
embed.add_field(name=i, value="", inline=False)
|
embed.add_field(value=f"**{i+1}. {app}**", name="", inline=False)
|
||||||
await ctx.response.send_message(embed=embed)
|
await ctx.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
@application.command(description="Opens editor for selected application")
|
@application.command(description="Opens editor for selected application")
|
||||||
|
@ -148,7 +146,6 @@ class SelectResponseChannelView(discord.ui.View):
|
||||||
)
|
)
|
||||||
async def select_callback(self, select, interaction: discord.Interaction):
|
async def select_callback(self, select, interaction: discord.Interaction):
|
||||||
self.disable_all_items()
|
self.disable_all_items()
|
||||||
print(select.values[0].id)
|
|
||||||
GuildAppDB.set_response_channel(interaction.guild.id, )
|
GuildAppDB.set_response_channel(interaction.guild.id, )
|
||||||
await interaction.response.edit_message(content=f"Selected channel: {select.values[0].mention}", view=None)
|
await interaction.response.edit_message(content=f"Selected channel: {select.values[0].mention}", view=None)
|
||||||
|
|
||||||
|
@ -164,7 +161,7 @@ class SelectApplicationOptionsRespChannel(discord.ui.Select):
|
||||||
async def callback(self, interaction: discord.Interaction):
|
async def callback(self, interaction: discord.Interaction):
|
||||||
self.disabled = True
|
self.disabled = True
|
||||||
view = discord.ui.View()
|
view = discord.ui.View()
|
||||||
options = SelectResponseChannel(select_type=discord.ComponentType.channel_select, channel_types=[discord.ChannelType.text], max_values=1)
|
options = SelectResponseChannel(select_type=discord.ComponentType.channel_select, channel_types=[discord.ChannelType.text], max_values=1, placeholder="Select channel")
|
||||||
options.set_app_name(self.values[0])
|
options.set_app_name(self.values[0])
|
||||||
view.add_item(options)
|
view.add_item(options)
|
||||||
await interaction.response.edit_message(view=view)
|
await interaction.response.edit_message(view=view)
|
||||||
|
@ -191,7 +188,6 @@ class ApplicationEditorView(discord.ui.View):
|
||||||
row=0
|
row=0
|
||||||
)
|
)
|
||||||
async def add_question(self, button: discord.ui.Button, interaction: discord.Interaction):
|
async def add_question(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||||
print("add question")
|
|
||||||
modal = AddQuestionModal(self.application_name)
|
modal = AddQuestionModal(self.application_name)
|
||||||
await interaction.response.send_modal(modal)
|
await interaction.response.send_modal(modal)
|
||||||
|
|
||||||
|
@ -202,7 +198,6 @@ class ApplicationEditorView(discord.ui.View):
|
||||||
row=0
|
row=0
|
||||||
)
|
)
|
||||||
async def remove_question(self, button, interaction: discord.Interaction):
|
async def remove_question(self, button, interaction: discord.Interaction):
|
||||||
print("remove question")
|
|
||||||
view = ApplicationEditorView(str(interaction.guild.id), self.application_name)
|
view = ApplicationEditorView(str(interaction.guild.id), self.application_name)
|
||||||
options = RemoveQuestionSelect(max_values=1, placeholder="Select question to remove")
|
options = RemoveQuestionSelect(max_values=1, placeholder="Select question to remove")
|
||||||
options.set_app_name(self.application_name)
|
options.set_app_name(self.application_name)
|
||||||
|
@ -219,7 +214,6 @@ class ApplicationEditorView(discord.ui.View):
|
||||||
row=0
|
row=0
|
||||||
)
|
)
|
||||||
async def edit_question(self, button, interaction: discord.Interaction):
|
async def edit_question(self, button, interaction: discord.Interaction):
|
||||||
print("edit question")
|
|
||||||
view = ApplicationEditorView(str(interaction.guild.id), self.application_name)
|
view = ApplicationEditorView(str(interaction.guild.id), self.application_name)
|
||||||
options = EditQuestionSelect(max_values=1, placeholder="Select question to edit")
|
options = EditQuestionSelect(max_values=1, placeholder="Select question to edit")
|
||||||
options.set_app_name(self.application_name)
|
options.set_app_name(self.application_name)
|
||||||
|
@ -236,7 +230,6 @@ class ApplicationEditorView(discord.ui.View):
|
||||||
row=0
|
row=0
|
||||||
)
|
)
|
||||||
async def move_question(self, button, interaction: discord.Interaction):
|
async def move_question(self, button, interaction: discord.Interaction):
|
||||||
print("move question")
|
|
||||||
view = ApplicationEditorView(str(interaction.guild.id), self.application_name)
|
view = ApplicationEditorView(str(interaction.guild.id), self.application_name)
|
||||||
options = MoveQuestionSelect(max_values=1, placeholder="Select question to move")
|
options = MoveQuestionSelect(max_values=1, placeholder="Select question to move")
|
||||||
options.set_app_name(self.application_name)
|
options.set_app_name(self.application_name)
|
||||||
|
@ -339,14 +332,15 @@ class ApplicationStartButtonView(discord.ui.View):
|
||||||
)
|
)
|
||||||
async def start_app(self, button: discord.ui.Button, interaction: discord.Interaction):
|
async def start_app(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||||
app_name, guild_id = StartButtonDB.get_start_msg(interaction.message.id)
|
app_name, guild_id = StartButtonDB.get_start_msg(interaction.message.id)
|
||||||
print(app_name)
|
|
||||||
print(guild_id)
|
|
||||||
|
|
||||||
questions, max_questions=GuildAppDB.get_questions(guild_id, app_name)
|
questions, max_questions=GuildAppDB.get_questions(guild_id, app_name)
|
||||||
|
if questions == "error on get questions: application not found":
|
||||||
|
await interaction.response.send_message(content="Application no longer exists", ephemeral=True)
|
||||||
|
return
|
||||||
response_channel = GuildAppDB.get_response_channel(guild_id, app_name)
|
response_channel = GuildAppDB.get_response_channel(guild_id, app_name)
|
||||||
|
|
||||||
user = await interaction.user.create_dm()
|
user = await interaction.user.create_dm()
|
||||||
embedd = discord.Embed(title=f'CreaTopia Application', description="Hey! Your application has started. You have 300 seconds to complete it.")
|
embedd = discord.Embed(title=f'{interaction.guild.name} application: {app_name}', description="Hey! Your application has started. You have 300 seconds to complete it.")
|
||||||
embedd.add_field(value=f'You can cancel the application by answering "cancel" to any of the questions', name="", inline=False)
|
embedd.add_field(value=f'You can cancel the application by answering "cancel" to any of the questions', name="", inline=False)
|
||||||
embedd.set_footer(text="Made by @anorak01", icon_url="https://cdn.discordapp.com/avatars/269164865480949760/a1af9962da20d5ddaa136043cf45d015?size=1024")
|
embedd.set_footer(text="Made by @anorak01", icon_url="https://cdn.discordapp.com/avatars/269164865480949760/a1af9962da20d5ddaa136043cf45d015?size=1024")
|
||||||
|
|
||||||
|
@ -385,7 +379,7 @@ class ApplicationStartButtonView(discord.ui.View):
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
channel = bot.get_channel(int(response_channel))
|
channel = bot.get_channel(int(response_channel))
|
||||||
embed = discord.Embed(title='Application: ' + interaction.user.display_name)
|
embed = discord.Embed(title=f"Application: {app_name}\nUser: {interaction.user.display_name}")
|
||||||
for i in range(0, max_questions):
|
for i in range(0, max_questions):
|
||||||
embed.add_field(name=f'{questions[i]}', value=application[f'question{i}'], inline=False)
|
embed.add_field(name=f'{questions[i]}', value=application[f'question{i}'], inline=False)
|
||||||
embed.set_footer(text=f"Applicant ID: {interaction.user.id}")
|
embed.set_footer(text=f"Applicant ID: {interaction.user.id}")
|
||||||
|
@ -394,8 +388,6 @@ class ApplicationStartButtonView(discord.ui.View):
|
||||||
|
|
||||||
msg = await channel.send(embed=embed, view=appView)
|
msg = await channel.send(embed=embed, view=appView)
|
||||||
|
|
||||||
print(msg.id)
|
|
||||||
|
|
||||||
MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.id)
|
MessageDB.add_application_msg(msg.id, interaction.user.id, interaction.guild.id)
|
||||||
|
|
||||||
await user.send('Thank you for applying!')
|
await user.send('Thank you for applying!')
|
||||||
|
@ -448,11 +440,11 @@ class ApplicationModal(discord.ui.Modal):
|
||||||
user_id, guild_id = MessageDB.get_application_msg(msg_id)
|
user_id, guild_id = 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"You have been accepted to the CreatTopia Minecraft server!")
|
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")
|
||||||
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()
|
||||||
embed = discord.Embed(title='Accepted')
|
embed = discord.Embed(title='Accepted')
|
||||||
|
@ -464,7 +456,7 @@ class ApplicationModal(discord.ui.Modal):
|
||||||
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"You have been declined access to the CreatTopia Minecraft server.")
|
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)
|
||||||
emb = interaction.message.embeds[0]
|
emb = interaction.message.embeds[0]
|
||||||
|
|
|
@ -38,7 +38,6 @@ class StartButtonDB():
|
||||||
con = sqlite3.connect("applications.db")
|
con = sqlite3.connect("applications.db")
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("SELECT app_name, guild_id FROM app_start_db WHERE msg_id=?", (str(msg_id), ))
|
cur.execute("SELECT app_name, guild_id FROM app_start_db WHERE msg_id=?", (str(msg_id), ))
|
||||||
#print(cur.fetchone())
|
|
||||||
app_name, guild_id = cur.fetchone()
|
app_name, guild_id = cur.fetchone()
|
||||||
return app_name, guild_id
|
return app_name, guild_id
|
||||||
|
|
||||||
|
@ -78,7 +77,6 @@ class GuildAppDB():
|
||||||
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, ))
|
||||||
application_blob = cur.fetchone()
|
application_blob = cur.fetchone()
|
||||||
applications = pickle.loads(application_blob[0])
|
applications = pickle.loads(application_blob[0])
|
||||||
print(applications)
|
|
||||||
if application_name not in applications.keys():
|
if application_name not in applications.keys():
|
||||||
applications[application_name] = {
|
applications[application_name] = {
|
||||||
"app_id": "",
|
"app_id": "",
|
||||||
|
@ -174,7 +172,7 @@ class GuildAppDB():
|
||||||
questions = applications[application_name]["questions"]
|
questions = applications[application_name]["questions"]
|
||||||
return questions, len(questions)
|
return questions, len(questions)
|
||||||
else:
|
else:
|
||||||
return "error on get questions: application not found"
|
return "error on get questions: application not found", ""
|
||||||
|
|
||||||
def edit_question(guild_id: str, application_name: str, question_index: int, new_question: str):
|
def edit_question(guild_id: str, application_name: str, question_index: int, new_question: str):
|
||||||
con = sqlite3.connect("applications.db")
|
con = sqlite3.connect("applications.db")
|
||||||
|
|
Loading…
Reference in New Issue