44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Сервис экономики: очищение, яички, монетки."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from common.models import EggsResult, PurificationResult
|
|
from common.repositories import economy_repo
|
|
|
|
#: id действия для начисления монеток.
|
|
ACTION_COIN = 1
|
|
|
|
|
|
async def purify(id_user: int) -> PurificationResult:
|
|
"""Выполнить ежедневное очищение."""
|
|
row = await economy_repo.purification(id_user)
|
|
if not row:
|
|
return PurificationResult(success=False)
|
|
return PurificationResult(
|
|
success=int(row.get("res") or 0) != 0,
|
|
exp_add=int(row.get("expr_add") or 0),
|
|
money_add=int(row.get("mny_add") or 0),
|
|
hours=int(row.get("h") or 0),
|
|
minutes=int(row.get("m") or 0),
|
|
seconds=int(row.get("s") or 0),
|
|
)
|
|
|
|
|
|
async def collect_eggs(id_user: int) -> EggsResult:
|
|
"""Получить ежедневные яички."""
|
|
row = await economy_repo.add_eggs(id_user)
|
|
if not row:
|
|
return EggsResult(success=False)
|
|
return EggsResult(
|
|
success=int(row.get("res") or 0) != 0,
|
|
eggs=int(row.get("eggs_add") or 0),
|
|
hours=int(row.get("h") or 0),
|
|
minutes=int(row.get("m") or 0),
|
|
seconds=int(row.get("s") or 0),
|
|
)
|
|
|
|
|
|
async def add_coins(id_user: int, amount: int) -> None:
|
|
"""Начислить монеты."""
|
|
await economy_repo.money_action(id_user, amount, ACTION_COIN)
|