From 949e67ec1a53f1454a0356107e33945629c8ce98 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 22 Mar 2024 17:09:15 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86api?= =?UTF-8?q?=E5=8F=82=E8=80=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/.vuepress/sidebar.ts | 5 +++++ src/posts/plugin/apiref.md | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/posts/plugin/apiref.md diff --git a/src/.vuepress/sidebar.ts b/src/.vuepress/sidebar.ts index c9fb38586..fb129b931 100644 --- a/src/.vuepress/sidebar.ts +++ b/src/.vuepress/sidebar.ts @@ -192,6 +192,11 @@ export default sidebar({ icon: "code", link: "extension", }, + { + text: "API 参考", + icon: "api", + link: "apiref", + }, ], }, { diff --git a/src/posts/plugin/apiref.md b/src/posts/plugin/apiref.md new file mode 100644 index 000000000..05907bae8 --- /dev/null +++ b/src/posts/plugin/apiref.md @@ -0,0 +1,45 @@ +--- +head: + - - meta + - name: keywords + content: QChatGPT API 参考 +title: API 参考 +icon: code +order: 5 +author: RockChinQ +date: 2024-03-22 +category: + - 插件介绍 +index: false +--- + +暂时未设计独立 API 层,本页面讲解了一些常用的功能的调用方法。 +以下提到的对象及访问方式均在前文有所提及,请先阅读插件开发教程。 + +## 消息处理 + +### 回复消息 + +切入方法:`pkg.platform.adapter.MessageSourceAdapter.reply_message` + +由于程序中可能同时运行多个 消息平台适配器(MessageSourceAdapter),故在`query: pkg.core.entities.Query` 对象中包含了 `adapter` 对象,保存了此次请求对应的适配器,通过这个对象可以调用适配器的回复消息方法。 + +需要传入: +- `message_source`本次消息的来源事件,可以从`query`对象中获取。 +- `message`回复的消息内容,YiriMirai 的 MessageChain对象 +- `quote_origin: bool`是否引用原消息 + +### 发送主动消息 + +不推荐。 + +切入方法:`pkg.platform.adapter.MessageSourceAdapter.send_message` + +需要自己找到一个适配器对象,然后调用此方法。 +`ap: pkg.core.app.Application`的`platform_mgr: pkg.platform.manager.PlatformManager`对象中保存了所有适配器对象:`adapters`,从中取出一个即可调用`send_message`方法。 + +需要传入: + +- `target_type`目标类型,可以是`group`或`person` +- `target_id`目标id +- `message`消息内容,YiriMirai 的 MessageChain对象