From cd445b19b2bf0bcfad611dfea8ff8620340f11fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Wed, 24 Jul 2024 21:41:24 -0400 Subject: [PATCH] chore: remove ts-mixer dependency (#223) * feat: mixer * feat(api): allow token in proxy options * feat(member): timeout's * chore: apply formatting * fix: xd? * fix: timeout reason * fix: hasTimeout getter * feat: mixer... * fix: setter --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- LICENSE | 203 +++----------------------------- biome.json | 9 +- package.json | 22 +--- pnpm-lock.yaml | 146 +++++++++++++++++++++-- src/api/api.ts | 2 +- src/common/shorters/members.ts | 49 +++++++- src/common/types/resolvables.ts | 4 +- src/deps/mixer.ts | 70 +++++++++++ src/structures/GuildMember.ts | 8 ++ src/structures/Interaction.ts | 10 +- src/structures/channels.ts | 2 +- src/types/index.ts | 24 ++++ 12 files changed, 326 insertions(+), 223 deletions(-) create mode 100644 src/deps/mixer.ts diff --git a/LICENSE b/LICENSE index f887b44..a9c2a68 100644 --- a/LICENSE +++ b/LICENSE @@ -1,190 +1,21 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ +MIT License - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +Copyright (c) 2024 socram03 - 1. Definitions. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - Copyright 2021 Alan Delgado - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/biome.json b/biome.json index 3b539fb..c52ade5 100644 --- a/biome.json +++ b/biome.json @@ -83,7 +83,14 @@ }, "files": { "ignoreUnknown": true, - "ignore": ["node_modules/", "build", "lib", "__test__"] + "ignore": [ + "node_modules/", + "build", + "lib", + "__test__", + "package.json", + "tsconfig.json" + ] }, "organizeImports": { "enabled": false diff --git a/package.json b/package.json index 7d14f40..b97f3ba 100644 --- a/package.json +++ b/package.json @@ -5,16 +5,14 @@ "main": "./lib/index.js", "module": "./lib/index.js", "types": "./lib/index.d.ts", - "files": [ - "lib/**", - "deps/**" - ], + "files": ["lib/**", "deps/**"], "scripts": { - "build": "tsc --outDir ./lib", + "build": "npm run clean && tsc --outDir ./lib", "prepublishOnly": "npm run build", "prepare": "npm run build && husky", "lint": "biome lint --write ./src", "format": "biome format --write ./src", + "clean": "rimraf ./lib", "check-h": "biome check --write ./src", "check": "biome check --write --no-errors-on-unmatched ./src" }, @@ -22,13 +20,10 @@ "license": "Apache-2.0", "dependencies": { "magic-bytes.js": "^1.10.0", - "ts-mixer": "^6.0.4", "ws": "^8.18.0" }, "lint-staged": { - "*.ts": [ - "biome check --write" - ] + "*.ts": ["biome check --write"] }, "devDependencies": { "@biomejs/biome": "1.8.3", @@ -38,6 +33,7 @@ "@types/ws": "^8.5.11", "husky": "^9.1.1", "lint-staged": "^15.2.7", + "rimraf": "5.0.9", "typescript": "^5.5.3" }, "optionalDependencies": { @@ -54,13 +50,7 @@ "bugs": { "url": "https://github.com/tiramisulabs/seyfert" }, - "keywords": [ - "api", - "discord", - "bots", - "typescript", - "botdev" - ], + "keywords": ["api", "discord", "bots", "typescript", "botdev"], "publishConfig": { "access": "public" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e0e29a..aba54f4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,9 +11,6 @@ importers: magic-bytes.js: specifier: ^1.10.0 version: 1.10.0 - ts-mixer: - specifier: ^6.0.4 - version: 6.0.4 ws: specifier: ^8.18.0 version: 8.18.0 @@ -52,6 +49,9 @@ importers: lint-staged: specifier: ^15.2.7 version: 15.2.7 + rimraf: + specifier: 5.0.9 + version: 5.0.9 typescript: specifier: ^5.5.3 version: 5.5.3 @@ -195,6 +195,14 @@ packages: '@ioredis/commands@1.2.0': resolution: {integrity: sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg==} + '@isaacs/cliui@8.0.2': + resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} + engines: {node: '>=12'} + + '@pkgjs/parseargs@0.11.0': + resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} + engines: {node: '>=14'} + '@types/conventional-commits-parser@5.0.0': resolution: {integrity: sha512-loB369iXNmAZglwWATL+WRe+CRMmmBPtpolYzIebFaX4YA3x+BEfLqhUAV9WanycKI3TG1IMr5bMJDajDKLlUQ==} @@ -245,10 +253,16 @@ packages: array-ify@1.0.0: resolution: {integrity: sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==} + balanced-match@1.0.2: + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + binary-extensions@2.3.0: resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} engines: {node: '>=8'} + brace-expansion@2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -363,12 +377,18 @@ packages: resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==} engines: {node: '>=8'} + eastasianwidth@0.2.0: + resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} + emoji-regex@10.3.0: resolution: {integrity: sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==} emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + emoji-regex@9.2.2: + resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} + env-paths@2.2.1: resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==} engines: {node: '>=6'} @@ -405,6 +425,10 @@ packages: resolution: {integrity: sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==} engines: {node: '>=18'} + foreground-child@3.2.1: + resolution: {integrity: sha512-PXUUyLqrR2XCWICfv6ukppP96sdFwWbNEnfEMt7jNsISjMsvaLNinAHNDYyvkyU+SZG2BTSbT5NjG+vZslfGTA==} + engines: {node: '>=14'} + fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} @@ -431,6 +455,10 @@ packages: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} + glob@10.4.5: + resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==} + hasBin: true + global-directory@4.0.1: resolution: {integrity: sha512-wHTUcDUoZ1H5/0iVqEudYW4/kAlN5cZ3j/bXn0Dpbizl9iaUVeWSHqiOjsgk6OW2bkLclbBjzewBz6weQ1zA2Q==} engines: {node: '>=18'} @@ -509,6 +537,9 @@ packages: isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + jackspeak@3.4.3: + resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} + jiti@1.21.6: resolution: {integrity: sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==} hasBin: true @@ -587,6 +618,9 @@ packages: resolution: {integrity: sha512-niTvB4gqvtof056rRIrTZvjNYE4rCUzO6X/X+kYjd7WFxXeJ0NwEFnRxX6ehkvv3jTwrXnNdtAak5XYZuIyPFw==} engines: {node: '>=18'} + lru-cache@10.4.3: + resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} + magic-bytes.js@1.10.0: resolution: {integrity: sha512-/k20Lg2q8LE5xiaaSkMXk4sfvI+9EGEykFS4b0CHHGWqDYU0bGUFSwchNOMA56D7TCs9GwVTkqe9als1/ns8UQ==} @@ -609,9 +643,17 @@ packages: resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} engines: {node: '>=12'} + minimatch@9.0.5: + resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} + engines: {node: '>=16 || 14 >=14.17'} + minimist@1.2.8: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + minipass@7.1.2: + resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} + engines: {node: '>=16 || 14 >=14.17'} + ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} @@ -639,6 +681,9 @@ packages: resolution: {integrity: sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + package-json-from-dist@1.0.0: + resolution: {integrity: sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==} + parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -659,6 +704,10 @@ packages: resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==} engines: {node: '>=12'} + path-scurry@1.11.1: + resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==} + engines: {node: '>=16 || 14 >=14.18'} + picocolors@1.0.1: resolution: {integrity: sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==} @@ -706,6 +755,11 @@ packages: rfdc@1.4.1: resolution: {integrity: sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==} + rimraf@5.0.9: + resolution: {integrity: sha512-3i7b8OcswU6CpU8Ej89quJD4O98id7TtVM5U4Mybh84zQXdrFmDLouWBEEaD/QfO3gDDfH+AGFCGsR7kngzQnA==} + engines: {node: 14 >=14.20 || 16 >=16.20 || >=18} + hasBin: true + semver@7.6.3: resolution: {integrity: sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==} engines: {node: '>=10'} @@ -749,6 +803,10 @@ packages: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} + string-width@5.1.2: + resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} + engines: {node: '>=12'} + string-width@7.2.0: resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==} engines: {node: '>=18'} @@ -780,9 +838,6 @@ packages: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} - ts-mixer@6.0.4: - resolution: {integrity: sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA==} - tweetnacl@1.0.3: resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==} @@ -811,6 +866,10 @@ packages: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} + wrap-ansi@8.1.0: + resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} + engines: {node: '>=12'} + wrap-ansi@9.0.0: resolution: {integrity: sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==} engines: {node: '>=18'} @@ -1013,6 +1072,18 @@ snapshots: '@ioredis/commands@1.2.0': optional: true + '@isaacs/cliui@8.0.2': + dependencies: + string-width: 5.1.2 + string-width-cjs: string-width@4.2.3 + strip-ansi: 7.1.0 + strip-ansi-cjs: strip-ansi@6.0.1 + wrap-ansi: 8.1.0 + wrap-ansi-cjs: wrap-ansi@7.0.0 + + '@pkgjs/parseargs@0.11.0': + optional: true + '@types/conventional-commits-parser@5.0.0': dependencies: '@types/node': 20.14.11 @@ -1063,9 +1134,15 @@ snapshots: array-ify@1.0.0: {} + balanced-match@1.0.2: {} + binary-extensions@2.3.0: optional: true + brace-expansion@2.0.1: + dependencies: + balanced-match: 1.0.2 + braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -1182,10 +1259,14 @@ snapshots: dependencies: is-obj: 2.0.0 + eastasianwidth@0.2.0: {} + emoji-regex@10.3.0: {} emoji-regex@8.0.0: {} + emoji-regex@9.2.2: {} + env-paths@2.2.1: {} error-ex@1.3.2: @@ -1224,6 +1305,11 @@ snapshots: path-exists: 5.0.0 unicorn-magic: 0.1.0 + foreground-child@3.2.1: + dependencies: + cross-spawn: 7.0.3 + signal-exit: 4.1.0 + fsevents@2.3.3: optional: true @@ -1244,6 +1330,15 @@ snapshots: is-glob: 4.0.3 optional: true + glob@10.4.5: + dependencies: + foreground-child: 3.2.1 + jackspeak: 3.4.3 + minimatch: 9.0.5 + minipass: 7.1.2 + package-json-from-dist: 1.0.0 + path-scurry: 1.11.1 + global-directory@4.0.1: dependencies: ini: 4.1.1 @@ -1313,6 +1408,12 @@ snapshots: isexe@2.0.0: {} + jackspeak@3.4.3: + dependencies: + '@isaacs/cliui': 8.0.2 + optionalDependencies: + '@pkgjs/parseargs': 0.11.0 + jiti@1.21.6: {} js-tokens@4.0.0: {} @@ -1391,6 +1492,8 @@ snapshots: strip-ansi: 7.1.0 wrap-ansi: 9.0.0 + lru-cache@10.4.3: {} + magic-bytes.js@1.10.0: {} meow@12.1.1: {} @@ -1406,8 +1509,14 @@ snapshots: mimic-fn@4.0.0: {} + minimatch@9.0.5: + dependencies: + brace-expansion: 2.0.1 + minimist@1.2.8: {} + minipass@7.1.2: {} + ms@2.1.2: {} normalize-path@3.0.0: @@ -1433,6 +1542,8 @@ snapshots: dependencies: p-limit: 4.0.0 + package-json-from-dist@1.0.0: {} + parent-module@1.0.1: dependencies: callsites: 3.1.0 @@ -1450,6 +1561,11 @@ snapshots: path-key@4.0.0: {} + path-scurry@1.11.1: + dependencies: + lru-cache: 10.4.3 + minipass: 7.1.2 + picocolors@1.0.1: {} picomatch@2.3.1: {} @@ -1484,6 +1600,10 @@ snapshots: rfdc@1.4.1: {} + rimraf@5.0.9: + dependencies: + glob: 10.4.5 + semver@7.6.3: {} shebang-command@2.0.0: @@ -1519,6 +1639,12 @@ snapshots: is-fullwidth-code-point: 3.0.0 strip-ansi: 6.0.1 + string-width@5.1.2: + dependencies: + eastasianwidth: 0.2.0 + emoji-regex: 9.2.2 + strip-ansi: 7.1.0 + string-width@7.2.0: dependencies: emoji-regex: 10.3.0 @@ -1547,8 +1673,6 @@ snapshots: dependencies: is-number: 7.0.0 - ts-mixer@6.0.4: {} - tweetnacl@1.0.3: optional: true @@ -1571,6 +1695,12 @@ snapshots: string-width: 4.2.3 strip-ansi: 6.0.1 + wrap-ansi@8.1.0: + dependencies: + ansi-styles: 6.2.1 + string-width: 5.1.2 + strip-ansi: 7.1.0 + wrap-ansi@9.0.0: dependencies: ansi-styles: 6.2.1 diff --git a/src/api/api.ts b/src/api/api.ts index c52a50c..710b267 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -420,7 +420,7 @@ export class ApiHandler { } } -export type RequestOptions = Pick; +export type RequestOptions = Pick; export type RequestObject< M extends ProxyRequestMethod, B = Record, diff --git a/src/common/shorters/members.ts b/src/common/shorters/members.ts index 37d514c..2a2b80e 100644 --- a/src/common/shorters/members.ts +++ b/src/common/shorters/members.ts @@ -30,12 +30,16 @@ export class MemberShorter extends BaseShorter { } return this.search(guildId, { query: resolve, limit: 1 }).then(x => x[0]); } - if (resolve.id) { - return this.client.members.fetch(guildId, resolve.id); + + const id = 'id' in resolve ? resolve.id : resolve.user?.id; + + if (id) { + return this.client.members.fetch(guildId, id); } - return resolve.displayName - ? this.search(guildId, { query: resolve.displayName, limit: 1 }).then(x => x[0]) - : undefined; + + const displayName = 'displayName' in resolve ? resolve.displayName : resolve.nick ?? resolve.user?.username; + + return displayName ? this.search(guildId, { query: displayName, limit: 1 }).then(x => x[0]) : undefined; } /** @@ -221,4 +225,39 @@ export class MemberShorter extends BaseShorter { voice(guildId: string, memberId: string) { return this.client.cache.voiceStates?.get(memberId, guildId); } + + /** + * Timeouts a member from the guild. + * @param guildId The ID of the guild. + * @param memberId The ID of the member to timeout. + * @param time The time in seconds to timeout the member for. + * @param reason The reason for the timeout. + */ + timeout(guildId: string, memberId: string, time: number | null, reason?: string) { + return this.edit( + guildId, + memberId, + { + communication_disabled_until: time ? new Date(Date.now() + time * 1000).toISOString() : null, + }, + reason, + ); + } + + /** + * Checks if a member has a timeout. + * @param member The member to check. + * @returns The time left until the timeout expires, in milliseconds, or false if the member does not have a timeout. + */ + hasTimeout(member: Exclude): false | number { + // @ts-expect-error + const timeout = member.communication_disabled_until ?? member.communicationDisabledUntil; + + if (!timeout) return false; + + const parsed = Date.parse(timeout); + const now = Date.now(); + if (parsed > now) return parsed - now; + return false; + } } diff --git a/src/common/types/resolvables.ts b/src/common/types/resolvables.ts index 70be9c7..80a2678 100644 --- a/src/common/types/resolvables.ts +++ b/src/common/types/resolvables.ts @@ -1,9 +1,9 @@ -import type { APIPartialEmoji } from '../../types'; +import type { APIGuildMember, APIPartialEmoji } from '../../types'; import type { EmbedColors } from '..'; import type { Attachment, AttachmentDataType, AttachmentResolvable } from '../../builders'; import type { GuildMember } from '../../structures'; export type EmojiResolvable = string | Partial | `<${string | undefined}:${string}:${string}>`; -export type GuildMemberResolvable = string | Partial; +export type GuildMemberResolvable = string | Partial | APIGuildMember; export type ColorResolvable = `#${string}` | number | keyof typeof EmbedColors | 'Random' | [number, number, number]; export type ImageResolvable = { data: AttachmentResolvable; type: AttachmentDataType } | Attachment; diff --git a/src/deps/mixer.ts b/src/deps/mixer.ts new file mode 100644 index 0000000..35b7a69 --- /dev/null +++ b/src/deps/mixer.ts @@ -0,0 +1,70 @@ +/** + * Gets the descriptors of a class. + * @param c The class to get the descriptors of. + * @returns The descriptors of the class. + */ +function getDescriptors(c: TypeClass) { + let proto = c.prototype; + const result: Record | PropertyDescriptor>[] = []; + while (proto) { + const descriptors = Object.getOwnPropertyDescriptors(proto); + // @ts-expect-error this is not a function in all cases + if (descriptors.valueOf.configurable) break; + result.push(descriptors); + proto = proto.__proto__; + } + return result; +} + +/** + * Mixes a class with other classes. + * @param args The classes to mix. + * @returns The mixed class. + */ +export function Mixin(...args: C): C[number] & T { + function MixedClass(...constructorArgs: any[]) { + for (const i of args) { + const descriptors = getDescriptors(i); + for (const j of descriptors) { + // @ts-expect-error + Object.assign(this, new j.constructor.value(...constructorArgs)); + + for (const descriptorK in j) { + if (descriptorK === 'constructor') continue; + const descriptor = j[descriptorK]; + if (descriptor.value) { + MixedClass.prototype[descriptorK] = descriptor.value; + continue; + } + if (descriptor.get || descriptor.set) { + Object.defineProperty(MixedClass.prototype, descriptorK, { + get: descriptor.get, + set: descriptor.set, + }); + } + } + } + } + } + + return MixedClass as C[number] & T; +} + +// https://github.com/tannerntannern/ts-mixer +export type TypeClass = (abstract new ( + ...args: any[] +) => InstanceType) & + StaticType; + +export const mix = + (...ingredients: TypeClass[]) => + (decoratedClass: any) => { + const mixedClass = Mixin(...ingredients.concat([decoratedClass])); + + Object.defineProperty(mixedClass, 'name', { + value: decoratedClass.name, + writable: false, + }); + + return mixedClass as any; + }; diff --git a/src/structures/GuildMember.ts b/src/structures/GuildMember.ts index 229101f..a99b83a 100644 --- a/src/structures/GuildMember.ts +++ b/src/structures/GuildMember.ts @@ -82,6 +82,14 @@ export class BaseGuildMember extends DiscordBase { return Formatter.userMention(this.id); } + timeout(time: null | number, reason?: string) { + return this.client.members.timeout(this.guildId, this.id, time, reason); + } + + get hasTimeout(): false | number { + return this.client.members.hasTimeout(this); + } + private patch(data: GuildMemberData) { if ('joined_at' in data && data.joined_at) { this.joinedTimestamp = Date.parse(data.joined_at); diff --git a/src/structures/Interaction.ts b/src/structures/Interaction.ts index abd40b2..fc109a6 100644 --- a/src/structures/Interaction.ts +++ b/src/structures/Interaction.ts @@ -37,12 +37,15 @@ import { type RESTPostAPIInteractionCallbackJSONBody, type RESTAPIAttachment, } from '../types'; -import { mix } from 'ts-mixer'; + import type { RawFile } from '../api'; import { ActionRow, Embed, Modal, PollBuilder, resolveAttachment, resolveFiles } from '../builders'; import type { ContextOptionsResolved, UsingClient } from '../commands'; -import type { ObjectToLower, OmitInsert, ToClass, When } from '../common'; import type { + ObjectToLower, + OmitInsert, + ToClass, + When, ComponentInteractionMessageUpdate, InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, @@ -50,7 +53,7 @@ import type { MessageUpdateBodyRequest, MessageWebhookCreateBodyRequest, ModalCreateBodyRequest, -} from '../common/types/write'; +} from '../common'; import type { AllChannels } from './'; import channelFrom from './channels'; import { DiscordBase } from './extra/DiscordBase'; @@ -64,6 +67,7 @@ import { type WebhookMessageStructure, type OptionResolverStructure, } from '../client/transformers'; +import { mix } from '../deps/mixer'; export type ReplyInteractionBody = | { type: InteractionResponseType.Modal; data: ModalCreateBodyRequest } diff --git a/src/structures/channels.ts b/src/structures/channels.ts index 298b1ee..56b1468 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -25,7 +25,6 @@ import { ChannelType, VideoQualityMode, } from '../types'; -import { mix } from 'ts-mixer'; import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders'; import type { UsingClient } from '../commands'; import type { @@ -58,6 +57,7 @@ import { Transformers, type VoiceChannelStructure, } from '../client/transformers'; +import { mix } from '../deps/mixer'; export class BaseChannel extends DiscordBase> { declare type: T; diff --git a/src/types/index.ts b/src/types/index.ts index 3a4621e..a78d030 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2020 vladfrangu + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + export * from './gateway'; export * from './rest'; export * from './payloads';