@alemonjs/kook 2.1.0-alpha.4 → 2.1.1

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.
@@ -0,0 +1,4 @@
1
+ import type { DataEnums, DataMarkDown } from 'alemonjs';
2
+ export declare const markdownToKMarkdown: (items: DataMarkDown["value"]) => string;
3
+ export declare const markdownRawToKMarkdown: (raw: string) => string;
4
+ export declare const dataEnumToKMarkdown: (item: DataEnums) => string;
package/lib/format.js ADDED
@@ -0,0 +1,85 @@
1
+ const markdownToKMarkdown = (items) => {
2
+ return items
3
+ .map(item => {
4
+ switch (item.type) {
5
+ case 'MD.text':
6
+ return item.value;
7
+ case 'MD.title':
8
+ return `**${item.value}**\n`;
9
+ case 'MD.subtitle':
10
+ return `**${item.value}**\n`;
11
+ case 'MD.bold':
12
+ return `**${item.value}**`;
13
+ case 'MD.italic':
14
+ case 'MD.italicStar':
15
+ return `*${item.value}*`;
16
+ case 'MD.strikethrough':
17
+ return `~~${item.value}~~`;
18
+ case 'MD.link': {
19
+ const v = item.value;
20
+ return `[${v.text}](${v.url})`;
21
+ }
22
+ case 'MD.image':
23
+ return '[图片]';
24
+ case 'MD.list':
25
+ return (item.value
26
+ .map(li => {
27
+ if (typeof li.value === 'object') {
28
+ return `${li.value.index}. ${li.value.text ?? ''}`;
29
+ }
30
+ return `- ${li.value}`;
31
+ })
32
+ .join('\n') + '\n');
33
+ case 'MD.blockquote':
34
+ return `> ${item.value}\n`;
35
+ case 'MD.divider':
36
+ return '---\n';
37
+ case 'MD.newline':
38
+ return '\n';
39
+ case 'MD.code': {
40
+ const lang = item?.options?.language || '';
41
+ return `\`\`\`${lang}\n${item.value}\n\`\`\`\n`;
42
+ }
43
+ case 'MD.mention':
44
+ if (item.value === 'everyone') {
45
+ return '(met)all(met)';
46
+ }
47
+ return `(met)${item.value ?? ''}(met)`;
48
+ case 'MD.content':
49
+ return item.value;
50
+ case 'MD.button':
51
+ return `[${item.value}]`;
52
+ default:
53
+ return String(item?.value ?? '');
54
+ }
55
+ })
56
+ .join('');
57
+ };
58
+ const markdownRawToKMarkdown = (raw) => {
59
+ let text = raw;
60
+ text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, '[图片]');
61
+ return text;
62
+ };
63
+ const dataEnumToKMarkdown = (item) => {
64
+ switch (item.type) {
65
+ case 'Markdown':
66
+ return markdownToKMarkdown(item.value);
67
+ case 'MarkdownOriginal':
68
+ return markdownRawToKMarkdown(String(item.value));
69
+ case 'BT.group':
70
+ case 'ButtonGroup':
71
+ return item.value
72
+ .map((row) => row.value.map((btn) => `[${btn.value}]`).join(' '))
73
+ .join('\n');
74
+ case 'Attachment':
75
+ return `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
76
+ case 'Audio':
77
+ return '[音频]';
78
+ case 'Video':
79
+ return '[视频]';
80
+ default:
81
+ return '';
82
+ }
83
+ };
84
+
85
+ export { dataEnumToKMarkdown, markdownRawToKMarkdown, markdownToKMarkdown };
package/lib/index.js CHANGED
@@ -4,6 +4,7 @@ import { KOOKClient } from './sdk/wss.js';
4
4
  import { readFileSync } from 'fs';
5
5
  import { getKOOKConfig, getMaster, platform } from './config.js';
6
6
  import { getBufferByURL } from 'alemonjs/utils';
7
+ import { dataEnumToKMarkdown } from './format.js';
7
8
  export { useClient, useValue } from './hook.js';
8
9
 
9
10
  const main = () => {
@@ -12,6 +13,13 @@ const main = () => {
12
13
  token: config.token
13
14
  });
14
15
  void client.connect();
16
+ let botId = '';
17
+ client
18
+ .userMe()
19
+ .then(res => {
20
+ botId = String(res?.data?.id ?? '');
21
+ })
22
+ .catch(() => { });
15
23
  const port = process.env?.port || 17117;
16
24
  const url = `ws://127.0.0.1:${port}`;
17
25
  const cbp = cbpPlatform(url);
@@ -38,8 +46,8 @@ const main = () => {
38
46
  MessageId: event.msg_id,
39
47
  MessageText: msg,
40
48
  OpenId: data?.code,
41
- CreateAt: Date.now(),
42
- tag: 'MESSAGES_DIRECT',
49
+ BotId: botId,
50
+ _tag: 'MESSAGES_DIRECT',
43
51
  value: event
44
52
  };
45
53
  cbp.send(e);
@@ -51,12 +59,12 @@ const main = () => {
51
59
  const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
52
60
  const avatar = event.extra.author.avatar;
53
61
  let msg = event.content;
54
- const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
55
- for (const item of mention_role_part) {
62
+ const mentionRolePart = event.extra.kmarkdown?.mention_role_part ?? [];
63
+ for (const item of mentionRolePart) {
56
64
  msg = msg.replace(`(rol)${item.role_id}(rol)`, '').trim();
57
65
  }
58
- const mention_part = event.extra.kmarkdown?.mention_part ?? [];
59
- for (const item of mention_part) {
66
+ const mentionPart = event.extra.kmarkdown?.mention_part ?? [];
67
+ for (const item of mentionPart) {
60
68
  msg = msg.replace(`(met)${item.id}(met)`, '').trim();
61
69
  }
62
70
  const UserAvatar = avatar.substring(0, avatar.indexOf('?'));
@@ -77,8 +85,8 @@ const main = () => {
77
85
  MessageId: event.msg_id,
78
86
  MessageText: msg,
79
87
  OpenId: data?.code,
80
- CreateAt: Date.now(),
81
- tag: 'MESSAGES_PUBLIC',
88
+ BotId: botId,
89
+ _tag: 'MESSAGES_PUBLIC',
82
90
  value: event
83
91
  };
84
92
  cbp.send(e);
@@ -86,11 +94,253 @@ const main = () => {
86
94
  client.on('ERROR', msg => {
87
95
  console.error(msg);
88
96
  });
97
+ client.on('REACTIONS', event => {
98
+ const reactionType = event.extra?.type;
99
+ const body = event.extra?.body;
100
+ if (!body) {
101
+ return;
102
+ }
103
+ if (reactionType === 'added_reaction') {
104
+ const e = {
105
+ name: 'message.reaction.add',
106
+ Platform: platform,
107
+ GuildId: body.channel_id ?? '',
108
+ ChannelId: body.channel_id ?? '',
109
+ SpaceId: body.channel_id ?? '',
110
+ MessageId: body.msg_id ?? '',
111
+ BotId: botId,
112
+ _tag: 'REACTIONS_ADD',
113
+ value: event
114
+ };
115
+ cbp.send(e);
116
+ }
117
+ else if (reactionType === 'deleted_reaction') {
118
+ const e = {
119
+ name: 'message.reaction.remove',
120
+ Platform: platform,
121
+ GuildId: body.channel_id ?? '',
122
+ ChannelId: body.channel_id ?? '',
123
+ SpaceId: body.channel_id ?? '',
124
+ MessageId: body.msg_id ?? '',
125
+ BotId: botId,
126
+ _tag: 'REACTIONS_REMOVE',
127
+ value: event
128
+ };
129
+ cbp.send(e);
130
+ }
131
+ });
132
+ client.on('MEMBER_ADD', event => {
133
+ const body = event.extra?.body;
134
+ if (!body) {
135
+ return;
136
+ }
137
+ const UserId = body.user_id ?? event.author_id;
138
+ const [isMaster, UserKey] = getMaster(UserId);
139
+ const e = {
140
+ name: 'member.add',
141
+ Platform: platform,
142
+ GuildId: event.target_id ?? '',
143
+ ChannelId: '',
144
+ SpaceId: event.target_id ?? '',
145
+ UserId: UserId,
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);
155
+ });
156
+ client.on('MEMBER_REMOVE', event => {
157
+ const body = event.extra?.body;
158
+ if (!body) {
159
+ return;
160
+ }
161
+ const UserId = body.user_id ?? event.author_id;
162
+ const [isMaster, UserKey] = getMaster(UserId);
163
+ const e = {
164
+ name: 'member.remove',
165
+ Platform: platform,
166
+ GuildId: event.target_id ?? '',
167
+ ChannelId: '',
168
+ SpaceId: event.target_id ?? '',
169
+ UserId: UserId,
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);
179
+ });
180
+ client.on('MESSAGES_UPDATE', event => {
181
+ const body = event.extra?.body;
182
+ if (!body) {
183
+ return;
184
+ }
185
+ const e = {
186
+ name: 'message.update',
187
+ Platform: platform,
188
+ GuildId: body.channel_id ?? event.target_id ?? '',
189
+ ChannelId: body.channel_id ?? event.target_id ?? '',
190
+ SpaceId: body.channel_id ?? event.target_id ?? '',
191
+ UserId: body.author_id ?? event.author_id ?? '',
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);
201
+ });
202
+ client.on('MESSAGES_DELETE', event => {
203
+ const body = event.extra?.body;
204
+ if (!body) {
205
+ return;
206
+ }
207
+ const e = {
208
+ name: 'message.delete',
209
+ Platform: platform,
210
+ GuildId: body.channel_id ?? event.target_id ?? '',
211
+ ChannelId: body.channel_id ?? event.target_id ?? '',
212
+ SpaceId: body.channel_id ?? event.target_id ?? '',
213
+ MessageId: body.msg_id ?? event.msg_id ?? '',
214
+ BotId: botId,
215
+ _tag: 'MESSAGES_DELETE',
216
+ value: event
217
+ };
218
+ cbp.send(e);
219
+ });
220
+ client.on('MESSAGES_PIN', event => {
221
+ const body = event.extra?.body;
222
+ if (!body) {
223
+ return;
224
+ }
225
+ const e = {
226
+ name: 'message.pin',
227
+ Platform: platform,
228
+ GuildId: body.channel_id ?? event.target_id ?? '',
229
+ ChannelId: body.channel_id ?? event.target_id ?? '',
230
+ SpaceId: body.channel_id ?? event.target_id ?? '',
231
+ MessageId: body.msg_id ?? event.msg_id ?? '',
232
+ BotId: botId,
233
+ _tag: 'MESSAGES_PIN',
234
+ value: event
235
+ };
236
+ cbp.send(e);
237
+ });
238
+ client.on('GUILD_JOIN', event => {
239
+ const body = event.extra?.body;
240
+ const e = {
241
+ name: 'guild.join',
242
+ Platform: platform,
243
+ GuildId: body?.guild_id ?? event.target_id ?? '',
244
+ ChannelId: '',
245
+ SpaceId: body?.guild_id ?? event.target_id ?? '',
246
+ UserId: event.author_id ?? '',
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);
256
+ });
257
+ client.on('GUILD_EXIT', event => {
258
+ const body = event.extra?.body;
259
+ const e = {
260
+ name: 'guild.exit',
261
+ Platform: platform,
262
+ GuildId: body?.guild_id ?? event.target_id ?? '',
263
+ ChannelId: '',
264
+ SpaceId: body?.guild_id ?? event.target_id ?? '',
265
+ UserId: event.author_id ?? '',
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);
275
+ });
276
+ client.on('CHANNEL_CREATE', event => {
277
+ const body = event.extra?.body;
278
+ if (!body) {
279
+ return;
280
+ }
281
+ const e = {
282
+ name: 'channel.create',
283
+ Platform: platform,
284
+ GuildId: body.guild_id ?? event.target_id ?? '',
285
+ ChannelId: body.id ?? '',
286
+ SpaceId: body.guild_id ?? event.target_id ?? '',
287
+ MessageId: event.msg_id ?? '',
288
+ BotId: botId,
289
+ _tag: 'CHANNEL_CREATE',
290
+ value: event
291
+ };
292
+ cbp.send(e);
293
+ });
294
+ client.on('CHANNEL_DELETE', event => {
295
+ const body = event.extra?.body;
296
+ if (!body) {
297
+ return;
298
+ }
299
+ const e = {
300
+ name: 'channel.delete',
301
+ Platform: platform,
302
+ GuildId: body.guild_id ?? event.target_id ?? '',
303
+ ChannelId: body.id ?? '',
304
+ SpaceId: body.guild_id ?? event.target_id ?? '',
305
+ MessageId: event.msg_id ?? '',
306
+ BotId: botId,
307
+ _tag: 'CHANNEL_DELETE',
308
+ value: event
309
+ };
310
+ cbp.send(e);
311
+ });
312
+ client.on('CHANNEL_UPDATE', event => {
313
+ const body = event.extra?.body;
314
+ if (!body) {
315
+ return;
316
+ }
317
+ const e = {
318
+ name: 'channel.update',
319
+ Platform: platform,
320
+ GuildId: body.guild_id ?? event.target_id ?? '',
321
+ ChannelId: body.id ?? '',
322
+ SpaceId: body.guild_id ?? event.target_id ?? '',
323
+ MessageId: event.msg_id ?? '',
324
+ BotId: botId,
325
+ _tag: 'CHANNEL_UPDATE',
326
+ value: event
327
+ };
328
+ cbp.send(e);
329
+ });
89
330
  const formatKookContent = (val) => {
90
- return val
91
- .filter(item => item.type === 'Mention' || item.type === 'Text')
331
+ const nativeItems = val.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link');
332
+ const unsupportedItems = val.filter(item => item.type !== 'Mention'
333
+ && item.type !== 'Text'
334
+ && item.type !== 'Link'
335
+ && item.type !== 'Image'
336
+ && item.type !== 'ImageURL'
337
+ && item.type !== 'ImageFile');
338
+ const nativeText = nativeItems
92
339
  .map(item => {
93
- if (item.type === 'Mention') {
340
+ if (item.type === 'Link') {
341
+ return `[${item.value}](${item?.options?.link ?? item.value})`;
342
+ }
343
+ else if (item.type === 'Mention') {
94
344
  if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
95
345
  return '(met)all(met)';
96
346
  }
@@ -123,6 +373,10 @@ const main = () => {
123
373
  return '';
124
374
  })
125
375
  .join('');
376
+ const fallbackText = unsupportedItems.length > 0
377
+ ? unsupportedItems.map(item => dataEnumToKMarkdown(item)).filter(Boolean).join('')
378
+ : '';
379
+ return [nativeText, fallbackText].filter(Boolean).join('');
126
380
  };
127
381
  const resolveImageBuffer = async (val) => {
128
382
  const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
@@ -167,25 +421,38 @@ const main = () => {
167
421
  const url = imageRes.data?.url;
168
422
  return url || null;
169
423
  };
170
- const sendChannel = async (target_id, val) => {
424
+ const sendChannel = async (targetId, val) => {
171
425
  if (!val || val.length <= 0) {
172
426
  return [];
173
427
  }
174
428
  const content = formatKookContent(val);
175
429
  try {
430
+ const imageUrl = await uploadAndGetImageUrl(val);
431
+ if (imageUrl && content) {
432
+ const imgRes = await client.createMessage({
433
+ type: 2,
434
+ target_id: targetId,
435
+ content: imageUrl
436
+ });
437
+ const txtRes = await client.createMessage({
438
+ type: 9,
439
+ target_id: targetId,
440
+ content: content
441
+ });
442
+ return [createResult(ResultCode.Ok, 'client.createMessage', imgRes), createResult(ResultCode.Ok, 'client.createMessage', txtRes)];
443
+ }
176
444
  if (content) {
177
445
  const res = await client.createMessage({
178
446
  type: 9,
179
- target_id: target_id,
447
+ target_id: targetId,
180
448
  content: content
181
449
  });
182
450
  return [createResult(ResultCode.Ok, 'client.createMessage', res)];
183
451
  }
184
- const imageUrl = await uploadAndGetImageUrl(val);
185
452
  if (imageUrl) {
186
453
  const res = await client.createMessage({
187
454
  type: 2,
188
- target_id: target_id,
455
+ target_id: targetId,
189
456
  content: imageUrl
190
457
  });
191
458
  return [createResult(ResultCode.Ok, 'client.createMessage', res)];
@@ -196,25 +463,38 @@ const main = () => {
196
463
  return [createResult(ResultCode.Fail, 'client.createMessage', error)];
197
464
  }
198
465
  };
199
- const sendUser = async (open_id, val) => {
466
+ const sendUser = async (openId, val) => {
200
467
  if (!val || val.length <= 0) {
201
468
  return [];
202
469
  }
203
470
  const content = formatKookContent(val);
204
471
  try {
472
+ const imageUrl = await uploadAndGetImageUrl(val);
473
+ if (imageUrl && content) {
474
+ const imgRes = await client.createDirectMessage({
475
+ type: 2,
476
+ chat_code: openId,
477
+ content: imageUrl
478
+ });
479
+ const txtRes = await client.createDirectMessage({
480
+ type: 9,
481
+ chat_code: openId,
482
+ content: content
483
+ });
484
+ return [createResult(ResultCode.Ok, 'client.createDirectMessage', imgRes), createResult(ResultCode.Ok, 'client.createDirectMessage', txtRes)];
485
+ }
205
486
  if (content) {
206
487
  const res = await client.createDirectMessage({
207
488
  type: 9,
208
- chat_code: open_id,
489
+ chat_code: openId,
209
490
  content: content
210
491
  });
211
492
  return [createResult(ResultCode.Ok, 'client.createDirectMessage', res)];
212
493
  }
213
- const imageUrl = await uploadAndGetImageUrl(val);
214
494
  if (imageUrl) {
215
495
  const res = await client.createDirectMessage({
216
496
  type: 2,
217
- chat_code: open_id,
497
+ chat_code: openId,
218
498
  content: imageUrl
219
499
  });
220
500
  return [createResult(ResultCode.Ok, 'client.createDirectMessage', res)];
@@ -248,8 +528,8 @@ const main = () => {
248
528
  mention: e => {
249
529
  const event = e.value;
250
530
  const MessageMention = [];
251
- const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
252
- for (const item of mention_role_part) {
531
+ const mentionRolePart = event.extra.kmarkdown?.mention_role_part ?? [];
532
+ for (const item of mentionRolePart) {
253
533
  const UserId = item.role_id;
254
534
  const [isMaster, UserKey] = getMaster(UserId);
255
535
  MessageMention.push({
@@ -260,8 +540,8 @@ const main = () => {
260
540
  IsBot: true
261
541
  });
262
542
  }
263
- const mention_part = event.extra.kmarkdown?.mention_part ?? [];
264
- for (const item of mention_part) {
543
+ const mentionPart = event.extra.kmarkdown?.mention_part ?? [];
544
+ for (const item of mentionPart) {
265
545
  const UserId = item.id;
266
546
  const [isMaster, UserKey] = getMaster(UserId);
267
547
  MessageMention.push({
@@ -291,9 +571,9 @@ const main = () => {
291
571
  consume(res.map(item => createResult(ResultCode.Ok, '请求完成', item)));
292
572
  }
293
573
  else if (data.action === 'message.send.channel') {
294
- const channel_id = data.payload.ChannelId;
574
+ const channelId = data.payload.ChannelId;
295
575
  const val = data.payload.params.format;
296
- const res = await api.active.send.channel(channel_id, val);
576
+ const res = await api.active.send.channel(channelId, val);
297
577
  if (!res) {
298
578
  consume([createResult(ResultCode.Ok, '请求完成', null)]);
299
579
  return;
@@ -39,12 +39,12 @@ const ConversationMap = {
39
39
  return '';
40
40
  }
41
41
  else if (event.extra.type === 'exited_channel') {
42
- console.info('111exited_channel');
42
+ console.info('exited_channel');
43
43
  return '';
44
44
  }
45
45
  else if (event.extra.type === 'updated_channel') {
46
46
  console.info('updated_channel');
47
- return '';
47
+ return KOOKEventKey['CHANNEL_UPDATE'];
48
48
  }
49
49
  else if (event.extra.type === 'joined_guild') {
50
50
  console.info('joined_guild');
@@ -54,13 +54,33 @@ const ConversationMap = {
54
54
  console.info('exited_guild');
55
55
  return KOOKEventKey['MEMBER_REMOVE'];
56
56
  }
57
+ else if (event.extra.type === 'self_joined_guild') {
58
+ console.info('self_joined_guild');
59
+ return KOOKEventKey['GUILD_JOIN'];
60
+ }
61
+ else if (event.extra.type === 'self_exited_guild') {
62
+ console.info('self_exited_guild');
63
+ return KOOKEventKey['GUILD_EXIT'];
64
+ }
65
+ else if (event.extra.type === 'added_channel') {
66
+ console.info('added_channel');
67
+ return KOOKEventKey['CHANNEL_CREATE'];
68
+ }
69
+ else if (event.extra.type === 'deleted_channel') {
70
+ console.info('deleted_channel');
71
+ return KOOKEventKey['CHANNEL_DELETE'];
72
+ }
57
73
  else if (event.extra.type === 'updated_message') {
58
74
  console.info('updated_message');
59
- return '';
75
+ return KOOKEventKey['MESSAGES_UPDATE'];
76
+ }
77
+ else if (event.extra.type === 'deleted_message') {
78
+ console.info('deleted_message');
79
+ return KOOKEventKey['MESSAGES_DELETE'];
60
80
  }
61
81
  else if (event.extra.type === 'pinned_message') {
62
82
  console.info('pinned_message');
63
- return '';
83
+ return KOOKEventKey['MESSAGES_PIN'];
64
84
  }
65
85
  },
66
86
  direct: (event) => {
@@ -11,6 +11,14 @@ export declare const KOOKEventKey: {
11
11
  MESSAGES_DIRECT: string;
12
12
  MESSAGES_PUBLIC: string;
13
13
  REACTIONS: string;
14
+ MESSAGES_UPDATE: string;
15
+ MESSAGES_DELETE: string;
16
+ MESSAGES_PIN: string;
17
+ CHANNEL_CREATE: string;
18
+ CHANNEL_DELETE: string;
19
+ CHANNEL_UPDATE: string;
20
+ GUILD_JOIN: string;
21
+ GUILD_EXIT: string;
14
22
  ERROR: string;
15
23
  };
16
24
  export type KOOKEventMap = {
@@ -20,5 +28,13 @@ export type KOOKEventMap = {
20
28
  MESSAGES_DIRECT: MESSAGES_DIRECT_TYPE;
21
29
  MESSAGES_PUBLIC: MESSAGES_PUBLIC_TYPE;
22
30
  REACTIONS: REACTIONS_TYPE;
31
+ MESSAGES_UPDATE: any;
32
+ MESSAGES_DELETE: any;
33
+ MESSAGES_PIN: any;
34
+ CHANNEL_CREATE: any;
35
+ CHANNEL_DELETE: any;
36
+ CHANNEL_UPDATE: any;
37
+ GUILD_JOIN: any;
38
+ GUILD_EXIT: any;
23
39
  ERROR: any;
24
40
  };
@@ -5,6 +5,14 @@ const KOOKEventKey = {
5
5
  MESSAGES_DIRECT: 'MESSAGES_DIRECT',
6
6
  MESSAGES_PUBLIC: 'MESSAGES_PUBLIC',
7
7
  REACTIONS: 'REACTIONS',
8
+ MESSAGES_UPDATE: 'MESSAGES_UPDATE',
9
+ MESSAGES_DELETE: 'MESSAGES_DELETE',
10
+ MESSAGES_PIN: 'MESSAGES_PIN',
11
+ CHANNEL_CREATE: 'CHANNEL_CREATE',
12
+ CHANNEL_DELETE: 'CHANNEL_DELETE',
13
+ CHANNEL_UPDATE: 'CHANNEL_UPDATE',
14
+ GUILD_JOIN: 'GUILD_JOIN',
15
+ GUILD_EXIT: 'GUILD_EXIT',
8
16
  ERROR: 'ERROR'
9
17
  };
10
18
 
@@ -255,4 +255,4 @@ export interface EditingData {
255
255
  embeds: any[];
256
256
  msg_id: string;
257
257
  }
258
- export declare const SystemDataEnum: readonly ["exited_guild", "joined_guild", "joined_channel", "exited_channel", "updated_channel", "pinned_message", "guild_member_online", "added_reaction", "deleted_reaction", "updated_message", "message_btn_click"];
258
+ export declare const SystemDataEnum: readonly ["joined_guild", "exited_guild", "self_joined_guild", "self_exited_guild", "joined_channel", "exited_channel", "updated_channel", "added_channel", "deleted_channel", "pinned_message", "deleted_message", "guild_member_online", "added_reaction", "deleted_reaction", "updated_message", "message_btn_click"];
@@ -77,12 +77,17 @@ var ApiEnum;
77
77
  ApiEnum["GatewayIndex"] = "/api/v3/gateway/index";
78
78
  })(ApiEnum || (ApiEnum = {}));
79
79
  const SystemDataEnum = [
80
- 'exited_guild',
81
80
  'joined_guild',
81
+ 'exited_guild',
82
+ 'self_joined_guild',
83
+ 'self_exited_guild',
82
84
  'joined_channel',
83
85
  'exited_channel',
84
86
  'updated_channel',
87
+ 'added_channel',
88
+ 'deleted_channel',
85
89
  'pinned_message',
90
+ 'deleted_message',
86
91
  'guild_member_online',
87
92
  'added_reaction',
88
93
  'deleted_reaction',
package/lib/sdk/wss.js CHANGED
@@ -83,7 +83,12 @@ class KOOKClient extends KOOKAPI {
83
83
  console.info('[ws] Connection failed, reconnect');
84
84
  this.#isConnected = false;
85
85
  this.#sessionId = null;
86
- console.info('[ws] sessionId', this.#sessionId);
86
+ if (this.#heartbeatInterval) {
87
+ clearInterval(this.#heartbeatInterval);
88
+ this.#heartbeatInterval = null;
89
+ }
90
+ this.#ws.close();
91
+ void this.connect();
87
92
  },
88
93
  6: () => {
89
94
  console.info('[ws] resume ack');
@@ -120,6 +125,13 @@ class KOOKClient extends KOOKAPI {
120
125
  this.#heartbeatInterval = null;
121
126
  }
122
127
  console.error('[ws] close');
128
+ if (this.#isConnected) {
129
+ this.#isConnected = false;
130
+ this.#sessionId = null;
131
+ setTimeout(() => {
132
+ void this.connect();
133
+ }, 5000);
134
+ }
123
135
  });
124
136
  this.#ws.on('error', err => {
125
137
  console.error('[ws] error', err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/kook",
3
- "version": "2.1.0-alpha.4",
3
+ "version": "2.1.1",
4
4
  "description": "kook platform connection",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",