wtf questions

This commit is contained in:
AllfatherHatt 2025-05-18 13:03:21 +02:00
parent 9a3e5860a7
commit a5ef741ad7

View File

@ -184,20 +184,23 @@ class Recruitment(commands.Cog): # noqa
return False return False
async def ask_questions(self, member: discord.Member) -> Optional[Dict[str, str]]: async def ask_questions(self, member: discord.Member) -> Optional[Dict[str, str]]:
"""Ask each question, let the user confirm their answer, and return the final answers.""" """
Ask each question, let the user confirm their answer,
and return the final answers (or None on abort).
"""
answers: Dict[str, str] = {} answers: Dict[str, str] = {}
for q in QUESTIONS_LIST: for q in QUESTIONS_LIST:
prompt = q["prompt"] prompt = q["prompt"]
while True: while True:
# 1) Ask the question # 1) send the question
try: try:
await member.send(prompt) await member.send(prompt)
except discord.Forbidden: except discord.Forbidden:
return None return None # can't DM
# 2) Wait for their reply (match by ID, not object equality) # 2) wait for their reply (match on ID, not object)
try: try:
msg = await asyncio.wait_for( msg = await asyncio.wait_for(
self.bot.wait_for( self.bot.wait_for(
@ -205,25 +208,25 @@ class Recruitment(commands.Cog): # noqa
check=lambda m: ( check=lambda m: (
m.author.id == member.id m.author.id == member.id
and isinstance(m.channel, discord.DMChannel) and isinstance(m.channel, discord.DMChannel)
), )
), ),
timeout=300.0, timeout=300.0,
) )
except asyncio.TimeoutError: except asyncio.TimeoutError:
await member.send( await member.send(
"You took too long to answer. Please run the application command again." "You took too long to answer. Please restart the application with `!application`."
) )
return None return None
answer = sanitize_input(msg.content) answer = sanitize_input(msg.content)
# 3) Ask for confirmation # 3) echo back for confirmation
try: try:
await member.send(f"You answered:\n> {answer}\n\nIs that correct? (yes/no)") await member.send(f"You answered:\n> {answer}\n\nIs that correct? (yes/no)")
except discord.Forbidden: except discord.Forbidden:
return None return None
# 4) Wait for yes/no # 4) wait for a yes/no
try: try:
confirm = await asyncio.wait_for( confirm = await asyncio.wait_for(
self.bot.wait_for( self.bot.wait_for(
@ -232,24 +235,27 @@ class Recruitment(commands.Cog): # noqa
m.author.id == member.id m.author.id == member.id
and isinstance(m.channel, discord.DMChannel) and isinstance(m.channel, discord.DMChannel)
and m.content.lower() in ("y", "yes", "n", "no") and m.content.lower() in ("y", "yes", "n", "no")
), )
), ),
timeout=60.0, timeout=60.0,
) )
except asyncio.TimeoutError: except asyncio.TimeoutError:
await member.send( await member.send(
"Confirmation timed out. Please start your application again." "Confirmation timed out. Please restart the application with `!application`."
) )
return None return None
if confirm.content.lower() in ("y", "yes"): if confirm.content.lower() in ("y", "yes"):
# user confirmed, save and move on
answers[q["key"]] = answer answers[q["key"]] = answer
break # move on to next question break
else: else:
# user said “no” → repeat this question
await member.send("Okay, let's try that again.") await member.send("Okay, let's try that again.")
return answers return answers
def format_application( def format_application(
self, answers: Dict[str, str], member: discord.Member self, answers: Dict[str, str], member: discord.Member
) -> discord.Embed: ) -> discord.Embed: