From b0e4d038ef413a0b624ed7a8cf36a5cbfdea5f7b Mon Sep 17 00:00:00 2001 From: whatevertogo Date: Tue, 17 Mar 2026 21:21:03 +0800 Subject: [PATCH] delete: remove hello_plugin example and its related files --- examples/hello_plugin/README.md | 47 ------------------ examples/hello_plugin/main.py | 13 ----- examples/hello_plugin/plugin.yaml | 9 ---- examples/hello_plugin/requirements.txt | 1 - examples/hello_plugin/tests/conftest.py | 10 ---- examples/hello_plugin/tests/test_dispatch.py | 15 ------ examples/hello_plugin/tests/test_plugin.py | 52 -------------------- 7 files changed, 147 deletions(-) delete mode 100644 examples/hello_plugin/README.md delete mode 100644 examples/hello_plugin/main.py delete mode 100644 examples/hello_plugin/plugin.yaml delete mode 100644 examples/hello_plugin/requirements.txt delete mode 100644 examples/hello_plugin/tests/conftest.py delete mode 100644 examples/hello_plugin/tests/test_dispatch.py delete mode 100644 examples/hello_plugin/tests/test_plugin.py diff --git a/examples/hello_plugin/README.md b/examples/hello_plugin/README.md deleted file mode 100644 index bb95f4cc2..000000000 --- a/examples/hello_plugin/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Hello Plugin - -这是给 AstrBot SDK 插件作者准备的最小示例。 - -## 目录结构 - -```text -hello_plugin/ -├── plugin.yaml -├── requirements.txt -├── main.py -└── tests - └── test_plugin.py -``` - -## 能学到什么 - -- 如何定义一个 `Star` 插件 -- 如何注册命令 handler -- 如何使用 `MessageEvent.reply()` -- 如何用 `PluginHarness.from_plugin_dir()` 走真实 dispatch 链 -- 如何从 `Context` 里读取当前插件元数据 -- 如何用 `MockContext` / `MockMessageEvent` 写插件测试 - -## 运行 - -在仓库根目录执行: - -```bash -cd examples/hello_plugin -astrbot-sdk validate -astrbot-sdk dev --local --event-text hello -astrbot-sdk dev --local --watch --event-text hello -``` - -## 测试 - -```bash -python -m pytest examples/hello_plugin/tests/test_plugin.py -v -``` - -## 代码说明 - -- `hello`: 最小命令,收到 `hello` 时回复 `Hello, World!` -- `about`: 读取 `ctx.metadata.get_current_plugin()`,演示 capability 客户端的基础用法 -- `tests/test_plugin.py`: 展示 direct handler test -- `tests/test_dispatch.py`: 展示 `PluginHarness.from_plugin_dir()` dispatch test diff --git a/examples/hello_plugin/main.py b/examples/hello_plugin/main.py deleted file mode 100644 index 08e673416..000000000 --- a/examples/hello_plugin/main.py +++ /dev/null @@ -1,13 +0,0 @@ -from astrbot_sdk import Context, MessageEvent, Star, on_command - - -class HelloPlugin(Star): - @on_command("hello", description="发送最小问候") - async def hello(self, event: MessageEvent, ctx: Context) -> None: - await event.reply("Hello, World!") - - @on_command("about", description="返回当前插件信息") - async def about(self, event: MessageEvent, ctx: Context) -> None: - plugin = await ctx.metadata.get_current_plugin() - display_name = plugin.display_name if plugin is not None else ctx.plugin_id - await event.reply(f"我是 {display_name}") diff --git a/examples/hello_plugin/plugin.yaml b/examples/hello_plugin/plugin.yaml deleted file mode 100644 index 558e12cfb..000000000 --- a/examples/hello_plugin/plugin.yaml +++ /dev/null @@ -1,9 +0,0 @@ -name: hello_plugin -display_name: Hello Plugin -desc: 一个适合插件作者入门的最小示例插件 -author: your-name -version: 0.1.0 -runtime: - python: "3.12" -components: - - class: main:HelloPlugin diff --git a/examples/hello_plugin/requirements.txt b/examples/hello_plugin/requirements.txt deleted file mode 100644 index 8b1378917..000000000 --- a/examples/hello_plugin/requirements.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/examples/hello_plugin/tests/conftest.py b/examples/hello_plugin/tests/conftest.py deleted file mode 100644 index b43c33dcd..000000000 --- a/examples/hello_plugin/tests/conftest.py +++ /dev/null @@ -1,10 +0,0 @@ -from __future__ import annotations - -import sys -from pathlib import Path - -REPO_ROOT = Path(__file__).resolve().parents[3] -SRC_NEW = REPO_ROOT / "src-new" - -if str(SRC_NEW) not in sys.path: - sys.path.insert(0, str(SRC_NEW)) diff --git a/examples/hello_plugin/tests/test_dispatch.py b/examples/hello_plugin/tests/test_dispatch.py deleted file mode 100644 index 0d18b05d4..000000000 --- a/examples/hello_plugin/tests/test_dispatch.py +++ /dev/null @@ -1,15 +0,0 @@ -from pathlib import Path - -import pytest - -from astrbot_sdk.testing import PluginHarness - - -@pytest.mark.asyncio -async def test_dispatch_hello_command() -> None: - plugin_dir = Path(__file__).resolve().parents[1] - - async with PluginHarness.from_plugin_dir(plugin_dir) as harness: - records = await harness.dispatch_text("hello") - - assert any(record.text == "Hello, World!" for record in records) diff --git a/examples/hello_plugin/tests/test_plugin.py b/examples/hello_plugin/tests/test_plugin.py deleted file mode 100644 index 7b03305bb..000000000 --- a/examples/hello_plugin/tests/test_plugin.py +++ /dev/null @@ -1,52 +0,0 @@ -import importlib.util -from pathlib import Path - -import pytest - -from astrbot_sdk.testing import MockContext, MockMessageEvent - -PLUGIN_DIR = Path(__file__).resolve().parents[1] - - -def _load_plugin_class(): - module_path = PLUGIN_DIR / "main.py" - spec = importlib.util.spec_from_file_location( - "examples_hello_plugin_main", - module_path, - ) - assert spec is not None and spec.loader is not None - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - return module.HelloPlugin - - -HelloPlugin = _load_plugin_class() - - -@pytest.mark.asyncio -async def test_hello_handler() -> None: - plugin = HelloPlugin() - ctx = MockContext( - plugin_id="hello_plugin", - plugin_metadata={"display_name": "Hello Plugin"}, - ) - event = MockMessageEvent(text="/hello", context=ctx) - - await plugin.hello(event, ctx) - - assert event.replies == ["Hello, World!"] - ctx.platform.assert_sent("Hello, World!") - - -@pytest.mark.asyncio -async def test_about_handler() -> None: - plugin = HelloPlugin() - ctx = MockContext( - plugin_id="hello_plugin", - plugin_metadata={"display_name": "Hello Plugin"}, - ) - event = MockMessageEvent(text="/about", context=ctx) - - await plugin.about(event, ctx) - - assert any("Hello Plugin" in reply for reply in event.replies)