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