Skip to content

Commit cc69788

Browse files
committed
update README.md and website
1 parent c6a2e3b commit cc69788

File tree

4 files changed

+733
-274
lines changed

4 files changed

+733
-274
lines changed

README.md

Lines changed: 40 additions & 269 deletions
Original file line numberDiff line numberDiff line change
@@ -58,284 +58,55 @@ Simple Robot OneBot 组件是一个将
5858

5959
## 快速开始
6060

61-
> [!warning]
62-
> 手册施工完成之前,此处临时提供快速开始。手册施工完成后会删除
61+
前往 [OneBot组件手册](https://simple-robot.github.io/simbot-component-onebot/)
62+
参考其中的[开始使用](https://simple-robot.github.io/simbot-component-onebot/onebot11-quick-start.html)
6363

64-
> [!note]
65-
> 核心库的版本可前往
66-
> [此处](https://github.com/simple-robot/simpler-robot/releases)
67-
> 参考。
6864

69-
### Ktor 客户端引擎
70-
71-
首先,OneBot组件使用 [Ktor](https://ktor.io/)
72-
作为HTTP客户端与WS客户端,但是默认情况下依赖中不会有任何具体的引擎实现。
73-
74-
因此你需要根据你的使用平台前往 [Ktor client Engines](https://ktor.io/docs/client-engines.html#limitations)
75-
选择一个合适的引擎使用。
76-
77-
> [!tip]
78-
> 注意,你需要选择一个支持HTTP和WebSocket的引擎。
79-
> 除非你打算通过更详细的配置为两个场景分配不同的引擎实现。
80-
81-
以 Java11+ 的情况为例,我们选择使用 `Java` 引擎:
82-
83-
Gradle:
84-
85-
```kotlin
86-
runtimeOnly("io.ktor:ktor-client-java:$KTOR_VERSION")
87-
```
88-
89-
Maven:
90-
91-
```xml
92-
<dependency>
93-
<groupId>io.ktor</groupId>
94-
<artifactId>ktor-client-java-jvm</artifactId>
95-
<version>${KTOR_VERSION}</version>
96-
<scope>runtime</scope>
97-
</dependency>
98-
```
99-
100-
### 普通核心库
101-
102-
Gradle:
103-
104-
```kotlin
105-
// 指定核心库依赖
106-
implementation("love.forte.simbot:simbot-core:$SIMBOT_VERSION")
107-
// 引入OneBot组件库
108-
implementation("love.forte.simbot.component:simbot-component-onebot-v11-core:$VERSION")
109-
```
110-
111-
Maven:
112-
113-
```xml
114-
<dependencies>
115-
<!-- 指定核心库依赖 -->
116-
<dependency>
117-
<groupId>love.forte.simbot</groupId>
118-
<artifactId>simbot-core-jvm</artifactId>
119-
<version>${SIMBOT_VERSION}</version>
120-
</dependency>
121-
<dependency>
122-
<groupId>love.forte.simbot.component</groupId>
123-
<artifactId>simbot-component-onebot-v11-core-jvm</artifactId>
124-
<version>${VERSION}</version>
125-
</dependency>
126-
</dependencies>
127-
```
128-
129-
```kotlin
130-
suspend fun main() {
131-
val app = launchSimpleApplication {
132-
// 使用OneBot11协议组件
133-
useOneBot11()
134-
}
135-
136-
// 注册、监听事件
137-
app.listeners {
138-
// 例如:监听OneBot的普通群消息
139-
process<OneBotNormalGroupMessageEvent> { event ->
140-
println("event: $event")
141-
if (event.messageContent.plainText?.trim() == "你好") {
142-
event.reply("你也好")
143-
}
144-
}
145-
}
146-
147-
// 注册Bot
148-
// 先得到OneBot的BotManager
149-
app.oneBot11Bots {
150-
val bot = register(OneBotBotConfiguration().apply {
151-
botUniqueId = "123456"
152-
apiServerHost = Url("http://localhost:3000")
153-
eventServerHost = Url("ws://localhost:3001")
154-
})
155-
156-
// 启动bot
157-
bot.start()
158-
}
159-
160-
// 挂起直到被终止
161-
app.join()
162-
}
163-
```
164-
165-
### 配合 Spring Boot
166-
167-
Gradle:
168-
169-
```kotlin
170-
// 你的其他SpringBoot依赖..
171-
172-
// 指定核心库依赖
173-
implementation("love.forte.simbot:simbot-core-spring-boot-starter:$SIMBOT_VERSION")
174-
// 引入OneBot组件库
175-
implementation("love.forte.simbot.component:simbot-component-onebot-v11-core:$VERSION")
176-
```
177-
178-
Maven:
179-
180-
```xml
181-
<dependencies>
182-
<!-- 你的其他SpringBoot依赖.. -->
183-
184-
185-
<!-- 指定核心库依赖 -->
186-
<dependency>
187-
<groupId>love.forte.simbot</groupId>
188-
<artifactId>simbot-core-spring-boot-starter</artifactId>
189-
<version>${SIMBOT_VERSION}</version>
190-
</dependency>
191-
<dependency>
192-
<groupId>love.forte.simbot.component</groupId>
193-
<artifactId>simbot-component-onebot-v11-core-jvm</artifactId>
194-
<version>${VERSION}</version>
195-
</dependency>
196-
</dependencies>
197-
```
198-
199-
200-
Kotlin:
201-
202-
```Kotlin
203-
@SpringBootApplication
204-
@EnableSimbot
205-
class MyApp
206-
207-
fun main(vararg args: String) {
208-
runApplication<MyApp>(*args)
209-
}
210-
211-
@Component
212-
class MyHandlers {
213-
214-
/**
215-
* 例如:监听OneBot的普通群消息
216-
*/
217-
@Listener
218-
@Filter("你好")
219-
@ContentTrim
220-
suspend fun onGroupMessage(event: OneBotNormalGroupMessageEvent) {
221-
event.reply("你也好")
222-
}
223-
}
224-
```
225-
226-
or Java:
227-
228-
```java
229-
@SpringBootApplication
230-
@EnableSimbot
231-
public class MyApp {
232-
public static void main(String[] args) {
233-
SpringApplication.run(MyApp.class, args);
234-
}
235-
236-
@Component
237-
public static class MyHandlers {
238-
239-
/**
240-
* 例如:监听OneBot的普通群消息
241-
*/
242-
@Listener
243-
@Filter("你好")
244-
@ContentTrim
245-
public CompletableFuture<?> onGroupMessage(OneBotNormalGroupMessageEvent event) {
246-
return event.replyAsync("你也好");
247-
}
248-
}
249-
}
250-
```
251-
252-
#### 配置文件
253-
254-
使用spring的时候用的。需要注意实际上是不允许使用注释的,这里只是方便展示。
255-
256-
配置文件放在资源目录 `resources` 中的 `/simbot-bots/` 目录下,以 `.bot.json` 格式结尾,
257-
例如 `myBot.bot.json`
258-
259-
```json5
260-
{
261-
// 固定值
262-
"component": "simbot.onebot11",
263-
"authorization": {
264-
// 唯一ID,作为组件内 Bot 的 id,用于组件内去重。可以随便编,但建议是bot的qq号
265-
"botUniqueId": "123456",
266-
// api地址,是个http/https服务器的路径,默认localhost:3000
267-
"apiServerHost": "http://localhost:3000",
268-
// 订阅事件的服务器地址,是个ws/wss路径,默认localhost:3001
269-
"eventServerHost":"ws://localhost:3001",
270-
// 配置的 token,可以是null
271-
"accessToken": null
272-
},
273-
// 额外的可选配置
274-
// config本身以及其内的各项属性绝大多数都可省略或null
275-
"config": {
276-
// API请求中的超时请求配置。整数数字,单位毫秒,默认为 `null`。
277-
"apiHttpRequestTimeoutMillis": null,
278-
// API请求中的超时请求配置。整数数字,单位毫秒,默认为 `null`。
279-
"apiHttpConnectTimeoutMillis": null,
280-
// API请求中的超时请求配置。整数数字,单位毫秒,默认为 `null`。
281-
"apiHttpSocketTimeoutMillis": null,
282-
// 每次尝试连接到 ws 服务时的最大重试次数,大于等于0的整数,默认为 2147483647
283-
"wsConnectMaxRetryTimes": null,
284-
// 每次尝试连接到 ws 服务时,如果需要重新尝试,则每次尝试之间的等待时长
285-
// 整数数字,单位毫秒,默认为 3500
286-
"wsConnectRetryDelayMillis": null,
287-
}
288-
}
289-
```
290-
291-
## 事件监听
65+
## 事件关系
29266

29367
简单列举一下原始事件与可能对应的组件事件之间的关系。
29468

295-
| 原始事件 | 组件事件 |
296-
|-----------------------------------------------|----------------------------------------|
297-
| `MetaEvent` | `OneBotMetaEvent` |
298-
| > `LifecycleEvent` | > `OneBotLifecycleEvent` |
299-
| > `HeartbeatEvent` | > `OneBotHeartbeatEvent` |
300-
| `MessageEvent` | `OneBotMessageEvent` |
301-
| > `GroupMessageEvent` | > `OneBotGroupMessageEvent` |
302-
| > `GroupMessageEvent` | > > `OneBotNormalGroupMessageEvent` |
303-
| > `GroupMessageEvent` | > > `OneBotAnonymousGroupMessageEvent` |
304-
| > `GroupMessageEvent` | > > `OneBotNoticeGroupMessageEvent` |
305-
| > `PrivateMessageEvent` | > `OneBotPrivateMessageEvent` |
306-
| > `PrivateMessageEvent` | > > `OneBotFriendMessageEvent` |
307-
| > `PrivateMessageEvent` | > > `OneBotGroupPrivateMessageEvent` |
308-
| `RequestEvent` | `OneBotRequestEvent` |
309-
| > `FriendRequestEvent` | > `OneBotFriendRequestEvent` |
310-
| > `GroupRequestEvent` | > `OneBotGroupRequestEvent` |
311-
| `NoticeEvent` | `OneBotNoticeEvent` |
312-
| > `FriendAddEvent` | > `OneBotFriendAddEvent` |
313-
| > `FriendRecallEvent` | > `OneBotFriendRecallEvent` |
314-
| > `GroupAdminEvent` | > `OneBotGroupAdminEvent` |
315-
| > `GroupBanEvent` | > `OneBotGroupBanEvent` |
316-
| > `GroupIncreaseEvent``GroupDecreaseEvent` | > `OneBotGroupChangeEvent` |
317-
| > `GroupIncreaseEvent` | > > `OneBotGroupMemberIncreaseEvent` |
318-
| > `GroupDecreaseEvent` | > > `OneBotGroupMemberDecreaseEvent` |
319-
| > `GroupRecallEvent` | > `OneBotGroupRecallEvent` |
320-
| > `GroupUploadEvent` | > `OneBotGroupUploadEvent` |
321-
| > `NotifyEvent` | > `OneBotNotifyEvent` |
322-
| > `NotifyEvent` | > > `OneBotHonorEvent` |
323-
| > `NotifyEvent` | > > `OneBotLuckyKingEvent` |
324-
| > `NotifyEvent` | > > `OneBotPokeEvent` |
325-
| > `NotifyEvent` | > > > `OneBotMemberPokeEvent` |
326-
| > `NotifyEvent` | > > > `OneBotBotSelfPokeEvent` |
327-
| `UnknownEvent` | > `UnknownEvent` |
328-
|| `OneBotBotStageEvent` |
329-
|| > `OneBotBotRegisteredEvent` |
330-
|| > `OneBotBotStartedEvent` |
331-
| 任意未支持事件 | `OneBotUnsupportedEvent` |
69+
| 原始事件类型 | 组件事件 |
70+
|-----------------------------------------------------|----------------------------------------|
71+
| `RawMetaEvent` | `OneBotMetaEvent` |
72+
| > `RawLifecycleEvent` | > `OneBotLifecycleEvent` |
73+
| > `RawHeartbeatEvent` | > `OneBotHeartbeatEvent` |
74+
| `RawMessageEvent` | `OneBotMessageEvent` |
75+
| > `RawGroupMessageEvent` | > `OneBotGroupMessageEvent` |
76+
| > `RawGroupMessageEvent` | > > `OneBotNormalGroupMessageEvent` |
77+
| > `RawGroupMessageEvent` | > > `OneBotAnonymousGroupMessageEvent` |
78+
| > `RawGroupMessageEvent` | > > `OneBotNoticeGroupMessageEvent` |
79+
| > `RawPrivateMessageEvent` | > `OneBotPrivateMessageEvent` |
80+
| > `RawPrivateMessageEvent` | > > `OneBotFriendMessageEvent` |
81+
| > `RawPrivateMessageEvent` | > > `OneBotGroupPrivateMessageEvent` |
82+
| `RawRequestEvent` | `OneBotRequestEvent` |
83+
| > `RawFriendRequestEvent` | > `OneBotFriendRequestEvent` |
84+
| > `RawGroupRequestEvent` | > `OneBotGroupRequestEvent` |
85+
| `RawNoticeEvent` | `OneBotNoticeEvent` |
86+
| > `RawFriendAddEvent` | > `OneBotFriendAddEvent` |
87+
| > `RawFriendRecallEvent` | > `OneBotFriendRecallEvent` |
88+
| > `RawGroupAdminEvent` | > `OneBotGroupAdminEvent` |
89+
| > `RawGroupBanEvent` | > `OneBotGroupBanEvent` |
90+
| > `RawGroupIncreaseEvent``RawGroupDecreaseEvent` | > `OneBotGroupChangeEvent` |
91+
| > `RawGroupIncreaseEvent` | > > `OneBotGroupMemberIncreaseEvent` |
92+
| > `RawGroupDecreaseEvent` | > > `OneBotGroupMemberDecreaseEvent` |
93+
| > `RawGroupRecallEvent` | > `OneBotGroupRecallEvent` |
94+
| > `RawGroupUploadEvent` | > `OneBotGroupUploadEvent` |
95+
| > `RawNotifyEvent` | > `OneBotNotifyEvent` |
96+
| > `RawNotifyEvent` | > > `OneBotHonorEvent` |
97+
| > `RawNotifyEvent` | > > `OneBotLuckyKingEvent` |
98+
| > `RawNotifyEvent` | > > `OneBotPokeEvent` |
99+
| > `RawNotifyEvent` | > > > `OneBotMemberPokeEvent` |
100+
| > `RawNotifyEvent` | > > > `OneBotBotSelfPokeEvent` |
101+
| `UnknownEvent` | > `UnknownEvent` |
102+
| | `OneBotBotStageEvent` |
103+
| | > `OneBotBotRegisteredEvent` |
104+
| | > `OneBotBotStartedEvent` |
105+
| 任意未支持事件 | `OneBotUnsupportedEvent` |
332106

333107
其中,可以通过 `OneBotUnsupportedEvent``OneBotUnknownEvent`
334108
来间接地监听那些尚未提供组件事件类型的原始事件。
335109

336-
> [!note]
337-
> OB11协议中的事件类型均有实现。
338-
339110
## License
340111

341112
```

0 commit comments

Comments
 (0)