You've already forked Travel-Agent
feat: Added menu command
This commit is contained in:
+12
-5
@@ -6,9 +6,14 @@ from aiogram import Bot, Dispatcher
|
||||
from aiogram.enums import ParseMode
|
||||
from aiogram.fsm.storage.redis import RedisStorage
|
||||
|
||||
from app.callbacks import profile
|
||||
from app.callbacks import menu, profile
|
||||
from app.config import Config
|
||||
from app.handlers import help_command, profile_command, start_command
|
||||
from app.handlers import (
|
||||
help_command,
|
||||
menu_command,
|
||||
profile_command,
|
||||
start_command,
|
||||
)
|
||||
from app.middlewares.throttling import ThrottlingMiddleware
|
||||
|
||||
|
||||
@@ -23,12 +28,14 @@ async def main() -> None:
|
||||
bot = Bot(bot_token, parse_mode=ParseMode.HTML)
|
||||
|
||||
dp.message.middleware(ThrottlingMiddleware(0.5))
|
||||
# type: ignore
|
||||
|
||||
dp.include_routers(
|
||||
start_command.router,
|
||||
profile_command.router,
|
||||
profile.router, # type: ignore
|
||||
help_command.router,
|
||||
menu_command.router,
|
||||
profile_command.router,
|
||||
menu.router, # type: ignore
|
||||
profile.router, # type: ignore
|
||||
)
|
||||
|
||||
await bot.delete_webhook(drop_pending_updates=True)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# type: ignore
|
||||
__all__ = ()
|
||||
|
||||
from aiogram import F, Router
|
||||
from aiogram.exceptions import TelegramBadRequest
|
||||
from aiogram.types import CallbackQuery
|
||||
|
||||
from app import messages
|
||||
from app.filters.user import RegisteredCallback
|
||||
from app.keyboards.profile import get
|
||||
from app.models.user import User
|
||||
|
||||
|
||||
router = Router(name="menu_callback")
|
||||
|
||||
|
||||
@router.callback_query(F.data == "menu_profile", RegisteredCallback())
|
||||
async def profile_callback(callback: CallbackQuery) -> None:
|
||||
if callback.data is None or callback.message is None:
|
||||
return
|
||||
|
||||
user = User().get_user_by_telegram_id(callback.from_user.id)
|
||||
|
||||
await callback.message.answer(
|
||||
messages.PROFILE.format(
|
||||
username=user.username,
|
||||
age=user.age,
|
||||
bio=user.bio if user.bio else messages.NOT_SET,
|
||||
sex=user.sex.capitalize(),
|
||||
country=user.country,
|
||||
city=user.city,
|
||||
),
|
||||
reply_markup=get(),
|
||||
)
|
||||
await callback.answer()
|
||||
|
||||
try:
|
||||
await callback.message.delete()
|
||||
except TelegramBadRequest:
|
||||
pass
|
||||
@@ -0,0 +1,17 @@
|
||||
__all__ = ()
|
||||
|
||||
from aiogram import Router
|
||||
from aiogram.filters import Command
|
||||
from aiogram.types import Message
|
||||
|
||||
from app import messages
|
||||
from app.filters.user import Registered
|
||||
from app.keyboards.menu import get
|
||||
|
||||
|
||||
router = Router(name="menu_command")
|
||||
|
||||
|
||||
@router.message(Command("menu"), Registered())
|
||||
async def command_menu_handler(message: Message) -> None:
|
||||
await message.answer(messages.MENU, reply_markup=get())
|
||||
@@ -0,0 +1,31 @@
|
||||
__all__ = ("get",)
|
||||
|
||||
from aiogram import types
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
|
||||
def get():
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="👤 Profile",
|
||||
callback_data="menu_profile",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="➕ Create travel",
|
||||
callback_data="menu_create_travel",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="📃 Travels",
|
||||
callback_data="menu_travels",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="🔵 Temp",
|
||||
callback_data="menu_temp",
|
||||
),
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
@@ -1,5 +1,7 @@
|
||||
# flake8: noqa
|
||||
|
||||
MENU = "<b>Menu:</b>"
|
||||
|
||||
WELCOME_MESSAGE = "Hello, <b>{name}</b>! Welcome to the ✈️ Travel Agent bot! Let's start our journey by filling out some information about you."
|
||||
WELCOME_AGAIN_MESSAGE = "Hello, <b>{name}</b>! Welcome back to the ✈️ Travel Agent bot! If you get lost, you can always call the /help command for assistance."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user