@alemonjs/qq-bot 2.1.0-alpha.8 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -45
- package/lib/config.d.ts +8 -0
- package/lib/config.js +20 -0
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +3 -12
- package/lib/hook.d.ts +36 -9
- package/lib/hook.js +21 -19
- package/lib/index.d.ts +5 -7
- package/lib/index.js +11 -21
- package/lib/index.webhook.d.ts +1 -0
- package/lib/index.webhook.js +5 -4
- package/lib/index.websoket.d.ts +1 -0
- package/lib/index.websoket.js +31 -23
- package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -0
- package/lib/message/AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/CHANNEL_CREATE.d.ts +15 -0
- package/lib/message/CHANNEL_CREATE.js +1 -0
- package/lib/message/CHANNEL_DELETE.d.ts +15 -0
- package/lib/message/CHANNEL_DELETE.js +1 -0
- package/lib/message/CHANNEL_UPDATE.d.ts +15 -0
- package/lib/message/CHANNEL_UPDATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -0
- package/lib/message/ERROR.d.ts +1 -0
- package/lib/message/ERROR.js +1 -0
- package/lib/message/GUILD_CREATE.d.ts +15 -0
- package/lib/message/GUILD_CREATE.js +1 -0
- package/lib/message/GUILD_DELETE.d.ts +15 -0
- package/lib/message/GUILD_DELETE.js +1 -0
- package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/message/GUILD_UPDATE.d.ts +15 -0
- package/lib/message/GUILD_UPDATE.js +1 -0
- package/lib/message/INTERACTION_CREATE.d.ts +53 -0
- package/lib/message/INTERACTION_CREATE.js +1 -0
- package/lib/message/MESSAGE_CREATE.d.ts +1 -0
- package/lib/message/MESSAGE_CREATE.js +1 -0
- package/lib/message/MESSAGE_DELETE.d.ts +1 -0
- package/lib/message/MESSAGE_DELETE.js +1 -0
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -0
- package/lib/message/READY.d.ts +6 -0
- package/lib/message/READY.js +1 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +9 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/C2C_MSG_RECEIVE.d.ts +4 -0
- package/lib/message/group/C2C_MSG_RECEIVE.js +1 -0
- package/lib/message/group/C2C_MSG_REJECT.d.ts +4 -0
- package/lib/message/group/C2C_MSG_REJECT.js +1 -0
- package/lib/message/group/FRIEND_ADD.d.ts +4 -0
- package/lib/message/group/FRIEND_ADD.js +1 -0
- package/lib/message/group/FRIEND_DEL.d.ts +4 -0
- package/lib/message/group/FRIEND_DEL.js +1 -0
- package/lib/message/group/GROUP_ADD_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_ADD_ROBOT.js +1 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +11 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/GROUP_DEL_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_DEL_ROBOT.js +1 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -0
- package/lib/message/group/GROUP_MSG_REJECT.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_REJECT.js +1 -0
- package/lib/register.d.ts +2 -3
- package/lib/register.js +427 -252
- package/lib/sdk/api.d.ts +10 -567
- package/lib/sdk/api.js +234 -796
- package/lib/sdk/client.webhook.d.ts +9 -0
- package/lib/sdk/{client.js → client.webhook.js} +18 -55
- package/lib/sdk/client.websoket.d.ts +9 -0
- package/lib/sdk/client.websoket.js +52 -97
- package/lib/sdk/config.d.ts +1 -0
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +93 -0
- package/lib/sdk/intents.d.ts +3 -0
- package/lib/sdk/intents.js +25 -90
- package/lib/sdk/message.d.ts +4 -0
- package/lib/sdk/message.group.d.ts +24 -0
- package/lib/sdk/message.group.js +1 -0
- package/lib/sdk/message.guild.d.ts +38 -0
- package/lib/sdk/message.guild.js +1 -0
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/message.public.d.ts +6 -0
- package/lib/sdk/message.public.js +1 -0
- package/lib/sdk/typing.d.ts +22 -11
- package/lib/sdk/typing.js +1 -0
- package/lib/sdk/webhook.secret.d.ts +14 -0
- package/lib/sdk/webhook.secret.js +6 -21
- package/lib/sends.d.ts +29 -0
- package/lib/sends.js +326 -745
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +7 -12
- package/package.json +9 -5
- package/lib/index.group.js +0 -19
- package/lib/index.guild.js +0 -36
- package/lib/sdk/client.websoket.group.js +0 -221
- package/lib/sdk/client.websoket.guild.js +0 -205
- package/lib/sdk/counter.js +0 -19
- package/lib/sdk/from.js +0 -44
package/lib/register.js
CHANGED
|
@@ -1,344 +1,272 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cbpPlatform, 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
|
+
import { getQQBotConfig, platform, getMaster } from './config.js';
|
|
3
4
|
|
|
4
|
-
// import dayjs from 'dayjs'
|
|
5
|
-
const platform = 'qq-bot';
|
|
6
|
-
const getQQBotConfig = () => {
|
|
7
|
-
let value = getConfigValue();
|
|
8
|
-
if (!value)
|
|
9
|
-
value = {};
|
|
10
|
-
return value[platform] || {};
|
|
11
|
-
};
|
|
12
5
|
const register = (client) => {
|
|
13
6
|
const config = getQQBotConfig();
|
|
14
|
-
|
|
15
|
-
* 连接 alemonjs 服务器。
|
|
16
|
-
* 向 alemonjs 推送标准信息
|
|
17
|
-
*/
|
|
7
|
+
const botId = String(config?.app_id ?? '');
|
|
18
8
|
const port = process.env?.port || config?.port || 17117;
|
|
19
9
|
const url = `ws://127.0.0.1:${port}`;
|
|
20
10
|
const cbp = cbpPlatform(url);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
* GROUP_AT_MESSAGE_CREATE
|
|
25
|
-
* C2C_MESSAGE_CREATE
|
|
26
|
-
*/
|
|
27
|
-
const createUserAvatarURL = (author_id) => {
|
|
28
|
-
return `https://q.qlogo.cn/qqapp/${config.app_id}/${author_id}/640`;
|
|
11
|
+
const createUserAvatarURL = (authorId) => {
|
|
12
|
+
return `https://q.qlogo.cn/qqapp/${config.app_id}/${authorId}/640`;
|
|
29
13
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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}`,
|
|
21
|
+
UserId: event.op_member_openid,
|
|
22
|
+
UserKey: event.op_member_openid,
|
|
23
|
+
UserAvatar: createUserAvatarURL(event.op_member_openid),
|
|
24
|
+
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);
|
|
33
|
+
});
|
|
34
|
+
client.on('GROUP_DEL_ROBOT', event => {
|
|
35
|
+
const e = {
|
|
36
|
+
name: 'guild.exit',
|
|
37
37
|
Platform: platform,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
GuildId: event.group_openid,
|
|
39
|
+
ChannelId: event.group_openid,
|
|
40
|
+
SpaceId: `GROUP:${event.group_openid}`,
|
|
41
|
+
UserId: event.op_member_openid,
|
|
42
|
+
UserKey: event.op_member_openid,
|
|
43
|
+
UserAvatar: createUserAvatarURL(event.op_member_openid),
|
|
44
|
+
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);
|
|
53
|
+
});
|
|
54
|
+
client.on('GROUP_AT_MESSAGE_CREATE', event => {
|
|
55
|
+
const UserId = event.author.id;
|
|
56
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
57
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
41
58
|
const e = {
|
|
42
59
|
name: 'message.create',
|
|
43
60
|
Platform: platform,
|
|
44
|
-
// guild
|
|
45
61
|
GuildId: event.group_id,
|
|
46
62
|
ChannelId: event.group_id,
|
|
47
|
-
|
|
63
|
+
SpaceId: `GROUP:${event.group_id}`,
|
|
48
64
|
UserId: event.author.id,
|
|
49
65
|
UserKey,
|
|
50
66
|
UserAvatar: UserAvatar,
|
|
51
67
|
IsMaster: isMaster,
|
|
52
68
|
IsBot: false,
|
|
53
|
-
// 格式化数据
|
|
54
69
|
MessageId: event.id,
|
|
55
70
|
MessageText: event.content?.trim(),
|
|
56
|
-
OpenId: event.author.member_openid
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
OpenId: `C2C:${event.author.member_openid}`,
|
|
72
|
+
BotId: botId,
|
|
73
|
+
_tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
59
74
|
value: event
|
|
60
75
|
};
|
|
61
76
|
cbp.send(e);
|
|
62
77
|
});
|
|
63
|
-
client.on('C2C_MESSAGE_CREATE',
|
|
64
|
-
const master_key = config?.master_key ?? [];
|
|
65
|
-
const isMaster = master_key.includes(event.author.id);
|
|
66
|
-
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
78
|
+
client.on('C2C_MESSAGE_CREATE', event => {
|
|
67
79
|
const UserId = event.author.id;
|
|
68
|
-
const UserKey =
|
|
69
|
-
|
|
70
|
-
UserId: UserId
|
|
71
|
-
});
|
|
72
|
-
// 定义消
|
|
80
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
81
|
+
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
73
82
|
const e = {
|
|
74
83
|
name: 'private.message.create',
|
|
75
|
-
// 事件类型
|
|
76
84
|
Platform: platform,
|
|
77
|
-
// 用户Id
|
|
78
85
|
UserId: event.author.id,
|
|
79
86
|
UserKey,
|
|
80
87
|
UserAvatar: UserAvatar,
|
|
81
88
|
IsMaster: isMaster,
|
|
82
89
|
IsBot: false,
|
|
83
|
-
// 格式化数据
|
|
84
90
|
MessageId: event.id,
|
|
85
91
|
MessageText: event.content?.trim(),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
tag: 'C2C_MESSAGE_CREATE',
|
|
92
|
+
OpenId: `C2C:${event.author.user_openid}`,
|
|
93
|
+
BotId: botId,
|
|
94
|
+
_tag: 'C2C_MESSAGE_CREATE',
|
|
90
95
|
value: event
|
|
91
96
|
};
|
|
92
97
|
cbp.send(e);
|
|
93
98
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*/
|
|
97
|
-
client.on('DIRECT_MESSAGE_CREATE', async (event) => {
|
|
98
|
-
// 屏蔽其他机器人的消息
|
|
99
|
-
if (event?.author?.bot)
|
|
99
|
+
client.on('DIRECT_MESSAGE_CREATE', event => {
|
|
100
|
+
if (event?.author?.bot) {
|
|
100
101
|
return;
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
let msg = event?.content ?? '';
|
|
102
|
+
}
|
|
103
|
+
const msg = event?.content ?? '';
|
|
104
104
|
const UserAvatar = event?.author?.avatar;
|
|
105
105
|
const UserId = event.author.id;
|
|
106
|
-
const UserKey =
|
|
107
|
-
Platform: platform,
|
|
108
|
-
UserId: UserId
|
|
109
|
-
});
|
|
110
|
-
// 定义消
|
|
106
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
111
107
|
const e = {
|
|
112
108
|
name: 'private.message.create',
|
|
113
|
-
// 事件类型
|
|
114
109
|
Platform: platform,
|
|
115
|
-
//
|
|
116
|
-
// GuildId: event.guild_id,
|
|
117
|
-
// ChannelId: event.channel_id,
|
|
118
|
-
// 用户Id
|
|
119
110
|
UserId: event?.author?.id ?? '',
|
|
120
111
|
UserKey,
|
|
121
112
|
UserName: event?.author?.username ?? '',
|
|
122
113
|
UserAvatar: UserAvatar,
|
|
123
114
|
IsMaster: isMaster,
|
|
124
115
|
IsBot: event.author?.bot,
|
|
125
|
-
// message
|
|
126
116
|
MessageId: event.id,
|
|
127
117
|
MessageText: msg?.trim(),
|
|
128
|
-
OpenId: event.guild_id
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
tag: 'DIRECT_MESSAGE_CREATE',
|
|
118
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
119
|
+
BotId: botId,
|
|
120
|
+
_tag: 'DIRECT_MESSAGE_CREATE',
|
|
132
121
|
value: event
|
|
133
122
|
};
|
|
134
123
|
cbp.send(e);
|
|
135
124
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// 屏蔽其他机器人的消息
|
|
139
|
-
if (event?.author?.bot)
|
|
125
|
+
client.on('AT_MESSAGE_CREATE', event => {
|
|
126
|
+
if (event?.author?.bot) {
|
|
140
127
|
return;
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
let msg = getMessageContent(event);
|
|
128
|
+
}
|
|
129
|
+
const msg = getMessageContent(event);
|
|
144
130
|
const UserAvatar = event?.author?.avatar;
|
|
145
131
|
const UserId = event.author.id;
|
|
146
|
-
const UserKey =
|
|
147
|
-
Platform: platform,
|
|
148
|
-
UserId: UserId
|
|
149
|
-
});
|
|
150
|
-
// 定义消
|
|
132
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
151
133
|
const e = {
|
|
152
134
|
name: 'message.create',
|
|
153
|
-
// 事件类型
|
|
154
135
|
Platform: platform,
|
|
155
136
|
GuildId: event.guild_id,
|
|
156
137
|
ChannelId: event.channel_id,
|
|
138
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
157
139
|
IsMaster: isMaster,
|
|
158
|
-
// 用户Id
|
|
159
140
|
UserId: event?.author?.id ?? '',
|
|
160
141
|
UserKey,
|
|
161
142
|
UserName: event?.author?.username ?? '',
|
|
162
143
|
UserAvatar: UserAvatar,
|
|
163
144
|
IsBot: event.author?.bot,
|
|
164
|
-
// message
|
|
165
145
|
MessageId: event.id,
|
|
166
146
|
MessageText: msg?.trim(),
|
|
167
|
-
OpenId: event.guild_id
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
tag: 'AT_MESSAGE_CREATE',
|
|
147
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
148
|
+
BotId: botId,
|
|
149
|
+
_tag: 'AT_MESSAGE_CREATE',
|
|
171
150
|
value: event
|
|
172
151
|
};
|
|
173
152
|
cbp.send(e);
|
|
174
153
|
});
|
|
175
|
-
/**
|
|
176
|
-
*
|
|
177
|
-
* @param event
|
|
178
|
-
* @returns
|
|
179
|
-
*/
|
|
180
154
|
const getMessageContent = event => {
|
|
181
155
|
let msg = event?.content ?? '';
|
|
182
|
-
|
|
183
|
-
const at_users = [];
|
|
156
|
+
const atUsers = [];
|
|
184
157
|
if (event.mentions) {
|
|
185
|
-
// 去掉@ 转为纯消息
|
|
186
158
|
for (const item of event.mentions) {
|
|
187
|
-
|
|
159
|
+
atUsers.push({
|
|
188
160
|
id: item.id
|
|
189
161
|
});
|
|
190
162
|
}
|
|
191
|
-
|
|
192
|
-
at_users.forEach(item => {
|
|
163
|
+
atUsers.forEach(item => {
|
|
193
164
|
msg = msg.replace(`<@!${item.id}>`, '').trim();
|
|
194
165
|
});
|
|
195
166
|
}
|
|
196
167
|
return msg;
|
|
197
168
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
// 屏蔽其他机器人的消息
|
|
201
|
-
if (event.author?.bot)
|
|
169
|
+
client.on('MESSAGE_CREATE', event => {
|
|
170
|
+
if (event.author?.bot) {
|
|
202
171
|
return;
|
|
203
|
-
|
|
204
|
-
if (new RegExp(/DELETE$/).test(event.eventType))
|
|
172
|
+
}
|
|
173
|
+
if (new RegExp(/DELETE$/).test(event.eventType)) {
|
|
205
174
|
return;
|
|
206
|
-
|
|
175
|
+
}
|
|
207
176
|
const UserId = event.author.id;
|
|
208
|
-
const isMaster = master_key.includes(UserId);
|
|
209
177
|
const msg = getMessageContent(event);
|
|
210
178
|
const UserAvatar = event?.author?.avatar;
|
|
211
|
-
const UserKey =
|
|
212
|
-
Platform: platform,
|
|
213
|
-
UserId: UserId
|
|
214
|
-
});
|
|
215
|
-
// 定义消
|
|
179
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
216
180
|
const e = {
|
|
217
181
|
name: 'message.create',
|
|
218
|
-
// 事件类型
|
|
219
182
|
Platform: platform,
|
|
220
|
-
//
|
|
221
183
|
GuildId: event.guild_id,
|
|
222
184
|
ChannelId: event.channel_id,
|
|
185
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
223
186
|
UserId: event?.author?.id ?? '',
|
|
224
187
|
UserKey,
|
|
225
188
|
UserName: event?.author?.username ?? '',
|
|
226
189
|
UserAvatar: UserAvatar,
|
|
227
190
|
IsMaster: isMaster,
|
|
228
191
|
IsBot: false,
|
|
229
|
-
// message
|
|
230
192
|
MessageId: event.id,
|
|
231
193
|
MessageText: msg?.trim(),
|
|
232
|
-
OpenId: event.guild_id
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
tag: 'MESSAGE_CREATE',
|
|
194
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
195
|
+
BotId: botId,
|
|
196
|
+
_tag: 'MESSAGE_CREATE',
|
|
236
197
|
value: event
|
|
237
198
|
};
|
|
238
199
|
cbp.send(e);
|
|
239
200
|
});
|
|
240
|
-
client.on('INTERACTION_CREATE',
|
|
241
|
-
// try {
|
|
242
|
-
// if (event.scene === 'group' || event.scene === 'c2c') {
|
|
243
|
-
// await client.interactionResponse('group', event.id)
|
|
244
|
-
// }
|
|
245
|
-
// else if (event.scene === 'guild') {
|
|
246
|
-
// await client.interactionResponse('guild', event.id)
|
|
247
|
-
// }
|
|
248
|
-
// } catch (err) {
|
|
249
|
-
// createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
250
|
-
// }
|
|
201
|
+
client.on('INTERACTION_CREATE', event => {
|
|
251
202
|
if (event.scene === 'group') {
|
|
252
|
-
const master_key = config?.master_key ?? [];
|
|
253
|
-
const isMaster = master_key.includes(event.group_member_openid);
|
|
254
203
|
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
255
204
|
const UserId = event.group_member_openid;
|
|
256
|
-
const UserKey =
|
|
257
|
-
Platform: platform,
|
|
258
|
-
UserId: UserId
|
|
259
|
-
});
|
|
205
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
260
206
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
261
207
|
const e = {
|
|
262
208
|
name: 'interaction.create',
|
|
263
209
|
Platform: platform,
|
|
264
|
-
// guild
|
|
265
210
|
GuildId: event.group_openid,
|
|
266
211
|
ChannelId: event.group_openid,
|
|
267
|
-
|
|
212
|
+
SpaceId: `GROUP:${event.group_openid}`,
|
|
268
213
|
UserId: event.group_member_openid,
|
|
269
214
|
UserKey,
|
|
270
215
|
UserAvatar: UserAvatar,
|
|
271
216
|
IsMaster: isMaster,
|
|
272
217
|
IsBot: false,
|
|
273
|
-
|
|
274
|
-
MessageId: event.id,
|
|
218
|
+
MessageId: `INTERACTION_CREATE:${event.id}`,
|
|
275
219
|
MessageText: MessageText,
|
|
276
|
-
OpenId: event.group_member_openid
|
|
277
|
-
|
|
278
|
-
|
|
220
|
+
OpenId: `C2C:${event.group_member_openid}`,
|
|
221
|
+
BotId: botId,
|
|
222
|
+
_tag: 'INTERACTION_CREATE_GROUP',
|
|
279
223
|
value: event
|
|
280
224
|
};
|
|
281
225
|
cbp.send(e);
|
|
282
226
|
}
|
|
283
227
|
else if (event.scene === 'c2c') {
|
|
284
|
-
const master_key = config?.master_key ?? [];
|
|
285
|
-
const isMaster = master_key.includes(event.user_openid);
|
|
286
228
|
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
287
229
|
const UserId = event.user_openid;
|
|
288
|
-
const UserKey =
|
|
289
|
-
Platform: platform,
|
|
290
|
-
UserId: UserId
|
|
291
|
-
});
|
|
230
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
292
231
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
293
|
-
// 处理消息
|
|
294
232
|
const e = {
|
|
295
233
|
name: 'private.interaction.create',
|
|
296
234
|
Platform: platform,
|
|
297
|
-
// 用户Id
|
|
298
235
|
UserId: event.user_openid,
|
|
299
236
|
UserKey,
|
|
300
237
|
UserAvatar: UserAvatar,
|
|
301
238
|
IsMaster: isMaster,
|
|
302
239
|
IsBot: false,
|
|
303
|
-
// 格式化数据
|
|
304
240
|
MessageId: event.id,
|
|
305
241
|
MessageText: MessageText,
|
|
306
|
-
OpenId: event.user_openid
|
|
307
|
-
|
|
308
|
-
|
|
242
|
+
OpenId: `C2C:${event.user_openid}`,
|
|
243
|
+
BotId: botId,
|
|
244
|
+
_tag: 'INTERACTION_CREATE_C2C',
|
|
309
245
|
value: event
|
|
310
246
|
};
|
|
311
247
|
cbp.send(e);
|
|
312
248
|
}
|
|
313
249
|
else if (event.scene === 'guild') {
|
|
314
|
-
const master_key = config?.master_key ?? [];
|
|
315
|
-
const isMaster = master_key.includes(event.data.resolved.user_id);
|
|
316
250
|
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
317
251
|
const UserId = event.data.resolved.user_id;
|
|
318
|
-
const UserKey =
|
|
319
|
-
Platform: platform,
|
|
320
|
-
UserId: UserId
|
|
321
|
-
});
|
|
252
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
322
253
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
323
|
-
// 处理消息
|
|
324
254
|
const e = {
|
|
325
255
|
name: 'interaction.create',
|
|
326
256
|
Platform: platform,
|
|
327
|
-
// guild
|
|
328
257
|
GuildId: event.guild_id,
|
|
329
258
|
ChannelId: event.channel_id,
|
|
330
|
-
|
|
259
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
331
260
|
UserId: event.data.resolved.user_id,
|
|
332
261
|
UserKey,
|
|
333
262
|
UserAvatar: UserAvatar,
|
|
334
263
|
IsMaster: isMaster,
|
|
335
264
|
IsBot: false,
|
|
336
|
-
// 格式化数据
|
|
337
265
|
MessageId: event.data.resolved.message_id,
|
|
338
266
|
MessageText: MessageText,
|
|
339
|
-
OpenId: event.guild_id
|
|
340
|
-
|
|
341
|
-
|
|
267
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
268
|
+
BotId: botId,
|
|
269
|
+
_tag: 'INTERACTION_CREATE_GUILD',
|
|
342
270
|
value: event
|
|
343
271
|
};
|
|
344
272
|
cbp.send(e);
|
|
@@ -351,119 +279,366 @@ const register = (client) => {
|
|
|
351
279
|
});
|
|
352
280
|
}
|
|
353
281
|
});
|
|
282
|
+
client.on('MESSAGE_DELETE', event => {
|
|
283
|
+
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);
|
|
296
|
+
});
|
|
297
|
+
client.on('PUBLIC_MESSAGE_DELETE', event => {
|
|
298
|
+
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);
|
|
311
|
+
});
|
|
312
|
+
client.on('DIRECT_MESSAGE_DELETE', event => {
|
|
313
|
+
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);
|
|
323
|
+
});
|
|
324
|
+
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);
|
|
337
|
+
});
|
|
338
|
+
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);
|
|
351
|
+
});
|
|
352
|
+
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);
|
|
365
|
+
});
|
|
366
|
+
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);
|
|
379
|
+
});
|
|
380
|
+
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);
|
|
397
|
+
});
|
|
398
|
+
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);
|
|
415
|
+
});
|
|
416
|
+
client.on('GUILD_MEMBER_ADD', event => {
|
|
417
|
+
const UserId = event.user?.id ?? '';
|
|
418
|
+
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);
|
|
437
|
+
});
|
|
438
|
+
client.on('GUILD_MEMBER_REMOVE', event => {
|
|
439
|
+
const UserId = event.user?.id ?? '';
|
|
440
|
+
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);
|
|
459
|
+
});
|
|
460
|
+
client.on('FRIEND_ADD', event => {
|
|
461
|
+
const e = {
|
|
462
|
+
name: 'private.friend.add',
|
|
463
|
+
Platform: platform,
|
|
464
|
+
UserId: event.openid ?? '',
|
|
465
|
+
UserKey: '',
|
|
466
|
+
IsMaster: false,
|
|
467
|
+
IsBot: false,
|
|
468
|
+
MessageId: '',
|
|
469
|
+
BotId: botId,
|
|
470
|
+
_tag: 'FRIEND_ADD',
|
|
471
|
+
value: event
|
|
472
|
+
};
|
|
473
|
+
cbp.send(e);
|
|
474
|
+
});
|
|
354
475
|
client.on('ERROR', console.error);
|
|
355
476
|
const api = {
|
|
356
477
|
active: {
|
|
357
478
|
send: {
|
|
358
|
-
channel: async (
|
|
359
|
-
if (
|
|
360
|
-
|
|
479
|
+
channel: async (SpaceId, val) => {
|
|
480
|
+
if (/^GUILD:/.test(SpaceId)) {
|
|
481
|
+
const id = SpaceId.replace('GUILD:', '');
|
|
482
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
483
|
+
ChannelId: id
|
|
484
|
+
}, val);
|
|
485
|
+
}
|
|
486
|
+
if (/^GROUP:/.test(SpaceId)) {
|
|
487
|
+
const id = SpaceId.replace('GROUP:', '');
|
|
488
|
+
return await GROUP_AT_MESSAGE_CREATE(client, {
|
|
489
|
+
ChannelId: id
|
|
490
|
+
}, val);
|
|
361
491
|
}
|
|
362
|
-
return
|
|
363
|
-
ChannelId: channel_id
|
|
364
|
-
}, val);
|
|
492
|
+
return [];
|
|
365
493
|
},
|
|
366
|
-
user: async (
|
|
367
|
-
if (
|
|
368
|
-
|
|
494
|
+
user: async (OpenId, val) => {
|
|
495
|
+
if (/^C2C:/.test(OpenId)) {
|
|
496
|
+
const id = OpenId.replace('C2C:', '');
|
|
497
|
+
return await C2C_MESSAGE_CREATE(client, {
|
|
498
|
+
UserId: id
|
|
499
|
+
}, val);
|
|
369
500
|
}
|
|
370
|
-
|
|
371
|
-
OpenId:
|
|
372
|
-
|
|
501
|
+
else if (/^DIRECT:/.test(OpenId)) {
|
|
502
|
+
const id = OpenId.replace('DIRECT:', '');
|
|
503
|
+
return await DIRECT_MESSAGE_CREATE(client, {
|
|
504
|
+
UserId: id
|
|
505
|
+
}, val);
|
|
506
|
+
}
|
|
507
|
+
else if (/^GUILD:/.test(OpenId)) {
|
|
508
|
+
const id = OpenId.replace('GUILD:', '');
|
|
509
|
+
return await AT_MESSAGE_CREATE(client, {
|
|
510
|
+
ChannelId: id
|
|
511
|
+
}, val);
|
|
512
|
+
}
|
|
513
|
+
return [];
|
|
373
514
|
}
|
|
374
515
|
}
|
|
375
516
|
},
|
|
376
517
|
use: {
|
|
377
518
|
send: async (event, val) => {
|
|
378
|
-
if (val.length
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const tag = event.
|
|
382
|
-
|
|
383
|
-
if (tag == 'GROUP_AT_MESSAGE_CREATE') {
|
|
519
|
+
if (!val || val.length <= 0) {
|
|
520
|
+
return [];
|
|
521
|
+
}
|
|
522
|
+
const tag = event._tag;
|
|
523
|
+
if (tag === 'GROUP_AT_MESSAGE_CREATE') {
|
|
384
524
|
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
385
525
|
}
|
|
386
|
-
|
|
387
|
-
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
526
|
+
if (tag === 'C2C_MESSAGE_CREATE') {
|
|
388
527
|
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
389
528
|
}
|
|
390
|
-
|
|
391
|
-
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
529
|
+
if (tag === 'DIRECT_MESSAGE_CREATE') {
|
|
392
530
|
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
393
531
|
}
|
|
394
|
-
|
|
395
|
-
if (tag == 'AT_MESSAGE_CREATE') {
|
|
532
|
+
if (tag === 'AT_MESSAGE_CREATE') {
|
|
396
533
|
return await AT_MESSAGE_CREATE(client, event, val);
|
|
397
534
|
}
|
|
398
|
-
|
|
399
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
535
|
+
if (tag === 'MESSAGE_CREATE') {
|
|
400
536
|
return await MESSAGE_CREATE(client, event, val);
|
|
401
537
|
}
|
|
402
|
-
|
|
403
|
-
if (tag == 'INTERACTION_CREATE_GROUP') {
|
|
538
|
+
if (tag === 'INTERACTION_CREATE_GROUP') {
|
|
404
539
|
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
405
540
|
}
|
|
406
|
-
if (tag
|
|
541
|
+
if (tag === 'INTERACTION_CREATE_C2C') {
|
|
407
542
|
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
408
543
|
}
|
|
409
|
-
if (tag
|
|
544
|
+
if (tag === 'INTERACTION_CREATE_GUILD') {
|
|
410
545
|
return await AT_MESSAGE_CREATE(client, event, val);
|
|
411
546
|
}
|
|
412
|
-
return
|
|
547
|
+
return [];
|
|
413
548
|
},
|
|
414
|
-
mention:
|
|
415
|
-
event.value || {};
|
|
416
|
-
event.
|
|
417
|
-
// const event = e.value
|
|
549
|
+
mention: event => {
|
|
550
|
+
const value = event.value || {};
|
|
551
|
+
const tag = event._tag;
|
|
418
552
|
const Metions = [];
|
|
419
|
-
|
|
420
|
-
|
|
553
|
+
if (tag === 'GROUP_AT_MESSAGE_CREATE' || tag === 'C2C_MESSAGE_CREATE') {
|
|
554
|
+
return new Promise(resolve => resolve(Metions));
|
|
555
|
+
}
|
|
556
|
+
if (value.mentions) {
|
|
557
|
+
const mentions = event.value['mentions'];
|
|
558
|
+
const MessageMention = mentions.map(item => {
|
|
559
|
+
const UserId = item.id;
|
|
560
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
561
|
+
return {
|
|
562
|
+
UserId: item.id,
|
|
563
|
+
IsMaster: isMaster,
|
|
564
|
+
UserName: item.username,
|
|
565
|
+
IsBot: item.bot,
|
|
566
|
+
UserKey: UserKey
|
|
567
|
+
};
|
|
568
|
+
});
|
|
569
|
+
return new Promise(resolve => resolve(MessageMention));
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
return new Promise(resolve => resolve(Metions));
|
|
573
|
+
}
|
|
421
574
|
}
|
|
422
575
|
}
|
|
423
576
|
};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
577
|
+
const onactions = async (data, consume) => {
|
|
578
|
+
try {
|
|
579
|
+
if (data.action === 'me.info') {
|
|
580
|
+
const res = await client.usersMe();
|
|
581
|
+
const UserId = res.id;
|
|
582
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
583
|
+
const botInfo = {
|
|
584
|
+
UserId: res?.id,
|
|
585
|
+
UserName: res?.username,
|
|
586
|
+
UserAvatar: createUserAvatarURL(res?.id),
|
|
587
|
+
IsBot: true,
|
|
588
|
+
IsMaster: isMaster,
|
|
589
|
+
UserKey: UserKey
|
|
590
|
+
};
|
|
591
|
+
consume([createResult(ResultCode.Ok, '请求完成', botInfo)]);
|
|
592
|
+
}
|
|
593
|
+
else if (data.action === 'message.send') {
|
|
594
|
+
const event = data.payload.event;
|
|
595
|
+
const paramFormat = data.payload.params.format;
|
|
596
|
+
const res = await api.use.send(event, paramFormat);
|
|
597
|
+
consume(res);
|
|
598
|
+
}
|
|
599
|
+
else if (data.action === 'mention.get') {
|
|
600
|
+
const event = data.payload.event;
|
|
601
|
+
const metions = await api.use.mention(event);
|
|
602
|
+
consume([createResult(ResultCode.Ok, '请求完成', metions)]);
|
|
603
|
+
}
|
|
604
|
+
else if (data.action === 'message.send.channel') {
|
|
605
|
+
const channelId = data.payload.ChannelId;
|
|
606
|
+
const paramFormat = data.payload.params.format;
|
|
607
|
+
const res = await api.active.send.channel(channelId, paramFormat);
|
|
608
|
+
consume(res);
|
|
609
|
+
}
|
|
610
|
+
else if (data.action === 'message.send.user') {
|
|
611
|
+
const userId = data.payload.UserId;
|
|
612
|
+
const paramFormat = data.payload.params.format;
|
|
613
|
+
const res = await api.active.send.user(userId, paramFormat);
|
|
614
|
+
consume(res);
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
618
|
+
}
|
|
447
619
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const user_id = data.payload.UserId;
|
|
451
|
-
const paramFormat = data.payload.params.format;
|
|
452
|
-
const res = await api.active.send.user(user_id, paramFormat);
|
|
453
|
-
consume(res);
|
|
620
|
+
catch (error) {
|
|
621
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
454
622
|
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const params = data.payload.params;
|
|
623
|
+
};
|
|
624
|
+
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
625
|
+
const onapis = async (data, consume) => {
|
|
626
|
+
const key = data.payload?.key;
|
|
627
|
+
if (client[key]) {
|
|
628
|
+
const params = data.payload.params;
|
|
629
|
+
try {
|
|
463
630
|
const res = await client[key](...params);
|
|
464
631
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
465
632
|
}
|
|
466
|
-
|
|
633
|
+
catch (error) {
|
|
634
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
467
642
|
};
|
|
468
643
|
|
|
469
|
-
export {
|
|
644
|
+
export { register };
|