updated /nucleus suggest to be nice, fixed help, added needs saving to footer for automod settings.
diff --git a/src/commands/settings/automod.ts b/src/commands/settings/automod.ts
index b65eb4c..68454e4 100644
--- a/src/commands/settings/automod.ts
+++ b/src/commands/settings/automod.ts
@@ -28,6 +28,7 @@
import getEmojiByName from "../../utils/getEmojiByName.js";
import { modalInteractionCollector } from "../../utils/dualCollector.js";
import listToAndMore from "../../utils/listToAndMore.js";
+import _ from "lodash";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder.setName("automod").setDescription("Setting for automatic moderation features");
@@ -157,6 +158,7 @@
const imageMenu = async (
interaction: StringSelectMenuInteraction,
m: Message,
+ unsavedChanges: boolean,
current: {
NSFW: boolean;
size: boolean;
@@ -186,7 +188,10 @@
.setTitle("Image Settings")
.setDescription(
`${emojiFromBoolean(current.NSFW)} **NSFW**\n` + `${emojiFromBoolean(current.size)} **Size**\n`
- );
+ )
+ .setFooter({
+ text: unsavedChanges ? "No changes made" : "Changes not saved"
+ });
await interaction.editReply({ embeds: [embed], components: [options] });
@@ -207,10 +212,12 @@
}
case "nsfw": {
current.NSFW = !current.NSFW;
+ unsavedChanges = true;
break;
}
case "size": {
current.size = !current.size;
+ unsavedChanges = true;
break;
}
}
@@ -221,6 +228,7 @@
const wordMenu = async (
interaction: StringSelectMenuInteraction,
m: Message,
+ unsavedChanges: boolean,
current: {
enabled: boolean;
words: { strict: string[]; loose: string[] };
@@ -296,7 +304,10 @@
)
)
.setStatus("Success")
- .setEmoji("GUILD.SETTINGS.GREEN");
+ .setEmoji("GUILD.SETTINGS.GREEN")
+ .setFooter({
+ text: unsavedChanges ? "No changes made" : "Changes not saved"
+ });
await interaction.editReply({ embeds: [embed], components: [selectMenu, buttons] });
@@ -320,6 +331,7 @@
}
case "enabled": {
current.enabled = !current.enabled;
+ unsavedChanges = true;
break;
}
}
@@ -391,6 +403,7 @@
.split(",")
.map((s) => s.trim())
.filter((s) => s.length > 0);
+ unsavedChanges = true;
break;
}
case "allowedUsers": {
@@ -402,6 +415,7 @@
"member",
"Word Filter"
);
+ unsavedChanges = true;
break;
}
case "allowedRoles": {
@@ -413,6 +427,7 @@
"role",
"Word Filter"
);
+ unsavedChanges = true;
break;
}
case "allowedChannels": {
@@ -424,6 +439,7 @@
"channel",
"Word Filter"
);
+ unsavedChanges = true;
break;
}
}
@@ -435,6 +451,7 @@
const inviteMenu = async (
interaction: StringSelectMenuInteraction,
m: Message,
+ unsavedChanges: boolean,
current: {
enabled: boolean;
allowed: { users: string[]; roles: string[]; channels: string[] };
@@ -503,7 +520,10 @@
)
)
.setStatus("Success")
- .setEmoji("GUILD.SETTINGS.GREEN");
+ .setEmoji("GUILD.SETTINGS.GREEN")
+ .setFooter({
+ text: unsavedChanges ? "No changes made" : "Changes not saved"
+ });
await interaction.editReply({ embeds: [embed], components: [menu, buttons] });
@@ -526,6 +546,7 @@
}
case "enabled": {
current.enabled = !current.enabled;
+ unsavedChanges = true;
break;
}
}
@@ -540,6 +561,7 @@
"member",
"Invite Settings"
);
+ unsavedChanges = true;
break;
}
case "roles": {
@@ -550,6 +572,7 @@
"role",
"Invite Settings"
);
+ unsavedChanges = true;
break;
}
case "channels": {
@@ -560,6 +583,7 @@
"channel",
"Invite Settings"
);
+ unsavedChanges = true;
break;
}
}
@@ -571,6 +595,7 @@
const mentionMenu = async (
interaction: StringSelectMenuInteraction,
m: Message,
+ unsavedChanges: boolean,
current: {
mass: number;
everyone: boolean;
@@ -690,7 +715,10 @@
}`
)
.setStatus("Success")
- .setEmoji("GUILD.SETTINGS.GREEN");
+ .setEmoji("GUILD.SETTINGS.GREEN")
+ .setFooter({
+ text: unsavedChanges ? "No changes made" : "Changes not saved"
+ });;
await interaction.editReply({ embeds: [embed], components: [menu, allowedMenu, buttons] });
@@ -714,10 +742,12 @@
}
case "everyone": {
current.everyone = !current.everyone;
+ unsavedChanges = true;
break;
}
case "roles": {
current.roles = !current.roles;
+ unsavedChanges = true;
break;
}
}
@@ -767,6 +797,7 @@
if (!out) break;
if (out.isButton()) break;
current.mass = parseInt(out.fields.getTextInputValue("mass"));
+ unsavedChanges = true;
break;
}
case "roles": {
@@ -778,6 +809,7 @@
"role",
"Mention Settings"
);
+ unsavedChanges = true;
break;
}
}
@@ -794,6 +826,7 @@
"member",
"Mention Settings"
);
+ unsavedChanges = true;
break;
}
case "roles": {
@@ -804,6 +837,7 @@
"role",
"Mention Settings"
);
+ unsavedChanges = true;
break;
}
case "channels": {
@@ -814,6 +848,7 @@
"channel",
"Mention Settings"
);
+ unsavedChanges = true;
break;
}
}
@@ -828,6 +863,7 @@
const cleanMenu = async (
interaction: StringSelectMenuInteraction,
m: Message,
+ unsavedChanges: boolean,
current?: {
channels?: string[];
allowed?: {
@@ -890,7 +926,10 @@
: "None"
}\n\n`
)
- .setStatus("Success");
+ .setStatus("Success")
+ .setFooter({
+ text: unsavedChanges ? "No changes made" : "Changes not saved"
+ });
await interaction.editReply({ embeds: [embed], components: [channelMenu, allowedMenu, buttons] });
@@ -958,6 +997,7 @@
}
}
}
+ unsavedChanges = true;
break;
}
case "allowed": {
@@ -970,6 +1010,7 @@
"member",
"Mention Settings"
);
+ unsavedChanges = true;
break;
}
case "roles": {
@@ -980,6 +1021,7 @@
"role",
"Mention Settings"
);
+ unsavedChanges = true;
break;
}
}
@@ -1001,15 +1043,16 @@
const callback = async (interaction: CommandInteraction): Promise<void> => {
if (!interaction.guild) return;
const m = await interaction.reply({ embeds: LoadingEmbed, fetchReply: true, ephemeral: true });
- const config = (await client.database.guilds.read(interaction.guild.id)).filters;
+ let config = (await client.database.guilds.read(interaction.guild.id)).filters;
let closed = false;
- const button = new ActionRowBuilder<ButtonBuilder>().addComponents(
- new ButtonBuilder().setCustomId("save").setLabel("Save").setStyle(ButtonStyle.Success)
- );
+ let current = _.cloneDeep(config);
do {
+ const button = new ActionRowBuilder<ButtonBuilder>().addComponents(
+ new ButtonBuilder().setCustomId("save").setLabel("Save").setStyle(ButtonStyle.Success).setDisabled(_.isEqual(config, current))
+ );
const selectMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId("filter")
@@ -1055,7 +1098,10 @@
`${emojiFromBoolean(config.clean.channels.length > 0)} **Clean**\n`
)
.setStatus("Success")
- .setEmoji("GUILD.SETTINGS.GREEN");
+ .setEmoji("GUILD.SETTINGS.GREEN")
+ .setFooter({
+ text: _.isEqual(config, current) ? "No changes made" : "Changes not saved"
+ });
await interaction.editReply({ embeds: [embed], components: [selectMenu, button] });
@@ -1069,41 +1115,37 @@
closed = true;
continue;
}
- if (i.isButton()) {
- await i.deferUpdate();
- await client.database.guilds.write(interaction.guild.id, { filters: config });
+ await i.deferUpdate();
+ if(i.isButton()) {
+ await client.database.guilds.write(interaction.guild.id, { filters: current });
await client.memory.forceUpdate(interaction.guild.id);
+ config = current;
+ current = _.cloneDeep(config);
} else {
switch (i.values[0]) {
case "invites": {
- await i.deferUpdate();
- config.invite = await inviteMenu(i, m, config.invite);
+ config.invite = await inviteMenu(i, m, _.isEqual(config, current), config.invite);
break;
}
case "mentions": {
- await i.deferUpdate();
- config.pings = await mentionMenu(i, m, config.pings);
+ config.pings = await mentionMenu(i, m, _.isEqual(config, current), config.pings);
break;
}
case "words": {
- await i.deferUpdate();
- config.wordFilter = await wordMenu(i, m, config.wordFilter);
+ config.wordFilter = await wordMenu(i, m, _.isEqual(config, current), config.wordFilter);
break;
}
case "malware": {
- await i.deferUpdate();
config.malware = !config.malware;
break;
}
case "images": {
- await i.deferUpdate();
- const next = await imageMenu(i, m, config.images);
+ const next = await imageMenu(i, m, _.isEqual(config, current), config.images);
config.images = next;
break;
}
case "clean": {
- await i.deferUpdate();
- const next = await cleanMenu(i, m, config.clean);
+ const next = await cleanMenu(i, m, _.isEqual(config, current), config.clean);
config.clean = next;
break;
}