From 470445a895984f568bdded711f26f91aa2b05cca Mon Sep 17 00:00:00 2001 From: nathen418 Date: Thu, 1 Sep 2022 18:41:55 +0000 Subject: [PATCH] Apply auto formatting changes --- commands/owner/createRoles.ts | 64 ++++++----- commands/owner/csClassPoll.ts | 34 +++--- commands/owner/say.ts | 44 +++++--- commands/owner/staffPoll.ts | 130 ++++++++++++---------- commands/owner/yearPoll.ts | 149 +++++++++++++------------ commands/user/clear.ts | 49 +++++---- commands/user/github.ts | 62 ++++++----- commands/user/help.ts | 125 +++++++++++---------- commands/user/ping.ts | 62 ++++++----- commands/user/status.ts | 62 ++++++----- commands/user/uptime.ts | 28 +++-- commands/user/version.ts | 62 ++++++----- commands/user/view.ts | 25 +++-- features/interactionCreate.ts | 148 ++++++++++++------------- features/status-changer.ts | 69 ++++++------ features/statuspage.ts | 24 ++-- index.ts | 87 ++++++++------- models/classModel.ts | 18 +-- models/staffModel.ts | 8 +- models/yearModel.ts | 9 +- rolesOps.ts | 200 +++++++++++++++++++--------------- 21 files changed, 799 insertions(+), 660 deletions(-) diff --git a/commands/owner/createRoles.ts b/commands/owner/createRoles.ts index c8320b7..992c297 100644 --- a/commands/owner/createRoles.ts +++ b/commands/owner/createRoles.ts @@ -3,34 +3,42 @@ import { createRoles } from "../../rolesOps"; import chalk from "chalk"; export default { - name: "createRoles", - category: "owner", - description: "Creates roles if they do not exist in the server", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"], - ownerOnly: true, + name: "createRoles", + category: "owner", + description: "Creates roles if they do not exist in the server", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"], + ownerOnly: true, - callback: async ({ interaction }) => { - console.log(chalk.green("Creating roles...\nCopy and paste the following output into your .env file")); - console.log(chalk.red("------------------------------------------------------")); - // Create the roles - createRoles(interaction.guild!, "class"); - createRoles(interaction.guild!, "staff"); - createRoles(interaction.guild!, "year"); - interaction.reply({ - content: "Roles created!", - ephemeral: true, - }); + callback: async ({ interaction }) => { + console.log( + chalk.green( + "Creating roles...\nCopy and paste the following output into your .env file" + ) + ); + console.log( + chalk.red("------------------------------------------------------") + ); + // Create the roles + createRoles(interaction.guild!, "class"); + createRoles(interaction.guild!, "staff"); + createRoles(interaction.guild!, "year"); + interaction.reply({ + content: "Roles created!", + ephemeral: true, + }); - // Log the command usage - console.log( - chalk.blue( - `${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/yearPoll`)} command in ${chalk.yellow( - interaction.guild?.name - )}` - ) - ); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/yearPoll`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index ce970e6..6bee095 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -1,16 +1,21 @@ -import { MessageEmbed, MessageActionRow, MessageSelectMenu, MessageSelectOptionData } from "discord.js"; +import { + MessageEmbed, + MessageActionRow, + MessageSelectMenu, + MessageSelectOptionData, +} from "discord.js"; import chalk from "chalk"; import { ICommand } from "wokcommands"; import classModel from "../../models/classModel"; import { checkForRoles } from "../../rolesOps"; export interface Class { - CODE: string, - TITLE: string, - INFO: string, - ROLE_NAME: string, - ROLE_ID: string, - UUID: string, + CODE: string; + TITLE: string; + INFO: string; + ROLE_NAME: string; + ROLE_ID: string; + UUID: string; } export default { @@ -34,7 +39,7 @@ export default { let classes: Class[] = await classModel.find({}).sort({ CODE: 1 }); const class_chunks = split_list(classes, 25); - let rows:MessageActionRow[] = []; + let rows: MessageActionRow[] = []; for (let index = 0; index < class_chunks.length; index++) { const menu = new MessageSelectMenu(); menu.setCustomId(`csClassPoll+${index}`); @@ -50,8 +55,7 @@ export default { rows.push(row); } - - const row_chunks = split_list(rows, 5) + const row_chunks = split_list(rows, 5); for (let index = 0; index < row_chunks.length; index++) { if (index == 0) { // Define embeds used in this command @@ -91,12 +95,11 @@ export default { // Splits any size list into lists of at most `max_list_len` function split_list(list: Array, max_list_len: number) { - let class_chunks = [] + let class_chunks = []; for (let i = 0; i < list.length; i += max_list_len) { - class_chunks.push(list.slice(i, i + max_list_len)) - + class_chunks.push(list.slice(i, i + max_list_len)); } - return class_chunks + return class_chunks; } // consumes a Class and returns Message Selec tOption data @@ -105,6 +108,5 @@ function create_option_from_class(_class: Class): MessageSelectOptionData { label: _class.CODE, value: _class.CODE, description: _class.TITLE, - } + }; } - diff --git a/commands/owner/say.ts b/commands/owner/say.ts index bda5122..c7bab8d 100644 --- a/commands/owner/say.ts +++ b/commands/owner/say.ts @@ -20,25 +20,41 @@ export default { type: DiscordJS.Constants.ApplicationCommandOptionTypes.STRING, required: true, }, - { - name: "channel", - description: "The channel to say the thing in", - type: DiscordJS.Constants.ApplicationCommandOptionTypes.CHANNEL, - required: false, - } - ], + { + name: "channel", + description: "The channel to say the thing in", + type: DiscordJS.Constants.ApplicationCommandOptionTypes.CHANNEL, + required: false, + }, + ], callback: ({ interaction }) => { const content = interaction.options.getString("content") as string; - const channel = interaction.options.getChannel("channel") as TextChannel || interaction.channel as TextChannel; + const channel = + (interaction.options.getChannel("channel") as TextChannel) || + (interaction.channel as TextChannel); if (!content) { - interaction.reply({ content: "You need to provide a content to say", ephemeral: true }); - return; + interaction.reply({ + content: "You need to provide a content to say", + ephemeral: true, + }); + return; } channel.send(content); - interaction.reply({ content: `Message sent in <#${channel.id}>`, ephemeral: true }); + interaction.reply({ + content: `Message sent in <#${channel.id}>`, + ephemeral: true, + }); // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/say`)} command in ${chalk.yellow(interaction.guild?.name)}`)); - } -} as ICommand; \ No newline at end of file + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/say`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, +} as ICommand; diff --git a/commands/owner/staffPoll.ts b/commands/owner/staffPoll.ts index f6ca37a..c35d75c 100644 --- a/commands/owner/staffPoll.ts +++ b/commands/owner/staffPoll.ts @@ -4,68 +4,78 @@ import { ICommand } from "wokcommands"; import { checkForRoles } from "../../rolesOps"; export default { - name: "staffPoll", - category: "owner", - description: "Posts the College Staff Poll", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"], - ownerOnly: true, + name: "staffPoll", + category: "owner", + description: "Posts the College Staff Poll", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"], + ownerOnly: true, - callback: async ({ client, interaction: msgInt }) => { - // Define embeds used in this command - const infoEmbed = new MessageEmbed() - .setTitle("Choose a role") - .setColor("#0099ff") - .setDescription("Select the option with your current occupation at UWM.") - .setFooter({ - text: `Delivered in: ${client.ws.ping}ms | CSSC-Bot | ${process.env.VERSION}`, - iconURL: "https://playantares.com/resources/CSSC-bot/icon.jpg", - }); + callback: async ({ client, interaction: msgInt }) => { + // Define embeds used in this command + const infoEmbed = new MessageEmbed() + .setTitle("Choose a role") + .setColor("#0099ff") + .setDescription("Select the option with your current occupation at UWM.") + .setFooter({ + text: `Delivered in: ${client.ws.ping}ms | CSSC-Bot | ${process.env.VERSION}`, + iconURL: "https://playantares.com/resources/CSSC-bot/icon.jpg", + }); - // Create row one of the buttons for the poll - const row = new MessageActionRow().addComponents( - new MessageSelectMenu() - .setCustomId("collegeStaffPoll") - .setPlaceholder("Select an option") - .addOptions( - { - label: "Tutor", - value: "Tutor", - }, - { - label: "SI Leader", - value: "Sileader", - }, - { - label: "TA", - value: "Ta", - }, - { - label: "Professor", - value: "Professor", - }, - { - label: "Student Employee", - value: "Studentemployee", - }, - { - label: "None", - value: "None", - description: "Clear all staff roles", - } - ) - ); + // Create row one of the buttons for the poll + const row = new MessageActionRow().addComponents( + new MessageSelectMenu() + .setCustomId("collegeStaffPoll") + .setPlaceholder("Select an option") + .addOptions( + { + label: "Tutor", + value: "Tutor", + }, + { + label: "SI Leader", + value: "Sileader", + }, + { + label: "TA", + value: "Ta", + }, + { + label: "Professor", + value: "Professor", + }, + { + label: "Student Employee", + value: "Studentemployee", + }, + { + label: "None", + value: "None", + description: "Clear all staff roles", + } + ) + ); - // Send the embed and message component rows - if (!checkForRoles(msgInt.guild!)) { - msgInt.reply("Please run the `/createRoles` command in this server to create the necessary roles for this poll!"); - } else { - msgInt.reply({ embeds: [infoEmbed], components: [row] }); - } + // Send the embed and message component rows + if (!checkForRoles(msgInt.guild!)) { + msgInt.reply( + "Please run the `/createRoles` command in this server to create the necessary roles for this poll!" + ); + } else { + msgInt.reply({ embeds: [infoEmbed], components: [row] }); + } - // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(msgInt.user.tag)} used the ${chalk.green(`/staffPoll`)} command in ${chalk.yellow(msgInt.guild?.name)}`)); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + msgInt.user.tag + )} used the ${chalk.green(`/staffPoll`)} command in ${chalk.yellow( + msgInt.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/owner/yearPoll.ts b/commands/owner/yearPoll.ts index d90126a..17f6e62 100644 --- a/commands/owner/yearPoll.ts +++ b/commands/owner/yearPoll.ts @@ -4,77 +4,88 @@ import { ICommand } from "wokcommands"; import { checkForRoles } from "../../rolesOps"; export default { - name: "yearPoll", - category: "owner", - description: "Posts the College Year Poll", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"], - ownerOnly: true, + name: "yearPoll", + category: "owner", + description: "Posts the College Year Poll", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["MANAGE_GUILD", "MANAGE_ROLES"], + ownerOnly: true, - callback: async ({ client, interaction: msgInt }) => { - // Define embeds used in this command - const infoEmbed = new MessageEmbed() - .setTitle("Choose a role") - .setColor("#0099ff") - .setDescription("Select the button with your current college year.") - .setFooter({ - text: `Delivered in: ${client.ws.ping}ms | CSSC-Bot | ${process.env.VERSION}`, - iconURL: "https://playantares.com/resources/CSSC-bot/icon.jpg", - }); + callback: async ({ client, interaction: msgInt }) => { + // Define embeds used in this command + const infoEmbed = new MessageEmbed() + .setTitle("Choose a role") + .setColor("#0099ff") + .setDescription("Select the button with your current college year.") + .setFooter({ + text: `Delivered in: ${client.ws.ping}ms | CSSC-Bot | ${process.env.VERSION}`, + iconURL: "https://playantares.com/resources/CSSC-bot/icon.jpg", + }); - - // Create row one of the buttons for the poll - const row = new MessageActionRow().addComponents( - new MessageSelectMenu() - .setCustomId("collegeYearPoll") - .setPlaceholder("Select an option.") - .addOptions( - { - label: "Prefrosh", - value: "Prefrosh", - }, - { - label: "Freshman", - value: "Freshman", - }, - { - label: "Sophomore", - value: "Sophomore", - }, - { - label: "Junior", - value: "Junior", - }, - { - label: "Senior", - value: "Senior", - }, - { - label: "Grad Student", - value: "Graduatestudent", - }, - { - label: "Alumni", - value: "Alumni", - }, - { - label: "None", - value: "None", - description: "Clear all year roles", - } - ) - ); + // Create row one of the buttons for the poll + const row = new MessageActionRow().addComponents( + new MessageSelectMenu() + .setCustomId("collegeYearPoll") + .setPlaceholder("Select an option.") + .addOptions( + { + label: "Prefrosh", + value: "Prefrosh", + }, + { + label: "Freshman", + value: "Freshman", + }, + { + label: "Sophomore", + value: "Sophomore", + }, + { + label: "Junior", + value: "Junior", + }, + { + label: "Senior", + value: "Senior", + }, + { + label: "Grad Student", + value: "Graduatestudent", + }, + { + label: "Alumni", + value: "Alumni", + }, + { + label: "None", + value: "None", + description: "Clear all year roles", + } + ) + ); - // Send the embed and message component rows - if (!checkForRoles(msgInt.guild!)) { - msgInt.reply({content: "Please run the /createRoles command in this server to create the necessary roles for this poll!", ephemeral: true}); - } else { - msgInt.reply({ embeds: [infoEmbed], components: [row] }); - } + // Send the embed and message component rows + if (!checkForRoles(msgInt.guild!)) { + msgInt.reply({ + content: + "Please run the /createRoles command in this server to create the necessary roles for this poll!", + ephemeral: true, + }); + } else { + msgInt.reply({ embeds: [infoEmbed], components: [row] }); + } - // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(msgInt.user.tag)} used the ${chalk.green(`/yearPoll`)} command in ${chalk.yellow(msgInt.guild?.name)}`)); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + msgInt.user.tag + )} used the ${chalk.green(`/yearPoll`)} command in ${chalk.yellow( + msgInt.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/user/clear.ts b/commands/user/clear.ts index 6f41e84..207b792 100644 --- a/commands/user/clear.ts +++ b/commands/user/clear.ts @@ -4,25 +4,36 @@ import { ICommand } from "wokcommands"; import { removeRole } from "../../rolesOps"; export default { - name: "clear", - category: "user", - description: "removes all roles the bot has assigned to a user", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["SEND_MESSAGES"], + name: "clear", + category: "user", + description: "removes all roles the bot has assigned to a user", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["SEND_MESSAGES"], - callback: async ({ interaction }) => { - // Remove roles from user - if (!interaction.member) return; - const member = interaction.member as GuildMember; - removeRole(member, "class"); - removeRole(member, "year"); - removeRole(member, "staff"); - // Reply to the user - interaction.reply({ content: "Cleared all roles that I have assigned to you.", ephemeral: true }); + callback: async ({ interaction }) => { + // Remove roles from user + if (!interaction.member) return; + const member = interaction.member as GuildMember; + removeRole(member, "class"); + removeRole(member, "year"); + removeRole(member, "staff"); + // Reply to the user + interaction.reply({ + content: "Cleared all roles that I have assigned to you.", + ephemeral: true, + }); - // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/clear`)} command in ${chalk.yellow(interaction.guild?.name)}`)); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/clear`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/user/github.ts b/commands/user/github.ts index 32641d1..9ca20fe 100644 --- a/commands/user/github.ts +++ b/commands/user/github.ts @@ -3,34 +3,44 @@ import { MessageEmbed } from "discord.js"; import { ICommand } from "wokcommands"; export default { - name: "github", - category: "user", - description: "Sends an embed with a link to the github repo for the bot.", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["SEND_MESSAGES"], + name: "github", + category: "user", + description: "Sends an embed with a link to the github repo for the bot.", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["SEND_MESSAGES"], - callback: async ({ client, interaction }) => { - // Embed values - const color = "#0099ff"; - const thumbnail = "https://playantares.com/resources/CSSC-bot/cssc-server-icon.png"; - const title = "Github"; - const description = "Click here to go to the CSSC-bot repo: \n https://github.com/Antares-Network/CSSC-Bot"; - const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; - const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; + callback: async ({ client, interaction }) => { + // Embed values + const color = "#0099ff"; + const thumbnail = + "https://playantares.com/resources/CSSC-bot/cssc-server-icon.png"; + const title = "Github"; + const description = + "Click here to go to the CSSC-bot repo: \n https://github.com/Antares-Network/CSSC-Bot"; + const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; + const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; - // Embed construction - const Embed = new MessageEmbed() - .setColor(color) - .setTitle(title) - .setThumbnail(thumbnail) - .setDescription(description) - .setFooter({ text: footer, iconURL: footerIcon }); + // Embed construction + const Embed = new MessageEmbed() + .setColor(color) + .setTitle(title) + .setThumbnail(thumbnail) + .setDescription(description) + .setFooter({ text: footer, iconURL: footerIcon }); - interaction.reply({ embeds: [Embed] }); + interaction.reply({ embeds: [Embed] }); - // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/github`)} command in ${chalk.yellow(interaction.guild?.name)}`)); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/github`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/user/help.ts b/commands/user/help.ts index a4194e6..3c3030e 100644 --- a/commands/user/help.ts +++ b/commands/user/help.ts @@ -1,62 +1,69 @@ import chalk from "chalk"; -import { - MessageEmbed, - } from "discord.js"; - import { ICommand } from "wokcommands"; - - export default { - name: "help", - category: "user", - description: "Shows the help embed", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["SEND_MESSAGES"], - - callback: async ({ client, interaction }) => { +import { MessageEmbed } from "discord.js"; +import { ICommand } from "wokcommands"; - const color = "#0099ff" ; - const thumbnail = "https://playantares.com/resources/CSSC-bot/cssc-server-icon.png"; - const title = "Help and Commands List"; - const description = "Welcome to CSSC-Bot! My purpose in this server is to make sure you have the correct roles for this server. My purpose mey evolve over time. You can always use this command to see my latest features."; - const fields = [ - { - name: "User Commands", - value: - "**/help** - Shows this help embed\n" + - "**/github** - Shows the official GitHub repository for this bot.\n" + - "**/view** - Shows a list of all roles that I have assigned to you\n" + - "**/clear** - Removes all roles that I have assigned to you\n" + - "**/uptime** - Shows how long I have been online\n" + - "**/status** - Shows the status of the bot" - }, - { - name: "Admin Commands", - value: - "**/createRoles** - Creates the roles that will be used in the server and in polls\n" + - "**/staffpoll** - Creates a poll for staff role choosing\n" + - "**/yearpoll** - Creates a poll for year role choosing\n" - }, - { - name: "Features", - value: - "**College Student Roles** - Assigns the correct role for your year in school.\n" + - "**College Employee Roles** - Assigns the correct role for your job title.", - } - ] - const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; - const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; +export default { + name: "help", + category: "user", + description: "Shows the help embed", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["SEND_MESSAGES"], - const Embed = new MessageEmbed() - .setColor(color) - .setTitle(title) - .setThumbnail(thumbnail) - .setDescription(description) - .addFields(fields) - .setFooter({text: footer, iconURL: footerIcon}); - interaction.reply({embeds: [Embed]}); - - // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/help`)} command in ${chalk.yellow(interaction.guild?.name)}`)); - } - } as ICommand; \ No newline at end of file + callback: async ({ client, interaction }) => { + const color = "#0099ff"; + const thumbnail = + "https://playantares.com/resources/CSSC-bot/cssc-server-icon.png"; + const title = "Help and Commands List"; + const description = + "Welcome to CSSC-Bot! My purpose in this server is to make sure you have the correct roles for this server. My purpose mey evolve over time. You can always use this command to see my latest features."; + const fields = [ + { + name: "User Commands", + value: + "**/help** - Shows this help embed\n" + + "**/github** - Shows the official GitHub repository for this bot.\n" + + "**/view** - Shows a list of all roles that I have assigned to you\n" + + "**/clear** - Removes all roles that I have assigned to you\n" + + "**/uptime** - Shows how long I have been online\n" + + "**/status** - Shows the status of the bot", + }, + { + name: "Admin Commands", + value: + "**/createRoles** - Creates the roles that will be used in the server and in polls\n" + + "**/staffpoll** - Creates a poll for staff role choosing\n" + + "**/yearpoll** - Creates a poll for year role choosing\n", + }, + { + name: "Features", + value: + "**College Student Roles** - Assigns the correct role for your year in school.\n" + + "**College Employee Roles** - Assigns the correct role for your job title.", + }, + ]; + const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; + const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; + + const Embed = new MessageEmbed() + .setColor(color) + .setTitle(title) + .setThumbnail(thumbnail) + .setDescription(description) + .addFields(fields) + .setFooter({ text: footer, iconURL: footerIcon }); + interaction.reply({ embeds: [Embed] }); + + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/help`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, +} as ICommand; diff --git a/commands/user/ping.ts b/commands/user/ping.ts index 69c2479..672d6b5 100644 --- a/commands/user/ping.ts +++ b/commands/user/ping.ts @@ -3,38 +3,40 @@ import { ICommand } from "wokcommands"; import chalk from "chalk"; export default { - name: "ping", - category: "user", - description: "Sends the ping time of the bot.", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["SEND_MESSAGES"], + name: "ping", + category: "user", + description: "Sends the ping time of the bot.", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["SEND_MESSAGES"], - callback: async ({ client, interaction }) => { - // Embed values - const color = "#0099ff"; - const title = "Bot/API Ping"; - const description = `Ping: 🏓 | Latency is: **${client.ws.ping}**ms.`; - const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; - const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; + callback: async ({ client, interaction }) => { + // Embed values + const color = "#0099ff"; + const title = "Bot/API Ping"; + const description = `Ping: 🏓 | Latency is: **${client.ws.ping}**ms.`; + const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; + const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; - const Embed = new MessageEmbed() - .setColor(color) - .setTitle(title) - .setDescription(description) - .setFooter({ text: footer, iconURL: footerIcon }); + const Embed = new MessageEmbed() + .setColor(color) + .setTitle(title) + .setDescription(description) + .setFooter({ text: footer, iconURL: footerIcon }); - // Return the embed - interaction.reply({ embeds: [Embed] }); + // Return the embed + interaction.reply({ embeds: [Embed] }); - // Log the command usage - console.log( - chalk.blue( - `${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/ping`)} command in ${chalk.yellow( - interaction.guild?.name - )}` - ) - ); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/ping`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/user/status.ts b/commands/user/status.ts index 53d1fef..22742c2 100644 --- a/commands/user/status.ts +++ b/commands/user/status.ts @@ -3,34 +3,44 @@ import { MessageEmbed } from "discord.js"; import { ICommand } from "wokcommands"; export default { - name: "status", - category: "user", - description: "Sends an embed with a link to the status page for the bot.", - slash: true, - testOnly: false, - guildOnly: true, - requiredPermissions: ["SEND_MESSAGES"], + name: "status", + category: "user", + description: "Sends an embed with a link to the status page for the bot.", + slash: true, + testOnly: false, + guildOnly: true, + requiredPermissions: ["SEND_MESSAGES"], - callback: async ({ client, interaction }) => { - // Embed values - const color = "#0099ff"; - const thumbnail = "https://playantares.com/resources/CSSC-bot/cssc-server-icon.png"; - const title = "Status Page"; - const description = "CLick here to see the bot's status: \nhttps://status.playantares.com"; - const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; - const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; + callback: async ({ client, interaction }) => { + // Embed values + const color = "#0099ff"; + const thumbnail = + "https://playantares.com/resources/CSSC-bot/cssc-server-icon.png"; + const title = "Status Page"; + const description = + "CLick here to see the bot's status: \nhttps://status.playantares.com"; + const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; + const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; - // Embed construction - const Embed = new MessageEmbed() - .setColor(color) - .setTitle(title) - .setThumbnail(thumbnail) - .setDescription(description) - .setFooter({ text: footer, iconURL: footerIcon }); + // Embed construction + const Embed = new MessageEmbed() + .setColor(color) + .setTitle(title) + .setThumbnail(thumbnail) + .setDescription(description) + .setFooter({ text: footer, iconURL: footerIcon }); - interaction.reply({ embeds: [Embed] }); + interaction.reply({ embeds: [Embed] }); - // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/status`)} command in ${chalk.yellow(interaction.guild?.name)}`)); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/status`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/user/uptime.ts b/commands/user/uptime.ts index 4f248cf..c2688cc 100644 --- a/commands/user/uptime.ts +++ b/commands/user/uptime.ts @@ -24,23 +24,31 @@ export default { const seconds = Math.floor(time / 1000) % 60; // Embed values - const color = "#0099ff" - const title = "Bot Uptime" - const description = `I have been online for ${days}d ${hours}h ${minutes}m ${seconds}s` + const color = "#0099ff"; + const title = "Bot Uptime"; + const description = `I have been online for ${days}d ${hours}h ${minutes}m ${seconds}s`; const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; - const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; - + const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; + // Embed construction const Embed = new MessageEmbed() .setColor(color) .setTitle(title) .setDescription(description) - .setFooter({text: footer, iconURL: footerIcon}); - + .setFooter({ text: footer, iconURL: footerIcon }); + // Return the embed - interaction.reply({embeds: [Embed]}); + interaction.reply({ embeds: [Embed] }); // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/uptime`)} command in ${chalk.yellow(interaction.guild?.name)}`)); + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/uptime`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); }, -} as ICommand; \ No newline at end of file +} as ICommand; diff --git a/commands/user/version.ts b/commands/user/version.ts index f6f833b..5a5d42f 100644 --- a/commands/user/version.ts +++ b/commands/user/version.ts @@ -3,38 +3,40 @@ import { ICommand } from "wokcommands"; import chalk from "chalk"; export default { - name: "version", - category: "user", - description: "Sends the version number of the bot", - slash: true, - guildOnly: true, - requiredPermissions: ["SEND_MESSAGES"], + name: "version", + category: "user", + description: "Sends the version number of the bot", + slash: true, + guildOnly: true, + requiredPermissions: ["SEND_MESSAGES"], - callback: async ({ client, interaction }) => { - // Embed values - const color = "#0099ff"; - const title = "Bot Version"; - const description = `I am running version: ${process.env.VERSION}`; - const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; - const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; + callback: async ({ client, interaction }) => { + // Embed values + const color = "#0099ff"; + const title = "Bot Version"; + const description = `I am running version: ${process.env.VERSION}`; + const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; + const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; - // Embed construction - const Embed = new MessageEmbed() - .setColor(color) - .setTitle(title) - .setDescription(description) - .setFooter({ text: footer, iconURL: footerIcon }); + // Embed construction + const Embed = new MessageEmbed() + .setColor(color) + .setTitle(title) + .setDescription(description) + .setFooter({ text: footer, iconURL: footerIcon }); - // Return the embed - interaction.reply({ embeds: [Embed] }); + // Return the embed + interaction.reply({ embeds: [Embed] }); - // Log the command usage - console.log( - chalk.blue( - `${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/version`)} command in ${chalk.yellow( - interaction.guild?.name - )}` - ) - ); - }, + // Log the command usage + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/version`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); + }, } as ICommand; diff --git a/commands/user/view.ts b/commands/user/view.ts index 59cc020..c6b0cd9 100644 --- a/commands/user/view.ts +++ b/commands/user/view.ts @@ -3,7 +3,6 @@ import { GuildMember } from "discord.js"; import { ICommand } from "wokcommands"; import { getUsersRoles } from "../../rolesOps"; - export default { name: "view", category: "user", @@ -14,20 +13,32 @@ export default { requiredPermissions: ["SEND_MESSAGES"], callback: async ({ interaction }) => { - // Remove roles from user if (!interaction.member) return; const list = await getUsersRoles(interaction.member as GuildMember); - // Reply to the user if (list === "") { - interaction.reply({content: "You don't have any College roles assigned to you.", ephemeral: true}); + interaction.reply({ + content: "You don't have any College roles assigned to you.", + ephemeral: true, + }); } else { - interaction.reply({content: "**Your roles:**\n" + list, ephemeral: true}); + interaction.reply({ + content: "**Your roles:**\n" + list, + ephemeral: true, + }); } // Log the command usage - console.log(chalk.blue(`${chalk.green(`[COMMAND]`)} ${chalk.yellow(interaction.user.tag)} used the ${chalk.green(`/view`)} command in ${chalk.yellow(interaction.guild?.name)}`)); + console.log( + chalk.blue( + `${chalk.green(`[COMMAND]`)} ${chalk.yellow( + interaction.user.tag + )} used the ${chalk.green(`/view`)} command in ${chalk.yellow( + interaction.guild?.name + )}` + ) + ); }, -} as ICommand; \ No newline at end of file +} as ICommand; diff --git a/features/interactionCreate.ts b/features/interactionCreate.ts index efe6fdf..2956a80 100644 --- a/features/interactionCreate.ts +++ b/features/interactionCreate.ts @@ -3,86 +3,86 @@ import { removeRole, addNewRole } from "../rolesOps"; // Listen interactionCreate events from the client export default (client: Client): void => { - client.on("interactionCreate", async (interaction) => { - // Make sure the interaction is from a select menu - if (!interaction.isSelectMenu()) return; - const color = "#0099ff"; - const description = `You selected the ${interaction.values[0]} role.`; - const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; - const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; - // Constants for all interactions - const member = interaction.member as GuildMember; + client.on("interactionCreate", async (interaction) => { + // Make sure the interaction is from a select menu + if (!interaction.isSelectMenu()) return; + const color = "#0099ff"; + const description = `You selected the ${interaction.values[0]} role.`; + const footer = `Delivered in: ${client.ws.ping}ms | CSSC-bot | ${process.env.VERSION}`; + const footerIcon = "https://playantares.com/resources/CSSC-bot/icon.jpg"; + // Constants for all interactions + const member = interaction.member as GuildMember; - // Get the select menu by it's custom ID - if (interaction.customId === "collegeYearPoll") { - // Set the embed values - const title = "College Year Poll"; + // Get the select menu by it's custom ID + if (interaction.customId === "collegeYearPoll") { + // Set the embed values + const title = "College Year Poll"; - // Create and send the embed object - interaction.reply({ - embeds: [ - new MessageEmbed() - .setColor(color) - .setTitle(title) - .setDescription(description) - .setFooter({ text: footer, iconURL: footerIcon }), - ], - ephemeral: true, - }); - // Remove any previous roles in the dictionary from the user - if (interaction.values[0] === "None") { - removeRole(member, "year"); - return; - } - removeRole(member, "year"); + // Create and send the embed object + interaction.reply({ + embeds: [ + new MessageEmbed() + .setColor(color) + .setTitle(title) + .setDescription(description) + .setFooter({ text: footer, iconURL: footerIcon }), + ], + ephemeral: true, + }); + // Remove any previous roles in the dictionary from the user + if (interaction.values[0] === "None") { + removeRole(member, "year"); + return; + } + removeRole(member, "year"); - // Assign the new role to the user - addNewRole(member, "year", interaction.values[0]); - } else if (interaction.customId === "collegeStaffPoll") { - // Set the embed title - const title = "College Staff Poll"; - // Create and send the embed object - interaction.reply({ - embeds: [ - new MessageEmbed() - .setColor(color) - .setTitle(title) - .setDescription(description) - .setFooter({ text: footer, iconURL: footerIcon }), - ], - ephemeral: true, - }); - // Remove any previous roles in the dictionary from the user - if (interaction.values[0] === "None") { - removeRole(member, "staff"); - return; - } - removeRole(member, "staff"); + // Assign the new role to the user + addNewRole(member, "year", interaction.values[0]); + } else if (interaction.customId === "collegeStaffPoll") { + // Set the embed title + const title = "College Staff Poll"; + // Create and send the embed object + interaction.reply({ + embeds: [ + new MessageEmbed() + .setColor(color) + .setTitle(title) + .setDescription(description) + .setFooter({ text: footer, iconURL: footerIcon }), + ], + ephemeral: true, + }); + // Remove any previous roles in the dictionary from the user + if (interaction.values[0] === "None") { + removeRole(member, "staff"); + return; + } + removeRole(member, "staff"); - // Assign the new role to the user - addNewRole(member, "staff", interaction.values[0]); - } else if (interaction.customId.startsWith("csClassPoll+")) { - // Set the embed title - const title = "CS Class Poll"; - // Create and send the embed object - interaction.reply({ - embeds: [ - new MessageEmbed() - .setColor(color) - .setTitle(title) - .setDescription(description) - .setFooter({ text: footer, iconURL: footerIcon }), - ], - ephemeral: true, - }); - // Assign the new role to the user + // Assign the new role to the user + addNewRole(member, "staff", interaction.values[0]); + } else if (interaction.customId.startsWith("csClassPoll+")) { + // Set the embed title + const title = "CS Class Poll"; + // Create and send the embed object + interaction.reply({ + embeds: [ + new MessageEmbed() + .setColor(color) + .setTitle(title) + .setDescription(description) + .setFooter({ text: footer, iconURL: footerIcon }), + ], + ephemeral: true, + }); + // Assign the new role to the user - addNewRole(member, "class", interaction.values[0]); - } - }); + addNewRole(member, "class", interaction.values[0]); + } + }); }; export const config = { - dbName: "INTERACTION_CREATE", - displayName: "Interaction Create Event (ICE)", + dbName: "INTERACTION_CREATE", + displayName: "Interaction Create Event (ICE)", }; diff --git a/features/status-changer.ts b/features/status-changer.ts index 0d0cd9f..c232230 100644 --- a/features/status-changer.ts +++ b/features/status-changer.ts @@ -1,42 +1,39 @@ import { Client } from "discord.js"; - export default async (client: Client) => { - - const statusOptions = [ - `/help | Ping: ${client.ws.ping}ms`, - `V.${process.env.VERSION}`, - `status.playantares.com`, - `playantares.com/github`, - `status.playantares.com`, - `Antares Network Server Hosting`, - 'Go to #roles!', - 'Hello! I\'m CSSC-Bot', - -]; - let counter = 0; - - const updateStatus = () => { - client.user?.setPresence({ - status: "online", - activities: [ - { - name: statusOptions[counter], - type: "PLAYING", - }, - ], - }); - - if (++counter >= statusOptions.length) { - counter = 0; - } - - setTimeout(updateStatus, 1000 * 60 * 5); - }; - updateStatus(); + const statusOptions = [ + `/help | Ping: ${client.ws.ping}ms`, + `V.${process.env.VERSION}`, + `status.playantares.com`, + `playantares.com/github`, + `status.playantares.com`, + `Antares Network Server Hosting`, + "Go to #roles!", + "Hello! I'm CSSC-Bot", + ]; + let counter = 0; + + const updateStatus = () => { + client.user?.setPresence({ + status: "online", + activities: [ + { + name: statusOptions[counter], + type: "PLAYING", + }, + ], + }); + + if (++counter >= statusOptions.length) { + counter = 0; + } + + setTimeout(updateStatus, 1000 * 60 * 5); + }; + updateStatus(); }; export const config = { - dbName: "STATUS_CHANGER", - displayName: "Status Changer", -}; \ No newline at end of file + dbName: "STATUS_CHANGER", + displayName: "Status Changer", +}; diff --git a/features/statuspage.ts b/features/statuspage.ts index fc4b6bc..2c09c0d 100644 --- a/features/statuspage.ts +++ b/features/statuspage.ts @@ -1,18 +1,18 @@ - import axios from "axios"; import { Client } from "discord.js"; -export default (client: Client): void => { - const updateStatus = async () => { - // This function is called every 1 minutes and pings the network status page for uptime monitoring - axios.get(`https://${process.env.UPTIME_KUMA_MONITOR_DOMAIN}/api/push/${process.env.UPTIME_KUMA_MONITOR_ID}?msg=OK&ping=${client.ws.ping}`); - setTimeout(updateStatus, 1000 * 60); - }; - updateStatus() - .catch(err => console.log(err)); +export default (client: Client): void => { + const updateStatus = async () => { + // This function is called every 1 minutes and pings the network status page for uptime monitoring + axios.get( + `https://${process.env.UPTIME_KUMA_MONITOR_DOMAIN}/api/push/${process.env.UPTIME_KUMA_MONITOR_ID}?msg=OK&ping=${client.ws.ping}` + ); + setTimeout(updateStatus, 1000 * 60); + }; + updateStatus().catch((err) => console.log(err)); }; export const config = { - dbName: "STATUSPAGE_UPDATE", - displayName: "Status Page Update", -}; \ No newline at end of file + dbName: "STATUSPAGE_UPDATE", + displayName: "Status Page Update", +}; diff --git a/index.ts b/index.ts index 05be61e..3bea332 100644 --- a/index.ts +++ b/index.ts @@ -13,60 +13,73 @@ dotenv.config(); // Create a new Discord client const client = new DiscordJs.Client({ - intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS], + intents: [ + Intents.FLAGS.GUILDS, + Intents.FLAGS.GUILD_MESSAGES, + Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, + Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, + ], }); client.on("ready", () => { - if (client.user) { - console.log(chalk.green(`Logged in as ${client.user.tag}!`)); - console.log(chalk.yellow.bold(`I am running version: ${process.env.VERSION}`)); - // Check to make sure the roles exist in all servers - console.log("Checking if all roles exist in servers.") - client.guilds.cache.forEach(async (guild) => { - checkForRoles(guild); - }); - } + if (client.user) { + console.log(chalk.green(`Logged in as ${client.user.tag}!`)); + console.log( + chalk.yellow.bold(`I am running version: ${process.env.VERSION}`) + ); + // Check to make sure the roles exist in all servers + console.log("Checking if all roles exist in servers."); + client.guilds.cache.forEach(async (guild) => { + checkForRoles(guild); + }); + } - const dbOptions = { - // These are the default values - keepAlive: true, - useNewUrlParser: true, - useUnifiedTopology: true, - }; + const dbOptions = { + // These are the default values + keepAlive: true, + useNewUrlParser: true, + useUnifiedTopology: true, + }; - // Set up the WOKCommands instance - const wok = new WOKCommands(client, { - commandDir: path.join(__dirname, "commands"), - featureDir: path.join(__dirname, "features"), - dbOptions, - typeScript: true, - mongoUri: String(process.env.MONGODB_URI), - disabledDefaultCommands: ["help", "language"], - botOwners: ["603629606154666024", "680813135556378634", "451761128704573440"], - }).setDefaultPrefix(String(process.env.BOT_DEFAULT_PREFIX)); + // Set up the WOKCommands instance + const wok = new WOKCommands(client, { + commandDir: path.join(__dirname, "commands"), + featureDir: path.join(__dirname, "features"), + dbOptions, + typeScript: true, + mongoUri: String(process.env.MONGODB_URI), + disabledDefaultCommands: ["help", "language"], + botOwners: [ + "603629606154666024", + "680813135556378634", + "451761128704573440", + ], + }).setDefaultPrefix(String(process.env.BOT_DEFAULT_PREFIX)); - // Set up the connection to the database - wok.on("databaseConnected", async () => { - console.log(chalk.green("Connected to the database")); - }); + // Set up the connection to the database + wok.on("databaseConnected", async () => { + console.log(chalk.green("Connected to the database")); + }); }); // Catch all errors that are not handled well and just dump to the console. THis will be changed later but for now it's fine. client.on("error", console.error); client.on("warn", (e) => console.warn(e)); process.on("unhandledRejection", (promise, reason) => { - console.error("Unhandled promise rejection:", promise, "\nreason", reason); + console.error("Unhandled promise rejection:", promise, "\nreason", reason); }); // Login to Discord with the bot token and display an error if it fails. client.login(process.env.BOT_TOKEN).catch((error) => { - console.log(chalk.red.bold(`There was an error connecting to the Discord API`)); - console.error(error); - process.exit(1); + console.log( + chalk.red.bold(`There was an error connecting to the Discord API`) + ); + console.error(error); + process.exit(1); }); // Exit gracefully and print the exit code. process.on("exit", (code) => { - console.log("Now exiting..."); - console.log(`Exited with status code: ${code}`); -}); \ No newline at end of file + console.log("Now exiting..."); + console.log(`Exited with status code: ${code}`); +}); diff --git a/models/classModel.ts b/models/classModel.ts index fbcf549..6413cb9 100644 --- a/models/classModel.ts +++ b/models/classModel.ts @@ -2,16 +2,16 @@ import mongoose, { Schema } from "mongoose"; const CLASS = new Schema({ id: String, - CODE: String, - TITLE: String, - INFO: String, - ROLE_NAME: String, - ROLE_ID: String, - CHANNEL_NAME: String, - CHANNEL_ID: String, - UUID: String + CODE: String, + TITLE: String, + INFO: String, + ROLE_NAME: String, + ROLE_ID: String, + CHANNEL_NAME: String, + CHANNEL_ID: String, + UUID: String, }); const name = "class"; -export = mongoose.models[name] || mongoose.model(name, CLASS, name); \ No newline at end of file +export = mongoose.models[name] || mongoose.model(name, CLASS, name); diff --git a/models/staffModel.ts b/models/staffModel.ts index b0b3532..d92ace9 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -2,11 +2,11 @@ import mongoose, { Schema } from "mongoose"; const STAFF = new Schema({ id: String, - NAME: String, - ROLE_NAME: String, - ROLE_ID: String, + NAME: String, + ROLE_NAME: String, + ROLE_ID: String, }); const name = "staff"; -export = mongoose.models[name] || mongoose.model(name, STAFF, name); \ No newline at end of file +export = mongoose.models[name] || mongoose.model(name, STAFF, name); diff --git a/models/yearModel.ts b/models/yearModel.ts index 5c7da47..f8bd9f0 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -2,12 +2,11 @@ import mongoose, { Schema } from "mongoose"; const YEAR = new Schema({ id: String, - NAME: String, - ROLE_NAME: String, - ROLE_ID: String, - + NAME: String, + ROLE_NAME: String, + ROLE_ID: String, }); const name = "year"; -export = mongoose.models[name] || mongoose.model(name, YEAR, name); \ No newline at end of file +export = mongoose.models[name] || mongoose.model(name, YEAR, name); diff --git a/rolesOps.ts b/rolesOps.ts index d390781..ca6ead1 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -4,111 +4,133 @@ import classModel from "./models/classModel"; import staffModel from "./models/staffModel"; import yearModel from "./models/yearModel"; - -async function dbQuery(){ - const classes = await classModel.find({}); - const staff = await staffModel.find({}); - const years = await yearModel.find({}); - return [classes, staff, years]; +async function dbQuery() { + const classes = await classModel.find({}); + const staff = await staffModel.find({}); + const years = await yearModel.find({}); + return [classes, staff, years]; } export async function getUsersRoles(member: GuildMember): Promise { - let list = ""; - for (const group of await dbQuery()) { - for (const element of group) { - if (member.roles.cache.has(element.ROLE_ID)) { - list += `${member.guild.roles.cache.get(element.ROLE_ID)?.name}\n`; - } - } - } - return list; + let list = ""; + for (const group of await dbQuery()) { + for (const element of group) { + if (member.roles.cache.has(element.ROLE_ID)) { + list += `${member.guild.roles.cache.get(element.ROLE_ID)?.name}\n`; + } + } + } + return list; } -export async function removeRole(member: GuildMember, type: string): Promise { - // This function is triggered when a user changes their role, - // it removes the previous role from the user - let list = []; - if (type === "class") { - list = await classModel.find({}); - } else if (type === "staff") { - list = await staffModel.find({}); - } else if (type === "year") { - list = await yearModel.find({}); - } +export async function removeRole( + member: GuildMember, + type: string +): Promise { + // This function is triggered when a user changes their role, + // it removes the previous role from the user + let list = []; + if (type === "class") { + list = await classModel.find({}); + } else if (type === "staff") { + list = await staffModel.find({}); + } else if (type === "year") { + list = await yearModel.find({}); + } - for (const role of list) { - if (member.roles.cache.has(role.ROLE_ID)) { - await member.roles.remove(role.ROLE_ID); - console.log(chalk.green(`Removed role ${chalk.green(role.ROLE_ID)} from ${chalk.yellow(member.user.tag)}`)); - } - } + for (const role of list) { + if (member.roles.cache.has(role.ROLE_ID)) { + await member.roles.remove(role.ROLE_ID); + console.log( + chalk.green( + `Removed role ${chalk.green(role.ROLE_ID)} from ${chalk.yellow( + member.user.tag + )}` + ) + ); + } + } } -export async function addNewRole(member: GuildMember, type: string, id: string) { - // This function is triggered when a user changes their role, it adds the new role to the user - let role; - if (type === "class") { - role = await classModel.findOne({ CODE: id }); - } else if (type === "staff") { - role = await staffModel.findOne({ NAME: id }); - } else if (type === "year") { - role = await yearModel.findOne({ NAME: id }); - } - if (!member.roles.cache.has(role?.ROLE_ID)) { - await member.roles.add(role?.ROLE_ID); - console.log(chalk.green(`Added role ${chalk.green(role.ROLE_NAME)} to ${chalk.yellow(member.user.tag)}`)); - } +export async function addNewRole( + member: GuildMember, + type: string, + id: string +) { + // This function is triggered when a user changes their role, it adds the new role to the user + let role; + if (type === "class") { + role = await classModel.findOne({ CODE: id }); + } else if (type === "staff") { + role = await staffModel.findOne({ NAME: id }); + } else if (type === "year") { + role = await yearModel.findOne({ NAME: id }); + } + if (!member.roles.cache.has(role?.ROLE_ID)) { + await member.roles.add(role?.ROLE_ID); + console.log( + chalk.green( + `Added role ${chalk.green(role.ROLE_NAME)} to ${chalk.yellow( + member.user.tag + )}` + ) + ); + } } export async function createRoles(guild: Guild, type: string): Promise { - let list; - if (type === "class") { - list = await classModel.find({}); - } else if (type === "staff") { - list = await staffModel.find({}); - } else if (type === "year") { - list = await yearModel.find({}); - } + let list; + if (type === "class") { + list = await classModel.find({}); + } else if (type === "staff") { + list = await staffModel.find({}); + } else if (type === "year") { + list = await yearModel.find({}); + } - list?.forEach(async (element) => { - if (!guild.roles.cache.find((r) => r.name === element.ROLE_NAME)) { - // Create the role - const role = await guild.roles.create({ name: element.ROLE_NAME }); - element.ROLE_ID = role.id; - element.save(); - // Print the role id to the console - console.log(chalk.yellow(`${element}: ${role?.id}`)); - } else { - // If the role already exists, print the id to the console - const role = guild.roles.cache.find((r) => r.name === element.ROLE_NAME); - element.ROLE_ID = role?.id; - element.save(); - console.log(chalk.yellow(`${element}: ${role?.id}`)); - } - }); + list?.forEach(async (element) => { + if (!guild.roles.cache.find((r) => r.name === element.ROLE_NAME)) { + // Create the role + const role = await guild.roles.create({ name: element.ROLE_NAME }); + element.ROLE_ID = role.id; + element.save(); + // Print the role id to the console + console.log(chalk.yellow(`${element}: ${role?.id}`)); + } else { + // If the role already exists, print the id to the console + const role = guild.roles.cache.find((r) => r.name === element.ROLE_NAME); + element.ROLE_ID = role?.id; + element.save(); + console.log(chalk.yellow(`${element}: ${role?.id}`)); + } + }); } export async function checkForRoles(guild: Guild): Promise { - // Check if all roles exist in a guild - // Return true if they do, false if they don't + // Check if all roles exist in a guild + // Return true if they do, false if they don't - let collection: boolean[] = []; + let collection: boolean[] = []; - for (const group of await dbQuery()) { - for (const element of group) { - const name = guild.roles.cache.find((r) => r.name === element.ROLE_NAME); - const id = guild.roles.cache.find((r) => r.id === element.ROLE_ID); + for (const group of await dbQuery()) { + for (const element of group) { + const name = guild.roles.cache.find((r) => r.name === element.ROLE_NAME); + const id = guild.roles.cache.find((r) => r.id === element.ROLE_ID); - if (name == undefined && id == undefined) { - console.log(chalk.red.bold(`Role ${name} does not exist in ${guild.name}, Please run the /createRoles command in that server.`)); - collection.push(false); - } - } - } - if (collection.includes(false)) { - return false; - } else { - console.log(chalk.yellow.bold(`All roles in list exist in ${guild.name}`)); - return true; - } + if (name == undefined && id == undefined) { + console.log( + chalk.red.bold( + `Role ${name} does not exist in ${guild.name}, Please run the /createRoles command in that server.` + ) + ); + collection.push(false); + } + } + } + if (collection.includes(false)) { + return false; + } else { + console.log(chalk.yellow.bold(`All roles in list exist in ${guild.name}`)); + return true; + } }