feat: Reorganized project, added user registration, throttling middleware, help command, profile command

This commit is contained in:
ITQ
2024-03-20 20:53:43 +03:00
parent 7086a1cf52
commit 6d755490d6
21 changed files with 603 additions and 44 deletions
+15 -20
View File
@@ -2,34 +2,29 @@ __all__ = ("main",)
from typing import Optional
from aiogram import Bot, Dispatcher, types
from aiogram import Bot, Dispatcher
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
from aiogram.types import Message
from aiogram.utils.markdown import hbold
from app.config import Config
dp = Dispatcher()
@dp.message(CommandStart())
async def command_start_handler(message: Message) -> None:
await message.answer(f"Hello, {hbold(message.from_user.full_name)}!")
@dp.message()
async def echo_handler(message: types.Message) -> None:
try:
await message.send_copy(chat_id=message.chat.id)
except TypeError:
await message.answer("Nice try!")
from app.handlers import help_command, profile_command, start_command
from app.middlewares.throttling import ThrottlingMiddleware
async def main() -> None:
dp = Dispatcher()
bot_token: Optional[str] = Config.BOT_TOKEN
if bot_token is not None:
bot = Bot(bot_token, parse_mode=ParseMode.HTML)
dp.message.middleware(ThrottlingMiddleware(0.5))
dp.include_routers(
start_command.router,
profile_command.router,
help_command.router,
)
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
else:
exit("BOT_TOKEN is not set")