@alemonjs/discord 2.1.0-alpha.4 → 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/dist/assets/index.css +1248 -1
- package/dist/assets/index.js +10986 -5
- package/dist/index.html +1 -1
- package/lib/config.d.ts +3 -0
- package/lib/config.js +11 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +28 -23
- package/lib/sdk/api.d.ts +886 -0
- package/lib/sdk/api.js +62 -36
- package/lib/sdk/typings.d.ts +221 -0
- package/lib/sdk/wss.js +9 -37
- package/lib/send.js +86 -84
- 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/types.js +0 -25
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>AlemonJS</title>
|
|
8
8
|
<script type="module" crossorigin src="/assets/index.js"></script>
|
|
9
|
-
<link rel="stylesheet" crossorigin href="/assets/index.css"
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index.css" />
|
|
10
10
|
</head>
|
|
11
11
|
|
|
12
12
|
<body>
|
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) {
|
|
@@ -202,7 +198,7 @@ var index = () => {
|
|
|
202
198
|
use: {
|
|
203
199
|
send: async (event, val) => {
|
|
204
200
|
if (val.length < 0) {
|
|
205
|
-
return
|
|
201
|
+
return [];
|
|
206
202
|
}
|
|
207
203
|
const tag = event.tag;
|
|
208
204
|
if (tag == 'message.create') {
|
|
@@ -233,16 +229,15 @@ var index = () => {
|
|
|
233
229
|
}, val);
|
|
234
230
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
235
231
|
}
|
|
236
|
-
return
|
|
232
|
+
return [];
|
|
237
233
|
},
|
|
238
234
|
mention: async (e) => {
|
|
239
235
|
const event = e.value;
|
|
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 };
|