Add experimental getgamebychannel function

This commit is contained in:
Cal Corum 2024-10-12 09:26:55 -05:00 committed by GitHub
parent 0deb547257
commit 57610fe8a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 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() 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): class Gameplay(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot