@alemonjs/discord 2.1.20 → 2.1.21
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/format.js +1 -1
- package/lib/sdk/api.js +2 -6
- package/lib/send.js +21 -16
- package/package.json +1 -1
package/lib/format.js
CHANGED
|
@@ -26,7 +26,7 @@ const markdownToDiscordText = (items, hideUnsupported) => {
|
|
|
26
26
|
return Number(hideUnsupported) >= 2 ? v.url : `[${v.text}](${v.url})`;
|
|
27
27
|
}
|
|
28
28
|
case 'MD.image':
|
|
29
|
-
return
|
|
29
|
+
return `[image](${item.value})`;
|
|
30
30
|
case 'MD.list':
|
|
31
31
|
return (item.value
|
|
32
32
|
.map(li => {
|
package/lib/sdk/api.js
CHANGED
|
@@ -44,18 +44,14 @@ class DCAPI {
|
|
|
44
44
|
}
|
|
45
45
|
async channelsMessagesForm(channel_id, param = {}, img) {
|
|
46
46
|
const formData = new FormData();
|
|
47
|
-
for (const key in param) {
|
|
48
|
-
if (param[key]) {
|
|
49
|
-
formData.append(key, param[key]);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
47
|
if (img) {
|
|
53
48
|
const from = await createPicFrom(img);
|
|
54
49
|
if (from) {
|
|
55
50
|
const { picData, name } = from;
|
|
56
|
-
formData.append('
|
|
51
|
+
formData.append('files[0]', picData, name);
|
|
57
52
|
}
|
|
58
53
|
}
|
|
54
|
+
formData.append('payload_json', JSON.stringify(param ?? {}));
|
|
59
55
|
return this.request({
|
|
60
56
|
method: 'post',
|
|
61
57
|
url: `channels/${channel_id}/messages`,
|
package/lib/send.js
CHANGED
|
@@ -175,6 +175,18 @@ const sendchannel = async (client, param, val) => {
|
|
|
175
175
|
components.push(createSelectData(sel));
|
|
176
176
|
}
|
|
177
177
|
const embedData = embeds.length > 0 ? embeds.map(createEmbedData) : undefined;
|
|
178
|
+
const hasComponents = components.length > 0;
|
|
179
|
+
const hasEmbeds = !!embedData;
|
|
180
|
+
const payload = {};
|
|
181
|
+
if (finalContent) {
|
|
182
|
+
payload.content = finalContent;
|
|
183
|
+
}
|
|
184
|
+
if (hasComponents) {
|
|
185
|
+
payload.components = components;
|
|
186
|
+
}
|
|
187
|
+
if (hasEmbeds) {
|
|
188
|
+
payload.embeds = embedData;
|
|
189
|
+
}
|
|
178
190
|
if (images.length > 0) {
|
|
179
191
|
let bufferData = null;
|
|
180
192
|
for (const img of images) {
|
|
@@ -183,25 +195,18 @@ const sendchannel = async (client, param, val) => {
|
|
|
183
195
|
break;
|
|
184
196
|
}
|
|
185
197
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
if (bufferData && hasEmbeds) {
|
|
199
|
+
payload.attachments = [{ id: 0, filename: 'image.png' }];
|
|
200
|
+
const firstEmbed = payload.embeds[0];
|
|
201
|
+
if (firstEmbed && !firstEmbed.image) {
|
|
202
|
+
firstEmbed.image = { url: 'attachment://image.png' };
|
|
203
|
+
}
|
|
192
204
|
}
|
|
193
|
-
const res = await client.channelsMessagesForm(channelId, payload, bufferData);
|
|
205
|
+
const res = await client.channelsMessagesForm(channelId, payload, bufferData ?? undefined);
|
|
194
206
|
return [createResult(ResultCode.Ok, '完成', res)];
|
|
195
207
|
}
|
|
196
|
-
if (
|
|
197
|
-
const
|
|
198
|
-
if (components.length > 0) {
|
|
199
|
-
payload.components = components;
|
|
200
|
-
}
|
|
201
|
-
if (embedData) {
|
|
202
|
-
payload.embeds = embedData;
|
|
203
|
-
}
|
|
204
|
-
const res = components.length > 0 || embedData ? await client.channelsMessages(channelId, payload) : await client.channelsMessagesForm(channelId, payload);
|
|
208
|
+
if (hasComponents || hasEmbeds || finalContent) {
|
|
209
|
+
const res = await client.channelsMessages(channelId, payload);
|
|
205
210
|
return [createResult(ResultCode.Ok, '完成', res)];
|
|
206
211
|
}
|
|
207
212
|
return [];
|