mirror of https://github.com/Mai-with-u/MaiBot.git
修复消息过滤时机:将过滤检查移至消息处理之后
- 将过滤检查从message.process()之前移动到之后 - 确保_check_ban_words使用processed_plain_text时能正常工作 - 保持_check_ban_regex使用raw_message,确保正则过滤正常工作 - 这样既保证了过滤功能的完整性,又符合消息处理的逻辑顺序 修复问题: - 原代码在message.process()之前进行过滤检查 - 此时processed_plain_text还是空的,导致关键词过滤不生效 - 现在过滤检查在消息处理之后进行,确保所有过滤功能正常工作pull/1259/head
parent
a1e9893ac1
commit
56c83d0da0
|
|
@ -251,18 +251,6 @@ class ChatBot:
|
|||
# return
|
||||
pass
|
||||
|
||||
# 过滤检查
|
||||
if _check_ban_words(
|
||||
message.processed_plain_text,
|
||||
user_info, # type: ignore
|
||||
group_info,
|
||||
) or _check_ban_regex(
|
||||
message.raw_message, # type: ignore
|
||||
user_info, # type: ignore
|
||||
group_info,
|
||||
):
|
||||
return
|
||||
|
||||
get_chat_manager().register_message(message)
|
||||
|
||||
chat = await get_chat_manager().get_or_create_stream(
|
||||
|
|
@ -276,6 +264,18 @@ class ChatBot:
|
|||
# 处理消息内容,生成纯文本
|
||||
await message.process()
|
||||
|
||||
# 过滤检查(在消息处理之后进行)
|
||||
if _check_ban_words(
|
||||
message.processed_plain_text,
|
||||
user_info, # type: ignore
|
||||
group_info,
|
||||
) or _check_ban_regex(
|
||||
message.raw_message, # type: ignore
|
||||
user_info, # type: ignore
|
||||
group_info,
|
||||
):
|
||||
return
|
||||
|
||||
# if await self.check_ban_content(message):
|
||||
# logger.warning(f"检测到消息中含有违法,色情,暴力,反动,敏感内容,消息内容:{message.processed_plain_text},发送者:{message.message_info.user_info.user_nickname}")
|
||||
# return
|
||||
|
|
|
|||
Loading…
Reference in New Issue