mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Track trivia scores
This commit is contained in:
parent
807f0998b4
commit
e2db40943d
3 changed files with 40 additions and 3 deletions
|
@ -7,7 +7,9 @@ from ..command import Command
|
||||||
from ..commandargs import CommandArgs
|
from ..commandargs import CommandArgs
|
||||||
from ..commanddata import CommandData
|
from ..commanddata import CommandData
|
||||||
from ..commandinterface import CommandInterface
|
from ..commandinterface import CommandInterface
|
||||||
|
from ...utils import asyncify
|
||||||
from ...error import *
|
from ...error import *
|
||||||
|
from ...database.tables import TriviaScore
|
||||||
|
|
||||||
|
|
||||||
class TriviaCommand(Command):
|
class TriviaCommand(Command):
|
||||||
|
@ -15,13 +17,15 @@ class TriviaCommand(Command):
|
||||||
|
|
||||||
description: str = "Manda una domanda dell'OpenTDB in chat."
|
description: str = "Manda una domanda dell'OpenTDB in chat."
|
||||||
|
|
||||||
|
require_alchemy_tables = {TriviaScore}
|
||||||
|
|
||||||
_letter_emojis = ["🇦", "🇧", "🇨", "🇩"]
|
_letter_emojis = ["🇦", "🇧", "🇨", "🇩"]
|
||||||
|
|
||||||
_correct_emoji = "✅"
|
_correct_emoji = "✅"
|
||||||
|
|
||||||
_wrong_emoji = "❌"
|
_wrong_emoji = "❌"
|
||||||
|
|
||||||
_answer_time = 15
|
_answer_time = 18
|
||||||
|
|
||||||
def __init__(self, interface: CommandInterface):
|
def __init__(self, interface: CommandInterface):
|
||||||
super().__init__(interface)
|
super().__init__(interface)
|
||||||
|
@ -88,8 +92,11 @@ class TriviaCommand(Command):
|
||||||
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
|
||||||
|
answerer.trivia_score.correct_answers += 1
|
||||||
else:
|
else:
|
||||||
results += self._wrong_emoji
|
results += self._wrong_emoji
|
||||||
results += f" {answerer}\n"
|
answerer.trivia_score.wrong_answers += 1
|
||||||
|
results += f" {answerer} ({answerer.trivia_score.correct_answers}|{answerer.trivia_score.wrong_answers})\n"
|
||||||
await data.reply(results)
|
await data.reply(results)
|
||||||
del self._answerers[question_id]
|
del self._answerers[question_id]
|
||||||
|
await asyncify(self.interface.session.commit)
|
||||||
|
|
|
@ -12,6 +12,7 @@ from .medals import Medal
|
||||||
from .medalawards import MedalAward
|
from .medalawards import MedalAward
|
||||||
from .bios import Bio
|
from .bios import Bio
|
||||||
from .reminders import Reminder
|
from .reminders import Reminder
|
||||||
|
from .triviascores import TriviaScore
|
||||||
|
|
||||||
__all__ = ["Royal", "Telegram", "Diario", "Alias", "ActiveKvGroup", "Keyvalue", "Keygroup", "Discord", "WikiPage",
|
__all__ = ["Royal", "Telegram", "Diario", "Alias", "ActiveKvGroup", "Keyvalue", "Keygroup", "Discord", "WikiPage",
|
||||||
"WikiRevision", "Medal", "MedalAward", "Bio", "Reminder"]
|
"WikiRevision", "Medal", "MedalAward", "Bio", "Reminder", "TriviaScore"]
|
||||||
|
|
29
royalnet/database/tables/triviascores.py
Normal file
29
royalnet/database/tables/triviascores.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
from sqlalchemy import Column, \
|
||||||
|
Integer, \
|
||||||
|
ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship, backref
|
||||||
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
|
from .royals import Royal
|
||||||
|
|
||||||
|
|
||||||
|
class TriviaScore:
|
||||||
|
__tablename__ = "triviascores"
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def royal_id(self):
|
||||||
|
return Column(Integer, ForeignKey("royals.uid"), primary_key=True)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def royal(self):
|
||||||
|
return relationship("Royal", backref=backref("trivia_score", uselist=False))
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def correct_answers(self):
|
||||||
|
return Column(Integer, nullable=False, default=0)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def wrong_answers(self):
|
||||||
|
return Column(Integer, nullable=False, default=0)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<TriviaScore of {self.royal}: ({self.correct_answers}|{self.wrong_answers})>"
|
Loading…
Reference in a new issue