From 6fbbc37a2da58369cb63d690de68c559b33efeb5 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Thu, 21 Mar 2024 16:21:55 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E6=B7=BB=E5=8A=A0=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/.vuepress/sidebar.ts | 5 +++++ src/posts/plugin/develop.md | 2 +- src/posts/plugin/extension.md | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/posts/plugin/extension.md diff --git a/src/.vuepress/sidebar.ts b/src/.vuepress/sidebar.ts index e6c4551b0..c9fb38586 100644 --- a/src/.vuepress/sidebar.ts +++ b/src/.vuepress/sidebar.ts @@ -187,6 +187,11 @@ export default sidebar({ icon: "code", link: "develop", }, + { + text: "组件扩展", + icon: "code", + link: "extension", + }, ], }, { diff --git a/src/posts/plugin/develop.md b/src/posts/plugin/develop.md index a47412f5b..60ae2ef26 100644 --- a/src/posts/plugin/develop.md +++ b/src/posts/plugin/develop.md @@ -35,7 +35,7 @@ QChatGPT 还支持组件扩展,可以不局限于监听预定事件,做到 按照文档部署此项目,并使其正常运行。 在`plugins`目录下新建目录`hello`,在其中新建空文件`__init__.py`以标记此目录为软件包,继续新建文件`main.py`。 -> 建议使用[hello_plugin](https://github.com/RockChinQ/hello_plugin)作为模板直接生成插件代码仓库后按照下方步骤进行修改。 +> 建议使用[HelloPlugin](https://github.com/RockChinQ/HelloPlugin)作为模板直接生成插件代码仓库后按照下方步骤进行修改。 编辑`main.py`输入以下内容: diff --git a/src/posts/plugin/extension.md b/src/posts/plugin/extension.md new file mode 100644 index 000000000..7d2769eb8 --- /dev/null +++ b/src/posts/plugin/extension.md @@ -0,0 +1,34 @@ +--- +head: + - - meta + - name: keywords + content: QChatGPT 组件扩展教程 +title: 组件扩展 +icon: code +order: 4 +author: RockChinQ +date: 2024-03-21 +category: + - 插件介绍 +index: false +--- + +> 请先阅读[插件介绍页](../plugin/intro.md) + +:::info 目录 +[[toc]] +::: + +普通的以 `BasePlugin` 子类包装的插件只能监听预定事件,而组件扩展则可以替换整个组件,实现更强大的功能扩展。 + +- 组件扩展不需要包装在 `BasePlugin` 子类中 +- 扩展的组件不受插件开关控制 +- 扩展的组件通常由配置文件中的选项选用 + +## 可扩展的组件 + +### 命令 + +- 基类:`pkg.command.operator.CommandOperator` +- 装饰器:`pkg.command.operator.operator_class(name: str, help: str="", usage: str=None, alias: list[str]=[], privilege: int=1, parent_class: typing.Type[CommandOperator] = None)` +- 参考类:`pkg.command.operators/` \ No newline at end of file