Skip to content

Commit

Permalink
added my team start button
Browse files Browse the repository at this point in the history
  • Loading branch information
bomzheg committed Jul 31, 2023
1 parent 3045ef0 commit 2a0e851
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions shvatka/tgbot/dialogs/main_menu/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion shvatka/tgbot/dialogs/team_view/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 22 additions & 1 deletion shvatka/tgbot/dialogs/team_view/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
11 changes: 11 additions & 0 deletions shvatka/tgbot/dialogs/team_view/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 4 additions & 0 deletions shvatka/tgbot/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,9 @@ class TeamsSg(StatesGroup):
one = State()


class MyTeamSg(StatesGroup):
team = State()


class PlayerSg(StatesGroup):
main = State()

0 comments on commit 2a0e851

Please sign in to comment.