|
| 1 | +import { |
| 2 | + ApplicationCommandType, |
| 3 | + ApplicationIntegrationType, |
| 4 | + Command, |
| 5 | + type CommandInteraction, |
| 6 | +} from "@buape/carbon"; |
| 7 | + |
| 8 | +export default class DeleteOldBookmarksCommand extends Command { |
| 9 | + name = "Delete Old Bookmarks"; |
| 10 | + description = "Deletes old bookmarks from V1 of Bookmarker"; |
| 11 | + type: ApplicationCommandType = ApplicationCommandType.Message; |
| 12 | + integrationTypes: ApplicationIntegrationType[] = [ |
| 13 | + ApplicationIntegrationType.GuildInstall, |
| 14 | + ApplicationIntegrationType.UserInstall, |
| 15 | + ]; |
| 16 | + |
| 17 | + defer = true; |
| 18 | + ephemeral = true; |
| 19 | + |
| 20 | + async run(interaction: CommandInteraction) { |
| 21 | + if (interaction.rawData.data.type !== ApplicationCommandType.Message) |
| 22 | + return; |
| 23 | + |
| 24 | + if (!interaction.user) return; |
| 25 | + if (!interaction.channel) return; |
| 26 | + if (interaction.guild?.id) |
| 27 | + return interaction.reply({ |
| 28 | + content: "This command can only be used in DMs.", |
| 29 | + }); |
| 30 | + |
| 31 | + const resolvedTargetMessage = |
| 32 | + interaction.rawData.data.resolved.messages[ |
| 33 | + interaction.rawData.data.target_id |
| 34 | + ]; |
| 35 | + |
| 36 | + const message = await interaction.client |
| 37 | + .fetchMessage(resolvedTargetMessage.channel_id, resolvedTargetMessage.id) |
| 38 | + .catch(() => { |
| 39 | + return null; |
| 40 | + }); |
| 41 | + |
| 42 | + if (!message) |
| 43 | + return interaction.reply({ |
| 44 | + content: |
| 45 | + "Failed to fetch message. This command can only be used in your personal DMs with me.", |
| 46 | + }); |
| 47 | + |
| 48 | + console.log(message.author?.id, process.env.DISCORD_CLIENT_ID); |
| 49 | + |
| 50 | + if (message.author?.id !== process.env.DISCORD_CLIENT_ID) { |
| 51 | + return interaction.reply({ |
| 52 | + content: "I can only delete bookmarks that I created.", |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + try { |
| 57 | + await message.delete().then(async () => { |
| 58 | + return interaction.reply({ |
| 59 | + content: "Bookmark deleted successfully!", |
| 60 | + }); |
| 61 | + }); |
| 62 | + } catch (error) { |
| 63 | + return interaction.reply({ |
| 64 | + content: `Failed to delete bookmark. Try again?\n\n${error}`, |
| 65 | + }); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments