pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 1 | import { SelectMenuOption } from '@discordjs/builders'; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 2 | import Discord, { MessageActionRow, MessageButton } from "discord.js"; |
| 3 | import generateEmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 4 | import getEmojiByName from "../utils/getEmojiByName.js"; |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 5 | import createPageIndicator from "../utils/createPageIndicator.js"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 6 | |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 7 | class Embed { |
| 8 | embed: Discord.MessageEmbed; |
| 9 | title: string; |
| 10 | description: string = ""; |
| 11 | pageId: number = 0; |
| 12 | setEmbed(embed: Discord.MessageEmbed) { this.embed = embed; return this; } |
| 13 | setTitle(title: string) { this.title = title; return this; } |
| 14 | setDescription(description: string) { this.description = description; return this; } |
| 15 | setPageId(pageId: number) { this.pageId = pageId; return this; } |
| 16 | } |
| 17 | |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 18 | export default async (guild, interaction?) => { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 19 | let c = guild.publicUpdatesChannel ? guild.publicUpdatesChannel : guild.systemChannel; |
| 20 | c = c ? c : guild.channels.cache.find(ch => ch.type === "GUILD_TEXT" && ch.permissionsFor(guild.roles.everyone).has("SEND_MESSAGES") && ch.permissionsFor(guild.me).has("EMBED_LINKS")); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 21 | let pages = [ |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 22 | new Embed() |
| 23 | .setEmbed(new generateEmojiEmbed() |
| 24 | .setTitle("Welcome to Nucleus") |
| 25 | .setDescription( |
| 26 | "Thanks for adding Nucleus to your server\n\n" + |
| 27 | "On the next few pages you can find instructions on getting started, and commands you may want to set up\n\n" + |
| 28 | "If you need support, have questions or want features, you can let us know in [Clicks](https://discord.gg/bPaNnxe)" |
| 29 | ) |
| 30 | .setEmoji("NUCLEUS.LOGO") |
| 31 | .setStatus("Danger") |
| 32 | ).setTitle("Welcome").setDescription("About Nucleus").setPageId(0), |
| 33 | new Embed() |
| 34 | .setEmbed(new generateEmojiEmbed() |
| 35 | .setTitle("Logging") |
| 36 | .setDescription( |
| 37 | "Nucleus can log server events and keep you informed with what content is being posted to your server.\n" + |
| 38 | "We have 2 different types of logs, which each can be configured to send to a channel of your choice:\n" + |
| 39 | "**General Logs:** These are events like kicks and channel changes etc.\n" + |
| 40 | "**Warning Logs:** Warnings like NSFW avatars and spam etc that may require action by a server staff member.\n\n" + |
| 41 | "A general log channel can be set with `/settings log channel`\n" + |
| 42 | "A warning log channel can be set with `/settings warnings channel`" |
| 43 | ) |
| 44 | .setEmoji("NUCLEUS.LOGO") |
| 45 | .setStatus("Danger") |
| 46 | ).setTitle("Logging").setDescription("Logging, staff warning logs etc.").setPageId(1), |
| 47 | new Embed() |
| 48 | .setEmbed(new generateEmojiEmbed() |
| 49 | .setTitle("Moderation") |
| 50 | .setDescription( |
| 51 | "Nucleus has a number of commands that can be used to moderate your server.\n" + |
| 52 | "These commands are all found under `/mod`, and they include:\n" + |
| 53 | `**${getEmojiByName("PUNISH.WARN.YELLOW")} Warn:** The user is warned (via DM) that they violated server rules.\n` + |
| 54 | `**${getEmojiByName("PUNISH.CLEARHISTORY")} Clear:** Some messages from a user are deleted in a channel.\n` + |
| 55 | `**${getEmojiByName("PUNISH.MUTE.YELLOW")} Mute:** The user is unable to send messages or join voice chats.\n` + |
| 56 | `**${getEmojiByName("PUNISH.MUTE.GREEN")} Unmute:** The user is able to send messages in the server.\n` + |
| 57 | `**${getEmojiByName("PUNISH.KICK.RED")} Kick:** The user is removed from the server.\n` + |
| 58 | `**${getEmojiByName("PUNISH.SOFTBAN")} Softban:** Kicks the user, deleting their messages from every channel.\n` + |
| 59 | `**${getEmojiByName("PUNISH.BAN.RED")} Ban:** The user is removed from the server, and they are unable to rejoin.\n` + |
| 60 | `**${getEmojiByName("PUNISH.BAN.GREEN")} Unban:** The user is able to rejoin the server.` |
| 61 | ) |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 62 | .setEmoji("NUCLEUS.LOGO") |
| 63 | .setStatus("Danger") |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 64 | ).setTitle("Moderation").setDescription("Basic moderation commands").setPageId(2), |
| 65 | new Embed() |
| 66 | .setEmbed(new generateEmojiEmbed() |
| 67 | .setTitle("Verify") |
| 68 | .setDescription( |
| 69 | "Nucleus has a verification system that allows users to prove they aren't bots.\n" + |
| 70 | "This is done by running `/verify` which sends a message only the user can see, giving them a link to a CAPTCHA to verify.\n" + |
| 71 | "After the user complete's the CAPTCHA, they are given a role and can use the permissions accordingly.\n" + |
| 72 | "You can set the role given with `/settings verify role`" |
| 73 | ) |
| 74 | .setEmoji("NUCLEUS.LOGO") |
| 75 | .setStatus("Danger") |
| 76 | ).setTitle("Verify").setDescription("Captcha verification system").setPageId(3), |
| 77 | new Embed() |
| 78 | .setEmbed(new generateEmojiEmbed() |
| 79 | .setTitle("Content Scanning") |
| 80 | .setDescription( |
| 81 | "Nucleus has a content scanning system that automatically scans links and images sent by users.\n" + |
| 82 | "Nucleus can detect, delete, and punish users for sending NSFW content, or links to scam or adult sites.\n" + |
| 83 | "You can set the threshold for this in `/settings automation`" |
| 84 | ) |
| 85 | .setEmoji("NUCLEUS.LOGO") |
| 86 | .setStatus("Danger") |
| 87 | ).setTitle("Content Scanning").setDescription("Content (NSFW, malware, scams) scanning").setPageId(4), |
| 88 | new Embed() |
| 89 | .setEmbed(new generateEmojiEmbed() |
| 90 | .setTitle("Tickets") |
| 91 | .setDescription( |
| 92 | "Nucleus has a ticket system that allows users to create tickets and have a support team respond to them.\n" + |
| 93 | "Tickets can be created with `/ticket create` and a channel is created, pinging the user and support role.\n" + |
| 94 | "When the ticket is resolved, anyone can run `/ticket close` to archive it.\n" + |
| 95 | "Running `/ticket close` again will delete the ticket." |
| 96 | ) |
| 97 | .setEmoji("NUCLEUS.LOGO") |
| 98 | .setStatus("Danger") |
| 99 | ).setTitle("Tickets").setDescription("Ticket system").setPageId(5) |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 100 | ] |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 101 | let m; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 102 | if (interaction) { |
| 103 | m = await interaction.reply({embeds: [ |
| 104 | new generateEmojiEmbed() |
| 105 | .setTitle("Welcome") |
| 106 | .setDescription(`One moment...`) |
| 107 | .setStatus("Danger") |
| 108 | .setEmoji("NUCLEUS.LOADING") |
| 109 | ], fetchReply: true, ephemeral: true}); |
| 110 | } else { |
| 111 | m = await c.send({embeds: [ |
| 112 | new generateEmojiEmbed() |
| 113 | .setTitle("Welcome") |
| 114 | .setDescription(`One moment...`) |
| 115 | .setStatus("Danger") |
| 116 | .setEmoji("NUCLEUS.LOADING") |
| 117 | ], fetchReply: true }); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 118 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 119 | let page = 0; |
| 120 | |
| 121 | let f = async (component) => { |
| 122 | return (component.member as Discord.GuildMember).permissions.has("MANAGE_GUILD"); |
| 123 | } |
| 124 | |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 125 | let selectPaneOpen = false; |
| 126 | |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 127 | while (true) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 128 | let selectPane = [] |
| 129 | |
| 130 | if (selectPaneOpen) { |
| 131 | let options = []; |
| 132 | pages.forEach(embed => { |
| 133 | options.push(new SelectMenuOption({ |
| 134 | label: embed.title, |
| 135 | value: embed.pageId.toString(), |
| 136 | description: embed.description || "", |
| 137 | })) |
| 138 | }) |
| 139 | selectPane = [new MessageActionRow().addComponents([ |
| 140 | new Discord.MessageSelectMenu() |
| 141 | .addOptions(options) |
| 142 | .setCustomId("page") |
| 143 | .setMaxValues(1) |
| 144 | .setPlaceholder("Choose a page...") |
| 145 | ])] |
| 146 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 147 | if (interaction) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 148 | let em = new Discord.MessageEmbed(pages[page].embed) |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 149 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 150 | await interaction.editReply({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 151 | embeds: [em], |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 152 | components: selectPane.concat([new MessageActionRow().addComponents([ |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 153 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 154 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(false), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 155 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1), |
| 156 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER") |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 157 | ])]), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 158 | fetchReply: true |
| 159 | }); |
| 160 | } else { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 161 | let em = new Discord.MessageEmbed(pages[page].embed) |
| 162 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 163 | await m.edit({ |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 164 | embeds: [em], |
| 165 | components: selectPane.concat([new MessageActionRow().addComponents([ |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 166 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 167 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(false), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 168 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1), |
| 169 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER") |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 170 | ])]), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 171 | fetchReply: true |
| 172 | }); |
| 173 | } |
| 174 | let i |
| 175 | try { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 176 | i = await m.awaitMessageComponent({filter: interaction ? () => { return true } : f, time: 600000}); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 177 | } catch(e) { break } |
| 178 | i.deferUpdate() |
| 179 | if (i.component.customId == "left") { |
| 180 | if (page > 0) page--; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 181 | selectPaneOpen = false; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 182 | } else if (i.component.customId == "right") { |
| 183 | if (page < pages.length - 1) page++; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 184 | selectPaneOpen = false; |
| 185 | } else if (i.component.customId == "select") { |
| 186 | selectPaneOpen = !selectPaneOpen; |
| 187 | } else if (i.component.customId == "page") { |
| 188 | page = parseInt(i.values[0]); |
| 189 | selectPaneOpen = false; |
| 190 | } else { |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 191 | if (interaction) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 192 | let em = new Discord.MessageEmbed(pages[page].embed) |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 193 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message closed"); |
| 194 | interaction.editReply({embeds: [em], components: [new MessageActionRow().addComponents([ |
| 195 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 196 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(true), |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 197 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true), |
| 198 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true) |
| 199 | ])], fetchReply: true}); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 200 | } else { |
| 201 | m.delete(); |
| 202 | } |
| 203 | return; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | if (interaction) { |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 207 | let em = new Discord.MessageEmbed(pages[page]) |
| 208 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message timed out"); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 209 | await interaction.editReply({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 210 | embeds: [em], |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 211 | components: [new MessageActionRow().addComponents([ |
| 212 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 213 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 214 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true), |
| 215 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true) |
| 216 | ])] |
| 217 | }); |
| 218 | } else { |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 219 | let em = new Discord.MessageEmbed(pages[page]) |
| 220 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message timed out"); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 221 | await m.edit({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 222 | embeds: [em], |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 223 | components: [new MessageActionRow().addComponents([ |
| 224 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 225 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 226 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true), |
| 227 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true) |
| 228 | ])] |
| 229 | }); |
| 230 | } |
| 231 | } |