diff --git a/src/commands/post.ts b/src/commands/post.ts index d7a9129..be88931 100644 --- a/src/commands/post.ts +++ b/src/commands/post.ts @@ -13,6 +13,7 @@ import isTOTPTokenCorrect from "#utils/is-totp-token-correct.js"; import MissingSystemKeyError from "#utils/errors/MissingSystemKeyError.js"; import MFAIncorrectCodeError from "#utils/errors/MFAIncorrectCodeError.js"; import IncorrectDecryptionKeyError from "#utils/errors/IncorrectDecryptionKeyError.js"; +import PostoadError from "#utils/errors/PostoadError.js"; const command = new Command({ name: "post", @@ -127,29 +128,30 @@ const command = new Command({ let mode: "image" | "video" = "image"; if (attachmentSourceJumpLink && !attachmentSourceJumpLink.includes("-#")) { - // + // Download each attachment. const attachmentSourceJumpLinkSplits = attachmentSourceJumpLink.split("/"); const channelID = attachmentSourceJumpLinkSplits[attachmentSourceJumpLinkSplits.length - 2]; const messageID = attachmentSourceJumpLinkSplits[attachmentSourceJumpLinkSplits.length - 1]; - const message = await interaction.client.rest.channels.getMessage(channelID, messageID); - for (const attachment of message.attachments.filter(() => true)) { + + try { - const response = await fetch(attachment.url); - if (!response.ok) { + const message = await interaction.client.rest.channels.getMessage(channelID, messageID); + for (const attachment of message.attachments.filter(() => true)) { - + const response = await fetch(attachment.url); + if (!response.ok) throw new PostoadError(`Unable to download attachment: ${attachment.url}`); - } + const blob = await response.blob(); + const altText = attachment.description; + blobsWithAltText.push([blob, altText]); - const blob = await response.blob(); - const altText = attachment.description; - blobsWithAltText.push([blob, altText]); + mode = attachment.contentType?.includes("video") ? "video" : mode; - if (attachment.contentType?.includes("video")) { + } - mode = "video"; + } catch { - } + // All alone again... } @@ -158,11 +160,23 @@ const command = new Command({ // Verify that there is at least text or media. if (!blobsWithAltText[0] && !text) { + const originalEmbed = originalResponse.embeds?.[0]; const originalComponent = originalResponse.components?.[0]; - if (!originalComponent) return; + if (!originalComponent || !originalEmbed) throw new Error(); await interaction.editOriginal({ + embeds: [ + { + ...originalEmbed, + fields: [ + { + name: "Attachment source", + value: "-# Reply to this message with any media that you want to add." + } + ] + } + ], components: [ { ...originalComponent, diff --git a/src/utils/Command.ts b/src/utils/Command.ts index 81c2c29..cdcbeeb 100644 --- a/src/utils/Command.ts +++ b/src/utils/Command.ts @@ -163,6 +163,10 @@ export default class Command { const authorID = (interaction.member ?? interaction.user)?.id; if (!authorID) return; + // Ignore everyone else that isn't the original actor. + const originalActorID = "message" in interaction ? interaction.message?.interactionMetadata?.user.id : undefined; + if (originalActorID && authorID !== originalActorID) return; + // Now check if the creator is under a cooldown. const executionTime = new Date().getTime(); const remainingCooldownTime = this.rateLimitedUsers[authorID] ? (this.rateLimitedUsers[authorID][0] + this.rateLimitedUsers[authorID][1]) - executionTime : 0;