@alemonjs/kook 2.1.8 → 2.1.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/dist/assets/index.css +1 -1
- package/dist/assets/index.js +5 -5
- package/dist/index.html +1 -1
- package/lib/desktop.js +4 -4
- package/lib/hook.d.ts +9 -0
- package/lib/hook.js +1 -1
- package/lib/index.js +113 -211
- package/lib/sdk/wss.js +2 -1
- package/package.json +2 -2
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>
|
|
7
|
+
<title>ALemonJS</title>
|
|
8
8
|
<script type="module" crossorigin src="/assets/index.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index.css">
|
|
10
10
|
</head>
|
package/lib/desktop.js
CHANGED
|
@@ -3,16 +3,16 @@ import { dirname, join } from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { getConfig, getConfigValue } from 'alemonjs';
|
|
5
5
|
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const activate = context => {
|
|
8
8
|
const webView = context.createSidebarWebView(context);
|
|
9
9
|
context.onCommand('open.kook', () => {
|
|
10
|
-
const dir = join(__dirname, '../', 'dist', 'index.html');
|
|
10
|
+
const dir = join(__dirname$1, '../', 'dist', 'index.html');
|
|
11
11
|
const scriptReg = /<script.*?src="(.+?)".*?>/;
|
|
12
12
|
const styleReg = /<link.*?rel="stylesheet".*?href="(.+?)".*?>/;
|
|
13
13
|
const iconReg = /<link.*?rel="icon".*?href="(.+?)".*?>/g;
|
|
14
|
-
const styleUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.css'));
|
|
15
|
-
const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
|
|
14
|
+
const styleUri = context.createExtensionDir(join(__dirname$1, '../', 'dist', 'assets', 'index.css'));
|
|
15
|
+
const scriptUri = context.createExtensionDir(join(__dirname$1, '../', 'dist', 'assets', 'index.js'));
|
|
16
16
|
const html = readFileSync(dir, 'utf-8')
|
|
17
17
|
.replace(iconReg, '')
|
|
18
18
|
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
package/lib/hook.d.ts
CHANGED
|
@@ -18,8 +18,17 @@ type MAP = {
|
|
|
18
18
|
'member.remove': undefined;
|
|
19
19
|
'private.message.update': undefined;
|
|
20
20
|
'private.message.delete': undefined;
|
|
21
|
+
'message.pin': undefined;
|
|
22
|
+
'channel.update': undefined;
|
|
23
|
+
'guild.update': undefined;
|
|
24
|
+
'member.ban': undefined;
|
|
25
|
+
'member.unban': undefined;
|
|
26
|
+
'member.update': undefined;
|
|
27
|
+
'notice.create': undefined;
|
|
21
28
|
'private.friend.add': undefined;
|
|
29
|
+
'private.friend.remove': undefined;
|
|
22
30
|
'private.guild.add': undefined;
|
|
31
|
+
'private.notice.create': undefined;
|
|
23
32
|
};
|
|
24
33
|
export declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
25
34
|
export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
|
package/lib/hook.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definePlatform, cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
1
|
+
import { definePlatform, cbpPlatform, FormatEvent, 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';
|
|
@@ -34,23 +34,13 @@ const main = () => {
|
|
|
34
34
|
const UserAvatar = url;
|
|
35
35
|
const UserId = event.author_id;
|
|
36
36
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
IsMaster: isMaster,
|
|
45
|
-
IsBot: false,
|
|
46
|
-
MessageId: event.msg_id,
|
|
47
|
-
MessageText: msg,
|
|
48
|
-
OpenId: data?.code,
|
|
49
|
-
BotId: botId,
|
|
50
|
-
_tag: 'MESSAGES_DIRECT',
|
|
51
|
-
value: event
|
|
52
|
-
};
|
|
53
|
-
cbp.send(e);
|
|
37
|
+
cbp.send(FormatEvent.create('private.message.create')
|
|
38
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
39
|
+
.addUser({ UserId, UserKey, UserName: event.extra.author.username, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
|
|
40
|
+
.addMessage({ MessageId: event.msg_id })
|
|
41
|
+
.addText({ MessageText: msg })
|
|
42
|
+
.addOpen({ OpenId: data?.code })
|
|
43
|
+
.add({ tag: 'MESSAGES_DIRECT' }).value);
|
|
54
44
|
});
|
|
55
45
|
client.on('MESSAGES_PUBLIC', async (event) => {
|
|
56
46
|
if (event.extra?.author?.bot) {
|
|
@@ -70,26 +60,15 @@ const main = () => {
|
|
|
70
60
|
const UserAvatar = avatar.substring(0, avatar.indexOf('?'));
|
|
71
61
|
const UserId = event.author_id;
|
|
72
62
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
UserAvatar: UserAvatar,
|
|
83
|
-
IsMaster: isMaster,
|
|
84
|
-
IsBot: false,
|
|
85
|
-
MessageId: event.msg_id,
|
|
86
|
-
MessageText: msg,
|
|
87
|
-
OpenId: data?.code,
|
|
88
|
-
BotId: botId,
|
|
89
|
-
_tag: 'MESSAGES_PUBLIC',
|
|
90
|
-
value: event
|
|
91
|
-
};
|
|
92
|
-
cbp.send(e);
|
|
63
|
+
cbp.send(FormatEvent.create('message.create')
|
|
64
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
65
|
+
.addGuild({ GuildId: event.extra.guild_id, SpaceId: event.target_id })
|
|
66
|
+
.addChannel({ ChannelId: event.target_id })
|
|
67
|
+
.addUser({ UserId, UserKey, UserName: event.extra.author.username, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
|
|
68
|
+
.addMessage({ MessageId: event.msg_id })
|
|
69
|
+
.addText({ MessageText: msg })
|
|
70
|
+
.addOpen({ OpenId: data?.code })
|
|
71
|
+
.add({ tag: 'MESSAGES_PUBLIC' }).value);
|
|
93
72
|
});
|
|
94
73
|
client.on('ERROR', msg => {
|
|
95
74
|
console.error(msg);
|
|
@@ -101,32 +80,20 @@ const main = () => {
|
|
|
101
80
|
return;
|
|
102
81
|
}
|
|
103
82
|
if (reactionType === 'added_reaction') {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
MessageId: body.msg_id ?? '',
|
|
111
|
-
BotId: botId,
|
|
112
|
-
_tag: 'REACTIONS_ADD',
|
|
113
|
-
value: event
|
|
114
|
-
};
|
|
115
|
-
cbp.send(e);
|
|
83
|
+
cbp.send(FormatEvent.create('message.reaction.add')
|
|
84
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
85
|
+
.addGuild({ GuildId: body.channel_id ?? '', SpaceId: body.channel_id ?? '' })
|
|
86
|
+
.addChannel({ ChannelId: body.channel_id ?? '' })
|
|
87
|
+
.addMessage({ MessageId: body.msg_id ?? '' })
|
|
88
|
+
.add({ tag: 'REACTIONS_ADD' }).value);
|
|
116
89
|
}
|
|
117
90
|
else if (reactionType === 'deleted_reaction') {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
MessageId: body.msg_id ?? '',
|
|
125
|
-
BotId: botId,
|
|
126
|
-
_tag: 'REACTIONS_REMOVE',
|
|
127
|
-
value: event
|
|
128
|
-
};
|
|
129
|
-
cbp.send(e);
|
|
91
|
+
cbp.send(FormatEvent.create('message.reaction.remove')
|
|
92
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
93
|
+
.addGuild({ GuildId: body.channel_id ?? '', SpaceId: body.channel_id ?? '' })
|
|
94
|
+
.addChannel({ ChannelId: body.channel_id ?? '' })
|
|
95
|
+
.addMessage({ MessageId: body.msg_id ?? '' })
|
|
96
|
+
.add({ tag: 'REACTIONS_REMOVE' }).value);
|
|
130
97
|
}
|
|
131
98
|
});
|
|
132
99
|
client.on('MEMBER_ADD', event => {
|
|
@@ -136,22 +103,13 @@ const main = () => {
|
|
|
136
103
|
}
|
|
137
104
|
const UserId = body.user_id ?? event.author_id;
|
|
138
105
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
UserKey,
|
|
147
|
-
IsMaster: isMaster,
|
|
148
|
-
IsBot: false,
|
|
149
|
-
MessageId: event.msg_id ?? '',
|
|
150
|
-
BotId: botId,
|
|
151
|
-
_tag: 'MEMBER_ADD',
|
|
152
|
-
value: event
|
|
153
|
-
};
|
|
154
|
-
cbp.send(e);
|
|
106
|
+
cbp.send(FormatEvent.create('member.add')
|
|
107
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
108
|
+
.addGuild({ GuildId: event.target_id ?? '', SpaceId: event.target_id ?? '' })
|
|
109
|
+
.addChannel({ ChannelId: '' })
|
|
110
|
+
.addUser({ UserId, UserKey, IsMaster: isMaster, IsBot: false })
|
|
111
|
+
.addMessage({ MessageId: event.msg_id ?? '' })
|
|
112
|
+
.add({ tag: 'MEMBER_ADD' }).value);
|
|
155
113
|
});
|
|
156
114
|
client.on('MEMBER_REMOVE', event => {
|
|
157
115
|
const body = event.extra?.body;
|
|
@@ -160,172 +118,106 @@ const main = () => {
|
|
|
160
118
|
}
|
|
161
119
|
const UserId = body.user_id ?? event.author_id;
|
|
162
120
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
UserKey,
|
|
171
|
-
IsMaster: isMaster,
|
|
172
|
-
IsBot: false,
|
|
173
|
-
MessageId: event.msg_id ?? '',
|
|
174
|
-
BotId: botId,
|
|
175
|
-
_tag: 'MEMBER_REMOVE',
|
|
176
|
-
value: event
|
|
177
|
-
};
|
|
178
|
-
cbp.send(e);
|
|
121
|
+
cbp.send(FormatEvent.create('member.remove')
|
|
122
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
123
|
+
.addGuild({ GuildId: event.target_id ?? '', SpaceId: event.target_id ?? '' })
|
|
124
|
+
.addChannel({ ChannelId: '' })
|
|
125
|
+
.addUser({ UserId, UserKey, IsMaster: isMaster, IsBot: false })
|
|
126
|
+
.addMessage({ MessageId: event.msg_id ?? '' })
|
|
127
|
+
.add({ tag: 'MEMBER_REMOVE' }).value);
|
|
179
128
|
});
|
|
180
129
|
client.on('MESSAGES_UPDATE', event => {
|
|
181
130
|
const body = event.extra?.body;
|
|
182
131
|
if (!body) {
|
|
183
132
|
return;
|
|
184
133
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
UserKey: '',
|
|
193
|
-
IsMaster: false,
|
|
194
|
-
IsBot: false,
|
|
195
|
-
MessageId: body.msg_id ?? event.msg_id ?? '',
|
|
196
|
-
BotId: botId,
|
|
197
|
-
_tag: 'MESSAGES_UPDATE',
|
|
198
|
-
value: event
|
|
199
|
-
};
|
|
200
|
-
cbp.send(e);
|
|
134
|
+
cbp.send(FormatEvent.create('message.update')
|
|
135
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
136
|
+
.addGuild({ GuildId: body.channel_id ?? event.target_id ?? '', SpaceId: body.channel_id ?? event.target_id ?? '' })
|
|
137
|
+
.addChannel({ ChannelId: body.channel_id ?? event.target_id ?? '' })
|
|
138
|
+
.addUser({ UserId: body.author_id ?? event.author_id ?? '', UserKey: '', IsMaster: false, IsBot: false })
|
|
139
|
+
.addMessage({ MessageId: body.msg_id ?? event.msg_id ?? '' })
|
|
140
|
+
.add({ tag: 'MESSAGES_UPDATE' }).value);
|
|
201
141
|
});
|
|
202
142
|
client.on('MESSAGES_DELETE', event => {
|
|
203
143
|
const body = event.extra?.body;
|
|
204
144
|
if (!body) {
|
|
205
145
|
return;
|
|
206
146
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
MessageId: body.msg_id ?? event.msg_id ?? '',
|
|
214
|
-
BotId: botId,
|
|
215
|
-
_tag: 'MESSAGES_DELETE',
|
|
216
|
-
value: event
|
|
217
|
-
};
|
|
218
|
-
cbp.send(e);
|
|
147
|
+
cbp.send(FormatEvent.create('message.delete')
|
|
148
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
149
|
+
.addGuild({ GuildId: body.channel_id ?? event.target_id ?? '', SpaceId: body.channel_id ?? event.target_id ?? '' })
|
|
150
|
+
.addChannel({ ChannelId: body.channel_id ?? event.target_id ?? '' })
|
|
151
|
+
.addMessage({ MessageId: body.msg_id ?? event.msg_id ?? '' })
|
|
152
|
+
.add({ tag: 'MESSAGES_DELETE' }).value);
|
|
219
153
|
});
|
|
220
154
|
client.on('MESSAGES_PIN', event => {
|
|
221
155
|
const body = event.extra?.body;
|
|
222
156
|
if (!body) {
|
|
223
157
|
return;
|
|
224
158
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
MessageId: body.msg_id ?? event.msg_id ?? '',
|
|
232
|
-
BotId: botId,
|
|
233
|
-
_tag: 'MESSAGES_PIN',
|
|
234
|
-
value: event
|
|
235
|
-
};
|
|
236
|
-
cbp.send(e);
|
|
159
|
+
cbp.send(FormatEvent.create('message.pin')
|
|
160
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
161
|
+
.addGuild({ GuildId: body.channel_id ?? event.target_id ?? '', SpaceId: body.channel_id ?? event.target_id ?? '' })
|
|
162
|
+
.addChannel({ ChannelId: body.channel_id ?? event.target_id ?? '' })
|
|
163
|
+
.addMessage({ MessageId: body.msg_id ?? event.msg_id ?? '' })
|
|
164
|
+
.add({ tag: 'MESSAGES_PIN' }).value);
|
|
237
165
|
});
|
|
238
166
|
client.on('GUILD_JOIN', event => {
|
|
239
167
|
const body = event.extra?.body;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
UserKey: '',
|
|
248
|
-
IsMaster: false,
|
|
249
|
-
IsBot: true,
|
|
250
|
-
MessageId: event.msg_id ?? '',
|
|
251
|
-
BotId: botId,
|
|
252
|
-
_tag: 'GUILD_JOIN',
|
|
253
|
-
value: event
|
|
254
|
-
};
|
|
255
|
-
cbp.send(e);
|
|
168
|
+
cbp.send(FormatEvent.create('guild.join')
|
|
169
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
170
|
+
.addGuild({ GuildId: body?.guild_id ?? event.target_id ?? '', SpaceId: body?.guild_id ?? event.target_id ?? '' })
|
|
171
|
+
.addChannel({ ChannelId: '' })
|
|
172
|
+
.addUser({ UserId: event.author_id ?? '', UserKey: '', IsMaster: false, IsBot: true })
|
|
173
|
+
.addMessage({ MessageId: event.msg_id ?? '' })
|
|
174
|
+
.add({ tag: 'GUILD_JOIN' }).value);
|
|
256
175
|
});
|
|
257
176
|
client.on('GUILD_EXIT', event => {
|
|
258
177
|
const body = event.extra?.body;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
UserKey: '',
|
|
267
|
-
IsMaster: false,
|
|
268
|
-
IsBot: true,
|
|
269
|
-
MessageId: event.msg_id ?? '',
|
|
270
|
-
BotId: botId,
|
|
271
|
-
_tag: 'GUILD_EXIT',
|
|
272
|
-
value: event
|
|
273
|
-
};
|
|
274
|
-
cbp.send(e);
|
|
178
|
+
cbp.send(FormatEvent.create('guild.exit')
|
|
179
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
180
|
+
.addGuild({ GuildId: body?.guild_id ?? event.target_id ?? '', SpaceId: body?.guild_id ?? event.target_id ?? '' })
|
|
181
|
+
.addChannel({ ChannelId: '' })
|
|
182
|
+
.addUser({ UserId: event.author_id ?? '', UserKey: '', IsMaster: false, IsBot: true })
|
|
183
|
+
.addMessage({ MessageId: event.msg_id ?? '' })
|
|
184
|
+
.add({ tag: 'GUILD_EXIT' }).value);
|
|
275
185
|
});
|
|
276
186
|
client.on('CHANNEL_CREATE', event => {
|
|
277
187
|
const body = event.extra?.body;
|
|
278
188
|
if (!body) {
|
|
279
189
|
return;
|
|
280
190
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
MessageId: event.msg_id ?? '',
|
|
288
|
-
BotId: botId,
|
|
289
|
-
_tag: 'CHANNEL_CREATE',
|
|
290
|
-
value: event
|
|
291
|
-
};
|
|
292
|
-
cbp.send(e);
|
|
191
|
+
cbp.send(FormatEvent.create('channel.create')
|
|
192
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
193
|
+
.addGuild({ GuildId: body.guild_id ?? event.target_id ?? '', SpaceId: body.guild_id ?? event.target_id ?? '' })
|
|
194
|
+
.addChannel({ ChannelId: body.id ?? '' })
|
|
195
|
+
.addMessage({ MessageId: event.msg_id ?? '' })
|
|
196
|
+
.add({ tag: 'CHANNEL_CREATE' }).value);
|
|
293
197
|
});
|
|
294
198
|
client.on('CHANNEL_DELETE', event => {
|
|
295
199
|
const body = event.extra?.body;
|
|
296
200
|
if (!body) {
|
|
297
201
|
return;
|
|
298
202
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
MessageId: event.msg_id ?? '',
|
|
306
|
-
BotId: botId,
|
|
307
|
-
_tag: 'CHANNEL_DELETE',
|
|
308
|
-
value: event
|
|
309
|
-
};
|
|
310
|
-
cbp.send(e);
|
|
203
|
+
cbp.send(FormatEvent.create('channel.delete')
|
|
204
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
205
|
+
.addGuild({ GuildId: body.guild_id ?? event.target_id ?? '', SpaceId: body.guild_id ?? event.target_id ?? '' })
|
|
206
|
+
.addChannel({ ChannelId: body.id ?? '' })
|
|
207
|
+
.addMessage({ MessageId: event.msg_id ?? '' })
|
|
208
|
+
.add({ tag: 'CHANNEL_DELETE' }).value);
|
|
311
209
|
});
|
|
312
210
|
client.on('CHANNEL_UPDATE', event => {
|
|
313
211
|
const body = event.extra?.body;
|
|
314
212
|
if (!body) {
|
|
315
213
|
return;
|
|
316
214
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
MessageId: event.msg_id ?? '',
|
|
324
|
-
BotId: botId,
|
|
325
|
-
_tag: 'CHANNEL_UPDATE',
|
|
326
|
-
value: event
|
|
327
|
-
};
|
|
328
|
-
cbp.send(e);
|
|
215
|
+
cbp.send(FormatEvent.create('channel.update')
|
|
216
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
217
|
+
.addGuild({ GuildId: body.guild_id ?? event.target_id ?? '', SpaceId: body.guild_id ?? event.target_id ?? '' })
|
|
218
|
+
.addChannel({ ChannelId: body.id ?? '' })
|
|
219
|
+
.addMessage({ MessageId: event.msg_id ?? '' })
|
|
220
|
+
.add({ tag: 'CHANNEL_UPDATE' }).value);
|
|
329
221
|
});
|
|
330
222
|
const formatKookContent = (val) => {
|
|
331
223
|
const nativeItems = val.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link');
|
|
@@ -891,18 +783,28 @@ const main = () => {
|
|
|
891
783
|
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
892
784
|
const onapis = async (data, consume) => {
|
|
893
785
|
const key = data.payload?.key;
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
786
|
+
const params = data.payload?.params;
|
|
787
|
+
try {
|
|
788
|
+
const keys = key.split('.');
|
|
789
|
+
let parent = null;
|
|
790
|
+
let target = client;
|
|
791
|
+
for (const k of keys) {
|
|
792
|
+
if (target === null || target === undefined || !(k in target)) {
|
|
793
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
parent = target;
|
|
797
|
+
target = target[k];
|
|
899
798
|
}
|
|
900
|
-
|
|
901
|
-
consume([createResult(ResultCode.Fail, '
|
|
799
|
+
if (typeof target !== 'function') {
|
|
800
|
+
consume([createResult(ResultCode.Fail, '目标不是可调用方法', null)]);
|
|
801
|
+
return;
|
|
902
802
|
}
|
|
803
|
+
const res = await target.call(parent, ...params);
|
|
804
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
903
805
|
}
|
|
904
|
-
|
|
905
|
-
consume([createResult(ResultCode.Fail, '
|
|
806
|
+
catch (error) {
|
|
807
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
906
808
|
}
|
|
907
809
|
};
|
|
908
810
|
cbp.onapis((data, consume) => void onapis(data, consume));
|
package/lib/sdk/wss.js
CHANGED
|
@@ -6,6 +6,7 @@ import { ConversationMap } from './conversation.js';
|
|
|
6
6
|
class KOOKClient extends KOOKAPI {
|
|
7
7
|
#isConnected = false;
|
|
8
8
|
#lastMessageSN = 0;
|
|
9
|
+
#sessionId = null;
|
|
9
10
|
constructor(opstion) {
|
|
10
11
|
super();
|
|
11
12
|
config.set('token', opstion.token);
|
|
@@ -57,7 +58,7 @@ class KOOKClient extends KOOKAPI {
|
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
60
|
1: ({ d }) => {
|
|
60
|
-
if (d
|
|
61
|
+
if (d?.code === 0) {
|
|
61
62
|
console.info('[ws] ok');
|
|
62
63
|
this.#sessionId = d.session_id;
|
|
63
64
|
this.#isConnected = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/kook",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "kook platform connection",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"type": "git",
|
|
60
60
|
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "fee3935ca19b1658ea4b41d5d3e7f281e7efc932"
|
|
63
63
|
}
|