去除mmc端的白名单机制
This commit is contained in:
@@ -38,10 +38,10 @@ class ChatBot:
|
|||||||
|
|
||||||
async def _create_pfc_chat(self, message: MessageRecv):
|
async def _create_pfc_chat(self, message: MessageRecv):
|
||||||
try:
|
try:
|
||||||
chat_id = str(message.chat_stream.stream_id)
|
if global_config.experimental.pfc_chatting:
|
||||||
private_name = str(message.message_info.user_info.user_nickname)
|
chat_id = str(message.chat_stream.stream_id)
|
||||||
|
private_name = str(message.message_info.user_info.user_nickname)
|
||||||
|
|
||||||
if global_config.experimental.enable_pfc_chatting:
|
|
||||||
await self.pfc_manager.get_or_create_conversation(chat_id, private_name)
|
await self.pfc_manager.get_or_create_conversation(chat_id, private_name)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -75,27 +75,27 @@ class ChatBot:
|
|||||||
# print(message_data)
|
# print(message_data)
|
||||||
logger.trace(f"处理消息:{str(message_data)[:120]}...")
|
logger.trace(f"处理消息:{str(message_data)[:120]}...")
|
||||||
message = MessageRecv(message_data)
|
message = MessageRecv(message_data)
|
||||||
groupinfo = message.message_info.group_info
|
group_info = message.message_info.group_info
|
||||||
userinfo = message.message_info.user_info
|
user_info = message.message_info.user_info
|
||||||
|
|
||||||
# 用户黑名单拦截
|
# 用户黑名单拦截
|
||||||
if userinfo.user_id in global_config.chat_target.ban_user_id:
|
# if userinfo.user_id in global_config.chat_target.ban_user_id:
|
||||||
logger.debug(f"用户{userinfo.user_id}被禁止回复")
|
# logger.debug(f"用户{userinfo.user_id}被禁止回复")
|
||||||
return
|
# return
|
||||||
|
|
||||||
if groupinfo is None:
|
# if groupinfo is None:
|
||||||
logger.trace("检测到私聊消息,检查")
|
# logger.trace("检测到私聊消息,检查")
|
||||||
# 好友黑名单拦截
|
# # 好友黑名单拦截
|
||||||
if userinfo.user_id not in global_config.experimental.talk_allowed_private:
|
# if userinfo.user_id not in global_config.experimental.talk_allowed_private:
|
||||||
# logger.debug(f"用户{userinfo.user_id}没有私聊权限")
|
# # logger.debug(f"用户{userinfo.user_id}没有私聊权限")
|
||||||
return
|
# return
|
||||||
|
|
||||||
# 群聊黑名单拦截
|
# 群聊黑名单拦截
|
||||||
# print(groupinfo.group_id)
|
# print(groupinfo.group_id)
|
||||||
# print(global_config.chat_target.talk_allowed_groups)
|
# print(global_config.chat_target.talk_allowed_groups)
|
||||||
if groupinfo is not None and groupinfo.group_id not in global_config.chat_target.talk_allowed_groups:
|
# if groupinfo is not None and groupinfo.group_id not in global_config.chat_target.talk_allowed_groups:
|
||||||
logger.debug(f"群{groupinfo.group_id}被禁止回复")
|
# logger.debug(f"群{groupinfo.group_id}被禁止回复")
|
||||||
return
|
# return
|
||||||
|
|
||||||
# 确认从接口发来的message是否有自定义的prompt模板信息
|
# 确认从接口发来的message是否有自定义的prompt模板信息
|
||||||
if message.message_info.template_info and not message.message_info.template_info.template_default:
|
if message.message_info.template_info and not message.message_info.template_info.template_default:
|
||||||
@@ -112,33 +112,49 @@ class ChatBot:
|
|||||||
async def preprocess():
|
async def preprocess():
|
||||||
logger.trace("开始预处理消息...")
|
logger.trace("开始预处理消息...")
|
||||||
# 如果在私聊中
|
# 如果在私聊中
|
||||||
if groupinfo is None:
|
if group_info is None:
|
||||||
logger.trace("检测到私聊消息")
|
logger.trace("检测到私聊消息")
|
||||||
# 是否在配置信息中开启私聊模式
|
# 是否在配置信息中开启私聊模式
|
||||||
if global_config.experimental.enable_friend_chat:
|
# if global_config.experimental.enable_friend_chat:
|
||||||
logger.trace("私聊模式已启用")
|
# logger.trace("私聊模式已启用")
|
||||||
# 是否进入PFC
|
# # 是否进入PFC
|
||||||
if global_config.enable_pfc_chatting:
|
# if global_config.enable_pfc_chatting:
|
||||||
logger.trace("进入PFC私聊处理流程")
|
# logger.trace("进入PFC私聊处理流程")
|
||||||
userinfo = message.message_info.user_info
|
# userinfo = message.message_info.user_info
|
||||||
messageinfo = message.message_info
|
# messageinfo = message.message_info
|
||||||
# 创建聊天流
|
# # 创建聊天流
|
||||||
logger.trace(f"为{userinfo.user_id}创建/获取聊天流")
|
# logger.trace(f"为{userinfo.user_id}创建/获取聊天流")
|
||||||
chat = await chat_manager.get_or_create_stream(
|
# chat = await chat_manager.get_or_create_stream(
|
||||||
platform=messageinfo.platform,
|
# platform=messageinfo.platform,
|
||||||
user_info=userinfo,
|
# user_info=userinfo,
|
||||||
group_info=groupinfo,
|
# group_info=groupinfo,
|
||||||
)
|
# )
|
||||||
message.update_chat_stream(chat)
|
# message.update_chat_stream(chat)
|
||||||
await self.only_process_chat.process_message(message)
|
# await self.only_process_chat.process_message(message)
|
||||||
await self._create_pfc_chat(message)
|
# await self._create_pfc_chat(message)
|
||||||
# 禁止PFC,进入普通的心流消息处理逻辑
|
# # 禁止PFC,进入普通的心流消息处理逻辑
|
||||||
else:
|
# else:
|
||||||
logger.trace("进入普通心流私聊处理")
|
# logger.trace("进入普通心流私聊处理")
|
||||||
await self.heartflow_processor.process_message(message_data)
|
# await self.heartflow_processor.process_message(message_data)
|
||||||
|
if global_config.experimental.pfc_chatting:
|
||||||
|
logger.trace("进入PFC私聊处理流程")
|
||||||
|
# 创建聊天流
|
||||||
|
logger.trace(f"为{user_info.user_id}创建/获取聊天流")
|
||||||
|
chat = await chat_manager.get_or_create_stream(
|
||||||
|
platform=message.message_info.platform,
|
||||||
|
user_info=user_info,
|
||||||
|
group_info=group_info,
|
||||||
|
)
|
||||||
|
message.update_chat_stream(chat)
|
||||||
|
await self.only_process_chat.process_message(message)
|
||||||
|
await self._create_pfc_chat(message)
|
||||||
|
# 禁止PFC,进入普通的心流消息处理逻辑
|
||||||
|
else:
|
||||||
|
logger.trace("进入普通心流私聊处理")
|
||||||
|
await self.heartflow_processor.process_message(message_data)
|
||||||
# 群聊默认进入心流消息处理逻辑
|
# 群聊默认进入心流消息处理逻辑
|
||||||
else:
|
else:
|
||||||
logger.trace(f"检测到群聊消息,群ID: {groupinfo.group_id}")
|
logger.trace(f"检测到群聊消息,群ID: {group_info.group_id}")
|
||||||
await self.heartflow_processor.process_message(message_data)
|
await self.heartflow_processor.process_message(message_data)
|
||||||
|
|
||||||
if template_group_name:
|
if template_group_name:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class ChatStream:
|
|||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
"""转换为字典格式"""
|
"""转换为字典格式"""
|
||||||
result = {
|
return {
|
||||||
"stream_id": self.stream_id,
|
"stream_id": self.stream_id,
|
||||||
"platform": self.platform,
|
"platform": self.platform,
|
||||||
"user_info": self.user_info.to_dict() if self.user_info else None,
|
"user_info": self.user_info.to_dict() if self.user_info else None,
|
||||||
@@ -47,7 +47,6 @@ class ChatStream:
|
|||||||
"create_time": self.create_time,
|
"create_time": self.create_time,
|
||||||
"last_active_time": self.last_active_time,
|
"last_active_time": self.last_active_time,
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict) -> "ChatStream":
|
def from_dict(cls, data: dict) -> "ChatStream":
|
||||||
@@ -235,33 +234,34 @@ class ChatManager:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
async def _save_stream(stream: ChatStream):
|
async def _save_stream(stream: ChatStream):
|
||||||
"""保存聊天流到数据库"""
|
"""保存聊天流到数据库"""
|
||||||
if not stream.saved:
|
if stream.saved:
|
||||||
stream_data_dict = stream.to_dict()
|
return
|
||||||
|
stream_data_dict = stream.to_dict()
|
||||||
|
|
||||||
def _db_save_stream_sync(s_data_dict: dict):
|
def _db_save_stream_sync(s_data_dict: dict):
|
||||||
user_info_d = s_data_dict.get("user_info")
|
user_info_d = s_data_dict.get("user_info")
|
||||||
group_info_d = s_data_dict.get("group_info")
|
group_info_d = s_data_dict.get("group_info")
|
||||||
|
|
||||||
fields_to_save = {
|
fields_to_save = {
|
||||||
"platform": s_data_dict["platform"],
|
"platform": s_data_dict["platform"],
|
||||||
"create_time": s_data_dict["create_time"],
|
"create_time": s_data_dict["create_time"],
|
||||||
"last_active_time": s_data_dict["last_active_time"],
|
"last_active_time": s_data_dict["last_active_time"],
|
||||||
"user_platform": user_info_d["platform"] if user_info_d else "",
|
"user_platform": user_info_d["platform"] if user_info_d else "",
|
||||||
"user_id": user_info_d["user_id"] if user_info_d else "",
|
"user_id": user_info_d["user_id"] if user_info_d else "",
|
||||||
"user_nickname": user_info_d["user_nickname"] if user_info_d else "",
|
"user_nickname": user_info_d["user_nickname"] if user_info_d else "",
|
||||||
"user_cardname": user_info_d.get("user_cardname", "") if user_info_d else None,
|
"user_cardname": user_info_d.get("user_cardname", "") if user_info_d else None,
|
||||||
"group_platform": group_info_d["platform"] if group_info_d else "",
|
"group_platform": group_info_d["platform"] if group_info_d else "",
|
||||||
"group_id": group_info_d["group_id"] if group_info_d else "",
|
"group_id": group_info_d["group_id"] if group_info_d else "",
|
||||||
"group_name": group_info_d["group_name"] if group_info_d else "",
|
"group_name": group_info_d["group_name"] if group_info_d else "",
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatStreams.replace(stream_id=s_data_dict["stream_id"], **fields_to_save).execute()
|
ChatStreams.replace(stream_id=s_data_dict["stream_id"], **fields_to_save).execute()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.to_thread(_db_save_stream_sync, stream_data_dict)
|
await asyncio.to_thread(_db_save_stream_sync, stream_data_dict)
|
||||||
stream.saved = True
|
stream.saved = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"保存聊天流 {stream.stream_id} 到数据库失败 (Peewee): {e}", exc_info=True)
|
logger.error(f"保存聊天流 {stream.stream_id} 到数据库失败 (Peewee): {e}", exc_info=True)
|
||||||
|
|
||||||
async def _save_all_streams(self):
|
async def _save_all_streams(self):
|
||||||
"""保存所有聊天流"""
|
"""保存所有聊天流"""
|
||||||
|
|||||||
@@ -340,11 +340,11 @@ class TelemetryConfig(ConfigBase):
|
|||||||
class ExperimentalConfig(ConfigBase):
|
class ExperimentalConfig(ConfigBase):
|
||||||
"""实验功能配置类"""
|
"""实验功能配置类"""
|
||||||
|
|
||||||
enable_friend_chat: bool = False
|
# enable_friend_chat: bool = False
|
||||||
"""是否启用好友聊天"""
|
# """是否启用好友聊天"""
|
||||||
|
|
||||||
talk_allowed_private: set[str] = field(default_factory=lambda: set())
|
# talk_allowed_private: set[str] = field(default_factory=lambda: set())
|
||||||
"""允许聊天的私聊列表"""
|
# """允许聊天的私聊列表"""
|
||||||
|
|
||||||
pfc_chatting: bool = False
|
pfc_chatting: bool = False
|
||||||
"""是否启用PFC"""
|
"""是否启用PFC"""
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[inner]
|
[inner]
|
||||||
version = "2.0.0"
|
version = "2.1.0"
|
||||||
|
|
||||||
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
||||||
#如果你想要修改配置文件,请在修改后将version的值进行变更
|
#如果你想要修改配置文件,请在修改后将version的值进行变更
|
||||||
@@ -18,12 +18,7 @@ nickname = "麦麦"
|
|||||||
alias_names = ["麦叠", "牢麦"] #该选项还在调试中,暂时未生效
|
alias_names = ["麦叠", "牢麦"] #该选项还在调试中,暂时未生效
|
||||||
|
|
||||||
[chat_target]
|
[chat_target]
|
||||||
talk_allowed_groups = [
|
|
||||||
123,
|
|
||||||
123,
|
|
||||||
] #可以回复消息的群号码
|
|
||||||
talk_frequency_down_groups = [] #降低回复频率的群号码
|
talk_frequency_down_groups = [] #降低回复频率的群号码
|
||||||
ban_user_id = [] #禁止回复和读取消息的QQ号
|
|
||||||
|
|
||||||
[personality] #未完善
|
[personality] #未完善
|
||||||
personality_core = "用一句话或几句话描述人格的核心特点" # 建议20字以内,谁再写3000字小作文敲谁脑袋
|
personality_core = "用一句话或几句话描述人格的核心特点" # 建议20字以内,谁再写3000字小作文敲谁脑袋
|
||||||
@@ -171,8 +166,6 @@ enable_kaomoji_protection = false # 是否启用颜文字保护
|
|||||||
enable = true
|
enable = true
|
||||||
|
|
||||||
[experimental] #实验性功能
|
[experimental] #实验性功能
|
||||||
enable_friend_chat = false # 是否启用好友聊天
|
|
||||||
talk_allowed_private = [] # 可以回复消息的QQ号
|
|
||||||
pfc_chatting = false # 是否启用PFC聊天,该功能仅作用于私聊,与回复模式独立
|
pfc_chatting = false # 是否启用PFC聊天,该功能仅作用于私聊,与回复模式独立
|
||||||
|
|
||||||
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
||||||
|
|||||||
Reference in New Issue
Block a user