Format("Now: {now}"), Progress("progress", 10), Progress("progress2", 10, filled="🟩"), Group( Button(Format("{name}"), "b1"), Button(Const("Is it Fun?"), "b2", on_click=fun), Checkbox(Const("Yes"), Const("No"), "check"), width=100, ), select, radio, 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 ) )
await dialog.next(manager) async def get_name_data(dialog_manager: DialogManager, **kwargs): 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):
second = State() last = State() async def on_input(m: Message, dialog: Dialog, manager: DialogManager): manager.current_context().dialog_data["name"] = m.text await dialog.next(manager) # rendering tool cannot detect this call dialog = Dialog( Window( Const("1. First"), Next(), state=RenderSG.first, ), Window( Const("2. Second"), Back(), MessageInput(on_input), state=RenderSG.second, preview_add_transitions=[Next()], # this is a hint for rendering tool ), Window( Const("3. Last"), Back(), state=RenderSG.last, ), ) render_transitions([dialog])
), 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, keep_rows=False), getter=get_image, state=Broadcast.broadcast_image)) # @TODO починить выбор картинки
multi = Multiselect( Format("✓ {item[0]}"), # E.g `✓ Apple` Format("{item[0]}"), id="check", item_id_getter=operator.itemgetter(1), items="fruits", ) dialog = Dialog( Window( Format("Clicked: {counter}\n\n{stack}\n\n{context}\n\n{now}"), Button(Const("Click me!"), id="btn1", on_click=on_click), multi, Cancel(), MessageInput(name_handler), # Inputs work only in default stack! state=DialogSG.greeting, getter=get_data, ), ) async def main(): # real main logging.basicConfig(level=logging.INFO) storage = MemoryStorage() bot = Bot(token=API_TOKEN) dp = Dispatcher(bot, storage=storage) registry = DialogRegistry(dp) # register handler which resets stack and start dialogs on /start command registry.register_start_handler(DialogSG.greeting) registry.register(dialog)