Update aiogram 3 template

This commit is contained in:
dj
2026-05-29 09:44:39 +03:00
parent e144cb1424
commit 2eced5dc4f
43 changed files with 1877 additions and 1252 deletions
+12 -14
View File
@@ -1,6 +1,7 @@
# - *- coding: utf- 8 - *-
from aiogram import Router
from aiogram.filters import ExceptionMessageFilter
from aiogram.exceptions import TelegramBadRequest
from aiogram.filters import ExceptionTypeFilter
from aiogram.handlers import ErrorHandler
from tgbot.utils.misc.bot_logging import bot_logger
@@ -8,22 +9,19 @@ from tgbot.utils.misc.bot_logging import bot_logger
router = Router(name=__name__)
# Error with block forbidden user
# Ошибка при отправке сообщения пользователю, который заблокировал бота
# @router.errors(ExceptionTypeFilter(TelegramForbiddenError))
# class MyHandler(ErrorHandler):
# class ForbiddenErrorHandler(ErrorHandler):
# async def handle(self):
# ...
# Error with edit duplicate message
@router.errors(ExceptionMessageFilter(
"Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message")
)
class MyHandler(ErrorHandler):
# Безопасно игнорируем повторное редактирование сообщения без изменений
@router.errors(ExceptionTypeFilter(TelegramBadRequest))
class MessageNotModifiedHandler(ErrorHandler):
async def handle(self):
bot_logger.exception(
f"====================\n"
f"Exception name: {self.exception_name}\n"
f"Exception message: {self.exception_message}\n"
f"===================="
)
if "message is not modified" in self.exception_message.lower():
bot_logger.debug("Telegram отклонил повторное редактирование сообщения без изменений")
return True
raise self.event