Template
mirror of
https://github.com/djimboy/djimbo_template_aio3.git
synced 2026-08-25 14:37:43 +00:00
Update aiogram 3 template
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user