@karinjs/adapter-qqbot 1.2.8 → 1.2.10
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/config/comment/config.json +3 -0
- package/config/config/config.yaml +53 -0
- package/lib/cli/pr.d.ts +2 -0
- package/lib/cli/pr.js +73 -0
- package/lib/core/adapter/adapter.d.ts +91 -0
- package/lib/core/adapter/adapter.js +144 -0
- package/lib/core/adapter/handler.d.ts +49 -0
- package/lib/core/adapter/handler.js +140 -0
- package/lib/core/adapter/markdown.d.ts +38 -0
- package/lib/core/adapter/markdown.js +220 -0
- package/lib/core/adapter/normal.d.ts +30 -0
- package/lib/core/adapter/normal.js +263 -0
- package/lib/core/api/index.d.ts +167 -0
- package/lib/core/api/index.js +180 -0
- package/lib/core/api/sign.d.ts +22 -0
- package/lib/core/api/sign.js +40 -0
- package/lib/core/api/types.d.ts +236 -0
- package/lib/core/event/conver.d.ts +10 -0
- package/lib/core/event/conver.js +57 -0
- package/lib/core/event/index.d.ts +9 -0
- package/lib/core/event/index.js +98 -0
- package/lib/core/event/message.d.ts +27 -0
- package/lib/core/event/message.js +95 -0
- package/lib/core/event/notice.d.ts +50 -0
- package/lib/core/event/notice.js +133 -0
- package/lib/{types/event.d.ts → core/event/types.d.ts} +255 -14
- package/lib/core/internal/axios.d.ts +25 -0
- package/lib/core/internal/axios.js +46 -0
- package/lib/core/internal/sign.d.ts +22 -0
- package/lib/core/internal/sign.js +40 -0
- package/lib/core/webhook/c2c.d.ts +2 -0
- package/lib/core/webhook/c2c.js +14 -0
- package/lib/core/webhook/http.d.ts +2 -0
- package/lib/core/webhook/http.js +35 -0
- package/lib/core/webhook/index.d.ts +17 -0
- package/lib/core/webhook/index.js +87 -0
- package/lib/core/webhook/ws.d.ts +2 -0
- package/lib/core/webhook/ws.js +79 -0
- package/lib/index.d.ts +1 -3
- package/lib/index.js +5 -7
- package/lib/root.d.ts +5 -0
- package/lib/root.js +9 -0
- package/lib/types/config.d.ts +53 -0
- package/lib/utils/common.d.ts +75 -61
- package/lib/utils/common.js +190 -202
- package/lib/utils/config.d.ts +5 -130
- package/lib/utils/config.js +50 -172
- package/lib/utils/dir.d.ts +1 -5
- package/lib/utils/dir.js +1 -10
- package/lib/utils/index.d.ts +4 -3
- package/lib/utils/index.js +4 -3
- package/package.json +41 -23
- package/config/config.yaml +0 -69
- package/lib/core/api.d.ts +0 -166
- package/lib/core/api.js +0 -429
- package/lib/core/index.d.ts +0 -92
- package/lib/core/index.js +0 -343
- package/lib/core/intents.d.ts +0 -6
- package/lib/core/intents.js +0 -57
- package/lib/core/markdown.d.ts +0 -23
- package/lib/core/markdown.js +0 -265
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -3
- package/lib/types/media.d.ts +0 -100
- package/lib/types/message.d.ts +0 -85
- /package/lib/{types/event.js → core/api/types.js} +0 -0
- /package/lib/{types/media.js → core/event/types.js} +0 -0
- /package/lib/types/{message.js → config.js} +0 -0
package/lib/core/api.js
DELETED
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import got from 'got';
|
|
2
|
-
import WebSocket from 'ws';
|
|
3
|
-
import EventEmitter from 'events';
|
|
4
|
-
import { Intents } from './intents.js';
|
|
5
|
-
import { common, logger } from 'node-karin';
|
|
6
|
-
export class QQBotApi extends EventEmitter {
|
|
7
|
-
/** 开发者的appId */
|
|
8
|
-
appId;
|
|
9
|
-
/** Bot头像 */
|
|
10
|
-
avatar;
|
|
11
|
-
/** Bot的昵称 */
|
|
12
|
-
nick;
|
|
13
|
-
/** 调用凭证 */
|
|
14
|
-
#access_token;
|
|
15
|
-
/** wss地址 */
|
|
16
|
-
wssUrl;
|
|
17
|
-
/** 开发者的Secret 仅在内部使用 防止泄露 */
|
|
18
|
-
#Secret;
|
|
19
|
-
/** wss连接 */
|
|
20
|
-
wss;
|
|
21
|
-
/** wss连接唯一值 */
|
|
22
|
-
seq = 0;
|
|
23
|
-
/** 心跳内容 */
|
|
24
|
-
heartbeat;
|
|
25
|
-
/** 心跳生命周期 单位:毫秒 */
|
|
26
|
-
heartbeat_interval;
|
|
27
|
-
/** 请求头 用于鉴权 */
|
|
28
|
-
headers = {};
|
|
29
|
-
/** 基本请求接口 */
|
|
30
|
-
host;
|
|
31
|
-
#config;
|
|
32
|
-
constructor(config) {
|
|
33
|
-
super();
|
|
34
|
-
this.#config = config;
|
|
35
|
-
this.appId = String(this.#config.appId);
|
|
36
|
-
this.avatar = '';
|
|
37
|
-
this.nick = '';
|
|
38
|
-
this.#Secret = this.#config.secret;
|
|
39
|
-
this.host = this.#config.sandBox ? this.#config.sandBoxApi : this.#config.qqBotApi;
|
|
40
|
-
this.#access_token = '';
|
|
41
|
-
this.wssUrl = '';
|
|
42
|
-
this.heartbeat = { op: 1, d: null, session_id: '' };
|
|
43
|
-
this.heartbeat_interval = 0;
|
|
44
|
-
// todo: 后续处理 重启后重新建立历史会话
|
|
45
|
-
}
|
|
46
|
-
logger(level, ...args) {
|
|
47
|
-
logger.bot(level, this.appId, ...args);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* post请求
|
|
51
|
-
* @param url 请求地址
|
|
52
|
-
* @param options 请求参数
|
|
53
|
-
*/
|
|
54
|
-
async post(url, options) {
|
|
55
|
-
try {
|
|
56
|
-
return await got.post(url, { json: options, headers: this.headers });
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
logger.error(`[got] 请求错误: ${JSON.stringify(error.response.body)}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* 获取调用凭证
|
|
64
|
-
* @param clientSecret 开发者的Secret
|
|
65
|
-
* @param isRefresh 是否是刷新凭证
|
|
66
|
-
*/
|
|
67
|
-
async getAccessToken(isRefresh = false) {
|
|
68
|
-
if (isRefresh)
|
|
69
|
-
this.logger('debug', '凭证即将过期,开始刷新凭证');
|
|
70
|
-
const url = this.#config.accessTokenApi;
|
|
71
|
-
const data = await got.post(url, {
|
|
72
|
-
json: { appId: this.appId, clientSecret: this.#Secret },
|
|
73
|
-
headers: { 'Content-Type': 'application/json' },
|
|
74
|
-
}).json();
|
|
75
|
-
const { expires_in, access_token } = data;
|
|
76
|
-
this.#access_token = access_token;
|
|
77
|
-
this.headers = { Authorization: `QQBot ${this.#access_token}`, 'X-Union-Appid': `BOT_${this.appId}` };
|
|
78
|
-
this.logger('debug', `凭证获取成功: ${JSON.stringify(data)}`);
|
|
79
|
-
/** 刷新凭证 */
|
|
80
|
-
const time = Number(expires_in) * 1000 - 50000;
|
|
81
|
-
setTimeout(async () => {
|
|
82
|
-
this.getAccessToken(true);
|
|
83
|
-
}, time);
|
|
84
|
-
return data;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* wss鉴权
|
|
88
|
-
* @param isAuth 是否鉴权
|
|
89
|
-
*/
|
|
90
|
-
async wssAuth(isAuth) {
|
|
91
|
-
if (!isAuth) {
|
|
92
|
-
/** 断连后不需要重新ws鉴权 需要恢复登录态 Session */
|
|
93
|
-
const data = {
|
|
94
|
-
op: 6 /* Opcode.Resume */,
|
|
95
|
-
d: {
|
|
96
|
-
token: `QQBot ${this.#access_token}`,
|
|
97
|
-
session_id: this.heartbeat.session_id,
|
|
98
|
-
seq: this.heartbeat.d || 0,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
this.wss.send(JSON.stringify(data));
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const intents = Intents(['GROUP_AT_MESSAGE_CREATE']);
|
|
105
|
-
if (intents === 0)
|
|
106
|
-
throw new Error('intents 无效,请检查传入的事件名称是否正确');
|
|
107
|
-
const data = {
|
|
108
|
-
op: 2 /* Opcode.Identify */,
|
|
109
|
-
d: {
|
|
110
|
-
token: `QQBot ${this.#access_token}`,
|
|
111
|
-
intents,
|
|
112
|
-
shard: [0, 1],
|
|
113
|
-
properties: {
|
|
114
|
-
$os: 'Linux',
|
|
115
|
-
$browser: '@karinjs/adapter-qqbot',
|
|
116
|
-
$device: 'karin',
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
this.wss.send(JSON.stringify(data));
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* 获取wss地址
|
|
124
|
-
*/
|
|
125
|
-
async getWssUrl() {
|
|
126
|
-
const url = `${this.host}/gateway`;
|
|
127
|
-
const data = await got.get(url, { headers: this.headers }).json();
|
|
128
|
-
this.wssUrl = data.url;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* 获取当前Bot信息
|
|
132
|
-
*/
|
|
133
|
-
async getBotInfo() {
|
|
134
|
-
const url = `${this.host}/users/@me`;
|
|
135
|
-
const data = await got.get(url, { headers: this.headers }).json();
|
|
136
|
-
return data;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* 创建wss连接
|
|
140
|
-
*/
|
|
141
|
-
createWss(isAuth = true) {
|
|
142
|
-
this.wss = new WebSocket(this.wssUrl);
|
|
143
|
-
/** 建立连接成功之后 需要鉴权 */
|
|
144
|
-
this.wss.once('open', () => this.wssAuth(isAuth));
|
|
145
|
-
/** 监听事件 */
|
|
146
|
-
this.wss.on('message', (data) => this.payload(data));
|
|
147
|
-
/** 监听ws关闭 */
|
|
148
|
-
this.wss.once('close', () => {
|
|
149
|
-
this.logger('error', 'ws连接关闭,正在重连');
|
|
150
|
-
/** 回收监听器 */
|
|
151
|
-
this.wss.removeAllListeners();
|
|
152
|
-
this.createWss(false);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
payload(payload) {
|
|
156
|
-
const data = JSON.parse(payload);
|
|
157
|
-
this.logger('debug', `收到事件推送: ${JSON.stringify(data, null, 2)}`);
|
|
158
|
-
switch (data.op) {
|
|
159
|
-
case 0:
|
|
160
|
-
this.intents(data);
|
|
161
|
-
this.logger('debug', '事件推送', JSON.stringify(data, null, 2));
|
|
162
|
-
break;
|
|
163
|
-
case 1 /* Opcode.Heartbeat */:
|
|
164
|
-
/** 在指定时间进行回包 */
|
|
165
|
-
this.wss.send(JSON.stringify({ op: 11, d: null }));
|
|
166
|
-
this.logger('debug', '心跳', JSON.stringify(data, null, 2));
|
|
167
|
-
break;
|
|
168
|
-
case 2 /* Opcode.Identify */:
|
|
169
|
-
this.logger('info', '鉴权成功', JSON.stringify(data, null, 2));
|
|
170
|
-
break;
|
|
171
|
-
case 6 /* Opcode.Resume */:
|
|
172
|
-
this.logger('info', '客户端恢复连接', JSON.stringify(data, null, 2));
|
|
173
|
-
break;
|
|
174
|
-
case 7 /* Opcode.Reconnect */:
|
|
175
|
-
this.logger('info', '服务端要求重新连接', JSON.stringify(data, null, 2));
|
|
176
|
-
/** 断开已有ws */
|
|
177
|
-
this.wss.close();
|
|
178
|
-
break;
|
|
179
|
-
case 9 /* Opcode.InvalidSession */:
|
|
180
|
-
/** 当 identify 或 resume 的时候,如果参数有错,服务端会返回该消息 */
|
|
181
|
-
this.logger('error', '参数错误', JSON.stringify(data, null, 2));
|
|
182
|
-
break;
|
|
183
|
-
case 10 /* Opcode.Hello */:
|
|
184
|
-
/** 更新生命周期 对声明周期减少3秒 防止过时 */
|
|
185
|
-
this.heartbeat_interval = data.d.heartbeat_interval - 3000;
|
|
186
|
-
this.logger('debug', '心跳生命周期更新', JSON.stringify(data, null, 2));
|
|
187
|
-
break;
|
|
188
|
-
case 11 /* Opcode.HeartbeatACK */:
|
|
189
|
-
this.logger('debug', '心跳回包', JSON.stringify(data, null, 2));
|
|
190
|
-
break;
|
|
191
|
-
case 12 /* Opcode.HTTPCallbackACK */:
|
|
192
|
-
/** 仅用于 http 回调模式的回包,代表机器人收到了平台推送的数据 */
|
|
193
|
-
this.logger('debug', '回包', JSON.stringify(data, null, 2));
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 事件处理
|
|
199
|
-
*/
|
|
200
|
-
async intents(data) {
|
|
201
|
-
switch (data.t) {
|
|
202
|
-
case "READY" /* EventType.READY */: {
|
|
203
|
-
/** 发送第一次心跳 */
|
|
204
|
-
this.wss.send(JSON.stringify(this.heartbeat));
|
|
205
|
-
/** 更新心跳唯一值 */
|
|
206
|
-
this.heartbeat.d = data.s;
|
|
207
|
-
/** 记录session_id 用于重新连接 */
|
|
208
|
-
this.heartbeat.session_id = data.d.session_id;
|
|
209
|
-
/** 心跳 */
|
|
210
|
-
setInterval(() => this.wss.send(JSON.stringify(this.heartbeat)), this.heartbeat_interval);
|
|
211
|
-
const info = await this.getBotInfo();
|
|
212
|
-
this.avatar = info.avatar;
|
|
213
|
-
this.nick = data.d.user.username;
|
|
214
|
-
this.emit('start');
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
case "GROUP_AT_MESSAGE_CREATE" /* EventType.GROUP_AT_MESSAGE_CREATE */: {
|
|
218
|
-
this.heartbeat.d = data.s;
|
|
219
|
-
this.emit("GROUP_AT_MESSAGE_CREATE" /* EventType.GROUP_AT_MESSAGE_CREATE */, data);
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
case "C2C_MESSAGE_CREATE" /* EventType.C2C_MESSAGE_CREATE */: {
|
|
223
|
-
this.heartbeat.d = data.s;
|
|
224
|
-
this.emit("C2C_MESSAGE_CREATE" /* EventType.C2C_MESSAGE_CREATE */, data);
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
// case 'GUILD_CREATE':
|
|
228
|
-
// case 'GUILD_UPDATE':
|
|
229
|
-
// case 'GUILD_DELETE':
|
|
230
|
-
// case 'CHANNEL_CREATE':
|
|
231
|
-
// case 'CHANNEL_UPDATE':
|
|
232
|
-
// case 'CHANNEL_DELETE':
|
|
233
|
-
// case 'GUILD_MEMBER_ADD':
|
|
234
|
-
// case 'GUILD_MEMBER_UPDATE':
|
|
235
|
-
// case 'GUILD_MEMBER_REMOVE':
|
|
236
|
-
// case 'MESSAGE_CREATE':
|
|
237
|
-
// case 'MESSAGE_DELETE':
|
|
238
|
-
// case 'MESSAGE_REACTION_ADD':
|
|
239
|
-
// case 'MESSAGE_REACTION_REMOVE':
|
|
240
|
-
// case 'DIRECT_MESSAGE_CREATE':
|
|
241
|
-
// case 'DIRECT_MESSAGE_DELETE':
|
|
242
|
-
// case 'FRIEND_ADD':
|
|
243
|
-
// case 'FRIEND_DEL':
|
|
244
|
-
// case 'C2C_MSG_REJECT':
|
|
245
|
-
// case 'C2C_MSG_RECEIVE':
|
|
246
|
-
// case 'GROUP_ADD_ROBOT':
|
|
247
|
-
// case 'GROUP_DEL_ROBOT':
|
|
248
|
-
// case 'GROUP_MSG_REJECT':
|
|
249
|
-
// case 'GROUP_MSG_RECEIVE':
|
|
250
|
-
// case 'INTERACTION_CREATE':
|
|
251
|
-
// case 'MESSAGE_AUDIT_PASS':
|
|
252
|
-
// case 'MESSAGE_AUDIT_REJECT':
|
|
253
|
-
// case 'FORUM_THREAD_CREATE':
|
|
254
|
-
// case 'FORUM_THREAD_UPDATE':
|
|
255
|
-
// case 'FORUM_THREAD_DELETE':
|
|
256
|
-
// case 'FORUM_POST_CREATE':
|
|
257
|
-
// case 'FORUM_POST_DELETE':
|
|
258
|
-
// case 'FORUM_REPLY_CREATE':
|
|
259
|
-
// case 'FORUM_REPLY_DELETE':
|
|
260
|
-
// case 'FORUM_PUBLISH_AUDIT_RESULT':
|
|
261
|
-
// case 'AUDIO_START':
|
|
262
|
-
// case 'AUDIO_FINISH':
|
|
263
|
-
// case 'AUDIO_ON_MIC':
|
|
264
|
-
// case 'AUDIO_OFF_MIC':
|
|
265
|
-
// case 'AT_MESSAGE_CREATE':
|
|
266
|
-
// case 'PUBLIC_MESSAGE_DELETE':
|
|
267
|
-
// case 'RESUMED: {"op":0,"s":53,"t":"RESUMED","d":""} 在客户端恢复连接时收到
|
|
268
|
-
default:
|
|
269
|
-
console.log(`Unhandled event: ${JSON.stringify(data)}`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* 发送消息
|
|
274
|
-
* @param openid 用户、群openid
|
|
275
|
-
* @param type 请求路径类型
|
|
276
|
-
* @param options 请求参数
|
|
277
|
-
*/
|
|
278
|
-
async sendMessage(openid, type, options) {
|
|
279
|
-
const url = this.buildUrl(openid, type, "messages" /* V2ApiType.Message */);
|
|
280
|
-
const result = await this.post(url, options);
|
|
281
|
-
return JSON.parse(result.body);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* 构建发送文本消息请求参数
|
|
285
|
-
*/
|
|
286
|
-
buildText(content, id, seq) {
|
|
287
|
-
const options = {
|
|
288
|
-
content,
|
|
289
|
-
msg_type: 0 /* MessageType.Text */,
|
|
290
|
-
};
|
|
291
|
-
/** id存在 */
|
|
292
|
-
if (id) {
|
|
293
|
-
const { key, value } = this.buildId(id);
|
|
294
|
-
options[key] = value;
|
|
295
|
-
options["msg_seq" /* SeqType.MsgSeq */] = seq;
|
|
296
|
-
}
|
|
297
|
-
return options;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* 上传富媒体文件
|
|
301
|
-
* @param openid 用户、群openid
|
|
302
|
-
* @param type 请求类型
|
|
303
|
-
* @param file 文件内容 http、base64、file://
|
|
304
|
-
* @param file_type 文件类型
|
|
305
|
-
*/
|
|
306
|
-
async uploadMedia(openid, type, file, file_type) {
|
|
307
|
-
const options = await this.buildUploadMedia(file, file_type);
|
|
308
|
-
const url = this.buildUrl(openid, type, "files" /* V2ApiType.Files */);
|
|
309
|
-
return await got.post(url, options).json();
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* 构建v2接口请求地址
|
|
313
|
-
* @param openid 用户、群openid
|
|
314
|
-
* @param type 请求类型
|
|
315
|
-
* @param apiType v2接口类型
|
|
316
|
-
*/
|
|
317
|
-
buildUrl(openid, type, apiType) {
|
|
318
|
-
return `${this.host}/v2/${type}/${openid}/${apiType}`;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* 传入一个msg_id或者event_id 返回其对应的key和value
|
|
322
|
-
* @param id 消息id或者事件id
|
|
323
|
-
*/
|
|
324
|
-
buildId(id) {
|
|
325
|
-
if (id.startsWith(':')) {
|
|
326
|
-
return { key: "event_id" /* IdType.EventID */, value: id };
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
return { key: "msg_id" /* IdType.MsgID */, value: id };
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* 构建发送富媒体请求参数
|
|
334
|
-
* 富媒体消息只能单独发送 并且必须进行上传
|
|
335
|
-
* @param file_info 富媒体接口返回的file_info
|
|
336
|
-
* @param id 消息id或者事件id
|
|
337
|
-
*/
|
|
338
|
-
buildMedia(file_info, id, seq) {
|
|
339
|
-
const options = {
|
|
340
|
-
content: '',
|
|
341
|
-
msg_type: 7 /* MessageType.Media */,
|
|
342
|
-
media: {
|
|
343
|
-
file_info,
|
|
344
|
-
},
|
|
345
|
-
};
|
|
346
|
-
/** id存在 */
|
|
347
|
-
if (id) {
|
|
348
|
-
const { key, value } = this.buildId(id);
|
|
349
|
-
options[key] = value;
|
|
350
|
-
options["msg_seq" /* SeqType.MsgSeq */] = seq;
|
|
351
|
-
}
|
|
352
|
-
return options;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* 构建发送Markdown模板请求参数
|
|
356
|
-
* @param custom_template_id 模板id
|
|
357
|
-
* @param params 模板参数
|
|
358
|
-
* @param id 消息id或者事件id
|
|
359
|
-
* @param seq 消息序号
|
|
360
|
-
*/
|
|
361
|
-
buildTplMarkdown(custom_template_id, params, keyboard, id, seq) {
|
|
362
|
-
const options = {
|
|
363
|
-
msg_type: 2 /* MessageType.Markdown */,
|
|
364
|
-
content: '',
|
|
365
|
-
keyboard,
|
|
366
|
-
markdown: {
|
|
367
|
-
custom_template_id,
|
|
368
|
-
params,
|
|
369
|
-
},
|
|
370
|
-
};
|
|
371
|
-
/** id存在 */
|
|
372
|
-
if (id) {
|
|
373
|
-
const { key, value } = this.buildId(id);
|
|
374
|
-
options[key] = value;
|
|
375
|
-
options["msg_seq" /* SeqType.MsgSeq */] = seq;
|
|
376
|
-
}
|
|
377
|
-
return options;
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* 构建发送原生Markdown请求参数
|
|
381
|
-
* @param content markdown文本
|
|
382
|
-
* @param id 消息id或者事件id
|
|
383
|
-
* @param seq 消息序号
|
|
384
|
-
*/
|
|
385
|
-
buildRawMarkdown(content, keyboard, id, seq) {
|
|
386
|
-
const options = {
|
|
387
|
-
msg_type: 2 /* MessageType.Markdown */,
|
|
388
|
-
content: '',
|
|
389
|
-
markdown: { content },
|
|
390
|
-
keyboard,
|
|
391
|
-
};
|
|
392
|
-
/** id存在 */
|
|
393
|
-
if (id) {
|
|
394
|
-
const { key, value } = this.buildId(id);
|
|
395
|
-
options[key] = value;
|
|
396
|
-
options["msg_seq" /* SeqType.MsgSeq */] = seq;
|
|
397
|
-
}
|
|
398
|
-
return options;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* 构建上传富媒体请求参数
|
|
402
|
-
* @param file 文件内容 http、base64、file://
|
|
403
|
-
* @param file_type 文件类型
|
|
404
|
-
*/
|
|
405
|
-
async buildUploadMedia(file, file_type) {
|
|
406
|
-
/** 非http转base64 */
|
|
407
|
-
if (!file.startsWith('http')) {
|
|
408
|
-
file = await common.base64(file);
|
|
409
|
-
return {
|
|
410
|
-
json: {
|
|
411
|
-
/** 发base64,无前缀 */
|
|
412
|
-
file_data: file,
|
|
413
|
-
file_type,
|
|
414
|
-
srv_send_msg: false,
|
|
415
|
-
},
|
|
416
|
-
headers: this.headers,
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
return {
|
|
420
|
-
json: {
|
|
421
|
-
/** http */
|
|
422
|
-
url: file,
|
|
423
|
-
file_type,
|
|
424
|
-
srv_send_msg: false,
|
|
425
|
-
},
|
|
426
|
-
headers: this.headers,
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
}
|
package/lib/core/index.d.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { QQBotApi } from './api.js';
|
|
2
|
-
import { PathType, C2CMessageCreateEvent, GroupAtMessageCreateEvent } from '../types/index.js';
|
|
3
|
-
import { GlobalCfgType, AccountCfgType } from '../utils/index.js';
|
|
4
|
-
import { Contact, LoggerLevel, ReplyReturn, KarinMessage, KarinAdapter, KarinElement } from 'node-karin';
|
|
5
|
-
/**
|
|
6
|
-
* - QQBot适配器
|
|
7
|
-
*/
|
|
8
|
-
export declare class AdapterQQBot implements KarinAdapter {
|
|
9
|
-
#private;
|
|
10
|
-
super: QQBotApi;
|
|
11
|
-
socket: WebSocket;
|
|
12
|
-
account: KarinAdapter['account'];
|
|
13
|
-
adapter: KarinAdapter['adapter'];
|
|
14
|
-
version: KarinAdapter['version'];
|
|
15
|
-
markdown: GlobalCfgType;
|
|
16
|
-
constructor(config: AccountCfgType);
|
|
17
|
-
init(): Promise<void>;
|
|
18
|
-
_sendNsg(e: KarinMessage, elements: Array<KarinElement>, type: PathType, openid: string, message_id?: string): Promise<ReplyReturn>;
|
|
19
|
-
get self_id(): string;
|
|
20
|
-
logger(level: LoggerLevel, ...args: any[]): void;
|
|
21
|
-
GetVersion(): Promise<{
|
|
22
|
-
name: string;
|
|
23
|
-
app_name: string;
|
|
24
|
-
version: string;
|
|
25
|
-
}>;
|
|
26
|
-
/**
|
|
27
|
-
* QQBot转karin
|
|
28
|
-
* @return karin格式消息
|
|
29
|
-
* */
|
|
30
|
-
AdapterConvertKarin(event: C2CMessageCreateEvent | GroupAtMessageCreateEvent): Array<KarinElement>;
|
|
31
|
-
/**
|
|
32
|
-
* karin转qqbot
|
|
33
|
-
* @param data karin格式消息
|
|
34
|
-
* */
|
|
35
|
-
KarinConvertAdapter(data: Array<KarinElement>, type: PathType, openid: string, message_id?: string): Promise<ReplyReturn>;
|
|
36
|
-
SendMessage(_contact: Contact, elements: Array<KarinElement>): Promise<{
|
|
37
|
-
message_id: string;
|
|
38
|
-
}>;
|
|
39
|
-
getAvatarUrl(user_id: string, size?: number): string;
|
|
40
|
-
getGroupAvatarUrl(): string;
|
|
41
|
-
GetCurrentAccount(): Promise<{
|
|
42
|
-
account_uid: string;
|
|
43
|
-
account_uin: string;
|
|
44
|
-
account_name: string;
|
|
45
|
-
}>;
|
|
46
|
-
GetEssenceMessageList(): Promise<any>;
|
|
47
|
-
DownloadForwardMessage(): Promise<any>;
|
|
48
|
-
SetEssenceMessage(): Promise<any>;
|
|
49
|
-
DeleteEssenceMessage(): Promise<any>;
|
|
50
|
-
SetFriendApplyResult(): Promise<any>;
|
|
51
|
-
SetGroupApplyResult(): Promise<any>;
|
|
52
|
-
SetInvitedJoinGroupResult(): Promise<any>;
|
|
53
|
-
ReactMessageWithEmoji(): Promise<any>;
|
|
54
|
-
UploadPrivateFile(): Promise<any>;
|
|
55
|
-
UploadGroupFile(): Promise<any>;
|
|
56
|
-
UploadForwardMessage(): Promise<any>;
|
|
57
|
-
sendForwardMessage(): Promise<any>;
|
|
58
|
-
SendMessageByResId(): Promise<any>;
|
|
59
|
-
RecallMessage(): Promise<any>;
|
|
60
|
-
GetMessage(): Promise<any>;
|
|
61
|
-
GetHistoryMessage(): Promise<any>;
|
|
62
|
-
VoteUser(): Promise<any>;
|
|
63
|
-
KickMember(): Promise<any>;
|
|
64
|
-
BanMember(): Promise<any>;
|
|
65
|
-
SetGroupWholeBan(): Promise<any>;
|
|
66
|
-
SetGroupAdmin(): Promise<any>;
|
|
67
|
-
ModifyMemberCard(): Promise<any>;
|
|
68
|
-
ModifyGroupName(): Promise<any>;
|
|
69
|
-
LeaveGroup(): Promise<any>;
|
|
70
|
-
SetGroupUniqueTitle(): Promise<any>;
|
|
71
|
-
GetStrangerProfileCard(): Promise<any>;
|
|
72
|
-
GetFriendList(): Promise<any>;
|
|
73
|
-
GetGroupInfo(): Promise<any>;
|
|
74
|
-
GetGroupList(): Promise<any>;
|
|
75
|
-
GetGroupMemberInfo(): Promise<any>;
|
|
76
|
-
GetGroupMemberList(): Promise<any>;
|
|
77
|
-
GetGroupHonor(): Promise<any>;
|
|
78
|
-
DownloadFile(): Promise<any>;
|
|
79
|
-
CreateFolder(): Promise<any>;
|
|
80
|
-
RenameFolder(): Promise<any>;
|
|
81
|
-
DeleteFolde(): Promise<any>;
|
|
82
|
-
DeleteFolder(): Promise<any>;
|
|
83
|
-
UploadFile(): Promise<any>;
|
|
84
|
-
DeleteFile(): Promise<any>;
|
|
85
|
-
GetFileSystemInfo(): Promise<any>;
|
|
86
|
-
GetFileList(): Promise<any>;
|
|
87
|
-
ModifyGroupRemark(): Promise<any>;
|
|
88
|
-
GetRemainCountAtAll(): Promise<any>;
|
|
89
|
-
GetProhibitedUserList(): Promise<any>;
|
|
90
|
-
PokeMember(): Promise<any>;
|
|
91
|
-
SetMessageReaded(): Promise<any>;
|
|
92
|
-
}
|