From 720e546dad6f8c67795140d9d4df5a9698ca2ede Mon Sep 17 00:00:00 2001 From: Kitosight Date: Sat, 25 Jan 2025 14:46:16 +0300 Subject: [PATCH] 5.0.0 --- .gitignore | 5 + .npmignore | 3 + CHANGELOG.md | 56 +-- README.md | 240 ++++++++++++- package.json | 58 +-- pnpm-lock.yaml | 329 ++--------------- src/consts.ts | 25 +- src/enums.ts | 30 +- src/index.ts | 950 +++++++++++++++++++++++++++---------------------- src/utils.ts | 114 +----- tsconfig.json | 27 +- 11 files changed, 905 insertions(+), 932 deletions(-) create mode 100644 .gitignore create mode 100644 .npmignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99ea580 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vscode +node_modules +dist +packs +types \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..0bea2ff --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +src +packs +.vscode \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 6474a91..c7606a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,42 +1,58 @@ # Changelog +## 2025 + +### January + +#### 5.0.0 + +- Rewrite +- Removed Nodes Endpoint +- Added New READ ME + ## 2024 ### January #### 4.0.0 -- Source Code Refactoring + +- Source Code Refactoring ## 2023 ### July #### 3.0.0 + > Breaking Changes -- Package Renamed -- Source Code Refactoring -- Implemented Nodes Endpoint -- Updated README + +- Package Renamed +- Source Code Refactoring +- Implemented Nodes Endpoint +- Updated README ### April #### 2.0.0 -- Source Code Refactoring -- Implemented Callbacks Endpoint -- Updated README - - Updated style - - Updated `TypeScript Specials` article - - Updated examples + +- Source Code Refactoring +- Implemented Callbacks Endpoint +- Updated README + - Updated style + - Updated `TypeScript Specials` article + - Updated examples #### 1.1.0 -- Source Code Refactoring -- Dependencies Switch - - From `node-fetch` to `centra` -- Updated README - - Added `TypeScript Specials` article - - Added badges -- Added LICENSE -- Added CHANGELOG + +- Source Code Refactoring +- Dependencies Switch + - From `node-fetch` to `centra` +- Updated README + - Added `TypeScript Specials` article + - Added badges +- Added LICENSE +- Added CHANGELOG #### 1.0.0 - 1.0.3 -- First Release & Public Access \ No newline at end of file + +- First Release & Public Access diff --git a/README.md b/README.md index 1b86d93..a306e7b 100644 --- a/README.md +++ b/README.md @@ -1 +1,239 @@ -The old README was deleted. The new one coming soon... \ No newline at end of file +> [!NOTE] +> This is the fifth iteration of the package. + +The code base was fully rewritten from scratch, and support for Nodes endpoint was removed due to compatibility issues in some bundled projects caused by jsdom, replacement of which I could not find. + +Anyways, here are quick examples of using the new version, breaking changes are applied for it, but responses remain the same. + +# Examples + +Of course, you have to import the wrapper first: +```ts +import { Wrapper } from "@synthexia/bpapi-wrapper"; +``` + +## Function Info Endpoint + +```ts +new Wrapper("function") + .function("info", "$addS") + .then((info) => { + // Work with the response + }) + .catch((r) => { + // Catch an error + }); +``` + +```json +{ + "tag": "$addSelectMenuOption[Menu option ID;Label;Value;Description;(Default;Emoji;Message ID)]", + "description": "Adds select menu option to a select menu. Check wiki for examples.", + "args": [ + { + "name": "Menu option ID", + "type": "String", + "required": true + }, + { + "name": "Label", + "type": "String", + "required": true + }, + { + "name": "Value", + "type": "String", + "required": true + }, + { + "name": "Description", + "type": "String", + "required": true, + "empty": true + }, + { + "name": "Default", + "type": "Bool", + "required": false, + "empty": true + }, + { + "name": "Emoji", + "type": "Emoji", + "required": false, + "empty": true + }, + { + "name": "Message ID", + "type": "String", + "required": false, + "empty": true + } + ], + "intents": "None", + "premium": false +} +``` + +## Callback List Endpoint + +```ts +new Wrapper("callback") + .callback("list") + .then((list) => { + // Work with the response + }) + .catch((r) => { + // Catch an error + }); +``` + +```json +[ + { + "name": "$onJoined[channel ID]", + "description": "Triggers command when user joins server", + "args": [ + { + "name": "Channel ID", + "description": "Channel ID of the welcome channel", + "type": "Snowflake", + "required": true + } + ], + "intents": "Members", + "premium": false + }, + { + "name": "$onLeave[channel ID]", + "description": "Triggers command when user leaves server", + "args": [ + { + "name": "Channel ID", + "description": "Channel ID of the leave channel", + "type": "Snowflake", + "required": true + } + ], + "intents": "Members", + "premium": false + }, + { + "name": "$onMessageDelete[channel ID]", + "description": "Triggers command when user deletes message", + "args": [ + { + "name": "Channel ID", + "description": "Channel ID of the log channel", + "type": "Snowflake", + "required": true + } + ], + "intents": "None", + "premium": false + }, + { + "name": "$onBanAdd[channel ID]", + "description": "Triggers command when user is banned from the server", + "args": [ + { + "name": "Channel ID", + "description": "Channel ID of the log channel", + "type": "Snowflake", + "required": true + } + ], + "intents": "None", + "premium": false + }, + { + "name": "$onBanRemove[channel ID]", + "description": "Triggers command when user is unbanned from the server", + "args": [ + { + "name": "Channel ID", + "description": "Channel ID of the log channel", + "type": "Snowflake", + "required": true + } + ], + "intents": "None", + "premium": false + }, + { + "name": "$alwaysReply", + "description": "Makes command get triggered by every message", + "args": [], + "intents": "None", + "premium": true + }, + { + "name": "$messageContains[word;...]", + "description": "Command gets triggered every time message contains one of the provided words", + "args": [ + { + "name": "Word", + "type": "String", + "required": true + } + ], + "intents": "None", + "premium": true + }, + { + "name": "$awaitedCommand[name;(filter)]", + "description": "Used for awaited functions.", + "args": [ + { + "name": "Name", + "description": "Awaited command name", + "type": "String", + "required": true + }, + { + "name": "Filter", + "description": "Awaited command filter", + "type": "String", + "required": false + } + ], + "intents": "None", + "premium": false + }, + { + "name": "$reaction[name]", + "description": "Used for awaited reactions.", + "args": [ + { + "name": "Name", + "description": "Awaited reaction name", + "type": "String", + "required": true + } + ], + "intents": "None", + "premium": true + }, + { + "name": "$onInteraction[custom ID]", + "description": "Triggered by a component interaction. For example: a user pressing a button", + "args": [ + { + "name": "Custom ID", + "description": "Custom ID assigned to that interaction", + "type": "String", + "required": true + } + ], + "intents": "None", + "premium": false + }, + { + "name": "$onInteraction", + "description": "Triggered by a component interaction. For example: a user pressing a button", + "args": [], + "intents": "None", + "premium": false + } +] +``` diff --git a/package.json b/package.json index 34f9a12..844990b 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,32 @@ { - "name": "@synthexia/bpapi-wrapper", - "version": "4.0.1", - "description": "BPAPI Wrapper allows you to work with BDFD Public API more easier and pretty!", - "author": "Kitomanari", - "main": "./dist/index.js", - "typings": "./types/", - "repository": { - "url": "https://github.com/synthexia/bpapi-wrapper" - }, - "scripts": { - "build": "tsc -p . && pnpm pack" - }, - "keywords": [ - "bds", - "bdscript", - "bdfd", - "bpapi" - ], - "license": "MIT", - "dependencies": { - "centra": "^2.6.0", - "jsdom": "^24.0.0" - }, - "devDependencies": { - "@types/centra": "^2.2.3", - "@types/jsdom": "^21.1.6" - }, - "packageManager": "pnpm@8.14.1" + "name": "@synthexia/bpapi-wrapper", + "version": "5.0.0", + "description": "BPAPI Wrapper allows you to work with BDFD Public API more easier and pretty!", + "author": { + "name": "Kitosight", + "url": "https://github.com/Kitosight" + }, + "main": "./dist/index.js", + "typings": "./types/", + "repository": { + "url": "https://github.com/synthexia/bpapi-wrapper" + }, + "scripts": { + "build": "tsc -p . && pnpm pack --pack-destination packs" + }, + "keywords": [ + "bds", + "bdscript", + "bdfd", + "bpapi" + ], + "license": "MIT", + "dependencies": { + "centra": "^2.7.0" + }, + "devDependencies": { + "@types/centra": "^2.2.3", + "@types/node": "^22.10.7" + }, + "packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d0a73a6..0654996 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,336 +6,49 @@ settings: dependencies: centra: - specifier: ^2.6.0 - version: 2.6.0 - jsdom: - specifier: ^24.0.0 - version: 24.0.0 + specifier: ^2.7.0 + version: 2.7.0 devDependencies: '@types/centra': specifier: ^2.2.3 version: 2.2.3 - '@types/jsdom': - specifier: ^21.1.6 - version: 21.1.6 + '@types/node': + specifier: ^22.10.7 + version: 22.10.7 packages: /@types/centra@2.2.3: resolution: {integrity: sha512-7ylrBi66/xZuQ4nuNuXnk5RUBQcLUgMdAqls44buCssA2goua9YuqbY8cCpMTWX+U+Y5e9JDwWAaiBEN4ehMOw==} dependencies: - '@types/node': 20.4.0 + '@types/node': 22.10.7 dev: true - /@types/jsdom@21.1.6: - resolution: {integrity: sha512-/7kkMsC+/kMs7gAYmmBR9P0vGTnOoLhQhyhQJSlXGI5bzTHp6xdo0TtKWQAsz6pmSAeVqKSbqeyP6hytqr9FDw==} + /@types/node@22.10.7: + resolution: {integrity: sha512-V09KvXxFiutGp6B7XkpaDXlNadZxrzajcY50EuoLIpQ6WWYCSvf19lVIazzfIzQvhUN2HjX12spLojTnhuKlGg==} dependencies: - '@types/node': 20.4.0 - '@types/tough-cookie': 4.0.2 - parse5: 7.1.2 + undici-types: 6.20.0 dev: true - /@types/node@20.4.0: - resolution: {integrity: sha512-jfT7iTf/4kOQ9S7CHV9BIyRaQqHu67mOjsIQBC3BKZvzvUB6zLxEwJ6sBE3ozcvP8kF6Uk5PXN0Q+c0dfhGX0g==} - dev: true - - /@types/tough-cookie@4.0.2: - resolution: {integrity: sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw==} - dev: true - - /agent-base@7.1.0: - resolution: {integrity: sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==} - engines: {node: '>= 14'} + /centra@2.7.0: + resolution: {integrity: sha512-PbFMgMSrmgx6uxCdm57RUos9Tc3fclMvhLSATYN39XsDV29B89zZ3KA89jmY0vwSGazyU+uerqwa6t+KaodPcg==} dependencies: - debug: 4.3.4 + follow-redirects: 1.15.9 transitivePeerDependencies: - - supports-color - dev: false - - /asynckit@0.4.0: - resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} - dev: false - - /centra@2.6.0: - resolution: {integrity: sha512-dgh+YleemrT8u85QL11Z6tYhegAs3MMxsaWAq/oXeAmYJ7VxL3SI9TZtnfaEvNDMAPolj25FXIb3S+HCI4wQaQ==} + - debug dev: false - /combined-stream@1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} - engines: {node: '>= 0.8'} - dependencies: - delayed-stream: 1.0.0 - dev: false - - /cssstyle@4.0.1: - resolution: {integrity: sha512-8ZYiJ3A/3OkDd093CBT/0UKDWry7ak4BdPTFP2+QEP7cmhouyq/Up709ASSj2cK02BbZiMgk7kYjZNS4QP5qrQ==} - engines: {node: '>=18'} - dependencies: - rrweb-cssom: 0.6.0 - dev: false - - /data-urls@5.0.0: - resolution: {integrity: sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==} - engines: {node: '>=18'} - dependencies: - whatwg-mimetype: 4.0.0 - whatwg-url: 14.0.0 - dev: false - - /debug@4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} - engines: {node: '>=6.0'} + /follow-redirects@1.15.9: + resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==} + engines: {node: '>=4.0'} peerDependencies: - supports-color: '*' + debug: '*' peerDependenciesMeta: - supports-color: + debug: optional: true - dependencies: - ms: 2.1.2 - dev: false - - /decimal.js@10.4.3: - resolution: {integrity: sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==} - dev: false - - /delayed-stream@1.0.0: - resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} - engines: {node: '>=0.4.0'} - dev: false - - /entities@4.5.0: - resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} - engines: {node: '>=0.12'} - - /form-data@4.0.0: - resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} - engines: {node: '>= 6'} - dependencies: - asynckit: 0.4.0 - combined-stream: 1.0.8 - mime-types: 2.1.35 - dev: false - - /html-encoding-sniffer@4.0.0: - resolution: {integrity: sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==} - engines: {node: '>=18'} - dependencies: - whatwg-encoding: 3.1.1 dev: false - /http-proxy-agent@7.0.0: - resolution: {integrity: sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ==} - engines: {node: '>= 14'} - dependencies: - agent-base: 7.1.0 - debug: 4.3.4 - transitivePeerDependencies: - - supports-color - dev: false - - /https-proxy-agent@7.0.2: - resolution: {integrity: sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA==} - engines: {node: '>= 14'} - dependencies: - agent-base: 7.1.0 - debug: 4.3.4 - transitivePeerDependencies: - - supports-color - dev: false - - /iconv-lite@0.6.3: - resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} - engines: {node: '>=0.10.0'} - dependencies: - safer-buffer: 2.1.2 - dev: false - - /is-potential-custom-element-name@1.0.1: - resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==} - dev: false - - /jsdom@24.0.0: - resolution: {integrity: sha512-UDS2NayCvmXSXVP6mpTj+73JnNQadZlr9N68189xib2tx5Mls7swlTNao26IoHv46BZJFvXygyRtyXd1feAk1A==} - engines: {node: '>=18'} - peerDependencies: - canvas: ^2.11.2 - peerDependenciesMeta: - canvas: - optional: true - dependencies: - cssstyle: 4.0.1 - data-urls: 5.0.0 - decimal.js: 10.4.3 - form-data: 4.0.0 - html-encoding-sniffer: 4.0.0 - http-proxy-agent: 7.0.0 - https-proxy-agent: 7.0.2 - is-potential-custom-element-name: 1.0.1 - nwsapi: 2.2.7 - parse5: 7.1.2 - rrweb-cssom: 0.6.0 - saxes: 6.0.0 - symbol-tree: 3.2.4 - tough-cookie: 4.1.3 - w3c-xmlserializer: 5.0.0 - webidl-conversions: 7.0.0 - whatwg-encoding: 3.1.1 - whatwg-mimetype: 4.0.0 - whatwg-url: 14.0.0 - ws: 8.16.0 - xml-name-validator: 5.0.0 - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - dev: false - - /mime-db@1.52.0: - resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} - engines: {node: '>= 0.6'} - dev: false - - /mime-types@2.1.35: - resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} - engines: {node: '>= 0.6'} - dependencies: - mime-db: 1.52.0 - dev: false - - /ms@2.1.2: - resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} - dev: false - - /nwsapi@2.2.7: - resolution: {integrity: sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ==} - dev: false - - /parse5@7.1.2: - resolution: {integrity: sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==} - dependencies: - entities: 4.5.0 - - /psl@1.9.0: - resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==} - dev: false - - /punycode@2.3.0: - resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==} - engines: {node: '>=6'} - dev: false - - /punycode@2.3.1: - resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} - engines: {node: '>=6'} - dev: false - - /querystringify@2.2.0: - resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} - dev: false - - /requires-port@1.0.0: - resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} - dev: false - - /rrweb-cssom@0.6.0: - resolution: {integrity: sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==} - dev: false - - /safer-buffer@2.1.2: - resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} - dev: false - - /saxes@6.0.0: - resolution: {integrity: sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==} - engines: {node: '>=v12.22.7'} - dependencies: - xmlchars: 2.2.0 - dev: false - - /symbol-tree@3.2.4: - resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==} - dev: false - - /tough-cookie@4.1.3: - resolution: {integrity: sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==} - engines: {node: '>=6'} - dependencies: - psl: 1.9.0 - punycode: 2.3.0 - universalify: 0.2.0 - url-parse: 1.5.10 - dev: false - - /tr46@5.0.0: - resolution: {integrity: sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==} - engines: {node: '>=18'} - dependencies: - punycode: 2.3.1 - dev: false - - /universalify@0.2.0: - resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==} - engines: {node: '>= 4.0.0'} - dev: false - - /url-parse@1.5.10: - resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==} - dependencies: - querystringify: 2.2.0 - requires-port: 1.0.0 - dev: false - - /w3c-xmlserializer@5.0.0: - resolution: {integrity: sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==} - engines: {node: '>=18'} - dependencies: - xml-name-validator: 5.0.0 - dev: false - - /webidl-conversions@7.0.0: - resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==} - engines: {node: '>=12'} - dev: false - - /whatwg-encoding@3.1.1: - resolution: {integrity: sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==} - engines: {node: '>=18'} - dependencies: - iconv-lite: 0.6.3 - dev: false - - /whatwg-mimetype@4.0.0: - resolution: {integrity: sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==} - engines: {node: '>=18'} - dev: false - - /whatwg-url@14.0.0: - resolution: {integrity: sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==} - engines: {node: '>=18'} - dependencies: - tr46: 5.0.0 - webidl-conversions: 7.0.0 - dev: false - - /ws@8.16.0: - resolution: {integrity: sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==} - engines: {node: '>=10.0.0'} - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: '>=5.0.2' - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true - dev: false - - /xml-name-validator@5.0.0: - resolution: {integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==} - engines: {node: '>=18'} - dev: false - - /xmlchars@2.2.0: - resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==} - dev: false + /undici-types@6.20.0: + resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==} + dev: true diff --git a/src/consts.ts b/src/consts.ts index 41138fa..8845492 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -1,15 +1,14 @@ -export const API = 'https://botdesignerdiscord.com/public/api/'; -export const NODES = 'https://botdesignerdiscord.com/status'; +export const Api = "https://botdesignerdiscord.com/public/api/"; -export const ENDPOINT_PATH = { - FUNCTION: { - INFO: 'function/', - LIST: 'function_list', - TAG_LIST: 'function_tag_list' - }, - CALLBACK: { - INFO: 'callback/', - LIST: 'callback_list', - TAG_LIST: 'callback_tag_list' - } +export const EndpointPath = { + function: { + info: "function/", + list: "function_list", + tagList: "function_tag_list", + }, + callback: { + info: "callback/", + list: "callback_list", + tagList: "callback_tag_list", + }, } as const; diff --git a/src/enums.ts b/src/enums.ts index 7eb89b9..8f339d7 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -1,29 +1,11 @@ export enum Intents { - None = 'None', - Members = 'Members', - Presence = 'Presence' + None = "None", + Members = "Members", + Presence = "Presence", } export enum RawIntents { - None = 0, - Members = 2, - Presence = 256 -} - -export enum FunctionEndpoint { - Info = 'FunctionInfo', - List = 'FunctionList', - TagList = 'FunctionTagList', -} - -export enum CallbackEndpoint { - Info = 'CallbackInfo', - List = 'CallbackList', - TagList = 'CallbackTagList' -} - -export enum Target { - Functions = 'Functions', - Callbacks = 'Callbacks', - Nodes = 'Nodes' + None = 0, + Members = 2, + Presence = 256, } diff --git a/src/index.ts b/src/index.ts index a148023..f0df208 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,431 +1,537 @@ import * as centra from "centra"; -import { JSDOM } from "jsdom"; - -import { API, ENDPOINT_PATH, NODES } from "./consts"; -import { buildInfo, findTag, parseBody } from "./utils"; - -import { CallbackEndpoint, FunctionEndpoint, Intents, RawIntents, Target } from "./enums"; - -export declare namespace Node { - interface Info { - name: string; - stats: Stats[]; - } - - interface Stats { - nodeId: string; - /** - * The stats presented as a text line. - */ - text: string; - /** - * The stats presented as an object. - */ - rawStats: RawStats; - } - - interface RawStats { - botCount: string; - ping: string; - status: string; - } -} +import { Api, EndpointPath } from "./consts"; +import { Intents, RawIntents } from "./enums"; +import { HumanizeIntents } from "./utils"; export declare namespace Function { - interface Info { - /** - * The tag of the function - */ - tag: string; - /** - * The description of the function - */ - description: string; - /** - * The arguments of the function - */ - args: Arguments[] | null; - /** - * The intents of the function - */ - intents: Intents; - /** - * Whether the function requires premium hosting time - */ - premium: boolean; - } - - interface Response { - /** - * The tag of the function - */ - tag: string; - /** - * The description of the function - */ - shortDescription: string; - /** - * The description of the function? - * - * *It was never used* - */ - longDescription: string; - /** - * The arguments of the function - */ - arguments: Arguments[] | null; - /** - * The intents of the function - * - * 0 = None - * - * 2 = Members - * - * 256 = Presence - */ - intents: RawIntents; - /** - * Whether the function requires premium hosting time - */ - premium: boolean; - /** - * Deprecated key - * - * *No longer is being used* - */ - color: 0; - } - - interface Arguments { - /** - * The name of the argument - */ - name: string; - /** - * The description of the argument - */ - description?: string; - /** - * The type of the argument - */ - type: ArgumentType; - /** - * Whether the argument is required - */ - required: boolean; - /** - * Whether the argument can be repeated - */ - repeatable?: boolean; - /** - * Whether the argument can be empty - */ - empty?: boolean; - /** - * The Enums of the argument. - */ - enumData?: any; - } - - type ArgumentType = ( - 'Bool' | 'URL | String' | 'String' | 'Enum' | 'Emoji' | 'Snowflake' | 'URL' | 'Integer' | - 'Float | String | Integer' | 'HowMany' | 'Tuple' | 'Snowflake | String' | 'Permission' | - 'Color' | 'Duration' | 'Integer | Float' | 'String | URL' | 'String | Snowflake' | - 'Float | Bool | Integer | String' | 'Float | Integer | String' | - 'String | Bool | Integer | Float' | 'HowMany | String' | 'Float | Integer' | 'Float' - ); - - namespace ArgumentEnums { - type AddButton = readonly ['primary', 'secondary', 'success', 'danger', 'link']; - type Modal = readonly ['short', 'paragraph']; - type Category = readonly ['count', 'name', 'id', 'mention']; - type Channel = readonly ['text', 'voice', 'category', 'stage', 'forum']; - type EditButton = readonly ['primary', 'secondary', 'success', 'danger', 'link']; - type Error = readonly ['row', 'column', 'command', 'source', 'message']; - type Cooldown = readonly ['normal', 'global', 'server']; - type EmbedData = readonly ['description', 'footer', 'color', 'image', 'timestamp', 'title']; - type InviteInfo = readonly ['uses', 'channel', 'creationDate', 'inviter', 'isTemporary']; - type LeaderboardType = readonly ['user', 'server', 'globalUser']; - type Sort = readonly ['desc', 'asc']; - type LeaderboardReturnType = readonly ['id', 'value']; - type MessageData = readonly ['content', 'authorID', 'username', 'avatar']; - type Timestamp = readonly ['ns', 'ms', 's']; - type MembersCount = readonly ['invisible', 'dnd', 'online', 'offline', 'idle']; - type Url = readonly ['decode', 'encode']; - type VariablesCount = readonly ['channel', 'user', 'server', 'globaluser']; - } + interface Info { + /** + * The tag of the function + */ + tag: string; + /** + * The description of the function + */ + description: string; + /** + * The arguments of the function + */ + args: Argument[] | null; + /** + * The intents of the function + */ + intents: Intents; + /** + * Whether the function requires premium hosting time + */ + premium: boolean; + } + + interface Response { + /** + * The tag of the function + */ + tag: string; + /** + * The description of the function + */ + shortDescription: string; + /** + * The description of the function? + * + * *It was never used* + */ + longDescription: string; + /** + * The arguments of the function + */ + arguments: Argument[] | null; + /** + * The intents of the function + * + * 0 = None + * + * 2 = Members + * + * 256 = Presence + */ + intents: RawIntents; + /** + * Whether the function requires premium hosting time + */ + premium: boolean; + /** + * Deprecated key + * + * *No longer is being used* + */ + color: 0; + } + + interface Argument { + /** + * The name of the argument + */ + name: string; + /** + * The description of the argument + */ + description?: string; + /** + * The type of the argument + */ + type: ArgumentType; + /** + * Whether the argument is required + */ + required: boolean; + /** + * Whether the argument can be repeated + */ + repeatable?: boolean; + /** + * Whether the argument can be empty + */ + empty?: boolean; + /** + * The Enums of the argument. + */ + enumData?: any; + } + + type ArgumentType = + | "Bool" + | "URL | String" + | "String" + | "Enum" + | "Emoji" + | "Snowflake" + | "URL" + | "Integer" + | "Float | String | Integer" + | "HowMany" + | "Tuple" + | "Snowflake | String" + | "Permission" + | "Color" + | "Duration" + | "Integer | Float" + | "String | URL" + | "String | Snowflake" + | "Float | Bool | Integer | String" + | "Float | Integer | String" + | "String | Bool | Integer | Float" + | "HowMany | String" + | "Float | Integer" + | "Float"; + + namespace ArgumentEnums { + type AddButton = readonly [ + "primary", + "secondary", + "success", + "danger", + "link" + ]; + type Modal = readonly ["short", "paragraph"]; + type Category = readonly ["count", "name", "id", "mention"]; + type Channel = readonly ["text", "voice", "category", "stage", "forum"]; + type EditButton = readonly [ + "primary", + "secondary", + "success", + "danger", + "link" + ]; + type Error = readonly ["row", "column", "command", "source", "message"]; + type Cooldown = readonly ["normal", "global", "server"]; + type EmbedData = readonly [ + "description", + "footer", + "color", + "image", + "timestamp", + "title" + ]; + type InviteInfo = readonly [ + "uses", + "channel", + "creationDate", + "inviter", + "isTemporary" + ]; + type LeaderboardType = readonly ["user", "server", "globalUser"]; + type Sort = readonly ["desc", "asc"]; + type LeaderboardReturnType = readonly ["id", "value"]; + type MessageData = readonly [ + "content", + "authorID", + "username", + "avatar" + ]; + type Timestamp = readonly ["ns", "ms", "s"]; + type MembersCount = readonly [ + "invisible", + "dnd", + "online", + "offline", + "idle" + ]; + type Url = readonly ["decode", "encode"]; + type VariablesCount = readonly [ + "channel", + "user", + "server", + "globaluser" + ]; + } } export declare namespace Callback { - interface Info { - /** - * The name (tag-name) of the callback - */ - name: string; - /** - * The description of the callback - */ - description: string; - /** - * The arguments of the callback - */ - args: Arguments[] | []; - /** - * The intents of the callback - */ - intents: Intents; - /** - * Whether the callback requires premium hosting time - */ - premium: boolean; - } - - interface Response { - /** - * The name of the callback - */ - name: string; - /** - * The description of the callback - */ - description: string; - /** - * The arguments of the callback - */ - arguments: Arguments[] | null; - /** - * The intents of the callback - * - * 0 = None - * - * 2 = Members - * - * 256 = Presence - */ - intents: RawIntents; - /** - * Whether the callback requires premium hosting time - */ - is_premium: boolean; - } - - interface Arguments { - /** - * The name of the argument - */ - name: string; - /** - * The description of the argument - */ - description: string; - /** - * The type of the argument - */ - type: ArgumentType; - /** - * Whether the argument is required - */ - required: boolean; - } - - type ArgumentType = 'String' | 'Snowflake'; -} - -class Request { - public static async functions(params: { - endpoint: FunctionEndpoint.Info, - tag: string - }): Promise; - public static async functions(params: { - endpoint: FunctionEndpoint.List - }): Promise; - public static async functions(params: { - endpoint: FunctionEndpoint.TagList - }): Promise; - - public static async functions( - params: - | { endpoint: FunctionEndpoint.List | FunctionEndpoint.TagList } - | { endpoint: FunctionEndpoint.Info, tag: string } - ) { - switch (params.endpoint) { - case FunctionEndpoint.Info: - const tag = await findTag(Target.Functions, params.tag!); - if (!tag) return; - - return await ( - await centra(API + ENDPOINT_PATH.FUNCTION.INFO + tag).send() - ).json(); - case FunctionEndpoint.List: - return await ( - await centra(API + ENDPOINT_PATH.FUNCTION.LIST).send() - ).json(); - case FunctionEndpoint.TagList: - return await ( - await centra(API + ENDPOINT_PATH.FUNCTION.TAG_LIST).send() - ).json(); - } - } - - public static async callbacks(params: { - endpoint: CallbackEndpoint.Info, - tag: string - }): Promise; - public static async callbacks(params: { - endpoint: CallbackEndpoint.List - }): Promise; - public static async callbacks(params: { - endpoint: CallbackEndpoint.TagList - }): Promise; - - public static async callbacks( - params: - | { endpoint: CallbackEndpoint.List | CallbackEndpoint.TagList } - | { endpoint: CallbackEndpoint.Info, tag: string } - ) { - switch (params.endpoint) { - case CallbackEndpoint.Info: - const tag = await findTag(Target.Callbacks, params.tag!); - if (!tag) return; - - return await ( - await centra(API + ENDPOINT_PATH.CALLBACK.INFO + tag).send() - ).json(); - case CallbackEndpoint.List: - return await ( - await centra(API + ENDPOINT_PATH.CALLBACK.LIST).send() - ).json(); - case CallbackEndpoint.TagList: - return await ( - await centra(API + ENDPOINT_PATH.CALLBACK.TAG_LIST).send() - ).json(); - } - } - - public static async nodes() { - return await ( - await centra(NODES).send() - ).text(); - } + interface Info { + /** + * The name (tag-name) of the callback + */ + name: string; + /** + * The description of the callback + */ + description: string; + /** + * The arguments of the callback + */ + args: Argument[] | []; + /** + * The intents of the callback + */ + intents: Intents; + /** + * Whether the callback requires premium hosting time + */ + premium: boolean; + } + + interface Response { + /** + * The name of the callback + */ + name: string; + /** + * The description of the callback + */ + description: string; + /** + * The arguments of the callback + */ + arguments: Argument[] | null; + /** + * The intents of the callback + * + * 0 = None + * + * 2 = Members + * + * 256 = Presence + */ + intents: RawIntents; + /** + * Whether the callback requires premium hosting time + */ + is_premium: boolean; + } + + interface Argument { + /** + * The name of the argument + */ + name: string; + /** + * The description of the argument + */ + description: string; + /** + * The type of the argument + */ + type: ArgumentType; + /** + * Whether the argument is required + */ + required: boolean; + } + + type ArgumentType = "String" | "Snowflake"; } -export class Nodes { - /** - * - * @returns An array containing info about nodes - */ - public static async list(): Promise { - const html = await Request.nodes(); - const document = new JSDOM(html).window.document; - - const [defaultTable, highPerfTable] = document.getElementsByClassName('uk-table'); - - if (!defaultTable) - throw new Error('Failed to parse the Default table, please try again later.'); - if (!highPerfTable) - throw new Error('Failed to parse the High Perfomance table, please try again later.'); - - const [dtCaptionElement, _dtTHeadElement, dtTBodyElement] = defaultTable.children; - const [hptCaptionElement, _hptTHeadElement, hptTBodyElement] = highPerfTable.children; - - const dtCaption = dtCaptionElement.textContent!; - const hptCaption = hptCaptionElement.textContent!; - - const dtBody = []; - const hptBody = []; - - for (const element of dtTBodyElement.children) - dtBody.push( parseBody(element.children) ); - for (const element of hptTBodyElement.children) - hptBody.push( parseBody(element.children) ); - - return [ - { - name: dtCaption, - stats: dtBody - }, - { - name: hptCaption, - stats: hptBody - } - ]; - } -} - -export class Functions { - /** - * Get the information about the function - * - * @param tag The tag of the function. The tag can be written partially (e.g `$addB`) - * @returns Information about the function or `undefined` if the function wasn't found - */ - public static async info(tag: string): Promise { - const data = await Request.functions({ endpoint: FunctionEndpoint.Info, tag }); - if (!data) return; - - return buildInfo({ target: Target.Functions, response: data}); - } - - /** - * Get the information about all functions - * - * @returns An array of objects containing information about all functions - */ - public static async list(): Promise { - const data = await Request.functions({ endpoint: FunctionEndpoint.List }); - const functionList: Function.Info[] = []; - - for (const f of data) - functionList.push(buildInfo({ target: Target.Functions, response: f })); - - return functionList; - } - - /** - * Get the tags of all functions - * - * @returns An array of strings containing the tags of all functions - */ - public static async tagList(): Promise { - return await Request.functions({ endpoint: FunctionEndpoint.TagList }); - } -} - -export class Callbacks { - /** - * Get the information about the callback - * - * @param tag The tag of the callback. The tag can be written partially (e.g `$addB`) - * @returns Information about the callback or `undefined` if the callback wasn't found - */ - public static async info(tag: string): Promise { - const data = await Request.callbacks({ endpoint: CallbackEndpoint.Info , tag }); - if (!data) return; - - return buildInfo({ target: Target.Callbacks, response: data }); - } - - /** - * Get the information about all callbacks - * - * @returns An array of objects containing information about all callbacks - */ - public static async list(): Promise { - const data = await Request.callbacks({ endpoint: CallbackEndpoint.List }); - const callbackList: Callback.Info[] = []; - - for (const c of data) - callbackList.push(buildInfo({ target: Target.Callbacks, response: c })); - - return callbackList; - } - - /** - * Get the tags of all callbacks - * - * @returns An array of strings containing the tags of all callbacks - */ - public static async tagList(): Promise { - return await Request.callbacks({ endpoint: CallbackEndpoint.TagList }); - } +type PartialTag = string; +type TagArray = string[]; +type WrapperTarget = "function" | "callback"; +type Endpoint = "info" | "list" | "tag-list"; + +export class Wrapper { + private target: WrapperTarget; + + constructor(target: WrapperTarget) { + this.target = target; + } + + private async findByPartialTag( + target: WrapperTarget, + tag: string + ): Promise { + let tagList: string[]; + + switch (target) { + case "function": + tagList = await new Wrapper("function").fetch("tag-list"); + break; + case "callback": + tagList = await new Wrapper("callback").fetch("tag-list"); + break; + } + + for (const t of tagList) { + if (t.includes(tag)) return t; + } + } + + private buildInfo( + target: WrapperTarget, + response: Function.Response | Callback.Response + ) { + switch (target) { + case "function": + const { + tag, + shortDescription, + premium, + intents: functionIntents, + arguments: functionArguments, + } = response; + + return { + tag, + description: shortDescription, + args: functionArguments, + intents: HumanizeIntents(functionIntents), + premium, + }; + case "callback": + const { + name, + description, + is_premium, + intents: callbackIntents, + arguments: callbackArguments, + } = response; + + return { + name, + description, + args: callbackArguments, + intents: HumanizeIntents(callbackIntents), + premium: is_premium, + }; + } + } + + private async fetch( + endpoint: "info", + tag: string + ): Promise; + private async fetch( + endpoint: "list" + ): Promise; + private async fetch(endpoint: "tag-list"): Promise; + + private async fetch(endpoint: Endpoint, tag: string = "") { + switch (this.target) { + case "function": + switch (endpoint) { + case "info": + return await this.findByPartialTag( + "function", + tag + ).then( + async ( + completedTag + ): Promise => { + if (!completedTag) + throw new Error( + `Failed to find function by partial tag "${tag}": resulted in "${completedTag}"` + ); + return await ( + await centra( + Api + + EndpointPath.function.info + + completedTag + ).send() + ).json(); + } + ); + case "list": + return ( + await ( + await centra( + Api + EndpointPath.function.list + ).send() + ).json() + ); + case "tag-list": + return ( + await ( + await centra( + Api + EndpointPath.function.tagList + ).send() + ).json() + ); + } + case "callback": + switch (endpoint) { + case "info": + return await this.findByPartialTag( + "callback", + tag + ).then( + async (completedTag): Promise => + await ( + await centra( + Api + + EndpointPath.callback.info + + completedTag + ).send() + ).json() + ); + case "list": + return ( + await ( + await centra( + Api + EndpointPath.callback.list + ).send() + ).json() + ); + case "tag-list": + return ( + await ( + await centra( + Api + EndpointPath.callback.tagList + ).send() + ).json() + ); + } + default: + throw new Error( + `Target "${this.target}" does not exist! Available targets: "function", "callback".` + ); + } + } + + /** + * + * Makes request to function-related endpoints + * + * @param endpoint The endpoint to make the request to + * @param tag A function tag, it can even be written partially + */ + public async function( + endpoint: "info", + tag: PartialTag + ): Promise; + /** + * + * Makes request to function-related endpoints + * + * @param endpoint The endpoint to make the request to + */ + public async function(endpoint: "list"): Promise; + /** + * + * Makes request to function-related endpoints + * + * @param endpoint The endpoint to make the request to + */ + public async function(endpoint: "tag-list"): Promise; + + public async function(endpoint: Endpoint, tag: PartialTag = "") { + if (this.target === "callback") + throw new Error( + `Cannot use "${this.function.name}" method when target is "${this.target}"!` + ); + + switch (endpoint) { + case "info": + return this.buildInfo( + this.target, + await this.fetch("info", tag) + ); + case "list": + return await this.fetch("list").then((data) => { + const list: Function.Info[] = []; + + for (const response of data) { + list.push( + this.buildInfo(this.target, response) + ); + } + + return list; + }); + case "tag-list": + return await this.fetch("tag-list"); + } + } + + /** + * + * Makes request to callback-related endpoints + * + * @param endpoint The endpoint to make the request to + * @param tag A function tag, it can even be written partially + */ + public async callback( + endpoint: "info", + tag: PartialTag + ): Promise; + /** + * + * Makes request to callback-related endpoints + * + * @param endpoint The endpoint to make the request to + */ + public async callback(endpoint: "list"): Promise; + /** + * + * Makes request to callback-related endpoints + * + * @param endpoint The endpoint to make the request to + */ + public async callback(endpoint: "tag-list"): Promise; + + public async callback(endpoint: Endpoint, tag: PartialTag = "") { + if (this.target === "function") + throw new Error( + `Cannot use "${this.callback.name}" method when target is "${this.target}"!` + ); + + switch (endpoint) { + case "info": + return this.buildInfo( + this.target, + await this.fetch("info", tag) + ); + case "list": + return await this.fetch("list").then((data) => { + const list: Callback.Info[] = []; + + for (const response of data) { + list.push( + this.buildInfo(this.target, response) + ); + } + + return list; + }); + case "tag-list": + return await this.fetch("tag-list"); + } + } } diff --git a/src/utils.ts b/src/utils.ts index 28fd059..32a60f9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,104 +1,12 @@ -import { - type Function, - type Callback, - type Node, - Functions, - Callbacks -} from "."; -import { Intents, RawIntents, Target } from "./enums"; - -export async function findTag(target: Target.Functions | Target.Callbacks, tag: string): Promise { - let tags: string[]; - - switch (target) { - case Target.Functions: - tags = await Functions.tagList(); - break; - case Target.Callbacks: - tags = await Callbacks.tagList(); - break; - } - - for (const t of tags) { - if (t.includes(tag)) return t; - } -} - -export function intentsSwitcher(raw: RawIntents): Intents { - switch (raw) { - case RawIntents.Presence: - return Intents.Presence; - case RawIntents.Members: - return Intents.Members; - default: - return Intents.None; - } -} - -export function buildInfo(params: { - target: Target.Functions, - response: Function.Response -}): Function.Info; -export function buildInfo(params: { - target: Target.Callbacks, - response: Callback.Response -}): Callback.Info; - -export function buildInfo( - params: - | { target: Target.Functions, response: Function.Response } - | { target: Target.Callbacks, response: Callback.Response } -) { - switch (params.target) { - case Target.Functions: - const { - tag, - shortDescription, - premium, - intents: functionIntents, - arguments: functionArgs - } = params.response; - - return { - tag, - description: shortDescription, - args: functionArgs, - intents: intentsSwitcher(functionIntents), - premium - }; - case Target.Callbacks: - const { - name, - description, - is_premium, - intents: callbackIntents, - arguments: callbackArgs - } = params.response; - - return { - name, - description, - args: callbackArgs, - intents: intentsSwitcher(callbackIntents), - premium: is_premium - }; - } -} - -export function parseBody(bodyElementChildren: HTMLCollection): Node.Stats { - const [serverIdElement, botCountElement, pingElement, statusElement] = bodyElementChildren; - - const nodeId = serverIdElement.textContent!; - const botCount = botCountElement.textContent!; - const ping = pingElement.textContent!; - const status = statusElement.textContent! - .replaceAll('\n', '') - .replaceAll('\t', '') - .replaceAll(' ', ''); - - return { - nodeId, - text: `Server #${nodeId} is ${status} (${ping}): ${botCount} bots online`, - rawStats: { botCount, ping, status } - }; +import { Intents, RawIntents } from "./enums"; + +export function HumanizeIntents(raw: RawIntents): Intents { + switch (raw) { + case RawIntents.Presence: + return Intents.Presence; + case RawIntents.Members: + return Intents.Members; + default: + return Intents.None; + } } diff --git a/tsconfig.json b/tsconfig.json index 8c52961..0c5a501 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,15 @@ { - "compilerOptions": { - "strict": true, - "declaration": true, - "module": "CommonJS", - "moduleResolution": "node", - "target": "ESNext", - "outDir": "./dist/", - "rootDir": "./src/", - "declarationDir": "./types/" - }, - "exclude": ["ignore"], - "include": ["src"] -} \ No newline at end of file + "compilerOptions": { + "strict": true, + "declaration": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "module": "CommonJS", + "moduleResolution": "node", + "target": "ESNext", + "outDir": "./dist/", + "rootDir": "./src/", + "declarationDir": "./types/" + }, + "include": ["src"] +}