From 0d0363fe83550b410a71cd8cdf15522ba79a57b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Sep 2022 22:59:06 +0000 Subject: [PATCH 01/53] Bump mongoose from 6.5.3 to 6.5.4 Bumps [mongoose](https://github.com/Automattic/mongoose) from 6.5.3 to 6.5.4. - [Release notes](https://github.com/Automattic/mongoose/releases) - [Changelog](https://github.com/Automattic/mongoose/blob/master/CHANGELOG.md) - [Commits](https://github.com/Automattic/mongoose/compare/6.5.3...6.5.4) --- updated-dependencies: - dependency-name: mongoose dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 059f41a..c7cc6de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "axios": "^0.27.2", "chalk": "^4.1.2", "discord.js": "^13.9.2", - "mongoose": "^6.2.2", + "mongoose": "^6.5.4", "path": "^0.12.7", "prettier": "^2.7.1", "ts-node": "^10.5.0", @@ -548,9 +548,9 @@ } }, "node_modules/mongoose": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.5.3.tgz", - "integrity": "sha512-0L2ZOPzNQ7kcIgpdfpmVXc+/SypdhzcTlaHXYa983u1lrVp7/i3ekwHpPiTXxYBvV6FwBAsFoHI7+Ovf8tp3Mg==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.5.4.tgz", + "integrity": "sha512-8hKV+9baDa7fyWRADQcSN/c0/QQbnewA2D0xOqdFb7f1UGYAHk4YSMNu9Hu2bdRUfQbK/daFuqlcmI17j6/8eg==", "dependencies": { "bson": "^4.6.5", "kareem": "2.4.1", @@ -1255,9 +1255,9 @@ } }, "mongoose": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.5.3.tgz", - "integrity": "sha512-0L2ZOPzNQ7kcIgpdfpmVXc+/SypdhzcTlaHXYa983u1lrVp7/i3ekwHpPiTXxYBvV6FwBAsFoHI7+Ovf8tp3Mg==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.5.4.tgz", + "integrity": "sha512-8hKV+9baDa7fyWRADQcSN/c0/QQbnewA2D0xOqdFb7f1UGYAHk4YSMNu9Hu2bdRUfQbK/daFuqlcmI17j6/8eg==", "requires": { "bson": "^4.6.5", "kareem": "2.4.1", diff --git a/package.json b/package.json index e04d259..5d3be28 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "axios": "^0.27.2", "chalk": "^4.1.2", "discord.js": "^13.9.2", - "mongoose": "^6.2.2", + "mongoose": "^6.5.4", "path": "^0.12.7", "prettier": "^2.7.1", "ts-node": "^10.5.0", From 79cb7fa1fb2862ebf2d8a71a9822ecf44f41da77 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Sep 2022 22:59:37 +0000 Subject: [PATCH 02/53] Bump chalk from 4.1.2 to 5.0.1 Bumps [chalk](https://github.com/chalk/chalk) from 4.1.2 to 5.0.1. - [Release notes](https://github.com/chalk/chalk/releases) - [Commits](https://github.com/chalk/chalk/compare/v4.1.2...v5.0.1) --- updated-dependencies: - dependency-name: chalk dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package-lock.json | 107 ++++------------------------------------------ package.json | 2 +- 2 files changed, 9 insertions(+), 100 deletions(-) diff --git a/package-lock.json b/package-lock.json index 059f41a..6167d8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "axios": "^0.27.2", - "chalk": "^4.1.2", + "chalk": "^5.0.1", "discord.js": "^13.9.2", "mongoose": "^6.2.2", "path": "^0.12.7", @@ -196,20 +196,6 @@ "node": ">=0.4.0" } }, - "node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, "node_modules/arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", @@ -283,36 +269,16 @@ } }, "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", + "integrity": "sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==", "engines": { - "node": ">=10" + "node": "^12.17.0 || ^14.13 || >=16.0.0" }, "funding": { "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -444,14 +410,6 @@ "node": ">= 6" } }, - "node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "engines": { - "node": ">=8" - } - }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -717,17 +675,6 @@ "memory-pager": "^1.0.2" } }, - "node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", @@ -1019,14 +966,6 @@ "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==" }, - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "requires": { - "color-convert": "^2.0.1" - } - }, "arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", @@ -1069,26 +1008,9 @@ } }, "chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", + "integrity": "sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==" }, "combined-stream": { "version": "1.0.8", @@ -1179,11 +1101,6 @@ "mime-types": "^2.1.12" } }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" - }, "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -1376,14 +1293,6 @@ "memory-pager": "^1.0.2" } }, - "supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "requires": { - "has-flag": "^4.0.0" - } - }, "tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", diff --git a/package.json b/package.json index e04d259..83efd86 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "homepage": "https://github.com/Antares-Network/CSSC-Bot#readme", "dependencies": { "axios": "^0.27.2", - "chalk": "^4.1.2", + "chalk": "^5.0.1", "discord.js": "^13.9.2", "mongoose": "^6.2.2", "path": "^0.12.7", From e2fedd85daa112f9c632c795f2f5483dab900667 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 17:19:14 -0500 Subject: [PATCH 03/53] Ignore all .env files --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2358922..6ca9203 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ **/__pycache__ .vscode -.env +*.env node_modules unused-commands d.py/ \ No newline at end of file From 5e0b6ac7598811877d38a4c4e762db5d84a5a3dc Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 19:12:45 -0500 Subject: [PATCH 04/53] Add interfaces for Schemas Update csClassPoll to reflect the update --- commands/owner/csClassPoll.ts | 16 ++++------------ models/classModel.ts | 18 ++++++++++++++---- models/staffModel.ts | 13 +++++++++---- models/yearModel.ts | 13 +++++++++---- rolesOps.ts | 6 +++--- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index 6bee095..f97609f 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -6,18 +6,9 @@ import { } from "discord.js"; import chalk from "chalk"; import { ICommand } from "wokcommands"; -import classModel from "../../models/classModel"; +import { classModel, IClass } from "../../models/classModel"; import { checkForRoles } from "../../rolesOps"; -export interface Class { - CODE: string; - TITLE: string; - INFO: string; - ROLE_NAME: string; - ROLE_ID: string; - UUID: string; -} - export default { name: "csClassPoll", category: "owner", @@ -36,7 +27,8 @@ export default { return; } - let classes: Class[] = await classModel.find({}).sort({ CODE: 1 }); + // let classes: IClass[] = await classModel.find({}).sort({ CODE: 1 }); + let classes = await classModel.find({}).sort({ CODE: 1 }); const class_chunks = split_list(classes, 25); let rows: MessageActionRow[] = []; @@ -103,7 +95,7 @@ function split_list(list: Array, max_list_len: number) { } // consumes a Class and returns Message Selec tOption data -function create_option_from_class(_class: Class): MessageSelectOptionData { +function create_option_from_class(_class: IClass): MessageSelectOptionData { return { label: _class.CODE, value: _class.CODE, diff --git a/models/classModel.ts b/models/classModel.ts index 6413cb9..96e1988 100644 --- a/models/classModel.ts +++ b/models/classModel.ts @@ -1,6 +1,18 @@ import mongoose, { Schema } from "mongoose"; -const CLASS = new Schema({ +export interface IClass { + id: string; + CODE: string; + TITLE: string; + INFO: string; + ROLE_NAME: string; + ROLE_ID: string; + CHANNEL_NAME: string; + CHANNEL_ID: string; + UUID: string; +} + +const ClassSchema = new Schema({ id: String, CODE: String, TITLE: String, @@ -12,6 +24,4 @@ const CLASS = new Schema({ UUID: String, }); -const name = "class"; - -export = mongoose.models[name] || mongoose.model(name, CLASS, name); +export let classModel = mongoose.model("class", ClassSchema); diff --git a/models/staffModel.ts b/models/staffModel.ts index d92ace9..48a253d 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -1,12 +1,17 @@ import mongoose, { Schema } from "mongoose"; -const STAFF = new Schema({ +export interface IStaff { + id: string; + NAME: string; + ROLE_NAME: string; + ROLE_ID: string; +} + +const StaffSchema = new Schema({ id: String, NAME: String, ROLE_NAME: String, ROLE_ID: String, }); -const name = "staff"; - -export = mongoose.models[name] || mongoose.model(name, STAFF, name); +export let staffModel = mongoose.model("staff", StaffSchema); diff --git a/models/yearModel.ts b/models/yearModel.ts index f8bd9f0..2d54a71 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -1,12 +1,17 @@ import mongoose, { Schema } from "mongoose"; -const YEAR = new Schema({ +export interface IYear { + id: string; + NAME: string; + ROLE_NAME: string; + ROLE_ID: string; +} + +const YearSchema = new Schema({ id: String, NAME: String, ROLE_NAME: String, ROLE_ID: String, }); -const name = "year"; - -export = mongoose.models[name] || mongoose.model(name, YEAR, name); +export let yearModel = mongoose.model("year", YearSchema); diff --git a/rolesOps.ts b/rolesOps.ts index ca6ead1..01ccaee 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -1,8 +1,8 @@ import { GuildMember, Guild } from "discord.js"; import chalk from "chalk"; -import classModel from "./models/classModel"; -import staffModel from "./models/staffModel"; -import yearModel from "./models/yearModel"; +import { classModel } from "./models/classModel"; +import { staffModel } from "./models/staffModel"; +import { yearModel } from "./models/yearModel"; async function dbQuery() { const classes = await classModel.find({}); From 59a53643d59f48ee4c2006df6a13f14be967b399 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 20:05:04 -0500 Subject: [PATCH 05/53] update models make fields required Add null checks to role operations --- models/classModel.ts | 18 +++++++++--------- models/staffModel.ts | 12 ++++++------ models/yearModel.ts | 8 ++++---- rolesOps.ts | 29 ++++++++++++++++++----------- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/models/classModel.ts b/models/classModel.ts index 96e1988..db769a1 100644 --- a/models/classModel.ts +++ b/models/classModel.ts @@ -13,15 +13,15 @@ export interface IClass { } const ClassSchema = new Schema({ - id: String, - CODE: String, - TITLE: String, - INFO: String, - ROLE_NAME: String, - ROLE_ID: String, - CHANNEL_NAME: String, - CHANNEL_ID: String, - UUID: String, + id: { type: String, required: true }, + CODE: { type: String, required: true }, + TITLE: { type: String, required: true }, + INFO: { type: String, required: true }, + ROLE_NAME: { type: String, required: true }, + ROLE_ID: { type: String, required: true }, + CHANNEL_NAME: { type: String, required: true }, + CHANNEL_ID: { type: String, required: true }, + UUID: { type: String, default: "remove" }, }); export let classModel = mongoose.model("class", ClassSchema); diff --git a/models/staffModel.ts b/models/staffModel.ts index 48a253d..cf89164 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -1,4 +1,4 @@ -import mongoose, { Schema } from "mongoose"; +import mongoose, { Schema, model } from "mongoose"; export interface IStaff { id: string; @@ -8,10 +8,10 @@ export interface IStaff { } const StaffSchema = new Schema({ - id: String, - NAME: String, - ROLE_NAME: String, - ROLE_ID: String, + id: { type: String, required: true }, + NAME: { type: String, required: true }, + ROLE_NAME: { type: String, required: true }, + ROLE_ID: { type: String, required: true }, }); -export let staffModel = mongoose.model("staff", StaffSchema); +export let staffModel = model("staff", StaffSchema); diff --git a/models/yearModel.ts b/models/yearModel.ts index 2d54a71..86513f6 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -8,10 +8,10 @@ export interface IYear { } const YearSchema = new Schema({ - id: String, - NAME: String, - ROLE_NAME: String, - ROLE_ID: String, + id: { type: String, required: true }, + NAME: { type: String, required: true }, + ROLE_NAME: { type: String, required: true }, + ROLE_ID: { type: String, required: true }, }); export let yearModel = mongoose.model("year", YearSchema); diff --git a/rolesOps.ts b/rolesOps.ts index 01ccaee..80b0b49 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -1,8 +1,8 @@ import { GuildMember, Guild } from "discord.js"; import chalk from "chalk"; -import { classModel } from "./models/classModel"; -import { staffModel } from "./models/staffModel"; -import { yearModel } from "./models/yearModel"; +import { classModel, IClass } from "./models/classModel"; +import { staffModel, IStaff } from "./models/staffModel"; +import { yearModel, IYear } from "./models/yearModel"; async function dbQuery() { const classes = await classModel.find({}); @@ -29,7 +29,7 @@ export async function removeRole( ): Promise { // This function is triggered when a user changes their role, // it removes the previous role from the user - let list = []; + let list: any[] = []; if (type === "class") { list = await classModel.find({}); } else if (type === "staff") { @@ -58,7 +58,7 @@ export async function addNewRole( id: string ) { // This function is triggered when a user changes their role, it adds the new role to the user - let role; + let role: IClass | IYear | IStaff | null = null; if (type === "class") { role = await classModel.findOne({ CODE: id }); } else if (type === "staff") { @@ -66,8 +66,11 @@ export async function addNewRole( } 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); + if (role === null) { + throw new Error(`No roll found with id: ${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( @@ -79,7 +82,7 @@ export async function addNewRole( } export async function createRoles(guild: Guild, type: string): Promise { - let list; + let list = null; if (type === "class") { list = await classModel.find({}); } else if (type === "staff") { @@ -98,10 +101,14 @@ export async function createRoles(guild: Guild, type: string): Promise { 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; + const id = guild.roles.cache.find( + (r) => r.name === element.ROLE_NAME + )?.id; + if (id !== undefined) { + element.ROLE_ID = id; + } element.save(); - console.log(chalk.yellow(`${element}: ${role?.id}`)); + console.log(chalk.yellow(`${element}: ${id}`)); } }); } From 344a2b1ecfe9cb6132b9c1a7a3348235e00a33b0 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 21:42:51 -0500 Subject: [PATCH 06/53] Update model exports --- models/classModel.ts | 4 +++- models/staffModel.ts | 5 ++++- models/yearModel.ts | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/models/classModel.ts b/models/classModel.ts index db769a1..9980f78 100644 --- a/models/classModel.ts +++ b/models/classModel.ts @@ -24,4 +24,6 @@ const ClassSchema = new Schema({ UUID: { type: String, default: "remove" }, }); -export let classModel = mongoose.model("class", ClassSchema); +const name = "class"; + +export const classModel = mongoose.model(name, ClassSchema, name); diff --git a/models/staffModel.ts b/models/staffModel.ts index cf89164..ed52c8e 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -14,4 +14,7 @@ const StaffSchema = new Schema({ ROLE_ID: { type: String, required: true }, }); -export let staffModel = model("staff", StaffSchema); +// export let staffModel = model("staff", StaffSchema); +const name = "staff"; + +export const staffModel = mongoose.model(name, StaffSchema, name); diff --git a/models/yearModel.ts b/models/yearModel.ts index 86513f6..e2bce3b 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -14,4 +14,6 @@ const YearSchema = new Schema({ ROLE_ID: { type: String, required: true }, }); -export let yearModel = mongoose.model("year", YearSchema); +// export let yearModel = mongoose.model("year", YearSchema); +const name = "year"; +export let yearModel = mongoose.model(name, YearSchema, name); From 8d51103339f4fa0f20e2de9719a776470a691112 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 21:43:15 -0500 Subject: [PATCH 07/53] Add checks to make sure collections exist on boot --- index.ts | 8 +++++++- rolesOps.ts | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 3bea332..e75901e 100644 --- a/index.ts +++ b/index.ts @@ -6,7 +6,10 @@ import chalk from "chalk"; import dotenv from "dotenv"; // import custom modules -import { checkForRoles } from "./rolesOps"; +import { checkForRoles, checkIfCollectionsExist } from "./rolesOps"; +import { classModel } from "./models/classModel"; +import { staffModel } from "./models/staffModel"; +import { yearModel } from "./models/yearModel"; // import all environment variables from .env file dotenv.config(); @@ -58,6 +61,9 @@ client.on("ready", () => { // Set up the connection to the database wok.on("databaseConnected", async () => { + checkIfCollectionsExist(classModel); + checkIfCollectionsExist(staffModel); + checkIfCollectionsExist(yearModel); console.log(chalk.green("Connected to the database")); }); }); diff --git a/rolesOps.ts b/rolesOps.ts index 80b0b49..81c751b 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -3,7 +3,13 @@ import chalk from "chalk"; import { classModel, IClass } from "./models/classModel"; import { staffModel, IStaff } from "./models/staffModel"; import { yearModel, IYear } from "./models/yearModel"; +import { Model } from "mongoose"; +export async function checkIfCollectionsExist(model: Model) { + if (!(await model.exists({}))) { + throw new Error(`${model.name} collection does not exist`); + } +} async function dbQuery() { const classes = await classModel.find({}); const staff = await staffModel.find({}); From cbf250ff79906acf457762849e6995d4c19ba9b5 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 21:46:55 -0500 Subject: [PATCH 08/53] Update model requirements --- models/classModel.ts | 6 +++--- models/staffModel.ts | 2 +- models/yearModel.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/models/classModel.ts b/models/classModel.ts index 9980f78..af644d2 100644 --- a/models/classModel.ts +++ b/models/classModel.ts @@ -13,14 +13,14 @@ export interface IClass { } const ClassSchema = new Schema({ - id: { type: String, required: true }, + id: { type: String }, CODE: { type: String, required: true }, TITLE: { type: String, required: true }, INFO: { type: String, required: true }, ROLE_NAME: { type: String, required: true }, ROLE_ID: { type: String, required: true }, - CHANNEL_NAME: { type: String, required: true }, - CHANNEL_ID: { type: String, required: true }, + CHANNEL_NAME: { type: String }, + CHANNEL_ID: { type: String }, UUID: { type: String, default: "remove" }, }); diff --git a/models/staffModel.ts b/models/staffModel.ts index ed52c8e..8f4e37e 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -8,7 +8,7 @@ export interface IStaff { } const StaffSchema = new Schema({ - id: { type: String, required: true }, + id: { type: String }, NAME: { type: String, required: true }, ROLE_NAME: { type: String, required: true }, ROLE_ID: { type: String, required: true }, diff --git a/models/yearModel.ts b/models/yearModel.ts index e2bce3b..0d8721e 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -8,7 +8,7 @@ export interface IYear { } const YearSchema = new Schema({ - id: { type: String, required: true }, + id: { type: String }, NAME: { type: String, required: true }, ROLE_NAME: { type: String, required: true }, ROLE_ID: { type: String, required: true }, From e320cfee69c43a7d151de6be6606dcced27eb221 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 21:47:06 -0500 Subject: [PATCH 09/53] Remove unnecessary log line --- commands/owner/createRoles.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/commands/owner/createRoles.ts b/commands/owner/createRoles.ts index 992c297..6cee1c9 100644 --- a/commands/owner/createRoles.ts +++ b/commands/owner/createRoles.ts @@ -13,11 +13,7 @@ export default { ownerOnly: true, callback: async ({ interaction }) => { - console.log( - chalk.green( - "Creating roles...\nCopy and paste the following output into your .env file" - ) - ); + console.log(chalk.green("Creating roles...")); console.log( chalk.red("------------------------------------------------------") ); From cf86634d6fd05386688ccd03929b2c36f85d4151 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 21:49:54 -0500 Subject: [PATCH 10/53] remove commented out code --- models/staffModel.ts | 1 - models/yearModel.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/models/staffModel.ts b/models/staffModel.ts index 8f4e37e..254164d 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -14,7 +14,6 @@ const StaffSchema = new Schema({ ROLE_ID: { type: String, required: true }, }); -// export let staffModel = model("staff", StaffSchema); const name = "staff"; export const staffModel = mongoose.model(name, StaffSchema, name); diff --git a/models/yearModel.ts b/models/yearModel.ts index 0d8721e..d809da0 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -14,6 +14,5 @@ const YearSchema = new Schema({ ROLE_ID: { type: String, required: true }, }); -// export let yearModel = mongoose.model("year", YearSchema); const name = "year"; export let yearModel = mongoose.model(name, YearSchema, name); From a64c376379b6e846051f35100df7db87c8dc3813 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 21:58:11 -0500 Subject: [PATCH 11/53] remove unused import --- models/staffModel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/staffModel.ts b/models/staffModel.ts index 254164d..1f8c7f4 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -1,4 +1,4 @@ -import mongoose, { Schema, model } from "mongoose"; +import mongoose, { Schema } from "mongoose"; export interface IStaff { id: string; From d804edb2871e675189efdb8a6561ec60829febb2 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 21:59:35 -0500 Subject: [PATCH 12/53] make yer model const --- models/yearModel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/yearModel.ts b/models/yearModel.ts index d809da0..d5e7dea 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -15,4 +15,4 @@ const YearSchema = new Schema({ }); const name = "year"; -export let yearModel = mongoose.model(name, YearSchema, name); +export const yearModel = mongoose.model(name, YearSchema, name); From 1df65f0326afbc28a8abb536d67b3875b7004f06 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 22:23:01 -0500 Subject: [PATCH 13/53] print element name if it can't find it --- rolesOps.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rolesOps.ts b/rolesOps.ts index 81c751b..7b49f7d 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -133,7 +133,7 @@ export async function checkForRoles(guild: Guild): Promise { 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.` + `Role ${element.ROLE_NAME} does not exist in ${guild.name}, Please run the /createRoles command in that server.` ) ); collection.push(false); From 5c4109777d4100ff775b1eb8622d626fa56742bf Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 22:50:50 -0500 Subject: [PATCH 14/53] update what branches workflows run on --- .github/dependabot.yml | 2 +- .github/workflows/codeql.yml | 7 ++----- .github/workflows/dependency-review.yml | 3 ++- .github/workflows/docker-image.yml | 6 ++---- .github/workflows/format.yml | 1 + .github/workflows/publish-docker-image.yml | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 14304da..7d8cdfd 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,5 +8,5 @@ updates: - package-ecosystem: "npm" # See documentation for possible values directory: "/" # Location of package manifests schedule: - interval: "weekly" + interval: "daily" target-branch: "staging" diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f51a845..4f733cf 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -12,11 +12,8 @@ name: "CodeQL" on: - push: - branches: [ "main, staging" ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ "main, staging" ] + [push, pull_request]: + branches: [ main, staging ] schedule: - cron: '19 8 * * 2' diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index fe461b4..2a6f5bb 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -5,7 +5,8 @@ # Source repository: https://github.com/actions/dependency-review-action # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement name: 'Dependency Review' -on: [pull_request] +on: [pull_request, push] + branches: [main, staging] permissions: contents: read diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 6091a86..b0fbb8b 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,10 +1,8 @@ name: Docker Image CI on: - push: - branches: [ "main, staging" ] - pull_request: - branches: [ "main, staging" ] + [push, pull_request]: + branches: [ main, staging ] jobs: diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index dec7807..633af27 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -1,6 +1,7 @@ name: Format on: pull_request: + branches: ['*', '!main'] jobs: format: runs-on: ubuntu-latest diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index 585312f..08af35f 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -1,7 +1,7 @@ name: Publish Docker image to GitHub Package Registry on: push: - branches: [ "main" ] + branches: [ main ] jobs: build: runs-on: ubuntu-latest From df02be7764dab6725dc70500abd7f342e6ba54ea Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:03:37 -0500 Subject: [PATCH 15/53] update list format --- .github/workflows/codeql.yml | 5 ++--- .github/workflows/docker-image.yml | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 4f733cf..3c4f4b5 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -11,9 +11,8 @@ # name: "CodeQL" -on: - [push, pull_request]: - branches: [ main, staging ] +on: [push, pull_request]: + branches: [ main, staging ] schedule: - cron: '19 8 * * 2' diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b0fbb8b..8506baf 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,8 +1,7 @@ name: Docker Image CI -on: - [push, pull_request]: - branches: [ main, staging ] +on: [push, pull_request]: + branches: [ main, staging ] jobs: From 0e164ff189866398522cf1bf64c63756244d6dff Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:06:39 -0500 Subject: [PATCH 16/53] remove trailing colon --- .github/workflows/codeql.yml | 2 +- .github/workflows/docker-image.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 3c4f4b5..77f3b4b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -11,7 +11,7 @@ # name: "CodeQL" -on: [push, pull_request]: +on: [push, pull_request] branches: [ main, staging ] schedule: - cron: '19 8 * * 2' diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 8506baf..405295d 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,6 +1,6 @@ name: Docker Image CI -on: [push, pull_request]: +on: [push, pull_request] branches: [ main, staging ] jobs: From 2afe37e0a14a15c234634cd108e604913079dde6 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:10:40 -0500 Subject: [PATCH 17/53] remove indent --- .github/workflows/codeql.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 77f3b4b..308beda 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -12,9 +12,9 @@ name: "CodeQL" on: [push, pull_request] - branches: [ main, staging ] - schedule: - - cron: '19 8 * * 2' +branches: [ main, staging ] +schedule: + - cron: '19 8 * * 2' jobs: analyze: From 34173a7201db26c759a2d6af7dcf9a96992b027c Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:13:21 -0500 Subject: [PATCH 18/53] repeat for other workflows --- .github/workflows/dependency-review.yml | 2 +- .github/workflows/docker-image.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 2a6f5bb..847e798 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -6,7 +6,7 @@ # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement name: 'Dependency Review' on: [pull_request, push] - branches: [main, staging] +branches: [main, staging] permissions: contents: read diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 405295d..6ae17f8 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,7 +1,7 @@ name: Docker Image CI on: [push, pull_request] - branches: [ main, staging ] +branches: [ main, staging ] jobs: From 3cd475b0adaaf4d4a64fb1c7ee4c4593c4472a83 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:21:33 -0500 Subject: [PATCH 19/53] Separate out triggers --- .github/workflows/codeql.yml | 10 ++++++---- .github/workflows/dependency-review.yml | 6 ++++-- .github/workflows/docker-image.yml | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 308beda..56bdca6 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -11,10 +11,12 @@ # name: "CodeQL" -on: [push, pull_request] -branches: [ main, staging ] -schedule: - - cron: '19 8 * * 2' +on: + push: + pull_request: + branches: [ main, staging ] + schedule: + - cron: '19 8 * * 2' jobs: analyze: diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 847e798..c05a66a 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -5,8 +5,10 @@ # Source repository: https://github.com/actions/dependency-review-action # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement name: 'Dependency Review' -on: [pull_request, push] -branches: [main, staging] +on: + push: + pull_request: + branches: [main, staging] permissions: contents: read diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 6ae17f8..b129292 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,7 +1,9 @@ name: Docker Image CI -on: [push, pull_request] -branches: [ main, staging ] +on: + push: + pull_request: + branches: [ main, staging ] jobs: From 3c0e6b70bbb57fba6dd86a98ae9e5a9800928076 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:25:52 -0500 Subject: [PATCH 20/53] only run dependency review on pr --- .github/workflows/dependency-review.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index c05a66a..2ff1a16 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -6,7 +6,6 @@ # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement name: 'Dependency Review' on: - push: pull_request: branches: [main, staging] From 79978980481250d49911078210d2959ae1dd672c Mon Sep 17 00:00:00 2001 From: Nate Goldsborough Date: Sun, 4 Sep 2022 23:36:06 -0500 Subject: [PATCH 21/53] Add CONTRIBUTING.md --- CONTRIBUTING.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..2e0c22e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,20 @@ +# CSSC-bot Contributing guidelines + +## Developing New Features + +First create a new branch with it's base set to the [staging](https://github.com/Antares-Network/CSSC-Bot/tree/staging) branch. +For naming conventions use `feature/GithubUsername/FeatureName`. Example: `feature/nathen418/mongodb-support` +Next when your feature is ready to be merged, submit a pull request to the [staging](https://github.com/Antares-Network/CSSC-Bot/tree/staging) branch. +This will be used to test your changes along side the rest of the code and any other pending new features. + +## Fixing Bugs + +Do the same as the instructions except when naming your branch use the naming convention: `bugfix/GithubUsername/BugName`. Example: `bugfix/nathen418/fix-api-connection-err` + +## Editing/Merging Pull Requests + +Only merge pull requests you authored or have been approved by the author to merge. + +## Pushing to branches + +Only push to branches you have been given permission to push to. This means that you should only commit to branches that have your name in the branch name unless the branch owner has given you permission to push to it. From fdd66bdd17ecd5393f4867694d3fa666994a1435 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:39:12 -0500 Subject: [PATCH 22/53] PR template --- .github/PULL_REQUEST_TEMPLATE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..a05e745 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,21 @@ + +# Descriptive title + +A person with no idea what task you were working on before should at least +have an idea as to what you did. + +# link to github card +Type `#` to see list of autolinks to pull requests or issues + +# A descriptive body +The body should contain a high-level overview of the individual changes you made, what parts of the application you changed, etc. +This may be in list form. + + +* +* +* + + +You may also wish to include links to related pull requests, issues, or branches which may affect your changes. +You can mention people by using `@` From 2f0a8ab394032744480ac31bd88dea4db941d2e3 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Sun, 4 Sep 2022 23:44:31 -0500 Subject: [PATCH 23/53] Fix typos --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a05e745..70e02a9 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,10 +4,10 @@ A person with no idea what task you were working on before should at least have an idea as to what you did. -# link to github card +# Link to github card Type `#` to see list of autolinks to pull requests or issues -# A descriptive body +# Changes The body should contain a high-level overview of the individual changes you made, what parts of the application you changed, etc. This may be in list form. From 937e0173f32b474447c649b34f492c025f86695a Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 15:58:09 -0500 Subject: [PATCH 24/53] Create roles interface for role models --- models/classModel.ts | 5 ++--- models/staffModel.ts | 5 ++--- models/yearModel.ts | 5 ++--- rolesOps.ts | 5 +++++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/models/classModel.ts b/models/classModel.ts index af644d2..b0d3c07 100644 --- a/models/classModel.ts +++ b/models/classModel.ts @@ -1,12 +1,11 @@ import mongoose, { Schema } from "mongoose"; +import { IRole } from "../rolesOps"; -export interface IClass { +export interface IClass extends IRole { id: string; CODE: string; TITLE: string; INFO: string; - ROLE_NAME: string; - ROLE_ID: string; CHANNEL_NAME: string; CHANNEL_ID: string; UUID: string; diff --git a/models/staffModel.ts b/models/staffModel.ts index 1f8c7f4..3d6f3c2 100644 --- a/models/staffModel.ts +++ b/models/staffModel.ts @@ -1,10 +1,9 @@ import mongoose, { Schema } from "mongoose"; +import { IRole } from "../rolesOps"; -export interface IStaff { +export interface IStaff extends IRole { id: string; NAME: string; - ROLE_NAME: string; - ROLE_ID: string; } const StaffSchema = new Schema({ diff --git a/models/yearModel.ts b/models/yearModel.ts index d5e7dea..dcded9e 100644 --- a/models/yearModel.ts +++ b/models/yearModel.ts @@ -1,10 +1,9 @@ import mongoose, { Schema } from "mongoose"; +import { IRole } from "../rolesOps"; -export interface IYear { +export interface IYear extends IRole { id: string; NAME: string; - ROLE_NAME: string; - ROLE_ID: string; } const YearSchema = new Schema({ diff --git a/rolesOps.ts b/rolesOps.ts index 7b49f7d..2b98bd4 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -5,6 +5,11 @@ import { staffModel, IStaff } from "./models/staffModel"; import { yearModel, IYear } from "./models/yearModel"; import { Model } from "mongoose"; +export interface IRole { + ROLE_NAME: string; + ROLE_ID: string; +} + export async function checkIfCollectionsExist(model: Model) { if (!(await model.exists({}))) { throw new Error(`${model.name} collection does not exist`); From c0784827eeb02d09a145a7ee5ad06a6339b58df5 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 15:58:42 -0500 Subject: [PATCH 25/53] Rewrite Clear roles to accept a model that implements IRole --- commands/user/clear.ts | 9 ++++++--- features/interactionCreate.ts | 13 +++++++++---- rolesOps.ts | 13 +++---------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/commands/user/clear.ts b/commands/user/clear.ts index 207b792..53f52fe 100644 --- a/commands/user/clear.ts +++ b/commands/user/clear.ts @@ -1,6 +1,9 @@ import chalk from "chalk"; import { GuildMember } from "discord.js"; import { ICommand } from "wokcommands"; +import { classModel } from "../../models/classModel"; +import { staffModel } from "../../models/staffModel"; +import { yearModel } from "../../models/yearModel"; import { removeRole } from "../../rolesOps"; export default { @@ -16,9 +19,9 @@ export default { // Remove roles from user if (!interaction.member) return; const member = interaction.member as GuildMember; - removeRole(member, "class"); - removeRole(member, "year"); - removeRole(member, "staff"); + removeRole(member, classModel); + removeRole(member, yearModel); + removeRole(member, staffModel); // Reply to the user interaction.reply({ content: "Cleared all roles that I have assigned to you.", diff --git a/features/interactionCreate.ts b/features/interactionCreate.ts index 2956a80..55008f9 100644 --- a/features/interactionCreate.ts +++ b/features/interactionCreate.ts @@ -1,5 +1,7 @@ import { Client, MessageEmbed, GuildMember } from "discord.js"; +import { yearModel } from "../models/yearModel"; import { removeRole, addNewRole } from "../rolesOps"; +import { staffModel } from "../models/staffModel"; // Listen interactionCreate events from the client export default (client: Client): void => { @@ -30,11 +32,12 @@ export default (client: Client): void => { ephemeral: true, }); // Remove any previous roles in the dictionary from the user + removeRole(member, yearModel); + + // No role to add 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]); @@ -52,12 +55,14 @@ export default (client: Client): void => { ], ephemeral: true, }); + // Remove any previous roles in the dictionary from the user + removeRole(member, staffModel); + + // No role to add 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]); diff --git a/rolesOps.ts b/rolesOps.ts index 2b98bd4..de8c98a 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -34,20 +34,13 @@ export async function getUsersRoles(member: GuildMember): Promise { return list; } -export async function removeRole( +export async function removeRole( member: GuildMember, - type: string + model: Model ): Promise { // This function is triggered when a user changes their role, // it removes the previous role from the user - let list: any[] = []; - if (type === "class") { - list = await classModel.find({}); - } else if (type === "staff") { - list = await staffModel.find({}); - } else if (type === "year") { - list = await yearModel.find({}); - } + const list = await model.find({}); for (const role of list) { if (member.roles.cache.has(role.ROLE_ID)) { From 4eae91522df39aaf6c9e69c6db9d0bbf28dabf7d Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 16:40:34 -0500 Subject: [PATCH 26/53] rewrite createRoles --- commands/owner/createRoles.ts | 9 ++++++--- rolesOps.ts | 14 +++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/commands/owner/createRoles.ts b/commands/owner/createRoles.ts index 6cee1c9..ee82c88 100644 --- a/commands/owner/createRoles.ts +++ b/commands/owner/createRoles.ts @@ -1,6 +1,9 @@ import { ICommand } from "wokcommands"; import { createRoles } from "../../rolesOps"; import chalk from "chalk"; +import { classModel } from "../../models/classModel"; +import { staffModel } from "../../models/staffModel"; +import { yearModel } from "../../models/yearModel"; export default { name: "createRoles", @@ -18,9 +21,9 @@ export default { chalk.red("------------------------------------------------------") ); // Create the roles - createRoles(interaction.guild!, "class"); - createRoles(interaction.guild!, "staff"); - createRoles(interaction.guild!, "year"); + createRoles(interaction.guild!, classModel); + createRoles(interaction.guild!, staffModel); + createRoles(interaction.guild!, yearModel); interaction.reply({ content: "Roles created!", ephemeral: true, diff --git a/rolesOps.ts b/rolesOps.ts index de8c98a..c130a92 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -85,15 +85,11 @@ export async function addNewRole( } } -export async function createRoles(guild: Guild, type: string): Promise { - let list = null; - 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 createRoles( + guild: Guild, + model: Model +): Promise { + let list = await model.find({}); list?.forEach(async (element) => { if (!guild.roles.cache.find((r) => r.name === element.ROLE_NAME)) { From 6a0e624c0ca284341ee7e64bb1f8bc2626a41e1d Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 16:47:24 -0500 Subject: [PATCH 27/53] Rewrite addNewRole --- features/interactionCreate.ts | 7 ++++--- rolesOps.ts | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/features/interactionCreate.ts b/features/interactionCreate.ts index 55008f9..88b6944 100644 --- a/features/interactionCreate.ts +++ b/features/interactionCreate.ts @@ -2,6 +2,7 @@ import { Client, MessageEmbed, GuildMember } from "discord.js"; import { yearModel } from "../models/yearModel"; import { removeRole, addNewRole } from "../rolesOps"; import { staffModel } from "../models/staffModel"; +import { classModel } from "../models/classModel"; // Listen interactionCreate events from the client export default (client: Client): void => { @@ -40,7 +41,7 @@ export default (client: Client): void => { } // Assign the new role to the user - addNewRole(member, "year", interaction.values[0]); + addNewRole(member, yearModel, interaction.values[0]); } else if (interaction.customId === "collegeStaffPoll") { // Set the embed title const title = "College Staff Poll"; @@ -65,7 +66,7 @@ export default (client: Client): void => { } // Assign the new role to the user - addNewRole(member, "staff", interaction.values[0]); + addNewRole(member, staffModel, interaction.values[0]); } else if (interaction.customId.startsWith("csClassPoll+")) { // Set the embed title const title = "CS Class Poll"; @@ -82,7 +83,7 @@ export default (client: Client): void => { }); // Assign the new role to the user - addNewRole(member, "class", interaction.values[0]); + addNewRole(member, classModel, interaction.values[0]); } }); }; diff --git a/rolesOps.ts b/rolesOps.ts index c130a92..1a07987 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -56,23 +56,25 @@ export async function removeRole( } } -export async function addNewRole( +export async function addNewRole( member: GuildMember, - type: string, + model: Model, id: string ) { // This function is triggered when a user changes their role, it adds the new role to the user - let role: IClass | IYear | IStaff | null = null; - 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 }); + let role; + switch (model.constructor) { + case classModel: + //TODO: Rewrite IRole to include name, and replace CODE with name + role = await model.findOne({ CODE: id }); + default: + role = await model.findOne({ Name: id }); } + if (role === null) { throw new Error(`No roll found with id: ${id}`); } + if (!member.roles.cache.has(role.ROLE_ID)) { await member.roles.add(role.ROLE_ID); console.log( From 2a1698e6cfb3588433472960f924cd42424f6eec Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 16:48:33 -0500 Subject: [PATCH 28/53] use generic rather than any --- rolesOps.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rolesOps.ts b/rolesOps.ts index 1a07987..98cda6a 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -10,7 +10,7 @@ export interface IRole { ROLE_ID: string; } -export async function checkIfCollectionsExist(model: Model) { +export async function checkIfCollectionsExist(model: Model) { if (!(await model.exists({}))) { throw new Error(`${model.name} collection does not exist`); } From b35a78578dcb6f09b6ed9cf1e1a2793f9ec13374 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 16:57:34 -0500 Subject: [PATCH 29/53] Clean up code and swap to const --- commands/owner/csClassPoll.ts | 3 +-- rolesOps.ts | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index f97609f..d3a0107 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -27,8 +27,7 @@ export default { return; } - // let classes: IClass[] = await classModel.find({}).sort({ CODE: 1 }); - let classes = await classModel.find({}).sort({ CODE: 1 }); + const classes = await classModel.find({}).sort({ CODE: 1 }); const class_chunks = split_list(classes, 25); let rows: MessageActionRow[] = []; diff --git a/rolesOps.ts b/rolesOps.ts index 98cda6a..c890bc5 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -1,8 +1,8 @@ import { GuildMember, Guild } from "discord.js"; import chalk from "chalk"; -import { classModel, IClass } from "./models/classModel"; -import { staffModel, IStaff } from "./models/staffModel"; -import { yearModel, IYear } from "./models/yearModel"; +import { classModel } from "./models/classModel"; +import { staffModel } from "./models/staffModel"; +import { yearModel } from "./models/yearModel"; import { Model } from "mongoose"; export interface IRole { @@ -91,7 +91,7 @@ export async function createRoles( guild: Guild, model: Model ): Promise { - let list = await model.find({}); + const list = await model.find({}); list?.forEach(async (element) => { if (!guild.roles.cache.find((r) => r.name === element.ROLE_NAME)) { From fb8585cc290c32a4102af2bd6227f60a0099ed18 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 17:00:21 -0500 Subject: [PATCH 30/53] Add missing awaits --- features/interactionCreate.ts | 10 +++++----- index.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/features/interactionCreate.ts b/features/interactionCreate.ts index 88b6944..7f25607 100644 --- a/features/interactionCreate.ts +++ b/features/interactionCreate.ts @@ -33,7 +33,7 @@ export default (client: Client): void => { ephemeral: true, }); // Remove any previous roles in the dictionary from the user - removeRole(member, yearModel); + await removeRole(member, yearModel); // No role to add if (interaction.values[0] === "None") { @@ -41,7 +41,7 @@ export default (client: Client): void => { } // Assign the new role to the user - addNewRole(member, yearModel, interaction.values[0]); + await addNewRole(member, yearModel, interaction.values[0]); } else if (interaction.customId === "collegeStaffPoll") { // Set the embed title const title = "College Staff Poll"; @@ -58,7 +58,7 @@ export default (client: Client): void => { }); // Remove any previous roles in the dictionary from the user - removeRole(member, staffModel); + await removeRole(member, staffModel); // No role to add if (interaction.values[0] === "None") { @@ -66,7 +66,7 @@ export default (client: Client): void => { } // Assign the new role to the user - addNewRole(member, staffModel, interaction.values[0]); + await addNewRole(member, staffModel, interaction.values[0]); } else if (interaction.customId.startsWith("csClassPoll+")) { // Set the embed title const title = "CS Class Poll"; @@ -83,7 +83,7 @@ export default (client: Client): void => { }); // Assign the new role to the user - addNewRole(member, classModel, interaction.values[0]); + await addNewRole(member, classModel, interaction.values[0]); } }); }; diff --git a/index.ts b/index.ts index e75901e..3111af8 100644 --- a/index.ts +++ b/index.ts @@ -61,9 +61,9 @@ client.on("ready", () => { // Set up the connection to the database wok.on("databaseConnected", async () => { - checkIfCollectionsExist(classModel); - checkIfCollectionsExist(staffModel); - checkIfCollectionsExist(yearModel); + await checkIfCollectionsExist(classModel); + await checkIfCollectionsExist(staffModel); + await checkIfCollectionsExist(yearModel); console.log(chalk.green("Connected to the database")); }); }); From 5ee66cc45447ea0dc27de2148263208c969d468e Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 17:01:39 -0500 Subject: [PATCH 31/53] Add other missing awaits --- commands/owner/createRoles.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/owner/createRoles.ts b/commands/owner/createRoles.ts index ee82c88..63d717e 100644 --- a/commands/owner/createRoles.ts +++ b/commands/owner/createRoles.ts @@ -21,9 +21,9 @@ export default { chalk.red("------------------------------------------------------") ); // Create the roles - createRoles(interaction.guild!, classModel); - createRoles(interaction.guild!, staffModel); - createRoles(interaction.guild!, yearModel); + await createRoles(interaction.guild!, classModel); + await createRoles(interaction.guild!, staffModel); + await createRoles(interaction.guild!, yearModel); interaction.reply({ content: "Roles created!", ephemeral: true, From 6c79b91e28b412c1722d541d8f7e40cedf0ec8d0 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 17:03:28 -0500 Subject: [PATCH 32/53] Added other other missing awaits --- commands/user/clear.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/user/clear.ts b/commands/user/clear.ts index 53f52fe..d3520a9 100644 --- a/commands/user/clear.ts +++ b/commands/user/clear.ts @@ -19,9 +19,9 @@ export default { // Remove roles from user if (!interaction.member) return; const member = interaction.member as GuildMember; - removeRole(member, classModel); - removeRole(member, yearModel); - removeRole(member, staffModel); + await removeRole(member, classModel); + await removeRole(member, yearModel); + await removeRole(member, staffModel); // Reply to the user interaction.reply({ content: "Cleared all roles that I have assigned to you.", From 61bbc80391249970a806474a228caf24516a4af4 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 17:08:18 -0500 Subject: [PATCH 33/53] swap to explicit null check --- commands/owner/createRoles.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/commands/owner/createRoles.ts b/commands/owner/createRoles.ts index 63d717e..2b1efd4 100644 --- a/commands/owner/createRoles.ts +++ b/commands/owner/createRoles.ts @@ -20,10 +20,13 @@ export default { console.log( chalk.red("------------------------------------------------------") ); + if (interaction.guild === null) { + return; + } // Create the roles - await createRoles(interaction.guild!, classModel); - await createRoles(interaction.guild!, staffModel); - await createRoles(interaction.guild!, yearModel); + await createRoles(interaction.guild, classModel); + await createRoles(interaction.guild, staffModel); + await createRoles(interaction.guild, yearModel); interaction.reply({ content: "Roles created!", ephemeral: true, From 63feec3bce173cd0ff00e43a3ca23f6ad0c4aa3b Mon Sep 17 00:00:00 2001 From: John Schiltz <45466247+schiltz3@users.noreply.github.com> Date: Mon, 5 Sep 2022 19:27:30 -0500 Subject: [PATCH 34/53] Downgrade chalk version --- package-lock.json | 145 +++++++++++++++++++++++++++++++++++++--------- package.json | 4 +- 2 files changed, 120 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6051be0..860b625 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "axios": "^0.27.2", - "chalk": "^5.0.1", + "chalk": "4.1.2", "discord.js": "^13.9.2", "mongoose": "^6.5.4", "path": "^0.12.7", @@ -96,9 +96,9 @@ } }, "node_modules/@sapphire/shapeshift": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.5.1.tgz", - "integrity": "sha512-7JFsW5IglyOIUQI1eE0g6h06D/Far6HqpcowRScgCiLSqTf3hhkPWCWotVTtVycnDCMYIwPeaw6IEPBomKC8pA==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.6.0.tgz", + "integrity": "sha512-tu2WLRdo5wotHRvsCkspg3qMiP6ETC3Q1dns1Q5V6zKUki+1itq6AbhMwohF9ZcLoYqg+Y8LkgRRtVxxTQVTBQ==", "dependencies": { "fast-deep-equal": "^3.1.3", "lodash.uniqwith": "^4.5.0" @@ -129,9 +129,9 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==" }, "node_modules/@types/node": { - "version": "18.7.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", - "integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==" + "version": "18.7.15", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.15.tgz", + "integrity": "sha512-XnjpaI8Bgc3eBag2Aw4t2Uj/49lLBSStHWfqKvIuXD7FIrZyMLWp8KuAFHAqxMZYTF9l08N1ctUn9YNybZJVmQ==" }, "node_modules/@types/node-fetch": { "version": "2.6.2", @@ -156,9 +156,9 @@ } }, "node_modules/@types/webidl-conversions": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-6.1.1.tgz", - "integrity": "sha512-XAahCdThVuCFDQLT7R7Pk/vqeObFNL3YqRyFZg+AqAP/W1/w3xHaIxuW7WszQqTbIBOPRcItYJIou3i/mppu3Q==" + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==" }, "node_modules/@types/whatwg-url": { "version": "8.2.2", @@ -196,6 +196,20 @@ "node": ">=0.4.0" } }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", @@ -269,16 +283,36 @@ } }, "node_modules/chalk": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", - "integrity": "sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, "engines": { - "node": "^12.17.0 || ^14.13 || >=16.0.0" + "node": ">=10" }, "funding": { "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -410,6 +444,14 @@ "node": ">= 6" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -675,6 +717,17 @@ "memory-pager": "^1.0.2" } }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", @@ -880,9 +933,9 @@ "integrity": "sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==" }, "@sapphire/shapeshift": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.5.1.tgz", - "integrity": "sha512-7JFsW5IglyOIUQI1eE0g6h06D/Far6HqpcowRScgCiLSqTf3hhkPWCWotVTtVycnDCMYIwPeaw6IEPBomKC8pA==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.6.0.tgz", + "integrity": "sha512-tu2WLRdo5wotHRvsCkspg3qMiP6ETC3Q1dns1Q5V6zKUki+1itq6AbhMwohF9ZcLoYqg+Y8LkgRRtVxxTQVTBQ==", "requires": { "fast-deep-equal": "^3.1.3", "lodash.uniqwith": "^4.5.0" @@ -909,9 +962,9 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==" }, "@types/node": { - "version": "18.7.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", - "integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==" + "version": "18.7.15", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.15.tgz", + "integrity": "sha512-XnjpaI8Bgc3eBag2Aw4t2Uj/49lLBSStHWfqKvIuXD7FIrZyMLWp8KuAFHAqxMZYTF9l08N1ctUn9YNybZJVmQ==" }, "@types/node-fetch": { "version": "2.6.2", @@ -935,9 +988,9 @@ } }, "@types/webidl-conversions": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-6.1.1.tgz", - "integrity": "sha512-XAahCdThVuCFDQLT7R7Pk/vqeObFNL3YqRyFZg+AqAP/W1/w3xHaIxuW7WszQqTbIBOPRcItYJIou3i/mppu3Q==" + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==" }, "@types/whatwg-url": { "version": "8.2.2", @@ -966,6 +1019,14 @@ "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==" }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, "arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", @@ -1008,9 +1069,26 @@ } }, "chalk": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", - "integrity": "sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==" + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "combined-stream": { "version": "1.0.8", @@ -1101,6 +1179,11 @@ "mime-types": "^2.1.12" } }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -1293,6 +1376,14 @@ "memory-pager": "^1.0.2" } }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + }, "tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", @@ -1385,4 +1476,4 @@ "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==" } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 365a1b3..b135bcb 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "homepage": "https://github.com/Antares-Network/CSSC-Bot#readme", "dependencies": { "axios": "^0.27.2", - "chalk": "^5.0.1", + "chalk": "4.1.2", "discord.js": "^13.9.2", "mongoose": "^6.5.4", "path": "^0.12.7", @@ -31,4 +31,4 @@ "typescript": "^4.5.5", "wokcommands": "^1.5.3" } -} +} \ No newline at end of file From c1a164823258241d4f41a26d5ba32115905803c4 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 21:41:39 -0500 Subject: [PATCH 35/53] Replace any with type variable JS-0323 --- commands/owner/csClassPoll.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index d3a0107..1105c4f 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -85,7 +85,7 @@ export default { } as ICommand; // Splits any size list into lists of at most `max_list_len` -function split_list(list: Array, max_list_len: number) { +function split_list(list: T[], max_list_len: number):T[][] { let class_chunks = []; for (let i = 0; i < list.length; i += max_list_len) { class_chunks.push(list.slice(i, i + max_list_len)); From ec80927dcd5388ce2999d41516cbb43228af6b79 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 21:51:12 -0500 Subject: [PATCH 36/53] Move non export functions to top JS-0357 --- commands/owner/csClassPoll.ts | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index 1105c4f..b27ef54 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -9,6 +9,23 @@ import { ICommand } from "wokcommands"; import { classModel, IClass } from "../../models/classModel"; import { checkForRoles } from "../../rolesOps"; +// Splits any size list into lists of at most `max_list_len` +function split_list(list: T[], max_list_len: number):T[][] { + let class_chunks = []; + for (let i = 0; i < list.length; i += max_list_len) { + class_chunks.push(list.slice(i, i + max_list_len)); + } + return class_chunks; +} + +// consumes a Class and returns Message Selec tOption data +function create_option_from_class(_class: IClass): MessageSelectOptionData { + return { + label: _class.CODE, + value: _class.CODE, + description: _class.TITLE, + }; +} export default { name: "csClassPoll", category: "owner", @@ -83,21 +100,3 @@ export default { ); }, } as ICommand; - -// Splits any size list into lists of at most `max_list_len` -function split_list(list: T[], max_list_len: number):T[][] { - let class_chunks = []; - for (let i = 0; i < list.length; i += max_list_len) { - class_chunks.push(list.slice(i, i + max_list_len)); - } - return class_chunks; -} - -// consumes a Class and returns Message Selec tOption data -function create_option_from_class(_class: IClass): MessageSelectOptionData { - return { - label: _class.CODE, - value: _class.CODE, - description: _class.TITLE, - }; -} From 380d541951b6d76a25ced2a62c8f02e35f42e73d Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 21:52:21 -0500 Subject: [PATCH 37/53] Remove unused variables JS-0356 --- commands/user/uptime.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/commands/user/uptime.ts b/commands/user/uptime.ts index c2688cc..7aa8c5a 100644 --- a/commands/user/uptime.ts +++ b/commands/user/uptime.ts @@ -12,10 +12,6 @@ export default { requiredPermissions: ["SEND_MESSAGES"], callback: async ({ client, interaction }) => { - // Command information - const id = interaction.user.id; - const chan = interaction.channel as TextChannel; - // Computed values const time = client.uptime!; const days = Math.floor(time / 86400000); From fc980777c62f767c3890bc19e2af2b5e861ff177 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 21:54:15 -0500 Subject: [PATCH 38/53] add missing awaits JS-0336 --- commands/owner/csClassPoll.ts | 4 ++-- commands/owner/staffPoll.ts | 2 +- commands/owner/yearPoll.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index b27ef54..b971d3f 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -10,7 +10,7 @@ import { classModel, IClass } from "../../models/classModel"; import { checkForRoles } from "../../rolesOps"; // Splits any size list into lists of at most `max_list_len` -function split_list(list: T[], max_list_len: number):T[][] { +function split_list(list: T[], max_list_len: number): T[][] { let class_chunks = []; for (let i = 0; i < list.length; i += max_list_len) { class_chunks.push(list.slice(i, i + max_list_len)); @@ -37,7 +37,7 @@ export default { ownerOnly: true, callback: async ({ client, interaction: msgInt }) => { - if (!checkForRoles(msgInt.guild!)) { + if (!(await checkForRoles(msgInt.guild!))) { msgInt.reply( "Please run the `/ createRoles` command in this server to create the necessary roles for this poll!" ); diff --git a/commands/owner/staffPoll.ts b/commands/owner/staffPoll.ts index c35d75c..b0601bf 100644 --- a/commands/owner/staffPoll.ts +++ b/commands/owner/staffPoll.ts @@ -59,7 +59,7 @@ export default { ); // Send the embed and message component rows - if (!checkForRoles(msgInt.guild!)) { + if (!(await checkForRoles(msgInt.guild!))) { msgInt.reply( "Please run the `/createRoles` command in this server to create the necessary roles for this poll!" ); diff --git a/commands/owner/yearPoll.ts b/commands/owner/yearPoll.ts index 17f6e62..2e64eb3 100644 --- a/commands/owner/yearPoll.ts +++ b/commands/owner/yearPoll.ts @@ -67,7 +67,7 @@ export default { ); // Send the embed and message component rows - if (!checkForRoles(msgInt.guild!)) { + if (!(await checkForRoles(msgInt.guild!))) { msgInt.reply({ content: "Please run the /createRoles command in this server to create the necessary roles for this poll!", From f682488c2f194715eef4f69557fea3b13d485e63 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:04:39 -0500 Subject: [PATCH 39/53] resolve use of eval() like method JS-0330 --- commands/owner/csClassPoll.ts | 7 +++---- util.ts | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 util.ts diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index b971d3f..0538658 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -8,6 +8,7 @@ import chalk from "chalk"; import { ICommand } from "wokcommands"; import { classModel, IClass } from "../../models/classModel"; import { checkForRoles } from "../../rolesOps"; +import { sleep } from "../../util"; // Splits any size list into lists of at most `max_list_len` function split_list(list: T[], max_list_len: number): T[][] { @@ -82,10 +83,8 @@ export default { } else { msgInt.channel!.send({ components: row_chunks[index] }); } - // await on a new promise that resolves itself after a delay of 200 ms - await new Promise((resolve) => { - setTimeout(resolve, 200); - }); + + await sleep(200); } // Log the command usage diff --git a/util.ts b/util.ts new file mode 100644 index 0000000..ccf6b87 --- /dev/null +++ b/util.ts @@ -0,0 +1,4 @@ +export function sleep(ms: number) { + // Create new promise that resolves itself after a delay of + return new Promise((resolve: Function) => setTimeout(resolve, ms)); +} From 6784379d2dac376ee8a2e051df35bd8f5f4ad6fa Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:13:44 -0500 Subject: [PATCH 40/53] remove non-null assertion Swap to reply to not have to check for null --- commands/owner/csClassPoll.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index 0538658..588cb48 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -38,7 +38,11 @@ export default { ownerOnly: true, callback: async ({ client, interaction: msgInt }) => { - if (!(await checkForRoles(msgInt.guild!))) { + if (msgInt.guild === null) { + console.log(chalk.red("No guild")); + return; + } + if (!(await checkForRoles(msgInt.guild))) { msgInt.reply( "Please run the `/ createRoles` command in this server to create the necessary roles for this poll!" ); @@ -81,7 +85,7 @@ export default { msgInt.reply({ embeds: [infoEmbed], components: row_chunks[index] }); } else { - msgInt.channel!.send({ components: row_chunks[index] }); + msgInt.reply({ components: row_chunks[index] }); } await sleep(200); From c773ed526390e446005869b22e752161af68325e Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:13:53 -0500 Subject: [PATCH 41/53] remove non-null assertions --- commands/owner/staffPoll.ts | 6 +++++- commands/owner/yearPoll.ts | 6 +++++- commands/user/uptime.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/commands/owner/staffPoll.ts b/commands/owner/staffPoll.ts index b0601bf..8b6cc06 100644 --- a/commands/owner/staffPoll.ts +++ b/commands/owner/staffPoll.ts @@ -58,8 +58,12 @@ export default { ) ); + if (msgInt.guild === null) { + console.log(chalk.red("No guild")); + return; + } // Send the embed and message component rows - if (!(await checkForRoles(msgInt.guild!))) { + if (!(await checkForRoles(msgInt.guild))) { msgInt.reply( "Please run the `/createRoles` command in this server to create the necessary roles for this poll!" ); diff --git a/commands/owner/yearPoll.ts b/commands/owner/yearPoll.ts index 2e64eb3..01e74fd 100644 --- a/commands/owner/yearPoll.ts +++ b/commands/owner/yearPoll.ts @@ -66,8 +66,12 @@ export default { ) ); + if (msgInt.guild === null) { + console.log(chalk.red("No guild")); + return; + } // Send the embed and message component rows - if (!(await checkForRoles(msgInt.guild!))) { + if (!(await checkForRoles(msgInt.guild))) { msgInt.reply({ content: "Please run the /createRoles command in this server to create the necessary roles for this poll!", diff --git a/commands/user/uptime.ts b/commands/user/uptime.ts index 7aa8c5a..f03d769 100644 --- a/commands/user/uptime.ts +++ b/commands/user/uptime.ts @@ -13,7 +13,7 @@ export default { callback: async ({ client, interaction }) => { // Computed values - const time = client.uptime!; + const time = client.uptime !== null ? client.uptime : 0; const days = Math.floor(time / 86400000); const hours = Math.floor(time / 3600000) % 24; const minutes = Math.floor(time / 60000) % 60; From 84cac64b90793ba5a89ad87f7345882138950231 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:15:43 -0500 Subject: [PATCH 42/53] Use const declarations for variables that are never reassigned JS-0242 --- commands/owner/csClassPoll.ts | 4 ++-- rolesOps.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/owner/csClassPoll.ts b/commands/owner/csClassPoll.ts index 588cb48..37457e6 100644 --- a/commands/owner/csClassPoll.ts +++ b/commands/owner/csClassPoll.ts @@ -12,7 +12,7 @@ import { sleep } from "../../util"; // Splits any size list into lists of at most `max_list_len` function split_list(list: T[], max_list_len: number): T[][] { - let class_chunks = []; + const class_chunks: T[][] = []; for (let i = 0; i < list.length; i += max_list_len) { class_chunks.push(list.slice(i, i + max_list_len)); } @@ -52,7 +52,7 @@ export default { const classes = await classModel.find({}).sort({ CODE: 1 }); const class_chunks = split_list(classes, 25); - let rows: MessageActionRow[] = []; + const rows: MessageActionRow[] = []; for (let index = 0; index < class_chunks.length; index++) { const menu = new MessageSelectMenu(); menu.setCustomId(`csClassPoll+${index}`); diff --git a/rolesOps.ts b/rolesOps.ts index c890bc5..a950f81 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -119,7 +119,7 @@ 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 - let collection: boolean[] = []; + const collection: boolean[] = []; for (const group of await dbQuery()) { for (const element of group) { From 98f7f28e18808952c19167859f98bf29d7ca875b Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:26:26 -0500 Subject: [PATCH 43/53] not using await on async function JS-0116 --- commands/owner/yearPoll.ts | 4 ++-- commands/user/github.ts | 2 +- commands/user/help.ts | 2 +- commands/user/ping.ts | 2 +- commands/user/status.ts | 2 +- commands/user/uptime.ts | 2 +- commands/user/version.ts | 2 +- features/status-changer.ts | 2 +- features/statuspage.ts | 2 +- index.ts | 11 +++++++---- 10 files changed, 17 insertions(+), 14 deletions(-) diff --git a/commands/owner/yearPoll.ts b/commands/owner/yearPoll.ts index 01e74fd..2042765 100644 --- a/commands/owner/yearPoll.ts +++ b/commands/owner/yearPoll.ts @@ -72,13 +72,13 @@ export default { } // Send the embed and message component rows if (!(await checkForRoles(msgInt.guild))) { - msgInt.reply({ + await 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] }); + await msgInt.reply({ embeds: [infoEmbed], components: [row] }); } // Log the command usage diff --git a/commands/user/github.ts b/commands/user/github.ts index 9ca20fe..f94f6d0 100644 --- a/commands/user/github.ts +++ b/commands/user/github.ts @@ -30,7 +30,7 @@ export default { .setDescription(description) .setFooter({ text: footer, iconURL: footerIcon }); - interaction.reply({ embeds: [Embed] }); + await interaction.reply({ embeds: [Embed] }); // Log the command usage console.log( diff --git a/commands/user/help.ts b/commands/user/help.ts index 3c3030e..9bd3086 100644 --- a/commands/user/help.ts +++ b/commands/user/help.ts @@ -53,7 +53,7 @@ export default { .setDescription(description) .addFields(fields) .setFooter({ text: footer, iconURL: footerIcon }); - interaction.reply({ embeds: [Embed] }); + await interaction.reply({ embeds: [Embed] }); // Log the command usage console.log( diff --git a/commands/user/ping.ts b/commands/user/ping.ts index 672d6b5..e9d5fec 100644 --- a/commands/user/ping.ts +++ b/commands/user/ping.ts @@ -26,7 +26,7 @@ export default { .setFooter({ text: footer, iconURL: footerIcon }); // Return the embed - interaction.reply({ embeds: [Embed] }); + await interaction.reply({ embeds: [Embed] }); // Log the command usage console.log( diff --git a/commands/user/status.ts b/commands/user/status.ts index 22742c2..bd7a48d 100644 --- a/commands/user/status.ts +++ b/commands/user/status.ts @@ -30,7 +30,7 @@ export default { .setDescription(description) .setFooter({ text: footer, iconURL: footerIcon }); - interaction.reply({ embeds: [Embed] }); + await interaction.reply({ embeds: [Embed] }); // Log the command usage console.log( diff --git a/commands/user/uptime.ts b/commands/user/uptime.ts index f03d769..b761a3a 100644 --- a/commands/user/uptime.ts +++ b/commands/user/uptime.ts @@ -34,7 +34,7 @@ export default { .setFooter({ text: footer, iconURL: footerIcon }); // Return the embed - interaction.reply({ embeds: [Embed] }); + await interaction.reply({ embeds: [Embed] }); // Log the command usage console.log( diff --git a/commands/user/version.ts b/commands/user/version.ts index 5a5d42f..c039b87 100644 --- a/commands/user/version.ts +++ b/commands/user/version.ts @@ -26,7 +26,7 @@ export default { .setFooter({ text: footer, iconURL: footerIcon }); // Return the embed - interaction.reply({ embeds: [Embed] }); + await interaction.reply({ embeds: [Embed] }); // Log the command usage console.log( diff --git a/features/status-changer.ts b/features/status-changer.ts index c232230..0d46db6 100644 --- a/features/status-changer.ts +++ b/features/status-changer.ts @@ -1,6 +1,6 @@ import { Client } from "discord.js"; -export default async (client: Client) => { +export default (client: Client) => { const statusOptions = [ `/help | Ping: ${client.ws.ping}ms`, `V.${process.env.VERSION}`, diff --git a/features/statuspage.ts b/features/statuspage.ts index 2c09c0d..a555560 100644 --- a/features/statuspage.ts +++ b/features/statuspage.ts @@ -4,7 +4,7 @@ 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( + await 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); diff --git a/index.ts b/index.ts index 3111af8..c85a073 100644 --- a/index.ts +++ b/index.ts @@ -24,7 +24,7 @@ const client = new DiscordJs.Client({ ], }); -client.on("ready", () => { +client.on("ready", async () => { if (client.user) { console.log(chalk.green(`Logged in as ${client.user.tag}!`)); console.log( @@ -32,9 +32,12 @@ client.on("ready", () => { ); // 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); - }); + + await Promise.all( + client.guilds.cache.map(async (guild) => { + await checkForRoles(guild); + }) + ); } const dbOptions = { From a434f192897af8b35baedb6f4e647b447a7980ce Mon Sep 17 00:00:00 2001 From: schiltz3 Date: Tue, 6 Sep 2022 03:29:02 +0000 Subject: [PATCH 44/53] Apply auto formatting changes --- util.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util.ts b/util.ts index ccf6b87..6f992af 100644 --- a/util.ts +++ b/util.ts @@ -1,4 +1,4 @@ -export function sleep(ms: number) { - // Create new promise that resolves itself after a delay of - return new Promise((resolve: Function) => setTimeout(resolve, ms)); -} +export function sleep(ms: number) { + // Create new promise that resolves itself after a delay of + return new Promise((resolve: Function) => setTimeout(resolve, ms)); +} From 3ebf80183c83b42eed6494775980e3423890a45b Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:30:08 -0500 Subject: [PATCH 45/53] remove unused variable JS-0356 --- commands/user/uptime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/user/uptime.ts b/commands/user/uptime.ts index b761a3a..17adffe 100644 --- a/commands/user/uptime.ts +++ b/commands/user/uptime.ts @@ -1,5 +1,5 @@ import chalk from "chalk"; -import { MessageEmbed, TextChannel } from "discord.js"; +import { MessageEmbed } from "discord.js"; import { ICommand } from "wokcommands"; export default { From 5bd4c69ebe6fad5dd491f753f6ed4eaa97f652ed Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:32:44 -0500 Subject: [PATCH 46/53] remove Function type --- util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.ts b/util.ts index 6f992af..7532b00 100644 --- a/util.ts +++ b/util.ts @@ -1,4 +1,4 @@ export function sleep(ms: number) { // Create new promise that resolves itself after a delay of - return new Promise((resolve: Function) => setTimeout(resolve, ms)); + return new Promise((resolve) => setTimeout(resolve, ms)); } From 79cf04aba4060d41c44c0e650ea69d0d182962f4 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:57:46 -0500 Subject: [PATCH 47/53] fix awaiting a non-promise --- index.ts | 2 +- rolesOps.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index c85a073..e0cf81b 100644 --- a/index.ts +++ b/index.ts @@ -35,7 +35,7 @@ client.on("ready", async () => { await Promise.all( client.guilds.cache.map(async (guild) => { - await checkForRoles(guild); + checkForRoles(guild); }) ); } diff --git a/rolesOps.ts b/rolesOps.ts index a950f81..bc54a4d 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -16,10 +16,11 @@ export async function checkIfCollectionsExist(model: Model) { } } async function dbQuery() { - const classes = await classModel.find({}); - const staff = await staffModel.find({}); - const years = await yearModel.find({}); - return [classes, staff, years]; + return await Promise.all([ + classModel.find({}), + staffModel.find({}), + yearModel.find({}), + ]); } export async function getUsersRoles(member: GuildMember): Promise { From 29b870111cc121f75dfe4f8fbccef82712a6d5d3 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 22:57:59 -0500 Subject: [PATCH 48/53] try callback for resolve --- util.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util.ts b/util.ts index 7532b00..e8606bc 100644 --- a/util.ts +++ b/util.ts @@ -1,4 +1,8 @@ export function sleep(ms: number) { // Create new promise that resolves itself after a delay of - return new Promise((resolve) => setTimeout(resolve, ms)); + return new Promise((resolve) => + setTimeout(function () { + resolve; + }, ms) + ); } From 5dfbeb5ba91d6985dc6c4e83c0641279c79983f5 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 23:00:04 -0500 Subject: [PATCH 49/53] return promise for all --- index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index e0cf81b..73d2091 100644 --- a/index.ts +++ b/index.ts @@ -34,8 +34,8 @@ client.on("ready", async () => { console.log("Checking if all roles exist in servers."); await Promise.all( - client.guilds.cache.map(async (guild) => { - checkForRoles(guild); + client.guilds.cache.map((guild) => { + return checkForRoles(guild); }) ); } From 1918b801ef5cd3e243c0471208f3fdb9a858786f Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 23:09:42 -0500 Subject: [PATCH 50/53] don't return in map --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 73d2091..ee5ec5e 100644 --- a/index.ts +++ b/index.ts @@ -35,7 +35,7 @@ client.on("ready", async () => { await Promise.all( client.guilds.cache.map((guild) => { - return checkForRoles(guild); + checkForRoles(guild); }) ); } From a5a6a983a0f415eba186aea5e49db996027af6c9 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 23:23:13 -0500 Subject: [PATCH 51/53] rewrite wait to specify resolve type --- index.ts | 1 + util.ts | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index ee5ec5e..49f69fa 100644 --- a/index.ts +++ b/index.ts @@ -10,6 +10,7 @@ import { checkForRoles, checkIfCollectionsExist } from "./rolesOps"; import { classModel } from "./models/classModel"; import { staffModel } from "./models/staffModel"; import { yearModel } from "./models/yearModel"; +import { sleep } from "./util"; // import all environment variables from .env file dotenv.config(); diff --git a/util.ts b/util.ts index e8606bc..6d492e6 100644 --- a/util.ts +++ b/util.ts @@ -1,8 +1,6 @@ export function sleep(ms: number) { // Create new promise that resolves itself after a delay of - return new Promise((resolve) => - setTimeout(function () { - resolve; - }, ms) + return new Promise((resolve: (args: void) => void) => + setTimeout(resolve, ms) ); } From 70cae6ab3ff66762cd60f0761db2d41c1295d553 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Mon, 5 Sep 2022 23:24:35 -0500 Subject: [PATCH 52/53] remove unused import --- index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/index.ts b/index.ts index 49f69fa..ee5ec5e 100644 --- a/index.ts +++ b/index.ts @@ -10,7 +10,6 @@ import { checkForRoles, checkIfCollectionsExist } from "./rolesOps"; import { classModel } from "./models/classModel"; import { staffModel } from "./models/staffModel"; import { yearModel } from "./models/yearModel"; -import { sleep } from "./util"; // import all environment variables from .env file dotenv.config(); From fd8b571a7a239e3e9329f99ead160ae7fa8164d1 Mon Sep 17 00:00:00 2001 From: John Schiltz Date: Tue, 6 Sep 2022 15:40:34 -0500 Subject: [PATCH 53/53] Fix bug in `addNewRole` switch on wrong field forgot `break` didn't capitalize query field --- rolesOps.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rolesOps.ts b/rolesOps.ts index c890bc5..0f29289 100644 --- a/rolesOps.ts +++ b/rolesOps.ts @@ -63,12 +63,13 @@ export async function addNewRole( ) { // This function is triggered when a user changes their role, it adds the new role to the user let role; - switch (model.constructor) { - case classModel: + switch (model.modelName) { + case "class": //TODO: Rewrite IRole to include name, and replace CODE with name role = await model.findOne({ CODE: id }); + break; default: - role = await model.findOne({ Name: id }); + role = await model.findOne({ NAME: id }); } if (role === null) {