From 05fc3fbeba743a33cd5fbdc2cf0a91407d22d20a Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 1 Apr 2023 02:46:46 +0200 Subject: [PATCH] style: format (#2925) --- .devcontainer/devcontainer.json | 52 +++---- .eslintrc.json | 10 +- .github/workflows/other-runtime-unit-test.yml | 2 +- .github/workflows/release.yml | 6 +- .github/workflows/site.yml | 28 ++-- .github/workflows/sync_repos.yml | 4 +- .gitignore | 2 + .gitpod.yml | 2 - .helix/languages.toml | 4 + .vscode/settings.json | 2 +- .yarnrc.yml | 4 +- denoImportMap.json | 2 +- examples/.vscode/settings.json | 10 +- examples/bigbot/docker-compose.yml | 4 +- examples/bigbot/nodemon.json | 8 +- examples/bigbot/package.json | 100 ++++++------- .../bigbot/src/bot/languages/translate.ts | 4 +- .../src/bot/utils/slash/createCommand.ts | 2 +- examples/nodejs/Managers/CommandManager.js | 138 +++++++++--------- examples/nodejs/Managers/EventManager.js | 40 ++--- .../nodejs/Plugins/Developer/commands/eval.js | 71 ++++----- .../Plugins/Developer/commands/reload.js | 24 +-- .../nodejs/Plugins/General/commands/ping.js | 28 ++-- .../nodejs/Plugins/Moderation/commands/ban.js | 50 ++++--- .../Plugins/Moderation/commands/warn.js | 119 ++++++++------- examples/nodejs/Structures/BaseCommand.js | 22 +-- examples/nodejs/Structures/CommandResponse.js | 44 +++--- examples/nodejs/events/interactionCreate.js | 6 +- examples/nodejs/events/messageCreate.js | 6 +- examples/nodejs/events/ready.js | 6 +- examples/nodejs/index.js | 30 ++-- jsdoc2md.json | 5 +- packages/benchmark/tsconfig.json | 16 +- packages/bot/src/handlers/channels/index.ts | 24 +-- packages/bot/src/handlers/emojis/index.ts | 2 +- .../handlers/guilds/GUILD_STICKERS_UPDATE.ts | 6 +- packages/bot/src/handlers/guilds/index.ts | 20 +-- .../handlers/guilds/scheduledEvents/index.ts | 10 +- .../bot/src/handlers/integrations/index.ts | 6 +- .../APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts | 8 +- packages/bot/src/handlers/invites/index.ts | 4 +- packages/bot/src/handlers/members/index.ts | 8 +- packages/bot/src/handlers/messages/index.ts | 16 +- packages/bot/src/handlers/misc/index.ts | 8 +- packages/bot/src/handlers/roles/index.ts | 6 +- packages/bot/src/handlers/voice/index.ts | 4 +- .../src/handlers/webhooks/WEBHOOKS_UPDATE.ts | 2 +- packages/bot/src/handlers/webhooks/index.ts | 2 +- .../bot/src/transformers/reverse/index.ts | 32 ++-- .../transformers/toggles/ToggleBitfield.ts | 28 ++-- .../bot/src/transformers/toggles/index.ts | 14 +- packages/bot/tsconfig.json | 16 +- packages/bot/tsconfig.test.json | 12 +- packages/discordeno/tsconfig.json | 16 +- packages/discordeno/tsconfig.test.json | 12 +- packages/gateway/src/Shard.ts | 2 +- packages/gateway/tsconfig.json | 16 +- packages/gateway/tsconfig.test.json | 12 +- packages/rest/src/manager.ts | 10 +- packages/rest/tests/e2e/guild.spec.ts | 1 - packages/rest/tests/e2e/utils.ts | 4 +- packages/rest/tests/e2e/webhook.spec.ts | 2 - packages/rest/tsconfig.json | 16 +- packages/rest/tsconfig.test.json | 12 +- packages/tsconfig/test.json | 2 +- packages/types/src/index.ts | 2 +- packages/types/tsconfig.json | 16 +- packages/types/tsconfig.test.json | 12 +- packages/utils/src/casing.ts | 4 +- packages/utils/tests/logger.spec.ts | 4 +- packages/utils/tsconfig.json | 16 +- packages/utils/tsconfig.test.json | 12 +- scripts/coveragePathFixing.js | 7 +- scripts/finalizeTypedocs.js | 10 +- tsconfig.json | 14 +- turbo.json | 81 +++------- typedoc.json | 24 +-- website/babel.config.js | 7 +- website/blog/changelogs/19.0.0.md | 2 +- website/docs/bigbot/step-1-decisions.md | 1 - website/docs/bigbot/step-2-rest.md | 15 +- website/docs/bigbot/step-3-gateway.md | 66 ++++----- website/docs/generated/README.md | 2 +- .../docs/generated/classes/_category_.json | 13 +- website/sidebars.js | 6 +- 85 files changed, 670 insertions(+), 828 deletions(-) create mode 100644 .helix/languages.toml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 991516fec..139305d94 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,36 +1,32 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/typescript-node { - "name": "Node.js & TypeScript", - "build": { - "dockerfile": "Dockerfile", - // Update 'VARIANT' to pick a Node version: 18, 16, 14. - // Append -bullseye or -buster to pin to an OS version. - // Use -bullseye variants on local on arm64/Apple Silicon. - "args": { - "VARIANT": "18-bullseye" - } - }, + "name": "Node.js & TypeScript", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick a Node version: 18, 16, 14. + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "args": { + "VARIANT": "18-bullseye" + } + }, - // Configure tool-specific properties. - "customizations": { - // Configure properties specific to VS Code. - "vscode": { - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "dbaeumer.vscode-eslint", - "esbenp.prettier-vscode", - "TabNine.tabnine-vscode" - ] - } - }, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "TabNine.tabnine-vscode"] + } + }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "yarn install", + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "yarn install", - // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "node", + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "node" } diff --git a/.eslintrc.json b/.eslintrc.json index d94a7377d..f4c676fd3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,5 @@ { - "root": true, - // This tells ESLint to load the config from the package `eslint-config-custom` - "extends": [ - "discordeno" - ] -} \ No newline at end of file + "root": true, + // This tells ESLint to load the config from the package `eslint-config-custom` + "extends": ["discordeno"] +} diff --git a/.github/workflows/other-runtime-unit-test.yml b/.github/workflows/other-runtime-unit-test.yml index 344c333a2..68c70f8fb 100644 --- a/.github/workflows/other-runtime-unit-test.yml +++ b/.github/workflows/other-runtime-unit-test.yml @@ -18,7 +18,7 @@ jobs: node-version: 18 - uses: denoland/setup-deno@main with: - deno-version: "v1.29" + deno-version: 'v1.29' - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 11c776b0f..63dbf5141 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,14 +18,14 @@ jobs: strategy: fail-fast: false matrix: - package: ["gateway", "rest", "types", "utils", "bot"] + package: ['gateway', 'rest', 'types', 'utils', 'bot'] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18 - registry-url: "https://registry.npmjs.org" - scope: "@discordeno" + registry-url: 'https://registry.npmjs.org' + scope: '@discordeno' - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index 80d3c1001..4c8ca9e0d 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -6,23 +6,23 @@ name: Deploy Docs Site on: # Triggers the workflow on push or pull request events but only for the "main" branch push: - branches: ["main"] + branches: ['main'] paths: - - "website/**" - - ".github/workflows/site.yml" - - "jsdoc2md.json" - - "typedoc.json" - - "package.json" - - "packages/**" + - 'website/**' + - '.github/workflows/site.yml' + - 'jsdoc2md.json' + - 'typedoc.json' + - 'package.json' + - 'packages/**' pull_request: - branches: ["main"] + branches: ['main'] paths: - - "website/**" - - ".github/workflows/site.yml" - - "jsdoc2md.json" - - "typedoc.json" - - "package.json" - - "packages/**" + - 'website/**' + - '.github/workflows/site.yml' + - 'jsdoc2md.json' + - 'typedoc.json' + - 'package.json' + - 'packages/**' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/sync_repos.yml b/.github/workflows/sync_repos.yml index 60860953b..653f258ae 100644 --- a/.github/workflows/sync_repos.yml +++ b/.github/workflows/sync_repos.yml @@ -5,8 +5,8 @@ on: branches: - main paths: - - "website/**" - # - "template/**" + - 'website/**' + # - "template/**" jobs: sync: diff --git a/.gitignore b/.gitignore index 91d8e5cc9..2889f596d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ # Test file for testing dd changes debug.ts +testing + # dependencies node_modules diff --git a/.gitpod.yml b/.gitpod.yml index 72c309053..e2b6d816a 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -7,5 +7,3 @@ tasks: - init: yarn install && yarn run build && yarn run lint && yarn run build:doc command: yarn run dev - - diff --git a/.helix/languages.toml b/.helix/languages.toml new file mode 100644 index 000000000..40e086475 --- /dev/null +++ b/.helix/languages.toml @@ -0,0 +1,4 @@ +[[language]] +name = "typescript" +formatter = { command = "npx" , args = ["prettier", "--write", "."] } + diff --git a/.vscode/settings.json b/.vscode/settings.json index e1627da12..e77cd721f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,4 +12,4 @@ "yaml.schemas": { "https://json.schemastore.org/github-workflow.json": "file:///c%3A/Users/Heihe/Downloads/discordeno/discordeno/.github/workflows/site.yml" } -} \ No newline at end of file +} diff --git a/.yarnrc.yml b/.yarnrc.yml index b31951a03..4e0a5e1e9 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -2,8 +2,8 @@ nodeLinker: node-modules plugins: - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs - spec: "@yarnpkg/plugin-typescript" + spec: '@yarnpkg/plugin-typescript' - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs - spec: "@yarnpkg/plugin-interactive-tools" + spec: '@yarnpkg/plugin-interactive-tools' yarnPath: .yarn/releases/yarn-3.3.0.cjs diff --git a/denoImportMap.json b/denoImportMap.json index 36dd25d67..a2c52b31d 100644 --- a/denoImportMap.json +++ b/denoImportMap.json @@ -19,4 +19,4 @@ "@discordeno/gateway": "./packages/gateway/dist/index.js", "@discordeno/bot": "./packages/bot/dist/index.js" } -} \ No newline at end of file +} diff --git a/examples/.vscode/settings.json b/examples/.vscode/settings.json index aa0db1af7..1eafdc762 100644 --- a/examples/.vscode/settings.json +++ b/examples/.vscode/settings.json @@ -11,15 +11,7 @@ "https://deno.land": true }, "discord.enabled": true, - "cSpell.words": [ - "denoland", - "Discordeno", - "Kwik", - "Loglevels", - "msgpack", - "Slowmode", - "upsert" - ], + "cSpell.words": ["denoland", "Discordeno", "Kwik", "Loglevels", "msgpack", "Slowmode", "upsert"], "deno.unstable": true, "deno.inlayHints.enumMemberValues.enabled": true, "deno.inlayHints.functionLikeReturnTypes.enabled": true, diff --git a/examples/bigbot/docker-compose.yml b/examples/bigbot/docker-compose.yml index 3ccdaf1d7..f0d2a9d15 100644 --- a/examples/bigbot/docker-compose.yml +++ b/examples/bigbot/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.8' services: influxdb: - image: "influxdb:2.4.0-alpine" + image: 'influxdb:2.4.0-alpine' ports: - 127.0.0.1:8086:8086 env_file: @@ -41,4 +41,4 @@ services: deploy: replicas: 2 env_file: - - .env \ No newline at end of file + - .env diff --git a/examples/bigbot/nodemon.json b/examples/bigbot/nodemon.json index 67912f1f7..cfc23ffd7 100644 --- a/examples/bigbot/nodemon.json +++ b/examples/bigbot/nodemon.json @@ -1,6 +1,6 @@ { - "watch": "./src/**/*.ts", - "ext ": "env,ts", - "signal": "SIGKILL", - "exec": "npm run build && node" + "watch": "./src/**/*.ts", + "ext ": "env,ts", + "signal": "SIGKILL", + "exec": "npm run build && node" } diff --git a/examples/bigbot/package.json b/examples/bigbot/package.json index 4ef9dd4d3..fdbf492a6 100644 --- a/examples/bigbot/package.json +++ b/examples/bigbot/package.json @@ -1,51 +1,51 @@ { - "name": "dd-big-bot", - "version": "1.0.0", - "main": "index.js", - "type": "module", - "scripts": { - "devbg": "npx prisma generate && tsc --watch", - "fmt": "eslint --fix \"src/**/*.ts*\"", - "devg": "nodemon --ignore ./src/bot/**/* --ignore ./src/rest/**/* --ignore ./dist/**/* -e ts dist/gateway/index.js", - "devr": "nodemon --ignore ./src/bot/**/* --ignore ./src/gateway/**/* --ignore ./dist/**/* -e ts dist/rest/index.js", - "devb": "nodemon --ignore ./src/rest/**/* --ignore ./src/gateway/**/* --ignore ./dist/**/* -e ts dist/bot/index.js", - "type": "tsc --noEmit", - "build": "swc --delete-dir-on-start src --out-dir dist", - "startr": "node dist/rest/index.js", - "startg": "node dist/gateway/index.js", - "startb": "node dist/bot/index.js" - }, - "dependencies": { - "@influxdata/influxdb-client": "^1.29.0", - "@prisma/client": "^3.15.2", - "amqplib": "^0.10.3", - "colorette": "^2.0.19", - "discordeno": "^16.0.1", - "dotenv": "^16.0.3", - "express": "^4.18.1", - "fastify": "^4.10.2", - "nanoid": "^4.0.0", - "node-fetch": "^3.2.10", - "web-worker": "^1.2.0" - }, - "devDependencies": { - "@swc/cli": "^0.1.57", - "@swc/core": "^1.3.9", - "@types/amqplib": "^0.8.2", - "@types/express": "^4.17.13", - "@types/node": "^17.0.23", - "@types/ws": "^8.5.3", - "nodemon": "^2.0.15", - "prettier": "2.6.2", - "prisma": "^4.2.1", - "typescript": "^4.6.3" - }, - "prettier": { - "trailingComma": "all", - "useTabs": true, - "tabWidth": 2, - "singleQuote": true, - "semi": true, - "printWidth": 120 - } -} \ No newline at end of file + "name": "dd-big-bot", + "version": "1.0.0", + "main": "index.js", + "type": "module", + "scripts": { + "devbg": "npx prisma generate && tsc --watch", + "fmt": "eslint --fix \"src/**/*.ts*\"", + "devg": "nodemon --ignore ./src/bot/**/* --ignore ./src/rest/**/* --ignore ./dist/**/* -e ts dist/gateway/index.js", + "devr": "nodemon --ignore ./src/bot/**/* --ignore ./src/gateway/**/* --ignore ./dist/**/* -e ts dist/rest/index.js", + "devb": "nodemon --ignore ./src/rest/**/* --ignore ./src/gateway/**/* --ignore ./dist/**/* -e ts dist/bot/index.js", + "type": "tsc --noEmit", + "build": "swc --delete-dir-on-start src --out-dir dist", + "startr": "node dist/rest/index.js", + "startg": "node dist/gateway/index.js", + "startb": "node dist/bot/index.js" + }, + "dependencies": { + "@influxdata/influxdb-client": "^1.29.0", + "@prisma/client": "^3.15.2", + "amqplib": "^0.10.3", + "colorette": "^2.0.19", + "discordeno": "^16.0.1", + "dotenv": "^16.0.3", + "express": "^4.18.1", + "fastify": "^4.10.2", + "nanoid": "^4.0.0", + "node-fetch": "^3.2.10", + "web-worker": "^1.2.0" + }, + "devDependencies": { + "@swc/cli": "^0.1.57", + "@swc/core": "^1.3.9", + "@types/amqplib": "^0.8.2", + "@types/express": "^4.17.13", + "@types/node": "^17.0.23", + "@types/ws": "^8.5.3", + "nodemon": "^2.0.15", + "prettier": "2.6.2", + "prisma": "^4.2.1", + "typescript": "^4.6.3" + }, + "prettier": { + "trailingComma": "all", + "useTabs": true, + "tabWidth": 2, + "singleQuote": true, + "semi": true, + "printWidth": 120 + } +} diff --git a/examples/bigbot/src/bot/languages/translate.ts b/examples/bigbot/src/bot/languages/translate.ts index 75371353e..492ec860f 100644 --- a/examples/bigbot/src/bot/languages/translate.ts +++ b/examples/bigbot/src/bot/languages/translate.ts @@ -79,6 +79,6 @@ export async function missingTranslation(language: keyof typeof languages, key: // type translationKeys = keyof typeof english | string export type translationKeys = keyof typeof english; -type getArgs = typeof english[K] extends (...any: any[]) => unknown - ? Parameters +type getArgs = (typeof english)[K] extends (...any: any[]) => unknown + ? Parameters<(typeof english)[K]> : []; diff --git a/examples/bigbot/src/bot/utils/slash/createCommand.ts b/examples/bigbot/src/bot/utils/slash/createCommand.ts index 0d2747a23..e4e360d4d 100644 --- a/examples/bigbot/src/bot/utils/slash/createCommand.ts +++ b/examples/bigbot/src/bot/utils/slash/createCommand.ts @@ -150,7 +150,7 @@ export type ArgumentDefinition = | SubcommandArgumentDefinition | SubcommandGroupArgumentDefinition; -type getName = typeof english[K] extends string ? typeof english[K] : never; +type getName = (typeof english)[K] extends string ? (typeof english)[K] : never; // OPTIONALS MUST BE FIRST!!! export type ConvertArgumentDefinitionsToArgs = Identity< diff --git a/examples/nodejs/Managers/CommandManager.js b/examples/nodejs/Managers/CommandManager.js index 3baf6d2e4..69670e352 100644 --- a/examples/nodejs/Managers/CommandManager.js +++ b/examples/nodejs/Managers/CommandManager.js @@ -1,91 +1,91 @@ -const resolveFolder = (folderName) => path.resolve(__dirname, ".", folderName); -const fs = require("fs"); -const path = require("path"); +const resolveFolder = (folderName) => path.resolve(__dirname, '.', folderName) +const fs = require('fs') +const path = require('path') class CommandManager { constructor(client) { - this.client = client; - this.cache = new Map(); - this.aliases = new Map(); + this.client = client + this.cache = new Map() + this.aliases = new Map() } load(options = {}) { - const commandFolderPath = options.path || "../Plugins"; - const commandFolder = resolveFolder(commandFolderPath); - if (options.category === undefined) options.category = true; - if (options.plugins === undefined) options.plugins = true; + const commandFolderPath = options.path || '../Plugins' + const commandFolder = resolveFolder(commandFolderPath) + if (options.category === undefined) options.category = true + if (options.plugins === undefined) options.plugins = true // PluginMode will iterate through all SubFolders fs.readdirSync(commandFolder).map(async (dir) => { - if (dir.endsWith(".txt")) return; - if (!options.category && dir.endsWith(".js")) { - const commandPath = path.join(commandFolder, dir); - this.loadCommand(commandPath); + if (dir.endsWith('.txt')) return + if (!options.category && dir.endsWith('.js')) { + const commandPath = path.join(commandFolder, dir) + this.loadCommand(commandPath) } else { fs.readdirSync(path.join(commandFolder, dir)).map((cmd) => { - if (cmd.endsWith(".js") && !options.plugins) { - const commandPath = path.join(commandFolder, dir, cmd); - this.loadCommand(commandPath); - } else if (commandFolderPath === "../Plugins") { - if (cmd !== "commands") return; + if (cmd.endsWith('.js') && !options.plugins) { + const commandPath = path.join(commandFolder, dir, cmd) + this.loadCommand(commandPath) + } else if (commandFolderPath === '../Plugins') { + if (cmd !== 'commands') return fs.readdirSync(path.join(commandFolder, dir, cmd)).map((cmdfile) => { - if (!cmdfile.endsWith(".js")) return; - const commandPath = path.join(commandFolder, dir, cmd, cmdfile); - this.loadCommand(commandPath); - }); + if (!cmdfile.endsWith('.js')) return + const commandPath = path.join(commandFolder, dir, cmd, cmdfile) + this.loadCommand(commandPath) + }) } - }); + }) } - }); + }) } loadCommand(commandPath) { - const pull = require(path.join(commandPath)); + const pull = require(path.join(commandPath)) if (pull.name) { - pull.path = commandPath; - this.cache.set(pull.name, pull); + pull.path = commandPath + this.cache.set(pull.name, pull) } if (pull.aliases) { - pull.aliases.map((p) => this.aliases.set(p, pull)); + pull.aliases.map((p) => this.aliases.set(p, pull)) } - return pull; + return pull } reloadCommand(commandName) { - const command = this.cache.get(commandName); - if (!command) return; - const commandPath = path.join(command.path); - delete require.cache[require.resolve(commandPath)]; - return this.loadCommand(commandPath); + const command = this.cache.get(commandName) + if (!command) return + const commandPath = path.join(command.path) + delete require.cache[require.resolve(commandPath)] + return this.loadCommand(commandPath) } isCommand(message) { - if (message.isFromBot) return false; - const prefix = "!"; - const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - const prefixRegex = new RegExp(`^(<@!?${this.client.id}>|${escapeRegex(prefix)})\\s*`); - if (!prefixRegex.test(message.content)) return false; + if (message.isFromBot) return false + const prefix = '!' + const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + const prefixRegex = new RegExp(`^(<@!?${this.client.id}>|${escapeRegex(prefix)})\\s*`) + if (!prefixRegex.test(message.content)) return false - const [, matchedPrefix] = message.content.match(prefixRegex); - const args = message.content.slice(matchedPrefix.length).trim().split(/ +/); + const [, matchedPrefix] = message.content.match(prefixRegex) + const args = message.content.slice(matchedPrefix.length).trim().split(/ +/) - this.onMessage(message, prefix, args); - return true; + this.onMessage(message, prefix, args) + return true } isInteraction(interaction) { - if (interaction.type !== 2) return; - this.onInteraction(interaction); + if (interaction.type !== 2) return + this.onInteraction(interaction) } async onMessage(message, guild, args) { - const commandName = args.shift().toLowerCase(); - const command = this.cache.get(commandName); // || this.cache.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); + const commandName = args.shift().toLowerCase() + const command = this.cache.get(commandName) // || this.cache.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); if (!command && message.content.includes(this.client.id)) { // Handle, when Command has not been found - const options = { content: "I did not found the Command!" }; - this.client.helpers.sendMessage(message.channelId, options); + const options = { content: 'I did not found the Command!' } + this.client.helpers.sendMessage(message.channelId, options) } - if (!command) return; + if (!command) return const messagecommand = new command({ manager: this, @@ -94,30 +94,30 @@ class CommandManager { args, settings: {}, commandName: command.name, - }); + }) messagecommand.execute()?.catch?.((error) => { - console.log(error); + console.log(error) // Call Function on CommandResponse.js, handle the error - return messagecommand.onError(error ?? "custom"); - }); + return messagecommand.onError(error ?? 'custom') + }) } async onInteraction(interaction) { - const command = this.cache.get(interaction.data.name); - if (!command) return; + const command = this.cache.get(interaction.data.name) + if (!command) return - const args = []; + const args = [] // Map all Values and Args interaction.data.options?.map((o) => { - if (o.name) args.push(o.name); + if (o.name) args.push(o.name) if (o.options) { o.options.map((o2) => { - if (o2.value) return args.push(o2.value); - if (o2.name) args.push(o2.name); - if (o2.options) o2.options.map((v) => args.push(v.value)); - }); + if (o2.value) return args.push(o2.value) + if (o2.name) args.push(o2.name) + if (o2.options) o2.options.map((v) => args.push(v.value)) + }) } - }); + }) const messagecommand = new command({ manager: this, @@ -126,12 +126,12 @@ class CommandManager { args, settings: {}, commandName: command.name, - }); + }) messagecommand.execute()?.catch?.((error) => { - console.log(error); + console.log(error) // Call Function on CommandResponse.js, handle the error - return messagecommand.onError(error ?? "custom"); - }); + return messagecommand.onError(error ?? 'custom') + }) } } -module.exports = CommandManager; +module.exports = CommandManager diff --git a/examples/nodejs/Managers/EventManager.js b/examples/nodejs/Managers/EventManager.js index a90a41fc3..3512fd1b8 100644 --- a/examples/nodejs/Managers/EventManager.js +++ b/examples/nodejs/Managers/EventManager.js @@ -1,32 +1,32 @@ -const fs = require("fs"); -const path = require("path"); -const resolveFolder = (folderName) => path.resolve(__dirname, ".", folderName); +const fs = require('fs') +const path = require('path') +const resolveFolder = (folderName) => path.resolve(__dirname, '.', folderName) -const EventEmitter = require("events"); +const EventEmitter = require('events') class EventManager extends EventEmitter { constructor() { - super(); - this.cache = new Map(); - this.allEvents = {}; + super() + this.cache = new Map() + this.allEvents = {} } load(options = {}) { - const eventsFolder = resolveFolder("../events"); - let i = 0; + const eventsFolder = resolveFolder('../events') + let i = 0 fs.readdirSync(eventsFolder).map(async (file) => { - if (!file.endsWith(".js")) return; - i++; - const fileName = path.join(eventsFolder, file); - const event = require(fileName); - const eventName = file.split(".")[0]; + if (!file.endsWith('.js')) return + i++ + const fileName = path.join(eventsFolder, file) + const event = require(fileName) + const eventName = file.split('.')[0] this.allEvents[`${eventName}`] = (...args) => { - this.emit(eventName, ...args); - return event(...args); - }; - }); - return this.allEvents; + this.emit(eventName, ...args) + return event(...args) + } + }) + return this.allEvents } } -module.exports = EventManager; +module.exports = EventManager diff --git a/examples/nodejs/Plugins/Developer/commands/eval.js b/examples/nodejs/Plugins/Developer/commands/eval.js index cc9805120..a690a472e 100644 --- a/examples/nodejs/Plugins/Developer/commands/eval.js +++ b/examples/nodejs/Plugins/Developer/commands/eval.js @@ -1,51 +1,56 @@ -const Discord = require("discordeno.js"); +const Discord = require('discordeno.js') -const BaseCommand = require("../../../Structures/BaseCommand.js"); +const BaseCommand = require('../../../Structures/BaseCommand.js') class evalcommand extends BaseCommand { - static name = "eval"; - static description = "danger !!!"; - static category = "Developer"; - static slash = { name: "eval", category: "dev" }; + static name = 'eval' + static description = 'danger !!!' + static category = 'Developer' + static slash = { name: 'eval', category: 'dev' } constructor(data) { - super(data); + super(data) } async execute() { - if (!this.client.config.owners.includes(String(this.user.id))) return; - if (!(this.args.length > 0)) return this.reply({ content: "**You must provide something to eval!**" }); + if (!this.client.config.owners.includes(String(this.user.id))) return + if (!(this.args.length > 0)) return this.reply({ content: '**You must provide something to eval!**' }) - const inputOfEval = this.args.join(" "); - let outputOfEval; - let typeOfEval; + const inputOfEval = this.args.join(' ') + let outputOfEval + let typeOfEval try { - if (this.args.includes("await")) { - outputOfEval = await eval("(async () => {" + inputOfEval + "})()"); + if (this.args.includes('await')) { + outputOfEval = await eval('(async () => {' + inputOfEval + '})()') } else { - outputOfEval = await eval(inputOfEval); + outputOfEval = await eval(inputOfEval) } } catch (e) { - outputOfEval = e.message; - typeOfEval = e.name; + outputOfEval = e.message + typeOfEval = e.name } - const seen = []; - outputOfEval = typeof outputOfEval === "object" - ? JSON.stringify(outputOfEval, (_, value) => { - if (value == `Bot ${this.client.config.token}`) return `BOT_TOKEN`; - if (typeof value === "bigint") value = value.toString(); - if (typeof value === "object" && value !== null) { - if (seen.indexOf(value) !== -1) return; - else seen.push(value); - } - return value; - }, 1) - : outputOfEval; + const seen = [] + outputOfEval = + typeof outputOfEval === 'object' + ? JSON.stringify( + outputOfEval, + (_, value) => { + if (value == `Bot ${this.client.config.token}`) return `BOT_TOKEN` + if (typeof value === 'bigint') value = value.toString() + if (typeof value === 'object' && value !== null) { + if (seen.indexOf(value) !== -1) return + else seen.push(value) + } + return value + }, + 1, + ) + : outputOfEval const embed = new Discord.Embed() - .addField({ name: "Input", value: "```js\n" + inputOfEval + "```" }) - .addField({ name: "Output", value: "```json\n" + `${outputOfEval}`.slice(0, 1000) + "```" }); - this.reply({ embeds: [embed] }); + .addField({ name: 'Input', value: '```js\n' + inputOfEval + '```' }) + .addField({ name: 'Output', value: '```json\n' + `${outputOfEval}`.slice(0, 1000) + '```' }) + this.reply({ embeds: [embed] }) } } -module.exports = evalcommand; +module.exports = evalcommand diff --git a/examples/nodejs/Plugins/Developer/commands/reload.js b/examples/nodejs/Plugins/Developer/commands/reload.js index 023f79bec..59f283bf9 100644 --- a/examples/nodejs/Plugins/Developer/commands/reload.js +++ b/examples/nodejs/Plugins/Developer/commands/reload.js @@ -1,19 +1,19 @@ -const BaseCommand = require("../../../Structures/BaseCommand.js"); +const BaseCommand = require('../../../Structures/BaseCommand.js') class reloadcommand extends BaseCommand { - static name = "reload"; - static description = "Reloads a Command"; - static category = "Developer"; - static slash = { name: "reload", category: "dev" }; + static name = 'reload' + static description = 'Reloads a Command' + static category = 'Developer' + static slash = { name: 'reload', category: 'dev' } constructor(data) { - super(data); + super(data) } async execute() { - if (!this.client.config.owners.includes(String(this.user.id))) return; - if (!this.args[0]) return this.reply({ content: "**You must provide a command to reload!**" }); - const op = this.client.commands.reloadCommand(this.args[0]); - if (!op) return this.reply({ content: "**That command doesn't exist!**" }); - return this.reply({ content: "**Reloaded Command: `" + this.args[0] + "`**" }); + if (!this.client.config.owners.includes(String(this.user.id))) return + if (!this.args[0]) return this.reply({ content: '**You must provide a command to reload!**' }) + const op = this.client.commands.reloadCommand(this.args[0]) + if (!op) return this.reply({ content: "**That command doesn't exist!**" }) + return this.reply({ content: '**Reloaded Command: `' + this.args[0] + '`**' }) } } -module.exports = reloadcommand; +module.exports = reloadcommand diff --git a/examples/nodejs/Plugins/General/commands/ping.js b/examples/nodejs/Plugins/General/commands/ping.js index 5eff13448..f4b672536 100644 --- a/examples/nodejs/Plugins/General/commands/ping.js +++ b/examples/nodejs/Plugins/General/commands/ping.js @@ -1,25 +1,23 @@ -const BaseCommand = require("../../../Structures/BaseCommand.js"); -const Discord = require("discordeno.js"); +const BaseCommand = require('../../../Structures/BaseCommand.js') +const Discord = require('discordeno.js') class pingcommand extends BaseCommand { - static name = "ping"; - static description = "See if the bot latency is okay"; - static usage = ""; - static category = "General"; - static slash = { name: "ping", category: "info" }; + static name = 'ping' + static description = 'See if the bot latency is okay' + static usage = '' + static category = 'General' + static slash = { name: 'ping', category: 'info' } constructor(data) { - super(data); + super(data) } async execute() { - const msg = await this.channel.send({ content: `Pinging...` }); + const msg = await this.channel.send({ content: `Pinging...` }) // Assign properties to the response - const ping = msg.timestamp - (this.message ? this.message.timestamp : this.interaction.timestamp); + const ping = msg.timestamp - (this.message ? this.message.timestamp : this.interaction.timestamp) - const embed = new Discord.Embed() - .setTitle(`The Bots ping is ${ping} ms`) - .toJSON(); + const embed = new Discord.Embed().setTitle(`The Bots ping is ${ping} ms`).toJSON() // Edit Message with the Embed - return this.reply({ embeds: [embed] }); + return this.reply({ embeds: [embed] }) } } -module.exports = pingcommand; +module.exports = pingcommand diff --git a/examples/nodejs/Plugins/Moderation/commands/ban.js b/examples/nodejs/Plugins/Moderation/commands/ban.js index e03f67a2e..feede96c7 100644 --- a/examples/nodejs/Plugins/Moderation/commands/ban.js +++ b/examples/nodejs/Plugins/Moderation/commands/ban.js @@ -1,41 +1,47 @@ -const BaseCommand = require("../../../Structures/BaseCommand.js"); -const Discord = require("discordeno.js"); +const BaseCommand = require('../../../Structures/BaseCommand.js') +const Discord = require('discordeno.js') class bancommand extends BaseCommand { - static name = "ban"; - static description = "Ban a user from the server"; - static usage = ""; - static category = "Moderation"; - static slash = { name: "ban", category: "mod" }; + static name = 'ban' + static description = 'Ban a user from the server' + static usage = '' + static category = 'Moderation' + static slash = { name: 'ban', category: 'mod' } constructor(data) { - super(data); + super(data) } async execute() { // Show Case Modal // Because no permission system has not been added - if (!this.client.config.owners.includes(String(this.user.id))) return; + if (!this.client.config.owners.includes(String(this.user.id))) return const textinput = new Discord.Component() - .setType("TEXT_INPUT") - .setStyle("SHORT") - .setCustomId("t1") - .setLabel("User ID") - .setPlaceholder("User ID") + .setType('TEXT_INPUT') + .setStyle('SHORT') + .setCustomId('t1') + .setLabel('User ID') + .setPlaceholder('User ID') .setRequired(true) .setMaxLength(20) .setMinLength(1) .setValue(this.args[0]) - .toJSON(); - const textinput2 = new Discord.Component().setType("TEXT_INPUT").setStyle("PARAGRAPH").setCustomId("t2") - .setLabel("Reason").setPlaceholder("Reason for Ban").setRequired(false) - .setMaxLength(300).toJSON(); + .toJSON() + const textinput2 = new Discord.Component() + .setType('TEXT_INPUT') + .setStyle('PARAGRAPH') + .setCustomId('t2') + .setLabel('Reason') + .setPlaceholder('Reason for Ban') + .setRequired(false) + .setMaxLength(300) + .toJSON() - const actionrow = new Discord.Component().setType(1).setComponents(textinput).toJSON(); - const actionrow2 = new Discord.Component().setType(1).setComponents(textinput2).toJSON(); + const actionrow = new Discord.Component().setType(1).setComponents(textinput).toJSON() + const actionrow2 = new Discord.Component().setType(1).setComponents(textinput2).toJSON() - this.interaction.popupModal({ customId: "ban_modal", title: "Ban User", components: [actionrow, actionrow2] }); + this.interaction.popupModal({ customId: 'ban_modal', title: 'Ban User', components: [actionrow, actionrow2] }) } } -module.exports = bancommand; +module.exports = bancommand diff --git a/examples/nodejs/Plugins/Moderation/commands/warn.js b/examples/nodejs/Plugins/Moderation/commands/warn.js index 9d70fd54b..a0975ef00 100644 --- a/examples/nodejs/Plugins/Moderation/commands/warn.js +++ b/examples/nodejs/Plugins/Moderation/commands/warn.js @@ -1,82 +1,89 @@ -const BaseCommand = require("../../../Structures/BaseCommand.js"); +const BaseCommand = require('../../../Structures/BaseCommand.js') -const { Interaction, Collector, ComponentOptions, Embed, Component } = require("discordeno.js"); +const { Interaction, Collector, ComponentOptions, Embed, Component } = require('discordeno.js') class warncommand extends BaseCommand { - static name = "warn"; - static description = "Warn a user from the server"; - static usage = ""; - static category = "Moderation"; - static slash = { name: "warn", category: "mod" }; + static name = 'warn' + static description = 'Warn a user from the server' + static usage = '' + static category = 'Moderation' + static slash = { name: 'warn', category: 'mod' } constructor(data) { - super(data); + super(data) } async execute() { // Show Case Modal - if (!this.interaction) return this.reply("You currently can just use this command as slash command."); + if (!this.interaction) return this.reply('You currently can just use this command as slash command.') - if (!this.interaction.member.permissions.has("KICK_MEMBERS")) { - return this.reply("You need the permission `KICK_MEMBERS` to use this command."); + if (!this.interaction.member.permissions.has('KICK_MEMBERS')) { + return this.reply('You need the permission `KICK_MEMBERS` to use this command.') } const textinput = new Component() - .setType("TEXT_INPUT") - .setStyle("SHORT") - .setCustomId("t1") - .setLabel("User ID") - .setPlaceholder("User ID") + .setType('TEXT_INPUT') + .setStyle('SHORT') + .setCustomId('t1') + .setLabel('User ID') + .setPlaceholder('User ID') .setRequired(true) .setMaxLength(20) .setMinLength(1) .setValue(this.args[0]) - .toJSON(); - const textinput2 = new Component().setType("TEXT_INPUT").setStyle("PARAGRAPH").setCustomId("t2") - .setLabel("Reason").setPlaceholder("Reason for Warning").setRequired(false) - .setMaxLength(300).toJSON(); + .toJSON() + const textinput2 = new Component() + .setType('TEXT_INPUT') + .setStyle('PARAGRAPH') + .setCustomId('t2') + .setLabel('Reason') + .setPlaceholder('Reason for Warning') + .setRequired(false) + .setMaxLength(300) + .toJSON() - const actionrow = new Component().setType(1).setComponents(textinput).toJSON(); - const actionrow2 = new Component().setType(1).setComponents(textinput2).toJSON(); + const actionrow = new Component().setType(1).setComponents(textinput).toJSON() + const actionrow2 = new Component().setType(1).setComponents(textinput2).toJSON() - this.interaction.popupModal({ customId: "warn_modal", title: "Warn User", components: [actionrow, actionrow2] }); + this.interaction.popupModal({ customId: 'warn_modal', title: 'Warn User', components: [actionrow, actionrow2] }) - const filter = (m) => m.data?.customId === "warn_modal"; - const collector = new Collector("interactionCreate", { client: this.client, timeout: 60000, filter }); - collector.on("collect", (m) => { - const options = new ComponentOptions(m.data.components); - const i = new Interaction(this.client, m); - collector.stop(); + const filter = (m) => m.data?.customId === 'warn_modal' + const collector = new Collector('interactionCreate', { client: this.client, timeout: 60000, filter }) + collector.on('collect', (m) => { + const options = new ComponentOptions(m.data.components) + const i = new Interaction(this.client, m) + collector.stop() - const memberId = options.get("t1").value; - const reason = options.get("t2").value; + const memberId = options.get('t1').value + const reason = options.get('t2').value - const embed = new Embed() - .setTitle("Warned User:") - .setDescription(`User ID: <@${memberId}> \n Reason: ${reason}`) - .setColor(0x00ff00) - .toJSON(); + const embed = new Embed().setTitle('Warned User:').setDescription(`User ID: <@${memberId}> \n Reason: ${reason}`).setColor(0x00ff00).toJSON() const warnMessage = new Embed() - .setTitle("Warning:") - .setDescription(`You have been warned in **${this.guild.name}** for ${"`" + reason + "`"}`) - .toJSON(); + .setTitle('Warning:') + .setDescription(`You have been warned in **${this.guild.name}** for ${'`' + reason + '`'}`) + .toJSON() - this.guild.members.fetch(memberId).then((m) => { - m.send({ embeds: [warnMessage] }).then(() => { - i.reply({ embeds: [embed] }); - }).catch((e) => { - console.log(e); - i.reply({ content: `Could not warn user ${"<@" + m.id + ">"} | They likely do not have their DMs open.` }); - }); - }).catch((e) => { - const embed = new Embed() - .setTitle("Member not found") - .setDescription(`The member with the ID of ${"`" + memberId + "`"} has not been found in this Server.`) - .setColor(0xff0000) - .toJSON(); - i.reply({ embeds: [embed] }); - }); - }); + this.guild.members + .fetch(memberId) + .then((m) => { + m.send({ embeds: [warnMessage] }) + .then(() => { + i.reply({ embeds: [embed] }) + }) + .catch((e) => { + console.log(e) + i.reply({ content: `Could not warn user ${'<@' + m.id + '>'} | They likely do not have their DMs open.` }) + }) + }) + .catch((e) => { + const embed = new Embed() + .setTitle('Member not found') + .setDescription(`The member with the ID of ${'`' + memberId + '`'} has not been found in this Server.`) + .setColor(0xff0000) + .toJSON() + i.reply({ embeds: [embed] }) + }) + }) } } -module.exports = warncommand; +module.exports = warncommand diff --git a/examples/nodejs/Structures/BaseCommand.js b/examples/nodejs/Structures/BaseCommand.js index da1ff523f..59ca18f58 100644 --- a/examples/nodejs/Structures/BaseCommand.js +++ b/examples/nodejs/Structures/BaseCommand.js @@ -1,15 +1,15 @@ -const UtilCommand = require("./CommandResponse.js"); +const UtilCommand = require('./CommandResponse.js') class BaseCommand extends UtilCommand { constructor(data) { - super(data); - this.message = data.message; - this.interaction = data.interaction; - this.user = this.message ? this.message.author : this.interaction.user; - this.guild = this.message ? this.message.guild : this.interaction.guild; - this.member = this.message ? this.message.member : this.interaction.member; - this.channel = this.message ? this.message.channel : this.interaction.channel; - this.client = data.client; - this.settings = data.settings ?? {}; + super(data) + this.message = data.message + this.interaction = data.interaction + this.user = this.message ? this.message.author : this.interaction.user + this.guild = this.message ? this.message.guild : this.interaction.guild + this.member = this.message ? this.message.member : this.interaction.member + this.channel = this.message ? this.message.channel : this.interaction.channel + this.client = data.client + this.settings = data.settings ?? {} } } -module.exports = BaseCommand; +module.exports = BaseCommand diff --git a/examples/nodejs/Structures/CommandResponse.js b/examples/nodejs/Structures/CommandResponse.js index 434ae38b2..12ef58dce 100644 --- a/examples/nodejs/Structures/CommandResponse.js +++ b/examples/nodejs/Structures/CommandResponse.js @@ -1,50 +1,50 @@ class Responses { constructor(data) { - this.manager = data.manager; - this.args = this._validateArguments(data.args); - this.replied = false; + this.manager = data.manager + this.args = this._validateArguments(data.args) + this.replied = false } async reply(content) { // When just a string is passed, we assume it's the content -> transform to correct formatted payload - if (typeof content === "string") content = { content }; + if (typeof content === 'string') content = { content } if (this.interaction) { - if (this.replied) return this.followUp(content); - const reply = await this.interaction.reply(content); - this.replied = true; - return {}; + if (this.replied) return this.followUp(content) + const reply = await this.interaction.reply(content) + this.replied = true + return {} } if (this.message) { - if (this.replied) return this.followUp(content); + if (this.replied) return this.followUp(content) - const msg = await this.message.channel.send(content); + const msg = await this.message.channel.send(content) // Assign properties to the response - const response = this.client.messages.forge(msg); - this.replied = true; - return response; + const response = this.client.messages.forge(msg) + this.replied = true + return response } } async followUp(content) { if (this.interaction) { - const reply = await this.interaction.followUp(content); - return {}; + const reply = await this.interaction.followUp(content) + return {} } if (this.message) { - const msg = await this.message.channel.send(content); - const response = this.client.messages.forge(msg); - return response; + const msg = await this.message.channel.send(content) + const response = this.client.messages.forge(msg) + return response } } onError(error) { - return this.reply({ content: `A unknown Error happend: \n> ${error}` }); + return this.reply({ content: `A unknown Error happend: \n> ${error}` }) } _validateArguments(args) { - this.args = args; - return args; + this.args = args + return args } } -module.exports = Responses; +module.exports = Responses diff --git a/examples/nodejs/events/interactionCreate.js b/examples/nodejs/events/interactionCreate.js index 3f5b27042..714d4a826 100644 --- a/examples/nodejs/events/interactionCreate.js +++ b/examples/nodejs/events/interactionCreate.js @@ -1,4 +1,4 @@ module.exports = async (client, interaction) => { - interaction = client.interactions.forge(interaction); - client.commands.isInteraction(interaction); -}; + interaction = client.interactions.forge(interaction) + client.commands.isInteraction(interaction) +} diff --git a/examples/nodejs/events/messageCreate.js b/examples/nodejs/events/messageCreate.js index b3c96f77e..cf34be528 100644 --- a/examples/nodejs/events/messageCreate.js +++ b/examples/nodejs/events/messageCreate.js @@ -1,4 +1,4 @@ module.exports = async (client, message) => { - message = client.messages.forge(message); - client.commands.isCommand(message); -}; + message = client.messages.forge(message) + client.commands.isCommand(message) +} diff --git a/examples/nodejs/events/ready.js b/examples/nodejs/events/ready.js index aa1b99934..9b6fb1e23 100644 --- a/examples/nodejs/events/ready.js +++ b/examples/nodejs/events/ready.js @@ -1,7 +1,7 @@ module.exports = async (client, payload) => { - client.user = client.users.forge(payload.user); + client.user = client.users.forge(payload.user) if (payload.shardId === client.gateway.lastShardId) { // All Shards are ready - console.log("Successfully connected to the gateway as " + client.user.tag); + console.log('Successfully connected to the gateway as ' + client.user.tag) } -}; +} diff --git a/examples/nodejs/index.js b/examples/nodejs/index.js index 731f7f543..d01f027c5 100644 --- a/examples/nodejs/index.js +++ b/examples/nodejs/index.js @@ -1,32 +1,32 @@ -require("dotenv").config(); +require('dotenv').config() -const Discord = require("discordeno.js"); +const Discord = require('discordeno.js') // Ideally you should switch this to .env but for a template a config json is enough -const config = require("./config.json"); +const config = require('./config.json') -const EventManager = require("./Managers/EventManager.js"); +const EventManager = require('./Managers/EventManager.js') // looping through all events and registering them -const events = new EventManager({}); +const events = new EventManager({}) const baseBot = Discord.createBot({ events: events.load({}), intents: Discord.Intents.Guilds | Discord.Intents.GuildMessages | Discord.Intents.MessageContent, token: process.env.TOKEN, -}); -const client = Discord.enableCachePlugin(baseBot, {}); +}) +const client = Discord.enableCachePlugin(baseBot, {}) -client.config = config; +client.config = config // looping through all commands and registering them in .cache of the class -const CommandManager = require("./Managers/CommandManager.js"); -client.commands = new CommandManager(client); -client.commands.load({}); +const CommandManager = require('./Managers/CommandManager.js') +client.commands = new CommandManager(client) +client.commands.load({}) // Starts your Bot -Discord.startBot(client); +Discord.startBot(client) /* -* You should handle all errors and fix the issues in your codes... -* process.on('unhandledRejection', (reason, p) => {console.log(reason, p)}) -*/ + * You should handle all errors and fix the issues in your codes... + * process.on('unhandledRejection', (reason, p) => {console.log(reason, p)}) + */ diff --git a/jsdoc2md.json b/jsdoc2md.json index c2c5d100b..5b74e8bcf 100644 --- a/jsdoc2md.json +++ b/jsdoc2md.json @@ -3,10 +3,7 @@ "babelrc": false, "extensions": ["ts", "tsx"], "ignore": ["**/*.(test|spec).ts"], - "plugins": [ - "@babel/proposal-class-properties", - "@babel/proposal-object-rest-spread" - ], + "plugins": ["@babel/proposal-class-properties", "@babel/proposal-object-rest-spread"], "presets": [ [ "@babel/preset-env", diff --git a/packages/benchmark/tsconfig.json b/packages/benchmark/tsconfig.json index 50e6ef6eb..6cc7ea9b5 100644 --- a/packages/benchmark/tsconfig.json +++ b/packages/benchmark/tsconfig.json @@ -1,16 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "node_modules", - "dist", - "test", - "tests" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts", "./src/**/*.tsx"], + "exclude": ["node_modules", "dist", "test", "tests"] +} diff --git a/packages/bot/src/handlers/channels/index.ts b/packages/bot/src/handlers/channels/index.ts index c55e6612d..088fb7c50 100644 --- a/packages/bot/src/handlers/channels/index.ts +++ b/packages/bot/src/handlers/channels/index.ts @@ -1,12 +1,12 @@ -export * from "./CHANNEL_CREATE.js"; -export * from "./CHANNEL_DELETE.js"; -export * from "./CHANNEL_PINS_UPDATE.js"; -export * from "./CHANNEL_UPDATE.js"; -export * from "./STAGE_INSTANCE_CREATE.js"; -export * from "./STAGE_INSTANCE_DELETE.js"; -export * from "./STAGE_INSTANCE_UPDATE.js"; -export * from "./THREAD_CREATE.js"; -export * from "./THREAD_DELETE.js"; -export * from "./THREAD_LIST_SYNC.js"; -export * from "./THREAD_MEMBERS_UPDATE.js"; -export * from "./THREAD_UPDATE.js"; +export * from './CHANNEL_CREATE.js' +export * from './CHANNEL_DELETE.js' +export * from './CHANNEL_PINS_UPDATE.js' +export * from './CHANNEL_UPDATE.js' +export * from './STAGE_INSTANCE_CREATE.js' +export * from './STAGE_INSTANCE_DELETE.js' +export * from './STAGE_INSTANCE_UPDATE.js' +export * from './THREAD_CREATE.js' +export * from './THREAD_DELETE.js' +export * from './THREAD_LIST_SYNC.js' +export * from './THREAD_MEMBERS_UPDATE.js' +export * from './THREAD_UPDATE.js' diff --git a/packages/bot/src/handlers/emojis/index.ts b/packages/bot/src/handlers/emojis/index.ts index 5a442ee5d..f98466c7d 100644 --- a/packages/bot/src/handlers/emojis/index.ts +++ b/packages/bot/src/handlers/emojis/index.ts @@ -1 +1 @@ -export * from "./GUILD_EMOJIS_UPDATE.js"; +export * from './GUILD_EMOJIS_UPDATE.js' diff --git a/packages/bot/src/handlers/guilds/GUILD_STICKERS_UPDATE.ts b/packages/bot/src/handlers/guilds/GUILD_STICKERS_UPDATE.ts index 6cbd16b3c..0f668a3bb 100644 --- a/packages/bot/src/handlers/guilds/GUILD_STICKERS_UPDATE.ts +++ b/packages/bot/src/handlers/guilds/GUILD_STICKERS_UPDATE.ts @@ -5,8 +5,8 @@ export async function handleGuildStickersUpdate(bot: Bot, data: DiscordGatewayPa bot.events.guildStickersUpdate?.( payload.stickers.map((sticker) => { - sticker.guild_id = payload.guild_id - return bot.transformers.sticker(bot, sticker) - }) + sticker.guild_id = payload.guild_id + return bot.transformers.sticker(bot, sticker) + }), ) } diff --git a/packages/bot/src/handlers/guilds/index.ts b/packages/bot/src/handlers/guilds/index.ts index ad793cefd..38cde1f3d 100644 --- a/packages/bot/src/handlers/guilds/index.ts +++ b/packages/bot/src/handlers/guilds/index.ts @@ -1,11 +1,11 @@ -export * from "./automod/index.js"; -export * from "./scheduledEvents/index.js"; +export * from './automod/index.js' +export * from './scheduledEvents/index.js' -export * from "./GUILD_AUDIT_LOG_ENTRY_CREATE.js"; -export * from "./GUILD_BAN_ADD.js"; -export * from "./GUILD_BAN_REMOVE.js"; -export * from "./GUILD_CREATE.js"; -export * from "./GUILD_DELETE.js"; -export * from "./GUILD_INTEGRATIONS_UPDATE.js"; -export * from "./GUILD_STICKERS_UPDATE.js"; -export * from "./GUILD_UPDATE.js"; +export * from './GUILD_AUDIT_LOG_ENTRY_CREATE.js' +export * from './GUILD_BAN_ADD.js' +export * from './GUILD_BAN_REMOVE.js' +export * from './GUILD_CREATE.js' +export * from './GUILD_DELETE.js' +export * from './GUILD_INTEGRATIONS_UPDATE.js' +export * from './GUILD_STICKERS_UPDATE.js' +export * from './GUILD_UPDATE.js' diff --git a/packages/bot/src/handlers/guilds/scheduledEvents/index.ts b/packages/bot/src/handlers/guilds/scheduledEvents/index.ts index ce7cf1545..7c4d5397a 100644 --- a/packages/bot/src/handlers/guilds/scheduledEvents/index.ts +++ b/packages/bot/src/handlers/guilds/scheduledEvents/index.ts @@ -1,5 +1,5 @@ -export * from "./GUILD_SCHEDULED_EVENT_CREATE.js"; -export * from "./GUILD_SCHEDULED_EVENT_DELETE.js"; -export * from "./GUILD_SCHEDULED_EVENT_UPDATE.js"; -export * from "./GUILD_SCHEDULED_EVENT_USER_ADD.js"; -export * from "./GUILD_SCHEDULED_EVENT_USER_REMOVE.js"; +export * from './GUILD_SCHEDULED_EVENT_CREATE.js' +export * from './GUILD_SCHEDULED_EVENT_DELETE.js' +export * from './GUILD_SCHEDULED_EVENT_UPDATE.js' +export * from './GUILD_SCHEDULED_EVENT_USER_ADD.js' +export * from './GUILD_SCHEDULED_EVENT_USER_REMOVE.js' diff --git a/packages/bot/src/handlers/integrations/index.ts b/packages/bot/src/handlers/integrations/index.ts index afff9f98e..9cffc13bd 100644 --- a/packages/bot/src/handlers/integrations/index.ts +++ b/packages/bot/src/handlers/integrations/index.ts @@ -1,3 +1,3 @@ -export * from "./INTEGRATION_CREATE.js"; -export * from "./INTEGRATION_DELETE.js"; -export * from "./INTEGRATION_UPDATE.js"; +export * from './INTEGRATION_CREATE.js' +export * from './INTEGRATION_DELETE.js' +export * from './INTEGRATION_UPDATE.js' diff --git a/packages/bot/src/handlers/interactions/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts b/packages/bot/src/handlers/interactions/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts index 31bb21f60..2747c4293 100644 --- a/packages/bot/src/handlers/interactions/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts +++ b/packages/bot/src/handlers/interactions/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts @@ -1,6 +1,6 @@ -import type { Bot, DiscordGatewayPayload, DiscordGuildApplicationCommandPermissions } from "../.."; +import type { Bot, DiscordGatewayPayload, DiscordGuildApplicationCommandPermissions } from '../..' export async function handleApplicationCommandPermissionsUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { - const payload = data.d as DiscordGuildApplicationCommandPermissions - bot.events.applicationCommandPermissionsUpdate?.(bot.transformers.applicationCommandPermission(bot, payload)) -} \ No newline at end of file + const payload = data.d as DiscordGuildApplicationCommandPermissions + bot.events.applicationCommandPermissionsUpdate?.(bot.transformers.applicationCommandPermission(bot, payload)) +} diff --git a/packages/bot/src/handlers/invites/index.ts b/packages/bot/src/handlers/invites/index.ts index 118a3b364..34e4fb5df 100644 --- a/packages/bot/src/handlers/invites/index.ts +++ b/packages/bot/src/handlers/invites/index.ts @@ -1,2 +1,2 @@ -export * from "./INVITE_CREATE.js"; -export * from "./INVITE_DELETE.js"; +export * from './INVITE_CREATE.js' +export * from './INVITE_DELETE.js' diff --git a/packages/bot/src/handlers/members/index.ts b/packages/bot/src/handlers/members/index.ts index 0348756a5..a0921f465 100644 --- a/packages/bot/src/handlers/members/index.ts +++ b/packages/bot/src/handlers/members/index.ts @@ -1,4 +1,4 @@ -export * from "./GUILD_MEMBER_ADD.js"; -export * from "./GUILD_MEMBER_REMOVE.js"; -export * from "./GUILD_MEMBER_UPDATE.js"; -export * from "./GUILD_MEMBERS_CHUNK.js"; +export * from './GUILD_MEMBER_ADD.js' +export * from './GUILD_MEMBER_REMOVE.js' +export * from './GUILD_MEMBER_UPDATE.js' +export * from './GUILD_MEMBERS_CHUNK.js' diff --git a/packages/bot/src/handlers/messages/index.ts b/packages/bot/src/handlers/messages/index.ts index ad6fef398..c165fd3d3 100644 --- a/packages/bot/src/handlers/messages/index.ts +++ b/packages/bot/src/handlers/messages/index.ts @@ -1,8 +1,8 @@ -export * from "./MESSAGE_CREATE.js"; -export * from "./MESSAGE_DELETE_BULK.js"; -export * from "./MESSAGE_DELETE.js"; -export * from "./MESSAGE_REACTION_ADD.js"; -export * from "./MESSAGE_REACTION_REMOVE_ALL.js"; -export * from "./MESSAGE_REACTION_REMOVE_EMOJI.js"; -export * from "./MESSAGE_REACTION_REMOVE.js"; -export * from "./MESSAGE_UPDATE.js"; +export * from './MESSAGE_CREATE.js' +export * from './MESSAGE_DELETE_BULK.js' +export * from './MESSAGE_DELETE.js' +export * from './MESSAGE_REACTION_ADD.js' +export * from './MESSAGE_REACTION_REMOVE_ALL.js' +export * from './MESSAGE_REACTION_REMOVE_EMOJI.js' +export * from './MESSAGE_REACTION_REMOVE.js' +export * from './MESSAGE_UPDATE.js' diff --git a/packages/bot/src/handlers/misc/index.ts b/packages/bot/src/handlers/misc/index.ts index 0b8c5a74c..7a1c12c68 100644 --- a/packages/bot/src/handlers/misc/index.ts +++ b/packages/bot/src/handlers/misc/index.ts @@ -1,4 +1,4 @@ -export * from "./PRESENCE_UPDATE.js"; -export * from "./READY.js"; -export * from "./TYPING_START.js"; -export * from "./USER_UPDATE.js"; +export * from './PRESENCE_UPDATE.js' +export * from './READY.js' +export * from './TYPING_START.js' +export * from './USER_UPDATE.js' diff --git a/packages/bot/src/handlers/roles/index.ts b/packages/bot/src/handlers/roles/index.ts index 6ba9e7a0b..9e369134f 100644 --- a/packages/bot/src/handlers/roles/index.ts +++ b/packages/bot/src/handlers/roles/index.ts @@ -1,3 +1,3 @@ -export * from "./GUILD_ROLE_CREATE.js"; -export * from "./GUILD_ROLE_DELETE.js"; -export * from "./GUILD_ROLE_UPDATE.js"; +export * from './GUILD_ROLE_CREATE.js' +export * from './GUILD_ROLE_DELETE.js' +export * from './GUILD_ROLE_UPDATE.js' diff --git a/packages/bot/src/handlers/voice/index.ts b/packages/bot/src/handlers/voice/index.ts index 6df599417..6302f4659 100644 --- a/packages/bot/src/handlers/voice/index.ts +++ b/packages/bot/src/handlers/voice/index.ts @@ -1,2 +1,2 @@ -export * from "./VOICE_SERVER_UPDATE.js"; -export * from "./VOICE_STATE_UPDATE.js"; +export * from './VOICE_SERVER_UPDATE.js' +export * from './VOICE_STATE_UPDATE.js' diff --git a/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts b/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts index c2e92a70b..61dc93275 100644 --- a/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts +++ b/packages/bot/src/handlers/webhooks/WEBHOOKS_UPDATE.ts @@ -1,7 +1,7 @@ import type { DiscordGatewayPayload, DiscordWebhookUpdate } from '@discordeno/types' import type { Bot } from '../../index.js' -export async function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) : Promise { +export async function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number): Promise { const payload = data.d as DiscordWebhookUpdate bot.events.webhooksUpdate?.({ channelId: bot.transformers.snowflake(payload.channel_id), diff --git a/packages/bot/src/handlers/webhooks/index.ts b/packages/bot/src/handlers/webhooks/index.ts index 4967148bb..baf5f8d4d 100644 --- a/packages/bot/src/handlers/webhooks/index.ts +++ b/packages/bot/src/handlers/webhooks/index.ts @@ -1 +1 @@ -export * from "./WEBHOOKS_UPDATE.js"; +export * from './WEBHOOKS_UPDATE.js' diff --git a/packages/bot/src/transformers/reverse/index.ts b/packages/bot/src/transformers/reverse/index.ts index 733f18215..1d2707510 100644 --- a/packages/bot/src/transformers/reverse/index.ts +++ b/packages/bot/src/transformers/reverse/index.ts @@ -1,16 +1,16 @@ -export * from "./activity.js"; -export * from "./application.js"; -export * from "./applicationCommand.js"; -export * from "./applicationCommandOption.js"; -export * from "./applicationCommandOptionChoice.js"; -export * from "./applicationCommandPermission.js"; -export * from "./attachment.js"; -export * from "./auditLogEntry.js"; -export * from "./component.js"; -export * from "./embed.js"; -export * from "./emoji.js"; -export * from "./gatewayBot.js"; -export * from "./member.js"; -export * from "./presence.js"; -export * from "./team.js"; -export * from "./widgetSettings.js"; +export * from './activity.js' +export * from './application.js' +export * from './applicationCommand.js' +export * from './applicationCommandOption.js' +export * from './applicationCommandOptionChoice.js' +export * from './applicationCommandPermission.js' +export * from './attachment.js' +export * from './auditLogEntry.js' +export * from './component.js' +export * from './embed.js' +export * from './emoji.js' +export * from './gatewayBot.js' +export * from './member.js' +export * from './presence.js' +export * from './team.js' +export * from './widgetSettings.js' diff --git a/packages/bot/src/transformers/toggles/ToggleBitfield.ts b/packages/bot/src/transformers/toggles/ToggleBitfield.ts index 985cefdb1..4ccd6d462 100644 --- a/packages/bot/src/transformers/toggles/ToggleBitfield.ts +++ b/packages/bot/src/transformers/toggles/ToggleBitfield.ts @@ -1,49 +1,49 @@ export class ToggleBitfield { - bitfield = 0; + bitfield = 0 constructor(bitfield?: number) { - if (bitfield) this.bitfield = bitfield; + if (bitfield) this.bitfield = bitfield } /** Tests whether or not this bitfield has the permission requested. */ contains(bits: number): boolean { - return Boolean(this.bitfield & bits); + return Boolean(this.bitfield & bits) } /** Adds some bits to the bitfield. */ add(bits: number): this { - this.bitfield |= bits; - return this; + this.bitfield |= bits + return this } /** Removes some bits from the bitfield. */ remove(bits: number): this { - this.bitfield &= ~bits; - return this; + this.bitfield &= ~bits + return this } } export class ToggleBitfieldBigint { - bitfield = 0n; + bitfield = 0n constructor(bitfield?: bigint) { - if (bitfield) this.bitfield = bitfield; + if (bitfield) this.bitfield = bitfield } /** Tests whether or not this bitfield has the permission requested. */ contains(bits: bigint): boolean { - return Boolean(this.bitfield & bits); + return Boolean(this.bitfield & bits) } /** Adds some bits to the bitfield. */ add(bits: bigint): this { - this.bitfield |= bits; - return this; + this.bitfield |= bits + return this } /** Removes some bits from the bitfield. */ remove(bits: bigint): this { - this.bitfield &= ~bits; - return this; + this.bitfield &= ~bits + return this } } diff --git a/packages/bot/src/transformers/toggles/index.ts b/packages/bot/src/transformers/toggles/index.ts index 48c016dab..a5783110c 100644 --- a/packages/bot/src/transformers/toggles/index.ts +++ b/packages/bot/src/transformers/toggles/index.ts @@ -1,7 +1,7 @@ -export * from "./emoji.js"; -export * from "./guild.js"; -export * from "./member.js"; -export * from "./role.js"; -export * from "./ToggleBitfield.js"; -export * from "./user.js"; -export * from "./voice.js"; +export * from './emoji.js' +export * from './guild.js' +export * from './member.js' +export * from './role.js' +export * from './ToggleBitfield.js' +export * from './user.js' +export * from './voice.js' diff --git a/packages/bot/tsconfig.json b/packages/bot/tsconfig.json index 50e6ef6eb..6cc7ea9b5 100644 --- a/packages/bot/tsconfig.json +++ b/packages/bot/tsconfig.json @@ -1,16 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "node_modules", - "dist", - "test", - "tests" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts", "./src/**/*.tsx"], + "exclude": ["node_modules", "dist", "test", "tests"] +} diff --git a/packages/bot/tsconfig.test.json b/packages/bot/tsconfig.test.json index eeb80c521..c4916d55a 100644 --- a/packages/bot/tsconfig.test.json +++ b/packages/bot/tsconfig.test.json @@ -1,11 +1,5 @@ { "extends": "tsconfig/test.json", - "include": [ - "tests", - ], - "exclude": [ - "node_modules", - "dist", - "src" - ] -} \ No newline at end of file + "include": ["tests"], + "exclude": ["node_modules", "dist", "src"] +} diff --git a/packages/discordeno/tsconfig.json b/packages/discordeno/tsconfig.json index 50e6ef6eb..6cc7ea9b5 100644 --- a/packages/discordeno/tsconfig.json +++ b/packages/discordeno/tsconfig.json @@ -1,16 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "node_modules", - "dist", - "test", - "tests" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts", "./src/**/*.tsx"], + "exclude": ["node_modules", "dist", "test", "tests"] +} diff --git a/packages/discordeno/tsconfig.test.json b/packages/discordeno/tsconfig.test.json index eeb80c521..c4916d55a 100644 --- a/packages/discordeno/tsconfig.test.json +++ b/packages/discordeno/tsconfig.test.json @@ -1,11 +1,5 @@ { "extends": "tsconfig/test.json", - "include": [ - "tests", - ], - "exclude": [ - "node_modules", - "dist", - "src" - ] -} \ No newline at end of file + "include": ["tests"], + "exclude": ["node_modules", "dist", "src"] +} diff --git a/packages/gateway/src/Shard.ts b/packages/gateway/src/Shard.ts index 0b078e222..746019296 100644 --- a/packages/gateway/src/Shard.ts +++ b/packages/gateway/src/Shard.ts @@ -467,7 +467,7 @@ export class DiscordenoShard { this.previousSequenceNumber = packet.s } - this.forwardToBot(packet); + this.forwardToBot(packet) } forwardToBot(packet: DiscordGatewayPayload): void { diff --git a/packages/gateway/tsconfig.json b/packages/gateway/tsconfig.json index 50e6ef6eb..6cc7ea9b5 100644 --- a/packages/gateway/tsconfig.json +++ b/packages/gateway/tsconfig.json @@ -1,16 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "node_modules", - "dist", - "test", - "tests" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts", "./src/**/*.tsx"], + "exclude": ["node_modules", "dist", "test", "tests"] +} diff --git a/packages/gateway/tsconfig.test.json b/packages/gateway/tsconfig.test.json index eeb80c521..c4916d55a 100644 --- a/packages/gateway/tsconfig.test.json +++ b/packages/gateway/tsconfig.test.json @@ -1,11 +1,5 @@ { "extends": "tsconfig/test.json", - "include": [ - "tests", - ], - "exclude": [ - "node_modules", - "dist", - "src" - ] -} \ No newline at end of file + "include": ["tests"], + "exclude": ["node_modules", "dist", "src"] +} diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 30dde9404..65628f0b4 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -984,7 +984,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage }) if (!result.ok) { - const err = (await result.json().catch(() => { })) as Record + const err = (await result.json().catch(() => {})) as Record // Legacy Handling to not break old code or when body is missing if (!err?.body) throw new Error(`Error: ${err.message ?? result.statusText}`) throw new Error(JSON.stringify(err)) @@ -999,7 +999,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage method, requestBodyOptions: options, retryCount: 0, - retryRequest: async function(payload: SendRequestOptions) { + retryRequest: async function (payload: SendRequestOptions) { rest.processRequest(payload) }, resolve: (data) => { @@ -1690,10 +1690,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await new Promise((resolve, reject) => { rest.sendRequest({ url: rest.routes.webhooks.webhook(rest.applicationId, token), - method: 'POST', + method: 'POST', requestBodyOptions: { body: options, files: options.files }, retryCount: 0, - retryRequest: async function(options: SendRequestOptions) { + retryRequest: async function (options: SendRequestOptions) { // TODO: should change to reprocess queue item await rest.sendRequest(options) }, @@ -1713,7 +1713,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage method: 'POST', requestBodyOptions: { body: options }, retryCount: 0, - retryRequest: async function(options: SendRequestOptions) { + retryRequest: async function (options: SendRequestOptions) { // TODO: should change to reprocess queue item await rest.sendRequest(options) }, diff --git a/packages/rest/tests/e2e/guild.spec.ts b/packages/rest/tests/e2e/guild.spec.ts index 7689557d8..315504f67 100644 --- a/packages/rest/tests/e2e/guild.spec.ts +++ b/packages/rest/tests/e2e/guild.spec.ts @@ -119,6 +119,5 @@ describe('Manage Guilds', async () => { // description: 'some description', // }) - // }) }) diff --git a/packages/rest/tests/e2e/utils.ts b/packages/rest/tests/e2e/utils.ts index c693a7e91..af78e5e47 100644 --- a/packages/rest/tests/e2e/utils.ts +++ b/packages/rest/tests/e2e/utils.ts @@ -11,8 +11,8 @@ export const rest = createRestManager({ }) rest.deleteQueueDelay = 10000 -const guild = await rest.createGuild({ name: 'ddenotester' }); -const channel = await rest.createChannel(guild.id, { name: "ddenotestchannel" }); +const guild = await rest.createGuild({ name: 'ddenotester' }) +const channel = await rest.createChannel(guild.id, { name: 'ddenotestchannel' }) export const e2ecache = { guild, diff --git a/packages/rest/tests/e2e/webhook.spec.ts b/packages/rest/tests/e2e/webhook.spec.ts index 4305261d8..2a3c3c25c 100644 --- a/packages/rest/tests/e2e/webhook.spec.ts +++ b/packages/rest/tests/e2e/webhook.spec.ts @@ -107,5 +107,3 @@ describe('Webhook helpers', async () => { await expect(rest.getWebhookMessage(webhook.id, webhook.token!, message!.id)).to.eventually.rejected }) }) - - diff --git a/packages/rest/tsconfig.json b/packages/rest/tsconfig.json index 50e6ef6eb..6cc7ea9b5 100644 --- a/packages/rest/tsconfig.json +++ b/packages/rest/tsconfig.json @@ -1,16 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "node_modules", - "dist", - "test", - "tests" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts", "./src/**/*.tsx"], + "exclude": ["node_modules", "dist", "test", "tests"] +} diff --git a/packages/rest/tsconfig.test.json b/packages/rest/tsconfig.test.json index eeb80c521..c4916d55a 100644 --- a/packages/rest/tsconfig.test.json +++ b/packages/rest/tsconfig.test.json @@ -1,11 +1,5 @@ { "extends": "tsconfig/test.json", - "include": [ - "tests", - ], - "exclude": [ - "node_modules", - "dist", - "src" - ] -} \ No newline at end of file + "include": ["tests"], + "exclude": ["node_modules", "dist", "src"] +} diff --git a/packages/tsconfig/test.json b/packages/tsconfig/test.json index 39e6b1d33..8a8c4804c 100644 --- a/packages/tsconfig/test.json +++ b/packages/tsconfig/test.json @@ -4,4 +4,4 @@ "noEmit": true, "incremental": false } -} \ No newline at end of file +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 7b8ddd37f..e610aa6c9 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,4 +1,4 @@ export * from './camel.js' export * from './discord.js' export * from './discordeno.js' -export * from './shared.js' \ No newline at end of file +export * from './shared.js' diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json index 50e6ef6eb..6cc7ea9b5 100644 --- a/packages/types/tsconfig.json +++ b/packages/types/tsconfig.json @@ -1,16 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "node_modules", - "dist", - "test", - "tests" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts", "./src/**/*.tsx"], + "exclude": ["node_modules", "dist", "test", "tests"] +} diff --git a/packages/types/tsconfig.test.json b/packages/types/tsconfig.test.json index eeb80c521..c4916d55a 100644 --- a/packages/types/tsconfig.test.json +++ b/packages/types/tsconfig.test.json @@ -1,11 +1,5 @@ { "extends": "tsconfig/test.json", - "include": [ - "tests", - ], - "exclude": [ - "node_modules", - "dist", - "src" - ] -} \ No newline at end of file + "include": ["tests"], + "exclude": ["node_modules", "dist", "src"] +} diff --git a/packages/utils/src/casing.ts b/packages/utils/src/casing.ts index 46b6bfddd..916aed1e2 100644 --- a/packages/utils/src/casing.ts +++ b/packages/utils/src/casing.ts @@ -1,6 +1,6 @@ import type { Camelize, Snakelize } from '@discordeno/types' -export function camelize (object: T): Camelize { +export function camelize(object: T): Camelize { if (Array.isArray(object)) { return object.map((element) => camelize(element)) as Camelize } @@ -16,7 +16,7 @@ export function camelize (object: T): Camelize { return object as Camelize } -export function snakelize (object: T): Snakelize { +export function snakelize(object: T): Snakelize { if (Array.isArray(object)) { return object.map((element) => snakelize(element)) as Snakelize } diff --git a/packages/utils/tests/logger.spec.ts b/packages/utils/tests/logger.spec.ts index 982f60456..d5917dfce 100644 --- a/packages/utils/tests/logger.spec.ts +++ b/packages/utils/tests/logger.spec.ts @@ -11,7 +11,7 @@ describe('Logger', () => { loggy.fatal('fatal') loggy.info('info') loggy.warn('warn') - + loggy.setDepth(LogDepth.Full) loggy.debug('debugging') @@ -20,7 +20,7 @@ describe('Logger', () => { loggy.info('info') loggy.warn('warn') }) - + it('create logger with a name', () => { const loggy = createLogger({ name: 'loggy' }) expect(loggy).to.exist diff --git a/packages/utils/tsconfig.json b/packages/utils/tsconfig.json index 50e6ef6eb..6cc7ea9b5 100644 --- a/packages/utils/tsconfig.json +++ b/packages/utils/tsconfig.json @@ -1,16 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "node_modules", - "dist", - "test", - "tests" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts", "./src/**/*.tsx"], + "exclude": ["node_modules", "dist", "test", "tests"] +} diff --git a/packages/utils/tsconfig.test.json b/packages/utils/tsconfig.test.json index eeb80c521..c4916d55a 100644 --- a/packages/utils/tsconfig.test.json +++ b/packages/utils/tsconfig.test.json @@ -1,11 +1,5 @@ { "extends": "tsconfig/test.json", - "include": [ - "tests", - ], - "exclude": [ - "node_modules", - "dist", - "src" - ] -} \ No newline at end of file + "include": ["tests"], + "exclude": ["node_modules", "dist", "src"] +} diff --git a/scripts/coveragePathFixing.js b/scripts/coveragePathFixing.js index 64b8d3e06..6fdca117b 100644 --- a/scripts/coveragePathFixing.js +++ b/scripts/coveragePathFixing.js @@ -1,9 +1,4 @@ import fs from 'node:fs' import { argv } from 'node:process' -fs.writeFileSync( - './coverage/lcov.info', - fs - .readFileSync('./coverage/lcov.info', 'utf-8') - .replace(/SF:src/g, `SF:packages/${argv[2]}/src`) -) +fs.writeFileSync('./coverage/lcov.info', fs.readFileSync('./coverage/lcov.info', 'utf-8').replace(/SF:src/g, `SF:packages/${argv[2]}/src`)) diff --git a/scripts/finalizeTypedocs.js b/scripts/finalizeTypedocs.js index eaf59f2fe..f1979fb68 100644 --- a/scripts/finalizeTypedocs.js +++ b/scripts/finalizeTypedocs.js @@ -39,11 +39,11 @@ for await (let filepath of walk(typedocOutPath)) { // Converts ugly names to clean names for example discordeno_types.ActionRow becomes ActionRow const cleanForms = [ - { ugly: 'discordeno_bot.md', clean: 'Bot.md'}, - { ugly: 'discordeno_gateway.md', clean: 'Gateway.md'}, - { ugly: 'discordeno_rest.md', clean: 'Rest.md'}, - { ugly: 'discordeno_types.md', clean: 'Types.md'}, - { ugly: 'discordeno_utils.md', clean: 'Utils.md'}, + { ugly: 'discordeno_bot.md', clean: 'Bot.md' }, + { ugly: 'discordeno_gateway.md', clean: 'Gateway.md' }, + { ugly: 'discordeno_rest.md', clean: 'Rest.md' }, + { ugly: 'discordeno_types.md', clean: 'Types.md' }, + { ugly: 'discordeno_utils.md', clean: 'Utils.md' }, { ugly: 'discordeno_bot.' }, { ugly: 'discordeno_gateway.' }, { ugly: 'discordeno_rest.' }, diff --git a/tsconfig.json b/tsconfig.json index 5380f07f0..2323e160e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,8 @@ { "extends": "tsconfig/base.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./dist" }, - "include": [ - "." - ], - "exclude": [ - "dist", - "build", - "node_modules" - ] -} \ No newline at end of file + "include": ["."], + "exclude": ["dist", "build", "node_modules"] +} diff --git a/turbo.json b/turbo.json index 9c6d648fb..20215e33e 100644 --- a/turbo.json +++ b/turbo.json @@ -2,89 +2,48 @@ "$schema": "https://turbo.build/schema.json", "pipeline": { "build": { - "outputs": [ - "dist/**/*.js" - ], - "inputs": [ - "src/**/*.ts" - ] + "outputs": ["dist/**/*.js"], + "inputs": ["src/**/*.ts"] }, "build:type": { - "dependsOn": [ - "^build:type" - ], - "outputs": [ - "dist/**/*.d.ts", - "dist/**/*.d.ts.map", - "dist/tsconfig.tsbuildinfo" - ] + "dependsOn": ["^build:type"], + "outputs": ["dist/**/*.d.ts", "dist/**/*.d.ts.map", "dist/tsconfig.tsbuildinfo"] }, "release-build": { - "dependsOn": [ - "^release-build" - ], - "outputs": [ - "dist/**" - ] + "dependsOn": ["^release-build"], + "outputs": ["dist/**"] }, "test:unit-coverage": { - "dependsOn": [ - "^build" - ], - "outputs": [ - "coverage/**" - ] + "dependsOn": ["^build"], + "outputs": ["coverage/**"] }, "test:unit": { - "dependsOn": [ - "^build" - ], - "outputs": [ - "coverage/**" - ] + "dependsOn": ["^build"], + "outputs": ["coverage/**"] }, "test:integration": { - "dependsOn": [ - "^build" - ], - "outputs": [ - "coverage/**" - ] + "dependsOn": ["^build"], + "outputs": ["coverage/**"] }, "test:test-type": { - "dependsOn": [ - "^build:type" - ] + "dependsOn": ["^build:type"] }, "test:deno-unit": { - "dependsOn": [ - "build", - "^build" - ], - "outputs": [ - "denoTestsDist/**" - ] + "dependsOn": ["build", "^build"], + "outputs": ["denoTestsDist/**"] }, "test:e2e": { - "dependsOn": [ - "^build" - ], - "outputs": [ - "coverage/**" - ] + "dependsOn": ["^build"], + "outputs": ["coverage/**"] }, "lint": { - "dependsOn": [ - "^build:type" - ] + "dependsOn": ["^build:type"] }, "fmt": { - "dependsOn": [ - "^build:type" - ] + "dependsOn": ["^build:type"] }, "dev": { "cache": false } } -} \ No newline at end of file +} diff --git a/typedoc.json b/typedoc.json index ee3ae8713..97191ca53 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,18 +1,10 @@ { - "entryPointStrategy": "packages", - "entryPoints": [ - "packages/bot", - "packages/gateway", - "packages/rest", - "packages/types", - "packages/utils" - ], - "logger": "console", - "skipErrorChecking": true, - "out": "./website/docs/generated/", - "cleanOutputDir": false, - "plugin": [ - "typedoc-plugin-markdown" - ], - "commentStyle": "all" + "entryPointStrategy": "packages", + "entryPoints": ["packages/bot", "packages/gateway", "packages/rest", "packages/types", "packages/utils"], + "logger": "console", + "skipErrorChecking": true, + "out": "./website/docs/generated/", + "cleanOutputDir": false, + "plugin": ["typedoc-plugin-markdown"], + "commentStyle": "all" } diff --git a/website/babel.config.js b/website/babel.config.js index 3a532fc17..675264818 100644 --- a/website/babel.config.js +++ b/website/babel.config.js @@ -1,6 +1,3 @@ module.exports = { - presets: [ - require.resolve('@docusaurus/core/lib/babel/preset'), - - ], -}; + presets: [require.resolve('@docusaurus/core/lib/babel/preset')], +} diff --git a/website/blog/changelogs/19.0.0.md b/website/blog/changelogs/19.0.0.md index 3ed7df3c0..a47ef0e4f 100644 --- a/website/blog/changelogs/19.0.0.md +++ b/website/blog/changelogs/19.0.0.md @@ -24,4 +24,4 @@ With that major rework, we began improving things we always wanted to do for a l ## Tips For Migrating From Previous Version 1. Find all instances of `bot.helpers.getAvatarURL` and replace with `avatarUrl` -2. Find and replace all `bot.helpers.xxx` with `rest.xxx` where `xxx` is any method on the helpers. +2. Find and replace all `bot.helpers.xxx` with `rest.xxx` where `xxx` is any method on the helpers. diff --git a/website/docs/bigbot/step-1-decisions.md b/website/docs/bigbot/step-1-decisions.md index 64b181ee0..76b867f06 100644 --- a/website/docs/bigbot/step-1-decisions.md +++ b/website/docs/bigbot/step-1-decisions.md @@ -16,4 +16,3 @@ This guide will proceed with Node.JS but you should apply the same concepts in y ## Choose A Coding Style Discordeno provides you the option to use a Class based approach or a No-Class based approach. If you are willing to take your time and optimize your bot to the max, I highly recommend you go the No-Class route. However, this guide will use the Class based approach as I believe most users will end up choosing this route. Should you require any help with the functional approach please contact us on Discord. - diff --git a/website/docs/bigbot/step-2-rest.md b/website/docs/bigbot/step-2-rest.md index 5750b4e38..c345e450c 100644 --- a/website/docs/bigbot/step-2-rest.md +++ b/website/docs/bigbot/step-2-rest.md @@ -204,10 +204,10 @@ Having multiple bot's sending requests from one source will impact your global r ::: ```ts -const MANAGERS = new Collection(); +const MANAGERS = new Collection() ``` -Create this MANAGERS collection at the near the top of the file. Then we can begin implementing this in our request handler. We are going to be changing this line: +Create this MANAGERS collection at the near the top of the file. Then we can begin implementing this in our request handler. We are going to be changing this line: ```ts try { @@ -228,20 +228,19 @@ try { const result = await manager.makeRequest(req.method, `${manager.baseUrl}${req.url}`, req.body) ``` - ### Evals One of the last things we should do, is make it possible to run commands on this process. To do this, we simply create a small bot on this process with an eval command that listens for our messages only on our developer server. This way we can dynamically update any properties we may need to. For example, if discord updates the API version, we can easily switch the api version with a simple command. Let's make a small bot on this process. Make a file called `services/rest/bot.ts`. Then paste the code below. -```ts +````ts import { createBot } from '@discordeno/bot' import { logger } from '@discordeno/utils' import * as util from 'util' const inspectOptions = { - depth: 1 + depth: 1, } const bot = createBot({ @@ -289,9 +288,9 @@ const bot = createBot({ response.push('```') await message.channel.createMessage(response.join('\n')) - } - } + }, + }, }) -``` +```` Now that you have an eval command available on ur `REST` service, whenever you need to modify something quickly you can easily do so from ur developer server where this bot is. For example, should you want to switch to a newer api version, it is as simple as `.eval REST.version = xxx` where xxx is the new API version. diff --git a/website/docs/bigbot/step-3-gateway.md b/website/docs/bigbot/step-3-gateway.md index 9844d25b3..42e481a81 100644 --- a/website/docs/bigbot/step-3-gateway.md +++ b/website/docs/bigbot/step-3-gateway.md @@ -35,7 +35,7 @@ export const REST = createRestManager({ proxy: { baseUrl: process.env.REST_URL, authorization: process.env.AUTHORIZATION, - } + }, }) ``` @@ -78,10 +78,10 @@ You can adjust the amount of **shardsPerWorker** and **totalWorkers** to fit you Let's make a file called `services/gateway/index.ts` and paste the following code: ```ts -import { logger } from '@discordeno/utils'; -import dotenv from 'dotenv'; -import express from 'express'; -dotenv.config(); +import { logger } from '@discordeno/utils' +import dotenv from 'dotenv' +import express from 'express' +dotenv.config() const AUTHORIZATION = process.env.AUTHORIZATION as string @@ -104,7 +104,7 @@ app.all('/*', async (req, res) => { // Identify A Shard switch (req.body.type) { case 'REQUEST_MEMBERS': { - return await GATEWAY.requestMembers(req.body.guildId, req.body.options); + return await GATEWAY.requestMembers(req.body.guildId, req.body.options) } default: logger.error(`[Shard] Unknown request received. ${JSON.stringify(req.body)}`) @@ -166,13 +166,13 @@ Now, let's go ahead and set up the server where we will receive this and start a Just like before, we are going to make another http listener to listen for incoming events and delegate them outwords. Make a file called `services/gateway/sharding/index.ts` ```ts -import { DiscordenoShard } from '@discordeno/gateway'; -import { logger } from '@discordeno/utils'; -import { Intents } from '@discordeno/types'; -import events from './events.js'; -import dotenv from 'dotenv'; -import express from 'express'; -dotenv.config(); +import { DiscordenoShard } from '@discordeno/gateway' +import { logger } from '@discordeno/utils' +import { Intents } from '@discordeno/types' +import events from './events.js' +import dotenv from 'dotenv' +import express from 'express' +dotenv.config() const AUTHORIZATION = process.env.AUTHORIZATION as string const SHARDS = new Collection() @@ -188,10 +188,10 @@ app.use( app.use(express.json()) function getUrlFromShardId(totalShards: number, shardId: number) { - const urls = process.env.EVENT_HANDLER_URLS?.split(',') ?? []; - const index = totalShards % shardId; + const urls = process.env.EVENT_HANDLER_URLS?.split(',') ?? [] + const index = totalShards % shardId - return urls[index] ?? urls[0]; + return urls[index] ?? urls[0] } app.all('/*', async (req, res) => { @@ -203,21 +203,23 @@ app.all('/*', async (req, res) => { // Identify A Shard switch (req.body.type) { case 'IDENTIFY_SHARD': { - logger.info(`[Shard] identifying ${SHARDS.has(req.body.shardId) ? 'existing' : 'new'} shard (${req.body.shardId})`); - const shard = SHARDS.get(req.body.shardId) ?? new DiscordenoShard({ - id: req.body.shardId, - connection: { - compress: req.body.compress, - intents: req.body.intents, - properties: req.body.properties, - token: req.body.token, - totalShards: req.body.totalShards, - url: req.body.url, - version: req.body.version, - }, - // TODO: Enable this in the next portion of the guide. - // events, - }); + logger.info(`[Shard] identifying ${SHARDS.has(req.body.shardId) ? 'existing' : 'new'} shard (${req.body.shardId})`) + const shard = + SHARDS.get(req.body.shardId) ?? + new DiscordenoShard({ + id: req.body.shardId, + connection: { + compress: req.body.compress, + intents: req.body.intents, + properties: req.body.properties, + token: req.body.token, + totalShards: req.body.totalShards, + url: req.body.url, + version: req.body.version, + }, + // TODO: Enable this in the next portion of the guide. + // events, + }) SHARDS.set(shard.id, shard) await shard.identify() @@ -384,8 +386,6 @@ Now let's enable resharding on our bot so we don't need to deal with it. Remembe - Manual: You can also trigger this manually should you choose. - When discord releases a new API version, updates your gateways to new version with no downtime. - - ### Evals One of the last things we should do, is make it possible to run commands on this process. To do this, we simply create a small bot on this process with an eval command that listens for our messages only on our developer server. This way we can dynamically update any properties we may need to. For example, if discord updates the API version, we can easily switch the api version with a simple command. diff --git a/website/docs/generated/README.md b/website/docs/generated/README.md index 13d5f74eb..e7a3497b0 100644 --- a/website/docs/generated/README.md +++ b/website/docs/generated/README.md @@ -2,4 +2,4 @@ discordeno-monorepo / [Modules](modules.md) # Discordeno -Thank you for using Discordeno. These docs are generated automatically. If you see any issues please contact us on [Discord](https://discord.gg/ddeno) \ No newline at end of file +Thank you for using Discordeno. These docs are generated automatically. If you see any issues please contact us on [Discord](https://discord.gg/ddeno) diff --git a/website/docs/generated/classes/_category_.json b/website/docs/generated/classes/_category_.json index 5f34fec49..182d14750 100644 --- a/website/docs/generated/classes/_category_.json +++ b/website/docs/generated/classes/_category_.json @@ -1,9 +1,8 @@ { - "label": "Classes", - "position": 2, - "link": { - "type": "generated-index", - "description": "Automatically generated documentation for modules." - } + "label": "Classes", + "position": 2, + "link": { + "type": "generated-index", + "description": "Automatically generated documentation for modules." } - \ No newline at end of file +} diff --git a/website/sidebars.js b/website/sidebars.js index 9ab54c245..f3303339e 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -14,7 +14,7 @@ /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ const sidebars = { // By default, Docusaurus generates a sidebar from the docs folder structure - tutorialSidebar: [{type: 'autogenerated', dirName: '.'}], + tutorialSidebar: [{ type: 'autogenerated', dirName: '.' }], // But you can create a sidebar manually /* @@ -28,6 +28,6 @@ const sidebars = { }, ], */ -}; +} -module.exports = sidebars; +module.exports = sidebars