コード例 #1
0
ファイル: message.py プロジェクト: livestreamx/quiz-bot
 def save(self, text: str) -> None:
     with db.create_session() as session:
         session.add(db.Message(text))
コード例 #2
0
 def get_challenge(self, challenge_id: int) -> Optional[ContextChallenge]:
     with db.create_session() as session:
         challenge = session.query(db.Challenge).get(challenge_id)
         if challenge is None:
             return None
         return cast(ContextChallenge, ContextChallenge.from_orm(challenge))
コード例 #3
0
 def get_finished_challenge_ids(self) -> Sequence[int]:
     with db.create_session() as session:
         return cast(Sequence[int],
                     session.query(db.Challenge).get_finished_ids())
コード例 #4
0
 def increment_score(self, participant_id: int) -> None:
     with db.create_session() as session:
         db_participant = session.query(db.Participant).get(participant_id)
         db_participant.scores += 1
コード例 #5
0
 def finish_participation(self, participant_id: int,
                          finished_at: datetime.datetime) -> None:
     with db.create_session() as session:
         db_participant = session.query(db.Participant).get(participant_id)
         db_participant.finished_at = finished_at
コード例 #6
0
 def has_all_winners(self, challenge_id: int, winner_amount: int) -> bool:
     with db.create_session() as session:
         db_pretenders: Sequence[db.Participant] = session.query(
             db.Participant).get_sorted_pretenders(
                 challenge_id=challenge_id, limit=winner_amount)
         return len(db_pretenders) == winner_amount
コード例 #7
0
 def finish_phase(self, result: ContextResult,
                  finish_time: datetime) -> None:
     with db.create_session() as session:
         db_result = session.query(db.Result).get(result.id)
         db_result.finished_at = finish_time
コード例 #8
0
 def create_result(self, participant_id: int, phase: int) -> ContextResult:
     with db.create_session() as session:
         db_result = db.Result(participant_id=participant_id, phase=phase)
         session.add(db_result)
         session.flush()
         return cast(ContextResult, ContextResult.from_orm(db_result))
コード例 #9
0
 def get_user_by_nick_name(self, nick_name: str) -> Optional[ContextUser]:
     with db.create_session() as session:
         internal_user = session.query(db.User).get_by_nick_name(nick_name)
         if internal_user is None:
             return None
         return cast(ContextUser, ContextUser.from_orm(internal_user))
コード例 #10
0
 def get_user(self, user: telebot.types.User) -> Optional[ContextUser]:
     with db.create_session() as session:
         internal_user = session.query(db.User).get_by_external_id(user.id)
         if internal_user is None:
             return None
         return cast(ContextUser, ContextUser.from_orm(internal_user))