From 9633cbf87c358310e77e9ec9e93e63eddf092ed8 Mon Sep 17 00:00:00 2001 From: notunderctrl Date: Thu, 23 Feb 2023 16:16:33 +0300 Subject: [PATCH] Complete autoRole --- 15 - AutoRole/.env.example | 2 + 15 - AutoRole/config.json | 5 + 15 - AutoRole/package-lock.json | 917 ++++++++++++++++++ 15 - AutoRole/package.json | 20 + .../src/commands/admin/autorole-configure.js | 56 ++ .../src/commands/admin/autorole-disable.js | 29 + 15 - AutoRole/src/commands/economy/daily.js | 62 ++ 15 - AutoRole/src/commands/economy/level.js | 82 ++ 15 - AutoRole/src/commands/misc/ping.js | 16 + 15 - AutoRole/src/commands/moderation/ban.js | 82 ++ 15 - AutoRole/src/commands/moderation/kick.js | 82 ++ .../src/commands/moderation/timeout.js | 94 ++ .../src/events/guildMemberAdd/autoRole.js | 21 + .../interactionCreate/handleCommands.js | 66 ++ .../src/events/messageCreate/giveUserXp.js | 68 ++ .../src/events/ready/01registerCommands.js | 56 ++ 15 - AutoRole/src/events/ready/consoleLog.js | 3 + 15 - AutoRole/src/handlers/eventHandler.js | 20 + 15 - AutoRole/src/index.js | 28 + 15 - AutoRole/src/models/AutoRole.js | 15 + 15 - AutoRole/src/models/Level.js | 22 + 15 - AutoRole/src/models/User.js | 22 + .../src/utils/areCommandsDifferent.js | 55 ++ 15 - AutoRole/src/utils/calculateLevelXp.js | 1 + 15 - AutoRole/src/utils/getAllFiles.js | 24 + .../src/utils/getApplicationCommands.js | 13 + 15 - AutoRole/src/utils/getLocalCommands.js | 27 + 27 files changed, 1888 insertions(+) create mode 100644 15 - AutoRole/.env.example create mode 100644 15 - AutoRole/config.json create mode 100644 15 - AutoRole/package-lock.json create mode 100644 15 - AutoRole/package.json create mode 100644 15 - AutoRole/src/commands/admin/autorole-configure.js create mode 100644 15 - AutoRole/src/commands/admin/autorole-disable.js create mode 100644 15 - AutoRole/src/commands/economy/daily.js create mode 100644 15 - AutoRole/src/commands/economy/level.js create mode 100644 15 - AutoRole/src/commands/misc/ping.js create mode 100644 15 - AutoRole/src/commands/moderation/ban.js create mode 100644 15 - AutoRole/src/commands/moderation/kick.js create mode 100644 15 - AutoRole/src/commands/moderation/timeout.js create mode 100644 15 - AutoRole/src/events/guildMemberAdd/autoRole.js create mode 100644 15 - AutoRole/src/events/interactionCreate/handleCommands.js create mode 100644 15 - AutoRole/src/events/messageCreate/giveUserXp.js create mode 100644 15 - AutoRole/src/events/ready/01registerCommands.js create mode 100644 15 - AutoRole/src/events/ready/consoleLog.js create mode 100644 15 - AutoRole/src/handlers/eventHandler.js create mode 100644 15 - AutoRole/src/index.js create mode 100644 15 - AutoRole/src/models/AutoRole.js create mode 100644 15 - AutoRole/src/models/Level.js create mode 100644 15 - AutoRole/src/models/User.js create mode 100644 15 - AutoRole/src/utils/areCommandsDifferent.js create mode 100644 15 - AutoRole/src/utils/calculateLevelXp.js create mode 100644 15 - AutoRole/src/utils/getAllFiles.js create mode 100644 15 - AutoRole/src/utils/getApplicationCommands.js create mode 100644 15 - AutoRole/src/utils/getLocalCommands.js diff --git a/15 - AutoRole/.env.example b/15 - AutoRole/.env.example new file mode 100644 index 0000000..b472127 --- /dev/null +++ b/15 - AutoRole/.env.example @@ -0,0 +1,2 @@ +TOKEN = YOUR_BOT_TOKEN +MONGODB_URI = YOUR_MONGO_URI \ No newline at end of file diff --git a/15 - AutoRole/config.json b/15 - AutoRole/config.json new file mode 100644 index 0000000..aec0fb4 --- /dev/null +++ b/15 - AutoRole/config.json @@ -0,0 +1,5 @@ +{ + "testServer": "1049345075366334617", + "clientId": "1051228977068519565", + "devs": ["1049343381903515778"] +} diff --git a/15 - AutoRole/package-lock.json b/15 - AutoRole/package-lock.json new file mode 100644 index 0000000..d33134e --- /dev/null +++ b/15 - AutoRole/package-lock.json @@ -0,0 +1,917 @@ +{ + "name": "discord-bot", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "discord-bot", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "canvacord": "^5.4.8", + "discord.js": "^14.7.1", + "dotenv": "^16.0.3", + "mongoose": "^6.9.0", + "ms": "^2.1.3", + "pretty-ms": "^8.0.0" + } + }, + "node_modules/@discordjs/builders": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.4.0.tgz", + "integrity": "sha512-nEeTCheTTDw5kO93faM1j8ZJPonAX86qpq/QVoznnSa8WWcCgJpjlu6GylfINTDW6o7zZY0my2SYdxx2mfNwGA==", + "dependencies": { + "@discordjs/util": "^0.1.0", + "@sapphire/shapeshift": "^3.7.1", + "discord-api-types": "^0.37.20", + "fast-deep-equal": "^3.1.3", + "ts-mixer": "^6.0.2", + "tslib": "^2.4.1" + }, + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/@discordjs/collection": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-1.3.0.tgz", + "integrity": "sha512-ylt2NyZ77bJbRij4h9u/wVy7qYw/aDqQLWnadjvDqW/WoWCxrsX6M3CIw9GVP5xcGCDxsrKj5e0r5evuFYwrKg==", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/@discordjs/rest": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-1.5.0.tgz", + "integrity": "sha512-lXgNFqHnbmzp5u81W0+frdXN6Etf4EUi8FAPcWpSykKd8hmlWh1xy6BmE0bsJypU1pxohaA8lQCgp70NUI3uzA==", + "dependencies": { + "@discordjs/collection": "^1.3.0", + "@discordjs/util": "^0.1.0", + "@sapphire/async-queue": "^1.5.0", + "@sapphire/snowflake": "^3.2.2", + "discord-api-types": "^0.37.23", + "file-type": "^18.0.0", + "tslib": "^2.4.1", + "undici": "^5.13.0" + }, + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/@discordjs/util": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@discordjs/util/-/util-0.1.0.tgz", + "integrity": "sha512-e7d+PaTLVQav6rOc2tojh2y6FE8S7REkqLldq1XF4soCx74XB/DIjbVbVLtBemf0nLW77ntz0v+o5DytKwFNLQ==", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/@napi-rs/canvas": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-0.1.34.tgz", + "integrity": "sha512-Nw719Ne/523nRIsM3ZHRfZFHKLE7Hy8K0ChQZNvOP4GebLBmeoySzEIaxxG4xja+jDGwhkbh43raMK7No9kx7A==", + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@napi-rs/canvas-android-arm64": "0.1.34", + "@napi-rs/canvas-darwin-arm64": "0.1.34", + "@napi-rs/canvas-darwin-x64": "0.1.34", + "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.34", + "@napi-rs/canvas-linux-arm64-gnu": "0.1.34", + "@napi-rs/canvas-linux-arm64-musl": "0.1.34", + "@napi-rs/canvas-linux-x64-gnu": "0.1.34", + "@napi-rs/canvas-linux-x64-musl": "0.1.34", + "@napi-rs/canvas-win32-x64-msvc": "0.1.34" + } + }, + "node_modules/@napi-rs/canvas-android-arm64": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-0.1.34.tgz", + "integrity": "sha512-oj6zoaLG3Re3EpKSaXy6rkYpw+dCiqFSpl2JL/uWZ5F2oB3A9KKL3wydQljgg8D40I6wEFAyUpbYgTU4q14quQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-darwin-arm64": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-0.1.34.tgz", + "integrity": "sha512-P8oEeRHJ5z2TYg+rHtEk5lxdODtvYKwfs3v8Uy5EuQJ7PIoEFjUfQnnntuZ1LwbDz0TfuaJz0aRH9TjMNnBKBw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-darwin-x64": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-0.1.34.tgz", + "integrity": "sha512-TptzmEvPbQtZQfpdVqXzvvyy0gRIxFSeaavUJEA0wstuXmMEEL3Ge6rk/lX38ixrwC6rTB3V6e2hziRd1UZ9Pg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-arm-gnueabihf": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-0.1.34.tgz", + "integrity": "sha512-w54DIqvdxc+cIP3y0esC26G5BKICE4nvo6J0u/q9zZruvnLkInKariAOMTN0gmDjZjHY3a5lTro4CTg0Odoteg==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-gnu": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-0.1.34.tgz", + "integrity": "sha512-N008ta7zer8v3cky4YLT9IcOmVmL7PyJ2P7L65GeICfOkczOD9THdgcbPWa6NNbHiDSHPSsXVRRrb5uAIDNbZQ==", + "cpu": [ + "arm64" + ], + "hasInstallScript": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-musl": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-0.1.34.tgz", + "integrity": "sha512-/axLA9UrNri93JqlbQaZ4Md2zUMwWxSHnTnlOnGBpDrAvFHrZ8VgYvQU6SbaiAuC7NvqADFgZ+lINo2JCMl1tw==", + "cpu": [ + "arm64" + ], + "hasInstallScript": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-gnu": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-0.1.34.tgz", + "integrity": "sha512-YEYdWWmAdZt/02t22DFlqFxANmmEI6/Vyqoz+7+Y6s/6nAohQ/S9qRjeYtMYW4J6qxSpoVhOm8NkZ7niv4OFJA==", + "cpu": [ + "x64" + ], + "hasInstallScript": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-musl": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-0.1.34.tgz", + "integrity": "sha512-K4Nk/BL6TiLkMU8QAH45j/YAn7B4//cp6FvivGJBr7/unEm+nv8nSFX/ueBV9G6/lyOBKcWdiMWoclJxVP9q4A==", + "cpu": [ + "x64" + ], + "hasInstallScript": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-win32-x64-msvc": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-0.1.34.tgz", + "integrity": "sha512-k8tPRVbB0svxC3sZ1qxMJbJYjnFN1oyi344DwbbOeUTUQNyGPwrpsHjtnPbNogl0/i/jFtRXH6fI5fCngmolCA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "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/@sapphire/shapeshift": { + "version": "3.8.1", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.8.1.tgz", + "integrity": "sha512-xG1oXXBhCjPKbxrRTlox9ddaZTvVpOhYLmKmApD/vIWOV1xEYXnpoFs68zHIZBGbqztq6FrUPNPerIrO1Hqeaw==", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "lodash": "^4.17.21" + }, + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@sapphire/snowflake": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.3.0.tgz", + "integrity": "sha512-Hec5N6zEkZuZFLybVKyLFLlcSgYmR6C1/+9NkIhxPwOf6tgX52ndJCSz8ADejmbrNE0VuNCNkpzhRZzenEC9vA==", + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@skyra/gifenc": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@skyra/gifenc/-/gifenc-1.0.1.tgz", + "integrity": "sha512-kxu65ZchumEKWnFwPwy+/T2+/lzQZtwK6f5VTG3OJIBqvfdyRyxrWvbeBHT6G8p6nBEuxSwyI3YXTv2koXvHVQ==", + "dependencies": { + "tslib": "^2.4.0" + }, + "engines": { + "node": ">=v14.18.0", + "npm": ">=7.24.2" + } + }, + "node_modules/@tokenizer/token": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz", + "integrity": "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==" + }, + "node_modules/@types/node": { + "version": "18.11.17", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.17.tgz", + "integrity": "sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng==" + }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==" + }, + "node_modules/@types/whatwg-url": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz", + "integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==", + "dependencies": { + "@types/node": "*", + "@types/webidl-conversions": "*" + } + }, + "node_modules/@types/ws": { + "version": "8.5.3", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz", + "integrity": "sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==", + "dependencies": { + "@types/node": "*" + } + }, + "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==", + "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/bson": { + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/bson/-/bson-4.7.2.tgz", + "integrity": "sha512-Ry9wCtIZ5kGqkJoi6aD8KjxFZEx78guTQDnpXWiNthsxzrxAK/i8E6pCHAIZTbaEFWcOCvbecMukfK7XUvyLpQ==", + "dependencies": { + "buffer": "^5.6.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "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": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, + "node_modules/canvacord": { + "version": "5.4.8", + "resolved": "https://registry.npmjs.org/canvacord/-/canvacord-5.4.8.tgz", + "integrity": "sha512-hxZ821JzQNCw/WkadVamFZDHvgzmTe9hfla1rG6c0cZoLwAAaSoQ3PPjpaTFbfkiYLeJugdlYnzm5sCJDsT5bA==", + "hasInstallScript": true, + "dependencies": { + "@napi-rs/canvas": "^0.1.29", + "@skyra/gifenc": "^1.0.0", + "chalk": "^5.0.1", + "moment": "^2.29.4", + "moment-duration-format": "^2.3.2", + "node-fetch": "2.6.7" + }, + "bin": { + "canvacord": "bin/canvacord.js" + }, + "funding": { + "type": "individual", + "url": "https://paypal.me/devsnowflake" + } + }, + "node_modules/chalk": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz", + "integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/debug/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==" + }, + "node_modules/discord-api-types": { + "version": "0.37.24", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.24.tgz", + "integrity": "sha512-1+Fb4huJCihdbkJLcq2p7nBmtlmAryNwjefT8wwJnL8c7bc7WA87Oaa5mbLe96QvZyfwnwRCDX40H0HhcVV50g==" + }, + "node_modules/discord.js": { + "version": "14.7.1", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.7.1.tgz", + "integrity": "sha512-1FECvqJJjjeYcjSm0IGMnPxLqja/pmG1B0W2l3lUY2Gi4KXiyTeQmU1IxWcbXHn2k+ytP587mMWqva2IA87EbA==", + "dependencies": { + "@discordjs/builders": "^1.4.0", + "@discordjs/collection": "^1.3.0", + "@discordjs/rest": "^1.4.0", + "@discordjs/util": "^0.1.0", + "@sapphire/snowflake": "^3.2.2", + "@types/ws": "^8.5.3", + "discord-api-types": "^0.37.20", + "fast-deep-equal": "^3.1.3", + "lodash.snakecase": "^4.1.1", + "tslib": "^2.4.1", + "undici": "^5.13.0", + "ws": "^8.11.0" + }, + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, + "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/file-type": { + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-18.0.0.tgz", + "integrity": "sha512-jjMwFpnW8PKofLE/4ohlhqwDk5k0NC6iy0UHAJFKoY1fQeGMN0GDdLgHQrvCbSpMwbqzoCZhRI5dETCZna5qVA==", + "dependencies": { + "readable-web-to-node-stream": "^3.0.2", + "strtok3": "^7.0.0", + "token-types": "^5.0.1" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sindresorhus/file-type?sponsor=1" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "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/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/ip": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", + "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==" + }, + "node_modules/kareem": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz", + "integrity": "sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==", + "engines": { + "node": ">=12.0.0" + } + }, + "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/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "optional": true + }, + "node_modules/moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "engines": { + "node": "*" + } + }, + "node_modules/moment-duration-format": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/moment-duration-format/-/moment-duration-format-2.3.2.tgz", + "integrity": "sha512-cBMXjSW+fjOb4tyaVHuaVE/A5TqkukDWiOfxxAjY+PEqmmBQlLwn+8OzwPiG3brouXKY5Un4pBjAeB6UToXHaQ==" + }, + "node_modules/mongodb": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.13.0.tgz", + "integrity": "sha512-+taZ/bV8d1pYuHL4U+gSwkhmDrwkWbH1l4aah4YpmpscMwgFBkufIKxgP/G7m87/NUuQzc2Z75ZTI7ZOyqZLbw==", + "dependencies": { + "bson": "^4.7.0", + "mongodb-connection-string-url": "^2.5.4", + "socks": "^2.7.1" + }, + "engines": { + "node": ">=12.9.0" + }, + "optionalDependencies": { + "@aws-sdk/credential-providers": "^3.186.0", + "saslprep": "^1.0.3" + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz", + "integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==", + "dependencies": { + "@types/whatwg-url": "^8.2.1", + "whatwg-url": "^11.0.0" + } + }, + "node_modules/mongoose": { + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.9.0.tgz", + "integrity": "sha512-5tu6+trwjk5TIH6b6iYgAwmzZ0RNOxFoqXQb9h21Oi45DeM1rWM/niHxJ4ROqBISDfQMwRvLSABHTsyn3AzoFQ==", + "dependencies": { + "bson": "^4.7.0", + "kareem": "2.5.1", + "mongodb": "4.13.0", + "mpath": "0.9.0", + "mquery": "4.0.3", + "ms": "2.1.3", + "sift": "16.0.1" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-4.0.3.tgz", + "integrity": "sha512-J5heI+P08I6VJ2Ky3+33IpCdAvlYGTSUjwTPxkAr8i8EoduPMBX2OY/wa3IKZIQl7MU4SbFk8ndgSKyB/cl1zA==", + "dependencies": { + "debug": "4.x" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/node-fetch/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/node-fetch/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/node-fetch/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/parse-ms": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-3.0.0.tgz", + "integrity": "sha512-Tpb8Z7r7XbbtBTrM9UhpkzzaMrqA2VXMT3YChzYltwV3P3pM6t8wl7TvpMnSTosz1aQAdVib7kdoys7vYOPerw==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/peek-readable": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-5.0.0.tgz", + "integrity": "sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==", + "engines": { + "node": ">=14.16" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/pretty-ms": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-8.0.0.tgz", + "integrity": "sha512-ASJqOugUF1bbzI35STMBUpZqdfYKlJugy6JBziGi2EE+AL5JPJGSzvpeVXojxrr0ViUYoToUjb5kjSEGf7Y83Q==", + "dependencies": { + "parse-ms": "^3.0.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/punycode": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", + "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", + "engines": { + "node": ">=6" + } + }, + "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==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/readable-web-to-node-stream": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-3.0.2.tgz", + "integrity": "sha512-ePeK6cc1EcKLEhJFt/AebMCLL+GgSKhuygrZ/GLaKZYEecIgIECf4UaUuaByiGtzckwR4ain9VzUh95T1exYGw==", + "dependencies": { + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "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/saslprep": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", + "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", + "optional": true, + "dependencies": { + "sparse-bitfield": "^3.0.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/sift": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/sift/-/sift-16.0.1.tgz", + "integrity": "sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ==" + }, + "node_modules/smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", + "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "dependencies": { + "ip": "^2.0.0", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.13.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "optional": true, + "dependencies": { + "memory-pager": "^1.0.2" + } + }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, + "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==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/strtok3": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-7.0.0.tgz", + "integrity": "sha512-pQ+V+nYQdC5H3Q7qBZAz/MO6lwGhoC2gOAjuouGf/VO0m7vQRh8QNMl2Uf6SwAtzZ9bOw3UIeBukEGNJl5dtXQ==", + "dependencies": { + "@tokenizer/token": "^0.3.0", + "peek-readable": "^5.0.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/token-types": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/token-types/-/token-types-5.0.1.tgz", + "integrity": "sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==", + "dependencies": { + "@tokenizer/token": "^0.3.0", + "ieee754": "^1.2.1" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/tr46": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", + "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", + "dependencies": { + "punycode": "^2.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/ts-mixer": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.2.tgz", + "integrity": "sha512-zvHx3VM83m2WYCE8XL99uaM7mFwYSkjR2OZti98fabHrwkjsCvgwChda5xctein3xGOyaQhtTeDq/1H/GNvF3A==" + }, + "node_modules/tslib": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", + "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==" + }, + "node_modules/undici": { + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.14.0.tgz", + "integrity": "sha512-yJlHYw6yXPPsuOH0x2Ib1Km61vu4hLiRRQoafs+WUgX1vO64vgnxiCEN9dpIrhZyHFsai3F0AEj4P9zy19enEQ==", + "dependencies": { + "busboy": "^1.6.0" + }, + "engines": { + "node": ">=12.18" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", + "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", + "dependencies": { + "tr46": "^3.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/ws": { + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + } +} diff --git a/15 - AutoRole/package.json b/15 - AutoRole/package.json new file mode 100644 index 0000000..7e1e784 --- /dev/null +++ b/15 - AutoRole/package.json @@ -0,0 +1,20 @@ +{ + "name": "discord-bot", + "version": "1.0.0", + "description": "", + "main": "src/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "canvacord": "^5.4.8", + "discord.js": "^14.7.1", + "dotenv": "^16.0.3", + "mongoose": "^6.9.0", + "ms": "^2.1.3", + "pretty-ms": "^8.0.0" + } +} diff --git a/15 - AutoRole/src/commands/admin/autorole-configure.js b/15 - AutoRole/src/commands/admin/autorole-configure.js new file mode 100644 index 0000000..cd5974a --- /dev/null +++ b/15 - AutoRole/src/commands/admin/autorole-configure.js @@ -0,0 +1,56 @@ +const { ApplicationCommandOptionType, Client, Interaction, PermissionFlagsBits } = require('discord.js'); +const AutoRole = require('../../models/AutoRole'); + +module.exports = { + /** + * + * @param {Client} client + * @param {Interaction} interaction + */ + callback: async (client, interaction) => { + if (!interaction.inGuild()) { + interaction.reply('You can only run this command inside a server.'); + return; + } + + const targetRoleId = interaction.options.get('role').value; + + try { + await interaction.deferReply(); + + let autoRole = await AutoRole.findOne({ guildId: interaction.guild.id }); + + if (autoRole) { + if (autoRole.roleId === targetRoleId) { + interaction.editReply('Auto role has already been configured for that role. To disable run `/autorole-disable`'); + return; + } + + autoRole.roleId = targetRoleId; + } else { + autoRole = new AutoRole({ + guildId: interaction.guild.id, + roleId: targetRoleId, + }); + } + + await autoRole.save(); + interaction.editReply('Autorole has now been configured. To disable run `/autorole-disable`'); + } catch (error) { + console.log(error); + } + }, + + name: 'autorole-configure', + description: 'Configure your auto-role for this server.', + options: [ + { + name: 'role', + description: 'The role you want users to get on join.', + type: ApplicationCommandOptionType.Role, + required: true, + }, + ], + permissionsRequired: [PermissionFlagsBits.Administrator], + botPermissions: [PermissionFlagsBits.ManageRoles], +}; diff --git a/15 - AutoRole/src/commands/admin/autorole-disable.js b/15 - AutoRole/src/commands/admin/autorole-disable.js new file mode 100644 index 0000000..4ca0ef0 --- /dev/null +++ b/15 - AutoRole/src/commands/admin/autorole-disable.js @@ -0,0 +1,29 @@ +const { Client, Interaction, PermissionFlagsBits } = require('discord.js'); +const AutoRole = require('../../models/AutoRole'); + +module.exports = { + /** + * + * @param {Client} client + * @param {Interaction} interaction + */ + callback: async (client, interaction) => { + try { + await interaction.deferReply(); + + if (!(await AutoRole.exists({ guildId: interaction.guild.id }))) { + interaction.editReply('Auto role has not been configured for this server. Use `/autorole-configure` to set it up.'); + return; + } + + await AutoRole.findOneAndDelete({ guildId: interaction.guild.id }); + interaction.editReply('Auto role has been disabled for this server. Use `/autorole-configure` to set it up again.'); + } catch (error) { + console.log(error); + } + }, + + name: 'autorole-disable', + description: 'Disable auto-role in this server.', + permissionsRequired: [PermissionFlagsBits.Administrator], +}; diff --git a/15 - AutoRole/src/commands/economy/daily.js b/15 - AutoRole/src/commands/economy/daily.js new file mode 100644 index 0000000..042b6f4 --- /dev/null +++ b/15 - AutoRole/src/commands/economy/daily.js @@ -0,0 +1,62 @@ +const { Client, Interaction } = require('discord.js'); +const User = require('../../models/User'); + +const dailyAmount = 1000; + +module.exports = { + name: 'daily', + description: 'Collect your dailies!', + /** + * + * @param {Client} client + * @param {Interaction} interaction + */ + callback: async (client, interaction) => { + if (!interaction.inGuild()) { + interaction.reply({ + content: 'You can only run this command inside a server.', + ephemeral: true, + }); + return; + } + + try { + await interaction.deferReply(); + + const query = { + userId: interaction.member.id, + guildId: interaction.guild.id, + }; + + let user = await User.findOne(query); + + if (user) { + const lastDailyDate = user.lastDaily.toDateString(); + const currentDate = new Date().toDateString(); + + if (lastDailyDate === currentDate) { + interaction.editReply( + 'You have already collected your dailies today. Come back tomorrow!' + ); + return; + } + + user.lastDaily = new Date(); + } else { + user = new User({ + ...query, + lastDaily: new Date(), + }); + } + + user.balance += dailyAmount; + await user.save(); + + interaction.editReply( + `${dailyAmount} was added to your balance. Your new balance is ${user.balance}` + ); + } catch (error) { + console.log(`Error with /daily: ${error}`); + } + }, +}; diff --git a/15 - AutoRole/src/commands/economy/level.js b/15 - AutoRole/src/commands/economy/level.js new file mode 100644 index 0000000..8103548 --- /dev/null +++ b/15 - AutoRole/src/commands/economy/level.js @@ -0,0 +1,82 @@ +const { + Client, + Interaction, + ApplicationCommandOptionType, + AttachmentBuilder, +} = require('discord.js'); +const canvacord = require('canvacord'); +const calculateLevelXp = require('../../utils/calculateLevelXp'); +const Level = require('../../models/Level'); + +module.exports = { + /** + * + * @param {Client} client + * @param {Interaction} interaction + */ + callback: async (client, interaction) => { + if (!interaction.inGuild()) { + interaction.reply('You can only run this command inside a server.'); + return; + } + + await interaction.deferReply(); + + const mentionedUserId = interaction.options.get('target-user')?.value; + const targetUserId = mentionedUserId || interaction.member.id; + const targetUserObj = await interaction.guild.members.fetch(targetUserId); + + const fetchedLevel = await Level.findOne({ + userId: targetUserId, + guildId: interaction.guild.id, + }); + + if (!fetchedLevel) { + interaction.editReply( + mentionedUserId + ? `${targetUserObj.user.tag} doesn't have any levels yet. Try again when they chat a little more.` + : "You don't have any levels yet. Chat a little more and try again." + ); + return; + } + + let allLevels = await Level.find({ guildId: interaction.guild.id }).select( + '-_id userId level xp' + ); + + allLevels.sort((a, b) => { + if (a.level === b.level) { + return b.xp - a.xp; + } else { + return b.level - a.level; + } + }); + + let currentRank = allLevels.findIndex((lvl) => lvl.userId === targetUserId) + 1; + + const rank = new canvacord.Rank() + .setAvatar(targetUserObj.user.displayAvatarURL({ size: 256 })) + .setRank(currentRank) + .setLevel(fetchedLevel.level) + .setCurrentXP(fetchedLevel.xp) + .setRequiredXP(calculateLevelXp(fetchedLevel.level)) + .setStatus(targetUserObj.presence.status) + .setProgressBar('#FFC300', 'COLOR') + .setUsername(targetUserObj.user.username) + .setDiscriminator(targetUserObj.user.discriminator); + + const data = await rank.build(); + const attachment = new AttachmentBuilder(data); + interaction.editReply({ files: [attachment] }); + }, + + name: 'level', + description: "Shows your/someone's level.", + options: [ + { + name: 'target-user', + description: 'The user whose level you want to see.', + type: ApplicationCommandOptionType.Mentionable, + }, + ], +}; diff --git a/15 - AutoRole/src/commands/misc/ping.js b/15 - AutoRole/src/commands/misc/ping.js new file mode 100644 index 0000000..870293c --- /dev/null +++ b/15 - AutoRole/src/commands/misc/ping.js @@ -0,0 +1,16 @@ +module.exports = { + name: 'ping', + description: 'Replies with the bot ping!', + + callback: async (client, interaction) => { + await interaction.deferReply(); + + const reply = await interaction.fetchReply(); + + const ping = reply.createdTimestamp - interaction.createdTimestamp; + + interaction.editReply( + `Pong! Client ${ping}ms | Websocket: ${client.ws.ping}ms` + ); + }, +}; diff --git a/15 - AutoRole/src/commands/moderation/ban.js b/15 - AutoRole/src/commands/moderation/ban.js new file mode 100644 index 0000000..72f498c --- /dev/null +++ b/15 - AutoRole/src/commands/moderation/ban.js @@ -0,0 +1,82 @@ +const { + Client, + Interaction, + ApplicationCommandOptionType, + PermissionFlagsBits, +} = require('discord.js'); + +module.exports = { + /** + * + * @param {Client} client + * @param {Interaction} interaction + */ + + callback: async (client, interaction) => { + const targetUserId = interaction.options.get('target-user').value; + const reason = + interaction.options.get('reason')?.value || 'No reason provided'; + + await interaction.deferReply(); + + const targetUser = await interaction.guild.members.fetch(targetUserId); + + if (!targetUser) { + await interaction.editReply("That user doesn't exist in this server."); + return; + } + + if (targetUser.id === interaction.guild.ownerId) { + await interaction.editReply( + "You can't ban that user because they're the server owner." + ); + return; + } + + const targetUserRolePosition = targetUser.roles.highest.position; // Highest role of the target user + const requestUserRolePosition = interaction.member.roles.highest.position; // Highest role of the user running the cmd + const botRolePosition = interaction.guild.members.me.roles.highest.position; // Highest role of the bot + + if (targetUserRolePosition >= requestUserRolePosition) { + await interaction.editReply( + "You can't ban that user because they have the same/higher role than you." + ); + return; + } + + if (targetUserRolePosition >= botRolePosition) { + await interaction.editReply( + "I can't ban that user because they have the same/higher role than me." + ); + return; + } + + // Ban the targetUser + try { + await targetUser.ban({ reason }); + await interaction.editReply( + `User ${targetUser} was banned\nReason: ${reason}` + ); + } catch (error) { + console.log(`There was an error when banning: ${error}`); + } + }, + + name: 'ban', + description: 'Bans a member from this server.', + options: [ + { + name: 'target-user', + description: 'The user you want to ban.', + type: ApplicationCommandOptionType.Mentionable, + required: true, + }, + { + name: 'reason', + description: 'The reason you want to ban.', + type: ApplicationCommandOptionType.String, + }, + ], + permissionsRequired: [PermissionFlagsBits.BanMembers], + botPermissions: [PermissionFlagsBits.BanMembers], +}; diff --git a/15 - AutoRole/src/commands/moderation/kick.js b/15 - AutoRole/src/commands/moderation/kick.js new file mode 100644 index 0000000..9b5a10d --- /dev/null +++ b/15 - AutoRole/src/commands/moderation/kick.js @@ -0,0 +1,82 @@ +const { + Client, + Interaction, + ApplicationCommandOptionType, + PermissionFlagsBits, +} = require('discord.js'); + +module.exports = { + /** + * + * @param {Client} client + * @param {Interaction} interaction + */ + + callback: async (client, interaction) => { + const targetUserId = interaction.options.get('target-user').value; + const reason = + interaction.options.get('reason')?.value || 'No reason provided'; + + await interaction.deferReply(); + + const targetUser = await interaction.guild.members.fetch(targetUserId); + + if (!targetUser) { + await interaction.editReply("That user doesn't exist in this server."); + return; + } + + if (targetUser.id === interaction.guild.ownerId) { + await interaction.editReply( + "You can't kick that user because they're the server owner." + ); + return; + } + + const targetUserRolePosition = targetUser.roles.highest.position; // Highest role of the target user + const requestUserRolePosition = interaction.member.roles.highest.position; // Highest role of the user running the cmd + const botRolePosition = interaction.guild.members.me.roles.highest.position; // Highest role of the bot + + if (targetUserRolePosition >= requestUserRolePosition) { + await interaction.editReply( + "You can't kick that user because they have the same/higher role than you." + ); + return; + } + + if (targetUserRolePosition >= botRolePosition) { + await interaction.editReply( + "I can't kick that user because they have the same/higher role than me." + ); + return; + } + + // Kick the targetUser + try { + await targetUser.kick({ reason }); + await interaction.editReply( + `User ${targetUser} was kicked\nReason: ${reason}` + ); + } catch (error) { + console.log(`There was an error when kicking: ${error}`); + } + }, + + name: 'kick', + description: 'Kicks a member from this server.', + options: [ + { + name: 'target-user', + description: 'The user you want to kick.', + type: ApplicationCommandOptionType.Mentionable, + required: true, + }, + { + name: 'reason', + description: 'The reason you want to kick.', + type: ApplicationCommandOptionType.String, + }, + ], + permissionsRequired: [PermissionFlagsBits.KickMembers], + botPermissions: [PermissionFlagsBits.KickMembers], +}; diff --git a/15 - AutoRole/src/commands/moderation/timeout.js b/15 - AutoRole/src/commands/moderation/timeout.js new file mode 100644 index 0000000..5738333 --- /dev/null +++ b/15 - AutoRole/src/commands/moderation/timeout.js @@ -0,0 +1,94 @@ +const { Client, Interaction, ApplicationCommandOptionType, PermissionFlagsBits } = require('discord.js'); +const ms = require('ms'); + +module.exports = { + /** + * + * @param {Client} client + * @param {Interaction} interaction + */ + + callback: async (client, interaction) => { + const mentionable = interaction.options.get('target-user').value; + const duration = interaction.options.get('duration').value; // 1d, 1 day, 1s 5s, 5m + const reason = interaction.options.get('reason')?.value || 'No reason provided'; + + await interaction.deferReply(); + + const targetUser = await interaction.guild.members.fetch(mentionable); + if (!targetUser) { + await interaction.editReply("That user doesn't exist in this server."); + return; + } + + if (targetUser.user.bot) { + await interaction.editReply("I can't timeout a bot."); + return; + } + + const msDuration = ms(duration); + if (isNaN(msDuration)) { + await interaction.editReply('Please provide a valid timeout duration.'); + return; + } + + if (msDuration < 5000 || msDuration > 2.419e9) { + await interaction.editReply('Timeout duration cannot be less than 5 seconds or more than 28 days.'); + return; + } + + const targetUserRolePosition = targetUser.roles.highest.position; // Highest role of the target user + const requestUserRolePosition = interaction.member.roles.highest.position; // Highest role of the user running the cmd + const botRolePosition = interaction.guild.members.me.roles.highest.position; // Highest role of the bot + + if (targetUserRolePosition >= requestUserRolePosition) { + await interaction.editReply("You can't timeout that user because they have the same/higher role than you."); + return; + } + + if (targetUserRolePosition >= botRolePosition) { + await interaction.editReply("I can't timeout that user because they have the same/higher role than me."); + return; + } + + // Timeout the user + try { + const { default: prettyMs } = await import('pretty-ms'); + + if (targetUser.isCommunicationDisabled()) { + await targetUser.timeout(msDuration, reason); + await interaction.editReply(`${targetUser}'s timeout has been updated to ${prettyMs(msDuration, { verbose: true })}\nReason: ${reason}`); + return; + } + + await targetUser.timeout(msDuration, reason); + await interaction.editReply(`${targetUser} was timed out for ${prettyMs(msDuration, { verbose: true })}.\nReason: ${reason}`); + } catch (error) { + console.log(`There was an error when timing out: ${error}`); + } + }, + + name: 'timeout', + description: 'Timeout a user.', + options: [ + { + name: 'target-user', + description: 'The user you want to timeout.', + type: ApplicationCommandOptionType.Mentionable, + required: true, + }, + { + name: 'duration', + description: 'Timeout duration (30m, 1h, 1 day).', + type: ApplicationCommandOptionType.String, + required: true, + }, + { + name: 'reason', + description: 'The reason for the timeout.', + type: ApplicationCommandOptionType.String, + }, + ], + permissionsRequired: [PermissionFlagsBits.MuteMembers], + botPermissions: [PermissionFlagsBits.MuteMembers], +}; diff --git a/15 - AutoRole/src/events/guildMemberAdd/autoRole.js b/15 - AutoRole/src/events/guildMemberAdd/autoRole.js new file mode 100644 index 0000000..2e74906 --- /dev/null +++ b/15 - AutoRole/src/events/guildMemberAdd/autoRole.js @@ -0,0 +1,21 @@ +const { Client, GuildMember } = require('discord.js'); +const AutoRole = require('../../models/AutoRole'); + +/** + * + * @param {Client} client + * @param {GuildMember} member + */ +module.exports = async (client, member) => { + try { + let guild = member.guild; + if (!guild) return; + + const autoRole = await AutoRole.findOne({ guildId: guild.id }); + if (!autoRole) return; + + await member.roles.add(autoRole.roleId); + } catch (error) { + console.log(`Error giving role automatically: ${error}`); + } +}; diff --git a/15 - AutoRole/src/events/interactionCreate/handleCommands.js b/15 - AutoRole/src/events/interactionCreate/handleCommands.js new file mode 100644 index 0000000..ce0063b --- /dev/null +++ b/15 - AutoRole/src/events/interactionCreate/handleCommands.js @@ -0,0 +1,66 @@ +const { devs, testServer } = require('../../../config.json'); +const getLocalCommands = require('../../utils/getLocalCommands'); + +module.exports = async (client, interaction) => { + if (!interaction.isChatInputCommand()) return; + + const localCommands = getLocalCommands(); + + try { + const commandObject = localCommands.find( + (cmd) => cmd.name === interaction.commandName + ); + + if (!commandObject) return; + + if (commandObject.devOnly) { + if (!devs.includes(interaction.member.id)) { + interaction.reply({ + content: 'Only developers are allowed to run this command.', + ephemeral: true, + }); + return; + } + } + + if (commandObject.testOnly) { + if (!(interaction.guild.id === testServer)) { + interaction.reply({ + content: 'This command cannot be ran here.', + ephemeral: true, + }); + return; + } + } + + if (commandObject.permissionsRequired?.length) { + for (const permission of commandObject.permissionsRequired) { + if (!interaction.member.permissions.has(permission)) { + interaction.reply({ + content: 'Not enough permissions.', + ephemeral: true, + }); + return; + } + } + } + + if (commandObject.botPermissions?.length) { + for (const permission of commandObject.botPermissions) { + const bot = interaction.guild.members.me; + + if (!bot.permissions.has(permission)) { + interaction.reply({ + content: "I don't have enough permissions.", + ephemeral: true, + }); + return; + } + } + } + + await commandObject.callback(client, interaction); + } catch (error) { + console.log(`There was an error running this command: ${error}`); + } +}; diff --git a/15 - AutoRole/src/events/messageCreate/giveUserXp.js b/15 - AutoRole/src/events/messageCreate/giveUserXp.js new file mode 100644 index 0000000..dd5519f --- /dev/null +++ b/15 - AutoRole/src/events/messageCreate/giveUserXp.js @@ -0,0 +1,68 @@ +const { Client, Message } = require('discord.js'); +const calculateLevelXp = require('../../utils/calculateLevelXp'); +const Level = require('../../models/Level'); +const cooldowns = new Set(); + +function getRandomXp(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +/** + * + * @param {Client} client + * @param {Message} message + */ +module.exports = async (client, message) => { + if (!message.inGuild() || message.author.bot || cooldowns.has(message.author.id)) return; + + const xpToGive = getRandomXp(5, 15); + + const query = { + userId: message.author.id, + guildId: message.guild.id, + }; + + try { + const level = await Level.findOne(query); + + if (level) { + level.xp += xpToGive; + + if (level.xp > calculateLevelXp(level.level)) { + level.xp = 0; + level.level += 1; + + message.channel.send(`${message.member} you have leveled up to **level ${level.level}**.`); + } + + await level.save().catch((e) => { + console.log(`Error saving updated level ${e}`); + return; + }); + cooldowns.add(message.author.id); + setTimeout(() => { + cooldowns.delete(message.author.id); + }, 60000); + } + + // if (!level) + else { + // create new level + const newLevel = new Level({ + userId: message.author.id, + guildId: message.guild.id, + xp: xpToGive, + }); + + await newLevel.save(); + cooldowns.add(message.author.id); + setTimeout(() => { + cooldowns.delete(message.author.id); + }, 60000); + } + } catch (error) { + console.log(`Error giving xp: ${error}`); + } +}; diff --git a/15 - AutoRole/src/events/ready/01registerCommands.js b/15 - AutoRole/src/events/ready/01registerCommands.js new file mode 100644 index 0000000..01e999d --- /dev/null +++ b/15 - AutoRole/src/events/ready/01registerCommands.js @@ -0,0 +1,56 @@ +const { testServer } = require('../../../config.json'); +const areCommandsDifferent = require('../../utils/areCommandsDifferent'); +const getApplicationCommands = require('../../utils/getApplicationCommands'); +const getLocalCommands = require('../../utils/getLocalCommands'); + +module.exports = async (client) => { + try { + const localCommands = getLocalCommands(); + const applicationCommands = await getApplicationCommands( + client, + testServer + ); + + for (const localCommand of localCommands) { + const { name, description, options } = localCommand; + + const existingCommand = await applicationCommands.cache.find( + (cmd) => cmd.name === name + ); + + if (existingCommand) { + if (localCommand.deleted) { + await applicationCommands.delete(existingCommand.id); + console.log(`🗑 Deleted command "${name}".`); + continue; + } + + if (areCommandsDifferent(existingCommand, localCommand)) { + await applicationCommands.edit(existingCommand.id, { + description, + options, + }); + + console.log(`🔁 Edited command "${name}".`); + } + } else { + if (localCommand.deleted) { + console.log( + `⏩ Skipping registering command "${name}" as it's set to delete.` + ); + continue; + } + + await applicationCommands.create({ + name, + description, + options, + }); + + console.log(`👍 Registered command "${name}."`); + } + } + } catch (error) { + console.log(`There was an error: ${error}`); + } +}; diff --git a/15 - AutoRole/src/events/ready/consoleLog.js b/15 - AutoRole/src/events/ready/consoleLog.js new file mode 100644 index 0000000..afc6c17 --- /dev/null +++ b/15 - AutoRole/src/events/ready/consoleLog.js @@ -0,0 +1,3 @@ +module.exports = (client) => { + console.log(`${client.user.tag} is online.`); +}; diff --git a/15 - AutoRole/src/handlers/eventHandler.js b/15 - AutoRole/src/handlers/eventHandler.js new file mode 100644 index 0000000..5127f14 --- /dev/null +++ b/15 - AutoRole/src/handlers/eventHandler.js @@ -0,0 +1,20 @@ +const path = require('path'); +const getAllFiles = require('../utils/getAllFiles'); + +module.exports = (client) => { + const eventFolders = getAllFiles(path.join(__dirname, '..', 'events'), true); + + for (const eventFolder of eventFolders) { + let eventFiles = getAllFiles(eventFolder); + eventFiles.sort(); + + const eventName = eventFolder.replace(/\\/g, '/').split('/').pop(); + + client.on(eventName, async (arg) => { + for (const eventFile of eventFiles) { + const eventFunction = require(eventFile); + await eventFunction(client, arg); + } + }); + } +}; diff --git a/15 - AutoRole/src/index.js b/15 - AutoRole/src/index.js new file mode 100644 index 0000000..726d19e --- /dev/null +++ b/15 - AutoRole/src/index.js @@ -0,0 +1,28 @@ +require('dotenv').config(); +const { Client, IntentsBitField } = require('discord.js'); +const mongoose = require('mongoose'); +const eventHandler = require('./handlers/eventHandler'); + +const client = new Client({ + intents: [ + IntentsBitField.Flags.Guilds, + IntentsBitField.Flags.GuildMembers, + IntentsBitField.Flags.GuildMessages, + IntentsBitField.Flags.GuildPresences, + IntentsBitField.Flags.MessageContent, + ], +}); + +(async () => { + try { + mongoose.set('strictQuery', false); + await mongoose.connect(process.env.MONGODB_URI); + console.log('Connected to DB.'); + + eventHandler(client); + + client.login(process.env.TOKEN); + } catch (error) { + console.log(`Error: ${error}`); + } +})(); diff --git a/15 - AutoRole/src/models/AutoRole.js b/15 - AutoRole/src/models/AutoRole.js new file mode 100644 index 0000000..596c813 --- /dev/null +++ b/15 - AutoRole/src/models/AutoRole.js @@ -0,0 +1,15 @@ +const { Schema, model } = require('mongoose'); + +const autoRoleSchema = new Schema({ + guildId: { + type: String, + required: true, + unique: true, + }, + roleId: { + type: String, + required: true, + }, +}); + +module.exports = model('AutoRole', autoRoleSchema); diff --git a/15 - AutoRole/src/models/Level.js b/15 - AutoRole/src/models/Level.js new file mode 100644 index 0000000..fd65e76 --- /dev/null +++ b/15 - AutoRole/src/models/Level.js @@ -0,0 +1,22 @@ +const { Schema, model } = require('mongoose'); + +const levelSchema = new Schema({ + userId: { + type: String, + required: true, + }, + guildId: { + type: String, + required: true, + }, + xp: { + type: Number, + default: 0, + }, + level: { + type: Number, + default: 0, + }, +}); + +module.exports = model('Level', levelSchema); diff --git a/15 - AutoRole/src/models/User.js b/15 - AutoRole/src/models/User.js new file mode 100644 index 0000000..2ae7cba --- /dev/null +++ b/15 - AutoRole/src/models/User.js @@ -0,0 +1,22 @@ +const { Schema, model } = require('mongoose'); + +const userSchema = new Schema({ + userId: { + type: String, + required: true, + }, + guildId: { + type: String, + required: true, + }, + balance: { + type: Number, + default: 0, + }, + lastDaily: { + type: Date, + reqired: true, + }, +}); + +module.exports = model('User', userSchema); diff --git a/15 - AutoRole/src/utils/areCommandsDifferent.js b/15 - AutoRole/src/utils/areCommandsDifferent.js new file mode 100644 index 0000000..8b4aac3 --- /dev/null +++ b/15 - AutoRole/src/utils/areCommandsDifferent.js @@ -0,0 +1,55 @@ +module.exports = (existingCommand, localCommand) => { + const areChoicesDifferent = (existingChoices, localChoices) => { + for (const localChoice of localChoices) { + const existingChoice = existingChoices?.find( + (choice) => choice.name === localChoice.name + ); + + if (!existingChoice) { + return true; + } + + if (localChoice.value !== existingChoice.value) { + return true; + } + } + return false; + }; + + const areOptionsDifferent = (existingOptions, localOptions) => { + for (const localOption of localOptions) { + const existingOption = existingOptions?.find( + (option) => option.name === localOption.name + ); + + if (!existingOption) { + return true; + } + + if ( + localOption.description !== existingOption.description || + localOption.type !== existingOption.type || + (localOption.required || false) !== existingOption.required || + (localOption.choices?.length || 0) !== + (existingOption.choices?.length || 0) || + areChoicesDifferent( + localOption.choices || [], + existingOption.choices || [] + ) + ) { + return true; + } + } + return false; + }; + + if ( + existingCommand.description !== localCommand.description || + existingCommand.options?.length !== (localCommand.options?.length || 0) || + areOptionsDifferent(existingCommand.options, localCommand.options || []) + ) { + return true; + } + + return false; +}; diff --git a/15 - AutoRole/src/utils/calculateLevelXp.js b/15 - AutoRole/src/utils/calculateLevelXp.js new file mode 100644 index 0000000..4eda6e3 --- /dev/null +++ b/15 - AutoRole/src/utils/calculateLevelXp.js @@ -0,0 +1 @@ +module.exports = (level) => 100 * level || 1; diff --git a/15 - AutoRole/src/utils/getAllFiles.js b/15 - AutoRole/src/utils/getAllFiles.js new file mode 100644 index 0000000..f3b4e03 --- /dev/null +++ b/15 - AutoRole/src/utils/getAllFiles.js @@ -0,0 +1,24 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = (directory, foldersOnly = false) => { + let fileNames = []; + + const files = fs.readdirSync(directory, { withFileTypes: true }); + + for (const file of files) { + const filePath = path.join(directory, file.name); + + if (foldersOnly) { + if (file.isDirectory()) { + fileNames.push(filePath); + } + } else { + if (file.isFile()) { + fileNames.push(filePath); + } + } + } + + return fileNames; +}; diff --git a/15 - AutoRole/src/utils/getApplicationCommands.js b/15 - AutoRole/src/utils/getApplicationCommands.js new file mode 100644 index 0000000..3d95a15 --- /dev/null +++ b/15 - AutoRole/src/utils/getApplicationCommands.js @@ -0,0 +1,13 @@ +module.exports = async (client, guildId) => { + let applicationCommands; + + if (guildId) { + const guild = await client.guilds.fetch(guildId); + applicationCommands = guild.commands; + } else { + applicationCommands = await client.application.commands; + } + + await applicationCommands.fetch(); + return applicationCommands; +}; diff --git a/15 - AutoRole/src/utils/getLocalCommands.js b/15 - AutoRole/src/utils/getLocalCommands.js new file mode 100644 index 0000000..73d8447 --- /dev/null +++ b/15 - AutoRole/src/utils/getLocalCommands.js @@ -0,0 +1,27 @@ +const path = require('path'); +const getAllFiles = require('./getAllFiles'); + +module.exports = (exceptions = []) => { + let localCommands = []; + + const commandCategories = getAllFiles( + path.join(__dirname, '..', 'commands'), + true + ); + + for (const commandCategory of commandCategories) { + const commandFiles = getAllFiles(commandCategory); + + for (const commandFile of commandFiles) { + const commandObject = require(commandFile); + + if (exceptions.includes(commandObject.name)) { + continue; + } + + localCommands.push(commandObject); + } + } + + return localCommands; +};