From 2a0e8518f0d538d69bec46b5b98307c66dfddf9d Mon Sep 17 00:00:00 2001 From: Yuriy Chebyshev Date: Mon, 31 Jul 2023 23:22:21 +0300 Subject: [PATCH] added my team start button --- shvatka/tgbot/dialogs/main_menu/dialogs.py | 6 ++++++ shvatka/tgbot/dialogs/team_view/__init__.py | 3 ++- shvatka/tgbot/dialogs/team_view/dialogs.py | 23 ++++++++++++++++++++- shvatka/tgbot/dialogs/team_view/handlers.py | 11 ++++++++++ shvatka/tgbot/states.py | 4 ++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/shvatka/tgbot/dialogs/main_menu/dialogs.py b/shvatka/tgbot/dialogs/main_menu/dialogs.py index c415fd53..03a14916 100644 --- a/shvatka/tgbot/dialogs/main_menu/dialogs.py +++ b/shvatka/tgbot/dialogs/main_menu/dialogs.py @@ -48,6 +48,12 @@ state=states.PromotionSG.disclaimer, when=F["player"].can_be_author, ), + Start( + Const("🚩Моя ΠΊΠΎΠΌΠ°Π½Π΄Π°"), + id="my_team", + state=states.MyTeamSg.team, + when=F["team"], + ), Start( Const("πŸš©Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄ΠΎΠΉ"), id="to_team_manage", diff --git a/shvatka/tgbot/dialogs/team_view/__init__.py b/shvatka/tgbot/dialogs/team_view/__init__.py index 0a71b9ca..07f91eb7 100644 --- a/shvatka/tgbot/dialogs/team_view/__init__.py +++ b/shvatka/tgbot/dialogs/team_view/__init__.py @@ -1,7 +1,8 @@ from aiogram import Router -from .dialogs import team_view +from .dialogs import team_view, my_team_view def setup(router: Router): router.include_router(team_view) + router.include_router(my_team_view) diff --git a/shvatka/tgbot/dialogs/team_view/dialogs.py b/shvatka/tgbot/dialogs/team_view/dialogs.py index 2f2662db..4fb7df84 100644 --- a/shvatka/tgbot/dialogs/team_view/dialogs.py +++ b/shvatka/tgbot/dialogs/team_view/dialogs.py @@ -4,7 +4,13 @@ from shvatka.tgbot import states from .getters import teams_getter, team_getter, filter_getter -from .handlers import select_team, select_player, change_active_filter, change_archive_filter +from .handlers import ( + select_team, + select_player, + change_active_filter, + change_archive_filter, + on_start_my_team, +) from ..common import BOOL_VIEW team_view = Dialog( @@ -71,3 +77,18 @@ state=states.TeamsSg.filter, ), ) + + +my_team_view = Dialog( + Window( + Jinja( + "Моя ΠΊΠΎΠΌΠ°Π½Π΄Π°: {{team.name }} \n" + "Наш ΠΊΠ°ΠΏΠΈΡ‚Π°Π½: {{team.captain.name_mention}}\n" + "Π‘Ρ‹Π³Ρ€Π°Π½Π½Ρ‹Π΅ ΠΈΠ³Ρ€Ρ‹: {{' '.join(game_numbers)}}" + ), + Cancel(Const("πŸ”™Π’Ρ‹Ρ…ΠΎΠ΄")), + getter=team_getter, + state=states.MyTeamSg.team, + ), + on_start=on_start_my_team, +) diff --git a/shvatka/tgbot/dialogs/team_view/handlers.py b/shvatka/tgbot/dialogs/team_view/handlers.py index dcd33a41..5a820c44 100644 --- a/shvatka/tgbot/dialogs/team_view/handlers.py +++ b/shvatka/tgbot/dialogs/team_view/handlers.py @@ -4,6 +4,9 @@ from aiogram_dialog import DialogManager from aiogram_dialog.widgets.kbd import Button +from shvatka.core.models import dto +from shvatka.core.services.player import get_my_team +from shvatka.infrastructure.db.dao.holder import HolderDao from shvatka.tgbot import states from shvatka.tgbot.dialogs.team_view.common import get_active_filter, get_archive_filter @@ -23,3 +26,11 @@ async def change_active_filter(c: CallbackQuery, button: Button, manager: Dialog async def change_archive_filter(c: CallbackQuery, button: Button, manager: DialogManager): manager.dialog_data[button.widget_id] = not get_archive_filter(manager) + + +async def on_start_my_team(start_data: dict, manager: DialogManager) -> None: + dao: HolderDao = manager.middleware_data["dao"] + player: dto.Player = manager.middleware_data["player"] + team = await get_my_team(player=player, dao=dao.team_player) + assert team + manager.dialog_data["team_id"] = team.id diff --git a/shvatka/tgbot/states.py b/shvatka/tgbot/states.py index 9f516b8d..04524197 100644 --- a/shvatka/tgbot/states.py +++ b/shvatka/tgbot/states.py @@ -126,5 +126,9 @@ class TeamsSg(StatesGroup): one = State() +class MyTeamSg(StatesGroup): + team = State() + + class PlayerSg(StatesGroup): main = State()