删除无用函数
This commit is contained in:
@@ -629,31 +629,6 @@ class CycleProcessor:
|
||||
traceback.print_exc()
|
||||
return False, "", ""
|
||||
|
||||
def _get_direct_reply_plan(self, loop_start_time):
|
||||
"""
|
||||
获取直接回复的规划结果
|
||||
|
||||
Args:
|
||||
loop_start_time: 循环开始时间
|
||||
|
||||
Returns:
|
||||
dict: 包含直接回复动作的规划结果
|
||||
|
||||
功能说明:
|
||||
- 在某些情况下跳过复杂规划,直接返回回复动作
|
||||
- 主要用于NORMAL模式下没有其他可用动作时的简化处理
|
||||
"""
|
||||
return {
|
||||
"action_result": {
|
||||
"action_type": "reply",
|
||||
"action_data": {"loop_start_time": loop_start_time},
|
||||
"reasoning": "",
|
||||
"timestamp": time.time(),
|
||||
"is_parallel": False,
|
||||
},
|
||||
"action_prompt": "",
|
||||
}
|
||||
|
||||
def _build_final_loop_info(self, reply_loop_info, action_success, action_reply_text, action_command, plan_result):
|
||||
"""
|
||||
构建最终的循环信息
|
||||
|
||||
@@ -261,13 +261,7 @@ class HeartFChatting:
|
||||
# 重置累积兴趣值,因为消息已经被成功处理
|
||||
self.context.breaking_accumulated_interest = 0.0
|
||||
logger.info(f"{self.context.log_prefix} 能量值增加,当前能量值:{self.context.energy_value:.1f},重置累积兴趣值")
|
||||
|
||||
self._check_focus_exit()
|
||||
|
||||
else:
|
||||
# 无新消息时,只进行模式检查,不进行思考循环
|
||||
self._check_focus_exit()
|
||||
|
||||
|
||||
|
||||
# 更新上一帧的睡眠状态
|
||||
self.context.was_sleeping = is_sleeping
|
||||
@@ -288,62 +282,6 @@ class HeartFChatting:
|
||||
|
||||
return has_new_messages
|
||||
|
||||
def _check_focus_exit(self):
|
||||
"""
|
||||
检查是否应该退出FOCUS模式
|
||||
|
||||
功能说明:
|
||||
- 区分私聊和群聊环境
|
||||
- 在强制私聊focus模式下,能量值低于1时重置为5但不退出
|
||||
- 在群聊focus模式下,如果配置为focus则不退出
|
||||
- 其他情况下,能量值低于1时退出到NORMAL模式
|
||||
"""
|
||||
is_private_chat = self.context.chat_stream.group_info is None if self.context.chat_stream else False
|
||||
is_group_chat = not is_private_chat
|
||||
|
||||
if global_config.chat.force_focus_private and is_private_chat:
|
||||
if self.context.energy_value <= 1:
|
||||
self.context.energy_value = 5
|
||||
return
|
||||
|
||||
if is_group_chat and global_config.chat.group_chat_mode == "focus":
|
||||
return
|
||||
|
||||
if self.context.energy_value <= 1: # 如果能量值小于等于1(非强制情况)
|
||||
self.context.energy_value = 1 # 将能量值设置为1
|
||||
|
||||
def _check_focus_entry(self, new_message_count: int):
|
||||
"""
|
||||
检查是否应该进入FOCUS模式
|
||||
|
||||
Args:
|
||||
new_message_count: 新消息数量
|
||||
|
||||
功能说明:
|
||||
- 区分私聊和群聊环境
|
||||
- 强制私聊focus模式:直接进入FOCUS模式并设置能量值为10
|
||||
- 群聊normal模式:不进入FOCUS模式
|
||||
- 根据focus_value配置和消息数量决定是否进入FOCUS模式
|
||||
- 当消息数量超过阈值或能量值达到30时进入FOCUS模式
|
||||
"""
|
||||
is_private_chat = self.context.chat_stream.group_info is None if self.context.chat_stream else False
|
||||
is_group_chat = not is_private_chat
|
||||
|
||||
if global_config.chat.force_focus_private and is_private_chat:
|
||||
self.context.energy_value = 10
|
||||
return
|
||||
|
||||
if is_group_chat and global_config.chat.group_chat_mode == "normal":
|
||||
return
|
||||
|
||||
if global_config.chat.focus_value != 0: # 如果专注值配置不为0(启用自动专注)
|
||||
if new_message_count > 3 / pow(
|
||||
global_config.chat.focus_value, 0.5
|
||||
): # 如果新消息数超过阈值(基于专注值计算)
|
||||
self.context.energy_value = (
|
||||
10 + (new_message_count / (3 / pow(global_config.chat.focus_value, 0.5))) * 10
|
||||
) # 根据消息数量计算能量值
|
||||
return # 返回,不再检查其他条件
|
||||
|
||||
def _handle_wakeup_messages(self, messages):
|
||||
"""
|
||||
@@ -463,57 +401,3 @@ class HeartFChatting:
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
return False,0.0
|
||||
|
||||
async def _execute_no_reply(self, new_message: List[Dict[str, Any]]) -> bool:
|
||||
"""执行breaking形式的no_reply(原有逻辑)"""
|
||||
new_message_count = len(new_message)
|
||||
# 检查消息数量是否达到阈值
|
||||
talk_frequency = global_config.chat.get_current_talk_frequency(self.context.stream_id)
|
||||
modified_exit_count_threshold = self.context.focus_energy / talk_frequency
|
||||
|
||||
if new_message_count >= modified_exit_count_threshold:
|
||||
# 记录兴趣度到列表
|
||||
total_interest = 0.0
|
||||
for msg_dict in new_message:
|
||||
interest_value = msg_dict.get("interest_value", 0.0)
|
||||
if msg_dict.get("processed_plain_text", ""):
|
||||
total_interest += interest_value
|
||||
|
||||
self.recent_interest_records.append(total_interest)
|
||||
|
||||
logger.info(
|
||||
f"{self.context.log_prefix} 累计消息数量达到{new_message_count}条(>{modified_exit_count_threshold}),结束等待"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
# 检查累计兴趣值
|
||||
if new_message_count > 0:
|
||||
accumulated_interest = 0.0
|
||||
for msg_dict in new_message:
|
||||
text = msg_dict.get("processed_plain_text", "")
|
||||
interest_value = msg_dict.get("interest_value", 0.0)
|
||||
if text:
|
||||
accumulated_interest += interest_value
|
||||
|
||||
# 只在兴趣值变化时输出log
|
||||
if not hasattr(self, "_last_accumulated_interest") or accumulated_interest != self._last_accumulated_interest:
|
||||
logger.info(f"{self.context.log_prefix} breaking形式当前累计兴趣值: {accumulated_interest:.2f}, 当前聊天频率: {talk_frequency:.2f}")
|
||||
self._last_accumulated_interest = accumulated_interest
|
||||
|
||||
if accumulated_interest >= 3 / talk_frequency:
|
||||
# 记录兴趣度到列表
|
||||
self.recent_interest_records.append(accumulated_interest)
|
||||
|
||||
logger.info(
|
||||
f"{self.context.log_prefix} 累计兴趣值达到{accumulated_interest:.2f}(>{3 / talk_frequency}),结束等待"
|
||||
)
|
||||
return True
|
||||
|
||||
# 每10秒输出一次等待状态
|
||||
if int(time.time() - self.context.last_read_time) > 0 and int(time.time() - self.context.last_read_time) % 10 == 0:
|
||||
logger.info(
|
||||
f"{self.context.log_prefix} 已等待{time.time() - self.context.last_read_time:.0f}秒,累计{new_message_count}条消息,继续等待..."
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
@@ -122,43 +122,6 @@ class CycleDetail:
|
||||
self.loop_plan_info = loop_info["loop_plan_info"]
|
||||
self.loop_action_info = loop_info["loop_action_info"]
|
||||
|
||||
|
||||
def get_recent_message_stats(minutes: float = 30, chat_id: Optional[str] = None) -> dict:
|
||||
"""
|
||||
获取最近消息统计信息
|
||||
|
||||
Args:
|
||||
minutes: 检索的分钟数,默认30分钟
|
||||
chat_id: 指定的chat_id,仅统计该chat下的消息。为None时统计全部
|
||||
|
||||
Returns:
|
||||
dict: {"bot_reply_count": int, "total_message_count": int}
|
||||
|
||||
功能说明:
|
||||
- 统计指定时间范围内的消息数量
|
||||
- 区分机器人回复和总消息数
|
||||
- 可以针对特定聊天或全局统计
|
||||
- 用于分析聊天活跃度和机器人参与度
|
||||
"""
|
||||
|
||||
now = time.time()
|
||||
start_time = now - minutes * 60
|
||||
bot_id = global_config.bot.qq_account
|
||||
|
||||
filter_base: Dict[str, Any] = {"time": {"$gte": start_time}}
|
||||
if chat_id is not None:
|
||||
filter_base["chat_id"] = chat_id
|
||||
|
||||
# 总消息数
|
||||
total_message_count = count_messages(filter_base)
|
||||
# bot自身回复数
|
||||
bot_filter = filter_base.copy()
|
||||
bot_filter["user_id"] = bot_id
|
||||
bot_reply_count = count_messages(bot_filter)
|
||||
|
||||
return {"bot_reply_count": bot_reply_count, "total_message_count": total_message_count}
|
||||
|
||||
|
||||
async def send_typing():
|
||||
"""
|
||||
发送打字状态指示
|
||||
|
||||
Reference in New Issue
Block a user