Skip to content

Commit

Permalink
add new widgets to mega bot
Browse files Browse the repository at this point in the history
  • Loading branch information
chirizxc committed Dec 20, 2024
1 parent 1a2256b commit 9a7d7e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion example/mega/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from bot_dialogs.link_preview import link_preview_dialog
from bot_dialogs.main import main_dialog
from bot_dialogs.mutltiwidget import multiwidget_dialog
from bot_dialogs.reply_buttons import reply_kbd_dialog
from bot_dialogs.reply_buttons import reply_kbd_dialog, reply_kbd_router
from bot_dialogs.scrolls import scroll_dialog
from bot_dialogs.select import selects_dialog
from bot_dialogs.switch import switch_dialog
Expand Down Expand Up @@ -60,6 +60,7 @@ async def on_unknown_intent(event: ErrorEvent, dialog_manager: DialogManager):

dialog_router = Router()
dialog_router.include_routers(
reply_kbd_router,
layouts_dialog,
scroll_dialog,
main_dialog,
Expand Down
40 changes: 40 additions & 0 deletions example/mega/bot_dialogs/reply_buttons.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from aiogram import F, Router
from aiogram.types import Message

from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import (
Checkbox,
Radio,
RequestChat,
RequestContact,
RequestLocation,
RequestUser,
Row,
)
from aiogram_dialog.widgets.markup.reply_keyboard import ReplyKeyboardFactory
Expand All @@ -12,13 +17,48 @@
from . import states
from .common import MAIN_MENU_BUTTON

reply_kbd_router = Router()


@reply_kbd_router.message(F.chat_shared | F.user_shared)
async def on_user_shared(message: Message) -> None:
if message.chat_shared:
shifted_id = str(message.chat_shared.chat_id)[4:]
await message.answer(
f"ID: <b><code>{message.chat_shared.chat_id}</code></b>\n\n"
f"Shifted ID: <b><code>{shifted_id}</code></b>",
parse_mode="HTML",
)
elif message.user_shared:
await message.answer(
f"User ID: <b><code>{message.user_shared.user_id}</code></b>",
parse_mode="HTML",
)


reply_kbd_dialog = Dialog(
Window(
Const("Reply keyboard with multiple widgets.\n"),
Row(
RequestContact(Const("👤 Send contact")),
RequestLocation(Const("📍 Send location")),
),
Row(
RequestChat(
Const("Request chat"),
request_id=1,
chat_is_channel=True,
),
RequestUser(
Const("Request user"),
request_id=2,
),
RequestUser(
Const("Request premium user"),
request_id=3,
user_is_premium=True,
),
),
Checkbox(
checked_text=Const("✓ Checkbox"),
unchecked_text=Const(" Checkbox"),
Expand Down

0 comments on commit 9a7d7e5

Please sign in to comment.