@alemonjs/discord 2.1.0-alpha.6 → 2.1.0-alpha.8
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 +6 -2
- package/lib/config.js +13 -2
- package/lib/index.js +9 -29
- package/lib/send.js +1 -1
- package/package.json +1 -1
- package/dist/assets/index.css +0 -1248
- package/dist/assets/index.js +0 -11015
- package/dist/index.html +0 -15
package/README.md
CHANGED
|
@@ -18,12 +18,16 @@ 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'
|
|
27
31
|
```
|
|
28
32
|
|
|
29
33
|
```sh
|
package/lib/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getConfigValue } from 'alemonjs';
|
|
1
|
+
import { getConfigValue, useUserHashKey } from 'alemonjs';
|
|
2
2
|
|
|
3
3
|
// 平台
|
|
4
4
|
const platform = 'discord';
|
|
@@ -7,5 +7,16 @@ const getDiscordConfigValue = () => {
|
|
|
7
7
|
const config = value[platform] || {};
|
|
8
8
|
return config;
|
|
9
9
|
};
|
|
10
|
+
const getMaster = (UserId) => {
|
|
11
|
+
const config = getDiscordConfigValue();
|
|
12
|
+
const master_key = config.master_key || [];
|
|
13
|
+
const master_id = config.master_id || [];
|
|
14
|
+
const UserKey = useUserHashKey({
|
|
15
|
+
Platform: platform,
|
|
16
|
+
UserId: UserId
|
|
17
|
+
});
|
|
18
|
+
const is = master_key.includes(UserKey) || master_id.includes(UserId);
|
|
19
|
+
return [is, UserKey];
|
|
20
|
+
};
|
|
10
21
|
|
|
11
|
-
export { getDiscordConfigValue, platform };
|
|
22
|
+
export { getDiscordConfigValue, getMaster, platform };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import './env.js';
|
|
2
|
-
import { cbpPlatform,
|
|
2
|
+
import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
3
3
|
import { sendchannel, senduser } from './send.js';
|
|
4
4
|
import { DCClient } from './sdk/wss.js';
|
|
5
|
-
import { getDiscordConfigValue, platform } from './config.js';
|
|
5
|
+
import { getDiscordConfigValue, getMaster, platform } from './config.js';
|
|
6
6
|
export { DCAPI as API } from './sdk/api.js';
|
|
7
7
|
|
|
8
8
|
// main
|
|
@@ -47,13 +47,7 @@ var index = () => {
|
|
|
47
47
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
48
48
|
}
|
|
49
49
|
const UserId = event.author.id;
|
|
50
|
-
const UserKey =
|
|
51
|
-
Platform: platform,
|
|
52
|
-
UserId: UserId
|
|
53
|
-
});
|
|
54
|
-
const value = getDiscordConfigValue();
|
|
55
|
-
const master_key = value?.master_key ?? [];
|
|
56
|
-
const isMaster = master_key.includes(UserKey);
|
|
50
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
57
51
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
58
52
|
if (event.type == 0 && event.member) {
|
|
59
53
|
const e = {
|
|
@@ -63,6 +57,7 @@ var index = () => {
|
|
|
63
57
|
// guild
|
|
64
58
|
GuildId: event.guild_id,
|
|
65
59
|
ChannelId: event.channel_id,
|
|
60
|
+
SpaceId: event.channel_id,
|
|
66
61
|
// user
|
|
67
62
|
UserId: UserId,
|
|
68
63
|
UserKey,
|
|
@@ -87,9 +82,6 @@ var index = () => {
|
|
|
87
82
|
name: 'private.message.create',
|
|
88
83
|
// 事件类型
|
|
89
84
|
Platform: platform,
|
|
90
|
-
// guild
|
|
91
|
-
// GuildId: event.guild_id,
|
|
92
|
-
// ChannelId: event.channel_id,
|
|
93
85
|
// user
|
|
94
86
|
UserId: UserId,
|
|
95
87
|
UserKey,
|
|
@@ -111,19 +103,12 @@ var index = () => {
|
|
|
111
103
|
else ;
|
|
112
104
|
});
|
|
113
105
|
client.on('INTERACTION_CREATE', event => {
|
|
114
|
-
console.log('event', event);
|
|
115
106
|
const isPrivate = typeof event['user'] === 'object' ? true : false;
|
|
116
107
|
const user = isPrivate ? event['user'] : event['member'].user;
|
|
117
108
|
const UserId = user.id;
|
|
118
|
-
const UserKey = useUserHashKey({
|
|
119
|
-
Platform: platform,
|
|
120
|
-
UserId: UserId
|
|
121
|
-
});
|
|
122
109
|
const UserAvatar = createUserAvatar(UserId, user.avatar);
|
|
123
110
|
const UserName = user.username;
|
|
124
|
-
const
|
|
125
|
-
const master_key = value?.master_key ?? [];
|
|
126
|
-
const isMaster = master_key.includes(UserKey);
|
|
111
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
127
112
|
const MessageText = event.data.custom_id;
|
|
128
113
|
if (isPrivate) {
|
|
129
114
|
// 处理消息
|
|
@@ -160,6 +145,7 @@ var index = () => {
|
|
|
160
145
|
// guild
|
|
161
146
|
GuildId: event['guild_id'],
|
|
162
147
|
ChannelId: event.channel_id,
|
|
148
|
+
SpaceId: event.channel_id,
|
|
163
149
|
// user
|
|
164
150
|
UserId: UserId,
|
|
165
151
|
UserKey,
|
|
@@ -236,16 +222,11 @@ var index = () => {
|
|
|
236
222
|
const MessageMention = event.mentions.map(item => {
|
|
237
223
|
const UserId = item.id;
|
|
238
224
|
const avatar = event.author.avatar;
|
|
239
|
-
const value = getDiscordConfigValue();
|
|
240
|
-
const master_key = value?.master_key ?? [];
|
|
241
225
|
const UserAvatar = createUserAvatar(UserId, avatar);
|
|
242
|
-
const UserKey =
|
|
243
|
-
Platform: platform,
|
|
244
|
-
UserId: UserId
|
|
245
|
-
});
|
|
226
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
246
227
|
return {
|
|
247
228
|
UserId: item.id,
|
|
248
|
-
IsMaster:
|
|
229
|
+
IsMaster: isMaster,
|
|
249
230
|
IsBot: item.bot,
|
|
250
231
|
UserAvatar,
|
|
251
232
|
UserKey
|
|
@@ -280,8 +261,7 @@ var index = () => {
|
|
|
280
261
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
281
262
|
}
|
|
282
263
|
});
|
|
283
|
-
|
|
284
|
-
cbp?.onapis(async (data, consume) => {
|
|
264
|
+
cbp.onapis(async (data, consume) => {
|
|
285
265
|
const key = data.payload?.key;
|
|
286
266
|
if (client[key]) {
|
|
287
267
|
// 如果 client 上有对应的 key,直接调用。
|
package/lib/send.js
CHANGED