📝 Update changelog
Some checks failed
Ruff Lint / Ruff Lint (push) Successful in 18s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.11) (push) Failing after 1m39s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.11) (push) Failing after 1m48s
Pyright Lint / Pyright Lint (pydantic-v2) (push) Failing after 1m20s
Site Deploy / publish (push) Failing after 11m5s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.9) (push) Failing after 12m1s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.12) (push) Failing after 12m2s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.10) (push) Failing after 12m5s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.9) (push) Failing after 12m6s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.12) (push) Failing after 12m10s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.10) (push) Failing after 17m50s
Pyright Lint / Pyright Lint (pydantic-v1) (push) Failing after 18m23s
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.9) (push) Has been cancelled

This commit is contained in:
noneflow[bot] 2025-04-16 09:20:51 +00:00
parent a8549140c5
commit d0d9eef7e3
11 changed files with 48 additions and 41 deletions

View File

@ -6,6 +6,7 @@ import TabItem from "@theme/TabItem";
[`nonebot-plugin-alconna`](https://github.com/nonebot/plugin-alconna) 是一类极大地提升了 NoneBot 开发体验的插件。
该插件可分为三个部分:
- 增强的命令解析: 基于 [Alconna](https://github.com/ArcletProject/Alconna), 提供一类新的事件响应器辅助函数 `on_alconna`. 相比 `on_command`, `on_shell`, `on_regex` 等函数,`on_alconna` 提供了更强大的命令解析能力与诸多特性。
- 通用消息组件: 实现了跨平台接收、发送、撤回、编辑、表态消息的功能。
- `UniMessage` 通用消息模型,支持各适配器下的消息转换和导出,发送。
@ -23,7 +24,7 @@ import TabItem from "@theme/TabItem";
以最新版本为例 (v0.57), 本插件已支持 NoneBot 生态中几乎所有的适配器, 包括:
| 协议名称 | 路径 |
|---------------------------------------------------------------------|--------------------------------------|
| ------------------------------------------------------------------- | ------------------------------------ |
| [OneBot 协议](https://onebot.dev/) | adapters.onebot11, adapters.onebot12 |
| [Telegram](https://core.telegram.org/bots/api) | adapters.telegram |
| [飞书](https://open.feishu.cn/document/home/index) | adapters.feishu |
@ -47,7 +48,6 @@ import TabItem from "@theme/TabItem";
| [黑盒语音](https://github.com/lclbm/adapter-heybox) | adapters.heybox |
| [Gewechat](https://github.com/Shine-Light/nonebot-adapter-gewechat) | adapters.gewechat |
## 安装插件
在使用前请先安装 `nonebot-plugin-alconna` 插件至项目环境中,可参考[获取商店插件](../../tutorial/store.mdx#安装插件)来了解并选择安装插件的方式。如:

View File

@ -2,6 +2,7 @@
sidebar_position: 7
description: 内置组件
---
import Messenger from "@site/src/components/Messenger";
# 内置组件
@ -229,6 +230,7 @@ async def handle(content: Match[str]):
```
其构造时可传入两个参数:
- `add_left`: 否在当前消息的左侧合并回复消息,默认为 False
- `sep`: 合并时的分隔符,默认为空格
@ -265,6 +267,7 @@ async def remove(plugin: Match[str], time: Match[int]):
`MarkdownOutputExtension` 可将 Alconna 的自动输出转换为 Markdown 格式
其构造时可传入两个参数:
- `escape_dot`: 是否转义句中的点号(用来避免被识别为 url
- `text_to_image` 将文本转换为图片的函数,可不传入。一般用来设置渲染 markdown 为图片的函数

View File

@ -41,7 +41,7 @@ print(res.all_matched_args)
命令构造时, `Alconna([prefix], command)``Alconna(command, [prefix])` 是等价的。
| 前缀 | 命令名 | 匹配内容 | 说明 |
|:----------------------------:|:----------:|:---------------------------------------------------------:|:--------:|
| :--------------------------: | :--------: | :---------------------------------------------------------: | :--------------: |
| 不传入 | "foo" | `"foo"` | 无前缀的纯文字头 |
| 不传入 | 123 | `123` | 无前缀的元素头 |
| 不传入 | "re:\d{2}" | `"32"` | 无前缀的正则头 |

View File

@ -78,7 +78,6 @@ description: 配置项
是否启动时拉取一次[发送对象](./uniseg/utils.mdx#发送对象)列表。
## alconna_builtin_plugins
- **类型**: `set[str]`
@ -92,6 +91,7 @@ description: 配置项
- **默认值**: `"default"`
命令冲突解决策略,决定当不同插件之间或者同一插件之间存在两个以上相同的命令时的处理方式:
- `default`: 默认处理方式,保留两个命令
- `raise`: 抛出异常
- `ignore`: 忽略较新的命令

View File

@ -61,7 +61,6 @@ async def _(name: str, target: Match[tuple[At, ...]]):
]}
/>
## 声明
`on_alconna` 的参数如下:
@ -148,6 +147,7 @@ async def handle(
```
`AlconnaMatcher` 的依赖注入拓展支持以下情况:
- `xxx: CommandResult`
- `xxx: Arparma`:命令的[解析结果](./command.md#解析结果)
- `xxx: Duplication`:命令的解析结果的 [`Duplication`](./command.md#Duplication)
@ -260,7 +260,6 @@ async def handle_list(): ...
async def handle_add_admin(): ...
```
### `dispatch` 方法
此外,使用 `.dispatch` 还能像 `CommandGroup` 一样为每个分发设置独立的 matcher
@ -297,7 +296,6 @@ async def handle_add_admin(target: Query[tuple[At, ...]] = Query("~target")):
:::
### `got_path` 方法
另外,`AlconnaMatcher` 有类似于 [`got`](../../appendices/session-control.mdx#got) 的 `got_path` 与配套的 `get_path_arg`, `set_path_arg`
@ -324,7 +322,6 @@ async def tt(target: Union[str, At]):
`got_path` 中可以使用依赖注入函数 `AlconnaArg`, 类似于 [`Arg`](../../advanced/dependency.mdx#arg).
### `prompt` 方法
基于 [`Waiter`](https://github.com/RF-Tar-Railt/nonebot-plugin-waiter) 插件,`AlconnaMatcher` 提供了 `prompt` 方法来实现更灵活的交互式提示。
@ -426,6 +423,7 @@ def test(
prefix: bool = True
): ...
```
- `message`: 测试的消息
- `expected`: 预期的解析结果,若为 None 则表示只测试是否匹配
- `prefix`: 是否使用命令前缀,默认为 True

View File

@ -76,6 +76,7 @@ book = (
### 参数类型
`Command` 的参数类型也如 `koishi` 一样,**必选参数** 用尖括号包裹,**可选参数** 用方括号包裹:
- `foo` 表示参数 `foo`, 类型为 Any
- `foo:int` 表示参数 `foo`, 类型为 int
- `foo:int=1` 表示参数 `foo`, 类型为 int, 默认值为 1
@ -84,6 +85,7 @@ book = (
- `foo:+str`, `foo:text` 表示参数 `foo`, 类型为 str, 并且将包含空格 (即将变长参数的结果用空格合并)
特别的,针对类型部分,本插件拓展了如下内容:
- `foo:At`, `foo:Image`, ... 表示类型为[通用消息段](./uniseg/segment.md)
- `foo:select(Image).first` 表示获取子元素类型
- `foo:Dot(Image, 'url')` 表示类型为 `Image`,并且只获取 `url` 属性
@ -107,8 +109,7 @@ shortcuts:
- key: 测试
args: ["--anonymous"]
actions:
-
params: ["options"]
- params: ["options"]
code: |
return str(options)
```

View File

@ -101,6 +101,7 @@ async def send(
) -> Receipt:
...
```
- `target`: 发送目标,支持事件和[发送对象](./utils.mdx#发送对象),不传入时会尝试从响应器上下文中获取。
- `bot`: 发送消息使用的 Bot 对象,若不传入则会尝试从响应器上下文中获取。
- `fallback`: [回退策略](#回退策略)。
@ -134,6 +135,7 @@ async def tt(target: At):
### 回退策略
`send` 方法的 `fallback` 参数用于指定回退策略(即当前适配器不支持的消息段如何处理):
- `FallbackStrategy.ignore`: 忽略未转换的消息段
- `FallbackStrategy.to_text`: 将未转换的消息段转为文本元素
- `FallbackStrategy.rollback`: 从未转换消息段的子元素中提取可能的可发送消息段
@ -178,6 +180,7 @@ async def handle():
```
`Receipt` 对象拥有以下方法:
- `recallable`: 表明是否可以撤回
- `recall`: 撤回消息
- `editable`: 表明是否可以修改
@ -188,7 +191,6 @@ async def handle():
- `send`, `finish`: 发送消息
- `reply`: 回复已经发送的消息
## 构造
如同 `Message`, `UniMessage` 可以传入单个字符串/消息段,或可迭代的字符串/消息段:
@ -268,7 +270,6 @@ async def tt():
:::
### 拼接消息
`str`、`UniMessage`、`Segment` 对象之间可以直接相加,相加均会返回一个新的 `UniMessage` 对象:
@ -447,15 +448,15 @@ message.transform(rule)
转换规则的类型一般为 `dict[str, Transformer]`,以消息元素类型的名称为键,定义方式如下:
```typescript
type Fragment = Segment | Segment[]
type Render<T> = (attrs: dict, children: Segment[]) => T
type Transformer = boolean | Fragment | Render<boolean | Fragment>
type Fragment = Segment | Segment[];
type Render<T> = (attrs: dict, children: Segment[]) => T;
type Transformer = boolean | Fragment | Render<boolean | Fragment>;
```
### 字符串操作
类似于 `str`,消息序列可以通过如下方法来操作消息内的文本部分:
- `split`,
- `replace`,
- `startwith`, `endswith`,
@ -499,6 +500,7 @@ def dump(self, media_save_dir: str | Path | bool | None = None, json: bool = Fal
```
其中,`media_save_dir` 用于指定持久化的媒体文件存储目录:
- 若 `media_save_dir` 为 str 或 Path则会将媒体文件保存到指定目录下。
- 若 `media_save_dir` 为 False则不会保存媒体文件。
- 若 `media_save_dir` 为 True则会将文件数据转为 base64 编码。

View File

@ -16,7 +16,6 @@ import TabItem from "@theme/TabItem";
:::
## 消息事件 ID
消息事件 ID 是用来标识当前消息事件的唯一 ID通常用于回复/撤回/编辑/表态当前消息。
@ -175,7 +174,6 @@ async def _():
若配置了 [`alconna_apply_fetch_targets`](../config.md#alconna_apply_fetch_targets) 选项,则在启动时会主动拉取一次发送对象列表。即对于
某一主动构造的 `Target` 对象,插件将其与拉取下来的众多发送对象进行匹配,并选择第一个符合条件的发送对象,以选择对应的 Bot 对象。
## 撤回消息
通过 `message_recall` 方法来撤回消息事件。
@ -271,6 +269,7 @@ async def message_reaction(
## 响应规则
`uniseg` 模块提供了两个响应规则:
- `at_in`: 是否在消息中 @ 了指定的用户
- `at_me`: 是否在消息中 @ 了机器人

View File

@ -187,16 +187,19 @@ async def handle_onebot_reply(bot: OnebotBot, state: T_State, location: str = Ar
这些插件可以分为三类:
### 事件处理
- [all4one](https://github.com/nonepkg/nonebot-plugin-all4one): 将不同平台的事件转为符合 OneBot V12 协议的插件
- 支持的适配器: OneBot V11/V12, Discord, QQ, Telegram
### 消息处理
- [alconna](https://github.com/nonebot/plugin-alconna): 对几乎所有适配器中消息的收发、撤回、编辑、表态的统一插件
- 支持的适配器: OneBot V11/V12, Telegram, Feishu, Github, QQ, Ding, Console, Kaiheila, Mirai, NtChat, Minecraft, Discord, Satori, Red, Dodo, Kritor, Tailchat, Mail, WXMP, Heybox, Gewechat
- [send-anything-anywhere](https://github.com/felinae98/nonebot-plugin-send-anything-anywhere): 帮助处理不同适配器消息的适配和发送的插件
- 支持的适配器: OneBot V11/V12, Kaiheila, Telegram, Feishu, Red, DoDo, Satori, QQ, Discord
### 会话信息提取
- [uninfo](https://github.com/RF-Tar-Railt/nonebot-plugin-uninfo): 多平台的会话信息(用户、群组、频道)获取插件
- 支持的适配器: OneBot V11/V12, Telegram, Feishu, QQ, Console, Kaiheila, Mirai, Minecraft, Discord, Satori, Dodo, Kritor, Mail, WXMP, Gewechat
- [session](https://github.com/noneplugin/nonebot-plugin-session): 会话信息提取与会话 id 定义插件

View File

@ -9,6 +9,7 @@ toc_max_heading_level: 2
### 📝 文档
- Docs: 更新最佳实践 `Alconna` 章节 [@RF-Tar-Railt](https://github.com/RF-Tar-Railt) ([#3447](https://github.com/nonebot/nonebot2/pull/3447))
- Docs: 修复移动端侧边栏折叠状态异常 [@StarHeartHunt](https://github.com/StarHeartHunt) ([#3414](https://github.com/nonebot/nonebot2/pull/3414))
- Docs: 添加 Gewechat 适配器描述 [@Shine-Light](https://github.com/Shine-Light) ([#3372](https://github.com/nonebot/nonebot2/pull/3372))