diff --git a/README.md b/README.md index ceef771..356effc 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ _✨ 支持多API预设、MCP协议、联网搜索、视觉模型的AI群聊插 | LLMCHAT__RANDOM_TRIGGER_PROB | 否 | 0.05 | 默认随机触发概率 [0, 1] | | LLMCHAT__DEFAULT_PROMPT | 否 | 你的回答应该尽量简洁、幽默、可以使用一些语气词、颜文字。你应该拒绝回答任何政治相关的问题。 | 默认提示词 | | LLMCHAT__BLACKLIST_USER_IDS | 否 | [] | 黑名单用户ID列表,机器人将不会处理黑名单用户的消息 | +| LLMCHAT__IGNORE_PREFIXES | 否 | [] | 需要忽略的消息前缀列表,匹配到这些前缀的消息不会处理 | | LLMCHAT__MCP_SERVERS | 否 | {} | MCP服务器配置,具体见下表 | 其中LLMCHAT__API_PRESETS为一个列表,每项配置有以下的配置项 diff --git a/nonebot_plugin_llmchat/__init__.py b/nonebot_plugin_llmchat/__init__.py index 0d0feae..d3c6605 100755 --- a/nonebot_plugin_llmchat/__init__.py +++ b/nonebot_plugin_llmchat/__init__.py @@ -169,6 +169,12 @@ async def is_triggered(event: GroupMessageEvent) -> bool: if event.user_id in plugin_config.blacklist_user_ids: return False + # 忽略特定前缀的消息 + msg_text = event.get_plaintext().strip() + for prefix in plugin_config.ignore_prefixes: + if msg_text.startswith(prefix): + return False + state.past_events.append(event) # 原有@触发条件 diff --git a/nonebot_plugin_llmchat/config.py b/nonebot_plugin_llmchat/config.py index fa873d5..d658875 100755 --- a/nonebot_plugin_llmchat/config.py +++ b/nonebot_plugin_llmchat/config.py @@ -44,6 +44,10 @@ class ScopedConfig(BaseModel): ) mcp_servers: dict[str, MCPServerConfig] = Field({}, description="MCP服务器配置") blacklist_user_ids: set[int] = Field(set(), description="黑名单用户ID列表") + ignore_prefixes: list[str] = Field( + default_factory=list, + description="需要忽略的消息前缀列表,匹配到这些前缀的消息不会处理" + ) class Config(BaseModel): diff --git a/nonebot_plugin_llmchat/mcpclient.py b/nonebot_plugin_llmchat/mcpclient.py index a6c6ff3..55e1b44 100644 --- a/nonebot_plugin_llmchat/mcpclient.py +++ b/nonebot_plugin_llmchat/mcpclient.py @@ -66,7 +66,7 @@ class MCPClient: logger.info(f"正在服务器[{server_name}]上调用工具[{real_tool_name}]") session = self.sessions[server_name] try: - response = await asyncio.wait_for(session.call_tool(real_tool_name, tool_args), timeout=10) + response = await asyncio.wait_for(session.call_tool(real_tool_name, tool_args), timeout=30) except asyncio.TimeoutError: logger.error(f"调用工具[{real_tool_name}]超时") return f"调用工具[{real_tool_name}]超时" diff --git a/pyproject.toml b/pyproject.toml index 61e73fa..7c17df2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-llmchat" -version = "0.2.4" +version = "0.2.5" description = "Nonebot AI group chat plugin supporting multiple API preset configurations" license = "GPL" authors = ["FuQuan i@fuquan.moe"]