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