delete: remove hello_plugin example and its related files

This commit is contained in:
whatevertogo
2026-03-17 21:21:03 +08:00
parent 6d00add2ed
commit b0e4d038ef
7 changed files with 0 additions and 147 deletions

View File

@@ -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

View File

@@ -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}")

View File

@@ -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

View File

@@ -1 +0,0 @@

View File

@@ -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))

View File

@@ -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)

View File

@@ -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)