Fix a bunch of linter errors
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index c554ee7..b78c423 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -1,4 +1,9 @@
-import Discord, { CommandInteraction, GuildChannel, GuildMember, TextChannel } from "discord.js";
+import Discord, {
+ CommandInteraction,
+ GuildChannel,
+ GuildMember,
+ TextChannel
+} from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@@ -10,19 +15,41 @@
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));
+ .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<void | unknown> => {
- 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()))) {
+const callback = async (
+ interaction: CommandInteraction
+): Promise<void | unknown> => {
+ 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: [
new EmojiEmbed()
@@ -36,7 +63,7 @@
});
}
// TODO:[Modals] Replace this with a modal
- if ( !interaction.options.getInteger("amount") ) {
+ if (!interaction.options.getInteger("amount")) {
await interaction.reply({
embeds: [
new EmojiEmbed()
@@ -51,12 +78,14 @@
});
let deleted = [] as Discord.Message[];
while (true) {
- const m = await interaction.editReply({
+ const m = (await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("CHANNEL.PURGE.RED")
.setTitle("Purge")
- .setDescription("Select how many messages to delete. You can continue clicking until all messages are cleared.")
+ .setDescription(
+ "Select how many messages to delete. You can continue clicking until all messages are cleared."
+ )
.setStatus("Danger")
],
components: [
@@ -96,40 +125,64 @@
.setEmoji(getEmojiByName("CONTROL.TICK", "id"))
])
]
- }) as Discord.Message;
+ })) as Discord.Message;
let component;
try {
- component = m.awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 300000});
- } catch (e) { break; }
+ component = m.awaitMessageComponent({
+ filter: (m) => m.user.id === interaction.user.id,
+ time: 300000
+ });
+ } catch (e) {
+ break;
+ }
component.deferUpdate();
if (component.customId === "done") break;
let amount;
- try { amount = parseInt(component.customId); } catch { break; }
+ try {
+ amount = parseInt(component.customId);
+ } catch {
+ break;
+ }
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);
- }
- messages = await (channel as TextChannel).bulkDelete(ms, true);
- });
+ await (interaction.channel as TextChannel).messages
+ .fetch({ limit: amount })
+ .then(async (ms) => {
+ if (user) {
+ 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({
- embeds: [
- new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.RED")
- .setTitle("Purge")
- .setDescription("No messages were deleted")
- .setStatus("Danger")
- ],
- components: []
- });
+ if (deleted.length === 0)
+ return await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.RED")
+ .setTitle("Purge")
+ .setDescription("No messages were deleted")
+ .setStatus("Danger")
+ ],
+ components: []
+ });
if (user) {
- await client.database.history.create("purge", interaction.guild.id, user, interaction.options.getString("reason"), null, null, deleted.length);
+ await client.database.history.create(
+ "purge",
+ interaction.guild.id,
+ user,
+ interaction.options.getString("reason"),
+ null,
+ null,
+ deleted.length
+ );
}
- const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
+ const { log, NucleusColors, entry, renderUser, renderChannel } =
+ client.logger;
const data = {
meta: {
type: "channelPurge",
@@ -140,9 +193,18 @@
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)),
+ 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: {
@@ -151,10 +213,16 @@
};
log(data);
let out = "";
- deleted.reverse().forEach(message => {
- out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`;
+ 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`;});
+ lines.forEach((line) => {
+ out += `> ${line}\n`;
+ });
out += "\n\n";
});
const attachmentObject = {
@@ -162,47 +230,73 @@
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([
- new Discord.MessageButton()
- .setCustomId("download")
- .setLabel("Download transcript")
- .setStyle("SUCCESS")
- .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
- ])]}) as Discord.Message;
+ const m = (await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Messages cleared")
+ .setStatus("Success")
+ ],
+ components: [
+ new Discord.MessageActionRow().addComponents([
+ new Discord.MessageButton()
+ .setCustomId("download")
+ .setLabel("Download transcript")
+ .setStyle("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; }
+ component = await m.awaitMessageComponent({
+ filter: (m) => m.user.id === interaction.user.id,
+ time: 300000
+ });
+ } catch {
+ return;
+ }
if (component && component.customId === "download") {
- interaction.editReply({embeds: [new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("Uploaded")
- .setStatus("Success")
- ], components: [], files: [attachmentObject]});
+ interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Uploaded")
+ .setStatus("Success")
+ ],
+ components: [],
+ files: [attachmentObject]
+ });
} else {
- interaction.editReply({embeds: [new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("Messages cleared")
- .setStatus("Success")
- ], components: []});
+ interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Messages cleared")
+ .setStatus("Success")
+ ],
+ components: []
+ });
}
return;
} else {
const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.PURGE.RED")
.setTitle("Purge")
- .setDescription(keyValueList({
- "channel": `<#${channel.id}>`,
- "amount": interaction.options.getInteger("amount").toString(),
- "reason": `\n> ${interaction.options.getString("reason") ? interaction.options.getString("reason") : "*No reason provided*"}`
- }))
+ .setDescription(
+ keyValueList({
+ channel: `<#${channel.id}>`,
+ amount: interaction.options.getInteger("amount").toString(),
+ reason: `\n> ${
+ interaction.options.getString("reason")
+ ? interaction.options.getString("reason")
+ : "*No reason provided*"
+ }`
+ })
+ )
.setColor("Danger")
.send();
if (confirmation.cancelled) return;
@@ -210,25 +304,57 @@
let messages;
try {
if (!user) {
- const toDelete = await (interaction.channel as TextChannel).messages.fetch({limit: interaction.options.getInteger("amount")});
- messages = await (channel as TextChannel).bulkDelete(toDelete, true);
+ const toDelete = await (
+ interaction.channel as TextChannel
+ ).messages.fetch({
+ limit: interaction.options.getInteger("amount")
+ });
+ 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.getInteger("amount"));
- messages = await (channel as TextChannel).bulkDelete(toDelete, true);
+ 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")
- .setDescription("Something went wrong and no messages were deleted")
- .setStatus("Danger")
- ], components: []});
+ } 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 (user) {
- await client.database.history.create("purge", interaction.guild.id, user, interaction.options.getString("reason"), null, null, messages.size);
+ await client.database.history.create(
+ "purge",
+ interaction.guild.id,
+ user,
+ interaction.options.getString("reason"),
+ null,
+ null,
+ messages.size
+ );
}
- const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
+ const { log, NucleusColors, entry, renderUser, renderChannel } =
+ client.logger;
const data = {
meta: {
type: "channelPurge",
@@ -239,9 +365,18 @@
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)),
+ 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: {
@@ -250,10 +385,16 @@
};
log(data);
let out = "";
- messages.reverse().forEach(message => {
- out += `${message.author.username}#${message.author.discriminator} (${message.author.id}) [${new Date(message.createdTimestamp).toISOString()}]\n`;
+ 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`;});
+ lines.forEach((line) => {
+ out += `> ${line}\n`;
+ });
out += "\n\n";
});
const attachmentObject = {
@@ -261,59 +402,85 @@
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([
- new Discord.MessageButton()
- .setCustomId("download")
- .setLabel("Download transcript")
- .setStyle("SUCCESS")
- .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
- ])]}) as Discord.Message;
+ const m = (await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("Messages cleared")
+ .setStatus("Success")
+ ],
+ components: [
+ new Discord.MessageActionRow().addComponents([
+ new Discord.MessageButton()
+ .setCustomId("download")
+ .setLabel("Download transcript")
+ .setStyle("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; }
+ component = await m.awaitMessageComponent({
+ filter: (m) => m.user.id === interaction.user.id,
+ time: 300000
+ });
+ } catch {
+ return;
+ }
if (component && component.customId === "download") {
- interaction.editReply({embeds: [new EmojiEmbed()
- .setEmoji("CHANNEL.PURGE.GREEN")
- .setTitle("Purge")
- .setDescription("Transcript uploaded above")
- .setStatus("Success")
- ], components: [], files: [attachmentObject]});
+ 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: []});
+ 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: []});
+ await interaction.editReply({
+ embeds: [
+ new EmojiEmbed()
+ .setEmoji("CHANNEL.PURGE.GREEN")
+ .setTitle("Purge")
+ .setDescription("No changes were made")
+ .setStatus("Success")
+ ],
+ components: []
+ });
}
}
};
const check = (interaction: CommandInteraction) => {
- const member = (interaction.member as GuildMember);
- const me = (interaction.guild.me as GuildMember);
+ const member = interaction.member as GuildMember;
+ const me = interaction.guild.me!;
// Check if nucleus has the manage_messages permission
- if (! me.permissions.has("MANAGE_MESSAGES")) throw "I do not have 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;
// Check if the user has manage_messages permission
- if (! member.permissions.has("MANAGE_MESSAGES")) throw "You do not have the *Manage Messages* permission";
+ if (!member.permissions.has("MANAGE_MESSAGES"))
+ throw "You do not have the *Manage Messages* permission";
// Allow purge
return true;
};
-export { command, callback, check };
\ No newline at end of file
+export { command, callback, check };