@alemonjs/kook 2.1.0-alpha.0 → 2.1.0-alpha.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/README.md +5 -2
- package/dist/assets/index.css +1 -0
- package/dist/assets/index.js +34 -0
- package/dist/index.html +15 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.js +1 -1
- package/lib/core/config.js +2 -1
- package/lib/desktop.js +3 -2
- package/lib/hook.d.ts +2 -2
- package/lib/hook.js +2 -2
- package/lib/index.d.ts +3 -4
- package/lib/index.js +107 -70
- package/lib/sdk/api.d.ts +1 -2
- package/lib/sdk/api.js +34 -30
- package/lib/sdk/conversation.js +26 -26
- package/lib/sdk/instance.js +109 -0
- package/lib/sdk/typings.d.ts +1 -1
- package/lib/sdk/wss.js +18 -10
- package/package.json +4 -1
package/lib/desktop.js
CHANGED
|
@@ -20,7 +20,7 @@ const activate = context => {
|
|
|
20
20
|
const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
|
|
21
21
|
// 确保路径存在
|
|
22
22
|
const html = readFileSync(dir, 'utf-8')
|
|
23
|
-
.replace(iconReg,
|
|
23
|
+
.replace(iconReg, '')
|
|
24
24
|
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
|
25
25
|
.replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
|
|
26
26
|
// 立即渲染 webview
|
|
@@ -42,8 +42,9 @@ const activate = context => {
|
|
|
42
42
|
}
|
|
43
43
|
else if (data.type === 'kook.init') {
|
|
44
44
|
let config = getConfigValue();
|
|
45
|
-
if (!config)
|
|
45
|
+
if (!config) {
|
|
46
46
|
config = {};
|
|
47
|
+
}
|
|
47
48
|
// 发送消息
|
|
48
49
|
webView.postMessage({
|
|
49
50
|
type: 'kook.init',
|
package/lib/hook.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventKeys, Events } from 'alemonjs';
|
|
2
|
-
import API from 'node-telegram-bot-api';
|
|
3
2
|
import { EventData } from './sdk/typings.js';
|
|
3
|
+
import { KOOKAPI } from './sdk/api.js';
|
|
4
4
|
|
|
5
5
|
type MAP = {
|
|
6
6
|
'message.create': EventData;
|
|
@@ -33,6 +33,6 @@ declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP
|
|
|
33
33
|
* @param event
|
|
34
34
|
* @returns
|
|
35
35
|
*/
|
|
36
|
-
declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [
|
|
36
|
+
declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [KOOKAPI, MAP[T]];
|
|
37
37
|
|
|
38
38
|
export { useClient, useValue };
|
package/lib/hook.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEventValue, useClient as useClient$1 } from 'alemonjs';
|
|
2
|
-
import
|
|
2
|
+
import { KOOKAPI } from './sdk/api.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -16,7 +16,7 @@ const useValue = (event) => {
|
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
18
|
const useClient = (event) => {
|
|
19
|
-
const [client] = useClient$1(event,
|
|
19
|
+
const [client] = useClient$1(event, KOOKAPI);
|
|
20
20
|
const value = createEventValue(event);
|
|
21
21
|
return [client, value];
|
|
22
22
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { useClient, useValue } from './hook.js';
|
|
2
|
+
export { Options, platform } from './config.js';
|
|
2
3
|
export { KOOKAPI as API } from './sdk/api.js';
|
|
3
4
|
|
|
4
|
-
declare const
|
|
5
|
+
declare const main: () => void;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export { _default as default, platform };
|
|
7
|
+
export { main as default };
|
package/lib/index.js
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
export { KOOKAPI as API } from './sdk/api.js';
|
|
3
3
|
import { KOOKClient } from './sdk/wss.js';
|
|
4
4
|
import { readFileSync } from 'fs';
|
|
5
|
-
import { getMaster } from './config.js';
|
|
5
|
+
import { getKOOKConfig, getMaster, platform } from './config.js';
|
|
6
6
|
import { getBufferByURL } from 'alemonjs/utils';
|
|
7
7
|
export { useClient, useValue } from './hook.js';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
let value = getConfigValue();
|
|
12
|
-
if (!value)
|
|
13
|
-
value = {};
|
|
14
|
-
const config = value[platform];
|
|
9
|
+
const main = () => {
|
|
10
|
+
const config = getKOOKConfig();
|
|
15
11
|
// 创建客户端
|
|
16
12
|
const client = new KOOKClient({
|
|
17
13
|
token: config.token
|
|
18
14
|
});
|
|
19
15
|
// 连接
|
|
20
|
-
client.connect();
|
|
21
|
-
const
|
|
16
|
+
void client.connect();
|
|
17
|
+
const port = process.env?.port || 17117;
|
|
18
|
+
const url = `ws://127.0.0.1:${port}`;
|
|
22
19
|
const cbp = cbpPlatform(url);
|
|
23
20
|
client.on('MESSAGES_DIRECT', async (event) => {
|
|
24
21
|
// 过滤机器人
|
|
25
|
-
if (event.extra?.author?.bot)
|
|
22
|
+
if (event.extra?.author?.bot) {
|
|
26
23
|
return false;
|
|
24
|
+
}
|
|
27
25
|
// 创建私聊标记
|
|
28
26
|
const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
|
|
29
27
|
// 头像
|
|
30
28
|
const avatar = event.extra.author.avatar;
|
|
31
29
|
// 获取消息
|
|
32
|
-
|
|
30
|
+
const msg = event.content;
|
|
33
31
|
const url = avatar.substring(0, avatar.indexOf('?'));
|
|
34
32
|
const UserAvatar = url;
|
|
35
33
|
const UserId = event.author_id;
|
|
@@ -60,8 +58,9 @@ var index = () => {
|
|
|
60
58
|
// 监听消息
|
|
61
59
|
client.on('MESSAGES_PUBLIC', async (event) => {
|
|
62
60
|
// 过滤机器人
|
|
63
|
-
if (event.extra?.author?.bot)
|
|
61
|
+
if (event.extra?.author?.bot) {
|
|
64
62
|
return false;
|
|
63
|
+
}
|
|
65
64
|
// 创建私聊标记
|
|
66
65
|
const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
|
|
67
66
|
// 头像
|
|
@@ -124,40 +123,38 @@ var index = () => {
|
|
|
124
123
|
* @returns
|
|
125
124
|
*/
|
|
126
125
|
const sendChannel = async (target_id, val) => {
|
|
127
|
-
if (val.length < 0)
|
|
126
|
+
if (val.length < 0) {
|
|
128
127
|
return Promise.all([]);
|
|
128
|
+
}
|
|
129
129
|
const content = val
|
|
130
|
-
.filter(item => item.type
|
|
130
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text')
|
|
131
131
|
.map(item => {
|
|
132
|
-
if (item.type
|
|
133
|
-
if (item.value
|
|
134
|
-
|
|
135
|
-
item.value == '' ||
|
|
136
|
-
typeof item.value != 'string') {
|
|
137
|
-
return `(met)all(met)`;
|
|
132
|
+
if (item.type === 'Mention') {
|
|
133
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
134
|
+
return '(met)all(met)';
|
|
138
135
|
}
|
|
139
|
-
if (item.options?.belong
|
|
136
|
+
if (item.options?.belong === 'user') {
|
|
140
137
|
return `(met)${item.value}(met)`;
|
|
141
138
|
}
|
|
142
|
-
else if (item.options?.belong
|
|
139
|
+
else if (item.options?.belong === 'channel') {
|
|
143
140
|
return `(chn)${item.value}(chn)`;
|
|
144
141
|
}
|
|
145
142
|
return '';
|
|
146
143
|
}
|
|
147
|
-
else if (item.type
|
|
148
|
-
if (item.options?.style
|
|
144
|
+
else if (item.type === 'Text') {
|
|
145
|
+
if (item.options?.style === 'block') {
|
|
149
146
|
return `\`${item.value}\``;
|
|
150
147
|
}
|
|
151
|
-
else if (item.options?.style
|
|
148
|
+
else if (item.options?.style === 'italic') {
|
|
152
149
|
return `*${item.value}*`;
|
|
153
150
|
}
|
|
154
|
-
else if (item.options?.style
|
|
151
|
+
else if (item.options?.style === 'bold') {
|
|
155
152
|
return `**${item.value}**`;
|
|
156
153
|
}
|
|
157
|
-
else if (item.options?.style
|
|
154
|
+
else if (item.options?.style === 'strikethrough') {
|
|
158
155
|
return `~~${item.value}~~`;
|
|
159
156
|
}
|
|
160
|
-
else if (item.options?.style
|
|
157
|
+
else if (item.options?.style === 'boldItalic') {
|
|
161
158
|
return `***${item.value}***`;
|
|
162
159
|
}
|
|
163
160
|
return item.value;
|
|
@@ -173,32 +170,36 @@ var index = () => {
|
|
|
173
170
|
});
|
|
174
171
|
return [createResult(ResultCode.Ok, 'client.createMessage', res)];
|
|
175
172
|
}
|
|
176
|
-
const images = val.filter(item => item.type
|
|
173
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
177
174
|
if (images.length > 0) {
|
|
178
175
|
let bufferData = null;
|
|
179
176
|
for (let i = 0; i < images.length; i++) {
|
|
180
|
-
if (bufferData)
|
|
177
|
+
if (bufferData) {
|
|
181
178
|
break;
|
|
179
|
+
}
|
|
182
180
|
const item = images[i];
|
|
183
|
-
if (item.type
|
|
181
|
+
if (item.type === 'Image') {
|
|
184
182
|
bufferData = Buffer.from(item.value, 'base64');
|
|
185
183
|
}
|
|
186
|
-
else if (item.type
|
|
184
|
+
else if (item.type === 'ImageURL') {
|
|
187
185
|
bufferData = await getBufferByURL(item.value);
|
|
188
186
|
}
|
|
189
|
-
else if (item.type
|
|
187
|
+
else if (item.type === 'ImageFile') {
|
|
190
188
|
bufferData = readFileSync(item.value);
|
|
191
189
|
}
|
|
192
190
|
}
|
|
193
|
-
if (!bufferData)
|
|
191
|
+
if (!bufferData) {
|
|
194
192
|
return [];
|
|
193
|
+
}
|
|
195
194
|
// 上传图片
|
|
196
195
|
const imageRes = await client.postImage(bufferData);
|
|
197
|
-
if (!imageRes)
|
|
196
|
+
if (!imageRes) {
|
|
198
197
|
return [];
|
|
198
|
+
}
|
|
199
199
|
const url = imageRes.data?.url;
|
|
200
|
-
if (!url)
|
|
200
|
+
if (!url) {
|
|
201
201
|
return [];
|
|
202
|
+
}
|
|
202
203
|
// 发送消息
|
|
203
204
|
const res = await client.createMessage({
|
|
204
205
|
type: 2,
|
|
@@ -220,40 +221,38 @@ var index = () => {
|
|
|
220
221
|
* @returns
|
|
221
222
|
*/
|
|
222
223
|
const sendUser = async (open_id, val) => {
|
|
223
|
-
if (val.length < 0)
|
|
224
|
+
if (val.length < 0) {
|
|
224
225
|
return [];
|
|
226
|
+
}
|
|
225
227
|
const content = val
|
|
226
|
-
.filter(item => item.type
|
|
228
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text')
|
|
227
229
|
.map(item => {
|
|
228
|
-
if (item.type
|
|
229
|
-
if (item.value
|
|
230
|
-
|
|
231
|
-
item.value == '' ||
|
|
232
|
-
typeof item.value != 'string') {
|
|
233
|
-
return `(met)all(met)`;
|
|
230
|
+
if (item.type === 'Mention') {
|
|
231
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
232
|
+
return '(met)all(met)';
|
|
234
233
|
}
|
|
235
|
-
if (item.options?.belong
|
|
234
|
+
if (item.options?.belong === 'user') {
|
|
236
235
|
return `(met)${item.value}(met)`;
|
|
237
236
|
}
|
|
238
|
-
else if (item.options?.belong
|
|
237
|
+
else if (item.options?.belong === 'channel') {
|
|
239
238
|
return `(chn)${item.value}(chn)`;
|
|
240
239
|
}
|
|
241
240
|
return '';
|
|
242
241
|
}
|
|
243
|
-
else if (item.type
|
|
244
|
-
if (item.options?.style
|
|
242
|
+
else if (item.type === 'Text') {
|
|
243
|
+
if (item.options?.style === 'block') {
|
|
245
244
|
return `\`${item.value}\``;
|
|
246
245
|
}
|
|
247
|
-
else if (item.options?.style
|
|
246
|
+
else if (item.options?.style === 'italic') {
|
|
248
247
|
return `*${item.value}*`;
|
|
249
248
|
}
|
|
250
|
-
else if (item.options?.style
|
|
249
|
+
else if (item.options?.style === 'bold') {
|
|
251
250
|
return `**${item.value}**`;
|
|
252
251
|
}
|
|
253
|
-
else if (item.options?.style
|
|
252
|
+
else if (item.options?.style === 'strikethrough') {
|
|
254
253
|
return `~~${item.value}~~`;
|
|
255
254
|
}
|
|
256
|
-
else if (item.options?.style
|
|
255
|
+
else if (item.options?.style === 'boldItalic') {
|
|
257
256
|
return `***${item.value}***`;
|
|
258
257
|
}
|
|
259
258
|
return item.value;
|
|
@@ -269,32 +268,36 @@ var index = () => {
|
|
|
269
268
|
});
|
|
270
269
|
return [createResult(ResultCode.Ok, 'client.createDirectMessage', res)];
|
|
271
270
|
}
|
|
272
|
-
const images = val.filter(item => item.type
|
|
271
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
273
272
|
if (images.length > 0) {
|
|
274
273
|
let bufferData = null;
|
|
275
274
|
for (let i = 0; i < images.length; i++) {
|
|
276
|
-
if (bufferData)
|
|
275
|
+
if (bufferData) {
|
|
277
276
|
break;
|
|
277
|
+
}
|
|
278
278
|
const item = images[i];
|
|
279
|
-
if (item.type
|
|
279
|
+
if (item.type === 'Image') {
|
|
280
280
|
bufferData = Buffer.from(item.value, 'base64');
|
|
281
281
|
}
|
|
282
|
-
else if (item.type
|
|
282
|
+
else if (item.type === 'ImageURL') {
|
|
283
283
|
bufferData = await getBufferByURL(item.value);
|
|
284
284
|
}
|
|
285
|
-
else if (item.type
|
|
285
|
+
else if (item.type === 'ImageFile') {
|
|
286
286
|
bufferData = readFileSync(item.value);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
if (!bufferData)
|
|
289
|
+
if (!bufferData) {
|
|
290
290
|
return [];
|
|
291
|
+
}
|
|
291
292
|
// 上传图片
|
|
292
293
|
const imageRes = await client.postImage(bufferData);
|
|
293
|
-
if (!imageRes)
|
|
294
|
+
if (!imageRes) {
|
|
294
295
|
return [];
|
|
296
|
+
}
|
|
295
297
|
const url = imageRes.data?.url;
|
|
296
|
-
if (!url)
|
|
298
|
+
if (!url) {
|
|
297
299
|
return [];
|
|
300
|
+
}
|
|
298
301
|
const res = await client.createDirectMessage({
|
|
299
302
|
type: 2,
|
|
300
303
|
chat_code: open_id,
|
|
@@ -330,17 +333,18 @@ var index = () => {
|
|
|
330
333
|
},
|
|
331
334
|
use: {
|
|
332
335
|
send: async (event, val) => {
|
|
333
|
-
if (val.length < 0)
|
|
336
|
+
if (val.length < 0) {
|
|
334
337
|
return [];
|
|
335
|
-
|
|
338
|
+
}
|
|
339
|
+
if (event.name === 'message.create') {
|
|
336
340
|
return await sendChannel(event.ChannelId, val);
|
|
337
341
|
}
|
|
338
|
-
else if (event.name
|
|
342
|
+
else if (event.name === 'private.message.create') {
|
|
339
343
|
return await sendUser(event.OpenId, val);
|
|
340
344
|
}
|
|
341
345
|
return [];
|
|
342
346
|
},
|
|
343
|
-
mention:
|
|
347
|
+
mention: e => {
|
|
344
348
|
const event = e.value;
|
|
345
349
|
const MessageMention = [];
|
|
346
350
|
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
|
|
@@ -367,11 +371,13 @@ var index = () => {
|
|
|
367
371
|
IsBot: false
|
|
368
372
|
});
|
|
369
373
|
}
|
|
370
|
-
return
|
|
374
|
+
return new Promise(resolve => {
|
|
375
|
+
resolve(MessageMention);
|
|
376
|
+
});
|
|
371
377
|
}
|
|
372
378
|
}
|
|
373
379
|
};
|
|
374
|
-
|
|
380
|
+
const onactions = async (data, consume) => {
|
|
375
381
|
if (data.action === 'message.send') {
|
|
376
382
|
const event = data.payload.event;
|
|
377
383
|
const paramFormat = data.payload.params.format;
|
|
@@ -407,8 +413,9 @@ var index = () => {
|
|
|
407
413
|
const res = await api.use.mention(event);
|
|
408
414
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
409
415
|
}
|
|
410
|
-
}
|
|
411
|
-
cbp.
|
|
416
|
+
};
|
|
417
|
+
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
418
|
+
const onapis = async (data, consume) => {
|
|
412
419
|
const key = data.payload?.key;
|
|
413
420
|
if (client[key]) {
|
|
414
421
|
// 如果 client 上有对应的 key,直接调用。
|
|
@@ -416,7 +423,37 @@ var index = () => {
|
|
|
416
423
|
const res = await client[key](...params);
|
|
417
424
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
418
425
|
}
|
|
426
|
+
};
|
|
427
|
+
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
428
|
+
};
|
|
429
|
+
const mainProcess = () => {
|
|
430
|
+
['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
|
|
431
|
+
process?.on?.(sig, () => {
|
|
432
|
+
logger?.info?.(`[alemonjs][${sig}] 收到信号,正在关闭...`);
|
|
433
|
+
setImmediate(() => process.exit(0));
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
process?.on?.('exit', code => {
|
|
437
|
+
logger?.info?.(`[alemonjs][exit] 进程退出,code=${code}`);
|
|
438
|
+
});
|
|
439
|
+
// 监听主进程消息
|
|
440
|
+
process.on('message', msg => {
|
|
441
|
+
try {
|
|
442
|
+
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
443
|
+
if (data?.type === 'start') {
|
|
444
|
+
main();
|
|
445
|
+
}
|
|
446
|
+
else if (data?.type === 'stop') {
|
|
447
|
+
process.exit(0);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch { }
|
|
419
451
|
});
|
|
452
|
+
// 主动发送 ready 消息
|
|
453
|
+
if (process.send) {
|
|
454
|
+
process.send(JSON.stringify({ type: 'ready' }));
|
|
455
|
+
}
|
|
420
456
|
};
|
|
457
|
+
mainProcess();
|
|
421
458
|
|
|
422
|
-
export {
|
|
459
|
+
export { main as default, platform };
|
package/lib/sdk/api.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as axios from 'axios';
|
|
2
1
|
import { AxiosRequestConfig } from 'axios';
|
|
3
2
|
import { Readable } from 'stream';
|
|
4
3
|
import { SendMessageParams, SendDirectMessageParams } from './typings.js';
|
|
@@ -12,7 +11,7 @@ declare class KOOKAPI {
|
|
|
12
11
|
* @param config
|
|
13
12
|
* @returns
|
|
14
13
|
*/
|
|
15
|
-
service(opstoin: AxiosRequestConfig): Promise<
|
|
14
|
+
service(opstoin: AxiosRequestConfig): Promise<any>;
|
|
16
15
|
/**
|
|
17
16
|
*
|
|
18
17
|
* @returns
|
package/lib/sdk/api.js
CHANGED
|
@@ -3,6 +3,7 @@ import FormData from 'form-data';
|
|
|
3
3
|
import { ApiEnum } from './typings.js';
|
|
4
4
|
import { config } from './config.js';
|
|
5
5
|
import { createPicFrom } from 'alemonjs/utils';
|
|
6
|
+
import { createAxiosInstance } from './instance.js';
|
|
6
7
|
|
|
7
8
|
const API_URL = 'https://www.kookapp.cn';
|
|
8
9
|
/**
|
|
@@ -23,20 +24,20 @@ class KOOKAPI {
|
|
|
23
24
|
Authorization: `Bot ${token}`
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
|
-
return req
|
|
27
|
+
return createAxiosInstance(req, opstoin);
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
*
|
|
30
31
|
* @returns
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
gateway() {
|
|
33
34
|
return this.service({
|
|
34
35
|
baseURL: 'https://www.kookapp.cn/api/v3/gateway/index',
|
|
35
36
|
method: 'get',
|
|
36
37
|
params: {
|
|
37
38
|
compress: 0
|
|
38
39
|
}
|
|
39
|
-
})
|
|
40
|
+
});
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* ************
|
|
@@ -54,14 +55,16 @@ class KOOKAPI {
|
|
|
54
55
|
image: file,
|
|
55
56
|
name: Name
|
|
56
57
|
});
|
|
57
|
-
if (!from)
|
|
58
|
+
if (!from) {
|
|
58
59
|
return false;
|
|
60
|
+
}
|
|
59
61
|
const { picData, name } = from;
|
|
60
62
|
const formdata = new FormData();
|
|
61
63
|
formdata.append('file', picData, name);
|
|
62
64
|
const url = await this.createUrl(formdata);
|
|
63
|
-
if (url)
|
|
65
|
+
if (url) {
|
|
64
66
|
return url;
|
|
67
|
+
}
|
|
65
68
|
return false;
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
@@ -74,8 +77,9 @@ class KOOKAPI {
|
|
|
74
77
|
const formdata = new FormData();
|
|
75
78
|
formdata.append('file', [file], Name);
|
|
76
79
|
const url = await this.createUrl(formdata);
|
|
77
|
-
if (url)
|
|
80
|
+
if (url) {
|
|
78
81
|
return url;
|
|
82
|
+
}
|
|
79
83
|
return false;
|
|
80
84
|
}
|
|
81
85
|
/**
|
|
@@ -89,7 +93,7 @@ class KOOKAPI {
|
|
|
89
93
|
url: ApiEnum.AssetCreate,
|
|
90
94
|
data: formdata,
|
|
91
95
|
headers: formdata.getHeaders()
|
|
92
|
-
})
|
|
96
|
+
});
|
|
93
97
|
}
|
|
94
98
|
/**
|
|
95
99
|
* *********
|
|
@@ -106,7 +110,7 @@ class KOOKAPI {
|
|
|
106
110
|
method: 'post',
|
|
107
111
|
url: ApiEnum.MessageCreate,
|
|
108
112
|
data
|
|
109
|
-
})
|
|
113
|
+
});
|
|
110
114
|
}
|
|
111
115
|
/**
|
|
112
116
|
* 创建私聊消息
|
|
@@ -116,88 +120,88 @@ class KOOKAPI {
|
|
|
116
120
|
* @param target_id
|
|
117
121
|
* @returns
|
|
118
122
|
*/
|
|
119
|
-
|
|
123
|
+
userChatCreate(target_id) {
|
|
120
124
|
return this.service({
|
|
121
125
|
method: 'post',
|
|
122
126
|
url: ApiEnum.UserChatCreate,
|
|
123
127
|
data: {
|
|
124
128
|
target_id
|
|
125
129
|
}
|
|
126
|
-
})
|
|
130
|
+
});
|
|
127
131
|
}
|
|
128
132
|
/**
|
|
129
133
|
* 创建消息
|
|
130
134
|
* @param data
|
|
131
135
|
* @returns
|
|
132
136
|
*/
|
|
133
|
-
|
|
137
|
+
createDirectMessage(data) {
|
|
134
138
|
return this.service({
|
|
135
139
|
method: 'post',
|
|
136
140
|
url: ApiEnum.DirectMessageCreate,
|
|
137
141
|
data
|
|
138
|
-
})
|
|
142
|
+
});
|
|
139
143
|
}
|
|
140
144
|
/**
|
|
141
145
|
* 删除指定消息
|
|
142
146
|
* @param msg_id
|
|
143
147
|
* @returns
|
|
144
148
|
*/
|
|
145
|
-
|
|
149
|
+
messageDelete(msg_id) {
|
|
146
150
|
return this.service({
|
|
147
151
|
method: 'post',
|
|
148
152
|
url: ApiEnum.MessageDelete,
|
|
149
153
|
data: {
|
|
150
154
|
msg_id
|
|
151
155
|
}
|
|
152
|
-
})
|
|
156
|
+
});
|
|
153
157
|
}
|
|
154
158
|
/**
|
|
155
159
|
* 重编辑指定消息
|
|
156
160
|
* @param data
|
|
157
161
|
* @returns
|
|
158
162
|
*/
|
|
159
|
-
|
|
163
|
+
messageUpdate(data) {
|
|
160
164
|
return this.service({
|
|
161
165
|
method: 'post',
|
|
162
166
|
url: ApiEnum.MessageUpdate,
|
|
163
167
|
data
|
|
164
|
-
})
|
|
168
|
+
});
|
|
165
169
|
}
|
|
166
170
|
/**
|
|
167
171
|
* 删回应
|
|
168
172
|
* @param data
|
|
169
173
|
* @returns
|
|
170
174
|
*/
|
|
171
|
-
|
|
175
|
+
messageDeleteReaction(data) {
|
|
172
176
|
return this.service({
|
|
173
177
|
method: 'post',
|
|
174
178
|
url: ApiEnum.MessageDeleteReaction,
|
|
175
179
|
data
|
|
176
|
-
})
|
|
180
|
+
});
|
|
177
181
|
}
|
|
178
182
|
/**
|
|
179
183
|
* 发回应
|
|
180
184
|
* @param data
|
|
181
185
|
* @returns
|
|
182
186
|
*/
|
|
183
|
-
|
|
187
|
+
messageAddReaction(data) {
|
|
184
188
|
return this.service({
|
|
185
189
|
method: 'post',
|
|
186
190
|
url: ApiEnum.MessageAddReaction,
|
|
187
191
|
data
|
|
188
|
-
})
|
|
192
|
+
});
|
|
189
193
|
}
|
|
190
194
|
/**
|
|
191
195
|
* 某个回应的所有用户
|
|
192
196
|
* @param data
|
|
193
197
|
* @returns
|
|
194
198
|
*/
|
|
195
|
-
|
|
199
|
+
messageReactionList(params) {
|
|
196
200
|
return this.service({
|
|
197
201
|
method: 'get',
|
|
198
202
|
url: ApiEnum.MessageReactionList,
|
|
199
203
|
params
|
|
200
|
-
})
|
|
204
|
+
});
|
|
201
205
|
}
|
|
202
206
|
/**
|
|
203
207
|
* **********
|
|
@@ -210,11 +214,11 @@ class KOOKAPI {
|
|
|
210
214
|
* @param user_id
|
|
211
215
|
* @returns
|
|
212
216
|
*/
|
|
213
|
-
|
|
217
|
+
userMe() {
|
|
214
218
|
return this.service({
|
|
215
219
|
method: 'get',
|
|
216
220
|
url: ApiEnum.UserMe
|
|
217
|
-
})
|
|
221
|
+
});
|
|
218
222
|
}
|
|
219
223
|
/**
|
|
220
224
|
* 得到用户信息
|
|
@@ -222,7 +226,7 @@ class KOOKAPI {
|
|
|
222
226
|
* @param user_id
|
|
223
227
|
* @returns
|
|
224
228
|
*/
|
|
225
|
-
|
|
229
|
+
userView(guild_id, user_id) {
|
|
226
230
|
return this.service({
|
|
227
231
|
method: 'get',
|
|
228
232
|
url: ApiEnum.UserView,
|
|
@@ -230,7 +234,7 @@ class KOOKAPI {
|
|
|
230
234
|
guild_id,
|
|
231
235
|
user_id
|
|
232
236
|
}
|
|
233
|
-
})
|
|
237
|
+
});
|
|
234
238
|
}
|
|
235
239
|
/**
|
|
236
240
|
* 踢出
|
|
@@ -238,7 +242,7 @@ class KOOKAPI {
|
|
|
238
242
|
* @param user_id
|
|
239
243
|
* @returns
|
|
240
244
|
*/
|
|
241
|
-
|
|
245
|
+
guildKickout(guild_id, user_id) {
|
|
242
246
|
return this.service({
|
|
243
247
|
method: 'post',
|
|
244
248
|
url: ApiEnum.GuildKickout,
|
|
@@ -246,7 +250,7 @@ class KOOKAPI {
|
|
|
246
250
|
guild_id,
|
|
247
251
|
target_id: user_id
|
|
248
252
|
}
|
|
249
|
-
})
|
|
253
|
+
});
|
|
250
254
|
}
|
|
251
255
|
/**
|
|
252
256
|
* 创建角色
|
|
@@ -255,7 +259,7 @@ class KOOKAPI {
|
|
|
255
259
|
* @param value
|
|
256
260
|
* @returns
|
|
257
261
|
*/
|
|
258
|
-
|
|
262
|
+
channelRoleCreate(channel_id, type, value) {
|
|
259
263
|
return this.service({
|
|
260
264
|
method: 'post',
|
|
261
265
|
url: ApiEnum.ChannelRoleCreate,
|
|
@@ -264,7 +268,7 @@ class KOOKAPI {
|
|
|
264
268
|
type,
|
|
265
269
|
value
|
|
266
270
|
}
|
|
267
|
-
})
|
|
271
|
+
});
|
|
268
272
|
}
|
|
269
273
|
}
|
|
270
274
|
|