Compare commits
3 Commits
fcc409dd37
...
0eff35508f
Author | SHA1 | Date |
---|---|---|
|
0eff35508f | |
|
15ce50196d | |
|
413c1eff27 |
32
bot.py
32
bot.py
|
@ -18,16 +18,16 @@ bot = discord.Bot(intents=discord.Intents.all())
|
|||
|
||||
channel_id = int(CHANNEL_ID)
|
||||
|
||||
questions = {
|
||||
1: "What is your Minecraft username?",
|
||||
2: "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)",
|
||||
3: "Have you been a part of a minecraft community before, if so, let us know what your experience was with that community.",
|
||||
4: "How old are you?",
|
||||
5: "Do you have a good microphone for proximity chat?",
|
||||
6: "Do you plan on spending at least 2-3 hours a week on the server (our current definition of active)",
|
||||
7: "What will you be able to do to help us grow and build our community?",
|
||||
8: "Any other questions or concerns?"
|
||||
}
|
||||
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)
|
||||
|
||||
|
||||
|
@ -46,8 +46,8 @@ async def apply(ctx):
|
|||
|
||||
application = {'userId': ctx.author.id}
|
||||
|
||||
for i in range(1, max_questions+1):
|
||||
embed = discord.Embed(title=f'Question [{i}/{max_questions}]', description=questions[i])
|
||||
for i in range(0, max_questions):
|
||||
embed = discord.Embed(title=f'Question [{i+1}/{max_questions}]', description=questions[i])
|
||||
await user.send(embed=embed)
|
||||
response = await bot.wait_for('message', check=lambda m: m.author == ctx.author and m.channel == user, timeout=300)
|
||||
application[f'question{i}'] = response.content
|
||||
|
@ -64,7 +64,7 @@ async def apply(ctx):
|
|||
|
||||
channel = bot.get_channel(channel_id)
|
||||
embed = discord.Embed(title='Application: ' + ctx.author.display_name)
|
||||
for i in range(1, max_questions+1):
|
||||
for i in range(0, max_questions):
|
||||
embed.add_field(name=f'{questions[i]}', value=application[f'question{i}'], inline=False)
|
||||
embed.set_footer(text=f"Applicant ID: {ctx.author.id}")
|
||||
|
||||
|
@ -185,9 +185,9 @@ class ApplicationStartButtonView(discord.ui.View):
|
|||
|
||||
application = {'userId': interaction.user.id}
|
||||
|
||||
for i in range(1, max_questions+1):
|
||||
for i in range(0, max_questions):
|
||||
try:
|
||||
embed = discord.Embed(title=f'Question [{i}/{max_questions}]', description=questions[i])
|
||||
embed = discord.Embed(title=f'Question [{i+1}/{max_questions}]', description=questions[i])
|
||||
await user.send(embed=embed)
|
||||
response = await bot.wait_for('message', check=lambda m: m.author == interaction.user and m.channel == user, timeout=300)
|
||||
if response.content.startswith("cancel"):
|
||||
|
@ -211,7 +211,7 @@ class ApplicationStartButtonView(discord.ui.View):
|
|||
|
||||
channel = bot.get_channel(channel_id)
|
||||
embed = discord.Embed(title='Application: ' + interaction.user.display_name)
|
||||
for i in range(1, max_questions+1):
|
||||
for i in range(0, max_questions):
|
||||
embed.add_field(name=f'{questions[i]}', value=application[f'question{i}'], inline=False)
|
||||
embed.set_footer(text=f"Applicant ID: {interaction.user.id}")
|
||||
|
||||
|
|
155
dbutil.py
155
dbutil.py
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
import pickle
|
||||
|
||||
|
||||
class MessageDB():
|
||||
|
@ -22,4 +23,156 @@ class MessageDB():
|
|||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"DELETE FROM app_msg_db WHERE msg_id={msg_id}")
|
||||
con.commit()
|
||||
con.commit()
|
||||
|
||||
class GuildAppDB():
|
||||
def create_guild(guild_id: str, guild_name: str) -> None:
|
||||
applications = {}
|
||||
application_blob = pickle.dumps(applications)
|
||||
data = guild_id, guild_name, application_blob
|
||||
con = sqlite3.connect("application.db")
|
||||
cur = con.cursor()
|
||||
cur.execute("INSERT INTO app_guildapp_db VALUES (?, ?, ?)", data)
|
||||
con.commit()
|
||||
|
||||
def remove_guild(guild_id: str) -> None:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"DELETE FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
con.commit()
|
||||
|
||||
def add_application_entry(guild_id: str, application_name: str) -> str:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name not in applications.keys():
|
||||
applications[f"application_name"] = {
|
||||
"app_id": "",
|
||||
"resp_channel": ""
|
||||
}
|
||||
application_blob2 = pickle.dumps(applications)
|
||||
cur.execute(f"UPDATE app_guildapp_db SET application_blob = ? WHERE guild_id={guild_id}", application_blob2)
|
||||
con.commit()
|
||||
return "success"
|
||||
else:
|
||||
return "error on add application entry: application exists"
|
||||
|
||||
def remove_application_entry(guild_id: str, application_name: str) -> str:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name in applications.keys():
|
||||
applications.pop(application_name)
|
||||
application_blob2 = pickle.dumps(applications)
|
||||
cur.execute(f"UPDATE app_guildapp_db SET application_blob = ? WHERE guild_id={guild_id}", application_blob2)
|
||||
con.commit()
|
||||
return "success"
|
||||
else:
|
||||
return "error on remove application entry: application not found"
|
||||
|
||||
def set_response_channel(guild_id: str, application_name: str, channel_id: str) -> str:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name in applications.keys():
|
||||
applications[application_name]["resp_channel"] = channel_id
|
||||
application_blob2 = pickle.dumps(applications)
|
||||
cur.execute(f"UPDATE app_guildapp_db SET application_blob = ? WHERE guild_id={guild_id}", application_blob2)
|
||||
con.commit()
|
||||
return "success"
|
||||
else:
|
||||
return "error on set response channel: application not found"
|
||||
|
||||
def add_question(guild_id: str, application_name: str, question: str) -> str:
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name in applications.keys():
|
||||
question_index = int(len(applications[application_name]["questions"]))
|
||||
applications[application_name]["questions"][question_index] = question
|
||||
application_blob2 = pickle.dumps(applications)
|
||||
cur.execute(f"UPDATE app_guildapp_db SET application_blob = ? WHERE guild_id={guild_id}", application_blob2)
|
||||
con.commit()
|
||||
return "success"
|
||||
else:
|
||||
return "error on add question: application not found"
|
||||
|
||||
def get_questions(guild_id: str, application_name: str):
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name in applications.keys():
|
||||
questions = applications[application_name]["questions"]
|
||||
return questions
|
||||
else:
|
||||
return "error on get questions: application not found"
|
||||
|
||||
def edit_question(guild_id: str, application_name: str, question_index: int, new_question: str):
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name in applications.keys():
|
||||
if question_index in applications[application_name].keys():
|
||||
questions = applications[application_name]["questions"]#[question_index] = new_question
|
||||
questions[question_index-1] = new_question
|
||||
applications[application_name]["questions"] = questions
|
||||
application_blob2 = pickle.dumps(applications)
|
||||
cur.execute(f"UPDATE app_guildapp_db SET application_blob = ? WHERE guild_id={guild_id}", application_blob2)
|
||||
con.commit()
|
||||
return "success"
|
||||
else:
|
||||
return "error on edit question: question index not found"
|
||||
else:
|
||||
return "error on edit question: application not found"
|
||||
|
||||
def move_question(guild_id: str, application_name: str, init_que_index: int, fin_que_index: int):
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name in applications.keys():
|
||||
questions = applications[application_name]["questions"]
|
||||
if init_que_index <= len(questions) and fin_que_index <= len(questions):
|
||||
questions.insert(init_que_index-1, questions.pop(fin_que_index-1))
|
||||
applications[application_name]["questions"] = questions
|
||||
application_blob2 = pickle.dumps(applications)
|
||||
cur.execute(f"UPDATE app_guildapp_db SET application_blob = ? WHERE guild_id={guild_id}", application_blob2)
|
||||
con.commit()
|
||||
return "success"
|
||||
else:
|
||||
return "error on move question: question index not found"
|
||||
else:
|
||||
return "error on move question: application not found"
|
||||
|
||||
def remove_question(guild_id: str, application_name: str, question_index: int):
|
||||
con = sqlite3.connect("applications.db")
|
||||
cur = con.cursor()
|
||||
cur.execute(f"SELECT application_blob FROM app_guildapp_db WHERE guild_id={guild_id}")
|
||||
application_blob = cur.fetchone()
|
||||
applications = pickle.loads(application_blob)
|
||||
if application_name in applications.keys():
|
||||
questions = applications[application_name]["questions"]
|
||||
if question_index <= len(questions):
|
||||
questions.pop(question_index-1)
|
||||
applications[application_name]["questions"] = questions
|
||||
application_blob2 = pickle.dumps(applications)
|
||||
cur.execute(f"UPDATE app_guildapp_db SET application_blob = ? WHERE guild_id={guild_id}", application_blob2)
|
||||
con.commit()
|
||||
return "success"
|
||||
else:
|
||||
return "error on remove question: question index not found"
|
||||
else:
|
||||
return "error on remove question: application not found"
|
Loading…
Reference in New Issue