mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 23:55:46 +02:00
Fix wordle code
This commit is contained in:
parent
8a4baf6bb8
commit
73d44de46e
11 changed files with 58 additions and 48 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue