From d9e2f0e65581fcf3a516dd6adfb72f4f46f9bc5b Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 14:02:44 +0200 Subject: [PATCH 01/38] added slah command documentation and options for /translate --- commands/utility/translate.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 commands/utility/translate.js diff --git a/commands/utility/translate.js b/commands/utility/translate.js new file mode 100644 index 0000000..c42c85e --- /dev/null +++ b/commands/utility/translate.js @@ -0,0 +1,32 @@ +const { SlashCommandBuilder } = require("discord.js"); +const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); +const db = require("../../helpers/db"); +const { logToFileAndDatabase } = require("../../helpers/logger"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("translate") + .setDescription("Translates a message to a specified language.") + .addStringOption(option => + option + .setName("message") + .setDescription("The text you would like to translate.") + .setRequired(true) + ) + .addStringOption(option => + option + .setName("target-language") + .setDescription("The language you would like to translate the message to (default: English).") + .setRequired(false) + ) + .addStringOption(option => + option + .setName("source-language") + .setDescription("The language you would like to translate the message from (default: auto detect).") + .setRequired(false) + ) + .setDMPermission(true), + async execute(interaction) { + + } +} \ No newline at end of file From f5fe8556451fb30b3c660b0b55ecccf9b6051864 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 14:14:33 +0200 Subject: [PATCH 02/38] added google-translate-api package --- commands/utility/translate.js | 10 +- package-lock.json | 282 +++++++++++++++++++++++++++++++++- package.json | 1 + 3 files changed, 287 insertions(+), 6 deletions(-) diff --git a/commands/utility/translate.js b/commands/utility/translate.js index c42c85e..5995e1d 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -27,6 +27,14 @@ module.exports = { ) .setDMPermission(true), async execute(interaction) { - + const message = interaction.options.getString("message"); + const sourceLanguage = interaction.options.getString("source-language") || "auto"; + const targetLanguage = interaction.options.getString("target-language") || "en"; + + await interaction.reply({ embeds: [embedReply] }); + + //logging + const response = JSON.stringify(embedReply.toJSON()); + await logToFileAndDatabase(interaction, response); } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 48b1a0a..616bb0c 100755 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "discord.js": "^14.14.1", "dotenv": "^16.4.5", "fetch": "^1.1.0", + "google-translate-api": "^2.3.0", "jest": "^29.7.0", "mariadb": "^3.3.0", "node-fetch": "^3.3.2", @@ -1637,6 +1638,17 @@ } ] }, + "node_modules/capture-stack-trace": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.2.tgz", + "integrity": "sha512-X/WM2UQs6VMHUtjUDnZTRI+i1crWteJySFzr9UpGoQa4WQffXVTTXuekjl7TjZRlcF2XfjgITT0HxZ9RnxeT0w==", + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -1819,6 +1831,41 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, + "node_modules/configstore": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/configstore/-/configstore-2.1.0.tgz", + "integrity": "sha512-BOCxwwxF5WPspp1OBq9j0JLyL5JgJOTssz9PdOHr8VWjFijaC3PpjU48vFEX3uxx8sTusnVQckLbNzBq6fmkGw==", + "dependencies": { + "dot-prop": "^3.0.0", + "graceful-fs": "^4.1.2", + "mkdirp": "^0.5.0", + "object-assign": "^4.0.1", + "os-tmpdir": "^1.0.0", + "osenv": "^0.1.0", + "uuid": "^2.0.1", + "write-file-atomic": "^1.1.2", + "xdg-basedir": "^2.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/configstore/node_modules/uuid": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-2.0.3.tgz", + "integrity": "sha512-FULf7fayPdpASncVy4DLh3xydlXEJJpvIELjYjNeQWYUZ9pclcpvCZSr2gkmN2FrrGcI7G/cJsIEwk5/8vfXpg==", + "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details." + }, + "node_modules/configstore/node_modules/write-file-atomic": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz", + "integrity": "sha512-SdrHoC/yVBPpV0Xq/mUZQIpW2sWXAShb/V4pomcJXh92RuaO+f3UTWItiR3Px+pLnV2PvC2/bfn5cwr5X6Vfxw==", + "dependencies": { + "graceful-fs": "^4.1.11", + "imurmurhash": "^0.1.4", + "slide": "^1.1.5" + } + }, "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", @@ -1831,6 +1878,17 @@ "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", "peer": true }, + "node_modules/create-error-class": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz", + "integrity": "sha512-gYTKKexFO3kh200H1Nit76sRwRtOY32vQd3jpAQKpLtZqyNsSQNfI4N7o3eP2wUjV35pTWKRYqFUDBvUha/Pkw==", + "dependencies": { + "capture-stack-trace": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -2068,6 +2126,17 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dot-prop": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-3.0.0.tgz", + "integrity": "sha512-k4ELWeEU3uCcwub7+dWydqQBRjAjkV9L33HjVRG5Xo2QybI6ja/v+4W73SRi8ubCqJz0l9XsTP1NbewfyqaSlw==", + "dependencies": { + "is-obj": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/dotenv": { "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", @@ -2079,6 +2148,11 @@ "url": "https://dotenvx.com" } }, + "node_modules/duplexer3": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.5.tgz", + "integrity": "sha512-1A8za6ws41LQgv9HrE/66jyC5yuSjQ3L/KOpFtoBilsAK2iA2wuS5rTt1OCzIvtS2V7nVmedsUU+DGRcjBmOYA==" + }, "node_modules/ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -2491,11 +2565,67 @@ "node": ">=4" } }, + "node_modules/google-translate-api": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/google-translate-api/-/google-translate-api-2.3.0.tgz", + "integrity": "sha512-a7MRJpSAoS9HyQPE7Yqp5jYSRePWju53+Je/AkgU//zbSmZhy2tc+MvxlwbOegpptT7Ep6GCt7Q1/j7WmTntZw==", + "dependencies": { + "configstore": "^2.0.0", + "google-translate-token": "latest", + "got": "^6.3.0", + "safe-eval": "^0.3.0" + } + }, + "node_modules/google-translate-token": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/google-translate-token/-/google-translate-token-1.0.0.tgz", + "integrity": "sha512-X+cONF24KI3PP94ih3L8QlqNgVxZxsfOyJtX93UISO7TRdTSrFpp4rmDpyS/x6xRxJOLcd6ApCTAkB+tNFtc3g==", + "dependencies": { + "configstore": "^2.0.0", + "got": "^6.3.0" + } + }, + "node_modules/got": { + "version": "6.7.1", + "resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", + "integrity": "sha512-Y/K3EDuiQN9rTZhBvPRWMLXIKdeD1Rj0nzunfoi0Yyn5WBEbzxXKU9Ub2X41oZBagVWOBU3MuDonFMgPWQFnwg==", + "dependencies": { + "create-error-class": "^3.0.0", + "duplexer3": "^0.1.4", + "get-stream": "^3.0.0", + "is-redirect": "^1.0.0", + "is-retry-allowed": "^1.0.0", + "is-stream": "^1.0.0", + "lowercase-keys": "^1.0.0", + "safe-buffer": "^5.0.1", + "timed-out": "^4.0.0", + "unzip-response": "^2.0.1", + "url-parse-lax": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/got/node_modules/get-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "integrity": "sha512-GlhdIUuVakc8SJ6kK0zAFbiGzRFzNnY4jUuEbV9UROo4Y+0Ny4fjvcZFVTeDA4odpFyOQzaw6hXukJSq/f28sQ==", + "engines": { + "node": ">=4" + } + }, + "node_modules/got/node_modules/is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" }, "node_modules/har-schema": { "version": "2.0.0", @@ -2651,7 +2781,6 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", - "dev": true, "engines": { "node": ">=0.8.19" } @@ -2754,6 +2883,30 @@ "node": ">=0.12.0" } }, + "node_modules/is-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "integrity": "sha512-l4RyHgRqGN4Y3+9JHVrNqO+tN0rV5My76uW5/nuO4K1b6vw5G8d/cmFjP9tRfEsdhZNt0IFdZuK/c2Vr4Nb+Qg==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-redirect": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-redirect/-/is-redirect-1.0.0.tgz", + "integrity": "sha512-cr/SlUEe5zOGmzvj9bUyC4LVvkNVAXu4GytXLNMr1pny+a65MpQ9IJzFHD5vi7FyJgb4qt27+eS3TuQnqB+RQw==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-retry-allowed": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz", + "integrity": "sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -3562,6 +3715,14 @@ "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==" }, + "node_modules/lowercase-keys": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", + "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -3693,6 +3854,25 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -3854,6 +4034,14 @@ "node": "*" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -3878,6 +4066,32 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "deprecated": "This package is no longer supported.", + "dependencies": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -4059,6 +4273,14 @@ "node": ">=8" } }, + "node_modules/prepend-http": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz", + "integrity": "sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -4305,8 +4527,12 @@ "type": "consulting", "url": "https://feross.org/support" } - ], - "peer": true + ] + }, + "node_modules/safe-eval": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/safe-eval/-/safe-eval-0.3.0.tgz", + "integrity": "sha512-uPIAjU2zpyv2QJCZ1zaWZKnPv/5jgkaitE7WHomV4Mxu6kgHY1ruIQ1oTikEta/Sux3E8pZAozzJRsAUu3iDZA==" }, "node_modules/safer-buffer": { "version": "2.1.2", @@ -4388,6 +4614,14 @@ "node": ">=8" } }, + "node_modules/slide": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", + "integrity": "sha512-NwrtjCg+lZoqhFU8fOwl4ay2ei8PaqCBOUV3/ektPY9trO1yQ1oXEfmHAhKArUVUr/hOHvy5f6AdP17dCM0zMw==", + "engines": { + "node": "*" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -4565,6 +4799,14 @@ "node": ">=8" } }, + "node_modules/timed-out": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz", + "integrity": "sha512-G7r3AhovYtr5YKOWQkta8RKAPb+J9IsO4uVmzjl8AZwfhs8UcUwTiD6gcJYSgOtzyjvQKrKYn41syHbUWMkafA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -4681,6 +4923,14 @@ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==" }, + "node_modules/unzip-response": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/unzip-response/-/unzip-response-2.0.1.tgz", + "integrity": "sha512-N0XH6lqDtFH84JxptQoZYmloF4nzrQqqrAymNj+/gW60AO2AZgOcf4O/nUXJcYfyQkqvMo9lSupBZmmgvuVXlw==", + "engines": { + "node": ">=4" + } + }, "node_modules/update-browserslist-db": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", @@ -4720,6 +4970,17 @@ "punycode": "^2.1.0" } }, + "node_modules/url-parse-lax": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-1.0.0.tgz", + "integrity": "sha512-BVA4lR5PIviy2PMseNd2jbFQ+jwSwQGdJejf5ctd1rEXt0Ypd7yanUK9+lYechVlN5VaTJGsu2U/3MDDu6KgBA==", + "dependencies": { + "prepend-http": "^1.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", @@ -4865,6 +5126,17 @@ } } }, + "node_modules/xdg-basedir": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-2.0.0.tgz", + "integrity": "sha512-NF1pPn594TaRSUO/HARoB4jK8I+rWgcpVlpQCK6/6o5PHyLUt2CSiDrpUZbQ6rROck+W2EwF8mBJcTs+W98J9w==", + "dependencies": { + "os-homedir": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index c812e3c..19e45e3 100755 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "discord.js": "^14.14.1", "dotenv": "^16.4.5", "fetch": "^1.1.0", + "google-translate-api": "^2.3.0", "jest": "^29.7.0", "mariadb": "^3.3.0", "node-fetch": "^3.3.2", From cd3644da7206da3f3873a3d79cbb69f460508b3e Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 14:50:15 +0200 Subject: [PATCH 03/38] added base translation logic --- commands/utility/translate.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/commands/utility/translate.js b/commands/utility/translate.js index 5995e1d..d202452 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -2,6 +2,7 @@ const { SlashCommandBuilder } = require("discord.js"); const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); const db = require("../../helpers/db"); const { logToFileAndDatabase } = require("../../helpers/logger"); +const translate = require("google-translate-api"); module.exports = { data: new SlashCommandBuilder() @@ -31,6 +32,24 @@ module.exports = { const sourceLanguage = interaction.options.getString("source-language") || "auto"; const targetLanguage = interaction.options.getString("target-language") || "en"; + try { + const res = await translate(message, { from: sourceLanguage, to: targetLanguage }); + + var embedReply = embedReplyPrimaryColor( + "Translation", + res.text, + interaction + ); + } + catch (error) { + console.error(error); + var embedReply = embedReplyFailureColor( + "Translation", + `An error occurred while translating the message. Please try again later.`, + interaction + ); + } + await interaction.reply({ embeds: [embedReply] }); //logging From 13e94b4455207c43b37347801565951808ba674f Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 15:04:59 +0200 Subject: [PATCH 04/38] used an actually working package --- commands/utility/translate.js | 4 +- package-lock.json | 289 ++-------------------------------- package.json | 2 +- 3 files changed, 18 insertions(+), 277 deletions(-) diff --git a/commands/utility/translate.js b/commands/utility/translate.js index d202452..9b5849b 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -2,7 +2,7 @@ const { SlashCommandBuilder } = require("discord.js"); const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); const db = require("../../helpers/db"); const { logToFileAndDatabase } = require("../../helpers/logger"); -const translate = require("google-translate-api"); +const translate = require('google-translate-api-x'); module.exports = { data: new SlashCommandBuilder() @@ -31,7 +31,7 @@ module.exports = { const message = interaction.options.getString("message"); const sourceLanguage = interaction.options.getString("source-language") || "auto"; const targetLanguage = interaction.options.getString("target-language") || "en"; - + console.log(message, sourceLanguage, targetLanguage); try { const res = await translate(message, { from: sourceLanguage, to: targetLanguage }); diff --git a/package-lock.json b/package-lock.json index 616bb0c..39946a9 100755 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "discord.js": "^14.14.1", "dotenv": "^16.4.5", "fetch": "^1.1.0", - "google-translate-api": "^2.3.0", + "google-translate-api-x": "^10.7.1", "jest": "^29.7.0", "mariadb": "^3.3.0", "node-fetch": "^3.3.2", @@ -1638,17 +1638,6 @@ } ] }, - "node_modules/capture-stack-trace": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.2.tgz", - "integrity": "sha512-X/WM2UQs6VMHUtjUDnZTRI+i1crWteJySFzr9UpGoQa4WQffXVTTXuekjl7TjZRlcF2XfjgITT0HxZ9RnxeT0w==", - "engines": { - "node": ">=0.10.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -1831,41 +1820,6 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, - "node_modules/configstore": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/configstore/-/configstore-2.1.0.tgz", - "integrity": "sha512-BOCxwwxF5WPspp1OBq9j0JLyL5JgJOTssz9PdOHr8VWjFijaC3PpjU48vFEX3uxx8sTusnVQckLbNzBq6fmkGw==", - "dependencies": { - "dot-prop": "^3.0.0", - "graceful-fs": "^4.1.2", - "mkdirp": "^0.5.0", - "object-assign": "^4.0.1", - "os-tmpdir": "^1.0.0", - "osenv": "^0.1.0", - "uuid": "^2.0.1", - "write-file-atomic": "^1.1.2", - "xdg-basedir": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/configstore/node_modules/uuid": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-2.0.3.tgz", - "integrity": "sha512-FULf7fayPdpASncVy4DLh3xydlXEJJpvIELjYjNeQWYUZ9pclcpvCZSr2gkmN2FrrGcI7G/cJsIEwk5/8vfXpg==", - "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details." - }, - "node_modules/configstore/node_modules/write-file-atomic": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.4.tgz", - "integrity": "sha512-SdrHoC/yVBPpV0Xq/mUZQIpW2sWXAShb/V4pomcJXh92RuaO+f3UTWItiR3Px+pLnV2PvC2/bfn5cwr5X6Vfxw==", - "dependencies": { - "graceful-fs": "^4.1.11", - "imurmurhash": "^0.1.4", - "slide": "^1.1.5" - } - }, "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", @@ -1878,17 +1832,6 @@ "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", "peer": true }, - "node_modules/create-error-class": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz", - "integrity": "sha512-gYTKKexFO3kh200H1Nit76sRwRtOY32vQd3jpAQKpLtZqyNsSQNfI4N7o3eP2wUjV35pTWKRYqFUDBvUha/Pkw==", - "dependencies": { - "capture-stack-trace": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -2126,17 +2069,6 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, - "node_modules/dot-prop": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-3.0.0.tgz", - "integrity": "sha512-k4ELWeEU3uCcwub7+dWydqQBRjAjkV9L33HjVRG5Xo2QybI6ja/v+4W73SRi8ubCqJz0l9XsTP1NbewfyqaSlw==", - "dependencies": { - "is-obj": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/dotenv": { "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", @@ -2148,11 +2080,6 @@ "url": "https://dotenvx.com" } }, - "node_modules/duplexer3": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.5.tgz", - "integrity": "sha512-1A8za6ws41LQgv9HrE/66jyC5yuSjQ3L/KOpFtoBilsAK2iA2wuS5rTt1OCzIvtS2V7nVmedsUU+DGRcjBmOYA==" - }, "node_modules/ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -2565,67 +2492,23 @@ "node": ">=4" } }, - "node_modules/google-translate-api": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/google-translate-api/-/google-translate-api-2.3.0.tgz", - "integrity": "sha512-a7MRJpSAoS9HyQPE7Yqp5jYSRePWju53+Je/AkgU//zbSmZhy2tc+MvxlwbOegpptT7Ep6GCt7Q1/j7WmTntZw==", - "dependencies": { - "configstore": "^2.0.0", - "google-translate-token": "latest", - "got": "^6.3.0", - "safe-eval": "^0.3.0" - } - }, - "node_modules/google-translate-token": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/google-translate-token/-/google-translate-token-1.0.0.tgz", - "integrity": "sha512-X+cONF24KI3PP94ih3L8QlqNgVxZxsfOyJtX93UISO7TRdTSrFpp4rmDpyS/x6xRxJOLcd6ApCTAkB+tNFtc3g==", - "dependencies": { - "configstore": "^2.0.0", - "got": "^6.3.0" - } - }, - "node_modules/got": { - "version": "6.7.1", - "resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", - "integrity": "sha512-Y/K3EDuiQN9rTZhBvPRWMLXIKdeD1Rj0nzunfoi0Yyn5WBEbzxXKU9Ub2X41oZBagVWOBU3MuDonFMgPWQFnwg==", - "dependencies": { - "create-error-class": "^3.0.0", - "duplexer3": "^0.1.4", - "get-stream": "^3.0.0", - "is-redirect": "^1.0.0", - "is-retry-allowed": "^1.0.0", - "is-stream": "^1.0.0", - "lowercase-keys": "^1.0.0", - "safe-buffer": "^5.0.1", - "timed-out": "^4.0.0", - "unzip-response": "^2.0.1", - "url-parse-lax": "^1.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/got/node_modules/get-stream": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha512-GlhdIUuVakc8SJ6kK0zAFbiGzRFzNnY4jUuEbV9UROo4Y+0Ny4fjvcZFVTeDA4odpFyOQzaw6hXukJSq/f28sQ==", - "engines": { - "node": ">=4" - } - }, - "node_modules/got/node_modules/is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==", + "node_modules/google-translate-api-x": { + "version": "10.7.1", + "resolved": "https://registry.npmjs.org/google-translate-api-x/-/google-translate-api-x-10.7.1.tgz", + "integrity": "sha512-OdZDS6jRWzn1woOk62aOKQ5OyVaJSA+eyc6CktOWxo36IWfstOjwG/dkvnGl3Z2Sbpmk1A+jc2WwrBiRjqaY2A==", "engines": { - "node": ">=0.10.0" + "node": ">=14.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/AidanWelch" } }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true }, "node_modules/har-schema": { "version": "2.0.0", @@ -2781,6 +2664,7 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, "engines": { "node": ">=0.8.19" } @@ -2883,30 +2767,6 @@ "node": ">=0.12.0" } }, - "node_modules/is-obj": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", - "integrity": "sha512-l4RyHgRqGN4Y3+9JHVrNqO+tN0rV5My76uW5/nuO4K1b6vw5G8d/cmFjP9tRfEsdhZNt0IFdZuK/c2Vr4Nb+Qg==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-redirect": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-redirect/-/is-redirect-1.0.0.tgz", - "integrity": "sha512-cr/SlUEe5zOGmzvj9bUyC4LVvkNVAXu4GytXLNMr1pny+a65MpQ9IJzFHD5vi7FyJgb4qt27+eS3TuQnqB+RQw==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-retry-allowed": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz", - "integrity": "sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -3715,14 +3575,6 @@ "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==" }, - "node_modules/lowercase-keys": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", - "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -3854,25 +3706,6 @@ "node": "*" } }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -4034,14 +3867,6 @@ "node": "*" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -4066,32 +3891,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/os-tmpdir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/osenv": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", - "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", - "deprecated": "This package is no longer supported.", - "dependencies": { - "os-homedir": "^1.0.0", - "os-tmpdir": "^1.0.0" - } - }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -4273,14 +4072,6 @@ "node": ">=8" } }, - "node_modules/prepend-http": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz", - "integrity": "sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -4527,12 +4318,8 @@ "type": "consulting", "url": "https://feross.org/support" } - ] - }, - "node_modules/safe-eval": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/safe-eval/-/safe-eval-0.3.0.tgz", - "integrity": "sha512-uPIAjU2zpyv2QJCZ1zaWZKnPv/5jgkaitE7WHomV4Mxu6kgHY1ruIQ1oTikEta/Sux3E8pZAozzJRsAUu3iDZA==" + ], + "peer": true }, "node_modules/safer-buffer": { "version": "2.1.2", @@ -4614,14 +4401,6 @@ "node": ">=8" } }, - "node_modules/slide": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", - "integrity": "sha512-NwrtjCg+lZoqhFU8fOwl4ay2ei8PaqCBOUV3/ektPY9trO1yQ1oXEfmHAhKArUVUr/hOHvy5f6AdP17dCM0zMw==", - "engines": { - "node": "*" - } - }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -4799,14 +4578,6 @@ "node": ">=8" } }, - "node_modules/timed-out": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz", - "integrity": "sha512-G7r3AhovYtr5YKOWQkta8RKAPb+J9IsO4uVmzjl8AZwfhs8UcUwTiD6gcJYSgOtzyjvQKrKYn41syHbUWMkafA==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -4923,14 +4694,6 @@ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==" }, - "node_modules/unzip-response": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/unzip-response/-/unzip-response-2.0.1.tgz", - "integrity": "sha512-N0XH6lqDtFH84JxptQoZYmloF4nzrQqqrAymNj+/gW60AO2AZgOcf4O/nUXJcYfyQkqvMo9lSupBZmmgvuVXlw==", - "engines": { - "node": ">=4" - } - }, "node_modules/update-browserslist-db": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", @@ -4970,17 +4733,6 @@ "punycode": "^2.1.0" } }, - "node_modules/url-parse-lax": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-1.0.0.tgz", - "integrity": "sha512-BVA4lR5PIviy2PMseNd2jbFQ+jwSwQGdJejf5ctd1rEXt0Ypd7yanUK9+lYechVlN5VaTJGsu2U/3MDDu6KgBA==", - "dependencies": { - "prepend-http": "^1.0.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", @@ -5126,17 +4878,6 @@ } } }, - "node_modules/xdg-basedir": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-2.0.0.tgz", - "integrity": "sha512-NF1pPn594TaRSUO/HARoB4jK8I+rWgcpVlpQCK6/6o5PHyLUt2CSiDrpUZbQ6rROck+W2EwF8mBJcTs+W98J9w==", - "dependencies": { - "os-homedir": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 19e45e3..bba17fe 100755 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "discord.js": "^14.14.1", "dotenv": "^16.4.5", "fetch": "^1.1.0", - "google-translate-api": "^2.3.0", + "google-translate-api-x": "^10.7.1", "jest": "^29.7.0", "mariadb": "^3.3.0", "node-fetch": "^3.3.2", From eb24448aae7f2a5dbbc150d847c17c9c084ac319 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 15:05:59 +0200 Subject: [PATCH 05/38] updated packages --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 39946a9..7173c7d 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1619,9 +1619,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001664", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001664.tgz", - "integrity": "sha512-AmE7k4dXiNKQipgn7a2xg558IRqPN3jMQY/rOsbxDhrd0tyChwbITBfiwtnqz8bi2M5mIWbxAYBvk7W7QBUS2g==", + "version": "1.0.30001666", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001666.tgz", + "integrity": "sha512-gD14ICmoV5ZZM1OdzPWmpx+q4GyefaK06zi8hmfHV5xe4/2nOQX3+Dw5o+fSqOws2xVwL9j+anOPFwHzdEdV4g==", "dev": true, "funding": [ { @@ -2091,9 +2091,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.29", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.29.tgz", - "integrity": "sha512-PF8n2AlIhCKXQ+gTpiJi0VhcHDb69kYX4MtCiivctc2QD3XuNZ/XIOlbGzt7WAjjEev0TtaH6Cu3arZExm5DOw==", + "version": "1.5.31", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.31.tgz", + "integrity": "sha512-QcDoBbQeYt0+3CWcK/rEbuHvwpbT/8SV9T3OSgs6cX1FlcUAkgrkqbg9zLnDrMM/rLamzQwal4LYFCiWk861Tg==", "dev": true }, "node_modules/emittery": { From 73ec22bbb83f417f36f5d828684a5e46745b18f7 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 15:21:21 +0200 Subject: [PATCH 06/38] added json filled with correct language ISO codes, parsed json in translate.js --- commands/utility/translate.js | 11 +- data/language-codes.json | 937 ++++++++++++++++++++++++++++++++++ 2 files changed, 945 insertions(+), 3 deletions(-) create mode 100644 data/language-codes.json diff --git a/commands/utility/translate.js b/commands/utility/translate.js index 9b5849b..8b2aa46 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -1,8 +1,13 @@ const { SlashCommandBuilder } = require("discord.js"); const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); -const db = require("../../helpers/db"); const { logToFileAndDatabase } = require("../../helpers/logger"); const translate = require('google-translate-api-x'); +const fs = require('fs'); +const path = require('path'); + +const languageCodesPath = path.join(__dirname, '../../data/language-codes.json'); +const languageCodes = JSON.parse(fs.readFileSync(languageCodesPath, 'utf8')); +const supportedLanguages = languageCodes.map(lang => lang.code); module.exports = { data: new SlashCommandBuilder() @@ -17,13 +22,13 @@ module.exports = { .addStringOption(option => option .setName("target-language") - .setDescription("The language you would like to translate the message to (default: English).") + .setDescription("[ISO] The language you would like to translate the message to (default: English).") .setRequired(false) ) .addStringOption(option => option .setName("source-language") - .setDescription("The language you would like to translate the message from (default: auto detect).") + .setDescription("[ISO] The language you would like to translate the message from (default: auto detect).") .setRequired(false) ) .setDMPermission(true), diff --git a/data/language-codes.json b/data/language-codes.json new file mode 100644 index 0000000..a8f29bb --- /dev/null +++ b/data/language-codes.json @@ -0,0 +1,937 @@ +[ + { + "code": "aa", + "name": "Afar", + "native": "Afar" + }, + { + "code": "ab", + "name": "Abkhazian", + "native": "Аҧсуа" + }, + { + "code": "af", + "name": "Afrikaans", + "native": "Afrikaans" + }, + { + "code": "ak", + "name": "Akan", + "native": "Akana" + }, + { + "code": "am", + "name": "Amharic", + "native": "አማርኛ" + }, + { + "code": "an", + "name": "Aragonese", + "native": "Aragonés" + }, + { + "code": "ar", + "name": "Arabic", + "native": "العربية", + "rtl": 1 + }, + { + "code": "as", + "name": "Assamese", + "native": "অসমীয়া" + }, + { + "code": "av", + "name": "Avar", + "native": "Авар" + }, + { + "code": "ay", + "name": "Aymara", + "native": "Aymar" + }, + { + "code": "az", + "name": "Azerbaijani", + "native": "Azərbaycanca" + }, + { + "code": "ba", + "name": "Bashkir", + "native": "Башҡорт" + }, + { + "code": "be", + "name": "Belarusian", + "native": "Беларуская" + }, + { + "code": "bg", + "name": "Bulgarian", + "native": "Български" + }, + { + "code": "bh", + "name": "Bihari", + "native": "भोजपुरी" + }, + { + "code": "bi", + "name": "Bislama", + "native": "Bislama" + }, + { + "code": "bm", + "name": "Bambara", + "native": "Bamanankan" + }, + { + "code": "bn", + "name": "Bengali", + "native": "বাংলা" + }, + { + "code": "bo", + "name": "Tibetan", + "native": "བོད་ཡིག / Bod skad" + }, + { + "code": "br", + "name": "Breton", + "native": "Brezhoneg" + }, + { + "code": "bs", + "name": "Bosnian", + "native": "Bosanski" + }, + { + "code": "ca", + "name": "Catalan", + "native": "Català" + }, + { + "code": "ce", + "name": "Chechen", + "native": "Нохчийн" + }, + { + "code": "ch", + "name": "Chamorro", + "native": "Chamoru" + }, + { + "code": "co", + "name": "Corsican", + "native": "Corsu" + }, + { + "code": "cr", + "name": "Cree", + "native": "Nehiyaw" + }, + { + "code": "cs", + "name": "Czech", + "native": "Česky" + }, + { + "code": "cu", + "name": "Old Church Slavonic / Old Bulgarian", + "native": "словѣньскъ / slověnĭskŭ" + }, + { + "code": "cv", + "name": "Chuvash", + "native": "Чăваш" + }, + { + "code": "cy", + "name": "Welsh", + "native": "Cymraeg" + }, + { + "code": "da", + "name": "Danish", + "native": "Dansk" + }, + { + "code": "de", + "name": "German", + "native": "Deutsch" + }, + { + "code": "dv", + "name": "Divehi", + "native": "ދިވެހިބަސް", + "rtl": 1 + }, + { + "code": "dz", + "name": "Dzongkha", + "native": "ཇོང་ཁ" + }, + { + "code": "ee", + "name": "Ewe", + "native": "Ɛʋɛ" + }, + { + "code": "el", + "name": "Greek", + "native": "Ελληνικά" + }, + { + "code": "en", + "name": "English", + "native": "English" + }, + { + "code": "eo", + "name": "Esperanto", + "native": "Esperanto" + }, + { + "code": "es", + "name": "Spanish", + "native": "Español" + }, + { + "code": "et", + "name": "Estonian", + "native": "Eesti" + }, + { + "code": "eu", + "name": "Basque", + "native": "Euskara" + }, + { + "code": "fa", + "name": "Persian", + "native": "فارسی", + "rtl": 1 + }, + { + "code": "ff", + "name": "Peul", + "native": "Fulfulde" + }, + { + "code": "fi", + "name": "Finnish", + "native": "Suomi" + }, + { + "code": "fj", + "name": "Fijian", + "native": "Na Vosa Vakaviti" + }, + { + "code": "fo", + "name": "Faroese", + "native": "Føroyskt" + }, + { + "code": "fr", + "name": "French", + "native": "Français" + }, + { + "code": "fy", + "name": "West Frisian", + "native": "Frysk" + }, + { + "code": "ga", + "name": "Irish", + "native": "Gaeilge" + }, + { + "code": "gd", + "name": "Scottish Gaelic", + "native": "Gàidhlig" + }, + { + "code": "gl", + "name": "Galician", + "native": "Galego" + }, + { + "code": "gn", + "name": "Guarani", + "native": "Avañe'ẽ" + }, + { + "code": "gu", + "name": "Gujarati", + "native": "ગુજરાતી" + }, + { + "code": "gv", + "name": "Manx", + "native": "Gaelg" + }, + { + "code": "ha", + "name": "Hausa", + "native": "هَوُسَ", + "rtl": 1 + }, + { + "code": "he", + "name": "Hebrew", + "native": "עברית", + "rtl": 1 + }, + { + "code": "hi", + "name": "Hindi", + "native": "हिन्दी" + }, + { + "code": "ho", + "name": "Hiri Motu", + "native": "Hiri Motu" + }, + { + "code": "hr", + "name": "Croatian", + "native": "Hrvatski" + }, + { + "code": "ht", + "name": "Haitian", + "native": "Krèyol ayisyen" + }, + { + "code": "hu", + "name": "Hungarian", + "native": "Magyar" + }, + { + "code": "hy", + "name": "Armenian", + "native": "Հայերեն" + }, + { + "code": "hz", + "name": "Herero", + "native": "Otsiherero" + }, + { + "code": "ia", + "name": "Interlingua", + "native": "Interlingua" + }, + { + "code": "id", + "name": "Indonesian", + "native": "Bahasa Indonesia" + }, + { + "code": "ie", + "name": "Interlingue", + "native": "Interlingue" + }, + { + "code": "ig", + "name": "Igbo", + "native": "Igbo" + }, + { + "code": "ii", + "name": "Sichuan Yi", + "native": "ꆇꉙ / 四川彝语" + }, + { + "code": "ik", + "name": "Inupiak", + "native": "Iñupiak" + }, + { + "code": "io", + "name": "Ido", + "native": "Ido" + }, + { + "code": "is", + "name": "Icelandic", + "native": "Íslenska" + }, + { + "code": "it", + "name": "Italian", + "native": "Italiano" + }, + { + "code": "iu", + "name": "Inuktitut", + "native": "ᐃᓄᒃᑎᑐᑦ" + }, + { + "code": "ja", + "name": "Japanese", + "native": "日本語" + }, + { + "code": "jv", + "name": "Javanese", + "native": "Basa Jawa" + }, + { + "code": "ka", + "name": "Georgian", + "native": "ქართული" + }, + { + "code": "kg", + "name": "Kongo", + "native": "KiKongo" + }, + { + "code": "ki", + "name": "Kikuyu", + "native": "Gĩkũyũ" + }, + { + "code": "kj", + "name": "Kuanyama", + "native": "Kuanyama" + }, + { + "code": "kk", + "name": "Kazakh", + "native": "Қазақша" + }, + { + "code": "kl", + "name": "Greenlandic", + "native": "Kalaallisut" + }, + { + "code": "km", + "name": "Cambodian", + "native": "ភាសាខ្មែរ" + }, + { + "code": "kn", + "name": "Kannada", + "native": "ಕನ್ನಡ" + }, + { + "code": "ko", + "name": "Korean", + "native": "한국어" + }, + { + "code": "kr", + "name": "Kanuri", + "native": "Kanuri" + }, + { + "code": "ks", + "name": "Kashmiri", + "native": "कश्मीरी / كشميري", + "rtl": 1 + }, + { + "code": "ku", + "name": "Kurdish", + "native": "Kurdî / كوردی", + "rtl": 1 + }, + { + "code": "kv", + "name": "Komi", + "native": "Коми" + }, + { + "code": "kw", + "name": "Cornish", + "native": "Kernewek" + }, + { + "code": "ky", + "name": "Kirghiz", + "native": "Kırgızca / Кыргызча" + }, + { + "code": "la", + "name": "Latin", + "native": "Latina" + }, + { + "code": "lb", + "name": "Luxembourgish", + "native": "Lëtzebuergesch" + }, + { + "code": "lg", + "name": "Ganda", + "native": "Luganda" + }, + { + "code": "li", + "name": "Limburgian", + "native": "Limburgs" + }, + { + "code": "ln", + "name": "Lingala", + "native": "Lingála" + }, + { + "code": "lo", + "name": "Laotian", + "native": "ລາວ / Pha xa lao" + }, + { + "code": "lt", + "name": "Lithuanian", + "native": "Lietuvių" + }, + { + "code": "lu", + "name": "Luba-Katanga", + "native": "Tshiluba" + }, + { + "code": "lv", + "name": "Latvian", + "native": "Latviešu" + }, + { + "code": "mg", + "name": "Malagasy", + "native": "Malagasy" + }, + { + "code": "mh", + "name": "Marshallese", + "native": "Kajin Majel / Ebon" + }, + { + "code": "mi", + "name": "Maori", + "native": "Māori" + }, + { + "code": "mk", + "name": "Macedonian", + "native": "Македонски" + }, + { + "code": "ml", + "name": "Malayalam", + "native": "മലയാളം" + }, + { + "code": "mn", + "name": "Mongolian", + "native": "Монгол" + }, + { + "code": "mo", + "name": "Moldovan", + "native": "Moldovenească" + }, + { + "code": "mr", + "name": "Marathi", + "native": "मराठी" + }, + { + "code": "ms", + "name": "Malay", + "native": "Bahasa Melayu" + }, + { + "code": "mt", + "name": "Maltese", + "native": "bil-Malti" + }, + { + "code": "my", + "name": "Burmese", + "native": "မြန်မာစာ" + }, + { + "code": "na", + "name": "Nauruan", + "native": "Dorerin Naoero" + }, + { + "code": "nb", + "name": "Norwegian Bokmål", + "native": "Norsk bokmål" + }, + { + "code": "nd", + "name": "North Ndebele", + "native": "Sindebele" + }, + { + "code": "ne", + "name": "Nepali", + "native": "नेपाली" + }, + { + "code": "ng", + "name": "Ndonga", + "native": "Oshiwambo" + }, + { + "code": "nl", + "name": "Dutch", + "native": "Nederlands" + }, + { + "code": "nn", + "name": "Norwegian Nynorsk", + "native": "Norsk nynorsk" + }, + { + "code": "no", + "name": "Norwegian", + "native": "Norsk" + }, + { + "code": "nr", + "name": "South Ndebele", + "native": "isiNdebele" + }, + { + "code": "nv", + "name": "Navajo", + "native": "Diné bizaad" + }, + { + "code": "ny", + "name": "Chichewa", + "native": "Chi-Chewa" + }, + { + "code": "oc", + "name": "Occitan", + "native": "Occitan" + }, + { + "code": "oj", + "name": "Ojibwa", + "native": "ᐊᓂᔑᓈᐯᒧᐎᓐ / Anishinaabemowin" + }, + { + "code": "om", + "name": "Oromo", + "native": "Oromoo" + }, + { + "code": "or", + "name": "Oriya", + "native": "ଓଡ଼ିଆ" + }, + { + "code": "os", + "name": "Ossetian / Ossetic", + "native": "Иронау" + }, + { + "code": "pa", + "name": "Panjabi / Punjabi", + "native": "ਪੰਜਾਬੀ / पंजाबी / پنجابي" + }, + { + "code": "pi", + "name": "Pali", + "native": "Pāli / पाऴि" + }, + { + "code": "pl", + "name": "Polish", + "native": "Polski" + }, + { + "code": "ps", + "name": "Pashto", + "native": "پښتو", + "rtl": 1 + }, + { + "code": "pt", + "name": "Portuguese", + "native": "Português" + }, + { + "code": "qu", + "name": "Quechua", + "native": "Runa Simi" + }, + { + "code": "rm", + "name": "Raeto Romance", + "native": "Rumantsch" + }, + { + "code": "rn", + "name": "Kirundi", + "native": "Kirundi" + }, + { + "code": "ro", + "name": "Romanian", + "native": "Română" + }, + { + "code": "ru", + "name": "Russian", + "native": "Русский" + }, + { + "code": "rw", + "name": "Rwandi", + "native": "Kinyarwandi" + }, + { + "code": "sa", + "name": "Sanskrit", + "native": "संस्कृतम्" + }, + { + "code": "sc", + "name": "Sardinian", + "native": "Sardu" + }, + { + "code": "sd", + "name": "Sindhi", + "native": "सिनधि" + }, + { + "code": "se", + "name": "Northern Sami", + "native": "Sámegiella" + }, + { + "code": "sg", + "name": "Sango", + "native": "Sängö" + }, + { + "code": "sh", + "name": "Serbo-Croatian", + "native": "Srpskohrvatski / Српскохрватски" + }, + { + "code": "si", + "name": "Sinhalese", + "native": "සිංහල" + }, + { + "code": "sk", + "name": "Slovak", + "native": "Slovenčina" + }, + { + "code": "sl", + "name": "Slovenian", + "native": "Slovenščina" + }, + { + "code": "sm", + "name": "Samoan", + "native": "Gagana Samoa" + }, + { + "code": "sn", + "name": "Shona", + "native": "chiShona" + }, + { + "code": "so", + "name": "Somalia", + "native": "Soomaaliga" + }, + { + "code": "sq", + "name": "Albanian", + "native": "Shqip" + }, + { + "code": "sr", + "name": "Serbian", + "native": "Српски" + }, + { + "code": "ss", + "name": "Swati", + "native": "SiSwati" + }, + { + "code": "st", + "name": "Southern Sotho", + "native": "Sesotho" + }, + { + "code": "su", + "name": "Sundanese", + "native": "Basa Sunda" + }, + { + "code": "sv", + "name": "Swedish", + "native": "Svenska" + }, + { + "code": "sw", + "name": "Swahili", + "native": "Kiswahili" + }, + { + "code": "ta", + "name": "Tamil", + "native": "தமிழ்" + }, + { + "code": "te", + "name": "Telugu", + "native": "తెలుగు" + }, + { + "code": "tg", + "name": "Tajik", + "native": "Тоҷикӣ" + }, + { + "code": "th", + "name": "Thai", + "native": "ไทย / Phasa Thai" + }, + { + "code": "ti", + "name": "Tigrinya", + "native": "ትግርኛ" + }, + { + "code": "tk", + "name": "Turkmen", + "native": "Туркмен / تركمن" + }, + { + "code": "tl", + "name": "Tagalog / Filipino", + "native": "Tagalog" + }, + { + "code": "tn", + "name": "Tswana", + "native": "Setswana" + }, + { + "code": "to", + "name": "Tonga", + "native": "Lea Faka-Tonga" + }, + { + "code": "tr", + "name": "Turkish", + "native": "Türkçe" + }, + { + "code": "ts", + "name": "Tsonga", + "native": "Xitsonga" + }, + { + "code": "tt", + "name": "Tatar", + "native": "Tatarça" + }, + { + "code": "tw", + "name": "Twi", + "native": "Twi" + }, + { + "code": "ty", + "name": "Tahitian", + "native": "Reo Mā`ohi" + }, + { + "code": "ug", + "name": "Uyghur", + "native": "Uyƣurqə / ئۇيغۇرچە" + }, + { + "code": "uk", + "name": "Ukrainian", + "native": "Українська" + }, + { + "code": "ur", + "name": "Urdu", + "native": "اردو", + "rtl": 1 + }, + { + "code": "uz", + "name": "Uzbek", + "native": "Ўзбек" + }, + { + "code": "ve", + "name": "Venda", + "native": "Tshivenḓa" + }, + { + "code": "vi", + "name": "Vietnamese", + "native": "Tiếng Việt" + }, + { + "code": "vo", + "name": "Volapük", + "native": "Volapük" + }, + { + "code": "wa", + "name": "Walloon", + "native": "Walon" + }, + { + "code": "wo", + "name": "Wolof", + "native": "Wollof" + }, + { + "code": "xh", + "name": "Xhosa", + "native": "isiXhosa" + }, + { + "code": "yi", + "name": "Yiddish", + "native": "ייִדיש", + "rtl": 1 + }, + { + "code": "yo", + "name": "Yoruba", + "native": "Yorùbá" + }, + { + "code": "za", + "name": "Zhuang", + "native": "Cuengh / Tôô / 壮语" + }, + { + "code": "zh", + "name": "Chinese", + "native": "中文" + }, + { + "code": "zu", + "name": "Zulu", + "native": "isiZulu" + } +] \ No newline at end of file From 7da1d86aa699984164d2d84993bca4e9de5a9f9a Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 18:39:37 +0200 Subject: [PATCH 07/38] added iso code checks --- commands/utility/translate.js | 39 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/commands/utility/translate.js b/commands/utility/translate.js index 8b2aa46..50c3969 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -23,12 +23,16 @@ module.exports = { option .setName("target-language") .setDescription("[ISO] The language you would like to translate the message to (default: English).") + .setMinLength(2) + .setMaxLength(2) .setRequired(false) ) .addStringOption(option => option .setName("source-language") .setDescription("[ISO] The language you would like to translate the message from (default: auto detect).") + .setMinLength(2) + .setMaxLength(2) .setRequired(false) ) .setDMPermission(true), @@ -37,23 +41,40 @@ module.exports = { const sourceLanguage = interaction.options.getString("source-language") || "auto"; const targetLanguage = interaction.options.getString("target-language") || "en"; console.log(message, sourceLanguage, targetLanguage); - try { - const res = await translate(message, { from: sourceLanguage, to: targetLanguage }); - var embedReply = embedReplyPrimaryColor( - "Translation", - res.text, + if (sourceLanguage !== "auto" && !supportedLanguages.includes(sourceLanguage)) { + var embedReply = embedReplyFailureColor( + "Translation: Error", + `The source language code *"${sourceLanguage}"* isn't supported.\nPlease use a valid ISO language code.`, interaction ); } - catch (error) { - console.error(error); + else if (!supportedLanguages.includes(targetLanguage)) { var embedReply = embedReplyFailureColor( - "Translation", - `An error occurred while translating the message. Please try again later.`, + "Translation: Error", + `The target language code *"${targetLanguage}"* isn't supported.\nPlease use a valid ISO language code.`, interaction ); } + else { + try { + const res = await translate(message, { from: sourceLanguage, to: targetLanguage }); + + var embedReply = embedReplyPrimaryColor( + "Translation", + res.text, + interaction + ); + } + catch (error) { + console.error(error); + var embedReply = embedReplyFailureColor( + "Translation: Error", + `An error occurred while translating the message. Please try again later.`, + interaction + ); + } + } await interaction.reply({ embeds: [embedReply] }); From e245ed1f44484b1c680acc07920c17cb510761fe Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 18:51:12 +0200 Subject: [PATCH 08/38] updated embed reply design --- commands/utility/translate.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/commands/utility/translate.js b/commands/utility/translate.js index 50c3969..fe76187 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require("discord.js"); -const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); +const { embedReplyPrimaryColorWithFields, embedReplyFailureColor } = require("../../helpers/embed-reply"); const { logToFileAndDatabase } = require("../../helpers/logger"); const translate = require('google-translate-api-x'); const fs = require('fs'); @@ -60,9 +60,14 @@ module.exports = { try { const res = await translate(message, { from: sourceLanguage, to: targetLanguage }); - var embedReply = embedReplyPrimaryColor( + var embedReply = embedReplyPrimaryColorWithFields( "Translation", res.text, + [ + { name: "Original message:", value: message }, + { name: "From:", value: sourceLanguage, inline: true }, + { name: "To:", value: targetLanguage, inline: true } + ], interaction ); } From 2e89647f4f703e5c44c229ae9450be098e070692 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 18:56:33 +0200 Subject: [PATCH 09/38] updated formatting --- commands/utility/translate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/utility/translate.js b/commands/utility/translate.js index fe76187..8559f9d 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -62,9 +62,9 @@ module.exports = { var embedReply = embedReplyPrimaryColorWithFields( "Translation", - res.text, + `"${res.text}"`, [ - { name: "Original message:", value: message }, + { name: "Original message:", value: `*"${message}"*` }, { name: "From:", value: sourceLanguage, inline: true }, { name: "To:", value: targetLanguage, inline: true } ], From e51e92c59bf9ec95c70a010cc28adb2aeb32cc0d Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 20:38:35 +0200 Subject: [PATCH 10/38] mapped and displayed complete language names in embed response --- commands/utility/translate.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/commands/utility/translate.js b/commands/utility/translate.js index 8559f9d..e3482fc 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -8,6 +8,11 @@ const path = require('path'); const languageCodesPath = path.join(__dirname, '../../data/language-codes.json'); const languageCodes = JSON.parse(fs.readFileSync(languageCodesPath, 'utf8')); const supportedLanguages = languageCodes.map(lang => lang.code); +const languageMap = languageCodes.reduce((map, lang) => { + map[lang.code] = lang.name; + return map; +}, {}); + module.exports = { data: new SlashCommandBuilder() @@ -60,13 +65,19 @@ module.exports = { try { const res = await translate(message, { from: sourceLanguage, to: targetLanguage }); + const detectedSourceLanguage = res.from.language.iso; + const sourceLanguageName = sourceLanguage === "auto" + ? `${languageMap[detectedSourceLanguage]} (${detectedSourceLanguage})\n*(Auto-detected)*` + : `${languageMap[sourceLanguage]} (${sourceLanguage})`; + const targetLanguageName = `${languageMap[targetLanguage]} (${targetLanguage})`; + var embedReply = embedReplyPrimaryColorWithFields( "Translation", - `"${res.text}"`, + res.text, [ { name: "Original message:", value: `*"${message}"*` }, - { name: "From:", value: sourceLanguage, inline: true }, - { name: "To:", value: targetLanguage, inline: true } + { name: "From:", value: sourceLanguageName, inline: true }, + { name: "To:", value: targetLanguageName, inline: true } ], interaction ); From bf05448c029d46807d551a43271a3af375a5427d Mon Sep 17 00:00:00 2001 From: vb2007 Date: Wed, 2 Oct 2024 20:41:10 +0200 Subject: [PATCH 11/38] added command to /help --- commands/utility/help.js | 1 + commands/utility/translate.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/utility/help.js b/commands/utility/help.js index 2f8558c..806564c 100755 --- a/commands/utility/help.js +++ b/commands/utility/help.js @@ -29,6 +29,7 @@ module.exports = { "`/ping-db` - Displays the current latency between the bot and it's database.\n" + "`/server` - Provides information about the current server.\n" + "`/user` - Provides information about a specified user.\n" + + "`/translate` - Translates a message from any language to any language.\n" + "`/say` - Makes the bot say a specified message." }; diff --git a/commands/utility/translate.js b/commands/utility/translate.js index e3482fc..9f7ea91 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -75,7 +75,7 @@ module.exports = { "Translation", res.text, [ - { name: "Original message:", value: `*"${message}"*` }, + { name: "Original message:", value: `*${message}*` }, { name: "From:", value: sourceLanguageName, inline: true }, { name: "To:", value: targetLanguageName, inline: true } ], From 8cd31507cf262c6cf4c220fa6b1f3e4935cb624f Mon Sep 17 00:00:00 2001 From: vb2007 Date: Thu, 3 Oct 2024 18:46:36 +0200 Subject: [PATCH 12/38] addedf welcome-configure and made base template for /welcome-disable --- commands/administration/welcome-configure.js | 0 commands/administration/welcome-disable.js | 38 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 commands/administration/welcome-configure.js create mode 100644 commands/administration/welcome-disable.js diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js new file mode 100644 index 0000000..e69de29 diff --git a/commands/administration/welcome-disable.js b/commands/administration/welcome-disable.js new file mode 100644 index 0000000..d34073e --- /dev/null +++ b/commands/administration/welcome-disable.js @@ -0,0 +1,38 @@ +const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js"); +const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); +const { logToFileAndDatabase } = require("../../helpers/logger"); +const db = require("../../helpers/db"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("welcome-disable") + .setDescription("Disables welcome messages for the current server.") + .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) + .setDMPermission(false), + async execute(interaction) { + if (!interaction.inGuild()) { + var embedReply = embedReplyFailureColor( + "Welcome Disable: Error", + "You can only disable the welcome messages in a server.", + interaction + ); + } + else if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administrator)) { + var embedReply = embedReplyFailureColor( + "Welcome Disable: Error", + "This feature requires **administrator** *(8)* privileges which the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges.", + interaction + ); + } + else { + try { + + } + catch (error) { + + } + } + + await interaction.reply({ embeds: [embedReply] }); + } +} \ No newline at end of file From b9809f4f6512ec63f0e76e58ff51dbd355120ae0 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Thu, 3 Oct 2024 18:47:58 +0200 Subject: [PATCH 13/38] added error handling --- commands/administration/welcome-disable.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/administration/welcome-disable.js b/commands/administration/welcome-disable.js index d34073e..73902bb 100644 --- a/commands/administration/welcome-disable.js +++ b/commands/administration/welcome-disable.js @@ -29,7 +29,12 @@ module.exports = { } catch (error) { - + var embedReply = embedReplyFailureColor( + "Welcome Disable: Error", + "There was an error while trying to disable the welcome messages.", + interaction + ); + // console.error(error); } } From cdf8175e37e8a749c44e409bb621854219a72526 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Thu, 3 Oct 2024 18:55:47 +0200 Subject: [PATCH 14/38] added base table schema for welcome table --- sql/welcome/table.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 sql/welcome/table.sql diff --git a/sql/welcome/table.sql b/sql/welcome/table.sql new file mode 100644 index 0000000..d720f5f --- /dev/null +++ b/sql/welcome/table.sql @@ -0,0 +1,10 @@ +-- discordbot.welcome definition + +CREATE TABLE IF NOT EXISTS `welcome` ( + `guildId` varchar(50) NOT NULL, + `welcomeMessage` text DEFAULT NULL, + `addedAt` timestamp NOT NULL DEFAULT current_timestamp(), + `adderId` text DEFAULT NULL, + `adderUsername` text DEFAULT NULL, + PRIMARY KEY (`guildId`) +); \ No newline at end of file From 665c3ef249293716835665861074911dcc7346e8 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Thu, 3 Oct 2024 19:14:47 +0200 Subject: [PATCH 15/38] updated guildMemberAdd event --- events/guildMemberAdd.js | 21 ++++++++++++++++++++- sql/welcome/table.sql | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index ac1d1de..6199092 100755 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -5,6 +5,7 @@ module.exports = { async execute(member) { const guildId = member.guild.id; + //autorole try { const rows = await db.query("SELECT roleId FROM autorole WHERE guildId = ?", [guildId]); const roleId = rows[0].roleId; @@ -18,7 +19,25 @@ module.exports = { } } catch (error) { - console.error(error); + console.error(`Failed to addign role: ${error}`); + } + + //welcome messages + try { + const rows = await db.query("SELECT channelId, message FROM welcome WHERE guildId = ?", [guildId]); + const channelId = rows[0].channelId; + const message = rows[0].message; + + if (channelId && message) { + const channel = member.guild.channels.cache.get(channelId); + if (channel) { + await channel.send(message.replace("{user}", member.user.tag)); + console.log(`Sent welcome message to ${member.user.tag} in ${member.guild.name}`); + } + } + } + catch (error) { + console.error(`Failed to display welcome message: ${error}`); } }, }; \ No newline at end of file diff --git a/sql/welcome/table.sql b/sql/welcome/table.sql index d720f5f..94ef964 100644 --- a/sql/welcome/table.sql +++ b/sql/welcome/table.sql @@ -2,7 +2,8 @@ CREATE TABLE IF NOT EXISTS `welcome` ( `guildId` varchar(50) NOT NULL, - `welcomeMessage` text DEFAULT NULL, + `channelId` text DEFAULT NULL, + `message` text DEFAULT NULL, `addedAt` timestamp NOT NULL DEFAULT current_timestamp(), `adderId` text DEFAULT NULL, `adderUsername` text DEFAULT NULL, From 5e2022b0bf5b32d13c74d2f57f26ad53c1110fd8 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Thu, 3 Oct 2024 19:16:42 +0200 Subject: [PATCH 16/38] updated packages --- package-lock.json | 214 +++++++++++++++++++++++----------------------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7173c7d..3c3796a 100755 --- a/package-lock.json +++ b/package-lock.json @@ -39,12 +39,12 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", - "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.25.7.tgz", + "integrity": "sha512-0xZJFNE5XMpENsgfHYTw8FbX4kv53mFLn2i3XPoq69LyhYSCBJtitaHx9QnsVTrsogI4Z3+HtEfZ2/GFPOtf5g==", "dev": true, "dependencies": { - "@babel/highlight": "^7.24.7", + "@babel/highlight": "^7.25.7", "picocolors": "^1.0.0" }, "engines": { @@ -52,30 +52,30 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.25.4.tgz", - "integrity": "sha512-+LGRog6RAsCJrrrg/IO6LGmpphNe5DiK30dGjCoxxeGv49B10/3XYGxPsAwrDlMFcFEvdAUavDT8r9k/hSyQqQ==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.25.7.tgz", + "integrity": "sha512-9ickoLz+hcXCeh7jrcin+/SLWm+GkxE2kTvoYyp38p4WkdFXfQJxDFGWp/YHjiKLPx06z2A7W8XKuqbReXDzsw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.25.2", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.25.2.tgz", - "integrity": "sha512-BBt3opiCOxUr9euZ5/ro/Xv8/V7yJ5bjYMqG/C1YAo8MIKAnumZalCN+msbci3Pigy4lIQfPUpfMM27HMGaYEA==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.25.7.tgz", + "integrity": "sha512-yJ474Zv3cwiSOO9nXJuqzvwEeM+chDuQ8GJirw+pZ91sCGCyOZ3dJkVE09fTV0VEVzXyLWhh3G/AolYTPX7Mow==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.24.7", - "@babel/generator": "^7.25.0", - "@babel/helper-compilation-targets": "^7.25.2", - "@babel/helper-module-transforms": "^7.25.2", - "@babel/helpers": "^7.25.0", - "@babel/parser": "^7.25.0", - "@babel/template": "^7.25.0", - "@babel/traverse": "^7.25.2", - "@babel/types": "^7.25.2", + "@babel/code-frame": "^7.25.7", + "@babel/generator": "^7.25.7", + "@babel/helper-compilation-targets": "^7.25.7", + "@babel/helper-module-transforms": "^7.25.7", + "@babel/helpers": "^7.25.7", + "@babel/parser": "^7.25.7", + "@babel/template": "^7.25.7", + "@babel/traverse": "^7.25.7", + "@babel/types": "^7.25.7", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -91,29 +91,29 @@ } }, "node_modules/@babel/generator": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.25.6.tgz", - "integrity": "sha512-VPC82gr1seXOpkjAAKoLhP50vx4vGNlF4msF64dSFq1P8RfB+QAuJWGHPXXPc8QyfVWwwB/TNNU4+ayZmHNbZw==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.25.7.tgz", + "integrity": "sha512-5Dqpl5fyV9pIAD62yK9P7fcA768uVPUyrQmqpqstHWgMma4feF1x/oFysBCVZLY5wJ2GkMUCdsNDnGZrPoR6rA==", "dev": true, "dependencies": { - "@babel/types": "^7.25.6", + "@babel/types": "^7.25.7", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", - "jsesc": "^2.5.1" + "jsesc": "^3.0.2" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.25.2", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.2.tgz", - "integrity": "sha512-U2U5LsSaZ7TAt3cfaymQ8WHh0pxvdHoEk6HVpaexxixjyEquMh0L0YNJNM6CTGKMXV1iksi0iZkGw4AcFkPaaw==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.7.tgz", + "integrity": "sha512-DniTEax0sv6isaw6qSQSfV4gVRNtw2rte8HHM45t9ZR0xILaufBRNkpMifCRiAPyvL4ACD6v0gfCwCmtOQaV4A==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.25.2", - "@babel/helper-validator-option": "^7.24.8", - "browserslist": "^4.23.1", + "@babel/compat-data": "^7.25.7", + "@babel/helper-validator-option": "^7.25.7", + "browserslist": "^4.24.0", "lru-cache": "^5.1.1", "semver": "^6.3.1" }, @@ -122,28 +122,28 @@ } }, "node_modules/@babel/helper-module-imports": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.7.tgz", - "integrity": "sha512-8AyH3C+74cgCVVXow/myrynrAGv+nTVg5vKu2nZph9x7RcRwzmh0VFallJuFTZ9mx6u4eSdXZfcOzSqTUm0HCA==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.25.7.tgz", + "integrity": "sha512-o0xCgpNmRohmnoWKQ0Ij8IdddjyBFE4T2kagL/x6M3+4zUgc+4qTOUBoNe4XxDskt1HPKO007ZPiMgLDq2s7Kw==", "dev": true, "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" + "@babel/traverse": "^7.25.7", + "@babel/types": "^7.25.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.25.2", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.25.2.tgz", - "integrity": "sha512-BjyRAbix6j/wv83ftcVJmBt72QtHI56C7JXZoG2xATiLpmoC7dpd8WnkikExHDVPpi/3qCmO6WY1EaXOluiecQ==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.25.7.tgz", + "integrity": "sha512-k/6f8dKG3yDz/qCwSM+RKovjMix563SLxQFo0UhRNo239SP6n9u5/eLtKD6EAjwta2JHJ49CsD8pms2HdNiMMQ==", "dev": true, "dependencies": { - "@babel/helper-module-imports": "^7.24.7", - "@babel/helper-simple-access": "^7.24.7", - "@babel/helper-validator-identifier": "^7.24.7", - "@babel/traverse": "^7.25.2" + "@babel/helper-module-imports": "^7.25.7", + "@babel/helper-simple-access": "^7.25.7", + "@babel/helper-validator-identifier": "^7.25.7", + "@babel/traverse": "^7.25.7" }, "engines": { "node": ">=6.9.0" @@ -153,74 +153,74 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.8.tgz", - "integrity": "sha512-FFWx5142D8h2Mgr/iPVGH5G7w6jDn4jUSpZTyDnQO0Yn7Ks2Kuz6Pci8H6MPCoUJegd/UZQ3tAvfLCxQSnWWwg==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.25.7.tgz", + "integrity": "sha512-eaPZai0PiqCi09pPs3pAFfl/zYgGaE6IdXtYvmf0qlcDTd3WCtO7JWCcRd64e0EQrcYgiHibEZnOGsSY4QSgaw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-simple-access": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.7.tgz", - "integrity": "sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.25.7.tgz", + "integrity": "sha512-FPGAkJmyoChQeM+ruBGIDyrT2tKfZJO8NcxdC+CWNJi7N8/rZpSxK7yvBJ5O/nF1gfu5KzN7VKG3YVSLFfRSxQ==", "dev": true, "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" + "@babel/traverse": "^7.25.7", + "@babel/types": "^7.25.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz", - "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.7.tgz", + "integrity": "sha512-CbkjYdsJNHFk8uqpEkpCvRs3YRp9tY6FmFY7wLMSYuGYkrdUi7r2lc4/wqsvlHoMznX3WJ9IP8giGPq68T/Y6g==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", - "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.7.tgz", + "integrity": "sha512-AM6TzwYqGChO45oiuPqwL2t20/HdMC1rTPAesnBCgPCSF1x3oN9MVUwQV2iyz4xqWrctwK5RNC8LV22kaQCNYg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-option": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.8.tgz", - "integrity": "sha512-xb8t9tD1MHLungh/AIoWYN+gVHaB9kwlu8gffXGSt3FFEIT7RjS+xWbc2vUD1UTZdIpKj/ab3rdqJ7ufngyi2Q==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.25.7.tgz", + "integrity": "sha512-ytbPLsm+GjArDYXJ8Ydr1c/KJuutjF2besPNbIZnZ6MKUxi/uTA22t2ymmA4WFjZFpjiAMO0xuuJPqK2nvDVfQ==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.25.6.tgz", - "integrity": "sha512-Xg0tn4HcfTijTwfDwYlvVCl43V6h4KyVVX2aEm4qdO/PC6L2YvzLHFdmxhoeSA3eslcE6+ZVXHgWwopXYLNq4Q==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.25.7.tgz", + "integrity": "sha512-Sv6pASx7Esm38KQpF/U/OXLwPPrdGHNKoeblRxgZRLXnAtnkEe4ptJPDtAZM7fBLadbc1Q07kQpSiGQ0Jg6tRA==", "dev": true, "dependencies": { - "@babel/template": "^7.25.0", - "@babel/types": "^7.25.6" + "@babel/template": "^7.25.7", + "@babel/types": "^7.25.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", - "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.25.7.tgz", + "integrity": "sha512-iYyACpW3iW8Fw+ZybQK+drQre+ns/tKpXbNESfrhNnPLIklLbXr7MYJ6gPEd0iETGLOK+SxMjVvKb/ffmk+FEw==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.24.7", + "@babel/helper-validator-identifier": "^7.25.7", "chalk": "^2.4.2", "js-tokens": "^4.0.0", "picocolors": "^1.0.0" @@ -301,12 +301,12 @@ } }, "node_modules/@babel/parser": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.6.tgz", - "integrity": "sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.7.tgz", + "integrity": "sha512-aZn7ETtQsjjGG5HruveUK06cU3Hljuhd9Iojm4M8WWv3wLE6OkE5PWbDUkItmMgegmccaITudyuW5RPYrYlgWw==", "dev": true, "dependencies": { - "@babel/types": "^7.25.6" + "@babel/types": "^7.25.7" }, "bin": { "parser": "bin/babel-parser.js" @@ -367,12 +367,12 @@ } }, "node_modules/@babel/plugin-syntax-import-attributes": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.25.6.tgz", - "integrity": "sha512-sXaDXaJN9SNLymBdlWFA+bjzBhFD617ZaFiY13dGt7TVslVvVgA6fkZOP7Ki3IGElC45lwHdOTrCtKZGVAWeLQ==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.25.7.tgz", + "integrity": "sha512-AqVo+dguCgmpi/3mYBdu9lkngOBlQ2w2vnNpa6gfiCxQZLzV4ZbhsXitJ2Yblkoe1VQwtHSaNmIaGll/26YWRw==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.8" + "@babel/helper-plugin-utils": "^7.25.7" }, "engines": { "node": ">=6.9.0" @@ -406,12 +406,12 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.7.tgz", - "integrity": "sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.25.7.tgz", + "integrity": "sha512-ruZOnKO+ajVL/MVx+PwNBPOkrnXTXoWMtte1MBpegfCArhqOe3Bj52avVj1huLLxNKYKXYaSxZ2F+woK1ekXfw==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.7" + "@babel/helper-plugin-utils": "^7.25.7" }, "engines": { "node": ">=6.9.0" @@ -523,12 +523,12 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.25.4.tgz", - "integrity": "sha512-uMOCoHVU52BsSWxPOMVv5qKRdeSlPuImUCB2dlPuBSU+W2/ROE7/Zg8F2Kepbk+8yBa68LlRKxO+xgEVWorsDg==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.25.7.tgz", + "integrity": "sha512-rR+5FDjpCHqqZN2bzZm18bVYGaejGq5ZkpVCJLXor/+zlSrSoc4KWcHI0URVWjl/68Dyr1uwZUz/1njycEAv9g==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.8" + "@babel/helper-plugin-utils": "^7.25.7" }, "engines": { "node": ">=6.9.0" @@ -538,30 +538,30 @@ } }, "node_modules/@babel/template": { - "version": "7.25.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz", - "integrity": "sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.7.tgz", + "integrity": "sha512-wRwtAgI3bAS+JGU2upWNL9lSlDcRCqD05BZ1n3X2ONLH1WilFP6O1otQjeMK/1g0pvYcXC7b/qVUB1keofjtZA==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/parser": "^7.25.0", - "@babel/types": "^7.25.0" + "@babel/code-frame": "^7.25.7", + "@babel/parser": "^7.25.7", + "@babel/types": "^7.25.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.6.tgz", - "integrity": "sha512-9Vrcx5ZW6UwK5tvqsj0nGpp/XzqthkT0dqIc9g1AdtygFToNtTF67XzYS//dm+SAK9cp3B9R4ZO/46p63SCjlQ==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.7.tgz", + "integrity": "sha512-jatJPT1Zjqvh/1FyJs6qAHL+Dzb7sTb+xr7Q+gM1b+1oBsMsQQ4FkVKb6dFlJvLlVssqkRzV05Jzervt9yhnzg==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/generator": "^7.25.6", - "@babel/parser": "^7.25.6", - "@babel/template": "^7.25.0", - "@babel/types": "^7.25.6", + "@babel/code-frame": "^7.25.7", + "@babel/generator": "^7.25.7", + "@babel/parser": "^7.25.7", + "@babel/template": "^7.25.7", + "@babel/types": "^7.25.7", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -570,13 +570,13 @@ } }, "node_modules/@babel/types": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.6.tgz", - "integrity": "sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw==", + "version": "7.25.7", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.7.tgz", + "integrity": "sha512-vwIVdXG+j+FOpkwqHRcBgHLYNL7XMkufrlaFvL9o6Ai9sJn9+PdyIL5qa0XzTZw084c+u9LOls53eoZWP/W5WQ==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.24.8", - "@babel/helper-validator-identifier": "^7.24.7", + "@babel/helper-string-parser": "^7.25.7", + "@babel/helper-validator-identifier": "^7.25.7", "to-fast-properties": "^2.0.0" }, "engines": { @@ -3468,15 +3468,15 @@ "peer": true }, "node_modules/jsesc": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", - "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz", + "integrity": "sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==", "dev": true, "bin": { "jsesc": "bin/jsesc" }, "engines": { - "node": ">=4" + "node": ">=6" } }, "node_modules/json-parse-even-better-errors": { From 066029a69dd54a1a5aa4ca1c33f9e46b417844f0 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Thu, 3 Oct 2024 19:25:35 +0200 Subject: [PATCH 17/38] added base concept for welcome-configure --- commands/administration/autorole-configure.js | 2 +- commands/administration/welcome-configure.js | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/commands/administration/autorole-configure.js b/commands/administration/autorole-configure.js index 790c614..ac7f3c1 100755 --- a/commands/administration/autorole-configure.js +++ b/commands/administration/autorole-configure.js @@ -20,7 +20,7 @@ module.exports = { var localEmbedResponse = embedReply( embedColors.failure, "AutoRole Configure: Error", - "You can only set autorole in a server.", + "You can only set up autorole in a server.", interaction ); } diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index e69de29..5c9d483 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -0,0 +1,39 @@ +const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js"); +const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); +const { logToFileAndDatabase } = require("../../helpers/logger"); +const db = require("../../helpers/db"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("welcome-configure") + .setDescription("Sets a welcome message that will be displayed for the new members in a specified channel.") + .addChannelOption(option => + option + .setName("channel") + .setDescription("A channel where the welcome message will be displayed.") + .setRequired(true) + ) + .addStringOption(option => + option + .setName("message") + .setDescription("A message that the new members will see. You can use the following placeholders: {user} - the new member's username, {server} - the server's name, {memberCount} - the server's member count.") + .setRequired(true) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) + .setDMPermission(false), + async execute(interaction) { + if (!interaction.inGuild()) { + var embedReply = embedReplyFailureColor( + "Welcome Configure: Error", + "You can only set a welcome message in a server.", + interaction + ); + } + + await interaction.reply({ embeds: [embedReply] }); + + //logging + const response = JSON.stringify(embedReply.toJSON()); + await logToFileAndDatabase(interaction, response); + } +} \ No newline at end of file From 91dd48a82403c5cf1113f7f9e981b25643c9b7da Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 17:50:38 +0200 Subject: [PATCH 18/38] made table selection script execute more queries --- create-tables.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/create-tables.js b/create-tables.js index 1ea44df..cf8f197 100755 --- a/create-tables.js +++ b/create-tables.js @@ -1,6 +1,7 @@ const fs = require("fs"); const path = require("path"); const db = require("./helpers/db"); +db.getConnection(); // reads the SQL queries from a folder's subfolder function readSQLFiles(dir) { @@ -9,8 +10,8 @@ function readSQLFiles(dir) { for (const file of sqlFiles) { const filePath = path.join(dir, file); - const query = fs.readFileSync(filePath, "utf8"); - sqlQueries.push(query); + const queries = fs.readFileSync(filePath, "utf8").split(';').filter(query => query.trim() !== ''); + sqlQueries.push(...queries); } return sqlQueries; @@ -37,21 +38,21 @@ async function createTables() { } } - //executes the table creation queries + //executes the table creation (and other) queries for (const query of sqlQueries) { try { await db.query(query); - console.log("Table created successfully."); + console.log("Query executed successfully."); } catch (error) { - console.error("Error creating table: ", error); + console.error("Error executing query: ", error); } } - console.log("All tables are processed.") ; + console.log("All queries are executed & all tables are processed."); } catch (error) { - console.error("Error creating tables: ", error); + console.error("Error executing queries & creating tables: ", error); } } From 3c01b4ac44195652b62d6fee9fb54020e650acb8 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 17:51:13 +0200 Subject: [PATCH 19/38] fixed syntax errors in table creation scripts --- sql/economy/table.sql | 2 +- sql/log/table.sql | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/economy/table.sql b/sql/economy/table.sql index 5798a70..e66eef5 100644 --- a/sql/economy/table.sql +++ b/sql/economy/table.sql @@ -17,4 +17,4 @@ CREATE TABLE IF NOT EXISTS `economy` ( PRIMARY KEY (`id`) ); -CREATE INDEX idx_userId ON economy(userId); \ No newline at end of file +CREATE INDEX IF NOT EXISTS idx_userId ON economy(userId); \ No newline at end of file diff --git a/sql/log/table.sql b/sql/log/table.sql index d7c8853..766ee04 100755 --- a/sql/log/table.sql +++ b/sql/log/table.sql @@ -2,7 +2,8 @@ CREATE TABLE IF NOT EXISTS `log` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, - `commandName` tinytext DEFAULT NULL, --tinytext = max. 255 characters + `commandName` tinytext DEFAULT NULL, + /* tinytext = max. 255 characters */ `executorUserName` text DEFAULT NULL, `executorUserId` bigint(20) DEFAULT NULL, `isInServer` tinyint(1) DEFAULT NULL, From 7c74fe2ecc7a6aa04869e8b8b5942433292695e3 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 17:52:13 +0200 Subject: [PATCH 20/38] made welcome-configure actually do something --- commands/administration/autorole-configure.js | 4 +- commands/administration/welcome-configure.js | 66 ++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/commands/administration/autorole-configure.js b/commands/administration/autorole-configure.js index ac7f3c1..00e4e95 100755 --- a/commands/administration/autorole-configure.js +++ b/commands/administration/autorole-configure.js @@ -43,12 +43,12 @@ module.exports = { const autoRoleGuildId = query[0]?.guildId || null; const autoRoleRoleId = query[0]?.roleId || null; - //if autorole has already been configured at this server... + //if autorole has already been configured for this server... if (autoRoleRoleId == targetRole) { var localEmbedResponse = embedReply( embedColors.failure, "AutoRole Configure: Error", - "Autorole has been already configured for this server with this role. :x:\nRun the command with another role to overwrite the current role.\nRun `/autorole-disable` to disable this feature.", + "Autorole has already been configured for this server with this role. :x:\nRun the command with another role to overwrite the current role.\nRun `/autorole-disable` to disable this feature completely.", interaction ); } diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index 5c9d483..1ced9e5 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js"); -const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); +const { embedReplySuccessColor, embedReplySuccessSecondaryColor, embedReplyWarningColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); const { logToFileAndDatabase } = require("../../helpers/logger"); const db = require("../../helpers/db"); @@ -29,6 +29,70 @@ module.exports = { interaction ); } + else if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administrator)) { + var embedReply = embedReplyFailureColor( + "Welcome Disable: Error", + "This feature requires **administrator** *(8)* privileges which the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges.", + interaction + ); + } + else { + try { + const channelId = interaction.options.get("channel"); + const welcomeMessage = interaction.options.getString("message"); + const guildId = interaction.guild.id; + const adderId = interaction.user.id; + const adderUsername = interaction.user.username; + + const query = await db.query("SELECT guildId, channelId, message FROM welcome WHERE guildId = ?", [guildId]); + const existingChannelId = query[0]?.channelId || null; + const existingWelcomeMessage = query[0]?.message || null; + const existingGuildId = query[0]?.guildId || null; + + //if welcome messages has already been configured for this server... + if (welcomeMessage == existingWelcomeMessage && channelId == existingChannelId) { + var embedReply = embedReplyWarningColor( + "Welcome Configure: Warning", + "The same welcome message has already been configured in this server for that channel. :x:\nRun the command with another channel and/or new welcome message to overwrite the current setup.\nRun `/welcome-disable` if you want to disable this feature.", + interaction + ); + } + else { + if (channelId == existingChannelId) { + var embedReply = embedReplySuccessSecondaryColor( + "Welcome Configure: Configuration Modified", + "The **welcome message** has been successfully **modified**. :white_check_mark:\nRun this command again later if you want to modify the message / channel.\nRun `/welcome-disable` if you want to disable this feature.", + interaction + ); + } + else if (welcomeMessage == existingWelcomeMessage) { + var embedReply = embedReplySuccessSecondaryColor( + "Welcome Configure: Configuration Modified", + `The **welcome channel** has been successfully **modified** to <#${channelId}>. :white_check_mark:\nRun this command again later if you want to modify the message / channel.\nRun \`/welcome-disable\` if you want to disable this feature.`, + interaction + ); + } + else { + var embedReply = embedReplySuccessColor( + "Welcome Configure: Configuration Set", + "The **welcome message** has been successfully **set**. :white_check_mark:\nRun this command again later if you want to modify the message / channel.\nRun `/welcome-disable` if you want to disable this feature.", + interaction + ); + } + + await db.query("INSERT INTO welcome (guildId, channelId, message, adderId, adderUsername) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE channelId = ?, message = ?, adderId = ?, adderUsername = ?", + [guildId, channelId, welcomeMessage, adderId, adderUsername, channelId, welcomeMessage, adderId, adderUsername] + ); + } + } + catch (error) { + var embedReply = embedReplyFailureColor( + "Welcome Configure: Error", + "There was an error while trying to configure the welcome messages.", + interaction + ); + } + } await interaction.reply({ embeds: [embedReply] }); From e0b7b6c89a9ea55aa3983607d41c4bfc6ea15013 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 21:28:14 +0200 Subject: [PATCH 21/38] minimal fixed is welcome-configure --- commands/administration/welcome-configure.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index 1ced9e5..a2e0cd9 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -16,7 +16,8 @@ module.exports = { .addStringOption(option => option .setName("message") - .setDescription("A message that the new members will see. You can use the following placeholders: {user} - the new member's username, {server} - the server's name, {memberCount} - the server's member count.") + //the description length is limited to 100 characters ¯\_(ツ)_/¯ + .setDescription("A message that the new members will see.") //You can use the following placeholders: {user} - the new member's username, {server} - the server's name, {memberCount} - the server's member count. .setRequired(true) ) .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) @@ -38,7 +39,7 @@ module.exports = { } else { try { - const channelId = interaction.options.get("channel"); + const channelId = interaction.options.getChannel("channel").id; const welcomeMessage = interaction.options.getString("message"); const guildId = interaction.guild.id; const adderId = interaction.user.id; @@ -80,7 +81,7 @@ module.exports = { ); } - await db.query("INSERT INTO welcome (guildId, channelId, message, adderId, adderUsername) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE channelId = ?, message = ?, adderId = ?, adderUsername = ?", + await db.query("INSERT INTO welcome (guildId, channelId, message, adderId, adderUsername) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE channelId = ?, message = ?, adderId = ?, adderUsername = ?", [guildId, channelId, welcomeMessage, adderId, adderUsername, channelId, welcomeMessage, adderId, adderUsername] ); } From 5c0812f8ccd0cb0d30dd6b0a4a9342bf998a0f87 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 21:28:37 +0200 Subject: [PATCH 22/38] updated guildMemberAdd event --- events/guildMemberAdd.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index 6199092..7e3f899 100755 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -4,6 +4,11 @@ module.exports = { name: "guildMemberAdd", async execute(member) { const guildId = member.guild.id; + const serverName = member.guild.name; + const memberCount = member.guild.memberCount; + + const userTag = member.user.tag; + const userId = member.user.id; //autorole try { @@ -26,13 +31,17 @@ module.exports = { try { const rows = await db.query("SELECT channelId, message FROM welcome WHERE guildId = ?", [guildId]); const channelId = rows[0].channelId; - const message = rows[0].message; + let message = rows[0].message; if (channelId && message) { const channel = member.guild.channels.cache.get(channelId); if (channel) { - await channel.send(message.replace("{user}", member.user.tag)); - console.log(`Sent welcome message to ${member.user.tag} in ${member.guild.name}`); + message = message + .replace("{user}", `<@${userId}>`) + .replace("{server}", serverName) + .replace("{memberCount}", memberCount); + await channel.send(message); + console.log(`Sent welcome message to ${userTag} in ${serverName}.`); } } } From 35445bc59ca9074141ae8e18e795116012741e97 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 21:53:54 +0200 Subject: [PATCH 23/38] implemented logic for /welcome-disable --- commands/administration/welcome-disable.js | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/commands/administration/welcome-disable.js b/commands/administration/welcome-disable.js index 73902bb..84514d2 100644 --- a/commands/administration/welcome-disable.js +++ b/commands/administration/welcome-disable.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js"); -const { embedReplyPrimaryColor, embedReplyFailureColor } = require("../../helpers/embed-reply"); +const { embedReplyPrimaryColor, embedReplyFailureColor, embedReplyWarningColor, embedReplySuccessColor } = require("../../helpers/embed-reply"); const { logToFileAndDatabase } = require("../../helpers/logger"); const db = require("../../helpers/db"); @@ -26,7 +26,26 @@ module.exports = { } else { try { - + const currentGuildId = interaction.guild.id; + const query = await db.query("SELECT guildId FROM welcome WHERE guildId = ?", [currentGuildId]); + const welcomeGuildId = query[0]?.guildId || null; + + if (welcomeGuildId) { + await db.query("DELETE FROM welcome WHERE guildId = ?", [welcomeGuildId]); + + var embedReply = embedReplySuccessColor( + "Welcome Disable: Success", + "The welcome messages have been disabled successfully for this server.\nYou can re-enable them with the `/welcome-configure` command.", + interaction + ); + } + else { + var embedReply = embedReplyWarningColor( + "Welcome Disable: Warning", + "Welcome messages have not been configured for this server.\nTherefore, you can't disable them.\nYou can enable this feature with the `/welcome-configure` command.", + interaction + ); + } } catch (error) { var embedReply = embedReplyFailureColor( From f4b393861695ca9a2c7bf7b153cfe14d33398577 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 22:01:23 +0200 Subject: [PATCH 24/38] seperated the guildMemberAdd events into individual files --- events/guildMemberAdd.js | 50 ++--------------------- events/scripts/guildMemberAdd/autorole.js | 23 +++++++++++ events/scripts/guildMemberAdd/welcome.js | 32 +++++++++++++++ 3 files changed, 59 insertions(+), 46 deletions(-) create mode 100644 events/scripts/guildMemberAdd/autorole.js create mode 100644 events/scripts/guildMemberAdd/welcome.js diff --git a/events/guildMemberAdd.js b/events/guildMemberAdd.js index 7e3f899..328edfc 100755 --- a/events/guildMemberAdd.js +++ b/events/guildMemberAdd.js @@ -1,52 +1,10 @@ -const db = require("../helpers/db"); +const autorole = require("./scripts/guildMemberAdd/autorole"); +const welcome = require("./scripts/guildMemberAdd/welcome"); module.exports = { name: "guildMemberAdd", async execute(member) { - const guildId = member.guild.id; - const serverName = member.guild.name; - const memberCount = member.guild.memberCount; - - const userTag = member.user.tag; - const userId = member.user.id; - - //autorole - try { - const rows = await db.query("SELECT roleId FROM autorole WHERE guildId = ?", [guildId]); - const roleId = rows[0].roleId; - - if (roleId) { - const role = member.guild.roles.cache.get(roleId); - if (role) { - await member.roles.add(role); - console.log(`Assigned ${role.name} role to ${member.user.tag} in ${member.guild.name}`); - } - } - } - catch (error) { - console.error(`Failed to addign role: ${error}`); - } - - //welcome messages - try { - const rows = await db.query("SELECT channelId, message FROM welcome WHERE guildId = ?", [guildId]); - const channelId = rows[0].channelId; - let message = rows[0].message; - - if (channelId && message) { - const channel = member.guild.channels.cache.get(channelId); - if (channel) { - message = message - .replace("{user}", `<@${userId}>`) - .replace("{server}", serverName) - .replace("{memberCount}", memberCount); - await channel.send(message); - console.log(`Sent welcome message to ${userTag} in ${serverName}.`); - } - } - } - catch (error) { - console.error(`Failed to display welcome message: ${error}`); - } + await autorole.assignRole(member); + await welcome.sendWelcomeMessage(member); }, }; \ No newline at end of file diff --git a/events/scripts/guildMemberAdd/autorole.js b/events/scripts/guildMemberAdd/autorole.js new file mode 100644 index 0000000..755a08d --- /dev/null +++ b/events/scripts/guildMemberAdd/autorole.js @@ -0,0 +1,23 @@ +const db = require("../../../helpers/db"); + +module.exports = { + async assignRole (member) { + const guildId = member.guild.id; + + try { + const rows = await db.query("SELECT roleId FROM autorole WHERE guildId = ?", [guildId]); + const roleId = rows[0]?.roleId; + + if (roleId) { + const role = member.guild.roles.cache.get(roleId); + if (role) { + await member.roles.add(role); + console.log(`Assigned ${role.name} role to ${member.user.tag} in ${member.guild.name}`); + } + } + } + catch (error) { + console.error(`Failed to assign role: ${error}`); + } + } +} \ No newline at end of file diff --git a/events/scripts/guildMemberAdd/welcome.js b/events/scripts/guildMemberAdd/welcome.js new file mode 100644 index 0000000..49d17ea --- /dev/null +++ b/events/scripts/guildMemberAdd/welcome.js @@ -0,0 +1,32 @@ +const db = require("../../../helpers/db"); + +module.exports = { + async sendWelcomeMessage(member) { + const guildId = member.guild.id; + const serverName = member.guild.name; + const memberCount = member.guild.memberCount; + const userTag = member.user.tag; + const userId = member.user.id; + + try { + const rows = await db.query("SELECT channelId, message FROM welcome WHERE guildId = ?", [guildId]); + const channelId = rows[0]?.channelId; + let message = rows[0]?.message; + + if (channelId && message) { + const channel = member.guild.channels.cache.get(channelId); + if (channel) { + message = message + .replace("{user}", `<@${userId}>`) + .replace("{server}", serverName) + .replace("{memberCount}", memberCount); + await channel.send(message); + console.log(`Sent welcome message to ${userTag} in ${serverName}.`); + } + } + } + catch (error) { + console.error(`Failed to display welcome message: ${error}`); + } + } +}; \ No newline at end of file From bf707164d2562cb6e3a936e5b090b088c2d8f394 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 5 Oct 2024 22:02:43 +0200 Subject: [PATCH 25/38] defined member variables at the top of the file --- events/scripts/guildMemberAdd/autorole.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/events/scripts/guildMemberAdd/autorole.js b/events/scripts/guildMemberAdd/autorole.js index 755a08d..bb34afd 100644 --- a/events/scripts/guildMemberAdd/autorole.js +++ b/events/scripts/guildMemberAdd/autorole.js @@ -3,6 +3,9 @@ const db = require("../../../helpers/db"); module.exports = { async assignRole (member) { const guildId = member.guild.id; + const serverName = member.guild.name; + + const userTag = member.user.tag; try { const rows = await db.query("SELECT roleId FROM autorole WHERE guildId = ?", [guildId]); @@ -12,7 +15,7 @@ module.exports = { const role = member.guild.roles.cache.get(roleId); if (role) { await member.roles.add(role); - console.log(`Assigned ${role.name} role to ${member.user.tag} in ${member.guild.name}`); + console.log(`Assigned ${role.name} role to ${userTag} in ${serverName}`); } } } From fde1fb3dd0d05ef23280a21352a022bdea6714b5 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Mon, 7 Oct 2024 20:18:40 +0200 Subject: [PATCH 26/38] added embed options --- commands/administration/welcome-configure.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index a2e0cd9..e784959 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -20,6 +20,18 @@ module.exports = { .setDescription("A message that the new members will see.") //You can use the following placeholders: {user} - the new member's username, {server} - the server's name, {memberCount} - the server's member count. .setRequired(true) ) + .addBooleanOption(option => + option + .setName("embed") + .setDescription("Whether the message should be sent as an embed (doesn't supports pinging users).") + .setRequired(false) + ) + .addStringOption(option => + option + .setName("emed-color") + .setDescription("The color of the embed message. Leave empty for default color.") + .setRequired(false) + ) .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) .setDMPermission(false), async execute(interaction) { @@ -45,10 +57,9 @@ module.exports = { const adderId = interaction.user.id; const adderUsername = interaction.user.username; - const query = await db.query("SELECT guildId, channelId, message FROM welcome WHERE guildId = ?", [guildId]); + const query = await db.query("SELECT channelId, message FROM welcome WHERE guildId = ?", [guildId]); const existingChannelId = query[0]?.channelId || null; const existingWelcomeMessage = query[0]?.message || null; - const existingGuildId = query[0]?.guildId || null; //if welcome messages has already been configured for this server... if (welcomeMessage == existingWelcomeMessage && channelId == existingChannelId) { From be63948f45f6dafbd63364b5962690c675a6bf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20V=C3=A1gv=C3=B6lgyi?= Date: Tue, 8 Oct 2024 13:58:15 +0200 Subject: [PATCH 27/38] modified table accordingly to the new welcome options --- sql/welcome/table.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/welcome/table.sql b/sql/welcome/table.sql index 94ef964..0622c4a 100644 --- a/sql/welcome/table.sql +++ b/sql/welcome/table.sql @@ -4,6 +4,8 @@ CREATE TABLE IF NOT EXISTS `welcome` ( `guildId` varchar(50) NOT NULL, `channelId` text DEFAULT NULL, `message` text DEFAULT NULL, + `isEmbed` tinyint(1) NOT NULL DEFAULT 0, + `embedColor` text DEFAULT NULL, `addedAt` timestamp NOT NULL DEFAULT current_timestamp(), `adderId` text DEFAULT NULL, `adderUsername` text DEFAULT NULL, From 7dddb293a3c4e16fc9ca8e488a2f9ad8d10f080f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20V=C3=A1gv=C3=B6lgyi?= Date: Tue, 8 Oct 2024 14:00:21 +0200 Subject: [PATCH 28/38] started implementing embed option setup --- commands/administration/welcome-configure.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index e784959..cddced9 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -28,7 +28,7 @@ module.exports = { ) .addStringOption(option => option - .setName("emed-color") + .setName("embed-color") .setDescription("The color of the embed message. Leave empty for default color.") .setRequired(false) ) @@ -53,16 +53,21 @@ module.exports = { try { const channelId = interaction.options.getChannel("channel").id; const welcomeMessage = interaction.options.getString("message"); + const isEmbed = interaction.options.getBoolean("embed") || 0; + const embedColor = interaction.options.getString("embed-color") || null; + const guildId = interaction.guild.id; const adderId = interaction.user.id; const adderUsername = interaction.user.username; - const query = await db.query("SELECT channelId, message FROM welcome WHERE guildId = ?", [guildId]); + const query = await db.query("SELECT channelId, message, isEmbed, embedColor FROM welcome WHERE guildId = ?", [guildId]); const existingChannelId = query[0]?.channelId || null; const existingWelcomeMessage = query[0]?.message || null; + const existingIsEmbed = query[0]?.isEmbed || 0; + const existingEmbedColor = query[0]?.embedColor || null; //if welcome messages has already been configured for this server... - if (welcomeMessage == existingWelcomeMessage && channelId == existingChannelId) { + if (welcomeMessage == existingWelcomeMessage && channelId == existingChannelId && isEmbed == existingIsEmbed && embedColor == existingEmbedColor) { var embedReply = embedReplyWarningColor( "Welcome Configure: Warning", "The same welcome message has already been configured in this server for that channel. :x:\nRun the command with another channel and/or new welcome message to overwrite the current setup.\nRun `/welcome-disable` if you want to disable this feature.", From 39ea4a5478ce96a380d456618e4e38bd52708d7e Mon Sep 17 00:00:00 2001 From: vb2007 Date: Tue, 8 Oct 2024 21:46:02 +0200 Subject: [PATCH 29/38] added checking other command parameter modifications --- commands/administration/welcome-configure.js | 61 ++++++++++++-------- sql/welcome/table.sql | 2 +- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index cddced9..104d51c 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -26,10 +26,10 @@ module.exports = { .setDescription("Whether the message should be sent as an embed (doesn't supports pinging users).") .setRequired(false) ) - .addStringOption(option => + .addIntegerOption(option => option .setName("embed-color") - .setDescription("The color of the embed message. Leave empty for default color.") + .setDescription("The HEX color of the embed message. Leave empty for default color.") .setRequired(false) ) .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) @@ -54,7 +54,7 @@ module.exports = { const channelId = interaction.options.getChannel("channel").id; const welcomeMessage = interaction.options.getString("message"); const isEmbed = interaction.options.getBoolean("embed") || 0; - const embedColor = interaction.options.getString("embed-color") || null; + const embedColor = interaction.options.getInteger("embed-color") || null; const guildId = interaction.guild.id; const adderId = interaction.user.id; @@ -66,41 +66,52 @@ module.exports = { const existingIsEmbed = query[0]?.isEmbed || 0; const existingEmbedColor = query[0]?.embedColor || null; - //if welcome messages has already been configured for this server... - if (welcomeMessage == existingWelcomeMessage && channelId == existingChannelId && isEmbed == existingIsEmbed && embedColor == existingEmbedColor) { - var embedReply = embedReplyWarningColor( - "Welcome Configure: Warning", - "The same welcome message has already been configured in this server for that channel. :x:\nRun the command with another channel and/or new welcome message to overwrite the current setup.\nRun `/welcome-disable` if you want to disable this feature.", + //if welcome messages haven't been configured for the current server + if (!existingChannelId) { + var embedReply = embedReplySuccessColor( + "Welcome Configure: Configuration Set", + "The **welcome message** has been successfully **set**. :white_check_mark:\nRun this command again later if you want to modify the current configuration.\nRun `/welcome-disable` if you want to disable this feature.", interaction ); } else { - if (channelId == existingChannelId) { - var embedReply = embedReplySuccessSecondaryColor( - "Welcome Configure: Configuration Modified", - "The **welcome message** has been successfully **modified**. :white_check_mark:\nRun this command again later if you want to modify the message / channel.\nRun `/welcome-disable` if you want to disable this feature.", - interaction - ); + //checks if anything has been modified in the the command + let modifications = []; + if (channelId != existingChannelId) { + modifications.push(`**welcome channel** to <#${channelId}>`); } - else if (welcomeMessage == existingWelcomeMessage) { - var embedReply = embedReplySuccessSecondaryColor( - "Welcome Configure: Configuration Modified", - `The **welcome channel** has been successfully **modified** to <#${channelId}>. :white_check_mark:\nRun this command again later if you want to modify the message / channel.\nRun \`/welcome-disable\` if you want to disable this feature.`, + if (welcomeMessage != existingWelcomeMessage) { + modifications.push("**welcome message**"); + } + if (isEmbed != existingIsEmbed) { + modifications.push("**embed option**"); + } + if (embedColor != existingEmbedColor) { + modifications.push("**embed color**"); + } + + + //if the exact same welcome configuration is set for the current server (aka. nothing got modified) + if (modifications.length === 0) { + var embedReply = embedReplyWarningColor( + "Welcome Configure: Warning", + "The exact same welcome configuration has been set for this server already. :x:\nRun the command again with different options to overwrite the current configuration.\nRun `/welcome-disable`, if you want to disable this feature.", interaction ); } + //if the welcome configuration has been modified else { - var embedReply = embedReplySuccessColor( - "Welcome Configure: Configuration Set", - "The **welcome message** has been successfully **set**. :white_check_mark:\nRun this command again later if you want to modify the message / channel.\nRun `/welcome-disable` if you want to disable this feature.", + var embedReply = embedReplySuccessSecondaryColor( + "Welcome Configure: Configuration Modified", + `The ${modifications.join(", ")} has been successfully modified. :white_check_mark:\nRun the command again with different options to overwrite the current configuration.\nRun \`/welcome-disable\`, if you want to disable this feature.`, interaction ); } - - await db.query("INSERT INTO welcome (guildId, channelId, message, adderId, adderUsername) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE channelId = ?, message = ?, adderId = ?, adderUsername = ?", - [guildId, channelId, welcomeMessage, adderId, adderUsername, channelId, welcomeMessage, adderId, adderUsername] - ); } + + await db.query("INSERT INTO welcome (guildId, channelId, message, isEmbed, embedColor, adderId, adderUsername) VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE channelId = ?, message = ?, adderId = ?, adderUsername = ?, isEmbed = ?, embedColor = ?", + [guildId, channelId, welcomeMessage, isEmbed, embedColor, adderId, adderUsername, channelId, welcomeMessage, adderId, adderUsername, isEmbed, embedColor] + ); } catch (error) { var embedReply = embedReplyFailureColor( diff --git a/sql/welcome/table.sql b/sql/welcome/table.sql index 0622c4a..7ab889f 100644 --- a/sql/welcome/table.sql +++ b/sql/welcome/table.sql @@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS `welcome` ( `channelId` text DEFAULT NULL, `message` text DEFAULT NULL, `isEmbed` tinyint(1) NOT NULL DEFAULT 0, - `embedColor` text DEFAULT NULL, + `embedColor` int DEFAULT NULL, `addedAt` timestamp NOT NULL DEFAULT current_timestamp(), `adderId` text DEFAULT NULL, `adderUsername` text DEFAULT NULL, From 0010b91c015e272a322cbd7c45f5097b082a9f9e Mon Sep 17 00:00:00 2001 From: vb2007 Date: Thu, 10 Oct 2024 22:51:06 +0200 Subject: [PATCH 30/38] added embed welcome messages --- events/scripts/guildMemberAdd/welcome.js | 21 +++++++++++++++++++-- helpers/embed-reply.js | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/events/scripts/guildMemberAdd/welcome.js b/events/scripts/guildMemberAdd/welcome.js index 49d17ea..c578287 100644 --- a/events/scripts/guildMemberAdd/welcome.js +++ b/events/scripts/guildMemberAdd/welcome.js @@ -1,4 +1,6 @@ const db = require("../../../helpers/db"); +const { embedColors } = require("../../../config.json"); +const { embedMessage } = require("../../../helpers/embed-reply"); module.exports = { async sendWelcomeMessage(member) { @@ -9,9 +11,11 @@ module.exports = { const userId = member.user.id; try { - const rows = await db.query("SELECT channelId, message FROM welcome WHERE guildId = ?", [guildId]); + const rows = await db.query("SELECT channelId, message, isEmbed, embedColor FROM welcome WHERE guildId = ?", [guildId]); const channelId = rows[0]?.channelId; let message = rows[0]?.message; + const isEmbed = rows[0]?.isEmbed; + const embedColor = rows[0]?.embedColor || embedColors.primary; if (channelId && message) { const channel = member.guild.channels.cache.get(channelId); @@ -20,7 +24,20 @@ module.exports = { .replace("{user}", `<@${userId}>`) .replace("{server}", serverName) .replace("{memberCount}", memberCount); - await channel.send(message); + + if (isEmbed) { + const embedContent = embedMessage( + embedColor, + "Welcome!", + message, + ); + + await channel.send({ embeds: [embedContent] }); + } + else { + await channel.send(message); + } + console.log(`Sent welcome message to ${userTag} in ${serverName}.`); } } diff --git a/helpers/embed-reply.js b/helpers/embed-reply.js index 22a58f0..de55a95 100644 --- a/helpers/embed-reply.js +++ b/helpers/embed-reply.js @@ -313,6 +313,23 @@ function embedReplySaidByPrimaryColor(title, description, interaction) { return embedReply; } +/** + * @param {color} color - Embed's sidebar HEX Color + * @param {title} title - Embed's title + * @param {description} description - Embed's description + * @returns {embedReply} An embed reply object + */ +function embedMessage(color, title, description) { + const embedReply = new EmbedBuilder({ + color: parseInt(color), + title: title, + description: description, + timestamp: new Date().toISOString() + }); + + return embedReply; +} + module.exports = { embedReply, embedReplyPrimaryColor, @@ -326,5 +343,6 @@ module.exports = { embedReplyPrimaryColorImg, embedReplyPrimaryColorWithFields, embedReplyPrimaryColorWithFieldsAndAuthor, - embedReplySaidByPrimaryColor + embedReplySaidByPrimaryColor, + embedMessage } \ No newline at end of file From 7c06f04cd21776c9d5f18d7096b10dbb34547df2 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Fri, 11 Oct 2024 00:07:40 +0200 Subject: [PATCH 31/38] added better config modification feedback --- commands/administration/welcome-configure.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index 104d51c..c9042d4 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -77,9 +77,6 @@ module.exports = { else { //checks if anything has been modified in the the command let modifications = []; - if (channelId != existingChannelId) { - modifications.push(`**welcome channel** to <#${channelId}>`); - } if (welcomeMessage != existingWelcomeMessage) { modifications.push("**welcome message**"); } @@ -89,7 +86,9 @@ module.exports = { if (embedColor != existingEmbedColor) { modifications.push("**embed color**"); } - + if (channelId != existingChannelId) { + modifications.push(`**welcome channel** to <#${channelId}>`); + } //if the exact same welcome configuration is set for the current server (aka. nothing got modified) if (modifications.length === 0) { @@ -101,9 +100,16 @@ module.exports = { } //if the welcome configuration has been modified else { + let modificationsMessage; + if (modifications.length === 1) { + modificationsMessage = modifications[0]; + } else { + modificationsMessage = modifications.slice(0, -1).join(", ") + " and " + modifications[modifications.length - 1]; + } + var embedReply = embedReplySuccessSecondaryColor( "Welcome Configure: Configuration Modified", - `The ${modifications.join(", ")} has been successfully modified. :white_check_mark:\nRun the command again with different options to overwrite the current configuration.\nRun \`/welcome-disable\`, if you want to disable this feature.`, + `Successfully modified ${modificationsMessage}. :white_check_mark:\nRun the command again with different options to overwrite the current configuration.\nRun \`/welcome-disable\`, if you want to disable this feature.`, interaction ); } From 62eb58798da274cbeb13f5d603441477bfa3bd1b Mon Sep 17 00:00:00 2001 From: vb2007 Date: Fri, 11 Oct 2024 00:10:35 +0200 Subject: [PATCH 32/38] specified text channel option --- commands/administration/welcome-configure.js | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/administration/welcome-configure.js b/commands/administration/welcome-configure.js index c9042d4..6d07f2e 100644 --- a/commands/administration/welcome-configure.js +++ b/commands/administration/welcome-configure.js @@ -11,6 +11,7 @@ module.exports = { option .setName("channel") .setDescription("A channel where the welcome message will be displayed.") + .addChannelTypes(0) //= GUILD_TEXT aka. text channels .setRequired(true) ) .addStringOption(option => From 69e3e0ceb22d7931e3715cdb20cb1b5eae086f7f Mon Sep 17 00:00:00 2001 From: vb2007 Date: Fri, 11 Oct 2024 22:03:01 +0200 Subject: [PATCH 33/38] added welcome commands to /help --- commands/utility/help.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/utility/help.js b/commands/utility/help.js index 806564c..ba622f1 100755 --- a/commands/utility/help.js +++ b/commands/utility/help.js @@ -69,6 +69,8 @@ module.exports = { "**__NOTE__**: The following commands require relevant **administration permissions** for both the bot and the command's executor to work.\n" + "`/autorole-configure` - Sets / modifies the autorole feature. When a new member joins the server, a specified role will get assigned to them automatically.\n" + "`/autorole-disable` - Disables the autorole feature. New members won't get the specified role automatically on join anymore.\n" + + "`/welcome-configure` - Sets / modifies the welcome messages feature. When a new member joins the server, the bot send a specified welcome message.\n" + + "`/welcome-disable` - Disables the welcome messages feature. The bot won't send a welcome message on join anymore.\n" + "`/rename` - Renames a specified user to a specified nickname in the current server." }; From 2d256b34ac5ba250b712bc1ee7375ac541653985 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Fri, 11 Oct 2024 22:20:13 +0200 Subject: [PATCH 34/38] updated npm pacage documentation --- package.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index bba17fe..bc7e72c 100755 --- a/package.json +++ b/package.json @@ -16,7 +16,18 @@ "sql", "mariadb" ], - "author": "vb2007 (https://vb2007.hu)", + "author": { + "name": "vb2007", + "email": "admin@vb2007.hu", + "url": "https://vb2007.hu" + }, + "repository": { + "type": "git", + "url": "https://github.com/vb2007/discordbot.git" + }, + "bugs": { + "url" : "https://github.com/vb2007/discordbot/issues" + }, "license": "AGPL-3.0-only", "dependencies": { "ajv": "^8.17.1", From 00f0e5540c9ca36f98491a7661148738d305ca1c Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 12 Oct 2024 16:46:03 +0200 Subject: [PATCH 35/38] added security.md --- SECURITY.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..10f53c1 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,20 @@ +# Security Policy + +## Supported Versions + +Currently, only the latest version of the project gets regular security updates and pathces. + +If the latest version has any vulnerability, it is likely going to get patched in the next release. + +I don't maintain any version that's not the latest. + +| Version | Supported | +| -------- | ------------------ | +| > latest | :white_check_mark: | +| < latest | :x: | + +## Reporting a Vulnerability + +You can report a vulnerability on the [repository's security page](https://github.com/vb2007/discordbot/security). + +When reporting, please explain the with as much details as possible. \ No newline at end of file From ed4181d63bc2cf3459781cacad415883ac03099f Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 12 Oct 2024 17:37:30 +0200 Subject: [PATCH 36/38] added contributing.md --- CONTRIBUTING.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..8f6661d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,41 @@ +# Discordbot contributing guide + +Thank you for investing your time in contributing to this project. + +When contributing, please make sure to always follow the project's [CODE OF CONDUCT](./CODE_OF_CONDUCT.md). + +This guide will help you get some ground about how contributions work. + +## Contributing + +### Issues + +If you found a bug, or you think the project needs new commands / features, please open an issue on the project's [issues page](https://github.com/vb2007/discordbot/issues/new). + +If possible, please go with an issue template. + +Before opening an issue, make sure it hasn't been reported already by somebody else. [Project's existing issues.](https://github.com/vb2007/discordbot/issues) + +#### Reporting bugs + +If you found a bug with the bot, please make sure to explain the issue with as much details as possible, and **attack screenshots / videos**. + +### Pull requests + +#### Basic steps for newcomers + +1. Fork the repository +2. Clone your fork +3. Make your changes with relevant commit messages +4. Push your commits +5. When you're done, open a Pull Request (PR) + +#### Making changes + +When making changes to the codebase, please watch out for the following: + +- Don't remove code that's essential for the project to work properly +- Try to write optimal code +- Make sure the project passes all unit tests after your changes + +After you're done, make a Pull Request to the `dev` branch. If possible, please link an issue / issues to your PR. \ No newline at end of file From 89439f4e6bc4cd9036dcc521871f9e586463537c Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 12 Oct 2024 17:37:58 +0200 Subject: [PATCH 37/38] updated packages --- package-lock.json | 86 ++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3c3796a..057aab0 100755 --- a/package-lock.json +++ b/package-lock.json @@ -52,18 +52,18 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.25.7.tgz", - "integrity": "sha512-9ickoLz+hcXCeh7jrcin+/SLWm+GkxE2kTvoYyp38p4WkdFXfQJxDFGWp/YHjiKLPx06z2A7W8XKuqbReXDzsw==", + "version": "7.25.8", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.25.8.tgz", + "integrity": "sha512-ZsysZyXY4Tlx+Q53XdnOFmqwfB9QDTHYxaZYajWRoBLuLEAwI2UIbtxOjWh/cFaa9IKUlcB+DDuoskLuKu56JA==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.25.7.tgz", - "integrity": "sha512-yJ474Zv3cwiSOO9nXJuqzvwEeM+chDuQ8GJirw+pZ91sCGCyOZ3dJkVE09fTV0VEVzXyLWhh3G/AolYTPX7Mow==", + "version": "7.25.8", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.25.8.tgz", + "integrity": "sha512-Oixnb+DzmRT30qu9d3tJSQkxuygWm32DFykT4bRoORPa9hZ/L4KhVB/XiRm6KG+roIEM7DBQlmg27kw2HZkdZg==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", @@ -72,10 +72,10 @@ "@babel/helper-compilation-targets": "^7.25.7", "@babel/helper-module-transforms": "^7.25.7", "@babel/helpers": "^7.25.7", - "@babel/parser": "^7.25.7", + "@babel/parser": "^7.25.8", "@babel/template": "^7.25.7", "@babel/traverse": "^7.25.7", - "@babel/types": "^7.25.7", + "@babel/types": "^7.25.8", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -301,12 +301,12 @@ } }, "node_modules/@babel/parser": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.7.tgz", - "integrity": "sha512-aZn7ETtQsjjGG5HruveUK06cU3Hljuhd9Iojm4M8WWv3wLE6OkE5PWbDUkItmMgegmccaITudyuW5RPYrYlgWw==", + "version": "7.25.8", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.8.tgz", + "integrity": "sha512-HcttkxzdPucv3nNFmfOOMfFf64KgdJVqm1KaCm25dPGMLElo9nsLvXeJECQg8UzPuBGLyTSA0ZzqCtDSzKTEoQ==", "dev": true, "dependencies": { - "@babel/types": "^7.25.7" + "@babel/types": "^7.25.8" }, "bin": { "parser": "bin/babel-parser.js" @@ -570,9 +570,9 @@ } }, "node_modules/@babel/types": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.7.tgz", - "integrity": "sha512-vwIVdXG+j+FOpkwqHRcBgHLYNL7XMkufrlaFvL9o6Ai9sJn9+PdyIL5qa0XzTZw084c+u9LOls53eoZWP/W5WQ==", + "version": "7.25.8", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.8.tgz", + "integrity": "sha512-JWtuCu8VQsMladxVz/P4HzHUGCAwpuqacmowgXFs5XjxIgKuNjnLokQzuVjlTvIzODaDmpjT3oxcC48vyk9EWg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.25.7", @@ -679,6 +679,14 @@ "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.97.tgz", "integrity": "sha512-No1BXPcVkyVD4ZVmbNgDKaBoqgeQ+FJpzZ8wqHkfmBnTZig1FcH3iPPersiK1TUIAzgClh2IvOuVUYfcWLQAOA==" }, + "node_modules/@discordjs/rest/node_modules/undici": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz", + "integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==", + "engines": { + "node": ">=18.17" + } + }, "node_modules/@discordjs/util": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@discordjs/util/-/util-1.1.1.tgz", @@ -1213,9 +1221,9 @@ } }, "node_modules/@types/node": { - "version": "22.7.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.4.tgz", - "integrity": "sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==", + "version": "22.7.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", + "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", "dependencies": { "undici-types": "~6.19.2" } @@ -1619,9 +1627,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001666", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001666.tgz", - "integrity": "sha512-gD14ICmoV5ZZM1OdzPWmpx+q4GyefaK06zi8hmfHV5xe4/2nOQX3+Dw5o+fSqOws2xVwL9j+anOPFwHzdEdV4g==", + "version": "1.0.30001668", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001668.tgz", + "integrity": "sha512-nWLrdxqCdblixUO+27JtGJJE/txpJlyUy5YN1u53wLZkP0emYCo5zgS6QYft7VUYR42LGgi/S5hdLZTrnyIddw==", "dev": true, "funding": [ { @@ -2018,6 +2026,14 @@ "url": "https://github.com/discordjs/discord.js?sponsor" } }, + "node_modules/discord.js/node_modules/undici": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz", + "integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==", + "engines": { + "node": ">=18.17" + } + }, "node_modules/dom-serializer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", @@ -2091,9 +2107,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.31", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.31.tgz", - "integrity": "sha512-QcDoBbQeYt0+3CWcK/rEbuHvwpbT/8SV9T3OSgs6cX1FlcUAkgrkqbg9zLnDrMM/rLamzQwal4LYFCiWk861Tg==", + "version": "1.5.36", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.36.tgz", + "integrity": "sha512-HYTX8tKge/VNp6FGO+f/uVDmUkq+cEfcxYhKf15Akc4M5yxt5YmorwlAitKWjWhWQnKcDRBAQKXkhqqXMqcrjw==", "dev": true }, "node_modules/emittery": { @@ -3961,22 +3977,22 @@ } }, "node_modules/parse5": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", - "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.2.0.tgz", + "integrity": "sha512-ZkDsAOcxsUMZ4Lz5fVciOehNcJ+Gb8gTzcA4yl3wnc273BAybYWrQ+Ks/OjCjSEpjvQkDSeZbybK9qj2VHHdGA==", "dependencies": { - "entities": "^4.4.0" + "entities": "^4.5.0" }, "funding": { "url": "https://github.com/inikulin/parse5?sponsor=1" } }, "node_modules/parse5-htmlparser2-tree-adapter": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", - "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.1.0.tgz", + "integrity": "sha512-ruw5xyKs6lrpo9x9rCZqZZnIUntICjQAd0Wsmp396Ul9lN/h+ifgVV1x1gZHi8euej6wTfpqX8j+BFQxF0NS/g==", "dependencies": { - "domhandler": "^5.0.2", + "domhandler": "^5.0.3", "parse5": "^7.0.0" }, "funding": { @@ -4682,9 +4698,9 @@ "dev": true }, "node_modules/undici": { - "version": "6.19.8", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz", - "integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.20.0.tgz", + "integrity": "sha512-AITZfPuxubm31Sx0vr8bteSalEbs9wQb/BOBi9FPlD9Qpd6HxZ4Q0+hI742jBhkPb4RT2v5MQzaW5VhRVyj+9A==", "engines": { "node": ">=18.17" } From 3219342b7bd606604d42552ec4d0bc74e92745d8 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Sat, 12 Oct 2024 21:51:00 +0200 Subject: [PATCH 38/38] patched issue with role displaying in /autorole-configure --- commands/administration/autorole-configure.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/administration/autorole-configure.js b/commands/administration/autorole-configure.js index 00e4e95..e723b4f 100755 --- a/commands/administration/autorole-configure.js +++ b/commands/administration/autorole-configure.js @@ -58,7 +58,7 @@ module.exports = { var localEmbedResponse = embedReply( embedColors.successSecondary, "AutoRole Configure: Configuration Modified", - `The role that will get assigned to new members has been **modified** to \`@<${targetRole}>\` :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`, + `The role that will get assigned to new members has been **modified** to <@&${targetRole}>. :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`, interaction ); } @@ -66,7 +66,7 @@ module.exports = { var localEmbedResponse = embedReply( embedColors.success, "AutoRole Configure: Configuration Set", - `The role that will get assigned to new members has been **set** to \`@<${targetRole}>\` :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`, + `The role that will get assigned to new members has been **set** to <@&${targetRole}>. :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`, interaction ); }