@alemonjs/qq-bot 2.1.12 → 2.1.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/register.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cbpPlatform, ResultCode, createResult } from 'alemonjs';
1
+ import { cbpPlatform, FormatEvent, ResultCode, createResult } from 'alemonjs';
2
2
  import { GROUP_AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, AT_MESSAGE_CREATE, MESSAGE_CREATE } from './sends.js';
3
3
  import { getQQBotConfig, platform, getMaster } from './config.js';
4
4
 
@@ -12,89 +12,60 @@ const register = (client) => {
12
12
  return `https://q.qlogo.cn/qqapp/${config.app_id}/${authorId}/640`;
13
13
  };
14
14
  client.on('GROUP_ADD_ROBOT', event => {
15
- const e = {
16
- name: 'guild.join',
17
- Platform: platform,
18
- GuildId: event.group_openid,
19
- ChannelId: event.group_openid,
20
- SpaceId: `GROUP:${event.group_openid}`,
15
+ cbp.send(FormatEvent.create('guild.join')
16
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
17
+ .addGuild({ GuildId: event.group_openid, SpaceId: `GROUP:${event.group_openid}` })
18
+ .addChannel({ ChannelId: event.group_openid })
19
+ .addUser({
21
20
  UserId: event.op_member_openid,
22
21
  UserKey: event.op_member_openid,
23
22
  UserAvatar: createUserAvatarURL(event.op_member_openid),
24
23
  IsMaster: false,
25
- IsBot: false,
26
- OpenId: `C2C:${event.op_member_openid}`,
27
- MessageId: '',
28
- BotId: botId,
29
- _tag: 'GROUP_ADD_ROBOT',
30
- value: event
31
- };
32
- cbp.send(e);
24
+ IsBot: false
25
+ })
26
+ .addMessage({ MessageId: '' })
27
+ .add({ tag: 'GROUP_ADD_ROBOT' }).value);
33
28
  });
34
29
  client.on('GROUP_DEL_ROBOT', event => {
35
- const e = {
36
- name: 'guild.exit',
37
- Platform: platform,
38
- GuildId: event.group_openid,
39
- ChannelId: event.group_openid,
40
- SpaceId: `GROUP:${event.group_openid}`,
30
+ cbp.send(FormatEvent.create('guild.exit')
31
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
32
+ .addGuild({ GuildId: event.group_openid, SpaceId: `GROUP:${event.group_openid}` })
33
+ .addChannel({ ChannelId: event.group_openid })
34
+ .addUser({
41
35
  UserId: event.op_member_openid,
42
36
  UserKey: event.op_member_openid,
43
37
  UserAvatar: createUserAvatarURL(event.op_member_openid),
44
38
  IsMaster: false,
45
- IsBot: false,
46
- OpenId: `C2C:${event.op_member_openid}`,
47
- MessageId: '',
48
- BotId: botId,
49
- _tag: 'GROUP_DEL_ROBOT',
50
- value: event
51
- };
52
- cbp.send(e);
39
+ IsBot: false
40
+ })
41
+ .addMessage({ MessageId: '' })
42
+ .add({ tag: 'GROUP_DEL_ROBOT' }).value);
53
43
  });
54
44
  client.on('GROUP_AT_MESSAGE_CREATE', event => {
55
45
  const UserId = event.author.id;
56
46
  const [isMaster, UserKey] = getMaster(UserId);
57
47
  const UserAvatar = createUserAvatarURL(event.author.id);
58
- const e = {
59
- name: 'message.create',
60
- Platform: platform,
61
- GuildId: event.group_id,
62
- ChannelId: event.group_id,
63
- SpaceId: `GROUP:${event.group_id}`,
64
- UserId: event.author.id,
65
- UserKey,
66
- UserAvatar: UserAvatar,
67
- IsMaster: isMaster,
68
- IsBot: false,
69
- MessageId: event.id,
70
- MessageText: event.content?.trim(),
71
- OpenId: `C2C:${event.author.member_openid}`,
72
- BotId: botId,
73
- _tag: 'GROUP_AT_MESSAGE_CREATE',
74
- value: event
75
- };
76
- cbp.send(e);
48
+ cbp.send(FormatEvent.create('message.create')
49
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
50
+ .addGuild({ GuildId: event.group_id, SpaceId: `GROUP:${event.group_id}` })
51
+ .addChannel({ ChannelId: event.group_id })
52
+ .addUser({ UserId: event.author.id, UserKey, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
53
+ .addMessage({ MessageId: event.id })
54
+ .addText({ MessageText: event.content?.trim() })
55
+ .addOpen({ OpenId: `C2C:${event.author.member_openid}` })
56
+ .add({ tag: 'GROUP_AT_MESSAGE_CREATE' }).value);
77
57
  });
78
58
  client.on('C2C_MESSAGE_CREATE', event => {
79
59
  const UserId = event.author.id;
80
60
  const [isMaster, UserKey] = getMaster(UserId);
81
61
  const UserAvatar = createUserAvatarURL(event.author.id);
82
- const e = {
83
- name: 'private.message.create',
84
- Platform: platform,
85
- UserId: event.author.id,
86
- UserKey,
87
- UserAvatar: UserAvatar,
88
- IsMaster: isMaster,
89
- IsBot: false,
90
- MessageId: event.id,
91
- MessageText: event.content?.trim(),
92
- OpenId: `C2C:${event.author.user_openid}`,
93
- BotId: botId,
94
- _tag: 'C2C_MESSAGE_CREATE',
95
- value: event
96
- };
97
- cbp.send(e);
62
+ cbp.send(FormatEvent.create('private.message.create')
63
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
64
+ .addUser({ UserId: event.author.id, UserKey, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
65
+ .addMessage({ MessageId: event.id })
66
+ .addText({ MessageText: event.content?.trim() })
67
+ .addOpen({ OpenId: `C2C:${event.author.user_openid}` })
68
+ .add({ tag: 'C2C_MESSAGE_CREATE' }).value);
98
69
  });
99
70
  client.on('DIRECT_MESSAGE_CREATE', event => {
100
71
  if (event?.author?.bot) {
@@ -104,23 +75,20 @@ const register = (client) => {
104
75
  const UserAvatar = event?.author?.avatar;
105
76
  const UserId = event.author.id;
106
77
  const [isMaster, UserKey] = getMaster(UserId);
107
- const e = {
108
- name: 'private.message.create',
109
- Platform: platform,
78
+ cbp.send(FormatEvent.create('private.message.create')
79
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
80
+ .addUser({
110
81
  UserId: event?.author?.id ?? '',
111
82
  UserKey,
112
83
  UserName: event?.author?.username ?? '',
113
84
  UserAvatar: UserAvatar,
114
85
  IsMaster: isMaster,
115
- IsBot: event.author?.bot,
116
- MessageId: event.id,
117
- MessageText: msg?.trim(),
118
- OpenId: `DIRECT:${event.guild_id}`,
119
- BotId: botId,
120
- _tag: 'DIRECT_MESSAGE_CREATE',
121
- value: event
122
- };
123
- cbp.send(e);
86
+ IsBot: event.author?.bot
87
+ })
88
+ .addMessage({ MessageId: event.id })
89
+ .addText({ MessageText: msg?.trim() })
90
+ .addOpen({ OpenId: `DIRECT:${event.guild_id}` })
91
+ .add({ tag: 'DIRECT_MESSAGE_CREATE' }).value);
124
92
  });
125
93
  client.on('AT_MESSAGE_CREATE', event => {
126
94
  if (event?.author?.bot) {
@@ -130,26 +98,22 @@ const register = (client) => {
130
98
  const UserAvatar = event?.author?.avatar;
131
99
  const UserId = event.author.id;
132
100
  const [isMaster, UserKey] = getMaster(UserId);
133
- const e = {
134
- name: 'message.create',
135
- Platform: platform,
136
- GuildId: event.guild_id,
137
- ChannelId: event.channel_id,
138
- SpaceId: `GUILD:${event.channel_id}`,
139
- IsMaster: isMaster,
101
+ cbp.send(FormatEvent.create('message.create')
102
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
103
+ .addGuild({ GuildId: event.guild_id, SpaceId: `GUILD:${event.channel_id}` })
104
+ .addChannel({ ChannelId: event.channel_id })
105
+ .addUser({
140
106
  UserId: event?.author?.id ?? '',
141
107
  UserKey,
142
108
  UserName: event?.author?.username ?? '',
143
109
  UserAvatar: UserAvatar,
144
- IsBot: event.author?.bot,
145
- MessageId: event.id,
146
- MessageText: msg?.trim(),
147
- OpenId: `DIRECT:${event.guild_id}`,
148
- BotId: botId,
149
- _tag: 'AT_MESSAGE_CREATE',
150
- value: event
151
- };
152
- cbp.send(e);
110
+ IsMaster: isMaster,
111
+ IsBot: event.author?.bot
112
+ })
113
+ .addMessage({ MessageId: event.id })
114
+ .addText({ MessageText: msg?.trim() })
115
+ .addOpen({ OpenId: `DIRECT:${event.guild_id}` })
116
+ .add({ tag: 'AT_MESSAGE_CREATE' }).value);
153
117
  });
154
118
  const getMessageContent = event => {
155
119
  let msg = event?.content ?? '';
@@ -177,26 +141,22 @@ const register = (client) => {
177
141
  const msg = getMessageContent(event);
178
142
  const UserAvatar = event?.author?.avatar;
179
143
  const [isMaster, UserKey] = getMaster(UserId);
180
- const e = {
181
- name: 'message.create',
182
- Platform: platform,
183
- GuildId: event.guild_id,
184
- ChannelId: event.channel_id,
185
- SpaceId: `GUILD:${event.channel_id}`,
144
+ cbp.send(FormatEvent.create('message.create')
145
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
146
+ .addGuild({ GuildId: event.guild_id, SpaceId: `GUILD:${event.channel_id}` })
147
+ .addChannel({ ChannelId: event.channel_id })
148
+ .addUser({
186
149
  UserId: event?.author?.id ?? '',
187
150
  UserKey,
188
151
  UserName: event?.author?.username ?? '',
189
152
  UserAvatar: UserAvatar,
190
153
  IsMaster: isMaster,
191
- IsBot: false,
192
- MessageId: event.id,
193
- MessageText: msg?.trim(),
194
- OpenId: `DIRECT:${event.guild_id}`,
195
- BotId: botId,
196
- _tag: 'MESSAGE_CREATE',
197
- value: event
198
- };
199
- cbp.send(e);
154
+ IsBot: false
155
+ })
156
+ .addMessage({ MessageId: event.id })
157
+ .addText({ MessageText: msg?.trim() })
158
+ .addOpen({ OpenId: `DIRECT:${event.guild_id}` })
159
+ .add({ tag: 'MESSAGE_CREATE' }).value);
200
160
  });
201
161
  client.on('INTERACTION_CREATE', event => {
202
162
  if (event.scene === 'group') {
@@ -204,24 +164,15 @@ const register = (client) => {
204
164
  const UserId = event.group_member_openid;
205
165
  const [isMaster, UserKey] = getMaster(UserId);
206
166
  const MessageText = event.data.resolved.button_data?.trim() || '';
207
- const e = {
208
- name: 'interaction.create',
209
- Platform: platform,
210
- GuildId: event.group_openid,
211
- ChannelId: event.group_openid,
212
- SpaceId: `GROUP:${event.group_openid}`,
213
- UserId: event.group_member_openid,
214
- UserKey,
215
- UserAvatar: UserAvatar,
216
- IsMaster: isMaster,
217
- IsBot: false,
218
- MessageId: `INTERACTION_CREATE:${event.id}`,
219
- MessageText: MessageText,
220
- OpenId: `C2C:${event.group_member_openid}`,
221
- BotId: botId,
222
- _tag: 'INTERACTION_CREATE_GROUP',
223
- value: event
224
- };
167
+ const e = FormatEvent.create('interaction.create')
168
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
169
+ .addGuild({ GuildId: event.group_openid, SpaceId: `GROUP:${event.group_openid}` })
170
+ .addChannel({ ChannelId: event.group_openid })
171
+ .addUser({ UserId: event.group_member_openid, UserKey, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
172
+ .addMessage({ MessageId: `INTERACTION_CREATE:${event.id}` })
173
+ .addText({ MessageText: MessageText })
174
+ .addOpen({ OpenId: `C2C:${event.group_member_openid}` })
175
+ .add({ tag: 'INTERACTION_CREATE_GROUP' }).value;
225
176
  cbp.send(e);
226
177
  }
227
178
  else if (event.scene === 'c2c') {
@@ -229,21 +180,13 @@ const register = (client) => {
229
180
  const UserId = event.user_openid;
230
181
  const [isMaster, UserKey] = getMaster(UserId);
231
182
  const MessageText = event.data.resolved.button_data?.trim() || '';
232
- const e = {
233
- name: 'private.interaction.create',
234
- Platform: platform,
235
- UserId: event.user_openid,
236
- UserKey,
237
- UserAvatar: UserAvatar,
238
- IsMaster: isMaster,
239
- IsBot: false,
240
- MessageId: event.id,
241
- MessageText: MessageText,
242
- OpenId: `C2C:${event.user_openid}`,
243
- BotId: botId,
244
- _tag: 'INTERACTION_CREATE_C2C',
245
- value: event
246
- };
183
+ const e = FormatEvent.create('private.interaction.create')
184
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
185
+ .addUser({ UserId: event.user_openid, UserKey, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
186
+ .addMessage({ MessageId: event.id })
187
+ .addText({ MessageText: MessageText })
188
+ .addOpen({ OpenId: `C2C:${event.user_openid}` })
189
+ .add({ tag: 'INTERACTION_CREATE_C2C' }).value;
247
190
  cbp.send(e);
248
191
  }
249
192
  else if (event.scene === 'guild') {
@@ -251,24 +194,15 @@ const register = (client) => {
251
194
  const UserId = event.data.resolved.user_id;
252
195
  const [isMaster, UserKey] = getMaster(UserId);
253
196
  const MessageText = event.data.resolved.button_data?.trim() || '';
254
- const e = {
255
- name: 'interaction.create',
256
- Platform: platform,
257
- GuildId: event.guild_id,
258
- ChannelId: event.channel_id,
259
- SpaceId: `GUILD:${event.channel_id}`,
260
- UserId: event.data.resolved.user_id,
261
- UserKey,
262
- UserAvatar: UserAvatar,
263
- IsMaster: isMaster,
264
- IsBot: false,
265
- MessageId: event.data.resolved.message_id,
266
- MessageText: MessageText,
267
- OpenId: `DIRECT:${event.guild_id}`,
268
- BotId: botId,
269
- _tag: 'INTERACTION_CREATE_GUILD',
270
- value: event
271
- };
197
+ const e = FormatEvent.create('interaction.create')
198
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
199
+ .addGuild({ GuildId: event.guild_id, SpaceId: `GUILD:${event.channel_id}` })
200
+ .addChannel({ ChannelId: event.channel_id })
201
+ .addUser({ UserId: event.data.resolved.user_id, UserKey, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
202
+ .addMessage({ MessageId: event.data.resolved.message_id })
203
+ .addText({ MessageText: MessageText })
204
+ .addOpen({ OpenId: `DIRECT:${event.guild_id}` })
205
+ .add({ tag: 'INTERACTION_CREATE_GUILD' }).value;
272
206
  cbp.send(e);
273
207
  }
274
208
  else {
@@ -281,331 +215,173 @@ const register = (client) => {
281
215
  });
282
216
  client.on('MESSAGE_DELETE', event => {
283
217
  const msg = event?.message ?? event;
284
- const e = {
285
- name: 'message.delete',
286
- Platform: platform,
287
- GuildId: msg?.guild_id ?? '',
288
- ChannelId: msg?.channel_id ?? '',
289
- SpaceId: `GUILD:${msg?.channel_id ?? ''}`,
290
- MessageId: msg?.id ?? '',
291
- BotId: botId,
292
- _tag: 'MESSAGE_DELETE',
293
- value: event
294
- };
295
- cbp.send(e);
218
+ cbp.send(FormatEvent.create('message.delete')
219
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
220
+ .addGuild({ GuildId: msg?.guild_id ?? '', SpaceId: `GUILD:${msg?.channel_id ?? ''}` })
221
+ .addChannel({ ChannelId: msg?.channel_id ?? '' })
222
+ .addMessage({ MessageId: msg?.id ?? '' })
223
+ .add({ tag: 'MESSAGE_DELETE' }).value);
296
224
  });
297
225
  client.on('PUBLIC_MESSAGE_DELETE', event => {
298
226
  const msg = event.message;
299
- const e = {
300
- name: 'message.delete',
301
- Platform: platform,
302
- GuildId: msg.guild_id ?? '',
303
- ChannelId: msg.channel_id ?? '',
304
- SpaceId: `GUILD:${msg.channel_id ?? ''}`,
305
- MessageId: msg.id ?? '',
306
- BotId: botId,
307
- _tag: 'PUBLIC_MESSAGE_DELETE',
308
- value: event
309
- };
310
- cbp.send(e);
227
+ cbp.send(FormatEvent.create('message.delete')
228
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
229
+ .addGuild({ GuildId: msg.guild_id ?? '', SpaceId: `GUILD:${msg.channel_id ?? ''}` })
230
+ .addChannel({ ChannelId: msg.channel_id ?? '' })
231
+ .addMessage({ MessageId: msg.id ?? '' })
232
+ .add({ tag: 'PUBLIC_MESSAGE_DELETE' }).value);
311
233
  });
312
234
  client.on('DIRECT_MESSAGE_DELETE', event => {
313
235
  const msg = event.message;
314
- const e = {
315
- name: 'private.message.delete',
316
- Platform: platform,
317
- MessageId: msg.id ?? '',
318
- BotId: botId,
319
- _tag: 'DIRECT_MESSAGE_DELETE',
320
- value: event
321
- };
322
- cbp.send(e);
236
+ cbp.send(FormatEvent.create('private.message.delete')
237
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
238
+ .addMessage({ MessageId: msg.id ?? '' })
239
+ .add({ tag: 'DIRECT_MESSAGE_DELETE' }).value);
323
240
  });
324
241
  client.on('MESSAGE_REACTION_ADD', event => {
325
- const e = {
326
- name: 'message.reaction.add',
327
- Platform: platform,
328
- GuildId: event.guild_id ?? '',
329
- ChannelId: event.channel_id ?? '',
330
- SpaceId: `GUILD:${event.channel_id ?? ''}`,
331
- MessageId: event.target?.id ?? '',
332
- BotId: botId,
333
- _tag: 'MESSAGE_REACTION_ADD',
334
- value: event
335
- };
336
- cbp.send(e);
242
+ cbp.send(FormatEvent.create('message.reaction.add')
243
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
244
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.channel_id ?? ''}` })
245
+ .addChannel({ ChannelId: event.channel_id ?? '' })
246
+ .addMessage({ MessageId: event.target?.id ?? '' })
247
+ .add({ tag: 'MESSAGE_REACTION_ADD' }).value);
337
248
  });
338
249
  client.on('MESSAGE_REACTION_REMOVE', event => {
339
- const e = {
340
- name: 'message.reaction.remove',
341
- Platform: platform,
342
- GuildId: event.guild_id ?? '',
343
- ChannelId: event.channel_id ?? '',
344
- SpaceId: `GUILD:${event.channel_id ?? ''}`,
345
- MessageId: event.target?.id ?? '',
346
- BotId: botId,
347
- _tag: 'MESSAGE_REACTION_REMOVE',
348
- value: event
349
- };
350
- cbp.send(e);
250
+ cbp.send(FormatEvent.create('message.reaction.remove')
251
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
252
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.channel_id ?? ''}` })
253
+ .addChannel({ ChannelId: event.channel_id ?? '' })
254
+ .addMessage({ MessageId: event.target?.id ?? '' })
255
+ .add({ tag: 'MESSAGE_REACTION_REMOVE' }).value);
351
256
  });
352
257
  client.on('CHANNEL_CREATE', event => {
353
- const e = {
354
- name: 'channel.create',
355
- Platform: platform,
356
- GuildId: event.guild_id ?? '',
357
- ChannelId: event.id ?? '',
358
- SpaceId: `GUILD:${event.guild_id ?? ''}`,
359
- MessageId: '',
360
- BotId: botId,
361
- _tag: 'CHANNEL_CREATE',
362
- value: event
363
- };
364
- cbp.send(e);
258
+ cbp.send(FormatEvent.create('channel.create')
259
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
260
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.guild_id ?? ''}` })
261
+ .addChannel({ ChannelId: event.id ?? '' })
262
+ .addMessage({ MessageId: '' })
263
+ .add({ tag: 'CHANNEL_CREATE' }).value);
365
264
  });
366
265
  client.on('CHANNEL_DELETE', event => {
367
- const e = {
368
- name: 'channel.delete',
369
- Platform: platform,
370
- GuildId: event.guild_id ?? '',
371
- ChannelId: event.id ?? '',
372
- SpaceId: `GUILD:${event.guild_id ?? ''}`,
373
- MessageId: '',
374
- BotId: botId,
375
- _tag: 'CHANNEL_DELETE',
376
- value: event
377
- };
378
- cbp.send(e);
266
+ cbp.send(FormatEvent.create('channel.delete')
267
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
268
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.guild_id ?? ''}` })
269
+ .addChannel({ ChannelId: event.id ?? '' })
270
+ .addMessage({ MessageId: '' })
271
+ .add({ tag: 'CHANNEL_DELETE' }).value);
379
272
  });
380
273
  client.on('GUILD_CREATE', event => {
381
- const e = {
382
- name: 'guild.join',
383
- Platform: platform,
384
- GuildId: event.id ?? '',
385
- ChannelId: '',
386
- SpaceId: `GUILD:${event.id ?? ''}`,
387
- UserId: event.op_user_id ?? '',
388
- UserKey: '',
389
- IsMaster: false,
390
- IsBot: false,
391
- MessageId: '',
392
- BotId: botId,
393
- _tag: 'GUILD_CREATE',
394
- value: event
395
- };
396
- cbp.send(e);
274
+ cbp.send(FormatEvent.create('guild.join')
275
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
276
+ .addGuild({ GuildId: event.id ?? '', SpaceId: `GUILD:${event.id ?? ''}` })
277
+ .addChannel({ ChannelId: '' })
278
+ .addUser({ UserId: event.op_user_id ?? '', UserKey: '', IsMaster: false, IsBot: false })
279
+ .addMessage({ MessageId: '' })
280
+ .add({ tag: 'GUILD_CREATE' }).value);
397
281
  });
398
282
  client.on('GUILD_DELETE', event => {
399
- const e = {
400
- name: 'guild.exit',
401
- Platform: platform,
402
- GuildId: event.id ?? '',
403
- ChannelId: '',
404
- SpaceId: `GUILD:${event.id ?? ''}`,
405
- UserId: event.op_user_id ?? '',
406
- UserKey: '',
407
- IsMaster: false,
408
- IsBot: false,
409
- MessageId: '',
410
- BotId: botId,
411
- _tag: 'GUILD_DELETE',
412
- value: event
413
- };
414
- cbp.send(e);
283
+ cbp.send(FormatEvent.create('guild.exit')
284
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
285
+ .addGuild({ GuildId: event.id ?? '', SpaceId: `GUILD:${event.id ?? ''}` })
286
+ .addChannel({ ChannelId: '' })
287
+ .addUser({ UserId: event.op_user_id ?? '', UserKey: '', IsMaster: false, IsBot: false })
288
+ .addMessage({ MessageId: '' })
289
+ .add({ tag: 'GUILD_DELETE' }).value);
415
290
  });
416
291
  client.on('GUILD_MEMBER_ADD', event => {
417
292
  const UserId = event.user?.id ?? '';
418
293
  const [isMaster, UserKey] = getMaster(UserId);
419
- const e = {
420
- name: 'member.add',
421
- Platform: platform,
422
- GuildId: event.guild_id ?? '',
423
- ChannelId: '',
424
- SpaceId: `GUILD:${event.guild_id ?? ''}`,
425
- UserId: UserId,
426
- UserKey,
427
- UserName: event.user?.username ?? '',
428
- UserAvatar: createUserAvatarURL(UserId),
429
- IsMaster: isMaster,
430
- IsBot: false,
431
- MessageId: '',
432
- BotId: botId,
433
- _tag: 'GUILD_MEMBER_ADD',
434
- value: event
435
- };
436
- cbp.send(e);
294
+ cbp.send(FormatEvent.create('member.add')
295
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
296
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.guild_id ?? ''}` })
297
+ .addChannel({ ChannelId: '' })
298
+ .addUser({ UserId: UserId, UserKey, UserName: event.user?.username ?? '', UserAvatar: createUserAvatarURL(UserId), IsMaster: isMaster, IsBot: false })
299
+ .addMessage({ MessageId: '' })
300
+ .add({ tag: 'GUILD_MEMBER_ADD' }).value);
437
301
  });
438
302
  client.on('GUILD_MEMBER_REMOVE', event => {
439
303
  const UserId = event.user?.id ?? '';
440
304
  const [isMaster, UserKey] = getMaster(UserId);
441
- const e = {
442
- name: 'member.remove',
443
- Platform: platform,
444
- GuildId: event.guild_id ?? '',
445
- ChannelId: '',
446
- SpaceId: `GUILD:${event.guild_id ?? ''}`,
447
- UserId: UserId,
448
- UserKey,
449
- UserName: event.user?.username ?? '',
450
- UserAvatar: createUserAvatarURL(UserId),
451
- IsMaster: isMaster,
452
- IsBot: false,
453
- MessageId: '',
454
- BotId: botId,
455
- _tag: 'GUILD_MEMBER_REMOVE',
456
- value: event
457
- };
458
- cbp.send(e);
305
+ cbp.send(FormatEvent.create('member.remove')
306
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
307
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.guild_id ?? ''}` })
308
+ .addChannel({ ChannelId: '' })
309
+ .addUser({ UserId: UserId, UserKey, UserName: event.user?.username ?? '', UserAvatar: createUserAvatarURL(UserId), IsMaster: isMaster, IsBot: false })
310
+ .addMessage({ MessageId: '' })
311
+ .add({ tag: 'GUILD_MEMBER_REMOVE' }).value);
459
312
  });
460
313
  client.on('GUILD_MEMBER_UPDATE', event => {
461
314
  const UserId = event.user?.id ?? '';
462
315
  const [isMaster, UserKey] = getMaster(UserId);
463
- const e = {
464
- name: 'member.update',
465
- Platform: platform,
466
- GuildId: event.guild_id ?? '',
467
- ChannelId: '',
468
- SpaceId: `GUILD:${event.guild_id ?? ''}`,
469
- UserId: UserId,
470
- UserKey,
471
- UserName: event.user?.username ?? '',
472
- UserAvatar: createUserAvatarURL(UserId),
473
- IsMaster: isMaster,
474
- IsBot: false,
475
- MessageId: '',
476
- BotId: botId,
477
- _tag: 'GUILD_MEMBER_UPDATE',
478
- value: event
479
- };
480
- cbp.send(e);
316
+ cbp.send(FormatEvent.create('member.update')
317
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
318
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.guild_id ?? ''}` })
319
+ .addChannel({ ChannelId: '' })
320
+ .addUser({ UserId: UserId, UserKey, UserName: event.user?.username ?? '', UserAvatar: createUserAvatarURL(UserId), IsMaster: isMaster, IsBot: false })
321
+ .addMessage({ MessageId: '' })
322
+ .add({ tag: 'GUILD_MEMBER_UPDATE' }).value);
481
323
  });
482
324
  client.on('FRIEND_ADD', event => {
483
- const e = {
484
- name: 'private.friend.add',
485
- Platform: platform,
486
- UserId: event.openid ?? '',
487
- UserKey: '',
488
- IsMaster: false,
489
- IsBot: false,
490
- MessageId: '',
491
- BotId: botId,
492
- _tag: 'FRIEND_ADD',
493
- value: event
494
- };
495
- cbp.send(e);
325
+ cbp.send(FormatEvent.create('private.friend.add')
326
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
327
+ .addUser({ UserId: event.openid ?? '', UserKey: '', IsMaster: false, IsBot: false })
328
+ .addMessage({ MessageId: '' })
329
+ .add({ tag: 'FRIEND_ADD' }).value);
496
330
  });
497
331
  client.on('FRIEND_DEL', event => {
498
- const e = {
499
- name: 'private.friend.remove',
500
- Platform: platform,
501
- UserId: event.openid ?? '',
502
- UserKey: '',
503
- IsMaster: false,
504
- IsBot: false,
505
- MessageId: '',
506
- BotId: botId,
507
- _tag: 'FRIEND_DEL',
508
- value: event
509
- };
510
- cbp.send(e);
332
+ cbp.send(FormatEvent.create('private.friend.remove')
333
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
334
+ .addUser({ UserId: event.openid ?? '', UserKey: '', IsMaster: false, IsBot: false })
335
+ .addMessage({ MessageId: '' })
336
+ .add({ tag: 'FRIEND_DEL' }).value);
511
337
  });
512
338
  client.on('CHANNEL_UPDATE', event => {
513
- const e = {
514
- name: 'channel.update',
515
- Platform: platform,
516
- GuildId: event.guild_id ?? '',
517
- ChannelId: event.id ?? '',
518
- SpaceId: `GUILD:${event.guild_id ?? ''}`,
519
- MessageId: '',
520
- BotId: botId,
521
- _tag: 'CHANNEL_UPDATE',
522
- value: event
523
- };
524
- cbp.send(e);
339
+ cbp.send(FormatEvent.create('channel.update')
340
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
341
+ .addGuild({ GuildId: event.guild_id ?? '', SpaceId: `GUILD:${event.guild_id ?? ''}` })
342
+ .addChannel({ ChannelId: event.id ?? '' })
343
+ .addMessage({ MessageId: '' })
344
+ .add({ tag: 'CHANNEL_UPDATE' }).value);
525
345
  });
526
346
  client.on('GUILD_UPDATE', event => {
527
- const e = {
528
- name: 'guild.update',
529
- Platform: platform,
530
- GuildId: event.id ?? '',
531
- ChannelId: '',
532
- SpaceId: `GUILD:${event.id ?? ''}`,
533
- MessageId: '',
534
- BotId: botId,
535
- _tag: 'GUILD_UPDATE',
536
- value: event
537
- };
538
- cbp.send(e);
347
+ cbp.send(FormatEvent.create('guild.update')
348
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
349
+ .addGuild({ GuildId: event.id ?? '', SpaceId: `GUILD:${event.id ?? ''}` })
350
+ .addChannel({ ChannelId: '' })
351
+ .addMessage({ MessageId: '' })
352
+ .add({ tag: 'GUILD_UPDATE' }).value);
539
353
  });
540
354
  client.on('GROUP_MSG_RECEIVE', event => {
541
- const e = {
542
- name: 'notice.create',
543
- Platform: platform,
544
- GuildId: event.group_openid,
545
- ChannelId: event.group_openid,
546
- SpaceId: `GROUP:${event.group_openid}`,
547
- UserId: event.op_member_openid,
548
- UserKey: '',
549
- IsMaster: false,
550
- IsBot: false,
551
- MessageId: `group_msg_receive_${event.group_openid}_${event.timestamp}`,
552
- MessageText: '',
553
- OpenId: `C2C:${event.op_member_openid}`,
554
- BotId: botId,
555
- _tag: 'GROUP_MSG_RECEIVE',
556
- value: event
557
- };
558
- cbp.send(e);
355
+ cbp.send(FormatEvent.create('notice.create')
356
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
357
+ .addGuild({ GuildId: event.group_openid, SpaceId: `GROUP:${event.group_openid}` })
358
+ .addChannel({ ChannelId: event.group_openid })
359
+ .addUser({ UserId: event.op_member_openid, UserKey: '', IsMaster: false, IsBot: false })
360
+ .addMessage({ MessageId: `group_msg_receive_${event.group_openid}_${event.timestamp}` })
361
+ .add({ tag: 'GROUP_MSG_RECEIVE' }).value);
559
362
  });
560
363
  client.on('GROUP_MSG_REJECT', event => {
561
- const e = {
562
- name: 'notice.create',
563
- Platform: platform,
564
- GuildId: event.group_openid,
565
- ChannelId: event.group_openid,
566
- SpaceId: `GROUP:${event.group_openid}`,
567
- UserId: event.op_member_openid,
568
- UserKey: '',
569
- IsMaster: false,
570
- IsBot: false,
571
- MessageId: `group_msg_reject_${event.group_openid}_${event.timestamp}`,
572
- MessageText: '',
573
- OpenId: `C2C:${event.op_member_openid}`,
574
- BotId: botId,
575
- _tag: 'GROUP_MSG_REJECT',
576
- value: event
577
- };
578
- cbp.send(e);
364
+ cbp.send(FormatEvent.create('notice.create')
365
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
366
+ .addGuild({ GuildId: event.group_openid, SpaceId: `GROUP:${event.group_openid}` })
367
+ .addChannel({ ChannelId: event.group_openid })
368
+ .addUser({ UserId: event.op_member_openid, UserKey: '', IsMaster: false, IsBot: false })
369
+ .addMessage({ MessageId: `group_msg_reject_${event.group_openid}_${event.timestamp}` })
370
+ .add({ tag: 'GROUP_MSG_REJECT' }).value);
579
371
  });
580
372
  client.on('C2C_MSG_RECEIVE', event => {
581
- const e = {
582
- name: 'private.notice.create',
583
- Platform: platform,
584
- UserId: event.openid ?? '',
585
- UserKey: '',
586
- IsMaster: false,
587
- IsBot: false,
588
- MessageId: `c2c_msg_receive_${event.openid}_${event.timestamp}`,
589
- BotId: botId,
590
- _tag: 'C2C_MSG_RECEIVE',
591
- value: event
592
- };
593
- cbp.send(e);
373
+ cbp.send(FormatEvent.create('private.notice.create')
374
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
375
+ .addUser({ UserId: event.openid ?? '', UserKey: '', IsMaster: false, IsBot: false })
376
+ .addMessage({ MessageId: `c2c_msg_receive_${event.openid}_${event.timestamp}` })
377
+ .add({ tag: 'C2C_MSG_RECEIVE' }).value);
594
378
  });
595
379
  client.on('C2C_MSG_REJECT', event => {
596
- const e = {
597
- name: 'private.notice.create',
598
- Platform: platform,
599
- UserId: event.openid ?? '',
600
- UserKey: '',
601
- IsMaster: false,
602
- IsBot: false,
603
- MessageId: `c2c_msg_reject_${event.openid}_${event.timestamp}`,
604
- BotId: botId,
605
- _tag: 'C2C_MSG_REJECT',
606
- value: event
607
- };
608
- cbp.send(e);
380
+ cbp.send(FormatEvent.create('private.notice.create')
381
+ .addPlatform({ Platform: platform, value: event, BotId: botId })
382
+ .addUser({ UserId: event.openid ?? '', UserKey: '', IsMaster: false, IsBot: false })
383
+ .addMessage({ MessageId: `c2c_msg_reject_${event.openid}_${event.timestamp}` })
384
+ .add({ tag: 'C2C_MSG_REJECT' }).value);
609
385
  });
610
386
  client.on('ERROR', console.error);
611
387
  const api = {
@@ -1052,18 +828,26 @@ const register = (client) => {
1052
828
  cbp.onactions((data, consume) => void onactions(data, consume));
1053
829
  const onapis = async (data, consume) => {
1054
830
  const key = data.payload?.key;
1055
- if (client[key]) {
1056
- const params = data.payload.params;
1057
- try {
1058
- const res = await client[key](...params);
1059
- consume([createResult(ResultCode.Ok, '请求完成', res)]);
831
+ const params = data.payload?.params;
832
+ try {
833
+ const keys = key.split('.');
834
+ let target = client;
835
+ for (const k of keys) {
836
+ if (target === null || target === undefined || !(k in target)) {
837
+ consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
838
+ return;
839
+ }
840
+ target = target[k];
1060
841
  }
1061
- catch (error) {
1062
- consume([createResult(ResultCode.Fail, '请求失败', error)]);
842
+ if (typeof target !== 'function') {
843
+ consume([createResult(ResultCode.Fail, '目标不是可调用方法', null)]);
844
+ return;
1063
845
  }
846
+ const res = await target(...params);
847
+ consume([createResult(ResultCode.Ok, '请求完成', res)]);
1064
848
  }
1065
- else {
1066
- consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
849
+ catch (error) {
850
+ consume([createResult(ResultCode.Fail, '请求失败', error)]);
1067
851
  }
1068
852
  };
1069
853
  cbp.onapis((data, consume) => void onapis(data, consume));