Exemplo n.º 1
0
from aiogram_dialog.widgets.kbd import Row, SwitchTo, Next, Back
from aiogram_dialog.widgets.text import Const


class DialogSG(StatesGroup):
    first = State()
    second = State()
    third = State()


dialog = Dialog(
    Window(
        Const("First"),
        SwitchTo(Const("To second"), id="sec", state=DialogSG.second),
        state=DialogSG.first,
    ),
    Window(
        Const("Second"),
        Row(
            Back(),
            Next(),
        ),
        state=DialogSG.second,
    ),
    Window(
        Const("Third"),
        Back(),
        state=DialogSG.third,
    )
)
Exemplo n.º 2
0
        multiselect,
        Button(Format("{now}"), "b3"),
        Row(Button(Progress("progress", 5), "b3"), Button(Progress("progress2", 5, filled="🟩"), "b4")),
        Next(),
        MessageInput(input_fun),
        getter=get_data,
        state=Register.hello,
    ),
    Window(
        Const("Выберите время начала"),
        Group(*[
            Button(Const(f"{h % 24:2}:{m:02}"), f"{h}_{m}")
            for h in range(20, 26) for m in range(0, 60, 15)
        ], width=4),
        Group(Button(Const("Позже"), "ltr"), Button(Const("Раньше"), "erl"), width=100),
        Back(Const("Назад")),
        state=Register.name
    )
)


# ----- Dialog 2

async def get_data2(dialog_manager: DialogManager, **kwargs):
    return {
        "text": dialog_manager.current_context().start_data,
        "now": datetime.now().isoformat(),
    }


dialog2 = Dialog(
Exemplo n.º 3
0
            items=["0-12", "12-18", "18-25", "25-40", "40+"],
            item_id_getter=lambda x: x,
            id="w_age",
            on_click=on_age_changed,
        ),
        state=DialogSG.age,
        getter=get_data,
    ),
    Window(
        text=Multi(
            Format("{name}! Thank you for your answers."),
            Const("Hope you are not smoking", when="can_smoke"),
            sep="\n\n",
        ),
        kbd=Row(
            Back(),
            SwitchState(Const("Restart"),
                        id="restart",
                        state=DialogSG.greeting),
            Button(Const("Finish"), on_click=on_finish, id="finish"),
        ),
        getter=get_data,
        state=DialogSG.finish,
    ))


async def start(m: Message, dialog_manager: DialogManager):
    await dialog_manager.start(DialogSG.greeting, reset_stack=True)


async def main():
Exemplo n.º 4
0
    return {"name": dialog_manager.context.data("name", None)}


async def on_finish(c: CallbackQuery, button: Button, manager: DialogManager):
    await manager.done({"name": manager.context.data("name")})


name_dialog = Dialog(
    Window(
        Const("What is your name?"),
        Cancel(),
        MessageInput(name_handler),
        state=NameSG.input,
    ),
    Window(Format("Your name is `{name}`, it is correct?"),
           Row(Back(Const("No")),
               Button(Const("Yes"), id="yes", on_click=on_finish)),
           state=NameSG.confirm,
           getter=get_name_data))


# main dialog
class MainSG(StatesGroup):
    main = State()


async def process_result(result: Any, manager: DialogManager):
    if result:
        manager.context.set_data("name", result["name"])

Exemplo n.º 5
0
           width=2,
           keep_rows=False),
     getter=get_data,
     state=Broadcast.broadcast_type,
 ),
 Window(
     Format("<b>Следующие роли получат рассылку:</b>"
            "\n• {selected}"
            "\n\n<b>Текст рассылаемого сообщения:</b>"
            "\n{text}"
            "\n\n<i>Поддерживается встроенное в Telegram форматирование!"
            "\nМаксимальное кол-во символов: 4096</i>"),
     Url(Const("Про форматирование"),
         Const("https://lifehacker.ru/formatirovanie-teksta-v-telegram/")),
     Button(Const("Отмена"), id="Cancel", on_click=on_finish),
     Group(Back(Const("Назад")),
           Next(Const("Далее")),
           width=2,
           keep_rows=False),
     MessageInput(broadcast_text),
     getter=get_text,
     state=Broadcast.broadcast_text,
 ),
 Window(Format(
     "<b>Если хотите прикрепить фотографию к вашей рассылке, пришлите ее на этом этапе:</b>\n"
     "{image_id}"),
        MessageInput(broadcast_image),
        Button(Const("Отмена"), id="Cancel", on_click=on_finish),
        Group(Back(Const("Назад")),
              Next(Const("Далее")),
              width=2,