node-karin 0.8.10 → 0.8.13
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/adapter/index.d.ts +0 -2
- package/lib/adapter/index.js +0 -2
- package/lib/adapter/input/index.js +8 -4
- package/lib/cli/karin.js +2 -1
- package/lib/core/karin.d.ts +37 -4
- package/lib/core/karin.js +35 -4
- package/lib/core/listener.d.ts +2 -1
- package/lib/core/listener.js +23 -2
- package/lib/core/plugin.app.d.ts +1 -0
- package/lib/core/plugin.app.js +1 -0
- package/lib/core/plugin.d.ts +2 -2
- package/lib/core/plugin.loader.js +1 -3
- package/lib/core/server.d.ts +1 -1
- package/lib/core/server.js +0 -3
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/render/client.d.ts +2 -2
- package/lib/render/client.js +1 -1
- package/lib/types/event/event.d.ts +13 -1
- package/lib/types/event/notice.d.ts +1 -1
- package/lib/types/event/notice.js +2 -1
- package/lib/types/event/request.d.ts +1 -1
- package/lib/types/event/request.js +2 -1
- package/lib/types/plugin.d.ts +13 -4
- package/lib/utils/common.d.ts +1 -1
- package/lib/utils/common.js +5 -1
- package/lib/utils/config.js +3 -1
- package/lib/utils/handler.d.ts +2 -2
- package/lib/utils/init.js +1 -3
- package/package.json +7 -6
- package/lib/adapter/kritor/grpc.d.ts +0 -33
- package/lib/adapter/kritor/grpc.js +0 -997
- package/lib/adapter/kritor/index.d.ts +0 -411
- package/lib/adapter/kritor/index.js +0 -1188
- package/lib/modules/grpc-js.d.ts +0 -2
- package/lib/modules/grpc-js.js +0 -2
- package/lib/modules/kritor-proto.d.ts +0 -2
- package/lib/modules/kritor-proto.js +0 -2
- package/lib/modules/proto-loader.d.ts +0 -2
- package/lib/modules/proto-loader.js +0 -2
- package/modules.d.ts +0 -15
- package/modules.js +0 -15
|
@@ -1,1188 +0,0 @@
|
|
|
1
|
-
import { kritor } from 'kritor-proto';
|
|
2
|
-
import { listener } from '../../core/index.js';
|
|
3
|
-
import { logger, config, segment } from '../../utils/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* @extends KarinAdapter
|
|
6
|
-
*/
|
|
7
|
-
export default class AdapterKritor {
|
|
8
|
-
account;
|
|
9
|
-
adapter;
|
|
10
|
-
version;
|
|
11
|
-
/**
|
|
12
|
-
* - gRPC 服务
|
|
13
|
-
*/
|
|
14
|
-
grpc;
|
|
15
|
-
/**
|
|
16
|
-
* - 自增索引
|
|
17
|
-
*/
|
|
18
|
-
seq;
|
|
19
|
-
constructor(
|
|
20
|
-
/**
|
|
21
|
-
* - gRPC 服务
|
|
22
|
-
*/
|
|
23
|
-
grpc, uid, uin) {
|
|
24
|
-
this.account = { uid, uin, name: '' };
|
|
25
|
-
this.adapter = { id: 'QQ', name: 'Kritor', type: 'grpc', sub_type: 'server', start_time: Date.now(), connect: '', index: 0 };
|
|
26
|
-
this.version = { name: '', app_name: '', version: '' };
|
|
27
|
-
this.grpc = grpc;
|
|
28
|
-
/** 自增 */
|
|
29
|
-
this.seq = 0;
|
|
30
|
-
/** 监听响应事件 */
|
|
31
|
-
this.grpc.on('data', data => this.grpc.emit(data.seq, data));
|
|
32
|
-
/** 监听关闭事件 */
|
|
33
|
-
this.grpc.once('end', () => {
|
|
34
|
-
this.logger('warn', '[反向gRPC] 连接已断开');
|
|
35
|
-
this.grpc.removeAllListeners();
|
|
36
|
-
this.adapter.index && listener.delBot(this.adapter.index);
|
|
37
|
-
});
|
|
38
|
-
this.#init();
|
|
39
|
-
}
|
|
40
|
-
get self_id() {
|
|
41
|
-
return this.account.uid || this.account.uin;
|
|
42
|
-
}
|
|
43
|
-
async #init() {
|
|
44
|
-
const { account_name: name } = await this.GetCurrentAccount();
|
|
45
|
-
this.account.name = name;
|
|
46
|
-
const { app_name, version } = await this.GetVersion();
|
|
47
|
-
this.version.name = app_name;
|
|
48
|
-
this.version.app_name = app_name;
|
|
49
|
-
this.version.version = version;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 编码
|
|
53
|
-
* @param service - 服务名
|
|
54
|
-
* @param cmd - 方法名
|
|
55
|
-
* @param type - 类型
|
|
56
|
-
* @param buf - 数据
|
|
57
|
-
*/
|
|
58
|
-
encode(service, cmd, type, buf) {
|
|
59
|
-
buf = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
60
|
-
cmd = `${service}.${cmd}`;
|
|
61
|
-
return { cmd, buf };
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* 解码
|
|
65
|
-
* @param cmd - 服务名.方法名
|
|
66
|
-
* @param type - 类型
|
|
67
|
-
* @param buf - 数据
|
|
68
|
-
*/
|
|
69
|
-
decode(cmd, type, buf) {
|
|
70
|
-
return kritor[type][`${cmd}Response`].decode(buf);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* karin 转 kritor
|
|
74
|
-
* @param data - 消息元素
|
|
75
|
-
*/
|
|
76
|
-
AdapterConvertKarin(data) {
|
|
77
|
-
const elements = [];
|
|
78
|
-
for (const i of data) {
|
|
79
|
-
switch (i.type) {
|
|
80
|
-
/** 文本消息 */
|
|
81
|
-
case kritor.common.Element.ElementType.TEXT: {
|
|
82
|
-
const text = i.text.text;
|
|
83
|
-
elements.push(segment.text(text));
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
/** 艾特消息 */
|
|
87
|
-
case kritor.common.Element.ElementType.AT: {
|
|
88
|
-
const uid = i.at.uid;
|
|
89
|
-
const uin = String(i.at.uin);
|
|
90
|
-
elements.push(segment.at(uid, uin));
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
/** 表情消息 */
|
|
94
|
-
case kritor.common.Element.ElementType.FACE: {
|
|
95
|
-
const face = i.face.id;
|
|
96
|
-
const is_big = i.face.is_big;
|
|
97
|
-
elements.push(segment.face(face, is_big));
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
/** 图片消息 */
|
|
101
|
-
case kritor.common.Element.ElementType.IMAGE: {
|
|
102
|
-
const file_url = i.image.file_url;
|
|
103
|
-
const typeMap = {
|
|
104
|
-
0: 'show',
|
|
105
|
-
1: 'original',
|
|
106
|
-
2: 'flash',
|
|
107
|
-
};
|
|
108
|
-
const options = {
|
|
109
|
-
file_type: typeMap[i.image.file_type || 0],
|
|
110
|
-
name: i.image.file_name || '',
|
|
111
|
-
md5: i.image.file_md5 || '',
|
|
112
|
-
sub_type: String(i.image.sub_type),
|
|
113
|
-
width: undefined,
|
|
114
|
-
height: undefined,
|
|
115
|
-
};
|
|
116
|
-
elements.push(segment.image(file_url, options));
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
/** 弹射表情 */
|
|
120
|
-
case kritor.common.Element.ElementType.BUBBLE_FACE: {
|
|
121
|
-
const id = i.bubble_face.id;
|
|
122
|
-
const count = i.bubble_face.count;
|
|
123
|
-
elements.push(segment.bubble_face(id, count));
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
/** 回复消息 */
|
|
127
|
-
case kritor.common.Element.ElementType.REPLY: {
|
|
128
|
-
const message_id = i.reply.message_id;
|
|
129
|
-
elements.push(segment.reply(message_id));
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
/** 语音消息 */
|
|
133
|
-
case kritor.common.Element.ElementType.VOICE: {
|
|
134
|
-
const file = i.voice.file_url;
|
|
135
|
-
const magic = i.voice.magic;
|
|
136
|
-
const md5 = i.voice.file_md5;
|
|
137
|
-
const name = i.voice.file_name;
|
|
138
|
-
elements.push(segment.record(file, magic, md5, name));
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
/** 视频消息 */
|
|
142
|
-
case kritor.common.Element.ElementType.VIDEO: {
|
|
143
|
-
const file = i.video.file_url;
|
|
144
|
-
const md5 = i.video.file_md5;
|
|
145
|
-
const name = i.video.file_name;
|
|
146
|
-
elements.push(segment.video(file, md5, name));
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
/** 篮球消息 */
|
|
150
|
-
case kritor.common.Element.ElementType.BASKETBALL: {
|
|
151
|
-
const id = i.basketball.id;
|
|
152
|
-
elements.push(segment.basketball(id));
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
/** 骰子消息 */
|
|
156
|
-
case kritor.common.Element.ElementType.DICE: {
|
|
157
|
-
const id = i.dice.id;
|
|
158
|
-
elements.push(segment.dice(id));
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
case kritor.common.Element.ElementType.RPS: {
|
|
162
|
-
const id = i.rps.id;
|
|
163
|
-
elements.push(segment.rps(id));
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
/** 戳一戳消息 */
|
|
167
|
-
case kritor.common.Element.ElementType.POKE: {
|
|
168
|
-
const id = i.poke.id;
|
|
169
|
-
const poke_type = i.poke.poke_type;
|
|
170
|
-
const strength = i.poke.strength;
|
|
171
|
-
elements.push(segment.poke(id, poke_type, strength));
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
/** 音乐消息 */
|
|
175
|
-
case kritor.common.Element.ElementType.MUSIC: {
|
|
176
|
-
const id = i.music.id;
|
|
177
|
-
const custom = i.music.custom;
|
|
178
|
-
const { url, audio, title, author, pic } = custom;
|
|
179
|
-
elements.push(segment.customMusic(url, audio, title, author, pic, id));
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
/** 天气消息 */
|
|
183
|
-
case kritor.common.Element.ElementType.WEATHER: {
|
|
184
|
-
const city = i.weather.city;
|
|
185
|
-
const code = i.weather.code;
|
|
186
|
-
elements.push(segment.weather(city, code));
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
/** 位置消息 */
|
|
190
|
-
case kritor.common.Element.ElementType.LOCATION: {
|
|
191
|
-
const lat = i.location.lat;
|
|
192
|
-
const lon = i.location.lon;
|
|
193
|
-
const title = i.location.title;
|
|
194
|
-
const address = i.location.address;
|
|
195
|
-
elements.push(segment.location(lat, lon, title, address));
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
/** 链接分享 */
|
|
199
|
-
case kritor.common.Element.ElementType.SHARE: {
|
|
200
|
-
const url = i.share.url;
|
|
201
|
-
const title = i.share.title;
|
|
202
|
-
const content = i.share.content;
|
|
203
|
-
const image = i.share.image;
|
|
204
|
-
elements.push(segment.share(url, title, content, image));
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
/** 礼物消息 只收不发 */
|
|
208
|
-
case kritor.common.Element.ElementType.GIFT: {
|
|
209
|
-
const qq = Number(i.gift.qq);
|
|
210
|
-
const id = Number(i.gift.id);
|
|
211
|
-
elements.push(segment.gift(qq, id));
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
/** 转发消息 */
|
|
215
|
-
case kritor.common.Element.ElementType.FORWARD: {
|
|
216
|
-
const res_id = i.forward.res_id;
|
|
217
|
-
const uniseq = i.forward.uniseq;
|
|
218
|
-
const summary = i.forward.summary;
|
|
219
|
-
const description = i.forward.description;
|
|
220
|
-
elements.push(segment.forward(res_id, uniseq, summary, description));
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
/** 文件消息 收不到 文件为通知事件 不走这里 */
|
|
224
|
-
case kritor.common.Element.ElementType.FILE: {
|
|
225
|
-
// const file_url = (i.file as kritor.common.IFileElement).file_url as string
|
|
226
|
-
// elements.push(new KarinFileElement(i.file.file_url))
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
/** JSON消息 */
|
|
230
|
-
case kritor.common.Element.ElementType.JSON: {
|
|
231
|
-
const json = i.json.json;
|
|
232
|
-
elements.push(segment.json(json));
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
/** XML消息 */
|
|
236
|
-
case kritor.common.Element.ElementType.XML: {
|
|
237
|
-
const xml = i.xml.xml;
|
|
238
|
-
elements.push(segment.xml(xml));
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
// 这都啥玩意啊...
|
|
242
|
-
case kritor.common.Element.ElementType.MARKET_FACE:
|
|
243
|
-
case kritor.common.Element.ElementType.CONTACT:
|
|
244
|
-
case kritor.common.Element.ElementType.MARKDOWN:
|
|
245
|
-
case kritor.common.Element.ElementType.KEYBOARD:
|
|
246
|
-
default: {
|
|
247
|
-
let { ...args } = i;
|
|
248
|
-
args = JSON.stringify(args);
|
|
249
|
-
logger.warn(`未知消息类型 ${i.type} ${args}`);
|
|
250
|
-
elements.push(segment.text(args));
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return elements;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* karin 转 kritor
|
|
258
|
-
*/
|
|
259
|
-
KarinConvertAdapter(elements) {
|
|
260
|
-
const _elements = [];
|
|
261
|
-
// const ElementType = kritor.common.Element.ElementType
|
|
262
|
-
for (const i of elements) {
|
|
263
|
-
switch (i.type) {
|
|
264
|
-
case 'text': {
|
|
265
|
-
// const { TEXT: type } = ElementType
|
|
266
|
-
const text = i.text;
|
|
267
|
-
_elements.push(new kritor.common.TextElement({ text }));
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
case 'image': {
|
|
271
|
-
// const { IMAGE: type } = ElementType
|
|
272
|
-
const file = i.file;
|
|
273
|
-
_elements.push(new kritor.common.ImageElement({ file }));
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case 'at': {
|
|
277
|
-
// const { AT: type } = ElementType
|
|
278
|
-
const { uid, uin = '' } = i;
|
|
279
|
-
_elements.push(new kritor.common.AtElement({ uid, uin: Number(uin) }));
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case 'face': {
|
|
283
|
-
// const { FACE: type } = ElementType
|
|
284
|
-
const { id, is_big = false } = i;
|
|
285
|
-
_elements.push(new kritor.common.FaceElement({ id, is_big }));
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
case 'reply': {
|
|
289
|
-
// const { REPLY: type } = ElementType
|
|
290
|
-
const { message_id } = i;
|
|
291
|
-
_elements.push(new kritor.common.ReplyElement({ message_id }));
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
case 'voice': {
|
|
295
|
-
// const { VOICE: type } = ElementType
|
|
296
|
-
const file = i.file;
|
|
297
|
-
_elements.push(new kritor.common.VoiceElement({ file }));
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
return _elements;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* 发送消息
|
|
306
|
-
* @param contact - 联系人
|
|
307
|
-
* @param elements - 消息元素
|
|
308
|
-
* @param retry_count - 重试次数
|
|
309
|
-
*/
|
|
310
|
-
async SendMessage(contact, elements, retry_count = 1) {
|
|
311
|
-
/**
|
|
312
|
-
* - 请求服务名
|
|
313
|
-
*/
|
|
314
|
-
const service = 'MessageService';
|
|
315
|
-
/**
|
|
316
|
-
* - 请求方法名
|
|
317
|
-
*/
|
|
318
|
-
const cmd = 'SendMessage';
|
|
319
|
-
/**
|
|
320
|
-
* - 请求类型
|
|
321
|
-
*/
|
|
322
|
-
const type = 'message';
|
|
323
|
-
const message = this.KarinConvertAdapter(elements);
|
|
324
|
-
const buf = { contact: contact, elements: message, retry_count };
|
|
325
|
-
/**
|
|
326
|
-
* 请求编码
|
|
327
|
-
*/
|
|
328
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
329
|
-
/**
|
|
330
|
-
* 请求命令名
|
|
331
|
-
*/
|
|
332
|
-
const command = `${service}.${cmd}`;
|
|
333
|
-
/**
|
|
334
|
-
* 发送请求
|
|
335
|
-
*/
|
|
336
|
-
const res = await this.SendApi(command, data);
|
|
337
|
-
/**
|
|
338
|
-
* 响应解码
|
|
339
|
-
*/
|
|
340
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
341
|
-
return {
|
|
342
|
-
message_id: response.message_id,
|
|
343
|
-
message_time: Number(response.message_time),
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* 撤回消息
|
|
348
|
-
* @param contact - 联系人
|
|
349
|
-
* @param message_id - 消息ID
|
|
350
|
-
*/
|
|
351
|
-
async RecallMessage(contact, message_id) {
|
|
352
|
-
const service = 'MessageService';
|
|
353
|
-
const cmd = 'RecallMessage';
|
|
354
|
-
const type = 'message';
|
|
355
|
-
const buf = { contact: contact, message_id };
|
|
356
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
357
|
-
const command = `${service}.${cmd}`;
|
|
358
|
-
const res = await this.SendApi(command, data);
|
|
359
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
360
|
-
return response;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* 设置消息评论表情
|
|
364
|
-
* @param contact - 联系人
|
|
365
|
-
* @param message_id - 消息ID
|
|
366
|
-
* @param face_id - 表情ID
|
|
367
|
-
* @param is_set - 是否设置
|
|
368
|
-
*/
|
|
369
|
-
async ReactMessageWithEmoji(contact, message_id, face_id, is_set) {
|
|
370
|
-
const service = 'MessageService';
|
|
371
|
-
const cmd = 'ReactMessageWithEmoji';
|
|
372
|
-
const type = 'message';
|
|
373
|
-
const buf = { contact: contact, message_id, face_id, is_set };
|
|
374
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
375
|
-
const command = `${service}.${cmd}`;
|
|
376
|
-
const res = await this.SendApi(command, data);
|
|
377
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
378
|
-
return response;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* 获取msg_id获取消息
|
|
382
|
-
* @param contact - 联系人
|
|
383
|
-
* @param message_id - 消息ID
|
|
384
|
-
*/
|
|
385
|
-
async GetMessage(contact, message_id) {
|
|
386
|
-
const service = 'MessageService';
|
|
387
|
-
const cmd = 'GetMessage';
|
|
388
|
-
const type = 'message';
|
|
389
|
-
const buf = { contact: contact, message_id };
|
|
390
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
391
|
-
const command = `${service}.${cmd}`;
|
|
392
|
-
const res = await this.SendApi(command, data);
|
|
393
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
394
|
-
const message = response.message;
|
|
395
|
-
return {
|
|
396
|
-
time: Number(message.time),
|
|
397
|
-
message_id: String(message.message_id),
|
|
398
|
-
message_seq: Number(message.message_seq),
|
|
399
|
-
contact: message.contact,
|
|
400
|
-
sender: message.sender,
|
|
401
|
-
elements: this.AdapterConvertKarin(message.elements),
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* 通过seq获取消息
|
|
406
|
-
* @param contact - 联系人
|
|
407
|
-
* @param message_seq - 消息seq
|
|
408
|
-
*/
|
|
409
|
-
async GetMessageBySeq(contact, message_seq) {
|
|
410
|
-
const service = 'MessageService';
|
|
411
|
-
const cmd = 'GetMessageBySeq';
|
|
412
|
-
const type = 'message';
|
|
413
|
-
const buf = { contact: contact, message_seq };
|
|
414
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
415
|
-
const command = `${service}.${cmd}`;
|
|
416
|
-
const res = await this.SendApi(command, data);
|
|
417
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
418
|
-
return response;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* 获取msg_id获取历史消息
|
|
422
|
-
* @param contact - 联系人
|
|
423
|
-
* @param start_message_id - 开始消息ID
|
|
424
|
-
* @param count - 数量
|
|
425
|
-
*/
|
|
426
|
-
async GetHistoryMessage(contact, start_message_id, count) {
|
|
427
|
-
const service = 'MessageService';
|
|
428
|
-
const cmd = 'GetHistoryMessage';
|
|
429
|
-
const type = 'message';
|
|
430
|
-
const buf = { contact: contact, start_message_id, count };
|
|
431
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
432
|
-
const command = `${service}.${cmd}`;
|
|
433
|
-
const res = await this.SendApi(command, data);
|
|
434
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
435
|
-
return response;
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* 通过seq获取历史消息
|
|
439
|
-
* @param contact - 联系人
|
|
440
|
-
* @param start_message_seq - 开始消息seq
|
|
441
|
-
* @param count - 数量
|
|
442
|
-
*/
|
|
443
|
-
async GetHistoryMessageBySeq(contact, start_message_seq, count) {
|
|
444
|
-
const service = 'MessageService';
|
|
445
|
-
const cmd = 'GetHistoryMessageBySeq';
|
|
446
|
-
const type = 'message';
|
|
447
|
-
const buf = { contact: contact, start_message_seq, count };
|
|
448
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
449
|
-
const command = `${service}.${cmd}`;
|
|
450
|
-
const res = await this.SendApi(command, data);
|
|
451
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
452
|
-
return response;
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* 清空本地聊天记录
|
|
456
|
-
* @param contact - 联系人
|
|
457
|
-
*/
|
|
458
|
-
async SetMessageReaded(contact) {
|
|
459
|
-
const service = 'MessageService';
|
|
460
|
-
const cmd = 'SetMessageRead';
|
|
461
|
-
const type = 'message';
|
|
462
|
-
const buf = { contact: contact };
|
|
463
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
464
|
-
const command = `${service}.${cmd}`;
|
|
465
|
-
const res = await this.SendApi(command, data);
|
|
466
|
-
kritor[type][`${cmd}Response`].decode(res.buf);
|
|
467
|
-
return true;
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* 上传合并转发消息
|
|
471
|
-
* @param contact - 联系人
|
|
472
|
-
* @param elements - 消息
|
|
473
|
-
* @param retry_count - 重试次数
|
|
474
|
-
*/
|
|
475
|
-
async UploadForwardMessage(contact, elements, retry_count = 1) {
|
|
476
|
-
const service = 'MessageService';
|
|
477
|
-
const cmd = 'UploadForwardMessage';
|
|
478
|
-
const type = 'message';
|
|
479
|
-
if (service)
|
|
480
|
-
throw new Error('service is required');
|
|
481
|
-
// todo 这里格式不对 要改成转发消息的格式
|
|
482
|
-
const messages = this.KarinConvertAdapter(elements);
|
|
483
|
-
const buf = { contact: contact, messages, retry_count };
|
|
484
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
485
|
-
const command = `${service}.${cmd}`;
|
|
486
|
-
const res = await this.SendApi(command, data);
|
|
487
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
488
|
-
return response;
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* 下载合并转发消息
|
|
492
|
-
* @param res_id - 资源ID
|
|
493
|
-
*/
|
|
494
|
-
async DownloadForwardMessage(res_id) {
|
|
495
|
-
const service = 'MessageService';
|
|
496
|
-
const cmd = 'DownloadForwardMessage';
|
|
497
|
-
const type = 'message';
|
|
498
|
-
const buf = { res_id };
|
|
499
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
500
|
-
const command = `${service}.${cmd}`;
|
|
501
|
-
const res = await this.SendApi(command, data);
|
|
502
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
503
|
-
return response;
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* 获取精华消息
|
|
507
|
-
* @param group_id - 群组ID
|
|
508
|
-
* @param page - 页码
|
|
509
|
-
* @param page_size - 每页数量
|
|
510
|
-
*/
|
|
511
|
-
async GetEssenceMessageList(group_id, page, page_size) {
|
|
512
|
-
const service = 'MessageService';
|
|
513
|
-
const cmd = 'GetEssenceMessageList';
|
|
514
|
-
const type = 'message';
|
|
515
|
-
const buf = { group_id: Number(group_id), page, page_size };
|
|
516
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
517
|
-
const command = `${service}.${cmd}`;
|
|
518
|
-
const res = await this.SendApi(command, data);
|
|
519
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
520
|
-
return response;
|
|
521
|
-
}
|
|
522
|
-
/** 设置精华消息 */
|
|
523
|
-
async SetEssenceMessage(group_id, message_id) {
|
|
524
|
-
const service = 'MessageService';
|
|
525
|
-
const cmd = 'SetEssenceMessage';
|
|
526
|
-
const type = 'message';
|
|
527
|
-
const buf = { group_id: Number(group_id), message_id };
|
|
528
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
529
|
-
const command = `${service}.${cmd}`;
|
|
530
|
-
const res = await this.SendApi(command, data);
|
|
531
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
532
|
-
return response;
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* 删除精华消息
|
|
536
|
-
* @param group_id - 群组ID
|
|
537
|
-
* @param message_id - 消息ID
|
|
538
|
-
*/
|
|
539
|
-
async DeleteEssenceMessage(group_id, message_id) {
|
|
540
|
-
const service = 'MessageService';
|
|
541
|
-
const cmd = 'DeleteEssenceMessage';
|
|
542
|
-
const type = 'message';
|
|
543
|
-
const buf = { group_id: Number(group_id), message_id };
|
|
544
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
545
|
-
const command = `${service}.${cmd}`;
|
|
546
|
-
const res = await this.SendApi(command, data);
|
|
547
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
548
|
-
return response;
|
|
549
|
-
}
|
|
550
|
-
logger(level, ...args) {
|
|
551
|
-
logger.bot(level, this.account.uin, ...args);
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* 获取用户头像
|
|
555
|
-
* @param {string} uid - 用户id,默认为发送者uid
|
|
556
|
-
* @param {number} [size] - 头像大小,默认`0`
|
|
557
|
-
* @returns {string} - 头像的url地址
|
|
558
|
-
*/
|
|
559
|
-
getAvatarUrl(uid, size = 0) {
|
|
560
|
-
return `https://q1.qlogo.cn/g?b=qq&s=${size}&nk=` + uid;
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* 获取群头像
|
|
564
|
-
* @param group_id - 群号
|
|
565
|
-
* @param size - 头像大小,默认`0`
|
|
566
|
-
* @param history - 历史头像记录,默认`0`,若要获取历史群头像则填写1,2,3...
|
|
567
|
-
* @returns - 群头像的url地址
|
|
568
|
-
*/
|
|
569
|
-
getGroupAvatar(group_id, size = 0, history = 0) {
|
|
570
|
-
return `https://p.qlogo.cn/gh/${group_id}/${group_id}${history ? '_' + history : ''}/` + size;
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* 获取Kritor版本
|
|
574
|
-
*/
|
|
575
|
-
async GetVersion() {
|
|
576
|
-
const service = 'CoreService';
|
|
577
|
-
const cmd = 'GetVersion';
|
|
578
|
-
const type = 'core';
|
|
579
|
-
const buf = {};
|
|
580
|
-
const command = `${service}.${cmd}`;
|
|
581
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
582
|
-
const res = await this.SendApi(command, data);
|
|
583
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
584
|
-
return response;
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* 让Kritor下载文件到Kritor本地
|
|
588
|
-
* @param file - 文件地址
|
|
589
|
-
* @param file_type - 文件类型
|
|
590
|
-
* @param root_path - 文件保存路径
|
|
591
|
-
* @param file_name - 文件名
|
|
592
|
-
* @param thread_cnt - 线程数
|
|
593
|
-
* @param headers - 请求头
|
|
594
|
-
* @returns - 下载文件的响应
|
|
595
|
-
*/
|
|
596
|
-
async DownloadFile(options) {
|
|
597
|
-
const { file, file_type, root_path = '', file_name = '', thread_cnt = 1, headers = '' } = options;
|
|
598
|
-
const service = 'CoreService';
|
|
599
|
-
const cmd = 'DownloadFile';
|
|
600
|
-
const type = 'core';
|
|
601
|
-
const buf = { [file_type]: file, root_path, file_name, thread_cnt, headers };
|
|
602
|
-
const command = `${service}.${cmd}`;
|
|
603
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
604
|
-
const res = await this.SendApi(command, data);
|
|
605
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
606
|
-
return response;
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* 获取当前账户的信息
|
|
610
|
-
*/
|
|
611
|
-
async GetCurrentAccount() {
|
|
612
|
-
const service = 'CoreService';
|
|
613
|
-
const cmd = 'GetCurrentAccount';
|
|
614
|
-
const type = 'core';
|
|
615
|
-
const buf = {};
|
|
616
|
-
const command = `${service}.${cmd}`;
|
|
617
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
618
|
-
const res = await this.SendApi(command, data);
|
|
619
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
620
|
-
const karinRes = { ...response, account_uin: response.account_uin + '' };
|
|
621
|
-
return karinRes;
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* 获取好友列表
|
|
625
|
-
* @param refresh - 是否刷新缓存
|
|
626
|
-
*/
|
|
627
|
-
async GetFriendList(refresh) {
|
|
628
|
-
const service = 'FriendService';
|
|
629
|
-
const cmd = 'GetFriendList';
|
|
630
|
-
const type = 'friend';
|
|
631
|
-
const buf = { refresh };
|
|
632
|
-
const command = `${service}.${cmd}`;
|
|
633
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
634
|
-
const res = await this.SendApi(command, data);
|
|
635
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
636
|
-
return response;
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* 获取好友名片信息
|
|
640
|
-
* @param options - 好友名片信息选项
|
|
641
|
-
*/
|
|
642
|
-
async GetFriendProfileCard(options) {
|
|
643
|
-
const service = 'FriendService';
|
|
644
|
-
const cmd = 'GetFriendProfileCard';
|
|
645
|
-
const type = 'friend';
|
|
646
|
-
const buf = options;
|
|
647
|
-
const command = `${service}.${cmd}`;
|
|
648
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
649
|
-
const res = await this.SendApi(command, data);
|
|
650
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
651
|
-
return response;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* 获取陌生人信息
|
|
655
|
-
* @param target_uid_or_uin - 目标用户的 uid 或者 uin 数组
|
|
656
|
-
*/
|
|
657
|
-
async GetStrangerProfileCard(target_uid_or_uin) {
|
|
658
|
-
const service = 'FriendService';
|
|
659
|
-
const cmd = 'GetStrangerProfileCard';
|
|
660
|
-
const type = 'friend';
|
|
661
|
-
const buf = { target_uins: [], target_uids: [] };
|
|
662
|
-
target_uid_or_uin.forEach(v => Number(v) ? buf.target_uins.push(Number(v)) : buf.target_uids.push(v));
|
|
663
|
-
const command = `${service}.${cmd}`;
|
|
664
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
665
|
-
const res = await this.SendApi(command, data);
|
|
666
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
667
|
-
return response;
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* 设置自己的名片
|
|
671
|
-
* @param options - 名片信息选项
|
|
672
|
-
*/
|
|
673
|
-
async SetProfileCard(options) {
|
|
674
|
-
const service = 'FriendService';
|
|
675
|
-
const cmd = 'SetProfileCard';
|
|
676
|
-
const type = 'friend';
|
|
677
|
-
const buf = options || {};
|
|
678
|
-
const command = `${service}.${cmd}`;
|
|
679
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
680
|
-
const res = await this.SendApi(command, data);
|
|
681
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
682
|
-
return response;
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* 判断是否是黑名单用户
|
|
686
|
-
* @param target_uid - 目标用户的 uid
|
|
687
|
-
* @param target_uin - 目标用户的 uin
|
|
688
|
-
*/
|
|
689
|
-
async IsBlackListUser(target_uid, target_uin) {
|
|
690
|
-
const service = 'FriendService';
|
|
691
|
-
const cmd = 'IsBlackListUser';
|
|
692
|
-
const type = 'friend';
|
|
693
|
-
const buf = { target_uid, target_uin: Number(target_uin) };
|
|
694
|
-
const command = `${service}.${cmd}`;
|
|
695
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
696
|
-
const res = await this.SendApi(command, data);
|
|
697
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
698
|
-
return response;
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* 点赞好友
|
|
702
|
-
* @param target_uid_or_uin - 目标用户的 uid 或者 uin
|
|
703
|
-
* @param vote_count - 点赞数量
|
|
704
|
-
*/
|
|
705
|
-
async VoteUser(target_uid_or_uin, vote_count) {
|
|
706
|
-
const service = 'FriendService';
|
|
707
|
-
const cmd = 'VoteUser';
|
|
708
|
-
const type = 'friend';
|
|
709
|
-
let buf = {};
|
|
710
|
-
if (Number(target_uid_or_uin)) {
|
|
711
|
-
buf = { target_uin: Number(target_uid_or_uin), vote_count };
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
buf = { target_uid: target_uid_or_uin, vote_count };
|
|
715
|
-
}
|
|
716
|
-
const command = `${service}.${cmd}`;
|
|
717
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
718
|
-
const res = await this.SendApi(command, data);
|
|
719
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
720
|
-
return response;
|
|
721
|
-
}
|
|
722
|
-
/**
|
|
723
|
-
* 根据 uin 获取 uid
|
|
724
|
-
* @param target_uins - 目标用户的 uin 数组
|
|
725
|
-
*/
|
|
726
|
-
async GetUidByUin(target_uins) {
|
|
727
|
-
const service = 'FriendService';
|
|
728
|
-
const cmd = 'GetUidByUin';
|
|
729
|
-
const type = 'friend';
|
|
730
|
-
const buf = { target_uins };
|
|
731
|
-
const command = `${service}.${cmd}`;
|
|
732
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
733
|
-
const res = await this.SendApi(command, data);
|
|
734
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
735
|
-
return response;
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* 根据 uid 获取 uin
|
|
739
|
-
* @param target_uids - 目标用户的 uid 数组
|
|
740
|
-
*/
|
|
741
|
-
async GetUinByUid(target_uids) {
|
|
742
|
-
const service = 'FriendService';
|
|
743
|
-
const cmd = 'GetUinByUid';
|
|
744
|
-
const type = 'friend';
|
|
745
|
-
const buf = { target_uids };
|
|
746
|
-
const command = `${service}.${cmd}`;
|
|
747
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
748
|
-
const res = await this.SendApi(command, data);
|
|
749
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
750
|
-
return response;
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
* 禁言用户
|
|
754
|
-
* @param group_id - 群组ID
|
|
755
|
-
* @param target_uid_or_uin - 被禁言目标的 uid 任选其一
|
|
756
|
-
* @param duration - 禁言时长 单位秒
|
|
757
|
-
*/
|
|
758
|
-
async BanMember(group_id, target_uid_or_uin, duration) {
|
|
759
|
-
const service = 'GroupService';
|
|
760
|
-
const cmd = 'BanMember';
|
|
761
|
-
const type = 'group';
|
|
762
|
-
let buf = {};
|
|
763
|
-
if (Number(target_uid_or_uin)) {
|
|
764
|
-
buf = { group_id, target_uin: Number(target_uid_or_uin), duration };
|
|
765
|
-
}
|
|
766
|
-
else {
|
|
767
|
-
buf = { group_id, target_uid: target_uid_or_uin, duration };
|
|
768
|
-
}
|
|
769
|
-
const command = `${service}.${cmd}`;
|
|
770
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
771
|
-
const res = await this.SendApi(command, data);
|
|
772
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
773
|
-
return response;
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* 戳一戳用户头像
|
|
777
|
-
* @param options - 戳一戳选项
|
|
778
|
-
*/
|
|
779
|
-
async PokeMember(group_id, target_uid_or_uin) {
|
|
780
|
-
const service = 'GroupService';
|
|
781
|
-
const cmd = 'PokeMember';
|
|
782
|
-
const type = 'group';
|
|
783
|
-
let buf = {};
|
|
784
|
-
if (Number(target_uid_or_uin)) {
|
|
785
|
-
buf = { group_id, target_uin: Number(target_uid_or_uin) };
|
|
786
|
-
}
|
|
787
|
-
else {
|
|
788
|
-
buf = { group_id, target_uid: target_uid_or_uin };
|
|
789
|
-
}
|
|
790
|
-
const command = `${service}.${cmd}`;
|
|
791
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
792
|
-
const res = await this.SendApi(command, data);
|
|
793
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
794
|
-
return response;
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* 群组踢人
|
|
798
|
-
* @param group_id - 群组ID
|
|
799
|
-
* @param target_uid_or_uin - 被踢目标的 uid、uin 任选其一
|
|
800
|
-
* @param reject_add_request - 是否拒绝再次入群请求
|
|
801
|
-
* @param kick_reason - 踢人原因
|
|
802
|
-
*/
|
|
803
|
-
async KickMember(group_id, target_uid_or_uin, reject_add_request, kick_reason) {
|
|
804
|
-
const service = 'GroupService';
|
|
805
|
-
const cmd = 'KickMember';
|
|
806
|
-
const type = 'group';
|
|
807
|
-
let buf = {};
|
|
808
|
-
if (Number(target_uid_or_uin)) {
|
|
809
|
-
buf = { group_id, target_uin: Number(target_uid_or_uin), reject_add_request, kick_reason };
|
|
810
|
-
}
|
|
811
|
-
else {
|
|
812
|
-
buf = { group_id, target_uid: target_uid_or_uin, reject_add_request, kick_reason };
|
|
813
|
-
}
|
|
814
|
-
const command = `${service}.${cmd}`;
|
|
815
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
816
|
-
const res = await this.SendApi(command, data);
|
|
817
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
818
|
-
return response;
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* 退出群组
|
|
822
|
-
* @param group_id - 群组ID
|
|
823
|
-
*/
|
|
824
|
-
async LeaveGroup(group_id) {
|
|
825
|
-
const service = 'GroupService';
|
|
826
|
-
const cmd = 'LeaveGroup';
|
|
827
|
-
const type = 'group';
|
|
828
|
-
const buf = { group_id: Number(group_id) };
|
|
829
|
-
const command = `${service}.${cmd}`;
|
|
830
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
831
|
-
const res = await this.SendApi(command, data);
|
|
832
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
833
|
-
return response;
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* 修改群名片
|
|
837
|
-
* @param group_id - 群组ID
|
|
838
|
-
* @param target_uid_or_uin - 目标用户的 uid、uin 任选其一
|
|
839
|
-
* @param card - 新的群名片
|
|
840
|
-
*/
|
|
841
|
-
async ModifyMemberCard(group_id, target_uid_or_uin, card) {
|
|
842
|
-
const service = 'GroupService';
|
|
843
|
-
const cmd = 'ModifyMemberCard';
|
|
844
|
-
const type = 'group';
|
|
845
|
-
let buf = {};
|
|
846
|
-
if (Number(target_uid_or_uin)) {
|
|
847
|
-
buf = { group_id, target_uin: Number(target_uid_or_uin), card };
|
|
848
|
-
}
|
|
849
|
-
else {
|
|
850
|
-
buf = { group_id, target_uid: target_uid_or_uin, card };
|
|
851
|
-
}
|
|
852
|
-
const command = `${service}.${cmd}`;
|
|
853
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
854
|
-
const res = await this.SendApi(command, data);
|
|
855
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
856
|
-
return response;
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* 修改群名称
|
|
860
|
-
* @param group_id - 群组ID
|
|
861
|
-
* @param group_name - 新的群名称
|
|
862
|
-
*/
|
|
863
|
-
async ModifyGroupName(group_id, group_name) {
|
|
864
|
-
const service = 'GroupService';
|
|
865
|
-
const cmd = 'ModifyGroupName';
|
|
866
|
-
const type = 'group';
|
|
867
|
-
const buf = { group_id: Number(group_id), group_name };
|
|
868
|
-
const command = `${service}.${cmd}`;
|
|
869
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
870
|
-
const res = await this.SendApi(command, data);
|
|
871
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
872
|
-
return response;
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* 修改群备注
|
|
876
|
-
* @param group_id - 群组ID
|
|
877
|
-
* @param remark - 新的群备注
|
|
878
|
-
*/
|
|
879
|
-
async ModifyGroupRemark(group_id, remark) {
|
|
880
|
-
const service = 'GroupService';
|
|
881
|
-
const cmd = 'ModifyGroupRemark';
|
|
882
|
-
const type = 'group';
|
|
883
|
-
const buf = { group_id: Number(group_id), remark };
|
|
884
|
-
const command = `${service}.${cmd}`;
|
|
885
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
886
|
-
const res = await this.SendApi(command, data);
|
|
887
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
888
|
-
return response;
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* 设置群管理员
|
|
892
|
-
* @param group_id - 群组ID
|
|
893
|
-
* @param target_uid_or_uin - 目标用户的 uid、uin 任选其一
|
|
894
|
-
* @param is_admin - 是否设置为管理员
|
|
895
|
-
*/
|
|
896
|
-
async SetGroupAdmin(group_id, target_uid_or_uin, is_admin) {
|
|
897
|
-
const service = 'GroupService';
|
|
898
|
-
const cmd = 'SetGroupAdmin';
|
|
899
|
-
const type = 'group';
|
|
900
|
-
let buf = {};
|
|
901
|
-
if (Number(target_uid_or_uin)) {
|
|
902
|
-
buf = { group_id, target_uin: Number(target_uid_or_uin), is_admin };
|
|
903
|
-
}
|
|
904
|
-
else {
|
|
905
|
-
buf = { group_id, target_uid: target_uid_or_uin, is_admin };
|
|
906
|
-
}
|
|
907
|
-
const command = `${service}.${cmd}`;
|
|
908
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
909
|
-
const res = await this.SendApi(command, data);
|
|
910
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
911
|
-
return response;
|
|
912
|
-
}
|
|
913
|
-
/**
|
|
914
|
-
* 设置群头衔
|
|
915
|
-
* @param group_id - 群组ID
|
|
916
|
-
* @param target_uid_or_uin - 目标用户的 uid、uin 任选其一
|
|
917
|
-
* @param special_title - 新的群头衔
|
|
918
|
-
*/
|
|
919
|
-
async SetGroupUniqueTitle(group_id, target_uid_or_uin, unique_title) {
|
|
920
|
-
const service = 'GroupService';
|
|
921
|
-
const cmd = 'SetGroupUniqueTitle';
|
|
922
|
-
const type = 'group';
|
|
923
|
-
let buf = {};
|
|
924
|
-
if (Number(target_uid_or_uin)) {
|
|
925
|
-
buf = { group_id, target_uin: Number(target_uid_or_uin), unique_title };
|
|
926
|
-
}
|
|
927
|
-
else {
|
|
928
|
-
buf = { group_id, target_uid: target_uid_or_uin, unique_title };
|
|
929
|
-
}
|
|
930
|
-
const command = `${service}.${cmd}`;
|
|
931
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
932
|
-
const res = await this.SendApi(command, data);
|
|
933
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
934
|
-
return response;
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* 设置全员禁言
|
|
938
|
-
* @param group_id - 群组ID
|
|
939
|
-
* @param is_ban - 是否全员禁言
|
|
940
|
-
*/
|
|
941
|
-
async SetGroupWholeBan(group_id, is_ban) {
|
|
942
|
-
const service = 'GroupService';
|
|
943
|
-
const cmd = 'SetGroupWholeBan';
|
|
944
|
-
const type = 'group';
|
|
945
|
-
const buf = { group_id: Number(group_id), is_ban };
|
|
946
|
-
const command = `${service}.${cmd}`;
|
|
947
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
948
|
-
const res = await this.SendApi(command, data);
|
|
949
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
950
|
-
return response;
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* 获取群信息
|
|
954
|
-
* @param group_id - 群组ID
|
|
955
|
-
* @param no_cache - 是否刷新缓存
|
|
956
|
-
*/
|
|
957
|
-
async GetGroupInfo(group_id, no_cache = false) {
|
|
958
|
-
const service = 'GroupService';
|
|
959
|
-
const cmd = 'GetGroupInfo';
|
|
960
|
-
const type = 'group';
|
|
961
|
-
const buf = { group_id: Number(group_id), no_cache };
|
|
962
|
-
const command = `${service}.${cmd}`;
|
|
963
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
964
|
-
const res = await this.SendApi(command, data);
|
|
965
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
966
|
-
return response;
|
|
967
|
-
}
|
|
968
|
-
/**
|
|
969
|
-
* 获取群列表
|
|
970
|
-
* @param refresh - 是否刷新缓存
|
|
971
|
-
*/
|
|
972
|
-
async GetGroupList(refresh = false) {
|
|
973
|
-
const service = 'GroupService';
|
|
974
|
-
const cmd = 'GetGroupList';
|
|
975
|
-
const type = 'group';
|
|
976
|
-
const buf = { refresh };
|
|
977
|
-
const command = `${service}.${cmd}`;
|
|
978
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
979
|
-
const res = await this.SendApi(command, data);
|
|
980
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
981
|
-
return response;
|
|
982
|
-
}
|
|
983
|
-
/**
|
|
984
|
-
* 获取群成员信息
|
|
985
|
-
* @param group_id - 群组ID
|
|
986
|
-
* @param target_uid_or_uin - 目标用户的 uid、uin 任选其一
|
|
987
|
-
* @param refresh - 是否刷新缓存
|
|
988
|
-
*/
|
|
989
|
-
async GetGroupMemberInfo(group_id, target_uid_or_uin, refresh = false) {
|
|
990
|
-
const service = 'GroupService';
|
|
991
|
-
const cmd = 'GetGroupMemberInfo';
|
|
992
|
-
const type = 'group';
|
|
993
|
-
let buf = {};
|
|
994
|
-
if (Number(target_uid_or_uin)) {
|
|
995
|
-
buf = { group_id, target_uin: Number(target_uid_or_uin), refresh };
|
|
996
|
-
}
|
|
997
|
-
else {
|
|
998
|
-
buf = { group_id, target_uid: target_uid_or_uin, refresh };
|
|
999
|
-
}
|
|
1000
|
-
const command = `${service}.${cmd}`;
|
|
1001
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1002
|
-
const res = await this.SendApi(command, data);
|
|
1003
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1004
|
-
return response;
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* 获取群成员列表
|
|
1008
|
-
* @param group_id - 群组ID
|
|
1009
|
-
* @param refresh - 是否刷新缓存
|
|
1010
|
-
*/
|
|
1011
|
-
async GetGroupMemberList(group_id, refresh = false) {
|
|
1012
|
-
const service = 'GroupService';
|
|
1013
|
-
const cmd = 'GetGroupMemberList';
|
|
1014
|
-
const type = 'group';
|
|
1015
|
-
const buf = { group_id: Number(group_id), refresh };
|
|
1016
|
-
const command = `${service}.${cmd}`;
|
|
1017
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1018
|
-
const res = await this.SendApi(command, data);
|
|
1019
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1020
|
-
return response;
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* 获取禁言用户列表
|
|
1024
|
-
* @param group_id - 群组ID
|
|
1025
|
-
*/
|
|
1026
|
-
async GetProhibitedUserList(group_id) {
|
|
1027
|
-
const service = 'GroupService';
|
|
1028
|
-
const cmd = 'GetProhibitedUserList';
|
|
1029
|
-
const type = 'group';
|
|
1030
|
-
const buf = { group_id: Number(group_id) };
|
|
1031
|
-
const command = `${service}.${cmd}`;
|
|
1032
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1033
|
-
const res = await this.SendApi(command, data);
|
|
1034
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1035
|
-
return response;
|
|
1036
|
-
}
|
|
1037
|
-
/**
|
|
1038
|
-
* 获取艾特全体成员剩余次数
|
|
1039
|
-
* @param group_id - 群组ID
|
|
1040
|
-
*/
|
|
1041
|
-
async GetRemainCountAtAll(group_id) {
|
|
1042
|
-
const service = 'GroupService';
|
|
1043
|
-
const cmd = 'GetRemainCountAtAll';
|
|
1044
|
-
const type = 'group';
|
|
1045
|
-
const buf = { group_id: Number(group_id) };
|
|
1046
|
-
const command = `${service}.${cmd}`;
|
|
1047
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1048
|
-
const res = await this.SendApi(command, data);
|
|
1049
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1050
|
-
return response;
|
|
1051
|
-
}
|
|
1052
|
-
/**
|
|
1053
|
-
* 获取群荣誉信息
|
|
1054
|
-
* @param group_id - 群组ID
|
|
1055
|
-
* @param refresh - 是否刷新缓存
|
|
1056
|
-
* @returns - 群荣誉信息
|
|
1057
|
-
*/
|
|
1058
|
-
async GetGroupHonor(group_id, refresh = false) {
|
|
1059
|
-
const service = 'GroupService';
|
|
1060
|
-
const cmd = 'GetGroupHonor';
|
|
1061
|
-
const type = 'group';
|
|
1062
|
-
const buf = { group_id: Number(group_id), refresh };
|
|
1063
|
-
const command = `${service}.${cmd}`;
|
|
1064
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1065
|
-
const res = await this.SendApi(command, data);
|
|
1066
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1067
|
-
return response;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* 获取未加入群组信息
|
|
1071
|
-
* @param group_id - 群组ID
|
|
1072
|
-
*/
|
|
1073
|
-
async GetNotJoinedGroupInfo(group_id) {
|
|
1074
|
-
const service = 'GroupService';
|
|
1075
|
-
const cmd = 'GetNotJoinedGroupInfo';
|
|
1076
|
-
const type = 'group';
|
|
1077
|
-
const buf = { group_id: Number(group_id) };
|
|
1078
|
-
const command = `${service}.${cmd}`;
|
|
1079
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1080
|
-
const res = await this.SendApi(command, data);
|
|
1081
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1082
|
-
return response;
|
|
1083
|
-
}
|
|
1084
|
-
/**
|
|
1085
|
-
* 设置好友请求结果
|
|
1086
|
-
* @param request_id - 请求ID
|
|
1087
|
-
* @param is_approve - 是否同意
|
|
1088
|
-
* @param remark - 好友备注 同意时有效
|
|
1089
|
-
* @returns
|
|
1090
|
-
*/
|
|
1091
|
-
async SetFriendApplyResult(request_id, is_approve, remark) {
|
|
1092
|
-
const service = 'FriendService';
|
|
1093
|
-
const cmd = 'SetFriendApplyResult';
|
|
1094
|
-
const type = 'process';
|
|
1095
|
-
const buf = { request_id, is_approve, remark };
|
|
1096
|
-
const command = `${service}.${cmd}`;
|
|
1097
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1098
|
-
const res = await this.SendApi(command, data);
|
|
1099
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1100
|
-
return response;
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* 设置申请加入群请求结果
|
|
1104
|
-
* @param request_id - 请求ID
|
|
1105
|
-
* @param is_approve - 是否同意
|
|
1106
|
-
* @param deny_reason - 拒绝原因
|
|
1107
|
-
*/
|
|
1108
|
-
async SetGroupApplyResult(request_id, is_approve, deny_reason) {
|
|
1109
|
-
const service = 'GroupService';
|
|
1110
|
-
const cmd = 'SetGroupApplyResult';
|
|
1111
|
-
const type = 'process';
|
|
1112
|
-
const buf = { request_id, is_approve, deny_reason };
|
|
1113
|
-
const command = `${service}.${cmd}`;
|
|
1114
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1115
|
-
const res = await this.SendApi(command, data);
|
|
1116
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1117
|
-
return response;
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* 设置邀请加入群请求结果
|
|
1121
|
-
* @param request_id - 请求ID
|
|
1122
|
-
* @param is_approve - 是否同意
|
|
1123
|
-
*/
|
|
1124
|
-
async SetInvitedJoinGroupResult(request_id, is_approve) {
|
|
1125
|
-
const service = 'GroupService';
|
|
1126
|
-
const cmd = 'SetInvitedJoinGroupResult';
|
|
1127
|
-
const type = 'process';
|
|
1128
|
-
const buf = { request_id, is_approve };
|
|
1129
|
-
const command = `${service}.${cmd}`;
|
|
1130
|
-
const data = kritor[type][`${cmd}Request`].encode(buf).finish();
|
|
1131
|
-
const res = await this.SendApi(command, data);
|
|
1132
|
-
const response = kritor[type][`${cmd}Response`].decode(res.buf);
|
|
1133
|
-
return response;
|
|
1134
|
-
}
|
|
1135
|
-
CreateFolder() { throw new Error('Method not implemented.'); }
|
|
1136
|
-
RenameFolder() { throw new Error('Method not implemented.'); }
|
|
1137
|
-
DeleteFolder() { throw new Error('Method not implemented.'); }
|
|
1138
|
-
UploadFile() { throw new Error('Method not implemented.'); }
|
|
1139
|
-
DeleteFile() { throw new Error('Method not implemented.'); }
|
|
1140
|
-
GetFileSystemInfo() { throw new Error('Method not implemented.'); }
|
|
1141
|
-
GetFileList() { throw new Error('Method not implemented.'); }
|
|
1142
|
-
async SendMessageByResId(contact, id) {
|
|
1143
|
-
if (contact)
|
|
1144
|
-
throw new Error('不支持的操作');
|
|
1145
|
-
return '未实现';
|
|
1146
|
-
}
|
|
1147
|
-
async sendForwardMessage(contact, elements) {
|
|
1148
|
-
if (contact)
|
|
1149
|
-
throw new Error('未实现');
|
|
1150
|
-
return '未实现';
|
|
1151
|
-
}
|
|
1152
|
-
async UploadGroupFile(group_id, file, name, folder) {
|
|
1153
|
-
if (group_id)
|
|
1154
|
-
throw new Error('未实现');
|
|
1155
|
-
return '未实现';
|
|
1156
|
-
}
|
|
1157
|
-
async UploadPrivateFile(user_id, file, name) {
|
|
1158
|
-
if (user_id)
|
|
1159
|
-
throw new Error('未实现');
|
|
1160
|
-
return '未实现';
|
|
1161
|
-
}
|
|
1162
|
-
/**
|
|
1163
|
-
* 发送Api请求 返回未解码的数据
|
|
1164
|
-
* @param cmd - cmd的构成由 服务名 + "." + 方法名
|
|
1165
|
-
* @param buf - 请求参数
|
|
1166
|
-
* @param time - 请求超时时间 默认10s
|
|
1167
|
-
*/
|
|
1168
|
-
SendApi(cmd, buf, time = 60) {
|
|
1169
|
-
this.seq++;
|
|
1170
|
-
const seq = this.seq;
|
|
1171
|
-
if (!time)
|
|
1172
|
-
time = config.timeout('grpc');
|
|
1173
|
-
// ps: 我也不想写any啊 可是这里它不符合啊!!!
|
|
1174
|
-
const params = { cmd, seq, buf };
|
|
1175
|
-
logger.debug(`[API请求] ${cmd} seq: ${seq} buf: ${JSON.stringify(buf)}`);
|
|
1176
|
-
return new Promise((resolve, reject) => {
|
|
1177
|
-
const timeoutId = setTimeout(() => {
|
|
1178
|
-
reject(new Error('API请求超时'));
|
|
1179
|
-
}, time * 1000);
|
|
1180
|
-
this.grpc.write(params);
|
|
1181
|
-
this.grpc.once(seq + '', data => {
|
|
1182
|
-
/** 停止计时器 */
|
|
1183
|
-
clearTimeout(timeoutId);
|
|
1184
|
-
data.code === 'SUCCESS' ? resolve(data) : resolve(data);
|
|
1185
|
-
});
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
|
-
}
|