Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions src/commands/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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...

}

Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading