Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1 | import { getCommandMentionByName } from "./../utils/getCommandDataByName.js"; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 2 | import { LoadingEmbed } from "../utils/defaults.js"; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 3 | import Discord, { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 4 | ActionRowBuilder, |
| 5 | ButtonBuilder, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 6 | MessageComponentInteraction, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 7 | Guild, |
| 8 | CommandInteraction, |
| 9 | GuildTextBasedChannel, |
| 10 | Message, |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 11 | ButtonStyle, |
| 12 | ChannelType |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 13 | } from "discord.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 14 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 15 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 16 | import createPageIndicator from "../utils/createPageIndicator.js"; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 17 | import { Embed } from "../utils/defaults.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 18 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 19 | export default async (guild: Guild, interaction?: CommandInteraction) => { |
| 20 | let c: GuildTextBasedChannel | null = guild.publicUpdatesChannel ? guild.publicUpdatesChannel : guild.systemChannel; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 21 | c = c |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 22 | ? c |
| 23 | : (guild.channels.cache.find( |
| 24 | (ch) => |
| 25 | [ |
| 26 | ChannelType.GuildText, |
| 27 | ChannelType.GuildAnnouncement, |
| 28 | ChannelType.PublicThread, |
| 29 | ChannelType.PrivateThread, |
| 30 | ChannelType.AnnouncementThread |
| 31 | ].includes(ch.type) && |
| 32 | ch.permissionsFor(guild.roles.everyone).has("SendMessages") && |
| 33 | ch.permissionsFor(guild.members.me!).has("EmbedLinks") |
| 34 | ) as GuildTextBasedChannel | undefined) ?? null; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 35 | if (interaction) c = interaction.channel as GuildTextBasedChannel; |
| 36 | if (!c) { |
| 37 | return; |
| 38 | } |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 39 | let m: Message; |
| 40 | if (interaction) { |
| 41 | m = (await interaction.reply({ |
| 42 | embeds: LoadingEmbed, |
| 43 | fetchReply: true, |
| 44 | ephemeral: true |
| 45 | })) as Message; |
| 46 | } else { |
| 47 | m = await c.send({ embeds: LoadingEmbed }); |
| 48 | } |
| 49 | let page = 0; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 50 | const pages = [ |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 51 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 52 | .setEmbed( |
| 53 | new EmojiEmbed() |
| 54 | .setTitle("Welcome to Nucleus") |
| 55 | .setDescription( |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 56 | "Thanks for adding Nucleus to your server!\n\n" + |
| 57 | "The next few pages will show what features Nucleus has to offer, and how to enable them.\n\n" + |
| 58 | "If you need support, have questions or want features, you can let us know in [Clicks](https://discord.gg/bPaNnxe)!" |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 59 | ) |
| 60 | .setEmoji("NUCLEUS.LOGO") |
| 61 | .setStatus("Danger") |
| 62 | ) |
| 63 | .setTitle("Welcome") |
| 64 | .setDescription("About Nucleus") |
| 65 | .setPageId(0), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 66 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 67 | .setEmbed( |
| 68 | new EmojiEmbed() |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 69 | .setTitle("Logs") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 70 | .setDescription( |
| 71 | "Nucleus can log server events and keep you informed with what content is being posted to your server.\n" + |
| 72 | "We have 2 different types of logs, which each can be configured to send to a channel of your choice:\n" + |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 73 | "**General:** These are events like kicks and channel changes etc.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 74 | `> These are standard logs and can be set with ${getCommandMentionByName( |
| 75 | "settings/logs/general" |
| 76 | )}\n` + |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 77 | "**Warnings:** Warnings like NSFW avatars and spam etc. that may require action by a server staff member.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 78 | `> These may require special action by a moderator. You can set the channel with ${getCommandMentionByName( |
| 79 | "settings/logs/warnings" |
| 80 | )}\n` + |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 81 | "**Attachments:** All images sent in the server - Used to keep a record of deleted images\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 82 | `> Sent to a separate log channel to avoid spam. This can be set with ${getCommandMentionByName( |
| 83 | "settings/logs/attachments" |
| 84 | )}\n` + |
| 85 | `> ${getEmojiByName( |
| 86 | "NUCLEUS.PREMIUM" |
| 87 | )} Please note this feature is only available with ${getCommandMentionByName( |
| 88 | "nucleus/premium" |
| 89 | )}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 90 | ) |
| 91 | .setEmoji("ICONS.LOGGING") |
| 92 | .setStatus("Danger") |
| 93 | ) |
| 94 | .setTitle("Logging") |
| 95 | .setDescription("Logging, staff warning logs etc.") |
| 96 | .setPageId(1), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 97 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 98 | .setEmbed( |
| 99 | new EmojiEmbed() |
| 100 | .setTitle("Moderation") |
| 101 | .setDescription( |
| 102 | "Nucleus has a number of commands that can be used to moderate your server.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 103 | `These commands are all found under ${getCommandMentionByName( |
| 104 | "mod" |
| 105 | )}, and they include:\n` + |
| 106 | `${getEmojiByName("PUNISH.WARN.YELLOW")} ${getCommandMentionByName( |
| 107 | "mod/warn" |
| 108 | )}: The user is warned (via DM) that they violated server rules. More options given if DMs are disabled.\n` + |
| 109 | `${getEmojiByName("PUNISH.CLEARHISTORY")} ${getCommandMentionByName( |
| 110 | "mod/purge" |
| 111 | )}: Deletes messages in a channel, giving options to only delete messages by a certain user.\n` + |
| 112 | `${getEmojiByName("PUNISH.MUTE.YELLOW")} ${getCommandMentionByName( |
| 113 | "mod/mute" |
| 114 | )}: Stops users sending messages or joining voice chats.\n` + |
| 115 | `${getEmojiByName("PUNISH.MUTE.GREEN")} ${getCommandMentionByName( |
| 116 | "mod/unmute" |
| 117 | )}: Allows user to send messages and join voice chats.\n` + |
| 118 | `${getEmojiByName("PUNISH.KICK.RED")} ${getCommandMentionByName( |
| 119 | "mod/kick" |
| 120 | )}: Removes a member from the server. They will be able to rejoin.\n` + |
| 121 | `${getEmojiByName("PUNISH.SOFTBAN")} ${getCommandMentionByName( |
| 122 | "mod/softban" |
| 123 | )}: Kicks the user, deleting their messages from every channel in a given time frame.\n` + |
| 124 | `${getEmojiByName("PUNISH.BAN.RED")} ${getCommandMentionByName( |
| 125 | "mod/ban" |
| 126 | )}: Removes the user from the server, deleting messages from every channel and stops them from rejoining.\n` + |
| 127 | `${getEmojiByName("PUNISH.BAN.GREEN")} ${getCommandMentionByName( |
| 128 | "mod/unban" |
| 129 | )}: Allows a member to rejoin the server after being banned.` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 130 | ) |
| 131 | .setEmoji("PUNISH.BAN.RED") |
| 132 | .setStatus("Danger") |
| 133 | ) |
| 134 | .setTitle("Moderation") |
| 135 | .setDescription("Basic moderation commands") |
| 136 | .setPageId(2), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 137 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 138 | .setEmbed( |
| 139 | new EmojiEmbed() |
| 140 | .setTitle("Verify") |
| 141 | .setDescription( |
| 142 | "Nucleus has a verification system that allows users to prove they aren't bots.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 143 | `This is done by running ${getCommandMentionByName( |
| 144 | "verify" |
| 145 | )} which sends a message only the user can see, giving them a link to a website to verify.\n` + |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 146 | "After the user complete's the check, they are given a role, which can be set to unlock specific channels.\n" + |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 147 | `You can set the role given with ${getCommandMentionByName("settings/verify")}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 148 | ) |
| 149 | .setEmoji("CONTROL.REDTICK") |
| 150 | .setStatus("Danger") |
| 151 | ) |
| 152 | .setTitle("Verify") |
| 153 | .setDescription("Captcha verification system") |
| 154 | .setPageId(3), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 155 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 156 | .setEmbed( |
| 157 | new EmojiEmbed() |
| 158 | .setTitle("Content Scanning") |
| 159 | .setDescription( |
| 160 | "Nucleus has a content scanning system that automatically scans links and images sent by users.\n" + |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 161 | "The staff team can be notified when an NSFW image is detected, or malicious links are sent.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 162 | `You can check and manage what to moderate in ${getCommandMentionByName( |
| 163 | "settings/automod" |
| 164 | )}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 165 | ) |
| 166 | .setEmoji("MOD.IMAGES.TOOSMALL") |
| 167 | .setStatus("Danger") |
| 168 | ) |
| 169 | .setTitle("Content Scanning") |
| 170 | .setDescription("Content (NSFW, malware, scams) scanning") |
| 171 | .setPageId(4), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 172 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 173 | .setEmbed( |
| 174 | new EmojiEmbed() |
| 175 | .setTitle("Tickets") |
| 176 | .setDescription( |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 177 | "Nucleus has a ticket system which allows users to create tickets and talk to the server staff or support team.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 178 | `Tickets can be created by users with ${getCommandMentionByName( |
| 179 | "ticket/create" |
| 180 | )}, or by clicking a button created by moderators.\n` + |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 181 | `After being created, a new channel or thread is created, and the user and support team are pinged. \n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 182 | `The category or channel to create threads in can be set with ${getCommandMentionByName( |
| 183 | "settings/tickets" |
| 184 | )}\n` + |
| 185 | `When the ticket is resolved, anyone can run ${getCommandMentionByName( |
| 186 | "ticket/close" |
| 187 | )} (or click the button) to close it.\n` + |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 188 | `Running ${getCommandMentionByName("ticket/close")} again will delete the ticket.` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 189 | ) |
| 190 | .setEmoji("GUILD.TICKET.CLOSE") |
| 191 | .setStatus("Danger") |
| 192 | ) |
| 193 | .setTitle("Tickets") |
| 194 | .setDescription("Ticket system") |
| 195 | .setPageId(5), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 196 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 197 | .setEmbed( |
| 198 | new EmojiEmbed() |
| 199 | .setTitle("Tags") |
| 200 | .setDescription( |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 201 | "Nucleus allows you to create tags, which allow a message to be sent when a specific tag is typed.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 202 | `Tags can be created with ${getCommandMentionByName( |
| 203 | "tags/create" |
| 204 | )}, and can be edited with ${getCommandMentionByName("tags/edit")}\n` + |
| 205 | `Tags can be deleted with ${getCommandMentionByName( |
| 206 | "tags/delete" |
| 207 | )}, and can be listed with ${getCommandMentionByName("tags/list")}\n` + |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 208 | `To use a tag, you can type ${getCommandMentionByName("tag")}, followed by the tag to send` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 209 | ) |
| 210 | .setEmoji("PUNISH.NICKNAME.RED") |
| 211 | .setStatus("Danger") |
| 212 | ) |
| 213 | .setTitle("Tags") |
| 214 | .setDescription("Tag system") |
| 215 | .setPageId(6), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 216 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 217 | .setEmbed( |
| 218 | new EmojiEmbed() |
| 219 | .setTitle("Premium") |
| 220 | .setDescription( |
PineaFan | d471ccd | 2023-01-26 20:48:40 +0000 | [diff] [blame] | 221 | "Nucleus Premium allows you to use extra features in your server, which are useful but not essential.\n" + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 222 | "**No currently free commands will become premium features.**\n" + |
| 223 | "Premium features include creating ticket transcripts and attachment logs.\n\n" + |
| 224 | "Premium can be purchased in [our server](https://discord.gg/bPaNnxe) in the subscriptions page" // TODO: add a table graphic |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 225 | ) |
TheCodedProf | 1c3ad3c | 2023-01-25 17:58:36 -0500 | [diff] [blame] | 226 | .setEmoji("NUCLEUS.PREMIUM") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 227 | .setStatus("Danger") |
| 228 | ) |
| 229 | .setTitle("Premium") |
| 230 | .setDescription("Premium features") |
| 231 | .setPageId(7) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 232 | ]; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 233 | |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 234 | const publicFilter = async (component: MessageComponentInteraction) => { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 235 | return (component.member as Discord.GuildMember).permissions.has("ManageGuild"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 236 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 237 | |
| 238 | let selectPaneOpen = false; |
| 239 | |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 240 | let cancelled = false; |
| 241 | let timedOut = false; |
| 242 | while (!cancelled && !timedOut) { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 243 | let selectPane: ActionRowBuilder<Discord.StringSelectMenuBuilder | ButtonBuilder>[] = []; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 244 | |
| 245 | if (selectPaneOpen) { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 246 | const options: Discord.StringSelectMenuOptionBuilder[] = []; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 247 | pages.forEach((embed) => { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 248 | options.push( |
| 249 | new Discord.StringSelectMenuOptionBuilder() |
| 250 | .setLabel(embed.title) |
| 251 | .setValue(embed.pageId.toString()) |
| 252 | .setDescription(embed.description || "") |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 253 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 254 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 255 | selectPane = [ |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 256 | new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents([ |
| 257 | new Discord.StringSelectMenuBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 258 | .addOptions(options) |
| 259 | .setCustomId("page") |
| 260 | .setMaxValues(1) |
| 261 | .setPlaceholder("Choose a page...") |
| 262 | ]) |
| 263 | ]; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 264 | } |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 265 | const components: ActionRowBuilder<ButtonBuilder | Discord.StringSelectMenuBuilder>[] = selectPane.concat([ |
| 266 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 267 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 268 | .setCustomId("left") |
| 269 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 270 | .setStyle(ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 271 | .setDisabled(page === 0), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 272 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 273 | .setCustomId("select") |
| 274 | .setEmoji(getEmojiByName("CONTROL.MENU", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 275 | .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 276 | .setDisabled(false), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 277 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 278 | .setCustomId("right") |
| 279 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 280 | .setStyle(ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 281 | .setDisabled(page === pages.length - 1) |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 282 | ) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 283 | ]); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 284 | if (interaction) { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 285 | const em = new Discord.EmbedBuilder(pages[page]!.embed); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 286 | em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 287 | await interaction.editReply({ |
| 288 | embeds: [em], |
| 289 | components: components |
| 290 | }); |
| 291 | } else { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 292 | const em = new Discord.EmbedBuilder(pages[page]!.embed); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 293 | em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 294 | (await m.edit({ |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 295 | embeds: [em], |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 296 | components: components |
| 297 | })) as Message; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 298 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 299 | let i; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 300 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 301 | i = await m.awaitMessageComponent({ |
| 302 | filter: interaction |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 303 | ? (i) => { |
| 304 | return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id; |
| 305 | } |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 306 | : publicFilter, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 307 | time: 300000 |
| 308 | }); |
| 309 | } catch (e) { |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 310 | timedOut = true; |
| 311 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 312 | } |
TheCodedProf | 267563a | 2023-01-21 17:00:57 -0500 | [diff] [blame] | 313 | await i.deferUpdate(); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 314 | if (!("customId" in i.component)) { |
| 315 | continue; |
| 316 | } else if (i.component.customId === "left") { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 317 | if (page > 0) page--; |
| 318 | selectPaneOpen = false; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 319 | } else if (i.component.customId === "right") { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 320 | if (page < pages.length - 1) page++; |
| 321 | selectPaneOpen = false; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 322 | } else if (i.component.customId === "select") { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 323 | selectPaneOpen = !selectPaneOpen; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame] | 324 | } else if (i.isStringSelectMenu() && i.component.customId === "page") { |
| 325 | page = parseInt(i.values[0]!); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 326 | selectPaneOpen = false; |
| 327 | } else { |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 328 | cancelled = true; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 329 | } |
| 330 | } |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 331 | if (timedOut) { |
| 332 | if (interaction) { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 333 | const em = new Discord.EmbedBuilder(pages[page]!.embed); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 334 | em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({ |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 335 | text: "Message timed out" |
| 336 | }); |
| 337 | await interaction.editReply({ |
| 338 | embeds: [em], |
| 339 | components: [] |
| 340 | }); |
| 341 | } else { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 342 | const em = new Discord.EmbedBuilder(pages[page]!.embed); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 343 | em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({ |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 344 | text: "Message timed out" |
| 345 | }); |
| 346 | await m.edit({ |
| 347 | embeds: [em], |
| 348 | components: [] |
| 349 | }); |
| 350 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 351 | } else { |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 352 | if (interaction) { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 353 | const em = new Discord.EmbedBuilder(pages[page]!.embed); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 354 | em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)); |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 355 | em.setFooter({ text: "Message closed" }); |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 356 | await interaction.editReply({ |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 357 | embeds: [em], |
| 358 | components: [] |
| 359 | }); |
| 360 | } else { |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 361 | await m.delete(); |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 362 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 363 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 364 | }; |