guess who forgot to add files
diff --git a/src/automations/createModActionTicket.ts b/src/automations/createModActionTicket.ts
new file mode 100644
index 0000000..a4d549c
--- /dev/null
+++ b/src/automations/createModActionTicket.ts
@@ -0,0 +1,82 @@
+import Discord from 'discord.js';
+import readConfig from '../utils/readConfig.js'
+import generateEmojiEmbed from '../utils/generateEmojiEmbed.js'
+
+export async function create(guild: Discord.Guild, member: Discord.User, client) {
+ let config = await readConfig(guild.id);
+ // @ts-ignore
+ const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger
+ let overwrites = [{
+ id: member,
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+ type: "member"
+ }] as Discord.OverwriteResolvable[];
+ if (config.tickets.supportRole != null) {
+ overwrites.push({
+ id: guild.roles.cache.get(config.tickets.supportRole),
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+ type: "role"
+ })
+ }
+
+ let c;
+ try {
+ c = await guild.channels.create(member.username, {
+ type: "GUILD_TEXT",
+ topic: `${member.id} Active`,
+ parent: config.tickets.category,
+ nsfw: false,
+ permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]),
+ reason: "Creating ticket"
+ })
+ } catch (e) {
+ return null
+ }
+ try {
+ await c.send(
+ {
+ content: (`<@${member.id}>` + (config.tickets.supportRole != null ? ` • <@&${config.tickets.supportRole}>` : "")),
+ allowedMentions: {
+ users: [member.id],
+ roles: (config.tickets.supportRole != null ? [config.tickets.supportRole] : [])
+ }
+ }
+ )
+ await c.send({ embeds: [new generateEmojiEmbed()
+ .setTitle("New Ticket")
+ .setDescription(
+ `Ticket created by a Moderator\n` +
+ `**Support type:** Appeal submission\n` +
+ `**Ticket ID:** \`${c.id}\`\n` +
+ `Type \`/ticket close\` to archive this ticket.`,
+ )
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ]})
+ let data = {
+ meta:{
+ type: 'ticketCreate',
+ displayName: 'Ticket Created',
+ calculateType: true,
+ color: NucleusColors.green,
+ emoji: 'GUILD.TICKET.OPEN',
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(member.id, renderUser(member)),
+ created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ ticketChannel: entry(c.id, renderChannel(c)),
+ },
+ hidden: {
+ guild: guild.id
+ }
+ }
+ log(data, client);
+ } catch (e) { console.log(e); return null }
+ return c.id
+}
+
+export async function areTicketsEnabled(guild: string) {
+ let config = await readConfig(guild);
+ return config.tickets.enabled;
+}
\ No newline at end of file
diff --git a/src/automations/guide.ts b/src/automations/guide.ts
new file mode 100644
index 0000000..66c9eb0
--- /dev/null
+++ b/src/automations/guide.ts
@@ -0,0 +1,162 @@
+import Discord, { MessageActionRow, MessageButton } from "discord.js";
+import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../utils/getEmojiByName.js";
+
+export default async (guild, interaction?) => {
+ let c = guild.publicUpdatesChannel ? guild.publicUpdatesChannel : guild.systemChannel;
+ 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"));
+ let pages = [
+ new generateEmojiEmbed()
+ .setTitle("Welcome to Nucleus")
+ .setDescription(
+ "Thanks for adding Nucleus to your server\n\n" +
+ "On the next few pages you can find instructions on getting started, and commands you may want to set up\n\n" +
+ "If you need support, have questions or want features, you can let us know in [Clicks](https://discord.gg/bPaNnxe)"
+ )
+ .setEmoji("NUCLEUS.LOGO")
+ .setStatus("Danger"),
+ new generateEmojiEmbed()
+ .setTitle("Logging")
+ .setDescription(
+ "Nucleus can log server events and keep you informed with what content is being posted to your server.\n" +
+ "We have 2 different types of logs, which each can be configured to send to a channel of your choice:\n" +
+ "**General Logs:** These are events like kicks and channel changes etc.\n" +
+ "**Warning Logs:** Warnings like NSFW avatars and spam etc that may require action by a server staff member.\n\n" +
+ "A general log channel can be set with `/settings log channel`\n" +
+ "A warning log channel can be set with `/settings warnings channel`"
+ )
+ .setEmoji("NUCLEUS.LOGO")
+ .setStatus("Danger"),
+ new generateEmojiEmbed()
+ .setTitle("Moderation")
+ .setDescription(
+ "Nucleus has a number of commands that can be used to moderate your server.\n" +
+ "These commands are all found under `/mod`, and they include:\n" +
+ `**${getEmojiByName("PUNISH.WARN.YELLOW")} Warn:** The user is warned (via DM) that they violated server rules.\n` +
+ `**${getEmojiByName("PUNISH.CLEARHISTORY")} Clear:** Some messages from a user are deleted in a channel.\n` +
+ `**${getEmojiByName("PUNISH.MUTE.YELLOW")} Mute:** The user is unable to send messages or join voice chats.\n` +
+ `**${getEmojiByName("PUNISH.MUTE.GREEN")} Unmute:** The user is able to send messages in the server.\n` +
+ `**${getEmojiByName("PUNISH.KICK.RED")} Kick:** The user is removed from the server.\n` +
+ `**${getEmojiByName("PUNISH.SOFTBAN")} Softban:** Kicks the user, deleting their messages from every channel.\n` +
+ `**${getEmojiByName("PUNISH.BAN.RED")} Ban:** The user is removed from the server, and they are unable to rejoin.\n` +
+ `**${getEmojiByName("PUNISH.BAN.GREEN")} Unban:** The user is able to rejoin the server.\n`
+ )
+ .setEmoji("NUCLEUS.LOGO")
+ .setStatus("Danger"),
+ new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(
+ "Nucleus has a verification system that allows users to prove they aren't bots.\n" +
+ "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" +
+ "After the user complete's the CAPTCHA, they are given a role and can use the permissions accordingly.\n" +
+ "You can set the role given with `/settings verify role`"
+ )
+ .setEmoji("NUCLEUS.LOGO")
+ .setStatus("Danger"),
+ new generateEmojiEmbed()
+ .setTitle("Content Scanning")
+ .setDescription(
+ "Nucleus has a content scanning system that automatically scans links and images sent by users.\n" +
+ "Nucleus can detect, delete, and punish users for sending NSFW content, or links to scam or adult sites.\n" +
+ "You can set the threshold for this in `/settings automation`"
+ )
+ .setEmoji("NUCLEUS.LOGO")
+ .setStatus("Danger"),
+ new generateEmojiEmbed()
+ .setTitle("Tickets")
+ .setDescription(
+ "Nucleus has a ticket system that allows users to create tickets and have a support team respond to them.\n" +
+ "Tickets can be created with `/ticket create` and a channel is created, pinging the user and support role.\n" +
+ "When the ticket is resolved, anyone can run `/ticket close` to archive it.\n" +
+ "Running `/ticket close` again will delete the ticket."
+ )
+ .setEmoji("NUCLEUS.LOGO")
+ .setStatus("Danger")
+ ]
+ let m;
+ if (interaction) {
+ m = await interaction.reply({embeds: [
+ new generateEmojiEmbed()
+ .setTitle("Welcome")
+ .setDescription(`One moment...`)
+ .setStatus("Danger")
+ .setEmoji("NUCLEUS.LOADING")
+ ], fetchReply: true, ephemeral: true});
+ } else {
+ m = await c.send({embeds: [
+ new generateEmojiEmbed()
+ .setTitle("Welcome")
+ .setDescription(`One moment...`)
+ .setStatus("Danger")
+ .setEmoji("NUCLEUS.LOADING")
+ ], fetchReply: true });
+ }
+ let page = 0;
+
+ let f = async (component) => {
+ return (component.member as Discord.GuildMember).permissions.has("MANAGE_GUILD");
+ }
+
+ while (true) {
+ if (interaction) {
+ await interaction.editReply({
+ embeds: [pages[page].setFooter({text: `Page ${page + 1}/${pages.length}`})],
+ components: [new MessageActionRow().addComponents([
+ new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0),
+ new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1),
+ new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER")
+ ])],
+ fetchReply: true
+ });
+ } else {
+ await m.edit({
+ embeds: [pages[page].setFooter({text: `Page ${page + 1}/${pages.length}`})],
+ components: [new MessageActionRow().addComponents([
+ new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0),
+ new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1),
+ new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER")
+ ])],
+ fetchReply: true
+ });
+ }
+ let i
+ try {
+ i = await m.awaitMessageComponent({filter: interaction ? () => { return true } : f, componentType: "BUTTON", time: 600000});
+ } catch(e) { break }
+ i.deferUpdate()
+ if (i.component.customId == "left") {
+ if (page > 0) page--;
+ } else if (i.component.customId == "right") {
+ if (page < pages.length - 1) page++;
+ } else if (i.component.customId == "close") {
+ if (interaction) {
+ interaction.delete();
+ } else {
+ m.delete();
+ }
+ return;
+ } else {
+ await m.delete()
+ break;
+ }
+ }
+ if (interaction) {
+ await interaction.editReply({
+ embeds: [pages[page].setFooter({text: `Page ${page + 1}/${pages.length} | Message timed out`})],
+ components: [new MessageActionRow().addComponents([
+ new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true),
+ new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true),
+ new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true)
+ ])]
+ });
+ } else {
+ await m.edit({
+ embeds: [pages[page].setFooter({text: `Page ${page + 1}/${pages.length} | Message timed out`})],
+ components: [new MessageActionRow().addComponents([
+ new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(true),
+ new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(true),
+ new MessageButton().setCustomId("close").setEmoji(getEmojiByName("CONTROL.CROSS", "id")).setStyle("DANGER").setDisabled(true)
+ ])]
+ });
+ }
+}
diff --git a/src/automations/roleMenu.ts b/src/automations/roleMenu.ts
new file mode 100644
index 0000000..2412c70
--- /dev/null
+++ b/src/automations/roleMenu.ts
@@ -0,0 +1,148 @@
+import { Message, MessageButton } from "discord.js";
+import readConfig from '../utils/readConfig.js'
+import generateEmojiEmbed from '../utils/generateEmojiEmbed.js'
+import { MessageActionRow, MessageSelectMenu } from 'discord.js';
+import getEmojiByName from "../utils/getEmojiByName.js";
+
+export async function callback(interaction) {
+ let config = await readConfig(interaction.guild.id);
+ if (!config.roleMenu.enabled) await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setDescription("Self roles are currently disabled. Please contact a staff member or try again later.")
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ], ephemeral: true})
+ if (config.roleMenu.options.length === 0) await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setDescription("There are no roles available. Please contact a staff member or try again later.")
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ], ephemeral: true})
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setDescription("Loading...")
+ .setStatus("Success")
+ .setEmoji("NUCLEUS.LOADING")
+ ], ephemeral: true})
+ let m;
+ if (config.roleMenu.allowWebUI) {
+ let code = ""
+ let length = 5
+ let itt = 0
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ while (true) {
+ itt += 1
+ code = ""
+ for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); }
+ if (code in interaction.client.roleMenu) continue;
+ if (itt > 1000) {
+ itt = 0
+ length += 1
+ continue;
+ }
+ break;
+ }
+ interaction.client.roleMenu[code] = {
+ guild: interaction.guild.id,
+ guildIcon: interaction.guild.iconURL({format: "png"}),
+ user: interaction.member.user.id,
+ interaction: interaction
+ };
+ m = await interaction.editReply({
+ embeds: [new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setDescription("Select how to choose your roles")
+ .setStatus("Success")
+ .setEmoji("GUILD.GREEN")
+ ], components: [new MessageActionRow().addComponents([
+ new MessageButton()
+ .setLabel("Online")
+ .setStyle("LINK")
+ .setURL(`https://clicksminuteper.net/nuclues/rolemenu?code=${code}`),
+ new MessageButton()
+ .setLabel("Manual")
+ .setStyle("PRIMARY")
+ .setCustomId("manual")
+ ])]
+ })
+ }
+ let component;
+ try { component = await (m as Message).awaitMessageComponent({time: 2.5 * 60 * 1000});
+ } catch (e) { return }
+ component.deferUpdate()
+ let rolesToAdd = []
+ for (let i = 0; i < config.roleMenu.options.length; i++) {
+ let object = config.roleMenu.options[i];
+ let m = await interaction.editReply({
+ embeds: [
+ new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setEmoji("GUILD.GREEN")
+ .setDescription(`**${object.name}**` + (object.description ? `\n${object.description}` : ``) +
+ `\n\nSelect ${object.min}` + (object.min != object.max ? ` to ${object.max}` : ``) + ` role${object.max == 1 ? '' : 's'} to add.`)
+ .setStatus("Success")
+ .setFooter({text: `Step ${i + 1}/${config.roleMenu.options.length}`})
+ ],
+ components: [
+ new MessageActionRow().addComponents([
+ new MessageButton()
+ .setLabel("Cancel")
+ .setStyle("DANGER")
+ .setCustomId("cancel")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ].concat(object.min == 0 ? [
+ new MessageButton()
+ .setLabel("Skip")
+ .setStyle("SECONDARY")
+ .setCustomId("skip")
+ .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
+ ] : []))
+ ].concat([new MessageActionRow().addComponents([new MessageSelectMenu()
+ .setPlaceholder(`${object.name}`)
+ .setCustomId("rolemenu")
+ .setMinValues(object.min)
+ .setMaxValues(object.max)
+ .setOptions(object.options.map(o => { return {label: o.name, description: o.description, value: o.role} }))
+ ])])
+ });
+ let component;
+ try {
+ component = await (m as Message).awaitMessageComponent({time: 2.5 * 60 * 1000});
+ } catch (e) {
+ return
+ }
+ component.deferUpdate()
+ if (component.customId == "rolemenu") {
+ rolesToAdd = rolesToAdd.concat(component.values)
+ } else if (component.customId == "cancel") {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setDescription("Cancelled. No changes were made.")
+ .setStatus("Danger")
+ .setEmoji("GUILD.RED")
+ ], components: []})
+ }
+ }
+ let rolesToRemove = config.roleMenu.options.map(o => o.options.map(o => o.role)).flat()
+ let memberRoles = interaction.member.roles.cache.map(r => r.id)
+ rolesToRemove = rolesToRemove.filter(r => memberRoles.includes(r)).filter(r => !rolesToAdd.includes(r))
+ rolesToAdd = rolesToAdd.filter(r => !memberRoles.includes(r))
+ try {
+ await interaction.member.roles.remove(rolesToRemove)
+ await interaction.member.roles.add(rolesToAdd)
+ } catch (e) {
+ return await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setDescription("Something went wrong and your roles were not added. Please contact a staff member or try again later.")
+ .setStatus("Danger")
+ .setEmoji("GUILD.RED")
+ ]})
+ }
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Roles")
+ .setDescription("Roles have been added. You may close this message.")
+ .setStatus("Success")
+ .setEmoji("GUILD.GREEN")
+ ], components: []})
+ return
+}
diff --git a/src/automations/tickets/create.ts b/src/automations/tickets/create.ts
new file mode 100644
index 0000000..1fd743b
--- /dev/null
+++ b/src/automations/tickets/create.ts
@@ -0,0 +1,202 @@
+import Discord, { MessageActionRow, MessageButton } from "discord.js";
+import { tickets, toHexArray } from "../../utils/calculate.js";
+import readConfig from "../../utils/readConfig.js";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+
+function capitalize(s: string) {
+ s = s.replace(/([A-Z])/g, ' $1');
+ return s.length < 3 ? s.toUpperCase() : s[0].toUpperCase() + s.slice(1).toLowerCase();
+}
+
+export default async function (interaction) {
+ // @ts-ignore
+ const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = interaction.client.logger
+
+ let config = await readConfig(interaction.guild.id);
+ if (!config.tickets.enabled || !config.tickets.category) {
+ return await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Tickets are disabled")
+ .setDescription("Please enable tickets in the configuration to use this command.")
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ], ephemeral: true});
+ }
+ let category = interaction.guild.channels.cache.get(config.tickets.category) as Discord.CategoryChannel;
+ let count = 0;
+ category.children.forEach(element => {
+ if (!(element.type == "GUILD_TEXT")) return;
+ if ((element as Discord.TextChannel).topic.includes(`${interaction.member.user.id}`)) {
+ if ((element as Discord.TextChannel).topic.endsWith("Active")) {
+ count++;
+ }
+ }
+ });
+ if (count >= config.tickets.maxTickets) {
+ return await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Create Ticket")
+ .setDescription(`You have reached the maximum amount of tickets (${config.tickets.maxTickets}). Please close one of your active tickets before creating a new one.`)
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ], ephemeral: true});
+ }
+ let ticketTypes;
+ let custom = false
+ if (config.tickets.customTypes) { ticketTypes = config.tickets.customTypes; custom = true }
+ else if (config.tickets.types) ticketTypes = toHexArray(config.tickets.types, tickets);
+ else ticketTypes = [];
+ let chosenType;
+ let splitFormattedTicketTypes = [];
+ if (ticketTypes.length > 0) {
+ let formattedTicketTypes = [];
+ formattedTicketTypes = ticketTypes.map(type => {
+ if (custom) {
+ return new MessageButton()
+ .setLabel(type)
+ .setStyle("PRIMARY")
+ .setCustomId(type)
+ } else {
+ return new MessageButton()
+ .setLabel(capitalize(type))
+ .setStyle("PRIMARY")
+ .setCustomId(type)
+ .setEmoji(getEmojiByName(("TICKETS." + type.toString().toUpperCase()), "id"));
+ }
+ });
+ for (let i = 0; i < formattedTicketTypes.length; i += 4) {
+ splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 4)));
+ }
+ let m = await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Create Ticket")
+ .setDescription("Select a ticket type")
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ], ephemeral: true, fetchReply: true, components: splitFormattedTicketTypes});
+ let component;
+ try {
+ component = await (m as Discord.Message).awaitMessageComponent({time: 2.5 * 60 * 1000});
+ } catch (e) {
+ return;
+ }
+ chosenType = component.customId;
+ splitFormattedTicketTypes = [];
+ formattedTicketTypes = [];
+ formattedTicketTypes = ticketTypes.map(type => {
+ if (custom) {
+ return new MessageButton()
+ .setLabel(type)
+ .setStyle(chosenType == type ? "SUCCESS" : "SECONDARY")
+ .setCustomId(type)
+ .setDisabled(true)
+ } else {
+ return new MessageButton()
+ .setLabel(capitalize(type))
+ .setStyle(chosenType == type ? "SUCCESS" : "SECONDARY")
+ .setCustomId(type)
+ .setEmoji(getEmojiByName(("TICKETS." + type.toString().toUpperCase()), "id"))
+ .setDisabled(true)
+ }
+ });
+ for (let i = 0; i < formattedTicketTypes.length; i += 4) {
+ splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 4)));
+ }
+ component.update({embeds: [new generateEmojiEmbed()
+ .setTitle("Create Ticket")
+ .setDescription("Select a ticket type")
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ], components: splitFormattedTicketTypes});
+ } else {
+ chosenType = null
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Create Ticket")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ], ephemeral: true, components: splitFormattedTicketTypes})
+ }
+ let overwrites = [{
+ id: interaction.member,
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+ type: "member"
+ }] as Discord.OverwriteResolvable[];
+ if (config.tickets.supportRole != null) {
+ overwrites.push({
+ id: interaction.guild.roles.cache.get(config.tickets.supportRole),
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+ type: "role"
+ })
+ }
+
+ let c;
+ try {
+ c = await interaction.guild.channels.create(interaction.member.user.username, {
+ type: "GUILD_TEXT",
+ topic: `${interaction.member.user.id} Active`,
+ parent: config.tickets.category,
+ nsfw: false,
+ permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]),
+ reason: "Creating ticket"
+ })
+ } catch (e) {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Create Ticket")
+ .setDescription("Failed to create ticket")
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ]});
+ }
+ try {
+ await c.send(
+ {
+ content: (`<@${interaction.member.user.id}>` + (config.tickets.supportRole != null ? ` • <@&${config.tickets.supportRole}>` : "")),
+ allowedMentions: {
+ users: [(interaction.member as Discord.GuildMember).id],
+ roles: (config.tickets.supportRole != null ? [config.tickets.supportRole] : [])
+ }
+ }
+ )
+ let content = interaction.options ? interaction.options.getString("message") || "" : "";
+ if (content) content = `**Message:**\n> ${content}\n`;
+ let emoji = custom ? "" : getEmojiByName("TICKETS." + chosenType.toUpperCase());
+ await c.send({ embeds: [new generateEmojiEmbed()
+ .setTitle("New Ticket")
+ .setDescription(
+ `Ticket created by <@${interaction.member.user.id}>\n` +
+ `**Support type:** ${chosenType != null ? (emoji) + " " + capitalize(chosenType) : "General"}\n` +
+ `**Ticket ID:** \`${c.id}\`\n${content}\n` +
+ `Type \`/ticket close\` to archive this ticket.`,
+ )
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ], components: [new MessageActionRow().addComponents([new MessageButton()
+ .setLabel("Close")
+ .setStyle("DANGER")
+ .setCustomId("closeticket")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ])]})
+ let data = {
+ meta:{
+ type: 'ticketCreate',
+ displayName: 'Ticket Created',
+ calculateType: true,
+ color: NucleusColors.green,
+ emoji: 'GUILD.TICKET.OPEN',
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ ticketChannel: entry(c.id, renderChannel(c)),
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ }
+ log(data, interaction.client);
+ } catch (e) { console.log(e)}
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Create Ticket")
+ .setDescription(`Ticket created. You can view it here: <#${c.id}>`)
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ], components: splitFormattedTicketTypes});
+}
\ No newline at end of file
diff --git a/src/automations/tickets/delete.ts b/src/automations/tickets/delete.ts
new file mode 100644
index 0000000..8feeb4b
--- /dev/null
+++ b/src/automations/tickets/delete.ts
@@ -0,0 +1,137 @@
+import Discord, { MessageButton, MessageActionRow } from "discord.js";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import readConfig from "../../utils/readConfig.js";
+
+export default async function (interaction) {
+ // @ts-ignore
+ const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = interaction.client.logger
+
+ let config = await readConfig(interaction.guild.id);
+ let channel = (interaction.channel as Discord.TextChannel)
+ if (config.tickets.category != channel.parent.id) {
+ return interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Close Ticket")
+ .setDescription("This ticket is not in your tickets category, so cannot be deleted.")
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ], ephemeral: true});
+ }
+ let status = channel.topic.split(" ")[1];
+ if (status == "Archived") {
+ interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Close Ticket")
+ .setDescription("This ticket will be deleted in 3 seconds.")
+ .setStatus("Danger")
+ .setEmoji("GUILD.TICKET.CLOSE")
+ ]});
+ setTimeout(async () => {
+ let data = {
+ meta:{
+ type: 'ticketClosed',
+ displayName: 'Ticket Closed',
+ calculateType: true,
+ color: NucleusColors.red,
+ emoji: 'GUILD.TICKET.CLOSE',
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
+ closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ closed: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ }
+ log(data, interaction.client);
+ interaction.channel.delete();
+ }, 3000);
+ return;
+ } else if (status == "Active") {
+ interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Close Ticket")
+ .setDescription("This ticket will be archived in 3 seconds.")
+ .setStatus("Warning")
+ .setEmoji("GUILD.TICKET.ARCHIVED")
+ ]});
+ setTimeout(async () =>{
+ channel.permissionsFor(await interaction.guild.members.fetch(channel.topic.split(" ")[0])).remove("VIEW_CHANNEL");
+ channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
+ let data = {
+ meta:{
+ type: 'ticketArchive',
+ displayName: 'Ticket Archived',
+ calculateType: true,
+ color: NucleusColors.yellow,
+ emoji: 'GUILD.TICKET.ARCHIVED',
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
+ archivedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ archived: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ ticketChannel: entry(channel.id, renderChannel(channel)),
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ }
+ log(data, interaction.client);
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Close Ticket")
+ .setDescription("This ticket has been archived.\nType `/ticket close` to delete it.")
+ .setStatus("Warning")
+ .setEmoji("GUILD.TICKET.ARCHIVED") // TODO:[Premium] Add a transcript option ||\----/|| <- the bridge we will cross when we come to it
+ ], components: [new MessageActionRow().addComponents([new MessageButton()
+ .setLabel("Close")
+ .setStyle("DANGER")
+ .setCustomId("closeticket")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ])]});
+ }, 3000);
+ return;
+ }
+}
+
+async function purgeByUser(member, guild) {
+ let config = await readConfig(guild.id);
+ if (!config.tickets.category) return;
+ let tickets = guild.channels.cache.get(config.tickets.category);
+ let ticketChannels = tickets.children;
+ let deleted = 0
+ ticketChannels.forEach(element => {
+ if (element.type != "GUILD_TEXT") return;
+ if (element.topic.split(" ")[0] == member) {
+ element.delete();
+ deleted++
+ }
+ });
+ if (deleted) {
+ try {
+ const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger
+ let data = {
+ meta:{
+ type: 'ticketPurge',
+ displayName: 'Tickets Purged',
+ calculateType: true,
+ color: NucleusColors.red,
+ emoji: 'GUILD.TICKET.DELETE',
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(member, renderUser(member)),
+ deletedBy: entry(null, "Member left server"),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ ticketsDeleted: deleted,
+ },
+ hidden: {
+ guild: guild.id
+ }
+ }
+ log(data, member.client);
+ } catch {}
+ }
+}
+
+export { purgeByUser }
\ No newline at end of file
diff --git a/src/automations/verify.ts b/src/automations/verify.ts
new file mode 100644
index 0000000..80087a4
--- /dev/null
+++ b/src/automations/verify.ts
@@ -0,0 +1,129 @@
+import Discord, { CommandInteraction, GuildMember } from "discord.js";
+import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
+import readConfig from "../utils/readConfig.js";
+import fetch from "node-fetch";
+import { TestString, NSFWCheck } from "../automations/unscan.js";
+
+export default async function(interaction) {
+ // @ts-ignore
+ let verify = interaction.client.verify
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Loading")
+ .setStatus("Danger")
+ .setEmoji("NUCLEUS.LOADING")
+ ], ephemeral: true, fetchReply: true});
+ let config = await readConfig(interaction.guild.id);
+ if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`You already have the <@&${config.verify.role}> role`)
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ]});
+ }
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Checking our servers are up`)
+ .setStatus("Warning")
+ .setEmoji("NUCLEUS.LOADING")
+ ]});
+ try {
+ let status = await fetch(`https://clicksminuteper.net`).then(res => res.status);
+ if (status != 200) {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Our servers appear to be down, please try again later`)
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ]});
+ }
+ } catch {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Our servers appear to be down, please try again later`)
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ], components: [new Discord.MessageActionRow().addComponents([
+ new Discord.MessageButton()
+ .setLabel("Open webpage")
+ .setStyle("LINK")
+ .setURL("https://clicksminuteper.net/"),
+ new Discord.MessageButton()
+ .setLabel("Support")
+ .setStyle("LINK")
+ .setURL("https://discord.gg/bPaNnxe")
+ ])]});
+ }
+ if (config.filters.images.NSFW) {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Checking your avatar is safe for work`)
+ .setStatus("Warning")
+ .setEmoji("NUCLEUS.LOADING")
+ ]});
+ if (await NSFWCheck((interaction.member as GuildMember).user.avatarURL({format: "png"}))) {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Your avatar was detected as NSFW, which we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake`)
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ]});
+ }
+ }
+ if (config.filters.wordFilter) {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Checking your name is allowed`)
+ .setStatus("Warning")
+ .setEmoji("NUCLEUS.LOADING")
+ ]});
+ if (TestString((interaction.member as Discord.GuildMember).displayName, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict) != "none") {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Your name contained a word we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake`)
+ .setStatus("Danger")
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ]});
+ }
+ }
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`One moment...`)
+ .setStatus("Warning")
+ .setEmoji("NUCLEUS.LOADING")
+ ]});
+ let code = ""
+ let length = 5
+ let itt = 0
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ while (true) {
+ itt += 1
+ code = ""
+ for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); }
+ if (code in verify) continue;
+ if (itt > 1000) {
+ itt = 0
+ length += 1
+ continue
+ }
+ break;
+ }
+ verify[code] = {
+ uID: interaction.member.user.id,
+ gID: interaction.guild.id,
+ rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
+ mCount: interaction.guild.memberCount,
+ gName: interaction.guild.name,
+ guildIcon: interaction.guild.iconURL({format: "png"})
+ }
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Verify")
+ .setDescription(`Looking good!\nClick the button below to get verified`)
+ .setStatus("Success")
+ .setEmoji("MEMBER.JOIN")
+ ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
+ .setLabel("Verify")
+ .setStyle("LINK")
+ .setURL(`https://clicksminuteper.net/nucleus/verify?code=${code}`)
+ ])]});
+}
\ No newline at end of file
diff --git a/src/commands/categorisationTest.ts b/src/commands/categorisationTest.ts
new file mode 100644
index 0000000..2852a2b
--- /dev/null
+++ b/src/commands/categorisationTest.ts
@@ -0,0 +1,75 @@
+import { CommandInteraction, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js";
+import { SelectMenuComponent, SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
+import generateKeyValueList, { toCapitals } from "../utils/generateKeyValueList.js";
+import getEmojiByName from "../utils/getEmojiByName.js";
+
+const command = new SlashCommandBuilder()
+ .setName("categorise")
+ .setDescription("Categorises your servers channels")
+
+const callback = async (interaction: CommandInteraction) => {
+ // @ts-ignore
+ const { renderChannel } = interaction.client.logger
+
+ let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY");
+ let categorised = {}
+
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Loading...")
+ .setEmoji("NUCLEUS.LOADING")
+ .setStatus("Success")
+ ], ephemeral: true});
+ for (let c of channels.values()) {
+ let predicted = []
+ let types = {
+ general: ["general"],
+ commands: ["bot", "command", "music"],
+ images: ["pic", "selfies", "image"],
+ nsfw: ["porn", "nsfw", "sex"],
+ links: ["links"],
+ advertising: ["ads", "advert", "server", "partner"],
+ staff: ["staff", "mod", "admin"]
+ }
+
+ for (let type in types) {
+ for (let word of types[type]) {
+ if (c.name.toLowerCase().includes(word)) {
+ predicted.push(type)
+ }
+ }
+ }
+
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Categorise")
+ .setDescription(generateKeyValueList({
+ channel: renderChannel(c),
+ category: c.parent ? c.parent.name : "Uncategorised"
+ }) + "\n\n" + `Suggested tags: ${predicted.join(", ")}`)
+ .setEmoji("CHANNEL.TEXT.CREATE")
+ .setStatus("Success")
+ ], components: [ new MessageActionRow().addComponents([
+ new MessageButton()
+ .setLabel("Use suggested")
+ .setStyle("PRIMARY")
+ .setCustomId("accept")
+ .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
+ ]), new MessageActionRow().addComponents([new MessageSelectMenu()
+ .setPlaceholder("Select a category")
+ .setCustomId("category")
+ .setMinValues(0)
+ .setMaxValues(1)
+ // .setMaxValues(Object.keys(types).length)
+ .setOptions(Object.keys(types).map(type => {return {label: toCapitals(type), value: type}}))
+ ])]});
+ }
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/createTestButton.ts b/src/commands/createTestButton.ts
new file mode 100644
index 0000000..71f9ef1
--- /dev/null
+++ b/src/commands/createTestButton.ts
@@ -0,0 +1,35 @@
+import { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+
+const command = new SlashCommandBuilder()
+ .setName("createtestbutton")
+ .setDescription("creates a test button")
+
+const callback = (interaction: CommandInteraction) => {
+ interaction.reply({components: [new MessageActionRow().addComponents([
+ new MessageButton()
+ .setCustomId("createticket")
+ .setLabel("Create Ticket")
+ .setStyle("PRIMARY")
+ .setDisabled(false),
+ new MessageButton()
+ .setCustomId("verifybutton")
+ .setLabel("Verify")
+ .setStyle("PRIMARY")
+ .setDisabled(false),
+ new MessageButton()
+ .setCustomId("rolemenu")
+ .setLabel("Get roles")
+ .setStyle("PRIMARY")
+ .setDisabled(false)
+ ])]});
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/mod/unnamed.ts b/src/commands/mod/unnamed.ts
new file mode 100644
index 0000000..2d65a87
--- /dev/null
+++ b/src/commands/mod/unnamed.ts
@@ -0,0 +1,233 @@
+import Discord, { CommandInteraction, GuildMember, MessageActionRow } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import confirmationMessage from "../../utils/confirmationMessage.js";
+import keyValueList from "../../utils/generateKeyValueList.js";
+import humanizeDuration from "humanize-duration";
+import { create, areTicketsEnabled } from "../../automations/createModActionTicket.js";
+import readConfig from '../../utils/readConfig.js'
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("unnamed")
+ .setDescription("Gives a user a role")
+ .addUserOption(option => option.setName("user").setDescription("The user to UNNAMED").setRequired(true)) // TODO
+ .addIntegerOption(option => option.setName("days").setDescription("The number of days to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(27).setRequired(false))
+ .addIntegerOption(option => option.setName("hours").setDescription("The number of hours to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(23).setRequired(false))
+ .addIntegerOption(option => option.setName("minutes").setDescription("The number of minutes to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false))
+ .addIntegerOption(option => option.setName("seconds").setDescription("The number of seconds to UNNAMED the user for | Default 0").setMinValue(0).setMaxValue(59).setRequired(false))
+ .addStringOption(option => option.setName("reason").setDescription("The reason for the UNNAMED").setRequired(false))
+ .addStringOption(option => option.setName("notify").setDescription("If the user should get a message when they are UNNAMED | Default yes").setRequired(false)
+ .addChoices([["Yes", "yes"], ["No", "no"]]))
+
+const callback = async (interaction: CommandInteraction) => {
+ // @ts-ignore
+ const { log, NucleusColors, renderUser, entry } = interaction.client.logger
+ let config = await readConfig(interaction.guild.id);
+ const user = interaction.options.getMember("user") as GuildMember
+ const reason = interaction.options.getString("reason")
+ const time = {
+ days: interaction.options.getInteger("days") || 0,
+ hours: interaction.options.getInteger("hours") || 0,
+ minutes: interaction.options.getInteger("minutes") || 0,
+ seconds: interaction.options.getInteger("seconds") || 0
+ }
+ let muteTime = (time.days * 24 * 60 * 60) + (time.hours * 60 * 60) + (time.minutes * 60) + time.seconds
+ if (muteTime == 0) {
+ let m = await interaction.reply({embeds: [
+ new generateEmojiEmbed()
+ .setEmoji("PUNISH.MUTE.GREEN") // TODO
+ .setTitle("UNNAMED")
+ .setDescription("How long should the user be UNNAMED")
+ .setStatus("Success")
+ ], components: [
+ new MessageActionRow().addComponents([
+ new Discord.MessageButton()
+ .setCustomId("1m")
+ .setLabel("1 Minute")
+ .setStyle("SECONDARY"),
+ new Discord.MessageButton()
+ .setCustomId("10m")
+ .setLabel("10 Minutes")
+ .setStyle("SECONDARY"),
+ new Discord.MessageButton()
+ .setCustomId("30m")
+ .setLabel("30 Minutes")
+ .setStyle("SECONDARY"),
+ new Discord.MessageButton()
+ .setCustomId("1h")
+ .setLabel("1 Hour")
+ .setStyle("SECONDARY")
+ ]),
+ new MessageActionRow().addComponents([
+ new Discord.MessageButton()
+ .setCustomId("6h")
+ .setLabel("6 Hours")
+ .setStyle("SECONDARY"),
+ new Discord.MessageButton()
+ .setCustomId("12h")
+ .setLabel("12 Hours")
+ .setStyle("SECONDARY"),
+ new Discord.MessageButton()
+ .setCustomId("1d")
+ .setLabel("1 Day")
+ .setStyle("SECONDARY"),
+ new Discord.MessageButton()
+ .setCustomId("1w")
+ .setLabel("1 Week")
+ .setStyle("SECONDARY")
+ ]),
+ new MessageActionRow().addComponents([
+ new Discord.MessageButton()
+ .setCustomId("cancel")
+ .setLabel("Cancel")
+ .setStyle("DANGER")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ])
+ ], ephemeral: true, fetchReply: true})
+ let component;
+ try {
+ component = await (m as Discord.Message).awaitMessageComponent({filter: (m) => m.user.id === interaction.user.id, time: 2.5 * 60 * 1000});
+ } catch { return }
+ component.deferUpdate();
+ if (component.customId == "cancel") return interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("PUNISH.MUTE.RED") // TODO
+ .setTitle("UNNAMED")
+ .setDescription("UNNAMED cancelled")
+ .setStatus("Danger")
+ ]})
+ switch (component.customId) {
+ case "1m": { muteTime = 60; break; }
+ case "10m": { muteTime = 60 * 10; break; }
+ case "30m": { muteTime = 60 * 30; break; }
+ case "1h": { muteTime = 60 * 60; break; }
+ case "6h": { muteTime = 60 * 60 * 6; break; }
+ case "12h": { muteTime = 60 * 60 * 12; break; }
+ case "1d": { muteTime = 60 * 60 * 24; break; }
+ case "1w": { muteTime = 60 * 60 * 24 * 7; break; }
+ }
+ } else {
+ await interaction.reply({embeds: [
+ new generateEmojiEmbed()
+ .setEmoji("PUNISH.MUTE.GREEN") // TODO
+ .setTitle("UNNAMED")
+ .setDescription("Loading...")
+ .setStatus("Success")
+ ], ephemeral: true, fetchReply: true})
+ }
+ // TODO:[Modals] Replace this with a modal
+ let confirmation = await new confirmationMessage(interaction)
+ .setEmoji("PUNISH.MUTE.RED") // TODO
+ .setTitle("UNNAMED")
+ .setDescription(keyValueList({
+ "user": `<@!${user.id}> (${user.user.username})`,
+ "time": `${humanizeDuration(muteTime * 1000, {round: true})}`,
+ "reason": `\n> ${reason ? reason : "*No reason provided*"}`
+ })
+ + `The user **will${interaction.options.getString("notify") === "no" ? ' not' : ''}** be notified\n\n`
+ + `Are you sure you want to mute <@!${(interaction.options.getMember("user") as GuildMember).id}>?`) // TODO
+ .setColor("Danger")
+ .addCustomCallback(
+ "Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)),
+ () => { create(interaction.guild, interaction.options.getUser("user"), interaction.client)},
+ "An appeal ticket was created")
+// pluralize("day", interaction.options.getInteger("delete"))
+// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
+ .send()
+ if (confirmation.success) {
+ let dmd = false
+ let dm;
+ try {
+ if (interaction.options.getString("notify") != "no") {
+ dm = await (interaction.options.getMember("user") as GuildMember).send({
+ embeds: [new generateEmojiEmbed()
+ .setEmoji("PUNISH.MUTE.RED") // TODO
+ .setTitle("UNNAMED")
+ .setDescription(`You have been muted in ${interaction.guild.name}` + // TODO
+ (interaction.options.getString("reason") ? ` for:\n> ${interaction.options.getString("reason")}` : ".\n\n" +
+ `You will be unmuted at: <t:${Math.round((new Date).getTime() / 1000) + muteTime}:D> at <t:${Math.round((new Date).getTime() / 1000) + muteTime}:T> (<t:${Math.round((new Date).getTime() / 1000) + muteTime}:R>)`)) // TODO
+ .setStatus("Danger")
+ ]
+ })
+ dmd = true
+ }
+ } catch {}
+ try {
+ await ((interaction.options.getMember("user") as GuildMember).roles.add(interaction.guild.roles.cache.find((r) => r.id === config.moderation.role.role)))
+ // TODO: Store when to remove the role
+ } catch {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("PUNISH.MUTE.RED")
+ .setTitle(`Mute`)
+ .setDescription("Something went wrong and the user was not UNNAMED")
+ .setStatus("Danger")
+ ], components: []})
+ if (dmd) await dm.delete()
+ return
+ }
+ let failed = (dmd == false && interaction.options.getString("notify") != "no")
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji(`PUNISH.MUTE.${failed ? "YELLOW" : "GREEN"}`) // TODO
+ .setTitle(`Mute`) // TODO
+ .setDescription("The member was muted" + (failed ? ", but could not be notified" : "")) // TODO
+ .setStatus(failed ? "Warning" : "Success")
+ ], components: []})
+ let data = {
+ meta:{
+ type: 'memberMute', // TODO
+ displayName: 'Member Muted', // TODO
+ calculateType: 'guildMemberPunish',
+ color: NucleusColors.yellow,
+ emoji: 'PUNISH.WARN.YELLOW', // TODO
+ timestamp: new Date().getTime()
+ },
+ list: {
+ user: entry((interaction.options.getMember("user") as GuildMember).user.id, renderUser((interaction.options.getMember("user") as GuildMember).user)),
+ mutedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)), // TODO
+ time: entry(muteTime, `${humanizeDuration(muteTime * 1000, {round: true})}`),
+ reason: (interaction.options.getString("reason") ? `\n> ${interaction.options.getString("reason")}` : "No reason provided")
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ }
+ log(data, interaction.client);
+ } else {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("PUNISH.MUTE.GREEN") // TODO
+ .setTitle(`Mute`) // TODO
+ .setDescription("No changes were made")
+ .setStatus("Success")
+ ], components: []})
+ }
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ let member = (interaction.member as GuildMember)
+ let me = (interaction.guild.me as GuildMember)
+ let apply = (interaction.options.getMember("user") as GuildMember)
+ if (member == null || me == null || apply == null) throw "That member is not in the server"
+ let memberPos = member.roles ? member.roles.highest.position : 0
+ let mePos = me.roles ? me.roles.highest.position : 0
+ let applyPos = apply.roles ? apply.roles.highest.position : 0
+ // Check if Nucleus can UNNAMED the member
+ if (! (mePos > applyPos)) throw "I do not have a role higher than that member"
+ // Check if Nucleus has permission to UNNAMED
+ if (! interaction.guild.me.permissions.has("MANAGE_ROLES")) throw "I do not have the `manage_roles` permission";
+ // Do not allow the user to have admin or be the owner
+ if ((interaction.options.getMember("user") as GuildMember).permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot mute an admin or the owner"
+ // Do not allow muting Nucleus
+ if ((interaction.member as GuildMember).id == interaction.guild.me.id) throw "I cannot UNNAMED myself"
+ // Allow the owner to UNNAMED anyone
+ if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ // Check if the user has moderate_members permission
+ if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
+ // Check if the user is below on the role list
+ if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
+ // Allow UNNAMED
+ return true
+}
+
+export { command, callback, check };
\ No newline at end of file
diff --git a/src/commands/nucleus/guide.ts b/src/commands/nucleus/guide.ts
new file mode 100644
index 0000000..814d2f5
--- /dev/null
+++ b/src/commands/nucleus/guide.ts
@@ -0,0 +1,24 @@
+import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import guide from "../../automations/guide.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("guide")
+ .setDescription("Shows the welcome guide for the bot")
+
+
+const callback = async (interaction) => {
+ guide(interaction.guild, interaction)
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ return true
+}
+
+export { command };
+export { callback };
+export { check };
diff --git a/src/commands/nucleus/invite.ts b/src/commands/nucleus/invite.ts
new file mode 100644
index 0000000..44934e1
--- /dev/null
+++ b/src/commands/nucleus/invite.ts
@@ -0,0 +1,30 @@
+import { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("invite")
+ .setDescription("Invites Nucleus to your server")
+
+const callback = (interaction: CommandInteraction) => {
+ interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Invite")
+ .setDescription("You can invite Nucleus to your server by clicking the button below")
+ .setEmoji("NUCLEUS.LOGO")
+ .setStatus("Danger")
+ ], components: [new MessageActionRow().addComponents([new MessageButton()
+ .setLabel("Invite")
+ .setStyle("LINK")
+ .setURL(`https://discord.com/api/oauth2/authorize?client_id=${interaction.client.user.id}&permissions=295157886134&scope=bot%20applications.commands`)
+ ])], ephemeral: true});
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/server/_meta.ts b/src/commands/server/_meta.ts
new file mode 100644
index 0000000..379aac6
--- /dev/null
+++ b/src/commands/server/_meta.ts
@@ -0,0 +1,4 @@
+const name = "server";
+const description = "Commands for the server";
+
+export { name, description };
\ No newline at end of file
diff --git a/src/commands/server/about.ts b/src/commands/server/about.ts
new file mode 100644
index 0000000..054cad3
--- /dev/null
+++ b/src/commands/server/about.ts
@@ -0,0 +1,50 @@
+import Discord, { CommandInteraction, Guild, MessageActionRow, MessageButton } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import generateKeyValueList, { toCapitals } from "../../utils/generateKeyValueList.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) => builder
+ .setName("about")
+ .setDescription("Shows info about the server")
+
+const callback = async (interaction: CommandInteraction) => {
+ let guild = interaction.guild as Guild;
+ // @ts-ignore
+ const { renderUser, renderDelta } = interaction.client.logger
+ interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Server Info")
+ .setStatus("Success")
+ .setEmoji("GUILD.GREEN")
+ .setDescription(
+ generateKeyValueList({
+ "name": guild.name,
+ "id": `\`${guild.id}\``,
+ "owner": `${renderUser((await guild.fetchOwner()).user)}`,
+ "created": `${renderDelta(guild.createdTimestamp)}`,
+ "emojis": `${guild.emojis.cache.size}` + (guild.emojis.cache.size > 1 ? `\n> ${
+ guild.emojis.cache.first(10).map((emoji) => `<${emoji.animated ? 'a' : ''}:${emoji.name}:${emoji.id}>`).join(" ")
+ }` +
+ (guild.emojis.cache.size > 10 ? ` and ${guild.emojis.cache.size - 10} more` : ``) : ""),
+ "icon": `[Discord](${guild.iconURL()})`,
+ "2 factor authentication": `${guild.mfaLevel === "NONE" ? `${getEmojiByName("CONTROL.CROSS")} No` : `${getEmojiByName("CONTROL.TICK")} Yes`}`,
+ "verification level": `${toCapitals(guild.verificationLevel)}`,
+ "explicit content filter": `${toCapitals(guild.explicitContentFilter.toString().replace(/_/, " ", ))}`,
+ "nitro boost level": `${guild.premiumTier != "NONE" ? guild.premiumTier.toString()[-1] : "0"}`,
+ "channels": `${guild.channels.cache.size}`,
+ "roles": `${guild.roles.cache.size}`,
+ "members": `${guild.memberCount}`,
+ })
+ )
+ .setThumbnail(guild.iconURL({dynamic: true}))
+ ], ephemeral: true});
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/user/track.ts b/src/commands/user/track.ts
new file mode 100644
index 0000000..da6a37a
--- /dev/null
+++ b/src/commands/user/track.ts
@@ -0,0 +1,174 @@
+import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js";
+import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import generateKeyValueList from "../../utils/generateKeyValueList.js";
+import readConfig from "../../utils/readConfig.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("track")
+ .setDescription("Moves a user along a role track")
+ .addUserOption(option => option.setName("user").setDescription("The user to manage").setRequired(true))
+
+const generateFromTrack = (position: number, active: any, size: number, disabled: any) => {
+ active = active ? "ACTIVE" : "INACTIVE"
+ disabled = disabled ? "GREY." : ""
+ if (position == 0 && size == 1) return "TRACKS.SINGLE." + disabled + active
+ if (position == size - 1) return "TRACKS.VERTICAL.BOTTOM." + disabled + active
+ if (position == 0) return "TRACKS.VERTICAL.TOP." + disabled + active
+ return "TRACKS.VERTICAL.MIDDLE." + disabled + active
+}
+
+const callback = async (interaction: CommandInteraction) => {
+ // @ts-ignore
+ const { renderUser } = interaction.client.logger
+ const member = interaction.options.getMember("user") as GuildMember;
+ const guild = interaction.guild;
+ let config = await readConfig(guild.id);
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setEmoji("NUCLEUS.LOADING")
+ .setTitle("Loading")
+ .setStatus("Danger")
+ ], ephemeral: true})
+ let track = 0
+ let generated;
+ const roles = await guild.roles.fetch()
+ let memberRoles = await member.roles
+ while (true) {
+ let data = config.tracks[track]
+ let managed = data.manageableBy.some(element => {return memberRoles.cache.has(element)})
+ let dropdown = new Discord.MessageSelectMenu().addOptions(config.tracks.map((option, index) => {
+ let hasRoleInTrack = option.track.some(element => {return memberRoles.cache.has(element)})
+ return new SelectMenuOption({
+ default: index == track,
+ label: option.name,
+ value: index.toString(),
+ description: option.track.length == 0 ? "No" : option.track.length + " role" + (option.track.length == 1 ? "" : "s"), // TODO[s addition]
+ emoji: interaction.client.emojis.resolve(getEmojiByName("TRACKS.SINGLE." + (hasRoleInTrack ? "ACTIVE" : "INACTIVE"), "id"))
+ })
+ })).setCustomId("select").setMaxValues(1)
+ let allowed = []
+ generated = "**Track:** " + data.name + "\n" + "**Member:** " + renderUser(member.user) + "\n"
+ generated += (data.nullable ? "Members do not need a role in this track" : "A role in this track is required") + "\n"
+ generated += (data.retainPrevious ? "When promoted, the user keeps previous roles" : "Members will lose their current role when promoted") + "\n"
+ generated += "\n" + data.track.map((role, index) => {
+ let allow = (roles.get(role).position >= (interaction.member as GuildMember).roles.highest.position) && !managed
+ allowed.push(!allow)
+ return getEmojiByName(generateFromTrack(
+ index,
+ memberRoles.cache.has(role),
+ data.track.length,
+ allow
+ )) + " " +
+ roles.get(role).name + " [<@&" + roles.get(role).id + ">]"
+ }).join("\n")
+ let selected = [];
+ for (let i = 0; i < data.track.length; i++) {
+ if (memberRoles.cache.has(data.track[i])) selected.push(data.track[i])
+ }
+ let conflict = data.retainPrevious ? false : selected.length > 1;
+ let conflictDropdown
+ let currentRoleIndex
+ if (conflict) {
+ generated += `\n\n${getEmojiByName(`PUNISH.WARN.${managed ? "YELLOW" : "RED"}`)} This user has ${selected.length} roles from this track. `
+ conflictDropdown = []
+ if (
+ (roles.get(selected[0]).position < memberRoles.highest.position) || managed
+ ) {
+ generated += `In order to promote or demote this user, you must select which role the member should keep.`
+ selected.forEach(role => {
+ conflictDropdown.push(new SelectMenuOption({
+ label: roles.get(role).name,
+ value: roles.get(role).id,
+ }))
+ })
+ conflictDropdown = [new Discord.MessageSelectMenu()
+ .addOptions(conflictDropdown)
+ .setCustomId("conflict")
+ .setMaxValues(1)
+ .setPlaceholder("Select a role to keep")]
+ } else {
+ generated += "You don't have permission to manage one or more of the users roles, and therefore can't select one to keep."
+ }
+ } else {
+ currentRoleIndex = selected.length == 0 ? -1 : data.track.indexOf(selected[0].toString())
+ }
+ let m = await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("TRACKS.ICON")
+ .setTitle("Tracks")
+ .setDescription(`${generated}`)
+ .setStatus("Success")
+ ], components: [
+ new MessageActionRow().addComponents(dropdown)
+ ]
+ .concat(conflict && conflictDropdown.length ? [new MessageActionRow().addComponents(conflictDropdown)] : [])
+ .concat([
+ new MessageActionRow().addComponents([
+ new MessageButton()
+ .setEmoji(getEmojiByName("CONTROL.UP", "id"))
+ .setLabel("Move up")
+ .setCustomId("promote")
+ .setStyle("SUCCESS")
+ .setDisabled(conflict || currentRoleIndex == 0 || (currentRoleIndex == -1 ? false : !allowed[currentRoleIndex - 1])),
+ new MessageButton()
+ .setEmoji(getEmojiByName("CONTROL.DOWN", "id"))
+ .setLabel("Move down")
+ .setCustomId("demote")
+ .setStyle("DANGER")
+ .setDisabled(conflict || (
+ data.nullable ? currentRoleIndex <= -1 :
+ currentRoleIndex == data.track.length - 1 || currentRoleIndex <= -1
+ ) || !allowed[currentRoleIndex]),
+ ])
+ ])})
+ let component;
+ try {
+ component = await (m as Message).awaitMessageComponent({time: 2.5 * 60 * 1000});
+ } catch (e) {
+ return
+ }
+ component.deferUpdate()
+ if (component.customId == "conflict") {
+ let rolesToRemove = selected.filter(role => role != component.values[0])
+ await member.roles.remove(rolesToRemove)
+ } else if (component.customId == "promote") {
+ if (
+ currentRoleIndex == -1 ? allowed[data.track.length - 1] :
+ allowed[currentRoleIndex - 1] && allowed[currentRoleIndex]
+ ) {
+ if (currentRoleIndex == -1) {
+ await member.roles.add(data.track[data.track.length - 1])
+ } else if (currentRoleIndex < data.track.length) {
+ if (!data.retainPrevious) await member.roles.remove(data.track[currentRoleIndex])
+ await member.roles.add(data.track[currentRoleIndex - 1])
+ }
+ }
+ } else if (component.customId == "demote") {
+ if(allowed[currentRoleIndex]) {
+ if (currentRoleIndex == data.track.length - 1) {
+ if (data.nullable) await member.roles.remove(data.track[currentRoleIndex])
+ } else if (currentRoleIndex > -1) {
+ await member.roles.remove(data.track[currentRoleIndex])
+ await member.roles.add(data.track[currentRoleIndex + 1])
+ }
+ }
+ } else if (component.customId == "select") {
+ track = component.values[0]
+ }
+ }
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ // Allow the owner to promote anyone
+ if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ // Check if the user has manage_roles permission
+ if (! (interaction.member as GuildMember).permissions.has("MANAGE_ROLES")) throw "You do not have the `manage_roles` permission";
+ // Allow track
+ return true // TODO: allow if the member has manage perms
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
new file mode 100644
index 0000000..3470450
--- /dev/null
+++ b/src/events/interactionCreate.ts
@@ -0,0 +1,21 @@
+import { callback as roleMenu } from "../automations/roleMenu.js"
+import verify from "../automations/verify.js";
+import create from "../automations/tickets/create.js";
+import close from "../automations/tickets/delete.js";
+
+export const event = 'interactionCreate';
+
+async function interactionCreate(interaction) {
+ if (interaction.componentType === "BUTTON") {
+ if (interaction.customId === "rolemenu") return await roleMenu(interaction)
+ if (interaction.customId === "verifybutton") return verify(interaction)
+ if (interaction.customId === "createticket") return create(interaction)
+ if (interaction.customId === "closeticket") return close(interaction)
+ } else if (interaction.componentType === "MESSAGE_COMPONENT") {
+ console.table(interaction)
+ }
+}
+
+export async function callback(client, interaction) {
+ await interactionCreate(interaction)
+}
\ No newline at end of file
diff --git a/src/utils/singleNotify.ts b/src/utils/singleNotify.ts
new file mode 100644
index 0000000..4e9e6fe
--- /dev/null
+++ b/src/utils/singleNotify.ts
@@ -0,0 +1,26 @@
+import readConfig from "./readConfig.js";
+import generateEmojiEmbed from "./generateEmojiEmbed.js";
+
+let severities = {
+ "Critical": "Danger",
+ "Warning": "Warning",
+ "Info": "Success"
+}
+
+export default async function(client, type: string, guild: string, message: string, severity: string) {
+ let config = await readConfig(guild);
+ if (config.singleEventNotifications[type]) return;
+ // TODO: Set config.singleEventNotifications[type] to true
+ let channel = await client.channels.fetch(config.logging.staff);
+ if (!channel) return;
+ try {
+ await channel.send({embeds: [new generateEmojiEmbed()
+ .setTitle(`${severity} notification`)
+ .setDescription(message)
+ .setColor(severities[severity])
+ .setEmoji("CONTROL.BLOCKCROSS")
+ ]})
+ } catch (err) {
+ console.error(err)
+ }
+}