From f1cb716468c0088da51fb1aa9010d93f4f5fb4fc Mon Sep 17 00:00:00 2001 From: AshyBoxy Date: Fri, 1 Nov 2024 22:47:13 +0000 Subject: [PATCH] updates --- .eslintignore | 2 - .eslintrc.json | 123 ---------------------------------- eslint.config.js | 135 ++++++++++++++++++++++++++++++++++++++ index.ts | 2 + package-lock.json | 18 ++--- package.json | 19 +++--- src/Classes/Client.ts | 9 ++- src/Classes/Command.ts | 15 +++-- src/Interfaces/Message.ts | 4 +- 9 files changed, 175 insertions(+), 152 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json create mode 100644 eslint.config.js create mode 100644 index.ts diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index de4d1f0..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -dist -node_modules diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 56194ad..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,123 +0,0 @@ -{ - "parserOptions": { - "ecmaVersion": 2022, - "sourceType": "module" - }, - "env": { - "node": true, - "es2022": true - }, - "root": true, - "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint" - ], - "extends": [ - "eslint:recommended" - ], - "rules": { - "no-console": "error", - "no-extra-boolean-cast": [ - "error", - { - "enforceForLogicalOperands": true - } - ], - "no-template-curly-in-string": "error", - "no-unreachable-loop": "error", - "curly": [ - "error", - "multi" - ], - "default-case-last": "error", - "default-case": "error", - "dot-notation": "error", - "eqeqeq": "error", - "no-empty-function": "error", - "no-lone-blocks": "error", - "require-await": "error", - "yoda": "error", - "array-bracket-newline": [ - "error", - { - "minItems": 2 - } - ], - "camelcase": "error", - "comma-dangle": [ - "error", - "never" - ], - "comma-style": [ - "error", - "last" - ], - "linebreak-style": [ - "error", - "unix" - ], - "new-parens": "error", - "no-trailing-spaces": "error", - "no-unneeded-ternary": "error", - "no-whitespace-before-property": "error", - "operator-assignment": "error", - "arrow-body-style": [ - "error", - "as-needed" - ], - "arrow-parens": "error", - "no-var": "error", - "prefer-const": [ - "error", - { - "destructuring": "any" - } - ], - "prefer-template": "error", - "template-curly-spacing": "error", - "quote-props": [ - "error", - "as-needed", - { - "numbers": true - } - ], - // typescript rules - "comma-spacing": "off", - "quotes": "off" - }, - "overrides": [ - { - "files": [ - "*.ts" - ], - "extends": [ - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "@typescript-eslint/explicit-function-return-type": "error", - "@typescript-eslint/comma-spacing": "error", - "@typescript-eslint/quotes": [ - "error", - "double", - { - "avoidEscape": true - } - ], - "@typescript-eslint/no-var-requires": "off", - "@typescript-eslint/no-namespace": "off", - "no-shadow": "off", - "@typescript-eslint/no-shadow": [ - "error" - ], - "@typescript-eslint/consistent-type-assertions": [ - "error", - { - "assertionStyle": "angle-bracket", - "objectLiteralTypeAssertions": "never" - } - ] - } - } - ] -} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..9425ead --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,135 @@ +import js from "@eslint/js"; +import stylistic from "@stylistic/eslint-plugin"; +import tsParser from "@typescript-eslint/parser"; +import globals from "globals"; +import ts from "typescript-eslint"; + + +const tsConfigMain = ts.configs.recommended.map((config) => ({ + ...config, files: ["**/*.ts"] +})); +const tsConfigStylistic = ts.configs.stylistic.map((config) => ({ + ...config, files: ["**/*.ts"] +})); + + +export default [ + { + ignores: [ + "**/dist", "**/node_modules" + ] + }, + js.configs.recommended, + { + plugins: { + "@typescript-eslint": ts.plugin, + "@stylistic": stylistic + }, + + languageOptions: { + globals: { + ...globals.node + }, + parser: tsParser, + ecmaVersion: 2022, + sourceType: "module" + }, + + rules: { + "no-console": "error", + + "no-extra-boolean-cast": [ + "error", { + enforceForLogicalOperands: true + } + ], + + "no-template-curly-in-string": "error", + "no-unreachable-loop": "error", + curly: [ + "error", "multi" + ], + "default-case-last": "error", + "default-case": "error", + "dot-notation": "error", + eqeqeq: "error", + "no-empty-function": "error", + "no-lone-blocks": "error", + "require-await": "error", + yoda: "error", + + "array-bracket-newline": [ + "error", { + minItems: 2 + } + ], + + camelcase: "error", + "comma-dangle": [ + "error", "never" + ], + "comma-style": [ + "error", "last" + ], + "linebreak-style": [ + "error", "unix" + ], + "new-parens": "error", + "no-trailing-spaces": "error", + "no-unneeded-ternary": "error", + "no-whitespace-before-property": "error", + "operator-assignment": "error", + "arrow-body-style": [ + "error", "as-needed" + ], + "arrow-parens": "error", + "no-var": "error", + + "prefer-const": [ + "error", { + destructuring: "any" + } + ], + + "prefer-template": "error", + "template-curly-spacing": "error", + + "quote-props": [ + "error", "as-needed", { + numbers: true + } + ], + + "comma-spacing": "off", + quotes: "off" + } + }, + ...tsConfigMain, + ...tsConfigStylistic, + { + files: ["**/*.ts"], + + rules: { + "@typescript-eslint/explicit-function-return-type": "error", + "@stylistic/comma-spacing": "error", + + "@stylistic/quotes": [ + "error", "double", { + avoidEscape: true + } + ], + + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-namespace": "off", + "no-shadow": "off", + "@typescript-eslint/no-shadow": ["error"], + + "@typescript-eslint/consistent-type-assertions": [ + "error", { + assertionStyle: "angle-bracket", + objectLiteralTypeAssertions: "never" + } + ] + } + } +]; diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..68c517a --- /dev/null +++ b/index.ts @@ -0,0 +1,2 @@ +// bun doesn't seem to look for package.json for relative path imports +export * from "./src"; diff --git a/package-lock.json b/package-lock.json index a7023e3..cffb34d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "devDependencies": { "@types/leveldown": "^4.0.4", "@types/levelup": "^5.1.3", - "@types/node": "^20.12.7", + "@types/node": "^22.8.6", "@typescript-eslint/eslint-plugin": "^6.6.0", "@typescript-eslint/parser": "^6.6.0", "eslint": "^8.48.0", @@ -313,11 +313,12 @@ } }, "node_modules/@types/node": { - "version": "20.12.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", - "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "version": "22.8.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.6.tgz", + "integrity": "sha512-tosuJYKrIqjQIlVCM4PEGxOmyg3FCPa/fViuJChnGeEIhjA46oy8FMVoF9su1/v8PNs2a8Q0iFNyOx0uOF91nw==", + "license": "MIT", "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.19.8" } }, "node_modules/@types/semver": { @@ -2074,9 +2075,10 @@ } }, "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "license": "MIT" }, "node_modules/uri-js": { "version": "4.4.1", diff --git a/package.json b/package.json index e576980..d67d836 100644 --- a/package.json +++ b/package.json @@ -24,18 +24,21 @@ "author": "AshyBoxy ", "license": "MIT", "dependencies": { - "discord.js": "^14.13.0", + "discord.js": "^14.16.3", "leveldown": "^6.1.1", "levelup": "^5.1.1", "resolve": "^1.22.8" }, "devDependencies": { - "@types/leveldown": "^4.0.4", - "@types/levelup": "^5.1.3", - "@types/node": "^20.12.7", - "@typescript-eslint/eslint-plugin": "^6.6.0", - "@typescript-eslint/parser": "^6.6.0", - "eslint": "^8.48.0", - "typescript": "^5.2.2" + "@types/leveldown": "^4.0.6", + "@types/levelup": "^5.1.5", + "@types/node": "^22.8.6", + "eslint": "^9.14.0", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.14.0", + "@stylistic/eslint-plugin": "^2.10.1", + "globals": "^15.11.0", + "typescript": "^5.6.3", + "typescript-eslint": "^8.12.2" } } diff --git a/src/Classes/Client.ts b/src/Classes/Client.ts index 74050d3..e725637 100644 --- a/src/Classes/Client.ts +++ b/src/Classes/Client.ts @@ -40,6 +40,9 @@ class MapDB implements IDatabase { close = (): Promise => new Promise((r) => r()); } +const validFileRegex = /\.[tj]s$/; +const fileSplitRegex = /\.[tj]s/; + // using true here basically makes typescript assume the bot is ready // meaning it won't enforce type checking // this probably shouldn't be left like this(?) @@ -81,7 +84,7 @@ class BreadClient> = Record ({ path: x, dir: this.config.eventsPath })) : [], ...readdirSync(BreadClient.BuiltInEventPath).map((x) => ({ path: x, dir: BreadClient.BuiltInEventPath })) - ].filter((x: eventFile) => x.path.endsWith(".js")); + ].filter((x: eventFile) => validFileRegex.test(x.path)); for (let i = 0; i < eventFiles.length; i++) { const event: EventHandler = (await import(path.join(eventFiles[i].dir, eventFiles[i].path))).default; @@ -103,13 +106,13 @@ class BreadClient> = Record x.endsWith(".js")); + const cmdFiles = readdirSync(path.join(this.modules[i].path.startsWith("/") ? "" : this.config.commandsPath || "", this.modules[i].path)).filter((x: string) => validFileRegex.test(x)); const commands: string[] = []; for (let x = 0; x < cmdFiles.length; x++) { const cmd: Command = (await import(path.join(this.modules[i].path.startsWith("/") ? "" : this.config.commandsPath || "", this.modules[i].path, cmdFiles[x]))).default; if (!cmd?.run || !cmd?.name) { - warnings.push(strings.get("bread_framework.classes.breadclient.commandwarning", cmdFiles[x].split(".js")[0], this.modules[i].name)); + warnings.push(strings.get("bread_framework.classes.breadclient.commandwarning", cmdFiles[x].split(fileSplitRegex)[0], this.modules[i].name)); continue; } cmd.module = this.modules[i]; diff --git a/src/Classes/Command.ts b/src/Classes/Command.ts index d5fa010..b97864d 100644 --- a/src/Classes/Command.ts +++ b/src/Classes/Command.ts @@ -1,10 +1,11 @@ -import { ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder, TextBasedChannel } from "discord.js"; -import Client from "./Client"; +import { InteractionContextType } from "discord-api-types/v10"; +import { ChatInputCommandInteraction, PartialGroupDMChannel, PermissionResolvable, SlashCommandBuilder, TextBasedChannel } from "discord.js"; import IGeneralCommandData from "../Interfaces/GeneralCommandData"; -import IModule from "../Interfaces/Module"; import BreadMessage from "../Interfaces/Message"; +import IModule from "../Interfaces/Module"; +import Client from "./Client"; -export type run = (bot: Client, message: BreadMessage | (ChatInputCommandInteraction & { channel: TextBasedChannel; }), args: string[]) => number | void | Promise; +export type run = (bot: Client, message: BreadMessage | (ChatInputCommandInteraction & { channel: Exclude; }), args: string[]) => number | void | Promise; class Command implements IGeneralCommandData { @@ -25,7 +26,7 @@ class Command implements IGeneralCommandData { module: IModule = { name: "None", path: "none", - description: "Not part of a module???" + description: "Placeholder module" }; constructor(execute: run, data: IGeneralCommandData) { @@ -44,7 +45,9 @@ class Command implements IGeneralCommandData { this.slashCommand = new SlashCommandBuilder() .setName(this.name.toLowerCase()) .setDescription(this.info) - .setDMPermission(!this.dmOnly); + .setContexts(this.dmOnly ? [InteractionContextType.BotDM] : this.guildOnly ? [InteractionContextType.Guild] : [InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel]); + + if (this.guildOnly && this.dmOnly) throw new Error(`${this.name} is both a dm and guild only command?`); } } diff --git a/src/Interfaces/Message.ts b/src/Interfaces/Message.ts index e092301..7f2e3f0 100644 --- a/src/Interfaces/Message.ts +++ b/src/Interfaces/Message.ts @@ -1,4 +1,4 @@ -import { Message, StageChannel } from "discord.js"; +import { Message, PartialGroupDMChannel, StageChannel } from "discord.js"; import BreadClient from "../Classes/Client"; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -7,6 +7,6 @@ type ReplaceReturnType any, TNewReturn> = (...a: Parame // following BreadClient's naming scheme export default interface BreadMessage extends Message { client: BreadClient; - channel: Exclude; // reasons + channel: Exclude; // reasons fetch: ReplaceReturnType<(force?: boolean) => Promise, Promise>; }