pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../../utils/defaultEmbeds.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 2 | import getEmojiByName from "../../utils/getEmojiByName.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../../utils/generateEmojiEmbed.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 4 | import confirmationMessage from "../../utils/confirmationMessage.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 5 | import Discord, { |
| 6 | CommandInteraction, |
| 7 | GuildChannel, |
| 8 | Message, |
| 9 | MessageActionRow, |
| 10 | MessageActionRowComponent, |
| 11 | MessageButton, |
| 12 | MessageComponentInteraction, |
| 13 | MessageSelectMenu, |
| 14 | Role, |
| 15 | SelectMenuInteraction, |
| 16 | TextInputComponent |
| 17 | } from "discord.js"; |
| 18 | import { |
| 19 | SelectMenuOption, |
| 20 | SlashCommandSubcommandBuilder |
| 21 | } from "@discordjs/builders"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | import { ChannelType } from "discord-api-types"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 23 | import client from "../../utils/client.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 24 | import { |
| 25 | toHexInteger, |
| 26 | toHexArray, |
| 27 | tickets as ticketTypes |
| 28 | } from "../../utils/calculate.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | import { capitalize } from "../../utils/generateKeyValueList.js"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 30 | import { modalInteractionCollector } from "../../utils/dualCollector.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 31 | import { GuildConfig } from "../../utils/database.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 32 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 33 | const command = (builder: SlashCommandSubcommandBuilder) => |
| 34 | builder |
| 35 | .setName("tickets") |
| 36 | .setDescription( |
| 37 | "Shows settings for tickets | Use no arguments to manage custom types" |
| 38 | ) |
| 39 | .addStringOption((option) => |
| 40 | option |
| 41 | .setName("enabled") |
| 42 | .setDescription("If users should be able to create tickets") |
| 43 | .setRequired(false) |
| 44 | .addChoices([ |
| 45 | ["Yes", "yes"], |
| 46 | ["No", "no"] |
| 47 | ]) |
| 48 | ) |
| 49 | .addChannelOption((option) => |
| 50 | option |
| 51 | .setName("category") |
| 52 | .setDescription("The category where tickets are created") |
| 53 | .addChannelType(ChannelType.GuildCategory) |
| 54 | .setRequired(false) |
| 55 | ) |
| 56 | .addNumberOption((option) => |
| 57 | option |
| 58 | .setName("maxticketsperuser") |
| 59 | .setDescription( |
| 60 | "The maximum amount of tickets a user can create | Default: 5" |
| 61 | ) |
| 62 | .setRequired(false) |
| 63 | .setMinValue(1) |
| 64 | ) |
| 65 | .addRoleOption((option) => |
| 66 | option |
| 67 | .setName("supportrole") |
| 68 | .setDescription( |
| 69 | "This role will have view access to all tickets and will be pinged when a ticket is created" |
| 70 | ) |
| 71 | .setRequired(false) |
| 72 | ); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 73 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 74 | const callback = async ( |
| 75 | interaction: CommandInteraction |
| 76 | ): Promise<void | unknown> => { |
| 77 | let m = (await interaction.reply({ |
| 78 | embeds: LoadingEmbed, |
| 79 | ephemeral: true, |
| 80 | fetchReply: true |
| 81 | })) as Message; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 82 | const options = { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 83 | enabled: interaction.options.getString("enabled") as string | boolean, |
| 84 | category: interaction.options.getChannel("category"), |
| 85 | maxtickets: interaction.options.getNumber("maxticketsperuser"), |
| 86 | supportping: interaction.options.getRole("supportrole") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 87 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 88 | if ( |
| 89 | options.enabled !== null || |
| 90 | options.category || |
| 91 | options.maxtickets || |
| 92 | options.supportping |
| 93 | ) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 94 | options.enabled = options.enabled === "yes" ? true : false; |
| 95 | if (options.category) { |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 96 | let channel: GuildChannel; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 97 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 98 | channel = await interaction.guild.channels.fetch( |
| 99 | options.category.id |
| 100 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 101 | } catch { |
| 102 | return await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 103 | embeds: [ |
| 104 | new EmojiEmbed() |
| 105 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 106 | .setTitle("Tickets > Category") |
| 107 | .setDescription( |
| 108 | "The channel you provided is not a valid category" |
| 109 | ) |
| 110 | .setStatus("Danger") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 111 | ] |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 112 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 113 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 114 | channel = channel as Discord.CategoryChannel; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 115 | if (channel.guild.id !== interaction.guild.id) |
| 116 | return interaction.editReply({ |
| 117 | embeds: [ |
| 118 | new EmojiEmbed() |
| 119 | .setTitle("Tickets > Category") |
| 120 | .setDescription( |
| 121 | "You must choose a category in this server" |
| 122 | ) |
| 123 | .setStatus("Danger") |
| 124 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 125 | ] |
| 126 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 127 | } |
| 128 | if (options.maxtickets) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 129 | if (options.maxtickets < 1) |
| 130 | return interaction.editReply({ |
| 131 | embeds: [ |
| 132 | new EmojiEmbed() |
| 133 | .setTitle("Tickets > Max Tickets") |
| 134 | .setDescription( |
| 135 | "You must choose a number greater than 0" |
| 136 | ) |
| 137 | .setStatus("Danger") |
| 138 | .setEmoji("CHANNEL.TEXT.DELETE") |
| 139 | ] |
| 140 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 141 | } |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 142 | let role: Role; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 143 | if (options.supportping) { |
| 144 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 145 | role = await interaction.guild.roles.fetch( |
| 146 | options.supportping.id |
| 147 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 148 | } catch { |
| 149 | return await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 150 | embeds: [ |
| 151 | new EmojiEmbed() |
| 152 | .setEmoji("GUILD.ROLE.DELETE") |
| 153 | .setTitle("Tickets > Support Ping") |
| 154 | .setDescription( |
| 155 | "The role you provided is not a valid role" |
| 156 | ) |
| 157 | .setStatus("Danger") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 158 | ] |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 159 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 160 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 161 | role = role as Discord.Role; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 162 | if (role.guild.id !== interaction.guild.id) |
| 163 | return interaction.editReply({ |
| 164 | embeds: [ |
| 165 | new EmojiEmbed() |
| 166 | .setTitle("Tickets > Support Ping") |
| 167 | .setDescription( |
| 168 | "You must choose a role in this server" |
| 169 | ) |
| 170 | .setStatus("Danger") |
| 171 | .setEmoji("GUILD.ROLE.DELETE") |
| 172 | ] |
| 173 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 174 | } |
| 175 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 176 | const confirmation = await new confirmationMessage(interaction) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 177 | .setEmoji("GUILD.TICKET.ARCHIVED") |
| 178 | .setTitle("Tickets") |
| 179 | .setDescription( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 180 | (options.category |
| 181 | ? `**Category:** ${options.category.name}\n` |
| 182 | : "") + |
| 183 | (options.maxtickets |
| 184 | ? `**Max Tickets:** ${options.maxtickets}\n` |
| 185 | : "") + |
| 186 | (options.supportping |
| 187 | ? `**Support Ping:** ${options.supportping.name}\n` |
| 188 | : "") + |
| 189 | (options.enabled !== null |
| 190 | ? `**Enabled:** ${ |
| 191 | options.enabled |
| 192 | ? `${getEmojiByName("CONTROL.TICK")} Yes` |
| 193 | : `${getEmojiByName("CONTROL.CROSS")} No` |
| 194 | }\n` |
| 195 | : "") + |
| 196 | "\nAre you sure you want to apply these settings?" |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 197 | ) |
| 198 | .setColor("Warning") |
| 199 | .setInverted(true) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 200 | .send(true); |
| 201 | if (confirmation.cancelled) return; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 202 | if (confirmation.success) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 203 | const toUpdate = {}; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 204 | if (options.enabled !== null) |
| 205 | toUpdate["tickets.enabled"] = options.enabled; |
| 206 | if (options.category) |
| 207 | toUpdate["tickets.category"] = options.category.id; |
| 208 | if (options.maxtickets) |
| 209 | toUpdate["tickets.maxTickets"] = options.maxtickets; |
| 210 | if (options.supportping) |
| 211 | toUpdate["tickets.supportRole"] = options.supportping.id; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 212 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 213 | await client.database.guilds.write( |
| 214 | interaction.guild.id, |
| 215 | toUpdate |
| 216 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 217 | } catch (e) { |
| 218 | return interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 219 | embeds: [ |
| 220 | new EmojiEmbed() |
| 221 | .setTitle("Tickets") |
| 222 | .setDescription( |
| 223 | "Something went wrong and the staff notifications channel could not be set" |
| 224 | ) |
| 225 | .setStatus("Danger") |
| 226 | .setEmoji("GUILD.TICKET.DELETE") |
| 227 | ], |
| 228 | components: [] |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 229 | }); |
| 230 | } |
| 231 | } else { |
| 232 | return interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 233 | embeds: [ |
| 234 | new EmojiEmbed() |
| 235 | .setTitle("Tickets") |
| 236 | .setDescription("No changes were made") |
| 237 | .setStatus("Success") |
| 238 | .setEmoji("GUILD.TICKET.OPEN") |
| 239 | ], |
| 240 | components: [] |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 241 | }); |
| 242 | } |
| 243 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 244 | let data = await client.database.guilds.read(interaction.guild.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 245 | data.tickets.customTypes = (data.tickets.customTypes || []).filter( |
| 246 | (value: string, index: number, array: string[]) => |
| 247 | array.indexOf(value) === index |
| 248 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 249 | let lastClicked = ""; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 250 | let embed: EmojiEmbed; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 251 | data = { |
| 252 | enabled: data.tickets.enabled, |
| 253 | category: data.tickets.category, |
| 254 | maxTickets: data.tickets.maxTickets, |
| 255 | supportRole: data.tickets.supportRole, |
| 256 | useCustom: data.tickets.useCustom, |
| 257 | types: data.tickets.types, |
| 258 | customTypes: data.tickets.customTypes |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 259 | }; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 260 | while (true) { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 261 | embed = new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 262 | .setTitle("Tickets") |
| 263 | .setDescription( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 264 | `${ |
| 265 | data.enabled ? "" : getEmojiByName("TICKETS.REPORT") |
| 266 | } **Enabled:** ${ |
| 267 | data.enabled |
| 268 | ? `${getEmojiByName("CONTROL.TICK")} Yes` |
| 269 | : `${getEmojiByName("CONTROL.CROSS")} No` |
| 270 | }\n` + |
| 271 | `${ |
| 272 | data.category ? "" : getEmojiByName("TICKETS.REPORT") |
| 273 | } **Category:** ${ |
| 274 | data.category ? `<#${data.category}>` : "*None set*" |
| 275 | }\n` + |
| 276 | `**Max Tickets:** ${ |
| 277 | data.maxTickets ? data.maxTickets : "*No limit*" |
| 278 | }\n` + |
| 279 | `**Support Ping:** ${ |
| 280 | data.supportRole |
| 281 | ? `<@&${data.supportRole}>` |
| 282 | : "*None set*" |
| 283 | }\n\n` + |
| 284 | (data.useCustom && data.customTypes === null |
| 285 | ? `${getEmojiByName("TICKETS.REPORT")} ` |
| 286 | : "") + |
| 287 | `${data.useCustom ? "Custom" : "Default"} types in use` + |
| 288 | "\n\n" + |
| 289 | `${getEmojiByName( |
| 290 | "TICKETS.REPORT" |
| 291 | )} *Indicates a setting stopping tickets from being used*` |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 292 | ) |
| 293 | .setStatus("Success") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 294 | .setEmoji("GUILD.TICKET.OPEN"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 295 | m = (await interaction.editReply({ |
| 296 | embeds: [embed], |
| 297 | components: [ |
| 298 | new MessageActionRow().addComponents([ |
| 299 | new MessageButton() |
| 300 | .setLabel( |
| 301 | "Tickets " + (data.enabled ? "enabled" : "disabled") |
| 302 | ) |
| 303 | .setEmoji( |
| 304 | getEmojiByName( |
| 305 | "CONTROL." + (data.enabled ? "TICK" : "CROSS"), |
| 306 | "id" |
| 307 | ) |
| 308 | ) |
| 309 | .setStyle(data.enabled ? "SUCCESS" : "DANGER") |
| 310 | .setCustomId("enabled"), |
| 311 | new MessageButton() |
| 312 | .setLabel( |
| 313 | lastClicked === "cat" |
| 314 | ? "Click again to confirm" |
| 315 | : "Clear category" |
| 316 | ) |
| 317 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 318 | .setStyle("DANGER") |
| 319 | .setCustomId("clearCategory") |
| 320 | .setDisabled(data.category === null), |
| 321 | new MessageButton() |
| 322 | .setLabel( |
| 323 | lastClicked === "max" |
| 324 | ? "Click again to confirm" |
| 325 | : "Reset max tickets" |
| 326 | ) |
| 327 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 328 | .setStyle("DANGER") |
| 329 | .setCustomId("clearMaxTickets") |
| 330 | .setDisabled(data.maxTickets === 5), |
| 331 | new MessageButton() |
| 332 | .setLabel( |
| 333 | lastClicked === "sup" |
| 334 | ? "Click again to confirm" |
| 335 | : "Clear support ping" |
| 336 | ) |
| 337 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| 338 | .setStyle("DANGER") |
| 339 | .setCustomId("clearSupportPing") |
| 340 | .setDisabled(data.supportRole === null) |
| 341 | ]), |
| 342 | new MessageActionRow().addComponents([ |
| 343 | new MessageButton() |
| 344 | .setLabel("Manage types") |
| 345 | .setEmoji(getEmojiByName("TICKETS.OTHER", "id")) |
| 346 | .setStyle("SECONDARY") |
| 347 | .setCustomId("manageTypes"), |
| 348 | new MessageButton() |
| 349 | .setLabel("Add create ticket button") |
| 350 | .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id")) |
| 351 | .setStyle("PRIMARY") |
| 352 | .setCustomId("send") |
| 353 | ]) |
| 354 | ] |
| 355 | })) as Message; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 356 | let i: MessageComponentInteraction; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 357 | try { |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 358 | i = await m.awaitMessageComponent({ time: 300000 }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 359 | } catch (e) { |
| 360 | break; |
| 361 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 362 | i.deferUpdate(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 363 | if ( |
| 364 | (i.component as MessageActionRowComponent).customId === |
| 365 | "clearCategory" |
| 366 | ) { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 367 | if (lastClicked === "cat") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 368 | lastClicked = ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 369 | await client.database.guilds.write(interaction.guild.id, null, [ |
| 370 | "tickets.category" |
| 371 | ]); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 372 | data.category = undefined; |
| 373 | } else lastClicked = "cat"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 374 | } else if ( |
| 375 | (i.component as MessageActionRowComponent).customId === |
| 376 | "clearMaxTickets" |
| 377 | ) { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 378 | if (lastClicked === "max") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 379 | lastClicked = ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 380 | await client.database.guilds.write(interaction.guild.id, null, [ |
| 381 | "tickets.maxTickets" |
| 382 | ]); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 383 | data.maxTickets = 5; |
| 384 | } else lastClicked = "max"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 385 | } else if ( |
| 386 | (i.component as MessageActionRowComponent).customId === |
| 387 | "clearSupportPing" |
| 388 | ) { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 389 | if (lastClicked === "sup") { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 390 | lastClicked = ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 391 | await client.database.guilds.write(interaction.guild.id, null, [ |
| 392 | "tickets.supportRole" |
| 393 | ]); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 394 | data.supportRole = undefined; |
| 395 | } else lastClicked = "sup"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 396 | } else if ( |
| 397 | (i.component as MessageActionRowComponent).customId === "send" |
| 398 | ) { |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 399 | const ticketMessages = [ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 400 | { |
| 401 | label: "Create ticket", |
| 402 | description: "Click the button below to create a ticket" |
| 403 | }, |
| 404 | { |
| 405 | label: "Issues, questions or feedback?", |
| 406 | description: |
| 407 | "Click below to open a ticket and get help from our staff team" |
| 408 | }, |
| 409 | { |
| 410 | label: "Contact Us", |
| 411 | description: |
| 412 | "Click the button below to speak to us privately" |
| 413 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 414 | ]; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 415 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 416 | const enabled = data.enabled && data.category !== null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 417 | await interaction.editReply({ |
| 418 | embeds: [ |
| 419 | new EmojiEmbed() |
| 420 | .setTitle("Ticket Button") |
| 421 | .setDescription( |
| 422 | "Select a message template to send in this channel" |
| 423 | ) |
| 424 | .setFooter({ |
| 425 | text: enabled |
| 426 | ? "" |
| 427 | : "Tickets are not set up correctly so the button may not work for users. Check the main menu to find which options must be set." |
| 428 | }) |
| 429 | .setStatus(enabled ? "Success" : "Warning") |
| 430 | .setEmoji("GUILD.ROLES.CREATE") |
| 431 | ], |
| 432 | components: [ |
| 433 | new MessageActionRow().addComponents([ |
| 434 | new MessageSelectMenu() |
| 435 | .setOptions( |
| 436 | ticketMessages.map( |
| 437 | ( |
| 438 | t: { |
| 439 | label: string; |
| 440 | description: string; |
| 441 | value?: string; |
| 442 | }, |
| 443 | index |
| 444 | ) => { |
| 445 | t.value = index.toString(); |
| 446 | return t as { |
| 447 | value: string; |
| 448 | label: string; |
| 449 | description: string; |
| 450 | }; |
| 451 | } |
| 452 | ) |
| 453 | ) |
| 454 | .setCustomId("template") |
| 455 | .setMaxValues(1) |
| 456 | .setMinValues(1) |
| 457 | .setPlaceholder("Select a message template") |
| 458 | ]), |
| 459 | new MessageActionRow().addComponents([ |
| 460 | new MessageButton() |
| 461 | .setCustomId("back") |
| 462 | .setLabel("Back") |
| 463 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 464 | .setStyle("DANGER"), |
| 465 | new MessageButton() |
| 466 | .setCustomId("blank") |
| 467 | .setLabel("Empty") |
| 468 | .setStyle("SECONDARY"), |
| 469 | new MessageButton() |
| 470 | .setCustomId("custom") |
| 471 | .setLabel("Custom") |
| 472 | .setEmoji(getEmojiByName("TICKETS.OTHER", "id")) |
| 473 | .setStyle("PRIMARY") |
| 474 | ]) |
| 475 | ] |
| 476 | }); |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 477 | let i: MessageComponentInteraction; |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 478 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 479 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 480 | } catch (e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 481 | break; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 482 | } |
| 483 | if ( |
| 484 | (i.component as MessageActionRowComponent).customId === |
| 485 | "template" |
| 486 | ) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 487 | i.deferUpdate(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 488 | await interaction.channel.send({ |
| 489 | embeds: [ |
| 490 | new EmojiEmbed() |
| 491 | .setTitle( |
| 492 | ticketMessages[ |
| 493 | parseInt( |
| 494 | (i as SelectMenuInteraction) |
| 495 | .values[0] |
| 496 | ) |
| 497 | ].label |
| 498 | ) |
| 499 | .setDescription( |
| 500 | ticketMessages[ |
| 501 | parseInt( |
| 502 | (i as SelectMenuInteraction) |
| 503 | .values[0] |
| 504 | ) |
| 505 | ].description |
| 506 | ) |
| 507 | .setStatus("Success") |
| 508 | .setEmoji("GUILD.TICKET.OPEN") |
| 509 | ], |
| 510 | components: [ |
| 511 | new MessageActionRow().addComponents([ |
| 512 | new MessageButton() |
| 513 | .setLabel("Create Ticket") |
| 514 | .setEmoji( |
| 515 | getEmojiByName("CONTROL.TICK", "id") |
| 516 | ) |
| 517 | .setStyle("SUCCESS") |
| 518 | .setCustomId("createticket") |
| 519 | ]) |
| 520 | ] |
| 521 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 522 | break; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 523 | } else if ( |
| 524 | (i.component as MessageActionRowComponent).customId === |
| 525 | "blank" |
| 526 | ) { |
| 527 | i.deferUpdate(); |
| 528 | await interaction.channel.send({ |
| 529 | components: [ |
| 530 | new MessageActionRow().addComponents([ |
| 531 | new MessageButton() |
| 532 | .setLabel("Create Ticket") |
| 533 | .setEmoji( |
| 534 | getEmojiByName( |
| 535 | "TICKETS.SUGGESTION", |
| 536 | "id" |
| 537 | ) |
| 538 | ) |
| 539 | .setStyle("SUCCESS") |
| 540 | .setCustomId("createticket") |
| 541 | ]) |
| 542 | ] |
| 543 | }); |
| 544 | break; |
| 545 | } else if ( |
| 546 | (i.component as MessageActionRowComponent).customId === |
| 547 | "custom" |
| 548 | ) { |
| 549 | await i.showModal( |
| 550 | new Discord.Modal() |
| 551 | .setCustomId("modal") |
| 552 | .setTitle("Enter embed details") |
| 553 | .addComponents( |
| 554 | new MessageActionRow<TextInputComponent>().addComponents( |
| 555 | new TextInputComponent() |
| 556 | .setCustomId("title") |
| 557 | .setLabel("Title") |
| 558 | .setMaxLength(256) |
| 559 | .setRequired(true) |
| 560 | .setStyle("SHORT") |
| 561 | ), |
| 562 | new MessageActionRow<TextInputComponent>().addComponents( |
| 563 | new TextInputComponent() |
| 564 | .setCustomId("description") |
| 565 | .setLabel("Description") |
| 566 | .setMaxLength(4000) |
| 567 | .setRequired(true) |
| 568 | .setStyle("PARAGRAPH") |
| 569 | ) |
| 570 | ) |
| 571 | ); |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 572 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 573 | embeds: [ |
| 574 | new EmojiEmbed() |
| 575 | .setTitle("Ticket Button") |
| 576 | .setDescription( |
| 577 | "Modal opened. If you can't see it, click back and try again." |
| 578 | ) |
| 579 | .setStatus("Success") |
| 580 | .setEmoji("GUILD.TICKET.OPEN") |
| 581 | ], |
| 582 | components: [ |
| 583 | new MessageActionRow().addComponents([ |
| 584 | new MessageButton() |
| 585 | .setLabel("Back") |
| 586 | .setEmoji( |
| 587 | getEmojiByName("CONTROL.LEFT", "id") |
| 588 | ) |
| 589 | .setStyle("PRIMARY") |
| 590 | .setCustomId("back") |
| 591 | ]) |
| 592 | ] |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 593 | }); |
| 594 | let out; |
| 595 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 596 | out = await modalInteractionCollector( |
| 597 | m, |
| 598 | (m) => m.channel.id === interaction.channel.id, |
| 599 | (m) => m.customId === "modify" |
| 600 | ); |
| 601 | } catch (e) { |
| 602 | break; |
| 603 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 604 | if (out.fields) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 605 | const title = out.fields.getTextInputValue("title"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 606 | const description = |
| 607 | out.fields.getTextInputValue("description"); |
| 608 | await interaction.channel.send({ |
| 609 | embeds: [ |
| 610 | new EmojiEmbed() |
| 611 | .setTitle(title) |
| 612 | .setDescription(description) |
| 613 | .setStatus("Success") |
| 614 | .setEmoji("GUILD.TICKET.OPEN") |
| 615 | ], |
| 616 | components: [ |
| 617 | new MessageActionRow().addComponents([ |
| 618 | new MessageButton() |
| 619 | .setLabel("Create Ticket") |
| 620 | .setEmoji( |
| 621 | getEmojiByName( |
| 622 | "TICKETS.SUGGESTION", |
| 623 | "id" |
| 624 | ) |
| 625 | ) |
| 626 | .setStyle("SUCCESS") |
| 627 | .setCustomId("createticket") |
| 628 | ]) |
| 629 | ] |
| 630 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 631 | break; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 632 | } else { |
| 633 | continue; |
| 634 | } |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 635 | } |
| 636 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 637 | } else if ( |
| 638 | (i.component as MessageActionRowComponent).customId === "enabled" |
| 639 | ) { |
| 640 | await client.database.guilds.write(interaction.guild.id, { |
| 641 | "tickets.enabled": !data.enabled |
| 642 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 643 | data.enabled = !data.enabled; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 644 | } else if ( |
| 645 | (i.component as MessageActionRowComponent).customId === |
| 646 | "manageTypes" |
| 647 | ) { |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 648 | data = await manageTypes(interaction, data, m as Message); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 649 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 650 | break; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 651 | } |
| 652 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 653 | await interaction.editReply({ |
| 654 | embeds: [embed.setFooter({ text: "Message closed" })], |
| 655 | components: [] |
| 656 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 657 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 658 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 659 | async function manageTypes( |
| 660 | interaction: CommandInteraction, |
| 661 | data: GuildConfig["tickets"], |
| 662 | m: Message |
| 663 | ) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 664 | while (true) { |
| 665 | if (data.useCustom) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 666 | const customTypes = data.customTypes; |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 667 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 668 | embeds: [ |
| 669 | new EmojiEmbed() |
| 670 | .setTitle("Tickets > Types") |
| 671 | .setDescription( |
| 672 | "**Custom types enabled**\n\n" + |
| 673 | "**Types in use:**\n" + |
| 674 | (customTypes !== null |
| 675 | ? customTypes |
| 676 | .map((t) => `> ${t}`) |
| 677 | .join("\n") |
| 678 | : "*None set*") + |
| 679 | "\n\n" + |
| 680 | (customTypes === null |
| 681 | ? `${getEmojiByName( |
| 682 | "TICKETS.REPORT" |
| 683 | )} Having no types will disable tickets. Please add at least 1 type or use default types` |
| 684 | : "") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 685 | ) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 686 | .setStatus("Success") |
| 687 | .setEmoji("GUILD.TICKET.OPEN") |
| 688 | ], |
| 689 | components: (customTypes |
| 690 | ? [ |
| 691 | new MessageActionRow().addComponents([ |
| 692 | new Discord.MessageSelectMenu() |
| 693 | .setCustomId("removeTypes") |
| 694 | .setPlaceholder("Select types to remove") |
| 695 | .setMaxValues(customTypes.length) |
| 696 | .setMinValues(1) |
| 697 | .addOptions( |
| 698 | customTypes.map((t) => ({ |
| 699 | label: t, |
| 700 | value: t |
| 701 | })) |
| 702 | ) |
| 703 | ]) |
| 704 | ] |
| 705 | : [] |
| 706 | ).concat([ |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 707 | new MessageActionRow().addComponents([ |
| 708 | new MessageButton() |
| 709 | .setLabel("Back") |
| 710 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 711 | .setStyle("PRIMARY") |
| 712 | .setCustomId("back"), |
| 713 | new MessageButton() |
| 714 | .setLabel("Add new type") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 715 | .setEmoji( |
| 716 | getEmojiByName("TICKETS.SUGGESTION", "id") |
| 717 | ) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 718 | .setStyle("PRIMARY") |
| 719 | .setCustomId("addType") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 720 | .setDisabled( |
| 721 | customTypes !== null && customTypes.length >= 25 |
| 722 | ), |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 723 | new MessageButton() |
| 724 | .setLabel("Switch to default types") |
| 725 | .setStyle("SECONDARY") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 726 | .setCustomId("switchToDefault") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 727 | ]) |
| 728 | ]) |
| 729 | }); |
| 730 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 731 | const inUse = toHexArray(data.types, ticketTypes); |
| 732 | const options = []; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 733 | ticketTypes.forEach((type) => { |
| 734 | options.push( |
| 735 | new SelectMenuOption({ |
| 736 | label: capitalize(type), |
| 737 | value: type, |
| 738 | emoji: client.emojis.cache.get( |
| 739 | getEmojiByName( |
| 740 | `TICKETS.${type.toUpperCase()}`, |
| 741 | "id" |
| 742 | ) |
| 743 | ), |
| 744 | default: inUse.includes(type) |
| 745 | }) |
| 746 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 747 | }); |
| 748 | const selectPane = new MessageActionRow().addComponents([ |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 749 | new Discord.MessageSelectMenu() |
| 750 | .addOptions(options) |
| 751 | .setCustomId("types") |
| 752 | .setMaxValues(ticketTypes.length) |
| 753 | .setMinValues(1) |
| 754 | .setPlaceholder("Select types to use") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 755 | ]); |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 756 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 757 | embeds: [ |
| 758 | new EmojiEmbed() |
| 759 | .setTitle("Tickets > Types") |
| 760 | .setDescription( |
| 761 | "**Default types enabled**\n\n" + |
| 762 | "**Types in use:**\n" + |
| 763 | inUse |
| 764 | .map( |
| 765 | (t) => |
| 766 | `> ${getEmojiByName( |
| 767 | "TICKETS." + t.toUpperCase() |
| 768 | )} ${capitalize(t)}` |
| 769 | ) |
| 770 | .join("\n") |
| 771 | ) |
| 772 | .setStatus("Success") |
| 773 | .setEmoji("GUILD.TICKET.OPEN") |
| 774 | ], |
| 775 | components: [ |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 776 | selectPane, |
| 777 | new MessageActionRow().addComponents([ |
| 778 | new MessageButton() |
| 779 | .setLabel("Back") |
| 780 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 781 | .setStyle("PRIMARY") |
| 782 | .setCustomId("back"), |
| 783 | new MessageButton() |
| 784 | .setLabel("Switch to custom types") |
| 785 | .setStyle("SECONDARY") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 786 | .setCustomId("switchToCustom") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 787 | ]) |
| 788 | ] |
| 789 | }); |
| 790 | } |
| 791 | let i; |
| 792 | try { |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 793 | i = await m.awaitMessageComponent({ time: 300000 }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 794 | } catch (e) { |
| 795 | break; |
| 796 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 797 | if (i.component.customId === "types") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 798 | i.deferUpdate(); |
| 799 | const types = toHexInteger(i.values, ticketTypes); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 800 | await client.database.guilds.write(interaction.guild.id, { |
| 801 | "tickets.types": types |
| 802 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 803 | data.types = types; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 804 | } else if (i.component.customId === "removeTypes") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 805 | i.deferUpdate(); |
| 806 | const types = i.values; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 807 | let customTypes = data.customTypes; |
| 808 | if (customTypes) { |
| 809 | customTypes = customTypes.filter((t) => !types.includes(t)); |
| 810 | customTypes = customTypes.length > 0 ? customTypes : null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 811 | await client.database.guilds.write(interaction.guild.id, { |
| 812 | "tickets.customTypes": customTypes |
| 813 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 814 | data.customTypes = customTypes; |
| 815 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 816 | } else if (i.component.customId === "addType") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 817 | await i.showModal( |
| 818 | new Discord.Modal() |
| 819 | .setCustomId("modal") |
| 820 | .setTitle("Enter a name for the new type") |
| 821 | .addComponents( |
| 822 | new MessageActionRow<TextInputComponent>().addComponents( |
| 823 | new TextInputComponent() |
| 824 | .setCustomId("type") |
| 825 | .setLabel("Name") |
| 826 | .setMaxLength(100) |
| 827 | .setMinLength(1) |
| 828 | .setPlaceholder('E.g. "Server Idea"') |
| 829 | .setRequired(true) |
| 830 | .setStyle("SHORT") |
| 831 | ) |
| 832 | ) |
| 833 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 834 | await interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 835 | embeds: [ |
| 836 | new EmojiEmbed() |
| 837 | .setTitle("Tickets > Types") |
| 838 | .setDescription( |
| 839 | "Modal opened. If you can't see it, click back and try again." |
| 840 | ) |
| 841 | .setStatus("Success") |
| 842 | .setEmoji("GUILD.TICKET.OPEN") |
| 843 | ], |
| 844 | components: [ |
| 845 | new MessageActionRow().addComponents([ |
| 846 | new MessageButton() |
| 847 | .setLabel("Back") |
| 848 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| 849 | .setStyle("PRIMARY") |
| 850 | .setCustomId("back") |
| 851 | ]) |
| 852 | ] |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 853 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 854 | let out; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 855 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 856 | out = await modalInteractionCollector( |
| 857 | m, |
| 858 | (m) => m.channel.id === interaction.channel.id, |
| 859 | (m) => m.customId === "addType" |
| 860 | ); |
| 861 | } catch (e) { |
| 862 | continue; |
| 863 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 864 | if (out.fields) { |
| 865 | let toAdd = out.fields.getTextInputValue("type"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 866 | if (!toAdd) { |
| 867 | continue; |
| 868 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 869 | toAdd = toAdd.substring(0, 80); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 870 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 871 | await client.database.guilds.append( |
| 872 | interaction.guild.id, |
| 873 | "tickets.customTypes", |
| 874 | toAdd |
| 875 | ); |
| 876 | } catch { |
| 877 | continue; |
| 878 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 879 | data.customTypes = data.customTypes || []; |
| 880 | if (!data.customTypes.includes(toAdd)) { |
| 881 | data.customTypes.push(toAdd); |
| 882 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 883 | } else { |
| 884 | continue; |
| 885 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 886 | } else if (i.component.customId === "switchToDefault") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 887 | i.deferUpdate(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 888 | await client.database.guilds.write( |
| 889 | interaction.guild.id, |
| 890 | { "tickets.useCustom": false }, |
| 891 | [] |
| 892 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 893 | data.useCustom = false; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 894 | } else if (i.component.customId === "switchToCustom") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 895 | i.deferUpdate(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 896 | await client.database.guilds.write( |
| 897 | interaction.guild.id, |
| 898 | { "tickets.useCustom": true }, |
| 899 | [] |
| 900 | ); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 901 | data.useCustom = true; |
| 902 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 903 | i.deferUpdate(); |
| 904 | break; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 905 | } |
| 906 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 907 | return data; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 910 | const check = (interaction: CommandInteraction) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 911 | const member = interaction.member as Discord.GuildMember; |
| 912 | if (!member.permissions.has("MANAGE_GUILD")) |
| 913 | throw "You must have the *Manage Server* permission to use this command"; |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 914 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 915 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 916 | |
| 917 | export { command }; |
| 918 | export { callback }; |
Skyler Grey | 1a67e18 | 2022-08-04 23:05:44 +0100 | [diff] [blame] | 919 | export { check }; |