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") |
| 637 | .setPlaceholder("Edit exceptions") |
| 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( |
| 663 | current.allowed.rolesToMention.map((r) => `<@&${r}>`), |
| 664 | 3 |
| 665 | )}*\n` |
| 666 | : "") + |
| 667 | "\n" + |
| 668 | `Except if...\n` + |
| 669 | `> ${ |
| 670 | current.allowed.users.length > 0 |
| 671 | ? `Member is: ${listToAndMore( |
| 672 | current.allowed.users.map((u) => `<@${u}>`), |
| 673 | 3 |
| 674 | )}\n` |
| 675 | : "" |
| 676 | }` + |
| 677 | `> ${ |
| 678 | current.allowed.roles.length > 0 |
| 679 | ? `Member has role: ${listToAndMore( |
| 680 | current.allowed.roles.map((r) => `<@&${r}>`), |
| 681 | 3 |
| 682 | )}\n` |
| 683 | : "" |
| 684 | }` + |
| 685 | `> ${ |
| 686 | current.allowed.channels.length > 0 |
| 687 | ? `In channel: ${listToAndMore( |
| 688 | current.allowed.channels.map((c) => `<#${c}>`), |
| 689 | 3 |
| 690 | )}\n` |
| 691 | : "" |
| 692 | }` |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 693 | ) |
| 694 | .setStatus("Success") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 695 | .setEmoji("GUILD.SETTINGS.GREEN"); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 696 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 697 | await interaction.editReply({ embeds: [embed], components: [menu, allowedMenu, buttons] }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 698 | |
| 699 | let i: ButtonInteraction | StringSelectMenuInteraction; |
| 700 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 701 | i = (await m.awaitMessageComponent({ |
| 702 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 703 | time: 300000 |
| 704 | })) as ButtonInteraction | StringSelectMenuInteraction; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 705 | } catch (e) { |
| 706 | closed = true; |
| 707 | break; |
| 708 | } |
| 709 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 710 | if (i.isButton()) { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 711 | await i.deferUpdate(); |
| 712 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 713 | case "back": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 714 | closed = true; |
| 715 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 716 | } |
| 717 | case "everyone": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 718 | current.everyone = !current.everyone; |
| 719 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 720 | } |
| 721 | case "roles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 722 | current.roles = !current.roles; |
| 723 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 724 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 725 | } |
| 726 | } else { |
| 727 | switch (i.customId) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 728 | case "toEdit": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 729 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 730 | case "mass": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 731 | await interaction.editReply({ |
| 732 | embeds: [ |
| 733 | new EmojiEmbed() |
| 734 | .setTitle("Word Filter") |
| 735 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
| 736 | .setStatus("Success") |
| 737 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 738 | ], |
| 739 | components: [ |
| 740 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 741 | new ButtonBuilder() |
| 742 | .setLabel("Back") |
| 743 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 744 | .setStyle(ButtonStyle.Primary) |
| 745 | .setCustomId("back") |
| 746 | ) |
| 747 | ] |
| 748 | }); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 749 | const modal = new ModalBuilder() |
| 750 | .setTitle("Mass Mention Amount") |
| 751 | .setCustomId("mass") |
| 752 | .addComponents( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 753 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 754 | new TextInputBuilder() |
| 755 | .setCustomId("mass") |
| 756 | .setPlaceholder("Amount") |
| 757 | .setMinLength(1) |
| 758 | .setMaxLength(3) |
| 759 | .setStyle(TextInputStyle.Short) |
| 760 | ) |
| 761 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 762 | await i.showModal(modal); |
| 763 | let out; |
| 764 | try { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 765 | out = await modalInteractionCollector(m, interaction.user); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 766 | } catch (e) { |
| 767 | break; |
| 768 | } |
| 769 | if (!out) break; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 770 | if (out.isButton()) break; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 771 | current.mass = parseInt(out.fields.getTextInputValue("mass")); |
| 772 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 773 | } |
| 774 | case "roles": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 775 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 776 | current.allowed.rolesToMention = await toSelectMenu( |
| 777 | interaction, |
| 778 | m, |
| 779 | current.allowed.rolesToMention, |
| 780 | "role", |
| 781 | "Mention Settings" |
| 782 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 783 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 784 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 785 | } |
| 786 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 787 | } |
| 788 | case "allowed": { |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 789 | await i.deferUpdate(); |
| 790 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 791 | case "users": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 792 | current.allowed.users = await toSelectMenu( |
| 793 | interaction, |
| 794 | m, |
| 795 | current.allowed.users, |
| 796 | "member", |
| 797 | "Mention Settings" |
| 798 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 799 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 800 | } |
| 801 | case "roles": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 802 | current.allowed.roles = await toSelectMenu( |
| 803 | interaction, |
| 804 | m, |
| 805 | current.allowed.roles, |
| 806 | "role", |
| 807 | "Mention Settings" |
| 808 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 809 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 810 | } |
| 811 | case "channels": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 812 | current.allowed.channels = await toSelectMenu( |
| 813 | interaction, |
| 814 | m, |
| 815 | current.allowed.channels, |
| 816 | "channel", |
| 817 | "Mention Settings" |
| 818 | ); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 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 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 823 | } |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 824 | } |
| 825 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 826 | } while (!closed); |
| 827 | return current; |
| 828 | }; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 829 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 830 | const cleanMenu = async ( |
| 831 | interaction: StringSelectMenuInteraction, |
| 832 | m: Message, |
| 833 | current?: { |
| 834 | channels?: string[]; |
| 835 | allowed?: { |
| 836 | roles: string[]; |
| 837 | users: string[]; |
| 838 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 839 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 840 | ): Promise<{ |
| 841 | channels: string[]; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 842 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 843 | roles: string[]; |
| 844 | users: string[]; |
| 845 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 846 | }> => { |
| 847 | let closed = false; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 848 | if (!current) current = { channels: [], allowed: { roles: [], users: [] } }; |
| 849 | if (!current.channels) current.channels = []; |
| 850 | if (!current.allowed) current.allowed = { roles: [], users: [] }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 851 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 852 | const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents( |
| 853 | new ChannelSelectMenuBuilder().setCustomId("toAdd").setPlaceholder("Select a channel") |
| 854 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 855 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 856 | const allowedMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 857 | new StringSelectMenuBuilder() |
| 858 | .setCustomId("allowed") |
| 859 | .setPlaceholder("Edit exceptions") |
| 860 | .addOptions( |
| 861 | new StringSelectMenuOptionBuilder() |
| 862 | .setLabel("Users") |
| 863 | .setDescription("Users that are unaffected by the mention filter") |
| 864 | .setValue("users"), |
| 865 | new StringSelectMenuOptionBuilder() |
| 866 | .setLabel("Roles") |
| 867 | .setDescription("Roles that are unaffected by the mention filter") |
| 868 | .setValue("roles") |
| 869 | ) |
| 870 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 871 | |
| 872 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 873 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 874 | new ButtonBuilder() |
| 875 | .setCustomId("back") |
| 876 | .setLabel("Back") |
| 877 | .setStyle(ButtonStyle.Primary) |
| 878 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 879 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 880 | |
| 881 | const embed = new EmojiEmbed() |
| 882 | .setTitle("Clean Settings") |
| 883 | .setEmoji("GUILD.SETTINGS.GREEN") |
| 884 | .setDescription( |
| 885 | `Current clean channels:\n\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 886 | `${ |
| 887 | current.channels.length > 0 |
| 888 | ? listToAndMore( |
| 889 | current.channels.map((c) => `<#${c}>`), |
| 890 | 10 |
| 891 | ) |
| 892 | : "None" |
| 893 | }\n\n` |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 894 | ) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 895 | .setStatus("Success"); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 896 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 897 | await interaction.editReply({ embeds: [embed], components: [channelMenu, allowedMenu, buttons] }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 898 | |
| 899 | let i: ButtonInteraction | ChannelSelectMenuInteraction; |
| 900 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 901 | i = (await m.awaitMessageComponent({ |
| 902 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 903 | time: 300000 |
| 904 | })) as ButtonInteraction | ChannelSelectMenuInteraction; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 905 | } catch (e) { |
| 906 | closed = true; |
| 907 | break; |
| 908 | } |
| 909 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 910 | if (i.isButton()) { |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 911 | switch (i.customId) { |
| 912 | case "back": { |
| 913 | closed = true; |
| 914 | break; |
| 915 | } |
| 916 | } |
| 917 | } else { |
| 918 | switch (i.customId) { |
| 919 | case "toAdd": { |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 920 | const channelEmbed = new EmojiEmbed() |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 921 | .setTitle("Clean Settings") |
| 922 | .setDescription(`Editing <#${i.values[0]}>`) |
| 923 | .setEmoji("GUILD.SETTINGS.GREEN") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 924 | .setStatus("Success"); |
| 925 | const channelButtons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 926 | new ButtonBuilder() |
| 927 | .setCustomId("back") |
| 928 | .setLabel("Back") |
| 929 | .setStyle(ButtonStyle.Primary) |
| 930 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")), |
| 931 | new ButtonBuilder() |
| 932 | .setCustomId("switch") |
| 933 | .setLabel(current.channels.includes(i.values[0]!) ? "Remove" : "Add") |
| 934 | .setStyle( |
| 935 | current.channels.includes(i.values[0]!) ? ButtonStyle.Danger : ButtonStyle.Success |
| 936 | ) |
| 937 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 938 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 939 | await i.editReply({ embeds: [channelEmbed], components: [channelButtons] }); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 940 | let j: ButtonInteraction; |
| 941 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 942 | j = (await m.awaitMessageComponent({ |
| 943 | filter: (i) => interaction.user.id === i.user.id && i.message.id === m.id, |
| 944 | time: 300000 |
| 945 | })) as ButtonInteraction; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 946 | } catch (e) { |
| 947 | closed = true; |
| 948 | break; |
| 949 | } |
| 950 | await j.deferUpdate(); |
| 951 | switch (j.customId) { |
| 952 | case "back": { |
| 953 | break; |
| 954 | } |
| 955 | case "switch": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 956 | if (current.channels.includes(i.values[0]!)) { |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 957 | current.channels.splice(current.channels.indexOf(i.values[0]!), 1); |
| 958 | } else { |
| 959 | current.channels.push(i.values[0]!); |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | break; |
| 964 | } |
| 965 | case "allowed": { |
| 966 | switch (i.values[0]) { |
| 967 | case "users": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 968 | current.allowed.users = await toSelectMenu( |
| 969 | interaction, |
| 970 | m, |
| 971 | current.allowed.users, |
| 972 | "member", |
| 973 | "Mention Settings" |
| 974 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 975 | break; |
| 976 | } |
| 977 | case "roles": { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 978 | current.allowed.roles = await toSelectMenu( |
| 979 | interaction, |
| 980 | m, |
| 981 | current.allowed.roles, |
| 982 | "role", |
| 983 | "Mention Settings" |
| 984 | ); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 985 | break; |
| 986 | } |
| 987 | } |
| 988 | break; |
| 989 | } |
| 990 | } |
| 991 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 992 | } while (!closed); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 993 | |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 994 | return current as { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 995 | channels: string[]; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 996 | allowed: { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 997 | roles: string[]; |
| 998 | users: string[]; |
| 999 | }; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 1000 | }; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1001 | }; |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1002 | |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1003 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
| 1004 | if (!interaction.guild) return; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1005 | const m = await interaction.reply({ embeds: LoadingEmbed, fetchReply: true, ephemeral: true }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1006 | const config = (await client.database.guilds.read(interaction.guild.id)).filters; |
| 1007 | |
| 1008 | let closed = false; |
| 1009 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1010 | const button = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 1011 | new ButtonBuilder().setCustomId("save").setLabel("Save").setStyle(ButtonStyle.Success) |
| 1012 | ); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1013 | |
| 1014 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1015 | const selectMenu = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents( |
| 1016 | new StringSelectMenuBuilder() |
| 1017 | .setCustomId("filter") |
| 1018 | .setPlaceholder("Select a filter to edit") |
| 1019 | .addOptions( |
| 1020 | new StringSelectMenuOptionBuilder() |
| 1021 | .setLabel("Invites") |
| 1022 | .setDescription("Automatically delete messages containing server invites") |
| 1023 | .setValue("invites"), |
| 1024 | new StringSelectMenuOptionBuilder() |
| 1025 | .setLabel("Mentions") |
| 1026 | .setDescription("Deletes messages with excessive mentions") |
| 1027 | .setValue("mentions"), |
| 1028 | new StringSelectMenuOptionBuilder() |
| 1029 | .setLabel("Words") |
| 1030 | .setDescription("Delete messages containing filtered words") |
| 1031 | .setValue("words"), |
| 1032 | new StringSelectMenuOptionBuilder() |
| 1033 | .setLabel("Malware") |
| 1034 | .setDescription("Automatically delete files and links containing malware") |
| 1035 | .setValue("malware"), |
| 1036 | new StringSelectMenuOptionBuilder() |
| 1037 | .setLabel("Images") |
| 1038 | .setDescription("Checks performed on images (NSFW, size checking, etc.)") |
| 1039 | .setValue("images"), |
| 1040 | new StringSelectMenuOptionBuilder() |
| 1041 | .setLabel("Clean") |
| 1042 | .setDescription("Automatically delete new messages in specific channels") |
| 1043 | .setValue("clean") |
| 1044 | ) |
| 1045 | ); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1046 | |
| 1047 | const embed = new EmojiEmbed() |
| 1048 | .setTitle("Automod Settings") |
| 1049 | .setDescription( |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1050 | `${emojiFromBoolean(config.invite.enabled)} **Invites**\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1051 | `${emojiFromBoolean( |
| 1052 | config.pings.everyone || config.pings.mass > 0 || config.pings.roles |
| 1053 | )} **Mentions**\n` + |
| 1054 | `${emojiFromBoolean(config.wordFilter.enabled)} **Words**\n` + |
| 1055 | `${emojiFromBoolean(config.malware)} **Malware**\n` + |
| 1056 | `${emojiFromBoolean(config.images.NSFW || config.images.size)} **Images**\n` + |
| 1057 | `${emojiFromBoolean(config.clean.channels.length > 0)} **Clean**\n` |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1058 | ) |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1059 | .setStatus("Success") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1060 | .setEmoji("GUILD.SETTINGS.GREEN"); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1061 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1062 | await interaction.editReply({ embeds: [embed], components: [selectMenu, button] }); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1063 | |
| 1064 | let i: StringSelectMenuInteraction | ButtonInteraction; |
| 1065 | try { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1066 | i = (await m.awaitMessageComponent({ |
| 1067 | filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id, |
| 1068 | time: 300000 |
| 1069 | })) as StringSelectMenuInteraction | ButtonInteraction; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1070 | } catch (e) { |
| 1071 | closed = true; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1072 | continue; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1073 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1074 | if (i.isButton()) { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 1075 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1076 | await client.database.guilds.write(interaction.guild.id, { filters: config }); |
Skyler Grey | 16ecb17 | 2023-03-05 07:30:32 +0000 | [diff] [blame] | 1077 | await client.memory.forceUpdate(interaction.guild.id); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1078 | } else { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1079 | switch (i.values[0]) { |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1080 | case "invites": { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 1081 | i.deferUpdate(); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1082 | config.invite = await inviteMenu(i, m, config.invite); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1083 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1084 | } |
| 1085 | case "mentions": { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 1086 | i.deferUpdate(); |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1087 | config.pings = await mentionMenu(i, m, config.pings); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1088 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1089 | } |
| 1090 | case "words": { |
TheCodedProf | 486bca3 | 2023-02-02 16:49:44 -0500 | [diff] [blame] | 1091 | config.wordFilter = await wordMenu(i, m, config.wordFilter); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1092 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1093 | } |
| 1094 | case "malware": { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 1095 | i.deferUpdate(); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1096 | config.malware = !config.malware; |
| 1097 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1098 | } |
| 1099 | case "images": { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 1100 | i.deferUpdate(); |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1101 | const next = await imageMenu(i, m, config.images); |
| 1102 | config.images = next; |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1103 | break; |
PineaFan | b0d0c24 | 2023-02-05 10:59:45 +0000 | [diff] [blame] | 1104 | } |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1105 | case "clean": { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 1106 | i.deferUpdate(); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 1107 | const next = await cleanMenu(i, m, config.clean); |
| 1108 | config.clean = next; |
| 1109 | break; |
| 1110 | } |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1111 | } |
| 1112 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1113 | } while (!closed); |
| 1114 | await interaction.deleteReply(); |
TheCodedProf | 8b3da21 | 2023-02-02 15:09:55 -0500 | [diff] [blame] | 1115 | }; |
| 1116 | |
| 1117 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
| 1118 | const member = interaction.member as Discord.GuildMember; |
| 1119 | if (!member.permissions.has("ManageMessages")) |
| 1120 | return "You must have the *Manage Messages* permission to use this command"; |
| 1121 | return true; |
| 1122 | }; |
| 1123 | |
| 1124 | export { command }; |
| 1125 | export { callback }; |
| 1126 | export { check }; |