2024-12-24 18:08:03 +00:00
|
|
|
from aiogram import F
|
|
|
|
from aiogram_dialog import Dialog, Window
|
|
|
|
from aiogram_dialog.widgets.input import TextInput
|
|
|
|
from aiogram_dialog.widgets.kbd import (
|
|
|
|
Back,
|
|
|
|
Button,
|
|
|
|
Group,
|
|
|
|
Row,
|
|
|
|
ScrollingGroup,
|
|
|
|
Select,
|
|
|
|
Start,
|
|
|
|
SwitchTo,
|
|
|
|
)
|
|
|
|
from aiogram_dialog.widgets.text import Const, Format, Multi
|
|
|
|
from pydantic import NonNegativeInt
|
|
|
|
|
2024-12-25 01:30:33 +00:00
|
|
|
from shopbot.bot.getters import (
|
2024-12-24 18:08:03 +00:00
|
|
|
get_account_details,
|
|
|
|
get_account_info,
|
|
|
|
get_accounts,
|
|
|
|
)
|
2024-12-25 01:30:33 +00:00
|
|
|
from shopbot.bot.getters.filters import (
|
|
|
|
get_filters_info,
|
|
|
|
on_filter_selected,
|
|
|
|
update_filters,
|
|
|
|
)
|
|
|
|
from shopbot.bot.services import on_account_selected, on_buy_button_click
|
|
|
|
from shopbot.bot.states import (
|
2024-12-24 18:08:03 +00:00
|
|
|
PurchaseAccountsSG,
|
|
|
|
StartSG,
|
|
|
|
)
|
|
|
|
|
|
|
|
purchase_accounts_dialog = Dialog(
|
|
|
|
Window(
|
|
|
|
Format("{text}"),
|
|
|
|
SwitchTo(Const("⚙️ Фильтры"), id="filters", state=PurchaseAccountsSG.filters),
|
|
|
|
ScrollingGroup(
|
|
|
|
Select(
|
|
|
|
Format("{item[0]}"),
|
|
|
|
id="account_select",
|
|
|
|
item_id_getter=lambda x: x[1],
|
|
|
|
items="accounts",
|
|
|
|
on_click=on_account_selected,
|
|
|
|
),
|
|
|
|
id="accounts_scrool",
|
|
|
|
width=1,
|
|
|
|
height=6,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
Start(Const("🔙 Назад"), id="back", state=StartSG.start),
|
|
|
|
),
|
|
|
|
state=PurchaseAccountsSG.purchase_accounts,
|
|
|
|
getter=get_accounts,
|
|
|
|
),
|
|
|
|
Window(
|
|
|
|
Const("⚙️<b>Выберите фильтр:</b>"),
|
|
|
|
Group(
|
|
|
|
Select(
|
|
|
|
Multi(
|
|
|
|
Format("{item.name}"),
|
|
|
|
Format(": {item.value}", when=F["item"].value > 0),
|
|
|
|
),
|
|
|
|
id="filter",
|
|
|
|
item_id_getter=lambda _: _.id,
|
|
|
|
items="filters",
|
|
|
|
when="filters",
|
|
|
|
on_click=on_filter_selected,
|
|
|
|
),
|
|
|
|
width=2,
|
|
|
|
),
|
|
|
|
Back(Const("Назад")),
|
|
|
|
state=PurchaseAccountsSG.filters,
|
|
|
|
getter=get_filters_info,
|
|
|
|
),
|
|
|
|
Window(
|
|
|
|
Format(
|
|
|
|
"Введите новое значение для фильтра: {dialog_data[current_filter].value}"
|
|
|
|
),
|
|
|
|
TextInput(
|
|
|
|
id="new_filter_amount",
|
|
|
|
type_factory=NonNegativeInt,
|
|
|
|
on_success=update_filters,
|
|
|
|
),
|
|
|
|
state=PurchaseAccountsSG.enter_filter_value,
|
|
|
|
),
|
|
|
|
Window(
|
|
|
|
Format("{account_info}"),
|
|
|
|
Button(
|
|
|
|
Const("💸 Купить"),
|
|
|
|
id="buy_button",
|
|
|
|
on_click=on_buy_button_click,
|
|
|
|
when=lambda data,
|
|
|
|
widget,
|
|
|
|
manager: not manager.current_context().dialog_data.get("purchased", False),
|
|
|
|
),
|
|
|
|
Button(
|
|
|
|
Const("🔙 Назад"),
|
|
|
|
id="back",
|
|
|
|
on_click=Back(),
|
|
|
|
),
|
|
|
|
state=PurchaseAccountsSG.account_details,
|
|
|
|
getter=get_account_details,
|
|
|
|
),
|
|
|
|
Window(
|
|
|
|
Const("🎉 Поздравляем! Вы успешно приобрели аккаунт.\n"),
|
|
|
|
Format("{account_info}"),
|
|
|
|
Start(Const("🔙 Вернуться"), id="back", state=StartSG.start),
|
|
|
|
state=PurchaseAccountsSG.purchase_completed,
|
|
|
|
getter=get_account_info,
|
|
|
|
),
|
|
|
|
)
|