@alemonjs/qq-bot 2.1.11 → 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/dist/assets/index.css +1 -1
- package/dist/assets/index.js +5 -5
- package/lib/config.d.ts +1 -1
- package/lib/config.js +7 -2
- package/lib/desktop.js +4 -4
- package/lib/hook.js +1 -1
- package/lib/register.js +230 -446
- package/package.json +2 -2
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
27
|
-
MessageId: ''
|
|
28
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
47
|
-
MessageId: ''
|
|
48
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
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
|
-
|
|
1062
|
-
consume([createResult(ResultCode.Fail, '
|
|
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
|
-
|
|
1066
|
-
consume([createResult(ResultCode.Fail, '
|
|
849
|
+
catch (error) {
|
|
850
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
1067
851
|
}
|
|
1068
852
|
};
|
|
1069
853
|
cbp.onapis((data, consume) => void onapis(data, consume));
|