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