TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1 | import type Discord from "discord.js"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 2 | import { |
| 3 | ActionRowBuilder, |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 4 | AnySelectMenuInteraction, |
| 5 | APIMessageComponentEmoji, |
| 6 | ButtonBuilder, |
| 7 | ButtonInteraction, |
| 8 | ButtonStyle, |
| 9 | ChannelSelectMenuBuilder, |
| 10 | ChannelSelectMenuInteraction, |
| 11 | CommandInteraction, |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 12 | Message, |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 13 | ModalBuilder, |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 14 | RoleSelectMenuBuilder, |
| 15 | RoleSelectMenuInteraction, |
| 16 | StringSelectMenuBuilder, |
| 17 | StringSelectMenuInteraction, |
| 18 | StringSelectMenuOptionBuilder, |
| 19 | TextInputBuilder, |
| 20 | TextInputStyle, |
| 21 | UserSelectMenuBuilder, |
| 22 | UserSelectMenuInteraction |
| 23 | } from "discord.js"; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 24 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
| 25 | import { LoadingEmbed } from "../../utils/defaults.js"; |
| 26 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
| 27 | import client from "../../utils/client.js"; |
| 28 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 29 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
TheCodedProf | 1f67504 | 2023-02-16 17:01:29 -0500 | [diff] [blame] | 30 | import listToAndMore from "../../utils/listToAndMore.js"; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 31 | import _ from "lodash"; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 32 | |
| 33 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 34 | builder.setName("automod").setDescription("Setting for automatic moderation features"); |
| 35 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 36 | const emojiFromBoolean = (bool: boolean, id?: string) => |
| 37 | bool ? getEmojiByName("CONTROL.TICK", id) : getEmojiByName("CONTROL.CROSS", id); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 38 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 39 | const toSelectMenu = async ( |
| 40 | interaction: StringSelectMenuInteraction, |
| 41 | m: Message, |
| 42 | ids: string[], |
| 43 | type: "member" | "role" | "channel", |
| 44 | title: string |
| 45 | ): Promise<string[]> => { |
| 46 | const back = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 47 | new ButtonBuilder() |
| 48 | .setCustomId("back") |
| 49 | .setLabel("Back") |
| 50 | .setStyle(ButtonStyle.Secondary) |
| 51 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji) |
| 52 | ); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 53 | let closed; |
| 54 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 55 | let render: string[] = []; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 56 | let mapped: string[] = []; |
| 57 | let menu: UserSelectMenuBuilder | RoleSelectMenuBuilder | ChannelSelectMenuBuilder; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 58 | switch (type) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 59 | case "member": { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 60 | menu = new UserSelectMenuBuilder().setCustomId("user").setPlaceholder("Select users").setMaxValues(25); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 61 | mapped = await Promise.all( |
| 62 | ids.map(async (id) => { |
| 63 | return (await client.users.fetch(id).then((user) => user.tag)) || "Unknown User"; |
| 64 | }) |
| 65 | ); |
| 66 | render = ids.map((id) => client.logger.renderUser(id)); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 67 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 68 | } |
| 69 | case "role": { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 70 | menu = new RoleSelectMenuBuilder().setCustomId("role").setPlaceholder("Select roles").setMaxValues(25); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 71 | mapped = await Promise.all( |
| 72 | ids.map(async (id) => { |
| 73 | return await interaction.guild!.roles.fetch(id).then((role) => role?.name ?? "Unknown Role"); |
| 74 | }) |
| 75 | ); |
| 76 | render = ids.map((id) => client.logger.renderRole(id, interaction.guild!)); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 77 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 78 | } |
| 79 | case "channel": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 80 | menu = new ChannelSelectMenuBuilder() |
| 81 | .setCustomId("channel") |
| 82 | .setPlaceholder("Select channels") |
| 83 | .setMaxValues(25); |
| 84 | mapped = await Promise.all( |
| 85 | ids.map(async (id) => { |
| 86 | return await interaction |
| 87 | .guild!.channels.fetch(id) |
| 88 | .then((channel) => channel?.name ?? "Unknown Role"); |
| 89 | }) |
| 90 | ); |
| 91 | render = ids.map((id) => client.logger.renderChannel(id)); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 92 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 93 | } |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 94 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 95 | const removeOptions = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 96 | new StringSelectMenuBuilder() |
| 97 | .setCustomId("remove") |
| 98 | .setPlaceholder("Remove") |
| 99 | .addOptions( |
| 100 | mapped.map((name, i) => new StringSelectMenuOptionBuilder().setLabel(name).setValue(ids[i]!)) |
| 101 | ) |
| 102 | .setDisabled(ids.length === 0) |
| 103 | ); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 104 | |
| 105 | const embed = new EmojiEmbed() |
| 106 | .setTitle(title) |
| 107 | .setEmoji(getEmojiByName("GUILD.SETTINGS.GREEN")) |
| 108 | .setDescription(`Select ${type}s:\n\nCurrent:\n` + (render.length > 0 ? render.join("\n") : "None")) |
| 109 | .setStatus("Success"); |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 110 | const components: ActionRowBuilder< |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 111 | | StringSelectMenuBuilder |
| 112 | | ButtonBuilder |
| 113 | | ChannelSelectMenuBuilder |
| 114 | | UserSelectMenuBuilder |
| 115 | | RoleSelectMenuBuilder |
| 116 | >[] = [new ActionRowBuilder<typeof menu>().addComponents(menu)]; |
| 117 | if (ids.length > 0) components.push(removeOptions); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 118 | components.push(back); |
| 119 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 120 | await interaction.editReply({ embeds: [embed], components: components }); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 121 | |
| 122 | let i: AnySelectMenuInteraction | ButtonInteraction; |
| 123 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 124 | i = await m.awaitMessageComponent({ filter: (i) => i.user.id === interaction.user.id, time: 300000 }); |
| 125 | } catch (e) { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 126 | closed = true; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 127 | continue; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 128 | } |
| 129 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 130 | if (i.isButton()) { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 131 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 132 | if (i.customId === "back") { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 133 | closed = true; |
| 134 | break; |
| 135 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 136 | } else if (i.isStringSelectMenu()) { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 137 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 138 | if (i.customId === "remove") { |
| 139 | ids = ids.filter((id) => id !== (i as StringSelectMenuInteraction).values[0]); |
| 140 | if (ids.length === 0) { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 141 | menu.data.disabled = true; |
| 142 | } |
| 143 | } |
| 144 | } else { |
| 145 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 146 | if (i.customId === "user") { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 147 | ids = ids.concat((i as UserSelectMenuInteraction).values); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 148 | } else if (i.customId === "role") { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 149 | ids = ids.concat((i as RoleSelectMenuInteraction).values); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 150 | } else if (i.customId === "channel") { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 151 | ids = ids.concat((i as ChannelSelectMenuInteraction).values); |
| 152 | } |
| 153 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 154 | } while (!closed); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 155 | return ids; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 156 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 157 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 158 | const imageMenu = async ( |
| 159 | interaction: StringSelectMenuInteraction, |
| 160 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 161 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 162 | current: { |
| 163 | NSFW: boolean; |
| 164 | size: boolean; |
| 165 | } |
| 166 | ): Promise<{ NSFW: boolean; size: boolean }> => { |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 167 | let closed = false; |
| 168 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 169 | const options = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 170 | new ButtonBuilder() |
| 171 | .setCustomId("back") |
| 172 | .setLabel("Back") |
| 173 | .setStyle(ButtonStyle.Secondary) |
| 174 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 175 | new ButtonBuilder() |
| 176 | .setCustomId("nsfw") |
| 177 | .setLabel("NSFW") |
| 178 | .setStyle(current.NSFW ? ButtonStyle.Success : ButtonStyle.Danger) |
| 179 | .setEmoji(emojiFromBoolean(current.NSFW, "id") as APIMessageComponentEmoji), |
| 180 | new ButtonBuilder() |
| 181 | .setCustomId("size") |
| 182 | .setLabel("Size") |
| 183 | .setStyle(current.size ? ButtonStyle.Success : ButtonStyle.Danger) |
| 184 | .setEmoji(emojiFromBoolean(current.size, "id") as APIMessageComponentEmoji) |
| 185 | ); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 186 | |
| 187 | const embed = new EmojiEmbed() |
| 188 | .setTitle("Image Settings") |
| 189 | .setDescription( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 190 | `${emojiFromBoolean(current.NSFW)} **NSFW**\n` + `${emojiFromBoolean(current.size)} **Size**\n` |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 191 | ) |
| 192 | .setFooter({ |
| 193 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
| 194 | }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 195 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 196 | await interaction.editReply({ embeds: [embed], components: [options] }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 197 | |
| 198 | let i: ButtonInteraction; |
| 199 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 200 | i = (await m.awaitMessageComponent({ |
| 201 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 202 | time: 300000 |
| 203 | })) as ButtonInteraction; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 204 | } catch (e) { |
| 205 | return current; |
| 206 | } |
| 207 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 208 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 209 | case "back": { |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 210 | closed = true; |
| 211 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 212 | } |
| 213 | case "nsfw": { |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 214 | current.NSFW = !current.NSFW; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 215 | unsavedChanges = true; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 216 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 217 | } |
| 218 | case "size": { |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 219 | current.size = !current.size; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 220 | unsavedChanges = true; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 221 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 222 | } |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 223 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 224 | } while (!closed); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 225 | return current; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 226 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 227 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 228 | const wordMenu = async ( |
| 229 | interaction: StringSelectMenuInteraction, |
| 230 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 231 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 232 | current: { |
| 233 | enabled: boolean; |
| 234 | words: { strict: string[]; loose: string[] }; |
| 235 | allowed: { users: string[]; roles: string[]; channels: string[] }; |
| 236 | } |
| 237 | ): Promise<{ |
| 238 | enabled: boolean; |
| 239 | words: { strict: string[]; loose: string[] }; |
| 240 | allowed: { users: string[]; roles: string[]; channels: string[] }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 241 | }> => { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 242 | let closed = false; |
| 243 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 244 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 245 | new ButtonBuilder() |
| 246 | .setCustomId("back") |
| 247 | .setLabel("Back") |
| 248 | .setStyle(ButtonStyle.Secondary) |
| 249 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 250 | new ButtonBuilder() |
| 251 | .setCustomId("enabled") |
| 252 | .setLabel("Enabled") |
| 253 | .setStyle(current.enabled ? ButtonStyle.Success : ButtonStyle.Danger) |
| 254 | .setEmoji(emojiFromBoolean(current.enabled, "id") as APIMessageComponentEmoji) |
| 255 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 256 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 257 | const selectMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 258 | new StringSelectMenuBuilder() |
| 259 | .setCustomId("edit") |
| 260 | .setPlaceholder("Edit... ") |
| 261 | .addOptions( |
| 262 | new StringSelectMenuOptionBuilder() |
| 263 | .setLabel("Words") |
| 264 | .setDescription("Edit your list of words to filter") |
| 265 | .setValue("words"), |
| 266 | new StringSelectMenuOptionBuilder() |
| 267 | .setLabel("Allowed Users") |
| 268 | .setDescription("Users who will be unaffected by the word filter") |
| 269 | .setValue("allowedUsers"), |
| 270 | new StringSelectMenuOptionBuilder() |
| 271 | .setLabel("Allowed Roles") |
| 272 | .setDescription("Roles that will be unaffected by the word filter") |
| 273 | .setValue("allowedRoles"), |
| 274 | new StringSelectMenuOptionBuilder() |
| 275 | .setLabel("Allowed Channels") |
| 276 | .setDescription("Channels where the word filter will not apply") |
| 277 | .setValue("allowedChannels") |
| 278 | ) |
| 279 | .setDisabled(!current.enabled) |
| 280 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 281 | |
| 282 | const embed = new EmojiEmbed() |
| 283 | .setTitle("Word Filters") |
| 284 | .setDescription( |
| 285 | `${emojiFromBoolean(current.enabled)} **Enabled**\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 286 | `**Strict Words:** ${listToAndMore(current.words.strict, 5)}\n` + |
| 287 | `**Loose Words:** ${listToAndMore(current.words.loose, 5)}\n\n` + |
| 288 | `**Users:** ` + |
| 289 | listToAndMore( |
| 290 | current.allowed.users.map((user) => `<@${user}>`), |
| 291 | 5 |
| 292 | ) + |
| 293 | `\n` + |
| 294 | `**Roles:** ` + |
| 295 | listToAndMore( |
| 296 | current.allowed.roles.map((role) => `<@&${role}>`), |
| 297 | 5 |
| 298 | ) + |
| 299 | `\n` + |
| 300 | `**Channels:** ` + |
| 301 | listToAndMore( |
| 302 | current.allowed.channels.map((channel) => `<#${channel}>`), |
| 303 | 5 |
| 304 | ) |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 305 | ) |
| 306 | .setStatus("Success") |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 307 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 308 | .setFooter({ |
| 309 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
| 310 | }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 311 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 312 | await interaction.editReply({ embeds: [embed], components: [selectMenu, buttons] }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 313 | |
| 314 | let i: ButtonInteraction | StringSelectMenuInteraction; |
| 315 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 316 | i = (await m.awaitMessageComponent({ |
| 317 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 318 | time: 300000 |
| 319 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 320 | } catch (e) { |
| 321 | closed = true; |
| 322 | break; |
| 323 | } |
| 324 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 325 | if (i.isButton()) { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 326 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 327 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 328 | case "back": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 329 | closed = true; |
| 330 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 331 | } |
| 332 | case "enabled": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 333 | current.enabled = !current.enabled; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 334 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 335 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 336 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 337 | } |
| 338 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 339 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 340 | case "words": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 341 | await interaction.editReply({ |
| 342 | embeds: [ |
| 343 | new EmojiEmbed() |
| 344 | .setTitle("Word Filter") |
| 345 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 346 | .setStatus("Success") |
| 347 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 348 | ], |
| 349 | components: [ |
| 350 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 351 | new ButtonBuilder() |
| 352 | .setLabel("Back") |
| 353 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 354 | .setStyle(ButtonStyle.Primary) |
| 355 | .setCustomId("back") |
| 356 | ) |
| 357 | ] |
| 358 | }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 359 | const modal = new ModalBuilder() |
| 360 | .setTitle("Word Filter") |
| 361 | .setCustomId("wordFilter") |
| 362 | .addComponents( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 363 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 364 | new TextInputBuilder() |
| 365 | .setCustomId("wordStrict") |
| 366 | .setLabel("Strict Words") |
| 367 | .setPlaceholder( |
| 368 | "Matches anywhere in the message, including surrounded by other characters" |
| 369 | ) |
| 370 | .setValue(current.words.strict.join(", ")) |
| 371 | .setStyle(TextInputStyle.Paragraph) |
| 372 | .setRequired(false) |
| 373 | ), |
| 374 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 375 | new TextInputBuilder() |
| 376 | .setCustomId("wordLoose") |
| 377 | .setLabel("Loose Words") |
| 378 | .setPlaceholder( |
| 379 | "Matches only if the word is by itself, surrounded by spaces or punctuation" |
| 380 | ) |
| 381 | .setValue(current.words.loose.join(", ")) |
| 382 | .setStyle(TextInputStyle.Paragraph) |
| 383 | .setRequired(false) |
| 384 | ) |
| 385 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 386 | |
| 387 | await i.showModal(modal); |
| 388 | let out; |
| 389 | try { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 390 | out = await modalInteractionCollector(m, interaction.user); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 391 | } catch (e) { |
| 392 | break; |
| 393 | } |
| 394 | if (!out) break; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 395 | if (out.isButton()) break; |
| 396 | current.words.strict = out.fields |
| 397 | .getTextInputValue("wordStrict") |
| 398 | .split(",") |
| 399 | .map((s) => s.trim()) |
| 400 | .filter((s) => s.length > 0); |
| 401 | current.words.loose = out.fields |
| 402 | .getTextInputValue("wordLoose") |
| 403 | .split(",") |
| 404 | .map((s) => s.trim()) |
| 405 | .filter((s) => s.length > 0); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 406 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 407 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 408 | } |
| 409 | case "allowedUsers": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 410 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 411 | current.allowed.users = await toSelectMenu( |
| 412 | interaction, |
| 413 | m, |
| 414 | current.allowed.users, |
| 415 | "member", |
| 416 | "Word Filter" |
| 417 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 418 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 419 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 420 | } |
| 421 | case "allowedRoles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 422 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 423 | current.allowed.roles = await toSelectMenu( |
| 424 | interaction, |
| 425 | m, |
| 426 | current.allowed.roles, |
| 427 | "role", |
| 428 | "Word Filter" |
| 429 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 430 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 431 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 432 | } |
| 433 | case "allowedChannels": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 434 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 435 | current.allowed.channels = await toSelectMenu( |
| 436 | interaction, |
| 437 | m, |
| 438 | current.allowed.channels, |
| 439 | "channel", |
| 440 | "Word Filter" |
| 441 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 442 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 443 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 444 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 445 | } |
| 446 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 447 | } while (!closed); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 448 | return current; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 449 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 450 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 451 | const inviteMenu = async ( |
| 452 | interaction: StringSelectMenuInteraction, |
| 453 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 454 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 455 | current: { |
| 456 | enabled: boolean; |
| 457 | allowed: { users: string[]; roles: string[]; channels: string[] }; |
| 458 | } |
| 459 | ): Promise<{ |
| 460 | enabled: boolean; |
| 461 | allowed: { users: string[]; roles: string[]; channels: string[] }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 462 | }> => { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 463 | let closed = false; |
| 464 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 465 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 466 | new ButtonBuilder() |
| 467 | .setCustomId("back") |
| 468 | .setLabel("Back") |
| 469 | .setStyle(ButtonStyle.Secondary) |
| 470 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 471 | new ButtonBuilder() |
| 472 | .setCustomId("enabled") |
| 473 | .setLabel(current.enabled ? "Enabled" : "Disabled") |
| 474 | .setStyle(current.enabled ? ButtonStyle.Success : ButtonStyle.Danger) |
| 475 | .setEmoji(emojiFromBoolean(current.enabled, "id") as APIMessageComponentEmoji) |
| 476 | ); |
| 477 | const menu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 478 | new StringSelectMenuBuilder() |
| 479 | .setCustomId("toEdit") |
| 480 | .setPlaceholder("Edit your allow list") |
| 481 | .addOptions( |
| 482 | new StringSelectMenuOptionBuilder() |
| 483 | .setLabel("Users") |
| 484 | .setDescription("Users that are allowed to send invites") |
| 485 | .setValue("users"), |
| 486 | new StringSelectMenuOptionBuilder() |
| 487 | .setLabel("Roles") |
| 488 | .setDescription("Roles that are allowed to send invites") |
| 489 | .setValue("roles"), |
| 490 | new StringSelectMenuOptionBuilder() |
| 491 | .setLabel("Channels") |
| 492 | .setDescription("Channels that anyone is allowed to send invites in") |
| 493 | .setValue("channels") |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 494 | ) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 495 | .setDisabled(!current.enabled) |
| 496 | ); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 497 | |
| 498 | const embed = new EmojiEmbed() |
| 499 | .setTitle("Invite Settings") |
| 500 | .setDescription( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 501 | "Automatically deletes invites sent by users (outside of staff members and self promotion channels)" + |
| 502 | `\n\n` + |
| 503 | `${emojiFromBoolean(current.enabled)} **${current.enabled ? "Enabled" : "Disabled"}**\n\n` + |
| 504 | `**Users:** ` + |
| 505 | listToAndMore( |
| 506 | current.allowed.users.map((user) => `<@${user}>`), |
| 507 | 5 |
| 508 | ) + |
| 509 | `\n` + |
| 510 | `**Roles:** ` + |
| 511 | listToAndMore( |
| 512 | current.allowed.roles.map((role) => `<@&${role}>`), |
| 513 | 5 |
| 514 | ) + |
| 515 | `\n` + |
| 516 | `**Channels:** ` + |
| 517 | listToAndMore( |
| 518 | current.allowed.channels.map((channel) => `<#${channel}>`), |
| 519 | 5 |
| 520 | ) |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 521 | ) |
| 522 | .setStatus("Success") |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 523 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 524 | .setFooter({ |
| 525 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
| 526 | }); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 527 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 528 | await interaction.editReply({ embeds: [embed], components: [menu, buttons] }); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 529 | |
| 530 | let i: ButtonInteraction | StringSelectMenuInteraction; |
| 531 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 532 | i = (await m.awaitMessageComponent({ |
| 533 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 534 | time: 300000 |
| 535 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 536 | } catch (e) { |
| 537 | return current; |
| 538 | } |
| 539 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 540 | if (i.isButton()) { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 541 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 542 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 543 | case "back": { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 544 | closed = true; |
| 545 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 546 | } |
| 547 | case "enabled": { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 548 | current.enabled = !current.enabled; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 549 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 550 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 551 | } |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 552 | } |
| 553 | } else { |
| 554 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 555 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 556 | case "users": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 557 | current.allowed.users = await toSelectMenu( |
| 558 | interaction, |
| 559 | m, |
| 560 | current.allowed.users, |
| 561 | "member", |
| 562 | "Invite Settings" |
| 563 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 564 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 565 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 566 | } |
| 567 | case "roles": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 568 | current.allowed.roles = await toSelectMenu( |
| 569 | interaction, |
| 570 | m, |
| 571 | current.allowed.roles, |
| 572 | "role", |
| 573 | "Invite Settings" |
| 574 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 575 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 576 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 577 | } |
| 578 | case "channels": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 579 | current.allowed.channels = await toSelectMenu( |
| 580 | interaction, |
| 581 | m, |
| 582 | current.allowed.channels, |
| 583 | "channel", |
| 584 | "Invite Settings" |
| 585 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 586 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 587 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 588 | } |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 589 | } |
| 590 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 591 | } while (!closed); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 592 | return current; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 593 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 594 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 595 | const mentionMenu = async ( |
| 596 | interaction: StringSelectMenuInteraction, |
| 597 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 598 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 599 | current: { |
| 600 | mass: number; |
| 601 | everyone: boolean; |
| 602 | roles: boolean; |
| 603 | allowed: { |
| 604 | roles: string[]; |
| 605 | rolesToMention: string[]; |
| 606 | users: string[]; |
| 607 | channels: string[]; |
| 608 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 609 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 610 | ): Promise<{ |
| 611 | mass: number; |
| 612 | everyone: boolean; |
| 613 | roles: boolean; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 614 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 615 | roles: string[]; |
| 616 | rolesToMention: string[]; |
| 617 | users: string[]; |
| 618 | channels: string[]; |
| 619 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 620 | }> => { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 621 | let closed = false; |
| 622 | |
| 623 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 624 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 625 | new ButtonBuilder() |
| 626 | .setCustomId("back") |
| 627 | .setLabel("Back") |
| 628 | .setStyle(ButtonStyle.Secondary) |
| 629 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 630 | new ButtonBuilder() |
| 631 | .setCustomId("everyone") |
| 632 | .setLabel(current.everyone ? "Everyone" : "No one") |
| 633 | .setStyle(current.everyone ? ButtonStyle.Success : ButtonStyle.Danger) |
| 634 | .setEmoji(emojiFromBoolean(current.everyone, "id") as APIMessageComponentEmoji), |
| 635 | new ButtonBuilder() |
| 636 | .setCustomId("roles") |
| 637 | .setLabel(current.roles ? "Roles" : "No roles") |
| 638 | .setStyle(current.roles ? ButtonStyle.Success : ButtonStyle.Danger) |
| 639 | .setEmoji(emojiFromBoolean(current.roles, "id") as APIMessageComponentEmoji) |
| 640 | ); |
| 641 | const menu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 642 | new StringSelectMenuBuilder() |
| 643 | .setCustomId("toEdit") |
| 644 | .setPlaceholder("Edit mention settings") |
| 645 | .addOptions( |
| 646 | new StringSelectMenuOptionBuilder() |
| 647 | .setLabel("Mass Mention Amount") |
| 648 | .setDescription("The amount of mentions before the bot will delete the message") |
| 649 | .setValue("mass"), |
| 650 | new StringSelectMenuOptionBuilder() |
| 651 | .setLabel("Roles") |
| 652 | .setDescription("Roles that are able to be mentioned") |
| 653 | .setValue("roles") |
| 654 | ) |
| 655 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 656 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 657 | const allowedMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 658 | new StringSelectMenuBuilder() |
| 659 | .setCustomId("allowed") |
| 660 | .setPlaceholder("Edit exceptions") |
| 661 | .addOptions( |
| 662 | new StringSelectMenuOptionBuilder() |
| 663 | .setLabel("Users") |
| 664 | .setDescription("Users that are unaffected by the mention filter") |
| 665 | .setValue("users"), |
| 666 | new StringSelectMenuOptionBuilder() |
| 667 | .setLabel("Roles") |
| 668 | .setDescription("Roles that are unaffected by the mention filter") |
| 669 | .setValue("roles"), |
| 670 | new StringSelectMenuOptionBuilder() |
| 671 | .setLabel("Channels") |
| 672 | .setDescription("Channels where anyone is unaffected by the mention filter") |
| 673 | .setValue("channels") |
| 674 | ) |
| 675 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 676 | |
| 677 | const embed = new EmojiEmbed() |
| 678 | .setTitle("Mention Settings") |
| 679 | .setDescription( |
| 680 | `Log when members mention:\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 681 | `${emojiFromBoolean(true)} **${current.mass}+ members** in one message\n` + |
| 682 | `${emojiFromBoolean(current.everyone)} **Everyone**\n` + |
| 683 | `${emojiFromBoolean(current.roles)} **Roles**\n` + |
| 684 | (current.allowed.rolesToMention.length > 0 |
| 685 | ? `> *Except for ${listToAndMore( |
| 686 | current.allowed.rolesToMention.map((r) => `<@&${r}>`), |
| 687 | 3 |
| 688 | )}*\n` |
| 689 | : "") + |
| 690 | "\n" + |
| 691 | `Except if...\n` + |
| 692 | `> ${ |
| 693 | current.allowed.users.length > 0 |
| 694 | ? `Member is: ${listToAndMore( |
| 695 | current.allowed.users.map((u) => `<@${u}>`), |
| 696 | 3 |
| 697 | )}\n` |
| 698 | : "" |
| 699 | }` + |
| 700 | `> ${ |
| 701 | current.allowed.roles.length > 0 |
| 702 | ? `Member has role: ${listToAndMore( |
| 703 | current.allowed.roles.map((r) => `<@&${r}>`), |
| 704 | 3 |
| 705 | )}\n` |
| 706 | : "" |
| 707 | }` + |
| 708 | `> ${ |
| 709 | current.allowed.channels.length > 0 |
| 710 | ? `In channel: ${listToAndMore( |
| 711 | current.allowed.channels.map((c) => `<#${c}>`), |
| 712 | 3 |
| 713 | )}\n` |
| 714 | : "" |
| 715 | }` |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 716 | ) |
| 717 | .setStatus("Success") |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 718 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 719 | .setFooter({ |
| 720 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 721 | }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 722 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 723 | await interaction.editReply({ embeds: [embed], components: [menu, allowedMenu, buttons] }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 724 | |
| 725 | let i: ButtonInteraction | StringSelectMenuInteraction; |
| 726 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 727 | i = (await m.awaitMessageComponent({ |
| 728 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 729 | time: 300000 |
| 730 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 731 | } catch (e) { |
| 732 | closed = true; |
| 733 | break; |
| 734 | } |
| 735 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 736 | if (i.isButton()) { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 737 | await i.deferUpdate(); |
| 738 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 739 | case "back": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 740 | closed = true; |
| 741 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 742 | } |
| 743 | case "everyone": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 744 | current.everyone = !current.everyone; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 745 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 746 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 747 | } |
| 748 | case "roles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 749 | current.roles = !current.roles; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 750 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 751 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 752 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 753 | } |
| 754 | } else { |
| 755 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 756 | case "toEdit": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 757 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 758 | case "mass": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 759 | await interaction.editReply({ |
| 760 | embeds: [ |
| 761 | new EmojiEmbed() |
| 762 | .setTitle("Word Filter") |
| 763 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 764 | .setStatus("Success") |
| 765 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 766 | ], |
| 767 | components: [ |
| 768 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 769 | new ButtonBuilder() |
| 770 | .setLabel("Back") |
| 771 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 772 | .setStyle(ButtonStyle.Primary) |
| 773 | .setCustomId("back") |
| 774 | ) |
| 775 | ] |
| 776 | }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 777 | const modal = new ModalBuilder() |
| 778 | .setTitle("Mass Mention Amount") |
| 779 | .setCustomId("mass") |
| 780 | .addComponents( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 781 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 782 | new TextInputBuilder() |
| 783 | .setCustomId("mass") |
| 784 | .setPlaceholder("Amount") |
| 785 | .setMinLength(1) |
| 786 | .setMaxLength(3) |
| 787 | .setStyle(TextInputStyle.Short) |
| 788 | ) |
| 789 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 790 | await i.showModal(modal); |
| 791 | let out; |
| 792 | try { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 793 | out = await modalInteractionCollector(m, interaction.user); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 794 | } catch (e) { |
| 795 | break; |
| 796 | } |
| 797 | if (!out) break; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 798 | if (out.isButton()) break; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 799 | current.mass = parseInt(out.fields.getTextInputValue("mass")); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 800 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 801 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 802 | } |
| 803 | case "roles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 804 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 805 | current.allowed.rolesToMention = await toSelectMenu( |
| 806 | interaction, |
| 807 | m, |
| 808 | current.allowed.rolesToMention, |
| 809 | "role", |
| 810 | "Mention Settings" |
| 811 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 812 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 813 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 814 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 815 | } |
| 816 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 817 | } |
| 818 | case "allowed": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 819 | await i.deferUpdate(); |
| 820 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 821 | case "users": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 822 | current.allowed.users = await toSelectMenu( |
| 823 | interaction, |
| 824 | m, |
| 825 | current.allowed.users, |
| 826 | "member", |
| 827 | "Mention Settings" |
| 828 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 829 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 830 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 831 | } |
| 832 | case "roles": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 833 | current.allowed.roles = await toSelectMenu( |
| 834 | interaction, |
| 835 | m, |
| 836 | current.allowed.roles, |
| 837 | "role", |
| 838 | "Mention Settings" |
| 839 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 840 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 841 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 842 | } |
| 843 | case "channels": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 844 | current.allowed.channels = await toSelectMenu( |
| 845 | interaction, |
| 846 | m, |
| 847 | current.allowed.channels, |
| 848 | "channel", |
| 849 | "Mention Settings" |
| 850 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 851 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 852 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 853 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 854 | } |
| 855 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 856 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 857 | } |
| 858 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 859 | } while (!closed); |
| 860 | return current; |
| 861 | }; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 862 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 863 | const cleanMenu = async ( |
| 864 | interaction: StringSelectMenuInteraction, |
| 865 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 866 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 867 | current?: { |
| 868 | channels?: string[]; |
| 869 | allowed?: { |
| 870 | roles: string[]; |
| 871 | users: string[]; |
| 872 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 873 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 874 | ): Promise<{ |
| 875 | channels: string[]; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 876 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 877 | roles: string[]; |
| 878 | users: string[]; |
| 879 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 880 | }> => { |
| 881 | let closed = false; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 882 | if (!current) current = { channels: [], allowed: { roles: [], users: [] } }; |
| 883 | if (!current.channels) current.channels = []; |
| 884 | if (!current.allowed) current.allowed = { roles: [], users: [] }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 885 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 886 | const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents( |
| 887 | new ChannelSelectMenuBuilder().setCustomId("toAdd").setPlaceholder("Select a channel") |
| 888 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 889 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 890 | const allowedMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 891 | new StringSelectMenuBuilder() |
| 892 | .setCustomId("allowed") |
| 893 | .setPlaceholder("Edit exceptions") |
| 894 | .addOptions( |
| 895 | new StringSelectMenuOptionBuilder() |
| 896 | .setLabel("Users") |
| 897 | .setDescription("Users that are unaffected by the mention filter") |
| 898 | .setValue("users"), |
| 899 | new StringSelectMenuOptionBuilder() |
| 900 | .setLabel("Roles") |
| 901 | .setDescription("Roles that are unaffected by the mention filter") |
| 902 | .setValue("roles") |
| 903 | ) |
| 904 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 905 | |
| 906 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 907 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 908 | new ButtonBuilder() |
| 909 | .setCustomId("back") |
| 910 | .setLabel("Back") |
| 911 | .setStyle(ButtonStyle.Primary) |
| 912 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 913 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 914 | |
| 915 | const embed = new EmojiEmbed() |
| 916 | .setTitle("Clean Settings") |
| 917 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 918 | .setDescription( |
| 919 | `Current clean channels:\n\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 920 | `${ |
| 921 | current.channels.length > 0 |
| 922 | ? listToAndMore( |
| 923 | current.channels.map((c) => `<#${c}>`), |
| 924 | 10 |
| 925 | ) |
| 926 | : "None" |
| 927 | }\n\n` |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 928 | ) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 929 | .setStatus("Success") |
| 930 | .setFooter({ |
| 931 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
| 932 | }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 933 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 934 | await interaction.editReply({ embeds: [embed], components: [channelMenu, allowedMenu, buttons] }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 935 | |
| 936 | let i: ButtonInteraction | ChannelSelectMenuInteraction; |
| 937 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 938 | i = (await m.awaitMessageComponent({ |
| 939 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 940 | time: 300000 |
| 941 | })) as ButtonInteraction | ChannelSelectMenuInteraction; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 942 | } catch (e) { |
| 943 | closed = true; |
| 944 | break; |
| 945 | } |
| 946 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 947 | if (i.isButton()) { |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 948 | switch (i.customId) { |
| 949 | case "back": { |
| 950 | closed = true; |
| 951 | break; |
| 952 | } |
| 953 | } |
| 954 | } else { |
| 955 | switch (i.customId) { |
| 956 | case "toAdd": { |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 957 | const channelEmbed = new EmojiEmbed() |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 958 | .setTitle("Clean Settings") |
| 959 | .setDescription(`Editing <#${i.values[0]}>`) |
| 960 | .setEmoji("GUILD.SETTINGS.GREEN") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 961 | .setStatus("Success"); |
| 962 | const channelButtons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 963 | new ButtonBuilder() |
| 964 | .setCustomId("back") |
| 965 | .setLabel("Back") |
| 966 | .setStyle(ButtonStyle.Primary) |
| 967 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")), |
| 968 | new ButtonBuilder() |
| 969 | .setCustomId("switch") |
| 970 | .setLabel(current.channels.includes(i.values[0]!) ? "Remove" : "Add") |
| 971 | .setStyle( |
| 972 | current.channels.includes(i.values[0]!) ? ButtonStyle.Danger : ButtonStyle.Success |
| 973 | ) |
| 974 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 975 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 976 | await i.editReply({ embeds: [channelEmbed], components: [channelButtons] }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 977 | let j: ButtonInteraction; |
| 978 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 979 | j = (await m.awaitMessageComponent({ |
| 980 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 981 | time: 300000 |
| 982 | })) as ButtonInteraction; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 983 | } catch (e) { |
| 984 | closed = true; |
| 985 | break; |
| 986 | } |
| 987 | await j.deferUpdate(); |
| 988 | switch (j.customId) { |
| 989 | case "back": { |
| 990 | break; |
| 991 | } |
| 992 | case "switch": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 993 | if (current.channels.includes(i.values[0]!)) { |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 994 | current.channels.splice(current.channels.indexOf(i.values[0]!), 1); |
| 995 | } else { |
| 996 | current.channels.push(i.values[0]!); |
| 997 | } |
| 998 | } |
| 999 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1000 | unsavedChanges = true; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1001 | break; |
| 1002 | } |
| 1003 | case "allowed": { |
| 1004 | switch (i.values[0]) { |
| 1005 | case "users": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1006 | current.allowed.users = await toSelectMenu( |
| 1007 | interaction, |
| 1008 | m, |
| 1009 | current.allowed.users, |
| 1010 | "member", |
| 1011 | "Mention Settings" |
| 1012 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1013 | unsavedChanges = true; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1014 | break; |
| 1015 | } |
| 1016 | case "roles": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1017 | current.allowed.roles = await toSelectMenu( |
| 1018 | interaction, |
| 1019 | m, |
| 1020 | current.allowed.roles, |
| 1021 | "role", |
| 1022 | "Mention Settings" |
| 1023 | ); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1024 | unsavedChanges = true; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1025 | break; |
| 1026 | } |
| 1027 | } |
| 1028 | break; |
| 1029 | } |
| 1030 | } |
| 1031 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1032 | } while (!closed); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1033 | |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1034 | return current as { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1035 | channels: string[]; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1036 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1037 | roles: string[]; |
| 1038 | users: string[]; |
| 1039 | }; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1040 | }; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1041 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1042 | |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1043 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
| 1044 | if (!interaction.guild) return; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1045 | const m = await interaction.reply({ embeds: LoadingEmbed, fetchReply: true, ephemeral: true }); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1046 | let config = (await client.database.guilds.read(interaction.guild.id)).filters; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1047 | |
| 1048 | let closed = false; |
| 1049 | |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1050 | let current = _.cloneDeep(config); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1051 | do { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1052 | const button = new ActionRowBuilder<ButtonBuilder>().addComponents( |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 1053 | new ButtonBuilder() |
| 1054 | .setCustomId("save") |
| 1055 | .setLabel("Save") |
| 1056 | .setStyle(ButtonStyle.Success) |
| 1057 | .setDisabled(_.isEqual(config, current)) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1058 | ); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1059 | const selectMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 1060 | new StringSelectMenuBuilder() |
| 1061 | .setCustomId("filter") |
| 1062 | .setPlaceholder("Select a filter to edit") |
| 1063 | .addOptions( |
| 1064 | new StringSelectMenuOptionBuilder() |
| 1065 | .setLabel("Invites") |
| 1066 | .setDescription("Automatically delete messages containing server invites") |
| 1067 | .setValue("invites"), |
| 1068 | new StringSelectMenuOptionBuilder() |
| 1069 | .setLabel("Mentions") |
| 1070 | .setDescription("Deletes messages with excessive mentions") |
| 1071 | .setValue("mentions"), |
| 1072 | new StringSelectMenuOptionBuilder() |
| 1073 | .setLabel("Words") |
| 1074 | .setDescription("Delete messages containing filtered words") |
| 1075 | .setValue("words"), |
| 1076 | new StringSelectMenuOptionBuilder() |
| 1077 | .setLabel("Malware") |
| 1078 | .setDescription("Automatically delete files and links containing malware") |
| 1079 | .setValue("malware"), |
| 1080 | new StringSelectMenuOptionBuilder() |
| 1081 | .setLabel("Images") |
| 1082 | .setDescription("Checks performed on images (NSFW, size checking, etc.)") |
| 1083 | .setValue("images"), |
| 1084 | new StringSelectMenuOptionBuilder() |
| 1085 | .setLabel("Clean") |
| 1086 | .setDescription("Automatically delete new messages in specific channels") |
| 1087 | .setValue("clean") |
| 1088 | ) |
| 1089 | ); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1090 | |
| 1091 | const embed = new EmojiEmbed() |
| 1092 | .setTitle("Automod Settings") |
| 1093 | .setDescription( |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1094 | `${emojiFromBoolean(config.invite.enabled)} **Invites**\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1095 | `${emojiFromBoolean( |
| 1096 | config.pings.everyone || config.pings.mass > 0 || config.pings.roles |
| 1097 | )} **Mentions**\n` + |
| 1098 | `${emojiFromBoolean(config.wordFilter.enabled)} **Words**\n` + |
| 1099 | `${emojiFromBoolean(config.malware)} **Malware**\n` + |
| 1100 | `${emojiFromBoolean(config.images.NSFW || config.images.size)} **Images**\n` + |
| 1101 | `${emojiFromBoolean(config.clean.channels.length > 0)} **Clean**\n` |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1102 | ) |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1103 | .setStatus("Success") |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1104 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 1105 | .setFooter({ |
| 1106 | text: _.isEqual(config, current) ? "No changes made" : "Changes not saved" |
| 1107 | }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1108 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1109 | await interaction.editReply({ embeds: [embed], components: [selectMenu, button] }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1110 | |
| 1111 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 1112 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1113 | i = (await m.awaitMessageComponent({ |
| 1114 | filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id, |
| 1115 | time: 300000 |
| 1116 | })) as StringSelectMenuInteraction | ButtonInteraction; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1117 | } catch (e) { |
| 1118 | closed = true; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1119 | continue; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1120 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1121 | await i.deferUpdate(); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 1122 | if (i.isButton()) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1123 | await client.database.guilds.write(interaction.guild.id, { filters: current }); |
Skyler Grey | 16ecb17 | 2023-03-05 07:30:32 +0000 | [diff] [blame] | 1124 | await client.memory.forceUpdate(interaction.guild.id); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1125 | config = current; |
| 1126 | current = _.cloneDeep(config); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1127 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1128 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1129 | case "invites": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1130 | config.invite = await inviteMenu(i, m, _.isEqual(config, current), config.invite); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1131 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1132 | } |
| 1133 | case "mentions": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1134 | config.pings = await mentionMenu(i, m, _.isEqual(config, current), config.pings); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1135 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1136 | } |
| 1137 | case "words": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1138 | config.wordFilter = await wordMenu(i, m, _.isEqual(config, current), config.wordFilter); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1139 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1140 | } |
| 1141 | case "malware": { |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1142 | config.malware = !config.malware; |
| 1143 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1144 | } |
| 1145 | case "images": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1146 | const next = await imageMenu(i, m, _.isEqual(config, current), config.images); |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1147 | config.images = next; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1148 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1149 | } |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1150 | case "clean": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1151 | const next = await cleanMenu(i, m, _.isEqual(config, current), config.clean); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1152 | config.clean = next; |
| 1153 | break; |
| 1154 | } |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1155 | } |
| 1156 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1157 | } while (!closed); |
| 1158 | await interaction.deleteReply(); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1159 | }; |
| 1160 | |
| 1161 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
| 1162 | const member = interaction.member as Discord.GuildMember; |
| 1163 | if (!member.permissions.has("ManageMessages")) |
| 1164 | return "You must have the *Manage Messages* permission to use this command"; |
| 1165 | return true; |
| 1166 | }; |
| 1167 | |
| 1168 | export { command }; |
| 1169 | export { callback }; |
| 1170 | export { check }; |