Reformat using prettier
diff --git a/src/context/messages/purgeto.ts b/src/context/messages/purgeto.ts
index 3d7e95a..d2191d1 100644
--- a/src/context/messages/purgeto.ts
+++ b/src/context/messages/purgeto.ts
@@ -1,18 +1,28 @@
-import confirmationMessage from '../../utils/confirmationMessage.js';
-import EmojiEmbed from '../../utils/generateEmojiEmbed.js';
-import { LoadingEmbed } from '../../utils/defaults.js';
-import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContextMenuCommandBuilder, GuildMember, GuildTextBasedChannel, Message, MessageContextMenuCommandInteraction } from "discord.js";
+import confirmationMessage from "../../utils/confirmationMessage.js";
+import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import { LoadingEmbed } from "../../utils/defaults.js";
+import Discord, {
+ ActionRowBuilder,
+ ButtonBuilder,
+ ButtonStyle,
+ ContextMenuCommandBuilder,
+ GuildMember,
+ GuildTextBasedChannel,
+ Message,
+ MessageContextMenuCommandInteraction
+} from "discord.js";
import client from "../../utils/client.js";
-import { messageException } from '../../utils/createTemporaryStorage.js';
+import { messageException } from "../../utils/createTemporaryStorage.js";
-const command = new ContextMenuCommandBuilder()
- .setName("Purge up to here")
-
+const command = new ContextMenuCommandBuilder().setName("Purge up to here");
async function waitForButton(m: Discord.Message, member: Discord.GuildMember): Promise<boolean> {
let component;
try {
- component = m.awaitMessageComponent({ time: 200000, filter: (i) => i.user.id === member.id && i.channel!.id === m.channel.id && i.message.id === m.id });
+ component = m.awaitMessageComponent({
+ time: 200000,
+ filter: (i) => i.user.id === member.id && i.channel!.id === m.channel.id && i.message.id === m.id
+ });
} catch (e) {
return false;
}
@@ -20,7 +30,6 @@
return true;
}
-
const callback = async (interaction: MessageContextMenuCommandInteraction) => {
await interaction.targetMessage.fetch();
const targetMessage = interaction.targetMessage;
@@ -34,56 +43,74 @@
const history: Discord.Collection<string, Discord.Message> = await channel.messages.fetch({ limit: 100 });
if (Date.now() - targetMessage.createdTimestamp > 2 * 7 * 24 * 60 * 60 * 1000) {
- const m = await interaction.editReply({ embeds: [new EmojiEmbed()
- .setTitle("Purge")
- .setDescription("The message you selected is older than 2 weeks. Discord only allows bots to delete messages that are 2 weeks old or younger.")
- .setEmoji("CHANNEL.PURGE.RED")
- .setStatus("Danger")
- ], components: [
- new ActionRowBuilder<ButtonBuilder>().addComponents(
- new ButtonBuilder()
- .setCustomId("oldest")
- .setLabel("Select first allowed message")
- .setStyle(ButtonStyle.Primary),
- )
- ]});
- if (!await waitForButton(m, interaction.member as Discord.GuildMember)) return;
+ const m = await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Purge")
+ .setDescription(
+ "The message you selected is older than 2 weeks. Discord only allows bots to delete messages that are 2 weeks old or younger."
+ )
+ .setEmoji("CHANNEL.PURGE.RED")
+ .setStatus("Danger")
+ ],
+ components: [
+ new ActionRowBuilder<ButtonBuilder>().addComponents(
+ new ButtonBuilder()
+ .setCustomId("oldest")
+ .setLabel("Select first allowed message")
+ .setStyle(ButtonStyle.Primary)
+ )
+ ]
+ });
+ if (!(await waitForButton(m, interaction.member as Discord.GuildMember))) return;
} else if (!history.has(targetMessage.id)) {
- const m = await interaction.editReply({ embeds: [new EmojiEmbed()
- .setTitle("Purge")
- .setDescription("The message you selected is not in the last 100 messages in this channel. Discord only allows bots to delete 100 messages at a time.")
- .setEmoji("CHANNEL.PURGE.YELLOW")
- .setStatus("Warning")
- ], components: [
- new ActionRowBuilder<ButtonBuilder>().addComponents(
- new ButtonBuilder()
- .setCustomId("oldest")
- .setLabel("Select first allowed message")
- .setStyle(ButtonStyle.Primary),
- )
- ]});
- if (!await waitForButton(m, interaction.member as Discord.GuildMember)) return;
+ const m = await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Purge")
+ .setDescription(
+ "The message you selected is not in the last 100 messages in this channel. Discord only allows bots to delete 100 messages at a time."
+ )
+ .setEmoji("CHANNEL.PURGE.YELLOW")
+ .setStatus("Warning")
+ ],
+ components: [
+ new ActionRowBuilder<ButtonBuilder>().addComponents(
+ new ButtonBuilder()
+ .setCustomId("oldest")
+ .setLabel("Select first allowed message")
+ .setStyle(ButtonStyle.Primary)
+ )
+ ]
+ });
+ if (!(await waitForButton(m, interaction.member as Discord.GuildMember))) return;
} else {
allowedMessage = targetMessage;
}
if (!allowedMessage) {
// Find the oldest message thats younger than 2 weeks
- const messages = history.filter(m => Date.now() - m.createdTimestamp < 2 * 7 * 24 * 60 * 60 * 1000);
+ const messages = history.filter((m) => Date.now() - m.createdTimestamp < 2 * 7 * 24 * 60 * 60 * 1000);
allowedMessage = messages.sort((a, b) => a.createdTimestamp - b.createdTimestamp).first();
}
if (!allowedMessage) {
- await interaction.editReply({ embeds: [new EmojiEmbed()
- .setTitle("Purge")
- .setDescription("There are no valid messages in the last 100 messages. (No messages younger than 2 weeks)")
- .setEmoji("CHANNEL.PURGE.RED")
- .setStatus("Danger")
- ], components: [] });
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setTitle("Purge")
+ .setDescription(
+ "There are no valid messages in the last 100 messages. (No messages younger than 2 weeks)"
+ )
+ .setEmoji("CHANNEL.PURGE.RED")
+ .setStatus("Danger")
+ ],
+ components: []
+ });
return;
}
- let reason: string | null = null
+ let reason: string | null = null;
let confirmation;
let chosen = false;
let timedOut = false;
@@ -95,8 +122,9 @@
.setTitle("Purge")
.setDescription(
`[[Selected Message]](${allowedMessage.url})\n\n` +
- (reason ? "\n> " + reason.replaceAll("\n", "\n> ") : "*No reason provided*") + "\n\n" +
- `Are you sure you want to delete all messages from below the selected message?`
+ (reason ? "\n> " + reason.replaceAll("\n", "\n> ") : "*No reason provided*") +
+ "\n\n" +
+ `Are you sure you want to delete all messages from below the selected message?`
)
.addCustomBoolean(
"includeSelected",
@@ -121,8 +149,8 @@
.setColor("Danger")
.addReasonButton(reason ?? "")
.setFailedMessage("No changes were made", "Success", "CHANNEL.PURGE.GREEN")
- .send(true)
- reason = reason ?? ""
+ .send(true);
+ reason = reason ?? "";
if (confirmation.cancelled) timedOut = true;
else if (confirmation.success !== undefined) chosen = true;
else if (confirmation.newReason) reason = confirmation.newReason;
@@ -133,9 +161,9 @@
} while (!chosen && !timedOut);
if (timedOut || !confirmation.success) return;
const filteredMessages = history
- .filter(m => m.createdTimestamp >= allowedMessage!.createdTimestamp) // older than selected
- .filter(m => deleteUser ? m.author.id === targetMember.id : true) // only selected user
- .filter(m => deleteSelected ? true : m.id !== allowedMessage!.id) // include selected
+ .filter((m) => m.createdTimestamp >= allowedMessage!.createdTimestamp) // older than selected
+ .filter((m) => (deleteUser ? m.author.id === targetMember.id : true)) // only selected user
+ .filter((m) => (deleteSelected ? true : m.id !== allowedMessage!.id)); // include selected
const deleted = await (channel as GuildTextBasedChannel).bulkDelete(filteredMessages, true);
if (deleted.size === 0) {
@@ -183,16 +211,24 @@
}
};
log(data);
- const messages: Message[] = deleted.map(m => m).filter(m => m instanceof Message).map(m => m as Message);
- if (messages.length === 1) messageException(interaction.guild!.id, interaction.channel.id, messages[0]!.id)
- const messageArray: Message[] = messages.filter(message => !(
- message!.components.some(
- component => component.components.some(
- child => child.customId?.includes("transcript") ?? false
- )
+ const messages: Message[] = deleted
+ .map((m) => m)
+ .filter((m) => m instanceof Message)
+ .map((m) => m as Message);
+ if (messages.length === 1) messageException(interaction.guild!.id, interaction.channel.id, messages[0]!.id);
+ const messageArray: Message[] = messages
+ .filter(
+ (message) =>
+ !message!.components.some((component) =>
+ component.components.some((child) => child.customId?.includes("transcript") ?? false)
+ )
)
- )).map(message => message as Message);
- const transcript = await client.database.transcripts.createTranscript(messageArray, interaction, interaction.member as GuildMember);
+ .map((message) => message as Message);
+ const transcript = await client.database.transcripts.createTranscript(
+ messageArray,
+ interaction,
+ interaction.member as GuildMember
+ );
const [code, key, iv] = await client.database.transcripts.create(transcript);
@@ -206,14 +242,18 @@
],
components: [
new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
- new ButtonBuilder().setLabel("View").setStyle(ButtonStyle.Link).setURL(`https://clicks.codes/nucleus/transcript/${code}?key=${key}&iv=${iv}`).setDisabled(!code),
+ new ButtonBuilder()
+ .setLabel("View")
+ .setStyle(ButtonStyle.Link)
+ .setURL(`https://clicks.codes/nucleus/transcript/${code}?key=${key}&iv=${iv}`)
+ .setDisabled(!code)
])
]
});
-}
+};
const check = async (_interaction: MessageContextMenuCommandInteraction) => {
return true;
-}
+};
-export { command, callback, check }
+export { command, callback, check };