From 8181bb510e4dd18d387d8ae03a880e737e261b32 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 25 Jan 2023 12:36:42 -0700 Subject: [PATCH] actually fix files -> attachments --- src/lib/commandDispatcher.js | 24 ++++++++++++++++++++---- src/modules/fedimbed.js | 10 +++++----- src/modules/foxwells.js | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/lib/commandDispatcher.js b/src/lib/commandDispatcher.js index 94eec60..ccc5585 100644 --- a/src/lib/commandDispatcher.js +++ b/src/lib/commandDispatcher.js @@ -142,15 +142,31 @@ async function CommandDispatcher(msg) { if (response.file) { const newFile = response.file; delete response.file; - newFile.contents = newFile.file; - delete newFile.file; - const files = response.files ?? []; + if (newFile.contents) { + newFile.file = newFile.contents; + delete newFile.contents; + } + if (newFile.name) { + newFile.filename = newFile.name; + delete newFile.name; + } + const files = response.attachments ?? []; files.push(newFile); - response.files = files; + response.attachments = files; } if (response.files) { response.attachments = 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) { response.embeds = [...(response.embeds ?? []), response.embed]; diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 0627a4b..363a71b 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -466,14 +466,14 @@ async function processUrl(msg, url, spoiler = false) { .then((buf) => Buffer.from(buf)); files.push({ - name: + filename: (cw != "" || spoiler ? "SPOILER_" : "") + (attachment.type.indexOf("/") > -1 ? attachment.type.replace("/", ".") : attachment.type + "." + (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)); files.push({ - name: + filename: (cw != "" || spoiler ? "SPOILER_" : "") + (attachment.type.indexOf("/") > -1 ? attachment.type @@ -508,7 +508,7 @@ async function processUrl(msg, url, spoiler = false) { : attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3")), - contents: file, + file, }); } } @@ -530,7 +530,7 @@ async function processUrl(msg, url, spoiler = false) { ? `|| ${url} ||` : "", embeds, - files, + attachments: files, allowedMentions: { repliedUser: false, }, diff --git a/src/modules/foxwells.js b/src/modules/foxwells.js index 0bfebeb..eb1abeb 100644 --- a/src/modules/foxwells.js +++ b/src/modules/foxwells.js @@ -243,7 +243,7 @@ async function createBoardMessage(msg, count, fetchAttachment = true) { username: msg.member?.displayName ?? msg.author.username, threadID: VINBOARD_THREAD_ID, embeds: [embed], - files: image?.file ? [{contents: image.file, name: "thumb.jpg"}] : null, + attachments: image?.file ? [{file: image.file, filename: "thumb.jpg"}] : null, wait: true, }; }