mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Close questions after they expire.
This commit is contained in:
parent
316f3d2c3f
commit
dda5beabe5
1 changed files with 7 additions and 6 deletions
|
@ -25,7 +25,7 @@ class TriviaCommand(Command):
|
||||||
|
|
||||||
def __init__(self, interface: CommandInterface):
|
def __init__(self, interface: CommandInterface):
|
||||||
super().__init__(interface)
|
super().__init__(interface)
|
||||||
self.answerers: typing.Dict[uuid.UUID, typing.Dict[..., bool]] = {}
|
self._answerers: typing.Dict[uuid.UUID, typing.Dict[..., bool]] = {}
|
||||||
|
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
# Fetch the question
|
# Fetch the question
|
||||||
|
@ -55,13 +55,13 @@ class TriviaCommand(Command):
|
||||||
answers[index] = f"{self._letter_emojis[index]} {answers[index]}"
|
answers[index] = f"{self._letter_emojis[index]} {answers[index]}"
|
||||||
# Create the question id
|
# Create the question id
|
||||||
question_id = uuid.uuid4()
|
question_id = uuid.uuid4()
|
||||||
self.answerers[question_id] = {}
|
self._answerers[question_id] = {}
|
||||||
|
|
||||||
# Create the correct and wrong functions
|
# Create the correct and wrong functions
|
||||||
async def correct(data: CommandData):
|
async def correct(data: CommandData):
|
||||||
answerer_ = await data.get_author(error_if_none=True)
|
answerer_ = await data.get_author(error_if_none=True)
|
||||||
try:
|
try:
|
||||||
self.answerers[question_id][answerer_] = True
|
self._answerers[question_id][answerer_] = True
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise KeyboardExpiredError("Question time ran out.")
|
raise KeyboardExpiredError("Question time ran out.")
|
||||||
return "🆗 Hai risposto alla domanda. Ora aspetta un attimo per i risultati!"
|
return "🆗 Hai risposto alla domanda. Ora aspetta un attimo per i risultati!"
|
||||||
|
@ -69,7 +69,7 @@ class TriviaCommand(Command):
|
||||||
async def wrong(data: CommandData):
|
async def wrong(data: CommandData):
|
||||||
answerer_ = await data.get_author(error_if_none=True)
|
answerer_ = await data.get_author(error_if_none=True)
|
||||||
try:
|
try:
|
||||||
self.answerers[question_id][answerer_] = False
|
self._answerers[question_id][answerer_] = False
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise KeyboardExpiredError("Question time ran out.")
|
raise KeyboardExpiredError("Question time ran out.")
|
||||||
return "🆗 Hai risposto alla domanda. Ora aspetta un attimo per i risultati!"
|
return "🆗 Hai risposto alla domanda. Ora aspetta un attimo per i risultati!"
|
||||||
|
@ -85,10 +85,11 @@ class TriviaCommand(Command):
|
||||||
await asyncio.sleep(self._answer_time)
|
await asyncio.sleep(self._answer_time)
|
||||||
results = f"❗️ Tempo scaduto!\n" \
|
results = f"❗️ Tempo scaduto!\n" \
|
||||||
f"La risposta corretta era [b]{answers[correct_index]}[/b]!\n\n"
|
f"La risposta corretta era [b]{answers[correct_index]}[/b]!\n\n"
|
||||||
for answerer in self.answerers[question_id]:
|
for answerer in self._answerers[question_id]:
|
||||||
if self.answerers[question_id][answerer]:
|
if self._answerers[question_id][answerer]:
|
||||||
results += self._correct_emoji
|
results += self._correct_emoji
|
||||||
else:
|
else:
|
||||||
results += self._wrong_emoji
|
results += self._wrong_emoji
|
||||||
results += f" {answerer}"
|
results += f" {answerer}"
|
||||||
await data.reply(results)
|
await data.reply(results)
|
||||||
|
del self._answerers[question_id]
|
||||||
|
|
Loading…
Reference in a new issue