onebot_v11 0.1.3

OneBot v11 with NapCat/llonebot extension
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
use crate::{event::message::Anonymous, traits::EndPoint, MessageSegment};
use onebot_v11_macro::{endpoint, ApiDataDerive};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, ApiDataDerive)]
pub enum ApiPayload {
    // 发送私聊消息
    SendPrivateMsg(SendPrivateMsg),
    // 发送群消息
    SendGroupMsg(SendGroupMsg),
    // 发送消息
    SendMsg(SendMsg),
    // 撤回消息
    DeleteMsg(DeleteMsg),
    // 获取消息
    GetMsg(GetMsg),
    // 获取合并转发消息
    GetForwardMsg(GetForwardMsg),
    // 发送好友赞
    SendLike(SendLike),
    // 群组踢人
    SetGroupKick(SetGroupKick),
    // 群组禁言
    SetGroupBan(SetGroupBan),
    // 群组匿名用户禁言
    SetGroupAnonymousBan(SetGroupAnonymousBan),
    // 群组全员禁言
    SetGroupWholeBan(SetGroupWholeBan),
    // 群组设置管理员
    SetGroupAdmin(SetGroupAdmin),
    // 群组匿名
    SetGroupAnonymous(SetGroupAnonymous),
    // 设置群名片(群备注)
    SetGroupCard(SetGroupCard),
    // 设置群名
    SetGroupName(SetGroupName),
    // 退出群组
    SetGroupLeave(SetGroupLeave),
    // 设置群组专属头衔
    SetGroupSpecialTitle(SetGroupSpecialTitle),
    // 处理加好友请求
    SetFriendAddRequest(SetFriendAddRequest),
    // 处理加群请求/邀请
    SetGroupAddRequest(SetGroupAddRequest),
    // 获取登录号信息
    GetLoginInfo(GetLoginInfo),
    // 获取陌生人信息
    GetStrangerInfo(GetStrangerInfo),
    // 获取好友列表
    GetFriendList(GetFriendList),
    // 获取群信息
    GetGroupInfo(GetGroupInfo),
    // 获取群列表
    GetGroupList(GetGroupList),
    // 获取群成员信息
    GetGroupMemberInfo(GetGroupMemberInfo),
    // 获取群成员列表
    GetGroupMemberList(GetGroupMemberList),
    // 获取群荣誉信息
    GetGroupHonorInfo(GetGroupHonorInfo),
    // 获取 Cookies
    GetCookies(GetCookies),
    // 获取 CSRF Token
    GetCsrfToken(GetCsrfToken),
    // 获取 QQ 相关接口凭证
    GetCredentials(GetCredentials),
    // 获取语音
    GetRecord(GetRecord),
    // 获取图片
    GetImage(GetImage),
    // 检查是否可以发送图片
    CanSendImage(CanSendImage),
    // 检查是否可以发送语音
    CanSendRecord(CanSendRecord),
    // 获取运行状态
    GetStatus(GetStatus),
    // 获取版本信息
    GetVersionInfo(GetVersionInfo),
    // 重启 OneBot 实现
    SetRestart(SetRestart),
    // 清理 OneBot 实现缓存
    CleanCache(CleanCache),
    // NapCat/llonebot扩展

    // 设置头像
    SetQQAvatar(SetQQAvatar),
    // 获取群系统通知
    GetGroupSystemMsg(GetGroupSystemMsg),
    // 下载群文件或私聊文件
    GetFile(GetFile),
    // 转发单条消息给好友
    ForwardFriendSingleMsg(ForwardFriendSingleMsg),
    // 转发单条消息给群
    ForwardGroupSingleMsg(ForwardGroupSingleMsg),
    // 设置表情回应
    SetMsgEmojiLike(SetMsgEmojiLike),
    // 标记私聊消息为已读
    MarkPrivateMsgAsRead(MarkPrivateMsgAsRead),
    // 标记群消息为已读
    MarkGroupMsgAsRead(MarkGroupMsgAsRead),
    // 获取官方bot qq号范围
    GetRobotUinRange(GetRobotUinRange),
    // 设置自身在线状态
    SetOnlineStatus(SetOnlineStatus),
    // 获取好友分类列表
    GetFriendsWithCategory(GetFriendsWithCategory),
    // 获取群文件数量
    GetGroupFileCount(GetGroupFileCount),
    // 获取群文件列表
    GetGroupFileList(GetGroupFileList),
    // 创建群文件夹
    SetGroupFileFolder(SetGroupFileFolder),
    // 删除群文件
    DelGroupFile(DelGroupFile),
    // 删除群文件夹
    DelGroupFileFolder(DelGroupFileFolder),

    // NapCat gocq拓展

    // 合并转发消息给群聊
    SendGroupForwardMsg(SendGroupForwardMsg),
    // 合并转发消息给好友
    SendPrivateForwardMsg(SendPrivateForwardMsg),
}

// 发送私聊消息结构体
#[endpoint("send_private_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SendPrivateMsg {
    pub user_id: i64,                 // 对方 QQ 号
    pub message: Vec<MessageSegment>, // 要发送的内容
    pub auto_escape: bool, // 消息内容是否作为纯文本发送(即不解析 CQ 码),只在 message 字段是字符串时有效
}

// 发送群消息结构体
#[endpoint("send_group_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SendGroupMsg {
    pub group_id: i64,                // 群号
    pub message: Vec<MessageSegment>, // 要发送的消息内容
    pub auto_escape: bool,            // 消息内容是否作为纯文本发送(不解析 CQ 码)
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum MessageType {
    #[serde(rename = "private")]
    Private,
    #[serde(rename = "group")]
    Group,
}

// 发送消息结构体
#[endpoint("send_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SendMsg {
    pub message_type: MessageType,    // 消息类型(private 或 group)
    pub user_id: Option<i64>,         // 对方 QQ 号(私聊时需要)
    pub group_id: Option<i64>,        // 群号(群聊时需要)
    pub message: Vec<MessageSegment>, // 要发送的消息内容
    pub auto_escape: bool,            // 消息内容是否作为纯文本发送(不解析 CQ 码)
}

// 撤回消息结构体
#[endpoint("delete_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DeleteMsg {
    pub message_id: i64, // 消息 ID
}

// 获取消息结构体
#[endpoint("get_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetMsg {
    pub message_id: i64, // 消息 ID
}

// 获取合并转发消息结构体
#[endpoint("get_forward_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetForwardMsg {
    pub id: String, // 合并转发 ID
}

// 发送好友赞结构体
#[endpoint("send_like")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SendLike {
    pub user_id: i64, // 对方 QQ 号
    pub times: i64,   // 赞的次数,每个好友每天最多 10 次
}

// 群组踢人结构体
#[endpoint("set_group_kick")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupKick {
    pub group_id: i64,            // 群号
    pub user_id: i64,             // 要踢的 QQ 号
    pub reject_add_request: bool, // 拒绝此人的加群请求
}

// 群组单人禁言结构体
#[endpoint("set_group_ban")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupBan {
    pub group_id: i64, // 群号
    pub user_id: i64,  // 要禁言的 QQ 号
    pub duration: i64, // 禁言时长,单位秒,0 表示取消禁言
}

// 群组匿名用户禁言结构体
#[endpoint("set_group_anonymous_ban")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupAnonymousBan {
    pub group_id: i64,                  // 群号
    pub anonymous: Option<Anonymous>,   // 可选,要禁言的匿名用户对象
    pub anonymous_flag: Option<String>, // 可选,要禁言的匿名用户的 flag
    pub duration: i64,                  // 禁言时长,单位秒,无法取消匿名用户禁言
}

// 群组全员禁言结构体
#[endpoint("set_group_whole_ban")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupWholeBan {
    pub group_id: i64, // 群号
    pub enable: bool,  // 是否禁言
}

// 群组设置管理员结构体
#[endpoint("set_group_admin")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupAdmin {
    pub group_id: i64, // 群号
    pub user_id: i64,  // 要设置管理员的 QQ 号
    pub enable: bool,  // true 为设置,false 为取消
}

// 群组匿名结构体
#[endpoint("set_group_anonymous")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupAnonymous {
    pub group_id: i64, // 群号
    pub enable: bool,  // 是否允许匿名聊天
}

// 设置群名片(群备注)结构体
#[endpoint("set_group_card")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupCard {
    pub group_id: i64, // 群号
    pub user_id: i64,  // 要设置的 QQ 号
    pub card: String,  // 群名片内容,不填或空字符串表示删除群名片
}

// 设置群名结构体
#[endpoint("set_group_name")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupName {
    pub group_id: i64,      // 群号
    pub group_name: String, // 新群名
}

// 退出群组结构体
#[endpoint("set_group_leave")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupLeave {
    pub group_id: i64,    // 群号
    pub is_dismiss: bool, // 是否解散,如果登录号是群主,则仅在此项为 true 时能够解散
}

// 设置群组专属头衔结构体
#[endpoint("set_group_special_title")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupSpecialTitle {
    pub group_id: i64,         // 群号
    pub user_id: i64,          // 要设置的 QQ 号
    pub special_title: String, // 专属头衔,不填或空字符串表示删除专属头衔
    pub duration: i64,         // 专属头衔有效期,单位秒,-1 表示永久,此项似乎没有效果,有待测试
}

// 处理加好友请求结构体
#[endpoint("set_friend_add_request")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetFriendAddRequest {
    pub flag: String,  // 加好友请求的 flag
    pub approve: bool, // 是否同意请求
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remark: Option<String>, // 添加后的好友备注(仅在同意时有效)
}

// 处理加群请求/邀请结构体
#[endpoint("    set_group_add_request")]                                    
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupAddRequest {
    pub flag: String,     // 加群请求的 flag
    pub sub_type: String, // 请求类型(add 或 invite)
    pub approve: bool,    // 是否同意请求/邀请
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,   // 拒绝理由(仅在拒绝时有效)
}

// 获取登录号信息结构体
#[endpoint("get_login_info")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetLoginInfo {}

// 获取陌生人信息结构体
#[endpoint("get_stranger_info")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetStrangerInfo {
    pub user_id: i64,   // QQ 号
    pub no_cache: bool, // 是否不使用缓存
}

// 获取好友列表结构体
#[endpoint("get_friend_list")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetFriendList {}

// 获取群信息结构体
#[endpoint("get_group_info")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupInfo {
    pub group_id: i64,  // 群号
    pub no_cache: bool, // 是否不使用缓存
}

// 获取群列表结构体
#[endpoint("get_group_list")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupList {}

// 获取群成员信息结构体
#[endpoint("get_group_member_info")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupMemberInfo {
    pub group_id: i64,  // 群号
    pub user_id: i64,   // QQ 号
    pub no_cache: bool, // 是否不使用缓存
}

// 获取群成员列表结构体
#[endpoint("get_group_member_list")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupMemberList {
    pub group_id: i64, // 群号
}

// 获取群荣誉信息结构体
#[endpoint("get_group_honor_info")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupHonorInfo {
    pub group_id: i64, // 群号
    #[serde(rename = "type")]
    pub honor_type: String, // 要获取的群荣誉类型
}

// 获取 Cookies 结构体
#[endpoint("get_cookies")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetCookies {
    pub domain: String, // 需要获取 cookies 的域名
}

// 获取 CSRF Token 结构体
#[endpoint("get_csrf_token")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetCsrfToken {}

// 获取 QQ 相关接口凭证结构体
#[endpoint("get_credentials")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetCredentials {
    pub domain: String, // 需要获取 cookies 的域名
}

// 获取语音结构体
#[endpoint("get_record")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetRecord {
    pub file: String,       // 收到的语音文件名
    pub out_format: String, // 要转换到的格式
}

// 获取图片结构体
#[endpoint("get_image")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetImage {
    pub file: String, // 收到的图片文件名
}

// 检查是否可以发送图片结构体
#[endpoint("can_send_image")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct CanSendImage {}

// 检查是否可以发送语音结构体
#[endpoint("can_send_record")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct CanSendRecord {}

// 获取运行状态结构体
#[endpoint("get_status")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetStatus {}

// 获取版本信息结构体
#[endpoint("get_version_info")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetVersionInfo {}

// 重启 OneBot 实现结构体
#[endpoint("set_restart")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetRestart {
    pub delay: i64, // 要延迟的毫秒数
}

// 清理缓存结构体
#[endpoint("clean_cache")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct CleanCache {}

// NapCat/llonebot扩展

// 设置头像✔
#[endpoint("set_qq_avatar")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetQQAvatar {
    pub file: String, // 图片路径/链接/base64
}

// 获取群系统通知✔
#[endpoint("get_group_system_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupSystemMsg {
    pub group_id: i64, // 群号
}

// 下载群文件或私聊文件
#[endpoint("get_file")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetFile {
    pub file_id: String, // 文件 ID
}

// 转发单条消息给好友✔
#[endpoint("forward_friend_single_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ForwardFriendSingleMsg {
    pub user_id: i64,    // 对方 QQ 号
    pub message_id: i64, // 消息 ID
}

// 转发单条消息给群✔
#[endpoint("forward_group_single_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ForwardGroupSingleMsg {
    pub group_id: i64,   // 群号
    pub message_id: i64, // 消息 ID
}

// 设置表情回应✔
#[endpoint("set_msg_emoji_like")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetMsgEmojiLike {
    pub message_id: String, // 消息 ID
    // emoji_id 参考 https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType
    pub emoji_id: String, // 表情 ID
}

// 设置私聊消息已读✔
#[endpoint("mark_private_msg_as_read")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct MarkPrivateMsgAsRead {
    pub user_id: i64, // 对方 QQ 号
}

// 设置群消息已读✔
#[endpoint("mark_group_msg_as_read")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct MarkGroupMsgAsRead {
    pub group_id: i64, // 群号
}

// 获取官方bot qq号范围✔
#[endpoint("get_robot_uin_range")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetRobotUinRange {}

// 设置自身在线状态✔
// 参考: https://napneko.github.io/zh-CN/develop/status_list
#[endpoint("set_online_status")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetOnlineStatus {
    pub status: u32, // 在线状态
    #[serde(rename = "extStatus")]
    pub ext_status: u32, // 扩展在线状态
    #[serde(rename = "batteryStatus")]
    pub battery_status: u32, // 电量状态
}

// 获取好友分类列表(untested)
#[endpoint("get_friends_with_category")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetFriendsWithCategory {}

// 获取群文件数量✔
#[endpoint("get_group_file_count")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupFileCount {
    pub group_id: i64, // 群号
}

// 获取群文件列表✔
#[endpoint("get_group_file_list")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct GetGroupFileList {
    pub group_id: i64,    // 群号
    pub start_index: i64, // 起始文件序号
    pub file_count: i64,  // 获取的文件数量
}

// 创建群文件夹✔
#[endpoint("set_group_file_folder")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SetGroupFileFolder {
    pub group_id: i64,       // 群号
    pub folder_name: String, // 文件夹名称
}

// 删除群文件✔
#[endpoint("del_group_file")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DelGroupFile {
    pub group_id: i64,   // 群号
    pub file_id: String, // 文件 ID
}

// 删除群文件夹✔
#[endpoint("del_group_file_folder")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DelGroupFileFolder {
    pub group_id: i64,     // 群号
    pub folder_id: String, // 文件夹 ID
}

// NapCat gocq拓展

// 合并转发消息给群聊
#[endpoint("send_group_forward_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SendGroupForwardMsg {
    pub group_id: i64,                 // 群号
    pub messages: Vec<MessageSegment>, // 要发送的消息内容
}

// 合并转发消息给好友
#[endpoint("send_private_forward_msg")]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SendPrivateForwardMsg {
    pub user_id: i64,                  // 对方 QQ 号
    pub messages: Vec<MessageSegment>, // 要发送的消息内容
}