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