fix:修复插件无法被关闭,新增新log浏览器

This commit is contained in:
SengokuCola
2025-06-16 19:34:07 +08:00
parent 840dc538d4
commit 986e88d48c
10 changed files with 755 additions and 11 deletions

View File

@@ -96,7 +96,7 @@ class NormalChatGenerator:
try:
content, (reasoning_content, model_name) = await model.generate_response_async(prompt)
logger.debug(f"prompt:{prompt}\n生成回复:{content}")
logger.info(f"prompt:{prompt}\n生成回复:{content}")
logger.info(f"{message.processed_plain_text} 的回复:{content}")

View File

@@ -158,10 +158,10 @@ class NormalChatPlanner:
try:
content, (reasoning_content, model_name) = await self.planner_llm.generate_response_async(prompt)
logger.debug(f"{self.log_prefix}规划器原始提示词: {prompt}")
logger.debug(f"{self.log_prefix}规划器原始响应: {content}")
logger.debug(f"{self.log_prefix}规划器推理: {reasoning_content}")
logger.debug(f"{self.log_prefix}规划器模型: {model_name}")
logger.info(f"{self.log_prefix}规划器原始提示词: {prompt}")
logger.info(f"{self.log_prefix}规划器原始响应: {content}")
logger.info(f"{self.log_prefix}规划器推理: {reasoning_content}")
logger.info(f"{self.log_prefix}规划器模型: {model_name}")
# 解析JSON响应
try:
@@ -263,7 +263,7 @@ class NormalChatPlanner:
if action_parameters:
param_text = "\n"
print(action_parameters)
# print(action_parameters)
for param_name, param_description in action_parameters.items():
param_text += f' "{param_name}":"{param_description}"\n'
param_text = param_text.rstrip("\n")

View File

@@ -357,7 +357,7 @@ def _build_readable_messages_internal(
limit = 200
replace_content = "......(内容太长了)"
elif percentile < 1.0: # 80% 到 100% 之前的消息 (即较新的 20%)
limit = 300
limit = 400
replace_content = "......(太长了)"
truncated_content = content

View File

@@ -633,7 +633,7 @@ def translate_timestamp_to_human_readable(timestamp: float, mode: str = "normal"
elif diff < 86400 * 2:
return f"{int(diff / 86400)}天前"
else:
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) + ":\n"
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) + ":"
else: # mode = "lite" or unknown
# 只返回时分秒格式,喵~
return time.strftime("%H:%M:%S", time.localtime(timestamp))

View File

@@ -109,6 +109,11 @@ class BasePlugin(ABC):
with open(config_file_path, "r", encoding="utf-8") as f:
self.config = toml.load(f) or {}
logger.debug(f"{self.log_prefix} 配置已从 {config_file_path} 加载")
# 从配置中更新 enable_plugin
if "plugin" in self.config and "enabled" in self.config["plugin"]:
self.enable_plugin = self.config["plugin"]["enabled"]
logger.debug(f"{self.log_prefix} 从配置更新插件启用状态: {self.enable_plugin}")
else:
logger.warning(f"{self.log_prefix} 不支持的配置文件格式: {file_ext},仅支持 .toml")
self.config = {}

View File

@@ -93,6 +93,12 @@ class PluginManager:
self.plugin_paths[plugin_name] = plugin_dir
plugin_instance = plugin_class(plugin_dir=plugin_dir)
# 检查插件是否启用
if not plugin_instance.enable_plugin:
logger.info(f"插件 {plugin_name} 已禁用,跳过加载")
continue
if plugin_instance.register_plugin():
total_registered += 1
self.loaded_plugins[plugin_name] = plugin_instance

View File

@@ -3,13 +3,13 @@
[plugin]
name = "mute_plugin"
version = "2.0.0"
enabled = true
enabled = false
description = "群聊禁言管理插件,提供智能禁言功能"
# 组件启用控制
[components]
enable_smart_mute = true # 启用智能禁言Action
enable_mute_command = false # 启用禁言命令Command
enable_mute_command = true # 启用禁言命令Command
# 禁言配置
[mute]

View File

@@ -163,11 +163,25 @@ class MuteAction(BaseAction):
success = await self.send_command(
command_name="GROUP_BAN",
args={"qq_id": str(user_id), "duration": str(duration_int)},
display_message=f"禁言了 {target} {time_str}",
display_message=f"发送禁言命令",
)
if success:
logger.info(f"{self.log_prefix} 成功发送禁言命令,用户 {target}({user_id}),时长 {duration_int}")
# 存储动作信息
await self.api.store_action_info(
action_build_into_prompt=True,
action_prompt_display=f"尝试禁言了用户 {target},时长 {time_str},原因:{reason}",
action_done=True,
thinking_id=self.thinking_id,
action_data={
"target": target,
"user_id": user_id,
"duration": duration_int,
"duration_str": time_str,
"reason": reason
}
)
return True, f"成功禁言 {target},时长 {time_str}"
else:
error_msg = "发送禁言命令失败"