@alemonjs/discord 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 +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 +1 -2
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +4 -12
- package/lib/hook.d.ts +8 -20
- package/lib/hook.js +0 -10
- package/lib/index.d.ts +6 -7
- package/lib/index.js +274 -111
- package/lib/sdk/api.d.ts +7 -745
- package/lib/sdk/api.js +327 -1090
- 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 +2 -3
- package/lib/sdk/message/INTERACTION_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +1 -7
- 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 +103 -126
- 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 +15 -7
- package/lib/env.js +0 -1
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
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { EventKeys, Events } from 'alemonjs';
|
|
2
|
-
import { DCAPI } from './sdk/api
|
|
3
|
-
import { MESSAGE_CREATE_TYPE } from './sdk/message/MESSAGE_CREATE
|
|
4
|
-
import { INTERACTION_CREATE_TYPE } from './sdk/message/INTERACTION_CREATE
|
|
5
|
-
|
|
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';
|
|
6
5
|
type MAP = {
|
|
7
6
|
'message.create': MESSAGE_CREATE_TYPE;
|
|
8
7
|
'private.message.create': MESSAGE_CREATE_TYPE;
|
|
@@ -12,8 +11,8 @@ type MAP = {
|
|
|
12
11
|
'message.delete': undefined;
|
|
13
12
|
'message.reaction.add': undefined;
|
|
14
13
|
'message.reaction.remove': undefined;
|
|
15
|
-
'
|
|
16
|
-
'
|
|
14
|
+
'channel.create': undefined;
|
|
15
|
+
'channel.delete': undefined;
|
|
17
16
|
'guild.join': undefined;
|
|
18
17
|
'guild.exit': undefined;
|
|
19
18
|
'member.add': undefined;
|
|
@@ -23,17 +22,6 @@ type MAP = {
|
|
|
23
22
|
'private.friend.add': undefined;
|
|
24
23
|
'private.guild.add': undefined;
|
|
25
24
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @param event
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [DCAPI, MAP[T]];
|
|
38
|
-
|
|
39
|
-
export { useClient, useValue };
|
|
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
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { createEventValue, useClient as useClient$1 } from 'alemonjs';
|
|
2
2
|
import { DCAPI } from './sdk/api.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param event
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
4
|
const useValue = (event) => {
|
|
10
5
|
const value = createEventValue(event);
|
|
11
6
|
return [value];
|
|
12
7
|
};
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param event
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
8
|
const useClient = (event) => {
|
|
19
9
|
const [client] = useClient$1(event, DCAPI);
|
|
20
10
|
const value = createEventValue(event);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export { platform } from './config
|
|
2
|
-
export { DCAPI as API } from './sdk/api
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
declare const _default: () =>
|
|
6
|
-
|
|
7
|
-
export { _default as default };
|
|
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,102 +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';
|
|
7
6
|
export { useClient, useValue } from './hook.js';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const value = getDiscordConfig();
|
|
12
|
-
const port = process.env?.port || value?.port || 17117;
|
|
13
|
-
/**
|
|
14
|
-
* 连接 alemonjs 服务器。
|
|
15
|
-
* 向 alemonjs 推送标准信息
|
|
16
|
-
*/
|
|
8
|
+
const main = () => {
|
|
9
|
+
const port = process.env?.port || 17117;
|
|
17
10
|
const url = `ws://127.0.0.1:${port}`;
|
|
18
11
|
const cbp = cbpPlatform(url);
|
|
19
|
-
// 创建客户端
|
|
20
12
|
const client = new DCClient();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
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
|
+
});
|
|
29
20
|
const createUserAvatar = (UserId, avatar) => {
|
|
30
21
|
return client.userAvatar(UserId, avatar);
|
|
31
22
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// 消除bot消息
|
|
35
|
-
if (event.author?.bot)
|
|
23
|
+
client.on('MESSAGE_CREATE', event => {
|
|
24
|
+
if (event.author?.bot) {
|
|
36
25
|
return;
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
// 获取艾特用户
|
|
26
|
+
}
|
|
27
|
+
const atUsers = [];
|
|
40
28
|
for (const item of event.mentions) {
|
|
41
|
-
|
|
29
|
+
atUsers.push({
|
|
42
30
|
id: item.id
|
|
43
31
|
});
|
|
44
32
|
}
|
|
45
|
-
// 清除 @ 相关的消息
|
|
46
33
|
let msg = event.content;
|
|
47
|
-
for
|
|
34
|
+
for (const item of atUsers) {
|
|
48
35
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
49
36
|
}
|
|
50
37
|
const UserId = event.author.id;
|
|
51
38
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
52
39
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
53
|
-
if (event.type
|
|
40
|
+
if (event.type === 0 && event.member) {
|
|
54
41
|
const e = {
|
|
55
42
|
name: 'message.create',
|
|
56
|
-
// 事件类型
|
|
57
43
|
Platform: platform,
|
|
58
|
-
// guild
|
|
59
44
|
GuildId: event.guild_id,
|
|
60
45
|
ChannelId: event.channel_id,
|
|
61
46
|
SpaceId: event.channel_id,
|
|
62
|
-
// user
|
|
63
47
|
UserId: UserId,
|
|
64
48
|
UserKey,
|
|
65
49
|
UserName: event.author.username,
|
|
66
50
|
UserAvatar: UserAvatar,
|
|
67
51
|
IsMaster: isMaster,
|
|
68
52
|
IsBot: false,
|
|
69
|
-
|
|
53
|
+
OpenId: UserId,
|
|
70
54
|
MessageId: event.id,
|
|
71
55
|
MessageText: msg,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// other
|
|
75
|
-
tag: 'message.create',
|
|
56
|
+
BotId: botId,
|
|
57
|
+
_tag: 'message.create',
|
|
76
58
|
value: event
|
|
77
59
|
};
|
|
78
60
|
cbp.send(e);
|
|
79
61
|
}
|
|
80
|
-
else if (event.type
|
|
81
|
-
// 处理消息
|
|
62
|
+
else if (event.type === 0 && !event.member) {
|
|
82
63
|
const e = {
|
|
83
64
|
name: 'private.message.create',
|
|
84
|
-
// 事件类型
|
|
85
65
|
Platform: platform,
|
|
86
|
-
// user
|
|
87
66
|
UserId: UserId,
|
|
88
67
|
UserKey,
|
|
89
68
|
UserName: event.author.username,
|
|
90
69
|
UserAvatar: UserAvatar,
|
|
91
70
|
IsMaster: isMaster,
|
|
92
71
|
IsBot: false,
|
|
93
|
-
|
|
72
|
+
OpenId: UserId,
|
|
94
73
|
MessageId: event.id,
|
|
95
74
|
MessageText: msg,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// other
|
|
99
|
-
tag: 'private.message.create',
|
|
75
|
+
BotId: botId,
|
|
76
|
+
_tag: 'private.message.create',
|
|
100
77
|
value: event
|
|
101
78
|
};
|
|
102
79
|
cbp.send(e);
|
|
@@ -112,28 +89,20 @@ var index = () => {
|
|
|
112
89
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
113
90
|
const MessageText = event.data.custom_id;
|
|
114
91
|
if (isPrivate) {
|
|
115
|
-
// 处理消息
|
|
116
92
|
const e = {
|
|
117
93
|
name: 'private.interaction.create',
|
|
118
|
-
// 事件类型
|
|
119
94
|
Platform: platform,
|
|
120
|
-
// guild
|
|
121
|
-
// GuildId: event['guild_id'],
|
|
122
|
-
// ChannelId: event.channel_id,
|
|
123
|
-
// user
|
|
124
95
|
UserId: UserId,
|
|
125
96
|
UserKey,
|
|
126
97
|
UserName: UserName,
|
|
127
98
|
UserAvatar: UserAvatar,
|
|
128
99
|
IsMaster: isMaster,
|
|
129
100
|
IsBot: false,
|
|
130
|
-
|
|
101
|
+
OpenId: UserId,
|
|
131
102
|
MessageId: event.id,
|
|
132
103
|
MessageText: MessageText,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// other
|
|
136
|
-
tag: 'private.interaction.create',
|
|
104
|
+
BotId: botId,
|
|
105
|
+
_tag: 'private.interaction.create',
|
|
137
106
|
value: event
|
|
138
107
|
};
|
|
139
108
|
cbp.send(e);
|
|
@@ -141,59 +110,230 @@ var index = () => {
|
|
|
141
110
|
else {
|
|
142
111
|
const e = {
|
|
143
112
|
name: 'interaction.create',
|
|
144
|
-
// 事件类型
|
|
145
113
|
Platform: platform,
|
|
146
|
-
// guild
|
|
147
114
|
GuildId: event['guild_id'],
|
|
148
115
|
ChannelId: event.channel_id,
|
|
149
116
|
SpaceId: event.channel_id,
|
|
150
|
-
// user
|
|
151
117
|
UserId: UserId,
|
|
152
118
|
UserKey,
|
|
153
119
|
UserName: UserName,
|
|
154
120
|
UserAvatar: UserAvatar,
|
|
155
121
|
IsMaster: isMaster,
|
|
156
122
|
IsBot: false,
|
|
157
|
-
// message
|
|
158
123
|
MessageId: event.id,
|
|
159
124
|
MessageText: MessageText,
|
|
160
|
-
OpenId:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
tag: 'interaction.create',
|
|
125
|
+
OpenId: UserId,
|
|
126
|
+
BotId: botId,
|
|
127
|
+
_tag: 'interaction.create',
|
|
164
128
|
value: event
|
|
165
129
|
};
|
|
166
130
|
cbp.send(e);
|
|
167
131
|
}
|
|
168
|
-
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);
|
|
169
311
|
});
|
|
170
|
-
// 发送错误时
|
|
171
|
-
client.on('ERROR', console.error);
|
|
172
312
|
const api = {
|
|
173
313
|
active: {
|
|
174
314
|
send: {
|
|
175
|
-
channel: async (
|
|
176
|
-
const res = await sendchannel(client, { channel_id }, val);
|
|
315
|
+
channel: async (UserId, val) => {
|
|
316
|
+
const res = await sendchannel(client, { channel_id: UserId }, val);
|
|
177
317
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
178
318
|
},
|
|
179
|
-
user: async (
|
|
180
|
-
const res = await senduser(client, { author_id:
|
|
319
|
+
user: async (OpenId, val) => {
|
|
320
|
+
const res = await senduser(client, { author_id: OpenId }, val);
|
|
181
321
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
182
322
|
}
|
|
183
323
|
}
|
|
184
324
|
},
|
|
185
325
|
use: {
|
|
186
326
|
send: async (event, val) => {
|
|
187
|
-
if (val.length
|
|
327
|
+
if (!val || val.length <= 0) {
|
|
188
328
|
return [];
|
|
189
329
|
}
|
|
190
|
-
const tag = event.
|
|
191
|
-
if (tag
|
|
330
|
+
const tag = event._tag;
|
|
331
|
+
if (tag === 'message.create') {
|
|
192
332
|
const ChannelId = event.value.channel_id;
|
|
193
333
|
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
194
334
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
195
335
|
}
|
|
196
|
-
else if (tag
|
|
336
|
+
else if (tag === 'private.message.create') {
|
|
197
337
|
const UserId = event.value.author.id;
|
|
198
338
|
const ChannelId = event.value.channel_id;
|
|
199
339
|
const res = await senduser(client, {
|
|
@@ -202,12 +342,12 @@ var index = () => {
|
|
|
202
342
|
}, val);
|
|
203
343
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
204
344
|
}
|
|
205
|
-
else if (tag
|
|
345
|
+
else if (tag === 'interaction.create') {
|
|
206
346
|
const ChannelId = event.value.channel_id;
|
|
207
347
|
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
208
348
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
209
349
|
}
|
|
210
|
-
else if (tag
|
|
350
|
+
else if (tag === 'private.interaction.create') {
|
|
211
351
|
const UserId = event.value.user.id;
|
|
212
352
|
const ChannelId = event.value.channel_id;
|
|
213
353
|
const res = await senduser(client, {
|
|
@@ -218,11 +358,14 @@ var index = () => {
|
|
|
218
358
|
}
|
|
219
359
|
return [];
|
|
220
360
|
},
|
|
221
|
-
mention:
|
|
361
|
+
mention: e => {
|
|
222
362
|
const event = e.value;
|
|
363
|
+
if (!event?.mentions) {
|
|
364
|
+
return new Promise(resolve => resolve([]));
|
|
365
|
+
}
|
|
223
366
|
const MessageMention = event.mentions.map(item => {
|
|
224
367
|
const UserId = item.id;
|
|
225
|
-
const avatar =
|
|
368
|
+
const avatar = item.avatar;
|
|
226
369
|
const UserAvatar = createUserAvatar(UserId, avatar);
|
|
227
370
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
228
371
|
return {
|
|
@@ -233,44 +376,64 @@ var index = () => {
|
|
|
233
376
|
UserKey
|
|
234
377
|
};
|
|
235
378
|
});
|
|
236
|
-
return
|
|
379
|
+
return new Promise(resolve => {
|
|
380
|
+
resolve(MessageMention);
|
|
381
|
+
});
|
|
237
382
|
}
|
|
238
383
|
}
|
|
239
384
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
+
}
|
|
258
413
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const res = await api.use.mention(event);
|
|
262
|
-
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
414
|
+
catch (error) {
|
|
415
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
263
416
|
}
|
|
264
|
-
}
|
|
265
|
-
cbp.
|
|
417
|
+
};
|
|
418
|
+
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
419
|
+
const onapis = async (data, consume) => {
|
|
266
420
|
const key = data.payload?.key;
|
|
267
421
|
if (client[key]) {
|
|
268
|
-
// 如果 client 上有对应的 key,直接调用。
|
|
269
422
|
const params = data.payload.params;
|
|
270
|
-
|
|
271
|
-
|
|
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
|
+
}
|
|
272
430
|
}
|
|
273
|
-
|
|
431
|
+
else {
|
|
432
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
274
436
|
};
|
|
437
|
+
var index = definePlatform({ main });
|
|
275
438
|
|
|
276
439
|
export { index as default, platform };
|