修正willing_manager内因为代码合并导致的冗余,去除几个print

This commit is contained in:
Pliosauroidea
2025-03-12 08:25:55 +08:00
parent 0c26d9b412
commit 27be42b8f0

View File

@@ -5,10 +5,11 @@ from typing import Dict
from .config import global_config from .config import global_config
from .chat_stream import ChatStream from .chat_stream import ChatStream
from loguru import logger
class WillingManager: class WillingManager:
def __init__(self): def __init__(self):
self.chat_reply_willing: Dict[str, float] = {} # 存储每个聊天流的回复意愿
self.chat_reply_willing: Dict[str, float] = {} # 存储每个聊天流的回复意愿 self.chat_reply_willing: Dict[str, float] = {} # 存储每个聊天流的回复意愿
self._decay_task = None self._decay_task = None
self._started = False self._started = False
@@ -19,8 +20,6 @@ class WillingManager:
await asyncio.sleep(5) await asyncio.sleep(5)
for chat_id in self.chat_reply_willing: for chat_id in self.chat_reply_willing:
self.chat_reply_willing[chat_id] = max(0, self.chat_reply_willing[chat_id] * 0.6) self.chat_reply_willing[chat_id] = max(0, self.chat_reply_willing[chat_id] * 0.6)
for chat_id in self.chat_reply_willing:
self.chat_reply_willing[chat_id] = max(0, self.chat_reply_willing[chat_id] * 0.6)
def get_willing(self, chat_stream: ChatStream) -> float: def get_willing(self, chat_stream: ChatStream) -> float:
"""获取指定聊天流的回复意愿""" """获取指定聊天流的回复意愿"""
@@ -29,20 +28,19 @@ class WillingManager:
return self.chat_reply_willing.get(stream.stream_id, 0) return self.chat_reply_willing.get(stream.stream_id, 0)
return 0 return 0
def set_willing(self, chat_id: str, willing: float):
"""设置指定聊天流的回复意愿"""
self.chat_reply_willing[chat_id] = willing
def set_willing(self, chat_id: str, willing: float): def set_willing(self, chat_id: str, willing: float):
"""设置指定聊天流的回复意愿""" """设置指定聊天流的回复意愿"""
self.chat_reply_willing[chat_id] = willing self.chat_reply_willing[chat_id] = willing
async def change_reply_willing_received(self, async def change_reply_willing_received(
self,
chat_stream: ChatStream, chat_stream: ChatStream,
topic: str = None, topic: str = None,
is_mentioned_bot: bool = False, is_mentioned_bot: bool = False,
config=None, config=None,
is_emoji: bool = False, is_emoji: bool = False,
interested_rate: float = 0) -> float: interested_rate: float = 0,
) -> float:
"""改变指定聊天流的回复意愿并返回回复概率""" """改变指定聊天流的回复意愿并返回回复概率"""
# 获取或创建聊天流 # 获取或创建聊天流
stream = chat_stream stream = chat_stream
@@ -50,19 +48,18 @@ class WillingManager:
current_willing = self.chat_reply_willing.get(chat_id, 0) current_willing = self.chat_reply_willing.get(chat_id, 0)
# print(f"初始意愿: {current_willing}")
if is_mentioned_bot and current_willing < 1.0: if is_mentioned_bot and current_willing < 1.0:
current_willing += 0.9 current_willing += 0.9
print(f"被提及, 当前意愿: {current_willing}") logger.debug(f"被提及, 当前意愿: {current_willing}")
elif is_mentioned_bot: elif is_mentioned_bot:
current_willing += 0.05 current_willing += 0.05
print(f"被重复提及, 当前意愿: {current_willing}") logger.debug(f"被重复提及, 当前意愿: {current_willing}")
if is_emoji: if is_emoji:
current_willing *= 0.1 current_willing *= 0.1
print(f"表情包, 当前意愿: {current_willing}") logger.debug(f"表情包, 当前意愿: {current_willing}")
print(f"放大系数_interested_rate: {global_config.response_interested_rate_amplifier}") logger.debug(f"放大系数_interested_rate: {global_config.response_interested_rate_amplifier}")
interested_rate *= global_config.response_interested_rate_amplifier # 放大回复兴趣度 interested_rate *= global_config.response_interested_rate_amplifier # 放大回复兴趣度
if interested_rate > 0.4: if interested_rate > 0.4:
# print(f"兴趣度: {interested_rate}, 当前意愿: {current_willing}") # print(f"兴趣度: {interested_rate}, 当前意愿: {current_willing}")
@@ -107,5 +104,6 @@ class WillingManager:
self._decay_task = asyncio.create_task(self._decay_reply_willing()) self._decay_task = asyncio.create_task(self._decay_reply_willing())
self._started = True self._started = True
# 创建全局实例 # 创建全局实例
willing_manager = WillingManager() willing_manager = WillingManager()