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 | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 413 | current.allowed.users = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 414 | interaction, |
| 415 | m, |
| 416 | current.allowed.users, |
| 417 | "member", |
| 418 | "Word Filter" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 419 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 420 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 421 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 422 | } |
| 423 | case "allowedRoles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 424 | await i.deferUpdate(); |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 425 | current.allowed.roles = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 426 | interaction, |
| 427 | m, |
| 428 | current.allowed.roles, |
| 429 | "role", |
| 430 | "Word Filter" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 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 | } |
| 435 | case "allowedChannels": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 436 | await i.deferUpdate(); |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 437 | current.allowed.channels = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 438 | interaction, |
| 439 | m, |
| 440 | current.allowed.channels, |
| 441 | "channel", |
| 442 | "Word Filter" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 443 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 444 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 445 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 446 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 447 | } |
| 448 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 449 | } while (!closed); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 450 | return current; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 451 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 452 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 453 | const inviteMenu = async ( |
| 454 | interaction: StringSelectMenuInteraction, |
| 455 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 456 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 457 | current: { |
| 458 | enabled: boolean; |
| 459 | allowed: { users: string[]; roles: string[]; channels: string[] }; |
| 460 | } |
| 461 | ): Promise<{ |
| 462 | enabled: boolean; |
| 463 | allowed: { users: string[]; roles: string[]; channels: string[] }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 464 | }> => { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 465 | let closed = false; |
| 466 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 467 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 468 | new ButtonBuilder() |
| 469 | .setCustomId("back") |
| 470 | .setLabel("Back") |
| 471 | .setStyle(ButtonStyle.Secondary) |
| 472 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 473 | new ButtonBuilder() |
| 474 | .setCustomId("enabled") |
| 475 | .setLabel(current.enabled ? "Enabled" : "Disabled") |
| 476 | .setStyle(current.enabled ? ButtonStyle.Success : ButtonStyle.Danger) |
| 477 | .setEmoji(emojiFromBoolean(current.enabled, "id") as APIMessageComponentEmoji) |
| 478 | ); |
| 479 | const menu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 480 | new StringSelectMenuBuilder() |
| 481 | .setCustomId("toEdit") |
| 482 | .setPlaceholder("Edit your allow list") |
| 483 | .addOptions( |
| 484 | new StringSelectMenuOptionBuilder() |
| 485 | .setLabel("Users") |
| 486 | .setDescription("Users that are allowed to send invites") |
| 487 | .setValue("users"), |
| 488 | new StringSelectMenuOptionBuilder() |
| 489 | .setLabel("Roles") |
| 490 | .setDescription("Roles that are allowed to send invites") |
| 491 | .setValue("roles"), |
| 492 | new StringSelectMenuOptionBuilder() |
| 493 | .setLabel("Channels") |
| 494 | .setDescription("Channels that anyone is allowed to send invites in") |
| 495 | .setValue("channels") |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 496 | ) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 497 | .setDisabled(!current.enabled) |
| 498 | ); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 499 | |
| 500 | const embed = new EmojiEmbed() |
| 501 | .setTitle("Invite Settings") |
| 502 | .setDescription( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 503 | "Automatically deletes invites sent by users (outside of staff members and self promotion channels)" + |
| 504 | `\n\n` + |
| 505 | `${emojiFromBoolean(current.enabled)} **${current.enabled ? "Enabled" : "Disabled"}**\n\n` + |
| 506 | `**Users:** ` + |
| 507 | listToAndMore( |
| 508 | current.allowed.users.map((user) => `<@${user}>`), |
| 509 | 5 |
| 510 | ) + |
| 511 | `\n` + |
| 512 | `**Roles:** ` + |
| 513 | listToAndMore( |
| 514 | current.allowed.roles.map((role) => `<@&${role}>`), |
| 515 | 5 |
| 516 | ) + |
| 517 | `\n` + |
| 518 | `**Channels:** ` + |
| 519 | listToAndMore( |
| 520 | current.allowed.channels.map((channel) => `<#${channel}>`), |
| 521 | 5 |
| 522 | ) |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 523 | ) |
| 524 | .setStatus("Success") |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 525 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 526 | .setFooter({ |
| 527 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
| 528 | }); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 529 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 530 | await interaction.editReply({ embeds: [embed], components: [menu, buttons] }); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 531 | |
| 532 | let i: ButtonInteraction | StringSelectMenuInteraction; |
| 533 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 534 | i = (await m.awaitMessageComponent({ |
| 535 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 536 | time: 300000 |
| 537 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 538 | } catch (e) { |
| 539 | return current; |
| 540 | } |
| 541 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 542 | if (i.isButton()) { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 543 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 544 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 545 | case "back": { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 546 | closed = true; |
| 547 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 548 | } |
| 549 | case "enabled": { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 550 | current.enabled = !current.enabled; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 551 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 552 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 553 | } |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 554 | } |
| 555 | } else { |
| 556 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 557 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 558 | case "users": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 559 | current.allowed.users = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 560 | interaction, |
| 561 | m, |
| 562 | current.allowed.users, |
| 563 | "member", |
| 564 | "Invite Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 565 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 566 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 567 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 568 | } |
| 569 | case "roles": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 570 | current.allowed.roles = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 571 | interaction, |
| 572 | m, |
| 573 | current.allowed.roles, |
| 574 | "role", |
| 575 | "Invite Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 576 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 577 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 578 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 579 | } |
| 580 | case "channels": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 581 | current.allowed.channels = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 582 | interaction, |
| 583 | m, |
| 584 | current.allowed.channels, |
| 585 | "channel", |
| 586 | "Invite Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 587 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 588 | unsavedChanges = true; |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 589 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 590 | } |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 591 | } |
| 592 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 593 | } while (!closed); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 594 | return current; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 595 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 596 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 597 | const mentionMenu = async ( |
| 598 | interaction: StringSelectMenuInteraction, |
| 599 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 600 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 601 | current: { |
| 602 | mass: number; |
| 603 | everyone: boolean; |
| 604 | roles: boolean; |
| 605 | allowed: { |
| 606 | roles: string[]; |
| 607 | rolesToMention: string[]; |
| 608 | users: string[]; |
| 609 | channels: string[]; |
| 610 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 611 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 612 | ): Promise<{ |
| 613 | mass: number; |
| 614 | everyone: boolean; |
| 615 | roles: boolean; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 616 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 617 | roles: string[]; |
| 618 | rolesToMention: string[]; |
| 619 | users: string[]; |
| 620 | channels: string[]; |
| 621 | }; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 622 | }> => { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 623 | let closed = false; |
| 624 | |
| 625 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 626 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 627 | new ButtonBuilder() |
| 628 | .setCustomId("back") |
| 629 | .setLabel("Back") |
| 630 | .setStyle(ButtonStyle.Secondary) |
| 631 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji), |
| 632 | new ButtonBuilder() |
| 633 | .setCustomId("everyone") |
| 634 | .setLabel(current.everyone ? "Everyone" : "No one") |
| 635 | .setStyle(current.everyone ? ButtonStyle.Success : ButtonStyle.Danger) |
| 636 | .setEmoji(emojiFromBoolean(current.everyone, "id") as APIMessageComponentEmoji), |
| 637 | new ButtonBuilder() |
| 638 | .setCustomId("roles") |
| 639 | .setLabel(current.roles ? "Roles" : "No roles") |
| 640 | .setStyle(current.roles ? ButtonStyle.Success : ButtonStyle.Danger) |
| 641 | .setEmoji(emojiFromBoolean(current.roles, "id") as APIMessageComponentEmoji) |
| 642 | ); |
| 643 | const menu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 644 | new StringSelectMenuBuilder() |
| 645 | .setCustomId("toEdit") |
| 646 | .setPlaceholder("Edit mention settings") |
| 647 | .addOptions( |
| 648 | new StringSelectMenuOptionBuilder() |
| 649 | .setLabel("Mass Mention Amount") |
| 650 | .setDescription("The amount of mentions before the bot will delete the message") |
| 651 | .setValue("mass"), |
| 652 | new StringSelectMenuOptionBuilder() |
| 653 | .setLabel("Roles") |
| 654 | .setDescription("Roles that are able to be mentioned") |
| 655 | .setValue("roles") |
| 656 | ) |
| 657 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 658 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 659 | const allowedMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 660 | new StringSelectMenuBuilder() |
| 661 | .setCustomId("allowed") |
pineafan | 9ca34cd | 2023-03-21 18:45:58 +0000 | [diff] [blame] | 662 | .setPlaceholder("Edit allowed list") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 663 | .addOptions( |
| 664 | new StringSelectMenuOptionBuilder() |
| 665 | .setLabel("Users") |
| 666 | .setDescription("Users that are unaffected by the mention filter") |
| 667 | .setValue("users"), |
| 668 | new StringSelectMenuOptionBuilder() |
| 669 | .setLabel("Roles") |
| 670 | .setDescription("Roles that are unaffected by the mention filter") |
| 671 | .setValue("roles"), |
| 672 | new StringSelectMenuOptionBuilder() |
| 673 | .setLabel("Channels") |
| 674 | .setDescription("Channels where anyone is unaffected by the mention filter") |
| 675 | .setValue("channels") |
| 676 | ) |
| 677 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 678 | |
| 679 | const embed = new EmojiEmbed() |
| 680 | .setTitle("Mention Settings") |
| 681 | .setDescription( |
| 682 | `Log when members mention:\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 683 | `${emojiFromBoolean(true)} **${current.mass}+ members** in one message\n` + |
| 684 | `${emojiFromBoolean(current.everyone)} **Everyone**\n` + |
| 685 | `${emojiFromBoolean(current.roles)} **Roles**\n` + |
| 686 | (current.allowed.rolesToMention.length > 0 |
| 687 | ? `> *Except for ${listToAndMore( |
pineafan | 7c2aedd | 2023-03-27 16:54:52 +0100 | [diff] [blame] | 688 | current.allowed.rolesToMention.map((r) => `<@&${r}>`), |
| 689 | 3 |
| 690 | )}*\n` |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 691 | : "") + |
| 692 | "\n" + |
| 693 | `Except if...\n` + |
pineafan | 9ca34cd | 2023-03-21 18:45:58 +0000 | [diff] [blame] | 694 | (current.allowed.users.length > 0 |
| 695 | ? `> Member is: ${listToAndMore( |
pineafan | 7c2aedd | 2023-03-27 16:54:52 +0100 | [diff] [blame] | 696 | current.allowed.users.map((u) => `<@${u}>`), |
| 697 | 3 |
| 698 | )}\n` |
pineafan | 9ca34cd | 2023-03-21 18:45:58 +0000 | [diff] [blame] | 699 | : "") + |
| 700 | (current.allowed.roles.length > 0 |
| 701 | ? `> Member has role: ${listToAndMore( |
pineafan | 7c2aedd | 2023-03-27 16:54:52 +0100 | [diff] [blame] | 702 | current.allowed.roles.map((r) => `<@&${r}>`), |
| 703 | 3 |
| 704 | )}\n` |
pineafan | 9ca34cd | 2023-03-21 18:45:58 +0000 | [diff] [blame] | 705 | : "") + |
| 706 | (current.allowed.channels.length > 0 |
| 707 | ? `> In channel: ${listToAndMore( |
pineafan | 7c2aedd | 2023-03-27 16:54:52 +0100 | [diff] [blame] | 708 | current.allowed.channels.map((c) => `<#${c}>`), |
| 709 | 3 |
| 710 | )}\n` |
pineafan | 9ca34cd | 2023-03-21 18:45:58 +0000 | [diff] [blame] | 711 | : "") + |
pineafan | 7c2aedd | 2023-03-27 16:54:52 +0100 | [diff] [blame] | 712 | (current.allowed.users.length == 0 || |
| 713 | current.allowed.roles.length == 0 || |
| 714 | current.allowed.channels.length == 0 |
PineappleFan | 0786898 | 2023-03-30 17:36:47 +0100 | [diff] [blame] | 715 | ? "> *Nobody on allowed lists*\n" |
pineafan | 7c2aedd | 2023-03-27 16:54:52 +0100 | [diff] [blame] | 716 | : "") |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 717 | ) |
| 718 | .setStatus("Success") |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 719 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 720 | .setFooter({ |
| 721 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 722 | }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 723 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 724 | await interaction.editReply({ embeds: [embed], components: [menu, allowedMenu, buttons] }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 725 | |
| 726 | let i: ButtonInteraction | StringSelectMenuInteraction; |
| 727 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 728 | i = (await m.awaitMessageComponent({ |
| 729 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 730 | time: 300000 |
| 731 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 732 | } catch (e) { |
| 733 | closed = true; |
| 734 | break; |
| 735 | } |
| 736 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 737 | if (i.isButton()) { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 738 | await i.deferUpdate(); |
| 739 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 740 | case "back": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 741 | closed = true; |
| 742 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 743 | } |
| 744 | case "everyone": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 745 | current.everyone = !current.everyone; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 746 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 747 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 748 | } |
| 749 | case "roles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 750 | current.roles = !current.roles; |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 751 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 752 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 753 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 754 | } |
| 755 | } else { |
| 756 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 757 | case "toEdit": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 758 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 759 | case "mass": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 760 | await interaction.editReply({ |
| 761 | embeds: [ |
| 762 | new EmojiEmbed() |
| 763 | .setTitle("Word Filter") |
| 764 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 765 | .setStatus("Success") |
| 766 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 767 | ], |
| 768 | components: [ |
| 769 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 770 | new ButtonBuilder() |
| 771 | .setLabel("Back") |
| 772 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 773 | .setStyle(ButtonStyle.Primary) |
| 774 | .setCustomId("back") |
| 775 | ) |
| 776 | ] |
| 777 | }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 778 | const modal = new ModalBuilder() |
| 779 | .setTitle("Mass Mention Amount") |
| 780 | .setCustomId("mass") |
| 781 | .addComponents( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 782 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 783 | new TextInputBuilder() |
| 784 | .setCustomId("mass") |
| 785 | .setPlaceholder("Amount") |
| 786 | .setMinLength(1) |
| 787 | .setMaxLength(3) |
| 788 | .setStyle(TextInputStyle.Short) |
| 789 | ) |
| 790 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 791 | await i.showModal(modal); |
| 792 | let out; |
| 793 | try { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 794 | out = await modalInteractionCollector(m, interaction.user); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 795 | } catch (e) { |
| 796 | break; |
| 797 | } |
| 798 | if (!out) break; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 799 | if (out.isButton()) break; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 800 | current.mass = parseInt(out.fields.getTextInputValue("mass")); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 801 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 802 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 803 | } |
| 804 | case "roles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 805 | await i.deferUpdate(); |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 806 | current.allowed.rolesToMention = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 807 | interaction, |
| 808 | m, |
| 809 | current.allowed.rolesToMention, |
| 810 | "role", |
| 811 | "Mention Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 812 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 813 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 814 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 815 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 816 | } |
| 817 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 818 | } |
| 819 | case "allowed": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 820 | await i.deferUpdate(); |
| 821 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 822 | case "users": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 823 | current.allowed.users = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 824 | interaction, |
| 825 | m, |
| 826 | current.allowed.users, |
| 827 | "member", |
| 828 | "Mention Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 829 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 830 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 831 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 832 | } |
| 833 | case "roles": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 834 | current.allowed.roles = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 835 | interaction, |
| 836 | m, |
| 837 | current.allowed.roles, |
| 838 | "role", |
| 839 | "Mention Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 840 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 841 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 842 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 843 | } |
| 844 | case "channels": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 845 | current.allowed.channels = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 846 | interaction, |
| 847 | m, |
| 848 | current.allowed.channels, |
| 849 | "channel", |
| 850 | "Mention Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 851 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 852 | unsavedChanges = true; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 853 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 854 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 855 | } |
| 856 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 857 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 858 | } |
| 859 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 860 | } while (!closed); |
| 861 | return current; |
| 862 | }; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 863 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 864 | const cleanMenu = async ( |
| 865 | interaction: StringSelectMenuInteraction, |
| 866 | m: Message, |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 867 | unsavedChanges: boolean, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 868 | current?: { |
| 869 | channels?: string[]; |
| 870 | allowed?: { |
| 871 | roles: string[]; |
| 872 | users: string[]; |
| 873 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 874 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 875 | ): Promise<{ |
| 876 | channels: string[]; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 877 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 878 | roles: string[]; |
| 879 | users: string[]; |
| 880 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 881 | }> => { |
| 882 | let closed = false; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 883 | if (!current) current = { channels: [], allowed: { roles: [], users: [] } }; |
| 884 | if (!current.channels) current.channels = []; |
| 885 | if (!current.allowed) current.allowed = { roles: [], users: [] }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 886 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 887 | const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents( |
| 888 | new ChannelSelectMenuBuilder().setCustomId("toAdd").setPlaceholder("Select a channel") |
| 889 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 890 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 891 | const allowedMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 892 | new StringSelectMenuBuilder() |
| 893 | .setCustomId("allowed") |
| 894 | .setPlaceholder("Edit exceptions") |
| 895 | .addOptions( |
| 896 | new StringSelectMenuOptionBuilder() |
| 897 | .setLabel("Users") |
| 898 | .setDescription("Users that are unaffected by the mention filter") |
| 899 | .setValue("users"), |
| 900 | new StringSelectMenuOptionBuilder() |
| 901 | .setLabel("Roles") |
| 902 | .setDescription("Roles that are unaffected by the mention filter") |
| 903 | .setValue("roles") |
| 904 | ) |
| 905 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 906 | |
| 907 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 908 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 909 | new ButtonBuilder() |
| 910 | .setCustomId("back") |
| 911 | .setLabel("Back") |
| 912 | .setStyle(ButtonStyle.Primary) |
| 913 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 914 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 915 | |
| 916 | const embed = new EmojiEmbed() |
| 917 | .setTitle("Clean Settings") |
| 918 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 919 | .setDescription( |
| 920 | `Current clean channels:\n\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 921 | `${ |
| 922 | current.channels.length > 0 |
| 923 | ? listToAndMore( |
| 924 | current.channels.map((c) => `<#${c}>`), |
| 925 | 10 |
| 926 | ) |
| 927 | : "None" |
| 928 | }\n\n` |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 929 | ) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 930 | .setStatus("Success") |
| 931 | .setFooter({ |
| 932 | text: unsavedChanges ? "No changes made" : "Changes not saved" |
| 933 | }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 934 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 935 | await interaction.editReply({ embeds: [embed], components: [channelMenu, allowedMenu, buttons] }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 936 | |
| 937 | let i: ButtonInteraction | ChannelSelectMenuInteraction; |
| 938 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 939 | i = (await m.awaitMessageComponent({ |
| 940 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 941 | time: 300000 |
| 942 | })) as ButtonInteraction | ChannelSelectMenuInteraction; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 943 | } catch (e) { |
| 944 | closed = true; |
| 945 | break; |
| 946 | } |
| 947 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 948 | if (i.isButton()) { |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 949 | switch (i.customId) { |
| 950 | case "back": { |
| 951 | closed = true; |
| 952 | break; |
| 953 | } |
| 954 | } |
| 955 | } else { |
| 956 | switch (i.customId) { |
| 957 | case "toAdd": { |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 958 | const channelEmbed = new EmojiEmbed() |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 959 | .setTitle("Clean Settings") |
| 960 | .setDescription(`Editing <#${i.values[0]}>`) |
| 961 | .setEmoji("GUILD.SETTINGS.GREEN") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 962 | .setStatus("Success"); |
| 963 | const channelButtons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 964 | new ButtonBuilder() |
| 965 | .setCustomId("back") |
| 966 | .setLabel("Back") |
| 967 | .setStyle(ButtonStyle.Primary) |
| 968 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")), |
| 969 | new ButtonBuilder() |
| 970 | .setCustomId("switch") |
| 971 | .setLabel(current.channels.includes(i.values[0]!) ? "Remove" : "Add") |
| 972 | .setStyle( |
| 973 | current.channels.includes(i.values[0]!) ? ButtonStyle.Danger : ButtonStyle.Success |
| 974 | ) |
| 975 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 976 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 977 | await i.editReply({ embeds: [channelEmbed], components: [channelButtons] }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 978 | let j: ButtonInteraction; |
| 979 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 980 | j = (await m.awaitMessageComponent({ |
| 981 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 982 | time: 300000 |
| 983 | })) as ButtonInteraction; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 984 | } catch (e) { |
| 985 | closed = true; |
| 986 | break; |
| 987 | } |
| 988 | await j.deferUpdate(); |
| 989 | switch (j.customId) { |
| 990 | case "back": { |
| 991 | break; |
| 992 | } |
| 993 | case "switch": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 994 | if (current.channels.includes(i.values[0]!)) { |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 995 | current.channels.splice(current.channels.indexOf(i.values[0]!), 1); |
| 996 | } else { |
| 997 | current.channels.push(i.values[0]!); |
| 998 | } |
| 999 | } |
| 1000 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1001 | unsavedChanges = true; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1002 | break; |
| 1003 | } |
| 1004 | case "allowed": { |
| 1005 | switch (i.values[0]) { |
| 1006 | case "users": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 1007 | current.allowed.users = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1008 | interaction, |
| 1009 | m, |
| 1010 | current.allowed.users, |
| 1011 | "member", |
| 1012 | "Mention Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 1013 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1014 | unsavedChanges = true; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1015 | break; |
| 1016 | } |
| 1017 | case "roles": { |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 1018 | current.allowed.roles = _.cloneDeep(await toSelectMenu( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1019 | interaction, |
| 1020 | m, |
| 1021 | current.allowed.roles, |
| 1022 | "role", |
| 1023 | "Mention Settings" |
TheCodedProf | 4f9e97f | 2023-04-07 14:15:58 -0400 | [diff] [blame] | 1024 | )); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1025 | unsavedChanges = true; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1026 | break; |
| 1027 | } |
| 1028 | } |
| 1029 | break; |
| 1030 | } |
| 1031 | } |
| 1032 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1033 | } while (!closed); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1034 | |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1035 | return current as { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1036 | channels: string[]; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1037 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1038 | roles: string[]; |
| 1039 | users: string[]; |
| 1040 | }; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1041 | }; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1042 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1043 | |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1044 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
| 1045 | if (!interaction.guild) return; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1046 | const m = await interaction.reply({ embeds: LoadingEmbed, fetchReply: true, ephemeral: true }); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1047 | let config = (await client.database.guilds.read(interaction.guild.id)).filters; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1048 | |
| 1049 | let closed = false; |
| 1050 | |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1051 | let current = _.cloneDeep(config); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1052 | do { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1053 | const button = new ActionRowBuilder<ButtonBuilder>().addComponents( |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 1054 | new ButtonBuilder() |
| 1055 | .setCustomId("save") |
| 1056 | .setLabel("Save") |
| 1057 | .setStyle(ButtonStyle.Success) |
| 1058 | .setDisabled(_.isEqual(config, current)) |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1059 | ); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1060 | const selectMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 1061 | new StringSelectMenuBuilder() |
| 1062 | .setCustomId("filter") |
| 1063 | .setPlaceholder("Select a filter to edit") |
| 1064 | .addOptions( |
| 1065 | new StringSelectMenuOptionBuilder() |
| 1066 | .setLabel("Invites") |
| 1067 | .setDescription("Automatically delete messages containing server invites") |
| 1068 | .setValue("invites"), |
| 1069 | new StringSelectMenuOptionBuilder() |
| 1070 | .setLabel("Mentions") |
| 1071 | .setDescription("Deletes messages with excessive mentions") |
| 1072 | .setValue("mentions"), |
| 1073 | new StringSelectMenuOptionBuilder() |
| 1074 | .setLabel("Words") |
| 1075 | .setDescription("Delete messages containing filtered words") |
| 1076 | .setValue("words"), |
| 1077 | new StringSelectMenuOptionBuilder() |
| 1078 | .setLabel("Malware") |
| 1079 | .setDescription("Automatically delete files and links containing malware") |
| 1080 | .setValue("malware"), |
| 1081 | new StringSelectMenuOptionBuilder() |
| 1082 | .setLabel("Images") |
| 1083 | .setDescription("Checks performed on images (NSFW, size checking, etc.)") |
| 1084 | .setValue("images"), |
| 1085 | new StringSelectMenuOptionBuilder() |
| 1086 | .setLabel("Clean") |
| 1087 | .setDescription("Automatically delete new messages in specific channels") |
| 1088 | .setValue("clean") |
| 1089 | ) |
| 1090 | ); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1091 | |
| 1092 | const embed = new EmojiEmbed() |
| 1093 | .setTitle("Automod Settings") |
| 1094 | .setDescription( |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1095 | `${emojiFromBoolean(config.invite.enabled)} **Invites**\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1096 | `${emojiFromBoolean( |
| 1097 | config.pings.everyone || config.pings.mass > 0 || config.pings.roles |
| 1098 | )} **Mentions**\n` + |
| 1099 | `${emojiFromBoolean(config.wordFilter.enabled)} **Words**\n` + |
| 1100 | `${emojiFromBoolean(config.malware)} **Malware**\n` + |
| 1101 | `${emojiFromBoolean(config.images.NSFW || config.images.size)} **Images**\n` + |
| 1102 | `${emojiFromBoolean(config.clean.channels.length > 0)} **Clean**\n` |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1103 | ) |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1104 | .setStatus("Success") |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1105 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 1106 | .setFooter({ |
| 1107 | text: _.isEqual(config, current) ? "No changes made" : "Changes not saved" |
| 1108 | }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1109 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1110 | await interaction.editReply({ embeds: [embed], components: [selectMenu, button] }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1111 | |
| 1112 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 1113 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1114 | i = (await m.awaitMessageComponent({ |
| 1115 | filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id, |
| 1116 | time: 300000 |
| 1117 | })) as StringSelectMenuInteraction | ButtonInteraction; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1118 | } catch (e) { |
| 1119 | closed = true; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1120 | continue; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1121 | } |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1122 | await i.deferUpdate(); |
TheCodedProf | ca29ebb | 2023-03-10 17:40:09 -0500 | [diff] [blame] | 1123 | if (i.isButton()) { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1124 | await client.database.guilds.write(interaction.guild.id, { filters: current }); |
Skyler Grey | 16ecb17 | 2023-03-05 07:30:32 +0000 | [diff] [blame] | 1125 | await client.memory.forceUpdate(interaction.guild.id); |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1126 | config = current; |
| 1127 | current = _.cloneDeep(config); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1128 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1129 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1130 | case "invites": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1131 | config.invite = await inviteMenu(i, m, _.isEqual(config, current), config.invite); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1132 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1133 | } |
| 1134 | case "mentions": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1135 | config.pings = await mentionMenu(i, m, _.isEqual(config, current), config.pings); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1136 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1137 | } |
| 1138 | case "words": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1139 | config.wordFilter = await wordMenu(i, m, _.isEqual(config, current), config.wordFilter); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1140 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1141 | } |
| 1142 | case "malware": { |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1143 | config.malware = !config.malware; |
| 1144 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1145 | } |
| 1146 | case "images": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1147 | const next = await imageMenu(i, m, _.isEqual(config, current), config.images); |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1148 | config.images = next; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1149 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1150 | } |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1151 | case "clean": { |
TheCodedProf | 35e7371 | 2023-03-10 17:35:35 -0500 | [diff] [blame] | 1152 | const next = await cleanMenu(i, m, _.isEqual(config, current), config.clean); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1153 | config.clean = next; |
| 1154 | break; |
| 1155 | } |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1156 | } |
| 1157 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1158 | } while (!closed); |
| 1159 | await interaction.deleteReply(); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1160 | }; |
| 1161 | |
| 1162 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
| 1163 | const member = interaction.member as Discord.GuildMember; |
| 1164 | if (!member.permissions.has("ManageMessages")) |
| 1165 | return "You must have the *Manage Messages* permission to use this command"; |
| 1166 | return true; |
| 1167 | }; |
| 1168 | |
| 1169 | export { command }; |
| 1170 | export { callback }; |
| 1171 | export { check }; |