Trying to do timeout handling properly

This commit is contained in:
unknown 2023-03-13 15:40:22 +01:00
parent 6914d0caa1
commit 640ed01103

View File

@ -35,18 +35,13 @@ class Recruitment(commands.Cog):
async def interactive_application(self, author: discord.Member): async def interactive_application(self, author: discord.Member):
"""Ask the user several questions to create an application.""" """Ask the user several questions to create an application."""
embed = discord.Embed( embed = discord.Embed(
title="Kanium Membership Application", title="+++ KANIUM APPLICATION SYSTEM +++",
description="Ah, you wish to apply for Kanium membership. Very well, understand that This process is very important to us so we expect you to put effort in and be glorious about it. Let us begin!", description="Ah, you wish to apply for Kanium membership. Very well, understand that This process is very important to us so we expect you to put effort in and be glorious about it. Let us begin!",
color=discord.Color.green(), color=discord.Color.green(),
) )
await author.send(embed=embed) await author.send(embed=embed)
questions = ["First of all, what is your name?", "What age are you?", "Where are you from?", "Do you have any hobbies?", "Are you wishing to join because of a particular game? If so, which game?", "Write out, in a free-style way, what your motivation is for wanting to join us in particular and how you would be a good fit for Kanium"] answers = await self.ask_questions(author)
try:
answers = await self.ask_questions(author, questions)
except asyncio.TimeoutError:
await author.send("You took too long to answer. Please try again later.")
return
embeddedApplication = await self.format_application(answers, author) embeddedApplication = await self.format_application(answers, author)
@ -92,13 +87,20 @@ class Recruitment(commands.Cog):
return embed return embed
async def ask_questions(self, author: discord.Member, questions: List[str]) -> List[str]: async def ask_questions(self, author: discord.Member) -> List[str]:
"""Ask the user several questions and return the answers.""" """Ask the user several questions and return the answers."""
questions = ["First of all, what is your name?", "What age are you?", "Where are you from?", "Do you have any hobbies?", "Are you wishing to join because of a particular game? If so, which game?", "Write out, in a free-style way, what your motivation is for wanting to join us in particular and how you would be a good fit for Kanium"]
answers = [] answers = []
for question in questions: for question in questions:
await author.send(question) await author.send(question)
answer = await self.get_answers(author)
try:
answer = await asyncio.wait_for(self.get_answers(author), timeout=60.0)
except asyncio.TimeoutError:
await author.send("You took too long to answer. Please try again later.")
return None
answers.append(answer.content) answers.append(answer.content)
return answers return answers