Fix wordle code

This commit is contained in:
stijndcl 2022-08-29 20:49:29 +02:00
parent 8a4baf6bb8
commit 73d44de46e
11 changed files with 58 additions and 48 deletions

View file

@ -17,7 +17,7 @@ async def add_birthday(session: AsyncSession, user_id: int, birthday: date):
If already present, overwrites the existing one
"""
user = await users.get_or_add(session, user_id, options=[selectinload(User.birthday)])
user = await users.get_or_add_user(session, user_id, options=[selectinload(User.birthday)])
if user.birthday is not None:
bd = user.birthday

View file

@ -29,13 +29,13 @@ NIGHTLY_AMOUNT = 420
async def get_bank(session: AsyncSession, user_id: int) -> Bank:
"""Get a user's bank info"""
user = await users.get_or_add(session, user_id)
user = await users.get_or_add_user(session, user_id)
return user.bank
async def get_nightly_data(session: AsyncSession, user_id: int) -> NightlyData:
"""Get a user's nightly info"""
user = await users.get_or_add(session, user_id)
user = await users.get_or_add_user(session, user_id)
return user.nightly_data

View file

@ -6,11 +6,11 @@ from sqlalchemy.ext.asyncio import AsyncSession
from database.schemas import Bank, NightlyData, User
__all__ = [
"get_or_add",
"get_or_add_user",
]
async def get_or_add(session: AsyncSession, user_id: int, *, options: Optional[list] = None) -> User:
async def get_or_add_user(session: AsyncSession, user_id: int, *, options: Optional[list] = None) -> User:
"""Get a user's profile
If it doesn't exist yet, create it (along with all linked datastructures)

View file

@ -4,6 +4,7 @@ from typing import Optional
from sqlalchemy import delete, select
from sqlalchemy.ext.asyncio import AsyncSession
from database.crud.users import get_or_add_user
from database.schemas import WordleGuess, WordleWord
__all__ = [
@ -16,6 +17,7 @@ __all__ = [
async def get_active_wordle_game(session: AsyncSession, user_id: int) -> list[WordleGuess]:
"""Find a player's active game"""
await get_or_add_user(session, user_id)
statement = select(WordleGuess).where(WordleGuess.user_id == user_id)
guesses = (await session.execute(statement)).scalars().all()
return guesses

View file

@ -121,7 +121,7 @@ class WordleCache(DatabaseCache):
async def invalidate(self, database_session: AsyncSession):
word = await wordle.get_daily_word(database_session)
if word is not None:
self.data = [word]
self.data = [word.word]
class CacheManager: