@mrlingxd/koishi-plugin-adapter-onebot 0.1.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bot/cqcode.d.ts +204 -5
- package/lib/bot/cqcode.js +1 -1
- package/lib/bot/index.d.ts +35 -19
- package/lib/bot/index.js +89 -53
- package/lib/bot/message.d.ts +4 -4
- package/lib/bot/message.js +58 -57
- package/lib/http.d.ts +5 -6
- package/lib/http.js +5 -7
- package/lib/index.d.ts +12 -8
- package/lib/index.js +2 -3
- package/lib/internal.d.ts +132 -0
- package/lib/{types.js → internal.js} +6 -57
- package/lib/types/device.d.ts +8 -0
- package/lib/types/device.js +1 -0
- package/lib/types/enum.d.ts +65 -0
- package/lib/types/enum.js +70 -0
- package/lib/types/event/base.d.ts +26 -0
- package/lib/types/event/base.js +20 -0
- package/lib/types/event/message.d.ts +44 -0
- package/lib/types/event/message.js +11 -0
- package/lib/types/event/meta.d.ts +34 -0
- package/lib/types/event/meta.js +1 -0
- package/lib/types/event/notice.d.ts +256 -0
- package/lib/types/event/notice.js +40 -0
- package/lib/types/event/request.d.ts +30 -0
- package/lib/types/event/request.js +11 -0
- package/lib/types/group.d.ts +43 -0
- package/lib/types/group.js +1 -0
- package/lib/types/index.d.ts +334 -0
- package/lib/types/index.js +10 -0
- package/lib/types/sender.d.ts +43 -0
- package/lib/types/sender.js +10 -0
- package/lib/types/user.d.ts +16 -0
- package/lib/types/user.js +1 -0
- package/lib/utils.d.ts +15 -11
- package/lib/utils.js +210 -200
- package/lib/ws.d.ts +9 -10
- package/lib/ws.js +2 -4
- package/package.json +6 -9
- package/lib/bot/base.d.ts +0 -36
- package/lib/bot/base.js +0 -66
- package/lib/bot/qqguild.d.ts +0 -31
- package/lib/bot/qqguild.js +0 -66
- package/lib/types.d.ts +0 -474
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { Dict } from "koishi";
|
|
2
|
+
import { CQCode } from "../bot/cqcode";
|
|
3
|
+
/** OneBot API 响应格式 */
|
|
4
|
+
export interface ApiResponse<T = Dict> {
|
|
5
|
+
/** 请求状态 */
|
|
6
|
+
status: "ok" | "async" | "failed";
|
|
7
|
+
/** 返回码 */
|
|
8
|
+
retcode: number;
|
|
9
|
+
/** 返回数据 */
|
|
10
|
+
data: T;
|
|
11
|
+
/**
|
|
12
|
+
* 部分协议端实现的扩展字段
|
|
13
|
+
*
|
|
14
|
+
* '回声', 如果请求时指定了 echo, 那么响应也会包含 echo
|
|
15
|
+
* */
|
|
16
|
+
echo?: string;
|
|
17
|
+
/** go-cqhttp 字段,错误信息 */
|
|
18
|
+
wording?: string;
|
|
19
|
+
}
|
|
20
|
+
/** 请求超时错误 */
|
|
21
|
+
export declare class TimeoutError extends Error {
|
|
22
|
+
constructor(args: Dict, url: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 获取凭证响应
|
|
26
|
+
*/
|
|
27
|
+
export interface GetCredentialsResponse {
|
|
28
|
+
/** Cookies */
|
|
29
|
+
cookies: string;
|
|
30
|
+
/** CSRF Token */
|
|
31
|
+
csrf_token: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 获取在线机型
|
|
35
|
+
*/
|
|
36
|
+
export interface ModelVariant {
|
|
37
|
+
/** 展示内容 */
|
|
38
|
+
model_show: string;
|
|
39
|
+
/** 是否需要付费 */
|
|
40
|
+
need_pay: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 群文件对象
|
|
44
|
+
*/
|
|
45
|
+
export interface File {
|
|
46
|
+
/** 群号 */
|
|
47
|
+
group_id: number;
|
|
48
|
+
/** 文件ID */
|
|
49
|
+
file_id: string;
|
|
50
|
+
/** 文件名 */
|
|
51
|
+
file_name: string;
|
|
52
|
+
/** 文件类型 */
|
|
53
|
+
busid: number;
|
|
54
|
+
/** 文件大小 */
|
|
55
|
+
file_size: number;
|
|
56
|
+
/** 上传时间 */
|
|
57
|
+
upload_time: number;
|
|
58
|
+
/** 过期时间,永久文件恒为0 */
|
|
59
|
+
dead_time: number;
|
|
60
|
+
/** 最后修改时间 */
|
|
61
|
+
modify_time: number;
|
|
62
|
+
/** 下载次数 */
|
|
63
|
+
download_times: number;
|
|
64
|
+
/** 上传者ID */
|
|
65
|
+
uploader: number;
|
|
66
|
+
/** 上传者名字 */
|
|
67
|
+
uploader_name: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 群文件夹对象
|
|
71
|
+
*/
|
|
72
|
+
export interface Folder {
|
|
73
|
+
/** 群号 */
|
|
74
|
+
group_id: number;
|
|
75
|
+
/** 文件夹ID */
|
|
76
|
+
folder_id: string;
|
|
77
|
+
/** 文件名 */
|
|
78
|
+
folder_name: string;
|
|
79
|
+
/** 创建时间 */
|
|
80
|
+
create_time: number;
|
|
81
|
+
/** 创建者 */
|
|
82
|
+
creator: number;
|
|
83
|
+
/** 创建者名字 */
|
|
84
|
+
creator_name: string;
|
|
85
|
+
/** 子文件数量 */
|
|
86
|
+
total_file_count: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 获取群根目录文件列表响应
|
|
90
|
+
*/
|
|
91
|
+
export interface GroupFileList {
|
|
92
|
+
/** 文件列表 */
|
|
93
|
+
files: File[];
|
|
94
|
+
/** 文件夹列表 */
|
|
95
|
+
folders: Folder[];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 获取群文件系统信息
|
|
99
|
+
*/
|
|
100
|
+
export interface GroupFileSystemInfo {
|
|
101
|
+
/** 文件总数 */
|
|
102
|
+
file_count: number;
|
|
103
|
+
/** 文件上限 */
|
|
104
|
+
limit_count: number;
|
|
105
|
+
/** 已使用空间 */
|
|
106
|
+
used_space: number;
|
|
107
|
+
/** 空间上限 */
|
|
108
|
+
total_space: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 精华消息列表(cqhttp 扩展)
|
|
112
|
+
*
|
|
113
|
+
* get_essence_msg_list API 的响应数据
|
|
114
|
+
*/
|
|
115
|
+
export interface EssenceMessage {
|
|
116
|
+
/** 发送者 QQ 号 */
|
|
117
|
+
sender_id: number;
|
|
118
|
+
/** 发送者昵称· */
|
|
119
|
+
sender_nick: string;
|
|
120
|
+
/** 消息发送时间 */
|
|
121
|
+
sender_time: number;
|
|
122
|
+
/** 操作者昵称 */
|
|
123
|
+
operator_nick: string;
|
|
124
|
+
/** 精华设置时间 */
|
|
125
|
+
operator_time: number;
|
|
126
|
+
/** 消息 ID */
|
|
127
|
+
message_id: number;
|
|
128
|
+
/**
|
|
129
|
+
* 消息内容
|
|
130
|
+
*
|
|
131
|
+
* 此字段被其它实现端实现,原始 cqhttp 中并不存在该字段
|
|
132
|
+
*/
|
|
133
|
+
content?: CQCode.CQCodeUnion[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 图片 OCR 识别结果
|
|
137
|
+
*/
|
|
138
|
+
export interface ImageOcrResult {
|
|
139
|
+
/** 识别到的文本数组 */
|
|
140
|
+
texts: TextDetection[];
|
|
141
|
+
/** 识别到的语言 */
|
|
142
|
+
language: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 单个文本检测结果
|
|
146
|
+
*/
|
|
147
|
+
export interface TextDetection {
|
|
148
|
+
/** 检测到的文本内容 */
|
|
149
|
+
text: string;
|
|
150
|
+
/** 置信度 */
|
|
151
|
+
confidence: number;
|
|
152
|
+
/** 文本在图片中的坐标点数组 */
|
|
153
|
+
coordinates: Coordinate[];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 坐标点
|
|
157
|
+
*/
|
|
158
|
+
export interface Coordinate {
|
|
159
|
+
/** 横坐标 */
|
|
160
|
+
x: number;
|
|
161
|
+
/** 纵坐标 */
|
|
162
|
+
y: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 获取群 @全体成员 剩余次数 API 的响应类型
|
|
166
|
+
*/
|
|
167
|
+
export interface GroupAtAllRemain {
|
|
168
|
+
/** 是否可以 @全体成员 */
|
|
169
|
+
can_at_all: boolean;
|
|
170
|
+
/** 群内所有管理当天剩余 @全体成员 次数 */
|
|
171
|
+
remain_at_all_count_for_group: number;
|
|
172
|
+
/** Bot 当天剩余 @全体成员 次数 */
|
|
173
|
+
remain_at_all_count_for_uin: number;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 获取群公告
|
|
177
|
+
*/
|
|
178
|
+
export interface GroupNotice {
|
|
179
|
+
/** 文本内容 */
|
|
180
|
+
text: string;
|
|
181
|
+
/** 图片内容列表 */
|
|
182
|
+
image: NoticeMessageImage[];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 公告图片信息
|
|
186
|
+
*/
|
|
187
|
+
export interface NoticeMessageImage {
|
|
188
|
+
/** 图片 ID */
|
|
189
|
+
id: string;
|
|
190
|
+
/** 高度 */
|
|
191
|
+
height: string;
|
|
192
|
+
/** 宽度 */
|
|
193
|
+
width: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 公告结构
|
|
197
|
+
*/
|
|
198
|
+
export interface Notice {
|
|
199
|
+
/** 公告 ID */
|
|
200
|
+
notice_id: string;
|
|
201
|
+
/** 发送人 QQ 号 */
|
|
202
|
+
sender_id: number;
|
|
203
|
+
/** 发布时间 */
|
|
204
|
+
publish_time: number;
|
|
205
|
+
/** 公告消息内容 */
|
|
206
|
+
message: GroupNotice;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 获取登录号信息
|
|
210
|
+
*/
|
|
211
|
+
export interface LoginInfo {
|
|
212
|
+
/** 登录号 QQ 号 */
|
|
213
|
+
user_id: number;
|
|
214
|
+
/** 登录号昵称 */
|
|
215
|
+
nickname: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 好友信息
|
|
219
|
+
*/
|
|
220
|
+
export interface FriendInfo {
|
|
221
|
+
/** QQ 号 */
|
|
222
|
+
user_id: number;
|
|
223
|
+
/** 昵称 */
|
|
224
|
+
nickname: string;
|
|
225
|
+
/** 备注名 */
|
|
226
|
+
remark: string;
|
|
227
|
+
/** 更多字段 */
|
|
228
|
+
[property: string]: unknown;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* 单向好友信息
|
|
232
|
+
*/
|
|
233
|
+
export interface UnidirectionalFriendInfo {
|
|
234
|
+
/** QQ 号 */
|
|
235
|
+
user_id: number;
|
|
236
|
+
/** 昵称 */
|
|
237
|
+
nickname: string;
|
|
238
|
+
/** 来源 */
|
|
239
|
+
source: string;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 当前龙王信息
|
|
243
|
+
*/
|
|
244
|
+
export interface GroupHonorCurrentTalkative {
|
|
245
|
+
/** QQ 号 */
|
|
246
|
+
user_id: number;
|
|
247
|
+
/** 昵称 */
|
|
248
|
+
nickname: string;
|
|
249
|
+
/** 头像 URL */
|
|
250
|
+
avatar: string;
|
|
251
|
+
/** 持续天数 */
|
|
252
|
+
day_count: number;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 群荣誉成员信息
|
|
256
|
+
*/
|
|
257
|
+
export interface GroupHonorItem {
|
|
258
|
+
/** QQ 号 */
|
|
259
|
+
user_id: number;
|
|
260
|
+
/** 昵称 */
|
|
261
|
+
nickname: string;
|
|
262
|
+
/** 头像 URL */
|
|
263
|
+
avatar: string;
|
|
264
|
+
/** 荣誉描述 */
|
|
265
|
+
description: string;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* 群荣誉信息
|
|
269
|
+
*/
|
|
270
|
+
export interface GroupHonorInfo {
|
|
271
|
+
/** 群号 */
|
|
272
|
+
group_id: number;
|
|
273
|
+
/** 当前龙王 */
|
|
274
|
+
current_talkative?: GroupHonorCurrentTalkative;
|
|
275
|
+
/** 历史龙王列表 */
|
|
276
|
+
talkative_list: GroupHonorItem[];
|
|
277
|
+
/** 群聊之火列表 */
|
|
278
|
+
performer_list: GroupHonorItem[];
|
|
279
|
+
/** 群聊炽焰列表 */
|
|
280
|
+
legend_list: GroupHonorItem[];
|
|
281
|
+
/** 冒尖小春笋列表 */
|
|
282
|
+
strong_newbie_list: GroupHonorItem[];
|
|
283
|
+
/** 快乐之源列表 */
|
|
284
|
+
emotion_list: GroupHonorItem[];
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* 群邀请消息
|
|
288
|
+
*/
|
|
289
|
+
export interface InvitedRequest {
|
|
290
|
+
/** 请求ID */
|
|
291
|
+
request_id: number;
|
|
292
|
+
/** 邀请者 QQ 号 */
|
|
293
|
+
invitor_uin: number;
|
|
294
|
+
/** 邀请者昵称 */
|
|
295
|
+
invitor_nick: string;
|
|
296
|
+
/** 群号 */
|
|
297
|
+
group_id: number;
|
|
298
|
+
/** 群名 */
|
|
299
|
+
group_name: string;
|
|
300
|
+
/** 是否已被处理 */
|
|
301
|
+
checked: boolean;
|
|
302
|
+
/** 处理者,未处理为0 */
|
|
303
|
+
actor: number;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* 进群请求消息
|
|
307
|
+
*/
|
|
308
|
+
export interface JoinRequest {
|
|
309
|
+
/** 请求ID */
|
|
310
|
+
request_id: number;
|
|
311
|
+
/** 请求者 QQ 号 */
|
|
312
|
+
requester_uin: number;
|
|
313
|
+
/** 请求者昵称 */
|
|
314
|
+
requester_nick: string;
|
|
315
|
+
/** 验证消息 */
|
|
316
|
+
message: string;
|
|
317
|
+
/** 群号 */
|
|
318
|
+
group_id: number;
|
|
319
|
+
/** 群名 */
|
|
320
|
+
group_name: string;
|
|
321
|
+
/** 是否已被处理 */
|
|
322
|
+
checked: boolean;
|
|
323
|
+
/** 处理者,未处理为0 */
|
|
324
|
+
actor: number;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* 群系统消息响应
|
|
328
|
+
*/
|
|
329
|
+
export interface GroupSystemMsgResponse {
|
|
330
|
+
/** 邀请消息列表 */
|
|
331
|
+
invited_requests: InvitedRequest[] | null;
|
|
332
|
+
/** 进群消息列表 */
|
|
333
|
+
join_requests: JoinRequest[] | null;
|
|
334
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Dict } from "koishi";
|
|
2
|
+
import { GroupMemberRole, UserSex } from "./enum";
|
|
3
|
+
/** 发送者信息
|
|
4
|
+
*
|
|
5
|
+
* 每一个字段不一定存在,具体取决于 OneBot 实现
|
|
6
|
+
*/
|
|
7
|
+
export interface Sender {
|
|
8
|
+
/** 用户ID */
|
|
9
|
+
user_id: number;
|
|
10
|
+
/** 昵称 */
|
|
11
|
+
nickname: string;
|
|
12
|
+
/** 性别 */
|
|
13
|
+
sex?: UserSex;
|
|
14
|
+
/** 年龄 */
|
|
15
|
+
age?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 群发送者信息
|
|
19
|
+
*/
|
|
20
|
+
export interface GroupSender extends Sender {
|
|
21
|
+
/** 群名片/备注 */
|
|
22
|
+
card?: string;
|
|
23
|
+
/** 地区 */
|
|
24
|
+
area?: string;
|
|
25
|
+
/** 群等级 */
|
|
26
|
+
level?: number;
|
|
27
|
+
/** 角色 */
|
|
28
|
+
role?: GroupMemberRole;
|
|
29
|
+
/** 专属头衔 */
|
|
30
|
+
title?: string;
|
|
31
|
+
}
|
|
32
|
+
/** 匿名信息 */
|
|
33
|
+
export interface Anonymous {
|
|
34
|
+
/** 匿名用户 ID */
|
|
35
|
+
id: number;
|
|
36
|
+
/** 匿名用户名称 */
|
|
37
|
+
name: string;
|
|
38
|
+
/** 匿名用户 flag,在调用禁言 API 时需要传入 */
|
|
39
|
+
flag: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class SenderError extends Error {
|
|
42
|
+
constructor(args: Dict, url: string, retcode: number);
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class SenderError extends Error {
|
|
2
|
+
constructor(args, url, retcode) {
|
|
3
|
+
super(`Error with request ${url}, args: ${JSON.stringify(args)}, retcode: ${retcode}`);
|
|
4
|
+
Object.defineProperties(this, {
|
|
5
|
+
code: { value: retcode },
|
|
6
|
+
args: { value: args },
|
|
7
|
+
url: { value: url }
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UserSex } from "./enum";
|
|
2
|
+
/** 账号信息 */
|
|
3
|
+
export interface UserInfo {
|
|
4
|
+
/** 账号 ID */
|
|
5
|
+
user_id: number;
|
|
6
|
+
/** 昵称 */
|
|
7
|
+
nickname: string;
|
|
8
|
+
/** 性别 */
|
|
9
|
+
sex?: UserSex;
|
|
10
|
+
/** 年龄 */
|
|
11
|
+
age?: number;
|
|
12
|
+
/** 等级 */
|
|
13
|
+
level?: number;
|
|
14
|
+
/** 更多字段 */
|
|
15
|
+
[property: string]: unknown;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Universal } from "koishi";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { OneBot } from "./bot";
|
|
3
|
+
import { EventType } from "./types/enum";
|
|
4
|
+
import { BaseEvent } from "./types/event/base";
|
|
5
|
+
import { MessageEvent } from "./types/event/message";
|
|
6
|
+
import { GroupInfo, GroupMemberInfo } from "./types/group";
|
|
7
|
+
import { UserInfo } from "./types/user";
|
|
4
8
|
export * from "./types";
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare
|
|
8
|
-
export declare const
|
|
9
|
-
export declare function
|
|
10
|
-
export declare const adaptGuild: (info:
|
|
11
|
-
export declare const adaptChannel: (info:
|
|
12
|
-
export declare function dispatchSession(bot:
|
|
13
|
-
export declare function adaptSession(bot:
|
|
9
|
+
export declare const convertUser: (user: UserInfo, isBot?: boolean) => Universal.User;
|
|
10
|
+
export declare const decodeUser: (event: MessageEvent, isBot?: boolean) => Universal.User;
|
|
11
|
+
export declare function decodeGuild(group: GroupInfo): Universal.Guild;
|
|
12
|
+
export declare const decodeGuildMember: (user: GroupMemberInfo, isBot?: boolean) => Universal.GuildMember;
|
|
13
|
+
export declare function decodeMessage(bot: OneBot, event: MessageEvent, message?: Universal.Message, payload?: Universal.MessageLike): Promise<Universal.Message>;
|
|
14
|
+
export declare const adaptGuild: (info: GroupInfo) => Universal.Guild;
|
|
15
|
+
export declare const adaptChannel: (info: GroupInfo) => Universal.Channel;
|
|
16
|
+
export declare function dispatchSession(bot: OneBot, data: BaseEvent<EventType>): Promise<void>;
|
|
17
|
+
export declare function adaptSession(bot: OneBot, event: BaseEvent<EventType>): Promise<import("koishi").Session<never, never, import("koishi").Context>>;
|