Deleted mysql support, redis password, webhook, keyboard constructors, filters, loguru.

Added support of decorators in handlers
Added function to notify admins on startup
This commit is contained in:
Kostiantyn Kriuchkov
2020-04-14 01:50:57 +03:00
parent 13ff8d0478
commit eab45a5088
30 changed files with 141 additions and 223 deletions

View File

@@ -1,9 +1,3 @@
from aiogram import Dispatcher
from aiogram.utils import exceptions
from .error_handler import dp
from .not_modified import message_not_modified, message_to_delete_not_found
def setup(dp: Dispatcher):
dp.register_errors_handler(message_not_modified, exception=exceptions.MessageNotModified)
dp.register_errors_handler(message_to_delete_not_found, exception=exceptions.MessageToDeleteNotFound)
__all__ = ["dp"]

View File

@@ -0,0 +1,56 @@
import logging
from bot import dp
@dp.errors_handler()
async def errors_handler(update, exception):
"""
Exceptions handler. Catches all exceptions within task factory tasks.
:param dispatcher:
:param update:
:param exception:
:return: stdout logging
"""
from aiogram.utils.exceptions import (Unauthorized, InvalidQueryID, TelegramAPIError,
CantDemoteChatCreator, MessageNotModified, MessageToDeleteNotFound,
MessageTextIsEmpty, RetryAfter,
CantParseEntities, MessageCantBeDeleted)
if isinstance(exception, CantDemoteChatCreator):
logging.debug("Can't demote chat creator")
return True
if isinstance(exception, MessageNotModified):
logging.debug('Message is not modified')
return True
if isinstance(exception, MessageCantBeDeleted):
logging.debug('Message cant be deleted')
return True
if isinstance(exception, MessageToDeleteNotFound):
logging.debug('Message to delete not found')
return True
if isinstance(exception, MessageTextIsEmpty):
logging.debug('MessageTextIsEmpty')
return True
if isinstance(exception, Unauthorized):
logging.info(f'Unauthorized: {exception}')
return True
if isinstance(exception, InvalidQueryID):
logging.exception(f'InvalidQueryID: {exception} \nUpdate: {update}')
return True
if isinstance(exception, TelegramAPIError):
logging.exception(f'TelegramAPIError: {exception} \nUpdate: {update}')
return True
if isinstance(exception, RetryAfter):
logging.exception(f'RetryAfter: {exception} \nUpdate: {update}')
return True
if isinstance(exception, CantParseEntities):
logging.exception(f'CantParseEntities: {exception} \nUpdate: {update}')
return True
logging.exception(f'Update: {update} \n{exception}')

View File

@@ -1,10 +0,0 @@
from aiogram import types
from aiogram.utils import exceptions
async def message_not_modified(update: types.Update, error: exceptions.MessageNotModified):
return True
async def message_to_delete_not_found(update: types.Update, error: exceptions.MessageToDeleteNotFound):
return True