Still got errors and warnings, mostly the same and easy to fix
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index 521d8a7..13e688b 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -9,20 +9,20 @@
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
- .setName("purge")
- .setDescription("Bulk deletes messages in a channel")
- .addIntegerOption(option => option
- .setName("amount")
- .setDescription("The amount of messages to delete")
- .setRequired(false)
- .setMinValue(1)
- .setMaxValue(100))
- .addUserOption(option => option.setName("user").setDescription("The user to purge messages from").setRequired(false))
- .addStringOption(option => option.setName("reason").setDescription("The reason for the purge").setRequired(false))
+ .setName("purge")
+ .setDescription("Bulk deletes messages in a channel")
+ .addIntegerOption(option => option
+ .setName("amount")
+ .setDescription("The amount of messages to delete")
+ .setRequired(false)
+ .setMinValue(1)
+ .setMaxValue(100))
+ .addUserOption(option => option.setName("user").setDescription("The user to purge messages from").setRequired(false))
+ .addStringOption(option => option.setName("reason").setDescription("The reason for the purge").setRequired(false));
const callback = async (interaction: CommandInteraction): Promise<any> => {
- let user = interaction.options.getMember("user") as GuildMember ?? null
- let channel = (interaction.channel as GuildChannel)
+ const user = interaction.options.getMember("user") as GuildMember ?? null;
+ const channel = (interaction.channel as GuildChannel);
if (!(["GUILD_TEXT", "GUILD_NEWS", "GUILD_NEWS_THREAD", "GUILD_PUBLIC_THREAD", "GUILD_PRIVATE_THREAD"].includes(channel.type.toString()))) {
return await interaction.reply({
embeds: [
@@ -33,8 +33,8 @@
.setStatus("Danger")
],
components: [],
- ephemeral: true,
- })
+ ephemeral: true
+ });
}
// TODO:[Modals] Replace this with a modal
if ( !interaction.options.getInteger("amount") ) {
@@ -49,10 +49,10 @@
components: [],
ephemeral: true,
fetchReply: true
- })
- let deleted = [] as Discord.Message[]
+ });
+ let deleted = [] as Discord.Message[];
while (true) {
- let m = await interaction.editReply({
+ const m = await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.RED")
@@ -74,8 +74,8 @@
.setCustomId("5")
.setLabel("5")
.setStyle("SECONDARY")
- ]),
- new Discord.MessageActionRow().addComponents([
+ ]),
+ new Discord.MessageActionRow().addComponents([
new Discord.MessageButton()
.setCustomId("10")
.setLabel("10")
@@ -97,7 +97,7 @@
.setEmoji(getEmojiByName("CONTROL.TICK", "id"))
])
]
- })
+ });
let component;
try {
component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 300000});
@@ -109,12 +109,12 @@
let messages;
await (interaction.channel as TextChannel).messages.fetch({limit: amount}).then(async (ms) => {
if (user) {
- ms = ms.filter(m => m.author.id === user.id)
+ ms = ms.filter(m => m.author.id === user.id);
}
messages = await (channel as TextChannel).bulkDelete(ms, true);
- })
+ });
if (messages) {
- deleted = deleted.concat(messages.map(m => m))
+ deleted = deleted.concat(messages.map(m => m));
}
}
if (deleted.length === 0) return await interaction.editReply({
@@ -126,49 +126,46 @@
.setStatus("Danger")
],
components: []
- })
+ });
if (user) {
- try { await client.database.history.create("purge", interaction.guild.id, user, interaction.options.getString("reason"), null, null, deleted.length) } catch {}
+ await client.database.history.create("purge", interaction.guild.id, user, interaction.options.getString("reason"), null, null, deleted.length);
}
- let attachmentObject;
- try {
- const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger
- let 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)),
- messagesCleared: entry(deleted.length, deleted.length),
- },
- hidden: {
- guild: interaction.guild.id
- }
+ 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)),
+ messagesCleared: entry(deleted.length, deleted.length)
+ },
+ hidden: {
+ guild: interaction.guild.id
}
- log(data);
- let out = ""
- deleted.reverse().forEach(message => {
- out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`
- let lines = message.content.split("\n")
- lines.forEach(line => {out += `> ${line}\n`})
- out += `\n\n`
- })
- attachmentObject = {
- attachment: Buffer.from(out),
- name: `purge-${channel.id}-${Date.now()}.txt`,
- description: "Purge log"
- }
- } catch {}
- let m = await interaction.editReply({embeds: [new EmojiEmbed()
- .setEmoji(`CHANNEL.PURGE.GREEN`)
- .setTitle(`Purge`)
+ };
+ log(data);
+ let out = "";
+ deleted.reverse().forEach(message => {
+ out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`;
+ const lines = message.content.split("\n");
+ lines.forEach(line => {out += `> ${line}\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.MessageActionRow().addComponents([
@@ -177,29 +174,29 @@
.setLabel("Download transcript")
.setStyle("SUCCESS")
.setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
- ])]})
+ ])]});
let component;
try {
component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 300000});
- } catch {}
+ } catch { return; }
if (component && component.customId === "download") {
interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle(`Purge`)
+ .setTitle("Purge")
.setDescription("Uploaded")
.setStatus("Success")
- ], components: [], files: [attachmentObject]})
+ ], components: [], files: [attachmentObject]});
} else {
interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle(`Purge`)
+ .setTitle("Purge")
.setDescription("Messages cleared")
.setStatus("Success")
- ], components: []})
+ ], components: []});
}
- return
+ return;
} else {
- let confirmation = await new confirmationMessage(interaction)
+ const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.PURGE.RED")
.setTitle("Purge")
.setDescription(keyValueList({
@@ -208,69 +205,66 @@
"reason": `\n> ${interaction.options.getString("reason") ? interaction.options.getString("reason") : "*No reason provided*"}`
}))
.setColor("Danger")
- .send()
- if (confirmation.cancelled) return
+ .send();
+ if (confirmation.cancelled) return;
if (confirmation.success) {
let messages;
try {
if (!user) {
- let toDelete = await (interaction.channel as TextChannel).messages.fetch({limit: interaction.options.getInteger("amount")})
+ const toDelete = await (interaction.channel as TextChannel).messages.fetch({limit: interaction.options.getInteger("amount")});
messages = await (channel as TextChannel).bulkDelete(toDelete, true);
} else {
- let toDelete = (await (await (interaction.channel as TextChannel).messages.fetch({limit: 100}))
- .filter(m => m.author.id === user.id)).first(interaction.options.getInteger("amount"))
+ const toDelete = (await (await (interaction.channel as TextChannel).messages.fetch({limit: 100}))
+ .filter(m => m.author.id === user.id)).first(interaction.options.getInteger("amount"));
messages = await (channel as TextChannel).bulkDelete(toDelete, true);
}
} catch(e) {
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.RED")
- .setTitle(`Purge`)
+ .setTitle("Purge")
.setDescription("Something went wrong and no messages were deleted")
.setStatus("Danger")
- ], components: []})
+ ], components: []});
}
if (user) {
- try { await client.database.history.create("purge", interaction.guild.id, user, interaction.options.getString("reason"), null, null, messages.size) } catch {}
+ await client.database.history.create("purge", interaction.guild.id, user, interaction.options.getString("reason"), null, null, messages.size);
}
- let attachmentObject;
- try {
- const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger
- let 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)),
- messagesCleared: entry(messages.size, messages.size),
- },
- hidden: {
- guild: interaction.guild.id
- }
+ 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)),
+ messagesCleared: entry(messages.size, messages.size)
+ },
+ hidden: {
+ guild: interaction.guild.id
}
- log(data);
- let out = ""
- messages.reverse().forEach(message => {
- out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`
- let lines = message.content.split("\n")
- lines.forEach(line => {out += `> ${line}\n`})
- out += `\n\n`
- })
- attachmentObject = {
- attachment: Buffer.from(out),
- name: `purge-${channel.id}-${Date.now()}.txt`,
- description: `Purge log`
- }
- } catch {}
- let m = await interaction.editReply({embeds: [new EmojiEmbed()
- .setEmoji(`CHANNEL.PURGE.GREEN`)
- .setTitle(`Purge`)
+ };
+ log(data);
+ let out = "";
+ messages.reverse().forEach(message => {
+ out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`;
+ const lines = message.content.split("\n");
+ lines.forEach(line => {out += `> ${line}\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.MessageActionRow().addComponents([
@@ -279,48 +273,48 @@
.setLabel("Download transcript")
.setStyle("SUCCESS")
.setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
- ])]})
+ ])]});
let component;
try {
component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 300000});
- } catch {}
+ } catch { return; }
if (component && component.customId === "download") {
interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle(`Purge`)
+ .setTitle("Purge")
.setDescription("Transcript uploaded above")
.setStatus("Success")
- ], components: [], files: [attachmentObject]})
+ ], components: [], files: [attachmentObject]});
} else {
interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle(`Purge`)
+ .setTitle("Purge")
.setDescription("Messages cleared")
.setStatus("Success")
- ], components: []})
+ ], components: []});
}
} else {
await interaction.editReply({embeds: [new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle(`Purge`)
+ .setTitle("Purge")
.setDescription("No changes were made")
.setStatus("Success")
- ], components: []})
+ ], components: []});
}
}
-}
+};
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
- let member = (interaction.member as GuildMember)
- let me = (interaction.guild.me as GuildMember)
+ const member = (interaction.member as GuildMember);
+ const me = (interaction.guild.me as GuildMember);
// Check if nucleus has the manage_messages permission
if (! me.permissions.has("MANAGE_MESSAGES")) throw "I do not have the *Manage Messages* permission";
// Allow the owner to purge
- if (member.id === interaction.guild.ownerId) return true
+ if (member.id === interaction.guild.ownerId) return true;
// Check if the user has manage_messages permission
if (! member.permissions.has("MANAGE_MESSAGES")) throw "You do not have the *Manage Messages* permission";
// Allow purge
- return true
-}
+ return true;
+};
export { command, callback, check };
\ No newline at end of file