diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 06cde0ad9..000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,27 +0,0 @@ ---- - -name: Bug report -about: Report incorrect or unexpected behaviour of aoi.js -title: '' -labels: 'type: bug' -assignees: '' ---- - - -## Type -- [ ] Functions: \ -- [ ] Callbacks: \ -- [ ] Handlers: \ -- [ ] Others: \______ - -Code used: -``` -Your Code Here -``` - -More: -- Aoi.js version: -- Node.js version: -- Operating system: - -Screenshots (If any): Image or Link \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 000000000..b5396f8f4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,87 @@ +name: Reporting Bug +description: Report us the issue, and leave it to us! 🤗 +title: "Bug: " +labels: "bug" +assignees: "Leref" +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! Fill in the blanks by following the steps. 🙌 + + - type: dropdown + id: type + attributes: + label: Bug Type + description: Please select a type of bug you want to report. + options: + - Function + - Callback + - Handler + - Extensions + validations: + required: true + + - type: textarea + id: code + attributes: + label: Bugged Function + render: js + description: Please type usage of your code + placeholder: | + module.exports = { + name: "ping", + type: 'interaction', + prototype: 'slash', + code: ` + $sendMessage[Hello?] + ` + } + validations: + required: true + + - type: dropdown + id: aoijs-version + attributes: + label: Version of aoi.js + description: What version of aoi.js are you using? + options: + - v6.6.1 + - v6.6.0 + - v6.5.6 + validations: + required: true + + - type: dropdown + id: node-version + attributes: + label: Version of Node.js + description: Also, what version of Node.js are you using? + options: + - v16.11.0 (Lowest) + - v20.10.0 (LTS) + - v21.4.0 (Current) + validations: + required: true + + - type: textarea + id: excepted + attributes: + label: Excepted Output + description: Please describe your expectations the code you have tried. + + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: shell + + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/AkaruiDevelopment/aoi.js/blob/v5/.github/CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 663a8eff0..55546d85e 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,5 @@ blank_issues_enabled: false contact_links: - - name: Discord server + - name: Discord Server url: https://discord.gg/HMUfMXDQsV - about: Please visit our Discord server for question and support. \ No newline at end of file + about: Contact us in our Discord Server diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index b6bc56fd9..000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,18 +0,0 @@ ---- - -name: Feature request -about: Request feature about function, callback, handler, etc for aoi.js -title: '' -labels: 'type: enhancement' -assignees: '' ---- - - -## Type -- [ ] Functions: \ -- [ ] Callbacks: \ -- [ ] Handlers: \ -- [ ] Others: \______ - -## Description -Explain how it works \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_requesting.yml b/.github/ISSUE_TEMPLATE/feature_requesting.yml new file mode 100644 index 000000000..a9111be7b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_requesting.yml @@ -0,0 +1,42 @@ +name: Feature Request +description: Request a feature or suggest us what is in your mind! +labels: "enhancement" +assignees: + - enhancement +body: + - type: markdown + attributes: + value: | + Please explain what is in your mind, we would like to hear it from you! 🤠 + + - type: dropdown + id: type + attributes: + label: Featuring Type + description: Please select a type of feature you want to request. + options: + - Function + - Callback + - Handler + - Extensions + - Others + validations: + required: true + + - type: textarea + id: explaining + attributes: + label: So, what is it about? + description: Please describe what you're requesting for. So, we Akarui Team can understand your request better and work on it faster! + placeholder: It's about... + validations: + required: true + + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/AkaruiDevelopment/aoi.js/blob/v5/.github/CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE/Functions.md b/.github/PULL_REQUEST_TEMPLATE/Functions.md new file mode 100644 index 000000000..3d3c3902d --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/Functions.md @@ -0,0 +1,48 @@ +## Type +- [ ] Discord + - [ ] Client + - [ ] Guild + - [ ] Channel + - [ ] Message + - [ ] User + - [ ] Member + - [ ] Role + - [ ] Emoji + - [ ] Invite + - [ ] Webhook + - [ ] AutoMod + - [ ] Misc + +- [ ] JavaScript + - [ ] Array + - [ ] Conditions + - [ ] File System + - [ ] Loops + - [ ] Maths + - [ ] Misc + - [ ] Object + - [ ] Process + - [ ] String + +## Description + +> Give a brief description of the pull request. + +## Usage + +> Give a brief example of how would be the usage of this pull request. +> **( `--`, if usage is not changed)** + +## Semver Changes + +- [ ] Patch (bug fix, no new features) +- [ ] Minor (new features, no breaking changes) +- [ ] Major (breaking changes) + +## Issues + +> List any issues that this pull request closes. + +## Checklist + +- [ ] I have read the [Contributing Guidelines](../CONTRIBUTING.md). diff --git a/.github/PULL_REQUEST_TEMPLATE/Module.md b/.github/PULL_REQUEST_TEMPLATE/Module.md new file mode 100644 index 000000000..f688ba17a --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/Module.md @@ -0,0 +1,26 @@ +## Module + +- [ ] [Core](../../src/core/) +- [ ] [Events](../../src/events/) +- [ ] [Manager](../../src/manager/) +- [ ] [Structures](../../src/structures/) +- [ ] [Typings](../../src/typings/) +- [ ] [Utils](../../src/util/) + +## Description + +> Give a brief description of the pull request. + +## Semver Changes + +- [ ] Patch (bug fix, no new features) +- [ ] Minor (new features, no breaking changes) +- [ ] Major (breaking changes) + +## Issues + +> List any issues that this pull request closes. + +## Checklist + +- [ ] I have read the [Contributing Guidelines](../CONTRIBUTING.md). diff --git a/.github/PULL_REQUEST_TEMPLATE/nonCore.md b/.github/PULL_REQUEST_TEMPLATE/nonCore.md new file mode 100644 index 000000000..0222ae995 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/nonCore.md @@ -0,0 +1,17 @@ +## Description + +> Give a brief description of the pull request. + +## Semver Changes + +- [ ] Patch (bug fix, no new features) +- [ ] Minor (new features, no breaking changes) +- [ ] Major (breaking changes) + +## Issues + +> List any issues that this pull request closes. + +## Checklist + +- [ ] I have read the [Contributing Guidelines](../CONTRIBUTING.md). diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000..2be2d7630 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,18 @@ +Client: + - any: ['src/structures/Client.ts', 'src/functions/discord/client/*'] + +Classes: + - src/structures/* + +Manager: + - src/manager/* + +Core: + - src/core/**/* + +Functions:Discord: + - src/functions/discord/**/* + +Functions:JS: + - src/functions/js/**/* + diff --git a/.github/workflows/add-feature-label.yml b/.github/workflows/add-feature-label.yml new file mode 100644 index 000000000..80bcf4d65 --- /dev/null +++ b/.github/workflows/add-feature-label.yml @@ -0,0 +1,38 @@ +name: Add Feature label + +on: + - pull_request_target + +jobs: + add-feature-label: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Find new files in src directory + run: | + NEW_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) + CHANGED_FILES=() + for file in $NEW_FILES; do + if [[ $file == "src/"* ]]; then + CHANGED_FILES+=("$file") + fi + done + echo "::set-output name=changed_files::${CHANGED_FILES[*]}" + id: find-files + - name: Add Feature label + if: ${{ steps.find-files.outputs.changed_files != '' }} + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const issue = await github.issues.get(context.issue); + const labels = issue.data.labels.map(label => label.name); + if (!labels.includes('Feature')) { + await github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: ['Feature'] + }); + } diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 000000000..814f484e3 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,23 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler + +name: Labeler +on: +- pull_request_target + +jobs: + label: + + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/labeler@v4 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/publish-dev.yml b/.github/workflows/publish-dev.yml index e3e859e15..11ae3568b 100644 --- a/.github/workflows/publish-dev.yml +++ b/.github/workflows/publish-dev.yml @@ -21,7 +21,7 @@ jobs: run: npm ci --ignore-scripts - name: Deprecate old versions - run: npm deprecate aoi.js@"~5.0.0-dev" "This is no longer supported" || true + run: npm deprecate aoi.js@"~6.1.0-dev" "This is no longer supported" || true env: NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} diff --git a/.gitignore b/.gitignore index b585ce51e..9d44b1ce5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,17 @@ -commands -config.json +#Ignore modules node_modules -database -/test.js + +#Ignore database files +/database + +#Ignore Test Environment +/commands +config.json +src/tests/ +plugins +/index.js .idea -index.js \ No newline at end of file +.vscode +.DS_Store +/dist +ignore \ No newline at end of file diff --git a/LICENSE b/LICENSE index 7d2cd33f7..9a971340a 100644 --- a/LICENSE +++ b/LICENSE @@ -176,7 +176,7 @@ END OF TERMS AND CONDITIONS - Copyright 2021 Leref + Copyright 2021 - 2023 Akarui Development Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -188,4 +188,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/README.md b/README.md index fa3ec0009..2d2cb31a7 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,140 @@ -
-

- aoi.js -

+

+ + aoijs + +

-# aoi.js -[![Discord Server](https://img.shields.io/discord/773352845738115102?color=5865F2&logo=discord&logoColor=white)](https://aoi.js.org/invite) -[![NPM Version](https://img.shields.io/npm/v/aoi.js.svg?maxAge=3600)](https://www.npmjs.com/package/aoi.js) -[![NPM Downloads](https://img.shields.io/npm/dt/aoi.js.svg?maxAge=3600)](https://www.npmjs.com/package/aoi.js) +
+ The most powerful string package to create a simple and fast Discord Bot. +
-## About -aoi.js is a package with customization and ready-to-use functions to make Discord Bots with ease. +--- -- Interaction Commands Support -- Optimized and customizable -- 500+ functions available +
-The successor of [dbd.js](https://www.npmjs.com/package/dbd.js) +
- -## Installation +[![NPM downloads][download-image]][download-url]     +[![AoiJS Server][aoijs-server]][aoijs-server-url]     +[![NPM version][npm-image]][npm-url]     +![License](https://img.shields.io/npm/l/aoi.js)     +![Website](https://img.shields.io/website?url=https%3A%2F%2Faoi.js.org&label=aoi.js.org)     -**Node.JS 16.6.0 or newer is required.** +[npm-image]: https://img.shields.io/npm/v/aoi.js.svg?color=42cfff -```sh-session -npm install aoi.js -``` +[npm-url]: https://npmjs.org/package/aoi.js + +[download-image]: https://img.shields.io/npm/dt/aoi.js.svg?color=3182b0 + +[download-url]: https://npmjs.org/package/aoi.js + +[aoijs-server]: https://img.shields.io/discord/773352845738115102?color=5865F2&logo=discord&logoColor=white + +[aoijs-server-url]: https://discord.gg/HMUfMXDQsV + +
+ +
+ +
+ +**[ Documentation ](https://aoi.js.org/)** | **[ Support Server ](https://discord.gg/HMUfMXDQsV)** | **[ NPM ](https://npmjs.org/package/aoi.js)** | **[ GitHub ](https://github.com/akaruidevelopment/aoi.js)** + +
-### Setting up +--- -```js -const aoijs = require("aoi.js") +## About + +aoi.js is a JavaScript library that is designed to make it easy to build Discord bots. + +It is open-source and free to use, and provides a simple, easy-to-use interface for interacting with the Discord API and +handling events. + +aoi.js is suitable for beginners who are new to building bots, as well as experienced developers who want to save time +and streamline their workflow. + +## Features + +- **600+ Pre-built Functions:** aoi.js comes packed with over 600 pre-built functions that empower you to create dynamic + and interactive Discord bots with ease. +- **Built-in Custom Local Database:** With aoi.js, you get a powerful custom local database out of the box. +- **Extensions for Added Functionality:** Enhance your bots capabilities with aoi.js extensions like aoi.music and + aoi.panel. These extensions make it simple to add music playback, interactive panels, and more to your bot. +- **Easy-to-Use and Beginner Friendly:** aoi.js boasts a user-friendly syntax that is perfect for beginners. The + simple `$` prefix makes it easy to write commands and get your bot up and running quickly. -const bot = new aoijs.Bot({ -token: "TOKEN", //Discord Bot Token -prefix: "PREFIX", //Discord Bot Prefix -intents: "all" //Discord Intents -}) +## Setup -//Events -bot.onMessage() +```javascript +const {AoiClient} = require("aoi.js"); -//Command Example -bot.command({ -name: "ping", -code: `Pong! \`$ping\`ms` -}) +const client = new AoiClient({ + intents: ["MessageContent", "Guilds", "GuildMessages"], + events: ["onMessage", "onInteractionCreate"], + prefix: "Discord Bot Prefix", + token: "Discord Bot Token" +}); -//Ready Event -bot.readyCommand({ - channel: "", - code: `$log[Ready on $userTag[$clientID]]` -}) +// Ping Command +client.command({ + name: "ping", + code: `Pong! $pingms` +}); ``` -### Optional packages -- [ffmpeg-static](https://www.npmjs.com/package/ffmpeg-static) for allowing Music Filters to run smoothly (`npm install ffmpeg-static`) +### Adding Database + +```javascript +const {AoiClient} = require("aoi.js"); + +const client = new AoiClient({ + intents: ["MessageContent", "Guilds", "GuildMessages"], + events: ["onMessage", "onInteractionCreate"], + prefix: "Discord Bot Prefix", + token: "Discord Bot Token", + database: { + type: "aoi.db", + db: require("@akarui/aoi.db"), + dbType: "KeyValue", + tables: ["main"], + securityKey: "a-32-characters-long-string-here", + } +}); + +// Ping Command +client.command({ + name: "ping", + code: `Pong! $pingms` +}); +``` + +## Command Handler + +By default, aoi.js does not have a command handler. However, you can easily add one by using the `loadCommands` method. + +```javascript +client.loadCommands("./commands/", true); +``` -## Akarui Development +- `./commands/` is the directory where your commands are located. +- `true` allows to log the commands in console. -aoi.js is made possible by Akarui Development.
-A team of Developers that create packages. +## Notices -Owned by [Leref](https://leref.ga/)
+- **Reading Functions**: Currently it reads `$` functions from bottom to top. -## Links -- [Website](https://aoi.js.org) -- [Github](https://github.com/aoijs/aoi.js) -- [Discord Server](https://aoi.js.org/invite) -- [Documentation](https://aoi.leref.ga) +## Official Extensions -## Open Source + -aoi.js is available and open source for the community to explore and contribute for future updates. +## Contributing -Please read [Contributing](https://github.com/aoijs/aoi.js/blob/master/.github/CONTRIBUTING.md) \ No newline at end of file +[Refer to contribution documentation for more information](https://github.com/AkaruiDevelopment/aoi.js/blob/v6/.github/CONTRIBUTING.md) diff --git a/package-lock.json b/package-lock.json index 88335bf5c..331cd3c2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,840 +1,828 @@ { "name": "aoi.js", - "version": "5.0.0-dev", - "lockfileVersion": 2, + "version": "6.7.0", + "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "aoi.js", - "version": "5.0.0-dev", + "version": "6.7.0", "license": "Apache-2.0", "dependencies": { - "@discordjs/voice": "^0.5.6", - "dbdjs.db": "^2.0.1", - "discord.js": "13.2.0", - "lavacoffee": "^1.3.0", - "soundcloud-downloader": "^1.0.0", - "spotify-url-info": "^2.2.0", - "youtube-sr": "^4.1.7", - "ytdl-core-discord": "^1.3.1" + "@akarui/aoi.db": "^2.1.0", + "@akarui/structures": "^1.0.2", + "chalk": "^4.1.2", + "discord.js": "^14.14.1", + "undici": "^5.28.2" }, "devDependencies": { - "@discordjs/opus": "^0.5.0", - "axios": "^0.21.1", - "ffmpeg-static": "^4.3.0", - "m3u8stream": "^0.8.4", - "node-fetch": "^2.6.1", - "prettier": "~2.2.1", - "prism-media": "^1.2.7", - "segfault-handler": "^1.3.0", - "tweetnacl": "^1.0.3", - "workerpool": "^6.1.0", - "ws": "^7.4.6", - "ytdl-core": "^4.9.0" - }, - "engines": { - "node": ">=16.6" - } - }, - "node_modules/@babel/runtime": { - "version": "7.15.3", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.15.3.tgz", - "integrity": "sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA==", - "dependencies": { - "regenerator-runtime": "^0.13.4" + "aoi.js-library": "^2.0.2", + "discord-api-types": "^0.37.65", + "prettier": "^3.1.0", + "typescript": "^4.5.2", + "ws": "^8.3.0" }, "engines": { - "node": ">=6.9.0" + "node": ">=16.11.0" } }, - "node_modules/@derhuerst/http-basic": { - "version": "8.2.1", - "resolved": "https://registry.npmjs.org/@derhuerst/http-basic/-/http-basic-8.2.1.tgz", - "integrity": "sha512-Rmn7qQQulw2sxJ8qGfZ7OuqMWuhz8V+L5xnYKMF5cXVcYqmgWqlVEAme90pF7Ya8OVhxVxLmhh0rI2k6t7ITWw==", - "devOptional": true, + "node_modules/@akarui/aoi.db": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@akarui/aoi.db/-/aoi.db-2.1.0.tgz", + "integrity": "sha512-U8JS4WGO9ICaMg4NWnY5FrFMdF2czO1ARhk/GRAo6pT+3nF7RbB+wQr9zGkjGtH8cL44oSqodjEG5zIEPx9mqw==", "dependencies": { - "caseless": "^0.12.0", - "concat-stream": "^1.6.2", - "http-response-object": "^3.0.1", - "parse-cache-control": "^1.0.1" + "@akarui/structures": "^2.0.1", + "jsonrepair": "^3.4.1", + "tar": "^6.1.15", + "ws": "^8.13.0" }, "engines": { - "node": ">=6.0.0" + "node": ">=20.x" } }, + "node_modules/@akarui/aoi.db/node_modules/@akarui/structures": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@akarui/structures/-/structures-2.0.1.tgz", + "integrity": "sha512-KyI4oT/d/miXtmisu1xzT3IWd5rBTXW5Yi2ownFmLp+elJtOIKawPRd8yeCy5BKac39QRKkD9TBinQtod89NJQ==" + }, + "node_modules/@akarui/structures": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@akarui/structures/-/structures-1.0.2.tgz", + "integrity": "sha512-Ac0cCIi0zlduNv0+Cr2B5jDOXq6UMNarzTWBD5z2g5LQs1yh5qcGBwJx+DxhtkqQZbY26PnXsrHOLm8XFfSTlQ==" + }, "node_modules/@discordjs/builders": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.6.0.tgz", - "integrity": "sha512-mH3Gx61LKk2CD05laCI9K5wp+a3NyASHDUGx83DGJFkqJlRlSV5WMJNY6RS37A5SjqDtGMF4wVR9jzFaqShe6Q==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.7.0.tgz", + "integrity": "sha512-GDtbKMkg433cOZur8Dv6c25EHxduNIBsxeHrsRoIM8+AwmEZ8r0tEpckx/sHwTLwQPOF3e2JWloZh9ofCaMfAw==", "dependencies": { - "@sindresorhus/is": "^4.0.1", - "discord-api-types": "^0.22.0", - "ow": "^0.27.0", - "ts-mixer": "^6.0.0", - "tslib": "^2.3.1" + "@discordjs/formatters": "^0.3.3", + "@discordjs/util": "^1.0.2", + "@sapphire/shapeshift": "^3.9.3", + "discord-api-types": "0.37.61", + "fast-deep-equal": "^3.1.3", + "ts-mixer": "^6.0.3", + "tslib": "^2.6.2" }, "engines": { - "node": ">=14.0.0", - "npm": ">=7.0.0" + "node": ">=16.11.0" } }, + "node_modules/@discordjs/builders/node_modules/discord-api-types": { + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" + }, "node_modules/@discordjs/collection": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.2.1.tgz", - "integrity": "sha512-vhxqzzM8gkomw0TYRF3tgx7SwElzUlXT/Aa41O7mOcyN6wIJfj5JmDWaO5XGKsGSsNx7F3i5oIlrucCCWV1Nog==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-1.5.3.tgz", + "integrity": "sha512-SVb428OMd3WO1paV3rm6tSjM4wC+Kecaa1EUGX7vc6/fddvw/6lg90z4QtCqm21zvVe92vMMDt9+DkIvjXImQQ==", "engines": { - "node": ">=14.0.0" + "node": ">=16.11.0" } }, - "node_modules/@discordjs/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==", + "node_modules/@discordjs/formatters": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@discordjs/formatters/-/formatters-0.3.3.tgz", + "integrity": "sha512-wTcI1Q5cps1eSGhl6+6AzzZkBBlVrBdc9IUhJbijRgVjCNIIIZPgqnUj3ntFODsHrdbGU8BEG9XmDQmgEEYn3w==", "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "discord-api-types": "0.37.61" }, "engines": { - "node": ">= 6" + "node": ">=16.11.0" } }, - "node_modules/@discordjs/node-pre-gyp": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@discordjs/node-pre-gyp/-/node-pre-gyp-0.4.1.tgz", - "integrity": "sha512-PLYLPG3R+m9QlMROOjdy2htQq54g6f9vRb1xPfZ97CL53yj0uNTfpB/jtY/AXY6OKNtZtrre5SKjei8Hcc44HQ==", - "devOptional": true, - "dependencies": { - "detect-libc": "^1.0.3", - "https-proxy-agent": "^5.0.0", - "make-dir": "^3.1.0", - "node-fetch": "^2.6.1", - "nopt": "^5.0.0", - "npmlog": "^5.0.0", - "rimraf": "^3.0.2", - "semver": "^7.3.5", - "tar": "^6.1.8" - }, - "bin": { - "node-pre-gyp": "bin/node-pre-gyp" - } + "node_modules/@discordjs/formatters/node_modules/discord-api-types": { + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" }, - "node_modules/@discordjs/opus": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/@discordjs/opus/-/opus-0.5.3.tgz", - "integrity": "sha512-IQhCwCy2WKXLe+qkOkwO1Wjgk20uqeAbqM62tCbzIqbTsXX4YAge8Me9RFnI77Lx+UTkgm4rSVM3VPVdS/GsUw==", - "devOptional": true, - "hasInstallScript": true, + "node_modules/@discordjs/rest": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.2.0.tgz", + "integrity": "sha512-nXm9wT8oqrYFRMEqTXQx9DUTeEtXUDMmnUKIhZn6O2EeDY9VCdwj23XCPq7fkqMPKdF7ldAfeVKyxxFdbZl59A==", "dependencies": { - "@discordjs/node-pre-gyp": "^0.4.0", - "node-addon-api": "^3.2.1" + "@discordjs/collection": "^2.0.0", + "@discordjs/util": "^1.0.2", + "@sapphire/async-queue": "^1.5.0", + "@sapphire/snowflake": "^3.5.1", + "@vladfrangu/async_event_emitter": "^2.2.2", + "discord-api-types": "0.37.61", + "magic-bytes.js": "^1.5.0", + "tslib": "^2.6.2", + "undici": "5.27.2" }, "engines": { - "node": ">=12.0.0" + "node": ">=16.11.0" } }, - "node_modules/@discordjs/voice": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/@discordjs/voice/-/voice-0.5.6.tgz", - "integrity": "sha512-CGwD5pz1YB8MXfERcXQ6jVCThfMjzPKbad8pYuvPt4ozFcLWGRKFJ5lj+CSRNDj0Cobc6MIKOKpFfOPlXTKTrw==", - "dependencies": { - "@types/ws": "^7.4.4", - "discord-api-types": "^0.22.0", - "prism-media": "^1.3.1", - "tiny-typed-emitter": "^2.0.3", - "ws": "^7.4.4" - } - }, - "node_modules/@sapphire/async-queue": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.1.5.tgz", - "integrity": "sha512-NQ8GeTBeOkeAylVYTnO9zfEZO74iMNGCRrR3uIRnCrhkyPC+nsewyQtTamjSDWxXFTf+xGSJ9khiY2p56k/bMA==", - "engines": { - "node": ">=v14.18.0", - "npm": ">=7.24.1" - } - }, - "node_modules/@sindresorhus/is": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.0.tgz", - "integrity": "sha512-VkE3KLBmJwcCaVARtQpfuKcKv8gcBmUubrfHGF84dXuuW6jgsRYxPtzcIhPyK9WAPpRt2/xY6zkD9MnRaJzSyw==", + "node_modules/@discordjs/rest/node_modules/@discordjs/collection": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-2.0.0.tgz", + "integrity": "sha512-YTWIXLrf5FsrLMycpMM9Q6vnZoR/lN2AWX23/Cuo8uOOtS8eHB2dyQaaGnaF8aZPYnttf2bkLMcXn/j6JUOi3w==", "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sindresorhus/is?sponsor=1" + "node": ">=18" } }, - "node_modules/@types/node": { - "version": "16.6.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.6.2.tgz", - "integrity": "sha512-LSw8TZt12ZudbpHc6EkIyDM3nHVWKYrAvGy6EAJfNfjusbwnThqjqxUKKRwuV3iWYeW/LYMzNgaq3MaLffQ2xA==" + "node_modules/@discordjs/rest/node_modules/discord-api-types": { + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" }, - "node_modules/@types/ws": { - "version": "7.4.7", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", - "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", + "node_modules/@discordjs/rest/node_modules/undici": { + "version": "5.27.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.27.2.tgz", + "integrity": "sha512-iS857PdOEy/y3wlM3yRp+6SNQQ6xU0mmZcwRSriqk+et/cwWAtwmIGf6WkoDN2EK/AMdCO/dfXzIwi+rFMrjjQ==", "dependencies": { - "@types/node": "*" + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" } }, - "node_modules/abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", - "devOptional": true + "node_modules/@discordjs/util": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@discordjs/util/-/util-1.0.2.tgz", + "integrity": "sha512-IRNbimrmfb75GMNEjyznqM1tkI7HrZOf14njX7tCAAUetyZM1Pr8hX/EK2lxBCOgWDRmigbp24fD1hdMfQK5lw==", + "engines": { + "node": ">=16.11.0" + } }, - "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "devOptional": true, + "node_modules/@discordjs/ws": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@discordjs/ws/-/ws-1.0.2.tgz", + "integrity": "sha512-+XI82Rm2hKnFwAySXEep4A7Kfoowt6weO6381jgW+wVdTpMS/56qCvoXyFRY0slcv7c/U8My2PwIB2/wEaAh7Q==", "dependencies": { - "debug": "4" + "@discordjs/collection": "^2.0.0", + "@discordjs/rest": "^2.1.0", + "@discordjs/util": "^1.0.2", + "@sapphire/async-queue": "^1.5.0", + "@types/ws": "^8.5.9", + "@vladfrangu/async_event_emitter": "^2.2.2", + "discord-api-types": "0.37.61", + "tslib": "^2.6.2", + "ws": "^8.14.2" }, "engines": { - "node": ">= 6.0.0" + "node": ">=16.11.0" } }, - "node_modules/agent-base/node_modules/debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", - "devOptional": true, - "dependencies": { - "ms": "2.1.2" - }, + "node_modules/@discordjs/ws/node_modules/@discordjs/collection": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-2.0.0.tgz", + "integrity": "sha512-YTWIXLrf5FsrLMycpMM9Q6vnZoR/lN2AWX23/Cuo8uOOtS8eHB2dyQaaGnaF8aZPYnttf2bkLMcXn/j6JUOi3w==", "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "node": ">=18" } }, - "node_modules/agent-base/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "devOptional": true + "node_modules/@discordjs/ws/node_modules/discord-api-types": { + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" }, - "node_modules/ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "devOptional": true, + "node_modules/@esbuild/darwin-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.20.tgz", + "integrity": "sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/aproba": { + "node_modules/@fastify/busboy": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", - "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==", - "devOptional": true - }, - "node_modules/are-we-there-yet": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", - "devOptional": true, - "dependencies": { - "delegates": "^1.0.0", - "readable-stream": "^2.0.6" + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz", + "integrity": "sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==", + "engines": { + "node": ">=14" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + "node_modules/@sapphire/async-queue": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.0.tgz", + "integrity": "sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==", + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" + } }, - "node_modules/axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "node_modules/@sapphire/shapeshift": { + "version": "3.9.3", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.9.3.tgz", + "integrity": "sha512-WzKJSwDYloSkHoBbE8rkRW8UNKJiSRJ/P8NqJ5iVq7U2Yr/kriIBx2hW+wj2Z5e5EnXL1hgYomgaFsdK6b+zqQ==", "dependencies": { - "follow-redirects": "^1.14.0" + "fast-deep-equal": "^3.1.3", + "lodash": "^4.17.21" + }, + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" } }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "devOptional": true - }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "dev": true, - "dependencies": { - "file-uri-to-path": "1.0.0" + "node_modules/@sapphire/snowflake": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.5.1.tgz", + "integrity": "sha512-BxcYGzgEsdlG0dKAyOm0ehLGm2CafIrfQTZGWgkfKYbj+pNNsorZ7EotuZukc2MT70E0UbppVbtpBrqpzVzjNA==", + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" } }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "devOptional": true, + "node_modules/@types/node": { + "version": "18.11.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", + "integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==" + }, + "node_modules/@types/ws": { + "version": "8.5.9", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.9.tgz", + "integrity": "sha512-jbdrY0a8lxfdTp/+r7Z4CkycbOFN8WX+IOchLJr3juT/xzbJ8URyTVSJ/hvNdadTgM1mnedb47n+Y31GsFnQlg==", "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "@types/node": "*" } }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "devOptional": true - }, - "node_modules/callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "node_modules/@vladfrangu/async_event_emitter": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@vladfrangu/async_event_emitter/-/async_event_emitter-2.2.2.tgz", + "integrity": "sha512-HIzRG7sy88UZjBJamssEczH5q7t5+axva19UbZLO6u0ySbYPrwzWiXBcC0WuHyhKKoeCyneH+FvYzKQq/zTtkQ==", "engines": { - "node": ">=6" + "node": ">=v14.0.0", + "npm": ">=7.0.0" } }, - "node_modules/caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "devOptional": true + "node_modules/ansi-align": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", + "integrity": "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==", + "dev": true, + "dependencies": { + "string-width": "^4.1.0" + } }, - "node_modules/chownr": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", - "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", - "devOptional": true, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, "engines": { - "node": ">=10" + "node": ">=8" } }, - "node_modules/color-support": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", - "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", - "devOptional": true, - "bin": { - "color-support": "bin.js" + "node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "node_modules/aoi.js-library": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/aoi.js-library/-/aoi.js-library-2.0.2.tgz", + "integrity": "sha512-jUzFMFGUoam1SeCY73wNBpXYLdwoP7hzTMKc8ZYe4jKrvOmVBqKh/c0hCxcAszw1i8eAiwiRuD0V4ejrd8Peqg==", + "dev": true, "dependencies": { - "delayed-stream": "~1.0.0" + "boxen": "^7.1.1", + "chalk": "^5.3.0", + "esbuild": "^0.18.14", + "ora": "^6.3.1", + "undici": "^5.18.0" + }, + "bin": { + "aoilib": "bin/index.mjs" }, "engines": { - "node": ">= 0.8" + "node": ">=18.x" } }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "devOptional": true - }, - "node_modules/concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "devOptional": true, - "engines": [ - "node >= 0.8" - ], - "dependencies": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" + "node_modules/aoi.js-library/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/console-control-strings": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "devOptional": true + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] }, - "node_modules/core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "devOptional": true - }, - "node_modules/cross-fetch": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz", - "integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==", + "node_modules/bl": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-5.1.0.tgz", + "integrity": "sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==", + "dev": true, "dependencies": { - "node-fetch": "2.6.1" + "buffer": "^6.0.3", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" } }, - "node_modules/dbdjs.db": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/dbdjs.db/-/dbdjs.db-2.0.1.tgz", - "integrity": "sha512-sCglI46PTqO28keHe4uvBmQc+YtZXTCXB9TUgvf5sNS4B/y6hoCSCqYQfjZZJj5wHwsmLQb2rhcZJyvpLyfpAg==", + "node_modules/boxen": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/boxen/-/boxen-7.1.1.tgz", + "integrity": "sha512-2hCgjEmP8YLWQ130n2FerGv7rYpfBmnmp9Uy2Le1vge6X3gZIfSmEzP5QTDElFxcvVcXlEn8Aq6MU/PZygIOog==", + "dev": true, "dependencies": { - "fs": "0.0.1-security" + "ansi-align": "^3.0.1", + "camelcase": "^7.0.1", + "chalk": "^5.2.0", + "cli-boxes": "^3.0.0", + "string-width": "^5.1.2", + "type-fest": "^2.13.0", + "widest-line": "^4.0.1", + "wrap-ansi": "^8.1.0" }, "engines": { - "node": ">=12.11.0" + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "node_modules/boxen/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { - "node": ">=0.4.0" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/delegates": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", - "devOptional": true - }, - "node_modules/detect-libc": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", - "devOptional": true, - "bin": { - "detect-libc": "bin/detect-libc.js" - }, + "node_modules/boxen/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, "engines": { - "node": ">=0.10" + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/discord-api-types": { - "version": "0.22.0", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.22.0.tgz", - "integrity": "sha512-l8yD/2zRbZItUQpy7ZxBJwaLX/Bs2TGaCthRppk8Sw24LOIWg12t9JEreezPoYD0SQcC2htNNo27kYEpYW/Srg==", + "node_modules/boxen/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true + }, + "node_modules/boxen/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, "engines": { "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/discord.js": { - "version": "13.2.0", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.2.0.tgz", - "integrity": "sha512-nyxUvL8wuQG38zx13wUMkpcA8koFszyiXdkSLwwM9opKW2LC2H5gD0cTZxImeJ6GtEnKPWT8xBiE8lLBmbNIhw==", + "node_modules/boxen/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { - "@discordjs/builders": "^0.6.0", - "@discordjs/collection": "^0.2.1", - "@discordjs/form-data": "^3.0.1", - "@sapphire/async-queue": "^1.1.5", - "@types/ws": "^8.2.0", - "discord-api-types": "^0.23.1", - "node-fetch": "^2.6.1", - "ws": "^8.2.3" + "ansi-regex": "^6.0.1" }, "engines": { - "node": ">=16.6.0", - "npm": ">=7.0.0" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, - "node_modules/discord.js/node_modules/@types/ws": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.0.tgz", - "integrity": "sha512-cyeefcUCgJlEk+hk2h3N+MqKKsPViQgF5boi9TTHSK+PoR9KWBb/C5ccPcDyAqgsbAYHTwulch725DV84+pSpg==", + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], "dependencies": { - "@types/node": "*" + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" } }, - "node_modules/discord.js/node_modules/discord-api-types": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.23.1.tgz", - "integrity": "sha512-igWmn+45mzXRWNEPU25I/pr8MwxHb767wAr51oy3VRLRcTlp5ADBbrBR0lq3SA1Rfw3MtM4TQu1xo3kxscfVdQ==", + "node_modules/camelcase": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-7.0.1.tgz", + "integrity": "sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw==", + "dev": true, "engines": { - "node": ">=12" + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/discord.js/node_modules/ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==", - "engines": { - "node": ">=10.0.0" + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "engines": { + "node": ">=10" }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/dot-prop": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", - "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "node_modules/chalk/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dependencies": { - "is-obj": "^2.0.0" + "color-convert": "^2.0.1" }, "engines": { - "node": ">=10" + "node": ">=8" }, "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/dotenv": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", - "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", "engines": { "node": ">=10" } }, - "node_modules/env-paths": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", - "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==", - "devOptional": true, + "node_modules/cli-boxes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-3.0.0.tgz", + "integrity": "sha512-/lzGpEWL/8PfI0BmBOPRwp0c/wFNX1RdUML3jK/RcSBA9T8mZDdQpqYBKtCFTOfQbwPqWEOpjqW+Fnayc0969g==", + "dev": true, "engines": { - "node": ">=6" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/ffmpeg-static": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/ffmpeg-static/-/ffmpeg-static-4.4.0.tgz", - "integrity": "sha512-NIJHVPXlSsIK9pYvsTPh4ZlppauorpPLLeOaIG7VOXWQck4Fx4Qi7Ahe+j8mj8KZXhWwCg3Hx46JdWAIOWLcpg==", - "devOptional": true, - "hasInstallScript": true, + "node_modules/cli-cursor": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", + "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", + "dev": true, "dependencies": { - "@derhuerst/http-basic": "^8.2.0", - "env-paths": "^2.2.0", - "https-proxy-agent": "^5.0.0", - "progress": "^2.0.3" + "restore-cursor": "^4.0.0" }, "engines": { - "node": ">=10" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "dev": true - }, - "node_modules/follow-redirects": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.2.tgz", - "integrity": "sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], + "node_modules/cli-spinners": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.0.tgz", + "integrity": "sha512-4/aL9X3Wh0yiMQlE+eeRhWP6vclO3QRtw1JHKIT0FFUs5FjpFmESqtMvYZ0+lbzBw900b95mS0hohy+qn2VK/g==", + "dev": true, "engines": { - "node": ">=4.0" + "node": ">=6" }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/fs": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", - "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" - }, - "node_modules/fs-minipass": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", - "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "devOptional": true, - "dependencies": { - "minipass": "^3.0.0" - }, + "node_modules/clone": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", + "dev": true, "engines": { - "node": ">= 8" + "node": ">=0.8" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "devOptional": true - }, - "node_modules/gauge": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.1.tgz", - "integrity": "sha512-6STz6KdQgxO4S/ko+AbjlFGGdGcknluoqU+79GOFCDqqyYj5OanQf9AjxwN0jCidtT+ziPMmPSt9E4hfQ0CwIQ==", - "devOptional": true, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dependencies": { - "aproba": "^1.0.3 || ^2.0.0", - "color-support": "^1.1.2", - "console-control-strings": "^1.0.0", - "has-unicode": "^2.0.1", - "object-assign": "^4.1.1", - "signal-exit": "^3.0.0", - "string-width": "^1.0.1 || ^2.0.0", - "strip-ansi": "^3.0.1 || ^4.0.0", - "wide-align": "^1.1.2" + "color-name": "~1.1.4" }, "engines": { - "node": ">=10" + "node": ">=7.0.0" } }, - "node_modules/glob": { - "version": "7.1.7", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", - "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", - "devOptional": true, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "node_modules/defaults": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz", + "integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==", + "dev": true, "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" + "clone": "^1.0.2" }, "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/has-unicode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", - "devOptional": true - }, - "node_modules/himalaya": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/himalaya/-/himalaya-1.1.0.tgz", - "integrity": "sha512-LLase1dHCRMel68/HZTFft0N0wti0epHr3nNY7ynpLbyZpmrKMQ8YIpiOV77TM97cNpC8Wb2n6f66IRggwdWPw==" - }, - "node_modules/http-response-object": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.2.tgz", - "integrity": "sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==", - "devOptional": true, - "dependencies": { - "@types/node": "^10.0.3" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/http-response-object/node_modules/@types/node": { - "version": "10.17.60", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", - "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==", - "devOptional": true + "node_modules/discord-api-types": { + "version": "0.37.65", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.65.tgz", + "integrity": "sha512-CQHW3Nu04LEHIj1Xps/sfGhTdrowilxnek2tirpLhwvrmgmLr1C6A+4JFLs+0kJMH2IX2QgDyA9GfNehqN+xPQ==", + "dev": true }, - "node_modules/https-proxy-agent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", - "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", - "devOptional": true, + "node_modules/discord.js": { + "version": "14.14.1", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.14.1.tgz", + "integrity": "sha512-/hUVzkIerxKHyRKopJy5xejp4MYKDPTszAnpYxzVVv4qJYf+Tkt+jnT2N29PIPschicaEEpXwF2ARrTYHYwQ5w==", "dependencies": { - "agent-base": "6", - "debug": "4" + "@discordjs/builders": "^1.7.0", + "@discordjs/collection": "1.5.3", + "@discordjs/formatters": "^0.3.3", + "@discordjs/rest": "^2.1.0", + "@discordjs/util": "^1.0.2", + "@discordjs/ws": "^1.0.2", + "@sapphire/snowflake": "3.5.1", + "@types/ws": "8.5.9", + "discord-api-types": "0.37.61", + "fast-deep-equal": "3.1.3", + "lodash.snakecase": "4.1.1", + "tslib": "2.6.2", + "undici": "5.27.2", + "ws": "8.14.2" }, "engines": { - "node": ">= 6" + "node": ">=16.11.0" } }, - "node_modules/https-proxy-agent/node_modules/debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", - "devOptional": true, + "node_modules/discord.js/node_modules/discord-api-types": { + "version": "0.37.61", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.61.tgz", + "integrity": "sha512-o/dXNFfhBpYHpQFdT6FWzeO7pKc838QeeZ9d91CfVAtpr5XLK4B/zYxQbYgPdoMiTDvJfzcsLW5naXgmHGDNXw==" + }, + "node_modules/discord.js/node_modules/undici": { + "version": "5.27.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.27.2.tgz", + "integrity": "sha512-iS857PdOEy/y3wlM3yRp+6SNQQ6xU0mmZcwRSriqk+et/cwWAtwmIGf6WkoDN2EK/AMdCO/dfXzIwi+rFMrjjQ==", "dependencies": { - "ms": "2.1.2" + "@fastify/busboy": "^2.0.0" }, "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "node": ">=14.0" } }, - "node_modules/https-proxy-agent/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "devOptional": true - }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "devOptional": true, - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "devOptional": true + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true }, - "node_modules/is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "devOptional": true, + "node_modules/esbuild": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.20.tgz", + "integrity": "sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, "engines": { - "node": ">=4" - } + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.18.20", + "@esbuild/android-arm64": "0.18.20", + "@esbuild/android-x64": "0.18.20", + "@esbuild/darwin-arm64": "0.18.20", + "@esbuild/darwin-x64": "0.18.20", + "@esbuild/freebsd-arm64": "0.18.20", + "@esbuild/freebsd-x64": "0.18.20", + "@esbuild/linux-arm": "0.18.20", + "@esbuild/linux-arm64": "0.18.20", + "@esbuild/linux-ia32": "0.18.20", + "@esbuild/linux-loong64": "0.18.20", + "@esbuild/linux-mips64el": "0.18.20", + "@esbuild/linux-ppc64": "0.18.20", + "@esbuild/linux-riscv64": "0.18.20", + "@esbuild/linux-s390x": "0.18.20", + "@esbuild/linux-x64": "0.18.20", + "@esbuild/netbsd-x64": "0.18.20", + "@esbuild/openbsd-x64": "0.18.20", + "@esbuild/sunos-x64": "0.18.20", + "@esbuild/win32-arm64": "0.18.20", + "@esbuild/win32-ia32": "0.18.20", + "@esbuild/win32-x64": "0.18.20" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, - "node_modules/is-obj": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", - "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "dependencies": { + "minipass": "^3.0.0" + }, "engines": { - "node": ">=8" + "node": ">= 8" } }, - "node_modules/isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "devOptional": true - }, - "node_modules/lavacoffee": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/lavacoffee/-/lavacoffee-1.3.0.tgz", - "integrity": "sha512-oDe9w7zJQjmXW6UxAwadj3hWlJvWrVH6g5dhwBXnCtKCwmctDzxE+Cy6XBrLkaJr9z0G0Ep6b9o8D547P0AjCA==", - "dependencies": { - "tiny-typed-emitter": "^2.1.0", - "undici": "^4.9.3", - "ws": "^8.2.3" + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" } }, - "node_modules/lavacoffee/node_modules/ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==", - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" }, - "utf-8-validate": { - "optional": true + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" } - } + ] }, - "node_modules/lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, - "node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "devOptional": true, - "dependencies": { - "yallist": "^4.0.0" - }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, "engines": { - "node": ">=10" + "node": ">=8" } }, - "node_modules/m3u8stream": { - "version": "0.8.4", - "resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.4.tgz", - "integrity": "sha512-sco80Db+30RvcaIOndenX6E6oQNgTiBKeJbFPc+yDXwPQIkryfboEbCvXPlBRq3mQTCVPQO93TDVlfRwqpD35w==", - "dependencies": { - "miniget": "^4.0.0", - "sax": "^1.2.4" - }, + "node_modules/is-interactive": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", + "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", + "dev": true, "engines": { - "node": ">=10" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "devOptional": true, - "dependencies": { - "semver": "^6.0.0" - }, + "node_modules/is-unicode-supported": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", + "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", + "dev": true, "engines": { - "node": ">=8" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/make-dir/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "devOptional": true, + "node_modules/jsonrepair": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-3.5.0.tgz", + "integrity": "sha512-SavvDsUP9Xnqo2MoC6Wl6zNyX3f+I5199hRbXBtAITyP2NTPyAgyx5xM0bgcIljRjzsIvOBANbgfWe8XXlyeLA==", "bin": { - "semver": "bin/semver.js" + "jsonrepair": "bin/cli.js" } }, - "node_modules/mime-db": { - "version": "1.49.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz", - "integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==", - "engines": { - "node": ">= 0.6" - } + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "node_modules/lodash.snakecase": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", + "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==" }, - "node_modules/mime-types": { - "version": "2.1.32", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz", - "integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==", + "node_modules/log-symbols": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-5.1.0.tgz", + "integrity": "sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA==", + "dev": true, "dependencies": { - "mime-db": "1.49.0" + "chalk": "^5.0.0", + "is-unicode-supported": "^1.1.0" }, "engines": { - "node": ">= 0.6" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/miniget": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.1.tgz", - "integrity": "sha512-O/DduzDR6f+oDtVype9S/Qu5hhnx73EDYGyZKwU/qN82lehFZdfhoa4DT51SpsO+8epYrB3gcRmws56ROfTIoQ==", + "node_modules/log-symbols/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, "engines": { - "node": ">=10" + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "devOptional": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, + "node_modules/magic-bytes.js": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.5.0.tgz", + "integrity": "sha512-wJkXvutRbNWcc37tt5j1HyOK1nosspdh3dj6LUYYAvF6JYNqs53IfRvK9oEpcwiDA1NdoIi64yAMfdivPeVAyw==" + }, + "node_modules/mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true, "engines": { - "node": "*" + "node": ">=6" } }, "node_modules/minipass": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz", - "integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==", - "devOptional": true, + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", "dependencies": { "yallist": "^4.0.0" }, @@ -846,7 +834,6 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", - "devOptional": true, "dependencies": { "minipass": "^3.0.0", "yallist": "^4.0.0" @@ -859,7 +846,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "devOptional": true, "bin": { "mkdirp": "bin/cmd.js" }, @@ -867,1470 +853,456 @@ "node": ">=10" } }, - "node_modules/nan": { - "version": "2.15.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", - "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==", - "dev": true - }, - "node_modules/node-addon-api": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", - "integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==", - "devOptional": true - }, - "node_modules/node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", - "engines": { - "node": "4.x || >=6.0.0" - } - }, - "node_modules/nopt": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", - "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", - "devOptional": true, + "node_modules/onetime": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "dev": true, "dependencies": { - "abbrev": "1" - }, - "bin": { - "nopt": "bin/nopt.js" + "mimic-fn": "^2.1.0" }, "engines": { "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/npmlog": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.0.tgz", - "integrity": "sha512-ftpIiLjerL2tUg3dCqN8pOSoB90gqZlzv/gaZoxHaKjeLClrfJIEQ1Pdxi6qSzflz916Bljdy8dTWQ4J7hAFSQ==", - "devOptional": true, + "node_modules/ora": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/ora/-/ora-6.3.1.tgz", + "integrity": "sha512-ERAyNnZOfqM+Ao3RAvIXkYh5joP220yf59gVe2X/cI6SiCxIdi4c9HZKZD8R6q/RDXEje1THBju6iExiSsgJaQ==", + "dev": true, "dependencies": { - "are-we-there-yet": "^1.1.5", - "console-control-strings": "^1.1.0", - "gauge": "^3.0.0", - "set-blocking": "^2.0.0" + "chalk": "^5.0.0", + "cli-cursor": "^4.0.0", + "cli-spinners": "^2.6.1", + "is-interactive": "^2.0.0", + "is-unicode-supported": "^1.1.0", + "log-symbols": "^5.1.0", + "stdin-discarder": "^0.1.0", + "strip-ansi": "^7.0.1", + "wcwidth": "^1.0.1" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "devOptional": true, + "node_modules/ora/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { - "node": ">=0.10.0" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "devOptional": true, - "dependencies": { - "wrappy": "1" + "node_modules/ora/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/ow": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/ow/-/ow-0.27.0.tgz", - "integrity": "sha512-SGnrGUbhn4VaUGdU0EJLMwZWSupPmF46hnTRII7aCLCrqixTAC5eKo8kI4/XXf1eaaI8YEVT+3FeGNJI9himAQ==", + "node_modules/ora/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { - "@sindresorhus/is": "^4.0.1", - "callsites": "^3.1.0", - "dot-prop": "^6.0.1", - "lodash.isequal": "^4.5.0", - "type-fest": "^1.2.1", - "vali-date": "^1.0.0" + "ansi-regex": "^6.0.1" }, "engines": { "node": ">=12" }, "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/parse-cache-control": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz", - "integrity": "sha1-juqz5U+laSD+Fro493+iGqzC104=", - "devOptional": true - }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "devOptional": true, - "engines": { - "node": ">=0.10.0" + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, "node_modules/prettier": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", - "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.0.tgz", + "integrity": "sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/prism-media": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.2.tgz", - "integrity": "sha512-L6UsGHcT6i4wrQhFF1aPK+MNYgjRqR2tUoIqEY+CG1NqVkMjPRKzS37j9f8GiYPlD6wG9ruBj+q5Ax+bH8Ik1g==", - "peerDependencies": { - "@discordjs/opus": "^0.5.0", - "ffmpeg-static": "^4.2.7 || ^3.0.0 || ^2.4.0", - "node-opus": "^0.3.3", - "opusscript": "^0.0.8" + "node": ">=14" }, - "peerDependenciesMeta": { - "@discordjs/opus": { - "optional": true - }, - "ffmpeg-static": { - "optional": true - }, - "node-opus": { - "optional": true - }, - "opusscript": { - "optional": true - } + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } }, - "node_modules/process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "devOptional": true - }, - "node_modules/progress": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", - "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", - "devOptional": true, + "node_modules/readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, "engines": { - "node": ">=0.4.0" + "node": ">= 6" } }, - "node_modules/readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "devOptional": true, - "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "node_modules/regenerator-runtime": { - "version": "0.13.9", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz", - "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==" - }, - "node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "devOptional": true, + "node_modules/restore-cursor": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", + "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", + "dev": true, "dependencies": { - "glob": "^7.1.3" + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" }, - "bin": { - "rimraf": "bin.js" + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "funding": { - "url": "https://github.com/sponsors/isaacs" + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "devOptional": true + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] }, - "node_modules/sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true }, - "node_modules/segfault-handler": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/segfault-handler/-/segfault-handler-1.3.0.tgz", - "integrity": "sha512-p7kVHo+4uoYkr0jmIiTBthwV5L2qmWtben/KDunDZ834mbos+tY+iO0//HpAJpOFSQZZ+wxKWuRo4DxV02B7Lg==", + "node_modules/stdin-discarder": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.1.0.tgz", + "integrity": "sha512-xhV7w8S+bUwlPTb4bAOUQhv8/cSS5offJuX8GQGq32ONF0ZtDWKfkdomM3HMRA+LhX6um/FZ0COqlwsjD53LeQ==", "dev": true, - "hasInstallScript": true, - "dependencies": { - "bindings": "^1.2.1", - "nan": "^2.14.0" - } - }, - "node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "devOptional": true, "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" + "bl": "^5.0.0" }, "engines": { - "node": ">=10" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "devOptional": true - }, - "node_modules/signal-exit": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", - "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", - "devOptional": true - }, - "node_modules/soundcloud-downloader": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/soundcloud-downloader/-/soundcloud-downloader-1.0.0.tgz", - "integrity": "sha512-UaEGaO+NASmTKJduGGgFjWVixLKFbvkxuX1oIYseZCsdEAg4q3o+Zn5Q9NWjQ1y0QciPkhEDnS22wnPb3XZ7pw==", + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dev": true, "dependencies": { - "@babel/runtime": "^7.10.3", - "axios": "^0.21.0", - "dotenv": "^8.2.0", - "m3u8stream": "^0.8.0", - "soundcloud-key-fetch": "^1.0.10" - } - }, - "node_modules/soundcloud-key-fetch": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/soundcloud-key-fetch/-/soundcloud-key-fetch-1.0.11.tgz", - "integrity": "sha512-ofnXB3yeHGVKnFKEMBP/kIJzGu1SduQzJc+zmkPbKgelvYNsEU/aTGD0PlhmyZquaCkTGByF8CEPRrAnt7ki4g==" - }, - "node_modules/spotify-uri": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/spotify-uri/-/spotify-uri-2.2.0.tgz", - "integrity": "sha512-uUybj02bfyfCoZ0MJ80MkqbKxtIVRJfbRGk05KJFq1li3zb7yNfN1f+TAw4wcXgp7jLWExeiw2wyPQXZ8PHtfg==", - "engines": { - "node": ">= 6" + "safe-buffer": "~5.2.0" } }, - "node_modules/spotify-url-info": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/spotify-url-info/-/spotify-url-info-2.2.3.tgz", - "integrity": "sha512-cZTE5nOnaAjIiaHG9psVYqKXWOlNUIgSU2e+bNInRaYZNgmVgOcKH0D7V1nSER3gv3h5BXvOo0EJTtrMQQo1bA==", + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, "dependencies": { - "cross-fetch": "~3.1.4", - "himalaya": "~1.1.0", - "spotify-uri": "~2.2.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" }, "engines": { - "node": ">= 12" - } - }, - "node_modules/string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "devOptional": true, - "dependencies": { - "safe-buffer": "~5.1.0" + "node": ">=8" } }, - "node_modules/string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "devOptional": true, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" + "ansi-regex": "^5.0.1" }, "engines": { - "node": ">=4" + "node": ">=8" } }, - "node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "devOptional": true, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dependencies": { - "ansi-regex": "^3.0.0" + "has-flag": "^4.0.0" }, "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/tar": { - "version": "6.1.10", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.10.tgz", - "integrity": "sha512-kvvfiVvjGMxeUNB6MyYv5z7vhfFRwbwCXJAeL0/lnbrttBVqcMOnpHUf0X42LrPMR8mMpgapkJMchFH4FSHzNA==", - "devOptional": true, + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz", + "integrity": "sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==", "dependencies": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", - "minipass": "^3.0.0", + "minipass": "^5.0.0", "minizlib": "^2.1.1", "mkdirp": "^1.0.3", "yallist": "^4.0.0" }, "engines": { - "node": ">= 10" + "node": ">=10" } }, - "node_modules/tiny-typed-emitter": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz", - "integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==" + "node_modules/tar/node_modules/minipass": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", + "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", + "engines": { + "node": ">=8" + } }, "node_modules/ts-mixer": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.0.tgz", - "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.3.tgz", + "integrity": "sha512-k43M7uCG1AkTyxgnmI5MPwKoUvS/bRvLvUb7+Pgpdlmok8AoqmUaZxUUw8zKM5B1lqZrt41GjYgnvAi0fppqgQ==" }, "node_modules/tslib": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", - "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" - }, - "node_modules/tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", - "dev": true + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "node_modules/type-fest": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", - "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==", + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "dev": true, "engines": { - "node": ">=10" + "node": ">=12.20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "devOptional": true + "node_modules/typescript": { + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", + "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } }, "node_modules/undici": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/undici/-/undici-4.9.5.tgz", - "integrity": "sha512-t59IFVYiMnFThboJL9izqwsDEfSbZDPZ/8iCYBCkEFLy63x9m4YaNt0E+r5+X993syC9M0W/ksusZC9YuAamMg==", + "version": "5.28.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.2.tgz", + "integrity": "sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, "engines": { - "node": ">=12.18" + "node": ">=14.0" } }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "devOptional": true + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "dev": true }, - "node_modules/vali-date": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/vali-date/-/vali-date-1.0.0.tgz", - "integrity": "sha1-G5BKWWCfsyjvB4E4Qgk09rhnCaY=", - "engines": { - "node": ">=0.10.0" + "node_modules/wcwidth": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", + "integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==", + "dev": true, + "dependencies": { + "defaults": "^1.0.3" } }, - "node_modules/wide-align": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", - "devOptional": true, + "node_modules/widest-line": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-4.0.1.tgz", + "integrity": "sha512-o0cyEG0e8GPzT4iGHphIOh0cJOV8fivsXxddQasHPHfoZf1ZexrfeA21w2NaEN1RHE+fXlfISmOE8R9N3u3Qig==", + "dev": true, "dependencies": { - "string-width": "^1.0.2 || 2" + "string-width": "^5.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/workerpool": { - "version": "6.1.5", - "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.5.tgz", - "integrity": "sha512-XdKkCK0Zqc6w3iTxLckiuJ81tiD/o5rBE/m+nXpRCB+/Sq4DqkfXZ/x0jW02DG1tGsfUGXbTJyZDP+eu67haSw==", - "dev": true - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "devOptional": true - }, - "node_modules/ws": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", - "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", + "node_modules/widest-line/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { - "node": ">=8.3.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "node": ">=12" }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "devOptional": true + "node_modules/widest-line/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true }, - "node_modules/youtube-sr": { - "version": "4.1.7", - "resolved": "https://registry.npmjs.org/youtube-sr/-/youtube-sr-4.1.7.tgz", - "integrity": "sha512-OKbm+561Fq5RlnUtJBmPhnyfS6Zon44zdPhY1v/Y9vpAHzqdfxomD43yc0ZQv6zNsVzSlAkGeWhoweNd6DUUjQ==", + "node_modules/widest-line/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, "dependencies": { - "node-fetch": "^2.6.1" + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/ytdl-core": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/ytdl-core/-/ytdl-core-4.9.1.tgz", - "integrity": "sha512-6Jbp5RDhUEozlaJQAR+l8oV8AHsx3WUXxSyPxzE6wOIAaLql7Hjiy0ZM58wZoyj1YEenlEPjEqcJIjKYKxvHtQ==", + "node_modules/widest-line/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { - "m3u8stream": "^0.8.3", - "miniget": "^4.0.0", - "sax": "^1.1.3" + "ansi-regex": "^6.0.1" }, "engines": { - "node": ">=10" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, - "node_modules/ytdl-core-discord": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/ytdl-core-discord/-/ytdl-core-discord-1.3.1.tgz", - "integrity": "sha512-KW8zYY35jRSkxZTEQtT9EiR2exFwYKhCE8QZbRg5Ge9a0YWDDhBOixSdWb8Cn41B1uHhz8FR15E4E/k0kHNX3w==", + "node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, "dependencies": { - "@types/node": "^15.12.2", - "prism-media": "^1.3.1", - "ytdl-core": "^4.8.2" - } - }, - "node_modules/ytdl-core-discord/node_modules/@types/node": { - "version": "15.14.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-15.14.8.tgz", - "integrity": "sha512-+ZjmmoGV7WBwhzNh/GkwehB7uyXn9HFwzQUfj9pbyR8eFAq20Qguoh93sPbWzzhsbhTme6YE92/iJ54Z0WRH7A==" - } - }, - "dependencies": { - "@babel/runtime": { - "version": "7.15.3", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.15.3.tgz", - "integrity": "sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA==", - "requires": { - "regenerator-runtime": "^0.13.4" - } - }, - "@derhuerst/http-basic": { - "version": "8.2.1", - "resolved": "https://registry.npmjs.org/@derhuerst/http-basic/-/http-basic-8.2.1.tgz", - "integrity": "sha512-Rmn7qQQulw2sxJ8qGfZ7OuqMWuhz8V+L5xnYKMF5cXVcYqmgWqlVEAme90pF7Ya8OVhxVxLmhh0rI2k6t7ITWw==", - "devOptional": true, - "requires": { - "caseless": "^0.12.0", - "concat-stream": "^1.6.2", - "http-response-object": "^3.0.1", - "parse-cache-control": "^1.0.1" - } - }, - "@discordjs/builders": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.6.0.tgz", - "integrity": "sha512-mH3Gx61LKk2CD05laCI9K5wp+a3NyASHDUGx83DGJFkqJlRlSV5WMJNY6RS37A5SjqDtGMF4wVR9jzFaqShe6Q==", - "requires": { - "@sindresorhus/is": "^4.0.1", - "discord-api-types": "^0.22.0", - "ow": "^0.27.0", - "ts-mixer": "^6.0.0", - "tslib": "^2.3.1" - } - }, - "@discordjs/collection": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.2.1.tgz", - "integrity": "sha512-vhxqzzM8gkomw0TYRF3tgx7SwElzUlXT/Aa41O7mOcyN6wIJfj5JmDWaO5XGKsGSsNx7F3i5oIlrucCCWV1Nog==" - }, - "@discordjs/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, - "@discordjs/node-pre-gyp": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@discordjs/node-pre-gyp/-/node-pre-gyp-0.4.1.tgz", - "integrity": "sha512-PLYLPG3R+m9QlMROOjdy2htQq54g6f9vRb1xPfZ97CL53yj0uNTfpB/jtY/AXY6OKNtZtrre5SKjei8Hcc44HQ==", - "devOptional": true, - "requires": { - "detect-libc": "^1.0.3", - "https-proxy-agent": "^5.0.0", - "make-dir": "^3.1.0", - "node-fetch": "^2.6.1", - "nopt": "^5.0.0", - "npmlog": "^5.0.0", - "rimraf": "^3.0.2", - "semver": "^7.3.5", - "tar": "^6.1.8" - } - }, - "@discordjs/opus": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/@discordjs/opus/-/opus-0.5.3.tgz", - "integrity": "sha512-IQhCwCy2WKXLe+qkOkwO1Wjgk20uqeAbqM62tCbzIqbTsXX4YAge8Me9RFnI77Lx+UTkgm4rSVM3VPVdS/GsUw==", - "devOptional": true, - "requires": { - "@discordjs/node-pre-gyp": "^0.4.0", - "node-addon-api": "^3.2.1" - } - }, - "@discordjs/voice": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/@discordjs/voice/-/voice-0.5.6.tgz", - "integrity": "sha512-CGwD5pz1YB8MXfERcXQ6jVCThfMjzPKbad8pYuvPt4ozFcLWGRKFJ5lj+CSRNDj0Cobc6MIKOKpFfOPlXTKTrw==", - "requires": { - "@types/ws": "^7.4.4", - "discord-api-types": "^0.22.0", - "prism-media": "^1.3.1", - "tiny-typed-emitter": "^2.0.3", - "ws": "^7.4.4" - } - }, - "@sapphire/async-queue": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.1.5.tgz", - "integrity": "sha512-NQ8GeTBeOkeAylVYTnO9zfEZO74iMNGCRrR3uIRnCrhkyPC+nsewyQtTamjSDWxXFTf+xGSJ9khiY2p56k/bMA==" - }, - "@sindresorhus/is": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.0.tgz", - "integrity": "sha512-VkE3KLBmJwcCaVARtQpfuKcKv8gcBmUubrfHGF84dXuuW6jgsRYxPtzcIhPyK9WAPpRt2/xY6zkD9MnRaJzSyw==" - }, - "@types/node": { - "version": "16.6.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.6.2.tgz", - "integrity": "sha512-LSw8TZt12ZudbpHc6EkIyDM3nHVWKYrAvGy6EAJfNfjusbwnThqjqxUKKRwuV3iWYeW/LYMzNgaq3MaLffQ2xA==" - }, - "@types/ws": { - "version": "7.4.7", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", - "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", - "requires": { - "@types/node": "*" - } - }, - "abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", - "devOptional": true - }, - "agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "devOptional": true, - "requires": { - "debug": "4" + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" }, - "dependencies": { - "debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", - "devOptional": true, - "requires": { - "ms": "2.1.2" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "devOptional": true - } + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "devOptional": true - }, - "aproba": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", - "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==", - "devOptional": true - }, - "are-we-there-yet": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", - "devOptional": true, - "requires": { - "delegates": "^1.0.0", - "readable-stream": "^2.0.6" - } - }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, - "axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", - "requires": { - "follow-redirects": "^1.14.0" - } - }, - "balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "devOptional": true - }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "node_modules/wrap-ansi/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", "dev": true, - "requires": { - "file-uri-to-path": "1.0.0" - } - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "devOptional": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "devOptional": true - }, - "callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" - }, - "caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "devOptional": true - }, - "chownr": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", - "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", - "devOptional": true - }, - "color-support": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", - "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", - "devOptional": true - }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "requires": { - "delayed-stream": "~1.0.0" - } - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "devOptional": true - }, - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "devOptional": true, - "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, - "console-control-strings": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "devOptional": true - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "devOptional": true - }, - "cross-fetch": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz", - "integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==", - "requires": { - "node-fetch": "2.6.1" - } - }, - "dbdjs.db": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/dbdjs.db/-/dbdjs.db-2.0.1.tgz", - "integrity": "sha512-sCglI46PTqO28keHe4uvBmQc+YtZXTCXB9TUgvf5sNS4B/y6hoCSCqYQfjZZJj5wHwsmLQb2rhcZJyvpLyfpAg==", - "requires": { - "fs": "0.0.1-security" - } - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, - "delegates": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", - "devOptional": true - }, - "detect-libc": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", - "devOptional": true - }, - "discord-api-types": { - "version": "0.22.0", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.22.0.tgz", - "integrity": "sha512-l8yD/2zRbZItUQpy7ZxBJwaLX/Bs2TGaCthRppk8Sw24LOIWg12t9JEreezPoYD0SQcC2htNNo27kYEpYW/Srg==" - }, - "discord.js": { - "version": "13.2.0", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.2.0.tgz", - "integrity": "sha512-nyxUvL8wuQG38zx13wUMkpcA8koFszyiXdkSLwwM9opKW2LC2H5gD0cTZxImeJ6GtEnKPWT8xBiE8lLBmbNIhw==", - "requires": { - "@discordjs/builders": "^0.6.0", - "@discordjs/collection": "^0.2.1", - "@discordjs/form-data": "^3.0.1", - "@sapphire/async-queue": "^1.1.5", - "@types/ws": "^8.2.0", - "discord-api-types": "^0.23.1", - "node-fetch": "^2.6.1", - "ws": "^8.2.3" + "engines": { + "node": ">=12" }, - "dependencies": { - "@types/ws": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.0.tgz", - "integrity": "sha512-cyeefcUCgJlEk+hk2h3N+MqKKsPViQgF5boi9TTHSK+PoR9KWBb/C5ccPcDyAqgsbAYHTwulch725DV84+pSpg==", - "requires": { - "@types/node": "*" - } - }, - "discord-api-types": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.23.1.tgz", - "integrity": "sha512-igWmn+45mzXRWNEPU25I/pr8MwxHb767wAr51oy3VRLRcTlp5ADBbrBR0lq3SA1Rfw3MtM4TQu1xo3kxscfVdQ==" - }, - "ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==", - "requires": {} - } + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "dot-prop": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", - "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", - "requires": { - "is-obj": "^2.0.0" - } - }, - "dotenv": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", - "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==" - }, - "env-paths": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", - "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==", - "devOptional": true - }, - "ffmpeg-static": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/ffmpeg-static/-/ffmpeg-static-4.4.0.tgz", - "integrity": "sha512-NIJHVPXlSsIK9pYvsTPh4ZlppauorpPLLeOaIG7VOXWQck4Fx4Qi7Ahe+j8mj8KZXhWwCg3Hx46JdWAIOWLcpg==", - "devOptional": true, - "requires": { - "@derhuerst/http-basic": "^8.2.0", - "env-paths": "^2.2.0", - "https-proxy-agent": "^5.0.0", - "progress": "^2.0.3" - } - }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "node_modules/wrap-ansi/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", "dev": true }, - "follow-redirects": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.2.tgz", - "integrity": "sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA==" - }, - "fs": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", - "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" - }, - "fs-minipass": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", - "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "devOptional": true, - "requires": { - "minipass": "^3.0.0" - } - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "devOptional": true - }, - "gauge": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.1.tgz", - "integrity": "sha512-6STz6KdQgxO4S/ko+AbjlFGGdGcknluoqU+79GOFCDqqyYj5OanQf9AjxwN0jCidtT+ziPMmPSt9E4hfQ0CwIQ==", - "devOptional": true, - "requires": { - "aproba": "^1.0.3 || ^2.0.0", - "color-support": "^1.1.2", - "console-control-strings": "^1.0.0", - "has-unicode": "^2.0.1", - "object-assign": "^4.1.1", - "signal-exit": "^3.0.0", - "string-width": "^1.0.1 || ^2.0.0", - "strip-ansi": "^3.0.1 || ^4.0.0", - "wide-align": "^1.1.2" - } - }, - "glob": { - "version": "7.1.7", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", - "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", - "devOptional": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "has-unicode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", - "devOptional": true - }, - "himalaya": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/himalaya/-/himalaya-1.1.0.tgz", - "integrity": "sha512-LLase1dHCRMel68/HZTFft0N0wti0epHr3nNY7ynpLbyZpmrKMQ8YIpiOV77TM97cNpC8Wb2n6f66IRggwdWPw==" - }, - "http-response-object": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.2.tgz", - "integrity": "sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==", - "devOptional": true, - "requires": { - "@types/node": "^10.0.3" - }, + "node_modules/wrap-ansi/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, "dependencies": { - "@types/node": { - "version": "10.17.60", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", - "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==", - "devOptional": true - } - } - }, - "https-proxy-agent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", - "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", - "devOptional": true, - "requires": { - "agent-base": "6", - "debug": "4" + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" }, - "dependencies": { - "debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", - "devOptional": true, - "requires": { - "ms": "2.1.2" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "devOptional": true - } - } - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "devOptional": true, - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "devOptional": true - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "devOptional": true - }, - "is-obj": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", - "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==" - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "devOptional": true - }, - "lavacoffee": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/lavacoffee/-/lavacoffee-1.3.0.tgz", - "integrity": "sha512-oDe9w7zJQjmXW6UxAwadj3hWlJvWrVH6g5dhwBXnCtKCwmctDzxE+Cy6XBrLkaJr9z0G0Ep6b9o8D547P0AjCA==", - "requires": { - "tiny-typed-emitter": "^2.1.0", - "undici": "^4.9.3", - "ws": "^8.2.3" + "engines": { + "node": ">=12" }, - "dependencies": { - "ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==", - "requires": {} - } - } - }, - "lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "devOptional": true, - "requires": { - "yallist": "^4.0.0" + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "m3u8stream": { - "version": "0.8.4", - "resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.8.4.tgz", - "integrity": "sha512-sco80Db+30RvcaIOndenX6E6oQNgTiBKeJbFPc+yDXwPQIkryfboEbCvXPlBRq3mQTCVPQO93TDVlfRwqpD35w==", - "requires": { - "miniget": "^4.0.0", - "sax": "^1.2.4" + "node_modules/wrap-ansi/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, - "make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "devOptional": true, - "requires": { - "semver": "^6.0.0" + "node_modules/ws": { + "version": "8.14.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz", + "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==", + "engines": { + "node": ">=10.0.0" }, - "dependencies": { - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "devOptional": true + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true } } }, - "mime-db": { - "version": "1.49.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz", - "integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==" - }, - "mime-types": { - "version": "2.1.32", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz", - "integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==", - "requires": { - "mime-db": "1.49.0" - } - }, - "miniget": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/miniget/-/miniget-4.2.1.tgz", - "integrity": "sha512-O/DduzDR6f+oDtVype9S/Qu5hhnx73EDYGyZKwU/qN82lehFZdfhoa4DT51SpsO+8epYrB3gcRmws56ROfTIoQ==" - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "devOptional": true, - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "minipass": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz", - "integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==", - "devOptional": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "minizlib": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", - "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", - "devOptional": true, - "requires": { - "minipass": "^3.0.0", - "yallist": "^4.0.0" - } - }, - "mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "devOptional": true - }, - "nan": { - "version": "2.15.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", - "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==", - "dev": true - }, - "node-addon-api": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", - "integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==", - "devOptional": true - }, - "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" - }, - "nopt": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", - "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", - "devOptional": true, - "requires": { - "abbrev": "1" - } - }, - "npmlog": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.0.tgz", - "integrity": "sha512-ftpIiLjerL2tUg3dCqN8pOSoB90gqZlzv/gaZoxHaKjeLClrfJIEQ1Pdxi6qSzflz916Bljdy8dTWQ4J7hAFSQ==", - "devOptional": true, - "requires": { - "are-we-there-yet": "^1.1.5", - "console-control-strings": "^1.1.0", - "gauge": "^3.0.0", - "set-blocking": "^2.0.0" - } - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "devOptional": true - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "devOptional": true, - "requires": { - "wrappy": "1" - } - }, - "ow": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/ow/-/ow-0.27.0.tgz", - "integrity": "sha512-SGnrGUbhn4VaUGdU0EJLMwZWSupPmF46hnTRII7aCLCrqixTAC5eKo8kI4/XXf1eaaI8YEVT+3FeGNJI9himAQ==", - "requires": { - "@sindresorhus/is": "^4.0.1", - "callsites": "^3.1.0", - "dot-prop": "^6.0.1", - "lodash.isequal": "^4.5.0", - "type-fest": "^1.2.1", - "vali-date": "^1.0.0" - } - }, - "parse-cache-control": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz", - "integrity": "sha1-juqz5U+laSD+Fro493+iGqzC104=", - "devOptional": true - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "devOptional": true - }, - "prettier": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", - "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", - "dev": true - }, - "prism-media": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.2.tgz", - "integrity": "sha512-L6UsGHcT6i4wrQhFF1aPK+MNYgjRqR2tUoIqEY+CG1NqVkMjPRKzS37j9f8GiYPlD6wG9ruBj+q5Ax+bH8Ik1g==", - "requires": {} - }, - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "devOptional": true - }, - "progress": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", - "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", - "devOptional": true - }, - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "devOptional": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "regenerator-runtime": { - "version": "0.13.9", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz", - "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==" - }, - "rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "devOptional": true, - "requires": { - "glob": "^7.1.3" - } - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "devOptional": true - }, - "sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" - }, - "segfault-handler": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/segfault-handler/-/segfault-handler-1.3.0.tgz", - "integrity": "sha512-p7kVHo+4uoYkr0jmIiTBthwV5L2qmWtben/KDunDZ834mbos+tY+iO0//HpAJpOFSQZZ+wxKWuRo4DxV02B7Lg==", - "dev": true, - "requires": { - "bindings": "^1.2.1", - "nan": "^2.14.0" - } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "devOptional": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, - "set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "devOptional": true - }, - "signal-exit": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", - "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", - "devOptional": true - }, - "soundcloud-downloader": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/soundcloud-downloader/-/soundcloud-downloader-1.0.0.tgz", - "integrity": "sha512-UaEGaO+NASmTKJduGGgFjWVixLKFbvkxuX1oIYseZCsdEAg4q3o+Zn5Q9NWjQ1y0QciPkhEDnS22wnPb3XZ7pw==", - "requires": { - "@babel/runtime": "^7.10.3", - "axios": "^0.21.0", - "dotenv": "^8.2.0", - "m3u8stream": "^0.8.0", - "soundcloud-key-fetch": "^1.0.10" - } - }, - "soundcloud-key-fetch": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/soundcloud-key-fetch/-/soundcloud-key-fetch-1.0.11.tgz", - "integrity": "sha512-ofnXB3yeHGVKnFKEMBP/kIJzGu1SduQzJc+zmkPbKgelvYNsEU/aTGD0PlhmyZquaCkTGByF8CEPRrAnt7ki4g==" - }, - "spotify-uri": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/spotify-uri/-/spotify-uri-2.2.0.tgz", - "integrity": "sha512-uUybj02bfyfCoZ0MJ80MkqbKxtIVRJfbRGk05KJFq1li3zb7yNfN1f+TAw4wcXgp7jLWExeiw2wyPQXZ8PHtfg==" - }, - "spotify-url-info": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/spotify-url-info/-/spotify-url-info-2.2.3.tgz", - "integrity": "sha512-cZTE5nOnaAjIiaHG9psVYqKXWOlNUIgSU2e+bNInRaYZNgmVgOcKH0D7V1nSER3gv3h5BXvOo0EJTtrMQQo1bA==", - "requires": { - "cross-fetch": "~3.1.4", - "himalaya": "~1.1.0", - "spotify-uri": "~2.2.0" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "devOptional": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "devOptional": true, - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "devOptional": true, - "requires": { - "ansi-regex": "^3.0.0" - } - }, - "tar": { - "version": "6.1.10", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.10.tgz", - "integrity": "sha512-kvvfiVvjGMxeUNB6MyYv5z7vhfFRwbwCXJAeL0/lnbrttBVqcMOnpHUf0X42LrPMR8mMpgapkJMchFH4FSHzNA==", - "devOptional": true, - "requires": { - "chownr": "^2.0.0", - "fs-minipass": "^2.0.0", - "minipass": "^3.0.0", - "minizlib": "^2.1.1", - "mkdirp": "^1.0.3", - "yallist": "^4.0.0" - } - }, - "tiny-typed-emitter": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz", - "integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==" - }, - "ts-mixer": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.0.tgz", - "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" - }, - "tslib": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", - "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" - }, - "tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", - "dev": true - }, - "type-fest": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", - "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==" - }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "devOptional": true - }, - "undici": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/undici/-/undici-4.9.5.tgz", - "integrity": "sha512-t59IFVYiMnFThboJL9izqwsDEfSbZDPZ/8iCYBCkEFLy63x9m4YaNt0E+r5+X993syC9M0W/ksusZC9YuAamMg==" - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "devOptional": true - }, - "vali-date": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/vali-date/-/vali-date-1.0.0.tgz", - "integrity": "sha1-G5BKWWCfsyjvB4E4Qgk09rhnCaY=" - }, - "wide-align": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", - "devOptional": true, - "requires": { - "string-width": "^1.0.2 || 2" - } - }, - "workerpool": { - "version": "6.1.5", - "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.5.tgz", - "integrity": "sha512-XdKkCK0Zqc6w3iTxLckiuJ81tiD/o5rBE/m+nXpRCB+/Sq4DqkfXZ/x0jW02DG1tGsfUGXbTJyZDP+eu67haSw==", - "dev": true - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "devOptional": true - }, - "ws": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", - "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", - "requires": {} - }, - "yallist": { + "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "devOptional": true - }, - "youtube-sr": { - "version": "4.1.7", - "resolved": "https://registry.npmjs.org/youtube-sr/-/youtube-sr-4.1.7.tgz", - "integrity": "sha512-OKbm+561Fq5RlnUtJBmPhnyfS6Zon44zdPhY1v/Y9vpAHzqdfxomD43yc0ZQv6zNsVzSlAkGeWhoweNd6DUUjQ==", - "requires": { - "node-fetch": "^2.6.1" - } - }, - "ytdl-core": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/ytdl-core/-/ytdl-core-4.9.1.tgz", - "integrity": "sha512-6Jbp5RDhUEozlaJQAR+l8oV8AHsx3WUXxSyPxzE6wOIAaLql7Hjiy0ZM58wZoyj1YEenlEPjEqcJIjKYKxvHtQ==", - "requires": { - "m3u8stream": "^0.8.3", - "miniget": "^4.0.0", - "sax": "^1.1.3" - } - }, - "ytdl-core-discord": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/ytdl-core-discord/-/ytdl-core-discord-1.3.1.tgz", - "integrity": "sha512-KW8zYY35jRSkxZTEQtT9EiR2exFwYKhCE8QZbRg5Ge9a0YWDDhBOixSdWb8Cn41B1uHhz8FR15E4E/k0kHNX3w==", - "requires": { - "@types/node": "^15.12.2", - "prism-media": "^1.3.1", - "ytdl-core": "^4.8.2" - }, - "dependencies": { - "@types/node": { - "version": "15.14.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-15.14.8.tgz", - "integrity": "sha512-+ZjmmoGV7WBwhzNh/GkwehB7uyXn9HFwzQUfj9pbyR8eFAq20Qguoh93sPbWzzhsbhTme6YE92/iJ54Z0WRH7A==" - } - } + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" } } } diff --git a/package.json b/package.json index 66f3898aa..d4b2d1595 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,22 @@ { "name": "aoi.js", - "version": "5.0.0-dev", - "description": "aoi.js - Library that simplifies coding for Developing your Discord Bot with built-in functions.", - "main": "package/index.js", - "typings": "package/index.d.ts", + "version": "6.7.0", + "description": "A powerful package to create Discord Bots with built-in string functions.", + "author": "Leref ", + "main": "src/index.js", + "typings": "src/index.d.ts", "scripts": { - "start": "node test.js", - "prettycheck": "prettier --check \"package/**/*.js\"", - "prettywrite": "prettier --write \"package/**/*.js\"" - }, - "dependencies": { - "@discordjs/voice": "^0.5.6", - "dbdjs.db": "^2.0.1", - "discord.js": "13.2.0", - "lavacoffee": "^1.3.0", - "soundcloud-downloader": "^1.0.0", - "spotify-url-info": "^2.2.0", - "youtube-sr": "^4.1.7", - "ytdl-core-discord": "^1.3.1" - }, - "devDependencies": { - "@discordjs/opus": "^0.5.0", - "axios": "^0.21.1", - "ffmpeg-static": "^4.3.0", - "m3u8stream": "^0.8.4", - "node-fetch": "^2.6.1", - "prettier": "~2.2.1", - "prism-media": "^1.2.7", - "segfault-handler": "^1.3.0", - "tweetnacl": "^1.0.3", - "workerpool": "^6.1.0", - "ws": "^7.4.6", - "ytdl-core": "^4.9.0" + "start": "node index.js", + "prettycheck": "prettier --check \"src/**/*.js\"", + "prettywrite": "prettier --write \"src/**/*.js\"" }, "engines": { - "node": ">=16.6" + "node": ">=16.11.0" }, "files": [ - "package" + "src", + "LICENSE", + "README.md" ], "license": "Apache-2.0", "licenses": [ @@ -46,9 +25,10 @@ "url": "https://www.apache.org/licenses/LICENSE-2.0" } ], + "homepage": "https://aoi.js.org", "repository": { "type": "git", - "url": "git+https://github.com/USERSATOSHI/aoi.js.git" + "url": "git+https://github.com/AkaruiDevelopment/aoi.js.git" }, "keywords": [ "aoi.js", @@ -56,12 +36,33 @@ "aoi", "api", "dbd.js", + "dbdjs", "dbd", "bot", + "akarui", + "functions", "music", + "aoi.music", + "aoi.panel", "bdfd", "Bot Designer for Discord", "discord", "discordbot" - ] + ], + "dependencies": { + "@akarui/aoi.db": "^2.1.0", + "@akarui/structures": "^1.0.2", + "chalk": "^4.1.2", + "discord.js": "^14.14.1", + "undici": "^5.28.2" + }, + "devDependencies": { + "aoi.js-library": "^2.0.2", + "discord-api-types": "^0.37.65", + "prettier": "^3.1.0", + "typescript": "^4.5.2", + "ws": "^8.3.0" + }, + "type": "commonjs", + "types": "./src/index.d.ts" } diff --git a/package/CacheHandler/group.js b/package/CacheHandler/group.js deleted file mode 100644 index d39eddd84..000000000 --- a/package/CacheHandler/group.js +++ /dev/null @@ -1,112 +0,0 @@ - -class Group extends Map { - constructor(prototype) { - super(prototype); - - } - set(key, value) { - - return super.set(key, value) - } - delete(key) { - return super.delete(key) - } - clear() { - - return super.clear() - } - top(number = 1) { - const top = Array.from(this.values()).slice(0, number) - return top.length <= 1 ? top[0] : top - } - bottom(number = 1) { - const arr = Array.from(this.values()).slice(`-${number}`) - return arr.length <= 1 ? arr[0] : arr - } - find(data) { - return Array.from(this.values()).find(data) - } - filter(data, limit = this.size) { - let keys = Array.from(this.keys()) - let values = Array.from(this.values()) - const filters = Array.from(this.values()).filter(data).slice(0, limit) - let grp = new Group() - filters.forEach(x => grp.set(keys[values.indexOf(x)], x)) - return grp - } - allKeys() { - return Array.from(this.keys()) - } - allValues() { - return Array.from(this.values()) - } - some(data) { - return Array.from(this.values()).some(data) - } - indexOf(key) { - return Array.from(this.keys()).indexOf(key) - } - findIndex(data) { - return Array.from(this.values()).findIndex(data) - } - includes(data) { - return this.allValues().includes(data) - } - object() { - let keys = this.allKeys() - let values = this.allValues() - let object = {} - keys.forEach(x => object[x] = values[keys.indexOf(x)]) - return object - } - map(data) { - return this.allValues().map(data) - } - findKey(data) { - const value = this.allValues().find(data) - const key = this.allKeys()[this.allValues().indexOf(value)] - return key - } - sort(data) { - let grp = new Group() - let sorter = this.allValues().sort(data) - sorter.forEach(x => grp.set(this.findKey(y => y === x), x)) - return grp - } - every(data) { - this.allValues.every(data) - } - partition(data) { - let grp1 = this.filter(data) - let grp2 = new Group(this) - grp1.allKeys().forEach(x => grp2.delete(x)) - return [grp1, grp2] - } - getByPosition(index) { - let grp = new Group() - const key = this.allKeys()[index - 1] - grp.set(key, this.get(key)) - return grp - } - reverse() { - return this.allValues().reverse() - } - entries() { - return Array.from(super.entries()) - } - concat(...grps) { - let res = [] - grps.forEach(x => res.push(x.entries())) - res.push(grps.entries()) - let grp = new Group() - res.forEach(x => grp.set(x[0], x[1])) - return grp - } - sweep(func) { - const keys = this.filter(func).allKeys() - for (const key of keys) { - this.delete(key) - } - } -} -module.exports = Group; \ No newline at end of file diff --git a/package/CacheHandler/index.js b/package/CacheHandler/index.js deleted file mode 100644 index 8e0516e19..000000000 --- a/package/CacheHandler/index.js +++ /dev/null @@ -1,8 +0,0 @@ -const Group = require('./group.js') -const LimitGroup = require('./limitGroup.js') -const SuperSet = require('./superSet.js') -module.exports = { -cache:Group, -limitedCache:LimitGroup, -setCache:SuperSet, -} \ No newline at end of file diff --git a/package/CacheHandler/limitGroup.js b/package/CacheHandler/limitGroup.js deleted file mode 100644 index 8e1d5cf6f..000000000 --- a/package/CacheHandler/limitGroup.js +++ /dev/null @@ -1,107 +0,0 @@ - const Group = require('./group.js') -class LimitGroup extends Group { -constructor (limit=200, prototype){ - super(prototype); - this.limit = limit - } -set(key,value){ -if(this.size >this.limit) return ; - return super.set(key,value) - } -delete(key){ - return super.delete(key) - } -clear(){ - - return super.clear() -} -top(number = 1){ - return Array.from(this.values()).slice(0,number) -} -bottom(number = 1){ - return Array.from(this.values()).slice(`-${number}`) -} -find(data){ - return Array.from(this.values()).find(data) -} -filter(data,limit=this.size){ - let keys = Array.from(this.keys()) - let values = Array.from(this.values()) - const filters = Array.from(this.values()).filter(data).slice(0,limit) - let grp = new LimitGroup(this.limit) - - filters.forEach(x=>grp.set(keys[values.indexOf(x)],x)) - return grp - } -allKeys(){ - return Array.from(this.keys()) -} -allValues(){ - return Array.from(this.values()) - } -some(data){ - return Array.from(this.values()).some(data) - } -indexOf(key){ - return Array.from(this.keys()).indexOf(key) - } -findIndex(data){ - return Array.from(this.values()).findIndex(data) - } -includes(data){ - return this.allValues().includes(data) - } -object(){ - let keys = this.allKeys() - let values = this.allValues() - let object = {} - keys.forEach(x=>object[x] = values[keys.indexOf(x)]) - return object - } -map(data){ - return this.allValues.map(data) - } -findKey(data){ - const value = this.allValues().find(data) - const key = this.allKeys()[this.allValues().indexOf(value)] - return key - } -sort(data){ - let grp = new LimitGroup(this.limit) - let sorter = this.allValues().sort(data) -sorter.forEach(x=>grp.set(this.findKey(y=>y === x),x)) - return grp - } -every(data){ - this.allValues.every(data) - } -partition(data){ - let grp1 = this.filter(data) - let grp2 = this - grp1.allKeys().forEach(x=>grp2.delete(x)) - return [grp1 ,grp2] - } -getByPosition(index){ - let grp = new LimitGroup(this.limit) - const key = this.allKeys()[index-1] - grp.set(key,this.get(key)) - return grp - } -reverse(){ - return this.allValues().reverse() - } -entries(){ - return Array.from(super.entries()) - } -concat(...grps){ - let res = [] - grps.forEach(x=>res.push(x.entries())) - res.push(grps.entries()) - let grp = new LimitGroup(this.limit) - res.forEach(x=>{ - if(grp.size > this.limit){} - grp.set(x[0],x[1])}) - return grp - } - } -module.exports = LimitGroup; \ No newline at end of file diff --git a/package/CacheHandler/superSet.js b/package/CacheHandler/superSet.js deleted file mode 100644 index 1532b8c3a..000000000 --- a/package/CacheHandler/superSet.js +++ /dev/null @@ -1,85 +0,0 @@ -class SuperSet extends Set{ -constructor(prototype){ - super(prototype); -} -squash(...values){ - values.forEach(x=>{ - this.add(x) - }) -} -keys(){ - return Array.from(super.keys()) -} -get(value){ - return this[value] -} -values(){ - return Array.from(super.values()) -} -entries(){ - return Array.from(super.entries()) -} -array(){ - return Array.from(this) -} -map(func){ - return this.array().map(func) -} -isSubset(set){ - const subset = Array.from(set) - const Set = this.array() - return subset.every(x=>Set.find(y=>y === x)) -} -isParent(set){ - const subset = this.array() - const parent = Array.from(set) - return subset.every(x=>parent.find(y=>y===x)) -} -filter(data){ - const filter = this.array.filter(data) - return new SuperSet(filter) -} -find(data){ - return this.array().find(data) -} -union(...sets){ - const mainSet = sets.shift() - for(const oset of sets){ - Array.from(oset).forEach(x=>{ - mainSet.add(x) - }) - } - return mainSet -} -intersection(...sets){ - const mainSet = sets.shift() - for(const set of sets){ - Array.from(set).forEach(x=>{ - if(!mainSet.has(x)) mainSet.delete(x) - else {} - }) - } - return mainSet -} -difference(setA,setB){ - for(const value of Array.from(setB)){ - setA.delete(value) - } - return setA -} -equal(set){ - let pass = true - const thisSet = this.array() - set = Array.from(set) - if(this.size !== set.length) pass = false - for(let i = 0;i < thisSet.length;i++){ - if(thisSet[0] === set[0]) continue; - else{ pass = false; break;} - } - return pass -} -sort(func){ - return new SuperSet(this.array().sort(func)) -} -} -module.exports = SuperSet; \ No newline at end of file diff --git a/package/Handler/KMP.js b/package/Handler/KMP.js deleted file mode 100644 index f744bd46d..000000000 --- a/package/Handler/KMP.js +++ /dev/null @@ -1,54 +0,0 @@ -function searchIndexes(pat, txt) { - const patLength = pat.length - const txtLength = txt.length - - const lps = new Array(patLength).fill(0) - - processPattern(pat, patLength, lps) - - const indexes = [] - - let patIndex = 0 - let txtIndex = 0 - - while (txtIndex < txtLength) { - if (pat[patIndex] === txt[txtIndex]) { - ++patIndex - ++txtIndex - } - - if (patIndex === patLength) { - indexes.push(txtIndex - patIndex) - patIndex = lps[patIndex - 1] - } else if ( - txtIndex < txtLength && - pat[patIndex] !== txt[txtIndex] - ) { - if (patIndex !== 0) { - patIndex = lps[patIndex - 1] - } else { - ++txtIndex - } - } - } - - return indexes -} - -function processPattern(pat, patLength, lps) { - let len = 0 - let index = 1 - - while (index < patLength) { - if (pat[index] === pat[len]) { - ++len - lps[index++] = len - } else if (len !== 0) { - len = lps[len-1] - } else { - lps[index++] = 0 - } - } -} - -module.exports = searchIndexes \ No newline at end of file diff --git a/package/Handler/LavaCommands.js b/package/Handler/LavaCommands.js deleted file mode 100644 index 24ad97dee..000000000 --- a/package/Handler/LavaCommands.js +++ /dev/null @@ -1,306 +0,0 @@ -const { Utils } = require("lavacoffee"); -const Searches = new (require("discord.js")).LimitedCollection({ - sweepInterval: 5000, - sweepFilter: (require("discord.js")).LimitedCollection.filterByLifetime({ lifetime: 5000 }) -}); -const { randomBytes } = require("crypto"); - -function getRandomBytes(size) { - return new Promise(resolve => { - randomBytes(size, (_, buf) => { - resolve(buf); - }); - }); -} - -// async function error(d, data, message) { -// const m = await d.util.errorParser(message, d); -// d.aoiError.makeMessageError(d.client, d.channel, m, {},d) -// return { -// code: d.util.setCode(data), -// error: true -// }; -// } - -async function error(d, data, message) { - return d.aoiError.fnError(d, 'custom', data, message) -} - -async function Main(d) { - /** @type {import("discord.js").Message} */ - const message = d.message; - /** @type {import("discord.js").Client} */ - const client = d.client; - - // hi its me, kino, wassup - /** @type {import("../classes/Lavalink")} */ - const lavalink = client.lavalink; - - const da = d.util.openFunc(d); - const inside = da.inside; - const code = da.code; - - if (da.err) return await error(d, da, da.err); - if (!message.guild) return await error(d, da, "Lavalink ERR! GUILD_MISSING"); - - let response = ""; - let [method, ...data] = inside.splits; - let player = lavalink.lavalink.get(message.guild.id); - method = method.toLowerCase(); - let array = d.array; - if (method !== "connect" && !player) return await error(d, da, "Lavalink ERR! PLAYER_UNAVAILABLE in"); - - try { - switch (method) { - case "connect": { - const voice = message.member.voice; - if (!voice) return await error(d, da, "Lavalink ERR! MEMBER_NO_VOICE in"); - - const [deaf, mute] = data - player = lavalink.lavalink.create({ - guildID: message.guildId, - selfDeaf: deaf, - selfMute: mute - }); - player.options.voiceID = voice.channelId; - player.connect(); - player.text = d.channel; - } - break; - case "disconnect": { - player.disconnect(); - player.destroy(); - } - break; - case "version": { - response = lavalink.version; - } - break; - case "isplaying": { - response = Boolean(player?.state === Utils.PlayerStates.Playing); - } - break; - case "ispaused": { - response = Boolean(player?.state === Utils.PlayerStates.Paused && player.queue.current) - } - break; - case "isidling": { - response = Boolean(player?.state === Utils.PlayerStates.Paused && !player.queue.current); - } - break; - case "songinfo": { - const track = player.queue.at(Number(data[1]) - 1) || player.queue.current || player.queue.previous; - if (track) { - const p = data[0]; - if (p === "current_duration") { - const d = lavalink.getCurrent(player) - response = `${d.minute}:${d.second}`; - if (d.hour > 0) { - response = `${String(d.hour)}:${response}`; - } - } else if (p === "duration_left") { - const d = lavalink.getLeft(player, track) - response = `${d.minute}:${d.second}`; - if (d.hour > 0) { - response = `${String(d.hour)}:${response}`; - } - } - else if (track[p]) response = track[p] - else response = ""; - } - } - break; - case "skip": { - if (player.state !== Utils.PlayerStates.Destroyed && player.queue.current) { - player.stop(Number(data[0])); - } - } - break; - case "stop": { - player.queue.clear(); - player.setLoop(Utils.LoopMode.None); - player.stop(); - } - break; - case "pause": { - player.pause(true); - } - break; - case "resume": { - player.pause(false); - } - break; - case "seek": { - const n = (Number(data[0]) * 1000) ?? 0; - player.position = n; - player.lastUpdated = Date.now(); - player.seek(n); - } - break; - case "state": { - response = Utils.PlayerStates[player.state]; - } - break; - case "getthumbnail": { - response = `https://img.youtube.com/vi/${String(data[0])}/${data[1] || "default"}.jpg`; - } - break; - case "search": { - const res = await lavalink.lavalink.search({query: data[0], source: data[1] || "yt"}, message.member); - const id = (await getRandomBytes(10)).toString("hex"); - Searches.set(id, res.tracks.slice(0, 10).map(v => { - const d = lavalink.getTime(v.duration / 1000); - v.length = v.duration; - v.duration = `${d.minute}:${d.second}`; - if (d.hour > 0) { - v.duration = `${String(d.hour)}:${v.duration}` - }; - v.thumbnail = v.displayThumbnail("default"); - return v; - })); - response = id; - }; - break; - case "getsearch": { - const tracks = Searches.get(data[0]); - if (tracks) response = tracks.map(v => v.title.addBrackets()).join(",") - else response = ""; - } - break; - case "tracksplit": { - const tracks = Searches.get(data[0]); - if (tracks) { - response = "true"; - array = tracks.map(v => v.title); - }; response = "false"; - } - case "findentry": { - const tracks = Searches.get(data[0]); - if (!tracks) return await error(d, da, "Lavalink ERR! INVALID_KEYSEARCH in"); - const query = data.slice(1).join(";") - const index = tracks.findIndex(v => v.title.toLowerCase().includes(query.toLowerCase())); - - response = index + 1; - } - break; - case "addtrack": { - const tracks = Searches.get(data[0]); - if (!tracks) return await error(d, da, "Lavalink ERR! INVALID_KEYSEARCH in"); - - const n1 = Number(data[1]); - const n2 = Number(data[2] || "e"); - let sel_tracks = tracks[n1 - 1]; - if (!isNaN(n2)) sel_tracks = tracks.slice(n1 - 1, n2 - 1); - if (!sel_tracks) return await error(d, da, "Lavalink ERR! NO_MATCHES"); - - player.queue.add(sel_tracks); - response = Array.isArray(sel_tracks) ? sel_tracks.length : 1; - } - break; - case "play": { - player.play({}); - } - break; - case "resetfilters": { - player.filters = {}; - player.setFilters({ volume: 1.0 }); - player.patchFilters(); - } - break; - case "addfilters": { - const constructFilter = { ...player.filters }; - - for (const input of data) { - let [key, value = ""] = input.split("="); - try { - value = JSON.parse(value); - } catch {} - constructFilter[key] = value; - }; - - player.setFilters(constructFilter); - player.patchFilters(); - } - break; - case "destroy": { - console.warn("Lavalink WARN! method(loopsong) deprecated, use method(loopmode) in"); - player.destroy(); - } - break; - case "volume": { - if (!data[0]) response = player.filters.volume || 100 - else player.setVolume(Number(data[0])); - } - break; - case "queuelength": { - const type = data[0] || "total"; - if (type === "total") { - response = player.queue.size - } else if (type === "duration") { - response = player.queue.duration - }; - } - break; - case "queue": { - const mapFormat = data.join(";").addBrackets() || "{entrynumber}. [{title}]({url}) by {userTag}"; - const array = []; - let i; - for (i = 0; i < player.queue.size; i++) { - const track = player.queue.at(i); - const clone = { ...track, userID: track.requester.id, userTag: track.requester.user.tag, entrynumber: i + 1 }; - const res = mapFormat.replace(/{\w+}/g, (match) => { - const r = clone[match.replace(/[{}]/g, "")]; - if (r) return r; - return ""; - }); - array.push(res); - } - response = array.join("\n") - } - break; - case "loopmode": { - const mode = data[0]; - if (!mode) { - response = Utils.LoopMode[String(player.loop)]; - } else { - const r = Utils.LoopMode[data[0].slice(0,1).toUpperCase() + data[0].slice(1)]; - if (!r) return await error(d, da, "Lavalink ERR! LOOPMODE_UNKNOWN in"); - player.setLoop(r); - response = r; - } - }; - break; - case "loopqueue": { - console.warn("Lavalink WARN! method(loopqueue) deprecated, use method(loopmode) in"); - const r = player.loop === Utils.LoopMode.Queue ? Utils.LoopMode.None : Utils.LoopMode.Queue - player.setLoop(r); - response = r; - }; - break; - case "loopsong": { - console.warn("Lavalink WARN! method(loopsong) deprecated, use method(loopmode) in"); - const r = player.loop === Utils.LoopMode.Track ? Utils.LoopMode.None : Utils.LoopMode.Track - player.setLoop(r); - response = r; - } - break; - default: { - return await error(d, da, "Lavalink ERR! METHOD_UNAVAILABLE in") - } - } - } catch (err) { - return await error(d, da, `Lavalink INTERNAL_ERR! ${err.message}`); - } - - da.result = String(response ?? ""); - d.array = array; - d.data.array = d.array; - - return { - code: d.util.setCode(da), - array: d.array, - data: d.data - }; -} - -module.exports = Main; diff --git a/package/Handler/NewMusic/SearchManager.js b/package/Handler/NewMusic/SearchManager.js deleted file mode 100644 index f36b46dbe..000000000 --- a/package/Handler/NewMusic/SearchManager.js +++ /dev/null @@ -1,54 +0,0 @@ -////requiring -const ytsr = require('youtube-sr'); -const ytdl = require('ytdl-core'); -const scdl = require('soundcloud-downloader').default; -const axios = require('axios'); -const fs = require('fs'); - -////base class for each type -//Attachment class -class Attachment { - static async getStream(url) { - const { data } = await axios.get(url); - return data; - } - static getInfo(url, description = "An Track Taken From The Attachment") { - const data = { - title : url.split("/").pop(), - description, - url - } - - return data; - } - static async getData(url) { - return { - stream : await this.getStream(url) , - info : this.getInfo(url) - } - } -} -//fs class -class Fs { - static getStream(path) { - const stream = fs.createReadStream(process.cwd()+`/${path}`); - return stream; - } - static getInfo(path) { - const data = { - title : path , - description : "A File In The Project", - url : process.cwd()+`/${path}` - } - return data ; - } - static getData(path) { - return { - stream : this.getStream(path), - info : this.getInfo(path) - } - } -} -class Scdl { - static async search(track) {} -} \ No newline at end of file diff --git a/package/Handler/autoUpdate.js b/package/Handler/autoUpdate.js deleted file mode 100644 index d6b826abb..000000000 --- a/package/Handler/autoUpdate.js +++ /dev/null @@ -1,52 +0,0 @@ -const { exec } = require("child_process"); -const axios = require("axios").default; -const json = require("../../package.json"); -module.exports = async () => { - console.log("Aoi.js AutoUpdate System: \u001b[33mExecuting a contact with API...\u001b[0m") - - try { - const res = await axios.get("https://api.leref.ga/package/version") - if (json.version !== res.data.version) { - console.log("Aoi.js AutoUpdate System: \u001b[33mAvailable version v" + res.data.version + " ready to install.\u001b[0m"); - - // Install initiate - console.log("Aoi.js AutoUpdate System: \u001b[33m Installing version...\u001b[0m") - const Process = exec("npm i aoi.js@latest", (error, stdout, stderr) => { - if (error) return console.error("Aoi.JS AutoUpdate System: \u001b[31mERR!\u001b[0m " + error.message); - - console.log("Aoi.js AutoUpdate System: \u001b[32mSuccessfully Installed aoi.js v" + res.data.version + ".\u001b[0m") - console.log("Aoi.js AutoUpdate System: Commencing 'RESTART' in 3 Seconds..."); - - setTimeout(Reboot, 3000) - }) - Process.stdout.setEncoding("utf8"); - Process.stdout.on("data", (chunk) => { - console.log(chunk.toString()); - }); - - Process.stderr.setEncoding("utf8"); - Process.stderr.on("data", (chunk) => { - console.log(chunk.toString()); - }); - } else { - console.log("Aoi.JS AutoUpdate System: \u001b[32mVersion is up-to-date.\u001b[0m") - } - } catch (error) { - console.warn("Aoi.JS AutoUpdate System: \u001b[31mUnexpected error when trying to reach API.\u001b[0m"); - } -}; - -function Reboot() { - try { - process.on("exit", () => { - require("child_process").spawn(process.argv.shift(), process.argv, { - cwd: process.cwd(), - detached: true, - stdio: "inherit", - }); - }); - process.exit(); - } catch (e) { - console.error(`Aoi.JS AutoUpdate System: \u001b[31mERR!\u001b[0m Failed to commence 'RESTART', ${e.message}`); - } -} \ No newline at end of file diff --git a/package/Handler/custom/functionError.js b/package/Handler/custom/functionError.js deleted file mode 100644 index f1a942452..000000000 --- a/package/Handler/custom/functionError.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (error,client)=>{ -const cmds = client.cmd.functionError.allValues() -let chan; -const data = { - guild:error.guild, - channel:error.channel, - author:error.author, - client:client -} -for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = (await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true)); - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd, client.db,false,chan?.id,{errorData:error},chan) -} -} \ No newline at end of file diff --git a/package/Handler/custom/loop.js b/package/Handler/custom/loop.js deleted file mode 100644 index 7041b5d00..000000000 --- a/package/Handler/custom/loop.js +++ /dev/null @@ -1,23 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (client) => { - const cmds = client.cmd.loop.allValues() - let chan; - let data = { - client: client, - channel, - guild, - } - for (const cmd of cmds) { - if (cmd.channel?.includes("$")) { - const id = (await Interpreter(client, data, [], { name: "ChannelParser", code: cmd.channel }, client.db, true)); - chan = client.channels.cache.get(id?.code) - data.channel = chan - data.guild = chan?.guild - } - setInterval(async() => { - await Interpreter(client, data, [], cmd, client.db, false, chan?.id, {}, chan); - }, cmd.every || 60000); - - if (cmd.executeOnStartup) await Interpreter(client, data, [], cmd, client.db, false, chan?.id, {}, chan); - } -} \ No newline at end of file diff --git a/package/Handler/custom/timeout.js b/package/Handler/custom/timeout.js deleted file mode 100644 index 7b5afa8ec..000000000 --- a/package/Handler/custom/timeout.js +++ /dev/null @@ -1,36 +0,0 @@ -module.exports = async (d, name, duration, timeoutData, onReady) => { - let cmds = d.client.cmd.timeout.allValues(); - - if (onReady) { - const datas = await d.client.db.all(d.client.db.tables[0], x => x.key.startsWith('setTimeout')); - for (const data of datas.filter(x => !x.data.value.__pulseEvery__)) { - const t = data.data.value; - const dura =t.__duration__ - Date.now(); - cmds = cmds.filter(x => x.name === t.__timeoutName__); - if ((dura) > 0) { - for (const cmd of cmds) { - setTimeout(async() => { - await d.interpreter(d.client, {}, [], cmd, d.client.db, false, undefined, { timeoutData : t }); - - d.client.db.delete(d.client.db.tables[0], data.key) - }, dura) - } - } - else { - d.client.db.delete(d.client.db.tables[0], data.key) - } - } - } - else { - if (name) { - cmds = cmds.filter(x => x.name === name); - } - for (const cmd of cmds) { - setTimeout(async () => { - await d.interpreter(d.client, {}, [], cmd, d.client.db, false, undefined, { timeoutData }); - - d.client.db.delete(d.client.db.tables[0],'setTimeout',timeoutData.__id__); - }, duration) - } - } -} \ No newline at end of file diff --git a/package/Handler/custom/timeoutPulse.js b/package/Handler/custom/timeoutPulse.js deleted file mode 100644 index f4b7fd336..000000000 --- a/package/Handler/custom/timeoutPulse.js +++ /dev/null @@ -1,41 +0,0 @@ -module.exports = async (d, name, duration, pulse, timeoutData, onReady) => { - let cmds = d.client.cmd.pulse.allValues(); - - if (onReady) { - const datas = await d.client.db.all(d.client.db.tables[0], x => x.key.startsWith('setTimeout')); - for (const data of datas.filter(x => x.data.value.__pulseEvery__)) { - const t = data.data.value; - - cmds = cmds.filter(x => x.name === t.__timeoutName__); - if ((t.__duration__ - Date.now()) > 0) { - for (const cmd of cmds) { - - const interval = setInterval(async () => { - await d.interpreter(d.client, {}, [], cmd, d.client.db, false, undefined, { timeoutData : t }); - }, t.__pulseEvery__); - setTimeout(() => { - clearInterval(interval) - d.client.db.delete(d.client.db.tables[0], data.key) - }, (t.__duration__ - Date.now())); - } - } - else { - d.client.db.delete(d.client.db.tables[0], data.key) - } - } - } - else { - if (name) { - cmds = cmds.filter(x => x.name === name); - } - for (const cmd of cmds) { - const interval = setInterval(() => { - d.interpreter(d.client, {}, [], cmd, d.client.db, false, undefined, { timeoutData }); - }, pulse || duration); - setTimeout(() =>{ - clearInterval(interval) - d.client.db.delete(d.client.db.tables[0],'setTimeout',timeoutData.__id__); - }, duration); - } - } -} \ No newline at end of file diff --git a/package/Handler/custom/varCreate.js b/package/Handler/custom/varCreate.js deleted file mode 100644 index 5464f1ad3..000000000 --- a/package/Handler/custom/varCreate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('./interpreter.js') -module.exports = async (data,client)=>{ - let chan; - const d ={ - client:client, - guild:data.guild, - channel:data.channel, - message:data.message, - author:data.author, -} - const cmds = client.cmd.variableCreate.allValues() - for(const cmd of cmds){ - const id = cmd.channel?.includes("$") ? (await Interpreter(client,d,[],{name:"ChannelParser",code:cmd.channel},client.db,true)):{ code : cmd.channel } - chan = client.channels.cache.get(id?.code) - await Interpreter(client,d,[],cmd,client.db,false,chan?.id,{oldv:data},chan) -} - -} \ No newline at end of file diff --git a/package/Handler/custom/varDelete.js b/package/Handler/custom/varDelete.js deleted file mode 100644 index 265a26567..000000000 --- a/package/Handler/custom/varDelete.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('./interpreter.js') -module.exports = async (data,client)=>{ - let chan; - const d ={ - client:client, - guild:data.guild, - channel:data.channel, - message:data.message, - author:data.author, -} - const cmds = client.cmd.variableDelete.allValues() - for(const cmd of cmds){ - const id = cmd.channel?.includes("$") ? (await Interpreter(client,d,[],{name:"ChannelParser",code:cmd.channel},client.db,true)): { code : cmd.channel} - chan = client.channels.cache.get(id?.code) - await Interpreter(client,d,[],cmd,client.db,false,chan?.id,{newv:data},chan) -} - -} \ No newline at end of file diff --git a/package/Handler/custom/varUpdate.js b/package/Handler/custom/varUpdate.js deleted file mode 100644 index b322b094f..000000000 --- a/package/Handler/custom/varUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('./interpreter.js') -module.exports = async (olddata,newdata,client)=>{ - let chan; - const d ={ - client:client, - guild:newdata.guild, - channel:newdata.channel, - message:newdata.message, - author:newdata.author, -} - const cmds = client.cmd.variableUpdate.allValues() - for(const cmd of cmds){ - const id = cmd.channel?.includes("$") ? (await Interpreter(client,d,[],{name:"ChannelParser",code:cmd.channel},client.db,true)) : {code : cmd.channel } - chan = client.channels.cache.get(id?.code) - await Interpreter(client,d,[],cmd,client.db,false,chan?.id,{newv:newdata,oldv:olddata},chan) -} - -} \ No newline at end of file diff --git a/package/Handler/eventExecuter.js b/package/Handler/eventExecuter.js deleted file mode 100644 index 7e119b6f3..000000000 --- a/package/Handler/eventExecuter.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../interpreter.js') - -module.exports = async (event,client,commands,...data) =>{ - let msg = {channel: undefined,author:undefined,content:"",guild: undefined,member: undefined} - let EventData = {} - const cmds = commands.allValues() - for(const cmd of cmds){ - if(cmd.channel){ - const id =cmd.channel.includes("$") ? await Interpreter (client,{author: undefined, channel: undefined,message: undefined},[],{name:"channelParser",code:cmd.channel},client.db,true) : cmd.channel - const channel = client.channels.cache.get(id) - if(!channel) return console.error("Channel doesn't exist") - - msg = {channel:channel,author:undefined,content:"",guild:channel.guild,member: undefined} - } - EventData= data - await Interpreter(client,msg,[],cmd, undefined,false,cmd.channel,{eventData: EventData}) - } -} diff --git a/package/Handler/fetchInvites.js b/package/Handler/fetchInvites.js deleted file mode 100644 index 39cca364f..000000000 --- a/package/Handler/fetchInvites.js +++ /dev/null @@ -1,9 +0,0 @@ -const InviteSystem = require('../classes/InviteSystem.js') -module.exports = async client => { - client.inviteSystem = new InviteSystem(client,client.options.fetchInvites?.cacheInviters||false) - client.inviteSystem.fetchAll() - if(client.options.fetchInvites?.cacheInviters){ - client.inviteSystem.fetchInviters() - } - -} \ No newline at end of file diff --git a/package/Handler/guildBans/add.js b/package/Handler/guildBans/add.js deleted file mode 100644 index cc6cb598e..000000000 --- a/package/Handler/guildBans/add.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (ban,client) =>{ -const cmds = client.cmd.banAdd.allValues() -const data = {guild:ban.guild,author:ban?.user,client:client} - -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{banData:ban},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildBans/remove.js b/package/Handler/guildBans/remove.js deleted file mode 100644 index e90a8173e..000000000 --- a/package/Handler/guildBans/remove.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (ban,client) =>{ -const cmds = client.cmd.banRemove.allValues() -const data = {guild:ban.guild,author:ban?.user,client:client} - -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{banData:ban},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildEmojis/create.js b/package/Handler/guildEmojis/create.js deleted file mode 100644 index 33087d32f..000000000 --- a/package/Handler/guildEmojis/create.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (newe,client) =>{ -const cmds = client.cmd.emojiCreate.allValues() - -const data = {guild:newe.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newe:newe},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildEmojis/delete.js b/package/Handler/guildEmojis/delete.js deleted file mode 100644 index 76ef93cc5..000000000 --- a/package/Handler/guildEmojis/delete.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (olde,client) =>{ -const cmds = client.cmd.emojiDelete.allValues() - -const data = {guild:olde.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{olde:olde},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildEmojis/stickerCreate.js b/package/Handler/guildEmojis/stickerCreate.js deleted file mode 100644 index 2c29aad04..000000000 --- a/package/Handler/guildEmojis/stickerCreate.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (newe,client) =>{ -const cmds = client.cmd.stickerCreate.allValues() - -const data = {guild:newe.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{news:newe},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildEmojis/stickerDelete.js b/package/Handler/guildEmojis/stickerDelete.js deleted file mode 100644 index 8bd1d9928..000000000 --- a/package/Handler/guildEmojis/stickerDelete.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (olde,client) =>{ -const cmds = client.cmd.stickerDelete.allValues() - -const data = {guild:olde.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{olds:olde},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildEmojis/stickerUpdate.js b/package/Handler/guildEmojis/stickerUpdate.js deleted file mode 100644 index d65a37b67..000000000 --- a/package/Handler/guildEmojis/stickerUpdate.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (olde,newe,client) =>{ -const cmds = client.cmd.stickerUpdate.allValues() - -const data = {guild:newe.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{olds:olde,news:newe},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildEmojis/update.js b/package/Handler/guildEmojis/update.js deleted file mode 100644 index b03970f95..000000000 --- a/package/Handler/guildEmojis/update.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (olde,newe,client) =>{ -const cmds = client.cmd.emojiUpdate.allValues() - -const data = {guild:newe.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{olde:olde,newe:newe},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildInvites/create.js b/package/Handler/guildInvites/create.js deleted file mode 100644 index 749fc953d..000000000 --- a/package/Handler/guildInvites/create.js +++ /dev/null @@ -1,20 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (invite,client)=> { -const cmds = client.cmd.inviteCreate.allValues() -for(const cmd of cmds){ - let chan; - const data = { - guild:invite.guild, - client:client - } - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel?? undefined - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id||"",{inviteData:invite},chan||undefined) -} -if(client.options.fetchInvites.enabled){ - client.inviteSystem.inviteCreate(invite) -} -} \ No newline at end of file diff --git a/package/Handler/guildInvites/delete.js b/package/Handler/guildInvites/delete.js deleted file mode 100644 index 2979e19e9..000000000 --- a/package/Handler/guildInvites/delete.js +++ /dev/null @@ -1,20 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (invite,client)=> { -const cmds = client.cmd.inviteDelete.allValues() -for(const cmd of cmds){ - let chan; - const data = { - guild:invite.guild, - client:client - } - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel?? undefined - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id||"",{inviteData:invite},chan||undefined) -} -if(client.options.fetchInvites.enabled){ - client.inviteSystem.inviteDelete(invite) -} -} \ No newline at end of file diff --git a/package/Handler/guildMembers/available.js b/package/Handler/guildMembers/available.js deleted file mode 100644 index 97d4c3f62..000000000 --- a/package/Handler/guildMembers/available.js +++ /dev/null @@ -1,13 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (mem,client) =>{ -let chan; - const cmds = client.cmd.memberAvailable.allValues() - let data = {guild:mem.guild,author:mem.user,member:mem,client:client} - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{newm:mem},chan) - } -} \ No newline at end of file diff --git a/package/Handler/guildMembers/chunk.js b/package/Handler/guildMembers/chunk.js deleted file mode 100644 index 1933b9fdf..000000000 --- a/package/Handler/guildMembers/chunk.js +++ /dev/null @@ -1,13 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (mem,guild,chunk,client) =>{ -let chan; - const cmds = client.cmd.memberChunk.allValues() - let data = {guild:guild,channel: undefined,client:client} - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{membersChuck:{members:mem,guild:guild,chunk:chunk}},chan) - } -} \ No newline at end of file diff --git a/package/Handler/guildMembers/join.js b/package/Handler/guildMembers/join.js deleted file mode 100644 index c0ba4e72b..000000000 --- a/package/Handler/guildMembers/join.js +++ /dev/null @@ -1,16 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (mem,client) =>{ - if(client.options.fetchInvites.enabled){ - client.inviteSystem.userJoined(mem) - } - let chan; - const cmds = client.cmd.join.allValues() - let data = {guild:mem.guild,author:mem.user,member:mem,client:client} - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{newm:mem},chan) - } -} \ No newline at end of file diff --git a/package/Handler/guildMembers/leave.js b/package/Handler/guildMembers/leave.js deleted file mode 100644 index db159f60d..000000000 --- a/package/Handler/guildMembers/leave.js +++ /dev/null @@ -1,16 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (mem,client) =>{ - if(client.options.fetchInvites.enabled){ - client.inviteSystem.userLeft(mem) - } - let chan; - const cmds = client.cmd.leave.allValues() - let data = {guild:mem?.guild,author:mem?.user,member:mem,client:client} - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{newm:mem},chan) - } -} \ No newline at end of file diff --git a/package/Handler/guildMembers/update.js b/package/Handler/guildMembers/update.js deleted file mode 100644 index 5b552d6a3..000000000 --- a/package/Handler/guildMembers/update.js +++ /dev/null @@ -1,13 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldm,newm,client) =>{ - let chan; - const cmds = client.cmd.memberUpdate.allValues() - let data = {guild:newm?.guild,author:newm?.user,member:newm,client:client} - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{newm:newm,oldm:oldm},chan) - } -} \ No newline at end of file diff --git a/package/Handler/guildMessageReactions/add.js b/package/Handler/guildMessageReactions/add.js deleted file mode 100644 index 5b7247721..000000000 --- a/package/Handler/guildMessageReactions/add.js +++ /dev/null @@ -1,20 +0,0 @@ - -const Interpreter = require('../../interpreter.js') -module.exports = async (reaction,user,client)=>{ -const cmds = client.cmd.reactionAdd.allValues() -const data = { - message: reaction.message, - channel: reaction.message.channel, - client:client, - guild:reaction.emoji.guild, - author:user -} -for(const cmd of cmds){ - let chan; - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels?.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{ reactionData:reaction },chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildMessageReactions/remove.js b/package/Handler/guildMessageReactions/remove.js deleted file mode 100644 index 9d79a6ac2..000000000 --- a/package/Handler/guildMessageReactions/remove.js +++ /dev/null @@ -1,20 +0,0 @@ - -const Interpreter = require('../../interpreter.js') -module.exports = async (reaction,user,client)=>{ -const cmds = client.cmd.reactionRemove.allValues() -const data = { - message:reaction.message, - channel:reaction.message.channel, - client:client, - guild:reaction.emoji.guild, - author:user -} -for(const cmd of cmds){ - let chan; - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels?.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{ reactionData : reaction },chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildMessageReactions/removeAll.js b/package/Handler/guildMessageReactions/removeAll.js deleted file mode 100644 index 3aac9f647..000000000 --- a/package/Handler/guildMessageReactions/removeAll.js +++ /dev/null @@ -1,22 +0,0 @@ - -const Interpreter = require('../../interpreter.js') -module.exports = async (reactionMessage,client)=>{ -const cmds = client.cmd.reactionRemoveAll.allValues() -const data = { - client:client, - guild:reactionMessage.guild, - author:reactionMessage.author, - channel: reactionMessage.channel, - member:reactionMessage.member -} -for(const cmd of cmds){ - let chan; - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels?.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{},chan) - - -} -} \ No newline at end of file diff --git a/package/Handler/guildMessageReactions/removeEmoji.js b/package/Handler/guildMessageReactions/removeEmoji.js deleted file mode 100644 index 188023f0e..000000000 --- a/package/Handler/guildMessageReactions/removeEmoji.js +++ /dev/null @@ -1,19 +0,0 @@ - -const Interpreter = require('../../interpreter.js') -module.exports = async (reaction,client)=>{ -const cmds = client.cmd.reactionRemoveEmoji.allValues() -const data = { - message : reaction.message, - channel : reaction.message.channel, - client:client, - guild:reaction.emoji.guild -} -for(const cmd of cmds){ - let chan; - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels?.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{reactionData:reaction },chan) -} -} \ No newline at end of file diff --git a/package/Handler/guildMessageTypings/start.js b/package/Handler/guildMessageTypings/start.js deleted file mode 100644 index 0ba269706..000000000 --- a/package/Handler/guildMessageTypings/start.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (typing,client)=>{ - const cmds = client.cmd.typingStart.allValues() - let chan; - let data ={ - guild:typing.guild, - client:client, - author:typing.user, - channel:typing.channel, - member:typing.member - } - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ -const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{typing:typing},chan) - } -} \ No newline at end of file diff --git a/package/Handler/guildMessages/alwaysExecute.js b/package/Handler/guildMessages/alwaysExecute.js deleted file mode 100644 index 48a7eeae1..000000000 --- a/package/Handler/guildMessages/alwaysExecute.js +++ /dev/null @@ -1,28 +0,0 @@ -const Interpreter = require("../../interpreter.js") -const Util = require('../../classes/Util.js') -module.exports = async (client, message, db) => { - if (client.messageEventOptions) { - const options = client. - messageEventOptions - if ((options.respondToBots === false && ( message.webhookID || message.author.bot)) ||(options.guildOnly && message.channel.type === Util.channelTypes.Dm)) return; - } - const commands = client.cmd.default.allValues().filter(c => c.name === "$alwaysExecute") - if(!commands.length) return ; - commands.map(async command => { - const bl = client.blacklist - if(!command.whitelist){ - if(bl.server.blacklist.has(message.guild.id)){ - } - else if(bl.channel.blacklist.has(message.channel.id)){ - } - else if(bl.role.blacklist.find(x=>message.member._roles.includes(x))){ - } - else if(bl.user.blacklist.has(`${message.author.id}_${message.guild.id}`)){ - } - else if(bl.globalUser.blacklist.has(message.author.id)){ - } - } - if(command.dmOnly && message.channel.type === Util.channelTypes.Dm) return; - await Interpreter(client, message, message.content.split(" "), command, db) - }) -} \ No newline at end of file diff --git a/package/Handler/guildMessages/bulkDeleteMessage.js b/package/Handler/guildMessages/bulkDeleteMessage.js deleted file mode 100644 index a96b2f473..000000000 --- a/package/Handler/guildMessages/bulkDeleteMessage.js +++ /dev/null @@ -1,21 +0,0 @@ -const Interpreter = require("../../interpreter.js") -module.exports = async (dmsg,client) =>{ - const d = { - guild:dmsg.guild, - channel:dmsg.channel, - client:dmsg.client - } -let chan; -for(const cmd of client.cmd.messageDelete.allValues()){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,{},[],{command:"channelParser",code:cmd.channel}, client.db, true) - let channel = client.channels.cache.get(id?.code) - if(!channel) channel = dmsg.first().channel - chan = channel -} - else{chan = cmd.channel} - await Interpreter(client,d,[],cmd, client.db,false, undefined,{bulk:dmsg},chan) - -} - -} \ No newline at end of file diff --git a/package/Handler/guildMessages/commands.js b/package/Handler/guildMessages/commands.js deleted file mode 100644 index b868cf12d..000000000 --- a/package/Handler/guildMessages/commands.js +++ /dev/null @@ -1,77 +0,0 @@ -const Interpreter = require('../../interpreter.js') -const Util = require('../../classes/Util.js') -module.exports = async (message, client, db) => { - if (client.messageEventOptions) { - - const options = client. - - messageEventOptions - - if ((options.respondToBots === false && (message.webhookId || message.author.bot)) || (options.guildOnly && message.channel.type === Util.channelTypes.Dm)) return; - } - //array of cmds - let cmds = client.cmd.default.allValues() - //getting arrays of prefixes - const prefixes = Array.isArray(client.prefix) ? client.prefix.map(async x => x.includes("$") ? (await Interpreter(client, message, message.content.split(" "), { name: "PrefixParser", code: x }, client.db, true))?.code?.addBrackets() : x) : client.prefix.includes("$") ? [(await Interpreter(client, message, message.content.split(" "), { code: client.prefix }, client.db, true))?.code?.addBrackets()] : [client.prefix] - //for loop of prefix array - for (let prefix of prefixes) { - prefix = await prefix; - if (!message.content.toLowerCase().startsWith(prefix.toLowerCase())) continue; - //getting message - const msg = message.content.slice(prefix.length).trim() - //finding command - const cmd = cmds.filter(x => msg.toLowerCase().startsWith(x.name.toLowerCase()) && msg.split(" ").slice(0, x.name.split(" ").length).join(" ").toLowerCase() === x.name.toLowerCase() || (Array.isArray(x.aliases) ? x.aliases.find(y => msg.toLowerCase().startsWith(y.toLowerCase()) && msg.split(" ").slice(0, y.split(" ").length).join(" ").toLowerCase() === y.toLowerCase()) : msg?.toLowerCase().startsWith(x.aliases?.toLowerCase()) && msg.split(" ").slice(0, x.aliases?.split(" ").length).join(" ")?.toLowerCase() === x.aliases?.toLowerCase()))?.sort((a, b) => a.name.length - b.name.length).reverse()[0] - if (!cmd) break; - const cmdName = (msg.toLowerCase().startsWith(cmd.name.toLowerCase()) && msg.toLowerCase().split(" ").slice(0, cmd.name.split(" ").length).join(" ") === cmd.name.toLowerCase()) ? cmd.name : (Array.isArray(cmd.aliases) ? cmd.aliases.find(x => msg.toLowerCase().startsWith(x.toLowerCase()) && msg.toLowerCase().split(" ").slice(0, x.split(" ").length).join(" ") === x.toLowerCase()) : msg.toLowerCase().split(" ").slice(0, cmd.aliases.split(" ").length).join(" ") === cmd.aliases.toLowerCase()) ? cmd.aliases : undefined - //args - const args = msg.slice(cmdName?.length || "").split(" ").slice(1) - //check if blacklisted - const bl = client.blacklist - if (!bl.commands.includes(cmd.name?.toLowerCase())) { - if (!cmd.whitelist) { - if (bl.server.blacklist.has(message.guild?.id)) { - if (bl.server.errorMsg) { - message.channel.send(bl.server.errorMsg) - } - break; - } - else if (bl.channel.blacklist.has(message.channel.id)) { - if (bl.channel.errorMsg) { - console.log("Blacklist sent") - message.channel.send(bl.channel.errorMsg) - } - break; - } - else if (bl.role.blacklist.find(x => message.member_roles?.includes(x))) { - if (bl.role.errorMsg) { - message.channel.send(bl.role.errorMsg) - } - break; - } - else if (bl.user.blacklist.has(`${message.author.id}_${message.guild?.id}`)) { - if (bl.user.errorMsg) { - message.channel.send(bl.user.errorMsg) - } - break; - } - else if (bl.globalUser.blacklist.has(message.author.id)) { - if (bl.globalUser.errorMsg) { - message.channel.send(bl.globalUser.errorMsg) - } - break; - } - } - } - //if command doesn't exist , then break the loop - - if (cmd.dmOnly && message.channel.type !== Util.channelTypes.Dm) break; - //if cmd.async is true - if (cmd.async) { - await Interpreter(client, message, args, cmd, client.db) - } - //non async execution - else { - Interpreter(client, message, args, cmd, client.db) - } - } -} diff --git a/package/Handler/guildMessages/deleteMessage.js b/package/Handler/guildMessages/deleteMessage.js deleted file mode 100644 index bea20717e..000000000 --- a/package/Handler/guildMessages/deleteMessage.js +++ /dev/null @@ -1,21 +0,0 @@ -const Interpreter = require("../../interpreter.js") -module.exports = async (dmsg,client) =>{ - const data = {} - Object.assign(data,dmsg) -let chan ; - -if(!data.partial && client.user.id === data?.author?.id) return ; -for(const cmd of client.cmd.messageDelete.allValues()){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{command:"channelParser",code:cmd.channel}, client.db, true) - let channel = client.channels.cache.get(id?.code) - if(!channel) channel = dmsg.channel - chan = channel -} - else{data.channel = cmd.channel} - if(!data.guild) data.guild = dmsg.guild||dmsg.channel?.guild - await Interpreter(client,data,data?.content?.split(" "),cmd, client.db,false,dmsg.channel?.id,{},chan) - -} - -} \ No newline at end of file diff --git a/package/Handler/guildMessages/nonPrefixed.js b/package/Handler/guildMessages/nonPrefixed.js deleted file mode 100644 index 690d613bb..000000000 --- a/package/Handler/guildMessages/nonPrefixed.js +++ /dev/null @@ -1,38 +0,0 @@ -const Interpreter = require("../../interpreter.js") -const Util = require('../../classes/Util.js') -module.exports = async (client, message, db) => { - if (client.messageEventOptions) { - const options = client. - messageEventOptions - if ((options.respondToBots === false && ( message.webhookID || message.author.bot)) ||(options.guildOnly && message.channel.type === Util.channelTypes.Dm)) return; - } - const commands = client.cmd.default.allValues().filter(c => c.nonPrefixed) - if(!commands.length) return ; - for(const cmd of commands){ - const bl = client.blacklist - if(bl.commands.includes(cmd.name.toLowerCase())){ - if(bl.server.blacklist.has(message.guild.id)){ - continue; - } - else if(bl.channel.blacklist.has(message.channel.id)){ - continue; - } - else if(bl.role.blacklist.find(x=>message.member._roles.includes(x))){ - continue; - } - else if(bl.user.blacklist.has(`${message.author.id}_${message.guild.id}`)){ - continue; - } - else if(bl.globalUser.blacklist.has(message.author.id)){ - continue; - } - } - if(cmd.dmOnly && message.channel.type === Util.channelTypes.Dm) continue; - if(cmd.name.includes("$")){ - cmd.name = await Interpreter(client, message,message.content.split(" "),{name:"NameParser",code:cmd.name},client.db,true) - } - if(! message.content.toLowerCase().startsWith(cmd.name.toLowerCase()) || !(Array.isArray(cmd.aliases)?cmd.aliases.find(x=>message.content.toLowerCase().startsWith(x.toLowerCase())) : message.content.toLowerCase().startsWith(cmd.aliases))) continue; - await Interpreter(client, message, message.content.split(" "), cmd,client.db) - } - -} \ No newline at end of file diff --git a/package/Handler/guildMessages/oldCommands.js b/package/Handler/guildMessages/oldCommands.js deleted file mode 100644 index a4ed06cee..000000000 --- a/package/Handler/guildMessages/oldCommands.js +++ /dev/null @@ -1,41 +0,0 @@ -const Interpreter = require("../../interpreter.js") -//const alwaysExecuteCommands = require("./alwaysExecuteCommands") -//const nonPrefixedCommands = require("./nonPrefixedCommands.js") -//const testInterpreter = require("../testInterpreter") - -const CommandHandler = async (client, message, db) =>{ -// console.log(message) - if(!message) return; - if(message?.channel?.type === "dm" && client.messageEventOptions.guildOnly === false) return ; - if(message.author?.bot && client.messageEventOptions.respondToBots === false) return ; - const prefixes = [] - for(const prefix of client.prefix){ - if(prefix.startsWith("$")){ - prefixes.push( await Interpreter(client,message,message.content.split(" "),{name:"prefix",code:prefix},client.db,true) ) - } - else{ - prefixes.push(prefix) - } - } - for(const prefix of prefixes){ - const args = message.content.slice(prefix.length).trim().split(" ") - const cmdName = args.shift().toLowerCase() -if(message.content.toLowerCase().startsWith(prefix.toLowerCase())){ - - const cmd = client.cmd.default.filter(x=>(x.name?.toLowerCase() === cmdName) || (Array.isArray(x.aliases) ? (x.aliases?.find(x=>x.toLowerCase() === cmdName)) : (x.aliases?.toLowerCase() === cmdName))).allValues() - for(const command of cmd){ - - if(command.asynchronous === true){ -await Interpreter(client,message,args,command) - } - else{ -Interpreter(client,message,args,command) - } - } -} - - } - } - - -module.exports = CommandHandler \ No newline at end of file diff --git a/package/Handler/guildMessages/updateMessage.js b/package/Handler/guildMessages/updateMessage.js deleted file mode 100644 index 03d587f09..000000000 --- a/package/Handler/guildMessages/updateMessage.js +++ /dev/null @@ -1,13 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldm,newm, client)=>{ - let chan; -for(const cmd of client.cmd.messageUpdate.allValues()){ - const id = cmd.channel.includes("$")?await Interpreter(client,newm,[],{name:"channelParser",code:cmd.channel},client.db,true):{code :cmd.channel } -let channel = client.channels.cache.get(id) -if(!channel) channel = newm.channel - chan = channel - await Interpreter(client,newm,newm?. content?.split(" "),cmd, client.db,false, undefined,{oldm:oldm},chan) - - -} -} \ No newline at end of file diff --git a/package/Handler/guildPresences/update.js b/package/Handler/guildPresences/update.js deleted file mode 100644 index 3649e324a..000000000 --- a/package/Handler/guildPresences/update.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (op,np,client)=> { -const cmds = client.cmd.presenceUpdate.allValues() -for(const cmd of cmds){ - let chan; - const data = { - guild:np.guild, - client:client, - author:np.user, - member:np.member - } - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel?? undefined - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id||"",{oldPresence:op,newPresence:np},chan||undefined) -} -} \ No newline at end of file diff --git a/package/Handler/guildVoiceStates/update.js b/package/Handler/guildVoiceStates/update.js deleted file mode 100644 index d12f56263..000000000 --- a/package/Handler/guildVoiceStates/update.js +++ /dev/null @@ -1,19 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (os,ns,client)=> { -const cmds = client.cmd.voiceStateUpdate.allValues() -for(const cmd of cmds){ - let chan; - const data = { - guild:os.guild, - client:client, - author:ns.member.user, - member:ns.member - } - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel?? undefined - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id||"",{oldVoiceState:os,newVoiceState:ns},chan||undefined) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/channelCreate.js b/package/Handler/guilds/channelCreate.js deleted file mode 100644 index 1b05fe9d4..000000000 --- a/package/Handler/guilds/channelCreate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (newc,client) =>{ -const cmds = client.cmd.channelCreate.allValues() -const data = {guild:newc.guild,channel:newc,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newc:newc},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/channelDelete.js b/package/Handler/guilds/channelDelete.js deleted file mode 100644 index 8af48e359..000000000 --- a/package/Handler/guilds/channelDelete.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldc,client) =>{ -const cmds = client.cmd.channelDelete.allValues() -const data = {guild:oldc.guild,channel:oldc,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldc:oldc},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/channelPinsUpdate.js b/package/Handler/guilds/channelPinsUpdate.js deleted file mode 100644 index b662092f0..000000000 --- a/package/Handler/guilds/channelPinsUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (updatedPinsChannel, time,client) =>{ -const cmds = client.cmd.channelPinsUpdate.allValues() -const data = {guild:updatedPinsChannel.guild,channel:updatedPinsChannel,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{channel:updatedPinsChannel,time:time},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/channelUpdate.js b/package/Handler/guilds/channelUpdate.js deleted file mode 100644 index 4a2f6345f..000000000 --- a/package/Handler/guilds/channelUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldc,newc,client) =>{ -const cmds = client.cmd.channelUpdate.allValues() -const data = {guild:newc.guild,channel:newc,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldc:oldc,newc:newc},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/guildJoin.js b/package/Handler/guilds/guildJoin.js deleted file mode 100644 index 4eadc3f07..000000000 --- a/package/Handler/guilds/guildJoin.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (guild,client) =>{ -const cmds = client.cmd.guildJoin.allValues() -const data = {guild:guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newg : guild },chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/guildLeave.js b/package/Handler/guilds/guildLeave.js deleted file mode 100644 index 36aa3b843..000000000 --- a/package/Handler/guilds/guildLeave.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (guild,client) =>{ -const cmds = client.cmd.guildLeave.allValues() -const data = {guild:guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/guildUnavailable.js b/package/Handler/guilds/guildUnavailable.js deleted file mode 100644 index 09aa72904..000000000 --- a/package/Handler/guilds/guildUnavailable.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (guild,client) =>{ - let chan; -const cmds = client.cmd.guildLeave.allValues() -const data = {guild:guild,client:client} -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db,false, chan?.id,{},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/guildUpdate.js b/package/Handler/guilds/guildUpdate.js deleted file mode 100644 index df014a39b..000000000 --- a/package/Handler/guilds/guildUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldg,newg,client) =>{ - let chan; -const cmds = client.cmd.guildUpdate.allValues() -const data = {guild:newg,client:client} -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db,false, chan?.id,{oldg:oldg,newg:newg},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/roleCreate.js b/package/Handler/guilds/roleCreate.js deleted file mode 100644 index ef859f204..000000000 --- a/package/Handler/guilds/roleCreate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (role,client) =>{ -const cmds = client.cmd.roleCreate.allValues() -const data = {guild:role.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newr:role},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/roleDelete.js b/package/Handler/guilds/roleDelete.js deleted file mode 100644 index 74d3b5dd1..000000000 --- a/package/Handler/guilds/roleDelete.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (role,client) =>{ -const cmds = client.cmd.roleDelete.allValues() -const data = {guild:role.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldc:role},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/roleUpdate.js b/package/Handler/guilds/roleUpdate.js deleted file mode 100644 index 3889dc4ca..000000000 --- a/package/Handler/guilds/roleUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldr,newr,client) =>{ -const cmds = client.cmd.roleUpdate.allValues() -const data = {guild:newr.guild,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newr:newr,oldr:oldr},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/stageInstanceCreate.js b/package/Handler/guilds/stageInstanceCreate.js deleted file mode 100644 index e829fa127..000000000 --- a/package/Handler/guilds/stageInstanceCreate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (stageint,client) =>{ -const cmds = client.cmd.stageInstanceCreate.allValues() -const data = {guild:stageint.guild,channel:stageint,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newStageInstance:stageint},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/stageInstanceDelete.js b/package/Handler/guilds/stageInstanceDelete.js deleted file mode 100644 index b6e39d304..000000000 --- a/package/Handler/guilds/stageInstanceDelete.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (stageint,client) =>{ -const cmds = client.cmd.stageInstanceDelete.allValues() -const data = {guild:stageint.guild,channel:stageint,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldc:stageint},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/stageInstanceUpdate.js b/package/Handler/guilds/stageInstanceUpdate.js deleted file mode 100644 index 1b6e9036d..000000000 --- a/package/Handler/guilds/stageInstanceUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldstageint,newstageint,client) =>{ -const cmds = client.cmd.stageInstanceUpdate.allValues() -const data = {guild:newstageint.guild,channel:newstageint.channel,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldStageInstance:oldstageint,newStageInstance:newstageint},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/threadCreate.js b/package/Handler/guilds/threadCreate.js deleted file mode 100644 index 702f8670e..000000000 --- a/package/Handler/guilds/threadCreate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (thread,client) =>{ -const cmds = client.cmd.threadCreate.allValues() -const data = {guild:thread.guild,channel:thread,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newc:thread},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/threadDelete.js b/package/Handler/guilds/threadDelete.js deleted file mode 100644 index 3d8105063..000000000 --- a/package/Handler/guilds/threadDelete.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (thread,client) =>{ -const cmds = client.cmd.threadDelete.allValues() -const data = {guild:thread.guild,channel:thread,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldc:thread},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/threadListSync.js b/package/Handler/guilds/threadListSync.js deleted file mode 100644 index 2d37592a7..000000000 --- a/package/Handler/guilds/threadListSync.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (threadCollection,client) =>{ -const cmds = client.cmd.threadListSync.allValues() -const data = {guild:threadCollection.first().guild,channel:threadCollection.first(),client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{threadListSync:threadCollection},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/threadMemberUpdate.js b/package/Handler/guilds/threadMemberUpdate.js deleted file mode 100644 index a224f8dec..000000000 --- a/package/Handler/guilds/threadMemberUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldm,newm,client) =>{ -const cmds = client.cmd.threadMemberUpdate.allValues() -const data = {guild:oldm.thread?.guild||newm.thread?.guild,channel:oldm.thread||newm.thread,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldm:oldm,newm:newm},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/threadMembersUpdate.js b/package/Handler/guilds/threadMembersUpdate.js deleted file mode 100644 index 71b5eef2e..000000000 --- a/package/Handler/guilds/threadMembersUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldmCollection,newmCollection,client) =>{ -const cmds = client.cmd.threadMemberUpdate.allValues() -const data = {guild:oldmCollection.first().thread?.guild||newmCollection.first().thread?.guild,channel:oldmCollection.first().thread||newmCollection.first().thread,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{oldThreadMembers:oldmCollection,newThreadMembers:newmCollection},chan) -} -} \ No newline at end of file diff --git a/package/Handler/guilds/threadUpdate.js b/package/Handler/guilds/threadUpdate.js deleted file mode 100644 index f13da4657..000000000 --- a/package/Handler/guilds/threadUpdate.js +++ /dev/null @@ -1,18 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oldt,newt,client) =>{ -const cmds = client.cmd.threadUpdate.allValues() -const data = {guild:newt.guild,channel:newt,client:client} -let chan; -for(const cmd of cmds){ - if(cmd?.channel?.includes("$")){ - const id = await Interpreter (client,data,[],{name:"ChannelParser",code:cmd?.channel},client.db,true) - const channel = client.channels.cache.get(id?.code) - chan = channel - } - else { - const channel = client.channels.cache.get(cmd.channel) - chan = channel - } - await Interpreter(client,data,[],cmd,client.db, false,chan?.id,{newc:newt,oldc:oldt},chan) -} -} \ No newline at end of file diff --git a/package/Handler/lavalink/trackEvent.js b/package/Handler/lavalink/trackEvent.js deleted file mode 100644 index 8c2d5220d..000000000 --- a/package/Handler/lavalink/trackEvent.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * - * @param {import("lavacoffee").CoffeeTrack} track - * @param {import("lavacoffee").CoffeePlayer} player - * @param {import("../../classes/Lavalink")} lava - * @param {{name: string, code: string, channel: string}[]} commands - */ -module.exports = async (commands, track, player, lava, reason) => { - /** @type {import("discord.js").GuildMember} */ - const member = track.requester; - const client = member.client; - let chan; - let data = { - guild: member.guild, - channel: player.text, - author: member.user, - member, - client - } - if (reason) data["array"] = [reason] - for (const cmd of commands){ - const id = cmd.channel.includes("$")? await client.functionManager.interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel,functions:client.functionManager.findFunctions(cmd.channel)},client.db,true) : {code : cmd.channel} - chan = client.channels.cache.get(id?.code); - await client.functionManager.interpreter(client, data,[],cmd,client.db,false,chan?.id,{ track },chan) - } -} \ No newline at end of file diff --git a/package/Handler/music/class/Cacher.js b/package/Handler/music/class/Cacher.js deleted file mode 100644 index 6c5859b3a..000000000 --- a/package/Handler/music/class/Cacher.js +++ /dev/null @@ -1,24 +0,0 @@ -const Group = require('../../../CacheHandler/index.js').limitedCache -const fs = require('fs') -class Cacher { - constructor(limit=50){ - this.cache = new Group(limit) - this.limit = limit - } - cache(id,stream,guildId){ -if(this.cache.size < this.limit){ - if(!fs.existSync(process.cwd()+'/music')){ - fs.mkdirSync(process.cwd()+'/music') - } - if(!fs.existSync(process.cwd()+'/music/'+guildId)){ - fs.mkdirSync(process.cwd()+'/music/'+guildId) - } - const path = process.cwd()+`/music/${guildId}/${id}` - fs.open(path,"w",()=>{}) - const writeable = fs.createWriteStream(path) - stream.pipe(writeable) - this.cache.set(id,path) - } -} -} -module.exports = Cacher \ No newline at end of file diff --git a/package/Handler/music/class/FFmpeg.js b/package/Handler/music/class/FFmpeg.js deleted file mode 100644 index aabc70cfc..000000000 --- a/package/Handler/music/class/FFmpeg.js +++ /dev/null @@ -1,45 +0,0 @@ -const prism = require('prism-media') -const {PassThrough } = require('stream') -class FFmpeg { - constructor(){ - this.filters = ["aresample=48000"] - this.seekTo = "00:00:00" - this.args = [ - '-analyzeduration', '0', - '-loglevel', '0', - '-f', 's16le', - '-ar', '48000', - '-ac', '2', - '-ss',this.seekTo, - '-af',this.filters?.join(",") - ] - - } - transformStream(stream){ - this.seekTo = "00:00:00" - const ffmpeg = new prism.FFmpeg({ - args: this.args - }) - const opus = new prism.opus.Encoder({ rate: 48000, channels: 2, frameSize: 960 }) - return stream.pipe(ffmpeg).pipe(opus) - } - setSeekTo(timestamp){ - this.seekTo = timestamp/1000 - } - addFilters(...filters){ - if(!this.args.includes("-af")) this.args.push("-af") - - this.filters.concat(filters) - } - patchFilters(...filters){} - removeFilters(...filters){} - setFilters(...filters){ - if(!this.args.includes("-af")) this.args.push("-af") - - this.filters =filters - const index = this.args.indexOf("-af") - this.args[index+1] = this.filters?.join(",") -} - } - -module.exports = FFmpeg; \ No newline at end of file diff --git a/package/Handler/music/class/Search.js b/package/Handler/music/class/Search.js deleted file mode 100644 index f24893a14..000000000 --- a/package/Handler/music/class/Search.js +++ /dev/null @@ -1,80 +0,0 @@ -const ytsr = require('youtube-sr').default -//const {AxiosInstance} = require('axios') -const scdl = require('soundcloud-downloader').default -const ytdl = require('ytdl-core-discord') -class Youtube { - get baseYtUrl(){ - return ["https://youtube.com","www.youtube.com","https://m.youtube.com","https://youtu.be/"] - } - async search(track,options={limit:1}){ - if(this.baseYtUrl.some(x=>track.startsWith(x))){ - if(track.includes("playlist?list=")){ - console.log("playlist worked") - let playlist = await ytsr.getPlaylist(track) - if(playlist.videoCount>100){ - playlist = await playlist.fetch() - } - return playlist.videos.map(x=>x.id) - } - else return [track.split("/").pop()] - } - else{ - const vid = (await ytsr.search(track,options)) - return vid.map(x=>x.id) - } - } - async getData(url,yt){ - const info = await ytdl.getInfo(url,yt) - const stream = await ytdl.downloadFromInfo(info,yt) - return {info,stream} - } - async getStream(info,yt){ - const stream = await ytdl.downloadFromInfo(info,yt) - return stream - } -} -class SoundCloud { - get baseScUrl(){ - return ["https://soundcloud.com/","https://m.soundcloud.com"] - } - parseUrl(url){ - return url.replace("https://m.soundcloud.com","https://soundcloud.com") - } - async search(track,sc, limit=1){ - if(this.baseScUrl.some(x=>track.startsWith(x))){ - if(track.split("/")[4] === "sets"){ - const set = await scdl.getSetInfo(track,sc?.clientId) -return set.tracks.map(x=>x.permalink_url) - } - else if(track.endsWith("/likes")){ - const arr = track.split("/") - arr.pop() - const likeUrl = arr.join("/") - const {collection} = await scdl.getLikes({profileUrl:likeUrl},sc?.clientId) - return collection.map(x=>x.track.permalink_url) - } - else return [track] - } - else{ - const {collection} = await scdl.search({limit:limit, query:track}) - return Array.isArray(collection) ? [collection[0].permalink_url] : [collection.permalink_url] - } - } - async getData(url,sc){ - const info = await scdl.getInfo(url,sc?.clientId) - const stream = await scdl.download(url,sc?.clientId) - return {info,stream} - } - async transcodStream(link,sc){ - /* const sx = require('soundcloud-downloader/dist/download-media'). default - const media = await sx(link,sc?.clientId||"",require("axios")) - return media */ - } -} -class Search { - constructor(){ - this.Youtube = new Youtube() - this.SoundCloud = new SoundCloud() - } -} -module.exports = Search ; \ No newline at end of file diff --git a/package/Handler/music/class/ServerManager.js b/package/Handler/music/class/ServerManager.js deleted file mode 100644 index ad04061f0..000000000 --- a/package/Handler/music/class/ServerManager.js +++ /dev/null @@ -1,294 +0,0 @@ -const v = require('@discordjs/voice') -const fs= require('fs') - -const Track = require('./Track.js') -const Cacher = require('./Cacher.js') -const Search = require('./Search.js') -const FFmpeg = require('./FFmpeg.js') -const wait = (ms)=> new Promise(res=>res(),ms) -//const MusicPool = require('./MusicPool.js') -const {States,Events} = require('../../../Utils/VoiceConstants.js') -class ServerManager { - constructor(options={}){ - this.textChannel= options.textChannel - this.connection = options.connection - this.channel = options.channel - this.voice = options.voice - this.queue = [] - this.cacher = new Cacher() - this.search = new Search() - this.ffmpeg = new FFmpeg() - // this.musicPool = new MusicPool() - this.player = v.createAudioPlayer({debug: true}) - this.resource = v.createAudioResource - this.singleTrack = null - this._defaultOptions() - this._defaultStates() - this._configPlayer() - this._configConnection() - } - //public methods - async addTrack(track,type,member){ - if(type===0){ - const urls = await this.search.Youtube.search(track) - console.log(urls) - for(const url of urls){ - const yt = await this.search.Youtube.getData(url,this.voice.ytdl) - const stream = await this.ffmpeg.transformStream(yt.stream)//yt.stream - const resource = this.resource(stream,{inlineVolume:true}) - this.queue.push(new Track(yt.info,stream, resource,type,member)) - if(this.queue.length === 1){ - this._playTrack() - } - await wait(5000) - } - } - if(type===1){ - const urls = await this.search.SoundCloud.search(track) - for(const url of urls){ - try { - const sc = await this.search.SoundCloud.getData(url,this.voice.scdl) - const stream =/*await this.ffmpeg.transformStream(sc.stream)*/sc.stream - const resource = this.resource(stream,{inlineVolume:true}) - this.queue.push(new Track(sc.info,stream, resource,type,member)) - if(this.queue.length === 1){ - this._playTrack() - } - //await wait(5000) - } - - catch(e){ - console.error(e) - continue; - } - } - } - if(type===2){ - const trackStream = fs.createReadStream(process.cwd()+'/'+track) - const stream = await this.ffmpeg.transformStream(trackStream)//trackStream - const resource = this.resource(stream,{inlineVolume:true}) - this.queue.push(new Track(track,stream, resource,type,member)) - if(this.queue.length === 1){ - return this._playTrack() - } - - } - } - pause(){ - this.options.paused = true - this.player.pause() - } - resume(){ - this.options.paused = false - this.player.unpause() - } - skip(){} - - setFilters(...filters){ - this.ffmpeg.seekTo = (this.queue[0]. currentDuration/1000).toFixed(0) - this.ffmpeg.setFilters(...filters) - if(this.queue[0].type === 2){ - const raw = fs.createReadStream(process.cwd()+`/${this.queue[0].info.name}`) - const stream = this.ffmpeg.transformStream(raw) - const res = this.resource(stream,{inlineVolume:true}) - this.queue[0].stream = stream - this.queue[0].resource = res - this.player.play(res) - } - - } - - //private methods - _playSingleTrack(){ - if(this.singleTrack.type === 0){ - if(this.voice.cache.enabled){ - const stream = fs.createReadStream(process.cwd()+`/music/${this.channel.guild.id}/${this.singleTrack.Id}.mp4`) - const resource = this.resource(stream,{inlineVolume:true}) - this.player.play(resource) - } - else{ - const stream = this.search.Youtube.getStream(this.singleTrack.info.url) - const resource = this.resource(stream,{inlineVolume:true}) - this.player.play(resource) - } - } - if(this.singleTrack.type === 1){ - const stream = this.search.SoundCloud.transcodeUrl(this.singleTrack.rawInfo.transcodings[0].url) - const resource = this.resource(stream,{inlineVolume:true}) - this.player.play(resource) - } - if(this.singleTrack.type === 2){ - const stream = fs.createReadStream(process.cwd()+`/${this.singleTrack.queue.name}`) - const resource = this.resource(stream,{inlineVolume:true}) - this.player.play(resource) - } - } - async _loopQueue(){ - const queue = this.queue.shift() - if(queue.type === 0){ - if(this.voice.cache.enabled){ - const ytstream = fs.createReadStream(process.cwd()+`/music/${this.channel.guild.id}/${queue.info.Id}.mp4`) - const stream = await this.ffmpeg.transformStream(ytstream) - const resource = this.resource(stream,{inlineVolume: true}) - queue.stream = stream - queue.resource = resource - this.queue.push(queue) - } - else { - const ytstream = this.search.Youtube.getStream(queue.info.url) - const stream = await this.ffmpeg.transformStream(ytstream) - const resource = this.resource(stream,{inlineVolume:true}) - queue.stream = stream - queue.resource = resource - this.queue.push(queue) - this._playTrack() - } - } - if(queue.type === 1){ - const stream = await this.search.SoundCloud.transcodStream(queue.rawInfo.media.transcodings[0],this.voice.scdl) - const resource = this.resource(stream,{inlineVolume:true}) - queue.stream = stream - queue.resource = resource - this.queue.push(queue) - this._playTrack() - } - if(queue.type === 2){ - const stream = fs.createReadStream(process.cwd()+`/${queue.info.name}`) - const resource = this.resource(stream,{inlineVolume:true}) - queue.stream = stream - queue.resource = resource - - this.queue.push(queue) - this._playTrack() - } - - } - _playNextTrack(){ - this.queue.shift() - this._playTrack() - } - async _playTrack(){ - this.player.play(this.queue[0].resource) - try{ - await v.entersState(this.player,v.AudioPlayerStatus.Playing,10000) - this.voice.emit(Events.TRACK_START,this.queue[0],this) - } - catch(e){ - console.error(e) - // this._destroyPlayer() - } - } - _destroyPlayer(){ - this.queue = [] - this._defaultOptions() - this._defaultStates() - } - //{@Default_Methods} - _defaultOptions(){ - this.options = { - paused:false, - loopQueue:false, - loopSong:false, - volume:100, - leaveAfter:{enabled:false,time:60000}, - leaveWhenVcEmpty:false - } - } - _defaultStates(){ - this.states = { - queue:States.queue.IDLE, - loop:States.loop.NONE, - player:this.player.state.status - } - } - _configPlayer(){ - this.player.on("stateChange",async(os,ns)=>{ console.log([os.status,ns.status]?.join("|")) - if(os.status !== v.AudioPlayerStatus.Idle && ns.status === v.AudioPlayerStatus.Idle){ - if(this.options.paused) return ; - else if(this.options.loopSong && this.singleTrack){ - this._playSingleTrack() - } - else if(this.options.loopQueue && this.queue.length){ - this._loopQueue() - } - else if(this.queue.length > 1){ - this._playNextTrack() - } - else{ - //this._destroyPlayer() - } - } - }) - this.player.on("error",async message => console.error(message)) - this.player.on("debug",console.log) - this.connection.subscribe(this.player) - } - _configConnection(){ - this.connection.on('stateChange', async (_, newState) => { - console.log([newState.status,newState.closeCode,newState.reason]?.join("\n")) - - if (newState.status === v.VoiceConnectionStatus.Disconnected) { - if (newState.reason === v.VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) { - - /* - If the WebSocket closed with a 4014 code, this means that we should not manually attempt to reconnect, - but there is a chance the connection will recover itself if the reason of the disconnect was due to - switching voice channels. This is also the same code for the bot being kicked from the voice channel, - so we allow 5 seconds to figure out which scenario it is. If the bot has been kicked, we should destroy - the voice connection. - */ - try { - await v.entersState(this.connection, v.VoiceConnectionStatus.Connecting, 5_000); - // Probably moved voice channel - } catch { - this.connection.destroy(); - // Probably removed from voice channel - } - } else if (this.connection.rejoinAttempts < 5) { - /* - The disconnect in this case is recoverable, and we also have <5 repeated attempts so we will reconnect. - */ - await wait((this.connection.rejoinAttempts + 1) * 5_000); - this.connection.rejoin(); - } else { - /* - The disconnect in this case may be recoverable, but we have no more remaining attempts - destroy. - */ - this.connection.destroy(); - } - } else if (newState.status === v.VoiceConnectionStatus.Destroyed) { - /* - Once destroyed, stop the subscription - */ - this.stop(); - } else if ( - - (newState.status === v.VoiceConnectionStatus.Connecting || newState.status === v.VoiceConnectionStatus.Signalling) - ) { - /* - In the Signalling or Connecting states, we set a 20 second time limit for the connection to become ready - before destroying the voice connection. This stops the voice connection permanently existing in one of these - states. - */ - this.readyLock = true; - try { - await v.entersState(this.connection, v.VoiceConnectionStatus.Ready, 20_000); - } catch { - if (this.connection.state.status !== v.VoiceConnectionStatus.Destroyed) this.connection.destroy(); - } finally { - this.readyLock = false; - } - } - }); - } - stop() { - - this.queueLock = true; - - this.queue = []; - - this.player.stop(true); - - } -} -module.exports = ServerManager ; \ No newline at end of file diff --git a/package/Handler/music/class/Track.js b/package/Handler/music/class/Track.js deleted file mode 100644 index f9e8e2734..000000000 --- a/package/Handler/music/class/Track.js +++ /dev/null @@ -1,67 +0,0 @@ -const {TrackType} = require('../../../Utils/VoiceConstants.js') -class Track { - constructor(info,stream, resource,type,member){ - this.stream = stream - this.resource = resource - this.rawInfo = info - this.createInfo(info,type) - // this.platform = TrackType[type] - this.user = member - this.type = type - } - createInfo(info, type){ - if(type === 0){ - info = info.videoDetails - this.info = { - title : info.title, - description:info.description, - publisher:{ - profileUrl:info.ownerProfileUrl, - name:info.ownerChannelName, - thumbnail:info.author.thumbnails[0]?.url - }, - views:info.viewCount, - genre:info.category, - publishedAt:info.publishDate, - Id:info.videoId, - url:info.video_url, - likes:info.likes, - dislikes:info.dislikes, - thumbnail:info.thumbnails[0]?.url, - duration:info.lengthSeconds*1000 - } - } - if(type === 1){ - this.info = { - title : info.title, - description:info.description, - publisher:{ - profileUrl:info.user.permalink_url, - name:info.user.username, - thumbnail:info.user.avatar_url - }, - views:info.playback_count, - genre:info.genre, - publishedAt:info.createdAt, - Id:info.id, - url:info.permalink_url, - likes:info.likes_count, - dislikes:null, - thumbnail:info.artwork_url, - duration:info.duration - } - } - if(type === 2){ - this.info = { - name:info - } - } - } - get durationLeft(){ - return this.info.duration - this.resource.duration - } - get currentDuration(){ - return this.resource.duration - } -} -module.exports = Track \ No newline at end of file diff --git a/package/Handler/music/events/musicStart.js b/package/Handler/music/events/musicStart.js deleted file mode 100644 index f38dfe7fc..000000000 --- a/package/Handler/music/events/musicStart.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = async (track,server, voice,client)=>{ - //console.log(track) - const cmds = voice.cmd.musicStart.allValues() - let chan ; - let data ={ - guild: server.channel.guild, - channel:server.textChannel - } - for(const cmd of cmds){ - const id = cmd.channel.includes("$")? await client.functionManager.interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel,functions:client.functionManager.findFunctions(cmd.channel)},client.db,true) : {code : cmd.channel} - chan = client.channels.cache.get(id?.code) - await client.functionManager.interpreter(client, data,[],cmd,client.db,false,chan?.id,{track:track},chan) -} -} \ No newline at end of file diff --git a/package/Handler/nonIntents/appCmdCreate.js b/package/Handler/nonIntents/appCmdCreate.js deleted file mode 100644 index 404626323..000000000 --- a/package/Handler/nonIntents/appCmdCreate.js +++ /dev/null @@ -1,17 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (app,client)=>{ -const cmds = client.cmd.applicationCmdCreate.allValues() -let chan; - const data = { - guild:app.guild, - client:client - } - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } -await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{newapp:app},chan) - } - -} \ No newline at end of file diff --git a/package/Handler/nonIntents/appCmdDelete.js b/package/Handler/nonIntents/appCmdDelete.js deleted file mode 100644 index fac0939f5..000000000 --- a/package/Handler/nonIntents/appCmdDelete.js +++ /dev/null @@ -1,17 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (app,client)=>{ -const cmds = client.cmd.applicationCmdDelete.allValues() -let chan; - const data = { - guild:app.guild, - client:client - } - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } -await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{oldapp:app},chan) - } - -} \ No newline at end of file diff --git a/package/Handler/nonIntents/appCmdUpdate.js b/package/Handler/nonIntents/appCmdUpdate.js deleted file mode 100644 index 52ae7c61a..000000000 --- a/package/Handler/nonIntents/appCmdUpdate.js +++ /dev/null @@ -1,17 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (oa,na,client)=>{ -const cmds = client.cmd.applicationCmdUpdate.allValues() -let chan; - const data = { - guild:na.guild, - client:client - } - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } -await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{newapp:na,oldapp:oa},chan) - } - -} \ No newline at end of file diff --git a/package/Handler/nonIntents/interaction.js b/package/Handler/nonIntents/interaction.js deleted file mode 100644 index 9683cbf2e..000000000 --- a/package/Handler/nonIntents/interaction.js +++ /dev/null @@ -1,32 +0,0 @@ -const Interpreter = require('../../interpreter.js') -const { InteractionTypes, MessageComponentTypes } = require('../../Utils/InteractionConstants.js') -module.exports = async (interaction, client) => { - client.interactionManager.resolve(interaction) - if (interaction.isMessageComponent()) { - client.interactionManager.emit("messageComponentInteraction", interaction) - } - console.log(require('util').inspect(interaction, { depth: 0, showHidden: true })) - let cmds; - if (InteractionTypes[interaction.type] === "component") { - cmds = client.cmd.interaction[MessageComponentTypes[interaction.componentType]].filter(x => x.name ? (Array.isArray(x.name) ? x.name.includes(interaction.customId) : x.name === interaction.customId) : !x.name).allValues() - // console.log(cmds) - } - else { - cmds = client.cmd.interaction.slash.filter(x => x.name.toLowerCase() === interaction.commandName.toLowerCase()).allValues() - - } - console.log({cmds}) - if (!cmds.length) return; - const data = { - client: client, - guild: interaction.guild, - message: interaction?.message, - channel: interaction.channel, - author: interaction.author, - member: interaction.member - } - for (const cmd of cmds) { - await Interpreter(client, data, [], cmd, client.db, false, undefined, { interaction: interaction }, undefined) - } - -} \ No newline at end of file diff --git a/package/Handler/nonIntents/rateLimit.js b/package/Handler/nonIntents/rateLimit.js deleted file mode 100644 index 4a2c39c4c..000000000 --- a/package/Handler/nonIntents/rateLimit.js +++ /dev/null @@ -1,16 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (rl,client)=>{ -const cmds = client.cmd.rateLimit.allValues() -let chan; - const data = { - client:client - } - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - } -await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{rateLimit:rl},chan) - } - -} \ No newline at end of file diff --git a/package/Handler/nonIntents/ready.js b/package/Handler/nonIntents/ready.js deleted file mode 100644 index 46f339749..000000000 --- a/package/Handler/nonIntents/ready.js +++ /dev/null @@ -1,21 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (client)=>{ -const cmds = client.cmd.ready.allValues() -let chan; - const data = { - client:client - } - for(const cmd of cmds){ - if(cmd.channel?.includes("$")){ - const id = await Interpreter(client,data,[],{name:"ChannelParser",code:cmd.channel},client.db,true) - chan = client.channels.cache.get(id?.code) - data.channel = chan - data.guild = chan.guild - } -await Interpreter(client,data,[],cmd,client.db,false,chan?.id,{},chan) - } - console.log('Initialized on \x1b[36maoi.js \x1b[0m|| \x1b[32mv' + require("../../../package.json").version + '\x1b[0m'); - console.log( - "Our Official Discord Server: https://aoi.js.org/invite" - ); -} \ No newline at end of file diff --git a/package/Handler/nonIntents/userUpdate.js b/package/Handler/nonIntents/userUpdate.js deleted file mode 100644 index 83a37a204..000000000 --- a/package/Handler/nonIntents/userUpdate.js +++ /dev/null @@ -1,17 +0,0 @@ -const Interpreter = require('../../interpreter.js') -module.exports = async (ou, nu, client) => { - const cmds = client.cmd.userUpdate.allValues() - let chan; - const data = { - author: nu, - client: client - } - for (const cmd of cmds) { - if (cmd.channel?.includes("$")) { - const id = await Interpreter(client, data, [], { name: "ChannelParser", code: cmd.channel }, client.db, true) - chan = client.channels.cache.get(id?.code) - } - await Interpreter(client, data, [], cmd, client.db, false, chan?.id, { olduser: ou, newuser: nu }, chan) - } - -} \ No newline at end of file diff --git a/package/Handler/parsers.js b/package/Handler/parsers.js deleted file mode 100644 index fa672a863..000000000 --- a/package/Handler/parsers.js +++ /dev/null @@ -1,561 +0,0 @@ -const Discord = require('discord.js') -const Util = require("../classes/Util.js") -const interpreter = require("../interpreter.js") - -const { mustEscape } = require('../Utils/helpers/mustEscape.js') -const { ButtonStyleOptions } = require('../Utils/Constants.js') -const SlashOption = require('./slashOption.js') -const { Time } = require('../Utils/helpers/customParser.js') -const EmbedParser = async (msg) => { - msg = (mustEscape(msg)) - - const embeds = [] - - - let msgs = msg.split("{newEmbed:").slice(1) - for (let rawr of msgs) { - rawr = rawr.slice(0, rawr.length - 1) - // console.log(rawr) - const embed = {} - embed.fields = [] - const Checker = (peko) => rawr.includes(`{${peko}:`) - if (Checker("author")) { - const auth = rawr.split("{author:")[1].split("}")[0].split(":") - embed.author = { - name: auth.shift().addBrackets() || "", - iconURL: auth.join(":").addBrackets() || "" - } - } - if (Checker("authorURL")) { - if (!embed.author) return console.error("{author:} was not used") - embed.author.url = rawr.split("{authorURL:")[1].split("}")[0].addBrackets() - } - if (Checker("title")) { - embed.title = rawr.split("{title:")[1].split("}")[0].addBrackets() - } - if (Checker("url")) { - if (!embed.title) return console.error("Title was not provided while using {url}") - embed.url = rawr.split("{url:")[1].split("}")[0].addBrackets() - } - if (Checker("description")) { - embed.description = rawr.split("{description:")[1].split("}")[0].addBrackets() - } - if (Checker("thumbnail")) { - embed.thumbnail = { - url: rawr.split("{thumbnail:")[1].split("}")[0].addBrackets() - } - } - if (Checker("image")) { - embed.image = { - url: rawr.split("{image:")[1].split("}")[0].addBrackets() - } - } - if (Checker("footer")) { - const f = rawr.split("{footer:")[1].split("}")[0].split(":") - embed.footer = { - text: f.shift().addBrackets() || "", - iconURL: f.join(":").addBrackets() || "" - } - } - if (Checker("color")) { - embed.color = Discord.Util.resolveColor(rawr.split("{color:")[1].split("}")[0].addBrackets()) - } - if (rawr.includes("{timestamp")) { - let t = rawr.split("{timestamp")[1].split("}")[0].replace(":", "") - if (t === "" || t === "ms") { t = Date.now() } - embed.timestamp = new Date(t) - } - if (Checker("field")) { - // console.log(typeof rawr) - const fi = rawr.split("{field:").slice(1) - for (let fo of fi) { - fo = fo.split("}")[0].split(":") - const fon = fo.shift().addBrackets() - const foi = ["yes", "no", "true", "false"].find(x => x === fo[Number(fo.length - 1)]) ? fo.pop()?.replace("yes", true)?.replace("no", false) : false - - const fov = fo.join(":").addBrackets() - embed.fields.push({ name: fon, value: fov, inline: foi }) - - } - } - if (Checker("fields")) { - const fie = rawr.split("{fields:").slice(1) - for (let fiel of fie) { - fiel = fiel.split("}")[0].split(":") - for (let oof of fiel) { - oof = oof.split(",") - const oofn = oof.shift().addBrackets() - const oofi = ["yes", "no", "true", "false"].find(x => x === oof[oof.length - 1]) ? oof.pop().replace("yes", true).replace("no", false) : false - const oofv = oof.join(",").addBrackets() - embed.fields.push({ name: oofn, value: oofv, inline: oofi }) - } - } - } - embeds.push(embed) - - } - return embeds -} -const ComponentParser = async (msg, client) => { - let components - msg = mustEscape(msg) - let msgs = msg.split("{actionRow:").slice(1) - const actionRows = [] - for (let nya of msgs) { - const index = nya.lastIndexOf("}") - nya = nya.slice(0, index) - - const buttonPart = [] - const Checker = (neko) => nya.includes("{" + neko + ":") - if (Checker("button")) { - const inside = nya.split("{button:").slice(1) - for (let button of inside) { - console.log(button) - button = button?.split("}")[0] - button = button?.split(":") - console.log(button) - const label = button.shift().addBrackets() - const btype = 2 - let style = isNaN(button[0]) ? button.shift() : Number(button.shift()) - style = ButtonStyleOptions[style] || style - const cus = button.shift().addBrackets() - const disable = button.shift()?.replace("yes", true)?.replace("no", false)?.replace("true", true)?.replace("false", false) || false - const emoji = button.length ? (button || "").join(":").trim().startsWith("<") ? client.emojis.cache.find(x => x.toString() === button.join(":")) : { name: button.split(",")[0], id: button.split(",")[1] || 0, animated: button.split(",")[2] || false } : undefined - const d = Number(style) === 5 ? { label: label, type: btype, style: style, url: cus, disabled: disable } : { label: label, type: btype, style: style, custom_id: cus, disabled: disable } - if (emoji) { - const en = emoji?.name - const eid = emoji?.id - const ea = emoji?.animated - d.emoji = { name: en, id: eid, animated: ea } - } - buttonPart.push(d) - } - } - if (Checker("selectMenu")) { - const selectMenu = [] - let inside = nya.split("{selectMenu:").slice(1).join("") - inside = inside.split(":") - const customID = inside.shift() - const placeholder = inside.shift() - const minVal = inside[0] === "" ? 0 : Number(inside.shift()) - const maxVal = inside[0] === "" ? 1 : Number(inside.shift()) - const options = inside.join(":").trim() - - let optArray = [] - if (options.includes("{selectMenuOptions:")) { - - const opts = options.split("{selectMenuOptions:").slice(1) - - for (let opt of opts) { - - opt = opt.split("}")[0].split(":") - const label = opt.shift() - const value = opt.shift() - const desc = opt.shift() - const def = opt.shift()?.replace("true", true)?.replace("false", false)?.replace("yes", true)?.replace("no", false) || false - const emoji = opt.length ? (opt || "").join(":").trim().startsWith("<") ? client.emojis.cache.find(x => x.toString() === opt.join(":")) : { name: opt.split(",")[0], id: opt.split(",")[1] || 0, animated: opt.split(",")[2] || false } : undefined - const ind = { - label: label, - value: value, - description: desc, - default: def, - } - if (emoji) { - const en = emoji?.name - const eid = emoji?.id - const ea = emoji?.animated - ind.emoji = { name: en, id: eid, animated: ea } - } - console.log(ind) - optArray.push(ind) - } - } - buttonPart.push({ type: 3, custom_id: customID, placeholder: placeholder, min_values: minVal, max_values: maxVal, options: optArray }) - } - actionRows.push({ type: 1, components: buttonPart }) - - } - return actionRows -} -const FileParser = (msg) => { - if (!msg) return; - msg = mustEscape(msg) - const Checker = (ayaya) => msg.includes("{" + ayaya + ":") - const att = [] - if (Checker("attachment")) { - - const e = msg?.split("{attachment:")?.slice(1) - for (let o of e) { - o = o.split("}")[0] - o = o.split(":") - const name = o.pop() - const url = o.join(":") - const attachment = new Discord.MessageAttachment(url, name) - att.push(attachment) - } - } - if (Checker("file")) { - const i = msg.split("{file:").slice(1) - for (let u of i) { - u = u.split("}")[0] - u = u.split(":") - const name = u.pop() - const text = u.join(":") - const attachment = new Discord.MessageAttachment(Buffer.from(text), name || "txt.txt") - att.push(attachment) - } - } - return att -} -const errorHandler = async (d, errorMessage, returnMsg = false, channel) => { - errorMessage = errorMessage.trim() - const embeds = [] - let deleteCommand = false - let send = true - - let deleteAfter - - let suppress = false - let files = [] - let reactions = [] - - let edits = { - time: null, - messages: [] - - } - if (errorMessage.includes("{edit:")) { - const inside = errorMessage.split("{edit:")[1].split("}}")[0] - - const duration = inside.split(":")[0] || 2500 - - for (const msg of inside.split(":{").slice(1).join(":{").split("}:{")) { - - const code = msg.split("}:{")[0] - console.log({ msgcode: code }) - edits.messages.push(code) - } - - edits.timeout = duration - - errorMessage = errorMessage.replace(`{edit:${inside}}}`, "") - } - - if (errorMessage.includes("{file:")) { - for (const after of errorMessage.split("{file:").slice(1)) { - const inside = after.split("}")[0] - const fields = inside.split(":") - const name = fields.pop().addBrackets() - const text = fields.join(":").addBrackets() - files.push(new Discord.MessageAttachment(Buffer.from(text), name)) - errorMessage = errorMessage.replace(`{file:${inside}}`, "") - } - } - if (errorMessage.includes("{suppress:")) { - const inside = errorMessage.split("{suppress:")[1].split("}")[0] - - suppress = inside === "yes" - - errorMessage = errorMessage.replace(`{suppress:${inside}}`, "") - } - - if (errorMessage.includes("{attachment:")) { - for (const after of errorMessage.split("{attachment:").slice(1)) { - const inside = after.split("}")[0]; let [name, ...url] = inside.split(":"); name = name.addBrackets(); url = url.join(":").addBrackets(); const attachment = new Discord.MessageAttachment(url, name); files.push(attachment); errorMessage = errorMessage.replace(`{attachment:${inside}}`, "") - } - } - - if (errorMessage.includes("{deletecommand")) { - const inside = errorMessage.split("{deletecommand")[1].split("}")[0] - deleteCommand = true - if (d && d.message) { - if (inside) { - const dur = Time.parse(inside.slice(1))?.ms; - d.message.delete({ - timeout: dur - }).catch(err => null) - } else d.message.delete().catch(err => null) - } - - errorMessage = errorMessage.replace(`{deletecommand${inside}}`, "") - } - if (errorMessage.includes("{delete:")) { - const duration = errorMessage.split("{delete:")[1].split("}")[0] - deleteAfter = Time.parse(duration || "1s")?.ms - errorMessage = errorMessage.replace(`{delete:${duration}}`, "") - } - - if (errorMessage.includes("{execute:")) { - const command = errorMessage.split("{execute:")[1].split("}")[0] - errorMessage = errorMessage.replace(`{execute:${command}}`, "") - const cmd = d.client.awaited_commands.find(c => c.name === command) - if (!cmd) return d.error(`:x: Invalid awaited command '${command}' in {execute:${command}}`) - await d.interpreter(d.client, d.message, d.args, cmd) - } - if (errorMessage.includes("{newEmbed:")) { - const o = errorMessage.split("{newEmbed:").slice(1) - for (let errorMessages of o) { - const index = (errorMessages).lastIndexOf("}") - errorMessages = (errorMessages).slice(0, index) - const old = (errorMessages) - console.log("e:" + old) - const embed = new Discord.MessageEmbed() - if (errorMessages.includes("{title:")) { - const inside = errorMessages.split("{title:")[1].split("}")[0] - embed.setTitle(inside.addBrackets()) - errorMessages = errorMessages.replace(`{title:${inside}}`, "") - } - - if (errorMessages.includes("{url:")) { - const url = errorMessages.split("{url:")[1].split("}")[0] - - if (embed.title) embed.setURL(url.addBrackets()) - - errorMessages = errorMessages.replace(`{url:${url}}`, "") - } - - if (errorMessages.includes("{timestamp")) { - const rest = errorMessages.includes("{timestamp:") ? errorMessages.split("{timestamp:")[1].split("}")[0] : "" - - embed.setTimestamp(Number(rest) || Date.now()) - - errorMessages = errorMessages.replace(`{timestamp${rest ? ":" + rest : ""}}`, "") - } - - if (errorMessages.includes("{author:")) { - const inside = errorMessages.split("{author:")[1].split("}")[0].split(":") - let to = inside.join(":") - const text = inside.shift() - const url = inside.join(":") - embed.setAuthor(text.addBrackets(), typeof url === "string" ? url.addBrackets() : undefined) - errorMessages = errorMessages.replace(`{author:${to}}`, "") - } - if (errorMessages.includes("{authorURL:")) { - const inside = errorMessages.split("{authorURL:")[1].split("}")[0] - if (embed.author) embed.author.url = inside - errorMessages = errorMessages.replace(`{authorURL:${inside}}`, "") - } - if (errorMessages.includes("{fields:")) { - const inside = errorMessages.split("{fields:").slice(1) - for (let o of inside) { - o = o.split("}")[0].split(":") - for (let i of o) { - //console.log(i) - i = i.split(",") - const ifn = i.shift() - const ifi = ["yes", "no", true, false].find(x => x == i[i.length - 1]) ? i.pop().replace("yes", true).replace("no", false) : false - const ifv = i.join(",") - //console.log(ifv) - embed.addField(ifn, ifv, ifi) - } - } - errorMessages = errorMessages.replace(`{fields:${inside}}`, "") - } - if (errorMessages.includes("{footer:")) { - const inside = errorMessages.split("{footer:")[1].split("}")[0].split(":") - let to = inside.join(":") - const text = inside.shift() - const url = inside.join(":") - embed.setFooter(text.addBrackets(), typeof url === "string" ? url.addBrackets() : undefined) - errorMessages = errorMessages.replace(`{footer:${to}}`, "") - } - - if (errorMessages.includes("{description:")) { - const inside = errorMessages.split("{description:")[1].split("}")[0] - embed.setDescription(inside.addBrackets()) - errorMessages = errorMessages.replace(`{description:${inside}}`, "") - } - - if (errorMessages.includes("{color:")) { - const inside = errorMessages.split("{color:")[1].split("}")[0] - embed.setColor(inside.addBrackets()) - errorMessages = errorMessages.replace(`{color:${inside}}`, "") - } - - if (errorMessages.includes("{thumbnail:")) { - const inside = errorMessages.split("{thumbnail:")[1].split("}")[0] - embed.setThumbnail(inside.addBrackets()) - errorMessages = errorMessages.replace(`{thumbnail:${inside}}`, "") - } - - if (errorMessages.includes("{field:")) { - const fields = errorMessages.split("{field:") - fields.shift() - for (const after of fields) { - const inside = after.split("}")[0].split(":") - let inline = false - let arg - if (inside.length > 2 && ["yes", "no"].some(w => inside[inside.length - 1] === w)) { - arg = inside.pop() - inline = arg === "yes" - } - embed.addField(inside[0].addBrackets(), inside.slice(1).join(":").addBrackets(), inline) - errorMessages = errorMessages.replace(`{field:${inside.join(":")}${arg ? `:${arg}` : ""}}`, "") - } - } - - if (errorMessages.includes("{image:")) { - const inside = errorMessages.split("{image:")[1].split("}")[0] - embed.setImage(inside.addBrackets()) - errorMessages = errorMessages.replace(`{image:${inside}}`, "") - } - errorMessage = errorMessage.replace("{newEmbed:" + old + "}", "") - console.log("{newEmbed:" + old + "}") - embeds.push(embed) - //console.log(embed) - } - } - if (errorMessage.includes("{reactions:")) { - const inside = errorMessage.split("{reactions:")[1].split("}")[0] - for (const reaction of inside.split(" ").join("").split(",")) { - reactions.push(reaction.addBrackets()) - } - errorMessage = errorMessage.replace(`{reactions:${inside}}`, "") - } - - if (!(embeds.length)) send = false - - if (send && suppress) send = false - - if (returnMsg === true) { - return { - reactions: reactions.length ? reactions : undefined, - suppress, - edits, - embeds: send ? embeds : [], - content: errorMessage.addBrackets(), - deleteIn: deleteAfter, - deleteCommand - } - } - - errorMessage = errorMessage.addBrackets().trim() - if (!(errorMessage.length || send || files.length)) return - - const ch = channel || d.channel - - - console.log({ errorMessage, embeds }) - if ((errorMessage.length || send || files.length) && d && ch && !returnMsg) { - const m = await ch.send({ - content: errorMessage.addBrackets(), - embeds: send ? embeds : [], - files: files?.length ? files : [] - }).catch(Err => { - }) - - if (!m) return - - if (m && reactions.length) { - for (const reaction of reactions) { - await m.react(reaction).catch(err => { }) - } - } - - if (m && edits.timeout) { - for (const code of edits.messages) { - await new Promise(e => setTimeout(e, edits.timeout)) - - const sender = await errorHandler(d, code, true) - - await m.suppressEmbeds(suppress) - - await m.edit(sender.message, sender.embed).catch(err => null) - - } - } - - if (m && deleteAfter) { - m.delete({ - timeout: deleteAfter - }).catch(err => null) - } - - if (returnMsg === "id") { - return m.id - } else if (returnMsg === "object") { - return m - } else if (returnMsg === "withMessage") return m - } -} -const SlashOptionsParser = async (options) => { - console.log("running") - options = mustEscape(options) - - - let Alloptions = [] - options = options.trim() - const Checker = (msg) => options.includes("{" + msg + ":") - console.log(options) - if (Checker("subGroup")) { - Alloptions = Alloptions.concat((await SlashOption.subGroup(options))) - } - if (Checker("subCommand") && !Checker("subGroup")) { - Alloptions = Alloptions.concat((await SlashOption.subCommand(options))) - } - if (Checker("string") && !(Checker("subCommand") || Checker("subGroup"))) { - console.log("string found") - console.log((await SlashOption.string(options))) - Alloptions = Alloptions.concat((await SlashOption.string(options))) - - } - if (Checker("integer") && !(Checker("subCommand") || Checker("subGroup"))) { - Alloptions = Alloptions.concat((await SlashOption.integer(options))) - } - if (Checker("boolean") && !(Checker("subCommand") || Checker("subGroup"))) { - Alloptions = Alloptions.concat((await SlashOption.boolean(options))) - } - if (Checker("user") && !(Checker("subCommand") || Checker("subGroup"))) { - Alloptions = Alloptions.concat((await SlashOption.user(options))) - } - if (Checker("channel") && !(Checker("subCommand") || Checker("subGroup"))) { - Alloptions = Alloptions.concat((await SlashOption.channel(options))) - } - if (Checker("role") && !(Checker("subCommand") || Checker("subGroup"))) { - Alloptions = Alloptions.concat((await SlashOption.role(options))) - } - if (Checker("mentionable") && !(Checker("subCommand") || Checker("subGroup"))) { - Alloptions = Alloptions.concat((await SlashOption.mentionable(options))) - } - if (Checker("number") && !(Checker("subCommand") || Checker("subGroup"))) { - Alloptions = Alloptions.concat((await SlashOption.number(options))) - } - console.log(Alloptions) - - return Alloptions -} -const OptionParser = async (options, d) => { - const Checker = msg => options.includes(msg) - const optionData = {} - if (Checker("edit")) { - const editPart = options.split("{edit:")[1].split("}}")[0] - const dur = editPart.split(":")[0] - const msgs = editPart.split(":{").slice(1).join(":{").split("}:{") - const messages = [] - for (const msg of msgs) { - console.log("raw message data:" + msg.split("}:{")[0]) - messages.push(await Util.errorParser(msg.split("}:{")[0], d)) - } - optionData.edits = { time: dur, messages } - } - if (Checker("reactions")) { - const react = options.split("{reactions:")[1].split("}")[0] - optionData.reactions = react.split(":") - } - if (Checker("delete")) { - optionData.deleteIn = Time.parse(options.split("{delete:")[1].split("}")[0] - )?.ms; - } - if (Checker("deletecommand")) { - optionData.deleteCommand = true - } - return optionData -} -module.exports = { - EmbedParser: EmbedParser, - ComponentParser: ComponentParser, - FileParser: FileParser, - ErrorHandler: errorHandler, - SlashOptionsParser: SlashOptionsParser, - OptionParser -} diff --git a/package/Handler/slashCommandOptionsParser.js b/package/Handler/slashCommandOptionsParser.js deleted file mode 100644 index 3c8ffd0e5..000000000 --- a/package/Handler/slashCommandOptionsParser.js +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = (fields) => { - - const object = [] - - - - for (const field of fields) { - - const [name, description, required = "true", type = 3] = field.split(":") - - - - object.push({ - - name, - - description, - - type: Number(type) || 3, - - required: required === "true" - - }) - - } - - - - return object - -} \ No newline at end of file diff --git a/package/Handler/slashOption.js b/package/Handler/slashOption.js deleted file mode 100644 index c838d3be9..000000000 --- a/package/Handler/slashOption.js +++ /dev/null @@ -1,176 +0,0 @@ -class SlashOption { -static choice(option){ - const Choice = [] - option = option.split("{choice:").slice(1) - console.log(option) - for(let opt of option){ - - opt = opt.split("}")[0].split(":") - console.log(opt) - const name = opt.shift()?. addBrackets() - const value = opt.shift()?.addBrackets() - Choice.push({name, value}) - } - console.log(Choice) - return Choice; -} -static async string(option){ - option = option.split("{string:").slice(1) - const stringOptions = [] - for(let opt of option){ - opt = opt.split(":"); - const name = opt.shift()?.addBrackets() - const description = opt.shift()?.addBrackets() - const required = opt?.shift()?.addBrackets() === "yes" || true - const choice = opt.join(":") - console.log(choice) - let choices; - if(choice.trim().length){ - choices = await this.choice(choice) - } - else choices = [] - stringOptions.push({type:3,name, description, required,choices}) - } - console.log(stringOptions) - return stringOptions -} -static async integer (options){ - options = options.split("{integer:").slice(1) - const integerOptions = [] -for(let option of options){ - option = option.split(":") - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const required = option?.shift()?.addBrackets() === "yes" || true - const choice = option.join(":") - let choices; - if(choice.trim().length){ - choices = await this.choice(choice) - } - else choices = [] - integerOptions.push({type:4,name, description, required,choices}) -} - return integerOptions; -} -static async number (options){ - options = options.split("{number:").slice(1) - const numberOptions = [] - for(const option of options){ - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const required = option?.shift()?.addBrackets()?.replace("yes",true)?.replace("no",false) || true - const choice = option.join(":") - let choices; - if(choice.trim().length){ - choices = await this.choice(choice) - } - else choices = [] - numberOptions.push({type:10,name, description, required,choices}) - } - return numberOptions ; -} -static async boolean(options){ - options= options.split("{boolean:").slice(1) - const booleanOptions = [] - for(const option of options){ - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const required = option?.shift()?.addBrackets()?.replace("yes",true)?.replace("no",false) || true - booleanOptions.push({type:5,name, description, required}) - } - return booleanOptions; -} -static async user(options){ - options= options.split("{user:").slice(1) - const userOptions = [] - for(const option of options){ - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const required = option?.shift()?.addBrackets()?.replace("yes",true)?.replace("no",false) || true - userOptions.push({type:6,name, description, required}) - } - return userOptions; -} -static async channel(options){ - options = options.split("{channel:").slice(1) - const channelOptions = [] - for(const option of options){ - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const required = option?.shift()?.addBrackets()?.replace("yes",true)?.replace("no",false) || true - channelOptions.push({type:7,name, description, required}) - } - return channelOptions ; -} -static async role(options){ - options = options.split("{role:").slice(1) - const roleOptions = [] - for(const option of options){ - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const required = option?.shift()?.addBrackets()?.replace("yes",true)?.replace("no",false) || true - roleOptions.push({type:8,name, description, required}) - } - return roleOptions -} -static async mentionable(options){ - options = options.split("{mentionable:").slice(1) - const mentionOptions = [] - for(let option of options){ - option = option.split("}")[0].split(":") - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const required = option?.shift()?.addBrackets()?.replace("yes",true)?.replace("no",false) || true - mentionOptions.push({type:9,name, description, required}) - } - return mentionOptions; -} -static async subCommand(options){ - options = options.split("{subCommand:").slice(1) - const subOptions = [] - for(let option of options){ - const index = option.lastIndexOf("}") - option = option.slice(0,index).split(":") - //console.log(option) - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - const opts = option.join(":") - let Options = [] - let opt = opts - //console.log(opt) - const Checker = o=>opt.includes(o) - if(Checker("string")) Options = Options.concat(await this.string(opt)) - //console.log(Options[0].choices) - if(Checker("integer")) Options = Options.concat(await this.integer(opt)) - if(Checker("boolean")) Options = Options.concat(await this.boolean(opt)) - if(Checker("user")) Options = Options.concat(await this.user(opt)) - if(Checker("channel")) Options = Options.concat(await this.channel(opt)) - if(Checker("role")) Options = Options.concat(await this.role(opt)) - if(Checker("mentionable")) Options = Options.concat(await this.mentionable(opt)) - if(Checker("number")) Options = Options.concat(await this.number(opt)) - - subOptions.push({name, description,type:1,options:Options}) - } - return subOptions; -} -static async subGroup(options){ - options = options.split("{subGroup:").slice(1) - const GroupOptions = [] - for(let option of options){ - const index = option.lastIndexOf("}") - option = option.slice(0,index).split(":") - const name = option.shift()?.addBrackets() - const description = option.shift()?.addBrackets() - let Option = [] - const opts = option.join(":") - console.log({opts}); - - - Option =Option.concat((await this.subCommand(opts))) - - GroupOptions.push({name, description,type:2,options:Option}) - } - return GroupOptions ; -} -} -module.exports = SlashOption; \ No newline at end of file diff --git a/package/Handler/startup.js b/package/Handler/startup.js deleted file mode 100644 index c7a8c0900..000000000 --- a/package/Handler/startup.js +++ /dev/null @@ -1,18 +0,0 @@ -const {User,Team} = require('discord.js'); -const Interpreter = require('../interpreter.js'); -module.exports = async client => { - const app = await client.application.fetch(); - if(app.owner instanceof Team) { - client.aoiOptions.Owner = app.owner.members.map( x => x.id ); - } - else { - client.aoiOptions.Owner = [ app.owner.id ] - } - - require('./custom/timeout.js')({client,interpreter :Interpreter},undefined,undefined,undefined,true); - require('./custom/timeoutPulse.js')({client,interpreter :Interpreter},undefined,undefined,undefined,undefined,true); - - if(client.cmd.loop.size){ - require('./custom/loop.js')(client); - } -} \ No newline at end of file diff --git a/package/Handler/status.js b/package/Handler/status.js deleted file mode 100644 index 442fe2deb..000000000 --- a/package/Handler/status.js +++ /dev/null @@ -1,26 +0,0 @@ -module.exports = (statuses, client) => { - console.log("Enabled Status") - if (statuses.size !== 0) { - let y = 0 - - let status = statuses.allValues(); - const f = async () => { - - if (!status[y]) { y = 0 } - setTimeout(async () => { - status[y].activity.name = status[y].activity.name.includes('$') ? ((await client.functionManager.interpreter(client, {}, [], { code: status[y].activity.name }, client.db, true))?.code) : (status[y].activity.name); - - client.user.setPresence({ - status: status[y].status, - activities: Array.isArray(status[y].activity) ? status[y].activity : [status[y].activity], - afk: status[y].afk - }) - - y++ - f() - - }, (status[y]?.time || 12) * 1000) - } - f() - } -} \ No newline at end of file diff --git a/package/ShardHandler/shardDisconnect.js b/package/ShardHandler/shardDisconnect.js deleted file mode 100644 index f02ede015..000000000 --- a/package/ShardHandler/shardDisconnect.js +++ /dev/null @@ -1,15 +0,0 @@ -const Interpreter = require('../interpreter.js') -module.exports = async (event, shardID, client, cmds) => { - for (const cmd of cmds.shardDisconnect.array()) { - const id = cmd?.channel?.includes("$") ? await Interpreter(client, {}, [], { - name: "channelParser", - code: cmd.channel - }, client.db, true) : cmd.channel - const channel = client.channels.cache.get(id) - if (!channel) return; - - await Interpreter(client, {}, [], cmd, client.db, false, undefined, { - closeEvent: event, shardID: shardID - }, channel) - } -} \ No newline at end of file diff --git a/package/ShardHandler/shardError.js b/package/ShardHandler/shardError.js deleted file mode 100644 index 5618877fc..000000000 --- a/package/ShardHandler/shardError.js +++ /dev/null @@ -1,15 +0,0 @@ -const Interpreter = require('../interpreter.js') -module.exports = async (error, shardID, client, cmds) => { - for (const cmd of cmds.shardError.array()) { - const id = cmd?.channel?.includes("$") ? await Interpreter(client, {}, [], { - name: "channelParser", - code: cmd.channel - }, client.db, true) : cmd.channel - const channel = client.channels.cache.get(id) - if (!channel) return; - - await Interpreter(client, {}, [], cmd, client.db, false, channel?.id, { - error: error, shardID: shardID - }, channel) - } -} \ No newline at end of file diff --git a/package/ShardHandler/shardReady.js b/package/ShardHandler/shardReady.js deleted file mode 100644 index 05aa17d10..000000000 --- a/package/ShardHandler/shardReady.js +++ /dev/null @@ -1,15 +0,0 @@ -const Interpreter = require('../interpreter.js') -module.exports = async (shardID, guilds, client, cmds) => { - for (const cmd of cmds.shardReady.array()) { - const id = cmd?.channel?.includes("$") ? await Interpreter(client, {}, [], { - name: "channelParser", - code: cmd.channel - }, client.db, true) : cmd.channel - const channel = client.channels.cache.get(id) - if (!channel) return; - - await Interpreter(client, {}, [], cmd, client.db, false, undefined, { - guilds: guilds, shardID: shardID - }, channel) - } -} \ No newline at end of file diff --git a/package/ShardHandler/shardReconnecting.js b/package/ShardHandler/shardReconnecting.js deleted file mode 100644 index 8b787fd92..000000000 --- a/package/ShardHandler/shardReconnecting.js +++ /dev/null @@ -1,15 +0,0 @@ -const Interpreter = require('../interpreter.js') -module.exports = async (shardID, client, cmds) => { - for (const cmd of cmds.shardReconnecting.array()) { - const id = cmd?.channel?.includes("$") ? await Interpreter(client, {}, [], { - name: "channelParser", - code: cmd.channel - }, client.db, true) : cmd.channel - const channel = client.channels.cache.get(id) - if (!channel) return; - - await Interpreter(client, {}, [], cmd, client.db, false, undefined, { - shardID: shardID - }, channel) - } -} \ No newline at end of file diff --git a/package/ShardHandler/shardResume.js b/package/ShardHandler/shardResume.js deleted file mode 100644 index 68303db06..000000000 --- a/package/ShardHandler/shardResume.js +++ /dev/null @@ -1,15 +0,0 @@ -const Interpreter = require('../interpreter.js') -module.exports = async (shardID, replayEvents, client, cmds) => { - for (const cmd of cmds.shardResume.array()) { - const id = cmd?.channel?.includes("$") ? await Interpreter(client, {}, [], { - name: "channelParser", - code: cmd.channel - }, client.db, true) : cmd.channel - const channel = client.channels.cache.get(id) - if (!channel) return; - - await Interpreter(client, {}, [], cmd, client.db, false, undefined, { - shardID: shardID, replayedEvents: replayedEvents - }, channel) - } -} \ No newline at end of file diff --git a/package/Utils/CallbackUtil.js b/package/Utils/CallbackUtil.js deleted file mode 100644 index 8f6a951cd..000000000 --- a/package/Utils/CallbackUtil.js +++ /dev/null @@ -1,53 +0,0 @@ -const BulkOptions = (d) => { - return { - messages: d.data.bulk.map(x => x.content).join(" , "), - ids: d.data.bulk.map(x => x.id).join(" , "), - createdTimestamp: d.data.bulk.map(x => x.createdTimestamp).join(" , "), - createdAt: d.data.bulk.map(x => x.createdAt).join(" , "), - userIds: d.data.bulk.map(x => x.author.id).join(" , "), - usernames: d.data.bulk.map(x => x.author.username).join(" , "), - userTags: d.data.bulk.map(x => x.author.tag).join(" , "), - userMentions: d.data.bulk.map(x => x.author.toString()).join(" , "), - guildId: d.data.bulk.first().guildId, - guildName: d.data.bulk.first().guild.name, - channelId: d.data.bulk.first().channelId, - channelName: d.data.bulk.first().channel.name - } -} - -const BulkData = (d, option) => { - return BulkOptions(d)[option] -} - -const PinData = (d) => { - const data = { - time: d.data.time, - channelId: d.data.channel.id, - channelName: d.data.channel.name, - channelMention: d.data.channel.toString(), - guildId: d.data.guild.id, - guildName: d.data.guild.name, - messageId: d.data.channel.messages.last()?.id, - messageContent: d.data.channel.messages.last()?.content - } -} -const RateLimitOptions = [ - "timeout", - "limit", //.limit", - "method",// "Method used to this endpoint;.method", - "path",// "The path to the api endpoint that triggered the rate limit;.path", - "route",// "The route that triggered this event;.route", -]; -const WebhookUpdateOptions = [ - 'id', //"id", - 'name',// "name.deleteBrackets()", - 'type',// "The type of the channel where the pins were updated;.type", - 'guildid'// "The guild's ID of the channel where the webhook was updated;.guild.id", -]; - -module.exports = { - BulkData, - PinData, - RateLimitOptions, - WebhookUpdateOptions, -} \ No newline at end of file diff --git a/package/Utils/Constants.js b/package/Utils/Constants.js deleted file mode 100644 index 8c8052929..000000000 --- a/package/Utils/Constants.js +++ /dev/null @@ -1,312 +0,0 @@ -//---------------Client------------------// - -const IntentOptions = { - guilds: "GUILDS", - guildMembers: "GUILD_MEMBERS", - guildBans: "GUILD_BANS", - guildEmojisAndStickers: "GUILD_EMOJIS_AND_STICKERS", - guildIntegrations: "GUILD_INTEGRATIONS", - guildWebhooks: "GUILD_WEBHOOKS", - guildInvites: "GUILD_INVITES", - guildVoiceStates: "GUILD_VOICE_STATES", - guildPresences: "GUILD_PRESENCES", - guildMessages: "GUILD_MESSAGES", - guildMessageReactions: "GUILD_MESSAGE_REACTIONS", - guildMessageTyping: "GUILD_MESSAGE_TYPING", - directMessages: "DIRECT_MESSAGES", - directMessageReactions: "DIRECT_MESSAGE_REACTIONS", - directMessageTyping: "DIRECT_MESSAGE_TYPING" -} -IntentOptions.all = Object.values(IntentOptions); - -const ActivityTypeAvailables = { - playing: "PLAYING", - watching: "WATCHING", - listening: "LISTENING", - streaming: "STREAMING", - competing: "COMPETING" -} - -const DebugAvailables = { - interpreter: "Boolean" -} - -const EventAvailables = { - timeout: "Boolean", - music: "Boolean", - functionError: "Boolean" -} - -const fetchInvitesOptions = { - enabled: "Boolean", - cacheInviters: "Boolean" -} - -//---------------Abbreviation------------// -const SI_SYMBOL = ["", "K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "O", "N", - "D", "UD", "UD", "DD", "TD", "QaD", "QiD", "SxD", "SpD", "OD", "ND", - "V", "UV", "DV", "TV", "QaV", "QiV", "SxV", "SpV", "OV", "NV", - "DT", "UDT", "DDT", "TDT", "QaDT", "QiDT", "SxDT", "SpDT", "ODT", "NDT", - "DQa", "UDQa", "DDQa", "TDQa", "QaDQa", "QiDQa", "SxDQa", "SpDQa", "ODQa", "NDQa", - "DQi", "UDQi", "DDQi", "TDQi", "QaDQi", "QiDQi", "SxDQi", "SpDQi", "ODQi", "NDQi", - "DSx", "UDSx", "DDSx", "TDSx", "QaDSx", "QiDSx", "SxDSx", "SpDSx", "ODSx", "NDSx", - "DSp", "UDSp", "DDSp", "TDSp", "QaDSp", "QiDSp", "SxDSp", "SpDSp", "ODSp", "NDSp", - "DO", "UDO", "DDO", "TDO", "QaDO", "QiDO", "SxDO", "SpDO", "ODO", "NDO", - "DN", "UDN", "DDN", "TDN", "QaDN", "QiDN", "SxDN", "SpDN", "ODN", "NDN", - "C", "UC", -]; -//---------------Callbacks---------------// -const ApplicationCmdOptions = { - id: "id of the slash cmd;.id", - name: "name of the slash cmd;.name", - description: "description of the slash cmd;.description", - version: "version of slash cmd;.version", - options: "options of slash cmd;.options", - guildID: "guildID of the slash cmd (returns null for global);.guildID", - applicationID: "returns Application ID", - defaultPermission: "returns default permission of the slash cmd;.defaultPermission", - timestamp: "returns timestamp of the creation of slash cmd (in ms);.timestamp", - createdAt: "returns the date of creation of slash cmd;.createdAt" -} -const ChannelOptions = { - //text + default - createdAt: "createdAt", - createdTimestamp: "createdTimestamp", - defaultAutoArchiveDuration: "defaultAuyoArchiveDuration", - deletable: "deletable", - deleted: "deleted", - guildID: "guild?.id", - id: "id", - lastMessageContent: "lastMessage?.content?.deleteBrackets()", - lastMessageID: "lastMessageId", - lastPinAt: "lastPinAt", - lastPinTimestamp: "lastPinTimestamp", - manageable: "manageable", - membersCount: "members?.size", - name: "name?.deleteBrackets()", - nsfw: "nsfw", - parentName: "parent?.name", - parentID: "parentId", - position: "position", - slowmode: "rateLimitPerUser", - topic: "topic?.deleteBrackets()", - type: "type", - viewable: "viewable", - permsAllowed: "permissionOverwrites?.cache?.map(x=>`type:${x.type}\nallowed:${x.allow}\nmetion:${x.type ==='?'<@'+x.id+'>':'<@&'+x.id+'>'}`).join(`\n`)", - permsDenied: "permissionOverwrites?.cache?.map(x=>`type:${x.type}\ndenied:${x.deny}\nmetion:${x.type ==='member'?'<@'+x.id+'>':'<@&'+x.id+'>'}`).join(`\n`)", - perms: "permissionOverwrites?.cache?.map(x=>`type:${x.type}\nallowed:${x.allow}\ndenied:${x.deny}\nmetion:${x.type ==='member'?'<@'+x.id+'>':'<@&'+x.id+'>'}`).join(`\n`)", - //category - childrenID: "children?.map(x=>x.id)?.join(' , ')", - childrenName: "children?.map(x=>x.name?.deleteBrackets())?.join(' , ')", - //voice - bitrate: "bitrate", - full: "full", - joinable: "joinable", - rtcRegion: "rtcRegion", - userLimit: "useeLimit", - speakable: "speakable", - //threads - archived: "archived", - archivedAt: "archivedAt", - archivedTimestamp: "archivedTimestamp", - autoArchiveDuration: "autoArchiveDuration", - threadMembersCount: "memberCount", - messagesCount: "messagesCount", - ownerID: "ownerId", - sendable: "sendable", - unachievable: "unarchivable" -} -const MemberOptions = { - id: "id", - name: "user?.username?.deleteBrackets()", - guildID: "guild.id", - nick: "nickname || ''", - roles: "roles?.cache?.filter(r => r.name !== '@everyone').map(r => r?.name.deleteBrackets()).join(', ')", - partial: "partial??false", - premiumStamp: "premiumSinceTimestamp || `0`", - joinedStamp: "joinedTimestamp", - voiceID: "voice.channelID || ''", - displayHex: "displayHexColor", - highestRoleID: "roles.highest.id", - permissions: "permissions.toArray().goof('_')", - newPermissions: `(() => { - const curr = d.data.newm?.permissions.toArray() - const old = d.data.oldm?.permissions.toArray() - - return curr?.filter(p => !old.includes(p))?.goof("_") - })()`, - removedPermissions: `(() => { - const curr = d.data.newm?.permissions.toArray() - const old = d.data.oldm?.permissions.toArray() - - return old?.filter(p => !curr.includes(p))?.goof("_") - })()`, - bannable: "bannable", - kickable: "kickable", - manageable: "manageable", - status: "status", - activities: "presence?.activities?.map(c => c.name).join(', ')", - removedRoles: `(() => { - const curr = d.data.newm?.roles.cache - const old = d.data.oldm?.roles.cache - - return old?.filter(r => !curr.has(r.id)).map(r => r.name).join(", ").deleteBrackets() - })()`, - addedRoles: `roles?.cache?.filter(r => !d.data.oldm.roles.cache.has(r.id)).map(r => r.name).join(", ").deleteBrackets()`, - //thread - threadChannel: "thread?.channel?.name?.deleteBrackets()", - threadFlags: "flags?.toArray()" -} -//---------------Interactions------------// -const ButtonStyleOptions = { - primary: 1, - secondary: 2, - success: 3, - danger: 4, - link: 5 -} -const CacheOptions = { - guilds: "GuildManager", - messages: "MessageManager", - channels: "ChannelManager", - users: "UserManager", - applicationCommands: "ApplicationCommandManager", - applicationCommandPermissions: "ApplicationCommandPermissionManager", - permissionOverwrites: "PermissionOverwritesManager", - presences: "PersenceManager", - reactions: "ReactionManager", - reactionUsers: "ReactionUserManager", - roles: "RoleManager", - stageInstances: "StageInstanceManager", - threads: "ThreadManager", - threadMembers: "ThreadMemberManager", - voiceStates: "VoiceStateManager", - guildApplicationCommand: "GuildApplicationCommandManager", - guildBans: "GuildBanManager", - guildChannels: "GuildChannelManager", - guildEmojis: "GuildEmojiManager", - guildEmojiRoles: "GuildEmojiRoleManager", - guildInvites: "GuildInviteManager", - guildMembers: "GuildMemberManager", - guildMemberRoles: "GuildMemberRoleManager", - guildStickers: "GuildStickerManager" -} -const SlashOptionTypes = { - subCommand: 1, - subGroup: 2, - string: 3, - integer: 4, - boolean: 5, - user: 6, - channel: 7, - role: 8, - mentionable: 9, - number: 10 -} -const Perms = { - createinvite: 'CREATE_INSTANT_INVITE', - kick: 'KICK_MEMBERS', - ban: 'BAN_MEMBERS', - admin: 'ADMINISTRATOR', // (implicitly has all permissions, and bypasses all channel overwrites) - managechannel: 'MANAGE_CHANNELS', // (edit and reorder channels) - manageserver: 'MANAGE_GUILD', // (edit the guild information, region, etc.) - addreactions: 'ADD_REACTIONS', // (add new reactions to messages) - viewauditlog: 'VIEW_AUDIT_LOG', - priorityspeaker: 'PRIORITY_SPEAKER', - stream: 'STREAM', - viewchannel: 'VIEW_CHANNEL', - sendmessage: 'SEND_MESSAGES', - sendtts: 'SEND_TTS_MESSAGES', - managemessages: 'MANAGE_MESSAGES', // (delete messages and reactions) - embedlinks: 'EMBED_LINKS', // (links posted will have a preview embedded) - attachfiles: 'ATTACH_FILES', - readmessagehistory: 'READ_MESSAGE_HISTORY', // (view messages that were posted prior to opening Discord) - mentioneveryone: 'MENTION_EVERYONE', - externalemojis: 'USE_EXTERNAL_EMOJIS', // (use emojis from different guilds) - viewguildinsights: 'VIEW_GUILD_INSIGHTS', - connect: 'CONNECT', // (connect to a voice channel) - speak: 'SPEAK', // (speak in a voice channel) - mutemembers: 'MUTE_MEMBERS', // (mute members across all voice channels) - deafenmembers: 'DEAFEN_MEMBERS', // (deafen members across all voice channels) - movemembers: 'MOVE_MEMBERS', // (move members between voice channels) - usevad: 'USE_VAD', // (use voice activity detection) - changenickname: 'CHANGE_NICKNAME', - managenicknames: 'MANAGE_NICKNAMES', // (change other members' nicknames) - manageroles: 'MANAGE_ROLES', - managewebhooks: 'MANAGE_WEBHOOKS', - manageemojisandstickers: 'MANAGE_EMOJIS_AND_STICKERS', - useappcmds: 'USE_APPLICATION_COMMANDS', - requesttospeak: 'REQUEST_TO_SPEAK', - managethreads: 'MANAGE_THREADS', - usepublicthreads: 'USE_PUBLIC_THREADS', - useprivatethreads: 'CREATE_PRIVATE_THREADS', - createpublicthreads: 'CREATE_PUBLIC_THREADS', - createprivatethreads: 'CREATE_PRIVATE_THREADS', - externalstickers: 'USE_EXTERNAL_STICKERS', // (use stickers from different guilds) - sendmessageinthreads: 'SEND_MESSAGES_IN_THREADS', - startembeddedactivities: 'START_EMBEDDED_ACTIVITIES' -} -const FormatOptions = (date, timeZone) => { - ////defining - // months - const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] - //days - const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] - - ////Returning Data - return { - YY: date.getFullYear().toString().slice(-2), - - YYYY: date.getFullYear(), - - M: (date.getMonth() + 1), - - MM: (date.getMonth() + 1).toString().length === 1 ? 0 + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString(), - - MMM: months[date.getMonth()].slice(0, 3), - - MMMM: months[date.getMonth()], - - D: date.getDate(), - - DD: date.getDate().toString().length === 1 ? (0 + date.getDate().toString()) : date.getDate().toString(), - - d: date.getDay(), - - dd: days[date.getDay()].slice(0, 2), - - ddd: days[date.getDay()].slice(0, 3), - - dddd: days[date.getDay()], - - H: date.getHours(), - - HH: date.getHours().toString().length === 1 ? (0 + date.getHours().toString()) : date.getHours().toString(), - - h: Math.abs(date.getHours() - 12), - - hh: "hi" - } -} -const Characters = ["1234567890", "qwertyuiopalskdjfhgznmxcbv", "qwertyuiopalskdjfhgznmxcbv".toUpperCase()].join(""); - -module.exports = { - // ClientOptions:ClientOptions, - IntentOptions: IntentOptions, - //ClientPresenceOptions:ClientPresenceOptions, - //PresenceActivityOptions:PresenceActivityOptions, - ActivityTypeAvailables: ActivityTypeAvailables, - //DatabaseOptions:DatabaseOptions, - DebugAvailables: DebugAvailables, - EventAvailables: EventAvailables, - SI_SYMBOL: SI_SYMBOL, - ButtonStyleOptions: ButtonStyleOptions, - ChannelOptions: ChannelOptions, - MemberOptions: MemberOptions, - CacheOptions: CacheOptions, - SlashOptionTypes, - Perms, - Characters, -} - - diff --git a/package/Utils/InteractionConstants.js b/package/Utils/InteractionConstants.js deleted file mode 100644 index 5a76a3988..000000000 --- a/package/Utils/InteractionConstants.js +++ /dev/null @@ -1,20 +0,0 @@ -const InteractionTypes = { - PING:"ping", - APPLICATION_COMMAND:"slash", - MESSAGE_COMPONENT:"component" -} -const MessageComponentTypes = { - ACTION_ROW:"actionRow", - BUTTON:"button", - SELECT_MENU:"selectMenu" -} -const SlashTypes = { - slash : "CHAT_INPUT", - user : "USER", - message : "MESSAGE" -} -module.exports = { -InteractionTypes: InteractionTypes , -MessageComponentTypes:MessageComponentTypes , -SlashTypes -} diff --git a/package/Utils/VoiceConstants.js b/package/Utils/VoiceConstants.js deleted file mode 100644 index cb8b20fd1..000000000 --- a/package/Utils/VoiceConstants.js +++ /dev/null @@ -1,42 +0,0 @@ -const VoiceOptions = { -client:">", -ytdl:"YtdlOptions", -soundcloud:"SoundCloud Client ID", -cache:"", -other:"any" -} -const VoiceSubscriptionDefaultOptions = { - paused:false, - loopQueue:false, - loopSong:false, - volume:100, - leaveAfter:60000, - leaveWhenEmpty:false -} -const States = { - queue:{ - IDLE:"idle", - PLAYING:"playing", - PAUSED:"paused" - }, - loop:{ - NONE:"none", - QUEUE:"queue", - SINGLE:"single" - } -} -const Events = { - ERROR:"musicError", - TRACK_START:"musicStart", - QUEUE_END:"queueEnd", - TRACK_END:"trackEnd" - -} -const TrackTypes = ["YouTube","SoundCloud","File"] -module.exports = { -VoiceOptions : VoiceOptions, -VoiceSubscriptionDefaultOptions:VoiceSubscriptionDefaultOptions, -States, -Events:Events , -TrackTypes : TrackTypes -} \ No newline at end of file diff --git a/package/Utils/helpers/customParser.js b/package/Utils/helpers/customParser.js deleted file mode 100644 index 16320d04d..000000000 --- a/package/Utils/helpers/customParser.js +++ /dev/null @@ -1,78 +0,0 @@ -class Time { - static format(time) { - const date = (t, ms) => Math.trunc(t / ms) - const data = { - object: { - years: date(time, 31536000000), - months: date(time, 2628002880) % 12, - weeks: date(time, 604800000) % 4, - days: date(time, 86400000) % 30, - hours: date(time, 3600000) % 24, - minutes: date(time, 60000) % 60, - seconds: date(time, 1000) % 60, - ms: date(time, 1) % 1000 - }, - - } - data.humanize = () => { - const string = [] - Object.entries(data.object).forEach(x => { - if (!x[1]) { } - else { - if (["months", "ms"].includes(x[0])) { - string.push(`${x[1]}${x[0].slice(0, 3)}`) - } - else { - string.push(`${x[1]}${x[0].slice(0, 1)}`) - } - } - }); - return string.join(" "); - } - data.toString = () => this.parse(data.humanize()).format - return data - } - static parse(time) { - console.time("parse") - if (!["string", "number"].includes(typeof time)) throw TypeError("Time Must Be A String Or Number"); - if (typeof time === "number") return this.format(time).humanize() - else { - const Hash = new Map(); - - time.split(" ").forEach(x => { - //console.log(x.split("s")[0]) - if (x.endsWith("y")) Hash.set("y", { format: `${Number(x.split("y")[0])} Year(s)`, ms: Number(x.split("y")[0]) * 31536000000, order: 1 }); - if (x.endsWith("mon") || x.endsWith("M")) Hash.set("mon", { format: `${Number(x.split("mon")[0].split("M")[0])} Month(s)`, ms: Number(x.split("mon")[0].split("M")[0]) * 2628002880, order: 2 }); - if (x.endsWith("w")) Hash.set("w", { format: `${Number(x.split("w")[0])} Week(s)`, ms: Number(x.split("w")[0]) * 604800000, order: 3 }); - if (x.endsWith("d")) Hash.set("d", { format: `${Number(x.split("d")[0])} Day(s)`, ms: Number(x.split("d")[0]) * 86400000, order: 4 }); - if (x.endsWith("h") || x.endsWith("hr")) Hash.set("h", { format: `${Number(x.split("h")[0].split("hr")[0])} Hour(s)`, ms: Number(x.split("hr")[0].split("h")[0]) * 3600000, order: 5 }); - if (x.endsWith("min") || x.endsWith("m")) Hash.set("min", { format: `${Number(x.split("min")[0].split("m")[0])} Minute(s)`, ms: Number(x.split("min")[0].split("m")[0]) * 60000, order: 6 }); - if (x.endsWith("s") && !x.endsWith("ms")) Hash.set("s", { format: `${Number(x.split("s")[0])} Seconds`, ms: Number(x.split("s")[0]) * 1000, order: 7 }); - if (x.endsWith("ms")) Hash.set("ms", { format: `${Number(x.split("ms")[0])} Milli Seconds`, ms: Number(x.split("ms")[0]), order: 8 }); - }); - const data = [...Hash.values()].sort(compare); - //console.log(data.map(x=>x.ms)) - const ms = data.map(x => x.ms).reduce((a, b) => a + b); - const format = data.map(x => x.format).join(" "); - console.timeEnd("parse") - return { - ms, - format - } - } - } -} -module.exports = { - Time -} - -//useless Functions -function compare(a, b) { - if (a.order < b.order) { - return -1; - } - if (a.order > b.order) { - return 1; - } - return 0; -} \ No newline at end of file diff --git a/package/Utils/helpers/functions.js b/package/Utils/helpers/functions.js deleted file mode 100644 index 1b86b243a..000000000 --- a/package/Utils/helpers/functions.js +++ /dev/null @@ -1,315 +0,0 @@ -const { SI_SYMBOL, FormatOptions } = require('../Constants.js') -module.exports = { - abbreviate(number, decimal) { - const tier = Math.floor(Math.log10(Math.abs(number || 1)) / 3); - if (tier === 0) return number; - const suffix = SI_SYMBOL[tier]; - const scale = Math.pow(10, tier * 3); - const scaled = number / scale; - return scaled.toFixed(decimal) + suffix; - }, - wait(time) { - new Promise(res => setTimeout(() => res, time)) - }, - categoryChannelsOption(cat) { - cat = cat.children; - return { - names: cat.map(x => x.name), - ids: cat.map(x => x.id), - mentions: cat.map(x => x.toString()), - count: cat.size, - json: JSON.stringify({ - names: cat.map(x => x.name), - ids: cat.map(x => x.id), - mentions: cat.map(x => x.toString()), - count: cat.size - }) - } - }, - Channel(channel) { - const data = Object.create(channel) - Object.assign(data, channel); - delete data.messages - delete data.permissionOverwrites - data.threads = channel.threads.cache.size - data.parent = channel.parent.name - data.mention = channel.toString() - - return data; - }, - Client(client) { - const data = { - prefix: Array.isArray(client.prefix) ? client.prefix.join(" , ") : client.prefix, - variables: { - name: client.variableManager.vars.join(" , "), - json: client.variableManager.toJSON(), - object: client.variableManager.cache.object() - }, - user: Object.assign(Object.create(client.user), client.user), - application: Object.assign(Object.create(client.application), client.application) - } - //user property modification - data.user.avatarUrl = client.user.displayAvatarURL() - data.user.displayAvatarURL = undefined - data.user.avatarURL = undefined - data.user.toJSON = undefined - data.user.flags = client.user.flags?.toArray().length ? client.user.flags?.toArray().join(" , ") : "none" - data.presence = client.presence.status - delete data.user.dmChannel - delete data.user.client - //application data modification - data.application.iconURL = client.application.iconURL() - data.application.flags = client.application.flags?.toArray().join(' , ') - data.application.commands = undefined - data.application.client = undefined - data.json = JSON.stringify(Object.assign({}, data), null, 2) - return data - }, - Emoji(emoji) { - const data = Object.assign(Object.create(emoji), emoji) - //emoji data modification - data.setName = undefined - data.delete = undefined - data.edit = undefined - data.equals = undefined - data.fetchAuthor = undefined - - data.string = emoji.toString() - data.json = JSON.stringify(data, null, 2) - data.guild = emoji.guild.id; - data.roles = emoji.roles.map(x => x.id).join(' , '); - - data.toJSON = undefined - return data; - }, - EmbedData(embed, embeds) { - const data = { - authorname: embed.author?.name, - authoricon: embed.author?.iconUrl, - authorurl: embed.author?.url, - image: embed.image?.url, - thumbnail: embed.thumbnail?.url, - color: embed.color, - footertext: embed.footer?.text, - footericon: embed.footer?.iconUrl, - description: embed.description, - title: embed.title, - url: embed?.url - - } - - embed.fields.forEach((x, y) => data[`field${y + 1}`] = x); - - data.json = JSON.stringify(data, null, 2); - data.rawjson = embed.toJSON(); - data.allEmbeds = JSON.stringify(embeds, null, 2); - - return data; - }, - Invite(invite) { - const data = Object.assign(Object.create({}, invite), invite); - - data.delete = undefined; - data.guild = undefined; - data.channel = undefined; - data.client = undefined; - data.inviter = undefined; - - data.channelname = invite.channel?.name; - data.channelid = invite.channel?.id; - data.channelmention = invite.channel?.toString(); - - data.guildname = invite.guild?.name; - data.guildid = invite.guild?.id; - data.guildmention = invite.guild?.toString(); - - data.invitername = invite.inviter?.username; - data.inviterdiscm = invite.inviter?.discriminator; - data.invitertag = invite.inviter?.tag; - data.inviterid = invite.inviter?.id; - data.invitermention = invite.inviter?.toString(); - - data.toString = data.toString(); - data.json = JSON.stringify(data, null, 2); - - return data; - }, - Guild(guild) { - const data = Object.assign({}, guild); - //modifying data - data.afkChannel = guild.afkChannel?.name; - data.bannerURL = guild.bannerURL(); - }, - Webhook(webhook) { - const data = Object.assign(Object.create(webhook), webhook); - - data.send = undefined; - data.sendSlackMessage = undefined; - data.avatarURL = webhook.avatarURL({ dynamic: true, size: 4096 }); - data.sourceChannel = undefined; - data.sourceGuild = undefined; - data.owner = webhook.owner?.id; - data.client = undefined; - data.delete = undefined; - data.deleteMessag = undefined; - data.edit = undefined; - data.editMessage = undefined; - data.fetchMessage = undefined; - data.isChannelFollower = webhook.isChannelFollower(); - data.isIncoming = webhook.isIncoming(); - - return data; - }, - Message(msg) { - const data = Object.assign({}, msg); - data.activityPartyId = msg.activity.partyId; - data.activityType = msg.activity.type; - data.activity = undefined; - - data.attachments = msg.attachments.map(x => x.url); - - data.authorName = msg.author.username; - data.authorId = msg.author.id; - data.authorIcon = msg.author.avatarURL({ size: 4096, dynamic: true }); - data.authorMention = msg.author.toString(); - data.author = undefined; - - data.channelName = msg.channel.name; - data.channelType = msg.channel.type; - data.channelMention = msg.channel.toString(); - data.channel = undefined; - - data.client = undefined; - - data.components = JSON.stringify(msg.components, null, 2); - - data.cleanContent = msg.cleanContent; - data.createdAt = msg.createdAt; - - data.deleted = msg.deleted; - data.deletable = msg.deletable; - - data.crosspostable = msg.crosspostable; - data.editable = msg.editable; - - data.editedAt = msg.editedAt; - data.embeds = JSON.stringify(msg.embeds, null, 2); - - data.groupActivityApplication = undefined; - - data.guildname = msg.guild.name; - data.guildicon = msg.guild.iconURL({ size: 4096, dynamic: true }); - data.guild = undefined; - - data.hasThread = msg.hasThread; - data.member = undefined; - - data.pinnable = msg.pinnable; - - return data; - }, - Role(role) { - const data = Object.assign({}, role); - //modifying data - data.createdAt = role.createdAt; - data.createdTimestamp = role.createdTimestamp; - - data.hexColor = role.hexColor; - - data.members = msg.members.map(x => x.id).join(' , '); - data.memberCount = msg.members.size; - - data.position = role.position; - - data.tagsbotid = role.tags.botId; - data.tagsapplicationid = role.tags.applicationId; - data.tagspremiumSubscriberRole = role.tags.premiumSubscriberRole; - - return data; - }, - VoiceState(state) { - const data = Object.assign({}, state); - - data.deaf = state.deaf; - data.mute = state.mute; - data.guild = undefined; - data.guildId = state.guild.id; - - return data; - }, - User(user) { - const data = Object.assign({}, user); - - data.accentColor = user.accentColor; - data.banner = user.banner; - data.bannerURL = user.bannerURL(); - data.createdAt = user.createdAt; - data.createdTimestamp = user.createdTimestamp; - data.avatarURL = user.avatarURL({ size: 4096, dynamic: true }); - data.flags = user.flags?.toArray().join(' , '); - data.partial = user.partial; - data.tag = user.tag; - data.dmChannel = user.dmChannel?.id; - - return data; - }, - Presence(presence) { - const data = Object.assign({}, presence); - - data.activities = JSON.stringify(presence.activities, null, 2) - data.webStatus = presence.clientStatus.web; - data.desktopStatus = presence.clientStatus.desktop; - data.mobileStatus = presence.clientStatus.mobile; - data.guildId = presence.guild.id; - - data.authorId = presence.userId; - data.user = undefined; - data.guild = undefined; - - return data; - }, - RBGtoHex(r, b, g) { - return "#" + this.PartToHex(r) + this.PartToHex(b) + this.PartToHex(g); - }, - PartToHex(d) { - const data = d.toString(16); - return data.length === 1 ? '0' + data : data - }, - FormatDate(date, format) { - ////Map for Storing Each Format - const FormatMap = new Map(); - - ////creating Array of format - format = format.split(" "); - - ////finding and setting indexes per format - // Map -> Map> - format.forEach((x, y) => { - if (!FormatMap.has(x)) FormatMap.set(x, [y]) - else { - const arr = FormatMap.get(x); - arr.push(y); - FormatMap.set(x, arr); - } - }); - - ////basic defining - let i = format.length - 1; - - }, - Timeout(d, name, duration, timeoutData, pulse) { - timeoutData.__duration__ = Date.now() + duration; - timeoutData.__timeoutName__ = name; - timeoutData.__pulseEvery__ = pulse; - timeoutData.__id__ = Math.floor(Math.random() * 999999); - - d.client.db.set(d.client.db.tables[0], 'setTimeout', timeoutData.__id__, timeoutData); - - if (!pulse) { - require('../../Handler/custom/timeout.js')(d, name, duration, timeoutData, false) - } - else { - require('../../Handler/custom/timeoutPulse.js')(d, name, duration, pulse, timeoutData, false) - } - } -} \ No newline at end of file diff --git a/package/Utils/helpers/if.js b/package/Utils/helpers/if.js deleted file mode 100644 index 2381db856..000000000 --- a/package/Utils/helpers/if.js +++ /dev/null @@ -1,18 +0,0 @@ -const interpreter = require('../../interpreter.js') -const IF = async (d) => { - const { code } = d.command - let results = [] - let everything; - let pass; - let elseIfPass; - if (code.toLowerCase().includes("$if[")) { - for (let statement of code.split(/\$if\[/gi).slice(1).reverse()) { - let everything = statement.split(/\$endif/gi)[0] - - let condition = statement.split("\n")[0].trim() - condition = condition.slice(0, condition.length - 1) - statement = statement.split(/$endif/)[0].split("\n").slice(1).join("\n") - } - } -} -module.exports = IF; \ No newline at end of file diff --git a/package/Utils/helpers/mustEscape.js b/package/Utils/helpers/mustEscape.js deleted file mode 100644 index 6ce67c84c..000000000 --- a/package/Utils/helpers/mustEscape.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - mustEscape: (msg) => { - return msg.split("\\[").join("#RIGHT#") - .replace(/\\]/g, "#LEFT#") - .replace(/\\;/g, "#SEMI#") - .replace(/\\:/g, "#COLON#") - .replace(/\\$/g, "#CHAR#") - .replace(/\\>/g, "#RIGHT_CLICK#") - .replace(/\\= 0) { - return ( - this.substring(0, index) + replace + this.substring(index + find.length) - ); - } - - return this.toString(); -}; -String.prototype.deleteBrackets = function () { - return this.replace(/\[/g, "#RIGHT#") - .replace(/\]/g, "#LEFT#") - .replace(/;/g, "#SEMI#") - .replace(/:/g, "#COLON#") - .replace(/\$/g, "#CHAR#") - .replace(/>/g, "#RIGHT_CLICK#") - .replace(/") - .replace(/#LEFT_CLICK#/g, "<") - .replace(/#EQUAL#/g, "=") - .replace(/#RIGHT_BRACKET#/g, "{") - .replace(/#LEFT_BRACKET#/g, "}") - .replace(/#COMMA#/g, ",") -}; - -Array.prototype.goof = function (sep = "_") { - return this.map((x) => - x - .split(sep) - .map((w) => - w.toLowerCase().replace(w[0].toLowerCase(), w[0].toUpperCase()) - ) - .join(" ") - ).join(", "); -}; -async function walk(path) { - - const something = await fs.promises - - .readdir(path, { withFileTypes: true }) - - .then((f) => { - - return f.map((d) => { - - d.name = `${path}/${d.name}`; - - return d; - - }); - - }); - - const files = something.filter((d) => d.isFile()); - - const dirs = something.filter((d) => d.isDirectory()); - - for (const d of dirs) { - - const items = await walk(d.name); - - files.push(...items); - - } - - return files; - -} \ No newline at end of file diff --git a/package/classes/AoiError.js b/package/classes/AoiError.js deleted file mode 100644 index e11a8e5cc..000000000 --- a/package/classes/AoiError.js +++ /dev/null @@ -1,108 +0,0 @@ -const { ComponentParser, EmbedParser, FileParser } = require('../Handler/parsers.js') -const Util = require('./Util.js'); -const { Time } = require('../Utils/helpers/customParser.js') -class AoiError { - constructor() { - const error = new Error(`Cannot initialize "AoiError" Class`) - error.name = "AoiError" - throw error; - } - static CallbackError(callback, intent, line) { - const error = new Error(`(Missing Intents) : "${callback}" requires "${intent}" intent.`); - error.name = "CallbackError"; - error.fileName = "./Bot.js" - error.lineNumber = line - throw error; - } - static CommandError(command, type, name, position) { - if (type === "name") { - const error = new Error(`"Name" property is missing in "${command}" (position: ${position})`) - error.name = "CommandNameError" - throw error - } - else if (type === "code") { - const error = new Error(`"Code" is not provided in "${name || "the Command"}" : ${command} (position: ${position})`) - error.name = "CommandCodeError" - throw error - } - } - static async makeMessageError(client, channel, options = {}, extraOptions = {}, d) { - options.content = options.content?.trim() || ' '; - if (options.embeds && typeof options.embeds === "string") { - options.embeds = await EmbedParser(options.embeds) - } - if (options.files && typeof options.files === "string") { - options.files = await FileParser(options.files) - } - if (options.components && typeof options.components === "string") { - options.components = await ComponentParser(options.componenents, client) - } - console.log({ extraOptions, message: extraOptions.edits?.messages }) - let msg; - if (extraOptions.interaction) { - msg = await d.data.interaction.reply(options); - } - else { - msg = await channel.send(options); - } - - if (extraOptions.reactions?.length) { - console.log("re working") - extraOptions.reactions.forEach(x => msg.react(x)) - } - if (extraOptions.edits) { - const editIn = setInterval(async () => { - if (!extraOptions.edits.messages?.length) clearInterval(editIn) - else { - const obj = await Util.errorParser(JSON.stringify(extraOptions.edits.messages.shift()), d) - console.log({ obj }) - msg.edit(obj) - } - }, Time.parse(extraOptions.edits.time)?.ms) - } - if (extraOptions.deleteIn) { - setTimeout(() => msg.delete(), extraOptions.deleteIn) - } - if (extraOptions.deleteCommand) { - d.message.delete() - } - return msg; - } - static consoleError(name, e) { - return console.error(`${name}: ${e}`) - } - static functionErrorResolve(d, type, data, message) { - let ans; - switch (type) { - case "message": - ans = `\`${d.func}: Invalid Message ID Provided In ${data.inside || ""} (line : ${d.funcLine})\`` - break; - case "channel": - ans = `\`${d.func}: Invalid Channel ID Provided In ${data.inside || ""} (line : ${d.funcLine}\`)` - break; - case "user": - ans = `\`${d.func}: Invalid User ID Provided In ${data.inside || ""} (line : ${d.funcLine})\`` - break; - case "role": - ans = `\`${d.func}: Invalid Role Provided In ${data.inside || ""} (line : ${d.funcLine})\`` - break; - case "guild": - ans = `\`${d.func}: Invalid Guild ID Provided In ${data.inside || ""} (line : ${d.funcLine})\`` - break; - case "emoji": - ans = `\`${d.func}: Invalid Emoji ID Provided In ${data.inside || ""} (line : ${d.funcLine})\`` - break; - case "option": - ans = `\`${d.func}: Invalid Option Provided In ${data.inside || ""} (line : ${d.funcLine})\`` - break; - case "custom": - ans = `\`${d.func}:${message} ${data.inside || ""} (line : ${d.funcLine})\`` - break; - } - return ans - } - static fnError(d, type, data, message) { - d.error(this.functionErrorResolve(d, type, data, message)) - } -} -module.exports = AoiError; \ No newline at end of file diff --git a/package/classes/Blacklist.js b/package/classes/Blacklist.js deleted file mode 100644 index 190432736..000000000 --- a/package/classes/Blacklist.js +++ /dev/null @@ -1,60 +0,0 @@ -const Group = require('../CacheHandler/index.js').setCache -const AoiError = require('./AoiError.js') -class Blacklist { - constructor(client) { - this.client = client - this.globalUser = { blacklist: new Group(), errorMsg: null } - this.server = { blacklist: new Group(), errorMsg: null } - this.channel = { blacklist: new Group(), errorMsg: null } - this.role = { blacklist: new Group(), errorMsg: null } - this.user = { blacklist: new Group(), errorMsg: null } - this.commands = [] - } - setBlacklist(type, errorMsg) { - if (!this.types.includes(type)) AoiError.consoleError("BlacklistTypeError", "Invalid Type Provided") - this[type].errorMsg = errorMsg - } - blacklistIds(type, ...ids) { - if (!this.types.includes(type)) AoiError.consoleError("BlacklistTypeError", "Invalid Type Provided") - this[type].blacklist.squash(...ids) - - } - whitelistIds(type, ...ids) { - if (!this.types.includes(type)) AoiError.consoleError("BlacklistTypeError", "Invalid Type Provided") - ids.forEach(x => { - this[type].blacklist.remove(x) - }) - } - get types() { - return ["globalUser", "server", "channel", "role", "user"] - } - getBlacklistTable(type = "all") { - let table = [] - if (type === "all") { - for (const type of this.types) { - table.push(` -|-----------------------------------------| -|++++++++++++++++${type}++++++++++++++++++| -|ID | -${this[type].blacklist.map(x => `|${x} |`).join("\n")} -|-----------------------------------------|` - ) - } - return table.join("") - } - else { - if (!this.types.includes(type)) AoiError.consoleError("BlacklistTypeError", "Invalid Type Provided") - { - table.push(` -|-----------------------------------------| -|++++++++++++++++${type}++++++++++++++++++| -|ID | -${this[type].blacklist.map(x => `|${x} |`).join("\n")} -|-----------------------------------------| -`) - } - return table.join("") - } - } -} -module.exports = Blacklist; \ No newline at end of file diff --git a/package/classes/Bot.js b/package/classes/Bot.js deleted file mode 100644 index 78520142d..000000000 --- a/package/classes/Bot.js +++ /dev/null @@ -1,507 +0,0 @@ -const fs = require('fs') -const AoiError = require('./AoiError.js') -const BaseClient = require('./base.js') -const { FunctionManager } = require('./Functions.js') -const { CommandManager, Command } = require('./Commands.js') -const Collection = require('../CacheHandler/index.js').cache; - -class Client extends BaseClient { - constructor(options) { - super(options); - new CommandManager(this) - this.functionManager = new FunctionManager(this) - if (this.aoiOptions.respondOnEdit) { - this.aoiOptions.respondOnEdit.time = this.aoiOptions.respondOnEdit.time || 60000 - } - } - //message Events - onMessage(options) { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGES")) AoiError.CallbackError("onMessage", "GUILD_MESSAGES", 91) - this.messageEventOptions = options || { guildOnly: true, respondToBots: false } - this.on("messageCreate", async data => { - await require('../Handler/guildMessages/commands.js')(data, this, this.db) - await require('../Handler/guildMessages/alwaysExecute.js')(this, data, this.db) - }) - } - onMessageDelete() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGES")) AoiError.CallbackError("onMessageDelete", "GUILD_MESSAGES", 99) - - this.on("messageDelete", async (data) => { - await require('../Handler/guildMessages/deleteMessage.js')(data, this) - }) - } - onMessageUpdate() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGES")) AoiError.CallbackError("onMessageUpdate", "GUILD_MESSAGES", 106) - - this.on("messageUpdate", async (oldm, newm) => { - await require('../Handler/guildMessages/updateMessage.js')(oldm, newm, this) - if (this.aoiOptions.respondOnEdit && newm.content !== oldm.content && this.aoiOptions.respondOnEdit.time > (Date.now() - newm.createdTimestamp)) { - if (this.aoiOptions.respondOnEdit.commands) { - await require('../Handler/guildMessages/commands.js')(newm, this, this.db) - } - if (this.aoiOptions.respondOnEdit.alwaysExecute) { - await require('../Handler/guildMessages/alwaysExecute.js')(this, newm, this.db) - } - if (this.aoiOptions.respondOnEdit.nonPrefixed) { - await require('../Handler/guildMessages/nonPrefixed.js')(this, newm, this.db) - } - } - }) - } - onMessageDeleteBulk() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGES")) AoiError.CallbackError("onMessageDeleteBulk", "GUILD_MESSAGES", 116) - - this.on("messageDeleteBulk", async (data) => { - await require('../Handler/guildMessages/bulkDeleteMessage.js')(data, this) - }) - } - //guild Events - onGuildJoin() { - this.on("guildCreate", async guild => await require('../Handler/guilds/guildJoin.js')(guild, this)) - } - onGuildLeave() { - this.on('guildDelete', async guild => await require('../Handler/guilds/guildLeave.js')(guild, this)) - } - onGuildUpdate() { - this.on("guildUpdate", async (oldg, newg) => await require('../Handler/guilds/guildUpdate.js')(oldg, newg, this)) - } - onGuildUnavailable() { - this.on("guildUnavailable", async guild => await require('../Handler/guilds/guildUnavailable.js')(guild, this)) - } - onRoleCreate() { - this.on("roleCreate", async role => await require('../Handler/guilds/roleCreate.js')(role, this)) - } - onRoleUpdate() { - this.on("roleUpdate", async (oldr, newr) => await require('../Handler/guilds/roleUpdate.js')(oldr, newr, this)) - } - onRoleDelete() { - this.on("roleDelete", async role => await require('../Handler/guilds/roleDelete.js')(role, this)) - } - onChannelCreate() { - this.on("channelCreate", async channel => await require('../Handler/guilds/channelCreate.js')(channel, this)) - } - onChannelUpdate() { - this.on("channelUpdate", async (oldc, newc) => await require('../Handler/guilds/channelUpdate.js')(oldc, newc, this)) - } - onChannelDelete() { - this.on("channelDelete", async channel => await require('../Handler/guilds/channelDelete.js')(channel, this)) - } - onChannelPinsUpdate() { - this.on("channelPinsUpdate", async (channel, time) => { - await require('../Handler/guilds/channelPinsUpdate.js')(channel, time, this) - }) - } - onStageInstanceCreate() { - this.on("stageInstanceCreate", async stageint => await require('../Handler/guilds/stageInstanceCreate.js')(stageint, this)) - } - onStageInstanceUpdate() { - - this.on("stageInstanceUpdate", async (oldstageint, newstageint) => await require('../Handler/guilds/stageInstanceUpdate.js')(oldstageint, newstageint, this)) - - } - onStageInstanceDelete() { - - this.on("stageInstanceDelete", async stageint => await require('../Handler/guilds/stageInstanceDelete.js')(stageint, this)) - - } - onThreadCreate() { - this.on("threadCreate", async thread => await require('../Handler/guilds/threadCreate.js')(thread, this)) - } - onThreadUpdate() { - - this.on("threadUpdate", async (oldt, newt) => await require('../Handler/guilds/threadUpdate.js')(oldt, newt, this)) - - } - onThreadDelete() { - - this.on("threadDelete", async thread => await require('../Handler/guilds/threadDelete.js')(thread, this)) - - } - onThreadListSync() { - - this.on("threadListSync", async collection => await require('../Handler/guilds/threadListSync.js')(collection, this)) - - } - onThreadMemberUpdate() { - - this.on("threadMemberUpdate", async threadMember => await require('../Handler/guilds/threadMemberUpdate.js')(threadMember, this)) - - } - onThreadMembersUpdate() { - - this.on("threadMembersUpdate", async collection => await require('../Handler/guilds/threadMembersUpdate.js')(collection, this)) - - } - //guildMembers Events - onJoin() { - if (!this.aoiOptions.intents.includes("GUILD_MEMBERS")) AoiError.CallbackError("onJoin", "GUILD_MEMBERS", 201) - this.on("guildMemberAdd", async mem => await require('../Handler/guildMembers/join.js')(mem, this)) - } - onLeave() { - if (!this.aoiOptions.intents.includes("GUILD_MEMBERS")) AoiError.CallbackError("onLeave", "GUILD_MEMBERS", 206) - this.on("guildMemberRemove", async mem => await require('../Handler/guildMembers/leave.js')(mem, this)) - } - onMemberUpdate() { - if (!this.aoiOptions.intents.includes("GUILD_MEMBERS")) AoiError.CallbackError("onMemberUpdate", "GUILD_MEMBERS", 209) - this.on("guildMemberUpdate", async (oldm, newm) => await require('../Handler/guildMembers/update.js')(oldm, newm, this)) - } - onMemberAvailable() { - if (!this.aoiOptions.intents.includes("GUILD_MEMBERS")) AoiError.CallbackError("onMemberAvailable", "GUILD_MEMBERS", 214) - this.on("guildMemberAvailable", async mem => await require('../Handler/guildMembers/available.js')(mem, this)) - } - onMembersChunk() { - if (!this.aoiOptions.intents.includes("GUILD_MEMBERS")) AoiError.CallbackError("onMembersChunk", "GUILD_MEMBERS", 217) - this.on("guildMembersChunk", async (mems, guild, chunk) => await require('../Handler/guildMembers/chunk.js')(mems, guild, chunk, this)) - } - //Emoji Events - onEmojiCreate() { - if (!this.aoiOptions.intents.includes("GUILD_EMOJIS_AND_STICKERS")) AoiError.CallbackError("onEmojiCreate", "GUILD_EMOJIS_AND_STICKERS", 222) - this.on("emojiCreate", async emoji => await require('../Handler/guildEmojis/create.js')(emoji, this)) - } - onEmojiDelete() { - if (!this.aoiOptions.intents.includes("GUILD_EMOJIS_AND_STICKERS")) AoiError.CallbackError("onEmojiDelete", "GUILD_EMOJIS_AND_STICKERS", 226) - this.on("emojiDelete", async emoji => await require('../Handler/guildEmojis/delete.js')(emoji, this)) - } - onEmojiUpdate() { - if (!this.aoiOptions.intents.includes("GUILD_EMOJIS_AND_STICKERS")) AoiError.CallbackError("onEmojiUpdate", "GUILD_EMOJIS_AND_STICKERS", 231) - this.on("emojiUpdate", async (olde, newe) => await require('../Handler/guildEmojis/update.js')(olde, newe, this)) - } - onStickerCreate() { - if (!this.aoiOptions.intents.includes("GUILD_EMOJIS_AND_STICKERS")) AoiError.CallbackError("onStickerCreate", "GUILD_EMOJIS_AND_STICKERS", 169) - this.on("stickerCreate", async sticker => await require('../Handler/guildEmojis/stickerCreate.js')(sticker, this)) - } - onStickerDelete() { - if (!this.aoiOptions.intents.includes("GUILD_EMOJIS_AND_STICKERS")) AoiError.CallbackError("onStickerDelete", "GUILD_EMOJIS_AND_STICKERS", 174) - this.on("stickerDelete", async emoji => await require('../Handler/guildEmojis/stickerDelete.js')(emoji, this)) - } - onStickerUpdate() { - if (!this.aoiOptions.intents.includes("GUILD_EMOJIS_AND_STICKERS")) AoiError.CallbackError("onStickerUpdate", "GUILD_EMOJIS_AND_STICKERS", 231) - this.on("stickerUpdate", async (olde, newe) => await require('../Handler/guildEmojis/stickerUpdate.js')(olde, newe, this)) - } - //ban events - onBanAdd() { - if (!this.aoiOptions.intents.includes("GUILD_BANS")) AoiError.CallbackError("onBanAdd", "GUILD_BANS", 235) - this.on("guildBanAdd", async ban => await require('../Handler/guildBans/add.js')(ban, this)) - } - onBanRemove() { - if (!this.aoiOptions.intents.includes("GUILD_BANS")) AoiError.CallbackError("onBanRemove", "GUILD_BANS", 239) - this.on("guildBanRemove", async ban => await require('../Handler/guildBans/remove.js')(ban, this)) - } - //invite Events - onInviteCreate() { - if (!this.aoiOptions.intents.includes("GUILD_INVITES")) AoiError.CallbackError("onInviteCreate", "GUILD_INVITES", 243) - this.on("inviteCreate", async invite => await require('../Handler/guildInvites/create.js')(invite, this)) - } - onInviteDelete() { - if (!this.aoiOptions.intents.includes("GUILD_INVITES")) AoiError.CallbackError("onInviteDelete", "GUILD_INVITES", 243) - this.on("inviteDelete", async invite => await require('../Handler/guildInvites/delete.js')(invite, this)) - } - //reactions - onReactionAdd() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGE_REACTIONS")) AoiError.CallbackError("onReactionAdd", "GUILD_MESSAGE_REACTIONS", 254) - this.on("messageReactionAdd", async (reaction, user) => await require('../Handler/guildMessageReactions/add.js')(reaction, user, this)) - } - onReactionRemove() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGE_REACTIONS")) AoiError.CallbackError("onReactionRemove", "GUILD_MESSAGE_REACTIONS", 258) - this.on("messageReactionRemove", async (reaction, user) => await require('../Handler/guildMessageReactions/remove.js')(reaction, user, this)) - } - onReactionRemoveAll() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGE_REACTIONS")) AoiError.CallbackError("onReactionRemoveAll", "GUILD_MESSAGE_REACTIONS", 263) - this.on("messageReactionRemoveAll", async message => await require('../Handler/guildMessageReactions/removeAll.js')(message, this)) - - } - onReactionRemoveEmoji() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGE_REACTIONS")) AoiError.CallbackError("onReactionRemoveEmoji", "GUILD_MESSAGE_REACTIONS", 267) - this.on("inviteCreate", async reaction => await require('../Handler/guildMessageReactions/removeEmoji.js')(reaction, this)) - } - //guildVoiceStates Events - onVoiceStateUpdate() { - if (!this.aoiOptions.intents.includes("GUILD_VOICE_STATES")) AoiError.CallbackError("onVoiceStateUpdate", "GUILD_VOICE_STATES", 272) - this.on("voiceStateUpdate", async (oldState, newState) => await require('../Handler/guildVoiceStates/update.js')(oldState, newState, this)) - } - //presence events - onPresenceUpdate() { - if (!this.aoiOptions.intents.includes("GUILD_PRESENCES")) AoiError.CallbackError("onPresenceUpdate", "GUILD_PRESENCES", 276) - this.on("presenceUpdate", async (op, np) => await require('../Handler/guildPresences/update.js')(op, np, this)) - } - //typing events - onTypingStart() { - if (!this.aoiOptions.intents.includes("GUILD_MESSAGE_TYPINGS") || !this.aoiOptions.intents.includes("DIRECT_MESSAGE_TYPINGS")) { - AoiError.CallbackError("onTypingStart", "GUILD_MESSAGE_TYPINGS or DIRECT_MESSAGE_TYPINGS", 229) - } - this.on("typingStart", async type => await require('../Handler/guildMessageTypings/start.js')(type, this)) - } - //nonIntents events - onInteractionCreate() { - this.on("interactionCreate", async interaction => await require('../Handler/nonIntents/interaction.js')(interaction, this)) - } - onApplicationCmdCreate() { - this.on("applicationCommandCreate", async app => await require('../Handler/nonIntents/appCmdCreate.js')(app, this)) - } - onApplicationCmdDelete() { - this.on("applicationCommandDelete", async app => await require('../Handler/nonIntents/appCmdDelete.js')(app, this)) - } - onApplicationCmdUpdate() { - this.on("applicationCommandUpdate", async (oapp, napp) => await require('../Handler/nonIntents/appCmdUpdate.js')(oapp, napp, this)) - } - onUserUpdate() { - this.on("userUpdate", async (ouser, nuser) => await require("../Handler/nonIntents/userUpdate.js")(ouser, nuser, this)) - } - //custom - onVariableCreate() { - this.on("variableCreate", async data => await require('../Handler/custom/varCreate.js')(data, this)) - } - onVariableDelete() { - this.on("variableDelete", async data => await require("../Handler/custom/varDelete.js")(data, this)) - } - onVariableUpdate() { - this.on("variableUpdate", async (od, nd) => await require('../Handler/custom/varUpdate.js')(od, nd, this)) - } - //commands - command(...args) { - for (const d of args) { - if (!d.name) - throw new TypeError( - `Command ${this.cmd.default.size} needs a name!` - ); - if (!d.code) - throw new TypeError( - `Command ${this.cmd.default.size} needs a code!` - ); - - this.cmd.default.set(this.cmd.default.size, d); - } - } - awaitedCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d.name}`) } - if (!d.name) { throw new Error(`Name is not probided to cmd at position ${this.cmd.awaited.size}`) } - - this.cmd.awaited.set(this.cmd.awaited.size, d) - } - deletedCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: deletedCommand. position: ${this.cmd.messageDelete.size}`) } - this.cmd.messageDelete.set(this.cmd.messageDelete.size, d) - } - updateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: updateCommand. position: ${this.cmd.messageUpdate.size}`) } - - this.cmd.messageUpdate.set(this.cmd.messageUpdate.size, d) - } - bulkDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: bulkDeletedCommand. position: ${this.cmd.messageDeleteBulk.size}`) } - - this.cmd.messageDeleteBulk.set(this.cmd.messageDeleteBulk.size, d) - } - //-------------------// - guildJoinCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: guildJoinCommand. position: ${this.cmd.guildJoin.size}`) } - - this.cmd.guildJoin.set(this.cmd.guildJoin.size, d) - } - guildLeaveCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: guildLeaveCommand. position: ${this.cmd.guildLeave.size}`) } - - this.cmd.guildLeave.set(this.cmd.guildLeave.size, d) - } - guildUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: guildUpdateCommand. position: ${this.cmd.guildUpdate.size}`) } - - this.cmd.guildUpdate.set(this.cmd.guildUpdate.size, d) - } - guildUnavailableCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: guildUnavailableCommand. position: ${this.cmd.guildUnavailable.size}`) } - this.cmd.guildUnavailable.set(this.cmd.guildUnavailable.size, d) - } - - roleCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: roleCreateCommand. position: ${this.cmd.roleCreate.size}`) } - this.cmd.roleCreate.set(this.cmd.roleCreate.size, d) - } - roleUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: roleUpdateCommand. position: ${this.cmd.roleUpdate.size}`) } - this.cmd.roleUpdate.set(this.cmd.roleUpdate.size, d) - } - roleDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: roleDeleteCommand. position: ${this.cmd.roleDelete.size}`) } - this.cmd.roleDelete.set(this.cmd.roleDelete.size, d) - } - - channelCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: channelCreateCommand. position: ${this.cmd.channelCreate.size}`) } - this.cmd.channelCreate.set(this.cmd.channelCreate.size, d) - } - channelUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: channelUpdateCommand. position: ${this.cmd.channelUpdate.size}`) } - this.cmd.channelUpdate.set(this.cmd.channelUpdate.size, d) - } - channelDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: channelDeleteCommand. position: ${this.cmd.channelDelete.size}`) } - this.cmd.channelDelete.set(this.cmd.channelDelete.size, d) - } - channelPinsUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: channelPinsUpdateCommand. position: ${this.cmd.channelPinsUpdate.size}`) } - this.cmd.channelPinsUpdate.set(this.cmd.channelPinsUpdate.size, d) - } - - stageInstanceCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: stageInstanceCreateCommand. position: ${this.cmd.stageInstanceCreate.size}`) } - this.cmd.stageInstanceCreate.set(this.cmd.stageInstanceCreate.size, d) - } - stageInstanceUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: stageInstanceUpdateCommand. position: ${this.cmd.stageInstanceUpdate.size}`) } - this.cmd.stageInstanceUpdate.set(this.cmd.stageInstanceUpdate.size, d) - } - stageInstanceDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: stageInstanceDeleteCommand. position: ${this.cmd.stageInstanceDelete.size}`) } - this.cmd.stageInstanceDelete.set(this.cmd.stageInstanceDelete.size, d) - } - - threadCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: threadCreateCommand. position: ${this.cmd.threadCreate.size}`) } - this.cmd.threadCreate.set(this.cmd.threadCreate.size, d) - } - threadUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: threadUpdateCommand. position: ${this.cmd.threadUpdate.size}`) } - this.cmd.threadUpdate.set(this.cmd.threadUpdate.size, d) - } - threadDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: threadDeleteCommand. position: ${this.cmd.threadDelete.size}`) } - this.cmd.threadDelete.set(this.cmd.threadDelete.size, d) - } - threadListSyncCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: threadListSyncCommand. position: ${this.cmd.threadListSync.size}`) } - this.cmd.threadListSync.set(this.cmd.threadListSync.size, d) - } - threadMemberUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: threadMemberUpdateCommand. position: ${this.cmd.threadMemberUpdate.size}`) } - this.cmd.threadMemberUpdate.set(this.cmd.threadMemberUpdate.size, d) - } - //--------------------------------// - joinCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: joinCommand. position: ${this.cmd.join.size}`) } - this.cmd.join.set(this.cmd.join.size, d) - } - leaveCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: leaveCommand. position: ${this.cmd.leave.size}`) } - this.cmd.leave.set(this.cmd.leave.size, d) - } - memberUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: threadMembersUpdateCommand. position: ${this.cmd.threadMembersUpdate.size}`) } - this.cmd.threadMembersUpdate.set(this.cmd.threadMembersUpdate.size, d) - } - threadMembersUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: membersUpdateCommand. position: ${this.cmd.membersUpdate.size}`) } - this.cmd.membersUpdate.set(this.cmd.membersUpdate.size, d) - } - memberAvailableCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: memberAvailableCommand. position: ${this.cmd.memberAvailable.size}`) } - this.cmd.memberAvailable.set(this.cmd.memberAvailable.size, d) - } - membersChunkCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: membersChunkCommand. position: ${this.cmd.membersChunk.size}`) } - this.cmd.membersChunk.set(this.cmd.membersChunk.size, d) - } - //---------------------------------// - emojiCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: emojiCreateCommand. position: ${this.cmd.emojiCreate.size}`) } - this.cmd.emojiCreate.set(this.cmd.emojiCreate.size, d) - } - emojiDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: emojiDeleteCommand. position: ${this.cmd.emojiDelete.size}`) } - this.cmd.emojiDelete.set(this.cmd.emojiDelete.size, d) - } - emojiUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: emojiUpdateCommand. position: ${this.cmd.emojiUpdate.size}`) } - this.cmd.emojiUpdate.set(this.cmd.emojiUpdate.size, d) - } - //--------------------------------// - banAddCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: banAddCommand. position: ${this.cmd.banAdd.size}`) } - this.cmd.banAdd.set(this.cmd.banAdd.size, d) - } - banRemoveCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: banRemoveCommand. position: ${this.cmd.banRemove.size}`) } - this.cmd.banRemove.set(this.cmd.banRemove.size, d) - } - //---------------------------------// - inviteCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: inviteCreateCommand. position: ${this.cmd.inviteCreate.size}`) } - this.cmd.inviteCreate.set(this.cmd.inviteCreate.size, d) - } - inviteDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: inviteDeleteCommand. position: ${this.cmd.inviteDelete.size}`) } - this.cmd.inviteDelete.set(this.cmd.inviteDelete.size, d) - } - //---------------------------------// - reactionAddCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: reactionAddCommand. position: ${this.cmd.reactionAdd.size}`) } - this.cmd.reactionAdd.set(this.cmd.reactionAdd.size, d) - } - reactionRemoveCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: reactionRemoveCommand. position: ${this.cmd.reactionRemove.size}`) } - this.cmd.reactionRemove.set(this.cmd.reactionRemove.size, d) - } - reactionRemoveAllCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: reactionRemoveAllCommand. position: ${this.cmd.reactionRemoveAll.size}`) } - this.cmd.reactiomRemoveAll.set(this.cmd.reactionRemoveAll.size, d) - } - reactionRemoveEmojiCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: reactionRemoveEmojiCommand. position: ${this.cmd.reactionRemoveEmoji.size}`) } - this.cmd.reactionRemoveEmoji.set(this.cmd.reactionRemoveEmoji.size, d) - } - //---------------------------------// - presenceUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: presenceUpdateCommand. position: ${this.cmd.presenceUpdate.size}`) } - this.cmd.presenceUpdate.set(this.cmd.presenceUpdate.size, d) - } - //---------------------------------// - voiceStateUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: voiceStateUpdateCommand. position: ${this.cmd.voiceStateUpdate.size}`) } - this.cmd.voiceStateUpdate.set(this.cmd.voiceStateUpdate.size, d) - } - //---------------------------------// - interactionCommand(d = {}) { - if (!d.prototype) { throw new TypeError(`Prototype is not provided in ${d.name || "unknown name"}: interactionCommand.`) } - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: interactionCommand. position: ${this.cmd.interaction[d.prototype]?.size}`) } - this.cmd.interaction[d.prototype]?.set(this.cmd.interaction[d.prototype].size, d) - } - applicationCmdCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: ApplicationCmdCreateCommand. position: ${this.cmd.applicationCmdCreate.size}`) } - this.cmd.applicationCmdCreate?.set(this.cmd.applicationCmdCreate.size, d) - } - applicationCmdDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: ApplicationCmdDeleteCommand. position: ${this.cmd.applicationCmdDelete.size}`) } - this.cmd.applicationCmdDelete?.set(this.cmd.applicationCmdDelete.size, d) - } - applicationCmdUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: ApplicationCmdUpdateCommand. position: ${this.cmd.onApplicationCmdUpdate.size}`) } - this.cmd.onApplicationCmdUpdate?.set(this.cmd.onApplicationCmdUpdate.size, d) - } - userUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: userUpdateCommand. position: ${this.cmd.userUpdate.size}`) } - this.cmd.userUpdate?.set(this.cmd.userUpdate.size, d) - } - variableCreateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: variableCreateCommand. position: ${this.cmd.variableCreate.size}`) } - this.cmd.variableCreate?.set(this.cmd.variableCreate.size, d) - } - variableDeleteCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: variableDeleteCommand. position: ${this.cmd.variableDelete.size}`) } - this.cm - d.variableDelete?.set(this.cmd.variableDelete.size, d) - } - variableUpdateCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: variableUpdateCommand. position: ${this.cmd.variableUpdate.size}`) } - this.cmd.variableUpdate?.set(this.cmd.variableUpdate.size, d) - } - readyCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: readyCommand. position: ${this.cmd.ready.size}`) } - this.cmd.ready?.set(this.cmd.ready.size, d) - } - functionErrorCommand(d = {}) { - if (!d.code) { throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: functionErrorCommand. position: ${this.cmd.functionError.size}`) } - this.cmd.functionError?.set(this.cmd.functionError.size, d) - } -} -require('../Utils/helpers/prototypes.js') -module.exports = Client; \ No newline at end of file diff --git a/package/classes/CacheManager.js b/package/classes/CacheManager.js deleted file mode 100644 index b84bd7c10..000000000 --- a/package/classes/CacheManager.js +++ /dev/null @@ -1,43 +0,0 @@ -const { CacheOptions } = require('../Utils/Constants.js') -const { Options } = require("discord.js") -const Cachers = require('../CacheHandler/index.js') -const AoiError = require('./AoiError.js') -class CacheManager { - constructor(client) { - client.cacheManager = this - Object.defineProperty(this, "client", { value: client }) - this.caches = { - cache: {}, - limitedCache: {}, - setCache: {} - } - this.Group = Cachers.cache - this.LimitGroup = Cachers.limitedCache - this.SuperSet = Cachers.setCache - } - get types() { - return ["cache", "limitedCache", "setCache"] - } - _validType(type) { - return this.types.includes(type) - } - createCache(type, name, options) { - if (!this._validType(type)) return AoiError.consoleError("CacheManagerError", "Wrong Cache Type Provided"); - - this.caches[type][name] = new Cachers[type](options) - return this.caches[type][name] - } - deleteCache(type, name) { - if (!this.validType(type)) return AoiError.consoleError("CacheManagerError", "Wrong Cache Type Provided"); - - delete this.cache[type][name] - } - static _setDjsCacheManagers(cache) { - let managers = {} - for (const [key, value] of Object.entries(cache)) { - managers[CacheOptions[key]] = value - } - return Options.cacheWithLimits(managers) - } -} -module.exports = CacheManager \ No newline at end of file diff --git a/package/classes/ClientShard.js b/package/classes/ClientShard.js deleted file mode 100644 index 205a6dff3..000000000 --- a/package/classes/ClientShard.js +++ /dev/null @@ -1,44 +0,0 @@ -const { ShardingManager } = require('discord.js') -const Collection = require('../CacheHandler/index.js').cache -class ClientShard extends ShardingManager { - constructor(file, options = {}, client) { - super(file, options); - this.client = client; - this.file = file - this.cmd = { - shardDisconnect: new Collection(), - shardError: new Collection(), - shardReady: new Collection(), - shardReconnecting: new Collection(), - shardResume: new Collection() - } - this.client.clientShard = this - this.spawn() - } - onShardDisconnect() { - this.client.on("shardDisconnect", async (event, id) => { - await require('../ShardHandler/shardDisconnect.js')(event, id, this.client, this.cmd) - }) - } - onShardError() { - this.client.on("shardError", async (error, shardID) => { - await require('../ShardHandler/shardError.js')(error, shardID, this.client, this.cmd) - }) - } - onShardReady() { - this.client.on("shardReady", async (shardID, guilds) => { - await require('../ShardHandler/shardReady.js')(shardID, guilds, this.client, this.cmd) - }) - } - onShardReconnecting() { - this.client.on("shardReconnecting", async (shardID) => { - await require('../ShardHandler/shardReconnecting.js')(shardID, this.client, this.cmd) - }) - } - onShardResume() { - this.client.on("shardResume", async (shardID, events) => { - await require('../ShardHandler/shardError.js')(shardID, events, this.client, this.cmd) - }) - } -} -module.exports = ClientShard; \ No newline at end of file diff --git a/package/classes/Commands.js b/package/classes/Commands.js deleted file mode 100644 index b8465966f..000000000 --- a/package/classes/Commands.js +++ /dev/null @@ -1,110 +0,0 @@ -const Group = require('../CacheHandler/index.js').cache -class Command { - constructor(d = {}, client) { - Object.defineProperty(this, "__client__", { value: client }) - Object.entries(d).forEach(x => this[x[0]] = x[1]) - this.functions = this.serializeFunctions(); - this.codeLines = this.serializeCode(); - } - serializeFunctions() { - - let Functions = this.__client__.functionManager.functions - let code = this.code?.replace(/\\]/g, "#LEFT#").split("\\[").join("#RIGHT#").replace("\\,", "#COMMA#") - let customFuncs = [] - let funcs = [] - let loadsOfFunc = Functions.filter(thatfunc => code.toLowerCase().includes(thatfunc.toLowerCase())) - const funcyboys = code.split("$") - for (const funcboy of funcyboys) { - let Func = loadsOfFunc.filter(f => (f).toLowerCase() === ("$" + funcboy.toLowerCase()).slice(0, f.length)) - if (!Func.length) { continue; } - if (Func.length === 1) { funcs.push(Func[0]) } - else if (Func.length > 1) { - funcs.push(Func.sort((a, b) => b.length - a.length)[0]) - } - } - return funcs - } - serializeCode() { - return this.code?.split('\n') - } - toString() { - return JSON.stringify(this) - } - toArray() { - return Object.entries(this) - } - values() { - return Object.values(this) - } - keys() { - return Object.keys(this) - } -} -class CommandManager { - constructor(client, formCommand = true, customCmds = []) { - client.cmd = this - this.client = client - this.isClientCommand = formCommand - - - if (formCommand) { - this.formCommand() - } - else { - this.customCmds = customCmds - this.formCustomCommand(customCmds) - } - } - get types() { - return [ - 'default', 'awaited', 'messageDelete', - 'messageUpdate', 'messageDeleteBulk', 'guildJoin', - 'guildUpdate', 'guildLeave', 'guildUnavailable', - 'roleCreate', 'roleUpdate', 'roleDelete', - 'channelCreate', 'channelUpdate', 'channelDelete', - 'channelPinsUpdate', 'stageInstanceCreate', 'stageInstanceUpdate', - 'stageInstanceDelete', 'stickerCreate', 'stickerDelete', - 'stickerUpdate', 'threadCreate', 'threadDelete', - 'threadListSync', 'threadMemberUpdate', 'threadMembersUpdate', - 'threadUpdate', 'join', 'leave', - 'memberUpdate', 'memberAvailable', 'membersChunk', - 'emojiCreate', 'emojiUpdate', 'emojiDelete', - 'banAdd', 'banRemove', 'webhookUpdate', - 'inviteCreate', 'inviteDelete', 'voiceStateUpdate', - 'presenceUpdate', 'reactionAdd', 'reactionRemove', - 'reactionRemoveEmoji', 'reactionRemoveAll', 'typingStart', - 'loop', 'timeout', 'pulse', - 'ready', 'variableCreate', 'variableDelete', - 'variableUpdate', 'functionError', 'interaction', - 'applicationCmdCreate', 'applicationCmdUpdate', 'applicationCmdDelete', - 'userUpdate', 'rateLimit' - ] - } - formCommand() { - this.types.forEach(x => this[x] = new Group()) - this.interaction = { - selectMenu: new Group(), - button: new Group(), - slash: new Group() - } - } - createCommand(d = {}) { - d.type = d.type || "default" - if (d.type === "interaction") { - this[d.type][d.prototype].set(this[d.type][d.prototype].size, new Command(d, this.client)) - } - else { - this[d.type].set(this[d.type].size, new Command(d, this.client)) - } - } - formCustomCommand(customCmds) { - customCmds.forEach(x => { - this[x] = new Group - }) - if (!customCmds.includes("default")) this.default = new Group() - } -} -module.exports = { - CommandManager, - Command -} \ No newline at end of file diff --git a/package/classes/Database.js b/package/classes/Database.js deleted file mode 100644 index 65f169025..000000000 --- a/package/classes/Database.js +++ /dev/null @@ -1,180 +0,0 @@ -const aoiDb = require('dbdjs.db') -const AoiError = require('./AoiError.js') -class Database { - constructor(DbModule, options = { path: "./database/", tables: ["main"] }, promisify = false) { - this.path = options.path - this.tables = options.tables || ["main"] - this.module = DbModule - - this.promisify = promisify || false - } - set(table, name, id, value) { - this.db.set(table, id ? name + "_" + id : name, value) - } - get(table, name, id) { - if (!this.promisify) return this.db.get(table, id ? name + "_" + id : name) - else return new Promise(res => res(this.db.get(table, id ? name + "_" + id : name))) - } - all(table, filter) { - if (!this.promisify) return this.db.all(table, { filter }) - else return new Promise(res => res(this.db.all(table, { filter }))) - } - delete(table, name, id) { - if (!this.promisify) return this.db.delete(table, id ? name + "_" + id : name) - else return new Promise(res => res(this.db.delete(table, id ? name + "_" + id : name))) - } - get ping() { - const start = Date.now(); - this.db.all(this.tables[0]) - return Date.now() - start - } -} -class AoijsAPI extends Database { - constructor(module, options = {}, db = {}, extraOptions = {}) { - super(module, options, db.promisify); - this.type = db.type || "default" - this.createTable(this.type) - this.extraOptions = extraOptions - } - createTable(type) { - if (["default", "dbdjs.db"].includes(type)) { - const tables = this.tables.map(x => ({ name: x })) - this.db = new aoiDb.Database({ - path: this.path, - tables: tables, - maxFileData: 10000, - cache: 10000, - saveTime: 3, - getTime: 1, - allTime: 2, - deleteTime: 4, - }) - this.db.connect(); - - this.module = aoiDb - } - else if (type === "dbdjs.mongo") { - this.db = this.module.default - this.tables.forEach(x => this.db.createModel(x)) - } - else if (type === "dbdjs.db-sql") { - this.db = this.module.PromisedDatabase(this.path.replace("./", "") + "/database.sql", this.extraOptions.sqlOptions || { timeout: 5000 }) - - } - } -} -class DbdTsDb extends Database { - constructor(module, options = {}, db = {}, extraOptions = {}) { - super(module, options, db.promisify); - this.createSetUp() - this.extraOptions = extraOptions - this.type = db.type - } - createSetUp() { - const { Database, Table, Column, ApiDatabase } = this.module - if (!this.extraOptions?.dbdtsType) { - this.db = new Database({ path: this.path.endsWith("/") ? this.path + "database.sql" : this.path + "/database.sql" }) - this.tables.forEach(x => this.db.addTable(new Table(x, this.db, [{ name: "id", type: "TEXT", primary: false }, { name: "invite_tracker", type: "JSON", default: {} }]))) - - } - else if (this.extraOptions?.dbdtsType === "api") { - - } - - } - set(table, name, id, value) { - const data = {} - data.id = id - data[name] = value - this.db.set(table, data) - } - get(table, name, id) { - let data = this.db.get(table, { - where: { - column: "id", - equals: id - } - }) - return new Promise(res => res(data[name])) - } - all(table, filter) { - if (!filter) return new Promise(res => res(this.db.all(table))); - else return new Promise(res => res(this.db.all(table).filter(filter))) - } - delete(table, name) { - this.db.delete(table, { where: { column: name } }) - } - addColumns(table, data) { - this.db.tables.get(table).addColumns(data) - this.db.connect() - } -} -class CustomDb extends Database { - constructor(module, options = {}, db = {}, extraOptions = {}) { - super(module, options, db.promisfy); - this.type = db.type - this.extraOptions = extraOptions - this.methods = Object.getOwnPropertyNames(this.module) - this.tableList = {} - this.createTables(); - } - createTables() { - let method = this.methods.filter(x => x.includes("table")) - if (method.length === 1) method = method[0] - else if (method.length >= 2) method = method.find(x => x.includes("create")) - else method = method[0] - console.log(method) - if (!method) return AoiError.consoleError("DatabaseSupportError", "This Database Is Not Supported, You Can Make An Issue At Aoijs GitHub") - this.tables.forEach(x => this.tableList[x] = new this.module[method](x)) - } - set(table, name, id, value) { - try { - this.tableList[table].set(!id ? name : name + "_" + id, value) - } - catch (e) { - AoiError.consoleError("DatabaseSupportError", "This Database Is Not Supported, You Can Make An Issue At Aoijs GitHub") - } - } - get(table, name, id) { - try { - this.tableList[table].get(`${!id ? name : name + "_" + id}`) - } - catch (e) { - AoiError.consoleError("DatabaseSupportError", "This Database Is Not Supported, You Can Make An Issue At Aoijs GitHub") - } - } - all(table, filter) { - try { - if (!filter) return this.tableList[table].all(); - else return this.tableList[table].all().filter(filter) - } - catch (e) { - AoiError.consoleError("DatabaseSupportError", "This Database Is Not Supported, You Can Make An Issue At Aoijs GitHub") - } - } - delete(table, name, id) { - try { - this.tableList[table].delete(!id ? name : name + "_" + id) - } - catch (e) { - AoiError.consoleError("DatabaseSupportError", "This Database Is Not Supported, You Can Make An Issue At Aoijs GitHub") - } - } -} -class Promisify extends CustomDb { - constructor(module, options = {}, db = {}, extraOptions = {}) { - super(module, options, db, extraOptions); - } - get(table, name, id, value) { - return new Promise(res => res(super.get(table, id ? name + "_" + id : name, value))) - } - all(table) { - return new Promise(res => res(super.all(table))) - } -} -module.exports = { - AoijsAPI, - DbdTsDb, - CustomDb, - Promisify -} diff --git a/package/classes/Functions.js b/package/classes/Functions.js deleted file mode 100644 index eca6f665e..000000000 --- a/package/classes/Functions.js +++ /dev/null @@ -1,94 +0,0 @@ -const { functions: parser, maps } = require('../functions/parser.js') -const Group = require('../CacheHandler/index.js').cache -class Function { - constructor(code, name) { - this.name = name - this.code = code - } -} -class CustomFunction { - constructor(d = {}, client) { - this.client = client - this.name = d.name - this.code = d.code - this.type = d.type - this.params = d.params - this.functions = this.type === "aoi.js" ? this.serializeFunctions() : undefined - } - serializeFunctions() { - let Functions = this.client.functionManager.functions - let code = this.code?.replace(/\\]/g, "#LEFT#").split("\\[").join("#RIGHT#").replace("\\,", "#COMMA#") - let customFuncs = [] - let funcs = [] - let loadsOfFunc = Functions.filter(thatfunc => code.toLowerCase().includes(thatfunc.toLowerCase())) - const funcyboys = code.split("$") - for (const funcboy of funcyboys) { - let Func = loadsOfFunc.filter(f => (f).toLowerCase() === ("$" + funcboy.toLowerCase()).slice(0, f.length)) - if (!Func.length) { continue; } - if (Func.length === 1) { funcs.push(Func[0]) } - else if (Func.length > 1) { - funcs.push(Func.sort((a, b) => b.length - a.length)[0]) - } - } - return funcs - } - -} -class FunctionManager { - constructor(client) { - this.client = client - this.maps = maps - this.functions = /*Object.keys(parser)*/parser - this.cache = new Group() - this.cacheFunctions() - this.interpreter = require('../interpreter.js') - } - async cacheFunctions() { - for (const func of this.functions) { - try { - const ogname = func.replace("$", "").replace("[", "") - //this.cache.set(ogname, new Function(require('../functions/funcs/'+ogname+'.js'),func)) - const file = Object.entries(this.maps).find(y => y[1].includes(ogname))?.[0] - if (!file) continue; - else { - this.cache.set(ogname, new Function(require(`../functions/Funcs/${file}/${ogname}.js`), func)) - } - } - catch (e) { - console.error(e) - continue; - } - } - } - createCustomFunction(...ds) { - for (const d of ds) { - this.cache.set(d.name.replace("$", ""), new CustomFunction(d, this.client)) - this.functions.push(d.name) - } - } - findFunctions(code = "") { - let Functions = this.functions - code = code?.replace(/\\]/g, "#LEFT#").split("\\[").join("#RIGHT#").replace("\\,", "#COMMA#") - let customFuncs = [] - let funcs = [] - let loadsOfFunc = Functions.filter(thatfunc => code.toLowerCase().includes(thatfunc.toLowerCase())) - const funcyboys = code.split("$") - for (const funcboy of funcyboys) { - let Func = loadsOfFunc.filter(f => (f).toLowerCase() === ("$" + funcboy.toLowerCase()).slice(0, f.length)) - if (!Func.length) { continue; } - if (Func.length === 1) { funcs.push(Func[0]) } - else if (Func.length > 1) { - funcs.push(Func.sort((a, b) => b.length - a.length)[0]) - } - } - return funcs - } - serializeCode(code) { - return code?.split('\n') - } -} -module.exports = { - FunctionManager, - Function, - CustomFunction -} diff --git a/package/classes/Interaction.js b/package/classes/Interaction.js deleted file mode 100644 index 5294efa61..000000000 --- a/package/classes/Interaction.js +++ /dev/null @@ -1,102 +0,0 @@ -const { cache: Group } = require('../CacheHandler/index.js') -const { EventEmitter } = require('events') -class Interaction extends EventEmitter { - constructor(client) { - super(); - this.client = client - } - resolve(data) { - data.author = data.user - } -} -class Await extends Interaction { - constructor(options, client, varData = {}) { - super(client); - this.options = options - this.tries = 0 - this.data = varData - } - async await(msgid, user, customID, data) { - this.resolve(data) - if (this.options.msgId === msgid && this.options.filter === user && this.options.customIds.includes(customID) && this.options.uses > this.tries) { - this.emit("AwaitComponent", data) - - this.tries += 1 - } else if (this.options.uses <= this.tries) { - this.removeAllListeners("AwaitComponent") - } - if (this.options.filter !== user && this.options.filter !== "everyone" && this.options.uses > this.tries && this.options.msgId === msgid) { - if (Object.keys(this.options.errorMessage).length !== 0) { - data.reply(JSON.parse(this.options.errorMessage)) - } - } - } -} -class CustomCollector extends Interaction { - constructor(options, client, varData = {}) { - super(client); - this.options = options - this.mainData = [] - this.timeout = setTimeout - this.endsOn = (Date.now() + Number(options.time)); - this.data = varData - } - async start(msgid, user, customID, data) { - this.resolve(data) - if (this.options.customIDs.includes(customID) && this.endsOn >= Date.now() && this.options.msgid === msgid && (this.options.filter === "everyone" || this.options.filter === user)) { - this.mainData.push(data) - this.emit("ItemFound", data) - } - this.timeout(() => { - this.emit("CustomCollectorOff", this.mainData); - delete this.options._timeout - delete this._events.ItemFound - }, this.options._timeout) - - if (this.options.filter !== "everyone" && this.options.filter !== user && Object.keys(this.options.errorMessage).length !== 0 && this.endsOn > Date.now() && this.options.msgid === msgid) { - data.reply(this.options.errorMessage) - } - } -} -class InteractionManager extends Interaction { - constructor(client) { - super(client); - this.awaitComponents = Await - this.ComponentsCollector = CustomCollector - - this.buttonData = new Group() - this.applicationData = new Group() - this.selectMenuData = new Group() - } - createApplicationData(d = {}) { - this.applicationData.set(d.guildId ? `${d.data.name}_${d.guildId}` : d.data.name, d.data) - } - createButtonData(d = {}) { - this.buttonData.set(d.customId, d) - } - createSelectMenuData(d = {}) { - this.selectMenuData.set(d.customId, d) - } - stringifyApplicationData(name) { - return JSON.stringify(this.ApplicationData.get(name)) - } - resolveButtonData(customId) { - const d = this.buttonData.get(customId) - return `{button:${d.label}:${d.style}:${d.customId}:${d.disabled}:${d.emoji}}` - } - resolveSelectMenuData(customId) { - const d = this.selectMenuData.get(customId) - return `{selectMenu:${d.customId}:${d.placeholder}:${d.minValues}:${d.maxValues}:${d.disabled}:${this.resolveSelectMenuOptionData(d.options)}` - } - resolveSelectMenuOptionData(options) { - let opt = [] - for (const o of options) { - opt.push(`{selectMenuOptions:${o.label}:${o.value}:${o.description}:${o.default}:${o.emoji}}`) - } - return opt.join("") - } - get buttonDataLength() { - return this.buttonData.size - } -} -module.exports = InteractionManager \ No newline at end of file diff --git a/package/classes/InviteSystem.js b/package/classes/InviteSystem.js deleted file mode 100644 index 64873c74c..000000000 --- a/package/classes/InviteSystem.js +++ /dev/null @@ -1,152 +0,0 @@ -const Group = require('../CacheHandler/index.js').cache -const {EventEmitter} = require ('events'); -const timer = ms => new Promise((res,rej)=>setTimeout(()=>res,ms)) -class InviteSystem extends EventEmitter { -constructor(client,cache=false){ - super(); - this.fakeLimit = "1209600000" - this.cache = cache - this.client = client - this.invites = new Group() - this.ready =false - this.timeStamp = null - this.guilds = client.guilds.cache - this.db = this.client.db - if(cache){ - this.users = new Group() - } - - this.on("FINISHED",()=>{console.log("Fetched All Invites"); - this.timeStamp = Date.now() - this.ready = true - }) - this.client.inviteSystem = this - } -async fetchAll(){ - this.ready = false - for(let i = 0;i < this.guilds.size;i++){ - const guild = [...this.guilds.values()][i] - this.invites.set(guild.id,await guild.invites.fetch()) - - await timer(1500); - - } - this.emit("FINISHED") - } -async fetchInvites(guild){ - return guild.invites.fetch() -} -async fetchInviters(){ - const allData = await this.db.all("invite") -for(const data of allData){ - this.users.set(data.key,data) - } -console.log("Fetched All Inviters") -} -get totalInvitesCount(){ - let i = 0 - for(const invites of this.invites.array()){ - i += invites.size - } - return i; -} -set(guildID,code,invite){ -return this.invites.get(guildID).set(code,invite) -} -invitesCount(guildID){ - return this.invites.get(guildID).size - } -delete(guildID,code){ - this.invites.get(guildID).delete(code) -} -dataFormat(){ - const format ={ - inviter:{id:"id",code:[]}, - counts :{real:0,fake:0,leave:0,bonus:0,total:0} - } - return format -} -createUser(guild,userID,code){ -let data = this.dataFormat() -data.inviter.id = userID -data.inviter.code.push(code) -this.db.set(this.db.tables[0],`${guild}_${userID}`,data) - return ; -} -async count(guildID,inviter,type){ - if(this.cache){ - const user = this.users.get(`${guildID}_${inviter}`) - if(!user) return "User isn't An Inviter For this Server" - return user.value.counts[type] - } - else { const data = await this.db.get(this.db.tables[0],`${guildID}_${inviter}`) -return data.value.counts[type]||"" - } -} -async lb(custom="{top}) {username}: `total:{total}`,`real:{real}`,`fake:{fake}`,`leave:{leave}`",list=10,page=1){ - let datas; -if(this.cache){ - datas = this.users.allValues() - } -else{ - datas = await this.db.all(this.db.tables[0]) - } - let lb = [] - let i = 1 - - for(const d of datas){ - const format = custom.replace(/{top}/g,i) -.replace(/{username}/g,this.client.users.cache.get(d.data.value.inviter.id)?.username) -.replace(/{total}/g,d.data.value.counts.total) -.replace(/{real}/g,d.data.value.counts.real) -.replace(/{fake}/g,d.data.value.counts.fake) -.replace(/{leave}/g,d.data.value.counts.leave) -.replace(/{id}/g,(d.data.value.inviter.id)) -.replace(/{tag}/g,this.client.users.cache.get(d.data.value.inviter.id)?.tag) - - lb.push(format) - i++ - } - return lb.slice((page-1)*list,page*list).join("\n") -} -async userJoined(mem){ - const invites = this.invites.get(mem.guild.id).allValues() - const newDatas = (await this.fetchInvites(mem.guild)).allValues() - for(let i = 0;i < invites.length;i++){ - const index = invites.indexOf(newDatas[i].code) - -if(invites[index] && invites[index].uses < newDatas[i].uses){ - const inviter = await this.db.get("invite",`${mem.guild.id}_${invites[index].inviter.id}`) -if(Number(BigInt(mem.user.createdTimestamp)) >= Number(BigInt(this.fake.limit))){ - inviter.value.counts.real += 1 - inviter.value.counts.total += 1 - } - else{ - inviter.value.counts.fake += 1 - } -this.db.set("invite",`${mem.guild.id}_${inviter.id}`,inviter.value) - break; - } - else{continue;} - } -} -async inviteCreate(invite){ - const user =await this.db.get(invite.inviter?.id) - if(user){ - user.inviter.code.push(invite.code) - this.db.set("invite", invite.inviter?.id,user) - } - else return ; -} -async inviteDelete(invite){ - const user = await this.db.get(invite.inviter?.id) - if(user){ - const index = user.inviter.code.indexOf(invite.code) - user.inviter.code.splice(index,1) - this.db.set("invite",invite.inviter?.id,user) - } -} -} - - -module.exports = InviteSystem ; \ No newline at end of file diff --git a/package/classes/Lavalink.js b/package/classes/Lavalink.js deleted file mode 100644 index 808a932ae..000000000 --- a/package/classes/Lavalink.js +++ /dev/null @@ -1,158 +0,0 @@ -const LavaCoffee = require("lavacoffee"); -const { EventEmitter } = require("events"); -const emit = require("../Handler/lavalink/trackEvent"); - -class Lavalink extends EventEmitter { - constructor(client) { - super(); - /** - * @type {import("discord.js").Client} - */ - this.client = client; - /** - * @type {{name: string, code: string, channel: string}[]} - */ - this.start_commands = []; - /** @type {{name: string, code: string, channel: string}[]} */ - this.end_commands = []; - const lavalink = new LavaCoffee.CoffeeLava({ send: (guildId, d) => { - const guild = this.client.guilds.cache.get(guildId); - if (guild) guild.shard.send(d); - }}); - lavalink.on("nodeConnect", (node) => this.debug(`Node ${node.options.url} connected`)); - lavalink.on("nodeDisconnect", (node) => this.debug(`Node ${node.options.url} disconnected`)); - lavalink.on("playerCreate", (p) => this.debug(`Player created for GUILD(${p.options.guildID})`)); - lavalink.on("playerDestroy", (p) => this.debug(`Player destroyed for GUILD(${p.options.guildID})`)); - // lavalink.on("playerReplay", (p) => { - // this.debug(`Player replayed for GUILD(${p.options.guildID})`); - // this.emit("trackReplayed", p, p.queue.current); - // }); - lavalink.on("trackStart", (p, track) => { - this.debug(`Player starting track for GUILD(${p.options.guildID})`); - this.handleEvent('start', p, track); - }); - lavalink.on("trackEnd", (p, track, reason) => { - this.debug(`Player ended track for GUILD(${p.options.guildID})`); - this.handleEvent("end", p, track, reason); - }); - lavalink.on("trackStuck", (p, track, reason) => { - this.debug(`Player sent STUCK for GUILD(${p.options.guildID})`); - p.queue.current = undefined; - this.handleEvent("end", p, track, reason); - }); - lavalink.on("trackError", (p, track, reason) => { - this.debug(`Player sent EXCEPTION for GUILD(${p.options.guildID})`); - p.queue.current = undefined; - this.handleEvent("end", p, track, reason); - }); - /** @type {import("lavacoffee").CoffeeLava} */ - this.lavalink = lavalink; - this.client.lavalink = this; - this.client.on("raw", (d) => this.lavalink.updateVoiceData(d)); - if (this.client.readyTimestamp) this.lavalink.init(this.client.user.id); - this.client.once("ready", () => this.lavalink.init(this.client.user.id)); - }; - - _validate(command) { - if (!command.channel) return new Error("Channel is required"); - if (!command.code) return new Error("Code is required"); - } - /** - * - * @param {LavaCoffee.CoffeePlayer} player - * @param {LavaCoffee.CoffeeTrack} track - */ - getLeft(player, track) { - // const rate = player.filters.timescale?.rate ?? 1; - // const speed = player.filters.timescale?.speed ?? 1; - - const length = track.length; - let sub = Date.now() - player.lastUpdated; - if (player.queue.current && player.state === LavaCoffee.Utils.PlayerStates.Paused) - sub = 0; - const res = length - (player.position + Math.round(sub) /* *rate */) - return this.getTime(res /* /speed */ / 1000); - } - /** - * - * @param {LavaCoffee.CoffeePlayer} player - */ - getCurrent(player) { - // const rate = (player.filters.timescale?.rate ?? 1); - // const speed = player.filters.timescale?.speed ?? 1; - - let sub = Date.now() - player.lastUpdated; - if (player.queue.current && player.state === LavaCoffee.Utils.PlayerStates.Paused) - sub = 0; - //(player.position + (Date.now() - player.lastUpdated)) / 1000) - const res = player.position + Math.round(sub) /* *rate */; - return this.getTime(Math.round(res /* *speed */ / 1000)); - } - /** - * - * @param {{name: string, code: string, channel: string}} command - */ - trackStartCommand(command) { - const c = this._validate(command); - if (c) throw c; - - this.start_commands.push(command) - } - - /** - * - * @param {{name: string, code: string, channel: string}} command - */ - trackEndCommand(command) { - const c = this._validate(command); - if (c) throw c; - - this.end_commands.push(command) - } - - /** - * - * @param {"start" | "end"} event - * @param {LavaCoffee.CoffeePlayer} player - * @param {LavaCoffee.CoffeeTrack} track - * @param {string?} [reason] - */ - handleEvent(event, player, track, reason) { - if (event === "start") { - // Hardest to implement because of v5 compatibility - emit(this.start_commands, track, player, this); - } else if (event === "end") { - // hi weird system, here's a counter - player.state = LavaCoffee.Utils.PlayerStates.Paused; - emit(this.end_commands, track, player, this, reason); - } - } - - getTime(ms) { - const h = Math.trunc(ms / 3600); - const m = Math.trunc((ms - (h * 3600)) / 60); - const s = Math.trunc((ms - (h * 3600 + m * 60))) - - return { - hour: h, - minute: `${String(m).length<2 ? "0" : ""}${String(m)}`, - second: `${String(s).length<2 ? "0" : ""}${String(s)}` - } - } - get version() { - return LavaCoffee.version - } - /** - * Creates a connection to Lavalink, refers as node - * @param {import("lavacoffee/dist/utils/typings").NodeOptions} options - */ - addNode(options) { - return this.lavalink.add(options); - } - - debug(message) { - this.emit("debug", `[\u001b[36;1mLavaCoffee\u001b[0m]:`, String(message)); - } -} - -module.exports = Lavalink; diff --git a/package/classes/LoadCommands.js b/package/classes/LoadCommands.js deleted file mode 100644 index 462e37b06..000000000 --- a/package/classes/LoadCommands.js +++ /dev/null @@ -1,287 +0,0 @@ -const fs = require("fs"); -const { CommandManager } = require('./Commands.js') -const Group = require("../CacheHandler/group.js") -//const Client = require("./Bot.js") -class LoadCommands { - constructor(client, addClassInClient = true) { - this.client = client - this.paths = [] - this.colors = {} - if (addClassInClient) { - this.client.loader = this - } - } - async load(client, path, debug = true) { - - - function isObject(data) { - return ( - data instanceof Object && - !Buffer.isBuffer(data) && - !Array.isArray(data) && - !(data instanceof RegExp) - ); - } - - async function walk(file) { - const something = await fs.promises - .readdir(file, { withFileTypes: true }) - .then(f => { - return f.map(d => { - d.name = `${file}/${d.name}`; - - return d; - }); - }); - - const files = something.filter(d => d.isFile()); - const dirs = something.filter(d => d.isDirectory()); - - for (const d of dirs) { - const items = await walk(d.name); - - files.push(...items); - } - - return files; - } - - if (typeof path !== "string") - throw new TypeError( - `Expecting typeof string on 'path' parameter, get '${typeof path}' instead` - ); - - if (!require("path").isAbsolute(path)) path = require("path").resolve(path); - - try { - if (await fs.promises.stat(path).then(f => !f.isDirectory())) - throw new Error("e"); - } catch { - throw new TypeError("Path is not a valid directory!"); - } - - const index = this.paths.findIndex(d => d.path === path); - - if (index < 0) - this.paths.push({ - path, - debug, - commandsLocation: client, - keys: Object.keys(client) - }); - - const validCmds = Object.getOwnPropertyNames(client); - - const dirents = await walk(path); - const debugs = []; - - for (const { name } of dirents) { - delete require.cache[name]; - - let cmds; - - try { - cmds = require(name); - } catch { - debugs.push(`${this.colors.failedWalking?.text || ""} Failed to walk in ${this.colors.failedWalking?.name || ""}${name}${this.allColors.reset || ""}`); - - continue; - } - - if (cmds == null) { - debugs.push(`${this.colors.noData?.text || ""} No data provided in ${this.colors.noData?.name || ""}${name}${this.allColors.reset || ""}`); - - continue; - } - - if (!Array.isArray(cmds)) cmds = [cmds]; - - debugs.push(`${this.colors?.walking || ""} Walking in ${name}${this.allColors.reset || ""}`); - - for (const cmd of cmds) { - if (!isObject(cmd)) { - debugs.push(` Provided data is not an object`); - - continue; - } - - if (!("type" in cmd)) cmd.type = "default"; - - const valid = validCmds.some(c => c === cmd.type); - - if (!valid) { - debugs.push( - `|${this.colors.typeError?.command || ""}${cmd.name || cmd.channel}${this.allColors.reset}|${this.colors.typeError?.type || ""}${cmd.type} ${this.allColors.reset}|${this.colors.typeError?.text || ""}Invalid Type Provided${this.allColors.reset}|` - ); - - continue; - } - - cmd.load = true; - - try { - if (client instanceof CommandManager) { - client.createCommand(cmd) - } - else { -/*if(cmd.type === "interaction"){ - client[cmd.type][cmd.prototype].set(client[cmd.type][cmd.prototype].size,cmd); -} - else */client[cmd.type].set(client[cmd.type].size, cmd) - } - } catch (e) { - console.log(e) - debugs.push( - `|${this.colors.failLoad?.command || ""}'${cmd.name || cmd.channel}'| ${this.colors.failLoad?.type || ""}${cmd.type}${this.allColors.reset}| ${this.colors.failLoad?.text || ""}Failed To Load${this.allColors.reset}| -|-------------------------------------------|` - ); - - continue; - } - - debugs.push(`|${this.colors.loaded?.command || ""}'${cmd.name || cmd.channel}' |${this.colors.loaded?.type || ""}${cmd.type} ${this.allColors.reset || ""}|${this.colors.loaded?.text || ""}Loaded${this.allColors.reset || ""}| -|------------------------------------------|`); - } - } - - if (debug) { - console.log( - `| ${this.colors.loaded?.command || ""}Command${this.allColors.reset} | ${this.colors.loaded?.type || ""}Type${this.allColors.reset} | ${this.colors.loaded?.text}State${this.allColors.reset} | -|------------------------------------------|\n` + - debugs.join("\n") - - ); - } - } - async update(debug = true) { - for (const dp of this.paths) { - - for (const cmd of dp.keys) { - try { - if (cmd === "interaction") { - dp.commandsLocation.interaction.slash = dp.commandsLocation.interaction.slash.filter(x => !x.load) - dp.commandsLocation.interaction.button = dp.commandsLocation.interaction.button.filter(x => !x.load) - dp.commandsLocation.interaction.selectMenu = dp.commandsLocation.interaction.selectMenu.filter(x => !x.load) - } - else dp.commandsLocation[cmd] = dp.commandsLocation[cmd].filter(x => !x.load) - if (cmd.loopInterval) { - clearInterval(cmd.loopInterval) - } - } - catch (e) { - - continue; - } - } - await this.load(dp.commandsLocation, dp.path, debug) - } - } - setColors(c = { - failLoad: null, - walking: null, - failedWalking: null, - loaded: null, - typeError: null, - noData: null - }) { - for (const co of Object.keys(c)) { - if (Array.isArray(c[co])) { - this.colors[co] = c[co]?.map(x => this.allColors[x]).join(" ") - } - else if (typeof c[co] === "object" && !Array.isArray(c[co])) { - this.colors[co] = {} - for (const coo of Object.keys(c[co])) { - if (Array.isArray(c[co][coo])) { - this.colors[co][coo] = c[co][coo].map(x => this.allColors[x]).join(" ") - } - else this.colors[co][coo] = c[co][coo] - } - } - else this.colors[co] = this.allColors[c[co]] - } - } - get allColors() { - return { - reset: "\x1b[0m", - bright: "\x1b[1m", - dim: "\x1b[2m", - underscore: "\x1b[4m", - blink: "\x1b[5m", - reverse: "\x1b[7m", - hidden: "\x1b[8m", - - - fgBlack: "\x1b[30m", - fgRed: "\x1b[31m", - fgGreen: "\x1b[32m", - fgYellow: "\x1b[33m", - fgBlue: "\x1b[34m", - fgMagenta: "\x1b[35m", - fgCyan: "\x1b[36m", - fgWhite: "\x1b[37m", - - bgBlack: "\x1b[40m", - bgRed: "\x1b[41m", - bgGreen: "\x1b[42m", - bgYellow: "\x1b[43m", - bgBlue: "\x1b[44m", - bgMagenta: "\x1b[45m", - bgCyan: "\x1b[46m", - bgWhite: "\x1b[47m", - - - }; - } - get themes() { - return { - default: { - walking: ["blink", "dim", "fgWhite"], - failedWalking: { - name: ["bright", "fgYellow", "underline"], - - text: ["bright", "fgRed"] - }, - typeError: { - command: ["bright", "fgYellow"], - type: ["fgYellow"], - text: ["bright", "fgRed"] - }, - failLoad: { - command: ["bright", "fgMagenta"], - type: ["fgRed"], - text: ["bright", "fgRed"], - }, - loaded: { - command: ["bright", "fgCyan"], - type: ["bright", "fgBlue"], - text: ["bright", "fgGreen"] - }, - }, - diff: { - walking: ['fgGreen'], - failedWalking: { - text: ['fgRed'], - name: ['bright', 'fgRed'] - }, - typeError: { - command: ['bright', 'fgRed'], - type: ['fgRed'], - text: ['dim', 'fgRed'], - }, - failLoad: { - command: ['bright', 'fgRed'], - type: ['fgRed'], - text: ['dim', 'fgRed'], - }, - loaded: { - command: ['bright', 'fgCyan'], - type: ['fgCyan'], - text: ['dim', 'fgCyan'], - } - } - } - } -} - - -module.exports = LoadCommands; diff --git a/package/classes/NewEvent.js b/package/classes/NewEvent.js deleted file mode 100644 index c1b1249e2..000000000 --- a/package/classes/NewEvent.js +++ /dev/null @@ -1,32 +0,0 @@ -const Collection = require('../CacheHandler/index.js').cache -const EventExecuter = require('../Handler/eventExecuter.js') -const { EventEmitter } = require('events') -class CustomEvent extends EventEmitter { - constructor(client) { - super(client); - this.client = client - this.commands = new Collection() - this.client.customEvents = this - } - command(d = {}) { - if (!d.listen) { - throw new TypeError(`Listen is not provided in ${d.name}`) - } - if (!d.code) { - throw new TypeError(`Code is not provided in ${d.name}`) - } - - this.commands.set(d.name, d) - } - listen(event) { - - super.on(event, async (...data) => { - - const commands = this.commands.filter(x => x.listen.toLowerCase() === event) - EventExecuter(event, this.client, commands, ...data) - }) - - } - -} -module.exports = CustomEvent; \ No newline at end of file diff --git a/package/classes/Util.js b/package/classes/Util.js deleted file mode 100644 index 06a3dff51..000000000 --- a/package/classes/Util.js +++ /dev/null @@ -1,139 +0,0 @@ -const Constants = require('../Utils/Constants.js') -const Discord = require("discord.js") -class Util { - static constants = Constants - - static getUser(d, id) { - let user = d.client.users.cache.get(id) - if (!user) { - user = this.fetchUser(d, id) - } - return user - } - static async fetchUser(d, id) { - return d.client.users.fetch(id).catch(err => undefined) - } - static async fetchChannel(d, id) { - return d.client.channels.fetch(id).catch(e => undefined) - } - static getChannel(d, id, force = false) { - if (d.channel?.id === id) return d.channel; - else { - let channel = d.client.channels.cache.get(id) - if (!channel && force) channel = this.fetchChannel(d, id) - return channel - } - } - static async fetchMember(guild, id) { - return guild.members.fetch(id).catch(err => undefined) - } - static async fetchMembers(guild, options) { - return guild.members.fetch(options) - } - static getMember(guild, id) { - let member = guild.members.cache.get(id) - if (!member) member = this.fetchMember(guild, id) - return member - } - static getMembers(guild, options = { type: "startsWith", query: "", limit: 10 }, force = false) { - let members; - if (!force) { - members = guild.members.cache.filter(x => x.user.username.toLowerCase()[options.type](options.query) || x.displayName?.toLowerCase()[options.type](options.query)).first(options.limit); - } - else { - members = this.fetchMembers(guild, options) - } - return members - } - static async fetchMessage(channel, id) { - return channel.messages.fetch(id).catch(err => undefined) - - } - static getMessage(channel, id) { - let message = channel.messages.cache.get(id) - if (!message) message = this.fetchMessage(channel, id) - return message - } - static setCode(options = {}, esacpe = true) { - return options.code.replaceLast(options.inside ? `${options.function}${options.inside}` : `${options.function}`, (esacpe ? options.result?.toString()?.deleteBrackets() : options.result.toString()) ?? " "); - } - static async getGuild(d, id) { - if (d.guild?.id === id && d.guild?.id) return d.guild; - else { - if (!d.client.clientShard) return d.client.guilds.cache.get(id); - else { - const arr = await d.client.clientShard.broadcastEval(client => client.guilds.cache.get(id)); - return arr.find(x => x); - } - } - } - static get channelTypes() { - return { - Text: "GUILD_TEXT", - Dm: "DM", - Voice: "GUILD_VOICE", - GroupDm: "GROUP_DM", - Category: "GUILD_CATEGORY", - News: "GUILD_NEWS", - Store: "GUILD_STORE", - NewsThread: "GUILD_NEWS_THREAD", - PublicThread: "GUILD_PUBLIC_THREAD", - PrivateThread: "GUILD_PRIVATE_THREAD", - Stage: "GUILD_STAGE_VOICE", - Unknown: "UNKNOWN" - } - } - static get threadTypes() { - return { - public: "GUILD_PUBLIC_THREAD", - private: "GUILD_PRIVATE_THREAD" - } - } - static async errorParser(error, d) { - const parsers = require('../Handler/parsers.js') - try { - error = JSON.parse(error) - if (error.embeds?.includes("{newEmbed:")) { - error.embeds = await parsers.EmbedParser(error.embeds || "") - } - if (error.components?.includes("{actionRow:")) { - error.components = await parsers.ComponentParser(error.components || "", d.client) - - } - if (typeof error.options === "string" && ["{reactions:", "{edit:", "{deletecommand:", "{delete:"].some(x => error.options?.includes(x))) { - console.log("options working"); - error.options = await parsers.OptionParser(error.options || "", d) - } - if (error.embeds?.includes("{attachment:") || error.embeds?.includes("{file:")) { - error.files = await parsers.FileParser(error.files || "") - console.log(error) - } - } - catch (e) { - error = await parsers.ErrorHandler(d, error, true) - } - return error; - } - static openFunc(d, FieldsRequired = true) { - const data = { - code: d.command.code, - inside: d.unpack(), - function: d.func - } - if (FieldsRequired) { - data.err = d.inside(data.inside) - } - return data - } - static getEmoji(d, Emoji) { - return d.client.emojis.cache.find(x => x.name.toLowerCase() === Emoji.toLowerCase().addBrackets() || x.id === Emoji || x.toString() === Emoji) - } - static getSticker(guild, Sticker) { - return guild.stickers.cache.find(x => x.name.toLowerCase() === Sticker.toLowerCase().addBrackets() || x.id === Sticker) - } - static async findId(d, id) { - const data = this.getGuild(d, id) || await this.getUser(d, id) || await this.getChannel(d, id, false) || await this.getMessage(d.channel, id) || this.getEmoji(d, id) || this.getSticker(d.guild, id) || "nope" - return data - } -} -module.exports = Util; diff --git a/package/classes/Variables.js b/package/classes/Variables.js deleted file mode 100644 index 98ad12816..000000000 --- a/package/classes/Variables.js +++ /dev/null @@ -1,77 +0,0 @@ -const Group = require('../CacheHandler/index.js').cache -class Variable { - constructor(data = {}) { - this.name = data.name - this.type = data.type - this.default = data.value - - } - object() { - let x = {} - Object.assign(x, this) - return x - } - toJSON() { - return JSON.stringify(this.object(), null, 2) - } - entries() { - return Object.entries(this) - } - get toArray() { - return Object.values(this) - } -} -class VariableManager { - constructor(client) { - this.client = client - this.cache = new Group() - } - findType(value) { - let res; - switch (typeof value) { - case "string": - res = "TEXT" - break; - case "number": - if (Number.isInteger(value)) res = "INTEGER" - else res = "NUMERIC" - break; - case "object": - res = "JSON" - break; - } - return res - } - get size() { - return this.cache.size - } - get values() { - return this.cache.allValues().map(x => x.value) - } - get vars() { - return this.cache.allKeys() - } - add(data) { - data.type = this.findType(data.value) - this.cache.set(data.name, new Variable(data)) - } - delete(name) { - this.cache.delete(name) - } - get(name) { - return this.cache.get(name) - } - has(name) { - return this.cache.has(name); - } - toJSON() { - const keys = this.cache.allKeys(); - const values = this.cache.allValues(); - const json = keys.map(x => this.cache.get(x).toJSON()) - return "{\n" + keys.map((x, y) => `"${x}" : ${json[y]} `).join(",\n") + "\n}" - } -} -module.exports = { - Variable, - VariableManager -} \ No newline at end of file diff --git a/package/classes/Voice.js b/package/classes/Voice.js deleted file mode 100644 index 39823483e..000000000 --- a/package/classes/Voice.js +++ /dev/null @@ -1,69 +0,0 @@ -const { joinVoiceChannel, entersState, VoiceConnectionStatus } = require('@discordjs/voice') -const { CommandManager } = require('./Commands.js') -const Group = require('../CacheHandler/index.js').cache -const ServerManager = require('../Handler/music/class/ServerManager.js') -const { EventEmitter } = require('events') -const { Events } = require('../Utils/VoiceConstants.js') -const AoiError = require('./AoiError.js') -class Voice extends EventEmitter { - constructor(client, - yt = {}, - sc = {}, - cache = { - enabled: false, - tracksPerGuild: 20 - } - ) { - super(); - this.functionManager = client.functionManager - this.client = client - client.voiceManager = this - this.voice = client.voice - this.servers = new Group() - this.ytdl = yt - this.scdl = sc - this.cache = cache - new CommandManager(this, false, Object.values(Events)) - } - async joinVc(channel, textChannel, debug = false) { - const d = { - channelId: channel.id, - guildId: channel.guildId, - adapterCreator: channel.guild.voiceAdapterCreator, - debug: debug, - group: this.client.user.id - } - console.log(d) - const connection = joinVoiceChannel(d) - connection.on("debug", console.log) - connection.on('error', console.error) - try { - await entersState(connection, VoiceConnectionStatus.Ready, 30000) - this.servers.set(channel.guild.id, new ServerManager({ connection, channel, textChannel, voice: this })) - } - catch (error) { - - connection.destroy() - AoiError.consoleError("joinVoiceChannelError", error) - } - } - get serversSize() { - return this.servers.size - } - musicStartCommand(d = {}) { - this.cmd.musicStart.set(this.cmd.musicStart.size, d) - } - musicErrorCommand(d = {}) { - this.cmd.musicError.set(this.cmd.musicError.size, d) - } - trackEndCommand(d = {}) { - this.cmd.trackEnd.set(this.cmd.trackEnd.size, d) - } - queueEndCommand(d = {}) { - this.cmd.queueEnd.set(this.cmd.queueEnd.size, d) - } - onMusicStart() { - this.on(Events.TRACK_START, async (track, server) => require('../Handler/music/events/musicStart.js')(track, server, this, this.client)) - } -} -module.exports = Voice; \ No newline at end of file diff --git a/package/classes/base.js b/package/classes/base.js deleted file mode 100644 index e8481c69a..000000000 --- a/package/classes/base.js +++ /dev/null @@ -1,130 +0,0 @@ -const Discord = require("discord.js"); -const dbddb = require('dbdjs.db') - -const { VariableManager } = require('./Variables.js') -const Blacklist = require('./Blacklist.js') -const Group = require('../CacheHandler/index.js').cache -const InteractionManager = require("./Interaction.js") -const { ActivityTypeAvailables, IntentOptions, SlashOptionTypes } = require('../Utils/Constants.js') -const { AoijsAPI, DbdTsDb, CustomDB, Promisify } = require('./Database.js') -const CacheManager = require('./CacheManager.js') - -class BaseClient extends Discord.Client { - constructor(options) { - if (options.cache) { - options.makeCache = CacheManager._setDjsCacheManagers(options.cache) - } - - if (options.presence?.activites?.length) { - if (Object.keys(ActivityTypeAvailables).includes(options.presence?.activities[0].type) || Object.values(ActivityTypeAvailables).includes(options.presence?.activities[0].type)) { - options.presence.activities[0].type = ActivityTypeAvailables[options.presence?.activities[0].type] || options.presence?.activities[0].type - - } - else { - throw new TypeError(`ActivityTypeAvailablesError: Invalid Activity Type (${options.presence?.activities[0].type}) Provided`) - } - } - - options.partials = options.partials || ["CHANNEL", "GUILD_MEMBER", "MESSAGE", "USER", "REACTION"] - - options.intents = !Array.isArray(options.intents) ? (options.intents?.toLowerCase() === "all" ? IntentOptions.all : undefined) : options.intents.map(x => IntentOptions[x] || x) - - const aoiOptions = Object.assign({}, options); - - super(options); - this.aoiOptions = aoiOptions; - - this.interactionManager = new InteractionManager(this) - - this.blacklist = new Blacklist(this) - - this.cacheManager = new CacheManager(this) - - this.variableManager = new VariableManager(this) - - if (["default", "dbdjs.db", "dbdjs.db-sql", "dbdjs.mongo"].includes(options?.database?.type)) { - this.db = new AoijsAPI(options?.database?.db || dbddb, { - path: options?.database?.path || "./database/", - tables: options?.database?.tables || ["main"] - }, { type: options?.database?.type || "default", promisify: options?.database?.promisify || false }, options.database?.extraOptions || {}) - - } - - else if (options?.database?.type === "dbdts.db") { - this.db = new DbdTsDb(options.database?.db, { path: options.database?.path || "./database", tables: options?.database?.tables || ["main"] }, { type: "dbdts.db", promisify: false }, options.database?.extraOptions || {}) - } - - else if (options?.database?.type === "custom" && !options?.database?.promisify) { - this.db = new CustomDB(options?.database?.db, { path: options.database?.path || "./database", tables: options?.database?.tables || ["main"] }, { type: "custom", promisify: true }, options.database?.extraOptions || {}) - } - else if (options?.database?.type === "custom" && options?.database?.promisify) { - this.db = new Promisify(options.database?.db, { path: options.database?.path || "./database", tables: options?.database?.tables || ["main"] }, { type: "custom", promisify: true }, options.database?.extraOptions || {}) - } - - else { - this.db = new AoijsAPI(options?.database?.db || dbddb, - { - - path: options?.database?.path || "./database/", - - tables: options?.database?.tables || ["main"] - - }, - { - type: options?.database?.type || "default", promisify: options?.database?.promisify || false - }, - options.database?.extraOptions || {}) - } - - if (options?.events?.functionError) { - this.on("functionError", async (data, client) => { await require('../Handler/custom/functionError.js')(data, client) }) - } - - this.prefix = options.prefix - Object.defineProperty(this, "statuses", { value: new Group() }) - if (options.mobilePlatform === true) { - this.options.ws.properties.$browser = "Discord Android" - } - this.on("ready", async () => { - require('../Handler/status.js')(this.statuses, this); - require('../Handler/startup.js')(this); - if (options?.fetchInvites?.enabled) { - require('../Handler/fetchInvites.js')(this) - } - await require('../Handler/nonIntents/ready.js')(this) - }) - this._api = (url) => `https://discord.com/api/v9/${url.startsWith("/") ? url.slice(1) : url}` - this.login(options.token) - - } - status(...statuses) { - - for (const status of statuses) { - status.type = (Object.keys(ActivityTypeAvailables).includes(status.type) || Object.values(ActivityTypeAvailables).includes(status.type)) ? (ActivityTypeAvailables[status.type] || status.type) : "PLAYING" - const option = { name: status.text, type: status.type } - if (status.url) { option.url = status.url } - this.statuses.set(this.statuses.size, { - status: status.status || "online", - time: isNaN(status.time || 12) ? 12 : status.time, - activity: option, - afk: status.afk || false, - shardID: status.shardIDs || 0 - }) - } - } - variables(d, table = this.db.tables[0]) { - for (const [name, value] of Object.entries(d)) { - this.variableManager.add({ name, value }) - } - if (this.db instanceof DbdTsDb) { - const data = this.variableManager.cache.allValues().map(x => x.object()) - console.log(data) - this.db.addColumns(table, data) - } - } - async _createCacheFactory(options) { - options.makeCache = await CacheManager._setDjsCacheManagers(options.cache) - } - -} -module.exports = BaseClient; diff --git a/package/functions/parser.js b/package/functions/parser.js deleted file mode 100644 index 7de85053a..000000000 --- a/package/functions/parser.js +++ /dev/null @@ -1,7 +0,0 @@ -const fs = require('fs'); -const maps = {}; -const functions = fs.readdirSync(__dirname+'/Funcs').map( x => fs.readdirSync(__dirname+`/Funcs/${x}`) ).map( x => x.join(',') ).join(',').split(',').map( x => '$'+x.split('.js')[0] ); - -require('fs').readdirSync(__dirname+'/Funcs').map(x => maps[x] = fs.readdirSync(__dirname+'/Funcs/' + x).map(y => y.split(".js")[0])); - -module.exports = {functions,maps } diff --git a/package/index.d.ts b/package/index.d.ts deleted file mode 100644 index c17358fcc..000000000 --- a/package/index.d.ts +++ /dev/null @@ -1,363 +0,0 @@ -import Group from "./CacheHandler/group"; -import LimitGroup from "./CacheHandler/limitGroup"; -import SuperSet from "./CacheHandler/superSet"; -import { Client, Collection, ShardingManager } from "discord.js"; - -declare module "aoi.js" { - - import { EventEmitter } from "events"; - - type ErrorMsg = string | Record - //AoiError - class AoiError { - constructor(); - static CallbackError(callback: string, intent: string, line?: number): void; - static CommandError(command: string, type: string, name: string, position?: number): void - static makeMessageError(client: Bot, channel: Channel, message: ErrorMsg, options?: Record): void - static consoleError(errorname: string, errorMsg: ErrorMsg): void - static functionErrorResolve(d: d, type: string, object: object, message: ErrorMsg): void - static fnError(d: d, type: string, object: object, message: ErrorMsg): void - } - - //Blacklist - type BlacklistTypes = "globalUser" | "server" | "channel" | "role" | "user"; - - class Blacklist { - constructor(client: Bot); - public setBlacklist(type: BlacklistTypes, errorMsg: ErrorMsg): void - public blacklistIds(type: BlacklistTypes, ids: string[]): void - public whitelistIds(type: BlacklistTypes, ids: string[]): void - public get types(): BlacklistTypes; - public getBlacklistTable(type: 'all' | "globalUser" | "server" | "channel" | "role" | "user"): string - } - - type IntentOptions = "all" | string[]; - - type DatabaseOption = { - type: "default" | "dbdjs.db" | "dbdts.db" | "dbdjs.mongo" | "dbdjs.db-sql" | "custom"; - db: Database; - path?: string; - tables?: Array; - extraOptions?: Record; - promisify?: boolean; - } - - type RespondOnEditOptions = { - commands?: boolean; - alwaysExecute?: boolean; - nonPrefixed?: boolean; - time?: number; - } - - type CacheOptions = Record - - type EventOptions = { - functionError?: boolean; - timeout?: boolean; - } - - type ClientOptions = { - token: string; - prefix: string | Array; - intents: IntentOptions; - database?: DatabaseOption; - respondOnEdit?: RespondOnEditOptions; - cache: CacheOptions; - mobilePlatform?: boolean; - fetchInvites?: { - enabled: boolean; - cacheInviters?: boolean; - }; - suppressAllErrors?: boolean; - errorMessage?: Array; - events?: EventOptions; - disableFunctions?: Array; - autoUpdate?: boolean; - } - - interface BaseCommand { - code: string; - } - interface EventCommand extends BaseCommand { - name?: string; - channel?: string; - [key: string]: any; - } - interface Command extends BaseCommand { - name: string; - aliases?: string | Array; - async?: boolean; - whitelist?: boolean; - nonPrefixed?: boolean; - error?: string; - } - interface AwaitCommand extends BaseCommand { - name: string; - } - interface InteractionCommand extends BaseCommand { - name: string | Array; - prototype: "application" | "button" | "selectMenu" - } - interface CustomEventCommand extends BaseCommand { - name: string - listen: string - } - - type StatusOption = { - text: string; - url?: string; - time: number; - shardId?: number; - type: "PLAYING" | "LISTENING" | " WATCHING" | "STREAMING" | "playing" | "listening" | "streaming" | "watching"; - } - - class BaseClient extends Client { - aoiOptions: Record; - interactionManager: InteractionManager; - cacheManager: CacheManager; - variableManager: any /*VariableManager*/; - blacklist: Blacklist; - _api: string; - prefix: string | string[]; - db: any /*DbdjsApi | DbdTsDb | CustomDb | Promisify*/; - statuses: Group; - constructor(options: ClientOptions); - public status(d: StatusOption[]): void; - public variables(data: object, table?: string): void; - } - class Bot extends BaseClient { - cmd: CommandManager; - functionManager: FunctionManager; - constructor(options: ClientOptions); - public command(d: Command): void; - public awaitedCommand(d: AwaitCommand): void - public deletedCommand(d: EventCommand): void - public updateCommand(d: EventCommand): void - public bulkDeleteCommand(d: EventCommand): void - public guildJoinCommand(d: EventCommand): void - public guildLeaveCommand(d: EventCommand): void - public guildUpdateCommand(d: EventCommand): void - public guildUnavailableCommand(d: EventCommand): void - public roleCreateCommand(d: EventCommand): void - public roleUpdateCommand(d: EventCommand): void - public roleDeleteCommand(d: EventCommand): void - public channelCreateCommand(d: EventCommand): void - public channelUpdateCommand(d: EventCommand): void - public channelDeleteCommand(d: EventCommand): void - public channelPinsUpdateCommand(d: EventCommand): void - public stageInstanceCreateCommand(d: EventCommand): void - public stageInstanceUpdateCommand(d: EventCommand): void - public stageInstanceDeleteCommand(d: EventCommand): void - public threadCreateCommand(d: EventCommand): void - public threadUpdateCommand(d: EventCommand): void - public threadDeleteCommand(d: EventCommand): void - public threadListSyncCommand(d: EventCommand): void - public threadMemberUpdateCommand(d: EventCommand): void - public joinCommand(d: EventCommand): void - public leaveCommand(d: EventCommand): void - public memberUpdateCommand(d: EventCommand): void - public threadMembersUpdateCommand(d: EventCommand): void - public memberAvailableCommand(d: EventCommand): void - public membersChunkCommand(d: EventCommand): void - public emojiCreateCommand(d: EventCommand): void - public emojiDeleteCommand(d: EventCommand): void - public emojiUpdateCommand(d: EventCommand): void - public banAddCommand(d: EventCommand): void - public banRemoveCommand(d: EventCommand): void - public inviteCreateCommand(d: EventCommand): void - public inviteDeleteCommand(d: EventCommand): void - public reactionAddCommand(d: EventCommand): void - public reactionRemoveCommand(d: EventCommand): void - public reactionRemoveAllCommand(d: EventCommand): void - public reactionRemoveEmojiCommand(d: EventCommand): void - public presenceUpdateCommand(d: EventCommand): void - public voiceStateUpdateCommand(d: EventCommand): void - public interactionCommand(d: InteractionCommand): void - public applicationCmdCreateCommand(d: EventCommand): void - public applicationCmdDeleteCommand(d: EventCommand): void - public applicationCmdUpdateCommand(d: EventCommand): void - public userUpdateCommand(d: EventCommand): void - public variableCreateCommand(d: EventCommand): void - public variableDeleteCommand(d: EventCommand): void - public variableUpdateCommand(d: EventCommand): void - public readyCommand(d: EventCommand): void - public functionErrorCommand(d: EventCommand): void - public onMessage(d?: { - guildOnly?: boolean, - respondToBot?: boolean - }): void - public onMessageDelete(): void - public onMessageUpdate(): void - public onMessageDeleteBulk(): void - public onGuildJoin(): void - public onGuildLeave(): void - public onGuildUpdate(): void - public onGuildUnavailable(): void - public onRoleCreate(): void - public onRoleUpdate(): void - public onRoleDelete(): void - public onChannelCreate(): void - public onChannelUpdate(): void - public onChannelDelete(): void - public onChannelPinsUpdate(): void - public onStageInstanceCreate(): void - public onStageInstanceUpdate(): void - public onStageInstanceDelete(): void - public onThreadCreate(): void - public onThreadUpdate(): void - public onThreadDelete(): void - public onThreadListSync(): void - public onThreadMemberUpdate(): void - public onThreadMembersUpdate(): void - public onJoin(): void - public onLeave(): void - public onMemberUpdate(): void - public onMemberAvailable(): void - public onMembersChunk(): void - public onEmojiCreate(): void - public onEmojiDelete(): void - public onEmojiUpdate(): void - public onStickerCreate(): void - public onStickerDelete(): void - public onStickerUpdate(): void - public onBanAdd(): void - public onBanRemove(): void - public onInviteCreate(): void - public onInviteDelete(): void - public onReactionAdd(): void - public onReactionRemove(): void - public onReactionRemoveAll(): void - public onReactionRemoveEmoji(): void - public onVoiceStateUpdate(): void - public onPresenceUpdate(): void - public onTypingStart(): void - public onInteractionCreate(): void - public onApplicationCmdCreate(): void - public onApplicationCmdDelete(): void - public onApplicationCmdUpdate(): void - public onUserUpdate(): void - public onVariableCreate(): void - public onVariableDelete(): void - public onVariableUpdate(): void - - } - //cacheManager - type CacheTypes = 'cache' | 'limitCache' | 'setCache'; - - class CacheManager { - constructor(client: Bot); - public get types(): CacheTypes; - public _validType(type: string): boolean; - public createCache(type: 'cache', name: string): Group; - public createCache(type: 'limitCache', name: string): LimitGroup; - public createCache(type: 'setCache', name: string): SuperSet; - public deleteCache(type: 'cache', name: string): Group; - public deleteCache(type: 'limitCache', name: string): LimitGroup; - public deleteCache(type: 'setCache', name: string): SuperSet; - public static _DjsCacheManager(cache: CacheOptions): any; - } - //ClientShard - class ClientShard extends ShardingManager { - file: string; - client: Bot; - constructor(file: string, options: object, client: Bot); - public onShardDisconnect(): void; - public onShardError(): void; - public onShardResume(): void; - public onShardReconnecting(): void; - public onShardReady(): void; - - } - //CommandManager - class Command { - [key: string]: any; - __client__: Bot; - constructor(d: object, client: Bot); - public serializeFunctions(): string[]; - public serializeCode(): void | string[]; - public toString(): string; - public toArray(): [string, any][]; - public keys(): string[]; - public values(): unknown[] - - } - class CommandManager { - client: Bot; - customCmds?: Array; - constructor(client: Bot, formCommand?: boolean, customCmds?: string[]); - public get types(): string[]; - public createCommand(d: any): void; - public formCommand(): void; - public formCustomCommand(customCmds: string[]): void; - } - //FunctionManager - class FunctionManager { - client: Bot; - maps: Record; - functions: string[]; - cache: Group; - interpreter: unknown; - constructor(client: Bot); - public cacheFunctions(): void; - public createCustomFunction(data: Array>): void; - public findFunctions(code: string): string[]; - public serializeCode(code: string): string[]; - } - //LoadCommands - class LoadCommands { - Client: Bot; - AddToClient?: boolean; - constructor(Client: Bot, AddToClient?: boolean); - - public load(cmd: CommandManager, path: string, debug?: boolean): void; - public update(debug?: boolean): void; - public setColors(colors: object): void; - public get allColors(): object; - public get themes(): object; - } - class CustomEvent extends EventEmitter { - client: Bot; - commands: Group; - constructor(client: Bot); - command(d: CustomEventCommand): void; - listen(event: string): void; - } - - type ApplcationOptionData = { - type: 'SUB_COMMAND' | 'SUB_COMMAND_GROUP' | 'STRING' | "INTEGER" | 'BOOLEAN' | 'USER' | 'CHANNEL' | 'ROLE' | 'MENTIONABLE' | 'NUMBER' | number; - } - type ApplicationData = { - data: { - name: string; - description: void | string; - options?: object[]; - type?: 'CHAT_INPUT' | "USER" | "MESSAGE"; - defaultPermission?: boolean; - }, - guildId?: string; - } - - - class Interaction extends EventEmitter { - client: Bot; - constructor(client: Bot); - public resolve(interaction: Interaction): Interaction; - } - class InteractionManager extends Interaction { - client: Bot; - awaitComponents: unknown /*Await*/; - componentCollector: unknown /*CustomCollector*/; - buttonData: Group; - applicationData: Group; - selectMenuData: Group; - constructor(client: Bot); - public createApplicationData(d: ApplicationData): void - public createButtonData(d: object): void - public createSelectMenuData(d: object): void - public stringifyApplicationData(name: string): string; - public resolveButtonData(name: string): string - public resolveSelectMenuData(name: string): string - public resolveSelectMenuOptionData(options: object[]): string - public get buttonDataLength(): number - } -} \ No newline at end of file diff --git a/package/index.js b/package/index.js deleted file mode 100644 index 60a447416..000000000 --- a/package/index.js +++ /dev/null @@ -1,37 +0,0 @@ -const Client = require("./classes/Bot.js"); -const CustomEvent = require('./classes/NewEvent.js') -const LoadCommands = require('./classes/LoadCommands.js') -const ClientShard = require('./classes/ClientShard.js') -const Voice = require('./classes/Voice.js') -const Lavalink = require('./classes/Lavalink.js') -const AoiError = require('./classes/AoiError.js') -const Util = require('./classes/Util.js') -module.exports = { - /** - * The Discord Bot Client - * @param {!Object} options The options to use Discord as a Bot - * @example - * - * new Bot({token:"Discord Bot Token", prefix:"!"}) - */ - //Bot: Client, - Bot: Client, - /** - * custom Events Class - * @example new CustomEvent(client (eg: bot)) - **/ - CustomEvent: CustomEvent, - /** - * loadCommands - * loads the commands of the provided file - @example new LoadCommands(path,true/false) - **/ - LoadCommands: LoadCommands, - ClientShard: ClientShard, - Voice: Voice, - Lavalink: Lavalink, - AoiError: AoiError, - Util -}; - -//Aoi.Js client diff --git a/package/interpreter.js b/package/interpreter.js deleted file mode 100644 index 3e35dc39f..000000000 --- a/package/interpreter.js +++ /dev/null @@ -1,296 +0,0 @@ -const IF = require('./Utils/helpers/if.js') -const Discord = require('discord.js'); -const { Function, CustomFunction } = require('./classes/Functions.js') -const AoiError = require('./classes/AoiError.js') -const Util = require('./classes/Util.js') -const Interpreter = async (client, message, args, command, db, returnCode = false, channelUsed, data = {}, useChannel, returnMessage, returnExecution, returnID, sendMessage = false) => { - try { - - //defining vars// - let code = command.code?.replaceAll("\\]", "#LEFT#").split("\\[").join("#RIGHT#").replaceAll("\\,", "#COMMA#").replaceAll("\\;", "#SEMI#") - // const oldcode = code - let [randoms, timezone, letVars, object, disableMentions, array, reactions, channel, author, guild, mentions, member, msg] = [data.randoms || {}, "UTC", data.vars || {}, data.object || {}, ["roles", "users", "everyone"], data.array || [], [], message.channel, message.author, message.guild, message.mentions, message.member, message]; - let anErrorOccuredPlsWait; - let embeds; - let deleteIn; - let suppressErrors; - let editIn; - let error; - let attachments = [] - let components = [] - let reply; - let allowedMentions = {} - let FuncData; - let msgobj; - let funcLine; - let returnData = {} - command.codeLines = command.codeLines || client.functionManager.serializeCode(command.code); - const funcs = command.functions?.length ? command.functions : client.functionManager.findFunctions(command.code) - //debug system - const debug = { - code, - functions: command.functions, - } - //console.log(error) - - const start = Date.now() - if (client?.aoiOptions?.debugs?.interpreter) { - console.log(`|------------------------------------------|`) - console.time(`interpreter-${start}`) - } - //parsing functions (dont touch) - for (let i = funcs.length; i > 0; i--) { - if (!funcs.length) break; - - if ((i > funcs.length) && (funcs.length !== 0)) i = funcs.length - - let func = funcs[i - 1] - - if (error) break; - const regex = new RegExp("\\" + func.replace("[", "\\["), "gi") - - code = code.replace(regex, func) - //more debug - debug[func] = { regex, func } - - funcLine = command.codeLines.length - (command.codeLines?.reverse().findIndex(x => x.toLowerCase().split(' ').includes(func.toLowerCase()))); - - const functionObj = client.functionManager.cache.get(func.replace("$", "").replace("[", "")) - if (functionObj instanceof CustomFunction && functionObj.type === "aoi.js") { - const d = {} - Object.assign(d, functionObj) - - for (let p = functionObj.params.length - 1; p >= 0; p--) { - d.code = d.code.replace(`{${functionObj.params[p]}}`, unpack(code, func).splits[p]) - } - FuncData = await client.functionManager.interpreter(client, message, args, d, client.db, true) - - - } - else { - FuncData = await client.functionManager.cache.get(func.replace("$", "").replace("[", ""))?.code({ - randoms: randoms, - command: { - name: command.name, - code: code, - error: command.error, - async: command.async || false, - functions: command.functions, - codeLines: command.codeLines - }, - args: args, - aoiError: require('./classes/AoiError.js'), - data: data, - func: func, - funcLine, - util: Util, - allowedMentions: allowedMentions, - embeds: embeds || [], - components: components, - files: attachments || [], - timezone: timezone, - channelUsed: channelUsed, - vars: letVars, - object: object, - disableMentions: disableMentions, - array: array, - reactions: reactions, - message: message.message || message, - msg: msg.message || msg, - author: author, - guild: guild, - channel: channel, - member: member, - mentions: mentions, - unpack() { - const last = code.split(func.replace("[", "")).length - 1; - const sliced = code.split(func.replace("[", ""))[last]; - - return sliced.after(); - }, - inside(unpacked) { - if (typeof unpacked.inside !== "string") { - if (suppressErrors) return suppressErrors - else { - const e = client.options.suppressAllErrors ? client.options.errorMessage : ` \`${func}: Invalid Usage\` (line : ${funcLine})` - return e - } - } - else return false - }, - noop() { }, - async error(err) { - client.emit("functionError", { error: err?.addBrackets(), function: func, command: command.name, channel, guild }, client) - if (client.options.suppressAllErrors) { - if (client.options.errorMessage) { - const { ErrorHandler, EmbedParser, FileParser, ComponentParser } = require('./Handler/parsers.js') - - if (!message || !message.channel) { - console.error(client.options.errorMessage.addBrackets()) - } - else { - let [con, em, com, fil] = [" ", "", "", ""] - let isArray = Array.isArray(client.options.errorMessage) - if (isArray) { - isArray = client.options.errorMessage - con = (isArray[0] === "" || !isArray[0]) ? " " : isArray[0] - em = isArray[1] !== "" && isArray[1] ? await EmbedParser(isArray[1] || "") : [] - fil = isArray[3] !== "" && isArray[3] ? await FileParser(isArray[3] || "") : [] - com = isArray[2] !== "" && isArray[2] ? await ComponentParser(isArray[2] || "") : [] - } - else { - con = client.options.errorMessage.addBrackets() === "" ? " " : client.options.errorMessage.addBrackets() - - } - - if (!anErrorOccuredPlsWait) { message.channel?.send({ content: con, embeds: em || [], components: com || [], files: fil || [] }) } - anErrorOccuredPlsWait = true - } - } - else return; - } - else { - anErrorOccuredPlsWait = true - if (!message || !message.channel) { - console.error(err.addBrackets()) - } - if (suppressErrors) { - ErrorHandler({ channel: channel, message: message, guild: guild, author: author }, suppressErrors?.split("{error}").join(err.addBrackets())) - } - else { - - - message.channel?.send(typeof err === "object" ? err : err?.addBrackets()) - } - } - }, - interpreter: Interpreter, - client: client, - embed: Discord.MessageEmbed - }) - - } - - if (client?.aoiOptions?.debugs?.interpreter) { - debug[func].funcData = require('util').inspect(FuncData, { depth: 0 }) - - } - // console.log("i:"+(i-1) ) - // console.log("code:"+code) - code = FuncData?.code ?? code - - if (FuncData?.randoms) { randoms = FuncData.randoms } - if (FuncData?.data) { - data = FuncData.data - array = FuncData.data?.array ?? array - object = FuncData?.data?.object ?? object - letVars = FuncData?.data?.vars ?? letVars - } - if (FuncData?.timezone) { timezone = FuncData.timezone } - if (FuncData?.allowedMentions) { allowedMentions = FuncData.allowedMentions } - if (FuncData?.embeds) { embeds = FuncData.embeds } - if (FuncData?.reactions) { reactions = FuncData.reactions } - if (FuncData?.disableMentions) { disableMentions = FuncData.disableMentions } - if (FuncData?.editIn) { editIn = FuncData.editIn } - if (FuncData?.files) { attachments = FuncData.files } - if (FuncData?.suppressErrors) { suppressErrors = FuncData?.suppressErrors } - if (FuncData?.components) { components = FuncData.components } - if (FuncData?.reply) { reply = FuncData.reply } - if (FuncData?.useChannel) { useChannel = FuncData.useChannel } - if (FuncData?.returnID) { returnID = FuncData?.returnID } - if (FuncData?.error) { error = FuncData?.error } - - } - if (client?.aoiOptions?.debugs?.interpreter) { - debug.executionTime = (Date.now() - start) + " ms" - console.timeEnd(`interpreter-${start}`) - } - // console.log(code) - embeds = JSON.parse(JSON.stringify(embeds || [])?.replaceAll("$executionTime", Date.now() - start)) - - debug.executionTime = (Date.now() - start) + " ms" - code = code?.replace(/\$executiontime/gi, (debug.executionTime.split("ms")[0])) - - code = code.trim() - if (embeds?.some(x => x === undefined)) { - return AoiError.consoleError("EmbedError", "Some Indexes Are Empty") - error = true - } - if (returnCode) { returnData.code = code } - if (returnExecution) { returnData.data = data } - if ((code.length || embeds?.length) && !anErrorOccuredPlsWait && !error) { - try { - // console.log(components) - const send = { - embeds: embeds, - files: attachments, - components: components, - allowedMentions: { parse: disableMentions, repliedUser: reply?.user || false }, - referenceMessage: reply?.message || {} - } - if (code.trim() !== "") { send.content = (code.addBrackets() === "" ? " " : code.addBrackets()) } - if (returnCode && !sendMessage) { } - else { - if (!useChannel) { - msgobj = await message.channel?.send( - send - ) - } - else { - msgobj = await useChannel?.send(send) - } - } - if (client?.aoiOptions?.debugs?.interpreter) { - - - - console.log(debug) - - - console.log(`|------------------------------------------|`) - } - if (reactions?.length) { - const react = setInterval(() => { - const r = reactions.shift() - msgobj.react(r) - if (!reactions.length) { clearInterval(react) } - }, 1500) - } - if (editIn) { - const ee = setInterval(() => { - const m = editIn.msgs - msgobj.edit(m.shift()) - if (!m.length) { ClearInterval(ee) } - }, editIn.time) - } - if (deleteIn) { - setTimeout(() => msgobj.delete(), deleteIn) - } - - if (returnID) { returnData.id = msgobj?.id } - if (returnMessage) { returnData.message = msgobj } - - - - } - catch (e) { - console.error(e) - } - } - return Object.keys(returnData).length ? returnData : undefined - } - - catch (e) { - console.error(e) - } -} -module.exports = Interpreter -function unpack(code, func) { - - const last = code.split(func.replace("[", "")).length - 1; - - const sliced = code.split(func.replace("[", ""))[last]; - - return sliced.after(); - -}; \ No newline at end of file diff --git a/src/classes/AoiBase.js b/src/classes/AoiBase.js new file mode 100644 index 000000000..f017f0a9c --- /dev/null +++ b/src/classes/AoiBase.js @@ -0,0 +1,200 @@ +const Discord = require("discord.js"); +const { VariableManager } = require("./Variables.js"); +const InteractionManager = require("./Interaction.js"); +const LoadCommands = require("./LoadCommands.js"); +const { + ActivityTypeAvailables, + IntentOptions, + EventsToIntents, + EventsToDjsEvents, + EventstoFile, +} = require("../utils/Constants.js"); +const Database = require("./Database.js"); +const CacheManager = require("./CacheManager.js"); +const { CommandManager } = require("./Commands.js"); +const { Group } = require("@akarui/structures"); +const AoiError = require("./AoiError.js"); +const { functions: parser } = require("../core/AoiReader.js"); + +class BaseClient extends Discord.Client { + constructor(options) { + if (options.cache) { + options.makeCache = CacheManager._setDjsCacheManagers(options.cache); + } + + options.partials = options.partials || [ + Discord.Partials.GuildMember, + Discord.Partials.Channel, + Discord.Partials.Message, + Discord.Partials.Reaction, + Discord.Partials.User, + Discord.Partials.GuildScheduledEvent, + Discord.Partials.ThreadMember, + ]; + + const aoiOptions = {}; + Object.assign(aoiOptions, options); + if (!options.intents) { + throw new TypeError("Client intents must be provided."); + } + options.intents = options.intents.map((x) => IntentOptions[x] || x); + super(options); + this.aoiOptions = aoiOptions; + + this.cmd = new CommandManager(this); + + this.interactionManager = new InteractionManager(this); + + this.cacheManager = new CacheManager(this); + + this.variableManager = new VariableManager(this); + + if ( + options.disableAoiDB !== true && + (["default", "aoi.db"].includes(options?.database?.type) || + !options?.database) + ) { + const dbData = options?.database; + + this.db = new Database( + dbData?.type + ? dbData?.type === "default" + ? "aoi.db" + : dbData?.type + : "aoi.db", + dbData?.db ?? require("@akarui/aoi.db"), + dbData?.dbType ?? "KeyValue", + { + dataConfig: { + path: dbData?.path ?? "./database", + tables: dbData?.tables?.length + ? [...dbData?.tables, "__aoijs_vars__"] + : ["main", "__aoijs_vars__"], + }, + encryptionConfig: { + securityKey: dbData?.securityKey ?? "a-32-characters-long-string-here", + encriptData: dbData?.encriptData ?? false, + }, + ...dbData?.extraOptions, + } + ); + } + + if ( + Array.isArray(options?.disableFunctions) && + options?.disableFunctions.length + ) { + options?.disableFunctions.forEach((func) => { + const index = parser.findIndex((f) => f === func); + if (index !== -1) { + parser.splice(index, 1); + } + }); + } + + this.prefix = options.prefix; + this.#bindEvents(); + + Object.defineProperty(this, "statuses", { value: new Group() }); + + this.on("ready", async () => { + await require("../handler/NonIntents/ready.js")(this); + await require("../handler/status.js")(this.statuses, this); + await require("../handler/AoiStart.js")(this); + }); + this.login(options.token); + } + + loadCommands(directory, debug = true) { + const loader = new LoadCommands(this); + loader.load(this.cmd, directory, debug); + } + + status(...statuses) { + for (const status of statuses) { + status.type = + Object.keys(ActivityTypeAvailables).includes( + status.type.toLowerCase() + ) || Object.values(ActivityTypeAvailables).includes(status.type) + ? ActivityTypeAvailables[status.type.toLowerCase()] + : ActivityTypeAvailables.playing; + + const option = { + name: status.name, + type: status.type, + url: status.url, + }; + + this.statuses.set(this.statuses.size, { + status: status.status || "online", + time: isNaN(status.time) ? 12 : status.time, + activity: option, + afk: status.afk || false, + shardID: status.shardId || 0, + }); + } + } + + /** + * Adds variables to the variable manager. + * @param {Object} d - The object containing the variables to be added. + * @param {Object} [table=this.db?.tables?.[0]] - The table to which the variables belong. + * @throws {TypeError} If a database is not provided. + */ + variables(d, table = this.db?.tables?.[0]) { + if (this.db === undefined) { + throw new TypeError( + "A database must be provided to use the variables method." + ); + } + + for (const [name, value] of Object.entries(d)) { + this.variableManager.add({ name, value, table }); + } + } + + async _createCacheFactory(options) { + options.makeCache = await CacheManager._setDjsCacheManagers(options.cache); + } + + #bindEvents() { + const bits = new Discord.IntentsBitField(this.options.intents); + for (const event of this.aoiOptions.events ?? []) { + let intent = EventsToIntents[event]; + const filedir = intent; + const eventName = EventsToDjsEvents[event]; + const file = EventstoFile[event]; + if (intent === "GuildEmojis") intent = "GuildEmojisAndStickers"; + if (intent === "GuildMessageTypings") intent = "GuildMessageTyping"; + if ( + intent && + !["Custom", "NonIntents"].includes(intent) && + !bits.has(intent[0].toUpperCase() + intent.slice(1)) + ) { + return AoiError.EventError(event, intent, 357); + } + + try { + const func = [ + "shardDisconnect", + "shardError", + "shardReconnecting", + "shardResume", + ].includes(event) + ? require(`../shardhandler/${event}.js`) + : Array.isArray(file) + ? file.map((x) => require(`../handler/${filedir}/${x}.js`)) + : require(`../handler/${filedir}/${file}.js`); + + this.on(eventName, (...args) => { + if (Array.isArray(func)) func.forEach((x) => x(...args, this)); + else func(...args, this); + }); + } catch (error) { + throw new TypeError(`Error loading "${event}" event, does not exist!`); + } + } + } +} + +module.exports = BaseClient; diff --git a/src/classes/AoiClient.js b/src/classes/AoiClient.js new file mode 100644 index 000000000..c6bd6e812 --- /dev/null +++ b/src/classes/AoiClient.js @@ -0,0 +1,297 @@ +const BaseClient = require("./AoiBase"); +const {Command} = require("./Commands"); +const {FunctionManager} = require("./Functions"); + +const [major] = process.version.replace("v", "").split("."); +if (isNaN(Number(major)) || Number(major) < 16) { + throw new Error("node.js version must be v16.11.0 or above."); +} + +// Initialize aoi.js Client +class Client extends BaseClient { + constructor(options) { + super(options); + this.functionManager = new FunctionManager(this); + if (this.aoiOptions.respondOnEdit) { + this.aoiOptions.respondOnEdit.time = + this.aoiOptions.respondOnEdit.time ?? 60000; + } + } + + // Commands + command(...args) { + for (const d of args) { + if (!d.name) + throw new TypeError(`Command ${this.cmd.default.size} needs a name!`); + if (!d.code) + throw new TypeError(`Command ${this.cmd.default.size} needs a code!`); + + this.cmd.default.set(this.cmd.default.size, new Command(d, this)); + } + } + + interactionCommand(d = {}) { + if (!d.prototype) { + throw new TypeError(`Prototype is not provided in ${d.name || "unknown name"}: interactionCommand.`,); + } + if (!d.code) { + throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: interactionCommand. position: ${this.cmd.interaction[d.prototype]?.size}`,); + } + this.cmd.interaction[d.prototype]?.set(this.cmd.interaction[d.prototype].size, d); + } + + addCommandType(type, d = {}) { + if (!d.code) { + throw new TypeError(`Code is not provided in ${d?.name || "unknown name"}: ${type}. position: ${this.cmd[type].size}`); + } + + this.cmd[type].set(this.cmd[type].size, new Command(d, this)); + } + + awaitedCommand(d = {}) { + this.addCommandType("awaited", d); + } + + deletedCommand(d = {}) { + this.addCommandType("messageDelete", d); + } + + updateCommand(d = {}) { + this.addCommandType("messageUpdate", d); + } + + bulkDeleteCommand(d = {}) { + this.addCommandType("messageDeleteBulk", d); + } + + guildJoinCommand(d = {}) { + this.addCommandType("guildJoin", d); + } + + guildLeaveCommand(d = {}) { + this.addCommandType("guildLeave", d); + } + + guildUpdateCommand(d = {}) { + this.addCommandType("guildUpdate", d); + } + + guildUnavailableCommand(d = {}) { + this.addCommandType("guildUnavailable", d); + } + + roleCreateCommand(d = {}) { + this.addCommandType("roleCreate", d); + } + + roleUpdateCommand(d = {}) { + this.addCommandType("roleUpdate", d); + } + + roleDeleteCommand(d = {}) { + this.addCommandType("roleDelete", d); + } + + channelCreateCommand(d = {}) { + this.addCommandType("channelCreate", d); + } + + channelUpdateCommand(d = {}) { + this.addCommandType("channelUpdate", d); + } + + channelDeleteCommand(d = {}) { + this.addCommandType("channelDelete", d); + } + + channelPinsUpdateCommand(d = {}) { + this.addCommandType("channelPinsUpdate", d); + } + + stageInstanceCreateCommand(d = {}) { + this.addCommandType("stageInstanceCreate", d); + } + + stageInstanceUpdateCommand(d = {}) { + this.addCommandType("stageInstanceUpdate", d); + } + + stageInstanceDeleteCommand(d = {}) { + this.addCommandType("stageInstanceDelete", d); + } + + threadCreateCommand(d = {}) { + this.addCommandType("threadCreate", d); + } + + threadUpdateCommand(d = {}) { + this.addCommandType("threadUpdate", d); + } + + threadDeleteCommand(d = {}) { + this.addCommandType("threadDelete", d); + } + + threadListSyncCommand(d = {}) { + this.addCommandType("threadListSync", d); + } + + threadMemberUpdateCommand(d = {}) { + this.addCommandType("threadMemberUpdate", d); + } + + joinCommand(d = {}) { + this.addCommandType("join", d); + } + + leaveCommand(d = {}) { + this.addCommandType("leave", d); + } + + memberUpdateCommand(d = {}) { + this.addCommandType("memberUpdate", d); + } + + threadMembersUpdateCommand(d = {}) { + this.addCommandType("threadMembersUpdate", d); + } + + memberAvailableCommand(d = {}) { + this.addCommandType("memberAvailable", d); + } + + membersChunkCommand(d = {}) { + this.addCommandType("membersChunk", d); + } + + emojiCreateCommand(d = {}) { + this.addCommandType("emojiCreate", d); + } + + emojiDeleteCommand(d = {}) { + this.addCommandType("emojiDelete", d); + } + + emojiUpdateCommand(d = {}) { + this.addCommandType("emojiUpdate", d); + } + + banAddCommand(d = {}) { + this.addCommandType("banAdd", d); + } + + banRemoveCommand(d = {}) { + this.addCommandType("banRemove", d); + } + + reactionAddCommand(d = {}) { + this.addCommandType("reactionAdd", d); + } + + reactionRemoveCommand(d = {}) { + this.addCommandType("reactionRemove", d); + } + + reactionRemoveAllCommand(d = {}) { + this.addCommandType("reactionRemoveAll", d); + } + + reactionRemoveEmojiCommand(d = {}) { + this.addCommandType("reactionRemoveEmoji", d); + } + + presenceUpdateCommand(d = {}) { + this.addCommandType("presenceUpdate", d); + } + + voiceStateUpdateCommand(d = {}) { + this.addCommandType("voiceStateUpdate", d); + } + + applicationCmdCreateCommand(d = {}) { + this.addCommandType("applicationCmdCreate", d); + } + + applicationCmdDeleteCommand(d = {}) { + this.addCommandType("applicationCmdDelete", d); + } + + applicationCmdUpdateCommand(d = {}) { + this.addCommandType("applicationCmdUpdate", d); + } + + applicationCmdPermissionsUpdateCommand(d = {}) { + this.addCommandType("applicationCmdPermissionsUpdate", d); + } + + userUpdateCommand(d = {}) { + this.addCommandType("userUpdate", d); + } + + variableCreateCommand(d = {}) { + this.addCommandType("variableCreate", d); + } + + variableDeleteCommand(d = {}) { + this.addCommandType("variableDelete", d); + } + + variableUpdateCommand(d = {}) { + this.addCommandType("variableUpdate", d); + } + + readyCommand(d = {}) { + this.addCommandType("ready", d); + } + + functionErrorCommand(d = {}) { + this.addCommandType("functionError", d); + } + + loopCommand(d = {}) { + this.addCommandType("loop", d); + } + + timeoutCommand(d = {}) { + this.addCommandType("timeout", d); + } + + pulseCommand(d = {}) { + this.addCommandType("pulse", d); + } + + rateLimitCommand(d = {}) { + this.addCommandType("rateLimit", d); + } + + webhooksUpdateCommand(d = {}) { + this.addCommandType("webhooksUpdate", d); + } + + autoModActionExecutionCommand(d = {}) { + this.addCommandType("autoModActionExecution", d); + } + + autoModCreateCommand(d = {}) { + this.addCommandType("autoModCreate", d); + } + + autoModDeleteCommand(d = {}) { + this.addCommandType("autoModDelete", d); + } + + autoModUpdateCommand(d = {}) { + this.addCommandType("autoModUpdate", d); + } + + inviteCreateCommand(d = {}) { + this.addCommandType("inviteCreate", d); + } + + inviteDeleteCommand(d = {}) { + this.addCommandType("inviteDelete", d); + } +} + +require("../utils/helpers/prototypes.js"); +module.exports = Client; \ No newline at end of file diff --git a/src/classes/AoiError.js b/src/classes/AoiError.js new file mode 100644 index 000000000..ce8c49004 --- /dev/null +++ b/src/classes/AoiError.js @@ -0,0 +1,273 @@ +const Util = require("./Util.js"); +const chalk = require("chalk"); +const { ComponentParser, EmbedParser, FileParser } = Util.parsers; +const { Time } = require("../utils/helpers/customParser.js"); +const { BaseInteraction } = require("discord.js"); + +class AoiError { + constructor() { + const error = new Error(`Cannot initialize "AoiError" Class`); + error.name = "AoiError"; + throw error; + } + + /** + * @param {string} event + * @param {string} intent + * @param {number} line + * @returns {Error} + */ + static EventError(event, intent, line) { + const error = new Error( + `(Missing Intents) : "${event}" requires "${intent}" intent.` + ); + error.name = "EventError"; + error.fileName = "./AoiClient.js"; + error.lineNumber = line; + throw error; + } + + /** + * @param {string} command + * @param {string} type + * @param {string} name + * @param {number} position + * @returns {Error} + */ + static CommandError(command, type, name, position) { + if (type === "name") { + const error = new Error( + `AoiError: "Name" property is missing in "${command}" (position: ${position})` + ); + error.name = "CommandNameError"; + throw error; + } else if (type === "code") { + const error = new Error( + `AoiError: "Code" is not provided in "${ + name || "the Command" + }" : ${command} (position: ${position})` + ); + error.name = "CommandCodeError"; + throw error; + } else if (type === "channel") { + const error = new Error( + `AoiError: "Channel" is not provided in "${ + name || "the Command" + }" : ${command} (position: ${position})` + ); + error.name = "CommandChannelError"; + throw error; + } + } + + /** + * @param {import('./AoiClient.js')} client + * @param {import('discord.js').TextChannel | + * import('discord.js').ThreadChannel | + * import('discord.js').NewsChannel | + * import('discord.js').User | + * import('discord.js').Webhook | import('discord.js').Interaction } channel + * @param {object} options={} + * @param {object} extraOptions={} + * @param {object} d + * @returns {Promise} + */ + static async makeMessageError( + client, + channel, + options = {}, + extraOptions = {}, + d + ) { + options = options.data ?? options; + console.log(options) + if (typeof options === "object") { + options.content = options.content?.toString()?.trim() || " "; + if (options.embeds && typeof options.embeds === "string") { + options.embeds = await EmbedParser(options.embeds, d); + } + if (options.files && typeof options.files === "string") { + options.files = FileParser(options.files, d); + } + if (options.components && typeof options.components === "string") { + options.components = await ComponentParser(options.components, d); + } + } else { + options = { + content: options?.toString()?.trim() === "" ? " " : options?.toString(), + }; + } + let msg; + if (extraOptions.interaction) { + if ( + options.content === "" && + options.embeds?.length === 0 && + options.files?.length === 0 + ) + return; + msg = await d.data.interaction.reply(options); + } else { + if (channel instanceof BaseInteraction) { + if ( + options.content === "" && + options.embeds?.length === 0 && + options.files?.length === 0 + ) + return; + msg = await channel.reply(options).catch((e) => { + AoiError.consoleError("CreateMessageError", e); + return undefined; + }); + } else { + if ( + options.content === " " && + (options.embeds?.length ?? 0) === 0 && + (options.files?.length ?? 0) === 0 && + (options.stickers?.length ?? 0) === 0 + ) + return; + msg = await channel.send(options).catch((e) => { + AoiError.consoleError("CreateMessageError", e); + return undefined; + }); + } + } + + if (extraOptions.reactions?.length) { + extraOptions.reactions.forEach((x) => msg.react(x)); + } + if (extraOptions.edits) { + const editIn = setInterval(async () => { + if (!extraOptions.edits.messages?.length) clearInterval(editIn); + else { + const obj = extraOptions.edits.messages.shift(); + + msg.edit(obj); + } + }, Time.parse(extraOptions.edits.time)?.ms); + } + if (extraOptions.deleteIn) { + extraOptions.deleteIn = Time.parse(extraOptions.deleteIn.split("}")[0])?.ms; + setTimeout(() => msg.delete(), extraOptions.deleteIn); + } + if (extraOptions.deleteCommand) { + d.message.delete(); + } + return msg; + } + + /** + * @param {string} name + * @param err + * @returns {void} + */ + static consoleError(name, err) { + return console.error(`${name}: ${err}`); + } + + /** + * @param {object} d + * @param {"member" | "message" | "channel" | "user" | "role" | 'guild' | "emoji" | "option" | "custom" } type + * @param {object} data + * @param {string | void} message + * @returns {string} + */ + static functionErrorResolve(d, type, data, message) { + let errorData = { + Function: `\`${d.func}\``, + Command: `\`${d.command.name}\``, + Version: require("../../package.json").version, + }; + + switch (type) { + case "member": + errorData.type = "Member ID"; + break; + case "message": + errorData.type = "Message ID"; + break; + case "channel": + errorData.type = "Channel ID"; + break; + case "user": + errorData.type = "User ID"; + break; + case "role": + errorData.type = "Role ID"; + break; + case "guild": + errorData.type = "Guild ID"; + break; + case "emoji": + errorData.type = "Emoji ID"; + break; + case "option": + errorData.type = "Option ID"; + break; + case "custom": + errorData.type = message; + break; + } + return `\`\`\`js\nAoiError: Invalid ${errorData.type} ${ + data.inside || "" + } \n { \n Function : ${errorData.Function},\n Command : ${ + errorData.Command + },\n Version : ${errorData.Version} \n }\`\`\``; + } + + /** + * @param {object} d - The data object. + * @param {"member" | "message" | "channel" | "user" | "role" | "guild" | "emoji" | "option" | "custom"} type - The type of error. + * @param {object} data - The additional error data. + * @param {string} [message] - An optional custom error message. + * @returns {void} + */ + static fnError(d, type, data, message) { + d.error(this.functionErrorResolve(d, type, data, message)); + } + + /** + * Creates a custom boxed message with optional title and border color. + * @param {Array<{text: string, textColor?: string}> | {text: string, textColor?: string}} messages - The messages to be displayed in the box. + * @param {string} [borderColor="yellow"] - The color of the box border. Default is "yellow". + * @param {{text: string, textColor?: string}} [title] - The title of the box. + * @returns {void} + */ + static createCustomBoxedMessage(messages, borderColor = "yellow", title) { + if (!Array.isArray(messages)) { + messages = [messages]; + } + + const maxLength = title + ? Math.max(...messages.map((msg) => msg.text.length), title.text.length) + : Math.max(...messages.map((msg) => msg.text.length)); + + const topBorder = chalk[borderColor](`╭${"─".repeat(maxLength + 2)}╮`); + const bottomBorder = chalk[borderColor](`╰${"─".repeat(maxLength + 2)}╯`); + + console.log(topBorder); + + if (title) { + const titlePadding = " ".repeat((maxLength - title.text.length) / 2); + const titleText = `${chalk[borderColor]("│")} ${titlePadding}${chalk[ + title.textColor + ](title.text)}${titlePadding} ${chalk[borderColor]("│")}`; + console.log(titleText); + } + + messages.forEach((message) => { + const paddingLength = (maxLength - message.text.length) / 2; + const leftPadding = " ".repeat(Math.floor(paddingLength)); + const rightPadding = " ".repeat(Math.ceil(paddingLength)); + const textColor = message.textColor || "reset"; + const messageText = `${chalk[borderColor]("│")} ${leftPadding}${chalk[ + textColor + ](message.text)}${rightPadding} ${chalk[borderColor]("│")}`; + console.log(messageText); + }); + + console.log(bottomBorder); + } +} + +module.exports = AoiError; diff --git a/src/classes/CacheManager.js b/src/classes/CacheManager.js new file mode 100644 index 000000000..adbe0a214 --- /dev/null +++ b/src/classes/CacheManager.js @@ -0,0 +1,53 @@ +const { CacheOptions } = require("../utils/Constants.js"); +const { Options } = require("discord.js"); +const Cachers = require("@akarui/structures"); +const AoiError = require("./AoiError.js"); + +class CacheManager { + constructor(client) { + client.cacheManager = this; + Object.defineProperty(this, "client", { value: client }); + this.caches = { + }; + this.cachers = Cachers; + } + + get types() { + return Object.keys(Cachers); + } + + _validType(type) { + return this.types.includes(type); + } + + createCache(type, name, options) { + if (!this._validType(type)) + return AoiError.consoleError( + "CacheManagerError", + "Wrong Cache Type Provided", + ); + if(!this.caches[type]) this.caches[type] = {}; + this.caches[type][name] = new Cachers[type](options); + return this.caches[type][name]; + } + + deleteCache(type, name) { + if (!this._validType(type)) + return AoiError.consoleError( + "CacheManagerError", + "Wrong Cache Type Provided", + ); + + delete this.caches[type][name]; + } + + static _setDjsCacheManagers(cache) { + let managers = {}; + for (const [key, value] of Object.entries(cache)) { + managers[CacheOptions[key]] = value; + } + const factory = Options.cacheWithLimits(managers); + return factory + } +} +module.exports = CacheManager; \ No newline at end of file diff --git a/src/classes/ClientShard.js b/src/classes/ClientShard.js new file mode 100644 index 000000000..a415f5448 --- /dev/null +++ b/src/classes/ClientShard.js @@ -0,0 +1,27 @@ +const { ShardingManager } = require("discord.js"); +const { Group : Collection } = require( "@akarui/structures" ); + +class ClientShard extends ShardingManager { + constructor(file, options = {}, spawnOptions) { + super(file, options); + this.file = file; + this.spawnOptions = spawnOptions; + this.cmd = { + shardCreate: new Collection(), + }; + } + + shardCreateCommand(d) { + this.cmd.shardCreate.set(this.cmd.shardCreate.size, d); + } + startProcess() { + this.spawn(this.spawnOptions); + } + + onShardCreate() { + this.on("shardCreate", async (shard) => + require("../shardhandler/shardCreate.js")(shard, this.cmd), + ); + } +} +module.exports = ClientShard; \ No newline at end of file diff --git a/src/classes/Commands.js b/src/classes/Commands.js new file mode 100644 index 000000000..0a5c3768c --- /dev/null +++ b/src/classes/Commands.js @@ -0,0 +1,122 @@ +const { Group } = require("@akarui/structures"); + +class Command { + constructor(data = {}, client) { + this.__client__ = client; + if (typeof data.code === "string") { + this.code = data.code; + } else { + throw new TypeError(`Missing or invalid 'code' property in '${data.name}' command`); + } + Object.entries(data).forEach(([key, value]) => (this[key] = value)); + this.functions = this.serializeFunctions(); + this.codeLines = this.serializeCode(); + } + + serializeFunctions() { + const availableFunctions = this.__client__.functionManager.functions; + let code = this.code.replace(/\\]/g, "#LEFT#").split("\\[").join("#RIGHT#").replace("\\,", "#COMMA#"); + const usedFunctions = []; + + const functionTokens = code.split("$"); + for (const functionToken of functionTokens) { + const matchingFunctions = availableFunctions.filter(func => + func.toLowerCase() === ("$" + functionToken.toLowerCase()).slice(0, func.length) + ); + + if (matchingFunctions.length) { + if (matchingFunctions.length === 1) { + usedFunctions.push(matchingFunctions[0]); + } else if (matchingFunctions.length > 1) { + usedFunctions.push(matchingFunctions.sort((a, b) => b.length - a.length)[0]); + } + } + } + + return usedFunctions; + } + + serializeCode() { + return this.code?.split("\n"); + } + + toString() { + return JSON.stringify(this); + } + + toArray() { + return Object.entries(this); + } + + values() { + return Object.values(this); + } + + keys() { + return Object.keys(this); + } +} + +class CommandManager { + constructor(client, formCommand = true, customCmds = []) { + client.cmd = this; + this.client = client; + this.isClientCommand = formCommand; + this.types = [ + "default", "awaited", "messageDelete", "messageUpdate", "messageDeleteBulk", "guildJoin", + "guildUpdate", "guildLeave", "guildUnavailable", "roleCreate", "roleUpdate", "roleDelete", + "channelCreate", "channelUpdate", "channelDelete", "channelPinsUpdate", "stageInstanceCreate", + "stageInstanceUpdate", "stageInstanceDelete", "stickerCreate", "stickerDelete", "stickerUpdate", + "threadCreate", "threadDelete", "threadListSync", "threadMemberUpdate", "threadMembersUpdate", + "threadUpdate", "join", "leave", "inviteCreate", "inviteDelete", "memberUpdate", "memberAvailable", + "membersChunk", "emojiCreate", "emojiUpdate", "emojiDelete", "banAdd", "banRemove", "webhooksUpdate", + "voiceStateUpdate", "presenceUpdate", "reactionAdd", "reactionRemove", "reactionRemoveEmoji", + "reactionRemoveAll", "typingStart", "loop", "timeout", "pulse", "ready", "variableCreate", + "variableDelete", "variableUpdate", "functionError", "interaction", "applicationCmdCreate", + "applicationCmdUpdate", "applicationCmdDelete", "applicationCmdPermissionsUpdate", "userUpdate", + "rateLimit", "shardReady", "shardResume", "shardReconnecting", "shardDisconnect", "shardError", + "autoModActionExecution", "autoModCreate", "autoModDelete", "autoModUpdate" + ]; + + if (formCommand) { + this.formCommand(); + } else { + this.customCmds = customCmds; + this.formCustomCommand(customCmds); + } + } + + formCommand() { + this.types.forEach(x => (this[x] = new Group())); + this.interaction = { + selectMenu: new Group(), + button: new Group(), + slash: new Group(), + modal: new Group(), + }; + } + + createCommand(data = {}) { + data.type = data.type || "default"; + if (data.type === "interaction") { + this.interaction[data.prototype].set(this.interaction[data.prototype].size, new Command(data, this.client)); + } else { + this[data.type].set(this[data.type].size, new Command(data, this.client)); + } + } + + formCustomCommand(customCmds) { + customCmds.forEach(x => { + this[x] = new Group(); + }); + + if (!customCmds.includes("default")) { + this.default = new Group(); + } + } +} + +module.exports = { + CommandManager, + Command, +}; diff --git a/src/classes/CustomEvent.js b/src/classes/CustomEvent.js new file mode 100644 index 000000000..96a0a19f5 --- /dev/null +++ b/src/classes/CustomEvent.js @@ -0,0 +1,34 @@ +const EventExecuter = require("../handler/eventExecuter.js"); +const {EventEmitter} = require("events"); +const { Group : Collection } = require( "@akarui/structures" ); + +class CustomEvent extends EventEmitter { + constructor(client) { + super(client); + this.client = client; + this.commands = new Collection(); + this.client.customEvents = this; + } + + command(d = {}) { + if (!d.listen) { + throw new TypeError(`Listen is not provided in ${d.name}`); + } + if (!d.code) { + throw new TypeError(`Code is not provided in ${d.name}`); + } + + this.commands.set(d.name, d); + } + + listen(event) { + this.on(event, async (...data) => { + const commands = this.commands.filter( + (x) => x.listen === event, + ); + await EventExecuter(event, this.client, commands, ...data); + }); + } +} + +module.exports = CustomEvent; \ No newline at end of file diff --git a/src/classes/Database.js b/src/classes/Database.js new file mode 100644 index 000000000..8057599d2 --- /dev/null +++ b/src/classes/Database.js @@ -0,0 +1,83 @@ +const aoidb = require("@akarui/aoi.db"); +const AoiError = require("../classes/AoiError.js"); + +class Database { + /** + * @type {aoidb.KeyValue | aoidb.Transmitter} db + * @type {boolean} ready + * @type {number} readyAt + * @type {"aoi.db"} type + * @type {"KeyValue" | "Transmitter"} moduleType + * @type {string[]} tables + */ + db; + ready = false; + readyAt = 0; + type; + tables = []; + moduleType = "KeyValue"; + /** + * Description + * @param moduleType + * @param {any} module + * @param {"KeyValue" | "Transmitter"} type + * @param {aoidb.KeyValueOptions | aoidb.TransmitterOptions} config + * @returns {any} + */ + constructor(moduleType, module, type, config) { + this.moduleType = type; + this.db = new module[type](config); + this.tables = config.dataConfig.tables; + this.type = moduleType; + this.db.on(aoidb.DatabaseEvents.Connect, () => { + AoiError.createCustomBoxedMessage( + [ + { + text: `Successfully connected ${type} database`, + textColor: "white", + }, + ], + "white", + { text: "@akarui/aoi.db ", textColor: "cyan" } + ); + this.ready = true; + this.readyAt = Date.now(); + }); + + this.db.connect(); + } + + async set(table, key, id, value) { + return await this.db.set(table, id ? `${key}_${id}` : key, { value }); + } + + async get(table, key, id) { + return await this.db.get(table, id ? `${key}_${id}` : key); + } + + async delete(table, key, id) { + return await this.db.delete(table, id ? `${key}_${id}` : key); + } + + async all(table, query, limit) { + return await this.db.all(table, query, limit); + } + + async has(table, key, id) { + return await this.db.has(table, id ? `${key}_${id}` : key); + } + + async deleteMany(table, query) { + return await this.db.deleteMany(table, query); + } + + async findOne(table, query) { + return await this.db.findOne(table, query); + } + + async findMany(table, query, limit) { + return await this.db.findMany(table, query, limit); + } +} + +module.exports = Database; diff --git a/src/classes/Functions.js b/src/classes/Functions.js new file mode 100644 index 000000000..b4ae491fb --- /dev/null +++ b/src/classes/Functions.js @@ -0,0 +1,146 @@ +const { Group } = require("@akarui/structures"); +const { functions: parser, maps, grp } = require("../core/AoiReader.js"); +class Block { + constructor(func) { + this.parent = func; + this.childs = []; + } + add(child) { + this.childs.push(child); + } +} +class Function { + constructor(code, name) { + this.name = name; + this.code = code; + } +} + +class CustomFunction { + constructor(d = {}, client) { + this.client = client; + this.name = d.name; + this.code = d.code; + this.type = d.type; + this.params = d.params || []; + this.functions = + this.type === "aoi.js" ? this.serializeFunctions() : undefined; + } + + serializeFunctions() { + let Functions = this.client.functionManager.functions; + let code = this.code + ?.replace(/\\]/g, "#LEFT#") + .split("\\[") + .join("#RIGHT#") + .replace("\\,", "#COMMA#"); + let funcs = []; + let loadsOfFunc = Functions.filter((thatfunc) => + code.toLowerCase().includes(thatfunc.toLowerCase()), + ); + const funcyboys = code.split("$"); + for (const funcboy of funcyboys) { + let Func = loadsOfFunc.filter( + (f) => + f.toLowerCase() === + ("$" + funcboy.toLowerCase()).slice(0, f.length), + ); + if (!Func.length) { + continue; + } + if (Func.length === 1) { + funcs.push(Func[0]); + } else if (Func.length > 1) { + funcs.push(Func.sort((a, b) => b.length - a.length)[0]); + } + } + return funcs; + } +} + +class FunctionManager { + constructor(client) { + this.client = client; + this.maps = maps; + this.functions = /*Object.keys(parser)*/ parser; + this.cache = new Group(); + this.cacheFunctions(); + this.interpreter = require("../core/interpreter.js"); + this.usage = grp; + } + + async cacheFunctions() { + for (const func of this.functions) { + try { + const ogname = func.replace("$", "").replace("[", ""); + //this.cache.set(ogname, new Function(require('../functions/funcs/'+ogname+'.js'),func)) + const file = Object.entries(this.maps).find((y) => + y[1].includes(ogname), + )?.[0]; + if (!file) continue; + else { + this.cache.set( + ogname, + new Function( + require(`../functions/${file}/${ogname}.js`), + func, + ), + ); + } + } catch (e) { + console.error(e); + continue; + } + } + } + + createFunction(...ds) { + for (const d of ds) { + this.cache.set( + d.name.replace("$", ""), + new CustomFunction(d, this.client), + ); + this.functions.push(d.name); + } + } + + findFunctions(code = "") { + let Functions = this.functions; + code = code + ?.replace(/\\]/g, "#LEFT#") + .split("\\[") + .join("#RIGHT#") + .replace("\\,", "#COMMA#"); + let funcs = []; + let loadsOfFunc = Functions.filter((thatfunc) => + code.toLowerCase().includes(thatfunc.toLowerCase()), + ); + const funcyboys = code.split("$"); + for (const funcboy of funcyboys) { + let Func = loadsOfFunc.filter( + (f) => + f.toLowerCase() === + ("$" + funcboy.toLowerCase()).slice(0, f.length), + ); + if (!Func.length) { + continue; + } + if (Func.length === 1) { + funcs.push(Func[0]); + } else if (Func.length > 1) { + funcs.push(Func.sort((a, b) => b.length - a.length)[0]); + } + } + return funcs; + } + + serializeCode(code) { + return code?.split("\n"); + } +} + +module.exports = { + FunctionManager, + Function, + CustomFunction, +}; diff --git a/src/classes/Interaction.js b/src/classes/Interaction.js new file mode 100644 index 000000000..0986f905c --- /dev/null +++ b/src/classes/Interaction.js @@ -0,0 +1,146 @@ +const {EventEmitter} = require("events"); +const { Group } = require("@akarui/structures"); + +class Interaction extends EventEmitter { + constructor(client) { + super(); + this.client = client; + } + + resolve(data) { + data.author = data.user; + } +} + +class Await extends Interaction { + constructor(options, client, varData = {}) { + super(client); + this.options = options; + this.tries = 0; + this.data = varData; + } + + async await(msgid, user, customID, data) { + this.resolve(data); + if ( + this.options.msgId === msgid && + this.options.filter === user && + this.options.customIds.includes(customID) && + this.options.uses > this.tries + ) { + this.emit("AwaitComponent", data); + + this.tries += 1; + } else if (this.options.uses <= this.tries) { + this.removeAllListeners("AwaitComponent"); + } + if ( + this.options.filter !== user && + this.options.filter !== "everyone" && + this.options.uses > this.tries && + this.options.msgId === msgid + ) { + if (Object.keys(this.options.errorMessage).length !== 0) { + data.reply(JSON.parse(this.options.errorMessage)); + } + } + } +} + +class CustomCollector extends Interaction { + constructor(options, client, varData = {}) { + super(client); + this.options = options; + this.mainData = []; + this.timeout = setTimeout; + this.endsOn = Date.now() + Number(options.time); + this.data = varData; + } + + async start(msgid, user, customID, data) { + this.resolve(data); + if ( + this.options.customIDs.includes(customID) && + this.endsOn >= Date.now() && + this.options.msgId === msgid && + (this.options.filter === "everyone" || this.options.filter === user) + ) { + this.mainData.push(data); + this.emit("ItemFound", data); + } + this.timeout(() => { + this.emit("CustomCollectorOff", this.mainData); + delete this.options._timeout; + delete this._events.ItemFound; + }, this.options._timeout); + + if ( + this.options.filter !== "everyone" && + this.options.filter !== user && + Object.keys(this.options.errorMessage).length !== 0 && + this.endsOn > Date.now() && + this.options.msgid === msgid + ) { + data.reply(this.options.errorMessage); + } + } +} + +class InteractionManager extends Interaction { + constructor(client) { + super(client); + this.awaitComponents = Await; + this.ComponentCollector = CustomCollector; + + this.buttonData = new Group(); + this.applicationData = new Group(); + this.selectMenuData = new Group(); + } + + createApplicationData(d = {}) { + this.applicationData.set( + d.guildId ? `${d.data.name}_${d.guildId}` : d.data.name, + d.data, + ); + } + + createButtonData(d = {}) { + this.buttonData.set(d.customId, d); + } + + createSelectMenuData(d = {}) { + this.selectMenuData.set(d.customId, d); + } + + stringifyApplicationData(name) { + return JSON.stringify(this.ApplicationData.get(name)); + } + + resolveButtonData(customId) { + const d = this.buttonData.get(customId); + return `{button:${d.label}:${d.style}:${d.customId}:${d.disabled}:${d.emoji}}`; + } + + resolveSelectMenuData(customId) { + const d = this.selectMenuData.get(customId); + return `{selectMenu:${d.customId}:${d.placeholder}:${d.minValues}:${ + d.maxValues + }:${d.disabled}:${this.resolveSelectMenuOptionData(d.options)}`; + } + + resolveSelectMenuOptionData(options) { + let opt = []; + for (const o of options) { + opt.push( + `{selectMenuOptions:${o.label}:${o.value}:${o.description}:${o.default}:${o.emoji}}`, + ); + } + return opt.join(""); + } + + get buttonDataLength() { + return this.buttonData.size; + } +} + +module.exports = InteractionManager; \ No newline at end of file diff --git a/src/classes/LoadCommands.js b/src/classes/LoadCommands.js new file mode 100644 index 000000000..6b780cbb0 --- /dev/null +++ b/src/classes/LoadCommands.js @@ -0,0 +1,313 @@ +const fs = require("fs"); +const {CommandManager} = require("./Commands.js"); +const PATH = require("path"); + +class LoadCommands { + constructor(client, addClassInClient = true) { + this.client = client; + this.paths = []; + this.colors = {}; + if (addClassInClient) { + this.client.loader = this; + } + } + + get allColors() { + return { + reset: "\x1b[0m", + bright: "\x1b[1m", + dim: "\x1b[2m", + underscore: "\x1b[4m", + blink: "\x1b[5m", + reverse: "\x1b[7m", + hidden: "\x1b[8m", + + fgBlack: "\x1b[30m", + fgRed: "\x1b[31m", + fgGreen: "\x1b[32m", + fgYellow: "\x1b[33m", + fgBlue: "\x1b[34m", + fgMagenta: "\x1b[35m", + fgCyan: "\x1b[36m", + fgWhite: "\x1b[37m", + + bgBlack: "\x1b[40m", + bgRed: "\x1b[41m", + bgGreen: "\x1b[42m", + bgYellow: "\x1b[43m", + bgBlue: "\x1b[44m", + bgMagenta: "\x1b[45m", + bgCyan: "\x1b[46m", + bgWhite: "\x1b[47m", + }; + } + + get themes() { + return { + default: { + loading: ["blink", "dim", "fgWhite"], + failedLoading: { + name: ["bright", "fgYellow", "underline"], + text: ["bright", "fgRed"], + }, + typeError: { + command: ["bright", "fgYellow"], + type: ["fgYellow"], + text: ["bright", "fgRed"], + }, + failLoad: { + command: ["bright", "fgMagenta"], + type: ["fgRed"], + text: ["bright", "fgRed"], + }, + loaded: { + command: ["bright", "fgCyan"], + type: ["bright", "fgBlue"], + text: ["bright", "fgGreen"], + }, + }, + diff: { + loading: ["fgGreen"], + failedLoading: { + text: ["fgRed"], + name: ["bright", "fgRed"], + }, + typeError: { + command: ["bright", "fgRed"], + type: ["fgRed"], + text: ["dim", "fgRed"], + }, + failLoad: { + command: ["bright", "fgRed"], + type: ["fgRed"], + text: ["dim", "fgRed"], + }, + loaded: { + command: ["bright", "fgCyan"], + type: ["fgCyan"], + text: ["dim", "fgCyan"], + }, + }, + }; + } + + async load(client, path, debug = true) { + function isObject(data) { + return ( + data instanceof Object && + !Buffer.isBuffer(data) && + !Array.isArray(data) && + !(data instanceof RegExp) + ); + } + + async function walk(file) { + const something = await fs.promises + .readdir(file, {withFileTypes: true}) + .then((f) => { + return f.map((d) => { + d.name = `${file}${PATH.sep}${d.name}`; + + return d; + }); + }); + + const files = something.filter((d) => d.isFile()); + const dirs = something.filter((d) => d.isDirectory()); + + for (const d of dirs) { + const items = await walk(d.name); + + files.push(...items); + } + + return files; + } + + if (typeof path !== "string") + throw new TypeError( + `Expecting typeof string on 'path' parameter, get '${typeof path}' instead`, + ); + + if (!PATH.isAbsolute(path)) path = PATH.resolve(path); + + try { + if (await fs.promises.stat(path).then((f) => !f.isDirectory())) + throw new TypeError("Path is not a valid directory!"); + } catch (e) { + throw new TypeError("Path is not a valid directory! ErrorMessage: " + e); + } + + const index = this.paths.findIndex((d) => d.path === path); + + if (index < 0) + this.paths.push({ + path, + debug, + commandsLocation: client, + keys: Object.keys(client), + }); + + const validCmds = Object.getOwnPropertyNames(client); + + const dirents = await walk(path); + const debugs = []; + + for (const {name} of dirents) { + delete require.cache[name]; + + let cmds; + + try { + cmds = require(name); + } catch { + debugs.push( + `${this.colors.failedLoading?.text || ""}Failed to load in ${ + this.colors.failedLoading?.name || "" + }${name}${this.allColors.reset || ""}`, + ); + + continue; + } + + if (cmds == null) { + debugs.push( + `${this.colors.noData?.text || ""} No data provided in ${ + this.colors.noData?.name || "" + }${name}${this.allColors.reset || ""}`, + ); + + continue; + } + + if (!Array.isArray(cmds)) cmds = [cmds]; + + debugs.push( + `|${this.colors?.loading || ""} Loading in ${name}${ + this.allColors.reset || "" + } |`, + ); + + for (const cmd of cmds) { + if (!isObject(cmd)) { + debugs.push(` Provided data is not an object`); + + continue; + } + + if (!("type" in cmd)) cmd.type = "default"; + + const valid = validCmds.some((c) => c === cmd.type); + + if (!valid) { + const typeErrorCommand = this.colors.typeError?.command || ""; + const cmdNameOrChannel = cmd.name || cmd.channel; + const typeErrorType = this.colors.typeError?.type || ""; + const invalidTypeMessage = "Invalid Type Provided"; + const typeErrorText = this.colors.typeError?.text || ""; + + const debugMessage = `| ${typeErrorCommand}${cmdNameOrChannel}${this.allColors.reset} | ${typeErrorType}${cmd.type}${this.allColors.reset} | ${typeErrorText}${invalidTypeMessage}${this.allColors.reset} |`; + + debugs.push(debugMessage); + + continue; + } + + cmd.load = true; + cmd.__path__ = name.split(PATH.sep).slice(-2).join(PATH.sep); + + try { + if (client instanceof CommandManager) { + client.createCommand(cmd); + } else { + client[cmd.type].set(client[cmd.type].size, cmd); + } + } catch (e) { + console.error(e); + debugs.push( + `|${this.colors.failLoad?.command || ""}'${ + cmd.name || cmd.channel + }'| ${this.colors.failLoad?.type || ""}${cmd.type}${ + this.allColors.reset + }| ${this.colors.failLoad?.text || ""}Failed To Load${ + this.allColors.reset + }`); + + continue; + } + + debugs.push(`Loaded ${this.colors.loaded?.command || ""}'${ + cmd.name || cmd.channel + }' ${this.colors.loaded?.type || ""}|${cmd.type}| ${ + this.allColors.reset || "" + }${this.colors.loaded?.text || ""}${this.allColors.reset || ""}`); + } + } + + if (debug) { + console.log( + `| ${this.colors.loaded?.command || ""}Command${ + this.allColors.reset + } | ${this.colors.loaded?.type || ""}Type${ + this.allColors.reset + } | ${this.colors.loaded?.text || ""}State${this.allColors.reset} | +|------------------------------------------|\n` + debugs.join("\n"), + ); + } + } + + async update(debug = true) { + for (const dp of this.paths) { + for (const cmd of dp.keys) { + try { + if (cmd === "interaction") { + dp.commandsLocation.interaction.slash = + dp.commandsLocation.interaction.slash.filter((x) => !x.load); + dp.commandsLocation.interaction.button = + dp.commandsLocation.interaction.button.filter((x) => !x.load); + dp.commandsLocation.interaction.selectMenu = + dp.commandsLocation.interaction.selectMenu.filter((x) => !x.load); + dp.commandsLocation.interaction.modal = dp.commandsLocation.interaction.modal.filter((x) => !x.load); + } else + dp.commandsLocation[cmd] = dp.commandsLocation[cmd].filter( + (x) => !x.load, + ); + if (cmd.loopInterval) { + clearInterval(cmd.loopInterval); + } + } catch (e) { + + } + } + await this.load(dp.commandsLocation, dp.path, debug); + } + } + + setColors( + c = { + failLoad: null, + loading: null, + failedLoading: null, + loaded: null, + typeError: null, + noData: null, + }, + ) { + for (const co of Object.keys(c)) { + if (Array.isArray(c[co])) { + this.colors[co] = c[co]?.map((x) => this.allColors[x]).join(" "); + } else if (typeof c[co] === "object" && !Array.isArray(c[co])) { + this.colors[co] = {}; + for (const coo of Object.keys(c[co])) { + if (Array.isArray(c[co][coo])) { + this.colors[co][coo] = c[co][coo] + .map((x) => this.allColors[x]) + .join(" "); + } else this.colors[co][coo] = c[co][coo]; + } + } else this.colors[co] = this.allColors[c[co]]; + } + } +} + +module.exports = LoadCommands; \ No newline at end of file diff --git a/src/classes/Util.js b/src/classes/Util.js new file mode 100644 index 000000000..4f9198840 --- /dev/null +++ b/src/classes/Util.js @@ -0,0 +1,322 @@ +const Constants = require("../utils/Constants.js"); +const Discord = require("discord.js"); +const parsers = require("../handler/parsers.js"); + +class Util { + static constants = Constants; + static parsers = parsers; + + static async getUser(d, id) { + let user = d.client.users.cache.get(id); + if (!user) { + user = await this.fetchUser(d, id); + } + return user; + } + + static async fetchUser(d, id) { + try { + return await d.client.users.fetch(id, { force: true }); + } catch (err) { + return undefined; + } + } + + static async fetchChannel(d, id) { + try { + return await d.client.channels.fetch(id, { force: true }); + } catch (e) { + return undefined; + } + } + + static getChannel(d, id, force = false) { + if (d.channel?.id === id) return d.channel; + else { + let channel = d.client.channels.cache.get(id); + if (!channel && force) channel = this.fetchChannel(d, id); + return channel; + } + } + + static async fetchMember(guild, id) { + try { + return await guild.members.fetch(id, { force: true }); + } catch (err) { + return undefined; + } + } + + static async fetchMembers(guild, options) { + return guild.members.fetch(options); + } + + static getMember(guild, id) { + let member = guild.members.cache.get(id); + if (!member) member = this.fetchMember(guild, id); + return member; + } + + static getMembers( + guild, + options = { type: "startsWith", query: "", limit: 10 }, + force = false + ) { + let members; + if (!force) { + members = guild.members.cache + .filter( + (x) => + x.user.username.toLowerCase()[options.type](options.query) || + x.displayName?.toLowerCase()[options.type](options.query) + ) + .first(options.limit); + } else { + members = this.fetchMembers(guild, options); + } + return members; + } + + static async fetchMessage(channel, id) { + try { + return await channel.messages.fetch(id, { force: true }); + } catch (err) { + return undefined; + } + } + + static getMessage(channel, id) { + let message = channel.messages.cache.get(id); + if (!message) message = this.fetchMessage(channel, id); + return message; + } + + static setCode(options = {}, escape = true) { + return options.code.replaceLast( + options.inside + ? `${options.function}${options.inside}` + : `${options.function}`, + (escape + ? options.result?.toString()?.deleteBrackets() + : options.result.toString()) ?? "" + ); + } + + static async getGuild(d, id) { + if (d.guild?.id === id && d.guild?.id) return d.guild; + else { + if (!d.client.shard) return d.client.guilds.cache.get(id); + else { + const arr = await d.client.shard.broadcastEval((client) => + client.guilds.cache.get(id) + ); + return arr.find((x) => x); + } + } + } + + static get channelTypes() { + return { + Text: Discord.ChannelType.GuildText, + Voice: Discord.ChannelType.GuildVoice, + Category: Discord.ChannelType.GuildCategory, + DM: Discord.ChannelType.DM, + Announcement: Discord.ChannelType.GuildAnnouncement, + AnnouncementThread: Discord.ChannelType.AnnouncementThread, + PublicThread: Discord.ChannelType.PublicThread, + PrivateThread: Discord.ChannelType.PrivateThread, + Stage: Discord.ChannelType.GuildStageVoice, + Forum: Discord.ChannelType.GuildForum, + Media: Discord.ChannelType.GuildMedia, + GuildDirectory: Discord.ChannelType.GuildDirectory, + GroupDM: Discord.ChannelType.GroupDM, + }; + } + + static get threadTypes() { + return { + public: Discord.ChannelType.PublicThread, + private: Discord.ChannelType.PrivateThread, + }; + } + + static async errorParser(errorM, d) { + let error; + if (typeof errorM === "object") return errorM; + + try { + error = await this.parsers.ErrorHandler(errorM, d, true); + } catch (e) { + error = undefined; + } + return error; + } + + static async getRole(guild, id) { + try { + let role = guild.roles.cache.get(id); + if (!role) role = await this.fetchRole(guild, id); + return role; + } catch (err) { + return undefined; + } + } + + static async fetchRole(guild, id) { + try { + return await guild.roles.fetch(id, { force: true }); + } catch (err) { + return undefined; + } + } + + static aoiFunc(d, FieldsRequired = true) { + const data = { + inside: d.unpack(), + code: d.command.code, + function: d.func, + }; + if (FieldsRequired) { + data.err = d.inside(data.inside); + } + return data; + } + + static getEmoji(d, Emoji) { + return d.client.emojis.cache.find( + (x) => + x.name.toLowerCase() === Emoji.toLowerCase().addBrackets() || + x.id === Emoji || + x.toString() === Emoji + ); + } + + static getSticker(guild, Sticker) { + return guild.stickers.cache.find( + (x) => + x.name.toLowerCase() === Sticker.toLowerCase().addBrackets() || + x.id === Sticker + ); + } + + static async findId(d, id) { + return ( + (await this.getGuild(d, id)) || + (await this.getUser(d, id)) || + (await this.getChannel(d, id, false)) || + (await this.getMessage(d.channel, id)) || + (await this.getRole(d.guild, id)) || + this.getEmoji(d, id) || + this.getSticker(d.guild, id) || + undefined + ); + } + + static findMember(guild, memberResolver) { + return guild.members.cache.findKey( + (x) => + x.displayName.toLowerCase() === memberResolver.toLowerCase() || + x.user.username.toLowerCase() === memberResolver.toLowerCase() || + x.id === memberResolver || + x.toString() === memberResolver + ); + } + + static findGuildChannel(guild, ChannelResolver) { + return guild.channels.cache.findKey( + (x) => + x.name.toLowerCase() === ChannelResolver.toLowerCase() || + x.id === ChannelResolver || + x.toString() === ChannelResolver + ); + } + + static findChannel(client, ChannelResolver) { + return client.channels.cache.findKey( + (x) => + x.name.toLowerCase() === ChannelResolver.toLowerCase() || + x.id === ChannelResolver || + x.toString() === ChannelResolver + ); + } + + static findRole(guild, RoleResolver) { + return guild.roles.cache.findKey( + (x) => + x.name.toLowerCase() === RoleResolver.toLowerCase() || + x.id === RoleResolver || + x.toString() === RoleResolver + ); + } + + static findUser(client, UserResolver) { + return client.users.cache.findKey( + (x) => + x.username.toLowerCase() === UserResolver.toLowerCase() || + x.tag.toLowerCase() === UserResolver.toLowerCase() || + x.id === UserResolver || + x.toString() === UserResolver + ); + } + + static findRoles( + guild, + options = { type: "startsWith", query: "", limit: 10 } + ) { + return guild.roles.cache + .filter((x) => { + return x.name.toLowerCase()[options.type](options.query.toLowerCase()); + }) + .first(options.limit); + } +} + +Util.searchType = ["soundcloud", "localfile", "url", "youtube", "spotify"]; +Util.audioFilters = { + nightcore: (value) => { + return { + asetrate: 48000 * value, + aresample: 48000, + }; + }, + bassboost: (value) => { + return { + bass: `g=${value}`, + }; + }, + "8d": () => { + return { + extrastereo: "", + aecho: "1:1:40:0.5", + apulsator: "hz=0.125", + stereowiden: "", + }; + }, + pitch: (value) => { + return { + asetrate: 48000 * value, + atempo: 1 - Number(`${value}`.split(".")[1]), + aresample: 48000, + }; + }, + karaoke: (value) => { + return { + stereotools: `mlev=${0.015625 * value}`, + }; + }, + slowed: (value) => { + return { + asetrate: 48000 * Math.abs(Math.ceil(value) - value), + aresample: 48000, + }; + }, + deep: (value) => { + return { + asetrate: 48000 * Math.abs(Math.ceil(value) - value), + atempo: 2 - Math.abs(Math.ceil(value) - value), + aresample: 48000, + }; + }, +}; + +module.exports = Util; \ No newline at end of file diff --git a/src/classes/Variables.js b/src/classes/Variables.js new file mode 100644 index 000000000..f3f82604a --- /dev/null +++ b/src/classes/Variables.js @@ -0,0 +1,122 @@ +const { Group } = require("@akarui/structures"); + +class Variable { + constructor(data = {}) { + this.name = data.name; + this.type = data.type; + this.default = data.value; + } + + object() { + let x = {}; + Object.assign(x, this); + return x; + } + + toJSON() { + return JSON.stringify(this.object(), null, 2); + } + + entries() { + return Object.entries(this); + } + + get toArray() { + return Object.values(this); + } + + checkType(value) { + let res = true; + if (this.type === "TEXT" && typeof value !== "string") res = false; + else if (this.type === "INTEGER" && !Number.isInteger(Number(value))) + res = false; + else if (this.type === "NUMERIC" && isNaN(value)) res = false; + else if (this.type === "JSON") { + try { + JSON.parse(value); + } catch (E) { + res = false; + } + } + return res; + } +} + +class VariableManager { + constructor(client) { + this.client = client; + this.cache = new Group(); + } + + findType(value) { + let res; + switch (typeof value) { + case "string": + res = "TEXT"; + break; + case "number": + if (Number.isInteger(value)) res = "INTEGER"; + else res = "NUMERIC"; + break; + case "object": + res = "JSON"; + break; + } + return res; + } + + parseData(value, type) { + if (type === "NUMERIC" || type === "INTEGER") { + if (!isNaN(value)) return Number(value); + } else if (type === "JSON") { + try { + return JSON.parse(value); + } catch (e) { + return; + } + } else return value; + } + + get size() { + return this.cache.size; + } + + get values() { + return this.cache.allValues().map((x) => x.value); + } + + get vars() { + return this.cache.allKeys(); + } + + add(data) { + data.type = this.findType(data.value); + this.cache.set(`${data.name}_${data.table}`, new Variable(data)); + } + + delete(name) { + this.cache.delete(name); + } + + get(name, table) { + return this.cache.get(`${name}_${table}`); + } + + has(name, table = this.client.db.tables[0]) { + return this.cache.has(`${name}_${table}`); + } + + toJSON() { + const keys = this.cache.allKeys(); + const values = this.cache.allValues(); + const json = keys.map((x) => this.cache.get(x).toJSON()); + return ( + "{\n" + keys.map((x, y) => `"${x}" : ${json[y]} `).join(",\n") + "\n}" + ); + } +} + +module.exports = { + Variable, + VariableManager, +}; \ No newline at end of file diff --git a/src/core/AoiReader.js b/src/core/AoiReader.js new file mode 100644 index 000000000..4fbea8077 --- /dev/null +++ b/src/core/AoiReader.js @@ -0,0 +1,16 @@ +const fs = require("fs"); +const { Group } = require("@akarui/structures"); +const path = require("path"); + +const maps = {}; +const grp = new Group(); + +const functions = fs + .readdirSync(path.join(__dirname, "../functions")) + .flatMap((dir) => { + const files = fs.readdirSync(path.join(__dirname, `../functions/${dir}`)); + maps[dir] = files.map((file) => file.split(".js")[0]); + return files.map((file) => "$" + file.split(".js")[0]); + }); + +module.exports = { functions, maps, grp }; diff --git a/src/core/interpreter.js b/src/core/interpreter.js new file mode 100644 index 000000000..3ed0df978 --- /dev/null +++ b/src/core/interpreter.js @@ -0,0 +1,634 @@ +const Discord = require("discord.js"); +const { CustomFunction } = require("../classes/Functions.js"); +const AoiError = require("../classes/AoiError.js"); +const Util = require("../classes/Util.js"); +const IF = require("../utils/helpers/if.js"); +//Helper of aoijs +const { Time } = require("../utils/helpers/customParser.js"); +const { CheckCondition } = require("../utils/helpers/checkCondition.js"); +const { mustEscape } = require("../utils/helpers/mustEscape.js"); +const { Command } = require("../classes/Commands.js"); +const PATH = require("path"); +const { deprecate } = require("util"); + +// Deprecate error for $if: old +let isDeprecated = false; +function deprecateOldIfUsage() { + if (!isDeprecated) { + deprecate(() => { }, "Using $if: old is deprecated. Use $if")(); + isDeprecated = true; + } +} + +/** + * @param {import('../classes/AoiClient.js')} client + * @param {Discord.Message | { + * message?:Discord.Message, + * channel?:Discord.PartialDMChannel | Discord.DMChannel | Discord.TextChannel | Discord.NewsChannel | Discord.ThreadChannel, + * guild?:Discord.Guild | null, + * author?:Discord.User, + * member?:Discord.GuildMember, + * mentions?:Discord.MessageMentions }} message + * @param {string[]} args + * @param {Command | object } command + * @param {string} _db db to be used (deprecated param) + * @param {boolean} returnCode=false + * @param {string | void} channelUsed + * @param {object} data={} + * @param {Discord.TextChannel} useChannel + * @param {boolean} returnMessage + * @param {boolean} returnExecution + * @param {boolean} returnID + * @param {boolean} sendMessage=false + */ +const Interpreter = async ( + client, + message, + args, + command, + _db, + returnCode = false, + channelUsed, + data = {}, + useChannel, + returnMessage, + returnExecution, + returnID, + sendMessage = false +) => { + try { + const start = performance.now(); + //defining vars// + let code = command.code + ?.replaceAll("\\]", "#LEFT#") + .split("\\[") + .join("#RIGHT#") + .replaceAll("\\,", "#COMMA#") + .replaceAll("\\;", "#SEMI#"); + + let [ + randoms, + timezone, + letVars, + object, + disableMentions, + array, + arrays, + reactions, + channel, + author, + guild, + mentions, + member, + msg, + ] = [ + data.randoms || {}, + "UTC", + data.vars || {}, + data.object || {}, + ["roles", "users", "everyone"], + data.array || [], + data.arrays || [], + [], + message.channel, + message.author, + message.guild, + message.mentions, + message.member, + message, + ]; + let errorOccurred; + let embeds; + let deleteIn; + let suppressErrors; + let editIn = undefined; + let error; + let attachments = []; + let components = []; + let reply; + let allowedMentions = disableMentions; + let FuncData; + let msgobj; + let funcLine; + let returnData = {}; + command.codeLines = + command.codeLines || + client.functionManager.serializeCode(command.code); + let funcs = command.functions?.length + ? command.functions + : client.functionManager.findFunctions(command.code); + command.__path__ = PATH.sep + command.name + ".js"; + // debug system + const debug = { + code, + functions: command.functions, + }; + if (command["$if"] === "old") { + deprecateOldIfUsage(); + code = ( + await IF({ + client, + code, + message, + channel, + args, + data: { + randoms: randoms, + command: { + name: command.name, + code: code, + error: command.error, + async: command.async || false, + functions: command.functions, + __path__: command.__path__, + codeLines: command.codeLines, + }, + helpers: { + time: Time, + checkCondition: CheckCondition, + mustEscape, + }, + args: args, + aoiError: require("../classes/AoiError.js"), + data: data, + func: undefined, + funcLine: undefined, + util: Util, + allowedMentions: allowedMentions, + embeds: embeds || [], + components: components, + files: attachments || [], + timezone: timezone, + channelUsed: channelUsed, + vars: letVars, + object: object, + disableMentions: disableMentions, + returnID: returnID, + array: array, + arrays, + reactions: reactions, + message: message.message || message, + msg: msg.message || msg, + author: author, + guild: guild, + channel: channel, + member: member, + mentions: mentions, + unpack() { + const last = + code.split(this.func.replace("[", "")).length - 1; + const sliced = code.split( + this.func.replace("[", "") + )[last]; + + return sliced.after(); + }, + inside(unpacked) { + if (typeof unpacked.inside !== "string") { + if (suppressErrors) return suppressErrors; + else { + return client.aoiOptions.suppressAllErrors + ? client.aoiOptions.errorMessage + : `\`\`\`js\nAoiError: ${this.func}: Invalid Usage\`\`\``; + } + } else return false; + }, + noop() { }, + interpreter: Interpreter, + client: client, + embed: Discord.EmbedBuilder, + }, + }) + ).code; + funcs = client.functionManager.findFunctions(code); + } + //parsing functions (dont touch) + for (let i = funcs.length; i > 0; i--) { + if (!funcs.length) break; + + if (i > funcs.length && funcs.length !== 0) i = funcs.length; + + let func = funcs[i - 1]; + + if (error) break; + const regex = new RegExp( + "\\" + func.replace("[", "\\["), + "gi" + ); + + code = code.replace(regex, func); + //more debug + debug[func] = { regex, func }; + command.codeLines?.map((x) => x.replace(regex, func)); + funcLine = + command.codeLines.length - + command.codeLines + ?.reverse() + .findIndex((x) => + x.toLowerCase().split(" ").includes(func.toLowerCase()) + ); + + const functionObj = client.functionManager.cache.get( + func.replace("$", "").replace("[", "") + ); + if ( + functionObj instanceof CustomFunction && + functionObj.type === "aoi.js" + ) { + const d = {}; + Object.assign(d, functionObj); + let param = []; + for (let p = functionObj.params.length - 1; p >= 0; p--) { + d.code = d.code.replace( + `{${functionObj.params[p]}}`, + unpack(code, func).splits[p] + ); + param.push(functionObj.params[p]); + } + FuncData = await client.functionManager.interpreter( + client, + message, + args, + d, + client.db, + true, + channelUsed, + { + randoms: randoms, + command: { + name: command.name, + code: code, + error: command.error, + async: command.async || false, + functions: command.functions, + __path__: command.__path__, + codeLines: command.codeLines, + funcLine: funcLine, + }, + helpers: { + time: Time, + checkCondition: CheckCondition, + mustEscape, + }, + args: args, + aoiError: require("../classes/AoiError.js"), + data: data, + func: func, + funcLine, + util: Util, + allowedMentions: allowedMentions, + embeds: embeds || [], + components: components, + files: attachments || [], + timezone: timezone, + channelUsed: channelUsed, + vars: letVars, + object: object, + disableMentions: disableMentions, + returnID: returnID, + array: array, + arrays, + reactions: reactions, + message: message.message || message, + msg: msg.message || msg, + author: author, + guild: guild, + channel: channel, + member: member, + mentions: mentions, + unpack() { + const last = code.split(func.replace("[", "")).length - 1; + const sliced = code.split(func.replace("[", ""))[last]; + + return sliced.after(); + }, + inside(unpacked) { + if (typeof unpacked.inside !== "string") { + if (suppressErrors) return suppressErrors; + else { + return client.aoiOptions.suppressAllErrors + ? client.aoiOptions.errorMessage + : `\`\`\`js\nAoiError: ${this.func}: Invalid Usage\`\`\``; + } + } else return false; + }, + noop() { }, + interpreter: Interpreter, + client: client, + embed: Discord.EmbedBuilder, + }, + useChannel, + returnMessage, + returnExecution, + returnID, + sendMessage + ); + FuncData.code = code.replaceLast( + functionObj.params.length + ? `${func}${param.join(";")}` + : func, + FuncData.code + ); + } else { + FuncData = await client.functionManager.cache + .get(func.replace("$", "").replace("[", "")) + ?.code({ + randoms: randoms, + command: { + name: command.name, + code: code, + error: command.error, + async: command.async || false, + functions: command.functions, + __path__: command.__path__, + codeLines: command.codeLines, + funcLine: funcLine, + }, + helpers: { + time: Time, + checkCondition: CheckCondition, + mustEscape, + }, + args: args, + aoiError: require("../classes/AoiError.js"), + data: data, + func: func, + funcLine, + util: Util, + allowedMentions: allowedMentions, + embeds: embeds || [], + components: components, + files: attachments || [], + timezone: timezone, + channelUsed: channelUsed, + vars: letVars, + object: object, + disableMentions: disableMentions, + array: array, + arrays, + reactions: reactions, + message: message.message || message, + msg: msg.message || msg, + author: author, + guild: guild, + channel: channel, + member: member, + mentions: mentions, //cleanup (ignore) + unpack() { + const last = code.split(func.replace("[", "")).length - 1; + const sliced = code.split(func.replace("[", ""))[last]; + + return sliced.after(); + }, + inside(unpacked) { + if (typeof unpacked.inside !== "string") { + if (suppressErrors) return suppressErrors; + else { + return client.aoiOptions.suppressAllErrors + ? client.aoiOptions.errorMessage + : `\`\`\`js\nAoiError: ${this.func}: Invalid Usage\`\`\``; + } + } else return false; + }, + noop() { }, + async error(err, d) { + error = true; + client.emit( + "functionError", + { + error: err?.addBrackets(), + function: func, + command: command.name, + channel, + guild, + }, + client + ); + if (client.aoiOptions.suppressAllErrors) { + if (client.aoiOptions.errorMessage) { + const msg = message; + if (!msg || !msg.channel) { + console.error(client.aoiOptions.errorMessage.addBrackets()); + } else { + if (!errorOccurred) { + try { + await Interpreter( + client, + msg ?? data, + args ?? [], + { code: client.aoiOptions.errorMessage }, + client.db, + false, + msg.channel ?? [], + {}, + msg.channel ?? [], + false, + false, + false, + true, + ); + } catch (e) { + console.error(client.aoiOptions.errorMessage.addBrackets()); + } + errorOccurred = true; + } + } + } + } else { + if (!message || !message.channel) { + console.error(err.addBrackets()); + } else if (suppressErrors && !errorOccurred) { + if (suppressErrors.trim() !== "") { + const { + makeMessageError, + } = require("../classes/AoiError.js"); + const msg = await Util.errorParser( + suppressErrors + ?.split("{error}") + .join(err.addBrackets()), + { + channel: channel, + message: message, + guild: guild, + author: author, + } + ); + await makeMessageError( + client, + channel, + msg.data ?? msg, + msg.options, + { + channel: channel, + message: message, + guild: guild, + author: author, + data: data, + } + ); + } + } else { + await message.channel.send( + typeof err === "object" ? err : err?.addBrackets() + ); + } + errorOccurred = true; + } + }, + interpreter: Interpreter, + client: client, + embed: Discord.EmbedBuilder, + }); + } + + code = FuncData?.code ?? code; + + if (FuncData?.randoms) { + randoms = FuncData.randoms; + } + if (FuncData?.data) { + data = FuncData.data; + array = FuncData.data?.array ?? array; + arrays = FuncData.data?.arrays ?? arrays; + object = FuncData?.data?.object ?? object; + letVars = FuncData?.data?.vars ?? letVars; + } + if (FuncData?.timezone) { + timezone = FuncData.timezone; + } + if (FuncData?.allowedMentions) { + allowedMentions = FuncData.allowedMentions; + } + if (FuncData?.embeds) { + embeds = FuncData.embeds; + } + if (FuncData?.reactions) { + reactions = FuncData.reactions; + } + if (FuncData?.disableMentions) { + disableMentions = FuncData.disableMentions; + } + if (FuncData?.editIn) { + editIn = FuncData.editIn; + } + if (FuncData?.deleteIn) { + deleteIn = FuncData.deleteIn; + } + if (FuncData?.files) { + attachments = FuncData.files; + } + if (FuncData?.suppressErrors) { + suppressErrors = FuncData.suppressErrors; + } + if (FuncData?.components) { + components = FuncData.components; + } + if (FuncData?.reply) { + reply = FuncData.reply; + } + if (FuncData?.useChannel) { + useChannel = FuncData.useChannel; + } + if (FuncData?.returnID) { + returnID = FuncData.returnID; + } + if (FuncData?.error) { + error = FuncData?.error; + } + if (FuncData?.arrays) { + arrays = FuncData?.arrays; + } + } + + const ended = (performance.now() - start).toFixed(3); + embeds = JSON.parse( + JSON.stringify(embeds || [])?.replaceAll("$executionTime", ended) + ); + + debug.executionTime = ended + " ms"; + code = code?.replace(/\$executiontime/gi, ended); + + code = code.trim(); + if (embeds?.some((x) => x === undefined)) { + error = true; + return AoiError.consoleError("EmbedError", "Index are not defined."); + } + if (returnCode) { + returnData.code = code; + } + if (returnExecution) { + returnData.data = data; + } + if ( + (code.length || embeds?.length || attachments?.length) && + !errorOccurred && + !error + ) { + try { + const send = { + embeds: embeds, + files: attachments, + components: components, + allowedMentions: { + parse: allowedMentions, + repliedUser: reply?.user || false, + }, + reply: { + messageReference: reply?.message, + }, + }; + if (code.trim() !== "") { + send.content = code.addBrackets() === "" ? " " : code.addBrackets(); + } + if (returnCode && !sendMessage) { + } else { + if (!useChannel) { + msgobj = await message.channel?.send(send); + } else { + msgobj = await useChannel.send(send); + } + } + if (reactions?.length) { + const react = setInterval(() => { + const r = reactions.shift(); + msgobj.react(r); + if (!reactions.length) { + clearInterval(react); + } + }, 1500); + } + if (editIn) { + const ee = setInterval(() => { + const m = editIn.msgs; + msgobj.edit(m.shift()); + if (!m.length) { + clearInterval(ee); + } + }, editIn.time); + } + if (deleteIn) { + setTimeout(() => msgobj.delete(), deleteIn); + } + + if (returnID) { + returnData.id = msgobj?.id; + } + if (returnMessage) { + returnData.message = msgobj; + } + } catch (e) { + console.error(e); + } + } + return Object.keys(returnData).length ? returnData : undefined; + } catch (e) { + console.error(e); + } +}; +module.exports = Interpreter; + +function unpack(code, func) { + const last = code.split(func.replace("[", "")).length - 1; + const sliced = code.split(func.replace("[", ""))[last]; + return sliced.after(); +} diff --git a/src/functions/array/arrayAt.js b/src/functions/array/arrayAt.js new file mode 100644 index 000000000..778f8caaf --- /dev/null +++ b/src/functions/array/arrayAt.js @@ -0,0 +1,16 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if ( data.err ) return d.error( data.err ); + + const [ name,index ] = data.inside.splits; + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + + data.result = d.arrays[ name ].at(index-1); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayConcat.js b/src/functions/array/arrayConcat.js new file mode 100644 index 000000000..b5f6c18ba --- /dev/null +++ b/src/functions/array/arrayConcat.js @@ -0,0 +1,24 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [separator, ...names] = data.inside.splits; + + const name = names.shift(); + + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array with name '" + name + "' does not exist.", + ); + } + + data.result = d.arrays[name] + .concat(...names.map((x) => d.arrays[x])) + .join(separator); + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/array/arrayEvery.js b/src/functions/array/arrayEvery.js new file mode 100644 index 000000000..e167db6f8 --- /dev/null +++ b/src/functions/array/arrayEvery.js @@ -0,0 +1,24 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, query, queryType = "=="] = data.inside.splits; + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array with name '" + name + "' does not exist.", + ); + } + + data.result = d.arrays[name].every((x) => + ["==", "!=", "<=", ">=", "<", ">"].includes(queryType) + ? eval(d.helpers.checkCondition.solve(`${x}${queryType}${query}`)) + : x[queryType](query), + ); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/array/arrayFilter.js b/src/functions/array/arrayFilter.js new file mode 100644 index 000000000..5b02145cf --- /dev/null +++ b/src/functions/array/arrayFilter.js @@ -0,0 +1,26 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, query, queryType = "==", separator = ","] = data.inside.splits; + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array with name '" + name + "' does not exist.", + ); + } + + data.result = d.arrays[name] + .filter((x) => + ["==", "!=", "<=", ">=", "<", ">"].includes(queryType) + ? eval(d.helpers.checkCondition.solve(`${x}${queryType}${query}`)) + : x[queryType](query), + ) + .join(separator); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/array/arrayFind.js b/src/functions/array/arrayFind.js new file mode 100644 index 000000000..dd871796a --- /dev/null +++ b/src/functions/array/arrayFind.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, query, queryType = "=="] = data.inside.splits; + + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array with name '" + name + "' does not exist.", + ); + } + + data.result = d.arrays[name].find((x) => + ["==", "!=", "<=", ">=", "<", ">"].includes(queryType) + ? eval(d.helpers.checkCondition.solve(`${x}${queryType}${query}`)) + : x[queryType](query), + ); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/array/arrayForEach.js b/src/functions/array/arrayForEach.js new file mode 100644 index 000000000..91a64cdfd --- /dev/null +++ b/src/functions/array/arrayForEach.js @@ -0,0 +1,48 @@ +const Interpreter = require( "../../core/interpreter.js" ); +module.exports = async d => +{ + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name, awaitedCmd, awaitData = '{}' ] = data.inside.splits; + + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array With Name '" + name + "' Does Not Exist." ); + } + + let cmd = d.client.cmd.awaited.find( c => c.name.toLowerCase() === awaitedCmd.toLowerCase() ); + + if ( !cmd ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Awaited Command With Name '" + awaitedCmd + "' Does Not Exist." ); + } + let parsedData; + try + { + parsedData = JSON.parse( awaitData ); + } catch ( e ) + { + return d.aoiError.fnError( d, "custom", {}, `Failed To Parse Data With Reason: ${ e.message }` ); + } + + for ( const el of d.arrays[ name ] ) + { + const c = { ...cmd }; + c.code = c.code.replaceAll("{value}", el); + const result = await Interpreter( + d.client, + d.message, + d.args, + c, + d.client.db, + true, + undefined, + { ...d.data, awaitData: parsedData } + ); + } + + return { + code: d.util.setCode( data ), + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayIncludes.js b/src/functions/array/arrayIncludes.js new file mode 100644 index 000000000..c0a064907 --- /dev/null +++ b/src/functions/array/arrayIncludes.js @@ -0,0 +1,20 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, query] = data.inside.splits; + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array with name '" + name + "' does not exist.", + ); + } + + data.result = d.arrays[name].includes(query); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/array/arrayIndexOf.js b/src/functions/array/arrayIndexOf.js new file mode 100644 index 000000000..35f6cf594 --- /dev/null +++ b/src/functions/array/arrayIndexOf.js @@ -0,0 +1,17 @@ +module.exports = async d => +{ + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name,query ] = data.inside.splits; + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + + data.result = d.arrays[ name ].indexOf(query)+1; + + return { + code: d.util.setCode( data ), + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayJoin.js b/src/functions/array/arrayJoin.js new file mode 100644 index 000000000..84565ffc3 --- /dev/null +++ b/src/functions/array/arrayJoin.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name,separator = ","] = data.inside.splits; + data.result = d.arrays[name].join(separator); + + return { + code: d.util.setCode(data), + } +} \ No newline at end of file diff --git a/src/functions/array/arrayLastIndexOf.js b/src/functions/array/arrayLastIndexOf.js new file mode 100644 index 000000000..59501151a --- /dev/null +++ b/src/functions/array/arrayLastIndexOf.js @@ -0,0 +1,16 @@ +module.exports = async d => +{ + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name,query ] = data.inside.splits; + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + data.result = d.arrays[ name ].lastIndexOf(query)+1; + + return { + code: d.util.setCode( data ), + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayLength.js b/src/functions/array/arrayLength.js new file mode 100644 index 000000000..d4fdd56d5 --- /dev/null +++ b/src/functions/array/arrayLength.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const name = data.inside.inside; + + data.result = d.arrays[name]?.length ?? 0; + + return { + code: d.util.setCode(data), + } +} \ No newline at end of file diff --git a/src/functions/array/arrayMap.js b/src/functions/array/arrayMap.js new file mode 100644 index 000000000..c4c1ac676 --- /dev/null +++ b/src/functions/array/arrayMap.js @@ -0,0 +1,50 @@ +const Interpreter = require( "../../core/interpreter.js" ); +module.exports = async d => +{ + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name, awaitedCmd, separator = ',', awaitData = '{}' ] = data.inside.splits; + + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array With Name '" + name + "' Does Not Exist." ); + } + + let cmd = d.client.cmd.awaited.find( c => c.name.toLowerCase() === awaitedCmd.toLowerCase() ); + + if ( !cmd ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Awaited Command With Name '" + awaitedCmd + "' Does Not Exist." ); + } + let parsedData; + try + { + parsedData = JSON.parse( awaitData ); + } catch ( e ) + { + return d.aoiError.fnError( d, "custom", {}, `Failed To Parse Data With Reason: ${ e.message }` ); + } + const res = []; + for ( const el of d.arrays[ name ] ) + { + const c = { ...cmd }; + c.code = c.code.replaceAll( '{value}', el ); + const result = await Interpreter( + d.client, + d.message, + d.args, + c, + d.client.db, + true, + undefined, + { ...d.data, awaitData: parsedData } + ); + res.push( result?.code ); + } + + data.result = res.join( separator ); + return { + code: d.util.setCode( data ), + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayPop.js b/src/functions/array/arrayPop.js new file mode 100644 index 000000000..41b8a3cf4 --- /dev/null +++ b/src/functions/array/arrayPop.js @@ -0,0 +1,20 @@ +module.exports = async d => +{ + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name] = data.inside.splits; + + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + + data.result = d.arrays[ name ].pop(); + d.data.arrays = d.arrays; + return { + code: d.util.setCode(data), + arrays: d.arrays, + data: d.data, + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayPush.js b/src/functions/array/arrayPush.js new file mode 100644 index 000000000..21558b84d --- /dev/null +++ b/src/functions/array/arrayPush.js @@ -0,0 +1,20 @@ +module.exports = async d => +{ + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name, ...elements ] = data.inside.splits; + + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + + data.result = d.arrays[ name ].push( ...elements ); + d.data.arrays = d.arrays; + return { + code: d.util.setCode(data), + arrays: d.arrays, + data: d.data, + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayReverse.js b/src/functions/array/arrayReverse.js new file mode 100644 index 000000000..e1a388b72 --- /dev/null +++ b/src/functions/array/arrayReverse.js @@ -0,0 +1,23 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name] = data.inside.splits; + + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array With Name '" + name + "' Does Not Exist.", + ); + } + + d.arrays[name] = d.arrays[name].reverse(); + d.data.arrays = d.arrays; + return { + code: d.util.setCode(data), + arrays: d.arrays, + data: d.data, + }; +}; diff --git a/src/functions/array/arrayShift.js b/src/functions/array/arrayShift.js new file mode 100644 index 000000000..e6bda88d0 --- /dev/null +++ b/src/functions/array/arrayShift.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name] = data.inside.splits; + + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + + data.result = d.arrays[ name ].shift(); + d.data.arrays = d.arrays; + return { + code: d.util.setCode(data), + arrays: d.arrays, + data: d.data, + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayShuffle.js b/src/functions/array/arrayShuffle.js new file mode 100644 index 000000000..4956fa10b --- /dev/null +++ b/src/functions/array/arrayShuffle.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name] = data.inside.splits; + const array = d.arrays[name]; + + for (let i = array.length - 1; i > 0; i--) { + const u = Math.floor(Math.random() * (i + 1)); + [array[i], array[u]] = [array[u], array[i]]; + } + + d.data.arrays = d.arrays; + + return { + code: d.util.setCode(data), + arrays: d.arrays, + data: d.data, + } +} diff --git a/src/functions/array/arraySome.js b/src/functions/array/arraySome.js new file mode 100644 index 000000000..489181c2e --- /dev/null +++ b/src/functions/array/arraySome.js @@ -0,0 +1,23 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, query, queryType = "=="] = data.inside.splits; + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array with name '" + name + "' does not exist.", + ); + } + + data.result = d.arrays[name].some((x) => + ["==", "!=", "<=", ">=", "<", ">"].includes(queryType) + ? eval(d.helpers.checkCondition.solve(`${x}${queryType}${query}`)) + : x[queryType](query), + ); + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/array/arraySort.js b/src/functions/array/arraySort.js new file mode 100644 index 000000000..4f66e2383 --- /dev/null +++ b/src/functions/array/arraySort.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, type = "asc"] = data.inside.splits; + + if (!d.data.arrays[name]) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Array With Name '" + name + "' Does Not Exist.", + ); + } + + d.arrays[name] = d.arrays[name].sort((a, b) => + type === "asc" ? a - b : b - a, + ); + d.data.arrays = d.arrays; + return { + code: d.util.setCode(data), + arrays: d.arrays, + data: d.data, + }; +}; diff --git a/src/functions/array/arraySplice.js b/src/functions/array/arraySplice.js new file mode 100644 index 000000000..abd5a1db4 --- /dev/null +++ b/src/functions/array/arraySplice.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name, index,amount,...elements ] = data.inside.splits; + + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + + data.result = d.arrays[ name ].splice(index,amount,...elements); + d.data.arrays = d.arrays; + return { + code: d.util.setCode( data ), + arrays: d.arrays, + data: d.data, + }; +}; \ No newline at end of file diff --git a/src/functions/array/arrayUnshift.js b/src/functions/array/arrayUnshift.js new file mode 100644 index 000000000..f4e43ad15 --- /dev/null +++ b/src/functions/array/arrayUnshift.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc( d ); + if ( data.err ) return d.error( data.err ); + + const [ name,...elements] = data.inside.splits; + + if ( !d.data.arrays[ name ] ) + { + return d.aoiError.fnError( d, "custom", { inside: data.inside }, "Array with name '" + name + "' does not exist." ); + } + + data.result = d.arrays[ name ].unshift(...elements); + d.data.arrays = d.arrays; + + return { + code: d.util.setCode( data ), + arrays: d.arrays, + data: d.data, + }; +}; \ No newline at end of file diff --git a/src/functions/array/createArray.js b/src/functions/array/createArray.js new file mode 100644 index 000000000..7b264eb54 --- /dev/null +++ b/src/functions/array/createArray.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if(data.err) return d.error(data.err); + + const [name,...elements] = data.inside.splits; + d.arrays[name] = elements; + d.data.arrays = d.arrays; + + return { + code: d.util.setCode(data), + arrays: d.arrays, + data:d.data, + } +} \ No newline at end of file diff --git a/src/functions/array/deleteArray.js b/src/functions/array/deleteArray.js new file mode 100644 index 000000000..6c48cdf24 --- /dev/null +++ b/src/functions/array/deleteArray.js @@ -0,0 +1,14 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name] = data.inside.splits; + delete d.arrays[name]; + d.data.arrays = d.arrays; + + return { + code: d.util.setCode(data), + arrays: d.arrays, + data: d.data, + }; +}; diff --git a/src/functions/awaited/awaitCmdReactions.js b/src/functions/awaited/awaitCmdReactions.js new file mode 100644 index 000000000..c640cb433 --- /dev/null +++ b/src/functions/awaited/awaitCmdReactions.js @@ -0,0 +1,86 @@ +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + let [userfilter, time, reactions, commands, errorMsg = "", awaitData = ""] = + data.inside.splits; + + reactions = reactions.split(","); + + const filter = (r, u) => { + return ( + (userfilter === "everyone" + ? u.id !== d.client.user.id + : u.id === userfilter) && + (reactions.includes(r.emoji.toString()) || + reactions.includes(r.emoji.name) || + reactions.includes(r.emoji.id)) + ); + }; + + time = Time.parse(time)?.ms; + if (!time) + d.aoiError.fnError(d, "custom", {inside}, "Invalid Time Provided In"); + + commands = commands.split(","); + commands.forEach((cmd) => { + if ( + !d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === cmd.toLowerCase(), + ) + ) + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + cmd + " Doesn't Exist", + ); + }); + + if (awaitData !== "") { + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError(d, "custom", {inside: inside.data}, "Invalid Data Provided In"); + } + } + d.message + .awaitReactions({filter, time}) + .then(async (collected) => { + collected = collected.first(); + const index = reactions.findIndex( + (r) => + (r === collected.emoji?.toString()) | (r === collected.emoji?.id) || + r.toLowerCase() === collected.emoji?.name.toLowerCase(), + ); + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === commands[index]?.toLowerCase(), + ); + if (!cmd) + return d.aoiError.fnError( + d, + "custom", + {}, + "Invalid Await Command: " + commands[index], + ); + await d.interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + {...d.data, awaitData: awaitData}, + ); + }) + .catch(async (err) => { + if (errorMsg !== "") { + const emsg = await d.util.errorParser(errorMsg, d); + d.aoiError.makeMessageError(d.client, d.channel, emsg.data ?? emsg, emsg.options); + } else d.aoiError.consoleError("$awaitCmdReactions", err); + }); + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/awaited/awaitComponents.js b/src/functions/awaited/awaitComponents.js new file mode 100644 index 000000000..fcf3e6c3f --- /dev/null +++ b/src/functions/awaited/awaitComponents.js @@ -0,0 +1,87 @@ +module.exports = async (d) => { + const code = d.command.code; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + //----------------------------------------// + let [ + messageID, + userFilter, + customIDs, + cmds, + errorMsg = "", + uses = 1, + data = "", + ] = inside.splits; + if (errorMsg?.trim !== "" && errorMsg) { + errorMsg = await d.util.errorParser(errorMsg, d); + } + if (data !== "") { + try { + data = JSON.parse(data); + } catch (e) { + d.aoiError.fnError(d, "custom", {inside}, "Invalid Data Provided In"); + } + } + cmds = cmds.split(","); + cmds.forEach((x) => { + if ( + d.client.cmd.awaited.find((y) => y.name.toLowerCase() === x.toLowerCase()) + ) { + } else { + d.aoiError.fnError(d, "custom", {}, "Could not find awaitedCommand " + x); + } + }); + customIDs = customIDs.split(","); + //---------------------------------------// + const Component = new d.client.interactionManager.awaitComponents( + { + msgId: messageID, + filter: userFilter, + customIds: customIDs, + cmds: cmds, + errorMessage: errorMsg.data, + uses: uses, + }, + d.client, + data, + ); + d.client.interactionManager.on("messageComponentInteraction", interact); + Component.on("AwaitComponent", async (interaction) => { + const index = cmds[customIDs?.indexOf(interaction.customId)]; + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === index.toLowerCase(), + ); + if (!cmd) return; + await d.interpreter( + d.client, + interaction, + interaction.message.content?.split(" "), + cmd, + d.client.db, + false, + undefined, + {awaitData: Component.data, interaction: interaction}, + ); + }); + + //--------------------------------------// + async function interact(interaction) { + if (Component.uses <= Component.tries) { + d.client.interactionManager.removeListener( + "messageComponentInteraction", + interact, + ); + } else + Component.await( + interaction.message.id, + interaction.user.id, + interaction.customId, + interaction, + ); + } + + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; \ No newline at end of file diff --git a/src/functions/awaited/awaitComponentsUntil.js b/src/functions/awaited/awaitComponentsUntil.js new file mode 100644 index 000000000..0441dfafb --- /dev/null +++ b/src/functions/awaited/awaitComponentsUntil.js @@ -0,0 +1,95 @@ +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + let [channelID, messageID, userFilter, time, customIds, awaitCommands, errorMsg = "", data = "",] = inside.splits; + let chan = await d.util.getChannel(d, channelID); + if (!chan) return d.aoiError.fnError(d, "channel", {inside}); + const msg = await d.util.getMessage(chan, messageID); + if (!msg) return d.aoiError.fnError(d, "message", {inside}); + time = Time.parse(time)?.ms; + + if (!time) + return d.aoiError.fnError( + d, + "custom", + {inside}, + "Invalid Time Provided In", + ); + customIds = customIds.split(","); + errorMsg = await d.util.errorParser( errorMsg, d ); + awaitCommands = awaitCommands.split(","); + awaitCommands.forEach((x) => { + if ( + d.client.cmd.awaited.find((y) => y.name.toLowerCase() === x.toLowerCase()) + ) { + } else { + return d.aoiError.fnError( + d, + "custom", + {}, + `Could Not Found AwaitedCommand:${x} `, + ); + } + }); + if (data !== "") { + try { + data = JSON.parse(data); + } catch (err) { + return d.aoiError.fnError( + d, + "custom", + {inside}, + `Invalid Data Format Provided In ${inside}`, + ); + } + } + const filter = (int) => { + return (userFilter === "everyone" ? true : int.user.id === userFilter) && + customIds.includes(int.customId); + }; + msg + .awaitMessageComponent({filter, time}) + .then(async (int) => { + const index = customIds.indexOf(int.customId); + const cmd = awaitCommands[index]; + if (!cmd) return; + await d.interpreter( + d.client, + { + message: int.message, + guild: int.guild, + channel: int.channel, + member: int.member, + author: int.user, + client: d.client, + }, + int.message?.content.split(" "), + cmd, + d.client.db, + false, + undefined, + {interaction: int, awaitData: data}, + ); + }) + .catch((err) => { + if (errorMsg !== "") { + const extraOptions = errorMsg.options || {}; + delete errorMsg.options; + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + extraOptions, + ); + } else { + d.aoiError.consoleError(d.func, err); + } + }); + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; diff --git a/src/functions/awaited/awaitData.js b/src/functions/awaited/awaitData.js new file mode 100644 index 000000000..9e800826f --- /dev/null +++ b/src/functions/awaited/awaitData.js @@ -0,0 +1,14 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + + const [option] = data.inside.splits; + + try { + data.result = eval(`d.data.awaitData?.${option.addBrackets()}`); + } catch (e) { + data.result = undefined; + } + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/awaited/awaitMessageReactions.js b/src/functions/awaited/awaitMessageReactions.js new file mode 100644 index 000000000..3a7ac1afe --- /dev/null +++ b/src/functions/awaited/awaitMessageReactions.js @@ -0,0 +1,104 @@ +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + let [ + channelID, + messageID, + filter, + time, + reactions, + commands, + errorMsg = "", + data = "", + ] = inside.splits; + reactions = reactions.split(","); + const channel = await d.util.getChannel(d, channelID); + if (!channel) d.aoiError.fnError(d, "channel", {inside}); + const m = await d.util.getMessage(channel, messageID); + if (!m) d.aoiError.fnError(d, "message", {inside}); + reactions.forEach((x) => { + m.react(x).catch((err) => + d.aoiError.fnError(d, "custom", {}, err.addBrackets()), + ); + }); + + filter = (r, u) => { + return ( + (filter === "everyone" ? true : u.id === filter) && + (reactions.includes(r._emoji.toString()) || + reactions.includes(r._emoji.name) || + reactions.includes(r._emoji.id)) + ); + }; + time = Time.parse(time)?.ms; + if (!time) + d.aoiError.fnError(d, "custom", {inside}, "Invalid Time Provided In"); + + commands = commands.split(","); + commands.forEach((cmd) => { + if ( + !d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === cmd.toLowerCase(), + ) + ) + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + cmd + " Doesn't Exist", + ); + }); + + if (data !== "") { + try { + data = JSON.parse(data); + } catch (e) { + d.aoiError.fnError(d, "custom", {inside}, "Invalid Data Provided In"); + } + } + m.awaitReactions({filter, time}) + .then(async (collected) => { + collected = collected.first(); + const index = reactions.findIndex( + (r) => + reactions.includes(collected.emoji.toString()) || + reactions.includes(collected.emoji.name) || + reactions.includes(collected.emoji.id), + ); + const cmd = d.client.awaited.find( + (x) => x.name.toLowerCase() === commands[index]?.toLowerCase(), + ); + if (!cmd) + return d.aoiError.fnError( + d, + "custom", + {}, + "Invalid Await Command: " + commands[index], + ); + await d.interpreter(d.client, m, [], cmd, d.client.db, false, undefined, { + ...d.data, + awaitData: data, + }); + }) + .catch(async (err) => { + console.error(err); + if (errorMsg !== "") { + errorMsg = await d.util.errorParser(errorMsg, d); + const extraOptions = errorMsg.options; + delete errorMsg.options; + d.aoiError.makeMessageError( + d.client, + channel, + errorMsg.data ?? errorMsg, + {...extraOptions}, + ); + } else d.aoiError.consoleError("$awaitMessageReactions", err); + }); + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; \ No newline at end of file diff --git a/src/functions/awaited/awaitMessages.js b/src/functions/awaited/awaitMessages.js new file mode 100644 index 000000000..bdbf9d7c9 --- /dev/null +++ b/src/functions/awaited/awaitMessages.js @@ -0,0 +1,91 @@ +const {Time} = require("../../utils/helpers/customParser.js"); +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + let [channelID, userFilter, time, replies, cmds, errorMsg = "", data = "{}", dm,] = inside.splits; + try { + data = JSON.parse(data); + } catch (e) { + d.aoiError.fnError(d, "custom", {inside}, "Invalid Data Provided In"); + } + + userFilter = userFilter === "everyone" ? userFilter : userFilter.split(","); + time = Time.parse(time)?.ms; + if (!time) + d.aoiError.fnError(d, "custom", {inside}, "Invalid Time Provided In"); + cmds = cmds.split(","); + cmds.forEach((x) => { + if ( + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ) + ) + return d.aoiError.fnError( + d, + "custom", + {}, + "Couldn't Find Awaited Command: " + x, + ); + }); + replies = replies.split(","); + let channel; + if (dm) { + const user = await d.util.getUser(d, dm); + if (!user.dmChannel) { + channel = await user.createDM(); + } else { + channel = user.dmChannel; + } + } else { + channel = await d.util.getChannel(d, channelID); + } + const filter = (m) => { + return ( + (userFilter === "everyone" + ? true + : userFilter.some((id) => id === m.author.id)) && + (replies.length === 1 && replies[0] === "everything" + ? true + : replies.includes(m.content.toLowerCase())) + ); + }; + channel + .awaitMessages({filter, time, max: 1, errors: ["time"]}) + .then(async (collected) => { + collected = collected.first(); + const c = + cmds[ + replies.length === 1 && replies[0] === "everything" + ? 0 + : replies.indexOf(collected.content.toLowerCase()) + ]; + const cmd = d.client.cmd.awaited.find((x) => x.name.toLowerCase() === c); + await Interpreter( + d.client, + collected, + collected.content.split(" "), + cmd, + d.client.db, + false, + undefined, + {...d.data, awaitData: data}, + ); + }) + .catch(async (_) => { + if (errorMsg !== "") { + errorMsg = await d.util.errorParser(errorMsg, d); + d.aoiError.makeMessageError( + d.client, + channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + ); + } + }); + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; diff --git a/src/functions/awaited/componentCollector.js b/src/functions/awaited/componentCollector.js new file mode 100644 index 000000000..8274b8523 --- /dev/null +++ b/src/functions/awaited/componentCollector.js @@ -0,0 +1,92 @@ +const {Time} = require("../../utils/helpers/customParser"); + +module.exports = async (d) => { + const code = d.command.code; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + //----------------------------------------// + let [messageID, filter, time, customIDs, cmds, errorMsg = {}, endcommand = "", awaitData = "{}",] = inside.splits; + time = Time.parse(time)?.ms; + if (!time) + return d.aoiError.fnError( + d, + "custom", + {inside}, + `Invalid Time provided In`, + ); + errorMsg = await d.util.errorParser( errorMsg, d ); + errorMsg = errorMsg.data ?? errorMsg; + awaitData = JSON.parse(awaitData); + cmds = cmds.split(","); + cmds.forEach((x) => { + if (d.client.cmd.awaited.find((y) => y.name === x)) { + undefined; + } else { + d.aoiError.fnError(d, "custom", {}, `Could not find awaitedCommand ${x}`); + } + }); + customIDs = customIDs.split(","); + //---------------------------------------// + + const button = new d.client.interactionManager.ComponentCollector( + {msgId: messageID, filter, time, customIDs, cmds, errorMessage: errorMsg}, + d.client, + ); + const endcmd = d.client.cmd.awaited.find((x) => x.name === endcommand); + + //---------------------------------------// + d.client.interactionManager.on( + "messageComponentInteraction", + async (data) => { + button.start(data.message.id, data.author.id, data.customId, data); + }, + ); + button.on("ItemFound", async (data) => { + const cmd = d.client.cmd.awaited.find( + (x) => x.name === cmds[customIDs.indexOf(data.customId)], + ); + if (!cmd) return; + await d.interpreter( + d.client, + { + author: data.author, + message: data.message, + channel: data.channel, + guild: data.guild, + member: data.member, + client: d.client, + }, + [], + cmd, + undefined, + undefined, + undefined, + { + interaction: data, + awaitData: awaitData, + }, + ); + }); + if (endcommand !== "") { + button.once("CustomCollectorOff", async (data) => { + await d.interpreter( + d.client, + {}, + [], + endcmd, + undefined, + undefined, + undefined, + { + interaction: data[data.length - 1], + endData: data, + awaitData: awaitData, + }, + ); + }); + } + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; \ No newline at end of file diff --git a/src/functions/awaited/reactionCollector.js b/src/functions/awaited/reactionCollector.js new file mode 100644 index 000000000..82421d440 --- /dev/null +++ b/src/functions/awaited/reactionCollector.js @@ -0,0 +1,118 @@ +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, messageID, userFilters, time, reactions, awaits, removeReaction = "true", awaitData = "{}", endAwait,] = data.inside.splits; + + const channel = d.util.getChannel(d, channelID); + if (!channel) + return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const msg = await d.util.getMessage(channel, messageID); + if (!msg) return d.aoiError.fnError(d, "message", {inside: data.inside}); + + time = isNaN(time) ? Time.parse(time)?.ms : Number(time); + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Data Is Provided In", + ); + } + userFilters = + userFilters === "everyone" + ? "everyone" + : userFilters.split(",").map((x) => x.trim()); + reactions = reactions.split(",").map((x) => x.trim()); + awaits = awaits.split(",").map((x) => x.trim()); + + if ( + awaits.some( + (y) => + !d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === y.toLowerCase().trim(), + ), + ) + ) { + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Awaited Commands Provided In", + ); + } + + const filter = (r, u) => + (userFilters === "everyone" + ? u.id !== d.client.user.id + : userFilters.includes(u.id)) && + reactions.includes(r.emoji.toString() || r.emoji.id); + + reactions.forEach((x) => { + msg.react(x).catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To React With Reaction: ${x} With Reason: ${err}`, + ); + }); + }); + + const collector = msg.createReactionCollector({filter, time}); + + collector.on("collect", async (r, u) => { + if (removeReaction === "true") { + await r.users.remove(u.id); + } + + const index = + reactions.indexOf(r.emoji.id) === -1 + ? reactions.indexOf(r.emoji.toString()) + : reactions.indexOf(r.emoji.id); + + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === awaits[index].toLowerCase(), + ); + if (!cmd) return; + + await d.interpreter( + d.client, + d.message, + [msg.id], + cmd, + d.client.db, + false, + undefined, + {awaitData}, + ); + }); + + if (endAwait) { + collector.on("finish", async (r) => { + const endCmd = d.client.cmd.awaited.find( + (x) => + x.name.toLowerCase() === endAwait.trim().addBrackets().toLowerCase(), + ); + if (!endCmd) return; + await d.interpreter( + d.client, + d.message, + [msg.id], + d.client.db, + false, + undefined, + {awaitData}, + ); + }); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/broadcastEval.js b/src/functions/client/broadcastEval.js new file mode 100644 index 000000000..3bc97572d --- /dev/null +++ b/src/functions/client/broadcastEval.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [func] = data.inside.splits; + + function evalfunc(client, { func }) { + return eval(func); + } + + if (!d.client.shard) return d.aoiError.fnError(d,"custom", {}, "ClientShard Class is Not Initialised"); + + data.result = await d.client.shard.broadcastEval(evalfunc, { + context: { func: func }, + }); + + data.result = data.result.join(" , "); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/clientID.js b/src/functions/client/clientID.js new file mode 100644 index 000000000..6fcadaa42 --- /dev/null +++ b/src/functions/client/clientID.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + data.result = d.client.user.id + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/clientLeave.js b/src/functions/client/clientLeave.js new file mode 100644 index 000000000..fbeb09912 --- /dev/null +++ b/src/functions/client/clientLeave.js @@ -0,0 +1,20 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + data.result = guild.leave().catch((_err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Leave The Guild With Reason" + _err, + ); + }); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/clientMutualGuilds.js b/src/functions/client/clientMutualGuilds.js new file mode 100644 index 000000000..ac4940da8 --- /dev/null +++ b/src/functions/client/clientMutualGuilds.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, sep = ' , '] = data.inside.splits; + + const mutual = d.client.guilds.cache.filter(x => x.members.cache.has(userID)); + + data.result = mutual.map(x => x.id).join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/clientOwnerIDs.js b/src/functions/client/clientOwnerIDs.js new file mode 100644 index 000000000..20e9cfeb7 --- /dev/null +++ b/src/functions/client/clientOwnerIDs.js @@ -0,0 +1,16 @@ +const { Team } = require("discord.js"); +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [separator = " , "] = data.inside.splits; + + const owner = (await d.client.application.fetch()).owner; + if (owner instanceof Team) { + data.result = owner.members.map((x) => x.id).join(separator); + } else { + data.result = owner.id; + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/clientPrefixes.js b/src/functions/client/clientPrefixes.js new file mode 100644 index 000000000..34d218440 --- /dev/null +++ b/src/functions/client/clientPrefixes.js @@ -0,0 +1,13 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + if (Array.isArray(d.client.prefix)) { + data.result = d.client.prefix.join(" , "); + } else { + data.result = d.client.prefix; + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/clientToken.js b/src/functions/client/clientToken.js new file mode 100644 index 000000000..8d567f748 --- /dev/null +++ b/src/functions/client/clientToken.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + data.result = d.client.token + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/clientTyping.js b/src/functions/client/clientTyping.js new file mode 100644 index 000000000..d01c6e85d --- /dev/null +++ b/src/functions/client/clientTyping.js @@ -0,0 +1,9 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = await d.channel.sendTyping(); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/createCache.js b/src/functions/client/createCache.js new file mode 100644 index 000000000..76b95cb8b --- /dev/null +++ b/src/functions/client/createCache.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + const [type, name, options] = inside.splits; + + d.client.cacheManager.createCache(type, name, options); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/client/djsEval.js b/src/functions/client/djsEval.js new file mode 100644 index 000000000..2a377ca23 --- /dev/null +++ b/src/functions/client/djsEval.js @@ -0,0 +1,27 @@ +module.exports = async d => { + const {client, message, msg, author, guild, channel, member, mentions, reactions, util, aoiError, args} = d; + const data = d.util.aoiFunc(d); + + const __fields__ = data.inside.splits; + let __output__ = "false" + if (["true", "false"].includes(__fields__[__fields__.length - 1])) { + __output__ = __fields__.pop(); + } + let __evaled__; + + try { + __evaled__ = await eval(__fields__.join(";").addBrackets()); + } catch (e) { + d.aoiError.fnError(d, "custom", {}, e); + } + + data.result = (__output__ === "true" ? ( + typeof __evaled__ === "object" ? require('util').inspect(__evaled__, {depth: 0}).deleteBrackets() : ( + typeof __evaled__ === "string" ? __evaled__.deleteBrackets() : __evaled__ + ) + ) : "") + + return { + code: data.code.replaceLast(`${d.func}${data.inside}`, data.result) + } +} \ No newline at end of file diff --git a/src/functions/client/eval.js b/src/functions/client/eval.js new file mode 100644 index 000000000..a5bf761f2 --- /dev/null +++ b/src/functions/client/eval.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [code, returnCode = "false", sendMessage = "true", returnExecution = "false", returnID = "false"] = data.inside.splits; + + const options = { + name: "eval", + code: code.addBrackets(), + }; + + let result = await d.interpreter(d.client, d.message, d.args, options, d.client.db, returnCode === "true", undefined, {}, undefined, undefined, returnExecution === "true", returnID === "true", sendMessage === "true"); + + data.result = returnCode === "true" ? ([returnID, returnExecution].join(",") === "false,false" ? result.code : require('util').inspect(result)) : undefined; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/exec.js b/src/functions/client/exec.js new file mode 100644 index 000000000..624342149 --- /dev/null +++ b/src/functions/client/exec.js @@ -0,0 +1,14 @@ +const cld = require('child_process'); +module.exports = async d => { + const data = d.util.aoiFunc(d); + + try { + data.result = await cld.execSync(data.inside.inside?.addBrackets()).toString(); + } catch (e) { + data.result = e + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/executionTime.js b/src/functions/client/executionTime.js new file mode 100644 index 000000000..3e363985d --- /dev/null +++ b/src/functions/client/executionTime.js @@ -0,0 +1,2 @@ +module.exports = async d => { +} \ No newline at end of file diff --git a/src/functions/client/fetch.js b/src/functions/client/fetch.js new file mode 100644 index 000000000..8f791705d --- /dev/null +++ b/src/functions/client/fetch.js @@ -0,0 +1,75 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [method, query, ...properties] = data.inside.splits; + + let result = {}; + + try { + switch (method) { + case "message": + result = await d.util.fetchMessage(d.channel, query); + break; + + case "channel": + result = await d.util.fetchChannel(d.channel, query); + break; + + case "user": + result = await d.util.fetchUser(d.channel, query); + break; + + case "invite": + result = await d.client.fetchInvite(d.channel, query); + break; + + case "guildPreview": + result = await d.client.fetchGuildPreview(query); + break; + + case "guildTemplate": + result = await d.client.fetchGuildTemplate(query); + break; + + case "premiumStickerPacks": + result = await d.client.fetchPremiumStickerPacks(); + break; + + case "sticker": + result = await d.client.fetchSticker(query); + break; + + case "guildCommand": + const guildID = await d.util.getGuild(d, query); + result = await guildID.commands.fetch(properties.join(' ')); + break; + + case "webhook": + result = await d.client.fetchWebhook(query); + break; + + case "application": + result = await d.client.application.fetch(query); + break; + } + + for (const property of properties) { + if (property && result[property] !== undefined) { + result = result[property]; + } else { + result = ""; + break; + } + } + + data.result = JSON.stringify(result, null, 2); + } catch (e) { + d.aoiError.fnError(d, "custom", {}, "Failed To Fetch With Reason: " + e); + data.result = ""; + } + + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/client/fetchClientValues.js b/src/functions/client/fetchClientValues.js new file mode 100644 index 000000000..dca8d525d --- /dev/null +++ b/src/functions/client/fetchClientValues.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [func] = data.inside.splits; + if (!d.client.shard) return d.aoiError.fnError(d, 'custom', {}, 'ClientShard Class is Not Initialised'); + + data.result = await d.client.shard.fetchClientValues(func); + + return { + code: d.util.setCode(data), + } +} \ No newline at end of file diff --git a/src/functions/client/getClientInvite.js b/src/functions/client/getClientInvite.js new file mode 100644 index 000000000..be0d86c2e --- /dev/null +++ b/src/functions/client/getClientInvite.js @@ -0,0 +1,18 @@ +const {Perms} = require('../../utils/Constants.js'); +const {PermissionFlagsBits, OAuth2Scopes} = require('discord.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + let [...perms] = data.inside.splits; + + if (perms.some(perm => !Perms[perm] && !PermissionFlagsBits[perm] && isNaN(perm))) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Perm(s) Provided In'); + perms = perms.map(perm => Perms[perm] || PermissionFlagsBits[perm] || perm); + data.result = d.client.generateInvite({ + scopes: [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands], + permissions: perms + }) + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/client/killClient.js b/src/functions/client/killClient.js new file mode 100644 index 000000000..c54191743 --- /dev/null +++ b/src/functions/client/killClient.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + d.client.destroy(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/log.js b/src/functions/client/log.js new file mode 100644 index 000000000..85d5dab33 --- /dev/null +++ b/src/functions/client/log.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [msg] = data.inside.splits; + + console.log(msg.addBrackets()); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/nodeVersion.js b/src/functions/client/nodeVersion.js new file mode 100644 index 000000000..3c9ffb08f --- /dev/null +++ b/src/functions/client/nodeVersion.js @@ -0,0 +1,8 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = process.version; + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/onlyClientPerms.js b/src/functions/client/onlyClientPerms.js new file mode 100644 index 000000000..7f557c9ae --- /dev/null +++ b/src/functions/client/onlyClientPerms.js @@ -0,0 +1,40 @@ +const {Perms} = require("../../utils/Constants.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [...stuffs] = data.inside.splits; + const err = stuffs.pop(); + + if (stuffs.some((x) => !Perms[x])) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Permission(s) Provided In", + ); + + const BotPerms = d.guild.members.me.permissions; + if (BotPerms.has(Perms.administrator)) { + } else if (!stuffs.every((x) => BotPerms.has(Perms[x.trim()]))) { + error = true; + if (err?.trim() === "") { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error, + }; +}; diff --git a/src/functions/client/packageDependencies.js b/src/functions/client/packageDependencies.js new file mode 100644 index 000000000..ee0e87ba9 --- /dev/null +++ b/src/functions/client/packageDependencies.js @@ -0,0 +1,8 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = Object.keys(require("../../../package.json").dependencies).join(", ") + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/packageVersion.js b/src/functions/client/packageVersion.js new file mode 100644 index 000000000..6b44998a1 --- /dev/null +++ b/src/functions/client/packageVersion.js @@ -0,0 +1,10 @@ +const {version} = require('../../../package.json'); + +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = version; + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/reboot.js b/src/functions/client/reboot.js new file mode 100644 index 000000000..c86848b40 --- /dev/null +++ b/src/functions/client/reboot.js @@ -0,0 +1,16 @@ +module.exports = d => { + const {code} = d.util.aoiFunc(d); + + try { + process.on("exit", () => { + require("child_process").spawn(process.argv.shift(), process.argv, { + cwd: process.cwd(), + detached: true, + stdio: "inherit", + }); + }); + process.exit(); + } catch (e) { + return d.aoiError.fnError(d, 'custom', {}, `Failed To Restart With Reason: ${e}`); + } +} \ No newline at end of file diff --git a/src/functions/client/setClientAvatar.js b/src/functions/client/setClientAvatar.js new file mode 100644 index 000000000..f3dc838e3 --- /dev/null +++ b/src/functions/client/setClientAvatar.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [avatar] = data.inside.splits; + + d.client.user.setAvatar(avatar.addBrackets()).catch(err => { + d.aoiError.fnError(d, 'custom', {}, `Failed To Set Client Avatar To "${avatar.addBrackets()}" With Reason: ${err}`); + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/client/setClientName.js b/src/functions/client/setClientName.js new file mode 100644 index 000000000..6d362b0f7 --- /dev/null +++ b/src/functions/client/setClientName.js @@ -0,0 +1,16 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [username] = data.inside.splits; + + d.client.user.setUsername(username.addBrackets()) + + .catch(err => { + d.aoiError.fnError(d, 'custom', {}, `Failed To Set Client Username To "${username.addBrackets()}" With Reason: ${err}`); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/client/setStatus.js b/src/functions/client/setStatus.js new file mode 100644 index 000000000..3a4161ebe --- /dev/null +++ b/src/functions/client/setStatus.js @@ -0,0 +1,40 @@ +const {ActivityTypeAvailables} = require("../../utils/Constants"); +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, type = "playing", status = "online", url, afk = "false"] = + data.inside.splits; + + const lowercaseType = type.toLowerCase(); + + const state = lowercaseType === "custom" ? { state: name.addBrackets() } : {}; + + try { + const typeValue = ActivityTypeAvailables[lowercaseType] || ActivityTypeAvailables.playing; + + d.client.user.setPresence({ + status, + activities: [ + { + name: name.addBrackets(), + ...state, + type: typeValue, + url: url?.addBrackets(), + }, + ], + afk: afk === "true", + }); + } catch (err) { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Set Status With Reason: " + err, + ); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/client/shutdown.js b/src/functions/client/shutdown.js new file mode 100644 index 000000000..f4eeba897 --- /dev/null +++ b/src/functions/client/shutdown.js @@ -0,0 +1,4 @@ +module.exports = async (d) => { + d.client.destroy(); + process.exit(); +}; \ No newline at end of file diff --git a/src/functions/client/updateCommands.js b/src/functions/client/updateCommands.js new file mode 100644 index 000000000..642a5c402 --- /dev/null +++ b/src/functions/client/updateCommands.js @@ -0,0 +1,10 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + if (!d.client.loader) return d.aoiError.fnError(d, 'custom', {}, 'LoadCommands Class Is Not Initiated'); + await d.client.loader.update(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/database/advanceCooldown.js b/src/functions/database/advanceCooldown.js new file mode 100644 index 000000000..f8a998ff4 --- /dev/null +++ b/src/functions/database/advanceCooldown.js @@ -0,0 +1,50 @@ +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time, id, errorObject = ""] = data.inside.splits; + let error; + + let cooldown = await d.client.db.get("__aoijs_vars__", "cooldown", id); + cooldown = cooldown?.value; + if (!cooldown) { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set("__aoijs_vars__", "cooldown", id, cooldown); + } else if (Date.now() < cooldown) { + if (errorObject.trim() === "") { + } else { + const {object, humanize, toString} = Time.format(cooldown - Date.now()); + errorObject = errorObject + .replaceAll("%time%", humanize()) + .replaceAll("%year%", object.years) + .replaceAll("%month%", object.months) + .replaceAll("%week%", object.weeks) + .replaceAll("%day%", object.days) + .replaceAll("%hour%", object.hours) + .replaceAll("%min%", object.minutes) + .replaceAll("%sec%", object.seconds) + .replaceAll("%ms%", object.ms) + .replaceAll("%fullTime%", toString()); + + errorObject = await d.util.errorParser(errorObject); + await d.aoiError.makeMessageError( + d.client, + d.channel, + errorObject.data ?? errorObject, + errorObject.options, + d + ); + } + error = true; + } else { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set("__aoijs_vars__", "cooldown", id, cooldown); + } + + return { + code: d.util.setCode(data), + error, + }; +}; diff --git a/src/functions/database/channelCooldown.js b/src/functions/database/channelCooldown.js new file mode 100644 index 000000000..331715364 --- /dev/null +++ b/src/functions/database/channelCooldown.js @@ -0,0 +1,63 @@ +const {Time} = require("../../utils/helpers/customParser.js"); +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time, errorObject = ""] = data.inside.splits; + let error; + + let cooldown = await d.client.db.get( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.channel.id}`, + ); + + if (!cooldown) { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.channel.id}`, + cooldown, + ); + } else if (Date.now() > cooldown) { + if (errorObject.trim() === "") { + } else { + const {object, humanize, toString} = Time.format(cooldown - Date.now()); + errorObject = errorObject + .replaceAll("%time%", humanize()) + .replaceAll("%year%", object.years) + .replaceAll("%month%", object.months) + .replaceAll("%week%", object.weeks) + .replaceAll("%day%", object.days) + .replaceAll("%hour%", object.hours) + .replaceAll("%min%", object.minutes) + .replaceAll("%sec%", object.seconds) + .replaceAll("%ms%", object.ms) + .replaceAll("%fullTime%", toString()); + + errorObject = await d.util.errorParser(errorObject); + await d.aoiError.makeMessageError( + d.client, + d.channel, + errorObject.data ?? errorObject, + errorObject.options, + d + ); + } + error = true; + } else { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.channel.id}`, + cooldown, + ); + } + + return { + code: d.util.setCode(data), + error, + }; +}; diff --git a/src/functions/database/cooldown.js b/src/functions/database/cooldown.js new file mode 100644 index 000000000..ef19bd4e0 --- /dev/null +++ b/src/functions/database/cooldown.js @@ -0,0 +1,65 @@ +const {Time} = require("../../utils/helpers/customParser.js"); +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [time, errorObject = ""] = inside.splits; + let error; + + let cooldown = await d.client.db.get( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.author.id}_${d.guild.id || "dm"}`, + ); + cooldown = cooldown?.value; + + if (!cooldown) { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.author.id}_${d.guild.id || "dm"}`, + cooldown, + ); + } else if (Date.now() < cooldown) { + if (errorObject.trim() === "") { + } else { + const {object, humanize, toString} = Time.format(cooldown - Date.now()); + errorObject = errorObject + .replaceAll("%time%", humanize()) + .replaceAll("%year%", object.years) + .replaceAll("%month%", object.months) + .replaceAll("%week%", object.weeks) + .replaceAll("%day%", object.days) + .replaceAll("%hour%", object.hours) + .replaceAll("%min%", object.minutes) + .replaceAll("%sec%", object.seconds) + .replaceAll("%ms%", object.ms) + .replaceAll("%fullTime%", toString()); + + errorObject = await d.util.errorParser(errorObject, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorObject.data ?? errorObject, + errorObject?.options, + d + ); + } + error = true; + } else { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.author.id}_${d.guild.id || "dm"}`, + cooldown, + ); + } + return { + code: d.util.setCode({function: d.func, code, inside}), + error, + }; +}; diff --git a/src/functions/database/createTemporaryVar.js b/src/functions/database/createTemporaryVar.js new file mode 100644 index 000000000..e9df2db1d --- /dev/null +++ b/src/functions/database/createTemporaryVar.js @@ -0,0 +1,24 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + const [table, ...vars] = inside.splits; + + vars.forEach(x => { + const [name, value] = x.split(":"); + d.client.variableManager.add( + { + name: name.addBrackets(), + value: value.addBrackets(), + table: table === "" ? d.client.db.tables[0] : table.addBrackets(), + }, + table === "" ? d.client.db.tables[0] : table, + ); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/database/deleteVar.js b/src/functions/database/deleteVar.js new file mode 100644 index 000000000..7663ef32b --- /dev/null +++ b/src/functions/database/deleteVar.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + const [variable, id, table = d.client.db.tables[0]] = inside.splits; + + if (!d.client.variableManager.has(variable.addBrackets(), table)) return d.aoiError.fnError(d, "custom", {}, `Variable: ${variable.addBrackets()} Doesn't Exist In Table: ${table}`); + d.client.db.delete(table, variable, id); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/database/getChannelVar.js b/src/functions/database/getChannelVar.js new file mode 100644 index 000000000..d1ea8f3de --- /dev/null +++ b/src/functions/database/getChannelVar.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, channelID = d.channel?.id, table = d.client.db.tables[0]] = data.inside.splits; + varname = varname.addBrackets(); + + if (!d.client.variableManager.has(varname, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${varname}" Not Found`); + + data.result = (await d.client.db.get(table, varname, channelID))?.value || d.client.variableManager.get(varname, table)?.default; + + data.result = typeof data.result === 'object' ? JSON.stringify(data.result) : data.result; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/database/getGlobalUserVar.js b/src/functions/database/getGlobalUserVar.js new file mode 100644 index 000000000..512a8c797 --- /dev/null +++ b/src/functions/database/getGlobalUserVar.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, userID = d.author?.id, table = d.client.db.tables[0]] = data.inside.splits; + varname = varname.addBrackets(); + + if (!d.client.variableManager.has(varname, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${varname}" Not Found`); + + data.result = (await d.client.db.get(table, varname, userID))?.value || d.client.variableManager.get(varname, table)?.default; + + data.result = typeof data.result === 'object' ? JSON.stringify(data.result) : data.result; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/database/getGuildVar.js b/src/functions/database/getGuildVar.js new file mode 100644 index 000000000..1845d7bb8 --- /dev/null +++ b/src/functions/database/getGuildVar.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, guildID = d.guild?.id, table = d.client.db.tables[0]] = data.inside.splits; + varname = varname.addBrackets(); + + if (!d.client.variableManager.has(varname, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${varname}" Not Found`); + + data.result = + (await d.client.db.get(table, varname, guildID))?.value || + d.client.variableManager.get(varname, table)?.default; + + data.result = typeof data.result === 'object' ? JSON.stringify(data.result) : data.result; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/database/getLeaderboardInfo.js b/src/functions/database/getLeaderboardInfo.js new file mode 100644 index 000000000..b5d56e63d --- /dev/null +++ b/src/functions/database/getLeaderboardInfo.js @@ -0,0 +1,74 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [variable, id, type = "guild", format, table = d.client.db.tables[0]] = + data.inside.splits; + + if (!d.client.variableManager.has(variable, table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable "${variable}" Not Found` + ); + + let key = null; + let cache = null; + let user = null; + if (type === "guild") { + key = `${variable.addBrackets()}_${`${id}_${ + d.guild?.id === "undefined" ? "dm" : d.guild?.id + }`}`; + cache = await d.util.getGuild(d, id); + user = + typeof cache === "undefined" || Object.keys(cache).length === 0 + ? await d.util.getUser(d, id) + : undefined; + } else if (type === "global") { + key = `${variable.addBrackets()}_${id}`; + cache = await d.util.getGuild(d, id); + user = + typeof cache === "undefined" || Object.keys(cache).length === 0 + ? await d.util.getUser(d, id) + : undefined; + } else if (type === "message" || type === "channel") { + key = `${variable.addBrackets()}_${id}`; + } else { + d.aoiError.fnError(d, "custom", { inside: data.inside }, `type`); + } + const all = await d.client.db.all(table, (data) => + data.key.startsWith(variable.deleteBrackets()) && + data.key.split("_").length === key.split("_").length && ( + type === "guild" ? data.key.split("_")[2] === key.split("_")[2] : true + ) + ); + + + + + + switch (format) { + case "top": + data.result = all.sort((a, b) => b.value - a.value).findIndex((x) => x.key === key) + 1 || 0; + break; + case "value": + data.result = all.find(x => x.key === key).value || 0; + break; + case "id": + data.result = user.id || null; + break; + case "username": + data.result = user.username || null; + break; + case "tag": + data.result = user.tag || '0000'; + break; + default: + data.result = null; + } + + return { + code: d.util.setCode(data), + }; + }; \ No newline at end of file diff --git a/src/functions/database/getMessageVar.js b/src/functions/database/getMessageVar.js new file mode 100644 index 000000000..093c875b7 --- /dev/null +++ b/src/functions/database/getMessageVar.js @@ -0,0 +1,27 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, messageID = d.message?.id, table = d.client.db.tables[0]] = + data.inside.splits; + varname = varname.addBrackets(); + + if (!d.client.variableManager.has(varname, table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable "${varname}" Not Found`, + ); + + data.result = + (await d.client.db.get(table, varname, messageID))?.value || + d.client.variableManager.get(varname, table)?.default; + + data.result = + typeof data.result === "object" ? JSON.stringify(data.result) : data.result; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/getUserVar.js b/src/functions/database/getUserVar.js new file mode 100644 index 000000000..db607d8d2 --- /dev/null +++ b/src/functions/database/getUserVar.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, userID = d.author?.id, guildID = d.guild?.id || 'dm', table = d.client.db.tables[0]] = data.inside.splits; + varname = varname.addBrackets(); + + if (!d.client.variableManager.has(varname, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${varname}" Not Found`); + + data.result = + (await d.client.db.get(table, varname, `${userID}_${guildID}`))?.value || + d.client.variableManager.get(varname, table)?.default; + + data.result = typeof data.result === 'object' ? JSON.stringify(data.result) : data.result; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/database/getVar.js b/src/functions/database/getVar.js new file mode 100644 index 000000000..a2290171c --- /dev/null +++ b/src/functions/database/getVar.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, table = d.client.db.tables[0]] = data.inside.splits; + varname = varname.addBrackets(); + + if (!d.client.variableManager.has(varname, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${varname}" Not Found`); + + data.result = + (await d.client.db.get(table, varname))?.value || + d.client.variableManager.get(varname, table)?.default; + + data.result = typeof data.result === 'object' ? JSON.stringify(data.result) : data.result; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/database/globalCooldown.js b/src/functions/database/globalCooldown.js new file mode 100644 index 000000000..7fdc70337 --- /dev/null +++ b/src/functions/database/globalCooldown.js @@ -0,0 +1,67 @@ +const { Time } = require("../../utils/helpers/customParser.js"); +module.exports = async (d) => { + const { code } = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [time, errorObject = ""] = inside.splits; + let error; + + let cooldown = await d.client.db.get( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.author.id}`, + ); + cooldown = cooldown?.value; + + if (!cooldown) { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.author.id}`, + cooldown, + ); + } else if (Date.now() < cooldown) { + if (errorObject.trim() === "") { + } else { + const { object, humanize, toString } = Time.format( + cooldown - Date.now(), + ); + errorObject = errorObject + .replaceAll("%time%", humanize()) + .replaceAll("%year%", object.years) + .replaceAll("%month%", object.months) + .replaceAll("%week%", object.weeks) + .replaceAll("%day%", object.days) + .replaceAll("%hour%", object.hours) + .replaceAll("%min%", object.minutes) + .replaceAll("%sec%", object.seconds) + .replaceAll("%ms%", object.ms) + .replaceAll("%fullTime%", toString()); + + errorObject = await d.util.errorParser(errorObject); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorObject.data ?? errorObject, + errorObject.options, + d, + ); + } + error = true; + } else { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + "__aoijs_vars__", + "cooldown", + `${d.command.name}_${d.author.id}`, + cooldown, + ); + } + return { + code: d.util.setCode({ function: d.func, code, inside }), + error, + }; +}; diff --git a/src/functions/database/globalUserLeaderBoard.js b/src/functions/database/globalUserLeaderBoard.js new file mode 100644 index 000000000..f95a02526 --- /dev/null +++ b/src/functions/database/globalUserLeaderBoard.js @@ -0,0 +1,93 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let c = Date.now(); + const [ + variable, + type = "asc", + custom = `{top}. {username}: {value:,}`, + list = 10, + page = 1, + table = d.client.db.tables[0], + hideNegativeValue = false, + hideZeroValue = false + ] = data.inside.splits; + + if (!d.client.variableManager.has(variable, table)) + return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" Not Found`); + + let v = d.client.variableManager.get(variable, table); + + let db = await d.client.db.all(table, (data) => + data.key.startsWith(variable.deleteBrackets()) && data.key.split("_").length === 2, + ); + if (d.client.db.type === "aoi.db") + db.sort((a, b) => Number(a.value) - Number(b.value)); + else db.sort((a, b) => Number(y.data.value) - Number(x.data.value)); + + if (type === "desc") db = db.reverse(); + + if (hideNegativeValue === "true") db = db.filter(x => x.value >= 0); + if (hideZeroValue === "true") db = db.filter(x => x.value != 0); + + let y = 0; + let value; + let content = []; + + for (const Data of db) { + let user; + if (d.client.db.type === "aoi.db") value = Number(Data.value); + else value = Number(Data.data.value); + user = await d.util.getUser(d, Data.key.split("_")[1]); + + if (user) { + y++; + let text = custom + .replaceAll(`{top}`, y) + .replaceAll("{id}", user.id) + .replaceAll("{tag}", user.tag) + .replaceAll(`{username}`, user.username.removeBrackets()) + .replaceAll(`{value}`, value); + + if (text.includes("{value:")) { + let sep = text.split("{value:")[1].split("}")[0]; + text = text.replaceAll(`{value:${sep}}`, value.toLocaleString().replaceAll(",", sep)); + } + + if (text.includes("{execute:")) { + let ins = text.split("{execute:")[1].split("}")[0]; + const awaited = d.client.cmd.awaited.find((c) => c.name === ins); + + if (!awaited) + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + ` Invalid awaited command '${ins}' in`, + ); + + const CODE = await d.interpreter( + d.client, + { + guild: d.message.guild, + channel: d.message.channel, + author: user, + }, + d.args, + awaited, + undefined, + true, + ); + text = text.replaceAll(`{execute:${ins}}`, CODE); + } + + content.push(text); + } + } + + data.result = content.slice(page * list - list, page * list).join("\n"); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/database/guildLeaderBoard.js b/src/functions/database/guildLeaderBoard.js new file mode 100644 index 000000000..d51a21672 --- /dev/null +++ b/src/functions/database/guildLeaderBoard.js @@ -0,0 +1,90 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [ + variable, + type = "asc", + custom = `{top}. {username}: {value:,}`, + list = 10, + page = 1, + table = d.client.db.tables[0], + hideNegativeValue = false, + hideZeroValue = false + ] = data.inside.splits; + + if (!d.client.variableManager.has(variable, table)) + return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" Not Found`); + let v = d.client.variableManager.get(variable, table); + + let db = await d.client.db.all(table, (data) => data.key.startsWith(variable.deleteBrackets()) && data.key.split("_").length === 2); + + if (d.client.db.type === "aoi.db") + db.sort((a, b) => Number(a.value) - Number(b.value)); + else db.sort((a, b) => Number(y.data.value) - Number(x.data.value)); + + if (type === "desc") db = db.reverse(); + + if (hideNegativeValue === "true") db = db.filter(x => x.value >= 0); + if (hideZeroValue === "true") db = db.filter(x => x.value != 0); + + let y = 0; + let value; + let content = []; + + for (const Data of db) { + let guild; + if (d.client.db.type === "aoi.db") value = Number(Data.value); + else value = Number(Data.data.value); + guild = await d.util.getGuild(d, Data.key.split("_")[1]); + + if (guild) { + y++; + let text = custom + .replaceAll(`{top}`, y) + .replaceAll("{id}", guild.id) + .replaceAll(`{name}`, guild.name.removeBrackets()) + .replaceAll(`{value}`, value); + + if (text.includes("{value:")) { + let sep = text.split("{value:")[1].split("}")[0]; + text = text.replaceAll(`{value:${sep}}`, value.toLocaleString().replaceAll(",", sep)); + } + + if (text.includes("{execute:")) { + let ins = text.split("{execute:")[1].split("}")[0]; + const awaited = d.client.cmd.awaited.find((c) => c.name === ins); + + if (!awaited) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + ` Invalid awaited command '${ins}' in`, + ); + + const CODE = await d.interpreter( + d.client, + { + guild: guild, + channel: d.message.channel, + }, + d.args, + awaited, + undefined, + true, + ); + + text = text.replaceAll(`{execute:${ins}}`, CODE); + } + + content.push(text); + } + } + + data.result = content.slice(page * list - list, page * list).join("\n"); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/database/rawLeaderboard.js b/src/functions/database/rawLeaderboard.js new file mode 100644 index 000000000..00cf778ab --- /dev/null +++ b/src/functions/database/rawLeaderboard.js @@ -0,0 +1,140 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [ + variable, + order = "asc", + type = "user", + custom = "{top}. {name}: {value}", + list = 10, + page = 1, + table = d.client.db.tables[0], + ] = data.inside.splits; + + if (!d.client.variableManager.has(variable.addBrackets())) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${variable.addBrackets()} Not Found!`, + ); + + const idLength = type === "user" ? 2 : 1; + let y = 0; + let value; + let content = []; + let all = await d.client.db.all( + table, + (data) => + data.key.startsWith(variable.deleteBrackets()) && + data.key.split("_").length === idLength + 1, + ); + + all = all.sort((x, y) => { + if (d.client.db.type === "aoi.db") + return Number(y.value) - Number(x.value); + else return Number(y.data.value) - Number(x.data.value); + }); + + const getdata = async (user, Data, key) => { + user = + (type === "globalUser" + ? await d.util.getUser(d, Data.key.split("_")[key]) + : type === "user" + ? await d.util.getMember(d.guild, Data.key.split("_")[key]) + : type === "server" + ? await d.util.getGuild(d, Data.key.split("_")[key]) + : Data.key.split("_")[key]) ?? Data.key.split("_")[key]; + return user; + }; + + for (let i = 0; i < all.length; i++) { + const Data = all[i]; + + let user; + + if (d.client.db.type === "aoi.db") value = Number(Data.value); + else value = Number(Data.data.value); + + user = await getdata(user, Data, 1); + + + if (user) { + user = + typeof user === "object" + ? type === "user" + ? user.user + : user + : { id: user }; + y++; + + let text = custom + .replaceAll(`{top}`, y) + .replaceAll("{id}", user.id) + .replaceAll("{tag}", user?.tag?.removeBrackets()) + .replaceAll( + `{name}`, + ["user", "globalUser"].includes(type) + ? user.username?.removeBrackets() + : user.name?.removeBrackets(), + ) + .replaceAll(`{value}`, value); + + if (text.includes("{execute:")) { + let ins = text.split("{execute:")[1].split("}")[0]; + + const awaited = d.client.cmd.awaited.find( + (c) => c.name === ins, + ); + + if (!awaited) + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + ` Invalid awaited command '${ins}' in`, + ); + + const CODE = await d.interpreter( + d.client, + { + guild: d.message.guild, + channel: d.message.channel, + author: user, + }, + d.args, + awaited, + undefined, + true, + ); + + text = text.replace(`{execute:${ins}}`, CODE); + } + + content.push(text); + } + } + if (order === "desc") content = content.reverse(); + + const px = page * list - list, + py = page * list; + + data.result = content.slice(px, py).join("\n"); + + return { + code: d.util.setCode(data), + }; +}; + +async function customarr(arr) { + user = + (type === "globalUser" + ? await d.util.getUser(d, arr[1]) + : type === "user" + ? await d.util.getMember(d.guild, arr[1]) + : type === "server" + ? await d.util.getGuild(d, arr[1]) + : arr[1]) ?? arr[1]; + return user; +} diff --git a/src/functions/database/resetGlobalUserVar.js b/src/functions/database/resetGlobalUserVar.js new file mode 100644 index 000000000..03214b96e --- /dev/null +++ b/src/functions/database/resetGlobalUserVar.js @@ -0,0 +1,21 @@ + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [varname, table = d.client.db.tables[0]] = data.inside.splits; + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Doesn't Exist!`, + ); + + await d.client.db.deleteMany(table, (Data) => Data.key.startsWith(`${varname}_`)); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/resetGuildVar.js b/src/functions/database/resetGuildVar.js new file mode 100644 index 000000000..ec74d4075 --- /dev/null +++ b/src/functions/database/resetGuildVar.js @@ -0,0 +1,25 @@ + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [varname, table = d.client.db.tables[0]] = data.inside.splits; + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Doesn't Exist!`, + ); + + await d.client.db.deleteMany(table, (Data) => { + return Data.key.startsWith(`${varname}_`) && + Data.key.split("_").length == 2 && + d.client.guilds.cache.has(Data.key.split("_")[1]); + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/resetUserVar.js b/src/functions/database/resetUserVar.js new file mode 100644 index 000000000..e221b980b --- /dev/null +++ b/src/functions/database/resetUserVar.js @@ -0,0 +1,28 @@ + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [varname, guildID = d.guild?.id, table = d.client.db.tables[0]] = + data.inside.splits; + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Doesn't Exist!`, + ); + + await d.client.db.deleteMany(table, (Data) => { + return ( + Data.key.startsWith(`${varname}_`) && + Data.key.split("_").length == 3&& + Data.key.split("_").endsWith(`_${guildID}`) + ); + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/setChannelVar.js b/src/functions/database/setChannelVar.js new file mode 100644 index 000000000..eefad902b --- /dev/null +++ b/src/functions/database/setChannelVar.js @@ -0,0 +1,50 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [ + varname, + value, + channelID = d.channel.id, + table = d.client.db.tables[0], + ] = data.inside.splits; + + value = value.addBrackets(); + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Not Found!`, + ); + + const variable = d.client.variableManager.get(varname, table); + + if (!variable.checkType(value)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Variable "${varname.addBrackets()}" Needs Value Of Type "${ + variable.type + }". Provided Wrong Type In`, + ); + + value = d.client.variableManager.parseData(value, variable.type); + + try { + await d.client.db.set(table, varname.addBrackets(), channelID, value); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`, + ); + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/setGlobalUserVar.js b/src/functions/database/setGlobalUserVar.js new file mode 100644 index 000000000..de365866c --- /dev/null +++ b/src/functions/database/setGlobalUserVar.js @@ -0,0 +1,46 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, value, userID = d.author?.id, table = d.client.db.tables[0]] = + data.inside.splits; + + value = value.addBrackets(); + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Not Found!`, + ); + + const variable = d.client.variableManager.get(varname, table); + + if (!variable.checkType(value)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Variable "${varname.addBrackets()}" Needs Value Of Type "${ + variable.type + }". Provided Wrong Type In`, + ); + + value = d.client.variableManager.parseData(value, variable.type); + + try { + await d.client.db.set(table, varname.addBrackets(), userID, value); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`, + ); + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/setGuildVar.js b/src/functions/database/setGuildVar.js new file mode 100644 index 000000000..fec4b7537 --- /dev/null +++ b/src/functions/database/setGuildVar.js @@ -0,0 +1,50 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [ + varname, + value, + Id = d.guild?.id || "dm", + table = d.client.db.tables[0], + ] = data.inside.splits; + + value = value.addBrackets(); + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Not Found!`, + ); + + const variable = d.client.variableManager.get(varname, table); + + if (!variable.checkType(value)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Variable "${varname.addBrackets()}" Needs Value Of Type "${ + variable.type + }". Provided Wrong Type In`, + ); + + value = d.client.variableManager.parseData(value, variable.type); + + try { + await d.client.db.set(table, varname.addBrackets(), Id, value); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`, + ); + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/setMessageVar.js b/src/functions/database/setMessageVar.js new file mode 100644 index 000000000..4633ead60 --- /dev/null +++ b/src/functions/database/setMessageVar.js @@ -0,0 +1,46 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [varname, value, messageID = d.message?.id, table = d.client.db.tables[0]] = + data.inside.splits; + + value = value.addBrackets(); + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Not Found!`, + ); + + const variable = d.client.variableManager.get(varname, table); + + if (!variable.checkType(value)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Variable "${varname.addBrackets()}" Needs Value Of Type "${ + variable.type + }". Provided Wrong Type In`, + ); + + value = d.client.variableManager.parseData(value, variable.type); + + try { + await d.client.db.set(table, varname.addBrackets(), messageID, value); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`, + ); + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/setUserVar.js b/src/functions/database/setUserVar.js new file mode 100644 index 000000000..cddb437fa --- /dev/null +++ b/src/functions/database/setUserVar.js @@ -0,0 +1,56 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [ + varname, + value, + userID = d.author?.id, + Id = d.guild?.id || "dm", + table = d.client.db.tables[0], + ] = data.inside.splits; + + value = value.addBrackets(); + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Not Found!`, + ); + + const variable = d.client.variableManager.get(varname, table); + + if (!variable.checkType(value)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Variable "${varname.addBrackets()}" Needs Value Of Type "${ + variable.type + }". Provided Wrong Type In`, + ); + + value = d.client.variableManager.parseData(value, variable.type); + + try { + await d.client.db.set( + table, + varname.addBrackets(), + `${userID}_${Id}`, + value, + ); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`, + ); + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/setVar.js b/src/functions/database/setVar.js new file mode 100644 index 000000000..35ea2f924 --- /dev/null +++ b/src/functions/database/setVar.js @@ -0,0 +1,44 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let [varname, value, table = d.client.db.tables[0]] = data.inside.splits; + + value = value.addBrackets(); + + if (!d.client.variableManager.has(varname.addBrackets(), table)) + return d.aoiError.fnError( + d, + "custom", + {}, + `Variable ${varname.addBrackets()} Not Found!`, + ); + + const variable = d.client.variableManager.get(varname, table); + + if (!variable.checkType(value)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Variable "${varname.addBrackets()}" Needs Value Of Type "${ + variable.type + }". Provided Wrong Type In`, + ); + + value = d.client.variableManager.parseData(value, variable.type); + + try { + await d.client.db.set(table, varname.addBrackets(), undefined, value); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`, + ); + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/database/userLeaderBoard.js b/src/functions/database/userLeaderBoard.js new file mode 100644 index 000000000..816c88bdf --- /dev/null +++ b/src/functions/database/userLeaderBoard.js @@ -0,0 +1,84 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [ + guildID = d.guild?.id, + variable, + type = 'asc', + custom = `{top}. {username}: {value:,}`, + list = 10, + page = 1, + table = d.client.db.tables[0], + hideNegativeValue = false, + hideZeroValue = false + ] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); + + if (!d.client.variableManager.has(variable, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" Not Found`); + let v = d.client.variableManager.get(variable, table); + + let db = await d.client.db.all(table, (data) => data.key.startsWith(variable.deleteBrackets()) && (data.key.split("_").length === 3) && (data.key.split("_")[2] == guildID)); + if (d.client.db.type === "aoi.db") + db.sort((a, b) => Number(a.value) - Number(b.value)); + else db.sort((a, b) => Number(y.data.value) - Number(x.data.value)); + + if (type === "desc") db = db.reverse(); + + if (hideNegativeValue === "true") db = db.filter(x => x.value >= 0); + if (hideZeroValue === "true") db = db.filter(x => x.value != 0); + + let y = 0; + let value; + let content = []; + + for (const Data of db) { + let user; + if (d.client.db.type === "aoi.db") value = Number(Data.value); + else value = Number(Data.data.value); + user = await d.util.getMember(guild, Data.key.split('_')[1]); + + if (user) { + nick = user.nickname + user = user.user; + y++; + let text = custom + .replaceAll(`{top}`, y) + .replaceAll("{id}", user.id) + .replaceAll("{tag}", user.tag) + .replaceAll(`{username}`, user.username.removeBrackets()) + .replaceAll(`{value}`, value) + .replaceAll(`{nick}`, nick || user.username); + + if (text.includes("{value:")) { + let sep = text.split("{value:")[1].split("}")[0]; + text = text.replaceAll(`{value:${sep}}`, value.toLocaleString().replaceAll(",", sep)); + } + if (text.includes("{execute:")) { + let ins = text.split("{execute:")[1].split("}")[0]; + + const awaited = d.client.cmd.awaited.find(c => c.name === ins); + + if (!awaited) return d.aoiError.fnError(d, 'custom', { inside: data.inside }, ` Invalid awaited command '${ins}' in`); + + const CODE = await d.interpreter(d.client, { + guild: guild, + channel: d.message.channel, + author: user + }, d.args, awaited, undefined, true); + + text = text.replace(`{execute:${ins}}`, CODE); + } + + content.push(text); + } + } + + data.result = content.slice(page * list - list, page * list).join("\n"); + + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/database/variablesCount.js b/src/functions/database/variablesCount.js new file mode 100644 index 000000000..d39080389 --- /dev/null +++ b/src/functions/database/variablesCount.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.client.variableManager.size; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/embed/addField.js b/src/functions/embed/addField.js new file mode 100644 index 000000000..c66a22903 --- /dev/null +++ b/src/functions/embed/addField.js @@ -0,0 +1,28 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0])) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const name = fields[i + 1].addBrackets(); + const value = fields[i + 2].addBrackets(); + const inline = fields[i + 3] === "true"; + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].addFields({ + name, + value, + inline, + }); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/addTimestamp.js b/src/functions/embed/addTimestamp.js new file mode 100644 index 000000000..d3eabc35f --- /dev/null +++ b/src/functions/embed/addTimestamp.js @@ -0,0 +1,24 @@ +const { Time } = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 0) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const embed = fields[i + 1] ?? Date.now(); + const timestamp = Time.parse(embed)?.ms ?? embed; + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setTimestamp(timestamp); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/attachment.js b/src/functions/embed/attachment.js new file mode 100644 index 000000000..ebf0eb32b --- /dev/null +++ b/src/functions/embed/attachment.js @@ -0,0 +1,19 @@ +const {AttachmentBuilder} = require("discord.js"); +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + let [attachment, name, type = "url"] = inside.splits; + const result = new AttachmentBuilder( + type === "buffer" + ? Buffer.from(attachment.addBrackets()) + : attachment.addBrackets(), + {name: name.addBrackets()}, + ); + d.files.push(result); + return { + code: d.util.setCode({function: d.func, code, inside}), + files: d.files, + }; +}; diff --git a/src/functions/embed/author.js b/src/functions/embed/author.js new file mode 100644 index 000000000..2d19a9e4c --- /dev/null +++ b/src/functions/embed/author.js @@ -0,0 +1,28 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 0) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const name = fields[i + 1].addBrackets(); + const iconURL = fields[i + 2]?.addBrackets(); + const url = fields[i + 3]?.addBrackets(); + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setAuthor({ + name, + iconURL, + url, + }); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/color.js b/src/functions/embed/color.js new file mode 100644 index 000000000..a656f6ade --- /dev/null +++ b/src/functions/embed/color.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 1 || fields[0] > 10) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const color = fields[i + 1].addBrackets(); + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setColor(color); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/description.js b/src/functions/embed/description.js new file mode 100644 index 000000000..5c712c9a8 --- /dev/null +++ b/src/functions/embed/description.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 1 || fields[0] > 10) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const text = fields[i + 1].addBrackets(); + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setDescription(text); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/footer.js b/src/functions/embed/footer.js new file mode 100644 index 000000000..6dc06cdcf --- /dev/null +++ b/src/functions/embed/footer.js @@ -0,0 +1,26 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 1 || fields[0] > 10) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const text = fields[i + 1].addBrackets(); + const iconURL = fields[i + 2]?.addBrackets(); + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setFooter({ + text, + iconURL, + }); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/image.js b/src/functions/embed/image.js new file mode 100644 index 000000000..886891b15 --- /dev/null +++ b/src/functions/embed/image.js @@ -0,0 +1,22 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 1 || fields[0] > 10) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const url = fields[i + 1]?.addBrackets(); + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setImage(url); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/thumbnail.js b/src/functions/embed/thumbnail.js new file mode 100644 index 000000000..d1c038b4f --- /dev/null +++ b/src/functions/embed/thumbnail.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 1 || fields[0] > 10) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const url = fields[i + 1].addBrackets(); + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setThumbnail(url); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/embed/title.js b/src/functions/embed/title.js new file mode 100644 index 000000000..a1711e030 --- /dev/null +++ b/src/functions/embed/title.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let fields = data.inside.splits; + let i = 0; + + if (isNaN(fields[0]) || fields[0] < 1 || fields[0] > 10) i = -1; + + const index = Number(fields[i] ?? 1) - 1; + const text = fields[i + 1].addBrackets(); + const url = fields[i + 2]?.addBrackets(); + + if (!d.embeds[index]) d.embeds[index] = new d.embed(); + + d.embeds[index].setTitle(text.addBrackets()); + + if (url && url.trim() !== "") d.embeds[index].setURL(url); + + return { + code: d.util.setCode(data), + data: { ...d.data, embeds: Object.assign({}, d.data.embeds, d.embeds) }, + embeds: d.embeds, + }; +}; diff --git a/src/functions/event/bulk.js b/src/functions/event/bulk.js new file mode 100644 index 000000000..df2c05a25 --- /dev/null +++ b/src/functions/event/bulk.js @@ -0,0 +1,14 @@ +const { BulkData } = require("../../utils/EventUtil.js"); + +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option, sep = " , "] = data.inside.splits; + + data.result = BulkData(d, sep, option).deleteBrackets(); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/event/channelUsed.js b/src/functions/event/channelUsed.js new file mode 100644 index 000000000..60632947e --- /dev/null +++ b/src/functions/event/channelUsed.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.channelUsed; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/handleError.js b/src/functions/event/handleError.js new file mode 100644 index 000000000..ec214088e --- /dev/null +++ b/src/functions/event/handleError.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = d.data?.errorData?.[option]?.deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/interactionData.js b/src/functions/event/interactionData.js new file mode 100644 index 000000000..997b27aa0 --- /dev/null +++ b/src/functions/event/interactionData.js @@ -0,0 +1,16 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + let evaled; + + try { + evaled = await eval(`d.data.interaction?.${data.inside.addBrackets()}`); + data.result = typeof evaled === "object" ? require('util').inspect(evaled, {depth: 0}).deleteBrackets() : typeof evaled === "string" ? evaled.deleteBrackets() : evaled; + } catch (e) { + data.result = "undefined" + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/interactionDefer.js b/src/functions/event/interactionDefer.js new file mode 100644 index 000000000..f2f5a926d --- /dev/null +++ b/src/functions/event/interactionDefer.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [ephemeral = "false"] = data.inside.splits; + + await d.data.interaction + ?.deferReply({ephemeral: ephemeral === "true"}) + .catch((e) => { + d.aoiError.fnError(d, "custom", {}, "Failed To Reply With Reason: " + e); + }); + + return { + code: d.util.setCode({ + function: d.func, + code: data.code, + inside: data.inside, + }), + }; +}; diff --git a/src/functions/event/interactionDeferUpdate.js b/src/functions/event/interactionDeferUpdate.js new file mode 100644 index 000000000..91ea63ffb --- /dev/null +++ b/src/functions/event/interactionDeferUpdate.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + await d.data.interaction?.deferUpdate().catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Reply With Reason: ' + e) + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/event/interactionDelete.js b/src/functions/event/interactionDelete.js new file mode 100644 index 000000000..062e27ef6 --- /dev/null +++ b/src/functions/event/interactionDelete.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + await d.data.interaction?.deleteReply().catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Reply With Reason: ' + e) + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/interactionEdit.js b/src/functions/event/interactionEdit.js new file mode 100644 index 000000000..797a36239 --- /dev/null +++ b/src/functions/event/interactionEdit.js @@ -0,0 +1,30 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [content = "", embeds = "", components = "", files = "", allowedMentions = "all"] = data.inside.splits; + + embeds = await d.util.parsers.EmbedParser(embeds, d); + + components = await d.util.parsers.ComponentParser(components, d); + + files = await d.util.parsers.FileParser(files, d); + + allowedMentions = allowedMentions === "all" ? [ "everyone", "users", "roles" ] : (allowedMentions ? allowedMentions?.split(",") : []); + + await d.data.interaction?.editReply({ + content: content.trim() === "" ? " " : content.addBrackets(), + embeds: embeds, + components: components, + files, + allowedMentions: { + parse: allowedMentions + } + }).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Reply With Reason: ' + e) + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/event/interactionFollowUp.js b/src/functions/event/interactionFollowUp.js new file mode 100644 index 000000000..8a40659a9 --- /dev/null +++ b/src/functions/event/interactionFollowUp.js @@ -0,0 +1,26 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [content = "", embeds = "", components = "", files = "", ephemeral = "false"] = data.inside.splits + + embeds = await d.util.parsers.EmbedParser(embeds, d); + + components = await d.util.parsers.ComponentParser(components, d); + + files = await d.util.parsers.FileParser(files, d); + + await d.data.interaction?.followUp({ + content: content.trim() === "" ? " " : content.addBrackets(), + embeds: embeds, + components: components, + files, + ephemeral: ephemeral === "true" || ephemeral === "true" + }).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Reply With Reason: ' + e) + }) + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/event/interactionReply.js b/src/functions/event/interactionReply.js new file mode 100644 index 000000000..3fa24b910 --- /dev/null +++ b/src/functions/event/interactionReply.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [content = "", embeds = "", components = "", files = "", allowedMentions = "all", ephemeral = "false"] = data.inside.splits + + embeds = await d.util.parsers.EmbedParser(embeds, d); + + components = await d.util.parsers.ComponentParser(components, d); + + files = await d.util.parsers.FileParser(files, d); + + allowedMentions = allowedMentions === "all" ? [ "everyone", "users", "roles" ] : (allowedMentions ? allowedMentions?.split(",") : []); + + await d.data.interaction?.reply({ + content: content.trim() === "" ? " " : content.addBrackets(), + embeds: embeds, + components: components, + files, + allowedMentions: { + parse: allowedMentions + }, + ephemeral: ephemeral === "true" || ephemeral === "true" + }) + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/event/interactionUpdate.js b/src/functions/event/interactionUpdate.js new file mode 100644 index 000000000..a1d97f967 --- /dev/null +++ b/src/functions/event/interactionUpdate.js @@ -0,0 +1,26 @@ + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [content = "", embeds = "", components = "", files = ""] = data.inside.splits + + embeds = await d.util.parsers.EmbedParser(embeds, d); + + components = await d.util.parsers.ComponentParser(components, d); + + files = await d.util.parsers.FileParser(files, d); + + await d.data.interaction?.update({ + content: content.trim() === "" ? " " : content.addBrackets(), + embeds: embeds, + components: components, + files + }).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Reply With Reason: ' + e) + }) + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/event/isButtonInteraction.js b/src/functions/event/isButtonInteraction.js new file mode 100644 index 000000000..414db3bed --- /dev/null +++ b/src/functions/event/isButtonInteraction.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.data.interaction?.isButton; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/isCommandInteraction.js b/src/functions/event/isCommandInteraction.js new file mode 100644 index 000000000..5db322536 --- /dev/null +++ b/src/functions/event/isCommandInteraction.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.data.interaction?.isCommand; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/isComponentInteraction.js b/src/functions/event/isComponentInteraction.js new file mode 100644 index 000000000..d9ea45aed --- /dev/null +++ b/src/functions/event/isComponentInteraction.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.data.interaction?.isMessageComponent; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/isContextMenuInteraction.js b/src/functions/event/isContextMenuInteraction.js new file mode 100644 index 000000000..d74fbfe6a --- /dev/null +++ b/src/functions/event/isContextMenuInteraction.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.data.interaction?.isContextMenuCommand(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/isSelectMenuInteraction.js b/src/functions/event/isSelectMenuInteraction.js new file mode 100644 index 000000000..335c2e838 --- /dev/null +++ b/src/functions/event/isSelectMenuInteraction.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.data.interaction?.isStringSelectMenu; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/musicEventData.js b/src/functions/event/musicEventData.js new file mode 100644 index 000000000..c8976d595 --- /dev/null +++ b/src/functions/event/musicEventData.js @@ -0,0 +1,16 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [func] = data.inside.splits; + + data.result = eval( + Array.isArray(d.data.track) + ? `d.data.track[${func}]` + : `d.data.track.${func}`, + ); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/event/newApplicationCmd.js b/src/functions/event/newApplicationCmd.js new file mode 100644 index 000000000..efd95c288 --- /dev/null +++ b/src/functions/event/newApplicationCmd.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = eval(`d.data.newapp?.${option}`); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newChannel.js b/src/functions/event/newChannel.js new file mode 100644 index 000000000..d4dc70a87 --- /dev/null +++ b/src/functions/event/newChannel.js @@ -0,0 +1,14 @@ +const {ChannelOptions} = require('../../utils/Constants.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + const Opx = ChannelOptions[option]; + data.result = eval(`d.data.newc?.${Opx}`); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newEmoji.js b/src/functions/event/newEmoji.js new file mode 100644 index 000000000..e89982040 --- /dev/null +++ b/src/functions/event/newEmoji.js @@ -0,0 +1,13 @@ +const {Emoji} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = Emoji(d.data.newe)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newGuild.js b/src/functions/event/newGuild.js new file mode 100644 index 000000000..4f01e1acc --- /dev/null +++ b/src/functions/event/newGuild.js @@ -0,0 +1,13 @@ +const {Guild} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = Guild(d.data.newg)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newMember.js b/src/functions/event/newMember.js new file mode 100644 index 000000000..c5e2dd1d4 --- /dev/null +++ b/src/functions/event/newMember.js @@ -0,0 +1,14 @@ +const {MemberOptions} = require('../../utils/Constants.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + const Opx = MemberOptions[option]; + data.result = eval(`d.data.newm?.${Opx}`); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newPresence.js b/src/functions/event/newPresence.js new file mode 100644 index 000000000..ceb09c2c4 --- /dev/null +++ b/src/functions/event/newPresence.js @@ -0,0 +1,13 @@ +const {Presence} = require('../../utils/helpers/functions.js') +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = Presence(d.data.newPresence)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newRole.js b/src/functions/event/newRole.js new file mode 100644 index 000000000..ec208c13e --- /dev/null +++ b/src/functions/event/newRole.js @@ -0,0 +1,13 @@ +const {Role} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = Role(d.data.newr)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newState.js b/src/functions/event/newState.js new file mode 100644 index 000000000..369f5671f --- /dev/null +++ b/src/functions/event/newState.js @@ -0,0 +1,13 @@ +const {VoiceState} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = VoiceState(d.data.newVoiceState)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/newUser.js b/src/functions/event/newUser.js new file mode 100644 index 000000000..f6bd943b0 --- /dev/null +++ b/src/functions/event/newUser.js @@ -0,0 +1,13 @@ +const {User} = require('../../utils/helpers/functions.js') +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = User(d.data.newuser)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldApplicationCmd.js b/src/functions/event/oldApplicationCmd.js new file mode 100644 index 000000000..ef198b8bb --- /dev/null +++ b/src/functions/event/oldApplicationCmd.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = eval(`d.data.oldApp?.${option}`); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldChannel.js b/src/functions/event/oldChannel.js new file mode 100644 index 000000000..d764e8236 --- /dev/null +++ b/src/functions/event/oldChannel.js @@ -0,0 +1,14 @@ +const {ChannelOptions} = require('../../utils/Constants.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + const Opx = ChannelOptions[option]; + data.result = eval(`d.data.oldc?.${Opx}`); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldEmoji.js b/src/functions/event/oldEmoji.js new file mode 100644 index 000000000..1cdc4c801 --- /dev/null +++ b/src/functions/event/oldEmoji.js @@ -0,0 +1,13 @@ +const {Emoji} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = Emoji(d.data.olde)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldGuild.js b/src/functions/event/oldGuild.js new file mode 100644 index 000000000..d71fc0101 --- /dev/null +++ b/src/functions/event/oldGuild.js @@ -0,0 +1,13 @@ +const {Guild} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = Guild(d.data.oldg)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldMember.js b/src/functions/event/oldMember.js new file mode 100644 index 000000000..faf3f2603 --- /dev/null +++ b/src/functions/event/oldMember.js @@ -0,0 +1,14 @@ +const {MemberOptions} = require('../../utils/Constants.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + const Opx = MemberOptions[option]; + data.result = eval(`d.data.oldm?.${Opx}`); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldMessage.js b/src/functions/event/oldMessage.js new file mode 100644 index 000000000..e030e1643 --- /dev/null +++ b/src/functions/event/oldMessage.js @@ -0,0 +1,9 @@ +module.exports = async d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.data.oldm?.content; + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} diff --git a/src/functions/event/oldMsgData.js b/src/functions/event/oldMsgData.js new file mode 100644 index 000000000..5f7b57020 --- /dev/null +++ b/src/functions/event/oldMsgData.js @@ -0,0 +1,12 @@ +const {Message} = require("../../utils/helpers/functions.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [option = "cleanContent"] = data.inside.splits; + data.result = eval(`Message(d.data.oldm)?.${option}`); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/event/oldPresence.js b/src/functions/event/oldPresence.js new file mode 100644 index 000000000..39096d4f9 --- /dev/null +++ b/src/functions/event/oldPresence.js @@ -0,0 +1,13 @@ +const {Presence} = require('../../utils/helpers/functions.js') +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = Presence(d.data.oldPresence)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldRole.js b/src/functions/event/oldRole.js new file mode 100644 index 000000000..7aeddbd58 --- /dev/null +++ b/src/functions/event/oldRole.js @@ -0,0 +1,13 @@ +const {Role} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = Role(d.data.oldr)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldState.js b/src/functions/event/oldState.js new file mode 100644 index 000000000..d49d642ee --- /dev/null +++ b/src/functions/event/oldState.js @@ -0,0 +1,13 @@ +const {VoiceState} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = 'name'] = data.inside.splits; + + data.result = VoiceState(d.data.oldVoiceState)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldUser.js b/src/functions/event/oldUser.js new file mode 100644 index 000000000..c4b07926d --- /dev/null +++ b/src/functions/event/oldUser.js @@ -0,0 +1,13 @@ +const {User} = require('../../utils/helpers/functions.js') +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = User(d.data.olduser)[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/oldVariable.js b/src/functions/event/oldVariable.js new file mode 100644 index 000000000..dcfc8d9d2 --- /dev/null +++ b/src/functions/event/oldVariable.js @@ -0,0 +1,14 @@ +module.exports = async d => { + let code = d.command.code; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [opt, seperator = " , "] = inside.splits; + + if (!["variable", "key", "value", "guild", "for", "type", "timestamp"].includes(opt)) return d.error(`Invalid Option in $oldVariable${inside}`) + + return { + code: code.replaceLast(`$oldVariable${inside}`, typeof d.data.oldv[opt] == "object" ? d.data.oldv[opt].join(seperator) : d.data.oldv[opt] || "") + } +} \ No newline at end of file diff --git a/src/functions/event/pinsUpdate.js b/src/functions/event/pinsUpdate.js new file mode 100644 index 000000000..d9785b038 --- /dev/null +++ b/src/functions/event/pinsUpdate.js @@ -0,0 +1,13 @@ +const {PinData} = require("../../utils/EventUtil.js"); +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = PinData(d)[option].deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/rateLimit.js b/src/functions/event/rateLimit.js new file mode 100644 index 000000000..66e6abcab --- /dev/null +++ b/src/functions/event/rateLimit.js @@ -0,0 +1,18 @@ +const {RateLimitOptions} = require("../../utils/EventUtil.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const option = RateLimitOptions.find( + (x) => x === data.inside.inside.toLowerCase(), + ); + + if (!option) return d.aoiError.fnError(d, "option", {inside: data.inside}); + + data.result = d.data.rateLimit[option]; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/event/reactionData.js b/src/functions/event/reactionData.js new file mode 100644 index 000000000..06a866ce9 --- /dev/null +++ b/src/functions/event/reactionData.js @@ -0,0 +1,17 @@ +const {Emoji} = require('../../utils/helpers/functions.js'); +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [option = "name"] = data.inside.splits; + + const reactionData = Emoji(d.data.reactionData.emoji); + reactionData.usernames = d.data.reactionData.users.cache.map(y => y.username.deleteBrackets()).join(" , "); + reactionData.userIds = d.data.reactionData.users.cache.map(y => y.id).join(" , "); + reactionData.tags = d.data.reactionData.users.cache.map(y => y.tag.deleteBrackets()).join(" , "); + + data.result = reactionData?.[option].deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/shard.js b/src/functions/event/shard.js new file mode 100644 index 000000000..60681e465 --- /dev/null +++ b/src/functions/event/shard.js @@ -0,0 +1,12 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = eval(`d.data.shard.${option}`); + + return { + code: d.util.setCode(d), + }; +}; diff --git a/src/functions/event/slashOption.js b/src/functions/event/slashOption.js new file mode 100644 index 000000000..f7932feb4 --- /dev/null +++ b/src/functions/event/slashOption.js @@ -0,0 +1,12 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const option = data.inside.inside; + + data.result = d.data.interaction.options.get(option.addBrackets())?.value; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/event/textInputValue.js b/src/functions/event/textInputValue.js new file mode 100644 index 000000000..7340493cd --- /dev/null +++ b/src/functions/event/textInputValue.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [customID] = data.inside.splits; + + data.result = d.data.interaction.fields.getTextInputValue(customID.addBrackets()); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/timeoutData.js b/src/functions/event/timeoutData.js new file mode 100644 index 000000000..0d9e644d9 --- /dev/null +++ b/src/functions/event/timeoutData.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [option] = data.inside.splits; + + data.result = d.data.timeoutData[option].deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/event/webhookUpdate.js b/src/functions/event/webhookUpdate.js new file mode 100644 index 000000000..1ed4ac1b8 --- /dev/null +++ b/src/functions/event/webhookUpdate.js @@ -0,0 +1,16 @@ +const {WebhookUpdateOptions} = require("../../utils/EventUtil.js") + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const option = WebhookUpdateOptions.includes(data.inside.inside); + + if (!option) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, `Invalid option in`); + + data.result = d.data.channel[WebhookUpdateOptions[option]]; + + return { + code: d.util.setCode(data) + }; +}; \ No newline at end of file diff --git a/src/functions/guild/addEmoji.js b/src/functions/guild/addEmoji.js new file mode 100644 index 000000000..f8f6f6f7d --- /dev/null +++ b/src/functions/guild/addEmoji.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + const [guildID, url, name, returnEmoji = "false", reason, ...roles] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const emoji = await guild.emojis.create({ + attachment: url.addBrackets(), + name: name.addBrackets(), + reason: reason, + roles: roles.length ? roles : undefined + }) + .catch((err) => d.aoiError.fnError(d, "custom", {}, err.message)); + + data.result = returnEmoji === "true" ? emoji.toString() : undefined + return { + code: d.util.setCode(data) + } +} + diff --git a/src/functions/guild/addThreadMember.js b/src/functions/guild/addThreadMember.js new file mode 100644 index 000000000..5ac1b57c6 --- /dev/null +++ b/src/functions/guild/addThreadMember.js @@ -0,0 +1,20 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, threadID, userID, reason] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID); + + if (!channel) d.aoiError.fnError(d, "channel", {inside: data.inside}); + const thread = channel.threads.cache.get(threadID); + + if (!thread) + d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid ThreadID Provided In"); + await thread.members + .add(userID, reason) + .catch((err) => d.aoiError.fnError(d, "custom", {}, err.message)); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/archiveThread.js b/src/functions/guild/archiveThread.js new file mode 100644 index 000000000..79cbc40da --- /dev/null +++ b/src/functions/guild/archiveThread.js @@ -0,0 +1,30 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [threadID, channelID = d.channel.id, archive = "true", reason] = + data.inside.splits; + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const thread = await channel.threads.fetch(threadID).catch((e) => { + return d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Fetch Thread With Reason : ${e.message}`, + ); + }); + thread.setArchived(archive === "true", reason?.addBrackets()).catch((e) => { + return d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Set Archive With Reason : ${e.message}`, + ); + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/categoryChannels.js b/src/functions/guild/categoryChannels.js new file mode 100644 index 000000000..e11a1d513 --- /dev/null +++ b/src/functions/guild/categoryChannels.js @@ -0,0 +1,17 @@ +const {categoryChannelsOption} = require('../../utils/helpers/functions.js'); +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [id, option = "names", sep = " , "] = data.inside.splits; + const category = await d.util.getChannel(d, id); + if (category.type !== d.util.channelTypes.Category) return d.aoiError.fnError(d, "custom", {inside}, "Provided Channel Is Not A Category"); + + data.result = categoryChannelsOption(category)[option]; + + data.result = Array.isArray(data.result) ? data.result.join(sep) + : data.result; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/channelCategoryID.js b/src/functions/guild/channelCategoryID.js new file mode 100644 index 000000000..f4c06226e --- /dev/null +++ b/src/functions/guild/channelCategoryID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [channelID = d.channel.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + data.result = channel.parentId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/channelCount.js b/src/functions/guild/channelCount.js new file mode 100644 index 000000000..c795b9bda --- /dev/null +++ b/src/functions/guild/channelCount.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild.id, type = "all"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + data.result = + type === "all" + ? guild.channels.cache.size + : guild.channels.cache.filter((x) => + type === "NSFW" ? x.nsfw === true : x.type === d.util.channelTypes[type], + ).size; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/channelID.js b/src/functions/guild/channelID.js new file mode 100644 index 000000000..eb3a2b5c2 --- /dev/null +++ b/src/functions/guild/channelID.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [name] = data.inside.splits; + + data.result = name ? d.client.channels.cache.find(x => x.name.toLowerCase() === name.toLowerCase().addBrackets())?.id : d.channel?.id; + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/channelNSFW.js b/src/functions/guild/channelNSFW.js new file mode 100644 index 000000000..708512344 --- /dev/null +++ b/src/functions/guild/channelNSFW.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID,true); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + data.result = channel.nsfw + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/channelName.js b/src/functions/guild/channelName.js new file mode 100644 index 000000000..87e3ea8c4 --- /dev/null +++ b/src/functions/guild/channelName.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID,true); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + data.result = channel.name + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/channelOverwrites.js b/src/functions/guild/channelOverwrites.js new file mode 100644 index 000000000..4c57c3d60 --- /dev/null +++ b/src/functions/guild/channelOverwrites.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [channelID = d.channel?.id, response = "{mention} ({type}):\nAllowed Perms: {allow}\nDenied Perms: {deny}", sep = " , "] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID,true); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + let overwrites = [...channel.permissionOverwrites.cache.values()]; + data.result = overwrites.map(x => response.replaceAll("{mention}", x.type === "role" ? `<@&${x.id}>` : `<@&${x.id}>`).replaceAll("{type}", x.type).replaceAll("{allow}", x.allow.toArray().join(" , ")).replaceAll("{deny}", x.deny.toArray().join(" , "))).join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/channelPermissionsFor.js b/src/functions/guild/channelPermissionsFor.js new file mode 100644 index 000000000..943c817ed --- /dev/null +++ b/src/functions/guild/channelPermissionsFor.js @@ -0,0 +1,16 @@ +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + + const [uorrId = d.author.id, channelID = d.channel.id, sep = " , "] = + inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + const result = channel.permissionsFor(uorrId)?.toArray().join(sep); + + return { + code: d.util.setCode({function: d.func, code, inside, result}), + }; +}; diff --git a/src/functions/guild/channelTopic.js b/src/functions/guild/channelTopic.js new file mode 100644 index 000000000..20e01fcc6 --- /dev/null +++ b/src/functions/guild/channelTopic.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [channelID = d.channel.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID,true); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + data.result = channel.topic?.addBrackets() ?? "none"; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/channelType.js b/src/functions/guild/channelType.js new file mode 100644 index 000000000..f9b1317f9 --- /dev/null +++ b/src/functions/guild/channelType.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [channelID = d.channel.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID,true); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + const types = Object.entries(d.util.channelTypes); + + data.result = types.find(x => x[1] === channel.type)?.[0]?.toLowerCase(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/cloneChannel.js b/src/functions/guild/cloneChannel.js new file mode 100644 index 000000000..1471410eb --- /dev/null +++ b/src/functions/guild/cloneChannel.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + + const [channelID = d.channel.id, name, returnID = "false"] = inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + let result = await channel.clone({name}).catch(err => { + d.aoiError.fnError(d, "custom", {}, "Failed To Clone Channel With Reason: " + err); + }); + + result = returnID === "true" ? result?.id : undefined; + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} + \ No newline at end of file diff --git a/src/functions/guild/createAutomodRule.js b/src/functions/guild/createAutomodRule.js new file mode 100644 index 000000000..f9223eb2f --- /dev/null +++ b/src/functions/guild/createAutomodRule.js @@ -0,0 +1,26 @@ +module.exports = async(d) => { + const data = d.util.aoiFunc(d); + const [guildID = d.guild?.id, name, triggerType, triggerMetadata, actions, enabled = true, exemptRoles, exemptChannels, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + + if (isNaN(Number(triggerType))) { + return d.aoiError.fnError(d, "custom", {}, "argument(s). \`" + data.inside.splits[2] + "\` is not a valid triggerType."); + } + + await guild.autoModerationRules.create({ + name, + eventType: 1, + triggerType: Number(triggerType), + triggerMetadata: triggerMetadata === "" ? {} : JSON.parse(triggerMetadata), + actions: actions === "" ? {} : JSON.parse(actions), + enabled: Boolean(enabled), + exemptRoles: exemptRoles ? exemptRoles.split(',').map(role => role.trim()) : [], + exemptChannels: exemptChannels ? exemptChannels.split(',').map(channel => channel.trim()) : [], + reason + }); + + return { + code: d.util.setCode(data), + }; +} diff --git a/src/functions/guild/createChannel.js b/src/functions/guild/createChannel.js new file mode 100644 index 000000000..3e6b2771a --- /dev/null +++ b/src/functions/guild/createChannel.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [guildID, name, type, returnID = 'false', parentId] = inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside}); + + name = name.addBrackets(); + + type = d.util.channelTypes[type]; + + let result = await guild.channels.create( + { + name, + type, + parent: parentId, + }).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Create Channel With Reason: " + e); + }); + result = returnID === 'true' ? result.id : undefined; + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/guild/createChannelInvite.js b/src/functions/guild/createChannelInvite.js new file mode 100644 index 000000000..bf1250cb0 --- /dev/null +++ b/src/functions/guild/createChannelInvite.js @@ -0,0 +1,42 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [channelID = d.channel?.id, ...options] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) + return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + let object; + + try { + object = JSON.parse(options[0]); + } catch { + object = { + temporary: options[0], + maxAge: options[1], + maxUses: options[2], + unique: options[3], + targetUser: options[4]?.trim() || undefined, + targetApplication: options[5]?.trim() || undefined, + targetType: options[6]?.trim() || undefined, + }; + } + + const invite = await channel.guild.invites + .create(channel.id, object) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Create Invite With Reason: " + e, + ); + }); + + data.result = invite.url; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/createRole.js b/src/functions/guild/createRole.js new file mode 100644 index 000000000..5d14a1445 --- /dev/null +++ b/src/functions/guild/createRole.js @@ -0,0 +1,45 @@ +const {Perms: Permissions} = require('../../utils/Constants.js'); +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) d.error(err); + + let [guildID, name, color, position, icon, hoist = "false", unicodeEmoji, mentionable = "false", returnID = "false", reason, ...permissions] = inside.splits; + + const guild = await d.util.getGuild(d, guildID === "" ? d.guild.id : guildID) + if (!guild) return d.aoiError.fnError(d, "guild", {inside}); + + name = name.addBrackets(); + color = color === "" ? undefined : color + position = isNaN(position) ? 1 : position + icon = icon === "" ? undefined : icon + unicodeEmoji = unicodeEmoji === "" ? undefined : unicodeEmoji + hoist = hoist === "true" + mentionable = mentionable === "true" + const wrongPerms = [] + permissions = permissions.map(x => { + if (isNaN(permissions)) { + if (Object.values(Permissions).includes(x)) { + return x; + } else if (Permissions[x]) { + return Permissions[x]; + } else { + wrongPerms.push(x) + } + } else { + return x + } + }); + if (wrongPerms.length) d.aoiError.fnError(d, "custom", {inside}, "Invalid Permissions: " + wrongPerms.join(" , ") + " Provided In"); + + const role = await guild.roles.create({name, color, position, icon, hoist, unicodeEmoji, mentionable, reason, permissions}).catch(e => { + d.aoiError.fnError(d, "custom", {inside}, "Failed To Create Role With Reason: " + e); + }); + + const result = returnID === "true" ? role?.id : undefined + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/guild/createScheduledEvent.js b/src/functions/guild/createScheduledEvent.js new file mode 100644 index 000000000..8985d7be5 --- /dev/null +++ b/src/functions/guild/createScheduledEvent.js @@ -0,0 +1,55 @@ +const {GuildScheduledEventEntityType} = require('discord.js'); +const {Time} = require('../../utils/helpers/customParser.js'); +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, name, description, starTime, EndTime = undefined, entityType = GuildScheduledEventEntityType.StageInstance, entityMetadata, image, reason] = data.inside.splits; + + try { + const se = JSON.parse(channelID); + if (typeof se !== "object" || se === null) throw new Error("Invalid JSON"); + const guild = d.guild; + + await guild.scheduledEvents.create(se).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Create Stage Instance With Reason: " + e); + }); + return { + code: d.util.setCode(data) + } + + } catch (e) { + // Do nothing + } + channelID = channelID !== "" ? channelID : undefined; + name = name !== "" ? name : undefined; + description = description !== "" ? description : undefined; + starTime = starTime !== "" ? starTime : undefined; + EndTime = EndTime !== "" ? EndTime : undefined; + entityType = entityType !== "" ? Number(entityType) : GuildScheduledEventEntityType.StageInstance; + entityMetadata = entityMetadata !== "" ? entityMetadata : undefined; + image = image !== "" ? image : undefined; + reason = reason !== "" ? reason : undefined; + + const guild = d.guild; + starTime = Time.parse(!isNaN(starTime) ? Number(starTime) : starTime).ms; + EndTime = EndTime ? Time.parse(!isNaN(EndTime) ? Number(EndTime) : EndTime).ms : undefined; + guild.scheduledEvents.create({ + channel: channelID, + name: name.addBrackets(), + description: description?.addBrackets(), + scheduledStartTime: starTime, + scheduledEndTime: EndTime, + privacyLevel: 2, + entityType: entityType, + entityMetadata: entityMetadata ? {location: entityMetadata?.addBrackets()} : undefined, + image: image?.addBrackets(), + reason: reason?.addBrackets() + }).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Create ScheduledEvent With Reason: " + e); + }); + + return { + code: d.util.setCode(data) + }; +}; \ No newline at end of file diff --git a/src/functions/guild/createStageInstance.js b/src/functions/guild/createStageInstance.js new file mode 100644 index 000000000..6d5ce776c --- /dev/null +++ b/src/functions/guild/createStageInstance.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + const [channelID, topic, privacy = "public"] = inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + if (channel.type !== d.util.channelTypes.Stage) return d.aoiError.fnError(d, "custom", {}, "Provided Channel Is Not A Stage Channel"); + + channel.createStageInstance({topic: topic.addBrackets(), privacyLevel: privacy.toUpperCase()}).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Create Stage Instance With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/createSticker.js b/src/functions/guild/createSticker.js new file mode 100644 index 000000000..f20eeecc4 --- /dev/null +++ b/src/functions/guild/createSticker.js @@ -0,0 +1,32 @@ +const {AttachmentBuilder} = require("discord.js"); +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [guildID, url, name, returnSticker = "false", tags, description, reason] = + inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside}); + + const file = new AttachmentBuilder(url); + + const sticker = await guild.stickers + .create({file, name, tags, description, reason}) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Create Sticker With Reason: ${e}`, + ); + }); + + if (returnSticker === "true") d.stickers.push(sticker); + return { + code: d.util.setCode({function: d.func, code, inside, result}), + sticker: d.stickers, + }; +}; diff --git a/src/functions/guild/createThread.js b/src/functions/guild/createThread.js new file mode 100644 index 000000000..b19a84d44 --- /dev/null +++ b/src/functions/guild/createThread.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + if (data.err) return d.error(data.err); + + let [channelID, name, archive = "MAX", type = "public", startMessage, returnID = "false"] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); + + type = d.util.threadTypes[type]; + if (!type) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Type Provided In"); + if (!["60", "1440", "4320", "10080", "MAX"].includes(archive.toUpperCase())) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Archive Duration Provided In"); + + const result = await channel.threads.create({ + name, + autoArchiveDuration: archive.toUpperCase().replace("MAX", "10080"), + type, + startMessage: startMessage?.trim() === "" ? undefined : startMessage + }).catch(e => { + return d.aoiError.fnError(d, "custom", {}, "Failed To Create Thread With Reason: " + e); + }); + + data.result = returnID === "true" ? result?.id : undefined; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/createWebhook.js b/src/functions/guild/createWebhook.js new file mode 100644 index 000000000..78133095c --- /dev/null +++ b/src/functions/guild/createWebhook.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [channel, name, avatar, reason, separator = " , "] = inside.splits; + + channel = await d.util.getChannel(d, channel); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + name = name.addBrackets(); + avatar = avatar.trim() === "" ? undefined : avatar.addBrackets(); + let result = await channel.createWebhook({name, avatar, reason}).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Create Webhook With Reason: " + e); + }); + result = [result.id, result.token].join(separator); + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/guild/deleteAutomodRule.js b/src/functions/guild/deleteAutomodRule.js new file mode 100644 index 000000000..74ceb579a --- /dev/null +++ b/src/functions/guild/deleteAutomodRule.js @@ -0,0 +1,16 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [guildID, automodRuleName, reason, force = true] = data.inside.splits; + + const guild = await d.client.guilds.fetch(guildID); + + const autoModerationRules = await guild.autoModerationRules.fetch({ force: force, cache: force === false ? true : false }); + + const automodRule = autoModerationRules.find(rule => rule.name === automodRuleName || rule.id === automodRuleName); + + guild.autoModerationRules.delete(automodRule.id, { reason: reason }) + + return { + code: d.util.setCode(data), + }; +} \ No newline at end of file diff --git a/src/functions/guild/deleteChannel.js b/src/functions/guild/deleteChannel.js new file mode 100644 index 000000000..bf9ffb6e8 --- /dev/null +++ b/src/functions/guild/deleteChannel.js @@ -0,0 +1,16 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [channel] = inside.splits; + channel = await d.util.getChannel(d, channel); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + channel.delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Channel: " + channel.name + " With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/deleteChannels.js b/src/functions/guild/deleteChannels.js new file mode 100644 index 000000000..353b2faf6 --- /dev/null +++ b/src/functions/guild/deleteChannels.js @@ -0,0 +1,24 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [...channels] = inside.splits; + const wrongChannels = [] + const chans = [] + await channels.forEach(async x => { + const c = await d.util.getChannel(d, x); + if (!c) wrongChannels.push(x); + else chans.push(c); + }); + if (wrongChannels.length) return d.aoiError.fnError(d, "custom", {inside}, `Invalid Channels : ${wrongChannels.join(" , ")} Provided In`); + for (let i = chans.length - 1; i >= 0; i--) { + chans[i].delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Channel: " + chans[i].name + " With Reason: " + e); + }); + + } + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/deleteEmoji.js b/src/functions/guild/deleteEmoji.js new file mode 100644 index 000000000..ef51898d8 --- /dev/null +++ b/src/functions/guild/deleteEmoji.js @@ -0,0 +1,16 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [emoji] = inside.splits; + emoji = await d.util.getEmoji(d, emoji); + if (!emoji) return d.aoiError.fnError(d, "emoji", {inside}); + + emoji.delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Emoji: " + emoji.name + " With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/deleteEmojis.js b/src/functions/guild/deleteEmojis.js new file mode 100644 index 000000000..e3bce6bef --- /dev/null +++ b/src/functions/guild/deleteEmojis.js @@ -0,0 +1,24 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [...emojis] = inside.splits; + const wrongEmojis = [] + const emos = [] + emojis.forEach(x => { + if (!d.client.emojis.cache.find(y => y.name.toLowerCase() === x.toLowerCase().addBrackets() || y.id === x.id || y.toString() === x)) wrongEmojis.push(x) + else emos.push(d.client.emojis.cache.find(y => y.name.toLowerCase() === x.toLowerCase().addBrackets() || y.id === x.id || y.toString() === x)) + }) + if (wrongEmojis.length) return d.aoiError.fnError(d, "custom", {inside}, `Invalid Emojis : ${wrongEmojis.join(" , ")} Provided In`); + + for (let i = emos.length - 1; i >= 0; i--) { + emos[i].delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Emoji: " + emos[i].name + " With Reason: " + e); + }); + + } + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/deleteInvite.js b/src/functions/guild/deleteInvite.js new file mode 100644 index 000000000..ca95ff951 --- /dev/null +++ b/src/functions/guild/deleteInvite.js @@ -0,0 +1,24 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID = d.guild?.id, code, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + await guild.invites + .delete(code.addBrackets(), reason?.addBrackets()) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Delete Invite: " + code + " With Reason: " + e, + ); + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/deleteRoles.js b/src/functions/guild/deleteRoles.js new file mode 100644 index 000000000..1ec36abb2 --- /dev/null +++ b/src/functions/guild/deleteRoles.js @@ -0,0 +1,51 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, ...roles] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + const wrongRoles = []; + const ros = []; + + roles.forEach((x) => { + if ( + !guild.roles.cache.find( + (y) => + y.name.toLowerCase() === x.toLowerCase().addBrackets() || y.id === x, + ) + ) + wrongRoles.push(x); + else + ros.push( + guild.roles.cache.find( + (y) => + y.name.toLowerCase() === x.toLowerCase().addBrackets() || + y.id === x, + ), + ); + }); + if (wrongRoles.length) + return d.aoiError.fnError( + d, + "custom", + {inside}, + `Invalid Roles : ${wrongRoles.join(" , ")} Provided In`, + ); + + for (let i = ros.length - 1; i >= 0; i--) { + ros[i].delete().catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Delete Roles: " + ros[i].name + " With Reason: " + e, + ); + }); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/deleteStageInstance.js b/src/functions/guild/deleteStageInstance.js new file mode 100644 index 000000000..109e0e090 --- /dev/null +++ b/src/functions/guild/deleteStageInstance.js @@ -0,0 +1,39 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) + return d.aoiError.fnError(d, "channel", {inside: data.inside}); + if (channel.type !== d.util.channelTypes.Stage) + return d.aoiError.fnError( + d, + "custom", + {}, + "Provided Channel Is Not A Stage Channel", + ); + + if (!channel.stageInstance) { + return d.aoiError.fnError( + d, + "custom", + {}, + "Provided Channel Has No Stage Instance", + ); + } + + await channel.stageInstance.delete().catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Delete Stage Instance With Reason: " + e, + ); + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/deleteSticker.js b/src/functions/guild/deleteSticker.js new file mode 100644 index 000000000..f00d2754f --- /dev/null +++ b/src/functions/guild/deleteSticker.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [guildID, sticker] = inside.splits; + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside}); + + sticker = await d.util.getSticker(d.guild, sticker); + if (!sticker) return d.aoiError.fnError(d, "sticker", {inside}); + + sticker.delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Sticker: " + sticker.name + " With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/deleteThread.js b/src/functions/guild/deleteThread.js new file mode 100644 index 000000000..c46040da3 --- /dev/null +++ b/src/functions/guild/deleteThread.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, threadID, reason] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}) + + const thread = channel.threads.cache.get(threadID); + if (!thread) return d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid ThreadID Provided In") + + thread.delete(reason); + + return { + code: d.util.setCode(data) + } + +} \ No newline at end of file diff --git a/src/functions/guild/deleteWebhook.js b/src/functions/guild/deleteWebhook.js new file mode 100644 index 000000000..4e8fb997a --- /dev/null +++ b/src/functions/guild/deleteWebhook.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [id, token] = inside.splits; + const webhook = await d.client.fetchWebhook(id, token).catch(e => { + d.aoiError.fnError(d, "custom", {inside}, "Invalid WebhookId Provided In"); + }); + + webhook.delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Webhook With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/editChannel.js b/src/functions/guild/editChannel.js new file mode 100644 index 000000000..523384b10 --- /dev/null +++ b/src/functions/guild/editChannel.js @@ -0,0 +1,100 @@ +const {Time} = require("../../utils/helpers/customParser.js"); +module.exports = async (d) => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [channelID, ...fields] = inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + if (fields.length === 1) { + try { + fields = JSON.parse(fields[0]); + + channel + .edit(fields, fields.reason) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Edit Channel With Reason: " + e, + ); + }); + + } catch { + let [ + name = "$default", + type = "$default", + position = "$default", + topic = "$default", + nsfw = "$default", + bitrate = "$default", + userLimit = "$default", + parent = "$default", + lockPermissions = "$default", + permissionOverwrites = "$default", + rateLimitPerUser = "$default", + defaultAutoArchiveDuration = "$default", + rtcRegion = "$default", + reason, + ] = fields; + + name = name === "$default" ? channel.name : name.addBrackets(); + type = type === "$default" ? channel.type : d.util.channelTypes[type]; + position = position === "$default" ? channel.position : Number(position); + nsfw = nsfw === "$default" ? channel.nsfw : nsfw === "true"; + topic = topic === "$default" ? channel.topic : topic.addBrackets(); + bitrate = bitrate === "$default" ? channel.bitrate : Number(bitrate); + userLimit = + userLimit === "$default" ? channel.userLimit : Number(userLimit); + parent = parent === "$default" ? channel.parent : parent; + lockPermissions = + lockPermissions === "$default" + ? channel.permissionsLocked + : lockPermissions === "true"; + rateLimitPerUser = + rateLimitPerUser === "$default" + ? channel.rateLimitPerUser + : Time.parse(rateLimitPerUser).ms; + permissionOverwrites = + permissionOverwrites === "$default" + ? channel.permissionOverwrites.cache + : JSON.parse(permissionOverwrites.addBrackets()); + defaultAutoArchiveDuration = + defaultAutoArchiveDuration === "$default" + ? channel.defaultAutoArchiveDuration + : defaultAutoArchiveDuration; + rtcRegion = rtcRegion === "$default" ? channel.rtcRegion : rtcRegion; + + channel + .edit({ + name, + type, + position, + topic, + nsfw, + bitrate, + userLimit, + parent, + lockPermissions, + permissionOverwrites, + rateLimitPerUser, + defaultAutoArchiveDuration, + rtcRegion, + }, reason) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Edit Channel With Reason: " + e, + ); + }); + } + } + + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/editMessage.js b/src/functions/guild/editMessage.js new file mode 100644 index 000000000..4cb10a654 --- /dev/null +++ b/src/functions/guild/editMessage.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [messageID, msg, channelID = d.channel.id] = inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "message", {inside}); + + msg = await d.util.errorParser(msg, d); + + message.edit(msg.data ? msg.data : msg).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Edit Message With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/guild/findChannel.js b/src/functions/guild/findChannel.js new file mode 100644 index 000000000..7d41b0bfa --- /dev/null +++ b/src/functions/guild/findChannel.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelResolver, returnSelf = "true"] = data.inside.splits; + channelResolver = channelResolver.addBrackets(); + + data.result = d.util.findChannel(d.client, channelResolver) || (returnSelf === "true" ? d.channel.id : undefined); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/findGuild.js b/src/functions/guild/findGuild.js new file mode 100644 index 000000000..0b12e7519 --- /dev/null +++ b/src/functions/guild/findGuild.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [resolve] = data.inside.splits; + + const guild = d.client.guilds.cache.get(resolve) || d.client.guilds.cache.find(g => g.name.toLowerCase() === resolve.toLowerCase()); + + data.result = guild ? guild.id : undefined; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/findGuildChannel.js b/src/functions/guild/findGuildChannel.js new file mode 100644 index 000000000..1a9870ddb --- /dev/null +++ b/src/functions/guild/findGuildChannel.js @@ -0,0 +1,17 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelResolver, returnSelf = "true", guildID = d.guild.id] = + data.inside.splits; + channelResolver = channelResolver.addBrackets(); + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + data.result = d.util.findGuildChannel(guild, channelResolver) || (returnSelf === "true" ? d.channel.id : undefined); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/getAutomodRuleId.js b/src/functions/guild/getAutomodRuleId.js new file mode 100644 index 000000000..b73ac6846 --- /dev/null +++ b/src/functions/guild/getAutomodRuleId.js @@ -0,0 +1,15 @@ +module.exports = async(d) => { + const data = d.util.aoiFunc(d); + const [guildID = d.guild?.id, name, force = true] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + + const autoModerationRules = await guild.autoModerationRules.fetch({ force: force, cache: force === false ? true : false }); + const result = autoModerationRules.find(rule => rule.name === name || rule.id === name); + + data.result = result.id; + + return { + code: d.util.setCode(data), + }; +} diff --git a/src/functions/guild/getGuildAutomodNames.js b/src/functions/guild/getGuildAutomodNames.js new file mode 100644 index 000000000..883b82505 --- /dev/null +++ b/src/functions/guild/getGuildAutomodNames.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', { inside: data.inside }); + + const autoModRules = await guild.autoModerationRules.fetch(); + const autoModNames = autoModRules.map((rule) => rule.name); + + const spacedNames = autoModNames.join(", "); + + data.result = spacedNames; + + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/guild/getGuildForumTags.js b/src/functions/guild/getGuildForumTags.js new file mode 100644 index 000000000..89bc4e400 --- /dev/null +++ b/src/functions/guild/getGuildForumTags.js @@ -0,0 +1,72 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [forumId, option = "id", separator = " , "] = data.inside.splits; + + const forum = await d.util.fetchChannel(d, forumId); + + const parseTags = forum.availableTags + .filter(tag => tag.emoji !== null) + .map(tag => { + let result; + switch (option.toLowerCase()) { + case "emoji": + result = tag.emoji.name || `<${tag.emoji.animated ? "a" : ""}:${tag.emoji.name || "undefined"}:${tag.emoji.id}>`; + break; + case "emojiid": + result = tag.emoji.id !== null ? tag.emoji.id : "undefined"; + break; + case "moderated": + result = tag.moderated; + break; + case "name": + result = tag.name; + break; + case "id": + result = tag.id; + break; + default: + result = "unknown"; + break; + } + return result; + }); + + if (option.includes("{") && option.includes("}")) { + const parseCustomTags = []; + for (const tag of forum.availableTags) { + const format = option.replace(/\{(\w+)\}/g, (_, key) => { + let tags; + if (key.toLowerCase() === "emoji") { + if (tag.emoji && tag.emoji.name !== "unknown" && tag.emoji.id !== null) { + tags = tag.emoji.animated ? `` : `<:${tag.emoji.name}:${tag.emoji.id}>`; + } else if (tag.emoji && tag.emoji.name !== "unknown") { + tags = tag.emoji.name; + } else { + tags = ""; + } + } else if (key.toLowerCase() === "emojiid") { + tags = tag?.emoji?.id !== null ? tag?.emoji?.id : "unknown"; + } else if (key.toLowerCase() === "managed") { + tags = tag?.managed !== null ? tag?.managed : "unknown"; + } else if (key.toLowerCase() === "id") { + tags = tag?.id !== null ? tag?.id : "unknown"; + } else { + tags = tag[key] !== undefined ? tag[key] : `${key}`; + } + return tags; + }); + if (format) { + parseCustomTags.push(format); + } + } + data.result = parseCustomTags.length > 0 ? parseCustomTags.join(separator) : "null"; + } else { + data.result = parseTags[0] === "unknown" ? d.aoiError.fnError(d, "custom", { inside: data.inside }, "option provided.") : (parseTags.length > 0 ? parseTags.join(separator) : "null"); + } + + return { + code: d.util.setCode(data) + }; +} diff --git a/src/functions/guild/getGuildInvite.js b/src/functions/guild/getGuildInvite.js new file mode 100644 index 000000000..82c321941 --- /dev/null +++ b/src/functions/guild/getGuildInvite.js @@ -0,0 +1,44 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, ...options] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + let object; + const channel = guild.channels.cache + .filter((x) => x.type === d.util.channelTypes.Text) + .random(); + + try { + object = JSON.parse(options[0]); + } catch { + object = { + temporary: options[0], + maxAge: options[1], + maxUses: options[2], + unique: options[3], + targetUser: options[4]?.trim() || undefined, + targetApplication: options[5]?.trim() || undefined, + targetType: options[6]?.trim() || undefined, + }; + } + + const invite = await guild.invites + .create(channel?.id, object) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Create Invite With Reason: " + e, + ); + }); + + data.result = invite.url; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/getGuildTemplate.js b/src/functions/guild/getGuildTemplate.js new file mode 100644 index 000000000..7aad5ca98 --- /dev/null +++ b/src/functions/guild/getGuildTemplate.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let template; + + const [templateCode, property] = data.inside.splits; + + try { + template = await d.client.fetchGuildTemplate(`https://discord.new/${templateCode}`); + } catch (err) { + return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Template ID"); + } + + data.result = property.split(".").reduce((obj, prop) => obj && obj[prop], template); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/getGuildTemplates.js b/src/functions/guild/getGuildTemplates.js new file mode 100644 index 000000000..473c3aa00 --- /dev/null +++ b/src/functions/guild/getGuildTemplates.js @@ -0,0 +1,21 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let templates; + + const [guildID = d.guild?.id, option = "code", separator = " , "] = data.inside.splits; + + try { + const guild = await d.util.getGuild(d, guildID); + templates = await guild.fetchTemplates(); + } catch (err) { + data.result = undefined; + return; + } + + data.result = templates.map(x => option.split(".").reduce((obj, prop) => obj && obj[prop], x)).join(separator); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/getRoleColor.js b/src/functions/guild/getRoleColor.js new file mode 100644 index 000000000..aac5dacb3 --- /dev/null +++ b/src/functions/guild/getRoleColor.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Get Role Data With Reason: " + e); + }); + + data.result = role.hexColor; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/giveRole.js b/src/functions/guild/giveRole.js new file mode 100644 index 000000000..c79f3b459 --- /dev/null +++ b/src/functions/guild/giveRole.js @@ -0,0 +1,21 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, userID, roleID, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + member.roles.add(roleID, reason).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Give Role With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/giveRoles.js b/src/functions/guild/giveRoles.js new file mode 100644 index 000000000..4af68647a --- /dev/null +++ b/src/functions/guild/giveRoles.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, userID, reason, ...roleID] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + member.roles.add(roleID, reason).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Give Roles With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/guildAFKChannelID.js b/src/functions/guild/guildAFKChannelID.js new file mode 100644 index 000000000..d18b1ded6 --- /dev/null +++ b/src/functions/guild/guildAFKChannelID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.afkChannelId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildAvailable.js b/src/functions/guild/guildAvailable.js new file mode 100644 index 000000000..d58a7e576 --- /dev/null +++ b/src/functions/guild/guildAvailable.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.available; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildBanner.js b/src/functions/guild/guildBanner.js new file mode 100644 index 000000000..c4d9894b3 --- /dev/null +++ b/src/functions/guild/guildBanner.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, size = 4096, dynamic = 'true', extension] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.bannerURL({ + size: Number(size), + forceStatic: dynamic === 'false', + extension + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/guildBoostCount.js b/src/functions/guild/guildBoostCount.js new file mode 100644 index 000000000..842695443 --- /dev/null +++ b/src/functions/guild/guildBoostCount.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.premiumSubscriptionCount; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildBoostLevel.js b/src/functions/guild/guildBoostLevel.js new file mode 100644 index 000000000..12d3ea84d --- /dev/null +++ b/src/functions/guild/guildBoostLevel.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.premiumTier; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildBotCount.js b/src/functions/guild/guildBotCount.js new file mode 100644 index 000000000..075aba5af --- /dev/null +++ b/src/functions/guild/guildBotCount.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID) + + data.result = guild?.members.cache.filter(x => x.user.bot).size || 0 + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildChannelExists.js b/src/functions/guild/guildChannelExists.js new file mode 100644 index 000000000..32b193922 --- /dev/null +++ b/src/functions/guild/guildChannelExists.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID = d.guild?.id, channel] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + channel = guild.channels.cache.find(x => x.name.toLowerCase() === channel.toLowerCase().addBrackets() || x.id === channel) + + data.result = !!channel + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildChannels.js b/src/functions/guild/guildChannels.js new file mode 100644 index 000000000..1ca6d02b9 --- /dev/null +++ b/src/functions/guild/guildChannels.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, option = 'name', sep = ' , '] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.channels.cache.map(x => option === 'mention' ? x.toString() : x[option]).join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildCommunityUpdatesChannelID.js b/src/functions/guild/guildCommunityUpdatesChannelID.js new file mode 100644 index 000000000..1422afc56 --- /dev/null +++ b/src/functions/guild/guildCommunityUpdatesChannelID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.publicUpdatesChannelId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildContentFilter.js b/src/functions/guild/guildContentFilter.js new file mode 100644 index 000000000..3ab212fdc --- /dev/null +++ b/src/functions/guild/guildContentFilter.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.explicitContentFilter; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildCooldown.js b/src/functions/guild/guildCooldown.js new file mode 100644 index 000000000..6d8251271 --- /dev/null +++ b/src/functions/guild/guildCooldown.js @@ -0,0 +1,63 @@ +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time, errorObject = ""] = data.inside.splits; + let error; + + let cooldown = await d.client.db.get( + d.client.db.tables[0], + "cooldown", + `${d.command.name}_${d.guild?.id || "dm"}`, + ); + if (!cooldown) { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + d.client.db.tables[0], + "cooldown", + `${d.command.name}_${d.guild?.id || "dm"}`, + cooldown, + ); + } else if (Date.now() < cooldown.value) { + if (errorObject.trim() === "") { + } else { + const {object, humanize, toString} = Time.format(cooldown.value - Date.now()); + errorObject = errorObject + .replaceAll("%time%", humanize()) + .replaceAll("%year%", object.years) + .replaceAll("%month%", object.months) + .replaceAll("%week%", object.weeks) + .replaceAll("%day%", object.days) + .replaceAll("%hour%", object.hours) + .replaceAll("%min%", object.minutes) + .replaceAll("%sec%", object.seconds) + .replaceAll("%ms%", object.ms) + .replaceAll("%fullTime%", toString()); + + errorObject = await d.util.errorParser(errorObject); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorObject.data ?? errorObject, + errorObject.options, + d + ); + } + error = true; + } else { + cooldown = Date.now() + Time.parse(time).ms; + d.client.db.set( + d.client.db.tables[0], + "cooldown", + `${d.command.name}_${d.guild?.id || "dm"}`, + cooldown, + ); + } + + return { + code: d.util.setCode(data), + error, + }; +}; diff --git a/src/functions/guild/guildCount.js b/src/functions/guild/guildCount.js new file mode 100644 index 000000000..3f39eb91e --- /dev/null +++ b/src/functions/guild/guildCount.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.client.guilds.cache.size; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildCreatePost.js b/src/functions/guild/guildCreatePost.js new file mode 100644 index 000000000..5ca4d39e8 --- /dev/null +++ b/src/functions/guild/guildCreatePost.js @@ -0,0 +1,29 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [forumId, name, content, autoArchiveDuration = "10080", returnId = false, reason, ...appliedTags] = data.inside.splits; + + const forum = await d.util.fetchChannel(d, forumId); + + const parseTags = appliedTags.map(tag => { + const tags = forum.availableTags.find(t => t.name === tag || t.id === tag); + return tags ? tags.id : null; + }).filter(tag => tag !== null); + + content = await d.util.errorParser(content, d); + + const thread = await forum.threads.create({ + name, + autoArchiveDuration, + message: content.data ? content.data : content, + appliedTags: parseTags, + reason + }); + + data.result = returnId === "true" ? thread.id : undefined; + + return { + code: d.util.setCode(data) + }; +} \ No newline at end of file diff --git a/src/functions/guild/guildDefaultMessageNotifications.js b/src/functions/guild/guildDefaultMessageNotifications.js new file mode 100644 index 000000000..b6d557d03 --- /dev/null +++ b/src/functions/guild/guildDefaultMessageNotifications.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const type = { + 0: "All Messages", + 1: "Only Mentions" + } + + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = type[guild.defaultMessageNotifications]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildDescription.js b/src/functions/guild/guildDescription.js new file mode 100644 index 000000000..80ba83047 --- /dev/null +++ b/src/functions/guild/guildDescription.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.description; + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildEditPost.js b/src/functions/guild/guildEditPost.js new file mode 100644 index 000000000..9efec232e --- /dev/null +++ b/src/functions/guild/guildEditPost.js @@ -0,0 +1,38 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [threadId, reason, returnTags = false, ...threadTags] = data.inside.splits; + + const thread = await d.util.fetchChannel(d, threadId); + const forum = await d.util.fetchChannel(d, thread.parentId); + + threadTags.map(tags => { + const threadTag = tags.replace(/^[-+]/, ''); + + const applyTags = forum.availableTags.find(tag => tag.name === threadTag || tag.id === threadTag); + + if (applyTags) { + const appliedTags = thread.appliedTags; + + if (tags.startsWith('+') && !appliedTags.includes(applyTags.id)) { + appliedTags.push(applyTags.id); + } else if (tags.startsWith('-') && appliedTags.includes(applyTags.id)) { + const index = appliedTags.indexOf(applyTags.id); + appliedTags.splice(index, 1); + } + + thread.setAppliedTags(appliedTags, reason); + + return applyTags.id; + } else { + return null; + } + }).filter(tag => tag !== null); + + data.result = returnTags === "true" ? thread.appliedTags : undefined; + + return { + code: d.util.setCode(data), + }; +} diff --git a/src/functions/guild/guildEmojiExists.js b/src/functions/guild/guildEmojiExists.js new file mode 100644 index 000000000..a4b99775c --- /dev/null +++ b/src/functions/guild/guildEmojiExists.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [emoji, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.emojis.cache.some(x => x.id === emoji || x.toString() === emoji || x.identifier.toLowerCase() === emoji.toLowerCase()) + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildEmojis.js b/src/functions/guild/guildEmojis.js new file mode 100644 index 000000000..ab32247e5 --- /dev/null +++ b/src/functions/guild/guildEmojis.js @@ -0,0 +1,14 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [sep = " , ", guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + data.result = guild.emojis.cache.map((x) => x.toString()).join(sep); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/guildExists.js b/src/functions/guild/guildExists.js new file mode 100644 index 000000000..bfcdb0882 --- /dev/null +++ b/src/functions/guild/guildExists.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const guildID = data.inside.inside; + + data.result = !!(await d.util.getGuild(d, guildID)); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildFeatures.js b/src/functions/guild/guildFeatures.js new file mode 100644 index 000000000..3321bcfa4 --- /dev/null +++ b/src/functions/guild/guildFeatures.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.features.join(' , '); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildHighestRole.js b/src/functions/guild/guildHighestRole.js new file mode 100644 index 000000000..51bbb0286 --- /dev/null +++ b/src/functions/guild/guildHighestRole.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, option = 'id'] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = option === "mention" ? guild.roles.highest.toString() : guild.roles.highest[option]; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/guildID.js b/src/functions/guild/guildID.js new file mode 100644 index 000000000..a94a5fb2d --- /dev/null +++ b/src/functions/guild/guildID.js @@ -0,0 +1,10 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [name = d.guild?.name] = data.inside.splits; + + data.result = d.guild?.name === name ? d.guild?.id : d.client.guilds.cache.find(x => x.name.toLowerCase() === name.addBrackets().toLowerCase())?.id; + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildIDS.js b/src/functions/guild/guildIDS.js new file mode 100644 index 000000000..a8d7590c8 --- /dev/null +++ b/src/functions/guild/guildIDS.js @@ -0,0 +1,11 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [sep = ' , '] = data.inside.splits + + data.result = [...d.client.guilds.cache.keys()].join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildIcon.js b/src/functions/guild/guildIcon.js new file mode 100644 index 000000000..37c2b2be4 --- /dev/null +++ b/src/functions/guild/guildIcon.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, size = 4096, dynamic = 'true', extension] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.iconURL({ + size: Number(size), + forceStatic: dynamic === 'false', + extension + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/guildLowestRole.js b/src/functions/guild/guildLowestRole.js new file mode 100644 index 000000000..6cca5792f --- /dev/null +++ b/src/functions/guild/guildLowestRole.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, option = "id"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); + + const role = guild.roles.cache.filter((role) => role.id !== guild.id).sort((a, b) => a.position - b.position) .first(); + + data.result = !role + ? guild?.roles.everyone.id + : role === undefined + ? guild.id + : role?.[option.toLowerCase()]; + + return { code: d.util.setCode(data) }; +}; diff --git a/src/functions/guild/guildMFALevel.js b/src/functions/guild/guildMFALevel.js new file mode 100644 index 000000000..b92a7ba19 --- /dev/null +++ b/src/functions/guild/guildMFALevel.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.mfaLevel; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildMaxStageVideoChannelUsers.js b/src/functions/guild/guildMaxStageVideoChannelUsers.js new file mode 100644 index 000000000..1618c6790 --- /dev/null +++ b/src/functions/guild/guildMaxStageVideoChannelUsers.js @@ -0,0 +1,14 @@ +module.exports = async d => { + let data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.maxStageVideoChannelUsers; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildMaxVideoChannelUsers.js b/src/functions/guild/guildMaxVideoChannelUsers.js new file mode 100644 index 000000000..a43dd8050 --- /dev/null +++ b/src/functions/guild/guildMaxVideoChannelUsers.js @@ -0,0 +1,14 @@ +module.exports = async d => { + let data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.maxVideoChannelUsers; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildMaximumMembers.js b/src/functions/guild/guildMaximumMembers.js new file mode 100644 index 000000000..feb426fe5 --- /dev/null +++ b/src/functions/guild/guildMaximumMembers.js @@ -0,0 +1,14 @@ +module.exports = async d => { + let data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.maximumMembers; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildNSFWLevel.js b/src/functions/guild/guildNSFWLevel.js new file mode 100644 index 000000000..714beabc8 --- /dev/null +++ b/src/functions/guild/guildNSFWLevel.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.nsfwLevel; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildName.js b/src/functions/guild/guildName.js new file mode 100644 index 000000000..f0e1dc87d --- /dev/null +++ b/src/functions/guild/guildName.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.name; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildNames.js b/src/functions/guild/guildNames.js new file mode 100644 index 000000000..1ad65500b --- /dev/null +++ b/src/functions/guild/guildNames.js @@ -0,0 +1,11 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [sep = ' , '] = data.inside.splits + + data.result = d.client.guilds.cache.map(x => x.name).join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildOwnerID.js b/src/functions/guild/guildOwnerID.js new file mode 100644 index 000000000..6f5ab28de --- /dev/null +++ b/src/functions/guild/guildOwnerID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.ownerId ? guild.ownerId : (await guild.fetchOwner())?.id; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildPreferredLocale.js b/src/functions/guild/guildPreferredLocale.js new file mode 100644 index 000000000..b03dd1c8f --- /dev/null +++ b/src/functions/guild/guildPreferredLocale.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.preferredLocale; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildRandomID.js b/src/functions/guild/guildRandomID.js new file mode 100644 index 000000000..ef7231577 --- /dev/null +++ b/src/functions/guild/guildRandomID.js @@ -0,0 +1,14 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.client.guilds.cache.random()?.id; + if (!d.randoms.randomGuild) { + d.randoms.randomGuild = result + } else { + result = d.randoms.randomGuild; + } + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildRoleIconURL.js b/src/functions/guild/guildRoleIconURL.js new file mode 100644 index 000000000..c5b5b3dfe --- /dev/null +++ b/src/functions/guild/guildRoleIconURL.js @@ -0,0 +1,21 @@ +const {Role} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID = d.guild?.id, roleID,] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(err => { + d.aoiError.fnError(d, 'role', {inside: data.inside}); + }); + + data.result = role.iconURL({dynamic: true, size: 1024}); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildRoles.js b/src/functions/guild/guildRoles.js new file mode 100644 index 000000000..a240e5f99 --- /dev/null +++ b/src/functions/guild/guildRoles.js @@ -0,0 +1,33 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [ + guildID = d.guild?.id, + type = "name", + sep = " , ", + removeManagedRoles = "true", + fetch = "false", + ] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + if (fetch === " true") { + guild.roles.fetch(); + } + let cache; + + if (removeManagedRoles === "true") + cache = guild.roles.cache.filter((x) => !x.managed); + else cache = guild.roles.cache; + + data.result = cache.map((x) => + type?.trim() === "mention" ? x.toString() : x[type], + ) + .join(sep) + .removeBrackets(); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/guildRulesChannelID.js b/src/functions/guild/guildRulesChannelID.js new file mode 100644 index 000000000..de0207156 --- /dev/null +++ b/src/functions/guild/guildRulesChannelID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.rulesChannelId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildSafetyChannelID.js b/src/functions/guild/guildSafetyChannelID.js new file mode 100644 index 000000000..f5081e3fb --- /dev/null +++ b/src/functions/guild/guildSafetyChannelID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.safetyAlertsChannelId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildShard.js b/src/functions/guild/guildShard.js new file mode 100644 index 000000000..7481760b3 --- /dev/null +++ b/src/functions/guild/guildShard.js @@ -0,0 +1,29 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [option = "id", sep = " , ", shardId] = data.inside.splits; + if (shardId && isNaN(shardId)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid ShardId Provided In", + ); + + function evalfunc(client, {option, sep}) { + return client.guilds.cache + .map((x) => eval(option === "" ? x : `x.${option}`)) + .join(sep); + } + + const arr = await d.client.shard.broadcastEval(evalfunc, { + shard: !shardId ? undefined : Number(shardId), + context: {option: option, sep: sep}, + }); + + data.result = arr.join(sep); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/guildShardID.js b/src/functions/guild/guildShardID.js new file mode 100644 index 000000000..0a8470624 --- /dev/null +++ b/src/functions/guild/guildShardID.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + data.result = d.guild?.shardId || 0; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildShardPing.js b/src/functions/guild/guildShardPing.js new file mode 100644 index 000000000..0881b2d31 --- /dev/null +++ b/src/functions/guild/guildShardPing.js @@ -0,0 +1,21 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [shardId = 0] = data.inside.splits; + + if (isNaN(shardId)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid ShardId Provided In", + ); + + data.result = await d.client.shard.broadcastEval((c) => c.ws.ping, { + shard: Number(shardId), + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/guild/guildSplash.js b/src/functions/guild/guildSplash.js new file mode 100644 index 000000000..621dbaadb --- /dev/null +++ b/src/functions/guild/guildSplash.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, size = 4096, dynamic = 'true', extension] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.splashURL({ + size: Number(size), + forceStatic: dynamic === 'false', + extension + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/guildSystemChannelID.js b/src/functions/guild/guildSystemChannelID.js new file mode 100644 index 000000000..5bb3b9a6f --- /dev/null +++ b/src/functions/guild/guildSystemChannelID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.systemChannelId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildVanityURL.js b/src/functions/guild/guildVanityURL.js new file mode 100644 index 000000000..a6a3717aa --- /dev/null +++ b/src/functions/guild/guildVanityURL.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.vanityURLCode ? `discord.gg/${guild.vanityURLCode}` : 'undefined'; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildVanityUses.js b/src/functions/guild/guildVanityUses.js new file mode 100644 index 000000000..5c8060cff --- /dev/null +++ b/src/functions/guild/guildVanityUses.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.vanityURLUses; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildVerificationLevel.js b/src/functions/guild/guildVerificationLevel.js new file mode 100644 index 000000000..85d4d5bfd --- /dev/null +++ b/src/functions/guild/guildVerificationLevel.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.verificationLevel; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/guildWidgetChannelID.js b/src/functions/guild/guildWidgetChannelID.js new file mode 100644 index 000000000..52d376a08 --- /dev/null +++ b/src/functions/guild/guildWidgetChannelID.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.widgetChannelId || "none"; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/hasAnyPerm.js b/src/functions/guild/hasAnyPerm.js new file mode 100644 index 000000000..2976f381c --- /dev/null +++ b/src/functions/guild/hasAnyPerm.js @@ -0,0 +1,25 @@ +const {Perms} = require("../../utils/Constants.js"); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID, userID, ...perms] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + perms = perms.map(x => Perms[x]); + if (perms.includes(undefined)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Permission Provided In"); + + const memPerms = member.permissions; + + data.result = memPerms.has(Perms.administrator) ? true : perms.some(x => memPerms.has(x)); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/hasAnyRole.js b/src/functions/guild/hasAnyRole.js new file mode 100644 index 000000000..6a5850a78 --- /dev/null +++ b/src/functions/guild/hasAnyRole.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID, userID, ...roles] = data.inside.splits; + + roles = roles.map(x => x.toLowerCase()); + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + const memRoles = member.roles.cache + + data.result = roles.some(x => memRoles.has(x) || memRoles.find(y => y.name.toLowerCase() === x)); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/hasEmbeds.js b/src/functions/guild/hasEmbeds.js new file mode 100644 index 000000000..4890474ab --- /dev/null +++ b/src/functions/guild/hasEmbeds.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + data.result = message.embeds.length ? true : false; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/hasPerms.js b/src/functions/guild/hasPerms.js new file mode 100644 index 000000000..278143990 --- /dev/null +++ b/src/functions/guild/hasPerms.js @@ -0,0 +1,25 @@ +const {Perms} = require("../../utils/Constants.js"); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID, userID, ...perms] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + perms = perms.map(x => Perms[x]); + if (perms.includes(undefined)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Permission Provided In"); + + const memPerms = member.permissions + + data.result = memPerms.has(Perms.administrator) ? true : perms.every(x => memPerms.has(x)); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/hasPermsInChannel.js b/src/functions/guild/hasPermsInChannel.js new file mode 100644 index 000000000..4d300364e --- /dev/null +++ b/src/functions/guild/hasPermsInChannel.js @@ -0,0 +1,36 @@ +const {Perms} = require("../../utils/Constants.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID, roleoruserId, ...perms] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID, true); + if (!channel) + return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const pms = perms.map((key) => Perms[key]); + if (pms.includes(undefined)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Invalid Permissions In`, + ); + + const upms = channel.permissionsFor(roleoruserId); + + if (!upms) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Role or User not found`, + ); + + data.result = upms.has(Perms.administrator) ? true : upms && pms.every((p) => upms.has(p)); + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/hasRoles.js b/src/functions/guild/hasRoles.js new file mode 100644 index 000000000..2fa5dcf92 --- /dev/null +++ b/src/functions/guild/hasRoles.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID, userID, ...roles] = data.inside.splits; + + roles = roles.map(x => x.toLowerCase()); + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + const memRoles = member.roles.cache + + data.result = roles.every(x => memRoles.has(x) || memRoles.find(y => y.name.toLowerCase() === x)); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/joinThread.js b/src/functions/guild/joinThread.js new file mode 100644 index 000000000..e5919a1c6 --- /dev/null +++ b/src/functions/guild/joinThread.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, threadID] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const thread = channel.threads.cache.get(threadID); + if (!thread) return d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid ThreadID Provided In"); + + thread.join() + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/leaveThread.js b/src/functions/guild/leaveThread.js new file mode 100644 index 000000000..700b4c685 --- /dev/null +++ b/src/functions/guild/leaveThread.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, threadID] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const thread = channel.threads.cache.get(threadID); + if (!thread) return d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid ThreadID Provided In"); + + thread.leave(); + + return { + code: d.util.setCode(data) + } + +} \ No newline at end of file diff --git a/src/functions/guild/lockThread.js b/src/functions/guild/lockThread.js new file mode 100644 index 000000000..0f71ce806 --- /dev/null +++ b/src/functions/guild/lockThread.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, threadID, reason] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}) + + const thread = channel.threads.cache.get(threadID); + if (!thread) return d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid ThreadID Provided In") + + await thread.setLocked(true, reason); + + return { + code: d.util.setCode(data) + } + +} \ No newline at end of file diff --git a/src/functions/guild/messagePublish.js b/src/functions/guild/messagePublish.js new file mode 100644 index 000000000..7603961b6 --- /dev/null +++ b/src/functions/guild/messagePublish.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = messageID === d.message?.id ? d.message : await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + message.crosspost().catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Faild To Publish The Message With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/modifyChannelPerms.js b/src/functions/guild/modifyChannelPerms.js new file mode 100644 index 000000000..afa26b6d0 --- /dev/null +++ b/src/functions/guild/modifyChannelPerms.js @@ -0,0 +1,26 @@ +const {FormatPerms: Perms} = require('../../utils/Constants.js') + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID = d.channel?.id, roleoruserID, ...perms] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + let objPerms = {}; + + for (const perm of perms) { + const sign = perm.slice(0, 1); + objPerms[Perms[perm.slice(1)]] = sign === '+' ? true : sign === '/' ? null : false; + } + + channel.permissionOverwrites.edit(roleoruserID, objPerms).catch(e => { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Failed To Modify Channel Perms With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/modifyEmoji.js b/src/functions/guild/modifyEmoji.js new file mode 100644 index 000000000..ab6b2a52e --- /dev/null +++ b/src/functions/guild/modifyEmoji.js @@ -0,0 +1,22 @@ +const {ReactionUserManager} = require("discord.js"); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, emojiId, name, ...roles] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const emoji = await d.util.getEmoji(guild, emojiId) + if (!emoji) return d.aoiError.fnError(d, 'emoji', {inside: data.inside}); + + emoji.edit({name: name.addBrackets(), roles: roles}).catch(e => { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Failed To Modify Emoji With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/modifyRole.js b/src/functions/guild/modifyRole.js new file mode 100644 index 000000000..746fc639b --- /dev/null +++ b/src/functions/guild/modifyRole.js @@ -0,0 +1,40 @@ +const {ReactionUserManager} = require("discord.js"); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, roleID, ...roleDatas] = data.inside.splits; + let RoleData; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(e => undefined); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + + if (roleDatas.length === 1) { + try { + RoleData = JSON.parse(roleDatas[0].addBrackets()); + } catch (e) { + } + } else { + RoleData = { + name: roleDatas[0]?.addBrackets(), + color: roleDatas[1]?.addBrackets(), + hoist: roleDatas[2] === 'true', + position: roleDatas[3] === '$default' ? role.position : Number(roleDatas[3]), + mentionable: roleDatas[4] === 'true', + icon: roleDatas[5]?.addBrackets(), + unicodeEmoji: roleDatas[6]?.addBrackets() + } + } + + role.edit(RoleData).catch(e => { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Failed To Modify Role With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/modifyRolePerms.js b/src/functions/guild/modifyRolePerms.js new file mode 100644 index 000000000..827cd94cc --- /dev/null +++ b/src/functions/guild/modifyRolePerms.js @@ -0,0 +1,40 @@ +const {Perms} = require('../../utils/Constants.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, roleID, ...perms] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(e => undefined); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + + let arrayPerms = role.permissions; + if (perms.includes('+all')) { + arrayPerms = ['Administrator']; + } else if (perms.includes('-all')) { + arrayPerms = []; + } else { + for (const perm of perms) { + const sign = perm.slice(0, 1); + + if (sign === '+') { + arrayPerms.add(Perms[perm.slice(1)]); + } else if (sign === '-') { + arrayPerms.remove(Perms[perm.slice(1)]); + } + arrayPerms = Array.from(arrayPerms); + } + } + + role.setPermissions(arrayPerms).catch(e => { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Failed To Modify Channel Perms With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/modifyWebhook.js b/src/functions/guild/modifyWebhook.js new file mode 100644 index 000000000..7854c02c4 --- /dev/null +++ b/src/functions/guild/modifyWebhook.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [webhookId, name, avatar, channelID = d.channel?.id, reason] = data.inside.splits; + + const webhook = await d.client.fetchWebhook(webhookId).catch(e => { + return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Id Provided In'); + }); + + webhook.edit({ + name: name.addBrackets(), + avatar: avatar.addBrackets(), + channel: channelID + }, reason?.addBrackets()).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Modify Webhook With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/referenceChannelID.js b/src/functions/guild/referenceChannelID.js new file mode 100644 index 000000000..b064b1d10 --- /dev/null +++ b/src/functions/guild/referenceChannelID.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.message?.reference.channelId + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/referenceGuildID.js b/src/functions/guild/referenceGuildID.js new file mode 100644 index 000000000..52bd4648a --- /dev/null +++ b/src/functions/guild/referenceGuildID.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.message?.reference?.guildId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/referenceMessageID.js b/src/functions/guild/referenceMessageID.js new file mode 100644 index 000000000..d69e69a6d --- /dev/null +++ b/src/functions/guild/referenceMessageID.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.message?.reference?.messageId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/removeRole.js b/src/functions/guild/removeRole.js new file mode 100644 index 000000000..6954489c9 --- /dev/null +++ b/src/functions/guild/removeRole.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, userID, roleID, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + member.roles.remove(roleID, reason).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Remove Role With Reason: ' + err); + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/removeRoles.js b/src/functions/guild/removeRoles.js new file mode 100644 index 000000000..dfad7b835 --- /dev/null +++ b/src/functions/guild/removeRoles.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, userID, reason, ...roleID] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + member.roles.remove(roleID, reason).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Remove Role With Reason: ' + err); + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/roleCount.js b/src/functions/guild/roleCount.js new file mode 100644 index 000000000..7c4e3dbf4 --- /dev/null +++ b/src/functions/guild/roleCount.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, fetchFirst = 'false'] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + if (fetchFirst === 'true') { + guild.roles.fetch(); + } + + data.result = guild.roles.cache.size; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/roleMembersCount.js b/src/functions/guild/roleMembersCount.js new file mode 100644 index 000000000..3930c512b --- /dev/null +++ b/src/functions/guild/roleMembersCount.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(err => { + d.aoiError.fnError(d, 'role', {inside: data.inside}) + }); + + data.result = role.members.size + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/roleName.js b/src/functions/guild/roleName.js new file mode 100644 index 000000000..a772fdc0c --- /dev/null +++ b/src/functions/guild/roleName.js @@ -0,0 +1,21 @@ +const {Role} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(err => { + d.aoiError.fnError(d, 'role', {inside: data.inside}); + }); + + data.result = role.name.deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/rolePerms.js b/src/functions/guild/rolePerms.js new file mode 100644 index 000000000..7e5569f3c --- /dev/null +++ b/src/functions/guild/rolePerms.js @@ -0,0 +1,23 @@ +const {FormatPerms: Perms} = require('../../utils/Constants.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, sep = ' , ', guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(err => { + d.aoiError.fnError(d, 'role', {inside: data.inside}); + }); + + const PERMS = Object.entries(Perms); + + data.result = role.permissions.toArray().map(y => PERMS.find(x => x[1] === y)?.[0]).join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/rolePosition.js b/src/functions/guild/rolePosition.js new file mode 100644 index 000000000..f9270b096 --- /dev/null +++ b/src/functions/guild/rolePosition.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(err => { + d.aoiError.fnError(d, 'role', {inside: data.inside}); + }); + + data.result = guild.roles.cache.size - role.position; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/setChannelTopic.js b/src/functions/guild/setChannelTopic.js new file mode 100644 index 000000000..ec56498fa --- /dev/null +++ b/src/functions/guild/setChannelTopic.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID, topic] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + channel.setTopic(topic.addBrackets()).catch(err => { + d.aoiError.fnError(d, 'custom', {}, `Failed To Set Channel Topic With Reason: ${err}`); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/setGuildBanner.js b/src/functions/guild/setGuildBanner.js new file mode 100644 index 000000000..4bcbbbae2 --- /dev/null +++ b/src/functions/guild/setGuildBanner.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, url, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + try { + await guild.setBanner(url, reason); + data.result = ""; + } catch (err) { + d.aoiError.fnError(d, "custom", {}, err.message) + } + + return { + code: d.util.setCode(data), + }; +} \ No newline at end of file diff --git a/src/functions/guild/setGuildDiscoverySplash.js b/src/functions/guild/setGuildDiscoverySplash.js new file mode 100644 index 000000000..b1309c072 --- /dev/null +++ b/src/functions/guild/setGuildDiscoverySplash.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, url, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + try { + await guild.setDiscoverySplash(url, reason); + data.result = ""; + } catch (err) { + d.aoiError.fnError(d, "custom", {}, err.message) + } + + return { + code: d.util.setCode(data), + }; +} \ No newline at end of file diff --git a/src/functions/guild/setGuildIcon.js b/src/functions/guild/setGuildIcon.js new file mode 100644 index 000000000..c5b3e753a --- /dev/null +++ b/src/functions/guild/setGuildIcon.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [avatar, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + guild.setIcon(avatar.addBrackets()).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Set Guild Icon With Reason: ' + err); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/setGuildName.js b/src/functions/guild/setGuildName.js new file mode 100644 index 000000000..2f5123a78 --- /dev/null +++ b/src/functions/guild/setGuildName.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + guild.setName(name.addBrackets()).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Set Guild Name With Reason: ' + err); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/setRoleColor.js b/src/functions/guild/setRoleColor.js new file mode 100644 index 000000000..80a636bee --- /dev/null +++ b/src/functions/guild/setRoleColor.js @@ -0,0 +1,20 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, color] = data.inside.splits; + + const role = d.guild.roles.cache.get(roleID); + if (!role) return d.error(`${d.func}: Invalid role ID in ${data.inside}`); + + const re = await role.setColor(color).catch((err) => { + }); + if (!re) + return d.error( + `${d.func}: Failed to change ${role.name} color to ${color}!`, + ); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/guild/setRoleIcon.js b/src/functions/guild/setRoleIcon.js new file mode 100644 index 000000000..7557762d2 --- /dev/null +++ b/src/functions/guild/setRoleIcon.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + const [guildID = d.guild?.id, roleID, icon] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + + await role.setIcon(icon.addBrackets()).catch(err => { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, `Failed to change \`${role.name}\` icon to \`${icon}\` with Reason: ${err}`); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/setRolePosition.js b/src/functions/guild/setRolePosition.js new file mode 100644 index 000000000..484bd8f42 --- /dev/null +++ b/src/functions/guild/setRolePosition.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + const [guildID = d.guild?.id, roleID, newPosition] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + + await role.setPosition(newPosition).catch((err) => { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, `Failed to change \`${role.name}\` position to \`${newPosition}\` with Reason: ${err}`); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/guild/setRoles.js b/src/functions/guild/setRoles.js new file mode 100644 index 000000000..2f2f37476 --- /dev/null +++ b/src/functions/guild/setRoles.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, memberId, reason, ...roleIds] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, memberId); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + member.roles.set(roleIds, reason).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Set Roles With Reason: ' + err); + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/guild/unlockThread.js b/src/functions/guild/unlockThread.js new file mode 100644 index 000000000..fea63d813 --- /dev/null +++ b/src/functions/guild/unlockThread.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, threadID, reason] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}) + + const thread = channel.threads.cache.get(threadID); + if (!thread) return d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid ThreadID Provided In") + + await thread.setLocked(false, reason); + + return { + code: d.util.setCode(data) + } + +} \ No newline at end of file diff --git a/src/functions/info/allChannelsCount.js b/src/functions/info/allChannelsCount.js new file mode 100644 index 000000000..4151b7653 --- /dev/null +++ b/src/functions/info/allChannelsCount.js @@ -0,0 +1,14 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + let [type] = data.inside.splits + + type = d.util.channelTypes[type] ?? type; + data.result = type + ? d.client.channels.cache.filter((x) => + type === "NSFW" ? (x.nsfw === true) : (x.type === type), + ).size + : d.client.channels.cache.size; + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/info/allEmojisCount.js b/src/functions/info/allEmojisCount.js new file mode 100644 index 000000000..d6e1ab5d5 --- /dev/null +++ b/src/functions/info/allEmojisCount.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + let [type] = data.inside.splits; + data.result = type + ? d.client.emojis.cache.filter((x) => + type === "animated" + ? x.animated + : type === "roles" + ? x.roles.cache.size + : type === "normal" + ? !x.animated + : x[type], + ).size + : d.client.emojis.cache.size; + return { + code: d.util.setCode(data) + }; +}; \ No newline at end of file diff --git a/src/functions/info/allMembersCount.js b/src/functions/info/allMembersCount.js new file mode 100644 index 000000000..f57f6f09a --- /dev/null +++ b/src/functions/info/allMembersCount.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + data.result = d.client.guilds.cache.map(x => x.memberCount ?? 0).reduce((a, b) => a + b, 0) + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/banCount.js b/src/functions/info/banCount.js new file mode 100644 index 000000000..dc3304724 --- /dev/null +++ b/src/functions/info/banCount.js @@ -0,0 +1,16 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + let [guildID = d.guild.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID) + let result; + data.result = await guild.bans.fetch().catch(err => { + result = 0; + d.aoiError.fnError(d, "custom", {}, "Failed To Fetch Bans"); + }) + data.result = isNaN(data.result) ? data.result.size : data.result; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/info/boostingSince.js b/src/functions/info/boostingSince.js new file mode 100644 index 000000000..aeb66dc4b --- /dev/null +++ b/src/functions/info/boostingSince.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + let [guildID = d.guild?.id, userID = d.author.id, format = "ms"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID) + if (d.channel.type !== d.util.channelTypes.DM && !guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const user = !guild ? true : await d.util.getMember(guild, userID); + if (!user) return d.aoiError.fnError(d, "user", {inside: data.inside}); + + data.result = (user === true ? + 0 : + (format === "date" ? + user.premiumSince : + user.premiumSinceTimestamp) + ) ?? 0; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/commandCode.js b/src/functions/info/commandCode.js new file mode 100644 index 000000000..8efffc945 --- /dev/null +++ b/src/functions/info/commandCode.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const {name, code} = d.command; + + return { + code: d.util.setCode({function: d.func, code, result: code}) + } +} \ No newline at end of file diff --git a/src/functions/info/commandInfo.js b/src/functions/info/commandInfo.js new file mode 100644 index 000000000..aa0d52599 --- /dev/null +++ b/src/functions/info/commandInfo.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, option] = data.inside.splits; + + const cmd = d.client.cmd.default.find(x => (x.name.toLowerCase() === name.toLowerCase()) || (Array.isArray(x.aliases) ? x.aliases?.includes(name.toLowerCase()) : (x.aliases?.toLowerCase() === name.toLowerCase()))); + + try { + data.result = eval(`cmd?.${option}`) + } catch (e) { + data.result = "" + } + return { + code: d.util.setCode(data), + } +} \ No newline at end of file diff --git a/src/functions/info/commandName.js b/src/functions/info/commandName.js new file mode 100644 index 000000000..0310e9146 --- /dev/null +++ b/src/functions/info/commandName.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const {name, code} = d.command; + + return { + code: d.util.setCode({function: d.func, code, result: name}) + } +} \ No newline at end of file diff --git a/src/functions/info/commandsCount.js b/src/functions/info/commandsCount.js new file mode 100644 index 000000000..d0d1669e4 --- /dev/null +++ b/src/functions/info/commandsCount.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const {code} = d.command; + + return { + code: d.util.setCode({function: d.func, code, result: d.client.cmd.default.size}) + } +} \ No newline at end of file diff --git a/src/functions/info/cpu.js b/src/functions/info/cpu.js new file mode 100644 index 000000000..2cbe9cf7d --- /dev/null +++ b/src/functions/info/cpu.js @@ -0,0 +1,39 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [method = "process"] = data.inside.splits; + + if (!["process", "os"].includes(method)) { + return d.aoiError.fnError(d, "option", {inside: data.inside}); + } + + const initial = process.cpuUsage(); + + if (method === "process") { + const start = Date.now(); + + if ((start - (d.client.aoiOptions.cpu?.time || 0)) > 5000) { + while (Date.now() - start > 1) ; + const final = process.cpuUsage(initial); + data.result = ((final.user + final.system) / 1000).toFixed(2); + d.client.aoiOptions.cpu = { + time: start, + usage: data.result + }; + } else { + data.result = d.client.aoiOptions.cpu?.usage; + } + } else { + const cpus = require('os').cpus(); + const avgs = cpus.map(cpu => { + const total = Object.values(cpu.times).reduce((a, b) => a + b); + const nonIdle = total - cpu.times.idle; + return nonIdle / total; + }); + data.result = (avgs.reduce((a, b) => a + b) / cpus.length).toFixed(2); + } + + return { + code: d.util.setCode(data) + } +}; diff --git a/src/functions/info/customEmoji.js b/src/functions/info/customEmoji.js new file mode 100644 index 000000000..1faa58c3f --- /dev/null +++ b/src/functions/info/customEmoji.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [emoji, id = "global"] = inside.splits; + emoji = emoji.addBrackets(); + let result; + + if (id === "global") { + result = (await d.util.getEmoji(d, emoji)).toString(); + } else { + result = d.client.guilds.cache.get(id)?.emojis.cache.find(x => x.name.toLowerCase() === emoji.toLowerCase() || x.toString() === emoji || x.id === emoji)?.toString() + } + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/info/databasePing.js b/src/functions/info/databasePing.js new file mode 100644 index 000000000..4ec8e2d00 --- /dev/null +++ b/src/functions/info/databasePing.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + data.result = d.client.db.ping + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/date.js b/src/functions/info/date.js new file mode 100644 index 000000000..4b00d1d9c --- /dev/null +++ b/src/functions/info/date.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const {code} = d.util.aoiFunc(d); + + return { + code: d.util.setCode({function: d.func, code, result: new Date().getDate()}) + } +} \ No newline at end of file diff --git a/src/functions/info/datestamp.js b/src/functions/info/datestamp.js new file mode 100644 index 000000000..c961a9638 --- /dev/null +++ b/src/functions/info/datestamp.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const {code} = d.util.aoiFunc(d); + + return { + code: d.util.setCode({function: d.func, code, result: Date.now()}) + } +} \ No newline at end of file diff --git a/src/functions/info/day.js b/src/functions/info/day.js new file mode 100644 index 000000000..1f285ab20 --- /dev/null +++ b/src/functions/info/day.js @@ -0,0 +1,8 @@ +module.exports = async d => { + const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']; + const {code} = d.util.aoiFunc(d); + + return { + code: d.util.setCode({function: d.func, code, result: days[new Date().getDay()]}) + } +} \ No newline at end of file diff --git a/src/functions/info/emojiCount.js b/src/functions/info/emojiCount.js new file mode 100644 index 000000000..bc9d0c2d7 --- /dev/null +++ b/src/functions/info/emojiCount.js @@ -0,0 +1,28 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + let [guildID, type, force = "false"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + if (force === "true") { + guild.emojis.fetch(); + } + + data.result = type + ? guild.emojis.cache.filter((x) => + type === "animated" + ? x.animated + : type === "roles" + ? x.roles.cache.size + : type === "normal" + ? !x.animated + : type === "all" + ? true + : x[type], + ).size + : guild.emojis.cache.size; + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/info/getAttachments.js b/src/functions/info/getAttachments.js new file mode 100644 index 000000000..143f3a189 --- /dev/null +++ b/src/functions/info/getAttachments.js @@ -0,0 +1,21 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID, messageID, index = 1, option = 'url'] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + const attachments = [...message.attachments.values()]; + if (!attachments.length) return d.aoiError.fnError(d, 'custom', {}, "Message Doesn't Have Any Attachments"); + + data.result = attachments[index - 1][option]; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/info/getAuditLogs.js b/src/functions/info/getAuditLogs.js new file mode 100644 index 000000000..b4b88d673 --- /dev/null +++ b/src/functions/info/getAuditLogs.js @@ -0,0 +1,54 @@ +module.exports = async (d) => { + const {AuditLogEvent} = require("discord.js"); + const data = d.util.aoiFunc(d); + + let [ + guildID = d.guild?.id, + userID = d.author?.id, + limit = 5, + action, + format = "{executor.username}: {target.id} - {action}" + ] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + limit = Number(limit); + if (isNaN(limit)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Index Provided In" + ); + + const audit = await guild.fetchAuditLogs({ + limit, + user: userID === "" ? undefined : userID, + type: action === "" ? undefined : action + }) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Get Audit Logs With Reason: " + e + ); + }); + data.result = audit.entries + .map((logs) => { + return format + .replaceAll(`{executor.username}`, logs.executor.username) + .replaceAll(`{executor.mention}`, logs.executor) + .replaceAll(`{executor.id}`, logs.executor?.id) + .replaceAll(`{executor.tag}`, logs.executor?.tag) + .replaceAll("{target.id}", logs.target?.id) + .replaceAll("{reason}", logs.reason) + .replaceAll("{action}", AuditLogEvent[logs.action]) + .replaceAll("{id}", logs.id); + } + ).join("\n"); + + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/info/getBanReason.js b/src/functions/info/getBanReason.js new file mode 100644 index 000000000..d3b7b6c05 --- /dev/null +++ b/src/functions/info/getBanReason.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id,] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + let banned = await guild.bans.fetch(userID).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Get Ban Data With Reason: ' + e); + }); + + data.result = banned?.reason; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/getChannelSlowmode.js b/src/functions/info/getChannelSlowmode.js new file mode 100644 index 000000000..5d101576f --- /dev/null +++ b/src/functions/info/getChannelSlowmode.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + data.result = channel.rateLimitPerUser || 0; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/getEmbed.js b/src/functions/info/getEmbed.js new file mode 100644 index 000000000..931162736 --- /dev/null +++ b/src/functions/info/getEmbed.js @@ -0,0 +1,25 @@ +const {EmbedData} = require('../../utils/helpers/functions.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let [channelID = d.channel?.id, messageID = d.message?.id, index = 1, option = 'description'] = data.inside.splits; + index = index - 1; + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + const embedData = EmbedData(message.embeds[index], message.embeds) + try { + data.result = eval(`embedData?.${option}`); + + data.result = typeof data.result === 'object' ? JSON.stringify(data.result, null, 2) : data.result; + } catch (e) { + data.result = '' + } + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/getMessage.js b/src/functions/info/getMessage.js new file mode 100644 index 000000000..73c999357 --- /dev/null +++ b/src/functions/info/getMessage.js @@ -0,0 +1,25 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID = d.channel?.id, messageID = d.message?.id, option = 'content'] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + const msg = { + content: message.content, + userid: message.author?.id, + usertag: message.author?.tag, + username: message.author?.username + } + + data.result = msg[option.addBrackets().toLowerCase()] + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/getReactions.js b/src/functions/info/getReactions.js new file mode 100644 index 000000000..b4e1a6988 --- /dev/null +++ b/src/functions/info/getReactions.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID, messageID, reaction, force = "false", option = "username"] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "message", {inside: data.inside}); + + const reactions = message.reactions.cache.find(x => x.emoji.toString() === reaction.addBrackets()); + + if (force === "true") await reactions?.users?.fetch(); + + data.result = reactions?.users?.cache.map(x => option.toLowerCase() === "mention" ? x.toString() : x[option.toLowerCase()]) || "none"; + + return { + code: d.util.setCode(data), + } +} \ No newline at end of file diff --git a/src/functions/info/interactionPing.js b/src/functions/info/interactionPing.js new file mode 100644 index 000000000..41a1f877c --- /dev/null +++ b/src/functions/info/interactionPing.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const {code} = d.util.aoiFunc(d); + + return { + code: d.util.setCode({ + function: d.func, + code, + result: Math.abs(Date.now() - d.data.interaction?.createdTimestamp) + }) + } +} \ No newline at end of file diff --git a/src/functions/info/maxRam.js b/src/functions/info/maxRam.js new file mode 100644 index 000000000..27923ddb4 --- /dev/null +++ b/src/functions/info/maxRam.js @@ -0,0 +1,11 @@ +const os = require('os'); + +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = (os.totalmem() / 1024 / 1024).toFixed(2); + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/info/ping.js b/src/functions/info/ping.js new file mode 100644 index 000000000..00e576c3c --- /dev/null +++ b/src/functions/info/ping.js @@ -0,0 +1,9 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.client.ws.ping; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/reactionCount.js b/src/functions/info/reactionCount.js new file mode 100644 index 000000000..2bd7ca699 --- /dev/null +++ b/src/functions/info/reactionCount.js @@ -0,0 +1,28 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID, messageID, emojiResolver] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside }); + + let emoji; + + try { + emoji = message.reactions.cache.find((x) => x.emoji.id === d.util.getEmoji(d, emojiResolver).id)?.count; + } catch { + emoji = message.reactions.cache.find((x) => x.emoji.toString().toLowerCase() === emojiResolver.toLowerCase())?.count; + } finally { + emoji = emoji ?? 0; + } + + data.result = emoji; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/info/readyTimestamp.js b/src/functions/info/readyTimestamp.js new file mode 100644 index 000000000..5a656d734 --- /dev/null +++ b/src/functions/info/readyTimestamp.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const {code} = d.command; + const result = d.client?.readyTimestamp + return { + code: d.util.setCode({function: d.func, code, result}) + } +} diff --git a/src/functions/info/uptime.js b/src/functions/info/uptime.js new file mode 100644 index 000000000..08bfc2ab3 --- /dev/null +++ b/src/functions/info/uptime.js @@ -0,0 +1,13 @@ +const {Time} = require('../../utils/helpers/customParser.js'); + +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [option = 'full'] = data.inside.splits; + + data.result = option === 'ms' ? d.client.uptime : option === 'humanize' ? Time.format(d.client.uptime).humanize() : Time.format(d.client.uptime).toString(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/uri.js b/src/functions/info/uri.js new file mode 100644 index 000000000..72eea621e --- /dev/null +++ b/src/functions/info/uri.js @@ -0,0 +1,11 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [text, type = 'encode'] = data.inside.splits; + + data.result = type === 'encode' ? encodeURIComponent(text.addBrackets()) : decodeURIComponent(text.addBrackets()); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/voiceID.js b/src/functions/info/voiceID.js new file mode 100644 index 000000000..0e0efa40c --- /dev/null +++ b/src/functions/info/voiceID.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.voice.channelId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/info/webhookExists.js b/src/functions/info/webhookExists.js new file mode 100644 index 000000000..7e7d2a7d3 --- /dev/null +++ b/src/functions/info/webhookExists.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [id, token = null] = data.inside.splits; + + const webhook = await d.client.fetchWebhook(id, token).catch(err => { + }); + + data.result = !!webhook; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/interaction/addApplicationCommandPermissions.js b/src/functions/interaction/addApplicationCommandPermissions.js new file mode 100644 index 000000000..052517246 --- /dev/null +++ b/src/functions/interaction/addApplicationCommandPermissions.js @@ -0,0 +1,48 @@ +const {ApplicationCommandPermissionType} = require("discord.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID = "global", id, ...perms] = data.inside.splits; + + let permissions = []; + if (perms.length === 1) { + try { + permissions = JSON.parse(perms); + } catch { + const e = perms[0].split(":"); + permissions.push({ + id: e[0], + type: ApplicationCommandPermissionType[e[1]], + permission: e[2] === "true", + }); + } + } else { + const e = perms[0].split(":"); + permissions.push({ + id: e[0], + type: ApplicationCommandPermissionType[e[1]], + permission: e[2] === "true", + }); + } + + if (guildID == "global") { + d.client.application.commands.permissions.add({ + command: id, + permissions, + token: d.client.token, + }); + } else { + d.client.application.commands.permissions.add({ + guild: guildID, + command: id, + permissions, + token: d.client.token, + }); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/addButton.js b/src/functions/interaction/addButton.js new file mode 100644 index 000000000..66d09eacd --- /dev/null +++ b/src/functions/interaction/addButton.js @@ -0,0 +1,43 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + if (data.err) return d.error(data.err); + + let [index, label, style, custom, disabled = "false", emoji] = data.inside.splits; + + if (isNaN(index) || Number(index) < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Index"); + + index = Number(index) - 1; + style = isNaN(style) ? d.util.constants.ButtonStyleOptions[style] : Number(style); + disabled = disabled === "true"; + + if (!style || style > 5 || style < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Style"); + + try { + emoji = d.util.getEmoji(d, emoji.addBrackets()).id; + } catch { + emoji = emoji?.addBrackets() ?? undefined; + } + + const button = { + label, + type: 2, + style, + disabled, + emoji, + }; + + button[style === 5 ? "url" : "customId"] = custom; + + if (!d.components[index]) d.components[index] = { type: 1, components: [] }; + d.components[index].components.push(button); + + return { + code: d.util.setCode({ function: d.func, inside: data.inside, code }), + data: { + ...d.data, + components: Object.assign({}, d.data.components, d.components), + }, + components: d.components, + }; +}; diff --git a/src/functions/interaction/addClientReactions.js b/src/functions/interaction/addClientReactions.js new file mode 100644 index 000000000..e49f5b248 --- /dev/null +++ b/src/functions/interaction/addClientReactions.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [...reactions] = data.inside.splits; + + reactions = reactions.map((x) => { + try { + let emoji = d.util.getEmoji(d, x.addBrackets()); + x = emoji.id ? `:${emoji.name}:${emoji.id}` : emoji.name; + } catch { + x = x?.addBrackets() ?? undefined; + } finally { + if (x === undefined) return d.util.aoiError.fnError(d, "custom", { inside: data.inside }, "Emoji"); + } + return x; + }); + + data.result = ""; + + return { + code: d.util.setCode(data), + reactions, + }; +}; diff --git a/src/functions/interaction/addCmdReactions.js b/src/functions/interaction/addCmdReactions.js new file mode 100644 index 000000000..3238c2677 --- /dev/null +++ b/src/functions/interaction/addCmdReactions.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [...reactions] = data.inside.splits; + reactions = reactions.reverse(); + + for (let i = reactions.length - 1; i >= 0; i--) { + let reaction; + try { + reaction = d.util.getEmoji(d, reactions[i].addBrackets()).id; + } catch { + reaction = reactions[i]?.addBrackets() ?? undefined; + } finally { + if (reaction === undefined) return d.util.aoiError.fnError(d, "custom", { inside: data.inside}, "Emoji"); + } + await d.message.react(reaction).catch((err) => d.aoiError.fnError(d, "custom", {}, err.message)); + } + + data.result = ""; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/addMessageReactions.js b/src/functions/interaction/addMessageReactions.js new file mode 100644 index 000000000..22fa0f81a --- /dev/null +++ b/src/functions/interaction/addMessageReactions.js @@ -0,0 +1,32 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID, messageID, ...reactions] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID); + + if (!channel) + return d.aoiError.fnError(d, "channel", { inside: data.inside }); + const message = await d.util.getMessage(channel, messageID); + + if (!message) + return d.aoiError.fnError(d, "message", { inside: data.inside }); + reactions = reactions.reverse(); + + for (let i = reactions.length - 1; i >= 0; i--) { + let reaction; + try { + reaction = d.util.getEmoji(d, reactions[i].addBrackets()).id; + } catch { + reaction = reactions[i]?.addBrackets() ?? undefined; + } finally { + if (reaction === undefined) return d.util.aoiError.fnError(d, "custom", { inside: data.inside }, "Emoji" ); + } + await message.react(reaction).catch((err) => d.aoiError.fnError(d, "custom", {}, err.message)); + } + + data.result = ""; + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/addSelectMenu.js b/src/functions/interaction/addSelectMenu.js new file mode 100644 index 000000000..2a9c51926 --- /dev/null +++ b/src/functions/interaction/addSelectMenu.js @@ -0,0 +1,107 @@ +const { StringSelectMenuBuilder, UserSelectMenuBuilder, RoleSelectMenuBuilder, MentionableSelectMenuBuilder, ChannelSelectMenuBuilder } = require("discord.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + if (data.err) return d.error(data.err); + + let [ index = 1, type, customId, placeholder, minValues = 1, maxValues = 1, disabled = "false", ...options ] = data.inside.splits; + + index = Number(index) - 1; + + if (isNaN(index) || index < 0) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Index"); + + disabled = disabled === "true"; + placeholder = placeholder?.addBrackets(); + customId = customId?.addBrackets(); + minValues = Number(minValues); + maxValues = Number(maxValues); + + if (!options.length && type === "string") return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Options Are Not Provided In"); + + if (minValues > 25 || minValues < 0) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "minValues must be between 0 and 25 (both inclusive)."); + + if (maxValues > 25 || maxValues < 1) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "maxValues must be between 1 and 25 (both Inclusive)."); + + if (placeholder.length > 100) return d.aoiError.fnError(d, "custom", {}, "Placeholder should be at most 100 Characters long"); + + let selectBuilder; + + switch (type.toLowerCase()) { + case "string": + selectBuilder = new StringSelectMenuBuilder(); + break; + case "user": + selectBuilder = new UserSelectMenuBuilder(); + break; + case "role": + selectBuilder = new RoleSelectMenuBuilder(); + break; + case "mentionable": + selectBuilder = new MentionableSelectMenuBuilder(); + break; + case "channel": + selectBuilder = new ChannelSelectMenuBuilder(); + break; + default: + return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Select Menu Type"); + } + + selectBuilder + .setCustomId(customId) + .setPlaceholder(placeholder) + .setMaxValues(maxValues) + .setMinValues(minValues) + .setDisabled(disabled); + + for (let option of options) { + option = option.split(":"); + const label = option[0].addBrackets(); + const description = option[1].addBrackets(); + const value = option[2].addBrackets(); + const def = option[3]?.addBrackets() === "true"; + let emoji; + + try { + emoji = d.util.getEmoji(d, option[4]?.addBrackets()).id; + } catch { + emoji = option[4]?.addBrackets() ?? undefined; + } + + switch (type.toLowerCase()) { + case "string": + selectBuilder.addOptions({ + label, + description, + value, + default: def, + emoji, + }); + break; + case "user": + case "role": + case "mentionable": + case "channel": + selectBuilder.addOption({ + label, + value, + type: type.toUpperCase(), + }); + break; + default: + d.aoiError.fnError(d, "custom", { inside: data.inside }, "Select Menu Type"); + } + } + + d.components[index] = d.components[index] || { type: 1, components: [] }; + d.components[index].components.push(selectBuilder); + + return { + code: d.util.setCode({ function: d.func, code, inside: data.inside }), + data: { + ...d.data, + components: Object.assign({}, d.data.components, d.components), + }, + components: d.components, + }; +}; diff --git a/src/functions/interaction/autoCompleteRespond.js b/src/functions/interaction/autoCompleteRespond.js new file mode 100644 index 000000000..dd3353d34 --- /dev/null +++ b/src/functions/interaction/autoCompleteRespond.js @@ -0,0 +1,46 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [...options] = data.inside.splits; + + let opt; + if (options.length === 1) { + try { + opt = JSON.parse(options[0].addBrackets()); + if (!Array.isArray(opt)) opt = [opt]; + } catch (e) { + console.error(e) + return d.aoiError.fnError(d, "custom", {}, `Invalid JSON: ${options[0]}`); + } + } else { + opt = []; + let i = 0, + u = 0; + while (i < options.length) { + opt[u] = { + name: options[i], + value: options[i + 1], + }; + u++; + i += 2; + } + } + + if (opt.length > 25) { + opt = opt.slice(0, 25); + } + + await d.data.interaction.respond(opt).catch((e) => { + return d.aoiError.fnError( + d, + "custom", + {}, + `Failed to respond with reason: ${e}`, + ); + }); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/awaitExecute.js b/src/functions/interaction/awaitExecute.js new file mode 100644 index 000000000..3708c0203 --- /dev/null +++ b/src/functions/interaction/awaitExecute.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [awaitfunc] = data.inside.splits; + + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === awaitfunc.addBrackets().toLowerCase() + ); + + if (!cmd) + return d.aoiError.fnError( + d, + "custom", + {}, + `Invalid Awaited Command: '${awaitfunc.addBrackets()}' Provided` + ); + + await Interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + d.data + ); + + data.result = null; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/ban.js b/src/functions/interaction/ban.js new file mode 100644 index 000000000..be96019b3 --- /dev/null +++ b/src/functions/interaction/ban.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID = d.guild?.id, userID, deleteMessageSeconds = "7", reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const deleteMessageDays = parseInt(deleteMessageSeconds); + if (isNaN(deleteMessageDays) || deleteMessageDays > 7 || deleteMessageDays < 0) + return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Day Provided In'); + + deleteMessageSeconds = deleteMessageDays * 24 * 60 * 60; + + guild.members + .ban(userID, {deleteMessageSeconds, reason: reason?.addBrackets()}) + .catch((error) => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Ban With Reason: ' + error); + }); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/clear.js b/src/functions/interaction/clear.js new file mode 100644 index 000000000..c8e642d33 --- /dev/null +++ b/src/functions/interaction/clear.js @@ -0,0 +1,53 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + if (data.err) return d.error(data.err); + + let [channelID = d.channel.id, amount, filters = "everyone", returnCount = "false" ] = data.inside.splits; + + if (isNaN(amount)) + return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Amount Provided In" ); + amount = +amount + 1; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) + return d.aoiError.fnError(d, "channel", { inside: data.inside }); + + let messages = await channel.messages + .fetch({ limit: 100, cache: false }) + .catch((err) => { + d.aoiError.fnError(d, "custom", {}, "Failed To Fetch Messages With Reason: " + err); + }); + + filters = filters.toLowerCase().split(","); + + messages = [...messages.values()] + .filter((x) => { + if (filters.includes("everyone")) return true; + if (filters.includes("notpinned") && x.pinned) return false; + if (filters.includes("bots") && x.author?.bot) return true; + if ( + filters.some( + (filter) => + filter.startsWith("user:") && x.author?.id === filter.split(":")[1] + ) + ) + return true; + return false; + }) + .slice(0, amount); + + if (!messages.length) { + messages = [...messages.values()].slice(0, amount); + } + + let result = await channel.bulkDelete(messages, true).catch((err) => { + d.aoiError.fnError(d, "custom" ,{}, "Failed To Delete Message With Reason: " + err); + }); + + result = returnCount === "true" ? result.size : undefined; + + return { + code: d.util.setCode({ function: d.func, code, inside: data.inside, result }), + }; +}; diff --git a/src/functions/interaction/clearReaction.js b/src/functions/interaction/clearReaction.js new file mode 100644 index 000000000..1dd4f8d77 --- /dev/null +++ b/src/functions/interaction/clearReaction.js @@ -0,0 +1,35 @@ +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + const [channelID, messageID, userID, emoji] = inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "message", {inside}); + + message.reactions.cache + .find( + (x) => + x.emoji.name.toLowerCase() === emoji.toLowerCase() || + x.emoji.toString() === emoji.addBrackets() || + x.emoji.id === emoji, + ) + ?.users.remove(userID) + .catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Remove Reaction For The User:'${userID}' With Reason: ${err}`, + ); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; diff --git a/src/functions/interaction/clearReactions.js b/src/functions/interaction/clearReactions.js new file mode 100644 index 000000000..a5c01d7dd --- /dev/null +++ b/src/functions/interaction/clearReactions.js @@ -0,0 +1,42 @@ +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + const [channelID, messageID, emoji = "all"] = inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "message", {inside}); + + if (emoji === "all") { + message.reactions.removeAll().catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Remove All Reactions With Reason: " + err, + ); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}), + }; + } else { + message.reactions.cache + .find( + (x) => + x.emoji.toString() === emoji || + x.emoji.name.toLowerCase() === emoji.toLowerCase() || + x.emoji.id === emoji, + ) + ?.remove(); + } + + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; diff --git a/src/functions/interaction/createApplicationCommand.js b/src/functions/interaction/createApplicationCommand.js new file mode 100644 index 000000000..c46b3599f --- /dev/null +++ b/src/functions/interaction/createApplicationCommand.js @@ -0,0 +1,82 @@ +const parser = require("../../handler/slashCommandOptionsParser"); +const {SlashTypes} = require("../../utils/InteractionConstants.js"); +const {ApplicationCommandType} = require("discord.js"); +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [ + guildID, + name, + description, + defaultPermission = "true", + type = "slash", + ...opts + ] = inside.splits; + name = name.addBrackets(); + let options; + let data; + const guild = + guildID === "global" + ? undefined + : guildID === "custom" + ? "custom" + : await d.util.getGuild(d, guildID); + if (!guild && !["global", "custom"].includes(guildID)) + return d.aoiError.fnError(d, "guild", {inside}); + type = SlashTypes[type] || type; + if (type === ApplicationCommandType.ChatInput) { + if (opts.length) { + if (opts.length === 1) { + try { + options = JSON.parse(opts[0]); + options = Array.isArray(options) ? options : [options]; + } catch (e) { + if (opts[0].startsWith("{") && opts[0].endsWith("}")) + options = await d.util.parsers.SlashOptionsParser(opts[0] || ""); + else options = await parser(opts); + } + } else { + options = await parser(opts); + } + } + } else { + description = null; + } + + if (guild === "custom") { + data = d.client.interactionManager.applicationData.get(name.toLowerCase()); + if (!data) + return d.aoiError.fnError( + d, + "custom", + {}, + "No Slash Data Present With Following Keyword: " + name.toLowerCase(), + ); + } else { + data = { + data: { + name: name, + type, + description: description?.addBrackets(), + defaultMemberPermission: defaultPermission === "true" || defaultPermission === "true", + options, + }, + guildID: guild?.id, + }; + } + await d.client.application.commands.create(data.data, data.guildID).catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Create Application Command With Reason: " + e, + ); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; \ No newline at end of file diff --git a/src/functions/interaction/createFile.js b/src/functions/interaction/createFile.js new file mode 100644 index 000000000..53e0f67d8 --- /dev/null +++ b/src/functions/interaction/createFile.js @@ -0,0 +1,14 @@ +const {AttachmentBuilder} = require('discord.js') +module.exports = async d => { + const {code} = d.command + const inside = d.unpack() + const err = d.inside(inside) + if (err) return d.error(err) + let [attachment, name] = inside.splits; + const result = new AttachmentBuilder(Buffer.from(attachment.addBrackets()), {name: name.addBrackets()}) + d.files.push(result) + return { + code: d.util.setCode({function: d.func, code, inside}), + files: d.files + } +} \ No newline at end of file diff --git a/src/functions/interaction/deleteApplicationCommand.js b/src/functions/interaction/deleteApplicationCommand.js new file mode 100644 index 000000000..4d31192f6 --- /dev/null +++ b/src/functions/interaction/deleteApplicationCommand.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [guildID, id] = inside.splits; + const guild = guildID === "global" ? undefined : await d.util.getGuild(d, guildID); + if (!guild && !["global"].includes(guildID)) return d.aoiError.fnError(d, "guild", {inside}); + + d.client.application.commands.delete(id, guildID === 'global' ? undefined : guildID).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Application Command With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/interaction/deleteCommand.js b/src/functions/interaction/deleteCommand.js new file mode 100644 index 000000000..770b7decb --- /dev/null +++ b/src/functions/interaction/deleteCommand.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const {code} = d.util.aoiFunc(d); + + d.message.delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Message With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code}) + } +} \ No newline at end of file diff --git a/src/functions/interaction/dm.js b/src/functions/interaction/dm.js new file mode 100644 index 000000000..12042e95d --- /dev/null +++ b/src/functions/interaction/dm.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const {code, inside} = d.util.aoiFunc(d); + + const [id = d.author.id] = inside.splits; + + let dm = await d.util.getUser(d, id); + if (!dm) return d.aoiError.fnError(d, "user", {inside}); + + return { + code: d.util.setCode({function: d.func, code, inside}), + useChannel: dm + } +} \ No newline at end of file diff --git a/src/functions/interaction/editButton.js b/src/functions/interaction/editButton.js new file mode 100644 index 000000000..89bcdc480 --- /dev/null +++ b/src/functions/interaction/editButton.js @@ -0,0 +1,44 @@ +const { ButtonBuilder, ActionRowBuilder } = require('discord.js'); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const inside = d.unpack(); + if (data.err) return d.error(data.err); + + let [index, customId, custom, label, style, disabled, emoji, messageID, channelID = d.channel.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside }); + if (!customId) return d.aoiError.fnError(d, "custom", { inside }, "Empty customId was provided"); + if (isNaN(index) || Number(index) < 1) d.aoiError.fnError(d, "custom", {inside}, "Invalid Index Provided In"); + index = Number(index) - 1; + if (style) { + style = d.util.constants.ButtonStyleOptions[style] || Number(style); + if (style > 5 || style < 1) d.aoiError.fnError(d, "custom", { inside }, "Invalid Style Provided In"); + } + const components = message.components; + if (!components[index]) components[index] = { type: 1, components: [] }; + const rows = []; + components[index].components.forEach(button => { + if (button.customId === customId) { + const newButton = new ButtonBuilder() + .setLabel(label || button.label) + .setStyle(style || button.style) + .setDisabled(disabled ? JSON.parse(disabled) : button.disabled); + if (emoji) newButton.setEmoji(emoji || button.emoji); + style != 5 + ? newButton.setCustomId(custom || button.customId) + : newButton.setURL(custom || button.url); + rows.push(newButton); + } else { + rows.push(button); + } + }); + components[index] = new ActionRowBuilder().addComponents(rows); + await message.edit({ components }); + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/interaction/fetchActiveThreads.js b/src/functions/interaction/fetchActiveThreads.js new file mode 100644 index 000000000..4c1d82882 --- /dev/null +++ b/src/functions/interaction/fetchActiveThreads.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID = d.channel.id, ...options] = data.inside.splits; + if (!options.length) options = ["name"] + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const threadData = await channel.threads.fetchActive(); + + options = options.reduce((a, v) => ({...a, [v]: threadData.map(x => x[v]).join(" , ")}), {}); + + data.result = Object.keys(options).length <= 1 ? Object.values(options)[0] : JSON.stringify(options); + + return { + code: d.util.setCode(data) + + } +} \ No newline at end of file diff --git a/src/functions/interaction/fetchArchivedThreads.js b/src/functions/interaction/fetchArchivedThreads.js new file mode 100644 index 000000000..789c74175 --- /dev/null +++ b/src/functions/interaction/fetchArchivedThreads.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channelID = d.channel.id, ...options] = data.inside.splits; + if (!options.length) options = ["name"] + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const threadData = await channel.threads.fetchArchived(); + + options = options.reduce((a, v) => ({...a, [v]: threadData.map(x => x[v]).join(" , ")}), {}); + + data.result = Object.keys(options).length <= 1 ? Object.values(options)[0] : JSON.stringify(options); + + return { + code: d.util.setCode(data) + + } +} \ No newline at end of file diff --git a/src/functions/interaction/getApplicationCommandID.js b/src/functions/interaction/getApplicationCommandID.js new file mode 100644 index 000000000..dc120ad61 --- /dev/null +++ b/src/functions/interaction/getApplicationCommandID.js @@ -0,0 +1,25 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, type = 'global'] = data.inside.splits; + + if (type === 'global') { + const all = await d.client.application.commands.fetch(); + + data.result = all.find( + (x) => x.name.toLowerCase() === name.addBrackets().toLowerCase(), + )?.id; + } else { + const guild = await d.util.getGuild(d, type); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const all = await guild.commands.fetch(); + + data.result = all.find(x => x.name.toLowerCase() === name.addBrackets().toLowerCase())?.id; + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/getApplicationCommandOptions.js b/src/functions/interaction/getApplicationCommandOptions.js new file mode 100644 index 000000000..cca64df62 --- /dev/null +++ b/src/functions/interaction/getApplicationCommandOptions.js @@ -0,0 +1,23 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, type = 'global'] = data.inside.splits; + + if (type === 'global') { + const all = await d.client.application.commands.fetch(); + + data.result = JSON.stringify(all.find(x => x.name === name.addBrackets().toLowerCase())?.options, null, 2); + } else { + const guild = await d.util.getGuild(d, type); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const all = await guild.commands.fetch(); + + data.result = JSON.stringify(all.find(x => x.name === name.addBrackets().toLowerCase())?.options, null, 2); + } + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/interaction/interactionModal.js b/src/functions/interaction/interactionModal.js new file mode 100644 index 000000000..2499eee9a --- /dev/null +++ b/src/functions/interaction/interactionModal.js @@ -0,0 +1,27 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [title, customID, components] = data.inside.splits; + + const parsedComponents = await d.util.parsers.ComponentParser(components, d); + + await d.data.interaction + .showModal({ + title: title.addBrackets(), + customId: customID.addBrackets(), + components: parsedComponents, + }) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed to render modals with reason: " + e, + ); + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/interaction/isAutoComplete.js b/src/functions/interaction/isAutoComplete.js new file mode 100644 index 000000000..a1914b446 --- /dev/null +++ b/src/functions/interaction/isAutoComplete.js @@ -0,0 +1,8 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = d.message.isAutocomplete ?? false + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/kick.js b/src/functions/interaction/kick.js new file mode 100644 index 000000000..6e3669113 --- /dev/null +++ b/src/functions/interaction/kick.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID = d.guild?.id, userID, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + member.kick(reason?.addBrackets()).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Kick With Reason: ' + e) + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/killShard.js b/src/functions/interaction/killShard.js new file mode 100644 index 000000000..cf41f4392 --- /dev/null +++ b/src/functions/interaction/killShard.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [shardId = 0] = data.inside.splits; + + await d.client.shard.broadcastEval(c => { + if (c.shard.ids.includes(Number(shardId))) process.exit(); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/modifyApplicationCommand.js b/src/functions/interaction/modifyApplicationCommand.js new file mode 100644 index 000000000..bfdbcbec7 --- /dev/null +++ b/src/functions/interaction/modifyApplicationCommand.js @@ -0,0 +1,43 @@ +const {SlashOptionsParser} = require('../../handler/parsers.js') +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, id, ...Datas] = data.inside.splits; + let DATA; + + if (guildID === 'custom') { + const cmd = await d.client.application.commands.fetch(id).catch(e => { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Id Provided In'); + }); + + DATA = d.client.interactionManager.applicationData.get(cmd.name); + + cmd.edit(DATA.data); + } else { + if (Datas.length === 1) { + try { + DATA = JSON.parse(Datas[0]); + } catch (e) { + DATA = { + name: Datas[0]?.addBrackets(), + } + } + } else { + DATA = { + name: Datas[0]?.addBrackets(), + description: Datas[1]?.trim()?.addBrackets() || null, + type: Number(Datas[2]) < 1 ? 1 : Number(Datas[2]), + options: await SlashOptionsParser(Datas[3] || ''), + defaultPermission: Datas[4] === 'true' + } + } + d.client.application.commands.edit(id, DATA, guildID === 'global' ? undefined : guildID).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Edit Application Command With Reason: ' + e); + }); + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/removeApplicationCommandPermissions.js b/src/functions/interaction/removeApplicationCommandPermissions.js new file mode 100644 index 000000000..ec6a8f722 --- /dev/null +++ b/src/functions/interaction/removeApplicationCommandPermissions.js @@ -0,0 +1,39 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID = "global", id, ...roleoruserID] = data.inside.splits; + + let permissions = {}; + if (roleoruserID.length === 1) { + try { + permissions = JSON.parse(roleoruserID); + } catch { + const e = roleoruserID[0].split(":"); + permissions[`${e[1].toLowerCase()}s`] = [e[0]]; + } + } else { + const e = roleoruserID[0].split(":"); + permissions[`${e[1].toLowerCase()}s`] = + permissions[`${e[1].toLowerCase()}s`] || []; + permissions[`${e[1].toLowerCase()}s`].push(e[0]); + } + if (guildID === "global") { + d.client.application.commands.permissions.remove({ + command: id, + token: d.client.token, + ...permissions, + }); + } else { + d.client.application.commands.permissions.remove({ + guild: guildID, + command: id, + token: d.client.token, + ...permissions, + }); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/reply.js b/src/functions/interaction/reply.js new file mode 100644 index 000000000..e720a3bea --- /dev/null +++ b/src/functions/interaction/reply.js @@ -0,0 +1,16 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, mentionUser = 'true'] = data.inside.splits; + + d.allowedMentions.repliedUser = mentionUser === "true"; + + return { + code: d.util.setCode(data), + reply: { + message: messageID, + user: mentionUser === 'true' + }, + allowedMentions: d.allowedMentions + } +} \ No newline at end of file diff --git a/src/functions/interaction/respawnAllShards.js b/src/functions/interaction/respawnAllShards.js new file mode 100644 index 000000000..e7c88cf98 --- /dev/null +++ b/src/functions/interaction/respawnAllShards.js @@ -0,0 +1,8 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + data.result = await d.client.shard.respawnAll(); + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/sendDM.js b/src/functions/interaction/sendDM.js new file mode 100644 index 000000000..c99ef0c69 --- /dev/null +++ b/src/functions/interaction/sendDM.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [msg, userID = d.author?.id, returnID = 'false'] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + msg = await d.util.errorParser(msg, d); + + try { + data.result = await d.aoiError.makeMessageError(d.client, user, msg.data ?? msg, msg.options, d); + } catch (err) { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Send Dm With Reason: ' + err); + } + data.result = returnID === 'true' ? data.result.id : undefined; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/sendTTS.js b/src/functions/interaction/sendTTS.js new file mode 100644 index 000000000..9340cf522 --- /dev/null +++ b/src/functions/interaction/sendTTS.js @@ -0,0 +1,24 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID, message, returnID = 'false'] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const sendData = { + content: message.addBrackets(), + tts: true + } + + const msg = await channel.send(sendData).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Send TTS With Reason: ' + err); + }); + + data.result = returnID === 'true' ? msg.id : undefined; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/setApplicationCommandPermissions.js b/src/functions/interaction/setApplicationCommandPermissions.js new file mode 100644 index 000000000..97459018f --- /dev/null +++ b/src/functions/interaction/setApplicationCommandPermissions.js @@ -0,0 +1,48 @@ +const {ApplicationCommandPermissionType} = require("discord.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID = "global", id, ...perms] = data.inside.splits; + + let permissions = []; + if (perms.length === 1) { + try { + permissions = JSON.parse(perms); + } catch { + const e = perms[0].split(":"); + permissions.push({ + id: e[0], + type: ApplicationCommandPermissionType[e[1]], + permission: e[2] === "true", + }); + } + } else { + const e = perms[0].split(":"); + permissions.push({ + id: e[0], + type: ApplicationCommandPermissionType[e[1]], + permission: e[2] === "true", + }); + } + + if (guildID == "global") { + d.client.application.commands.permissions.set({ + command: id, + token: d.client.token, + permissions, + }); + } else { + d.client.application.commands.permissions.set({ + guild: guildID, + command: id, + token: d.client.token, + permissions, + }); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/interaction/slowmode.js b/src/functions/interaction/slowmode.js new file mode 100644 index 000000000..9098ace48 --- /dev/null +++ b/src/functions/interaction/slowmode.js @@ -0,0 +1,23 @@ +const {Time} = require('../../utils/helpers/customParser.js'); + +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time, channelID = d.channel?.id] = data.inside.splits; + + const channel = d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + time = isNaN(time) ? Time.parse(time)?.ms : Number(time); + + channel.edit({ + rateLimitPerUser: (time / 1000).toFixed(0) + }).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Set Slowmode With Reason: ' + err); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/interaction/spawnShard.js b/src/functions/interaction/spawnShard.js new file mode 100644 index 000000000..0be32f158 --- /dev/null +++ b/src/functions/interaction/spawnShard.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [shardId = 0] = data.inside.splits; + + await d.client.shard.broadcastEval(c => { + if (c.shard.ids.includes(Number(shardId))) c.spawn(); + }); + + return { + code: d.util.setCode(data) + } + +} \ No newline at end of file diff --git a/src/functions/interaction/unban.js b/src/functions/interaction/unban.js new file mode 100644 index 000000000..72e37b2b9 --- /dev/null +++ b/src/functions/interaction/unban.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID = d.guild?.id, userID, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + guild.members.unban(userID, reason).catch((err) => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Unban With Reason: ' + err) + }); + + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/invite/invite.js b/src/functions/invite/invite.js new file mode 100644 index 000000000..461cb81d8 --- /dev/null +++ b/src/functions/invite/invite.js @@ -0,0 +1,29 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const guildID = d.guild.id; + const invite = d.data.inviteData; + if (!invite) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Invite data not found." + ); + } + + const inviteInfo = { + inviteURL: invite.url || "", + inviteCode: invite.code || "", + inviteGuildID: invite.guild?.id || "", + inviteChannelID: invite.channel?.id || "", + inviteUserID: invite.inviter?.id || "", + inviteMaxUses: invite.maxUses || "", + }; + + data.result = inviteInfo; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/invite/inviteChannelID.js b/src/functions/invite/inviteChannelID.js new file mode 100644 index 000000000..d1fd2c0ad --- /dev/null +++ b/src/functions/invite/inviteChannelID.js @@ -0,0 +1,9 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = d.data.inviteData.channelId; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/invite/inviteCode.js b/src/functions/invite/inviteCode.js new file mode 100644 index 000000000..913b14c9d --- /dev/null +++ b/src/functions/invite/inviteCode.js @@ -0,0 +1,9 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = d.data.inviteData.code; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/invite/inviteGuildID.js b/src/functions/invite/inviteGuildID.js new file mode 100644 index 000000000..127666a84 --- /dev/null +++ b/src/functions/invite/inviteGuildID.js @@ -0,0 +1,9 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = d.data.inviteData.guildId; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/invite/inviteMaxUses.js b/src/functions/invite/inviteMaxUses.js new file mode 100644 index 000000000..90c749e89 --- /dev/null +++ b/src/functions/invite/inviteMaxUses.js @@ -0,0 +1,9 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = d.data.inviteData.maxUses; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/invite/inviteURL.js b/src/functions/invite/inviteURL.js new file mode 100644 index 000000000..750dd11d3 --- /dev/null +++ b/src/functions/invite/inviteURL.js @@ -0,0 +1,9 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = d.data.inviteData.url; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/invite/inviteUserID.js b/src/functions/invite/inviteUserID.js new file mode 100644 index 000000000..87ca04aec --- /dev/null +++ b/src/functions/invite/inviteUserID.js @@ -0,0 +1,9 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = d.data.inviteData.inviterId; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/math/abbreviate.js b/src/functions/math/abbreviate.js new file mode 100644 index 000000000..4ff142bc7 --- /dev/null +++ b/src/functions/math/abbreviate.js @@ -0,0 +1,37 @@ +const { abbreviate } = require("../../utils/helpers/functions.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [num, dec = 0] = data.inside.splits; + const n = Number(num); + const de = Number(dec); + + if (isNaN(n) || isNaN(de)) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + `${ + isNaN(n) + ? "Invalid Number in " + : isNaN(de) + ? "Invalid Decimal Position in" + : "" + }` + ); + } + + let a; + try { + a = abbreviate(n, de); + } catch (e) { + return d.aoiError.fnError(d, "custom", {}, e); + } + + data.result = a; + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/math/abs.js b/src/functions/math/abs.js new file mode 100644 index 000000000..9ff1a3cba --- /dev/null +++ b/src/functions/math/abs.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [number] = data.inside.splits; + + if (isNaN(number) || number.trim() === '') return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + + data.result = Math.abs(Number(number)); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/math/divide.js b/src/functions/math/divide.js new file mode 100644 index 000000000..5b01e0320 --- /dev/null +++ b/src/functions/math/divide.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [...numbers] = inside.splits; + if (numbers.some(x => isNaN(x))) return d.aoiError.fnError(d, 'custom', {inside: inside}, 'Invalid Number Provided In'); + if (numbers.length < 2) return d.aoiError.fnError(d, 'custom', {inside: inside}, `At Least 2 Numbers Are Needed. Provided ${numbers.length} Numbers In`) + + const result = numbers.reduce((a, b) => a / b); + + return { + code: d.util.setCode({function: d.func, inside, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/math/expandNumber.js b/src/functions/math/expandNumber.js new file mode 100644 index 000000000..5250e32e1 --- /dev/null +++ b/src/functions/math/expandNumber.js @@ -0,0 +1,37 @@ +const {SI_SYMBOL} = require("../../utils/Constants") + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [abbrNumber] = data.inside.toUpperCase() + + let abbrIndex + + for (let i = SI_SYMBOL.length - 1; i >= 0; i--) { + const sym = SI_SYMBOL[i] + if (abbrNumber.endsWith(sym.toUpperCase())) { + abbrIndex = i + break + } + } + + const abbr = SI_SYMBOL[abbrIndex] + const number = abbrIndex ? abbrNumber.slice( 0, -abbr.length ) : abbrNumber + + if (isNaN(Number(number))) return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid number in" + ) + + const num = parseFloat(number) + const multiplier = abbrIndex ? 1e3 ** abbrIndex : 1 + + data.result = num * multiplier + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/math/math.js b/src/functions/math/math.js new file mode 100644 index 000000000..5826c63b9 --- /dev/null +++ b/src/functions/math/math.js @@ -0,0 +1,28 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let result; + + const OPERATORS = /([0-9]|\/|\+|\*|-|%|<|\(|\)|\[|\]|\.|\^)/g; + + try { + const operation = data.inside.inside.addBrackets().match(OPERATORS).join(""); + + if (operation.replace(OPERATORS, "").trim().length) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Invalid operation in`, + ); + + result = eval(operation); + } catch (e) { + return d.aoiError.fnError(d, "custom", {}, `Failed to calculate in`); + } + + return { + code: d.command.code.replaceLast(`$math${data.inside.total}`, result), + }; +}; diff --git a/src/functions/math/max.js b/src/functions/math/max.js new file mode 100644 index 000000000..f230c039c --- /dev/null +++ b/src/functions/math/max.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const { code, inside, err } = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [...numbers] = inside.splits; + if (numbers.some((x) => isNaN(x))) { + return d.aoiError.fnError(d, 'custom', { inside: inside }, 'Invalid Number Provided In'); + } + if (numbers.length < 2) { + return d.aoiError.fnError(d, 'custom', { inside: inside }, `At Least 2 Numbers Are Needed. Provided ${numbers.length} Numbers In`); + } + + const result = Math.max(...numbers); + + return { + code: d.util.setCode({ function: d.func, inside, code, result }), + }; +}; diff --git a/src/functions/math/min.js b/src/functions/math/min.js new file mode 100644 index 000000000..a3eadbcb1 --- /dev/null +++ b/src/functions/math/min.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const { code, inside, err } = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [...numbers] = inside.splits; + if (numbers.some((x) => isNaN(x))) { + return d.aoiError.fnError(d, 'custom', { inside: inside }, 'Invalid Number Provided In'); + } + if (numbers.length < 2) { + return d.aoiError.fnError(d, 'custom', { inside: inside }, `At Least 2 Numbers Are Needed. Provided ${numbers.length} Numbers In`); + } + + const result = Math.min(...numbers); + + return { + code: d.util.setCode({ function: d.func, inside, code, result }), + }; +}; diff --git a/src/functions/math/modulo.js b/src/functions/math/modulo.js new file mode 100644 index 000000000..7923f2ab6 --- /dev/null +++ b/src/functions/math/modulo.js @@ -0,0 +1,15 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [...numbers] = data.inside.splits; + + if (numbers.some(x => isNaN(x))) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + if (numbers.length < 2) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, `At Least 2 Numbers Are Needed. Provided ${numbers.length} Numbers In`) + + data.result = numbers.length === 2 ? (numbers[0] % numbers[1]) : (numbers.reduce((a, b) => Number(a) % Number(b))); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/math/multi.js b/src/functions/math/multi.js new file mode 100644 index 000000000..19719d095 --- /dev/null +++ b/src/functions/math/multi.js @@ -0,0 +1,15 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [...numbers] = data.inside.splits; + + if (numbers.some(x => isNaN(x))) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + if (numbers.length < 2) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, `At Least 2 Numbers Are Needed. Provided ${numbers.length} Numbers In`) + + data.result = numbers.length === 2 ? (numbers[0] * numbers[1]) : (numbers.reduce((a, b) => Number(a) * Number(b))); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/math/ordinal.js b/src/functions/math/ordinal.js new file mode 100644 index 000000000..d8d6e0aaa --- /dev/null +++ b/src/functions/math/ordinal.js @@ -0,0 +1,20 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [number] = data.inside.splits; + + if (isNaN(number)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Number Provided In"); + + if ([11, 12, 13].includes(Number(number))) { + data.result = number + 'th' + } else if ([1, 2, 3].some(x => number.endsWith(x.toString()))) { + data.result = number.endsWith('1') ? number + 'st' : number.endsWith('2') ? number + 'nd' : number + 'rd'; + } else { + data.result = number + 'th'; + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/math/round.js b/src/functions/math/round.js new file mode 100644 index 000000000..745a57753 --- /dev/null +++ b/src/functions/math/round.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [number] = data.inside.splits; + + if (isNaN(number) || number.trim() === '') return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + + data.result = Math.round(Number(number)); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/math/roundTenth.js b/src/functions/math/roundTenth.js new file mode 100644 index 000000000..b53fcac94 --- /dev/null +++ b/src/functions/math/roundTenth.js @@ -0,0 +1,15 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [number, decimalPosition] = data.inside.splits; + + if (isNaN(number) || number.trim() === '') return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + if (isNaN(decimalPosition) || decimalPosition.trim() === '') return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Decimal Position Provided In'); + + data.result = Number(number).toFixed(Number(decimalPosition)); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/math/sub.js b/src/functions/math/sub.js new file mode 100644 index 000000000..8571f7b56 --- /dev/null +++ b/src/functions/math/sub.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [...numbers] = inside.splits; + if (numbers.some(x => isNaN(x))) return d.aoiError.fnError(d, 'custom', {inside: inside}, 'Invalid Number Provided In'); + if (numbers.length < 2) return d.aoiError.fnError(d, 'custom', {inside: inside}, `At Least 2 Numbers Are Needed. Provided ${numbers.length} Numbers In`) + + const result = numbers.reduce((a, b) => Number(a) - Number(b)); + + return { + code: d.util.setCode({function: d.func, inside, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/math/sum.js b/src/functions/math/sum.js new file mode 100644 index 000000000..c3392dd72 --- /dev/null +++ b/src/functions/math/sum.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [...numbers] = inside.splits; + if (numbers.some(x => isNaN(x))) return d.aoiError.fnError(d, 'custom', {inside: inside}, 'Invalid Number Provided In'); + if (numbers.length < 2) return d.aoiError.fnError(d, 'custom', {inside: inside}, `At Least 2 Numbers Are Needed. Provided ${numbers.length} Numbers In`) + + const result = numbers.reduce((a, b) => Number(a) + Number(b)); + + return { + code: d.util.setCode({function: d.func, inside, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/math/truncate.js b/src/functions/math/truncate.js new file mode 100644 index 000000000..364883141 --- /dev/null +++ b/src/functions/math/truncate.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [number] = data.inside.splits; + + if (isNaN(number)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + + data.result = Math.trunc(Number(number)); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/channelSendMessage.js b/src/functions/message/channelSendMessage.js new file mode 100644 index 000000000..b4af606d0 --- /dev/null +++ b/src/functions/message/channelSendMessage.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [channelID, message, returnID = "false"] = inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + message = await d.util.errorParser(message, d); + + const msg = await d.aoiError.makeMessageError(d.client, channel, message.data ?? message, message.options, d); + + + const result = (returnID === "true" ? msg?.id : "") || ""; + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/message/deleteIn.js b/src/functions/message/deleteIn.js new file mode 100644 index 000000000..5310804ae --- /dev/null +++ b/src/functions/message/deleteIn.js @@ -0,0 +1,13 @@ +const {Time} = require('../../utils/helpers/customParser.js'); +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [time] = inside.splits; + time = Time.parse(time).ms; + + return { + code: d.util.setCode({function: d.func, code, inside}), + deleteIn: time + } +} \ No newline at end of file diff --git a/src/functions/message/deleteMessage.js b/src/functions/message/deleteMessage.js new file mode 100644 index 000000000..742fafcff --- /dev/null +++ b/src/functions/message/deleteMessage.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [messageID, channel = d.channel.id] = inside.splits; + channel = await d.util.getChannel(d, channel); + if (!channel) return d.aoiError.fnError(d, "channel", {inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "channel", {inside}); + + message.delete().catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Delete Message With Reason: " + e); + }); + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/message/editIn.js b/src/functions/message/editIn.js new file mode 100644 index 000000000..e3c62e70e --- /dev/null +++ b/src/functions/message/editIn.js @@ -0,0 +1,22 @@ +const { Time } = require("../../utils/helpers/customParser.js"); +module.exports = async (d) => { + const { code, inside, err } = d.util.aoiFunc(d); + if (err) return d.error(err); + + let [time, ...mesgs] = inside.splits; + + time = Time.parse(time).ms; + const msgs = []; + mesgs.forEach(async (x) => { + const msg = await d.util.errorParser(x, d); + msgs.push(msg.data ?? msg); + }); + + return { + code: d.util.setCode({ function: d.func, code, inside }), + editIn: { + time, + msgs, + }, + }; +}; diff --git a/src/functions/message/editWebhookMessage.js b/src/functions/message/editWebhookMessage.js new file mode 100644 index 000000000..465f5ec31 --- /dev/null +++ b/src/functions/message/editWebhookMessage.js @@ -0,0 +1,22 @@ +const {WebhookClient} = require("discord.js"); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [id, token, messageID, message, returnID = "true"] = data.inside.splits; + + const webhook = new WebhookClient({id, token: token.addBrackets()}); + const editMessage = await d.util.errorParser(message, d); + + const editedMessageData = await webhook.editMessage(messageID, editMessage.data ?? editMessage).catch(e => { + d.aoiError.fnError(d, "custom", {}, "Failed To Edit Webhook Message With Reason: " + e); + }); + + if (returnID === "true") data.result = editedMessageData?.id; + + return { + code: d.util.setCode(data) + } + +} \ No newline at end of file diff --git a/src/functions/message/hasAttachment.js b/src/functions/message/hasAttachment.js new file mode 100644 index 000000000..8304dc9a4 --- /dev/null +++ b/src/functions/message/hasAttachment.js @@ -0,0 +1,17 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + data.result = message.attachments.size ? true : false; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/message/message.js b/src/functions/message/message.js new file mode 100644 index 000000000..8d9ccfc9b --- /dev/null +++ b/src/functions/message/message.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [args] = data.inside.splits; + + if (isNaN(args) && args < 1) return d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid Index Provided In"); + + data.result = args ? d.args[args - 1]?.deleteBrackets() : d.args.join(" ")?.deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/messageAttachment.js b/src/functions/message/messageAttachment.js new file mode 100644 index 000000000..a7ee97204 --- /dev/null +++ b/src/functions/message/messageAttachment.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + let [index = 1] = data.inside.splits; + + index = Number(index) - 1; + + data.result = [...d.message.attachments.values()][index]?.url; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/messageFlags.js b/src/functions/message/messageFlags.js new file mode 100644 index 000000000..a071b1002 --- /dev/null +++ b/src/functions/message/messageFlags.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [messageID, sep = ' , ', channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + data.result = message.flags.toArray().join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/messageID.js b/src/functions/message/messageID.js new file mode 100644 index 000000000..da83795ae --- /dev/null +++ b/src/functions/message/messageID.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + data.result = d.message?.id; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/messagePing.js b/src/functions/message/messagePing.js new file mode 100644 index 000000000..06ed289c2 --- /dev/null +++ b/src/functions/message/messagePing.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + data.result = Date.now() - d.message?.createdTimestamp + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/messageType.js b/src/functions/message/messageType.js new file mode 100644 index 000000000..51aae4b45 --- /dev/null +++ b/src/functions/message/messageType.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = messageID === d.message?.id ? d.message : await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + data.result = message?.type; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/messageURL.js b/src/functions/message/messageURL.js new file mode 100644 index 000000000..346e936c6 --- /dev/null +++ b/src/functions/message/messageURL.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = messageID === d.message?.id ? d.message : await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + data.result = message?.url; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/messageWebhookID.js b/src/functions/message/messageWebhookID.js new file mode 100644 index 000000000..23ebe3bad --- /dev/null +++ b/src/functions/message/messageWebhookID.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = messageID === d.message?.id ? d.message : await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + data.result = message?.webhookId; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/pinMessage.js b/src/functions/message/pinMessage.js new file mode 100644 index 000000000..bf3b080f3 --- /dev/null +++ b/src/functions/message/pinMessage.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + message.pin().catch(err => { + d.aoiError.fnError(d, 'custom', {}, "Failed To Pin Message With Reason: " + err); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/sendCrosspostingMessage.js b/src/functions/message/sendCrosspostingMessage.js new file mode 100644 index 000000000..a41b6be98 --- /dev/null +++ b/src/functions/message/sendCrosspostingMessage.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [msg, ...channelIds] = data.inside.splits; + + msg = await d.util.errorParser(msg, d); + + for (const x of channelIds) { + const channel = await d.util.getChannel(d, x); + + if (channel) { + await d.aoiError.makeMessageError(d.client, channel, msg.data ?? msg, msg.options, d); + } + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/sendMessage.js b/src/functions/message/sendMessage.js new file mode 100644 index 000000000..ba9da4286 --- /dev/null +++ b/src/functions/message/sendMessage.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [message, returnID = "false"] = inside.splits; + + message = await d.util.errorParser(message, d); + const msg = await d.aoiError.makeMessageError(d.client, d.channel, message.data ?? message, message.options, d); + + + const result = (returnID === "true" ? msg?.id : "") || ""; + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/message/sendSticker.js b/src/functions/message/sendSticker.js new file mode 100644 index 000000000..73ede4003 --- /dev/null +++ b/src/functions/message/sendSticker.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + let [resolver] = data.inside.splits; + + const guild = d.client.guilds.cache.get(d.guild?.id); + if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); + + const sticker = await d.util.getSticker(guild, resolver); + if (!sticker) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "sticker"); + + try { + await d.channel.send({ stickers: [sticker.id] }); + } catch (err) { + return d.aoiError.fnError(d, "custom", { inside: data.inside }, `Failed to send resolver: ${err}`); + } + + return { code: d.util.setCode(data) }; +}; diff --git a/src/functions/message/sendWebhookMessage.js b/src/functions/message/sendWebhookMessage.js new file mode 100644 index 000000000..d8a743d48 --- /dev/null +++ b/src/functions/message/sendWebhookMessage.js @@ -0,0 +1,24 @@ +const {WebhookClient} = require('discord.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [id, token, message, returnID = 'false'] = data.inside.splits; + + const webhook = new WebhookClient({id, token: token.addBrackets()}); + const sendMessage = await d.util.errorParser(message, d); + + let msg; + try { + msg = await d.aoiError.makeMessageError(d.client, webhook, sendMessage.data ?? sendMessage, sendMessage.options, d); + } catch (err) { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Send Webhook Message With Reason: ' + err); + } + + data.result = returnID === 'true' ? msg?.id : undefined; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/message/unPinMessage.js b/src/functions/message/unPinMessage.js new file mode 100644 index 000000000..b12016225 --- /dev/null +++ b/src/functions/message/unPinMessage.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [messageID = d.message?.id, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, 'message', {inside: data.inside}); + + message.unpin().catch(err => { + d.aoiError.fnError(d, 'custom', {}, "Failed To Unpin Message With Reason: " + err); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/advancedTextSplit.js b/src/functions/misc/advancedTextSplit.js new file mode 100644 index 000000000..3572b6b88 --- /dev/null +++ b/src/functions/misc/advancedTextSplit.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const code = d.command.code; + const inside = d.unpack(); + let [text, ...fields] = inside.splits; + let i = 0; + while (i < fields.length) { + let split = fields[i]; + let index = fields[i + 1]; + i += 2; + index = Number(index) - 1 || 0; + text = text.addBrackets().split(split.addBrackets())[index] || ""; + } + return { + code: code.replaceLast( + `$advancedTextSplit${inside.total}`, + text.deleteBrackets(), + ), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/appendFile.js b/src/functions/misc/appendFile.js new file mode 100644 index 000000000..6a659c55a --- /dev/null +++ b/src/functions/misc/appendFile.js @@ -0,0 +1,25 @@ +const fs = require("fs/promises"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [file, text, encode = "utf8"] = data.inside.splits; + + await fs + .appendFile(file, text.addBrackets(), { + encoding: encode, + }) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Append File With Reason: " + e, + ); + }); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/argsCount.js b/src/functions/misc/argsCount.js new file mode 100644 index 000000000..5bc7b4714 --- /dev/null +++ b/src/functions/misc/argsCount.js @@ -0,0 +1,7 @@ +module.exports = async d => { + const {code} = d.command + return { + code: d.util.setCode({function: d.func, code, result: d.args.length}) + + } +} \ No newline at end of file diff --git a/src/functions/misc/cloneObject.js b/src/functions/misc/cloneObject.js new file mode 100644 index 000000000..13f49010e --- /dev/null +++ b/src/functions/misc/cloneObject.js @@ -0,0 +1,19 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + + const [objectName, newObjectName] = data.inside.splits; + const objects = d.data.objects; + + if (!objects || !objects[objectName]) { + return d.aoiError.fnError(d, "custom", {}, "Object not found!"); + } + + const clonedObject = JSON.parse(JSON.stringify(objects[objectName])); + d.data.objects[newObjectName] = clonedObject; + + return { + code: d.util.setCode({ function: d.func, code: code, inside: data.inside }), + data: { ...d.data, objects: { ...d.data.objects } }, + }; +}; diff --git a/src/functions/misc/closeTicket.js b/src/functions/misc/closeTicket.js new file mode 100644 index 000000000..5b5212169 --- /dev/null +++ b/src/functions/misc/closeTicket.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + let [error] = data.inside.splits; + + const exists = await d.client.db.get( + d.client.db.tables[0], + `ticketChannel`, + d.channel?.id + ); + + if (error) error = await d.util.errorParser(error, d); + + if (!exists) return d.aoiError.makeMessageError(d.client, d.channel, error.data ?? error, error.options, d); + const channel = await d.message.channel.delete().catch((err) => { + d.aoiError.makeMessageError(d.client, d.channel, error, error.options, d); + }); + + return { + code: d.util.setCode(data) + }; +}; \ No newline at end of file diff --git a/src/functions/misc/createObject.js b/src/functions/misc/createObject.js new file mode 100644 index 000000000..66fb4d90d --- /dev/null +++ b/src/functions/misc/createObject.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + + const [objectName, json] = data.inside.splits; + + try { + const object = JSON.parse(json.addBrackets()); + d.data.objects = d.data.objects || {}; + d.data.objects[objectName] = object; + d.object = object; + } catch (e) { + return d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Create Object With Reason: " + e + ); + } + + return { + code: d.util.setCode({ function: d.func, code: code, inside: data.inside }), + data: { ...d.data, objects: { ...d.data.objects } }, + }; +}; diff --git a/src/functions/misc/deleteFile.js b/src/functions/misc/deleteFile.js new file mode 100644 index 000000000..60ec950d3 --- /dev/null +++ b/src/functions/misc/deleteFile.js @@ -0,0 +1,22 @@ +const fs = require("fs/promises"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [file] = data.inside.splits; + + await fs + .unlink(file) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Delete File With Reason: " + e, + ); + }); + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/deleteObject.js b/src/functions/misc/deleteObject.js new file mode 100644 index 000000000..8b601a000 --- /dev/null +++ b/src/functions/misc/deleteObject.js @@ -0,0 +1,27 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "object"); + + const objects = data.inside.splits; + try { + for (const objectName of objects) { + if (d.data.objects && objects in d.data.objects) { + delete d.data.objects[objectName]; + } + } + } catch (e) { + return d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Create Object With Reason: " + e + ); + } + + return { + code: d.util.setCode({ function: d.func, code: code, inside: data.inside }), + data: { ...d.data, objects: { ...d.data.objects } }, + }; +}; diff --git a/src/functions/misc/editObjectProperty.js b/src/functions/misc/editObjectProperty.js new file mode 100644 index 000000000..a4bcbe2e1 --- /dev/null +++ b/src/functions/misc/editObjectProperty.js @@ -0,0 +1,33 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + + const [objectName, property, propertyValue] = data.inside.splits; + const properties = property.split('.'); + + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "Object"); + + let object = d.data.objects[objectName] || {}; + + let Object = object; + for (let i = 0; i < properties.length - 1; i++) { + const propertyName = properties[i]; + Object[propertyName] = Object[propertyName] || {}; + Object = Object[propertyName]; + } + + try { + Object[properties[properties.length - 1]] = JSON.parse(propertyValue); + } catch (e){ + Object[properties[properties.length - 1]] = propertyValue; + } + + d.data.objects[objectName] = object; + d.object = object; + + return { + code: d.util.setCode({ function: d.func, code: code, inside: data.inside }), + data: { ...d.data, objects: { ...d.data.objects } }, + }; + }; + \ No newline at end of file diff --git a/src/functions/misc/editTextSplitElement.js b/src/functions/misc/editTextSplitElement.js new file mode 100644 index 000000000..ba7e06425 --- /dev/null +++ b/src/functions/misc/editTextSplitElement.js @@ -0,0 +1,26 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [index, text] = data.inside.splits; + data.function = d.func; + index = index - 1; + + if (isNaN(index) || index < 0) + return d.aoiError.fnError( + d, + "custom", + {inside}, + "Invalid Index Provided In", + ); + + d.array[index] = text; + + return { + code: d.util.setCode(data), + data: { + ...d.data, + array: d.array, + }, + }; +}; \ No newline at end of file diff --git a/src/functions/misc/endif.js b/src/functions/misc/endif.js new file mode 100644 index 000000000..6ed685c9b --- /dev/null +++ b/src/functions/misc/endif.js @@ -0,0 +1,2 @@ +module.exports = d => { +} \ No newline at end of file diff --git a/src/functions/misc/error.js b/src/functions/misc/error.js new file mode 100644 index 000000000..9a5625c7b --- /dev/null +++ b/src/functions/misc/error.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + return { + code: d.util.setCode({ + function: data.function, + code: data.code, + result: require('util').inspect(d.data.error)?.deleteBrackets() + }) + } +} \ No newline at end of file diff --git a/src/functions/misc/eventData.js b/src/functions/misc/eventData.js new file mode 100644 index 000000000..0043ef745 --- /dev/null +++ b/src/functions/misc/eventData.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + try { + data.result = await eval(`d.data.eventData${data.inside.inside}`) + } catch (e) { + data.result = "" + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/eventEmit.js b/src/functions/misc/eventEmit.js new file mode 100644 index 000000000..70fc3f85c --- /dev/null +++ b/src/functions/misc/eventEmit.js @@ -0,0 +1,21 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + if (!d.client.customEvents) return d.aoiError.fnError(d.func, "custom", {}, "CustomEvent Class Was Not Initialised"); + + let [name, ...datas] = data.inside.splits; + name = name.addBrackets(); + datas = datas.map(x => { + try { + return JSON.parse(x) + } catch (e) { + return x + } + }); + + data.result = d.client.customEvents.emit(name, ...datas); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/misc/fileExists.js b/src/functions/misc/fileExists.js new file mode 100644 index 000000000..c53f1b36f --- /dev/null +++ b/src/functions/misc/fileExists.js @@ -0,0 +1,12 @@ +const {existsSync} = require('fs'); +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) d.error(data.err); + + const [path] = data.inside.splits; + data.result = existsSync(path); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/fileSize.js b/src/functions/misc/fileSize.js new file mode 100644 index 000000000..bc4c9233b --- /dev/null +++ b/src/functions/misc/fileSize.js @@ -0,0 +1,30 @@ +const units = { + byte: 1, + kiloByte: 1024, + megaByte: (1024 ** 2), + gigaByte: (1024 ** 3), + + bit: 1 / 8, + kiloBit: (1024 / 8), + megaBit: (1024 ** 2) / 8, + gigaBit: (1024 ** 3) / 8 + +}; +[units.B, units.KB, units.MB, units.GB, units.b, units.kb, units.mb, units.gb] = Object.values(units); + +const {statSync} = require('fs'); +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [path, unit = "b"] = data.inside.splits; + try { + data.result = statSync(process.cwd() + `/${path}`)?.size / units[unit]; + } catch (e) { + d.aoiError.fnError(d, "custom", {}, e); + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/findInCache.js b/src/functions/misc/findInCache.js new file mode 100644 index 000000000..0eb30337d --- /dev/null +++ b/src/functions/misc/findInCache.js @@ -0,0 +1,50 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [type, name, prop, value, findType = "===", returnValue = "$default"] = + data.inside.splits; + prop = prop.trim() === "" ? "" : "?." + prop; + + findType = ["includes", "startsWith", "endsWith"].includes(findType) + ? findType + : [">=", "==", "===", "<=", "<", ">"].includes(findType) + ? findType + : d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid FindType Provided In", + ); + try { + if (["includes", "startsWith", "endsWith"].includes(findType)) { + data.result = eval( + `d.client.cacheManager.caches[type][name].find(x => (prop.trim() === "" ? x : x${prop})[findType]("${value}"))`, + ); + + data.result = + typeof data.result === "object" + ? returnValue === "$default" + ? JSON.stringify(data.result, null, 2) + : eval(`data.result?.${returnValue}`) + : data.result; + } else { + data.result = + eval(`d.client.cacheManager.caches[type][name].find(x => (prop.trim() === "" ? x : x${prop}) ${findType} "${value}")`); + + data.result = + typeof data.result === "object" + ? returnValue === "$default" + ? JSON.stringify(data.result, null, 2) + : eval(`data.result?.${returnValue}`) + : data.result; + } + } catch (e) { + console.error(e); + data.result = ""; + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/findObjectProperty.js b/src/functions/misc/findObjectProperty.js new file mode 100644 index 000000000..d15330e3f --- /dev/null +++ b/src/functions/misc/findObjectProperty.js @@ -0,0 +1,24 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "object"); + + const [objectName, property, format = false] = data.inside.splits; + let object = d.data.objects?.[objectName]; + + if (!object) { + return d.aoiError.fnError(d, "custom", {}, "Object not found!"); + } + + const properties = {}; + for (const prop in object) { + if (prop === property) { + properties[prop] = object[prop]; + } + } + + data.result = JSON.stringify(properties, null, format === "true" ? 2 : 0); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/findTextSplitIndex.js b/src/functions/misc/findTextSplitIndex.js new file mode 100644 index 000000000..830240d50 --- /dev/null +++ b/src/functions/misc/findTextSplitIndex.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [query] = data.inside.splits; + + data.result = d.array.indexOf(query) + 1; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/misc/forEachChannel.js b/src/functions/misc/forEachChannel.js new file mode 100644 index 000000000..8d91ef401 --- /dev/null +++ b/src/functions/misc/forEachChannel.js @@ -0,0 +1,110 @@ +const { wait } = require("../../utils/helpers/functions.js"); +const { Time } = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time = "", awaitData, ...cmds] = data.inside.splits; + const endCmd = cmds.pop(); + + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Invalid Data Provided In", + ); + } + + time = isNaN(time) ? Time.parse(time).ms : Number(time); + + cmds.forEach((x) => { + if ( + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ) + ) { + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + x + " Not Found", + ); + } + }); + + cmds = cmds + .map((x) => + d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ), + ) + .reverse(); + + const channels = [...d.client.channels.cache.values()].reverse(); + + let i = channels.length - 1; + + while (i >= 0) { + const channel = channels[i]; + + let u = cmds.length - 1; + + const loopData = { + channel, + message: d.message, + guild: channel.guild, + client: d.client, + author: d.author, + member: d.member, + }; + + while (u >= 0) { + const cmd = cmds[u]; + await d.interpreter( + d.client, + loopData, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + + u--; + } + + await wait(time); + + i--; + } + + if (endCmd !== "") { + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase(), + ); + if (!cmd) return; + await d.interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/forEachGuild.js b/src/functions/misc/forEachGuild.js new file mode 100644 index 000000000..9a9200cb9 --- /dev/null +++ b/src/functions/misc/forEachGuild.js @@ -0,0 +1,110 @@ +const {wait} = require("../../utils/helpers/functions.js"); +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time = "", awaitData, ...cmds] = data.inside.splits; + const endCmd = cmds.pop(); + + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Data Provided In", + ); + } + + time = isNaN(time) ? Time.parse(time).ms : Number(time); + + cmds.forEach((x) => { + if ( + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ) + ) { + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + x + " Not Found", + ); + } + }); + + cmds = cmds + .map((x) => + d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ), + ) + .reverse(); + + const datas = [...d.client.guilds.cache.values()].reverse(); + + let i = datas.length - 1; + + while (i >= 0) { + const guild = datas[i]; + + let u = cmds.length - 1; + + const loopData = { + channel: d.channel, + message: d.message, + guild, + client: d.client, + author: d.author, + member: d.member, + }; + + while (u >= 0) { + const cmd = cmds[u]; + await d.interpreter( + d.client, + loopData, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + + u--; + } + + await wait(time); + + i--; + } + + if (endCmd !== "") { + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase(), + ); + if (!cmd) return; + await d.interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/forEachGuildChannel.js b/src/functions/misc/forEachGuildChannel.js new file mode 100644 index 000000000..a9fc23b73 --- /dev/null +++ b/src/functions/misc/forEachGuildChannel.js @@ -0,0 +1,107 @@ +const {wait} = require("../../utils/helpers/functions.js"); +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time = "", awaitData, ...cmds] = data.inside.splits; + const endCmd = cmds.pop(); + + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Data Provided In", + ); + } + + time = isNaN(time) ? Time.parse(time).ms : Number(time); + + cmds.forEach((x) => { + if ( + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ) + ) { + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + x + " Not Found", + ); + } + }); + + cmds = cmds + .map((x) => + d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ), + ) + .reverse(); + + const channels = [...d.guild.channels.cache.values()].reverse(); + + let i = channels.length - 1; + + while (i >= 0) { + const channel = channels[i]; + + let u = cmds.length - 1; + + const loopData = { + channel, + message: d.message, + guild: d.guild, + client: d.client, + author: d.author, + member: d.member, + }; + + while (u >= 0) { + const cmd = cmds[u]; + await d.interpreter( + d.client, + loopData, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + u--; + } + await wait(time); + i--; + } + + if (endCmd !== "") { + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase(), + ); + if (!cmd) return; + await d.interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/forEachMember.js b/src/functions/misc/forEachMember.js new file mode 100644 index 000000000..7308cc344 --- /dev/null +++ b/src/functions/misc/forEachMember.js @@ -0,0 +1,110 @@ +const { wait } = require("../../utils/helpers/functions.js"); +const { Time } = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time = "", awaitData, ...cmds] = data.inside.splits; + const endCmd = cmds.pop(); + + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Invalid Data Provided In", + ); + } + + time = isNaN(time) ? Time.parse(time).ms : Number(time); + + cmds.forEach((x) => { + if ( + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ) + ) { + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + x + " Not Found", + ); + } + }); + + cmds = cmds + .map((x) => + d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ), + ) + .reverse(); + + const datas = [...d.guild.members.cache.values()].reverse(); + + let i = datas.length - 1; + + while (i >= 0) { + const member = datas[i]; + + let u = cmds.length - 1; + + const loopData = { + channel: d.channel, + message: d.message, + guild: d.guild, + client: d.client, + author: member.user, + member, + }; + + while (u >= 0) { + const cmd = cmds[u]; + await d.interpreter( + d.client, + loopData, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + + u--; + } + + await wait(time); + + i--; + } + + if (endCmd !== "") { + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase(), + ); + if (!cmd) return; + await d.interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/forEachRole.js b/src/functions/misc/forEachRole.js new file mode 100644 index 000000000..2fcf26575 --- /dev/null +++ b/src/functions/misc/forEachRole.js @@ -0,0 +1,111 @@ +const {wait} = require("../../utils/helpers/functions.js"); +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [guildID = d.guild?.id, time = "", awaitData, ...cmds] = + data.inside.splits; + const endCmd = cmds.pop(); + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Data Provided In", + ); + } + + time = isNaN(time) ? Time.parse(time).ms : Number(time); + + cmds.forEach((x) => { + if ( + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ) + ) { + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + x + " Not Found", + ); + } + }); + + cmds = cmds + .map((x) => + d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ), + ) + .reverse(); + + const datas = [...guild.roles.cache.values()].reverse(); + + let i = datas.length - 1; + + while (i >= 0) { + + let u = cmds.length - 1; + + const loopData = { + channel: d.channel, + message: d.message, + guild: d.guild, + client: d.client, + }; + + while (u >= 0) { + const cmd = cmds[u]; + await d.interpreter( + d.client, + loopData, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData: {...awaitData, role: datas[i]}, + }, + ); + + u--; + } + + await wait(time); + + i--; + } + + if (endCmd !== "") { + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase(), + ); + if (!cmd) return; + await d.interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/forEachUser.js b/src/functions/misc/forEachUser.js new file mode 100644 index 000000000..64ea97882 --- /dev/null +++ b/src/functions/misc/forEachUser.js @@ -0,0 +1,110 @@ +const { wait } = require("../../utils/helpers/functions.js"); +const { Time } = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time = "", awaitData, ...cmds] = data.inside.splits; + const endCmd = cmds.pop(); + + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "Invalid Data Provided In", + ); + } + + time = isNaN(time) ? Time.parse(time).ms : Number(time); + + cmds.forEach((x) => { + if ( + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ) + ) { + d.aoiError.fnError( + d, + "custom", + {}, + "Awaited Command: " + x + " Not Found", + ); + } + }); + + cmds = cmds + .map((x) => + d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.toLowerCase(), + ), + ) + .reverse(); + + const datas = [...d.client.users.cache.values()].reverse(); + + let i = datas.length - 1; + + while (i >= 0) { + const author = datas[i]; + + let u = cmds.length - 1; + + const loopData = { + channel: d.channel, + message: d.message, + guild: d.guild, + client: d.client, + author, + member: d.member, + }; + + while (u >= 0) { + const cmd = cmds[u]; + await d.interpreter( + d.client, + loopData, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + + u--; + } + + await wait(time); + + i--; + } + + if (endCmd !== "") { + const cmd = d.client.cmd.awaited.find( + (x) => x.name.toLowerCase() === endCmd.addBrackets().toLowerCase(), + ); + if (!cmd) return; + await d.interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + { + awaitData, + }, + ); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/getCacheData.js b/src/functions/misc/getCacheData.js new file mode 100644 index 000000000..fc2266ce7 --- /dev/null +++ b/src/functions/misc/getCacheData.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [type, name, key, option = "$default"] = data.inside.splits; + + data.result = d.client.cacheManager.caches[type]?.[name].get(key); + data.result = option === '$default' ? data.result : eval(`data.result?.${option}`); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/getCooldownTime.js b/src/functions/misc/getCooldownTime.js new file mode 100644 index 000000000..93306a1e7 --- /dev/null +++ b/src/functions/misc/getCooldownTime.js @@ -0,0 +1,28 @@ +const { Time } = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time, type, cmdName, id] = data.inside.splits; + + time = Time.parse(time)?.ms; + if (!time) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Time"); + + const types = { + globalUser: id, + user: `${id}_${d.message.guild.id || "dm"}`, + server: id, + channel: id, + static: undefined, + }; + + if (!types[type]) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Type"); + + const timeEnd = await d.client.db.get("__aoijs_vars__", "cooldown", cmdName + "_" + types[type]); + data.result = ((timeEnd?.value || d) - Date.now()) < 0 ? 0 : (timeEnd?.value || d) - Date.now(); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/getObject.js b/src/functions/misc/getObject.js new file mode 100644 index 000000000..175f9d6bc --- /dev/null +++ b/src/functions/misc/getObject.js @@ -0,0 +1,18 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + + const [objectName, format] = data.inside.splits; + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "object"); + + const object = d.data.objects?.[objectName]; + + if (!object) { + return d.aoiError.fnError(d, "custom", {}, "Object not found!"); + } + + data.result = JSON.stringify(object, null, format === "true" ? 2 : 0); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/getObjectKeys.js b/src/functions/misc/getObjectKeys.js new file mode 100644 index 000000000..74565b1dc --- /dev/null +++ b/src/functions/misc/getObjectKeys.js @@ -0,0 +1,31 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [objectName, sep = ", "] = data.inside.splits; + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "object"); + + const object = d.data.objects?.[objectName]; + + if (!object) return d.aoiError.fnError(d, "custom", {}, "Object not found!"); + + const keys = []; + + const stack = Array.isArray(object) ? [...object] : [object]; + + while (stack.length > 0) { + const current = stack.pop(); + for (const key in current) { + keys.push(key); + if (typeof current[key] === "object") { + stack.push(current[key]); + } + } + } + + data.result = keys.join(sep); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/getObjectProperty.js b/src/functions/misc/getObjectProperty.js new file mode 100644 index 000000000..3f0db7059 --- /dev/null +++ b/src/functions/misc/getObjectProperty.js @@ -0,0 +1,23 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [objectName, option] = data.inside.splits; + + const object = d.data.objects?.[objectName]; + if (!object) return d.aoiError.fnError("Object not found"); + + try { + const evaled = eval(`object?.${option}`); + data.result = typeof evaled === "object" + ? JSON.stringify(evaled, null, 2) + : evaled ?? "undefined"; + } catch (e) { + data.result = "undefined"; + } + + return { + code: d.util.setCode(data), + }; + }; + \ No newline at end of file diff --git a/src/functions/misc/getObjectValues.js b/src/functions/misc/getObjectValues.js new file mode 100644 index 000000000..4fd878659 --- /dev/null +++ b/src/functions/misc/getObjectValues.js @@ -0,0 +1,35 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [objectName, sep = " , "] = data.inside.splits; + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "object"); + + let object = d.data.objects?.[objectName]; + + if (!object) return d.aoiError.fnError(d, "custom", {}, "Object"); + + let values = []; + + const stack = Array.isArray(object) ? [...object] : [object]; + + while (stack.length > 0) { + const current = stack.pop(); + for (const key in current) { + const value = current?.[key]; + if (Array.isArray(value)) { + values.push(...value); + } else if (typeof value === "object") { + stack.push(value); + } else { + values.push(value); + } + } + } + + data.result = values.join(sep); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/hour.js b/src/functions/misc/hour.js new file mode 100644 index 000000000..2ada47137 --- /dev/null +++ b/src/functions/misc/hour.js @@ -0,0 +1,8 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = new Date(new Date().toLocaleString('en-us', {timeZone: d.timezone})).getHours(); + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/humanizeMs.js b/src/functions/misc/humanizeMs.js new file mode 100644 index 000000000..9e823caac --- /dev/null +++ b/src/functions/misc/humanizeMs.js @@ -0,0 +1,16 @@ +const {Time} = require('../../utils/helpers/customParser.js'); + +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [time] = data.inside.splits; + + if (isNaN(time)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Time Provided In"); + + data.result = Time.format(Number(time)).humanize(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/if.js b/src/functions/misc/if.js new file mode 100644 index 000000000..fc1f2f039 --- /dev/null +++ b/src/functions/misc/if.js @@ -0,0 +1,17 @@ +const Interpreter = require("../../core/interpreter.js"); +const { CheckCondition } = require("../../utils/helpers/checkCondition.js"); +const { mustEscape } = require("../../utils/helpers/mustEscape.js"); +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [condition, truecon,falsecon] = data.inside.splits; + + const res = eval(CheckCondition.solve(mustEscape(condition))) + + data.result = res ? truecon : falsecon; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/ifawaited.js b/src/functions/misc/ifawaited.js new file mode 100644 index 000000000..fa79f47cf --- /dev/null +++ b/src/functions/misc/ifawaited.js @@ -0,0 +1,54 @@ +const Interpreter = require("../../core/interpreter.js"); +const {CheckCondition} = require("../../utils/helpers/checkCondition.js"); +const {mustEscape} = require("../../utils/helpers/mustEscape.js"); +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [condition, trueawait, falseawait = ""] = data.inside.splits; + + data.result = eval(CheckCondition.solve(mustEscape(condition))) + ? trueawait.addBrackets() + : falseawait.addBrackets(); + + if (data.result.includes("{execute:")) { + const cmd = d.client.cmd.awaited.find( + (x) => + x.name.toLowerCase() === + data.result + .addBrackets() + .split("{execute:")[1] + .split("}")[0] + .toLowerCase(), + ); + if (!cmd) + return d.aoiError.fnError( + d, + "custom", + {}, + `Invalid Awaited Command: '${data.result.addBrackets().split("{execute:")[1].split("}")[0]}' Provided`, + ); + await Interpreter( + d.client, + d.message, + d.args, + cmd, + d.client.db, + false, + undefined, + d.data, + ); + data.result = data.result + .addBrackets() + .replace( + `{execute:${ + data.result.addBrackets().split("{execute:")[1].split("}")[0] + }}`, + "", + ); + } else data.result = data.result.addBrackets(); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/isTicket.js b/src/functions/misc/isTicket.js new file mode 100644 index 000000000..e2b10c39a --- /dev/null +++ b/src/functions/misc/isTicket.js @@ -0,0 +1,17 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [channelID = d.channel?.id] = data.inside.splits; + + let isTicket = await d.client.db.get( + d.client.db.tables[0], + "ticketChannel", + channelID, + ); + + data.result = !!isTicket; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/joinSplitText.js b/src/functions/misc/joinSplitText.js new file mode 100644 index 000000000..796d7aaa8 --- /dev/null +++ b/src/functions/misc/joinSplitText.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const sep = data.inside.inside; + + data.result = d.array.join(sep.addBrackets()); + + return { + code: d.util.setCode(data, false) + } +} \ No newline at end of file diff --git a/src/functions/misc/lerefAvatar.js b/src/functions/misc/lerefAvatar.js new file mode 100644 index 000000000..6494d849c --- /dev/null +++ b/src/functions/misc/lerefAvatar.js @@ -0,0 +1,10 @@ +module.exports = async d => { + let data = d.util.aoiFunc(d); + + const Leref = await d.util.getUser(d, "608358453580136499"); + + data.result = Leref.avatarURL({extension: 'png', size: 4096, dynamic: true}); + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/misc/loop.js b/src/functions/misc/loop.js new file mode 100644 index 000000000..0ec59f867 --- /dev/null +++ b/src/functions/misc/loop.js @@ -0,0 +1,27 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + let [time, awaitData, ...awaits] = data.inside.splits; + + try { + awaitData = JSON.parse(awaitData); + } catch (e) { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Data Provided In'); + } + + awaits.forEach(cmd => { + if (!d.client.cmd.awaited.find(x => x.name.toLowerCase() === cmd.addBrackets().toLowerCase())) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Awaited Command : " + cmd + " Not Found"); + }); + + for (let i = 0; i < time; i++) { + for (let cmd of awaits) { + cmd = d.client.cmd.awaited.find(x => x.name.toLowerCase() === cmd.addBrackets().toLowerCase()); + + await d.interpreter(d.client, d.message, d.args, cmd, d.client.db, false, undefined, {...d.data, awaitData}); + } + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/map.js b/src/functions/misc/map.js new file mode 100644 index 000000000..662c75935 --- /dev/null +++ b/src/functions/misc/map.js @@ -0,0 +1,27 @@ +const Interpreter = require("../../core/interpreter.js"); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, split, awaits, sep = ' , '] = data.inside.splits; + + const arr = text.addBrackets().split(split.addBrackets()); + const res = []; + + const cmd = d.client.cmd.awaited.find(x => x.name.toLowerCase() === awaits.addBrackets().toLowerCase()); + if (!cmd) returnd.aoiError.fnError(d, 'custom', {inside: data.inside}, `Coundn't Find AwaitedCommand: ${awaits} In`); + + arr.forEach(async x => { + const code = cmd.code.replaceAll('{value}', x); + const command = {...cmd, code} + + res.push((await Interpreter(d.client, d.message, d.args, command, d.client.db, true))?.code); + }); + + data.result = res.join(sep.addBrackets()).deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/minute.js b/src/functions/misc/minute.js new file mode 100644 index 000000000..33c1d4993 --- /dev/null +++ b/src/functions/misc/minute.js @@ -0,0 +1,8 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = new Date(new Date().toLocaleString('en-us', {timeZone: d.timezone})).getMinutes(); + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/month.js b/src/functions/misc/month.js new file mode 100644 index 000000000..ac9ef11ed --- /dev/null +++ b/src/functions/misc/month.js @@ -0,0 +1,9 @@ +module.exports = d => { + let data = d.util.aoiFunc(d); + const months = ['january', 'febuary', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'] + data.result = months[new Date(new Date().toLocaleString('en-us', {timeZone: d.timezone})).getMonth()]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/newTicket.js b/src/functions/misc/newTicket.js new file mode 100644 index 000000000..a55bf5233 --- /dev/null +++ b/src/functions/misc/newTicket.js @@ -0,0 +1,136 @@ +const {Guild} = require("discord.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, msg = "", place = d.guild?.id, returnID = "false", error] = + data.inside.splits; + + const createAt = + (await d.util.getChannel(d, place)) || (await d.util.getGuild(d, place)); + if (!createAt) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Id Provided In", + ); + + if (createAt instanceof Guild) { + const channel = await createAt.channels + .create(name.addBrackets()) + .catch(async (err) => { + if (error && error?.trim() !== "") { + const ticketError = await d.util.errorParser(error || "", d); + d.aoiError.makeMessageError( + d.client, + d.channel, + ticketError.data ?? ticketError, + ticketError.options, + ); + } else + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Failed To Create Channel Wih Reason: " + err, + ); + }); + if (channel) { + channel.permissionOverwrites + .edit(d.author.id, { + SendMessages: true, + ViewChannel: true, + ReadMessageHistory: true, + }) + .catch(async (err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Update Ticket Permissions With Reason: " + err, + ); + }); + if (msg?.trim() !== "") { + const ticketMsg = await d.util.errorParser( msg.addBrackets(), d ); + channel?.send(ticketMsg.data ?? ticketMsg).catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Send Message In Ticket With Reason: " + err, + ); + }); + } + } + d.client.db.set( + d.client.db.tables[0], + "ticketChannel", + channel.id, + channel.id, + ); + + data.result = returnID === "true" ? channel?.id : undefined; + } else { + const channel = await createAt + .children.create( { name: name.addBrackets() } ) + .catch(async (err) => { + if (error && error?.trim() !== "") { + const ticketError = await d.util.errorParser(error || "", d); + d.aoiError.makeMessageError( + d.client, + d.channel, + ticketError.data ?? ticketError, + ticketError.options, + ); + } else + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Failed To Create Channel Wih Reason: " + err, + ); + }); + + if (channel) { + channel.permissionOverwrites + .edit(d.author.id, { + SendMessages: true, + ViewChannel: true, + ReadMessageHistory: true, + }) + .catch(async (err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Update Ticket Permissions With Reason: " + err, + ); + }); + if (msg?.trim() !== "") { + const ticketMsg = await d.util.errorParser(msg.addBrackets(), d); + channel?.send(ticketMsg.data ?? ticketMsg).catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Send Message In Ticket With Reason: " + err, + ); + }); + } + } + d.client.db.set( + d.client.db.tables[0], + "ticketChannel", + channel.id, + channel.id, + ); + + data.result = returnID === "true" ? channel?.id : undefined; + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/noEscapingMessage.js b/src/functions/misc/noEscapingMessage.js new file mode 100644 index 000000000..1f326e792 --- /dev/null +++ b/src/functions/misc/noEscapingMessage.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + let [arg = '0'] = data.inside.splits; + + arg = Number(arg) - 1; + if (isNaN(arg)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Number Provided In"); + + data.result = arg === -1 ? d.args.join(" ") : d.args[arg]; + + return { + code: d.util.setCode(data, false) + } +} \ No newline at end of file diff --git a/src/functions/misc/noMentionMessage.js b/src/functions/misc/noMentionMessage.js new file mode 100644 index 000000000..60f61ef9d --- /dev/null +++ b/src/functions/misc/noMentionMessage.js @@ -0,0 +1,16 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + let [arg = '0'] = data.inside.splits; + + arg = Number(arg) - 1; + if (isNaN(arg)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Number Provided In"); + + const args = d.args.join(" ").replace(/(<#(\d{17,19})>|<@!?(\d{17,19})>|<@&(\d{17,19})>)/g, "").trim().split(/ +/g) + + data.result = arg === -1 ? args.join(" ") : args[arg]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/objectExists.js b/src/functions/misc/objectExists.js new file mode 100644 index 000000000..5c289fca1 --- /dev/null +++ b/src/functions/misc/objectExists.js @@ -0,0 +1,12 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const objectName = data.inside.splits; + const objects = d.data.objects || {}; + + data.result = objects.hasOwnProperty(objectName); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/misc/readFile.js b/src/functions/misc/readFile.js new file mode 100644 index 000000000..aaa57181b --- /dev/null +++ b/src/functions/misc/readFile.js @@ -0,0 +1,26 @@ +const fs = require("fs/promises"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [file, encoding = "utf8", flag] = data.inside.splits; + + data.result = await fs + .readFile(file.addBrackets(), { + encoding, + flag, + }) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Read File With Reason: " + e, + ); + }); + data.result = data.result.deleteBrackets(); + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/removeContains.js b/src/functions/misc/removeContains.js new file mode 100644 index 000000000..54047117e --- /dev/null +++ b/src/functions/misc/removeContains.js @@ -0,0 +1,16 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, ...words] = data.inside.splits; + + data.result = text.addBrackets(); + + words.forEach(x => { + data.result = data.result.replaceAll(x, ''); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/removeObjectProperty.js b/src/functions/misc/removeObjectProperty.js new file mode 100644 index 000000000..272f459a9 --- /dev/null +++ b/src/functions/misc/removeObjectProperty.js @@ -0,0 +1,20 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (!d.object) return d.aoiError.fnError(d, "custom", {}, "object"); + + const [objectName, ...properties] = data.inside.splits; + let object = d.data.objects?.[objectName]; + + if (!object) { + return d.aoiError.fnError(d, "custom", {}, "Object not found!"); + } + + properties.forEach((property) => { + delete object[property]; + }); + + return { + code: d.util.setCode(data), + data: { ...d.data, objects: { ...d.data.objects, [objectName]: object } }, + }; +}; diff --git a/src/functions/misc/removeSplitTextElement.js b/src/functions/misc/removeSplitTextElement.js new file mode 100644 index 000000000..d73716f88 --- /dev/null +++ b/src/functions/misc/removeSplitTextElement.js @@ -0,0 +1,21 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [...elements] = data.inside.splits; + + for (const element of elements) { + const index = d.array.indexOf(element.addBrackets()); + + if (index !== -1) { + d.array.splice(index, 1); + } + } + d.data.array = d.array; + + return { + code: d.util.setCode(data), + data: d.data, + array: d.array + } +} \ No newline at end of file diff --git a/src/functions/misc/removeTextSplitElement.js b/src/functions/misc/removeTextSplitElement.js new file mode 100644 index 000000000..e25c45957 --- /dev/null +++ b/src/functions/misc/removeTextSplitElement.js @@ -0,0 +1,20 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [element] = data.inside.splits; + + const index = d.array.indexOf(element.addBrackets()); + + if (index !== -1) { + d.array.splice(index, 1); + } + + d.data.array = d.array; + + return { + code: d.util.setCode(data), + data: d.data, + array: d.array + } +} \ No newline at end of file diff --git a/src/functions/misc/renameFile.js b/src/functions/misc/renameFile.js new file mode 100644 index 000000000..8718ec76e --- /dev/null +++ b/src/functions/misc/renameFile.js @@ -0,0 +1,22 @@ +const fs = require('fs'); + +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [oldfile, newfile] = data.inside.splits; + + if (fs.existsSync(oldfile) && !fs.existsSync(newfile)) { + + fs.renameSync(oldfile, newfile) + + } else { + if (!fs.existsSync(oldfile)) return d.aoiError.fnError(d, 'custom', {}, `Couldn't Found the ${oldfile} file`) + if (fs.existsSync(newfile)) return d.aoiError.fnError(d, 'custom', {}, `File with name \`${newfile}\` already exist`) + + + } + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/second.js b/src/functions/misc/second.js new file mode 100644 index 000000000..0e98cdca4 --- /dev/null +++ b/src/functions/misc/second.js @@ -0,0 +1,9 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = new Date(new Date().toLocaleString('en-us', {timeZone: d.timezone})).getSeconds(); + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/misc/setCacheData.js b/src/functions/misc/setCacheData.js new file mode 100644 index 000000000..9c931505c --- /dev/null +++ b/src/functions/misc/setCacheData.js @@ -0,0 +1,30 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [type, cacheName, cacheKey, cacheValue] = data.inside.splits; + + if (!d.client.cacheManager.caches[type]) + return d.aoiError.fnError( + d, + "custom", + {inside: data.insde}, + `Cache type ${type} does not exist.`, + ); + let value; + try { + value = JSON.parse(cacheValue.addBrackets()); + } catch { + value = cacheValue.addBrackets(); + } + + d.client.cacheManager.caches[type][cacheName.addBrackets()][ + d.client.cacheManager.caches[type][cacheName.addBrackets()].set + ? "set" + : "add" + ](cacheKey.addBrackets(), value); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/setObjectProperty.js b/src/functions/misc/setObjectProperty.js new file mode 100644 index 000000000..07bf831e1 --- /dev/null +++ b/src/functions/misc/setObjectProperty.js @@ -0,0 +1,24 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const { code } = d.command; + + const [objectName, propertyName, propertyValue] = data.inside.splits; + + if (!d.data.objects) return d.aoiError.fnError(d, "custom", {}, "Object"); + + const object = d.data.objects[objectName] || {}; + + try { + object[propertyName] = JSON.parse(propertyValue); + } catch (e) { + object[propertyName] = propertyValue; + } + + d.data.objects[objectName] = object; + d.object = object; + + return { + code: d.util.setCode({ function: d.func, code: code, inside: data.inside }), + data: { ...d.data, objects: { ...d.data.objects } }, + }; +}; diff --git a/src/functions/misc/setTimeout.js b/src/functions/misc/setTimeout.js new file mode 100644 index 000000000..9263c47fc --- /dev/null +++ b/src/functions/misc/setTimeout.js @@ -0,0 +1,43 @@ +const {Time} = require("../../utils/helpers/customParser.js"); +const {Timeout} = require("../../utils/helpers/functions.js"); + +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [name, duration, timeoutData, returnID = "false", pulse] = + data.inside.splits; + + const time = isNaN(duration) ? Time.parse(duration)?.ms : Number(duration); + const pulseEvery = pulse + ? isNaN(pulse) + ? Time.parse(pulse)?.ms + : Number(pulse) + : undefined; + const timeoutName = name.trim() === "" ? undefined : name.addBrackets(); + let tdata = {}; + + if (timeoutData.addBrackets().startsWith("{")) { + try { + tdata = JSON.parse(timeoutData.addBrackets()); + } catch (e) { + d.aoiError.fnError(d, "custom", {inside: data.inside}); + } + } else { + for (let timeData of timeoutData.split("\n")) { + timeData = timeData.split(":"); + + tdata[timeData[0].trim()] = timeData[1].trim(); + } + } + + const timeout = Timeout(d, name.addBrackets(), time, tdata, pulseEvery); + + if (returnID === "true") { + data.result = timeout; + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/stopTimeout.js b/src/functions/misc/stopTimeout.js new file mode 100644 index 000000000..edf24add8 --- /dev/null +++ b/src/functions/misc/stopTimeout.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [id] = data.inside.splits; + + const timeout = await d.client.db.get( + d.client.db.tables[0], + "setTimeout", + id, + ); + if (!timeout) return d.error(`Timeout with ID: ${id} not found.`); + + timeout.value.__timeoutIds__.forEach((x) => clearTimeout(x)); + timeout.value.__pulseIds__?.forEach((x) => clearInterval(x)); + + await d.client.db.delete(d.client.db.tables[0], "setTimeout", id); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/suppressErrors.js b/src/functions/misc/suppressErrors.js new file mode 100644 index 000000000..345af99b4 --- /dev/null +++ b/src/functions/misc/suppressErrors.js @@ -0,0 +1,10 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [text = ' '] = data.inside.splits; + + return { + code: d.util.setCode(data), + suppressErrors: text.addBrackets() + } +} diff --git a/src/functions/misc/timeZone.js b/src/functions/misc/timeZone.js new file mode 100644 index 000000000..081b18933 --- /dev/null +++ b/src/functions/misc/timeZone.js @@ -0,0 +1,18 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [timezone = d.timezone] = data.inside.splits; + + try { + new Date().toLocaleString('en-us', { + timeZone: timezone.addBrackets(), + }); + } catch (err) { + d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid TimeZone Provided In'); + } + + return { + code: d.util.setCode(data), + timezone: timezone.addBrackets(), + } +} \ No newline at end of file diff --git a/src/functions/misc/useChannel.js b/src/functions/misc/useChannel.js new file mode 100644 index 000000000..e5b60d86b --- /dev/null +++ b/src/functions/misc/useChannel.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const channelID = data.inside.inside; + + const channel = await d.util.getChannel(d, channelID, true); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + return { + code: d.util.setCode(data), + useChannel: channel, + } +} \ No newline at end of file diff --git a/src/functions/misc/wait.js b/src/functions/misc/wait.js new file mode 100644 index 000000000..959db9655 --- /dev/null +++ b/src/functions/misc/wait.js @@ -0,0 +1,16 @@ +const {wait} = require('../../utils/helpers/functions.js'); +const {Time} = require('../../utils/helpers/customParser.js'); +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [time] = data.inside.splits; + + const timer = isNaN(time) ? Time.parse(time)?.ms || 0 : Number(time); + + await wait(timer); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/misc/writeFile.js b/src/functions/misc/writeFile.js new file mode 100644 index 000000000..baa0f8133 --- /dev/null +++ b/src/functions/misc/writeFile.js @@ -0,0 +1,24 @@ +const fs = require("fs/promises"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [file, text, encode = "utf8"] = data.inside.splits; + + await fs + .writeFile(file, text.addBrackets(), { + encoding: encode, + }) + .catch((e) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Write File With Reason: " + e, + ); + }); + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/misc/year.js b/src/functions/misc/year.js new file mode 100644 index 000000000..cee7d2640 --- /dev/null +++ b/src/functions/misc/year.js @@ -0,0 +1,8 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + data.result = new Date(new Date().toLocaleString('en-us', {timeZone: d.timezone})).getFullYear(); + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/authorAvatar.js b/src/functions/user/authorAvatar.js new file mode 100644 index 000000000..306c5badb --- /dev/null +++ b/src/functions/user/authorAvatar.js @@ -0,0 +1,9 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [size = 4096, dynamic = "true", extension = "webp"] = data.inside.splits; + + data.result = d.author?.displayAvatarURL({size: Number(size), forceStatic: dynamic === 'false', extension}) + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/authorBanner.js b/src/functions/user/authorBanner.js new file mode 100644 index 000000000..464f06c9b --- /dev/null +++ b/src/functions/user/authorBanner.js @@ -0,0 +1,22 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [size = 4096, dynamic = 'true', extension] = data.inside.splits; + + if (!d.author?.banner) { + await d.author?.fetch({force: true}); + } + + if (!d.author.banner) data.result = "null"; + else { + data.result = d.author?.bannerURL({ + size: Number(size), + forceStatic: dynamic === 'false', + extension, + }); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/user/authorBannerColor.js b/src/functions/user/authorBannerColor.js new file mode 100644 index 000000000..deb58abb1 --- /dev/null +++ b/src/functions/user/authorBannerColor.js @@ -0,0 +1,15 @@ +module.exports = async d => { + let data = d.util.aoiFunc(d); + + const [def = 'default'] = data.inside.splits; + + if (!d.author?.accentColor) { + await d.author?.fetch({force: true}) + } + + data.result = d.author?.hexAccentColor ?? def; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/authorID.js b/src/functions/user/authorID.js new file mode 100644 index 000000000..709332350 --- /dev/null +++ b/src/functions/user/authorID.js @@ -0,0 +1,8 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + data.result = d.author?.id + return { + code: d.util.setCode(data) + } +}; diff --git a/src/functions/user/cacheMembers.js b/src/functions/user/cacheMembers.js new file mode 100644 index 000000000..c05fc2efc --- /dev/null +++ b/src/functions/user/cacheMembers.js @@ -0,0 +1,26 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + const [guildID = d.guild.id, returnCount = "false"] = data.inside.splits; + let result; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); + + if (guild.memberCount > guild.members.cache.size) { + result = await guild.members.fetch().catch((err) => { + d.aoiError.fnError( + d, + "custom", + {}, + "Failed To Fetch Members With Reason :" + err + ); + }); + } + + data.result = returnCount === "true" ? guild.members.cache.size.toString() : undefined; + + return { + code: d.util.setCode(data), + }; + }; \ No newline at end of file diff --git a/src/functions/user/deafenUser.js b/src/functions/user/deafenUser.js new file mode 100644 index 000000000..79f00f66c --- /dev/null +++ b/src/functions/user/deafenUser.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d) + if (err) return d.error(err); + + const [userID = d.author.id, deaf = "true"] = inside.splits; + const member = await d.util.getMember(d.guild, userID) + if (!member) return d.aoiError.fnError(d, "member", {inside}); + + const voiceState = member.voice; + if (!voiceState.channelID) return d.aoiError.fnError(d, "custom", {}, "Provided Member Is Not In A Voice/Stage Channel"); + + voiceState.setDeaf(deaf === "true") + + return { + code: d.util.setCode({function: d.func, code, inside}) + } +} \ No newline at end of file diff --git a/src/functions/user/discriminator.js b/src/functions/user/discriminator.js new file mode 100644 index 000000000..a0565ad94 --- /dev/null +++ b/src/functions/user/discriminator.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.discriminator; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/findMember.js b/src/functions/user/findMember.js new file mode 100644 index 000000000..049b8b285 --- /dev/null +++ b/src/functions/user/findMember.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [memberResolver, returnSelf = "true", guildID = d.guild.id] = data.inside.splits; + memberResolver = memberResolver.addBrackets().replace(/[\\<>@!]/g, '').trim(); + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + data.result = d.util.findMember(guild, memberResolver) || (returnSelf === "true" ? d.author.id : undefined); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/findMembers.js b/src/functions/user/findMembers.js new file mode 100644 index 000000000..538b696a7 --- /dev/null +++ b/src/functions/user/findMembers.js @@ -0,0 +1,24 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [query, limit = 10, type = "startsWith", force = "false", res = "{position}) {username}: {id}"] = data.inside.splits; + query = query.toLowerCase().addBrackets(); + if (isNaN(limit)) return d.aoiError.fnError(d, "custom", {inside: data.inside}, "Limit is Not A Number In"); + + limit = Number(limit); + + data.result = await d.util.getMembers(d.guild, {query, limit, type}, force === "true"); + + data.result = data.result.map((x, y) => { + return res.replaceAll("{username}", x.user.username) + .replaceAll("{tag}", x.user.tag) + .replaceAll("{nick}", x.displayName) + .replaceAll("{position}", y + 1) + .replaceAll("{id}", x.user.id) + }).join("\n"); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/isBotVerified.js b/src/functions/user/isBotVerified.js new file mode 100644 index 000000000..7b4674713 --- /dev/null +++ b/src/functions/user/isBotVerified.js @@ -0,0 +1,16 @@ +const { UserFlags } = require('discord.js'); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.flags.has(UserFlags.VerifiedBot); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/memberAvatar.js b/src/functions/user/memberAvatar.js new file mode 100644 index 000000000..a4b0b00dc --- /dev/null +++ b/src/functions/user/memberAvatar.js @@ -0,0 +1,21 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id, size = 4096, dynamic = "true", extension] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}) + + const user = userID === d.author?.id ? d.member : await d.util.getMember(guild, userID); + if (!user) return d.aoiError.fnError(d, "member", {inside: data.inside}); + + data.result = user.avatarURL({ + size: Number(size), + forceStatic: dynamic === "false", + extension, + }); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/user/memberDisplayColor.js b/src/functions/user/memberDisplayColor.js new file mode 100644 index 000000000..2b674603a --- /dev/null +++ b/src/functions/user/memberDisplayColor.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.displayColor + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/memberDisplayName.js b/src/functions/user/memberDisplayName.js new file mode 100644 index 000000000..161510545 --- /dev/null +++ b/src/functions/user/memberDisplayName.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.displayName + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/memberExists.js b/src/functions/user/memberExists.js new file mode 100644 index 000000000..64dcc8e06 --- /dev/null +++ b/src/functions/user/memberExists.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [userID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'custom', {inside: data.inside}); + + data.result = userID.trim() === '' ? false : await d.util.getMember(guild, userID) ? true : false; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/memberJoinDate.js b/src/functions/user/memberJoinDate.js new file mode 100644 index 000000000..7f60b19b3 --- /dev/null +++ b/src/functions/user/memberJoinDate.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.joinedTimestamp; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/memberJoinPosition.js b/src/functions/user/memberJoinPosition.js new file mode 100644 index 000000000..7f1848610 --- /dev/null +++ b/src/functions/user/memberJoinPosition.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'custom', {inside: data.inside}); + + data.result = [...guild.members.cache.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp).values()].findIndex(x => x.id === userID) + 1; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/membersCount.js b/src/functions/user/membersCount.js new file mode 100644 index 000000000..f08872a46 --- /dev/null +++ b/src/functions/user/membersCount.js @@ -0,0 +1,32 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, presence = "", countBot = "true"] = + data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + if (presence === "" && countBot === "true") data.result = guild.memberCount; + else if (presence === "offline") { + const mems = guild.members.cache.filter( + (x) => + (x.presence?.status?.toLowerCase() === "offline" || + !x.presence?.status) && + (countBot === "true" ? true : !x.user.bot), + ); + data.result = mems.size; + } else { + const mems = guild.members.cache.filter( + (x) => + (presence === "" || presence === "all" + ? true + : x.presence?.status?.toLowerCase() === presence.toLowerCase()) && + (countBot === "true" ? true : !x.user.bot), + ); + + data.result = mems.size; + } + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/user/moveUser.js b/src/functions/user/moveUser.js new file mode 100644 index 000000000..07f47dd65 --- /dev/null +++ b/src/functions/user/moveUser.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, userID, channelID, reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + const state = guild.voiceStates.cache.get(member.id); + if (!state?.channel) return d.aoiError.fnError(d, 'custom', {}, 'User Is Not In Any Voice/Stage Channel.'); + + if (channelID?.trim() === '' || !channelID) { + state.disconnect(reason?.addBrackets()).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Disconnect User With Reason: ' + e); + }); + } else { + state.setChannel(channelID, reason?.addBrackets()).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Move User With Reason: ' + e); + }); + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/muteUser.js b/src/functions/user/muteUser.js new file mode 100644 index 000000000..960ddfa30 --- /dev/null +++ b/src/functions/user/muteUser.js @@ -0,0 +1,23 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [guildID, userID, mute = 'true', reason] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + const state = guild.voiceStates.cache.get(member.id); + if (!state?.channel) return d.aoiError.fnError(d, 'custom', {}, 'User Is Not In Any Voice/Stage Channel.'); + + state.setMute(mute === 'true', reason?.addBrackets()).catch(e => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Move User With Reason: ' + e); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/pruneMembers.js b/src/functions/user/pruneMembers.js new file mode 100644 index 000000000..8e51530fe --- /dev/null +++ b/src/functions/user/pruneMembers.js @@ -0,0 +1,27 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [days = 7, guildID = d.guild?.id, roleIds, dry = 'false', reason, count = 'false'] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + + if (roleIds && roleIds?.split(',').some(x => !guild.roles.cache.get(x.trim()))) { + d.aoiError.fnError(d, 'role', {inside: data.inside}); + } + + data.result = await guild.members.prune({ + days: Number(days), + count: count === 'true', + dry: dry === 'true', + roles: roleIds.split(',').map(x => x.trim()), + reason: reason?.addBrackets(), + }).catch(err => { + d.aoiError.fnError(d, 'custom', {}, 'Failed To Prune Members With Reason: ' + err); + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/referenceUserId.js b/src/functions/user/referenceUserId.js new file mode 100644 index 000000000..4d4d1de4d --- /dev/null +++ b/src/functions/user/referenceUserId.js @@ -0,0 +1,15 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [messageID = d.message.id] = data.inside.splits; + + const message = messageID ? await d.channel.messages.fetch(messageID) : d.message; + if (!message) return d.aoiError.fnError(d, 'message', { inside: data.inside }); + + const id = message.reference?.messageId; + + data.result = id ? (await d.channel.messages.fetch(id))?.author.id : ''; + + return { + code: d.util.setCode(data), + } + } diff --git a/src/functions/user/removeThreadMember.js b/src/functions/user/removeThreadMember.js new file mode 100644 index 000000000..98b1cab9c --- /dev/null +++ b/src/functions/user/removeThreadMember.js @@ -0,0 +1,21 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err) + + let [channelID, threadID, userID, reason] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID) + if (!channel) d.aoiError.fnError(d, "channel", {inside: data.inside}) + + const thread = channel.threads.cache.get(threadID); + if (!thread) d.aoiError.fnError(d, "custom", {inside: data.inside}, "Invalid ThreadID Provided In") + + thread.members.remove(userID, reason).catch(err => d.aoiError.fnError(d, "custom", {}, `Failed To Remove The Member With Reason: ${err}`)) + + return { + + code: d.util.setCode(data) + + } + +} \ No newline at end of file diff --git a/src/functions/user/setUserNickname.js b/src/functions/user/setUserNickname.js new file mode 100644 index 000000000..e101bf1d4 --- /dev/null +++ b/src/functions/user/setUserNickname.js @@ -0,0 +1,17 @@ +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + const [userID, nick, reason] = inside.splits; + + const member = await d.util.getMember(d.guild, userID); + if (!member) return d.aoiError.fnError(d, "member", {inside}); + + await member.setNickname(nick === "" ? null : nick.addBrackets(), reason); + + return { + code: d.util.setCode({function: d.func, code, inside}), + }; +}; diff --git a/src/functions/user/timeoutMember.js b/src/functions/user/timeoutMember.js new file mode 100644 index 000000000..ce0484fc1 --- /dev/null +++ b/src/functions/user/timeoutMember.js @@ -0,0 +1,40 @@ +const {Time} = require("../../utils/helpers/customParser.js"); +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + let [ + guildID = d.guild?.id, + memberId = d.author?.id, + timeout = "60s", + timeoutEndsAt = "false", + reason, + ] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + const member = await d.util.getMember(guild, memberId); + if (!member) return d.aoiError.fnError(d, "member", {inside: data.inside}); + + timeout = isNaN(timeout) ? Time.parse(timeout).ms : Number(timeout) * 1000; + + const mem = await member + .timeout(timeout === 0 ? null : timeout, reason) + .catch((err) => { + return d.aoiError.fnError( + d, + "custom", + {}, + `Failed To Timeout The Member With Reason:${err}`, + ); + }); + + data.result = + timeoutEndsAt === "true" + ? mem.communicationDisabledUntilTimestamp + : undefined; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/user/userActivity.js b/src/functions/user/userActivity.js new file mode 100644 index 000000000..0287cf26d --- /dev/null +++ b/src/functions/user/userActivity.js @@ -0,0 +1,15 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [guildID = d.guild?.id, userID = d.author?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + let u = await d.util.getMember(guild, userID) + if (!u) return d.aoiError.fnError(d, "member", {inside: data.inside}) + + data.result = u.presence?.activities?.join(", ")?.deleteBrackets() || "none" + return { + code: d.util.setCode(data) + } +}; \ No newline at end of file diff --git a/src/functions/user/userAvatar.js b/src/functions/user/userAvatar.js new file mode 100644 index 000000000..9a2946dfa --- /dev/null +++ b/src/functions/user/userAvatar.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, size = 4096, dynamic = 'true', extension] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.displayAvatarURL({ + size: Number(size), + forceStatic: dynamic === 'false', + extension + }); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/userBadges.js b/src/functions/user/userBadges.js new file mode 100644 index 000000000..848a47e51 --- /dev/null +++ b/src/functions/user/userBadges.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, sep = ' , '] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.flags?.toArray().join(sep) || 'none'; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/userBanner.js b/src/functions/user/userBanner.js new file mode 100644 index 000000000..d221ad3ff --- /dev/null +++ b/src/functions/user/userBanner.js @@ -0,0 +1,25 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, size = 4096, dynamic = 'true', extension] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + if (!user) return d.aoiError.fnError(d, "user", {inside: data.inside}); + + if (!user.banner) { + await user.fetch({force: true}) + } + + if (!user.banner) data.result = "null"; + else { + data.result = user.bannerURL({ + size: Number(size), + forceStatic: dynamic === 'false', + extension, + }); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/user/userBannerColor.js b/src/functions/user/userBannerColor.js new file mode 100644 index 000000000..8b0765eaf --- /dev/null +++ b/src/functions/user/userBannerColor.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + if (!user.accentColor) { + await user.fetch({force: true}) + } + + data.result = user.hexAccentColor; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userCustomStatus.js b/src/functions/user/userCustomStatus.js new file mode 100644 index 000000000..6a2f73aec --- /dev/null +++ b/src/functions/user/userCustomStatus.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const {ActivityType} = require("discord.js"); + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id, type = 'state'] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const user = await d.util.getMember(d.guild, userID); + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + const status = user.presence?.activities?.find(x => x.type === ActivityType.Custom); + data.result = status?.[type] || "none"; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/userDefaultAvatar.js b/src/functions/user/userDefaultAvatar.js new file mode 100644 index 000000000..4387638ae --- /dev/null +++ b/src/functions/user/userDefaultAvatar.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.defaultAvatarURL; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/userDisplayName.js b/src/functions/user/userDisplayName.js new file mode 100644 index 000000000..9cd88d547 --- /dev/null +++ b/src/functions/user/userDisplayName.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.displayName; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userExists.js b/src/functions/user/userExists.js new file mode 100644 index 000000000..6641572da --- /dev/null +++ b/src/functions/user/userExists.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + + data.result = !!user; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userGlobalName.js b/src/functions/user/userGlobalName.js new file mode 100644 index 000000000..f8600915c --- /dev/null +++ b/src/functions/user/userGlobalName.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.globalName; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userHighestRole.js b/src/functions/user/userHighestRole.js new file mode 100644 index 000000000..57755c069 --- /dev/null +++ b/src/functions/user/userHighestRole.js @@ -0,0 +1,18 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id, option = "id"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, "member", { inside: data.inside }); + + data.result = + option === "mention" + ? member.roles.highest.toString() + : member.roles.highest[option]; + + return { code: d.util.setCode(data) }; +}; diff --git a/src/functions/user/userHoistedRole.js b/src/functions/user/userHoistedRole.js new file mode 100644 index 000000000..34805b270 --- /dev/null +++ b/src/functions/user/userHoistedRole.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id, option = 'id'] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + const roles = member.roles.cache.sort((a, b) => b.position - a.position); + + data.result = option === "mention" ? roles.first().toString() : roles.first()[option]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userID.js b/src/functions/user/userID.js new file mode 100644 index 000000000..048c78cff --- /dev/null +++ b/src/functions/user/userID.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [user] = data.inside.splits; + + const res = d.client.users.cache.findKey(x => x.username.toLowerCase() === user.addBrackets().toLowerCase()); + if (!res) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid User Provided In'); + + data.result = res; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userLowestRole.js b/src/functions/user/userLowestRole.js new file mode 100644 index 000000000..ff4b52b27 --- /dev/null +++ b/src/functions/user/userLowestRole.js @@ -0,0 +1,21 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id, option = "id"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, "member", { inside: data.inside }); + + const role = member.roles.cache.filter((role) => role.id !== guild.id).sort((a, b) => a.position - b.position).first(); + + data.result = !role + ? guild?.roles.everyone.id + : role === undefined + ? guild.id + : role?.[option.toLowerCase()]; + + return { code: d.util.setCode(data) }; +}; diff --git a/src/functions/user/userNickname.js b/src/functions/user/userNickname.js new file mode 100644 index 000000000..f0cbb0dfe --- /dev/null +++ b/src/functions/user/userNickname.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id, returnUser = "false"] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = returnUser === "true" ? member.displayName : member.nickname; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userPerms.js b/src/functions/user/userPerms.js new file mode 100644 index 000000000..876938008 --- /dev/null +++ b/src/functions/user/userPerms.js @@ -0,0 +1,21 @@ +const {FormatPerms:Perms} = require('../../utils/Constants.js'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, sep = ' , ', guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + const PERMS = Object.entries(Perms); + + data.result = member.permissions.toArray().map(y => PERMS.find(x => x[1] === y)?.[0]).join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userPlatform.js b/src/functions/user/userPlatform.js new file mode 100644 index 000000000..c9b7213ac --- /dev/null +++ b/src/functions/user/userPlatform.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id, sep = ' , '] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.presence?.status === 'offline' ? 'none' : Object.keys(member.presence?.clientStatus || {none: "none"}); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/userReacted.js b/src/functions/user/userReacted.js new file mode 100644 index 000000000..eded96aa0 --- /dev/null +++ b/src/functions/user/userReacted.js @@ -0,0 +1,22 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [channelID, messageID, userID, reaction] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID, true); + if (!channel) return d.aoiError.fnError(d, "channel", {inside: data.inside}); + + const message = await d.util.getMessage(channel, messageID); + if (!message) return d.aoiError.fnError(d, "message", {inside: data.inside}); + + const reactions = message.reactions.cache.find(x => x.emoji.toString() === reaction.addBrackets()); + + await reactions?.users?.fetch(); + + data.result = reactions?.users?.cache.has(userID); + + return { + code: d.util.setCode(data), + } +} \ No newline at end of file diff --git a/src/functions/user/userRoleColor.js b/src/functions/user/userRoleColor.js new file mode 100644 index 000000000..2fb376bcb --- /dev/null +++ b/src/functions/user/userRoleColor.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.displayHexColor; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/userRoles.js b/src/functions/user/userRoles.js new file mode 100644 index 000000000..990b7d255 --- /dev/null +++ b/src/functions/user/userRoles.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id, option = 'name', sep = ' , '] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.roles.cache.map(x => option === 'mention' ? x.toString() : x[option.addBrackets()]).join(sep.addBrackets()); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userRolesCount.js b/src/functions/user/userRolesCount.js new file mode 100644 index 000000000..057a6415e --- /dev/null +++ b/src/functions/user/userRolesCount.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.roles.cache.size; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userStatus.js b/src/functions/user/userStatus.js new file mode 100644 index 000000000..3b41db44e --- /dev/null +++ b/src/functions/user/userStatus.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.presence?.status || 'offline'; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/userTag.js b/src/functions/user/userTag.js new file mode 100644 index 000000000..efef01d89 --- /dev/null +++ b/src/functions/user/userTag.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.tag; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/username.js b/src/functions/user/username.js new file mode 100644 index 000000000..23c5331cf --- /dev/null +++ b/src/functions/user/username.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = (userID === d.author?.id) ? d.author : (await d.util.getUser(d, userID)); + if (!user) return d.aoiError.fnError(d, 'user', {inside: data.inside}); + + data.result = user.username; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/user/usersBanned.js b/src/functions/user/usersBanned.js new file mode 100644 index 000000000..29e64a447 --- /dev/null +++ b/src/functions/user/usersBanned.js @@ -0,0 +1,16 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, force = 'false', option = 'id', sep = ' , '] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + if (force === 'true') await guild.bans.fetch(); + + data.result = guild.bans.cache.map(x => option === 'mention' ? x.user.toString() : x.user[option]).join(sep); + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/user/usersInChannel.js b/src/functions/user/usersInChannel.js new file mode 100644 index 000000000..9e73c08dd --- /dev/null +++ b/src/functions/user/usersInChannel.js @@ -0,0 +1,28 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [channelID, option = "id", sep = " , "] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID, true); + if (!channel) + return d.aoiError.fnError(d, "channel", {inside: data.inside}); + if ( + ![d.util.channelTypes.Voice, d.util.channelTypes.Stage].includes( + channel.type, + ) + ) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Channel Type Is Not Voice/Stage", + ); + + data.result = channel.members + .map((x) => (option === "mention" ? x.toString() : x[option])) + .join(sep); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/user/usersWithRole.js b/src/functions/user/usersWithRole.js new file mode 100644 index 000000000..6fca2c0e5 --- /dev/null +++ b/src/functions/user/usersWithRole.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [roleID, guildID = d.guild?.id, option = 'id', sep = ' , '] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(err => { + d.aoiError.fnError(d, 'role', {inside: data.inside}); + }); + + data.result = role.members.map(x => option === "mention" ? x.toString() : x[option]).join(sep) + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/argsCheck.js b/src/functions/util/argsCheck.js new file mode 100644 index 000000000..27106ac40 --- /dev/null +++ b/src/functions/util/argsCheck.js @@ -0,0 +1,24 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [condition, errorMessage = ""] = data.inside.splits; + + const checker = { + a: d.args.length < Number(condition.replace("<", "")), + b: d.args.length > Number(condition.replace(">", "")), + c: d.args.length <= Number(condition.replace("<=", "")), + d: d.args.length >= Number(condition.replace(">=", "")), + e: d.args.length === Number(condition), + } + const check = condition.startsWith("<=") ? checker.c : condition.startsWith(">=") ? checker.d : condition.startsWith("<") ? checker.a : condition.startsWith(">") ? checker.b : checker.e + if (!check && errorMessage !== "") { + const senderr = await d.util.errorParser(errorMessage, d) + await d.aoiError.makeMessageError(d.client, d.channel, senderr.data ?? senderr, senderr.options, d) + } + return { + code: d.util.setCode(data), + error: !check + } + +} \ No newline at end of file diff --git a/src/functions/util/argsSlice.js b/src/functions/util/argsSlice.js new file mode 100644 index 000000000..5573cc322 --- /dev/null +++ b/src/functions/util/argsSlice.js @@ -0,0 +1,22 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + + let [text, from = 0, to] = data.inside.splits; + + from = Number(from); + to = to ? Number(to) : undefined; + + if (isNaN(from) || (to && isNaN(to))) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Number Provided In", + ); + + data.result = text.split(" ").slice(from, to).join(" "); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/channelExists.js b/src/functions/util/channelExists.js new file mode 100644 index 000000000..ea0093358 --- /dev/null +++ b/src/functions/util/channelExists.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [channel] = data.inside.splits; + + channel = d.client.channels.cache.find(x => x.name.toLowerCase() === channel.toLowerCase().addBrackets() || x.id === channel) + + data.result = !!channel + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/charCount.js b/src/functions/util/charCount.js new file mode 100644 index 000000000..80b133930 --- /dev/null +++ b/src/functions/util/charCount.js @@ -0,0 +1,12 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [text, find] = data.inside.splits; + + data.result = find + ? (text.split(find).length - 1) * find.length + : text.length; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/checkCondition.js b/src/functions/util/checkCondition.js new file mode 100644 index 000000000..90bc32d2c --- /dev/null +++ b/src/functions/util/checkCondition.js @@ -0,0 +1,26 @@ +const { CheckCondition } = require('../../utils/helpers/checkCondition.js') +const { mustEscape } = require('../../utils/helpers/mustEscape.js') + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [condition] = data.inside.splits; + + if (!["==", "!=", "<=", ">=", "||", "&&", "<", ">"].some(x => condition.includes(x))) { + return d.aoiError.fnError(d, "custom", data.inside, "Valid Operators Not Provided In"); + } + + let result = CheckCondition.solve(mustEscape(condition) || ""); + result = eval(result)?.toString(); + + if (!["true", "false"].includes(result)) { + d.aoiError.fnError(d, "custom", data.inside, "Invalid Condition Provided In"); + result = undefined; + } + + data.result = result; + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/util/checkContains.js b/src/functions/util/checkContains.js new file mode 100644 index 000000000..500460efb --- /dev/null +++ b/src/functions/util/checkContains.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, ...characters] = data.inside.splits; + + data.result = characters.some(x => text.deleteBrackets().includes(x.deleteBrackets())); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/concatTextSplit.js b/src/functions/util/concatTextSplit.js new file mode 100644 index 000000000..02958f61c --- /dev/null +++ b/src/functions/util/concatTextSplit.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [...text] = inside.splits; + text = text.map(x => x.addBrackets()); + d.array.concat(text) + + return { + code: d.util.setCode({function: d.func, code, inside}), + data: { + array: d.array + } + } +} \ No newline at end of file diff --git a/src/functions/util/creationDate.js b/src/functions/util/creationDate.js new file mode 100644 index 000000000..1b32c98a9 --- /dev/null +++ b/src/functions/util/creationDate.js @@ -0,0 +1,20 @@ +const {Time} = require('../../utils/helpers/customParser.js'); +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [id, format = "date"] = inside.splits; + + const Id = await d.util.findId(d, id) + if (!Id) return d.aoiError.fnError(d, "custom", {inside}, "Invalid Id Provided In"); + + let result; + if (format === "date") result = new Date(Id.createdTimestamp).toLocaleString("en-us", {timeZone: d.timezone ?? "en-us"}) + else if (format === "time-full" || format === "time") result = Time.format((Date.now() - Id.createdTimestamp)).toString() + else if (format === "time-humanize") result = Time.format((Date.now() - (Id.createdTimestamp) || 0)).humanize() + else result = Id.createdTimestamp; + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/util/cropText.js b/src/functions/util/cropText.js new file mode 100644 index 000000000..156d5f8e0 --- /dev/null +++ b/src/functions/util/cropText.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const {code, inside, err} = d.util.aoiFunc(d); + if (err) return d.error(err); + + const [text, limit = 2000, start = 0, char = ""] = inside.splits; + + const result = text.addBrackets().trim().split(char).slice(Number(start), Number(limit)).join(char); + + return { + code: d.util.setCode({function: d.func, code, inside, result}) + } +} \ No newline at end of file diff --git a/src/functions/util/digitalFormat.js b/src/functions/util/digitalFormat.js new file mode 100644 index 000000000..0be7f9bd6 --- /dev/null +++ b/src/functions/util/digitalFormat.js @@ -0,0 +1,13 @@ +const {Time} = require("../../utils/helpers/customParser.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + const [ms] = data.inside.splits; + const time = isNaN(ms) ? Time.parse(ms)?.ms : Number(ms); + + data.result = Time.digital(time); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/disableMentionType.js b/src/functions/util/disableMentionType.js new file mode 100644 index 000000000..65e63870b --- /dev/null +++ b/src/functions/util/disableMentionType.js @@ -0,0 +1,33 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [type = "all"] = data.inside.splits; + if (!["everyone", "users", "roles", "all"].includes(type)) + d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Type Provided In", + ); + + switch (type) { + case "all": + d.allowedMentions = []; + break; + + case "everyone": + d.allowedMentions = d.allowedMentions.filter((x) => x !== "everyone"); + break; + case "roles": + d.allowedMentions = d.allowedMentions.filter((x) => x !== "roles"); + break; + case "users": + d.allowedMentions = d.allowedMentions.filter((x) => x !== "users"); + break; + } + + return { + code: d.util.setCode(data), + allowedMentions: d.allowedMentions + } +}; diff --git a/src/functions/util/emojiExists.js b/src/functions/util/emojiExists.js new file mode 100644 index 000000000..87a68472d --- /dev/null +++ b/src/functions/util/emojiExists.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [emoji] = data.inside.splits; + + data.result = !!(await d.util.getEmoji(d, emoji)); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/emojisFromMessage.js b/src/functions/util/emojisFromMessage.js new file mode 100644 index 000000000..6ac703343 --- /dev/null +++ b/src/functions/util/emojisFromMessage.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + let [text = d.args.join(" "), sep = " , "] = data.inside.splits; + text = text.split(" "); + + const emojis = []; + + text.forEach(x => { + if (x.match(/\p{Emoji}/ug) || d.client.emojis.cache.find(y => y.toString() === x)) emojis.push(x) + }); + + data.result = emojis.join(sep); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/filterMessage.js b/src/functions/util/filterMessage.js new file mode 100644 index 000000000..9f393339b --- /dev/null +++ b/src/functions/util/filterMessage.js @@ -0,0 +1,15 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, ...letters] = data.inside.splits; + data.result = text; + + for (let i = letters.length - 1; i >= 0; i--) { + data.result = data.result.split(letters[i]).join(" "); + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/filterTextSplitElement.js b/src/functions/util/filterTextSplitElement.js new file mode 100644 index 000000000..8c608ffc5 --- /dev/null +++ b/src/functions/util/filterTextSplitElement.js @@ -0,0 +1,26 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [query, type = "equal", separator = ","] = data.inside.splits; + if (!["equal", "starts", "ends", "includes"].includes(type)) return d.aoiError.fnError(d, "custom", {inside: data.inside}, `Invalid Type Provided In`); + + switch (type) { + case "equal" : + data.result = d.array.filter(x => x === query) + break; + case "starts": + data.result = d.array.filter(x => x.startsWith(query)) + break; + case "ends" : + data.result = d.array.filter(x => x.endsWith(query)) + break; + case "includes": + data.result = d.array.filter(x => x.includes(query)) + break; + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/findChars.js b/src/functions/util/findChars.js new file mode 100644 index 000000000..2f2f9aefb --- /dev/null +++ b/src/functions/util/findChars.js @@ -0,0 +1,10 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let chars = data.inside.inside; + data.result = chars.addBrackets().replace(/(\W|\d+)/g, "").deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/findNumbers.js b/src/functions/util/findNumbers.js new file mode 100644 index 000000000..81c0f356c --- /dev/null +++ b/src/functions/util/findNumbers.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text] = data.inside.splits; + + data.result = text.addBrackets().replace(/\D/g, ""); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/findRole.js b/src/functions/util/findRole.js new file mode 100644 index 000000000..c663968fc --- /dev/null +++ b/src/functions/util/findRole.js @@ -0,0 +1,16 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [roleResolver, guildID = d.guild.id] = data.inside.splits; + roleResolver = roleResolver.addBrackets(); + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + data.result = d.util.findRole(guild, roleResolver); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/findRoles.js b/src/functions/util/findRoles.js new file mode 100644 index 000000000..615718608 --- /dev/null +++ b/src/functions/util/findRoles.js @@ -0,0 +1,45 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [ + query, + limit = 10, + type = "startsWith", + res = "{position}) {username}: {id}", + ] = data.inside.splits; + query = query.addBrackets(); + if (isNaN(limit)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Limit is Not A Number In", + ); + + limit = Number(limit); + + const result = await d.util.findRoles(d.guild, {query, limit, type}); + + const props = res.match(/{([^}]+)}/g); + + data.result = result + .map((x, y) => { + let response = res; + props.forEach((a) => { + response = response.replaceAll(a, (b) => { + if (b === "{position}") return y + 1; + else if (b === "{mention}") return x.toString(); + else { + return x[b.replaceAll("{", "").replaceAll("}", "")]; + } + }); + }); + return response; + }) + .join("\n"); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/findSpecialChars.js b/src/functions/util/findSpecialChars.js new file mode 100644 index 000000000..563ed81e1 --- /dev/null +++ b/src/functions/util/findSpecialChars.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text] = data.inside.splits; + + data.result = text.addBrackets().replace(/(\w+)/g, "").deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/findUser.js b/src/functions/util/findUser.js new file mode 100644 index 000000000..60ed151d2 --- /dev/null +++ b/src/functions/util/findUser.js @@ -0,0 +1,21 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [userResolver, returnSelf = "true"] = data.inside.splits; + userResolver = userResolver + .addBrackets() + .replace(/[\\<>@!]/g, "") + .trim(); + data.result = d.util.findUser(d.client, userResolver); + if (!data.result) + data.result = ( + await d.client.users.fetch(userResolver).catch((e) => undefined) + )?.id; + + data.result = data.result || (returnSelf === "true" ? d.author.id : undefined); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/formatDate.js b/src/functions/util/formatDate.js new file mode 100644 index 000000000..46ea93e02 --- /dev/null +++ b/src/functions/util/formatDate.js @@ -0,0 +1,34 @@ +const formatDate = require("../../handler/FormatDate"); + +module.exports = (d) => { + const code = d.command.code, + r = code.split("$formatDate").length - 1, + inside = code.split("$formatDate")[r].after(); + + const err = d.inside(inside); + + if (err) return d.error(err); + + let [ + date = Date.now().toLocaleString("en-us", {timeZone: d.timezone}), + format = "dddd, DD MMMM YYYY", + ] = inside.splits; + const checkIsValid = new Date( + isNaN(Number(date)) ? date : Number(date) + ); + + if (isNaN(checkIsValid.getTime())) { + return d.error( + `\`${d.func}: Invalid date in ${inside}\`` + ); + } + + return { + code: code.replaceLast( + `$formatDate${inside}`, + format.replace(/\w+/g, (value) => + formatDate(value, checkIsValid, d.timezone) + ) + ), + }; +}; diff --git a/src/functions/util/get.js b/src/functions/util/get.js new file mode 100644 index 000000000..4d6dfa464 --- /dev/null +++ b/src/functions/util/get.js @@ -0,0 +1,10 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [name] = data.inside.splits; + + data.result = d.data.vars[name?.addBrackets()]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/getMentions.js b/src/functions/util/getMentions.js new file mode 100644 index 000000000..f226cd928 --- /dev/null +++ b/src/functions/util/getMentions.js @@ -0,0 +1,23 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + const [type = "users", sep = ", "] = data.inside.splits; + + const mentions = d.mentions; + let result = "" + switch (type) { + case 'users': + result = mentions.users.map(u => u.id).join(sep); + break; + case 'roles': + result = mentions.roles.map(r => r.id).join(sep); + break; + default: + break; + } + + data.result = result + + return { + code: d.util.setCode(data), + }; +} \ No newline at end of file diff --git a/src/functions/util/getTextSplitLength.js b/src/functions/util/getTextSplitLength.js new file mode 100644 index 000000000..e45a46cba --- /dev/null +++ b/src/functions/util/getTextSplitLength.js @@ -0,0 +1,7 @@ +module.exports = d => { + const {code} = d.util.aoiFunc(d); + + return { + code: d.util.setCode({function: d.func, code, result: d.array.length}) + } +} \ No newline at end of file diff --git a/src/functions/util/httpRequest.js b/src/functions/util/httpRequest.js new file mode 100644 index 000000000..a75371ece --- /dev/null +++ b/src/functions/util/httpRequest.js @@ -0,0 +1,65 @@ +const { Agent, fetch } = require('undici'); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [url, method = 'get', body = '', property, error = 'default', ...header] = + data.inside.splits; + + body = body?.trim() === '' ? undefined : body + let headers = {}; + if (header.length === 1) { + try { + headers = JSON.parse(header); + } catch (e) { + header.forEach((x) => { + const split = x.split(':'); + headers[split[0]] = split[1]; + }); + } + } else if (header.length > 1) { + header.forEach((x) => { + const split = x.split(':'); + headers[split[0]] = split[1]; + }); + } + + try { + const response = await fetch(url.addBrackets(), { + method, + headers, + body, + agent: new Agent(), + }); + + const responseBody = await response.text(); + data.result = property + ? eval(`JSON.parse(responseBody)?.${property}`) + : responseBody; + } catch (err) { + console.error(err); + if (error === 'default') { + return d.aoiError.makeMessageError( + d.client, + d.channel, + { content: err }, + {}, + d + ); + } else { + const parsedError = await d.util.errorParser(error, d); + return d.aoiError.makeMessageError( + d.client, + d.channel, + parsedError.data ?? parsedError, + parsedError.options, + d + ); + } + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/indexOf.js b/src/functions/util/indexOf.js new file mode 100644 index 000000000..04a1c9610 --- /dev/null +++ b/src/functions/util/indexOf.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [string, char] = data.inside.splits; + string = string.addBrackets(); + char = char.addBrackets(); + + data.result = string.indexOf(char) + 1; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/indexOfArg.js b/src/functions/util/indexOfArg.js new file mode 100644 index 000000000..0895a4e88 --- /dev/null +++ b/src/functions/util/indexOfArg.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d) + if (data.err) return d.error(data.err) + + const [string, query] = data.inside.splits + + data.result = string.addBrackets().split(" ").indexOf(query.addBrackets()) + 1 + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/util/isBanned.js b/src/functions/util/isBanned.js new file mode 100644 index 000000000..89717a526 --- /dev/null +++ b/src/functions/util/isBanned.js @@ -0,0 +1,20 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id, userID = d.author?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + + let banned = guild.bans.cache.get(userID); + if (!banned) banned = await guild.bans.fetch(userID).catch(e => { + undefined + }); + + data.result = !!banned; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isBoosting.js b/src/functions/util/isBoosting.js new file mode 100644 index 000000000..7fd8bd355 --- /dev/null +++ b/src/functions/util/isBoosting.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = member.premiumSince ? true : false; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isBot.js b/src/functions/util/isBot.js new file mode 100644 index 000000000..4d55e5db1 --- /dev/null +++ b/src/functions/util/isBot.js @@ -0,0 +1,13 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + + data.result = !!user?.bot; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/isChannelManageable.js b/src/functions/util/isChannelManageable.js new file mode 100644 index 000000000..2298ec6bb --- /dev/null +++ b/src/functions/util/isChannelManageable.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d) + if (data.err) return d.error(data.err); + const [channelID = d.channel?.id] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID) + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + data.result = channel.manageable + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isCustomEmoji.js b/src/functions/util/isCustomEmoji.js new file mode 100644 index 000000000..1157d243c --- /dev/null +++ b/src/functions/util/isCustomEmoji.js @@ -0,0 +1,23 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [emoji, guildID = d.guild?.id] = data.inside.splits; + emoji = emoji.split(":"); + if (emoji.length > 1) { + emoji = emoji.pop().replace(">", ""); + } else { + emoji = emoji[0]; + } + const guild = + guildID === "global" ? d.client : await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, "guild", {inside: data.inside}); + + let isemoji = emoji.trim() === "" ? undefined : guild.emojis.cache.get(emoji); + + data.result = !!isemoji; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/isDM.js b/src/functions/util/isDM.js new file mode 100644 index 000000000..f8a410e3a --- /dev/null +++ b/src/functions/util/isDM.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d) + + const [channelID = d.channel?.id] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID) + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + data.result = channel.isDMBased() + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isDeafen.js b/src/functions/util/isDeafen.js new file mode 100644 index 000000000..0157070ed --- /dev/null +++ b/src/functions/util/isDeafen.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = (member?.voice?.serverDeaf || member?.voice?.selfDeaf); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isEveryoneMentioned.js b/src/functions/util/isEveryoneMentioned.js new file mode 100644 index 000000000..291b34cf8 --- /dev/null +++ b/src/functions/util/isEveryoneMentioned.js @@ -0,0 +1,9 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.mentions.everyone; + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} diff --git a/src/functions/util/isGuildDeafened.js b/src/functions/util/isGuildDeafened.js new file mode 100644 index 000000000..ea76ced21 --- /dev/null +++ b/src/functions/util/isGuildDeafened.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + const [userID = d.member?.id, guildID = d.guild?.id] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const user = await d.util.getMember(guild, userID) + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + data.result = user.voice.serverDeaf + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isGuildMuted.js b/src/functions/util/isGuildMuted.js new file mode 100644 index 000000000..4e9610771 --- /dev/null +++ b/src/functions/util/isGuildMuted.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + const [userID = d.member?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const user = await d.util.getMember(guild, userID) + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = user.voice.serverMute + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isGuildPartnered.js b/src/functions/util/isGuildPartnered.js new file mode 100644 index 000000000..678c5fe0c --- /dev/null +++ b/src/functions/util/isGuildPartnered.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.partnered; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isGuildVerified.js b/src/functions/util/isGuildVerified.js new file mode 100644 index 000000000..f4ea11d79 --- /dev/null +++ b/src/functions/util/isGuildVerified.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.verified; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isHoisted.js b/src/functions/util/isHoisted.js new file mode 100644 index 000000000..9a0a3c39e --- /dev/null +++ b/src/functions/util/isHoisted.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(e => undefined); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + + data.result = role.hoist; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isInteger.js b/src/functions/util/isInteger.js new file mode 100644 index 000000000..32dbcf7ab --- /dev/null +++ b/src/functions/util/isInteger.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [number] = data.inside.splits; + + data.result = number.trim() === '' ? false : Number.isInteger(number); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isMentionable.js b/src/functions/util/isMentionable.js new file mode 100644 index 000000000..3ce7c470f --- /dev/null +++ b/src/functions/util/isMentionable.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(e => undefined); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + + data.result = role.mentionable; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isMentioned.js b/src/functions/util/isMentioned.js new file mode 100644 index 000000000..bb968d98f --- /dev/null +++ b/src/functions/util/isMentioned.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [opt] = data.inside.splits; + + data.result = (d.mentions[opt] || d.mentions.users.has(opt) || d.mentions.roles.has(opt) || d.mentions.channels.has(opt)) ? true : false; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isMuted.js b/src/functions/util/isMuted.js new file mode 100644 index 000000000..4cc5222f4 --- /dev/null +++ b/src/functions/util/isMuted.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const member = await d.util.getMember(guild, userID); + if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = (member?.voice?.serverMute || member?.voice?.selfMute); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isNumber.js b/src/functions/util/isNumber.js new file mode 100644 index 000000000..3ca4b4298 --- /dev/null +++ b/src/functions/util/isNumber.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [number] = data.inside.splits; + + data.result = number.trim() === '' ? false : !isNaN(number); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isRoleEditable.js b/src/functions/util/isRoleEditable.js new file mode 100644 index 000000000..379d72cd8 --- /dev/null +++ b/src/functions/util/isRoleEditable.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d) + if (data.err) return d.error(data.err); + const [roleID, guildID = d.guild?.id] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const role = await guild.roles.fetch(roleID); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + data.result = role.editable + return { + code: d.util.setCode(data) + } +} +//Usage: $isRoleEditable[role id;guild id(optional)] diff --git a/src/functions/util/isRoleManaged.js b/src/functions/util/isRoleManaged.js new file mode 100644 index 000000000..a6600608c --- /dev/null +++ b/src/functions/util/isRoleManaged.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = await guild.roles.fetch(roleID).catch(e => undefined); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + + data.result = role.managed; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isSelfDeafened.js b/src/functions/util/isSelfDeafened.js new file mode 100644 index 000000000..df2c43cc7 --- /dev/null +++ b/src/functions/util/isSelfDeafened.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + const [userID = d.member?.id, guildID = d.guild?.id] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const user = await d.util.getMember(guild, userID); + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + data.result = user.voice.selfDeaf + return { + code: d.util.setCode(data) + } +} +//Usage `$isSelfDeafened[user's id(optional); server's id(optional)]` diff --git a/src/functions/util/isSelfMuted.js b/src/functions/util/isSelfMuted.js new file mode 100644 index 000000000..2d9e0540b --- /dev/null +++ b/src/functions/util/isSelfMuted.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + if (data.err) return d.error(data.err); + + const [userID = d.member?.id, guildID = d.guild?.id] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const user = await d.util.getMember(guild, userID) + + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = user.voice.selfMute + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isStreaming.js b/src/functions/util/isStreaming.js new file mode 100644 index 000000000..575c0efa2 --- /dev/null +++ b/src/functions/util/isStreaming.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + const [userID = d.member?.id, guildID = d.guild?.id] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const user = await d.util.getMember(guild, userID) + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + data.result = user.voice.streaming + return { + code: d.util.setCode(data) + } +} +//Usage `$isStreaming[user's id(optional); server's id(optional)]` diff --git a/src/functions/util/isThread.js b/src/functions/util/isThread.js new file mode 100644 index 000000000..9dd9ac919 --- /dev/null +++ b/src/functions/util/isThread.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d) + + const [channelID = d.channel?.id] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID) + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + data.result = channel.isThread() + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isTimeout.js b/src/functions/util/isTimeout.js new file mode 100644 index 000000000..16492c754 --- /dev/null +++ b/src/functions/util/isTimeout.js @@ -0,0 +1,19 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + if (data.err) return d.error(data.err); + + const [guildID = d.guild?.id, userID = d.member?.id] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const user = await d.util.getMember(guild, userID) + + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = user.isCommunicationDisabled() + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isUnicodeEmoji.js b/src/functions/util/isUnicodeEmoji.js new file mode 100644 index 000000000..d1f31fc0f --- /dev/null +++ b/src/functions/util/isUnicodeEmoji.js @@ -0,0 +1,13 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [emoji] = data.inside.splits; + + const extendedPictographicRegex = /[\u{1F300}-\u{1F5FF}\u{1F900}-\u{1F9FF}\u{1FA70}-\u{1FAFF}\u{2600}-\u{27BF}\u{1F680}-\u{1F6FF}\u{24C2}-\u{1F251}]/u; + data.result = extendedPictographicRegex.test(emoji); + + return { + code: d.util.setCode(data) + }; +}; diff --git a/src/functions/util/isUserDmEnabled.js b/src/functions/util/isUserDmEnabled.js new file mode 100644 index 000000000..873c3f104 --- /dev/null +++ b/src/functions/util/isUserDmEnabled.js @@ -0,0 +1,16 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + const [userID = d.author.id] = data.inside.splits; + + const user = await d.util.getUser(d, userID); + if (!user) return d.aoiError.fnError(d, "user", {inside: data.inside}); + + data.result = await user.send(" ").catch(err => err.code); + + data.result = data.result !== 50007; + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/isValidColor.js b/src/functions/util/isValidColor.js new file mode 100644 index 000000000..ce5c4599f --- /dev/null +++ b/src/functions/util/isValidColor.js @@ -0,0 +1,13 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [hex] = data.inside.splits; + const regex = /^#?([0-9A-Fa-f]{3}){1,2}$/; + + data.result = regex.test(hex) + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/util/isValidHex.js b/src/functions/util/isValidHex.js new file mode 100644 index 000000000..5e0e93c8d --- /dev/null +++ b/src/functions/util/isValidHex.js @@ -0,0 +1,13 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [hex] = data.inside.splits; + hex = hex.addBrackets().replace('#', ''); + + data.result = isNaN(parseInt(hex, 16)) ? false : true; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/util/isValidImageLink.js b/src/functions/util/isValidImageLink.js new file mode 100644 index 000000000..fe7583b31 --- /dev/null +++ b/src/functions/util/isValidImageLink.js @@ -0,0 +1,33 @@ +const { Agent, fetch } = require('undici'); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + if (data.err) { + return d.error(data.err); + } + + const [link] = data.inside.splits; + + try { + const response = await fetch(data.inside.inside.addBrackets(), { + method: 'GET', + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36', + }, + agent: new Agent(), + signal: null, // Allows the request to be aborted if necessary + timeout: 5000 // Add a timeout to prevent waiting indefinitely + }); + + const contentType = response.headers.get('content-type'); + data.result = contentType && contentType.startsWith('image'); + } catch (error) { + console.error(error); + return d.error("An error occurred while processing your request."); + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/isValidInvite.js b/src/functions/util/isValidInvite.js new file mode 100644 index 000000000..d4e2b40ca --- /dev/null +++ b/src/functions/util/isValidInvite.js @@ -0,0 +1,13 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [link] = data.inside.splits; + + let res = await d.client.fetchInvite(link.addBrackets()).catch(e => undefined); + data.result = !!res; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isValidLink.js b/src/functions/util/isValidLink.js new file mode 100644 index 000000000..78d58e6eb --- /dev/null +++ b/src/functions/util/isValidLink.js @@ -0,0 +1,19 @@ +const { Agent, fetch } = require('undici'); + +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [link] = data.inside.splits; + + const response = await fetch(link.addBrackets(), { + agent: new Agent(), + method: 'GET', + }).catch(() => null); + + data.result = response !== null; + + return { + code: d.util.setCode(data) + }; +} \ No newline at end of file diff --git a/src/functions/util/isValidObject.js b/src/functions/util/isValidObject.js new file mode 100644 index 000000000..e1f88b8fd --- /dev/null +++ b/src/functions/util/isValidObject.js @@ -0,0 +1,18 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [json] = data.inside.splits; + let validObject = false; + + try { + json = JSON.parse(json.addBrackets()); + validObject = true; + + } catch (e) { + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isVariableExist.js b/src/functions/util/isVariableExist.js new file mode 100644 index 000000000..faa7e519e --- /dev/null +++ b/src/functions/util/isVariableExist.js @@ -0,0 +1,11 @@ +module.exports = (d) => { + + const data = d.util.aoiFunc(d); + const [variable,table = d.client.db.tables[0]] = data.inside.splits; + + data.result = d.client.variableManager.has(variable,table) + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isVideoOn.js b/src/functions/util/isVideoOn.js new file mode 100644 index 000000000..102ee939a --- /dev/null +++ b/src/functions/util/isVideoOn.js @@ -0,0 +1,18 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + if (data.err) return d.error(data.err); + + const [userID = d.member?.id, guildID = d.guild?.id] = data.inside.splits; + const guild = await d.util.getGuild(d, guildID); + + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + const user = await d.util.getMember(guild, userID) + + if (!user) return d.aoiError.fnError(d, 'member', {inside: data.inside}); + + data.result = user.voice.selfVideo + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isVoice.js b/src/functions/util/isVoice.js new file mode 100644 index 000000000..d1aad50ce --- /dev/null +++ b/src/functions/util/isVoice.js @@ -0,0 +1,11 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d) + + const [channelID = d.channel?.id] = data.inside.splits; + const channel = await d.util.getChannel(d, channelID) + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + data.result = channel.isVoiceBased() + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/isWidgetEnabled.js b/src/functions/util/isWidgetEnabled.js new file mode 100644 index 000000000..47573e9bc --- /dev/null +++ b/src/functions/util/isWidgetEnabled.js @@ -0,0 +1,14 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + + const [guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + data.result = guild.widgetEnabled; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/jsonRequest.js b/src/functions/util/jsonRequest.js new file mode 100644 index 000000000..b92da1ce9 --- /dev/null +++ b/src/functions/util/jsonRequest.js @@ -0,0 +1,50 @@ +const { Agent, fetch } = require('undici'); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) { + return { error: data.err }; + } + + const [link, property = '', error, ...heads] = data.inside.splits; + let headers; + + if (heads.length === 0) headers = {}; + else if (heads.length >= 1) { + try { + headers = JSON.parse(heads[0].addBrackets()); + } catch (e) { + for (let head of heads) { + head = head.split(':'); + + headers[head[0].addBrackets()] = head[1].addBrackets() + } + } + } + + let res = await fetch(link.addBrackets(), { + method: 'GET', + headers: headers, + agent: new Agent() + }).catch(async e => { + if (!error || error === '$default') { + return { error: `Failed To Request To API With Reason: ${e}` }; + } else { + const jsonError = await d.util.errorParser(error, d); + await d.aoiError.makeMessageError(d.client, d.channel, jsonError.data ?? jsonError, jsonError.options); + return { error: `Failed To Request To API With Reason: ${e}` }; + } + }); + + res = await res.text(); + + try { + data.result = (property?.trim() === '') ? JSON.stringify(JSON.parse(res), null, 2) : eval(`JSON.parse(res)?.${property?.addBrackets()}`); + } catch (e) { + data.result = res; + } + + return { + code: d.util.setCode(data) + }; +} \ No newline at end of file diff --git a/src/functions/util/let.js b/src/functions/util/let.js new file mode 100644 index 000000000..11a535e92 --- /dev/null +++ b/src/functions/util/let.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [varname, varvalue] = data.inside.splits; + + d.vars[varname.addBrackets()] = varvalue.addBrackets(); + d.data.vars = d.vars; + + return { + code: d.util.setCode(data), + data: d.data + } +} \ No newline at end of file diff --git a/src/functions/util/mentionType.js b/src/functions/util/mentionType.js new file mode 100644 index 000000000..9dd8e7b11 --- /dev/null +++ b/src/functions/util/mentionType.js @@ -0,0 +1,21 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [mention] = data.inside.splits; + + mention = mention.replace(/[\\<>#!@&]/g, ""); + + data.result = d.mentions.everyone || 'none' + + for (const type of ['users', 'channels', 'members', 'roles', 'crosspostedChannels']) { + if (d.mentions[type].has(mention)) { + data.result = type; + break; + } + } + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/mentioned.js b/src/functions/util/mentioned.js new file mode 100644 index 000000000..abbeeb4d2 --- /dev/null +++ b/src/functions/util/mentioned.js @@ -0,0 +1,15 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [index, returnSelf = 'true'] = data.inside.splits; + + index = Number(index) - 1; + if (isNaN(index)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Index Provided In"); + + data.result = [...d.mentions.users.values()][index]?.id || (returnSelf === 'true' ? d.author?.id : "undefined"); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/mentionedChannels.js b/src/functions/util/mentionedChannels.js new file mode 100644 index 000000000..629a85a65 --- /dev/null +++ b/src/functions/util/mentionedChannels.js @@ -0,0 +1,15 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [index, returnSelf = 'true'] = data.inside.splits; + + index = Number(index) - 1; + if (isNaN(index)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Index Provided In"); + + data.result = [...d.mentions.channels.values()][index]?.id || (returnSelf === 'true' ? d.channel?.id : "undefined"); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/mentionedChannelsCount.js b/src/functions/util/mentionedChannelsCount.js new file mode 100644 index 000000000..8c5d7451c --- /dev/null +++ b/src/functions/util/mentionedChannelsCount.js @@ -0,0 +1,9 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.mentions.channels.size; + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/util/mentionedRoles.js b/src/functions/util/mentionedRoles.js new file mode 100644 index 000000000..6391490be --- /dev/null +++ b/src/functions/util/mentionedRoles.js @@ -0,0 +1,15 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [index] = data.inside.splits; + + index = Number(index) - 1; + if (isNaN(index)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, "Invalid Index Provided In"); + + data.result = [...d.mentions.roles.values()][index]?.id || 'undefined'; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/mentionedRolesCount.js b/src/functions/util/mentionedRolesCount.js new file mode 100644 index 000000000..9e9bd9ea7 --- /dev/null +++ b/src/functions/util/mentionedRolesCount.js @@ -0,0 +1,9 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.mentions.roles.size; + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/util/mentionedUsersCount.js b/src/functions/util/mentionedUsersCount.js new file mode 100644 index 000000000..4c9a334ce --- /dev/null +++ b/src/functions/util/mentionedUsersCount.js @@ -0,0 +1,9 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.mentions.users.size; + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/util/messageExists.js b/src/functions/util/messageExists.js new file mode 100644 index 000000000..258be161d --- /dev/null +++ b/src/functions/util/messageExists.js @@ -0,0 +1,15 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [messageID, channelID = d.channel?.id] = data.inside.splits; + + const channel = await d.util.getChannel(d, channelID); + if (!channel) return d.aoiError.fnError(d, 'channel', {inside: data.inside}); + + data.result = (await d.util.getMessage(channel, messageID)) ? true : false; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/messageSlice.js b/src/functions/util/messageSlice.js new file mode 100644 index 000000000..672785f70 --- /dev/null +++ b/src/functions/util/messageSlice.js @@ -0,0 +1,16 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + let [from = 0, to = d.args.length] = data.inside.splits; + + from = Number(from); + to = Number(to); + + if (isNaN(from) || isNaN(to)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + + data.result = d.args.slice(from, to).join(' '); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/nonEscape.js b/src/functions/util/nonEscape.js new file mode 100644 index 000000000..60eedcb85 --- /dev/null +++ b/src/functions/util/nonEscape.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [msg] = data.inside.splits; + + data.result = msg.addBrackets(); + + return { + code: d.util.setCode(data, false) + } +} \ No newline at end of file diff --git a/src/functions/util/numberSeparator.js b/src/functions/util/numberSeparator.js new file mode 100644 index 000000000..da2178d56 --- /dev/null +++ b/src/functions/util/numberSeparator.js @@ -0,0 +1,20 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [number, sep = ','] = data.inside.splits; + + if (isNaN(number)) return d.aoiError.fnError(d, 'custom', {}, 'Invalid Number Provided In'); + + const splits = number.split('.'); + + data.result = Number(splits[0]).toLocaleString().replaceAll(",", sep.addBrackets()) + if (splits[1]) { + data.result = data.result + '.' + splits[1]; + } + + return { + code: d.util.setCode(data) + } +} + diff --git a/src/functions/util/onlyForCategories.js b/src/functions/util/onlyForCategories.js new file mode 100644 index 000000000..8d2c02cd6 --- /dev/null +++ b/src/functions/util/onlyForCategories.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [...stuffs] = data.inside.splits; + const err = stuffs.pop(); + const errorMsg = await d.util.errorParser(err, d); + + if (!stuffs.includes(d.channel.parentId)) { + error = true; + if (err?.trim() === '') { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error + } +} \ No newline at end of file diff --git a/src/functions/util/onlyForChannels.js b/src/functions/util/onlyForChannels.js new file mode 100644 index 000000000..45e2138f7 --- /dev/null +++ b/src/functions/util/onlyForChannels.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [...stuffs] = data.inside.splits; + const err = stuffs.pop(); + const errorMsg = await d.util.errorParser(err, d); + + if (!stuffs.includes(d.channel.id)) { + error = true; + if (err?.trim() === '') { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error + } +} \ No newline at end of file diff --git a/src/functions/util/onlyForGuilds.js b/src/functions/util/onlyForGuilds.js new file mode 100644 index 000000000..03faa0646 --- /dev/null +++ b/src/functions/util/onlyForGuilds.js @@ -0,0 +1,28 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [...stuffs] = data.inside.splits; + const err = stuffs.pop(); + + if (!stuffs.includes(d.guild?.id)) { + error = true; + if (err?.trim() === '') { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error + } +} \ No newline at end of file diff --git a/src/functions/util/onlyForIDs.js b/src/functions/util/onlyForIDs.js new file mode 100644 index 000000000..cdf204820 --- /dev/null +++ b/src/functions/util/onlyForIDs.js @@ -0,0 +1,28 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [...stuffs] = data.inside.splits; + const err = stuffs.pop(); + + if (!stuffs.includes(d.author?.id)) { + error = true; + if (err?.trim() === '') { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error + } +} diff --git a/src/functions/util/onlyForRoles.js b/src/functions/util/onlyForRoles.js new file mode 100644 index 000000000..0949fa161 --- /dev/null +++ b/src/functions/util/onlyForRoles.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [...stuffs] = data.inside.splits; + const err = stuffs.pop(); + const errorMsg = await d.util.errorParser(err, d); + + if (!stuffs.some(x => d.member._roles.includes(x))) { + error = true; + if (err?.trim() === '') { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error + } +} \ No newline at end of file diff --git a/src/functions/util/onlyIf.js b/src/functions/util/onlyIf.js new file mode 100644 index 000000000..edb5d8d60 --- /dev/null +++ b/src/functions/util/onlyIf.js @@ -0,0 +1,30 @@ +const {CheckCondition} = require("../../utils/helpers/checkCondition.js"); +const {mustEscape} = require("../../utils/helpers/mustEscape.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [condition, err = ''] = data.inside.splits; + + if (!eval(CheckCondition.solve(mustEscape(condition)))) { + error = true; + if (err?.trim() === "") { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error, + }; +}; diff --git a/src/functions/util/onlyIfMessageContains.js b/src/functions/util/onlyIfMessageContains.js new file mode 100644 index 000000000..242d6a54c --- /dev/null +++ b/src/functions/util/onlyIfMessageContains.js @@ -0,0 +1,29 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [text, ...stuffs] = data.inside.splits; + const err = stuffs.pop(); + const errorMsg = await d.util.errorParser(err, d); + + if (!stuffs.every(x => text.addBrackets().includes(x.addBrackets()))) { + error = true; + if (err?.trim() === '') { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error + } +} \ No newline at end of file diff --git a/src/functions/util/onlyNSFW.js b/src/functions/util/onlyNSFW.js new file mode 100644 index 000000000..f19ca885d --- /dev/null +++ b/src/functions/util/onlyNSFW.js @@ -0,0 +1,28 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [err] = data.inside.splits; + const errorMsg = await d.util.errorParser(err, d); + + if (!d.channel.nsfw) { + error = true; + if (err?.trim() === '') { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error + } +} \ No newline at end of file diff --git a/src/functions/util/onlyPerms.js b/src/functions/util/onlyPerms.js new file mode 100644 index 000000000..18b7ab113 --- /dev/null +++ b/src/functions/util/onlyPerms.js @@ -0,0 +1,41 @@ +const {Perms} = require("../../utils/Constants.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + let error = false; + + const [...stuffs] = data.inside.splits; + const err = stuffs.pop(); + const errorMsg = await d.util.errorParser(err, d); + + if (stuffs.some((x) => !Perms[x])) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Permission(s) Provided In", + ); + + const memPerms = d.member.permissions; + if (memPerms.has(Perms.administrator)) { + } else if (!stuffs.every((x) => memPerms.has(Perms[x.trim()]))) { + error = true; + if (err?.trim() === "") { + } else { + const errorMsg = await d.util.errorParser(err, d); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorMsg.data ?? errorMsg, + errorMsg.options, + d, + ); + } + } + + return { + code: d.util.setCode(data), + error, + }; +}; diff --git a/src/functions/util/parseDate.js b/src/functions/util/parseDate.js new file mode 100644 index 000000000..4436bf563 --- /dev/null +++ b/src/functions/util/parseDate.js @@ -0,0 +1,18 @@ +const {Time} = require('../../utils/helpers/customParser.js'); + +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time, type = 'date'] = data.inside.splits; + + if (new Date(Number(time)).toLocaleString('en-US') === "Invalid Date") return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Time Provided In'); + + data.result = type === 'time' ? Time.format(Number(time)).toString() : new Date(Number(time)).toLocaleString('en-us', { + timeZone: d.timezone + }); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/parseTime.js b/src/functions/util/parseTime.js new file mode 100644 index 000000000..dcc461a19 --- /dev/null +++ b/src/functions/util/parseTime.js @@ -0,0 +1,18 @@ +const {Time} = require('../../utils/helpers/customParser.js'); + +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [time] = data.inside.splits; + + time = isNaN(time) ? time : Number(time); + + data.result = Time.parse(time); + + data.result = (typeof data.result === 'string' ? data.result : data.result?.ms) || -1; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/partial.js b/src/functions/util/partial.js new file mode 100644 index 000000000..dc409d3ff --- /dev/null +++ b/src/functions/util/partial.js @@ -0,0 +1,9 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.message?.partial; + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/util/ram.js b/src/functions/util/ram.js new file mode 100644 index 000000000..2092ba1d8 --- /dev/null +++ b/src/functions/util/ram.js @@ -0,0 +1,11 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + const [type = 'rss'] = data.inside.splits; + + data.result = process.memoryUsage()[type] / 1024 / 1024; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/util/random.js b/src/functions/util/random.js new file mode 100644 index 000000000..546ee7348 --- /dev/null +++ b/src/functions/util/random.js @@ -0,0 +1,24 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [n1, n2, allow = 'false', random = 'false'] = data.inside.splits; + + const inside = data.inside; + + if (data.inside.splits.length > 4) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Too Many Fields In'); + + if (isNaN(Number(n1)) || isNaN(Number(n2)) || Number(n1) >= Number(n2)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number In'); + + let n = allow === "true" ? Math.random() * (Number(n2) - Number(n1)) + Number(n1) : Math.round(Math.random() * (Number(n2) - Number(n1))) + Number(n1) + + if (d.randoms[inside] && random !== "true") n = d.randoms[inside] + else if (random === "true") d.randoms[`${inside}_${Math.floor(Math.random() * 999999)}`] = n + else d.randoms[inside] = n + + data.result = n; + + return { + code: d.util.setCode(data) + } +} diff --git a/src/functions/util/randomChannelID.js b/src/functions/util/randomChannelID.js new file mode 100644 index 000000000..4f298d9c9 --- /dev/null +++ b/src/functions/util/randomChannelID.js @@ -0,0 +1,29 @@ +module.exports = (d) => { + let data = d.util.aoiFunc(d); + + const [guildID = "global", type = "all"] = data.inside.splits; + + data.result = + guildID === "global" + ? type === "all" + ? d.client.channels.cache.random()?.id + : d.client.channels.cache + .filter((x) => x.type === d.util.channelTypes[type]) + .random()?.id + : d.client.guilds.cache + .get(guildID) + ?.channels.cache.filter((x) => + type === "all" ? true : x.type === d.util.channelTypes[type], + ) + .random()?.id; + + if (!d.randoms[`randomChannelId${data.inside.splits}`]) { + d.randoms[`randomChannelId${data.inside.splits}`] = data.result; + } else { + data.result = d.randoms[`randomChannelId${data.inside.splits}`]; + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/randomEmoji.js b/src/functions/util/randomEmoji.js new file mode 100644 index 000000000..cf6b32ec9 --- /dev/null +++ b/src/functions/util/randomEmoji.js @@ -0,0 +1,14 @@ +module.exports = d => { + let {code, result} = d.util.aoiFunc(d); + + result = d.client.emojis.cache.random()?.id; + if (!d.randoms.randomEmoji) { + d.randoms.randomEmoji = result + } else { + result = d.randoms.randomEmoji; + } + + return { + code: d.util.setCode({function: d.func, code, result}) + } +} \ No newline at end of file diff --git a/src/functions/util/randomRoleID.js b/src/functions/util/randomRoleID.js new file mode 100644 index 000000000..937ded7c2 --- /dev/null +++ b/src/functions/util/randomRoleID.js @@ -0,0 +1,18 @@ +module.exports = d => { + let {code, result, inside} = d.util.aoiFunc(d); + const [guildID = d.guild?.id] = inside.splits; + + const guild = d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside}); + + result = guild.roles.cache.random()?.id; + if (!d.randoms[`randomRole_${guild.id}`]) { + d.randoms[`randomRole_${guild.id}`] = result + } else { + result = d.randoms[`randomRole_${guild.id}`]; + } + + return { + code: d.util.setCode({function: d.func, code, result, inside}) + } +} \ No newline at end of file diff --git a/src/functions/util/randomShuffle.js b/src/functions/util/randomShuffle.js new file mode 100644 index 000000000..8c0e10909 --- /dev/null +++ b/src/functions/util/randomShuffle.js @@ -0,0 +1,17 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + let [...texts] = data.inside.splits; + + function shuffle(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; + } + + data.result = shuffle(texts)[Math.floor(Math.random() * texts.length)] + return { + code: d.util.setCode(data), + }; +} \ No newline at end of file diff --git a/src/functions/util/randomString.js b/src/functions/util/randomString.js new file mode 100644 index 000000000..c22bc8320 --- /dev/null +++ b/src/functions/util/randomString.js @@ -0,0 +1,39 @@ +const {Characters} = require("../../utils/Constants.js"); +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [range, diffExec = "false"] = data.inside.splits; + + if (isNaN(range)) + return d.aoiError.fnError(d, "custom", {inside: data.inside}); + + let i = 0; + data.result = ''; + const randoms = d.randoms; + + if (randoms[`randomString${data.inside}`]) + data.result = randoms[`randomString${data.inside}`]; + else if (diffExec === "true") { + while (i < Number(range)) { + data.result += Characters.charAt( + Math.floor(Math.random() * Characters.length), + ); + i++; + } + d.randoms[ + `$randomString${data.inside}${Math.floor(Math.random() * 999999)}` + ] = data.result; + } else { + while (i < Number(range)) { + data.result += Characters.charAt( + Math.floor(Math.random() * Characters.length), + ); + i++; + } + d.randoms[`$randomString${data.inside}`] = data.result; + } + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/randomText.js b/src/functions/util/randomText.js new file mode 100644 index 000000000..72935889f --- /dev/null +++ b/src/functions/util/randomText.js @@ -0,0 +1,18 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [...words] = data.inside.splits; + + data.result = words[Math.floor(Math.random() * words.length)]; + const randoms = d.randoms; + if (!randoms[`randomText${data.inside}`]) { + randoms[`randomText${data.inside}`] = data.result; + } else { + data.result = randoms[`randomText${data.inside}`]; + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/randomUserID.js b/src/functions/util/randomUserID.js new file mode 100644 index 000000000..5d838a85b --- /dev/null +++ b/src/functions/util/randomUserID.js @@ -0,0 +1,17 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + + const [guildID = "global"] = data.inside.splits; + if (d.randoms.randomUserId) data.result = d.randoms.randomUserId; + else { + if (guildID === "global") data.result = d.client.users.cache.random()?.id; + else + data.result = d.client.guilds.cache + .get(guildID) + ?.members.cache.random()?.id; + d.randoms.randomUserId = data.result; + } + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/repeatMessage.js b/src/functions/util/repeatMessage.js new file mode 100644 index 000000000..35e00459f --- /dev/null +++ b/src/functions/util/repeatMessage.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [time, text] = data.inside.splits; + + if (isNaN(time)) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Number Provided In'); + + data.result = text.repeat(Number(time)); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/replaceText.js b/src/functions/util/replaceText.js new file mode 100644 index 000000000..d5590f4f7 --- /dev/null +++ b/src/functions/util/replaceText.js @@ -0,0 +1,52 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, replacer, replacedTo, times = "all"] = data.inside.splits; + + if (times === "all") { + data.result = text + .addBrackets() + .replaceAll(replacer.addBrackets(), replacedTo.addBrackets()) + .deleteBrackets(); + } else { + if (Number(times) === 0) data.result = text.deleteBrackets(); + else if (Number(times) === 1) { + data.result = text + .addBrackets() + .replace(replacer.addBrackets(), replacedTo.addBrackets()) + .deleteBrackets(); + } else { + const time = Number(times) + 1; + if (isNaN(time)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Number Provided In", + ); + + const arr = text.addBrackets().split(replacer.addBrackets()); + let sliceTo; + let slice; + if (Number(times) > 0) { + sliceTo = arr.slice(0, time).join(replacedTo.addBrackets()); + } else { + sliceTo = arr.slice(0, Number(times)).join(replacer.addBrackets()); + } + if (Number(times) > 0) { + slice = + replacer.addBrackets() + arr.slice(time).join(replacer.addBrackets()); + } else { + slice = + replacedTo.addBrackets() + + arr.slice(Number(times)).join(replacedTo.addBrackets()); + } + data.result = (sliceTo + slice).deleteBrackets(); + } + } + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/replaceTextWithRegex.js b/src/functions/util/replaceTextWithRegex.js new file mode 100644 index 000000000..b388a05f5 --- /dev/null +++ b/src/functions/util/replaceTextWithRegex.js @@ -0,0 +1,31 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + let [text, reg, flags, newT] = data.inside.splits; + + reg = + reg.startsWith("/") && reg.endsWith("/") + ? reg.slice(1, reg.length - 1) + : reg; + + if (newT === undefined) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + `Invalid Amount Of Fields In`, + ); + + data.result = text + .addBrackets() + .replace( + new RegExp(reg.addBrackets(), flags || undefined), + newT.addBrackets(), + ) + .deleteBrackets(); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/resolveColor.js b/src/functions/util/resolveColor.js new file mode 100644 index 000000000..86f690e04 --- /dev/null +++ b/src/functions/util/resolveColor.js @@ -0,0 +1,38 @@ +const {Util} = require("discord.js"); +const {RBGtoHex} = require("../../utils/helpers/functions.js"); +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [type, returnAs = "number", ...datas] = data.inside.splits; + + if (returnAs === "number") { + data.result = Util.resolveColor(datas.length === 1 ? datas[0] : datas); + } else { + if (type === "decimal") { + if (datas.length !== 1) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Number Of Fields Provided In", + ); + + data.result = "#" + Number(datas[0]).toString(16); + } else if (type === "rgb") { + if (!datas.every((x) => isNaN(x) === false)) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Number Provided In", + ); + + data.result = RBGtoHex(...datas.map((x) => Number(x))); + } + } + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/resolveEmojiID.js b/src/functions/util/resolveEmojiID.js new file mode 100644 index 000000000..4fe804085 --- /dev/null +++ b/src/functions/util/resolveEmojiID.js @@ -0,0 +1,12 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const emoji = data.inside.inside; + + data.result = (await d.util.getEmoji(d, emoji))?.id ?? ""; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/resolveStickerID.js b/src/functions/util/resolveStickerID.js new file mode 100644 index 000000000..eacdbacb9 --- /dev/null +++ b/src/functions/util/resolveStickerID.js @@ -0,0 +1,12 @@ +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const sticker = data.inside.inside; + + data.result = (await d.util.getSticker(d, sticker))?.id ?? ""; + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/reverse.js b/src/functions/util/reverse.js new file mode 100644 index 000000000..1684229c1 --- /dev/null +++ b/src/functions/util/reverse.js @@ -0,0 +1,12 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text] = data.inside.splits; + + data.result = text.split("").reverse().join(""); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/roleExists.js b/src/functions/util/roleExists.js new file mode 100644 index 000000000..2a8d5c6a9 --- /dev/null +++ b/src/functions/util/roleExists.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleID, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = roleID.trim() === '' ? false : await guild.roles.fetch(roleID).catch(err => undefined); + + data.result = role ? true : false; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/roleID.js b/src/functions/util/roleID.js new file mode 100644 index 000000000..c05bdbe00 --- /dev/null +++ b/src/functions/util/roleID.js @@ -0,0 +1,17 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [roleResolver, guildID = d.guild?.id] = data.inside.splits; + + const guild = await d.util.getGuild(d, guildID); + if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); + + const role = guild.roles.cache.find(x => x.id === roleResolver || x.name.toLowerCase() === roleResolver.addBrackets().toLowerCase()); + if (!role) return d.aoiError.fnError(d, 'role', {inside: data.inside}); + data.result = role?.id + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/spliceTextJoin.js b/src/functions/util/spliceTextJoin.js new file mode 100644 index 000000000..78ee7194a --- /dev/null +++ b/src/functions/util/spliceTextJoin.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, splitter, sep1 = ' , ', sep2 = '\n'] = data.inside.splits; + + const Data = text.addBrackets()?.split(splitter.addBrackets()); + + data.result = Data.map(_ => Data.splice(0, Number(every))).filter(e => e).map(d => d.join(separator1.addBrackets())).join(separator2.addBrackets()).deleteBrackets(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/splitText.js b/src/functions/util/splitText.js new file mode 100644 index 000000000..95e104635 --- /dev/null +++ b/src/functions/util/splitText.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [index] = data.inside.splits; + + if (isNaN(index) || Number(index) < 1) return d.aoiError.fnError(d, 'custom', {inside: data.inside}, 'Invalid Index Provided In'); + + data.result = d.array[Number(index) - 1]; + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/stringEndsWith.js b/src/functions/util/stringEndsWith.js new file mode 100644 index 000000000..9f223e045 --- /dev/null +++ b/src/functions/util/stringEndsWith.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, ...checks] = data.inside.splits; + const result = checks.some(check => text.addBrackets().endsWith(check.addBrackets())); + data.result = result + + return { + code: d.util.setCode(data) + } + } diff --git a/src/functions/util/stringStartsWith.js b/src/functions/util/stringStartsWith.js new file mode 100644 index 000000000..ae51b2cc7 --- /dev/null +++ b/src/functions/util/stringStartsWith.js @@ -0,0 +1,12 @@ +module.exports = async d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text, ...checks] = data.inside.splits; + const result = checks.some(check => text.addBrackets().startsWith(check.addBrackets())); + data.result = result + + return { + code: d.util.setCode(data) + } + } diff --git a/src/functions/util/tempCooldown.js b/src/functions/util/tempCooldown.js new file mode 100644 index 000000000..fa65e2338 --- /dev/null +++ b/src/functions/util/tempCooldown.js @@ -0,0 +1,62 @@ +const {Time} = require("../../utils/helpers/customParser.js"); +module.exports = async (d) => { + const {code} = d.command; + const inside = d.unpack(); + const err = d.inside(inside); + if (err) return d.error(err); + + let [time, id, errorObject = ""] = inside.splits; + let error; + + time = isNaN(time) ? Time.parse(time).ms : time; + + if (!time) + return d.aoiError.fnError( + d, + "custom", + {inside}, + "Invalid Time Provided In", + ); + + let CooldownTable = d.client.cacheManager.caches.cache.cooldowns; + if (!CooldownTable) + CooldownTable = d.client.cacheManager.createCache("cache", "cooldowns"); + + let cooldown = CooldownTable.get(id); + + if (!cooldown) { + cooldown = Date.now() + time; + CooldownTable.set(id, cooldown); + } else if (Date.now() < cooldown) { + const {object, humanize, toString} = Time.format(cooldown - Date.now()); + errorObject = errorObject + .replaceAll("%time%", humanize()) + .replaceAll("%year%", object.years) + .replaceAll("%month%", object.months) + .replaceAll("%week%", object.weeks) + .replaceAll("%day%", object.days) + .replaceAll("%hour%", object.hours) + .replaceAll("%min%", object.minutes) + .replaceAll("%sec%", object.seconds) + .replaceAll("%ms%", object.ms) + .replaceAll("%fullTime%", toString()); + + errorObject = await d.util.errorParser(errorObject); + d.aoiError.makeMessageError( + d.client, + d.channel, + errorObject.data ?? errorObject, + errorObject.options, + d, + ); + error = true; + } else { + cooldown = Date.now() + time; + CooldownTable.set(id, cooldown); + } + + return { + code: d.util.setCode({function: d.func, code, inside}), + error, + }; +}; diff --git a/src/functions/util/textSlice.js b/src/functions/util/textSlice.js new file mode 100644 index 000000000..d1a1a7bf9 --- /dev/null +++ b/src/functions/util/textSlice.js @@ -0,0 +1,21 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + + let [text, from = 0, to] = data.inside.splits; + + from = Number(from); + to = to ? Number(to) : undefined; + if (isNaN(from) || (to && isNaN(to))) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Number Provided In", + ); + + data.result = text.slice(from, to); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/textSplit.js b/src/functions/util/textSplit.js new file mode 100644 index 000000000..1aa57f83b --- /dev/null +++ b/src/functions/util/textSplit.js @@ -0,0 +1,14 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + let [text, sep = ' '] = data.inside.splits; + + d.array = text.addBrackets().split(sep.addBrackets()); + d.data.array = d.array; + + return { + code: d.util.setCode(data), + data: d.data, + array: d.array, + } +} diff --git a/src/functions/util/textSplitMap.js b/src/functions/util/textSplitMap.js new file mode 100644 index 000000000..947f630e4 --- /dev/null +++ b/src/functions/util/textSplitMap.js @@ -0,0 +1,44 @@ +const Interpreter = require("../../core/interpreter.js"); + +module.exports = async (d) => { + const data = d.util.aoiFunc(d); + + let commands = data.inside.splits; + const content = []; + + if ( + commands.some( + (x) => + !d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === x.trim().toLowerCase(), + ), + ) + ) + return d.aoiError.fnError( + d, + "custom", + {inside: data.inside}, + "Invalid Awaited Command In", + ); + + for (const a of d.array) { + for (const command of commands) { + const cmd = d.client.cmd.awaited.find( + (y) => y.name.toLowerCase() === command.trim().toLowerCase(), + ); + if (!cmd) continue; + else { + const code = ( + await Interpreter(d.client, d.message, [a], cmd, d.client.db, true, undefined, {...d.data}) + )?.code; + content.push(code); + } + } + } + + data.result = content.join("\n"); + + return { + code: d.util.setCode(data), + }; +}; diff --git a/src/functions/util/textTrim.js b/src/functions/util/textTrim.js new file mode 100644 index 000000000..3f064a5ca --- /dev/null +++ b/src/functions/util/textTrim.js @@ -0,0 +1,10 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + + let [text] = data.inside.splits; + data.result = text.trim(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/toLocaleUpperCase.js b/src/functions/util/toLocaleUpperCase.js new file mode 100644 index 000000000..aa58feddf --- /dev/null +++ b/src/functions/util/toLocaleUpperCase.js @@ -0,0 +1,18 @@ +module.exports = (d) => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [texts] = data.inside.splits; + + data.result = texts + .split(" ") + .map( + (text) => + text.addBrackets().slice(0, 1).toUpperCase() + + text.addBrackets().slice(1).toLowerCase(), + ).join(" "); + + return { + code: d.util.setCode(data), + }; +}; \ No newline at end of file diff --git a/src/functions/util/toLowerCase.js b/src/functions/util/toLowerCase.js new file mode 100644 index 000000000..60439e7e0 --- /dev/null +++ b/src/functions/util/toLowerCase.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text] = data.inside.splits; + + data.result = text.addBrackets().toLowerCase(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/functions/util/toUpperCase.js b/src/functions/util/toUpperCase.js new file mode 100644 index 000000000..d88c3726b --- /dev/null +++ b/src/functions/util/toUpperCase.js @@ -0,0 +1,12 @@ +module.exports = d => { + const data = d.util.aoiFunc(d); + if (data.err) return d.error(data.err); + + const [text] = data.inside.splits; + + data.result = text.addBrackets().toUpperCase(); + + return { + code: d.util.setCode(data) + } +} \ No newline at end of file diff --git a/src/handler/AoiAutoUpdate.js b/src/handler/AoiAutoUpdate.js new file mode 100644 index 000000000..2b8eec2b2 --- /dev/null +++ b/src/handler/AoiAutoUpdate.js @@ -0,0 +1,120 @@ +const { exec } = require("child_process"); +const { Agent, fetch } = require("undici"); +const json = require("../../package.json"); +const AoiError = require("../classes/AoiError.js"); + +module.exports = async () => { + try { + const res = await fetch("https://registry.npmjs.org/aoi.js", { + dispatcher: new Agent({ + keepAliveTimeout: 10000, + keepAliveMaxTimeout: 15000, + }), + headers: { + "User-Agent": "aoi.js", + }, + }); + + const data = await res.json(); + if (json.version !== data["dist-tags"].latest) { + AoiError.createCustomBoxedMessage( + [ + { + text: "", + textColor: "white", + }, + { + text: "aoi.js is outdated!", + textColor: "red", + }, + { + text: `Available version: ${data["dist-tags"].latest} ready to install.`, + textColor: "white", + }, + { + text: "", + textColor: "white", + }, + { + text: "Installing latest aoi.js version...", + textColor: "yellow", + }, + ], + "white", + { text: "aoi.js AutoUpdate ", textColor: "yellow" } + ); + + const Process = exec("npm i aoi.js@latest", (error) => { + if (error) + return AoiError.createCustomBoxedMessage( + [ + { + text: `aoi.js AutoUpdate: ERR! ${error.message}`, + textColor: "red", + }, + ], + "white", + { text: "aoi.js AutoUpdate", textColor: "yellow" } + ); + + AoiError.createCustomBoxedMessage( + [ + { + text: `Successfully Installed aoi.js v${data["dist-tags"].latest}.`, + textColor: "white", + }, + { + text: "", + textColor: "white", + }, + { + text: "Commencing 'RESTART' in 3 seconds...", + textColor: "yellow", + }, + ], + "white", + { text: "aoi.js AutoUpdate ", textColor: "yellow" } + ); + + setTimeout(Reboot, 3000); + }); + } else { + return; + } + } catch (error) { + AoiError.createCustomBoxedMessage( + [ + { + text: "aoi.js AutoUpdate: Unexpected error when trying to reach API.", + textColor: "red", + }, + ], + "white", + { text: "aoi.js AutoUpdate ", textColor: "yellow" } + ); + } +}; + +function Reboot() { + try { + process.on("exit", () => { + require("child_process").spawn(process.argv.shift(), process.argv, { + cwd: process.cwd(), + detached: true, + stdio: "inherit", + }); + }); + process.exit(); + } catch (e) { + AoiError.createCustomBoxedMessage( + [ + { + text: `aoi.js AutoUpdate: ERR! Failed to commence 'RESTART', ${e.message}`, + textColor: "red", + }, + ], + "white", + { text: "aoi.js AutoUpdate ", textColor: "yellow" } + ); + } +} diff --git a/src/handler/AoiLogs.js b/src/handler/AoiLogs.js new file mode 100644 index 000000000..6fccdcc1e --- /dev/null +++ b/src/handler/AoiLogs.js @@ -0,0 +1,26 @@ +const json = require("../../package.json"); +const AoiError = require("../classes/AoiError.js"); + +module.exports = async () => { + try { + AoiError.createCustomBoxedMessage( + [ + { + text: `Installed on v${json.version}`, + textColor: "green", + }, + { + text: "Discord Server: https://discord.gg/HMUfMXDQsV", + textColor: "blue", + }, + ], + "white", + { + text: "aoi.js ", + textColor: "cyan", + } + ); + } catch (err) { + console.error(`AoiLogs: Error during initialization: ${err}`); + } +}; diff --git a/src/handler/AoiStart.js b/src/handler/AoiStart.js new file mode 100644 index 000000000..2c730f279 --- /dev/null +++ b/src/handler/AoiStart.js @@ -0,0 +1,42 @@ +const Interpreter = require("../core/interpreter.js"); + +module.exports = async (client, options) => { + if (client.aoiOptions.aoiLogs !== false) { + await require("./AoiLogs.js")(client); + } + + if (client.aoiOptions.aoiWarning !== false) { + await require("./AoiWarning.js")(client); + } + + if (client.aoiOptions.aoiAutoUpdate === true) { + await require("./AoiAutoUpdate.js")(client); + } + + if (!(client.aoiOptions.disableAoiDB === true || (client.aoiOptions.database && client.aoiOptions.database))) { + await require("./Custom/timeout.js")( + { client, interpreter: Interpreter }, + undefined, + undefined, + undefined, + true, + ); + + await require("./Custom/timeoutPulse.js")( + { client, interpreter: Interpreter }, + undefined, + undefined, + undefined, + undefined, + true, + ); + + setInterval(async () => { + await require("./Custom/handleResidueData.js")(client); + }, 3.6e6); + } + + if (client.cmd.loop.size) { + await require("./Custom/loop.js")(client); + } +}; diff --git a/src/handler/AoiWarning.js b/src/handler/AoiWarning.js new file mode 100644 index 000000000..44b06dddd --- /dev/null +++ b/src/handler/AoiWarning.js @@ -0,0 +1,61 @@ +const { Agent, fetch } = require("undici"); +const json = require("../../package.json"); +const AoiError = require("../classes/AoiError.js"); + +const compareVersions = (a, b) => a.split(".").map(Number).some((v, i) => v > (b.split(".")[i] || 0)); + +module.exports = async () => { + try { + const res = await fetch("https://registry.npmjs.org/aoi.js", { + dispatcher: new Agent({ + keepAliveTimeout: 10000, // 10 seconds + keepAliveMaxTimeout: 15000, // 15 seconds + }), + headers: { + "User-Agent": "aoi.js", // required by npm registry API + }, + }); + + const data = await res.json(); + const latestVersion = data["dist-tags"].latest; + + if (compareVersions(json.version, latestVersion) === false && json.version !== latestVersion) { + AoiError.createCustomBoxedMessage( + [ + { + text: 'aoi.js is outdated! Update with "npm install aoi.js@latest".', + textColor: "red", + }, + ], + "white", + { text: "AoiWarning", textColor: "yellow" } + ); + } else if (json.version.includes("dev") || compareVersions( json.version, latestVersion) === true) { + AoiError.createCustomBoxedMessage( + [ + { + text: "You are currently on a development version.", + textColor: "red", + }, + { + text: "This version may or may not contain unfinished features.", + textColor: "red", + }, + ], + "white", + { text: "AoiWarning ", textColor: "yellow" } + ); + } + } catch (error) { + AoiError.createCustomBoxedMessage( + [ + { + text: `AoiWarning: Failed to check for updates: ${error.message}`, + textColor: "white", + }, + ], + "red", + { text: "AoiWarning", textColor: "yellow" } + ); + } +}; diff --git a/src/handler/AutoModerationConfiguration/automodCreate.js b/src/handler/AutoModerationConfiguration/automodCreate.js new file mode 100644 index 000000000..819121cac --- /dev/null +++ b/src/handler/AutoModerationConfiguration/automodCreate.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (app, client) => { + const cmds = client.cmd.autoModCreate.allValues(); + let chan; + const data = { + guild: client.guilds.cache.get(app.guildId), + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { automodAction: app }, + chan, + ); + } +}; diff --git a/src/handler/AutoModerationConfiguration/automodDelete.js b/src/handler/AutoModerationConfiguration/automodDelete.js new file mode 100644 index 000000000..a8804c325 --- /dev/null +++ b/src/handler/AutoModerationConfiguration/automodDelete.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (app, client) => { + const cmds = client.cmd.autoModDelete.allValues(); + let chan; + const data = { + guild: client.guilds.cache.get(app.guildId), + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldautomodAction: app }, + chan, + ); + } +}; diff --git a/src/handler/AutoModerationConfiguration/automodUpdate.js b/src/handler/AutoModerationConfiguration/automodUpdate.js new file mode 100644 index 000000000..35690ad62 --- /dev/null +++ b/src/handler/AutoModerationConfiguration/automodUpdate.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oa, na, client) => { + const cmds = client.cmd.autoModUpdate.allValues(); + let chan; + const data = { + guild: na.guild, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { automodAction: na, oldautomodAction: oa }, + chan, + ); + } +}; diff --git a/src/handler/AutoModerationExecution/autoModActionExecution.js b/src/handler/AutoModerationExecution/autoModActionExecution.js new file mode 100644 index 000000000..511aaf63a --- /dev/null +++ b/src/handler/AutoModerationExecution/autoModActionExecution.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (app, client) => { + const cmds = client.cmd.autoModActionExecution.allValues(); + let chan; + const data = { + guild: client.guilds.cache.get(app.guildId), + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { automodAction: app }, + chan, + ); + } +}; diff --git a/src/handler/Custom/functionError.js b/src/handler/Custom/functionError.js new file mode 100644 index 000000000..e93aefe93 --- /dev/null +++ b/src/handler/Custom/functionError.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (error, client) => { + const cmds = client.cmd.functionError.allValues(); + let chan; + const data = { + guild: error.guild, + channel: error.channel, + author: error.author, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { errorData: error }, + chan, + ); + } +}; diff --git a/src/handler/Custom/handleResidueData.js b/src/handler/Custom/handleResidueData.js new file mode 100644 index 000000000..d00eda889 --- /dev/null +++ b/src/handler/Custom/handleResidueData.js @@ -0,0 +1,9 @@ +async function handleResidueData(client) { + const db = client.db; + await client.db.deleteMany("__aoijs_vars__", (data) => { + const key = data.key.split("_")[0]; + if (key === "cooldown" && data.value < Date.now()) return true; + }); +} + +module.exports = handleResidueData; diff --git a/src/handler/Custom/loop.js b/src/handler/Custom/loop.js new file mode 100644 index 000000000..a4f10c9b6 --- /dev/null +++ b/src/handler/Custom/loop.js @@ -0,0 +1,59 @@ +const Interpreter = require("../../core/interpreter.js"); +/** + * @param {import('../../classes/AoiClient.js')} client + */ +module.exports = async (client) => { + const cmds = client.cmd.loop.allValues(); + let chan; + let Data = { + client: client, + channel: undefined, + guild: undefined, + }; + for (const cmd of cmds) { + const data = { ...Data }; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = await client.channels.fetch(id?.code); + data.channel = chan; + data.guild = chan?.guild; + } else { + chan = await client.channels.fetch(cmd.channel); + data.channel = chan; + data.guild = chan?.guild; + } + setInterval(async () => { + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + {}, + chan, + ); + }, cmd.every || 60000); + + if (cmd.executeOnStartup) + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + {}, + chan, + ); + } +}; diff --git a/src/handler/Custom/timeout.js b/src/handler/Custom/timeout.js new file mode 100644 index 000000000..6ab7c24be --- /dev/null +++ b/src/handler/Custom/timeout.js @@ -0,0 +1,103 @@ +module.exports = async (d, name, duration, timeoutData, onReady) => { + let cmds = d.client.cmd.timeout.allValues(); + if (onReady) { + const datas = await d.client.db.all( + "__aoijs_vars__", + (data) => data.key.startsWith("setTimeout_"), + ); + for (const data of datas.filter((x) => { + return !x.value.__pulseEvery__; + })) { + let t = data.value; + t.__timeoutIds__ = []; + const dura = t.__duration__ - Date.now(); + cmds = cmds.filter((x) => x.name === t.__timeoutName__); + if (dura > 0) { + for (const cmd of cmds) { + const timeout = setTimeout(async () => { + await d.interpreter( + d.client, + {}, + [], + cmd, + d.client.db, + false, + undefined, + { timeoutData: t }, + ); + t.__timeoutIds__.push(timeout[Symbol.toPrimitive]()); + + await d.client.db.delete( + "__aoijs_vars__", + data.key, + ); + }, dura); + } + d.client.db.set( + "__aoijs_vars__", + "setTimeout", + t.__id__, + t, + ); + } else { + for (const cmd of cmds) { + await d.interpreter( + d.client, + {}, + [], + cmd, + d.client.db, + false, + undefined, + { timeoutData: t }, + ); + } + await d.client.db.delete("__aoijs_vars__", data.key); + continue; + } + } + } else { + timeoutData.__timeoutIds__ = []; + if (name) { + cmds = cmds.filter((x) => x.name === name); + } + const ids = []; + for (const cmd of cmds) { + const timeout = setTimeout(async () => { + await d.interpreter( + d.client, + {}, + [], + cmd, + d.client.db, + false, + undefined, + { timeoutData }, + ); + + ids.splice(ids.indexOf(timeout[Symbol.toPrimitive]()), 1); + if (ids.length === 0) { + await d.client.db.delete( + "__aoijs_vars__", + timeoutData.__id__, + ); + } else { + await d.client.db.set( + "__aoijs_vars__", + "setTimeout", + timeoutData.__id__, + timeoutData, + ); + } + }, duration); + ids.push(timeout[Symbol.toPrimitive]()); + } + timeoutData.__timeoutIds__ = ids; + await d.client.db.set( + "__aoijs_vars__", + "setTimeout", + timeoutData.__id__, + timeoutData, + ); + } +}; diff --git a/src/handler/Custom/timeoutPulse.js b/src/handler/Custom/timeoutPulse.js new file mode 100644 index 000000000..1246b7601 --- /dev/null +++ b/src/handler/Custom/timeoutPulse.js @@ -0,0 +1,102 @@ +module.exports = async (d, name, duration, pulse, timeoutData, onReady) => { + let cmds = d.client.cmd.pulse.allValues(); + + if (onReady) { + const datas = await d.client.db.all("__aoijs_vars__", (data) => + data.key.startsWith("setTimeout_"), + ); + for (const data of datas.filter((x) => x.value?.__pulseEvery__)) { + let t = data.value; + + t.__timeoutIds__ = []; + t.__pulseIds__ = []; + cmds = cmds.filter((x) => x.name === t.__timeoutName__); + + if (t.__duration__ - Date.now() > 0) { + for (const cmd of cmds) { + const interval = setInterval(async () => { + await d.interpreter( + d.client, + {}, + [], + cmd, + d.client.db, + false, + undefined, + { timeoutData: t }, + ); + }, t.__pulseEvery__); + + t.__pulseIds__.push(interval[Symbol.toPrimitive()]()); + + const timeout = setTimeout(async () => { + clearInterval(interval); + await d.client.db.delete("__aoijs_vars__", data.key); + }, t.__duration__ - Date.now()); + + t.__timeoutIds__.push(timeout[Symbol.toPrimitive()]()); + } + d.client.db.set("__aoijs_vars__", "setTimeout", t.__id__, t); + } else { + await d.client.db + .delete("__aoijs_vars__", data.key) + .catch(console.error); + } + } + } else { + if (name) { + cmds = cmds.filter((x) => x.name === name); + } + + timeoutData.__timeoutIds__ = []; + timeoutData.__pulseIds__ = []; + + for (const cmd of cmds) { + const interval = setInterval(() => { + d.interpreter( + d.client, + {}, + [], + cmd, + d.client.db, + false, + undefined, + { + timeoutData, + }, + ); + }, pulse || duration); + + timeoutData.__pulseIds__.push(interval[Symbol.toPrimitive()]()); + + const timeout = setTimeout(async () => { + clearInterval(interval); + + const ids = timeoutData.__timeoutIds__; + ids.splice(ids.indexOf(timeout[Symbol.toPrimitive]()), 1); + + if (ids.length === 0) + await d.client.db.delete( + "__aoijs_vars__", + timeoutData.__id__, + ); + else + await d.client.db.set( + "__aoijs_vars__", + "setTimeout", + timeoutData.__id__, + timeoutData, + ); + }, duration); + + timeoutData.__timeoutIds__.push(timeout[Symbol.toPrimitive()]()); + } + + d.client.db.set( + "__aoijs_vars__", + "setTimeout", + timeoutData.__id__, + timeoutData, + ); + } +}; diff --git a/src/handler/Custom/varCreate.js b/src/handler/Custom/varCreate.js new file mode 100644 index 000000000..0a146fa6b --- /dev/null +++ b/src/handler/Custom/varCreate.js @@ -0,0 +1,40 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (data, client) => { + let chan; + const d = { + client: client, + guild: data.guild, + channel: data.channel, + message: data.message, + author: data.author, + }; + const cmds = client.cmd.variableCreate.allValues(); + for (const cmd of cmds) { + const id = cmd.channel?.includes("$") + ? ( + await Interpreter( + client, + d, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ) + )?.code + : cmd.channel; + + chan = client.channels.cache.get(id); + + await Interpreter( + client, + d, + [], + cmd, + client.db, + false, + chan?.id, + { oldv: data }, + chan, + ); + } +}; diff --git a/src/handler/Custom/varDelete.js b/src/handler/Custom/varDelete.js new file mode 100644 index 000000000..f86fabc87 --- /dev/null +++ b/src/handler/Custom/varDelete.js @@ -0,0 +1,40 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (data, client) => { + let chan; + const d = { + client: client, + guild: data.guild, + channel: data.channel, + message: data.message, + author: data.author, + }; + const cmds = client.cmd.variableDelete.allValues(); + for (const cmd of cmds) { + const id = cmd.channel?.includes("$") + ? ( + await Interpreter( + client, + d, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ) + )?.code + : cmd.channel; + + chan = client.channels.cache.get(id); + + await Interpreter( + client, + d, + [], + cmd, + client.db, + false, + chan?.id, + { newv: data }, + chan, + ); + } +}; diff --git a/src/handler/Custom/varUpdate.js b/src/handler/Custom/varUpdate.js new file mode 100644 index 000000000..763f59474 --- /dev/null +++ b/src/handler/Custom/varUpdate.js @@ -0,0 +1,40 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (olddata, newdata, client) => { + let chan; + const d = { + client: client, + guild: newdata.guild, + channel: newdata.channel, + message: newdata.message, + author: newdata.author, + }; + const cmds = client.cmd.variableUpdate.allValues(); + for (const cmd of cmds) { + const id = cmd.channel?.includes("$") + ? ( + await Interpreter( + client, + d, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ) + )?.code + : cmd.channel; + + chan = client.channels.cache.get(id?.code); + + await Interpreter( + client, + d, + [], + cmd, + client.db, + false, + chan?.id, + { newv: newdata, oldv: olddata }, + chan, + ); + } +}; diff --git a/src/handler/FormatDate.js b/src/handler/FormatDate.js new file mode 100644 index 000000000..dec00f4b3 --- /dev/null +++ b/src/handler/FormatDate.js @@ -0,0 +1,413 @@ +function getWeekOfYear(dateMSOrString, Timezone) { + const date = new Date(dateMSOrString); + date.setDate(date.getDate() + 4 - (date.getDay() || 7)); + + const yearStart = new Date( + new Date(Date.UTC(date.getFullYear(), 0, 1)).toLocaleString("en-us", { + timeZone: Timezone, + }), + ); + + const weekNumber = Math.ceil(((date - yearStart) / 86400000 + 1) / 7); + + return [date.getFullYear(), weekNumber]; +} + +function getQuarterOfMonth(dateMSOrString) { + const date = new Date(dateMSOrString); + return Math.trunc((date.getMonth() + 1) / 4); +} + +module.exports = (format, date, timezone) => { + const aNewDate = new Date(new Date(date).toLocaleString('en-us',{timeZone: timezone})); + switch (format) { + // Months of Year + case "M": { + format = aNewDate.getMonth() + 1; + } + break; + case "MM": { + format = aNewDate.getMonth() + 1; + } + break; + case "MMM": { + format = [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", + ][aNewDate.getMonth()]; + } + break; + case "MMMM": { + format = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ][aNewDate.getMonth()]; + } + break; + // Date of Month + case "D": { + format = aNewDate.getDate(); + } + break; + case "DD": { + format = aNewDate.getDate(); + } + break; + // with Ordinal + case "Do": { + const month = aNewDate.getDate(); + if ( + month.toString().endsWith("1") && + !month.toString().endsWith("11") + ) { + format = month.toString() + "st"; + } else if ( + month.toString().endsWith("2") && + !month.toString().endsWith("12") + ) { + format = month.toString() + "nd"; + } else if ( + month.toString().endsWith("3") && + !month.toString().endsWith("13") + ) { + format = month.toString() + "rd"; + } else { + format = month.toString() + "th"; + } + } + break; + // With Abbrev and Full + case "ddd": { + format = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][ + aNewDate.getDay() + ]; + } + break; + case "dddd": { + format = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ][aNewDate.getDay()]; + } + break; + // Day of Year + case "DDD": { + const aDay = 1000 * 3600 * 24; + const nowDate = aNewDate; + const firstDate = new Date( + new Date(Date.UTC(nowDate.getFullYear(), 0, 0)).toLocaleString( + "en-US", + {timeZone: timezone}, + ), + ); + + const difference = + nowDate - + firstDate - + (firstDate.getTimezoneOffset() - nowDate.getTimezoneOffset()) * + 60 * + 1000; + + format = Math.floor(difference / aDay); + } + break; + case "DDDD": { + const aDay = 1000 * 3600 * 24; + const nowDate = aNewDate; + const firstDate = new Date( + new Date(Date.UTC(nowDate.getFullYear(), 0, 0)).toLocaleString( + "en-US", + {timeZone: timezone}, + ), + ); + + const difference = + nowDate - + firstDate - + (firstDate.getTimezoneOffset() - nowDate.getTimezoneOffset()) * + 60 * + 1000; + + format = Math.floor(difference / aDay); + } + break; + // Unix Timestamp + //in MS + case "x": { + format = aNewDate.getTime(); + } + break; + //in Seconds + case "X": { + format = aNewDate.getTime() / 1000; + } + break; + // Year + // 4 digits + case "YYYY": { + format = aNewDate.getFullYear(); + } + break; + // 2 digits + case "YY": { + format = aNewDate.getFullYear().toString().split("").splice(2).join(""); + } + break; + // Quarter of Year + case "Q": { + format = getQuarterOfMonth(date); + } + break; + + // Week Locales and ISO + case "gg": { + format = aNewDate.getFullYear().toString().split("").splice(2).join(""); + } + break; + case "gggg": { + format = aNewDate.getFullYear(); + } + break; + case "w": { + format = getWeekOfYear(aNewDate, timezone); + } + break; + case "ww": { + format = getWeekOfYear(aNewDate, timezone); + } + break; + case "e": { + format = aNewDate.getDay(); + } + break; + case "GG": { + format = new Date(aNewDate.toISOString()) + .getFullYear() + .toString() + .split("") + .splice(2) + .join(""); + } + break; + case "GGGG": { + format = new Date(aNewDate.toISOString()).getFullYear(); + } + break; + case "W": { + format = getWeekOfYear(new Date(aNewDate.toISOString()), timezone); + } + break; + case "WW": { + format = getWeekOfYear(new Date(aNewDate.toISOString()), timezone); + } + break; + case "E": { + format = new Date(aNewDate.toISOString()).getDay(); + } + break; + + // Locale Aware Functions + case "L": { + format = aNewDate + .toLocaleString("en-US", {timeZone: timezone}) + .split(", ")[0]; + } + break; + case "LL": { + const clonedDate = aNewDate; + format = `${ + [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ][clonedDate.getMonth()] + } ${clonedDate.getDate()} ${clonedDate.getFullYear()}`; + } + break; + case "LLL": { + const clonedDate = aNewDate; + format = `${ + [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ][clonedDate.getMonth()] + } ${clonedDate.getDate()} ${clonedDate.getFullYear()} ${ + clonedDate.getHours() > 12 + ? clonedDate.getHours() - 12 + : clonedDate.getHours() + }:${ + clonedDate.getMinutes().toString().length === 2 + ? clonedDate.getMinutes() + : "0" + clonedDate.getMinutes().toString() + } ${clonedDate.getHours() > 12 ? "PM" : "AM"}`; + } + break; + case "LLLL": { + const clonedDate = aNewDate; + format = `${ + [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ][clonedDate.getDay()] + }, ${ + [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ][clonedDate.getMonth()] + } ${clonedDate.getDate()} ${clonedDate.getFullYear()} ${ + clonedDate.getHours() > 12 + ? clonedDate.getHours() - 12 + : clonedDate.getHours() + }:${ + clonedDate.getMinutes().toString().length === 2 + ? clonedDate.getMinutes() + : "0" + clonedDate.getMinutes().toString() + } ${clonedDate.getHours() > 12 ? "PM" : "AM"}`; + } + break; + case "LT": { + const clonedDate = aNewDate; + const isPM = clonedDate.getHours() > 12; + format = `${ + isPM ? clonedDate.getHours() - 12 : clonedDate.getHours() + }:${ + clonedDate.getMinutes().toString().length === 2 + ? clonedDate.getMinutes() + : "0" + clonedDate.getMinutes().toString() + } ${isPM ? "PM" : "AM"}`; + } + break; + case "LTS": { + const clonedDate = aNewDate; + const isPM = clonedDate.getHours() > 12; + format = `${ + isPM ? clonedDate.getHours() - 12 : clonedDate.getHours() + }:${ + clonedDate.getMinutes().toString().length === 2 + ? clonedDate.getMinutes() + : "0" + clonedDate.getMinutes().toString() + }:${ + clonedDate.getSeconds().toString().length === 2 + ? clonedDate.getSeconds() + : "0" + clonedDate.getSeconds().toString() + } ${isPM ? "PM" : "AM"}`; + } + break; + + // Hours, mins,seconds, offset + //24 Hours Format + case "H": { + format = aNewDate.getHours(); + } + break; + case "HH": { + format = aNewDate.getHours(); + } + break; + //12 Hours Format + case "h": { + const newDate = aNewDate; + format = + newDate.getHours() > 12 + ? newDate.getHours() - 12 + : newDate.getHours(); + } + break; + case "hh": { + const newDate = aNewDate; + format = + newDate.getHours() > 12 + ? newDate.getHours() - 12 + : newDate.getHours(); + } + break; + case "a": { + format = aNewDate.getHours() > 12 ? "PM" : "AM"; + } + break; + case "A": { + format = aNewDate.getHours() > 12 ? "PM" : "AM"; + } + break; + case "m": { + format = aNewDate.getMinutes(); + } + break; + case "mm": { + format = aNewDate.getMinutes(); + } + break; + case "s": { + format = aNewDate.getSeconds(); + } + break; + case "ss": { + format = aNewDate.getSeconds(); + } + break; + case "ms": { + format = aNewDate.getMilliseconds(); + } + break; + } + return format; +}; \ No newline at end of file diff --git a/src/handler/GuildBans/add.js b/src/handler/GuildBans/add.js new file mode 100644 index 000000000..c3536ff07 --- /dev/null +++ b/src/handler/GuildBans/add.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (ban, client) => { + const cmds = client.cmd.banAdd.allValues(); + const data = { guild: ban.guild, author: ban?.user, client: client }; + + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { banData: ban }, + chan, + ); + } +}; diff --git a/src/handler/GuildBans/remove.js b/src/handler/GuildBans/remove.js new file mode 100644 index 000000000..81b5cee93 --- /dev/null +++ b/src/handler/GuildBans/remove.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (ban, client) => { + const cmds = client.cmd.banRemove.allValues(); + const data = { guild: ban.guild, author: ban?.user, client: client }; + + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { banData: ban }, + chan, + ); + } +}; diff --git a/src/handler/GuildEmojis/create.js b/src/handler/GuildEmojis/create.js new file mode 100644 index 000000000..c222b96c7 --- /dev/null +++ b/src/handler/GuildEmojis/create.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (newe, client) => { + const cmds = client.cmd.emojiCreate.allValues(); + + const data = { guild: newe.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newe: newe }, + chan, + ); + } +}; diff --git a/src/handler/GuildEmojis/delete.js b/src/handler/GuildEmojis/delete.js new file mode 100644 index 000000000..9b37a02a5 --- /dev/null +++ b/src/handler/GuildEmojis/delete.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (olde, client) => { + const cmds = client.cmd.emojiDelete.allValues(); + + const data = { guild: olde.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { olde: olde }, + chan, + ); + } +}; diff --git a/src/handler/GuildEmojis/stickerCreate.js b/src/handler/GuildEmojis/stickerCreate.js new file mode 100644 index 000000000..13bbb6900 --- /dev/null +++ b/src/handler/GuildEmojis/stickerCreate.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (newe, client) => { + const cmds = client.cmd.stickerCreate.allValues(); + + const data = { guild: newe.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { news: newe }, + chan, + ); + } +}; diff --git a/src/handler/GuildEmojis/stickerDelete.js b/src/handler/GuildEmojis/stickerDelete.js new file mode 100644 index 000000000..6f3a4772e --- /dev/null +++ b/src/handler/GuildEmojis/stickerDelete.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (olde, client) => { + const cmds = client.cmd.stickerDelete.allValues(); + + const data = { guild: olde.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { olds: olde }, + chan, + ); + } +}; diff --git a/src/handler/GuildEmojis/stickerUpdate.js b/src/handler/GuildEmojis/stickerUpdate.js new file mode 100644 index 000000000..791407b6e --- /dev/null +++ b/src/handler/GuildEmojis/stickerUpdate.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (olde, newe, client) => { + const cmds = client.cmd.stickerUpdate.allValues(); + + const data = { guild: newe.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { olds: olde, news: newe }, + chan, + ); + } +}; diff --git a/src/handler/GuildEmojis/update.js b/src/handler/GuildEmojis/update.js new file mode 100644 index 000000000..bb06ca601 --- /dev/null +++ b/src/handler/GuildEmojis/update.js @@ -0,0 +1,35 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (olde, newe, client) => { + const cmds = client.cmd.emojiUpdate.allValues(); + + const data = { guild: newe.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { olde: olde, newe: newe }, + chan, + ); + } +}; diff --git a/src/handler/GuildInvites/inviteCreate.js b/src/handler/GuildInvites/inviteCreate.js new file mode 100644 index 000000000..09cbc7dd2 --- /dev/null +++ b/src/handler/GuildInvites/inviteCreate.js @@ -0,0 +1,42 @@ +const Interpreter = require("../../core/interpreter.js"); + +module.exports = async (invite, client) => { + const cmds = client.cmd.inviteCreate.allValues(); + for (const cmd of cmds) { + let chan; + const data = { + guild: invite.guild, + client: client, + inviteData: invite, + author: invite.inviter + }; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true + ); + const channel = client.channels.cache.get(id?.code); + chan = channel ?? undefined; + data.channel = chan; + } else { + const channel = client.channels.cache.get(cmd.channel); + chan = channel ?? undefined; + data.channel = channel; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id || "", + { inviteData: invite }, + chan || undefined + ); + } +}; diff --git a/src/handler/GuildInvites/inviteDelete.js b/src/handler/GuildInvites/inviteDelete.js new file mode 100644 index 000000000..9fc5cfce4 --- /dev/null +++ b/src/handler/GuildInvites/inviteDelete.js @@ -0,0 +1,43 @@ +const Interpreter = require("../../core/interpreter.js"); + +module.exports = async (invite, client) => { + const cmds = client.cmd.inviteDelete.allValues(); + for (const cmd of cmds) { + let chan; + const data = { + guild: invite.guild, + client: client, + inviteData: invite, + author: invite.inviter ?? { + id: invite.inviterId + } + }; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true + ); + const channel = client.channels.cache.get(id?.code); + chan = channel ?? undefined; + } else { + const channel = client.channels.cache.get(cmd.channel); + chan = channel ?? undefined; + data.channel = channel; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id || "", + { inviteData: invite }, + chan || undefined + ); + } +}; diff --git a/src/handler/GuildMembers/available.js b/src/handler/GuildMembers/available.js new file mode 100644 index 000000000..285999c04 --- /dev/null +++ b/src/handler/GuildMembers/available.js @@ -0,0 +1,39 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (mem, client) => { + let chan; + const cmds = client.cmd.memberAvailable.allValues(); + let data = { + guild: mem.guild, + author: mem.user, + member: mem, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newm: mem }, + chan, + ); + } +}; diff --git a/src/handler/GuildMembers/chunk.js b/src/handler/GuildMembers/chunk.js new file mode 100644 index 000000000..06a277642 --- /dev/null +++ b/src/handler/GuildMembers/chunk.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (mem, guild, chunk, client) => { + let chan; + const cmds = client.cmd.membersChuck.allValues(); + let data = { guild: guild, channel: undefined, client: client }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { membersChuck: { members: mem, guild: guild, chunk: chunk } }, + chan, + ); + } +}; diff --git a/src/handler/GuildMembers/join.js b/src/handler/GuildMembers/join.js new file mode 100644 index 000000000..5433a8e59 --- /dev/null +++ b/src/handler/GuildMembers/join.js @@ -0,0 +1,39 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (mem, client) => { + let chan; + const cmds = client.cmd.join.allValues(); + let data = { + guild: mem.guild, + author: mem.user, + member: mem, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newm: mem }, + chan, + ); + } +}; diff --git a/src/handler/GuildMembers/leave.js b/src/handler/GuildMembers/leave.js new file mode 100644 index 000000000..3845b0304 --- /dev/null +++ b/src/handler/GuildMembers/leave.js @@ -0,0 +1,39 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (mem, client) => { + let chan; + const cmds = client.cmd.leave.allValues(); + let data = { + guild: mem?.guild, + author: mem?.user, + member: mem, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newm: mem }, + chan, + ); + } +}; diff --git a/src/handler/GuildMembers/update.js b/src/handler/GuildMembers/update.js new file mode 100644 index 000000000..222d751aa --- /dev/null +++ b/src/handler/GuildMembers/update.js @@ -0,0 +1,39 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldm, newm, client) => { + let chan; + const cmds = client.cmd.memberUpdate.allValues(); + let data = { + guild: newm?.guild, + author: newm?.user, + member: newm, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newm: newm, oldm: oldm }, + chan, + ); + } +}; diff --git a/src/handler/GuildMessageReactions/add.js b/src/handler/GuildMessageReactions/add.js new file mode 100644 index 000000000..88160c4f6 --- /dev/null +++ b/src/handler/GuildMessageReactions/add.js @@ -0,0 +1,44 @@ +const { MessageReaction, User } = require("discord.js"); +const Interpreter = require("../../core/interpreter.js"); +/** + * @param {MessageReaction} reaction + * @param {User} user + * @param {import('../../classes/AoiClient.js')} client + */ +module.exports = async (reaction, user, client) => { + const cmds = client.cmd.reactionAdd.allValues(); + const data = { + message: reaction.message, + channel: reaction.message.channel, + client: client, + guild: reaction.message.guild, + author: user, + }; + for (const cmd of cmds) { + let chan; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels?.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { reactionData: reaction }, + chan, + ); + } +}; diff --git a/src/handler/GuildMessageReactions/remove.js b/src/handler/GuildMessageReactions/remove.js new file mode 100644 index 000000000..0fd38a6f7 --- /dev/null +++ b/src/handler/GuildMessageReactions/remove.js @@ -0,0 +1,44 @@ +const Interpreter = require("../../core/interpreter.js"); +const { MessageReaction } = require("discord.js"); +/** + * @param {MessageReaction} reaction + * @param {User} user + * @param {import('../../classes/AoiClient.js')} client + */ +module.exports = async (reaction, user, client) => { + const cmds = client.cmd.reactionRemove.allValues(); + const data = { + message: reaction.message, + channel: reaction.message.channel, + client: client, + guild: reaction.message.guild, + author: user, + }; + for (const cmd of cmds) { + let chan; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels?.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { reactionData: reaction }, + chan, + ); + } +}; diff --git a/src/handler/GuildMessageReactions/removeAll.js b/src/handler/GuildMessageReactions/removeAll.js new file mode 100644 index 000000000..122405fd6 --- /dev/null +++ b/src/handler/GuildMessageReactions/removeAll.js @@ -0,0 +1,43 @@ +const Interpreter = require("../../core/interpreter.js"); +const { Message } = require("discord.js"); +/** + * @param {Message} reactionMessage + * @param {import('../../classes/AoiClient.js')} client + */ +module.exports = async (reactionMessage, client) => { + const cmds = client.cmd.reactionRemoveAll.allValues(); + const data = { + client: client, + guild: reactionMessage.guild, + author: reactionMessage.author, + channel: reactionMessage.channel, + member: reactionMessage.member, + }; + for (const cmd of cmds) { + let chan; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels?.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + {}, + chan, + ); + } +}; diff --git a/src/handler/GuildMessageReactions/removeEmoji.js b/src/handler/GuildMessageReactions/removeEmoji.js new file mode 100644 index 000000000..3c0829788 --- /dev/null +++ b/src/handler/GuildMessageReactions/removeEmoji.js @@ -0,0 +1,43 @@ +const Interpreter = require("../../core/interpreter.js"); +const { MessageReaction } = require("discord.js"); +/** + * @param {MessageReaction} reaction + * @param {User} user + * @param {import('../../classes/AoiClient.js')} client + */ +module.exports = async (reaction, client) => { + const cmds = client.cmd.reactionRemoveEmoji.allValues(); + const data = { + message: reaction.message, + channel: reaction.message.channel, + client: client, + guild: reaction.message.guild, + }; + for (const cmd of cmds) { + let chan; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels?.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { reactionData: reaction }, + chan, + ); + } +}; diff --git a/src/handler/GuildMessageTypings/start.js b/src/handler/GuildMessageTypings/start.js new file mode 100644 index 000000000..e34053e09 --- /dev/null +++ b/src/handler/GuildMessageTypings/start.js @@ -0,0 +1,38 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (typing, client) => { + const cmds = client.cmd.typingStart.allValues(); + let chan; + let data = { + guild: typing.guild, + client: client, + author: typing.user, + channel: typing.channel, + member: typing.member, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { typing: typing }, + chan, + ); + } +}; diff --git a/src/handler/GuildMessages/alwaysExecute.js b/src/handler/GuildMessages/alwaysExecute.js new file mode 100644 index 000000000..6082be87f --- /dev/null +++ b/src/handler/GuildMessages/alwaysExecute.js @@ -0,0 +1,28 @@ +const Interpreter = require("../../core/interpreter.js"); +const Util = require("../../classes/Util.js"); +module.exports = async ( message,client, db) => { + if (client.aoiOptions) { + const options = client.aoiOptions; + if ( + (!options.respondToBots && + (message.webhookId || message.author.bot)) || + (options.guildOnly && message.channel.type === Util.channelTypes.DM) + ) + return; + } + const commands = client.cmd.default + .allValues() + .filter((c) => c.name === "$alwaysExecute"); + if (!commands.length) return; + commands.map(async (command) => { + if (command.dmOnly && message.channel.type !== Util.channelTypes.DM) + return; + await Interpreter( + client, + message, + message.content.split(" "), + command, + db, + ); + }); +}; diff --git a/src/handler/GuildMessages/bulkDeleteMessage.js b/src/handler/GuildMessages/bulkDeleteMessage.js new file mode 100644 index 000000000..107309270 --- /dev/null +++ b/src/handler/GuildMessages/bulkDeleteMessage.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (dmsg, dchannel, client) => { + const d = { + guild: dchannel.guild, + channel: dchannel, + client: dmsg.client, + }; + let chan; + for (const cmd of client.cmd.messageDeleteBulk.allValues()) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + {}, + [], + { command: "channelParser", code: cmd.channel }, + client.db, + true, + ); + let channel = client.channels.cache.get(id?.code); + if (!channel) channel = dchannel; + chan = channel; + } else { + chan = cmd.channel; + } + await Interpreter( + client, + d, + [], + cmd, + client.db, + false, + undefined, + { bulk: dmsg }, + chan, + ); + } +}; diff --git a/src/handler/GuildMessages/commands.js b/src/handler/GuildMessages/commands.js new file mode 100644 index 000000000..bdc812ba4 --- /dev/null +++ b/src/handler/GuildMessages/commands.js @@ -0,0 +1,142 @@ +const Interpreter = require("../../core/interpreter.js"); +const Util = require("../../classes/Util.js"); +module.exports = async (message, client) => { + if (client.aoiOptions) { + const options = client.aoiOptions; + + if ( + (!options.respondToBots && + (message.webhookId || message.author.bot)) || + (options.guildOnly && message.channel.type === Util.channelTypes.DM) + ) + return; + } + //array of cmds + let cmds = client.cmd.default + .allValues() + .filter((x) => !x.nonPrefixed && x.name !== "$alwaysExecute"); + //getting arrays of prefixes + const prefixes = Array.isArray(client.prefix) + ? client.prefix.map(async (x) => + x.includes("$") + ? ( + await Interpreter( + client, + message, + message.content.split(" "), + { name: "PrefixParser", code: x }, + client.db, + true, + ) + )?.code?.addBrackets() + : x, + ) + : client.prefix.includes("$") + ? [ + ( + await Interpreter( + client, + message, + message.content.split(" "), + { code: client.prefix }, + client.db, + true, + ) + )?.code?.addBrackets(), + ] + : [ client.prefix ]; + //for loop of prefix array + for (let prefix of prefixes) { + prefix = await prefix; + if (!message.content.toLowerCase().startsWith(prefix.toLowerCase())) + continue; + //getting message + const msg = message.content.slice(prefix.length).trim(); + //finding command + const cmd = cmds + .filter( + ( x ) => + { + return ( msg.toLowerCase().startsWith( x.name.toLowerCase() ) && + msg + .split( " " ) + .slice( 0, x.name.split( " " ).length ) + .join( " " ) + .toLowerCase() === x.name.toLowerCase() ) || + ( Array.isArray( x.aliases ) + ? x.aliases.find( + ( y ) => + msg + .toLowerCase() + .startsWith( y.toLowerCase() ) && + msg + .split( " " ) + .slice( 0, y.split( " " ).length ) + .join( " " ) + .toLowerCase() === y.toLowerCase(), + ) + : msg + ?.toLowerCase() + .startsWith( x.aliases?.toLowerCase() ) && + msg + .split( " " ) + .slice( 0, x.aliases?.split( " " ).length ) + .join( " " ) + ?.toLowerCase() === x.aliases?.toLowerCase() ); + } ) + ?.sort((a, b) => a.name.length - b.name.length) + .reverse()[0]; + if (!cmd) break; + const cmdName = + msg.toLowerCase().startsWith(cmd.name.toLowerCase()) && + msg + .toLowerCase() + .split(" ") + .slice(0, cmd.name.split(" ").length) + .join(" ") === cmd.name.toLowerCase() + ? cmd.name + : (Array.isArray(cmd.aliases) + ? cmd.aliases.find( + (x) => + msg.toLowerCase().startsWith(x.toLowerCase()) && + msg + .toLowerCase() + .split(" ") + .slice(0, x.split(" ").length) + .join(" ") === x.toLowerCase(), + ) + : msg + .toLowerCase() + .split(" ") + .slice(0, cmd.aliases.split(" ").length) + .join(" ") === cmd.aliases.toLowerCase()) || + cmd.aliases; + //args + const args = msg + .slice(cmdName?.length || "") + .split(" ") + .slice(1); + + //if command doesn't exist , then break the loop + if (!cmd.executeAt) cmd.executeAt = "guild"; + if ( + cmd.executeAt === "guild" && + message.channel.type === Util.channelTypes.DM + ) + break; + else if ( + cmd.executeAt === "dm" && + message.channel.type !== Util.channelTypes.DM + ) + break; + //if cmd.async is true + if (cmd.async) { + await Interpreter(client, message, args, cmd, client.db); + } + //non async execution + else { + Interpreter(client, message, args, cmd, client.db); + } + break; + } +}; diff --git a/src/handler/GuildMessages/deleteMessage.js b/src/handler/GuildMessages/deleteMessage.js new file mode 100644 index 000000000..74291b793 --- /dev/null +++ b/src/handler/GuildMessages/deleteMessage.js @@ -0,0 +1,40 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (dmsg, client) => { + const data = Object.assign({}, dmsg); + data.channel = dmsg.channel; + data.guild = dmsg.guild; + data.content = dmsg.content; + let chan; + + if (!data.partial && client.user.id === data?.author?.id) return; + for (const cmd of client.cmd.messageDelete.allValues()) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { command: "channelParser", code: cmd.channel }, + client.db, + true, + ); + let channel = client.channels.cache.get(id?.code); + if (!channel) channel = dmsg.channel; + chan = channel; + } else { + data.channel = + client.channels.cache.get(cmd.channel) || dmsg.channel; + } + if (!data.guild) data.guild = dmsg.guild || dmsg.channel?.guild; + await Interpreter( + client, + data, + data?.content?.split(" ") || [], + cmd, + client.db, + false, + dmsg.channel?.id, + { oldm: dmsg }, + chan, + ); + } +}; diff --git a/src/handler/GuildMessages/nonPrefixed.js b/src/handler/GuildMessages/nonPrefixed.js new file mode 100644 index 000000000..7acce0280 --- /dev/null +++ b/src/handler/GuildMessages/nonPrefixed.js @@ -0,0 +1,51 @@ +const Interpreter = require("../../core/interpreter.js"); +const Util = require("../../classes/Util.js"); +module.exports = async ( message,client) => { + if (client.aoiOptions) { + const options = client.aoiOptions; + if ( + (!options.respondToBots && + (message.webhookId || message.author.bot)) || + (options.guildOnly && message.channel.type === Util.channelTypes.DM) + ) + return; + } + const commands = client.cmd.default + .allValues() + .filter((c) => c.nonPrefixed); + if (!commands.length) return; + for (const cmd of commands) { + if (cmd.dmOnly && message.channel.type !== Util.channelTypes.DM) + continue; + if (cmd.name.includes("$")) { + cmd.name = ( + await Interpreter( + client, + message, + message.content.split(" "), + { name: "NameParser", code: cmd.name }, + client.db, + true, + ) + )?.code; + } + if ( + !message.content.toLowerCase().startsWith(cmd.name.toLowerCase()) && + !(Array.isArray(cmd.aliases) + ? cmd.aliases.find((x) => + message.content.toLowerCase().startsWith(x.toLowerCase()), + ) + : cmd.aliases + ? message.content.toLowerCase().startsWith(cmd.aliases) + : undefined) + ) + continue; + await Interpreter( + client, + message, + message.content.split(" "), + cmd, + client.db, + ); + } +}; diff --git a/src/handler/GuildMessages/oldCommands.js b/src/handler/GuildMessages/oldCommands.js new file mode 100644 index 000000000..ee5a1bac3 --- /dev/null +++ b/src/handler/GuildMessages/oldCommands.js @@ -0,0 +1,53 @@ +const Interpreter = require("../../core/interpreter.js"); + +const CommandHandler = async (client, message, db) => { + if (!message) return; + if ( + message?.channel?.type === "dm" && + client.aoiOptions.guildOnly === false + ) + return; + if (message.author?.bot && client.aoiOptions.respondToBots === false) + return; + const prefixes = []; + for (const prefix of client.prefix) { + if (prefix.startsWith("$")) { + prefixes.push( + await Interpreter( + client, + message, + message.content.split(" "), + {name: "prefix", code: prefix}, + client.db, + true, + ), + ); + } else { + prefixes.push(prefix); + } + } + for (const prefix of prefixes) { + const args = message.content.slice(prefix.length).trim().split(" "); + const cmdName = args.shift().toLowerCase(); + if (message.content.toLowerCase().startsWith(prefix.toLowerCase())) { + const cmd = client.cmd.default + .filter( + (x) => + x.name?.toLowerCase() === cmdName || + (Array.isArray(x.aliases) + ? x.aliases?.find((x) => x.toLowerCase() === cmdName) + : x.aliases?.toLowerCase() === cmdName), + ) + .allValues(); + for (const command of cmd) { + if (command.asynchronous === true) { + await Interpreter(client, message, args, command); + } else { + Interpreter(client, message, args, command); + } + } + } + } +}; + +module.exports = CommandHandler; diff --git a/src/handler/GuildMessages/updateMessage.js b/src/handler/GuildMessages/updateMessage.js new file mode 100644 index 000000000..fa5c83159 --- /dev/null +++ b/src/handler/GuildMessages/updateMessage.js @@ -0,0 +1,64 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldm, newm, client) => { + let chan; + + for (const cmd of client.cmd.messageUpdate.allValues()) { + const id = cmd.channel.includes("$") + ? ( + await Interpreter( + client, + newm, + [], + { name: "channelParser", code: cmd.channel }, + client.db, + true, + ) + )?.code + : cmd.channel; + + let channel = client.channels.cache.get(id); + if (!channel) channel = newm.channel; + chan = channel; + await Interpreter( + client, + newm, + newm?.content?.split(" "), + cmd, + client.db, + false, + chan?.id, + { oldm: oldm }, + chan, + ); + } + + + if ( + client.aoiOptions.respondOnEdit && + newm.content !== oldm.content && + client.aoiOptions.respondOnEdit.time > + Date.now() - newm.createdTimestamp + ) { + if (client.aoiOptions.respondOnEdit.commands) { + await require("./commands.js")( + newm, + client, + client.db, + ); + } + if (client.aoiOptions.respondOnEdit.alwaysExecute) { + await require("./alwaysExecute.js")( + client, + newm, + client.db, + ); + } + if (client.aoiOptions.respondOnEdit.nonPrefixed) { + await require("./nonPrefixed.js")( + client, + newm, + client.db, + ); + } + } +}; diff --git a/src/handler/GuildPresences/update.js b/src/handler/GuildPresences/update.js new file mode 100644 index 000000000..c7ffb31d1 --- /dev/null +++ b/src/handler/GuildPresences/update.js @@ -0,0 +1,40 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (op, np, client) => { + const cmds = client.cmd.presenceUpdate.allValues(); + for (const cmd of cmds) { + let chan; + const data = { + guild: np.guild, + client: client, + author: np.user, + member: np.member, + }; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + const channel = client.channels.cache.get(id?.code); + chan = channel ?? undefined; + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id || "", + { oldPresence: op, newPresence: np }, + chan || undefined, + ); + } +}; diff --git a/src/handler/GuildVoiceStates/update.js b/src/handler/GuildVoiceStates/update.js new file mode 100644 index 000000000..0dcc49d8d --- /dev/null +++ b/src/handler/GuildVoiceStates/update.js @@ -0,0 +1,40 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (os, ns, client) => { + const cmds = client.cmd.voiceStateUpdate.allValues(); + for (const cmd of cmds) { + let chan; + const data = { + guild: os.guild, + client: client, + author: ns.member.user, + member: ns.member, + }; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + const channel = client.channels.cache.get(id?.code); + chan = channel ?? undefined; + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id || "", + { oldVoiceState: os, newVoiceState: ns }, + chan || undefined, + ); + } +}; diff --git a/src/handler/GuildWebhooks/update.js b/src/handler/GuildWebhooks/update.js new file mode 100644 index 000000000..80508769b --- /dev/null +++ b/src/handler/GuildWebhooks/update.js @@ -0,0 +1,44 @@ +const { TextChannel, NewsChannel } = require("discord.js"); +const Interpreter = require("../../core/interpreter.js"); +/** + * @param os + * @param ns + * @param {TextChannel | NewsChannel } channelData + * @param {import('../../classes/AoiClient.js')} client + */ +module.exports = async (os, ns, channelData, client) => { + const cmds = client.cmd.webhooksUpdate.allValues(); + for (const cmd of cmds) { + let chan; + const data = { + guild: channelData.guild, + client: client, + channel: channelData, + }; + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + const channel = client.channels.cache.get(id?.code); + chan = channel ?? undefined; + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id || "", + { oldVoiceState: os, newVoiceState: ns }, + chan || undefined, + ); + } +}; diff --git a/src/handler/Guilds/channelCreate.js b/src/handler/Guilds/channelCreate.js new file mode 100644 index 000000000..324257446 --- /dev/null +++ b/src/handler/Guilds/channelCreate.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (newc, client) => { + const cmds = client.cmd.channelCreate.allValues(); + const data = { guild: newc.guild, channel: newc, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newc: newc }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/channelDelete.js b/src/handler/Guilds/channelDelete.js new file mode 100644 index 000000000..bffc06571 --- /dev/null +++ b/src/handler/Guilds/channelDelete.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldc, client) => { + const cmds = client.cmd.channelDelete.allValues(); + const data = { guild: oldc.guild, channel: oldc, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldc: oldc }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/channelPinsUpdate.js b/src/handler/Guilds/channelPinsUpdate.js new file mode 100644 index 000000000..fdfb12376 --- /dev/null +++ b/src/handler/Guilds/channelPinsUpdate.js @@ -0,0 +1,36 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (updatedPinsChannel, time, client) => { + const cmds = client.cmd.channelPinsUpdate.allValues(); + const data = { + guild: updatedPinsChannel.guild, + channel: updatedPinsChannel, + client: client, + }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { channel: updatedPinsChannel, time: time }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/channelUpdate.js b/src/handler/Guilds/channelUpdate.js new file mode 100644 index 000000000..b4438ce83 --- /dev/null +++ b/src/handler/Guilds/channelUpdate.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldc, newc, client) => { + const cmds = client.cmd.channelUpdate.allValues(); + const data = { guild: newc.guild, channel: newc, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldc: oldc, newc: newc }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/guildJoin.js b/src/handler/Guilds/guildJoin.js new file mode 100644 index 000000000..a090d6b65 --- /dev/null +++ b/src/handler/Guilds/guildJoin.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (guild, client) => { + const cmds = client.cmd.guildJoin.allValues(); + const data = { guild: guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newg: guild }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/guildLeave.js b/src/handler/Guilds/guildLeave.js new file mode 100644 index 000000000..ff9dcc704 --- /dev/null +++ b/src/handler/Guilds/guildLeave.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (guild, client) => { + const cmds = client.cmd.guildLeave.allValues(); + const data = { guild: guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + {}, + chan, + ); + } +}; diff --git a/src/handler/Guilds/guildUnavailable.js b/src/handler/Guilds/guildUnavailable.js new file mode 100644 index 000000000..22b57d620 --- /dev/null +++ b/src/handler/Guilds/guildUnavailable.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (guild, client) => { + let chan; + const cmds = client.cmd.guildLeave.allValues(); + const data = { guild: guild, client: client }; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + {}, + chan, + ); + } +}; diff --git a/src/handler/Guilds/guildUpdate.js b/src/handler/Guilds/guildUpdate.js new file mode 100644 index 000000000..73e3da82d --- /dev/null +++ b/src/handler/Guilds/guildUpdate.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldg, newg, client) => { + let chan; + const cmds = client.cmd.guildUpdate.allValues(); + const data = { guild: newg, client: client }; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldg: oldg, newg: newg }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/roleCreate.js b/src/handler/Guilds/roleCreate.js new file mode 100644 index 000000000..7cdde768a --- /dev/null +++ b/src/handler/Guilds/roleCreate.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (role, client) => { + const cmds = client.cmd.roleCreate.allValues(); + const data = { guild: role.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newr: role }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/roleDelete.js b/src/handler/Guilds/roleDelete.js new file mode 100644 index 000000000..dcddcb89e --- /dev/null +++ b/src/handler/Guilds/roleDelete.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (role, client) => { + const cmds = client.cmd.roleDelete.allValues(); + const data = { guild: role.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldr: role }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/roleUpdate.js b/src/handler/Guilds/roleUpdate.js new file mode 100644 index 000000000..bdd7212ab --- /dev/null +++ b/src/handler/Guilds/roleUpdate.js @@ -0,0 +1,34 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldr, newr, client) => { + const cmds = client.cmd.roleUpdate.allValues(); + const data = { guild: newr.guild, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newr: newr, oldr: oldr }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/stageInstanceCreate.js b/src/handler/Guilds/stageInstanceCreate.js new file mode 100644 index 000000000..ad9b6286e --- /dev/null +++ b/src/handler/Guilds/stageInstanceCreate.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (stageint, client) => { + const cmds = client.cmd.stageInstanceCreate.allValues(); + const data = { guild: stageint.guild, channel: stageint, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newStageInstance: stageint }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/stageInstanceDelete.js b/src/handler/Guilds/stageInstanceDelete.js new file mode 100644 index 000000000..1b4f9472c --- /dev/null +++ b/src/handler/Guilds/stageInstanceDelete.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (stageint, client) => { + const cmds = client.cmd.stageInstanceDelete.allValues(); + const data = { guild: stageint.guild, channel: stageint, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldc: stageint }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/stageInstanceUpdate.js b/src/handler/Guilds/stageInstanceUpdate.js new file mode 100644 index 000000000..ce555e4d4 --- /dev/null +++ b/src/handler/Guilds/stageInstanceUpdate.js @@ -0,0 +1,36 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldstageint, newstageint, client) => { + const cmds = client.cmd.stageInstanceUpdate.allValues(); + const data = { + guild: newstageint.guild, + channel: newstageint.channel, + client: client, + }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldStageInstance: oldstageint, newStageInstance: newstageint }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/threadCreate.js b/src/handler/Guilds/threadCreate.js new file mode 100644 index 000000000..2077516a5 --- /dev/null +++ b/src/handler/Guilds/threadCreate.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (thread, newc, client) => { + const cmds = client.cmd.threadCreate.allValues(); + const data = { guild: thread.guild, channel: thread, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newc: thread }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/threadDelete.js b/src/handler/Guilds/threadDelete.js new file mode 100644 index 000000000..a2d7996bc --- /dev/null +++ b/src/handler/Guilds/threadDelete.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (thread, client) => { + const cmds = client.cmd.threadDelete.allValues(); + const data = { guild: thread.guild, channel: thread, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldc: thread }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/threadListSync.js b/src/handler/Guilds/threadListSync.js new file mode 100644 index 000000000..53ea80214 --- /dev/null +++ b/src/handler/Guilds/threadListSync.js @@ -0,0 +1,36 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (threadCollection, client) => { + const cmds = client.cmd.threadListSync.allValues(); + const data = { + guild: threadCollection.first().guild, + channel: threadCollection.first(), + client: client, + }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { threadListSync: threadCollection }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/threadMemberUpdate.js b/src/handler/Guilds/threadMemberUpdate.js new file mode 100644 index 000000000..0b2bcb030 --- /dev/null +++ b/src/handler/Guilds/threadMemberUpdate.js @@ -0,0 +1,36 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldm, newm, client) => { + const cmds = client.cmd.threadMemberUpdate.allValues(); + const data = { + guild: oldm.thread?.guild || newm.thread?.guild, + channel: oldm.thread || newm.thread, + client: client, + }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldm: oldm, newm: newm }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/threadMembersUpdate.js b/src/handler/Guilds/threadMembersUpdate.js new file mode 100644 index 000000000..1a24b0999 --- /dev/null +++ b/src/handler/Guilds/threadMembersUpdate.js @@ -0,0 +1,41 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldmCollection, newmCollection, client) => { + const cmds = client.cmd.threadMembersUpdate.allValues(); + const data = { + guild: + oldmCollection.first().thread?.guild || + newmCollection.first().thread?.guild, + channel: oldmCollection.first().thread || newmCollection.first().thread, + client: client, + }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { + oldThreadMembers: oldmCollection, + newThreadMembers: newmCollection, + }, + chan, + ); + } +}; diff --git a/src/handler/Guilds/threadUpdate.js b/src/handler/Guilds/threadUpdate.js new file mode 100644 index 000000000..169226b22 --- /dev/null +++ b/src/handler/Guilds/threadUpdate.js @@ -0,0 +1,32 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oldt, newt, client) => { + const cmds = client.cmd.threadUpdate.allValues(); + const data = { guild: newt.guild, channel: newt, client: client }; + let chan; + for (const cmd of cmds) { + if (cmd?.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd?.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + } else { + chan = client.channels.cache.get(cmd.channel); + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newc: newt, oldc: oldt }, + chan, + ); + } +}; diff --git a/src/handler/NonIntents/appCmdCreate.js b/src/handler/NonIntents/appCmdCreate.js new file mode 100644 index 000000000..fad943a14 --- /dev/null +++ b/src/handler/NonIntents/appCmdCreate.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (app, client) => { + const cmds = client.cmd.applicationCmdCreate.allValues(); + let chan; + const data = { + guild: app.guild, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newapp: app }, + chan, + ); + } +}; diff --git a/src/handler/NonIntents/appCmdDelete.js b/src/handler/NonIntents/appCmdDelete.js new file mode 100644 index 000000000..cbaf889ed --- /dev/null +++ b/src/handler/NonIntents/appCmdDelete.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (app, client) => { + const cmds = client.cmd.applicationCmdDelete.allValues(); + let chan; + const data = { + guild: app.guild, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { oldapp: app }, + chan, + ); + } +}; diff --git a/src/handler/NonIntents/appCmdPermissionsUpdate.js b/src/handler/NonIntents/appCmdPermissionsUpdate.js new file mode 100644 index 000000000..68c95e093 --- /dev/null +++ b/src/handler/NonIntents/appCmdPermissionsUpdate.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (app, client) => { + const cmds = client.cmd.applicationCmdPermissionsUpdate.allValues(); + let chan; + const data = { + guild: client.guilds.cache.get(app.guildId), + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newapp: app }, + chan, + ); + } +}; diff --git a/src/handler/NonIntents/appCmdUpdate.js b/src/handler/NonIntents/appCmdUpdate.js new file mode 100644 index 000000000..1bb6aa40e --- /dev/null +++ b/src/handler/NonIntents/appCmdUpdate.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (oa, na, client) => { + const cmds = client.cmd.applicationCmdUpdate.allValues(); + let chan; + const data = { + guild: na.guild, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { newapp: na, oldapp: oa }, + chan, + ); + } +}; diff --git a/src/handler/NonIntents/interaction.js b/src/handler/NonIntents/interaction.js new file mode 100644 index 000000000..95e67ecc8 --- /dev/null +++ b/src/handler/NonIntents/interaction.js @@ -0,0 +1,181 @@ +const { + Interaction, + ButtonInteraction, + SelectMenuInteraction, + ContextMenuCommandInteraction, + CommandInteraction, + InteractionResponseType, +} = require("discord.js"); +const Interpreter = require("../../core/interpreter.js"); +const { + InteractionTypes, + MessageComponentTypes, +} = require("../../utils/InteractionConstants.js"); +/** + * @param {Interaction | ButtonInteraction | SelectMenuInteraction | ContextMenuCommandInteraction | CommandInteraction } interaction + * @param {import('../../classes/AoiClient.js')} client + */ +module.exports = async (interaction, client) => { + client.interactionManager.resolve(interaction); + if (interaction.isMessageComponent()) { + client.interactionManager.emit( + "messageComponentInteraction", + interaction, + ); + } + + let cmds; + const type = InteractionTypes[ interaction.type ]; + + if (type === "component") { + cmds = client.cmd.interaction[ + MessageComponentTypes[interaction.componentType] + ] + .filter((x) => + x.name + ? Array.isArray(x.name) + ? x.name?.includes(interaction.customId) + : x.name === interaction.customId + : !x.name, + ) + .allValues(); + + if (!cmds.length) return; + const data = { + client: client, + guild: interaction.guild, + message: interaction?.message, + channel: interaction.channel, + author: interaction.author, + member: interaction.member, + isAutocomplete: interaction.isAutocomplete(), + }; + for (const cmd of cmds) { + if (cmd.name?.includes("$")) { + cmd.name = ( + await Interpreter( + client, + data, + [], + { code: cmd.name, name: "NameParser" }, + client.db, + true, + undefined, + { interaction }, + ) + )?.code; + } + await Interpreter( + client, + data, + interaction.values || + interaction.options?._hoistedOptions?.map( + (x) => x.value, + ) || [interaction.customId] || + [], + cmd, + client.db, + false, + undefined, + { interaction: interaction }, + undefined, + ); + } + } else if (type === "modal") { + cmds = client.cmd.interaction.modal.filterArray( + (x) => x.name === interaction.customId, + ); + if (!cmds.length) return; + const data = { + client: client, + guild: interaction.guild, + message: interaction?.message, + channel: interaction.channel, + author: interaction.author, + member: interaction.member, + }; + for (const cmd of cmds) { + if (cmd.name?.includes("$")) { + cmd.name = ( + await Interpreter( + client, + data, + [], + { code: cmd.name, name: "NameParser" }, + client.db, + true, + undefined, + { interaction }, + ) + )?.code; + } + await Interpreter( + client, + data, + interaction.values || + interaction.options?._hoistedOptions?.map( + (x) => x.value, + ) || [interaction.customId] || + [], + cmd, + client.db, + false, + undefined, + { interaction: interaction }, + undefined, + ); + } + } else + { + + cmds = client.cmd.interaction.slash + .filter( + (x) => + x.name.toLowerCase() === + interaction.commandName.toLowerCase(), + ) + .allValues(); + + if (!cmds.length) return; + const data = { + client: client, + guild: interaction.guild, + message: interaction?.message, + channel: interaction.channel, + author: interaction.author, + member: interaction.member, + isAutocomplete: interaction.isAutocomplete(), + }; + for (const cmd of cmds) { + if (cmd.name?.includes("$")) { + cmd.name = ( + await Interpreter( + client, + data, + [], + { code: cmd.name, name: "NameParser" }, + client.db, + true, + undefined, + { interaction }, + ) + )?.code; + } + await Interpreter( + client, + data, + interaction.values || + interaction.options?._hoistedOptions?.map( + (x) => x.value, + ) || [interaction.customId] || + [], + cmd, + client.db, + false, + undefined, + { interaction: interaction }, + undefined, + ); + } + } +}; diff --git a/src/handler/NonIntents/ready.js b/src/handler/NonIntents/ready.js new file mode 100644 index 000000000..c599e8fe5 --- /dev/null +++ b/src/handler/NonIntents/ready.js @@ -0,0 +1,38 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (client) => { + const cmds = client.cmd.ready.allValues(); + let chan; + const data = { + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + data.guild = chan?.guild; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + data.guild = chan?.guild; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + {}, + chan, + ); + } +}; diff --git a/src/handler/NonIntents/userUpdate.js b/src/handler/NonIntents/userUpdate.js new file mode 100644 index 000000000..0eb2b7ee0 --- /dev/null +++ b/src/handler/NonIntents/userUpdate.js @@ -0,0 +1,37 @@ +const Interpreter = require("../../core/interpreter.js"); +module.exports = async (ou, nu, client) => { + const cmds = client.cmd.userUpdate.allValues(); + let chan; + const data = { + author: nu, + client: client, + }; + for (const cmd of cmds) { + if (cmd.channel?.includes("$")) { + const id = await Interpreter( + client, + data, + [], + { name: "ChannelParser", code: cmd.channel }, + client.db, + true, + ); + chan = client.channels.cache.get(id?.code); + data.channel = chan; + } else { + chan = client.channels.cache.get(cmd.channel); + data.channel = chan; + } + await Interpreter( + client, + data, + [], + cmd, + client.db, + false, + chan?.id, + { olduser: ou, newuser: nu }, + chan, + ); + } +}; diff --git a/src/handler/eventExecuter.js b/src/handler/eventExecuter.js new file mode 100644 index 000000000..78660712a --- /dev/null +++ b/src/handler/eventExecuter.js @@ -0,0 +1,43 @@ +const Interpreter = require("../core/interpreter.js"); + +module.exports = async (event, client, commands, ...data) => { + let msg = { + channel: undefined, + author: undefined, + content: "", + guild: undefined, + member: undefined, + }; + let EventData = {}; + const cmds = commands.allValues(); + for (const cmd of cmds) { + if (cmd.channel) { + const id = cmd.channel.includes("$") + ? ( + await Interpreter( + client, + {author: undefined, channel: undefined, message: undefined}, + [], + {name: "channelParser", code: cmd.channel}, + client.db, + true, + ) + )?.code + : cmd.channel; + const channel = client.channels.cache.get(id); + if (!channel) return console.error("Channel doesn't exist"); + + msg = { + channel: channel, + author: undefined, + content: "", + guild: channel.guild, + member: undefined, + }; + } + EventData = data; + await Interpreter(client, msg, [], cmd, undefined, false, cmd.channel, { + eventData: EventData, + }); + } +}; diff --git a/src/handler/parsers.js b/src/handler/parsers.js new file mode 100644 index 000000000..ea932e0ce --- /dev/null +++ b/src/handler/parsers.js @@ -0,0 +1,484 @@ +const Discord = require("discord.js"); +const { mustEscape } = require("../utils/helpers/mustEscape.js"); +const { ButtonStyleOptions } = require("../utils/Constants.js"); +const SlashOption = require("./slashOption.js"); +const { CreateObjectAST } = require("../utils/helpers/functions.js"); +const EmbedParser = async (msg, d) => { + msg = mustEscape(msg); + + const embeds = []; + + let msgs = msg.split("{newEmbed:").slice(1); + for (let rawr of msgs) { + rawr = rawr.slice(0, rawr.length - 1); + + const embed = {}; + embed.fields = []; + const Checker = (peko) => rawr.includes(`{${peko}:`); + if (Checker("author")) { + const auth = rawr.split("{author:")[1].split("}")[0].split(":"); + embed.author = { + name: auth.shift().addBrackets()?.trim() || "", + icon_url: auth.join(":").addBrackets()?.trim() || "", + }; + } + if (Checker("authorURL")) { + if (!embed.author) return console.error("{author:} was not used"); + embed.author.url = rawr + .split("{authorURL:")[1] + .split("}")[0] + .addBrackets() + .trim(); + } + if (Checker("title")) { + embed.title = rawr.split("{title:")[1].split("}")[0].addBrackets().trim(); + } + if (Checker("url")) { + if (!embed.title) + return console.error("Title was not provided while using {url}"); + embed.url = rawr.split("{url:")[1].split("}")[0].addBrackets().trim(); + } + if (Checker("description")) { + embed.description = rawr + .split("{description:")[1] + .split("}")[0] + .addBrackets() + .trim(); + } + if (Checker("thumbnail")) { + embed.thumbnail = { + url: rawr.split("{thumbnail:")[1].split("}")[0].addBrackets().trim(), + }; + } + if (Checker("image")) { + embed.image = { + url: rawr.split("{image:")[1].split("}")[0].addBrackets().trim(), + }; + } + if (Checker("footer")) { + const f = rawr.split("{footer:")[1].split("}")[0].split(":"); + embed.footer = { + text: f.shift().addBrackets().trim() || "", + icon_url: f.join(":").addBrackets().trim() || "", + }; + } + if (Checker("color")) { + embed.color = Discord.resolveColor( + rawr.split("{color:")[1].split("}")[0].addBrackets().trim() + ); + } + if (rawr.includes("{timestamp")) { + let t = rawr.split("{timestamp")[1].split("}")[0].replace(":", "").trim(); + if (t === "" || t === "ms") { + t = Date.now(); + } + embed.timestamp = new Date(t); + } + if (Checker("field")) { + const fi = rawr.split("{field:").slice(1); + for (let fo of fi) { + fo = fo.split("}")[0].split(":"); + const fon = fo.shift().addBrackets().trim(); + const foi = ["yes", "no", "true", "false"].find( + (x) => x === fo[Number(fo.length - 1)].trim() + ) + ? fo.pop().trim() === "true" + : false; + + const fov = fo.join(":").addBrackets().trim(); + embed.fields.push({ name: fon, value: fov, inline: foi }); + } + } + + embeds.push(embed); + } + return embeds; +}; + +const ComponentParser = async (msg, d) => { + msg = mustEscape(msg); + let msgs = msg.split("{actionRow:").slice(1); + const actionRows = []; + + for (let aoi of msgs) { + const index = aoi.lastIndexOf("}"); + aoi = aoi.slice(0, index); + + const buttonPart = []; + const Checker = (checker) => aoi.includes("{" + checker + ":"); + if (Checker("button")) { + const inside = aoi.split("{button:").slice(1); + for (let button of inside) { + button = button?.split("}")[0]; + button = button?.split(":").map((x) => x.trim()); + + const label = button.shift().addBrackets(); + let style = isNaN(button[0]) ? button.shift() : Number(button.shift()); + style = ButtonStyleOptions[style] || style; + const cus = button.shift().addBrackets(); + const disable = + button.shift()?.replace("true", true)?.replace("false", false) || + false; + let emoji; + const dInside = + Number(style) === 5 + ? { + label: label, + type: 2, + style: style, + url: cus, + disabled: disable, + } + : { + label: label, + type: 2, + style: style, + custom_id: cus, + disabled: disable, + }; + + if (button) { + try { + emoji = d.util.getEmoji(d, button.toString().addBrackets()); + dInside.emoji = { + name: emoji.name, + id: emoji.id, + animated: emoji.animated, + }; + } catch { + emoji = emoji ?? button.toString().addBrackets(); + dInside.emoji = emoji || undefined; + } + } + buttonPart.push(dInside); + } + } + if (Checker("selectMenu")) { + let inside = aoi.split("{selectMenu:").slice(1).join(""); + inside = inside.split(":").map((c) => c.trim()); + const customID = inside.shift(); + const placeholder = inside.shift(); + const minVal = inside[0] === "" ? 0 : Number(inside.shift()); + const maxVal = inside[0] === "" ? 1 : Number(inside.shift()); + const disabled = inside.shift() === "true"; + const options = inside.join(":").trim(); + + let optArray = []; + if (options.includes("{selectMenuOptions:")) { + const opts = options.split("{selectMenuOptions:").slice(1); + + for (let opt of opts) { + opt = opt.split("}")[0].split(":"); + const label = opt.shift(); + const value = opt.shift(); + const desc = opt.shift(); + const def = opt.shift() === "true"; + let emoji; + + const ind = { + label: label, + value: value, + description: desc, + default: def, + }; + + if (opt) { + try { + emoji = d.util.getEmoji(d, opt.toString().addBrackets()); + ind.emoji = { + name: emoji.name, + id: emoji.id, + animated: emoji.animated, + }; + } catch { + emoji = emoji ?? opt.toString().addBrackets(); + ind.emoji = emoji || undefined; + } + } + + optArray.push(ind); + } + } + + buttonPart.push({ + type: 3, + custom_id: customID, + placeholder: placeholder, + min_values: minVal, + max_values: maxVal, + disabled, + options: optArray, + }); + } + if (Checker("textInput")) { + let inside = aoi.split("{textInput:").slice(1); + for (let textInput of inside) { + textInput = textInput.split("}")[0].split(":"); + const label = textInput.shift().addBrackets().trim(); + let style = textInput.shift().addBrackets().trim(); + style = isNaN(style) ? style : Number(style); + const custom_id = textInput.shift().addBrackets().trim(); + const required = textInput.shift()?.addBrackets().trim() === "true"; + const placeholder = textInput.shift()?.addBrackets().trim(); + const min_length = textInput.shift()?.addBrackets().trim(); + const max_length = textInput.shift()?.addBrackets().trim(); + const value = textInput.shift()?.addBrackets().trim(); + buttonPart.push({ + type: 4, + label, + style, + custom_id, + required, + placeholder, + min_length, + max_length, + value, + }); + } + } + actionRows.push({ type: 1, components: buttonPart }); + } + return actionRows; +}; + +const FileParser = (msg, d) => { + if (!msg) return; + msg = mustEscape(msg); + const Checker = (ayaya) => msg.includes("{" + ayaya + ":"); + + const att = []; + if (Checker("attachment")) { + const e = msg + ?.split("{attachment:") + ?.slice(1) + .map((x) => x.trim()); + for (let o of e) { + o = o.split("}")[0]; + o = o.split(":"); + + const attachment = new Discord.AttachmentBuilder(o.pop().addBrackets(), { + name: o.join(":").toString().addBrackets() ?? "attachment.png", + }); + att.push(attachment); + } + } + if (Checker("file")) { + const i = msg + .split("{file:") + ?.slice(1) + .map((x) => x.trim()); + for (let u of i) { + u = u.split("}")[0]; + u = u.split(":"); + + const attachment = new Discord.AttachmentBuilder( + Buffer.from(u.pop().addBrackets()), + { name: u.join(":").toString().addBrackets() ?? "file.txt" } + ); + att.push(attachment); + } + } + return att; +}; + +const errorHandler = async (errorMessage, d, returnMsg = false, channel) => { + errorMessage = errorMessage.trim(); + const Checker = (parts, ayaya) => parts.includes("{" + ayaya + ":"); + + let send = true; + let deleteCommand = false; + let suppress = false; + let interaction; + let deleteIn; + + let files = []; + let reactions = []; + const embeds = []; + const components = []; + + let edits = { + time: "", + messages: [], + }; + const parts = CreateObjectAST(errorMessage); + for (const part of parts) { + errorMessage = errorMessage.replace(part, ""); + if (Checker(part, "newEmbed")) embeds.push(...(await EmbedParser(part, d))); + else if (Checker(part, "actionRow")) + components.push(...(await ComponentParser(part))); + else if (Checker(part, "attachment") || Checker(part, "file")) + files = FileParser(part); + else if (Checker(part, "edit")) edits = await EditParser(part); + else if (Checker(part, "suppress")) suppress = true; + else if (Checker(part, "deleteCommand")) deleteCommand = true; + else if (Checker(part, "interaction")) interaction = true; + else if (Checker(part, "deleteIn")) + deleteIn = part.split(":")[1].trim(); + else if (Checker(part, "reactions")) + reactions = reactionParser(part.split(":").slice(1).join(":").replace("}", "")); + } + + if (!embeds.length) send = false; + + if (send && suppress) send = false; + + if (returnMsg === true) { + return { + embeds: send ? embeds : [], + components, + content: errorMessage.addBrackets() === "" ? " " : errorMessage.addBrackets(), + files, + options: { + reactions: reactions.length ? reactions : undefined, + suppress, + interaction, + edits, + deleteIn, + deleteCommand, + }, + }; + } + + errorMessage = errorMessage.addBrackets().trim(); + if (!(errorMessage.length || send || files.length)) return; + + const ch = channel || d.channel; + + if ((errorMessage.length || send || files.length) && d && ch && !returnMsg) { + const m = await ch + .send({ + content: errorMessage.addBrackets(), + embeds: send ? embeds : [], + files: files?.length ? files : [], + }) + .catch(() => {}); + + if (!m) return; + + if (m && reactions.length) { + for (const reaction of reactions) { + await m.react(reaction).catch(console.error); + } + } + + if (m && edits.timeout) { + for (const code of edits.messages) { + await new Promise((e) => setTimeout(e, edits.timeout)); + + const sender = await errorHandler(d, code, true); + + await m.suppressEmbeds(suppress); + + await m.edit(sender.message, sender.embed).catch(() => null); + } + } + + if (m && deleteIn) { + m.delete({ + timeout: deleteIn, + }).catch(() => null); + } + + if (returnMsg === "id") { + return m.id; + } else if (returnMsg === "object") { + return m; + } else if (returnMsg === "withMessage") return m; + } +}; + +const reactionParser = (reactions) => { + const regex = /()|\p{Extended_Pictographic}/gu; + const matches = reactions.match(regex); + if (!matches) return []; + return matches; +} + +const SlashOptionsParser = async (options) => { + options = mustEscape(options); + + let Alloptions = []; + options = options.trim(); + const Checker = (msg) => options.includes("{" + msg + ":"); + + if (Checker("subGroup")) { + Alloptions = Alloptions.concat(await SlashOption.subGroup(options)); + } + if (Checker("subCommand") && !Checker("subGroup")) { + Alloptions = Alloptions.concat(await SlashOption.subCommand(options)); + } + if (Checker("string") && !(Checker("subCommand") || Checker("subGroup"))) { + Alloptions = Alloptions.concat(await SlashOption.string(options)); + } + if (Checker("integer") && !(Checker("subCommand") || Checker("subGroup"))) { + Alloptions = Alloptions.concat(await SlashOption.integer(options)); + } + if (Checker("boolean") && !(Checker("subCommand") || Checker("subGroup"))) { + Alloptions = Alloptions.concat(await SlashOption.boolean(options)); + } + if (Checker("user") && !(Checker("subCommand") || Checker("subGroup"))) { + Alloptions = Alloptions.concat(await SlashOption.user(options)); + } + if (Checker("channel") && !(Checker("subCommand") || Checker("subGroup"))) { + Alloptions = Alloptions.concat(await SlashOption.channel(options)); + } + if (Checker("role") && !(Checker("subCommand") || Checker("subGroup"))) { + Alloptions = Alloptions.concat(await SlashOption.role(options)); + } + if ( + Checker("mentionable") && + !(Checker("subCommand") || Checker("subGroup")) + ) { + Alloptions = Alloptions.concat(await SlashOption.mentionable(options)); + } + if (Checker("number") && !(Checker("subCommand") || Checker("subGroup"))) { + Alloptions = Alloptions.concat(await SlashOption.number(options)); + } + + return Alloptions; +}; + +const OptionParser = async (options, d) => { + const Checker = (msg) => options.includes(msg); + const optionData = {}; + if (Checker("{edit:")) { + const editPart = options.split("{edit:")[1].split("}}")[0]; + const dur = editPart.split(":")[0]; + const msgs = editPart.split(":{").slice(1).join(":{").split("}:{"); + const messages = []; + for (const msg of msgs) { + messages.push(await errorHandler(msg.split("}:{")[0], d)); + } + optionData.edits = { time: dur, messages }; + } + if (Checker("{reactions:")) { + const react = options.split("{reactions:")[1].split("}")[0]; + optionData.reactions = react.split(",").map((x) => x.trim()); + } + if (Checker("{delete:")) { + optionData.deleteIn = Time.parse( + options.split("{delete:")[1].split("}")[0].trim() + )?.ms; + } + if (Checker("{deleteIn:")) { + optionData.deleteIn = Time.parse( + options.split("{deleteIn:")[1].split("}")[0].trim() + )?.ms; + } + if (Checker("deletecommand")) { + optionData.deleteCommand = true; + } + if (Checker("interaction")) { + optionData.interaction = true; + } + return optionData; +}; + +module.exports = { + EmbedParser: EmbedParser, + ComponentParser: ComponentParser, + FileParser: FileParser, + ErrorHandler: errorHandler, + SlashOptionsParser: SlashOptionsParser, + OptionParser, +}; diff --git a/src/handler/searchIndexes.js b/src/handler/searchIndexes.js new file mode 100644 index 000000000..f8ccc1942 --- /dev/null +++ b/src/handler/searchIndexes.js @@ -0,0 +1,51 @@ +function searchIndexes(pat, txt) { + const patLength = pat.length; + const txtLength = txt.length; + + const lps = new Int32Array(patLength); + + processPattern(pat, patLength, lps); + + const indexes = []; + + let patIndex = 0; + let txtIndex = 0; + + while (txtIndex < txtLength) { + if (pat[patIndex] === txt[txtIndex]) { + patIndex++; + txtIndex++; + } + + if (patIndex === patLength) { + indexes.push(txtIndex - patIndex); + patIndex = lps[patIndex - 1]; + } else if (txtIndex < txtLength && pat[patIndex] !== txt[txtIndex]) { + if (patIndex !== 0) { + patIndex = lps[patIndex - 1]; + } else { + txtIndex++; + } + } + } + + return indexes; +} + +function processPattern(pat, patLength, lps) { + let len = 0; + let index = 1; + + while (index < patLength) { + if (pat[index] === pat[len]) { + len++; + lps[index++] = len; + } else if (len !== 0) { + len = lps[len - 1]; + } else { + lps[index++] = 0; + } + } +} + +module.exports = searchIndexes; \ No newline at end of file diff --git a/src/handler/slashCommandOptionsParser.js b/src/handler/slashCommandOptionsParser.js new file mode 100644 index 000000000..625069395 --- /dev/null +++ b/src/handler/slashCommandOptionsParser.js @@ -0,0 +1,13 @@ +module.exports = (fields) => { + const object = []; + for (const field of fields) { + const [name, description, required = "true", type = 3] = field.split(":"); + object.push({ + name, + description, + type: Number(type) || 3, + required: required === "true", + }); + } + return object; +}; diff --git a/src/handler/slashOption.js b/src/handler/slashOption.js new file mode 100644 index 000000000..c401c31b1 --- /dev/null +++ b/src/handler/slashOption.js @@ -0,0 +1,212 @@ +class SlashOption { + static choice(option) { + const Choice = []; + option = option.split("{choice:").slice(1); + + for (let opt of option) { + opt = opt.split("}")[0].split(":"); + + const name = opt.shift()?.addBrackets(); + const value = opt.shift()?.addBrackets(); + Choice.push({name, value}); + } + + return Choice; + } + + static async string(option) { + option = option.split("{string:").slice(1); + const stringOptions = []; + for (let opt of option) { + opt = opt.split(":"); + const name = opt.shift()?.addBrackets(); + const description = opt.shift()?.addBrackets(); + const required = opt?.shift()?.addBrackets() === "true" || false; + const choice = opt.join(":"); + + let choices; + if (choice.trim().length) { + choices = this.choice(choice); + } else choices = []; + stringOptions.push({type: 3, name, description, required, choices}); + } + + return stringOptions; + } + + static async integer(options) { + options = options.split("{integer:").slice(1); + const integerOptions = []; + for (let option of options) { + option = option.split(":"); + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const required = opt?.shift()?.addBrackets() === "true" || false; + const choice = option.join(":"); + let choices; + if (choice.trim().length) { + choices = this.choice(choice); + } else choices = []; + integerOptions.push({type: 4, name, description, required, choices}); + } + return integerOptions; + } + + static async number(options) { + options = options.split("{number:").slice(1); + const numberOptions = []; + for (const option of options) { + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const required = + option + ?.shift() + ?.addBrackets() + ?.replace("true", true) + ?.replace("false", false) || true; + const choice = option.join(":"); + let choices; + if (choice.trim().length) { + choices = this.choice(choice); + } else choices = []; + numberOptions.push({type: 10, name, description, required, choices}); + } + return numberOptions; + } + + static async boolean(options) { + options = options.split("{boolean:").slice(1); + const booleanOptions = []; + for (const option of options) { + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const required = + option + ?.shift() + ?.addBrackets() + ?.replace("true", true) + ?.replace("false", false) || true; + booleanOptions.push({type: 5, name, description, required}); + } + return booleanOptions; + } + + static async user(options) { + options = options.split("{user:").slice(1); + const userOptions = []; + for (const option of options) { + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const required = + option + ?.shift() + ?.addBrackets() + ?.replace("true", true) + ?.replace("false", false) || true; + userOptions.push({type: 6, name, description, required}); + } + return userOptions; + } + + static async channel(options) { + options = options.split("{channel:").slice(1); + const channelOptions = []; + for (const option of options) { + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const required = + option + ?.shift() + ?.addBrackets() + ?.replace("true", true) + ?.replace("false", false) || true; + channelOptions.push({type: 7, name, description, required}); + } + return channelOptions; + } + + static async role(options) { + options = options.split("{role:").slice(1); + const roleOptions = []; + for (const option of options) { + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const required = + option + ?.shift() + ?.addBrackets() + ?.replace("true", true) + ?.replace("false", false) || true; + roleOptions.push({type: 8, name, description, required}); + } + return roleOptions; + } + + static async mentionable(options) { + options = options.split("{mentionable:").slice(1); + const mentionOptions = []; + for (let option of options) { + option = option.split("}")[0].split(":"); + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const required = + option + ?.shift() + ?.addBrackets() + ?.replace("true", true) + ?.replace("false", false) || true; + mentionOptions.push({type: 9, name, description, required}); + } + return mentionOptions; + } + + static async subCommand(options) { + options = options.split("{subCommand:").slice(1); + const subOptions = []; + for (let option of options) { + const index = option.lastIndexOf("}"); + option = option.slice(0, index).split(":"); + + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + const opts = option.join(":"); + let Options = []; + let opt = opts; + + const Checker = (o) => opt.includes(o); + if (Checker("string")) Options = Options.concat(await this.string(opt)); + + if (Checker("integer")) Options = Options.concat(await this.integer(opt)); + if (Checker("boolean")) Options = Options.concat(await this.boolean(opt)); + if (Checker("user")) Options = Options.concat(await this.user(opt)); + if (Checker("channel")) Options = Options.concat(await this.channel(opt)); + if (Checker("role")) Options = Options.concat(await this.role(opt)); + if (Checker("mentionable")) + Options = Options.concat(await this.mentionable(opt)); + if (Checker("number")) Options = Options.concat(await this.number(opt)); + + subOptions.push({name, description, type: 1, options: Options}); + } + return subOptions; + } + + static async subGroup(options) { + options = options.split("{subGroup:").slice(1); + const GroupOptions = []; + for (let option of options) { + const index = option.lastIndexOf("}"); + option = option.slice(0, index).split(":"); + const name = option.shift()?.addBrackets(); + const description = option.shift()?.addBrackets(); + let Option = []; + const opts = option.join(":"); + + Option = Option.concat(await this.subCommand(opts)); + + GroupOptions.push({name, description, type: 2, options: Option}); + } + return GroupOptions; + } +} + +module.exports = SlashOption; \ No newline at end of file diff --git a/src/handler/status.js b/src/handler/status.js new file mode 100644 index 000000000..fd6389b3b --- /dev/null +++ b/src/handler/status.js @@ -0,0 +1,47 @@ +module.exports = async (status, client) => { + let statuses = client.statuses.allValues() + if (statuses.length <= 0) { + return; + } + + let y = 0; + + const processStatus = async () => { + statuses = client.statuses.allValues() + if (!statuses[y]) { + y = 0; + } + + const stats = { + activity: statuses[y].activity, + }; + + if (name = stats?.activity?.name) { + if (name.includes("$")) { + stats.activity.name = ( + await client.functionManager.interpreter( + client, + {}, + [], + { code: statuses[y].activity.name }, + client.db, + true + ) + )?.code; + } + } else { + throw new TypeError(`Missing or invalid 'name' method in status[${y}]`); + } + + client.user.setPresence({ + status: statuses[y].status, + activities: [stats.activity], + afk: statuses[y].afk, + }); + + setTimeout(processStatus, statuses[y]?.time * 1000 || 0); + y++; + }; + + await processStatus(); +}; diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 000000000..a1d2cadc7 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,483 @@ +import { Client, ShardingManager } from "discord.js"; +import { Group, LimitGroup, SuperSet } from "@akarui/structures"; +import { Group as Collection } from "@akarui/structures"; +import { AllEvents } from "./utils/Constants"; +import { Constants } from "./utils/Constants"; +import { parsers } from "./handler/parsers"; + +declare module "aoi.js" { + import { EventEmitter } from "events"; + + type ErrorMsg = string | Record; + + declare global { + interface String { + replaceLast(find: string, replace: string): string; + deleteBrackets(): string; + removeBrackets(): string; + check(): string; + after(): { + inside: string; + total: string; + splits: string[]; + toString(): string; + addBrackets(): string; + }; + addBrackets(): string; + } + + interface Array { + goof(sep?: string): string; + } + } + + class Util { + static constants: typeof Constants; + static parsers: typeof parsers; + + static getUser(d: any, id: string): Promise; + static fetchUser(d: any, id: string): Promise; + + static fetchChannel(d: any, id: string): Promise; + static getChannel(d: any, id: string, force?: boolean): Channel | undefined; + + static fetchMember(guild: Guild, id: string): Promise; + static fetchMembers(guild: Guild, options: any): Promise>; + static getMember(guild: Guild, id: string): GuildMember | undefined; + + static getMembers(guild: Guild, options: { type: string; query: string; limit: number }, force?: boolean): Collection; + + static fetchMessage(channel: Channel, id: string): Promise; + static getMessage(channel: Channel, id: string): Message | undefined; + + static setCode(options: any, escape?: boolean): string; + + static getGuild(d: any, id: string): Guild | undefined; + + static get channelTypes(): { + Text: number; + DM: number; + GroupDM: number; + Forum: number; + Voice: number; + Category: number; + Announcement: number; + AnnouncementThread: number; + PublicThread: number; + PrivateThread: number; + Stage: number; + GuildDirectory: number; + }; + + static get threadTypes(): { + public: string; + private: string; + }; + + static errorParser(errorM: ErrorMsg, d: any): Promise; + + static getRole(guild: Guild, id: string): Promise; + static fetchRole(guild: Guild, id: string): Promise; + + static aoiFunc(d: any, FieldsRequired?: boolean): any; + + static getEmoji(d: any, Emoji: string): Emoji | undefined; + + static getSticker(guild: Guild, Sticker: string): any; + + static findId(d: any, id: string): Promise; + + static findMember(guild: Guild, memberResolver: string): string | undefined; + + static findGuildChannel(guild: Guild, ChannelResolver: string): string | undefined; + + static findChannel(client: Client, ChannelResolver: string): string | undefined; + + static findRole(guild: Guild, RoleResolver: string): string | undefined; + + static findUser(client: Client, UserResolver: string): string | undefined; + + static findRoles(guild: Guild, options: { type: string; query: string; limit: number }): Collection; + + static searchType: string[]; + static audioFilters: { + nightcore: (value: number) => any; + bassboost: (value: number) => any; + "8d": () => any; + pitch: (value: number) => any; + karaoke: (value: number) => any; + slowed: (value: number) => any; + deep: (value: number) => any; + }; + } + + class CustomEvent extends EventEmitter { + client: AoiClient; + commands: Collection; + + constructor(client: AoiClient); + + command(d: { + name: string; + listen: string; + code: string; + }): void; + + listen(event: string): void; + } + + class AoiError { + static EventError(event: string, intent: string, line?: number): void; + static CommandError( + command: string, + type: string, + name: string, + position?: number + ): void; + static makeMessageError( + client: AoiClient, + channel: Channel, + message: ErrorMsg, + options?: Record + ): void; + static consoleError(errorname: string, errorMsg: ErrorMsg): void; + static functionErrorResolve( + d: d, + type: string, + object: object, + message: ErrorMsg + ): void; + static fnError( + d: d, + type: string, + object: object, + message: ErrorMsg + ): void; + } + + type IntentOptions = string[]; + + type DatabaseOption = { + type: + | "default" + | "aoi.db" + | "custom"; + db: Database; + path?: string; + tables?: Array; + extraOptions?: Record; + promisify?: boolean; + }; + + type RespondOnEditOptions = { + commands?: boolean; + alwaysExecute?: boolean; + nonPrefixed?: boolean; + time?: number; + }; + + type CacheOptions = Record; + + type ClientOptions = { + token: string; + prefix: string | Array; + intents: IntentOptions; + database?: DatabaseOption; + respondOnEdit?: RespondOnEditOptions; + disableFunctions?: Array; + respondToBots: boolean; + guildOnly: boolean; + cache: CacheOptions; + aoiLogs?: boolean; + aoiWarning?: boolean; + aoiAutoUpdate?: boolean; + disableAoiDB: boolean; + suppressAllErrors?: boolean; + errorMessage?: Array; + events?: Array; + fetchInvites?: { + enabled: boolean; + cacheInviters?: boolean; + }; + }; + + interface BaseCommand { + code: string; + } + + interface EventCommand extends BaseCommand { + name?: string; + channel?: string; + + [key: string]: any; + } + + interface Command extends BaseCommand { + name: string; + aliases?: string | Array; + whitelist?: boolean; + nonPrefixed?: boolean; + dmOnly?: boolean; + } + + interface AwaitCommand extends BaseCommand { + name: string; + } + + interface InteractionCommand extends BaseCommand { + name: string | Array; + prototype: "application" | "button" | "selectMenu"; + } + + interface LoopCommand extends BaseCommand { + every: number; + channel?: string; + executeOnStartup?: boolean; + } + + type StatusOption = { + name: string; + url: string; + time: number; + shardID: number; + type: "Playing" | "Listening" | "Watching" | "Streaming"; + status: string; + }; + + class BaseClient extends Client { + aoiOptions: Record; + interactionManager: InteractionManager; + cacheManager: CacheManager; + variableManager: any; + prefix: string | string[]; + db: any; + statuses: Group; + + constructor(options: ClientOptions); + + status(d: StatusOption[]): void; + loadCommands(directory: string, debug?: boolean): void; + variables(data: object, table?: string): void; + } + + class AoiClient extends BaseClient { + cmd: CommandManager; + functionManager: FunctionManager; + + constructor(options: ClientOptions); + + command(d: Command): void; + awaitedCommand(d: AwaitCommand): void; + deletedCommand(d: EventCommand): void; + updateCommand(d: EventCommand): void; + bulkDeleteCommand(d: EventCommand): void; + guildJoinCommand(d: EventCommand): void; + guildLeaveCommand(d: EventCommand): void; + guildUpdateCommand(d: EventCommand): void; + guildUnavailableCommand(d: EventCommand): void; + roleCreateCommand(d: EventCommand): void; + roleUpdateCommand(d: EventCommand): void; + roleDeleteCommand(d: EventCommand): void; + channelCreateCommand(d: EventCommand): void; + channelUpdateCommand(d: EventCommand): void; + channelDeleteCommand(d: EventCommand): void; + channelPinsUpdateCommand(d: EventCommand): void; + stageInstanceCreateCommand(d: EventCommand): void; + stageInstanceUpdateCommand(d: EventCommand): void; + stageInstanceDeleteCommand(d: EventCommand): void; + threadCreateCommand(d: EventCommand): void; + threadUpdateCommand(d: EventCommand): void; + threadDeleteCommand(d: EventCommand): void; + threadListSyncCommand(d: EventCommand): void; + threadMemberUpdateCommand(d: EventCommand): void; + joinCommand(d: EventCommand): void; + leaveCommand(d: EventCommand): void; + memberUpdateCommand(d: EventCommand): void; + threadMembersUpdateCommand(d: EventCommand): void; + memberAvailableCommand(d: EventCommand): void; + membersChunkCommand(d: EventCommand): void; + emojiCreateCommand(d: EventCommand): void; + emojiDeleteCommand(d: EventCommand): void; + emojiUpdateCommand(d: EventCommand): void; + banAddCommand(d: EventCommand): void; + banRemoveCommand(d: EventCommand): void; + reactionAddCommand(d: EventCommand): void; + reactionRemoveCommand(d: EventCommand): void; + reactionRemoveAllCommand(d: EventCommand): void; + reactionRemoveEmojiCommand(d: EventCommand): void; + presenceUpdateCommand(d: EventCommand): void; + voiceStateUpdateCommand(d: EventCommand): void; + interactionCommand(d: InteractionCommand): void; + applicationCmdCreateCommand(d: EventCommand): void; + applicationCmdDeleteCommand(d: EventCommand): void; + applicationCmdUpdateCommand(d: EventCommand): void; + userUpdateCommand(d: EventCommand): void; + variableCreateCommand(d: EventCommand): void; + variableDeleteCommand(d: EventCommand): void; + variableUpdateCommand(d: EventCommand): void; + readyCommand(d: EventCommand): void; + functionErrorCommand(d: EventCommand): void; + loopCommand(d: LoopCommand): void; + timeoutCommand(d: EventCommand): void; + pulseCommand(d: EventCommand): void; + rateLimitCommand(d: EventCommand): void; + webhooksUpdateCommand(d: EventCommand): void; + } + + // cacheManager + type CacheTypes = "cache" | "limitCache" | "setCache"; + + class CacheManager { + constructor(client: AoiClient); + + get types(): CacheTypes; + + _validType(type: string): boolean; + + createCache(type: "cache", name: string): Group; + createCache(type: "limitCache", name: string): LimitGroup; + createCache(type: "setCache", name: string): SuperSet; + + deleteCache(type: "cache", name: string): Group; + deleteCache(type: "limitCache", name: string): LimitGroup; + deleteCache(type: "setCache", name: string): SuperSet; + + static _DjsCacheManager(cache: CacheOptions): any; + } + + // ClientShard + class ClientShard extends ShardingManager { + file: string; + client: AoiClient; + + constructor(file: string, options: object, client: AoiClient); + + onShardDisconnect(): void; + onShardError(): void; + onShardResume(): void; + onShardReconnecting(): void; + onShardReady(): void; + } + + // CommandManager + class Command { + [key: string]: any; + + __client__: AoiClient; + + constructor(d: object, client: AoiClient); + + serializeFunctions(): string[]; + serializeCode(): void | string[]; + toString(): string; + toArray(): [string, any][]; + keys(): string[]; + values(): unknown[]; + } + + class CommandManager { + client: AoiClient; + customCmds?: Array; + + constructor(client: AoiClient, formCommand?: boolean, customCmds?: string[]); + + get types(): string[]; + + createCommand(d: any): void; + formCommand(): void; + formCustomCommand(customCmds: string[]): void; + } + + // FunctionManager + class FunctionManager { + client: AoiClient; + maps: Record; + functions: string[]; + cache: Group; + interpreter: unknown; + + constructor(client: AoiClient); + + cacheFunctions(): void; + createFunction(data: Array>): void; + findFunctions(code: string): string[]; + serializeCode(code: string): string[]; + } + + // LoadCommands + class LoadCommands { + Client: AoiClient; + AddToClient?: boolean; + + constructor(Client: AoiClient, AddToClient?: boolean); + + load(cmd: CommandManager, path: string, debug?: boolean): void; + update(debug?: boolean): void; + setColors(colors: object): void; + get allColors(): object; + get themes(): object; + } + + class CustomEvent extends EventEmitter { + client: AoiClient; + commands: Group; + + constructor(client: AoiClient); + + command(d: CustomEventCommand): void; + listen(event: string): void; + } + + type ApplicationOptionData = { + type: + | "SUB_COMMAND" + | "SUB_COMMAND_GROUP" + | "STRING" + | "INTEGER" + | "BOOLEAN" + | "USER" + | "CHANNEL" + | "ROLE" + | "MENTIONABLE" + | "NUMBER" + | number; + }; + type ApplicationData = { + data: { + name: string; + description?: string; + options?: object[]; + type?: "CHAT_INPUT" | "USER" | "MESSAGE"; + defaultPermission?: boolean; + }; + guildId?: string; + }; + + class Interaction extends EventEmitter { + client: AoiClient; + + constructor(client: AoiClient); + + resolve(interaction: Interaction): Interaction; + } + + class InteractionManager extends Interaction { + client: AoiClient; + awaitComponents: unknown; + componentCollector: unknown; + buttonData: Group; + applicationData: Group; + selectMenuData: Group; + + constructor(client: AoiClient); + + createApplicationData(d: ApplicationData): void; + createButtonData(d: object): void; + createSelectMenuData(d: object): void; + stringifyApplicationData(name: string): string; + resolveButtonData(name: string): string; + resolveSelectMenuData(name: string): string; + resolveSelectMenuOptionData(options: object[]): string; + get buttonDataLength(): number; + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 000000000..7f9031db7 --- /dev/null +++ b/src/index.js @@ -0,0 +1,23 @@ +const AoiClient = require("./classes/AoiClient"); +const CustomEvent = require("./classes/CustomEvent.js"); +const LoadCommands = require("./classes/LoadCommands.js"); +const ClientShard = require("./classes/ClientShard.js"); +const AoiError = require("./classes/AoiError.js"); +const Util = require("./classes/Util.js"); +const Database = require("./classes/Database.js"); +const CacheManager = require("./classes/CacheManager.js"); + +/** + * AoiClient, custom events, command loader, client shard, error handling and utility functions + * @namespace + */ +module.exports = { + AoiClient, + CustomEvent, + LoadCommands, + ClientShard, + AoiError, + Util, + Database, + CacheManager, +}; diff --git a/src/shardhandler/shardCreate.js b/src/shardhandler/shardCreate.js new file mode 100644 index 000000000..008a39265 --- /dev/null +++ b/src/shardhandler/shardCreate.js @@ -0,0 +1,36 @@ +const Interpreter = require("../core/interpreter.js"); +module.exports = async (shard, cmds, client) => { + for (const cmd of cmds.shardCreate.array()) { + const id = cmd?.channel?.includes("$") + ? ( + await Interpreter( + client, + {}, + [], + { + name: "channelParser", + code: cmd.channel, + }, + client.db, + true, + ) + )?.code + : cmd.channel; + const channel = client.channels.cache.get(id); + if (!channel) return; + + await Interpreter( + client, + {}, + [], + cmd, + client.db, + false, + undefined, + { + shard: shard, + }, + channel, + ); + } +}; \ No newline at end of file diff --git a/src/shardhandler/shardDisconnect.js b/src/shardhandler/shardDisconnect.js new file mode 100644 index 000000000..f5d6996b5 --- /dev/null +++ b/src/shardhandler/shardDisconnect.js @@ -0,0 +1,37 @@ +const Interpreter = require("../core/interpreter.js"); +module.exports = async (event, shardID, client, cmds) => { + for (const cmd of cmds.shardDisconnect.array()) { + const id = cmd?.channel?.includes("$") + ? ( + await Interpreter( + client, + {}, + [], + { + name: "channelParser", + code: cmd.channel, + }, + client.db, + true, + ) + )?.code + : cmd.channel; + const channel = client.channels.cache.get(id); + if (!channel) return; + + await Interpreter( + client, + {}, + [], + cmd, + client.db, + false, + undefined, + { + closeEvent: event, + shardID: shardID, + }, + channel, + ); + } +}; diff --git a/src/shardhandler/shardError.js b/src/shardhandler/shardError.js new file mode 100644 index 000000000..9d7753110 --- /dev/null +++ b/src/shardhandler/shardError.js @@ -0,0 +1,37 @@ +const Interpreter = require("../core/interpreter.js"); +module.exports = async (error, shardID, client, cmds) => { + for (const cmd of cmds.shardError.array()) { + const id = cmd?.channel?.includes("$") + ? ( + await Interpreter( + client, + {}, + [], + { + name: "channelParser", + code: cmd.channel, + }, + client.db, + true, + ) + )?.code + : cmd.channel; + const channel = client.channels.cache.get(id); + if (!channel) return; + + await Interpreter( + client, + {}, + [], + cmd, + client.db, + false, + channel?.id, + { + error: error, + shardID: shardID, + }, + channel, + ); + } +}; diff --git a/src/shardhandler/shardReady.js b/src/shardhandler/shardReady.js new file mode 100644 index 000000000..8a23eb0c8 --- /dev/null +++ b/src/shardhandler/shardReady.js @@ -0,0 +1,37 @@ +const Interpreter = require("../core/interpreter.js"); +module.exports = async (shardID, guilds, client, cmds) => { + for (const cmd of cmds.shardReady.array()) { + const id = cmd?.channel?.includes("$") + ? ( + await Interpreter( + client, + {}, + [], + { + name: "channelParser", + code: cmd.channel, + }, + client.db, + true, + ) + )?.code + : cmd.channel; + const channel = client.channels.cache.get(id); + if (!channel) return; + + await Interpreter( + client, + {}, + [], + cmd, + client.db, + false, + undefined, + { + guilds: guilds, + shardID: shardID, + }, + channel, + ); + } +}; diff --git a/src/shardhandler/shardReconnecting.js b/src/shardhandler/shardReconnecting.js new file mode 100644 index 000000000..ebee43a4d --- /dev/null +++ b/src/shardhandler/shardReconnecting.js @@ -0,0 +1,36 @@ +const Interpreter = require("../core/interpreter.js"); +module.exports = async (shardID, client, cmds) => { + for (const cmd of cmds.shardReconnecting.array()) { + const id = cmd?.channel?.includes("$") + ? ( + await Interpreter( + client, + {}, + [], + { + name: "channelParser", + code: cmd.channel, + }, + client.db, + true, + ) + )?.code + : cmd.channel; + const channel = client.channels.cache.get(id); + if (!channel) return; + + await Interpreter( + client, + {}, + [], + cmd, + client.db, + false, + undefined, + { + shardID: shardID, + }, + channel, + ); + } +}; diff --git a/src/shardhandler/shardResume.js b/src/shardhandler/shardResume.js new file mode 100644 index 000000000..831f5b334 --- /dev/null +++ b/src/shardhandler/shardResume.js @@ -0,0 +1,37 @@ +const Interpreter = require("../core/interpreter.js"); +module.exports = async (shardID, replayEvents, client, cmds) => { + for (const cmd of cmds.shardResume.array()) { + const id = cmd?.channel?.includes("$") + ? ( + await Interpreter( + client, + {}, + [], + { + name: "channelParser", + code: cmd.channel, + }, + client.db, + true, + ) + )?.code + : cmd.channel; + const channel = client.channels.cache.get(id); + if (!channel) return; + + await Interpreter( + client, + {}, + [], + cmd, + client.db, + false, + undefined, + { + shardID: shardID, + replayedEvents: replayedEvents, + }, + channel, + ); + } +}; diff --git a/package/Utils/CacheConstants.js b/src/utils/CacheConstants.js similarity index 94% rename from package/Utils/CacheConstants.js rename to src/utils/CacheConstants.js index 59506fdb0..f18e8fc95 100644 --- a/package/Utils/CacheConstants.js +++ b/src/utils/CacheConstants.js @@ -14,7 +14,7 @@ module.exports = { set: manager[name].set, get: manager[name].get, delete: manager[name].delete, - } - } - } -} \ No newline at end of file + }, + }; + }, +}; diff --git a/src/utils/Constants.js b/src/utils/Constants.js new file mode 100644 index 000000000..dca64c8c5 --- /dev/null +++ b/src/utils/Constants.js @@ -0,0 +1,713 @@ +//---------------Client------------------// + +const { + IntentsBitField, + ActivityType, + PermissionsBitField, + Events, +} = require("discord.js"); + +const IntentOptions = { + ...IntentsBitField.Flags, +}; + +const ActivityTypeAvailables = { + playing: ActivityType.Playing, + streaming: ActivityType.Streaming, + listening: ActivityType.Listening, + watching: ActivityType.Watching, + custom: ActivityType.Custom, + competing: ActivityType.Competing, +}; + +const DebugAvailables = { + interpreter: "Boolean", +}; + +const EventAvailables = { + timeout: "Boolean", + music: "Boolean", + functionError: "Boolean", +}; + +//---------------Abbreviation------------// + +const SI_SYMBOL = [ + "", + "K", + "M", + "B", + "T", + "Qa", + "Qi", + "Sx", + "Sp", + "O", + "N", + "D", + "UD", + "UD", + "DD", + "TD", + "QaD", + "QiD", + "SxD", + "SpD", + "OD", + "ND", + "V", + "UV", + "DV", + "TV", + "QaV", + "QiV", + "SxV", + "SpV", + "OV", + "NV", + "DT", + "UDT", + "DDT", + "TDT", + "QaDT", + "QiDT", + "SxDT", + "SpDT", + "ODT", + "NDT", + "DQa", + "UDQa", + "DDQa", + "TDQa", + "QaDQa", + "QiDQa", + "SxDQa", + "SpDQa", + "ODQa", + "NDQa", + "DQi", + "UDQi", + "DDQi", + "TDQi", + "QaDQi", + "QiDQi", + "SxDQi", + "SpDQi", + "ODQi", + "NDQi", + "DSx", + "UDSx", + "DDSx", + "TDSx", + "QaDSx", + "QiDSx", + "SxDSx", + "SpDSx", + "ODSx", + "NDSx", + "DSp", + "UDSp", + "DDSp", + "TDSp", + "QaDSp", + "QiDSp", + "SxDSp", + "SpDSp", + "ODSp", + "NDSp", + "DO", + "UDO", + "DDO", + "TDO", + "QaDO", + "QiDO", + "SxDO", + "SpDO", + "ODO", + "NDO", + "DN", + "UDN", + "DDN", + "TDN", + "QaDN", + "QiDN", + "SxDN", + "SpDN", + "ODN", + "NDN", + "C", + "UC", +]; + +//---------------Events---------------// + +const ApplicationCmdOptions = { + id: "id of the slash cmd;.id", + name: "name of the slash cmd;.name", + description: "description of the slash cmd;.description", + version: "version of slash cmd;.version", + options: "options of slash cmd;.options", + guildID: "guildID of the slash cmd (returns null for global);.guildID", + applicationID: "returns Application ID", + defaultPermission: + "returns default permission of the slash cmd;.defaultPermission", + timestamp: + "returns timestamp of the creation of slash cmd (in ms);.timestamp", + createdAt: "returns the date of creation of slash cmd;.createdAt", +}; +const ChannelOptions = { + //text + default + createdAt: "createdAt", + createdTimestamp: "createdTimestamp", + defaultAutoArchiveDuration: "defaultAuyoArchiveDuration", + deletable: "deletable", + deleted: "deleted", + guildID: "guild?.id", + id: "id", + lastMessageContent: "lastMessage?.content?.deleteBrackets()", + lastMessageID: "lastMessageId", + lastPinAt: "lastPinAt", + lastPinTimestamp: "lastPinTimestamp", + manageable: "manageable", + membersCount: "members?.size", + name: "name?.deleteBrackets()", + nsfw: "nsfw", + parentName: "parent?.name", + parentID: "parentId", + position: "position", + slowmode: "rateLimitPerUser", + topic: "topic?.deleteBrackets()", + type: "type", + viewable: "viewable", + permsAllowed: + "permissionOverwrites?.cache?.map(x=>`type:${x.type}\nallowed:${x.allow}\nmetion:${x.type ==='?'<@'+x.id+'>':'<@&'+x.id+'>'}`).join(`\n`)", + permsDenied: + "permissionOverwrites?.cache?.map(x=>`type:${x.type}\ndenied:${x.deny}\nmetion:${x.type ==='member'?'<@'+x.id+'>':'<@&'+x.id+'>'}`).join(`\n`)", + perms: "permissionOverwrites?.cache?.map(x=>`type:${x.type}\nallowed:${x.allow}\ndenied:${x.deny}\nmetion:${x.type ==='member'?'<@'+x.id+'>':'<@&'+x.id+'>'}`).join(`\n`)", + //category + childrenID: "children?.map(x=>x.id)?.join(' , ')", + childrenName: "children?.map(x=>x.name?.deleteBrackets())?.join(' , ')", + //voice + bitrate: "bitrate", + full: "full", + joinable: "joinable", + rtcRegion: "rtcRegion", + userLimit: "userLimit", + speakable: "speakable", + //threads + archived: "archived", + archivedAt: "archivedAt", + archivedTimestamp: "archivedTimestamp", + autoArchiveDuration: "autoArchiveDuration", + threadMembersCount: "memberCount", + messagesCount: "messagesCount", + ownerID: "ownerId", + sendable: "sendable", + unachievable: "unarchivable", +}; +const MemberOptions = { + id: "id", + name: "user?.username?.deleteBrackets()", + guildID: "guild.id", + nick: "nickname || ''", + roles: "roles?.cache?.filter(r => r.name !== '@everyone').map(r => r?.name.deleteBrackets()).join(', ')", + partial: "partial??false", + premiumStamp: "premiumSinceTimestamp || `0`", + joinedStamp: "joinedTimestamp", + voiceID: "voice.channelID || ''", + displayHex: "displayHexColor", + highestRoleID: "roles.highest.id", + permissions: "permissions.toArray().goof('_')", + newPermissions: `(() => { + const curr = d.data.newm?.permissions.toArray() + const old = d.data.oldm?.permissions.toArray() + + return curr?.filter(p => !old.includes(p))?.goof("_") + })()`, + removedPermissions: `(() => { + const curr = d.data.newm?.permissions.toArray() + const old = d.data.oldm?.permissions.toArray() + + return old?.filter(p => !curr.includes(p))?.goof("_") + })()`, + bannable: "bannable", + kickable: "kickable", + manageable: "manageable", + status: "status", + activities: "presence?.activities?.map(c => c.name).join(', ')", + removedRoles: `roles.cache?.filter(r => ! d.data.newm?.roles.cache.has(r.id)).map(r => r.name).join(", ").deleteBrackets()`, + addedRoles: `roles?.cache?.filter(r => !d.data.oldm.roles.cache.has(r.id)).map(r => r.name).join(", ").deleteBrackets()`, + //thread + threadChannel: "thread?.channel?.name?.deleteBrackets()", + threadFlags: "flags?.toArray()", +}; + +//---------------Interactions------------// + +const ButtonStyleOptions = { + primary: 1, + secondary: 2, + success: 3, + danger: 4, + link: 5, +}; +const CacheOptions = { + guilds: "GuildManager", + messages: "MessageManager", + channels: "ChannelManager", + users: "UserManager", + applicationCommands: "ApplicationCommandManager", + applicationCommandPermissions: "ApplicationCommandPermissionManager", + permissionOverwrites: "PermissionOverwritesManager", + presences: "PersenceManager", + reactions: "ReactionManager", + reactionUsers: "ReactionUserManager", + roles: "RoleManager", + stageInstances: "StageInstanceManager", + threads: "ThreadManager", + threadMembers: "ThreadMemberManager", + voiceStates: "VoiceStateManager", + guildApplicationCommand: "GuildApplicationCommandManager", + guildBans: "GuildBanManager", + guildChannels: "GuildChannelManager", + guildEmojis: "GuildEmojiManager", + guildEmojiRoles: "GuildEmojiRoleManager", + guildInvites: "GuildInviteManager", + guildMembers: "GuildMemberManager", + guildMemberRoles: "GuildMemberRoleManager", + guildStickers: "GuildStickerManager", +}; +const SlashOptionTypes = { + subCommand: 1, + subGroup: 2, + string: 3, + integer: 4, + boolean: 5, + user: 6, + channel: 7, + role: 8, + mentionable: 9, + number: 10, +}; + +const Perms = { + createinvite: PermissionsBitField["Flags"].CreateInstantInvite, + kickmembers: PermissionsBitField["Flags"].KickMembers, + banmembers: PermissionsBitField["Flags"].BanMembers, + administrator: PermissionsBitField["Flags"].Administrator, + managechannels: PermissionsBitField["Flags"].ManageChannels, + manageguild: PermissionsBitField["Flags"].ManageGuild, + addreactions: PermissionsBitField["Flags"].AddReactions, + viewauditlog: PermissionsBitField["Flags"].ViewAuditLog, + priorityspeaker: PermissionsBitField["Flags"].PrioritySpeaker, + stream: PermissionsBitField["Flags"].Stream, + viewchannel: PermissionsBitField["Flags"].ViewChannel, + sendmessages: PermissionsBitField["Flags"].SendMessages, + sendttsmessages: PermissionsBitField["Flags"].SendTTSMessages, + managemessages: PermissionsBitField["Flags"].ManageMessages, + embedlinks: PermissionsBitField["Flags"].EmbedLinks, + attachfiles: PermissionsBitField["Flags"].AttachFiles, + readmessagehistory: PermissionsBitField["Flags"].ReadMessageHistory, + mentioneveryone: PermissionsBitField["Flags"].MentionEveryone, + useexternalemojis: PermissionsBitField["Flags"].UseExternalEmojis, + viewguildinsights: PermissionsBitField["Flags"].ViewGuildInsights, + connect: PermissionsBitField["Flags"].Connect, + speak: PermissionsBitField["Flags"].Speak, + mute: PermissionsBitField["Flags"].MuteMembers, + deafen: PermissionsBitField["Flags"].DeafenMembers, + movemembers: PermissionsBitField["Flags"].MoveMembers, + usevad: PermissionsBitField["Flags"].UseVAD, + changenickname: PermissionsBitField["Flags"].ChangeNickname, + managenicknames: PermissionsBitField["Flags"].ManageNicknames, + manageroles: PermissionsBitField["Flags"].ManageRoles, + manageemojisandstickers: PermissionsBitField["Flags"].ManageEmojisAndStickers, + moderatemembers: PermissionsBitField["Flags"].ModerateMembers, + managewebhooks: PermissionsBitField["Flags"].ManageWebhooks, + //voice + requesttospeak: PermissionsBitField["Flags"].RequestToSpeak, + managethreads: PermissionsBitField["Flags"].ManageThreads, + createpublicthreads: PermissionsBitField["Flags"].CreatePublicThreads, + createprivatethreads: PermissionsBitField["Flags"].CreatePrivateThreads, + useexternalsticker: PermissionsBitField["Flags"].UseExternalStickers, + sendmessagesinthreads: PermissionsBitField["Flags"].SendMessagesInThreads, + useembeddedactivities: PermissionsBitField["Flags"].UseEmbeddedActivities, + //guild + all: Object.keys(PermissionsBitField["Flags"]), +}; +const FormatPerms = {}; +for (const perm in PermissionsBitField.Flags) { + FormatPerms[perm.toLowerCase()] = perm; +} +const FormatOptions = (date) => { + const months = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ]; + //days + const days = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ]; + + ////Returning Data + return { + YY: date.getFullYear().toString().slice(-2), + + YYYY: date.getFullYear(), + + M: date.getMonth() + 1, + + MM: + (date.getMonth() + 1).toString().length === 1 + ? 0 + (date.getMonth() + 1).toString() + : (date.getMonth() + 1).toString(), + + MMM: months[date.getMonth()].slice(0, 3), + + MMMM: months[date.getMonth()], + + D: date.getDate(), + + DD: + date.getDate().toString().length === 1 + ? 0 + date.getDate().toString() + : date.getDate().toString(), + + d: date.getDay(), + + dd: days[date.getDay()].slice(0, 2), + + ddd: days[date.getDay()].slice(0, 3), + + dddd: days[date.getDay()], + + H: date.getHours(), + + HH: + date.getHours().toString().length === 1 + ? 0 + date.getHours().toString() + : date.getHours().toString(), + + h: Math.abs(date.getHours() - 12), + + hh: "hi", + }; +}; +const Characters = [ + "1234567890", + "qwertyuiopalskdjfhgznmxcbv", + "qwertyuiopalskdjfhgznmxcbv".toUpperCase(), +].join(""); + +const EventsToIntents = { + // Guild Messages + onMessage: "GuildMessages", + onMessageDelete: "GuildMessages", + onMessageUpdate: "GuildMessages", + onMessageDeleteBulk: "GuildMessages", + + // Guilds + onGuildJoin: "Guilds", + onGuildLeave: "Guilds", + onGuildUpdate: "Guilds", + onGuildUnavailable: "Guilds", + onRoleCreate: "Guilds", + onRoleUpdate: "Guilds", + onRoleDelete: "Guilds", + onChannelCreate: "Guilds", + onChannelUpdate: "Guilds", + onChannelDelete: "Guilds", + onChannelPinsUpdate: "Guilds", + onStageInstanceCreate: "Guilds", + onStageInstanceUpdate: "Guilds", + onStageInstanceDelete: "Guilds", + onThreadCreate: "Guilds", + onThreadUpdate: "Guilds", + onThreadDelete: "Guilds", + onThreadListSync: "Guilds", + onThreadMemberUpdate: "Guilds", + onThreadMembersUpdate: "Guilds", + + // Guild Members + onJoin: "GuildMembers", + onLeave: "GuildMembers", + onMemberUpdate: "GuildMembers", + onMemberAvailable: "GuildMembers", + onMembersChunk: "GuildMembers", + + // Guild Emojis + onEmojiCreate: "GuildEmojis", + onEmojiDelete: "GuildEmojis", + onEmojiUpdate: "GuildEmojis", + onStickerCreate: "GuildEmojis", + onStickerDelete: "GuildEmojis", + onStickerUpdate: "GuildEmojis", + + // Guild Bans + onBanAdd: "GuildBans", + onBanRemove: "GuildBans", + + // Guild Invites + onInviteCreate: "GuildInvites", + onInviteDelete: "GuildInvites", + + // Guild Message Reactions + onReactionAdd: "GuildMessageReactions", + onReactionRemove: "GuildMessageReactions", + onReactionRemoveAll: "GuildMessageReactions", + onReactionRemoveEmoji: "GuildMessageReactions", + + // Guild Voice States + onVoiceStateUpdate: "GuildVoiceStates", + + // Guild Presences + onPresenceUpdate: "GuildPresences", + + // Guild Message Typings + onTypingStart: "GuildMessageTypings", + + // Non-Intents + onInteractionCreate: "NonIntents", + onApplicationCommandPermissionsUpdate: "NonIntents", + onUserUpdate: "NonIntents", + + // Guild Webhooks + onWebhooksUpdate: "GuildWebhooks", + + //Automod + onAutoModerationActionExecution: "AutoModerationExecution", + onAutoModerationRuleDelete: "AutoModerationConfiguration", + onAutoModerationRuleCreate:"AutoModerationConfiguration", + onAutoModerationRuleUpdate: "AutoModerationConfiguration", + + // Custom + onVariableCreate: "Custom", + onVariableDelete: "Custom", + onVariableUpdate: "Custom", + onFunctionError: "Custom", +}; + +const EventsToDjsEvents = { + // Guilds + onGuildJoin: Events.GuildCreate, + onGuildLeave: Events.GuildDelete, + onGuildUpdate: Events.GuildUpdate, + onGuildUnavailable: Events.GuildUnavailable, + onRoleCreate: Events.GuildRoleCreate, + onRoleUpdate: Events.GuildRoleUpdate, + onRoleDelete: Events.GuildRoleDelete, + onChannelCreate: Events.ChannelCreate, + onChannelUpdate: Events.ChannelUpdate, + onChannelDelete: Events.ChannelDelete, + onChannelPinsUpdate: Events.ChannelPinsUpdate, + onStageInstanceCreate: Events.StageInstanceCreate, + onStageInstanceUpdate: Events.StageInstanceUpdate, + onStageInstanceDelete: Events.StageInstanceDelete, + onThreadCreate: Events.ThreadCreate, + onThreadUpdate: Events.ThreadUpdate, + onThreadDelete: Events.ThreadDelete, + onThreadListSync: Events.ThreadListSync, + onThreadMemberUpdate: Events.ThreadMemberUpdate, + onThreadMembersUpdate: Events.ThreadMembersUpdate, + + // Guild Members + onJoin: Events.GuildMemberAdd, + onLeave: Events.GuildMemberRemove, + onMemberUpdate: Events.GuildMemberUpdate, + onMemberAvailable: Events.GuildMemberAvailable, + onMembersChunk: Events.GuildMembersChunk, + + // Guild Emojis + onEmojiCreate: Events.GuildEmojiCreate, + onEmojiDelete: Events.GuildEmojiDelete, + onEmojiUpdate: Events.GuildEmojiUpdate, + onStickerCreate: Events.GuildStickerCreate, + onStickerDelete: Events.GuildStickerDelete, + onStickerUpdate: Events.GuildStickerUpdate, + + // Guild Bans + onBanAdd: Events.GuildBanAdd, + onBanRemove: Events.GuildBanRemove, + + // Guild Invites + onInviteCreate: Events.InviteCreate, + onInviteDelete: Events.InviteDelete, + + // Guild Messages + onMessage: Events.MessageCreate, + onMessageDelete: Events.MessageDelete, + onMessageUpdate: Events.MessageUpdate, + onMessageDeleteBulk: Events.MessageBulkDelete, + + // Guild Message Reactions + onReactionAdd: Events.MessageReactionAdd, + onReactionRemove: Events.MessageReactionRemove, + onReactionRemoveAll: Events.MessageReactionRemoveAll, + onReactionRemoveEmoji: Events.MessageReactionRemoveEmoji, + + // Guild Voice States + onVoiceStateUpdate: Events.VoiceStateUpdate, + + // Guild Presences + onPresenceUpdate: Events.PresenceUpdate, + + // Guild Message Typings + onTypingStart: Events.TypingStart, + + // Guild Webhooks + onWebhooksUpdate: Events.WebhooksUpdate, + + // Non-Intents + onInteractionCreate: Events.InteractionCreate, + onApplicationCommandPermissionsUpdate: Events.ApplicationCommandPermissionsUpdate, + onUserUpdate: Events.UserUpdate, + + //Automod + onAutoModerationActionExecution: Events.AutoModerationActionExecution, + onAutoModerationRuleDelete: Events.AutoModerationRuleDelete, + onAutoModerationRuleCreate: Events.AutoModerationRuleCreate, + onAutoModerationRuleUpdate: Events.AutoModerationRuleUpdate, + + // Custom + onVariableCreate: "variableCreate", + onVariableDelete: "variableDelete", + onVariableUpdate: "variableUpdate", + onFunctionError: "functionError", +}; + +const EventstoFile = { + onMessage: ["commands", "alwaysExecute", "nonPrefixed"], + onMessageDelete: "deleteMessage", + onMessageUpdate: "updateMessage", + onMessageDeleteBulk: "bulkDeleteMessage", + onChannelPinsUpdate: "channelPinsUpdate", + onTypingStart: "start", + + // Guild events + onGuildJoin: "guildJoin", + onGuildLeave: "guildLeave", + onGuildUpdate: "guildUpdate", + onGuildUnavailable: "guildUnavailable", + + // Role events + onRoleCreate: "roleCreate", + onRoleUpdate: "roleUpdate", + onRoleDelete: "roleDelete", + + // Channel events + onChannelCreate: "channelCreate", + onChannelUpdate: "channelUpdate", + onChannelDelete: "channelDelete", + + // Stage instance events + onStageInstanceCreate: "stageInstanceCreate", + onStageInstanceUpdate: "stageInstanceUpdate", + onStageInstanceDelete: "stageInstanceDelete", + + // Thread events + onThreadCreate: "threadCreate", + onThreadUpdate: "threadUpdate", + onThreadDelete: "threadDelete", + onThreadListSync: "threadListSync", + onThreadMemberUpdate: "threadMemberUpdate", + onThreadMembersUpdate: "threadMembersUpdate", + + // Member events + onJoin: "join", + onLeave: "leave", + onMemberUpdate: "update", + onMemberAvailable: "available", + onMembersChunk: "chunk", + + // Invite events + onInviteCreate: "inviteCreate", + onInviteDelete: "inviteDelete", + + // Emoji and sticker events + onEmojiCreate: "create", + onEmojiDelete: "delete", + onEmojiUpdate: "update", + onStickerCreate: "stickerCreate", + onStickerDelete: "stickerDelete", + onStickerUpdate: "stickerUpdate", + + // Ban events + onBanAdd: "add", + onBanRemove: "remove", + + // Reaction events + onReactionAdd: "add", + onReactionRemove: "remove", + onReactionRemoveAll: "removeAll", + onReactionRemoveEmoji: "removeEmoji", + + // Voice and presence events + onVoiceStateUpdate: "update", + onPresenceUpdate: "update", + + // Non-Intents + onInteractionCreate: "interaction", + onApplicationCommandPermissionsUpdate: "appCmdPermissionsUpdate", + onUserUpdate: "userUpdate", + + // Variable events + onVariableCreate: "varCreate", + onVariableDelete: "varDelete", + onVariableUpdate: "varUpdate", + + // Other events + onFunctionError: "functionError", + onWebhooksUpdate: "update", + + //Automod + onAutoModerationActionExecution: "autoModActionExecution", + onAutoModerationRuleDelete: "autoModCreate", + onAutoModerationRuleCreate: "autoModDelete", + onAutoModerationRuleUpdate: "autoModUpdate", + +}; + +const AllEvents = Object.keys(EventstoFile); + +const fetchInvitesOptions = { + enabled: "Boolean", + cacheInviters: "Boolean", +}; + +module.exports = { + FormatOptions, + fetchInvitesOptions, + ApplicationCmdOptions, + ActivityTypeAvailables, + DebugAvailables, + EventAvailables, + SI_SYMBOL, + ButtonStyleOptions, + ChannelOptions, + MemberOptions, + CacheOptions, + SlashOptionTypes, + Perms, + Characters, + IntentOptions, + FormatPerms, + EventsToIntents, + EventsToDjsEvents, + AllEvents, + EventstoFile, +}; diff --git a/src/utils/EventUtil.js b/src/utils/EventUtil.js new file mode 100644 index 000000000..46222264c --- /dev/null +++ b/src/utils/EventUtil.js @@ -0,0 +1,53 @@ +const BulkOptions = (d, sep) => { + return { + messages: d.data.bulk.map((x) => x.content).join(sep), + ids: d.data.bulk.map((x) => x.id).join(sep), + createdTimestamp: d.data.bulk.map((x) => x.createdTimestamp).join(sep), + createdAt: d.data.bulk.map((x) => x.createdAt).join(sep), + userIds: d.data.bulk.map((x) => x.author.id).join(sep), + usernames: d.data.bulk.map((x) => x.author.username).join(sep), + userTags: d.data.bulk.map((x) => x.author.tag).join(sep), + userMentions: d.data.bulk.map((x) => x.author.toString()).join(sep), + guildId: d.data.bulk.first().guild.id, + guildName: d.data.bulk.first().guild.name, + channelID: d.data.bulk.first().channel.id, + channelName: d.data.bulk.first().channel.name, + }; +}; + +const BulkData = (d, sep, option) => { + return BulkOptions(d, sep)[option]; +}; + +const PinData = (d) => { + const data = { + time: d.data.time, + channelID: d.data.channel.id, + channelName: d.data.channel.name, + channelMention: d.data.channel.toString(), + guildId: d.data.guild.id, + guildName: d.data.guild.name, + messageID: d.data.channel.messages.last()?.id, + messageContent: d.data.channel.messages.last()?.content, + }; +}; +const RateLimitOptions = [ + "timeout", + "limit", //.limit", + "method", // "Method used to this endpoint;.method", + "path", // "The path to the api endpoint that triggered the rate limit;.path", + "route", // "The route that triggered this event;.route", +]; +const WebhookUpdateOptions = [ + "id", //"id", + "name", // "name.deleteBrackets()", + "type", // "The type of the channel where the pins were updated;.type", + "guildid", // "The guild's ID of the channel where the webhook was updated;.guild.id", +]; + +module.exports = { + BulkData, + PinData, + RateLimitOptions, + WebhookUpdateOptions, +}; diff --git a/src/utils/InteractionConstants.js b/src/utils/InteractionConstants.js new file mode 100644 index 000000000..c10cca10f --- /dev/null +++ b/src/utils/InteractionConstants.js @@ -0,0 +1,30 @@ +const {ApplicationCommandType, InteractionType, ComponentType} = require("discord.js"); +const InteractionTypes = { + [InteractionType.Ping]: "ping", + [InteractionType.ApplicationCommand]: "slash", + [InteractionType.MessageComponent]: "component", + [InteractionType.ApplicationCommandAutocomplete]: "autocomplete", + [InteractionType.ModalSubmit]: "modal", +}; + +const MessageComponentTypes = { + [ComponentType.ActionRow]: "actionRow", + [ComponentType.Button]: "button", + [ComponentType.SelectMenu]: "selectMenu", + [ComponentType.StringSelect]: "selectMenu", + [ComponentType.ChannelSelect]: "selectMenu", + [ComponentType.RoleSelect]: "selectMenu", + [ComponentType.UserSelect]: "selectMenu", + [ComponentType.MentionableSelect]: "selectMenu", + [ComponentType.TextInput]: "modal", +}; +const SlashTypes = { + slash: ApplicationCommandType.ChatInput, + user: ApplicationCommandType.User, + message: ApplicationCommandType.Message, +}; +module.exports = { + InteractionTypes: InteractionTypes, + MessageComponentTypes: MessageComponentTypes, + SlashTypes, +}; diff --git a/src/utils/VoiceConstants.js b/src/utils/VoiceConstants.js new file mode 100644 index 000000000..9a73b1b04 --- /dev/null +++ b/src/utils/VoiceConstants.js @@ -0,0 +1,41 @@ +const VoiceOptions = { + client: ">", + ytdl: "YtdlOptions", + soundcloud: "SoundCloud Client ID", + cache: "", + other: "any", +}; +const VoiceSubscriptionDefaultOptions = { + paused: false, + loopQueue: false, + loopSong: false, + volume: 100, + leaveAfter: 60000, + leaveWhenEmpty: false, +}; +const States = { + queue: { + IDLE: "idle", + PLAYING: "playing", + PAUSED: "paused", + }, + loop: { + NONE: "none", + QUEUE: "queue", + SINGLE: "single", + }, +}; +const Events = { + ERROR: "musicError", + TRACK_START: "musicStart", + QUEUE_END: "queueEnd", + TRACK_END: "trackEnd", +}; +const TrackTypes = ["YouTube", "SoundCloud", "File"]; +module.exports = { + VoiceOptions: VoiceOptions, + VoiceSubscriptionDefaultOptions: VoiceSubscriptionDefaultOptions, + States, + Events: Events, + TrackTypes: TrackTypes, +}; diff --git a/package/Utils/helpers/checkCondition.js b/src/utils/helpers/checkCondition.js similarity index 52% rename from package/Utils/helpers/checkCondition.js rename to src/utils/helpers/checkCondition.js index cdf31ade7..7a1b05ccb 100644 --- a/package/Utils/helpers/checkCondition.js +++ b/src/utils/helpers/checkCondition.js @@ -1,126 +1,146 @@ class CheckCondition { static hasAnd(msg) { - return msg.includes("&&") + return msg.includes("&&"); } + static hasOr(msg) { - return msg.includes("||") + return msg.includes("||"); } + static hasEqual(msg) { - return msg.includes("==") + return msg.includes("=="); } + static hasNotEqual(msg) { - return msg.includes("!=") + return msg.includes("!="); } + static hasGreater(msg) { - return msg.includes(">") + return msg.includes(">"); } + static hasLesser(msg) { - return msg.includes("<") + return msg.includes("<"); } + static hasGE(msg) { - return msg.includes(">=") + return msg.includes(">="); } + static hasLE(msg) { - return msg.includes("<=") + return msg.includes("<="); } static solveEqual(msg) { let pass = true; const parts = msg.split("=="); - console.log(parts) + if (parts[0] !== parts[1]) pass = false; - return pass + return pass; } + static solveNotEqual(msg) { let pass = true; const parts = msg.split("!="); - if (parts[0] === parts[1]) pass = false; - return pass + if (parts[0].addBrackets() === parts[1].addBrackets()) pass = false; + return pass; } + static solveGreater(msg) { let pass = true; - const parts = msg.split(">"); + let parts = msg.split(">"); + parts = parts.every((x) => isNaN(x)) ? parts : parts.map((x) => Number(x)); if (parts[0] <= parts[1]) pass = false; - return pass + return pass; } + static solveLesser(msg) { let pass = true; - const parts = msg.split("<"); + let parts = msg.split("<"); + parts = parts.every((x) => isNaN(x)) ? parts : parts.map((x) => Number(x)); if (parts[0] >= parts[1]) pass = false; - return pass + return pass; } + static solveLE(msg) { let pass = true; - const parts = msg.split("<="); + let parts = msg.split("<="); + parts = parts.every((x) => isNaN(x)) ? parts : parts.map((x) => Number(x)); + if (parts[0] > parts[1]) pass = false; - return pass + return pass; } + static solveGE(msg) { let pass = true; - const parts = msg.split(">="); + let parts = msg.split(">="); + parts = parts.every((x) => isNaN(x)) ? parts : parts.map((x) => Number(x)); + if (parts[0] < parts[1]) pass = false; - return pass + return pass; } static solveAnd(msg) { const parts = msg.split("&&"); - // console.log(parts) const final = []; for (let part of parts) { - const has = part.includes(")") ? ")" : "" - part = part.split(")")[0] - if (this.hasOr(part)) final.push(this.solveOr(part) + has) - else if (this.hasEqual(part)) final.push(this.solveEqual(part) + has) - else if (this.hasNotEqual(part)) final.push(this.solveNotEqual(part) + has) - else if (this.hasGreater(part)) final.push(this.solveGreater(part) + has) - else if (this.hasLesser(part)) final.push(this.solveLesser(part) + has) - else if (this.hasGE(part)) final.push(this.solveGE(part) + has) - else if (this.hasLE(part)) final.push(this.solveLE(part) + has) + const has = part.includes(")") ? ")" : ""; + part = part.split(")")[0]; + if (this.hasOr(part)) final.push(this.solveOr(part) + has); + else if (this.hasEqual(part)) final.push(this.solveEqual(part) + has); + else if (this.hasNotEqual(part)) + final.push(this.solveNotEqual(part) + has); + else if (this.hasGE(part)) final.push(this.solveGE(part) + has); + else if (this.hasLE(part)) final.push(this.solveLE(part) + has); + else if (this.hasGreater(part)) final.push(this.solveGreater(part) + has); + else if (this.hasLesser(part)) final.push(this.solveLesser(part) + has); else if (part.trim() === "") final.push(part); } - console.log("andArray:" + final) - console.log("andpart:" + final.join("&&")) - return final.join("&&") + return final.join("&&"); } + static solveOr(msg) { const parts = msg.split("||"); const final = []; for (let part of parts) { - const has = part.includes(")") ? ")" : "" - part = part.split(")")[0] - if (this.hasEqual(part)) final.push(this.solveEqual(part) + has) - else if (this.hasNotEqual(part)) final.push(this.solveNotEqual(part) + has) - else if (this.hasGreater(part)) final.push(this.solveGreater(part) + has) - else if (this.hasLesser(part)) final.push(this.solveLesser(part) + has) - - else if (this.hasGE(part)) final.push(this.solveGE(part) + has) - else if (this.hasLE(part)) final.push(this.solveLE(part) + has) - else if (part.trim() === "") final.push(part) + const has = part.includes(")") ? ")" : ""; + part = part.split(")")[0]; + if (this.hasEqual(part)) final.push(this.solveEqual(part) + has); + else if (this.hasNotEqual(part)) + final.push(this.solveNotEqual(part) + has); + else if (this.hasGE(part)) final.push(this.solveGE(part) + has); + else if (this.hasLE(part)) final.push(this.solveLE(part) + has); + else if (this.hasGreater(part)) final.push(this.solveGreater(part) + has); + else if (this.hasLesser(part)) final.push(this.solveLesser(part) + has); + else if (part.trim() === "") final.push(part); } - return final.join("||") + return final.join("||"); } + static solve(msg) { - const parts = msg.split("(") - const final = [] - console.log(parts) + const parts = msg.split("("); + const final = []; + for (const part of parts) { if (part.trim() === "") { - final.push("") + final.push(""); continue; } - let solve = this.solveAnd(part) - console.log("solve:" + solve) + let solve = this.solveAnd(part); - final.push(solve) + final.push(solve); } - console.log({ final }) - let result = final.join("(") - if (result.split("(").length !== result.split(")").length) result = result + ")".repeat(result.split("(").length - result.split(")").length) - return result - } + let result = final.join("("); + if (result.split("(").length !== result.split(")").length) + result = + result + + ")".repeat(result.split("(").length - result.split(")").length); + return result; + } } + module.exports = { - CheckCondition -} \ No newline at end of file + CheckCondition, +}; diff --git a/src/utils/helpers/customParser.js b/src/utils/helpers/customParser.js new file mode 100644 index 000000000..d81b4565a --- /dev/null +++ b/src/utils/helpers/customParser.js @@ -0,0 +1,181 @@ +class Time { + /** + * @param {number} time + * @return {{ + * object : { + * years: number, + * months: number, + * weeks:number, + * days:number, + * hours:number, + * minutes: number, + * seconds:number, + * ms:number + * }, + * humanize():string, + * toString():string + * }} + */ + static format(time) { + const date = (ms) => { + const res = Math.trunc(Math.abs(time) / ms); + time -= res * ms; + return res; + }; + const data = { + object: { + years: date(31536000000), + months: date(2628746000), + weeks: date(604800000), + days: date(86400000), + hours: date(3600000), + minutes: date(60000), + seconds: date(1000), + ms: date(1), + }, + humanize: undefined, + toString: undefined, + }; + data.humanize = () => { + const string = []; + Object.entries(data.object) + .slice(0, -1) + .forEach((x) => { + if (!x[1]) { + } else { + if (["months", "ms"].includes(x[0])) { + string.push(`${x[1]}${x[0].slice(0, 3)}`); + } else { + string.push(`${x[1]}${x[0].slice(0, 1)}`); + } + } + }); + return string.join(" "); + }; + data.toString = () => this.parse(data.humanize()).format; + return data; + } + + /** + * @param {string | number } time + * @returns {{ + * ms : number; + * format : string; + * }} + */ + static parse(time) { + if (!["string", "number"].includes(typeof time)) + throw TypeError("'time' must be a string or number"); + if (typeof time === "number") + return { + ms: time, + format: this.format(time).toString(), + }; + else { + const Hash = new Map(); + + time.split(" ").forEach((x) => { + if (x.endsWith("y")) + Hash.set("y", { + format: pluralize(Number(x.split("y")[0]), "year"), + ms: Number(x.split("y")[0]) * 31536000000, + order: 1, + }); + if (x.endsWith("mon") || x.endsWith("M")) + Hash.set("mon", { + format: pluralize(Number(x.split("mon")[0].split("M")[0]), "month"), + ms: Number(x.split("mon")[0].split("M")[0]) * 2628002880, + order: 2, + }); + if (x.endsWith("w")) + Hash.set("w", { + format: pluralize(Number(x.split("w")[0]), "week"), + ms: Number(x.split("w")[0]) * 604800000, + order: 3, + }); + if (x.endsWith("d")) + Hash.set("d", { + format: pluralize(Number(x.split("d")[0]), "day"), + ms: Number(x.split("d")[0]) * 86400000, + order: 4, + }); + if (x.endsWith("h") || x.endsWith("hr")) + Hash.set("h", { + format: pluralize(Number(x.split("h")[0].split("hr")[0]), "hour"), + ms: Number(x.split("hr")[0].split("h")[0]) * 3600000, + order: 5, + }); + if (x.endsWith("min") || x.endsWith("m")) + Hash.set("min", { + format: pluralize( + Number(x.split("min")[0].split("m")[0]), + "minute", + ), + ms: Number(x.split("min")[0].split("m")[0]) * 60000, + order: 6, + }); + if (x.endsWith("s") && !x.endsWith("ms")) + Hash.set("s", { + format: pluralize(Number(x.split("s")[0]), "second"), + ms: Number(x.split("s")[0]) * 1000, + order: 7, + }); + if (x.endsWith("ms")) + Hash.set("ms", { + ms: Number(x.split("ms")[0]), + order: 8, + }); + }); + const data = [...Hash.values()].sort(compare); + + const ms = data.map((x) => x.ms).reduce((a, b) => a + b, 0); + const format = data + .filter((x) => x.format) + .map((x) => x.format) + .join(", "); + + return { + ms, + format, + }; + } + } + + /** + * @param {number} time + */ + static digital(time) { + let seconds = Math.trunc(time / 1000); + let res = []; + let i = 0; + const a = [3600, 60, 60]; + while (i < 2) { + const num = Math.trunc(seconds / a[i]).toString(); + if (num === 0 && i === 0) { + } else { + res.push(num.length === 1 ? `0${num}` : num); + } + seconds = seconds % a[i]; + i++; + } + res.push(seconds.toString().length === 1 ? `0${seconds}` : seconds); + return res.join(":"); + } +} + +module.exports = { + Time, +}; + +function compare(a, b) { + if (a.order < b.order) { + return -1; + } + if (a.order > b.order) { + return 1; + } + return 0; +} + +const pluralize = (num, txt, suffix = "s") => + `${num} ${txt}${num !== 1 ? suffix : ""}`; \ No newline at end of file diff --git a/src/utils/helpers/functions.js b/src/utils/helpers/functions.js new file mode 100644 index 000000000..15f6d8bb3 --- /dev/null +++ b/src/utils/helpers/functions.js @@ -0,0 +1,370 @@ +const { SI_SYMBOL, FormatOptions } = require("../Constants.js"); +const { setTimeout } = require("timers/promises"); +const { + CategoryChannel, + GuildEmoji, + ReactionEmoji, + VoiceState, + Role, +} = require("discord.js"); +const { CheckCondition } = require("./checkCondition.js"); + +function PartToHex(d) { + const data = d.toString(16); + return data.length === 1 ? "0" + data : data; +} + +function RBGtoHex(r, b, g) { + return "#" + PartToHex(r) + PartToHex(b) + PartToHex(g); +} + +module.exports = { + /** + * @param {number} number + * @param {number} decimal + */ + abbreviate(number, decimal) { + const tier = Math.floor(Math.log10(Math.abs(number || 1)) / 3); + if (tier === 0) return number; + const suffix = SI_SYMBOL[tier]; + const scale = Math.pow(10, tier * 3); + const scaled = number / scale; + return scaled.toFixed(decimal) + suffix; + }, + /** + * @param {number} time + */ + async wait(time) { + await setTimeout(time); + }, + /** + * @param {CategoryChannel} category + */ + categoryChannelsOption(category) { + const cat = category.children.cache; + return { + names: cat.map((x) => x.name), + ids: cat.map((x) => x.id), + mentions: cat.map((x) => x.toString()), + count: cat.size, + json: JSON.stringify({ + names: cat.map((x) => x.name), + ids: cat.map((x) => x.id), + mentions: cat.map((x) => x.toString()), + count: cat.size, + }), + }; + }, + Channel(channel) { + const data = Object.create(channel); + Object.assign(data, channel); + delete data.messages; + delete data.permissionOverwrites; + data.threads = channel.threads?.cache.size; + data.parent = channel.parent?.name; + data.mention = channel.toString(); + + return data; + }, + /** + * @param {import('../../classes/AoiClient.js')} client + */ + Client(client) { + const data = { + prefix: Array.isArray(client.prefix) + ? client.prefix.join(" , ") + : client.prefix, + variables: { + name: client.variableManager.vars.join(" , "), + json: client.variableManager.toJSON(), + object: client.variableManager.cache.object(), + }, + user: Object.assign(Object.create(client.user), client.user), + application: Object.assign( + Object.create(client.application), + client.application, + ), + }; + //user property modification + data.user.avatarUrl = client.user.displayAvatarURL(); + data.user.displayAvatarURL = undefined; + data.user.avatarURL = undefined; + data.user.toJSON = undefined; + data.user.flags = client.user.flags?.toArray().length + ? client.user.flags?.toArray().join(" , ") + : "none"; + data.presence = client.status; + delete data.user.dmChannel; + delete data.user.client; + //application data modification + data.application.iconURL = client.application.iconURL(); + data.application.flags = client.application.flags + ?.toArray() + .join(" , "); + data.application.commands = undefined; + data.application.client = undefined; + data.json = JSON.stringify(Object.assign({}, data), null, 2); + return data; + }, + /** + * @param {GuildEmoji | ReactionEmoji } emoji + */ + Emoji(emoji) { + const data = Object.assign({}, emoji); + //emoji data modification + data.setName = undefined; + data.delete = undefined; + data.edit = undefined; + data.equals = undefined; + data.fetchAuthor = undefined; + + data.string = emoji.toString(); + data.json = JSON.stringify(data, null, 2); + data.guild = emoji.guild?.id; + data.roles = emoji.roles?.cache.map((x) => x.id).join(" , "); + data.url = emoji.url; + data.toJSON = undefined; + return data; + }, + EmbedData(embed, embeds) { + const data = { + authorname: embed.author?.name, + authoricon: embed.author?.iconURL, + authorurl: embed.author?.url, + image: embed.image?.url, + thumbnail: embed.thumbnail?.url, + color: embed.color, + footertext: embed.footer?.text, + footericon: embed.footer?.iconURL, + description: embed.description, + title: embed.title, + url: embed?.url, + }; + + embed.fields.forEach((x, y) => (data[`field${y + 1}`] = x)); + + data.json = JSON.stringify(data, null, 2); + data.rawjson = embed.toJSON(); + data.allEmbeds = JSON.stringify(embeds, null, 2); + + return data; + }, + Guild(guild) { + const data = Object.assign({}, guild); + // modifying data + data.afkChannel = guild.afkChannel?.name; + data.bannerURL = guild.bannerURL(); + return data; + }, + Message(msg) { + const data = Object.assign({}, msg); + data.activityPartyId = msg.activity?.partyId; + data.activityType = msg.activity?.type; + data.activity = undefined; + + data.attachments = msg.attachments.map((x) => x.url); + + data.authorName = msg.author.username; + data.authorId = msg.author.id; + data.authorIcon = msg.author.avatarURL({ size: 4096, dynamic: true }); + data.authorMention = msg.author.toString(); + data.author = undefined; + + data.channelName = msg.channel.name; + data.channelType = msg.channel.type; + data.channelMention = msg.channel.toString(); + data.channel = undefined; + + data.client = undefined; + + data.components = JSON.stringify(msg.components, null, 2); + + data.cleanContent = msg.cleanContent; + data.createdAt = msg.createdAt; + + data.deleted = msg.deleted; + data.deletable = msg.deletable; + + data.crosspostable = msg.crosspostable; + data.editable = msg.editable; + + data.editedAt = msg.editedAt; + data.embeds = JSON.stringify(msg.embeds, null, 2); + + data.groupActivityApplication = undefined; + + data.guildname = msg.guild.name; + data.guildicon = msg.guild.iconURL({ size: 4096, dynamic: true }); + data.guild = undefined; + + data.hasThread = msg.hasThread; + data.member = undefined; + + data.pinnable = msg.pinnable; + + return data; + }, + /** + * @param {Role} role + */ + Role(role) { + const data = Object.assign({}, role); + //modifying data + data.createdAt = role.createdAt; + data.createdTimestamp = role.createdTimestamp; + + data.hexColor = role.hexColor; + + data.members = role.members.map((x) => x.id).join(" , "); + data.memberCount = role.members.size; + data.managed = role.managed; + data.position = role.position; + data.permissions = role.permissions.toArray().join(" , "); + data.tagsbotid = role.tags?.botId; + data.tagsintegrationId = role.tags?.integrationId; + data.tagspremiumSubscriberRole = role.tags?.premiumSubscriberRole; + + return data; + }, + + /** + * @param {VoiceState} state + */ + VoiceState(state) { + const data = Object.assign({}, state); + + data.deaf = state.deaf; + data.mute = state.mute; + data.guild = undefined; + data.guildId = state.guild.id; + + return data; + }, + User(user) { + const data = Object.assign({}, user); + + data.accentColor = user.accentColor; + data.banner = user.banner; + data.bannerURL = user.bannerURL(); + data.createdAt = user.createdAt; + data.createdTimestamp = user.createdTimestamp; + data.avatarURL = user.avatarURL({ size: 4096, dynamic: true }); + data.flags = user.flags?.toArray().join(" , "); + data.partial = user.partial; + data.tag = user.tag; + data.dmChannel = user.dmChannel?.id; + + return data; + }, + Presence(presence) { + const data = Object.assign({}, presence || { status: "offline" }); + + data.activities = JSON.stringify(presence?.activities, null, 2); + data.webStatus = presence?.clientStatus?.web; + data.desktopStatus = presence?.clientStatus.desktop; + data.mobileStatus = presence?.clientStatus.mobile; + data.guildId = presence?.guild.id; + + data.authorId = presence?.authorId; + data.user = undefined; + data.guild = undefined; + + return data; + }, + + FormatDate(date, format) { + ////Map for Storing Each Format + const FormatMap = new Map(); + + ////creating Array of format + format = format.split(" "); + + ////finding and setting indexes per format + // Map -> Map> + format.forEach((x, y) => { + if (!FormatMap.has(x)) FormatMap.set(x, [y]); + else { + const arr = FormatMap.get(x); + arr.push(y); + FormatMap.set(x, arr); + } + }); + + ////basic defining + let i = format.length - 1; + }, + Timeout(d, name, duration, timeoutData, pulse) { + timeoutData.__duration__ = Date.now() + duration; + timeoutData.__timeoutName__ = name; + timeoutData.__pulseEvery__ = pulse; + timeoutData.__id__ = Math.floor(Math.random() * 999999); + + d.client.db.set( + d.client.db.tables[0], + "setTimeout", + timeoutData.__id__, + timeoutData, + ); + + if (!pulse) { + require("../../handler/Custom/timeout.js")( + d, + name, + duration, + timeoutData, + false, + ); + } else { + require("../../handler/Custom/timeoutPulse.js")( + d, + name, + duration, + pulse, + timeoutData, + false, + ); + } + return timeoutData.__id__; + }, + CreateObjectAST(parser) { + let left = 0, + right = 0; + let ans = []; + let part = ""; + let i = 0; + while (i < parser.length) { + if (parser[0] !== "{") { + while ( parser[ i ] !== "{" ) + { + if(i >= parser.length) break; + i++; + } + } + + if(i >= parser.length) { + if(part.length) ans.push(part); + break; + } + while (left === 0 || right < left) { + part += parser[i]; + if (parser[i] === "{") left++; + else if (parser[i] === "}") right++; + i += 1; + if (i === parser.length) break; + if (left === right) break; + } + if(left === right && left !== 0) { + ans.push(part); + right = 0; + left = 0; + part = ""; + } else { + part += parser[i]; + } + } + return ans; + }, +}; + +module.exports.RBGtoHex = RBGtoHex; +module.exports.PartToHex = PartToHex; diff --git a/src/utils/helpers/if.js b/src/utils/helpers/if.js new file mode 100644 index 000000000..e04d2a44f --- /dev/null +++ b/src/utils/helpers/if.js @@ -0,0 +1,140 @@ +const IF = async (d) => { + const interpreter = require("../../core/interpreter.js"); + let code = d.code; + let message = d.message; + let client = d.client; + let args = d.args; + const Data = d.data.data; + + if (code.toLowerCase().includes("$if[")) { + for (let statement of code + .split(/\$if\[/gi) + .slice(1) + .reverse()) { + const r = code.toLowerCase().split("$if[").length - 1; + + if (!code.toLowerCase().includes("$endif")) + return message.channel.send( + `\`AoiError: $if: Invalid Usage: missing $endif\``, + ); + + const everything = code.split(/\$if\[/gi)[r].split(/\$endif/gi)[0]; + + statement = code.split(/\$if\[/gi)[r].split(/\$endif/gi)[0]; + + let condition = statement.split("\n")[0].trim(); + + condition = condition.slice(0, condition.length - 1); + + const pass = + ( + await interpreter( + client, + message, + args, + { + code: `$checkCondition[${condition}]`, + name: "check", + }, + undefined, + true, + undefined, + Data, + ) + )?.code === "true"; + + const elseIfAction = statement.toLowerCase().includes("$elseif"); + + const elseIfs = {}; + + if (elseIfAction) { + for (const data of statement.split(/\$elseif\[/gi).slice(1)) { + if (!data.toLowerCase().includes("$endelseif")) + return message.channel.send( + `\`AoiError: $elseIf: Invalid Usage: missing $endelseIf\``, + ); + + const inside = data.split(/\$endelseIf/gi)[0]; + + let CONDITION = inside.split("\n")[0].trim(); + + CONDITION = CONDITION.slice(0, CONDITION.length - 1); + + elseIfs[CONDITION] = inside.split("\n").slice(1).join("\n"); + + function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\\n]/g, "\\$&"); + } + + statement = statement.replace( + new RegExp( + `\\$elseif\\[${escapeRegExp(inside)}\\$endelseif`, + "mi", + ), + "", + ); + } + } + + const elseAction = statement.toLowerCase().includes("$else"); + + const ifCode = elseAction + ? statement + .split("\n") + .slice(1) + .join("\n") + .split(/\$else/gi)[0] + : statement + .split("\n") + .slice(1) + .join("\n") + .split(/\$endif/gi)[0]; + + const elseCode = elseAction + ? statement.split(/\$else/gi)[1].split(/\$endif/gi)[0] + : ""; + + let passes = false; + + let lastCode; + + if (elseIfAction) { + for (const data of Object.entries(elseIfs)) { + if (!passes) { + const response = + ( + await interpreter( + client, + message, + args, + { + code: `$checkCondition[${data[0]}]`, + name: "check", + }, + undefined, + true, + undefined, + Data, + ) + )?.code === "true"; + + if (response) { + passes = true; + lastCode = data[1]; + } + } + } + } + + code = code + .replace(/\$if\[/gi, "$if[") + .replace(/\$endif/gi, "$endif"); + code = code.replaceLast( + `$if[${everything}$endif`, + pass ? ifCode : passes ? lastCode : elseCode, + ); + } + } + return { code }; +}; +module.exports = IF; diff --git a/src/utils/helpers/mustEscape.js b/src/utils/helpers/mustEscape.js new file mode 100644 index 000000000..28996d92e --- /dev/null +++ b/src/utils/helpers/mustEscape.js @@ -0,0 +1,19 @@ +module.exports = { + mustEscape: (msg) => { + return msg + .split("\\[") + .join("#RIGHT#") + .replace(/\\]/g, "#LEFT#") + .replace(/\\;/g, "#SEMI#") + .replace(/\\:/g, "#COLON#") + .replace(/\\$/g, "#CHAR#") + .replace(/\\>/g, "#RIGHT_CLICK#") + .replace(/\\= 0) { + return this.substring(0, index) + replace + this.substring(index + find.length); + } + + return this.toString(); +}; + +String.prototype.deleteBrackets = function () { + return this.replace(/\[/g, "#RIGHT#") + .replace(/]/g, "#LEFT#") + .replace(/;/g, "#SEMI#") + .replace(/:/g, "#COLON#") + .replace(/\$/g, "#CHAR#") + .replace(/>/g, "#RIGHT_CLICK#") + .replace(/") + .replace(/#LEFT_CLICK#/g, "<") + .replace(/#EQUAL#/g, "=") + .replace(/#RIGHT_BRACKET#/g, "{") + .replace(/#LEFT_BRACKET#/g, "}") + .replace(/#COMMA#/g, ",") + .replace(/#LB#/g, "(") + .replace(/#RB#/g, ")") + .replace(/#AND#/g, "&&") + .replace(/#OR#/g, "||"); +}; + +Array.prototype.goof = function (sep = "_") { + return this.map((x) => + x + .split(sep) + .map((w) => + w.toLowerCase().replace(w[0].toLowerCase(), w[0].toUpperCase()) + ) + .join(" ") + ).join(", "); +}; + +async function walk(path) { + const something = await fs.promises + .readdir(path, { withFileTypes: true }) + .then((f) => { + return f.map((d) => { + d.name = `${path}/${d.name}`; + return d; + }); + }); + + const files = something.filter((d) => d.isFile()); + const dirs = something.filter((d) => d.isDirectory()); + + for (const d of dirs) { + const items = await walk(d.name); + files.push(...items); + } + + return files; +} + +module.exports = { + walk, + searchIndexes, +};