🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -213,4 +213,3 @@ def analyze_expressions():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
analyze_expressions()
|
analyze_expressions()
|
||||||
|
|
||||||
|
|||||||
@@ -194,4 +194,3 @@ def analyze_group_similarity():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
analyze_group_similarity()
|
analyze_group_similarity()
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class HeartFChatting:
|
|||||||
# 基础值30条,通过exit_focus_threshold调节:threshold越小,越容易疲惫
|
# 基础值30条,通过exit_focus_threshold调节:threshold越小,越容易疲惫
|
||||||
self._message_threshold = max(10, int(30 * global_config.chat.exit_focus_threshold))
|
self._message_threshold = max(10, int(30 * global_config.chat.exit_focus_threshold))
|
||||||
self._fatigue_triggered = False # 是否已触发疲惫退出
|
self._fatigue_triggered = False # 是否已触发疲惫退出
|
||||||
|
|
||||||
# 初始化观察器
|
# 初始化观察器
|
||||||
self.observations: List[Observation] = []
|
self.observations: List[Observation] = []
|
||||||
self._register_observations()
|
self._register_observations()
|
||||||
@@ -184,7 +184,9 @@ class HeartFChatting:
|
|||||||
actual_version = performance_version or get_hfc_version()
|
actual_version = performance_version or get_hfc_version()
|
||||||
self.performance_logger = HFCPerformanceLogger(chat_id, actual_version)
|
self.performance_logger = HFCPerformanceLogger(chat_id, actual_version)
|
||||||
|
|
||||||
logger.info(f"{self.log_prefix} HeartFChatting 初始化完成,消息疲惫阈值: {self._message_threshold}条(基于exit_focus_threshold={global_config.chat.exit_focus_threshold}计算,仅在auto模式下生效)")
|
logger.info(
|
||||||
|
f"{self.log_prefix} HeartFChatting 初始化完成,消息疲惫阈值: {self._message_threshold}条(基于exit_focus_threshold={global_config.chat.exit_focus_threshold}计算,仅在auto模式下生效)"
|
||||||
|
)
|
||||||
|
|
||||||
def _register_observations(self):
|
def _register_observations(self):
|
||||||
"""注册所有观察器"""
|
"""注册所有观察器"""
|
||||||
@@ -300,7 +302,7 @@ class HeartFChatting:
|
|||||||
try:
|
try:
|
||||||
# 重置消息计数器,开始新的focus会话
|
# 重置消息计数器,开始新的focus会话
|
||||||
self.reset_message_count()
|
self.reset_message_count()
|
||||||
|
|
||||||
# 标记为活动状态,防止重复启动
|
# 标记为活动状态,防止重复启动
|
||||||
self._loop_active = True
|
self._loop_active = True
|
||||||
|
|
||||||
@@ -1180,19 +1182,26 @@ class HeartFChatting:
|
|||||||
if action == "reply" and success:
|
if action == "reply" and success:
|
||||||
self._message_count += 1
|
self._message_count += 1
|
||||||
current_threshold = self._get_current_fatigue_threshold()
|
current_threshold = self._get_current_fatigue_threshold()
|
||||||
logger.info(f"{self.log_prefix} 已发送第 {self._message_count} 条消息(动态阈值: {current_threshold}, exit_focus_threshold: {global_config.chat.exit_focus_threshold})")
|
logger.info(
|
||||||
|
f"{self.log_prefix} 已发送第 {self._message_count} 条消息(动态阈值: {current_threshold}, exit_focus_threshold: {global_config.chat.exit_focus_threshold})"
|
||||||
|
)
|
||||||
|
|
||||||
# 检查是否达到疲惫阈值(只有在auto模式下才会自动退出)
|
# 检查是否达到疲惫阈值(只有在auto模式下才会自动退出)
|
||||||
if (global_config.chat.chat_mode == "auto" and
|
if (
|
||||||
self._message_count >= current_threshold and
|
global_config.chat.chat_mode == "auto"
|
||||||
not self._fatigue_triggered):
|
and self._message_count >= current_threshold
|
||||||
|
and not self._fatigue_triggered
|
||||||
|
):
|
||||||
self._fatigue_triggered = True
|
self._fatigue_triggered = True
|
||||||
logger.info(f"{self.log_prefix} [auto模式] 已发送 {self._message_count} 条消息,达到疲惫阈值 {current_threshold},麦麦感到疲惫了,准备退出专注聊天模式")
|
logger.info(
|
||||||
|
f"{self.log_prefix} [auto模式] 已发送 {self._message_count} 条消息,达到疲惫阈值 {current_threshold},麦麦感到疲惫了,准备退出专注聊天模式"
|
||||||
|
)
|
||||||
# 设置系统命令,在下次循环检查时触发退出
|
# 设置系统命令,在下次循环检查时触发退出
|
||||||
command = "stop_focus_chat"
|
command = "stop_focus_chat"
|
||||||
elif (self._message_count >= current_threshold and
|
elif self._message_count >= current_threshold and global_config.chat.chat_mode != "auto":
|
||||||
global_config.chat.chat_mode != "auto"):
|
logger.info(
|
||||||
logger.info(f"{self.log_prefix} [非auto模式] 已发送 {self._message_count} 条消息,达到疲惫阈值 {current_threshold},但非auto模式不会自动退出")
|
f"{self.log_prefix} [非auto模式] 已发送 {self._message_count} 条消息,达到疲惫阈值 {current_threshold},但非auto模式不会自动退出"
|
||||||
|
)
|
||||||
|
|
||||||
logger.debug(f"{self.log_prefix} 麦麦执行了'{action}', 返回结果'{success}', '{reply_text}', '{command}'")
|
logger.debug(f"{self.log_prefix} 麦麦执行了'{action}', 返回结果'{success}', '{reply_text}', '{command}'")
|
||||||
|
|
||||||
@@ -1205,7 +1214,7 @@ class HeartFChatting:
|
|||||||
|
|
||||||
def _get_current_fatigue_threshold(self) -> int:
|
def _get_current_fatigue_threshold(self) -> int:
|
||||||
"""动态获取当前的疲惫阈值,基于exit_focus_threshold配置
|
"""动态获取当前的疲惫阈值,基于exit_focus_threshold配置
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: 当前的疲惫阈值
|
int: 当前的疲惫阈值
|
||||||
"""
|
"""
|
||||||
@@ -1213,7 +1222,7 @@ class HeartFChatting:
|
|||||||
|
|
||||||
def get_message_count_info(self) -> dict:
|
def get_message_count_info(self) -> dict:
|
||||||
"""获取消息计数信息
|
"""获取消息计数信息
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: 包含消息计数信息的字典
|
dict: 包含消息计数信息的字典
|
||||||
"""
|
"""
|
||||||
@@ -1222,7 +1231,7 @@ class HeartFChatting:
|
|||||||
"current_count": self._message_count,
|
"current_count": self._message_count,
|
||||||
"threshold": current_threshold,
|
"threshold": current_threshold,
|
||||||
"fatigue_triggered": self._fatigue_triggered,
|
"fatigue_triggered": self._fatigue_triggered,
|
||||||
"remaining": max(0, current_threshold - self._message_count)
|
"remaining": max(0, current_threshold - self._message_count),
|
||||||
}
|
}
|
||||||
|
|
||||||
def reset_message_count(self):
|
def reset_message_count(self):
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class MuteAction(BaseAction):
|
|||||||
if allowed_group == current_group_key:
|
if allowed_group == current_group_key:
|
||||||
logger.info(f"{self.log_prefix} 群组 {current_group_key} 有禁言动作权限")
|
logger.info(f"{self.log_prefix} 群组 {current_group_key} 有禁言动作权限")
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
logger.warning(f"{self.log_prefix} 群组 {current_group_key} 没有禁言动作权限")
|
logger.warning(f"{self.log_prefix} 群组 {current_group_key} 没有禁言动作权限")
|
||||||
return False, "当前群组没有使用禁言动作的权限"
|
return False, "当前群组没有使用禁言动作的权限"
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ class MuteAction(BaseAction):
|
|||||||
|
|
||||||
# 获取模板化消息
|
# 获取模板化消息
|
||||||
message = self._get_template_message(target, time_str, reason)
|
message = self._get_template_message(target, time_str, reason)
|
||||||
|
|
||||||
if not has_permission:
|
if not has_permission:
|
||||||
logger.warning(f"{self.log_prefix} 权限检查失败: {permission_error}")
|
logger.warning(f"{self.log_prefix} 权限检查失败: {permission_error}")
|
||||||
result_status, result_message = await generator_api.rewrite_reply(
|
result_status, result_message = await generator_api.rewrite_reply(
|
||||||
@@ -196,20 +196,18 @@ class MuteAction(BaseAction):
|
|||||||
"reason": "表达自己没有在这个群禁言的能力",
|
"reason": "表达自己没有在这个群禁言的能力",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if result_status:
|
if result_status:
|
||||||
for reply_seg in result_message:
|
for reply_seg in result_message:
|
||||||
data = reply_seg[1]
|
data = reply_seg[1]
|
||||||
await self.send_text(data)
|
await self.send_text(data)
|
||||||
|
|
||||||
await self.store_action_info(
|
await self.store_action_info(
|
||||||
action_build_into_prompt=True,
|
action_build_into_prompt=True,
|
||||||
action_prompt_display=f"尝试禁言了用户 {target},但是没有权限,无法禁言",
|
action_prompt_display=f"尝试禁言了用户 {target},但是没有权限,无法禁言",
|
||||||
action_done=True,
|
action_done=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 不发送错误消息,静默拒绝
|
# 不发送错误消息,静默拒绝
|
||||||
return False, permission_error
|
return False, permission_error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user