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