From 195fc7327cb71d142e601189334f63d4bf9153f9 Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Tue, 15 Apr 2025 22:39:33 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E9=87=8D=E6=9E=84mxp=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E7=9A=84=E5=9F=BA=E7=A1=80=E6=84=8F=E6=84=BF=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/willing/mode_classical.py | 5 ---- src/plugins/willing/mode_dynamic.py | 5 ---- src/plugins/willing/mode_mxp.py | 41 +++++++------------------- src/plugins/willing/willing_manager.py | 20 ++++++------- 4 files changed, 21 insertions(+), 50 deletions(-) diff --git a/src/plugins/willing/mode_classical.py b/src/plugins/willing/mode_classical.py index 294539d08..b74666215 100644 --- a/src/plugins/willing/mode_classical.py +++ b/src/plugins/willing/mode_classical.py @@ -75,8 +75,3 @@ class ClassicalWillingManager(BaseWillingManager): async def not_reply_handle(self, message_id): return await super().not_reply_handle(message_id) - async def get_variable_parameters(self): - return await super().get_variable_parameters() - - async def set_variable_parameters(self, parameters): - return await super().set_variable_parameters(parameters) diff --git a/src/plugins/willing/mode_dynamic.py b/src/plugins/willing/mode_dynamic.py index 0487a1a98..1a5ebbd15 100644 --- a/src/plugins/willing/mode_dynamic.py +++ b/src/plugins/willing/mode_dynamic.py @@ -235,8 +235,3 @@ class DynamicWillingManager(BaseWillingManager): async def after_generate_reply_handle(self, message_id): return await super().after_generate_reply_handle(message_id) - async def get_variable_parameters(self): - return await super().get_variable_parameters() - - async def set_variable_parameters(self, parameters): - return await super().set_variable_parameters(parameters) diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index b4fc1448c..05b6c7e5c 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -37,8 +37,8 @@ class MxpWillingManager(BaseWillingManager): # 可变参数 self.intention_decay_rate = 0.93 # 意愿衰减率 - self.message_expiration_time = 120 # 消息过期时间(秒) - self.number_of_message_storage = 10 # 消息存储数量 + self.number_of_message_storage = 12 # 消息存储数量 + self.expected_replies_per_min = 3 # 每分钟预期回复数 self.basic_maximum_willing = 0.5 # 基础最大意愿值 self.mention_willing_gain = 0.6 # 提及意愿增益 self.interest_willing_gain = 0.3 # 兴趣意愿增益 @@ -193,7 +193,8 @@ class MxpWillingManager(BaseWillingManager): # 清理过期消息 current_time = time.time() message_times = [ - msg_time for msg_time in message_times if current_time - msg_time < self.message_expiration_time + msg_time for msg_time in message_times if current_time - msg_time < + self.number_of_message_storage * self.basic_maximum_willing / self.expected_replies_per_min * 60 ] self.chat_new_message_time[chat_id] = message_times @@ -202,38 +203,13 @@ class MxpWillingManager(BaseWillingManager): update_time = 20 elif len(message_times) == self.number_of_message_storage: time_interval = current_time - message_times[0] - basic_willing = self.basic_maximum_willing * math.sqrt( - time_interval / self.message_expiration_time - ) + basic_willing = self._basic_willing_coefficient_culculate(time_interval) self.chat_reply_willing[chat_id] = basic_willing - update_time = 17 * math.sqrt(time_interval / self.message_expiration_time) + 3 + update_time = 17 * basic_willing / self.basic_maximum_willing + 3 else: self.logger.debug(f"聊天流{chat_id}消息时间数量异常,数量:{len(message_times)}") self.chat_reply_willing[chat_id] = 0 - async def get_variable_parameters(self) -> Dict[str, str]: - """获取可变参数""" - return { - "intention_decay_rate": "意愿衰减率", - "message_expiration_time": "消息过期时间(秒)", - "number_of_message_storage": "消息存储数量", - "basic_maximum_willing": "基础最大意愿值", - "mention_willing_gain": "提及意愿增益", - "interest_willing_gain": "兴趣意愿增益", - "emoji_response_penalty": "表情包回复惩罚", - "down_frequency_rate": "降低回复频率的群组惩罚系数", - "single_chat_gain": "单聊增益(不仅是私聊)", - } - - async def set_variable_parameters(self, parameters: Dict[str, any]): - """设置可变参数""" - async with self.lock: - for key, value in parameters.items(): - if hasattr(self, key): - setattr(self, key, value) - self.logger.debug(f"参数 {key} 已更新为 {value}") - else: - self.logger.debug(f"尝试设置未知参数 {key}") def _get_relationship_level_num(self, relationship_value) -> int: """关系等级计算""" @@ -253,5 +229,10 @@ class MxpWillingManager(BaseWillingManager): level_num = 5 if relationship_value > 1000 else 0 return level_num - 2 + def _basic_willing_coefficient_culculate(self, t: float) -> float: + """基础意愿值系数计算""" + return math.tan(t * self.expected_replies_per_min * math.pi + / 120 / self.number_of_message_storage) / 2 + async def get_willing(self, chat_id): return self.temporary_willing diff --git a/src/plugins/willing/willing_manager.py b/src/plugins/willing/willing_manager.py index ada995120..28185bff1 100644 --- a/src/plugins/willing/willing_manager.py +++ b/src/plugins/willing/willing_manager.py @@ -18,8 +18,8 @@ after_generate_reply_handle 确定要回复后,在生成回复后的处理 not_reply_handle 确定不回复后的处理 get_reply_probability 获取回复概率 bombing_buffer_message_handle 缓冲器炸飞消息后的处理 -get_variable_parameters 获取可变参数组,返回一个字典,key为参数名称,value为参数描述(此方法是为拆分全局设置准备) -set_variable_parameters 设置可变参数组,你需要传入一个字典,key为参数名称,value为参数值(此方法是为拆分全局设置准备) +get_variable_parameters 暂不确定 +set_variable_parameters 暂不确定 以下2个方法根据你的实现可以做调整: get_willing 获取某聊天流意愿 set_willing 设置某聊天流意愿 @@ -152,15 +152,15 @@ class BaseWillingManager(ABC): async with self.lock: self.chat_reply_willing[chat_id] = willing - @abstractmethod - async def get_variable_parameters(self) -> Dict[str, str]: - """抽象方法:获取可变参数""" - pass + # @abstractmethod + # async def get_variable_parameters(self) -> Dict[str, str]: + # """抽象方法:获取可变参数""" + # pass - @abstractmethod - async def set_variable_parameters(self, parameters: Dict[str, any]): - """抽象方法:设置可变参数""" - pass + # @abstractmethod + # async def set_variable_parameters(self, parameters: Dict[str, any]): + # """抽象方法:设置可变参数""" + # pass def init_willing_manager() -> BaseWillingManager: From 21179884cfd2396ba49a8e762839b41d0652c76a Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Tue, 15 Apr 2025 23:55:15 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E7=96=B2=E5=8A=B3=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/willing/mode_mxp.py | 51 +++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index 05b6c7e5c..3fb1d7db2 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -10,6 +10,7 @@ Mxp 模式:梦溪畔独家赞助 4.限制同时思考的消息数量,防止喷射 5.拥有单聊增益,无论在群里还是私聊,只要bot一直和你聊,就会增加意愿值 6.意愿分为衰减意愿+临时意愿 +7.疲劳机制 如果你发现本模式出现了bug 上上策是询问智慧的小草神() @@ -34,26 +35,47 @@ class MxpWillingManager(BaseWillingManager): self.chat_new_message_time: Dict[str, list[float]] = {} # 聊天流ID: 消息时间 self.last_response_person: Dict[str, tuple[str, int]] = {} # 上次回复的用户信息 self.temporary_willing: float = 0 # 临时意愿值 + self.chat_bot_message_time: Dict[str, list[float]] = {} # 聊天流ID: bot已回复消息时间 + self.chat_fatigue_punishment_list: Dict[str, list[tuple[float, float]]] = {} # 聊天流疲劳惩罚列, 聊天流ID: 惩罚时间列(开始时间,持续时间) + self.chat_fatigue_willing_attenuation: Dict[str, float] = {} # 聊天流疲劳意愿衰减值 # 可变参数 self.intention_decay_rate = 0.93 # 意愿衰减率 + self.number_of_message_storage = 12 # 消息存储数量 self.expected_replies_per_min = 3 # 每分钟预期回复数 self.basic_maximum_willing = 0.5 # 基础最大意愿值 + self.mention_willing_gain = 0.6 # 提及意愿增益 self.interest_willing_gain = 0.3 # 兴趣意愿增益 self.emoji_response_penalty = self.global_config.emoji_response_penalty # 表情包回复惩罚 self.down_frequency_rate = self.global_config.down_frequency_rate # 降低回复频率的群组惩罚系数 self.single_chat_gain = 0.12 # 单聊增益 + self.fatigue_messages_triggered_num = self.expected_replies_per_min # 疲劳消息触发数量(int) + self.fatigue_coefficient = 1.0 # 疲劳系数 + async def async_task_starter(self) -> None: """异步任务启动器""" asyncio.create_task(self._return_to_basic_willing()) asyncio.create_task(self._chat_new_message_to_change_basic_willing()) + asyncio.create_task(self.fatigue_attenuation()) async def before_generate_reply_handle(self, message_id: str): """回复前处理""" - pass + current_time = time.time() + async with self.lock: + w_info = self.ongoing_messages[message_id] + if w_info.chat_id not in self.chat_bot_message_time: + self.chat_bot_message_time[w_info.chat_id] = [] + self.chat_bot_message_time[w_info.chat_id] = \ + [t for t in self.chat_bot_message_time[w_info.chat_id] if current_time - t < 60] + self.chat_bot_message_time[w_info.chat_id].append(current_time) + if len(self.chat_bot_message_time[w_info.chat_id]) == int(self.fatigue_messages_triggered_num): + time_interval = 60 - (current_time - self.chat_bot_message_time[w_info.chat_id].pop(0)) + if w_info.chat_id not in self.chat_fatigue_punishment_list: + self.chat_fatigue_punishment_list[w_info.chat_id] = [] + self.chat_fatigue_punishment_list[w_info.chat_id].append(current_time, time_interval * 2) async def after_generate_reply_handle(self, message_id: str): """回复后处理""" @@ -122,6 +144,8 @@ class MxpWillingManager(BaseWillingManager): elif len(chat_ongoing_messages) >= 4: current_willing = 0 + current_willing += self.chat_fatigue_willing_attenuation.get(w_info.chat_id, 0) + probability = self._willing_to_probability(current_willing) if w_info.is_emoji: @@ -179,8 +203,10 @@ class MxpWillingManager(BaseWillingManager): willing = max(0, willing) if willing < 2: probability = math.atan(willing * 2) / math.pi * 2 - else: + elif willing <2.5: probability = math.atan(willing * 4) / math.pi * 2 + else: + probability = 1 return probability async def _chat_new_message_to_change_basic_willing(self): @@ -203,7 +229,7 @@ class MxpWillingManager(BaseWillingManager): update_time = 20 elif len(message_times) == self.number_of_message_storage: time_interval = current_time - message_times[0] - basic_willing = self._basic_willing_coefficient_culculate(time_interval) + basic_willing = self._basic_willing_culculate(time_interval) self.chat_reply_willing[chat_id] = basic_willing update_time = 17 * basic_willing / self.basic_maximum_willing + 3 else: @@ -229,10 +255,25 @@ class MxpWillingManager(BaseWillingManager): level_num = 5 if relationship_value > 1000 else 0 return level_num - 2 - def _basic_willing_coefficient_culculate(self, t: float) -> float: - """基础意愿值系数计算""" + def _basic_willing_culculate(self, t: float) -> float: + """基础意愿值计算""" return math.tan(t * self.expected_replies_per_min * math.pi / 120 / self.number_of_message_storage) / 2 + + async def fatigue_attenuation(self): + """疲劳衰减""" + while True: + current_time = time.time() + await asyncio.sleep(1) + async with self.lock: + for chat_id, fatigue_list in self.chat_fatigue_punishment_list.items(): + fatigue_list = [z for z in fatigue_list if current_time - z[0] < z[1]] + self.chat_fatigue_willing_attenuation[chat_id] = 0 + for start_time, duration in fatigue_list: + self.chat_fatigue_willing_attenuation[chat_id] += \ + (self.chat_reply_willing[chat_id] * 2 / math.pi * math.asin( + 2 * (current_time - start_time) / duration - 1 + ) - self.chat_reply_willing[chat_id]) * self.fatigue_coefficient async def get_willing(self, chat_id): return self.temporary_willing From 10c89c0171d656247a1bc39b2c74eee9de2a5060 Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Wed, 16 Apr 2025 00:08:22 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/willing/mode_mxp.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index 3fb1d7db2..e0e233aac 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -55,6 +55,8 @@ class MxpWillingManager(BaseWillingManager): self.fatigue_messages_triggered_num = self.expected_replies_per_min # 疲劳消息触发数量(int) self.fatigue_coefficient = 1.0 # 疲劳系数 + self.is_debug = False # 是否开启调试模式 + async def async_task_starter(self) -> None: """异步任务启动器""" asyncio.create_task(self._return_to_basic_willing()) @@ -114,24 +116,38 @@ class MxpWillingManager(BaseWillingManager): async with self.lock: w_info = self.ongoing_messages[message_id] current_willing = self.chat_person_reply_willing[w_info.chat_id][w_info.person_id] + if self.is_debug: + self.logger.debug(f"基础意愿值:{current_willing}") if w_info.is_mentioned_bot: current_willing += self.mention_willing_gain / (int(current_willing) + 1) + if self.is_debug: + self.logger.debug(f"提及增益:{self.mention_willing_gain / (int(current_willing) + 1)}") if w_info.interested_rate > 0: current_willing += math.atan(w_info.interested_rate / 2) / math.pi * 2 * self.interest_willing_gain + if self.is_debug: + self.logger.debug(f"兴趣增益:{math.atan(w_info.interested_rate / 2) / math.pi * 2 * self.interest_willing_gain}") self.chat_person_reply_willing[w_info.chat_id][w_info.person_id] = current_willing rel_value = await w_info.person_info_manager.get_value(w_info.person_id, "relationship_value") rel_level = self._get_relationship_level_num(rel_value) current_willing += rel_level * 0.1 + if self.is_debug: + self.logger.debug(f"关系增益:{rel_level * 0.1}") if ( w_info.chat_id in self.last_response_person and self.last_response_person[w_info.chat_id][0] == w_info.person_id ): current_willing += self.single_chat_gain * (2 * self.last_response_person[w_info.chat_id][1] + 1) + if self.is_debug: + self.logger.debug(f"单聊增益:{self.single_chat_gain * (2 * self.last_response_person[w_info.chat_id][1] + 1)}") + + current_willing += self.chat_fatigue_willing_attenuation.get(w_info.chat_id, 0) + if self.is_debug: + self.logger.debug(f"疲劳衰减:{self.chat_fatigue_willing_attenuation.get(w_info.chat_id, 0)}") chat_ongoing_messages = [msg for msg in self.ongoing_messages.values() if msg.chat_id == w_info.chat_id] chat_person_ogoing_messages = [msg for msg in chat_ongoing_messages if msg.person_id == w_info.person_id] @@ -143,8 +159,10 @@ class MxpWillingManager(BaseWillingManager): current_willing -= 1.5 elif len(chat_ongoing_messages) >= 4: current_willing = 0 - - current_willing += self.chat_fatigue_willing_attenuation.get(w_info.chat_id, 0) + else: + if self.is_debug: + self.logger.debug("无进行中消息惩罚") + probability = self._willing_to_probability(current_willing) From a20ca1d0f2bfd5d6aca2ad94b880f74e04e34c3c Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Wed, 16 Apr 2025 01:43:36 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/willing/mode_mxp.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index e0e233aac..f2df94288 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -61,7 +61,7 @@ class MxpWillingManager(BaseWillingManager): """异步任务启动器""" asyncio.create_task(self._return_to_basic_willing()) asyncio.create_task(self._chat_new_message_to_change_basic_willing()) - asyncio.create_task(self.fatigue_attenuation()) + asyncio.create_task(self._fatigue_attenuation()) async def before_generate_reply_handle(self, message_id: str): """回复前处理""" @@ -77,7 +77,7 @@ class MxpWillingManager(BaseWillingManager): time_interval = 60 - (current_time - self.chat_bot_message_time[w_info.chat_id].pop(0)) if w_info.chat_id not in self.chat_fatigue_punishment_list: self.chat_fatigue_punishment_list[w_info.chat_id] = [] - self.chat_fatigue_punishment_list[w_info.chat_id].append(current_time, time_interval * 2) + self.chat_fatigue_punishment_list[w_info.chat_id].append([current_time, time_interval * 2]) async def after_generate_reply_handle(self, message_id: str): """回复后处理""" @@ -120,9 +120,10 @@ class MxpWillingManager(BaseWillingManager): self.logger.debug(f"基础意愿值:{current_willing}") if w_info.is_mentioned_bot: - current_willing += self.mention_willing_gain / (int(current_willing) + 1) + current_willing_ = self.mention_willing_gain / (int(current_willing) + 1) + current_willing += current_willing_ if self.is_debug: - self.logger.debug(f"提及增益:{self.mention_willing_gain / (int(current_willing) + 1)}") + self.logger.debug(f"提及增益:{current_willing_}") if w_info.interested_rate > 0: current_willing += math.atan(w_info.interested_rate / 2) / math.pi * 2 * self.interest_willing_gain @@ -153,15 +154,20 @@ class MxpWillingManager(BaseWillingManager): chat_person_ogoing_messages = [msg for msg in chat_ongoing_messages if msg.person_id == w_info.person_id] if len(chat_person_ogoing_messages) >= 2: current_willing = 0 + if self.is_debug: + self.logger.debug("进行中消息惩罚:归0") elif len(chat_ongoing_messages) == 2: current_willing -= 0.5 + if self.is_debug: + self.logger.debug("进行中消息惩罚:-0.5") elif len(chat_ongoing_messages) == 3: current_willing -= 1.5 + if self.is_debug: + self.logger.debug("进行中消息惩罚:-1.5") elif len(chat_ongoing_messages) >= 4: current_willing = 0 - else: if self.is_debug: - self.logger.debug("无进行中消息惩罚") + self.logger.debug("进行中消息惩罚:归0") probability = self._willing_to_probability(current_willing) @@ -229,8 +235,8 @@ class MxpWillingManager(BaseWillingManager): async def _chat_new_message_to_change_basic_willing(self): """聊天流新消息改变基础意愿""" + update_time = 20 while True: - update_time = 20 await asyncio.sleep(update_time) async with self.lock: for chat_id, message_times in self.chat_new_message_time.items(): @@ -253,6 +259,8 @@ class MxpWillingManager(BaseWillingManager): else: self.logger.debug(f"聊天流{chat_id}消息时间数量异常,数量:{len(message_times)}") self.chat_reply_willing[chat_id] = 0 + if self.is_debug: + self.logger.debug(f"聊天流意愿值更新:{self.chat_reply_willing}") def _get_relationship_level_num(self, relationship_value) -> int: @@ -278,11 +286,11 @@ class MxpWillingManager(BaseWillingManager): return math.tan(t * self.expected_replies_per_min * math.pi / 120 / self.number_of_message_storage) / 2 - async def fatigue_attenuation(self): + async def _fatigue_attenuation(self): """疲劳衰减""" while True: - current_time = time.time() await asyncio.sleep(1) + current_time = time.time() async with self.lock: for chat_id, fatigue_list in self.chat_fatigue_punishment_list.items(): fatigue_list = [z for z in fatigue_list if current_time - z[0] < z[1]] From 0bba90b48cb011ef50f8d043ef22de78d5c17239 Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Wed, 16 Apr 2025 10:31:27 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E8=A1=B0=E5=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/willing/mode_mxp.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index f2df94288..f063f6f24 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -75,8 +75,6 @@ class MxpWillingManager(BaseWillingManager): self.chat_bot_message_time[w_info.chat_id].append(current_time) if len(self.chat_bot_message_time[w_info.chat_id]) == int(self.fatigue_messages_triggered_num): time_interval = 60 - (current_time - self.chat_bot_message_time[w_info.chat_id].pop(0)) - if w_info.chat_id not in self.chat_fatigue_punishment_list: - self.chat_fatigue_punishment_list[w_info.chat_id] = [] self.chat_fatigue_punishment_list[w_info.chat_id].append([current_time, time_interval * 2]) async def after_generate_reply_handle(self, message_id: str): @@ -99,7 +97,7 @@ class MxpWillingManager(BaseWillingManager): async with self.lock: w_info = self.ongoing_messages[message_id] if w_info.is_mentioned_bot: - self.chat_person_reply_willing[w_info.chat_id][w_info.person_id] += 0.2 + self.chat_person_reply_willing[w_info.chat_id][w_info.person_id] += self.mention_willing_gain / 2.5 if ( w_info.chat_id in self.last_response_person and self.last_response_person[w_info.chat_id][0] == w_info.person_id @@ -216,12 +214,17 @@ class MxpWillingManager(BaseWillingManager): self.ongoing_messages[message.message_info.message_id].person_id, self.chat_reply_willing[chat.stream_id] ) + current_time = time.time() if chat.stream_id not in self.chat_new_message_time: self.chat_new_message_time[chat.stream_id] = [] - self.chat_new_message_time[chat.stream_id].append(time.time()) + self.chat_new_message_time[chat.stream_id].append(current_time) if len(self.chat_new_message_time[chat.stream_id]) > self.number_of_message_storage: self.chat_new_message_time[chat.stream_id].pop(0) + if chat.stream_id not in self.chat_fatigue_punishment_list: + self.chat_fatigue_punishment_list[chat.stream_id] = [current_time, + self.number_of_message_storage * self.basic_maximum_willing / self.expected_replies_per_min * 60] + def _willing_to_probability(self, willing: float) -> float: """意愿值转化为概率""" willing = max(0, willing) From def7e7a000b12af903e915b9d3adf0e078261c32 Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Wed, 16 Apr 2025 11:29:43 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BA=A7=E7=94=9F=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/willing/mode_mxp.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index f063f6f24..82b5850ae 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -85,9 +85,9 @@ class MxpWillingManager(BaseWillingManager): rel_level = self._get_relationship_level_num(rel_value) self.chat_person_reply_willing[w_info.chat_id][w_info.person_id] += rel_level * 0.05 - now_chat_new_person = self.last_response_person.get(w_info.chat_id, ["", 0]) + now_chat_new_person = self.last_response_person.get(w_info.chat_id, [w_info.person_id, 0]) if now_chat_new_person[0] == w_info.person_id: - if now_chat_new_person[1] < 2: + if now_chat_new_person[1] < 3: now_chat_new_person[1] += 1 else: self.last_response_person[w_info.chat_id] = [w_info.person_id, 0] @@ -101,9 +101,10 @@ class MxpWillingManager(BaseWillingManager): if ( w_info.chat_id in self.last_response_person and self.last_response_person[w_info.chat_id][0] == w_info.person_id + and self.last_response_person[w_info.chat_id][1] ): self.chat_person_reply_willing[w_info.chat_id][w_info.person_id] += self.single_chat_gain * ( - 2 * self.last_response_person[w_info.chat_id][1] + 1 + 2 * self.last_response_person[w_info.chat_id][1] - 1 ) now_chat_new_person = self.last_response_person.get(w_info.chat_id, ["", 0]) if now_chat_new_person[0] != w_info.person_id: @@ -133,16 +134,17 @@ class MxpWillingManager(BaseWillingManager): rel_value = await w_info.person_info_manager.get_value(w_info.person_id, "relationship_value") rel_level = self._get_relationship_level_num(rel_value) current_willing += rel_level * 0.1 - if self.is_debug: + if self.is_debug and rel_level != 0: self.logger.debug(f"关系增益:{rel_level * 0.1}") if ( w_info.chat_id in self.last_response_person and self.last_response_person[w_info.chat_id][0] == w_info.person_id + and self.last_response_person[w_info.chat_id][1] ): current_willing += self.single_chat_gain * (2 * self.last_response_person[w_info.chat_id][1] + 1) if self.is_debug: - self.logger.debug(f"单聊增益:{self.single_chat_gain * (2 * self.last_response_person[w_info.chat_id][1] + 1)}") + self.logger.debug(f"单聊增益:{self.single_chat_gain * (2 * self.last_response_person[w_info.chat_id][1] - 1)}") current_willing += self.chat_fatigue_willing_attenuation.get(w_info.chat_id, 0) if self.is_debug: @@ -222,8 +224,12 @@ class MxpWillingManager(BaseWillingManager): self.chat_new_message_time[chat.stream_id].pop(0) if chat.stream_id not in self.chat_fatigue_punishment_list: - self.chat_fatigue_punishment_list[chat.stream_id] = [current_time, - self.number_of_message_storage * self.basic_maximum_willing / self.expected_replies_per_min * 60] + self.chat_fatigue_punishment_list[chat.stream_id] = [ + (current_time, self.number_of_message_storage * self.basic_maximum_willing / self.expected_replies_per_min * 60) + ] + self.chat_fatigue_willing_attenuation[chat.stream_id] = - 2 * self.basic_maximum_willing + + def _willing_to_probability(self, willing: float) -> float: """意愿值转化为概率""" From cce0c65ff567bf41e0016a8a88c1d8106536ca65 Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Wed, 16 Apr 2025 11:38:39 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=BC=8F=E4=BA=86=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/willing/mode_mxp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index 82b5850ae..8ed3b60e4 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -227,7 +227,7 @@ class MxpWillingManager(BaseWillingManager): self.chat_fatigue_punishment_list[chat.stream_id] = [ (current_time, self.number_of_message_storage * self.basic_maximum_willing / self.expected_replies_per_min * 60) ] - self.chat_fatigue_willing_attenuation[chat.stream_id] = - 2 * self.basic_maximum_willing + self.chat_fatigue_willing_attenuation[chat.stream_id] = - 2 * self.basic_maximum_willing * self.fatigue_coefficient From 4501e19dc8d4edb06d361f597557e882a44c6d16 Mon Sep 17 00:00:00 2001 From: meng_xi_pan Date: Wed, 16 Apr 2025 14:06:16 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=B1=BB=E5=9E=8B=E7=BB=93=E6=9E=84=E5=8F=98?= =?UTF-8?q?=E5=8A=A8=E8=80=8C=E5=AF=BC=E8=87=B4buffer=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/message_buffer.py | 24 +++++++++++++++---- .../reasoning_chat/reasoning_chat.py | 14 ++++++++--- .../think_flow_chat/think_flow_chat.py | 14 ++++++++--- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/plugins/chat/message_buffer.py b/src/plugins/chat/message_buffer.py index 21e490433..c2cfaa826 100644 --- a/src/plugins/chat/message_buffer.py +++ b/src/plugins/chat/message_buffer.py @@ -3,7 +3,7 @@ from src.common.logger import get_module_logger import asyncio from dataclasses import dataclass, field from .message import MessageRecv -from ..message.message_base import BaseMessageInfo, GroupInfo +from ..message.message_base import BaseMessageInfo, GroupInfo, Seg import hashlib from typing import Dict from collections import OrderedDict @@ -130,22 +130,36 @@ class MessageBuffer: keep_msgs = OrderedDict() combined_text = [] found = False - type = "text" + type = "seglist" is_update = True for msg_id, msg in self.buffer_pool[person_id_].items(): if msg_id == message.message_info.message_id: found = True - type = msg.message.message_segment.type + if msg.message.message_segment.type != "seglist": + type = msg.message.message_segment.type + else: + if (isinstance(msg.message.message_segment.data, list) + and all(isinstance(x, Seg) for x in msg.message.message_segment.data) + and len(msg.message.message_segment.data) == 1): + type = msg.message.message_segment.data[0].type combined_text.append(msg.message.processed_plain_text) continue if found: keep_msgs[msg_id] = msg elif msg.result == "F": # 收集F消息的文本内容 + F_type = "seglist" + if msg.message.message_segment.type != "seglist": + F_type = msg.message.message_segment.type + else: + if (isinstance(msg.message.message_segment.data, list) + and all(isinstance(x, Seg) for x in msg.message.message_segment.data) + and len(msg.message.message_segment.data) == 1): + F_type = msg.message.message_segment.data[0].type if hasattr(msg.message, "processed_plain_text") and msg.message.processed_plain_text: - if msg.message.message_segment.type == "text": + if F_type == "text": combined_text.append(msg.message.processed_plain_text) - elif msg.message.message_segment.type != "text": + elif F_type != "text": is_update = False elif msg.result == "U": logger.debug(f"异常未处理信息id: {msg.message.message_info.message_id}") diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index 2ce218a6f..acc381f80 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -192,11 +192,19 @@ class ReasoningChat: if not buffer_result: await willing_manager.bombing_buffer_message_handle(message.message_info.message_id) willing_manager.delete(message.message_info.message_id) - if message.message_segment.type == "text": + F_type = "seglist" + if message.message_segment.type != "seglist": + F_type =message.message_segment.type + else: + if (isinstance(message.message_segment.data, list) + and all(isinstance(x, Seg) for x in message.message_segment.data) + and len(message.message_segment.data) == 1): + F_type = message.message_segment.data[0].type + if F_type == "text": logger.info(f"触发缓冲,已炸飞消息:{message.processed_plain_text}") - elif message.message_segment.type == "image": + elif F_type == "image": logger.info("触发缓冲,已炸飞表情包/图片") - elif message.message_segment.type == "seglist": + elif F_type == "seglist": logger.info("触发缓冲,已炸飞消息列") return diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index 1e8e844eb..74d88dd4d 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -204,11 +204,19 @@ class ThinkFlowChat: if not buffer_result: await willing_manager.bombing_buffer_message_handle(message.message_info.message_id) willing_manager.delete(message.message_info.message_id) - if message.message_segment.type == "text": + F_type = "seglist" + if message.message_segment.type != "seglist": + F_type =message.message_segment.type + else: + if (isinstance(message.message_segment.data, list) + and all(isinstance(x, Seg) for x in message.message_segment.data) + and len(message.message_segment.data) == 1): + F_type = message.message_segment.data[0].type + if F_type == "text": logger.info(f"触发缓冲,已炸飞消息:{message.processed_plain_text}") - elif message.message_segment.type == "image": + elif F_type == "image": logger.info("触发缓冲,已炸飞表情包/图片") - elif message.message_segment.type == "seglist": + elif F_type == "seglist": logger.info("触发缓冲,已炸飞消息列") return