@alemonjs/discord 2.1.0-alpha.5 → 2.1.0-alpha.6
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/lib/config.d.ts +3 -0
- package/lib/config.js +11 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +26 -21
- package/lib/sdk/api.d.ts +879 -965
- package/lib/sdk/api.js +61 -35
- package/lib/sdk/typings.d.ts +221 -0
- package/lib/sdk/wss.js +9 -37
- package/lib/send.js +87 -82
- package/package.json +1 -1
- package/lib/sdk/config.js +0 -10
- package/lib/sdk/core/config.js +0 -46
- package/lib/sdk/core/from.js +0 -42
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +0 -11
- package/lib/sdk/message/CHANNEL_UPDATE.d.ts +0 -48
- package/lib/sdk/message/GUILD_MEMBER_ADD.d.ts +0 -28
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.d.ts +0 -18
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.d.ts +0 -33
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +0 -126
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +0 -59
- package/lib/sdk/message/MESSAGE_DELETE.d.ts +0 -11
- package/lib/sdk/message/MESSAGE_REACTION_ADD.d.ts +0 -42
- package/lib/sdk/message/MESSAGE_UPDATE.d.ts +0 -56
- package/lib/sdk/message/PRESENCE_UPDATE.d.ts +0 -69
- package/lib/sdk/message/READY.d.ts +0 -9
- package/lib/sdk/message/TYPING_START.d.ts +0 -35
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +0 -10
- package/lib/sdk/message/VOICE_STATE_UPDATE.d.ts +0 -41
- package/lib/sdk/message.d.ts +0 -101
- package/lib/sdk/types.d.ts +0 -5
- package/lib/sdk/types.js +0 -25
- package/lib/sdk/wss.d.ts +0 -27
- package/lib/sdk/wss.types.d.ts +0 -30
package/lib/config.d.ts
ADDED
package/lib/config.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getConfigValue } from 'alemonjs';
|
|
2
|
+
|
|
3
|
+
// 平台
|
|
4
|
+
const platform = 'discord';
|
|
5
|
+
const getDiscordConfigValue = () => {
|
|
6
|
+
const value = getConfigValue() || {};
|
|
7
|
+
const config = value[platform] || {};
|
|
8
|
+
return config;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { getDiscordConfigValue, platform };
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import './env.js';
|
|
2
|
-
import {
|
|
2
|
+
import { cbpPlatform, useUserHashKey, createResult, ResultCode } from 'alemonjs';
|
|
3
3
|
import { sendchannel, senduser } from './send.js';
|
|
4
4
|
import { DCClient } from './sdk/wss.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getDiscordConfigValue, platform } from './config.js';
|
|
6
|
+
export { DCAPI as API } from './sdk/api.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
// main
|
|
8
9
|
var index = () => {
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
});
|
|
10
|
+
const value = getDiscordConfigValue();
|
|
11
|
+
const port = process.env?.port || value?.port || 17117;
|
|
20
12
|
/**
|
|
21
13
|
* 连接 alemonjs 服务器。
|
|
22
14
|
* 向 alemonjs 推送标准信息
|
|
23
15
|
*/
|
|
24
|
-
const url = `ws://127.0.0.1:${
|
|
16
|
+
const url = `ws://127.0.0.1:${port}`;
|
|
25
17
|
const cbp = cbpPlatform(url);
|
|
18
|
+
// 创建客户端
|
|
19
|
+
const client = new DCClient();
|
|
26
20
|
// 连接
|
|
27
|
-
client.connect(
|
|
21
|
+
client.connect();
|
|
28
22
|
/**
|
|
29
23
|
* 创建用户头像
|
|
30
24
|
* @param UserId
|
|
@@ -57,7 +51,8 @@ var index = () => {
|
|
|
57
51
|
Platform: platform,
|
|
58
52
|
UserId: UserId
|
|
59
53
|
});
|
|
60
|
-
const
|
|
54
|
+
const value = getDiscordConfigValue();
|
|
55
|
+
const master_key = value?.master_key ?? [];
|
|
61
56
|
const isMaster = master_key.includes(UserKey);
|
|
62
57
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
63
58
|
if (event.type == 0 && event.member) {
|
|
@@ -126,7 +121,8 @@ var index = () => {
|
|
|
126
121
|
});
|
|
127
122
|
const UserAvatar = createUserAvatar(UserId, user.avatar);
|
|
128
123
|
const UserName = user.username;
|
|
129
|
-
const
|
|
124
|
+
const value = getDiscordConfigValue();
|
|
125
|
+
const master_key = value?.master_key ?? [];
|
|
130
126
|
const isMaster = master_key.includes(UserKey);
|
|
131
127
|
const MessageText = event.data.custom_id;
|
|
132
128
|
if (isPrivate) {
|
|
@@ -240,9 +236,8 @@ var index = () => {
|
|
|
240
236
|
const MessageMention = event.mentions.map(item => {
|
|
241
237
|
const UserId = item.id;
|
|
242
238
|
const avatar = event.author.avatar;
|
|
243
|
-
const value =
|
|
244
|
-
const
|
|
245
|
-
const master_key = config?.master_key ?? [];
|
|
239
|
+
const value = getDiscordConfigValue();
|
|
240
|
+
const master_key = value?.master_key ?? [];
|
|
246
241
|
const UserAvatar = createUserAvatar(UserId, avatar);
|
|
247
242
|
const UserKey = useUserHashKey({
|
|
248
243
|
Platform: platform,
|
|
@@ -285,6 +280,16 @@ var index = () => {
|
|
|
285
280
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
286
281
|
}
|
|
287
282
|
});
|
|
283
|
+
// 处理 api 调用
|
|
284
|
+
cbp?.onapis(async (data, consume) => {
|
|
285
|
+
const key = data.payload?.key;
|
|
286
|
+
if (client[key]) {
|
|
287
|
+
// 如果 client 上有对应的 key,直接调用。
|
|
288
|
+
const params = data.payload.params;
|
|
289
|
+
const res = await client[key](...params);
|
|
290
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
288
293
|
};
|
|
289
294
|
|
|
290
295
|
export { index as default, platform };
|