Skip to content

Commit a736f07

Browse files
committed
docs: improve clarity
1 parent a7f7bc3 commit a736f07

2 files changed

Lines changed: 11 additions & 26 deletions

File tree

‎saltify-core/src/jvmTest/kotlin/org/ntqqrev/saltify/PluginTest.kt‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ class PluginTest {
9090
val content = greedyStringParameter("content", "words to repeat")
9191

9292
onExecute {
93-
val text = content.value
9493
respond {
95-
text(text)
94+
text(content.value)
9695
}
9796
}
9897

‎saltify-docs/content/quick-tour.md‎

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,13 @@ val client = SaltifyApplication {
6363
autoReconnect = true // 是否自动重连
6464
}
6565
}
66-
67-
// ...
68-
69-
// 释放 client
70-
client.close()
7166
```
7267

68+
下文所指的所有 `client` 均指本例中定义的 `SaltifyApplication` 实例。
69+
7370
## 调用 API
7471

75-
`SaltifyApplication` 暴露了许多 API 来与协议端进行交互,例如获取登录信息、发送消息等:
72+
Saltify 暴露了许多 API 来与协议端进行交互,例如获取登录信息、发送消息等:
7673

7774
```kotlin
7875
val loginInfo = client.getLoginInfo()
@@ -116,41 +113,30 @@ job.cancel()
116113
client.disconnectEvent()
117114
```
118115

119-
`client.disconnectEvent()` 不会被 `client.close()` 自动调用,事件服务可复用。
120-
121116
## 定义插件
122117

123-
可以通过 `createSaltifyPlugin` 定义一个插件。在其中同样可以使用 `on` 监听事件,也可以使用 `onStart` 和 `onStop` 定义插件的启动和停止逻辑,还可以使用 `command` 定义命令:
118+
插件是一系列功能的集合,可以通过 `createSaltifyPlugin` 定义一个插件。在其中同样可以使用 `on` 监听事件,也可以使用 `onStart` 和 `onStop` 定义插件的启动和停止逻辑,还可以使用 `command` 定义命令:
124119

125120
```kotlin
126121
val myPlugin = createSaltifyPlugin("test") {
127122
onStart {
128-
// ...
123+
println("Plugin initialized!")
129124
}
130125

131126
on<Event.GroupMemberIncrease> {
132127
// ...
133128
}
134129

135-
// /order <id> <note>
136-
command("order") {
137-
// id.value 的类型为 Int
138-
val id = parameter<Int>("id")
139-
// 贪婪匹配,即后面的参数视为一个参数
140-
val note = greedyStringParameter("note")
130+
// /say <content>
131+
command("say") {
132+
val content = greedyStringParameter("content", "words to repeat")
141133

142134
onExecute {
143135
respond {
144-
text("Order #${id.value} created\nnote:${note.value}")
136+
text(content.value)
145137
}
146138
}
147139

148-
// 优先级高于 onExecute,同样还有 onPrivateExecute
149-
onGroupExecute {
150-
// ...
151-
}
152-
153-
// 使用 Typed error 处理命令参数类型不匹配,命令参数缺失等情况
154140
onFailure {
155141
respond {
156142
text("Command run failed: $it")
@@ -160,7 +146,7 @@ val myPlugin = createSaltifyPlugin("test") {
160146
}
161147
```
162148

163-
可以在 SaltifyApplication 的初始化块内声明使用之前定义的插件,也可以直接定义一个匿名插件:
149+
可以在 SaltifyApplication 的初始化块内声明使用之前定义的插件,也可以直接在初始化块内直接定义插件:
164150

165151
```kotlin
166152
val client = SaltifyApplication {

0 commit comments

Comments
 (0)