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