From 57610fe8a79bcf8f9c96011200d540eacc9a135b Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 12 Oct 2024 09:26:55 -0500 Subject: [PATCH] Add experimental getgamebychannel function --- cogs/gameplay.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cogs/gameplay.py b/cogs/gameplay.py index 18bd4c2..148ecf0 100644 --- a/cogs/gameplay.py +++ b/cogs/gameplay.py @@ -11,10 +11,20 @@ from in_game.data_cache import get_pd_team from in_game.gameplay_db import Session, engine, create_db_and_tables, select, Game -def get_games_by_channel(session: Session, channel_id: int): +def get_games_by_channel(session: Session, channel_id: int) -> list[Game]: + # TODO: test .all() on empty return return session.exec(select(Game).where(Game.channel_id == channel_id)).all() +def get_channel_game_or_none(session: Session, channel_id: int) -> Game | None: + all_games = get_games_by_channel(session, channel_id) + if len(all_games) > 1: + pass # TODO: raise an exception + elif len(all_games) == 0: + return None + return all_games[0] + + class Gameplay(commands.Cog): def __init__(self, bot): self.bot = bot