小修消息处理炸飞
This commit is contained in:
@@ -2,7 +2,11 @@ from src.common.logger_manager import get_logger
|
|||||||
from src.chat.message_receive.message import MessageRecv
|
from src.chat.message_receive.message import MessageRecv
|
||||||
from src.chat.message_receive.storage import MessageStorage
|
from src.chat.message_receive.storage import MessageStorage
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
|
from src.chat.message_receive.chat_stream import ChatStream
|
||||||
|
|
||||||
|
from maim_message import UserInfo
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
logger = get_logger("pfc")
|
logger = get_logger("pfc")
|
||||||
|
|
||||||
@@ -14,7 +18,7 @@ class MessageProcessor:
|
|||||||
self.storage = MessageStorage()
|
self.storage = MessageStorage()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _check_ban_words(text: str, chat, userinfo) -> bool:
|
def _check_ban_words(text: str, chat: ChatStream, userinfo: UserInfo) -> bool:
|
||||||
"""检查消息中是否包含过滤词"""
|
"""检查消息中是否包含过滤词"""
|
||||||
for word in global_config.message_receive.ban_words:
|
for word in global_config.message_receive.ban_words:
|
||||||
if word in text:
|
if word in text:
|
||||||
@@ -26,13 +30,12 @@ class MessageProcessor:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _check_ban_regex(text: str, chat, userinfo) -> bool:
|
def _check_ban_regex(text: str, chat: ChatStream, userinfo: UserInfo) -> bool:
|
||||||
"""检查消息是否匹配过滤正则表达式"""
|
"""检查消息是否匹配过滤正则表达式"""
|
||||||
for pattern in global_config.chat.ban_msgs_regex:
|
for pattern in global_config.message_receive.ban_msgs_regex:
|
||||||
if pattern.search(text):
|
if re.search(pattern, text):
|
||||||
logger.info(
|
chat_name = chat.group_info.group_name if chat.group_info else "私聊"
|
||||||
f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}"
|
logger.info(f"[{chat_name}]{userinfo.user_nickname}:{text}")
|
||||||
)
|
|
||||||
logger.info(f"[正则表达式过滤]消息匹配到{pattern},filtered")
|
logger.info(f"[正则表达式过滤]消息匹配到{pattern},filtered")
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user