actually fix files -> attachments

This commit is contained in:
Cynthia Foxwell 2023-01-25 12:36:42 -07:00
parent 2dd510030d
commit 8181bb510e
3 changed files with 26 additions and 10 deletions

View file

@ -142,15 +142,31 @@ async function CommandDispatcher(msg) {
if (response.file) { if (response.file) {
const newFile = response.file; const newFile = response.file;
delete response.file; delete response.file;
newFile.contents = newFile.file; if (newFile.contents) {
delete newFile.file; newFile.file = newFile.contents;
const files = response.files ?? []; delete newFile.contents;
}
if (newFile.name) {
newFile.filename = newFile.name;
delete newFile.name;
}
const files = response.attachments ?? [];
files.push(newFile); files.push(newFile);
response.files = files; response.attachments = files;
} }
if (response.files) { if (response.files) {
response.attachments = response.files; response.attachments = response.files;
delete response.files; delete response.files;
for (const attachment of response.attachments) {
if (attachment.contents) {
attachment.file = attachment.contents;
delete attachment.contents;
}
if (attachment.name) {
attachment.filename = attachment.name;
delete attachment.name;
}
}
} }
if (response.embed) { if (response.embed) {
response.embeds = [...(response.embeds ?? []), response.embed]; response.embeds = [...(response.embeds ?? []), response.embed];

View file

@ -466,14 +466,14 @@ async function processUrl(msg, url, spoiler = false) {
.then((buf) => Buffer.from(buf)); .then((buf) => Buffer.from(buf));
files.push({ files.push({
name: filename:
(cw != "" || spoiler ? "SPOILER_" : "") + (cw != "" || spoiler ? "SPOILER_" : "") +
(attachment.type.indexOf("/") > -1 (attachment.type.indexOf("/") > -1
? attachment.type.replace("/", ".") ? attachment.type.replace("/", ".")
: attachment.type + : attachment.type +
"." + "." +
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")), (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")),
contents: file, file,
}); });
} }
} }
@ -497,7 +497,7 @@ async function processUrl(msg, url, spoiler = false) {
.then((buf) => Buffer.from(buf)); .then((buf) => Buffer.from(buf));
files.push({ files.push({
name: filename:
(cw != "" || spoiler ? "SPOILER_" : "") + (cw != "" || spoiler ? "SPOILER_" : "") +
(attachment.type.indexOf("/") > -1 (attachment.type.indexOf("/") > -1
? attachment.type ? attachment.type
@ -508,7 +508,7 @@ async function processUrl(msg, url, spoiler = false) {
: attachment.type + : attachment.type +
"." + "." +
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3")), (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3")),
contents: file, file,
}); });
} }
} }
@ -530,7 +530,7 @@ async function processUrl(msg, url, spoiler = false) {
? `|| ${url} ||` ? `|| ${url} ||`
: "", : "",
embeds, embeds,
files, attachments: files,
allowedMentions: { allowedMentions: {
repliedUser: false, repliedUser: false,
}, },

View file

@ -243,7 +243,7 @@ async function createBoardMessage(msg, count, fetchAttachment = true) {
username: msg.member?.displayName ?? msg.author.username, username: msg.member?.displayName ?? msg.author.username,
threadID: VINBOARD_THREAD_ID, threadID: VINBOARD_THREAD_ID,
embeds: [embed], embeds: [embed],
files: image?.file ? [{contents: image.file, name: "thumb.jpg"}] : null, attachments: image?.file ? [{file: image.file, filename: "thumb.jpg"}] : null,
wait: true, wait: true,
}; };
} }