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