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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.wrangler/
.dev.vars
.dev.vars
.env.prod
68 changes: 68 additions & 0 deletions src/commands/delete-old-bookmarks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
ApplicationCommandType,
ApplicationIntegrationType,
Command,
type CommandInteraction,
} from "@buape/carbon";

export default class DeleteOldBookmarksCommand extends Command {
name = "Delete Old Bookmarks";
description = "Deletes old bookmarks from V1 of Bookmarker";
type: ApplicationCommandType = ApplicationCommandType.Message;
integrationTypes: ApplicationIntegrationType[] = [
ApplicationIntegrationType.GuildInstall,
ApplicationIntegrationType.UserInstall,
];

defer = true;
ephemeral = true;

async run(interaction: CommandInteraction) {
if (interaction.rawData.data.type !== ApplicationCommandType.Message)
return;

if (!interaction.user) return;
if (!interaction.channel) return;
if (interaction.guild?.id)
return interaction.reply({
content: "This command can only be used in DMs.",
});

const resolvedTargetMessage =
interaction.rawData.data.resolved.messages[
interaction.rawData.data.target_id
];

const message = await interaction.client
.fetchMessage(resolvedTargetMessage.channel_id, resolvedTargetMessage.id)
.catch(() => {
return null;
});

if (!message)
return interaction.reply({
content:
"Failed to fetch message. This command can only be used in your personal DMs with me.",
});

console.log(message.author?.id, process.env.DISCORD_CLIENT_ID);

if (message.author?.id !== process.env.DISCORD_CLIENT_ID) {
return interaction.reply({
content: "I can only delete bookmarks that I created.",
});
}

try {
await message.delete().then(async () => {
return interaction.reply({
content: "Bookmark deleted successfully!",
});
});
} catch (error) {
return interaction.reply({
content: `Failed to delete bookmark. Try again?\n\n${error}`,
});
}
}
}
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Client } from "@buape/carbon";
import { createHandler } from "@buape/carbon/adapters/fetch";
import BookmarkCommand from "./commands/bookmark.js";
import HelpCommand from "./commands/help.js";
import DeleteOldBookmarksCommand from "./commands/delete-old-bookmarks.js";
import ApplicationAuthorized from "./events/authorized.js";

const isBeta = process.env.ENVIRONMENT === "beta";
Expand All @@ -24,7 +25,11 @@ const client = new Client(
devGuilds: process.env.DISCORD_DEV_GUILDS?.split(","),
},
{
commands: [new BookmarkCommand(), new HelpCommand()],
commands: [
new BookmarkCommand(),
new HelpCommand(),
new DeleteOldBookmarksCommand(),
],
listeners: [new ApplicationAuthorized()],
},
);
Expand Down