mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Add some things to trivia
This commit is contained in:
parent
4759f1951a
commit
0accb1176e
2 changed files with 26 additions and 1 deletions
|
@ -18,8 +18,12 @@ class TriviaCommand(Command):
|
||||||
|
|
||||||
tables = {TriviaScore}
|
tables = {TriviaScore}
|
||||||
|
|
||||||
|
syntax = "[credits|scores]"
|
||||||
|
|
||||||
_letter_emojis = ["🇦", "🇧", "🇨", "🇩"]
|
_letter_emojis = ["🇦", "🇧", "🇨", "🇩"]
|
||||||
|
|
||||||
|
_medal_emojis = ["🥇", "🥈", "🥉", "🔹"]
|
||||||
|
|
||||||
_correct_emoji = "✅"
|
_correct_emoji = "✅"
|
||||||
|
|
||||||
_wrong_emoji = "❌"
|
_wrong_emoji = "❌"
|
||||||
|
@ -33,6 +37,23 @@ class TriviaCommand(Command):
|
||||||
self._answerers: typing.Dict[uuid.UUID, typing.Dict[str, bool]] = {}
|
self._answerers: typing.Dict[uuid.UUID, typing.Dict[str, bool]] = {}
|
||||||
|
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
|
arg = args.optional(0)
|
||||||
|
if arg == "credits":
|
||||||
|
await data.reply(f"ℹ️ [c]{self.interface.prefix}{self.name}[/c] di [i]Steffo[/i]\n"
|
||||||
|
f"\n"
|
||||||
|
f"Tutte le domande vengono dall'[b]Open Trivia Database[/b] di [i]Pixeltail Games[/i],"
|
||||||
|
f" creatori di Tower Unite, e sono rilasciate sotto la licenza [b]CC BY-SA 4.0[/b].")
|
||||||
|
return
|
||||||
|
elif arg == "scores":
|
||||||
|
trivia_scores = await asyncify(data.session.query(self.alchemy.TriviaScore).all())
|
||||||
|
strings = ["🏆 [b]Trivia Leaderboards[/b]\n"]
|
||||||
|
for index, ts in sorted(trivia_scores, key=lambda ts: -ts.correct_rate):
|
||||||
|
if index > 3:
|
||||||
|
index = 3
|
||||||
|
strings.append(f"{self._medal_emojis[index]} {ts.royal.username}"
|
||||||
|
f" ({ts.correct_answers}/{ts.total_answers})")
|
||||||
|
await data.reply("\n".join(strings))
|
||||||
|
return
|
||||||
if self._question_lock:
|
if self._question_lock:
|
||||||
raise CommandError("C'è già un'altra domanda attiva!")
|
raise CommandError("C'è già un'altra domanda attiva!")
|
||||||
self._question_lock = True
|
self._question_lock = True
|
||||||
|
@ -104,7 +125,7 @@ class TriviaCommand(Command):
|
||||||
if answerer.trivia_score is None:
|
if answerer.trivia_score is None:
|
||||||
ts = self.interface.alchemy.TriviaScore(royal=answerer)
|
ts = self.interface.alchemy.TriviaScore(royal=answerer)
|
||||||
data.session.add(ts)
|
data.session.add(ts)
|
||||||
data.session.commit()
|
await asyncify(data.session.commit)
|
||||||
if self._answerers[question_id][answerer_id]:
|
if self._answerers[question_id][answerer_id]:
|
||||||
results += self._correct_emoji
|
results += self._correct_emoji
|
||||||
answerer.trivia_score.correct_answers += 1
|
answerer.trivia_score.correct_answers += 1
|
||||||
|
|
|
@ -32,5 +32,9 @@ class TriviaScore:
|
||||||
def offset(self):
|
def offset(self):
|
||||||
return self.correct_answers - self.wrong_answers
|
return self.correct_answers - self.wrong_answers
|
||||||
|
|
||||||
|
@property
|
||||||
|
def correct_rate(self):
|
||||||
|
return self.correct_answers / self.total_answers
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<TriviaScore of {self.royal}: ({self.correct_answers}|{self.wrong_answers})>"
|
return f"<TriviaScore of {self.royal}: ({self.correct_answers}|{self.wrong_answers})>"
|
||||||
|
|
Loading…
Reference in a new issue