Advertisement
xlebpushek

bot.py

Feb 5th, 2023
853
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. from aiogram import Bot, Dispatcher
  2. from aiogram.filters import Command
  3. from aiogram.types import Message
  4. from aiogram.utils.i18n import gettext as _
  5.  
  6. from src import keyboards
  7. from src.configs.env import TELEGRAM_TOKEN
  8. from src.database import db
  9. from src.handlers import settings
  10. from src.middlewares import i18n
  11. from src.models.user import UserModel
  12.  
  13. dispatcher = Dispatcher()
  14.  
  15.  
  16. @dispatcher.message(Command(commands=["start"]))
  17. async def command_start_handler(message: Message) -> None:
  18.   user: UserModel = db.users.find_one({"userId": message.from_user.id})
  19.  
  20.   if user:
  21.     return await message.answer(
  22.       _("I am your king <b>Tikhon</b>. I can analyze stocks, make market forecasts on them, and also trade them instead of you."),
  23.       reply_markup=keyboards.reply.command_start,
  24.       parse_mode="HTML"
  25.     )
  26.  
  27.   return await message.answer(_("You have no rights to use this bot!"))
  28.  
  29.  
  30. bot = Bot(token=TELEGRAM_TOKEN)
  31.  
  32.  
  33. async def on_startup():
  34.   i18n.setup(dispatcher)
  35.   dispatcher.include_router(settings.router)
  36.  
  37.   return await dispatcher.start_polling(bot)
  38.  
  39.  
  40. async def on_shutdown():
  41.   return await bot.session.close()
  42.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement