@alemonjs/qq-bot 2.1.0-alpha.9 → 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 +426 -252
- package/lib/sdk/api.d.ts +10 -567
- package/lib/sdk/api.js +224 -790
- 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,345 +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
|
-
const isMaster = master_key.includes(event.author.id);
|
|
34
|
-
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
35
|
-
const UserId = event.author.id;
|
|
36
|
-
const UserKey = useUserHashKey({
|
|
14
|
+
client.on('GROUP_ADD_ROBOT', event => {
|
|
15
|
+
const e = {
|
|
16
|
+
name: 'guild.join',
|
|
37
17
|
Platform: platform,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
Platform: platform,
|
|
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
|
-
}
|
|
249
|
-
catch (err) {
|
|
250
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null);
|
|
251
|
-
}
|
|
201
|
+
client.on('INTERACTION_CREATE', event => {
|
|
252
202
|
if (event.scene === 'group') {
|
|
253
|
-
const master_key = config?.master_key ?? [];
|
|
254
|
-
const isMaster = master_key.includes(event.group_member_openid);
|
|
255
203
|
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
256
204
|
const UserId = event.group_member_openid;
|
|
257
|
-
const UserKey =
|
|
258
|
-
Platform: platform,
|
|
259
|
-
UserId: UserId
|
|
260
|
-
});
|
|
205
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
261
206
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
262
207
|
const e = {
|
|
263
208
|
name: 'interaction.create',
|
|
264
209
|
Platform: platform,
|
|
265
|
-
// guild
|
|
266
210
|
GuildId: event.group_openid,
|
|
267
211
|
ChannelId: event.group_openid,
|
|
268
|
-
|
|
212
|
+
SpaceId: `GROUP:${event.group_openid}`,
|
|
269
213
|
UserId: event.group_member_openid,
|
|
270
214
|
UserKey,
|
|
271
215
|
UserAvatar: UserAvatar,
|
|
272
216
|
IsMaster: isMaster,
|
|
273
217
|
IsBot: false,
|
|
274
|
-
// 格式化数据
|
|
275
218
|
MessageId: `INTERACTION_CREATE:${event.id}`,
|
|
276
219
|
MessageText: MessageText,
|
|
277
|
-
OpenId: event.group_member_openid
|
|
278
|
-
|
|
279
|
-
|
|
220
|
+
OpenId: `C2C:${event.group_member_openid}`,
|
|
221
|
+
BotId: botId,
|
|
222
|
+
_tag: 'INTERACTION_CREATE_GROUP',
|
|
280
223
|
value: event
|
|
281
224
|
};
|
|
282
225
|
cbp.send(e);
|
|
283
226
|
}
|
|
284
227
|
else if (event.scene === 'c2c') {
|
|
285
|
-
const master_key = config?.master_key ?? [];
|
|
286
|
-
const isMaster = master_key.includes(event.user_openid);
|
|
287
228
|
const UserAvatar = createUserAvatarURL(event.user_openid);
|
|
288
229
|
const UserId = event.user_openid;
|
|
289
|
-
const UserKey =
|
|
290
|
-
Platform: platform,
|
|
291
|
-
UserId: UserId
|
|
292
|
-
});
|
|
230
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
293
231
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
294
|
-
// 处理消息
|
|
295
232
|
const e = {
|
|
296
233
|
name: 'private.interaction.create',
|
|
297
234
|
Platform: platform,
|
|
298
|
-
// 用户Id
|
|
299
235
|
UserId: event.user_openid,
|
|
300
236
|
UserKey,
|
|
301
237
|
UserAvatar: UserAvatar,
|
|
302
238
|
IsMaster: isMaster,
|
|
303
239
|
IsBot: false,
|
|
304
|
-
// 格式化数据
|
|
305
240
|
MessageId: event.id,
|
|
306
241
|
MessageText: MessageText,
|
|
307
|
-
OpenId: event.user_openid
|
|
308
|
-
|
|
309
|
-
|
|
242
|
+
OpenId: `C2C:${event.user_openid}`,
|
|
243
|
+
BotId: botId,
|
|
244
|
+
_tag: 'INTERACTION_CREATE_C2C',
|
|
310
245
|
value: event
|
|
311
246
|
};
|
|
312
247
|
cbp.send(e);
|
|
313
248
|
}
|
|
314
249
|
else if (event.scene === 'guild') {
|
|
315
|
-
const master_key = config?.master_key ?? [];
|
|
316
|
-
const isMaster = master_key.includes(event.data.resolved.user_id);
|
|
317
250
|
const UserAvatar = createUserAvatarURL(event.data.resolved.user_id);
|
|
318
251
|
const UserId = event.data.resolved.user_id;
|
|
319
|
-
const UserKey =
|
|
320
|
-
Platform: platform,
|
|
321
|
-
UserId: UserId
|
|
322
|
-
});
|
|
252
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
323
253
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
324
|
-
// 处理消息
|
|
325
254
|
const e = {
|
|
326
255
|
name: 'interaction.create',
|
|
327
256
|
Platform: platform,
|
|
328
|
-
// guild
|
|
329
257
|
GuildId: event.guild_id,
|
|
330
258
|
ChannelId: event.channel_id,
|
|
331
|
-
|
|
259
|
+
SpaceId: `GUILD:${event.channel_id}`,
|
|
332
260
|
UserId: event.data.resolved.user_id,
|
|
333
261
|
UserKey,
|
|
334
262
|
UserAvatar: UserAvatar,
|
|
335
263
|
IsMaster: isMaster,
|
|
336
264
|
IsBot: false,
|
|
337
|
-
// 格式化数据
|
|
338
265
|
MessageId: event.data.resolved.message_id,
|
|
339
266
|
MessageText: MessageText,
|
|
340
|
-
OpenId: event.guild_id
|
|
341
|
-
|
|
342
|
-
|
|
267
|
+
OpenId: `DIRECT:${event.guild_id}`,
|
|
268
|
+
BotId: botId,
|
|
269
|
+
_tag: 'INTERACTION_CREATE_GUILD',
|
|
343
270
|
value: event
|
|
344
271
|
};
|
|
345
272
|
cbp.send(e);
|
|
@@ -352,119 +279,366 @@ const register = (client) => {
|
|
|
352
279
|
});
|
|
353
280
|
}
|
|
354
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
|
+
});
|
|
355
475
|
client.on('ERROR', console.error);
|
|
356
476
|
const api = {
|
|
357
477
|
active: {
|
|
358
478
|
send: {
|
|
359
|
-
channel: async (
|
|
360
|
-
if (
|
|
361
|
-
|
|
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);
|
|
362
491
|
}
|
|
363
|
-
return
|
|
364
|
-
ChannelId: channel_id
|
|
365
|
-
}, val);
|
|
492
|
+
return [];
|
|
366
493
|
},
|
|
367
|
-
user: async (
|
|
368
|
-
if (
|
|
369
|
-
|
|
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);
|
|
370
500
|
}
|
|
371
|
-
|
|
372
|
-
OpenId:
|
|
373
|
-
|
|
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 [];
|
|
374
514
|
}
|
|
375
515
|
}
|
|
376
516
|
},
|
|
377
517
|
use: {
|
|
378
518
|
send: async (event, val) => {
|
|
379
|
-
if (val.length
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const tag = event.
|
|
383
|
-
|
|
384
|
-
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') {
|
|
385
524
|
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
386
525
|
}
|
|
387
|
-
|
|
388
|
-
if (tag == 'C2C_MESSAGE_CREATE') {
|
|
526
|
+
if (tag === 'C2C_MESSAGE_CREATE') {
|
|
389
527
|
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
390
528
|
}
|
|
391
|
-
|
|
392
|
-
if (tag == 'DIRECT_MESSAGE_CREATE') {
|
|
529
|
+
if (tag === 'DIRECT_MESSAGE_CREATE') {
|
|
393
530
|
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
394
531
|
}
|
|
395
|
-
|
|
396
|
-
if (tag == 'AT_MESSAGE_CREATE') {
|
|
532
|
+
if (tag === 'AT_MESSAGE_CREATE') {
|
|
397
533
|
return await AT_MESSAGE_CREATE(client, event, val);
|
|
398
534
|
}
|
|
399
|
-
|
|
400
|
-
if (tag == 'MESSAGE_CREATE') {
|
|
535
|
+
if (tag === 'MESSAGE_CREATE') {
|
|
401
536
|
return await MESSAGE_CREATE(client, event, val);
|
|
402
537
|
}
|
|
403
|
-
|
|
404
|
-
if (tag == 'INTERACTION_CREATE_GROUP') {
|
|
538
|
+
if (tag === 'INTERACTION_CREATE_GROUP') {
|
|
405
539
|
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
406
540
|
}
|
|
407
|
-
if (tag
|
|
541
|
+
if (tag === 'INTERACTION_CREATE_C2C') {
|
|
408
542
|
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
409
543
|
}
|
|
410
|
-
if (tag
|
|
544
|
+
if (tag === 'INTERACTION_CREATE_GUILD') {
|
|
411
545
|
return await AT_MESSAGE_CREATE(client, event, val);
|
|
412
546
|
}
|
|
413
|
-
return
|
|
547
|
+
return [];
|
|
414
548
|
},
|
|
415
|
-
mention:
|
|
416
|
-
event.value || {};
|
|
417
|
-
event.
|
|
418
|
-
// const event = e.value
|
|
549
|
+
mention: event => {
|
|
550
|
+
const value = event.value || {};
|
|
551
|
+
const tag = event._tag;
|
|
419
552
|
const Metions = [];
|
|
420
|
-
|
|
421
|
-
|
|
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
|
+
}
|
|
422
574
|
}
|
|
423
575
|
}
|
|
424
576
|
};
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
+
}
|
|
448
619
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
const user_id = data.payload.UserId;
|
|
452
|
-
const paramFormat = data.payload.params.format;
|
|
453
|
-
const res = await api.active.send.user(user_id, paramFormat);
|
|
454
|
-
consume(res);
|
|
620
|
+
catch (error) {
|
|
621
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
455
622
|
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
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 {
|
|
464
630
|
const res = await client[key](...params);
|
|
465
631
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
466
632
|
}
|
|
467
|
-
|
|
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));
|
|
468
642
|
};
|
|
469
643
|
|
|
470
|
-
export {
|
|
644
|
+
export { register };
|