1
Fork 0
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:
Steffo 2019-09-03 16:09:22 +02:00
parent 807f0998b4
commit e2db40943d
3 changed files with 40 additions and 3 deletions

View file

@ -7,7 +7,9 @@ from ..command import Command
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ..commandinterface import CommandInterface
from ...utils import asyncify
from ...error import *
from ...database.tables import TriviaScore
class TriviaCommand(Command):
@ -15,13 +17,15 @@ class TriviaCommand(Command):
description: str = "Manda una domanda dell'OpenTDB in chat."
require_alchemy_tables = {TriviaScore}
_letter_emojis = ["🇦", "🇧", "🇨", "🇩"]
_correct_emoji = ""
_wrong_emoji = ""
_answer_time = 15
_answer_time = 18
def __init__(self, interface: CommandInterface):
super().__init__(interface)
@ -88,8 +92,11 @@ class TriviaCommand(Command):
for answerer in self._answerers[question_id]:
if self._answerers[question_id][answerer]:
results += self._correct_emoji
answerer.trivia_score.correct_answers += 1
else:
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)
del self._answerers[question_id]
await asyncify(self.interface.session.commit)

View file

@ -12,6 +12,7 @@ from .medals import Medal
from .medalawards import MedalAward
from .bios import Bio
from .reminders import Reminder
from .triviascores import TriviaScore
__all__ = ["Royal", "Telegram", "Diario", "Alias", "ActiveKvGroup", "Keyvalue", "Keygroup", "Discord", "WikiPage",
"WikiRevision", "Medal", "MedalAward", "Bio", "Reminder"]
"WikiRevision", "Medal", "MedalAward", "Bio", "Reminder", "TriviaScore"]

View 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})>"