More commands fixed and purge to here
diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts
index e32a720..7346bcc 100644
--- a/src/commands/mod/ban.ts
+++ b/src/commands/mod/ban.ts
@@ -53,6 +53,7 @@
false,
undefined,
"The user will be sent a DM",
+ null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
diff --git a/src/commands/mod/info.ts b/src/commands/mod/info.ts
index 12c414f..6e9abed 100644
--- a/src/commands/mod/info.ts
+++ b/src/commands/mod/info.ts
@@ -1,3 +1,4 @@
+import { LoadingEmbed } from './../../utils/defaultEmbeds.js';
import type { HistorySchema } from "../../utils/database.js";
import Discord, {
CommandInteraction,
@@ -8,11 +9,12 @@
ButtonBuilder,
MessageComponentInteraction,
ModalSubmitInteraction,
- TextInputComponent,
ButtonStyle,
- StringSelectMenuInteraction
+ StringSelectMenuInteraction,
+ TextInputStyle,
+ APIMessageComponentEmoji
} from "discord.js";
-import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { SlashCommandSubcommandBuilder, StringSelectMenuOptionBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
import client from "../../utils/client.js";
@@ -153,60 +155,59 @@
}
}
if (pageIndex === null) pageIndex = 0;
- const components = (
- openFilterPane
- ? [
- new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents(
- new Discord.SelectMenuBuilder()
- .setOptions(
- Object.entries(types).map(([key, value]) => ({
- label: value.text,
- value: key,
- default: filteredTypes.includes(key),
- emoji: client.emojis.resolve(getEmojiByName(value.emoji, "id"))
- }))
- )
- .setMinValues(1)
- .setMaxValues(Object.keys(types).length)
- .setCustomId("filter")
- .setPlaceholder("Select at least one event")
- )
- ]
- : []
- ).concat([
- new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
- new ButtonBuilder()
- .setCustomId("prevYear")
- .setLabel((currentYear - 1).toString())
- .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder().setCustomId("prevPage").setLabel("Previous page").setStyle(ButtonStyle.Primary),
- new ButtonBuilder().setCustomId("today").setLabel("Today").setStyle(ButtonStyle.Primary),
- new ButtonBuilder()
- .setCustomId("nextPage")
- .setLabel("Next page")
- .setStyle(ButtonStyle.Primary)
- .setDisabled(pageIndex >= groups.length - 1 && currentYear === new Date().getFullYear()),
- new ButtonBuilder()
- .setCustomId("nextYear")
- .setLabel((currentYear + 1).toString())
- .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
- .setStyle(ButtonStyle.Secondary)
- .setDisabled(currentYear === new Date().getFullYear())
- ]),
- new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
- new ButtonBuilder()
- .setLabel("Mod notes")
- .setCustomId("modNotes")
- .setStyle(ButtonStyle.Primary)
- .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
- new ButtonBuilder()
- .setLabel("Filter")
- .setCustomId("openFilter")
- .setStyle(openFilterPane ? ButtonStyle.Success : ButtonStyle.Primary)
- .setEmoji(getEmojiByName("ICONS.FILTER", "id"))
- ])
- ]);
+ let components: (ActionRowBuilder<Discord.StringSelectMenuBuilder> | ActionRowBuilder<ButtonBuilder>)[] = []
+ if (openFilterPane) components = components.concat([
+ new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents(
+ new Discord.StringSelectMenuBuilder().setOptions(
+ ...Object.entries(types).map(([key, value]) => new StringSelectMenuOptionBuilder()
+ .setLabel(value.text)
+ .setValue(key)
+ .setDefault(filteredTypes.includes(key))
+ .setEmoji(client.emojis.resolve(getEmojiByName(value.emoji, "id"))! as APIMessageComponentEmoji)
+ )
+ )
+ .setMinValues(1)
+ .setMaxValues(Object.keys(types).length)
+ .setCustomId("filter")
+ .setPlaceholder("Select events to show")
+ )
+ ])
+ components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
+ new ButtonBuilder()
+ .setCustomId("prevYear")
+ .setLabel((currentYear - 1).toString())
+ .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+ .setStyle(ButtonStyle.Secondary),
+ new ButtonBuilder()
+ .setCustomId("prevPage")
+ .setLabel("Previous page")
+ .setStyle(ButtonStyle.Primary),
+ new ButtonBuilder().setCustomId("today").setLabel("Today").setStyle(ButtonStyle.Primary),
+ new ButtonBuilder()
+ .setCustomId("nextPage")
+ .setLabel("Next page")
+ .setStyle(ButtonStyle.Primary)
+ .setDisabled(pageIndex >= groups.length - 1 && currentYear === new Date().getFullYear()),
+ new ButtonBuilder()
+ .setCustomId("nextYear")
+ .setLabel((currentYear + 1).toString())
+ .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
+ .setStyle(ButtonStyle.Secondary)
+ .setDisabled(currentYear === new Date().getFullYear())
+ ])])
+ components = components.concat([new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
+ new ButtonBuilder()
+ .setLabel("Mod notes")
+ .setCustomId("modNotes")
+ .setStyle(ButtonStyle.Primary)
+ .setEmoji(getEmojiByName("ICONS.EDIT", "id")),
+ new ButtonBuilder()
+ .setLabel("Filter")
+ .setCustomId("openFilter")
+ .setStyle(openFilterPane ? ButtonStyle.Success : ButtonStyle.Primary)
+ .setEmoji(getEmojiByName("ICONS.FILTER", "id"))
+ ])])
+
const end =
"\n\nJanuary " +
currentYear.toString() +
@@ -216,7 +217,7 @@
currentYear.toString();
if (groups.length > 0) {
const toRender = groups[Math.min(pageIndex, groups.length - 1)]!;
- m = (await interaction.editReply({
+ m = await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("MEMBER.JOIN")
@@ -226,25 +227,25 @@
)
.setStatus("Success")
.setFooter({
- text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : ""
+ text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
})
],
components: components
- })) as Message;
+ });
} else {
- m = (await interaction.editReply({
+ m = await interaction.editReply({
embeds: [
new EmojiEmbed()
.setEmoji("MEMBER.JOIN")
.setTitle("Moderation history for " + member.user.username)
- .setDescription(`**${currentYear}**\n\n*No events*` + "\n\n" + end)
+ .setDescription(`**${currentYear}**\n\n*No events*`)
.setStatus("Success")
.setFooter({
- text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : ""
+ text: openFilterPane && filteredTypes.length ? "Filters are currently enabled" : "No filters selected"
})
],
components: components
- })) as Message;
+ })
}
let i: MessageComponentInteraction;
try {
@@ -315,7 +316,7 @@
let m: Message;
const member = interaction.options.getMember("user") as Discord.GuildMember;
await interaction.reply({
- embeds: [new EmojiEmbed().setEmoji("NUCLEUS.LOADING").setTitle("Downloading Data").setStatus("Danger")],
+ embeds: LoadingEmbed,
ephemeral: true,
fetchReply: true
});
@@ -324,9 +325,7 @@
let timedOut = false;
while (!timedOut) {
note = await client.database.notes.read(member.guild.id, member.id);
- if (firstLoad && !note) {
- await showHistory(member, interaction);
- }
+ if (firstLoad && !note) { await showHistory(member, interaction); }
firstLoad = false;
m = (await interaction.editReply({
embeds: [
@@ -344,7 +343,7 @@
.setCustomId("modify")
.setEmoji(getEmojiByName("ICONS.EDIT", "id")),
new ButtonBuilder()
- .setLabel("View moderation history")
+ .setLabel("Moderation history")
.setStyle(ButtonStyle.Primary)
.setCustomId("history")
.setEmoji(getEmojiByName("ICONS.HISTORY", "id"))
@@ -364,14 +363,14 @@
.setCustomId("modal")
.setTitle("Editing moderator note")
.addComponents(
- new ActionRowBuilder<Discord.TextInputComponent>().addComponents(
- new TextInputComponent()
+ new ActionRowBuilder<Discord.TextInputBuilder>().addComponents(
+ new Discord.TextInputBuilder()
.setCustomId("note")
.setLabel("Note")
.setMaxLength(4000)
.setRequired(false)
- .setStyle("PARAGRAPH")
- .setValue(note ? note : "")
+ .setStyle(TextInputStyle.Paragraph)
+ .setValue(note ? note : " ")
)
)
);
@@ -408,7 +407,9 @@
if (out === null) {
continue;
} else if (out instanceof ModalSubmitInteraction) {
- const toAdd = out.fields.getTextInputValue("note") || null;
+ let toAdd = out.fields.getTextInputValue("note") || null;
+ if (toAdd === " ") toAdd = null;
+ if (toAdd) toAdd = toAdd.trim();
await client.database.notes.create(member.guild.id, member.id, toAdd);
} else {
continue;
diff --git a/src/commands/mod/kick.ts b/src/commands/mod/kick.ts
index 2feb5d7..dd71892 100644
--- a/src/commands/mod/kick.ts
+++ b/src/commands/mod/kick.ts
@@ -1,4 +1,4 @@
-import { LinkWarningFooter } from './../../utils/defaultEmbeds';
+import { LinkWarningFooter } from './../../utils/defaultEmbeds.js';
import { CommandInteraction, GuildMember, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
// @ts-expect-error
import humanizeDuration from "humanize-duration";
@@ -42,6 +42,7 @@
false,
null,
"The user will be sent a DM",
+ null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index 0e76cba..95c8c5a 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -192,6 +192,7 @@
async () =>
await create(interaction.guild, interaction.options.getUser("user")!, interaction.user, reason),
"An appeal ticket will be created when Confirm is clicked",
+ null,
"CONTROL.TICKET",
createAppealTicket
)
@@ -201,6 +202,7 @@
false,
undefined,
null,
+ null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
diff --git a/src/commands/mod/nick.ts b/src/commands/mod/nick.ts
index b5e5554..0975375 100644
--- a/src/commands/mod/nick.ts
+++ b/src/commands/mod/nick.ts
@@ -45,6 +45,7 @@
false,
null,
null,
+ null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index e9aa41a..6087890 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -1,4 +1,4 @@
-import Discord, { CommandInteraction, GuildChannel, GuildMember, TextChannel, ButtonStyle } from "discord.js";
+import Discord, { CommandInteraction, GuildChannel, GuildMember, TextChannel, ButtonStyle, ButtonBuilder } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@@ -26,7 +26,8 @@
);
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
- const user = (interaction.options.getMember("user") as GuildMember);
+ if (!interaction.guild) return;
+ 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(
@@ -46,7 +47,7 @@
});
}
// TODO:[Modals] Replace this with a modal
- if (!interaction.options.getInteger("amount")) {
+ if (!interaction.options.get("amount")) {
await interaction.reply({
embeds: [
new EmojiEmbed()
@@ -74,17 +75,17 @@
.setStatus("Danger")
],
components: [
- new Discord.ActionRowBuilder().addComponents([
+ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
new Discord.ButtonBuilder().setCustomId("1").setLabel("1").setStyle(ButtonStyle.Secondary),
new Discord.ButtonBuilder().setCustomId("3").setLabel("3").setStyle(ButtonStyle.Secondary),
new Discord.ButtonBuilder().setCustomId("5").setLabel("5").setStyle(ButtonStyle.Secondary)
]),
- new Discord.ActionRowBuilder().addComponents([
+ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
new Discord.ButtonBuilder().setCustomId("10").setLabel("10").setStyle(ButtonStyle.Secondary),
new Discord.ButtonBuilder().setCustomId("25").setLabel("25").setStyle(ButtonStyle.Secondary),
new Discord.ButtonBuilder().setCustomId("50").setLabel("50").setStyle(ButtonStyle.Secondary)
]),
- new Discord.ActionRowBuilder().addComponents([
+ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
new Discord.ButtonBuilder()
.setCustomId("done")
.setLabel("Done")
@@ -110,16 +111,14 @@
}
const amount = parseInt((await component).customId);
- let messages;
+ let messages: Discord.Message[] = [];
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);
+ messages = (await (channel as TextChannel).bulkDelete(ms, true)).map(m => m as Discord.Message);
});
- if (messages) {
- deleted = deleted.concat(messages.map((m) => m));
- }
+ deleted = deleted.concat(messages);
}
if (deleted.length === 0)
return await interaction.editReply({
@@ -136,11 +135,12 @@
await client.database.history.create(
"purge",
interaction.guild.id,
- user,
- interaction.options.getString("reason"),
+ user.user,
+ interaction.user,
+ (interaction.options.get("reason")?.value as (string | null)) ?? "*No reason provided*",
null,
null,
- deleted.length
+ deleted.length.toString()
);
}
const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
@@ -156,8 +156,8 @@
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)
+ channel: entry(interaction.channel!.id, renderChannel(interaction.channel! as GuildChannel)),
+ messagesCleared: entry(deleted.length.toString(), deleted.length.toString())
},
hidden: {
guild: interaction.guild.id
@@ -189,7 +189,7 @@
.setStatus("Success")
],
components: [
- new Discord.ActionRowBuilder().addComponents([
+ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
new Discord.ButtonBuilder()
.setCustomId("download")
.setLabel("Download transcript")
@@ -207,7 +207,7 @@
} catch {
return;
}
- if (component && component.customId === "download") {
+ if (component.customId === "download") {
interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -239,12 +239,8 @@
.setDescription(
keyValueList({
channel: `<#${channel.id}>`,
- amount: interaction.options.getInteger("amount").toString(),
- reason: `\n> ${
- interaction.options.getString("reason")
- ? interaction.options.getString("reason")
- : "*No reason provided*"
- }`
+ amount: (interaction.options.get("amount")?.value as number).toString(),
+ reason: `\n> ${interaction.options.get("reason")?.value ? interaction.options.get("reason")?.value : "*No reason provided*"}`
})
)
.setColor("Danger")
@@ -255,7 +251,7 @@
try {
if (!user) {
const toDelete = await (interaction.channel as TextChannel).messages.fetch({
- limit: interaction.options.getInteger("amount")
+ limit: interaction.options.get("amount")?.value as number
});
messages = await (channel as TextChannel).bulkDelete(toDelete, true);
} else {
@@ -265,7 +261,7 @@
limit: 100
})
).filter((m) => m.author.id === user.id)
- ).first(interaction.options.getInteger("amount"));
+ ).first(interaction.options.get("amount")?.value as number);
messages = await (channel as TextChannel).bulkDelete(toDelete, true);
}
} catch (e) {
@@ -280,15 +276,29 @@
components: []
});
}
+ 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,
- interaction.options.getString("reason"),
+ user.user,
+ interaction.user,
+ (interaction.options.get("reason")?.value as (string | null)) ?? "*No reason provided*",
null,
null,
- messages.size
+ messages.size.toString()
);
}
const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
@@ -304,8 +314,8 @@
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)
+ channel: entry(interaction.channel!.id, renderChannel(interaction.channel! as GuildChannel)),
+ messagesCleared: entry(messages.size.toString(), messages.size.toString())
},
hidden: {
guild: interaction.guild.id
@@ -314,14 +324,26 @@
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";
+ 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),
@@ -337,7 +359,7 @@
.setStatus("Success")
],
components: [
- new Discord.ActionRowBuilder().addComponents([
+ new Discord.ActionRowBuilder<ButtonBuilder>().addComponents([
new Discord.ButtonBuilder()
.setCustomId("download")
.setLabel("Download transcript")
@@ -355,7 +377,7 @@
} catch {
return;
}
- if (component && component.customId === "download") {
+ if (component.customId === "download") {
interaction.editReply({
embeds: [
new EmojiEmbed()
@@ -395,14 +417,15 @@
};
const check = (interaction: CommandInteraction) => {
+ if (!interaction.guild) return false;
const member = interaction.member as GuildMember;
- const me = interaction.guild.me!;
+ const me = interaction.guild.members.me!;
// Check if nucleus has the manage_messages permission
- if (!me.permissions.has("MANAGE_MESSAGES")) throw new Error("I do not have the *Manage Messages* permission");
+ if (!me.permissions.has("ManageMessages")) throw new Error("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 new Error("You do not have the *Manage Messages* permission");
+ if (!member.permissions.has("ManageMessages")) throw new Error("You do not have the *Manage Messages* permission");
// Allow purge
return true;
};
diff --git a/src/commands/mod/softban.ts b/src/commands/mod/softban.ts
index c9a71f6..12bfc3e 100644
--- a/src/commands/mod/softban.ts
+++ b/src/commands/mod/softban.ts
@@ -51,6 +51,7 @@
false,
null,
null,
+ null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
diff --git a/src/commands/mod/unmute.ts b/src/commands/mod/unmute.ts
index 40510a8..c93f8cc 100644
--- a/src/commands/mod/unmute.ts
+++ b/src/commands/mod/unmute.ts
@@ -38,6 +38,7 @@
false,
null,
"The user will be sent a DM",
+ null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)
diff --git a/src/commands/mod/warn.ts b/src/commands/mod/warn.ts
index 1c5223f..390baa5 100644
--- a/src/commands/mod/warn.ts
+++ b/src/commands/mod/warn.ts
@@ -41,6 +41,7 @@
!(await areTicketsEnabled(interaction.guild.id)),
async () => await create(interaction.guild!, interaction.options.getUser("user")!, interaction.user, reason),
"An appeal ticket will be created",
+ null,
"CONTROL.TICKET",
createAppealTicket
)
@@ -50,6 +51,7 @@
false,
null,
"The user will be sent a DM",
+ null,
"ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
notify
)