Bot become a Community Guard & Post send manager
added: dictionary support for censore message/user management with dict triggers
This commit is contained in:
16
app/bot/handlers/errors.py
Normal file
16
app/bot/handlers/errors.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import traceback
|
||||
from telegram.ext import ContextTypes
|
||||
from app.db.session import get_session
|
||||
from app.db.models import ModerationLog
|
||||
|
||||
async def on_error(update: object, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
try:
|
||||
chat_id = getattr(getattr(update, "effective_chat", None), "id", 0)
|
||||
user_id = getattr(getattr(update, "effective_user", None), "id", 0)
|
||||
err = "".join(traceback.format_exception(context.error))[-4000:]
|
||||
with get_session() as s:
|
||||
s.add(ModerationLog(chat_id=chat_id or 0, tg_user_id=user_id or 0,
|
||||
message_id=None, reason=err, action="error"))
|
||||
s.commit()
|
||||
except Exception:
|
||||
pass
|
||||
Reference in New Issue
Block a user