@alemonjs/discord 2.1.0-alpha.2 → 2.1.0-alpha.20
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 +16 -2
- package/lib/config.d.ts +14 -0
- package/lib/config.js +21 -0
- 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 -4
- package/lib/index.js +102 -134
- package/lib/sdk/api.d.ts +147 -971
- package/lib/sdk/api.js +336 -1076
- package/lib/sdk/createPicFrom.d.ts +6 -0
- package/lib/sdk/{core/from.js → createPicFrom.js} +8 -13
- 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 -11
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.js +1 -0
- package/lib/sdk/message/CHANNEL_UPDATE.d.ts +42 -48
- package/lib/sdk/message/CHANNEL_UPDATE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_ADD.d.ts +23 -28
- package/lib/sdk/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.d.ts +12 -18
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.d.ts +27 -33
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +113 -114
- package/lib/sdk/message/INTERACTION_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +53 -59
- package/lib/sdk/message/MESSAGE_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_DELETE.d.ts +5 -11
- package/lib/sdk/message/MESSAGE_DELETE.js +1 -0
- package/lib/sdk/message/MESSAGE_REACTION_ADD.d.ts +36 -42
- package/lib/sdk/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/sdk/message/MESSAGE_UPDATE.d.ts +50 -56
- package/lib/sdk/message/MESSAGE_UPDATE.js +1 -0
- package/lib/sdk/message/PRESENCE_UPDATE.d.ts +56 -68
- package/lib/sdk/message/PRESENCE_UPDATE.js +1 -0
- package/lib/sdk/message/READY.d.ts +7 -9
- package/lib/sdk/message/READY.js +1 -0
- package/lib/sdk/message/TYPING_START.d.ts +29 -35
- package/lib/sdk/message/TYPING_START.js +1 -0
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +5 -10
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.js +1 -0
- package/lib/sdk/message/VOICE_STATE_UPDATE.d.ts +36 -41
- package/lib/sdk/message/VOICE_STATE_UPDATE.js +1 -0
- package/lib/sdk/message.d.ts +93 -101
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/types.d.ts +2 -5
- package/lib/sdk/typings.d.ts +190 -0
- package/lib/sdk/typings.js +1 -0
- package/lib/sdk/wss.d.ts +7 -26
- package/lib/sdk/wss.js +109 -162
- package/lib/sdk/wss.types.d.ts +6 -29
- package/lib/sdk/wss.types.js +1 -0
- package/lib/send.d.ts +11 -0
- package/lib/send.js +168 -92
- package/package.json +16 -8
- package/lib/env.js +0 -1
- package/lib/sdk/config.js +0 -10
- package/lib/sdk/core/config.js +0 -46
package/README.md
CHANGED
|
@@ -18,12 +18,26 @@ yarn add @alemonjs/discord
|
|
|
18
18
|
discord:
|
|
19
19
|
# 令牌
|
|
20
20
|
token: ''
|
|
21
|
-
# 主人
|
|
22
|
-
master_key: null
|
|
23
21
|
# 前缀(非必填)
|
|
24
22
|
intent: null
|
|
25
23
|
# 活动 非必填)
|
|
26
24
|
shard: null
|
|
25
|
+
# 使用 user_key
|
|
26
|
+
master_key:
|
|
27
|
+
- 'xxx'
|
|
28
|
+
# 使用 user_id
|
|
29
|
+
master_id:
|
|
30
|
+
- 'yyy'
|
|
31
|
+
# 请求代理(推荐使用)配置参考 axios
|
|
32
|
+
request_config:
|
|
33
|
+
proxy:
|
|
34
|
+
protocol: 'http'
|
|
35
|
+
host: 'localhost'
|
|
36
|
+
port: 7890
|
|
37
|
+
# ws 代理
|
|
38
|
+
websocket_proxy: 'http://localhost:7890'
|
|
39
|
+
# request_proxy: 'http://localhost:7890'
|
|
40
|
+
|
|
27
41
|
```
|
|
28
42
|
|
|
29
43
|
```sh
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DCIntentsEnum } from './sdk/types';
|
|
2
|
+
export interface Options {
|
|
3
|
+
gatewayURL?: string;
|
|
4
|
+
token: string;
|
|
5
|
+
intent?: DCIntentsEnum[];
|
|
6
|
+
shard?: number[];
|
|
7
|
+
master_key?: string[];
|
|
8
|
+
master_id?: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare const platform = "discord";
|
|
11
|
+
export declare const getDiscordConfig: () => Options & {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
export declare const getMaster: (UserId: string) => readonly [boolean, string];
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useUserHashKey, getConfigValue } from 'alemonjs';
|
|
2
|
+
|
|
3
|
+
const platform = 'discord';
|
|
4
|
+
const getDiscordConfig = () => {
|
|
5
|
+
const value = getConfigValue() || {};
|
|
6
|
+
const config = value[platform] || {};
|
|
7
|
+
return config;
|
|
8
|
+
};
|
|
9
|
+
const getMaster = (UserId) => {
|
|
10
|
+
const config = getDiscordConfig();
|
|
11
|
+
const master_key = config.master_key || [];
|
|
12
|
+
const master_id = config.master_id || [];
|
|
13
|
+
const UserKey = useUserHashKey({
|
|
14
|
+
Platform: platform,
|
|
15
|
+
UserId: UserId
|
|
16
|
+
});
|
|
17
|
+
const is = master_key.includes(UserKey) || master_id.includes(UserId);
|
|
18
|
+
return [is, UserKey];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { getDiscordConfig, getMaster, platform };
|
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,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
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,113 +1,72 @@
|
|
|
1
|
-
import './env.js';
|
|
2
|
-
import { getConfigValue, cbpPlatform, useUserHashKey } 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';
|
|
5
|
+
export { DCAPI as API } from './sdk/api.js';
|
|
6
|
+
export { useClient, useValue } from './hook.js';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!value)
|
|
11
|
-
value = {};
|
|
12
|
-
const config = value[platform];
|
|
13
|
-
// 创建客户端
|
|
14
|
-
const client = new DCClient({
|
|
15
|
-
gatewayURL: config?.gatewayURL,
|
|
16
|
-
token: config.token,
|
|
17
|
-
shard: config?.shard ?? [0, 1],
|
|
18
|
-
intent: config?.intent ?? AvailableIntentsEventsEnum
|
|
19
|
-
});
|
|
20
|
-
/**
|
|
21
|
-
* 连接 alemonjs 服务器。
|
|
22
|
-
* 向 alemonjs 推送标准信息
|
|
23
|
-
*/
|
|
24
|
-
const url = `ws://127.0.0.1:${process.env?.port || config?.port || 17117}`;
|
|
8
|
+
const main = () => {
|
|
9
|
+
const port = process.env?.port || 17117;
|
|
10
|
+
const url = `ws://127.0.0.1:${port}`;
|
|
25
11
|
const cbp = cbpPlatform(url);
|
|
26
|
-
|
|
27
|
-
client.connect(
|
|
28
|
-
/**
|
|
29
|
-
* 创建用户头像
|
|
30
|
-
* @param UserId
|
|
31
|
-
* @param avatar
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
12
|
+
const client = new DCClient();
|
|
13
|
+
void client.connect();
|
|
34
14
|
const createUserAvatar = (UserId, avatar) => {
|
|
35
15
|
return client.userAvatar(UserId, avatar);
|
|
36
16
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// 消除bot消息
|
|
40
|
-
if (event.author?.bot)
|
|
17
|
+
client.on('MESSAGE_CREATE', event => {
|
|
18
|
+
if (event.author?.bot) {
|
|
41
19
|
return;
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
// 获取艾特用户
|
|
20
|
+
}
|
|
21
|
+
const atUsers = [];
|
|
45
22
|
for (const item of event.mentions) {
|
|
46
|
-
|
|
23
|
+
atUsers.push({
|
|
47
24
|
id: item.id
|
|
48
25
|
});
|
|
49
26
|
}
|
|
50
|
-
// 清除 @ 相关的消息
|
|
51
27
|
let msg = event.content;
|
|
52
|
-
for
|
|
28
|
+
for (const item of atUsers) {
|
|
53
29
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
54
30
|
}
|
|
55
31
|
const UserId = event.author.id;
|
|
56
|
-
const UserKey =
|
|
57
|
-
Platform: platform,
|
|
58
|
-
UserId: UserId
|
|
59
|
-
});
|
|
60
|
-
const master_key = config?.master_key ?? [];
|
|
61
|
-
const isMaster = master_key.includes(UserKey);
|
|
32
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
62
33
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
63
|
-
if (event.type
|
|
34
|
+
if (event.type === 0 && event.member) {
|
|
64
35
|
const e = {
|
|
65
36
|
name: 'message.create',
|
|
66
|
-
// 事件类型
|
|
67
37
|
Platform: platform,
|
|
68
|
-
// guild
|
|
69
38
|
GuildId: event.guild_id,
|
|
70
39
|
ChannelId: event.channel_id,
|
|
71
|
-
|
|
40
|
+
SpaceId: event.channel_id,
|
|
72
41
|
UserId: UserId,
|
|
73
42
|
UserKey,
|
|
74
43
|
UserName: event.author.username,
|
|
75
44
|
UserAvatar: UserAvatar,
|
|
76
45
|
IsMaster: isMaster,
|
|
77
46
|
IsBot: false,
|
|
78
|
-
|
|
47
|
+
OpenId: UserId,
|
|
79
48
|
MessageId: event.id,
|
|
80
49
|
MessageText: msg,
|
|
81
|
-
OpenId: '',
|
|
82
50
|
CreateAt: Date.now(),
|
|
83
|
-
// other
|
|
84
51
|
tag: 'message.create',
|
|
85
52
|
value: event
|
|
86
53
|
};
|
|
87
54
|
cbp.send(e);
|
|
88
55
|
}
|
|
89
|
-
else if (event.type
|
|
90
|
-
// 处理消息
|
|
56
|
+
else if (event.type === 0 && !event.member) {
|
|
91
57
|
const e = {
|
|
92
58
|
name: 'private.message.create',
|
|
93
|
-
// 事件类型
|
|
94
59
|
Platform: platform,
|
|
95
|
-
// guild
|
|
96
|
-
// GuildId: event.guild_id,
|
|
97
|
-
// ChannelId: event.channel_id,
|
|
98
|
-
// user
|
|
99
60
|
UserId: UserId,
|
|
100
61
|
UserKey,
|
|
101
62
|
UserName: event.author.username,
|
|
102
63
|
UserAvatar: UserAvatar,
|
|
103
64
|
IsMaster: isMaster,
|
|
104
65
|
IsBot: false,
|
|
105
|
-
|
|
66
|
+
OpenId: UserId,
|
|
106
67
|
MessageId: event.id,
|
|
107
68
|
MessageText: msg,
|
|
108
|
-
OpenId: '',
|
|
109
69
|
CreateAt: Date.now(),
|
|
110
|
-
// other
|
|
111
70
|
tag: 'private.message.create',
|
|
112
71
|
value: event
|
|
113
72
|
};
|
|
@@ -116,41 +75,27 @@ var index = () => {
|
|
|
116
75
|
else ;
|
|
117
76
|
});
|
|
118
77
|
client.on('INTERACTION_CREATE', event => {
|
|
119
|
-
console.log('event', event);
|
|
120
78
|
const isPrivate = typeof event['user'] === 'object' ? true : false;
|
|
121
79
|
const user = isPrivate ? event['user'] : event['member'].user;
|
|
122
80
|
const UserId = user.id;
|
|
123
|
-
const UserKey = useUserHashKey({
|
|
124
|
-
Platform: platform,
|
|
125
|
-
UserId: UserId
|
|
126
|
-
});
|
|
127
81
|
const UserAvatar = createUserAvatar(UserId, user.avatar);
|
|
128
82
|
const UserName = user.username;
|
|
129
|
-
const
|
|
130
|
-
const isMaster = master_key.includes(UserKey);
|
|
83
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
131
84
|
const MessageText = event.data.custom_id;
|
|
132
85
|
if (isPrivate) {
|
|
133
|
-
// 处理消息
|
|
134
86
|
const e = {
|
|
135
87
|
name: 'private.interaction.create',
|
|
136
|
-
// 事件类型
|
|
137
88
|
Platform: platform,
|
|
138
|
-
// guild
|
|
139
|
-
// GuildId: event['guild_id'],
|
|
140
|
-
// ChannelId: event.channel_id,
|
|
141
|
-
// user
|
|
142
89
|
UserId: UserId,
|
|
143
90
|
UserKey,
|
|
144
91
|
UserName: UserName,
|
|
145
92
|
UserAvatar: UserAvatar,
|
|
146
93
|
IsMaster: isMaster,
|
|
147
94
|
IsBot: false,
|
|
148
|
-
|
|
95
|
+
OpenId: UserId,
|
|
149
96
|
MessageId: event.id,
|
|
150
97
|
MessageText: MessageText,
|
|
151
|
-
OpenId: '',
|
|
152
98
|
CreateAt: Date.now(),
|
|
153
|
-
// other
|
|
154
99
|
tag: 'private.interaction.create',
|
|
155
100
|
value: event
|
|
156
101
|
};
|
|
@@ -159,126 +104,149 @@ var index = () => {
|
|
|
159
104
|
else {
|
|
160
105
|
const e = {
|
|
161
106
|
name: 'interaction.create',
|
|
162
|
-
// 事件类型
|
|
163
107
|
Platform: platform,
|
|
164
|
-
// guild
|
|
165
108
|
GuildId: event['guild_id'],
|
|
166
109
|
ChannelId: event.channel_id,
|
|
167
|
-
|
|
110
|
+
SpaceId: event.channel_id,
|
|
168
111
|
UserId: UserId,
|
|
169
112
|
UserKey,
|
|
170
113
|
UserName: UserName,
|
|
171
114
|
UserAvatar: UserAvatar,
|
|
172
115
|
IsMaster: isMaster,
|
|
173
116
|
IsBot: false,
|
|
174
|
-
// message
|
|
175
117
|
MessageId: event.id,
|
|
176
118
|
MessageText: MessageText,
|
|
177
|
-
OpenId:
|
|
119
|
+
OpenId: UserId,
|
|
178
120
|
CreateAt: Date.now(),
|
|
179
|
-
// other
|
|
180
121
|
tag: 'interaction.create',
|
|
181
122
|
value: event
|
|
182
123
|
};
|
|
183
124
|
cbp.send(e);
|
|
184
125
|
}
|
|
185
|
-
client.interactionsCallback(event.id, event.token, MessageText);
|
|
126
|
+
void client.interactionsCallback(event.id, event.token, MessageText);
|
|
186
127
|
});
|
|
187
|
-
// 发送错误时
|
|
188
|
-
client.on('ERROR', console.error);
|
|
189
128
|
const api = {
|
|
190
129
|
active: {
|
|
191
130
|
send: {
|
|
192
|
-
channel: (
|
|
193
|
-
|
|
131
|
+
channel: async (UserId, val) => {
|
|
132
|
+
const res = await sendchannel(client, { channel_id: UserId }, val);
|
|
133
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
194
134
|
},
|
|
195
|
-
user: async (
|
|
196
|
-
|
|
135
|
+
user: async (OpenId, val) => {
|
|
136
|
+
const res = await senduser(client, { author_id: OpenId }, val);
|
|
137
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
197
138
|
}
|
|
198
139
|
}
|
|
199
140
|
},
|
|
200
141
|
use: {
|
|
201
142
|
send: async (event, val) => {
|
|
202
|
-
if (val.length
|
|
203
|
-
return
|
|
143
|
+
if (!val || val.length <= 0) {
|
|
144
|
+
return [];
|
|
204
145
|
}
|
|
205
146
|
const tag = event.tag;
|
|
206
|
-
if (tag
|
|
147
|
+
if (tag === 'message.create') {
|
|
207
148
|
const ChannelId = event.value.channel_id;
|
|
208
|
-
|
|
149
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
150
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
209
151
|
}
|
|
210
|
-
else if (tag
|
|
152
|
+
else if (tag === 'private.message.create') {
|
|
211
153
|
const UserId = event.value.author.id;
|
|
212
154
|
const ChannelId = event.value.channel_id;
|
|
213
|
-
|
|
155
|
+
const res = await senduser(client, {
|
|
214
156
|
channel_id: ChannelId,
|
|
215
157
|
author_id: UserId
|
|
216
158
|
}, val);
|
|
159
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
217
160
|
}
|
|
218
|
-
else if (tag
|
|
161
|
+
else if (tag === 'interaction.create') {
|
|
219
162
|
const ChannelId = event.value.channel_id;
|
|
220
|
-
|
|
163
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
164
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
221
165
|
}
|
|
222
|
-
else if (tag
|
|
166
|
+
else if (tag === 'private.interaction.create') {
|
|
223
167
|
const UserId = event.value.user.id;
|
|
224
168
|
const ChannelId = event.value.channel_id;
|
|
225
|
-
|
|
169
|
+
const res = await senduser(client, {
|
|
226
170
|
channel_id: ChannelId,
|
|
227
171
|
author_id: UserId
|
|
228
172
|
}, val);
|
|
173
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
229
174
|
}
|
|
230
|
-
return
|
|
175
|
+
return [];
|
|
231
176
|
},
|
|
232
|
-
mention:
|
|
177
|
+
mention: e => {
|
|
233
178
|
const event = e.value;
|
|
234
179
|
const MessageMention = event.mentions.map(item => {
|
|
235
180
|
const UserId = item.id;
|
|
236
|
-
const avatar =
|
|
237
|
-
const value = getConfigValue();
|
|
238
|
-
const config = value?.discord;
|
|
239
|
-
const master_key = config?.master_key ?? [];
|
|
181
|
+
const avatar = item.avatar;
|
|
240
182
|
const UserAvatar = createUserAvatar(UserId, avatar);
|
|
241
|
-
const UserKey =
|
|
242
|
-
Platform: platform,
|
|
243
|
-
UserId: UserId
|
|
244
|
-
});
|
|
183
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
245
184
|
return {
|
|
246
185
|
UserId: item.id,
|
|
247
|
-
IsMaster:
|
|
186
|
+
IsMaster: isMaster,
|
|
248
187
|
IsBot: item.bot,
|
|
249
188
|
UserAvatar,
|
|
250
189
|
UserKey
|
|
251
190
|
};
|
|
252
191
|
});
|
|
253
|
-
return
|
|
192
|
+
return new Promise(resolve => {
|
|
193
|
+
resolve(MessageMention);
|
|
194
|
+
});
|
|
254
195
|
}
|
|
255
196
|
}
|
|
256
197
|
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
198
|
+
const onactions = async (data, consume) => {
|
|
199
|
+
try {
|
|
200
|
+
if (data.action === 'message.send') {
|
|
201
|
+
const event = data.payload.event;
|
|
202
|
+
const paramFormat = data.payload.params.format;
|
|
203
|
+
const res = await api.use.send(event, paramFormat);
|
|
204
|
+
consume(res);
|
|
205
|
+
}
|
|
206
|
+
else if (data.action === 'message.send.channel') {
|
|
207
|
+
const channelId = data.payload.ChannelId;
|
|
208
|
+
const val = data.payload.params.format;
|
|
209
|
+
const res = await api.active.send.channel(channelId, val);
|
|
210
|
+
consume(res);
|
|
211
|
+
}
|
|
212
|
+
else if (data.action === 'message.send.user') {
|
|
213
|
+
const userId = data.payload.UserId;
|
|
214
|
+
const val = data.payload.params.format;
|
|
215
|
+
const res = await api.active.send.user(userId, val);
|
|
216
|
+
consume(res);
|
|
217
|
+
}
|
|
218
|
+
else if (data.action === 'mention.get') {
|
|
219
|
+
const event = data.payload.event;
|
|
220
|
+
const res = await api.use.mention(event);
|
|
221
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
225
|
+
}
|
|
263
226
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const val = data.payload.params.format;
|
|
267
|
-
const res = await api.active.send.channel(channel_id, val);
|
|
268
|
-
consume(res);
|
|
227
|
+
catch (error) {
|
|
228
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
269
229
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
230
|
+
};
|
|
231
|
+
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
232
|
+
const onapis = async (data, consume) => {
|
|
233
|
+
const key = data.payload?.key;
|
|
234
|
+
if (client[key]) {
|
|
235
|
+
const params = data.payload.params;
|
|
236
|
+
try {
|
|
237
|
+
const res = await client[key](...params);
|
|
238
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
242
|
+
}
|
|
275
243
|
}
|
|
276
|
-
else
|
|
277
|
-
|
|
278
|
-
const res = await api.use.mention(event);
|
|
279
|
-
consume(res);
|
|
244
|
+
else {
|
|
245
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
280
246
|
}
|
|
281
|
-
}
|
|
247
|
+
};
|
|
248
|
+
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
282
249
|
};
|
|
250
|
+
var index = definePlatform({ main });
|
|
283
251
|
|
|
284
252
|
export { index as default, platform };
|