@alemonjs/discord 2.1.0-alpha.3 → 2.1.0-alpha.5
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/index.js +17 -11
- package/lib/sdk/api.js +1 -1
- package/lib/send.js +8 -9
- package/package.json +1 -1
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/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './env.js';
|
|
2
|
-
import { getConfigValue, cbpPlatform, useUserHashKey } from 'alemonjs';
|
|
2
|
+
import { getConfigValue, cbpPlatform, useUserHashKey, createResult, ResultCode } from 'alemonjs';
|
|
3
3
|
import { sendchannel, senduser } from './send.js';
|
|
4
4
|
import { DCClient } from './sdk/wss.js';
|
|
5
5
|
import { AvailableIntentsEventsEnum } from './sdk/types.js';
|
|
@@ -189,45 +189,51 @@ var index = () => {
|
|
|
189
189
|
const api = {
|
|
190
190
|
active: {
|
|
191
191
|
send: {
|
|
192
|
-
channel: (channel_id, val) => {
|
|
193
|
-
|
|
192
|
+
channel: async (channel_id, val) => {
|
|
193
|
+
const res = await sendchannel(client, { channel_id }, val);
|
|
194
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
194
195
|
},
|
|
195
196
|
user: async (author_id, val) => {
|
|
196
|
-
|
|
197
|
+
const res = await senduser(client, { author_id: author_id }, val);
|
|
198
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
201
|
},
|
|
200
202
|
use: {
|
|
201
203
|
send: async (event, val) => {
|
|
202
204
|
if (val.length < 0) {
|
|
203
|
-
return
|
|
205
|
+
return [];
|
|
204
206
|
}
|
|
205
207
|
const tag = event.tag;
|
|
206
208
|
if (tag == 'message.create') {
|
|
207
209
|
const ChannelId = event.value.channel_id;
|
|
208
|
-
|
|
210
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
211
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
209
212
|
}
|
|
210
213
|
else if (tag == 'private.message.create') {
|
|
211
214
|
const UserId = event.value.author.id;
|
|
212
215
|
const ChannelId = event.value.channel_id;
|
|
213
|
-
|
|
216
|
+
const res = await senduser(client, {
|
|
214
217
|
channel_id: ChannelId,
|
|
215
218
|
author_id: UserId
|
|
216
219
|
}, val);
|
|
220
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
217
221
|
}
|
|
218
222
|
else if (tag == 'interaction.create') {
|
|
219
223
|
const ChannelId = event.value.channel_id;
|
|
220
|
-
|
|
224
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
225
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
221
226
|
}
|
|
222
227
|
else if (tag == 'private.interaction.create') {
|
|
223
228
|
const UserId = event.value.user.id;
|
|
224
229
|
const ChannelId = event.value.channel_id;
|
|
225
|
-
|
|
230
|
+
const res = await senduser(client, {
|
|
226
231
|
channel_id: ChannelId,
|
|
227
232
|
author_id: UserId
|
|
228
233
|
}, val);
|
|
234
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
229
235
|
}
|
|
230
|
-
return
|
|
236
|
+
return [];
|
|
231
237
|
},
|
|
232
238
|
mention: async (e) => {
|
|
233
239
|
const event = e.value;
|
|
@@ -276,7 +282,7 @@ var index = () => {
|
|
|
276
282
|
else if (data.action === 'mention.get') {
|
|
277
283
|
const event = data.payload.event;
|
|
278
284
|
const res = await api.use.mention(event);
|
|
279
|
-
consume(res);
|
|
285
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
280
286
|
}
|
|
281
287
|
});
|
|
282
288
|
};
|
package/lib/sdk/api.js
CHANGED
package/lib/send.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createResult, ResultCode } from 'alemonjs';
|
|
2
1
|
import { readFileSync } from 'fs';
|
|
3
2
|
|
|
4
3
|
const ImageURLToBuffer = async (url) => {
|
|
@@ -29,9 +28,9 @@ const createButtonsData = (rows) => {
|
|
|
29
28
|
};
|
|
30
29
|
});
|
|
31
30
|
};
|
|
32
|
-
const sendchannel = (client, param, val) => {
|
|
31
|
+
const sendchannel = async (client, param, val) => {
|
|
33
32
|
if (val.length < 0)
|
|
34
|
-
return
|
|
33
|
+
return [];
|
|
35
34
|
const channel_id = param?.channel_id ?? '';
|
|
36
35
|
// images
|
|
37
36
|
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageURL' || item.type == 'ImageFile');
|
|
@@ -86,7 +85,9 @@ const sendchannel = (client, param, val) => {
|
|
|
86
85
|
}
|
|
87
86
|
isText = true;
|
|
88
87
|
if (item.type == 'Image') {
|
|
89
|
-
return client.channelsMessagesImage(channel_id, Buffer.from(item.value, 'base64'), {
|
|
88
|
+
return client.channelsMessagesImage(channel_id, Buffer.from(item.value, 'base64'), {
|
|
89
|
+
content: text
|
|
90
|
+
});
|
|
90
91
|
}
|
|
91
92
|
else if (item.type == 'ImageURL') {
|
|
92
93
|
return client.channelsMessagesImage(channel_id, await ImageURLToBuffer(item.value), {
|
|
@@ -108,12 +109,10 @@ const sendchannel = (client, param, val) => {
|
|
|
108
109
|
content: content,
|
|
109
110
|
components: data
|
|
110
111
|
});
|
|
111
|
-
return
|
|
112
|
+
return {
|
|
112
113
|
id: res.id
|
|
113
|
-
}
|
|
114
|
-
}))
|
|
115
|
-
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
116
|
-
]);
|
|
114
|
+
};
|
|
115
|
+
}));
|
|
117
116
|
}
|
|
118
117
|
if (content) {
|
|
119
118
|
return Promise.all([content].map(item => client.channelsMessages(channel_id, {
|