fix: ban rule-based spam and add project icon

This commit is contained in:
ngfchl
2026-07-07 13:04:16 +08:00
parent 3f4af40d0d
commit 2b38fc91bd
10 changed files with 412 additions and 9 deletions
+20 -3
View File
@@ -90,10 +90,20 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
"reason": reason,
}))
# 删消息
# 删消息,并把记录标成已删除,避免前端继续显示“删除/删封”按钮
try:
await msg.delete()
message_record.manually_deleted = True
message_record.deleted_at = datetime.now()
message_record.delete_reason = "auto_spam_delete"
await message_record.save()
await Action.create(action="DELETE", chat_id=update.effective_chat.id, user_id=user.id, username=username, details={"reason": reason, "text": text[:120]})
await broadcast_sse("chat_delete", json_safe({
"id": message_record.id,
"msg_id": msg.message_id,
"chat_id": update.effective_chat.id,
"deleted_at": message_record.deleted_at,
}))
except Exception as e:
logger.error(f"❌ 删除消息失败: {e}")
@@ -135,10 +145,17 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
}))
logger.info(f"🔨 已封禁 [{username}] {config.BAN_DURATION_MINUTES} 分钟")
except Exception as e:
logger.error(f"❌ 封禁失败: {e}")
await Action.create(
action="BAN_FAILED",
chat_id=update.effective_chat.id,
user_id=user.id,
username=username,
details={"reason": reason, "error": f"{type(e).__name__}: {e}"},
)
logger.error(f"❌ 封禁失败 [{username or user.id}]: {type(e).__name__}: {e}")
# 标记为垃圾
await Message.filter(msg_id=msg.message_id).update(is_spam=True, spam_reason=reason)
await Message.filter(chat_id=update.effective_chat.id, msg_id=msg.message_id).update(is_spam=True, spam_reason=reason)
def register_spam(app):