From e982e7798d3cd79743c65ba4ba864229f298ed8d Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 11 Nov 2025 00:27:29 +0800 Subject: [PATCH] refactor: remove unused echo listener and hello tool; add HelloCommand in test_plugin --- src/handlers/listeners/echo.py | 12 ------- src/handlers/tools/hello.py | 31 ------------------- src/plugin.yaml | 2 +- .../commands/hello.py | 0 4 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 src/handlers/listeners/echo.py delete mode 100644 src/handlers/tools/hello.py rename src/{handlers => test_plugin}/commands/hello.py (100%) diff --git a/src/handlers/listeners/echo.py b/src/handlers/listeners/echo.py deleted file mode 100644 index 261a574b4..000000000 --- a/src/handlers/listeners/echo.py +++ /dev/null @@ -1,12 +0,0 @@ -from astrbot_sdk.api.components. import ListenerComponent -from astrbot.api.v1.event import AstrMessageEvent, filter -from astrbot.api.v1.context import Context - - -class EchoListener(ListenerComponent): - def __init__(self, context: Context): - super().__init__(context) - - @filter.platform_adapter_type(filter.PlatformAdapterType.ALL) - async def on_message(self, event: AstrMessageEvent): - yield event.plain_result("Hello, Astrbot!") diff --git a/src/handlers/tools/hello.py b/src/handlers/tools/hello.py deleted file mode 100644 index 7cf641a5d..000000000 --- a/src/handlers/tools/hello.py +++ /dev/null @@ -1,31 +0,0 @@ -from mcp.types import CallToolResult -from pydantic import Field -from pydantic.dataclasses import dataclass - -from astrbot.api.v1.components.agent.tool import FunctionTool -from astrbot.api.v1.components.agent import ContextWrapper, AstrAgentContext - - -@dataclass -class HelloWorldTool(FunctionTool): - name: str = "hello_world" # 工具名称 - description: str = "Say hello to the world." # 工具描述 - parameters: dict = Field( - default_factory=lambda: { - "type": "object", - "properties": { - "greeting": { - "type": "string", - "description": "The greeting message.", - }, - }, - "required": ["greeting"], - } - ) # 工具参数定义,见 OpenAI 官网或 https://json-schema.org/understanding-json-schema/ - - async def call( - self, context: ContextWrapper[AstrAgentContext], **kwargs - ) -> str | CallToolResult: - # event 在 context.context.event 中可用 - greeting = kwargs.get("greeting", "Hello") - return f"{greeting}, World!" # 也支持 mcp.types.CallToolResult 类型 diff --git a/src/plugin.yaml b/src/plugin.yaml index 64d932c82..a178bdbd8 100644 --- a/src/plugin.yaml +++ b/src/plugin.yaml @@ -5,7 +5,7 @@ desc: 一个简单的问候插件示例 author: Soulter version: 0.1.0 components: # 组件列表,将支持自动生成 - - class: handlers.commands.hello:HelloCommand + - class: test_plugin.commands.hello:HelloCommand type: command name: hello description: 发送问候消息 diff --git a/src/handlers/commands/hello.py b/src/test_plugin/commands/hello.py similarity index 100% rename from src/handlers/commands/hello.py rename to src/test_plugin/commands/hello.py