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