From e8764d385707395f2ce2dce6612d407cca9930c7 Mon Sep 17 00:00:00 2001 From: Bifeldy Date: Sat, 11 Nov 2023 21:32:14 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=94=20New=20Discord=20Bot=20Slash=20Comma?= =?UTF-8?q?nd=20~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 450 +++++++++++++++++++++------- package.json | 2 + src/api/services/discord.service.ts | 210 ++++++++----- 3 files changed, 481 insertions(+), 181 deletions(-) diff --git a/package-lock.json b/package-lock.json index c2193db7d..6f3d72d95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,9 @@ "@angular/platform-server": "^14.2.0", "@angular/router": "^14.2.0", "@angular/service-worker": "^14.3.0", + "@discordjs/builders": "^1.6.5", "@discordjs/opus": "^0.9.0", + "@discordjs/rest": "^0.4.1", "@iamtraction/google-translate": "^1.1.2", "@kolkov/angular-editor": "^2.1.0", "@nestjs/common": "^8.0.0", @@ -3172,28 +3174,45 @@ } }, "node_modules/@discordjs/builders": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", - "integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", - "dependencies": { - "@sindresorhus/is": "^4.2.0", - "discord-api-types": "^0.26.0", - "ts-mixer": "^6.0.0", - "tslib": "^2.3.1", - "zod": "^3.11.6" + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.6.5.tgz", + "integrity": "sha512-SdweyCs/+mHj+PNhGLLle7RrRFX9ZAhzynHahMCLqp5Zeq7np7XC6/mgzHc79QoVlQ1zZtOkTTiJpOZu5V8Ufg==", + "dependencies": { + "@discordjs/formatters": "^0.3.2", + "@discordjs/util": "^1.0.1", + "@sapphire/shapeshift": "^3.9.2", + "discord-api-types": "0.37.50", + "fast-deep-equal": "^3.1.3", + "ts-mixer": "^6.0.3", + "tslib": "^2.6.1" }, "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" + "node": ">=16.11.0" } }, + "node_modules/@discordjs/builders/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + }, "node_modules/@discordjs/collection": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz", - "integrity": "sha512-zmjq+l/rV35kE6zRrwe8BHqV78JvIh2ybJeZavBi5NySjWXqN3hmmAKg7kYMMXSeiWtSsMoZ/+MQi0DiQWy2lw==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0.tgz", + "integrity": "sha512-R5i8Wb8kIcBAFEPLLf7LVBQKBDYUL+ekb23sOgpkpyGT+V4P7V83wTxcsqmX+PbqHt4cEHn053uMWfRqh/Z/nA==", + "deprecated": "no longer supported", "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" + "node": ">=16.9.0" + } + }, + "node_modules/@discordjs/formatters": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@discordjs/formatters/-/formatters-0.3.2.tgz", + "integrity": "sha512-lE++JZK8LSSDRM5nLjhuvWhGuKiXqu+JZ/DsOR89DVVia3z9fdCJVcHF2W/1Zxgq0re7kCzmAJlCMMX3tetKpA==", + "dependencies": { + "discord-api-types": "0.37.50" + }, + "engines": { + "node": ">=16.11.0" } }, "node_modules/@discordjs/node-pre-gyp": { @@ -3271,6 +3290,76 @@ "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==" }, + "node_modules/@discordjs/rest": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-0.4.1.tgz", + "integrity": "sha512-rtWy+AIfNlfjGkAgA2TJLASdqli07aTNQceVGT6RQQiQaEqV0nsfBO4WtDlDzk7PmO3w+InP3dpwEolJI5jz0A==", + "deprecated": "no longer supported", + "dependencies": { + "@discordjs/collection": "^0.7.0-dev", + "@sapphire/async-queue": "^1.3.1", + "@sapphire/snowflake": "^3.2.1", + "@types/node-fetch": "^2.6.1", + "discord-api-types": "^0.29.0", + "form-data": "^4.0.0", + "node-fetch": "^2.6.7", + "tslib": "^2.3.1" + }, + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/@discordjs/rest/node_modules/discord-api-types": { + "version": "0.29.0", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.29.0.tgz", + "integrity": "sha512-Ekq1ICNpOTVajXKZguNFrsDeTmam+ZeA38txsNLZnANdXUjU6QBPIZLUQTC6MzigFGb0Tt8vk4xLnXmzv0shNg==" + }, + "node_modules/@discordjs/rest/node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/@discordjs/rest/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/@discordjs/rest/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/@discordjs/rest/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/@discordjs/util": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@discordjs/util/-/util-1.0.1.tgz", + "integrity": "sha512-d0N2yCxB8r4bn00/hvFZwM7goDcUhtViC5un4hPj73Ba4yrChLSJD8fy7Ps5jpTLg1fE9n4K0xBLc1y9WGwSsA==", + "engines": { + "node": ">=16.11.0" + } + }, "node_modules/@discoveryjs/json-ext": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", @@ -4757,9 +4846,31 @@ } }, "node_modules/@sapphire/async-queue": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.1.tgz", - "integrity": "sha512-FFTlPOWZX1kDj9xCAsRzH5xEJfawg1lNoYAA+ecOWJMHOfiZYb1uXOI3ne9U4UILSEPwfE68p3T9wUHwIQfR0g==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.0.tgz", + "integrity": "sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==", + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@sapphire/shapeshift": { + "version": "3.9.3", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.9.3.tgz", + "integrity": "sha512-WzKJSwDYloSkHoBbE8rkRW8UNKJiSRJ/P8NqJ5iVq7U2Yr/kriIBx2hW+wj2Z5e5EnXL1hgYomgaFsdK6b+zqQ==", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "lodash": "^4.17.21" + }, + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@sapphire/snowflake": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.5.1.tgz", + "integrity": "sha512-BxcYGzgEsdlG0dKAyOm0ehLGm2CafIrfQTZGWgkfKYbj+pNNsorZ7EotuZukc2MT70E0UbppVbtpBrqpzVzjNA==", "engines": { "node": ">=v14.0.0", "npm": ">=7.0.0" @@ -5157,30 +5268,17 @@ } }, "node_modules/@types/node": { - "version": "14.18.57", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.57.tgz", - "integrity": "sha512-AV54VmsNLLPoUm+EBroYLyXQUI8kfG+oFIocRw5DjA6R+8wg7VV1Vqoi9sdjbjk1Zmxhxp+ecLqLdybnfV6MGQ==" + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" }, "node_modules/@types/node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==", + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.9.tgz", + "integrity": "sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA==", "dependencies": { "@types/node": "*", - "form-data": "^3.0.0" - } - }, - "node_modules/@types/node-fetch/node_modules/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" + "form-data": "^4.0.0" } }, "node_modules/@types/parse-json": { @@ -5315,9 +5413,9 @@ "dev": true }, "node_modules/@types/ws": { - "version": "8.5.3", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz", - "integrity": "sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==", + "version": "8.5.9", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.9.tgz", + "integrity": "sha512-jbdrY0a8lxfdTp/+r7Z4CkycbOFN8WX+IOchLJr3juT/xzbJ8URyTVSJ/hvNdadTgM1mnedb47n+Y31GsFnQlg==", "dependencies": { "@types/node": "*" } @@ -9721,17 +9819,15 @@ } }, "node_modules/discord-api-types": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz", - "integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==", - "engines": { - "node": ">=12" - } + "version": "0.37.50", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.50.tgz", + "integrity": "sha512-X4CDiMnDbA3s3RaUXWXmgAIbY1uxab3fqe3qwzg5XutR3wjqi7M3IkgQbsIBzpqBN2YWr/Qdv7JrFRqSgb4TFg==" }, "node_modules/discord.js": { "version": "13.6.0", "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.6.0.tgz", "integrity": "sha512-tXNR8zgsEPxPBvGk3AQjJ9ljIIC6/LOPjzKwpwz8Y1Q2X66Vi3ZqFgRHYwnHKC0jC0F+l4LzxlhmOJsBZDNg9g==", + "deprecated": "Hard crashes on interactions with a channel in the payload, use 13.14.0 and up", "dependencies": { "@discordjs/builders": "^0.11.0", "@discordjs/collection": "^0.4.0", @@ -9748,10 +9844,45 @@ "npm": ">=7.0.0" } }, + "node_modules/discord.js/node_modules/@discordjs/builders": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", + "integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", + "deprecated": "no longer supported", + "dependencies": { + "@sindresorhus/is": "^4.2.0", + "discord-api-types": "^0.26.0", + "ts-mixer": "^6.0.0", + "tslib": "^2.3.1", + "zod": "^3.11.6" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/discord.js/node_modules/@discordjs/collection": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz", + "integrity": "sha512-zmjq+l/rV35kE6zRrwe8BHqV78JvIh2ybJeZavBi5NySjWXqN3hmmAKg7kYMMXSeiWtSsMoZ/+MQi0DiQWy2lw==", + "deprecated": "no longer supported", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/discord.js/node_modules/discord-api-types": { + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz", + "integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/discord.js/node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -9770,17 +9901,17 @@ "node_modules/discord.js/node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "node_modules/discord.js/node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "node_modules/discord.js/node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -20725,9 +20856,9 @@ } }, "node_modules/ts-mixer": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.1.tgz", - "integrity": "sha512-hvE+ZYXuINrx6Ei6D6hz+PTim0Uf++dYbK9FFifLNwQj+RwKquhQpn868yZsCtJYiclZF1u8l6WZxxKi+vv7Rg==" + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.3.tgz", + "integrity": "sha512-k43M7uCG1AkTyxgnmI5MPwKoUvS/bRvLvUb7+Pgpdlmok8AoqmUaZxUUw8zKM5B1lqZrt41GjYgnvAi0fppqgQ==" }, "node_modules/tslib": { "version": "2.4.0", @@ -22506,9 +22637,9 @@ } }, "node_modules/zod": { - "version": "3.14.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.14.4.tgz", - "integrity": "sha512-U9BFLb2GO34Sfo9IUYp0w3wJLlmcyGoMd75qU9yf+DrdGA4kEx6e+l9KOkAlyUO0PSQzZCa3TR4qVlcmwqSDuw==", + "version": "3.22.4", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", + "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==", "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -24583,21 +24714,38 @@ } }, "@discordjs/builders": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", - "integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", - "requires": { - "@sindresorhus/is": "^4.2.0", - "discord-api-types": "^0.26.0", - "ts-mixer": "^6.0.0", - "tslib": "^2.3.1", - "zod": "^3.11.6" + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.6.5.tgz", + "integrity": "sha512-SdweyCs/+mHj+PNhGLLle7RrRFX9ZAhzynHahMCLqp5Zeq7np7XC6/mgzHc79QoVlQ1zZtOkTTiJpOZu5V8Ufg==", + "requires": { + "@discordjs/formatters": "^0.3.2", + "@discordjs/util": "^1.0.1", + "@sapphire/shapeshift": "^3.9.2", + "discord-api-types": "0.37.50", + "fast-deep-equal": "^3.1.3", + "ts-mixer": "^6.0.3", + "tslib": "^2.6.1" + }, + "dependencies": { + "tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + } } }, "@discordjs/collection": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz", - "integrity": "sha512-zmjq+l/rV35kE6zRrwe8BHqV78JvIh2ybJeZavBi5NySjWXqN3hmmAKg7kYMMXSeiWtSsMoZ/+MQi0DiQWy2lw==" + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0.tgz", + "integrity": "sha512-R5i8Wb8kIcBAFEPLLf7LVBQKBDYUL+ekb23sOgpkpyGT+V4P7V83wTxcsqmX+PbqHt4cEHn053uMWfRqh/Z/nA==" + }, + "@discordjs/formatters": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@discordjs/formatters/-/formatters-0.3.2.tgz", + "integrity": "sha512-lE++JZK8LSSDRM5nLjhuvWhGuKiXqu+JZ/DsOR89DVVia3z9fdCJVcHF2W/1Zxgq0re7kCzmAJlCMMX3tetKpA==", + "requires": { + "discord-api-types": "0.37.50" + } }, "@discordjs/node-pre-gyp": { "version": "0.4.5", @@ -24660,6 +24808,60 @@ } } }, + "@discordjs/rest": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-0.4.1.tgz", + "integrity": "sha512-rtWy+AIfNlfjGkAgA2TJLASdqli07aTNQceVGT6RQQiQaEqV0nsfBO4WtDlDzk7PmO3w+InP3dpwEolJI5jz0A==", + "requires": { + "@discordjs/collection": "^0.7.0-dev", + "@sapphire/async-queue": "^1.3.1", + "@sapphire/snowflake": "^3.2.1", + "@types/node-fetch": "^2.6.1", + "discord-api-types": "^0.29.0", + "form-data": "^4.0.0", + "node-fetch": "^2.6.7", + "tslib": "^2.3.1" + }, + "dependencies": { + "discord-api-types": { + "version": "0.29.0", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.29.0.tgz", + "integrity": "sha512-Ekq1ICNpOTVajXKZguNFrsDeTmam+ZeA38txsNLZnANdXUjU6QBPIZLUQTC6MzigFGb0Tt8vk4xLnXmzv0shNg==" + }, + "node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + } + } + }, + "@discordjs/util": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@discordjs/util/-/util-1.0.1.tgz", + "integrity": "sha512-d0N2yCxB8r4bn00/hvFZwM7goDcUhtViC5un4hPj73Ba4yrChLSJD8fy7Ps5jpTLg1fE9n4K0xBLc1y9WGwSsA==" + }, "@discoveryjs/json-ext": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", @@ -25679,9 +25881,23 @@ "optional": true }, "@sapphire/async-queue": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.1.tgz", - "integrity": "sha512-FFTlPOWZX1kDj9xCAsRzH5xEJfawg1lNoYAA+ecOWJMHOfiZYb1uXOI3ne9U4UILSEPwfE68p3T9wUHwIQfR0g==" + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.0.tgz", + "integrity": "sha512-JkLdIsP8fPAdh9ZZjrbHWR/+mZj0wvKS5ICibcLrRI1j84UmLMshx5n9QmL8b95d4onJ2xxiyugTgSAX7AalmA==" + }, + "@sapphire/shapeshift": { + "version": "3.9.3", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.9.3.tgz", + "integrity": "sha512-WzKJSwDYloSkHoBbE8rkRW8UNKJiSRJ/P8NqJ5iVq7U2Yr/kriIBx2hW+wj2Z5e5EnXL1hgYomgaFsdK6b+zqQ==", + "requires": { + "fast-deep-equal": "^3.1.3", + "lodash": "^4.17.21" + } + }, + "@sapphire/snowflake": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.5.1.tgz", + "integrity": "sha512-BxcYGzgEsdlG0dKAyOm0ehLGm2CafIrfQTZGWgkfKYbj+pNNsorZ7EotuZukc2MT70E0UbppVbtpBrqpzVzjNA==" }, "@schematics/angular": { "version": "14.2.12", @@ -26049,29 +26265,17 @@ } }, "@types/node": { - "version": "14.18.57", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.57.tgz", - "integrity": "sha512-AV54VmsNLLPoUm+EBroYLyXQUI8kfG+oFIocRw5DjA6R+8wg7VV1Vqoi9sdjbjk1Zmxhxp+ecLqLdybnfV6MGQ==" + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" }, "@types/node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==", + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.9.tgz", + "integrity": "sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA==", "requires": { "@types/node": "*", - "form-data": "^3.0.0" - }, - "dependencies": { - "form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - } + "form-data": "^4.0.0" } }, "@types/parse-json": { @@ -26206,9 +26410,9 @@ "dev": true }, "@types/ws": { - "version": "8.5.3", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz", - "integrity": "sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==", + "version": "8.5.9", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.9.tgz", + "integrity": "sha512-jbdrY0a8lxfdTp/+r7Z4CkycbOFN8WX+IOchLJr3juT/xzbJ8URyTVSJ/hvNdadTgM1mnedb47n+Y31GsFnQlg==", "requires": { "@types/node": "*" } @@ -29400,9 +29604,9 @@ } }, "discord-api-types": { - "version": "0.26.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz", - "integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==" + "version": "0.37.50", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.50.tgz", + "integrity": "sha512-X4CDiMnDbA3s3RaUXWXmgAIbY1uxab3fqe3qwzg5XutR3wjqi7M3IkgQbsIBzpqBN2YWr/Qdv7JrFRqSgb4TFg==" }, "discord.js": { "version": "13.6.0", @@ -29420,10 +29624,32 @@ "ws": "^8.4.0" }, "dependencies": { + "@discordjs/builders": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.11.0.tgz", + "integrity": "sha512-ZTB8yJdJKrKlq44dpWkNUrAtEJEq0gqpb7ASdv4vmq6/mZal5kOv312hQ56I/vxwMre+VIkoHquNUAfnTbiYtg==", + "requires": { + "@sindresorhus/is": "^4.2.0", + "discord-api-types": "^0.26.0", + "ts-mixer": "^6.0.0", + "tslib": "^2.3.1", + "zod": "^3.11.6" + } + }, + "@discordjs/collection": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.4.0.tgz", + "integrity": "sha512-zmjq+l/rV35kE6zRrwe8BHqV78JvIh2ybJeZavBi5NySjWXqN3hmmAKg7kYMMXSeiWtSsMoZ/+MQi0DiQWy2lw==" + }, + "discord-api-types": { + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.26.1.tgz", + "integrity": "sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==" + }, "node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "requires": { "whatwg-url": "^5.0.0" } @@ -29431,17 +29657,17 @@ "tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, "whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", "requires": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -37292,9 +37518,9 @@ "dev": true }, "ts-mixer": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.1.tgz", - "integrity": "sha512-hvE+ZYXuINrx6Ei6D6hz+PTim0Uf++dYbK9FFifLNwQj+RwKquhQpn868yZsCtJYiclZF1u8l6WZxxKi+vv7Rg==" + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.3.tgz", + "integrity": "sha512-k43M7uCG1AkTyxgnmI5MPwKoUvS/bRvLvUb7+Pgpdlmok8AoqmUaZxUUw8zKM5B1lqZrt41GjYgnvAi0fppqgQ==" }, "tslib": { "version": "2.4.0", @@ -38529,9 +38755,9 @@ "integrity": "sha1-UBl+2yihxCymWcyLTmqd3W1ERVQ=" }, "zod": { - "version": "3.14.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.14.4.tgz", - "integrity": "sha512-U9BFLb2GO34Sfo9IUYp0w3wJLlmcyGoMd75qU9yf+DrdGA4kEx6e+l9KOkAlyUO0PSQzZCa3TR4qVlcmwqSDuw==" + "version": "3.22.4", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", + "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==" }, "zone.js": { "version": "0.11.5", diff --git a/package.json b/package.json index e0023ff9a..2280e00d9 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,9 @@ "@angular/platform-server": "^14.2.0", "@angular/router": "^14.2.0", "@angular/service-worker": "^14.3.0", + "@discordjs/builders": "^1.6.5", "@discordjs/opus": "^0.9.0", + "@discordjs/rest": "^0.4.1", "@iamtraction/google-translate": "^1.1.2", "@kolkov/angular-editor": "^2.1.0", "@nestjs/common": "^8.0.0", diff --git a/src/api/services/discord.service.ts b/src/api/services/discord.service.ts index f12d7c52b..b2fc19437 100644 --- a/src/api/services/discord.service.ts +++ b/src/api/services/discord.service.ts @@ -12,8 +12,12 @@ import { EmbedFooterData, GuildMember, PartialGuildMember, - MessageAttachment + MessageAttachment, + CommandInteraction } from 'discord.js'; +import { SlashCommandBuilder } from '@discordjs/builders'; +import { REST } from '@discordjs/rest'; +import { Routes } from 'discord-api-types/v9'; // NodeJS Library import cluster from 'node:cluster'; @@ -56,12 +60,15 @@ export class DiscordService { private ddlFileRepo: DdlFileService, private sosmedRepo: SocialMediaService ) { - if (environment.production) { + // if (environment.production) { this.setupBot(); + if (cluster.isMaster) { + this.setupSlash(); + } if (cluster.isWorker) { this.startBot(); } - } + // } } async cfgGithubSet(data): Promise { @@ -74,9 +81,39 @@ export class DiscordService { /** */ + async setupSlash(): Promise { + try { + const rest = new REST({ version: '9' }).setToken(environment.discord.loginToken); + const globalCommands = [ + new SlashCommandBuilder().setName('about').setDescription('FansubID Information ~'), + new SlashCommandBuilder().setName('ping').setDescription('Pong!') + ].map(command => command.toJSON()); + await rest.put( + Routes.applicationCommands(environment.discord.client_id), + { + body: globalCommands + } + ); + const fsidCommands = [ + new SlashCommandBuilder().setName('verify').setDescription('FansubID Account Verification') + .addStringOption(option => option.setName('app_token').setDescription('App Token Verifikasi')) + ].map(command => command.toJSON()); + await rest.put( + Routes.applicationGuildCommands(environment.discord.client_id, environment.discord.guild_id), + { + body: fsidCommands + } + ); + this.gs.log('[DISCORD_SLASH_COMMAND-SUCCESS] 🎉', [...globalCommands, ...fsidCommands]); + } catch (error) { + this.gs.log('[DISCORD_SLASH_COMMAND-FAILED] 🎉', error, 'error'); + } + return this; + } + setupBot(): void { this.bot = new Client({ - restRequestTimeout: 60 * 1000, + restRequestTimeout: CONSTANTS.timeDiscord, intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, @@ -102,14 +139,19 @@ export class DiscordService { 'CHANNEL' ] }); - this.bot.on('messageCreate', (msg: Message) => { - if (msg.channel.id === environment.discord.channelBotId && msg.content.startsWith('~')) { - this.gs.log(`[${msg.guild.name}] 🎉 [${(msg.channel as TextChannel).name}] [${msg.author.username}#${msg.author.discriminator}] ${msg.content} 🎶`); - if (cluster.isMaster) { + if (cluster.isMaster) { + this.bot.on('interactionCreate', async interaction => { + if (!interaction.isCommand()) return; + this.gs.log(`[${interaction.guild.name}] 🎉 [${(interaction.channel as TextChannel).name}] [${interaction.user.username}#${interaction.user.discriminator}] ${interaction.commandName} 🎶`); + this.handleInteraction(interaction); + }); + this.bot.on('messageCreate', (msg: Message) => { + if (msg.channel.id === environment.discord.channelBotId && msg.content.startsWith('~')) { + this.gs.log(`[${msg.guild.name}] 🎉 [${(msg.channel as TextChannel).name}] [${msg.author.username}#${msg.author.discriminator}] ${msg.content} 🎶`); this.handleMessage(msg); } - } - }); + }); + } this.bot.on('ready', async () => { try { this.gs.log(`[DISCORD_SERVICE-READY] 🎉 ${this.bot.user.username}#${this.bot.user.discriminator} - ${this.bot.user.id} 🎶`); @@ -335,20 +377,53 @@ export class DiscordService { }; } - async handleMessage(msg: Message): Promise { + async handleInteraction(interaction: CommandInteraction): Promise { try { - if (msg.content === '~about') { - await msg.reply({ content: `<@${msg.author.id}> https://github.com/${environment.author}/${environment.siteName}` }); - } else if (msg.content === '~ping') { - const latency = Date.now() - new Date(msg.createdTimestamp).getTime(); - await msg.reply({ content: `<@${msg.author.id}> Pong ${latency} ms late!` }); - } else if (msg.content.startsWith('~verify ')) { - await this.verifyAccount(msg); + if (interaction.commandName === 'about') { + await interaction.reply({ content: `<@${interaction.user.id}> https://github.com/${environment.author}/${environment.siteName}` }); + } else if (interaction.commandName === 'ping') { + const latency = Date.now() - new Date(interaction.createdTimestamp).getTime(); + await interaction.reply({ content: `<@${interaction.user.id}> Pong ${latency} ms late!` }); + } else if (interaction.commandName === 'verify') { + const appToken = interaction.options.getString('app_token'); + const args = appToken?.split(' '); + if (args?.length >= 2 && args?.length <= 3) { + await this.verifyAccount(args, interaction.user.id, interaction); + } else { + await interaction.reply({ content: `<@${interaction.user.id}> Untuk verifikasi, kunjungi ${environment.baseUrl}/verify-discord 🤔` }); + } } else { - await msg.reply({ content: `<@${msg.author.id}> Perintah tidak sesuai, silahkan lihat ${environment.baseUrl}/docs dan ${environment.baseUrl}/api` }); + await interaction.reply({ content: `<@${interaction.user.id}> Perintah tidak sesuai, silahkan lihat ${environment.baseUrl}/docs dan ${environment.baseUrl}/api` }); } - if (msg.content.includes('DELETE_CHAT')) { - await msg.delete(); + } catch (error) { + this.gs.log('[DISCORD_SERVICE-HANDLE_INTERACTION] 🎉', error, 'error'); + } + } + + async handleMessage(msg: Message): Promise { + try { + if (msg.content) { + if (msg.content === '~about') { + await msg.reply({ content: `<@${msg.author.id}> https://github.com/${environment.author}/${environment.siteName}` }); + } else if (msg.content === '~ping') { + const latency = Date.now() - new Date(msg.createdTimestamp).getTime(); + await msg.reply({ content: `<@${msg.author.id}> Pong ${latency} ms late!` }); + } else if (msg.content.startsWith('~verify ')) { + const args = msg.content.split(' '); + args.reverse(); + args.pop(); + args.reverse(); + if (args.length >= 2 && args.length <= 3) { + await this.verifyAccount([args[1], args[2]], msg.author.id, msg); + } else { + await msg.reply({ content: `<@${msg.author.id}> Untuk verifikasi, kunjungi ${environment.baseUrl}/verify-discord 🤔` }); + } + } else { + await msg.reply({ content: `<@${msg.author.id}> Perintah tidak sesuai, silahkan lihat ${environment.baseUrl}/docs dan ${environment.baseUrl}/api` }); + } + if (msg.content.includes('DELETE_CHAT')) { + await msg.delete(); + } } } catch (error) { this.gs.log('[DISCORD_SERVICE-HANDLE_MESSAGE] 🎉', error, 'error'); @@ -386,60 +461,57 @@ export class DiscordService { } } - async verifyAccount(msg: Message): Promise> { + async verifyAccount(appToken: string[], userAuthorId: string, interactionMessage): Promise { try { - const args = msg.content.split(' '); - if (args.length >= 3 && args.length <= 4) { - const decoded = this.cs.jwtDecode(args[2]); - if (decoded.discord.id === msg.author.id) { - const user = await this.userRepo.findOneOrFail({ - where: [ - { id: Equal(decoded.user.id) } - ], - relations: ['kartu_tanda_penduduk_', 'profile_'] - }) - if (user.verified) { - return await msg.reply({ content: `<@${msg.author.id}> Akun sudah diverifikasi 😍 Yeay 🥰` }); - } else if (args[1] === SosMedModel.DISCORD) { - if (!decoded.discord.verified) { - return await msg.reply({ content: `<@${msg.author.id}> Akun discord belum terverifikasi 🤔` }); - } - user.verified = true; - await this.userRepo.save(user); - const laboratoryRatsRole = msg.guild.roles.cache.get(environment.discord.laboratoryRatsRoleId); - if (!msg.member.roles.cache.has(laboratoryRatsRole.id)) { - await msg.guild.members.cache.get(decoded.discord.id).roles.add(laboratoryRatsRole); - } - await msg.reply({ content: `<@${msg.author.id}> 😚 .: Berhasil :: ${user.username}@${environment.mailTrap.domain} :. 🤩` }); - return await (msg.guild.channels.cache.get(environment.discord.channelEventId) as TextChannel).send({ - embeds: [ - new MessageEmbed() - .setColor('#69f0ae') - .setTitle(user.kartu_tanda_penduduk_.nama) - .setURL(`${environment.baseUrl}/user/${user.username}`) - .setAuthor({ - name: `${environment.siteName} - Verifikasi Pengguna`, - iconURL: `${environment.baseUrl}/assets/img/favicon.png`, - url: environment.baseUrl - }) - .setDescription(this.gs.htmlToText(user.profile_.description)) - .setThumbnail(user.image_url.startsWith('/') ? environment.baseUrl + user.image_url : user.image_url) - .setTimestamp(user.updated_at) - .setFooter({ - text: user.username, - iconURL: user.image_url.startsWith('/') ? environment.baseUrl + user.image_url : user.image_url - }) - ] - }); + const decoded = this.cs.jwtDecode(appToken[1]); + if (decoded.discord.id === userAuthorId) { + const user = await this.userRepo.findOneOrFail({ + where: [ + { id: Equal(decoded.user.id) } + ], + relations: ['kartu_tanda_penduduk_', 'profile_'] + }) + if (user.verified) { + return await interactionMessage.reply({ content: `<@${userAuthorId}> Akun sudah diverifikasi 😍 Yeay 🥰` }); + } else if (appToken[0] === SosMedModel.DISCORD) { + if (!decoded.discord.verified) { + return await interactionMessage.reply({ content: `<@${userAuthorId}> Akun discord belum terverifikasi 🤔` }); + } + user.verified = true; + await this.userRepo.save(user); + const laboratoryRatsRole = interactionMessage.guild.roles.cache.get(environment.discord.laboratoryRatsRoleId); + const member = interactionMessage.guild.members.cache.get(userAuthorId); + if (!member.roles.cache.has(laboratoryRatsRole.id)) { + await member.roles.add(laboratoryRatsRole); } - throw new Error('Format Data Salah / Token Expired!'); + (interactionMessage.guild.channels.cache.get(environment.discord.channelEventId) as TextChannel).send({ + embeds: [ + new MessageEmbed() + .setColor('#69f0ae') + .setTitle(user.kartu_tanda_penduduk_.nama) + .setURL(`${environment.baseUrl}/user/${user.username}`) + .setAuthor({ + name: `${environment.siteName} - Verifikasi Pengguna`, + iconURL: `${environment.baseUrl}/assets/img/favicon.png`, + url: environment.baseUrl + }) + .setDescription(this.gs.htmlToText(user.profile_.description)) + .setThumbnail(user.image_url.startsWith('/') ? environment.baseUrl + user.image_url : user.image_url) + .setTimestamp(user.updated_at) + .setFooter({ + text: user.username, + iconURL: user.image_url.startsWith('/') ? environment.baseUrl + user.image_url : user.image_url + }) + ] + }); + return await interactionMessage.reply({ content: `<@${userAuthorId}> 😚 .: Berhasil :: ${user.username}@${environment.mailTrap.domain} :. 🤩` }); } - return await msg.reply({ content: `<@${msg.author.id}> Siapa ya? Ini milik orang lain 🤔` }); + throw new Error('Format Data Salah / Token Expired!'); } - return await msg.reply({ content: `<@${msg.author.id}> Untuk verifikasi, kunjungi ${environment.baseUrl}/verify-discord 🤔` }); + return await interactionMessage.reply({ content: `<@${userAuthorId}> Siapa ya? Ini milik orang lain 🤔` }); } catch (error) { try { - return await msg.reply({ content: `<@${msg.author.id}> Format data salah atau token expired 🤔` }); + return await interactionMessage.reply({ content: `<@${userAuthorId}> Format data salah atau token expired 🤔` }); } catch (e) { this.gs.log('[DISCORD_SERVICE-VERIFY_ACCOUNT] 🎉', e, 'error'); return null;