doc: 添加组件扩展文档

This commit is contained in:
RockChinQ
2024-03-21 16:21:55 +08:00
parent 05f364a4d2
commit 6fbbc37a2d
3 changed files with 40 additions and 1 deletions
+5
View File
@@ -187,6 +187,11 @@ export default sidebar({
icon: "code",
link: "develop",
},
{
text: "组件扩展",
icon: "code",
link: "extension",
},
],
},
{
+1 -1
View File
@@ -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`输入以下内容:
+34
View File
@@ -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/`