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