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"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 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() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 23 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 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() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 34 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 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" + |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 40 | "**Warning Logs:** Warnings like NSFW avatars and spam etc. that may require action by a server staff member. " + |
| 41 | "These go to to a separate staff notifications channel.\n\n" + |
| 42 | "A general log channel can be set with `/settings log`\n" + |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 43 | "A warning log channel can be set with `/settings warnings channel`" |
| 44 | ) |
| 45 | .setEmoji("NUCLEUS.LOGO") |
| 46 | .setStatus("Danger") |
| 47 | ).setTitle("Logging").setDescription("Logging, staff warning logs etc.").setPageId(1), |
| 48 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 49 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 50 | .setTitle("Moderation") |
| 51 | .setDescription( |
| 52 | "Nucleus has a number of commands that can be used to moderate your server.\n" + |
| 53 | "These commands are all found under `/mod`, and they include:\n" + |
| 54 | `**${getEmojiByName("PUNISH.WARN.YELLOW")} Warn:** The user is warned (via DM) that they violated server rules.\n` + |
| 55 | `**${getEmojiByName("PUNISH.CLEARHISTORY")} Clear:** Some messages from a user are deleted in a channel.\n` + |
| 56 | `**${getEmojiByName("PUNISH.MUTE.YELLOW")} Mute:** The user is unable to send messages or join voice chats.\n` + |
| 57 | `**${getEmojiByName("PUNISH.MUTE.GREEN")} Unmute:** The user is able to send messages in the server.\n` + |
| 58 | `**${getEmojiByName("PUNISH.KICK.RED")} Kick:** The user is removed from the server.\n` + |
| 59 | `**${getEmojiByName("PUNISH.SOFTBAN")} Softban:** Kicks the user, deleting their messages from every channel.\n` + |
| 60 | `**${getEmojiByName("PUNISH.BAN.RED")} Ban:** The user is removed from the server, and they are unable to rejoin.\n` + |
| 61 | `**${getEmojiByName("PUNISH.BAN.GREEN")} Unban:** The user is able to rejoin the server.` |
| 62 | ) |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 63 | .setEmoji("NUCLEUS.LOGO") |
| 64 | .setStatus("Danger") |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 65 | ).setTitle("Moderation").setDescription("Basic moderation commands").setPageId(2), |
| 66 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 67 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 68 | .setTitle("Verify") |
| 69 | .setDescription( |
| 70 | "Nucleus has a verification system that allows users to prove they aren't bots.\n" + |
| 71 | "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" + |
| 72 | "After the user complete's the CAPTCHA, they are given a role and can use the permissions accordingly.\n" + |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 73 | "You can set the role given with `/settings verify`" |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 74 | ) |
| 75 | .setEmoji("NUCLEUS.LOGO") |
| 76 | .setStatus("Danger") |
| 77 | ).setTitle("Verify").setDescription("Captcha verification system").setPageId(3), |
| 78 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 79 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 80 | .setTitle("Content Scanning") |
| 81 | .setDescription( |
| 82 | "Nucleus has a content scanning system that automatically scans links and images sent by users.\n" + |
| 83 | "Nucleus can detect, delete, and punish users for sending NSFW content, or links to scam or adult sites.\n" + |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 84 | "You can set the threshold for this in `/settings automation`" // TODO |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 85 | ) |
| 86 | .setEmoji("NUCLEUS.LOGO") |
| 87 | .setStatus("Danger") |
| 88 | ).setTitle("Content Scanning").setDescription("Content (NSFW, malware, scams) scanning").setPageId(4), |
| 89 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 90 | .setEmbed(new EmojiEmbed() |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 91 | .setTitle("Tickets") |
| 92 | .setDescription( |
| 93 | "Nucleus has a ticket system that allows users to create tickets and have a support team respond to them.\n" + |
| 94 | "Tickets can be created with `/ticket create` and a channel is created, pinging the user and support role.\n" + |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 95 | "When the ticket is resolved, anyone can run `/ticket close` (or click the button) to close it.\n" + |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 96 | "Running `/ticket close` again will delete the ticket." |
| 97 | ) |
| 98 | .setEmoji("NUCLEUS.LOGO") |
| 99 | .setStatus("Danger") |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 100 | ).setTitle("Tickets").setDescription("Ticket system").setPageId(5), |
| 101 | new Embed() |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 102 | .setEmbed(new EmojiEmbed() |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 103 | .setTitle("Tags") |
| 104 | .setDescription( |
| 105 | "Add a tag system to your server with the `/tag` and `/tags` commands.\n" + |
| 106 | "To create a tag, type `/tags create <tag name> <tag content>`.\n" + |
| 107 | "Tag names and content can be edited with `/tags edit`.\n" + |
| 108 | "To delete a tag, type `/tags delete <tag name>`.\n" + |
| 109 | "To view all tags, type `/tags list`.\n" |
| 110 | ) |
| 111 | .setEmoji("NUCLEUS.LOGO") |
| 112 | .setStatus("Danger") |
| 113 | ).setTitle("Tags").setDescription("Tag system").setPageId(6) |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 114 | ] |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 115 | let m; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 116 | if (interaction) { |
| 117 | m = await interaction.reply({embeds: [ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 118 | new EmojiEmbed() |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 119 | .setTitle("Welcome") |
| 120 | .setDescription(`One moment...`) |
| 121 | .setStatus("Danger") |
| 122 | .setEmoji("NUCLEUS.LOADING") |
| 123 | ], fetchReply: true, ephemeral: true}); |
| 124 | } else { |
| 125 | m = await c.send({embeds: [ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 126 | new EmojiEmbed() |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 127 | .setTitle("Welcome") |
| 128 | .setDescription(`One moment...`) |
| 129 | .setStatus("Danger") |
| 130 | .setEmoji("NUCLEUS.LOADING") |
| 131 | ], fetchReply: true }); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 132 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 133 | let page = 0; |
| 134 | |
| 135 | let f = async (component) => { |
| 136 | return (component.member as Discord.GuildMember).permissions.has("MANAGE_GUILD"); |
| 137 | } |
| 138 | |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 139 | let selectPaneOpen = false; |
| 140 | |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 141 | while (true) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 142 | let selectPane = [] |
| 143 | |
| 144 | if (selectPaneOpen) { |
| 145 | let options = []; |
| 146 | pages.forEach(embed => { |
| 147 | options.push(new SelectMenuOption({ |
| 148 | label: embed.title, |
| 149 | value: embed.pageId.toString(), |
| 150 | description: embed.description || "", |
| 151 | })) |
| 152 | }) |
| 153 | selectPane = [new MessageActionRow().addComponents([ |
| 154 | new Discord.MessageSelectMenu() |
| 155 | .addOptions(options) |
| 156 | .setCustomId("page") |
| 157 | .setMaxValues(1) |
| 158 | .setPlaceholder("Choose a page...") |
| 159 | ])] |
| 160 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 161 | let components = selectPane.concat([new MessageActionRow().addComponents([ |
| 162 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0), |
| 163 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(false), |
| 164 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1), |
| 165 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER") |
| 166 | ])]) |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 167 | if (interaction) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 168 | let em = new Discord.MessageEmbed(pages[page].embed) |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 169 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 170 | await interaction.editReply({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 171 | embeds: [em], |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 172 | components: components |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 173 | }); |
| 174 | } else { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 175 | let em = new Discord.MessageEmbed(pages[page].embed) |
| 176 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 177 | await m.edit({ |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 178 | embeds: [em], |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 179 | components: components, |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 180 | fetchReply: true |
| 181 | }); |
| 182 | } |
| 183 | let i |
| 184 | try { |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 185 | i = await m.awaitMessageComponent({filter: interaction ? () => { return true } : f, time: 300000}); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 186 | } catch(e) { break } |
| 187 | i.deferUpdate() |
| 188 | if (i.component.customId == "left") { |
| 189 | if (page > 0) page--; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 190 | selectPaneOpen = false; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 191 | } else if (i.component.customId == "right") { |
| 192 | if (page < pages.length - 1) page++; |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 193 | selectPaneOpen = false; |
| 194 | } else if (i.component.customId == "select") { |
| 195 | selectPaneOpen = !selectPaneOpen; |
| 196 | } else if (i.component.customId == "page") { |
| 197 | page = parseInt(i.values[0]); |
| 198 | selectPaneOpen = false; |
| 199 | } else { |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 200 | if (interaction) { |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 201 | let em = new Discord.MessageEmbed(pages[page].embed) |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 202 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message closed"); |
| 203 | interaction.editReply({embeds: [em], components: [new MessageActionRow().addComponents([ |
| 204 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 205 | 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] | 206 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true), |
| 207 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true) |
| 208 | ])], fetchReply: true}); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 209 | } else { |
| 210 | m.delete(); |
| 211 | } |
| 212 | return; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | if (interaction) { |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 216 | let em = new Discord.MessageEmbed(pages[page]) |
| 217 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message timed out"); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 218 | await interaction.editReply({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 219 | embeds: [em], |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 220 | components: [new MessageActionRow().addComponents([ |
| 221 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 222 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 223 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true), |
| 224 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true) |
| 225 | ])] |
| 226 | }); |
| 227 | } else { |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 228 | let em = new Discord.MessageEmbed(pages[page]) |
| 229 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page) + " | Message timed out"); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 230 | await m.edit({ |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 231 | embeds: [em], |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 232 | components: [new MessageActionRow().addComponents([ |
| 233 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ea06304 | 2022-05-19 19:08:44 +0100 | [diff] [blame] | 234 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle("SECONDARY").setDisabled(true), |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 235 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true), |
| 236 | new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true) |
| 237 | ])] |
| 238 | }); |
| 239 | } |
| 240 | } |