@alemonjs/discord 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 +10 -0
- package/dist/assets/index.css +1 -0
- package/dist/assets/index.js +34 -0
- package/dist/index.html +15 -0
- package/lib/config.d.ts +14 -3
- package/lib/config.js +4 -5
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +4 -12
- package/lib/hook.d.ts +27 -0
- package/lib/hook.js +14 -0
- package/lib/index.d.ts +6 -6
- package/lib/index.js +275 -111
- package/lib/sdk/api.d.ts +7 -745
- package/lib/sdk/api.js +329 -1092
- package/lib/sdk/createPicFrom.d.ts +6 -0
- package/lib/sdk/createPicFrom.js +37 -0
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +93 -0
- package/lib/sdk/intents.d.ts +2 -0
- package/lib/sdk/intents.js +0 -121
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +5 -0
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.js +1 -0
- package/lib/sdk/message/CHANNEL_UPDATE.d.ts +42 -0
- package/lib/sdk/message/CHANNEL_UPDATE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_ADD.d.ts +23 -0
- package/lib/sdk/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.d.ts +12 -0
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.d.ts +27 -0
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +125 -0
- package/lib/sdk/message/INTERACTION_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +53 -0
- package/lib/sdk/message/MESSAGE_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_DELETE.d.ts +5 -0
- package/lib/sdk/message/MESSAGE_DELETE.js +1 -0
- package/lib/sdk/message/MESSAGE_REACTION_ADD.d.ts +36 -0
- package/lib/sdk/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/sdk/message/MESSAGE_UPDATE.d.ts +50 -0
- package/lib/sdk/message/MESSAGE_UPDATE.js +1 -0
- package/lib/sdk/message/PRESENCE_UPDATE.d.ts +57 -0
- package/lib/sdk/message/PRESENCE_UPDATE.js +1 -0
- package/lib/sdk/message/READY.d.ts +7 -0
- package/lib/sdk/message/READY.js +1 -0
- package/lib/sdk/message/TYPING_START.d.ts +29 -0
- package/lib/sdk/message/TYPING_START.js +1 -0
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +5 -0
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.js +1 -0
- package/lib/sdk/message/VOICE_STATE_UPDATE.d.ts +36 -0
- package/lib/sdk/message/VOICE_STATE_UPDATE.js +1 -0
- package/lib/sdk/message.d.ts +93 -0
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/types.d.ts +2 -0
- package/lib/sdk/types.js +25 -0
- package/lib/sdk/typings.d.ts +2 -33
- package/lib/sdk/typings.js +1 -0
- package/lib/sdk/wss.d.ts +8 -0
- package/lib/sdk/wss.js +106 -129
- package/lib/sdk/wss.types.d.ts +7 -0
- package/lib/sdk/wss.types.js +1 -0
- package/lib/send.d.ts +11 -0
- package/lib/send.js +118 -47
- package/package.json +16 -8
- package/lib/env.js +0 -1
package/lib/desktop.d.ts
CHANGED
package/lib/desktop.js
CHANGED
|
@@ -3,30 +3,22 @@ import { dirname, join } from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { getConfig, getConfigValue } from 'alemonjs';
|
|
5
5
|
|
|
6
|
-
// 当前目录
|
|
7
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
// 被激活的时候。
|
|
9
7
|
const activate = context => {
|
|
10
|
-
// 创建一个 webview。
|
|
11
8
|
const webView = context.createSidebarWebView(context);
|
|
12
|
-
// 当命令被触发的时候。
|
|
13
9
|
context.onCommand('open.discord', () => {
|
|
14
10
|
const dir = join(__dirname, '../', 'dist', 'index.html');
|
|
15
11
|
const scriptReg = /<script.*?src="(.+?)".*?>/;
|
|
16
12
|
const styleReg = /<link.*?rel="stylesheet".*?href="(.+?)".*?>/;
|
|
17
13
|
const iconReg = /<link.*?rel="icon".*?href="(.+?)".*?>/g;
|
|
18
|
-
// 创建 webview 路径
|
|
19
14
|
const styleUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.css'));
|
|
20
15
|
const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
|
|
21
|
-
// 确保路径存在
|
|
22
16
|
const html = readFileSync(dir, 'utf-8')
|
|
23
|
-
.replace(iconReg,
|
|
17
|
+
.replace(iconReg, '')
|
|
24
18
|
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
|
25
19
|
.replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
|
|
26
|
-
// 立即渲染 webview
|
|
27
20
|
webView.loadWebView(html);
|
|
28
21
|
});
|
|
29
|
-
// 监听 webview 的消息。
|
|
30
22
|
webView.onMessage(data => {
|
|
31
23
|
try {
|
|
32
24
|
if (data.type === 'discord.form.save') {
|
|
@@ -42,9 +34,9 @@ const activate = context => {
|
|
|
42
34
|
}
|
|
43
35
|
else if (data.type === 'discord.init') {
|
|
44
36
|
let config = getConfigValue();
|
|
45
|
-
if (!config)
|
|
37
|
+
if (!config) {
|
|
46
38
|
config = {};
|
|
47
|
-
|
|
39
|
+
}
|
|
48
40
|
webView.postMessage({
|
|
49
41
|
type: 'discord.init',
|
|
50
42
|
data: config.discord ?? {}
|
|
@@ -52,7 +44,7 @@ const activate = context => {
|
|
|
52
44
|
}
|
|
53
45
|
}
|
|
54
46
|
catch (e) {
|
|
55
|
-
|
|
47
|
+
logger.error(e);
|
|
56
48
|
}
|
|
57
49
|
});
|
|
58
50
|
};
|
package/lib/hook.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EventKeys, Events } from 'alemonjs';
|
|
2
|
+
import { DCAPI as API } from './sdk/api';
|
|
3
|
+
import { MESSAGE_CREATE_TYPE } from './sdk/message/MESSAGE_CREATE';
|
|
4
|
+
import { INTERACTION_CREATE_TYPE } from './sdk/message/INTERACTION_CREATE';
|
|
5
|
+
type MAP = {
|
|
6
|
+
'message.create': MESSAGE_CREATE_TYPE;
|
|
7
|
+
'private.message.create': MESSAGE_CREATE_TYPE;
|
|
8
|
+
'interaction.create': INTERACTION_CREATE_TYPE;
|
|
9
|
+
'private.interaction.create': INTERACTION_CREATE_TYPE;
|
|
10
|
+
'message.update': undefined;
|
|
11
|
+
'message.delete': undefined;
|
|
12
|
+
'message.reaction.add': undefined;
|
|
13
|
+
'message.reaction.remove': undefined;
|
|
14
|
+
'channel.create': undefined;
|
|
15
|
+
'channel.delete': undefined;
|
|
16
|
+
'guild.join': undefined;
|
|
17
|
+
'guild.exit': undefined;
|
|
18
|
+
'member.add': undefined;
|
|
19
|
+
'member.remove': undefined;
|
|
20
|
+
'private.message.update': undefined;
|
|
21
|
+
'private.message.delete': undefined;
|
|
22
|
+
'private.friend.add': undefined;
|
|
23
|
+
'private.guild.add': undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
26
|
+
export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
|
|
27
|
+
export {};
|
package/lib/hook.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createEventValue, useClient as useClient$1 } from 'alemonjs';
|
|
2
|
+
import { DCAPI } from './sdk/api.js';
|
|
3
|
+
|
|
4
|
+
const useValue = (event) => {
|
|
5
|
+
const value = createEventValue(event);
|
|
6
|
+
return [value];
|
|
7
|
+
};
|
|
8
|
+
const useClient = (event) => {
|
|
9
|
+
const [client] = useClient$1(event, DCAPI);
|
|
10
|
+
const value = createEventValue(event);
|
|
11
|
+
return [client, value];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useClient, useValue };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { platform } from './config
|
|
2
|
-
export { DCAPI as API } from './sdk/api
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
1
|
+
export { platform } from './config';
|
|
2
|
+
export { DCAPI as API } from './sdk/api';
|
|
3
|
+
export * from './hook';
|
|
4
|
+
export { type Options } from './config';
|
|
5
|
+
declare const _default: () => any;
|
|
6
|
+
export default _default;
|
package/lib/index.js
CHANGED
|
@@ -1,101 +1,79 @@
|
|
|
1
|
-
import './env.js';
|
|
2
|
-
import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
3
1
|
import { sendchannel, senduser } from './send.js';
|
|
4
2
|
import { DCClient } from './sdk/wss.js';
|
|
5
|
-
import {
|
|
3
|
+
import { definePlatform, cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
4
|
+
import { getMaster, platform } from './config.js';
|
|
6
5
|
export { DCAPI as API } from './sdk/api.js';
|
|
6
|
+
export { useClient, useValue } from './hook.js';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const value = getDiscordConfigValue();
|
|
11
|
-
const port = process.env?.port || value?.port || 17117;
|
|
12
|
-
/**
|
|
13
|
-
* 连接 alemonjs 服务器。
|
|
14
|
-
* 向 alemonjs 推送标准信息
|
|
15
|
-
*/
|
|
8
|
+
const main = () => {
|
|
9
|
+
const port = process.env?.port || 17117;
|
|
16
10
|
const url = `ws://127.0.0.1:${port}`;
|
|
17
11
|
const cbp = cbpPlatform(url);
|
|
18
|
-
// 创建客户端
|
|
19
12
|
const client = new DCClient();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
13
|
+
void client.connect();
|
|
14
|
+
let botId = '';
|
|
15
|
+
client.on('READY', event => {
|
|
16
|
+
if (event?.user?.id) {
|
|
17
|
+
botId = String(event.user.id);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
28
20
|
const createUserAvatar = (UserId, avatar) => {
|
|
29
21
|
return client.userAvatar(UserId, avatar);
|
|
30
22
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// 消除bot消息
|
|
34
|
-
if (event.author?.bot)
|
|
23
|
+
client.on('MESSAGE_CREATE', event => {
|
|
24
|
+
if (event.author?.bot) {
|
|
35
25
|
return;
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
// 获取艾特用户
|
|
26
|
+
}
|
|
27
|
+
const atUsers = [];
|
|
39
28
|
for (const item of event.mentions) {
|
|
40
|
-
|
|
29
|
+
atUsers.push({
|
|
41
30
|
id: item.id
|
|
42
31
|
});
|
|
43
32
|
}
|
|
44
|
-
// 清除 @ 相关的消息
|
|
45
33
|
let msg = event.content;
|
|
46
|
-
for
|
|
34
|
+
for (const item of atUsers) {
|
|
47
35
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
48
36
|
}
|
|
49
37
|
const UserId = event.author.id;
|
|
50
38
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
51
39
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
52
|
-
if (event.type
|
|
40
|
+
if (event.type === 0 && event.member) {
|
|
53
41
|
const e = {
|
|
54
42
|
name: 'message.create',
|
|
55
|
-
// 事件类型
|
|
56
43
|
Platform: platform,
|
|
57
|
-
// guild
|
|
58
44
|
GuildId: event.guild_id,
|
|
59
45
|
ChannelId: event.channel_id,
|
|
60
46
|
SpaceId: event.channel_id,
|
|
61
|
-
// user
|
|
62
47
|
UserId: UserId,
|
|
63
48
|
UserKey,
|
|
64
49
|
UserName: event.author.username,
|
|
65
50
|
UserAvatar: UserAvatar,
|
|
66
51
|
IsMaster: isMaster,
|
|
67
52
|
IsBot: false,
|
|
68
|
-
|
|
53
|
+
OpenId: UserId,
|
|
69
54
|
MessageId: event.id,
|
|
70
55
|
MessageText: msg,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// other
|
|
74
|
-
tag: 'message.create',
|
|
56
|
+
BotId: botId,
|
|
57
|
+
_tag: 'message.create',
|
|
75
58
|
value: event
|
|
76
59
|
};
|
|
77
60
|
cbp.send(e);
|
|
78
61
|
}
|
|
79
|
-
else if (event.type
|
|
80
|
-
// 处理消息
|
|
62
|
+
else if (event.type === 0 && !event.member) {
|
|
81
63
|
const e = {
|
|
82
64
|
name: 'private.message.create',
|
|
83
|
-
// 事件类型
|
|
84
65
|
Platform: platform,
|
|
85
|
-
// user
|
|
86
66
|
UserId: UserId,
|
|
87
67
|
UserKey,
|
|
88
68
|
UserName: event.author.username,
|
|
89
69
|
UserAvatar: UserAvatar,
|
|
90
70
|
IsMaster: isMaster,
|
|
91
71
|
IsBot: false,
|
|
92
|
-
|
|
72
|
+
OpenId: UserId,
|
|
93
73
|
MessageId: event.id,
|
|
94
74
|
MessageText: msg,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// other
|
|
98
|
-
tag: 'private.message.create',
|
|
75
|
+
BotId: botId,
|
|
76
|
+
_tag: 'private.message.create',
|
|
99
77
|
value: event
|
|
100
78
|
};
|
|
101
79
|
cbp.send(e);
|
|
@@ -111,28 +89,20 @@ var index = () => {
|
|
|
111
89
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
112
90
|
const MessageText = event.data.custom_id;
|
|
113
91
|
if (isPrivate) {
|
|
114
|
-
// 处理消息
|
|
115
92
|
const e = {
|
|
116
93
|
name: 'private.interaction.create',
|
|
117
|
-
// 事件类型
|
|
118
94
|
Platform: platform,
|
|
119
|
-
// guild
|
|
120
|
-
// GuildId: event['guild_id'],
|
|
121
|
-
// ChannelId: event.channel_id,
|
|
122
|
-
// user
|
|
123
95
|
UserId: UserId,
|
|
124
96
|
UserKey,
|
|
125
97
|
UserName: UserName,
|
|
126
98
|
UserAvatar: UserAvatar,
|
|
127
99
|
IsMaster: isMaster,
|
|
128
100
|
IsBot: false,
|
|
129
|
-
|
|
101
|
+
OpenId: UserId,
|
|
130
102
|
MessageId: event.id,
|
|
131
103
|
MessageText: MessageText,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// other
|
|
135
|
-
tag: 'private.interaction.create',
|
|
104
|
+
BotId: botId,
|
|
105
|
+
_tag: 'private.interaction.create',
|
|
136
106
|
value: event
|
|
137
107
|
};
|
|
138
108
|
cbp.send(e);
|
|
@@ -140,59 +110,230 @@ var index = () => {
|
|
|
140
110
|
else {
|
|
141
111
|
const e = {
|
|
142
112
|
name: 'interaction.create',
|
|
143
|
-
// 事件类型
|
|
144
113
|
Platform: platform,
|
|
145
|
-
// guild
|
|
146
114
|
GuildId: event['guild_id'],
|
|
147
115
|
ChannelId: event.channel_id,
|
|
148
116
|
SpaceId: event.channel_id,
|
|
149
|
-
// user
|
|
150
117
|
UserId: UserId,
|
|
151
118
|
UserKey,
|
|
152
119
|
UserName: UserName,
|
|
153
120
|
UserAvatar: UserAvatar,
|
|
154
121
|
IsMaster: isMaster,
|
|
155
122
|
IsBot: false,
|
|
156
|
-
// message
|
|
157
123
|
MessageId: event.id,
|
|
158
124
|
MessageText: MessageText,
|
|
159
|
-
OpenId:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
tag: 'interaction.create',
|
|
125
|
+
OpenId: UserId,
|
|
126
|
+
BotId: botId,
|
|
127
|
+
_tag: 'interaction.create',
|
|
163
128
|
value: event
|
|
164
129
|
};
|
|
165
130
|
cbp.send(e);
|
|
166
131
|
}
|
|
167
|
-
client.interactionsCallback(event.id, event.token, MessageText);
|
|
132
|
+
void client.interactionsCallback(event.id, event.token, MessageText);
|
|
133
|
+
});
|
|
134
|
+
client.on('MESSAGE_UPDATE', event => {
|
|
135
|
+
if (!event.author) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const UserId = event.author.id;
|
|
139
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
140
|
+
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
141
|
+
const e = {
|
|
142
|
+
name: 'message.update',
|
|
143
|
+
Platform: platform,
|
|
144
|
+
GuildId: event.guild_id,
|
|
145
|
+
ChannelId: event.channel_id,
|
|
146
|
+
SpaceId: event.channel_id,
|
|
147
|
+
UserId: UserId,
|
|
148
|
+
UserKey,
|
|
149
|
+
UserName: event.author.username,
|
|
150
|
+
UserAvatar: UserAvatar,
|
|
151
|
+
IsMaster: isMaster,
|
|
152
|
+
IsBot: event.author.bot ?? false,
|
|
153
|
+
MessageId: event.id,
|
|
154
|
+
BotId: botId,
|
|
155
|
+
_tag: 'MESSAGE_UPDATE',
|
|
156
|
+
value: event
|
|
157
|
+
};
|
|
158
|
+
cbp.send(e);
|
|
159
|
+
});
|
|
160
|
+
client.on('MESSAGE_DELETE', event => {
|
|
161
|
+
const e = {
|
|
162
|
+
name: 'message.delete',
|
|
163
|
+
Platform: platform,
|
|
164
|
+
GuildId: event.guild_id,
|
|
165
|
+
ChannelId: event.channel_id,
|
|
166
|
+
SpaceId: event.channel_id,
|
|
167
|
+
MessageId: event.id,
|
|
168
|
+
BotId: botId,
|
|
169
|
+
_tag: 'MESSAGE_DELETE',
|
|
170
|
+
value: event
|
|
171
|
+
};
|
|
172
|
+
cbp.send(e);
|
|
173
|
+
});
|
|
174
|
+
client.on('MESSAGE_REACTION_ADD', event => {
|
|
175
|
+
const e = {
|
|
176
|
+
name: 'message.reaction.add',
|
|
177
|
+
Platform: platform,
|
|
178
|
+
GuildId: event.guild_id,
|
|
179
|
+
ChannelId: event.channel_id,
|
|
180
|
+
SpaceId: event.channel_id,
|
|
181
|
+
MessageId: event.message_id,
|
|
182
|
+
BotId: botId,
|
|
183
|
+
_tag: 'MESSAGE_REACTION_ADD',
|
|
184
|
+
value: event
|
|
185
|
+
};
|
|
186
|
+
cbp.send(e);
|
|
187
|
+
});
|
|
188
|
+
client.on('MESSAGE_REACTION_REMOVE', event => {
|
|
189
|
+
const e = {
|
|
190
|
+
name: 'message.reaction.remove',
|
|
191
|
+
Platform: platform,
|
|
192
|
+
GuildId: event['guild_id'],
|
|
193
|
+
ChannelId: event['channel_id'],
|
|
194
|
+
SpaceId: event['channel_id'],
|
|
195
|
+
MessageId: event['message_id'],
|
|
196
|
+
BotId: botId,
|
|
197
|
+
_tag: 'MESSAGE_REACTION_REMOVE',
|
|
198
|
+
value: event
|
|
199
|
+
};
|
|
200
|
+
cbp.send(e);
|
|
201
|
+
});
|
|
202
|
+
client.on('GUILD_MEMBER_ADD', event => {
|
|
203
|
+
const UserId = event.user.id;
|
|
204
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
205
|
+
const UserAvatar = createUserAvatar(UserId, event.user.avatar);
|
|
206
|
+
const e = {
|
|
207
|
+
name: 'member.add',
|
|
208
|
+
Platform: platform,
|
|
209
|
+
GuildId: event.guild_id,
|
|
210
|
+
ChannelId: '',
|
|
211
|
+
SpaceId: event.guild_id,
|
|
212
|
+
UserId: UserId,
|
|
213
|
+
UserKey,
|
|
214
|
+
UserName: event.user.username,
|
|
215
|
+
UserAvatar: UserAvatar,
|
|
216
|
+
IsMaster: isMaster,
|
|
217
|
+
IsBot: false,
|
|
218
|
+
MessageId: '',
|
|
219
|
+
BotId: botId,
|
|
220
|
+
_tag: 'GUILD_MEMBER_ADD',
|
|
221
|
+
value: event
|
|
222
|
+
};
|
|
223
|
+
cbp.send(e);
|
|
224
|
+
});
|
|
225
|
+
client.on('GUILD_MEMBER_REMOVE', event => {
|
|
226
|
+
const UserId = event.user.id;
|
|
227
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
228
|
+
const UserAvatar = createUserAvatar(UserId, event.user.avatar);
|
|
229
|
+
const e = {
|
|
230
|
+
name: 'member.remove',
|
|
231
|
+
Platform: platform,
|
|
232
|
+
GuildId: event.guild_id,
|
|
233
|
+
ChannelId: '',
|
|
234
|
+
SpaceId: event.guild_id,
|
|
235
|
+
UserId: UserId,
|
|
236
|
+
UserKey,
|
|
237
|
+
UserName: event.user.username,
|
|
238
|
+
UserAvatar: UserAvatar,
|
|
239
|
+
IsMaster: isMaster,
|
|
240
|
+
IsBot: false,
|
|
241
|
+
MessageId: '',
|
|
242
|
+
BotId: botId,
|
|
243
|
+
_tag: 'GUILD_MEMBER_REMOVE',
|
|
244
|
+
value: event
|
|
245
|
+
};
|
|
246
|
+
cbp.send(e);
|
|
247
|
+
});
|
|
248
|
+
client.on('CHANNEL_CREATE', event => {
|
|
249
|
+
const e = {
|
|
250
|
+
name: 'channel.create',
|
|
251
|
+
Platform: platform,
|
|
252
|
+
GuildId: event.guild_id ?? '',
|
|
253
|
+
ChannelId: event.id ?? '',
|
|
254
|
+
SpaceId: event.guild_id ?? '',
|
|
255
|
+
MessageId: '',
|
|
256
|
+
BotId: botId,
|
|
257
|
+
_tag: 'CHANNEL_CREATE',
|
|
258
|
+
value: event
|
|
259
|
+
};
|
|
260
|
+
cbp.send(e);
|
|
261
|
+
});
|
|
262
|
+
client.on('CHANNEL_DELETE', event => {
|
|
263
|
+
const e = {
|
|
264
|
+
name: 'channel.delete',
|
|
265
|
+
Platform: platform,
|
|
266
|
+
GuildId: event.guild_id ?? '',
|
|
267
|
+
ChannelId: event.id ?? '',
|
|
268
|
+
SpaceId: event.guild_id ?? '',
|
|
269
|
+
MessageId: '',
|
|
270
|
+
BotId: botId,
|
|
271
|
+
_tag: 'CHANNEL_DELETE',
|
|
272
|
+
value: event
|
|
273
|
+
};
|
|
274
|
+
cbp.send(e);
|
|
275
|
+
});
|
|
276
|
+
client.on('GUILD_CREATE', event => {
|
|
277
|
+
const e = {
|
|
278
|
+
name: 'guild.join',
|
|
279
|
+
Platform: platform,
|
|
280
|
+
GuildId: event.id ?? '',
|
|
281
|
+
ChannelId: '',
|
|
282
|
+
SpaceId: event.id ?? '',
|
|
283
|
+
UserId: '',
|
|
284
|
+
UserKey: '',
|
|
285
|
+
IsMaster: false,
|
|
286
|
+
IsBot: false,
|
|
287
|
+
MessageId: '',
|
|
288
|
+
BotId: botId,
|
|
289
|
+
_tag: 'GUILD_CREATE',
|
|
290
|
+
value: event
|
|
291
|
+
};
|
|
292
|
+
cbp.send(e);
|
|
293
|
+
});
|
|
294
|
+
client.on('GUILD_DELETE', event => {
|
|
295
|
+
const e = {
|
|
296
|
+
name: 'guild.exit',
|
|
297
|
+
Platform: platform,
|
|
298
|
+
GuildId: event.id ?? '',
|
|
299
|
+
ChannelId: '',
|
|
300
|
+
SpaceId: event.id ?? '',
|
|
301
|
+
UserId: '',
|
|
302
|
+
UserKey: '',
|
|
303
|
+
IsMaster: false,
|
|
304
|
+
IsBot: false,
|
|
305
|
+
MessageId: '',
|
|
306
|
+
BotId: botId,
|
|
307
|
+
_tag: 'GUILD_DELETE',
|
|
308
|
+
value: event
|
|
309
|
+
};
|
|
310
|
+
cbp.send(e);
|
|
168
311
|
});
|
|
169
|
-
// 发送错误时
|
|
170
|
-
client.on('ERROR', console.error);
|
|
171
312
|
const api = {
|
|
172
313
|
active: {
|
|
173
314
|
send: {
|
|
174
|
-
channel: async (
|
|
175
|
-
const res = await sendchannel(client, { channel_id }, val);
|
|
315
|
+
channel: async (UserId, val) => {
|
|
316
|
+
const res = await sendchannel(client, { channel_id: UserId }, val);
|
|
176
317
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
177
318
|
},
|
|
178
|
-
user: async (
|
|
179
|
-
const res = await senduser(client, { author_id:
|
|
319
|
+
user: async (OpenId, val) => {
|
|
320
|
+
const res = await senduser(client, { author_id: OpenId }, val);
|
|
180
321
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
181
322
|
}
|
|
182
323
|
}
|
|
183
324
|
},
|
|
184
325
|
use: {
|
|
185
326
|
send: async (event, val) => {
|
|
186
|
-
if (val.length
|
|
327
|
+
if (!val || val.length <= 0) {
|
|
187
328
|
return [];
|
|
188
329
|
}
|
|
189
|
-
const tag = event.
|
|
190
|
-
if (tag
|
|
330
|
+
const tag = event._tag;
|
|
331
|
+
if (tag === 'message.create') {
|
|
191
332
|
const ChannelId = event.value.channel_id;
|
|
192
333
|
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
193
334
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
194
335
|
}
|
|
195
|
-
else if (tag
|
|
336
|
+
else if (tag === 'private.message.create') {
|
|
196
337
|
const UserId = event.value.author.id;
|
|
197
338
|
const ChannelId = event.value.channel_id;
|
|
198
339
|
const res = await senduser(client, {
|
|
@@ -201,12 +342,12 @@ var index = () => {
|
|
|
201
342
|
}, val);
|
|
202
343
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
203
344
|
}
|
|
204
|
-
else if (tag
|
|
345
|
+
else if (tag === 'interaction.create') {
|
|
205
346
|
const ChannelId = event.value.channel_id;
|
|
206
347
|
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
207
348
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
208
349
|
}
|
|
209
|
-
else if (tag
|
|
350
|
+
else if (tag === 'private.interaction.create') {
|
|
210
351
|
const UserId = event.value.user.id;
|
|
211
352
|
const ChannelId = event.value.channel_id;
|
|
212
353
|
const res = await senduser(client, {
|
|
@@ -217,11 +358,14 @@ var index = () => {
|
|
|
217
358
|
}
|
|
218
359
|
return [];
|
|
219
360
|
},
|
|
220
|
-
mention:
|
|
361
|
+
mention: e => {
|
|
221
362
|
const event = e.value;
|
|
363
|
+
if (!event?.mentions) {
|
|
364
|
+
return new Promise(resolve => resolve([]));
|
|
365
|
+
}
|
|
222
366
|
const MessageMention = event.mentions.map(item => {
|
|
223
367
|
const UserId = item.id;
|
|
224
|
-
const avatar =
|
|
368
|
+
const avatar = item.avatar;
|
|
225
369
|
const UserAvatar = createUserAvatar(UserId, avatar);
|
|
226
370
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
227
371
|
return {
|
|
@@ -232,44 +376,64 @@ var index = () => {
|
|
|
232
376
|
UserKey
|
|
233
377
|
};
|
|
234
378
|
});
|
|
235
|
-
return
|
|
379
|
+
return new Promise(resolve => {
|
|
380
|
+
resolve(MessageMention);
|
|
381
|
+
});
|
|
236
382
|
}
|
|
237
383
|
}
|
|
238
384
|
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
385
|
+
const onactions = async (data, consume) => {
|
|
386
|
+
try {
|
|
387
|
+
if (data.action === 'message.send') {
|
|
388
|
+
const event = data.payload.event;
|
|
389
|
+
const paramFormat = data.payload.params.format;
|
|
390
|
+
const res = await api.use.send(event, paramFormat);
|
|
391
|
+
consume(res);
|
|
392
|
+
}
|
|
393
|
+
else if (data.action === 'message.send.channel') {
|
|
394
|
+
const channelId = data.payload.ChannelId;
|
|
395
|
+
const val = data.payload.params.format;
|
|
396
|
+
const res = await api.active.send.channel(channelId, val);
|
|
397
|
+
consume(res);
|
|
398
|
+
}
|
|
399
|
+
else if (data.action === 'message.send.user') {
|
|
400
|
+
const userId = data.payload.UserId;
|
|
401
|
+
const val = data.payload.params.format;
|
|
402
|
+
const res = await api.active.send.user(userId, val);
|
|
403
|
+
consume(res);
|
|
404
|
+
}
|
|
405
|
+
else if (data.action === 'mention.get') {
|
|
406
|
+
const event = data.payload.event;
|
|
407
|
+
const res = await api.use.mention(event);
|
|
408
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
412
|
+
}
|
|
257
413
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const res = await api.use.mention(event);
|
|
261
|
-
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
414
|
+
catch (error) {
|
|
415
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
262
416
|
}
|
|
263
|
-
}
|
|
264
|
-
cbp.
|
|
417
|
+
};
|
|
418
|
+
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
419
|
+
const onapis = async (data, consume) => {
|
|
265
420
|
const key = data.payload?.key;
|
|
266
421
|
if (client[key]) {
|
|
267
|
-
// 如果 client 上有对应的 key,直接调用。
|
|
268
422
|
const params = data.payload.params;
|
|
269
|
-
|
|
270
|
-
|
|
423
|
+
try {
|
|
424
|
+
const res = await client[key](...params);
|
|
425
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
429
|
+
}
|
|
271
430
|
}
|
|
272
|
-
|
|
431
|
+
else {
|
|
432
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
273
436
|
};
|
|
437
|
+
var index = definePlatform({ main });
|
|
274
438
|
|
|
275
439
|
export { index as default, platform };
|