@alemonjs/kook 0.2.6 → 0.2.7
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 +3 -13
- package/dist/assets/index.css +1 -1
- package/dist/assets/index.js +1 -1
- package/lib/desktop.d.ts +2 -2
- package/lib/desktop.js +55 -52
- package/lib/index.d.ts +7 -7
- package/lib/index.js +109 -23
- package/lib/sdk/platform/kook/sdk/api.d.ts +279 -267
- package/lib/sdk/platform/kook/sdk/message/INTERACTION.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MEMBER_ADD.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MEMBER_REMOVE.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_DIRECT.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_PUBLIC.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/REACTIONS.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message.d.ts +15 -15
- package/lib/sdk/platform/kook/sdk/typings.d.ts +167 -138
- package/lib/sdk/platform/kook/sdk/wss.d.ts +22 -22
- package/lib/sdk/platform/kook/sdk/wss.types.d.ts +5 -5
- package/package.json +4 -1
package/lib/desktop.js
CHANGED
|
@@ -1,58 +1,61 @@
|
|
|
1
|
-
import { readFileSync } from 'fs'
|
|
2
|
-
import { dirname, join } from 'path'
|
|
3
|
-
import { fileURLToPath } from 'url'
|
|
4
|
-
import { getConfig, getConfigValue } from 'alemonjs'
|
|
1
|
+
import { readFileSync } from 'fs'
|
|
2
|
+
import { dirname, join } from 'path'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
4
|
+
import { getConfig, getConfigValue } from 'alemonjs'
|
|
5
5
|
|
|
6
6
|
// 当前目录
|
|
7
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
8
8
|
// 被激活的时候。
|
|
9
9
|
const activate = context => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!config)
|
|
44
|
-
config = {};
|
|
45
|
-
// 发送消息
|
|
46
|
-
webView.postMessage({
|
|
47
|
-
type: 'kook.init',
|
|
48
|
-
data: config.kook ?? {}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
10
|
+
// 创建一个 webview。
|
|
11
|
+
const webView = context.createSidebarWebView(context)
|
|
12
|
+
// 当命令被触发的时候。
|
|
13
|
+
context.onCommand('open.kook', () => {
|
|
14
|
+
const dir = join(__dirname, '../', 'dist', 'index.html')
|
|
15
|
+
const scriptReg = /<script.*?src="(.+?)".*?>/
|
|
16
|
+
const styleReg = /<link.*?rel="stylesheet".*?href="(.+?)".*?>/
|
|
17
|
+
const iconReg = /<link.*?rel="icon".*?href="(.+?)".*?>/g
|
|
18
|
+
// 创建 webview 路径
|
|
19
|
+
const styleUri = context.createExtensionDir(
|
|
20
|
+
join(__dirname, '../', 'dist', 'assets', 'index.css')
|
|
21
|
+
)
|
|
22
|
+
const scriptUri = context.createExtensionDir(
|
|
23
|
+
join(__dirname, '../', 'dist', 'assets', 'index.js')
|
|
24
|
+
)
|
|
25
|
+
// 确保路径存在
|
|
26
|
+
const html = readFileSync(dir, 'utf-8')
|
|
27
|
+
.replace(iconReg, ``)
|
|
28
|
+
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
|
29
|
+
.replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`)
|
|
30
|
+
// 立即渲染 webview
|
|
31
|
+
webView.loadWebView(html)
|
|
32
|
+
})
|
|
33
|
+
// 监听 webview 的消息。
|
|
34
|
+
webView.onMessage(data => {
|
|
35
|
+
try {
|
|
36
|
+
if (data.type === 'kook.form.save') {
|
|
37
|
+
const db = data.data
|
|
38
|
+
const config = getConfig()
|
|
39
|
+
const value = config.value ?? {}
|
|
40
|
+
value['kook'] = {
|
|
41
|
+
token: db.token ?? '',
|
|
42
|
+
master_key: db.master_key?.split(',') ?? null
|
|
51
43
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
44
|
+
config.saveValue(value)
|
|
45
|
+
context.notification('KOOK 配置保存成功~')
|
|
46
|
+
} else if (data.type === 'kook.init') {
|
|
47
|
+
let config = getConfigValue()
|
|
48
|
+
if (!config) config = {}
|
|
49
|
+
// 发送消息
|
|
50
|
+
webView.postMessage({
|
|
51
|
+
type: 'kook.init',
|
|
52
|
+
data: config.kook ?? {}
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.error(e)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
57
60
|
|
|
58
|
-
export { activate }
|
|
61
|
+
export { activate }
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as alemonjs from 'alemonjs'
|
|
2
|
-
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js'
|
|
1
|
+
import * as alemonjs from 'alemonjs'
|
|
2
|
+
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js'
|
|
3
3
|
|
|
4
|
-
type Client = typeof KOOKClient.prototype
|
|
5
|
-
declare const platform =
|
|
6
|
-
declare const client: Client
|
|
7
|
-
declare const _default:
|
|
4
|
+
type Client = typeof KOOKClient.prototype
|
|
5
|
+
declare const platform = 'kook'
|
|
6
|
+
declare const client: Client
|
|
7
|
+
declare const _default: alemonjs.DefineBotValue
|
|
8
8
|
|
|
9
|
-
export { type Client, client, _default as default, platform }
|
|
9
|
+
export { type Client, client, _default as default, platform }
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey,
|
|
2
|
-
import 'fs';
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
3
|
import 'axios';
|
|
4
4
|
import 'path';
|
|
5
5
|
import 'qrcode';
|
|
@@ -83,14 +83,8 @@ var index = defineBot(() => {
|
|
|
83
83
|
tag: 'MESSAGES_PUBLIC',
|
|
84
84
|
value: null
|
|
85
85
|
};
|
|
86
|
-
// 当访问的时候获取
|
|
87
|
-
Object.defineProperty(e, 'value', {
|
|
88
|
-
get() {
|
|
89
|
-
return event;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
86
|
// 处理消息
|
|
93
|
-
|
|
87
|
+
onProcessor('private.message.create', e, event);
|
|
94
88
|
});
|
|
95
89
|
// 监听消息
|
|
96
90
|
client.on('MESSAGES_PUBLIC', async (event) => {
|
|
@@ -164,14 +158,8 @@ var index = defineBot(() => {
|
|
|
164
158
|
tag: 'MESSAGES_PUBLIC',
|
|
165
159
|
value: null
|
|
166
160
|
};
|
|
167
|
-
// 当访问的时候获取
|
|
168
|
-
Object.defineProperty(e, 'value', {
|
|
169
|
-
get() {
|
|
170
|
-
return event;
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
161
|
// 处理消息
|
|
174
|
-
|
|
162
|
+
onProcessor('message.create', e, event);
|
|
175
163
|
});
|
|
176
164
|
// 发送错误时
|
|
177
165
|
client.on('ERROR', msg => {
|
|
@@ -180,18 +168,105 @@ var index = defineBot(() => {
|
|
|
180
168
|
// 客户端全局化。
|
|
181
169
|
global.client = client;
|
|
182
170
|
return {
|
|
171
|
+
platform,
|
|
183
172
|
api: {
|
|
173
|
+
active: {
|
|
174
|
+
send: {
|
|
175
|
+
channel: (channel_id, val) => {
|
|
176
|
+
if (val.length < 0)
|
|
177
|
+
return Promise.all([]);
|
|
178
|
+
const content = val
|
|
179
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
180
|
+
.map(item => {
|
|
181
|
+
// if (item.type == 'Link') {
|
|
182
|
+
// return `[${item.options?.title ?? item.value}](${item.value})`
|
|
183
|
+
// } else
|
|
184
|
+
if (item.type == 'Mention') {
|
|
185
|
+
if (item.value == 'everyone' ||
|
|
186
|
+
item.value == 'all' ||
|
|
187
|
+
item.value == '' ||
|
|
188
|
+
typeof item.value != 'string') {
|
|
189
|
+
return `(met)all(met)`;
|
|
190
|
+
}
|
|
191
|
+
if (item.options?.belong == 'user') {
|
|
192
|
+
return `(met)${item.value}(met)`;
|
|
193
|
+
}
|
|
194
|
+
else if (item.options?.belong == 'channel') {
|
|
195
|
+
return `(chn)${item.value}(chn)`;
|
|
196
|
+
}
|
|
197
|
+
return '';
|
|
198
|
+
}
|
|
199
|
+
else if (item.type == 'Text') {
|
|
200
|
+
if (item.options?.style == 'block') {
|
|
201
|
+
return `\`${item.value}\``;
|
|
202
|
+
}
|
|
203
|
+
else if (item.options?.style == 'italic') {
|
|
204
|
+
return `*${item.value}*`;
|
|
205
|
+
}
|
|
206
|
+
else if (item.options?.style == 'bold') {
|
|
207
|
+
return `**${item.value}**`;
|
|
208
|
+
}
|
|
209
|
+
else if (item.options?.style == 'strikethrough') {
|
|
210
|
+
return `~~${item.value}~~`;
|
|
211
|
+
}
|
|
212
|
+
else if (item.options?.style == 'boldItalic') {
|
|
213
|
+
return `***${item.value}***`;
|
|
214
|
+
}
|
|
215
|
+
return item.value;
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
.join('');
|
|
219
|
+
if (content) {
|
|
220
|
+
return Promise.all([content].map(item => client.createMessage({
|
|
221
|
+
type: 9,
|
|
222
|
+
target_id: channel_id,
|
|
223
|
+
content: item
|
|
224
|
+
})));
|
|
225
|
+
}
|
|
226
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
227
|
+
if (images) {
|
|
228
|
+
return Promise.all(images.map(async (item) => {
|
|
229
|
+
if (item.type == 'ImageURL') {
|
|
230
|
+
return await client.createMessage({
|
|
231
|
+
type: 2,
|
|
232
|
+
target_id: channel_id,
|
|
233
|
+
content: item.value
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
let data = item.value;
|
|
237
|
+
if (item.type == 'ImageFile') {
|
|
238
|
+
data = readFileSync(item.value);
|
|
239
|
+
}
|
|
240
|
+
// 上传图片
|
|
241
|
+
const res = await client.postImage(data);
|
|
242
|
+
if (!res)
|
|
243
|
+
return Promise.resolve();
|
|
244
|
+
// 发送消息
|
|
245
|
+
return await client.createMessage({
|
|
246
|
+
type: 2,
|
|
247
|
+
target_id: channel_id,
|
|
248
|
+
content: res.data.url
|
|
249
|
+
});
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
return Promise.all([]);
|
|
253
|
+
},
|
|
254
|
+
user: (channel_id, val) => {
|
|
255
|
+
return Promise.all([]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
184
259
|
use: {
|
|
185
260
|
send: (event, val) => {
|
|
186
261
|
if (val.length < 0)
|
|
187
262
|
return Promise.all([]);
|
|
188
263
|
const content = val
|
|
189
|
-
.filter(item => item.type == '
|
|
264
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
190
265
|
.map(item => {
|
|
191
|
-
if (item.type == 'Link') {
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
266
|
+
// if (item.type == 'Link') {
|
|
267
|
+
// return `[${item.options?.title ?? item.value}](${item.value})`
|
|
268
|
+
// } else
|
|
269
|
+
if (item.type == 'Mention') {
|
|
195
270
|
if (item.value == 'everyone' ||
|
|
196
271
|
item.value == 'all' ||
|
|
197
272
|
item.value == '' ||
|
|
@@ -233,11 +308,22 @@ var index = defineBot(() => {
|
|
|
233
308
|
content: item
|
|
234
309
|
})));
|
|
235
310
|
}
|
|
236
|
-
const images = val.filter(item => item.type == 'Image'
|
|
311
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
237
312
|
if (images) {
|
|
238
313
|
return Promise.all(images.map(async (item) => {
|
|
314
|
+
if (item.type == 'ImageURL') {
|
|
315
|
+
return await client.createMessage({
|
|
316
|
+
type: 2,
|
|
317
|
+
target_id: event.ChannelId,
|
|
318
|
+
content: item.value
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
let data = item.value;
|
|
322
|
+
if (item.type == 'ImageFile') {
|
|
323
|
+
data = readFileSync(item.value);
|
|
324
|
+
}
|
|
239
325
|
// 上传图片
|
|
240
|
-
const res = await client.postImage(
|
|
326
|
+
const res = await client.postImage(data);
|
|
241
327
|
if (!res)
|
|
242
328
|
return Promise.resolve();
|
|
243
329
|
// 发送消息
|