Working on viewas
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index 3020eb8..5425714 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -240,113 +240,153 @@
})
)
.setColor("Danger")
+ .setFailedMessage("No changes were made", "Success", "CHANNEL.PURGE.GREEN")
.send();
- if (confirmation.cancelled) return;
- if (confirmation.success) {
- let messages;
- try {
- if (!user) {
- const toDelete = await (interaction.channel as TextChannel).messages.fetch({
- limit: interaction.options.get("amount")?.value as number
- });
- messages = await (channel as TextChannel).bulkDelete(toDelete, true);
- } else {
- const toDelete = (
- await (
- await (interaction.channel as TextChannel).messages.fetch({
- limit: 100
- })
- ).filter((m) => m.author.id === user.id)
- ).first(interaction.options.get("amount")?.value as number);
- messages = await (channel as TextChannel).bulkDelete(toDelete, true);
- }
- } catch (e) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.RED")
- .setTitle("Purge")
- .setDescription("Something went wrong and no messages were deleted")
- .setStatus("Danger")
- ],
- components: []
+ if (confirmation.cancelled || !confirmation.success) return;
+ let messages;
+ try {
+ if (!user) {
+ const toDelete = await (interaction.channel as TextChannel).messages.fetch({
+ limit: interaction.options.get("amount")?.value as number
});
+ messages = await (channel as TextChannel).bulkDelete(toDelete, true);
+ } else {
+ const toDelete = (
+ await (
+ await (interaction.channel as TextChannel).messages.fetch({
+ limit: 100
+ })
+ ).filter((m) => m.author.id === user.id)
+ ).first(interaction.options.get("amount")?.value as number);
+ messages = await (channel as TextChannel).bulkDelete(toDelete, true);
}
- if (!messages) {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.RED")
- .setTitle("Purge")
- .setDescription("No messages could be deleted")
- .setStatus("Danger")
- ],
- components: []
- });
- return;
- }
- if (user) {
- await client.database.history.create(
- "purge",
- interaction.guild.id,
- user.user,
- interaction.user,
- (interaction.options.get("reason")?.value as (string | null)) ?? "*No reason provided*",
- null,
- null,
- messages.size.toString()
- );
- }
- const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
- const data = {
- meta: {
- type: "channelPurge",
- displayName: "Channel Purged",
- calculateType: "messageDelete",
- color: NucleusColors.red,
- emoji: "PUNISH.BAN.RED",
- timestamp: new Date().getTime()
- },
- list: {
- memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
- purgedBy: entry(interaction.user.id, renderUser(interaction.user)),
- channel: entry(interaction.channel!.id, renderChannel(interaction.channel! as GuildChannel)),
- messagesCleared: entry(messages.size.toString(), messages.size.toString())
- },
- hidden: {
- guild: interaction.guild.id
- }
- };
- log(data);
- let out = "";
- messages.reverse().forEach((message) => {
- if (!message) {
- out += "Unknown message\n\n"
- } else {
- const author = message.author ?? { username: "Unknown", discriminator: "0000", id: "Unknown" };
- out += `${author.username}#${author.discriminator} (${author.id}) [${new Date(
- message.createdTimestamp
- ).toISOString()}]\n`;
- if (message.content) {
- const lines = message.content.split("\n");
- lines.forEach((line) => {
- out += `> ${line}\n`;
- });
- }
- if (message.attachments.size > 0) {
- message.attachments.forEach((attachment) => {
- out += `Attachment > ${attachment.url}\n`;
- });
- }
- out += "\n\n";
- }
+ } catch (e) {
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.RED")
+ .setTitle("Purge")
+ .setDescription("Something went wrong and no messages were deleted")
+ .setStatus("Danger")
+ ],
+ components: []
});
- const attachmentObject = {
- attachment: Buffer.from(out),
- name: `purge-${channel.id}-${Date.now()}.txt`,
- description: "Purge log"
- };
- const m = (await interaction.editReply({
+ }
+ if (!messages) {
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.RED")
+ .setTitle("Purge")
+ .setDescription("No messages could be deleted")
+ .setStatus("Danger")
+ ],
+ components: []
+ });
+ return;
+ }
+ if (user) {
+ await client.database.history.create(
+ "purge",
+ interaction.guild.id,
+ user.user,
+ interaction.user,
+ (interaction.options.get("reason")?.value as (string | null)) ?? "*No reason provided*",
+ null,
+ null,
+ messages.size.toString()
+ );
+ }
+ const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
+ const data = {
+ meta: {
+ type: "channelPurge",
+ displayName: "Channel Purged",
+ calculateType: "messageDelete",
+ color: NucleusColors.red,
+ emoji: "PUNISH.BAN.RED",
+ timestamp: new Date().getTime()
+ },
+ list: {
+ memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
+ purgedBy: entry(interaction.user.id, renderUser(interaction.user)),
+ channel: entry(interaction.channel!.id, renderChannel(interaction.channel! as GuildChannel)),
+ messagesCleared: entry(messages.size.toString(), messages.size.toString())
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ };
+ log(data);
+ let out = "";
+ messages.reverse().forEach((message) => {
+ if (!message) {
+ out += "Unknown message\n\n"
+ } else {
+ const author = message.author ?? { username: "Unknown", discriminator: "0000", id: "Unknown" };
+ out += `${author.username}#${author.discriminator} (${author.id}) [${new Date(
+ message.createdTimestamp
+ ).toISOString()}]\n`;
+ if (message.content) {
+ const lines = message.content.split("\n");
+ lines.forEach((line) => {
+ out += `> ${line}\n`;
+ });
+ }
+ if (message.attachments.size > 0) {
+ message.attachments.forEach((attachment) => {
+ out += `Attachment > ${attachment.url}\n`;
+ });
+ }
+ out += "\n\n";
+ }
+ });
+ const attachmentObject = {
+ attachment: Buffer.from(out),
+ name: `purge-${channel.id}-${Date.now()}.txt`,
+ description: "Purge log"
+ };
+ const m = (await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Messages cleared")
+ .setStatus("Success")
+ ],
+ components: [
+ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
+ new Discord.ButtonBuilder()
+ .setCustomId("download")
+ .setLabel("Download transcript")
+ .setStyle(ButtonStyle.Success)
+ .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
+ ])
+ ]
+ })) as Discord.Message;
+ let component;
+ try {
+ component = await m.awaitMessageComponent({
+ filter: (m) => m.user.id === interaction.user.id,
+ time: 300000
+ });
+ } catch {
+ return;
+ }
+ if (component.customId === "download") {
+ interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Transcript uploaded above")
+ .setStatus("Success")
+ ],
+ components: [],
+ files: [attachmentObject]
+ });
+ } else {
+ interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
@@ -354,58 +394,6 @@
.setDescription("Messages cleared")
.setStatus("Success")
],
- components: [
- new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
- new Discord.ButtonBuilder()
- .setCustomId("download")
- .setLabel("Download transcript")
- .setStyle(ButtonStyle.Success)
- .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
- ])
- ]
- })) as Discord.Message;
- let component;
- try {
- component = await m.awaitMessageComponent({
- filter: (m) => m.user.id === interaction.user.id,
- time: 300000
- });
- } catch {
- return;
- }
- if (component.customId === "download") {
- interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("Transcript uploaded above")
- .setStatus("Success")
- ],
- components: [],
- files: [attachmentObject]
- });
- } else {
- interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("Messages cleared")
- .setStatus("Success")
- ],
- components: []
- });
- }
- } else {
- await interaction.editReply({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("No changes were made")
- .setStatus("Success")
- ],
components: []
});
}