-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_handler.py
52 lines (43 loc) · 1.61 KB
/
error_handler.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import traceback
import pprint
import html
from telegram import CallbackQuery
from telegram.ext import ContextTypes
import config
from utils import printlog
async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> None:
tb_list = traceback.format_exception(None, context.error, context.error.__traceback__)
tb_string = "".join(tb_list)
await printlog(update, f"{tb_string}", error=True)
rawtext = pprint.pformat(update.to_dict())
# print(rawtext)
rawtext = html.escape(rawtext)
if isinstance(update, CallbackQuery):
user = update.from_user
chat_id = update.message.chat.id
else:
user = update.effective_user
chat_id = update.effective_chat.id
link_chat_id = str(chat_id).replace("-100", "")
message_id = None
if update.effective_message and update.effective_message.message_id:
message_id = update.effective_message.message_id
emoji_link = ''
if link_chat_id and message_id:
emoji_link = f'<a href="t.me/c/{link_chat_id}/{message_id}">🔗</a> '
await context.bot.send_message(
chat_id=config.ID_BOTCENTRAL,
text=f'{emoji_link}ERRORE!',
parse_mode="HTML",
)
await update.message.forward(config.ID_BOTCENTRAL)
await context.bot.send_message(
chat_id=config.ID_BOTCENTRAL,
text=f'<pre><code class="language-python">{rawtext}</code></pre>',
parse_mode="HTML",
)
await context.bot.send_message(
chat_id=config.ID_BOTCENTRAL,
text=f'<pre><code class="language-python">{tb_string[:4000]}</code></pre>',
parse_mode="HTML",
)