Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed Jul 27, 2024
1 parent 501d40f commit 03aaf60
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions docs/开发/插件开发.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

:::

# 如何开发
## 如何开发

- clone AstrBot 项目本体到本地。
- 打开 [helloworld](https://github.com/Soulter/helloworld),这个是一个插件模板,接下来在这个模板上二次开发。
Expand All @@ -24,13 +24,13 @@
repo: https://github.com/Soulter/helloworld # 插件的仓库地址
```
# 开发后的插件如何使用?
## 开发后的插件如何使用?
- 开发完毕后,将插件推送至 GitHub。
- 上传好后使用指令 `plugin i 仓库地址` 进行导入。如 `plugin i https://github.com/Soulter/helloworld`
- 开发好的插件可以通过 issue 提交至此项目,我们会将其放至相应位置供用户安装。


# 最小实例
## 最小实例

```py
from util.plugin_dev.api.v1.bot import Context, AstrMessageEvent, CommandResult
Expand Down Expand Up @@ -58,7 +58,7 @@ class Main:
return CommandResult().message("Hello, World!")
```

# 注册指令
## 注册指令

用户可以通过输入指令来调用插件的功能。

Expand Down Expand Up @@ -87,7 +87,7 @@ def helloworld(self, message: AstrMessageEvent, context: Context):
```

# 指令返回值 CommandResult
## 指令返回值 CommandResult

CommandResult 是插件指令处理函数的返回值。

Expand All @@ -110,7 +110,7 @@ cmd_result = CommandResult(
)
```

# 主动发送消息
## 主动发送消息

插件可以主动给受支持的平台发送消息。(>=v3.3.3)

Expand All @@ -136,14 +136,14 @@ platforms = context.platforms

然后通过平台实例 `platform_instance` 的 send_msg 方法发送消息。send_msg 方法接收两个参数:`target` 和 `message`。`target` 为目标,`message` 为 `CommandResult` 对象。

## aiocqhttp
### aiocqhttp

`target` 接收一个 dict 类型的值引用。

- 要发给 QQ 下的某个用户,请添加 key `user_id`,值为 int 类型的 qq 号;
- 要发给某个群聊,请添加 key `group_id`,值为 int 类型的 qq 群号;

## nakuru
### nakuru

`target` 接收一个 dict 类型的值引用。

Expand All @@ -154,7 +154,7 @@ platforms = context.platforms
guild_id 不是频道号。


## qqchan
### qqchan

`target` 接收一个 dict 类型的值引用。

Expand Down Expand Up @@ -223,19 +223,19 @@ class HelloWorldPlugin:
```
上面的例子使用了异步的方式来实现定时任务。当然可以使用 threading.Thread 来实现,不过不推荐。

# Context
## Context

插件处理函数的参数之一。

它是一个上下文对象,包含了 AstrBot 实例中的一些共享数据。

在插件类的 `__init__` 方法中,你可以通过 `context` 参数获取到这个对象。

## 注册异步任务
### 注册异步任务

如果你需要接入一个其他的平台,或者需要定时任务等,除了直接使用 threading.Thread 之外,你还可以使用 context.register_task 注册一个任务。

# AstrMessageEvent
## AstrMessageEvent

插件处理函数的参数之一。

Expand All @@ -248,7 +248,7 @@ class HelloWorldPlugin:
- role: str 基本身份。`admin` 或 `member`
- session_id: int 会话 id

## AstrBotMessage
### AstrBotMessage

这是机器人内部的消息对象(v3.1.10 后),会对每个平台原本的消息类进行转译。原平台的消息类在 `raw_message` 中。

Expand Down

0 comments on commit 03aaf60

Please sign in to comment.