forked from sultansq/kiu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.py
56 lines (47 loc) · 1.55 KB
/
errors.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
52
53
54
55
56
import sys
import traceback
from functools import wraps
from pyrogram.errors.exceptions.forbidden_403 import ChatWriteForbidden
from AnonX import app
from AnonX.logging import LOGGER
def split_limits(text):
if len(text) < 2048:
return [text]
lines = text.splitlines(True)
small_msg = ""
result = []
for line in lines:
if len(small_msg) + len(line) < 2048:
small_msg += line
else:
result.append(small_msg)
small_msg = line
result.append(small_msg)
return result
def capture_err(func):
@wraps(func)
async def capture(client, message, *args, **kwargs):
try:
return await func(client, message, *args, **kwargs)
except ChatWriteForbidden:
await app.leave_chat(message.chat.id)
return
except Exception as err:
exc_type, exc_obj, exc_tb = sys.exc_info()
errors = traceback.format_exception(
etype=exc_type,
value=exc_obj,
tb=exc_tb,
)
error_feedback = split_limits(
"**ERROR** | `{}` | `{}`\n\n```{}```\n\n```{}```\n".format(
0 if not message.from_user else message.from_user.id,
0 if not message.chat else message.chat.id,
message.text or message.caption,
"".join(errors),
),
)
for x in error_feedback:
await app.send_message(LOGGER, x)
raise err
return capture