From d89697d5d986546fc989f96644b4628b87e30007 Mon Sep 17 00:00:00 2001 From: Rdeisenroth Date: Mon, 23 Oct 2023 03:59:37 +0200 Subject: [PATCH] minor fixes --- nodemon.json | 5 ++ package-lock.json | 124 ++++++++++++++++++++++++++- package.json | 4 +- src/bot.ts | 9 +- src/events/InteractionCreateEvent.ts | 2 + src/models/guild_settings.ts | 4 +- src/models/guilds.ts | 2 +- src/models/queues.ts | 7 +- src/models/slash_command_settings.ts | 2 +- tsconfig.json | 2 +- 10 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 nodemon.json diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..0d7fe4c --- /dev/null +++ b/nodemon.json @@ -0,0 +1,5 @@ +{ + "execMap": { + "ts": "ts-node" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index de9ca6b..8c3d154 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "@types/glob": "^8.1.0", "@types/jest": "^29.5.5", "@types/mocha": "^10.0.2", - "@types/moment-duration-format": "^2.2.4", + "@types/moment-duration-format": "^2.2.5", "@types/urban-dictionary": "^3.0.0", "@types/yargs": "^17.0.28", "@types/yargs-parser": "^21.0.1", @@ -54,6 +54,7 @@ "eslint": "^8.51.0", "jest": "^29.7.0", "mocha": "^10.2.0", + "nodemon": "^3.0.1", "ts-jest": "^29.1.1", "ts-mockito": "^2.6.1", "ts-node": "^10.9.1", @@ -1684,9 +1685,9 @@ "dev": true }, "node_modules/@types/moment-duration-format": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/@types/moment-duration-format/-/moment-duration-format-2.2.4.tgz", - "integrity": "sha512-yKbULlpoDMYAW2eLQNpvXDH1yEFz83qyRhQP1c/Xl5+/pfqEjhlHN//Oy8scLSsXEHy5vY3Ph3eUsoHckSq+zg==", + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/@types/moment-duration-format/-/moment-duration-format-2.2.5.tgz", + "integrity": "sha512-0ojMdyThftIMXblaNFbIC4RUNUuiKyXP9BwywS6fm6L4Sod78ziFzO+cH2UWReexJo3go3xhkY3CVdcBiryocg==", "dev": true, "dependencies": { "moment": ">=2.14.0" @@ -4104,6 +4105,12 @@ "node": ">= 4" } }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", + "dev": true + }, "node_modules/import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", @@ -5873,6 +5880,64 @@ "integrity": "sha512-QzsYKWhXTWx8h1kIvqfnC++o0pEmpRQA/aenALsL2F4pqNVr7YzcdMlDij5WBnwftRbJCNJL/O7zdKaxKPHqgQ==", "dev": true }, + "node_modules/nodemon": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz", + "integrity": "sha512-g9AZ7HmkhQkqXkRc20w+ZfQ73cHLbE8hnPbtaFbFtCumZsjyMhKk9LajQ07U5Ux28lvFjZ5X7HvWR1xzU8jHVw==", + "dev": true, + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^3.2.7", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/nodemon/node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/nodemon/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/nodemon/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/nopt": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", @@ -6325,6 +6390,12 @@ "node": ">= 6" } }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", + "dev": true + }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", @@ -6709,6 +6780,18 @@ "simple-concat": "^1.0.0" } }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "dev": true, + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", @@ -7115,6 +7198,33 @@ "node": ">=8.0" } }, + "node_modules/touch": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", + "integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", + "dev": true, + "dependencies": { + "nopt": "~1.0.10" + }, + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, + "node_modules/touch/node_modules/nopt": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", + "integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==", + "dev": true, + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": "*" + } + }, "node_modules/tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", @@ -7325,6 +7435,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", + "dev": true + }, "node_modules/undici": { "version": "5.22.1", "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", diff --git a/package.json b/package.json index 4824117..fc7cc4b 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "type": "commonjs", "scripts": { "start": "tsc --build --clean tsconfig.json; tsc --build tsconfig.json; node dist/index.js", + "nodemon": "nodemon --watch 'src/**/*.ts' src/index.ts", "build": "tsc --build --clean tsconfig.json; tsc --build tsconfig.json", "lint": "eslint --ext .ts src/", "watch": "tsc -p tsconfig.json -w", @@ -49,7 +50,7 @@ "@types/glob": "^8.1.0", "@types/jest": "^29.5.5", "@types/mocha": "^10.0.2", - "@types/moment-duration-format": "^2.2.4", + "@types/moment-duration-format": "^2.2.5", "@types/urban-dictionary": "^3.0.0", "@types/yargs": "^17.0.28", "@types/yargs-parser": "^21.0.1", @@ -59,6 +60,7 @@ "eslint": "^8.51.0", "jest": "^29.7.0", "mocha": "^10.2.0", + "nodemon": "^3.0.1", "ts-jest": "^29.1.1", "ts-mockito": "^2.6.1", "ts-node": "^10.9.1", diff --git a/src/bot.ts b/src/bot.ts index d3c365e..c399fcd 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -62,7 +62,12 @@ export class Bot extends Client { */ public async start(): Promise { this.logger.info("starting Bot..."); - this.login(this.config.get("token")).catch((e) => this.logger.error(e)); + try { + await this.login(this.config.get("token")); + } catch (error) { + this.logger.error("Invalid token", error); + process.exit(1); + } // Commands this.logger.info("Loading Commands..."); @@ -189,6 +194,8 @@ export class Bot extends Client { }, null, true, "America/Los_Angeles"); queueGuardJob.start(); + this.logger.ready(`Bot ${this.user?.displayName} is Ready!`); + // public async createGuildCommand(data:any, guildId:string) { // return await this.api.appl // } diff --git a/src/events/InteractionCreateEvent.ts b/src/events/InteractionCreateEvent.ts index b434d74..05f019b 100644 --- a/src/events/InteractionCreateEvent.ts +++ b/src/events/InteractionCreateEvent.ts @@ -2,6 +2,8 @@ import { Command, ExecuteEvent } from "../../typings"; import { ChatInputCommandInteraction, Collection, CommandInteractionOption } from "discord.js"; export const name = "interactionCreate"; import {GuildModel} from "../models/guilds"; +import { DocumentType, isDocument } from "@typegoose/typegoose"; +import { GuildSettings } from "../models/guild_settings"; export const execute: ExecuteEvent<"interactionCreate"> = async (client, interaction) => { diff --git a/src/models/guild_settings.ts b/src/models/guild_settings.ts index 7ad40cf..5db3201 100644 --- a/src/models/guild_settings.ts +++ b/src/models/guild_settings.ts @@ -26,12 +26,12 @@ export class GuildSettings { /** * The Guild Specific command Settings */ - @prop({ required: true, default: [], type: () => [SlashCommandSettings] }) + @prop({ required: true, default: [], type: () => SlashCommandSettings }) slashCommands!: mongoose.Types.DocumentArray>; /** * The Guild Specific role Settings */ - @prop({ default: [], type: () => [DBRole] }) + @prop({ default: [], type: () => DBRole }) roles?: mongoose.Types.DocumentArray>; /** * The User Account URL related to the guild diff --git a/src/models/guilds.ts b/src/models/guilds.ts index 2994864..20d1684 100644 --- a/src/models/guilds.ts +++ b/src/models/guilds.ts @@ -30,7 +30,7 @@ export class Guild { /** * The Settings for the Guild */ - @prop({ required: true }) + @prop({ required: true, type: () => GuildSettings }) guild_settings!: SubDocumentType; /** * The Relevant Text Channels of the Guild diff --git a/src/models/queues.ts b/src/models/queues.ts index ae852a1..beae820 100644 --- a/src/models/queues.ts +++ b/src/models/queues.ts @@ -3,7 +3,8 @@ import { VoiceChannel } from "./voice_channels"; import { QueueEntry } from "./queue_entry"; import * as utils from "../utils/utils"; import { StringReplacements } from "../../typings"; -import moment from "moment"; +import * as moment from "moment"; +import momentDurationFormatSetup from "moment-duration-format"; import { QueueSpan } from "./queue_span"; import { Guild } from "./guilds"; import { VoiceChannelSpawner } from "./voice_channel_spawner"; @@ -65,7 +66,7 @@ export class Queue { /** * A Template for spawning in Rooms (if empty default template is used) */ - @prop({ type: () => VoiceChannel }) + @prop({ type: () => VoiceChannelSpawner }) room_spawner?: SubDocumentType; /** * A text Channel to use if dms are disabled @@ -315,7 +316,7 @@ export class Queue { * Returns `true` if the Queue is Empty */ public isEmpty(this: DocumentType): boolean{ - return !!this.entries.length; + return this.entries.length < 1; } /** * Locks the queue. This removes the voice Channel Permissions and disallows the queue from the /queue join command diff --git a/src/models/slash_command_settings.ts b/src/models/slash_command_settings.ts index e32bcf4..1cb0de0 100644 --- a/src/models/slash_command_settings.ts +++ b/src/models/slash_command_settings.ts @@ -21,7 +21,7 @@ export class SlashCommandSettings { * The Default Command Permission overwrite */ @prop({ required: false }) - defaultPermission?: SubDocumentType; + defaultPermission?: PermissionResolvable; /** * If the command should be completely removed from the slash command List */ diff --git a/tsconfig.json b/tsconfig.json index 43725ae..5b37f82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2019", + "target": "ES2022", "module": "commonjs", // "moduleResolution": "node", "strict": true,