diff --git a/shvatka/tgbot/dialogs/game_manage/getters.py b/shvatka/tgbot/dialogs/game_manage/getters.py index 26e497a3..e3b79f22 100644 --- a/shvatka/tgbot/dialogs/game_manage/getters.py +++ b/shvatka/tgbot/dialogs/game_manage/getters.py @@ -5,6 +5,7 @@ from aiogram_dialog import DialogManager from aiogram_dialog.api.entities import MediaAttachment, MediaId from dishka import AsyncContainer +from dishka.integrations.aiogram import CONTAINER_NAME from telegraph import Telegraph from shvatka.common.url_factory import UrlFactory @@ -30,7 +31,7 @@ async def get_completed_game(dao: HolderDao, dialog_manager: DialogManager, **_) game_id = ( dialog_manager.dialog_data.get("game_id", None) or dialog_manager.start_data["game_id"] ) - dishka: AsyncContainer = dialog_manager.middleware_data["dishka_container"] + dishka: AsyncContainer = dialog_manager.middleware_data[CONTAINER_NAME] url_factory = await dishka.get(UrlFactory) return { "game": await game.get_game( diff --git a/shvatka/tgbot/dialogs/level_manage/getters.py b/shvatka/tgbot/dialogs/level_manage/getters.py index 07990bd8..a61a70bd 100644 --- a/shvatka/tgbot/dialogs/level_manage/getters.py +++ b/shvatka/tgbot/dialogs/level_manage/getters.py @@ -6,7 +6,6 @@ from shvatka.core.services.level import get_by_id, get_level_by_id_for_org, get_all_my_free_levels from shvatka.core.services.organizers import get_org_by_id, get_by_player from shvatka.infrastructure.db.dao.holder import HolderDao -from shvatka.tgbot.views.utils import render_time_hints async def get_level_id(dao: HolderDao, dialog_manager: DialogManager, **_): diff --git a/shvatka/tgbot/dialogs/level_scn/dialogs.py b/shvatka/tgbot/dialogs/level_scn/dialogs.py index af84acba..0ebb9d83 100644 --- a/shvatka/tgbot/dialogs/level_scn/dialogs.py +++ b/shvatka/tgbot/dialogs/level_scn/dialogs.py @@ -2,7 +2,7 @@ from aiogram_dialog import Dialog, Window from aiogram_dialog.widgets.input import TextInput from aiogram_dialog.widgets.kbd import Button, Cancel, ScrollingGroup, Select -from aiogram_dialog.widgets.text import Const, Jinja, Format +from aiogram_dialog.widgets.text import Const, Jinja from shvatka.tgbot import states from .getters import get_time_hints, get_level_id, get_level_data, get_keys, get_bonus_keys @@ -26,7 +26,8 @@ convert_bonus_keys, on_correct_bonus_keys, not_correct_bonus_keys, - start_bonus_keys, start_edit_time_hint, + start_bonus_keys, + start_edit_time_hint, ) level = Dialog( diff --git a/shvatka/tgbot/dialogs/level_scn/getters.py b/shvatka/tgbot/dialogs/level_scn/getters.py index 0b1398ec..917a2699 100644 --- a/shvatka/tgbot/dialogs/level_scn/getters.py +++ b/shvatka/tgbot/dialogs/level_scn/getters.py @@ -3,7 +3,6 @@ from shvatka.core.models.dto import scn from shvatka.core.models.dto.scn import TimeHint -from shvatka.tgbot.views.utils import render_time_hints async def get_level_id(dialog_manager: DialogManager, **_): diff --git a/shvatka/tgbot/dialogs/level_scn/handlers.py b/shvatka/tgbot/dialogs/level_scn/handlers.py index e4eb504b..1dfbb89d 100644 --- a/shvatka/tgbot/dialogs/level_scn/handlers.py +++ b/shvatka/tgbot/dialogs/level_scn/handlers.py @@ -4,7 +4,6 @@ from aiogram_dialog import Data, DialogManager from aiogram_dialog.widgets.kbd import Button from dataclass_factory import Factory -from dishka import AsyncContainer from shvatka.core.models import dto from shvatka.core.models.dto import scn @@ -17,7 +16,6 @@ ) from shvatka.infrastructure.db.dao.holder import HolderDao from shvatka.tgbot import states -from shvatka.tgbot.views.hint_sender import HintSender def check_level_id(name_id: str) -> str: @@ -135,24 +133,17 @@ async def on_start_hints_edit(start_data: dict[str, Any], manager: DialogManager manager.dialog_data["time_hints"] = start_data["time_hints"] -async def start_edit_time_hint(c: CallbackQuery, widget: Any, manager: DialogManager, hint_time: str): +async def start_edit_time_hint( + c: CallbackQuery, widget: Any, manager: DialogManager, hint_time: str +): dcf: Factory = manager.middleware_data["dcf"] hints = dcf.load(manager.dialog_data.get("time_hints", []), list[scn.TimeHint]) await manager.start( state=states.TimeHintEditSG.details, - data={"time_hint": dcf.dump(next(filter(lambda x: x.time == int(hint_time), hints)))} + data={"time_hint": dcf.dump(next(filter(lambda x: x.time == int(hint_time), hints)))}, ) -async def edit_single_hint(c: CallbackQuery, widget: Any, manager: DialogManager, hint_index: str): - dcf: Factory = manager.middleware_data["dcf"] - dishka: AsyncContainer = manager.middleware_data["dishka_container"] - hint = dcf.load(manager.start_data.get("time_hint"), scn.TimeHint) - hint_sender = await dishka.get(HintSender) - await hint_sender.send_hint(hint.hint[int(hint_index)], c.message.chat.id) - - - async def start_add_time_hint(c: CallbackQuery, button: Button, manager: DialogManager): dcf: Factory = manager.middleware_data["dcf"] hints = dcf.load(manager.dialog_data.get("time_hints", []), list[scn.TimeHint]) diff --git a/shvatka/tgbot/dialogs/time_hint/dialogs.py b/shvatka/tgbot/dialogs/time_hint/dialogs.py index 2d0663ea..8b52afe7 100644 --- a/shvatka/tgbot/dialogs/time_hint/dialogs.py +++ b/shvatka/tgbot/dialogs/time_hint/dialogs.py @@ -1,14 +1,29 @@ from aiogram_dialog import Dialog, Window from aiogram_dialog.widgets.input import MessageInput -from aiogram_dialog.widgets.kbd import Select, Button, Group, Back, Cancel, SwitchTo, ScrollingGroup +from aiogram_dialog.widgets.kbd import ( + Select, + Button, + Group, + Back, + Cancel, + SwitchTo, + ScrollingGroup, +) from aiogram_dialog.widgets.text import Const, Format, Case, Jinja from shvatka.tgbot import states from .getters import get_available_times, get_hints -from .handlers import process_time_message, select_time, process_hint, on_finish, hint_on_start, hint_edit_on_start, \ - process_edit_time_message +from .handlers import ( + process_time_message, + select_time, + process_hint, + on_finish, + hint_on_start, + hint_edit_on_start, + process_edit_time_message, + edit_single_hint, +) from shvatka.tgbot.dialogs.preview_data import TIMES_PRESET -from ..level_scn.handlers import start_edit_time_hint, edit_single_hint time_hint = Dialog( Window( @@ -60,10 +75,7 @@ time_hint_edit = Dialog( Window( - Jinja( - "Подсказка выходящая в {{time}}:" - "{{hints | hints}}" - ), + Jinja("Подсказка выходящая в {{time}}:" "{{hints | hints}}"), SwitchTo( Const("Изменить время"), id="change_time", @@ -86,9 +98,7 @@ state=states.TimeHintEditSG.details, ), Window( - Jinja( - "Введи новое время выхода подсказки" - ), + Jinja("Введи новое время выхода подсказки"), MessageInput(func=process_edit_time_message), getter=get_hints, state=states.TimeHintEditSG.time, diff --git a/shvatka/tgbot/dialogs/time_hint/getters.py b/shvatka/tgbot/dialogs/time_hint/getters.py index 35f97cee..1d173396 100644 --- a/shvatka/tgbot/dialogs/time_hint/getters.py +++ b/shvatka/tgbot/dialogs/time_hint/getters.py @@ -2,7 +2,6 @@ from dataclass_factory import Factory from shvatka.core.models.dto.scn.hint_part import AnyHint -from shvatka.tgbot.views.utils import render_hints async def get_available_times(dialog_manager: DialogManager, **_): diff --git a/shvatka/tgbot/dialogs/time_hint/handlers.py b/shvatka/tgbot/dialogs/time_hint/handlers.py index 7f8e85f7..54ce1115 100644 --- a/shvatka/tgbot/dialogs/time_hint/handlers.py +++ b/shvatka/tgbot/dialogs/time_hint/handlers.py @@ -1,15 +1,19 @@ from typing import Any +from aiogram import types from aiogram.types import CallbackQuery, Message from aiogram_dialog import DialogManager from aiogram_dialog.widgets.kbd import Button from dataclass_factory import Factory +from dishka import AsyncContainer +from dishka.integrations.aiogram import CONTAINER_NAME from shvatka.core.models.dto import scn from shvatka.core.models.dto.scn import TimeHint from shvatka.core.models.dto.scn.hint_part import AnyHint from shvatka.tgbot import states from shvatka.tgbot.views.hint_factory.hint_parser import HintParser +from shvatka.tgbot.views.hint_sender import HintSender async def select_time(c: CallbackQuery, widget: Any, manager: DialogManager, item_id: str): @@ -38,6 +42,15 @@ async def process_time_message(m: Message, dialog_: Any, manager: DialogManager) await m.answer("Время выхода данной подсказки должно быть больше, чем предыдущей") +async def edit_single_hint(c: CallbackQuery, widget: Any, manager: DialogManager, hint_index: str): + dishka: AsyncContainer = manager.middleware_data[CONTAINER_NAME] + dcf = await dishka.get(Factory) + hint = dcf.load(manager.start_data.get("time_hint"), scn.TimeHint) + hint_sender = await dishka.get(HintSender) + chat: types.Chat = manager.middleware_data["event_from_chat"] + await hint_sender.send_hint(hint.hint[int(hint_index)], chat.id) + + async def set_time(time_minutes: int, manager: DialogManager): if time_minutes <= int(manager.start_data["previous_time"]): raise ValueError("Время меньше предыдущего") diff --git a/shvatka/tgbot/views/jinja_filters/__init__.py b/shvatka/tgbot/views/jinja_filters/__init__.py index f6e70502..d8dd418c 100644 --- a/shvatka/tgbot/views/jinja_filters/__init__.py +++ b/shvatka/tgbot/views/jinja_filters/__init__.py @@ -6,7 +6,12 @@ from .boolean_emoji import bool_render from .game_status import to_readable_name from .timezone import datetime_filter, timedelta_filter -from ..utils import render_single_hint, render_hints, render_time_hint, render_time_hints +from shvatka.tgbot.views.utils import ( + render_single_hint, + render_hints, + render_time_hint, + render_time_hints, +) def setup_jinja(bot: Bot):