-
Notifications
You must be signed in to change notification settings - Fork 14
/
bot_errors_logger.py
28 lines (25 loc) · 954 Bytes
/
bot_errors_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from hydrogram import Client, enums
from hydrogram.types import Message
from hydrogram.errors.exceptions.forbidden_403 import ChatWriteForbidden
from functools import wraps
import constants
def logging_errors(f):
@wraps(f)
async def err_log(client: Client, message: Message, *args, **kwargs):
try:
return await f(client, message, *args, **kwargs)
except ChatWriteForbidden:
await message.chat.leave()
return
except Exception as e:
try:
await message.reply(
constants.error_msg_string.format(f"{type(e).__name__}: {e}"),
parse_mode=enums.ParseMode.MARKDOWN,
reply_markup=constants.error_message_markup,
disable_web_page_preview=True,
)
except ChatWriteForbidden:
await message.chat.leave()
return
return err_log