Compare commits
3 Commits
536370ec17
...
83142e6633
Author | SHA1 | Date |
---|---|---|
Anorak_1 | 83142e6633 | |
Anorak_1 | 0d28df7868 | |
Anorak_1 | 75c3f98c98 |
102
bot.py
102
bot.py
|
@ -9,29 +9,14 @@ from discord.ui import Modal, InputText
|
|||
from discord.utils import get
|
||||
from discord.ext import commands
|
||||
from dbutil import MessageDB
|
||||
from dbutil import StartButtonDB
|
||||
from dbutil import GuildAppDB
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("TOKEN")
|
||||
SERVER_NAME = os.getenv("SERVER_NAME")
|
||||
CHANNEL_ID = os.getenv("CHANNEL_ID")
|
||||
bot = discord.Bot(intents=discord.Intents.all())
|
||||
|
||||
channel_id = int(CHANNEL_ID)
|
||||
|
||||
questions = [
|
||||
"What is your Minecraft username?",
|
||||
"How did you learn about CraftTopia? (If it was from a friend or a website we would like to know either who or where just to know where credit is due)",
|
||||
"Have you been a part of a minecraft community before, if so, let us know what your experience was with that community.",
|
||||
"How old are you?",
|
||||
"Do you have a good microphone for proximity chat?",
|
||||
"Do you plan on spending at least 2-3 hours a week on the server (our current definition of active)",
|
||||
"What will you be able to do to help us grow and build our community?",
|
||||
"Any other questions or concerns?"
|
||||
]
|
||||
max_questions = len(questions)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
|
@ -62,12 +47,12 @@ async def on_guild_remove(guild):
|
|||
@commands.has_permissions(administrator=True)
|
||||
@bot.slash_command(description = "Command used to set up the application prompt")
|
||||
async def start_button(ctx):
|
||||
embed = discord.Embed(title="**Start your application!**")
|
||||
embed.add_field(name="Click the button below to start your application", value="", inline=False)
|
||||
embed.set_footer(text="Made by @anorak01", icon_url="https://cdn.discordapp.com/avatars/269164865480949760/a1af9962da20d5ddaa136043cf45d015?size=1024")
|
||||
appStartView = ApplicationStartButtonView()
|
||||
await ctx.response.send_message("Message set up", ephemeral=True)
|
||||
await ctx.channel.send(embeds=[embed], view=appStartView)
|
||||
view = discord.ui.View()
|
||||
options = SelectApplicationStartButton(max_values=1, placeholder="Select application")
|
||||
for i in GuildAppDB.get_applications(str(ctx.guild.id)):
|
||||
options.add_option(label=i, value=i)
|
||||
view.add_item(options)
|
||||
await ctx.response.send_message(view=view, ephemeral=True)
|
||||
|
||||
@start_button.error
|
||||
async def on_application_command_error(ctx, error):
|
||||
|
@ -78,6 +63,7 @@ async def on_application_command_error(ctx, error):
|
|||
|
||||
application = discord.SlashCommandGroup("application", "The main command to manage applications")
|
||||
|
||||
@commands.has_permissions(administrator=True)
|
||||
@application.command(description="Create application")
|
||||
async def create(ctx, application):
|
||||
if len(application) < 40:
|
||||
|
@ -89,6 +75,7 @@ async def create(ctx, application):
|
|||
else:
|
||||
await ctx.response.send_message(f"please choose shorter name", ephemeral=True)
|
||||
|
||||
@commands.has_permissions(administrator=True)
|
||||
@application.command(description="Remove application")
|
||||
async def remove(ctx, application):
|
||||
result = GuildAppDB.remove_application_entry(str(ctx.guild.id), application)
|
||||
|
@ -97,6 +84,7 @@ async def remove(ctx, application):
|
|||
else:
|
||||
await ctx.response.send_message(f"Application {application} not found")
|
||||
|
||||
@commands.has_permissions(administrator=True)
|
||||
@application.command(description="List all applications")
|
||||
async def list(ctx):
|
||||
applications = GuildAppDB.get_applications(str(ctx.guild.id))
|
||||
|
@ -106,7 +94,7 @@ async def list(ctx):
|
|||
embed.add_field(name=i, value="", inline=False)
|
||||
await ctx.response.send_message(embed=embed)
|
||||
|
||||
|
||||
@commands.has_permissions(administrator=True)
|
||||
@application.command(description="Opens editor for selected application")
|
||||
async def editor(ctx):
|
||||
view = discord.ui.View()
|
||||
|
@ -116,6 +104,7 @@ async def editor(ctx):
|
|||
view.add_item(options)
|
||||
await ctx.response.send_message(view=view, ephemeral=True)
|
||||
|
||||
@commands.has_permissions(administrator=True)
|
||||
@application.command(description="Select response channel for application")
|
||||
async def response_channel(ctx):
|
||||
view = discord.ui.View()
|
||||
|
@ -125,24 +114,30 @@ async def response_channel(ctx):
|
|||
view.add_item(options)
|
||||
await ctx.response.send_message(view=view, ephemeral=True)
|
||||
|
||||
'''
|
||||
@application.command(description="test")
|
||||
async def test(ctx):
|
||||
view = SelectResponseChannelView()
|
||||
await ctx.response.send_message(view=view, ephemeral=True)
|
||||
|
||||
@application.command(description="appl")
|
||||
async def appl(ctx):
|
||||
viewx = discord.ui.View()
|
||||
options = SelectApplicationOptionsEditor(max_values=1)
|
||||
for i in GuildAppDB.get_applications(str(ctx.guild.id)):
|
||||
options.add_option(label=i, value=i)
|
||||
viewx.add_item(options)
|
||||
await ctx.response.send_message(view=viewx, ephemeral=True)'''
|
||||
|
||||
bot.add_application_command(application) # add application group commands
|
||||
|
||||
|
||||
def get_questions_embed(guild_id, application) -> discord.Embed:
|
||||
embed = discord.Embed(title=f"Application: {application}")
|
||||
questions, length = GuildAppDB.get_questions(str(guild_id), application)
|
||||
for i, que in enumerate(questions):
|
||||
embed.add_field(value=f"**{i+1}. {que}**", name="", inline=False)
|
||||
embed.set_footer(text="Made by @anorak01", icon_url="https://cdn.discordapp.com/avatars/269164865480949760/a1af9962da20d5ddaa136043cf45d015?size=1024")
|
||||
return embed
|
||||
|
||||
|
||||
class SelectApplicationStartButton(discord.ui.Select):
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
self.disabled = True
|
||||
|
||||
embed = discord.Embed(title="**Start your application!**")
|
||||
embed.add_field(name=f"Click the button below to start your application for: {self.values[0]}", value="", inline=False)
|
||||
embed.set_footer(text="Made by @anorak01", icon_url="https://cdn.discordapp.com/avatars/269164865480949760/a1af9962da20d5ddaa136043cf45d015?size=1024")
|
||||
appStartView = ApplicationStartButtonView()
|
||||
|
||||
await interaction.response.edit_message(embed=None, content="Application button created", view=None)
|
||||
message = await interaction.channel.send(embed = embed, view=appStartView)
|
||||
StartButtonDB.add_start_msg(str(message.id), str(self.values[0]), str(interaction.guild.id))
|
||||
|
||||
|
||||
class SelectResponseChannelView(discord.ui.View):
|
||||
|
@ -157,14 +152,6 @@ class SelectResponseChannelView(discord.ui.View):
|
|||
GuildAppDB.set_response_channel(interaction.guild.id, )
|
||||
await interaction.response.edit_message(content=f"Selected channel: {select.values[0].mention}", view=None)
|
||||
|
||||
class SelectResponseChannel(discord.ui.Select):
|
||||
def set_app_name(self, app_name):
|
||||
self.app_name = app_name
|
||||
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
self.disabled = True
|
||||
GuildAppDB.set_response_channel(str(interaction.guild.id), self.app_name, str(self.values[0].id))
|
||||
await interaction.response.edit_message(content=f"Selected channel: {self.values[0].mention} for application: {self.app_name}", view=None)
|
||||
|
||||
class SelectApplicationOptionsEditor(discord.ui.Select):
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
|
@ -182,13 +169,14 @@ class SelectApplicationOptionsRespChannel(discord.ui.Select):
|
|||
view.add_item(options)
|
||||
await interaction.response.edit_message(view=view)
|
||||
|
||||
def get_questions_embed(guild_id, application) -> discord.Embed:
|
||||
embed = discord.Embed(title=f"Application: {application}")
|
||||
questions, length = GuildAppDB.get_questions(str(guild_id), application)
|
||||
for i, que in enumerate(questions):
|
||||
embed.add_field(value=f"**{i+1}. {que}**", name="", inline=False)
|
||||
embed.set_footer(text="Made by @anorak01", icon_url="https://cdn.discordapp.com/avatars/269164865480949760/a1af9962da20d5ddaa136043cf45d015?size=1024")
|
||||
return embed
|
||||
class SelectResponseChannel(discord.ui.Select):
|
||||
def set_app_name(self, app_name):
|
||||
self.app_name = app_name
|
||||
|
||||
async def callback(self, interaction: discord.Interaction):
|
||||
self.disabled = True
|
||||
GuildAppDB.set_response_channel(str(interaction.guild.id), self.app_name, str(self.values[0].id))
|
||||
await interaction.response.edit_message(content=f"Selected channel: {self.values[0].mention} for application: {self.app_name}", view=None)
|
||||
|
||||
class ApplicationEditorView(discord.ui.View):
|
||||
def __init__(self, guild_id, application_name):
|
||||
|
@ -350,6 +338,12 @@ class ApplicationStartButtonView(discord.ui.View):
|
|||
custom_id=f"persistent:start_application",
|
||||
)
|
||||
async def start_app(self, button: discord.ui.Button, interaction: discord.Interaction):
|
||||
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)
|
||||
response_channel = GuildAppDB.get_response_channel(guild_id, app_name)
|
||||
|
||||
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.")
|
||||
|
@ -390,7 +384,7 @@ class ApplicationStartButtonView(discord.ui.View):
|
|||
with open('applications.json', 'w') as f:
|
||||
json.dump(data, f)
|
||||
|
||||
channel = bot.get_channel(channel_id)
|
||||
channel = bot.get_channel(int(response_channel))
|
||||
embed = discord.Embed(title='Application: ' + interaction.user.display_name)
|
||||
for i in range(0, max_questions):
|
||||
embed.add_field(name=f'{questions[i]}', value=application[f'question{i}'], inline=False)
|
||||
|
|
32
dbutil.py
32
dbutil.py
|
@ -25,6 +25,29 @@ class MessageDB():
|
|||
cur.execute(f"DELETE FROM app_msg_db WHERE msg_id={msg_id}")
|
||||
con.commit()
|
||||
|
||||
|
||||
class StartButtonDB():
|
||||
def add_start_msg(msg_id: str, app_name: str, guild_id: str) -> None:
|
||||
data = (msg_id, app_name, guild_id)
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute("INSERT INTO app_start_db VALUES (?, ?, ?)", data)
|
||||
con.commit()
|
||||
|
||||
def get_start_msg(msg_id: str) -> tuple[str, str]:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
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()
|
||||
return app_name, guild_id
|
||||
|
||||
def remove_start_msg(msg_id: str) -> None:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"DELETE FROM app_start_db WHERE msg_id={msg_id}")
|
||||
con.commit()
|
||||
|
||||
class GuildAppDB():
|
||||
def create_guild(guild_id: str, guild_name: str) -> None:
|
||||
applications = {}
|
||||
|
@ -116,6 +139,15 @@ class GuildAppDB():
|
|||
else:
|
||||
return "error on set response channel: application not found"
|
||||
|
||||
def get_response_channel(guild_id: str, application_name: str) -> 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():
|
||||
return applications[application_name]["resp_channel"]
|
||||
|
||||
def add_question(guild_id: str, application_name: str, question: str) -> str:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
|
|
Loading…
Reference in New Issue