PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../utils/defaults.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 2 | import Discord, { |
| 3 | Channel, |
| 4 | CommandInteraction, |
| 5 | Message, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 6 | ActionRowBuilder, |
| 7 | ButtonBuilder, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 8 | MessageComponentInteraction, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 9 | Role, |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 10 | ButtonStyle, |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 11 | AutocompleteInteraction, |
| 12 | GuildChannel, |
| 13 | EmbedBuilder |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 14 | } from "discord.js"; |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 15 | import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 16 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 17 | import client from "../../utils/client.js"; |
| 18 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
| 19 | import generateKeyValueList from "../../utils/generateKeyValueList.js"; |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 20 | import { ChannelType } from "discord-api-types/v9"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 21 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 22 | |
| 23 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 24 | builder |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 25 | .setName("welcome") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 26 | .setDescription("Messages and roles sent or given when someone joins the server") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 27 | .addStringOption((option) => |
| 28 | option |
| 29 | .setName("message") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 30 | .setDescription("The message to send when someone joins the server") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 31 | .setAutocomplete(true) |
| 32 | ) |
| 33 | .addRoleOption((option) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 34 | option.setName("role").setDescription("The role given when someone joins the server") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | ) |
| 36 | .addRoleOption((option) => |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 37 | option.setName("ping").setDescription("The role pinged when someone joins the server") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 38 | ) |
| 39 | .addChannelOption((option) => |
| 40 | option |
| 41 | .setName("channel") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 42 | .setDescription("The channel the welcome message should be sent to") |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 43 | .addChannelTypes(ChannelType.GuildText) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 44 | ); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 45 | |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 46 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 47 | const { renderRole, renderChannel, log, NucleusColors, entry, renderUser } = client.logger; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 48 | await interaction.reply({ |
| 49 | embeds: LoadingEmbed, |
| 50 | fetchReply: true, |
| 51 | ephemeral: true |
| 52 | }); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 53 | let m: Message; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 54 | if ( |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 55 | interaction.options.get("role")?.role || |
| 56 | interaction.options.get("channel")?.channel || |
| 57 | interaction.options.get("message")?.value as string |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 58 | ) { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 59 | let role: Role | null; |
| 60 | let ping: Role | null; |
| 61 | let channel: Channel | null; |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 62 | const message: string | null = interaction.options.get("message")?.value as string | null; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 63 | try { |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 64 | role = interaction.options.get("role")?.role as Role | null; |
| 65 | ping = interaction.options.get("ping")?.role as Role | null; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 66 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 67 | return await interaction.editReply({ |
| 68 | embeds: [ |
| 69 | new EmojiEmbed() |
| 70 | .setEmoji("GUILD.ROLES.DELETE") |
| 71 | .setTitle("Welcome Events") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 72 | .setDescription("The role you provided is not a valid role") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 73 | .setStatus("Danger") |
| 74 | ] |
| 75 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 76 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 77 | try { |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 78 | channel = interaction.options.get("channel")?.channel as Channel | null; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 79 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 80 | return await interaction.editReply({ |
| 81 | embeds: [ |
| 82 | new EmojiEmbed() |
| 83 | .setEmoji("GUILD.ROLES.DELETE") |
| 84 | .setTitle("Welcome Events") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 85 | .setDescription("The channel you provided is not a valid channel") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 86 | .setStatus("Danger") |
| 87 | ] |
| 88 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 89 | } |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 90 | const options: { |
| 91 | role?: string; |
| 92 | ping?: string; |
| 93 | channel?: string; |
| 94 | message?: string; |
| 95 | } = {}; |
| 96 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 97 | if (role) options.role = renderRole(role); |
| 98 | if (ping) options.ping = renderRole(ping); |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 99 | if (channel) options.channel = renderChannel(channel as GuildChannel); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 100 | if (message) options.message = "\n> " + message; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 101 | const confirmation = await new confirmationMessage(interaction) |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 102 | .setEmoji("GUILD.ROLES.EDIT") |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 103 | .setTitle("Welcome Events") |
| 104 | .setDescription(generateKeyValueList(options)) |
| 105 | .setColor("Warning") |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 106 | .setFailedMessage("No changes were made", "Success", "GUILD.ROLES.CREATE") |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 107 | .setInverted(true) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 108 | .send(true); |
| 109 | if (confirmation.cancelled) return; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 110 | if (confirmation.success) { |
| 111 | try { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 112 | const toChange: { |
| 113 | "welcome.role"?: string; |
| 114 | "welcome.ping"?: string; |
| 115 | "welcome.channel"?: string; |
| 116 | "welcome.message"?: string; |
| 117 | } = {}; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 118 | if (role) toChange["welcome.role"] = role.id; |
| 119 | if (ping) toChange["welcome.ping"] = ping.id; |
| 120 | if (channel) toChange["welcome.channel"] = channel.id; |
| 121 | if (message) toChange["welcome.message"] = message; |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 122 | await client.database.guilds.write(interaction.guild!.id, toChange); |
| 123 | const list: { |
| 124 | memberId: ReturnType<typeof entry>; |
| 125 | changedBy: ReturnType<typeof entry>; |
| 126 | role?: ReturnType<typeof entry>; |
| 127 | ping?: ReturnType<typeof entry>; |
| 128 | channel?: ReturnType<typeof entry>; |
| 129 | message?: ReturnType<typeof entry>; |
| 130 | } = { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 131 | memberId: entry(interaction.user.id, `\`${interaction.user.id}\``), |
| 132 | changedBy: entry(interaction.user.id, renderUser(interaction.user)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 133 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 134 | if (role) list.role = entry(role.id, renderRole(role)); |
| 135 | if (ping) list.ping = entry(ping.id, renderRole(ping)); |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 136 | if (channel) list.channel = entry(channel.id, renderChannel(channel as GuildChannel)); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 137 | if (message) list.message = entry(message, `\`${message}\``); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 138 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 139 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 140 | type: "welcomeSettingsUpdated", |
| 141 | displayName: "Welcome Settings Changed", |
| 142 | calculateType: "nucleusSettingsUpdated", |
| 143 | color: NucleusColors.green, |
| 144 | emoji: "CONTROL.BLOCKTICK", |
| 145 | timestamp: new Date().getTime() |
| 146 | }, |
| 147 | list: list, |
| 148 | hidden: { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 149 | guild: interaction.guild!.id |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 150 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 151 | }; |
| 152 | log(data); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 153 | } catch (e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 154 | console.log(e); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 155 | return interaction.editReply({ |
| 156 | embeds: [ |
| 157 | new EmojiEmbed() |
| 158 | .setTitle("Welcome Events") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 159 | .setDescription("Something went wrong while updating welcome settings") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 160 | .setStatus("Danger") |
| 161 | .setEmoji("GUILD.ROLES.DELETE") |
| 162 | ], |
| 163 | components: [] |
| 164 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 165 | } |
| 166 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 167 | return interaction.editReply({ |
| 168 | embeds: [ |
| 169 | new EmojiEmbed() |
| 170 | .setTitle("Welcome Events") |
| 171 | .setDescription("No changes were made") |
| 172 | .setStatus("Success") |
| 173 | .setEmoji("GUILD.ROLES.CREATE") |
| 174 | ], |
| 175 | components: [] |
| 176 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 177 | } |
| 178 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 179 | let lastClicked = null; |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 180 | let timedOut = false; |
| 181 | do { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 182 | const config = await client.database.guilds.read(interaction.guild!.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 183 | m = (await interaction.editReply({ |
| 184 | embeds: [ |
| 185 | new EmojiEmbed() |
| 186 | .setTitle("Welcome Events") |
| 187 | .setDescription( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 188 | `**Message:** ${config.welcome.message ? `\n> ${config.welcome.message}` : "*None set*"}\n` + |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 189 | `**Role:** ${ |
| 190 | config.welcome.role |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 191 | ? renderRole((await interaction.guild!.roles.fetch(config.welcome.role))!) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 192 | : "*None set*" |
| 193 | }\n` + |
| 194 | `**Ping:** ${ |
| 195 | config.welcome.ping |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 196 | ? renderRole((await interaction.guild!.roles.fetch(config.welcome.ping))!) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 197 | : "*None set*" |
| 198 | }\n` + |
| 199 | `**Channel:** ${ |
| 200 | config.welcome.channel |
| 201 | ? config.welcome.channel == "dm" |
| 202 | ? "DM" |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 203 | : renderChannel((await interaction.guild!.channels.fetch(config.welcome.channel))!) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 204 | : "*None set*" |
| 205 | }` |
| 206 | ) |
| 207 | .setStatus("Success") |
| 208 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 209 | ], |
| 210 | components: [ |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 211 | new ActionRowBuilder<ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 212 | new ButtonBuilder() |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 213 | .setLabel(lastClicked == "clear-message" ? "Click again to confirm" : "Clear Message") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 214 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 215 | .setCustomId("clear-message") |
| 216 | .setDisabled(!config.welcome.message) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 217 | .setStyle(ButtonStyle.Danger), |
| 218 | new ButtonBuilder() |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 219 | .setLabel(lastClicked == "clear-role" ? "Click again to confirm" : "Clear Role") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 220 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 221 | .setCustomId("clear-role") |
| 222 | .setDisabled(!config.welcome.role) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 223 | .setStyle(ButtonStyle.Danger), |
| 224 | new ButtonBuilder() |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 225 | .setLabel(lastClicked == "clear-ping" ? "Click again to confirm" : "Clear Ping") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 226 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 227 | .setCustomId("clear-ping") |
| 228 | .setDisabled(!config.welcome.ping) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 229 | .setStyle(ButtonStyle.Danger), |
| 230 | new ButtonBuilder() |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 231 | .setLabel(lastClicked == "clear-channel" ? "Click again to confirm" : "Clear Channel") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 232 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 233 | .setCustomId("clear-channel") |
| 234 | .setDisabled(!config.welcome.channel) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 235 | .setStyle(ButtonStyle.Danger), |
| 236 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 237 | .setLabel("Set Channel to DM") |
| 238 | .setCustomId("set-channel-dm") |
| 239 | .setDisabled(config.welcome.channel == "dm") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 240 | .setStyle(ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 241 | ]) |
| 242 | ] |
| 243 | })) as Message; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 244 | let i: MessageComponentInteraction; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 245 | try { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 246 | i = await m.awaitMessageComponent({ |
| 247 | time: 300000, |
| 248 | filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id } |
| 249 | }); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 250 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 251 | timedOut = true; |
| 252 | continue; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 253 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 254 | i.deferUpdate(); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 255 | if (i.customId == "clear-message") { |
| 256 | if (lastClicked == "clear-message") { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 257 | await client.database.guilds.write(interaction.guild!.id, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 258 | "welcome.message": null |
| 259 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 260 | lastClicked = null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 261 | } else { |
| 262 | lastClicked = "clear-message"; |
| 263 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 264 | } else if (i.customId == "clear-role") { |
| 265 | if (lastClicked == "clear-role") { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 266 | await client.database.guilds.write(interaction.guild!.id, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 267 | "welcome.role": null |
| 268 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 269 | lastClicked = null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 270 | } else { |
| 271 | lastClicked = "clear-role"; |
| 272 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 273 | } else if (i.customId == "clear-ping") { |
| 274 | if (lastClicked == "clear-ping") { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 275 | await client.database.guilds.write(interaction.guild!.id, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 276 | "welcome.ping": null |
| 277 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 278 | lastClicked = null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 279 | } else { |
| 280 | lastClicked = "clear-ping"; |
| 281 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 282 | } else if (i.customId == "clear-channel") { |
| 283 | if (lastClicked == "clear-channel") { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 284 | await client.database.guilds.write(interaction.guild!.id, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 285 | "welcome.channel": null |
| 286 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 287 | lastClicked = null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 288 | } else { |
| 289 | lastClicked = "clear-channel"; |
| 290 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 291 | } else if (i.customId == "set-channel-dm") { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 292 | await client.database.guilds.write(interaction.guild!.id, { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 293 | "welcome.channel": "dm" |
| 294 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 295 | lastClicked = null; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 296 | } |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 297 | } while (!timedOut); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 298 | await interaction.editReply({ |
TheCodedProf | 5129610 | 2023-01-18 22:35:02 -0500 | [diff] [blame] | 299 | embeds: [new EmbedBuilder(m.embeds[0]!.data).setFooter({ text: "Message timed out" })], |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 300 | components: [] |
| 301 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 302 | }; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 303 | |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 304 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 305 | const member = interaction.member as Discord.GuildMember; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 306 | if (!member.permissions.has("ManageGuild")) |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 307 | return "You must have the *Manage Server* permission to use this command"; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 308 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 309 | }; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 310 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 311 | const autocomplete = async (interaction: AutocompleteInteraction): Promise<string[]> => { |
| 312 | const validReplacements = ["serverName", "memberCount", "memberCount:bots", "memberCount:humans"] |
| 313 | if (!interaction.guild) return []; |
| 314 | const prompt = interaction.options.getString("message"); |
| 315 | const autocompletions = []; |
| 316 | if ( prompt === null ) { |
| 317 | for (const replacement of validReplacements) { |
| 318 | autocompletions.push(`{${replacement}}`); |
| 319 | }; |
| 320 | return autocompletions; |
| 321 | }; |
| 322 | const beforeLastOpenBracket = prompt.match(/(.*){[^{}]{0,15}$/); |
| 323 | const afterLastOpenBracket = prompt.match(/{[^{}]{0,15}$/); |
| 324 | if (beforeLastOpenBracket !== null) { |
| 325 | if (afterLastOpenBracket !== null) { |
| 326 | for (const replacement of validReplacements) { |
PineaFan | 5d98a4b | 2023-01-19 16:15:47 +0000 | [diff] [blame^] | 327 | if (replacement.startsWith(afterLastOpenBracket[0]!.slice(1))) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 328 | autocompletions.push(`${beforeLastOpenBracket[1]}{${replacement}}`); |
| 329 | } |
| 330 | } |
| 331 | } else { |
| 332 | for (const replacement of validReplacements) { |
| 333 | autocompletions.push(`${beforeLastOpenBracket[1]}{${replacement}}`); |
| 334 | } |
| 335 | } |
| 336 | } else { |
| 337 | for (const replacement of validReplacements) { |
| 338 | autocompletions.push(`${prompt} {${replacement}}`); |
| 339 | } |
| 340 | } |
| 341 | return autocompletions; |
| 342 | }; |
| 343 | |
| 344 | export { command, callback, check, autocomplete }; |