diff options
Diffstat (limited to 'node_modules/@discordjs')
79 files changed, 30275 insertions, 0 deletions
diff --git a/node_modules/@discordjs/builders/CHANGELOG.md b/node_modules/@discordjs/builders/CHANGELOG.md new file mode 100644 index 0000000..b6bbea4 --- /dev/null +++ b/node_modules/@discordjs/builders/CHANGELOG.md @@ -0,0 +1,327 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +# [@discordjs/builders@1.6.5](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.4...@discordjs/builders@1.6.5) - (2023-08-17) + +## Documentation + +- Update Node.js requirement to 16.11.0 (#9764) ([188877c](https://github.com/discordjs/discord.js/commit/188877c50af70f0d5cffb246620fa277435c6ce6)) + +# [@discordjs/builders@1.6.3](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.2...@discordjs/builders@1.6.3) - (2023-05-01) + +## Refactor + +- Remove `@discordjs/util` re-export (#9488) ([54ceedf](https://github.com/discordjs/discord.js/commit/54ceedf6c535d4641643d4106b6286cbef09de4a)) + +# [@discordjs/builders@1.6.2](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.1...@discordjs/builders@1.6.2) - (2023-05-01) + +## Bug Fixes + +- **BaseSelectMenuBuilder:** Modify class to be `abstract` (#9358) ([ca4de2d](https://github.com/discordjs/discord.js/commit/ca4de2d9c6bc204e85d1b7eae7eabd23dbeb4475)) +- Correct `@link` tags that involve parents (#9351) ([fbbce3e](https://github.com/discordjs/discord.js/commit/fbbce3eb4ba20bc0c4806ca2259d1f86001594be)) +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Reference package names properly (#9426) ([d6bca9b](https://github.com/discordjs/discord.js/commit/d6bca9bb4d976dc069a5039250db7d5b3e9142ef)) +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) +- **builders:** Add some basic documentation (#9359) ([8073561](https://github.com/discordjs/discord.js/commit/8073561824f911d1a18d0b4f1de39f452bc69fa9)) +- Use `@link` in `@see` (#9348) ([d66d113](https://github.com/discordjs/discord.js/commit/d66d1133331b81563588db4500c63a18c3c3dfae)) + +# [@discordjs/builders@1.6.3](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.2...@discordjs/builders@1.6.3) - (2023-05-01) + +## Refactor + +- Remove `@discordjs/util` re-export (#9488) ([54ceedf](https://github.com/discordjs/discord.js/commit/54ceedf6c535d4641643d4106b6286cbef09de4a)) + +# [@discordjs/builders@1.6.2](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.1...@discordjs/builders@1.6.2) - (2023-05-01) + +## Bug Fixes + +- **BaseSelectMenuBuilder:** Modify class to be `abstract` (#9358) ([ca4de2d](https://github.com/discordjs/discord.js/commit/ca4de2d9c6bc204e85d1b7eae7eabd23dbeb4475)) +- Correct `@link` tags that involve parents (#9351) ([fbbce3e](https://github.com/discordjs/discord.js/commit/fbbce3eb4ba20bc0c4806ca2259d1f86001594be)) +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Reference package names properly (#9426) ([d6bca9b](https://github.com/discordjs/discord.js/commit/d6bca9bb4d976dc069a5039250db7d5b3e9142ef)) +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) +- **builders:** Add some basic documentation (#9359) ([8073561](https://github.com/discordjs/discord.js/commit/8073561824f911d1a18d0b4f1de39f452bc69fa9)) +- Use `@link` in `@see` (#9348) ([d66d113](https://github.com/discordjs/discord.js/commit/d66d1133331b81563588db4500c63a18c3c3dfae)) + +# [@discordjs/builders@1.6.3](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.2...@discordjs/builders@1.6.3) - (2023-05-01) + +## Refactor + +- Remove `@discordjs/util` re-export (#9488) ([54ceedf](https://github.com/discordjs/discord.js/commit/54ceedf6c535d4641643d4106b6286cbef09de4a)) + +# [@discordjs/builders@1.6.2](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.1...@discordjs/builders@1.6.2) - (2023-05-01) + +## Bug Fixes + +- **BaseSelectMenuBuilder:** Modify class to be `abstract` (#9358) ([ca4de2d](https://github.com/discordjs/discord.js/commit/ca4de2d9c6bc204e85d1b7eae7eabd23dbeb4475)) +- Correct `@link` tags that involve parents (#9351) ([fbbce3e](https://github.com/discordjs/discord.js/commit/fbbce3eb4ba20bc0c4806ca2259d1f86001594be)) +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Reference package names properly (#9426) ([d6bca9b](https://github.com/discordjs/discord.js/commit/d6bca9bb4d976dc069a5039250db7d5b3e9142ef)) +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) +- **builders:** Add some basic documentation (#9359) ([8073561](https://github.com/discordjs/discord.js/commit/8073561824f911d1a18d0b4f1de39f452bc69fa9)) +- Use `@link` in `@see` (#9348) ([d66d113](https://github.com/discordjs/discord.js/commit/d66d1133331b81563588db4500c63a18c3c3dfae)) + +# [@discordjs/builders@1.6.2](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.6.1...@discordjs/builders@1.6.2) - (2023-05-01) + +## Bug Fixes + +- **BaseSelectMenuBuilder:** Modify class to be `abstract` (#9358) ([ca4de2d](https://github.com/discordjs/discord.js/commit/ca4de2d9c6bc204e85d1b7eae7eabd23dbeb4475)) +- Correct `@link` tags that involve parents (#9351) ([fbbce3e](https://github.com/discordjs/discord.js/commit/fbbce3eb4ba20bc0c4806ca2259d1f86001594be)) +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Reference package names properly (#9426) ([d6bca9b](https://github.com/discordjs/discord.js/commit/d6bca9bb4d976dc069a5039250db7d5b3e9142ef)) +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) +- **builders:** Add some basic documentation (#9359) ([8073561](https://github.com/discordjs/discord.js/commit/8073561824f911d1a18d0b4f1de39f452bc69fa9)) +- Use `@link` in `@see` (#9348) ([d66d113](https://github.com/discordjs/discord.js/commit/d66d1133331b81563588db4500c63a18c3c3dfae)) + +# [@discordjs/builders@1.6.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.5.0...@discordjs/builders@1.6.0) - (2023-04-01) + +## Bug Fixes + +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/builders@1.5.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.4.0...@discordjs/builders@1.5.0) - (2023-03-12) + +## Documentation + +- **EmbedBuilder#spliceFields:** Fix a typo (#9159) ([4367ab9](https://github.com/discordjs/discord.js/commit/4367ab930227048868db3ed8437f6c4507ff32e1)) +- Fix version export (#9049) ([8b70f49](https://github.com/discordjs/discord.js/commit/8b70f497a1207e30edebdecd12b926c981c13d28)) + +## Features + +- **website:** Add support for source file links (#9048) ([f6506e9](https://github.com/discordjs/discord.js/commit/f6506e99c496683ee0ab67db0726b105b929af38)) +- **StringSelectMenu:** Add `spliceOptions()` (#8937) ([a6941d5](https://github.com/discordjs/discord.js/commit/a6941d536ce24ed2b5446a154cbc886b2b97c63a)) +- Add support for nsfw commands (#7976) ([7a51344](https://github.com/discordjs/discord.js/commit/7a5134459c5f06864bf74631d83b96d9c21b72d8)) +- Add `@discordjs/formatters` (#8889) ([3fca638](https://github.com/discordjs/discord.js/commit/3fca638a8470dcea2f79ddb9f18526dbc0017c88)) + +## Styling + +- Run prettier (#9041) ([2798ba1](https://github.com/discordjs/discord.js/commit/2798ba1eb3d734f0cf2eeccd2e16cfba6804873b)) + +# [@discordjs/builders@1.4.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.3.0...@discordjs/builders@1.4.0) - (2022-11-28) + +## Bug Fixes + +- Pin @types/node version ([9d8179c](https://github.com/discordjs/discord.js/commit/9d8179c6a78e1c7f9976f852804055964d5385d4)) + +## Features + +- New select menus (#8793) ([5152abf](https://github.com/discordjs/discord.js/commit/5152abf7285581abf7689e9050fdc56c4abb1e2b)) +- Allow punctuation characters in context menus (#8783) ([b521366](https://github.com/discordjs/discord.js/commit/b5213664fa66746daab1673ebe2adf2db3d1522c)) + +## Typings + +- **Formatters:** Allow boolean in `formatEmoji` (#8823) ([ec37f13](https://github.com/discordjs/discord.js/commit/ec37f137fd4fca0fdbdb8a5c83abf32362a8f285)) + +# [@discordjs/builders@1.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.2.0...@discordjs/builders@1.3.0) - (2022-10-08) + +## Bug Fixes + +- Allow adding forums to `channelTypes` (#8658) ([b1e190c](https://github.com/discordjs/discord.js/commit/b1e190c4f0773a1a739625f5b41026f593515370)) +- **SlashCommandBuilder:** Missing methods in subcommand builder (#8583) ([1c5b78f](https://github.com/discordjs/discord.js/commit/1c5b78fd2130f09c951459cf4c2d637f46c3c2c9)) +- Footer / sidebar / deprecation alert ([ba3e0ed](https://github.com/discordjs/discord.js/commit/ba3e0ed348258fe8e51eefb4aa7379a1230616a9)) + +## Documentation + +- **builders/components:** Document constructors (#8636) ([8444576](https://github.com/discordjs/discord.js/commit/8444576f45da5fdddbf8ba2d91b4cb31a3b51c04)) +- Change name (#8604) ([dd5a089](https://github.com/discordjs/discord.js/commit/dd5a08944c258a847fc4377f1d5e953264ab47d0)) +- Use remarks instead of `Note` in descriptions (#8597) ([f3ce4a7](https://github.com/discordjs/discord.js/commit/f3ce4a75d0c4eafc89a1f0ce9f4964bcbcdae6da)) + +## Features + +- Web-components (#8715) ([0ac3e76](https://github.com/discordjs/discord.js/commit/0ac3e766bd9dbdeb106483fa4bb085d74de346a2)) +- Add `@discordjs/util` (#8591) ([b2ec865](https://github.com/discordjs/discord.js/commit/b2ec865765bf94181473864a627fb63ea8173fd3)) +- Add `chatInputApplicationCommandMention` formatter (#8546) ([d08a57c](https://github.com/discordjs/discord.js/commit/d08a57cadd9d69a734077cc1902d931ab10336db)) + +## Refactor + +- Replace usage of deprecated `ChannelType`s (#8625) ([669c3cd](https://github.com/discordjs/discord.js/commit/669c3cd2566eac68ef38ab522dd6378ba761e8b3)) +- Website components (#8600) ([c334157](https://github.com/discordjs/discord.js/commit/c3341570d983aea9ecc419979d5a01de658c9d67)) +- Use `eslint-config-neon` for packages. (#8579) ([edadb9f](https://github.com/discordjs/discord.js/commit/edadb9fe5dfd9ff51a3cfc9b25cb242d3f9f5241)) + +## Testing + +- Rename incorrect test (#8596) ([ce991dd](https://github.com/discordjs/discord.js/commit/ce991dd1d883f6785b5f4b4b3ac80ef21cb304e7)) + +## Typings + +- **interactions:** Fix `{Slash,ContextMenu}CommandBuilder#toJSON` (#8568) ([b7eb96d](https://github.com/discordjs/discord.js/commit/b7eb96d45670616521fbcca28a657793d91605c7)) + +# [@discordjs/builders@1.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.1.0...@discordjs/builders@1.2.0) - (2022-08-22) + +## Features + +- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007)) +- **website:** Show descriptions for `@typeParam` blocks (#8523) ([e475b63](https://github.com/discordjs/discord.js/commit/e475b63f257f6261d73cb89fee9ecbcdd84e2a6b)) +- **website:** Show parameter descriptions (#8519) ([7f415a2](https://github.com/discordjs/discord.js/commit/7f415a2502bf7ce2025dbcfed9017b0635a19966)) +- **WebSocketShard:** Support new resume url (#8480) ([bc06cc6](https://github.com/discordjs/discord.js/commit/bc06cc638d2f57ab5c600e8cdb6afc8eb2180166)) + +## Refactor + +- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e)) + +# [@discordjs/builders@1.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.16.0...@discordjs/builders@1.1.0) - (2022-07-29) + +## Bug Fixes + +- Use proper format for `@link` text (#8384) ([2655639](https://github.com/discordjs/discord.js/commit/26556390a3800e954974a00c1328ff47d3e67e9a)) +- **Formatters:** Add newline in `codeBlock` (#8369) ([5d8bd03](https://github.com/discordjs/discord.js/commit/5d8bd030d60ef364de3ef5f9963da8bda5c4efd4)) +- **selectMenu:** Allow json to be used for select menu options (#8322) ([6a2d0d8](https://github.com/discordjs/discord.js/commit/6a2d0d8e96d157d5b85cee7f17bffdfff4240074)) + +## Documentation + +- Use link tags (#8382) ([5494791](https://github.com/discordjs/discord.js/commit/549479131318c659f86f0eb18578d597e22522d3)) + +## Features + +- Add channel & message URL formatters (#8371) ([a7deb8f](https://github.com/discordjs/discord.js/commit/a7deb8f89830ead6185c5fb46a49688b6d209ed1)) + +## Testing + +- **builders:** Improve coverage (#8274) ([b7e6238](https://github.com/discordjs/discord.js/commit/b7e62380f2e6b9324d6bba9b9eaa5315080bf66a)) + +# [@discordjs/builders@0.16.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.15.0...@discordjs/builders@0.16.0) - (2022-07-17) + +## Bug Fixes + +- Slash command name regex (#8265) ([32f9056](https://github.com/discordjs/discord.js/commit/32f9056b15edede3bab07de96afb4b56d3a9ecca)) +- **TextInputBuilder:** Parse `custom_id`, `label`, and `style` (#8216) ([2d9dfa3](https://github.com/discordjs/discord.js/commit/2d9dfa3c6ea4bb972da2f7e088d148b798c866d9)) + +## Documentation + +- Add codecov coverage badge to readmes (#8226) ([f6db285](https://github.com/discordjs/discord.js/commit/f6db285c073898a749fe4591cbd4463d1896daf5)) + +## Features + +- **builder:** Add max min length in string option (#8214) ([96c8d21](https://github.com/discordjs/discord.js/commit/96c8d21f95eb366c46ae23505ba9054f44821b25)) +- Codecov (#8219) ([f10f4cd](https://github.com/discordjs/discord.js/commit/f10f4cdcd88ca6be7ec735ed3a415ba13da83db0)) +- **docgen:** Update typedoc ([b3346f4](https://github.com/discordjs/discord.js/commit/b3346f4b9b3d4f96443506643d4631dc1c6d7b21)) +- Website (#8043) ([127931d](https://github.com/discordjs/discord.js/commit/127931d1df7a2a5c27923c2f2151dbf3824e50cc)) +- **docgen:** Typescript support ([3279b40](https://github.com/discordjs/discord.js/commit/3279b40912e6aa61507bedb7db15a2b8668de44b)) +- Docgen package (#8029) ([8b979c0](https://github.com/discordjs/discord.js/commit/8b979c0245c42fd824d8e98745ee869f5360fc86)) + +## Refactor + +- **builder:** Remove `unsafe*Builder`s (#8074) ([a4d1862](https://github.com/discordjs/discord.js/commit/a4d18629828234f43f03d1bd4851d4b727c6903b)) +- Remove @sindresorhus/is as it's now esm only (#8133) ([c6f285b](https://github.com/discordjs/discord.js/commit/c6f285b7b089b004776fbeb444fe973a68d158d8)) +- Move all the config files to root (#8033) ([769ea0b](https://github.com/discordjs/discord.js/commit/769ea0bfe78c4f1d413c6b397c604ffe91e39c6a)) + +## Typings + +- Remove expect error (#8242) ([7e6dbaa](https://github.com/discordjs/discord.js/commit/7e6dbaaed900c07d1a04e23bbbf9cd0d1b0501c5)) +- **builder:** Remove casting (#8241) ([8198da5](https://github.com/discordjs/discord.js/commit/8198da5cd0898e06954615a2287853321e7ebbd4)) + +# [@discordjs/builders@0.15.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.14.0...@discordjs/builders@0.15.0) - (2022-06-06) + +## Features + +- Allow builders to accept rest params and arrays (#7874) ([ad75be9](https://github.com/discordjs/discord.js/commit/ad75be9a9cf90c8624495df99b75177e6c24022f)) +- Use vitest instead of jest for more speed ([8d8e6c0](https://github.com/discordjs/discord.js/commit/8d8e6c03decd7352a2aa180f6e5bc1a13602539b)) +- Add scripts package for locally used scripts ([f2ae1f9](https://github.com/discordjs/discord.js/commit/f2ae1f9348bfd893332a9060f71a8a5f272a1b8b)) + +# [@discordjs/builders@0.14.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.13.0...@discordjs/builders@0.14.0) - (2022-06-04) + +## Bug Fixes + +- **builders:** Leftover invalid null type ([8a7cd10](https://github.com/discordjs/discord.js/commit/8a7cd10554a2a71cd2fe7f6a177b5f4f43464348)) +- **SlashCommandBuilder:** Import `Permissions` correctly (#7921) ([7ce641d](https://github.com/discordjs/discord.js/commit/7ce641d33a4af6586d5e7beffbe7d38619dcf1a2)) +- Add localizations for subcommand builders and option choices (#7862) ([c1b5e73](https://github.com/discordjs/discord.js/commit/c1b5e731daa9cbbfca03a046e47cb1221ee1ed7c)) + +## Features + +- Export types from `interactions/slashCommands/mixins` (#7942) ([68d5169](https://github.com/discordjs/discord.js/commit/68d5169f66c96f8fe5be17a1c01cdd5155607ab2)) +- **builders:** Add new command permissions v2 (#7861) ([de3f157](https://github.com/discordjs/discord.js/commit/de3f1573f07dda294cc0fbb1ca4b659eb2388a12)) +- **builders:** Improve embed errors and predicates (#7795) ([ec8d87f](https://github.com/discordjs/discord.js/commit/ec8d87f93272cc9987f9613735c0361680c4ed1e)) + +## Refactor + +- Use arrays instead of rest parameters for builders (#7759) ([29293d7](https://github.com/discordjs/discord.js/commit/29293d7bbb5ed463e52e5a5853817e5a09cf265b)) + +## Styling + +- Cleanup tests and tsup configs ([6b8ef20](https://github.com/discordjs/discord.js/commit/6b8ef20cb3af5b5cfd176dd0aa0a1a1e98551629)) + +# [@discordjs/builders@0.13.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.12.0...@discordjs/builders@0.13.0) - (2022-04-17) + +## Bug Fixes + +- Validate select menu options (#7566) ([b1d63d9](https://github.com/discordjs/discord.js/commit/b1d63d919a61f309ac89f27016b0f148678dac2b)) +- **SelectMenu:** Set `placeholder` max to 150 (#7538) ([dcd4797](https://github.com/discordjs/discord.js/commit/dcd479767b6ec980a373f2ea1f22754f41661c1e)) +- Only check `instanceof Component` once (#7546) ([0aa4851](https://github.com/discordjs/discord.js/commit/0aa48516a4e33497e8e8dc50da164a57cdee09d3)) +- **builders:** Allow negative min/max value of number/integer option (#7484) ([3baa340](https://github.com/discordjs/discord.js/commit/3baa340821b8ecf8a16253bc0917a1033250d7c9)) +- **components:** SetX should take rest parameters (#7461) ([3617359](https://github.com/discordjs/discord.js/commit/36173590a712f041b087b7882054805a8bd42dae)) +- Unsafe embed builder field normalization (#7418) ([b936103](https://github.com/discordjs/discord.js/commit/b936103395121cb21a8c616f669ddab1d2efb0f1)) +- Fix some typos (#7393) ([92a04f4](https://github.com/discordjs/discord.js/commit/92a04f4d98f6c6760214034cc8f5a1eaa78893c7)) +- **builders:** Make type optional in constructor (#7391) ([4abb28c](https://github.com/discordjs/discord.js/commit/4abb28c0a1256c57a60369a6b8ec9e98c265b489)) +- Don't create new instances of builders classes (#7343) ([d6b56d0](https://github.com/discordjs/discord.js/commit/d6b56d0080c4c5f8ace731f1e8bcae0c9d3fb5a5)) + +## Documentation + +- Completely fix builders example link (#7543) ([1a14c0c](https://github.com/discordjs/discord.js/commit/1a14c0ca562ea173d363a770a0437209f461fd23)) +- Add slash command builders example, fixes #7338 (#7339) ([3ae6f3c](https://github.com/discordjs/discord.js/commit/3ae6f3c313091151245d6e6b52337b459ecfc765)) + +## Features + +- Slash command localization for builders (#7683) ([40b9a1d](https://github.com/discordjs/discord.js/commit/40b9a1d67d0b508ec593e030913acd8161cd17f8)) +- Add API v10 support (#7477) ([72577c4](https://github.com/discordjs/discord.js/commit/72577c4bfd02524a27afb6ff4aebba9301a690d3)) +- Add support for module: NodeNext in TS and ESM (#7598) ([8f1986a](https://github.com/discordjs/discord.js/commit/8f1986a6aa98365e09b00e84ad5f9f354ab61f3d)) +- Add Modals and Text Inputs (#7023) ([ed92015](https://github.com/discordjs/discord.js/commit/ed920156344233241a21b0c0b99736a3a855c23c)) +- Add missing `v13` component methods (#7466) ([f7257f0](https://github.com/discordjs/discord.js/commit/f7257f07655076eabfe355cb6a53260b39ca9670)) +- **builders:** Add attachment command option type (#7203) ([ae0f35f](https://github.com/discordjs/discord.js/commit/ae0f35f51d68dfa5a7dc43d161ef9365171debdb)) +- **components:** Add unsafe message component builders (#7387) ([6b6222b](https://github.com/discordjs/discord.js/commit/6b6222bf513d1ee8cd98fba0ad313def560b864f)) +- **embed:** Add setFields (#7322) ([bcc5cda](https://github.com/discordjs/discord.js/commit/bcc5cda8a902ddb28c7e3578e0f29b4272832624)) + +## Refactor + +- Remove nickname parsing (#7736) ([78a3afc](https://github.com/discordjs/discord.js/commit/78a3afcd7fdac358e06764cc0d675e1215c785f3)) +- Replace zod with shapeshift (#7547) ([3c0bbac](https://github.com/discordjs/discord.js/commit/3c0bbac82fa9988af4a62ff00c66d149fbe6b921)) +- Remove store channels (#7634) ([aedddb8](https://github.com/discordjs/discord.js/commit/aedddb875e740e1f1bd77f06ce1b361fd3b7bc36)) +- Allow builders to accept emoji strings (#7616) ([fb9a9c2](https://github.com/discordjs/discord.js/commit/fb9a9c221121ee1c7986f9c775b77b9691a0ae15)) +- Don't return builders from API data (#7584) ([549716e](https://github.com/discordjs/discord.js/commit/549716e4fcec89ca81216a6d22aa8e623175e37a)) +- Remove obsolete builder methods (#7590) ([10607db](https://github.com/discordjs/discord.js/commit/10607dbdafe257c5cbf5b952b7eecec4919e8b4a)) +- **Embed:** Remove add field (#7522) ([8478d2f](https://github.com/discordjs/discord.js/commit/8478d2f4de9ac013733850cbbc67902f7c5abc55)) +- Make `data` public in builders (#7486) ([ba31203](https://github.com/discordjs/discord.js/commit/ba31203a0ad96e0a00f8312c397889351e4c5cfd)) +- **embed:** Remove array support in favor of rest params (#7498) ([b3fa2ec](https://github.com/discordjs/discord.js/commit/b3fa2ece402839008738ad3adce3db958445838d)) +- **components:** Default set boolean methods to true (#7502) ([b122149](https://github.com/discordjs/discord.js/commit/b12214922cea2f43afbe6b1555a74a3c8e16f798)) +- Make public builder props getters (#7422) ([e8252ed](https://github.com/discordjs/discord.js/commit/e8252ed3b981a4b7e4013f12efadd2f5d9318d3e)) +- **builders-methods:** Make methods consistent (#7395) ([f495364](https://github.com/discordjs/discord.js/commit/f4953647ff9f39127978c73bf8a62c08462802ca)) +- Remove conditional autocomplete option return types (#7396) ([0909824](https://github.com/discordjs/discord.js/commit/09098240bfb13b8afafa4ab549f06d236e0ff1c9)) +- **embed:** Mark properties as readonly (#7332) ([31768fc](https://github.com/discordjs/discord.js/commit/31768fcd69ed5b4566a340bda89ce881418e8272)) + +## Typings + +- Fix regressions (#7649) ([5748dbe](https://github.com/discordjs/discord.js/commit/5748dbe08783beb80c526de38ccd105eb0e82664)) + +# [@discordjs/builders@0.12.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.11.0...@discordjs/builders@0.12.0) - (2022-01-24) + +## Bug Fixes + +- **builders:** Dont export `Button` component stuff twice (#7289) ([86d9d06](https://github.com/discordjs/discord.js/commit/86d9d0674347c08d056cd054cb4ce4253195bf94)) + +## Documentation + +- **SlashCommandSubcommands:** Updating old links from Discord developer portal (#7224) ([bd7a6f2](https://github.com/discordjs/discord.js/commit/bd7a6f265212624199fb0b2ddc8ece39759c63de)) + +## Features + +- Add components to /builders (#7195) ([2bb40fd](https://github.com/discordjs/discord.js/commit/2bb40fd767cf5918e3ba422ff73082734bfa05b0)) + +## Typings + +- Make `required` a boolean (#7307) ([c10afea](https://github.com/discordjs/discord.js/commit/c10afeadc702ab98bec5e077b3b92494a9596f9c)) diff --git a/node_modules/@discordjs/builders/LICENSE b/node_modules/@discordjs/builders/LICENSE new file mode 100644 index 0000000..cbe9c65 --- /dev/null +++ b/node_modules/@discordjs/builders/LICENSE @@ -0,0 +1,191 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "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 Noel Buechler + Copyright 2021 Vlad Frangu + + 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. diff --git a/node_modules/@discordjs/builders/README.md b/node_modules/@discordjs/builders/README.md new file mode 100644 index 0000000..dc88b7f --- /dev/null +++ b/node_modules/@discordjs/builders/README.md @@ -0,0 +1,72 @@ +<div align="center"> + <br /> + <p> + <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a> + </p> + <br /> + <p> + <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a> + <a href="https://www.npmjs.com/package/@discordjs/builders"><img src="https://img.shields.io/npm/v/@discordjs/builders.svg?maxAge=3600" alt="npm version" /></a> + <a href="https://www.npmjs.com/package/@discordjs/builders"><img src="https://img.shields.io/npm/dt/@discordjs/builders.svg?maxAge=3600" alt="npm downloads" /></a> + <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a> + <a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=builders" alt="Code coverage" /></a> + </p> + <p> + <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a> + <a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a> + </p> +</div> + +## About + +`@discordjs/builders` is a utility package for easily building Discord API payloads. + +## Installation + +**Node.js 16.11.0 or newer is required.** + +```sh +npm install @discordjs/builders +yarn add @discordjs/builders +pnpm add @discordjs/builders +``` + +## Examples + +You can find examples of how to use the builders in the [Slash Command Builders][example] examples. + +## Links + +- [Website][website] ([source][website-source]) +- [Documentation][documentation] +- [Guide][guide] ([source][guide-source]) + Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library. +- [discord.js Discord server][discord] +- [Discord API Discord server][discord-api] +- [GitHub][source] +- [npm][npm] +- [Related libraries][related-libs] + +## Contributing + +Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the +[documentation][documentation]. +See [the contribution guide][contributing] if you'd like to submit a PR. + +## Help + +If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord]. + +[example]: https://github.com/discordjs/discord.js/blob/main/packages/builders/docs/examples/Slash%20Command%20Builders.md +[website]: https://discord.js.org +[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website +[documentation]: https://discord.js.org/docs/packages/builders/stable +[guide]: https://discordjs.guide/ +[guide-source]: https://github.com/discordjs/guide +[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html +[discord]: https://discord.gg/djs +[discord-api]: https://discord.gg/discord-api +[source]: https://github.com/discordjs/discord.js/tree/main/packages/builders +[npm]: https://www.npmjs.com/package/@discordjs/builders +[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries +[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md diff --git a/node_modules/@discordjs/builders/dist/index.d.mts b/node_modules/@discordjs/builders/dist/index.d.mts new file mode 100644 index 0000000..ffa1792 --- /dev/null +++ b/node_modules/@discordjs/builders/dist/index.d.mts @@ -0,0 +1,1948 @@ +import * as _sapphire_shapeshift from '@sapphire/shapeshift'; +import { APIEmbedField, APIEmbedAuthor, APIEmbedFooter, APIEmbedImage, APIEmbed, APISelectMenuOption, APIMessageComponentEmoji, ButtonStyle, ChannelType, APIActionRowComponent, APIActionRowComponentTypes, APIBaseComponent, ComponentType, APIButtonComponent, APISelectMenuComponent, APIChannelSelectComponent, APIMentionableSelectComponent, APIRoleSelectComponent, APIStringSelectComponent, APIUserSelectComponent, APITextInputComponent, TextInputStyle, APIMessageActionRowComponent, APIModalActionRowComponent, APIModalComponent, APIMessageComponent, APIModalInteractionResponseCallbackData, LocalizationMap, LocaleString, ApplicationCommandOptionType, APIApplicationCommandBasicOption, APIApplicationCommandAttachmentOption, APIApplicationCommandBooleanOption, APIApplicationCommandChannelOption, APIApplicationCommandOptionChoice, APIApplicationCommandIntegerOption, APIApplicationCommandMentionableOption, APIApplicationCommandNumberOption, APIApplicationCommandRoleOption, APIApplicationCommandStringOption, APIApplicationCommandUserOption, APIApplicationCommandSubcommandGroupOption, APIApplicationCommandSubcommandOption, Permissions, RESTPostAPIChatInputApplicationCommandsJSONBody, APIApplicationCommandOption, Locale, ApplicationCommandType, RESTPostAPIContextMenuApplicationCommandsJSONBody } from 'discord-api-types/v10'; +export * from '@discordjs/formatters'; +import { JSONEncodable, Equatable } from '@discordjs/util'; + +declare const fieldNamePredicate: _sapphire_shapeshift.StringValidator<string>; +declare const fieldValuePredicate: _sapphire_shapeshift.StringValidator<string>; +declare const fieldInlinePredicate: _sapphire_shapeshift.UnionValidator<boolean | undefined>; +declare const embedFieldPredicate: _sapphire_shapeshift.ObjectValidator<{ + name: string; + value: string; + inline: boolean | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + name: string; + value: string; + inline: boolean | undefined; +}>>; +declare const embedFieldsArrayPredicate: _sapphire_shapeshift.ArrayValidator<_sapphire_shapeshift.UndefinedToOptional<{ + name: string; + value: string; + inline: boolean | undefined; +}>[], _sapphire_shapeshift.UndefinedToOptional<{ + name: string; + value: string; + inline: boolean | undefined; +}>>; +declare const fieldLengthPredicate: _sapphire_shapeshift.NumberValidator<number>; +declare function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void; +declare const authorNamePredicate: _sapphire_shapeshift.UnionValidator<string | null>; +declare const imageURLPredicate: _sapphire_shapeshift.UnionValidator<string | null | undefined>; +declare const urlPredicate: _sapphire_shapeshift.UnionValidator<string | null | undefined>; +declare const embedAuthorPredicate: _sapphire_shapeshift.ObjectValidator<{ + name: string | null; + iconURL: string | null | undefined; + url: string | null | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + name: string | null; + iconURL: string | null | undefined; + url: string | null | undefined; +}>>; +declare const RGBPredicate: _sapphire_shapeshift.NumberValidator<number>; +declare const colorPredicate: _sapphire_shapeshift.UnionValidator<number | [number, number, number] | null>; +declare const descriptionPredicate: _sapphire_shapeshift.UnionValidator<string | null>; +declare const footerTextPredicate: _sapphire_shapeshift.UnionValidator<string | null>; +declare const embedFooterPredicate: _sapphire_shapeshift.ObjectValidator<{ + text: string | null; + iconURL: string | null | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + text: string | null; + iconURL: string | null | undefined; +}>>; +declare const timestampPredicate: _sapphire_shapeshift.UnionValidator<number | Date | null>; +declare const titlePredicate: _sapphire_shapeshift.UnionValidator<string | null>; + +declare const Assertions$5_RGBPredicate: typeof RGBPredicate; +declare const Assertions$5_authorNamePredicate: typeof authorNamePredicate; +declare const Assertions$5_colorPredicate: typeof colorPredicate; +declare const Assertions$5_descriptionPredicate: typeof descriptionPredicate; +declare const Assertions$5_embedAuthorPredicate: typeof embedAuthorPredicate; +declare const Assertions$5_embedFieldPredicate: typeof embedFieldPredicate; +declare const Assertions$5_embedFieldsArrayPredicate: typeof embedFieldsArrayPredicate; +declare const Assertions$5_embedFooterPredicate: typeof embedFooterPredicate; +declare const Assertions$5_fieldInlinePredicate: typeof fieldInlinePredicate; +declare const Assertions$5_fieldLengthPredicate: typeof fieldLengthPredicate; +declare const Assertions$5_fieldNamePredicate: typeof fieldNamePredicate; +declare const Assertions$5_fieldValuePredicate: typeof fieldValuePredicate; +declare const Assertions$5_footerTextPredicate: typeof footerTextPredicate; +declare const Assertions$5_imageURLPredicate: typeof imageURLPredicate; +declare const Assertions$5_timestampPredicate: typeof timestampPredicate; +declare const Assertions$5_titlePredicate: typeof titlePredicate; +declare const Assertions$5_urlPredicate: typeof urlPredicate; +declare const Assertions$5_validateFieldLength: typeof validateFieldLength; +declare namespace Assertions$5 { + export { + Assertions$5_RGBPredicate as RGBPredicate, + Assertions$5_authorNamePredicate as authorNamePredicate, + Assertions$5_colorPredicate as colorPredicate, + Assertions$5_descriptionPredicate as descriptionPredicate, + Assertions$5_embedAuthorPredicate as embedAuthorPredicate, + Assertions$5_embedFieldPredicate as embedFieldPredicate, + Assertions$5_embedFieldsArrayPredicate as embedFieldsArrayPredicate, + Assertions$5_embedFooterPredicate as embedFooterPredicate, + Assertions$5_fieldInlinePredicate as fieldInlinePredicate, + Assertions$5_fieldLengthPredicate as fieldLengthPredicate, + Assertions$5_fieldNamePredicate as fieldNamePredicate, + Assertions$5_fieldValuePredicate as fieldValuePredicate, + Assertions$5_footerTextPredicate as footerTextPredicate, + Assertions$5_imageURLPredicate as imageURLPredicate, + Assertions$5_timestampPredicate as timestampPredicate, + Assertions$5_titlePredicate as titlePredicate, + Assertions$5_urlPredicate as urlPredicate, + Assertions$5_validateFieldLength as validateFieldLength, + }; +} + +/** + * Normalizes data that is a rest parameter or an array into an array with a depth of 1. + * + * @typeParam T - The data that must satisfy {@link RestOrArray}. + * @param arr - The (possibly variadic) data to normalize + */ +declare function normalizeArray<T>(arr: RestOrArray<T>): T[]; +/** + * Represents data that may be an array or came from a rest parameter. + * + * @remarks + * This type is used throughout builders to ensure both an array and variadic arguments + * may be used. It is normalized with {@link normalizeArray}. + */ +type RestOrArray<T> = T[] | [T[]]; + +/** + * A tuple satisfying the RGB color model. + * + * @see {@link https://developer.mozilla.org/docs/Glossary/RGB} + */ +type RGBTuple = [red: number, green: number, blue: number]; +/** + * The base icon data typically used in payloads. + */ +interface IconData { + /** + * The URL of the icon. + */ + iconURL?: string; + /** + * The proxy URL of the icon. + */ + proxyIconURL?: string; +} +/** + * Represents the author data of an embed. + */ +type EmbedAuthorData = IconData & Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'>; +/** + * Represents the author options of an embed. + */ +type EmbedAuthorOptions = Omit<EmbedAuthorData, 'proxyIconURL'>; +/** + * Represents the footer data of an embed. + */ +type EmbedFooterData = IconData & Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'>; +/** + * Represents the footer options of an embed. + */ +type EmbedFooterOptions = Omit<EmbedFooterData, 'proxyIconURL'>; +/** + * Represents the image data of an embed. + */ +interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> { + /** + * The proxy URL for the image. + */ + proxyURL?: string; +} +/** + * A builder that creates API-compatible JSON data for embeds. + */ +declare class EmbedBuilder { + /** + * The API data associated with this embed. + */ + readonly data: APIEmbed; + /** + * Creates a new embed from API data. + * + * @param data - The API data to create this embed with + */ + constructor(data?: APIEmbed); + /** + * Appends fields to the embed. + * + * @remarks + * This method accepts either an array of fields or a variable number of field parameters. + * The maximum amount of fields that can be added is 25. + * @example + * Using an array: + * ```ts + * const fields: APIEmbedField[] = ...; + * const embed = new EmbedBuilder() + * .addFields(fields); + * ``` + * @example + * Using rest parameters (variadic): + * ```ts + * const embed = new EmbedBuilder() + * .addFields( + * { name: 'Field 1', value: 'Value 1' }, + * { name: 'Field 2', value: 'Value 2' }, + * ); + * ``` + * @param fields - The fields to add + */ + addFields(...fields: RestOrArray<APIEmbedField>): this; + /** + * Removes, replaces, or inserts fields for this embed. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}. + * The maximum amount of fields that can be added is 25. + * + * It's useful for modifying and adjusting order of the already-existing fields of an embed. + * @example + * Remove the first field: + * ```ts + * embed.spliceFields(0, 1); + * ``` + * @example + * Remove the first n fields: + * ```ts + * const n = 4; + * embed.spliceFields(0, n); + * ``` + * @example + * Remove the last field: + * ```ts + * embed.spliceFields(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of fields to remove + * @param fields - The replacing field objects + */ + spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this; + /** + * Sets the fields for this embed. + * + * @remarks + * This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically, + * it splices the entire array of fields, replacing them with the provided fields. + * + * You can set a maximum of 25 fields. + * @param fields - The fields to set + */ + setFields(...fields: RestOrArray<APIEmbedField>): this; + /** + * Sets the author of this embed. + * + * @param options - The options to use + */ + setAuthor(options: EmbedAuthorOptions | null): this; + /** + * Sets the color of this embed. + * + * @param color - The color to use + */ + setColor(color: RGBTuple | number | null): this; + /** + * Sets the description of this embed. + * + * @param description - The description to use + */ + setDescription(description: string | null): this; + /** + * Sets the footer of this embed. + * + * @param options - The footer to use + */ + setFooter(options: EmbedFooterOptions | null): this; + /** + * Sets the image of this embed. + * + * @param url - The image URL to use + */ + setImage(url: string | null): this; + /** + * Sets the thumbnail of this embed. + * + * @param url - The thumbnail URL to use + */ + setThumbnail(url: string | null): this; + /** + * Sets the timestamp of this embed. + * + * @param timestamp - The timestamp or date to use + */ + setTimestamp(timestamp?: Date | number | null): this; + /** + * Sets the title for this embed. + * + * @param title - The title to use + */ + setTitle(title: string | null): this; + /** + * Sets the URL of this embed. + * + * @param url - The URL to use + */ + setURL(url: string | null): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): APIEmbed; +} + +/** + * A builder that creates API-compatible JSON data for string select menu options. + */ +declare class StringSelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> { + data: Partial<APISelectMenuOption>; + /** + * Creates a new string select menu option from API data. + * + * @param data - The API data to create this string select menu option with + * @example + * Creating a string select menu option from an API data object: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * label: 'catchy label', + * value: '1', + * }); + * ``` + * @example + * Creating a string select menu option using setters and API data: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * default: true, + * value: '1', + * }) + * .setLabel('woah'); + * ``` + */ + constructor(data?: Partial<APISelectMenuOption>); + /** + * Sets the label for this option. + * + * @param label - The label to use + */ + setLabel(label: string): this; + /** + * Sets the value for this option. + * + * @param value - The value to use + */ + setValue(value: string): this; + /** + * Sets the description for this option. + * + * @param description - The description to use + */ + setDescription(description: string): this; + /** + * Sets whether this option is selected by default. + * + * @param isDefault - Whether this option is selected by default + */ + setDefault(isDefault?: boolean): this; + /** + * Sets the emoji to display for this option. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji: APIMessageComponentEmoji): this; + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON(): APISelectMenuOption; +} + +declare const customIdValidator: _sapphire_shapeshift.StringValidator<string>; +declare const emojiValidator: _sapphire_shapeshift.ObjectValidator<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; +}>>; +declare const disabledValidator: _sapphire_shapeshift.BooleanValidator<boolean>; +declare const buttonLabelValidator: _sapphire_shapeshift.StringValidator<string>; +declare const buttonStyleValidator: _sapphire_shapeshift.NativeEnumValidator<typeof ButtonStyle>; +declare const placeholderValidator$1: _sapphire_shapeshift.StringValidator<string>; +declare const minMaxValidator: _sapphire_shapeshift.NumberValidator<number>; +declare const labelValueDescriptionValidator: _sapphire_shapeshift.StringValidator<string>; +declare const jsonOptionValidator: _sapphire_shapeshift.ObjectValidator<{ + label: string; + value: string; + description: string | undefined; + emoji: _sapphire_shapeshift.UndefinedToOptional<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; + }> | undefined; + default: boolean | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + label: string; + value: string; + description: string | undefined; + emoji: _sapphire_shapeshift.UndefinedToOptional<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; + }> | undefined; + default: boolean | undefined; +}>>; +declare const optionValidator: _sapphire_shapeshift.InstanceValidator<StringSelectMenuOptionBuilder>; +declare const optionsValidator: _sapphire_shapeshift.ArrayValidator<StringSelectMenuOptionBuilder[], StringSelectMenuOptionBuilder>; +declare const optionsLengthValidator: _sapphire_shapeshift.NumberValidator<number>; +declare function validateRequiredSelectMenuParameters(options: StringSelectMenuOptionBuilder[], customId?: string): void; +declare const defaultValidator: _sapphire_shapeshift.BooleanValidator<boolean>; +declare function validateRequiredSelectMenuOptionParameters(label?: string, value?: string): void; +declare const channelTypesValidator: _sapphire_shapeshift.ArrayValidator<ChannelType[], ChannelType>; +declare const urlValidator: _sapphire_shapeshift.StringValidator<string>; +declare function validateRequiredButtonParameters(style?: ButtonStyle, label?: string, emoji?: APIMessageComponentEmoji, customId?: string, url?: string): void; + +declare const Assertions$4_buttonLabelValidator: typeof buttonLabelValidator; +declare const Assertions$4_buttonStyleValidator: typeof buttonStyleValidator; +declare const Assertions$4_channelTypesValidator: typeof channelTypesValidator; +declare const Assertions$4_customIdValidator: typeof customIdValidator; +declare const Assertions$4_defaultValidator: typeof defaultValidator; +declare const Assertions$4_disabledValidator: typeof disabledValidator; +declare const Assertions$4_emojiValidator: typeof emojiValidator; +declare const Assertions$4_jsonOptionValidator: typeof jsonOptionValidator; +declare const Assertions$4_labelValueDescriptionValidator: typeof labelValueDescriptionValidator; +declare const Assertions$4_minMaxValidator: typeof minMaxValidator; +declare const Assertions$4_optionValidator: typeof optionValidator; +declare const Assertions$4_optionsLengthValidator: typeof optionsLengthValidator; +declare const Assertions$4_optionsValidator: typeof optionsValidator; +declare const Assertions$4_urlValidator: typeof urlValidator; +declare const Assertions$4_validateRequiredButtonParameters: typeof validateRequiredButtonParameters; +declare const Assertions$4_validateRequiredSelectMenuOptionParameters: typeof validateRequiredSelectMenuOptionParameters; +declare const Assertions$4_validateRequiredSelectMenuParameters: typeof validateRequiredSelectMenuParameters; +declare namespace Assertions$4 { + export { + Assertions$4_buttonLabelValidator as buttonLabelValidator, + Assertions$4_buttonStyleValidator as buttonStyleValidator, + Assertions$4_channelTypesValidator as channelTypesValidator, + Assertions$4_customIdValidator as customIdValidator, + Assertions$4_defaultValidator as defaultValidator, + Assertions$4_disabledValidator as disabledValidator, + Assertions$4_emojiValidator as emojiValidator, + Assertions$4_jsonOptionValidator as jsonOptionValidator, + Assertions$4_labelValueDescriptionValidator as labelValueDescriptionValidator, + Assertions$4_minMaxValidator as minMaxValidator, + Assertions$4_optionValidator as optionValidator, + Assertions$4_optionsLengthValidator as optionsLengthValidator, + Assertions$4_optionsValidator as optionsValidator, + placeholderValidator$1 as placeholderValidator, + Assertions$4_urlValidator as urlValidator, + Assertions$4_validateRequiredButtonParameters as validateRequiredButtonParameters, + Assertions$4_validateRequiredSelectMenuOptionParameters as validateRequiredSelectMenuOptionParameters, + Assertions$4_validateRequiredSelectMenuParameters as validateRequiredSelectMenuParameters, + }; +} + +/** + * Any action row component data represented as an object. + */ +type AnyAPIActionRowComponent = APIActionRowComponent<APIActionRowComponentTypes> | APIActionRowComponentTypes; +/** + * The base component builder that contains common symbols for all sorts of components. + * + * @typeParam DataType - The type of internal API data that is stored within the component + */ +declare abstract class ComponentBuilder<DataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>> implements JSONEncodable<AnyAPIActionRowComponent> { + /** + * The API data associated with this component. + */ + readonly data: Partial<DataType>; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + abstract toJSON(): AnyAPIActionRowComponent; + /** + * Constructs a new kind of component. + * + * @param data - The data to construct a component out of + */ + constructor(data: Partial<DataType>); +} + +/** + * A builder that creates API-compatible JSON data for buttons. + */ +declare class ButtonBuilder extends ComponentBuilder<APIButtonComponent> { + /** + * Creates a new button from API data. + * + * @param data - The API data to create this button with + * @example + * Creating a button from an API data object: + * ```ts + * const button = new ButtonBuilder({ + * custom_id: 'a cool button', + * style: ButtonStyle.Primary, + * label: 'Click Me', + * emoji: { + * name: 'smile', + * id: '123456789012345678', + * }, + * }); + * ``` + * @example + * Creating a button using setters and API data: + * ```ts + * const button = new ButtonBuilder({ + * style: ButtonStyle.Secondary, + * label: 'Click Me', + * }) + * .setEmoji({ name: '🙂' }) + * .setCustomId('another cool button'); + * ``` + */ + constructor(data?: Partial<APIButtonComponent>); + /** + * Sets the style of this button. + * + * @param style - The style to use + */ + setStyle(style: ButtonStyle): this; + /** + * Sets the URL for this button. + * + * @remarks + * This method is only available to buttons using the `Link` button style. + * Only three types of URL schemes are currently supported: `https://`, `http://`, and `discord://`. + * @param url - The URL to use + */ + setURL(url: string): this; + /** + * Sets the custom id for this button. + * + * @remarks + * This method is only applicable to buttons that are not using the `Link` button style. + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Sets the emoji to display on this button. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji: APIMessageComponentEmoji): this; + /** + * Sets whether this button is disabled. + * + * @param disabled - Whether to disable this button + */ + setDisabled(disabled?: boolean): this; + /** + * Sets the label for this button. + * + * @param label - The label to use + */ + setLabel(label: string): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APIButtonComponent; +} + +/** + * The base select menu builder that contains common symbols for select menu builders. + * + * @typeParam SelectMenuType - The type of select menu this would be instantiated for. + */ +declare abstract class BaseSelectMenuBuilder<SelectMenuType extends APISelectMenuComponent> extends ComponentBuilder<SelectMenuType> { + /** + * Sets the placeholder for this select menu. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder: string): this; + /** + * Sets the minimum values that must be selected in the select menu. + * + * @param minValues - The minimum values that must be selected + */ + setMinValues(minValues: number): this; + /** + * Sets the maximum values that must be selected in the select menu. + * + * @param maxValues - The maximum values that must be selected + */ + setMaxValues(maxValues: number): this; + /** + * Sets the custom id for this select menu. + * + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Sets whether this select menu is disabled. + * + * @param disabled - Whether this select menu is disabled + */ + setDisabled(disabled?: boolean): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): SelectMenuType; +} + +/** + * A builder that creates API-compatible JSON data for channel select menus. + */ +declare class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement) + * .setMinValues(2); + * ``` + */ + constructor(data?: Partial<APIChannelSelectComponent>); + /** + * Adds channel types to this select menu. + * + * @param types - The channel types to use + */ + addChannelTypes(...types: RestOrArray<ChannelType>): this; + /** + * Sets channel types for this select menu. + * + * @param types - The channel types to use + */ + setChannelTypes(...types: RestOrArray<ChannelType>): this; + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON(): APIChannelSelectComponent; +} + +/** + * A builder that creates API-compatible JSON data for mentionable select menus. + */ +declare class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder<APIMentionableSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data?: Partial<APIMentionableSelectComponent>); +} + +/** + * A builder that creates API-compatible JSON data for role select menus. + */ +declare class RoleSelectMenuBuilder extends BaseSelectMenuBuilder<APIRoleSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data?: Partial<APIRoleSelectComponent>); +} + +/** + * A builder that creates API-compatible JSON data for string select menus. + */ +declare class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSelectComponent> { + /** + * The options within this select menu. + */ + readonly options: StringSelectMenuOptionBuilder[]; + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * options: [ + * { label: 'option 1', value: '1' }, + * { label: 'option 2', value: '2' }, + * { label: 'option 3', value: '3' }, + * ], + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1) + * .addOptions({ + * label: 'Catchy', + * value: 'catch', + * }); + * ``` + */ + constructor(data?: Partial<APIStringSelectComponent>); + /** + * Adds options to this select menu. + * + * @param options - The options to add + */ + addOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this; + /** + * Sets the options for this select menu. + * + * @param options - The options to set + */ + setOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this; + /** + * Removes, replaces, or inserts options for this select menu. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}. + * It's useful for modifying and adjusting the order of existing options. + * @example + * Remove the first option: + * ```ts + * selectMenu.spliceOptions(0, 1); + * ``` + * @example + * Remove the first n option: + * ```ts + * const n = 4; + * selectMenu.spliceOptions(0, n); + * ``` + * @example + * Remove the last option: + * ```ts + * selectMenu.spliceOptions(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of options to remove + * @param options - The replacing option objects or builders + */ + spliceOptions(index: number, deleteCount: number, ...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this; + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON(): APIStringSelectComponent; +} + +/** + * A builder that creates API-compatible JSON data for user select menus. + */ +declare class UserSelectMenuBuilder extends BaseSelectMenuBuilder<APIUserSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data?: Partial<APIUserSelectComponent>); +} + +/** + * A builder that creates API-compatible JSON data for text inputs. + */ +declare class TextInputBuilder extends ComponentBuilder<APITextInputComponent> implements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>> { + /** + * Creates a new text input from API data. + * + * @param data - The API data to create this text input with + * @example + * Creating a select menu option from an API data object: + * ```ts + * const textInput = new TextInputBuilder({ + * custom_id: 'a cool select menu', + * label: 'Type something', + * style: TextInputStyle.Short, + * }); + * ``` + * @example + * Creating a select menu option using setters and API data: + * ```ts + * const textInput = new TextInputBuilder({ + * label: 'Type something else', + * }) + * .setCustomId('woah') + * .setStyle(TextInputStyle.Paragraph); + * ``` + */ + constructor(data?: APITextInputComponent & { + type?: ComponentType.TextInput; + }); + /** + * Sets the custom id for this text input. + * + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Sets the label for this text input. + * + * @param label - The label to use + */ + setLabel(label: string): this; + /** + * Sets the style for this text input. + * + * @param style - The style to use + */ + setStyle(style: TextInputStyle): this; + /** + * Sets the minimum length of text for this text input. + * + * @param minLength - The minimum length of text for this text input + */ + setMinLength(minLength: number): this; + /** + * Sets the maximum length of text for this text input. + * + * @param maxLength - The maximum length of text for this text input + */ + setMaxLength(maxLength: number): this; + /** + * Sets the placeholder for this text input. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder: string): this; + /** + * Sets the value for this text input. + * + * @param value - The value to use + */ + setValue(value: string): this; + /** + * Sets whether this text input is required. + * + * @param required - Whether this text input is required + */ + setRequired(required?: boolean): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APITextInputComponent; + /** + * {@inheritDoc Equatable.equals} + */ + equals(other: APITextInputComponent | JSONEncodable<APITextInputComponent>): boolean; +} + +/** + * The builders that may be used for messages. + */ +type MessageComponentBuilder = ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder; +/** + * The builders that may be used for modals. + */ +type ModalComponentBuilder = ActionRowBuilder<ModalActionRowComponentBuilder> | ModalActionRowComponentBuilder; +/** + * The builders that may be used within an action row for messages. + */ +type MessageActionRowComponentBuilder = ButtonBuilder | ChannelSelectMenuBuilder | MentionableSelectMenuBuilder | RoleSelectMenuBuilder | StringSelectMenuBuilder | UserSelectMenuBuilder; +/** + * The builders that may be used within an action row for modals. + */ +type ModalActionRowComponentBuilder = TextInputBuilder; +/** + * Any builder. + */ +type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalActionRowComponentBuilder; +/** + * A builder that creates API-compatible JSON data for action rows. + * + * @typeParam T - The types of components this action row holds + */ +declare class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>> { + /** + * The components within this action row. + */ + readonly components: T[]; + /** + * Creates a new action row from API data. + * + * @param data - The API data to create this action row with + * @example + * Creating an action row from an API data object: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Type something", + * style: TextInputStyle.Short, + * type: ComponentType.TextInput, + * }, + * ], + * }); + * ``` + * @example + * Creating an action row using setters and API data: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Click me", + * style: ButtonStyle.Primary, + * type: ComponentType.Button, + * }, + * ], + * }) + * .addComponents(button2, button3); + * ``` + */ + constructor({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>); + /** + * Adds components to this action row. + * + * @param components - The components to add + */ + addComponents(...components: RestOrArray<T>): this; + /** + * Sets components for this action row. + * + * @param components - The components to set + */ + setComponents(...components: RestOrArray<T>): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>>; +} + +/** + * Components here are mapped to their respective builder. + */ +interface MappedComponentTypes { + /** + * The action row component type is associated with an {@link ActionRowBuilder}. + */ + [ComponentType.ActionRow]: ActionRowBuilder<AnyComponentBuilder>; + /** + * The button component type is associated with an {@link ButtonBuilder}. + */ + [ComponentType.Button]: ButtonBuilder; + /** + * The string select component type is associated with an {@link StringSelectMenuBuilder}. + */ + [ComponentType.StringSelect]: StringSelectMenuBuilder; + /** + * The text inpiut component type is associated with an {@link TextInputBuilder}. + */ + [ComponentType.TextInput]: TextInputBuilder; + /** + * The user select component type is associated with an {@link UserSelectMenuBuilder}. + */ + [ComponentType.UserSelect]: UserSelectMenuBuilder; + /** + * The role select component type is associated with an {@link RoleSelectMenuBuilder}. + */ + [ComponentType.RoleSelect]: RoleSelectMenuBuilder; + /** + * The mentionable select component type is associated with an {@link MentionableSelectMenuBuilder}. + */ + [ComponentType.MentionableSelect]: MentionableSelectMenuBuilder; + /** + * The channel select component type is associated with an {@link ChannelSelectMenuBuilder}. + */ + [ComponentType.ChannelSelect]: ChannelSelectMenuBuilder; +} +/** + * Factory for creating components from API data. + * + * @typeParam T - The type of component to use + * @param data - The API data to transform to a component class + */ +declare function createComponentBuilder<T extends keyof MappedComponentTypes>(data: (APIModalComponent | APIMessageComponent) & { + type: T; +}): MappedComponentTypes[T]; +/** + * Factory for creating components from API data. + * + * @typeParam C - The type of component to use + * @param data - The API data to transform to a component class + */ +declare function createComponentBuilder<C extends MessageComponentBuilder | ModalComponentBuilder>(data: C): C; + +declare const textInputStyleValidator: _sapphire_shapeshift.NativeEnumValidator<typeof TextInputStyle>; +declare const minLengthValidator: _sapphire_shapeshift.NumberValidator<number>; +declare const maxLengthValidator: _sapphire_shapeshift.NumberValidator<number>; +declare const requiredValidator: _sapphire_shapeshift.BooleanValidator<boolean>; +declare const valueValidator: _sapphire_shapeshift.StringValidator<string>; +declare const placeholderValidator: _sapphire_shapeshift.StringValidator<string>; +declare const labelValidator: _sapphire_shapeshift.StringValidator<string>; +declare function validateRequiredParameters$3(customId?: string, style?: TextInputStyle, label?: string): void; + +declare const Assertions$3_labelValidator: typeof labelValidator; +declare const Assertions$3_maxLengthValidator: typeof maxLengthValidator; +declare const Assertions$3_minLengthValidator: typeof minLengthValidator; +declare const Assertions$3_placeholderValidator: typeof placeholderValidator; +declare const Assertions$3_requiredValidator: typeof requiredValidator; +declare const Assertions$3_textInputStyleValidator: typeof textInputStyleValidator; +declare const Assertions$3_valueValidator: typeof valueValidator; +declare namespace Assertions$3 { + export { + Assertions$3_labelValidator as labelValidator, + Assertions$3_maxLengthValidator as maxLengthValidator, + Assertions$3_minLengthValidator as minLengthValidator, + Assertions$3_placeholderValidator as placeholderValidator, + Assertions$3_requiredValidator as requiredValidator, + Assertions$3_textInputStyleValidator as textInputStyleValidator, + validateRequiredParameters$3 as validateRequiredParameters, + Assertions$3_valueValidator as valueValidator, + }; +} + +/** + * A builder that creates API-compatible JSON data for modals. + */ +declare class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> { + /** + * The API data associated with this modal. + */ + readonly data: Partial<APIModalInteractionResponseCallbackData>; + /** + * The components within this modal. + */ + readonly components: ActionRowBuilder<ModalActionRowComponentBuilder>[]; + /** + * Creates a new modal from API data. + * + * @param data - The API data to create this modal with + */ + constructor({ components, ...data }?: Partial<APIModalInteractionResponseCallbackData>); + /** + * Sets the title of this modal. + * + * @param title - The title to use + */ + setTitle(title: string): this; + /** + * Sets the custom id of this modal. + * + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Adds components to this modal. + * + * @param components - The components to add + */ + addComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder> | APIActionRowComponent<APIModalActionRowComponent>>): this; + /** + * Sets components for this modal. + * + * @param components - The components to set + */ + setComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder>>): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APIModalInteractionResponseCallbackData; +} + +declare const titleValidator: _sapphire_shapeshift.StringValidator<string>; +declare const componentsValidator: _sapphire_shapeshift.ArrayValidator<[ActionRowBuilder<AnyComponentBuilder>, ...ActionRowBuilder<AnyComponentBuilder>[]], ActionRowBuilder<AnyComponentBuilder>>; +declare function validateRequiredParameters$2(customId?: string, title?: string, components?: ActionRowBuilder<ModalActionRowComponentBuilder>[]): void; + +declare const Assertions$2_componentsValidator: typeof componentsValidator; +declare const Assertions$2_titleValidator: typeof titleValidator; +declare namespace Assertions$2 { + export { + Assertions$2_componentsValidator as componentsValidator, + Assertions$2_titleValidator as titleValidator, + validateRequiredParameters$2 as validateRequiredParameters, + }; +} + +/** + * This mixin holds name and description symbols for slash commands. + */ +declare class SharedNameAndDescription { + /** + * The name of this command. + */ + readonly name: string; + /** + * The name localizations of this command. + */ + readonly name_localizations?: LocalizationMap; + /** + * The description of this command. + */ + readonly description: string; + /** + * The description localizations of this command. + */ + readonly description_localizations?: LocalizationMap; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name: string): this; + /** + * Sets the description of this command. + * + * @param description - The description to use + */ + setDescription(description: string): this; + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale: LocaleString, localizedName: string | null): this; + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames: LocalizationMap | null): this; + /** + * Sets a description localization for this command. + * + * @param locale - The locale to set + * @param localizedDescription - The localized description for the given locale + */ + setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null): this; + /** + * Sets the description localizations for this command. + * + * @param localizedDescriptions - The object of localized descriptions to set + */ + setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null): this; +} + +/** + * The base application command option builder that contains common symbols for application command builders. + */ +declare abstract class ApplicationCommandOptionBase extends SharedNameAndDescription { + /** + * The type of this option. + */ + abstract readonly type: ApplicationCommandOptionType; + /** + * Whether this option is required. + * + * @defaultValue `false` + */ + readonly required: boolean; + /** + * Sets whether this option is required. + * + * @param required - Whether this option should be required + */ + setRequired(required: boolean): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + abstract toJSON(): APIApplicationCommandBasicOption; + /** + * This method runs required validators on this builder. + */ + protected runRequiredValidations(): void; +} + +/** + * A slash command attachment option. + */ +declare class SlashCommandAttachmentOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Attachment; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandAttachmentOption; +} + +/** + * A slash command boolean option. + */ +declare class SlashCommandBooleanOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Boolean; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandBooleanOption; +} + +/** + * The allowed channel types used for a channel option in a slash command builder. + * + * @privateRemarks This can't be dynamic because const enums are erased at runtime. + * @internal + */ +declare const allowedChannelTypes: readonly [ChannelType.GuildText, ChannelType.GuildVoice, ChannelType.GuildCategory, ChannelType.GuildAnnouncement, ChannelType.AnnouncementThread, ChannelType.PublicThread, ChannelType.PrivateThread, ChannelType.GuildStageVoice, ChannelType.GuildForum]; +/** + * The type of allowed channel types used for a channel option. + */ +type ApplicationCommandOptionAllowedChannelTypes = (typeof allowedChannelTypes)[number]; +/** + * This mixin holds channel type symbols used for options. + */ +declare class ApplicationCommandOptionChannelTypesMixin { + /** + * The channel types of this option. + */ + readonly channel_types?: ApplicationCommandOptionAllowedChannelTypes[]; + /** + * Adds channel types to this option. + * + * @param channelTypes - The channel types + */ + addChannelTypes(...channelTypes: ApplicationCommandOptionAllowedChannelTypes[]): this; +} + +/** + * A slash command channel option. + */ +declare class SlashCommandChannelOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Channel; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandChannelOption; +} +interface SlashCommandChannelOption extends ApplicationCommandOptionChannelTypesMixin { +} + +/** + * This mixin holds minimum and maximum symbols used for options. + */ +declare abstract class ApplicationCommandNumericOptionMinMaxValueMixin { + /** + * The maximum value of this option. + */ + readonly max_value?: number; + /** + * The minimum value of this option. + */ + readonly min_value?: number; + /** + * Sets the maximum number value of this option. + * + * @param max - The maximum value this option can be + */ + abstract setMaxValue(max: number): this; + /** + * Sets the minimum number value of this option. + * + * @param min - The minimum value this option can be + */ + abstract setMinValue(min: number): this; +} + +/** + * This mixin holds choices and autocomplete symbols used for options. + */ +declare class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends number | string> { + /** + * The choices of this option. + */ + readonly choices?: APIApplicationCommandOptionChoice<T>[]; + /** + * Whether this option utilizes autocomplete. + */ + readonly autocomplete?: boolean; + /** + * The type of this option. + * + * @privateRemarks Since this is present and this is a mixin, this is needed. + */ + readonly type: ApplicationCommandOptionType; + /** + * Adds multiple choices to this option. + * + * @param choices - The choices to add + */ + addChoices(...choices: APIApplicationCommandOptionChoice<T>[]): this; + /** + * Sets multiple choices for this option. + * + * @param choices - The choices to set + */ + setChoices<Input extends APIApplicationCommandOptionChoice<T>[]>(...choices: Input): this; + /** + * Whether this option uses autocomplete. + * + * @param autocomplete - Whether this option should use autocomplete + */ + setAutocomplete(autocomplete: boolean): this; +} + +/** + * A slash command integer option. + */ +declare class SlashCommandIntegerOption extends ApplicationCommandOptionBase implements ApplicationCommandNumericOptionMinMaxValueMixin { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Integer; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max: number): this; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min: number): this; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandIntegerOption; +} +interface SlashCommandIntegerOption extends ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> { +} + +/** + * A slash command mentionable option. + */ +declare class SlashCommandMentionableOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Mentionable; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandMentionableOption; +} + +/** + * A slash command number option. + */ +declare class SlashCommandNumberOption extends ApplicationCommandOptionBase implements ApplicationCommandNumericOptionMinMaxValueMixin { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Number; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max: number): this; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min: number): this; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandNumberOption; +} +interface SlashCommandNumberOption extends ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> { +} + +/** + * A slash command role option. + */ +declare class SlashCommandRoleOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Role; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandRoleOption; +} + +/** + * A slash command string option. + */ +declare class SlashCommandStringOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.String; + /** + * The maximum length of this option. + */ + readonly max_length?: number; + /** + * The minimum length of this option. + */ + readonly min_length?: number; + /** + * Sets the maximum length of this string option. + * + * @param max - The maximum length this option can be + */ + setMaxLength(max: number): this; + /** + * Sets the minimum length of this string option. + * + * @param min - The minimum length this option can be + */ + setMinLength(min: number): this; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandStringOption; +} +interface SlashCommandStringOption extends ApplicationCommandOptionWithChoicesAndAutocompleteMixin<string> { +} + +/** + * A slash command user option. + */ +declare class SlashCommandUserOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.User; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandUserOption; +} + +/** + * This mixin holds symbols that can be shared in slash command options. + * + * @typeParam ShouldOmitSubcommandFunctions - Whether to omit subcommand functions. + */ +declare class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> { + readonly options: ToAPIApplicationCommandOptions[]; + /** + * Adds a boolean option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addBooleanOption(input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a user option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a channel option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addChannelOption(input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a role option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds an attachment option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addAttachmentOption(input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a mentionable option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addMentionableOption(input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a string option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addStringOption(input: Omit<SlashCommandStringOption, 'addChoices'> | Omit<SlashCommandStringOption, 'setAutocomplete'> | SlashCommandStringOption | ((builder: SlashCommandStringOption) => Omit<SlashCommandStringOption, 'addChoices'> | Omit<SlashCommandStringOption, 'setAutocomplete'> | SlashCommandStringOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds an integer option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addIntegerOption(input: Omit<SlashCommandIntegerOption, 'addChoices'> | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | SlashCommandIntegerOption | ((builder: SlashCommandIntegerOption) => Omit<SlashCommandIntegerOption, 'addChoices'> | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | SlashCommandIntegerOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a number option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addNumberOption(input: Omit<SlashCommandNumberOption, 'addChoices'> | Omit<SlashCommandNumberOption, 'setAutocomplete'> | SlashCommandNumberOption | ((builder: SlashCommandNumberOption) => Omit<SlashCommandNumberOption, 'addChoices'> | Omit<SlashCommandNumberOption, 'setAutocomplete'> | SlashCommandNumberOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Where the actual adding magic happens. ✨ + * + * @param input - The input. What else? + * @param Instance - The instance of whatever is being added + * @internal + */ + private _sharedAddOptionMethod; +} + +/** + * Represents a folder for subcommands. + * + * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups} + */ +declare class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationCommandOptions { + /** + * The name of this subcommand group. + */ + readonly name: string; + /** + * The description of this subcommand group. + */ + readonly description: string; + /** + * The subcommands within this subcommand group. + */ + readonly options: SlashCommandSubcommandBuilder[]; + /** + * Adds a new subcommand to this group. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): APIApplicationCommandSubcommandGroupOption; +} +interface SlashCommandSubcommandGroupBuilder extends SharedNameAndDescription { +} +/** + * A builder that creates API-compatible JSON data for slash command subcommands. + * + * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups} + */ +declare class SlashCommandSubcommandBuilder implements ToAPIApplicationCommandOptions { + /** + * The name of this subcommand. + */ + readonly name: string; + /** + * The description of this subcommand. + */ + readonly description: string; + /** + * The options within this subcommand. + */ + readonly options: ApplicationCommandOptionBase[]; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): APIApplicationCommandSubcommandOption; +} +interface SlashCommandSubcommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions<false> { +} + +/** + * A builder that creates API-compatible JSON data for slash commands. + */ +declare class SlashCommandBuilder { + /** + * The name of this command. + */ + readonly name: string; + /** + * The name localizations of this command. + */ + readonly name_localizations?: LocalizationMap; + /** + * The description of this command. + */ + readonly description: string; + /** + * The description localizations of this command. + */ + readonly description_localizations?: LocalizationMap; + /** + * The options of this command. + */ + readonly options: ToAPIApplicationCommandOptions[]; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + readonly default_permission: boolean | undefined; + /** + * The set of permissions represented as a bit set for the command. + */ + readonly default_member_permissions: Permissions | null | undefined; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + readonly dm_permission: boolean | undefined; + /** + * Whether this command is NSFW. + */ + readonly nsfw: boolean | undefined; + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether or not to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value: boolean): this; + /** + * Sets the default permissions a member should have in order to run the command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined): this; + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled: boolean | null | undefined): this; + /** + * Sets whether this command is NSFW. + * + * @param nsfw - Whether this command is NSFW + */ + setNSFW(nsfw?: boolean): this; + /** + * Adds a new subcommand group to this command. + * + * @param input - A function that returns a subcommand group builder or an already built builder + */ + addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder; + /** + * Adds a new subcommand to this command. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody; +} +interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions { +} +/** + * An interface specifically for slash command subcommands. + */ +interface SlashCommandSubcommandsOnlyBuilder extends Omit<SlashCommandBuilder, Exclude<keyof SharedSlashCommandOptions, 'options'>> { +} +/** + * An interface specifically for slash command options. + */ +interface SlashCommandOptionsOnlyBuilder extends SharedNameAndDescription, SharedSlashCommandOptions, Pick<SlashCommandBuilder, 'toJSON'> { +} +/** + * An interface that ensures the `toJSON()` call will return something + * that can be serialized into API-compatible data. + */ +interface ToAPIApplicationCommandOptions { + toJSON(): APIApplicationCommandOption; +} + +declare function validateName$1(name: unknown): asserts name is string; +declare function validateDescription(description: unknown): asserts description is string; +declare function validateLocale(locale: unknown): Locale; +declare function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[]; +declare function validateRequiredParameters$1(name: string, description: string, options: ToAPIApplicationCommandOptions[]): void; +declare function validateDefaultPermission$1(value: unknown): asserts value is boolean; +declare function validateRequired(required: unknown): asserts required is boolean; +declare function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void; +declare function assertReturnOfBuilder<T extends ApplicationCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder>(input: unknown, ExpectedInstanceOf: new () => T): asserts input is T; +declare const localizationMapPredicate: _sapphire_shapeshift.UnionValidator<_sapphire_shapeshift.UndefinedToOptional<Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "sv-SE" | "th" | "tr" | "uk" | "vi", string | null>>> | null | undefined>; +declare function validateLocalizationMap(value: unknown): asserts value is LocalizationMap; +declare function validateDMPermission$1(value: unknown): asserts value is boolean | null | undefined; +declare function validateDefaultMemberPermissions$1(permissions: unknown): string | null | undefined; +declare function validateNSFW(value: unknown): asserts value is boolean; + +declare const Assertions$1_assertReturnOfBuilder: typeof assertReturnOfBuilder; +declare const Assertions$1_localizationMapPredicate: typeof localizationMapPredicate; +declare const Assertions$1_validateChoicesLength: typeof validateChoicesLength; +declare const Assertions$1_validateDescription: typeof validateDescription; +declare const Assertions$1_validateLocale: typeof validateLocale; +declare const Assertions$1_validateLocalizationMap: typeof validateLocalizationMap; +declare const Assertions$1_validateMaxOptionsLength: typeof validateMaxOptionsLength; +declare const Assertions$1_validateNSFW: typeof validateNSFW; +declare const Assertions$1_validateRequired: typeof validateRequired; +declare namespace Assertions$1 { + export { + Assertions$1_assertReturnOfBuilder as assertReturnOfBuilder, + Assertions$1_localizationMapPredicate as localizationMapPredicate, + Assertions$1_validateChoicesLength as validateChoicesLength, + validateDMPermission$1 as validateDMPermission, + validateDefaultMemberPermissions$1 as validateDefaultMemberPermissions, + validateDefaultPermission$1 as validateDefaultPermission, + Assertions$1_validateDescription as validateDescription, + Assertions$1_validateLocale as validateLocale, + Assertions$1_validateLocalizationMap as validateLocalizationMap, + Assertions$1_validateMaxOptionsLength as validateMaxOptionsLength, + Assertions$1_validateNSFW as validateNSFW, + validateName$1 as validateName, + Assertions$1_validateRequired as validateRequired, + validateRequiredParameters$1 as validateRequiredParameters, + }; +} + +/** + * The type a context menu command can be. + */ +type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User; +/** + * A builder that creates API-compatible JSON data for context menu commands. + */ +declare class ContextMenuCommandBuilder { + /** + * The name of this command. + */ + readonly name: string; + /** + * The name localizations of this command. + */ + readonly name_localizations?: LocalizationMap; + /** + * The type of this command. + */ + readonly type: ContextMenuCommandType; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + readonly default_permission: boolean | undefined; + /** + * The set of permissions represented as a bit set for the command. + */ + readonly default_member_permissions: Permissions | null | undefined; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + readonly dm_permission: boolean | undefined; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name: string): this; + /** + * Sets the type of this command. + * + * @param type - The type to use + */ + setType(type: ContextMenuCommandType): this; + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value: boolean): this; + /** + * Sets the default permissions a member should have in order to run this command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined): this; + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled: boolean | null | undefined): this; + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale: LocaleString, localizedName: string | null): this; + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames: LocalizationMap | null): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): RESTPostAPIContextMenuApplicationCommandsJSONBody; +} + +declare function validateDefaultPermission(value: unknown): asserts value is boolean; +declare function validateName(name: unknown): asserts name is string; +declare function validateType(type: unknown): asserts type is ContextMenuCommandType; +declare function validateRequiredParameters(name: string, type: number): void; +declare function validateDMPermission(value: unknown): asserts value is boolean | null | undefined; +declare function validateDefaultMemberPermissions(permissions: unknown): string | null | undefined; + +declare const Assertions_validateDMPermission: typeof validateDMPermission; +declare const Assertions_validateDefaultMemberPermissions: typeof validateDefaultMemberPermissions; +declare const Assertions_validateDefaultPermission: typeof validateDefaultPermission; +declare const Assertions_validateName: typeof validateName; +declare const Assertions_validateRequiredParameters: typeof validateRequiredParameters; +declare const Assertions_validateType: typeof validateType; +declare namespace Assertions { + export { + Assertions_validateDMPermission as validateDMPermission, + Assertions_validateDefaultMemberPermissions as validateDefaultMemberPermissions, + Assertions_validateDefaultPermission as validateDefaultPermission, + Assertions_validateName as validateName, + Assertions_validateRequiredParameters as validateRequiredParameters, + Assertions_validateType as validateType, + }; +} + +/** + * Calculates the length of the embed. + * + * @param data - The embed data to check + */ +declare function embedLength(data: APIEmbed): number; + +/** + * Enables validators. + * + * @returns Whether validation is occurring. + */ +declare function enableValidators(): boolean; +/** + * Disables validators. + * + * @returns Whether validation is occurring. + */ +declare function disableValidators(): boolean; +/** + * Checks whether validation is occurring. + */ +declare function isValidationEnabled(): boolean; + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/builders#readme | @discordjs/builders} version + * that you are currently using. + * + * @privateRemarks This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild. + */ +declare const version: string; + +export { ActionRowBuilder, AnyAPIActionRowComponent, AnyComponentBuilder, ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionAllowedChannelTypes, ApplicationCommandOptionBase, ApplicationCommandOptionChannelTypesMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin, BaseSelectMenuBuilder, ButtonBuilder, ChannelSelectMenuBuilder, Assertions$4 as ComponentAssertions, ComponentBuilder, Assertions as ContextMenuCommandAssertions, ContextMenuCommandBuilder, ContextMenuCommandType, Assertions$5 as EmbedAssertions, EmbedAuthorData, EmbedAuthorOptions, EmbedBuilder, EmbedFooterData, EmbedFooterOptions, EmbedImageData, IconData, MappedComponentTypes, MentionableSelectMenuBuilder, MessageActionRowComponentBuilder, MessageComponentBuilder, ModalActionRowComponentBuilder, Assertions$2 as ModalAssertions, ModalBuilder, ModalComponentBuilder, RGBTuple, RestOrArray, RoleSelectMenuBuilder, StringSelectMenuBuilder as SelectMenuBuilder, StringSelectMenuOptionBuilder as SelectMenuOptionBuilder, SharedNameAndDescription, SharedSlashCommandOptions, Assertions$1 as SlashCommandAssertions, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandBuilder, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandOptionsOnlyBuilder, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandUserOption, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Assertions$3 as TextInputAssertions, TextInputBuilder, ToAPIApplicationCommandOptions, UserSelectMenuBuilder, createComponentBuilder, disableValidators, embedLength, enableValidators, isValidationEnabled, normalizeArray, version }; diff --git a/node_modules/@discordjs/builders/dist/index.d.ts b/node_modules/@discordjs/builders/dist/index.d.ts new file mode 100644 index 0000000..ffa1792 --- /dev/null +++ b/node_modules/@discordjs/builders/dist/index.d.ts @@ -0,0 +1,1948 @@ +import * as _sapphire_shapeshift from '@sapphire/shapeshift'; +import { APIEmbedField, APIEmbedAuthor, APIEmbedFooter, APIEmbedImage, APIEmbed, APISelectMenuOption, APIMessageComponentEmoji, ButtonStyle, ChannelType, APIActionRowComponent, APIActionRowComponentTypes, APIBaseComponent, ComponentType, APIButtonComponent, APISelectMenuComponent, APIChannelSelectComponent, APIMentionableSelectComponent, APIRoleSelectComponent, APIStringSelectComponent, APIUserSelectComponent, APITextInputComponent, TextInputStyle, APIMessageActionRowComponent, APIModalActionRowComponent, APIModalComponent, APIMessageComponent, APIModalInteractionResponseCallbackData, LocalizationMap, LocaleString, ApplicationCommandOptionType, APIApplicationCommandBasicOption, APIApplicationCommandAttachmentOption, APIApplicationCommandBooleanOption, APIApplicationCommandChannelOption, APIApplicationCommandOptionChoice, APIApplicationCommandIntegerOption, APIApplicationCommandMentionableOption, APIApplicationCommandNumberOption, APIApplicationCommandRoleOption, APIApplicationCommandStringOption, APIApplicationCommandUserOption, APIApplicationCommandSubcommandGroupOption, APIApplicationCommandSubcommandOption, Permissions, RESTPostAPIChatInputApplicationCommandsJSONBody, APIApplicationCommandOption, Locale, ApplicationCommandType, RESTPostAPIContextMenuApplicationCommandsJSONBody } from 'discord-api-types/v10'; +export * from '@discordjs/formatters'; +import { JSONEncodable, Equatable } from '@discordjs/util'; + +declare const fieldNamePredicate: _sapphire_shapeshift.StringValidator<string>; +declare const fieldValuePredicate: _sapphire_shapeshift.StringValidator<string>; +declare const fieldInlinePredicate: _sapphire_shapeshift.UnionValidator<boolean | undefined>; +declare const embedFieldPredicate: _sapphire_shapeshift.ObjectValidator<{ + name: string; + value: string; + inline: boolean | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + name: string; + value: string; + inline: boolean | undefined; +}>>; +declare const embedFieldsArrayPredicate: _sapphire_shapeshift.ArrayValidator<_sapphire_shapeshift.UndefinedToOptional<{ + name: string; + value: string; + inline: boolean | undefined; +}>[], _sapphire_shapeshift.UndefinedToOptional<{ + name: string; + value: string; + inline: boolean | undefined; +}>>; +declare const fieldLengthPredicate: _sapphire_shapeshift.NumberValidator<number>; +declare function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void; +declare const authorNamePredicate: _sapphire_shapeshift.UnionValidator<string | null>; +declare const imageURLPredicate: _sapphire_shapeshift.UnionValidator<string | null | undefined>; +declare const urlPredicate: _sapphire_shapeshift.UnionValidator<string | null | undefined>; +declare const embedAuthorPredicate: _sapphire_shapeshift.ObjectValidator<{ + name: string | null; + iconURL: string | null | undefined; + url: string | null | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + name: string | null; + iconURL: string | null | undefined; + url: string | null | undefined; +}>>; +declare const RGBPredicate: _sapphire_shapeshift.NumberValidator<number>; +declare const colorPredicate: _sapphire_shapeshift.UnionValidator<number | [number, number, number] | null>; +declare const descriptionPredicate: _sapphire_shapeshift.UnionValidator<string | null>; +declare const footerTextPredicate: _sapphire_shapeshift.UnionValidator<string | null>; +declare const embedFooterPredicate: _sapphire_shapeshift.ObjectValidator<{ + text: string | null; + iconURL: string | null | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + text: string | null; + iconURL: string | null | undefined; +}>>; +declare const timestampPredicate: _sapphire_shapeshift.UnionValidator<number | Date | null>; +declare const titlePredicate: _sapphire_shapeshift.UnionValidator<string | null>; + +declare const Assertions$5_RGBPredicate: typeof RGBPredicate; +declare const Assertions$5_authorNamePredicate: typeof authorNamePredicate; +declare const Assertions$5_colorPredicate: typeof colorPredicate; +declare const Assertions$5_descriptionPredicate: typeof descriptionPredicate; +declare const Assertions$5_embedAuthorPredicate: typeof embedAuthorPredicate; +declare const Assertions$5_embedFieldPredicate: typeof embedFieldPredicate; +declare const Assertions$5_embedFieldsArrayPredicate: typeof embedFieldsArrayPredicate; +declare const Assertions$5_embedFooterPredicate: typeof embedFooterPredicate; +declare const Assertions$5_fieldInlinePredicate: typeof fieldInlinePredicate; +declare const Assertions$5_fieldLengthPredicate: typeof fieldLengthPredicate; +declare const Assertions$5_fieldNamePredicate: typeof fieldNamePredicate; +declare const Assertions$5_fieldValuePredicate: typeof fieldValuePredicate; +declare const Assertions$5_footerTextPredicate: typeof footerTextPredicate; +declare const Assertions$5_imageURLPredicate: typeof imageURLPredicate; +declare const Assertions$5_timestampPredicate: typeof timestampPredicate; +declare const Assertions$5_titlePredicate: typeof titlePredicate; +declare const Assertions$5_urlPredicate: typeof urlPredicate; +declare const Assertions$5_validateFieldLength: typeof validateFieldLength; +declare namespace Assertions$5 { + export { + Assertions$5_RGBPredicate as RGBPredicate, + Assertions$5_authorNamePredicate as authorNamePredicate, + Assertions$5_colorPredicate as colorPredicate, + Assertions$5_descriptionPredicate as descriptionPredicate, + Assertions$5_embedAuthorPredicate as embedAuthorPredicate, + Assertions$5_embedFieldPredicate as embedFieldPredicate, + Assertions$5_embedFieldsArrayPredicate as embedFieldsArrayPredicate, + Assertions$5_embedFooterPredicate as embedFooterPredicate, + Assertions$5_fieldInlinePredicate as fieldInlinePredicate, + Assertions$5_fieldLengthPredicate as fieldLengthPredicate, + Assertions$5_fieldNamePredicate as fieldNamePredicate, + Assertions$5_fieldValuePredicate as fieldValuePredicate, + Assertions$5_footerTextPredicate as footerTextPredicate, + Assertions$5_imageURLPredicate as imageURLPredicate, + Assertions$5_timestampPredicate as timestampPredicate, + Assertions$5_titlePredicate as titlePredicate, + Assertions$5_urlPredicate as urlPredicate, + Assertions$5_validateFieldLength as validateFieldLength, + }; +} + +/** + * Normalizes data that is a rest parameter or an array into an array with a depth of 1. + * + * @typeParam T - The data that must satisfy {@link RestOrArray}. + * @param arr - The (possibly variadic) data to normalize + */ +declare function normalizeArray<T>(arr: RestOrArray<T>): T[]; +/** + * Represents data that may be an array or came from a rest parameter. + * + * @remarks + * This type is used throughout builders to ensure both an array and variadic arguments + * may be used. It is normalized with {@link normalizeArray}. + */ +type RestOrArray<T> = T[] | [T[]]; + +/** + * A tuple satisfying the RGB color model. + * + * @see {@link https://developer.mozilla.org/docs/Glossary/RGB} + */ +type RGBTuple = [red: number, green: number, blue: number]; +/** + * The base icon data typically used in payloads. + */ +interface IconData { + /** + * The URL of the icon. + */ + iconURL?: string; + /** + * The proxy URL of the icon. + */ + proxyIconURL?: string; +} +/** + * Represents the author data of an embed. + */ +type EmbedAuthorData = IconData & Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'>; +/** + * Represents the author options of an embed. + */ +type EmbedAuthorOptions = Omit<EmbedAuthorData, 'proxyIconURL'>; +/** + * Represents the footer data of an embed. + */ +type EmbedFooterData = IconData & Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'>; +/** + * Represents the footer options of an embed. + */ +type EmbedFooterOptions = Omit<EmbedFooterData, 'proxyIconURL'>; +/** + * Represents the image data of an embed. + */ +interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> { + /** + * The proxy URL for the image. + */ + proxyURL?: string; +} +/** + * A builder that creates API-compatible JSON data for embeds. + */ +declare class EmbedBuilder { + /** + * The API data associated with this embed. + */ + readonly data: APIEmbed; + /** + * Creates a new embed from API data. + * + * @param data - The API data to create this embed with + */ + constructor(data?: APIEmbed); + /** + * Appends fields to the embed. + * + * @remarks + * This method accepts either an array of fields or a variable number of field parameters. + * The maximum amount of fields that can be added is 25. + * @example + * Using an array: + * ```ts + * const fields: APIEmbedField[] = ...; + * const embed = new EmbedBuilder() + * .addFields(fields); + * ``` + * @example + * Using rest parameters (variadic): + * ```ts + * const embed = new EmbedBuilder() + * .addFields( + * { name: 'Field 1', value: 'Value 1' }, + * { name: 'Field 2', value: 'Value 2' }, + * ); + * ``` + * @param fields - The fields to add + */ + addFields(...fields: RestOrArray<APIEmbedField>): this; + /** + * Removes, replaces, or inserts fields for this embed. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}. + * The maximum amount of fields that can be added is 25. + * + * It's useful for modifying and adjusting order of the already-existing fields of an embed. + * @example + * Remove the first field: + * ```ts + * embed.spliceFields(0, 1); + * ``` + * @example + * Remove the first n fields: + * ```ts + * const n = 4; + * embed.spliceFields(0, n); + * ``` + * @example + * Remove the last field: + * ```ts + * embed.spliceFields(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of fields to remove + * @param fields - The replacing field objects + */ + spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this; + /** + * Sets the fields for this embed. + * + * @remarks + * This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically, + * it splices the entire array of fields, replacing them with the provided fields. + * + * You can set a maximum of 25 fields. + * @param fields - The fields to set + */ + setFields(...fields: RestOrArray<APIEmbedField>): this; + /** + * Sets the author of this embed. + * + * @param options - The options to use + */ + setAuthor(options: EmbedAuthorOptions | null): this; + /** + * Sets the color of this embed. + * + * @param color - The color to use + */ + setColor(color: RGBTuple | number | null): this; + /** + * Sets the description of this embed. + * + * @param description - The description to use + */ + setDescription(description: string | null): this; + /** + * Sets the footer of this embed. + * + * @param options - The footer to use + */ + setFooter(options: EmbedFooterOptions | null): this; + /** + * Sets the image of this embed. + * + * @param url - The image URL to use + */ + setImage(url: string | null): this; + /** + * Sets the thumbnail of this embed. + * + * @param url - The thumbnail URL to use + */ + setThumbnail(url: string | null): this; + /** + * Sets the timestamp of this embed. + * + * @param timestamp - The timestamp or date to use + */ + setTimestamp(timestamp?: Date | number | null): this; + /** + * Sets the title for this embed. + * + * @param title - The title to use + */ + setTitle(title: string | null): this; + /** + * Sets the URL of this embed. + * + * @param url - The URL to use + */ + setURL(url: string | null): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): APIEmbed; +} + +/** + * A builder that creates API-compatible JSON data for string select menu options. + */ +declare class StringSelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> { + data: Partial<APISelectMenuOption>; + /** + * Creates a new string select menu option from API data. + * + * @param data - The API data to create this string select menu option with + * @example + * Creating a string select menu option from an API data object: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * label: 'catchy label', + * value: '1', + * }); + * ``` + * @example + * Creating a string select menu option using setters and API data: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * default: true, + * value: '1', + * }) + * .setLabel('woah'); + * ``` + */ + constructor(data?: Partial<APISelectMenuOption>); + /** + * Sets the label for this option. + * + * @param label - The label to use + */ + setLabel(label: string): this; + /** + * Sets the value for this option. + * + * @param value - The value to use + */ + setValue(value: string): this; + /** + * Sets the description for this option. + * + * @param description - The description to use + */ + setDescription(description: string): this; + /** + * Sets whether this option is selected by default. + * + * @param isDefault - Whether this option is selected by default + */ + setDefault(isDefault?: boolean): this; + /** + * Sets the emoji to display for this option. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji: APIMessageComponentEmoji): this; + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON(): APISelectMenuOption; +} + +declare const customIdValidator: _sapphire_shapeshift.StringValidator<string>; +declare const emojiValidator: _sapphire_shapeshift.ObjectValidator<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; +}>>; +declare const disabledValidator: _sapphire_shapeshift.BooleanValidator<boolean>; +declare const buttonLabelValidator: _sapphire_shapeshift.StringValidator<string>; +declare const buttonStyleValidator: _sapphire_shapeshift.NativeEnumValidator<typeof ButtonStyle>; +declare const placeholderValidator$1: _sapphire_shapeshift.StringValidator<string>; +declare const minMaxValidator: _sapphire_shapeshift.NumberValidator<number>; +declare const labelValueDescriptionValidator: _sapphire_shapeshift.StringValidator<string>; +declare const jsonOptionValidator: _sapphire_shapeshift.ObjectValidator<{ + label: string; + value: string; + description: string | undefined; + emoji: _sapphire_shapeshift.UndefinedToOptional<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; + }> | undefined; + default: boolean | undefined; +}, _sapphire_shapeshift.UndefinedToOptional<{ + label: string; + value: string; + description: string | undefined; + emoji: _sapphire_shapeshift.UndefinedToOptional<{ + name?: string | undefined; + id?: string | undefined; + animated?: boolean | undefined; + }> | undefined; + default: boolean | undefined; +}>>; +declare const optionValidator: _sapphire_shapeshift.InstanceValidator<StringSelectMenuOptionBuilder>; +declare const optionsValidator: _sapphire_shapeshift.ArrayValidator<StringSelectMenuOptionBuilder[], StringSelectMenuOptionBuilder>; +declare const optionsLengthValidator: _sapphire_shapeshift.NumberValidator<number>; +declare function validateRequiredSelectMenuParameters(options: StringSelectMenuOptionBuilder[], customId?: string): void; +declare const defaultValidator: _sapphire_shapeshift.BooleanValidator<boolean>; +declare function validateRequiredSelectMenuOptionParameters(label?: string, value?: string): void; +declare const channelTypesValidator: _sapphire_shapeshift.ArrayValidator<ChannelType[], ChannelType>; +declare const urlValidator: _sapphire_shapeshift.StringValidator<string>; +declare function validateRequiredButtonParameters(style?: ButtonStyle, label?: string, emoji?: APIMessageComponentEmoji, customId?: string, url?: string): void; + +declare const Assertions$4_buttonLabelValidator: typeof buttonLabelValidator; +declare const Assertions$4_buttonStyleValidator: typeof buttonStyleValidator; +declare const Assertions$4_channelTypesValidator: typeof channelTypesValidator; +declare const Assertions$4_customIdValidator: typeof customIdValidator; +declare const Assertions$4_defaultValidator: typeof defaultValidator; +declare const Assertions$4_disabledValidator: typeof disabledValidator; +declare const Assertions$4_emojiValidator: typeof emojiValidator; +declare const Assertions$4_jsonOptionValidator: typeof jsonOptionValidator; +declare const Assertions$4_labelValueDescriptionValidator: typeof labelValueDescriptionValidator; +declare const Assertions$4_minMaxValidator: typeof minMaxValidator; +declare const Assertions$4_optionValidator: typeof optionValidator; +declare const Assertions$4_optionsLengthValidator: typeof optionsLengthValidator; +declare const Assertions$4_optionsValidator: typeof optionsValidator; +declare const Assertions$4_urlValidator: typeof urlValidator; +declare const Assertions$4_validateRequiredButtonParameters: typeof validateRequiredButtonParameters; +declare const Assertions$4_validateRequiredSelectMenuOptionParameters: typeof validateRequiredSelectMenuOptionParameters; +declare const Assertions$4_validateRequiredSelectMenuParameters: typeof validateRequiredSelectMenuParameters; +declare namespace Assertions$4 { + export { + Assertions$4_buttonLabelValidator as buttonLabelValidator, + Assertions$4_buttonStyleValidator as buttonStyleValidator, + Assertions$4_channelTypesValidator as channelTypesValidator, + Assertions$4_customIdValidator as customIdValidator, + Assertions$4_defaultValidator as defaultValidator, + Assertions$4_disabledValidator as disabledValidator, + Assertions$4_emojiValidator as emojiValidator, + Assertions$4_jsonOptionValidator as jsonOptionValidator, + Assertions$4_labelValueDescriptionValidator as labelValueDescriptionValidator, + Assertions$4_minMaxValidator as minMaxValidator, + Assertions$4_optionValidator as optionValidator, + Assertions$4_optionsLengthValidator as optionsLengthValidator, + Assertions$4_optionsValidator as optionsValidator, + placeholderValidator$1 as placeholderValidator, + Assertions$4_urlValidator as urlValidator, + Assertions$4_validateRequiredButtonParameters as validateRequiredButtonParameters, + Assertions$4_validateRequiredSelectMenuOptionParameters as validateRequiredSelectMenuOptionParameters, + Assertions$4_validateRequiredSelectMenuParameters as validateRequiredSelectMenuParameters, + }; +} + +/** + * Any action row component data represented as an object. + */ +type AnyAPIActionRowComponent = APIActionRowComponent<APIActionRowComponentTypes> | APIActionRowComponentTypes; +/** + * The base component builder that contains common symbols for all sorts of components. + * + * @typeParam DataType - The type of internal API data that is stored within the component + */ +declare abstract class ComponentBuilder<DataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>> implements JSONEncodable<AnyAPIActionRowComponent> { + /** + * The API data associated with this component. + */ + readonly data: Partial<DataType>; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + abstract toJSON(): AnyAPIActionRowComponent; + /** + * Constructs a new kind of component. + * + * @param data - The data to construct a component out of + */ + constructor(data: Partial<DataType>); +} + +/** + * A builder that creates API-compatible JSON data for buttons. + */ +declare class ButtonBuilder extends ComponentBuilder<APIButtonComponent> { + /** + * Creates a new button from API data. + * + * @param data - The API data to create this button with + * @example + * Creating a button from an API data object: + * ```ts + * const button = new ButtonBuilder({ + * custom_id: 'a cool button', + * style: ButtonStyle.Primary, + * label: 'Click Me', + * emoji: { + * name: 'smile', + * id: '123456789012345678', + * }, + * }); + * ``` + * @example + * Creating a button using setters and API data: + * ```ts + * const button = new ButtonBuilder({ + * style: ButtonStyle.Secondary, + * label: 'Click Me', + * }) + * .setEmoji({ name: '🙂' }) + * .setCustomId('another cool button'); + * ``` + */ + constructor(data?: Partial<APIButtonComponent>); + /** + * Sets the style of this button. + * + * @param style - The style to use + */ + setStyle(style: ButtonStyle): this; + /** + * Sets the URL for this button. + * + * @remarks + * This method is only available to buttons using the `Link` button style. + * Only three types of URL schemes are currently supported: `https://`, `http://`, and `discord://`. + * @param url - The URL to use + */ + setURL(url: string): this; + /** + * Sets the custom id for this button. + * + * @remarks + * This method is only applicable to buttons that are not using the `Link` button style. + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Sets the emoji to display on this button. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji: APIMessageComponentEmoji): this; + /** + * Sets whether this button is disabled. + * + * @param disabled - Whether to disable this button + */ + setDisabled(disabled?: boolean): this; + /** + * Sets the label for this button. + * + * @param label - The label to use + */ + setLabel(label: string): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APIButtonComponent; +} + +/** + * The base select menu builder that contains common symbols for select menu builders. + * + * @typeParam SelectMenuType - The type of select menu this would be instantiated for. + */ +declare abstract class BaseSelectMenuBuilder<SelectMenuType extends APISelectMenuComponent> extends ComponentBuilder<SelectMenuType> { + /** + * Sets the placeholder for this select menu. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder: string): this; + /** + * Sets the minimum values that must be selected in the select menu. + * + * @param minValues - The minimum values that must be selected + */ + setMinValues(minValues: number): this; + /** + * Sets the maximum values that must be selected in the select menu. + * + * @param maxValues - The maximum values that must be selected + */ + setMaxValues(maxValues: number): this; + /** + * Sets the custom id for this select menu. + * + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Sets whether this select menu is disabled. + * + * @param disabled - Whether this select menu is disabled + */ + setDisabled(disabled?: boolean): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): SelectMenuType; +} + +/** + * A builder that creates API-compatible JSON data for channel select menus. + */ +declare class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement) + * .setMinValues(2); + * ``` + */ + constructor(data?: Partial<APIChannelSelectComponent>); + /** + * Adds channel types to this select menu. + * + * @param types - The channel types to use + */ + addChannelTypes(...types: RestOrArray<ChannelType>): this; + /** + * Sets channel types for this select menu. + * + * @param types - The channel types to use + */ + setChannelTypes(...types: RestOrArray<ChannelType>): this; + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON(): APIChannelSelectComponent; +} + +/** + * A builder that creates API-compatible JSON data for mentionable select menus. + */ +declare class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder<APIMentionableSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data?: Partial<APIMentionableSelectComponent>); +} + +/** + * A builder that creates API-compatible JSON data for role select menus. + */ +declare class RoleSelectMenuBuilder extends BaseSelectMenuBuilder<APIRoleSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data?: Partial<APIRoleSelectComponent>); +} + +/** + * A builder that creates API-compatible JSON data for string select menus. + */ +declare class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSelectComponent> { + /** + * The options within this select menu. + */ + readonly options: StringSelectMenuOptionBuilder[]; + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * options: [ + * { label: 'option 1', value: '1' }, + * { label: 'option 2', value: '2' }, + * { label: 'option 3', value: '3' }, + * ], + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1) + * .addOptions({ + * label: 'Catchy', + * value: 'catch', + * }); + * ``` + */ + constructor(data?: Partial<APIStringSelectComponent>); + /** + * Adds options to this select menu. + * + * @param options - The options to add + */ + addOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this; + /** + * Sets the options for this select menu. + * + * @param options - The options to set + */ + setOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this; + /** + * Removes, replaces, or inserts options for this select menu. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}. + * It's useful for modifying and adjusting the order of existing options. + * @example + * Remove the first option: + * ```ts + * selectMenu.spliceOptions(0, 1); + * ``` + * @example + * Remove the first n option: + * ```ts + * const n = 4; + * selectMenu.spliceOptions(0, n); + * ``` + * @example + * Remove the last option: + * ```ts + * selectMenu.spliceOptions(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of options to remove + * @param options - The replacing option objects or builders + */ + spliceOptions(index: number, deleteCount: number, ...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>): this; + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON(): APIStringSelectComponent; +} + +/** + * A builder that creates API-compatible JSON data for user select menus. + */ +declare class UserSelectMenuBuilder extends BaseSelectMenuBuilder<APIUserSelectComponent> { + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data?: Partial<APIUserSelectComponent>); +} + +/** + * A builder that creates API-compatible JSON data for text inputs. + */ +declare class TextInputBuilder extends ComponentBuilder<APITextInputComponent> implements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>> { + /** + * Creates a new text input from API data. + * + * @param data - The API data to create this text input with + * @example + * Creating a select menu option from an API data object: + * ```ts + * const textInput = new TextInputBuilder({ + * custom_id: 'a cool select menu', + * label: 'Type something', + * style: TextInputStyle.Short, + * }); + * ``` + * @example + * Creating a select menu option using setters and API data: + * ```ts + * const textInput = new TextInputBuilder({ + * label: 'Type something else', + * }) + * .setCustomId('woah') + * .setStyle(TextInputStyle.Paragraph); + * ``` + */ + constructor(data?: APITextInputComponent & { + type?: ComponentType.TextInput; + }); + /** + * Sets the custom id for this text input. + * + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Sets the label for this text input. + * + * @param label - The label to use + */ + setLabel(label: string): this; + /** + * Sets the style for this text input. + * + * @param style - The style to use + */ + setStyle(style: TextInputStyle): this; + /** + * Sets the minimum length of text for this text input. + * + * @param minLength - The minimum length of text for this text input + */ + setMinLength(minLength: number): this; + /** + * Sets the maximum length of text for this text input. + * + * @param maxLength - The maximum length of text for this text input + */ + setMaxLength(maxLength: number): this; + /** + * Sets the placeholder for this text input. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder: string): this; + /** + * Sets the value for this text input. + * + * @param value - The value to use + */ + setValue(value: string): this; + /** + * Sets whether this text input is required. + * + * @param required - Whether this text input is required + */ + setRequired(required?: boolean): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APITextInputComponent; + /** + * {@inheritDoc Equatable.equals} + */ + equals(other: APITextInputComponent | JSONEncodable<APITextInputComponent>): boolean; +} + +/** + * The builders that may be used for messages. + */ +type MessageComponentBuilder = ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder; +/** + * The builders that may be used for modals. + */ +type ModalComponentBuilder = ActionRowBuilder<ModalActionRowComponentBuilder> | ModalActionRowComponentBuilder; +/** + * The builders that may be used within an action row for messages. + */ +type MessageActionRowComponentBuilder = ButtonBuilder | ChannelSelectMenuBuilder | MentionableSelectMenuBuilder | RoleSelectMenuBuilder | StringSelectMenuBuilder | UserSelectMenuBuilder; +/** + * The builders that may be used within an action row for modals. + */ +type ModalActionRowComponentBuilder = TextInputBuilder; +/** + * Any builder. + */ +type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalActionRowComponentBuilder; +/** + * A builder that creates API-compatible JSON data for action rows. + * + * @typeParam T - The types of components this action row holds + */ +declare class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>> { + /** + * The components within this action row. + */ + readonly components: T[]; + /** + * Creates a new action row from API data. + * + * @param data - The API data to create this action row with + * @example + * Creating an action row from an API data object: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Type something", + * style: TextInputStyle.Short, + * type: ComponentType.TextInput, + * }, + * ], + * }); + * ``` + * @example + * Creating an action row using setters and API data: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Click me", + * style: ButtonStyle.Primary, + * type: ComponentType.Button, + * }, + * ], + * }) + * .addComponents(button2, button3); + * ``` + */ + constructor({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>); + /** + * Adds components to this action row. + * + * @param components - The components to add + */ + addComponents(...components: RestOrArray<T>): this; + /** + * Sets components for this action row. + * + * @param components - The components to set + */ + setComponents(...components: RestOrArray<T>): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>>; +} + +/** + * Components here are mapped to their respective builder. + */ +interface MappedComponentTypes { + /** + * The action row component type is associated with an {@link ActionRowBuilder}. + */ + [ComponentType.ActionRow]: ActionRowBuilder<AnyComponentBuilder>; + /** + * The button component type is associated with an {@link ButtonBuilder}. + */ + [ComponentType.Button]: ButtonBuilder; + /** + * The string select component type is associated with an {@link StringSelectMenuBuilder}. + */ + [ComponentType.StringSelect]: StringSelectMenuBuilder; + /** + * The text inpiut component type is associated with an {@link TextInputBuilder}. + */ + [ComponentType.TextInput]: TextInputBuilder; + /** + * The user select component type is associated with an {@link UserSelectMenuBuilder}. + */ + [ComponentType.UserSelect]: UserSelectMenuBuilder; + /** + * The role select component type is associated with an {@link RoleSelectMenuBuilder}. + */ + [ComponentType.RoleSelect]: RoleSelectMenuBuilder; + /** + * The mentionable select component type is associated with an {@link MentionableSelectMenuBuilder}. + */ + [ComponentType.MentionableSelect]: MentionableSelectMenuBuilder; + /** + * The channel select component type is associated with an {@link ChannelSelectMenuBuilder}. + */ + [ComponentType.ChannelSelect]: ChannelSelectMenuBuilder; +} +/** + * Factory for creating components from API data. + * + * @typeParam T - The type of component to use + * @param data - The API data to transform to a component class + */ +declare function createComponentBuilder<T extends keyof MappedComponentTypes>(data: (APIModalComponent | APIMessageComponent) & { + type: T; +}): MappedComponentTypes[T]; +/** + * Factory for creating components from API data. + * + * @typeParam C - The type of component to use + * @param data - The API data to transform to a component class + */ +declare function createComponentBuilder<C extends MessageComponentBuilder | ModalComponentBuilder>(data: C): C; + +declare const textInputStyleValidator: _sapphire_shapeshift.NativeEnumValidator<typeof TextInputStyle>; +declare const minLengthValidator: _sapphire_shapeshift.NumberValidator<number>; +declare const maxLengthValidator: _sapphire_shapeshift.NumberValidator<number>; +declare const requiredValidator: _sapphire_shapeshift.BooleanValidator<boolean>; +declare const valueValidator: _sapphire_shapeshift.StringValidator<string>; +declare const placeholderValidator: _sapphire_shapeshift.StringValidator<string>; +declare const labelValidator: _sapphire_shapeshift.StringValidator<string>; +declare function validateRequiredParameters$3(customId?: string, style?: TextInputStyle, label?: string): void; + +declare const Assertions$3_labelValidator: typeof labelValidator; +declare const Assertions$3_maxLengthValidator: typeof maxLengthValidator; +declare const Assertions$3_minLengthValidator: typeof minLengthValidator; +declare const Assertions$3_placeholderValidator: typeof placeholderValidator; +declare const Assertions$3_requiredValidator: typeof requiredValidator; +declare const Assertions$3_textInputStyleValidator: typeof textInputStyleValidator; +declare const Assertions$3_valueValidator: typeof valueValidator; +declare namespace Assertions$3 { + export { + Assertions$3_labelValidator as labelValidator, + Assertions$3_maxLengthValidator as maxLengthValidator, + Assertions$3_minLengthValidator as minLengthValidator, + Assertions$3_placeholderValidator as placeholderValidator, + Assertions$3_requiredValidator as requiredValidator, + Assertions$3_textInputStyleValidator as textInputStyleValidator, + validateRequiredParameters$3 as validateRequiredParameters, + Assertions$3_valueValidator as valueValidator, + }; +} + +/** + * A builder that creates API-compatible JSON data for modals. + */ +declare class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> { + /** + * The API data associated with this modal. + */ + readonly data: Partial<APIModalInteractionResponseCallbackData>; + /** + * The components within this modal. + */ + readonly components: ActionRowBuilder<ModalActionRowComponentBuilder>[]; + /** + * Creates a new modal from API data. + * + * @param data - The API data to create this modal with + */ + constructor({ components, ...data }?: Partial<APIModalInteractionResponseCallbackData>); + /** + * Sets the title of this modal. + * + * @param title - The title to use + */ + setTitle(title: string): this; + /** + * Sets the custom id of this modal. + * + * @param customId - The custom id to use + */ + setCustomId(customId: string): this; + /** + * Adds components to this modal. + * + * @param components - The components to add + */ + addComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder> | APIActionRowComponent<APIModalActionRowComponent>>): this; + /** + * Sets components for this modal. + * + * @param components - The components to set + */ + setComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder>>): this; + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON(): APIModalInteractionResponseCallbackData; +} + +declare const titleValidator: _sapphire_shapeshift.StringValidator<string>; +declare const componentsValidator: _sapphire_shapeshift.ArrayValidator<[ActionRowBuilder<AnyComponentBuilder>, ...ActionRowBuilder<AnyComponentBuilder>[]], ActionRowBuilder<AnyComponentBuilder>>; +declare function validateRequiredParameters$2(customId?: string, title?: string, components?: ActionRowBuilder<ModalActionRowComponentBuilder>[]): void; + +declare const Assertions$2_componentsValidator: typeof componentsValidator; +declare const Assertions$2_titleValidator: typeof titleValidator; +declare namespace Assertions$2 { + export { + Assertions$2_componentsValidator as componentsValidator, + Assertions$2_titleValidator as titleValidator, + validateRequiredParameters$2 as validateRequiredParameters, + }; +} + +/** + * This mixin holds name and description symbols for slash commands. + */ +declare class SharedNameAndDescription { + /** + * The name of this command. + */ + readonly name: string; + /** + * The name localizations of this command. + */ + readonly name_localizations?: LocalizationMap; + /** + * The description of this command. + */ + readonly description: string; + /** + * The description localizations of this command. + */ + readonly description_localizations?: LocalizationMap; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name: string): this; + /** + * Sets the description of this command. + * + * @param description - The description to use + */ + setDescription(description: string): this; + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale: LocaleString, localizedName: string | null): this; + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames: LocalizationMap | null): this; + /** + * Sets a description localization for this command. + * + * @param locale - The locale to set + * @param localizedDescription - The localized description for the given locale + */ + setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null): this; + /** + * Sets the description localizations for this command. + * + * @param localizedDescriptions - The object of localized descriptions to set + */ + setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null): this; +} + +/** + * The base application command option builder that contains common symbols for application command builders. + */ +declare abstract class ApplicationCommandOptionBase extends SharedNameAndDescription { + /** + * The type of this option. + */ + abstract readonly type: ApplicationCommandOptionType; + /** + * Whether this option is required. + * + * @defaultValue `false` + */ + readonly required: boolean; + /** + * Sets whether this option is required. + * + * @param required - Whether this option should be required + */ + setRequired(required: boolean): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + abstract toJSON(): APIApplicationCommandBasicOption; + /** + * This method runs required validators on this builder. + */ + protected runRequiredValidations(): void; +} + +/** + * A slash command attachment option. + */ +declare class SlashCommandAttachmentOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Attachment; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandAttachmentOption; +} + +/** + * A slash command boolean option. + */ +declare class SlashCommandBooleanOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Boolean; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandBooleanOption; +} + +/** + * The allowed channel types used for a channel option in a slash command builder. + * + * @privateRemarks This can't be dynamic because const enums are erased at runtime. + * @internal + */ +declare const allowedChannelTypes: readonly [ChannelType.GuildText, ChannelType.GuildVoice, ChannelType.GuildCategory, ChannelType.GuildAnnouncement, ChannelType.AnnouncementThread, ChannelType.PublicThread, ChannelType.PrivateThread, ChannelType.GuildStageVoice, ChannelType.GuildForum]; +/** + * The type of allowed channel types used for a channel option. + */ +type ApplicationCommandOptionAllowedChannelTypes = (typeof allowedChannelTypes)[number]; +/** + * This mixin holds channel type symbols used for options. + */ +declare class ApplicationCommandOptionChannelTypesMixin { + /** + * The channel types of this option. + */ + readonly channel_types?: ApplicationCommandOptionAllowedChannelTypes[]; + /** + * Adds channel types to this option. + * + * @param channelTypes - The channel types + */ + addChannelTypes(...channelTypes: ApplicationCommandOptionAllowedChannelTypes[]): this; +} + +/** + * A slash command channel option. + */ +declare class SlashCommandChannelOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Channel; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandChannelOption; +} +interface SlashCommandChannelOption extends ApplicationCommandOptionChannelTypesMixin { +} + +/** + * This mixin holds minimum and maximum symbols used for options. + */ +declare abstract class ApplicationCommandNumericOptionMinMaxValueMixin { + /** + * The maximum value of this option. + */ + readonly max_value?: number; + /** + * The minimum value of this option. + */ + readonly min_value?: number; + /** + * Sets the maximum number value of this option. + * + * @param max - The maximum value this option can be + */ + abstract setMaxValue(max: number): this; + /** + * Sets the minimum number value of this option. + * + * @param min - The minimum value this option can be + */ + abstract setMinValue(min: number): this; +} + +/** + * This mixin holds choices and autocomplete symbols used for options. + */ +declare class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends number | string> { + /** + * The choices of this option. + */ + readonly choices?: APIApplicationCommandOptionChoice<T>[]; + /** + * Whether this option utilizes autocomplete. + */ + readonly autocomplete?: boolean; + /** + * The type of this option. + * + * @privateRemarks Since this is present and this is a mixin, this is needed. + */ + readonly type: ApplicationCommandOptionType; + /** + * Adds multiple choices to this option. + * + * @param choices - The choices to add + */ + addChoices(...choices: APIApplicationCommandOptionChoice<T>[]): this; + /** + * Sets multiple choices for this option. + * + * @param choices - The choices to set + */ + setChoices<Input extends APIApplicationCommandOptionChoice<T>[]>(...choices: Input): this; + /** + * Whether this option uses autocomplete. + * + * @param autocomplete - Whether this option should use autocomplete + */ + setAutocomplete(autocomplete: boolean): this; +} + +/** + * A slash command integer option. + */ +declare class SlashCommandIntegerOption extends ApplicationCommandOptionBase implements ApplicationCommandNumericOptionMinMaxValueMixin { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Integer; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max: number): this; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min: number): this; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandIntegerOption; +} +interface SlashCommandIntegerOption extends ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> { +} + +/** + * A slash command mentionable option. + */ +declare class SlashCommandMentionableOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Mentionable; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandMentionableOption; +} + +/** + * A slash command number option. + */ +declare class SlashCommandNumberOption extends ApplicationCommandOptionBase implements ApplicationCommandNumericOptionMinMaxValueMixin { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Number; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max: number): this; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min: number): this; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandNumberOption; +} +interface SlashCommandNumberOption extends ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> { +} + +/** + * A slash command role option. + */ +declare class SlashCommandRoleOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.Role; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandRoleOption; +} + +/** + * A slash command string option. + */ +declare class SlashCommandStringOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.String; + /** + * The maximum length of this option. + */ + readonly max_length?: number; + /** + * The minimum length of this option. + */ + readonly min_length?: number; + /** + * Sets the maximum length of this string option. + * + * @param max - The maximum length this option can be + */ + setMaxLength(max: number): this; + /** + * Sets the minimum length of this string option. + * + * @param min - The minimum length this option can be + */ + setMinLength(min: number): this; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandStringOption; +} +interface SlashCommandStringOption extends ApplicationCommandOptionWithChoicesAndAutocompleteMixin<string> { +} + +/** + * A slash command user option. + */ +declare class SlashCommandUserOption extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + readonly type: ApplicationCommandOptionType.User; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON(): APIApplicationCommandUserOption; +} + +/** + * This mixin holds symbols that can be shared in slash command options. + * + * @typeParam ShouldOmitSubcommandFunctions - Whether to omit subcommand functions. + */ +declare class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> { + readonly options: ToAPIApplicationCommandOptions[]; + /** + * Adds a boolean option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addBooleanOption(input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a user option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a channel option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addChannelOption(input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a role option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds an attachment option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addAttachmentOption(input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a mentionable option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addMentionableOption(input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a string option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addStringOption(input: Omit<SlashCommandStringOption, 'addChoices'> | Omit<SlashCommandStringOption, 'setAutocomplete'> | SlashCommandStringOption | ((builder: SlashCommandStringOption) => Omit<SlashCommandStringOption, 'addChoices'> | Omit<SlashCommandStringOption, 'setAutocomplete'> | SlashCommandStringOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds an integer option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addIntegerOption(input: Omit<SlashCommandIntegerOption, 'addChoices'> | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | SlashCommandIntegerOption | ((builder: SlashCommandIntegerOption) => Omit<SlashCommandIntegerOption, 'addChoices'> | Omit<SlashCommandIntegerOption, 'setAutocomplete'> | SlashCommandIntegerOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Adds a number option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addNumberOption(input: Omit<SlashCommandNumberOption, 'addChoices'> | Omit<SlashCommandNumberOption, 'setAutocomplete'> | SlashCommandNumberOption | ((builder: SlashCommandNumberOption) => Omit<SlashCommandNumberOption, 'addChoices'> | Omit<SlashCommandNumberOption, 'setAutocomplete'> | SlashCommandNumberOption)): ShouldOmitSubcommandFunctions extends true ? Omit<this, "addSubcommand" | "addSubcommandGroup"> : this; + /** + * Where the actual adding magic happens. ✨ + * + * @param input - The input. What else? + * @param Instance - The instance of whatever is being added + * @internal + */ + private _sharedAddOptionMethod; +} + +/** + * Represents a folder for subcommands. + * + * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups} + */ +declare class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationCommandOptions { + /** + * The name of this subcommand group. + */ + readonly name: string; + /** + * The description of this subcommand group. + */ + readonly description: string; + /** + * The subcommands within this subcommand group. + */ + readonly options: SlashCommandSubcommandBuilder[]; + /** + * Adds a new subcommand to this group. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): APIApplicationCommandSubcommandGroupOption; +} +interface SlashCommandSubcommandGroupBuilder extends SharedNameAndDescription { +} +/** + * A builder that creates API-compatible JSON data for slash command subcommands. + * + * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups} + */ +declare class SlashCommandSubcommandBuilder implements ToAPIApplicationCommandOptions { + /** + * The name of this subcommand. + */ + readonly name: string; + /** + * The description of this subcommand. + */ + readonly description: string; + /** + * The options within this subcommand. + */ + readonly options: ApplicationCommandOptionBase[]; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): APIApplicationCommandSubcommandOption; +} +interface SlashCommandSubcommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions<false> { +} + +/** + * A builder that creates API-compatible JSON data for slash commands. + */ +declare class SlashCommandBuilder { + /** + * The name of this command. + */ + readonly name: string; + /** + * The name localizations of this command. + */ + readonly name_localizations?: LocalizationMap; + /** + * The description of this command. + */ + readonly description: string; + /** + * The description localizations of this command. + */ + readonly description_localizations?: LocalizationMap; + /** + * The options of this command. + */ + readonly options: ToAPIApplicationCommandOptions[]; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + readonly default_permission: boolean | undefined; + /** + * The set of permissions represented as a bit set for the command. + */ + readonly default_member_permissions: Permissions | null | undefined; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + readonly dm_permission: boolean | undefined; + /** + * Whether this command is NSFW. + */ + readonly nsfw: boolean | undefined; + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether or not to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value: boolean): this; + /** + * Sets the default permissions a member should have in order to run the command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined): this; + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled: boolean | null | undefined): this; + /** + * Sets whether this command is NSFW. + * + * @param nsfw - Whether this command is NSFW + */ + setNSFW(nsfw?: boolean): this; + /** + * Adds a new subcommand group to this command. + * + * @param input - A function that returns a subcommand group builder or an already built builder + */ + addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder; + /** + * Adds a new subcommand to this command. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody; +} +interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions { +} +/** + * An interface specifically for slash command subcommands. + */ +interface SlashCommandSubcommandsOnlyBuilder extends Omit<SlashCommandBuilder, Exclude<keyof SharedSlashCommandOptions, 'options'>> { +} +/** + * An interface specifically for slash command options. + */ +interface SlashCommandOptionsOnlyBuilder extends SharedNameAndDescription, SharedSlashCommandOptions, Pick<SlashCommandBuilder, 'toJSON'> { +} +/** + * An interface that ensures the `toJSON()` call will return something + * that can be serialized into API-compatible data. + */ +interface ToAPIApplicationCommandOptions { + toJSON(): APIApplicationCommandOption; +} + +declare function validateName$1(name: unknown): asserts name is string; +declare function validateDescription(description: unknown): asserts description is string; +declare function validateLocale(locale: unknown): Locale; +declare function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[]; +declare function validateRequiredParameters$1(name: string, description: string, options: ToAPIApplicationCommandOptions[]): void; +declare function validateDefaultPermission$1(value: unknown): asserts value is boolean; +declare function validateRequired(required: unknown): asserts required is boolean; +declare function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void; +declare function assertReturnOfBuilder<T extends ApplicationCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder>(input: unknown, ExpectedInstanceOf: new () => T): asserts input is T; +declare const localizationMapPredicate: _sapphire_shapeshift.UnionValidator<_sapphire_shapeshift.UndefinedToOptional<Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "sv-SE" | "th" | "tr" | "uk" | "vi", string | null>>> | null | undefined>; +declare function validateLocalizationMap(value: unknown): asserts value is LocalizationMap; +declare function validateDMPermission$1(value: unknown): asserts value is boolean | null | undefined; +declare function validateDefaultMemberPermissions$1(permissions: unknown): string | null | undefined; +declare function validateNSFW(value: unknown): asserts value is boolean; + +declare const Assertions$1_assertReturnOfBuilder: typeof assertReturnOfBuilder; +declare const Assertions$1_localizationMapPredicate: typeof localizationMapPredicate; +declare const Assertions$1_validateChoicesLength: typeof validateChoicesLength; +declare const Assertions$1_validateDescription: typeof validateDescription; +declare const Assertions$1_validateLocale: typeof validateLocale; +declare const Assertions$1_validateLocalizationMap: typeof validateLocalizationMap; +declare const Assertions$1_validateMaxOptionsLength: typeof validateMaxOptionsLength; +declare const Assertions$1_validateNSFW: typeof validateNSFW; +declare const Assertions$1_validateRequired: typeof validateRequired; +declare namespace Assertions$1 { + export { + Assertions$1_assertReturnOfBuilder as assertReturnOfBuilder, + Assertions$1_localizationMapPredicate as localizationMapPredicate, + Assertions$1_validateChoicesLength as validateChoicesLength, + validateDMPermission$1 as validateDMPermission, + validateDefaultMemberPermissions$1 as validateDefaultMemberPermissions, + validateDefaultPermission$1 as validateDefaultPermission, + Assertions$1_validateDescription as validateDescription, + Assertions$1_validateLocale as validateLocale, + Assertions$1_validateLocalizationMap as validateLocalizationMap, + Assertions$1_validateMaxOptionsLength as validateMaxOptionsLength, + Assertions$1_validateNSFW as validateNSFW, + validateName$1 as validateName, + Assertions$1_validateRequired as validateRequired, + validateRequiredParameters$1 as validateRequiredParameters, + }; +} + +/** + * The type a context menu command can be. + */ +type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User; +/** + * A builder that creates API-compatible JSON data for context menu commands. + */ +declare class ContextMenuCommandBuilder { + /** + * The name of this command. + */ + readonly name: string; + /** + * The name localizations of this command. + */ + readonly name_localizations?: LocalizationMap; + /** + * The type of this command. + */ + readonly type: ContextMenuCommandType; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + readonly default_permission: boolean | undefined; + /** + * The set of permissions represented as a bit set for the command. + */ + readonly default_member_permissions: Permissions | null | undefined; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + readonly dm_permission: boolean | undefined; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name: string): this; + /** + * Sets the type of this command. + * + * @param type - The type to use + */ + setType(type: ContextMenuCommandType): this; + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value: boolean): this; + /** + * Sets the default permissions a member should have in order to run this command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined): this; + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled: boolean | null | undefined): this; + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale: LocaleString, localizedName: string | null): this; + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames: LocalizationMap | null): this; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON(): RESTPostAPIContextMenuApplicationCommandsJSONBody; +} + +declare function validateDefaultPermission(value: unknown): asserts value is boolean; +declare function validateName(name: unknown): asserts name is string; +declare function validateType(type: unknown): asserts type is ContextMenuCommandType; +declare function validateRequiredParameters(name: string, type: number): void; +declare function validateDMPermission(value: unknown): asserts value is boolean | null | undefined; +declare function validateDefaultMemberPermissions(permissions: unknown): string | null | undefined; + +declare const Assertions_validateDMPermission: typeof validateDMPermission; +declare const Assertions_validateDefaultMemberPermissions: typeof validateDefaultMemberPermissions; +declare const Assertions_validateDefaultPermission: typeof validateDefaultPermission; +declare const Assertions_validateName: typeof validateName; +declare const Assertions_validateRequiredParameters: typeof validateRequiredParameters; +declare const Assertions_validateType: typeof validateType; +declare namespace Assertions { + export { + Assertions_validateDMPermission as validateDMPermission, + Assertions_validateDefaultMemberPermissions as validateDefaultMemberPermissions, + Assertions_validateDefaultPermission as validateDefaultPermission, + Assertions_validateName as validateName, + Assertions_validateRequiredParameters as validateRequiredParameters, + Assertions_validateType as validateType, + }; +} + +/** + * Calculates the length of the embed. + * + * @param data - The embed data to check + */ +declare function embedLength(data: APIEmbed): number; + +/** + * Enables validators. + * + * @returns Whether validation is occurring. + */ +declare function enableValidators(): boolean; +/** + * Disables validators. + * + * @returns Whether validation is occurring. + */ +declare function disableValidators(): boolean; +/** + * Checks whether validation is occurring. + */ +declare function isValidationEnabled(): boolean; + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/builders#readme | @discordjs/builders} version + * that you are currently using. + * + * @privateRemarks This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild. + */ +declare const version: string; + +export { ActionRowBuilder, AnyAPIActionRowComponent, AnyComponentBuilder, ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionAllowedChannelTypes, ApplicationCommandOptionBase, ApplicationCommandOptionChannelTypesMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin, BaseSelectMenuBuilder, ButtonBuilder, ChannelSelectMenuBuilder, Assertions$4 as ComponentAssertions, ComponentBuilder, Assertions as ContextMenuCommandAssertions, ContextMenuCommandBuilder, ContextMenuCommandType, Assertions$5 as EmbedAssertions, EmbedAuthorData, EmbedAuthorOptions, EmbedBuilder, EmbedFooterData, EmbedFooterOptions, EmbedImageData, IconData, MappedComponentTypes, MentionableSelectMenuBuilder, MessageActionRowComponentBuilder, MessageComponentBuilder, ModalActionRowComponentBuilder, Assertions$2 as ModalAssertions, ModalBuilder, ModalComponentBuilder, RGBTuple, RestOrArray, RoleSelectMenuBuilder, StringSelectMenuBuilder as SelectMenuBuilder, StringSelectMenuOptionBuilder as SelectMenuOptionBuilder, SharedNameAndDescription, SharedSlashCommandOptions, Assertions$1 as SlashCommandAssertions, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandBuilder, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandOptionsOnlyBuilder, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandUserOption, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Assertions$3 as TextInputAssertions, TextInputBuilder, ToAPIApplicationCommandOptions, UserSelectMenuBuilder, createComponentBuilder, disableValidators, embedLength, enableValidators, isValidationEnabled, normalizeArray, version }; diff --git a/node_modules/@discordjs/builders/dist/index.js b/node_modules/@discordjs/builders/dist/index.js new file mode 100644 index 0000000..4a8f89c --- /dev/null +++ b/node_modules/@discordjs/builders/dist/index.js @@ -0,0 +1,2612 @@ +"use strict"; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); +var __decorateClass = (decorators, target, key, kind) => { + var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; + for (var i = decorators.length - 1, decorator; i >= 0; i--) + if (decorator = decorators[i]) + result = (kind ? decorator(target, key, result) : decorator(result)) || result; + if (kind && result) + __defProp(target, key, result); + return result; +}; + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + ActionRowBuilder: () => ActionRowBuilder, + ApplicationCommandNumericOptionMinMaxValueMixin: () => ApplicationCommandNumericOptionMinMaxValueMixin, + ApplicationCommandOptionBase: () => ApplicationCommandOptionBase, + ApplicationCommandOptionChannelTypesMixin: () => ApplicationCommandOptionChannelTypesMixin, + ApplicationCommandOptionWithChoicesAndAutocompleteMixin: () => ApplicationCommandOptionWithChoicesAndAutocompleteMixin, + BaseSelectMenuBuilder: () => BaseSelectMenuBuilder, + ButtonBuilder: () => ButtonBuilder, + ChannelSelectMenuBuilder: () => ChannelSelectMenuBuilder, + ComponentAssertions: () => Assertions_exports2, + ComponentBuilder: () => ComponentBuilder, + ContextMenuCommandAssertions: () => Assertions_exports6, + ContextMenuCommandBuilder: () => ContextMenuCommandBuilder, + EmbedAssertions: () => Assertions_exports, + EmbedBuilder: () => EmbedBuilder, + MentionableSelectMenuBuilder: () => MentionableSelectMenuBuilder, + ModalAssertions: () => Assertions_exports4, + ModalBuilder: () => ModalBuilder, + RoleSelectMenuBuilder: () => RoleSelectMenuBuilder, + SelectMenuBuilder: () => StringSelectMenuBuilder, + SelectMenuOptionBuilder: () => StringSelectMenuOptionBuilder, + SharedNameAndDescription: () => SharedNameAndDescription, + SharedSlashCommandOptions: () => SharedSlashCommandOptions, + SlashCommandAssertions: () => Assertions_exports5, + SlashCommandAttachmentOption: () => SlashCommandAttachmentOption, + SlashCommandBooleanOption: () => SlashCommandBooleanOption, + SlashCommandBuilder: () => SlashCommandBuilder, + SlashCommandChannelOption: () => SlashCommandChannelOption, + SlashCommandIntegerOption: () => SlashCommandIntegerOption, + SlashCommandMentionableOption: () => SlashCommandMentionableOption, + SlashCommandNumberOption: () => SlashCommandNumberOption, + SlashCommandRoleOption: () => SlashCommandRoleOption, + SlashCommandStringOption: () => SlashCommandStringOption, + SlashCommandSubcommandBuilder: () => SlashCommandSubcommandBuilder, + SlashCommandSubcommandGroupBuilder: () => SlashCommandSubcommandGroupBuilder, + SlashCommandUserOption: () => SlashCommandUserOption, + StringSelectMenuBuilder: () => StringSelectMenuBuilder, + StringSelectMenuOptionBuilder: () => StringSelectMenuOptionBuilder, + TextInputAssertions: () => Assertions_exports3, + TextInputBuilder: () => TextInputBuilder, + UserSelectMenuBuilder: () => UserSelectMenuBuilder, + createComponentBuilder: () => createComponentBuilder, + disableValidators: () => disableValidators, + embedLength: () => embedLength, + enableValidators: () => enableValidators, + isValidationEnabled: () => isValidationEnabled, + normalizeArray: () => normalizeArray, + version: () => version +}); +module.exports = __toCommonJS(src_exports); + +// src/messages/embed/Assertions.ts +var Assertions_exports = {}; +__export(Assertions_exports, { + RGBPredicate: () => RGBPredicate, + authorNamePredicate: () => authorNamePredicate, + colorPredicate: () => colorPredicate, + descriptionPredicate: () => descriptionPredicate, + embedAuthorPredicate: () => embedAuthorPredicate, + embedFieldPredicate: () => embedFieldPredicate, + embedFieldsArrayPredicate: () => embedFieldsArrayPredicate, + embedFooterPredicate: () => embedFooterPredicate, + fieldInlinePredicate: () => fieldInlinePredicate, + fieldLengthPredicate: () => fieldLengthPredicate, + fieldNamePredicate: () => fieldNamePredicate, + fieldValuePredicate: () => fieldValuePredicate, + footerTextPredicate: () => footerTextPredicate, + imageURLPredicate: () => imageURLPredicate, + timestampPredicate: () => timestampPredicate, + titlePredicate: () => titlePredicate, + urlPredicate: () => urlPredicate, + validateFieldLength: () => validateFieldLength +}); +var import_shapeshift = require("@sapphire/shapeshift"); + +// src/util/validation.ts +var validate = true; +function enableValidators() { + return validate = true; +} +__name(enableValidators, "enableValidators"); +function disableValidators() { + return validate = false; +} +__name(disableValidators, "disableValidators"); +function isValidationEnabled() { + return validate; +} +__name(isValidationEnabled, "isValidationEnabled"); + +// src/messages/embed/Assertions.ts +var fieldNamePredicate = import_shapeshift.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(256).setValidationEnabled(isValidationEnabled); +var fieldValuePredicate = import_shapeshift.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(1024).setValidationEnabled(isValidationEnabled); +var fieldInlinePredicate = import_shapeshift.s.boolean.optional; +var embedFieldPredicate = import_shapeshift.s.object({ + name: fieldNamePredicate, + value: fieldValuePredicate, + inline: fieldInlinePredicate +}).setValidationEnabled(isValidationEnabled); +var embedFieldsArrayPredicate = embedFieldPredicate.array.setValidationEnabled(isValidationEnabled); +var fieldLengthPredicate = import_shapeshift.s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateFieldLength(amountAdding, fields) { + fieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding); +} +__name(validateFieldLength, "validateFieldLength"); +var authorNamePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled); +var imageURLPredicate = import_shapeshift.s.string.url({ + allowedProtocols: ["http:", "https:", "attachment:"] +}).nullish.setValidationEnabled(isValidationEnabled); +var urlPredicate = import_shapeshift.s.string.url({ + allowedProtocols: ["http:", "https:"] +}).nullish.setValidationEnabled(isValidationEnabled); +var embedAuthorPredicate = import_shapeshift.s.object({ + name: authorNamePredicate, + iconURL: imageURLPredicate, + url: urlPredicate +}).setValidationEnabled(isValidationEnabled); +var RGBPredicate = import_shapeshift.s.number.int.greaterThanOrEqual(0).lessThanOrEqual(255).setValidationEnabled(isValidationEnabled); +var colorPredicate = import_shapeshift.s.number.int.greaterThanOrEqual(0).lessThanOrEqual(16777215).or(import_shapeshift.s.tuple([RGBPredicate, RGBPredicate, RGBPredicate])).nullable.setValidationEnabled(isValidationEnabled); +var descriptionPredicate = import_shapeshift.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(4096).nullable.setValidationEnabled(isValidationEnabled); +var footerTextPredicate = import_shapeshift.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(2048).nullable.setValidationEnabled(isValidationEnabled); +var embedFooterPredicate = import_shapeshift.s.object({ + text: footerTextPredicate, + iconURL: imageURLPredicate +}).setValidationEnabled(isValidationEnabled); +var timestampPredicate = import_shapeshift.s.union(import_shapeshift.s.number, import_shapeshift.s.date).nullable.setValidationEnabled(isValidationEnabled); +var titlePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled); + +// src/util/normalizeArray.ts +function normalizeArray(arr) { + if (Array.isArray(arr[0])) + return arr[0]; + return arr; +} +__name(normalizeArray, "normalizeArray"); + +// src/messages/embed/Embed.ts +var EmbedBuilder = class { + static { + __name(this, "EmbedBuilder"); + } + /** + * The API data associated with this embed. + */ + data; + /** + * Creates a new embed from API data. + * + * @param data - The API data to create this embed with + */ + constructor(data = {}) { + this.data = { ...data }; + if (data.timestamp) + this.data.timestamp = new Date(data.timestamp).toISOString(); + } + /** + * Appends fields to the embed. + * + * @remarks + * This method accepts either an array of fields or a variable number of field parameters. + * The maximum amount of fields that can be added is 25. + * @example + * Using an array: + * ```ts + * const fields: APIEmbedField[] = ...; + * const embed = new EmbedBuilder() + * .addFields(fields); + * ``` + * @example + * Using rest parameters (variadic): + * ```ts + * const embed = new EmbedBuilder() + * .addFields( + * { name: 'Field 1', value: 'Value 1' }, + * { name: 'Field 2', value: 'Value 2' }, + * ); + * ``` + * @param fields - The fields to add + */ + addFields(...fields) { + const normalizedFields = normalizeArray(fields); + validateFieldLength(normalizedFields.length, this.data.fields); + embedFieldsArrayPredicate.parse(normalizedFields); + if (this.data.fields) + this.data.fields.push(...normalizedFields); + else + this.data.fields = normalizedFields; + return this; + } + /** + * Removes, replaces, or inserts fields for this embed. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}. + * The maximum amount of fields that can be added is 25. + * + * It's useful for modifying and adjusting order of the already-existing fields of an embed. + * @example + * Remove the first field: + * ```ts + * embed.spliceFields(0, 1); + * ``` + * @example + * Remove the first n fields: + * ```ts + * const n = 4; + * embed.spliceFields(0, n); + * ``` + * @example + * Remove the last field: + * ```ts + * embed.spliceFields(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of fields to remove + * @param fields - The replacing field objects + */ + spliceFields(index, deleteCount, ...fields) { + validateFieldLength(fields.length - deleteCount, this.data.fields); + embedFieldsArrayPredicate.parse(fields); + if (this.data.fields) + this.data.fields.splice(index, deleteCount, ...fields); + else + this.data.fields = fields; + return this; + } + /** + * Sets the fields for this embed. + * + * @remarks + * This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically, + * it splices the entire array of fields, replacing them with the provided fields. + * + * You can set a maximum of 25 fields. + * @param fields - The fields to set + */ + setFields(...fields) { + this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields)); + return this; + } + /** + * Sets the author of this embed. + * + * @param options - The options to use + */ + setAuthor(options) { + if (options === null) { + this.data.author = void 0; + return this; + } + embedAuthorPredicate.parse(options); + this.data.author = { name: options.name, url: options.url, icon_url: options.iconURL }; + return this; + } + /** + * Sets the color of this embed. + * + * @param color - The color to use + */ + setColor(color) { + colorPredicate.parse(color); + if (Array.isArray(color)) { + const [red, green, blue] = color; + this.data.color = (red << 16) + (green << 8) + blue; + return this; + } + this.data.color = color ?? void 0; + return this; + } + /** + * Sets the description of this embed. + * + * @param description - The description to use + */ + setDescription(description) { + descriptionPredicate.parse(description); + this.data.description = description ?? void 0; + return this; + } + /** + * Sets the footer of this embed. + * + * @param options - The footer to use + */ + setFooter(options) { + if (options === null) { + this.data.footer = void 0; + return this; + } + embedFooterPredicate.parse(options); + this.data.footer = { text: options.text, icon_url: options.iconURL }; + return this; + } + /** + * Sets the image of this embed. + * + * @param url - The image URL to use + */ + setImage(url) { + imageURLPredicate.parse(url); + this.data.image = url ? { url } : void 0; + return this; + } + /** + * Sets the thumbnail of this embed. + * + * @param url - The thumbnail URL to use + */ + setThumbnail(url) { + imageURLPredicate.parse(url); + this.data.thumbnail = url ? { url } : void 0; + return this; + } + /** + * Sets the timestamp of this embed. + * + * @param timestamp - The timestamp or date to use + */ + setTimestamp(timestamp = Date.now()) { + timestampPredicate.parse(timestamp); + this.data.timestamp = timestamp ? new Date(timestamp).toISOString() : void 0; + return this; + } + /** + * Sets the title for this embed. + * + * @param title - The title to use + */ + setTitle(title) { + titlePredicate.parse(title); + this.data.title = title ?? void 0; + return this; + } + /** + * Sets the URL of this embed. + * + * @param url - The URL to use + */ + setURL(url) { + urlPredicate.parse(url); + this.data.url = url ?? void 0; + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + return { ...this.data }; + } +}; + +// src/index.ts +__reExport(src_exports, require("@discordjs/formatters"), module.exports); + +// src/components/Assertions.ts +var Assertions_exports2 = {}; +__export(Assertions_exports2, { + buttonLabelValidator: () => buttonLabelValidator, + buttonStyleValidator: () => buttonStyleValidator, + channelTypesValidator: () => channelTypesValidator, + customIdValidator: () => customIdValidator, + defaultValidator: () => defaultValidator, + disabledValidator: () => disabledValidator, + emojiValidator: () => emojiValidator, + jsonOptionValidator: () => jsonOptionValidator, + labelValueDescriptionValidator: () => labelValueDescriptionValidator, + minMaxValidator: () => minMaxValidator, + optionValidator: () => optionValidator, + optionsLengthValidator: () => optionsLengthValidator, + optionsValidator: () => optionsValidator, + placeholderValidator: () => placeholderValidator, + urlValidator: () => urlValidator, + validateRequiredButtonParameters: () => validateRequiredButtonParameters, + validateRequiredSelectMenuOptionParameters: () => validateRequiredSelectMenuOptionParameters, + validateRequiredSelectMenuParameters: () => validateRequiredSelectMenuParameters +}); +var import_shapeshift2 = require("@sapphire/shapeshift"); +var import_v10 = require("discord-api-types/v10"); + +// src/components/selectMenu/StringSelectMenuOption.ts +var StringSelectMenuOptionBuilder = class { + /** + * Creates a new string select menu option from API data. + * + * @param data - The API data to create this string select menu option with + * @example + * Creating a string select menu option from an API data object: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * label: 'catchy label', + * value: '1', + * }); + * ``` + * @example + * Creating a string select menu option using setters and API data: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * default: true, + * value: '1', + * }) + * .setLabel('woah'); + * ``` + */ + constructor(data = {}) { + this.data = data; + } + static { + __name(this, "StringSelectMenuOptionBuilder"); + } + /** + * Sets the label for this option. + * + * @param label - The label to use + */ + setLabel(label) { + this.data.label = labelValueDescriptionValidator.parse(label); + return this; + } + /** + * Sets the value for this option. + * + * @param value - The value to use + */ + setValue(value) { + this.data.value = labelValueDescriptionValidator.parse(value); + return this; + } + /** + * Sets the description for this option. + * + * @param description - The description to use + */ + setDescription(description) { + this.data.description = labelValueDescriptionValidator.parse(description); + return this; + } + /** + * Sets whether this option is selected by default. + * + * @param isDefault - Whether this option is selected by default + */ + setDefault(isDefault = true) { + this.data.default = defaultValidator.parse(isDefault); + return this; + } + /** + * Sets the emoji to display for this option. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji) { + this.data.emoji = emojiValidator.parse(emoji); + return this; + } + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON() { + validateRequiredSelectMenuOptionParameters(this.data.label, this.data.value); + return { + ...this.data + }; + } +}; + +// src/components/Assertions.ts +var customIdValidator = import_shapeshift2.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var emojiValidator = import_shapeshift2.s.object({ + id: import_shapeshift2.s.string, + name: import_shapeshift2.s.string, + animated: import_shapeshift2.s.boolean +}).partial.strict.setValidationEnabled(isValidationEnabled); +var disabledValidator = import_shapeshift2.s.boolean; +var buttonLabelValidator = import_shapeshift2.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(80).setValidationEnabled(isValidationEnabled); +var buttonStyleValidator = import_shapeshift2.s.nativeEnum(import_v10.ButtonStyle); +var placeholderValidator = import_shapeshift2.s.string.lengthLessThanOrEqual(150).setValidationEnabled(isValidationEnabled); +var minMaxValidator = import_shapeshift2.s.number.int.greaterThanOrEqual(0).lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +var labelValueDescriptionValidator = import_shapeshift2.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var jsonOptionValidator = import_shapeshift2.s.object({ + label: labelValueDescriptionValidator, + value: labelValueDescriptionValidator, + description: labelValueDescriptionValidator.optional, + emoji: emojiValidator.optional, + default: import_shapeshift2.s.boolean.optional +}).setValidationEnabled(isValidationEnabled); +var optionValidator = import_shapeshift2.s.instance(StringSelectMenuOptionBuilder).setValidationEnabled(isValidationEnabled); +var optionsValidator = optionValidator.array.lengthGreaterThanOrEqual(0).setValidationEnabled(isValidationEnabled); +var optionsLengthValidator = import_shapeshift2.s.number.int.greaterThanOrEqual(0).lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateRequiredSelectMenuParameters(options, customId) { + customIdValidator.parse(customId); + optionsValidator.parse(options); +} +__name(validateRequiredSelectMenuParameters, "validateRequiredSelectMenuParameters"); +var defaultValidator = import_shapeshift2.s.boolean; +function validateRequiredSelectMenuOptionParameters(label, value) { + labelValueDescriptionValidator.parse(label); + labelValueDescriptionValidator.parse(value); +} +__name(validateRequiredSelectMenuOptionParameters, "validateRequiredSelectMenuOptionParameters"); +var channelTypesValidator = import_shapeshift2.s.nativeEnum(import_v10.ChannelType).array.setValidationEnabled(isValidationEnabled); +var urlValidator = import_shapeshift2.s.string.url({ + allowedProtocols: ["http:", "https:", "discord:"] +}).setValidationEnabled(isValidationEnabled); +function validateRequiredButtonParameters(style, label, emoji, customId, url) { + if (url && customId) { + throw new RangeError("URL and custom id are mutually exclusive"); + } + if (!label && !emoji) { + throw new RangeError("Buttons must have a label and/or an emoji"); + } + if (style === import_v10.ButtonStyle.Link) { + if (!url) { + throw new RangeError("Link buttons must have a url"); + } + } else if (url) { + throw new RangeError("Non-link buttons cannot have a url"); + } +} +__name(validateRequiredButtonParameters, "validateRequiredButtonParameters"); + +// src/components/ActionRow.ts +var import_v1011 = require("discord-api-types/v10"); + +// src/components/Component.ts +var ComponentBuilder = class { + static { + __name(this, "ComponentBuilder"); + } + /** + * The API data associated with this component. + */ + data; + /** + * Constructs a new kind of component. + * + * @param data - The data to construct a component out of + */ + constructor(data) { + this.data = data; + } +}; + +// src/components/Components.ts +var import_v1010 = require("discord-api-types/v10"); + +// src/components/button/Button.ts +var import_v102 = require("discord-api-types/v10"); +var ButtonBuilder = class extends ComponentBuilder { + static { + __name(this, "ButtonBuilder"); + } + /** + * Creates a new button from API data. + * + * @param data - The API data to create this button with + * @example + * Creating a button from an API data object: + * ```ts + * const button = new ButtonBuilder({ + * custom_id: 'a cool button', + * style: ButtonStyle.Primary, + * label: 'Click Me', + * emoji: { + * name: 'smile', + * id: '123456789012345678', + * }, + * }); + * ``` + * @example + * Creating a button using setters and API data: + * ```ts + * const button = new ButtonBuilder({ + * style: ButtonStyle.Secondary, + * label: 'Click Me', + * }) + * .setEmoji({ name: '🙂' }) + * .setCustomId('another cool button'); + * ``` + */ + constructor(data) { + super({ type: import_v102.ComponentType.Button, ...data }); + } + /** + * Sets the style of this button. + * + * @param style - The style to use + */ + setStyle(style) { + this.data.style = buttonStyleValidator.parse(style); + return this; + } + /** + * Sets the URL for this button. + * + * @remarks + * This method is only available to buttons using the `Link` button style. + * Only three types of URL schemes are currently supported: `https://`, `http://`, and `discord://`. + * @param url - The URL to use + */ + setURL(url) { + this.data.url = urlValidator.parse(url); + return this; + } + /** + * Sets the custom id for this button. + * + * @remarks + * This method is only applicable to buttons that are not using the `Link` button style. + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Sets the emoji to display on this button. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji) { + this.data.emoji = emojiValidator.parse(emoji); + return this; + } + /** + * Sets whether this button is disabled. + * + * @param disabled - Whether to disable this button + */ + setDisabled(disabled = true) { + this.data.disabled = disabledValidator.parse(disabled); + return this; + } + /** + * Sets the label for this button. + * + * @param label - The label to use + */ + setLabel(label) { + this.data.label = buttonLabelValidator.parse(label); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + validateRequiredButtonParameters( + this.data.style, + this.data.label, + this.data.emoji, + this.data.custom_id, + this.data.url + ); + return { + ...this.data + }; + } +}; + +// src/components/selectMenu/ChannelSelectMenu.ts +var import_v103 = require("discord-api-types/v10"); + +// src/components/selectMenu/BaseSelectMenu.ts +var BaseSelectMenuBuilder = class extends ComponentBuilder { + static { + __name(this, "BaseSelectMenuBuilder"); + } + /** + * Sets the placeholder for this select menu. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder) { + this.data.placeholder = placeholderValidator.parse(placeholder); + return this; + } + /** + * Sets the minimum values that must be selected in the select menu. + * + * @param minValues - The minimum values that must be selected + */ + setMinValues(minValues) { + this.data.min_values = minMaxValidator.parse(minValues); + return this; + } + /** + * Sets the maximum values that must be selected in the select menu. + * + * @param maxValues - The maximum values that must be selected + */ + setMaxValues(maxValues) { + this.data.max_values = minMaxValidator.parse(maxValues); + return this; + } + /** + * Sets the custom id for this select menu. + * + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Sets whether this select menu is disabled. + * + * @param disabled - Whether this select menu is disabled + */ + setDisabled(disabled = true) { + this.data.disabled = disabledValidator.parse(disabled); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + customIdValidator.parse(this.data.custom_id); + return { + ...this.data + }; + } +}; + +// src/components/selectMenu/ChannelSelectMenu.ts +var ChannelSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "ChannelSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement) + * .setMinValues(2); + * ``` + */ + constructor(data) { + super({ ...data, type: import_v103.ComponentType.ChannelSelect }); + } + /** + * Adds channel types to this select menu. + * + * @param types - The channel types to use + */ + addChannelTypes(...types) { + const normalizedTypes = normalizeArray(types); + this.data.channel_types ??= []; + this.data.channel_types.push(...channelTypesValidator.parse(normalizedTypes)); + return this; + } + /** + * Sets channel types for this select menu. + * + * @param types - The channel types to use + */ + setChannelTypes(...types) { + const normalizedTypes = normalizeArray(types); + this.data.channel_types ??= []; + this.data.channel_types.splice(0, this.data.channel_types.length, ...channelTypesValidator.parse(normalizedTypes)); + return this; + } + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON() { + customIdValidator.parse(this.data.custom_id); + return { + ...this.data + }; + } +}; + +// src/components/selectMenu/MentionableSelectMenu.ts +var import_v104 = require("discord-api-types/v10"); +var MentionableSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "MentionableSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data) { + super({ ...data, type: import_v104.ComponentType.MentionableSelect }); + } +}; + +// src/components/selectMenu/RoleSelectMenu.ts +var import_v105 = require("discord-api-types/v10"); +var RoleSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "RoleSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data) { + super({ ...data, type: import_v105.ComponentType.RoleSelect }); + } +}; + +// src/components/selectMenu/StringSelectMenu.ts +var import_v106 = require("discord-api-types/v10"); +var StringSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "StringSelectMenuBuilder"); + } + /** + * The options within this select menu. + */ + options; + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * options: [ + * { label: 'option 1', value: '1' }, + * { label: 'option 2', value: '2' }, + * { label: 'option 3', value: '3' }, + * ], + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1) + * .addOptions({ + * label: 'Catchy', + * value: 'catch', + * }); + * ``` + */ + constructor(data) { + const { options, ...initData } = data ?? {}; + super({ ...initData, type: import_v106.ComponentType.StringSelect }); + this.options = options?.map((option) => new StringSelectMenuOptionBuilder(option)) ?? []; + } + /** + * Adds options to this select menu. + * + * @param options - The options to add + */ + addOptions(...options) { + const normalizedOptions = normalizeArray(options); + optionsLengthValidator.parse(this.options.length + normalizedOptions.length); + this.options.push( + ...normalizedOptions.map( + (normalizedOption) => normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)) + ) + ); + return this; + } + /** + * Sets the options for this select menu. + * + * @param options - The options to set + */ + setOptions(...options) { + return this.spliceOptions(0, this.options.length, ...options); + } + /** + * Removes, replaces, or inserts options for this select menu. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}. + * It's useful for modifying and adjusting the order of existing options. + * @example + * Remove the first option: + * ```ts + * selectMenu.spliceOptions(0, 1); + * ``` + * @example + * Remove the first n option: + * ```ts + * const n = 4; + * selectMenu.spliceOptions(0, n); + * ``` + * @example + * Remove the last option: + * ```ts + * selectMenu.spliceOptions(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of options to remove + * @param options - The replacing option objects or builders + */ + spliceOptions(index, deleteCount, ...options) { + const normalizedOptions = normalizeArray(options); + const clone = [...this.options]; + clone.splice( + index, + deleteCount, + ...normalizedOptions.map( + (normalizedOption) => normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)) + ) + ); + optionsLengthValidator.parse(clone.length); + this.options.splice(0, this.options.length, ...clone); + return this; + } + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON() { + validateRequiredSelectMenuParameters(this.options, this.data.custom_id); + return { + ...this.data, + options: this.options.map((option) => option.toJSON()) + }; + } +}; + +// src/components/selectMenu/UserSelectMenu.ts +var import_v107 = require("discord-api-types/v10"); +var UserSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "UserSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data) { + super({ ...data, type: import_v107.ComponentType.UserSelect }); + } +}; + +// src/components/textInput/TextInput.ts +var import_util = require("@discordjs/util"); +var import_v109 = require("discord-api-types/v10"); +var import_fast_deep_equal = __toESM(require("fast-deep-equal")); + +// src/components/textInput/Assertions.ts +var Assertions_exports3 = {}; +__export(Assertions_exports3, { + labelValidator: () => labelValidator, + maxLengthValidator: () => maxLengthValidator, + minLengthValidator: () => minLengthValidator, + placeholderValidator: () => placeholderValidator2, + requiredValidator: () => requiredValidator, + textInputStyleValidator: () => textInputStyleValidator, + validateRequiredParameters: () => validateRequiredParameters, + valueValidator: () => valueValidator +}); +var import_shapeshift3 = require("@sapphire/shapeshift"); +var import_v108 = require("discord-api-types/v10"); +var textInputStyleValidator = import_shapeshift3.s.nativeEnum(import_v108.TextInputStyle); +var minLengthValidator = import_shapeshift3.s.number.int.greaterThanOrEqual(0).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); +var maxLengthValidator = import_shapeshift3.s.number.int.greaterThanOrEqual(1).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); +var requiredValidator = import_shapeshift3.s.boolean; +var valueValidator = import_shapeshift3.s.string.lengthLessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); +var placeholderValidator2 = import_shapeshift3.s.string.lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var labelValidator = import_shapeshift3.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45).setValidationEnabled(isValidationEnabled); +function validateRequiredParameters(customId, style, label) { + customIdValidator.parse(customId); + textInputStyleValidator.parse(style); + labelValidator.parse(label); +} +__name(validateRequiredParameters, "validateRequiredParameters"); + +// src/components/textInput/TextInput.ts +var TextInputBuilder = class extends ComponentBuilder { + static { + __name(this, "TextInputBuilder"); + } + /** + * Creates a new text input from API data. + * + * @param data - The API data to create this text input with + * @example + * Creating a select menu option from an API data object: + * ```ts + * const textInput = new TextInputBuilder({ + * custom_id: 'a cool select menu', + * label: 'Type something', + * style: TextInputStyle.Short, + * }); + * ``` + * @example + * Creating a select menu option using setters and API data: + * ```ts + * const textInput = new TextInputBuilder({ + * label: 'Type something else', + * }) + * .setCustomId('woah') + * .setStyle(TextInputStyle.Paragraph); + * ``` + */ + constructor(data) { + super({ type: import_v109.ComponentType.TextInput, ...data }); + } + /** + * Sets the custom id for this text input. + * + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Sets the label for this text input. + * + * @param label - The label to use + */ + setLabel(label) { + this.data.label = labelValidator.parse(label); + return this; + } + /** + * Sets the style for this text input. + * + * @param style - The style to use + */ + setStyle(style) { + this.data.style = textInputStyleValidator.parse(style); + return this; + } + /** + * Sets the minimum length of text for this text input. + * + * @param minLength - The minimum length of text for this text input + */ + setMinLength(minLength) { + this.data.min_length = minLengthValidator.parse(minLength); + return this; + } + /** + * Sets the maximum length of text for this text input. + * + * @param maxLength - The maximum length of text for this text input + */ + setMaxLength(maxLength) { + this.data.max_length = maxLengthValidator.parse(maxLength); + return this; + } + /** + * Sets the placeholder for this text input. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder) { + this.data.placeholder = placeholderValidator2.parse(placeholder); + return this; + } + /** + * Sets the value for this text input. + * + * @param value - The value to use + */ + setValue(value) { + this.data.value = valueValidator.parse(value); + return this; + } + /** + * Sets whether this text input is required. + * + * @param required - Whether this text input is required + */ + setRequired(required = true) { + this.data.required = requiredValidator.parse(required); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + validateRequiredParameters(this.data.custom_id, this.data.style, this.data.label); + return { + ...this.data + }; + } + /** + * {@inheritDoc Equatable.equals} + */ + equals(other) { + if ((0, import_util.isJSONEncodable)(other)) { + return (0, import_fast_deep_equal.default)(other.toJSON(), this.data); + } + return (0, import_fast_deep_equal.default)(other, this.data); + } +}; + +// src/components/Components.ts +function createComponentBuilder(data) { + if (data instanceof ComponentBuilder) { + return data; + } + switch (data.type) { + case import_v1010.ComponentType.ActionRow: + return new ActionRowBuilder(data); + case import_v1010.ComponentType.Button: + return new ButtonBuilder(data); + case import_v1010.ComponentType.StringSelect: + return new StringSelectMenuBuilder(data); + case import_v1010.ComponentType.TextInput: + return new TextInputBuilder(data); + case import_v1010.ComponentType.UserSelect: + return new UserSelectMenuBuilder(data); + case import_v1010.ComponentType.RoleSelect: + return new RoleSelectMenuBuilder(data); + case import_v1010.ComponentType.MentionableSelect: + return new MentionableSelectMenuBuilder(data); + case import_v1010.ComponentType.ChannelSelect: + return new ChannelSelectMenuBuilder(data); + default: + throw new Error(`Cannot properly serialize component type: ${data.type}`); + } +} +__name(createComponentBuilder, "createComponentBuilder"); + +// src/components/ActionRow.ts +var ActionRowBuilder = class extends ComponentBuilder { + static { + __name(this, "ActionRowBuilder"); + } + /** + * The components within this action row. + */ + components; + /** + * Creates a new action row from API data. + * + * @param data - The API data to create this action row with + * @example + * Creating an action row from an API data object: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Type something", + * style: TextInputStyle.Short, + * type: ComponentType.TextInput, + * }, + * ], + * }); + * ``` + * @example + * Creating an action row using setters and API data: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Click me", + * style: ButtonStyle.Primary, + * type: ComponentType.Button, + * }, + * ], + * }) + * .addComponents(button2, button3); + * ``` + */ + constructor({ components, ...data } = {}) { + super({ type: import_v1011.ComponentType.ActionRow, ...data }); + this.components = components?.map((component) => createComponentBuilder(component)) ?? []; + } + /** + * Adds components to this action row. + * + * @param components - The components to add + */ + addComponents(...components) { + this.components.push(...normalizeArray(components)); + return this; + } + /** + * Sets components for this action row. + * + * @param components - The components to set + */ + setComponents(...components) { + this.components.splice(0, this.components.length, ...normalizeArray(components)); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + return { + ...this.data, + components: this.components.map((component) => component.toJSON()) + }; + } +}; + +// src/interactions/modals/Assertions.ts +var Assertions_exports4 = {}; +__export(Assertions_exports4, { + componentsValidator: () => componentsValidator, + titleValidator: () => titleValidator, + validateRequiredParameters: () => validateRequiredParameters2 +}); +var import_shapeshift4 = require("@sapphire/shapeshift"); +var titleValidator = import_shapeshift4.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45).setValidationEnabled(isValidationEnabled); +var componentsValidator = import_shapeshift4.s.instance(ActionRowBuilder).array.lengthGreaterThanOrEqual(1).setValidationEnabled(isValidationEnabled); +function validateRequiredParameters2(customId, title, components) { + customIdValidator.parse(customId); + titleValidator.parse(title); + componentsValidator.parse(components); +} +__name(validateRequiredParameters2, "validateRequiredParameters"); + +// src/interactions/modals/Modal.ts +var ModalBuilder = class { + static { + __name(this, "ModalBuilder"); + } + /** + * The API data associated with this modal. + */ + data; + /** + * The components within this modal. + */ + components = []; + /** + * Creates a new modal from API data. + * + * @param data - The API data to create this modal with + */ + constructor({ components, ...data } = {}) { + this.data = { ...data }; + this.components = components?.map((component) => createComponentBuilder(component)) ?? []; + } + /** + * Sets the title of this modal. + * + * @param title - The title to use + */ + setTitle(title) { + this.data.title = titleValidator.parse(title); + return this; + } + /** + * Sets the custom id of this modal. + * + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Adds components to this modal. + * + * @param components - The components to add + */ + addComponents(...components) { + this.components.push( + ...normalizeArray(components).map( + (component) => component instanceof ActionRowBuilder ? component : new ActionRowBuilder(component) + ) + ); + return this; + } + /** + * Sets components for this modal. + * + * @param components - The components to set + */ + setComponents(...components) { + this.components.splice(0, this.components.length, ...normalizeArray(components)); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + validateRequiredParameters2(this.data.custom_id, this.data.title, this.components); + return { + ...this.data, + components: this.components.map((component) => component.toJSON()) + }; + } +}; + +// src/interactions/slashCommands/Assertions.ts +var Assertions_exports5 = {}; +__export(Assertions_exports5, { + assertReturnOfBuilder: () => assertReturnOfBuilder, + localizationMapPredicate: () => localizationMapPredicate, + validateChoicesLength: () => validateChoicesLength, + validateDMPermission: () => validateDMPermission, + validateDefaultMemberPermissions: () => validateDefaultMemberPermissions, + validateDefaultPermission: () => validateDefaultPermission, + validateDescription: () => validateDescription, + validateLocale: () => validateLocale, + validateLocalizationMap: () => validateLocalizationMap, + validateMaxOptionsLength: () => validateMaxOptionsLength, + validateNSFW: () => validateNSFW, + validateName: () => validateName, + validateRequired: () => validateRequired, + validateRequiredParameters: () => validateRequiredParameters3 +}); +var import_shapeshift5 = require("@sapphire/shapeshift"); +var import_v1012 = require("discord-api-types/v10"); +var namePredicate = import_shapeshift5.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(32).regex(/^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u).setValidationEnabled(isValidationEnabled); +function validateName(name) { + namePredicate.parse(name); +} +__name(validateName, "validateName"); +var descriptionPredicate2 = import_shapeshift5.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var localePredicate = import_shapeshift5.s.nativeEnum(import_v1012.Locale); +function validateDescription(description) { + descriptionPredicate2.parse(description); +} +__name(validateDescription, "validateDescription"); +var maxArrayLengthPredicate = import_shapeshift5.s.unknown.array.lengthLessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateLocale(locale) { + return localePredicate.parse(locale); +} +__name(validateLocale, "validateLocale"); +function validateMaxOptionsLength(options) { + maxArrayLengthPredicate.parse(options); +} +__name(validateMaxOptionsLength, "validateMaxOptionsLength"); +function validateRequiredParameters3(name, description, options) { + validateName(name); + validateDescription(description); + validateMaxOptionsLength(options); +} +__name(validateRequiredParameters3, "validateRequiredParameters"); +var booleanPredicate = import_shapeshift5.s.boolean; +function validateDefaultPermission(value) { + booleanPredicate.parse(value); +} +__name(validateDefaultPermission, "validateDefaultPermission"); +function validateRequired(required) { + booleanPredicate.parse(required); +} +__name(validateRequired, "validateRequired"); +var choicesLengthPredicate = import_shapeshift5.s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateChoicesLength(amountAdding, choices) { + choicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding); +} +__name(validateChoicesLength, "validateChoicesLength"); +function assertReturnOfBuilder(input, ExpectedInstanceOf) { + import_shapeshift5.s.instance(ExpectedInstanceOf).parse(input); +} +__name(assertReturnOfBuilder, "assertReturnOfBuilder"); +var localizationMapPredicate = import_shapeshift5.s.object(Object.fromEntries(Object.values(import_v1012.Locale).map((locale) => [locale, import_shapeshift5.s.string.nullish]))).strict.nullish.setValidationEnabled(isValidationEnabled); +function validateLocalizationMap(value) { + localizationMapPredicate.parse(value); +} +__name(validateLocalizationMap, "validateLocalizationMap"); +var dmPermissionPredicate = import_shapeshift5.s.boolean.nullish; +function validateDMPermission(value) { + dmPermissionPredicate.parse(value); +} +__name(validateDMPermission, "validateDMPermission"); +var memberPermissionPredicate = import_shapeshift5.s.union( + import_shapeshift5.s.bigint.transform((value) => value.toString()), + import_shapeshift5.s.number.safeInt.transform((value) => value.toString()), + import_shapeshift5.s.string.regex(/^\d+$/) +).nullish; +function validateDefaultMemberPermissions(permissions) { + return memberPermissionPredicate.parse(permissions); +} +__name(validateDefaultMemberPermissions, "validateDefaultMemberPermissions"); +function validateNSFW(value) { + booleanPredicate.parse(value); +} +__name(validateNSFW, "validateNSFW"); + +// src/interactions/slashCommands/SlashCommandBuilder.ts +var import_ts_mixer6 = require("ts-mixer"); + +// src/interactions/slashCommands/SlashCommandSubcommands.ts +var import_v1024 = require("discord-api-types/v10"); +var import_ts_mixer5 = require("ts-mixer"); + +// src/interactions/slashCommands/mixins/NameAndDescription.ts +var SharedNameAndDescription = class { + static { + __name(this, "SharedNameAndDescription"); + } + /** + * The name of this command. + */ + name; + /** + * The name localizations of this command. + */ + name_localizations; + /** + * The description of this command. + */ + description; + /** + * The description localizations of this command. + */ + description_localizations; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name) { + validateName(name); + Reflect.set(this, "name", name); + return this; + } + /** + * Sets the description of this command. + * + * @param description - The description to use + */ + setDescription(description) { + validateDescription(description); + Reflect.set(this, "description", description); + return this; + } + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale, localizedName) { + if (!this.name_localizations) { + Reflect.set(this, "name_localizations", {}); + } + const parsedLocale = validateLocale(locale); + if (localizedName === null) { + this.name_localizations[parsedLocale] = null; + return this; + } + validateName(localizedName); + this.name_localizations[parsedLocale] = localizedName; + return this; + } + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames) { + if (localizedNames === null) { + Reflect.set(this, "name_localizations", null); + return this; + } + Reflect.set(this, "name_localizations", {}); + for (const args of Object.entries(localizedNames)) { + this.setNameLocalization(...args); + } + return this; + } + /** + * Sets a description localization for this command. + * + * @param locale - The locale to set + * @param localizedDescription - The localized description for the given locale + */ + setDescriptionLocalization(locale, localizedDescription) { + if (!this.description_localizations) { + Reflect.set(this, "description_localizations", {}); + } + const parsedLocale = validateLocale(locale); + if (localizedDescription === null) { + this.description_localizations[parsedLocale] = null; + return this; + } + validateDescription(localizedDescription); + this.description_localizations[parsedLocale] = localizedDescription; + return this; + } + /** + * Sets the description localizations for this command. + * + * @param localizedDescriptions - The object of localized descriptions to set + */ + setDescriptionLocalizations(localizedDescriptions) { + if (localizedDescriptions === null) { + Reflect.set(this, "description_localizations", null); + return this; + } + Reflect.set(this, "description_localizations", {}); + for (const args of Object.entries(localizedDescriptions)) { + this.setDescriptionLocalization(...args); + } + return this; + } +}; + +// src/interactions/slashCommands/options/attachment.ts +var import_v1013 = require("discord-api-types/v10"); + +// src/interactions/slashCommands/mixins/ApplicationCommandOptionBase.ts +var ApplicationCommandOptionBase = class extends SharedNameAndDescription { + static { + __name(this, "ApplicationCommandOptionBase"); + } + /** + * Whether this option is required. + * + * @defaultValue `false` + */ + required = false; + /** + * Sets whether this option is required. + * + * @param required - Whether this option should be required + */ + setRequired(required) { + validateRequired(required); + Reflect.set(this, "required", required); + return this; + } + /** + * This method runs required validators on this builder. + */ + runRequiredValidations() { + validateRequiredParameters3(this.name, this.description, []); + validateLocalizationMap(this.name_localizations); + validateLocalizationMap(this.description_localizations); + validateRequired(this.required); + } +}; + +// src/interactions/slashCommands/options/attachment.ts +var SlashCommandAttachmentOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandAttachmentOption"); + } + /** + * The type of this option. + */ + type = import_v1013.ApplicationCommandOptionType.Attachment; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/boolean.ts +var import_v1014 = require("discord-api-types/v10"); +var SlashCommandBooleanOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandBooleanOption"); + } + /** + * The type of this option. + */ + type = import_v1014.ApplicationCommandOptionType.Boolean; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/channel.ts +var import_v1016 = require("discord-api-types/v10"); +var import_ts_mixer = require("ts-mixer"); + +// src/interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.ts +var import_shapeshift6 = require("@sapphire/shapeshift"); +var import_v1015 = require("discord-api-types/v10"); +var allowedChannelTypes = [ + import_v1015.ChannelType.GuildText, + import_v1015.ChannelType.GuildVoice, + import_v1015.ChannelType.GuildCategory, + import_v1015.ChannelType.GuildAnnouncement, + import_v1015.ChannelType.AnnouncementThread, + import_v1015.ChannelType.PublicThread, + import_v1015.ChannelType.PrivateThread, + import_v1015.ChannelType.GuildStageVoice, + import_v1015.ChannelType.GuildForum +]; +var channelTypesPredicate = import_shapeshift6.s.array(import_shapeshift6.s.union(...allowedChannelTypes.map((type) => import_shapeshift6.s.literal(type)))); +var ApplicationCommandOptionChannelTypesMixin = class { + static { + __name(this, "ApplicationCommandOptionChannelTypesMixin"); + } + /** + * The channel types of this option. + */ + channel_types; + /** + * Adds channel types to this option. + * + * @param channelTypes - The channel types + */ + addChannelTypes(...channelTypes) { + if (this.channel_types === void 0) { + Reflect.set(this, "channel_types", []); + } + this.channel_types.push(...channelTypesPredicate.parse(channelTypes)); + return this; + } +}; + +// src/interactions/slashCommands/options/channel.ts +var SlashCommandChannelOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = import_v1016.ApplicationCommandOptionType.Channel; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; +__name(SlashCommandChannelOption, "SlashCommandChannelOption"); +SlashCommandChannelOption = __decorateClass([ + (0, import_ts_mixer.mix)(ApplicationCommandOptionChannelTypesMixin) +], SlashCommandChannelOption); + +// src/interactions/slashCommands/options/integer.ts +var import_shapeshift8 = require("@sapphire/shapeshift"); +var import_v1018 = require("discord-api-types/v10"); +var import_ts_mixer2 = require("ts-mixer"); + +// src/interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.ts +var ApplicationCommandNumericOptionMinMaxValueMixin = class { + static { + __name(this, "ApplicationCommandNumericOptionMinMaxValueMixin"); + } + /** + * The maximum value of this option. + */ + max_value; + /** + * The minimum value of this option. + */ + min_value; +}; + +// src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts +var import_shapeshift7 = require("@sapphire/shapeshift"); +var import_v1017 = require("discord-api-types/v10"); +var stringPredicate = import_shapeshift7.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100); +var numberPredicate = import_shapeshift7.s.number.greaterThan(Number.NEGATIVE_INFINITY).lessThan(Number.POSITIVE_INFINITY); +var choicesPredicate = import_shapeshift7.s.object({ + name: stringPredicate, + name_localizations: localizationMapPredicate, + value: import_shapeshift7.s.union(stringPredicate, numberPredicate) +}).array; +var booleanPredicate2 = import_shapeshift7.s.boolean; +var ApplicationCommandOptionWithChoicesAndAutocompleteMixin = class { + static { + __name(this, "ApplicationCommandOptionWithChoicesAndAutocompleteMixin"); + } + /** + * The choices of this option. + */ + choices; + /** + * Whether this option utilizes autocomplete. + */ + autocomplete; + /** + * The type of this option. + * + * @privateRemarks Since this is present and this is a mixin, this is needed. + */ + type; + /** + * Adds multiple choices to this option. + * + * @param choices - The choices to add + */ + addChoices(...choices) { + if (choices.length > 0 && this.autocomplete) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + choicesPredicate.parse(choices); + if (this.choices === void 0) { + Reflect.set(this, "choices", []); + } + validateChoicesLength(choices.length, this.choices); + for (const { name, name_localizations, value } of choices) { + if (this.type === import_v1017.ApplicationCommandOptionType.String) { + stringPredicate.parse(value); + } else { + numberPredicate.parse(value); + } + this.choices.push({ name, name_localizations, value }); + } + return this; + } + /** + * Sets multiple choices for this option. + * + * @param choices - The choices to set + */ + setChoices(...choices) { + if (choices.length > 0 && this.autocomplete) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + choicesPredicate.parse(choices); + Reflect.set(this, "choices", []); + this.addChoices(...choices); + return this; + } + /** + * Whether this option uses autocomplete. + * + * @param autocomplete - Whether this option should use autocomplete + */ + setAutocomplete(autocomplete) { + booleanPredicate2.parse(autocomplete); + if (autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + Reflect.set(this, "autocomplete", autocomplete); + return this; + } +}; + +// src/interactions/slashCommands/options/integer.ts +var numberValidator = import_shapeshift8.s.number.int; +var SlashCommandIntegerOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = import_v1018.ApplicationCommandOptionType.Integer; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max) { + numberValidator.parse(max); + Reflect.set(this, "max_value", max); + return this; + } + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min) { + numberValidator.parse(min); + Reflect.set(this, "min_value", min); + return this; + } + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + return { ...this }; + } +}; +__name(SlashCommandIntegerOption, "SlashCommandIntegerOption"); +SlashCommandIntegerOption = __decorateClass([ + (0, import_ts_mixer2.mix)(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin) +], SlashCommandIntegerOption); + +// src/interactions/slashCommands/options/mentionable.ts +var import_v1019 = require("discord-api-types/v10"); +var SlashCommandMentionableOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandMentionableOption"); + } + /** + * The type of this option. + */ + type = import_v1019.ApplicationCommandOptionType.Mentionable; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/number.ts +var import_shapeshift9 = require("@sapphire/shapeshift"); +var import_v1020 = require("discord-api-types/v10"); +var import_ts_mixer3 = require("ts-mixer"); +var numberValidator2 = import_shapeshift9.s.number; +var SlashCommandNumberOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = import_v1020.ApplicationCommandOptionType.Number; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max) { + numberValidator2.parse(max); + Reflect.set(this, "max_value", max); + return this; + } + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min) { + numberValidator2.parse(min); + Reflect.set(this, "min_value", min); + return this; + } + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + return { ...this }; + } +}; +__name(SlashCommandNumberOption, "SlashCommandNumberOption"); +SlashCommandNumberOption = __decorateClass([ + (0, import_ts_mixer3.mix)(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin) +], SlashCommandNumberOption); + +// src/interactions/slashCommands/options/role.ts +var import_v1021 = require("discord-api-types/v10"); +var SlashCommandRoleOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandRoleOption"); + } + /** + * The type of this option. + */ + type = import_v1021.ApplicationCommandOptionType.Role; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/string.ts +var import_shapeshift10 = require("@sapphire/shapeshift"); +var import_v1022 = require("discord-api-types/v10"); +var import_ts_mixer4 = require("ts-mixer"); +var minLengthValidator2 = import_shapeshift10.s.number.greaterThanOrEqual(0).lessThanOrEqual(6e3); +var maxLengthValidator2 = import_shapeshift10.s.number.greaterThanOrEqual(1).lessThanOrEqual(6e3); +var SlashCommandStringOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = import_v1022.ApplicationCommandOptionType.String; + /** + * The maximum length of this option. + */ + max_length; + /** + * The minimum length of this option. + */ + min_length; + /** + * Sets the maximum length of this string option. + * + * @param max - The maximum length this option can be + */ + setMaxLength(max) { + maxLengthValidator2.parse(max); + Reflect.set(this, "max_length", max); + return this; + } + /** + * Sets the minimum length of this string option. + * + * @param min - The minimum length this option can be + */ + setMinLength(min) { + minLengthValidator2.parse(min); + Reflect.set(this, "min_length", min); + return this; + } + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + return { ...this }; + } +}; +__name(SlashCommandStringOption, "SlashCommandStringOption"); +SlashCommandStringOption = __decorateClass([ + (0, import_ts_mixer4.mix)(ApplicationCommandOptionWithChoicesAndAutocompleteMixin) +], SlashCommandStringOption); + +// src/interactions/slashCommands/options/user.ts +var import_v1023 = require("discord-api-types/v10"); +var SlashCommandUserOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandUserOption"); + } + /** + * The type of this option. + */ + type = import_v1023.ApplicationCommandOptionType.User; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/mixins/SharedSlashCommandOptions.ts +var SharedSlashCommandOptions = class { + static { + __name(this, "SharedSlashCommandOptions"); + } + options; + /** + * Adds a boolean option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addBooleanOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandBooleanOption); + } + /** + * Adds a user option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addUserOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandUserOption); + } + /** + * Adds a channel option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addChannelOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandChannelOption); + } + /** + * Adds a role option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addRoleOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandRoleOption); + } + /** + * Adds an attachment option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addAttachmentOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandAttachmentOption); + } + /** + * Adds a mentionable option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addMentionableOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandMentionableOption); + } + /** + * Adds a string option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addStringOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandStringOption); + } + /** + * Adds an integer option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addIntegerOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandIntegerOption); + } + /** + * Adds a number option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addNumberOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandNumberOption); + } + /** + * Where the actual adding magic happens. ✨ + * + * @param input - The input. What else? + * @param Instance - The instance of whatever is being added + * @internal + */ + _sharedAddOptionMethod(input, Instance) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new Instance()) : input; + assertReturnOfBuilder(result, Instance); + options.push(result); + return this; + } +}; + +// src/interactions/slashCommands/SlashCommandSubcommands.ts +var SlashCommandSubcommandGroupBuilder = class { + /** + * The name of this subcommand group. + */ + name = void 0; + /** + * The description of this subcommand group. + */ + description = void 0; + /** + * The subcommands within this subcommand group. + */ + options = []; + /** + * Adds a new subcommand to this group. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new SlashCommandSubcommandBuilder()) : input; + assertReturnOfBuilder(result, SlashCommandSubcommandBuilder); + options.push(result); + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters3(this.name, this.description, this.options); + return { + type: import_v1024.ApplicationCommandOptionType.SubcommandGroup, + name: this.name, + name_localizations: this.name_localizations, + description: this.description, + description_localizations: this.description_localizations, + options: this.options.map((option) => option.toJSON()) + }; + } +}; +__name(SlashCommandSubcommandGroupBuilder, "SlashCommandSubcommandGroupBuilder"); +SlashCommandSubcommandGroupBuilder = __decorateClass([ + (0, import_ts_mixer5.mix)(SharedNameAndDescription) +], SlashCommandSubcommandGroupBuilder); +var SlashCommandSubcommandBuilder = class { + /** + * The name of this subcommand. + */ + name = void 0; + /** + * The description of this subcommand. + */ + description = void 0; + /** + * The options within this subcommand. + */ + options = []; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters3(this.name, this.description, this.options); + return { + type: import_v1024.ApplicationCommandOptionType.Subcommand, + name: this.name, + name_localizations: this.name_localizations, + description: this.description, + description_localizations: this.description_localizations, + options: this.options.map((option) => option.toJSON()) + }; + } +}; +__name(SlashCommandSubcommandBuilder, "SlashCommandSubcommandBuilder"); +SlashCommandSubcommandBuilder = __decorateClass([ + (0, import_ts_mixer5.mix)(SharedNameAndDescription, SharedSlashCommandOptions) +], SlashCommandSubcommandBuilder); + +// src/interactions/slashCommands/SlashCommandBuilder.ts +var SlashCommandBuilder = class { + /** + * The name of this command. + */ + name = void 0; + /** + * The name localizations of this command. + */ + name_localizations; + /** + * The description of this command. + */ + description = void 0; + /** + * The description localizations of this command. + */ + description_localizations; + /** + * The options of this command. + */ + options = []; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + default_permission = void 0; + /** + * The set of permissions represented as a bit set for the command. + */ + default_member_permissions = void 0; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + dm_permission = void 0; + /** + * Whether this command is NSFW. + */ + nsfw = void 0; + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether or not to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value) { + validateDefaultPermission(value); + Reflect.set(this, "default_permission", value); + return this; + } + /** + * Sets the default permissions a member should have in order to run the command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions) { + const permissionValue = validateDefaultMemberPermissions(permissions); + Reflect.set(this, "default_member_permissions", permissionValue); + return this; + } + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled) { + validateDMPermission(enabled); + Reflect.set(this, "dm_permission", enabled); + return this; + } + /** + * Sets whether this command is NSFW. + * + * @param nsfw - Whether this command is NSFW + */ + setNSFW(nsfw = true) { + validateNSFW(nsfw); + Reflect.set(this, "nsfw", nsfw); + return this; + } + /** + * Adds a new subcommand group to this command. + * + * @param input - A function that returns a subcommand group builder or an already built builder + */ + addSubcommandGroup(input) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new SlashCommandSubcommandGroupBuilder()) : input; + assertReturnOfBuilder(result, SlashCommandSubcommandGroupBuilder); + options.push(result); + return this; + } + /** + * Adds a new subcommand to this command. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new SlashCommandSubcommandBuilder()) : input; + assertReturnOfBuilder(result, SlashCommandSubcommandBuilder); + options.push(result); + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters3(this.name, this.description, this.options); + validateLocalizationMap(this.name_localizations); + validateLocalizationMap(this.description_localizations); + return { + ...this, + options: this.options.map((option) => option.toJSON()) + }; + } +}; +__name(SlashCommandBuilder, "SlashCommandBuilder"); +SlashCommandBuilder = __decorateClass([ + (0, import_ts_mixer6.mix)(SharedSlashCommandOptions, SharedNameAndDescription) +], SlashCommandBuilder); + +// src/interactions/contextMenuCommands/Assertions.ts +var Assertions_exports6 = {}; +__export(Assertions_exports6, { + validateDMPermission: () => validateDMPermission2, + validateDefaultMemberPermissions: () => validateDefaultMemberPermissions2, + validateDefaultPermission: () => validateDefaultPermission2, + validateName: () => validateName2, + validateRequiredParameters: () => validateRequiredParameters4, + validateType: () => validateType +}); +var import_shapeshift11 = require("@sapphire/shapeshift"); +var import_v1025 = require("discord-api-types/v10"); +var namePredicate2 = import_shapeshift11.s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(32).regex(/^( *[\p{P}\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}]+ *)+$/u).setValidationEnabled(isValidationEnabled); +var typePredicate = import_shapeshift11.s.union(import_shapeshift11.s.literal(import_v1025.ApplicationCommandType.User), import_shapeshift11.s.literal(import_v1025.ApplicationCommandType.Message)).setValidationEnabled(isValidationEnabled); +var booleanPredicate3 = import_shapeshift11.s.boolean; +function validateDefaultPermission2(value) { + booleanPredicate3.parse(value); +} +__name(validateDefaultPermission2, "validateDefaultPermission"); +function validateName2(name) { + namePredicate2.parse(name); +} +__name(validateName2, "validateName"); +function validateType(type) { + typePredicate.parse(type); +} +__name(validateType, "validateType"); +function validateRequiredParameters4(name, type) { + validateName2(name); + validateType(type); +} +__name(validateRequiredParameters4, "validateRequiredParameters"); +var dmPermissionPredicate2 = import_shapeshift11.s.boolean.nullish; +function validateDMPermission2(value) { + dmPermissionPredicate2.parse(value); +} +__name(validateDMPermission2, "validateDMPermission"); +var memberPermissionPredicate2 = import_shapeshift11.s.union( + import_shapeshift11.s.bigint.transform((value) => value.toString()), + import_shapeshift11.s.number.safeInt.transform((value) => value.toString()), + import_shapeshift11.s.string.regex(/^\d+$/) +).nullish; +function validateDefaultMemberPermissions2(permissions) { + return memberPermissionPredicate2.parse(permissions); +} +__name(validateDefaultMemberPermissions2, "validateDefaultMemberPermissions"); + +// src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts +var ContextMenuCommandBuilder = class { + static { + __name(this, "ContextMenuCommandBuilder"); + } + /** + * The name of this command. + */ + name = void 0; + /** + * The name localizations of this command. + */ + name_localizations; + /** + * The type of this command. + */ + type = void 0; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + default_permission = void 0; + /** + * The set of permissions represented as a bit set for the command. + */ + default_member_permissions = void 0; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + dm_permission = void 0; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name) { + validateName2(name); + Reflect.set(this, "name", name); + return this; + } + /** + * Sets the type of this command. + * + * @param type - The type to use + */ + setType(type) { + validateType(type); + Reflect.set(this, "type", type); + return this; + } + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value) { + validateDefaultPermission2(value); + Reflect.set(this, "default_permission", value); + return this; + } + /** + * Sets the default permissions a member should have in order to run this command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions) { + const permissionValue = validateDefaultMemberPermissions2(permissions); + Reflect.set(this, "default_member_permissions", permissionValue); + return this; + } + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled) { + validateDMPermission2(enabled); + Reflect.set(this, "dm_permission", enabled); + return this; + } + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale, localizedName) { + if (!this.name_localizations) { + Reflect.set(this, "name_localizations", {}); + } + const parsedLocale = validateLocale(locale); + if (localizedName === null) { + this.name_localizations[parsedLocale] = null; + return this; + } + validateName2(localizedName); + this.name_localizations[parsedLocale] = localizedName; + return this; + } + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames) { + if (localizedNames === null) { + Reflect.set(this, "name_localizations", null); + return this; + } + Reflect.set(this, "name_localizations", {}); + for (const args of Object.entries(localizedNames)) + this.setNameLocalization(...args); + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters4(this.name, this.type); + validateLocalizationMap(this.name_localizations); + return { ...this }; + } +}; + +// src/util/componentUtil.ts +function embedLength(data) { + return (data.title?.length ?? 0) + (data.description?.length ?? 0) + (data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) + (data.footer?.text.length ?? 0) + (data.author?.name.length ?? 0); +} +__name(embedLength, "embedLength"); + +// src/index.ts +var version = "1.6.5"; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + ActionRowBuilder, + ApplicationCommandNumericOptionMinMaxValueMixin, + ApplicationCommandOptionBase, + ApplicationCommandOptionChannelTypesMixin, + ApplicationCommandOptionWithChoicesAndAutocompleteMixin, + BaseSelectMenuBuilder, + ButtonBuilder, + ChannelSelectMenuBuilder, + ComponentAssertions, + ComponentBuilder, + ContextMenuCommandAssertions, + ContextMenuCommandBuilder, + EmbedAssertions, + EmbedBuilder, + MentionableSelectMenuBuilder, + ModalAssertions, + ModalBuilder, + RoleSelectMenuBuilder, + SelectMenuBuilder, + SelectMenuOptionBuilder, + SharedNameAndDescription, + SharedSlashCommandOptions, + SlashCommandAssertions, + SlashCommandAttachmentOption, + SlashCommandBooleanOption, + SlashCommandBuilder, + SlashCommandChannelOption, + SlashCommandIntegerOption, + SlashCommandMentionableOption, + SlashCommandNumberOption, + SlashCommandRoleOption, + SlashCommandStringOption, + SlashCommandSubcommandBuilder, + SlashCommandSubcommandGroupBuilder, + SlashCommandUserOption, + StringSelectMenuBuilder, + StringSelectMenuOptionBuilder, + TextInputAssertions, + TextInputBuilder, + UserSelectMenuBuilder, + createComponentBuilder, + disableValidators, + embedLength, + enableValidators, + isValidationEnabled, + normalizeArray, + version, + ...require("@discordjs/formatters") +}); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/builders/dist/index.js.map b/node_modules/@discordjs/builders/dist/index.js.map new file mode 100644 index 0000000..53cf1bf --- /dev/null +++ b/node_modules/@discordjs/builders/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/messages/embed/Assertions.ts","../src/util/validation.ts","../src/util/normalizeArray.ts","../src/messages/embed/Embed.ts","../src/components/Assertions.ts","../src/components/selectMenu/StringSelectMenuOption.ts","../src/components/ActionRow.ts","../src/components/Component.ts","../src/components/Components.ts","../src/components/button/Button.ts","../src/components/selectMenu/ChannelSelectMenu.ts","../src/components/selectMenu/BaseSelectMenu.ts","../src/components/selectMenu/MentionableSelectMenu.ts","../src/components/selectMenu/RoleSelectMenu.ts","../src/components/selectMenu/StringSelectMenu.ts","../src/components/selectMenu/UserSelectMenu.ts","../src/components/textInput/TextInput.ts","../src/components/textInput/Assertions.ts","../src/interactions/modals/Assertions.ts","../src/interactions/modals/Modal.ts","../src/interactions/slashCommands/Assertions.ts","../src/interactions/slashCommands/SlashCommandBuilder.ts","../src/interactions/slashCommands/SlashCommandSubcommands.ts","../src/interactions/slashCommands/mixins/NameAndDescription.ts","../src/interactions/slashCommands/options/attachment.ts","../src/interactions/slashCommands/mixins/ApplicationCommandOptionBase.ts","../src/interactions/slashCommands/options/boolean.ts","../src/interactions/slashCommands/options/channel.ts","../src/interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.ts","../src/interactions/slashCommands/options/integer.ts","../src/interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.ts","../src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts","../src/interactions/slashCommands/options/mentionable.ts","../src/interactions/slashCommands/options/number.ts","../src/interactions/slashCommands/options/role.ts","../src/interactions/slashCommands/options/string.ts","../src/interactions/slashCommands/options/user.ts","../src/interactions/slashCommands/mixins/SharedSlashCommandOptions.ts","../src/interactions/contextMenuCommands/Assertions.ts","../src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts","../src/util/componentUtil.ts"],"sourcesContent":["export * as EmbedAssertions from './messages/embed/Assertions.js';\nexport * from './messages/embed/Embed.js';\n// TODO: Consider removing this dep in the next major version\nexport * from '@discordjs/formatters';\n\nexport * as ComponentAssertions from './components/Assertions.js';\nexport * from './components/ActionRow.js';\nexport * from './components/button/Button.js';\nexport * from './components/Component.js';\nexport * from './components/Components.js';\nexport * from './components/textInput/TextInput.js';\nexport * as TextInputAssertions from './components/textInput/Assertions.js';\nexport * from './interactions/modals/Modal.js';\nexport * as ModalAssertions from './interactions/modals/Assertions.js';\n\nexport * from './components/selectMenu/BaseSelectMenu.js';\nexport * from './components/selectMenu/ChannelSelectMenu.js';\nexport * from './components/selectMenu/MentionableSelectMenu.js';\nexport * from './components/selectMenu/RoleSelectMenu.js';\nexport * from './components/selectMenu/StringSelectMenu.js';\n// TODO: Remove those aliases in v2\nexport {\n\t/**\n\t * @deprecated Will be removed in the next major version, use {@link StringSelectMenuBuilder} instead.\n\t */\n\tStringSelectMenuBuilder as SelectMenuBuilder,\n} from './components/selectMenu/StringSelectMenu.js';\nexport {\n\t/**\n\t * @deprecated Will be removed in the next major version, use {@link StringSelectMenuOptionBuilder} instead.\n\t */\n\tStringSelectMenuOptionBuilder as SelectMenuOptionBuilder,\n} from './components/selectMenu/StringSelectMenuOption.js';\nexport * from './components/selectMenu/StringSelectMenuOption.js';\nexport * from './components/selectMenu/UserSelectMenu.js';\n\nexport * as SlashCommandAssertions from './interactions/slashCommands/Assertions.js';\nexport * from './interactions/slashCommands/SlashCommandBuilder.js';\nexport * from './interactions/slashCommands/SlashCommandSubcommands.js';\nexport * from './interactions/slashCommands/options/boolean.js';\nexport * from './interactions/slashCommands/options/channel.js';\nexport * from './interactions/slashCommands/options/integer.js';\nexport * from './interactions/slashCommands/options/mentionable.js';\nexport * from './interactions/slashCommands/options/number.js';\nexport * from './interactions/slashCommands/options/role.js';\nexport * from './interactions/slashCommands/options/attachment.js';\nexport * from './interactions/slashCommands/options/string.js';\nexport * from './interactions/slashCommands/options/user.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandOptionBase.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\nexport * from './interactions/slashCommands/mixins/NameAndDescription.js';\nexport * from './interactions/slashCommands/mixins/SharedSlashCommandOptions.js';\n\nexport * as ContextMenuCommandAssertions from './interactions/contextMenuCommands/Assertions.js';\nexport * from './interactions/contextMenuCommands/ContextMenuCommandBuilder.js';\n\nexport * from './util/componentUtil.js';\nexport * from './util/normalizeArray.js';\nexport * from './util/validation.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/builders#readme | @discordjs/builders} version\n * that you are currently using.\n *\n * @privateRemarks This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild.\n */\nexport const version = '1.6.5' as string;\n","import { s } from '@sapphire/shapeshift';\nimport type { APIEmbedField } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\n\nexport const fieldNamePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(256)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const fieldValuePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(1_024)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const fieldInlinePredicate = s.boolean.optional;\n\nexport const embedFieldPredicate = s\n\t.object({\n\t\tname: fieldNamePredicate,\n\t\tvalue: fieldValuePredicate,\n\t\tinline: fieldInlinePredicate,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const embedFieldsArrayPredicate = embedFieldPredicate.array.setValidationEnabled(isValidationEnabled);\n\nexport const fieldLengthPredicate = s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled);\n\nexport function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void {\n\tfieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding);\n}\n\nexport const authorNamePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const imageURLPredicate = s.string\n\t.url({\n\t\tallowedProtocols: ['http:', 'https:', 'attachment:'],\n\t})\n\t.nullish.setValidationEnabled(isValidationEnabled);\n\nexport const urlPredicate = s.string\n\t.url({\n\t\tallowedProtocols: ['http:', 'https:'],\n\t})\n\t.nullish.setValidationEnabled(isValidationEnabled);\n\nexport const embedAuthorPredicate = s\n\t.object({\n\t\tname: authorNamePredicate,\n\t\ticonURL: imageURLPredicate,\n\t\turl: urlPredicate,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const RGBPredicate = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(255)\n\t.setValidationEnabled(isValidationEnabled);\nexport const colorPredicate = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(0xffffff)\n\t.or(s.tuple([RGBPredicate, RGBPredicate, RGBPredicate]))\n\t.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const descriptionPredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(4_096)\n\t.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const footerTextPredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(2_048)\n\t.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const embedFooterPredicate = s\n\t.object({\n\t\ttext: footerTextPredicate,\n\t\ticonURL: imageURLPredicate,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const timestampPredicate = s.union(s.number, s.date).nullable.setValidationEnabled(isValidationEnabled);\n\nexport const titlePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled);\n","let validate = true;\n\n/**\n * Enables validators.\n *\n * @returns Whether validation is occurring.\n */\nexport function enableValidators() {\n\treturn (validate = true);\n}\n\n/**\n * Disables validators.\n *\n * @returns Whether validation is occurring.\n */\nexport function disableValidators() {\n\treturn (validate = false);\n}\n\n/**\n * Checks whether validation is occurring.\n */\nexport function isValidationEnabled() {\n\treturn validate;\n}\n","/**\n * Normalizes data that is a rest parameter or an array into an array with a depth of 1.\n *\n * @typeParam T - The data that must satisfy {@link RestOrArray}.\n * @param arr - The (possibly variadic) data to normalize\n */\nexport function normalizeArray<T>(arr: RestOrArray<T>): T[] {\n\tif (Array.isArray(arr[0])) return arr[0];\n\treturn arr as T[];\n}\n\n/**\n * Represents data that may be an array or came from a rest parameter.\n *\n * @remarks\n * This type is used throughout builders to ensure both an array and variadic arguments\n * may be used. It is normalized with {@link normalizeArray}.\n */\nexport type RestOrArray<T> = T[] | [T[]];\n","import type { APIEmbed, APIEmbedAuthor, APIEmbedField, APIEmbedFooter, APIEmbedImage } from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport {\n\tcolorPredicate,\n\tdescriptionPredicate,\n\tembedAuthorPredicate,\n\tembedFieldsArrayPredicate,\n\tembedFooterPredicate,\n\timageURLPredicate,\n\ttimestampPredicate,\n\ttitlePredicate,\n\turlPredicate,\n\tvalidateFieldLength,\n} from './Assertions.js';\n\n/**\n * A tuple satisfying the RGB color model.\n *\n * @see {@link https://developer.mozilla.org/docs/Glossary/RGB}\n */\nexport type RGBTuple = [red: number, green: number, blue: number];\n\n/**\n * The base icon data typically used in payloads.\n */\nexport interface IconData {\n\t/**\n\t * The URL of the icon.\n\t */\n\ticonURL?: string;\n\t/**\n\t * The proxy URL of the icon.\n\t */\n\tproxyIconURL?: string;\n}\n\n/**\n * Represents the author data of an embed.\n */\nexport type EmbedAuthorData = IconData & Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'>;\n\n/**\n * Represents the author options of an embed.\n */\nexport type EmbedAuthorOptions = Omit<EmbedAuthorData, 'proxyIconURL'>;\n\n/**\n * Represents the footer data of an embed.\n */\nexport type EmbedFooterData = IconData & Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'>;\n\n/**\n * Represents the footer options of an embed.\n */\nexport type EmbedFooterOptions = Omit<EmbedFooterData, 'proxyIconURL'>;\n\n/**\n * Represents the image data of an embed.\n */\nexport interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> {\n\t/**\n\t * The proxy URL for the image.\n\t */\n\tproxyURL?: string;\n}\n\n/**\n * A builder that creates API-compatible JSON data for embeds.\n */\nexport class EmbedBuilder {\n\t/**\n\t * The API data associated with this embed.\n\t */\n\tpublic readonly data: APIEmbed;\n\n\t/**\n\t * Creates a new embed from API data.\n\t *\n\t * @param data - The API data to create this embed with\n\t */\n\tpublic constructor(data: APIEmbed = {}) {\n\t\tthis.data = { ...data };\n\t\tif (data.timestamp) this.data.timestamp = new Date(data.timestamp).toISOString();\n\t}\n\n\t/**\n\t * Appends fields to the embed.\n\t *\n\t * @remarks\n\t * This method accepts either an array of fields or a variable number of field parameters.\n\t * The maximum amount of fields that can be added is 25.\n\t * @example\n\t * Using an array:\n\t * ```ts\n\t * const fields: APIEmbedField[] = ...;\n\t * const embed = new EmbedBuilder()\n\t * \t.addFields(fields);\n\t * ```\n\t * @example\n\t * Using rest parameters (variadic):\n\t * ```ts\n\t * const embed = new EmbedBuilder()\n\t * \t.addFields(\n\t * \t\t{ name: 'Field 1', value: 'Value 1' },\n\t * \t\t{ name: 'Field 2', value: 'Value 2' },\n\t * \t);\n\t * ```\n\t * @param fields - The fields to add\n\t */\n\tpublic addFields(...fields: RestOrArray<APIEmbedField>): this {\n\t\tconst normalizedFields = normalizeArray(fields);\n\t\t// Ensure adding these fields won't exceed the 25 field limit\n\t\tvalidateFieldLength(normalizedFields.length, this.data.fields);\n\n\t\t// Data assertions\n\t\tembedFieldsArrayPredicate.parse(normalizedFields);\n\n\t\tif (this.data.fields) this.data.fields.push(...normalizedFields);\n\t\telse this.data.fields = normalizedFields;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes, replaces, or inserts fields for this embed.\n\t *\n\t * @remarks\n\t * This method behaves similarly\n\t * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.\n\t * The maximum amount of fields that can be added is 25.\n\t *\n\t * It's useful for modifying and adjusting order of the already-existing fields of an embed.\n\t * @example\n\t * Remove the first field:\n\t * ```ts\n\t * embed.spliceFields(0, 1);\n\t * ```\n\t * @example\n\t * Remove the first n fields:\n\t * ```ts\n\t * const n = 4;\n\t * embed.spliceFields(0, n);\n\t * ```\n\t * @example\n\t * Remove the last field:\n\t * ```ts\n\t * embed.spliceFields(-1, 1);\n\t * ```\n\t * @param index - The index to start at\n\t * @param deleteCount - The number of fields to remove\n\t * @param fields - The replacing field objects\n\t */\n\tpublic spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this {\n\t\t// Ensure adding these fields won't exceed the 25 field limit\n\t\tvalidateFieldLength(fields.length - deleteCount, this.data.fields);\n\n\t\t// Data assertions\n\t\tembedFieldsArrayPredicate.parse(fields);\n\t\tif (this.data.fields) this.data.fields.splice(index, deleteCount, ...fields);\n\t\telse this.data.fields = fields;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the fields for this embed.\n\t *\n\t * @remarks\n\t * This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically,\n\t * it splices the entire array of fields, replacing them with the provided fields.\n\t *\n\t * You can set a maximum of 25 fields.\n\t * @param fields - The fields to set\n\t */\n\tpublic setFields(...fields: RestOrArray<APIEmbedField>) {\n\t\tthis.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the author of this embed.\n\t *\n\t * @param options - The options to use\n\t */\n\n\tpublic setAuthor(options: EmbedAuthorOptions | null): this {\n\t\tif (options === null) {\n\t\t\tthis.data.author = undefined;\n\t\t\treturn this;\n\t\t}\n\n\t\t// Data assertions\n\t\tembedAuthorPredicate.parse(options);\n\n\t\tthis.data.author = { name: options.name, url: options.url, icon_url: options.iconURL };\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the color of this embed.\n\t *\n\t * @param color - The color to use\n\t */\n\tpublic setColor(color: RGBTuple | number | null): this {\n\t\t// Data assertions\n\t\tcolorPredicate.parse(color);\n\n\t\tif (Array.isArray(color)) {\n\t\t\tconst [red, green, blue] = color;\n\t\t\tthis.data.color = (red << 16) + (green << 8) + blue;\n\t\t\treturn this;\n\t\t}\n\n\t\tthis.data.color = color ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description of this embed.\n\t *\n\t * @param description - The description to use\n\t */\n\tpublic setDescription(description: string | null): this {\n\t\t// Data assertions\n\t\tdescriptionPredicate.parse(description);\n\n\t\tthis.data.description = description ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the footer of this embed.\n\t *\n\t * @param options - The footer to use\n\t */\n\tpublic setFooter(options: EmbedFooterOptions | null): this {\n\t\tif (options === null) {\n\t\t\tthis.data.footer = undefined;\n\t\t\treturn this;\n\t\t}\n\n\t\t// Data assertions\n\t\tembedFooterPredicate.parse(options);\n\n\t\tthis.data.footer = { text: options.text, icon_url: options.iconURL };\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the image of this embed.\n\t *\n\t * @param url - The image URL to use\n\t */\n\tpublic setImage(url: string | null): this {\n\t\t// Data assertions\n\t\timageURLPredicate.parse(url);\n\n\t\tthis.data.image = url ? { url } : undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the thumbnail of this embed.\n\t *\n\t * @param url - The thumbnail URL to use\n\t */\n\tpublic setThumbnail(url: string | null): this {\n\t\t// Data assertions\n\t\timageURLPredicate.parse(url);\n\n\t\tthis.data.thumbnail = url ? { url } : undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the timestamp of this embed.\n\t *\n\t * @param timestamp - The timestamp or date to use\n\t */\n\tpublic setTimestamp(timestamp: Date | number | null = Date.now()): this {\n\t\t// Data assertions\n\t\ttimestampPredicate.parse(timestamp);\n\n\t\tthis.data.timestamp = timestamp ? new Date(timestamp).toISOString() : undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the title for this embed.\n\t *\n\t * @param title - The title to use\n\t */\n\tpublic setTitle(title: string | null): this {\n\t\t// Data assertions\n\t\ttitlePredicate.parse(title);\n\n\t\tthis.data.title = title ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the URL of this embed.\n\t *\n\t * @param url - The URL to use\n\t */\n\tpublic setURL(url: string | null): this {\n\t\t// Data assertions\n\t\turlPredicate.parse(url);\n\n\t\tthis.data.url = url ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): APIEmbed {\n\t\treturn { ...this.data };\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ButtonStyle, ChannelType, type APIMessageComponentEmoji } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../util/validation.js';\nimport { StringSelectMenuOptionBuilder } from './selectMenu/StringSelectMenuOption.js';\n\nexport const customIdValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(100)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const emojiValidator = s\n\t.object({\n\t\tid: s.string,\n\t\tname: s.string,\n\t\tanimated: s.boolean,\n\t})\n\t.partial.strict.setValidationEnabled(isValidationEnabled);\n\nexport const disabledValidator = s.boolean;\n\nexport const buttonLabelValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(80)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const buttonStyleValidator = s.nativeEnum(ButtonStyle);\n\nexport const placeholderValidator = s.string.lengthLessThanOrEqual(150).setValidationEnabled(isValidationEnabled);\nexport const minMaxValidator = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(25)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const labelValueDescriptionValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(100)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const jsonOptionValidator = s\n\t.object({\n\t\tlabel: labelValueDescriptionValidator,\n\t\tvalue: labelValueDescriptionValidator,\n\t\tdescription: labelValueDescriptionValidator.optional,\n\t\temoji: emojiValidator.optional,\n\t\tdefault: s.boolean.optional,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const optionValidator = s.instance(StringSelectMenuOptionBuilder).setValidationEnabled(isValidationEnabled);\n\nexport const optionsValidator = optionValidator.array\n\t.lengthGreaterThanOrEqual(0)\n\t.setValidationEnabled(isValidationEnabled);\nexport const optionsLengthValidator = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(25)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredSelectMenuParameters(options: StringSelectMenuOptionBuilder[], customId?: string) {\n\tcustomIdValidator.parse(customId);\n\toptionsValidator.parse(options);\n}\n\nexport const defaultValidator = s.boolean;\n\nexport function validateRequiredSelectMenuOptionParameters(label?: string, value?: string) {\n\tlabelValueDescriptionValidator.parse(label);\n\tlabelValueDescriptionValidator.parse(value);\n}\n\nexport const channelTypesValidator = s.nativeEnum(ChannelType).array.setValidationEnabled(isValidationEnabled);\n\nexport const urlValidator = s.string\n\t.url({\n\t\tallowedProtocols: ['http:', 'https:', 'discord:'],\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredButtonParameters(\n\tstyle?: ButtonStyle,\n\tlabel?: string,\n\temoji?: APIMessageComponentEmoji,\n\tcustomId?: string,\n\turl?: string,\n) {\n\tif (url && customId) {\n\t\tthrow new RangeError('URL and custom id are mutually exclusive');\n\t}\n\n\tif (!label && !emoji) {\n\t\tthrow new RangeError('Buttons must have a label and/or an emoji');\n\t}\n\n\tif (style === ButtonStyle.Link) {\n\t\tif (!url) {\n\t\t\tthrow new RangeError('Link buttons must have a url');\n\t\t}\n\t} else if (url) {\n\t\tthrow new RangeError('Non-link buttons cannot have a url');\n\t}\n}\n","import type { JSONEncodable } from '@discordjs/util';\nimport type { APIMessageComponentEmoji, APISelectMenuOption } from 'discord-api-types/v10';\nimport {\n\tdefaultValidator,\n\temojiValidator,\n\tlabelValueDescriptionValidator,\n\tvalidateRequiredSelectMenuOptionParameters,\n} from '../Assertions.js';\n\n/**\n * A builder that creates API-compatible JSON data for string select menu options.\n */\nexport class StringSelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {\n\t/**\n\t * Creates a new string select menu option from API data.\n\t *\n\t * @param data - The API data to create this string select menu option with\n\t * @example\n\t * Creating a string select menu option from an API data object:\n\t * ```ts\n\t * const selectMenuOption = new SelectMenuOptionBuilder({\n\t * \tlabel: 'catchy label',\n\t * \tvalue: '1',\n\t * });\n\t * ```\n\t * @example\n\t * Creating a string select menu option using setters and API data:\n\t * ```ts\n\t * const selectMenuOption = new SelectMenuOptionBuilder({\n\t * \tdefault: true,\n\t * \tvalue: '1',\n\t * })\n\t * \t.setLabel('woah');\n\t * ```\n\t */\n\tpublic constructor(public data: Partial<APISelectMenuOption> = {}) {}\n\n\t/**\n\t * Sets the label for this option.\n\t *\n\t * @param label - The label to use\n\t */\n\tpublic setLabel(label: string) {\n\t\tthis.data.label = labelValueDescriptionValidator.parse(label);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the value for this option.\n\t *\n\t * @param value - The value to use\n\t */\n\tpublic setValue(value: string) {\n\t\tthis.data.value = labelValueDescriptionValidator.parse(value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description for this option.\n\t *\n\t * @param description - The description to use\n\t */\n\tpublic setDescription(description: string) {\n\t\tthis.data.description = labelValueDescriptionValidator.parse(description);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this option is selected by default.\n\t *\n\t * @param isDefault - Whether this option is selected by default\n\t */\n\tpublic setDefault(isDefault = true) {\n\t\tthis.data.default = defaultValidator.parse(isDefault);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the emoji to display for this option.\n\t *\n\t * @param emoji - The emoji to use\n\t */\n\tpublic setEmoji(emoji: APIMessageComponentEmoji) {\n\t\tthis.data.emoji = emojiValidator.parse(emoji);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc BaseSelectMenuBuilder.toJSON}\n\t */\n\tpublic toJSON(): APISelectMenuOption {\n\t\tvalidateRequiredSelectMenuOptionParameters(this.data.label, this.data.value);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APISelectMenuOption;\n\t}\n}\n","/* eslint-disable jsdoc/check-param-names */\n\nimport {\n\ttype APIActionRowComponent,\n\tComponentType,\n\ttype APIMessageActionRowComponent,\n\ttype APIModalActionRowComponent,\n\ttype APIActionRowComponentTypes,\n} from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../util/normalizeArray.js';\nimport { ComponentBuilder } from './Component.js';\nimport { createComponentBuilder } from './Components.js';\nimport type { ButtonBuilder } from './button/Button.js';\nimport type { ChannelSelectMenuBuilder } from './selectMenu/ChannelSelectMenu.js';\nimport type { MentionableSelectMenuBuilder } from './selectMenu/MentionableSelectMenu.js';\nimport type { RoleSelectMenuBuilder } from './selectMenu/RoleSelectMenu.js';\nimport type { StringSelectMenuBuilder } from './selectMenu/StringSelectMenu.js';\nimport type { UserSelectMenuBuilder } from './selectMenu/UserSelectMenu.js';\nimport type { TextInputBuilder } from './textInput/TextInput.js';\n\n/**\n * The builders that may be used for messages.\n */\nexport type MessageComponentBuilder =\n\t| ActionRowBuilder<MessageActionRowComponentBuilder>\n\t| MessageActionRowComponentBuilder;\n\n/**\n * The builders that may be used for modals.\n */\nexport type ModalComponentBuilder = ActionRowBuilder<ModalActionRowComponentBuilder> | ModalActionRowComponentBuilder;\n\n/**\n * The builders that may be used within an action row for messages.\n */\nexport type MessageActionRowComponentBuilder =\n\t| ButtonBuilder\n\t| ChannelSelectMenuBuilder\n\t| MentionableSelectMenuBuilder\n\t| RoleSelectMenuBuilder\n\t| StringSelectMenuBuilder\n\t| UserSelectMenuBuilder;\n\n/**\n * The builders that may be used within an action row for modals.\n */\nexport type ModalActionRowComponentBuilder = TextInputBuilder;\n\n/**\n * Any builder.\n */\nexport type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalActionRowComponentBuilder;\n\n/**\n * A builder that creates API-compatible JSON data for action rows.\n *\n * @typeParam T - The types of components this action row holds\n */\nexport class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<\n\tAPIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>\n> {\n\t/**\n\t * The components within this action row.\n\t */\n\tpublic readonly components: T[];\n\n\t/**\n\t * Creates a new action row from API data.\n\t *\n\t * @param data - The API data to create this action row with\n\t * @example\n\t * Creating an action row from an API data object:\n\t * ```ts\n\t * const actionRow = new ActionRowBuilder({\n\t * \tcomponents: [\n\t * \t\t{\n\t * \t\t\tcustom_id: \"custom id\",\n\t * \t\t\tlabel: \"Type something\",\n\t * \t\t\tstyle: TextInputStyle.Short,\n\t * \t\t\ttype: ComponentType.TextInput,\n\t * \t\t},\n\t * \t],\n\t * });\n\t * ```\n\t * @example\n\t * Creating an action row using setters and API data:\n\t * ```ts\n\t * const actionRow = new ActionRowBuilder({\n\t * \tcomponents: [\n\t * \t\t{\n\t * \t\t\tcustom_id: \"custom id\",\n\t * \t\t\tlabel: \"Click me\",\n\t * \t\t\tstyle: ButtonStyle.Primary,\n\t * \t\t\ttype: ComponentType.Button,\n\t * \t\t},\n\t * \t],\n\t * })\n\t * \t.addComponents(button2, button3);\n\t * ```\n\t */\n\tpublic constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {\n\t\tsuper({ type: ComponentType.ActionRow, ...data });\n\t\tthis.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];\n\t}\n\n\t/**\n\t * Adds components to this action row.\n\t *\n\t * @param components - The components to add\n\t */\n\tpublic addComponents(...components: RestOrArray<T>) {\n\t\tthis.components.push(...normalizeArray(components));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets components for this action row.\n\t *\n\t * @param components - The components to set\n\t */\n\tpublic setComponents(...components: RestOrArray<T>) {\n\t\tthis.components.splice(0, this.components.length, ...normalizeArray(components));\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {\n\t\treturn {\n\t\t\t...this.data,\n\t\t\tcomponents: this.components.map((component) => component.toJSON()),\n\t\t} as APIActionRowComponent<ReturnType<T['toJSON']>>;\n\t}\n}\n","import type { JSONEncodable } from '@discordjs/util';\nimport type {\n\tAPIActionRowComponent,\n\tAPIActionRowComponentTypes,\n\tAPIBaseComponent,\n\tComponentType,\n} from 'discord-api-types/v10';\n\n/**\n * Any action row component data represented as an object.\n */\nexport type AnyAPIActionRowComponent = APIActionRowComponent<APIActionRowComponentTypes> | APIActionRowComponentTypes;\n\n/**\n * The base component builder that contains common symbols for all sorts of components.\n *\n * @typeParam DataType - The type of internal API data that is stored within the component\n */\nexport abstract class ComponentBuilder<\n\tDataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>,\n> implements JSONEncodable<AnyAPIActionRowComponent>\n{\n\t/**\n\t * The API data associated with this component.\n\t */\n\tpublic readonly data: Partial<DataType>;\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic abstract toJSON(): AnyAPIActionRowComponent;\n\n\t/**\n\t * Constructs a new kind of component.\n\t *\n\t * @param data - The data to construct a component out of\n\t */\n\tpublic constructor(data: Partial<DataType>) {\n\t\tthis.data = data;\n\t}\n}\n","import { ComponentType, type APIMessageComponent, type APIModalComponent } from 'discord-api-types/v10';\nimport {\n\tActionRowBuilder,\n\ttype AnyComponentBuilder,\n\ttype MessageComponentBuilder,\n\ttype ModalComponentBuilder,\n} from './ActionRow.js';\nimport { ComponentBuilder } from './Component.js';\nimport { ButtonBuilder } from './button/Button.js';\nimport { ChannelSelectMenuBuilder } from './selectMenu/ChannelSelectMenu.js';\nimport { MentionableSelectMenuBuilder } from './selectMenu/MentionableSelectMenu.js';\nimport { RoleSelectMenuBuilder } from './selectMenu/RoleSelectMenu.js';\nimport { StringSelectMenuBuilder } from './selectMenu/StringSelectMenu.js';\nimport { UserSelectMenuBuilder } from './selectMenu/UserSelectMenu.js';\nimport { TextInputBuilder } from './textInput/TextInput.js';\n\n/**\n * Components here are mapped to their respective builder.\n */\nexport interface MappedComponentTypes {\n\t/**\n\t * The action row component type is associated with an {@link ActionRowBuilder}.\n\t */\n\t[ComponentType.ActionRow]: ActionRowBuilder<AnyComponentBuilder>;\n\t/**\n\t * The button component type is associated with an {@link ButtonBuilder}.\n\t */\n\t[ComponentType.Button]: ButtonBuilder;\n\t/**\n\t * The string select component type is associated with an {@link StringSelectMenuBuilder}.\n\t */\n\t[ComponentType.StringSelect]: StringSelectMenuBuilder;\n\t/**\n\t * The text inpiut component type is associated with an {@link TextInputBuilder}.\n\t */\n\t[ComponentType.TextInput]: TextInputBuilder;\n\t/**\n\t * The user select component type is associated with an {@link UserSelectMenuBuilder}.\n\t */\n\t[ComponentType.UserSelect]: UserSelectMenuBuilder;\n\t/**\n\t * The role select component type is associated with an {@link RoleSelectMenuBuilder}.\n\t */\n\t[ComponentType.RoleSelect]: RoleSelectMenuBuilder;\n\t/**\n\t * The mentionable select component type is associated with an {@link MentionableSelectMenuBuilder}.\n\t */\n\t[ComponentType.MentionableSelect]: MentionableSelectMenuBuilder;\n\t/**\n\t * The channel select component type is associated with an {@link ChannelSelectMenuBuilder}.\n\t */\n\t[ComponentType.ChannelSelect]: ChannelSelectMenuBuilder;\n}\n\n/**\n * Factory for creating components from API data.\n *\n * @typeParam T - The type of component to use\n * @param data - The API data to transform to a component class\n */\nexport function createComponentBuilder<T extends keyof MappedComponentTypes>(\n\t// eslint-disable-next-line @typescript-eslint/sort-type-union-intersection-members\n\tdata: (APIModalComponent | APIMessageComponent) & { type: T },\n): MappedComponentTypes[T];\n\n/**\n * Factory for creating components from API data.\n *\n * @typeParam C - The type of component to use\n * @param data - The API data to transform to a component class\n */\nexport function createComponentBuilder<C extends MessageComponentBuilder | ModalComponentBuilder>(data: C): C;\n\nexport function createComponentBuilder(\n\tdata: APIMessageComponent | APIModalComponent | MessageComponentBuilder,\n): ComponentBuilder {\n\tif (data instanceof ComponentBuilder) {\n\t\treturn data;\n\t}\n\n\tswitch (data.type) {\n\t\tcase ComponentType.ActionRow:\n\t\t\treturn new ActionRowBuilder(data);\n\t\tcase ComponentType.Button:\n\t\t\treturn new ButtonBuilder(data);\n\t\tcase ComponentType.StringSelect:\n\t\t\treturn new StringSelectMenuBuilder(data);\n\t\tcase ComponentType.TextInput:\n\t\t\treturn new TextInputBuilder(data);\n\t\tcase ComponentType.UserSelect:\n\t\t\treturn new UserSelectMenuBuilder(data);\n\t\tcase ComponentType.RoleSelect:\n\t\t\treturn new RoleSelectMenuBuilder(data);\n\t\tcase ComponentType.MentionableSelect:\n\t\t\treturn new MentionableSelectMenuBuilder(data);\n\t\tcase ComponentType.ChannelSelect:\n\t\t\treturn new ChannelSelectMenuBuilder(data);\n\t\tdefault:\n\t\t\t// @ts-expect-error This case can still occur if we get a newer unsupported component type\n\t\t\tthrow new Error(`Cannot properly serialize component type: ${data.type}`);\n\t}\n}\n","import {\n\tComponentType,\n\ttype APIMessageComponentEmoji,\n\ttype APIButtonComponent,\n\ttype APIButtonComponentWithURL,\n\ttype APIButtonComponentWithCustomId,\n\ttype ButtonStyle,\n} from 'discord-api-types/v10';\nimport {\n\tbuttonLabelValidator,\n\tbuttonStyleValidator,\n\tcustomIdValidator,\n\tdisabledValidator,\n\temojiValidator,\n\turlValidator,\n\tvalidateRequiredButtonParameters,\n} from '../Assertions.js';\nimport { ComponentBuilder } from '../Component.js';\n\n/**\n * A builder that creates API-compatible JSON data for buttons.\n */\nexport class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {\n\t/**\n\t * Creates a new button from API data.\n\t *\n\t * @param data - The API data to create this button with\n\t * @example\n\t * Creating a button from an API data object:\n\t * ```ts\n\t * const button = new ButtonBuilder({\n\t * \tcustom_id: 'a cool button',\n\t * \tstyle: ButtonStyle.Primary,\n\t * \tlabel: 'Click Me',\n\t * \temoji: {\n\t * \t\tname: 'smile',\n\t * \t\tid: '123456789012345678',\n\t * \t},\n\t * });\n\t * ```\n\t * @example\n\t * Creating a button using setters and API data:\n\t * ```ts\n\t * const button = new ButtonBuilder({\n\t * \tstyle: ButtonStyle.Secondary,\n\t * \tlabel: 'Click Me',\n\t * })\n\t * \t.setEmoji({ name: '🙂' })\n\t * \t.setCustomId('another cool button');\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIButtonComponent>) {\n\t\tsuper({ type: ComponentType.Button, ...data });\n\t}\n\n\t/**\n\t * Sets the style of this button.\n\t *\n\t * @param style - The style to use\n\t */\n\tpublic setStyle(style: ButtonStyle) {\n\t\tthis.data.style = buttonStyleValidator.parse(style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the URL for this button.\n\t *\n\t * @remarks\n\t * This method is only available to buttons using the `Link` button style.\n\t * Only three types of URL schemes are currently supported: `https://`, `http://`, and `discord://`.\n\t * @param url - The URL to use\n\t */\n\tpublic setURL(url: string) {\n\t\t(this.data as APIButtonComponentWithURL).url = urlValidator.parse(url);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the custom id for this button.\n\t *\n\t * @remarks\n\t * This method is only applicable to buttons that are not using the `Link` button style.\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\t(this.data as APIButtonComponentWithCustomId).custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the emoji to display on this button.\n\t *\n\t * @param emoji - The emoji to use\n\t */\n\tpublic setEmoji(emoji: APIMessageComponentEmoji) {\n\t\tthis.data.emoji = emojiValidator.parse(emoji);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this button is disabled.\n\t *\n\t * @param disabled - Whether to disable this button\n\t */\n\tpublic setDisabled(disabled = true) {\n\t\tthis.data.disabled = disabledValidator.parse(disabled);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the label for this button.\n\t *\n\t * @param label - The label to use\n\t */\n\tpublic setLabel(label: string) {\n\t\tthis.data.label = buttonLabelValidator.parse(label);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APIButtonComponent {\n\t\tvalidateRequiredButtonParameters(\n\t\t\tthis.data.style,\n\t\t\tthis.data.label,\n\t\t\tthis.data.emoji,\n\t\t\t(this.data as APIButtonComponentWithCustomId).custom_id,\n\t\t\t(this.data as APIButtonComponentWithURL).url,\n\t\t);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APIButtonComponent;\n\t}\n}\n","import type { APIChannelSelectComponent, ChannelType } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport { channelTypesValidator, customIdValidator } from '../Assertions.js';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for channel select menus.\n */\nexport class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new ChannelSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new ChannelSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement)\n\t * \t.setMinValues(2);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIChannelSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.ChannelSelect });\n\t}\n\n\t/**\n\t * Adds channel types to this select menu.\n\t *\n\t * @param types - The channel types to use\n\t */\n\tpublic addChannelTypes(...types: RestOrArray<ChannelType>) {\n\t\tconst normalizedTypes = normalizeArray(types);\n\t\tthis.data.channel_types ??= [];\n\t\tthis.data.channel_types.push(...channelTypesValidator.parse(normalizedTypes));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets channel types for this select menu.\n\t *\n\t * @param types - The channel types to use\n\t */\n\tpublic setChannelTypes(...types: RestOrArray<ChannelType>) {\n\t\tconst normalizedTypes = normalizeArray(types);\n\t\tthis.data.channel_types ??= [];\n\t\tthis.data.channel_types.splice(0, this.data.channel_types.length, ...channelTypesValidator.parse(normalizedTypes));\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc BaseSelectMenuBuilder.toJSON}\n\t */\n\tpublic override toJSON(): APIChannelSelectComponent {\n\t\tcustomIdValidator.parse(this.data.custom_id);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APIChannelSelectComponent;\n\t}\n}\n","import type { APISelectMenuComponent } from 'discord-api-types/v10';\nimport { customIdValidator, disabledValidator, minMaxValidator, placeholderValidator } from '../Assertions.js';\nimport { ComponentBuilder } from '../Component.js';\n\n/**\n * The base select menu builder that contains common symbols for select menu builders.\n *\n * @typeParam SelectMenuType - The type of select menu this would be instantiated for.\n */\nexport abstract class BaseSelectMenuBuilder<\n\tSelectMenuType extends APISelectMenuComponent,\n> extends ComponentBuilder<SelectMenuType> {\n\t/**\n\t * Sets the placeholder for this select menu.\n\t *\n\t * @param placeholder - The placeholder to use\n\t */\n\tpublic setPlaceholder(placeholder: string) {\n\t\tthis.data.placeholder = placeholderValidator.parse(placeholder);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the minimum values that must be selected in the select menu.\n\t *\n\t * @param minValues - The minimum values that must be selected\n\t */\n\tpublic setMinValues(minValues: number) {\n\t\tthis.data.min_values = minMaxValidator.parse(minValues);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the maximum values that must be selected in the select menu.\n\t *\n\t * @param maxValues - The maximum values that must be selected\n\t */\n\tpublic setMaxValues(maxValues: number) {\n\t\tthis.data.max_values = minMaxValidator.parse(maxValues);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the custom id for this select menu.\n\t *\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\tthis.data.custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this select menu is disabled.\n\t *\n\t * @param disabled - Whether this select menu is disabled\n\t */\n\tpublic setDisabled(disabled = true) {\n\t\tthis.data.disabled = disabledValidator.parse(disabled);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): SelectMenuType {\n\t\tcustomIdValidator.parse(this.data.custom_id);\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as SelectMenuType;\n\t}\n}\n","import type { APIMentionableSelectComponent } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for mentionable select menus.\n */\nexport class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder<APIMentionableSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new MentionableSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new MentionableSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIMentionableSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.MentionableSelect });\n\t}\n}\n","import type { APIRoleSelectComponent } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for role select menus.\n */\nexport class RoleSelectMenuBuilder extends BaseSelectMenuBuilder<APIRoleSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new RoleSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new RoleSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIRoleSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.RoleSelect });\n\t}\n}\n","import { ComponentType } from 'discord-api-types/v10';\nimport type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport { jsonOptionValidator, optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\nimport { StringSelectMenuOptionBuilder } from './StringSelectMenuOption.js';\n\n/**\n * A builder that creates API-compatible JSON data for string select menus.\n */\nexport class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSelectComponent> {\n\t/**\n\t * The options within this select menu.\n\t */\n\tpublic readonly options: StringSelectMenuOptionBuilder[];\n\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new StringSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * \toptions: [\n\t * \t\t{ label: 'option 1', value: '1' },\n\t * \t\t{ label: 'option 2', value: '2' },\n\t * \t\t{ label: 'option 3', value: '3' },\n\t * \t],\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new StringSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1)\n\t * \t.addOptions({\n\t * \t\tlabel: 'Catchy',\n\t * \t\tvalue: 'catch',\n\t * \t});\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIStringSelectComponent>) {\n\t\tconst { options, ...initData } = data ?? {};\n\t\tsuper({ ...initData, type: ComponentType.StringSelect });\n\t\tthis.options = options?.map((option: APISelectMenuOption) => new StringSelectMenuOptionBuilder(option)) ?? [];\n\t}\n\n\t/**\n\t * Adds options to this select menu.\n\t *\n\t * @param options - The options to add\n\t */\n\tpublic addOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>) {\n\t\tconst normalizedOptions = normalizeArray(options);\n\t\toptionsLengthValidator.parse(this.options.length + normalizedOptions.length);\n\t\tthis.options.push(\n\t\t\t...normalizedOptions.map((normalizedOption) =>\n\t\t\t\tnormalizedOption instanceof StringSelectMenuOptionBuilder\n\t\t\t\t\t? normalizedOption\n\t\t\t\t\t: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),\n\t\t\t),\n\t\t);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the options for this select menu.\n\t *\n\t * @param options - The options to set\n\t */\n\tpublic setOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>) {\n\t\treturn this.spliceOptions(0, this.options.length, ...options);\n\t}\n\n\t/**\n\t * Removes, replaces, or inserts options for this select menu.\n\t *\n\t * @remarks\n\t * This method behaves similarly\n\t * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}.\n\t * It's useful for modifying and adjusting the order of existing options.\n\t * @example\n\t * Remove the first option:\n\t * ```ts\n\t * selectMenu.spliceOptions(0, 1);\n\t * ```\n\t * @example\n\t * Remove the first n option:\n\t * ```ts\n\t * const n = 4;\n\t * selectMenu.spliceOptions(0, n);\n\t * ```\n\t * @example\n\t * Remove the last option:\n\t * ```ts\n\t * selectMenu.spliceOptions(-1, 1);\n\t * ```\n\t * @param index - The index to start at\n\t * @param deleteCount - The number of options to remove\n\t * @param options - The replacing option objects or builders\n\t */\n\tpublic spliceOptions(\n\t\tindex: number,\n\t\tdeleteCount: number,\n\t\t...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>\n\t) {\n\t\tconst normalizedOptions = normalizeArray(options);\n\n\t\tconst clone = [...this.options];\n\n\t\tclone.splice(\n\t\t\tindex,\n\t\t\tdeleteCount,\n\t\t\t...normalizedOptions.map((normalizedOption) =>\n\t\t\t\tnormalizedOption instanceof StringSelectMenuOptionBuilder\n\t\t\t\t\t? normalizedOption\n\t\t\t\t\t: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),\n\t\t\t),\n\t\t);\n\n\t\toptionsLengthValidator.parse(clone.length);\n\t\tthis.options.splice(0, this.options.length, ...clone);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc BaseSelectMenuBuilder.toJSON}\n\t */\n\tpublic override toJSON(): APIStringSelectComponent {\n\t\tvalidateRequiredSelectMenuParameters(this.options, this.data.custom_id);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t} as APIStringSelectComponent;\n\t}\n}\n","import type { APIUserSelectComponent } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for user select menus.\n */\nexport class UserSelectMenuBuilder extends BaseSelectMenuBuilder<APIUserSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new UserSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new UserSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIUserSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.UserSelect });\n\t}\n}\n","import { isJSONEncodable, type Equatable, type JSONEncodable } from '@discordjs/util';\nimport { ComponentType, type TextInputStyle, type APITextInputComponent } from 'discord-api-types/v10';\nimport isEqual from 'fast-deep-equal';\nimport { customIdValidator } from '../Assertions.js';\nimport { ComponentBuilder } from '../Component.js';\nimport {\n\tmaxLengthValidator,\n\tminLengthValidator,\n\tplaceholderValidator,\n\trequiredValidator,\n\tvalueValidator,\n\tvalidateRequiredParameters,\n\tlabelValidator,\n\ttextInputStyleValidator,\n} from './Assertions.js';\n\n/**\n * A builder that creates API-compatible JSON data for text inputs.\n */\nexport class TextInputBuilder\n\textends ComponentBuilder<APITextInputComponent>\n\timplements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>>\n{\n\t/**\n\t * Creates a new text input from API data.\n\t *\n\t * @param data - The API data to create this text input with\n\t * @example\n\t * Creating a select menu option from an API data object:\n\t * ```ts\n\t * const textInput = new TextInputBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tlabel: 'Type something',\n\t * \tstyle: TextInputStyle.Short,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu option using setters and API data:\n\t * ```ts\n\t * const textInput = new TextInputBuilder({\n\t * \tlabel: 'Type something else',\n\t * })\n\t * \t.setCustomId('woah')\n\t * \t.setStyle(TextInputStyle.Paragraph);\n\t * ```\n\t */\n\tpublic constructor(data?: APITextInputComponent & { type?: ComponentType.TextInput }) {\n\t\tsuper({ type: ComponentType.TextInput, ...data });\n\t}\n\n\t/**\n\t * Sets the custom id for this text input.\n\t *\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\tthis.data.custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the label for this text input.\n\t *\n\t * @param label - The label to use\n\t */\n\tpublic setLabel(label: string) {\n\t\tthis.data.label = labelValidator.parse(label);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the style for this text input.\n\t *\n\t * @param style - The style to use\n\t */\n\tpublic setStyle(style: TextInputStyle) {\n\t\tthis.data.style = textInputStyleValidator.parse(style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the minimum length of text for this text input.\n\t *\n\t * @param minLength - The minimum length of text for this text input\n\t */\n\tpublic setMinLength(minLength: number) {\n\t\tthis.data.min_length = minLengthValidator.parse(minLength);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the maximum length of text for this text input.\n\t *\n\t * @param maxLength - The maximum length of text for this text input\n\t */\n\tpublic setMaxLength(maxLength: number) {\n\t\tthis.data.max_length = maxLengthValidator.parse(maxLength);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the placeholder for this text input.\n\t *\n\t * @param placeholder - The placeholder to use\n\t */\n\tpublic setPlaceholder(placeholder: string) {\n\t\tthis.data.placeholder = placeholderValidator.parse(placeholder);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the value for this text input.\n\t *\n\t * @param value - The value to use\n\t */\n\tpublic setValue(value: string) {\n\t\tthis.data.value = valueValidator.parse(value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this text input is required.\n\t *\n\t * @param required - Whether this text input is required\n\t */\n\tpublic setRequired(required = true) {\n\t\tthis.data.required = requiredValidator.parse(required);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APITextInputComponent {\n\t\tvalidateRequiredParameters(this.data.custom_id, this.data.style, this.data.label);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APITextInputComponent;\n\t}\n\n\t/**\n\t * {@inheritDoc Equatable.equals}\n\t */\n\tpublic equals(other: APITextInputComponent | JSONEncodable<APITextInputComponent>): boolean {\n\t\tif (isJSONEncodable(other)) {\n\t\t\treturn isEqual(other.toJSON(), this.data);\n\t\t}\n\n\t\treturn isEqual(other, this.data);\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { TextInputStyle } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\nimport { customIdValidator } from '../Assertions.js';\n\nexport const textInputStyleValidator = s.nativeEnum(TextInputStyle);\nexport const minLengthValidator = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(4_000)\n\t.setValidationEnabled(isValidationEnabled);\nexport const maxLengthValidator = s.number.int\n\t.greaterThanOrEqual(1)\n\t.lessThanOrEqual(4_000)\n\t.setValidationEnabled(isValidationEnabled);\nexport const requiredValidator = s.boolean;\nexport const valueValidator = s.string.lengthLessThanOrEqual(4_000).setValidationEnabled(isValidationEnabled);\nexport const placeholderValidator = s.string.lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled);\nexport const labelValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(45)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredParameters(customId?: string, style?: TextInputStyle, label?: string) {\n\tcustomIdValidator.parse(customId);\n\ttextInputStyleValidator.parse(style);\n\tlabelValidator.parse(label);\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow.js';\nimport { customIdValidator } from '../../components/Assertions.js';\nimport { isValidationEnabled } from '../../util/validation.js';\n\nexport const titleValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(45)\n\t.setValidationEnabled(isValidationEnabled);\nexport const componentsValidator = s\n\t.instance(ActionRowBuilder)\n\t.array.lengthGreaterThanOrEqual(1)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredParameters(\n\tcustomId?: string,\n\ttitle?: string,\n\tcomponents?: ActionRowBuilder<ModalActionRowComponentBuilder>[],\n) {\n\tcustomIdValidator.parse(customId);\n\ttitleValidator.parse(title);\n\tcomponentsValidator.parse(components);\n}\n","/* eslint-disable jsdoc/check-param-names */\n\nimport type { JSONEncodable } from '@discordjs/util';\nimport type {\n\tAPIActionRowComponent,\n\tAPIModalActionRowComponent,\n\tAPIModalInteractionResponseCallbackData,\n} from 'discord-api-types/v10';\nimport { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow.js';\nimport { customIdValidator } from '../../components/Assertions.js';\nimport { createComponentBuilder } from '../../components/Components.js';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport { titleValidator, validateRequiredParameters } from './Assertions.js';\n\n/**\n * A builder that creates API-compatible JSON data for modals.\n */\nexport class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> {\n\t/**\n\t * The API data associated with this modal.\n\t */\n\tpublic readonly data: Partial<APIModalInteractionResponseCallbackData>;\n\n\t/**\n\t * The components within this modal.\n\t */\n\tpublic readonly components: ActionRowBuilder<ModalActionRowComponentBuilder>[] = [];\n\n\t/**\n\t * Creates a new modal from API data.\n\t *\n\t * @param data - The API data to create this modal with\n\t */\n\tpublic constructor({ components, ...data }: Partial<APIModalInteractionResponseCallbackData> = {}) {\n\t\tthis.data = { ...data };\n\t\tthis.components = (components?.map((component) => createComponentBuilder(component)) ??\n\t\t\t[]) as ActionRowBuilder<ModalActionRowComponentBuilder>[];\n\t}\n\n\t/**\n\t * Sets the title of this modal.\n\t *\n\t * @param title - The title to use\n\t */\n\tpublic setTitle(title: string) {\n\t\tthis.data.title = titleValidator.parse(title);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the custom id of this modal.\n\t *\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\tthis.data.custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds components to this modal.\n\t *\n\t * @param components - The components to add\n\t */\n\tpublic addComponents(\n\t\t...components: RestOrArray<\n\t\t\tActionRowBuilder<ModalActionRowComponentBuilder> | APIActionRowComponent<APIModalActionRowComponent>\n\t\t>\n\t) {\n\t\tthis.components.push(\n\t\t\t...normalizeArray(components).map((component) =>\n\t\t\t\tcomponent instanceof ActionRowBuilder\n\t\t\t\t\t? component\n\t\t\t\t\t: new ActionRowBuilder<ModalActionRowComponentBuilder>(component),\n\t\t\t),\n\t\t);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets components for this modal.\n\t *\n\t * @param components - The components to set\n\t */\n\tpublic setComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder>>) {\n\t\tthis.components.splice(0, this.components.length, ...normalizeArray(components));\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APIModalInteractionResponseCallbackData {\n\t\tvalidateRequiredParameters(this.data.custom_id, this.data.title, this.components);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t\tcomponents: this.components.map((component) => component.toJSON()),\n\t\t} as APIModalInteractionResponseCallbackData;\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { Locale, type APIApplicationCommandOptionChoice, type LocalizationMap } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\nimport type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder.js';\nimport type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';\nimport type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase.js';\n\nconst namePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(32)\n\t.regex(/^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}_-]+$/u)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateName(name: unknown): asserts name is string {\n\tnamePredicate.parse(name);\n}\n\nconst descriptionPredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(100)\n\t.setValidationEnabled(isValidationEnabled);\nconst localePredicate = s.nativeEnum(Locale);\n\nexport function validateDescription(description: unknown): asserts description is string {\n\tdescriptionPredicate.parse(description);\n}\n\nconst maxArrayLengthPredicate = s.unknown.array.lengthLessThanOrEqual(25).setValidationEnabled(isValidationEnabled);\nexport function validateLocale(locale: unknown) {\n\treturn localePredicate.parse(locale);\n}\n\nexport function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {\n\tmaxArrayLengthPredicate.parse(options);\n}\n\nexport function validateRequiredParameters(\n\tname: string,\n\tdescription: string,\n\toptions: ToAPIApplicationCommandOptions[],\n) {\n\t// Assert name matches all conditions\n\tvalidateName(name);\n\n\t// Assert description conditions\n\tvalidateDescription(description);\n\n\t// Assert options conditions\n\tvalidateMaxOptionsLength(options);\n}\n\nconst booleanPredicate = s.boolean;\n\nexport function validateDefaultPermission(value: unknown): asserts value is boolean {\n\tbooleanPredicate.parse(value);\n}\n\nexport function validateRequired(required: unknown): asserts required is boolean {\n\tbooleanPredicate.parse(required);\n}\n\nconst choicesLengthPredicate = s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled);\n\nexport function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void {\n\tchoicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding);\n}\n\nexport function assertReturnOfBuilder<\n\tT extends ApplicationCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder,\n>(input: unknown, ExpectedInstanceOf: new () => T): asserts input is T {\n\ts.instance(ExpectedInstanceOf).parse(input);\n}\n\nexport const localizationMapPredicate = s\n\t.object<LocalizationMap>(Object.fromEntries(Object.values(Locale).map((locale) => [locale, s.string.nullish])))\n\t.strict.nullish.setValidationEnabled(isValidationEnabled);\n\nexport function validateLocalizationMap(value: unknown): asserts value is LocalizationMap {\n\tlocalizationMapPredicate.parse(value);\n}\n\nconst dmPermissionPredicate = s.boolean.nullish;\n\nexport function validateDMPermission(value: unknown): asserts value is boolean | null | undefined {\n\tdmPermissionPredicate.parse(value);\n}\n\nconst memberPermissionPredicate = s.union(\n\ts.bigint.transform((value) => value.toString()),\n\ts.number.safeInt.transform((value) => value.toString()),\n\ts.string.regex(/^\\d+$/),\n).nullish;\n\nexport function validateDefaultMemberPermissions(permissions: unknown) {\n\treturn memberPermissionPredicate.parse(permissions);\n}\n\nexport function validateNSFW(value: unknown): asserts value is boolean {\n\tbooleanPredicate.parse(value);\n}\n","import type {\n\tAPIApplicationCommandOption,\n\tLocalizationMap,\n\tPermissions,\n\tRESTPostAPIChatInputApplicationCommandsJSONBody,\n} from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport {\n\tassertReturnOfBuilder,\n\tvalidateDefaultMemberPermissions,\n\tvalidateDefaultPermission,\n\tvalidateLocalizationMap,\n\tvalidateDMPermission,\n\tvalidateMaxOptionsLength,\n\tvalidateRequiredParameters,\n\tvalidateNSFW,\n} from './Assertions.js';\nimport { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';\nimport { SharedNameAndDescription } from './mixins/NameAndDescription.js';\nimport { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';\n\n/**\n * A builder that creates API-compatible JSON data for slash commands.\n */\n@mix(SharedSlashCommandOptions, SharedNameAndDescription)\nexport class SlashCommandBuilder {\n\t/**\n\t * The name of this command.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The name localizations of this command.\n\t */\n\tpublic readonly name_localizations?: LocalizationMap;\n\n\t/**\n\t * The description of this command.\n\t */\n\tpublic readonly description: string = undefined!;\n\n\t/**\n\t * The description localizations of this command.\n\t */\n\tpublic readonly description_localizations?: LocalizationMap;\n\n\t/**\n\t * The options of this command.\n\t */\n\tpublic readonly options: ToAPIApplicationCommandOptions[] = [];\n\n\t/**\n\t * Whether this command is enabled by default when the application is added to a guild.\n\t *\n\t * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic readonly default_permission: boolean | undefined = undefined;\n\n\t/**\n\t * The set of permissions represented as a bit set for the command.\n\t */\n\tpublic readonly default_member_permissions: Permissions | null | undefined = undefined;\n\n\t/**\n\t * Indicates whether the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This property is only for global commands.\n\t */\n\tpublic readonly dm_permission: boolean | undefined = undefined;\n\n\t/**\n\t * Whether this command is NSFW.\n\t */\n\tpublic readonly nsfw: boolean | undefined = undefined;\n\n\t/**\n\t * Sets whether the command is enabled by default when the application is added to a guild.\n\t *\n\t * @remarks\n\t * If set to `false`, you will have to later `PUT` the permissions for this command.\n\t * @param value - Whether or not to enable this command by default\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t * @deprecated Use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic setDefaultPermission(value: boolean) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDefaultPermission(value);\n\n\t\tReflect.set(this, 'default_permission', value);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the default permissions a member should have in order to run the command.\n\t *\n\t * @remarks\n\t * You can set this to `'0'` to disable the command by default.\n\t * @param permissions - The permissions bit field to set\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {\n\t\t// Assert the value and parse it\n\t\tconst permissionValue = validateDefaultMemberPermissions(permissions);\n\n\t\tReflect.set(this, 'default_member_permissions', permissionValue);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets if the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This method is only for global commands.\n\t * @param enabled - Whether the command should be enabled in direct messages\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDMPermission(enabled: boolean | null | undefined) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDMPermission(enabled);\n\n\t\tReflect.set(this, 'dm_permission', enabled);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this command is NSFW.\n\t *\n\t * @param nsfw - Whether this command is NSFW\n\t */\n\tpublic setNSFW(nsfw = true) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateNSFW(nsfw);\n\t\tReflect.set(this, 'nsfw', nsfw);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a new subcommand group to this command.\n\t *\n\t * @param input - A function that returns a subcommand group builder or an already built builder\n\t */\n\tpublic addSubcommandGroup(\n\t\tinput:\n\t\t\t| SlashCommandSubcommandGroupBuilder\n\t\t\t| ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder),\n\t): SlashCommandSubcommandsOnlyBuilder {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\tconst result = typeof input === 'function' ? input(new SlashCommandSubcommandGroupBuilder()) : input;\n\n\t\tassertReturnOfBuilder(result, SlashCommandSubcommandGroupBuilder);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a new subcommand to this command.\n\t *\n\t * @param input - A function that returns a subcommand builder or an already built builder\n\t */\n\tpublic addSubcommand(\n\t\tinput:\n\t\t\t| SlashCommandSubcommandBuilder\n\t\t\t| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),\n\t): SlashCommandSubcommandsOnlyBuilder {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\tconst result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;\n\n\t\tassertReturnOfBuilder(result, SlashCommandSubcommandBuilder);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {\n\t\tvalidateRequiredParameters(this.name, this.description, this.options);\n\n\t\tvalidateLocalizationMap(this.name_localizations);\n\t\tvalidateLocalizationMap(this.description_localizations);\n\n\t\treturn {\n\t\t\t...this,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t};\n\t}\n}\n\nexport interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions {}\n\n/**\n * An interface specifically for slash command subcommands.\n */\nexport interface SlashCommandSubcommandsOnlyBuilder\n\textends Omit<SlashCommandBuilder, Exclude<keyof SharedSlashCommandOptions, 'options'>> {}\n\n/**\n * An interface specifically for slash command options.\n */\nexport interface SlashCommandOptionsOnlyBuilder\n\textends SharedNameAndDescription,\n\t\tSharedSlashCommandOptions,\n\t\tPick<SlashCommandBuilder, 'toJSON'> {}\n\n/**\n * An interface that ensures the `toJSON()` call will return something\n * that can be serialized into API-compatible data.\n */\nexport interface ToAPIApplicationCommandOptions {\n\ttoJSON(): APIApplicationCommandOption;\n}\n","import {\n\tApplicationCommandOptionType,\n\ttype APIApplicationCommandSubcommandGroupOption,\n\ttype APIApplicationCommandSubcommandOption,\n} from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { assertReturnOfBuilder, validateMaxOptionsLength, validateRequiredParameters } from './Assertions.js';\nimport type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder.js';\nimport type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase.js';\nimport { SharedNameAndDescription } from './mixins/NameAndDescription.js';\nimport { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';\n\n/**\n * Represents a folder for subcommands.\n *\n * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}\n */\n@mix(SharedNameAndDescription)\nexport class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationCommandOptions {\n\t/**\n\t * The name of this subcommand group.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The description of this subcommand group.\n\t */\n\tpublic readonly description: string = undefined!;\n\n\t/**\n\t * The subcommands within this subcommand group.\n\t */\n\tpublic readonly options: SlashCommandSubcommandBuilder[] = [];\n\n\t/**\n\t * Adds a new subcommand to this group.\n\t *\n\t * @param input - A function that returns a subcommand builder or an already built builder\n\t */\n\tpublic addSubcommand(\n\t\tinput:\n\t\t\t| SlashCommandSubcommandBuilder\n\t\t\t| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),\n\t) {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tconst result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tassertReturnOfBuilder(result, SlashCommandSubcommandBuilder);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): APIApplicationCommandSubcommandGroupOption {\n\t\tvalidateRequiredParameters(this.name, this.description, this.options);\n\n\t\treturn {\n\t\t\ttype: ApplicationCommandOptionType.SubcommandGroup,\n\t\t\tname: this.name,\n\t\t\tname_localizations: this.name_localizations,\n\t\t\tdescription: this.description,\n\t\t\tdescription_localizations: this.description_localizations,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t};\n\t}\n}\n\nexport interface SlashCommandSubcommandGroupBuilder extends SharedNameAndDescription {}\n\n/**\n * A builder that creates API-compatible JSON data for slash command subcommands.\n *\n * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}\n */\n@mix(SharedNameAndDescription, SharedSlashCommandOptions)\nexport class SlashCommandSubcommandBuilder implements ToAPIApplicationCommandOptions {\n\t/**\n\t * The name of this subcommand.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The description of this subcommand.\n\t */\n\tpublic readonly description: string = undefined!;\n\n\t/**\n\t * The options within this subcommand.\n\t */\n\tpublic readonly options: ApplicationCommandOptionBase[] = [];\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): APIApplicationCommandSubcommandOption {\n\t\tvalidateRequiredParameters(this.name, this.description, this.options);\n\n\t\treturn {\n\t\t\ttype: ApplicationCommandOptionType.Subcommand,\n\t\t\tname: this.name,\n\t\t\tname_localizations: this.name_localizations,\n\t\t\tdescription: this.description,\n\t\t\tdescription_localizations: this.description_localizations,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t};\n\t}\n}\n\nexport interface SlashCommandSubcommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions<false> {}\n","import type { LocaleString, LocalizationMap } from 'discord-api-types/v10';\nimport { validateDescription, validateLocale, validateName } from '../Assertions.js';\n\n/**\n * This mixin holds name and description symbols for slash commands.\n */\nexport class SharedNameAndDescription {\n\t/**\n\t * The name of this command.\n\t */\n\tpublic readonly name!: string;\n\n\t/**\n\t * The name localizations of this command.\n\t */\n\tpublic readonly name_localizations?: LocalizationMap;\n\n\t/**\n\t * The description of this command.\n\t */\n\tpublic readonly description!: string;\n\n\t/**\n\t * The description localizations of this command.\n\t */\n\tpublic readonly description_localizations?: LocalizationMap;\n\n\t/**\n\t * Sets the name of this command.\n\t *\n\t * @param name - The name to use\n\t */\n\tpublic setName(name: string): this {\n\t\t// Assert the name matches the conditions\n\t\tvalidateName(name);\n\n\t\tReflect.set(this, 'name', name);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description of this command.\n\t *\n\t * @param description - The description to use\n\t */\n\tpublic setDescription(description: string) {\n\t\t// Assert the description matches the conditions\n\t\tvalidateDescription(description);\n\n\t\tReflect.set(this, 'description', description);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets a name localization for this command.\n\t *\n\t * @param locale - The locale to set\n\t * @param localizedName - The localized name for the given `locale`\n\t */\n\tpublic setNameLocalization(locale: LocaleString, localizedName: string | null) {\n\t\tif (!this.name_localizations) {\n\t\t\tReflect.set(this, 'name_localizations', {});\n\t\t}\n\n\t\tconst parsedLocale = validateLocale(locale);\n\n\t\tif (localizedName === null) {\n\t\t\tthis.name_localizations![parsedLocale] = null;\n\t\t\treturn this;\n\t\t}\n\n\t\tvalidateName(localizedName);\n\n\t\tthis.name_localizations![parsedLocale] = localizedName;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the name localizations for this command.\n\t *\n\t * @param localizedNames - The object of localized names to set\n\t */\n\tpublic setNameLocalizations(localizedNames: LocalizationMap | null) {\n\t\tif (localizedNames === null) {\n\t\t\tReflect.set(this, 'name_localizations', null);\n\t\t\treturn this;\n\t\t}\n\n\t\tReflect.set(this, 'name_localizations', {});\n\n\t\tfor (const args of Object.entries(localizedNames)) {\n\t\t\tthis.setNameLocalization(...(args as [LocaleString, string | null]));\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets a description localization for this command.\n\t *\n\t * @param locale - The locale to set\n\t * @param localizedDescription - The localized description for the given locale\n\t */\n\tpublic setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null) {\n\t\tif (!this.description_localizations) {\n\t\t\tReflect.set(this, 'description_localizations', {});\n\t\t}\n\n\t\tconst parsedLocale = validateLocale(locale);\n\n\t\tif (localizedDescription === null) {\n\t\t\tthis.description_localizations![parsedLocale] = null;\n\t\t\treturn this;\n\t\t}\n\n\t\tvalidateDescription(localizedDescription);\n\n\t\tthis.description_localizations![parsedLocale] = localizedDescription;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description localizations for this command.\n\t *\n\t * @param localizedDescriptions - The object of localized descriptions to set\n\t */\n\tpublic setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null) {\n\t\tif (localizedDescriptions === null) {\n\t\t\tReflect.set(this, 'description_localizations', null);\n\t\t\treturn this;\n\t\t}\n\n\t\tReflect.set(this, 'description_localizations', {});\n\t\tfor (const args of Object.entries(localizedDescriptions)) {\n\t\t\tthis.setDescriptionLocalization(...(args as [LocaleString, string | null]));\n\t\t}\n\n\t\treturn this;\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandAttachmentOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command attachment option.\n */\nexport class SlashCommandAttachmentOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic override readonly type = ApplicationCommandOptionType.Attachment as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandAttachmentOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import type { APIApplicationCommandBasicOption, ApplicationCommandOptionType } from 'discord-api-types/v10';\nimport { validateRequiredParameters, validateRequired, validateLocalizationMap } from '../Assertions.js';\nimport { SharedNameAndDescription } from './NameAndDescription.js';\n\n/**\n * The base application command option builder that contains common symbols for application command builders.\n */\nexport abstract class ApplicationCommandOptionBase extends SharedNameAndDescription {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic abstract readonly type: ApplicationCommandOptionType;\n\n\t/**\n\t * Whether this option is required.\n\t *\n\t * @defaultValue `false`\n\t */\n\tpublic readonly required: boolean = false;\n\n\t/**\n\t * Sets whether this option is required.\n\t *\n\t * @param required - Whether this option should be required\n\t */\n\tpublic setRequired(required: boolean) {\n\t\t// Assert that you actually passed a boolean\n\t\tvalidateRequired(required);\n\n\t\tReflect.set(this, 'required', required);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic abstract toJSON(): APIApplicationCommandBasicOption;\n\n\t/**\n\t * This method runs required validators on this builder.\n\t */\n\tprotected runRequiredValidations() {\n\t\tvalidateRequiredParameters(this.name, this.description, []);\n\n\t\t// Validate localizations\n\t\tvalidateLocalizationMap(this.name_localizations);\n\t\tvalidateLocalizationMap(this.description_localizations);\n\n\t\t// Assert that you actually passed a boolean\n\t\tvalidateRequired(this.required);\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandBooleanOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command boolean option.\n */\nexport class SlashCommandBooleanOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Boolean as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandBooleanOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandChannelOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionChannelTypesMixin } from '../mixins/ApplicationCommandOptionChannelTypesMixin.js';\n\n/**\n * A slash command channel option.\n */\n@mix(ApplicationCommandOptionChannelTypesMixin)\nexport class SlashCommandChannelOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic override readonly type = ApplicationCommandOptionType.Channel as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandChannelOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n\nexport interface SlashCommandChannelOption extends ApplicationCommandOptionChannelTypesMixin {}\n","import { s } from '@sapphire/shapeshift';\nimport { ChannelType } from 'discord-api-types/v10';\n\n/**\n * The allowed channel types used for a channel option in a slash command builder.\n *\n * @privateRemarks This can't be dynamic because const enums are erased at runtime.\n * @internal\n */\nconst allowedChannelTypes = [\n\tChannelType.GuildText,\n\tChannelType.GuildVoice,\n\tChannelType.GuildCategory,\n\tChannelType.GuildAnnouncement,\n\tChannelType.AnnouncementThread,\n\tChannelType.PublicThread,\n\tChannelType.PrivateThread,\n\tChannelType.GuildStageVoice,\n\tChannelType.GuildForum,\n] as const;\n\n/**\n * The type of allowed channel types used for a channel option.\n */\nexport type ApplicationCommandOptionAllowedChannelTypes = (typeof allowedChannelTypes)[number];\n\nconst channelTypesPredicate = s.array(s.union(...allowedChannelTypes.map((type) => s.literal(type))));\n\n/**\n * This mixin holds channel type symbols used for options.\n */\nexport class ApplicationCommandOptionChannelTypesMixin {\n\t/**\n\t * The channel types of this option.\n\t */\n\tpublic readonly channel_types?: ApplicationCommandOptionAllowedChannelTypes[];\n\n\t/**\n\t * Adds channel types to this option.\n\t *\n\t * @param channelTypes - The channel types\n\t */\n\tpublic addChannelTypes(...channelTypes: ApplicationCommandOptionAllowedChannelTypes[]) {\n\t\tif (this.channel_types === undefined) {\n\t\t\tReflect.set(this, 'channel_types', []);\n\t\t}\n\n\t\tthis.channel_types!.push(...channelTypesPredicate.parse(channelTypes));\n\n\t\treturn this;\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandIntegerOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\n\nconst numberValidator = s.number.int;\n\n/**\n * A slash command integer option.\n */\n@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)\nexport class SlashCommandIntegerOption\n\textends ApplicationCommandOptionBase\n\timplements ApplicationCommandNumericOptionMinMaxValueMixin\n{\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Integer as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}\n\t */\n\tpublic setMaxValue(max: number): this {\n\t\tnumberValidator.parse(max);\n\n\t\tReflect.set(this, 'max_value', max);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}\n\t */\n\tpublic setMinValue(min: number): this {\n\t\tnumberValidator.parse(min);\n\n\t\tReflect.set(this, 'min_value', min);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandIntegerOption {\n\t\tthis.runRequiredValidations();\n\n\t\tif (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\treturn { ...this } as APIApplicationCommandIntegerOption;\n\t}\n}\n\nexport interface SlashCommandIntegerOption\n\textends ApplicationCommandNumericOptionMinMaxValueMixin,\n\t\tApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> {}\n","/**\n * This mixin holds minimum and maximum symbols used for options.\n */\nexport abstract class ApplicationCommandNumericOptionMinMaxValueMixin {\n\t/**\n\t * The maximum value of this option.\n\t */\n\tpublic readonly max_value?: number;\n\n\t/**\n\t * The minimum value of this option.\n\t */\n\tpublic readonly min_value?: number;\n\n\t/**\n\t * Sets the maximum number value of this option.\n\t *\n\t * @param max - The maximum value this option can be\n\t */\n\tpublic abstract setMaxValue(max: number): this;\n\n\t/**\n\t * Sets the minimum number value of this option.\n\t *\n\t * @param min - The minimum value this option can be\n\t */\n\tpublic abstract setMinValue(min: number): this;\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandOptionChoice } from 'discord-api-types/v10';\nimport { localizationMapPredicate, validateChoicesLength } from '../Assertions.js';\n\nconst stringPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);\nconst numberPredicate = s.number.greaterThan(Number.NEGATIVE_INFINITY).lessThan(Number.POSITIVE_INFINITY);\nconst choicesPredicate = s.object({\n\tname: stringPredicate,\n\tname_localizations: localizationMapPredicate,\n\tvalue: s.union(stringPredicate, numberPredicate),\n}).array;\nconst booleanPredicate = s.boolean;\n\n/**\n * This mixin holds choices and autocomplete symbols used for options.\n */\nexport class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends number | string> {\n\t/**\n\t * The choices of this option.\n\t */\n\tpublic readonly choices?: APIApplicationCommandOptionChoice<T>[];\n\n\t/**\n\t * Whether this option utilizes autocomplete.\n\t */\n\tpublic readonly autocomplete?: boolean;\n\n\t/**\n\t * The type of this option.\n\t *\n\t * @privateRemarks Since this is present and this is a mixin, this is needed.\n\t */\n\tpublic readonly type!: ApplicationCommandOptionType;\n\n\t/**\n\t * Adds multiple choices to this option.\n\t *\n\t * @param choices - The choices to add\n\t */\n\tpublic addChoices(...choices: APIApplicationCommandOptionChoice<T>[]): this {\n\t\tif (choices.length > 0 && this.autocomplete) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\tchoicesPredicate.parse(choices);\n\n\t\tif (this.choices === undefined) {\n\t\t\tReflect.set(this, 'choices', []);\n\t\t}\n\n\t\tvalidateChoicesLength(choices.length, this.choices);\n\n\t\tfor (const { name, name_localizations, value } of choices) {\n\t\t\t// Validate the value\n\t\t\tif (this.type === ApplicationCommandOptionType.String) {\n\t\t\t\tstringPredicate.parse(value);\n\t\t\t} else {\n\t\t\t\tnumberPredicate.parse(value);\n\t\t\t}\n\n\t\t\tthis.choices!.push({ name, name_localizations, value });\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets multiple choices for this option.\n\t *\n\t * @param choices - The choices to set\n\t */\n\tpublic setChoices<Input extends APIApplicationCommandOptionChoice<T>[]>(...choices: Input): this {\n\t\tif (choices.length > 0 && this.autocomplete) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\tchoicesPredicate.parse(choices);\n\n\t\tReflect.set(this, 'choices', []);\n\t\tthis.addChoices(...choices);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Whether this option uses autocomplete.\n\t *\n\t * @param autocomplete - Whether this option should use autocomplete\n\t */\n\tpublic setAutocomplete(autocomplete: boolean): this {\n\t\t// Assert that you actually passed a boolean\n\t\tbooleanPredicate.parse(autocomplete);\n\n\t\tif (autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\tReflect.set(this, 'autocomplete', autocomplete);\n\n\t\treturn this;\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandMentionableOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command mentionable option.\n */\nexport class SlashCommandMentionableOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Mentionable as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandMentionableOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandNumberOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\n\nconst numberValidator = s.number;\n\n/**\n * A slash command number option.\n */\n@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)\nexport class SlashCommandNumberOption\n\textends ApplicationCommandOptionBase\n\timplements ApplicationCommandNumericOptionMinMaxValueMixin\n{\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Number as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}\n\t */\n\tpublic setMaxValue(max: number): this {\n\t\tnumberValidator.parse(max);\n\n\t\tReflect.set(this, 'max_value', max);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}\n\t */\n\tpublic setMinValue(min: number): this {\n\t\tnumberValidator.parse(min);\n\n\t\tReflect.set(this, 'min_value', min);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandNumberOption {\n\t\tthis.runRequiredValidations();\n\n\t\tif (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\treturn { ...this } as APIApplicationCommandNumberOption;\n\t}\n}\n\nexport interface SlashCommandNumberOption\n\textends ApplicationCommandNumericOptionMinMaxValueMixin,\n\t\tApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> {}\n","import { ApplicationCommandOptionType, type APIApplicationCommandRoleOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command role option.\n */\nexport class SlashCommandRoleOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic override readonly type = ApplicationCommandOptionType.Role as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandRoleOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandStringOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\n\nconst minLengthValidator = s.number.greaterThanOrEqual(0).lessThanOrEqual(6_000);\nconst maxLengthValidator = s.number.greaterThanOrEqual(1).lessThanOrEqual(6_000);\n\n/**\n * A slash command string option.\n */\n@mix(ApplicationCommandOptionWithChoicesAndAutocompleteMixin)\nexport class SlashCommandStringOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.String as const;\n\n\t/**\n\t * The maximum length of this option.\n\t */\n\tpublic readonly max_length?: number;\n\n\t/**\n\t * The minimum length of this option.\n\t */\n\tpublic readonly min_length?: number;\n\n\t/**\n\t * Sets the maximum length of this string option.\n\t *\n\t * @param max - The maximum length this option can be\n\t */\n\tpublic setMaxLength(max: number): this {\n\t\tmaxLengthValidator.parse(max);\n\n\t\tReflect.set(this, 'max_length', max);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the minimum length of this string option.\n\t *\n\t * @param min - The minimum length this option can be\n\t */\n\tpublic setMinLength(min: number): this {\n\t\tminLengthValidator.parse(min);\n\n\t\tReflect.set(this, 'min_length', min);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandStringOption {\n\t\tthis.runRequiredValidations();\n\n\t\tif (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\treturn { ...this } as APIApplicationCommandStringOption;\n\t}\n}\n\nexport interface SlashCommandStringOption extends ApplicationCommandOptionWithChoicesAndAutocompleteMixin<string> {}\n","import { ApplicationCommandOptionType, type APIApplicationCommandUserOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command user option.\n */\nexport class SlashCommandUserOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.User as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandUserOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { assertReturnOfBuilder, validateMaxOptionsLength } from '../Assertions.js';\nimport type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder';\nimport { SlashCommandAttachmentOption } from '../options/attachment.js';\nimport { SlashCommandBooleanOption } from '../options/boolean.js';\nimport { SlashCommandChannelOption } from '../options/channel.js';\nimport { SlashCommandIntegerOption } from '../options/integer.js';\nimport { SlashCommandMentionableOption } from '../options/mentionable.js';\nimport { SlashCommandNumberOption } from '../options/number.js';\nimport { SlashCommandRoleOption } from '../options/role.js';\nimport { SlashCommandStringOption } from '../options/string.js';\nimport { SlashCommandUserOption } from '../options/user.js';\nimport type { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';\n\n/**\n * This mixin holds symbols that can be shared in slash command options.\n *\n * @typeParam ShouldOmitSubcommandFunctions - Whether to omit subcommand functions.\n */\nexport class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {\n\tpublic readonly options!: ToAPIApplicationCommandOptions[];\n\n\t/**\n\t * Adds a boolean option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addBooleanOption(\n\t\tinput: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandBooleanOption);\n\t}\n\n\t/**\n\t * Adds a user option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandUserOption);\n\t}\n\n\t/**\n\t * Adds a channel option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addChannelOption(\n\t\tinput: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandChannelOption);\n\t}\n\n\t/**\n\t * Adds a role option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandRoleOption);\n\t}\n\n\t/**\n\t * Adds an attachment option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addAttachmentOption(\n\t\tinput: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandAttachmentOption);\n\t}\n\n\t/**\n\t * Adds a mentionable option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addMentionableOption(\n\t\tinput: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandMentionableOption);\n\t}\n\n\t/**\n\t * Adds a string option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addStringOption(\n\t\tinput:\n\t\t\t| Omit<SlashCommandStringOption, 'addChoices'>\n\t\t\t| Omit<SlashCommandStringOption, 'setAutocomplete'>\n\t\t\t| SlashCommandStringOption\n\t\t\t| ((\n\t\t\t\t\tbuilder: SlashCommandStringOption,\n\t\t\t ) =>\n\t\t\t\t\t| Omit<SlashCommandStringOption, 'addChoices'>\n\t\t\t\t\t| Omit<SlashCommandStringOption, 'setAutocomplete'>\n\t\t\t\t\t| SlashCommandStringOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandStringOption);\n\t}\n\n\t/**\n\t * Adds an integer option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addIntegerOption(\n\t\tinput:\n\t\t\t| Omit<SlashCommandIntegerOption, 'addChoices'>\n\t\t\t| Omit<SlashCommandIntegerOption, 'setAutocomplete'>\n\t\t\t| SlashCommandIntegerOption\n\t\t\t| ((\n\t\t\t\t\tbuilder: SlashCommandIntegerOption,\n\t\t\t ) =>\n\t\t\t\t\t| Omit<SlashCommandIntegerOption, 'addChoices'>\n\t\t\t\t\t| Omit<SlashCommandIntegerOption, 'setAutocomplete'>\n\t\t\t\t\t| SlashCommandIntegerOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandIntegerOption);\n\t}\n\n\t/**\n\t * Adds a number option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addNumberOption(\n\t\tinput:\n\t\t\t| Omit<SlashCommandNumberOption, 'addChoices'>\n\t\t\t| Omit<SlashCommandNumberOption, 'setAutocomplete'>\n\t\t\t| SlashCommandNumberOption\n\t\t\t| ((\n\t\t\t\t\tbuilder: SlashCommandNumberOption,\n\t\t\t ) =>\n\t\t\t\t\t| Omit<SlashCommandNumberOption, 'addChoices'>\n\t\t\t\t\t| Omit<SlashCommandNumberOption, 'setAutocomplete'>\n\t\t\t\t\t| SlashCommandNumberOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandNumberOption);\n\t}\n\n\t/**\n\t * Where the actual adding magic happens. ✨\n\t *\n\t * @param input - The input. What else?\n\t * @param Instance - The instance of whatever is being added\n\t * @internal\n\t */\n\tprivate _sharedAddOptionMethod<T extends ApplicationCommandOptionBase>(\n\t\tinput:\n\t\t\t| Omit<T, 'addChoices'>\n\t\t\t| Omit<T, 'setAutocomplete'>\n\t\t\t| T\n\t\t\t| ((builder: T) => Omit<T, 'addChoices'> | Omit<T, 'setAutocomplete'> | T),\n\t\tInstance: new () => T,\n\t): ShouldOmitSubcommandFunctions extends true ? Omit<this, 'addSubcommand' | 'addSubcommandGroup'> : this {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\tconst result = typeof input === 'function' ? input(new Instance()) : input;\n\n\t\tassertReturnOfBuilder(result, Instance);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandType } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\nimport type { ContextMenuCommandType } from './ContextMenuCommandBuilder.js';\n\nconst namePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(32)\n\t// eslint-disable-next-line prefer-named-capture-group, unicorn/no-unsafe-regex\n\t.regex(/^( *[\\p{P}\\p{L}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}]+ *)+$/u)\n\t.setValidationEnabled(isValidationEnabled);\nconst typePredicate = s\n\t.union(s.literal(ApplicationCommandType.User), s.literal(ApplicationCommandType.Message))\n\t.setValidationEnabled(isValidationEnabled);\nconst booleanPredicate = s.boolean;\n\nexport function validateDefaultPermission(value: unknown): asserts value is boolean {\n\tbooleanPredicate.parse(value);\n}\n\nexport function validateName(name: unknown): asserts name is string {\n\tnamePredicate.parse(name);\n}\n\nexport function validateType(type: unknown): asserts type is ContextMenuCommandType {\n\ttypePredicate.parse(type);\n}\n\nexport function validateRequiredParameters(name: string, type: number) {\n\t// Assert name matches all conditions\n\tvalidateName(name);\n\n\t// Assert type is valid\n\tvalidateType(type);\n}\n\nconst dmPermissionPredicate = s.boolean.nullish;\n\nexport function validateDMPermission(value: unknown): asserts value is boolean | null | undefined {\n\tdmPermissionPredicate.parse(value);\n}\n\nconst memberPermissionPredicate = s.union(\n\ts.bigint.transform((value) => value.toString()),\n\ts.number.safeInt.transform((value) => value.toString()),\n\ts.string.regex(/^\\d+$/),\n).nullish;\n\nexport function validateDefaultMemberPermissions(permissions: unknown) {\n\treturn memberPermissionPredicate.parse(permissions);\n}\n","import type {\n\tApplicationCommandType,\n\tLocaleString,\n\tLocalizationMap,\n\tPermissions,\n\tRESTPostAPIContextMenuApplicationCommandsJSONBody,\n} from 'discord-api-types/v10';\nimport { validateLocale, validateLocalizationMap } from '../slashCommands/Assertions.js';\nimport {\n\tvalidateRequiredParameters,\n\tvalidateName,\n\tvalidateType,\n\tvalidateDefaultPermission,\n\tvalidateDefaultMemberPermissions,\n\tvalidateDMPermission,\n} from './Assertions.js';\n\n/**\n * The type a context menu command can be.\n */\nexport type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;\n\n/**\n * A builder that creates API-compatible JSON data for context menu commands.\n */\nexport class ContextMenuCommandBuilder {\n\t/**\n\t * The name of this command.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The name localizations of this command.\n\t */\n\tpublic readonly name_localizations?: LocalizationMap;\n\n\t/**\n\t * The type of this command.\n\t */\n\tpublic readonly type: ContextMenuCommandType = undefined!;\n\n\t/**\n\t * Whether this command is enabled by default when the application is added to a guild.\n\t *\n\t * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic readonly default_permission: boolean | undefined = undefined;\n\n\t/**\n\t * The set of permissions represented as a bit set for the command.\n\t */\n\tpublic readonly default_member_permissions: Permissions | null | undefined = undefined;\n\n\t/**\n\t * Indicates whether the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This property is only for global commands.\n\t */\n\tpublic readonly dm_permission: boolean | undefined = undefined;\n\n\t/**\n\t * Sets the name of this command.\n\t *\n\t * @param name - The name to use\n\t */\n\tpublic setName(name: string) {\n\t\t// Assert the name matches the conditions\n\t\tvalidateName(name);\n\n\t\tReflect.set(this, 'name', name);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the type of this command.\n\t *\n\t * @param type - The type to use\n\t */\n\tpublic setType(type: ContextMenuCommandType) {\n\t\t// Assert the type is valid\n\t\tvalidateType(type);\n\n\t\tReflect.set(this, 'type', type);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether the command is enabled by default when the application is added to a guild.\n\t *\n\t * @remarks\n\t * If set to `false`, you will have to later `PUT` the permissions for this command.\n\t * @param value - Whether to enable this command by default\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic setDefaultPermission(value: boolean) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDefaultPermission(value);\n\n\t\tReflect.set(this, 'default_permission', value);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the default permissions a member should have in order to run this command.\n\t *\n\t * @remarks\n\t * You can set this to `'0'` to disable the command by default.\n\t * @param permissions - The permissions bit field to set\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {\n\t\t// Assert the value and parse it\n\t\tconst permissionValue = validateDefaultMemberPermissions(permissions);\n\n\t\tReflect.set(this, 'default_member_permissions', permissionValue);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets if the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This method is only for global commands.\n\t * @param enabled - Whether the command should be enabled in direct messages\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDMPermission(enabled: boolean | null | undefined) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDMPermission(enabled);\n\n\t\tReflect.set(this, 'dm_permission', enabled);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets a name localization for this command.\n\t *\n\t * @param locale - The locale to set\n\t * @param localizedName - The localized name for the given `locale`\n\t */\n\tpublic setNameLocalization(locale: LocaleString, localizedName: string | null) {\n\t\tif (!this.name_localizations) {\n\t\t\tReflect.set(this, 'name_localizations', {});\n\t\t}\n\n\t\tconst parsedLocale = validateLocale(locale);\n\n\t\tif (localizedName === null) {\n\t\t\tthis.name_localizations![parsedLocale] = null;\n\t\t\treturn this;\n\t\t}\n\n\t\tvalidateName(localizedName);\n\n\t\tthis.name_localizations![parsedLocale] = localizedName;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the name localizations for this command.\n\t *\n\t * @param localizedNames - The object of localized names to set\n\t */\n\tpublic setNameLocalizations(localizedNames: LocalizationMap | null) {\n\t\tif (localizedNames === null) {\n\t\t\tReflect.set(this, 'name_localizations', null);\n\t\t\treturn this;\n\t\t}\n\n\t\tReflect.set(this, 'name_localizations', {});\n\n\t\tfor (const args of Object.entries(localizedNames))\n\t\t\tthis.setNameLocalization(...(args as [LocaleString, string | null]));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): RESTPostAPIContextMenuApplicationCommandsJSONBody {\n\t\tvalidateRequiredParameters(this.name, this.type);\n\n\t\tvalidateLocalizationMap(this.name_localizations);\n\n\t\treturn { ...this };\n\t}\n}\n","import type { APIEmbed } from 'discord-api-types/v10';\n\n/**\n * Calculates the length of the embed.\n *\n * @param data - The embed data to check\n */\nexport function embedLength(data: APIEmbed) {\n\treturn (\n\t\t(data.title?.length ?? 0) +\n\t\t(data.description?.length ?? 0) +\n\t\t(data.fields?.reduce((pr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,MAAM,KAAK,IAAI;AAE/C,4BAAwB,KAAK,kBAAkB;AAE/C,WAAO,EAAE,GAAG,KAAK;AAAA,EAClB;AACD;;;AC9LO,SAAS,YAAY,MAAgB;AAC3C,UACE,KAAK,OAAO,UAAU,MACtB,KAAK,aAAa,UAAU,MAC5B,KAAK,QAAQ,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,SAAS,KAAK,MAAM,QAAQ,CAAC,KAAK,MACvF,KAAK,QAAQ,KAAK,UAAU,MAC5B,KAAK,QAAQ,KAAK,UAAU;AAE/B;AARgB;;;AzC6DT,IAAM,UAAU;","names":["Assertions_exports","Assertions_exports","import_shapeshift","import_v10","import_v10","import_v10","import_v10","import_v10","import_v10","import_v10","import_v10","import_v10","Assertions_exports","placeholderValidator","import_shapeshift","import_v10","placeholderValidator","placeholderValidator","isEqual","Assertions_exports","validateRequiredParameters","import_shapeshift","validateRequiredParameters","validateRequiredParameters","Assertions_exports","validateRequiredParameters","import_shapeshift","import_v10","descriptionPredicate","validateRequiredParameters","import_ts_mixer","import_v10","import_ts_mixer","import_v10","validateRequiredParameters","import_v10","import_v10","import_shapeshift","import_v10","import_shapeshift","import_v10","import_ts_mixer","import_shapeshift","import_v10","booleanPredicate","import_v10","import_shapeshift","import_v10","import_ts_mixer","numberValidator","import_v10","import_shapeshift","import_v10","import_ts_mixer","minLengthValidator","maxLengthValidator","import_v10","validateRequiredParameters","validateRequiredParameters","Assertions_exports","validateDMPermission","validateDefaultMemberPermissions","validateDefaultPermission","validateName","validateRequiredParameters","import_shapeshift","import_v10","namePredicate","booleanPredicate","validateDefaultPermission","validateName","validateRequiredParameters","dmPermissionPredicate","validateDMPermission","memberPermissionPredicate","validateDefaultMemberPermissions","validateName","validateDefaultPermission","validateDefaultMemberPermissions","validateDMPermission","validateRequiredParameters"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/builders/dist/index.mjs b/node_modules/@discordjs/builders/dist/index.mjs new file mode 100644 index 0000000..6577d9b --- /dev/null +++ b/node_modules/@discordjs/builders/dist/index.mjs @@ -0,0 +1,2540 @@ +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __decorateClass = (decorators, target, key, kind) => { + var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; + for (var i = decorators.length - 1, decorator; i >= 0; i--) + if (decorator = decorators[i]) + result = (kind ? decorator(target, key, result) : decorator(result)) || result; + if (kind && result) + __defProp(target, key, result); + return result; +}; + +// src/messages/embed/Assertions.ts +var Assertions_exports = {}; +__export(Assertions_exports, { + RGBPredicate: () => RGBPredicate, + authorNamePredicate: () => authorNamePredicate, + colorPredicate: () => colorPredicate, + descriptionPredicate: () => descriptionPredicate, + embedAuthorPredicate: () => embedAuthorPredicate, + embedFieldPredicate: () => embedFieldPredicate, + embedFieldsArrayPredicate: () => embedFieldsArrayPredicate, + embedFooterPredicate: () => embedFooterPredicate, + fieldInlinePredicate: () => fieldInlinePredicate, + fieldLengthPredicate: () => fieldLengthPredicate, + fieldNamePredicate: () => fieldNamePredicate, + fieldValuePredicate: () => fieldValuePredicate, + footerTextPredicate: () => footerTextPredicate, + imageURLPredicate: () => imageURLPredicate, + timestampPredicate: () => timestampPredicate, + titlePredicate: () => titlePredicate, + urlPredicate: () => urlPredicate, + validateFieldLength: () => validateFieldLength +}); +import { s } from "@sapphire/shapeshift"; + +// src/util/validation.ts +var validate = true; +function enableValidators() { + return validate = true; +} +__name(enableValidators, "enableValidators"); +function disableValidators() { + return validate = false; +} +__name(disableValidators, "disableValidators"); +function isValidationEnabled() { + return validate; +} +__name(isValidationEnabled, "isValidationEnabled"); + +// src/messages/embed/Assertions.ts +var fieldNamePredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(256).setValidationEnabled(isValidationEnabled); +var fieldValuePredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(1024).setValidationEnabled(isValidationEnabled); +var fieldInlinePredicate = s.boolean.optional; +var embedFieldPredicate = s.object({ + name: fieldNamePredicate, + value: fieldValuePredicate, + inline: fieldInlinePredicate +}).setValidationEnabled(isValidationEnabled); +var embedFieldsArrayPredicate = embedFieldPredicate.array.setValidationEnabled(isValidationEnabled); +var fieldLengthPredicate = s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateFieldLength(amountAdding, fields) { + fieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding); +} +__name(validateFieldLength, "validateFieldLength"); +var authorNamePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled); +var imageURLPredicate = s.string.url({ + allowedProtocols: ["http:", "https:", "attachment:"] +}).nullish.setValidationEnabled(isValidationEnabled); +var urlPredicate = s.string.url({ + allowedProtocols: ["http:", "https:"] +}).nullish.setValidationEnabled(isValidationEnabled); +var embedAuthorPredicate = s.object({ + name: authorNamePredicate, + iconURL: imageURLPredicate, + url: urlPredicate +}).setValidationEnabled(isValidationEnabled); +var RGBPredicate = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(255).setValidationEnabled(isValidationEnabled); +var colorPredicate = s.number.int.greaterThanOrEqual(0).lessThanOrEqual(16777215).or(s.tuple([RGBPredicate, RGBPredicate, RGBPredicate])).nullable.setValidationEnabled(isValidationEnabled); +var descriptionPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(4096).nullable.setValidationEnabled(isValidationEnabled); +var footerTextPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(2048).nullable.setValidationEnabled(isValidationEnabled); +var embedFooterPredicate = s.object({ + text: footerTextPredicate, + iconURL: imageURLPredicate +}).setValidationEnabled(isValidationEnabled); +var timestampPredicate = s.union(s.number, s.date).nullable.setValidationEnabled(isValidationEnabled); +var titlePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled); + +// src/util/normalizeArray.ts +function normalizeArray(arr) { + if (Array.isArray(arr[0])) + return arr[0]; + return arr; +} +__name(normalizeArray, "normalizeArray"); + +// src/messages/embed/Embed.ts +var EmbedBuilder = class { + static { + __name(this, "EmbedBuilder"); + } + /** + * The API data associated with this embed. + */ + data; + /** + * Creates a new embed from API data. + * + * @param data - The API data to create this embed with + */ + constructor(data = {}) { + this.data = { ...data }; + if (data.timestamp) + this.data.timestamp = new Date(data.timestamp).toISOString(); + } + /** + * Appends fields to the embed. + * + * @remarks + * This method accepts either an array of fields or a variable number of field parameters. + * The maximum amount of fields that can be added is 25. + * @example + * Using an array: + * ```ts + * const fields: APIEmbedField[] = ...; + * const embed = new EmbedBuilder() + * .addFields(fields); + * ``` + * @example + * Using rest parameters (variadic): + * ```ts + * const embed = new EmbedBuilder() + * .addFields( + * { name: 'Field 1', value: 'Value 1' }, + * { name: 'Field 2', value: 'Value 2' }, + * ); + * ``` + * @param fields - The fields to add + */ + addFields(...fields) { + const normalizedFields = normalizeArray(fields); + validateFieldLength(normalizedFields.length, this.data.fields); + embedFieldsArrayPredicate.parse(normalizedFields); + if (this.data.fields) + this.data.fields.push(...normalizedFields); + else + this.data.fields = normalizedFields; + return this; + } + /** + * Removes, replaces, or inserts fields for this embed. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}. + * The maximum amount of fields that can be added is 25. + * + * It's useful for modifying and adjusting order of the already-existing fields of an embed. + * @example + * Remove the first field: + * ```ts + * embed.spliceFields(0, 1); + * ``` + * @example + * Remove the first n fields: + * ```ts + * const n = 4; + * embed.spliceFields(0, n); + * ``` + * @example + * Remove the last field: + * ```ts + * embed.spliceFields(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of fields to remove + * @param fields - The replacing field objects + */ + spliceFields(index, deleteCount, ...fields) { + validateFieldLength(fields.length - deleteCount, this.data.fields); + embedFieldsArrayPredicate.parse(fields); + if (this.data.fields) + this.data.fields.splice(index, deleteCount, ...fields); + else + this.data.fields = fields; + return this; + } + /** + * Sets the fields for this embed. + * + * @remarks + * This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically, + * it splices the entire array of fields, replacing them with the provided fields. + * + * You can set a maximum of 25 fields. + * @param fields - The fields to set + */ + setFields(...fields) { + this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields)); + return this; + } + /** + * Sets the author of this embed. + * + * @param options - The options to use + */ + setAuthor(options) { + if (options === null) { + this.data.author = void 0; + return this; + } + embedAuthorPredicate.parse(options); + this.data.author = { name: options.name, url: options.url, icon_url: options.iconURL }; + return this; + } + /** + * Sets the color of this embed. + * + * @param color - The color to use + */ + setColor(color) { + colorPredicate.parse(color); + if (Array.isArray(color)) { + const [red, green, blue] = color; + this.data.color = (red << 16) + (green << 8) + blue; + return this; + } + this.data.color = color ?? void 0; + return this; + } + /** + * Sets the description of this embed. + * + * @param description - The description to use + */ + setDescription(description) { + descriptionPredicate.parse(description); + this.data.description = description ?? void 0; + return this; + } + /** + * Sets the footer of this embed. + * + * @param options - The footer to use + */ + setFooter(options) { + if (options === null) { + this.data.footer = void 0; + return this; + } + embedFooterPredicate.parse(options); + this.data.footer = { text: options.text, icon_url: options.iconURL }; + return this; + } + /** + * Sets the image of this embed. + * + * @param url - The image URL to use + */ + setImage(url) { + imageURLPredicate.parse(url); + this.data.image = url ? { url } : void 0; + return this; + } + /** + * Sets the thumbnail of this embed. + * + * @param url - The thumbnail URL to use + */ + setThumbnail(url) { + imageURLPredicate.parse(url); + this.data.thumbnail = url ? { url } : void 0; + return this; + } + /** + * Sets the timestamp of this embed. + * + * @param timestamp - The timestamp or date to use + */ + setTimestamp(timestamp = Date.now()) { + timestampPredicate.parse(timestamp); + this.data.timestamp = timestamp ? new Date(timestamp).toISOString() : void 0; + return this; + } + /** + * Sets the title for this embed. + * + * @param title - The title to use + */ + setTitle(title) { + titlePredicate.parse(title); + this.data.title = title ?? void 0; + return this; + } + /** + * Sets the URL of this embed. + * + * @param url - The URL to use + */ + setURL(url) { + urlPredicate.parse(url); + this.data.url = url ?? void 0; + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + return { ...this.data }; + } +}; + +// src/index.ts +export * from "@discordjs/formatters"; + +// src/components/Assertions.ts +var Assertions_exports2 = {}; +__export(Assertions_exports2, { + buttonLabelValidator: () => buttonLabelValidator, + buttonStyleValidator: () => buttonStyleValidator, + channelTypesValidator: () => channelTypesValidator, + customIdValidator: () => customIdValidator, + defaultValidator: () => defaultValidator, + disabledValidator: () => disabledValidator, + emojiValidator: () => emojiValidator, + jsonOptionValidator: () => jsonOptionValidator, + labelValueDescriptionValidator: () => labelValueDescriptionValidator, + minMaxValidator: () => minMaxValidator, + optionValidator: () => optionValidator, + optionsLengthValidator: () => optionsLengthValidator, + optionsValidator: () => optionsValidator, + placeholderValidator: () => placeholderValidator, + urlValidator: () => urlValidator, + validateRequiredButtonParameters: () => validateRequiredButtonParameters, + validateRequiredSelectMenuOptionParameters: () => validateRequiredSelectMenuOptionParameters, + validateRequiredSelectMenuParameters: () => validateRequiredSelectMenuParameters +}); +import { s as s2 } from "@sapphire/shapeshift"; +import { ButtonStyle, ChannelType } from "discord-api-types/v10"; + +// src/components/selectMenu/StringSelectMenuOption.ts +var StringSelectMenuOptionBuilder = class { + /** + * Creates a new string select menu option from API data. + * + * @param data - The API data to create this string select menu option with + * @example + * Creating a string select menu option from an API data object: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * label: 'catchy label', + * value: '1', + * }); + * ``` + * @example + * Creating a string select menu option using setters and API data: + * ```ts + * const selectMenuOption = new SelectMenuOptionBuilder({ + * default: true, + * value: '1', + * }) + * .setLabel('woah'); + * ``` + */ + constructor(data = {}) { + this.data = data; + } + static { + __name(this, "StringSelectMenuOptionBuilder"); + } + /** + * Sets the label for this option. + * + * @param label - The label to use + */ + setLabel(label) { + this.data.label = labelValueDescriptionValidator.parse(label); + return this; + } + /** + * Sets the value for this option. + * + * @param value - The value to use + */ + setValue(value) { + this.data.value = labelValueDescriptionValidator.parse(value); + return this; + } + /** + * Sets the description for this option. + * + * @param description - The description to use + */ + setDescription(description) { + this.data.description = labelValueDescriptionValidator.parse(description); + return this; + } + /** + * Sets whether this option is selected by default. + * + * @param isDefault - Whether this option is selected by default + */ + setDefault(isDefault = true) { + this.data.default = defaultValidator.parse(isDefault); + return this; + } + /** + * Sets the emoji to display for this option. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji) { + this.data.emoji = emojiValidator.parse(emoji); + return this; + } + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON() { + validateRequiredSelectMenuOptionParameters(this.data.label, this.data.value); + return { + ...this.data + }; + } +}; + +// src/components/Assertions.ts +var customIdValidator = s2.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var emojiValidator = s2.object({ + id: s2.string, + name: s2.string, + animated: s2.boolean +}).partial.strict.setValidationEnabled(isValidationEnabled); +var disabledValidator = s2.boolean; +var buttonLabelValidator = s2.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(80).setValidationEnabled(isValidationEnabled); +var buttonStyleValidator = s2.nativeEnum(ButtonStyle); +var placeholderValidator = s2.string.lengthLessThanOrEqual(150).setValidationEnabled(isValidationEnabled); +var minMaxValidator = s2.number.int.greaterThanOrEqual(0).lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +var labelValueDescriptionValidator = s2.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var jsonOptionValidator = s2.object({ + label: labelValueDescriptionValidator, + value: labelValueDescriptionValidator, + description: labelValueDescriptionValidator.optional, + emoji: emojiValidator.optional, + default: s2.boolean.optional +}).setValidationEnabled(isValidationEnabled); +var optionValidator = s2.instance(StringSelectMenuOptionBuilder).setValidationEnabled(isValidationEnabled); +var optionsValidator = optionValidator.array.lengthGreaterThanOrEqual(0).setValidationEnabled(isValidationEnabled); +var optionsLengthValidator = s2.number.int.greaterThanOrEqual(0).lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateRequiredSelectMenuParameters(options, customId) { + customIdValidator.parse(customId); + optionsValidator.parse(options); +} +__name(validateRequiredSelectMenuParameters, "validateRequiredSelectMenuParameters"); +var defaultValidator = s2.boolean; +function validateRequiredSelectMenuOptionParameters(label, value) { + labelValueDescriptionValidator.parse(label); + labelValueDescriptionValidator.parse(value); +} +__name(validateRequiredSelectMenuOptionParameters, "validateRequiredSelectMenuOptionParameters"); +var channelTypesValidator = s2.nativeEnum(ChannelType).array.setValidationEnabled(isValidationEnabled); +var urlValidator = s2.string.url({ + allowedProtocols: ["http:", "https:", "discord:"] +}).setValidationEnabled(isValidationEnabled); +function validateRequiredButtonParameters(style, label, emoji, customId, url) { + if (url && customId) { + throw new RangeError("URL and custom id are mutually exclusive"); + } + if (!label && !emoji) { + throw new RangeError("Buttons must have a label and/or an emoji"); + } + if (style === ButtonStyle.Link) { + if (!url) { + throw new RangeError("Link buttons must have a url"); + } + } else if (url) { + throw new RangeError("Non-link buttons cannot have a url"); + } +} +__name(validateRequiredButtonParameters, "validateRequiredButtonParameters"); + +// src/components/ActionRow.ts +import { + ComponentType as ComponentType9 +} from "discord-api-types/v10"; + +// src/components/Component.ts +var ComponentBuilder = class { + static { + __name(this, "ComponentBuilder"); + } + /** + * The API data associated with this component. + */ + data; + /** + * Constructs a new kind of component. + * + * @param data - The data to construct a component out of + */ + constructor(data) { + this.data = data; + } +}; + +// src/components/Components.ts +import { ComponentType as ComponentType8 } from "discord-api-types/v10"; + +// src/components/button/Button.ts +import { + ComponentType +} from "discord-api-types/v10"; +var ButtonBuilder = class extends ComponentBuilder { + static { + __name(this, "ButtonBuilder"); + } + /** + * Creates a new button from API data. + * + * @param data - The API data to create this button with + * @example + * Creating a button from an API data object: + * ```ts + * const button = new ButtonBuilder({ + * custom_id: 'a cool button', + * style: ButtonStyle.Primary, + * label: 'Click Me', + * emoji: { + * name: 'smile', + * id: '123456789012345678', + * }, + * }); + * ``` + * @example + * Creating a button using setters and API data: + * ```ts + * const button = new ButtonBuilder({ + * style: ButtonStyle.Secondary, + * label: 'Click Me', + * }) + * .setEmoji({ name: '🙂' }) + * .setCustomId('another cool button'); + * ``` + */ + constructor(data) { + super({ type: ComponentType.Button, ...data }); + } + /** + * Sets the style of this button. + * + * @param style - The style to use + */ + setStyle(style) { + this.data.style = buttonStyleValidator.parse(style); + return this; + } + /** + * Sets the URL for this button. + * + * @remarks + * This method is only available to buttons using the `Link` button style. + * Only three types of URL schemes are currently supported: `https://`, `http://`, and `discord://`. + * @param url - The URL to use + */ + setURL(url) { + this.data.url = urlValidator.parse(url); + return this; + } + /** + * Sets the custom id for this button. + * + * @remarks + * This method is only applicable to buttons that are not using the `Link` button style. + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Sets the emoji to display on this button. + * + * @param emoji - The emoji to use + */ + setEmoji(emoji) { + this.data.emoji = emojiValidator.parse(emoji); + return this; + } + /** + * Sets whether this button is disabled. + * + * @param disabled - Whether to disable this button + */ + setDisabled(disabled = true) { + this.data.disabled = disabledValidator.parse(disabled); + return this; + } + /** + * Sets the label for this button. + * + * @param label - The label to use + */ + setLabel(label) { + this.data.label = buttonLabelValidator.parse(label); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + validateRequiredButtonParameters( + this.data.style, + this.data.label, + this.data.emoji, + this.data.custom_id, + this.data.url + ); + return { + ...this.data + }; + } +}; + +// src/components/selectMenu/ChannelSelectMenu.ts +import { ComponentType as ComponentType2 } from "discord-api-types/v10"; + +// src/components/selectMenu/BaseSelectMenu.ts +var BaseSelectMenuBuilder = class extends ComponentBuilder { + static { + __name(this, "BaseSelectMenuBuilder"); + } + /** + * Sets the placeholder for this select menu. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder) { + this.data.placeholder = placeholderValidator.parse(placeholder); + return this; + } + /** + * Sets the minimum values that must be selected in the select menu. + * + * @param minValues - The minimum values that must be selected + */ + setMinValues(minValues) { + this.data.min_values = minMaxValidator.parse(minValues); + return this; + } + /** + * Sets the maximum values that must be selected in the select menu. + * + * @param maxValues - The maximum values that must be selected + */ + setMaxValues(maxValues) { + this.data.max_values = minMaxValidator.parse(maxValues); + return this; + } + /** + * Sets the custom id for this select menu. + * + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Sets whether this select menu is disabled. + * + * @param disabled - Whether this select menu is disabled + */ + setDisabled(disabled = true) { + this.data.disabled = disabledValidator.parse(disabled); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + customIdValidator.parse(this.data.custom_id); + return { + ...this.data + }; + } +}; + +// src/components/selectMenu/ChannelSelectMenu.ts +var ChannelSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "ChannelSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new ChannelSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement) + * .setMinValues(2); + * ``` + */ + constructor(data) { + super({ ...data, type: ComponentType2.ChannelSelect }); + } + /** + * Adds channel types to this select menu. + * + * @param types - The channel types to use + */ + addChannelTypes(...types) { + const normalizedTypes = normalizeArray(types); + this.data.channel_types ??= []; + this.data.channel_types.push(...channelTypesValidator.parse(normalizedTypes)); + return this; + } + /** + * Sets channel types for this select menu. + * + * @param types - The channel types to use + */ + setChannelTypes(...types) { + const normalizedTypes = normalizeArray(types); + this.data.channel_types ??= []; + this.data.channel_types.splice(0, this.data.channel_types.length, ...channelTypesValidator.parse(normalizedTypes)); + return this; + } + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON() { + customIdValidator.parse(this.data.custom_id); + return { + ...this.data + }; + } +}; + +// src/components/selectMenu/MentionableSelectMenu.ts +import { ComponentType as ComponentType3 } from "discord-api-types/v10"; +var MentionableSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "MentionableSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new MentionableSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data) { + super({ ...data, type: ComponentType3.MentionableSelect }); + } +}; + +// src/components/selectMenu/RoleSelectMenu.ts +import { ComponentType as ComponentType4 } from "discord-api-types/v10"; +var RoleSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "RoleSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new RoleSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data) { + super({ ...data, type: ComponentType4.RoleSelect }); + } +}; + +// src/components/selectMenu/StringSelectMenu.ts +import { ComponentType as ComponentType5 } from "discord-api-types/v10"; +var StringSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "StringSelectMenuBuilder"); + } + /** + * The options within this select menu. + */ + options; + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * options: [ + * { label: 'option 1', value: '1' }, + * { label: 'option 2', value: '2' }, + * { label: 'option 3', value: '3' }, + * ], + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new StringSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1) + * .addOptions({ + * label: 'Catchy', + * value: 'catch', + * }); + * ``` + */ + constructor(data) { + const { options, ...initData } = data ?? {}; + super({ ...initData, type: ComponentType5.StringSelect }); + this.options = options?.map((option) => new StringSelectMenuOptionBuilder(option)) ?? []; + } + /** + * Adds options to this select menu. + * + * @param options - The options to add + */ + addOptions(...options) { + const normalizedOptions = normalizeArray(options); + optionsLengthValidator.parse(this.options.length + normalizedOptions.length); + this.options.push( + ...normalizedOptions.map( + (normalizedOption) => normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)) + ) + ); + return this; + } + /** + * Sets the options for this select menu. + * + * @param options - The options to set + */ + setOptions(...options) { + return this.spliceOptions(0, this.options.length, ...options); + } + /** + * Removes, replaces, or inserts options for this select menu. + * + * @remarks + * This method behaves similarly + * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}. + * It's useful for modifying and adjusting the order of existing options. + * @example + * Remove the first option: + * ```ts + * selectMenu.spliceOptions(0, 1); + * ``` + * @example + * Remove the first n option: + * ```ts + * const n = 4; + * selectMenu.spliceOptions(0, n); + * ``` + * @example + * Remove the last option: + * ```ts + * selectMenu.spliceOptions(-1, 1); + * ``` + * @param index - The index to start at + * @param deleteCount - The number of options to remove + * @param options - The replacing option objects or builders + */ + spliceOptions(index, deleteCount, ...options) { + const normalizedOptions = normalizeArray(options); + const clone = [...this.options]; + clone.splice( + index, + deleteCount, + ...normalizedOptions.map( + (normalizedOption) => normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)) + ) + ); + optionsLengthValidator.parse(clone.length); + this.options.splice(0, this.options.length, ...clone); + return this; + } + /** + * {@inheritDoc BaseSelectMenuBuilder.toJSON} + */ + toJSON() { + validateRequiredSelectMenuParameters(this.options, this.data.custom_id); + return { + ...this.data, + options: this.options.map((option) => option.toJSON()) + }; + } +}; + +// src/components/selectMenu/UserSelectMenu.ts +import { ComponentType as ComponentType6 } from "discord-api-types/v10"; +var UserSelectMenuBuilder = class extends BaseSelectMenuBuilder { + static { + __name(this, "UserSelectMenuBuilder"); + } + /** + * Creates a new select menu from API data. + * + * @param data - The API data to create this select menu with + * @example + * Creating a select menu from an API data object: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * placeholder: 'select an option', + * max_values: 2, + * }); + * ``` + * @example + * Creating a select menu using setters and API data: + * ```ts + * const selectMenu = new UserSelectMenuBuilder({ + * custom_id: 'a cool select menu', + * }) + * .setMinValues(1); + * ``` + */ + constructor(data) { + super({ ...data, type: ComponentType6.UserSelect }); + } +}; + +// src/components/textInput/TextInput.ts +import { isJSONEncodable } from "@discordjs/util"; +import { ComponentType as ComponentType7 } from "discord-api-types/v10"; +import isEqual from "fast-deep-equal"; + +// src/components/textInput/Assertions.ts +var Assertions_exports3 = {}; +__export(Assertions_exports3, { + labelValidator: () => labelValidator, + maxLengthValidator: () => maxLengthValidator, + minLengthValidator: () => minLengthValidator, + placeholderValidator: () => placeholderValidator2, + requiredValidator: () => requiredValidator, + textInputStyleValidator: () => textInputStyleValidator, + validateRequiredParameters: () => validateRequiredParameters, + valueValidator: () => valueValidator +}); +import { s as s3 } from "@sapphire/shapeshift"; +import { TextInputStyle } from "discord-api-types/v10"; +var textInputStyleValidator = s3.nativeEnum(TextInputStyle); +var minLengthValidator = s3.number.int.greaterThanOrEqual(0).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); +var maxLengthValidator = s3.number.int.greaterThanOrEqual(1).lessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); +var requiredValidator = s3.boolean; +var valueValidator = s3.string.lengthLessThanOrEqual(4e3).setValidationEnabled(isValidationEnabled); +var placeholderValidator2 = s3.string.lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var labelValidator = s3.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45).setValidationEnabled(isValidationEnabled); +function validateRequiredParameters(customId, style, label) { + customIdValidator.parse(customId); + textInputStyleValidator.parse(style); + labelValidator.parse(label); +} +__name(validateRequiredParameters, "validateRequiredParameters"); + +// src/components/textInput/TextInput.ts +var TextInputBuilder = class extends ComponentBuilder { + static { + __name(this, "TextInputBuilder"); + } + /** + * Creates a new text input from API data. + * + * @param data - The API data to create this text input with + * @example + * Creating a select menu option from an API data object: + * ```ts + * const textInput = new TextInputBuilder({ + * custom_id: 'a cool select menu', + * label: 'Type something', + * style: TextInputStyle.Short, + * }); + * ``` + * @example + * Creating a select menu option using setters and API data: + * ```ts + * const textInput = new TextInputBuilder({ + * label: 'Type something else', + * }) + * .setCustomId('woah') + * .setStyle(TextInputStyle.Paragraph); + * ``` + */ + constructor(data) { + super({ type: ComponentType7.TextInput, ...data }); + } + /** + * Sets the custom id for this text input. + * + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Sets the label for this text input. + * + * @param label - The label to use + */ + setLabel(label) { + this.data.label = labelValidator.parse(label); + return this; + } + /** + * Sets the style for this text input. + * + * @param style - The style to use + */ + setStyle(style) { + this.data.style = textInputStyleValidator.parse(style); + return this; + } + /** + * Sets the minimum length of text for this text input. + * + * @param minLength - The minimum length of text for this text input + */ + setMinLength(minLength) { + this.data.min_length = minLengthValidator.parse(minLength); + return this; + } + /** + * Sets the maximum length of text for this text input. + * + * @param maxLength - The maximum length of text for this text input + */ + setMaxLength(maxLength) { + this.data.max_length = maxLengthValidator.parse(maxLength); + return this; + } + /** + * Sets the placeholder for this text input. + * + * @param placeholder - The placeholder to use + */ + setPlaceholder(placeholder) { + this.data.placeholder = placeholderValidator2.parse(placeholder); + return this; + } + /** + * Sets the value for this text input. + * + * @param value - The value to use + */ + setValue(value) { + this.data.value = valueValidator.parse(value); + return this; + } + /** + * Sets whether this text input is required. + * + * @param required - Whether this text input is required + */ + setRequired(required = true) { + this.data.required = requiredValidator.parse(required); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + validateRequiredParameters(this.data.custom_id, this.data.style, this.data.label); + return { + ...this.data + }; + } + /** + * {@inheritDoc Equatable.equals} + */ + equals(other) { + if (isJSONEncodable(other)) { + return isEqual(other.toJSON(), this.data); + } + return isEqual(other, this.data); + } +}; + +// src/components/Components.ts +function createComponentBuilder(data) { + if (data instanceof ComponentBuilder) { + return data; + } + switch (data.type) { + case ComponentType8.ActionRow: + return new ActionRowBuilder(data); + case ComponentType8.Button: + return new ButtonBuilder(data); + case ComponentType8.StringSelect: + return new StringSelectMenuBuilder(data); + case ComponentType8.TextInput: + return new TextInputBuilder(data); + case ComponentType8.UserSelect: + return new UserSelectMenuBuilder(data); + case ComponentType8.RoleSelect: + return new RoleSelectMenuBuilder(data); + case ComponentType8.MentionableSelect: + return new MentionableSelectMenuBuilder(data); + case ComponentType8.ChannelSelect: + return new ChannelSelectMenuBuilder(data); + default: + throw new Error(`Cannot properly serialize component type: ${data.type}`); + } +} +__name(createComponentBuilder, "createComponentBuilder"); + +// src/components/ActionRow.ts +var ActionRowBuilder = class extends ComponentBuilder { + static { + __name(this, "ActionRowBuilder"); + } + /** + * The components within this action row. + */ + components; + /** + * Creates a new action row from API data. + * + * @param data - The API data to create this action row with + * @example + * Creating an action row from an API data object: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Type something", + * style: TextInputStyle.Short, + * type: ComponentType.TextInput, + * }, + * ], + * }); + * ``` + * @example + * Creating an action row using setters and API data: + * ```ts + * const actionRow = new ActionRowBuilder({ + * components: [ + * { + * custom_id: "custom id", + * label: "Click me", + * style: ButtonStyle.Primary, + * type: ComponentType.Button, + * }, + * ], + * }) + * .addComponents(button2, button3); + * ``` + */ + constructor({ components, ...data } = {}) { + super({ type: ComponentType9.ActionRow, ...data }); + this.components = components?.map((component) => createComponentBuilder(component)) ?? []; + } + /** + * Adds components to this action row. + * + * @param components - The components to add + */ + addComponents(...components) { + this.components.push(...normalizeArray(components)); + return this; + } + /** + * Sets components for this action row. + * + * @param components - The components to set + */ + setComponents(...components) { + this.components.splice(0, this.components.length, ...normalizeArray(components)); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + return { + ...this.data, + components: this.components.map((component) => component.toJSON()) + }; + } +}; + +// src/interactions/modals/Assertions.ts +var Assertions_exports4 = {}; +__export(Assertions_exports4, { + componentsValidator: () => componentsValidator, + titleValidator: () => titleValidator, + validateRequiredParameters: () => validateRequiredParameters2 +}); +import { s as s4 } from "@sapphire/shapeshift"; +var titleValidator = s4.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(45).setValidationEnabled(isValidationEnabled); +var componentsValidator = s4.instance(ActionRowBuilder).array.lengthGreaterThanOrEqual(1).setValidationEnabled(isValidationEnabled); +function validateRequiredParameters2(customId, title, components) { + customIdValidator.parse(customId); + titleValidator.parse(title); + componentsValidator.parse(components); +} +__name(validateRequiredParameters2, "validateRequiredParameters"); + +// src/interactions/modals/Modal.ts +var ModalBuilder = class { + static { + __name(this, "ModalBuilder"); + } + /** + * The API data associated with this modal. + */ + data; + /** + * The components within this modal. + */ + components = []; + /** + * Creates a new modal from API data. + * + * @param data - The API data to create this modal with + */ + constructor({ components, ...data } = {}) { + this.data = { ...data }; + this.components = components?.map((component) => createComponentBuilder(component)) ?? []; + } + /** + * Sets the title of this modal. + * + * @param title - The title to use + */ + setTitle(title) { + this.data.title = titleValidator.parse(title); + return this; + } + /** + * Sets the custom id of this modal. + * + * @param customId - The custom id to use + */ + setCustomId(customId) { + this.data.custom_id = customIdValidator.parse(customId); + return this; + } + /** + * Adds components to this modal. + * + * @param components - The components to add + */ + addComponents(...components) { + this.components.push( + ...normalizeArray(components).map( + (component) => component instanceof ActionRowBuilder ? component : new ActionRowBuilder(component) + ) + ); + return this; + } + /** + * Sets components for this modal. + * + * @param components - The components to set + */ + setComponents(...components) { + this.components.splice(0, this.components.length, ...normalizeArray(components)); + return this; + } + /** + * {@inheritDoc ComponentBuilder.toJSON} + */ + toJSON() { + validateRequiredParameters2(this.data.custom_id, this.data.title, this.components); + return { + ...this.data, + components: this.components.map((component) => component.toJSON()) + }; + } +}; + +// src/interactions/slashCommands/Assertions.ts +var Assertions_exports5 = {}; +__export(Assertions_exports5, { + assertReturnOfBuilder: () => assertReturnOfBuilder, + localizationMapPredicate: () => localizationMapPredicate, + validateChoicesLength: () => validateChoicesLength, + validateDMPermission: () => validateDMPermission, + validateDefaultMemberPermissions: () => validateDefaultMemberPermissions, + validateDefaultPermission: () => validateDefaultPermission, + validateDescription: () => validateDescription, + validateLocale: () => validateLocale, + validateLocalizationMap: () => validateLocalizationMap, + validateMaxOptionsLength: () => validateMaxOptionsLength, + validateNSFW: () => validateNSFW, + validateName: () => validateName, + validateRequired: () => validateRequired, + validateRequiredParameters: () => validateRequiredParameters3 +}); +import { s as s5 } from "@sapphire/shapeshift"; +import { Locale } from "discord-api-types/v10"; +var namePredicate = s5.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(32).regex(/^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u).setValidationEnabled(isValidationEnabled); +function validateName(name) { + namePredicate.parse(name); +} +__name(validateName, "validateName"); +var descriptionPredicate2 = s5.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled); +var localePredicate = s5.nativeEnum(Locale); +function validateDescription(description) { + descriptionPredicate2.parse(description); +} +__name(validateDescription, "validateDescription"); +var maxArrayLengthPredicate = s5.unknown.array.lengthLessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateLocale(locale) { + return localePredicate.parse(locale); +} +__name(validateLocale, "validateLocale"); +function validateMaxOptionsLength(options) { + maxArrayLengthPredicate.parse(options); +} +__name(validateMaxOptionsLength, "validateMaxOptionsLength"); +function validateRequiredParameters3(name, description, options) { + validateName(name); + validateDescription(description); + validateMaxOptionsLength(options); +} +__name(validateRequiredParameters3, "validateRequiredParameters"); +var booleanPredicate = s5.boolean; +function validateDefaultPermission(value) { + booleanPredicate.parse(value); +} +__name(validateDefaultPermission, "validateDefaultPermission"); +function validateRequired(required) { + booleanPredicate.parse(required); +} +__name(validateRequired, "validateRequired"); +var choicesLengthPredicate = s5.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled); +function validateChoicesLength(amountAdding, choices) { + choicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding); +} +__name(validateChoicesLength, "validateChoicesLength"); +function assertReturnOfBuilder(input, ExpectedInstanceOf) { + s5.instance(ExpectedInstanceOf).parse(input); +} +__name(assertReturnOfBuilder, "assertReturnOfBuilder"); +var localizationMapPredicate = s5.object(Object.fromEntries(Object.values(Locale).map((locale) => [locale, s5.string.nullish]))).strict.nullish.setValidationEnabled(isValidationEnabled); +function validateLocalizationMap(value) { + localizationMapPredicate.parse(value); +} +__name(validateLocalizationMap, "validateLocalizationMap"); +var dmPermissionPredicate = s5.boolean.nullish; +function validateDMPermission(value) { + dmPermissionPredicate.parse(value); +} +__name(validateDMPermission, "validateDMPermission"); +var memberPermissionPredicate = s5.union( + s5.bigint.transform((value) => value.toString()), + s5.number.safeInt.transform((value) => value.toString()), + s5.string.regex(/^\d+$/) +).nullish; +function validateDefaultMemberPermissions(permissions) { + return memberPermissionPredicate.parse(permissions); +} +__name(validateDefaultMemberPermissions, "validateDefaultMemberPermissions"); +function validateNSFW(value) { + booleanPredicate.parse(value); +} +__name(validateNSFW, "validateNSFW"); + +// src/interactions/slashCommands/SlashCommandBuilder.ts +import { mix as mix6 } from "ts-mixer"; + +// src/interactions/slashCommands/SlashCommandSubcommands.ts +import { + ApplicationCommandOptionType as ApplicationCommandOptionType11 +} from "discord-api-types/v10"; +import { mix as mix5 } from "ts-mixer"; + +// src/interactions/slashCommands/mixins/NameAndDescription.ts +var SharedNameAndDescription = class { + static { + __name(this, "SharedNameAndDescription"); + } + /** + * The name of this command. + */ + name; + /** + * The name localizations of this command. + */ + name_localizations; + /** + * The description of this command. + */ + description; + /** + * The description localizations of this command. + */ + description_localizations; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name) { + validateName(name); + Reflect.set(this, "name", name); + return this; + } + /** + * Sets the description of this command. + * + * @param description - The description to use + */ + setDescription(description) { + validateDescription(description); + Reflect.set(this, "description", description); + return this; + } + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale, localizedName) { + if (!this.name_localizations) { + Reflect.set(this, "name_localizations", {}); + } + const parsedLocale = validateLocale(locale); + if (localizedName === null) { + this.name_localizations[parsedLocale] = null; + return this; + } + validateName(localizedName); + this.name_localizations[parsedLocale] = localizedName; + return this; + } + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames) { + if (localizedNames === null) { + Reflect.set(this, "name_localizations", null); + return this; + } + Reflect.set(this, "name_localizations", {}); + for (const args of Object.entries(localizedNames)) { + this.setNameLocalization(...args); + } + return this; + } + /** + * Sets a description localization for this command. + * + * @param locale - The locale to set + * @param localizedDescription - The localized description for the given locale + */ + setDescriptionLocalization(locale, localizedDescription) { + if (!this.description_localizations) { + Reflect.set(this, "description_localizations", {}); + } + const parsedLocale = validateLocale(locale); + if (localizedDescription === null) { + this.description_localizations[parsedLocale] = null; + return this; + } + validateDescription(localizedDescription); + this.description_localizations[parsedLocale] = localizedDescription; + return this; + } + /** + * Sets the description localizations for this command. + * + * @param localizedDescriptions - The object of localized descriptions to set + */ + setDescriptionLocalizations(localizedDescriptions) { + if (localizedDescriptions === null) { + Reflect.set(this, "description_localizations", null); + return this; + } + Reflect.set(this, "description_localizations", {}); + for (const args of Object.entries(localizedDescriptions)) { + this.setDescriptionLocalization(...args); + } + return this; + } +}; + +// src/interactions/slashCommands/options/attachment.ts +import { ApplicationCommandOptionType } from "discord-api-types/v10"; + +// src/interactions/slashCommands/mixins/ApplicationCommandOptionBase.ts +var ApplicationCommandOptionBase = class extends SharedNameAndDescription { + static { + __name(this, "ApplicationCommandOptionBase"); + } + /** + * Whether this option is required. + * + * @defaultValue `false` + */ + required = false; + /** + * Sets whether this option is required. + * + * @param required - Whether this option should be required + */ + setRequired(required) { + validateRequired(required); + Reflect.set(this, "required", required); + return this; + } + /** + * This method runs required validators on this builder. + */ + runRequiredValidations() { + validateRequiredParameters3(this.name, this.description, []); + validateLocalizationMap(this.name_localizations); + validateLocalizationMap(this.description_localizations); + validateRequired(this.required); + } +}; + +// src/interactions/slashCommands/options/attachment.ts +var SlashCommandAttachmentOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandAttachmentOption"); + } + /** + * The type of this option. + */ + type = ApplicationCommandOptionType.Attachment; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/boolean.ts +import { ApplicationCommandOptionType as ApplicationCommandOptionType2 } from "discord-api-types/v10"; +var SlashCommandBooleanOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandBooleanOption"); + } + /** + * The type of this option. + */ + type = ApplicationCommandOptionType2.Boolean; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/channel.ts +import { ApplicationCommandOptionType as ApplicationCommandOptionType3 } from "discord-api-types/v10"; +import { mix } from "ts-mixer"; + +// src/interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.ts +import { s as s6 } from "@sapphire/shapeshift"; +import { ChannelType as ChannelType2 } from "discord-api-types/v10"; +var allowedChannelTypes = [ + ChannelType2.GuildText, + ChannelType2.GuildVoice, + ChannelType2.GuildCategory, + ChannelType2.GuildAnnouncement, + ChannelType2.AnnouncementThread, + ChannelType2.PublicThread, + ChannelType2.PrivateThread, + ChannelType2.GuildStageVoice, + ChannelType2.GuildForum +]; +var channelTypesPredicate = s6.array(s6.union(...allowedChannelTypes.map((type) => s6.literal(type)))); +var ApplicationCommandOptionChannelTypesMixin = class { + static { + __name(this, "ApplicationCommandOptionChannelTypesMixin"); + } + /** + * The channel types of this option. + */ + channel_types; + /** + * Adds channel types to this option. + * + * @param channelTypes - The channel types + */ + addChannelTypes(...channelTypes) { + if (this.channel_types === void 0) { + Reflect.set(this, "channel_types", []); + } + this.channel_types.push(...channelTypesPredicate.parse(channelTypes)); + return this; + } +}; + +// src/interactions/slashCommands/options/channel.ts +var SlashCommandChannelOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = ApplicationCommandOptionType3.Channel; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; +__name(SlashCommandChannelOption, "SlashCommandChannelOption"); +SlashCommandChannelOption = __decorateClass([ + mix(ApplicationCommandOptionChannelTypesMixin) +], SlashCommandChannelOption); + +// src/interactions/slashCommands/options/integer.ts +import { s as s8 } from "@sapphire/shapeshift"; +import { ApplicationCommandOptionType as ApplicationCommandOptionType5 } from "discord-api-types/v10"; +import { mix as mix2 } from "ts-mixer"; + +// src/interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.ts +var ApplicationCommandNumericOptionMinMaxValueMixin = class { + static { + __name(this, "ApplicationCommandNumericOptionMinMaxValueMixin"); + } + /** + * The maximum value of this option. + */ + max_value; + /** + * The minimum value of this option. + */ + min_value; +}; + +// src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts +import { s as s7 } from "@sapphire/shapeshift"; +import { ApplicationCommandOptionType as ApplicationCommandOptionType4 } from "discord-api-types/v10"; +var stringPredicate = s7.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100); +var numberPredicate = s7.number.greaterThan(Number.NEGATIVE_INFINITY).lessThan(Number.POSITIVE_INFINITY); +var choicesPredicate = s7.object({ + name: stringPredicate, + name_localizations: localizationMapPredicate, + value: s7.union(stringPredicate, numberPredicate) +}).array; +var booleanPredicate2 = s7.boolean; +var ApplicationCommandOptionWithChoicesAndAutocompleteMixin = class { + static { + __name(this, "ApplicationCommandOptionWithChoicesAndAutocompleteMixin"); + } + /** + * The choices of this option. + */ + choices; + /** + * Whether this option utilizes autocomplete. + */ + autocomplete; + /** + * The type of this option. + * + * @privateRemarks Since this is present and this is a mixin, this is needed. + */ + type; + /** + * Adds multiple choices to this option. + * + * @param choices - The choices to add + */ + addChoices(...choices) { + if (choices.length > 0 && this.autocomplete) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + choicesPredicate.parse(choices); + if (this.choices === void 0) { + Reflect.set(this, "choices", []); + } + validateChoicesLength(choices.length, this.choices); + for (const { name, name_localizations, value } of choices) { + if (this.type === ApplicationCommandOptionType4.String) { + stringPredicate.parse(value); + } else { + numberPredicate.parse(value); + } + this.choices.push({ name, name_localizations, value }); + } + return this; + } + /** + * Sets multiple choices for this option. + * + * @param choices - The choices to set + */ + setChoices(...choices) { + if (choices.length > 0 && this.autocomplete) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + choicesPredicate.parse(choices); + Reflect.set(this, "choices", []); + this.addChoices(...choices); + return this; + } + /** + * Whether this option uses autocomplete. + * + * @param autocomplete - Whether this option should use autocomplete + */ + setAutocomplete(autocomplete) { + booleanPredicate2.parse(autocomplete); + if (autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + Reflect.set(this, "autocomplete", autocomplete); + return this; + } +}; + +// src/interactions/slashCommands/options/integer.ts +var numberValidator = s8.number.int; +var SlashCommandIntegerOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = ApplicationCommandOptionType5.Integer; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max) { + numberValidator.parse(max); + Reflect.set(this, "max_value", max); + return this; + } + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min) { + numberValidator.parse(min); + Reflect.set(this, "min_value", min); + return this; + } + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + return { ...this }; + } +}; +__name(SlashCommandIntegerOption, "SlashCommandIntegerOption"); +SlashCommandIntegerOption = __decorateClass([ + mix2(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin) +], SlashCommandIntegerOption); + +// src/interactions/slashCommands/options/mentionable.ts +import { ApplicationCommandOptionType as ApplicationCommandOptionType6 } from "discord-api-types/v10"; +var SlashCommandMentionableOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandMentionableOption"); + } + /** + * The type of this option. + */ + type = ApplicationCommandOptionType6.Mentionable; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/number.ts +import { s as s9 } from "@sapphire/shapeshift"; +import { ApplicationCommandOptionType as ApplicationCommandOptionType7 } from "discord-api-types/v10"; +import { mix as mix3 } from "ts-mixer"; +var numberValidator2 = s9.number; +var SlashCommandNumberOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = ApplicationCommandOptionType7.Number; + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue} + */ + setMaxValue(max) { + numberValidator2.parse(max); + Reflect.set(this, "max_value", max); + return this; + } + /** + * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue} + */ + setMinValue(min) { + numberValidator2.parse(min); + Reflect.set(this, "min_value", min); + return this; + } + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + return { ...this }; + } +}; +__name(SlashCommandNumberOption, "SlashCommandNumberOption"); +SlashCommandNumberOption = __decorateClass([ + mix3(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin) +], SlashCommandNumberOption); + +// src/interactions/slashCommands/options/role.ts +import { ApplicationCommandOptionType as ApplicationCommandOptionType8 } from "discord-api-types/v10"; +var SlashCommandRoleOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandRoleOption"); + } + /** + * The type of this option. + */ + type = ApplicationCommandOptionType8.Role; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/options/string.ts +import { s as s10 } from "@sapphire/shapeshift"; +import { ApplicationCommandOptionType as ApplicationCommandOptionType9 } from "discord-api-types/v10"; +import { mix as mix4 } from "ts-mixer"; +var minLengthValidator2 = s10.number.greaterThanOrEqual(0).lessThanOrEqual(6e3); +var maxLengthValidator2 = s10.number.greaterThanOrEqual(1).lessThanOrEqual(6e3); +var SlashCommandStringOption = class extends ApplicationCommandOptionBase { + /** + * The type of this option. + */ + type = ApplicationCommandOptionType9.String; + /** + * The maximum length of this option. + */ + max_length; + /** + * The minimum length of this option. + */ + min_length; + /** + * Sets the maximum length of this string option. + * + * @param max - The maximum length this option can be + */ + setMaxLength(max) { + maxLengthValidator2.parse(max); + Reflect.set(this, "max_length", max); + return this; + } + /** + * Sets the minimum length of this string option. + * + * @param min - The minimum length this option can be + */ + setMinLength(min) { + minLengthValidator2.parse(min); + Reflect.set(this, "min_length", min); + return this; + } + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) { + throw new RangeError("Autocomplete and choices are mutually exclusive to each other."); + } + return { ...this }; + } +}; +__name(SlashCommandStringOption, "SlashCommandStringOption"); +SlashCommandStringOption = __decorateClass([ + mix4(ApplicationCommandOptionWithChoicesAndAutocompleteMixin) +], SlashCommandStringOption); + +// src/interactions/slashCommands/options/user.ts +import { ApplicationCommandOptionType as ApplicationCommandOptionType10 } from "discord-api-types/v10"; +var SlashCommandUserOption = class extends ApplicationCommandOptionBase { + static { + __name(this, "SlashCommandUserOption"); + } + /** + * The type of this option. + */ + type = ApplicationCommandOptionType10.User; + /** + * {@inheritDoc ApplicationCommandOptionBase.toJSON} + */ + toJSON() { + this.runRequiredValidations(); + return { ...this }; + } +}; + +// src/interactions/slashCommands/mixins/SharedSlashCommandOptions.ts +var SharedSlashCommandOptions = class { + static { + __name(this, "SharedSlashCommandOptions"); + } + options; + /** + * Adds a boolean option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addBooleanOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandBooleanOption); + } + /** + * Adds a user option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addUserOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandUserOption); + } + /** + * Adds a channel option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addChannelOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandChannelOption); + } + /** + * Adds a role option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addRoleOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandRoleOption); + } + /** + * Adds an attachment option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addAttachmentOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandAttachmentOption); + } + /** + * Adds a mentionable option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addMentionableOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandMentionableOption); + } + /** + * Adds a string option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addStringOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandStringOption); + } + /** + * Adds an integer option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addIntegerOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandIntegerOption); + } + /** + * Adds a number option. + * + * @param input - A function that returns an option builder or an already built builder + */ + addNumberOption(input) { + return this._sharedAddOptionMethod(input, SlashCommandNumberOption); + } + /** + * Where the actual adding magic happens. ✨ + * + * @param input - The input. What else? + * @param Instance - The instance of whatever is being added + * @internal + */ + _sharedAddOptionMethod(input, Instance) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new Instance()) : input; + assertReturnOfBuilder(result, Instance); + options.push(result); + return this; + } +}; + +// src/interactions/slashCommands/SlashCommandSubcommands.ts +var SlashCommandSubcommandGroupBuilder = class { + /** + * The name of this subcommand group. + */ + name = void 0; + /** + * The description of this subcommand group. + */ + description = void 0; + /** + * The subcommands within this subcommand group. + */ + options = []; + /** + * Adds a new subcommand to this group. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new SlashCommandSubcommandBuilder()) : input; + assertReturnOfBuilder(result, SlashCommandSubcommandBuilder); + options.push(result); + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters3(this.name, this.description, this.options); + return { + type: ApplicationCommandOptionType11.SubcommandGroup, + name: this.name, + name_localizations: this.name_localizations, + description: this.description, + description_localizations: this.description_localizations, + options: this.options.map((option) => option.toJSON()) + }; + } +}; +__name(SlashCommandSubcommandGroupBuilder, "SlashCommandSubcommandGroupBuilder"); +SlashCommandSubcommandGroupBuilder = __decorateClass([ + mix5(SharedNameAndDescription) +], SlashCommandSubcommandGroupBuilder); +var SlashCommandSubcommandBuilder = class { + /** + * The name of this subcommand. + */ + name = void 0; + /** + * The description of this subcommand. + */ + description = void 0; + /** + * The options within this subcommand. + */ + options = []; + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters3(this.name, this.description, this.options); + return { + type: ApplicationCommandOptionType11.Subcommand, + name: this.name, + name_localizations: this.name_localizations, + description: this.description, + description_localizations: this.description_localizations, + options: this.options.map((option) => option.toJSON()) + }; + } +}; +__name(SlashCommandSubcommandBuilder, "SlashCommandSubcommandBuilder"); +SlashCommandSubcommandBuilder = __decorateClass([ + mix5(SharedNameAndDescription, SharedSlashCommandOptions) +], SlashCommandSubcommandBuilder); + +// src/interactions/slashCommands/SlashCommandBuilder.ts +var SlashCommandBuilder = class { + /** + * The name of this command. + */ + name = void 0; + /** + * The name localizations of this command. + */ + name_localizations; + /** + * The description of this command. + */ + description = void 0; + /** + * The description localizations of this command. + */ + description_localizations; + /** + * The options of this command. + */ + options = []; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + default_permission = void 0; + /** + * The set of permissions represented as a bit set for the command. + */ + default_member_permissions = void 0; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + dm_permission = void 0; + /** + * Whether this command is NSFW. + */ + nsfw = void 0; + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether or not to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value) { + validateDefaultPermission(value); + Reflect.set(this, "default_permission", value); + return this; + } + /** + * Sets the default permissions a member should have in order to run the command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions) { + const permissionValue = validateDefaultMemberPermissions(permissions); + Reflect.set(this, "default_member_permissions", permissionValue); + return this; + } + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled) { + validateDMPermission(enabled); + Reflect.set(this, "dm_permission", enabled); + return this; + } + /** + * Sets whether this command is NSFW. + * + * @param nsfw - Whether this command is NSFW + */ + setNSFW(nsfw = true) { + validateNSFW(nsfw); + Reflect.set(this, "nsfw", nsfw); + return this; + } + /** + * Adds a new subcommand group to this command. + * + * @param input - A function that returns a subcommand group builder or an already built builder + */ + addSubcommandGroup(input) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new SlashCommandSubcommandGroupBuilder()) : input; + assertReturnOfBuilder(result, SlashCommandSubcommandGroupBuilder); + options.push(result); + return this; + } + /** + * Adds a new subcommand to this command. + * + * @param input - A function that returns a subcommand builder or an already built builder + */ + addSubcommand(input) { + const { options } = this; + validateMaxOptionsLength(options); + const result = typeof input === "function" ? input(new SlashCommandSubcommandBuilder()) : input; + assertReturnOfBuilder(result, SlashCommandSubcommandBuilder); + options.push(result); + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters3(this.name, this.description, this.options); + validateLocalizationMap(this.name_localizations); + validateLocalizationMap(this.description_localizations); + return { + ...this, + options: this.options.map((option) => option.toJSON()) + }; + } +}; +__name(SlashCommandBuilder, "SlashCommandBuilder"); +SlashCommandBuilder = __decorateClass([ + mix6(SharedSlashCommandOptions, SharedNameAndDescription) +], SlashCommandBuilder); + +// src/interactions/contextMenuCommands/Assertions.ts +var Assertions_exports6 = {}; +__export(Assertions_exports6, { + validateDMPermission: () => validateDMPermission2, + validateDefaultMemberPermissions: () => validateDefaultMemberPermissions2, + validateDefaultPermission: () => validateDefaultPermission2, + validateName: () => validateName2, + validateRequiredParameters: () => validateRequiredParameters4, + validateType: () => validateType +}); +import { s as s11 } from "@sapphire/shapeshift"; +import { ApplicationCommandType } from "discord-api-types/v10"; +var namePredicate2 = s11.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(32).regex(/^( *[\p{P}\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}]+ *)+$/u).setValidationEnabled(isValidationEnabled); +var typePredicate = s11.union(s11.literal(ApplicationCommandType.User), s11.literal(ApplicationCommandType.Message)).setValidationEnabled(isValidationEnabled); +var booleanPredicate3 = s11.boolean; +function validateDefaultPermission2(value) { + booleanPredicate3.parse(value); +} +__name(validateDefaultPermission2, "validateDefaultPermission"); +function validateName2(name) { + namePredicate2.parse(name); +} +__name(validateName2, "validateName"); +function validateType(type) { + typePredicate.parse(type); +} +__name(validateType, "validateType"); +function validateRequiredParameters4(name, type) { + validateName2(name); + validateType(type); +} +__name(validateRequiredParameters4, "validateRequiredParameters"); +var dmPermissionPredicate2 = s11.boolean.nullish; +function validateDMPermission2(value) { + dmPermissionPredicate2.parse(value); +} +__name(validateDMPermission2, "validateDMPermission"); +var memberPermissionPredicate2 = s11.union( + s11.bigint.transform((value) => value.toString()), + s11.number.safeInt.transform((value) => value.toString()), + s11.string.regex(/^\d+$/) +).nullish; +function validateDefaultMemberPermissions2(permissions) { + return memberPermissionPredicate2.parse(permissions); +} +__name(validateDefaultMemberPermissions2, "validateDefaultMemberPermissions"); + +// src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts +var ContextMenuCommandBuilder = class { + static { + __name(this, "ContextMenuCommandBuilder"); + } + /** + * The name of this command. + */ + name = void 0; + /** + * The name localizations of this command. + */ + name_localizations; + /** + * The type of this command. + */ + type = void 0; + /** + * Whether this command is enabled by default when the application is added to a guild. + * + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + default_permission = void 0; + /** + * The set of permissions represented as a bit set for the command. + */ + default_member_permissions = void 0; + /** + * Indicates whether the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This property is only for global commands. + */ + dm_permission = void 0; + /** + * Sets the name of this command. + * + * @param name - The name to use + */ + setName(name) { + validateName2(name); + Reflect.set(this, "name", name); + return this; + } + /** + * Sets the type of this command. + * + * @param type - The type to use + */ + setType(type) { + validateType(type); + Reflect.set(this, "type", type); + return this; + } + /** + * Sets whether the command is enabled by default when the application is added to a guild. + * + * @remarks + * If set to `false`, you will have to later `PUT` the permissions for this command. + * @param value - Whether to enable this command by default + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead. + */ + setDefaultPermission(value) { + validateDefaultPermission2(value); + Reflect.set(this, "default_permission", value); + return this; + } + /** + * Sets the default permissions a member should have in order to run this command. + * + * @remarks + * You can set this to `'0'` to disable the command by default. + * @param permissions - The permissions bit field to set + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDefaultMemberPermissions(permissions) { + const permissionValue = validateDefaultMemberPermissions2(permissions); + Reflect.set(this, "default_member_permissions", permissionValue); + return this; + } + /** + * Sets if the command is available in direct messages with the application. + * + * @remarks + * By default, commands are visible. This method is only for global commands. + * @param enabled - Whether the command should be enabled in direct messages + * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions} + */ + setDMPermission(enabled) { + validateDMPermission2(enabled); + Reflect.set(this, "dm_permission", enabled); + return this; + } + /** + * Sets a name localization for this command. + * + * @param locale - The locale to set + * @param localizedName - The localized name for the given `locale` + */ + setNameLocalization(locale, localizedName) { + if (!this.name_localizations) { + Reflect.set(this, "name_localizations", {}); + } + const parsedLocale = validateLocale(locale); + if (localizedName === null) { + this.name_localizations[parsedLocale] = null; + return this; + } + validateName2(localizedName); + this.name_localizations[parsedLocale] = localizedName; + return this; + } + /** + * Sets the name localizations for this command. + * + * @param localizedNames - The object of localized names to set + */ + setNameLocalizations(localizedNames) { + if (localizedNames === null) { + Reflect.set(this, "name_localizations", null); + return this; + } + Reflect.set(this, "name_localizations", {}); + for (const args of Object.entries(localizedNames)) + this.setNameLocalization(...args); + return this; + } + /** + * Serializes this builder to API-compatible JSON data. + * + * @remarks + * This method runs validations on the data before serializing it. + * As such, it may throw an error if the data is invalid. + */ + toJSON() { + validateRequiredParameters4(this.name, this.type); + validateLocalizationMap(this.name_localizations); + return { ...this }; + } +}; + +// src/util/componentUtil.ts +function embedLength(data) { + return (data.title?.length ?? 0) + (data.description?.length ?? 0) + (data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) + (data.footer?.text.length ?? 0) + (data.author?.name.length ?? 0); +} +__name(embedLength, "embedLength"); + +// src/index.ts +var version = "1.6.5"; +export { + ActionRowBuilder, + ApplicationCommandNumericOptionMinMaxValueMixin, + ApplicationCommandOptionBase, + ApplicationCommandOptionChannelTypesMixin, + ApplicationCommandOptionWithChoicesAndAutocompleteMixin, + BaseSelectMenuBuilder, + ButtonBuilder, + ChannelSelectMenuBuilder, + Assertions_exports2 as ComponentAssertions, + ComponentBuilder, + Assertions_exports6 as ContextMenuCommandAssertions, + ContextMenuCommandBuilder, + Assertions_exports as EmbedAssertions, + EmbedBuilder, + MentionableSelectMenuBuilder, + Assertions_exports4 as ModalAssertions, + ModalBuilder, + RoleSelectMenuBuilder, + StringSelectMenuBuilder as SelectMenuBuilder, + StringSelectMenuOptionBuilder as SelectMenuOptionBuilder, + SharedNameAndDescription, + SharedSlashCommandOptions, + Assertions_exports5 as SlashCommandAssertions, + SlashCommandAttachmentOption, + SlashCommandBooleanOption, + SlashCommandBuilder, + SlashCommandChannelOption, + SlashCommandIntegerOption, + SlashCommandMentionableOption, + SlashCommandNumberOption, + SlashCommandRoleOption, + SlashCommandStringOption, + SlashCommandSubcommandBuilder, + SlashCommandSubcommandGroupBuilder, + SlashCommandUserOption, + StringSelectMenuBuilder, + StringSelectMenuOptionBuilder, + Assertions_exports3 as TextInputAssertions, + TextInputBuilder, + UserSelectMenuBuilder, + createComponentBuilder, + disableValidators, + embedLength, + enableValidators, + isValidationEnabled, + normalizeArray, + version +}; +//# sourceMappingURL=index.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/builders/dist/index.mjs.map b/node_modules/@discordjs/builders/dist/index.mjs.map new file mode 100644 index 0000000..2907da1 --- /dev/null +++ b/node_modules/@discordjs/builders/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/messages/embed/Assertions.ts","../src/util/validation.ts","../src/util/normalizeArray.ts","../src/messages/embed/Embed.ts","../src/index.ts","../src/components/Assertions.ts","../src/components/selectMenu/StringSelectMenuOption.ts","../src/components/ActionRow.ts","../src/components/Component.ts","../src/components/Components.ts","../src/components/button/Button.ts","../src/components/selectMenu/ChannelSelectMenu.ts","../src/components/selectMenu/BaseSelectMenu.ts","../src/components/selectMenu/MentionableSelectMenu.ts","../src/components/selectMenu/RoleSelectMenu.ts","../src/components/selectMenu/StringSelectMenu.ts","../src/components/selectMenu/UserSelectMenu.ts","../src/components/textInput/TextInput.ts","../src/components/textInput/Assertions.ts","../src/interactions/modals/Assertions.ts","../src/interactions/modals/Modal.ts","../src/interactions/slashCommands/Assertions.ts","../src/interactions/slashCommands/SlashCommandBuilder.ts","../src/interactions/slashCommands/SlashCommandSubcommands.ts","../src/interactions/slashCommands/mixins/NameAndDescription.ts","../src/interactions/slashCommands/options/attachment.ts","../src/interactions/slashCommands/mixins/ApplicationCommandOptionBase.ts","../src/interactions/slashCommands/options/boolean.ts","../src/interactions/slashCommands/options/channel.ts","../src/interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.ts","../src/interactions/slashCommands/options/integer.ts","../src/interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.ts","../src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts","../src/interactions/slashCommands/options/mentionable.ts","../src/interactions/slashCommands/options/number.ts","../src/interactions/slashCommands/options/role.ts","../src/interactions/slashCommands/options/string.ts","../src/interactions/slashCommands/options/user.ts","../src/interactions/slashCommands/mixins/SharedSlashCommandOptions.ts","../src/interactions/contextMenuCommands/Assertions.ts","../src/interactions/contextMenuCommands/ContextMenuCommandBuilder.ts","../src/util/componentUtil.ts"],"sourcesContent":["import { s } from '@sapphire/shapeshift';\nimport type { APIEmbedField } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\n\nexport const fieldNamePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(256)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const fieldValuePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(1_024)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const fieldInlinePredicate = s.boolean.optional;\n\nexport const embedFieldPredicate = s\n\t.object({\n\t\tname: fieldNamePredicate,\n\t\tvalue: fieldValuePredicate,\n\t\tinline: fieldInlinePredicate,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const embedFieldsArrayPredicate = embedFieldPredicate.array.setValidationEnabled(isValidationEnabled);\n\nexport const fieldLengthPredicate = s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled);\n\nexport function validateFieldLength(amountAdding: number, fields?: APIEmbedField[]): void {\n\tfieldLengthPredicate.parse((fields?.length ?? 0) + amountAdding);\n}\n\nexport const authorNamePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const imageURLPredicate = s.string\n\t.url({\n\t\tallowedProtocols: ['http:', 'https:', 'attachment:'],\n\t})\n\t.nullish.setValidationEnabled(isValidationEnabled);\n\nexport const urlPredicate = s.string\n\t.url({\n\t\tallowedProtocols: ['http:', 'https:'],\n\t})\n\t.nullish.setValidationEnabled(isValidationEnabled);\n\nexport const embedAuthorPredicate = s\n\t.object({\n\t\tname: authorNamePredicate,\n\t\ticonURL: imageURLPredicate,\n\t\turl: urlPredicate,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const RGBPredicate = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(255)\n\t.setValidationEnabled(isValidationEnabled);\nexport const colorPredicate = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(0xffffff)\n\t.or(s.tuple([RGBPredicate, RGBPredicate, RGBPredicate]))\n\t.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const descriptionPredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(4_096)\n\t.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const footerTextPredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(2_048)\n\t.nullable.setValidationEnabled(isValidationEnabled);\n\nexport const embedFooterPredicate = s\n\t.object({\n\t\ttext: footerTextPredicate,\n\t\ticonURL: imageURLPredicate,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const timestampPredicate = s.union(s.number, s.date).nullable.setValidationEnabled(isValidationEnabled);\n\nexport const titlePredicate = fieldNamePredicate.nullable.setValidationEnabled(isValidationEnabled);\n","let validate = true;\n\n/**\n * Enables validators.\n *\n * @returns Whether validation is occurring.\n */\nexport function enableValidators() {\n\treturn (validate = true);\n}\n\n/**\n * Disables validators.\n *\n * @returns Whether validation is occurring.\n */\nexport function disableValidators() {\n\treturn (validate = false);\n}\n\n/**\n * Checks whether validation is occurring.\n */\nexport function isValidationEnabled() {\n\treturn validate;\n}\n","/**\n * Normalizes data that is a rest parameter or an array into an array with a depth of 1.\n *\n * @typeParam T - The data that must satisfy {@link RestOrArray}.\n * @param arr - The (possibly variadic) data to normalize\n */\nexport function normalizeArray<T>(arr: RestOrArray<T>): T[] {\n\tif (Array.isArray(arr[0])) return arr[0];\n\treturn arr as T[];\n}\n\n/**\n * Represents data that may be an array or came from a rest parameter.\n *\n * @remarks\n * This type is used throughout builders to ensure both an array and variadic arguments\n * may be used. It is normalized with {@link normalizeArray}.\n */\nexport type RestOrArray<T> = T[] | [T[]];\n","import type { APIEmbed, APIEmbedAuthor, APIEmbedField, APIEmbedFooter, APIEmbedImage } from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport {\n\tcolorPredicate,\n\tdescriptionPredicate,\n\tembedAuthorPredicate,\n\tembedFieldsArrayPredicate,\n\tembedFooterPredicate,\n\timageURLPredicate,\n\ttimestampPredicate,\n\ttitlePredicate,\n\turlPredicate,\n\tvalidateFieldLength,\n} from './Assertions.js';\n\n/**\n * A tuple satisfying the RGB color model.\n *\n * @see {@link https://developer.mozilla.org/docs/Glossary/RGB}\n */\nexport type RGBTuple = [red: number, green: number, blue: number];\n\n/**\n * The base icon data typically used in payloads.\n */\nexport interface IconData {\n\t/**\n\t * The URL of the icon.\n\t */\n\ticonURL?: string;\n\t/**\n\t * The proxy URL of the icon.\n\t */\n\tproxyIconURL?: string;\n}\n\n/**\n * Represents the author data of an embed.\n */\nexport type EmbedAuthorData = IconData & Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'>;\n\n/**\n * Represents the author options of an embed.\n */\nexport type EmbedAuthorOptions = Omit<EmbedAuthorData, 'proxyIconURL'>;\n\n/**\n * Represents the footer data of an embed.\n */\nexport type EmbedFooterData = IconData & Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'>;\n\n/**\n * Represents the footer options of an embed.\n */\nexport type EmbedFooterOptions = Omit<EmbedFooterData, 'proxyIconURL'>;\n\n/**\n * Represents the image data of an embed.\n */\nexport interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> {\n\t/**\n\t * The proxy URL for the image.\n\t */\n\tproxyURL?: string;\n}\n\n/**\n * A builder that creates API-compatible JSON data for embeds.\n */\nexport class EmbedBuilder {\n\t/**\n\t * The API data associated with this embed.\n\t */\n\tpublic readonly data: APIEmbed;\n\n\t/**\n\t * Creates a new embed from API data.\n\t *\n\t * @param data - The API data to create this embed with\n\t */\n\tpublic constructor(data: APIEmbed = {}) {\n\t\tthis.data = { ...data };\n\t\tif (data.timestamp) this.data.timestamp = new Date(data.timestamp).toISOString();\n\t}\n\n\t/**\n\t * Appends fields to the embed.\n\t *\n\t * @remarks\n\t * This method accepts either an array of fields or a variable number of field parameters.\n\t * The maximum amount of fields that can be added is 25.\n\t * @example\n\t * Using an array:\n\t * ```ts\n\t * const fields: APIEmbedField[] = ...;\n\t * const embed = new EmbedBuilder()\n\t * \t.addFields(fields);\n\t * ```\n\t * @example\n\t * Using rest parameters (variadic):\n\t * ```ts\n\t * const embed = new EmbedBuilder()\n\t * \t.addFields(\n\t * \t\t{ name: 'Field 1', value: 'Value 1' },\n\t * \t\t{ name: 'Field 2', value: 'Value 2' },\n\t * \t);\n\t * ```\n\t * @param fields - The fields to add\n\t */\n\tpublic addFields(...fields: RestOrArray<APIEmbedField>): this {\n\t\tconst normalizedFields = normalizeArray(fields);\n\t\t// Ensure adding these fields won't exceed the 25 field limit\n\t\tvalidateFieldLength(normalizedFields.length, this.data.fields);\n\n\t\t// Data assertions\n\t\tembedFieldsArrayPredicate.parse(normalizedFields);\n\n\t\tif (this.data.fields) this.data.fields.push(...normalizedFields);\n\t\telse this.data.fields = normalizedFields;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes, replaces, or inserts fields for this embed.\n\t *\n\t * @remarks\n\t * This method behaves similarly\n\t * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.\n\t * The maximum amount of fields that can be added is 25.\n\t *\n\t * It's useful for modifying and adjusting order of the already-existing fields of an embed.\n\t * @example\n\t * Remove the first field:\n\t * ```ts\n\t * embed.spliceFields(0, 1);\n\t * ```\n\t * @example\n\t * Remove the first n fields:\n\t * ```ts\n\t * const n = 4;\n\t * embed.spliceFields(0, n);\n\t * ```\n\t * @example\n\t * Remove the last field:\n\t * ```ts\n\t * embed.spliceFields(-1, 1);\n\t * ```\n\t * @param index - The index to start at\n\t * @param deleteCount - The number of fields to remove\n\t * @param fields - The replacing field objects\n\t */\n\tpublic spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this {\n\t\t// Ensure adding these fields won't exceed the 25 field limit\n\t\tvalidateFieldLength(fields.length - deleteCount, this.data.fields);\n\n\t\t// Data assertions\n\t\tembedFieldsArrayPredicate.parse(fields);\n\t\tif (this.data.fields) this.data.fields.splice(index, deleteCount, ...fields);\n\t\telse this.data.fields = fields;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the fields for this embed.\n\t *\n\t * @remarks\n\t * This method is an alias for {@link EmbedBuilder.spliceFields}. More specifically,\n\t * it splices the entire array of fields, replacing them with the provided fields.\n\t *\n\t * You can set a maximum of 25 fields.\n\t * @param fields - The fields to set\n\t */\n\tpublic setFields(...fields: RestOrArray<APIEmbedField>) {\n\t\tthis.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the author of this embed.\n\t *\n\t * @param options - The options to use\n\t */\n\n\tpublic setAuthor(options: EmbedAuthorOptions | null): this {\n\t\tif (options === null) {\n\t\t\tthis.data.author = undefined;\n\t\t\treturn this;\n\t\t}\n\n\t\t// Data assertions\n\t\tembedAuthorPredicate.parse(options);\n\n\t\tthis.data.author = { name: options.name, url: options.url, icon_url: options.iconURL };\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the color of this embed.\n\t *\n\t * @param color - The color to use\n\t */\n\tpublic setColor(color: RGBTuple | number | null): this {\n\t\t// Data assertions\n\t\tcolorPredicate.parse(color);\n\n\t\tif (Array.isArray(color)) {\n\t\t\tconst [red, green, blue] = color;\n\t\t\tthis.data.color = (red << 16) + (green << 8) + blue;\n\t\t\treturn this;\n\t\t}\n\n\t\tthis.data.color = color ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description of this embed.\n\t *\n\t * @param description - The description to use\n\t */\n\tpublic setDescription(description: string | null): this {\n\t\t// Data assertions\n\t\tdescriptionPredicate.parse(description);\n\n\t\tthis.data.description = description ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the footer of this embed.\n\t *\n\t * @param options - The footer to use\n\t */\n\tpublic setFooter(options: EmbedFooterOptions | null): this {\n\t\tif (options === null) {\n\t\t\tthis.data.footer = undefined;\n\t\t\treturn this;\n\t\t}\n\n\t\t// Data assertions\n\t\tembedFooterPredicate.parse(options);\n\n\t\tthis.data.footer = { text: options.text, icon_url: options.iconURL };\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the image of this embed.\n\t *\n\t * @param url - The image URL to use\n\t */\n\tpublic setImage(url: string | null): this {\n\t\t// Data assertions\n\t\timageURLPredicate.parse(url);\n\n\t\tthis.data.image = url ? { url } : undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the thumbnail of this embed.\n\t *\n\t * @param url - The thumbnail URL to use\n\t */\n\tpublic setThumbnail(url: string | null): this {\n\t\t// Data assertions\n\t\timageURLPredicate.parse(url);\n\n\t\tthis.data.thumbnail = url ? { url } : undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the timestamp of this embed.\n\t *\n\t * @param timestamp - The timestamp or date to use\n\t */\n\tpublic setTimestamp(timestamp: Date | number | null = Date.now()): this {\n\t\t// Data assertions\n\t\ttimestampPredicate.parse(timestamp);\n\n\t\tthis.data.timestamp = timestamp ? new Date(timestamp).toISOString() : undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the title for this embed.\n\t *\n\t * @param title - The title to use\n\t */\n\tpublic setTitle(title: string | null): this {\n\t\t// Data assertions\n\t\ttitlePredicate.parse(title);\n\n\t\tthis.data.title = title ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the URL of this embed.\n\t *\n\t * @param url - The URL to use\n\t */\n\tpublic setURL(url: string | null): this {\n\t\t// Data assertions\n\t\turlPredicate.parse(url);\n\n\t\tthis.data.url = url ?? undefined;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): APIEmbed {\n\t\treturn { ...this.data };\n\t}\n}\n","export * as EmbedAssertions from './messages/embed/Assertions.js';\nexport * from './messages/embed/Embed.js';\n// TODO: Consider removing this dep in the next major version\nexport * from '@discordjs/formatters';\n\nexport * as ComponentAssertions from './components/Assertions.js';\nexport * from './components/ActionRow.js';\nexport * from './components/button/Button.js';\nexport * from './components/Component.js';\nexport * from './components/Components.js';\nexport * from './components/textInput/TextInput.js';\nexport * as TextInputAssertions from './components/textInput/Assertions.js';\nexport * from './interactions/modals/Modal.js';\nexport * as ModalAssertions from './interactions/modals/Assertions.js';\n\nexport * from './components/selectMenu/BaseSelectMenu.js';\nexport * from './components/selectMenu/ChannelSelectMenu.js';\nexport * from './components/selectMenu/MentionableSelectMenu.js';\nexport * from './components/selectMenu/RoleSelectMenu.js';\nexport * from './components/selectMenu/StringSelectMenu.js';\n// TODO: Remove those aliases in v2\nexport {\n\t/**\n\t * @deprecated Will be removed in the next major version, use {@link StringSelectMenuBuilder} instead.\n\t */\n\tStringSelectMenuBuilder as SelectMenuBuilder,\n} from './components/selectMenu/StringSelectMenu.js';\nexport {\n\t/**\n\t * @deprecated Will be removed in the next major version, use {@link StringSelectMenuOptionBuilder} instead.\n\t */\n\tStringSelectMenuOptionBuilder as SelectMenuOptionBuilder,\n} from './components/selectMenu/StringSelectMenuOption.js';\nexport * from './components/selectMenu/StringSelectMenuOption.js';\nexport * from './components/selectMenu/UserSelectMenu.js';\n\nexport * as SlashCommandAssertions from './interactions/slashCommands/Assertions.js';\nexport * from './interactions/slashCommands/SlashCommandBuilder.js';\nexport * from './interactions/slashCommands/SlashCommandSubcommands.js';\nexport * from './interactions/slashCommands/options/boolean.js';\nexport * from './interactions/slashCommands/options/channel.js';\nexport * from './interactions/slashCommands/options/integer.js';\nexport * from './interactions/slashCommands/options/mentionable.js';\nexport * from './interactions/slashCommands/options/number.js';\nexport * from './interactions/slashCommands/options/role.js';\nexport * from './interactions/slashCommands/options/attachment.js';\nexport * from './interactions/slashCommands/options/string.js';\nexport * from './interactions/slashCommands/options/user.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandOptionBase.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandOptionChannelTypesMixin.js';\nexport * from './interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\nexport * from './interactions/slashCommands/mixins/NameAndDescription.js';\nexport * from './interactions/slashCommands/mixins/SharedSlashCommandOptions.js';\n\nexport * as ContextMenuCommandAssertions from './interactions/contextMenuCommands/Assertions.js';\nexport * from './interactions/contextMenuCommands/ContextMenuCommandBuilder.js';\n\nexport * from './util/componentUtil.js';\nexport * from './util/normalizeArray.js';\nexport * from './util/validation.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/builders#readme | @discordjs/builders} version\n * that you are currently using.\n *\n * @privateRemarks This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild.\n */\nexport const version = '1.6.5' as string;\n","import { s } from '@sapphire/shapeshift';\nimport { ButtonStyle, ChannelType, type APIMessageComponentEmoji } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../util/validation.js';\nimport { StringSelectMenuOptionBuilder } from './selectMenu/StringSelectMenuOption.js';\n\nexport const customIdValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(100)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const emojiValidator = s\n\t.object({\n\t\tid: s.string,\n\t\tname: s.string,\n\t\tanimated: s.boolean,\n\t})\n\t.partial.strict.setValidationEnabled(isValidationEnabled);\n\nexport const disabledValidator = s.boolean;\n\nexport const buttonLabelValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(80)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const buttonStyleValidator = s.nativeEnum(ButtonStyle);\n\nexport const placeholderValidator = s.string.lengthLessThanOrEqual(150).setValidationEnabled(isValidationEnabled);\nexport const minMaxValidator = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(25)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const labelValueDescriptionValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(100)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const jsonOptionValidator = s\n\t.object({\n\t\tlabel: labelValueDescriptionValidator,\n\t\tvalue: labelValueDescriptionValidator,\n\t\tdescription: labelValueDescriptionValidator.optional,\n\t\temoji: emojiValidator.optional,\n\t\tdefault: s.boolean.optional,\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport const optionValidator = s.instance(StringSelectMenuOptionBuilder).setValidationEnabled(isValidationEnabled);\n\nexport const optionsValidator = optionValidator.array\n\t.lengthGreaterThanOrEqual(0)\n\t.setValidationEnabled(isValidationEnabled);\nexport const optionsLengthValidator = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(25)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredSelectMenuParameters(options: StringSelectMenuOptionBuilder[], customId?: string) {\n\tcustomIdValidator.parse(customId);\n\toptionsValidator.parse(options);\n}\n\nexport const defaultValidator = s.boolean;\n\nexport function validateRequiredSelectMenuOptionParameters(label?: string, value?: string) {\n\tlabelValueDescriptionValidator.parse(label);\n\tlabelValueDescriptionValidator.parse(value);\n}\n\nexport const channelTypesValidator = s.nativeEnum(ChannelType).array.setValidationEnabled(isValidationEnabled);\n\nexport const urlValidator = s.string\n\t.url({\n\t\tallowedProtocols: ['http:', 'https:', 'discord:'],\n\t})\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredButtonParameters(\n\tstyle?: ButtonStyle,\n\tlabel?: string,\n\temoji?: APIMessageComponentEmoji,\n\tcustomId?: string,\n\turl?: string,\n) {\n\tif (url && customId) {\n\t\tthrow new RangeError('URL and custom id are mutually exclusive');\n\t}\n\n\tif (!label && !emoji) {\n\t\tthrow new RangeError('Buttons must have a label and/or an emoji');\n\t}\n\n\tif (style === ButtonStyle.Link) {\n\t\tif (!url) {\n\t\t\tthrow new RangeError('Link buttons must have a url');\n\t\t}\n\t} else if (url) {\n\t\tthrow new RangeError('Non-link buttons cannot have a url');\n\t}\n}\n","import type { JSONEncodable } from '@discordjs/util';\nimport type { APIMessageComponentEmoji, APISelectMenuOption } from 'discord-api-types/v10';\nimport {\n\tdefaultValidator,\n\temojiValidator,\n\tlabelValueDescriptionValidator,\n\tvalidateRequiredSelectMenuOptionParameters,\n} from '../Assertions.js';\n\n/**\n * A builder that creates API-compatible JSON data for string select menu options.\n */\nexport class StringSelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {\n\t/**\n\t * Creates a new string select menu option from API data.\n\t *\n\t * @param data - The API data to create this string select menu option with\n\t * @example\n\t * Creating a string select menu option from an API data object:\n\t * ```ts\n\t * const selectMenuOption = new SelectMenuOptionBuilder({\n\t * \tlabel: 'catchy label',\n\t * \tvalue: '1',\n\t * });\n\t * ```\n\t * @example\n\t * Creating a string select menu option using setters and API data:\n\t * ```ts\n\t * const selectMenuOption = new SelectMenuOptionBuilder({\n\t * \tdefault: true,\n\t * \tvalue: '1',\n\t * })\n\t * \t.setLabel('woah');\n\t * ```\n\t */\n\tpublic constructor(public data: Partial<APISelectMenuOption> = {}) {}\n\n\t/**\n\t * Sets the label for this option.\n\t *\n\t * @param label - The label to use\n\t */\n\tpublic setLabel(label: string) {\n\t\tthis.data.label = labelValueDescriptionValidator.parse(label);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the value for this option.\n\t *\n\t * @param value - The value to use\n\t */\n\tpublic setValue(value: string) {\n\t\tthis.data.value = labelValueDescriptionValidator.parse(value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description for this option.\n\t *\n\t * @param description - The description to use\n\t */\n\tpublic setDescription(description: string) {\n\t\tthis.data.description = labelValueDescriptionValidator.parse(description);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this option is selected by default.\n\t *\n\t * @param isDefault - Whether this option is selected by default\n\t */\n\tpublic setDefault(isDefault = true) {\n\t\tthis.data.default = defaultValidator.parse(isDefault);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the emoji to display for this option.\n\t *\n\t * @param emoji - The emoji to use\n\t */\n\tpublic setEmoji(emoji: APIMessageComponentEmoji) {\n\t\tthis.data.emoji = emojiValidator.parse(emoji);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc BaseSelectMenuBuilder.toJSON}\n\t */\n\tpublic toJSON(): APISelectMenuOption {\n\t\tvalidateRequiredSelectMenuOptionParameters(this.data.label, this.data.value);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APISelectMenuOption;\n\t}\n}\n","/* eslint-disable jsdoc/check-param-names */\n\nimport {\n\ttype APIActionRowComponent,\n\tComponentType,\n\ttype APIMessageActionRowComponent,\n\ttype APIModalActionRowComponent,\n\ttype APIActionRowComponentTypes,\n} from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../util/normalizeArray.js';\nimport { ComponentBuilder } from './Component.js';\nimport { createComponentBuilder } from './Components.js';\nimport type { ButtonBuilder } from './button/Button.js';\nimport type { ChannelSelectMenuBuilder } from './selectMenu/ChannelSelectMenu.js';\nimport type { MentionableSelectMenuBuilder } from './selectMenu/MentionableSelectMenu.js';\nimport type { RoleSelectMenuBuilder } from './selectMenu/RoleSelectMenu.js';\nimport type { StringSelectMenuBuilder } from './selectMenu/StringSelectMenu.js';\nimport type { UserSelectMenuBuilder } from './selectMenu/UserSelectMenu.js';\nimport type { TextInputBuilder } from './textInput/TextInput.js';\n\n/**\n * The builders that may be used for messages.\n */\nexport type MessageComponentBuilder =\n\t| ActionRowBuilder<MessageActionRowComponentBuilder>\n\t| MessageActionRowComponentBuilder;\n\n/**\n * The builders that may be used for modals.\n */\nexport type ModalComponentBuilder = ActionRowBuilder<ModalActionRowComponentBuilder> | ModalActionRowComponentBuilder;\n\n/**\n * The builders that may be used within an action row for messages.\n */\nexport type MessageActionRowComponentBuilder =\n\t| ButtonBuilder\n\t| ChannelSelectMenuBuilder\n\t| MentionableSelectMenuBuilder\n\t| RoleSelectMenuBuilder\n\t| StringSelectMenuBuilder\n\t| UserSelectMenuBuilder;\n\n/**\n * The builders that may be used within an action row for modals.\n */\nexport type ModalActionRowComponentBuilder = TextInputBuilder;\n\n/**\n * Any builder.\n */\nexport type AnyComponentBuilder = MessageActionRowComponentBuilder | ModalActionRowComponentBuilder;\n\n/**\n * A builder that creates API-compatible JSON data for action rows.\n *\n * @typeParam T - The types of components this action row holds\n */\nexport class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBuilder<\n\tAPIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>\n> {\n\t/**\n\t * The components within this action row.\n\t */\n\tpublic readonly components: T[];\n\n\t/**\n\t * Creates a new action row from API data.\n\t *\n\t * @param data - The API data to create this action row with\n\t * @example\n\t * Creating an action row from an API data object:\n\t * ```ts\n\t * const actionRow = new ActionRowBuilder({\n\t * \tcomponents: [\n\t * \t\t{\n\t * \t\t\tcustom_id: \"custom id\",\n\t * \t\t\tlabel: \"Type something\",\n\t * \t\t\tstyle: TextInputStyle.Short,\n\t * \t\t\ttype: ComponentType.TextInput,\n\t * \t\t},\n\t * \t],\n\t * });\n\t * ```\n\t * @example\n\t * Creating an action row using setters and API data:\n\t * ```ts\n\t * const actionRow = new ActionRowBuilder({\n\t * \tcomponents: [\n\t * \t\t{\n\t * \t\t\tcustom_id: \"custom id\",\n\t * \t\t\tlabel: \"Click me\",\n\t * \t\t\tstyle: ButtonStyle.Primary,\n\t * \t\t\ttype: ComponentType.Button,\n\t * \t\t},\n\t * \t],\n\t * })\n\t * \t.addComponents(button2, button3);\n\t * ```\n\t */\n\tpublic constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {\n\t\tsuper({ type: ComponentType.ActionRow, ...data });\n\t\tthis.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];\n\t}\n\n\t/**\n\t * Adds components to this action row.\n\t *\n\t * @param components - The components to add\n\t */\n\tpublic addComponents(...components: RestOrArray<T>) {\n\t\tthis.components.push(...normalizeArray(components));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets components for this action row.\n\t *\n\t * @param components - The components to set\n\t */\n\tpublic setComponents(...components: RestOrArray<T>) {\n\t\tthis.components.splice(0, this.components.length, ...normalizeArray(components));\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {\n\t\treturn {\n\t\t\t...this.data,\n\t\t\tcomponents: this.components.map((component) => component.toJSON()),\n\t\t} as APIActionRowComponent<ReturnType<T['toJSON']>>;\n\t}\n}\n","import type { JSONEncodable } from '@discordjs/util';\nimport type {\n\tAPIActionRowComponent,\n\tAPIActionRowComponentTypes,\n\tAPIBaseComponent,\n\tComponentType,\n} from 'discord-api-types/v10';\n\n/**\n * Any action row component data represented as an object.\n */\nexport type AnyAPIActionRowComponent = APIActionRowComponent<APIActionRowComponentTypes> | APIActionRowComponentTypes;\n\n/**\n * The base component builder that contains common symbols for all sorts of components.\n *\n * @typeParam DataType - The type of internal API data that is stored within the component\n */\nexport abstract class ComponentBuilder<\n\tDataType extends Partial<APIBaseComponent<ComponentType>> = APIBaseComponent<ComponentType>,\n> implements JSONEncodable<AnyAPIActionRowComponent>\n{\n\t/**\n\t * The API data associated with this component.\n\t */\n\tpublic readonly data: Partial<DataType>;\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic abstract toJSON(): AnyAPIActionRowComponent;\n\n\t/**\n\t * Constructs a new kind of component.\n\t *\n\t * @param data - The data to construct a component out of\n\t */\n\tpublic constructor(data: Partial<DataType>) {\n\t\tthis.data = data;\n\t}\n}\n","import { ComponentType, type APIMessageComponent, type APIModalComponent } from 'discord-api-types/v10';\nimport {\n\tActionRowBuilder,\n\ttype AnyComponentBuilder,\n\ttype MessageComponentBuilder,\n\ttype ModalComponentBuilder,\n} from './ActionRow.js';\nimport { ComponentBuilder } from './Component.js';\nimport { ButtonBuilder } from './button/Button.js';\nimport { ChannelSelectMenuBuilder } from './selectMenu/ChannelSelectMenu.js';\nimport { MentionableSelectMenuBuilder } from './selectMenu/MentionableSelectMenu.js';\nimport { RoleSelectMenuBuilder } from './selectMenu/RoleSelectMenu.js';\nimport { StringSelectMenuBuilder } from './selectMenu/StringSelectMenu.js';\nimport { UserSelectMenuBuilder } from './selectMenu/UserSelectMenu.js';\nimport { TextInputBuilder } from './textInput/TextInput.js';\n\n/**\n * Components here are mapped to their respective builder.\n */\nexport interface MappedComponentTypes {\n\t/**\n\t * The action row component type is associated with an {@link ActionRowBuilder}.\n\t */\n\t[ComponentType.ActionRow]: ActionRowBuilder<AnyComponentBuilder>;\n\t/**\n\t * The button component type is associated with an {@link ButtonBuilder}.\n\t */\n\t[ComponentType.Button]: ButtonBuilder;\n\t/**\n\t * The string select component type is associated with an {@link StringSelectMenuBuilder}.\n\t */\n\t[ComponentType.StringSelect]: StringSelectMenuBuilder;\n\t/**\n\t * The text inpiut component type is associated with an {@link TextInputBuilder}.\n\t */\n\t[ComponentType.TextInput]: TextInputBuilder;\n\t/**\n\t * The user select component type is associated with an {@link UserSelectMenuBuilder}.\n\t */\n\t[ComponentType.UserSelect]: UserSelectMenuBuilder;\n\t/**\n\t * The role select component type is associated with an {@link RoleSelectMenuBuilder}.\n\t */\n\t[ComponentType.RoleSelect]: RoleSelectMenuBuilder;\n\t/**\n\t * The mentionable select component type is associated with an {@link MentionableSelectMenuBuilder}.\n\t */\n\t[ComponentType.MentionableSelect]: MentionableSelectMenuBuilder;\n\t/**\n\t * The channel select component type is associated with an {@link ChannelSelectMenuBuilder}.\n\t */\n\t[ComponentType.ChannelSelect]: ChannelSelectMenuBuilder;\n}\n\n/**\n * Factory for creating components from API data.\n *\n * @typeParam T - The type of component to use\n * @param data - The API data to transform to a component class\n */\nexport function createComponentBuilder<T extends keyof MappedComponentTypes>(\n\t// eslint-disable-next-line @typescript-eslint/sort-type-union-intersection-members\n\tdata: (APIModalComponent | APIMessageComponent) & { type: T },\n): MappedComponentTypes[T];\n\n/**\n * Factory for creating components from API data.\n *\n * @typeParam C - The type of component to use\n * @param data - The API data to transform to a component class\n */\nexport function createComponentBuilder<C extends MessageComponentBuilder | ModalComponentBuilder>(data: C): C;\n\nexport function createComponentBuilder(\n\tdata: APIMessageComponent | APIModalComponent | MessageComponentBuilder,\n): ComponentBuilder {\n\tif (data instanceof ComponentBuilder) {\n\t\treturn data;\n\t}\n\n\tswitch (data.type) {\n\t\tcase ComponentType.ActionRow:\n\t\t\treturn new ActionRowBuilder(data);\n\t\tcase ComponentType.Button:\n\t\t\treturn new ButtonBuilder(data);\n\t\tcase ComponentType.StringSelect:\n\t\t\treturn new StringSelectMenuBuilder(data);\n\t\tcase ComponentType.TextInput:\n\t\t\treturn new TextInputBuilder(data);\n\t\tcase ComponentType.UserSelect:\n\t\t\treturn new UserSelectMenuBuilder(data);\n\t\tcase ComponentType.RoleSelect:\n\t\t\treturn new RoleSelectMenuBuilder(data);\n\t\tcase ComponentType.MentionableSelect:\n\t\t\treturn new MentionableSelectMenuBuilder(data);\n\t\tcase ComponentType.ChannelSelect:\n\t\t\treturn new ChannelSelectMenuBuilder(data);\n\t\tdefault:\n\t\t\t// @ts-expect-error This case can still occur if we get a newer unsupported component type\n\t\t\tthrow new Error(`Cannot properly serialize component type: ${data.type}`);\n\t}\n}\n","import {\n\tComponentType,\n\ttype APIMessageComponentEmoji,\n\ttype APIButtonComponent,\n\ttype APIButtonComponentWithURL,\n\ttype APIButtonComponentWithCustomId,\n\ttype ButtonStyle,\n} from 'discord-api-types/v10';\nimport {\n\tbuttonLabelValidator,\n\tbuttonStyleValidator,\n\tcustomIdValidator,\n\tdisabledValidator,\n\temojiValidator,\n\turlValidator,\n\tvalidateRequiredButtonParameters,\n} from '../Assertions.js';\nimport { ComponentBuilder } from '../Component.js';\n\n/**\n * A builder that creates API-compatible JSON data for buttons.\n */\nexport class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {\n\t/**\n\t * Creates a new button from API data.\n\t *\n\t * @param data - The API data to create this button with\n\t * @example\n\t * Creating a button from an API data object:\n\t * ```ts\n\t * const button = new ButtonBuilder({\n\t * \tcustom_id: 'a cool button',\n\t * \tstyle: ButtonStyle.Primary,\n\t * \tlabel: 'Click Me',\n\t * \temoji: {\n\t * \t\tname: 'smile',\n\t * \t\tid: '123456789012345678',\n\t * \t},\n\t * });\n\t * ```\n\t * @example\n\t * Creating a button using setters and API data:\n\t * ```ts\n\t * const button = new ButtonBuilder({\n\t * \tstyle: ButtonStyle.Secondary,\n\t * \tlabel: 'Click Me',\n\t * })\n\t * \t.setEmoji({ name: '🙂' })\n\t * \t.setCustomId('another cool button');\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIButtonComponent>) {\n\t\tsuper({ type: ComponentType.Button, ...data });\n\t}\n\n\t/**\n\t * Sets the style of this button.\n\t *\n\t * @param style - The style to use\n\t */\n\tpublic setStyle(style: ButtonStyle) {\n\t\tthis.data.style = buttonStyleValidator.parse(style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the URL for this button.\n\t *\n\t * @remarks\n\t * This method is only available to buttons using the `Link` button style.\n\t * Only three types of URL schemes are currently supported: `https://`, `http://`, and `discord://`.\n\t * @param url - The URL to use\n\t */\n\tpublic setURL(url: string) {\n\t\t(this.data as APIButtonComponentWithURL).url = urlValidator.parse(url);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the custom id for this button.\n\t *\n\t * @remarks\n\t * This method is only applicable to buttons that are not using the `Link` button style.\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\t(this.data as APIButtonComponentWithCustomId).custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the emoji to display on this button.\n\t *\n\t * @param emoji - The emoji to use\n\t */\n\tpublic setEmoji(emoji: APIMessageComponentEmoji) {\n\t\tthis.data.emoji = emojiValidator.parse(emoji);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this button is disabled.\n\t *\n\t * @param disabled - Whether to disable this button\n\t */\n\tpublic setDisabled(disabled = true) {\n\t\tthis.data.disabled = disabledValidator.parse(disabled);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the label for this button.\n\t *\n\t * @param label - The label to use\n\t */\n\tpublic setLabel(label: string) {\n\t\tthis.data.label = buttonLabelValidator.parse(label);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APIButtonComponent {\n\t\tvalidateRequiredButtonParameters(\n\t\t\tthis.data.style,\n\t\t\tthis.data.label,\n\t\t\tthis.data.emoji,\n\t\t\t(this.data as APIButtonComponentWithCustomId).custom_id,\n\t\t\t(this.data as APIButtonComponentWithURL).url,\n\t\t);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APIButtonComponent;\n\t}\n}\n","import type { APIChannelSelectComponent, ChannelType } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport { channelTypesValidator, customIdValidator } from '../Assertions.js';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for channel select menus.\n */\nexport class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new ChannelSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new ChannelSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement)\n\t * \t.setMinValues(2);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIChannelSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.ChannelSelect });\n\t}\n\n\t/**\n\t * Adds channel types to this select menu.\n\t *\n\t * @param types - The channel types to use\n\t */\n\tpublic addChannelTypes(...types: RestOrArray<ChannelType>) {\n\t\tconst normalizedTypes = normalizeArray(types);\n\t\tthis.data.channel_types ??= [];\n\t\tthis.data.channel_types.push(...channelTypesValidator.parse(normalizedTypes));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets channel types for this select menu.\n\t *\n\t * @param types - The channel types to use\n\t */\n\tpublic setChannelTypes(...types: RestOrArray<ChannelType>) {\n\t\tconst normalizedTypes = normalizeArray(types);\n\t\tthis.data.channel_types ??= [];\n\t\tthis.data.channel_types.splice(0, this.data.channel_types.length, ...channelTypesValidator.parse(normalizedTypes));\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc BaseSelectMenuBuilder.toJSON}\n\t */\n\tpublic override toJSON(): APIChannelSelectComponent {\n\t\tcustomIdValidator.parse(this.data.custom_id);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APIChannelSelectComponent;\n\t}\n}\n","import type { APISelectMenuComponent } from 'discord-api-types/v10';\nimport { customIdValidator, disabledValidator, minMaxValidator, placeholderValidator } from '../Assertions.js';\nimport { ComponentBuilder } from '../Component.js';\n\n/**\n * The base select menu builder that contains common symbols for select menu builders.\n *\n * @typeParam SelectMenuType - The type of select menu this would be instantiated for.\n */\nexport abstract class BaseSelectMenuBuilder<\n\tSelectMenuType extends APISelectMenuComponent,\n> extends ComponentBuilder<SelectMenuType> {\n\t/**\n\t * Sets the placeholder for this select menu.\n\t *\n\t * @param placeholder - The placeholder to use\n\t */\n\tpublic setPlaceholder(placeholder: string) {\n\t\tthis.data.placeholder = placeholderValidator.parse(placeholder);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the minimum values that must be selected in the select menu.\n\t *\n\t * @param minValues - The minimum values that must be selected\n\t */\n\tpublic setMinValues(minValues: number) {\n\t\tthis.data.min_values = minMaxValidator.parse(minValues);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the maximum values that must be selected in the select menu.\n\t *\n\t * @param maxValues - The maximum values that must be selected\n\t */\n\tpublic setMaxValues(maxValues: number) {\n\t\tthis.data.max_values = minMaxValidator.parse(maxValues);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the custom id for this select menu.\n\t *\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\tthis.data.custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this select menu is disabled.\n\t *\n\t * @param disabled - Whether this select menu is disabled\n\t */\n\tpublic setDisabled(disabled = true) {\n\t\tthis.data.disabled = disabledValidator.parse(disabled);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): SelectMenuType {\n\t\tcustomIdValidator.parse(this.data.custom_id);\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as SelectMenuType;\n\t}\n}\n","import type { APIMentionableSelectComponent } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for mentionable select menus.\n */\nexport class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder<APIMentionableSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new MentionableSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new MentionableSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIMentionableSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.MentionableSelect });\n\t}\n}\n","import type { APIRoleSelectComponent } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for role select menus.\n */\nexport class RoleSelectMenuBuilder extends BaseSelectMenuBuilder<APIRoleSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new RoleSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new RoleSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIRoleSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.RoleSelect });\n\t}\n}\n","import { ComponentType } from 'discord-api-types/v10';\nimport type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport { jsonOptionValidator, optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\nimport { StringSelectMenuOptionBuilder } from './StringSelectMenuOption.js';\n\n/**\n * A builder that creates API-compatible JSON data for string select menus.\n */\nexport class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSelectComponent> {\n\t/**\n\t * The options within this select menu.\n\t */\n\tpublic readonly options: StringSelectMenuOptionBuilder[];\n\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new StringSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * \toptions: [\n\t * \t\t{ label: 'option 1', value: '1' },\n\t * \t\t{ label: 'option 2', value: '2' },\n\t * \t\t{ label: 'option 3', value: '3' },\n\t * \t],\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new StringSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1)\n\t * \t.addOptions({\n\t * \t\tlabel: 'Catchy',\n\t * \t\tvalue: 'catch',\n\t * \t});\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIStringSelectComponent>) {\n\t\tconst { options, ...initData } = data ?? {};\n\t\tsuper({ ...initData, type: ComponentType.StringSelect });\n\t\tthis.options = options?.map((option: APISelectMenuOption) => new StringSelectMenuOptionBuilder(option)) ?? [];\n\t}\n\n\t/**\n\t * Adds options to this select menu.\n\t *\n\t * @param options - The options to add\n\t */\n\tpublic addOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>) {\n\t\tconst normalizedOptions = normalizeArray(options);\n\t\toptionsLengthValidator.parse(this.options.length + normalizedOptions.length);\n\t\tthis.options.push(\n\t\t\t...normalizedOptions.map((normalizedOption) =>\n\t\t\t\tnormalizedOption instanceof StringSelectMenuOptionBuilder\n\t\t\t\t\t? normalizedOption\n\t\t\t\t\t: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),\n\t\t\t),\n\t\t);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the options for this select menu.\n\t *\n\t * @param options - The options to set\n\t */\n\tpublic setOptions(...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>) {\n\t\treturn this.spliceOptions(0, this.options.length, ...options);\n\t}\n\n\t/**\n\t * Removes, replaces, or inserts options for this select menu.\n\t *\n\t * @remarks\n\t * This method behaves similarly\n\t * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}.\n\t * It's useful for modifying and adjusting the order of existing options.\n\t * @example\n\t * Remove the first option:\n\t * ```ts\n\t * selectMenu.spliceOptions(0, 1);\n\t * ```\n\t * @example\n\t * Remove the first n option:\n\t * ```ts\n\t * const n = 4;\n\t * selectMenu.spliceOptions(0, n);\n\t * ```\n\t * @example\n\t * Remove the last option:\n\t * ```ts\n\t * selectMenu.spliceOptions(-1, 1);\n\t * ```\n\t * @param index - The index to start at\n\t * @param deleteCount - The number of options to remove\n\t * @param options - The replacing option objects or builders\n\t */\n\tpublic spliceOptions(\n\t\tindex: number,\n\t\tdeleteCount: number,\n\t\t...options: RestOrArray<APISelectMenuOption | StringSelectMenuOptionBuilder>\n\t) {\n\t\tconst normalizedOptions = normalizeArray(options);\n\n\t\tconst clone = [...this.options];\n\n\t\tclone.splice(\n\t\t\tindex,\n\t\t\tdeleteCount,\n\t\t\t...normalizedOptions.map((normalizedOption) =>\n\t\t\t\tnormalizedOption instanceof StringSelectMenuOptionBuilder\n\t\t\t\t\t? normalizedOption\n\t\t\t\t\t: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),\n\t\t\t),\n\t\t);\n\n\t\toptionsLengthValidator.parse(clone.length);\n\t\tthis.options.splice(0, this.options.length, ...clone);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc BaseSelectMenuBuilder.toJSON}\n\t */\n\tpublic override toJSON(): APIStringSelectComponent {\n\t\tvalidateRequiredSelectMenuParameters(this.options, this.data.custom_id);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t} as APIStringSelectComponent;\n\t}\n}\n","import type { APIUserSelectComponent } from 'discord-api-types/v10';\nimport { ComponentType } from 'discord-api-types/v10';\nimport { BaseSelectMenuBuilder } from './BaseSelectMenu.js';\n\n/**\n * A builder that creates API-compatible JSON data for user select menus.\n */\nexport class UserSelectMenuBuilder extends BaseSelectMenuBuilder<APIUserSelectComponent> {\n\t/**\n\t * Creates a new select menu from API data.\n\t *\n\t * @param data - The API data to create this select menu with\n\t * @example\n\t * Creating a select menu from an API data object:\n\t * ```ts\n\t * const selectMenu = new UserSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tplaceholder: 'select an option',\n\t * \tmax_values: 2,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu using setters and API data:\n\t * ```ts\n\t * const selectMenu = new UserSelectMenuBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * })\n\t * \t.setMinValues(1);\n\t * ```\n\t */\n\tpublic constructor(data?: Partial<APIUserSelectComponent>) {\n\t\tsuper({ ...data, type: ComponentType.UserSelect });\n\t}\n}\n","import { isJSONEncodable, type Equatable, type JSONEncodable } from '@discordjs/util';\nimport { ComponentType, type TextInputStyle, type APITextInputComponent } from 'discord-api-types/v10';\nimport isEqual from 'fast-deep-equal';\nimport { customIdValidator } from '../Assertions.js';\nimport { ComponentBuilder } from '../Component.js';\nimport {\n\tmaxLengthValidator,\n\tminLengthValidator,\n\tplaceholderValidator,\n\trequiredValidator,\n\tvalueValidator,\n\tvalidateRequiredParameters,\n\tlabelValidator,\n\ttextInputStyleValidator,\n} from './Assertions.js';\n\n/**\n * A builder that creates API-compatible JSON data for text inputs.\n */\nexport class TextInputBuilder\n\textends ComponentBuilder<APITextInputComponent>\n\timplements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>>\n{\n\t/**\n\t * Creates a new text input from API data.\n\t *\n\t * @param data - The API data to create this text input with\n\t * @example\n\t * Creating a select menu option from an API data object:\n\t * ```ts\n\t * const textInput = new TextInputBuilder({\n\t * \tcustom_id: 'a cool select menu',\n\t * \tlabel: 'Type something',\n\t * \tstyle: TextInputStyle.Short,\n\t * });\n\t * ```\n\t * @example\n\t * Creating a select menu option using setters and API data:\n\t * ```ts\n\t * const textInput = new TextInputBuilder({\n\t * \tlabel: 'Type something else',\n\t * })\n\t * \t.setCustomId('woah')\n\t * \t.setStyle(TextInputStyle.Paragraph);\n\t * ```\n\t */\n\tpublic constructor(data?: APITextInputComponent & { type?: ComponentType.TextInput }) {\n\t\tsuper({ type: ComponentType.TextInput, ...data });\n\t}\n\n\t/**\n\t * Sets the custom id for this text input.\n\t *\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\tthis.data.custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the label for this text input.\n\t *\n\t * @param label - The label to use\n\t */\n\tpublic setLabel(label: string) {\n\t\tthis.data.label = labelValidator.parse(label);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the style for this text input.\n\t *\n\t * @param style - The style to use\n\t */\n\tpublic setStyle(style: TextInputStyle) {\n\t\tthis.data.style = textInputStyleValidator.parse(style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the minimum length of text for this text input.\n\t *\n\t * @param minLength - The minimum length of text for this text input\n\t */\n\tpublic setMinLength(minLength: number) {\n\t\tthis.data.min_length = minLengthValidator.parse(minLength);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the maximum length of text for this text input.\n\t *\n\t * @param maxLength - The maximum length of text for this text input\n\t */\n\tpublic setMaxLength(maxLength: number) {\n\t\tthis.data.max_length = maxLengthValidator.parse(maxLength);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the placeholder for this text input.\n\t *\n\t * @param placeholder - The placeholder to use\n\t */\n\tpublic setPlaceholder(placeholder: string) {\n\t\tthis.data.placeholder = placeholderValidator.parse(placeholder);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the value for this text input.\n\t *\n\t * @param value - The value to use\n\t */\n\tpublic setValue(value: string) {\n\t\tthis.data.value = valueValidator.parse(value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this text input is required.\n\t *\n\t * @param required - Whether this text input is required\n\t */\n\tpublic setRequired(required = true) {\n\t\tthis.data.required = requiredValidator.parse(required);\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APITextInputComponent {\n\t\tvalidateRequiredParameters(this.data.custom_id, this.data.style, this.data.label);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t} as APITextInputComponent;\n\t}\n\n\t/**\n\t * {@inheritDoc Equatable.equals}\n\t */\n\tpublic equals(other: APITextInputComponent | JSONEncodable<APITextInputComponent>): boolean {\n\t\tif (isJSONEncodable(other)) {\n\t\t\treturn isEqual(other.toJSON(), this.data);\n\t\t}\n\n\t\treturn isEqual(other, this.data);\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { TextInputStyle } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\nimport { customIdValidator } from '../Assertions.js';\n\nexport const textInputStyleValidator = s.nativeEnum(TextInputStyle);\nexport const minLengthValidator = s.number.int\n\t.greaterThanOrEqual(0)\n\t.lessThanOrEqual(4_000)\n\t.setValidationEnabled(isValidationEnabled);\nexport const maxLengthValidator = s.number.int\n\t.greaterThanOrEqual(1)\n\t.lessThanOrEqual(4_000)\n\t.setValidationEnabled(isValidationEnabled);\nexport const requiredValidator = s.boolean;\nexport const valueValidator = s.string.lengthLessThanOrEqual(4_000).setValidationEnabled(isValidationEnabled);\nexport const placeholderValidator = s.string.lengthLessThanOrEqual(100).setValidationEnabled(isValidationEnabled);\nexport const labelValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(45)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredParameters(customId?: string, style?: TextInputStyle, label?: string) {\n\tcustomIdValidator.parse(customId);\n\ttextInputStyleValidator.parse(style);\n\tlabelValidator.parse(label);\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow.js';\nimport { customIdValidator } from '../../components/Assertions.js';\nimport { isValidationEnabled } from '../../util/validation.js';\n\nexport const titleValidator = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(45)\n\t.setValidationEnabled(isValidationEnabled);\nexport const componentsValidator = s\n\t.instance(ActionRowBuilder)\n\t.array.lengthGreaterThanOrEqual(1)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateRequiredParameters(\n\tcustomId?: string,\n\ttitle?: string,\n\tcomponents?: ActionRowBuilder<ModalActionRowComponentBuilder>[],\n) {\n\tcustomIdValidator.parse(customId);\n\ttitleValidator.parse(title);\n\tcomponentsValidator.parse(components);\n}\n","/* eslint-disable jsdoc/check-param-names */\n\nimport type { JSONEncodable } from '@discordjs/util';\nimport type {\n\tAPIActionRowComponent,\n\tAPIModalActionRowComponent,\n\tAPIModalInteractionResponseCallbackData,\n} from 'discord-api-types/v10';\nimport { ActionRowBuilder, type ModalActionRowComponentBuilder } from '../../components/ActionRow.js';\nimport { customIdValidator } from '../../components/Assertions.js';\nimport { createComponentBuilder } from '../../components/Components.js';\nimport { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';\nimport { titleValidator, validateRequiredParameters } from './Assertions.js';\n\n/**\n * A builder that creates API-compatible JSON data for modals.\n */\nexport class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> {\n\t/**\n\t * The API data associated with this modal.\n\t */\n\tpublic readonly data: Partial<APIModalInteractionResponseCallbackData>;\n\n\t/**\n\t * The components within this modal.\n\t */\n\tpublic readonly components: ActionRowBuilder<ModalActionRowComponentBuilder>[] = [];\n\n\t/**\n\t * Creates a new modal from API data.\n\t *\n\t * @param data - The API data to create this modal with\n\t */\n\tpublic constructor({ components, ...data }: Partial<APIModalInteractionResponseCallbackData> = {}) {\n\t\tthis.data = { ...data };\n\t\tthis.components = (components?.map((component) => createComponentBuilder(component)) ??\n\t\t\t[]) as ActionRowBuilder<ModalActionRowComponentBuilder>[];\n\t}\n\n\t/**\n\t * Sets the title of this modal.\n\t *\n\t * @param title - The title to use\n\t */\n\tpublic setTitle(title: string) {\n\t\tthis.data.title = titleValidator.parse(title);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the custom id of this modal.\n\t *\n\t * @param customId - The custom id to use\n\t */\n\tpublic setCustomId(customId: string) {\n\t\tthis.data.custom_id = customIdValidator.parse(customId);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds components to this modal.\n\t *\n\t * @param components - The components to add\n\t */\n\tpublic addComponents(\n\t\t...components: RestOrArray<\n\t\t\tActionRowBuilder<ModalActionRowComponentBuilder> | APIActionRowComponent<APIModalActionRowComponent>\n\t\t>\n\t) {\n\t\tthis.components.push(\n\t\t\t...normalizeArray(components).map((component) =>\n\t\t\t\tcomponent instanceof ActionRowBuilder\n\t\t\t\t\t? component\n\t\t\t\t\t: new ActionRowBuilder<ModalActionRowComponentBuilder>(component),\n\t\t\t),\n\t\t);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets components for this modal.\n\t *\n\t * @param components - The components to set\n\t */\n\tpublic setComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder>>) {\n\t\tthis.components.splice(0, this.components.length, ...normalizeArray(components));\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ComponentBuilder.toJSON}\n\t */\n\tpublic toJSON(): APIModalInteractionResponseCallbackData {\n\t\tvalidateRequiredParameters(this.data.custom_id, this.data.title, this.components);\n\n\t\treturn {\n\t\t\t...this.data,\n\t\t\tcomponents: this.components.map((component) => component.toJSON()),\n\t\t} as APIModalInteractionResponseCallbackData;\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { Locale, type APIApplicationCommandOptionChoice, type LocalizationMap } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\nimport type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder.js';\nimport type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';\nimport type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase.js';\n\nconst namePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(32)\n\t.regex(/^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}_-]+$/u)\n\t.setValidationEnabled(isValidationEnabled);\n\nexport function validateName(name: unknown): asserts name is string {\n\tnamePredicate.parse(name);\n}\n\nconst descriptionPredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(100)\n\t.setValidationEnabled(isValidationEnabled);\nconst localePredicate = s.nativeEnum(Locale);\n\nexport function validateDescription(description: unknown): asserts description is string {\n\tdescriptionPredicate.parse(description);\n}\n\nconst maxArrayLengthPredicate = s.unknown.array.lengthLessThanOrEqual(25).setValidationEnabled(isValidationEnabled);\nexport function validateLocale(locale: unknown) {\n\treturn localePredicate.parse(locale);\n}\n\nexport function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {\n\tmaxArrayLengthPredicate.parse(options);\n}\n\nexport function validateRequiredParameters(\n\tname: string,\n\tdescription: string,\n\toptions: ToAPIApplicationCommandOptions[],\n) {\n\t// Assert name matches all conditions\n\tvalidateName(name);\n\n\t// Assert description conditions\n\tvalidateDescription(description);\n\n\t// Assert options conditions\n\tvalidateMaxOptionsLength(options);\n}\n\nconst booleanPredicate = s.boolean;\n\nexport function validateDefaultPermission(value: unknown): asserts value is boolean {\n\tbooleanPredicate.parse(value);\n}\n\nexport function validateRequired(required: unknown): asserts required is boolean {\n\tbooleanPredicate.parse(required);\n}\n\nconst choicesLengthPredicate = s.number.lessThanOrEqual(25).setValidationEnabled(isValidationEnabled);\n\nexport function validateChoicesLength(amountAdding: number, choices?: APIApplicationCommandOptionChoice[]): void {\n\tchoicesLengthPredicate.parse((choices?.length ?? 0) + amountAdding);\n}\n\nexport function assertReturnOfBuilder<\n\tT extends ApplicationCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder,\n>(input: unknown, ExpectedInstanceOf: new () => T): asserts input is T {\n\ts.instance(ExpectedInstanceOf).parse(input);\n}\n\nexport const localizationMapPredicate = s\n\t.object<LocalizationMap>(Object.fromEntries(Object.values(Locale).map((locale) => [locale, s.string.nullish])))\n\t.strict.nullish.setValidationEnabled(isValidationEnabled);\n\nexport function validateLocalizationMap(value: unknown): asserts value is LocalizationMap {\n\tlocalizationMapPredicate.parse(value);\n}\n\nconst dmPermissionPredicate = s.boolean.nullish;\n\nexport function validateDMPermission(value: unknown): asserts value is boolean | null | undefined {\n\tdmPermissionPredicate.parse(value);\n}\n\nconst memberPermissionPredicate = s.union(\n\ts.bigint.transform((value) => value.toString()),\n\ts.number.safeInt.transform((value) => value.toString()),\n\ts.string.regex(/^\\d+$/),\n).nullish;\n\nexport function validateDefaultMemberPermissions(permissions: unknown) {\n\treturn memberPermissionPredicate.parse(permissions);\n}\n\nexport function validateNSFW(value: unknown): asserts value is boolean {\n\tbooleanPredicate.parse(value);\n}\n","import type {\n\tAPIApplicationCommandOption,\n\tLocalizationMap,\n\tPermissions,\n\tRESTPostAPIChatInputApplicationCommandsJSONBody,\n} from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport {\n\tassertReturnOfBuilder,\n\tvalidateDefaultMemberPermissions,\n\tvalidateDefaultPermission,\n\tvalidateLocalizationMap,\n\tvalidateDMPermission,\n\tvalidateMaxOptionsLength,\n\tvalidateRequiredParameters,\n\tvalidateNSFW,\n} from './Assertions.js';\nimport { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands.js';\nimport { SharedNameAndDescription } from './mixins/NameAndDescription.js';\nimport { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';\n\n/**\n * A builder that creates API-compatible JSON data for slash commands.\n */\n@mix(SharedSlashCommandOptions, SharedNameAndDescription)\nexport class SlashCommandBuilder {\n\t/**\n\t * The name of this command.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The name localizations of this command.\n\t */\n\tpublic readonly name_localizations?: LocalizationMap;\n\n\t/**\n\t * The description of this command.\n\t */\n\tpublic readonly description: string = undefined!;\n\n\t/**\n\t * The description localizations of this command.\n\t */\n\tpublic readonly description_localizations?: LocalizationMap;\n\n\t/**\n\t * The options of this command.\n\t */\n\tpublic readonly options: ToAPIApplicationCommandOptions[] = [];\n\n\t/**\n\t * Whether this command is enabled by default when the application is added to a guild.\n\t *\n\t * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic readonly default_permission: boolean | undefined = undefined;\n\n\t/**\n\t * The set of permissions represented as a bit set for the command.\n\t */\n\tpublic readonly default_member_permissions: Permissions | null | undefined = undefined;\n\n\t/**\n\t * Indicates whether the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This property is only for global commands.\n\t */\n\tpublic readonly dm_permission: boolean | undefined = undefined;\n\n\t/**\n\t * Whether this command is NSFW.\n\t */\n\tpublic readonly nsfw: boolean | undefined = undefined;\n\n\t/**\n\t * Sets whether the command is enabled by default when the application is added to a guild.\n\t *\n\t * @remarks\n\t * If set to `false`, you will have to later `PUT` the permissions for this command.\n\t * @param value - Whether or not to enable this command by default\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t * @deprecated Use {@link SlashCommandBuilder.setDefaultMemberPermissions} or {@link SlashCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic setDefaultPermission(value: boolean) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDefaultPermission(value);\n\n\t\tReflect.set(this, 'default_permission', value);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the default permissions a member should have in order to run the command.\n\t *\n\t * @remarks\n\t * You can set this to `'0'` to disable the command by default.\n\t * @param permissions - The permissions bit field to set\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {\n\t\t// Assert the value and parse it\n\t\tconst permissionValue = validateDefaultMemberPermissions(permissions);\n\n\t\tReflect.set(this, 'default_member_permissions', permissionValue);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets if the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This method is only for global commands.\n\t * @param enabled - Whether the command should be enabled in direct messages\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDMPermission(enabled: boolean | null | undefined) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDMPermission(enabled);\n\n\t\tReflect.set(this, 'dm_permission', enabled);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether this command is NSFW.\n\t *\n\t * @param nsfw - Whether this command is NSFW\n\t */\n\tpublic setNSFW(nsfw = true) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateNSFW(nsfw);\n\t\tReflect.set(this, 'nsfw', nsfw);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a new subcommand group to this command.\n\t *\n\t * @param input - A function that returns a subcommand group builder or an already built builder\n\t */\n\tpublic addSubcommandGroup(\n\t\tinput:\n\t\t\t| SlashCommandSubcommandGroupBuilder\n\t\t\t| ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder),\n\t): SlashCommandSubcommandsOnlyBuilder {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\tconst result = typeof input === 'function' ? input(new SlashCommandSubcommandGroupBuilder()) : input;\n\n\t\tassertReturnOfBuilder(result, SlashCommandSubcommandGroupBuilder);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds a new subcommand to this command.\n\t *\n\t * @param input - A function that returns a subcommand builder or an already built builder\n\t */\n\tpublic addSubcommand(\n\t\tinput:\n\t\t\t| SlashCommandSubcommandBuilder\n\t\t\t| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),\n\t): SlashCommandSubcommandsOnlyBuilder {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\tconst result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;\n\n\t\tassertReturnOfBuilder(result, SlashCommandSubcommandBuilder);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): RESTPostAPIChatInputApplicationCommandsJSONBody {\n\t\tvalidateRequiredParameters(this.name, this.description, this.options);\n\n\t\tvalidateLocalizationMap(this.name_localizations);\n\t\tvalidateLocalizationMap(this.description_localizations);\n\n\t\treturn {\n\t\t\t...this,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t};\n\t}\n}\n\nexport interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions {}\n\n/**\n * An interface specifically for slash command subcommands.\n */\nexport interface SlashCommandSubcommandsOnlyBuilder\n\textends Omit<SlashCommandBuilder, Exclude<keyof SharedSlashCommandOptions, 'options'>> {}\n\n/**\n * An interface specifically for slash command options.\n */\nexport interface SlashCommandOptionsOnlyBuilder\n\textends SharedNameAndDescription,\n\t\tSharedSlashCommandOptions,\n\t\tPick<SlashCommandBuilder, 'toJSON'> {}\n\n/**\n * An interface that ensures the `toJSON()` call will return something\n * that can be serialized into API-compatible data.\n */\nexport interface ToAPIApplicationCommandOptions {\n\ttoJSON(): APIApplicationCommandOption;\n}\n","import {\n\tApplicationCommandOptionType,\n\ttype APIApplicationCommandSubcommandGroupOption,\n\ttype APIApplicationCommandSubcommandOption,\n} from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { assertReturnOfBuilder, validateMaxOptionsLength, validateRequiredParameters } from './Assertions.js';\nimport type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder.js';\nimport type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase.js';\nimport { SharedNameAndDescription } from './mixins/NameAndDescription.js';\nimport { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions.js';\n\n/**\n * Represents a folder for subcommands.\n *\n * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}\n */\n@mix(SharedNameAndDescription)\nexport class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationCommandOptions {\n\t/**\n\t * The name of this subcommand group.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The description of this subcommand group.\n\t */\n\tpublic readonly description: string = undefined!;\n\n\t/**\n\t * The subcommands within this subcommand group.\n\t */\n\tpublic readonly options: SlashCommandSubcommandBuilder[] = [];\n\n\t/**\n\t * Adds a new subcommand to this group.\n\t *\n\t * @param input - A function that returns a subcommand builder or an already built builder\n\t */\n\tpublic addSubcommand(\n\t\tinput:\n\t\t\t| SlashCommandSubcommandBuilder\n\t\t\t| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),\n\t) {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tconst result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tassertReturnOfBuilder(result, SlashCommandSubcommandBuilder);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): APIApplicationCommandSubcommandGroupOption {\n\t\tvalidateRequiredParameters(this.name, this.description, this.options);\n\n\t\treturn {\n\t\t\ttype: ApplicationCommandOptionType.SubcommandGroup,\n\t\t\tname: this.name,\n\t\t\tname_localizations: this.name_localizations,\n\t\t\tdescription: this.description,\n\t\t\tdescription_localizations: this.description_localizations,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t};\n\t}\n}\n\nexport interface SlashCommandSubcommandGroupBuilder extends SharedNameAndDescription {}\n\n/**\n * A builder that creates API-compatible JSON data for slash command subcommands.\n *\n * @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}\n */\n@mix(SharedNameAndDescription, SharedSlashCommandOptions)\nexport class SlashCommandSubcommandBuilder implements ToAPIApplicationCommandOptions {\n\t/**\n\t * The name of this subcommand.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The description of this subcommand.\n\t */\n\tpublic readonly description: string = undefined!;\n\n\t/**\n\t * The options within this subcommand.\n\t */\n\tpublic readonly options: ApplicationCommandOptionBase[] = [];\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): APIApplicationCommandSubcommandOption {\n\t\tvalidateRequiredParameters(this.name, this.description, this.options);\n\n\t\treturn {\n\t\t\ttype: ApplicationCommandOptionType.Subcommand,\n\t\t\tname: this.name,\n\t\t\tname_localizations: this.name_localizations,\n\t\t\tdescription: this.description,\n\t\t\tdescription_localizations: this.description_localizations,\n\t\t\toptions: this.options.map((option) => option.toJSON()),\n\t\t};\n\t}\n}\n\nexport interface SlashCommandSubcommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions<false> {}\n","import type { LocaleString, LocalizationMap } from 'discord-api-types/v10';\nimport { validateDescription, validateLocale, validateName } from '../Assertions.js';\n\n/**\n * This mixin holds name and description symbols for slash commands.\n */\nexport class SharedNameAndDescription {\n\t/**\n\t * The name of this command.\n\t */\n\tpublic readonly name!: string;\n\n\t/**\n\t * The name localizations of this command.\n\t */\n\tpublic readonly name_localizations?: LocalizationMap;\n\n\t/**\n\t * The description of this command.\n\t */\n\tpublic readonly description!: string;\n\n\t/**\n\t * The description localizations of this command.\n\t */\n\tpublic readonly description_localizations?: LocalizationMap;\n\n\t/**\n\t * Sets the name of this command.\n\t *\n\t * @param name - The name to use\n\t */\n\tpublic setName(name: string): this {\n\t\t// Assert the name matches the conditions\n\t\tvalidateName(name);\n\n\t\tReflect.set(this, 'name', name);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description of this command.\n\t *\n\t * @param description - The description to use\n\t */\n\tpublic setDescription(description: string) {\n\t\t// Assert the description matches the conditions\n\t\tvalidateDescription(description);\n\n\t\tReflect.set(this, 'description', description);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets a name localization for this command.\n\t *\n\t * @param locale - The locale to set\n\t * @param localizedName - The localized name for the given `locale`\n\t */\n\tpublic setNameLocalization(locale: LocaleString, localizedName: string | null) {\n\t\tif (!this.name_localizations) {\n\t\t\tReflect.set(this, 'name_localizations', {});\n\t\t}\n\n\t\tconst parsedLocale = validateLocale(locale);\n\n\t\tif (localizedName === null) {\n\t\t\tthis.name_localizations![parsedLocale] = null;\n\t\t\treturn this;\n\t\t}\n\n\t\tvalidateName(localizedName);\n\n\t\tthis.name_localizations![parsedLocale] = localizedName;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the name localizations for this command.\n\t *\n\t * @param localizedNames - The object of localized names to set\n\t */\n\tpublic setNameLocalizations(localizedNames: LocalizationMap | null) {\n\t\tif (localizedNames === null) {\n\t\t\tReflect.set(this, 'name_localizations', null);\n\t\t\treturn this;\n\t\t}\n\n\t\tReflect.set(this, 'name_localizations', {});\n\n\t\tfor (const args of Object.entries(localizedNames)) {\n\t\t\tthis.setNameLocalization(...(args as [LocaleString, string | null]));\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets a description localization for this command.\n\t *\n\t * @param locale - The locale to set\n\t * @param localizedDescription - The localized description for the given locale\n\t */\n\tpublic setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null) {\n\t\tif (!this.description_localizations) {\n\t\t\tReflect.set(this, 'description_localizations', {});\n\t\t}\n\n\t\tconst parsedLocale = validateLocale(locale);\n\n\t\tif (localizedDescription === null) {\n\t\t\tthis.description_localizations![parsedLocale] = null;\n\t\t\treturn this;\n\t\t}\n\n\t\tvalidateDescription(localizedDescription);\n\n\t\tthis.description_localizations![parsedLocale] = localizedDescription;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the description localizations for this command.\n\t *\n\t * @param localizedDescriptions - The object of localized descriptions to set\n\t */\n\tpublic setDescriptionLocalizations(localizedDescriptions: LocalizationMap | null) {\n\t\tif (localizedDescriptions === null) {\n\t\t\tReflect.set(this, 'description_localizations', null);\n\t\t\treturn this;\n\t\t}\n\n\t\tReflect.set(this, 'description_localizations', {});\n\t\tfor (const args of Object.entries(localizedDescriptions)) {\n\t\t\tthis.setDescriptionLocalization(...(args as [LocaleString, string | null]));\n\t\t}\n\n\t\treturn this;\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandAttachmentOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command attachment option.\n */\nexport class SlashCommandAttachmentOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic override readonly type = ApplicationCommandOptionType.Attachment as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandAttachmentOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import type { APIApplicationCommandBasicOption, ApplicationCommandOptionType } from 'discord-api-types/v10';\nimport { validateRequiredParameters, validateRequired, validateLocalizationMap } from '../Assertions.js';\nimport { SharedNameAndDescription } from './NameAndDescription.js';\n\n/**\n * The base application command option builder that contains common symbols for application command builders.\n */\nexport abstract class ApplicationCommandOptionBase extends SharedNameAndDescription {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic abstract readonly type: ApplicationCommandOptionType;\n\n\t/**\n\t * Whether this option is required.\n\t *\n\t * @defaultValue `false`\n\t */\n\tpublic readonly required: boolean = false;\n\n\t/**\n\t * Sets whether this option is required.\n\t *\n\t * @param required - Whether this option should be required\n\t */\n\tpublic setRequired(required: boolean) {\n\t\t// Assert that you actually passed a boolean\n\t\tvalidateRequired(required);\n\n\t\tReflect.set(this, 'required', required);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic abstract toJSON(): APIApplicationCommandBasicOption;\n\n\t/**\n\t * This method runs required validators on this builder.\n\t */\n\tprotected runRequiredValidations() {\n\t\tvalidateRequiredParameters(this.name, this.description, []);\n\n\t\t// Validate localizations\n\t\tvalidateLocalizationMap(this.name_localizations);\n\t\tvalidateLocalizationMap(this.description_localizations);\n\n\t\t// Assert that you actually passed a boolean\n\t\tvalidateRequired(this.required);\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandBooleanOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command boolean option.\n */\nexport class SlashCommandBooleanOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Boolean as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandBooleanOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandChannelOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionChannelTypesMixin } from '../mixins/ApplicationCommandOptionChannelTypesMixin.js';\n\n/**\n * A slash command channel option.\n */\n@mix(ApplicationCommandOptionChannelTypesMixin)\nexport class SlashCommandChannelOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic override readonly type = ApplicationCommandOptionType.Channel as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandChannelOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n\nexport interface SlashCommandChannelOption extends ApplicationCommandOptionChannelTypesMixin {}\n","import { s } from '@sapphire/shapeshift';\nimport { ChannelType } from 'discord-api-types/v10';\n\n/**\n * The allowed channel types used for a channel option in a slash command builder.\n *\n * @privateRemarks This can't be dynamic because const enums are erased at runtime.\n * @internal\n */\nconst allowedChannelTypes = [\n\tChannelType.GuildText,\n\tChannelType.GuildVoice,\n\tChannelType.GuildCategory,\n\tChannelType.GuildAnnouncement,\n\tChannelType.AnnouncementThread,\n\tChannelType.PublicThread,\n\tChannelType.PrivateThread,\n\tChannelType.GuildStageVoice,\n\tChannelType.GuildForum,\n] as const;\n\n/**\n * The type of allowed channel types used for a channel option.\n */\nexport type ApplicationCommandOptionAllowedChannelTypes = (typeof allowedChannelTypes)[number];\n\nconst channelTypesPredicate = s.array(s.union(...allowedChannelTypes.map((type) => s.literal(type))));\n\n/**\n * This mixin holds channel type symbols used for options.\n */\nexport class ApplicationCommandOptionChannelTypesMixin {\n\t/**\n\t * The channel types of this option.\n\t */\n\tpublic readonly channel_types?: ApplicationCommandOptionAllowedChannelTypes[];\n\n\t/**\n\t * Adds channel types to this option.\n\t *\n\t * @param channelTypes - The channel types\n\t */\n\tpublic addChannelTypes(...channelTypes: ApplicationCommandOptionAllowedChannelTypes[]) {\n\t\tif (this.channel_types === undefined) {\n\t\t\tReflect.set(this, 'channel_types', []);\n\t\t}\n\n\t\tthis.channel_types!.push(...channelTypesPredicate.parse(channelTypes));\n\n\t\treturn this;\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandIntegerOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\n\nconst numberValidator = s.number.int;\n\n/**\n * A slash command integer option.\n */\n@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)\nexport class SlashCommandIntegerOption\n\textends ApplicationCommandOptionBase\n\timplements ApplicationCommandNumericOptionMinMaxValueMixin\n{\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Integer as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}\n\t */\n\tpublic setMaxValue(max: number): this {\n\t\tnumberValidator.parse(max);\n\n\t\tReflect.set(this, 'max_value', max);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}\n\t */\n\tpublic setMinValue(min: number): this {\n\t\tnumberValidator.parse(min);\n\n\t\tReflect.set(this, 'min_value', min);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandIntegerOption {\n\t\tthis.runRequiredValidations();\n\n\t\tif (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\treturn { ...this } as APIApplicationCommandIntegerOption;\n\t}\n}\n\nexport interface SlashCommandIntegerOption\n\textends ApplicationCommandNumericOptionMinMaxValueMixin,\n\t\tApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> {}\n","/**\n * This mixin holds minimum and maximum symbols used for options.\n */\nexport abstract class ApplicationCommandNumericOptionMinMaxValueMixin {\n\t/**\n\t * The maximum value of this option.\n\t */\n\tpublic readonly max_value?: number;\n\n\t/**\n\t * The minimum value of this option.\n\t */\n\tpublic readonly min_value?: number;\n\n\t/**\n\t * Sets the maximum number value of this option.\n\t *\n\t * @param max - The maximum value this option can be\n\t */\n\tpublic abstract setMaxValue(max: number): this;\n\n\t/**\n\t * Sets the minimum number value of this option.\n\t *\n\t * @param min - The minimum value this option can be\n\t */\n\tpublic abstract setMinValue(min: number): this;\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandOptionChoice } from 'discord-api-types/v10';\nimport { localizationMapPredicate, validateChoicesLength } from '../Assertions.js';\n\nconst stringPredicate = s.string.lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100);\nconst numberPredicate = s.number.greaterThan(Number.NEGATIVE_INFINITY).lessThan(Number.POSITIVE_INFINITY);\nconst choicesPredicate = s.object({\n\tname: stringPredicate,\n\tname_localizations: localizationMapPredicate,\n\tvalue: s.union(stringPredicate, numberPredicate),\n}).array;\nconst booleanPredicate = s.boolean;\n\n/**\n * This mixin holds choices and autocomplete symbols used for options.\n */\nexport class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends number | string> {\n\t/**\n\t * The choices of this option.\n\t */\n\tpublic readonly choices?: APIApplicationCommandOptionChoice<T>[];\n\n\t/**\n\t * Whether this option utilizes autocomplete.\n\t */\n\tpublic readonly autocomplete?: boolean;\n\n\t/**\n\t * The type of this option.\n\t *\n\t * @privateRemarks Since this is present and this is a mixin, this is needed.\n\t */\n\tpublic readonly type!: ApplicationCommandOptionType;\n\n\t/**\n\t * Adds multiple choices to this option.\n\t *\n\t * @param choices - The choices to add\n\t */\n\tpublic addChoices(...choices: APIApplicationCommandOptionChoice<T>[]): this {\n\t\tif (choices.length > 0 && this.autocomplete) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\tchoicesPredicate.parse(choices);\n\n\t\tif (this.choices === undefined) {\n\t\t\tReflect.set(this, 'choices', []);\n\t\t}\n\n\t\tvalidateChoicesLength(choices.length, this.choices);\n\n\t\tfor (const { name, name_localizations, value } of choices) {\n\t\t\t// Validate the value\n\t\t\tif (this.type === ApplicationCommandOptionType.String) {\n\t\t\t\tstringPredicate.parse(value);\n\t\t\t} else {\n\t\t\t\tnumberPredicate.parse(value);\n\t\t\t}\n\n\t\t\tthis.choices!.push({ name, name_localizations, value });\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets multiple choices for this option.\n\t *\n\t * @param choices - The choices to set\n\t */\n\tpublic setChoices<Input extends APIApplicationCommandOptionChoice<T>[]>(...choices: Input): this {\n\t\tif (choices.length > 0 && this.autocomplete) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\tchoicesPredicate.parse(choices);\n\n\t\tReflect.set(this, 'choices', []);\n\t\tthis.addChoices(...choices);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Whether this option uses autocomplete.\n\t *\n\t * @param autocomplete - Whether this option should use autocomplete\n\t */\n\tpublic setAutocomplete(autocomplete: boolean): this {\n\t\t// Assert that you actually passed a boolean\n\t\tbooleanPredicate.parse(autocomplete);\n\n\t\tif (autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\tReflect.set(this, 'autocomplete', autocomplete);\n\n\t\treturn this;\n\t}\n}\n","import { ApplicationCommandOptionType, type APIApplicationCommandMentionableOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command mentionable option.\n */\nexport class SlashCommandMentionableOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Mentionable as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandMentionableOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandNumberOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin.js';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\n\nconst numberValidator = s.number;\n\n/**\n * A slash command number option.\n */\n@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)\nexport class SlashCommandNumberOption\n\textends ApplicationCommandOptionBase\n\timplements ApplicationCommandNumericOptionMinMaxValueMixin\n{\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.Number as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}\n\t */\n\tpublic setMaxValue(max: number): this {\n\t\tnumberValidator.parse(max);\n\n\t\tReflect.set(this, 'max_value', max);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}\n\t */\n\tpublic setMinValue(min: number): this {\n\t\tnumberValidator.parse(min);\n\n\t\tReflect.set(this, 'min_value', min);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandNumberOption {\n\t\tthis.runRequiredValidations();\n\n\t\tif (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\treturn { ...this } as APIApplicationCommandNumberOption;\n\t}\n}\n\nexport interface SlashCommandNumberOption\n\textends ApplicationCommandNumericOptionMinMaxValueMixin,\n\t\tApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> {}\n","import { ApplicationCommandOptionType, type APIApplicationCommandRoleOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command role option.\n */\nexport class SlashCommandRoleOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic override readonly type = ApplicationCommandOptionType.Role as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandRoleOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandOptionType, type APIApplicationCommandStringOption } from 'discord-api-types/v10';\nimport { mix } from 'ts-mixer';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\nimport { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.js';\n\nconst minLengthValidator = s.number.greaterThanOrEqual(0).lessThanOrEqual(6_000);\nconst maxLengthValidator = s.number.greaterThanOrEqual(1).lessThanOrEqual(6_000);\n\n/**\n * A slash command string option.\n */\n@mix(ApplicationCommandOptionWithChoicesAndAutocompleteMixin)\nexport class SlashCommandStringOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.String as const;\n\n\t/**\n\t * The maximum length of this option.\n\t */\n\tpublic readonly max_length?: number;\n\n\t/**\n\t * The minimum length of this option.\n\t */\n\tpublic readonly min_length?: number;\n\n\t/**\n\t * Sets the maximum length of this string option.\n\t *\n\t * @param max - The maximum length this option can be\n\t */\n\tpublic setMaxLength(max: number): this {\n\t\tmaxLengthValidator.parse(max);\n\n\t\tReflect.set(this, 'max_length', max);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the minimum length of this string option.\n\t *\n\t * @param min - The minimum length this option can be\n\t */\n\tpublic setMinLength(min: number): this {\n\t\tminLengthValidator.parse(min);\n\n\t\tReflect.set(this, 'min_length', min);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandStringOption {\n\t\tthis.runRequiredValidations();\n\n\t\tif (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {\n\t\t\tthrow new RangeError('Autocomplete and choices are mutually exclusive to each other.');\n\t\t}\n\n\t\treturn { ...this } as APIApplicationCommandStringOption;\n\t}\n}\n\nexport interface SlashCommandStringOption extends ApplicationCommandOptionWithChoicesAndAutocompleteMixin<string> {}\n","import { ApplicationCommandOptionType, type APIApplicationCommandUserOption } from 'discord-api-types/v10';\nimport { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase.js';\n\n/**\n * A slash command user option.\n */\nexport class SlashCommandUserOption extends ApplicationCommandOptionBase {\n\t/**\n\t * The type of this option.\n\t */\n\tpublic readonly type = ApplicationCommandOptionType.User as const;\n\n\t/**\n\t * {@inheritDoc ApplicationCommandOptionBase.toJSON}\n\t */\n\tpublic toJSON(): APIApplicationCommandUserOption {\n\t\tthis.runRequiredValidations();\n\n\t\treturn { ...this };\n\t}\n}\n","import { assertReturnOfBuilder, validateMaxOptionsLength } from '../Assertions.js';\nimport type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder';\nimport { SlashCommandAttachmentOption } from '../options/attachment.js';\nimport { SlashCommandBooleanOption } from '../options/boolean.js';\nimport { SlashCommandChannelOption } from '../options/channel.js';\nimport { SlashCommandIntegerOption } from '../options/integer.js';\nimport { SlashCommandMentionableOption } from '../options/mentionable.js';\nimport { SlashCommandNumberOption } from '../options/number.js';\nimport { SlashCommandRoleOption } from '../options/role.js';\nimport { SlashCommandStringOption } from '../options/string.js';\nimport { SlashCommandUserOption } from '../options/user.js';\nimport type { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js';\n\n/**\n * This mixin holds symbols that can be shared in slash command options.\n *\n * @typeParam ShouldOmitSubcommandFunctions - Whether to omit subcommand functions.\n */\nexport class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {\n\tpublic readonly options!: ToAPIApplicationCommandOptions[];\n\n\t/**\n\t * Adds a boolean option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addBooleanOption(\n\t\tinput: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandBooleanOption);\n\t}\n\n\t/**\n\t * Adds a user option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandUserOption);\n\t}\n\n\t/**\n\t * Adds a channel option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addChannelOption(\n\t\tinput: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandChannelOption);\n\t}\n\n\t/**\n\t * Adds a role option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandRoleOption);\n\t}\n\n\t/**\n\t * Adds an attachment option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addAttachmentOption(\n\t\tinput: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandAttachmentOption);\n\t}\n\n\t/**\n\t * Adds a mentionable option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addMentionableOption(\n\t\tinput: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandMentionableOption);\n\t}\n\n\t/**\n\t * Adds a string option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addStringOption(\n\t\tinput:\n\t\t\t| Omit<SlashCommandStringOption, 'addChoices'>\n\t\t\t| Omit<SlashCommandStringOption, 'setAutocomplete'>\n\t\t\t| SlashCommandStringOption\n\t\t\t| ((\n\t\t\t\t\tbuilder: SlashCommandStringOption,\n\t\t\t ) =>\n\t\t\t\t\t| Omit<SlashCommandStringOption, 'addChoices'>\n\t\t\t\t\t| Omit<SlashCommandStringOption, 'setAutocomplete'>\n\t\t\t\t\t| SlashCommandStringOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandStringOption);\n\t}\n\n\t/**\n\t * Adds an integer option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addIntegerOption(\n\t\tinput:\n\t\t\t| Omit<SlashCommandIntegerOption, 'addChoices'>\n\t\t\t| Omit<SlashCommandIntegerOption, 'setAutocomplete'>\n\t\t\t| SlashCommandIntegerOption\n\t\t\t| ((\n\t\t\t\t\tbuilder: SlashCommandIntegerOption,\n\t\t\t ) =>\n\t\t\t\t\t| Omit<SlashCommandIntegerOption, 'addChoices'>\n\t\t\t\t\t| Omit<SlashCommandIntegerOption, 'setAutocomplete'>\n\t\t\t\t\t| SlashCommandIntegerOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandIntegerOption);\n\t}\n\n\t/**\n\t * Adds a number option.\n\t *\n\t * @param input - A function that returns an option builder or an already built builder\n\t */\n\tpublic addNumberOption(\n\t\tinput:\n\t\t\t| Omit<SlashCommandNumberOption, 'addChoices'>\n\t\t\t| Omit<SlashCommandNumberOption, 'setAutocomplete'>\n\t\t\t| SlashCommandNumberOption\n\t\t\t| ((\n\t\t\t\t\tbuilder: SlashCommandNumberOption,\n\t\t\t ) =>\n\t\t\t\t\t| Omit<SlashCommandNumberOption, 'addChoices'>\n\t\t\t\t\t| Omit<SlashCommandNumberOption, 'setAutocomplete'>\n\t\t\t\t\t| SlashCommandNumberOption),\n\t) {\n\t\treturn this._sharedAddOptionMethod(input, SlashCommandNumberOption);\n\t}\n\n\t/**\n\t * Where the actual adding magic happens. ✨\n\t *\n\t * @param input - The input. What else?\n\t * @param Instance - The instance of whatever is being added\n\t * @internal\n\t */\n\tprivate _sharedAddOptionMethod<T extends ApplicationCommandOptionBase>(\n\t\tinput:\n\t\t\t| Omit<T, 'addChoices'>\n\t\t\t| Omit<T, 'setAutocomplete'>\n\t\t\t| T\n\t\t\t| ((builder: T) => Omit<T, 'addChoices'> | Omit<T, 'setAutocomplete'> | T),\n\t\tInstance: new () => T,\n\t): ShouldOmitSubcommandFunctions extends true ? Omit<this, 'addSubcommand' | 'addSubcommandGroup'> : this {\n\t\tconst { options } = this;\n\n\t\t// First, assert options conditions - we cannot have more than 25 options\n\t\tvalidateMaxOptionsLength(options);\n\n\t\t// Get the final result\n\t\tconst result = typeof input === 'function' ? input(new Instance()) : input;\n\n\t\tassertReturnOfBuilder(result, Instance);\n\n\t\t// Push it\n\t\toptions.push(result);\n\n\t\treturn this;\n\t}\n}\n","import { s } from '@sapphire/shapeshift';\nimport { ApplicationCommandType } from 'discord-api-types/v10';\nimport { isValidationEnabled } from '../../util/validation.js';\nimport type { ContextMenuCommandType } from './ContextMenuCommandBuilder.js';\n\nconst namePredicate = s.string\n\t.lengthGreaterThanOrEqual(1)\n\t.lengthLessThanOrEqual(32)\n\t// eslint-disable-next-line prefer-named-capture-group, unicorn/no-unsafe-regex\n\t.regex(/^( *[\\p{P}\\p{L}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}]+ *)+$/u)\n\t.setValidationEnabled(isValidationEnabled);\nconst typePredicate = s\n\t.union(s.literal(ApplicationCommandType.User), s.literal(ApplicationCommandType.Message))\n\t.setValidationEnabled(isValidationEnabled);\nconst booleanPredicate = s.boolean;\n\nexport function validateDefaultPermission(value: unknown): asserts value is boolean {\n\tbooleanPredicate.parse(value);\n}\n\nexport function validateName(name: unknown): asserts name is string {\n\tnamePredicate.parse(name);\n}\n\nexport function validateType(type: unknown): asserts type is ContextMenuCommandType {\n\ttypePredicate.parse(type);\n}\n\nexport function validateRequiredParameters(name: string, type: number) {\n\t// Assert name matches all conditions\n\tvalidateName(name);\n\n\t// Assert type is valid\n\tvalidateType(type);\n}\n\nconst dmPermissionPredicate = s.boolean.nullish;\n\nexport function validateDMPermission(value: unknown): asserts value is boolean | null | undefined {\n\tdmPermissionPredicate.parse(value);\n}\n\nconst memberPermissionPredicate = s.union(\n\ts.bigint.transform((value) => value.toString()),\n\ts.number.safeInt.transform((value) => value.toString()),\n\ts.string.regex(/^\\d+$/),\n).nullish;\n\nexport function validateDefaultMemberPermissions(permissions: unknown) {\n\treturn memberPermissionPredicate.parse(permissions);\n}\n","import type {\n\tApplicationCommandType,\n\tLocaleString,\n\tLocalizationMap,\n\tPermissions,\n\tRESTPostAPIContextMenuApplicationCommandsJSONBody,\n} from 'discord-api-types/v10';\nimport { validateLocale, validateLocalizationMap } from '../slashCommands/Assertions.js';\nimport {\n\tvalidateRequiredParameters,\n\tvalidateName,\n\tvalidateType,\n\tvalidateDefaultPermission,\n\tvalidateDefaultMemberPermissions,\n\tvalidateDMPermission,\n} from './Assertions.js';\n\n/**\n * The type a context menu command can be.\n */\nexport type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;\n\n/**\n * A builder that creates API-compatible JSON data for context menu commands.\n */\nexport class ContextMenuCommandBuilder {\n\t/**\n\t * The name of this command.\n\t */\n\tpublic readonly name: string = undefined!;\n\n\t/**\n\t * The name localizations of this command.\n\t */\n\tpublic readonly name_localizations?: LocalizationMap;\n\n\t/**\n\t * The type of this command.\n\t */\n\tpublic readonly type: ContextMenuCommandType = undefined!;\n\n\t/**\n\t * Whether this command is enabled by default when the application is added to a guild.\n\t *\n\t * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic readonly default_permission: boolean | undefined = undefined;\n\n\t/**\n\t * The set of permissions represented as a bit set for the command.\n\t */\n\tpublic readonly default_member_permissions: Permissions | null | undefined = undefined;\n\n\t/**\n\t * Indicates whether the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This property is only for global commands.\n\t */\n\tpublic readonly dm_permission: boolean | undefined = undefined;\n\n\t/**\n\t * Sets the name of this command.\n\t *\n\t * @param name - The name to use\n\t */\n\tpublic setName(name: string) {\n\t\t// Assert the name matches the conditions\n\t\tvalidateName(name);\n\n\t\tReflect.set(this, 'name', name);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the type of this command.\n\t *\n\t * @param type - The type to use\n\t */\n\tpublic setType(type: ContextMenuCommandType) {\n\t\t// Assert the type is valid\n\t\tvalidateType(type);\n\n\t\tReflect.set(this, 'type', type);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets whether the command is enabled by default when the application is added to a guild.\n\t *\n\t * @remarks\n\t * If set to `false`, you will have to later `PUT` the permissions for this command.\n\t * @param value - Whether to enable this command by default\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t * @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.\n\t */\n\tpublic setDefaultPermission(value: boolean) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDefaultPermission(value);\n\n\t\tReflect.set(this, 'default_permission', value);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the default permissions a member should have in order to run this command.\n\t *\n\t * @remarks\n\t * You can set this to `'0'` to disable the command by default.\n\t * @param permissions - The permissions bit field to set\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined) {\n\t\t// Assert the value and parse it\n\t\tconst permissionValue = validateDefaultMemberPermissions(permissions);\n\n\t\tReflect.set(this, 'default_member_permissions', permissionValue);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets if the command is available in direct messages with the application.\n\t *\n\t * @remarks\n\t * By default, commands are visible. This method is only for global commands.\n\t * @param enabled - Whether the command should be enabled in direct messages\n\t * @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}\n\t */\n\tpublic setDMPermission(enabled: boolean | null | undefined) {\n\t\t// Assert the value matches the conditions\n\t\tvalidateDMPermission(enabled);\n\n\t\tReflect.set(this, 'dm_permission', enabled);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets a name localization for this command.\n\t *\n\t * @param locale - The locale to set\n\t * @param localizedName - The localized name for the given `locale`\n\t */\n\tpublic setNameLocalization(locale: LocaleString, localizedName: string | null) {\n\t\tif (!this.name_localizations) {\n\t\t\tReflect.set(this, 'name_localizations', {});\n\t\t}\n\n\t\tconst parsedLocale = validateLocale(locale);\n\n\t\tif (localizedName === null) {\n\t\t\tthis.name_localizations![parsedLocale] = null;\n\t\t\treturn this;\n\t\t}\n\n\t\tvalidateName(localizedName);\n\n\t\tthis.name_localizations![parsedLocale] = localizedName;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the name localizations for this command.\n\t *\n\t * @param localizedNames - The object of localized names to set\n\t */\n\tpublic setNameLocalizations(localizedNames: LocalizationMap | null) {\n\t\tif (localizedNames === null) {\n\t\t\tReflect.set(this, 'name_localizations', null);\n\t\t\treturn this;\n\t\t}\n\n\t\tReflect.set(this, 'name_localizations', {});\n\n\t\tfor (const args of Object.entries(localizedNames))\n\t\t\tthis.setNameLocalization(...(args as [LocaleString, string | null]));\n\t\treturn this;\n\t}\n\n\t/**\n\t * Serializes this builder to API-compatible JSON data.\n\t *\n\t * @remarks\n\t * This method runs validations on the data before serializing it.\n\t * As such, it may throw an error if the data is invalid.\n\t */\n\tpublic toJSON(): RESTPostAPIContextMenuApplicationCommandsJSONBody {\n\t\tvalidateRequiredParameters(this.name, this.type);\n\n\t\tvalidateLocalizationMap(this.name_localizations);\n\n\t\treturn { ...this };\n\t}\n}\n","import type { APIEmbed } from 'discord-api-types/v10';\n\n/**\n * Calculates the length of the embed.\n *\n * @param data - The embed data to check\n */\nexport function embedLength(data: APIEmbed) {\n\treturn (\n\t\t(data.title?.length ?? 0) +\n\t\t(data.description?.length ?? 0) +\n\t\t(data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) +\n\t\t(data.footer?.text.length ?? 0) +\n\t\t(data.author?.name.length ?? 0)\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,SAAS;;;ACAlB,IAAI,WAAW;AAOR,SAAS,mBAAmB;AAClC,SAAQ,WAAW;AACpB;AAFgB;AAST,SAAS,oBAAoB;AACnC,SAAQ,WAAW;AACpB;AAFgB;AAOT,SAAS,sBAAsB;AACrC,SAAO;AACR;AAFgB;;;ADnBT,IAAM,qBAAqB,EAAE,OAClC,yBAAyB,CAAC,EAC1B,sBAAsB,GAAG,EACzB,qBAAqB,mBAAmB;AAEnC,IAAM,sBAAsB,EAAE,OACnC,yBAAyB,CAAC,EAC1B,sBAAsB,IAAK,EAC3B,qBAAqB,mBAAmB;AAEnC,IAAM,uBAAuB,EAAE,QAAQ;AAEvC,IAAM,sBAAsB,EACjC,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACT,CAAC,EACA,qBAAqB,mBAAmB;AAEnC,IAAM,4BAA4B,oBAAoB,MAAM,qBAAqB,mBAAmB;AAEpG,IAAM,uBAAuB,EAAE,OAAO,gBAAgB,EAAE,EAAE,qBAAqB,mBAAmB;AAElG,SAAS,oBAAoB,cAAsB,QAAgC;AACzF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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,SAA4D;AAClE,IAAAI,4BAA2B,KAAK,MAAM,KAAK,IAAI;AAE/C,4BAAwB,KAAK,kBAAkB;AAE/C,WAAO,EAAE,GAAG,KAAK;AAAA,EAClB;AACD;;;AC9LO,SAAS,YAAY,MAAgB;AAC3C,UACE,KAAK,OAAO,UAAU,MACtB,KAAK,aAAa,UAAU,MAC5B,KAAK,QAAQ,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,SAAS,KAAK,MAAM,QAAQ,CAAC,KAAK,MACvF,KAAK,QAAQ,KAAK,UAAU,MAC5B,KAAK,QAAQ,KAAK,UAAU;AAE/B;AARgB;;;ArC6DT,IAAM,UAAU;","names":["Assertions_exports","s","s","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","ComponentType","Assertions_exports","placeholderValidator","s","s","placeholderValidator","ComponentType","placeholderValidator","ComponentType","ComponentType","Assertions_exports","validateRequiredParameters","s","s","validateRequiredParameters","validateRequiredParameters","Assertions_exports","validateRequiredParameters","s","s","descriptionPredicate","validateRequiredParameters","mix","ApplicationCommandOptionType","mix","validateRequiredParameters","ApplicationCommandOptionType","ApplicationCommandOptionType","ApplicationCommandOptionType","s","ChannelType","ChannelType","s","ApplicationCommandOptionType","s","ApplicationCommandOptionType","mix","s","ApplicationCommandOptionType","s","booleanPredicate","ApplicationCommandOptionType","s","ApplicationCommandOptionType","mix","ApplicationCommandOptionType","ApplicationCommandOptionType","s","ApplicationCommandOptionType","mix","numberValidator","s","ApplicationCommandOptionType","mix","ApplicationCommandOptionType","ApplicationCommandOptionType","s","ApplicationCommandOptionType","mix","minLengthValidator","s","maxLengthValidator","ApplicationCommandOptionType","mix","ApplicationCommandOptionType","ApplicationCommandOptionType","validateRequiredParameters","ApplicationCommandOptionType","mix","validateRequiredParameters","mix","Assertions_exports","validateDMPermission","validateDefaultMemberPermissions","validateDefaultPermission","validateName","validateRequiredParameters","s","namePredicate","s","booleanPredicate","validateDefaultPermission","validateName","validateRequiredParameters","dmPermissionPredicate","validateDMPermission","memberPermissionPredicate","validateDefaultMemberPermissions","validateName","validateDefaultPermission","validateDefaultMemberPermissions","validateDMPermission","validateRequiredParameters"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/builders/package.json b/node_modules/@discordjs/builders/package.json new file mode 100644 index 0000000..acec7e3 --- /dev/null +++ b/node_modules/@discordjs/builders/package.json @@ -0,0 +1,90 @@ +{ + "name": "@discordjs/builders", + "version": "1.6.5", + "description": "A set of builders that you can use when creating your bot", + "scripts": { + "test": "vitest run", + "build": "tsup", + "build:docs": "tsc -p tsconfig.docs.json && yarn downlevel-dts ./dist-docs ./dist-docs", + "lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --format=pretty", + "format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix --format=pretty", + "fmt": "yarn format", + "docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json", + "prepack": "yarn lint && yarn test && yarn build", + "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/builders/*'", + "release": "cliff-jumper" + }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "directories": { + "lib": "src", + "test": "__tests__" + }, + "files": [ + "dist" + ], + "contributors": [ + "Vlad Frangu <kingdgrizzle@gmail.com>", + "Crawl <icrawltogo@gmail.com>", + "Amish Shah <amishshah.2k@gmail.com>", + "SpaceEEC <spaceeec@yahoo.com>", + "Aura Román <kyradiscord@gmail.com>" + ], + "license": "Apache-2.0", + "keywords": [ + "discord", + "api", + "bot", + "client", + "node", + "discordapp", + "discordjs" + ], + "repository": { + "type": "git", + "url": "https://github.com/discordjs/discord.js.git", + "directory": "packages/builders" + }, + "bugs": { + "url": "https://github.com/discordjs/discord.js/issues" + }, + "homepage": "https://discord.js.org", + "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" + }, + "devDependencies": { + "@favware/cliff-jumper": "^2.1.1", + "@microsoft/api-extractor": "^7.36.4", + "@types/node": "16.18.40", + "@vitest/coverage-v8": "^0.34.2", + "cross-env": "^7.0.3", + "downlevel-dts": "^0.11.0", + "esbuild-plugin-version-injector": "^1.2.0", + "eslint": "^8.47.0", + "eslint-config-neon": "^0.1.47", + "eslint-formatter-pretty": "^5.0.0", + "prettier": "^2.8.8", + "tsup": "^7.2.0", + "turbo": "^1.10.12", + "typescript": "^5.1.6", + "vitest": "^0.34.2" + }, + "engines": { + "node": ">=16.11.0" + }, + "publishConfig": { + "access": "public" + } +}
\ No newline at end of file diff --git a/node_modules/@discordjs/collection/CHANGELOG.md b/node_modules/@discordjs/collection/CHANGELOG.md new file mode 100644 index 0000000..2c43057 --- /dev/null +++ b/node_modules/@discordjs/collection/CHANGELOG.md @@ -0,0 +1,190 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +# [@discordjs/collection@1.5.3](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.5.2...@discordjs/collection@1.5.3) - (2023-08-17) + +## Documentation + +- Update Node.js requirement to 16.11.0 (#9764) ([188877c](https://github.com/discordjs/discord.js/commit/188877c50af70f0d5cffb246620fa277435c6ce6)) + +# [@discordjs/collection@1.5.2](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.5.1...@discordjs/collection@1.5.2) - (2023-07-31) + +## Refactor + +- **collection:** Reduce `reduce`'s code (#9581) ([b85a3f2](https://github.com/discordjs/discord.js/commit/b85a3f2ddee8fc5974749b95fc07389a03093df2)) + +# [@discordjs/collection@1.5.1](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.5.0...@discordjs/collection@1.5.1) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/collection@1.5.2](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.5.1...@discordjs/collection@1.5.2) - (2023-07-31) + +## Refactor + +- **collection:** Reduce `reduce`'s code (#9581) ([b85a3f2](https://github.com/discordjs/discord.js/commit/b85a3f2ddee8fc5974749b95fc07389a03093df2)) + +# [@discordjs/collection@1.5.1](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.5.0...@discordjs/collection@1.5.1) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/collection@1.5.1](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.5.0...@discordjs/collection@1.5.1) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/collection@1.5.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.4.0...@discordjs/collection@1.5.0) - (2023-04-01) + +## Bug Fixes + +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +## Refactor + +- **collection:** Fix/silence linter warnings (#9266) ([d6f4e60](https://github.com/discordjs/discord.js/commit/d6f4e60efd1a1796fc84dbbfbac4f9790e480a1c)) + +# [@discordjs/collection@1.4.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.3.0...@discordjs/collection@1.4.0) - (2023-03-12) + +## Documentation + +- Fix version export (#9049) ([8b70f49](https://github.com/discordjs/discord.js/commit/8b70f497a1207e30edebdecd12b926c981c13d28)) + +## Features + +- **website:** Add support for source file links (#9048) ([f6506e9](https://github.com/discordjs/discord.js/commit/f6506e99c496683ee0ab67db0726b105b929af38)) + +## Refactor + +- Compare with `undefined` directly (#9191) ([869153c](https://github.com/discordjs/discord.js/commit/869153c3fdf155783e7c0ecebd3627b087c3a026)) + +# [@discordjs/collection@1.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.2.0...@discordjs/collection@1.3.0) - (2022-11-28) + +## Bug Fixes + +- Pin @types/node version ([9d8179c](https://github.com/discordjs/discord.js/commit/9d8179c6a78e1c7f9976f852804055964d5385d4)) + +## Features + +- Add `Collection#subtract()` (#8393) ([291f36c](https://github.com/discordjs/discord.js/commit/291f36cd736b5dea058145a1335bf7c78ec1d81d)) + +# [@discordjs/collection@1.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.1.0...@discordjs/collection@1.2.0) - (2022-10-08) + +## Bug Fixes + +- Footer / sidebar / deprecation alert ([ba3e0ed](https://github.com/discordjs/discord.js/commit/ba3e0ed348258fe8e51eefb4aa7379a1230616a9)) + +## Documentation + +- Change name (#8604) ([dd5a089](https://github.com/discordjs/discord.js/commit/dd5a08944c258a847fc4377f1d5e953264ab47d0)) +- Remove xml tag from collection#find (#8550) ([4032457](https://github.com/discordjs/discord.js/commit/40324574ebea9894cadcc967e0db0e4e21d62768)) + +## Features + +- Web-components (#8715) ([0ac3e76](https://github.com/discordjs/discord.js/commit/0ac3e766bd9dbdeb106483fa4bb085d74de346a2)) + +## Refactor + +- Website components (#8600) ([c334157](https://github.com/discordjs/discord.js/commit/c3341570d983aea9ecc419979d5a01de658c9d67)) +- Use `eslint-config-neon` for packages. (#8579) ([edadb9f](https://github.com/discordjs/discord.js/commit/edadb9fe5dfd9ff51a3cfc9b25cb242d3f9f5241)) + +## Typings + +- **Collection:** Make fn return type unknown (#8676) ([822b7f2](https://github.com/discordjs/discord.js/commit/822b7f234af053c8f917b0a998b82abfccd33801)) + +# [@discordjs/collection@1.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@1.0.1...@discordjs/collection@1.1.0) - (2022-08-22) + +## Bug Fixes + +- Use proper format for `@link` text (#8384) ([2655639](https://github.com/discordjs/discord.js/commit/26556390a3800e954974a00c1328ff47d3e67e9a)) + +## Documentation + +- Fence examples in codeblocks ([193b252](https://github.com/discordjs/discord.js/commit/193b252672440a860318d3c2968aedd9cb88e0ce)) +- Use link tags (#8382) ([5494791](https://github.com/discordjs/discord.js/commit/549479131318c659f86f0eb18578d597e22522d3)) + +## Features + +- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007)) +- **website:** Show descriptions for `@typeParam` blocks (#8523) ([e475b63](https://github.com/discordjs/discord.js/commit/e475b63f257f6261d73cb89fee9ecbcdd84e2a6b)) + +## Refactor + +- **website:** Adjust typography (#8503) ([0f83402](https://github.com/discordjs/discord.js/commit/0f834029850d2448981596cf082ff59917018d66)) +- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e)) + +# [@discordjs/collection@0.8.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@0.7.0...@discordjs/collection@0.8.0) - (2022-07-17) + +## Bug Fixes + +- **Collection:** Make error messages consistent (#8224) ([5bd6b28](https://github.com/discordjs/discord.js/commit/5bd6b28b3ebfced1cb9d23e83bd7c0def7a12404)) +- Check for function type (#8064) ([3bb9c0e](https://github.com/discordjs/discord.js/commit/3bb9c0e5c37311044ff41761b572ac4f91cda57c)) + +## Documentation + +- Add codecov coverage badge to readmes (#8226) ([f6db285](https://github.com/discordjs/discord.js/commit/f6db285c073898a749fe4591cbd4463d1896daf5)) + +## Features + +- Codecov (#8219) ([f10f4cd](https://github.com/discordjs/discord.js/commit/f10f4cdcd88ca6be7ec735ed3a415ba13da83db0)) +- **docgen:** Update typedoc ([b3346f4](https://github.com/discordjs/discord.js/commit/b3346f4b9b3d4f96443506643d4631dc1c6d7b21)) +- Website (#8043) ([127931d](https://github.com/discordjs/discord.js/commit/127931d1df7a2a5c27923c2f2151dbf3824e50cc)) +- **docgen:** Typescript support ([3279b40](https://github.com/discordjs/discord.js/commit/3279b40912e6aa61507bedb7db15a2b8668de44b)) +- Docgen package (#8029) ([8b979c0](https://github.com/discordjs/discord.js/commit/8b979c0245c42fd824d8e98745ee869f5360fc86)) +- Use vitest instead of jest for more speed ([8d8e6c0](https://github.com/discordjs/discord.js/commit/8d8e6c03decd7352a2aa180f6e5bc1a13602539b)) +- Add scripts package for locally used scripts ([f2ae1f9](https://github.com/discordjs/discord.js/commit/f2ae1f9348bfd893332a9060f71a8a5f272a1b8b)) + +## Refactor + +- **collection:** Remove `default` property (#8055) ([c8f1690](https://github.com/discordjs/discord.js/commit/c8f1690896f55f06e05a83704262783cfc2bb91d)) +- **collection:** Remove default export (#8053) ([16810f3](https://github.com/discordjs/discord.js/commit/16810f3e410bf35ed7e6e7412d517ea74c792c5d)) +- Move all the config files to root (#8033) ([769ea0b](https://github.com/discordjs/discord.js/commit/769ea0bfe78c4f1d413c6b397c604ffe91e39c6a)) + +## Testing + +- **collection:** Improve coverage (#8222) ([a51f721](https://github.com/discordjs/discord.js/commit/a51f7215eca67a0f46fba8b2d706f7ec6f6dc228)) + +# [@discordjs/collection@0.7.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@0.6.0...@discordjs/collection@0.7.0) - (2022-06-04) + +## Styling + +- Cleanup tests and tsup configs ([6b8ef20](https://github.com/discordjs/discord.js/commit/6b8ef20cb3af5b5cfd176dd0aa0a1a1e98551629)) + +# [@discordjs/collection@0.6.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@0.5.0...@discordjs/collection@0.6.0) - (2022-04-17) + +## Features + +- Add support for module: NodeNext in TS and ESM (#7598) ([8f1986a](https://github.com/discordjs/discord.js/commit/8f1986a6aa98365e09b00e84ad5f9f354ab61f3d)) +- **builders:** Add attachment command option type (#7203) ([ae0f35f](https://github.com/discordjs/discord.js/commit/ae0f35f51d68dfa5a7dc43d161ef9365171debdb)) +- **Collection:** Add merging functions (#7299) ([e4bd07b](https://github.com/discordjs/discord.js/commit/e4bd07b2394f227ea06b72eb6999de9ab3127b25)) + +# [@discordjs/collection@0.5.0](https://github.com/discordjs/discord.js/compare/@discordjs/collection@0.4.0...@discordjs/collection@0.5.0) - (2022-01-24) + +## Refactor + +- Make `intersect` perform a true intersection (#7211) ([d8efba2](https://github.com/discordjs/discord.js/commit/d8efba24e09aa2a8dbf028fc57a561a56e7833fd)) + +## Typings + +- Add `ReadonlyCollection` (#7245) ([db25f52](https://github.com/discordjs/discord.js/commit/db25f529b26d7c819c1c42ad3e26c2263ea2da0e)) +- **Collection:** Union types on `intersect` and `difference` (#7196) ([1f9b922](https://github.com/discordjs/discord.js/commit/1f9b9225f2066e9cc66c3355417139fd25cc403c)) diff --git a/node_modules/@discordjs/collection/LICENSE b/node_modules/@discordjs/collection/LICENSE new file mode 100644 index 0000000..d21f37a --- /dev/null +++ b/node_modules/@discordjs/collection/LICENSE @@ -0,0 +1,191 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "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 Noel Buechler + Copyright 2015 Amish Shah + + 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. diff --git a/node_modules/@discordjs/collection/README.md b/node_modules/@discordjs/collection/README.md new file mode 100644 index 0000000..4ddde14 --- /dev/null +++ b/node_modules/@discordjs/collection/README.md @@ -0,0 +1,67 @@ +<div align="center"> + <br /> + <p> + <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a> + </p> + <br /> + <p> + <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a> + <a href="https://www.npmjs.com/package/@discordjs/collection"><img src="https://img.shields.io/npm/v/@discordjs/collection.svg?maxAge=3600" alt="npm version" /></a> + <a href="https://www.npmjs.com/package/@discordjs/collection"><img src="https://img.shields.io/npm/dt/@discordjs/collection.svg?maxAge=3600" alt="npm downloads" /></a> + <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a> + <a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=collection" alt="Code coverage" /></a> + </p> + <p> + <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a> + <a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a> + </p> +</div> + +## About + +`@discordjs/collection` is a powerful utility data structure used in discord.js. + +## Installation + +**Node.js 16.11.0 or newer is required.** + +```sh +npm install @discordjs/collection +yarn add @discordjs/collection +pnpm add @discordjs/collection +``` + +## Links + +- [Website][website] ([source][website-source]) +- [Documentation][documentation] +- [Guide][guide] ([source][guide-source]) + Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library. +- [discord.js Discord server][discord] +- [Discord API Discord server][discord-api] +- [GitHub][source] +- [npm][npm] +- [Related libraries][related-libs] + +## Contributing + +Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the +[documentation][documentation]. +See [the contribution guide][contributing] if you'd like to submit a PR. + +## Help + +If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord]. + +[website]: https://discord.js.org +[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website +[documentation]: https://discord.js.org/docs/packages/collection/stable +[guide]: https://discordjs.guide/ +[guide-source]: https://github.com/discordjs/guide +[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html +[discord]: https://discord.gg/djs +[discord-api]: https://discord.gg/discord-api +[source]: https://github.com/discordjs/discord.js/tree/main/packages/collection +[npm]: https://www.npmjs.com/package/@discordjs/collection +[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries +[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md diff --git a/node_modules/@discordjs/collection/dist/index.d.mts b/node_modules/@discordjs/collection/dist/index.d.mts new file mode 100644 index 0000000..5990c61 --- /dev/null +++ b/node_modules/@discordjs/collection/dist/index.d.mts @@ -0,0 +1,457 @@ +/** + * @internal + */ +interface CollectionConstructor { + new (): Collection<unknown, unknown>; + new <K, V>(entries?: readonly (readonly [K, V])[] | null): Collection<K, V>; + new <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>; + readonly prototype: Collection<unknown, unknown>; + readonly [Symbol.species]: CollectionConstructor; +} +/** + * Represents an immutable version of a collection + */ +type ReadonlyCollection<K, V> = Omit<Collection<K, V>, 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<K, V>; +/** + * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself + * + * @internal + */ +interface Collection<K, V> extends Map<K, V> { + constructor: CollectionConstructor; +} +/** + * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has + * an ID, for significantly improved performance and ease-of-use. + * + * @typeParam K - The key type this collection holds + * @typeParam V - The value type this collection holds + */ +declare class Collection<K, V> extends Map<K, V> { + /** + * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator. + * + * @param key - The key to get if it exists, or set otherwise + * @param defaultValueGenerator - A function that generates the default value + * @example + * ```ts + * collection.ensure(guildId, () => defaultGuildConfig); + * ``` + */ + ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V; + /** + * Checks if all of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if all of the elements exist, `false` if at least one does not exist. + */ + hasAll(...keys: K[]): boolean; + /** + * Checks if any of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if any of the elements exist, `false` if none exist. + */ + hasAny(...keys: K[]): boolean; + /** + * Obtains the first value(s) in this collection. + * + * @param amount - Amount of values to obtain from the beginning + * @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative + */ + first(): V | undefined; + first(amount: number): V[]; + /** + * Obtains the first key(s) in this collection. + * + * @param amount - Amount of keys to obtain from the beginning + * @returns A single key if no amount is provided or an array of keys, starting from the end if + * amount is negative + */ + firstKey(): K | undefined; + firstKey(amount: number): K[]; + /** + * Obtains the last value(s) in this collection. + * + * @param amount - Amount of values to obtain from the end + * @returns A single value if no amount is provided or an array of values, starting from the start if + * amount is negative + */ + last(): V | undefined; + last(amount: number): V[]; + /** + * Obtains the last key(s) in this collection. + * + * @param amount - Amount of keys to obtain from the end + * @returns A single key if no amount is provided or an array of keys, starting from the start if + * amount is negative + */ + lastKey(): K | undefined; + lastKey(amount: number): K[]; + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the item at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the element to obtain + */ + at(index: number): V | undefined; + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the key at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the key to obtain + */ + keyAt(index: number): K | undefined; + /** + * Obtains unique random value(s) from this collection. + * + * @param amount - Amount of values to obtain randomly + * @returns A single value if no amount is provided or an array of values + */ + random(): V | undefined; + random(amount: number): V[]; + /** + * Obtains unique random key(s) from this collection. + * + * @param amount - Amount of keys to obtain randomly + * @returns A single key if no amount is provided or an array + */ + randomKey(): K | undefined; + randomKey(amount: number): K[]; + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()} + * but returns a Collection instead of an Array. + */ + reverse(): this; + /** + * Searches for a single item where the given function returns a truthy value. This behaves like + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.find()}. + * All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you + * should use the `get` method. See + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details. + * + * @param fn - The function to test with (should return boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.find(user => user.username === 'Bob'); + * ``` + */ + find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined; + find(fn: (value: V, key: K, collection: this) => unknown): V | undefined; + find<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): V2 | undefined; + find<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): V | undefined; + /** + * Searches for the key of a single item where the given function returns a truthy value. This behaves like + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()}, + * but returns the key rather than the positional index. + * + * @param fn - The function to test with (should return boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.findKey(user => user.username === 'Bob'); + * ``` + */ + findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined; + findKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined; + findKey<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): K2 | undefined; + findKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined; + /** + * Removes items that satisfy the provided filter function. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @returns The number of removed entries + */ + sweep(fn: (value: V, key: K, collection: this) => unknown): number; + sweep<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): number; + /** + * Identical to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()}, + * but returns a Collection instead of an Array. + * + * @param fn - The function to test with (should return boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.filter(user => user.username === 'Bob'); + * ``` + */ + filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>; + filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>; + filter(fn: (value: V, key: K, collection: this) => unknown): Collection<K, V>; + filter<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): Collection<K2, V>; + filter<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): Collection<K, V2>; + filter<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): Collection<K, V>; + /** + * Partitions the collection into two collections where the first collection + * contains the items that passed and the second contains the items that failed. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * const [big, small] = collection.partition(guild => guild.memberCount > 250); + * ``` + */ + partition<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): [Collection<K2, V>, Collection<Exclude<K, K2>, V>]; + partition<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): [Collection<K, V2>, Collection<K, Exclude<V, V2>>]; + partition(fn: (value: V, key: K, collection: this) => unknown): [Collection<K, V>, Collection<K, V>]; + partition<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): [Collection<K2, V>, Collection<Exclude<K, K2>, V>]; + partition<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): [Collection<K, V2>, Collection<K, Exclude<V, V2>>]; + partition<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): [Collection<K, V>, Collection<K, V>]; + /** + * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}. + * + * @param fn - Function that produces a new Collection + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.flatMap(guild => guild.members.cache); + * ``` + */ + flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>; + flatMap<T, This>(fn: (this: This, value: V, key: K, collection: this) => Collection<K, T>, thisArg: This): Collection<K, T>; + /** + * Maps each item to another value into an array. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}. + * + * @param fn - Function that produces an element of the new array, taking three arguments + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.map(user => user.tag); + * ``` + */ + map<T>(fn: (value: V, key: K, collection: this) => T): T[]; + map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[]; + /** + * Maps each item to another value into a collection. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}. + * + * @param fn - Function that produces an element of the new collection, taking three arguments + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.mapValues(user => user.tag); + * ``` + */ + mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>; + mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>; + /** + * Checks if there exists an item that passes a test. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.some(user => user.discriminator === '0000'); + * ``` + */ + some(fn: (value: V, key: K, collection: this) => unknown): boolean; + some<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): boolean; + /** + * Checks if all items passes a test. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.every(user => !user.bot); + * ``` + */ + every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>; + every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>; + every(fn: (value: V, key: K, collection: this) => unknown): boolean; + every<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): this is Collection<K2, V>; + every<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): this is Collection<K, V2>; + every<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): boolean; + /** + * Applies a function to produce a single value. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}. + * + * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`, + * and `collection` + * @param initialValue - Starting value for the accumulator + * @example + * ```ts + * collection.reduce((acc, guild) => acc + guild.memberCount, 0); + * ``` + */ + reduce<T = V>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T; + /** + * Identical to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()}, + * but returns the collection instead of undefined. + * + * @param fn - Function to execute for each element + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection + * .each(user => console.log(user.username)) + * .filter(user => user.bot) + * .each(user => console.log(user.username)); + * ``` + */ + each(fn: (value: V, key: K, collection: this) => void): this; + each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this; + /** + * Runs a function on the collection and returns the collection. + * + * @param fn - Function to execute + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection + * .tap(coll => console.log(coll.size)) + * .filter(user => user.bot) + * .tap(coll => console.log(coll.size)) + * ``` + */ + tap(fn: (collection: this) => void): this; + tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this; + /** + * Creates an identical shallow copy of this collection. + * + * @example + * ```ts + * const newColl = someColl.clone(); + * ``` + */ + clone(): Collection<K, V>; + /** + * Combines this collection with others into a new collection. None of the source collections are modified. + * + * @param collections - Collections to merge + * @example + * ```ts + * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl); + * ``` + */ + concat(...collections: ReadonlyCollection<K, V>[]): Collection<K, V>; + /** + * Checks if this collection shares identical items with another. + * This is different to checking for equality using equal-signs, because + * the collections may be different objects, but contain the same data. + * + * @param collection - Collection to compare with + * @returns Whether the collections have identical contents + */ + equals(collection: ReadonlyCollection<K, V>): boolean; + /** + * The sort method sorts the items of a collection in place and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. + * @example + * ```ts + * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sort(compareFunction?: Comparator<K, V>): this; + /** + * The intersect method returns a new structure containing items where the keys and values are present in both original structures. + * + * @param other - The other Collection to filter against + */ + intersect<T>(other: ReadonlyCollection<K, T>): Collection<K, T>; + /** + * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other. + * + * @param other - The other Collection to filter against + */ + subtract<T>(other: ReadonlyCollection<K, T>): Collection<K, V>; + /** + * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other. + * + * @param other - The other Collection to filter against + */ + difference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>; + /** + * Merges two Collections together into a new Collection. + * + * @param other - The other Collection to merge with + * @param whenInSelf - Function getting the result if the entry only exists in this Collection + * @param whenInOther - Function getting the result if the entry only exists in the other Collection + * @param whenInBoth - Function getting the result if the entry exists in both Collections + * @example + * ```ts + * // Sums up the entries in two collections. + * coll.merge( + * other, + * x => ({ keep: true, value: x }), + * y => ({ keep: true, value: y }), + * (x, y) => ({ keep: true, value: x + y }), + * ); + * ``` + * @example + * ```ts + * // Intersects two collections in a left-biased manner. + * coll.merge( + * other, + * x => ({ keep: false }), + * y => ({ keep: false }), + * (x, _) => ({ keep: true, value: x }), + * ); + * ``` + */ + merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: (value: V, key: K) => Keep<R>, whenInOther: (valueOther: T, key: K) => Keep<R>, whenInBoth: (value: V, valueOther: T, key: K) => Keep<R>): Collection<K, R>; + /** + * The sorted method sorts the items of a collection and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, + * according to the string conversion of each element. + * @example + * ```ts + * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sorted(compareFunction?: Comparator<K, V>): Collection<K, V>; + toJSON(): V[]; + private static defaultSort; + /** + * Creates a Collection from a list of entries. + * + * @param entries - The list of entries + * @param combine - Function to combine an existing entry with a new one + * @example + * ```ts + * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); + * // returns Collection { "a" => 3, "b" => 2 } + * ``` + */ + static combineEntries<K, V>(entries: Iterable<[K, V]>, combine: (firstValue: V, secondValue: V, key: K) => V): Collection<K, V>; +} +/** + * @internal + */ +type Keep<V> = { + keep: false; +} | { + keep: true; + value: V; +}; +/** + * @internal + */ +type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number; + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection/#readme | @discordjs/collection} version + * that you are currently using. + */ +declare const version: string; + +export { Collection, CollectionConstructor, Comparator, Keep, ReadonlyCollection, version }; diff --git a/node_modules/@discordjs/collection/dist/index.d.ts b/node_modules/@discordjs/collection/dist/index.d.ts new file mode 100644 index 0000000..5990c61 --- /dev/null +++ b/node_modules/@discordjs/collection/dist/index.d.ts @@ -0,0 +1,457 @@ +/** + * @internal + */ +interface CollectionConstructor { + new (): Collection<unknown, unknown>; + new <K, V>(entries?: readonly (readonly [K, V])[] | null): Collection<K, V>; + new <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>; + readonly prototype: Collection<unknown, unknown>; + readonly [Symbol.species]: CollectionConstructor; +} +/** + * Represents an immutable version of a collection + */ +type ReadonlyCollection<K, V> = Omit<Collection<K, V>, 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<K, V>; +/** + * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself + * + * @internal + */ +interface Collection<K, V> extends Map<K, V> { + constructor: CollectionConstructor; +} +/** + * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has + * an ID, for significantly improved performance and ease-of-use. + * + * @typeParam K - The key type this collection holds + * @typeParam V - The value type this collection holds + */ +declare class Collection<K, V> extends Map<K, V> { + /** + * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator. + * + * @param key - The key to get if it exists, or set otherwise + * @param defaultValueGenerator - A function that generates the default value + * @example + * ```ts + * collection.ensure(guildId, () => defaultGuildConfig); + * ``` + */ + ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V; + /** + * Checks if all of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if all of the elements exist, `false` if at least one does not exist. + */ + hasAll(...keys: K[]): boolean; + /** + * Checks if any of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if any of the elements exist, `false` if none exist. + */ + hasAny(...keys: K[]): boolean; + /** + * Obtains the first value(s) in this collection. + * + * @param amount - Amount of values to obtain from the beginning + * @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative + */ + first(): V | undefined; + first(amount: number): V[]; + /** + * Obtains the first key(s) in this collection. + * + * @param amount - Amount of keys to obtain from the beginning + * @returns A single key if no amount is provided or an array of keys, starting from the end if + * amount is negative + */ + firstKey(): K | undefined; + firstKey(amount: number): K[]; + /** + * Obtains the last value(s) in this collection. + * + * @param amount - Amount of values to obtain from the end + * @returns A single value if no amount is provided or an array of values, starting from the start if + * amount is negative + */ + last(): V | undefined; + last(amount: number): V[]; + /** + * Obtains the last key(s) in this collection. + * + * @param amount - Amount of keys to obtain from the end + * @returns A single key if no amount is provided or an array of keys, starting from the start if + * amount is negative + */ + lastKey(): K | undefined; + lastKey(amount: number): K[]; + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the item at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the element to obtain + */ + at(index: number): V | undefined; + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the key at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the key to obtain + */ + keyAt(index: number): K | undefined; + /** + * Obtains unique random value(s) from this collection. + * + * @param amount - Amount of values to obtain randomly + * @returns A single value if no amount is provided or an array of values + */ + random(): V | undefined; + random(amount: number): V[]; + /** + * Obtains unique random key(s) from this collection. + * + * @param amount - Amount of keys to obtain randomly + * @returns A single key if no amount is provided or an array + */ + randomKey(): K | undefined; + randomKey(amount: number): K[]; + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()} + * but returns a Collection instead of an Array. + */ + reverse(): this; + /** + * Searches for a single item where the given function returns a truthy value. This behaves like + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.find()}. + * All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you + * should use the `get` method. See + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details. + * + * @param fn - The function to test with (should return boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.find(user => user.username === 'Bob'); + * ``` + */ + find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined; + find(fn: (value: V, key: K, collection: this) => unknown): V | undefined; + find<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): V2 | undefined; + find<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): V | undefined; + /** + * Searches for the key of a single item where the given function returns a truthy value. This behaves like + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()}, + * but returns the key rather than the positional index. + * + * @param fn - The function to test with (should return boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.findKey(user => user.username === 'Bob'); + * ``` + */ + findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined; + findKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined; + findKey<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): K2 | undefined; + findKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined; + /** + * Removes items that satisfy the provided filter function. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @returns The number of removed entries + */ + sweep(fn: (value: V, key: K, collection: this) => unknown): number; + sweep<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): number; + /** + * Identical to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()}, + * but returns a Collection instead of an Array. + * + * @param fn - The function to test with (should return boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.filter(user => user.username === 'Bob'); + * ``` + */ + filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>; + filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>; + filter(fn: (value: V, key: K, collection: this) => unknown): Collection<K, V>; + filter<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): Collection<K2, V>; + filter<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): Collection<K, V2>; + filter<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): Collection<K, V>; + /** + * Partitions the collection into two collections where the first collection + * contains the items that passed and the second contains the items that failed. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * const [big, small] = collection.partition(guild => guild.memberCount > 250); + * ``` + */ + partition<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): [Collection<K2, V>, Collection<Exclude<K, K2>, V>]; + partition<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): [Collection<K, V2>, Collection<K, Exclude<V, V2>>]; + partition(fn: (value: V, key: K, collection: this) => unknown): [Collection<K, V>, Collection<K, V>]; + partition<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): [Collection<K2, V>, Collection<Exclude<K, K2>, V>]; + partition<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): [Collection<K, V2>, Collection<K, Exclude<V, V2>>]; + partition<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): [Collection<K, V>, Collection<K, V>]; + /** + * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}. + * + * @param fn - Function that produces a new Collection + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.flatMap(guild => guild.members.cache); + * ``` + */ + flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>; + flatMap<T, This>(fn: (this: This, value: V, key: K, collection: this) => Collection<K, T>, thisArg: This): Collection<K, T>; + /** + * Maps each item to another value into an array. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}. + * + * @param fn - Function that produces an element of the new array, taking three arguments + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.map(user => user.tag); + * ``` + */ + map<T>(fn: (value: V, key: K, collection: this) => T): T[]; + map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[]; + /** + * Maps each item to another value into a collection. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}. + * + * @param fn - Function that produces an element of the new collection, taking three arguments + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.mapValues(user => user.tag); + * ``` + */ + mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>; + mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>; + /** + * Checks if there exists an item that passes a test. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.some(user => user.discriminator === '0000'); + * ``` + */ + some(fn: (value: V, key: K, collection: this) => unknown): boolean; + some<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): boolean; + /** + * Checks if all items passes a test. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}. + * + * @param fn - Function used to test (should return a boolean) + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection.every(user => !user.bot); + * ``` + */ + every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>; + every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>; + every(fn: (value: V, key: K, collection: this) => unknown): boolean; + every<This, K2 extends K>(fn: (this: This, value: V, key: K, collection: this) => key is K2, thisArg: This): this is Collection<K2, V>; + every<This, V2 extends V>(fn: (this: This, value: V, key: K, collection: this) => value is V2, thisArg: This): this is Collection<K, V2>; + every<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): boolean; + /** + * Applies a function to produce a single value. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}. + * + * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`, + * and `collection` + * @param initialValue - Starting value for the accumulator + * @example + * ```ts + * collection.reduce((acc, guild) => acc + guild.memberCount, 0); + * ``` + */ + reduce<T = V>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T; + /** + * Identical to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()}, + * but returns the collection instead of undefined. + * + * @param fn - Function to execute for each element + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection + * .each(user => console.log(user.username)) + * .filter(user => user.bot) + * .each(user => console.log(user.username)); + * ``` + */ + each(fn: (value: V, key: K, collection: this) => void): this; + each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this; + /** + * Runs a function on the collection and returns the collection. + * + * @param fn - Function to execute + * @param thisArg - Value to use as `this` when executing function + * @example + * ```ts + * collection + * .tap(coll => console.log(coll.size)) + * .filter(user => user.bot) + * .tap(coll => console.log(coll.size)) + * ``` + */ + tap(fn: (collection: this) => void): this; + tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this; + /** + * Creates an identical shallow copy of this collection. + * + * @example + * ```ts + * const newColl = someColl.clone(); + * ``` + */ + clone(): Collection<K, V>; + /** + * Combines this collection with others into a new collection. None of the source collections are modified. + * + * @param collections - Collections to merge + * @example + * ```ts + * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl); + * ``` + */ + concat(...collections: ReadonlyCollection<K, V>[]): Collection<K, V>; + /** + * Checks if this collection shares identical items with another. + * This is different to checking for equality using equal-signs, because + * the collections may be different objects, but contain the same data. + * + * @param collection - Collection to compare with + * @returns Whether the collections have identical contents + */ + equals(collection: ReadonlyCollection<K, V>): boolean; + /** + * The sort method sorts the items of a collection in place and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. + * @example + * ```ts + * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sort(compareFunction?: Comparator<K, V>): this; + /** + * The intersect method returns a new structure containing items where the keys and values are present in both original structures. + * + * @param other - The other Collection to filter against + */ + intersect<T>(other: ReadonlyCollection<K, T>): Collection<K, T>; + /** + * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other. + * + * @param other - The other Collection to filter against + */ + subtract<T>(other: ReadonlyCollection<K, T>): Collection<K, V>; + /** + * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other. + * + * @param other - The other Collection to filter against + */ + difference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V>; + /** + * Merges two Collections together into a new Collection. + * + * @param other - The other Collection to merge with + * @param whenInSelf - Function getting the result if the entry only exists in this Collection + * @param whenInOther - Function getting the result if the entry only exists in the other Collection + * @param whenInBoth - Function getting the result if the entry exists in both Collections + * @example + * ```ts + * // Sums up the entries in two collections. + * coll.merge( + * other, + * x => ({ keep: true, value: x }), + * y => ({ keep: true, value: y }), + * (x, y) => ({ keep: true, value: x + y }), + * ); + * ``` + * @example + * ```ts + * // Intersects two collections in a left-biased manner. + * coll.merge( + * other, + * x => ({ keep: false }), + * y => ({ keep: false }), + * (x, _) => ({ keep: true, value: x }), + * ); + * ``` + */ + merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: (value: V, key: K) => Keep<R>, whenInOther: (valueOther: T, key: K) => Keep<R>, whenInBoth: (value: V, valueOther: T, key: K) => Keep<R>): Collection<K, R>; + /** + * The sorted method sorts the items of a collection and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, + * according to the string conversion of each element. + * @example + * ```ts + * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sorted(compareFunction?: Comparator<K, V>): Collection<K, V>; + toJSON(): V[]; + private static defaultSort; + /** + * Creates a Collection from a list of entries. + * + * @param entries - The list of entries + * @param combine - Function to combine an existing entry with a new one + * @example + * ```ts + * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); + * // returns Collection { "a" => 3, "b" => 2 } + * ``` + */ + static combineEntries<K, V>(entries: Iterable<[K, V]>, combine: (firstValue: V, secondValue: V, key: K) => V): Collection<K, V>; +} +/** + * @internal + */ +type Keep<V> = { + keep: false; +} | { + keep: true; + value: V; +}; +/** + * @internal + */ +type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number; + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection/#readme | @discordjs/collection} version + * that you are currently using. + */ +declare const version: string; + +export { Collection, CollectionConstructor, Comparator, Keep, ReadonlyCollection, version }; diff --git a/node_modules/@discordjs/collection/dist/index.js b/node_modules/@discordjs/collection/dist/index.js new file mode 100644 index 0000000..d9379ea --- /dev/null +++ b/node_modules/@discordjs/collection/dist/index.js @@ -0,0 +1,543 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + Collection: () => Collection, + version: () => version +}); +module.exports = __toCommonJS(src_exports); + +// src/collection.ts +var Collection = class _Collection extends Map { + static { + __name(this, "Collection"); + } + /** + * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator. + * + * @param key - The key to get if it exists, or set otherwise + * @param defaultValueGenerator - A function that generates the default value + * @example + * ```ts + * collection.ensure(guildId, () => defaultGuildConfig); + * ``` + */ + ensure(key, defaultValueGenerator) { + if (this.has(key)) + return this.get(key); + if (typeof defaultValueGenerator !== "function") + throw new TypeError(`${defaultValueGenerator} is not a function`); + const defaultValue = defaultValueGenerator(key, this); + this.set(key, defaultValue); + return defaultValue; + } + /** + * Checks if all of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if all of the elements exist, `false` if at least one does not exist. + */ + hasAll(...keys) { + return keys.every((key) => super.has(key)); + } + /** + * Checks if any of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if any of the elements exist, `false` if none exist. + */ + hasAny(...keys) { + return keys.some((key) => super.has(key)); + } + first(amount) { + if (amount === void 0) + return this.values().next().value; + if (amount < 0) + return this.last(amount * -1); + amount = Math.min(this.size, amount); + const iter = this.values(); + return Array.from({ length: amount }, () => iter.next().value); + } + firstKey(amount) { + if (amount === void 0) + return this.keys().next().value; + if (amount < 0) + return this.lastKey(amount * -1); + amount = Math.min(this.size, amount); + const iter = this.keys(); + return Array.from({ length: amount }, () => iter.next().value); + } + last(amount) { + const arr = [...this.values()]; + if (amount === void 0) + return arr[arr.length - 1]; + if (amount < 0) + return this.first(amount * -1); + if (!amount) + return []; + return arr.slice(-amount); + } + lastKey(amount) { + const arr = [...this.keys()]; + if (amount === void 0) + return arr[arr.length - 1]; + if (amount < 0) + return this.firstKey(amount * -1); + if (!amount) + return []; + return arr.slice(-amount); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the item at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the element to obtain + */ + at(index) { + index = Math.floor(index); + const arr = [...this.values()]; + return arr.at(index); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the key at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the key to obtain + */ + keyAt(index) { + index = Math.floor(index); + const arr = [...this.keys()]; + return arr.at(index); + } + random(amount) { + const arr = [...this.values()]; + if (amount === void 0) + return arr[Math.floor(Math.random() * arr.length)]; + if (!arr.length || !amount) + return []; + return Array.from( + { length: Math.min(amount, arr.length) }, + () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0] + ); + } + randomKey(amount) { + const arr = [...this.keys()]; + if (amount === void 0) + return arr[Math.floor(Math.random() * arr.length)]; + if (!arr.length || !amount) + return []; + return Array.from( + { length: Math.min(amount, arr.length) }, + () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0] + ); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()} + * but returns a Collection instead of an Array. + */ + reverse() { + const entries = [...this.entries()].reverse(); + this.clear(); + for (const [key, value] of entries) + this.set(key, value); + return this; + } + find(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (fn(val, key, this)) + return val; + } + return void 0; + } + findKey(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (fn(val, key, this)) + return key; + } + return void 0; + } + sweep(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const previousSize = this.size; + for (const [key, val] of this) { + if (fn(val, key, this)) + this.delete(key); + } + return previousSize - this.size; + } + filter(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const results = new this.constructor[Symbol.species](); + for (const [key, val] of this) { + if (fn(val, key, this)) + results.set(key, val); + } + return results; + } + partition(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const results = [ + new this.constructor[Symbol.species](), + new this.constructor[Symbol.species]() + ]; + for (const [key, val] of this) { + if (fn(val, key, this)) { + results[0].set(key, val); + } else { + results[1].set(key, val); + } + } + return results; + } + flatMap(fn, thisArg) { + const collections = this.map(fn, thisArg); + return new this.constructor[Symbol.species]().concat(...collections); + } + map(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const iter = this.entries(); + return Array.from({ length: this.size }, () => { + const [key, value] = iter.next().value; + return fn(value, key, this); + }); + } + mapValues(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const coll = new this.constructor[Symbol.species](); + for (const [key, val] of this) + coll.set(key, fn(val, key, this)); + return coll; + } + some(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (fn(val, key, this)) + return true; + } + return false; + } + every(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (!fn(val, key, this)) + return false; + } + return true; + } + /** + * Applies a function to produce a single value. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}. + * + * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`, + * and `collection` + * @param initialValue - Starting value for the accumulator + * @example + * ```ts + * collection.reduce((acc, guild) => acc + guild.memberCount, 0); + * ``` + */ + reduce(fn, initialValue) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + let accumulator; + const iterator = this.entries(); + if (initialValue === void 0) { + if (this.size === 0) + throw new TypeError("Reduce of empty collection with no initial value"); + accumulator = iterator.next().value[1]; + } else { + accumulator = initialValue; + } + for (const [key, value] of iterator) { + accumulator = fn(accumulator, value, key, this); + } + return accumulator; + } + each(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, value] of this) { + fn(value, key, this); + } + return this; + } + tap(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + fn(this); + return this; + } + /** + * Creates an identical shallow copy of this collection. + * + * @example + * ```ts + * const newColl = someColl.clone(); + * ``` + */ + clone() { + return new this.constructor[Symbol.species](this); + } + /** + * Combines this collection with others into a new collection. None of the source collections are modified. + * + * @param collections - Collections to merge + * @example + * ```ts + * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl); + * ``` + */ + concat(...collections) { + const newColl = this.clone(); + for (const coll of collections) { + for (const [key, val] of coll) + newColl.set(key, val); + } + return newColl; + } + /** + * Checks if this collection shares identical items with another. + * This is different to checking for equality using equal-signs, because + * the collections may be different objects, but contain the same data. + * + * @param collection - Collection to compare with + * @returns Whether the collections have identical contents + */ + equals(collection) { + if (!collection) + return false; + if (this === collection) + return true; + if (this.size !== collection.size) + return false; + for (const [key, value] of this) { + if (!collection.has(key) || value !== collection.get(key)) { + return false; + } + } + return true; + } + /** + * The sort method sorts the items of a collection in place and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. + * @example + * ```ts + * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sort(compareFunction = _Collection.defaultSort) { + const entries = [...this.entries()]; + entries.sort((a, b) => compareFunction(a[1], b[1], a[0], b[0])); + super.clear(); + for (const [key, value] of entries) { + super.set(key, value); + } + return this; + } + /** + * The intersect method returns a new structure containing items where the keys and values are present in both original structures. + * + * @param other - The other Collection to filter against + */ + intersect(other) { + const coll = new this.constructor[Symbol.species](); + for (const [key, value] of other) { + if (this.has(key) && Object.is(value, this.get(key))) { + coll.set(key, value); + } + } + return coll; + } + /** + * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other. + * + * @param other - The other Collection to filter against + */ + subtract(other) { + const coll = new this.constructor[Symbol.species](); + for (const [key, value] of this) { + if (!other.has(key) || !Object.is(value, other.get(key))) { + coll.set(key, value); + } + } + return coll; + } + /** + * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other. + * + * @param other - The other Collection to filter against + */ + difference(other) { + const coll = new this.constructor[Symbol.species](); + for (const [key, value] of other) { + if (!this.has(key)) + coll.set(key, value); + } + for (const [key, value] of this) { + if (!other.has(key)) + coll.set(key, value); + } + return coll; + } + /** + * Merges two Collections together into a new Collection. + * + * @param other - The other Collection to merge with + * @param whenInSelf - Function getting the result if the entry only exists in this Collection + * @param whenInOther - Function getting the result if the entry only exists in the other Collection + * @param whenInBoth - Function getting the result if the entry exists in both Collections + * @example + * ```ts + * // Sums up the entries in two collections. + * coll.merge( + * other, + * x => ({ keep: true, value: x }), + * y => ({ keep: true, value: y }), + * (x, y) => ({ keep: true, value: x + y }), + * ); + * ``` + * @example + * ```ts + * // Intersects two collections in a left-biased manner. + * coll.merge( + * other, + * x => ({ keep: false }), + * y => ({ keep: false }), + * (x, _) => ({ keep: true, value: x }), + * ); + * ``` + */ + merge(other, whenInSelf, whenInOther, whenInBoth) { + const coll = new this.constructor[Symbol.species](); + const keys = /* @__PURE__ */ new Set([...this.keys(), ...other.keys()]); + for (const key of keys) { + const hasInSelf = this.has(key); + const hasInOther = other.has(key); + if (hasInSelf && hasInOther) { + const result = whenInBoth(this.get(key), other.get(key), key); + if (result.keep) + coll.set(key, result.value); + } else if (hasInSelf) { + const result = whenInSelf(this.get(key), key); + if (result.keep) + coll.set(key, result.value); + } else if (hasInOther) { + const result = whenInOther(other.get(key), key); + if (result.keep) + coll.set(key, result.value); + } + } + return coll; + } + /** + * The sorted method sorts the items of a collection and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, + * according to the string conversion of each element. + * @example + * ```ts + * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sorted(compareFunction = _Collection.defaultSort) { + return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk)); + } + toJSON() { + return [...this.values()]; + } + static defaultSort(firstValue, secondValue) { + return Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1; + } + /** + * Creates a Collection from a list of entries. + * + * @param entries - The list of entries + * @param combine - Function to combine an existing entry with a new one + * @example + * ```ts + * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); + * // returns Collection { "a" => 3, "b" => 2 } + * ``` + */ + static combineEntries(entries, combine) { + const coll = new _Collection(); + for (const [key, value] of entries) { + if (coll.has(key)) { + coll.set(key, combine(coll.get(key), value, key)); + } else { + coll.set(key, value); + } + } + return coll; + } +}; + +// src/index.ts +var version = "1.5.3"; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + Collection, + version +}); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/collection/dist/index.js.map b/node_modules/@discordjs/collection/dist/index.js.map new file mode 100644 index 0000000..247240c --- /dev/null +++ b/node_modules/@discordjs/collection/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/collection.ts"],"sourcesContent":["export * from './collection.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection/#readme | @discordjs/collection} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\nexport const version = '1.5.3' as string;\n","/* eslint-disable no-param-reassign */\n/**\n * @internal\n */\nexport interface CollectionConstructor {\n\tnew (): Collection<unknown, unknown>;\n\tnew <K, V>(entries?: readonly (readonly [K, V])[] | null): Collection<K, V>;\n\tnew <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;\n\treadonly prototype: Collection<unknown, unknown>;\n\treadonly [Symbol.species]: CollectionConstructor;\n}\n\n/**\n * Represents an immutable version of a collection\n */\nexport type ReadonlyCollection<K, V> = Omit<\n\tCollection<K, V>,\n\t'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'\n> &\n\tReadonlyMap<K, V>;\n\n/**\n * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself\n *\n * @internal\n */\nexport interface Collection<K, V> extends Map<K, V> {\n\tconstructor: CollectionConstructor;\n}\n\n/**\n * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has\n * an ID, for significantly improved performance and ease-of-use.\n *\n * @typeParam K - The key type this collection holds\n * @typeParam V - The value type this collection holds\n */\nexport class Collection<K, V> extends Map<K, V> {\n\t/**\n\t * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.\n\t *\n\t * @param key - The key to get if it exists, or set otherwise\n\t * @param defaultValueGenerator - A function that generates the default value\n\t * @example\n\t * ```ts\n\t * collection.ensure(guildId, () => defaultGuildConfig);\n\t * ```\n\t */\n\tpublic ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V {\n\t\tif (this.has(key)) return this.get(key)!;\n\t\tif (typeof defaultValueGenerator !== 'function') throw new TypeError(`${defaultValueGenerator} is not a function`);\n\t\tconst defaultValue = defaultValueGenerator(key, this);\n\t\tthis.set(key, defaultValue);\n\t\treturn defaultValue;\n\t}\n\n\t/**\n\t * Checks if all of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t * @returns `true` if all of the elements exist, `false` if at least one does not exist.\n\t */\n\tpublic hasAll(...keys: K[]) {\n\t\treturn keys.every((key) => super.has(key));\n\t}\n\n\t/**\n\t * Checks if any of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t * @returns `true` if any of the elements exist, `false` if none exist.\n\t */\n\tpublic hasAny(...keys: K[]) {\n\t\treturn keys.some((key) => super.has(key));\n\t}\n\n\t/**\n\t * Obtains the first value(s) in this collection.\n\t *\n\t * @param amount - Amount of values to obtain from the beginning\n\t * @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative\n\t */\n\tpublic first(): V | undefined;\n\tpublic first(amount: number): V[];\n\tpublic first(amount?: number): V | V[] | undefined {\n\t\tif (amount === undefined) return this.values().next().value;\n\t\tif (amount < 0) return this.last(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.values();\n\t\treturn Array.from({ length: amount }, (): V => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the first key(s) in this collection.\n\t *\n\t * @param amount - Amount of keys to obtain from the beginning\n\t * @returns A single key if no amount is provided or an array of keys, starting from the end if\n\t * amount is negative\n\t */\n\tpublic firstKey(): K | undefined;\n\tpublic firstKey(amount: number): K[];\n\tpublic firstKey(amount?: number): K | K[] | undefined {\n\t\tif (amount === undefined) return this.keys().next().value;\n\t\tif (amount < 0) return this.lastKey(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.keys();\n\t\treturn Array.from({ length: amount }, (): K => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the last value(s) in this collection.\n\t *\n\t * @param amount - Amount of values to obtain from the end\n\t * @returns A single value if no amount is provided or an array of values, starting from the start if\n\t * amount is negative\n\t */\n\tpublic last(): V | undefined;\n\tpublic last(amount: number): V[];\n\tpublic last(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (amount === undefined) return arr[arr.length - 1];\n\t\tif (amount < 0) return this.first(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains the last key(s) in this collection.\n\t *\n\t * @param amount - Amount of keys to obtain from the end\n\t * @returns A single key if no amount is provided or an array of keys, starting from the start if\n\t * amount is negative\n\t */\n\tpublic lastKey(): K | undefined;\n\tpublic lastKey(amount: number): K[];\n\tpublic lastKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (amount === undefined) return arr[arr.length - 1];\n\t\tif (amount < 0) return this.firstKey(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.\n\t * Returns the item at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index - The index of the element to obtain\n\t */\n\tpublic at(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.values()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.\n\t * Returns the key at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index - The index of the key to obtain\n\t */\n\tpublic keyAt(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.keys()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Obtains unique random value(s) from this collection.\n\t *\n\t * @param amount - Amount of values to obtain randomly\n\t * @returns A single value if no amount is provided or an array of values\n\t */\n\tpublic random(): V | undefined;\n\tpublic random(amount: number): V[];\n\tpublic random(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (amount === undefined) return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]!,\n\t\t);\n\t}\n\n\t/**\n\t * Obtains unique random key(s) from this collection.\n\t *\n\t * @param amount - Amount of keys to obtain randomly\n\t * @returns A single key if no amount is provided or an array\n\t */\n\tpublic randomKey(): K | undefined;\n\tpublic randomKey(amount: number): K[];\n\tpublic randomKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (amount === undefined) return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]!,\n\t\t);\n\t}\n\n\t/**\n\t * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}\n\t * but returns a Collection instead of an Array.\n\t */\n\tpublic reverse() {\n\t\tconst entries = [...this.entries()].reverse();\n\t\tthis.clear();\n\t\tfor (const [key, value] of entries) this.set(key, value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches for a single item where the given function returns a truthy value. This behaves like\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.find()}.\n\t * All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you\n\t * should use the `get` method. See\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details.\n\t *\n\t * @param fn - The function to test with (should return boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.find(user => user.username === 'Bob');\n\t * ```\n\t */\n\tpublic find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => unknown): V | undefined;\n\tpublic find<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): V2 | undefined;\n\tpublic find<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): V | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): V | undefined {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return val;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Searches for the key of a single item where the given function returns a truthy value. This behaves like\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},\n\t * but returns the key rather than the positional index.\n\t *\n\t * @param fn - The function to test with (should return boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.findKey(user => user.username === 'Bob');\n\t * ```\n\t */\n\tpublic findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined;\n\tpublic findKey<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): K2 | undefined;\n\tpublic findKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): K | undefined {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return key;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Removes items that satisfy the provided filter function.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @returns The number of removed entries\n\t */\n\tpublic sweep(fn: (value: V, key: K, collection: this) => unknown): number;\n\tpublic sweep<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): number;\n\tpublic sweep(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): number {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst previousSize = this.size;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) this.delete(key);\n\t\t}\n\n\t\treturn previousSize - this.size;\n\t}\n\n\t/**\n\t * Identical to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},\n\t * but returns a Collection instead of an Array.\n\t *\n\t * @param fn - The function to test with (should return boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.filter(user => user.username === 'Bob');\n\t * ```\n\t */\n\tpublic filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;\n\tpublic filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => unknown): Collection<K, V>;\n\tpublic filter<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): Collection<K2, V>;\n\tpublic filter<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): Collection<K, V2>;\n\tpublic filter<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): Collection<K, V>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): Collection<K, V> {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst results = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) results.set(key, val);\n\t\t}\n\n\t\treturn results;\n\t}\n\n\t/**\n\t * Partitions the collection into two collections where the first collection\n\t * contains the items that passed and the second contains the items that failed.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * const [big, small] = collection.partition(guild => guild.memberCount > 250);\n\t * ```\n\t */\n\tpublic partition<K2 extends K>(\n\t\tfn: (value: V, key: K, collection: this) => key is K2,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<V2 extends V>(\n\t\tfn: (value: V, key: K, collection: this) => value is V2,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition(fn: (value: V, key: K, collection: this) => unknown): [Collection<K, V>, Collection<K, V>];\n\tpublic partition<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition<This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => unknown,\n\t\tthisArg: This,\n\t): [Collection<K, V>, Collection<K, V>];\n\tpublic partition(\n\t\tfn: (value: V, key: K, collection: this) => unknown,\n\t\tthisArg?: unknown,\n\t): [Collection<K, V>, Collection<K, V>] {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst results: [Collection<K, V>, Collection<K, V>] = [\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t];\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) {\n\t\t\t\tresults[0].set(key, val);\n\t\t\t} else {\n\t\t\t\tresults[1].set(key, val);\n\t\t\t}\n\t\t}\n\n\t\treturn results;\n\t}\n\n\t/**\n\t * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.\n\t *\n\t * @param fn - Function that produces a new Collection\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.flatMap(guild => guild.members.cache);\n\t * ```\n\t */\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;\n\tpublic flatMap<T, This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => Collection<K, T>,\n\t\tthisArg: This,\n\t): Collection<K, T>;\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {\n\t\t// eslint-disable-next-line unicorn/no-array-method-this-argument\n\t\tconst collections = this.map(fn, thisArg);\n\t\treturn new this.constructor[Symbol.species]<K, T>().concat(...collections);\n\t}\n\n\t/**\n\t * Maps each item to another value into an array. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.\n\t *\n\t * @param fn - Function that produces an element of the new array, taking three arguments\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.map(user => user.tag);\n\t * ```\n\t */\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T): T[];\n\tpublic map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): T[] {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst iter = this.entries();\n\t\treturn Array.from({ length: this.size }, (): T => {\n\t\t\tconst [key, value] = iter.next().value;\n\t\t\treturn fn(value, key, this);\n\t\t});\n\t}\n\n\t/**\n\t * Maps each item to another value into a collection. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.\n\t *\n\t * @param fn - Function that produces an element of the new collection, taking three arguments\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.mapValues(user => user.tag);\n\t * ```\n\t */\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;\n\tpublic mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection<K, T> {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, val] of this) coll.set(key, fn(val, key, this));\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Checks if there exists an item that passes a test. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.some(user => user.discriminator === '0000');\n\t * ```\n\t */\n\tpublic some(fn: (value: V, key: K, collection: this) => unknown): boolean;\n\tpublic some<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): boolean;\n\tpublic some(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): boolean {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Checks if all items passes a test. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.every(user => !user.bot);\n\t * ```\n\t */\n\tpublic every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;\n\tpublic every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;\n\tpublic every(fn: (value: V, key: K, collection: this) => unknown): boolean;\n\tpublic every<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): this is Collection<K2, V>;\n\tpublic every<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): this is Collection<K, V2>;\n\tpublic every<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): boolean;\n\tpublic every(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): boolean {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (!fn(val, key, this)) return false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Applies a function to produce a single value. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.\n\t *\n\t * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,\n\t * and `collection`\n\t * @param initialValue - Starting value for the accumulator\n\t * @example\n\t * ```ts\n\t * collection.reduce((acc, guild) => acc + guild.memberCount, 0);\n\t * ```\n\t */\n\tpublic reduce<T = V>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tlet accumulator!: T;\n\n\t\tconst iterator = this.entries();\n\t\tif (initialValue === undefined) {\n\t\t\tif (this.size === 0) throw new TypeError('Reduce of empty collection with no initial value');\n\t\t\taccumulator = iterator.next().value[1];\n\t\t} else {\n\t\t\taccumulator = initialValue;\n\t\t}\n\n\t\tfor (const [key, value] of iterator) {\n\t\t\taccumulator = fn(accumulator, value, key, this);\n\t\t}\n\n\t\treturn accumulator;\n\t}\n\n\t/**\n\t * Identical to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},\n\t * but returns the collection instead of undefined.\n\t *\n\t * @param fn - Function to execute for each element\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection\n\t * .each(user => console.log(user.username))\n\t * .filter(user => user.bot)\n\t * .each(user => console.log(user.username));\n\t * ```\n\t */\n\tpublic each(fn: (value: V, key: K, collection: this) => void): this;\n\tpublic each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;\n\tpublic each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\n\t\tfor (const [key, value] of this) {\n\t\t\tfn(value, key, this);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Runs a function on the collection and returns the collection.\n\t *\n\t * @param fn - Function to execute\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection\n\t * .tap(coll => console.log(coll.size))\n\t * .filter(user => user.bot)\n\t * .tap(coll => console.log(coll.size))\n\t * ```\n\t */\n\tpublic tap(fn: (collection: this) => void): this;\n\tpublic tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;\n\tpublic tap(fn: (collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfn(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates an identical shallow copy of this collection.\n\t *\n\t * @example\n\t * ```ts\n\t * const newColl = someColl.clone();\n\t * ```\n\t */\n\tpublic clone(): Collection<K, V> {\n\t\treturn new this.constructor[Symbol.species](this);\n\t}\n\n\t/**\n\t * Combines this collection with others into a new collection. None of the source collections are modified.\n\t *\n\t * @param collections - Collections to merge\n\t * @example\n\t * ```ts\n\t * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);\n\t * ```\n\t */\n\tpublic concat(...collections: ReadonlyCollection<K, V>[]) {\n\t\tconst newColl = this.clone();\n\t\tfor (const coll of collections) {\n\t\t\tfor (const [key, val] of coll) newColl.set(key, val);\n\t\t}\n\n\t\treturn newColl;\n\t}\n\n\t/**\n\t * Checks if this collection shares identical items with another.\n\t * This is different to checking for equality using equal-signs, because\n\t * the collections may be different objects, but contain the same data.\n\t *\n\t * @param collection - Collection to compare with\n\t * @returns Whether the collections have identical contents\n\t */\n\tpublic equals(collection: ReadonlyCollection<K, V>) {\n\t\tif (!collection) return false; // runtime check\n\t\tif (this === collection) return true;\n\t\tif (this.size !== collection.size) return false;\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!collection.has(key) || value !== collection.get(key)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * The sort method sorts the items of a collection in place and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction - Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.\n\t * @example\n\t * ```ts\n\t * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t * ```\n\t */\n\tpublic sort(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\tconst entries = [...this.entries()];\n\t\tentries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0]));\n\n\t\t// Perform clean-up\n\t\tsuper.clear();\n\n\t\t// Set the new entries\n\t\tfor (const [key, value] of entries) {\n\t\t\tsuper.set(key, value);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * The intersect method returns a new structure containing items where the keys and values are present in both original structures.\n\t *\n\t * @param other - The other Collection to filter against\n\t */\n\tpublic intersect<T>(other: ReadonlyCollection<K, T>): Collection<K, T> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, value] of other) {\n\t\t\tif (this.has(key) && Object.is(value, this.get(key))) {\n\t\t\t\tcoll.set(key, value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other.\n\t *\n\t * @param other - The other Collection to filter against\n\t */\n\tpublic subtract<T>(other: ReadonlyCollection<K, T>): Collection<K, V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!other.has(key) || !Object.is(value, other.get(key))) {\n\t\t\t\tcoll.set(key, value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.\n\t *\n\t * @param other - The other Collection to filter against\n\t */\n\tpublic difference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, T | V>();\n\t\tfor (const [key, value] of other) {\n\t\t\tif (!this.has(key)) coll.set(key, value);\n\t\t}\n\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!other.has(key)) coll.set(key, value);\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Merges two Collections together into a new Collection.\n\t *\n\t * @param other - The other Collection to merge with\n\t * @param whenInSelf - Function getting the result if the entry only exists in this Collection\n\t * @param whenInOther - Function getting the result if the entry only exists in the other Collection\n\t * @param whenInBoth - Function getting the result if the entry exists in both Collections\n\t * @example\n\t * ```ts\n\t * // Sums up the entries in two collections.\n\t * coll.merge(\n\t * other,\n\t * x => ({ keep: true, value: x }),\n\t * y => ({ keep: true, value: y }),\n\t * (x, y) => ({ keep: true, value: x + y }),\n\t * );\n\t * ```\n\t * @example\n\t * ```ts\n\t * // Intersects two collections in a left-biased manner.\n\t * coll.merge(\n\t * other,\n\t * x => ({ keep: false }),\n\t * y => ({ keep: false }),\n\t * (x, _) => ({ keep: true, value: x }),\n\t * );\n\t * ```\n\t */\n\tpublic merge<T, R>(\n\t\tother: ReadonlyCollection<K, T>,\n\t\twhenInSelf: (value: V, key: K) => Keep<R>,\n\t\twhenInOther: (valueOther: T, key: K) => Keep<R>,\n\t\twhenInBoth: (value: V, valueOther: T, key: K) => Keep<R>,\n\t): Collection<K, R> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, R>();\n\t\tconst keys = new Set([...this.keys(), ...other.keys()]);\n\n\t\tfor (const key of keys) {\n\t\t\tconst hasInSelf = this.has(key);\n\t\t\tconst hasInOther = other.has(key);\n\n\t\t\tif (hasInSelf && hasInOther) {\n\t\t\t\tconst result = whenInBoth(this.get(key)!, other.get(key)!, key);\n\t\t\t\tif (result.keep) coll.set(key, result.value);\n\t\t\t} else if (hasInSelf) {\n\t\t\t\tconst result = whenInSelf(this.get(key)!, key);\n\t\t\t\tif (result.keep) coll.set(key, result.value);\n\t\t\t} else if (hasInOther) {\n\t\t\t\tconst result = whenInOther(other.get(key)!, key);\n\t\t\t\tif (result.keep) coll.set(key, result.value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The sorted method sorts the items of a collection and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction - Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t * @example\n\t * ```ts\n\t * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t * ```\n\t */\n\tpublic sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\treturn new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));\n\t}\n\n\tpublic toJSON() {\n\t\t// toJSON is called recursively by JSON.stringify.\n\t\treturn [...this.values()];\n\t}\n\n\tprivate static defaultSort<V>(firstValue: V, secondValue: V): number {\n\t\treturn Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;\n\t}\n\n\t/**\n\t * Creates a Collection from a list of entries.\n\t *\n\t * @param entries - The list of entries\n\t * @param combine - Function to combine an existing entry with a new one\n\t * @example\n\t * ```ts\n\t * Collection.combineEntries([[\"a\", 1], [\"b\", 2], [\"a\", 2]], (x, y) => x + y);\n\t * // returns Collection { \"a\" => 3, \"b\" => 2 }\n\t * ```\n\t */\n\tpublic static combineEntries<K, V>(\n\t\tentries: Iterable<[K, V]>,\n\t\tcombine: (firstValue: V, secondValue: V, key: K) => V,\n\t): Collection<K, V> {\n\t\tconst coll = new Collection<K, V>();\n\t\tfor (const [key, value] of entries) {\n\t\t\tif (coll.has(key)) {\n\t\t\t\tcoll.set(key, combine(coll.get(key)!, value, key));\n\t\t\t} else {\n\t\t\t\tcoll.set(key, value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n}\n\n/**\n * @internal\n */\nexport type Keep<V> = { keep: false } | { keep: true; value: V };\n\n/**\n * @internal\n */\nexport type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqCO,IAAM,aAAN,MAAM,oBAAyB,IAAU;AAAA,EArChD,OAqCgD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWxC,OAAO,KAAQ,uBAA2D;AAChF,QAAI,KAAK,IAAI,GAAG;AAAG,aAAO,KAAK,IAAI,GAAG;AACtC,QAAI,OAAO,0BAA0B;AAAY,YAAM,IAAI,UAAU,GAAG,qBAAqB,oBAAoB;AACjH,UAAM,eAAe,sBAAsB,KAAK,IAAI;AACpD,SAAK,IAAI,KAAK,YAAY;AAC1B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,UAAU,MAAW;AAC3B,WAAO,KAAK,MAAM,CAAC,QAAQ,MAAM,IAAI,GAAG,CAAC;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,UAAU,MAAW;AAC3B,WAAO,KAAK,KAAK,CAAC,QAAQ,MAAM,IAAI,GAAG,CAAC;AAAA,EACzC;AAAA,EAUO,MAAM,QAAsC;AAClD,QAAI,WAAW;AAAW,aAAO,KAAK,OAAO,EAAE,KAAK,EAAE;AACtD,QAAI,SAAS;AAAG,aAAO,KAAK,KAAK,SAAS,EAAE;AAC5C,aAAS,KAAK,IAAI,KAAK,MAAM,MAAM;AACnC,UAAM,OAAO,KAAK,OAAO;AACzB,WAAO,MAAM,KAAK,EAAE,QAAQ,OAAO,GAAG,MAAS,KAAK,KAAK,EAAE,KAAK;AAAA,EACjE;AAAA,EAWO,SAAS,QAAsC;AACrD,QAAI,WAAW;AAAW,a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WAAW,IAAI;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,OAAc,eACb,SACA,SACmB;AACnB,UAAM,OAAO,IAAI,YAAiB;AAClC,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AACnC,UAAI,KAAK,IAAI,GAAG,GAAG;AAClB,aAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,GAAG,GAAI,OAAO,GAAG,CAAC;AAAA,MAClD,OAAO;AACN,aAAK,IAAI,KAAK,KAAK;AAAA,MACpB;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;;;AD9yBO,IAAM,UAAU;","names":[]}
\ No newline at end of file diff --git a/node_modules/@discordjs/collection/dist/index.mjs b/node_modules/@discordjs/collection/dist/index.mjs new file mode 100644 index 0000000..c31c9ee --- /dev/null +++ b/node_modules/@discordjs/collection/dist/index.mjs @@ -0,0 +1,517 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); + +// src/collection.ts +var Collection = class _Collection extends Map { + static { + __name(this, "Collection"); + } + /** + * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator. + * + * @param key - The key to get if it exists, or set otherwise + * @param defaultValueGenerator - A function that generates the default value + * @example + * ```ts + * collection.ensure(guildId, () => defaultGuildConfig); + * ``` + */ + ensure(key, defaultValueGenerator) { + if (this.has(key)) + return this.get(key); + if (typeof defaultValueGenerator !== "function") + throw new TypeError(`${defaultValueGenerator} is not a function`); + const defaultValue = defaultValueGenerator(key, this); + this.set(key, defaultValue); + return defaultValue; + } + /** + * Checks if all of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if all of the elements exist, `false` if at least one does not exist. + */ + hasAll(...keys) { + return keys.every((key) => super.has(key)); + } + /** + * Checks if any of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if any of the elements exist, `false` if none exist. + */ + hasAny(...keys) { + return keys.some((key) => super.has(key)); + } + first(amount) { + if (amount === void 0) + return this.values().next().value; + if (amount < 0) + return this.last(amount * -1); + amount = Math.min(this.size, amount); + const iter = this.values(); + return Array.from({ length: amount }, () => iter.next().value); + } + firstKey(amount) { + if (amount === void 0) + return this.keys().next().value; + if (amount < 0) + return this.lastKey(amount * -1); + amount = Math.min(this.size, amount); + const iter = this.keys(); + return Array.from({ length: amount }, () => iter.next().value); + } + last(amount) { + const arr = [...this.values()]; + if (amount === void 0) + return arr[arr.length - 1]; + if (amount < 0) + return this.first(amount * -1); + if (!amount) + return []; + return arr.slice(-amount); + } + lastKey(amount) { + const arr = [...this.keys()]; + if (amount === void 0) + return arr[arr.length - 1]; + if (amount < 0) + return this.firstKey(amount * -1); + if (!amount) + return []; + return arr.slice(-amount); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the item at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the element to obtain + */ + at(index) { + index = Math.floor(index); + const arr = [...this.values()]; + return arr.at(index); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the key at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the key to obtain + */ + keyAt(index) { + index = Math.floor(index); + const arr = [...this.keys()]; + return arr.at(index); + } + random(amount) { + const arr = [...this.values()]; + if (amount === void 0) + return arr[Math.floor(Math.random() * arr.length)]; + if (!arr.length || !amount) + return []; + return Array.from( + { length: Math.min(amount, arr.length) }, + () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0] + ); + } + randomKey(amount) { + const arr = [...this.keys()]; + if (amount === void 0) + return arr[Math.floor(Math.random() * arr.length)]; + if (!arr.length || !amount) + return []; + return Array.from( + { length: Math.min(amount, arr.length) }, + () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0] + ); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()} + * but returns a Collection instead of an Array. + */ + reverse() { + const entries = [...this.entries()].reverse(); + this.clear(); + for (const [key, value] of entries) + this.set(key, value); + return this; + } + find(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (fn(val, key, this)) + return val; + } + return void 0; + } + findKey(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (fn(val, key, this)) + return key; + } + return void 0; + } + sweep(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const previousSize = this.size; + for (const [key, val] of this) { + if (fn(val, key, this)) + this.delete(key); + } + return previousSize - this.size; + } + filter(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const results = new this.constructor[Symbol.species](); + for (const [key, val] of this) { + if (fn(val, key, this)) + results.set(key, val); + } + return results; + } + partition(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const results = [ + new this.constructor[Symbol.species](), + new this.constructor[Symbol.species]() + ]; + for (const [key, val] of this) { + if (fn(val, key, this)) { + results[0].set(key, val); + } else { + results[1].set(key, val); + } + } + return results; + } + flatMap(fn, thisArg) { + const collections = this.map(fn, thisArg); + return new this.constructor[Symbol.species]().concat(...collections); + } + map(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const iter = this.entries(); + return Array.from({ length: this.size }, () => { + const [key, value] = iter.next().value; + return fn(value, key, this); + }); + } + mapValues(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + const coll = new this.constructor[Symbol.species](); + for (const [key, val] of this) + coll.set(key, fn(val, key, this)); + return coll; + } + some(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (fn(val, key, this)) + return true; + } + return false; + } + every(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (!fn(val, key, this)) + return false; + } + return true; + } + /** + * Applies a function to produce a single value. Identical in behavior to + * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}. + * + * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`, + * and `collection` + * @param initialValue - Starting value for the accumulator + * @example + * ```ts + * collection.reduce((acc, guild) => acc + guild.memberCount, 0); + * ``` + */ + reduce(fn, initialValue) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + let accumulator; + const iterator = this.entries(); + if (initialValue === void 0) { + if (this.size === 0) + throw new TypeError("Reduce of empty collection with no initial value"); + accumulator = iterator.next().value[1]; + } else { + accumulator = initialValue; + } + for (const [key, value] of iterator) { + accumulator = fn(accumulator, value, key, this); + } + return accumulator; + } + each(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, value] of this) { + fn(value, key, this); + } + return this; + } + tap(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + fn(this); + return this; + } + /** + * Creates an identical shallow copy of this collection. + * + * @example + * ```ts + * const newColl = someColl.clone(); + * ``` + */ + clone() { + return new this.constructor[Symbol.species](this); + } + /** + * Combines this collection with others into a new collection. None of the source collections are modified. + * + * @param collections - Collections to merge + * @example + * ```ts + * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl); + * ``` + */ + concat(...collections) { + const newColl = this.clone(); + for (const coll of collections) { + for (const [key, val] of coll) + newColl.set(key, val); + } + return newColl; + } + /** + * Checks if this collection shares identical items with another. + * This is different to checking for equality using equal-signs, because + * the collections may be different objects, but contain the same data. + * + * @param collection - Collection to compare with + * @returns Whether the collections have identical contents + */ + equals(collection) { + if (!collection) + return false; + if (this === collection) + return true; + if (this.size !== collection.size) + return false; + for (const [key, value] of this) { + if (!collection.has(key) || value !== collection.get(key)) { + return false; + } + } + return true; + } + /** + * The sort method sorts the items of a collection in place and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. + * @example + * ```ts + * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sort(compareFunction = _Collection.defaultSort) { + const entries = [...this.entries()]; + entries.sort((a, b) => compareFunction(a[1], b[1], a[0], b[0])); + super.clear(); + for (const [key, value] of entries) { + super.set(key, value); + } + return this; + } + /** + * The intersect method returns a new structure containing items where the keys and values are present in both original structures. + * + * @param other - The other Collection to filter against + */ + intersect(other) { + const coll = new this.constructor[Symbol.species](); + for (const [key, value] of other) { + if (this.has(key) && Object.is(value, this.get(key))) { + coll.set(key, value); + } + } + return coll; + } + /** + * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other. + * + * @param other - The other Collection to filter against + */ + subtract(other) { + const coll = new this.constructor[Symbol.species](); + for (const [key, value] of this) { + if (!other.has(key) || !Object.is(value, other.get(key))) { + coll.set(key, value); + } + } + return coll; + } + /** + * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other. + * + * @param other - The other Collection to filter against + */ + difference(other) { + const coll = new this.constructor[Symbol.species](); + for (const [key, value] of other) { + if (!this.has(key)) + coll.set(key, value); + } + for (const [key, value] of this) { + if (!other.has(key)) + coll.set(key, value); + } + return coll; + } + /** + * Merges two Collections together into a new Collection. + * + * @param other - The other Collection to merge with + * @param whenInSelf - Function getting the result if the entry only exists in this Collection + * @param whenInOther - Function getting the result if the entry only exists in the other Collection + * @param whenInBoth - Function getting the result if the entry exists in both Collections + * @example + * ```ts + * // Sums up the entries in two collections. + * coll.merge( + * other, + * x => ({ keep: true, value: x }), + * y => ({ keep: true, value: y }), + * (x, y) => ({ keep: true, value: x + y }), + * ); + * ``` + * @example + * ```ts + * // Intersects two collections in a left-biased manner. + * coll.merge( + * other, + * x => ({ keep: false }), + * y => ({ keep: false }), + * (x, _) => ({ keep: true, value: x }), + * ); + * ``` + */ + merge(other, whenInSelf, whenInOther, whenInBoth) { + const coll = new this.constructor[Symbol.species](); + const keys = /* @__PURE__ */ new Set([...this.keys(), ...other.keys()]); + for (const key of keys) { + const hasInSelf = this.has(key); + const hasInOther = other.has(key); + if (hasInSelf && hasInOther) { + const result = whenInBoth(this.get(key), other.get(key), key); + if (result.keep) + coll.set(key, result.value); + } else if (hasInSelf) { + const result = whenInSelf(this.get(key), key); + if (result.keep) + coll.set(key, result.value); + } else if (hasInOther) { + const result = whenInOther(other.get(key), key); + if (result.keep) + coll.set(key, result.value); + } + } + return coll; + } + /** + * The sorted method sorts the items of a collection and returns it. + * The sort is not necessarily stable in Node 10 or older. + * The default sort order is according to string Unicode code points. + * + * @param compareFunction - Specifies a function that defines the sort order. + * If omitted, the collection is sorted according to each character's Unicode code point value, + * according to the string conversion of each element. + * @example + * ```ts + * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` + */ + sorted(compareFunction = _Collection.defaultSort) { + return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk)); + } + toJSON() { + return [...this.values()]; + } + static defaultSort(firstValue, secondValue) { + return Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1; + } + /** + * Creates a Collection from a list of entries. + * + * @param entries - The list of entries + * @param combine - Function to combine an existing entry with a new one + * @example + * ```ts + * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); + * // returns Collection { "a" => 3, "b" => 2 } + * ``` + */ + static combineEntries(entries, combine) { + const coll = new _Collection(); + for (const [key, value] of entries) { + if (coll.has(key)) { + coll.set(key, combine(coll.get(key), value, key)); + } else { + coll.set(key, value); + } + } + return coll; + } +}; + +// src/index.ts +var version = "1.5.3"; +export { + Collection, + version +}; +//# sourceMappingURL=index.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/collection/dist/index.mjs.map b/node_modules/@discordjs/collection/dist/index.mjs.map new file mode 100644 index 0000000..fcf72ab --- /dev/null +++ b/node_modules/@discordjs/collection/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/collection.ts","../src/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\n/**\n * @internal\n */\nexport interface CollectionConstructor {\n\tnew (): Collection<unknown, unknown>;\n\tnew <K, V>(entries?: readonly (readonly [K, V])[] | null): Collection<K, V>;\n\tnew <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;\n\treadonly prototype: Collection<unknown, unknown>;\n\treadonly [Symbol.species]: CollectionConstructor;\n}\n\n/**\n * Represents an immutable version of a collection\n */\nexport type ReadonlyCollection<K, V> = Omit<\n\tCollection<K, V>,\n\t'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'\n> &\n\tReadonlyMap<K, V>;\n\n/**\n * Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself\n *\n * @internal\n */\nexport interface Collection<K, V> extends Map<K, V> {\n\tconstructor: CollectionConstructor;\n}\n\n/**\n * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has\n * an ID, for significantly improved performance and ease-of-use.\n *\n * @typeParam K - The key type this collection holds\n * @typeParam V - The value type this collection holds\n */\nexport class Collection<K, V> extends Map<K, V> {\n\t/**\n\t * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.\n\t *\n\t * @param key - The key to get if it exists, or set otherwise\n\t * @param defaultValueGenerator - A function that generates the default value\n\t * @example\n\t * ```ts\n\t * collection.ensure(guildId, () => defaultGuildConfig);\n\t * ```\n\t */\n\tpublic ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V {\n\t\tif (this.has(key)) return this.get(key)!;\n\t\tif (typeof defaultValueGenerator !== 'function') throw new TypeError(`${defaultValueGenerator} is not a function`);\n\t\tconst defaultValue = defaultValueGenerator(key, this);\n\t\tthis.set(key, defaultValue);\n\t\treturn defaultValue;\n\t}\n\n\t/**\n\t * Checks if all of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t * @returns `true` if all of the elements exist, `false` if at least one does not exist.\n\t */\n\tpublic hasAll(...keys: K[]) {\n\t\treturn keys.every((key) => super.has(key));\n\t}\n\n\t/**\n\t * Checks if any of the elements exist in the collection.\n\t *\n\t * @param keys - The keys of the elements to check for\n\t * @returns `true` if any of the elements exist, `false` if none exist.\n\t */\n\tpublic hasAny(...keys: K[]) {\n\t\treturn keys.some((key) => super.has(key));\n\t}\n\n\t/**\n\t * Obtains the first value(s) in this collection.\n\t *\n\t * @param amount - Amount of values to obtain from the beginning\n\t * @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative\n\t */\n\tpublic first(): V | undefined;\n\tpublic first(amount: number): V[];\n\tpublic first(amount?: number): V | V[] | undefined {\n\t\tif (amount === undefined) return this.values().next().value;\n\t\tif (amount < 0) return this.last(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.values();\n\t\treturn Array.from({ length: amount }, (): V => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the first key(s) in this collection.\n\t *\n\t * @param amount - Amount of keys to obtain from the beginning\n\t * @returns A single key if no amount is provided or an array of keys, starting from the end if\n\t * amount is negative\n\t */\n\tpublic firstKey(): K | undefined;\n\tpublic firstKey(amount: number): K[];\n\tpublic firstKey(amount?: number): K | K[] | undefined {\n\t\tif (amount === undefined) return this.keys().next().value;\n\t\tif (amount < 0) return this.lastKey(amount * -1);\n\t\tamount = Math.min(this.size, amount);\n\t\tconst iter = this.keys();\n\t\treturn Array.from({ length: amount }, (): K => iter.next().value);\n\t}\n\n\t/**\n\t * Obtains the last value(s) in this collection.\n\t *\n\t * @param amount - Amount of values to obtain from the end\n\t * @returns A single value if no amount is provided or an array of values, starting from the start if\n\t * amount is negative\n\t */\n\tpublic last(): V | undefined;\n\tpublic last(amount: number): V[];\n\tpublic last(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (amount === undefined) return arr[arr.length - 1];\n\t\tif (amount < 0) return this.first(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Obtains the last key(s) in this collection.\n\t *\n\t * @param amount - Amount of keys to obtain from the end\n\t * @returns A single key if no amount is provided or an array of keys, starting from the start if\n\t * amount is negative\n\t */\n\tpublic lastKey(): K | undefined;\n\tpublic lastKey(amount: number): K[];\n\tpublic lastKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (amount === undefined) return arr[arr.length - 1];\n\t\tif (amount < 0) return this.firstKey(amount * -1);\n\t\tif (!amount) return [];\n\t\treturn arr.slice(-amount);\n\t}\n\n\t/**\n\t * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.\n\t * Returns the item at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index - The index of the element to obtain\n\t */\n\tpublic at(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.values()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}.\n\t * Returns the key at a given index, allowing for positive and negative integers.\n\t * Negative integers count back from the last item in the collection.\n\t *\n\t * @param index - The index of the key to obtain\n\t */\n\tpublic keyAt(index: number) {\n\t\tindex = Math.floor(index);\n\t\tconst arr = [...this.keys()];\n\t\treturn arr.at(index);\n\t}\n\n\t/**\n\t * Obtains unique random value(s) from this collection.\n\t *\n\t * @param amount - Amount of values to obtain randomly\n\t * @returns A single value if no amount is provided or an array of values\n\t */\n\tpublic random(): V | undefined;\n\tpublic random(amount: number): V[];\n\tpublic random(amount?: number): V | V[] | undefined {\n\t\tconst arr = [...this.values()];\n\t\tif (amount === undefined) return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]!,\n\t\t);\n\t}\n\n\t/**\n\t * Obtains unique random key(s) from this collection.\n\t *\n\t * @param amount - Amount of keys to obtain randomly\n\t * @returns A single key if no amount is provided or an array\n\t */\n\tpublic randomKey(): K | undefined;\n\tpublic randomKey(amount: number): K[];\n\tpublic randomKey(amount?: number): K | K[] | undefined {\n\t\tconst arr = [...this.keys()];\n\t\tif (amount === undefined) return arr[Math.floor(Math.random() * arr.length)];\n\t\tif (!arr.length || !amount) return [];\n\t\treturn Array.from(\n\t\t\t{ length: Math.min(amount, arr.length) },\n\t\t\t(): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]!,\n\t\t);\n\t}\n\n\t/**\n\t * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()}\n\t * but returns a Collection instead of an Array.\n\t */\n\tpublic reverse() {\n\t\tconst entries = [...this.entries()].reverse();\n\t\tthis.clear();\n\t\tfor (const [key, value] of entries) this.set(key, value);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches for a single item where the given function returns a truthy value. This behaves like\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find | Array.find()}.\n\t * All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you\n\t * should use the `get` method. See\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get | MDN} for details.\n\t *\n\t * @param fn - The function to test with (should return boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.find(user => user.username === 'Bob');\n\t * ```\n\t */\n\tpublic find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => unknown): V | undefined;\n\tpublic find<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): V2 | undefined;\n\tpublic find<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): V | undefined;\n\tpublic find(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): V | undefined {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return val;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Searches for the key of a single item where the given function returns a truthy value. This behaves like\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | Array.findIndex()},\n\t * but returns the key rather than the positional index.\n\t *\n\t * @param fn - The function to test with (should return boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.findKey(user => user.username === 'Bob');\n\t * ```\n\t */\n\tpublic findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => unknown): K | undefined;\n\tpublic findKey<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): K2 | undefined;\n\tpublic findKey<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): K | undefined;\n\tpublic findKey(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): K | undefined {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return key;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Removes items that satisfy the provided filter function.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @returns The number of removed entries\n\t */\n\tpublic sweep(fn: (value: V, key: K, collection: this) => unknown): number;\n\tpublic sweep<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): number;\n\tpublic sweep(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): number {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst previousSize = this.size;\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) this.delete(key);\n\t\t}\n\n\t\treturn previousSize - this.size;\n\t}\n\n\t/**\n\t * Identical to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | Array.filter()},\n\t * but returns a Collection instead of an Array.\n\t *\n\t * @param fn - The function to test with (should return boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.filter(user => user.username === 'Bob');\n\t * ```\n\t */\n\tpublic filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;\n\tpublic filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => unknown): Collection<K, V>;\n\tpublic filter<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): Collection<K2, V>;\n\tpublic filter<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): Collection<K, V2>;\n\tpublic filter<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): Collection<K, V>;\n\tpublic filter(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): Collection<K, V> {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst results = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) results.set(key, val);\n\t\t}\n\n\t\treturn results;\n\t}\n\n\t/**\n\t * Partitions the collection into two collections where the first collection\n\t * contains the items that passed and the second contains the items that failed.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * const [big, small] = collection.partition(guild => guild.memberCount > 250);\n\t * ```\n\t */\n\tpublic partition<K2 extends K>(\n\t\tfn: (value: V, key: K, collection: this) => key is K2,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<V2 extends V>(\n\t\tfn: (value: V, key: K, collection: this) => value is V2,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition(fn: (value: V, key: K, collection: this) => unknown): [Collection<K, V>, Collection<K, V>];\n\tpublic partition<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): [Collection<K2, V>, Collection<Exclude<K, K2>, V>];\n\tpublic partition<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): [Collection<K, V2>, Collection<K, Exclude<V, V2>>];\n\tpublic partition<This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => unknown,\n\t\tthisArg: This,\n\t): [Collection<K, V>, Collection<K, V>];\n\tpublic partition(\n\t\tfn: (value: V, key: K, collection: this) => unknown,\n\t\tthisArg?: unknown,\n\t): [Collection<K, V>, Collection<K, V>] {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst results: [Collection<K, V>, Collection<K, V>] = [\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t\tnew this.constructor[Symbol.species]<K, V>(),\n\t\t];\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) {\n\t\t\t\tresults[0].set(key, val);\n\t\t\t} else {\n\t\t\t\tresults[1].set(key, val);\n\t\t\t}\n\t\t}\n\n\t\treturn results;\n\t}\n\n\t/**\n\t * Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap | Array.flatMap()}.\n\t *\n\t * @param fn - Function that produces a new Collection\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.flatMap(guild => guild.members.cache);\n\t * ```\n\t */\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;\n\tpublic flatMap<T, This>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => Collection<K, T>,\n\t\tthisArg: This,\n\t): Collection<K, T>;\n\tpublic flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {\n\t\t// eslint-disable-next-line unicorn/no-array-method-this-argument\n\t\tconst collections = this.map(fn, thisArg);\n\t\treturn new this.constructor[Symbol.species]<K, T>().concat(...collections);\n\t}\n\n\t/**\n\t * Maps each item to another value into an array. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.\n\t *\n\t * @param fn - Function that produces an element of the new array, taking three arguments\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.map(user => user.tag);\n\t * ```\n\t */\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T): T[];\n\tpublic map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];\n\tpublic map<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): T[] {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst iter = this.entries();\n\t\treturn Array.from({ length: this.size }, (): T => {\n\t\t\tconst [key, value] = iter.next().value;\n\t\t\treturn fn(value, key, this);\n\t\t});\n\t}\n\n\t/**\n\t * Maps each item to another value into a collection. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.map()}.\n\t *\n\t * @param fn - Function that produces an element of the new collection, taking three arguments\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.mapValues(user => user.tag);\n\t * ```\n\t */\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;\n\tpublic mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;\n\tpublic mapValues<T>(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection<K, T> {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, val] of this) coll.set(key, fn(val, key, this));\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Checks if there exists an item that passes a test. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some | Array.some()}.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.some(user => user.discriminator === '0000');\n\t * ```\n\t */\n\tpublic some(fn: (value: V, key: K, collection: this) => unknown): boolean;\n\tpublic some<T>(fn: (this: T, value: V, key: K, collection: this) => unknown, thisArg: T): boolean;\n\tpublic some(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): boolean {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (fn(val, key, this)) return true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Checks if all items passes a test. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every | Array.every()}.\n\t *\n\t * @param fn - Function used to test (should return a boolean)\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection.every(user => !user.bot);\n\t * ```\n\t */\n\tpublic every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;\n\tpublic every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;\n\tpublic every(fn: (value: V, key: K, collection: this) => unknown): boolean;\n\tpublic every<This, K2 extends K>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => key is K2,\n\t\tthisArg: This,\n\t): this is Collection<K2, V>;\n\tpublic every<This, V2 extends V>(\n\t\tfn: (this: This, value: V, key: K, collection: this) => value is V2,\n\t\tthisArg: This,\n\t): this is Collection<K, V2>;\n\tpublic every<This>(fn: (this: This, value: V, key: K, collection: this) => unknown, thisArg: This): boolean;\n\tpublic every(fn: (value: V, key: K, collection: this) => unknown, thisArg?: unknown): boolean {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfor (const [key, val] of this) {\n\t\t\tif (!fn(val, key, this)) return false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Applies a function to produce a single value. Identical in behavior to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | Array.reduce()}.\n\t *\n\t * @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,\n\t * and `collection`\n\t * @param initialValue - Starting value for the accumulator\n\t * @example\n\t * ```ts\n\t * collection.reduce((acc, guild) => acc + guild.memberCount, 0);\n\t * ```\n\t */\n\tpublic reduce<T = V>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tlet accumulator!: T;\n\n\t\tconst iterator = this.entries();\n\t\tif (initialValue === undefined) {\n\t\t\tif (this.size === 0) throw new TypeError('Reduce of empty collection with no initial value');\n\t\t\taccumulator = iterator.next().value[1];\n\t\t} else {\n\t\t\taccumulator = initialValue;\n\t\t}\n\n\t\tfor (const [key, value] of iterator) {\n\t\t\taccumulator = fn(accumulator, value, key, this);\n\t\t}\n\n\t\treturn accumulator;\n\t}\n\n\t/**\n\t * Identical to\n\t * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach | Map.forEach()},\n\t * but returns the collection instead of undefined.\n\t *\n\t * @param fn - Function to execute for each element\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection\n\t * .each(user => console.log(user.username))\n\t * .filter(user => user.bot)\n\t * .each(user => console.log(user.username));\n\t * ```\n\t */\n\tpublic each(fn: (value: V, key: K, collection: this) => void): this;\n\tpublic each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;\n\tpublic each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\n\t\tfor (const [key, value] of this) {\n\t\t\tfn(value, key, this);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Runs a function on the collection and returns the collection.\n\t *\n\t * @param fn - Function to execute\n\t * @param thisArg - Value to use as `this` when executing function\n\t * @example\n\t * ```ts\n\t * collection\n\t * .tap(coll => console.log(coll.size))\n\t * .filter(user => user.bot)\n\t * .tap(coll => console.log(coll.size))\n\t * ```\n\t */\n\tpublic tap(fn: (collection: this) => void): this;\n\tpublic tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;\n\tpublic tap(fn: (collection: this) => void, thisArg?: unknown): this {\n\t\tif (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);\n\t\tif (thisArg !== undefined) fn = fn.bind(thisArg);\n\t\tfn(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Creates an identical shallow copy of this collection.\n\t *\n\t * @example\n\t * ```ts\n\t * const newColl = someColl.clone();\n\t * ```\n\t */\n\tpublic clone(): Collection<K, V> {\n\t\treturn new this.constructor[Symbol.species](this);\n\t}\n\n\t/**\n\t * Combines this collection with others into a new collection. None of the source collections are modified.\n\t *\n\t * @param collections - Collections to merge\n\t * @example\n\t * ```ts\n\t * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);\n\t * ```\n\t */\n\tpublic concat(...collections: ReadonlyCollection<K, V>[]) {\n\t\tconst newColl = this.clone();\n\t\tfor (const coll of collections) {\n\t\t\tfor (const [key, val] of coll) newColl.set(key, val);\n\t\t}\n\n\t\treturn newColl;\n\t}\n\n\t/**\n\t * Checks if this collection shares identical items with another.\n\t * This is different to checking for equality using equal-signs, because\n\t * the collections may be different objects, but contain the same data.\n\t *\n\t * @param collection - Collection to compare with\n\t * @returns Whether the collections have identical contents\n\t */\n\tpublic equals(collection: ReadonlyCollection<K, V>) {\n\t\tif (!collection) return false; // runtime check\n\t\tif (this === collection) return true;\n\t\tif (this.size !== collection.size) return false;\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!collection.has(key) || value !== collection.get(key)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * The sort method sorts the items of a collection in place and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction - Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.\n\t * @example\n\t * ```ts\n\t * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t * ```\n\t */\n\tpublic sort(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\tconst entries = [...this.entries()];\n\t\tentries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0]));\n\n\t\t// Perform clean-up\n\t\tsuper.clear();\n\n\t\t// Set the new entries\n\t\tfor (const [key, value] of entries) {\n\t\t\tsuper.set(key, value);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * The intersect method returns a new structure containing items where the keys and values are present in both original structures.\n\t *\n\t * @param other - The other Collection to filter against\n\t */\n\tpublic intersect<T>(other: ReadonlyCollection<K, T>): Collection<K, T> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, T>();\n\t\tfor (const [key, value] of other) {\n\t\t\tif (this.has(key) && Object.is(value, this.get(key))) {\n\t\t\t\tcoll.set(key, value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other.\n\t *\n\t * @param other - The other Collection to filter against\n\t */\n\tpublic subtract<T>(other: ReadonlyCollection<K, T>): Collection<K, V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, V>();\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!other.has(key) || !Object.is(value, other.get(key))) {\n\t\t\t\tcoll.set(key, value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.\n\t *\n\t * @param other - The other Collection to filter against\n\t */\n\tpublic difference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, T | V>();\n\t\tfor (const [key, value] of other) {\n\t\t\tif (!this.has(key)) coll.set(key, value);\n\t\t}\n\n\t\tfor (const [key, value] of this) {\n\t\t\tif (!other.has(key)) coll.set(key, value);\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * Merges two Collections together into a new Collection.\n\t *\n\t * @param other - The other Collection to merge with\n\t * @param whenInSelf - Function getting the result if the entry only exists in this Collection\n\t * @param whenInOther - Function getting the result if the entry only exists in the other Collection\n\t * @param whenInBoth - Function getting the result if the entry exists in both Collections\n\t * @example\n\t * ```ts\n\t * // Sums up the entries in two collections.\n\t * coll.merge(\n\t * other,\n\t * x => ({ keep: true, value: x }),\n\t * y => ({ keep: true, value: y }),\n\t * (x, y) => ({ keep: true, value: x + y }),\n\t * );\n\t * ```\n\t * @example\n\t * ```ts\n\t * // Intersects two collections in a left-biased manner.\n\t * coll.merge(\n\t * other,\n\t * x => ({ keep: false }),\n\t * y => ({ keep: false }),\n\t * (x, _) => ({ keep: true, value: x }),\n\t * );\n\t * ```\n\t */\n\tpublic merge<T, R>(\n\t\tother: ReadonlyCollection<K, T>,\n\t\twhenInSelf: (value: V, key: K) => Keep<R>,\n\t\twhenInOther: (valueOther: T, key: K) => Keep<R>,\n\t\twhenInBoth: (value: V, valueOther: T, key: K) => Keep<R>,\n\t): Collection<K, R> {\n\t\tconst coll = new this.constructor[Symbol.species]<K, R>();\n\t\tconst keys = new Set([...this.keys(), ...other.keys()]);\n\n\t\tfor (const key of keys) {\n\t\t\tconst hasInSelf = this.has(key);\n\t\t\tconst hasInOther = other.has(key);\n\n\t\t\tif (hasInSelf && hasInOther) {\n\t\t\t\tconst result = whenInBoth(this.get(key)!, other.get(key)!, key);\n\t\t\t\tif (result.keep) coll.set(key, result.value);\n\t\t\t} else if (hasInSelf) {\n\t\t\t\tconst result = whenInSelf(this.get(key)!, key);\n\t\t\t\tif (result.keep) coll.set(key, result.value);\n\t\t\t} else if (hasInOther) {\n\t\t\t\tconst result = whenInOther(other.get(key)!, key);\n\t\t\t\tif (result.keep) coll.set(key, result.value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n\n\t/**\n\t * The sorted method sorts the items of a collection and returns it.\n\t * The sort is not necessarily stable in Node 10 or older.\n\t * The default sort order is according to string Unicode code points.\n\t *\n\t * @param compareFunction - Specifies a function that defines the sort order.\n\t * If omitted, the collection is sorted according to each character's Unicode code point value,\n\t * according to the string conversion of each element.\n\t * @example\n\t * ```ts\n\t * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);\n\t * ```\n\t */\n\tpublic sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) {\n\t\treturn new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));\n\t}\n\n\tpublic toJSON() {\n\t\t// toJSON is called recursively by JSON.stringify.\n\t\treturn [...this.values()];\n\t}\n\n\tprivate static defaultSort<V>(firstValue: V, secondValue: V): number {\n\t\treturn Number(firstValue > secondValue) || Number(firstValue === secondValue) - 1;\n\t}\n\n\t/**\n\t * Creates a Collection from a list of entries.\n\t *\n\t * @param entries - The list of entries\n\t * @param combine - Function to combine an existing entry with a new one\n\t * @example\n\t * ```ts\n\t * Collection.combineEntries([[\"a\", 1], [\"b\", 2], [\"a\", 2]], (x, y) => x + y);\n\t * // returns Collection { \"a\" => 3, \"b\" => 2 }\n\t * ```\n\t */\n\tpublic static combineEntries<K, V>(\n\t\tentries: Iterable<[K, V]>,\n\t\tcombine: (firstValue: V, secondValue: V, key: K) => V,\n\t): Collection<K, V> {\n\t\tconst coll = new Collection<K, V>();\n\t\tfor (const [key, value] of entries) {\n\t\t\tif (coll.has(key)) {\n\t\t\t\tcoll.set(key, combine(coll.get(key)!, value, key));\n\t\t\t} else {\n\t\t\t\tcoll.set(key, value);\n\t\t\t}\n\t\t}\n\n\t\treturn coll;\n\t}\n}\n\n/**\n * @internal\n */\nexport type Keep<V> = { keep: false } | { keep: true; value: V };\n\n/**\n * @internal\n */\nexport type Comparator<K, V> = (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number;\n","export * from './collection.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/collection/#readme | @discordjs/collection} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\nexport const version = '1.5.3' as string;\n"],"mappings":";;;;AAqCO,IAAM,aAAN,MAAM,oBAAyB,IAAU;AAAA,EArChD,OAqCgD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWxC,OAAO,KAAQ,uBAA2D;AAChF,QAAI,KAAK,IAAI,GAAG;AAAG,aAAO,KAAK,IAAI,GAAG;AACtC,QAAI,OAAO,0BAA0B;AAAY,YAAM,IAAI,UAAU,GAAG,qBAAqB,oBAAoB;AACjH,UAAM,eAAe,sBAAsB,KAAK,IAAI;AACpD,SAAK,IAAI,KAAK,YAAY;AAC1B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,UAAU,MAAW;AAC3B,WAAO,KAAK,MAAM,CAAC,QAAQ,MAAM,IAAI,GAAG,CAAC;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,UAAU,MAAW;AAC3B,WAAO,KAAK,KAAK,CAAC,QAAQ,MAAM,IAAI,GAAG,CAAC;AAAA,EACzC;AAAA,EAUO,MAAM,QAAsC;AAClD,QAAI,WAAW;AAAW,aAAO,KAAK,OAAO,EAAE,KAAK,EAAE;AACtD,QAAI,SAAS;AAAG,aAAO,KAAK,KAAK,SAAS,EAAE;AAC5C,aAAS,KAAK,IAAI,KAAK,MAAM,MAAM;AACnC,UAAM,OAAO,KAAK,OAAO;AACzB,WAAO,MAAM,KAAK,EAAE,QAAQ,OAAO,GAAG,MAAS,KAAK,K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EAEA,OAAe,YAAe,YAAe,aAAwB;AACpE,WAAO,OAAO,aAAa,WAAW,KAAK,OAAO,eAAe,WAAW,IAAI;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,OAAc,eACb,SACA,SACmB;AACnB,UAAM,OAAO,IAAI,YAAiB;AAClC,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AACnC,UAAI,KAAK,IAAI,GAAG,GAAG;AAClB,aAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,GAAG,GAAI,OAAO,GAAG,CAAC;AAAA,MAClD,OAAO;AACN,aAAK,IAAI,KAAK,KAAK;AAAA,MACpB;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;;;AC9yBO,IAAM,UAAU;","names":[]}
\ No newline at end of file diff --git a/node_modules/@discordjs/collection/package.json b/node_modules/@discordjs/collection/package.json new file mode 100644 index 0000000..81e2418 --- /dev/null +++ b/node_modules/@discordjs/collection/package.json @@ -0,0 +1,76 @@ +{ + "name": "@discordjs/collection", + "version": "1.5.3", + "description": "Utility data structure used in discord.js", + "scripts": { + "test": "vitest run", + "build": "tsup", + "build:docs": "tsc -p tsconfig.docs.json", + "lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --format=pretty", + "format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix --format=pretty", + "fmt": "yarn format", + "docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json", + "prepack": "yarn lint && yarn test && yarn build", + "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'", + "release": "cliff-jumper" + }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "directories": { + "lib": "src", + "test": "__tests__" + }, + "files": [ + "dist" + ], + "contributors": [ + "Crawl <icrawltogo@gmail.com>", + "Amish Shah <amishshah.2k@gmail.com>", + "SpaceEEC <spaceeec@yahoo.com>", + "Vlad Frangu <kingdgrizzle@gmail.com>", + "Aura Román <kyradiscord@gmail.com>" + ], + "license": "Apache-2.0", + "keywords": [ + "map", + "collection", + "utility" + ], + "repository": { + "type": "git", + "url": "https://github.com/discordjs/discord.js.git", + "directory": "packages/collection" + }, + "bugs": { + "url": "https://github.com/discordjs/discord.js/issues" + }, + "homepage": "https://discord.js.org", + "devDependencies": { + "@favware/cliff-jumper": "^2.1.1", + "@microsoft/api-extractor": "^7.36.4", + "@types/node": "16.18.40", + "@vitest/coverage-v8": "^0.34.2", + "cross-env": "^7.0.3", + "esbuild-plugin-version-injector": "^1.2.0", + "eslint": "^8.47.0", + "eslint-config-neon": "^0.1.47", + "eslint-formatter-pretty": "^5.0.0", + "prettier": "^2.8.8", + "tsup": "^7.2.0", + "turbo": "^1.10.12", + "typescript": "^5.1.6", + "vitest": "^0.34.2" + }, + "engines": { + "node": ">=16.11.0" + }, + "publishConfig": { + "access": "public" + } +}
\ No newline at end of file diff --git a/node_modules/@discordjs/formatters/CHANGELOG.md b/node_modules/@discordjs/formatters/CHANGELOG.md new file mode 100644 index 0000000..93381bb --- /dev/null +++ b/node_modules/@discordjs/formatters/CHANGELOG.md @@ -0,0 +1,55 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +# [@discordjs/formatters@0.3.2](https://github.com/discordjs/discord.js/compare/@discordjs/formatters@0.3.1...@discordjs/formatters@0.3.2) - (2023-08-17) + +## Documentation + +- Update Node.js requirement to 16.11.0 (#9764) ([188877c](https://github.com/discordjs/discord.js/commit/188877c50af70f0d5cffb246620fa277435c6ce6)) + +# [@discordjs/formatters@0.3.1](https://github.com/discordjs/discord.js/compare/@discordjs/formatters@0.3.0...@discordjs/formatters@0.3.1) - (2023-05-01) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) +- **formatters:** Enhance the documentation (#9364) ([23e0ac5](https://github.com/discordjs/discord.js/commit/23e0ac56f456c39d925e2644ec3ca209d4410a99)) + +# [@discordjs/formatters@0.3.1](https://github.com/discordjs/discord.js/compare/@discordjs/formatters@0.3.0...@discordjs/formatters@0.3.1) - (2023-05-01) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) +- **formatters:** Enhance the documentation (#9364) ([23e0ac5](https://github.com/discordjs/discord.js/commit/23e0ac56f456c39d925e2644ec3ca209d4410a99)) + +# [@discordjs/formatters@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/formatters@0.2.0...@discordjs/formatters@0.3.0) - (2023-04-01) + +## Bug Fixes + +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/formatters@0.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/formatters@0.1.0...@discordjs/formatters@0.2.0) - (2023-03-12) + +## Features + +- **website:** Add support for source file links (#9048) ([f6506e9](https://github.com/discordjs/discord.js/commit/f6506e99c496683ee0ab67db0726b105b929af38)) + +## Refactor + +- Compare with `undefined` directly (#9191) ([869153c](https://github.com/discordjs/discord.js/commit/869153c3fdf155783e7c0ecebd3627b087c3a026)) +- Moved the escapeX functions from discord.js to @discord.js/formatters (#8957) ([13ce78a](https://github.com/discordjs/discord.js/commit/13ce78af6e3aedc793f53a099a6a615df44311f7)) + +## Styling + +- Run prettier (#9041) ([2798ba1](https://github.com/discordjs/discord.js/commit/2798ba1eb3d734f0cf2eeccd2e16cfba6804873b)) + +# [@discordjs/formatters@0.1.0](https://github.com/discordjs/discord.js/tree/@discordjs/formatters@0.1.0) - (2022-12-16) + +## Features + +- Add `@discordjs/formatters` (#8889) ([3fca638](https://github.com/discordjs/discord.js/commit/3fca638a8470dcea2f79ddb9f18526dbc0017c88)) + diff --git a/node_modules/@discordjs/formatters/LICENSE b/node_modules/@discordjs/formatters/LICENSE new file mode 100644 index 0000000..e2baac1 --- /dev/null +++ b/node_modules/@discordjs/formatters/LICENSE @@ -0,0 +1,191 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "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 Noel Buechler + Copyright 2021 Vlad Frangu + + 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. diff --git a/node_modules/@discordjs/formatters/README.md b/node_modules/@discordjs/formatters/README.md new file mode 100644 index 0000000..b846625 --- /dev/null +++ b/node_modules/@discordjs/formatters/README.md @@ -0,0 +1,81 @@ +<div align="center"> + <br /> + <p> + <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a> + </p> + <br /> + <p> + <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a> + <a href="https://www.npmjs.com/package/@discordjs/formatters"><img src="https://img.shields.io/npm/v/@discordjs/formatters.svg?maxAge=3600" alt="npm version" /></a> + <a href="https://www.npmjs.com/package/@discordjs/formatters"><img src="https://img.shields.io/npm/dt/@discordjs/formatters.svg?maxAge=3600" alt="npm downloads" /></a> + <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a> + <a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=formatters" alt="Code coverage" /></a> + </p> + <p> + <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a> + <a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a> + </p> +</div> + +## About + +`@discordjs/formatters` is a collection of functions for formatting strings to be used on Discord. + +## Installation + +**Node.js 16.11.0 or newer is required.** + +```sh +npm install @discordjs/formatters +yarn add @discordjs/formatters +pnpm add @discordjs/formatters +``` + +## Example usage + +````ts +import { codeBlock } from '@discordjs/formatters'; + +const formattedCode = codeBlock('hello world!'); +console.log(formattedCode); + +// Prints: +// ``` +// hello world! +// ``` +```` + +## Links + +- [Website][website] ([source][website-source]) +- [Documentation][documentation] +- [Guide][guide] ([source][guide-source]) + Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library. +- [discord.js Discord server][discord] +- [Discord API Discord server][discord-api] +- [GitHub][source] +- [npm][npm] +- [Related libraries][related-libs] + +## Contributing + +Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the +[documentation][documentation]. +See [the contribution guide][contributing] if you'd like to submit a PR. + +## Help + +If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord]. + +[website]: https://discord.js.org +[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website +[documentation]: https://discord.js.org/docs/packages/formatters/stable +[guide]: https://discordjs.guide/ +[guide-source]: https://github.com/discordjs/guide +[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html +[discord]: https://discord.gg/djs +[discord-api]: https://discord.gg/discord-api +[source]: https://github.com/discordjs/discord.js/tree/main/packages/formatters +[npm]: https://www.npmjs.com/package/@discordjs/formatters +[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries +[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md diff --git a/node_modules/@discordjs/formatters/dist/index.d.mts b/node_modules/@discordjs/formatters/dist/index.d.mts new file mode 100644 index 0000000..383d71a --- /dev/null +++ b/node_modules/@discordjs/formatters/dist/index.d.mts @@ -0,0 +1,511 @@ +import { URL } from 'node:url'; +import { Snowflake } from 'discord-api-types/globals'; + +/** + * The options that affect what will be escaped. + */ +interface EscapeMarkdownOptions { + /** + * Whether to escape bold text. + * + * @defaultValue `true` + */ + bold?: boolean; + /** + * Whether to escape bulleted lists. + * + * @defaultValue `false` + */ + bulletedList?: boolean; + /** + * Whether to escape code blocks. + * + * @defaultValue `true` + */ + codeBlock?: boolean; + /** + * Whether to escape text inside code blocks. + * + * @defaultValue `true` + */ + codeBlockContent?: boolean; + /** + * Whether to escape `\`. + * + * @defaultValue `true` + */ + escape?: boolean; + /** + * Whether to escape headings. + * + * @defaultValue `false` + */ + heading?: boolean; + /** + * Whether to escape inline code. + * + * @defaultValue `true` + */ + inlineCode?: boolean; + /** + * Whether to escape text inside inline code. + * + * @defaultValue `true` + */ + inlineCodeContent?: boolean; + /** + * Whether to escape italics. + * + * @defaultValue `true` + */ + italic?: boolean; + /** + * Whether to escape masked links. + * + * @defaultValue `false` + */ + maskedLink?: boolean; + /** + * Whether to escape numbered lists. + * + * @defaultValue `false` + */ + numberedList?: boolean; + /** + * Whether to escape spoilers. + * + * @defaultValue `true` + */ + spoiler?: boolean; + /** + * Whether to escape strikethroughs. + * + * @defaultValue `true` + */ + strikethrough?: boolean; + /** + * Whether to escape underlines. + * + * @defaultValue `true` + */ + underline?: boolean; +} +/** + * Escapes any Discord-flavored markdown in a string. + * + * @param text - Content to escape + * @param options - Options for escaping the markdown + */ +declare function escapeMarkdown(text: string, options?: EscapeMarkdownOptions): string; +/** + * Escapes code block markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeCodeBlock(text: string): string; +/** + * Escapes inline code markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeInlineCode(text: string): string; +/** + * Escapes italic markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeItalic(text: string): string; +/** + * Escapes bold markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeBold(text: string): string; +/** + * Escapes underline markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeUnderline(text: string): string; +/** + * Escapes strikethrough markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeStrikethrough(text: string): string; +/** + * Escapes spoiler markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeSpoiler(text: string): string; +/** + * Escapes escape characters in a string. + * + * @param text - Content to escape + */ +declare function escapeEscape(text: string): string; +/** + * Escapes heading characters in a string. + * + * @param text - Content to escape + */ +declare function escapeHeading(text: string): string; +/** + * Escapes bulleted list characters in a string. + * + * @param text - Content to escape + */ +declare function escapeBulletedList(text: string): string; +/** + * Escapes numbered list characters in a string. + * + * @param text - Content to escape + */ +declare function escapeNumberedList(text: string): string; +/** + * Escapes masked link characters in a string. + * + * @param text - Content to escape + */ +declare function escapeMaskedLink(text: string): string; + +/** + * Wraps the content inside a code block with no language. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\n\`\`\``; +/** + * Wraps the content inside a code block with the specified language. + * + * @typeParam L - This is inferred by the supplied language + * @typeParam C - This is inferred by the supplied content + * @param language - The language for the code block + * @param content - The content to wrap + */ +declare function codeBlock<L extends string, C extends string>(language: L, content: C): `\`\`\`${L}\n${C}\n\`\`\``; +/** + * Wraps the content inside \`backticks\` which formats it as inline code. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function inlineCode<C extends string>(content: C): `\`${C}\``; +/** + * Formats the content into italic text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function italic<C extends string>(content: C): `_${C}_`; +/** + * Formats the content into bold text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function bold<C extends string>(content: C): `**${C}**`; +/** + * Formats the content into underscored text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function underscore<C extends string>(content: C): `__${C}__`; +/** + * Formats the content into strike-through text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function strikethrough<C extends string>(content: C): `~~${C}~~`; +/** + * Formats the content into a quote. + * + * @remarks This needs to be at the start of the line for Discord to format it. + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function quote<C extends string>(content: C): `> ${C}`; +/** + * Formats the content into a block quote. + * + * @remarks This needs to be at the start of the line for Discord to format it. + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function blockQuote<C extends string>(content: C): `>>> ${C}`; +/** + * Wraps the URL into `<>` which stops it from embedding. + * + * @typeParam C - This is inferred by the supplied content + * @param url - The URL to wrap + */ +declare function hideLinkEmbed<C extends string>(url: C): `<${C}>`; +/** + * Wraps the URL into `<>` which stops it from embedding. + * + * @param url - The URL to wrap + */ +declare function hideLinkEmbed(url: URL): `<${string}>`; +/** + * Formats the content and the URL into a masked URL. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to display + * @param url - The URL the content links to + */ +declare function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`; +/** + * Formats the content and the URL into a masked URL. + * + * @typeParam C - This is inferred by the supplied content + * @typeParam U - This is inferred by the supplied URL + * @param content - The content to display + * @param url - The URL the content links to + */ +declare function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`; +/** + * Formats the content and the URL into a masked URL with a custom tooltip. + * + * @typeParam C - This is inferred by the supplied content + * @typeParam T - This is inferred by the supplied title + * @param content - The content to display + * @param url - The URL the content links to + * @param title - The title shown when hovering on the masked link + */ +declare function hyperlink<C extends string, T extends string>(content: C, url: URL, title: T): `[${C}](${string} "${T}")`; +/** + * Formats the content and the URL into a masked URL with a custom tooltip. + * + * @typeParam C - This is inferred by the supplied content + * @typeParam U - This is inferred by the supplied URL + * @typeParam T - This is inferred by the supplied title + * @param content - The content to display + * @param url - The URL the content links to + * @param title - The title shown when hovering on the masked link + */ +declare function hyperlink<C extends string, U extends string, T extends string>(content: C, url: U, title: T): `[${C}](${U} "${T}")`; +/** + * Formats the content into a spoiler. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function spoiler<C extends string>(content: C): `||${C}||`; +/** + * Formats a user id into a user mention. + * + * @typeParam C - This is inferred by the supplied user id + * @param userId - The user id to format + */ +declare function userMention<C extends Snowflake>(userId: C): `<@${C}>`; +/** + * Formats a channel id into a channel mention. + * + * @typeParam C - This is inferred by the supplied channel id + * @param channelId - The channel id to format + */ +declare function channelMention<C extends Snowflake>(channelId: C): `<#${C}>`; +/** + * Formats a role id into a role mention. + * + * @typeParam C - This is inferred by the supplied role id + * @param roleId - The role id to format + */ +declare function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>`; +/** + * Formats an application command name, subcommand group name, subcommand name, and id into an application command mention. + * + * @typeParam N - This is inferred by the supplied command name + * @typeParam G - This is inferred by the supplied subcommand group name + * @typeParam S - This is inferred by the supplied subcommand name + * @typeParam I - This is inferred by the supplied command id + * @param commandName - The application command name to format + * @param subcommandGroupName - The subcommand group name to format + * @param subcommandName - The subcommand name to format + * @param commandId - The application command id to format + */ +declare function chatInputApplicationCommandMention<N extends string, G extends string, S extends string, I extends Snowflake>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`; +/** + * Formats an application command name, subcommand name, and id into an application command mention. + * + * @typeParam N - This is inferred by the supplied command name + * @typeParam S - This is inferred by the supplied subcommand name + * @typeParam I - This is inferred by the supplied command id + * @param commandName - The application command name to format + * @param subcommandName - The subcommand name to format + * @param commandId - The application command id to format + */ +declare function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(commandName: N, subcommandName: S, commandId: I): `</${N} ${S}:${I}>`; +/** + * Formats an application command name and id into an application command mention. + * + * @typeParam N - This is inferred by the supplied command name + * @typeParam I - This is inferred by the supplied command id + * @param commandName - The application command name to format + * @param commandId - The application command id to format + */ +declare function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(commandName: N, commandId: I): `</${N}:${I}>`; +/** + * Formats a non-animated emoji id into a fully qualified emoji identifier. + * + * @typeParam C - This is inferred by the supplied emoji id + * @param emojiId - The emoji id to format + */ +declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`; +/** + * Formats an animated emoji id into a fully qualified emoji identifier. + * + * @typeParam C - This is inferred by the supplied emoji id + * @param emojiId - The emoji id to format + * @param animated - Whether the emoji is animated + */ +declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`; +/** + * Formats an emoji id into a fully qualified emoji identifier. + * + * @typeParam C - This is inferred by the supplied emoji id + * @param emojiId - The emoji id to format + * @param animated - Whether the emoji is animated + */ +declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`; +/** + * Formats a channel link for a direct message channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @param channelId - The channel's id + */ +declare function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`; +/** + * Formats a channel link for a guild channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @typeParam G - This is inferred by the supplied guild id + * @param channelId - The channel's id + * @param guildId - The guild's id + */ +declare function channelLink<C extends Snowflake, G extends Snowflake>(channelId: C, guildId: G): `https://discord.com/channels/${G}/${C}`; +/** + * Formats a message link for a direct message channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @typeParam M - This is inferred by the supplied message id + * @param channelId - The channel's id + * @param messageId - The message's id + */ +declare function messageLink<C extends Snowflake, M extends Snowflake>(channelId: C, messageId: M): `https://discord.com/channels/@me/${C}/${M}`; +/** + * Formats a message link for a guild channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @typeParam M - This is inferred by the supplied message id + * @typeParam G - This is inferred by the supplied guild id + * @param channelId - The channel's id + * @param messageId - The message's id + * @param guildId - The guild's id + */ +declare function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(channelId: C, messageId: M, guildId: G): `https://discord.com/channels/${G}/${C}/${M}`; +/** + * Formats a date into a short date-time string. + * + * @param date - The date to format. Defaults to the current time + */ +declare function time(date?: Date): `<t:${bigint}>`; +/** + * Formats a date given a format style. + * + * @typeParam S - This is inferred by the supplied {@link TimestampStylesString} + * @param date - The date to format + * @param style - The style to use + */ +declare function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`; +/** + * Formats the given timestamp into a short date-time string. + * + * @typeParam C - This is inferred by the supplied timestamp + * @param seconds - A Unix timestamp in seconds + */ +declare function time<C extends number>(seconds: C): `<t:${C}>`; +/** + * Formats the given timestamp into a short date-time string. + * + * @typeParam C - This is inferred by the supplied timestamp + * @typeParam S - This is inferred by the supplied {@link TimestampStylesString} + * @param seconds - A Unix timestamp in seconds + * @param style - The style to use + */ +declare function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`; +/** + * The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles} + * supported by Discord. + */ +declare const TimestampStyles: { + /** + * Short time format, consisting of hours and minutes. + * + * @example `16:20` + */ + readonly ShortTime: "t"; + /** + * Long time format, consisting of hours, minutes, and seconds. + * + * @example `16:20:30` + */ + readonly LongTime: "T"; + /** + * Short date format, consisting of day, month, and year. + * + * @example `20/04/2021` + */ + readonly ShortDate: "d"; + /** + * Long date format, consisting of day, month, and year. + * + * @example `20 April 2021` + */ + readonly LongDate: "D"; + /** + * Short date-time format, consisting of short date and short time formats. + * + * @example `20 April 2021 16:20` + */ + readonly ShortDateTime: "f"; + /** + * Long date-time format, consisting of long date and short time formats. + * + * @example `Tuesday, 20 April 2021 16:20` + */ + readonly LongDateTime: "F"; + /** + * Relative time format, consisting of a relative duration format. + * + * @example `2 months ago` + */ + readonly RelativeTime: "R"; +}; +/** + * The possible {@link TimestampStyles} values. + */ +type TimestampStylesString = (typeof TimestampStyles)[keyof typeof TimestampStyles]; +/** + * All the available faces from Discord's native slash commands. + */ +declare enum Faces { + /** + * `¯\_(ツ)_/¯` + */ + Shrug = "\u00AF_(\u30C4)_/\u00AF", + /** + * `(╯°□°)╯︵ ┻━┻` + */ + Tableflip = "(\u256F\u00B0\u25A1\u00B0)\u256F\uFE35 \u253B\u2501\u253B", + /** + * `┬─┬ノ( º _ ºノ)` + */ + Unflip = "\u252C\u2500\u252C\u30CE( \u00BA _ \u00BA\u30CE)" +} + +export { EscapeMarkdownOptions, Faces, TimestampStyles, TimestampStylesString, blockQuote, bold, channelLink, channelMention, chatInputApplicationCommandMention, codeBlock, escapeBold, escapeBulletedList, escapeCodeBlock, escapeEscape, escapeHeading, escapeInlineCode, escapeItalic, escapeMarkdown, escapeMaskedLink, escapeNumberedList, escapeSpoiler, escapeStrikethrough, escapeUnderline, formatEmoji, hideLinkEmbed, hyperlink, inlineCode, italic, messageLink, quote, roleMention, spoiler, strikethrough, time, underscore, userMention }; diff --git a/node_modules/@discordjs/formatters/dist/index.d.ts b/node_modules/@discordjs/formatters/dist/index.d.ts new file mode 100644 index 0000000..383d71a --- /dev/null +++ b/node_modules/@discordjs/formatters/dist/index.d.ts @@ -0,0 +1,511 @@ +import { URL } from 'node:url'; +import { Snowflake } from 'discord-api-types/globals'; + +/** + * The options that affect what will be escaped. + */ +interface EscapeMarkdownOptions { + /** + * Whether to escape bold text. + * + * @defaultValue `true` + */ + bold?: boolean; + /** + * Whether to escape bulleted lists. + * + * @defaultValue `false` + */ + bulletedList?: boolean; + /** + * Whether to escape code blocks. + * + * @defaultValue `true` + */ + codeBlock?: boolean; + /** + * Whether to escape text inside code blocks. + * + * @defaultValue `true` + */ + codeBlockContent?: boolean; + /** + * Whether to escape `\`. + * + * @defaultValue `true` + */ + escape?: boolean; + /** + * Whether to escape headings. + * + * @defaultValue `false` + */ + heading?: boolean; + /** + * Whether to escape inline code. + * + * @defaultValue `true` + */ + inlineCode?: boolean; + /** + * Whether to escape text inside inline code. + * + * @defaultValue `true` + */ + inlineCodeContent?: boolean; + /** + * Whether to escape italics. + * + * @defaultValue `true` + */ + italic?: boolean; + /** + * Whether to escape masked links. + * + * @defaultValue `false` + */ + maskedLink?: boolean; + /** + * Whether to escape numbered lists. + * + * @defaultValue `false` + */ + numberedList?: boolean; + /** + * Whether to escape spoilers. + * + * @defaultValue `true` + */ + spoiler?: boolean; + /** + * Whether to escape strikethroughs. + * + * @defaultValue `true` + */ + strikethrough?: boolean; + /** + * Whether to escape underlines. + * + * @defaultValue `true` + */ + underline?: boolean; +} +/** + * Escapes any Discord-flavored markdown in a string. + * + * @param text - Content to escape + * @param options - Options for escaping the markdown + */ +declare function escapeMarkdown(text: string, options?: EscapeMarkdownOptions): string; +/** + * Escapes code block markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeCodeBlock(text: string): string; +/** + * Escapes inline code markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeInlineCode(text: string): string; +/** + * Escapes italic markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeItalic(text: string): string; +/** + * Escapes bold markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeBold(text: string): string; +/** + * Escapes underline markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeUnderline(text: string): string; +/** + * Escapes strikethrough markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeStrikethrough(text: string): string; +/** + * Escapes spoiler markdown in a string. + * + * @param text - Content to escape + */ +declare function escapeSpoiler(text: string): string; +/** + * Escapes escape characters in a string. + * + * @param text - Content to escape + */ +declare function escapeEscape(text: string): string; +/** + * Escapes heading characters in a string. + * + * @param text - Content to escape + */ +declare function escapeHeading(text: string): string; +/** + * Escapes bulleted list characters in a string. + * + * @param text - Content to escape + */ +declare function escapeBulletedList(text: string): string; +/** + * Escapes numbered list characters in a string. + * + * @param text - Content to escape + */ +declare function escapeNumberedList(text: string): string; +/** + * Escapes masked link characters in a string. + * + * @param text - Content to escape + */ +declare function escapeMaskedLink(text: string): string; + +/** + * Wraps the content inside a code block with no language. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\n\`\`\``; +/** + * Wraps the content inside a code block with the specified language. + * + * @typeParam L - This is inferred by the supplied language + * @typeParam C - This is inferred by the supplied content + * @param language - The language for the code block + * @param content - The content to wrap + */ +declare function codeBlock<L extends string, C extends string>(language: L, content: C): `\`\`\`${L}\n${C}\n\`\`\``; +/** + * Wraps the content inside \`backticks\` which formats it as inline code. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function inlineCode<C extends string>(content: C): `\`${C}\``; +/** + * Formats the content into italic text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function italic<C extends string>(content: C): `_${C}_`; +/** + * Formats the content into bold text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function bold<C extends string>(content: C): `**${C}**`; +/** + * Formats the content into underscored text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function underscore<C extends string>(content: C): `__${C}__`; +/** + * Formats the content into strike-through text. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function strikethrough<C extends string>(content: C): `~~${C}~~`; +/** + * Formats the content into a quote. + * + * @remarks This needs to be at the start of the line for Discord to format it. + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function quote<C extends string>(content: C): `> ${C}`; +/** + * Formats the content into a block quote. + * + * @remarks This needs to be at the start of the line for Discord to format it. + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function blockQuote<C extends string>(content: C): `>>> ${C}`; +/** + * Wraps the URL into `<>` which stops it from embedding. + * + * @typeParam C - This is inferred by the supplied content + * @param url - The URL to wrap + */ +declare function hideLinkEmbed<C extends string>(url: C): `<${C}>`; +/** + * Wraps the URL into `<>` which stops it from embedding. + * + * @param url - The URL to wrap + */ +declare function hideLinkEmbed(url: URL): `<${string}>`; +/** + * Formats the content and the URL into a masked URL. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to display + * @param url - The URL the content links to + */ +declare function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`; +/** + * Formats the content and the URL into a masked URL. + * + * @typeParam C - This is inferred by the supplied content + * @typeParam U - This is inferred by the supplied URL + * @param content - The content to display + * @param url - The URL the content links to + */ +declare function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`; +/** + * Formats the content and the URL into a masked URL with a custom tooltip. + * + * @typeParam C - This is inferred by the supplied content + * @typeParam T - This is inferred by the supplied title + * @param content - The content to display + * @param url - The URL the content links to + * @param title - The title shown when hovering on the masked link + */ +declare function hyperlink<C extends string, T extends string>(content: C, url: URL, title: T): `[${C}](${string} "${T}")`; +/** + * Formats the content and the URL into a masked URL with a custom tooltip. + * + * @typeParam C - This is inferred by the supplied content + * @typeParam U - This is inferred by the supplied URL + * @typeParam T - This is inferred by the supplied title + * @param content - The content to display + * @param url - The URL the content links to + * @param title - The title shown when hovering on the masked link + */ +declare function hyperlink<C extends string, U extends string, T extends string>(content: C, url: U, title: T): `[${C}](${U} "${T}")`; +/** + * Formats the content into a spoiler. + * + * @typeParam C - This is inferred by the supplied content + * @param content - The content to wrap + */ +declare function spoiler<C extends string>(content: C): `||${C}||`; +/** + * Formats a user id into a user mention. + * + * @typeParam C - This is inferred by the supplied user id + * @param userId - The user id to format + */ +declare function userMention<C extends Snowflake>(userId: C): `<@${C}>`; +/** + * Formats a channel id into a channel mention. + * + * @typeParam C - This is inferred by the supplied channel id + * @param channelId - The channel id to format + */ +declare function channelMention<C extends Snowflake>(channelId: C): `<#${C}>`; +/** + * Formats a role id into a role mention. + * + * @typeParam C - This is inferred by the supplied role id + * @param roleId - The role id to format + */ +declare function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>`; +/** + * Formats an application command name, subcommand group name, subcommand name, and id into an application command mention. + * + * @typeParam N - This is inferred by the supplied command name + * @typeParam G - This is inferred by the supplied subcommand group name + * @typeParam S - This is inferred by the supplied subcommand name + * @typeParam I - This is inferred by the supplied command id + * @param commandName - The application command name to format + * @param subcommandGroupName - The subcommand group name to format + * @param subcommandName - The subcommand name to format + * @param commandId - The application command id to format + */ +declare function chatInputApplicationCommandMention<N extends string, G extends string, S extends string, I extends Snowflake>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`; +/** + * Formats an application command name, subcommand name, and id into an application command mention. + * + * @typeParam N - This is inferred by the supplied command name + * @typeParam S - This is inferred by the supplied subcommand name + * @typeParam I - This is inferred by the supplied command id + * @param commandName - The application command name to format + * @param subcommandName - The subcommand name to format + * @param commandId - The application command id to format + */ +declare function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(commandName: N, subcommandName: S, commandId: I): `</${N} ${S}:${I}>`; +/** + * Formats an application command name and id into an application command mention. + * + * @typeParam N - This is inferred by the supplied command name + * @typeParam I - This is inferred by the supplied command id + * @param commandName - The application command name to format + * @param commandId - The application command id to format + */ +declare function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(commandName: N, commandId: I): `</${N}:${I}>`; +/** + * Formats a non-animated emoji id into a fully qualified emoji identifier. + * + * @typeParam C - This is inferred by the supplied emoji id + * @param emojiId - The emoji id to format + */ +declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`; +/** + * Formats an animated emoji id into a fully qualified emoji identifier. + * + * @typeParam C - This is inferred by the supplied emoji id + * @param emojiId - The emoji id to format + * @param animated - Whether the emoji is animated + */ +declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`; +/** + * Formats an emoji id into a fully qualified emoji identifier. + * + * @typeParam C - This is inferred by the supplied emoji id + * @param emojiId - The emoji id to format + * @param animated - Whether the emoji is animated + */ +declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`; +/** + * Formats a channel link for a direct message channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @param channelId - The channel's id + */ +declare function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`; +/** + * Formats a channel link for a guild channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @typeParam G - This is inferred by the supplied guild id + * @param channelId - The channel's id + * @param guildId - The guild's id + */ +declare function channelLink<C extends Snowflake, G extends Snowflake>(channelId: C, guildId: G): `https://discord.com/channels/${G}/${C}`; +/** + * Formats a message link for a direct message channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @typeParam M - This is inferred by the supplied message id + * @param channelId - The channel's id + * @param messageId - The message's id + */ +declare function messageLink<C extends Snowflake, M extends Snowflake>(channelId: C, messageId: M): `https://discord.com/channels/@me/${C}/${M}`; +/** + * Formats a message link for a guild channel. + * + * @typeParam C - This is inferred by the supplied channel id + * @typeParam M - This is inferred by the supplied message id + * @typeParam G - This is inferred by the supplied guild id + * @param channelId - The channel's id + * @param messageId - The message's id + * @param guildId - The guild's id + */ +declare function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(channelId: C, messageId: M, guildId: G): `https://discord.com/channels/${G}/${C}/${M}`; +/** + * Formats a date into a short date-time string. + * + * @param date - The date to format. Defaults to the current time + */ +declare function time(date?: Date): `<t:${bigint}>`; +/** + * Formats a date given a format style. + * + * @typeParam S - This is inferred by the supplied {@link TimestampStylesString} + * @param date - The date to format + * @param style - The style to use + */ +declare function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`; +/** + * Formats the given timestamp into a short date-time string. + * + * @typeParam C - This is inferred by the supplied timestamp + * @param seconds - A Unix timestamp in seconds + */ +declare function time<C extends number>(seconds: C): `<t:${C}>`; +/** + * Formats the given timestamp into a short date-time string. + * + * @typeParam C - This is inferred by the supplied timestamp + * @typeParam S - This is inferred by the supplied {@link TimestampStylesString} + * @param seconds - A Unix timestamp in seconds + * @param style - The style to use + */ +declare function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`; +/** + * The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles} + * supported by Discord. + */ +declare const TimestampStyles: { + /** + * Short time format, consisting of hours and minutes. + * + * @example `16:20` + */ + readonly ShortTime: "t"; + /** + * Long time format, consisting of hours, minutes, and seconds. + * + * @example `16:20:30` + */ + readonly LongTime: "T"; + /** + * Short date format, consisting of day, month, and year. + * + * @example `20/04/2021` + */ + readonly ShortDate: "d"; + /** + * Long date format, consisting of day, month, and year. + * + * @example `20 April 2021` + */ + readonly LongDate: "D"; + /** + * Short date-time format, consisting of short date and short time formats. + * + * @example `20 April 2021 16:20` + */ + readonly ShortDateTime: "f"; + /** + * Long date-time format, consisting of long date and short time formats. + * + * @example `Tuesday, 20 April 2021 16:20` + */ + readonly LongDateTime: "F"; + /** + * Relative time format, consisting of a relative duration format. + * + * @example `2 months ago` + */ + readonly RelativeTime: "R"; +}; +/** + * The possible {@link TimestampStyles} values. + */ +type TimestampStylesString = (typeof TimestampStyles)[keyof typeof TimestampStyles]; +/** + * All the available faces from Discord's native slash commands. + */ +declare enum Faces { + /** + * `¯\_(ツ)_/¯` + */ + Shrug = "\u00AF_(\u30C4)_/\u00AF", + /** + * `(╯°□°)╯︵ ┻━┻` + */ + Tableflip = "(\u256F\u00B0\u25A1\u00B0)\u256F\uFE35 \u253B\u2501\u253B", + /** + * `┬─┬ノ( º _ ºノ)` + */ + Unflip = "\u252C\u2500\u252C\u30CE( \u00BA _ \u00BA\u30CE)" +} + +export { EscapeMarkdownOptions, Faces, TimestampStyles, TimestampStylesString, blockQuote, bold, channelLink, channelMention, chatInputApplicationCommandMention, codeBlock, escapeBold, escapeBulletedList, escapeCodeBlock, escapeEscape, escapeHeading, escapeInlineCode, escapeItalic, escapeMarkdown, escapeMaskedLink, escapeNumberedList, escapeSpoiler, escapeStrikethrough, escapeUnderline, formatEmoji, hideLinkEmbed, hyperlink, inlineCode, italic, messageLink, quote, roleMention, spoiler, strikethrough, time, underscore, userMention }; diff --git a/node_modules/@discordjs/formatters/dist/index.js b/node_modules/@discordjs/formatters/dist/index.js new file mode 100644 index 0000000..6fd2653 --- /dev/null +++ b/node_modules/@discordjs/formatters/dist/index.js @@ -0,0 +1,393 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + Faces: () => Faces, + TimestampStyles: () => TimestampStyles, + blockQuote: () => blockQuote, + bold: () => bold, + channelLink: () => channelLink, + channelMention: () => channelMention, + chatInputApplicationCommandMention: () => chatInputApplicationCommandMention, + codeBlock: () => codeBlock, + escapeBold: () => escapeBold, + escapeBulletedList: () => escapeBulletedList, + escapeCodeBlock: () => escapeCodeBlock, + escapeEscape: () => escapeEscape, + escapeHeading: () => escapeHeading, + escapeInlineCode: () => escapeInlineCode, + escapeItalic: () => escapeItalic, + escapeMarkdown: () => escapeMarkdown, + escapeMaskedLink: () => escapeMaskedLink, + escapeNumberedList: () => escapeNumberedList, + escapeSpoiler: () => escapeSpoiler, + escapeStrikethrough: () => escapeStrikethrough, + escapeUnderline: () => escapeUnderline, + formatEmoji: () => formatEmoji, + hideLinkEmbed: () => hideLinkEmbed, + hyperlink: () => hyperlink, + inlineCode: () => inlineCode, + italic: () => italic, + messageLink: () => messageLink, + quote: () => quote, + roleMention: () => roleMention, + spoiler: () => spoiler, + strikethrough: () => strikethrough, + time: () => time, + underscore: () => underscore, + userMention: () => userMention +}); +module.exports = __toCommonJS(src_exports); + +// src/escapers.ts +function escapeMarkdown(text, options = {}) { + const { + codeBlock: codeBlock2 = true, + inlineCode: inlineCode2 = true, + bold: bold2 = true, + italic: italic2 = true, + underline = true, + strikethrough: strikethrough2 = true, + spoiler: spoiler2 = true, + codeBlockContent = true, + inlineCodeContent = true, + escape = true, + heading = false, + bulletedList = false, + numberedList = false, + maskedLink = false + } = options; + if (!codeBlockContent) { + return text.split("```").map((subString, index, array) => { + if (index % 2 && index !== array.length - 1) + return subString; + return escapeMarkdown(subString, { + inlineCode: inlineCode2, + bold: bold2, + italic: italic2, + underline, + strikethrough: strikethrough2, + spoiler: spoiler2, + inlineCodeContent, + escape, + heading, + bulletedList, + numberedList, + maskedLink + }); + }).join(codeBlock2 ? "\\`\\`\\`" : "```"); + } + if (!inlineCodeContent) { + return text.split(/(?<=^|[^`])`(?=[^`]|$)/g).map((subString, index, array) => { + if (index % 2 && index !== array.length - 1) + return subString; + return escapeMarkdown(subString, { + codeBlock: codeBlock2, + bold: bold2, + italic: italic2, + underline, + strikethrough: strikethrough2, + spoiler: spoiler2, + escape, + heading, + bulletedList, + numberedList, + maskedLink + }); + }).join(inlineCode2 ? "\\`" : "`"); + } + let res = text; + if (escape) + res = escapeEscape(res); + if (inlineCode2) + res = escapeInlineCode(res); + if (codeBlock2) + res = escapeCodeBlock(res); + if (italic2) + res = escapeItalic(res); + if (bold2) + res = escapeBold(res); + if (underline) + res = escapeUnderline(res); + if (strikethrough2) + res = escapeStrikethrough(res); + if (spoiler2) + res = escapeSpoiler(res); + if (heading) + res = escapeHeading(res); + if (bulletedList) + res = escapeBulletedList(res); + if (numberedList) + res = escapeNumberedList(res); + if (maskedLink) + res = escapeMaskedLink(res); + return res; +} +__name(escapeMarkdown, "escapeMarkdown"); +function escapeCodeBlock(text) { + return text.replaceAll("```", "\\`\\`\\`"); +} +__name(escapeCodeBlock, "escapeCodeBlock"); +function escapeInlineCode(text) { + return text.replaceAll(/(?<=^|[^`])``?(?=[^`]|$)/g, (match) => match.length === 2 ? "\\`\\`" : "\\`"); +} +__name(escapeInlineCode, "escapeInlineCode"); +function escapeItalic(text) { + let idx = 0; + const newText = text.replaceAll(/(?<=^|[^*])\*([^*]|\*\*|$)/g, (_, match) => { + if (match === "**") + return ++idx % 2 ? `\\*${match}` : `${match}\\*`; + return `\\*${match}`; + }); + idx = 0; + return newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => { + if (match === "__") + return ++idx % 2 ? `\\_${match}` : `${match}\\_`; + return `\\_${match}`; + }); +} +__name(escapeItalic, "escapeItalic"); +function escapeBold(text) { + let idx = 0; + return text.replaceAll(/\*\*(\*)?/g, (_, match) => { + if (match) + return ++idx % 2 ? `${match}\\*\\*` : `\\*\\*${match}`; + return "\\*\\*"; + }); +} +__name(escapeBold, "escapeBold"); +function escapeUnderline(text) { + let idx = 0; + return text.replaceAll(/(?<!<a?:.+)__(_)?(?!:\d+>)/g, (_, match) => { + if (match) + return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`; + return "\\_\\_"; + }); +} +__name(escapeUnderline, "escapeUnderline"); +function escapeStrikethrough(text) { + return text.replaceAll("~~", "\\~\\~"); +} +__name(escapeStrikethrough, "escapeStrikethrough"); +function escapeSpoiler(text) { + return text.replaceAll("||", "\\|\\|"); +} +__name(escapeSpoiler, "escapeSpoiler"); +function escapeEscape(text) { + return text.replaceAll("\\", "\\\\"); +} +__name(escapeEscape, "escapeEscape"); +function escapeHeading(text) { + return text.replaceAll(/^( {0,2})([*-] )?( *)(#{1,3} )/gm, "$1$2$3\\$4"); +} +__name(escapeHeading, "escapeHeading"); +function escapeBulletedList(text) { + return text.replaceAll(/^( *)([*-])( +)/gm, "$1\\$2$3"); +} +__name(escapeBulletedList, "escapeBulletedList"); +function escapeNumberedList(text) { + return text.replaceAll(/^( *\d+)\./gm, "$1\\."); +} +__name(escapeNumberedList, "escapeNumberedList"); +function escapeMaskedLink(text) { + return text.replaceAll(/\[.+]\(.+\)/gm, "\\$&"); +} +__name(escapeMaskedLink, "escapeMaskedLink"); + +// src/formatters.ts +function codeBlock(language, content) { + return content === void 0 ? `\`\`\` +${language} +\`\`\`` : `\`\`\`${language} +${content} +\`\`\``; +} +__name(codeBlock, "codeBlock"); +function inlineCode(content) { + return `\`${content}\``; +} +__name(inlineCode, "inlineCode"); +function italic(content) { + return `_${content}_`; +} +__name(italic, "italic"); +function bold(content) { + return `**${content}**`; +} +__name(bold, "bold"); +function underscore(content) { + return `__${content}__`; +} +__name(underscore, "underscore"); +function strikethrough(content) { + return `~~${content}~~`; +} +__name(strikethrough, "strikethrough"); +function quote(content) { + return `> ${content}`; +} +__name(quote, "quote"); +function blockQuote(content) { + return `>>> ${content}`; +} +__name(blockQuote, "blockQuote"); +function hideLinkEmbed(url) { + return `<${url}>`; +} +__name(hideLinkEmbed, "hideLinkEmbed"); +function hyperlink(content, url, title) { + return title ? `[${content}](${url} "${title}")` : `[${content}](${url})`; +} +__name(hyperlink, "hyperlink"); +function spoiler(content) { + return `||${content}||`; +} +__name(spoiler, "spoiler"); +function userMention(userId) { + return `<@${userId}>`; +} +__name(userMention, "userMention"); +function channelMention(channelId) { + return `<#${channelId}>`; +} +__name(channelMention, "channelMention"); +function roleMention(roleId) { + return `<@&${roleId}>`; +} +__name(roleMention, "roleMention"); +function chatInputApplicationCommandMention(commandName, subcommandGroupName, subcommandName, commandId) { + if (commandId !== void 0) { + return `</${commandName} ${subcommandGroupName} ${subcommandName}:${commandId}>`; + } + if (subcommandName !== void 0) { + return `</${commandName} ${subcommandGroupName}:${subcommandName}>`; + } + return `</${commandName}:${subcommandGroupName}>`; +} +__name(chatInputApplicationCommandMention, "chatInputApplicationCommandMention"); +function formatEmoji(emojiId, animated = false) { + return `<${animated ? "a" : ""}:_:${emojiId}>`; +} +__name(formatEmoji, "formatEmoji"); +function channelLink(channelId, guildId) { + return `https://discord.com/channels/${guildId ?? "@me"}/${channelId}`; +} +__name(channelLink, "channelLink"); +function messageLink(channelId, messageId, guildId) { + return `${guildId === void 0 ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`; +} +__name(messageLink, "messageLink"); +function time(timeOrSeconds, style) { + if (typeof timeOrSeconds !== "number") { + timeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1e3); + } + return typeof style === "string" ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`; +} +__name(time, "time"); +var TimestampStyles = { + /** + * Short time format, consisting of hours and minutes. + * + * @example `16:20` + */ + ShortTime: "t", + /** + * Long time format, consisting of hours, minutes, and seconds. + * + * @example `16:20:30` + */ + LongTime: "T", + /** + * Short date format, consisting of day, month, and year. + * + * @example `20/04/2021` + */ + ShortDate: "d", + /** + * Long date format, consisting of day, month, and year. + * + * @example `20 April 2021` + */ + LongDate: "D", + /** + * Short date-time format, consisting of short date and short time formats. + * + * @example `20 April 2021 16:20` + */ + ShortDateTime: "f", + /** + * Long date-time format, consisting of long date and short time formats. + * + * @example `Tuesday, 20 April 2021 16:20` + */ + LongDateTime: "F", + /** + * Relative time format, consisting of a relative duration format. + * + * @example `2 months ago` + */ + RelativeTime: "R" +}; +var Faces = /* @__PURE__ */ ((Faces2) => { + Faces2["Shrug"] = "\xAF_(\u30C4)_/\xAF"; + Faces2["Tableflip"] = "(\u256F\xB0\u25A1\xB0)\u256F\uFE35 \u253B\u2501\u253B"; + Faces2["Unflip"] = "\u252C\u2500\u252C\u30CE( \xBA _ \xBA\u30CE)"; + return Faces2; +})(Faces || {}); +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + Faces, + TimestampStyles, + blockQuote, + bold, + channelLink, + channelMention, + chatInputApplicationCommandMention, + codeBlock, + escapeBold, + escapeBulletedList, + escapeCodeBlock, + escapeEscape, + escapeHeading, + escapeInlineCode, + escapeItalic, + escapeMarkdown, + escapeMaskedLink, + escapeNumberedList, + escapeSpoiler, + escapeStrikethrough, + escapeUnderline, + formatEmoji, + hideLinkEmbed, + hyperlink, + inlineCode, + italic, + messageLink, + quote, + roleMention, + spoiler, + strikethrough, + time, + underscore, + userMention +}); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/formatters/dist/index.js.map b/node_modules/@discordjs/formatters/dist/index.js.map new file mode 100644 index 0000000..6b7c19a --- /dev/null +++ b/node_modules/@discordjs/formatters/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/escapers.ts","../src/formatters.ts"],"sourcesContent":["export * from './escapers.js';\nexport * from './formatters.js';\n","/* eslint-disable prefer-named-capture-group */\n\n/**\n * The options that affect what will be escaped.\n */\nexport interface EscapeMarkdownOptions {\n\t/**\n\t * Whether to escape bold text.\n\t *\n\t * @defaultValue `true`\n\t */\n\tbold?: boolean;\n\n\t/**\n\t * Whether to escape bulleted lists.\n\t *\n\t * @defaultValue `false`\n\t */\n\tbulletedList?: boolean;\n\n\t/**\n\t * Whether to escape code blocks.\n\t *\n\t * @defaultValue `true`\n\t */\n\tcodeBlock?: boolean;\n\n\t/**\n\t * Whether to escape text inside code blocks.\n\t *\n\t * @defaultValue `true`\n\t */\n\tcodeBlockContent?: boolean;\n\n\t/**\n\t * Whether to escape `\\`.\n\t *\n\t * @defaultValue `true`\n\t */\n\tescape?: boolean;\n\n\t/**\n\t * Whether to escape headings.\n\t *\n\t * @defaultValue `false`\n\t */\n\theading?: boolean;\n\n\t/**\n\t * Whether to escape inline code.\n\t *\n\t * @defaultValue `true`\n\t */\n\tinlineCode?: boolean;\n\n\t/**\n\t * Whether to escape text inside inline code.\n\t *\n\t * @defaultValue `true`\n\t */\n\tinlineCodeContent?: boolean;\n\t/**\n\t * Whether to escape italics.\n\t *\n\t * @defaultValue `true`\n\t */\n\titalic?: boolean;\n\n\t/**\n\t * Whether to escape masked links.\n\t *\n\t * @defaultValue `false`\n\t */\n\tmaskedLink?: boolean;\n\n\t/**\n\t * Whether to escape numbered lists.\n\t *\n\t * @defaultValue `false`\n\t */\n\tnumberedList?: boolean;\n\n\t/**\n\t * Whether to escape spoilers.\n\t *\n\t * @defaultValue `true`\n\t */\n\tspoiler?: boolean;\n\n\t/**\n\t * Whether to escape strikethroughs.\n\t *\n\t * @defaultValue `true`\n\t */\n\tstrikethrough?: boolean;\n\n\t/**\n\t * Whether to escape underlines.\n\t *\n\t * @defaultValue `true`\n\t */\n\tunderline?: boolean;\n}\n\n/**\n * Escapes any Discord-flavored markdown in a string.\n *\n * @param text - Content to escape\n * @param options - Options for escaping the markdown\n */\nexport function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}): string {\n\tconst {\n\t\tcodeBlock = true,\n\t\tinlineCode = true,\n\t\tbold = true,\n\t\titalic = true,\n\t\tunderline = true,\n\t\tstrikethrough = true,\n\t\tspoiler = true,\n\t\tcodeBlockContent = true,\n\t\tinlineCodeContent = true,\n\t\tescape = true,\n\t\theading = false,\n\t\tbulletedList = false,\n\t\tnumberedList = false,\n\t\tmaskedLink = false,\n\t} = options;\n\n\tif (!codeBlockContent) {\n\t\treturn text\n\t\t\t.split('```')\n\t\t\t.map((subString, index, array) => {\n\t\t\t\tif (index % 2 && index !== array.length - 1) return subString;\n\t\t\t\treturn escapeMarkdown(subString, {\n\t\t\t\t\tinlineCode,\n\t\t\t\t\tbold,\n\t\t\t\t\titalic,\n\t\t\t\t\tunderline,\n\t\t\t\t\tstrikethrough,\n\t\t\t\t\tspoiler,\n\t\t\t\t\tinlineCodeContent,\n\t\t\t\t\tescape,\n\t\t\t\t\theading,\n\t\t\t\t\tbulletedList,\n\t\t\t\t\tnumberedList,\n\t\t\t\t\tmaskedLink,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.join(codeBlock ? '\\\\`\\\\`\\\\`' : '```');\n\t}\n\n\tif (!inlineCodeContent) {\n\t\treturn text\n\t\t\t.split(/(?<=^|[^`])`(?=[^`]|$)/g)\n\t\t\t.map((subString, index, array) => {\n\t\t\t\tif (index % 2 && index !== array.length - 1) return subString;\n\t\t\t\treturn escapeMarkdown(subString, {\n\t\t\t\t\tcodeBlock,\n\t\t\t\t\tbold,\n\t\t\t\t\titalic,\n\t\t\t\t\tunderline,\n\t\t\t\t\tstrikethrough,\n\t\t\t\t\tspoiler,\n\t\t\t\t\tescape,\n\t\t\t\t\theading,\n\t\t\t\t\tbulletedList,\n\t\t\t\t\tnumberedList,\n\t\t\t\t\tmaskedLink,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.join(inlineCode ? '\\\\`' : '`');\n\t}\n\n\tlet res = text;\n\tif (escape) res = escapeEscape(res);\n\tif (inlineCode) res = escapeInlineCode(res);\n\tif (codeBlock) res = escapeCodeBlock(res);\n\tif (italic) res = escapeItalic(res);\n\tif (bold) res = escapeBold(res);\n\tif (underline) res = escapeUnderline(res);\n\tif (strikethrough) res = escapeStrikethrough(res);\n\tif (spoiler) res = escapeSpoiler(res);\n\tif (heading) res = escapeHeading(res);\n\tif (bulletedList) res = escapeBulletedList(res);\n\tif (numberedList) res = escapeNumberedList(res);\n\tif (maskedLink) res = escapeMaskedLink(res);\n\treturn res;\n}\n\n/**\n * Escapes code block markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeCodeBlock(text: string): string {\n\treturn text.replaceAll('```', '\\\\`\\\\`\\\\`');\n}\n\n/**\n * Escapes inline code markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeInlineCode(text: string): string {\n\treturn text.replaceAll(/(?<=^|[^`])``?(?=[^`]|$)/g, (match) => (match.length === 2 ? '\\\\`\\\\`' : '\\\\`'));\n}\n\n/**\n * Escapes italic markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeItalic(text: string): string {\n\tlet idx = 0;\n\tconst newText = text.replaceAll(/(?<=^|[^*])\\*([^*]|\\*\\*|$)/g, (_, match) => {\n\t\tif (match === '**') return ++idx % 2 ? `\\\\*${match}` : `${match}\\\\*`;\n\t\treturn `\\\\*${match}`;\n\t});\n\tidx = 0;\n\treturn newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+)_(?!:\\d+>)([^_]|__|$)/g, (_, match) => {\n\t\tif (match === '__') return ++idx % 2 ? `\\\\_${match}` : `${match}\\\\_`;\n\t\treturn `\\\\_${match}`;\n\t});\n}\n\n/**\n * Escapes bold markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeBold(text: string): string {\n\tlet idx = 0;\n\treturn text.replaceAll(/\\*\\*(\\*)?/g, (_, match) => {\n\t\tif (match) return ++idx % 2 ? `${match}\\\\*\\\\*` : `\\\\*\\\\*${match}`;\n\t\treturn '\\\\*\\\\*';\n\t});\n}\n\n/**\n * Escapes underline markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeUnderline(text: string): string {\n\tlet idx = 0;\n\treturn text.replaceAll(/(?<!<a?:.+)__(_)?(?!:\\d+>)/g, (_, match) => {\n\t\tif (match) return ++idx % 2 ? `${match}\\\\_\\\\_` : `\\\\_\\\\_${match}`;\n\t\treturn '\\\\_\\\\_';\n\t});\n}\n\n/**\n * Escapes strikethrough markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeStrikethrough(text: string): string {\n\treturn text.replaceAll('~~', '\\\\~\\\\~');\n}\n\n/**\n * Escapes spoiler markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeSpoiler(text: string): string {\n\treturn text.replaceAll('||', '\\\\|\\\\|');\n}\n\n/**\n * Escapes escape characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeEscape(text: string): string {\n\treturn text.replaceAll('\\\\', '\\\\\\\\');\n}\n\n/**\n * Escapes heading characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeHeading(text: string): string {\n\treturn text.replaceAll(/^( {0,2})([*-] )?( *)(#{1,3} )/gm, '$1$2$3\\\\$4');\n}\n\n/**\n * Escapes bulleted list characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeBulletedList(text: string): string {\n\treturn text.replaceAll(/^( *)([*-])( +)/gm, '$1\\\\$2$3');\n}\n\n/**\n * Escapes numbered list characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeNumberedList(text: string): string {\n\treturn text.replaceAll(/^( *\\d+)\\./gm, '$1\\\\.');\n}\n\n/**\n * Escapes masked link characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeMaskedLink(text: string): string {\n\treturn text.replaceAll(/\\[.+]\\(.+\\)/gm, '\\\\$&');\n}\n","import type { URL } from 'node:url';\nimport type { Snowflake } from 'discord-api-types/globals';\n\n/**\n * Wraps the content inside a code block with no language.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function codeBlock<C extends string>(content: C): `\\`\\`\\`\\n${C}\\n\\`\\`\\``;\n\n/**\n * Wraps the content inside a code block with the specified language.\n *\n * @typeParam L - This is inferred by the supplied language\n * @typeParam C - This is inferred by the supplied content\n * @param language - The language for the code block\n * @param content - The content to wrap\n */\nexport function codeBlock<L extends string, C extends string>(language: L, content: C): `\\`\\`\\`${L}\\n${C}\\n\\`\\`\\``;\n\nexport function codeBlock(language: string, content?: string): string {\n\treturn content === undefined ? `\\`\\`\\`\\n${language}\\n\\`\\`\\`` : `\\`\\`\\`${language}\\n${content}\\n\\`\\`\\``;\n}\n\n/**\n * Wraps the content inside \\`backticks\\` which formats it as inline code.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function inlineCode<C extends string>(content: C): `\\`${C}\\`` {\n\treturn `\\`${content}\\``;\n}\n\n/**\n * Formats the content into italic text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function italic<C extends string>(content: C): `_${C}_` {\n\treturn `_${content}_`;\n}\n\n/**\n * Formats the content into bold text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function bold<C extends string>(content: C): `**${C}**` {\n\treturn `**${content}**`;\n}\n\n/**\n * Formats the content into underscored text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function underscore<C extends string>(content: C): `__${C}__` {\n\treturn `__${content}__`;\n}\n\n/**\n * Formats the content into strike-through text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function strikethrough<C extends string>(content: C): `~~${C}~~` {\n\treturn `~~${content}~~`;\n}\n\n/**\n * Formats the content into a quote.\n *\n * @remarks This needs to be at the start of the line for Discord to format it.\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function quote<C extends string>(content: C): `> ${C}` {\n\treturn `> ${content}`;\n}\n\n/**\n * Formats the content into a block quote.\n *\n * @remarks This needs to be at the start of the line for Discord to format it.\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function blockQuote<C extends string>(content: C): `>>> ${C}` {\n\treturn `>>> ${content}`;\n}\n\n/**\n * Wraps the URL into `<>` which stops it from embedding.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed<C extends string>(url: C): `<${C}>`;\n\n/**\n * Wraps the URL into `<>` which stops it from embedding.\n *\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed(url: URL): `<${string}>`;\n\nexport function hideLinkEmbed(url: URL | string) {\n\treturn `<${url}>`;\n}\n\n/**\n * Formats the content and the URL into a masked URL.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`;\n\n/**\n * Formats the content and the URL into a masked URL.\n *\n * @typeParam C - This is inferred by the supplied content\n * @typeParam U - This is inferred by the supplied URL\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`;\n\n/**\n * Formats the content and the URL into a masked URL with a custom tooltip.\n *\n * @typeParam C - This is inferred by the supplied content\n * @typeParam T - This is inferred by the supplied title\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, T extends string>(\n\tcontent: C,\n\turl: URL,\n\ttitle: T,\n): `[${C}](${string} \"${T}\")`;\n\n/**\n * Formats the content and the URL into a masked URL with a custom tooltip.\n *\n * @typeParam C - This is inferred by the supplied content\n * @typeParam U - This is inferred by the supplied URL\n * @typeParam T - This is inferred by the supplied title\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, U extends string, T extends string>(\n\tcontent: C,\n\turl: U,\n\ttitle: T,\n): `[${C}](${U} \"${T}\")`;\n\nexport function hyperlink(content: string, url: URL | string, title?: string) {\n\treturn title ? `[${content}](${url} \"${title}\")` : `[${content}](${url})`;\n}\n\n/**\n * Formats the content into a spoiler.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function spoiler<C extends string>(content: C): `||${C}||` {\n\treturn `||${content}||`;\n}\n\n/**\n * Formats a user id into a user mention.\n *\n * @typeParam C - This is inferred by the supplied user id\n * @param userId - The user id to format\n */\nexport function userMention<C extends Snowflake>(userId: C): `<@${C}>` {\n\treturn `<@${userId}>`;\n}\n\n/**\n * Formats a channel id into a channel mention.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @param channelId - The channel id to format\n */\nexport function channelMention<C extends Snowflake>(channelId: C): `<#${C}>` {\n\treturn `<#${channelId}>`;\n}\n\n/**\n * Formats a role id into a role mention.\n *\n * @typeParam C - This is inferred by the supplied role id\n * @param roleId - The role id to format\n */\nexport function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>` {\n\treturn `<@&${roleId}>`;\n}\n\n/**\n * Formats an application command name, subcommand group name, subcommand name, and id into an application command mention.\n *\n * @typeParam N - This is inferred by the supplied command name\n * @typeParam G - This is inferred by the supplied subcommand group name\n * @typeParam S - This is inferred by the supplied subcommand name\n * @typeParam I - This is inferred by the supplied command id\n * @param commandName - The application command name to format\n * @param subcommandGroupName - The subcommand group name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command id to format\n */\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends string,\n\tS extends string,\n\tI extends Snowflake,\n>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`;\n\n/**\n * Formats an application command name, subcommand name, and id into an application command mention.\n *\n * @typeParam N - This is inferred by the supplied command name\n * @typeParam S - This is inferred by the supplied subcommand name\n * @typeParam I - This is inferred by the supplied command id\n * @param commandName - The application command name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command id to format\n */\nexport function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(\n\tcommandName: N,\n\tsubcommandName: S,\n\tcommandId: I,\n): `</${N} ${S}:${I}>`;\n\n/**\n * Formats an application command name and id into an application command mention.\n *\n * @typeParam N - This is inferred by the supplied command name\n * @typeParam I - This is inferred by the supplied command id\n * @param commandName - The application command name to format\n * @param commandId - The application command id to format\n */\nexport function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(\n\tcommandName: N,\n\tcommandId: I,\n): `</${N}:${I}>`;\n\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends Snowflake | string,\n\tS extends Snowflake | string,\n\tI extends Snowflake,\n>(\n\tcommandName: N,\n\tsubcommandGroupName: G,\n\tsubcommandName?: S,\n\tcommandId?: I,\n): `</${N} ${G} ${S}:${I}>` | `</${N} ${G}:${S}>` | `</${N}:${G}>` {\n\tif (commandId !== undefined) {\n\t\treturn `</${commandName} ${subcommandGroupName} ${subcommandName!}:${commandId}>`;\n\t}\n\n\tif (subcommandName !== undefined) {\n\t\treturn `</${commandName} ${subcommandGroupName}:${subcommandName}>`;\n\t}\n\n\treturn `</${commandName}:${subcommandGroupName}>`;\n}\n\n/**\n * Formats a non-animated emoji id into a fully qualified emoji identifier.\n *\n * @typeParam C - This is inferred by the supplied emoji id\n * @param emojiId - The emoji id to format\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`;\n\n/**\n * Formats an animated emoji id into a fully qualified emoji identifier.\n *\n * @typeParam C - This is inferred by the supplied emoji id\n * @param emojiId - The emoji id to format\n * @param animated - Whether the emoji is animated\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`;\n\n/**\n * Formats an emoji id into a fully qualified emoji identifier.\n *\n * @typeParam C - This is inferred by the supplied emoji id\n * @param emojiId - The emoji id to format\n * @param animated - Whether the emoji is animated\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`;\n\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated = false): `<:_:${C}>` | `<a:_:${C}>` {\n\treturn `<${animated ? 'a' : ''}:_:${emojiId}>`;\n}\n\n/**\n * Formats a channel link for a direct message channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @param channelId - The channel's id\n */\nexport function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`;\n\n/**\n * Formats a channel link for a guild channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @typeParam G - This is inferred by the supplied guild id\n * @param channelId - The channel's id\n * @param guildId - The guild's id\n */\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}`;\n\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}` | `https://discord.com/channels/${G}/${C}` {\n\treturn `https://discord.com/channels/${guildId ?? '@me'}/${channelId}`;\n}\n\n/**\n * Formats a message link for a direct message channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @typeParam M - This is inferred by the supplied message id\n * @param channelId - The channel's id\n * @param messageId - The message's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n): `https://discord.com/channels/@me/${C}/${M}`;\n\n/**\n * Formats a message link for a guild channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @typeParam M - This is inferred by the supplied message id\n * @typeParam G - This is inferred by the supplied guild id\n * @param channelId - The channel's id\n * @param messageId - The message's id\n * @param guildId - The guild's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}/${M}`;\n\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}/${M}` | `https://discord.com/channels/${G}/${C}/${M}` {\n\treturn `${guildId === undefined ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`;\n}\n\n/**\n * Formats a date into a short date-time string.\n *\n * @param date - The date to format. Defaults to the current time\n */\nexport function time(date?: Date): `<t:${bigint}>`;\n\n/**\n * Formats a date given a format style.\n *\n * @typeParam S - This is inferred by the supplied {@link TimestampStylesString}\n * @param date - The date to format\n * @param style - The style to use\n */\nexport function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`;\n\n/**\n * Formats the given timestamp into a short date-time string.\n *\n * @typeParam C - This is inferred by the supplied timestamp\n * @param seconds - A Unix timestamp in seconds\n */\nexport function time<C extends number>(seconds: C): `<t:${C}>`;\n\n/**\n * Formats the given timestamp into a short date-time string.\n *\n * @typeParam C - This is inferred by the supplied timestamp\n * @typeParam S - This is inferred by the supplied {@link TimestampStylesString}\n * @param seconds - A Unix timestamp in seconds\n * @param style - The style to use\n */\nexport function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`;\n\nexport function time(timeOrSeconds?: Date | number, style?: TimestampStylesString): string {\n\tif (typeof timeOrSeconds !== 'number') {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\ttimeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1_000);\n\t}\n\n\treturn typeof style === 'string' ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`;\n}\n\n/**\n * The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles}\n * supported by Discord.\n */\nexport const TimestampStyles = {\n\t/**\n\t * Short time format, consisting of hours and minutes.\n\t *\n\t * @example `16:20`\n\t */\n\tShortTime: 't',\n\n\t/**\n\t * Long time format, consisting of hours, minutes, and seconds.\n\t *\n\t * @example `16:20:30`\n\t */\n\tLongTime: 'T',\n\n\t/**\n\t * Short date format, consisting of day, month, and year.\n\t *\n\t * @example `20/04/2021`\n\t */\n\tShortDate: 'd',\n\n\t/**\n\t * Long date format, consisting of day, month, and year.\n\t *\n\t * @example `20 April 2021`\n\t */\n\tLongDate: 'D',\n\n\t/**\n\t * Short date-time format, consisting of short date and short time formats.\n\t *\n\t * @example `20 April 2021 16:20`\n\t */\n\tShortDateTime: 'f',\n\n\t/**\n\t * Long date-time format, consisting of long date and short time formats.\n\t *\n\t * @example `Tuesday, 20 April 2021 16:20`\n\t */\n\tLongDateTime: 'F',\n\n\t/**\n\t * Relative time format, consisting of a relative duration format.\n\t *\n\t * @example `2 months ago`\n\t */\n\tRelativeTime: 'R',\n} as const satisfies Record<string, string>;\n\n/**\n * The possible {@link TimestampStyles} values.\n */\nexport type TimestampStylesString = (typeof TimestampStyles)[keyof typeof TimestampStyles];\n\n// prettier-ignore\n/**\n * All the available faces from Discord's native slash commands.\n */\nexport enum Faces {\n\t/**\n\t * `¯\\_(ツ)_/¯`\n\t */\n\t// eslint-disable-next-line no-useless-escape\n\tShrug = '¯\\_(ツ)_/¯',\n\n\t/**\n\t * `(╯°□°)╯︵ ┻━┻`\n\t */\n\tTableflip = '(╯°□°)╯︵ ┻━┻',\n\n\t/**\n\t * `┬─┬ノ( º _ ºノ)`\n\t */\n\tUnflip = '┬─┬ノ( º _ ºノ)',\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AK,IAAI,SAAS;AACrE;AALgB;AAoCT,SAAS,YACf,WACA,WACA,SAC+F;AAC/F,SAAO,GAAG,YAAY,SAAY,YAAY,SAAS,IAAI,YAAY,WAAW,OAAO,CAAC,IAAI,SAAS;AACxG;AANgB;AA0CT,SAAS,KAAK,eAA+B,OAAuC;AAC1F,MAAI,OAAO,kBAAkB,UAAU;AAEtC,oBAAgB,KAAK,OAAO,eAAe,QAAQ,KAAK,KAAK,IAAI,KAAK,GAAK;AAAA,EAC5E;AAEA,SAAO,OAAO,UAAU,WAAW,MAAM,aAAa,IAAI,KAAK,MAAM,MAAM,aAAa;AACzF;AAPgB;AAaT,IAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM9B,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOX,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOV,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOX,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOV,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOf,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOd,cAAc;AACf;AAWO,IAAK,QAAL,kBAAKC,WAAL;AAKN,EAAAA,OAAA,WAAQ;AAKR,EAAAA,OAAA,eAAY;AAKZ,EAAAA,OAAA,YAAS;AAfE,SAAAA;AAAA,GAAA;","names":["codeBlock","inlineCode","bold","italic","strikethrough","spoiler","Faces"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/formatters/dist/index.mjs b/node_modules/@discordjs/formatters/dist/index.mjs new file mode 100644 index 0000000..82a6f65 --- /dev/null +++ b/node_modules/@discordjs/formatters/dist/index.mjs @@ -0,0 +1,335 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); + +// src/escapers.ts +function escapeMarkdown(text, options = {}) { + const { + codeBlock: codeBlock2 = true, + inlineCode: inlineCode2 = true, + bold: bold2 = true, + italic: italic2 = true, + underline = true, + strikethrough: strikethrough2 = true, + spoiler: spoiler2 = true, + codeBlockContent = true, + inlineCodeContent = true, + escape = true, + heading = false, + bulletedList = false, + numberedList = false, + maskedLink = false + } = options; + if (!codeBlockContent) { + return text.split("```").map((subString, index, array) => { + if (index % 2 && index !== array.length - 1) + return subString; + return escapeMarkdown(subString, { + inlineCode: inlineCode2, + bold: bold2, + italic: italic2, + underline, + strikethrough: strikethrough2, + spoiler: spoiler2, + inlineCodeContent, + escape, + heading, + bulletedList, + numberedList, + maskedLink + }); + }).join(codeBlock2 ? "\\`\\`\\`" : "```"); + } + if (!inlineCodeContent) { + return text.split(/(?<=^|[^`])`(?=[^`]|$)/g).map((subString, index, array) => { + if (index % 2 && index !== array.length - 1) + return subString; + return escapeMarkdown(subString, { + codeBlock: codeBlock2, + bold: bold2, + italic: italic2, + underline, + strikethrough: strikethrough2, + spoiler: spoiler2, + escape, + heading, + bulletedList, + numberedList, + maskedLink + }); + }).join(inlineCode2 ? "\\`" : "`"); + } + let res = text; + if (escape) + res = escapeEscape(res); + if (inlineCode2) + res = escapeInlineCode(res); + if (codeBlock2) + res = escapeCodeBlock(res); + if (italic2) + res = escapeItalic(res); + if (bold2) + res = escapeBold(res); + if (underline) + res = escapeUnderline(res); + if (strikethrough2) + res = escapeStrikethrough(res); + if (spoiler2) + res = escapeSpoiler(res); + if (heading) + res = escapeHeading(res); + if (bulletedList) + res = escapeBulletedList(res); + if (numberedList) + res = escapeNumberedList(res); + if (maskedLink) + res = escapeMaskedLink(res); + return res; +} +__name(escapeMarkdown, "escapeMarkdown"); +function escapeCodeBlock(text) { + return text.replaceAll("```", "\\`\\`\\`"); +} +__name(escapeCodeBlock, "escapeCodeBlock"); +function escapeInlineCode(text) { + return text.replaceAll(/(?<=^|[^`])``?(?=[^`]|$)/g, (match) => match.length === 2 ? "\\`\\`" : "\\`"); +} +__name(escapeInlineCode, "escapeInlineCode"); +function escapeItalic(text) { + let idx = 0; + const newText = text.replaceAll(/(?<=^|[^*])\*([^*]|\*\*|$)/g, (_, match) => { + if (match === "**") + return ++idx % 2 ? `\\*${match}` : `${match}\\*`; + return `\\*${match}`; + }); + idx = 0; + return newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => { + if (match === "__") + return ++idx % 2 ? `\\_${match}` : `${match}\\_`; + return `\\_${match}`; + }); +} +__name(escapeItalic, "escapeItalic"); +function escapeBold(text) { + let idx = 0; + return text.replaceAll(/\*\*(\*)?/g, (_, match) => { + if (match) + return ++idx % 2 ? `${match}\\*\\*` : `\\*\\*${match}`; + return "\\*\\*"; + }); +} +__name(escapeBold, "escapeBold"); +function escapeUnderline(text) { + let idx = 0; + return text.replaceAll(/(?<!<a?:.+)__(_)?(?!:\d+>)/g, (_, match) => { + if (match) + return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`; + return "\\_\\_"; + }); +} +__name(escapeUnderline, "escapeUnderline"); +function escapeStrikethrough(text) { + return text.replaceAll("~~", "\\~\\~"); +} +__name(escapeStrikethrough, "escapeStrikethrough"); +function escapeSpoiler(text) { + return text.replaceAll("||", "\\|\\|"); +} +__name(escapeSpoiler, "escapeSpoiler"); +function escapeEscape(text) { + return text.replaceAll("\\", "\\\\"); +} +__name(escapeEscape, "escapeEscape"); +function escapeHeading(text) { + return text.replaceAll(/^( {0,2})([*-] )?( *)(#{1,3} )/gm, "$1$2$3\\$4"); +} +__name(escapeHeading, "escapeHeading"); +function escapeBulletedList(text) { + return text.replaceAll(/^( *)([*-])( +)/gm, "$1\\$2$3"); +} +__name(escapeBulletedList, "escapeBulletedList"); +function escapeNumberedList(text) { + return text.replaceAll(/^( *\d+)\./gm, "$1\\."); +} +__name(escapeNumberedList, "escapeNumberedList"); +function escapeMaskedLink(text) { + return text.replaceAll(/\[.+]\(.+\)/gm, "\\$&"); +} +__name(escapeMaskedLink, "escapeMaskedLink"); + +// src/formatters.ts +function codeBlock(language, content) { + return content === void 0 ? `\`\`\` +${language} +\`\`\`` : `\`\`\`${language} +${content} +\`\`\``; +} +__name(codeBlock, "codeBlock"); +function inlineCode(content) { + return `\`${content}\``; +} +__name(inlineCode, "inlineCode"); +function italic(content) { + return `_${content}_`; +} +__name(italic, "italic"); +function bold(content) { + return `**${content}**`; +} +__name(bold, "bold"); +function underscore(content) { + return `__${content}__`; +} +__name(underscore, "underscore"); +function strikethrough(content) { + return `~~${content}~~`; +} +__name(strikethrough, "strikethrough"); +function quote(content) { + return `> ${content}`; +} +__name(quote, "quote"); +function blockQuote(content) { + return `>>> ${content}`; +} +__name(blockQuote, "blockQuote"); +function hideLinkEmbed(url) { + return `<${url}>`; +} +__name(hideLinkEmbed, "hideLinkEmbed"); +function hyperlink(content, url, title) { + return title ? `[${content}](${url} "${title}")` : `[${content}](${url})`; +} +__name(hyperlink, "hyperlink"); +function spoiler(content) { + return `||${content}||`; +} +__name(spoiler, "spoiler"); +function userMention(userId) { + return `<@${userId}>`; +} +__name(userMention, "userMention"); +function channelMention(channelId) { + return `<#${channelId}>`; +} +__name(channelMention, "channelMention"); +function roleMention(roleId) { + return `<@&${roleId}>`; +} +__name(roleMention, "roleMention"); +function chatInputApplicationCommandMention(commandName, subcommandGroupName, subcommandName, commandId) { + if (commandId !== void 0) { + return `</${commandName} ${subcommandGroupName} ${subcommandName}:${commandId}>`; + } + if (subcommandName !== void 0) { + return `</${commandName} ${subcommandGroupName}:${subcommandName}>`; + } + return `</${commandName}:${subcommandGroupName}>`; +} +__name(chatInputApplicationCommandMention, "chatInputApplicationCommandMention"); +function formatEmoji(emojiId, animated = false) { + return `<${animated ? "a" : ""}:_:${emojiId}>`; +} +__name(formatEmoji, "formatEmoji"); +function channelLink(channelId, guildId) { + return `https://discord.com/channels/${guildId ?? "@me"}/${channelId}`; +} +__name(channelLink, "channelLink"); +function messageLink(channelId, messageId, guildId) { + return `${guildId === void 0 ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`; +} +__name(messageLink, "messageLink"); +function time(timeOrSeconds, style) { + if (typeof timeOrSeconds !== "number") { + timeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1e3); + } + return typeof style === "string" ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`; +} +__name(time, "time"); +var TimestampStyles = { + /** + * Short time format, consisting of hours and minutes. + * + * @example `16:20` + */ + ShortTime: "t", + /** + * Long time format, consisting of hours, minutes, and seconds. + * + * @example `16:20:30` + */ + LongTime: "T", + /** + * Short date format, consisting of day, month, and year. + * + * @example `20/04/2021` + */ + ShortDate: "d", + /** + * Long date format, consisting of day, month, and year. + * + * @example `20 April 2021` + */ + LongDate: "D", + /** + * Short date-time format, consisting of short date and short time formats. + * + * @example `20 April 2021 16:20` + */ + ShortDateTime: "f", + /** + * Long date-time format, consisting of long date and short time formats. + * + * @example `Tuesday, 20 April 2021 16:20` + */ + LongDateTime: "F", + /** + * Relative time format, consisting of a relative duration format. + * + * @example `2 months ago` + */ + RelativeTime: "R" +}; +var Faces = /* @__PURE__ */ ((Faces2) => { + Faces2["Shrug"] = "\xAF_(\u30C4)_/\xAF"; + Faces2["Tableflip"] = "(\u256F\xB0\u25A1\xB0)\u256F\uFE35 \u253B\u2501\u253B"; + Faces2["Unflip"] = "\u252C\u2500\u252C\u30CE( \xBA _ \xBA\u30CE)"; + return Faces2; +})(Faces || {}); +export { + Faces, + TimestampStyles, + blockQuote, + bold, + channelLink, + channelMention, + chatInputApplicationCommandMention, + codeBlock, + escapeBold, + escapeBulletedList, + escapeCodeBlock, + escapeEscape, + escapeHeading, + escapeInlineCode, + escapeItalic, + escapeMarkdown, + escapeMaskedLink, + escapeNumberedList, + escapeSpoiler, + escapeStrikethrough, + escapeUnderline, + formatEmoji, + hideLinkEmbed, + hyperlink, + inlineCode, + italic, + messageLink, + quote, + roleMention, + spoiler, + strikethrough, + time, + underscore, + userMention +}; +//# sourceMappingURL=index.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/formatters/dist/index.mjs.map b/node_modules/@discordjs/formatters/dist/index.mjs.map new file mode 100644 index 0000000..ca8202d --- /dev/null +++ b/node_modules/@discordjs/formatters/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/escapers.ts","../src/formatters.ts"],"sourcesContent":["/* eslint-disable prefer-named-capture-group */\n\n/**\n * The options that affect what will be escaped.\n */\nexport interface EscapeMarkdownOptions {\n\t/**\n\t * Whether to escape bold text.\n\t *\n\t * @defaultValue `true`\n\t */\n\tbold?: boolean;\n\n\t/**\n\t * Whether to escape bulleted lists.\n\t *\n\t * @defaultValue `false`\n\t */\n\tbulletedList?: boolean;\n\n\t/**\n\t * Whether to escape code blocks.\n\t *\n\t * @defaultValue `true`\n\t */\n\tcodeBlock?: boolean;\n\n\t/**\n\t * Whether to escape text inside code blocks.\n\t *\n\t * @defaultValue `true`\n\t */\n\tcodeBlockContent?: boolean;\n\n\t/**\n\t * Whether to escape `\\`.\n\t *\n\t * @defaultValue `true`\n\t */\n\tescape?: boolean;\n\n\t/**\n\t * Whether to escape headings.\n\t *\n\t * @defaultValue `false`\n\t */\n\theading?: boolean;\n\n\t/**\n\t * Whether to escape inline code.\n\t *\n\t * @defaultValue `true`\n\t */\n\tinlineCode?: boolean;\n\n\t/**\n\t * Whether to escape text inside inline code.\n\t *\n\t * @defaultValue `true`\n\t */\n\tinlineCodeContent?: boolean;\n\t/**\n\t * Whether to escape italics.\n\t *\n\t * @defaultValue `true`\n\t */\n\titalic?: boolean;\n\n\t/**\n\t * Whether to escape masked links.\n\t *\n\t * @defaultValue `false`\n\t */\n\tmaskedLink?: boolean;\n\n\t/**\n\t * Whether to escape numbered lists.\n\t *\n\t * @defaultValue `false`\n\t */\n\tnumberedList?: boolean;\n\n\t/**\n\t * Whether to escape spoilers.\n\t *\n\t * @defaultValue `true`\n\t */\n\tspoiler?: boolean;\n\n\t/**\n\t * Whether to escape strikethroughs.\n\t *\n\t * @defaultValue `true`\n\t */\n\tstrikethrough?: boolean;\n\n\t/**\n\t * Whether to escape underlines.\n\t *\n\t * @defaultValue `true`\n\t */\n\tunderline?: boolean;\n}\n\n/**\n * Escapes any Discord-flavored markdown in a string.\n *\n * @param text - Content to escape\n * @param options - Options for escaping the markdown\n */\nexport function escapeMarkdown(text: string, options: EscapeMarkdownOptions = {}): string {\n\tconst {\n\t\tcodeBlock = true,\n\t\tinlineCode = true,\n\t\tbold = true,\n\t\titalic = true,\n\t\tunderline = true,\n\t\tstrikethrough = true,\n\t\tspoiler = true,\n\t\tcodeBlockContent = true,\n\t\tinlineCodeContent = true,\n\t\tescape = true,\n\t\theading = false,\n\t\tbulletedList = false,\n\t\tnumberedList = false,\n\t\tmaskedLink = false,\n\t} = options;\n\n\tif (!codeBlockContent) {\n\t\treturn text\n\t\t\t.split('```')\n\t\t\t.map((subString, index, array) => {\n\t\t\t\tif (index % 2 && index !== array.length - 1) return subString;\n\t\t\t\treturn escapeMarkdown(subString, {\n\t\t\t\t\tinlineCode,\n\t\t\t\t\tbold,\n\t\t\t\t\titalic,\n\t\t\t\t\tunderline,\n\t\t\t\t\tstrikethrough,\n\t\t\t\t\tspoiler,\n\t\t\t\t\tinlineCodeContent,\n\t\t\t\t\tescape,\n\t\t\t\t\theading,\n\t\t\t\t\tbulletedList,\n\t\t\t\t\tnumberedList,\n\t\t\t\t\tmaskedLink,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.join(codeBlock ? '\\\\`\\\\`\\\\`' : '```');\n\t}\n\n\tif (!inlineCodeContent) {\n\t\treturn text\n\t\t\t.split(/(?<=^|[^`])`(?=[^`]|$)/g)\n\t\t\t.map((subString, index, array) => {\n\t\t\t\tif (index % 2 && index !== array.length - 1) return subString;\n\t\t\t\treturn escapeMarkdown(subString, {\n\t\t\t\t\tcodeBlock,\n\t\t\t\t\tbold,\n\t\t\t\t\titalic,\n\t\t\t\t\tunderline,\n\t\t\t\t\tstrikethrough,\n\t\t\t\t\tspoiler,\n\t\t\t\t\tescape,\n\t\t\t\t\theading,\n\t\t\t\t\tbulletedList,\n\t\t\t\t\tnumberedList,\n\t\t\t\t\tmaskedLink,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.join(inlineCode ? '\\\\`' : '`');\n\t}\n\n\tlet res = text;\n\tif (escape) res = escapeEscape(res);\n\tif (inlineCode) res = escapeInlineCode(res);\n\tif (codeBlock) res = escapeCodeBlock(res);\n\tif (italic) res = escapeItalic(res);\n\tif (bold) res = escapeBold(res);\n\tif (underline) res = escapeUnderline(res);\n\tif (strikethrough) res = escapeStrikethrough(res);\n\tif (spoiler) res = escapeSpoiler(res);\n\tif (heading) res = escapeHeading(res);\n\tif (bulletedList) res = escapeBulletedList(res);\n\tif (numberedList) res = escapeNumberedList(res);\n\tif (maskedLink) res = escapeMaskedLink(res);\n\treturn res;\n}\n\n/**\n * Escapes code block markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeCodeBlock(text: string): string {\n\treturn text.replaceAll('```', '\\\\`\\\\`\\\\`');\n}\n\n/**\n * Escapes inline code markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeInlineCode(text: string): string {\n\treturn text.replaceAll(/(?<=^|[^`])``?(?=[^`]|$)/g, (match) => (match.length === 2 ? '\\\\`\\\\`' : '\\\\`'));\n}\n\n/**\n * Escapes italic markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeItalic(text: string): string {\n\tlet idx = 0;\n\tconst newText = text.replaceAll(/(?<=^|[^*])\\*([^*]|\\*\\*|$)/g, (_, match) => {\n\t\tif (match === '**') return ++idx % 2 ? `\\\\*${match}` : `${match}\\\\*`;\n\t\treturn `\\\\*${match}`;\n\t});\n\tidx = 0;\n\treturn newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+)_(?!:\\d+>)([^_]|__|$)/g, (_, match) => {\n\t\tif (match === '__') return ++idx % 2 ? `\\\\_${match}` : `${match}\\\\_`;\n\t\treturn `\\\\_${match}`;\n\t});\n}\n\n/**\n * Escapes bold markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeBold(text: string): string {\n\tlet idx = 0;\n\treturn text.replaceAll(/\\*\\*(\\*)?/g, (_, match) => {\n\t\tif (match) return ++idx % 2 ? `${match}\\\\*\\\\*` : `\\\\*\\\\*${match}`;\n\t\treturn '\\\\*\\\\*';\n\t});\n}\n\n/**\n * Escapes underline markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeUnderline(text: string): string {\n\tlet idx = 0;\n\treturn text.replaceAll(/(?<!<a?:.+)__(_)?(?!:\\d+>)/g, (_, match) => {\n\t\tif (match) return ++idx % 2 ? `${match}\\\\_\\\\_` : `\\\\_\\\\_${match}`;\n\t\treturn '\\\\_\\\\_';\n\t});\n}\n\n/**\n * Escapes strikethrough markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeStrikethrough(text: string): string {\n\treturn text.replaceAll('~~', '\\\\~\\\\~');\n}\n\n/**\n * Escapes spoiler markdown in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeSpoiler(text: string): string {\n\treturn text.replaceAll('||', '\\\\|\\\\|');\n}\n\n/**\n * Escapes escape characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeEscape(text: string): string {\n\treturn text.replaceAll('\\\\', '\\\\\\\\');\n}\n\n/**\n * Escapes heading characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeHeading(text: string): string {\n\treturn text.replaceAll(/^( {0,2})([*-] )?( *)(#{1,3} )/gm, '$1$2$3\\\\$4');\n}\n\n/**\n * Escapes bulleted list characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeBulletedList(text: string): string {\n\treturn text.replaceAll(/^( *)([*-])( +)/gm, '$1\\\\$2$3');\n}\n\n/**\n * Escapes numbered list characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeNumberedList(text: string): string {\n\treturn text.replaceAll(/^( *\\d+)\\./gm, '$1\\\\.');\n}\n\n/**\n * Escapes masked link characters in a string.\n *\n * @param text - Content to escape\n */\nexport function escapeMaskedLink(text: string): string {\n\treturn text.replaceAll(/\\[.+]\\(.+\\)/gm, '\\\\$&');\n}\n","import type { URL } from 'node:url';\nimport type { Snowflake } from 'discord-api-types/globals';\n\n/**\n * Wraps the content inside a code block with no language.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function codeBlock<C extends string>(content: C): `\\`\\`\\`\\n${C}\\n\\`\\`\\``;\n\n/**\n * Wraps the content inside a code block with the specified language.\n *\n * @typeParam L - This is inferred by the supplied language\n * @typeParam C - This is inferred by the supplied content\n * @param language - The language for the code block\n * @param content - The content to wrap\n */\nexport function codeBlock<L extends string, C extends string>(language: L, content: C): `\\`\\`\\`${L}\\n${C}\\n\\`\\`\\``;\n\nexport function codeBlock(language: string, content?: string): string {\n\treturn content === undefined ? `\\`\\`\\`\\n${language}\\n\\`\\`\\`` : `\\`\\`\\`${language}\\n${content}\\n\\`\\`\\``;\n}\n\n/**\n * Wraps the content inside \\`backticks\\` which formats it as inline code.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function inlineCode<C extends string>(content: C): `\\`${C}\\`` {\n\treturn `\\`${content}\\``;\n}\n\n/**\n * Formats the content into italic text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function italic<C extends string>(content: C): `_${C}_` {\n\treturn `_${content}_`;\n}\n\n/**\n * Formats the content into bold text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function bold<C extends string>(content: C): `**${C}**` {\n\treturn `**${content}**`;\n}\n\n/**\n * Formats the content into underscored text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function underscore<C extends string>(content: C): `__${C}__` {\n\treturn `__${content}__`;\n}\n\n/**\n * Formats the content into strike-through text.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function strikethrough<C extends string>(content: C): `~~${C}~~` {\n\treturn `~~${content}~~`;\n}\n\n/**\n * Formats the content into a quote.\n *\n * @remarks This needs to be at the start of the line for Discord to format it.\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function quote<C extends string>(content: C): `> ${C}` {\n\treturn `> ${content}`;\n}\n\n/**\n * Formats the content into a block quote.\n *\n * @remarks This needs to be at the start of the line for Discord to format it.\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function blockQuote<C extends string>(content: C): `>>> ${C}` {\n\treturn `>>> ${content}`;\n}\n\n/**\n * Wraps the URL into `<>` which stops it from embedding.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed<C extends string>(url: C): `<${C}>`;\n\n/**\n * Wraps the URL into `<>` which stops it from embedding.\n *\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed(url: URL): `<${string}>`;\n\nexport function hideLinkEmbed(url: URL | string) {\n\treturn `<${url}>`;\n}\n\n/**\n * Formats the content and the URL into a masked URL.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`;\n\n/**\n * Formats the content and the URL into a masked URL.\n *\n * @typeParam C - This is inferred by the supplied content\n * @typeParam U - This is inferred by the supplied URL\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`;\n\n/**\n * Formats the content and the URL into a masked URL with a custom tooltip.\n *\n * @typeParam C - This is inferred by the supplied content\n * @typeParam T - This is inferred by the supplied title\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, T extends string>(\n\tcontent: C,\n\turl: URL,\n\ttitle: T,\n): `[${C}](${string} \"${T}\")`;\n\n/**\n * Formats the content and the URL into a masked URL with a custom tooltip.\n *\n * @typeParam C - This is inferred by the supplied content\n * @typeParam U - This is inferred by the supplied URL\n * @typeParam T - This is inferred by the supplied title\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, U extends string, T extends string>(\n\tcontent: C,\n\turl: U,\n\ttitle: T,\n): `[${C}](${U} \"${T}\")`;\n\nexport function hyperlink(content: string, url: URL | string, title?: string) {\n\treturn title ? `[${content}](${url} \"${title}\")` : `[${content}](${url})`;\n}\n\n/**\n * Formats the content into a spoiler.\n *\n * @typeParam C - This is inferred by the supplied content\n * @param content - The content to wrap\n */\nexport function spoiler<C extends string>(content: C): `||${C}||` {\n\treturn `||${content}||`;\n}\n\n/**\n * Formats a user id into a user mention.\n *\n * @typeParam C - This is inferred by the supplied user id\n * @param userId - The user id to format\n */\nexport function userMention<C extends Snowflake>(userId: C): `<@${C}>` {\n\treturn `<@${userId}>`;\n}\n\n/**\n * Formats a channel id into a channel mention.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @param channelId - The channel id to format\n */\nexport function channelMention<C extends Snowflake>(channelId: C): `<#${C}>` {\n\treturn `<#${channelId}>`;\n}\n\n/**\n * Formats a role id into a role mention.\n *\n * @typeParam C - This is inferred by the supplied role id\n * @param roleId - The role id to format\n */\nexport function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>` {\n\treturn `<@&${roleId}>`;\n}\n\n/**\n * Formats an application command name, subcommand group name, subcommand name, and id into an application command mention.\n *\n * @typeParam N - This is inferred by the supplied command name\n * @typeParam G - This is inferred by the supplied subcommand group name\n * @typeParam S - This is inferred by the supplied subcommand name\n * @typeParam I - This is inferred by the supplied command id\n * @param commandName - The application command name to format\n * @param subcommandGroupName - The subcommand group name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command id to format\n */\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends string,\n\tS extends string,\n\tI extends Snowflake,\n>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`;\n\n/**\n * Formats an application command name, subcommand name, and id into an application command mention.\n *\n * @typeParam N - This is inferred by the supplied command name\n * @typeParam S - This is inferred by the supplied subcommand name\n * @typeParam I - This is inferred by the supplied command id\n * @param commandName - The application command name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command id to format\n */\nexport function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(\n\tcommandName: N,\n\tsubcommandName: S,\n\tcommandId: I,\n): `</${N} ${S}:${I}>`;\n\n/**\n * Formats an application command name and id into an application command mention.\n *\n * @typeParam N - This is inferred by the supplied command name\n * @typeParam I - This is inferred by the supplied command id\n * @param commandName - The application command name to format\n * @param commandId - The application command id to format\n */\nexport function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(\n\tcommandName: N,\n\tcommandId: I,\n): `</${N}:${I}>`;\n\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends Snowflake | string,\n\tS extends Snowflake | string,\n\tI extends Snowflake,\n>(\n\tcommandName: N,\n\tsubcommandGroupName: G,\n\tsubcommandName?: S,\n\tcommandId?: I,\n): `</${N} ${G} ${S}:${I}>` | `</${N} ${G}:${S}>` | `</${N}:${G}>` {\n\tif (commandId !== undefined) {\n\t\treturn `</${commandName} ${subcommandGroupName} ${subcommandName!}:${commandId}>`;\n\t}\n\n\tif (subcommandName !== undefined) {\n\t\treturn `</${commandName} ${subcommandGroupName}:${subcommandName}>`;\n\t}\n\n\treturn `</${commandName}:${subcommandGroupName}>`;\n}\n\n/**\n * Formats a non-animated emoji id into a fully qualified emoji identifier.\n *\n * @typeParam C - This is inferred by the supplied emoji id\n * @param emojiId - The emoji id to format\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`;\n\n/**\n * Formats an animated emoji id into a fully qualified emoji identifier.\n *\n * @typeParam C - This is inferred by the supplied emoji id\n * @param emojiId - The emoji id to format\n * @param animated - Whether the emoji is animated\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`;\n\n/**\n * Formats an emoji id into a fully qualified emoji identifier.\n *\n * @typeParam C - This is inferred by the supplied emoji id\n * @param emojiId - The emoji id to format\n * @param animated - Whether the emoji is animated\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`;\n\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated = false): `<:_:${C}>` | `<a:_:${C}>` {\n\treturn `<${animated ? 'a' : ''}:_:${emojiId}>`;\n}\n\n/**\n * Formats a channel link for a direct message channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @param channelId - The channel's id\n */\nexport function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`;\n\n/**\n * Formats a channel link for a guild channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @typeParam G - This is inferred by the supplied guild id\n * @param channelId - The channel's id\n * @param guildId - The guild's id\n */\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}`;\n\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}` | `https://discord.com/channels/${G}/${C}` {\n\treturn `https://discord.com/channels/${guildId ?? '@me'}/${channelId}`;\n}\n\n/**\n * Formats a message link for a direct message channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @typeParam M - This is inferred by the supplied message id\n * @param channelId - The channel's id\n * @param messageId - The message's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n): `https://discord.com/channels/@me/${C}/${M}`;\n\n/**\n * Formats a message link for a guild channel.\n *\n * @typeParam C - This is inferred by the supplied channel id\n * @typeParam M - This is inferred by the supplied message id\n * @typeParam G - This is inferred by the supplied guild id\n * @param channelId - The channel's id\n * @param messageId - The message's id\n * @param guildId - The guild's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}/${M}`;\n\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}/${M}` | `https://discord.com/channels/${G}/${C}/${M}` {\n\treturn `${guildId === undefined ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`;\n}\n\n/**\n * Formats a date into a short date-time string.\n *\n * @param date - The date to format. Defaults to the current time\n */\nexport function time(date?: Date): `<t:${bigint}>`;\n\n/**\n * Formats a date given a format style.\n *\n * @typeParam S - This is inferred by the supplied {@link TimestampStylesString}\n * @param date - The date to format\n * @param style - The style to use\n */\nexport function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`;\n\n/**\n * Formats the given timestamp into a short date-time string.\n *\n * @typeParam C - This is inferred by the supplied timestamp\n * @param seconds - A Unix timestamp in seconds\n */\nexport function time<C extends number>(seconds: C): `<t:${C}>`;\n\n/**\n * Formats the given timestamp into a short date-time string.\n *\n * @typeParam C - This is inferred by the supplied timestamp\n * @typeParam S - This is inferred by the supplied {@link TimestampStylesString}\n * @param seconds - A Unix timestamp in seconds\n * @param style - The style to use\n */\nexport function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`;\n\nexport function time(timeOrSeconds?: Date | number, style?: TimestampStylesString): string {\n\tif (typeof timeOrSeconds !== 'number') {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\ttimeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1_000);\n\t}\n\n\treturn typeof style === 'string' ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`;\n}\n\n/**\n * The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles}\n * supported by Discord.\n */\nexport const TimestampStyles = {\n\t/**\n\t * Short time format, consisting of hours and minutes.\n\t *\n\t * @example `16:20`\n\t */\n\tShortTime: 't',\n\n\t/**\n\t * Long time format, consisting of hours, minutes, and seconds.\n\t *\n\t * @example `16:20:30`\n\t */\n\tLongTime: 'T',\n\n\t/**\n\t * Short date format, consisting of day, month, and year.\n\t *\n\t * @example `20/04/2021`\n\t */\n\tShortDate: 'd',\n\n\t/**\n\t * Long date format, consisting of day, month, and year.\n\t *\n\t * @example `20 April 2021`\n\t */\n\tLongDate: 'D',\n\n\t/**\n\t * Short date-time format, consisting of short date and short time formats.\n\t *\n\t * @example `20 April 2021 16:20`\n\t */\n\tShortDateTime: 'f',\n\n\t/**\n\t * Long date-time format, consisting of long date and short time formats.\n\t *\n\t * @example `Tuesday, 20 April 2021 16:20`\n\t */\n\tLongDateTime: 'F',\n\n\t/**\n\t * Relative time format, consisting of a relative duration format.\n\t *\n\t * @example `2 months ago`\n\t */\n\tRelativeTime: 'R',\n} as const satisfies Record<string, string>;\n\n/**\n * The possible {@link TimestampStyles} values.\n */\nexport type TimestampStylesString = (typeof TimestampStyles)[keyof typeof TimestampStyles];\n\n// prettier-ignore\n/**\n * All the available faces from Discord's native slash commands.\n */\nexport enum Faces {\n\t/**\n\t * `¯\\_(ツ)_/¯`\n\t */\n\t// eslint-disable-next-line no-useless-escape\n\tShrug = '¯\\_(ツ)_/¯',\n\n\t/**\n\t * `(╯°□°)╯︵ ┻━┻`\n\t */\n\tTableflip = '(╯°□°)╯︵ ┻━┻',\n\n\t/**\n\t * `┬─┬ノ( º _ ºノ)`\n\t */\n\tUnflip = '┬─┬ノ( º _ ºノ)',\n}\n"],"mappings":";;;;AA8GO,SAAS,eAAe,MAAc,UAAiC,CAAC,GAAW;AACzF,QAAM;AAAA,IACL,WAAAA,aAAY;AAAA,IACZ,YAAAC,cAAa;AAAA,IACb,MAAAC,QAAO;AAAA,IACP,QAAAC,UAAS;AAAA,IACT,YAAY;AAAA,IACZ,eAAAC,iBAAgB;AAAA,IAChB,SAAAC,WAAU;AAAA,IACV,mBAAmB;AAAA,IACnB,o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AAAA;AAAA;AAAA;AAAA,EAM9B,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOX,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOV,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOX,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOV,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOf,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOd,cAAc;AACf;AAWO,IAAK,QAAL,kBAAKC,WAAL;AAKN,EAAAA,OAAA,WAAQ;AAKR,EAAAA,OAAA,eAAY;AAKZ,EAAAA,OAAA,YAAS;AAfE,SAAAA;AAAA,GAAA;","names":["codeBlock","inlineCode","bold","italic","strikethrough","spoiler","Faces"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/formatters/package.json b/node_modules/@discordjs/formatters/package.json new file mode 100644 index 0000000..3f63f9e --- /dev/null +++ b/node_modules/@discordjs/formatters/package.json @@ -0,0 +1,72 @@ +{ + "name": "@discordjs/formatters", + "version": "0.3.2", + "description": "A set of functions to format strings for Discord.", + "scripts": { + "test": "vitest run", + "build": "tsup", + "build:docs": "tsc -p tsconfig.docs.json", + "lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --format=pretty", + "format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix --format=pretty", + "docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json", + "prepack": "yarn build && yarn lint", + "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/formatters/*'", + "release": "cliff-jumper" + }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "typings": "./dist/index.d.ts", + "exports": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "directories": { + "lib": "src", + "test": "__tests__" + }, + "files": [ + "dist" + ], + "contributors": [ + "Crawl <icrawltogo@gmail.com>", + "SpaceEEC <spaceeec@yahoo.com>", + "Vlad Frangu <kingdgrizzle@gmail.com>", + "Aura Román <kyradiscord@gmail.com>" + ], + "license": "Apache-2.0", + "keywords": [], + "repository": { + "type": "git", + "url": "https://github.com/discordjs/discord.js.git", + "directory": "packages/formatters" + }, + "bugs": { + "url": "https://github.com/discordjs/discord.js/issues" + }, + "homepage": "https://discord.js.org", + "dependencies": { + "discord-api-types": "0.37.50" + }, + "devDependencies": { + "@favware/cliff-jumper": "^2.1.1", + "@microsoft/api-extractor": "^7.36.4", + "@types/node": "16.18.40", + "@vitest/coverage-v8": "^0.34.2", + "cross-env": "^7.0.3", + "eslint": "^8.47.0", + "eslint-config-neon": "^0.1.47", + "eslint-formatter-pretty": "^5.0.0", + "prettier": "^2.8.8", + "tsup": "^7.2.0", + "turbo": "^1.10.12", + "typescript": "^5.1.6", + "vitest": "^0.34.2" + }, + "engines": { + "node": ">=16.11.0" + }, + "publishConfig": { + "access": "public" + } +}
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/CHANGELOG.md b/node_modules/@discordjs/rest/CHANGELOG.md new file mode 100644 index 0000000..aa5311f --- /dev/null +++ b/node_modules/@discordjs/rest/CHANGELOG.md @@ -0,0 +1,302 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +# [@discordjs/rest@2.0.1](https://github.com/discordjs/discord.js/compare/@discordjs/rest@2.0.0...@discordjs/rest@2.0.1) - (2023-08-17) + +## Documentation + +- Update Node.js requirement to 16.11.0 (#9764) ([188877c](https://github.com/discordjs/discord.js/commit/188877c50af70f0d5cffb246620fa277435c6ce6)) + +# [@discordjs/rest@2.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.7.1...@discordjs/rest@2.0.0) - (2023-07-31) + +## Features + +- No-de-no-de, now with extra buns (#9683) ([386f206](https://github.com/discordjs/discord.js/commit/386f206caf74a04c426799af9796ca96dcb37056)) + - **BREAKING CHANGE:** The REST and RequestManager classes now extend AsyncEventEmitter
+from `@vladfrangu/async_event_emitter`, which aids in cross-compatibility
+between Node, Deno, Bun, CF Workers, Vercel Functions, etc. + - **BREAKING CHANGE:** DefaultUserAgentAppendix has been adapted to support multiple
+different platforms (previously mentioned Deno, Bun, CF Workers, etc) + - **BREAKING CHANGE:** the entry point for `@discordjs/rest` will now differ
+in non-node-like environments (CF Workers, etc.) + - **Co-authored-by:** Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> + - **Co-authored-by:** Jiralite <33201955+Jiralite@users.noreply.github.com> + - **Co-authored-by:** suneettipirneni <suneettipirneni@icloud.com> +- User avatar decorations (#8914) ([8d97017](https://github.com/discordjs/discord.js/commit/8d9701745840e23854e8f0b057d21cb10e7d1d54)) +- Support new username system (#9512) ([1ab60f9](https://github.com/discordjs/discord.js/commit/1ab60f9da4d6b7ea144fa05b97b029a4bfaeede2)) + +## Refactor + +- **REST:** Remove double classing (#9722) ([8f4256d](https://github.com/discordjs/discord.js/commit/8f4256db8a52ac08359d0b3436f41b641ac4e382)) + - **BREAKING CHANGE:** `REST` and `RequestManager` have been combined, most of the properties, methods, and events from both classes can now be found on `REST` + - **BREAKING CHANGE:** `REST#raw` has been removed in favor of `REST#queueRequest` + - **BREAKING CHANGE:** `REST#getAgent` has been removed in favor of `REST#agent` + +* chore: update for /rest changes +- **rest:** Switch api to fetch-like and provide strategies (#9416) ([cdaa0a3](https://github.com/discordjs/discord.js/commit/cdaa0a36f586459f1e5ede868c4250c7da90455c)) + - **BREAKING CHANGE:** NodeJS v18+ is required when using node due to the use of global `fetch` + - **BREAKING CHANGE:** The raw method of REST now returns a web compatible `Respone` object. + - **BREAKING CHANGE:** The `parseResponse` utility method has been updated to operate on a web compatible `Response` object. + - **BREAKING CHANGE:** Many underlying internals have changed, some of which were exported. + - **BREAKING CHANGE:** `DefaultRestOptions` used to contain a default `agent`, which is now set to `null` instead. + +# [@discordjs/rest@1.7.1](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.7.0...@discordjs/rest@1.7.1) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Reference package names properly (#9426) ([d6bca9b](https://github.com/discordjs/discord.js/commit/d6bca9bb4d976dc069a5039250db7d5b3e9142ef)) +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/rest@2.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.7.1...@discordjs/rest@2.0.0) - (2023-07-31) + +## Features + +- No-de-no-de, now with extra buns (#9683) ([386f206](https://github.com/discordjs/discord.js/commit/386f206caf74a04c426799af9796ca96dcb37056)) + - **BREAKING CHANGE:** The REST and RequestManager classes now extend AsyncEventEmitter
+from `@vladfrangu/async_event_emitter`, which aids in cross-compatibility
+between Node, Deno, Bun, CF Workers, Vercel Functions, etc. + - **BREAKING CHANGE:** DefaultUserAgentAppendix has been adapted to support multiple
+different platforms (previously mentioned Deno, Bun, CF Workers, etc) + - **BREAKING CHANGE:** the entry point for `@discordjs/rest` will now differ
+in non-node-like environments (CF Workers, etc.) + - **Co-authored-by:** Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> + - **Co-authored-by:** Jiralite <33201955+Jiralite@users.noreply.github.com> + - **Co-authored-by:** suneettipirneni <suneettipirneni@icloud.com> +- User avatar decorations (#8914) ([8d97017](https://github.com/discordjs/discord.js/commit/8d9701745840e23854e8f0b057d21cb10e7d1d54)) +- Support new username system (#9512) ([1ab60f9](https://github.com/discordjs/discord.js/commit/1ab60f9da4d6b7ea144fa05b97b029a4bfaeede2)) + +## Refactor + +- **REST:** Remove double classing (#9722) ([8f4256d](https://github.com/discordjs/discord.js/commit/8f4256db8a52ac08359d0b3436f41b641ac4e382)) + - **BREAKING CHANGE:** `REST` and `RequestManager` have been combined, most of the properties, methods, and events from both classes can now be found on `REST` + - **BREAKING CHANGE:** `REST#raw` has been removed in favor of `REST#queueRequest` + - **BREAKING CHANGE:** `REST#getAgent` has been removed in favor of `REST#agent` + +* chore: update for /rest changes +- **rest:** Switch api to fetch-like and provide strategies (#9416) ([cdaa0a3](https://github.com/discordjs/discord.js/commit/cdaa0a36f586459f1e5ede868c4250c7da90455c)) + - **BREAKING CHANGE:** NodeJS v18+ is required when using node due to the use of global `fetch` + - **BREAKING CHANGE:** The raw method of REST now returns a web compatible `Respone` object. + - **BREAKING CHANGE:** The `parseResponse` utility method has been updated to operate on a web compatible `Response` object. + - **BREAKING CHANGE:** Many underlying internals have changed, some of which were exported. + - **BREAKING CHANGE:** `DefaultRestOptions` used to contain a default `agent`, which is now set to `null` instead. + +# [@discordjs/rest@1.7.1](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.7.0...@discordjs/rest@1.7.1) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Reference package names properly (#9426) ([d6bca9b](https://github.com/discordjs/discord.js/commit/d6bca9bb4d976dc069a5039250db7d5b3e9142ef)) +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/rest@1.7.1](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.7.0...@discordjs/rest@1.7.1) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Documentation + +- Reference package names properly (#9426) ([d6bca9b](https://github.com/discordjs/discord.js/commit/d6bca9bb4d976dc069a5039250db7d5b3e9142ef)) +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/rest@1.7.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.6.0...@discordjs/rest@1.7.0) - (2023-04-01) + +## Bug Fixes + +- **handlers:** Create burst handler for interaction callbacks (#8996) ([db8df10](https://github.com/discordjs/discord.js/commit/db8df104c5e70a12f35b54e5f3f7c897068dde6f)) +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) +- **rest:** Remove `const enum`s in favour of regular enums (#9243) ([229ad07](https://github.com/discordjs/discord.js/commit/229ad077ff52d8706d68ed4d31983619a32eba45)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/rest@1.6.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.5.0...@discordjs/rest@1.6.0) - (2023-03-12) + +## Bug Fixes + +- **snowflake:** Snowflakes length (#9144) ([955e8fe](https://github.com/discordjs/discord.js/commit/955e8fe312c42ad4937cc1994d1d81e517c413c8)) +- **RequestManager:** Inference of image/apng (#9014) ([ecb4281](https://github.com/discordjs/discord.js/commit/ecb4281d1e2d9a0a427605f75352cbf74ffb2d7c)) + +## Documentation + +- Fix typos (#9127) ([1ba1f23](https://github.com/discordjs/discord.js/commit/1ba1f238f04221ec890fc921678909b5b7d92c26)) +- Fix version export (#9049) ([8b70f49](https://github.com/discordjs/discord.js/commit/8b70f497a1207e30edebdecd12b926c981c13d28)) + +## Features + +- **Sticker:** Add support for gif stickers (#9038) ([6a9875d](https://github.com/discordjs/discord.js/commit/6a9875da054a875a4711394547d47439bbe66fb6)) +- **website:** Add support for source file links (#9048) ([f6506e9](https://github.com/discordjs/discord.js/commit/f6506e99c496683ee0ab67db0726b105b929af38)) + +## Styling + +- Run prettier (#9041) ([2798ba1](https://github.com/discordjs/discord.js/commit/2798ba1eb3d734f0cf2eeccd2e16cfba6804873b)) + +# [@discordjs/rest@1.5.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.4.0...@discordjs/rest@1.5.0) - (2022-12-16) + +## Features + +- **core:** Add support for role connections (#8930) ([3d6fa24](https://github.com/discordjs/discord.js/commit/3d6fa248c07b2278504bbe8bafa17a3294971fd9)) + +# [@discordjs/rest@1.4.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.3.0...@discordjs/rest@1.4.0) - (2022-11-28) + +## Bug Fixes + +- **SequentialHandler:** Downlevel ECONNRESET errors (#8785) ([5a70057](https://github.com/discordjs/discord.js/commit/5a70057826b47fb8251f3d836a536de689444ca1)) +- Make ratelimit timeout require event loop to be active (#8779) ([68d5712](https://github.com/discordjs/discord.js/commit/68d5712deae85532604d93b4505f0953d664cde7)) +- Pin @types/node version ([9d8179c](https://github.com/discordjs/discord.js/commit/9d8179c6a78e1c7f9976f852804055964d5385d4)) + +## Features + +- Add `@discordjs/core` (#8736) ([2127b32](https://github.com/discordjs/discord.js/commit/2127b32d26dedeb44ec43d16ec2e2046919f9bb0)) +- New select menus (#8793) ([5152abf](https://github.com/discordjs/discord.js/commit/5152abf7285581abf7689e9050fdc56c4abb1e2b)) + +## Refactor + +- Update `makeURLSearchParams` to accept readonly non-`Record`s (#8868) ([8376e2d](https://github.com/discordjs/discord.js/commit/8376e2dbcd38697ce62615d9a539fd198fbc4713)) + +# [@discordjs/rest@1.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.2.0...@discordjs/rest@1.3.0) - (2022-10-08) + +## Bug Fixes + +- **SequentialHandler:** Throw http error with proper name and more useful message (#8694) ([3f86561](https://github.com/discordjs/discord.js/commit/3f8656115bf9df0dbf8391de68a3401535325895)) + +## Features + +- Web-components (#8715) ([0ac3e76](https://github.com/discordjs/discord.js/commit/0ac3e766bd9dbdeb106483fa4bb085d74de346a2)) +- Add `@discordjs/util` (#8591) ([b2ec865](https://github.com/discordjs/discord.js/commit/b2ec865765bf94181473864a627fb63ea8173fd3)) +- Add `AbortSignal` support (#8672) ([3c231ae](https://github.com/discordjs/discord.js/commit/3c231ae81a52b66940ba495f35fd59a76c65e306)) + +# [@discordjs/rest@1.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.1.0...@discordjs/rest@1.2.0) - (2022-09-25) + +## Bug Fixes + +- Footer / sidebar / deprecation alert ([ba3e0ed](https://github.com/discordjs/discord.js/commit/ba3e0ed348258fe8e51eefb4aa7379a1230616a9)) + +## Documentation + +- Change name (#8604) ([dd5a089](https://github.com/discordjs/discord.js/commit/dd5a08944c258a847fc4377f1d5e953264ab47d0)) + +## Features + +- **rest:** Use Agent with higher connect timeout (#8679) ([64cd53c](https://github.com/discordjs/discord.js/commit/64cd53c4c23dd9c9503fd0887ac5c542137c57e8)) + +## Refactor + +- Website components (#8600) ([c334157](https://github.com/discordjs/discord.js/commit/c3341570d983aea9ecc419979d5a01de658c9d67)) +- Use `eslint-config-neon` for packages. (#8579) ([edadb9f](https://github.com/discordjs/discord.js/commit/edadb9fe5dfd9ff51a3cfc9b25cb242d3f9f5241)) + +# [@discordjs/rest@1.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@1.0.1...@discordjs/rest@1.1.0) - (2022-08-22) + +## Features + +- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007)) +- **website:** Render `@defaultValue` blocks (#8527) ([8028813](https://github.com/discordjs/discord.js/commit/8028813825e7708915ea892760c1003afd60df2f)) +- **WebSocketShard:** Support new resume url (#8480) ([bc06cc6](https://github.com/discordjs/discord.js/commit/bc06cc638d2f57ab5c600e8cdb6afc8eb2180166)) + +## Refactor + +- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e)) + +# [@discordjs/rest@0.6.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@0.5.0...@discordjs/rest@0.6.0) - (2022-07-17) + +## Documentation + +- Add codecov coverage badge to readmes (#8226) ([f6db285](https://github.com/discordjs/discord.js/commit/f6db285c073898a749fe4591cbd4463d1896daf5)) + +## Features + +- **builder:** Add max min length in string option (#8214) ([96c8d21](https://github.com/discordjs/discord.js/commit/96c8d21f95eb366c46ae23505ba9054f44821b25)) +- Codecov (#8219) ([f10f4cd](https://github.com/discordjs/discord.js/commit/f10f4cdcd88ca6be7ec735ed3a415ba13da83db0)) +- **docgen:** Update typedoc ([b3346f4](https://github.com/discordjs/discord.js/commit/b3346f4b9b3d4f96443506643d4631dc1c6d7b21)) +- Website (#8043) ([127931d](https://github.com/discordjs/discord.js/commit/127931d1df7a2a5c27923c2f2151dbf3824e50cc)) +- **docgen:** Typescript support ([3279b40](https://github.com/discordjs/discord.js/commit/3279b40912e6aa61507bedb7db15a2b8668de44b)) +- Docgen package (#8029) ([8b979c0](https://github.com/discordjs/discord.js/commit/8b979c0245c42fd824d8e98745ee869f5360fc86)) +- Use vitest instead of jest for more speed ([8d8e6c0](https://github.com/discordjs/discord.js/commit/8d8e6c03decd7352a2aa180f6e5bc1a13602539b)) +- Add scripts package for locally used scripts ([f2ae1f9](https://github.com/discordjs/discord.js/commit/f2ae1f9348bfd893332a9060f71a8a5f272a1b8b)) + +## Refactor + +- **rest:** Add content-type(s) to uploads (#8290) ([103a358](https://github.com/discordjs/discord.js/commit/103a3584c95a7b7f57fa62d47b86520d5ec32303)) +- **collection:** Remove default export (#8053) ([16810f3](https://github.com/discordjs/discord.js/commit/16810f3e410bf35ed7e6e7412d517ea74c792c5d)) +- Move all the config files to root (#8033) ([769ea0b](https://github.com/discordjs/discord.js/commit/769ea0bfe78c4f1d413c6b397c604ffe91e39c6a)) + +# [@discordjs/rest@0.5.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@0.4.0...@discordjs/rest@0.5.0) - (2022-06-04) + +## Bug Fixes + +- **REST:** Remove dom types (#7922) ([e92b17d](https://github.com/discordjs/discord.js/commit/e92b17d8555164ff259e524efc6a26675660e5c2)) +- Ok statusCode can be 200..299 (#7919) ([d1504f2](https://github.com/discordjs/discord.js/commit/d1504f2ae19816b3fadcdb3ad17facc863ed7529)) + +## Features + +- **rest:** Add guild member banner cdn url (#7973) ([97eaab3](https://github.com/discordjs/discord.js/commit/97eaab35d7383ecbbd93dc623ceda969286c1554)) +- REST#raw (#7929) ([dfe449c](https://github.com/discordjs/discord.js/commit/dfe449c253b617e8f92c720a2f71135aa1601a65)) +- **rest:** Use undici (#7747) ([d1ec8c3](https://github.com/discordjs/discord.js/commit/d1ec8c37ffb7fe3b63eaa8c382f22ca1fb348c9b)) +- **REST:** Enable setting default authPrefix (#7853) ([679dcda](https://github.com/discordjs/discord.js/commit/679dcda9709376f37cc58a60f74d12d324d93e4e)) + +## Styling + +- Cleanup tests and tsup configs ([6b8ef20](https://github.com/discordjs/discord.js/commit/6b8ef20cb3af5b5cfd176dd0aa0a1a1e98551629)) + +# [@discordjs/rest@0.4.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@0.3.0...@discordjs/rest@0.4.0) - (2022-04-17) + +## Bug Fixes + +- **gateway:** Use version 10 (#7689) ([8880de0](https://github.com/discordjs/discord.js/commit/8880de0cecdf273fd6df23988e4cb77774a75390)) +- **RequestHandler:** Only reset tokens for authenticated 401s (#7508) ([b9ff7b0](https://github.com/discordjs/discord.js/commit/b9ff7b057379a47ce13265f78e21bf0d55feaf0a)) +- **ci:** Ci error (#7454) ([0af9bc8](https://github.com/discordjs/discord.js/commit/0af9bc841ffe1a297d308500d696bad4b85abda9)) +- Use png as extension for defaultAvatarURL (#7414) ([538e9ce](https://github.com/discordjs/discord.js/commit/538e9cef459d00d74b9bd6852da3ce2acac9bae5)) +- **rest:** Sublimit all requests on unhandled routes (#7366) ([733ac82](https://github.com/discordjs/discord.js/commit/733ac82d5dffabc622fb59e06d06e83396734dc6)) +- Fix some typos (#7393) ([92a04f4](https://github.com/discordjs/discord.js/commit/92a04f4d98f6c6760214034cc8f5a1eaa78893c7)) + +## Documentation + +- Enhance /rest README (#7757) ([a1329bd](https://github.com/discordjs/discord.js/commit/a1329bd3ebafc6d5b5e2788ff082674f01b726f3)) + +## Features + +- Add `makeURLSearchParams` utility function (#7744) ([8eaec11](https://github.com/discordjs/discord.js/commit/8eaec114a98026024c21545988860c123948c55d)) +- Add API v10 support (#7477) ([72577c4](https://github.com/discordjs/discord.js/commit/72577c4bfd02524a27afb6ff4aebba9301a690d3)) +- Add support for module: NodeNext in TS and ESM (#7598) ([8f1986a](https://github.com/discordjs/discord.js/commit/8f1986a6aa98365e09b00e84ad5f9f354ab61f3d)) +- **builders:** Add attachment command option type (#7203) ([ae0f35f](https://github.com/discordjs/discord.js/commit/ae0f35f51d68dfa5a7dc43d161ef9365171debdb)) +- **cdn:** Add support for scheduled event image covers (#7335) ([ac26d9b](https://github.com/discordjs/discord.js/commit/ac26d9b1307d63e116b043505e5f925db7ed01aa)) + +## Refactor + +- **requestmanager:** Use timestampfrom (#7459) ([3298510](https://github.com/discordjs/discord.js/commit/32985109c3b7614d364007608f8c5af4bed753ae)) +- **files:** Remove redundant file property names (#7340) ([6725038](https://github.com/discordjs/discord.js/commit/67250382f99872a9edff99ebaa482ffa895b0c37)) + +# [@discordjs/rest@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/rest@0.2.0...@discordjs/rest@0.3.0) - (2022-01-24) + +## Bug Fixes + +- **rest:** Don't add empty query (#7308) ([d0fa5aa](https://github.com/discordjs/discord.js/commit/d0fa5aaa26d316608120bca3050e14eefbe2f93b)) +- **rest:** Use http agent when protocol is not https (#7309) ([d8ea572](https://github.com/discordjs/discord.js/commit/d8ea572fb8a51f2f6a902c4926e814017d115708)) +- `ref` delay for rate limited requests (#7239) ([ed0cfd9](https://github.com/discordjs/discord.js/commit/ed0cfd91edc3a2b23a34a8ecd9db38baa12b52fa)) + +## Documentation + +- Fix a typo and use milliseconds instead of ms (#7251) ([0dd56af](https://github.com/discordjs/discord.js/commit/0dd56afe1cdf16f1e7d9afe1f8c29c31d1833a25)) + +## Features + +- Rest hash and handler sweeping (#7255) ([3bb4829](https://github.com/discordjs/discord.js/commit/3bb48298004d292214c6cb8f927c2fea78a42952)) +- Rest docs (#7281) ([9054f2f](https://github.com/discordjs/discord.js/commit/9054f2f7ad7f246431e5f53403535bf301c27a80)) + +## Refactor + +- **files:** File data can be much more than buffer (#7238) ([86ab526](https://github.com/discordjs/discord.js/commit/86ab526d493415b14b79b51d08c3677897d219ee)) +- **rest:** Rename attachment to file (#7199) ([c969cbf](https://github.com/discordjs/discord.js/commit/c969cbf6524093757d47108b6a55e62dcb210e8b)) + +## Testing + +- **voice:** Fix tests ([62c74b8](https://github.com/discordjs/discord.js/commit/62c74b8333066465e5bd295b8b102b35a506751d)) diff --git a/node_modules/@discordjs/rest/LICENSE b/node_modules/@discordjs/rest/LICENSE new file mode 100644 index 0000000..f9d970e --- /dev/null +++ b/node_modules/@discordjs/rest/LICENSE @@ -0,0 +1,192 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "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 Noel Buechler +Copyright 2021 Vlad Frangu +Copyright 2021 Aura Román + +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. diff --git a/node_modules/@discordjs/rest/README.md b/node_modules/@discordjs/rest/README.md new file mode 100644 index 0000000..243b28c --- /dev/null +++ b/node_modules/@discordjs/rest/README.md @@ -0,0 +1,137 @@ +<div align="center"> + <br /> + <p> + <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a> + </p> + <br /> + <p> + <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a> + <a href="https://www.npmjs.com/package/@discordjs/rest"><img src="https://img.shields.io/npm/v/@discordjs/rest.svg?maxAge=3600" alt="npm version" /></a> + <a href="https://www.npmjs.com/package/@discordjs/rest"><img src="https://img.shields.io/npm/dt/@discordjs/rest.svg?maxAge=3600" alt="npm downloads" /></a> + <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Tests status" /></a> + <a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=rest" alt="Code coverage" /></a> + </p> + <p> + <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a> + <a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a> + </p> +</div> + +## About + +`@discordjs/rest` is a module that allows you to easily make REST requests to the Discord API. + +## Installation + +**Node.js 16.11.0 or newer is required.** + +Note: native fetch (not recommended) is unavailable in this node version, either use a newer node version or use the more performant `undiciRequest` strategy (default) + +```sh +npm install @discordjs/rest +yarn add @discordjs/rest +pnpm add @discordjs/rest +``` + +## Examples + +Install all required dependencies: + +```sh +npm install @discordjs/rest discord-api-types +yarn add @discordjs/rest discord-api-types +pnpm add @discordjs/rest discord-api-types +``` + +Send a basic message: + +```js +import { REST } from '@discordjs/rest'; +import { Routes } from 'discord-api-types/v10'; + +const rest = new REST({ version: '10' }).setToken(TOKEN); + +try { + await rest.post(Routes.channelMessages(CHANNEL_ID), { + body: { + content: 'A message via REST!', + }, + }); +} catch (error) { + console.error(error); +} +``` + +Create a thread from an existing message to be archived after 60 minutes of inactivity: + +```js +import { REST } from '@discordjs/rest'; +import { Routes } from 'discord-api-types/v10'; + +const rest = new REST({ version: '10' }).setToken(TOKEN); + +try { + await rest.post(Routes.threads(CHANNEL_ID, MESSAGE_ID), { + body: { + name: 'Thread', + auto_archive_duration: 60, + }, + }); +} catch (error) { + console.error(error); +} +``` + +Send a basic message in an edge environment: + +```js +import { REST } from '@discordjs/rest'; +import { Routes } from 'discord-api-types/v10'; + +const rest = new REST({ version: '10', makeRequest: fetch }).setToken(TOKEN); + +try { + await rest.post(Routes.channelMessages(CHANNEL_ID), { + body: { + content: 'A message via REST from the edge!', + }, + }); +} catch (error) { + console.error(error); +} +``` + +## Links + +- [Website][website] ([source][website-source]) +- [Documentation][documentation] +- [Guide][guide] ([source][guide-source]) + Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library. +- [discord.js Discord server][discord] +- [Discord API Discord server][discord-api] +- [GitHub][source] +- [npm][npm] +- [Related libraries][related-libs] + +## Contributing + +Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the +[documentation][documentation]. +See [the contribution guide][contributing] if you'd like to submit a PR. + +## Help + +If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord]. + +[website]: https://discord.js.org +[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website +[documentation]: https://discord.js.org/docs/packages/rest/stable +[guide]: https://discordjs.guide/ +[guide-source]: https://github.com/discordjs/guide +[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html +[discord]: https://discord.gg/djs +[discord-api]: https://discord.gg/discord-api +[source]: https://github.com/discordjs/discord.js/tree/main/packages/rest +[npm]: https://www.npmjs.com/package/@discordjs/rest +[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries +[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md diff --git a/node_modules/@discordjs/rest/dist/index.d.mts b/node_modules/@discordjs/rest/dist/index.d.mts new file mode 100644 index 0000000..2417e2e --- /dev/null +++ b/node_modules/@discordjs/rest/dist/index.d.mts @@ -0,0 +1,510 @@ +import { R as ResponseLike, a as RawFile, I as InternalRequest, b as RateLimitData, c as RestEventsMap, H as HashData, d as IHandler, e as RESTOptions, f as RouteLike, g as RequestData } from './types-65527f29.js'; +export { A as APIRequest, m as HandlerRequestData, j as InvalidRequestWarningData, i as RateLimitQueueFilter, k as RequestHeaders, l as RequestMethod, h as RestEvents, n as RouteData } from './types-65527f29.js'; +import * as url from 'url'; +import { Snowflake } from 'discord-api-types/v10'; +import * as undici from 'undici'; +import { Dispatcher } from 'undici'; +import { Collection } from '@discordjs/collection'; +import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; +import 'node:stream'; +import 'node:stream/web'; + +declare const DefaultUserAgent: `DiscordBot (https://discord.js.org, ${string})`; +/** + * The default string to append onto the user agent. + */ +declare const DefaultUserAgentAppendix: string; +declare const DefaultRestOptions: { + readonly agent: null; + readonly api: "https://discord.com/api"; + readonly authPrefix: "Bot"; + readonly cdn: "https://cdn.discordapp.com"; + readonly headers: {}; + readonly invalidRequestWarningInterval: 0; + readonly globalRequestsPerSecond: 50; + readonly offset: 50; + readonly rejectOnRateLimit: null; + readonly retries: 3; + readonly timeout: 15000; + readonly userAgentAppendix: string; + readonly version: "10"; + readonly hashSweepInterval: 14400000; + readonly hashLifetime: 86400000; + readonly handlerSweepInterval: 3600000; + readonly makeRequest: (url: string, init: undici.RequestInit) => Promise<ResponseLike>; +}; +/** + * The events that the REST manager emits + */ +declare enum RESTEvents { + Debug = "restDebug", + HandlerSweep = "handlerSweep", + HashSweep = "hashSweep", + InvalidRequestWarning = "invalidRequestWarning", + RateLimited = "rateLimited", + Response = "response" +} +declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"]; +declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"]; +declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]; +type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number]; +type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number]; +type ImageSize = (typeof ALLOWED_SIZES)[number]; +declare const OverwrittenMimeTypes: { + readonly 'image/apng': "image/png"; +}; +declare const BurstHandlerMajorIdKey = "burst"; + +/** + * The options used for image URLs + */ +interface BaseImageURLOptions { + /** + * The extension to use for the image URL + * + * @defaultValue `'webp'` + */ + extension?: ImageExtension; + /** + * The size specified in the image URL + */ + size?: ImageSize; +} +/** + * The options used for image URLs with animated content + */ +interface ImageURLOptions extends BaseImageURLOptions { + /** + * Whether or not to prefer the static version of an image asset. + */ + forceStatic?: boolean; +} +/** + * The options to use when making a CDN URL + */ +interface MakeURLOptions { + /** + * The allowed extensions that can be used + */ + allowedExtensions?: readonly string[]; + /** + * The extension to use for the image URL + * + * @defaultValue `'webp'` + */ + extension?: string | undefined; + /** + * The size specified in the image URL + */ + size?: ImageSize; +} +/** + * The CDN link builder + */ +declare class CDN { + private readonly base; + constructor(base?: string); + /** + * Generates an app asset URL for a client's asset. + * + * @param clientId - The client id that has the asset + * @param assetHash - The hash provided by Discord for this asset + * @param options - Optional options for the asset + */ + appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates an app icon URL for a client's icon. + * + * @param clientId - The client id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates an avatar URL, e.g. for a user or a webhook. + * + * @param id - The id that has the icon + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates a user avatar decoration URL. + * + * @param userId - The id of the user + * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration + * @param options - Optional options for the avatar decoration + */ + avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a banner URL, e.g. for a user or a guild. + * + * @param id - The id that has the banner splash + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates an icon URL for a channel, e.g. a group DM. + * + * @param channelId - The channel id that has the icon + * @param iconHash - The hash provided by Discord for this channel + * @param options - Optional options for the icon + */ + channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a default avatar URL + * + * @param index - The default avatar index + * @remarks + * To calculate the index for a user do `(userId >> 22) % 6`, + * or `discriminator % 5` if they're using the legacy username system. + */ + defaultAvatar(index: number): string; + /** + * Generates a discovery splash URL for a guild's discovery splash. + * + * @param guildId - The guild id that has the discovery splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates an emoji's URL for an emoji. + * + * @param emojiId - The emoji id + * @param extension - The extension of the emoji + */ + emoji(emojiId: string, extension?: ImageExtension): string; + /** + * Generates a guild member avatar URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates a guild member banner URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates an icon URL, e.g. for a guild. + * + * @param id - The id that has the icon splash + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates a URL for the icon of a role + * + * @param roleId - The id of the role that has the icon + * @param roleIconHash - The hash provided by Discord for this role icon + * @param options - Optional options for the role icon + */ + roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a guild invite splash URL for a guild's invite splash. + * + * @param guildId - The guild id that has the invite splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a sticker URL. + * + * @param stickerId - The sticker id + * @param extension - The extension of the sticker + * @privateRemarks + * Stickers cannot have a `.webp` extension, so we default to a `.png` + */ + sticker(stickerId: string, extension?: StickerExtension): string; + /** + * Generates a sticker pack banner URL. + * + * @param bannerId - The banner id + * @param options - Optional options for the banner + */ + stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a team icon URL for a team's icon. + * + * @param teamId - The team id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a cover image for a guild scheduled event. + * + * @param scheduledEventId - The scheduled event id + * @param coverHash - The hash provided by discord for this cover image + * @param options - Optional options for the cover image + */ + guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`. + * + * @param route - The base cdn route + * @param hash - The hash provided by Discord for this icon + * @param options - Optional options for the link + */ + private dynamicMakeURL; + /** + * Constructs the URL for the resource + * + * @param route - The base cdn route + * @param options - The extension/size options for the link + */ + private makeURL; +} + +interface DiscordErrorFieldInformation { + code: string; + message: string; +} +interface DiscordErrorGroupWrapper { + _errors: DiscordError[]; +} +type DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | { + [k: string]: DiscordError; +}; +interface DiscordErrorData { + code: number; + errors?: DiscordError; + message: string; +} +interface OAuthErrorData { + error: string; + error_description?: string; +} +interface RequestBody { + files: RawFile[] | undefined; + json: unknown | undefined; +} +/** + * Represents an API error returned by Discord + */ +declare class DiscordAPIError extends Error { + rawError: DiscordErrorData | OAuthErrorData; + code: number | string; + status: number; + method: string; + url: string; + requestBody: RequestBody; + /** + * @param rawError - The error reported by Discord + * @param code - The error code reported by Discord + * @param status - The status code of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>); + /** + * The name of the error + */ + get name(): string; + private static getMessage; + private static flattenDiscordError; +} + +/** + * Represents a HTTP error + */ +declare class HTTPError extends Error { + status: number; + method: string; + url: string; + requestBody: RequestBody; + name: string; + /** + * @param status - The status code of the response + * @param statusText - The status text of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(status: number, statusText: string, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>); +} + +declare class RateLimitError extends Error implements RateLimitData { + timeToReset: number; + limit: number; + method: string; + hash: string; + url: string; + route: string; + majorParameter: string; + global: boolean; + constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData); + /** + * The name of the error + */ + get name(): string; +} + +/** + * Represents the class that manages handlers for endpoints + */ +declare class REST extends AsyncEventEmitter<RestEventsMap> { + #private; + /** + * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests + * performed by this manager. + */ + agent: Dispatcher | null; + readonly cdn: CDN; + /** + * The number of requests remaining in the global bucket + */ + globalRemaining: number; + /** + * The promise used to wait out the global rate limit + */ + globalDelay: Promise<void> | null; + /** + * The timestamp at which the global bucket resets + */ + globalReset: number; + /** + * API bucket hashes that are cached from provided routes + */ + readonly hashes: Collection<string, HashData>; + /** + * Request handlers created from the bucket hash and the major parameters + */ + readonly handlers: Collection<string, IHandler>; + private hashTimer; + private handlerTimer; + readonly options: RESTOptions; + constructor(options?: Partial<RESTOptions>); + private setupSweepers; + /** + * Runs a get request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a delete request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a post request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a put request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a patch request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a request from the api + * + * @param options - Request options + */ + request(options: InternalRequest): Promise<unknown>; + /** + * Sets the default agent to use for requests performed by this manager + * + * @param agent - The agent to use + */ + setAgent(agent: Dispatcher): this; + /** + * Sets the authorization token that should be used for requests + * + * @param token - The authorization token to use + */ + setToken(token: string): this; + /** + * Queues a request to be sent + * + * @param request - All the information needed to make a request + * @returns The response from the api request + */ + queueRequest(request: InternalRequest): Promise<ResponseLike>; + /** + * Creates a new rate limit handler from a hash, based on the hash and the major parameter + * + * @param hash - The hash for the route + * @param majorParameter - The major parameter for this handler + * @internal + */ + private createHandler; + /** + * Formats the request data to a usable format for fetch + * + * @param request - The request data + */ + private resolveRequest; + /** + * Stops the hash sweeping interval + */ + clearHashSweeper(): void; + /** + * Stops the request handler sweeping interval + */ + clearHandlerSweeper(): void; + /** + * Generates route data for an endpoint:method + * + * @param endpoint - The raw endpoint to generalize + * @param method - The HTTP method this endpoint is called without + * @internal + */ + private static generateRouteData; +} + +/** + * Creates and populates an URLSearchParams instance from an object, stripping + * out null and undefined values, while also coercing non-strings to strings. + * + * @param options - The options to use + * @returns A populated URLSearchParams instance + */ +declare function makeURLSearchParams<T extends object>(options?: Readonly<T>): url.URLSearchParams; +/** + * Converts the response to usable data + * + * @param res - The fetch response + */ +declare function parseResponse(res: ResponseLike): Promise<unknown>; +/** + * Calculates the default avatar index for a given user id. + * + * @param userId - The user id to calculate the default avatar index for + */ +declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number; + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version + * that you are currently using. + */ +declare const version: string; + +export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, DiscordErrorData, HTTPError, HashData, ImageExtension, ImageSize, ImageURLOptions, InternalRequest, MakeURLOptions, OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, RESTOptions, RateLimitData, RateLimitError, RawFile, RequestBody, RequestData, ResponseLike, RestEventsMap, RouteLike, StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version }; diff --git a/node_modules/@discordjs/rest/dist/index.d.ts b/node_modules/@discordjs/rest/dist/index.d.ts new file mode 100644 index 0000000..2417e2e --- /dev/null +++ b/node_modules/@discordjs/rest/dist/index.d.ts @@ -0,0 +1,510 @@ +import { R as ResponseLike, a as RawFile, I as InternalRequest, b as RateLimitData, c as RestEventsMap, H as HashData, d as IHandler, e as RESTOptions, f as RouteLike, g as RequestData } from './types-65527f29.js'; +export { A as APIRequest, m as HandlerRequestData, j as InvalidRequestWarningData, i as RateLimitQueueFilter, k as RequestHeaders, l as RequestMethod, h as RestEvents, n as RouteData } from './types-65527f29.js'; +import * as url from 'url'; +import { Snowflake } from 'discord-api-types/v10'; +import * as undici from 'undici'; +import { Dispatcher } from 'undici'; +import { Collection } from '@discordjs/collection'; +import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; +import 'node:stream'; +import 'node:stream/web'; + +declare const DefaultUserAgent: `DiscordBot (https://discord.js.org, ${string})`; +/** + * The default string to append onto the user agent. + */ +declare const DefaultUserAgentAppendix: string; +declare const DefaultRestOptions: { + readonly agent: null; + readonly api: "https://discord.com/api"; + readonly authPrefix: "Bot"; + readonly cdn: "https://cdn.discordapp.com"; + readonly headers: {}; + readonly invalidRequestWarningInterval: 0; + readonly globalRequestsPerSecond: 50; + readonly offset: 50; + readonly rejectOnRateLimit: null; + readonly retries: 3; + readonly timeout: 15000; + readonly userAgentAppendix: string; + readonly version: "10"; + readonly hashSweepInterval: 14400000; + readonly hashLifetime: 86400000; + readonly handlerSweepInterval: 3600000; + readonly makeRequest: (url: string, init: undici.RequestInit) => Promise<ResponseLike>; +}; +/** + * The events that the REST manager emits + */ +declare enum RESTEvents { + Debug = "restDebug", + HandlerSweep = "handlerSweep", + HashSweep = "hashSweep", + InvalidRequestWarning = "invalidRequestWarning", + RateLimited = "rateLimited", + Response = "response" +} +declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"]; +declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"]; +declare const ALLOWED_SIZES: readonly [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]; +type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number]; +type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number]; +type ImageSize = (typeof ALLOWED_SIZES)[number]; +declare const OverwrittenMimeTypes: { + readonly 'image/apng': "image/png"; +}; +declare const BurstHandlerMajorIdKey = "burst"; + +/** + * The options used for image URLs + */ +interface BaseImageURLOptions { + /** + * The extension to use for the image URL + * + * @defaultValue `'webp'` + */ + extension?: ImageExtension; + /** + * The size specified in the image URL + */ + size?: ImageSize; +} +/** + * The options used for image URLs with animated content + */ +interface ImageURLOptions extends BaseImageURLOptions { + /** + * Whether or not to prefer the static version of an image asset. + */ + forceStatic?: boolean; +} +/** + * The options to use when making a CDN URL + */ +interface MakeURLOptions { + /** + * The allowed extensions that can be used + */ + allowedExtensions?: readonly string[]; + /** + * The extension to use for the image URL + * + * @defaultValue `'webp'` + */ + extension?: string | undefined; + /** + * The size specified in the image URL + */ + size?: ImageSize; +} +/** + * The CDN link builder + */ +declare class CDN { + private readonly base; + constructor(base?: string); + /** + * Generates an app asset URL for a client's asset. + * + * @param clientId - The client id that has the asset + * @param assetHash - The hash provided by Discord for this asset + * @param options - Optional options for the asset + */ + appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates an app icon URL for a client's icon. + * + * @param clientId - The client id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates an avatar URL, e.g. for a user or a webhook. + * + * @param id - The id that has the icon + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates a user avatar decoration URL. + * + * @param userId - The id of the user + * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration + * @param options - Optional options for the avatar decoration + */ + avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a banner URL, e.g. for a user or a guild. + * + * @param id - The id that has the banner splash + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates an icon URL for a channel, e.g. a group DM. + * + * @param channelId - The channel id that has the icon + * @param iconHash - The hash provided by Discord for this channel + * @param options - Optional options for the icon + */ + channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a default avatar URL + * + * @param index - The default avatar index + * @remarks + * To calculate the index for a user do `(userId >> 22) % 6`, + * or `discriminator % 5` if they're using the legacy username system. + */ + defaultAvatar(index: number): string; + /** + * Generates a discovery splash URL for a guild's discovery splash. + * + * @param guildId - The guild id that has the discovery splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates an emoji's URL for an emoji. + * + * @param emojiId - The emoji id + * @param extension - The extension of the emoji + */ + emoji(emojiId: string, extension?: ImageExtension): string; + /** + * Generates a guild member avatar URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + guildMemberAvatar(guildId: string, userId: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates a guild member banner URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + guildMemberBanner(guildId: string, userId: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates an icon URL, e.g. for a guild. + * + * @param id - The id that has the icon splash + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string; + /** + * Generates a URL for the icon of a role + * + * @param roleId - The id of the role that has the icon + * @param roleIconHash - The hash provided by Discord for this role icon + * @param options - Optional options for the role icon + */ + roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a guild invite splash URL for a guild's invite splash. + * + * @param guildId - The guild id that has the invite splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a sticker URL. + * + * @param stickerId - The sticker id + * @param extension - The extension of the sticker + * @privateRemarks + * Stickers cannot have a `.webp` extension, so we default to a `.png` + */ + sticker(stickerId: string, extension?: StickerExtension): string; + /** + * Generates a sticker pack banner URL. + * + * @param bannerId - The banner id + * @param options - Optional options for the banner + */ + stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a team icon URL for a team's icon. + * + * @param teamId - The team id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Generates a cover image for a guild scheduled event. + * + * @param scheduledEventId - The scheduled event id + * @param coverHash - The hash provided by discord for this cover image + * @param options - Optional options for the cover image + */ + guildScheduledEventCover(scheduledEventId: string, coverHash: string, options?: Readonly<BaseImageURLOptions>): string; + /** + * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`. + * + * @param route - The base cdn route + * @param hash - The hash provided by Discord for this icon + * @param options - Optional options for the link + */ + private dynamicMakeURL; + /** + * Constructs the URL for the resource + * + * @param route - The base cdn route + * @param options - The extension/size options for the link + */ + private makeURL; +} + +interface DiscordErrorFieldInformation { + code: string; + message: string; +} +interface DiscordErrorGroupWrapper { + _errors: DiscordError[]; +} +type DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | { + [k: string]: DiscordError; +}; +interface DiscordErrorData { + code: number; + errors?: DiscordError; + message: string; +} +interface OAuthErrorData { + error: string; + error_description?: string; +} +interface RequestBody { + files: RawFile[] | undefined; + json: unknown | undefined; +} +/** + * Represents an API error returned by Discord + */ +declare class DiscordAPIError extends Error { + rawError: DiscordErrorData | OAuthErrorData; + code: number | string; + status: number; + method: string; + url: string; + requestBody: RequestBody; + /** + * @param rawError - The error reported by Discord + * @param code - The error code reported by Discord + * @param status - The status code of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(rawError: DiscordErrorData | OAuthErrorData, code: number | string, status: number, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>); + /** + * The name of the error + */ + get name(): string; + private static getMessage; + private static flattenDiscordError; +} + +/** + * Represents a HTTP error + */ +declare class HTTPError extends Error { + status: number; + method: string; + url: string; + requestBody: RequestBody; + name: string; + /** + * @param status - The status code of the response + * @param statusText - The status text of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(status: number, statusText: string, method: string, url: string, bodyData: Pick<InternalRequest, 'body' | 'files'>); +} + +declare class RateLimitError extends Error implements RateLimitData { + timeToReset: number; + limit: number; + method: string; + hash: string; + url: string; + route: string; + majorParameter: string; + global: boolean; + constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData); + /** + * The name of the error + */ + get name(): string; +} + +/** + * Represents the class that manages handlers for endpoints + */ +declare class REST extends AsyncEventEmitter<RestEventsMap> { + #private; + /** + * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests + * performed by this manager. + */ + agent: Dispatcher | null; + readonly cdn: CDN; + /** + * The number of requests remaining in the global bucket + */ + globalRemaining: number; + /** + * The promise used to wait out the global rate limit + */ + globalDelay: Promise<void> | null; + /** + * The timestamp at which the global bucket resets + */ + globalReset: number; + /** + * API bucket hashes that are cached from provided routes + */ + readonly hashes: Collection<string, HashData>; + /** + * Request handlers created from the bucket hash and the major parameters + */ + readonly handlers: Collection<string, IHandler>; + private hashTimer; + private handlerTimer; + readonly options: RESTOptions; + constructor(options?: Partial<RESTOptions>); + private setupSweepers; + /** + * Runs a get request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + get(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a delete request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + delete(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a post request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + post(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a put request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + put(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a patch request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + patch(fullRoute: RouteLike, options?: RequestData): Promise<unknown>; + /** + * Runs a request from the api + * + * @param options - Request options + */ + request(options: InternalRequest): Promise<unknown>; + /** + * Sets the default agent to use for requests performed by this manager + * + * @param agent - The agent to use + */ + setAgent(agent: Dispatcher): this; + /** + * Sets the authorization token that should be used for requests + * + * @param token - The authorization token to use + */ + setToken(token: string): this; + /** + * Queues a request to be sent + * + * @param request - All the information needed to make a request + * @returns The response from the api request + */ + queueRequest(request: InternalRequest): Promise<ResponseLike>; + /** + * Creates a new rate limit handler from a hash, based on the hash and the major parameter + * + * @param hash - The hash for the route + * @param majorParameter - The major parameter for this handler + * @internal + */ + private createHandler; + /** + * Formats the request data to a usable format for fetch + * + * @param request - The request data + */ + private resolveRequest; + /** + * Stops the hash sweeping interval + */ + clearHashSweeper(): void; + /** + * Stops the request handler sweeping interval + */ + clearHandlerSweeper(): void; + /** + * Generates route data for an endpoint:method + * + * @param endpoint - The raw endpoint to generalize + * @param method - The HTTP method this endpoint is called without + * @internal + */ + private static generateRouteData; +} + +/** + * Creates and populates an URLSearchParams instance from an object, stripping + * out null and undefined values, while also coercing non-strings to strings. + * + * @param options - The options to use + * @returns A populated URLSearchParams instance + */ +declare function makeURLSearchParams<T extends object>(options?: Readonly<T>): url.URLSearchParams; +/** + * Converts the response to usable data + * + * @param res - The fetch response + */ +declare function parseResponse(res: ResponseLike): Promise<unknown>; +/** + * Calculates the default avatar index for a given user id. + * + * @param userId - The user id to calculate the default avatar index for + */ +declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number; + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version + * that you are currently using. + */ +declare const version: string; + +export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, DiscordErrorData, HTTPError, HashData, ImageExtension, ImageSize, ImageURLOptions, InternalRequest, MakeURLOptions, OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, RESTOptions, RateLimitData, RateLimitError, RawFile, RequestBody, RequestData, ResponseLike, RestEventsMap, RouteLike, StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version }; diff --git a/node_modules/@discordjs/rest/dist/index.js b/node_modules/@discordjs/rest/dist/index.js new file mode 100644 index 0000000..16a6d46 --- /dev/null +++ b/node_modules/@discordjs/rest/dist/index.js @@ -0,0 +1,1423 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + ALLOWED_EXTENSIONS: () => ALLOWED_EXTENSIONS, + ALLOWED_SIZES: () => ALLOWED_SIZES, + ALLOWED_STICKER_EXTENSIONS: () => ALLOWED_STICKER_EXTENSIONS, + BurstHandlerMajorIdKey: () => BurstHandlerMajorIdKey, + CDN: () => CDN, + DefaultRestOptions: () => DefaultRestOptions, + DefaultUserAgent: () => DefaultUserAgent, + DefaultUserAgentAppendix: () => DefaultUserAgentAppendix, + DiscordAPIError: () => DiscordAPIError, + HTTPError: () => HTTPError, + OverwrittenMimeTypes: () => OverwrittenMimeTypes, + REST: () => REST, + RESTEvents: () => RESTEvents, + RateLimitError: () => RateLimitError, + RequestMethod: () => RequestMethod, + calculateUserDefaultAvatarIndex: () => calculateUserDefaultAvatarIndex, + makeURLSearchParams: () => makeURLSearchParams, + parseResponse: () => parseResponse, + version: () => version +}); +module.exports = __toCommonJS(src_exports); +var import_node_buffer = require("buffer"); +var import_util2 = require("@discordjs/util"); +var import_undici2 = require("undici"); + +// src/environment.ts +var defaultStrategy; +function setDefaultStrategy(newStrategy) { + defaultStrategy = newStrategy; +} +__name(setDefaultStrategy, "setDefaultStrategy"); +function getDefaultStrategy() { + return defaultStrategy; +} +__name(getDefaultStrategy, "getDefaultStrategy"); + +// src/strategies/undiciRequest.ts +var import_node_http = require("http"); +var import_node_url = require("url"); +var import_node_util = require("util"); +var import_undici = require("undici"); +async function makeRequest(url, init) { + const options = { + ...init, + body: await resolveBody(init.body) + }; + const res = await (0, import_undici.request)(url, options); + return { + body: res.body, + async arrayBuffer() { + return res.body.arrayBuffer(); + }, + async json() { + return res.body.json(); + }, + async text() { + return res.body.text(); + }, + get bodyUsed() { + return res.body.bodyUsed; + }, + headers: new import_undici.Headers(res.headers), + status: res.statusCode, + statusText: import_node_http.STATUS_CODES[res.statusCode], + ok: res.statusCode >= 200 && res.statusCode < 300 + }; +} +__name(makeRequest, "makeRequest"); +async function resolveBody(body) { + if (body == null) { + return null; + } else if (typeof body === "string") { + return body; + } else if (import_node_util.types.isUint8Array(body)) { + return body; + } else if (import_node_util.types.isArrayBuffer(body)) { + return new Uint8Array(body); + } else if (body instanceof import_node_url.URLSearchParams) { + return body.toString(); + } else if (body instanceof DataView) { + return new Uint8Array(body.buffer); + } else if (body instanceof Blob) { + return new Uint8Array(await body.arrayBuffer()); + } else if (body instanceof FormData) { + return body; + } else if (body[Symbol.iterator]) { + const chunks = [...body]; + return Buffer.concat(chunks); + } else if (body[Symbol.asyncIterator]) { + const chunks = []; + for await (const chunk of body) { + chunks.push(chunk); + } + return Buffer.concat(chunks); + } + throw new TypeError(`Unable to resolve body.`); +} +__name(resolveBody, "resolveBody"); + +// src/lib/utils/constants.ts +var import_util = require("@discordjs/util"); +var import_v10 = require("discord-api-types/v10"); +var DefaultUserAgent = `DiscordBot (https://discord.js.org, 2.0.1)`; +var DefaultUserAgentAppendix = (0, import_util.getUserAgentAppendix)(); +var DefaultRestOptions = { + agent: null, + api: "https://discord.com/api", + authPrefix: "Bot", + cdn: "https://cdn.discordapp.com", + headers: {}, + invalidRequestWarningInterval: 0, + globalRequestsPerSecond: 50, + offset: 50, + rejectOnRateLimit: null, + retries: 3, + timeout: 15e3, + userAgentAppendix: DefaultUserAgentAppendix, + version: import_v10.APIVersion, + hashSweepInterval: 144e5, + // 4 Hours + hashLifetime: 864e5, + // 24 Hours + handlerSweepInterval: 36e5, + // 1 Hour + async makeRequest(...args) { + return getDefaultStrategy()(...args); + } +}; +var RESTEvents = /* @__PURE__ */ ((RESTEvents2) => { + RESTEvents2["Debug"] = "restDebug"; + RESTEvents2["HandlerSweep"] = "handlerSweep"; + RESTEvents2["HashSweep"] = "hashSweep"; + RESTEvents2["InvalidRequestWarning"] = "invalidRequestWarning"; + RESTEvents2["RateLimited"] = "rateLimited"; + RESTEvents2["Response"] = "response"; + return RESTEvents2; +})(RESTEvents || {}); +var ALLOWED_EXTENSIONS = ["webp", "png", "jpg", "jpeg", "gif"]; +var ALLOWED_STICKER_EXTENSIONS = ["png", "json", "gif"]; +var ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]; +var OverwrittenMimeTypes = { + // https://github.com/discordjs/discord.js/issues/8557 + "image/apng": "image/png" +}; +var BurstHandlerMajorIdKey = "burst"; + +// src/lib/CDN.ts +var CDN = class { + constructor(base = DefaultRestOptions.cdn) { + this.base = base; + } + static { + __name(this, "CDN"); + } + /** + * Generates an app asset URL for a client's asset. + * + * @param clientId - The client id that has the asset + * @param assetHash - The hash provided by Discord for this asset + * @param options - Optional options for the asset + */ + appAsset(clientId, assetHash, options) { + return this.makeURL(`/app-assets/${clientId}/${assetHash}`, options); + } + /** + * Generates an app icon URL for a client's icon. + * + * @param clientId - The client id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + appIcon(clientId, iconHash, options) { + return this.makeURL(`/app-icons/${clientId}/${iconHash}`, options); + } + /** + * Generates an avatar URL, e.g. for a user or a webhook. + * + * @param id - The id that has the icon + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + avatar(id, avatarHash, options) { + return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options); + } + /** + * Generates a user avatar decoration URL. + * + * @param userId - The id of the user + * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration + * @param options - Optional options for the avatar decoration + */ + avatarDecoration(userId, userAvatarDecoration, options) { + return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options); + } + /** + * Generates a banner URL, e.g. for a user or a guild. + * + * @param id - The id that has the banner splash + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + banner(id, bannerHash, options) { + return this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options); + } + /** + * Generates an icon URL for a channel, e.g. a group DM. + * + * @param channelId - The channel id that has the icon + * @param iconHash - The hash provided by Discord for this channel + * @param options - Optional options for the icon + */ + channelIcon(channelId, iconHash, options) { + return this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options); + } + /** + * Generates a default avatar URL + * + * @param index - The default avatar index + * @remarks + * To calculate the index for a user do `(userId >> 22) % 6`, + * or `discriminator % 5` if they're using the legacy username system. + */ + defaultAvatar(index) { + return this.makeURL(`/embed/avatars/${index}`, { extension: "png" }); + } + /** + * Generates a discovery splash URL for a guild's discovery splash. + * + * @param guildId - The guild id that has the discovery splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + discoverySplash(guildId, splashHash, options) { + return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates an emoji's URL for an emoji. + * + * @param emojiId - The emoji id + * @param extension - The extension of the emoji + */ + emoji(emojiId, extension) { + return this.makeURL(`/emojis/${emojiId}`, { extension }); + } + /** + * Generates a guild member avatar URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + guildMemberAvatar(guildId, userId, avatarHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options); + } + /** + * Generates a guild member banner URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + guildMemberBanner(guildId, userId, bannerHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options); + } + /** + * Generates an icon URL, e.g. for a guild. + * + * @param id - The id that has the icon splash + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + icon(id, iconHash, options) { + return this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options); + } + /** + * Generates a URL for the icon of a role + * + * @param roleId - The id of the role that has the icon + * @param roleIconHash - The hash provided by Discord for this role icon + * @param options - Optional options for the role icon + */ + roleIcon(roleId, roleIconHash, options) { + return this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options); + } + /** + * Generates a guild invite splash URL for a guild's invite splash. + * + * @param guildId - The guild id that has the invite splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + splash(guildId, splashHash, options) { + return this.makeURL(`/splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates a sticker URL. + * + * @param stickerId - The sticker id + * @param extension - The extension of the sticker + * @privateRemarks + * Stickers cannot have a `.webp` extension, so we default to a `.png` + */ + sticker(stickerId, extension = "png") { + return this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension }); + } + /** + * Generates a sticker pack banner URL. + * + * @param bannerId - The banner id + * @param options - Optional options for the banner + */ + stickerPackBanner(bannerId, options) { + return this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options); + } + /** + * Generates a team icon URL for a team's icon. + * + * @param teamId - The team id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + teamIcon(teamId, iconHash, options) { + return this.makeURL(`/team-icons/${teamId}/${iconHash}`, options); + } + /** + * Generates a cover image for a guild scheduled event. + * + * @param scheduledEventId - The scheduled event id + * @param coverHash - The hash provided by discord for this cover image + * @param options - Optional options for the cover image + */ + guildScheduledEventCover(scheduledEventId, coverHash, options) { + return this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options); + } + /** + * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`. + * + * @param route - The base cdn route + * @param hash - The hash provided by Discord for this icon + * @param options - Optional options for the link + */ + dynamicMakeURL(route, hash, { forceStatic = false, ...options } = {}) { + return this.makeURL(route, !forceStatic && hash.startsWith("a_") ? { ...options, extension: "gif" } : options); + } + /** + * Constructs the URL for the resource + * + * @param route - The base cdn route + * @param options - The extension/size options for the link + */ + makeURL(route, { allowedExtensions = ALLOWED_EXTENSIONS, extension = "webp", size } = {}) { + extension = String(extension).toLowerCase(); + if (!allowedExtensions.includes(extension)) { + throw new RangeError(`Invalid extension provided: ${extension} +Must be one of: ${allowedExtensions.join(", ")}`); + } + if (size && !ALLOWED_SIZES.includes(size)) { + throw new RangeError(`Invalid size provided: ${size} +Must be one of: ${ALLOWED_SIZES.join(", ")}`); + } + const url = new URL(`${this.base}${route}.${extension}`); + if (size) { + url.searchParams.set("size", String(size)); + } + return url.toString(); + } +}; + +// src/lib/errors/DiscordAPIError.ts +function isErrorGroupWrapper(error) { + return Reflect.has(error, "_errors"); +} +__name(isErrorGroupWrapper, "isErrorGroupWrapper"); +function isErrorResponse(error) { + return typeof Reflect.get(error, "message") === "string"; +} +__name(isErrorResponse, "isErrorResponse"); +var DiscordAPIError = class _DiscordAPIError extends Error { + /** + * @param rawError - The error reported by Discord + * @param code - The error code reported by Discord + * @param status - The status code of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(rawError, code, status, method, url, bodyData) { + super(_DiscordAPIError.getMessage(rawError)); + this.rawError = rawError; + this.code = code; + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "DiscordAPIError"); + } + requestBody; + /** + * The name of the error + */ + get name() { + return `${_DiscordAPIError.name}[${this.code}]`; + } + static getMessage(error) { + let flattened = ""; + if ("code" in error) { + if (error.errors) { + flattened = [...this.flattenDiscordError(error.errors)].join("\n"); + } + return error.message && flattened ? `${error.message} +${flattened}` : error.message || flattened || "Unknown Error"; + } + return error.error_description ?? "No Description"; + } + static *flattenDiscordError(obj, key = "") { + if (isErrorResponse(obj)) { + return yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim(); + } + for (const [otherKey, val] of Object.entries(obj)) { + const nextKey = otherKey.startsWith("_") ? key : key ? Number.isNaN(Number(otherKey)) ? `${key}.${otherKey}` : `${key}[${otherKey}]` : otherKey; + if (typeof val === "string") { + yield val; + } else if (isErrorGroupWrapper(val)) { + for (const error of val._errors) { + yield* this.flattenDiscordError(error, nextKey); + } + } else { + yield* this.flattenDiscordError(val, nextKey); + } + } + } +}; + +// src/lib/errors/HTTPError.ts +var HTTPError = class _HTTPError extends Error { + /** + * @param status - The status code of the response + * @param statusText - The status text of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(status, statusText, method, url, bodyData) { + super(statusText); + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "HTTPError"); + } + requestBody; + name = _HTTPError.name; +}; + +// src/lib/errors/RateLimitError.ts +var RateLimitError = class _RateLimitError extends Error { + static { + __name(this, "RateLimitError"); + } + timeToReset; + limit; + method; + hash; + url; + route; + majorParameter; + global; + constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }) { + super(); + this.timeToReset = timeToReset; + this.limit = limit; + this.method = method; + this.hash = hash; + this.url = url; + this.route = route; + this.majorParameter = majorParameter; + this.global = global; + } + /** + * The name of the error + */ + get name() { + return `${_RateLimitError.name}[${this.route}]`; + } +}; + +// src/lib/REST.ts +var import_collection = require("@discordjs/collection"); +var import_snowflake = require("@sapphire/snowflake"); +var import_async_event_emitter = require("@vladfrangu/async_event_emitter"); +var import_magic_bytes = require("magic-bytes.js"); + +// src/lib/utils/types.ts +var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => { + RequestMethod2["Delete"] = "DELETE"; + RequestMethod2["Get"] = "GET"; + RequestMethod2["Patch"] = "PATCH"; + RequestMethod2["Post"] = "POST"; + RequestMethod2["Put"] = "PUT"; + return RequestMethod2; +})(RequestMethod || {}); + +// src/lib/utils/utils.ts +function serializeSearchParam(value) { + switch (typeof value) { + case "string": + return value; + case "number": + case "bigint": + case "boolean": + return value.toString(); + case "object": + if (value === null) + return null; + if (value instanceof Date) { + return Number.isNaN(value.getTime()) ? null : value.toISOString(); + } + if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) + return value.toString(); + return null; + default: + return null; + } +} +__name(serializeSearchParam, "serializeSearchParam"); +function makeURLSearchParams(options) { + const params = new URLSearchParams(); + if (!options) + return params; + for (const [key, value] of Object.entries(options)) { + const serialized = serializeSearchParam(value); + if (serialized !== null) + params.append(key, serialized); + } + return params; +} +__name(makeURLSearchParams, "makeURLSearchParams"); +async function parseResponse(res) { + if (res.headers.get("Content-Type")?.startsWith("application/json")) { + return res.json(); + } + return res.arrayBuffer(); +} +__name(parseResponse, "parseResponse"); +function hasSublimit(bucketRoute, body, method) { + if (bucketRoute === "/channels/:id") { + if (typeof body !== "object" || body === null) + return false; + if (method !== "PATCH" /* Patch */) + return false; + const castedBody = body; + return ["name", "topic"].some((key) => Reflect.has(castedBody, key)); + } + return true; +} +__name(hasSublimit, "hasSublimit"); +function shouldRetry(error) { + if (error.name === "AbortError") + return true; + return "code" in error && error.code === "ECONNRESET" || error.message.includes("ECONNRESET"); +} +__name(shouldRetry, "shouldRetry"); +async function onRateLimit(manager, rateLimitData) { + const { options } = manager; + if (!options.rejectOnRateLimit) + return; + const shouldThrow = typeof options.rejectOnRateLimit === "function" ? await options.rejectOnRateLimit(rateLimitData) : options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase())); + if (shouldThrow) { + throw new RateLimitError(rateLimitData); + } +} +__name(onRateLimit, "onRateLimit"); +function calculateUserDefaultAvatarIndex(userId) { + return Number(BigInt(userId) >> 22n) % 6; +} +__name(calculateUserDefaultAvatarIndex, "calculateUserDefaultAvatarIndex"); +async function sleep(ms) { + return new Promise((resolve) => { + setTimeout(() => resolve(), ms); + }); +} +__name(sleep, "sleep"); +function isBufferLike(value) { + return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray; +} +__name(isBufferLike, "isBufferLike"); + +// src/lib/handlers/Shared.ts +var invalidCount = 0; +var invalidCountResetTime = null; +function incrementInvalidCount(manager) { + if (!invalidCountResetTime || invalidCountResetTime < Date.now()) { + invalidCountResetTime = Date.now() + 1e3 * 60 * 10; + invalidCount = 0; + } + invalidCount++; + const emitInvalid = manager.options.invalidRequestWarningInterval > 0 && invalidCount % manager.options.invalidRequestWarningInterval === 0; + if (emitInvalid) { + manager.emit("invalidRequestWarning" /* InvalidRequestWarning */, { + count: invalidCount, + remainingTime: invalidCountResetTime - Date.now() + }); + } +} +__name(incrementInvalidCount, "incrementInvalidCount"); +async function makeNetworkRequest(manager, routeId, url, options, requestData, retries) { + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), manager.options.timeout); + if (requestData.signal) { + if (requestData.signal.aborted) + controller.abort(); + else + requestData.signal.addEventListener("abort", () => controller.abort()); + } + let res; + try { + res = await manager.options.makeRequest(url, { ...options, signal: controller.signal }); + } catch (error) { + if (!(error instanceof Error)) + throw error; + if (shouldRetry(error) && retries !== manager.options.retries) { + return null; + } + throw error; + } finally { + clearTimeout(timeout); + } + if (manager.listenerCount("response" /* Response */)) { + manager.emit( + "response" /* Response */, + { + method: options.method ?? "get", + path: routeId.original, + route: routeId.bucketRoute, + options, + data: requestData, + retries + }, + res instanceof Response ? res.clone() : { ...res } + ); + } + return res; +} +__name(makeNetworkRequest, "makeNetworkRequest"); +async function handleErrors(manager, res, method, url, requestData, retries) { + const status = res.status; + if (status >= 500 && status < 600) { + if (retries !== manager.options.retries) { + return null; + } + throw new HTTPError(status, res.statusText, method, url, requestData); + } else { + if (status >= 400 && status < 500) { + if (status === 401 && requestData.auth) { + manager.setToken(null); + } + const data = await parseResponse(res); + throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); + } + return res; + } +} +__name(handleErrors, "handleErrors"); + +// src/lib/handlers/BurstHandler.ts +var BurstHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "BurstHandler"); + } + /** + * {@inheritdoc IHandler.id} + */ + id; + /** + * {@inheritDoc IHandler.inactive} + */ + inactive = false; + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + return this.runRequest(routeId, url, options, requestData); + } + /** + * The method that actually makes the request to the API, and updates info about the bucket accordingly + * + * @param routeId - The generalized API route with literal ids for major parameters + * @param url - The fully resolved URL to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const retry = res.headers.get("Retry-After"); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (status >= 200 && status < 300) { + return res; + } else if (status === 429) { + const isGlobal = res.headers.has("X-RateLimit-Global"); + await onRateLimit(this.manager, { + timeToReset: retryAfter, + limit: Number.POSITIVE_INFINITY, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${Number.POSITIVE_INFINITY}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : None` + ].join("\n") + ); + await sleep(retryAfter); + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/handlers/SequentialHandler.ts +var import_async_queue = require("@sapphire/async-queue"); +var SequentialHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "SequentialHandler"); + } + /** + * {@inheritDoc IHandler.id} + */ + id; + /** + * The time this rate limit bucket will reset + */ + reset = -1; + /** + * The remaining requests that can be made before we are rate limited + */ + remaining = 1; + /** + * The total number of requests that can be made before we are rate limited + */ + limit = Number.POSITIVE_INFINITY; + /** + * The interface used to sequence async requests sequentially + */ + #asyncQueue = new import_async_queue.AsyncQueue(); + /** + * The interface used to sequence sublimited async requests sequentially + */ + #sublimitedQueue = null; + /** + * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed + */ + #sublimitPromise = null; + /** + * Whether the sublimit queue needs to be shifted in the finally block + */ + #shiftSublimit = false; + /** + * {@inheritDoc IHandler.inactive} + */ + get inactive() { + return this.#asyncQueue.remaining === 0 && (this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) && !this.limited; + } + /** + * If the rate limit bucket is currently limited by the global limit + */ + get globalLimited() { + return this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset; + } + /** + * If the rate limit bucket is currently limited by its limit + */ + get localLimited() { + return this.remaining <= 0 && Date.now() < this.reset; + } + /** + * If the rate limit bucket is currently limited + */ + get limited() { + return this.globalLimited || this.localLimited; + } + /** + * The time until queued requests can continue + */ + get timeToReset() { + return this.reset + this.manager.options.offset - Date.now(); + } + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * Delay all requests for the specified amount of time, handling global rate limits + * + * @param time - The amount of time to delay all requests for + */ + async globalDelayFor(time) { + await sleep(time); + this.manager.globalDelay = null; + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + let queue = this.#asyncQueue; + let queueType = 0 /* Standard */; + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + queueType = 1 /* Sublimit */; + } + await queue.wait({ signal: requestData.signal }); + if (queueType === 0 /* Standard */) { + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + const wait = queue.wait(); + this.#asyncQueue.shift(); + await wait; + } else if (this.#sublimitPromise) { + await this.#sublimitPromise.promise; + } + } + try { + return await this.runRequest(routeId, url, options, requestData); + } finally { + queue.shift(); + if (this.#shiftSublimit) { + this.#shiftSublimit = false; + this.#sublimitedQueue?.shift(); + } + if (this.#sublimitedQueue?.remaining === 0) { + this.#sublimitPromise?.resolve(); + this.#sublimitedQueue = null; + } + } + } + /** + * The method that actually makes the request to the api, and updates info about the bucket accordingly + * + * @param routeId - The generalized api route with literal ids for major parameters + * @param url - The fully resolved url to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + while (this.limited) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + let delay; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + if (!this.manager.globalDelay) { + this.manager.globalDelay = this.globalDelayFor(timeout); + } + delay = this.manager.globalDelay; + } else { + limit2 = this.limit; + timeout = this.timeToReset; + delay = sleep(timeout); + } + const rateLimitData = { + timeToReset: timeout, + limit: limit2, + method: options.method ?? "get", + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }; + this.manager.emit("rateLimited" /* RateLimited */, rateLimitData); + await onRateLimit(this.manager, rateLimitData); + if (isGlobal) { + this.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`); + } else { + this.debug(`Waiting ${timeout}ms for rate limit to pass`); + } + await delay; + } + if (!this.manager.globalReset || this.manager.globalReset < Date.now()) { + this.manager.globalReset = Date.now() + 1e3; + this.manager.globalRemaining = this.manager.options.globalRequestsPerSecond; + } + this.manager.globalRemaining--; + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const limit = res.headers.get("X-RateLimit-Limit"); + const remaining = res.headers.get("X-RateLimit-Remaining"); + const reset = res.headers.get("X-RateLimit-Reset-After"); + const hash = res.headers.get("X-RateLimit-Bucket"); + const retry = res.headers.get("Retry-After"); + this.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY; + this.remaining = remaining ? Number(remaining) : 1; + this.reset = reset ? Number(reset) * 1e3 + Date.now() + this.manager.options.offset : Date.now(); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (hash && hash !== this.hash) { + this.debug(["Received bucket hash update", ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join("\n")); + this.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() }); + } else if (hash) { + const hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`); + if (hashData) { + hashData.lastAccess = Date.now(); + } + } + let sublimitTimeout = null; + if (retryAfter > 0) { + if (res.headers.has("X-RateLimit-Global")) { + this.manager.globalRemaining = 0; + this.manager.globalReset = Date.now() + retryAfter; + } else if (!this.localLimited) { + sublimitTimeout = retryAfter; + } + } + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (res.ok) { + return res; + } else if (status === 429) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + } else { + limit2 = this.limit; + timeout = this.timeToReset; + } + await onRateLimit(this.manager, { + timeToReset: timeout, + limit: limit2, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal.toString()}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${limit2}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : "None"}` + ].join("\n") + ); + if (sublimitTimeout) { + const firstSublimit = !this.#sublimitedQueue; + if (firstSublimit) { + this.#sublimitedQueue = new import_async_queue.AsyncQueue(); + void this.#sublimitedQueue.wait(); + this.#asyncQueue.shift(); + } + this.#sublimitPromise?.resolve(); + this.#sublimitPromise = null; + await sleep(sublimitTimeout); + let resolve; + const promise = new Promise((res2) => resolve = res2); + this.#sublimitPromise = { promise, resolve }; + if (firstSublimit) { + await this.#asyncQueue.wait(); + this.#shiftSublimit = true; + } + } + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/REST.ts +var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter { + static { + __name(this, "REST"); + } + /** + * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests + * performed by this manager. + */ + agent = null; + cdn; + /** + * The number of requests remaining in the global bucket + */ + globalRemaining; + /** + * The promise used to wait out the global rate limit + */ + globalDelay = null; + /** + * The timestamp at which the global bucket resets + */ + globalReset = -1; + /** + * API bucket hashes that are cached from provided routes + */ + hashes = new import_collection.Collection(); + /** + * Request handlers created from the bucket hash and the major parameters + */ + handlers = new import_collection.Collection(); + #token = null; + hashTimer; + handlerTimer; + options; + constructor(options = {}) { + super(); + this.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn); + this.options = { ...DefaultRestOptions, ...options }; + this.options.offset = Math.max(0, this.options.offset); + this.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond); + this.agent = options.agent ?? null; + this.setupSweepers(); + } + setupSweepers() { + const validateMaxInterval = /* @__PURE__ */ __name((interval) => { + if (interval > 144e5) { + throw new Error("Cannot set an interval greater than 4 hours"); + } + }, "validateMaxInterval"); + if (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.hashSweepInterval); + this.hashTimer = setInterval(() => { + const sweptHashes = new import_collection.Collection(); + const currentDate = Date.now(); + this.hashes.sweep((val, key) => { + if (val.lastAccess === -1) + return false; + const shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime; + if (shouldSweep) { + sweptHashes.set(key, val); + this.emit("restDebug" /* Debug */, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`); + } + return shouldSweep; + }); + this.emit("hashSweep" /* HashSweep */, sweptHashes); + }, this.options.hashSweepInterval); + this.hashTimer.unref?.(); + } + if (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.handlerSweepInterval); + this.handlerTimer = setInterval(() => { + const sweptHandlers = new import_collection.Collection(); + this.handlers.sweep((val, key) => { + const { inactive } = val; + if (inactive) { + sweptHandlers.set(key, val); + this.emit("restDebug" /* Debug */, `Handler ${val.id} for ${key} swept due to being inactive`); + } + return inactive; + }); + this.emit("handlerSweep" /* HandlerSweep */, sweptHandlers); + }, this.options.handlerSweepInterval); + this.handlerTimer.unref?.(); + } + } + /** + * Runs a get request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async get(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "GET" /* Get */ }); + } + /** + * Runs a delete request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async delete(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "DELETE" /* Delete */ }); + } + /** + * Runs a post request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async post(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "POST" /* Post */ }); + } + /** + * Runs a put request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async put(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PUT" /* Put */ }); + } + /** + * Runs a patch request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async patch(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PATCH" /* Patch */ }); + } + /** + * Runs a request from the api + * + * @param options - Request options + */ + async request(options) { + const response = await this.queueRequest(options); + return parseResponse(response); + } + /** + * Sets the default agent to use for requests performed by this manager + * + * @param agent - The agent to use + */ + setAgent(agent) { + this.agent = agent; + return this; + } + /** + * Sets the authorization token that should be used for requests + * + * @param token - The authorization token to use + */ + setToken(token) { + this.#token = token; + return this; + } + /** + * Queues a request to be sent + * + * @param request - All the information needed to make a request + * @returns The response from the api request + */ + async queueRequest(request2) { + const routeId = _REST.generateRouteData(request2.fullRoute, request2.method); + const hash = this.hashes.get(`${request2.method}:${routeId.bucketRoute}`) ?? { + value: `Global(${request2.method}:${routeId.bucketRoute})`, + lastAccess: -1 + }; + const handler = this.handlers.get(`${hash.value}:${routeId.majorParameter}`) ?? this.createHandler(hash.value, routeId.majorParameter); + const { url, fetchOptions } = await this.resolveRequest(request2); + return handler.queueRequest(routeId, url, fetchOptions, { + body: request2.body, + files: request2.files, + auth: request2.auth !== false, + signal: request2.signal + }); + } + /** + * Creates a new rate limit handler from a hash, based on the hash and the major parameter + * + * @param hash - The hash for the route + * @param majorParameter - The major parameter for this handler + * @internal + */ + createHandler(hash, majorParameter) { + const queue = majorParameter === BurstHandlerMajorIdKey ? new BurstHandler(this, hash, majorParameter) : new SequentialHandler(this, hash, majorParameter); + this.handlers.set(queue.id, queue); + return queue; + } + /** + * Formats the request data to a usable format for fetch + * + * @param request - The request data + */ + async resolveRequest(request2) { + const { options } = this; + let query = ""; + if (request2.query) { + const resolvedQuery = request2.query.toString(); + if (resolvedQuery !== "") { + query = `?${resolvedQuery}`; + } + } + const headers = { + ...this.options.headers, + "User-Agent": `${DefaultUserAgent} ${options.userAgentAppendix}`.trim() + }; + if (request2.auth !== false) { + if (!this.#token) { + throw new Error("Expected token to be set for this request, but none was present"); + } + headers.Authorization = `${request2.authPrefix ?? this.options.authPrefix} ${this.#token}`; + } + if (request2.reason?.length) { + headers["X-Audit-Log-Reason"] = encodeURIComponent(request2.reason); + } + const url = `${options.api}${request2.versioned === false ? "" : `/v${options.version}`}${request2.fullRoute}${query}`; + let finalBody; + let additionalHeaders = {}; + if (request2.files?.length) { + const formData = new FormData(); + for (const [index, file] of request2.files.entries()) { + const fileKey = file.key ?? `files[${index}]`; + if (isBufferLike(file.data)) { + let contentType = file.contentType; + if (!contentType) { + const [parsedType] = (0, import_magic_bytes.filetypeinfo)(file.data); + if (parsedType) { + contentType = OverwrittenMimeTypes[parsedType.mime] ?? parsedType.mime ?? "application/octet-stream"; + } + } + formData.append(fileKey, new Blob([file.data], { type: contentType }), file.name); + } else { + formData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name); + } + } + if (request2.body != null) { + if (request2.appendToFormData) { + for (const [key, value] of Object.entries(request2.body)) { + formData.append(key, value); + } + } else { + formData.append("payload_json", JSON.stringify(request2.body)); + } + } + finalBody = formData; + } else if (request2.body != null) { + if (request2.passThroughBody) { + finalBody = request2.body; + } else { + finalBody = JSON.stringify(request2.body); + additionalHeaders = { "Content-Type": "application/json" }; + } + } + const method = request2.method.toUpperCase(); + const fetchOptions = { + // Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing + body: ["GET", "HEAD"].includes(method) ? null : finalBody, + headers: { ...request2.headers, ...additionalHeaders, ...headers }, + method, + // Prioritize setting an agent per request, use the agent for this instance otherwise. + dispatcher: request2.dispatcher ?? this.agent ?? void 0 + }; + return { url, fetchOptions }; + } + /** + * Stops the hash sweeping interval + */ + clearHashSweeper() { + clearInterval(this.hashTimer); + } + /** + * Stops the request handler sweeping interval + */ + clearHandlerSweeper() { + clearInterval(this.handlerTimer); + } + /** + * Generates route data for an endpoint:method + * + * @param endpoint - The raw endpoint to generalize + * @param method - The HTTP method this endpoint is called without + * @internal + */ + static generateRouteData(endpoint, method) { + if (endpoint.startsWith("/interactions/") && endpoint.endsWith("/callback")) { + return { + majorParameter: BurstHandlerMajorIdKey, + bucketRoute: "/interactions/:id/:token/callback", + original: endpoint + }; + } + const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{17,19})/.exec(endpoint); + const majorId = majorIdMatch?.[1] ?? "global"; + const baseRoute = endpoint.replaceAll(/\d{17,19}/g, ":id").replace(/\/reactions\/(.*)/, "/reactions/:reaction"); + let exceptions = ""; + if (method === "DELETE" /* Delete */ && baseRoute === "/channels/:id/messages/:id") { + const id = /\d{17,19}$/.exec(endpoint)[0]; + const timestamp = import_snowflake.DiscordSnowflake.timestampFrom(id); + if (Date.now() - timestamp > 1e3 * 60 * 60 * 24 * 14) { + exceptions += "/Delete Old Message"; + } + } + return { + majorParameter: majorId, + bucketRoute: baseRoute + exceptions, + original: endpoint + }; + } +}; + +// src/shared.ts +var version = "2.0.1"; + +// src/index.ts +globalThis.FormData ??= import_undici2.FormData; +globalThis.Blob ??= import_node_buffer.Blob; +setDefaultStrategy((0, import_util2.shouldUseGlobalFetchAndWebSocket)() ? fetch : makeRequest); +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + ALLOWED_EXTENSIONS, + ALLOWED_SIZES, + ALLOWED_STICKER_EXTENSIONS, + BurstHandlerMajorIdKey, + CDN, + DefaultRestOptions, + DefaultUserAgent, + DefaultUserAgentAppendix, + DiscordAPIError, + HTTPError, + OverwrittenMimeTypes, + REST, + RESTEvents, + RateLimitError, + RequestMethod, + calculateUserDefaultAvatarIndex, + makeURLSearchParams, + parseResponse, + version +}); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/index.js.map b/node_modules/@discordjs/rest/dist/index.js.map new file mode 100644 index 0000000..b57aca4 --- /dev/null +++ b/node_modules/@discordjs/rest/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/environment.ts","../src/strategies/undiciRequest.ts","../src/lib/utils/constants.ts","../src/lib/CDN.ts","../src/lib/errors/DiscordAPIError.ts","../src/lib/errors/HTTPError.ts","../src/lib/errors/RateLimitError.ts","../src/lib/REST.ts","../src/lib/utils/types.ts","../src/lib/utils/utils.ts","../src/lib/handlers/Shared.ts","../src/lib/handlers/BurstHandler.ts","../src/lib/handlers/SequentialHandler.ts","../src/shared.ts"],"sourcesContent":["import { Blob } from 'node:buffer';\nimport { shouldUseGlobalFetchAndWebSocket } from '@discordjs/util';\nimport { FormData } from 'undici';\nimport { setDefaultStrategy } from './environment.js';\nimport { makeRequest } from './strategies/undiciRequest.js';\n\n// TODO(ckohen): remove once node engine req is bumped to > v18\n(globalThis as any).FormData ??= FormData;\nglobalThis.Blob ??= Blob;\n\nsetDefaultStrategy(shouldUseGlobalFetchAndWebSocket() ? fetch : makeRequest);\n\nexport * from './shared.js';\n","import type { RESTOptions } from './shared.js';\n\nlet defaultStrategy: RESTOptions['makeRequest'];\n\nexport function setDefaultStrategy(newStrategy: RESTOptions['makeRequest']) {\n\tdefaultStrategy = newStrategy;\n}\n\nexport function getDefaultStrategy() {\n\treturn defaultStrategy;\n}\n","import { STATUS_CODES } from 'node:http';\nimport { URLSearchParams } from 'node:url';\nimport { types } from 'node:util';\nimport { type RequestInit, request, Headers } from 'undici';\nimport type { ResponseLike } from '../shared.js';\n\nexport type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;\n\nexport async function makeRequest(url: string, init: RequestInit): Promise<ResponseLike> {\n\t// The cast is necessary because `headers` and `method` are narrower types in `undici.request`\n\t// our request path guarantees they are of acceptable type for `undici.request`\n\tconst options = {\n\t\t...init,\n\t\tbody: await resolveBody(init.body),\n\t} as RequestOptions;\n\tconst res = await request(url, options);\n\treturn {\n\t\tbody: res.body,\n\t\tasync arrayBuffer() {\n\t\t\treturn res.body.arrayBuffer();\n\t\t},\n\t\tasync json() {\n\t\t\treturn res.body.json();\n\t\t},\n\t\tasync text() {\n\t\t\treturn res.body.text();\n\t\t},\n\t\tget bodyUsed() {\n\t\t\treturn res.body.bodyUsed;\n\t\t},\n\t\theaders: new Headers(res.headers as Record<string, string[] | string>),\n\t\tstatus: res.statusCode,\n\t\tstatusText: STATUS_CODES[res.statusCode]!,\n\t\tok: res.statusCode >= 200 && res.statusCode < 300,\n\t};\n}\n\nexport async function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>> {\n\t// eslint-disable-next-line no-eq-null, eqeqeq\n\tif (body == null) {\n\t\treturn null;\n\t} else if (typeof body === 'string') {\n\t\treturn body;\n\t} else if (types.isUint8Array(body)) {\n\t\treturn body;\n\t} else if (types.isArrayBuffer(body)) {\n\t\treturn new Uint8Array(body);\n\t} else if (body instanceof URLSearchParams) {\n\t\treturn body.toString();\n\t} else if (body instanceof DataView) {\n\t\treturn new Uint8Array(body.buffer);\n\t} else if (body instanceof Blob) {\n\t\treturn new Uint8Array(await body.arrayBuffer());\n\t} else if (body instanceof FormData) {\n\t\treturn body;\n\t} else if ((body as Iterable<Uint8Array>)[Symbol.iterator]) {\n\t\tconst chunks = [...(body as Iterable<Uint8Array>)];\n\n\t\treturn Buffer.concat(chunks);\n\t} else if ((body as AsyncIterable<Uint8Array>)[Symbol.asyncIterator]) {\n\t\tconst chunks: Uint8Array[] = [];\n\n\t\tfor await (const chunk of body as AsyncIterable<Uint8Array>) {\n\t\t\tchunks.push(chunk);\n\t\t}\n\n\t\treturn Buffer.concat(chunks);\n\t}\n\n\tthrow new TypeError(`Unable to resolve body.`);\n}\n","import { getUserAgentAppendix } from '@discordjs/util';\nimport { APIVersion } from 'discord-api-types/v10';\nimport { getDefaultStrategy } from '../../environment.js';\nimport type { RESTOptions, ResponseLike } from './types.js';\n\nexport const DefaultUserAgent =\n\t`DiscordBot (https://discord.js.org, 2.0.1)` as `DiscordBot (https://discord.js.org, ${string})`;\n\n/**\n * The default string to append onto the user agent.\n */\nexport const DefaultUserAgentAppendix = getUserAgentAppendix();\n\nexport const DefaultRestOptions = {\n\tagent: null,\n\tapi: 'https://discord.com/api',\n\tauthPrefix: 'Bot',\n\tcdn: 'https://cdn.discordapp.com',\n\theaders: {},\n\tinvalidRequestWarningInterval: 0,\n\tglobalRequestsPerSecond: 50,\n\toffset: 50,\n\trejectOnRateLimit: null,\n\tretries: 3,\n\ttimeout: 15_000,\n\tuserAgentAppendix: DefaultUserAgentAppendix,\n\tversion: APIVersion,\n\thashSweepInterval: 14_400_000, // 4 Hours\n\thashLifetime: 86_400_000, // 24 Hours\n\thandlerSweepInterval: 3_600_000, // 1 Hour\n\tasync makeRequest(...args): Promise<ResponseLike> {\n\t\treturn getDefaultStrategy()(...args);\n\t},\n} as const satisfies Required<RESTOptions>;\n\n/**\n * The events that the REST manager emits\n */\nexport enum RESTEvents {\n\tDebug = 'restDebug',\n\tHandlerSweep = 'handlerSweep',\n\tHashSweep = 'hashSweep',\n\tInvalidRequestWarning = 'invalidRequestWarning',\n\tRateLimited = 'rateLimited',\n\tResponse = 'response',\n}\n\nexport const ALLOWED_EXTENSIONS = ['webp', 'png', 'jpg', 'jpeg', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_STICKER_EXTENSIONS = ['png', 'json', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096] as const satisfies readonly number[];\n\nexport type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];\nexport type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];\nexport type ImageSize = (typeof ALLOWED_SIZES)[number];\n\nexport const OverwrittenMimeTypes = {\n\t// https://github.com/discordjs/discord.js/issues/8557\n\t'image/apng': 'image/png',\n} as const satisfies Readonly<Record<string, string>>;\n\nexport const BurstHandlerMajorIdKey = 'burst';\n","/* eslint-disable jsdoc/check-param-names */\nimport {\n\tALLOWED_EXTENSIONS,\n\tALLOWED_SIZES,\n\tALLOWED_STICKER_EXTENSIONS,\n\tDefaultRestOptions,\n\ttype ImageExtension,\n\ttype ImageSize,\n\ttype StickerExtension,\n} from './utils/constants.js';\n\n/**\n * The options used for image URLs\n */\nexport interface BaseImageURLOptions {\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: ImageExtension;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The options used for image URLs with animated content\n */\nexport interface ImageURLOptions extends BaseImageURLOptions {\n\t/**\n\t * Whether or not to prefer the static version of an image asset.\n\t */\n\tforceStatic?: boolean;\n}\n\n/**\n * The options to use when making a CDN URL\n */\nexport interface MakeURLOptions {\n\t/**\n\t * The allowed extensions that can be used\n\t */\n\tallowedExtensions?: readonly string[];\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: string | undefined;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The CDN link builder\n */\nexport class CDN {\n\tpublic constructor(private readonly base: string = DefaultRestOptions.cdn) {}\n\n\t/**\n\t * Generates an app asset URL for a client's asset.\n\t *\n\t * @param clientId - The client id that has the asset\n\t * @param assetHash - The hash provided by Discord for this asset\n\t * @param options - Optional options for the asset\n\t */\n\tpublic appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/${clientId}/${assetHash}`, options);\n\t}\n\n\t/**\n\t * Generates an app icon URL for a client's icon.\n\t *\n\t * @param clientId - The client id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-icons/${clientId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates an avatar URL, e.g. for a user or a webhook.\n\t *\n\t * @param id - The id that has the icon\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a user avatar decoration URL.\n\t *\n\t * @param userId - The id of the user\n\t * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration\n\t * @param options - Optional options for the avatar decoration\n\t */\n\tpublic avatarDecoration(\n\t\tuserId: string,\n\t\tuserAvatarDecoration: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);\n\t}\n\n\t/**\n\t * Generates a banner URL, e.g. for a user or a guild.\n\t *\n\t * @param id - The id that has the banner splash\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL for a channel, e.g. a group DM.\n\t *\n\t * @param channelId - The channel id that has the icon\n\t * @param iconHash - The hash provided by Discord for this channel\n\t * @param options - Optional options for the icon\n\t */\n\tpublic channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a default avatar URL\n\t *\n\t * @param index - The default avatar index\n\t * @remarks\n\t * To calculate the index for a user do `(userId >> 22) % 6`,\n\t * or `discriminator % 5` if they're using the legacy username system.\n\t */\n\tpublic defaultAvatar(index: number): string {\n\t\treturn this.makeURL(`/embed/avatars/${index}`, { extension: 'png' });\n\t}\n\n\t/**\n\t * Generates a discovery splash URL for a guild's discovery splash.\n\t *\n\t * @param guildId - The guild id that has the discovery splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates an emoji's URL for an emoji.\n\t *\n\t * @param emojiId - The emoji id\n\t * @param extension - The extension of the emoji\n\t */\n\tpublic emoji(emojiId: string, extension?: ImageExtension): string {\n\t\treturn this.makeURL(`/emojis/${emojiId}`, { extension });\n\t}\n\n\t/**\n\t * Generates a guild member avatar URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic guildMemberAvatar(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tavatarHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a guild member banner URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic guildMemberBanner(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tbannerHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL, e.g. for a guild.\n\t *\n\t * @param id - The id that has the icon splash\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options);\n\t}\n\n\t/**\n\t * Generates a URL for the icon of a role\n\t *\n\t * @param roleId - The id of the role that has the icon\n\t * @param roleIconHash - The hash provided by Discord for this role icon\n\t * @param options - Optional options for the role icon\n\t */\n\tpublic roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a guild invite splash URL for a guild's invite splash.\n\t *\n\t * @param guildId - The guild id that has the invite splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates a sticker URL.\n\t *\n\t * @param stickerId - The sticker id\n\t * @param extension - The extension of the sticker\n\t * @privateRemarks\n\t * Stickers cannot have a `.webp` extension, so we default to a `.png`\n\t */\n\tpublic sticker(stickerId: string, extension: StickerExtension = 'png'): string {\n\t\treturn this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension });\n\t}\n\n\t/**\n\t * Generates a sticker pack banner URL.\n\t *\n\t * @param bannerId - The banner id\n\t * @param options - Optional options for the banner\n\t */\n\tpublic stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options);\n\t}\n\n\t/**\n\t * Generates a team icon URL for a team's icon.\n\t *\n\t * @param teamId - The team id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/team-icons/${teamId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a cover image for a guild scheduled event.\n\t *\n\t * @param scheduledEventId - The scheduled event id\n\t * @param coverHash - The hash provided by discord for this cover image\n\t * @param options - Optional options for the cover image\n\t */\n\tpublic guildScheduledEventCover(\n\t\tscheduledEventId: string,\n\t\tcoverHash: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.\n\t *\n\t * @param route - The base cdn route\n\t * @param hash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the link\n\t */\n\tprivate dynamicMakeURL(\n\t\troute: string,\n\t\thash: string,\n\t\t{ forceStatic = false, ...options }: Readonly<ImageURLOptions> = {},\n\t): string {\n\t\treturn this.makeURL(route, !forceStatic && hash.startsWith('a_') ? { ...options, extension: 'gif' } : options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource\n\t *\n\t * @param route - The base cdn route\n\t * @param options - The extension/size options for the link\n\t */\n\tprivate makeURL(\n\t\troute: string,\n\t\t{ allowedExtensions = ALLOWED_EXTENSIONS, extension = 'webp', size }: Readonly<MakeURLOptions> = {},\n\t): string {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\textension = String(extension).toLowerCase();\n\n\t\tif (!allowedExtensions.includes(extension)) {\n\t\t\tthrow new RangeError(`Invalid extension provided: ${extension}\\nMust be one of: ${allowedExtensions.join(', ')}`);\n\t\t}\n\n\t\tif (size && !ALLOWED_SIZES.includes(size)) {\n\t\t\tthrow new RangeError(`Invalid size provided: ${size}\\nMust be one of: ${ALLOWED_SIZES.join(', ')}`);\n\t\t}\n\n\t\tconst url = new URL(`${this.base}${route}.${extension}`);\n\n\t\tif (size) {\n\t\t\turl.searchParams.set('size', String(size));\n\t\t}\n\n\t\treturn url.toString();\n\t}\n}\n","import type { InternalRequest, RawFile } from '../utils/types.js';\n\ninterface DiscordErrorFieldInformation {\n\tcode: string;\n\tmessage: string;\n}\n\ninterface DiscordErrorGroupWrapper {\n\t_errors: DiscordError[];\n}\n\ntype DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | { [k: string]: DiscordError };\n\nexport interface DiscordErrorData {\n\tcode: number;\n\terrors?: DiscordError;\n\tmessage: string;\n}\n\nexport interface OAuthErrorData {\n\terror: string;\n\terror_description?: string;\n}\n\nexport interface RequestBody {\n\tfiles: RawFile[] | undefined;\n\tjson: unknown | undefined;\n}\n\nfunction isErrorGroupWrapper(error: DiscordError): error is DiscordErrorGroupWrapper {\n\treturn Reflect.has(error as Record<string, unknown>, '_errors');\n}\n\nfunction isErrorResponse(error: DiscordError): error is DiscordErrorFieldInformation {\n\treturn typeof Reflect.get(error as Record<string, unknown>, 'message') === 'string';\n}\n\n/**\n * Represents an API error returned by Discord\n */\nexport class DiscordAPIError extends Error {\n\tpublic requestBody: RequestBody;\n\n\t/**\n\t * @param rawError - The error reported by Discord\n\t * @param code - The error code reported by Discord\n\t * @param status - The status code of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic rawError: DiscordErrorData | OAuthErrorData,\n\t\tpublic code: number | string,\n\t\tpublic status: number,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(DiscordAPIError.getMessage(rawError));\n\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${DiscordAPIError.name}[${this.code}]`;\n\t}\n\n\tprivate static getMessage(error: DiscordErrorData | OAuthErrorData) {\n\t\tlet flattened = '';\n\t\tif ('code' in error) {\n\t\t\tif (error.errors) {\n\t\t\t\tflattened = [...this.flattenDiscordError(error.errors)].join('\\n');\n\t\t\t}\n\n\t\t\treturn error.message && flattened\n\t\t\t\t? `${error.message}\\n${flattened}`\n\t\t\t\t: error.message || flattened || 'Unknown Error';\n\t\t}\n\n\t\treturn error.error_description ?? 'No Description';\n\t}\n\n\tprivate static *flattenDiscordError(obj: DiscordError, key = ''): IterableIterator<string> {\n\t\tif (isErrorResponse(obj)) {\n\t\t\treturn yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim();\n\t\t}\n\n\t\tfor (const [otherKey, val] of Object.entries(obj)) {\n\t\t\tconst nextKey = otherKey.startsWith('_')\n\t\t\t\t? key\n\t\t\t\t: key\n\t\t\t\t? Number.isNaN(Number(otherKey))\n\t\t\t\t\t? `${key}.${otherKey}`\n\t\t\t\t\t: `${key}[${otherKey}]`\n\t\t\t\t: otherKey;\n\n\t\t\tif (typeof val === 'string') {\n\t\t\t\tyield val;\n\t\t\t} else if (isErrorGroupWrapper(val)) {\n\t\t\t\tfor (const error of val._errors) {\n\t\t\t\t\tyield* this.flattenDiscordError(error, nextKey);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield* this.flattenDiscordError(val, nextKey);\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { InternalRequest } from '../utils/types.js';\nimport type { RequestBody } from './DiscordAPIError.js';\n\n/**\n * Represents a HTTP error\n */\nexport class HTTPError extends Error {\n\tpublic requestBody: RequestBody;\n\n\tpublic override name = HTTPError.name;\n\n\t/**\n\t * @param status - The status code of the response\n\t * @param statusText - The status text of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic status: number,\n\t\tstatusText: string,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(statusText);\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n}\n","import type { RateLimitData } from '../utils/types.js';\n\nexport class RateLimitError extends Error implements RateLimitData {\n\tpublic timeToReset: number;\n\n\tpublic limit: number;\n\n\tpublic method: string;\n\n\tpublic hash: string;\n\n\tpublic url: string;\n\n\tpublic route: string;\n\n\tpublic majorParameter: string;\n\n\tpublic global: boolean;\n\n\tpublic constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData) {\n\t\tsuper();\n\t\tthis.timeToReset = timeToReset;\n\t\tthis.limit = limit;\n\t\tthis.method = method;\n\t\tthis.hash = hash;\n\t\tthis.url = url;\n\t\tthis.route = route;\n\t\tthis.majorParameter = majorParameter;\n\t\tthis.global = global;\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${RateLimitError.name}[${this.route}]`;\n\t}\n}\n","import { Collection } from '@discordjs/collection';\nimport { DiscordSnowflake } from '@sapphire/snowflake';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { filetypeinfo } from 'magic-bytes.js';\nimport type { RequestInit, BodyInit, Dispatcher } from 'undici';\nimport { CDN } from './CDN.js';\nimport { BurstHandler } from './handlers/BurstHandler.js';\nimport { SequentialHandler } from './handlers/SequentialHandler.js';\nimport type { IHandler } from './interfaces/Handler.js';\nimport {\n\tBurstHandlerMajorIdKey,\n\tDefaultRestOptions,\n\tDefaultUserAgent,\n\tOverwrittenMimeTypes,\n\tRESTEvents,\n} from './utils/constants.js';\nimport { RequestMethod } from './utils/types.js';\nimport type {\n\tRESTOptions,\n\tResponseLike,\n\tRestEventsMap,\n\tHashData,\n\tInternalRequest,\n\tRouteLike,\n\tRequestHeaders,\n\tRouteData,\n\tRequestData,\n} from './utils/types.js';\nimport { isBufferLike, parseResponse } from './utils/utils.js';\n\n/**\n * Represents the class that manages handlers for endpoints\n */\nexport class REST extends AsyncEventEmitter<RestEventsMap> {\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests\n\t * performed by this manager.\n\t */\n\tpublic agent: Dispatcher | null = null;\n\n\tpublic readonly cdn: CDN;\n\n\t/**\n\t * The number of requests remaining in the global bucket\n\t */\n\tpublic globalRemaining: number;\n\n\t/**\n\t * The promise used to wait out the global rate limit\n\t */\n\tpublic globalDelay: Promise<void> | null = null;\n\n\t/**\n\t * The timestamp at which the global bucket resets\n\t */\n\tpublic globalReset = -1;\n\n\t/**\n\t * API bucket hashes that are cached from provided routes\n\t */\n\tpublic readonly hashes = new Collection<string, HashData>();\n\n\t/**\n\t * Request handlers created from the bucket hash and the major parameters\n\t */\n\tpublic readonly handlers = new Collection<string, IHandler>();\n\n\t#token: string | null = null;\n\n\tprivate hashTimer!: NodeJS.Timer | number;\n\n\tprivate handlerTimer!: NodeJS.Timer | number;\n\n\tpublic readonly options: RESTOptions;\n\n\tpublic constructor(options: Partial<RESTOptions> = {}) {\n\t\tsuper();\n\t\tthis.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn);\n\t\tthis.options = { ...DefaultRestOptions, ...options };\n\t\tthis.options.offset = Math.max(0, this.options.offset);\n\t\tthis.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond);\n\t\tthis.agent = options.agent ?? null;\n\n\t\t// Start sweepers\n\t\tthis.setupSweepers();\n\t}\n\n\tprivate setupSweepers() {\n\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\tconst validateMaxInterval = (interval: number) => {\n\t\t\tif (interval > 14_400_000) {\n\t\t\t\tthrow new Error('Cannot set an interval greater than 4 hours');\n\t\t\t}\n\t\t};\n\n\t\tif (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.hashSweepInterval);\n\t\t\tthis.hashTimer = setInterval(() => {\n\t\t\t\tconst sweptHashes = new Collection<string, HashData>();\n\t\t\t\tconst currentDate = Date.now();\n\n\t\t\t\t// Begin sweeping hash based on lifetimes\n\t\t\t\tthis.hashes.sweep((val, key) => {\n\t\t\t\t\t// `-1` indicates a global hash\n\t\t\t\t\tif (val.lastAccess === -1) return false;\n\n\t\t\t\t\t// Check if lifetime has been exceeded\n\t\t\t\t\tconst shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime;\n\n\t\t\t\t\t// Add hash to collection of swept hashes\n\t\t\t\t\tif (shouldSweep) {\n\t\t\t\t\t\t// Add to swept hashes\n\t\t\t\t\t\tsweptHashes.set(key, val);\n\n\t\t\t\t\t\t// Emit debug information\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn shouldSweep;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HashSweep, sweptHashes);\n\t\t\t}, this.options.hashSweepInterval);\n\n\t\t\tthis.hashTimer.unref?.();\n\t\t}\n\n\t\tif (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.handlerSweepInterval);\n\t\t\tthis.handlerTimer = setInterval(() => {\n\t\t\t\tconst sweptHandlers = new Collection<string, IHandler>();\n\n\t\t\t\t// Begin sweeping handlers based on activity\n\t\t\t\tthis.handlers.sweep((val, key) => {\n\t\t\t\t\tconst { inactive } = val;\n\n\t\t\t\t\t// Collect inactive handlers\n\t\t\t\t\tif (inactive) {\n\t\t\t\t\t\tsweptHandlers.set(key, val);\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Handler ${val.id} for ${key} swept due to being inactive`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn inactive;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HandlerSweep, sweptHandlers);\n\t\t\t}, this.options.handlerSweepInterval);\n\n\t\t\tthis.handlerTimer.unref?.();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a get request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async get(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Get });\n\t}\n\n\t/**\n\t * Runs a delete request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async delete(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Delete });\n\t}\n\n\t/**\n\t * Runs a post request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async post(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Post });\n\t}\n\n\t/**\n\t * Runs a put request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async put(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Put });\n\t}\n\n\t/**\n\t * Runs a patch request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async patch(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Patch });\n\t}\n\n\t/**\n\t * Runs a request from the api\n\t *\n\t * @param options - Request options\n\t */\n\tpublic async request(options: InternalRequest) {\n\t\tconst response = await this.queueRequest(options);\n\t\treturn parseResponse(response);\n\t}\n\n\t/**\n\t * Sets the default agent to use for requests performed by this manager\n\t *\n\t * @param agent - The agent to use\n\t */\n\tpublic setAgent(agent: Dispatcher) {\n\t\tthis.agent = agent;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the authorization token that should be used for requests\n\t *\n\t * @param token - The authorization token to use\n\t */\n\tpublic setToken(token: string) {\n\t\tthis.#token = token;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Queues a request to be sent\n\t *\n\t * @param request - All the information needed to make a request\n\t * @returns The response from the api request\n\t */\n\tpublic async queueRequest(request: InternalRequest): Promise<ResponseLike> {\n\t\t// Generalize the endpoint to its route data\n\t\tconst routeId = REST.generateRouteData(request.fullRoute, request.method);\n\t\t// Get the bucket hash for the generic route, or point to a global route otherwise\n\t\tconst hash = this.hashes.get(`${request.method}:${routeId.bucketRoute}`) ?? {\n\t\t\tvalue: `Global(${request.method}:${routeId.bucketRoute})`,\n\t\t\tlastAccess: -1,\n\t\t};\n\n\t\t// Get the request handler for the obtained hash, with its major parameter\n\t\tconst handler =\n\t\t\tthis.handlers.get(`${hash.value}:${routeId.majorParameter}`) ??\n\t\t\tthis.createHandler(hash.value, routeId.majorParameter);\n\n\t\t// Resolve the request into usable fetch options\n\t\tconst { url, fetchOptions } = await this.resolveRequest(request);\n\n\t\t// Queue the request\n\t\treturn handler.queueRequest(routeId, url, fetchOptions, {\n\t\t\tbody: request.body,\n\t\t\tfiles: request.files,\n\t\t\tauth: request.auth !== false,\n\t\t\tsignal: request.signal,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a new rate limit handler from a hash, based on the hash and the major parameter\n\t *\n\t * @param hash - The hash for the route\n\t * @param majorParameter - The major parameter for this handler\n\t * @internal\n\t */\n\tprivate createHandler(hash: string, majorParameter: string) {\n\t\t// Create the async request queue to handle requests\n\t\tconst queue =\n\t\t\tmajorParameter === BurstHandlerMajorIdKey\n\t\t\t\t? new BurstHandler(this, hash, majorParameter)\n\t\t\t\t: new SequentialHandler(this, hash, majorParameter);\n\t\t// Save the queue based on its id\n\t\tthis.handlers.set(queue.id, queue);\n\n\t\treturn queue;\n\t}\n\n\t/**\n\t * Formats the request data to a usable format for fetch\n\t *\n\t * @param request - The request data\n\t */\n\tprivate async resolveRequest(request: InternalRequest): Promise<{ fetchOptions: RequestInit; url: string }> {\n\t\tconst { options } = this;\n\n\t\tlet query = '';\n\n\t\t// If a query option is passed, use it\n\t\tif (request.query) {\n\t\t\tconst resolvedQuery = request.query.toString();\n\t\t\tif (resolvedQuery !== '') {\n\t\t\t\tquery = `?${resolvedQuery}`;\n\t\t\t}\n\t\t}\n\n\t\t// Create the required headers\n\t\tconst headers: RequestHeaders = {\n\t\t\t...this.options.headers,\n\t\t\t'User-Agent': `${DefaultUserAgent} ${options.userAgentAppendix}`.trim(),\n\t\t};\n\n\t\t// If this request requires authorization (allowing non-\"authorized\" requests for webhooks)\n\t\tif (request.auth !== false) {\n\t\t\t// If we haven't received a token, throw an error\n\t\t\tif (!this.#token) {\n\t\t\t\tthrow new Error('Expected token to be set for this request, but none was present');\n\t\t\t}\n\n\t\t\theaders.Authorization = `${request.authPrefix ?? this.options.authPrefix} ${this.#token}`;\n\t\t}\n\n\t\t// If a reason was set, set it's appropriate header\n\t\tif (request.reason?.length) {\n\t\t\theaders['X-Audit-Log-Reason'] = encodeURIComponent(request.reason);\n\t\t}\n\n\t\t// Format the full request URL (api base, optional version, endpoint, optional querystring)\n\t\tconst url = `${options.api}${request.versioned === false ? '' : `/v${options.version}`}${\n\t\t\trequest.fullRoute\n\t\t}${query}`;\n\n\t\tlet finalBody: RequestInit['body'];\n\t\tlet additionalHeaders: Record<string, string> = {};\n\n\t\tif (request.files?.length) {\n\t\t\tconst formData = new FormData();\n\n\t\t\t// Attach all files to the request\n\t\t\tfor (const [index, file] of request.files.entries()) {\n\t\t\t\tconst fileKey = file.key ?? `files[${index}]`;\n\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#parameters\n\t\t\t\t// FormData.append only accepts a string or Blob.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters\n\t\t\t\t// The Blob constructor accepts TypedArray/ArrayBuffer, strings, and Blobs.\n\t\t\t\tif (isBufferLike(file.data)) {\n\t\t\t\t\t// Try to infer the content type from the buffer if one isn't passed\n\t\t\t\t\tlet contentType = file.contentType;\n\n\t\t\t\t\tif (!contentType) {\n\t\t\t\t\t\tconst [parsedType] = filetypeinfo(file.data);\n\n\t\t\t\t\t\tif (parsedType) {\n\t\t\t\t\t\t\tcontentType =\n\t\t\t\t\t\t\t\tOverwrittenMimeTypes[parsedType.mime as keyof typeof OverwrittenMimeTypes] ??\n\t\t\t\t\t\t\t\tparsedType.mime ??\n\t\t\t\t\t\t\t\t'application/octet-stream';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tformData.append(fileKey, new Blob([file.data], { type: contentType }), file.name);\n\t\t\t\t} else {\n\t\t\t\t\tformData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If a JSON body was added as well, attach it to the form data, using payload_json unless otherwise specified\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t\tif (request.body != null) {\n\t\t\t\tif (request.appendToFormData) {\n\t\t\t\t\tfor (const [key, value] of Object.entries(request.body as Record<string, unknown>)) {\n\t\t\t\t\t\tformData.append(key, value);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tformData.append('payload_json', JSON.stringify(request.body));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Set the final body to the form data\n\t\t\tfinalBody = formData;\n\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t} else if (request.body != null) {\n\t\t\tif (request.passThroughBody) {\n\t\t\t\tfinalBody = request.body as BodyInit;\n\t\t\t} else {\n\t\t\t\t// Stringify the JSON data\n\t\t\t\tfinalBody = JSON.stringify(request.body);\n\t\t\t\t// Set the additional headers to specify the content-type\n\t\t\t\tadditionalHeaders = { 'Content-Type': 'application/json' };\n\t\t\t}\n\t\t}\n\n\t\tconst method = request.method.toUpperCase();\n\n\t\t// The non null assertions in the following block are due to exactOptionalPropertyTypes, they have been tested to work with undefined\n\t\tconst fetchOptions: RequestInit = {\n\t\t\t// Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing\n\t\t\tbody: ['GET', 'HEAD'].includes(method) ? null : finalBody!,\n\t\t\theaders: { ...request.headers, ...additionalHeaders, ...headers } as Record<string, string>,\n\t\t\tmethod,\n\t\t\t// Prioritize setting an agent per request, use the agent for this instance otherwise.\n\t\t\tdispatcher: request.dispatcher ?? this.agent ?? undefined!,\n\t\t};\n\n\t\treturn { url, fetchOptions };\n\t}\n\n\t/**\n\t * Stops the hash sweeping interval\n\t */\n\tpublic clearHashSweeper() {\n\t\tclearInterval(this.hashTimer);\n\t}\n\n\t/**\n\t * Stops the request handler sweeping interval\n\t */\n\tpublic clearHandlerSweeper() {\n\t\tclearInterval(this.handlerTimer);\n\t}\n\n\t/**\n\t * Generates route data for an endpoint:method\n\t *\n\t * @param endpoint - The raw endpoint to generalize\n\t * @param method - The HTTP method this endpoint is called without\n\t * @internal\n\t */\n\tprivate static generateRouteData(endpoint: RouteLike, method: RequestMethod): RouteData {\n\t\tif (endpoint.startsWith('/interactions/') && endpoint.endsWith('/callback')) {\n\t\t\treturn {\n\t\t\t\tmajorParameter: BurstHandlerMajorIdKey,\n\t\t\t\tbucketRoute: '/interactions/:id/:token/callback',\n\t\t\t\toriginal: endpoint,\n\t\t\t};\n\t\t}\n\n\t\tconst majorIdMatch = /^\\/(?:channels|guilds|webhooks)\\/(\\d{17,19})/.exec(endpoint);\n\n\t\t// Get the major id for this route - global otherwise\n\t\tconst majorId = majorIdMatch?.[1] ?? 'global';\n\n\t\tconst baseRoute = endpoint\n\t\t\t// Strip out all ids\n\t\t\t.replaceAll(/\\d{17,19}/g, ':id')\n\t\t\t// Strip out reaction as they fall under the same bucket\n\t\t\t.replace(/\\/reactions\\/(.*)/, '/reactions/:reaction');\n\n\t\tlet exceptions = '';\n\n\t\t// Hard-Code Old Message Deletion Exception (2 week+ old messages are a different bucket)\n\t\t// https://github.com/discord/discord-api-docs/issues/1295\n\t\tif (method === RequestMethod.Delete && baseRoute === '/channels/:id/messages/:id') {\n\t\t\tconst id = /\\d{17,19}$/.exec(endpoint)![0]!;\n\t\t\tconst timestamp = DiscordSnowflake.timestampFrom(id);\n\t\t\tif (Date.now() - timestamp > 1_000 * 60 * 60 * 24 * 14) {\n\t\t\t\texceptions += '/Delete Old Message';\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tmajorParameter: majorId,\n\t\t\tbucketRoute: baseRoute + exceptions,\n\t\t\toriginal: endpoint,\n\t\t};\n\t}\n}\n","import type { Readable } from 'node:stream';\nimport type { ReadableStream } from 'node:stream/web';\nimport type { Collection } from '@discordjs/collection';\nimport type { Agent, Dispatcher, RequestInit, BodyInit, Response } from 'undici';\nimport type { IHandler } from '../interfaces/Handler.js';\n\nexport interface RestEvents {\n\thandlerSweep: [sweptHandlers: Collection<string, IHandler>];\n\thashSweep: [sweptHashes: Collection<string, HashData>];\n\tinvalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];\n\trateLimited: [rateLimitInfo: RateLimitData];\n\tresponse: [request: APIRequest, response: ResponseLike];\n\trestDebug: [info: string];\n}\n\nexport type RestEventsMap = {\n\t[K in keyof RestEvents]: RestEvents[K];\n};\n\n/**\n * Options to be passed when creating the REST instance\n */\nexport interface RESTOptions {\n\t/**\n\t * The agent to set globally\n\t */\n\tagent: Dispatcher | null;\n\t/**\n\t * The base api path, without version\n\t *\n\t * @defaultValue `'https://discord.com/api'`\n\t */\n\tapi: string;\n\t/**\n\t * The authorization prefix to use for requests, useful if you want to use\n\t * bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix: 'Bearer' | 'Bot';\n\t/**\n\t * The cdn path\n\t *\n\t * @defaultValue `'https://cdn.discordapp.com'`\n\t */\n\tcdn: string;\n\t/**\n\t * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)\n\t *\n\t * @defaultValue `50`\n\t */\n\tglobalRequestsPerSecond: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)\n\t *\n\t * @defaultValue `3_600_000`\n\t */\n\thandlerSweepInterval: number;\n\t/**\n\t * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)\n\t *\n\t * @defaultValue `86_400_000`\n\t */\n\thashLifetime: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)\n\t *\n\t * @defaultValue `14_400_000`\n\t */\n\thashSweepInterval: number;\n\t/**\n\t * Additional headers to send for all API requests\n\t *\n\t * @defaultValue `{}`\n\t */\n\theaders: Record<string, string>;\n\t/**\n\t * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).\n\t * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.\n\t *\n\t * @defaultValue `0`\n\t */\n\tinvalidRequestWarningInterval: number;\n\t/**\n\t * The method called to perform the actual HTTP request given a url and web `fetch` options\n\t * For example, to use global fetch, simply provide `makeRequest: fetch`\n\t */\n\tmakeRequest(url: string, init: RequestInit): Promise<ResponseLike>;\n\t/**\n\t * The extra offset to add to rate limits in milliseconds\n\t *\n\t * @defaultValue `50`\n\t */\n\toffset: number;\n\t/**\n\t * Determines how rate limiting and pre-emptive throttling should be handled.\n\t * When an array of strings, each element is treated as a prefix for the request route\n\t * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)\n\t * for which to throw {@link RateLimitError}s. All other request routes will be queued normally\n\t *\n\t * @defaultValue `null`\n\t */\n\trejectOnRateLimit: RateLimitQueueFilter | string[] | null;\n\t/**\n\t * The number of retries for errors with the 500 code, or errors\n\t * that timeout\n\t *\n\t * @defaultValue `3`\n\t */\n\tretries: number;\n\t/**\n\t * The time to wait in milliseconds before a request is aborted\n\t *\n\t * @defaultValue `15_000`\n\t */\n\ttimeout: number;\n\t/**\n\t * Extra information to add to the user agent\n\t *\n\t * @defaultValue DefaultUserAgentAppendix\n\t */\n\tuserAgentAppendix: string;\n\t/**\n\t * The version of the API to use\n\t *\n\t * @defaultValue `'10'`\n\t */\n\tversion: string;\n}\n\n/**\n * Data emitted on `RESTEvents.RateLimited`\n */\nexport interface RateLimitData {\n\t/**\n\t * Whether the rate limit that was reached was the global limit\n\t */\n\tglobal: boolean;\n\t/**\n\t * The bucket hash for this request\n\t */\n\thash: string;\n\t/**\n\t * The amount of requests we can perform before locking requests\n\t */\n\tlimit: number;\n\t/**\n\t * The major parameter of the route\n\t *\n\t * For example, in `/channels/x`, this will be `x`.\n\t * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.\n\t */\n\tmajorParameter: string;\n\t/**\n\t * The HTTP method being performed\n\t */\n\tmethod: string;\n\t/**\n\t * The route being hit in this request\n\t */\n\troute: string;\n\t/**\n\t * The time, in milliseconds, until the request-lock is reset\n\t */\n\ttimeToReset: number;\n\t/**\n\t * The full URL for this request\n\t */\n\turl: string;\n}\n\n/**\n * A function that determines whether the rate limit hit should throw an Error\n */\nexport type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Promise<boolean> | boolean;\n\nexport interface APIRequest {\n\t/**\n\t * The data that was used to form the body of this request\n\t */\n\tdata: HandlerRequestData;\n\t/**\n\t * The HTTP method used in this request\n\t */\n\tmethod: string;\n\t/**\n\t * Additional HTTP options for this request\n\t */\n\toptions: RequestInit;\n\t/**\n\t * The full path used to make the request\n\t */\n\tpath: RouteLike;\n\t/**\n\t * The number of times this request has been attempted\n\t */\n\tretries: number;\n\t/**\n\t * The API route identifying the ratelimit for this request\n\t */\n\troute: string;\n}\n\nexport interface ResponseLike\n\textends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {\n\tbody: Readable | ReadableStream | null;\n}\n\nexport interface InvalidRequestWarningData {\n\t/**\n\t * Number of invalid requests that have been made in the window\n\t */\n\tcount: number;\n\t/**\n\t * Time in milliseconds remaining before the count resets\n\t */\n\tremainingTime: number;\n}\n\n/**\n * Represents a file to be added to the request\n */\nexport interface RawFile {\n\t/**\n\t * Content-Type of the file\n\t */\n\tcontentType?: string;\n\t/**\n\t * The actual data for the file\n\t */\n\tdata: Buffer | Uint8Array | boolean | number | string;\n\t/**\n\t * An explicit key to use for key of the formdata field for this file.\n\t * When not provided, the index of the file in the files array is used in the form `files[${index}]`.\n\t * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)\n\t */\n\tkey?: string;\n\t/**\n\t * The name of the file\n\t */\n\tname: string;\n}\n\n/**\n * Represents possible data to be given to an endpoint\n */\nexport interface RequestData {\n\t/**\n\t * Whether to append JSON data to form data instead of `payload_json` when sending files\n\t */\n\tappendToFormData?: boolean;\n\t/**\n\t * If this request needs the `Authorization` header\n\t *\n\t * @defaultValue `true`\n\t */\n\tauth?: boolean;\n\t/**\n\t * The authorization prefix to use for this request, useful if you use this with bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix?: 'Bearer' | 'Bot';\n\t/**\n\t * The body to send to this request.\n\t * If providing as BodyInit, set `passThroughBody: true`\n\t */\n\tbody?: BodyInit | unknown;\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.\n\t */\n\tdispatcher?: Agent;\n\t/**\n\t * Files to be attached to this request\n\t */\n\tfiles?: RawFile[] | undefined;\n\t/**\n\t * Additional headers to add to this request\n\t */\n\theaders?: Record<string, string>;\n\t/**\n\t * Whether to pass-through the body property directly to `fetch()`.\n\t * <warn>This only applies when files is NOT present</warn>\n\t */\n\tpassThroughBody?: boolean;\n\t/**\n\t * Query string parameters to append to the called endpoint\n\t */\n\tquery?: URLSearchParams;\n\t/**\n\t * Reason to show in the audit logs\n\t */\n\treason?: string | undefined;\n\t/**\n\t * The signal to abort the queue entry or the REST call, where applicable\n\t */\n\tsignal?: AbortSignal | undefined;\n\t/**\n\t * If this request should be versioned\n\t *\n\t * @defaultValue `true`\n\t */\n\tversioned?: boolean;\n}\n\n/**\n * Possible headers for an API call\n */\nexport interface RequestHeaders {\n\tAuthorization?: string;\n\t'User-Agent': string;\n\t'X-Audit-Log-Reason'?: string;\n}\n\n/**\n * Possible API methods to be used when doing requests\n */\nexport enum RequestMethod {\n\tDelete = 'DELETE',\n\tGet = 'GET',\n\tPatch = 'PATCH',\n\tPost = 'POST',\n\tPut = 'PUT',\n}\n\nexport type RouteLike = `/${string}`;\n\n/**\n * Internal request options\n *\n * @internal\n */\nexport interface InternalRequest extends RequestData {\n\tfullRoute: RouteLike;\n\tmethod: RequestMethod;\n}\n\nexport type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;\n\n/**\n * Parsed route data for an endpoint\n *\n * @internal\n */\nexport interface RouteData {\n\tbucketRoute: string;\n\tmajorParameter: string;\n\toriginal: RouteLike;\n}\n\n/**\n * Represents a hash and its associated fields\n *\n * @internal\n */\nexport interface HashData {\n\tlastAccess: number;\n\tvalue: string;\n}\n","import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';\nimport type { REST } from '../REST.js';\nimport { RateLimitError } from '../errors/RateLimitError.js';\nimport { RequestMethod, type RateLimitData, type ResponseLike } from './types.js';\n\nfunction serializeSearchParam(value: unknown): string | null {\n\tswitch (typeof value) {\n\t\tcase 'string':\n\t\t\treturn value;\n\t\tcase 'number':\n\t\tcase 'bigint':\n\t\tcase 'boolean':\n\t\t\treturn value.toString();\n\t\tcase 'object':\n\t\t\tif (value === null) return null;\n\t\t\tif (value instanceof Date) {\n\t\t\t\treturn Number.isNaN(value.getTime()) ? null : value.toISOString();\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) return value.toString();\n\t\t\treturn null;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n/**\n * Creates and populates an URLSearchParams instance from an object, stripping\n * out null and undefined values, while also coercing non-strings to strings.\n *\n * @param options - The options to use\n * @returns A populated URLSearchParams instance\n */\nexport function makeURLSearchParams<T extends object>(options?: Readonly<T>) {\n\tconst params = new URLSearchParams();\n\tif (!options) return params;\n\n\tfor (const [key, value] of Object.entries(options)) {\n\t\tconst serialized = serializeSearchParam(value);\n\t\tif (serialized !== null) params.append(key, serialized);\n\t}\n\n\treturn params;\n}\n\n/**\n * Converts the response to usable data\n *\n * @param res - The fetch response\n */\nexport async function parseResponse(res: ResponseLike): Promise<unknown> {\n\tif (res.headers.get('Content-Type')?.startsWith('application/json')) {\n\t\treturn res.json();\n\t}\n\n\treturn res.arrayBuffer();\n}\n\n/**\n * Check whether a request falls under a sublimit\n *\n * @param bucketRoute - The buckets route identifier\n * @param body - The options provided as JSON data\n * @param method - The HTTP method that will be used to make the request\n * @returns Whether the request falls under a sublimit\n */\nexport function hasSublimit(bucketRoute: string, body?: unknown, method?: string): boolean {\n\t// TODO: Update for new sublimits\n\t// Currently known sublimits:\n\t// Editing channel `name` or `topic`\n\tif (bucketRoute === '/channels/:id') {\n\t\tif (typeof body !== 'object' || body === null) return false;\n\t\t// This should never be a POST body, but just in case\n\t\tif (method !== RequestMethod.Patch) return false;\n\t\tconst castedBody = body as RESTPatchAPIChannelJSONBody;\n\t\treturn ['name', 'topic'].some((key) => Reflect.has(castedBody, key));\n\t}\n\n\t// If we are checking if a request has a sublimit on a route not checked above, sublimit all requests to avoid a flood of 429s\n\treturn true;\n}\n\n/**\n * Check whether an error indicates that a retry can be attempted\n *\n * @param error - The error thrown by the network request\n * @returns Whether the error indicates a retry should be attempted\n */\nexport function shouldRetry(error: Error | NodeJS.ErrnoException) {\n\t// Retry for possible timed out requests\n\tif (error.name === 'AbortError') return true;\n\t// Downlevel ECONNRESET to retry as it may be recoverable\n\treturn ('code' in error && error.code === 'ECONNRESET') || error.message.includes('ECONNRESET');\n}\n\n/**\n * Determines whether the request should be queued or whether a RateLimitError should be thrown\n *\n * @internal\n */\nexport async function onRateLimit(manager: REST, rateLimitData: RateLimitData) {\n\tconst { options } = manager;\n\tif (!options.rejectOnRateLimit) return;\n\n\tconst shouldThrow =\n\t\ttypeof options.rejectOnRateLimit === 'function'\n\t\t\t? await options.rejectOnRateLimit(rateLimitData)\n\t\t\t: options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));\n\tif (shouldThrow) {\n\t\tthrow new RateLimitError(rateLimitData);\n\t}\n}\n\n/**\n * Calculates the default avatar index for a given user id.\n *\n * @param userId - The user id to calculate the default avatar index for\n */\nexport function calculateUserDefaultAvatarIndex(userId: Snowflake) {\n\treturn Number(BigInt(userId) >> 22n) % 6;\n}\n\n/**\n * Sleeps for a given amount of time.\n *\n * @param ms - The amount of time (in milliseconds) to sleep for\n */\nexport async function sleep(ms: number): Promise<void> {\n\treturn new Promise<void>((resolve) => {\n\t\tsetTimeout(() => resolve(), ms);\n\t});\n}\n\n/**\n * Verifies that a value is a buffer-like object.\n *\n * @param value - The value to check\n */\nexport function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Uint8Array | Uint8ClampedArray {\n\treturn value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError.js';\nimport { DiscordAPIError } from '../errors/DiscordAPIError.js';\nimport { HTTPError } from '../errors/HTTPError.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { parseResponse, shouldRetry } from '../utils/utils.js';\n\n/**\n * Invalid request limiting is done on a per-IP basis, not a per-token basis.\n * The best we can do is track invalid counts process-wide (on the theory that\n * users could have multiple bots run from one process) rather than per-bot.\n * Therefore, store these at file scope here rather than in the client's\n * RESTManager object.\n */\nlet invalidCount = 0;\nlet invalidCountResetTime: number | null = null;\n\n/**\n * Increment the invalid request count and emit warning if necessary\n *\n * @internal\n */\nexport function incrementInvalidCount(manager: REST) {\n\tif (!invalidCountResetTime || invalidCountResetTime < Date.now()) {\n\t\tinvalidCountResetTime = Date.now() + 1_000 * 60 * 10;\n\t\tinvalidCount = 0;\n\t}\n\n\tinvalidCount++;\n\n\tconst emitInvalid =\n\t\tmanager.options.invalidRequestWarningInterval > 0 &&\n\t\tinvalidCount % manager.options.invalidRequestWarningInterval === 0;\n\tif (emitInvalid) {\n\t\t// Let library users know periodically about invalid requests\n\t\tmanager.emit(RESTEvents.InvalidRequestWarning, {\n\t\t\tcount: invalidCount,\n\t\t\tremainingTime: invalidCountResetTime - Date.now(),\n\t\t});\n\t}\n}\n\n/**\n * Performs the actual network request for a request handler\n *\n * @param manager - The manager that holds options and emits informational events\n * @param routeId - The generalized api route with literal ids for major parameters\n * @param url - The fully resolved url to make the request to\n * @param options - The fetch options needed to make the request\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns The respond from the network or `null` when the request should be retried\n * @internal\n */\nexport async function makeNetworkRequest(\n\tmanager: REST,\n\trouteId: RouteData,\n\turl: string,\n\toptions: RequestInit,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst controller = new AbortController();\n\tconst timeout = setTimeout(() => controller.abort(), manager.options.timeout);\n\tif (requestData.signal) {\n\t\t// If the user signal was aborted, abort the controller, else abort the local signal.\n\t\t// The reason why we don't re-use the user's signal, is because users may use the same signal for multiple\n\t\t// requests, and we do not want to cause unexpected side-effects.\n\t\tif (requestData.signal.aborted) controller.abort();\n\t\telse requestData.signal.addEventListener('abort', () => controller.abort());\n\t}\n\n\tlet res: ResponseLike;\n\ttry {\n\t\tres = await manager.options.makeRequest(url, { ...options, signal: controller.signal });\n\t} catch (error: unknown) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\t// Retry the specified number of times if needed\n\t\tif (shouldRetry(error) && retries !== manager.options.retries) {\n\t\t\t// Retry is handled by the handler upon receiving null\n\t\t\treturn null;\n\t\t}\n\n\t\tthrow error;\n\t} finally {\n\t\tclearTimeout(timeout);\n\t}\n\n\tif (manager.listenerCount(RESTEvents.Response)) {\n\t\tmanager.emit(\n\t\t\tRESTEvents.Response,\n\t\t\t{\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\tpath: routeId.original,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\toptions,\n\t\t\t\tdata: requestData,\n\t\t\t\tretries,\n\t\t\t},\n\t\t\tres instanceof Response ? res.clone() : { ...res },\n\t\t);\n\t}\n\n\treturn res;\n}\n\n/**\n * Handles 5xx and 4xx errors (not 429's) conventionally. 429's should be handled before calling this function\n *\n * @param manager - The manager that holds options and emits informational events\n * @param res - The response received from {@link makeNetworkRequest}\n * @param method - The method used to make the request\n * @param url - The fully resolved url to make the request to\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns - The response if the status code is not handled or null to request a retry\n */\nexport async function handleErrors(\n\tmanager: REST,\n\tres: ResponseLike,\n\tmethod: string,\n\turl: string,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst status = res.status;\n\tif (status >= 500 && status < 600) {\n\t\t// Retry the specified number of times for possible server side issues\n\t\tif (retries !== manager.options.retries) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We are out of retries, throw an error\n\t\tthrow new HTTPError(status, res.statusText, method, url, requestData);\n\t} else {\n\t\t// Handle possible malformed requests\n\t\tif (status >= 400 && status < 500) {\n\t\t\t// If we receive this status code, it means the token we had is no longer valid.\n\t\t\tif (status === 401 && requestData.auth) {\n\t\t\t\tmanager.setToken(null!);\n\t\t\t}\n\n\t\t\t// The request will not succeed for some reason, parse the error returned from the api\n\t\t\tconst data = (await parseResponse(res)) as DiscordErrorData | OAuthErrorData;\n\t\t\t// throw the API error\n\t\t\tthrow new DiscordAPIError(data, 'code' in data ? data.code : data.error, status, method, url, requestData);\n\t\t}\n\n\t\treturn res;\n\t}\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\n/**\n * The structure used to handle burst requests for a given bucket.\n * Burst requests have no ratelimit handling but allow for pre- and post-processing\n * of data in the same manner as sequentially queued requests.\n *\n * @remarks\n * This queue may still emit a rate limit error if an unexpected 429 is hit\n */\nexport class BurstHandler implements IHandler {\n\t/**\n\t * {@inheritdoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic inactive = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\treturn this.runRequest(routeId, url, options, requestData);\n\t}\n\n\t/**\n\t * The method that actually makes the request to the API, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized API route with literal ids for major parameters\n\t * @param url - The fully resolved URL to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (status >= 200 && status < 300) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// Unexpected ratelimit\n\t\t\tconst isGlobal = res.headers.has('X-RateLimit-Global');\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: retryAfter,\n\t\t\t\tlimit: Number.POSITIVE_INFINITY,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${Number.POSITIVE_INFINITY}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : None`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\n\t\t\t// We are bypassing all other limits, but an encountered limit should be respected (it's probably a non-punished rate limit anyways)\n\t\t\tawait sleep(retryAfter);\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","import { AsyncQueue } from '@sapphire/async-queue';\nimport type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { RateLimitData, ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { hasSublimit, onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\nconst enum QueueType {\n\tStandard,\n\tSublimit,\n}\n\n/**\n * The structure used to handle sequential requests for a given bucket\n */\nexport class SequentialHandler implements IHandler {\n\t/**\n\t * {@inheritDoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * The time this rate limit bucket will reset\n\t */\n\tprivate reset = -1;\n\n\t/**\n\t * The remaining requests that can be made before we are rate limited\n\t */\n\tprivate remaining = 1;\n\n\t/**\n\t * The total number of requests that can be made before we are rate limited\n\t */\n\tprivate limit = Number.POSITIVE_INFINITY;\n\n\t/**\n\t * The interface used to sequence async requests sequentially\n\t */\n\t#asyncQueue = new AsyncQueue();\n\n\t/**\n\t * The interface used to sequence sublimited async requests sequentially\n\t */\n\t#sublimitedQueue: AsyncQueue | null = null;\n\n\t/**\n\t * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed\n\t */\n\t#sublimitPromise: { promise: Promise<void>; resolve(): void } | null = null;\n\n\t/**\n\t * Whether the sublimit queue needs to be shifted in the finally block\n\t */\n\t#shiftSublimit = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic get inactive(): boolean {\n\t\treturn (\n\t\t\tthis.#asyncQueue.remaining === 0 &&\n\t\t\t(this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) &&\n\t\t\t!this.limited\n\t\t);\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by the global limit\n\t */\n\tprivate get globalLimited(): boolean {\n\t\treturn this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by its limit\n\t */\n\tprivate get localLimited(): boolean {\n\t\treturn this.remaining <= 0 && Date.now() < this.reset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited\n\t */\n\tprivate get limited(): boolean {\n\t\treturn this.globalLimited || this.localLimited;\n\t}\n\n\t/**\n\t * The time until queued requests can continue\n\t */\n\tprivate get timeToReset(): number {\n\t\treturn this.reset + this.manager.options.offset - Date.now();\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * Delay all requests for the specified amount of time, handling global rate limits\n\t *\n\t * @param time - The amount of time to delay all requests for\n\t */\n\tprivate async globalDelayFor(time: number): Promise<void> {\n\t\tawait sleep(time);\n\t\tthis.manager.globalDelay = null;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\tlet queue = this.#asyncQueue;\n\t\tlet queueType = QueueType.Standard;\n\t\t// Separate sublimited requests when already sublimited\n\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\tqueueType = QueueType.Sublimit;\n\t\t}\n\n\t\t// Wait for any previous requests to be completed before this one is run\n\t\tawait queue.wait({ signal: requestData.signal });\n\t\t// This set handles retroactively sublimiting requests\n\t\tif (queueType === QueueType.Standard) {\n\t\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\t\t/**\n\t\t\t\t * Remove the request from the standard queue, it should never be possible to get here while processing the\n\t\t\t\t * sublimit queue so there is no need to worry about shifting the wrong request\n\t\t\t\t */\n\t\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\t\tconst wait = queue.wait();\n\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\tawait wait;\n\t\t\t} else if (this.#sublimitPromise) {\n\t\t\t\t// Stall requests while the sublimit queue gets processed\n\t\t\t\tawait this.#sublimitPromise.promise;\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request, and return the results\n\t\t\treturn await this.runRequest(routeId, url, options, requestData);\n\t\t} finally {\n\t\t\t// Allow the next request to fire\n\t\t\tqueue.shift();\n\t\t\tif (this.#shiftSublimit) {\n\t\t\t\tthis.#shiftSublimit = false;\n\t\t\t\tthis.#sublimitedQueue?.shift();\n\t\t\t}\n\n\t\t\t// If this request is the last request in a sublimit\n\t\t\tif (this.#sublimitedQueue?.remaining === 0) {\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitedQueue = null;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The method that actually makes the request to the api, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized api route with literal ids for major parameters\n\t * @param url - The fully resolved url to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\t/*\n\t\t * After calculations have been done, pre-emptively stop further requests\n\t\t * Potentially loop until this task can run if e.g. the global rate limit is hit twice\n\t\t */\n\t\twhile (this.limited) {\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\t\t\tlet delay: Promise<void>;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t\t// If this is the first task to reach the global timeout, set the global delay\n\t\t\t\tif (!this.manager.globalDelay) {\n\t\t\t\t\t// The global delay function clears the global delay state when it is resolved\n\t\t\t\t\tthis.manager.globalDelay = this.globalDelayFor(timeout);\n\t\t\t\t}\n\n\t\t\t\tdelay = this.manager.globalDelay;\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t\tdelay = sleep(timeout);\n\t\t\t}\n\n\t\t\tconst rateLimitData: RateLimitData = {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t};\n\t\t\t// Let library users know they have hit a rate limit\n\t\t\tthis.manager.emit(RESTEvents.RateLimited, rateLimitData);\n\t\t\t// Determine whether a RateLimitError should be thrown\n\t\t\tawait onRateLimit(this.manager, rateLimitData);\n\t\t\t// When not erroring, emit debug for what is happening\n\t\t\tif (isGlobal) {\n\t\t\t\tthis.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`);\n\t\t\t} else {\n\t\t\t\tthis.debug(`Waiting ${timeout}ms for rate limit to pass`);\n\t\t\t}\n\n\t\t\t// Wait the remaining time left before the rate limit resets\n\t\t\tawait delay;\n\t\t}\n\n\t\t// As the request goes out, update the global usage information\n\t\tif (!this.manager.globalReset || this.manager.globalReset < Date.now()) {\n\t\t\tthis.manager.globalReset = Date.now() + 1_000;\n\t\t\tthis.manager.globalRemaining = this.manager.options.globalRequestsPerSecond;\n\t\t}\n\n\t\tthis.manager.globalRemaining--;\n\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\n\t\tconst limit = res.headers.get('X-RateLimit-Limit');\n\t\tconst remaining = res.headers.get('X-RateLimit-Remaining');\n\t\tconst reset = res.headers.get('X-RateLimit-Reset-After');\n\t\tconst hash = res.headers.get('X-RateLimit-Bucket');\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Update the total number of requests that can be made before the rate limit resets\n\t\tthis.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY;\n\t\t// Update the number of remaining requests that can be made before the rate limit resets\n\t\tthis.remaining = remaining ? Number(remaining) : 1;\n\t\t// Update the time when this rate limit resets (reset-after is in seconds)\n\t\tthis.reset = reset ? Number(reset) * 1_000 + Date.now() + this.manager.options.offset : Date.now();\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Handle buckets via the hash header retroactively\n\t\tif (hash && hash !== this.hash) {\n\t\t\t// Let library users know when rate limit buckets have been updated\n\t\t\tthis.debug(['Received bucket hash update', ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join('\\n'));\n\t\t\t// This queue will eventually be eliminated via attrition\n\t\t\tthis.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() });\n\t\t} else if (hash) {\n\t\t\t// Handle the case where hash value doesn't change\n\t\t\t// Fetch the hash data from the manager\n\t\t\tconst hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`);\n\n\t\t\t// When fetched, update the last access of the hash\n\t\t\tif (hashData) {\n\t\t\t\thashData.lastAccess = Date.now();\n\t\t\t}\n\t\t}\n\n\t\t// Handle retryAfter, which means we have actually hit a rate limit\n\t\tlet sublimitTimeout: number | null = null;\n\t\tif (retryAfter > 0) {\n\t\t\tif (res.headers.has('X-RateLimit-Global')) {\n\t\t\t\tthis.manager.globalRemaining = 0;\n\t\t\t\tthis.manager.globalReset = Date.now() + retryAfter;\n\t\t\t} else if (!this.localLimited) {\n\t\t\t\t/*\n\t\t\t\t * This is a sublimit (e.g. 2 channel name changes/10 minutes) since the headers don't indicate a\n\t\t\t\t * route-wide rate limit. Don't update remaining or reset to avoid rate limiting the whole\n\t\t\t\t * endpoint, just set a reset time on the request itself to avoid retrying too soon.\n\t\t\t\t */\n\t\t\t\tsublimitTimeout = retryAfter;\n\t\t\t}\n\t\t}\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (res.ok) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// A rate limit was hit - this may happen if the route isn't associated with an official bucket hash yet, or when first globally rate limited\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t}\n\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal.toString()}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${limit}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : 'None'}`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\t\t\t// If caused by a sublimit, wait it out here so other requests on the route can be handled\n\t\t\tif (sublimitTimeout) {\n\t\t\t\t// Normally the sublimit queue will not exist, however, if a sublimit is hit while in the sublimit queue, it will\n\t\t\t\tconst firstSublimit = !this.#sublimitedQueue;\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\tthis.#sublimitedQueue = new AsyncQueue();\n\t\t\t\t\tvoid this.#sublimitedQueue.wait();\n\t\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\t}\n\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitPromise = null;\n\t\t\t\tawait sleep(sublimitTimeout);\n\t\t\t\tlet resolve: () => void;\n\t\t\t\t// eslint-disable-next-line promise/param-names, no-promise-executor-return\n\t\t\t\tconst promise = new Promise<void>((res) => (resolve = res));\n\t\t\t\tthis.#sublimitPromise = { promise, resolve: resolve! };\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\t// Re-queue this request so it can be shifted by the finally\n\t\t\t\t\tawait this.#asyncQueue.wait();\n\t\t\t\t\tthis.#shiftSublimit = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","export * from './lib/CDN.js';\nexport * from './lib/errors/DiscordAPIError.js';\nexport * from './lib/errors/HTTPError.js';\nexport * from './lib/errors/RateLimitError.js';\nexport * from './lib/REST.js';\nexport * from './lib/utils/constants.js';\nexport * from './lib/utils/types.js';\nexport { calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse } from './lib/utils/utils.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\n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A,WAAO,EAAE,KAAK,aAAa;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKO,mBAAmB;AACzB,kBAAc,KAAK,SAAS;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKO,sBAAsB;AAC5B,kBAAc,KAAK,YAAY;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAe,kBAAkB,UAAqB,QAAkC;AACvF,QAAI,SAAS,WAAW,gBAAgB,KAAK,SAAS,SAAS,WAAW,GAAG;AAC5E,aAAO;AAAA,QACN,gBAAgB;AAAA,QAChB,aAAa;AAAA,QACb,UAAU;AAAA,MACX;AAAA,IACD;AAEA,UAAM,eAAe,+CAA+C,KAAK,QAAQ;AAGjF,UAAM,UAAU,eAAe,CAAC,KAAK;AAErC,UAAM,YAAY,SAEhB,WAAW,cAAc,KAAK,EAE9B,QAAQ,qBAAqB,sBAAsB;AAErD,QAAI,aAAa;AAIjB,QAAI,oCAAmC,cAAc,8BAA8B;AAClF,YAAM,KAAK,aAAa,KAAK,QAAQ,EAAG,CAAC;AACzC,YAAM,YAAY,kCAAiB,cAAc,EAAE;AACnD,UAAI,KAAK,IAAI,IAAI,YAAY,MAAQ,KAAK,KAAK,KAAK,IAAI;AACvD,sBAAc;AAAA,MACf;AAAA,IACD;AAEA,WAAO;AAAA,MACN,gBAAgB;AAAA,MAChB,aAAa,YAAY;AAAA,MACzB,UAAU;AAAA,IACX;AAAA,EACD;AACD;;;AMncO,IAAM,UAAU;;;AdPtB,WAAmB,aAAa;AACjC,WAAW,SAAS;AAEpB,uBAAmB,+CAAiC,IAAI,QAAQ,WAAW;","names":["import_util","import_undici","RESTEvents","RequestMethod","limit","res","request"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/index.mjs b/node_modules/@discordjs/rest/dist/index.mjs new file mode 100644 index 0000000..476da37 --- /dev/null +++ b/node_modules/@discordjs/rest/dist/index.mjs @@ -0,0 +1,1382 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); + +// src/index.ts +import { Blob as Blob2 } from "node:buffer"; +import { shouldUseGlobalFetchAndWebSocket } from "@discordjs/util"; +import { FormData as FormData2 } from "undici"; + +// src/environment.ts +var defaultStrategy; +function setDefaultStrategy(newStrategy) { + defaultStrategy = newStrategy; +} +__name(setDefaultStrategy, "setDefaultStrategy"); +function getDefaultStrategy() { + return defaultStrategy; +} +__name(getDefaultStrategy, "getDefaultStrategy"); + +// src/strategies/undiciRequest.ts +import { STATUS_CODES } from "node:http"; +import { URLSearchParams as URLSearchParams2 } from "node:url"; +import { types } from "node:util"; +import { request, Headers } from "undici"; +async function makeRequest(url, init) { + const options = { + ...init, + body: await resolveBody(init.body) + }; + const res = await request(url, options); + return { + body: res.body, + async arrayBuffer() { + return res.body.arrayBuffer(); + }, + async json() { + return res.body.json(); + }, + async text() { + return res.body.text(); + }, + get bodyUsed() { + return res.body.bodyUsed; + }, + headers: new Headers(res.headers), + status: res.statusCode, + statusText: STATUS_CODES[res.statusCode], + ok: res.statusCode >= 200 && res.statusCode < 300 + }; +} +__name(makeRequest, "makeRequest"); +async function resolveBody(body) { + if (body == null) { + return null; + } else if (typeof body === "string") { + return body; + } else if (types.isUint8Array(body)) { + return body; + } else if (types.isArrayBuffer(body)) { + return new Uint8Array(body); + } else if (body instanceof URLSearchParams2) { + return body.toString(); + } else if (body instanceof DataView) { + return new Uint8Array(body.buffer); + } else if (body instanceof Blob) { + return new Uint8Array(await body.arrayBuffer()); + } else if (body instanceof FormData) { + return body; + } else if (body[Symbol.iterator]) { + const chunks = [...body]; + return Buffer.concat(chunks); + } else if (body[Symbol.asyncIterator]) { + const chunks = []; + for await (const chunk of body) { + chunks.push(chunk); + } + return Buffer.concat(chunks); + } + throw new TypeError(`Unable to resolve body.`); +} +__name(resolveBody, "resolveBody"); + +// src/lib/utils/constants.ts +import { getUserAgentAppendix } from "@discordjs/util"; +import { APIVersion } from "discord-api-types/v10"; +var DefaultUserAgent = `DiscordBot (https://discord.js.org, 2.0.1)`; +var DefaultUserAgentAppendix = getUserAgentAppendix(); +var DefaultRestOptions = { + agent: null, + api: "https://discord.com/api", + authPrefix: "Bot", + cdn: "https://cdn.discordapp.com", + headers: {}, + invalidRequestWarningInterval: 0, + globalRequestsPerSecond: 50, + offset: 50, + rejectOnRateLimit: null, + retries: 3, + timeout: 15e3, + userAgentAppendix: DefaultUserAgentAppendix, + version: APIVersion, + hashSweepInterval: 144e5, + // 4 Hours + hashLifetime: 864e5, + // 24 Hours + handlerSweepInterval: 36e5, + // 1 Hour + async makeRequest(...args) { + return getDefaultStrategy()(...args); + } +}; +var RESTEvents = /* @__PURE__ */ ((RESTEvents2) => { + RESTEvents2["Debug"] = "restDebug"; + RESTEvents2["HandlerSweep"] = "handlerSweep"; + RESTEvents2["HashSweep"] = "hashSweep"; + RESTEvents2["InvalidRequestWarning"] = "invalidRequestWarning"; + RESTEvents2["RateLimited"] = "rateLimited"; + RESTEvents2["Response"] = "response"; + return RESTEvents2; +})(RESTEvents || {}); +var ALLOWED_EXTENSIONS = ["webp", "png", "jpg", "jpeg", "gif"]; +var ALLOWED_STICKER_EXTENSIONS = ["png", "json", "gif"]; +var ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]; +var OverwrittenMimeTypes = { + // https://github.com/discordjs/discord.js/issues/8557 + "image/apng": "image/png" +}; +var BurstHandlerMajorIdKey = "burst"; + +// src/lib/CDN.ts +var CDN = class { + constructor(base = DefaultRestOptions.cdn) { + this.base = base; + } + static { + __name(this, "CDN"); + } + /** + * Generates an app asset URL for a client's asset. + * + * @param clientId - The client id that has the asset + * @param assetHash - The hash provided by Discord for this asset + * @param options - Optional options for the asset + */ + appAsset(clientId, assetHash, options) { + return this.makeURL(`/app-assets/${clientId}/${assetHash}`, options); + } + /** + * Generates an app icon URL for a client's icon. + * + * @param clientId - The client id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + appIcon(clientId, iconHash, options) { + return this.makeURL(`/app-icons/${clientId}/${iconHash}`, options); + } + /** + * Generates an avatar URL, e.g. for a user or a webhook. + * + * @param id - The id that has the icon + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + avatar(id, avatarHash, options) { + return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options); + } + /** + * Generates a user avatar decoration URL. + * + * @param userId - The id of the user + * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration + * @param options - Optional options for the avatar decoration + */ + avatarDecoration(userId, userAvatarDecoration, options) { + return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options); + } + /** + * Generates a banner URL, e.g. for a user or a guild. + * + * @param id - The id that has the banner splash + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + banner(id, bannerHash, options) { + return this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options); + } + /** + * Generates an icon URL for a channel, e.g. a group DM. + * + * @param channelId - The channel id that has the icon + * @param iconHash - The hash provided by Discord for this channel + * @param options - Optional options for the icon + */ + channelIcon(channelId, iconHash, options) { + return this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options); + } + /** + * Generates a default avatar URL + * + * @param index - The default avatar index + * @remarks + * To calculate the index for a user do `(userId >> 22) % 6`, + * or `discriminator % 5` if they're using the legacy username system. + */ + defaultAvatar(index) { + return this.makeURL(`/embed/avatars/${index}`, { extension: "png" }); + } + /** + * Generates a discovery splash URL for a guild's discovery splash. + * + * @param guildId - The guild id that has the discovery splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + discoverySplash(guildId, splashHash, options) { + return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates an emoji's URL for an emoji. + * + * @param emojiId - The emoji id + * @param extension - The extension of the emoji + */ + emoji(emojiId, extension) { + return this.makeURL(`/emojis/${emojiId}`, { extension }); + } + /** + * Generates a guild member avatar URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + guildMemberAvatar(guildId, userId, avatarHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options); + } + /** + * Generates a guild member banner URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + guildMemberBanner(guildId, userId, bannerHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options); + } + /** + * Generates an icon URL, e.g. for a guild. + * + * @param id - The id that has the icon splash + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + icon(id, iconHash, options) { + return this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options); + } + /** + * Generates a URL for the icon of a role + * + * @param roleId - The id of the role that has the icon + * @param roleIconHash - The hash provided by Discord for this role icon + * @param options - Optional options for the role icon + */ + roleIcon(roleId, roleIconHash, options) { + return this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options); + } + /** + * Generates a guild invite splash URL for a guild's invite splash. + * + * @param guildId - The guild id that has the invite splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + splash(guildId, splashHash, options) { + return this.makeURL(`/splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates a sticker URL. + * + * @param stickerId - The sticker id + * @param extension - The extension of the sticker + * @privateRemarks + * Stickers cannot have a `.webp` extension, so we default to a `.png` + */ + sticker(stickerId, extension = "png") { + return this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension }); + } + /** + * Generates a sticker pack banner URL. + * + * @param bannerId - The banner id + * @param options - Optional options for the banner + */ + stickerPackBanner(bannerId, options) { + return this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options); + } + /** + * Generates a team icon URL for a team's icon. + * + * @param teamId - The team id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + teamIcon(teamId, iconHash, options) { + return this.makeURL(`/team-icons/${teamId}/${iconHash}`, options); + } + /** + * Generates a cover image for a guild scheduled event. + * + * @param scheduledEventId - The scheduled event id + * @param coverHash - The hash provided by discord for this cover image + * @param options - Optional options for the cover image + */ + guildScheduledEventCover(scheduledEventId, coverHash, options) { + return this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options); + } + /** + * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`. + * + * @param route - The base cdn route + * @param hash - The hash provided by Discord for this icon + * @param options - Optional options for the link + */ + dynamicMakeURL(route, hash, { forceStatic = false, ...options } = {}) { + return this.makeURL(route, !forceStatic && hash.startsWith("a_") ? { ...options, extension: "gif" } : options); + } + /** + * Constructs the URL for the resource + * + * @param route - The base cdn route + * @param options - The extension/size options for the link + */ + makeURL(route, { allowedExtensions = ALLOWED_EXTENSIONS, extension = "webp", size } = {}) { + extension = String(extension).toLowerCase(); + if (!allowedExtensions.includes(extension)) { + throw new RangeError(`Invalid extension provided: ${extension} +Must be one of: ${allowedExtensions.join(", ")}`); + } + if (size && !ALLOWED_SIZES.includes(size)) { + throw new RangeError(`Invalid size provided: ${size} +Must be one of: ${ALLOWED_SIZES.join(", ")}`); + } + const url = new URL(`${this.base}${route}.${extension}`); + if (size) { + url.searchParams.set("size", String(size)); + } + return url.toString(); + } +}; + +// src/lib/errors/DiscordAPIError.ts +function isErrorGroupWrapper(error) { + return Reflect.has(error, "_errors"); +} +__name(isErrorGroupWrapper, "isErrorGroupWrapper"); +function isErrorResponse(error) { + return typeof Reflect.get(error, "message") === "string"; +} +__name(isErrorResponse, "isErrorResponse"); +var DiscordAPIError = class _DiscordAPIError extends Error { + /** + * @param rawError - The error reported by Discord + * @param code - The error code reported by Discord + * @param status - The status code of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(rawError, code, status, method, url, bodyData) { + super(_DiscordAPIError.getMessage(rawError)); + this.rawError = rawError; + this.code = code; + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "DiscordAPIError"); + } + requestBody; + /** + * The name of the error + */ + get name() { + return `${_DiscordAPIError.name}[${this.code}]`; + } + static getMessage(error) { + let flattened = ""; + if ("code" in error) { + if (error.errors) { + flattened = [...this.flattenDiscordError(error.errors)].join("\n"); + } + return error.message && flattened ? `${error.message} +${flattened}` : error.message || flattened || "Unknown Error"; + } + return error.error_description ?? "No Description"; + } + static *flattenDiscordError(obj, key = "") { + if (isErrorResponse(obj)) { + return yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim(); + } + for (const [otherKey, val] of Object.entries(obj)) { + const nextKey = otherKey.startsWith("_") ? key : key ? Number.isNaN(Number(otherKey)) ? `${key}.${otherKey}` : `${key}[${otherKey}]` : otherKey; + if (typeof val === "string") { + yield val; + } else if (isErrorGroupWrapper(val)) { + for (const error of val._errors) { + yield* this.flattenDiscordError(error, nextKey); + } + } else { + yield* this.flattenDiscordError(val, nextKey); + } + } + } +}; + +// src/lib/errors/HTTPError.ts +var HTTPError = class _HTTPError extends Error { + /** + * @param status - The status code of the response + * @param statusText - The status text of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(status, statusText, method, url, bodyData) { + super(statusText); + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "HTTPError"); + } + requestBody; + name = _HTTPError.name; +}; + +// src/lib/errors/RateLimitError.ts +var RateLimitError = class _RateLimitError extends Error { + static { + __name(this, "RateLimitError"); + } + timeToReset; + limit; + method; + hash; + url; + route; + majorParameter; + global; + constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }) { + super(); + this.timeToReset = timeToReset; + this.limit = limit; + this.method = method; + this.hash = hash; + this.url = url; + this.route = route; + this.majorParameter = majorParameter; + this.global = global; + } + /** + * The name of the error + */ + get name() { + return `${_RateLimitError.name}[${this.route}]`; + } +}; + +// src/lib/REST.ts +import { Collection } from "@discordjs/collection"; +import { DiscordSnowflake } from "@sapphire/snowflake"; +import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter"; +import { filetypeinfo } from "magic-bytes.js"; + +// src/lib/utils/types.ts +var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => { + RequestMethod2["Delete"] = "DELETE"; + RequestMethod2["Get"] = "GET"; + RequestMethod2["Patch"] = "PATCH"; + RequestMethod2["Post"] = "POST"; + RequestMethod2["Put"] = "PUT"; + return RequestMethod2; +})(RequestMethod || {}); + +// src/lib/utils/utils.ts +function serializeSearchParam(value) { + switch (typeof value) { + case "string": + return value; + case "number": + case "bigint": + case "boolean": + return value.toString(); + case "object": + if (value === null) + return null; + if (value instanceof Date) { + return Number.isNaN(value.getTime()) ? null : value.toISOString(); + } + if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) + return value.toString(); + return null; + default: + return null; + } +} +__name(serializeSearchParam, "serializeSearchParam"); +function makeURLSearchParams(options) { + const params = new URLSearchParams(); + if (!options) + return params; + for (const [key, value] of Object.entries(options)) { + const serialized = serializeSearchParam(value); + if (serialized !== null) + params.append(key, serialized); + } + return params; +} +__name(makeURLSearchParams, "makeURLSearchParams"); +async function parseResponse(res) { + if (res.headers.get("Content-Type")?.startsWith("application/json")) { + return res.json(); + } + return res.arrayBuffer(); +} +__name(parseResponse, "parseResponse"); +function hasSublimit(bucketRoute, body, method) { + if (bucketRoute === "/channels/:id") { + if (typeof body !== "object" || body === null) + return false; + if (method !== "PATCH" /* Patch */) + return false; + const castedBody = body; + return ["name", "topic"].some((key) => Reflect.has(castedBody, key)); + } + return true; +} +__name(hasSublimit, "hasSublimit"); +function shouldRetry(error) { + if (error.name === "AbortError") + return true; + return "code" in error && error.code === "ECONNRESET" || error.message.includes("ECONNRESET"); +} +__name(shouldRetry, "shouldRetry"); +async function onRateLimit(manager, rateLimitData) { + const { options } = manager; + if (!options.rejectOnRateLimit) + return; + const shouldThrow = typeof options.rejectOnRateLimit === "function" ? await options.rejectOnRateLimit(rateLimitData) : options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase())); + if (shouldThrow) { + throw new RateLimitError(rateLimitData); + } +} +__name(onRateLimit, "onRateLimit"); +function calculateUserDefaultAvatarIndex(userId) { + return Number(BigInt(userId) >> 22n) % 6; +} +__name(calculateUserDefaultAvatarIndex, "calculateUserDefaultAvatarIndex"); +async function sleep(ms) { + return new Promise((resolve) => { + setTimeout(() => resolve(), ms); + }); +} +__name(sleep, "sleep"); +function isBufferLike(value) { + return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray; +} +__name(isBufferLike, "isBufferLike"); + +// src/lib/handlers/Shared.ts +var invalidCount = 0; +var invalidCountResetTime = null; +function incrementInvalidCount(manager) { + if (!invalidCountResetTime || invalidCountResetTime < Date.now()) { + invalidCountResetTime = Date.now() + 1e3 * 60 * 10; + invalidCount = 0; + } + invalidCount++; + const emitInvalid = manager.options.invalidRequestWarningInterval > 0 && invalidCount % manager.options.invalidRequestWarningInterval === 0; + if (emitInvalid) { + manager.emit("invalidRequestWarning" /* InvalidRequestWarning */, { + count: invalidCount, + remainingTime: invalidCountResetTime - Date.now() + }); + } +} +__name(incrementInvalidCount, "incrementInvalidCount"); +async function makeNetworkRequest(manager, routeId, url, options, requestData, retries) { + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), manager.options.timeout); + if (requestData.signal) { + if (requestData.signal.aborted) + controller.abort(); + else + requestData.signal.addEventListener("abort", () => controller.abort()); + } + let res; + try { + res = await manager.options.makeRequest(url, { ...options, signal: controller.signal }); + } catch (error) { + if (!(error instanceof Error)) + throw error; + if (shouldRetry(error) && retries !== manager.options.retries) { + return null; + } + throw error; + } finally { + clearTimeout(timeout); + } + if (manager.listenerCount("response" /* Response */)) { + manager.emit( + "response" /* Response */, + { + method: options.method ?? "get", + path: routeId.original, + route: routeId.bucketRoute, + options, + data: requestData, + retries + }, + res instanceof Response ? res.clone() : { ...res } + ); + } + return res; +} +__name(makeNetworkRequest, "makeNetworkRequest"); +async function handleErrors(manager, res, method, url, requestData, retries) { + const status = res.status; + if (status >= 500 && status < 600) { + if (retries !== manager.options.retries) { + return null; + } + throw new HTTPError(status, res.statusText, method, url, requestData); + } else { + if (status >= 400 && status < 500) { + if (status === 401 && requestData.auth) { + manager.setToken(null); + } + const data = await parseResponse(res); + throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); + } + return res; + } +} +__name(handleErrors, "handleErrors"); + +// src/lib/handlers/BurstHandler.ts +var BurstHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "BurstHandler"); + } + /** + * {@inheritdoc IHandler.id} + */ + id; + /** + * {@inheritDoc IHandler.inactive} + */ + inactive = false; + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + return this.runRequest(routeId, url, options, requestData); + } + /** + * The method that actually makes the request to the API, and updates info about the bucket accordingly + * + * @param routeId - The generalized API route with literal ids for major parameters + * @param url - The fully resolved URL to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const retry = res.headers.get("Retry-After"); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (status >= 200 && status < 300) { + return res; + } else if (status === 429) { + const isGlobal = res.headers.has("X-RateLimit-Global"); + await onRateLimit(this.manager, { + timeToReset: retryAfter, + limit: Number.POSITIVE_INFINITY, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${Number.POSITIVE_INFINITY}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : None` + ].join("\n") + ); + await sleep(retryAfter); + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/handlers/SequentialHandler.ts +import { AsyncQueue } from "@sapphire/async-queue"; +var SequentialHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "SequentialHandler"); + } + /** + * {@inheritDoc IHandler.id} + */ + id; + /** + * The time this rate limit bucket will reset + */ + reset = -1; + /** + * The remaining requests that can be made before we are rate limited + */ + remaining = 1; + /** + * The total number of requests that can be made before we are rate limited + */ + limit = Number.POSITIVE_INFINITY; + /** + * The interface used to sequence async requests sequentially + */ + #asyncQueue = new AsyncQueue(); + /** + * The interface used to sequence sublimited async requests sequentially + */ + #sublimitedQueue = null; + /** + * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed + */ + #sublimitPromise = null; + /** + * Whether the sublimit queue needs to be shifted in the finally block + */ + #shiftSublimit = false; + /** + * {@inheritDoc IHandler.inactive} + */ + get inactive() { + return this.#asyncQueue.remaining === 0 && (this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) && !this.limited; + } + /** + * If the rate limit bucket is currently limited by the global limit + */ + get globalLimited() { + return this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset; + } + /** + * If the rate limit bucket is currently limited by its limit + */ + get localLimited() { + return this.remaining <= 0 && Date.now() < this.reset; + } + /** + * If the rate limit bucket is currently limited + */ + get limited() { + return this.globalLimited || this.localLimited; + } + /** + * The time until queued requests can continue + */ + get timeToReset() { + return this.reset + this.manager.options.offset - Date.now(); + } + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * Delay all requests for the specified amount of time, handling global rate limits + * + * @param time - The amount of time to delay all requests for + */ + async globalDelayFor(time) { + await sleep(time); + this.manager.globalDelay = null; + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + let queue = this.#asyncQueue; + let queueType = 0 /* Standard */; + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + queueType = 1 /* Sublimit */; + } + await queue.wait({ signal: requestData.signal }); + if (queueType === 0 /* Standard */) { + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + const wait = queue.wait(); + this.#asyncQueue.shift(); + await wait; + } else if (this.#sublimitPromise) { + await this.#sublimitPromise.promise; + } + } + try { + return await this.runRequest(routeId, url, options, requestData); + } finally { + queue.shift(); + if (this.#shiftSublimit) { + this.#shiftSublimit = false; + this.#sublimitedQueue?.shift(); + } + if (this.#sublimitedQueue?.remaining === 0) { + this.#sublimitPromise?.resolve(); + this.#sublimitedQueue = null; + } + } + } + /** + * The method that actually makes the request to the api, and updates info about the bucket accordingly + * + * @param routeId - The generalized api route with literal ids for major parameters + * @param url - The fully resolved url to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + while (this.limited) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + let delay; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + if (!this.manager.globalDelay) { + this.manager.globalDelay = this.globalDelayFor(timeout); + } + delay = this.manager.globalDelay; + } else { + limit2 = this.limit; + timeout = this.timeToReset; + delay = sleep(timeout); + } + const rateLimitData = { + timeToReset: timeout, + limit: limit2, + method: options.method ?? "get", + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }; + this.manager.emit("rateLimited" /* RateLimited */, rateLimitData); + await onRateLimit(this.manager, rateLimitData); + if (isGlobal) { + this.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`); + } else { + this.debug(`Waiting ${timeout}ms for rate limit to pass`); + } + await delay; + } + if (!this.manager.globalReset || this.manager.globalReset < Date.now()) { + this.manager.globalReset = Date.now() + 1e3; + this.manager.globalRemaining = this.manager.options.globalRequestsPerSecond; + } + this.manager.globalRemaining--; + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const limit = res.headers.get("X-RateLimit-Limit"); + const remaining = res.headers.get("X-RateLimit-Remaining"); + const reset = res.headers.get("X-RateLimit-Reset-After"); + const hash = res.headers.get("X-RateLimit-Bucket"); + const retry = res.headers.get("Retry-After"); + this.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY; + this.remaining = remaining ? Number(remaining) : 1; + this.reset = reset ? Number(reset) * 1e3 + Date.now() + this.manager.options.offset : Date.now(); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (hash && hash !== this.hash) { + this.debug(["Received bucket hash update", ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join("\n")); + this.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() }); + } else if (hash) { + const hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`); + if (hashData) { + hashData.lastAccess = Date.now(); + } + } + let sublimitTimeout = null; + if (retryAfter > 0) { + if (res.headers.has("X-RateLimit-Global")) { + this.manager.globalRemaining = 0; + this.manager.globalReset = Date.now() + retryAfter; + } else if (!this.localLimited) { + sublimitTimeout = retryAfter; + } + } + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (res.ok) { + return res; + } else if (status === 429) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + } else { + limit2 = this.limit; + timeout = this.timeToReset; + } + await onRateLimit(this.manager, { + timeToReset: timeout, + limit: limit2, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal.toString()}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${limit2}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : "None"}` + ].join("\n") + ); + if (sublimitTimeout) { + const firstSublimit = !this.#sublimitedQueue; + if (firstSublimit) { + this.#sublimitedQueue = new AsyncQueue(); + void this.#sublimitedQueue.wait(); + this.#asyncQueue.shift(); + } + this.#sublimitPromise?.resolve(); + this.#sublimitPromise = null; + await sleep(sublimitTimeout); + let resolve; + const promise = new Promise((res2) => resolve = res2); + this.#sublimitPromise = { promise, resolve }; + if (firstSublimit) { + await this.#asyncQueue.wait(); + this.#shiftSublimit = true; + } + } + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/REST.ts +var REST = class _REST extends AsyncEventEmitter { + static { + __name(this, "REST"); + } + /** + * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests + * performed by this manager. + */ + agent = null; + cdn; + /** + * The number of requests remaining in the global bucket + */ + globalRemaining; + /** + * The promise used to wait out the global rate limit + */ + globalDelay = null; + /** + * The timestamp at which the global bucket resets + */ + globalReset = -1; + /** + * API bucket hashes that are cached from provided routes + */ + hashes = new Collection(); + /** + * Request handlers created from the bucket hash and the major parameters + */ + handlers = new Collection(); + #token = null; + hashTimer; + handlerTimer; + options; + constructor(options = {}) { + super(); + this.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn); + this.options = { ...DefaultRestOptions, ...options }; + this.options.offset = Math.max(0, this.options.offset); + this.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond); + this.agent = options.agent ?? null; + this.setupSweepers(); + } + setupSweepers() { + const validateMaxInterval = /* @__PURE__ */ __name((interval) => { + if (interval > 144e5) { + throw new Error("Cannot set an interval greater than 4 hours"); + } + }, "validateMaxInterval"); + if (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.hashSweepInterval); + this.hashTimer = setInterval(() => { + const sweptHashes = new Collection(); + const currentDate = Date.now(); + this.hashes.sweep((val, key) => { + if (val.lastAccess === -1) + return false; + const shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime; + if (shouldSweep) { + sweptHashes.set(key, val); + this.emit("restDebug" /* Debug */, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`); + } + return shouldSweep; + }); + this.emit("hashSweep" /* HashSweep */, sweptHashes); + }, this.options.hashSweepInterval); + this.hashTimer.unref?.(); + } + if (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.handlerSweepInterval); + this.handlerTimer = setInterval(() => { + const sweptHandlers = new Collection(); + this.handlers.sweep((val, key) => { + const { inactive } = val; + if (inactive) { + sweptHandlers.set(key, val); + this.emit("restDebug" /* Debug */, `Handler ${val.id} for ${key} swept due to being inactive`); + } + return inactive; + }); + this.emit("handlerSweep" /* HandlerSweep */, sweptHandlers); + }, this.options.handlerSweepInterval); + this.handlerTimer.unref?.(); + } + } + /** + * Runs a get request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async get(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "GET" /* Get */ }); + } + /** + * Runs a delete request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async delete(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "DELETE" /* Delete */ }); + } + /** + * Runs a post request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async post(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "POST" /* Post */ }); + } + /** + * Runs a put request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async put(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PUT" /* Put */ }); + } + /** + * Runs a patch request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async patch(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PATCH" /* Patch */ }); + } + /** + * Runs a request from the api + * + * @param options - Request options + */ + async request(options) { + const response = await this.queueRequest(options); + return parseResponse(response); + } + /** + * Sets the default agent to use for requests performed by this manager + * + * @param agent - The agent to use + */ + setAgent(agent) { + this.agent = agent; + return this; + } + /** + * Sets the authorization token that should be used for requests + * + * @param token - The authorization token to use + */ + setToken(token) { + this.#token = token; + return this; + } + /** + * Queues a request to be sent + * + * @param request - All the information needed to make a request + * @returns The response from the api request + */ + async queueRequest(request2) { + const routeId = _REST.generateRouteData(request2.fullRoute, request2.method); + const hash = this.hashes.get(`${request2.method}:${routeId.bucketRoute}`) ?? { + value: `Global(${request2.method}:${routeId.bucketRoute})`, + lastAccess: -1 + }; + const handler = this.handlers.get(`${hash.value}:${routeId.majorParameter}`) ?? this.createHandler(hash.value, routeId.majorParameter); + const { url, fetchOptions } = await this.resolveRequest(request2); + return handler.queueRequest(routeId, url, fetchOptions, { + body: request2.body, + files: request2.files, + auth: request2.auth !== false, + signal: request2.signal + }); + } + /** + * Creates a new rate limit handler from a hash, based on the hash and the major parameter + * + * @param hash - The hash for the route + * @param majorParameter - The major parameter for this handler + * @internal + */ + createHandler(hash, majorParameter) { + const queue = majorParameter === BurstHandlerMajorIdKey ? new BurstHandler(this, hash, majorParameter) : new SequentialHandler(this, hash, majorParameter); + this.handlers.set(queue.id, queue); + return queue; + } + /** + * Formats the request data to a usable format for fetch + * + * @param request - The request data + */ + async resolveRequest(request2) { + const { options } = this; + let query = ""; + if (request2.query) { + const resolvedQuery = request2.query.toString(); + if (resolvedQuery !== "") { + query = `?${resolvedQuery}`; + } + } + const headers = { + ...this.options.headers, + "User-Agent": `${DefaultUserAgent} ${options.userAgentAppendix}`.trim() + }; + if (request2.auth !== false) { + if (!this.#token) { + throw new Error("Expected token to be set for this request, but none was present"); + } + headers.Authorization = `${request2.authPrefix ?? this.options.authPrefix} ${this.#token}`; + } + if (request2.reason?.length) { + headers["X-Audit-Log-Reason"] = encodeURIComponent(request2.reason); + } + const url = `${options.api}${request2.versioned === false ? "" : `/v${options.version}`}${request2.fullRoute}${query}`; + let finalBody; + let additionalHeaders = {}; + if (request2.files?.length) { + const formData = new FormData(); + for (const [index, file] of request2.files.entries()) { + const fileKey = file.key ?? `files[${index}]`; + if (isBufferLike(file.data)) { + let contentType = file.contentType; + if (!contentType) { + const [parsedType] = filetypeinfo(file.data); + if (parsedType) { + contentType = OverwrittenMimeTypes[parsedType.mime] ?? parsedType.mime ?? "application/octet-stream"; + } + } + formData.append(fileKey, new Blob([file.data], { type: contentType }), file.name); + } else { + formData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name); + } + } + if (request2.body != null) { + if (request2.appendToFormData) { + for (const [key, value] of Object.entries(request2.body)) { + formData.append(key, value); + } + } else { + formData.append("payload_json", JSON.stringify(request2.body)); + } + } + finalBody = formData; + } else if (request2.body != null) { + if (request2.passThroughBody) { + finalBody = request2.body; + } else { + finalBody = JSON.stringify(request2.body); + additionalHeaders = { "Content-Type": "application/json" }; + } + } + const method = request2.method.toUpperCase(); + const fetchOptions = { + // Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing + body: ["GET", "HEAD"].includes(method) ? null : finalBody, + headers: { ...request2.headers, ...additionalHeaders, ...headers }, + method, + // Prioritize setting an agent per request, use the agent for this instance otherwise. + dispatcher: request2.dispatcher ?? this.agent ?? void 0 + }; + return { url, fetchOptions }; + } + /** + * Stops the hash sweeping interval + */ + clearHashSweeper() { + clearInterval(this.hashTimer); + } + /** + * Stops the request handler sweeping interval + */ + clearHandlerSweeper() { + clearInterval(this.handlerTimer); + } + /** + * Generates route data for an endpoint:method + * + * @param endpoint - The raw endpoint to generalize + * @param method - The HTTP method this endpoint is called without + * @internal + */ + static generateRouteData(endpoint, method) { + if (endpoint.startsWith("/interactions/") && endpoint.endsWith("/callback")) { + return { + majorParameter: BurstHandlerMajorIdKey, + bucketRoute: "/interactions/:id/:token/callback", + original: endpoint + }; + } + const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{17,19})/.exec(endpoint); + const majorId = majorIdMatch?.[1] ?? "global"; + const baseRoute = endpoint.replaceAll(/\d{17,19}/g, ":id").replace(/\/reactions\/(.*)/, "/reactions/:reaction"); + let exceptions = ""; + if (method === "DELETE" /* Delete */ && baseRoute === "/channels/:id/messages/:id") { + const id = /\d{17,19}$/.exec(endpoint)[0]; + const timestamp = DiscordSnowflake.timestampFrom(id); + if (Date.now() - timestamp > 1e3 * 60 * 60 * 24 * 14) { + exceptions += "/Delete Old Message"; + } + } + return { + majorParameter: majorId, + bucketRoute: baseRoute + exceptions, + original: endpoint + }; + } +}; + +// src/shared.ts +var version = "2.0.1"; + +// src/index.ts +globalThis.FormData ??= FormData2; +globalThis.Blob ??= Blob2; +setDefaultStrategy(shouldUseGlobalFetchAndWebSocket() ? fetch : makeRequest); +export { + ALLOWED_EXTENSIONS, + ALLOWED_SIZES, + ALLOWED_STICKER_EXTENSIONS, + BurstHandlerMajorIdKey, + CDN, + DefaultRestOptions, + DefaultUserAgent, + DefaultUserAgentAppendix, + DiscordAPIError, + HTTPError, + OverwrittenMimeTypes, + REST, + RESTEvents, + RateLimitError, + RequestMethod, + calculateUserDefaultAvatarIndex, + makeURLSearchParams, + parseResponse, + version +}; +//# sourceMappingURL=index.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/index.mjs.map b/node_modules/@discordjs/rest/dist/index.mjs.map new file mode 100644 index 0000000..51a8dfd --- /dev/null +++ b/node_modules/@discordjs/rest/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/environment.ts","../src/strategies/undiciRequest.ts","../src/lib/utils/constants.ts","../src/lib/CDN.ts","../src/lib/errors/DiscordAPIError.ts","../src/lib/errors/HTTPError.ts","../src/lib/errors/RateLimitError.ts","../src/lib/REST.ts","../src/lib/utils/types.ts","../src/lib/utils/utils.ts","../src/lib/handlers/Shared.ts","../src/lib/handlers/BurstHandler.ts","../src/lib/handlers/SequentialHandler.ts","../src/shared.ts"],"sourcesContent":["import { Blob } from 'node:buffer';\nimport { shouldUseGlobalFetchAndWebSocket } from '@discordjs/util';\nimport { FormData } from 'undici';\nimport { setDefaultStrategy } from './environment.js';\nimport { makeRequest } from './strategies/undiciRequest.js';\n\n// TODO(ckohen): remove once node engine req is bumped to > v18\n(globalThis as any).FormData ??= FormData;\nglobalThis.Blob ??= Blob;\n\nsetDefaultStrategy(shouldUseGlobalFetchAndWebSocket() ? fetch : makeRequest);\n\nexport * from './shared.js';\n","import type { RESTOptions } from './shared.js';\n\nlet defaultStrategy: RESTOptions['makeRequest'];\n\nexport function setDefaultStrategy(newStrategy: RESTOptions['makeRequest']) {\n\tdefaultStrategy = newStrategy;\n}\n\nexport function getDefaultStrategy() {\n\treturn defaultStrategy;\n}\n","import { STATUS_CODES } from 'node:http';\nimport { URLSearchParams } from 'node:url';\nimport { types } from 'node:util';\nimport { type RequestInit, request, Headers } from 'undici';\nimport type { ResponseLike } from '../shared.js';\n\nexport type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;\n\nexport async function makeRequest(url: string, init: RequestInit): Promise<ResponseLike> {\n\t// The cast is necessary because `headers` and `method` are narrower types in `undici.request`\n\t// our request path guarantees they are of acceptable type for `undici.request`\n\tconst options = {\n\t\t...init,\n\t\tbody: await resolveBody(init.body),\n\t} as RequestOptions;\n\tconst res = await request(url, options);\n\treturn {\n\t\tbody: res.body,\n\t\tasync arrayBuffer() {\n\t\t\treturn res.body.arrayBuffer();\n\t\t},\n\t\tasync json() {\n\t\t\treturn res.body.json();\n\t\t},\n\t\tasync text() {\n\t\t\treturn res.body.text();\n\t\t},\n\t\tget bodyUsed() {\n\t\t\treturn res.body.bodyUsed;\n\t\t},\n\t\theaders: new Headers(res.headers as Record<string, string[] | string>),\n\t\tstatus: res.statusCode,\n\t\tstatusText: STATUS_CODES[res.statusCode]!,\n\t\tok: res.statusCode >= 200 && res.statusCode < 300,\n\t};\n}\n\nexport async function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>> {\n\t// eslint-disable-next-line no-eq-null, eqeqeq\n\tif (body == null) {\n\t\treturn null;\n\t} else if (typeof body === 'string') {\n\t\treturn body;\n\t} else if (types.isUint8Array(body)) {\n\t\treturn body;\n\t} else if (types.isArrayBuffer(body)) {\n\t\treturn new Uint8Array(body);\n\t} else if (body instanceof URLSearchParams) {\n\t\treturn body.toString();\n\t} else if (body instanceof DataView) {\n\t\treturn new Uint8Array(body.buffer);\n\t} else if (body instanceof Blob) {\n\t\treturn new Uint8Array(await body.arrayBuffer());\n\t} else if (body instanceof FormData) {\n\t\treturn body;\n\t} else if ((body as Iterable<Uint8Array>)[Symbol.iterator]) {\n\t\tconst chunks = [...(body as Iterable<Uint8Array>)];\n\n\t\treturn Buffer.concat(chunks);\n\t} else if ((body as AsyncIterable<Uint8Array>)[Symbol.asyncIterator]) {\n\t\tconst chunks: Uint8Array[] = [];\n\n\t\tfor await (const chunk of body as AsyncIterable<Uint8Array>) {\n\t\t\tchunks.push(chunk);\n\t\t}\n\n\t\treturn Buffer.concat(chunks);\n\t}\n\n\tthrow new TypeError(`Unable to resolve body.`);\n}\n","import { getUserAgentAppendix } from '@discordjs/util';\nimport { APIVersion } from 'discord-api-types/v10';\nimport { getDefaultStrategy } from '../../environment.js';\nimport type { RESTOptions, ResponseLike } from './types.js';\n\nexport const DefaultUserAgent =\n\t`DiscordBot (https://discord.js.org, 2.0.1)` as `DiscordBot (https://discord.js.org, ${string})`;\n\n/**\n * The default string to append onto the user agent.\n */\nexport const DefaultUserAgentAppendix = getUserAgentAppendix();\n\nexport const DefaultRestOptions = {\n\tagent: null,\n\tapi: 'https://discord.com/api',\n\tauthPrefix: 'Bot',\n\tcdn: 'https://cdn.discordapp.com',\n\theaders: {},\n\tinvalidRequestWarningInterval: 0,\n\tglobalRequestsPerSecond: 50,\n\toffset: 50,\n\trejectOnRateLimit: null,\n\tretries: 3,\n\ttimeout: 15_000,\n\tuserAgentAppendix: DefaultUserAgentAppendix,\n\tversion: APIVersion,\n\thashSweepInterval: 14_400_000, // 4 Hours\n\thashLifetime: 86_400_000, // 24 Hours\n\thandlerSweepInterval: 3_600_000, // 1 Hour\n\tasync makeRequest(...args): Promise<ResponseLike> {\n\t\treturn getDefaultStrategy()(...args);\n\t},\n} as const satisfies Required<RESTOptions>;\n\n/**\n * The events that the REST manager emits\n */\nexport enum RESTEvents {\n\tDebug = 'restDebug',\n\tHandlerSweep = 'handlerSweep',\n\tHashSweep = 'hashSweep',\n\tInvalidRequestWarning = 'invalidRequestWarning',\n\tRateLimited = 'rateLimited',\n\tResponse = 'response',\n}\n\nexport const ALLOWED_EXTENSIONS = ['webp', 'png', 'jpg', 'jpeg', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_STICKER_EXTENSIONS = ['png', 'json', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096] as const satisfies readonly number[];\n\nexport type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];\nexport type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];\nexport type ImageSize = (typeof ALLOWED_SIZES)[number];\n\nexport const OverwrittenMimeTypes = {\n\t// https://github.com/discordjs/discord.js/issues/8557\n\t'image/apng': 'image/png',\n} as const satisfies Readonly<Record<string, string>>;\n\nexport const BurstHandlerMajorIdKey = 'burst';\n","/* eslint-disable jsdoc/check-param-names */\nimport {\n\tALLOWED_EXTENSIONS,\n\tALLOWED_SIZES,\n\tALLOWED_STICKER_EXTENSIONS,\n\tDefaultRestOptions,\n\ttype ImageExtension,\n\ttype ImageSize,\n\ttype StickerExtension,\n} from './utils/constants.js';\n\n/**\n * The options used for image URLs\n */\nexport interface BaseImageURLOptions {\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: ImageExtension;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The options used for image URLs with animated content\n */\nexport interface ImageURLOptions extends BaseImageURLOptions {\n\t/**\n\t * Whether or not to prefer the static version of an image asset.\n\t */\n\tforceStatic?: boolean;\n}\n\n/**\n * The options to use when making a CDN URL\n */\nexport interface MakeURLOptions {\n\t/**\n\t * The allowed extensions that can be used\n\t */\n\tallowedExtensions?: readonly string[];\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: string | undefined;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The CDN link builder\n */\nexport class CDN {\n\tpublic constructor(private readonly base: string = DefaultRestOptions.cdn) {}\n\n\t/**\n\t * Generates an app asset URL for a client's asset.\n\t *\n\t * @param clientId - The client id that has the asset\n\t * @param assetHash - The hash provided by Discord for this asset\n\t * @param options - Optional options for the asset\n\t */\n\tpublic appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/${clientId}/${assetHash}`, options);\n\t}\n\n\t/**\n\t * Generates an app icon URL for a client's icon.\n\t *\n\t * @param clientId - The client id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-icons/${clientId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates an avatar URL, e.g. for a user or a webhook.\n\t *\n\t * @param id - The id that has the icon\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a user avatar decoration URL.\n\t *\n\t * @param userId - The id of the user\n\t * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration\n\t * @param options - Optional options for the avatar decoration\n\t */\n\tpublic avatarDecoration(\n\t\tuserId: string,\n\t\tuserAvatarDecoration: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);\n\t}\n\n\t/**\n\t * Generates a banner URL, e.g. for a user or a guild.\n\t *\n\t * @param id - The id that has the banner splash\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL for a channel, e.g. a group DM.\n\t *\n\t * @param channelId - The channel id that has the icon\n\t * @param iconHash - The hash provided by Discord for this channel\n\t * @param options - Optional options for the icon\n\t */\n\tpublic channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a default avatar URL\n\t *\n\t * @param index - The default avatar index\n\t * @remarks\n\t * To calculate the index for a user do `(userId >> 22) % 6`,\n\t * or `discriminator % 5` if they're using the legacy username system.\n\t */\n\tpublic defaultAvatar(index: number): string {\n\t\treturn this.makeURL(`/embed/avatars/${index}`, { extension: 'png' });\n\t}\n\n\t/**\n\t * Generates a discovery splash URL for a guild's discovery splash.\n\t *\n\t * @param guildId - The guild id that has the discovery splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates an emoji's URL for an emoji.\n\t *\n\t * @param emojiId - The emoji id\n\t * @param extension - The extension of the emoji\n\t */\n\tpublic emoji(emojiId: string, extension?: ImageExtension): string {\n\t\treturn this.makeURL(`/emojis/${emojiId}`, { extension });\n\t}\n\n\t/**\n\t * Generates a guild member avatar URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic guildMemberAvatar(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tavatarHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a guild member banner URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic guildMemberBanner(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tbannerHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL, e.g. for a guild.\n\t *\n\t * @param id - The id that has the icon splash\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options);\n\t}\n\n\t/**\n\t * Generates a URL for the icon of a role\n\t *\n\t * @param roleId - The id of the role that has the icon\n\t * @param roleIconHash - The hash provided by Discord for this role icon\n\t * @param options - Optional options for the role icon\n\t */\n\tpublic roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a guild invite splash URL for a guild's invite splash.\n\t *\n\t * @param guildId - The guild id that has the invite splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates a sticker URL.\n\t *\n\t * @param stickerId - The sticker id\n\t * @param extension - The extension of the sticker\n\t * @privateRemarks\n\t * Stickers cannot have a `.webp` extension, so we default to a `.png`\n\t */\n\tpublic sticker(stickerId: string, extension: StickerExtension = 'png'): string {\n\t\treturn this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension });\n\t}\n\n\t/**\n\t * Generates a sticker pack banner URL.\n\t *\n\t * @param bannerId - The banner id\n\t * @param options - Optional options for the banner\n\t */\n\tpublic stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options);\n\t}\n\n\t/**\n\t * Generates a team icon URL for a team's icon.\n\t *\n\t * @param teamId - The team id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/team-icons/${teamId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a cover image for a guild scheduled event.\n\t *\n\t * @param scheduledEventId - The scheduled event id\n\t * @param coverHash - The hash provided by discord for this cover image\n\t * @param options - Optional options for the cover image\n\t */\n\tpublic guildScheduledEventCover(\n\t\tscheduledEventId: string,\n\t\tcoverHash: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.\n\t *\n\t * @param route - The base cdn route\n\t * @param hash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the link\n\t */\n\tprivate dynamicMakeURL(\n\t\troute: string,\n\t\thash: string,\n\t\t{ forceStatic = false, ...options }: Readonly<ImageURLOptions> = {},\n\t): string {\n\t\treturn this.makeURL(route, !forceStatic && hash.startsWith('a_') ? { ...options, extension: 'gif' } : options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource\n\t *\n\t * @param route - The base cdn route\n\t * @param options - The extension/size options for the link\n\t */\n\tprivate makeURL(\n\t\troute: string,\n\t\t{ allowedExtensions = ALLOWED_EXTENSIONS, extension = 'webp', size }: Readonly<MakeURLOptions> = {},\n\t): string {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\textension = String(extension).toLowerCase();\n\n\t\tif (!allowedExtensions.includes(extension)) {\n\t\t\tthrow new RangeError(`Invalid extension provided: ${extension}\\nMust be one of: ${allowedExtensions.join(', ')}`);\n\t\t}\n\n\t\tif (size && !ALLOWED_SIZES.includes(size)) {\n\t\t\tthrow new RangeError(`Invalid size provided: ${size}\\nMust be one of: ${ALLOWED_SIZES.join(', ')}`);\n\t\t}\n\n\t\tconst url = new URL(`${this.base}${route}.${extension}`);\n\n\t\tif (size) {\n\t\t\turl.searchParams.set('size', String(size));\n\t\t}\n\n\t\treturn url.toString();\n\t}\n}\n","import type { InternalRequest, RawFile } from '../utils/types.js';\n\ninterface DiscordErrorFieldInformation {\n\tcode: string;\n\tmessage: string;\n}\n\ninterface DiscordErrorGroupWrapper {\n\t_errors: DiscordError[];\n}\n\ntype DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | { [k: string]: DiscordError };\n\nexport interface DiscordErrorData {\n\tcode: number;\n\terrors?: DiscordError;\n\tmessage: string;\n}\n\nexport interface OAuthErrorData {\n\terror: string;\n\terror_description?: string;\n}\n\nexport interface RequestBody {\n\tfiles: RawFile[] | undefined;\n\tjson: unknown | undefined;\n}\n\nfunction isErrorGroupWrapper(error: DiscordError): error is DiscordErrorGroupWrapper {\n\treturn Reflect.has(error as Record<string, unknown>, '_errors');\n}\n\nfunction isErrorResponse(error: DiscordError): error is DiscordErrorFieldInformation {\n\treturn typeof Reflect.get(error as Record<string, unknown>, 'message') === 'string';\n}\n\n/**\n * Represents an API error returned by Discord\n */\nexport class DiscordAPIError extends Error {\n\tpublic requestBody: RequestBody;\n\n\t/**\n\t * @param rawError - The error reported by Discord\n\t * @param code - The error code reported by Discord\n\t * @param status - The status code of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic rawError: DiscordErrorData | OAuthErrorData,\n\t\tpublic code: number | string,\n\t\tpublic status: number,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(DiscordAPIError.getMessage(rawError));\n\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${DiscordAPIError.name}[${this.code}]`;\n\t}\n\n\tprivate static getMessage(error: DiscordErrorData | OAuthErrorData) {\n\t\tlet flattened = '';\n\t\tif ('code' in error) {\n\t\t\tif (error.errors) {\n\t\t\t\tflattened = [...this.flattenDiscordError(error.errors)].join('\\n');\n\t\t\t}\n\n\t\t\treturn error.message && flattened\n\t\t\t\t? `${error.message}\\n${flattened}`\n\t\t\t\t: error.message || flattened || 'Unknown Error';\n\t\t}\n\n\t\treturn error.error_description ?? 'No Description';\n\t}\n\n\tprivate static *flattenDiscordError(obj: DiscordError, key = ''): IterableIterator<string> {\n\t\tif (isErrorResponse(obj)) {\n\t\t\treturn yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim();\n\t\t}\n\n\t\tfor (const [otherKey, val] of Object.entries(obj)) {\n\t\t\tconst nextKey = otherKey.startsWith('_')\n\t\t\t\t? key\n\t\t\t\t: key\n\t\t\t\t? Number.isNaN(Number(otherKey))\n\t\t\t\t\t? `${key}.${otherKey}`\n\t\t\t\t\t: `${key}[${otherKey}]`\n\t\t\t\t: otherKey;\n\n\t\t\tif (typeof val === 'string') {\n\t\t\t\tyield val;\n\t\t\t} else if (isErrorGroupWrapper(val)) {\n\t\t\t\tfor (const error of val._errors) {\n\t\t\t\t\tyield* this.flattenDiscordError(error, nextKey);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield* this.flattenDiscordError(val, nextKey);\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { InternalRequest } from '../utils/types.js';\nimport type { RequestBody } from './DiscordAPIError.js';\n\n/**\n * Represents a HTTP error\n */\nexport class HTTPError extends Error {\n\tpublic requestBody: RequestBody;\n\n\tpublic override name = HTTPError.name;\n\n\t/**\n\t * @param status - The status code of the response\n\t * @param statusText - The status text of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic status: number,\n\t\tstatusText: string,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(statusText);\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n}\n","import type { RateLimitData } from '../utils/types.js';\n\nexport class RateLimitError extends Error implements RateLimitData {\n\tpublic timeToReset: number;\n\n\tpublic limit: number;\n\n\tpublic method: string;\n\n\tpublic hash: string;\n\n\tpublic url: string;\n\n\tpublic route: string;\n\n\tpublic majorParameter: string;\n\n\tpublic global: boolean;\n\n\tpublic constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData) {\n\t\tsuper();\n\t\tthis.timeToReset = timeToReset;\n\t\tthis.limit = limit;\n\t\tthis.method = method;\n\t\tthis.hash = hash;\n\t\tthis.url = url;\n\t\tthis.route = route;\n\t\tthis.majorParameter = majorParameter;\n\t\tthis.global = global;\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${RateLimitError.name}[${this.route}]`;\n\t}\n}\n","import { Collection } from '@discordjs/collection';\nimport { DiscordSnowflake } from '@sapphire/snowflake';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { filetypeinfo } from 'magic-bytes.js';\nimport type { RequestInit, BodyInit, Dispatcher } from 'undici';\nimport { CDN } from './CDN.js';\nimport { BurstHandler } from './handlers/BurstHandler.js';\nimport { SequentialHandler } from './handlers/SequentialHandler.js';\nimport type { IHandler } from './interfaces/Handler.js';\nimport {\n\tBurstHandlerMajorIdKey,\n\tDefaultRestOptions,\n\tDefaultUserAgent,\n\tOverwrittenMimeTypes,\n\tRESTEvents,\n} from './utils/constants.js';\nimport { RequestMethod } from './utils/types.js';\nimport type {\n\tRESTOptions,\n\tResponseLike,\n\tRestEventsMap,\n\tHashData,\n\tInternalRequest,\n\tRouteLike,\n\tRequestHeaders,\n\tRouteData,\n\tRequestData,\n} from './utils/types.js';\nimport { isBufferLike, parseResponse } from './utils/utils.js';\n\n/**\n * Represents the class that manages handlers for endpoints\n */\nexport class REST extends AsyncEventEmitter<RestEventsMap> {\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests\n\t * performed by this manager.\n\t */\n\tpublic agent: Dispatcher | null = null;\n\n\tpublic readonly cdn: CDN;\n\n\t/**\n\t * The number of requests remaining in the global bucket\n\t */\n\tpublic globalRemaining: number;\n\n\t/**\n\t * The promise used to wait out the global rate limit\n\t */\n\tpublic globalDelay: Promise<void> | null = null;\n\n\t/**\n\t * The timestamp at which the global bucket resets\n\t */\n\tpublic globalReset = -1;\n\n\t/**\n\t * API bucket hashes that are cached from provided routes\n\t */\n\tpublic readonly hashes = new Collection<string, HashData>();\n\n\t/**\n\t * Request handlers created from the bucket hash and the major parameters\n\t */\n\tpublic readonly handlers = new Collection<string, IHandler>();\n\n\t#token: string | null = null;\n\n\tprivate hashTimer!: NodeJS.Timer | number;\n\n\tprivate handlerTimer!: NodeJS.Timer | number;\n\n\tpublic readonly options: RESTOptions;\n\n\tpublic constructor(options: Partial<RESTOptions> = {}) {\n\t\tsuper();\n\t\tthis.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn);\n\t\tthis.options = { ...DefaultRestOptions, ...options };\n\t\tthis.options.offset = Math.max(0, this.options.offset);\n\t\tthis.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond);\n\t\tthis.agent = options.agent ?? null;\n\n\t\t// Start sweepers\n\t\tthis.setupSweepers();\n\t}\n\n\tprivate setupSweepers() {\n\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\tconst validateMaxInterval = (interval: number) => {\n\t\t\tif (interval > 14_400_000) {\n\t\t\t\tthrow new Error('Cannot set an interval greater than 4 hours');\n\t\t\t}\n\t\t};\n\n\t\tif (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.hashSweepInterval);\n\t\t\tthis.hashTimer = setInterval(() => {\n\t\t\t\tconst sweptHashes = new Collection<string, HashData>();\n\t\t\t\tconst currentDate = Date.now();\n\n\t\t\t\t// Begin sweeping hash based on lifetimes\n\t\t\t\tthis.hashes.sweep((val, key) => {\n\t\t\t\t\t// `-1` indicates a global hash\n\t\t\t\t\tif (val.lastAccess === -1) return false;\n\n\t\t\t\t\t// Check if lifetime has been exceeded\n\t\t\t\t\tconst shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime;\n\n\t\t\t\t\t// Add hash to collection of swept hashes\n\t\t\t\t\tif (shouldSweep) {\n\t\t\t\t\t\t// Add to swept hashes\n\t\t\t\t\t\tsweptHashes.set(key, val);\n\n\t\t\t\t\t\t// Emit debug information\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn shouldSweep;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HashSweep, sweptHashes);\n\t\t\t}, this.options.hashSweepInterval);\n\n\t\t\tthis.hashTimer.unref?.();\n\t\t}\n\n\t\tif (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.handlerSweepInterval);\n\t\t\tthis.handlerTimer = setInterval(() => {\n\t\t\t\tconst sweptHandlers = new Collection<string, IHandler>();\n\n\t\t\t\t// Begin sweeping handlers based on activity\n\t\t\t\tthis.handlers.sweep((val, key) => {\n\t\t\t\t\tconst { inactive } = val;\n\n\t\t\t\t\t// Collect inactive handlers\n\t\t\t\t\tif (inactive) {\n\t\t\t\t\t\tsweptHandlers.set(key, val);\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Handler ${val.id} for ${key} swept due to being inactive`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn inactive;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HandlerSweep, sweptHandlers);\n\t\t\t}, this.options.handlerSweepInterval);\n\n\t\t\tthis.handlerTimer.unref?.();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a get request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async get(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Get });\n\t}\n\n\t/**\n\t * Runs a delete request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async delete(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Delete });\n\t}\n\n\t/**\n\t * Runs a post request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async post(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Post });\n\t}\n\n\t/**\n\t * Runs a put request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async put(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Put });\n\t}\n\n\t/**\n\t * Runs a patch request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async patch(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Patch });\n\t}\n\n\t/**\n\t * Runs a request from the api\n\t *\n\t * @param options - Request options\n\t */\n\tpublic async request(options: InternalRequest) {\n\t\tconst response = await this.queueRequest(options);\n\t\treturn parseResponse(response);\n\t}\n\n\t/**\n\t * Sets the default agent to use for requests performed by this manager\n\t *\n\t * @param agent - The agent to use\n\t */\n\tpublic setAgent(agent: Dispatcher) {\n\t\tthis.agent = agent;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the authorization token that should be used for requests\n\t *\n\t * @param token - The authorization token to use\n\t */\n\tpublic setToken(token: string) {\n\t\tthis.#token = token;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Queues a request to be sent\n\t *\n\t * @param request - All the information needed to make a request\n\t * @returns The response from the api request\n\t */\n\tpublic async queueRequest(request: InternalRequest): Promise<ResponseLike> {\n\t\t// Generalize the endpoint to its route data\n\t\tconst routeId = REST.generateRouteData(request.fullRoute, request.method);\n\t\t// Get the bucket hash for the generic route, or point to a global route otherwise\n\t\tconst hash = this.hashes.get(`${request.method}:${routeId.bucketRoute}`) ?? {\n\t\t\tvalue: `Global(${request.method}:${routeId.bucketRoute})`,\n\t\t\tlastAccess: -1,\n\t\t};\n\n\t\t// Get the request handler for the obtained hash, with its major parameter\n\t\tconst handler =\n\t\t\tthis.handlers.get(`${hash.value}:${routeId.majorParameter}`) ??\n\t\t\tthis.createHandler(hash.value, routeId.majorParameter);\n\n\t\t// Resolve the request into usable fetch options\n\t\tconst { url, fetchOptions } = await this.resolveRequest(request);\n\n\t\t// Queue the request\n\t\treturn handler.queueRequest(routeId, url, fetchOptions, {\n\t\t\tbody: request.body,\n\t\t\tfiles: request.files,\n\t\t\tauth: request.auth !== false,\n\t\t\tsignal: request.signal,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a new rate limit handler from a hash, based on the hash and the major parameter\n\t *\n\t * @param hash - The hash for the route\n\t * @param majorParameter - The major parameter for this handler\n\t * @internal\n\t */\n\tprivate createHandler(hash: string, majorParameter: string) {\n\t\t// Create the async request queue to handle requests\n\t\tconst queue =\n\t\t\tmajorParameter === BurstHandlerMajorIdKey\n\t\t\t\t? new BurstHandler(this, hash, majorParameter)\n\t\t\t\t: new SequentialHandler(this, hash, majorParameter);\n\t\t// Save the queue based on its id\n\t\tthis.handlers.set(queue.id, queue);\n\n\t\treturn queue;\n\t}\n\n\t/**\n\t * Formats the request data to a usable format for fetch\n\t *\n\t * @param request - The request data\n\t */\n\tprivate async resolveRequest(request: InternalRequest): Promise<{ fetchOptions: RequestInit; url: string }> {\n\t\tconst { options } = this;\n\n\t\tlet query = '';\n\n\t\t// If a query option is passed, use it\n\t\tif (request.query) {\n\t\t\tconst resolvedQuery = request.query.toString();\n\t\t\tif (resolvedQuery !== '') {\n\t\t\t\tquery = `?${resolvedQuery}`;\n\t\t\t}\n\t\t}\n\n\t\t// Create the required headers\n\t\tconst headers: RequestHeaders = {\n\t\t\t...this.options.headers,\n\t\t\t'User-Agent': `${DefaultUserAgent} ${options.userAgentAppendix}`.trim(),\n\t\t};\n\n\t\t// If this request requires authorization (allowing non-\"authorized\" requests for webhooks)\n\t\tif (request.auth !== false) {\n\t\t\t// If we haven't received a token, throw an error\n\t\t\tif (!this.#token) {\n\t\t\t\tthrow new Error('Expected token to be set for this request, but none was present');\n\t\t\t}\n\n\t\t\theaders.Authorization = `${request.authPrefix ?? this.options.authPrefix} ${this.#token}`;\n\t\t}\n\n\t\t// If a reason was set, set it's appropriate header\n\t\tif (request.reason?.length) {\n\t\t\theaders['X-Audit-Log-Reason'] = encodeURIComponent(request.reason);\n\t\t}\n\n\t\t// Format the full request URL (api base, optional version, endpoint, optional querystring)\n\t\tconst url = `${options.api}${request.versioned === false ? '' : `/v${options.version}`}${\n\t\t\trequest.fullRoute\n\t\t}${query}`;\n\n\t\tlet finalBody: RequestInit['body'];\n\t\tlet additionalHeaders: Record<string, string> = {};\n\n\t\tif (request.files?.length) {\n\t\t\tconst formData = new FormData();\n\n\t\t\t// Attach all files to the request\n\t\t\tfor (const [index, file] of request.files.entries()) {\n\t\t\t\tconst fileKey = file.key ?? `files[${index}]`;\n\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#parameters\n\t\t\t\t// FormData.append only accepts a string or Blob.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters\n\t\t\t\t// The Blob constructor accepts TypedArray/ArrayBuffer, strings, and Blobs.\n\t\t\t\tif (isBufferLike(file.data)) {\n\t\t\t\t\t// Try to infer the content type from the buffer if one isn't passed\n\t\t\t\t\tlet contentType = file.contentType;\n\n\t\t\t\t\tif (!contentType) {\n\t\t\t\t\t\tconst [parsedType] = filetypeinfo(file.data);\n\n\t\t\t\t\t\tif (parsedType) {\n\t\t\t\t\t\t\tcontentType =\n\t\t\t\t\t\t\t\tOverwrittenMimeTypes[parsedType.mime as keyof typeof OverwrittenMimeTypes] ??\n\t\t\t\t\t\t\t\tparsedType.mime ??\n\t\t\t\t\t\t\t\t'application/octet-stream';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tformData.append(fileKey, new Blob([file.data], { type: contentType }), file.name);\n\t\t\t\t} else {\n\t\t\t\t\tformData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If a JSON body was added as well, attach it to the form data, using payload_json unless otherwise specified\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t\tif (request.body != null) {\n\t\t\t\tif (request.appendToFormData) {\n\t\t\t\t\tfor (const [key, value] of Object.entries(request.body as Record<string, unknown>)) {\n\t\t\t\t\t\tformData.append(key, value);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tformData.append('payload_json', JSON.stringify(request.body));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Set the final body to the form data\n\t\t\tfinalBody = formData;\n\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t} else if (request.body != null) {\n\t\t\tif (request.passThroughBody) {\n\t\t\t\tfinalBody = request.body as BodyInit;\n\t\t\t} else {\n\t\t\t\t// Stringify the JSON data\n\t\t\t\tfinalBody = JSON.stringify(request.body);\n\t\t\t\t// Set the additional headers to specify the content-type\n\t\t\t\tadditionalHeaders = { 'Content-Type': 'application/json' };\n\t\t\t}\n\t\t}\n\n\t\tconst method = request.method.toUpperCase();\n\n\t\t// The non null assertions in the following block are due to exactOptionalPropertyTypes, they have been tested to work with undefined\n\t\tconst fetchOptions: RequestInit = {\n\t\t\t// Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing\n\t\t\tbody: ['GET', 'HEAD'].includes(method) ? null : finalBody!,\n\t\t\theaders: { ...request.headers, ...additionalHeaders, ...headers } as Record<string, string>,\n\t\t\tmethod,\n\t\t\t// Prioritize setting an agent per request, use the agent for this instance otherwise.\n\t\t\tdispatcher: request.dispatcher ?? this.agent ?? undefined!,\n\t\t};\n\n\t\treturn { url, fetchOptions };\n\t}\n\n\t/**\n\t * Stops the hash sweeping interval\n\t */\n\tpublic clearHashSweeper() {\n\t\tclearInterval(this.hashTimer);\n\t}\n\n\t/**\n\t * Stops the request handler sweeping interval\n\t */\n\tpublic clearHandlerSweeper() {\n\t\tclearInterval(this.handlerTimer);\n\t}\n\n\t/**\n\t * Generates route data for an endpoint:method\n\t *\n\t * @param endpoint - The raw endpoint to generalize\n\t * @param method - The HTTP method this endpoint is called without\n\t * @internal\n\t */\n\tprivate static generateRouteData(endpoint: RouteLike, method: RequestMethod): RouteData {\n\t\tif (endpoint.startsWith('/interactions/') && endpoint.endsWith('/callback')) {\n\t\t\treturn {\n\t\t\t\tmajorParameter: BurstHandlerMajorIdKey,\n\t\t\t\tbucketRoute: '/interactions/:id/:token/callback',\n\t\t\t\toriginal: endpoint,\n\t\t\t};\n\t\t}\n\n\t\tconst majorIdMatch = /^\\/(?:channels|guilds|webhooks)\\/(\\d{17,19})/.exec(endpoint);\n\n\t\t// Get the major id for this route - global otherwise\n\t\tconst majorId = majorIdMatch?.[1] ?? 'global';\n\n\t\tconst baseRoute = endpoint\n\t\t\t// Strip out all ids\n\t\t\t.replaceAll(/\\d{17,19}/g, ':id')\n\t\t\t// Strip out reaction as they fall under the same bucket\n\t\t\t.replace(/\\/reactions\\/(.*)/, '/reactions/:reaction');\n\n\t\tlet exceptions = '';\n\n\t\t// Hard-Code Old Message Deletion Exception (2 week+ old messages are a different bucket)\n\t\t// https://github.com/discord/discord-api-docs/issues/1295\n\t\tif (method === RequestMethod.Delete && baseRoute === '/channels/:id/messages/:id') {\n\t\t\tconst id = /\\d{17,19}$/.exec(endpoint)![0]!;\n\t\t\tconst timestamp = DiscordSnowflake.timestampFrom(id);\n\t\t\tif (Date.now() - timestamp > 1_000 * 60 * 60 * 24 * 14) {\n\t\t\t\texceptions += '/Delete Old Message';\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tmajorParameter: majorId,\n\t\t\tbucketRoute: baseRoute + exceptions,\n\t\t\toriginal: endpoint,\n\t\t};\n\t}\n}\n","import type { Readable } from 'node:stream';\nimport type { ReadableStream } from 'node:stream/web';\nimport type { Collection } from '@discordjs/collection';\nimport type { Agent, Dispatcher, RequestInit, BodyInit, Response } from 'undici';\nimport type { IHandler } from '../interfaces/Handler.js';\n\nexport interface RestEvents {\n\thandlerSweep: [sweptHandlers: Collection<string, IHandler>];\n\thashSweep: [sweptHashes: Collection<string, HashData>];\n\tinvalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];\n\trateLimited: [rateLimitInfo: RateLimitData];\n\tresponse: [request: APIRequest, response: ResponseLike];\n\trestDebug: [info: string];\n}\n\nexport type RestEventsMap = {\n\t[K in keyof RestEvents]: RestEvents[K];\n};\n\n/**\n * Options to be passed when creating the REST instance\n */\nexport interface RESTOptions {\n\t/**\n\t * The agent to set globally\n\t */\n\tagent: Dispatcher | null;\n\t/**\n\t * The base api path, without version\n\t *\n\t * @defaultValue `'https://discord.com/api'`\n\t */\n\tapi: string;\n\t/**\n\t * The authorization prefix to use for requests, useful if you want to use\n\t * bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix: 'Bearer' | 'Bot';\n\t/**\n\t * The cdn path\n\t *\n\t * @defaultValue `'https://cdn.discordapp.com'`\n\t */\n\tcdn: string;\n\t/**\n\t * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)\n\t *\n\t * @defaultValue `50`\n\t */\n\tglobalRequestsPerSecond: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)\n\t *\n\t * @defaultValue `3_600_000`\n\t */\n\thandlerSweepInterval: number;\n\t/**\n\t * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)\n\t *\n\t * @defaultValue `86_400_000`\n\t */\n\thashLifetime: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)\n\t *\n\t * @defaultValue `14_400_000`\n\t */\n\thashSweepInterval: number;\n\t/**\n\t * Additional headers to send for all API requests\n\t *\n\t * @defaultValue `{}`\n\t */\n\theaders: Record<string, string>;\n\t/**\n\t * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).\n\t * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.\n\t *\n\t * @defaultValue `0`\n\t */\n\tinvalidRequestWarningInterval: number;\n\t/**\n\t * The method called to perform the actual HTTP request given a url and web `fetch` options\n\t * For example, to use global fetch, simply provide `makeRequest: fetch`\n\t */\n\tmakeRequest(url: string, init: RequestInit): Promise<ResponseLike>;\n\t/**\n\t * The extra offset to add to rate limits in milliseconds\n\t *\n\t * @defaultValue `50`\n\t */\n\toffset: number;\n\t/**\n\t * Determines how rate limiting and pre-emptive throttling should be handled.\n\t * When an array of strings, each element is treated as a prefix for the request route\n\t * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)\n\t * for which to throw {@link RateLimitError}s. All other request routes will be queued normally\n\t *\n\t * @defaultValue `null`\n\t */\n\trejectOnRateLimit: RateLimitQueueFilter | string[] | null;\n\t/**\n\t * The number of retries for errors with the 500 code, or errors\n\t * that timeout\n\t *\n\t * @defaultValue `3`\n\t */\n\tretries: number;\n\t/**\n\t * The time to wait in milliseconds before a request is aborted\n\t *\n\t * @defaultValue `15_000`\n\t */\n\ttimeout: number;\n\t/**\n\t * Extra information to add to the user agent\n\t *\n\t * @defaultValue DefaultUserAgentAppendix\n\t */\n\tuserAgentAppendix: string;\n\t/**\n\t * The version of the API to use\n\t *\n\t * @defaultValue `'10'`\n\t */\n\tversion: string;\n}\n\n/**\n * Data emitted on `RESTEvents.RateLimited`\n */\nexport interface RateLimitData {\n\t/**\n\t * Whether the rate limit that was reached was the global limit\n\t */\n\tglobal: boolean;\n\t/**\n\t * The bucket hash for this request\n\t */\n\thash: string;\n\t/**\n\t * The amount of requests we can perform before locking requests\n\t */\n\tlimit: number;\n\t/**\n\t * The major parameter of the route\n\t *\n\t * For example, in `/channels/x`, this will be `x`.\n\t * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.\n\t */\n\tmajorParameter: string;\n\t/**\n\t * The HTTP method being performed\n\t */\n\tmethod: string;\n\t/**\n\t * The route being hit in this request\n\t */\n\troute: string;\n\t/**\n\t * The time, in milliseconds, until the request-lock is reset\n\t */\n\ttimeToReset: number;\n\t/**\n\t * The full URL for this request\n\t */\n\turl: string;\n}\n\n/**\n * A function that determines whether the rate limit hit should throw an Error\n */\nexport type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Promise<boolean> | boolean;\n\nexport interface APIRequest {\n\t/**\n\t * The data that was used to form the body of this request\n\t */\n\tdata: HandlerRequestData;\n\t/**\n\t * The HTTP method used in this request\n\t */\n\tmethod: string;\n\t/**\n\t * Additional HTTP options for this request\n\t */\n\toptions: RequestInit;\n\t/**\n\t * The full path used to make the request\n\t */\n\tpath: RouteLike;\n\t/**\n\t * The number of times this request has been attempted\n\t */\n\tretries: number;\n\t/**\n\t * The API route identifying the ratelimit for this request\n\t */\n\troute: string;\n}\n\nexport interface ResponseLike\n\textends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {\n\tbody: Readable | ReadableStream | null;\n}\n\nexport interface InvalidRequestWarningData {\n\t/**\n\t * Number of invalid requests that have been made in the window\n\t */\n\tcount: number;\n\t/**\n\t * Time in milliseconds remaining before the count resets\n\t */\n\tremainingTime: number;\n}\n\n/**\n * Represents a file to be added to the request\n */\nexport interface RawFile {\n\t/**\n\t * Content-Type of the file\n\t */\n\tcontentType?: string;\n\t/**\n\t * The actual data for the file\n\t */\n\tdata: Buffer | Uint8Array | boolean | number | string;\n\t/**\n\t * An explicit key to use for key of the formdata field for this file.\n\t * When not provided, the index of the file in the files array is used in the form `files[${index}]`.\n\t * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)\n\t */\n\tkey?: string;\n\t/**\n\t * The name of the file\n\t */\n\tname: string;\n}\n\n/**\n * Represents possible data to be given to an endpoint\n */\nexport interface RequestData {\n\t/**\n\t * Whether to append JSON data to form data instead of `payload_json` when sending files\n\t */\n\tappendToFormData?: boolean;\n\t/**\n\t * If this request needs the `Authorization` header\n\t *\n\t * @defaultValue `true`\n\t */\n\tauth?: boolean;\n\t/**\n\t * The authorization prefix to use for this request, useful if you use this with bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix?: 'Bearer' | 'Bot';\n\t/**\n\t * The body to send to this request.\n\t * If providing as BodyInit, set `passThroughBody: true`\n\t */\n\tbody?: BodyInit | unknown;\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.\n\t */\n\tdispatcher?: Agent;\n\t/**\n\t * Files to be attached to this request\n\t */\n\tfiles?: RawFile[] | undefined;\n\t/**\n\t * Additional headers to add to this request\n\t */\n\theaders?: Record<string, string>;\n\t/**\n\t * Whether to pass-through the body property directly to `fetch()`.\n\t * <warn>This only applies when files is NOT present</warn>\n\t */\n\tpassThroughBody?: boolean;\n\t/**\n\t * Query string parameters to append to the called endpoint\n\t */\n\tquery?: URLSearchParams;\n\t/**\n\t * Reason to show in the audit logs\n\t */\n\treason?: string | undefined;\n\t/**\n\t * The signal to abort the queue entry or the REST call, where applicable\n\t */\n\tsignal?: AbortSignal | undefined;\n\t/**\n\t * If this request should be versioned\n\t *\n\t * @defaultValue `true`\n\t */\n\tversioned?: boolean;\n}\n\n/**\n * Possible headers for an API call\n */\nexport interface RequestHeaders {\n\tAuthorization?: string;\n\t'User-Agent': string;\n\t'X-Audit-Log-Reason'?: string;\n}\n\n/**\n * Possible API methods to be used when doing requests\n */\nexport enum RequestMethod {\n\tDelete = 'DELETE',\n\tGet = 'GET',\n\tPatch = 'PATCH',\n\tPost = 'POST',\n\tPut = 'PUT',\n}\n\nexport type RouteLike = `/${string}`;\n\n/**\n * Internal request options\n *\n * @internal\n */\nexport interface InternalRequest extends RequestData {\n\tfullRoute: RouteLike;\n\tmethod: RequestMethod;\n}\n\nexport type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;\n\n/**\n * Parsed route data for an endpoint\n *\n * @internal\n */\nexport interface RouteData {\n\tbucketRoute: string;\n\tmajorParameter: string;\n\toriginal: RouteLike;\n}\n\n/**\n * Represents a hash and its associated fields\n *\n * @internal\n */\nexport interface HashData {\n\tlastAccess: number;\n\tvalue: string;\n}\n","import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';\nimport type { REST } from '../REST.js';\nimport { RateLimitError } from '../errors/RateLimitError.js';\nimport { RequestMethod, type RateLimitData, type ResponseLike } from './types.js';\n\nfunction serializeSearchParam(value: unknown): string | null {\n\tswitch (typeof value) {\n\t\tcase 'string':\n\t\t\treturn value;\n\t\tcase 'number':\n\t\tcase 'bigint':\n\t\tcase 'boolean':\n\t\t\treturn value.toString();\n\t\tcase 'object':\n\t\t\tif (value === null) return null;\n\t\t\tif (value instanceof Date) {\n\t\t\t\treturn Number.isNaN(value.getTime()) ? null : value.toISOString();\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) return value.toString();\n\t\t\treturn null;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n/**\n * Creates and populates an URLSearchParams instance from an object, stripping\n * out null and undefined values, while also coercing non-strings to strings.\n *\n * @param options - The options to use\n * @returns A populated URLSearchParams instance\n */\nexport function makeURLSearchParams<T extends object>(options?: Readonly<T>) {\n\tconst params = new URLSearchParams();\n\tif (!options) return params;\n\n\tfor (const [key, value] of Object.entries(options)) {\n\t\tconst serialized = serializeSearchParam(value);\n\t\tif (serialized !== null) params.append(key, serialized);\n\t}\n\n\treturn params;\n}\n\n/**\n * Converts the response to usable data\n *\n * @param res - The fetch response\n */\nexport async function parseResponse(res: ResponseLike): Promise<unknown> {\n\tif (res.headers.get('Content-Type')?.startsWith('application/json')) {\n\t\treturn res.json();\n\t}\n\n\treturn res.arrayBuffer();\n}\n\n/**\n * Check whether a request falls under a sublimit\n *\n * @param bucketRoute - The buckets route identifier\n * @param body - The options provided as JSON data\n * @param method - The HTTP method that will be used to make the request\n * @returns Whether the request falls under a sublimit\n */\nexport function hasSublimit(bucketRoute: string, body?: unknown, method?: string): boolean {\n\t// TODO: Update for new sublimits\n\t// Currently known sublimits:\n\t// Editing channel `name` or `topic`\n\tif (bucketRoute === '/channels/:id') {\n\t\tif (typeof body !== 'object' || body === null) return false;\n\t\t// This should never be a POST body, but just in case\n\t\tif (method !== RequestMethod.Patch) return false;\n\t\tconst castedBody = body as RESTPatchAPIChannelJSONBody;\n\t\treturn ['name', 'topic'].some((key) => Reflect.has(castedBody, key));\n\t}\n\n\t// If we are checking if a request has a sublimit on a route not checked above, sublimit all requests to avoid a flood of 429s\n\treturn true;\n}\n\n/**\n * Check whether an error indicates that a retry can be attempted\n *\n * @param error - The error thrown by the network request\n * @returns Whether the error indicates a retry should be attempted\n */\nexport function shouldRetry(error: Error | NodeJS.ErrnoException) {\n\t// Retry for possible timed out requests\n\tif (error.name === 'AbortError') return true;\n\t// Downlevel ECONNRESET to retry as it may be recoverable\n\treturn ('code' in error && error.code === 'ECONNRESET') || error.message.includes('ECONNRESET');\n}\n\n/**\n * Determines whether the request should be queued or whether a RateLimitError should be thrown\n *\n * @internal\n */\nexport async function onRateLimit(manager: REST, rateLimitData: RateLimitData) {\n\tconst { options } = manager;\n\tif (!options.rejectOnRateLimit) return;\n\n\tconst shouldThrow =\n\t\ttypeof options.rejectOnRateLimit === 'function'\n\t\t\t? await options.rejectOnRateLimit(rateLimitData)\n\t\t\t: options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));\n\tif (shouldThrow) {\n\t\tthrow new RateLimitError(rateLimitData);\n\t}\n}\n\n/**\n * Calculates the default avatar index for a given user id.\n *\n * @param userId - The user id to calculate the default avatar index for\n */\nexport function calculateUserDefaultAvatarIndex(userId: Snowflake) {\n\treturn Number(BigInt(userId) >> 22n) % 6;\n}\n\n/**\n * Sleeps for a given amount of time.\n *\n * @param ms - The amount of time (in milliseconds) to sleep for\n */\nexport async function sleep(ms: number): Promise<void> {\n\treturn new Promise<void>((resolve) => {\n\t\tsetTimeout(() => resolve(), ms);\n\t});\n}\n\n/**\n * Verifies that a value is a buffer-like object.\n *\n * @param value - The value to check\n */\nexport function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Uint8Array | Uint8ClampedArray {\n\treturn value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError.js';\nimport { DiscordAPIError } from '../errors/DiscordAPIError.js';\nimport { HTTPError } from '../errors/HTTPError.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { parseResponse, shouldRetry } from '../utils/utils.js';\n\n/**\n * Invalid request limiting is done on a per-IP basis, not a per-token basis.\n * The best we can do is track invalid counts process-wide (on the theory that\n * users could have multiple bots run from one process) rather than per-bot.\n * Therefore, store these at file scope here rather than in the client's\n * RESTManager object.\n */\nlet invalidCount = 0;\nlet invalidCountResetTime: number | null = null;\n\n/**\n * Increment the invalid request count and emit warning if necessary\n *\n * @internal\n */\nexport function incrementInvalidCount(manager: REST) {\n\tif (!invalidCountResetTime || invalidCountResetTime < Date.now()) {\n\t\tinvalidCountResetTime = Date.now() + 1_000 * 60 * 10;\n\t\tinvalidCount = 0;\n\t}\n\n\tinvalidCount++;\n\n\tconst emitInvalid =\n\t\tmanager.options.invalidRequestWarningInterval > 0 &&\n\t\tinvalidCount % manager.options.invalidRequestWarningInterval === 0;\n\tif (emitInvalid) {\n\t\t// Let library users know periodically about invalid requests\n\t\tmanager.emit(RESTEvents.InvalidRequestWarning, {\n\t\t\tcount: invalidCount,\n\t\t\tremainingTime: invalidCountResetTime - Date.now(),\n\t\t});\n\t}\n}\n\n/**\n * Performs the actual network request for a request handler\n *\n * @param manager - The manager that holds options and emits informational events\n * @param routeId - The generalized api route with literal ids for major parameters\n * @param url - The fully resolved url to make the request to\n * @param options - The fetch options needed to make the request\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns The respond from the network or `null` when the request should be retried\n * @internal\n */\nexport async function makeNetworkRequest(\n\tmanager: REST,\n\trouteId: RouteData,\n\turl: string,\n\toptions: RequestInit,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst controller = new AbortController();\n\tconst timeout = setTimeout(() => controller.abort(), manager.options.timeout);\n\tif (requestData.signal) {\n\t\t// If the user signal was aborted, abort the controller, else abort the local signal.\n\t\t// The reason why we don't re-use the user's signal, is because users may use the same signal for multiple\n\t\t// requests, and we do not want to cause unexpected side-effects.\n\t\tif (requestData.signal.aborted) controller.abort();\n\t\telse requestData.signal.addEventListener('abort', () => controller.abort());\n\t}\n\n\tlet res: ResponseLike;\n\ttry {\n\t\tres = await manager.options.makeRequest(url, { ...options, signal: controller.signal });\n\t} catch (error: unknown) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\t// Retry the specified number of times if needed\n\t\tif (shouldRetry(error) && retries !== manager.options.retries) {\n\t\t\t// Retry is handled by the handler upon receiving null\n\t\t\treturn null;\n\t\t}\n\n\t\tthrow error;\n\t} finally {\n\t\tclearTimeout(timeout);\n\t}\n\n\tif (manager.listenerCount(RESTEvents.Response)) {\n\t\tmanager.emit(\n\t\t\tRESTEvents.Response,\n\t\t\t{\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\tpath: routeId.original,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\toptions,\n\t\t\t\tdata: requestData,\n\t\t\t\tretries,\n\t\t\t},\n\t\t\tres instanceof Response ? res.clone() : { ...res },\n\t\t);\n\t}\n\n\treturn res;\n}\n\n/**\n * Handles 5xx and 4xx errors (not 429's) conventionally. 429's should be handled before calling this function\n *\n * @param manager - The manager that holds options and emits informational events\n * @param res - The response received from {@link makeNetworkRequest}\n * @param method - The method used to make the request\n * @param url - The fully resolved url to make the request to\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns - The response if the status code is not handled or null to request a retry\n */\nexport async function handleErrors(\n\tmanager: REST,\n\tres: ResponseLike,\n\tmethod: string,\n\turl: string,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst status = res.status;\n\tif (status >= 500 && status < 600) {\n\t\t// Retry the specified number of times for possible server side issues\n\t\tif (retries !== manager.options.retries) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We are out of retries, throw an error\n\t\tthrow new HTTPError(status, res.statusText, method, url, requestData);\n\t} else {\n\t\t// Handle possible malformed requests\n\t\tif (status >= 400 && status < 500) {\n\t\t\t// If we receive this status code, it means the token we had is no longer valid.\n\t\t\tif (status === 401 && requestData.auth) {\n\t\t\t\tmanager.setToken(null!);\n\t\t\t}\n\n\t\t\t// The request will not succeed for some reason, parse the error returned from the api\n\t\t\tconst data = (await parseResponse(res)) as DiscordErrorData | OAuthErrorData;\n\t\t\t// throw the API error\n\t\t\tthrow new DiscordAPIError(data, 'code' in data ? data.code : data.error, status, method, url, requestData);\n\t\t}\n\n\t\treturn res;\n\t}\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\n/**\n * The structure used to handle burst requests for a given bucket.\n * Burst requests have no ratelimit handling but allow for pre- and post-processing\n * of data in the same manner as sequentially queued requests.\n *\n * @remarks\n * This queue may still emit a rate limit error if an unexpected 429 is hit\n */\nexport class BurstHandler implements IHandler {\n\t/**\n\t * {@inheritdoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic inactive = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\treturn this.runRequest(routeId, url, options, requestData);\n\t}\n\n\t/**\n\t * The method that actually makes the request to the API, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized API route with literal ids for major parameters\n\t * @param url - The fully resolved URL to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (status >= 200 && status < 300) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// Unexpected ratelimit\n\t\t\tconst isGlobal = res.headers.has('X-RateLimit-Global');\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: retryAfter,\n\t\t\t\tlimit: Number.POSITIVE_INFINITY,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${Number.POSITIVE_INFINITY}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : None`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\n\t\t\t// We are bypassing all other limits, but an encountered limit should be respected (it's probably a non-punished rate limit anyways)\n\t\t\tawait sleep(retryAfter);\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","import { AsyncQueue } from '@sapphire/async-queue';\nimport type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { RateLimitData, ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { hasSublimit, onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\nconst enum QueueType {\n\tStandard,\n\tSublimit,\n}\n\n/**\n * The structure used to handle sequential requests for a given bucket\n */\nexport class SequentialHandler implements IHandler {\n\t/**\n\t * {@inheritDoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * The time this rate limit bucket will reset\n\t */\n\tprivate reset = -1;\n\n\t/**\n\t * The remaining requests that can be made before we are rate limited\n\t */\n\tprivate remaining = 1;\n\n\t/**\n\t * The total number of requests that can be made before we are rate limited\n\t */\n\tprivate limit = Number.POSITIVE_INFINITY;\n\n\t/**\n\t * The interface used to sequence async requests sequentially\n\t */\n\t#asyncQueue = new AsyncQueue();\n\n\t/**\n\t * The interface used to sequence sublimited async requests sequentially\n\t */\n\t#sublimitedQueue: AsyncQueue | null = null;\n\n\t/**\n\t * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed\n\t */\n\t#sublimitPromise: { promise: Promise<void>; resolve(): void } | null = null;\n\n\t/**\n\t * Whether the sublimit queue needs to be shifted in the finally block\n\t */\n\t#shiftSublimit = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic get inactive(): boolean {\n\t\treturn (\n\t\t\tthis.#asyncQueue.remaining === 0 &&\n\t\t\t(this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) &&\n\t\t\t!this.limited\n\t\t);\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by the global limit\n\t */\n\tprivate get globalLimited(): boolean {\n\t\treturn this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by its limit\n\t */\n\tprivate get localLimited(): boolean {\n\t\treturn this.remaining <= 0 && Date.now() < this.reset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited\n\t */\n\tprivate get limited(): boolean {\n\t\treturn this.globalLimited || this.localLimited;\n\t}\n\n\t/**\n\t * The time until queued requests can continue\n\t */\n\tprivate get timeToReset(): number {\n\t\treturn this.reset + this.manager.options.offset - Date.now();\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * Delay all requests for the specified amount of time, handling global rate limits\n\t *\n\t * @param time - The amount of time to delay all requests for\n\t */\n\tprivate async globalDelayFor(time: number): Promise<void> {\n\t\tawait sleep(time);\n\t\tthis.manager.globalDelay = null;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\tlet queue = this.#asyncQueue;\n\t\tlet queueType = QueueType.Standard;\n\t\t// Separate sublimited requests when already sublimited\n\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\tqueueType = QueueType.Sublimit;\n\t\t}\n\n\t\t// Wait for any previous requests to be completed before this one is run\n\t\tawait queue.wait({ signal: requestData.signal });\n\t\t// This set handles retroactively sublimiting requests\n\t\tif (queueType === QueueType.Standard) {\n\t\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\t\t/**\n\t\t\t\t * Remove the request from the standard queue, it should never be possible to get here while processing the\n\t\t\t\t * sublimit queue so there is no need to worry about shifting the wrong request\n\t\t\t\t */\n\t\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\t\tconst wait = queue.wait();\n\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\tawait wait;\n\t\t\t} else if (this.#sublimitPromise) {\n\t\t\t\t// Stall requests while the sublimit queue gets processed\n\t\t\t\tawait this.#sublimitPromise.promise;\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request, and return the results\n\t\t\treturn await this.runRequest(routeId, url, options, requestData);\n\t\t} finally {\n\t\t\t// Allow the next request to fire\n\t\t\tqueue.shift();\n\t\t\tif (this.#shiftSublimit) {\n\t\t\t\tthis.#shiftSublimit = false;\n\t\t\t\tthis.#sublimitedQueue?.shift();\n\t\t\t}\n\n\t\t\t// If this request is the last request in a sublimit\n\t\t\tif (this.#sublimitedQueue?.remaining === 0) {\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitedQueue = null;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The method that actually makes the request to the api, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized api route with literal ids for major parameters\n\t * @param url - The fully resolved url to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\t/*\n\t\t * After calculations have been done, pre-emptively stop further requests\n\t\t * Potentially loop until this task can run if e.g. the global rate limit is hit twice\n\t\t */\n\t\twhile (this.limited) {\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\t\t\tlet delay: Promise<void>;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t\t// If this is the first task to reach the global timeout, set the global delay\n\t\t\t\tif (!this.manager.globalDelay) {\n\t\t\t\t\t// The global delay function clears the global delay state when it is resolved\n\t\t\t\t\tthis.manager.globalDelay = this.globalDelayFor(timeout);\n\t\t\t\t}\n\n\t\t\t\tdelay = this.manager.globalDelay;\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t\tdelay = sleep(timeout);\n\t\t\t}\n\n\t\t\tconst rateLimitData: RateLimitData = {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t};\n\t\t\t// Let library users know they have hit a rate limit\n\t\t\tthis.manager.emit(RESTEvents.RateLimited, rateLimitData);\n\t\t\t// Determine whether a RateLimitError should be thrown\n\t\t\tawait onRateLimit(this.manager, rateLimitData);\n\t\t\t// When not erroring, emit debug for what is happening\n\t\t\tif (isGlobal) {\n\t\t\t\tthis.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`);\n\t\t\t} else {\n\t\t\t\tthis.debug(`Waiting ${timeout}ms for rate limit to pass`);\n\t\t\t}\n\n\t\t\t// Wait the remaining time left before the rate limit resets\n\t\t\tawait delay;\n\t\t}\n\n\t\t// As the request goes out, update the global usage information\n\t\tif (!this.manager.globalReset || this.manager.globalReset < Date.now()) {\n\t\t\tthis.manager.globalReset = Date.now() + 1_000;\n\t\t\tthis.manager.globalRemaining = this.manager.options.globalRequestsPerSecond;\n\t\t}\n\n\t\tthis.manager.globalRemaining--;\n\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\n\t\tconst limit = res.headers.get('X-RateLimit-Limit');\n\t\tconst remaining = res.headers.get('X-RateLimit-Remaining');\n\t\tconst reset = res.headers.get('X-RateLimit-Reset-After');\n\t\tconst hash = res.headers.get('X-RateLimit-Bucket');\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Update the total number of requests that can be made before the rate limit resets\n\t\tthis.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY;\n\t\t// Update the number of remaining requests that can be made before the rate limit resets\n\t\tthis.remaining = remaining ? Number(remaining) : 1;\n\t\t// Update the time when this rate limit resets (reset-after is in seconds)\n\t\tthis.reset = reset ? Number(reset) * 1_000 + Date.now() + this.manager.options.offset : Date.now();\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Handle buckets via the hash header retroactively\n\t\tif (hash && hash !== this.hash) {\n\t\t\t// Let library users know when rate limit buckets have been updated\n\t\t\tthis.debug(['Received bucket hash update', ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join('\\n'));\n\t\t\t// This queue will eventually be eliminated via attrition\n\t\t\tthis.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() });\n\t\t} else if (hash) {\n\t\t\t// Handle the case where hash value doesn't change\n\t\t\t// Fetch the hash data from the manager\n\t\t\tconst hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`);\n\n\t\t\t// When fetched, update the last access of the hash\n\t\t\tif (hashData) {\n\t\t\t\thashData.lastAccess = Date.now();\n\t\t\t}\n\t\t}\n\n\t\t// Handle retryAfter, which means we have actually hit a rate limit\n\t\tlet sublimitTimeout: number | null = null;\n\t\tif (retryAfter > 0) {\n\t\t\tif (res.headers.has('X-RateLimit-Global')) {\n\t\t\t\tthis.manager.globalRemaining = 0;\n\t\t\t\tthis.manager.globalReset = Date.now() + retryAfter;\n\t\t\t} else if (!this.localLimited) {\n\t\t\t\t/*\n\t\t\t\t * This is a sublimit (e.g. 2 channel name changes/10 minutes) since the headers don't indicate a\n\t\t\t\t * route-wide rate limit. Don't update remaining or reset to avoid rate limiting the whole\n\t\t\t\t * endpoint, just set a reset time on the request itself to avoid retrying too soon.\n\t\t\t\t */\n\t\t\t\tsublimitTimeout = retryAfter;\n\t\t\t}\n\t\t}\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (res.ok) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// A rate limit was hit - this may happen if the route isn't associated with an official bucket hash yet, or when first globally rate limited\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t}\n\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal.toString()}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${limit}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : 'None'}`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\t\t\t// If caused by a sublimit, wait it out here so other requests on the route can be handled\n\t\t\tif (sublimitTimeout) {\n\t\t\t\t// Normally the sublimit queue will not exist, however, if a sublimit is hit while in the sublimit queue, it will\n\t\t\t\tconst firstSublimit = !this.#sublimitedQueue;\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\tthis.#sublimitedQueue = new AsyncQueue();\n\t\t\t\t\tvoid this.#sublimitedQueue.wait();\n\t\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\t}\n\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitPromise = null;\n\t\t\t\tawait sleep(sublimitTimeout);\n\t\t\t\tlet resolve: () => void;\n\t\t\t\t// eslint-disable-next-line promise/param-names, no-promise-executor-return\n\t\t\t\tconst promise = new Promise<void>((res) => (resolve = res));\n\t\t\t\tthis.#sublimitPromise = { promise, resolve: resolve! };\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\t// Re-queue this request so it can be shifted by the finally\n\t\t\t\t\tawait this.#asyncQueue.wait();\n\t\t\t\t\tthis.#shiftSublimit = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","export * from './lib/CDN.js';\nexport * from './lib/errors/DiscordAPIError.js';\nexport * from './lib/errors/HTTPError.js';\nexport * from './lib/errors/RateLimitError.js';\nexport * from './lib/REST.js';\nexport * from './lib/utils/constants.js';\nexport * from './lib/utils/types.js';\nexport { calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse } from './lib/utils/utils.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\nexport const version = '2.0.1' as string;\n"],"mappings":";;;;AAAA,SAAS,QAAAA,aAAY;AACrB,SAAS,wCAAwC;AACjD,SAAS,YAAAC,iBAAgB;;;ACAzB,IAAI;AAEG,SAAS,mBAAmB,aAAyC;AAC3E,oBAAkB;AACnB;AAFgB;AAIT,SAAS,qBAAqB;AACpC,SAAO;AACR;AAFgB;;;ACRhB,SAAS,oBAAoB;AAC7B,SAAS,mBAAAC,wBAAuB;AAChC,SAAS,aAAa;AACtB,SAA2B,SAAS,eAAe;AAKnD,eAAsB,YAAY,KAAa,MAA0C;AAGxF,QAAM,UAAU;AAAA,IACf,GAAG;AAAA,IACH,MAAM,MAAM,YAAY,KAAK,IAAI;AAAA,EAClC;AACA,QAAM,MAAM,MAAM,QAAQ,KAAK,OAAO;AACtC,SAAO;AAAA,IACN,MAAM,IAAI;AAAA,IACV,MAAM,cAAc;AACnB,aAAO,IAAI,KAAK,YAAY;AAAA,IAC7B;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,IAAI,WAAW;AACd,aAAO,IAAI,KAAK;AAAA,IACjB;AAAA,IACA,SAAS,IAAI,QAAQ,IAAI,OAA4C;AAAA,IACrE,QAAQ,IAAI;AAAA,IACZ,YAAY,aAAa,IAAI,UAAU;AAAA,IACvC,IAAI,IAAI,cAAc,OAAO,IAAI,aAAa;AAAA,EAC/C;AACD;AA3BsB;AA6BtB,eAAsB,YAAY,MAAgF;AAEjH,MAAI,QAAQ,MAAM;AACjB,WAAO;AAAA,EACR,WAAW,O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,SAAS,GAAG,mBAAmB,GAAG,QAAQ;AAAA,MAChE;AAAA;AAAA,MAEA,YAAYA,SAAQ,cAAc,KAAK,SAAS;AAAA,IACjD;AAEA,WAAO,EAAE,KAAK,aAAa;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKO,mBAAmB;AACzB,kBAAc,KAAK,SAAS;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKO,sBAAsB;AAC5B,kBAAc,KAAK,YAAY;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAe,kBAAkB,UAAqB,QAAkC;AACvF,QAAI,SAAS,WAAW,gBAAgB,KAAK,SAAS,SAAS,WAAW,GAAG;AAC5E,aAAO;AAAA,QACN,gBAAgB;AAAA,QAChB,aAAa;AAAA,QACb,UAAU;AAAA,MACX;AAAA,IACD;AAEA,UAAM,eAAe,+CAA+C,KAAK,QAAQ;AAGjF,UAAM,UAAU,eAAe,CAAC,KAAK;AAErC,UAAM,YAAY,SAEhB,WAAW,cAAc,KAAK,EAE9B,QAAQ,qBAAqB,sBAAsB;AAErD,QAAI,aAAa;AAIjB,QAAI,oCAAmC,cAAc,8BAA8B;AAClF,YAAM,KAAK,aAAa,KAAK,QAAQ,EAAG,CAAC;AACzC,YAAM,YAAY,iBAAiB,cAAc,EAAE;AACnD,UAAI,KAAK,IAAI,IAAI,YAAY,MAAQ,KAAK,KAAK,KAAK,IAAI;AACvD,sBAAc;AAAA,MACf;AAAA,IACD;AAEA,WAAO;AAAA,MACN,gBAAgB;AAAA,MAChB,aAAa,YAAY;AAAA,MACzB,UAAU;AAAA,IACX;AAAA,EACD;AACD;;;AMncO,IAAM,UAAU;;;AdPtB,WAAmB,aAAaC;AACjC,WAAW,SAASC;AAEpB,mBAAmB,iCAAiC,IAAI,QAAQ,WAAW;","names":["Blob","FormData","URLSearchParams","URLSearchParams","RESTEvents","RequestMethod","limit","res","request","FormData","Blob"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.mts b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.mts new file mode 100644 index 0000000..4e38977 --- /dev/null +++ b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.mts @@ -0,0 +1,11 @@ +import { request, RequestInit } from 'undici'; +import { R as ResponseLike } from '../types-65527f29.js'; +import 'node:stream'; +import 'node:stream/web'; +import '@discordjs/collection'; + +type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>; +declare function makeRequest(url: string, init: RequestInit): Promise<ResponseLike>; +declare function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>>; + +export { RequestOptions, makeRequest, resolveBody }; diff --git a/node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.ts b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.ts new file mode 100644 index 0000000..4e38977 --- /dev/null +++ b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.d.ts @@ -0,0 +1,11 @@ +import { request, RequestInit } from 'undici'; +import { R as ResponseLike } from '../types-65527f29.js'; +import 'node:stream'; +import 'node:stream/web'; +import '@discordjs/collection'; + +type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>; +declare function makeRequest(url: string, init: RequestInit): Promise<ResponseLike>; +declare function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>>; + +export { RequestOptions, makeRequest, resolveBody }; diff --git a/node_modules/@discordjs/rest/dist/strategies/undiciRequest.js b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.js new file mode 100644 index 0000000..640fe1d --- /dev/null +++ b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.js @@ -0,0 +1,94 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/strategies/undiciRequest.ts +var undiciRequest_exports = {}; +__export(undiciRequest_exports, { + makeRequest: () => makeRequest, + resolveBody: () => resolveBody +}); +module.exports = __toCommonJS(undiciRequest_exports); +var import_node_http = require("http"); +var import_node_url = require("url"); +var import_node_util = require("util"); +var import_undici = require("undici"); +async function makeRequest(url, init) { + const options = { + ...init, + body: await resolveBody(init.body) + }; + const res = await (0, import_undici.request)(url, options); + return { + body: res.body, + async arrayBuffer() { + return res.body.arrayBuffer(); + }, + async json() { + return res.body.json(); + }, + async text() { + return res.body.text(); + }, + get bodyUsed() { + return res.body.bodyUsed; + }, + headers: new import_undici.Headers(res.headers), + status: res.statusCode, + statusText: import_node_http.STATUS_CODES[res.statusCode], + ok: res.statusCode >= 200 && res.statusCode < 300 + }; +} +__name(makeRequest, "makeRequest"); +async function resolveBody(body) { + if (body == null) { + return null; + } else if (typeof body === "string") { + return body; + } else if (import_node_util.types.isUint8Array(body)) { + return body; + } else if (import_node_util.types.isArrayBuffer(body)) { + return new Uint8Array(body); + } else if (body instanceof import_node_url.URLSearchParams) { + return body.toString(); + } else if (body instanceof DataView) { + return new Uint8Array(body.buffer); + } else if (body instanceof Blob) { + return new Uint8Array(await body.arrayBuffer()); + } else if (body instanceof FormData) { + return body; + } else if (body[Symbol.iterator]) { + const chunks = [...body]; + return Buffer.concat(chunks); + } else if (body[Symbol.asyncIterator]) { + const chunks = []; + for await (const chunk of body) { + chunks.push(chunk); + } + return Buffer.concat(chunks); + } + throw new TypeError(`Unable to resolve body.`); +} +__name(resolveBody, "resolveBody"); +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + makeRequest, + resolveBody +}); +//# sourceMappingURL=undiciRequest.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/strategies/undiciRequest.js.map b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.js.map new file mode 100644 index 0000000..e3c49ee --- /dev/null +++ b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/strategies/undiciRequest.ts"],"sourcesContent":["import { STATUS_CODES } from 'node:http';\nimport { URLSearchParams } from 'node:url';\nimport { types } from 'node:util';\nimport { type RequestInit, request, Headers } from 'undici';\nimport type { ResponseLike } from '../shared.js';\n\nexport type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;\n\nexport async function makeRequest(url: string, init: RequestInit): Promise<ResponseLike> {\n\t// The cast is necessary because `headers` and `method` are narrower types in `undici.request`\n\t// our request path guarantees they are of acceptable type for `undici.request`\n\tconst options = {\n\t\t...init,\n\t\tbody: await resolveBody(init.body),\n\t} as RequestOptions;\n\tconst res = await request(url, options);\n\treturn {\n\t\tbody: res.body,\n\t\tasync arrayBuffer() {\n\t\t\treturn res.body.arrayBuffer();\n\t\t},\n\t\tasync json() {\n\t\t\treturn res.body.json();\n\t\t},\n\t\tasync text() {\n\t\t\treturn res.body.text();\n\t\t},\n\t\tget bodyUsed() {\n\t\t\treturn res.body.bodyUsed;\n\t\t},\n\t\theaders: new Headers(res.headers as Record<string, string[] | string>),\n\t\tstatus: res.statusCode,\n\t\tstatusText: STATUS_CODES[res.statusCode]!,\n\t\tok: res.statusCode >= 200 && res.statusCode < 300,\n\t};\n}\n\nexport async function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>> {\n\t// eslint-disable-next-line no-eq-null, eqeqeq\n\tif (body == null) {\n\t\treturn null;\n\t} else if (typeof body === 'string') {\n\t\treturn body;\n\t} else if (types.isUint8Array(body)) {\n\t\treturn body;\n\t} else if (types.isArrayBuffer(body)) {\n\t\treturn new Uint8Array(body);\n\t} else if (body instanceof URLSearchParams) {\n\t\treturn body.toString();\n\t} else if (body instanceof DataView) {\n\t\treturn new Uint8Array(body.buffer);\n\t} else if (body instanceof Blob) {\n\t\treturn new Uint8Array(await body.arrayBuffer());\n\t} else if (body instanceof FormData) {\n\t\treturn body;\n\t} else if ((body as Iterable<Uint8Array>)[Symbol.iterator]) {\n\t\tconst chunks = [...(body as Iterable<Uint8Array>)];\n\n\t\treturn Buffer.concat(chunks);\n\t} else if ((body as AsyncIterable<Uint8Array>)[Symbol.asyncIterator]) {\n\t\tconst chunks: Uint8Array[] = [];\n\n\t\tfor await (const chunk of body as AsyncIterable<Uint8Array>) {\n\t\t\tchunks.push(chunk);\n\t\t}\n\n\t\treturn Buffer.concat(chunks);\n\t}\n\n\tthrow new TypeError(`Unable to resolve body.`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA6B;AAC7B,sBAAgC;AAChC,uBAAsB;AACtB,oBAAmD;AAKnD,eAAsB,YAAY,KAAa,MAA0C;AAGxF,QAAM,UAAU;AAAA,IACf,GAAG;AAAA,IACH,MAAM,MAAM,YAAY,KAAK,IAAI;AAAA,EAClC;AACA,QAAM,MAAM,UAAM,uBAAQ,KAAK,OAAO;AACtC,SAAO;AAAA,IACN,MAAM,IAAI;AAAA,IACV,MAAM,cAAc;AACnB,aAAO,IAAI,KAAK,YAAY;AAAA,IAC7B;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,MAAM,OAAO;AACZ,aAAO,IAAI,KAAK,KAAK;AAAA,IACtB;AAAA,IACA,IAAI,WAAW;AACd,aAAO,IAAI,KAAK;AAAA,IACjB;AAAA,IACA,SAAS,IAAI,sBAAQ,IAAI,OAA4C;AAAA,IACrE,QAAQ,IAAI;AAAA,IACZ,YAAY,8BAAa,IAAI,UAAU;AAAA,IACvC,IAAI,IAAI,cAAc,OAAO,IAAI,aAAa;AAAA,EAC/C;AACD;AA3BsB;AA6BtB,eAAsB,YAAY,MAAgF;AAEjH,MAAI,QAAQ,MAAM;AACjB,WAAO;AAAA,EACR,WAAW,OAAO,SAAS,UAAU;AACpC,WAAO;AAAA,EACR,WAAW,uBAAM,aAAa,IAAI,GAAG;AACpC,WAAO;AAAA,EACR,WAAW,uBAAM,cAAc,IAAI,GAAG;AACrC,WAAO,IAAI,WAAW,IAAI;AAAA,EAC3B,WAAW,gBAAgB,iCAAiB;AAC3C,WAAO,KAAK,SAAS;AAAA,EACtB,WAAW,gBAAgB,UAAU;AACpC,WAAO,IAAI,WAAW,KAAK,MAAM;AAAA,EAClC,WAAW,gBAAgB,MAAM;AAChC,WAAO,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC;AAAA,EAC/C,WAAW,gBAAgB,UAAU;AACpC,WAAO;AAAA,EACR,WAAY,KAA8B,OAAO,QAAQ,GAAG;AAC3D,UAAM,SAAS,CAAC,GAAI,IAA6B;AAEjD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B,WAAY,KAAmC,OAAO,aAAa,GAAG;AACrE,UAAM,SAAuB,CAAC;AAE9B,qBAAiB,SAAS,MAAmC;AAC5D,aAAO,KAAK,KAAK;AAAA,IAClB;AAEA,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAEA,QAAM,IAAI,UAAU,yBAAyB;AAC9C;AAjCsB;","names":[]}
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs new file mode 100644 index 0000000..0e6ce0a --- /dev/null +++ b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs @@ -0,0 +1,70 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); + +// src/strategies/undiciRequest.ts +import { STATUS_CODES } from "node:http"; +import { URLSearchParams } from "node:url"; +import { types } from "node:util"; +import { request, Headers } from "undici"; +async function makeRequest(url, init) { + const options = { + ...init, + body: await resolveBody(init.body) + }; + const res = await request(url, options); + return { + body: res.body, + async arrayBuffer() { + return res.body.arrayBuffer(); + }, + async json() { + return res.body.json(); + }, + async text() { + return res.body.text(); + }, + get bodyUsed() { + return res.body.bodyUsed; + }, + headers: new Headers(res.headers), + status: res.statusCode, + statusText: STATUS_CODES[res.statusCode], + ok: res.statusCode >= 200 && res.statusCode < 300 + }; +} +__name(makeRequest, "makeRequest"); +async function resolveBody(body) { + if (body == null) { + return null; + } else if (typeof body === "string") { + return body; + } else if (types.isUint8Array(body)) { + return body; + } else if (types.isArrayBuffer(body)) { + return new Uint8Array(body); + } else if (body instanceof URLSearchParams) { + return body.toString(); + } else if (body instanceof DataView) { + return new Uint8Array(body.buffer); + } else if (body instanceof Blob) { + return new Uint8Array(await body.arrayBuffer()); + } else if (body instanceof FormData) { + return body; + } else if (body[Symbol.iterator]) { + const chunks = [...body]; + return Buffer.concat(chunks); + } else if (body[Symbol.asyncIterator]) { + const chunks = []; + for await (const chunk of body) { + chunks.push(chunk); + } + return Buffer.concat(chunks); + } + throw new TypeError(`Unable to resolve body.`); +} +__name(resolveBody, "resolveBody"); +export { + makeRequest, + resolveBody +}; +//# sourceMappingURL=undiciRequest.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs.map b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs.map new file mode 100644 index 0000000..e238a9c --- /dev/null +++ b/node_modules/@discordjs/rest/dist/strategies/undiciRequest.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/strategies/undiciRequest.ts"],"sourcesContent":["import { STATUS_CODES } from 'node:http';\nimport { URLSearchParams } from 'node:url';\nimport { types } from 'node:util';\nimport { type RequestInit, request, Headers } from 'undici';\nimport type { ResponseLike } from '../shared.js';\n\nexport type RequestOptions = Exclude<Parameters<typeof request>[1], undefined>;\n\nexport async function makeRequest(url: string, init: RequestInit): Promise<ResponseLike> {\n\t// The cast is necessary because `headers` and `method` are narrower types in `undici.request`\n\t// our request path guarantees they are of acceptable type for `undici.request`\n\tconst options = {\n\t\t...init,\n\t\tbody: await resolveBody(init.body),\n\t} as RequestOptions;\n\tconst res = await request(url, options);\n\treturn {\n\t\tbody: res.body,\n\t\tasync arrayBuffer() {\n\t\t\treturn res.body.arrayBuffer();\n\t\t},\n\t\tasync json() {\n\t\t\treturn res.body.json();\n\t\t},\n\t\tasync text() {\n\t\t\treturn res.body.text();\n\t\t},\n\t\tget bodyUsed() {\n\t\t\treturn res.body.bodyUsed;\n\t\t},\n\t\theaders: new Headers(res.headers as Record<string, string[] | string>),\n\t\tstatus: res.statusCode,\n\t\tstatusText: STATUS_CODES[res.statusCode]!,\n\t\tok: res.statusCode >= 200 && res.statusCode < 300,\n\t};\n}\n\nexport async function resolveBody(body: RequestInit['body']): Promise<Exclude<RequestOptions['body'], undefined>> {\n\t// eslint-disable-next-line no-eq-null, eqeqeq\n\tif (body == null) {\n\t\treturn null;\n\t} else if (typeof body === 'string') {\n\t\treturn body;\n\t} else if (types.isUint8Array(body)) {\n\t\treturn body;\n\t} else if (types.isArrayBuffer(body)) {\n\t\treturn new Uint8Array(body);\n\t} else if (body instanceof URLSearchParams) {\n\t\treturn body.toString();\n\t} else if (body instanceof DataView) {\n\t\treturn new Uint8Array(body.buffer);\n\t} else if (body instanceof Blob) {\n\t\treturn new Uint8Array(await body.arrayBuffer());\n\t} else if (body instanceof FormData) {\n\t\treturn body;\n\t} else if ((body as Iterable<Uint8Array>)[Symbol.iterator]) {\n\t\tconst chunks = [...(body as Iterable<Uint8Array>)];\n\n\t\treturn Buffer.concat(chunks);\n\t} else if ((body as AsyncIterable<Uint8Array>)[Symbol.asyncIterator]) {\n\t\tconst chunks: Uint8Array[] = [];\n\n\t\tfor await (const chunk of body as AsyncIterable<Uint8Array>) {\n\t\t\tchunks.push(chunk);\n\t\t}\n\n\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,YAAY,CAAC;AAAA,EAC/C,WAAW,gBAAgB,UAAU;AACpC,WAAO;AAAA,EACR,WAAY,KAA8B,OAAO,QAAQ,GAAG;AAC3D,UAAM,SAAS,CAAC,GAAI,IAA6B;AAEjD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B,WAAY,KAAmC,OAAO,aAAa,GAAG;AACrE,UAAM,SAAuB,CAAC;AAE9B,qBAAiB,SAAS,MAAmC;AAC5D,aAAO,KAAK,KAAK;AAAA,IAClB;AAEA,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAEA,QAAM,IAAI,UAAU,yBAAyB;AAC9C;AAjCsB;","names":[]}
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/types-65527f29.d.ts b/node_modules/@discordjs/rest/dist/types-65527f29.d.ts new file mode 100644 index 0000000..16c9e8b --- /dev/null +++ b/node_modules/@discordjs/rest/dist/types-65527f29.d.ts @@ -0,0 +1,363 @@ +import { Readable } from 'node:stream'; +import { ReadableStream } from 'node:stream/web'; +import { Collection } from '@discordjs/collection'; +import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici'; + +interface IHandler { + /** + * The unique id of the handler + */ + readonly id: string; + /** + * If the bucket is currently inactive (no pending requests) + */ + get inactive(): boolean; + /** + * Queues a request to be sent + * + * @param routeId - The generalized api route with literal ids for major parameters + * @param url - The url to do the request on + * @param options - All the information needed to make a request + * @param requestData - Extra data from the user's request needed for errors and additional processing + */ + queueRequest(routeId: RouteData, url: string, options: RequestInit, requestData: HandlerRequestData): Promise<ResponseLike>; +} + +interface RestEvents { + handlerSweep: [sweptHandlers: Collection<string, IHandler>]; + hashSweep: [sweptHashes: Collection<string, HashData>]; + invalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData]; + rateLimited: [rateLimitInfo: RateLimitData]; + response: [request: APIRequest, response: ResponseLike]; + restDebug: [info: string]; +} +type RestEventsMap = { + [K in keyof RestEvents]: RestEvents[K]; +}; +/** + * Options to be passed when creating the REST instance + */ +interface RESTOptions { + /** + * The agent to set globally + */ + agent: Dispatcher | null; + /** + * The base api path, without version + * + * @defaultValue `'https://discord.com/api'` + */ + api: string; + /** + * The authorization prefix to use for requests, useful if you want to use + * bearer tokens + * + * @defaultValue `'Bot'` + */ + authPrefix: 'Bearer' | 'Bot'; + /** + * The cdn path + * + * @defaultValue `'https://cdn.discordapp.com'` + */ + cdn: string; + /** + * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord) + * + * @defaultValue `50` + */ + globalRequestsPerSecond: number; + /** + * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h) + * + * @defaultValue `3_600_000` + */ + handlerSweepInterval: number; + /** + * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h) + * + * @defaultValue `86_400_000` + */ + hashLifetime: number; + /** + * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h) + * + * @defaultValue `14_400_000` + */ + hashSweepInterval: number; + /** + * Additional headers to send for all API requests + * + * @defaultValue `{}` + */ + headers: Record<string, string>; + /** + * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings). + * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on. + * + * @defaultValue `0` + */ + invalidRequestWarningInterval: number; + /** + * The method called to perform the actual HTTP request given a url and web `fetch` options + * For example, to use global fetch, simply provide `makeRequest: fetch` + */ + makeRequest(url: string, init: RequestInit): Promise<ResponseLike>; + /** + * The extra offset to add to rate limits in milliseconds + * + * @defaultValue `50` + */ + offset: number; + /** + * Determines how rate limiting and pre-emptive throttling should be handled. + * When an array of strings, each element is treated as a prefix for the request route + * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`) + * for which to throw {@link RateLimitError}s. All other request routes will be queued normally + * + * @defaultValue `null` + */ + rejectOnRateLimit: RateLimitQueueFilter | string[] | null; + /** + * The number of retries for errors with the 500 code, or errors + * that timeout + * + * @defaultValue `3` + */ + retries: number; + /** + * The time to wait in milliseconds before a request is aborted + * + * @defaultValue `15_000` + */ + timeout: number; + /** + * Extra information to add to the user agent + * + * @defaultValue DefaultUserAgentAppendix + */ + userAgentAppendix: string; + /** + * The version of the API to use + * + * @defaultValue `'10'` + */ + version: string; +} +/** + * Data emitted on `RESTEvents.RateLimited` + */ +interface RateLimitData { + /** + * Whether the rate limit that was reached was the global limit + */ + global: boolean; + /** + * The bucket hash for this request + */ + hash: string; + /** + * The amount of requests we can perform before locking requests + */ + limit: number; + /** + * The major parameter of the route + * + * For example, in `/channels/x`, this will be `x`. + * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`. + */ + majorParameter: string; + /** + * The HTTP method being performed + */ + method: string; + /** + * The route being hit in this request + */ + route: string; + /** + * The time, in milliseconds, until the request-lock is reset + */ + timeToReset: number; + /** + * The full URL for this request + */ + url: string; +} +/** + * A function that determines whether the rate limit hit should throw an Error + */ +type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Promise<boolean> | boolean; +interface APIRequest { + /** + * The data that was used to form the body of this request + */ + data: HandlerRequestData; + /** + * The HTTP method used in this request + */ + method: string; + /** + * Additional HTTP options for this request + */ + options: RequestInit; + /** + * The full path used to make the request + */ + path: RouteLike; + /** + * The number of times this request has been attempted + */ + retries: number; + /** + * The API route identifying the ratelimit for this request + */ + route: string; +} +interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> { + body: Readable | ReadableStream | null; +} +interface InvalidRequestWarningData { + /** + * Number of invalid requests that have been made in the window + */ + count: number; + /** + * Time in milliseconds remaining before the count resets + */ + remainingTime: number; +} +/** + * Represents a file to be added to the request + */ +interface RawFile { + /** + * Content-Type of the file + */ + contentType?: string; + /** + * The actual data for the file + */ + data: Buffer | Uint8Array | boolean | number | string; + /** + * An explicit key to use for key of the formdata field for this file. + * When not provided, the index of the file in the files array is used in the form `files[${index}]`. + * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`) + */ + key?: string; + /** + * The name of the file + */ + name: string; +} +/** + * Represents possible data to be given to an endpoint + */ +interface RequestData { + /** + * Whether to append JSON data to form data instead of `payload_json` when sending files + */ + appendToFormData?: boolean; + /** + * If this request needs the `Authorization` header + * + * @defaultValue `true` + */ + auth?: boolean; + /** + * The authorization prefix to use for this request, useful if you use this with bearer tokens + * + * @defaultValue `'Bot'` + */ + authPrefix?: 'Bearer' | 'Bot'; + /** + * The body to send to this request. + * If providing as BodyInit, set `passThroughBody: true` + */ + body?: BodyInit | unknown; + /** + * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request. + */ + dispatcher?: Agent; + /** + * Files to be attached to this request + */ + files?: RawFile[] | undefined; + /** + * Additional headers to add to this request + */ + headers?: Record<string, string>; + /** + * Whether to pass-through the body property directly to `fetch()`. + * <warn>This only applies when files is NOT present</warn> + */ + passThroughBody?: boolean; + /** + * Query string parameters to append to the called endpoint + */ + query?: URLSearchParams; + /** + * Reason to show in the audit logs + */ + reason?: string | undefined; + /** + * The signal to abort the queue entry or the REST call, where applicable + */ + signal?: AbortSignal | undefined; + /** + * If this request should be versioned + * + * @defaultValue `true` + */ + versioned?: boolean; +} +/** + * Possible headers for an API call + */ +interface RequestHeaders { + Authorization?: string; + 'User-Agent': string; + 'X-Audit-Log-Reason'?: string; +} +/** + * Possible API methods to be used when doing requests + */ +declare enum RequestMethod { + Delete = "DELETE", + Get = "GET", + Patch = "PATCH", + Post = "POST", + Put = "PUT" +} +type RouteLike = `/${string}`; +/** + * Internal request options + * + * @internal + */ +interface InternalRequest extends RequestData { + fullRoute: RouteLike; + method: RequestMethod; +} +type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>; +/** + * Parsed route data for an endpoint + * + * @internal + */ +interface RouteData { + bucketRoute: string; + majorParameter: string; + original: RouteLike; +} +/** + * Represents a hash and its associated fields + * + * @internal + */ +interface HashData { + lastAccess: number; + value: string; +} + +export { APIRequest as A, HashData as H, InternalRequest as I, ResponseLike as R, RawFile as a, RateLimitData as b, RestEventsMap as c, IHandler as d, RESTOptions as e, RouteLike as f, RequestData as g, RestEvents as h, RateLimitQueueFilter as i, InvalidRequestWarningData as j, RequestHeaders as k, RequestMethod as l, HandlerRequestData as m, RouteData as n }; diff --git a/node_modules/@discordjs/rest/dist/web.d.mts b/node_modules/@discordjs/rest/dist/web.d.mts new file mode 100644 index 0000000..4a4ce8a --- /dev/null +++ b/node_modules/@discordjs/rest/dist/web.d.mts @@ -0,0 +1,9 @@ +export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, DiscordErrorData, HTTPError, ImageExtension, ImageSize, ImageURLOptions, MakeURLOptions, OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, RateLimitError, RequestBody, StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version } from './index.mjs'; +export { A as APIRequest, m as HandlerRequestData, H as HashData, I as InternalRequest, j as InvalidRequestWarningData, e as RESTOptions, b as RateLimitData, i as RateLimitQueueFilter, a as RawFile, g as RequestData, k as RequestHeaders, l as RequestMethod, R as ResponseLike, h as RestEvents, c as RestEventsMap, n as RouteData, f as RouteLike } from './types-65527f29.js'; +import 'url'; +import 'discord-api-types/v10'; +import 'undici'; +import '@discordjs/collection'; +import '@vladfrangu/async_event_emitter'; +import 'node:stream'; +import 'node:stream/web'; diff --git a/node_modules/@discordjs/rest/dist/web.d.ts b/node_modules/@discordjs/rest/dist/web.d.ts new file mode 100644 index 0000000..98e05e9 --- /dev/null +++ b/node_modules/@discordjs/rest/dist/web.d.ts @@ -0,0 +1,9 @@ +export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, DiscordErrorData, HTTPError, ImageExtension, ImageSize, ImageURLOptions, MakeURLOptions, OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, RateLimitError, RequestBody, StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version } from './index.js'; +export { A as APIRequest, m as HandlerRequestData, H as HashData, I as InternalRequest, j as InvalidRequestWarningData, e as RESTOptions, b as RateLimitData, i as RateLimitQueueFilter, a as RawFile, g as RequestData, k as RequestHeaders, l as RequestMethod, R as ResponseLike, h as RestEvents, c as RestEventsMap, n as RouteData, f as RouteLike } from './types-65527f29.js'; +import 'url'; +import 'discord-api-types/v10'; +import 'undici'; +import '@discordjs/collection'; +import '@vladfrangu/async_event_emitter'; +import 'node:stream'; +import 'node:stream/web'; diff --git a/node_modules/@discordjs/rest/dist/web.js b/node_modules/@discordjs/rest/dist/web.js new file mode 100644 index 0000000..191975b --- /dev/null +++ b/node_modules/@discordjs/rest/dist/web.js @@ -0,0 +1,1355 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/web.ts +var web_exports = {}; +__export(web_exports, { + ALLOWED_EXTENSIONS: () => ALLOWED_EXTENSIONS, + ALLOWED_SIZES: () => ALLOWED_SIZES, + ALLOWED_STICKER_EXTENSIONS: () => ALLOWED_STICKER_EXTENSIONS, + BurstHandlerMajorIdKey: () => BurstHandlerMajorIdKey, + CDN: () => CDN, + DefaultRestOptions: () => DefaultRestOptions, + DefaultUserAgent: () => DefaultUserAgent, + DefaultUserAgentAppendix: () => DefaultUserAgentAppendix, + DiscordAPIError: () => DiscordAPIError, + HTTPError: () => HTTPError, + OverwrittenMimeTypes: () => OverwrittenMimeTypes, + REST: () => REST, + RESTEvents: () => RESTEvents, + RateLimitError: () => RateLimitError, + RequestMethod: () => RequestMethod, + calculateUserDefaultAvatarIndex: () => calculateUserDefaultAvatarIndex, + makeURLSearchParams: () => makeURLSearchParams, + parseResponse: () => parseResponse, + version: () => version +}); +module.exports = __toCommonJS(web_exports); + +// src/environment.ts +var defaultStrategy; +function setDefaultStrategy(newStrategy) { + defaultStrategy = newStrategy; +} +__name(setDefaultStrategy, "setDefaultStrategy"); +function getDefaultStrategy() { + return defaultStrategy; +} +__name(getDefaultStrategy, "getDefaultStrategy"); + +// src/lib/utils/constants.ts +var import_util = require("@discordjs/util"); +var import_v10 = require("discord-api-types/v10"); +var DefaultUserAgent = `DiscordBot (https://discord.js.org, 2.0.1)`; +var DefaultUserAgentAppendix = (0, import_util.getUserAgentAppendix)(); +var DefaultRestOptions = { + agent: null, + api: "https://discord.com/api", + authPrefix: "Bot", + cdn: "https://cdn.discordapp.com", + headers: {}, + invalidRequestWarningInterval: 0, + globalRequestsPerSecond: 50, + offset: 50, + rejectOnRateLimit: null, + retries: 3, + timeout: 15e3, + userAgentAppendix: DefaultUserAgentAppendix, + version: import_v10.APIVersion, + hashSweepInterval: 144e5, + // 4 Hours + hashLifetime: 864e5, + // 24 Hours + handlerSweepInterval: 36e5, + // 1 Hour + async makeRequest(...args) { + return getDefaultStrategy()(...args); + } +}; +var RESTEvents = /* @__PURE__ */ ((RESTEvents2) => { + RESTEvents2["Debug"] = "restDebug"; + RESTEvents2["HandlerSweep"] = "handlerSweep"; + RESTEvents2["HashSweep"] = "hashSweep"; + RESTEvents2["InvalidRequestWarning"] = "invalidRequestWarning"; + RESTEvents2["RateLimited"] = "rateLimited"; + RESTEvents2["Response"] = "response"; + return RESTEvents2; +})(RESTEvents || {}); +var ALLOWED_EXTENSIONS = ["webp", "png", "jpg", "jpeg", "gif"]; +var ALLOWED_STICKER_EXTENSIONS = ["png", "json", "gif"]; +var ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]; +var OverwrittenMimeTypes = { + // https://github.com/discordjs/discord.js/issues/8557 + "image/apng": "image/png" +}; +var BurstHandlerMajorIdKey = "burst"; + +// src/lib/CDN.ts +var CDN = class { + constructor(base = DefaultRestOptions.cdn) { + this.base = base; + } + static { + __name(this, "CDN"); + } + /** + * Generates an app asset URL for a client's asset. + * + * @param clientId - The client id that has the asset + * @param assetHash - The hash provided by Discord for this asset + * @param options - Optional options for the asset + */ + appAsset(clientId, assetHash, options) { + return this.makeURL(`/app-assets/${clientId}/${assetHash}`, options); + } + /** + * Generates an app icon URL for a client's icon. + * + * @param clientId - The client id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + appIcon(clientId, iconHash, options) { + return this.makeURL(`/app-icons/${clientId}/${iconHash}`, options); + } + /** + * Generates an avatar URL, e.g. for a user or a webhook. + * + * @param id - The id that has the icon + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + avatar(id, avatarHash, options) { + return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options); + } + /** + * Generates a user avatar decoration URL. + * + * @param userId - The id of the user + * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration + * @param options - Optional options for the avatar decoration + */ + avatarDecoration(userId, userAvatarDecoration, options) { + return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options); + } + /** + * Generates a banner URL, e.g. for a user or a guild. + * + * @param id - The id that has the banner splash + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + banner(id, bannerHash, options) { + return this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options); + } + /** + * Generates an icon URL for a channel, e.g. a group DM. + * + * @param channelId - The channel id that has the icon + * @param iconHash - The hash provided by Discord for this channel + * @param options - Optional options for the icon + */ + channelIcon(channelId, iconHash, options) { + return this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options); + } + /** + * Generates a default avatar URL + * + * @param index - The default avatar index + * @remarks + * To calculate the index for a user do `(userId >> 22) % 6`, + * or `discriminator % 5` if they're using the legacy username system. + */ + defaultAvatar(index) { + return this.makeURL(`/embed/avatars/${index}`, { extension: "png" }); + } + /** + * Generates a discovery splash URL for a guild's discovery splash. + * + * @param guildId - The guild id that has the discovery splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + discoverySplash(guildId, splashHash, options) { + return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates an emoji's URL for an emoji. + * + * @param emojiId - The emoji id + * @param extension - The extension of the emoji + */ + emoji(emojiId, extension) { + return this.makeURL(`/emojis/${emojiId}`, { extension }); + } + /** + * Generates a guild member avatar URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + guildMemberAvatar(guildId, userId, avatarHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options); + } + /** + * Generates a guild member banner URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + guildMemberBanner(guildId, userId, bannerHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options); + } + /** + * Generates an icon URL, e.g. for a guild. + * + * @param id - The id that has the icon splash + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + icon(id, iconHash, options) { + return this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options); + } + /** + * Generates a URL for the icon of a role + * + * @param roleId - The id of the role that has the icon + * @param roleIconHash - The hash provided by Discord for this role icon + * @param options - Optional options for the role icon + */ + roleIcon(roleId, roleIconHash, options) { + return this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options); + } + /** + * Generates a guild invite splash URL for a guild's invite splash. + * + * @param guildId - The guild id that has the invite splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + splash(guildId, splashHash, options) { + return this.makeURL(`/splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates a sticker URL. + * + * @param stickerId - The sticker id + * @param extension - The extension of the sticker + * @privateRemarks + * Stickers cannot have a `.webp` extension, so we default to a `.png` + */ + sticker(stickerId, extension = "png") { + return this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension }); + } + /** + * Generates a sticker pack banner URL. + * + * @param bannerId - The banner id + * @param options - Optional options for the banner + */ + stickerPackBanner(bannerId, options) { + return this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options); + } + /** + * Generates a team icon URL for a team's icon. + * + * @param teamId - The team id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + teamIcon(teamId, iconHash, options) { + return this.makeURL(`/team-icons/${teamId}/${iconHash}`, options); + } + /** + * Generates a cover image for a guild scheduled event. + * + * @param scheduledEventId - The scheduled event id + * @param coverHash - The hash provided by discord for this cover image + * @param options - Optional options for the cover image + */ + guildScheduledEventCover(scheduledEventId, coverHash, options) { + return this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options); + } + /** + * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`. + * + * @param route - The base cdn route + * @param hash - The hash provided by Discord for this icon + * @param options - Optional options for the link + */ + dynamicMakeURL(route, hash, { forceStatic = false, ...options } = {}) { + return this.makeURL(route, !forceStatic && hash.startsWith("a_") ? { ...options, extension: "gif" } : options); + } + /** + * Constructs the URL for the resource + * + * @param route - The base cdn route + * @param options - The extension/size options for the link + */ + makeURL(route, { allowedExtensions = ALLOWED_EXTENSIONS, extension = "webp", size } = {}) { + extension = String(extension).toLowerCase(); + if (!allowedExtensions.includes(extension)) { + throw new RangeError(`Invalid extension provided: ${extension} +Must be one of: ${allowedExtensions.join(", ")}`); + } + if (size && !ALLOWED_SIZES.includes(size)) { + throw new RangeError(`Invalid size provided: ${size} +Must be one of: ${ALLOWED_SIZES.join(", ")}`); + } + const url = new URL(`${this.base}${route}.${extension}`); + if (size) { + url.searchParams.set("size", String(size)); + } + return url.toString(); + } +}; + +// src/lib/errors/DiscordAPIError.ts +function isErrorGroupWrapper(error) { + return Reflect.has(error, "_errors"); +} +__name(isErrorGroupWrapper, "isErrorGroupWrapper"); +function isErrorResponse(error) { + return typeof Reflect.get(error, "message") === "string"; +} +__name(isErrorResponse, "isErrorResponse"); +var DiscordAPIError = class _DiscordAPIError extends Error { + /** + * @param rawError - The error reported by Discord + * @param code - The error code reported by Discord + * @param status - The status code of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(rawError, code, status, method, url, bodyData) { + super(_DiscordAPIError.getMessage(rawError)); + this.rawError = rawError; + this.code = code; + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "DiscordAPIError"); + } + requestBody; + /** + * The name of the error + */ + get name() { + return `${_DiscordAPIError.name}[${this.code}]`; + } + static getMessage(error) { + let flattened = ""; + if ("code" in error) { + if (error.errors) { + flattened = [...this.flattenDiscordError(error.errors)].join("\n"); + } + return error.message && flattened ? `${error.message} +${flattened}` : error.message || flattened || "Unknown Error"; + } + return error.error_description ?? "No Description"; + } + static *flattenDiscordError(obj, key = "") { + if (isErrorResponse(obj)) { + return yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim(); + } + for (const [otherKey, val] of Object.entries(obj)) { + const nextKey = otherKey.startsWith("_") ? key : key ? Number.isNaN(Number(otherKey)) ? `${key}.${otherKey}` : `${key}[${otherKey}]` : otherKey; + if (typeof val === "string") { + yield val; + } else if (isErrorGroupWrapper(val)) { + for (const error of val._errors) { + yield* this.flattenDiscordError(error, nextKey); + } + } else { + yield* this.flattenDiscordError(val, nextKey); + } + } + } +}; + +// src/lib/errors/HTTPError.ts +var HTTPError = class _HTTPError extends Error { + /** + * @param status - The status code of the response + * @param statusText - The status text of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(status, statusText, method, url, bodyData) { + super(statusText); + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "HTTPError"); + } + requestBody; + name = _HTTPError.name; +}; + +// src/lib/errors/RateLimitError.ts +var RateLimitError = class _RateLimitError extends Error { + static { + __name(this, "RateLimitError"); + } + timeToReset; + limit; + method; + hash; + url; + route; + majorParameter; + global; + constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }) { + super(); + this.timeToReset = timeToReset; + this.limit = limit; + this.method = method; + this.hash = hash; + this.url = url; + this.route = route; + this.majorParameter = majorParameter; + this.global = global; + } + /** + * The name of the error + */ + get name() { + return `${_RateLimitError.name}[${this.route}]`; + } +}; + +// src/lib/REST.ts +var import_collection = require("@discordjs/collection"); +var import_snowflake = require("@sapphire/snowflake"); +var import_async_event_emitter = require("@vladfrangu/async_event_emitter"); +var import_magic_bytes = require("magic-bytes.js"); + +// src/lib/utils/types.ts +var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => { + RequestMethod2["Delete"] = "DELETE"; + RequestMethod2["Get"] = "GET"; + RequestMethod2["Patch"] = "PATCH"; + RequestMethod2["Post"] = "POST"; + RequestMethod2["Put"] = "PUT"; + return RequestMethod2; +})(RequestMethod || {}); + +// src/lib/utils/utils.ts +function serializeSearchParam(value) { + switch (typeof value) { + case "string": + return value; + case "number": + case "bigint": + case "boolean": + return value.toString(); + case "object": + if (value === null) + return null; + if (value instanceof Date) { + return Number.isNaN(value.getTime()) ? null : value.toISOString(); + } + if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) + return value.toString(); + return null; + default: + return null; + } +} +__name(serializeSearchParam, "serializeSearchParam"); +function makeURLSearchParams(options) { + const params = new URLSearchParams(); + if (!options) + return params; + for (const [key, value] of Object.entries(options)) { + const serialized = serializeSearchParam(value); + if (serialized !== null) + params.append(key, serialized); + } + return params; +} +__name(makeURLSearchParams, "makeURLSearchParams"); +async function parseResponse(res) { + if (res.headers.get("Content-Type")?.startsWith("application/json")) { + return res.json(); + } + return res.arrayBuffer(); +} +__name(parseResponse, "parseResponse"); +function hasSublimit(bucketRoute, body, method) { + if (bucketRoute === "/channels/:id") { + if (typeof body !== "object" || body === null) + return false; + if (method !== "PATCH" /* Patch */) + return false; + const castedBody = body; + return ["name", "topic"].some((key) => Reflect.has(castedBody, key)); + } + return true; +} +__name(hasSublimit, "hasSublimit"); +function shouldRetry(error) { + if (error.name === "AbortError") + return true; + return "code" in error && error.code === "ECONNRESET" || error.message.includes("ECONNRESET"); +} +__name(shouldRetry, "shouldRetry"); +async function onRateLimit(manager, rateLimitData) { + const { options } = manager; + if (!options.rejectOnRateLimit) + return; + const shouldThrow = typeof options.rejectOnRateLimit === "function" ? await options.rejectOnRateLimit(rateLimitData) : options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase())); + if (shouldThrow) { + throw new RateLimitError(rateLimitData); + } +} +__name(onRateLimit, "onRateLimit"); +function calculateUserDefaultAvatarIndex(userId) { + return Number(BigInt(userId) >> 22n) % 6; +} +__name(calculateUserDefaultAvatarIndex, "calculateUserDefaultAvatarIndex"); +async function sleep(ms) { + return new Promise((resolve) => { + setTimeout(() => resolve(), ms); + }); +} +__name(sleep, "sleep"); +function isBufferLike(value) { + return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray; +} +__name(isBufferLike, "isBufferLike"); + +// src/lib/handlers/Shared.ts +var invalidCount = 0; +var invalidCountResetTime = null; +function incrementInvalidCount(manager) { + if (!invalidCountResetTime || invalidCountResetTime < Date.now()) { + invalidCountResetTime = Date.now() + 1e3 * 60 * 10; + invalidCount = 0; + } + invalidCount++; + const emitInvalid = manager.options.invalidRequestWarningInterval > 0 && invalidCount % manager.options.invalidRequestWarningInterval === 0; + if (emitInvalid) { + manager.emit("invalidRequestWarning" /* InvalidRequestWarning */, { + count: invalidCount, + remainingTime: invalidCountResetTime - Date.now() + }); + } +} +__name(incrementInvalidCount, "incrementInvalidCount"); +async function makeNetworkRequest(manager, routeId, url, options, requestData, retries) { + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), manager.options.timeout); + if (requestData.signal) { + if (requestData.signal.aborted) + controller.abort(); + else + requestData.signal.addEventListener("abort", () => controller.abort()); + } + let res; + try { + res = await manager.options.makeRequest(url, { ...options, signal: controller.signal }); + } catch (error) { + if (!(error instanceof Error)) + throw error; + if (shouldRetry(error) && retries !== manager.options.retries) { + return null; + } + throw error; + } finally { + clearTimeout(timeout); + } + if (manager.listenerCount("response" /* Response */)) { + manager.emit( + "response" /* Response */, + { + method: options.method ?? "get", + path: routeId.original, + route: routeId.bucketRoute, + options, + data: requestData, + retries + }, + res instanceof Response ? res.clone() : { ...res } + ); + } + return res; +} +__name(makeNetworkRequest, "makeNetworkRequest"); +async function handleErrors(manager, res, method, url, requestData, retries) { + const status = res.status; + if (status >= 500 && status < 600) { + if (retries !== manager.options.retries) { + return null; + } + throw new HTTPError(status, res.statusText, method, url, requestData); + } else { + if (status >= 400 && status < 500) { + if (status === 401 && requestData.auth) { + manager.setToken(null); + } + const data = await parseResponse(res); + throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); + } + return res; + } +} +__name(handleErrors, "handleErrors"); + +// src/lib/handlers/BurstHandler.ts +var BurstHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "BurstHandler"); + } + /** + * {@inheritdoc IHandler.id} + */ + id; + /** + * {@inheritDoc IHandler.inactive} + */ + inactive = false; + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + return this.runRequest(routeId, url, options, requestData); + } + /** + * The method that actually makes the request to the API, and updates info about the bucket accordingly + * + * @param routeId - The generalized API route with literal ids for major parameters + * @param url - The fully resolved URL to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const retry = res.headers.get("Retry-After"); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (status >= 200 && status < 300) { + return res; + } else if (status === 429) { + const isGlobal = res.headers.has("X-RateLimit-Global"); + await onRateLimit(this.manager, { + timeToReset: retryAfter, + limit: Number.POSITIVE_INFINITY, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${Number.POSITIVE_INFINITY}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : None` + ].join("\n") + ); + await sleep(retryAfter); + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/handlers/SequentialHandler.ts +var import_async_queue = require("@sapphire/async-queue"); +var SequentialHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "SequentialHandler"); + } + /** + * {@inheritDoc IHandler.id} + */ + id; + /** + * The time this rate limit bucket will reset + */ + reset = -1; + /** + * The remaining requests that can be made before we are rate limited + */ + remaining = 1; + /** + * The total number of requests that can be made before we are rate limited + */ + limit = Number.POSITIVE_INFINITY; + /** + * The interface used to sequence async requests sequentially + */ + #asyncQueue = new import_async_queue.AsyncQueue(); + /** + * The interface used to sequence sublimited async requests sequentially + */ + #sublimitedQueue = null; + /** + * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed + */ + #sublimitPromise = null; + /** + * Whether the sublimit queue needs to be shifted in the finally block + */ + #shiftSublimit = false; + /** + * {@inheritDoc IHandler.inactive} + */ + get inactive() { + return this.#asyncQueue.remaining === 0 && (this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) && !this.limited; + } + /** + * If the rate limit bucket is currently limited by the global limit + */ + get globalLimited() { + return this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset; + } + /** + * If the rate limit bucket is currently limited by its limit + */ + get localLimited() { + return this.remaining <= 0 && Date.now() < this.reset; + } + /** + * If the rate limit bucket is currently limited + */ + get limited() { + return this.globalLimited || this.localLimited; + } + /** + * The time until queued requests can continue + */ + get timeToReset() { + return this.reset + this.manager.options.offset - Date.now(); + } + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * Delay all requests for the specified amount of time, handling global rate limits + * + * @param time - The amount of time to delay all requests for + */ + async globalDelayFor(time) { + await sleep(time); + this.manager.globalDelay = null; + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + let queue = this.#asyncQueue; + let queueType = 0 /* Standard */; + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + queueType = 1 /* Sublimit */; + } + await queue.wait({ signal: requestData.signal }); + if (queueType === 0 /* Standard */) { + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + const wait = queue.wait(); + this.#asyncQueue.shift(); + await wait; + } else if (this.#sublimitPromise) { + await this.#sublimitPromise.promise; + } + } + try { + return await this.runRequest(routeId, url, options, requestData); + } finally { + queue.shift(); + if (this.#shiftSublimit) { + this.#shiftSublimit = false; + this.#sublimitedQueue?.shift(); + } + if (this.#sublimitedQueue?.remaining === 0) { + this.#sublimitPromise?.resolve(); + this.#sublimitedQueue = null; + } + } + } + /** + * The method that actually makes the request to the api, and updates info about the bucket accordingly + * + * @param routeId - The generalized api route with literal ids for major parameters + * @param url - The fully resolved url to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + while (this.limited) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + let delay; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + if (!this.manager.globalDelay) { + this.manager.globalDelay = this.globalDelayFor(timeout); + } + delay = this.manager.globalDelay; + } else { + limit2 = this.limit; + timeout = this.timeToReset; + delay = sleep(timeout); + } + const rateLimitData = { + timeToReset: timeout, + limit: limit2, + method: options.method ?? "get", + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }; + this.manager.emit("rateLimited" /* RateLimited */, rateLimitData); + await onRateLimit(this.manager, rateLimitData); + if (isGlobal) { + this.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`); + } else { + this.debug(`Waiting ${timeout}ms for rate limit to pass`); + } + await delay; + } + if (!this.manager.globalReset || this.manager.globalReset < Date.now()) { + this.manager.globalReset = Date.now() + 1e3; + this.manager.globalRemaining = this.manager.options.globalRequestsPerSecond; + } + this.manager.globalRemaining--; + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const limit = res.headers.get("X-RateLimit-Limit"); + const remaining = res.headers.get("X-RateLimit-Remaining"); + const reset = res.headers.get("X-RateLimit-Reset-After"); + const hash = res.headers.get("X-RateLimit-Bucket"); + const retry = res.headers.get("Retry-After"); + this.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY; + this.remaining = remaining ? Number(remaining) : 1; + this.reset = reset ? Number(reset) * 1e3 + Date.now() + this.manager.options.offset : Date.now(); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (hash && hash !== this.hash) { + this.debug(["Received bucket hash update", ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join("\n")); + this.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() }); + } else if (hash) { + const hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`); + if (hashData) { + hashData.lastAccess = Date.now(); + } + } + let sublimitTimeout = null; + if (retryAfter > 0) { + if (res.headers.has("X-RateLimit-Global")) { + this.manager.globalRemaining = 0; + this.manager.globalReset = Date.now() + retryAfter; + } else if (!this.localLimited) { + sublimitTimeout = retryAfter; + } + } + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (res.ok) { + return res; + } else if (status === 429) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + } else { + limit2 = this.limit; + timeout = this.timeToReset; + } + await onRateLimit(this.manager, { + timeToReset: timeout, + limit: limit2, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal.toString()}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${limit2}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : "None"}` + ].join("\n") + ); + if (sublimitTimeout) { + const firstSublimit = !this.#sublimitedQueue; + if (firstSublimit) { + this.#sublimitedQueue = new import_async_queue.AsyncQueue(); + void this.#sublimitedQueue.wait(); + this.#asyncQueue.shift(); + } + this.#sublimitPromise?.resolve(); + this.#sublimitPromise = null; + await sleep(sublimitTimeout); + let resolve; + const promise = new Promise((res2) => resolve = res2); + this.#sublimitPromise = { promise, resolve }; + if (firstSublimit) { + await this.#asyncQueue.wait(); + this.#shiftSublimit = true; + } + } + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/REST.ts +var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter { + static { + __name(this, "REST"); + } + /** + * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests + * performed by this manager. + */ + agent = null; + cdn; + /** + * The number of requests remaining in the global bucket + */ + globalRemaining; + /** + * The promise used to wait out the global rate limit + */ + globalDelay = null; + /** + * The timestamp at which the global bucket resets + */ + globalReset = -1; + /** + * API bucket hashes that are cached from provided routes + */ + hashes = new import_collection.Collection(); + /** + * Request handlers created from the bucket hash and the major parameters + */ + handlers = new import_collection.Collection(); + #token = null; + hashTimer; + handlerTimer; + options; + constructor(options = {}) { + super(); + this.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn); + this.options = { ...DefaultRestOptions, ...options }; + this.options.offset = Math.max(0, this.options.offset); + this.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond); + this.agent = options.agent ?? null; + this.setupSweepers(); + } + setupSweepers() { + const validateMaxInterval = /* @__PURE__ */ __name((interval) => { + if (interval > 144e5) { + throw new Error("Cannot set an interval greater than 4 hours"); + } + }, "validateMaxInterval"); + if (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.hashSweepInterval); + this.hashTimer = setInterval(() => { + const sweptHashes = new import_collection.Collection(); + const currentDate = Date.now(); + this.hashes.sweep((val, key) => { + if (val.lastAccess === -1) + return false; + const shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime; + if (shouldSweep) { + sweptHashes.set(key, val); + this.emit("restDebug" /* Debug */, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`); + } + return shouldSweep; + }); + this.emit("hashSweep" /* HashSweep */, sweptHashes); + }, this.options.hashSweepInterval); + this.hashTimer.unref?.(); + } + if (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.handlerSweepInterval); + this.handlerTimer = setInterval(() => { + const sweptHandlers = new import_collection.Collection(); + this.handlers.sweep((val, key) => { + const { inactive } = val; + if (inactive) { + sweptHandlers.set(key, val); + this.emit("restDebug" /* Debug */, `Handler ${val.id} for ${key} swept due to being inactive`); + } + return inactive; + }); + this.emit("handlerSweep" /* HandlerSweep */, sweptHandlers); + }, this.options.handlerSweepInterval); + this.handlerTimer.unref?.(); + } + } + /** + * Runs a get request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async get(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "GET" /* Get */ }); + } + /** + * Runs a delete request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async delete(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "DELETE" /* Delete */ }); + } + /** + * Runs a post request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async post(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "POST" /* Post */ }); + } + /** + * Runs a put request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async put(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PUT" /* Put */ }); + } + /** + * Runs a patch request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async patch(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PATCH" /* Patch */ }); + } + /** + * Runs a request from the api + * + * @param options - Request options + */ + async request(options) { + const response = await this.queueRequest(options); + return parseResponse(response); + } + /** + * Sets the default agent to use for requests performed by this manager + * + * @param agent - The agent to use + */ + setAgent(agent) { + this.agent = agent; + return this; + } + /** + * Sets the authorization token that should be used for requests + * + * @param token - The authorization token to use + */ + setToken(token) { + this.#token = token; + return this; + } + /** + * Queues a request to be sent + * + * @param request - All the information needed to make a request + * @returns The response from the api request + */ + async queueRequest(request) { + const routeId = _REST.generateRouteData(request.fullRoute, request.method); + const hash = this.hashes.get(`${request.method}:${routeId.bucketRoute}`) ?? { + value: `Global(${request.method}:${routeId.bucketRoute})`, + lastAccess: -1 + }; + const handler = this.handlers.get(`${hash.value}:${routeId.majorParameter}`) ?? this.createHandler(hash.value, routeId.majorParameter); + const { url, fetchOptions } = await this.resolveRequest(request); + return handler.queueRequest(routeId, url, fetchOptions, { + body: request.body, + files: request.files, + auth: request.auth !== false, + signal: request.signal + }); + } + /** + * Creates a new rate limit handler from a hash, based on the hash and the major parameter + * + * @param hash - The hash for the route + * @param majorParameter - The major parameter for this handler + * @internal + */ + createHandler(hash, majorParameter) { + const queue = majorParameter === BurstHandlerMajorIdKey ? new BurstHandler(this, hash, majorParameter) : new SequentialHandler(this, hash, majorParameter); + this.handlers.set(queue.id, queue); + return queue; + } + /** + * Formats the request data to a usable format for fetch + * + * @param request - The request data + */ + async resolveRequest(request) { + const { options } = this; + let query = ""; + if (request.query) { + const resolvedQuery = request.query.toString(); + if (resolvedQuery !== "") { + query = `?${resolvedQuery}`; + } + } + const headers = { + ...this.options.headers, + "User-Agent": `${DefaultUserAgent} ${options.userAgentAppendix}`.trim() + }; + if (request.auth !== false) { + if (!this.#token) { + throw new Error("Expected token to be set for this request, but none was present"); + } + headers.Authorization = `${request.authPrefix ?? this.options.authPrefix} ${this.#token}`; + } + if (request.reason?.length) { + headers["X-Audit-Log-Reason"] = encodeURIComponent(request.reason); + } + const url = `${options.api}${request.versioned === false ? "" : `/v${options.version}`}${request.fullRoute}${query}`; + let finalBody; + let additionalHeaders = {}; + if (request.files?.length) { + const formData = new FormData(); + for (const [index, file] of request.files.entries()) { + const fileKey = file.key ?? `files[${index}]`; + if (isBufferLike(file.data)) { + let contentType = file.contentType; + if (!contentType) { + const [parsedType] = (0, import_magic_bytes.filetypeinfo)(file.data); + if (parsedType) { + contentType = OverwrittenMimeTypes[parsedType.mime] ?? parsedType.mime ?? "application/octet-stream"; + } + } + formData.append(fileKey, new Blob([file.data], { type: contentType }), file.name); + } else { + formData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name); + } + } + if (request.body != null) { + if (request.appendToFormData) { + for (const [key, value] of Object.entries(request.body)) { + formData.append(key, value); + } + } else { + formData.append("payload_json", JSON.stringify(request.body)); + } + } + finalBody = formData; + } else if (request.body != null) { + if (request.passThroughBody) { + finalBody = request.body; + } else { + finalBody = JSON.stringify(request.body); + additionalHeaders = { "Content-Type": "application/json" }; + } + } + const method = request.method.toUpperCase(); + const fetchOptions = { + // Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing + body: ["GET", "HEAD"].includes(method) ? null : finalBody, + headers: { ...request.headers, ...additionalHeaders, ...headers }, + method, + // Prioritize setting an agent per request, use the agent for this instance otherwise. + dispatcher: request.dispatcher ?? this.agent ?? void 0 + }; + return { url, fetchOptions }; + } + /** + * Stops the hash sweeping interval + */ + clearHashSweeper() { + clearInterval(this.hashTimer); + } + /** + * Stops the request handler sweeping interval + */ + clearHandlerSweeper() { + clearInterval(this.handlerTimer); + } + /** + * Generates route data for an endpoint:method + * + * @param endpoint - The raw endpoint to generalize + * @param method - The HTTP method this endpoint is called without + * @internal + */ + static generateRouteData(endpoint, method) { + if (endpoint.startsWith("/interactions/") && endpoint.endsWith("/callback")) { + return { + majorParameter: BurstHandlerMajorIdKey, + bucketRoute: "/interactions/:id/:token/callback", + original: endpoint + }; + } + const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{17,19})/.exec(endpoint); + const majorId = majorIdMatch?.[1] ?? "global"; + const baseRoute = endpoint.replaceAll(/\d{17,19}/g, ":id").replace(/\/reactions\/(.*)/, "/reactions/:reaction"); + let exceptions = ""; + if (method === "DELETE" /* Delete */ && baseRoute === "/channels/:id/messages/:id") { + const id = /\d{17,19}$/.exec(endpoint)[0]; + const timestamp = import_snowflake.DiscordSnowflake.timestampFrom(id); + if (Date.now() - timestamp > 1e3 * 60 * 60 * 24 * 14) { + exceptions += "/Delete Old Message"; + } + } + return { + majorParameter: majorId, + bucketRoute: baseRoute + exceptions, + original: endpoint + }; + } +}; + +// src/shared.ts +var version = "2.0.1"; + +// src/web.ts +setDefaultStrategy(fetch); +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + ALLOWED_EXTENSIONS, + ALLOWED_SIZES, + ALLOWED_STICKER_EXTENSIONS, + BurstHandlerMajorIdKey, + CDN, + DefaultRestOptions, + DefaultUserAgent, + DefaultUserAgentAppendix, + DiscordAPIError, + HTTPError, + OverwrittenMimeTypes, + REST, + RESTEvents, + RateLimitError, + RequestMethod, + calculateUserDefaultAvatarIndex, + makeURLSearchParams, + parseResponse, + version +}); +//# sourceMappingURL=web.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/web.js.map b/node_modules/@discordjs/rest/dist/web.js.map new file mode 100644 index 0000000..69abc89 --- /dev/null +++ b/node_modules/@discordjs/rest/dist/web.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/web.ts","../src/environment.ts","../src/lib/utils/constants.ts","../src/lib/CDN.ts","../src/lib/errors/DiscordAPIError.ts","../src/lib/errors/HTTPError.ts","../src/lib/errors/RateLimitError.ts","../src/lib/REST.ts","../src/lib/utils/types.ts","../src/lib/utils/utils.ts","../src/lib/handlers/Shared.ts","../src/lib/handlers/BurstHandler.ts","../src/lib/handlers/SequentialHandler.ts","../src/shared.ts"],"sourcesContent":["import { setDefaultStrategy } from './environment.js';\n\nsetDefaultStrategy(fetch);\n\nexport * from './shared.js';\n","import type { RESTOptions } from './shared.js';\n\nlet defaultStrategy: RESTOptions['makeRequest'];\n\nexport function setDefaultStrategy(newStrategy: RESTOptions['makeRequest']) {\n\tdefaultStrategy = newStrategy;\n}\n\nexport function getDefaultStrategy() {\n\treturn defaultStrategy;\n}\n","import { getUserAgentAppendix } from '@discordjs/util';\nimport { APIVersion } from 'discord-api-types/v10';\nimport { getDefaultStrategy } from '../../environment.js';\nimport type { RESTOptions, ResponseLike } from './types.js';\n\nexport const DefaultUserAgent =\n\t`DiscordBot (https://discord.js.org, 2.0.1)` as `DiscordBot (https://discord.js.org, ${string})`;\n\n/**\n * The default string to append onto the user agent.\n */\nexport const DefaultUserAgentAppendix = getUserAgentAppendix();\n\nexport const DefaultRestOptions = {\n\tagent: null,\n\tapi: 'https://discord.com/api',\n\tauthPrefix: 'Bot',\n\tcdn: 'https://cdn.discordapp.com',\n\theaders: {},\n\tinvalidRequestWarningInterval: 0,\n\tglobalRequestsPerSecond: 50,\n\toffset: 50,\n\trejectOnRateLimit: null,\n\tretries: 3,\n\ttimeout: 15_000,\n\tuserAgentAppendix: DefaultUserAgentAppendix,\n\tversion: APIVersion,\n\thashSweepInterval: 14_400_000, // 4 Hours\n\thashLifetime: 86_400_000, // 24 Hours\n\thandlerSweepInterval: 3_600_000, // 1 Hour\n\tasync makeRequest(...args): Promise<ResponseLike> {\n\t\treturn getDefaultStrategy()(...args);\n\t},\n} as const satisfies Required<RESTOptions>;\n\n/**\n * The events that the REST manager emits\n */\nexport enum RESTEvents {\n\tDebug = 'restDebug',\n\tHandlerSweep = 'handlerSweep',\n\tHashSweep = 'hashSweep',\n\tInvalidRequestWarning = 'invalidRequestWarning',\n\tRateLimited = 'rateLimited',\n\tResponse = 'response',\n}\n\nexport const ALLOWED_EXTENSIONS = ['webp', 'png', 'jpg', 'jpeg', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_STICKER_EXTENSIONS = ['png', 'json', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096] as const satisfies readonly number[];\n\nexport type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];\nexport type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];\nexport type ImageSize = (typeof ALLOWED_SIZES)[number];\n\nexport const OverwrittenMimeTypes = {\n\t// https://github.com/discordjs/discord.js/issues/8557\n\t'image/apng': 'image/png',\n} as const satisfies Readonly<Record<string, string>>;\n\nexport const BurstHandlerMajorIdKey = 'burst';\n","/* eslint-disable jsdoc/check-param-names */\nimport {\n\tALLOWED_EXTENSIONS,\n\tALLOWED_SIZES,\n\tALLOWED_STICKER_EXTENSIONS,\n\tDefaultRestOptions,\n\ttype ImageExtension,\n\ttype ImageSize,\n\ttype StickerExtension,\n} from './utils/constants.js';\n\n/**\n * The options used for image URLs\n */\nexport interface BaseImageURLOptions {\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: ImageExtension;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The options used for image URLs with animated content\n */\nexport interface ImageURLOptions extends BaseImageURLOptions {\n\t/**\n\t * Whether or not to prefer the static version of an image asset.\n\t */\n\tforceStatic?: boolean;\n}\n\n/**\n * The options to use when making a CDN URL\n */\nexport interface MakeURLOptions {\n\t/**\n\t * The allowed extensions that can be used\n\t */\n\tallowedExtensions?: readonly string[];\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: string | undefined;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The CDN link builder\n */\nexport class CDN {\n\tpublic constructor(private readonly base: string = DefaultRestOptions.cdn) {}\n\n\t/**\n\t * Generates an app asset URL for a client's asset.\n\t *\n\t * @param clientId - The client id that has the asset\n\t * @param assetHash - The hash provided by Discord for this asset\n\t * @param options - Optional options for the asset\n\t */\n\tpublic appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/${clientId}/${assetHash}`, options);\n\t}\n\n\t/**\n\t * Generates an app icon URL for a client's icon.\n\t *\n\t * @param clientId - The client id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-icons/${clientId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates an avatar URL, e.g. for a user or a webhook.\n\t *\n\t * @param id - The id that has the icon\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a user avatar decoration URL.\n\t *\n\t * @param userId - The id of the user\n\t * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration\n\t * @param options - Optional options for the avatar decoration\n\t */\n\tpublic avatarDecoration(\n\t\tuserId: string,\n\t\tuserAvatarDecoration: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);\n\t}\n\n\t/**\n\t * Generates a banner URL, e.g. for a user or a guild.\n\t *\n\t * @param id - The id that has the banner splash\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL for a channel, e.g. a group DM.\n\t *\n\t * @param channelId - The channel id that has the icon\n\t * @param iconHash - The hash provided by Discord for this channel\n\t * @param options - Optional options for the icon\n\t */\n\tpublic channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a default avatar URL\n\t *\n\t * @param index - The default avatar index\n\t * @remarks\n\t * To calculate the index for a user do `(userId >> 22) % 6`,\n\t * or `discriminator % 5` if they're using the legacy username system.\n\t */\n\tpublic defaultAvatar(index: number): string {\n\t\treturn this.makeURL(`/embed/avatars/${index}`, { extension: 'png' });\n\t}\n\n\t/**\n\t * Generates a discovery splash URL for a guild's discovery splash.\n\t *\n\t * @param guildId - The guild id that has the discovery splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates an emoji's URL for an emoji.\n\t *\n\t * @param emojiId - The emoji id\n\t * @param extension - The extension of the emoji\n\t */\n\tpublic emoji(emojiId: string, extension?: ImageExtension): string {\n\t\treturn this.makeURL(`/emojis/${emojiId}`, { extension });\n\t}\n\n\t/**\n\t * Generates a guild member avatar URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic guildMemberAvatar(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tavatarHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a guild member banner URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic guildMemberBanner(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tbannerHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL, e.g. for a guild.\n\t *\n\t * @param id - The id that has the icon splash\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options);\n\t}\n\n\t/**\n\t * Generates a URL for the icon of a role\n\t *\n\t * @param roleId - The id of the role that has the icon\n\t * @param roleIconHash - The hash provided by Discord for this role icon\n\t * @param options - Optional options for the role icon\n\t */\n\tpublic roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a guild invite splash URL for a guild's invite splash.\n\t *\n\t * @param guildId - The guild id that has the invite splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates a sticker URL.\n\t *\n\t * @param stickerId - The sticker id\n\t * @param extension - The extension of the sticker\n\t * @privateRemarks\n\t * Stickers cannot have a `.webp` extension, so we default to a `.png`\n\t */\n\tpublic sticker(stickerId: string, extension: StickerExtension = 'png'): string {\n\t\treturn this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension });\n\t}\n\n\t/**\n\t * Generates a sticker pack banner URL.\n\t *\n\t * @param bannerId - The banner id\n\t * @param options - Optional options for the banner\n\t */\n\tpublic stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options);\n\t}\n\n\t/**\n\t * Generates a team icon URL for a team's icon.\n\t *\n\t * @param teamId - The team id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/team-icons/${teamId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a cover image for a guild scheduled event.\n\t *\n\t * @param scheduledEventId - The scheduled event id\n\t * @param coverHash - The hash provided by discord for this cover image\n\t * @param options - Optional options for the cover image\n\t */\n\tpublic guildScheduledEventCover(\n\t\tscheduledEventId: string,\n\t\tcoverHash: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.\n\t *\n\t * @param route - The base cdn route\n\t * @param hash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the link\n\t */\n\tprivate dynamicMakeURL(\n\t\troute: string,\n\t\thash: string,\n\t\t{ forceStatic = false, ...options }: Readonly<ImageURLOptions> = {},\n\t): string {\n\t\treturn this.makeURL(route, !forceStatic && hash.startsWith('a_') ? { ...options, extension: 'gif' } : options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource\n\t *\n\t * @param route - The base cdn route\n\t * @param options - The extension/size options for the link\n\t */\n\tprivate makeURL(\n\t\troute: string,\n\t\t{ allowedExtensions = ALLOWED_EXTENSIONS, extension = 'webp', size }: Readonly<MakeURLOptions> = {},\n\t): string {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\textension = String(extension).toLowerCase();\n\n\t\tif (!allowedExtensions.includes(extension)) {\n\t\t\tthrow new RangeError(`Invalid extension provided: ${extension}\\nMust be one of: ${allowedExtensions.join(', ')}`);\n\t\t}\n\n\t\tif (size && !ALLOWED_SIZES.includes(size)) {\n\t\t\tthrow new RangeError(`Invalid size provided: ${size}\\nMust be one of: ${ALLOWED_SIZES.join(', ')}`);\n\t\t}\n\n\t\tconst url = new URL(`${this.base}${route}.${extension}`);\n\n\t\tif (size) {\n\t\t\turl.searchParams.set('size', String(size));\n\t\t}\n\n\t\treturn url.toString();\n\t}\n}\n","import type { InternalRequest, RawFile } from '../utils/types.js';\n\ninterface DiscordErrorFieldInformation {\n\tcode: string;\n\tmessage: string;\n}\n\ninterface DiscordErrorGroupWrapper {\n\t_errors: DiscordError[];\n}\n\ntype DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | { [k: string]: DiscordError };\n\nexport interface DiscordErrorData {\n\tcode: number;\n\terrors?: DiscordError;\n\tmessage: string;\n}\n\nexport interface OAuthErrorData {\n\terror: string;\n\terror_description?: string;\n}\n\nexport interface RequestBody {\n\tfiles: RawFile[] | undefined;\n\tjson: unknown | undefined;\n}\n\nfunction isErrorGroupWrapper(error: DiscordError): error is DiscordErrorGroupWrapper {\n\treturn Reflect.has(error as Record<string, unknown>, '_errors');\n}\n\nfunction isErrorResponse(error: DiscordError): error is DiscordErrorFieldInformation {\n\treturn typeof Reflect.get(error as Record<string, unknown>, 'message') === 'string';\n}\n\n/**\n * Represents an API error returned by Discord\n */\nexport class DiscordAPIError extends Error {\n\tpublic requestBody: RequestBody;\n\n\t/**\n\t * @param rawError - The error reported by Discord\n\t * @param code - The error code reported by Discord\n\t * @param status - The status code of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic rawError: DiscordErrorData | OAuthErrorData,\n\t\tpublic code: number | string,\n\t\tpublic status: number,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(DiscordAPIError.getMessage(rawError));\n\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${DiscordAPIError.name}[${this.code}]`;\n\t}\n\n\tprivate static getMessage(error: DiscordErrorData | OAuthErrorData) {\n\t\tlet flattened = '';\n\t\tif ('code' in error) {\n\t\t\tif (error.errors) {\n\t\t\t\tflattened = [...this.flattenDiscordError(error.errors)].join('\\n');\n\t\t\t}\n\n\t\t\treturn error.message && flattened\n\t\t\t\t? `${error.message}\\n${flattened}`\n\t\t\t\t: error.message || flattened || 'Unknown Error';\n\t\t}\n\n\t\treturn error.error_description ?? 'No Description';\n\t}\n\n\tprivate static *flattenDiscordError(obj: DiscordError, key = ''): IterableIterator<string> {\n\t\tif (isErrorResponse(obj)) {\n\t\t\treturn yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim();\n\t\t}\n\n\t\tfor (const [otherKey, val] of Object.entries(obj)) {\n\t\t\tconst nextKey = otherKey.startsWith('_')\n\t\t\t\t? key\n\t\t\t\t: key\n\t\t\t\t? Number.isNaN(Number(otherKey))\n\t\t\t\t\t? `${key}.${otherKey}`\n\t\t\t\t\t: `${key}[${otherKey}]`\n\t\t\t\t: otherKey;\n\n\t\t\tif (typeof val === 'string') {\n\t\t\t\tyield val;\n\t\t\t} else if (isErrorGroupWrapper(val)) {\n\t\t\t\tfor (const error of val._errors) {\n\t\t\t\t\tyield* this.flattenDiscordError(error, nextKey);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield* this.flattenDiscordError(val, nextKey);\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { InternalRequest } from '../utils/types.js';\nimport type { RequestBody } from './DiscordAPIError.js';\n\n/**\n * Represents a HTTP error\n */\nexport class HTTPError extends Error {\n\tpublic requestBody: RequestBody;\n\n\tpublic override name = HTTPError.name;\n\n\t/**\n\t * @param status - The status code of the response\n\t * @param statusText - The status text of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic status: number,\n\t\tstatusText: string,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(statusText);\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n}\n","import type { RateLimitData } from '../utils/types.js';\n\nexport class RateLimitError extends Error implements RateLimitData {\n\tpublic timeToReset: number;\n\n\tpublic limit: number;\n\n\tpublic method: string;\n\n\tpublic hash: string;\n\n\tpublic url: string;\n\n\tpublic route: string;\n\n\tpublic majorParameter: string;\n\n\tpublic global: boolean;\n\n\tpublic constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData) {\n\t\tsuper();\n\t\tthis.timeToReset = timeToReset;\n\t\tthis.limit = limit;\n\t\tthis.method = method;\n\t\tthis.hash = hash;\n\t\tthis.url = url;\n\t\tthis.route = route;\n\t\tthis.majorParameter = majorParameter;\n\t\tthis.global = global;\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${RateLimitError.name}[${this.route}]`;\n\t}\n}\n","import { Collection } from '@discordjs/collection';\nimport { DiscordSnowflake } from '@sapphire/snowflake';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { filetypeinfo } from 'magic-bytes.js';\nimport type { RequestInit, BodyInit, Dispatcher } from 'undici';\nimport { CDN } from './CDN.js';\nimport { BurstHandler } from './handlers/BurstHandler.js';\nimport { SequentialHandler } from './handlers/SequentialHandler.js';\nimport type { IHandler } from './interfaces/Handler.js';\nimport {\n\tBurstHandlerMajorIdKey,\n\tDefaultRestOptions,\n\tDefaultUserAgent,\n\tOverwrittenMimeTypes,\n\tRESTEvents,\n} from './utils/constants.js';\nimport { RequestMethod } from './utils/types.js';\nimport type {\n\tRESTOptions,\n\tResponseLike,\n\tRestEventsMap,\n\tHashData,\n\tInternalRequest,\n\tRouteLike,\n\tRequestHeaders,\n\tRouteData,\n\tRequestData,\n} from './utils/types.js';\nimport { isBufferLike, parseResponse } from './utils/utils.js';\n\n/**\n * Represents the class that manages handlers for endpoints\n */\nexport class REST extends AsyncEventEmitter<RestEventsMap> {\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests\n\t * performed by this manager.\n\t */\n\tpublic agent: Dispatcher | null = null;\n\n\tpublic readonly cdn: CDN;\n\n\t/**\n\t * The number of requests remaining in the global bucket\n\t */\n\tpublic globalRemaining: number;\n\n\t/**\n\t * The promise used to wait out the global rate limit\n\t */\n\tpublic globalDelay: Promise<void> | null = null;\n\n\t/**\n\t * The timestamp at which the global bucket resets\n\t */\n\tpublic globalReset = -1;\n\n\t/**\n\t * API bucket hashes that are cached from provided routes\n\t */\n\tpublic readonly hashes = new Collection<string, HashData>();\n\n\t/**\n\t * Request handlers created from the bucket hash and the major parameters\n\t */\n\tpublic readonly handlers = new Collection<string, IHandler>();\n\n\t#token: string | null = null;\n\n\tprivate hashTimer!: NodeJS.Timer | number;\n\n\tprivate handlerTimer!: NodeJS.Timer | number;\n\n\tpublic readonly options: RESTOptions;\n\n\tpublic constructor(options: Partial<RESTOptions> = {}) {\n\t\tsuper();\n\t\tthis.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn);\n\t\tthis.options = { ...DefaultRestOptions, ...options };\n\t\tthis.options.offset = Math.max(0, this.options.offset);\n\t\tthis.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond);\n\t\tthis.agent = options.agent ?? null;\n\n\t\t// Start sweepers\n\t\tthis.setupSweepers();\n\t}\n\n\tprivate setupSweepers() {\n\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\tconst validateMaxInterval = (interval: number) => {\n\t\t\tif (interval > 14_400_000) {\n\t\t\t\tthrow new Error('Cannot set an interval greater than 4 hours');\n\t\t\t}\n\t\t};\n\n\t\tif (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.hashSweepInterval);\n\t\t\tthis.hashTimer = setInterval(() => {\n\t\t\t\tconst sweptHashes = new Collection<string, HashData>();\n\t\t\t\tconst currentDate = Date.now();\n\n\t\t\t\t// Begin sweeping hash based on lifetimes\n\t\t\t\tthis.hashes.sweep((val, key) => {\n\t\t\t\t\t// `-1` indicates a global hash\n\t\t\t\t\tif (val.lastAccess === -1) return false;\n\n\t\t\t\t\t// Check if lifetime has been exceeded\n\t\t\t\t\tconst shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime;\n\n\t\t\t\t\t// Add hash to collection of swept hashes\n\t\t\t\t\tif (shouldSweep) {\n\t\t\t\t\t\t// Add to swept hashes\n\t\t\t\t\t\tsweptHashes.set(key, val);\n\n\t\t\t\t\t\t// Emit debug information\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn shouldSweep;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HashSweep, sweptHashes);\n\t\t\t}, this.options.hashSweepInterval);\n\n\t\t\tthis.hashTimer.unref?.();\n\t\t}\n\n\t\tif (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.handlerSweepInterval);\n\t\t\tthis.handlerTimer = setInterval(() => {\n\t\t\t\tconst sweptHandlers = new Collection<string, IHandler>();\n\n\t\t\t\t// Begin sweeping handlers based on activity\n\t\t\t\tthis.handlers.sweep((val, key) => {\n\t\t\t\t\tconst { inactive } = val;\n\n\t\t\t\t\t// Collect inactive handlers\n\t\t\t\t\tif (inactive) {\n\t\t\t\t\t\tsweptHandlers.set(key, val);\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Handler ${val.id} for ${key} swept due to being inactive`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn inactive;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HandlerSweep, sweptHandlers);\n\t\t\t}, this.options.handlerSweepInterval);\n\n\t\t\tthis.handlerTimer.unref?.();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a get request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async get(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Get });\n\t}\n\n\t/**\n\t * Runs a delete request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async delete(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Delete });\n\t}\n\n\t/**\n\t * Runs a post request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async post(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Post });\n\t}\n\n\t/**\n\t * Runs a put request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async put(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Put });\n\t}\n\n\t/**\n\t * Runs a patch request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async patch(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Patch });\n\t}\n\n\t/**\n\t * Runs a request from the api\n\t *\n\t * @param options - Request options\n\t */\n\tpublic async request(options: InternalRequest) {\n\t\tconst response = await this.queueRequest(options);\n\t\treturn parseResponse(response);\n\t}\n\n\t/**\n\t * Sets the default agent to use for requests performed by this manager\n\t *\n\t * @param agent - The agent to use\n\t */\n\tpublic setAgent(agent: Dispatcher) {\n\t\tthis.agent = agent;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the authorization token that should be used for requests\n\t *\n\t * @param token - The authorization token to use\n\t */\n\tpublic setToken(token: string) {\n\t\tthis.#token = token;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Queues a request to be sent\n\t *\n\t * @param request - All the information needed to make a request\n\t * @returns The response from the api request\n\t */\n\tpublic async queueRequest(request: InternalRequest): Promise<ResponseLike> {\n\t\t// Generalize the endpoint to its route data\n\t\tconst routeId = REST.generateRouteData(request.fullRoute, request.method);\n\t\t// Get the bucket hash for the generic route, or point to a global route otherwise\n\t\tconst hash = this.hashes.get(`${request.method}:${routeId.bucketRoute}`) ?? {\n\t\t\tvalue: `Global(${request.method}:${routeId.bucketRoute})`,\n\t\t\tlastAccess: -1,\n\t\t};\n\n\t\t// Get the request handler for the obtained hash, with its major parameter\n\t\tconst handler =\n\t\t\tthis.handlers.get(`${hash.value}:${routeId.majorParameter}`) ??\n\t\t\tthis.createHandler(hash.value, routeId.majorParameter);\n\n\t\t// Resolve the request into usable fetch options\n\t\tconst { url, fetchOptions } = await this.resolveRequest(request);\n\n\t\t// Queue the request\n\t\treturn handler.queueRequest(routeId, url, fetchOptions, {\n\t\t\tbody: request.body,\n\t\t\tfiles: request.files,\n\t\t\tauth: request.auth !== false,\n\t\t\tsignal: request.signal,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a new rate limit handler from a hash, based on the hash and the major parameter\n\t *\n\t * @param hash - The hash for the route\n\t * @param majorParameter - The major parameter for this handler\n\t * @internal\n\t */\n\tprivate createHandler(hash: string, majorParameter: string) {\n\t\t// Create the async request queue to handle requests\n\t\tconst queue =\n\t\t\tmajorParameter === BurstHandlerMajorIdKey\n\t\t\t\t? new BurstHandler(this, hash, majorParameter)\n\t\t\t\t: new SequentialHandler(this, hash, majorParameter);\n\t\t// Save the queue based on its id\n\t\tthis.handlers.set(queue.id, queue);\n\n\t\treturn queue;\n\t}\n\n\t/**\n\t * Formats the request data to a usable format for fetch\n\t *\n\t * @param request - The request data\n\t */\n\tprivate async resolveRequest(request: InternalRequest): Promise<{ fetchOptions: RequestInit; url: string }> {\n\t\tconst { options } = this;\n\n\t\tlet query = '';\n\n\t\t// If a query option is passed, use it\n\t\tif (request.query) {\n\t\t\tconst resolvedQuery = request.query.toString();\n\t\t\tif (resolvedQuery !== '') {\n\t\t\t\tquery = `?${resolvedQuery}`;\n\t\t\t}\n\t\t}\n\n\t\t// Create the required headers\n\t\tconst headers: RequestHeaders = {\n\t\t\t...this.options.headers,\n\t\t\t'User-Agent': `${DefaultUserAgent} ${options.userAgentAppendix}`.trim(),\n\t\t};\n\n\t\t// If this request requires authorization (allowing non-\"authorized\" requests for webhooks)\n\t\tif (request.auth !== false) {\n\t\t\t// If we haven't received a token, throw an error\n\t\t\tif (!this.#token) {\n\t\t\t\tthrow new Error('Expected token to be set for this request, but none was present');\n\t\t\t}\n\n\t\t\theaders.Authorization = `${request.authPrefix ?? this.options.authPrefix} ${this.#token}`;\n\t\t}\n\n\t\t// If a reason was set, set it's appropriate header\n\t\tif (request.reason?.length) {\n\t\t\theaders['X-Audit-Log-Reason'] = encodeURIComponent(request.reason);\n\t\t}\n\n\t\t// Format the full request URL (api base, optional version, endpoint, optional querystring)\n\t\tconst url = `${options.api}${request.versioned === false ? '' : `/v${options.version}`}${\n\t\t\trequest.fullRoute\n\t\t}${query}`;\n\n\t\tlet finalBody: RequestInit['body'];\n\t\tlet additionalHeaders: Record<string, string> = {};\n\n\t\tif (request.files?.length) {\n\t\t\tconst formData = new FormData();\n\n\t\t\t// Attach all files to the request\n\t\t\tfor (const [index, file] of request.files.entries()) {\n\t\t\t\tconst fileKey = file.key ?? `files[${index}]`;\n\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#parameters\n\t\t\t\t// FormData.append only accepts a string or Blob.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters\n\t\t\t\t// The Blob constructor accepts TypedArray/ArrayBuffer, strings, and Blobs.\n\t\t\t\tif (isBufferLike(file.data)) {\n\t\t\t\t\t// Try to infer the content type from the buffer if one isn't passed\n\t\t\t\t\tlet contentType = file.contentType;\n\n\t\t\t\t\tif (!contentType) {\n\t\t\t\t\t\tconst [parsedType] = filetypeinfo(file.data);\n\n\t\t\t\t\t\tif (parsedType) {\n\t\t\t\t\t\t\tcontentType =\n\t\t\t\t\t\t\t\tOverwrittenMimeTypes[parsedType.mime as keyof typeof OverwrittenMimeTypes] ??\n\t\t\t\t\t\t\t\tparsedType.mime ??\n\t\t\t\t\t\t\t\t'application/octet-stream';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tformData.append(fileKey, new Blob([file.data], { type: contentType }), file.name);\n\t\t\t\t} else {\n\t\t\t\t\tformData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If a JSON body was added as well, attach it to the form data, using payload_json unless otherwise specified\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t\tif (request.body != null) {\n\t\t\t\tif (request.appendToFormData) {\n\t\t\t\t\tfor (const [key, value] of Object.entries(request.body as Record<string, unknown>)) {\n\t\t\t\t\t\tformData.append(key, value);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tformData.append('payload_json', JSON.stringify(request.body));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Set the final body to the form data\n\t\t\tfinalBody = formData;\n\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t} else if (request.body != null) {\n\t\t\tif (request.passThroughBody) {\n\t\t\t\tfinalBody = request.body as BodyInit;\n\t\t\t} else {\n\t\t\t\t// Stringify the JSON data\n\t\t\t\tfinalBody = JSON.stringify(request.body);\n\t\t\t\t// Set the additional headers to specify the content-type\n\t\t\t\tadditionalHeaders = { 'Content-Type': 'application/json' };\n\t\t\t}\n\t\t}\n\n\t\tconst method = request.method.toUpperCase();\n\n\t\t// The non null assertions in the following block are due to exactOptionalPropertyTypes, they have been tested to work with undefined\n\t\tconst fetchOptions: RequestInit = {\n\t\t\t// Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing\n\t\t\tbody: ['GET', 'HEAD'].includes(method) ? null : finalBody!,\n\t\t\theaders: { ...request.headers, ...additionalHeaders, ...headers } as Record<string, string>,\n\t\t\tmethod,\n\t\t\t// Prioritize setting an agent per request, use the agent for this instance otherwise.\n\t\t\tdispatcher: request.dispatcher ?? this.agent ?? undefined!,\n\t\t};\n\n\t\treturn { url, fetchOptions };\n\t}\n\n\t/**\n\t * Stops the hash sweeping interval\n\t */\n\tpublic clearHashSweeper() {\n\t\tclearInterval(this.hashTimer);\n\t}\n\n\t/**\n\t * Stops the request handler sweeping interval\n\t */\n\tpublic clearHandlerSweeper() {\n\t\tclearInterval(this.handlerTimer);\n\t}\n\n\t/**\n\t * Generates route data for an endpoint:method\n\t *\n\t * @param endpoint - The raw endpoint to generalize\n\t * @param method - The HTTP method this endpoint is called without\n\t * @internal\n\t */\n\tprivate static generateRouteData(endpoint: RouteLike, method: RequestMethod): RouteData {\n\t\tif (endpoint.startsWith('/interactions/') && endpoint.endsWith('/callback')) {\n\t\t\treturn {\n\t\t\t\tmajorParameter: BurstHandlerMajorIdKey,\n\t\t\t\tbucketRoute: '/interactions/:id/:token/callback',\n\t\t\t\toriginal: endpoint,\n\t\t\t};\n\t\t}\n\n\t\tconst majorIdMatch = /^\\/(?:channels|guilds|webhooks)\\/(\\d{17,19})/.exec(endpoint);\n\n\t\t// Get the major id for this route - global otherwise\n\t\tconst majorId = majorIdMatch?.[1] ?? 'global';\n\n\t\tconst baseRoute = endpoint\n\t\t\t// Strip out all ids\n\t\t\t.replaceAll(/\\d{17,19}/g, ':id')\n\t\t\t// Strip out reaction as they fall under the same bucket\n\t\t\t.replace(/\\/reactions\\/(.*)/, '/reactions/:reaction');\n\n\t\tlet exceptions = '';\n\n\t\t// Hard-Code Old Message Deletion Exception (2 week+ old messages are a different bucket)\n\t\t// https://github.com/discord/discord-api-docs/issues/1295\n\t\tif (method === RequestMethod.Delete && baseRoute === '/channels/:id/messages/:id') {\n\t\t\tconst id = /\\d{17,19}$/.exec(endpoint)![0]!;\n\t\t\tconst timestamp = DiscordSnowflake.timestampFrom(id);\n\t\t\tif (Date.now() - timestamp > 1_000 * 60 * 60 * 24 * 14) {\n\t\t\t\texceptions += '/Delete Old Message';\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tmajorParameter: majorId,\n\t\t\tbucketRoute: baseRoute + exceptions,\n\t\t\toriginal: endpoint,\n\t\t};\n\t}\n}\n","import type { Readable } from 'node:stream';\nimport type { ReadableStream } from 'node:stream/web';\nimport type { Collection } from '@discordjs/collection';\nimport type { Agent, Dispatcher, RequestInit, BodyInit, Response } from 'undici';\nimport type { IHandler } from '../interfaces/Handler.js';\n\nexport interface RestEvents {\n\thandlerSweep: [sweptHandlers: Collection<string, IHandler>];\n\thashSweep: [sweptHashes: Collection<string, HashData>];\n\tinvalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];\n\trateLimited: [rateLimitInfo: RateLimitData];\n\tresponse: [request: APIRequest, response: ResponseLike];\n\trestDebug: [info: string];\n}\n\nexport type RestEventsMap = {\n\t[K in keyof RestEvents]: RestEvents[K];\n};\n\n/**\n * Options to be passed when creating the REST instance\n */\nexport interface RESTOptions {\n\t/**\n\t * The agent to set globally\n\t */\n\tagent: Dispatcher | null;\n\t/**\n\t * The base api path, without version\n\t *\n\t * @defaultValue `'https://discord.com/api'`\n\t */\n\tapi: string;\n\t/**\n\t * The authorization prefix to use for requests, useful if you want to use\n\t * bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix: 'Bearer' | 'Bot';\n\t/**\n\t * The cdn path\n\t *\n\t * @defaultValue `'https://cdn.discordapp.com'`\n\t */\n\tcdn: string;\n\t/**\n\t * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)\n\t *\n\t * @defaultValue `50`\n\t */\n\tglobalRequestsPerSecond: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)\n\t *\n\t * @defaultValue `3_600_000`\n\t */\n\thandlerSweepInterval: number;\n\t/**\n\t * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)\n\t *\n\t * @defaultValue `86_400_000`\n\t */\n\thashLifetime: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)\n\t *\n\t * @defaultValue `14_400_000`\n\t */\n\thashSweepInterval: number;\n\t/**\n\t * Additional headers to send for all API requests\n\t *\n\t * @defaultValue `{}`\n\t */\n\theaders: Record<string, string>;\n\t/**\n\t * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).\n\t * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.\n\t *\n\t * @defaultValue `0`\n\t */\n\tinvalidRequestWarningInterval: number;\n\t/**\n\t * The method called to perform the actual HTTP request given a url and web `fetch` options\n\t * For example, to use global fetch, simply provide `makeRequest: fetch`\n\t */\n\tmakeRequest(url: string, init: RequestInit): Promise<ResponseLike>;\n\t/**\n\t * The extra offset to add to rate limits in milliseconds\n\t *\n\t * @defaultValue `50`\n\t */\n\toffset: number;\n\t/**\n\t * Determines how rate limiting and pre-emptive throttling should be handled.\n\t * When an array of strings, each element is treated as a prefix for the request route\n\t * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)\n\t * for which to throw {@link RateLimitError}s. All other request routes will be queued normally\n\t *\n\t * @defaultValue `null`\n\t */\n\trejectOnRateLimit: RateLimitQueueFilter | string[] | null;\n\t/**\n\t * The number of retries for errors with the 500 code, or errors\n\t * that timeout\n\t *\n\t * @defaultValue `3`\n\t */\n\tretries: number;\n\t/**\n\t * The time to wait in milliseconds before a request is aborted\n\t *\n\t * @defaultValue `15_000`\n\t */\n\ttimeout: number;\n\t/**\n\t * Extra information to add to the user agent\n\t *\n\t * @defaultValue DefaultUserAgentAppendix\n\t */\n\tuserAgentAppendix: string;\n\t/**\n\t * The version of the API to use\n\t *\n\t * @defaultValue `'10'`\n\t */\n\tversion: string;\n}\n\n/**\n * Data emitted on `RESTEvents.RateLimited`\n */\nexport interface RateLimitData {\n\t/**\n\t * Whether the rate limit that was reached was the global limit\n\t */\n\tglobal: boolean;\n\t/**\n\t * The bucket hash for this request\n\t */\n\thash: string;\n\t/**\n\t * The amount of requests we can perform before locking requests\n\t */\n\tlimit: number;\n\t/**\n\t * The major parameter of the route\n\t *\n\t * For example, in `/channels/x`, this will be `x`.\n\t * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.\n\t */\n\tmajorParameter: string;\n\t/**\n\t * The HTTP method being performed\n\t */\n\tmethod: string;\n\t/**\n\t * The route being hit in this request\n\t */\n\troute: string;\n\t/**\n\t * The time, in milliseconds, until the request-lock is reset\n\t */\n\ttimeToReset: number;\n\t/**\n\t * The full URL for this request\n\t */\n\turl: string;\n}\n\n/**\n * A function that determines whether the rate limit hit should throw an Error\n */\nexport type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Promise<boolean> | boolean;\n\nexport interface APIRequest {\n\t/**\n\t * The data that was used to form the body of this request\n\t */\n\tdata: HandlerRequestData;\n\t/**\n\t * The HTTP method used in this request\n\t */\n\tmethod: string;\n\t/**\n\t * Additional HTTP options for this request\n\t */\n\toptions: RequestInit;\n\t/**\n\t * The full path used to make the request\n\t */\n\tpath: RouteLike;\n\t/**\n\t * The number of times this request has been attempted\n\t */\n\tretries: number;\n\t/**\n\t * The API route identifying the ratelimit for this request\n\t */\n\troute: string;\n}\n\nexport interface ResponseLike\n\textends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {\n\tbody: Readable | ReadableStream | null;\n}\n\nexport interface InvalidRequestWarningData {\n\t/**\n\t * Number of invalid requests that have been made in the window\n\t */\n\tcount: number;\n\t/**\n\t * Time in milliseconds remaining before the count resets\n\t */\n\tremainingTime: number;\n}\n\n/**\n * Represents a file to be added to the request\n */\nexport interface RawFile {\n\t/**\n\t * Content-Type of the file\n\t */\n\tcontentType?: string;\n\t/**\n\t * The actual data for the file\n\t */\n\tdata: Buffer | Uint8Array | boolean | number | string;\n\t/**\n\t * An explicit key to use for key of the formdata field for this file.\n\t * When not provided, the index of the file in the files array is used in the form `files[${index}]`.\n\t * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)\n\t */\n\tkey?: string;\n\t/**\n\t * The name of the file\n\t */\n\tname: string;\n}\n\n/**\n * Represents possible data to be given to an endpoint\n */\nexport interface RequestData {\n\t/**\n\t * Whether to append JSON data to form data instead of `payload_json` when sending files\n\t */\n\tappendToFormData?: boolean;\n\t/**\n\t * If this request needs the `Authorization` header\n\t *\n\t * @defaultValue `true`\n\t */\n\tauth?: boolean;\n\t/**\n\t * The authorization prefix to use for this request, useful if you use this with bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix?: 'Bearer' | 'Bot';\n\t/**\n\t * The body to send to this request.\n\t * If providing as BodyInit, set `passThroughBody: true`\n\t */\n\tbody?: BodyInit | unknown;\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.\n\t */\n\tdispatcher?: Agent;\n\t/**\n\t * Files to be attached to this request\n\t */\n\tfiles?: RawFile[] | undefined;\n\t/**\n\t * Additional headers to add to this request\n\t */\n\theaders?: Record<string, string>;\n\t/**\n\t * Whether to pass-through the body property directly to `fetch()`.\n\t * <warn>This only applies when files is NOT present</warn>\n\t */\n\tpassThroughBody?: boolean;\n\t/**\n\t * Query string parameters to append to the called endpoint\n\t */\n\tquery?: URLSearchParams;\n\t/**\n\t * Reason to show in the audit logs\n\t */\n\treason?: string | undefined;\n\t/**\n\t * The signal to abort the queue entry or the REST call, where applicable\n\t */\n\tsignal?: AbortSignal | undefined;\n\t/**\n\t * If this request should be versioned\n\t *\n\t * @defaultValue `true`\n\t */\n\tversioned?: boolean;\n}\n\n/**\n * Possible headers for an API call\n */\nexport interface RequestHeaders {\n\tAuthorization?: string;\n\t'User-Agent': string;\n\t'X-Audit-Log-Reason'?: string;\n}\n\n/**\n * Possible API methods to be used when doing requests\n */\nexport enum RequestMethod {\n\tDelete = 'DELETE',\n\tGet = 'GET',\n\tPatch = 'PATCH',\n\tPost = 'POST',\n\tPut = 'PUT',\n}\n\nexport type RouteLike = `/${string}`;\n\n/**\n * Internal request options\n *\n * @internal\n */\nexport interface InternalRequest extends RequestData {\n\tfullRoute: RouteLike;\n\tmethod: RequestMethod;\n}\n\nexport type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;\n\n/**\n * Parsed route data for an endpoint\n *\n * @internal\n */\nexport interface RouteData {\n\tbucketRoute: string;\n\tmajorParameter: string;\n\toriginal: RouteLike;\n}\n\n/**\n * Represents a hash and its associated fields\n *\n * @internal\n */\nexport interface HashData {\n\tlastAccess: number;\n\tvalue: string;\n}\n","import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';\nimport type { REST } from '../REST.js';\nimport { RateLimitError } from '../errors/RateLimitError.js';\nimport { RequestMethod, type RateLimitData, type ResponseLike } from './types.js';\n\nfunction serializeSearchParam(value: unknown): string | null {\n\tswitch (typeof value) {\n\t\tcase 'string':\n\t\t\treturn value;\n\t\tcase 'number':\n\t\tcase 'bigint':\n\t\tcase 'boolean':\n\t\t\treturn value.toString();\n\t\tcase 'object':\n\t\t\tif (value === null) return null;\n\t\t\tif (value instanceof Date) {\n\t\t\t\treturn Number.isNaN(value.getTime()) ? null : value.toISOString();\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) return value.toString();\n\t\t\treturn null;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n/**\n * Creates and populates an URLSearchParams instance from an object, stripping\n * out null and undefined values, while also coercing non-strings to strings.\n *\n * @param options - The options to use\n * @returns A populated URLSearchParams instance\n */\nexport function makeURLSearchParams<T extends object>(options?: Readonly<T>) {\n\tconst params = new URLSearchParams();\n\tif (!options) return params;\n\n\tfor (const [key, value] of Object.entries(options)) {\n\t\tconst serialized = serializeSearchParam(value);\n\t\tif (serialized !== null) params.append(key, serialized);\n\t}\n\n\treturn params;\n}\n\n/**\n * Converts the response to usable data\n *\n * @param res - The fetch response\n */\nexport async function parseResponse(res: ResponseLike): Promise<unknown> {\n\tif (res.headers.get('Content-Type')?.startsWith('application/json')) {\n\t\treturn res.json();\n\t}\n\n\treturn res.arrayBuffer();\n}\n\n/**\n * Check whether a request falls under a sublimit\n *\n * @param bucketRoute - The buckets route identifier\n * @param body - The options provided as JSON data\n * @param method - The HTTP method that will be used to make the request\n * @returns Whether the request falls under a sublimit\n */\nexport function hasSublimit(bucketRoute: string, body?: unknown, method?: string): boolean {\n\t// TODO: Update for new sublimits\n\t// Currently known sublimits:\n\t// Editing channel `name` or `topic`\n\tif (bucketRoute === '/channels/:id') {\n\t\tif (typeof body !== 'object' || body === null) return false;\n\t\t// This should never be a POST body, but just in case\n\t\tif (method !== RequestMethod.Patch) return false;\n\t\tconst castedBody = body as RESTPatchAPIChannelJSONBody;\n\t\treturn ['name', 'topic'].some((key) => Reflect.has(castedBody, key));\n\t}\n\n\t// If we are checking if a request has a sublimit on a route not checked above, sublimit all requests to avoid a flood of 429s\n\treturn true;\n}\n\n/**\n * Check whether an error indicates that a retry can be attempted\n *\n * @param error - The error thrown by the network request\n * @returns Whether the error indicates a retry should be attempted\n */\nexport function shouldRetry(error: Error | NodeJS.ErrnoException) {\n\t// Retry for possible timed out requests\n\tif (error.name === 'AbortError') return true;\n\t// Downlevel ECONNRESET to retry as it may be recoverable\n\treturn ('code' in error && error.code === 'ECONNRESET') || error.message.includes('ECONNRESET');\n}\n\n/**\n * Determines whether the request should be queued or whether a RateLimitError should be thrown\n *\n * @internal\n */\nexport async function onRateLimit(manager: REST, rateLimitData: RateLimitData) {\n\tconst { options } = manager;\n\tif (!options.rejectOnRateLimit) return;\n\n\tconst shouldThrow =\n\t\ttypeof options.rejectOnRateLimit === 'function'\n\t\t\t? await options.rejectOnRateLimit(rateLimitData)\n\t\t\t: options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));\n\tif (shouldThrow) {\n\t\tthrow new RateLimitError(rateLimitData);\n\t}\n}\n\n/**\n * Calculates the default avatar index for a given user id.\n *\n * @param userId - The user id to calculate the default avatar index for\n */\nexport function calculateUserDefaultAvatarIndex(userId: Snowflake) {\n\treturn Number(BigInt(userId) >> 22n) % 6;\n}\n\n/**\n * Sleeps for a given amount of time.\n *\n * @param ms - The amount of time (in milliseconds) to sleep for\n */\nexport async function sleep(ms: number): Promise<void> {\n\treturn new Promise<void>((resolve) => {\n\t\tsetTimeout(() => resolve(), ms);\n\t});\n}\n\n/**\n * Verifies that a value is a buffer-like object.\n *\n * @param value - The value to check\n */\nexport function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Uint8Array | Uint8ClampedArray {\n\treturn value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError.js';\nimport { DiscordAPIError } from '../errors/DiscordAPIError.js';\nimport { HTTPError } from '../errors/HTTPError.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { parseResponse, shouldRetry } from '../utils/utils.js';\n\n/**\n * Invalid request limiting is done on a per-IP basis, not a per-token basis.\n * The best we can do is track invalid counts process-wide (on the theory that\n * users could have multiple bots run from one process) rather than per-bot.\n * Therefore, store these at file scope here rather than in the client's\n * RESTManager object.\n */\nlet invalidCount = 0;\nlet invalidCountResetTime: number | null = null;\n\n/**\n * Increment the invalid request count and emit warning if necessary\n *\n * @internal\n */\nexport function incrementInvalidCount(manager: REST) {\n\tif (!invalidCountResetTime || invalidCountResetTime < Date.now()) {\n\t\tinvalidCountResetTime = Date.now() + 1_000 * 60 * 10;\n\t\tinvalidCount = 0;\n\t}\n\n\tinvalidCount++;\n\n\tconst emitInvalid =\n\t\tmanager.options.invalidRequestWarningInterval > 0 &&\n\t\tinvalidCount % manager.options.invalidRequestWarningInterval === 0;\n\tif (emitInvalid) {\n\t\t// Let library users know periodically about invalid requests\n\t\tmanager.emit(RESTEvents.InvalidRequestWarning, {\n\t\t\tcount: invalidCount,\n\t\t\tremainingTime: invalidCountResetTime - Date.now(),\n\t\t});\n\t}\n}\n\n/**\n * Performs the actual network request for a request handler\n *\n * @param manager - The manager that holds options and emits informational events\n * @param routeId - The generalized api route with literal ids for major parameters\n * @param url - The fully resolved url to make the request to\n * @param options - The fetch options needed to make the request\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns The respond from the network or `null` when the request should be retried\n * @internal\n */\nexport async function makeNetworkRequest(\n\tmanager: REST,\n\trouteId: RouteData,\n\turl: string,\n\toptions: RequestInit,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst controller = new AbortController();\n\tconst timeout = setTimeout(() => controller.abort(), manager.options.timeout);\n\tif (requestData.signal) {\n\t\t// If the user signal was aborted, abort the controller, else abort the local signal.\n\t\t// The reason why we don't re-use the user's signal, is because users may use the same signal for multiple\n\t\t// requests, and we do not want to cause unexpected side-effects.\n\t\tif (requestData.signal.aborted) controller.abort();\n\t\telse requestData.signal.addEventListener('abort', () => controller.abort());\n\t}\n\n\tlet res: ResponseLike;\n\ttry {\n\t\tres = await manager.options.makeRequest(url, { ...options, signal: controller.signal });\n\t} catch (error: unknown) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\t// Retry the specified number of times if needed\n\t\tif (shouldRetry(error) && retries !== manager.options.retries) {\n\t\t\t// Retry is handled by the handler upon receiving null\n\t\t\treturn null;\n\t\t}\n\n\t\tthrow error;\n\t} finally {\n\t\tclearTimeout(timeout);\n\t}\n\n\tif (manager.listenerCount(RESTEvents.Response)) {\n\t\tmanager.emit(\n\t\t\tRESTEvents.Response,\n\t\t\t{\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\tpath: routeId.original,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\toptions,\n\t\t\t\tdata: requestData,\n\t\t\t\tretries,\n\t\t\t},\n\t\t\tres instanceof Response ? res.clone() : { ...res },\n\t\t);\n\t}\n\n\treturn res;\n}\n\n/**\n * Handles 5xx and 4xx errors (not 429's) conventionally. 429's should be handled before calling this function\n *\n * @param manager - The manager that holds options and emits informational events\n * @param res - The response received from {@link makeNetworkRequest}\n * @param method - The method used to make the request\n * @param url - The fully resolved url to make the request to\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns - The response if the status code is not handled or null to request a retry\n */\nexport async function handleErrors(\n\tmanager: REST,\n\tres: ResponseLike,\n\tmethod: string,\n\turl: string,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst status = res.status;\n\tif (status >= 500 && status < 600) {\n\t\t// Retry the specified number of times for possible server side issues\n\t\tif (retries !== manager.options.retries) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We are out of retries, throw an error\n\t\tthrow new HTTPError(status, res.statusText, method, url, requestData);\n\t} else {\n\t\t// Handle possible malformed requests\n\t\tif (status >= 400 && status < 500) {\n\t\t\t// If we receive this status code, it means the token we had is no longer valid.\n\t\t\tif (status === 401 && requestData.auth) {\n\t\t\t\tmanager.setToken(null!);\n\t\t\t}\n\n\t\t\t// The request will not succeed for some reason, parse the error returned from the api\n\t\t\tconst data = (await parseResponse(res)) as DiscordErrorData | OAuthErrorData;\n\t\t\t// throw the API error\n\t\t\tthrow new DiscordAPIError(data, 'code' in data ? data.code : data.error, status, method, url, requestData);\n\t\t}\n\n\t\treturn res;\n\t}\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\n/**\n * The structure used to handle burst requests for a given bucket.\n * Burst requests have no ratelimit handling but allow for pre- and post-processing\n * of data in the same manner as sequentially queued requests.\n *\n * @remarks\n * This queue may still emit a rate limit error if an unexpected 429 is hit\n */\nexport class BurstHandler implements IHandler {\n\t/**\n\t * {@inheritdoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic inactive = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\treturn this.runRequest(routeId, url, options, requestData);\n\t}\n\n\t/**\n\t * The method that actually makes the request to the API, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized API route with literal ids for major parameters\n\t * @param url - The fully resolved URL to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (status >= 200 && status < 300) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// Unexpected ratelimit\n\t\t\tconst isGlobal = res.headers.has('X-RateLimit-Global');\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: retryAfter,\n\t\t\t\tlimit: Number.POSITIVE_INFINITY,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${Number.POSITIVE_INFINITY}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : None`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\n\t\t\t// We are bypassing all other limits, but an encountered limit should be respected (it's probably a non-punished rate limit anyways)\n\t\t\tawait sleep(retryAfter);\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","import { AsyncQueue } from '@sapphire/async-queue';\nimport type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { RateLimitData, ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { hasSublimit, onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\nconst enum QueueType {\n\tStandard,\n\tSublimit,\n}\n\n/**\n * The structure used to handle sequential requests for a given bucket\n */\nexport class SequentialHandler implements IHandler {\n\t/**\n\t * {@inheritDoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * The time this rate limit bucket will reset\n\t */\n\tprivate reset = -1;\n\n\t/**\n\t * The remaining requests that can be made before we are rate limited\n\t */\n\tprivate remaining = 1;\n\n\t/**\n\t * The total number of requests that can be made before we are rate limited\n\t */\n\tprivate limit = Number.POSITIVE_INFINITY;\n\n\t/**\n\t * The interface used to sequence async requests sequentially\n\t */\n\t#asyncQueue = new AsyncQueue();\n\n\t/**\n\t * The interface used to sequence sublimited async requests sequentially\n\t */\n\t#sublimitedQueue: AsyncQueue | null = null;\n\n\t/**\n\t * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed\n\t */\n\t#sublimitPromise: { promise: Promise<void>; resolve(): void } | null = null;\n\n\t/**\n\t * Whether the sublimit queue needs to be shifted in the finally block\n\t */\n\t#shiftSublimit = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic get inactive(): boolean {\n\t\treturn (\n\t\t\tthis.#asyncQueue.remaining === 0 &&\n\t\t\t(this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) &&\n\t\t\t!this.limited\n\t\t);\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by the global limit\n\t */\n\tprivate get globalLimited(): boolean {\n\t\treturn this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by its limit\n\t */\n\tprivate get localLimited(): boolean {\n\t\treturn this.remaining <= 0 && Date.now() < this.reset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited\n\t */\n\tprivate get limited(): boolean {\n\t\treturn this.globalLimited || this.localLimited;\n\t}\n\n\t/**\n\t * The time until queued requests can continue\n\t */\n\tprivate get timeToReset(): number {\n\t\treturn this.reset + this.manager.options.offset - Date.now();\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * Delay all requests for the specified amount of time, handling global rate limits\n\t *\n\t * @param time - The amount of time to delay all requests for\n\t */\n\tprivate async globalDelayFor(time: number): Promise<void> {\n\t\tawait sleep(time);\n\t\tthis.manager.globalDelay = null;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\tlet queue = this.#asyncQueue;\n\t\tlet queueType = QueueType.Standard;\n\t\t// Separate sublimited requests when already sublimited\n\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\tqueueType = QueueType.Sublimit;\n\t\t}\n\n\t\t// Wait for any previous requests to be completed before this one is run\n\t\tawait queue.wait({ signal: requestData.signal });\n\t\t// This set handles retroactively sublimiting requests\n\t\tif (queueType === QueueType.Standard) {\n\t\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\t\t/**\n\t\t\t\t * Remove the request from the standard queue, it should never be possible to get here while processing the\n\t\t\t\t * sublimit queue so there is no need to worry about shifting the wrong request\n\t\t\t\t */\n\t\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\t\tconst wait = queue.wait();\n\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\tawait wait;\n\t\t\t} else if (this.#sublimitPromise) {\n\t\t\t\t// Stall requests while the sublimit queue gets processed\n\t\t\t\tawait this.#sublimitPromise.promise;\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request, and return the results\n\t\t\treturn await this.runRequest(routeId, url, options, requestData);\n\t\t} finally {\n\t\t\t// Allow the next request to fire\n\t\t\tqueue.shift();\n\t\t\tif (this.#shiftSublimit) {\n\t\t\t\tthis.#shiftSublimit = false;\n\t\t\t\tthis.#sublimitedQueue?.shift();\n\t\t\t}\n\n\t\t\t// If this request is the last request in a sublimit\n\t\t\tif (this.#sublimitedQueue?.remaining === 0) {\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitedQueue = null;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The method that actually makes the request to the api, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized api route with literal ids for major parameters\n\t * @param url - The fully resolved url to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\t/*\n\t\t * After calculations have been done, pre-emptively stop further requests\n\t\t * Potentially loop until this task can run if e.g. the global rate limit is hit twice\n\t\t */\n\t\twhile (this.limited) {\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\t\t\tlet delay: Promise<void>;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t\t// If this is the first task to reach the global timeout, set the global delay\n\t\t\t\tif (!this.manager.globalDelay) {\n\t\t\t\t\t// The global delay function clears the global delay state when it is resolved\n\t\t\t\t\tthis.manager.globalDelay = this.globalDelayFor(timeout);\n\t\t\t\t}\n\n\t\t\t\tdelay = this.manager.globalDelay;\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t\tdelay = sleep(timeout);\n\t\t\t}\n\n\t\t\tconst rateLimitData: RateLimitData = {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t};\n\t\t\t// Let library users know they have hit a rate limit\n\t\t\tthis.manager.emit(RESTEvents.RateLimited, rateLimitData);\n\t\t\t// Determine whether a RateLimitError should be thrown\n\t\t\tawait onRateLimit(this.manager, rateLimitData);\n\t\t\t// When not erroring, emit debug for what is happening\n\t\t\tif (isGlobal) {\n\t\t\t\tthis.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`);\n\t\t\t} else {\n\t\t\t\tthis.debug(`Waiting ${timeout}ms for rate limit to pass`);\n\t\t\t}\n\n\t\t\t// Wait the remaining time left before the rate limit resets\n\t\t\tawait delay;\n\t\t}\n\n\t\t// As the request goes out, update the global usage information\n\t\tif (!this.manager.globalReset || this.manager.globalReset < Date.now()) {\n\t\t\tthis.manager.globalReset = Date.now() + 1_000;\n\t\t\tthis.manager.globalRemaining = this.manager.options.globalRequestsPerSecond;\n\t\t}\n\n\t\tthis.manager.globalRemaining--;\n\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\n\t\tconst limit = res.headers.get('X-RateLimit-Limit');\n\t\tconst remaining = res.headers.get('X-RateLimit-Remaining');\n\t\tconst reset = res.headers.get('X-RateLimit-Reset-After');\n\t\tconst hash = res.headers.get('X-RateLimit-Bucket');\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Update the total number of requests that can be made before the rate limit resets\n\t\tthis.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY;\n\t\t// Update the number of remaining requests that can be made before the rate limit resets\n\t\tthis.remaining = remaining ? Number(remaining) : 1;\n\t\t// Update the time when this rate limit resets (reset-after is in seconds)\n\t\tthis.reset = reset ? Number(reset) * 1_000 + Date.now() + this.manager.options.offset : Date.now();\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Handle buckets via the hash header retroactively\n\t\tif (hash && hash !== this.hash) {\n\t\t\t// Let library users know when rate limit buckets have been updated\n\t\t\tthis.debug(['Received bucket hash update', ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join('\\n'));\n\t\t\t// This queue will eventually be eliminated via attrition\n\t\t\tthis.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() });\n\t\t} else if (hash) {\n\t\t\t// Handle the case where hash value doesn't change\n\t\t\t// Fetch the hash data from the manager\n\t\t\tconst hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`);\n\n\t\t\t// When fetched, update the last access of the hash\n\t\t\tif (hashData) {\n\t\t\t\thashData.lastAccess = Date.now();\n\t\t\t}\n\t\t}\n\n\t\t// Handle retryAfter, which means we have actually hit a rate limit\n\t\tlet sublimitTimeout: number | null = null;\n\t\tif (retryAfter > 0) {\n\t\t\tif (res.headers.has('X-RateLimit-Global')) {\n\t\t\t\tthis.manager.globalRemaining = 0;\n\t\t\t\tthis.manager.globalReset = Date.now() + retryAfter;\n\t\t\t} else if (!this.localLimited) {\n\t\t\t\t/*\n\t\t\t\t * This is a sublimit (e.g. 2 channel name changes/10 minutes) since the headers don't indicate a\n\t\t\t\t * route-wide rate limit. Don't update remaining or reset to avoid rate limiting the whole\n\t\t\t\t * endpoint, just set a reset time on the request itself to avoid retrying too soon.\n\t\t\t\t */\n\t\t\t\tsublimitTimeout = retryAfter;\n\t\t\t}\n\t\t}\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (res.ok) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// A rate limit was hit - this may happen if the route isn't associated with an official bucket hash yet, or when first globally rate limited\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t}\n\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal.toString()}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${limit}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : 'None'}`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\t\t\t// If caused by a sublimit, wait it out here so other requests on the route can be handled\n\t\t\tif (sublimitTimeout) {\n\t\t\t\t// Normally the sublimit queue will not exist, however, if a sublimit is hit while in the sublimit queue, it will\n\t\t\t\tconst firstSublimit = !this.#sublimitedQueue;\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\tthis.#sublimitedQueue = new AsyncQueue();\n\t\t\t\t\tvoid this.#sublimitedQueue.wait();\n\t\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\t}\n\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitPromise = null;\n\t\t\t\tawait sleep(sublimitTimeout);\n\t\t\t\tlet resolve: () => void;\n\t\t\t\t// eslint-disable-next-line promise/param-names, no-promise-executor-return\n\t\t\t\tconst promise = new Promise<void>((res) => (resolve = res));\n\t\t\t\tthis.#sublimitPromise = { promise, resolve: resolve! };\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\t// Re-queue this request so it can be shifted by the finally\n\t\t\t\t\tawait this.#asyncQueue.wait();\n\t\t\t\t\tthis.#shiftSublimit = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","export * from './lib/CDN.js';\nexport * from './lib/errors/DiscordAPIError.js';\nexport * from './lib/errors/HTTPError.js';\nexport * from './lib/errors/RateLimitError.js';\nexport * from './lib/REST.js';\nexport * from './lib/utils/constants.js';\nexport * from './lib/utils/types.js';\nexport { calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse } from './lib/utils/utils.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\nexport const version = '2.0.1' as string;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAI;AAEG,SAAS,mBAAmB,aAAyC;AAC3E,oBAAkB;AACnB;AAFgB;AAIT,SAAS,qBAAqB;AACpC,SAAO;AACR;AAFgB;;;ACRhB,kBAAqC;AACrC,iBAA2B;AAIpB,IAAM,mBACZ;AAKM,IAAM,+BAA2B,kCAAqB;AAEtD,IAAM,qBAAqB;AAAA,EACjC,OAAO;AAAA,EACP,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,KAAK;AAAA,EACL,SAAS,CAAC;AAAA,EACV,+BAA+B;AAAA,EAC/B,yBAAyB;AAAA,EACzB,QAAQ;AAAA,EACR,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,mBAAmB;AAAA;AAAA,EACnB,cAAc;AAAA;AAAA,EACd,sBAAsB;AAAA;AAAA,EACtB,MAAM,eAAe,MAA6B;AACjD,WAAO,mBAAmB,EAAE,GAAG,IAAI;AAAA,EACpC;AACD;AAKO,IAAK,aAAL,kBAAKA,gBAAL;AACN,E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Aa;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKO,mBAAmB;AACzB,kBAAc,KAAK,SAAS;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKO,sBAAsB;AAC5B,kBAAc,KAAK,YAAY;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAe,kBAAkB,UAAqB,QAAkC;AACvF,QAAI,SAAS,WAAW,gBAAgB,KAAK,SAAS,SAAS,WAAW,GAAG;AAC5E,aAAO;AAAA,QACN,gBAAgB;AAAA,QAChB,aAAa;AAAA,QACb,UAAU;AAAA,MACX;AAAA,IACD;AAEA,UAAM,eAAe,+CAA+C,KAAK,QAAQ;AAGjF,UAAM,UAAU,eAAe,CAAC,KAAK;AAErC,UAAM,YAAY,SAEhB,WAAW,cAAc,KAAK,EAE9B,QAAQ,qBAAqB,sBAAsB;AAErD,QAAI,aAAa;AAIjB,QAAI,oCAAmC,cAAc,8BAA8B;AAClF,YAAM,KAAK,aAAa,KAAK,QAAQ,EAAG,CAAC;AACzC,YAAM,YAAY,kCAAiB,cAAc,EAAE;AACnD,UAAI,KAAK,IAAI,IAAI,YAAY,MAAQ,KAAK,KAAK,KAAK,IAAI;AACvD,sBAAc;AAAA,MACf;AAAA,IACD;AAEA,WAAO;AAAA,MACN,gBAAgB;AAAA,MAChB,aAAa,YAAY;AAAA,MACzB,UAAU;AAAA,IACX;AAAA,EACD;AACD;;;AMncO,IAAM,UAAU;;;AbZvB,mBAAmB,KAAK;","names":["RESTEvents","RequestMethod","limit","res"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/web.mjs b/node_modules/@discordjs/rest/dist/web.mjs new file mode 100644 index 0000000..8c70b4f --- /dev/null +++ b/node_modules/@discordjs/rest/dist/web.mjs @@ -0,0 +1,1312 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); + +// src/environment.ts +var defaultStrategy; +function setDefaultStrategy(newStrategy) { + defaultStrategy = newStrategy; +} +__name(setDefaultStrategy, "setDefaultStrategy"); +function getDefaultStrategy() { + return defaultStrategy; +} +__name(getDefaultStrategy, "getDefaultStrategy"); + +// src/lib/utils/constants.ts +import { getUserAgentAppendix } from "@discordjs/util"; +import { APIVersion } from "discord-api-types/v10"; +var DefaultUserAgent = `DiscordBot (https://discord.js.org, 2.0.1)`; +var DefaultUserAgentAppendix = getUserAgentAppendix(); +var DefaultRestOptions = { + agent: null, + api: "https://discord.com/api", + authPrefix: "Bot", + cdn: "https://cdn.discordapp.com", + headers: {}, + invalidRequestWarningInterval: 0, + globalRequestsPerSecond: 50, + offset: 50, + rejectOnRateLimit: null, + retries: 3, + timeout: 15e3, + userAgentAppendix: DefaultUserAgentAppendix, + version: APIVersion, + hashSweepInterval: 144e5, + // 4 Hours + hashLifetime: 864e5, + // 24 Hours + handlerSweepInterval: 36e5, + // 1 Hour + async makeRequest(...args) { + return getDefaultStrategy()(...args); + } +}; +var RESTEvents = /* @__PURE__ */ ((RESTEvents2) => { + RESTEvents2["Debug"] = "restDebug"; + RESTEvents2["HandlerSweep"] = "handlerSweep"; + RESTEvents2["HashSweep"] = "hashSweep"; + RESTEvents2["InvalidRequestWarning"] = "invalidRequestWarning"; + RESTEvents2["RateLimited"] = "rateLimited"; + RESTEvents2["Response"] = "response"; + return RESTEvents2; +})(RESTEvents || {}); +var ALLOWED_EXTENSIONS = ["webp", "png", "jpg", "jpeg", "gif"]; +var ALLOWED_STICKER_EXTENSIONS = ["png", "json", "gif"]; +var ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]; +var OverwrittenMimeTypes = { + // https://github.com/discordjs/discord.js/issues/8557 + "image/apng": "image/png" +}; +var BurstHandlerMajorIdKey = "burst"; + +// src/lib/CDN.ts +var CDN = class { + constructor(base = DefaultRestOptions.cdn) { + this.base = base; + } + static { + __name(this, "CDN"); + } + /** + * Generates an app asset URL for a client's asset. + * + * @param clientId - The client id that has the asset + * @param assetHash - The hash provided by Discord for this asset + * @param options - Optional options for the asset + */ + appAsset(clientId, assetHash, options) { + return this.makeURL(`/app-assets/${clientId}/${assetHash}`, options); + } + /** + * Generates an app icon URL for a client's icon. + * + * @param clientId - The client id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + appIcon(clientId, iconHash, options) { + return this.makeURL(`/app-icons/${clientId}/${iconHash}`, options); + } + /** + * Generates an avatar URL, e.g. for a user or a webhook. + * + * @param id - The id that has the icon + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + avatar(id, avatarHash, options) { + return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options); + } + /** + * Generates a user avatar decoration URL. + * + * @param userId - The id of the user + * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration + * @param options - Optional options for the avatar decoration + */ + avatarDecoration(userId, userAvatarDecoration, options) { + return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options); + } + /** + * Generates a banner URL, e.g. for a user or a guild. + * + * @param id - The id that has the banner splash + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + banner(id, bannerHash, options) { + return this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options); + } + /** + * Generates an icon URL for a channel, e.g. a group DM. + * + * @param channelId - The channel id that has the icon + * @param iconHash - The hash provided by Discord for this channel + * @param options - Optional options for the icon + */ + channelIcon(channelId, iconHash, options) { + return this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options); + } + /** + * Generates a default avatar URL + * + * @param index - The default avatar index + * @remarks + * To calculate the index for a user do `(userId >> 22) % 6`, + * or `discriminator % 5` if they're using the legacy username system. + */ + defaultAvatar(index) { + return this.makeURL(`/embed/avatars/${index}`, { extension: "png" }); + } + /** + * Generates a discovery splash URL for a guild's discovery splash. + * + * @param guildId - The guild id that has the discovery splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + discoverySplash(guildId, splashHash, options) { + return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates an emoji's URL for an emoji. + * + * @param emojiId - The emoji id + * @param extension - The extension of the emoji + */ + emoji(emojiId, extension) { + return this.makeURL(`/emojis/${emojiId}`, { extension }); + } + /** + * Generates a guild member avatar URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param avatarHash - The hash provided by Discord for this avatar + * @param options - Optional options for the avatar + */ + guildMemberAvatar(guildId, userId, avatarHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options); + } + /** + * Generates a guild member banner URL. + * + * @param guildId - The id of the guild + * @param userId - The id of the user + * @param bannerHash - The hash provided by Discord for this banner + * @param options - Optional options for the banner + */ + guildMemberBanner(guildId, userId, bannerHash, options) { + return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options); + } + /** + * Generates an icon URL, e.g. for a guild. + * + * @param id - The id that has the icon splash + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + icon(id, iconHash, options) { + return this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options); + } + /** + * Generates a URL for the icon of a role + * + * @param roleId - The id of the role that has the icon + * @param roleIconHash - The hash provided by Discord for this role icon + * @param options - Optional options for the role icon + */ + roleIcon(roleId, roleIconHash, options) { + return this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options); + } + /** + * Generates a guild invite splash URL for a guild's invite splash. + * + * @param guildId - The guild id that has the invite splash + * @param splashHash - The hash provided by Discord for this splash + * @param options - Optional options for the splash + */ + splash(guildId, splashHash, options) { + return this.makeURL(`/splashes/${guildId}/${splashHash}`, options); + } + /** + * Generates a sticker URL. + * + * @param stickerId - The sticker id + * @param extension - The extension of the sticker + * @privateRemarks + * Stickers cannot have a `.webp` extension, so we default to a `.png` + */ + sticker(stickerId, extension = "png") { + return this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension }); + } + /** + * Generates a sticker pack banner URL. + * + * @param bannerId - The banner id + * @param options - Optional options for the banner + */ + stickerPackBanner(bannerId, options) { + return this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options); + } + /** + * Generates a team icon URL for a team's icon. + * + * @param teamId - The team id that has the icon + * @param iconHash - The hash provided by Discord for this icon + * @param options - Optional options for the icon + */ + teamIcon(teamId, iconHash, options) { + return this.makeURL(`/team-icons/${teamId}/${iconHash}`, options); + } + /** + * Generates a cover image for a guild scheduled event. + * + * @param scheduledEventId - The scheduled event id + * @param coverHash - The hash provided by discord for this cover image + * @param options - Optional options for the cover image + */ + guildScheduledEventCover(scheduledEventId, coverHash, options) { + return this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options); + } + /** + * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`. + * + * @param route - The base cdn route + * @param hash - The hash provided by Discord for this icon + * @param options - Optional options for the link + */ + dynamicMakeURL(route, hash, { forceStatic = false, ...options } = {}) { + return this.makeURL(route, !forceStatic && hash.startsWith("a_") ? { ...options, extension: "gif" } : options); + } + /** + * Constructs the URL for the resource + * + * @param route - The base cdn route + * @param options - The extension/size options for the link + */ + makeURL(route, { allowedExtensions = ALLOWED_EXTENSIONS, extension = "webp", size } = {}) { + extension = String(extension).toLowerCase(); + if (!allowedExtensions.includes(extension)) { + throw new RangeError(`Invalid extension provided: ${extension} +Must be one of: ${allowedExtensions.join(", ")}`); + } + if (size && !ALLOWED_SIZES.includes(size)) { + throw new RangeError(`Invalid size provided: ${size} +Must be one of: ${ALLOWED_SIZES.join(", ")}`); + } + const url = new URL(`${this.base}${route}.${extension}`); + if (size) { + url.searchParams.set("size", String(size)); + } + return url.toString(); + } +}; + +// src/lib/errors/DiscordAPIError.ts +function isErrorGroupWrapper(error) { + return Reflect.has(error, "_errors"); +} +__name(isErrorGroupWrapper, "isErrorGroupWrapper"); +function isErrorResponse(error) { + return typeof Reflect.get(error, "message") === "string"; +} +__name(isErrorResponse, "isErrorResponse"); +var DiscordAPIError = class _DiscordAPIError extends Error { + /** + * @param rawError - The error reported by Discord + * @param code - The error code reported by Discord + * @param status - The status code of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(rawError, code, status, method, url, bodyData) { + super(_DiscordAPIError.getMessage(rawError)); + this.rawError = rawError; + this.code = code; + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "DiscordAPIError"); + } + requestBody; + /** + * The name of the error + */ + get name() { + return `${_DiscordAPIError.name}[${this.code}]`; + } + static getMessage(error) { + let flattened = ""; + if ("code" in error) { + if (error.errors) { + flattened = [...this.flattenDiscordError(error.errors)].join("\n"); + } + return error.message && flattened ? `${error.message} +${flattened}` : error.message || flattened || "Unknown Error"; + } + return error.error_description ?? "No Description"; + } + static *flattenDiscordError(obj, key = "") { + if (isErrorResponse(obj)) { + return yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim(); + } + for (const [otherKey, val] of Object.entries(obj)) { + const nextKey = otherKey.startsWith("_") ? key : key ? Number.isNaN(Number(otherKey)) ? `${key}.${otherKey}` : `${key}[${otherKey}]` : otherKey; + if (typeof val === "string") { + yield val; + } else if (isErrorGroupWrapper(val)) { + for (const error of val._errors) { + yield* this.flattenDiscordError(error, nextKey); + } + } else { + yield* this.flattenDiscordError(val, nextKey); + } + } + } +}; + +// src/lib/errors/HTTPError.ts +var HTTPError = class _HTTPError extends Error { + /** + * @param status - The status code of the response + * @param statusText - The status text of the response + * @param method - The method of the request that erred + * @param url - The url of the request that erred + * @param bodyData - The unparsed data for the request that errored + */ + constructor(status, statusText, method, url, bodyData) { + super(statusText); + this.status = status; + this.method = method; + this.url = url; + this.requestBody = { files: bodyData.files, json: bodyData.body }; + } + static { + __name(this, "HTTPError"); + } + requestBody; + name = _HTTPError.name; +}; + +// src/lib/errors/RateLimitError.ts +var RateLimitError = class _RateLimitError extends Error { + static { + __name(this, "RateLimitError"); + } + timeToReset; + limit; + method; + hash; + url; + route; + majorParameter; + global; + constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }) { + super(); + this.timeToReset = timeToReset; + this.limit = limit; + this.method = method; + this.hash = hash; + this.url = url; + this.route = route; + this.majorParameter = majorParameter; + this.global = global; + } + /** + * The name of the error + */ + get name() { + return `${_RateLimitError.name}[${this.route}]`; + } +}; + +// src/lib/REST.ts +import { Collection } from "@discordjs/collection"; +import { DiscordSnowflake } from "@sapphire/snowflake"; +import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter"; +import { filetypeinfo } from "magic-bytes.js"; + +// src/lib/utils/types.ts +var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => { + RequestMethod2["Delete"] = "DELETE"; + RequestMethod2["Get"] = "GET"; + RequestMethod2["Patch"] = "PATCH"; + RequestMethod2["Post"] = "POST"; + RequestMethod2["Put"] = "PUT"; + return RequestMethod2; +})(RequestMethod || {}); + +// src/lib/utils/utils.ts +function serializeSearchParam(value) { + switch (typeof value) { + case "string": + return value; + case "number": + case "bigint": + case "boolean": + return value.toString(); + case "object": + if (value === null) + return null; + if (value instanceof Date) { + return Number.isNaN(value.getTime()) ? null : value.toISOString(); + } + if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) + return value.toString(); + return null; + default: + return null; + } +} +__name(serializeSearchParam, "serializeSearchParam"); +function makeURLSearchParams(options) { + const params = new URLSearchParams(); + if (!options) + return params; + for (const [key, value] of Object.entries(options)) { + const serialized = serializeSearchParam(value); + if (serialized !== null) + params.append(key, serialized); + } + return params; +} +__name(makeURLSearchParams, "makeURLSearchParams"); +async function parseResponse(res) { + if (res.headers.get("Content-Type")?.startsWith("application/json")) { + return res.json(); + } + return res.arrayBuffer(); +} +__name(parseResponse, "parseResponse"); +function hasSublimit(bucketRoute, body, method) { + if (bucketRoute === "/channels/:id") { + if (typeof body !== "object" || body === null) + return false; + if (method !== "PATCH" /* Patch */) + return false; + const castedBody = body; + return ["name", "topic"].some((key) => Reflect.has(castedBody, key)); + } + return true; +} +__name(hasSublimit, "hasSublimit"); +function shouldRetry(error) { + if (error.name === "AbortError") + return true; + return "code" in error && error.code === "ECONNRESET" || error.message.includes("ECONNRESET"); +} +__name(shouldRetry, "shouldRetry"); +async function onRateLimit(manager, rateLimitData) { + const { options } = manager; + if (!options.rejectOnRateLimit) + return; + const shouldThrow = typeof options.rejectOnRateLimit === "function" ? await options.rejectOnRateLimit(rateLimitData) : options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase())); + if (shouldThrow) { + throw new RateLimitError(rateLimitData); + } +} +__name(onRateLimit, "onRateLimit"); +function calculateUserDefaultAvatarIndex(userId) { + return Number(BigInt(userId) >> 22n) % 6; +} +__name(calculateUserDefaultAvatarIndex, "calculateUserDefaultAvatarIndex"); +async function sleep(ms) { + return new Promise((resolve) => { + setTimeout(() => resolve(), ms); + }); +} +__name(sleep, "sleep"); +function isBufferLike(value) { + return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray; +} +__name(isBufferLike, "isBufferLike"); + +// src/lib/handlers/Shared.ts +var invalidCount = 0; +var invalidCountResetTime = null; +function incrementInvalidCount(manager) { + if (!invalidCountResetTime || invalidCountResetTime < Date.now()) { + invalidCountResetTime = Date.now() + 1e3 * 60 * 10; + invalidCount = 0; + } + invalidCount++; + const emitInvalid = manager.options.invalidRequestWarningInterval > 0 && invalidCount % manager.options.invalidRequestWarningInterval === 0; + if (emitInvalid) { + manager.emit("invalidRequestWarning" /* InvalidRequestWarning */, { + count: invalidCount, + remainingTime: invalidCountResetTime - Date.now() + }); + } +} +__name(incrementInvalidCount, "incrementInvalidCount"); +async function makeNetworkRequest(manager, routeId, url, options, requestData, retries) { + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), manager.options.timeout); + if (requestData.signal) { + if (requestData.signal.aborted) + controller.abort(); + else + requestData.signal.addEventListener("abort", () => controller.abort()); + } + let res; + try { + res = await manager.options.makeRequest(url, { ...options, signal: controller.signal }); + } catch (error) { + if (!(error instanceof Error)) + throw error; + if (shouldRetry(error) && retries !== manager.options.retries) { + return null; + } + throw error; + } finally { + clearTimeout(timeout); + } + if (manager.listenerCount("response" /* Response */)) { + manager.emit( + "response" /* Response */, + { + method: options.method ?? "get", + path: routeId.original, + route: routeId.bucketRoute, + options, + data: requestData, + retries + }, + res instanceof Response ? res.clone() : { ...res } + ); + } + return res; +} +__name(makeNetworkRequest, "makeNetworkRequest"); +async function handleErrors(manager, res, method, url, requestData, retries) { + const status = res.status; + if (status >= 500 && status < 600) { + if (retries !== manager.options.retries) { + return null; + } + throw new HTTPError(status, res.statusText, method, url, requestData); + } else { + if (status >= 400 && status < 500) { + if (status === 401 && requestData.auth) { + manager.setToken(null); + } + const data = await parseResponse(res); + throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); + } + return res; + } +} +__name(handleErrors, "handleErrors"); + +// src/lib/handlers/BurstHandler.ts +var BurstHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "BurstHandler"); + } + /** + * {@inheritdoc IHandler.id} + */ + id; + /** + * {@inheritDoc IHandler.inactive} + */ + inactive = false; + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + return this.runRequest(routeId, url, options, requestData); + } + /** + * The method that actually makes the request to the API, and updates info about the bucket accordingly + * + * @param routeId - The generalized API route with literal ids for major parameters + * @param url - The fully resolved URL to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const retry = res.headers.get("Retry-After"); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (status >= 200 && status < 300) { + return res; + } else if (status === 429) { + const isGlobal = res.headers.has("X-RateLimit-Global"); + await onRateLimit(this.manager, { + timeToReset: retryAfter, + limit: Number.POSITIVE_INFINITY, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${Number.POSITIVE_INFINITY}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : None` + ].join("\n") + ); + await sleep(retryAfter); + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/handlers/SequentialHandler.ts +import { AsyncQueue } from "@sapphire/async-queue"; +var SequentialHandler = class { + /** + * @param manager - The request manager + * @param hash - The hash that this RequestHandler handles + * @param majorParameter - The major parameter for this handler + */ + constructor(manager, hash, majorParameter) { + this.manager = manager; + this.hash = hash; + this.majorParameter = majorParameter; + this.id = `${hash}:${majorParameter}`; + } + static { + __name(this, "SequentialHandler"); + } + /** + * {@inheritDoc IHandler.id} + */ + id; + /** + * The time this rate limit bucket will reset + */ + reset = -1; + /** + * The remaining requests that can be made before we are rate limited + */ + remaining = 1; + /** + * The total number of requests that can be made before we are rate limited + */ + limit = Number.POSITIVE_INFINITY; + /** + * The interface used to sequence async requests sequentially + */ + #asyncQueue = new AsyncQueue(); + /** + * The interface used to sequence sublimited async requests sequentially + */ + #sublimitedQueue = null; + /** + * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed + */ + #sublimitPromise = null; + /** + * Whether the sublimit queue needs to be shifted in the finally block + */ + #shiftSublimit = false; + /** + * {@inheritDoc IHandler.inactive} + */ + get inactive() { + return this.#asyncQueue.remaining === 0 && (this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) && !this.limited; + } + /** + * If the rate limit bucket is currently limited by the global limit + */ + get globalLimited() { + return this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset; + } + /** + * If the rate limit bucket is currently limited by its limit + */ + get localLimited() { + return this.remaining <= 0 && Date.now() < this.reset; + } + /** + * If the rate limit bucket is currently limited + */ + get limited() { + return this.globalLimited || this.localLimited; + } + /** + * The time until queued requests can continue + */ + get timeToReset() { + return this.reset + this.manager.options.offset - Date.now(); + } + /** + * Emits a debug message + * + * @param message - The message to debug + */ + debug(message) { + this.manager.emit("restDebug" /* Debug */, `[REST ${this.id}] ${message}`); + } + /** + * Delay all requests for the specified amount of time, handling global rate limits + * + * @param time - The amount of time to delay all requests for + */ + async globalDelayFor(time) { + await sleep(time); + this.manager.globalDelay = null; + } + /** + * {@inheritDoc IHandler.queueRequest} + */ + async queueRequest(routeId, url, options, requestData) { + let queue = this.#asyncQueue; + let queueType = 0 /* Standard */; + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + queueType = 1 /* Sublimit */; + } + await queue.wait({ signal: requestData.signal }); + if (queueType === 0 /* Standard */) { + if (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) { + queue = this.#sublimitedQueue; + const wait = queue.wait(); + this.#asyncQueue.shift(); + await wait; + } else if (this.#sublimitPromise) { + await this.#sublimitPromise.promise; + } + } + try { + return await this.runRequest(routeId, url, options, requestData); + } finally { + queue.shift(); + if (this.#shiftSublimit) { + this.#shiftSublimit = false; + this.#sublimitedQueue?.shift(); + } + if (this.#sublimitedQueue?.remaining === 0) { + this.#sublimitPromise?.resolve(); + this.#sublimitedQueue = null; + } + } + } + /** + * The method that actually makes the request to the api, and updates info about the bucket accordingly + * + * @param routeId - The generalized api route with literal ids for major parameters + * @param url - The fully resolved url to make the request to + * @param options - The fetch options needed to make the request + * @param requestData - Extra data from the user's request needed for errors and additional processing + * @param retries - The number of retries this request has already attempted (recursion) + */ + async runRequest(routeId, url, options, requestData, retries = 0) { + while (this.limited) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + let delay; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + if (!this.manager.globalDelay) { + this.manager.globalDelay = this.globalDelayFor(timeout); + } + delay = this.manager.globalDelay; + } else { + limit2 = this.limit; + timeout = this.timeToReset; + delay = sleep(timeout); + } + const rateLimitData = { + timeToReset: timeout, + limit: limit2, + method: options.method ?? "get", + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }; + this.manager.emit("rateLimited" /* RateLimited */, rateLimitData); + await onRateLimit(this.manager, rateLimitData); + if (isGlobal) { + this.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`); + } else { + this.debug(`Waiting ${timeout}ms for rate limit to pass`); + } + await delay; + } + if (!this.manager.globalReset || this.manager.globalReset < Date.now()) { + this.manager.globalReset = Date.now() + 1e3; + this.manager.globalRemaining = this.manager.options.globalRequestsPerSecond; + } + this.manager.globalRemaining--; + const method = options.method ?? "get"; + const res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries); + if (res === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + const status = res.status; + let retryAfter = 0; + const limit = res.headers.get("X-RateLimit-Limit"); + const remaining = res.headers.get("X-RateLimit-Remaining"); + const reset = res.headers.get("X-RateLimit-Reset-After"); + const hash = res.headers.get("X-RateLimit-Bucket"); + const retry = res.headers.get("Retry-After"); + this.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY; + this.remaining = remaining ? Number(remaining) : 1; + this.reset = reset ? Number(reset) * 1e3 + Date.now() + this.manager.options.offset : Date.now(); + if (retry) + retryAfter = Number(retry) * 1e3 + this.manager.options.offset; + if (hash && hash !== this.hash) { + this.debug(["Received bucket hash update", ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join("\n")); + this.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() }); + } else if (hash) { + const hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`); + if (hashData) { + hashData.lastAccess = Date.now(); + } + } + let sublimitTimeout = null; + if (retryAfter > 0) { + if (res.headers.has("X-RateLimit-Global")) { + this.manager.globalRemaining = 0; + this.manager.globalReset = Date.now() + retryAfter; + } else if (!this.localLimited) { + sublimitTimeout = retryAfter; + } + } + if (status === 401 || status === 403 || status === 429) { + incrementInvalidCount(this.manager); + } + if (res.ok) { + return res; + } else if (status === 429) { + const isGlobal = this.globalLimited; + let limit2; + let timeout; + if (isGlobal) { + limit2 = this.manager.options.globalRequestsPerSecond; + timeout = this.manager.globalReset + this.manager.options.offset - Date.now(); + } else { + limit2 = this.limit; + timeout = this.timeToReset; + } + await onRateLimit(this.manager, { + timeToReset: timeout, + limit: limit2, + method, + hash: this.hash, + url, + route: routeId.bucketRoute, + majorParameter: this.majorParameter, + global: isGlobal + }); + this.debug( + [ + "Encountered unexpected 429 rate limit", + ` Global : ${isGlobal.toString()}`, + ` Method : ${method}`, + ` URL : ${url}`, + ` Bucket : ${routeId.bucketRoute}`, + ` Major parameter: ${routeId.majorParameter}`, + ` Hash : ${this.hash}`, + ` Limit : ${limit2}`, + ` Retry After : ${retryAfter}ms`, + ` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : "None"}` + ].join("\n") + ); + if (sublimitTimeout) { + const firstSublimit = !this.#sublimitedQueue; + if (firstSublimit) { + this.#sublimitedQueue = new AsyncQueue(); + void this.#sublimitedQueue.wait(); + this.#asyncQueue.shift(); + } + this.#sublimitPromise?.resolve(); + this.#sublimitPromise = null; + await sleep(sublimitTimeout); + let resolve; + const promise = new Promise((res2) => resolve = res2); + this.#sublimitPromise = { promise, resolve }; + if (firstSublimit) { + await this.#asyncQueue.wait(); + this.#shiftSublimit = true; + } + } + return this.runRequest(routeId, url, options, requestData, retries); + } else { + const handled = await handleErrors(this.manager, res, method, url, requestData, retries); + if (handled === null) { + return this.runRequest(routeId, url, options, requestData, ++retries); + } + return handled; + } + } +}; + +// src/lib/REST.ts +var REST = class _REST extends AsyncEventEmitter { + static { + __name(this, "REST"); + } + /** + * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests + * performed by this manager. + */ + agent = null; + cdn; + /** + * The number of requests remaining in the global bucket + */ + globalRemaining; + /** + * The promise used to wait out the global rate limit + */ + globalDelay = null; + /** + * The timestamp at which the global bucket resets + */ + globalReset = -1; + /** + * API bucket hashes that are cached from provided routes + */ + hashes = new Collection(); + /** + * Request handlers created from the bucket hash and the major parameters + */ + handlers = new Collection(); + #token = null; + hashTimer; + handlerTimer; + options; + constructor(options = {}) { + super(); + this.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn); + this.options = { ...DefaultRestOptions, ...options }; + this.options.offset = Math.max(0, this.options.offset); + this.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond); + this.agent = options.agent ?? null; + this.setupSweepers(); + } + setupSweepers() { + const validateMaxInterval = /* @__PURE__ */ __name((interval) => { + if (interval > 144e5) { + throw new Error("Cannot set an interval greater than 4 hours"); + } + }, "validateMaxInterval"); + if (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.hashSweepInterval); + this.hashTimer = setInterval(() => { + const sweptHashes = new Collection(); + const currentDate = Date.now(); + this.hashes.sweep((val, key) => { + if (val.lastAccess === -1) + return false; + const shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime; + if (shouldSweep) { + sweptHashes.set(key, val); + this.emit("restDebug" /* Debug */, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`); + } + return shouldSweep; + }); + this.emit("hashSweep" /* HashSweep */, sweptHashes); + }, this.options.hashSweepInterval); + this.hashTimer.unref?.(); + } + if (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) { + validateMaxInterval(this.options.handlerSweepInterval); + this.handlerTimer = setInterval(() => { + const sweptHandlers = new Collection(); + this.handlers.sweep((val, key) => { + const { inactive } = val; + if (inactive) { + sweptHandlers.set(key, val); + this.emit("restDebug" /* Debug */, `Handler ${val.id} for ${key} swept due to being inactive`); + } + return inactive; + }); + this.emit("handlerSweep" /* HandlerSweep */, sweptHandlers); + }, this.options.handlerSweepInterval); + this.handlerTimer.unref?.(); + } + } + /** + * Runs a get request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async get(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "GET" /* Get */ }); + } + /** + * Runs a delete request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async delete(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "DELETE" /* Delete */ }); + } + /** + * Runs a post request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async post(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "POST" /* Post */ }); + } + /** + * Runs a put request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async put(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PUT" /* Put */ }); + } + /** + * Runs a patch request from the api + * + * @param fullRoute - The full route to query + * @param options - Optional request options + */ + async patch(fullRoute, options = {}) { + return this.request({ ...options, fullRoute, method: "PATCH" /* Patch */ }); + } + /** + * Runs a request from the api + * + * @param options - Request options + */ + async request(options) { + const response = await this.queueRequest(options); + return parseResponse(response); + } + /** + * Sets the default agent to use for requests performed by this manager + * + * @param agent - The agent to use + */ + setAgent(agent) { + this.agent = agent; + return this; + } + /** + * Sets the authorization token that should be used for requests + * + * @param token - The authorization token to use + */ + setToken(token) { + this.#token = token; + return this; + } + /** + * Queues a request to be sent + * + * @param request - All the information needed to make a request + * @returns The response from the api request + */ + async queueRequest(request) { + const routeId = _REST.generateRouteData(request.fullRoute, request.method); + const hash = this.hashes.get(`${request.method}:${routeId.bucketRoute}`) ?? { + value: `Global(${request.method}:${routeId.bucketRoute})`, + lastAccess: -1 + }; + const handler = this.handlers.get(`${hash.value}:${routeId.majorParameter}`) ?? this.createHandler(hash.value, routeId.majorParameter); + const { url, fetchOptions } = await this.resolveRequest(request); + return handler.queueRequest(routeId, url, fetchOptions, { + body: request.body, + files: request.files, + auth: request.auth !== false, + signal: request.signal + }); + } + /** + * Creates a new rate limit handler from a hash, based on the hash and the major parameter + * + * @param hash - The hash for the route + * @param majorParameter - The major parameter for this handler + * @internal + */ + createHandler(hash, majorParameter) { + const queue = majorParameter === BurstHandlerMajorIdKey ? new BurstHandler(this, hash, majorParameter) : new SequentialHandler(this, hash, majorParameter); + this.handlers.set(queue.id, queue); + return queue; + } + /** + * Formats the request data to a usable format for fetch + * + * @param request - The request data + */ + async resolveRequest(request) { + const { options } = this; + let query = ""; + if (request.query) { + const resolvedQuery = request.query.toString(); + if (resolvedQuery !== "") { + query = `?${resolvedQuery}`; + } + } + const headers = { + ...this.options.headers, + "User-Agent": `${DefaultUserAgent} ${options.userAgentAppendix}`.trim() + }; + if (request.auth !== false) { + if (!this.#token) { + throw new Error("Expected token to be set for this request, but none was present"); + } + headers.Authorization = `${request.authPrefix ?? this.options.authPrefix} ${this.#token}`; + } + if (request.reason?.length) { + headers["X-Audit-Log-Reason"] = encodeURIComponent(request.reason); + } + const url = `${options.api}${request.versioned === false ? "" : `/v${options.version}`}${request.fullRoute}${query}`; + let finalBody; + let additionalHeaders = {}; + if (request.files?.length) { + const formData = new FormData(); + for (const [index, file] of request.files.entries()) { + const fileKey = file.key ?? `files[${index}]`; + if (isBufferLike(file.data)) { + let contentType = file.contentType; + if (!contentType) { + const [parsedType] = filetypeinfo(file.data); + if (parsedType) { + contentType = OverwrittenMimeTypes[parsedType.mime] ?? parsedType.mime ?? "application/octet-stream"; + } + } + formData.append(fileKey, new Blob([file.data], { type: contentType }), file.name); + } else { + formData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name); + } + } + if (request.body != null) { + if (request.appendToFormData) { + for (const [key, value] of Object.entries(request.body)) { + formData.append(key, value); + } + } else { + formData.append("payload_json", JSON.stringify(request.body)); + } + } + finalBody = formData; + } else if (request.body != null) { + if (request.passThroughBody) { + finalBody = request.body; + } else { + finalBody = JSON.stringify(request.body); + additionalHeaders = { "Content-Type": "application/json" }; + } + } + const method = request.method.toUpperCase(); + const fetchOptions = { + // Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing + body: ["GET", "HEAD"].includes(method) ? null : finalBody, + headers: { ...request.headers, ...additionalHeaders, ...headers }, + method, + // Prioritize setting an agent per request, use the agent for this instance otherwise. + dispatcher: request.dispatcher ?? this.agent ?? void 0 + }; + return { url, fetchOptions }; + } + /** + * Stops the hash sweeping interval + */ + clearHashSweeper() { + clearInterval(this.hashTimer); + } + /** + * Stops the request handler sweeping interval + */ + clearHandlerSweeper() { + clearInterval(this.handlerTimer); + } + /** + * Generates route data for an endpoint:method + * + * @param endpoint - The raw endpoint to generalize + * @param method - The HTTP method this endpoint is called without + * @internal + */ + static generateRouteData(endpoint, method) { + if (endpoint.startsWith("/interactions/") && endpoint.endsWith("/callback")) { + return { + majorParameter: BurstHandlerMajorIdKey, + bucketRoute: "/interactions/:id/:token/callback", + original: endpoint + }; + } + const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{17,19})/.exec(endpoint); + const majorId = majorIdMatch?.[1] ?? "global"; + const baseRoute = endpoint.replaceAll(/\d{17,19}/g, ":id").replace(/\/reactions\/(.*)/, "/reactions/:reaction"); + let exceptions = ""; + if (method === "DELETE" /* Delete */ && baseRoute === "/channels/:id/messages/:id") { + const id = /\d{17,19}$/.exec(endpoint)[0]; + const timestamp = DiscordSnowflake.timestampFrom(id); + if (Date.now() - timestamp > 1e3 * 60 * 60 * 24 * 14) { + exceptions += "/Delete Old Message"; + } + } + return { + majorParameter: majorId, + bucketRoute: baseRoute + exceptions, + original: endpoint + }; + } +}; + +// src/shared.ts +var version = "2.0.1"; + +// src/web.ts +setDefaultStrategy(fetch); +export { + ALLOWED_EXTENSIONS, + ALLOWED_SIZES, + ALLOWED_STICKER_EXTENSIONS, + BurstHandlerMajorIdKey, + CDN, + DefaultRestOptions, + DefaultUserAgent, + DefaultUserAgentAppendix, + DiscordAPIError, + HTTPError, + OverwrittenMimeTypes, + REST, + RESTEvents, + RateLimitError, + RequestMethod, + calculateUserDefaultAvatarIndex, + makeURLSearchParams, + parseResponse, + version +}; +//# sourceMappingURL=web.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/dist/web.mjs.map b/node_modules/@discordjs/rest/dist/web.mjs.map new file mode 100644 index 0000000..e0459eb --- /dev/null +++ b/node_modules/@discordjs/rest/dist/web.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/environment.ts","../src/lib/utils/constants.ts","../src/lib/CDN.ts","../src/lib/errors/DiscordAPIError.ts","../src/lib/errors/HTTPError.ts","../src/lib/errors/RateLimitError.ts","../src/lib/REST.ts","../src/lib/utils/types.ts","../src/lib/utils/utils.ts","../src/lib/handlers/Shared.ts","../src/lib/handlers/BurstHandler.ts","../src/lib/handlers/SequentialHandler.ts","../src/shared.ts","../src/web.ts"],"sourcesContent":["import type { RESTOptions } from './shared.js';\n\nlet defaultStrategy: RESTOptions['makeRequest'];\n\nexport function setDefaultStrategy(newStrategy: RESTOptions['makeRequest']) {\n\tdefaultStrategy = newStrategy;\n}\n\nexport function getDefaultStrategy() {\n\treturn defaultStrategy;\n}\n","import { getUserAgentAppendix } from '@discordjs/util';\nimport { APIVersion } from 'discord-api-types/v10';\nimport { getDefaultStrategy } from '../../environment.js';\nimport type { RESTOptions, ResponseLike } from './types.js';\n\nexport const DefaultUserAgent =\n\t`DiscordBot (https://discord.js.org, 2.0.1)` as `DiscordBot (https://discord.js.org, ${string})`;\n\n/**\n * The default string to append onto the user agent.\n */\nexport const DefaultUserAgentAppendix = getUserAgentAppendix();\n\nexport const DefaultRestOptions = {\n\tagent: null,\n\tapi: 'https://discord.com/api',\n\tauthPrefix: 'Bot',\n\tcdn: 'https://cdn.discordapp.com',\n\theaders: {},\n\tinvalidRequestWarningInterval: 0,\n\tglobalRequestsPerSecond: 50,\n\toffset: 50,\n\trejectOnRateLimit: null,\n\tretries: 3,\n\ttimeout: 15_000,\n\tuserAgentAppendix: DefaultUserAgentAppendix,\n\tversion: APIVersion,\n\thashSweepInterval: 14_400_000, // 4 Hours\n\thashLifetime: 86_400_000, // 24 Hours\n\thandlerSweepInterval: 3_600_000, // 1 Hour\n\tasync makeRequest(...args): Promise<ResponseLike> {\n\t\treturn getDefaultStrategy()(...args);\n\t},\n} as const satisfies Required<RESTOptions>;\n\n/**\n * The events that the REST manager emits\n */\nexport enum RESTEvents {\n\tDebug = 'restDebug',\n\tHandlerSweep = 'handlerSweep',\n\tHashSweep = 'hashSweep',\n\tInvalidRequestWarning = 'invalidRequestWarning',\n\tRateLimited = 'rateLimited',\n\tResponse = 'response',\n}\n\nexport const ALLOWED_EXTENSIONS = ['webp', 'png', 'jpg', 'jpeg', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_STICKER_EXTENSIONS = ['png', 'json', 'gif'] as const satisfies readonly string[];\nexport const ALLOWED_SIZES = [16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096] as const satisfies readonly number[];\n\nexport type ImageExtension = (typeof ALLOWED_EXTENSIONS)[number];\nexport type StickerExtension = (typeof ALLOWED_STICKER_EXTENSIONS)[number];\nexport type ImageSize = (typeof ALLOWED_SIZES)[number];\n\nexport const OverwrittenMimeTypes = {\n\t// https://github.com/discordjs/discord.js/issues/8557\n\t'image/apng': 'image/png',\n} as const satisfies Readonly<Record<string, string>>;\n\nexport const BurstHandlerMajorIdKey = 'burst';\n","/* eslint-disable jsdoc/check-param-names */\nimport {\n\tALLOWED_EXTENSIONS,\n\tALLOWED_SIZES,\n\tALLOWED_STICKER_EXTENSIONS,\n\tDefaultRestOptions,\n\ttype ImageExtension,\n\ttype ImageSize,\n\ttype StickerExtension,\n} from './utils/constants.js';\n\n/**\n * The options used for image URLs\n */\nexport interface BaseImageURLOptions {\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: ImageExtension;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The options used for image URLs with animated content\n */\nexport interface ImageURLOptions extends BaseImageURLOptions {\n\t/**\n\t * Whether or not to prefer the static version of an image asset.\n\t */\n\tforceStatic?: boolean;\n}\n\n/**\n * The options to use when making a CDN URL\n */\nexport interface MakeURLOptions {\n\t/**\n\t * The allowed extensions that can be used\n\t */\n\tallowedExtensions?: readonly string[];\n\t/**\n\t * The extension to use for the image URL\n\t *\n\t * @defaultValue `'webp'`\n\t */\n\textension?: string | undefined;\n\t/**\n\t * The size specified in the image URL\n\t */\n\tsize?: ImageSize;\n}\n\n/**\n * The CDN link builder\n */\nexport class CDN {\n\tpublic constructor(private readonly base: string = DefaultRestOptions.cdn) {}\n\n\t/**\n\t * Generates an app asset URL for a client's asset.\n\t *\n\t * @param clientId - The client id that has the asset\n\t * @param assetHash - The hash provided by Discord for this asset\n\t * @param options - Optional options for the asset\n\t */\n\tpublic appAsset(clientId: string, assetHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/${clientId}/${assetHash}`, options);\n\t}\n\n\t/**\n\t * Generates an app icon URL for a client's icon.\n\t *\n\t * @param clientId - The client id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic appIcon(clientId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-icons/${clientId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates an avatar URL, e.g. for a user or a webhook.\n\t *\n\t * @param id - The id that has the icon\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a user avatar decoration URL.\n\t *\n\t * @param userId - The id of the user\n\t * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration\n\t * @param options - Optional options for the avatar decoration\n\t */\n\tpublic avatarDecoration(\n\t\tuserId: string,\n\t\tuserAvatarDecoration: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);\n\t}\n\n\t/**\n\t * Generates a banner URL, e.g. for a user or a guild.\n\t *\n\t * @param id - The id that has the banner splash\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic banner(id: string, bannerHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL for a channel, e.g. a group DM.\n\t *\n\t * @param channelId - The channel id that has the icon\n\t * @param iconHash - The hash provided by Discord for this channel\n\t * @param options - Optional options for the icon\n\t */\n\tpublic channelIcon(channelId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a default avatar URL\n\t *\n\t * @param index - The default avatar index\n\t * @remarks\n\t * To calculate the index for a user do `(userId >> 22) % 6`,\n\t * or `discriminator % 5` if they're using the legacy username system.\n\t */\n\tpublic defaultAvatar(index: number): string {\n\t\treturn this.makeURL(`/embed/avatars/${index}`, { extension: 'png' });\n\t}\n\n\t/**\n\t * Generates a discovery splash URL for a guild's discovery splash.\n\t *\n\t * @param guildId - The guild id that has the discovery splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates an emoji's URL for an emoji.\n\t *\n\t * @param emojiId - The emoji id\n\t * @param extension - The extension of the emoji\n\t */\n\tpublic emoji(emojiId: string, extension?: ImageExtension): string {\n\t\treturn this.makeURL(`/emojis/${emojiId}`, { extension });\n\t}\n\n\t/**\n\t * Generates a guild member avatar URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param avatarHash - The hash provided by Discord for this avatar\n\t * @param options - Optional options for the avatar\n\t */\n\tpublic guildMemberAvatar(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tavatarHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options);\n\t}\n\n\t/**\n\t * Generates a guild member banner URL.\n\t *\n\t * @param guildId - The id of the guild\n\t * @param userId - The id of the user\n\t * @param bannerHash - The hash provided by Discord for this banner\n\t * @param options - Optional options for the banner\n\t */\n\tpublic guildMemberBanner(\n\t\tguildId: string,\n\t\tuserId: string,\n\t\tbannerHash: string,\n\t\toptions?: Readonly<ImageURLOptions>,\n\t): string {\n\t\treturn this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options);\n\t}\n\n\t/**\n\t * Generates an icon URL, e.g. for a guild.\n\t *\n\t * @param id - The id that has the icon splash\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic icon(id: string, iconHash: string, options?: Readonly<ImageURLOptions>): string {\n\t\treturn this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options);\n\t}\n\n\t/**\n\t * Generates a URL for the icon of a role\n\t *\n\t * @param roleId - The id of the role that has the icon\n\t * @param roleIconHash - The hash provided by Discord for this role icon\n\t * @param options - Optional options for the role icon\n\t */\n\tpublic roleIcon(roleId: string, roleIconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a guild invite splash URL for a guild's invite splash.\n\t *\n\t * @param guildId - The guild id that has the invite splash\n\t * @param splashHash - The hash provided by Discord for this splash\n\t * @param options - Optional options for the splash\n\t */\n\tpublic splash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/splashes/${guildId}/${splashHash}`, options);\n\t}\n\n\t/**\n\t * Generates a sticker URL.\n\t *\n\t * @param stickerId - The sticker id\n\t * @param extension - The extension of the sticker\n\t * @privateRemarks\n\t * Stickers cannot have a `.webp` extension, so we default to a `.png`\n\t */\n\tpublic sticker(stickerId: string, extension: StickerExtension = 'png'): string {\n\t\treturn this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: ALLOWED_STICKER_EXTENSIONS, extension });\n\t}\n\n\t/**\n\t * Generates a sticker pack banner URL.\n\t *\n\t * @param bannerId - The banner id\n\t * @param options - Optional options for the banner\n\t */\n\tpublic stickerPackBanner(bannerId: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options);\n\t}\n\n\t/**\n\t * Generates a team icon URL for a team's icon.\n\t *\n\t * @param teamId - The team id that has the icon\n\t * @param iconHash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the icon\n\t */\n\tpublic teamIcon(teamId: string, iconHash: string, options?: Readonly<BaseImageURLOptions>): string {\n\t\treturn this.makeURL(`/team-icons/${teamId}/${iconHash}`, options);\n\t}\n\n\t/**\n\t * Generates a cover image for a guild scheduled event.\n\t *\n\t * @param scheduledEventId - The scheduled event id\n\t * @param coverHash - The hash provided by discord for this cover image\n\t * @param options - Optional options for the cover image\n\t */\n\tpublic guildScheduledEventCover(\n\t\tscheduledEventId: string,\n\t\tcoverHash: string,\n\t\toptions?: Readonly<BaseImageURLOptions>,\n\t): string {\n\t\treturn this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.\n\t *\n\t * @param route - The base cdn route\n\t * @param hash - The hash provided by Discord for this icon\n\t * @param options - Optional options for the link\n\t */\n\tprivate dynamicMakeURL(\n\t\troute: string,\n\t\thash: string,\n\t\t{ forceStatic = false, ...options }: Readonly<ImageURLOptions> = {},\n\t): string {\n\t\treturn this.makeURL(route, !forceStatic && hash.startsWith('a_') ? { ...options, extension: 'gif' } : options);\n\t}\n\n\t/**\n\t * Constructs the URL for the resource\n\t *\n\t * @param route - The base cdn route\n\t * @param options - The extension/size options for the link\n\t */\n\tprivate makeURL(\n\t\troute: string,\n\t\t{ allowedExtensions = ALLOWED_EXTENSIONS, extension = 'webp', size }: Readonly<MakeURLOptions> = {},\n\t): string {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\textension = String(extension).toLowerCase();\n\n\t\tif (!allowedExtensions.includes(extension)) {\n\t\t\tthrow new RangeError(`Invalid extension provided: ${extension}\\nMust be one of: ${allowedExtensions.join(', ')}`);\n\t\t}\n\n\t\tif (size && !ALLOWED_SIZES.includes(size)) {\n\t\t\tthrow new RangeError(`Invalid size provided: ${size}\\nMust be one of: ${ALLOWED_SIZES.join(', ')}`);\n\t\t}\n\n\t\tconst url = new URL(`${this.base}${route}.${extension}`);\n\n\t\tif (size) {\n\t\t\turl.searchParams.set('size', String(size));\n\t\t}\n\n\t\treturn url.toString();\n\t}\n}\n","import type { InternalRequest, RawFile } from '../utils/types.js';\n\ninterface DiscordErrorFieldInformation {\n\tcode: string;\n\tmessage: string;\n}\n\ninterface DiscordErrorGroupWrapper {\n\t_errors: DiscordError[];\n}\n\ntype DiscordError = DiscordErrorFieldInformation | DiscordErrorGroupWrapper | string | { [k: string]: DiscordError };\n\nexport interface DiscordErrorData {\n\tcode: number;\n\terrors?: DiscordError;\n\tmessage: string;\n}\n\nexport interface OAuthErrorData {\n\terror: string;\n\terror_description?: string;\n}\n\nexport interface RequestBody {\n\tfiles: RawFile[] | undefined;\n\tjson: unknown | undefined;\n}\n\nfunction isErrorGroupWrapper(error: DiscordError): error is DiscordErrorGroupWrapper {\n\treturn Reflect.has(error as Record<string, unknown>, '_errors');\n}\n\nfunction isErrorResponse(error: DiscordError): error is DiscordErrorFieldInformation {\n\treturn typeof Reflect.get(error as Record<string, unknown>, 'message') === 'string';\n}\n\n/**\n * Represents an API error returned by Discord\n */\nexport class DiscordAPIError extends Error {\n\tpublic requestBody: RequestBody;\n\n\t/**\n\t * @param rawError - The error reported by Discord\n\t * @param code - The error code reported by Discord\n\t * @param status - The status code of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic rawError: DiscordErrorData | OAuthErrorData,\n\t\tpublic code: number | string,\n\t\tpublic status: number,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(DiscordAPIError.getMessage(rawError));\n\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${DiscordAPIError.name}[${this.code}]`;\n\t}\n\n\tprivate static getMessage(error: DiscordErrorData | OAuthErrorData) {\n\t\tlet flattened = '';\n\t\tif ('code' in error) {\n\t\t\tif (error.errors) {\n\t\t\t\tflattened = [...this.flattenDiscordError(error.errors)].join('\\n');\n\t\t\t}\n\n\t\t\treturn error.message && flattened\n\t\t\t\t? `${error.message}\\n${flattened}`\n\t\t\t\t: error.message || flattened || 'Unknown Error';\n\t\t}\n\n\t\treturn error.error_description ?? 'No Description';\n\t}\n\n\tprivate static *flattenDiscordError(obj: DiscordError, key = ''): IterableIterator<string> {\n\t\tif (isErrorResponse(obj)) {\n\t\t\treturn yield `${key.length ? `${key}[${obj.code}]` : `${obj.code}`}: ${obj.message}`.trim();\n\t\t}\n\n\t\tfor (const [otherKey, val] of Object.entries(obj)) {\n\t\t\tconst nextKey = otherKey.startsWith('_')\n\t\t\t\t? key\n\t\t\t\t: key\n\t\t\t\t? Number.isNaN(Number(otherKey))\n\t\t\t\t\t? `${key}.${otherKey}`\n\t\t\t\t\t: `${key}[${otherKey}]`\n\t\t\t\t: otherKey;\n\n\t\t\tif (typeof val === 'string') {\n\t\t\t\tyield val;\n\t\t\t} else if (isErrorGroupWrapper(val)) {\n\t\t\t\tfor (const error of val._errors) {\n\t\t\t\t\tyield* this.flattenDiscordError(error, nextKey);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield* this.flattenDiscordError(val, nextKey);\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { InternalRequest } from '../utils/types.js';\nimport type { RequestBody } from './DiscordAPIError.js';\n\n/**\n * Represents a HTTP error\n */\nexport class HTTPError extends Error {\n\tpublic requestBody: RequestBody;\n\n\tpublic override name = HTTPError.name;\n\n\t/**\n\t * @param status - The status code of the response\n\t * @param statusText - The status text of the response\n\t * @param method - The method of the request that erred\n\t * @param url - The url of the request that erred\n\t * @param bodyData - The unparsed data for the request that errored\n\t */\n\tpublic constructor(\n\t\tpublic status: number,\n\t\tstatusText: string,\n\t\tpublic method: string,\n\t\tpublic url: string,\n\t\tbodyData: Pick<InternalRequest, 'body' | 'files'>,\n\t) {\n\t\tsuper(statusText);\n\t\tthis.requestBody = { files: bodyData.files, json: bodyData.body };\n\t}\n}\n","import type { RateLimitData } from '../utils/types.js';\n\nexport class RateLimitError extends Error implements RateLimitData {\n\tpublic timeToReset: number;\n\n\tpublic limit: number;\n\n\tpublic method: string;\n\n\tpublic hash: string;\n\n\tpublic url: string;\n\n\tpublic route: string;\n\n\tpublic majorParameter: string;\n\n\tpublic global: boolean;\n\n\tpublic constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global }: RateLimitData) {\n\t\tsuper();\n\t\tthis.timeToReset = timeToReset;\n\t\tthis.limit = limit;\n\t\tthis.method = method;\n\t\tthis.hash = hash;\n\t\tthis.url = url;\n\t\tthis.route = route;\n\t\tthis.majorParameter = majorParameter;\n\t\tthis.global = global;\n\t}\n\n\t/**\n\t * The name of the error\n\t */\n\tpublic override get name(): string {\n\t\treturn `${RateLimitError.name}[${this.route}]`;\n\t}\n}\n","import { Collection } from '@discordjs/collection';\nimport { DiscordSnowflake } from '@sapphire/snowflake';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { filetypeinfo } from 'magic-bytes.js';\nimport type { RequestInit, BodyInit, Dispatcher } from 'undici';\nimport { CDN } from './CDN.js';\nimport { BurstHandler } from './handlers/BurstHandler.js';\nimport { SequentialHandler } from './handlers/SequentialHandler.js';\nimport type { IHandler } from './interfaces/Handler.js';\nimport {\n\tBurstHandlerMajorIdKey,\n\tDefaultRestOptions,\n\tDefaultUserAgent,\n\tOverwrittenMimeTypes,\n\tRESTEvents,\n} from './utils/constants.js';\nimport { RequestMethod } from './utils/types.js';\nimport type {\n\tRESTOptions,\n\tResponseLike,\n\tRestEventsMap,\n\tHashData,\n\tInternalRequest,\n\tRouteLike,\n\tRequestHeaders,\n\tRouteData,\n\tRequestData,\n} from './utils/types.js';\nimport { isBufferLike, parseResponse } from './utils/utils.js';\n\n/**\n * Represents the class that manages handlers for endpoints\n */\nexport class REST extends AsyncEventEmitter<RestEventsMap> {\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} for all requests\n\t * performed by this manager.\n\t */\n\tpublic agent: Dispatcher | null = null;\n\n\tpublic readonly cdn: CDN;\n\n\t/**\n\t * The number of requests remaining in the global bucket\n\t */\n\tpublic globalRemaining: number;\n\n\t/**\n\t * The promise used to wait out the global rate limit\n\t */\n\tpublic globalDelay: Promise<void> | null = null;\n\n\t/**\n\t * The timestamp at which the global bucket resets\n\t */\n\tpublic globalReset = -1;\n\n\t/**\n\t * API bucket hashes that are cached from provided routes\n\t */\n\tpublic readonly hashes = new Collection<string, HashData>();\n\n\t/**\n\t * Request handlers created from the bucket hash and the major parameters\n\t */\n\tpublic readonly handlers = new Collection<string, IHandler>();\n\n\t#token: string | null = null;\n\n\tprivate hashTimer!: NodeJS.Timer | number;\n\n\tprivate handlerTimer!: NodeJS.Timer | number;\n\n\tpublic readonly options: RESTOptions;\n\n\tpublic constructor(options: Partial<RESTOptions> = {}) {\n\t\tsuper();\n\t\tthis.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn);\n\t\tthis.options = { ...DefaultRestOptions, ...options };\n\t\tthis.options.offset = Math.max(0, this.options.offset);\n\t\tthis.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond);\n\t\tthis.agent = options.agent ?? null;\n\n\t\t// Start sweepers\n\t\tthis.setupSweepers();\n\t}\n\n\tprivate setupSweepers() {\n\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\tconst validateMaxInterval = (interval: number) => {\n\t\t\tif (interval > 14_400_000) {\n\t\t\t\tthrow new Error('Cannot set an interval greater than 4 hours');\n\t\t\t}\n\t\t};\n\n\t\tif (this.options.hashSweepInterval !== 0 && this.options.hashSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.hashSweepInterval);\n\t\t\tthis.hashTimer = setInterval(() => {\n\t\t\t\tconst sweptHashes = new Collection<string, HashData>();\n\t\t\t\tconst currentDate = Date.now();\n\n\t\t\t\t// Begin sweeping hash based on lifetimes\n\t\t\t\tthis.hashes.sweep((val, key) => {\n\t\t\t\t\t// `-1` indicates a global hash\n\t\t\t\t\tif (val.lastAccess === -1) return false;\n\n\t\t\t\t\t// Check if lifetime has been exceeded\n\t\t\t\t\tconst shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime;\n\n\t\t\t\t\t// Add hash to collection of swept hashes\n\t\t\t\t\tif (shouldSweep) {\n\t\t\t\t\t\t// Add to swept hashes\n\t\t\t\t\t\tsweptHashes.set(key, val);\n\n\t\t\t\t\t\t// Emit debug information\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn shouldSweep;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HashSweep, sweptHashes);\n\t\t\t}, this.options.hashSweepInterval);\n\n\t\t\tthis.hashTimer.unref?.();\n\t\t}\n\n\t\tif (this.options.handlerSweepInterval !== 0 && this.options.handlerSweepInterval !== Number.POSITIVE_INFINITY) {\n\t\t\tvalidateMaxInterval(this.options.handlerSweepInterval);\n\t\t\tthis.handlerTimer = setInterval(() => {\n\t\t\t\tconst sweptHandlers = new Collection<string, IHandler>();\n\n\t\t\t\t// Begin sweeping handlers based on activity\n\t\t\t\tthis.handlers.sweep((val, key) => {\n\t\t\t\t\tconst { inactive } = val;\n\n\t\t\t\t\t// Collect inactive handlers\n\t\t\t\t\tif (inactive) {\n\t\t\t\t\t\tsweptHandlers.set(key, val);\n\t\t\t\t\t\tthis.emit(RESTEvents.Debug, `Handler ${val.id} for ${key} swept due to being inactive`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn inactive;\n\t\t\t\t});\n\n\t\t\t\t// Fire event\n\t\t\t\tthis.emit(RESTEvents.HandlerSweep, sweptHandlers);\n\t\t\t}, this.options.handlerSweepInterval);\n\n\t\t\tthis.handlerTimer.unref?.();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a get request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async get(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Get });\n\t}\n\n\t/**\n\t * Runs a delete request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async delete(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Delete });\n\t}\n\n\t/**\n\t * Runs a post request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async post(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Post });\n\t}\n\n\t/**\n\t * Runs a put request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async put(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Put });\n\t}\n\n\t/**\n\t * Runs a patch request from the api\n\t *\n\t * @param fullRoute - The full route to query\n\t * @param options - Optional request options\n\t */\n\tpublic async patch(fullRoute: RouteLike, options: RequestData = {}) {\n\t\treturn this.request({ ...options, fullRoute, method: RequestMethod.Patch });\n\t}\n\n\t/**\n\t * Runs a request from the api\n\t *\n\t * @param options - Request options\n\t */\n\tpublic async request(options: InternalRequest) {\n\t\tconst response = await this.queueRequest(options);\n\t\treturn parseResponse(response);\n\t}\n\n\t/**\n\t * Sets the default agent to use for requests performed by this manager\n\t *\n\t * @param agent - The agent to use\n\t */\n\tpublic setAgent(agent: Dispatcher) {\n\t\tthis.agent = agent;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the authorization token that should be used for requests\n\t *\n\t * @param token - The authorization token to use\n\t */\n\tpublic setToken(token: string) {\n\t\tthis.#token = token;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Queues a request to be sent\n\t *\n\t * @param request - All the information needed to make a request\n\t * @returns The response from the api request\n\t */\n\tpublic async queueRequest(request: InternalRequest): Promise<ResponseLike> {\n\t\t// Generalize the endpoint to its route data\n\t\tconst routeId = REST.generateRouteData(request.fullRoute, request.method);\n\t\t// Get the bucket hash for the generic route, or point to a global route otherwise\n\t\tconst hash = this.hashes.get(`${request.method}:${routeId.bucketRoute}`) ?? {\n\t\t\tvalue: `Global(${request.method}:${routeId.bucketRoute})`,\n\t\t\tlastAccess: -1,\n\t\t};\n\n\t\t// Get the request handler for the obtained hash, with its major parameter\n\t\tconst handler =\n\t\t\tthis.handlers.get(`${hash.value}:${routeId.majorParameter}`) ??\n\t\t\tthis.createHandler(hash.value, routeId.majorParameter);\n\n\t\t// Resolve the request into usable fetch options\n\t\tconst { url, fetchOptions } = await this.resolveRequest(request);\n\n\t\t// Queue the request\n\t\treturn handler.queueRequest(routeId, url, fetchOptions, {\n\t\t\tbody: request.body,\n\t\t\tfiles: request.files,\n\t\t\tauth: request.auth !== false,\n\t\t\tsignal: request.signal,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a new rate limit handler from a hash, based on the hash and the major parameter\n\t *\n\t * @param hash - The hash for the route\n\t * @param majorParameter - The major parameter for this handler\n\t * @internal\n\t */\n\tprivate createHandler(hash: string, majorParameter: string) {\n\t\t// Create the async request queue to handle requests\n\t\tconst queue =\n\t\t\tmajorParameter === BurstHandlerMajorIdKey\n\t\t\t\t? new BurstHandler(this, hash, majorParameter)\n\t\t\t\t: new SequentialHandler(this, hash, majorParameter);\n\t\t// Save the queue based on its id\n\t\tthis.handlers.set(queue.id, queue);\n\n\t\treturn queue;\n\t}\n\n\t/**\n\t * Formats the request data to a usable format for fetch\n\t *\n\t * @param request - The request data\n\t */\n\tprivate async resolveRequest(request: InternalRequest): Promise<{ fetchOptions: RequestInit; url: string }> {\n\t\tconst { options } = this;\n\n\t\tlet query = '';\n\n\t\t// If a query option is passed, use it\n\t\tif (request.query) {\n\t\t\tconst resolvedQuery = request.query.toString();\n\t\t\tif (resolvedQuery !== '') {\n\t\t\t\tquery = `?${resolvedQuery}`;\n\t\t\t}\n\t\t}\n\n\t\t// Create the required headers\n\t\tconst headers: RequestHeaders = {\n\t\t\t...this.options.headers,\n\t\t\t'User-Agent': `${DefaultUserAgent} ${options.userAgentAppendix}`.trim(),\n\t\t};\n\n\t\t// If this request requires authorization (allowing non-\"authorized\" requests for webhooks)\n\t\tif (request.auth !== false) {\n\t\t\t// If we haven't received a token, throw an error\n\t\t\tif (!this.#token) {\n\t\t\t\tthrow new Error('Expected token to be set for this request, but none was present');\n\t\t\t}\n\n\t\t\theaders.Authorization = `${request.authPrefix ?? this.options.authPrefix} ${this.#token}`;\n\t\t}\n\n\t\t// If a reason was set, set it's appropriate header\n\t\tif (request.reason?.length) {\n\t\t\theaders['X-Audit-Log-Reason'] = encodeURIComponent(request.reason);\n\t\t}\n\n\t\t// Format the full request URL (api base, optional version, endpoint, optional querystring)\n\t\tconst url = `${options.api}${request.versioned === false ? '' : `/v${options.version}`}${\n\t\t\trequest.fullRoute\n\t\t}${query}`;\n\n\t\tlet finalBody: RequestInit['body'];\n\t\tlet additionalHeaders: Record<string, string> = {};\n\n\t\tif (request.files?.length) {\n\t\t\tconst formData = new FormData();\n\n\t\t\t// Attach all files to the request\n\t\t\tfor (const [index, file] of request.files.entries()) {\n\t\t\t\tconst fileKey = file.key ?? `files[${index}]`;\n\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#parameters\n\t\t\t\t// FormData.append only accepts a string or Blob.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters\n\t\t\t\t// The Blob constructor accepts TypedArray/ArrayBuffer, strings, and Blobs.\n\t\t\t\tif (isBufferLike(file.data)) {\n\t\t\t\t\t// Try to infer the content type from the buffer if one isn't passed\n\t\t\t\t\tlet contentType = file.contentType;\n\n\t\t\t\t\tif (!contentType) {\n\t\t\t\t\t\tconst [parsedType] = filetypeinfo(file.data);\n\n\t\t\t\t\t\tif (parsedType) {\n\t\t\t\t\t\t\tcontentType =\n\t\t\t\t\t\t\t\tOverwrittenMimeTypes[parsedType.mime as keyof typeof OverwrittenMimeTypes] ??\n\t\t\t\t\t\t\t\tparsedType.mime ??\n\t\t\t\t\t\t\t\t'application/octet-stream';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tformData.append(fileKey, new Blob([file.data], { type: contentType }), file.name);\n\t\t\t\t} else {\n\t\t\t\t\tformData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If a JSON body was added as well, attach it to the form data, using payload_json unless otherwise specified\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t\tif (request.body != null) {\n\t\t\t\tif (request.appendToFormData) {\n\t\t\t\t\tfor (const [key, value] of Object.entries(request.body as Record<string, unknown>)) {\n\t\t\t\t\t\tformData.append(key, value);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tformData.append('payload_json', JSON.stringify(request.body));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Set the final body to the form data\n\t\t\tfinalBody = formData;\n\n\t\t\t// eslint-disable-next-line no-eq-null, eqeqeq\n\t\t} else if (request.body != null) {\n\t\t\tif (request.passThroughBody) {\n\t\t\t\tfinalBody = request.body as BodyInit;\n\t\t\t} else {\n\t\t\t\t// Stringify the JSON data\n\t\t\t\tfinalBody = JSON.stringify(request.body);\n\t\t\t\t// Set the additional headers to specify the content-type\n\t\t\t\tadditionalHeaders = { 'Content-Type': 'application/json' };\n\t\t\t}\n\t\t}\n\n\t\tconst method = request.method.toUpperCase();\n\n\t\t// The non null assertions in the following block are due to exactOptionalPropertyTypes, they have been tested to work with undefined\n\t\tconst fetchOptions: RequestInit = {\n\t\t\t// Set body to null on get / head requests. This does not follow fetch spec (likely because it causes subtle bugs) but is aligned with what request was doing\n\t\t\tbody: ['GET', 'HEAD'].includes(method) ? null : finalBody!,\n\t\t\theaders: { ...request.headers, ...additionalHeaders, ...headers } as Record<string, string>,\n\t\t\tmethod,\n\t\t\t// Prioritize setting an agent per request, use the agent for this instance otherwise.\n\t\t\tdispatcher: request.dispatcher ?? this.agent ?? undefined!,\n\t\t};\n\n\t\treturn { url, fetchOptions };\n\t}\n\n\t/**\n\t * Stops the hash sweeping interval\n\t */\n\tpublic clearHashSweeper() {\n\t\tclearInterval(this.hashTimer);\n\t}\n\n\t/**\n\t * Stops the request handler sweeping interval\n\t */\n\tpublic clearHandlerSweeper() {\n\t\tclearInterval(this.handlerTimer);\n\t}\n\n\t/**\n\t * Generates route data for an endpoint:method\n\t *\n\t * @param endpoint - The raw endpoint to generalize\n\t * @param method - The HTTP method this endpoint is called without\n\t * @internal\n\t */\n\tprivate static generateRouteData(endpoint: RouteLike, method: RequestMethod): RouteData {\n\t\tif (endpoint.startsWith('/interactions/') && endpoint.endsWith('/callback')) {\n\t\t\treturn {\n\t\t\t\tmajorParameter: BurstHandlerMajorIdKey,\n\t\t\t\tbucketRoute: '/interactions/:id/:token/callback',\n\t\t\t\toriginal: endpoint,\n\t\t\t};\n\t\t}\n\n\t\tconst majorIdMatch = /^\\/(?:channels|guilds|webhooks)\\/(\\d{17,19})/.exec(endpoint);\n\n\t\t// Get the major id for this route - global otherwise\n\t\tconst majorId = majorIdMatch?.[1] ?? 'global';\n\n\t\tconst baseRoute = endpoint\n\t\t\t// Strip out all ids\n\t\t\t.replaceAll(/\\d{17,19}/g, ':id')\n\t\t\t// Strip out reaction as they fall under the same bucket\n\t\t\t.replace(/\\/reactions\\/(.*)/, '/reactions/:reaction');\n\n\t\tlet exceptions = '';\n\n\t\t// Hard-Code Old Message Deletion Exception (2 week+ old messages are a different bucket)\n\t\t// https://github.com/discord/discord-api-docs/issues/1295\n\t\tif (method === RequestMethod.Delete && baseRoute === '/channels/:id/messages/:id') {\n\t\t\tconst id = /\\d{17,19}$/.exec(endpoint)![0]!;\n\t\t\tconst timestamp = DiscordSnowflake.timestampFrom(id);\n\t\t\tif (Date.now() - timestamp > 1_000 * 60 * 60 * 24 * 14) {\n\t\t\t\texceptions += '/Delete Old Message';\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tmajorParameter: majorId,\n\t\t\tbucketRoute: baseRoute + exceptions,\n\t\t\toriginal: endpoint,\n\t\t};\n\t}\n}\n","import type { Readable } from 'node:stream';\nimport type { ReadableStream } from 'node:stream/web';\nimport type { Collection } from '@discordjs/collection';\nimport type { Agent, Dispatcher, RequestInit, BodyInit, Response } from 'undici';\nimport type { IHandler } from '../interfaces/Handler.js';\n\nexport interface RestEvents {\n\thandlerSweep: [sweptHandlers: Collection<string, IHandler>];\n\thashSweep: [sweptHashes: Collection<string, HashData>];\n\tinvalidRequestWarning: [invalidRequestInfo: InvalidRequestWarningData];\n\trateLimited: [rateLimitInfo: RateLimitData];\n\tresponse: [request: APIRequest, response: ResponseLike];\n\trestDebug: [info: string];\n}\n\nexport type RestEventsMap = {\n\t[K in keyof RestEvents]: RestEvents[K];\n};\n\n/**\n * Options to be passed when creating the REST instance\n */\nexport interface RESTOptions {\n\t/**\n\t * The agent to set globally\n\t */\n\tagent: Dispatcher | null;\n\t/**\n\t * The base api path, without version\n\t *\n\t * @defaultValue `'https://discord.com/api'`\n\t */\n\tapi: string;\n\t/**\n\t * The authorization prefix to use for requests, useful if you want to use\n\t * bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix: 'Bearer' | 'Bot';\n\t/**\n\t * The cdn path\n\t *\n\t * @defaultValue `'https://cdn.discordapp.com'`\n\t */\n\tcdn: string;\n\t/**\n\t * How many requests to allow sending per second (Infinity for unlimited, 50 for the standard global limit used by Discord)\n\t *\n\t * @defaultValue `50`\n\t */\n\tglobalRequestsPerSecond: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 1h)\n\t *\n\t * @defaultValue `3_600_000`\n\t */\n\thandlerSweepInterval: number;\n\t/**\n\t * The maximum amount of time a hash can exist in milliseconds without being hit with a request (defaults to 24h)\n\t *\n\t * @defaultValue `86_400_000`\n\t */\n\thashLifetime: number;\n\t/**\n\t * The amount of time in milliseconds that passes between each hash sweep. (defaults to 4h)\n\t *\n\t * @defaultValue `14_400_000`\n\t */\n\thashSweepInterval: number;\n\t/**\n\t * Additional headers to send for all API requests\n\t *\n\t * @defaultValue `{}`\n\t */\n\theaders: Record<string, string>;\n\t/**\n\t * The number of invalid REST requests (those that return 401, 403, or 429) in a 10 minute window between emitted warnings (0 for no warnings).\n\t * That is, if set to 500, warnings will be emitted at invalid request number 500, 1000, 1500, and so on.\n\t *\n\t * @defaultValue `0`\n\t */\n\tinvalidRequestWarningInterval: number;\n\t/**\n\t * The method called to perform the actual HTTP request given a url and web `fetch` options\n\t * For example, to use global fetch, simply provide `makeRequest: fetch`\n\t */\n\tmakeRequest(url: string, init: RequestInit): Promise<ResponseLike>;\n\t/**\n\t * The extra offset to add to rate limits in milliseconds\n\t *\n\t * @defaultValue `50`\n\t */\n\toffset: number;\n\t/**\n\t * Determines how rate limiting and pre-emptive throttling should be handled.\n\t * When an array of strings, each element is treated as a prefix for the request route\n\t * (e.g. `/channels` to match any route starting with `/channels` such as `/channels/:id/messages`)\n\t * for which to throw {@link RateLimitError}s. All other request routes will be queued normally\n\t *\n\t * @defaultValue `null`\n\t */\n\trejectOnRateLimit: RateLimitQueueFilter | string[] | null;\n\t/**\n\t * The number of retries for errors with the 500 code, or errors\n\t * that timeout\n\t *\n\t * @defaultValue `3`\n\t */\n\tretries: number;\n\t/**\n\t * The time to wait in milliseconds before a request is aborted\n\t *\n\t * @defaultValue `15_000`\n\t */\n\ttimeout: number;\n\t/**\n\t * Extra information to add to the user agent\n\t *\n\t * @defaultValue DefaultUserAgentAppendix\n\t */\n\tuserAgentAppendix: string;\n\t/**\n\t * The version of the API to use\n\t *\n\t * @defaultValue `'10'`\n\t */\n\tversion: string;\n}\n\n/**\n * Data emitted on `RESTEvents.RateLimited`\n */\nexport interface RateLimitData {\n\t/**\n\t * Whether the rate limit that was reached was the global limit\n\t */\n\tglobal: boolean;\n\t/**\n\t * The bucket hash for this request\n\t */\n\thash: string;\n\t/**\n\t * The amount of requests we can perform before locking requests\n\t */\n\tlimit: number;\n\t/**\n\t * The major parameter of the route\n\t *\n\t * For example, in `/channels/x`, this will be `x`.\n\t * If there is no major parameter (e.g: `/bot/gateway`) this will be `global`.\n\t */\n\tmajorParameter: string;\n\t/**\n\t * The HTTP method being performed\n\t */\n\tmethod: string;\n\t/**\n\t * The route being hit in this request\n\t */\n\troute: string;\n\t/**\n\t * The time, in milliseconds, until the request-lock is reset\n\t */\n\ttimeToReset: number;\n\t/**\n\t * The full URL for this request\n\t */\n\turl: string;\n}\n\n/**\n * A function that determines whether the rate limit hit should throw an Error\n */\nexport type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Promise<boolean> | boolean;\n\nexport interface APIRequest {\n\t/**\n\t * The data that was used to form the body of this request\n\t */\n\tdata: HandlerRequestData;\n\t/**\n\t * The HTTP method used in this request\n\t */\n\tmethod: string;\n\t/**\n\t * Additional HTTP options for this request\n\t */\n\toptions: RequestInit;\n\t/**\n\t * The full path used to make the request\n\t */\n\tpath: RouteLike;\n\t/**\n\t * The number of times this request has been attempted\n\t */\n\tretries: number;\n\t/**\n\t * The API route identifying the ratelimit for this request\n\t */\n\troute: string;\n}\n\nexport interface ResponseLike\n\textends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {\n\tbody: Readable | ReadableStream | null;\n}\n\nexport interface InvalidRequestWarningData {\n\t/**\n\t * Number of invalid requests that have been made in the window\n\t */\n\tcount: number;\n\t/**\n\t * Time in milliseconds remaining before the count resets\n\t */\n\tremainingTime: number;\n}\n\n/**\n * Represents a file to be added to the request\n */\nexport interface RawFile {\n\t/**\n\t * Content-Type of the file\n\t */\n\tcontentType?: string;\n\t/**\n\t * The actual data for the file\n\t */\n\tdata: Buffer | Uint8Array | boolean | number | string;\n\t/**\n\t * An explicit key to use for key of the formdata field for this file.\n\t * When not provided, the index of the file in the files array is used in the form `files[${index}]`.\n\t * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`)\n\t */\n\tkey?: string;\n\t/**\n\t * The name of the file\n\t */\n\tname: string;\n}\n\n/**\n * Represents possible data to be given to an endpoint\n */\nexport interface RequestData {\n\t/**\n\t * Whether to append JSON data to form data instead of `payload_json` when sending files\n\t */\n\tappendToFormData?: boolean;\n\t/**\n\t * If this request needs the `Authorization` header\n\t *\n\t * @defaultValue `true`\n\t */\n\tauth?: boolean;\n\t/**\n\t * The authorization prefix to use for this request, useful if you use this with bearer tokens\n\t *\n\t * @defaultValue `'Bot'`\n\t */\n\tauthPrefix?: 'Bearer' | 'Bot';\n\t/**\n\t * The body to send to this request.\n\t * If providing as BodyInit, set `passThroughBody: true`\n\t */\n\tbody?: BodyInit | unknown;\n\t/**\n\t * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.\n\t */\n\tdispatcher?: Agent;\n\t/**\n\t * Files to be attached to this request\n\t */\n\tfiles?: RawFile[] | undefined;\n\t/**\n\t * Additional headers to add to this request\n\t */\n\theaders?: Record<string, string>;\n\t/**\n\t * Whether to pass-through the body property directly to `fetch()`.\n\t * <warn>This only applies when files is NOT present</warn>\n\t */\n\tpassThroughBody?: boolean;\n\t/**\n\t * Query string parameters to append to the called endpoint\n\t */\n\tquery?: URLSearchParams;\n\t/**\n\t * Reason to show in the audit logs\n\t */\n\treason?: string | undefined;\n\t/**\n\t * The signal to abort the queue entry or the REST call, where applicable\n\t */\n\tsignal?: AbortSignal | undefined;\n\t/**\n\t * If this request should be versioned\n\t *\n\t * @defaultValue `true`\n\t */\n\tversioned?: boolean;\n}\n\n/**\n * Possible headers for an API call\n */\nexport interface RequestHeaders {\n\tAuthorization?: string;\n\t'User-Agent': string;\n\t'X-Audit-Log-Reason'?: string;\n}\n\n/**\n * Possible API methods to be used when doing requests\n */\nexport enum RequestMethod {\n\tDelete = 'DELETE',\n\tGet = 'GET',\n\tPatch = 'PATCH',\n\tPost = 'POST',\n\tPut = 'PUT',\n}\n\nexport type RouteLike = `/${string}`;\n\n/**\n * Internal request options\n *\n * @internal\n */\nexport interface InternalRequest extends RequestData {\n\tfullRoute: RouteLike;\n\tmethod: RequestMethod;\n}\n\nexport type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;\n\n/**\n * Parsed route data for an endpoint\n *\n * @internal\n */\nexport interface RouteData {\n\tbucketRoute: string;\n\tmajorParameter: string;\n\toriginal: RouteLike;\n}\n\n/**\n * Represents a hash and its associated fields\n *\n * @internal\n */\nexport interface HashData {\n\tlastAccess: number;\n\tvalue: string;\n}\n","import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';\nimport type { REST } from '../REST.js';\nimport { RateLimitError } from '../errors/RateLimitError.js';\nimport { RequestMethod, type RateLimitData, type ResponseLike } from './types.js';\n\nfunction serializeSearchParam(value: unknown): string | null {\n\tswitch (typeof value) {\n\t\tcase 'string':\n\t\t\treturn value;\n\t\tcase 'number':\n\t\tcase 'bigint':\n\t\tcase 'boolean':\n\t\t\treturn value.toString();\n\t\tcase 'object':\n\t\t\tif (value === null) return null;\n\t\t\tif (value instanceof Date) {\n\t\t\t\treturn Number.isNaN(value.getTime()) ? null : value.toISOString();\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) return value.toString();\n\t\t\treturn null;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n/**\n * Creates and populates an URLSearchParams instance from an object, stripping\n * out null and undefined values, while also coercing non-strings to strings.\n *\n * @param options - The options to use\n * @returns A populated URLSearchParams instance\n */\nexport function makeURLSearchParams<T extends object>(options?: Readonly<T>) {\n\tconst params = new URLSearchParams();\n\tif (!options) return params;\n\n\tfor (const [key, value] of Object.entries(options)) {\n\t\tconst serialized = serializeSearchParam(value);\n\t\tif (serialized !== null) params.append(key, serialized);\n\t}\n\n\treturn params;\n}\n\n/**\n * Converts the response to usable data\n *\n * @param res - The fetch response\n */\nexport async function parseResponse(res: ResponseLike): Promise<unknown> {\n\tif (res.headers.get('Content-Type')?.startsWith('application/json')) {\n\t\treturn res.json();\n\t}\n\n\treturn res.arrayBuffer();\n}\n\n/**\n * Check whether a request falls under a sublimit\n *\n * @param bucketRoute - The buckets route identifier\n * @param body - The options provided as JSON data\n * @param method - The HTTP method that will be used to make the request\n * @returns Whether the request falls under a sublimit\n */\nexport function hasSublimit(bucketRoute: string, body?: unknown, method?: string): boolean {\n\t// TODO: Update for new sublimits\n\t// Currently known sublimits:\n\t// Editing channel `name` or `topic`\n\tif (bucketRoute === '/channels/:id') {\n\t\tif (typeof body !== 'object' || body === null) return false;\n\t\t// This should never be a POST body, but just in case\n\t\tif (method !== RequestMethod.Patch) return false;\n\t\tconst castedBody = body as RESTPatchAPIChannelJSONBody;\n\t\treturn ['name', 'topic'].some((key) => Reflect.has(castedBody, key));\n\t}\n\n\t// If we are checking if a request has a sublimit on a route not checked above, sublimit all requests to avoid a flood of 429s\n\treturn true;\n}\n\n/**\n * Check whether an error indicates that a retry can be attempted\n *\n * @param error - The error thrown by the network request\n * @returns Whether the error indicates a retry should be attempted\n */\nexport function shouldRetry(error: Error | NodeJS.ErrnoException) {\n\t// Retry for possible timed out requests\n\tif (error.name === 'AbortError') return true;\n\t// Downlevel ECONNRESET to retry as it may be recoverable\n\treturn ('code' in error && error.code === 'ECONNRESET') || error.message.includes('ECONNRESET');\n}\n\n/**\n * Determines whether the request should be queued or whether a RateLimitError should be thrown\n *\n * @internal\n */\nexport async function onRateLimit(manager: REST, rateLimitData: RateLimitData) {\n\tconst { options } = manager;\n\tif (!options.rejectOnRateLimit) return;\n\n\tconst shouldThrow =\n\t\ttypeof options.rejectOnRateLimit === 'function'\n\t\t\t? await options.rejectOnRateLimit(rateLimitData)\n\t\t\t: options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));\n\tif (shouldThrow) {\n\t\tthrow new RateLimitError(rateLimitData);\n\t}\n}\n\n/**\n * Calculates the default avatar index for a given user id.\n *\n * @param userId - The user id to calculate the default avatar index for\n */\nexport function calculateUserDefaultAvatarIndex(userId: Snowflake) {\n\treturn Number(BigInt(userId) >> 22n) % 6;\n}\n\n/**\n * Sleeps for a given amount of time.\n *\n * @param ms - The amount of time (in milliseconds) to sleep for\n */\nexport async function sleep(ms: number): Promise<void> {\n\treturn new Promise<void>((resolve) => {\n\t\tsetTimeout(() => resolve(), ms);\n\t});\n}\n\n/**\n * Verifies that a value is a buffer-like object.\n *\n * @param value - The value to check\n */\nexport function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Uint8Array | Uint8ClampedArray {\n\treturn value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError.js';\nimport { DiscordAPIError } from '../errors/DiscordAPIError.js';\nimport { HTTPError } from '../errors/HTTPError.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { parseResponse, shouldRetry } from '../utils/utils.js';\n\n/**\n * Invalid request limiting is done on a per-IP basis, not a per-token basis.\n * The best we can do is track invalid counts process-wide (on the theory that\n * users could have multiple bots run from one process) rather than per-bot.\n * Therefore, store these at file scope here rather than in the client's\n * RESTManager object.\n */\nlet invalidCount = 0;\nlet invalidCountResetTime: number | null = null;\n\n/**\n * Increment the invalid request count and emit warning if necessary\n *\n * @internal\n */\nexport function incrementInvalidCount(manager: REST) {\n\tif (!invalidCountResetTime || invalidCountResetTime < Date.now()) {\n\t\tinvalidCountResetTime = Date.now() + 1_000 * 60 * 10;\n\t\tinvalidCount = 0;\n\t}\n\n\tinvalidCount++;\n\n\tconst emitInvalid =\n\t\tmanager.options.invalidRequestWarningInterval > 0 &&\n\t\tinvalidCount % manager.options.invalidRequestWarningInterval === 0;\n\tif (emitInvalid) {\n\t\t// Let library users know periodically about invalid requests\n\t\tmanager.emit(RESTEvents.InvalidRequestWarning, {\n\t\t\tcount: invalidCount,\n\t\t\tremainingTime: invalidCountResetTime - Date.now(),\n\t\t});\n\t}\n}\n\n/**\n * Performs the actual network request for a request handler\n *\n * @param manager - The manager that holds options and emits informational events\n * @param routeId - The generalized api route with literal ids for major parameters\n * @param url - The fully resolved url to make the request to\n * @param options - The fetch options needed to make the request\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns The respond from the network or `null` when the request should be retried\n * @internal\n */\nexport async function makeNetworkRequest(\n\tmanager: REST,\n\trouteId: RouteData,\n\turl: string,\n\toptions: RequestInit,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst controller = new AbortController();\n\tconst timeout = setTimeout(() => controller.abort(), manager.options.timeout);\n\tif (requestData.signal) {\n\t\t// If the user signal was aborted, abort the controller, else abort the local signal.\n\t\t// The reason why we don't re-use the user's signal, is because users may use the same signal for multiple\n\t\t// requests, and we do not want to cause unexpected side-effects.\n\t\tif (requestData.signal.aborted) controller.abort();\n\t\telse requestData.signal.addEventListener('abort', () => controller.abort());\n\t}\n\n\tlet res: ResponseLike;\n\ttry {\n\t\tres = await manager.options.makeRequest(url, { ...options, signal: controller.signal });\n\t} catch (error: unknown) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\t// Retry the specified number of times if needed\n\t\tif (shouldRetry(error) && retries !== manager.options.retries) {\n\t\t\t// Retry is handled by the handler upon receiving null\n\t\t\treturn null;\n\t\t}\n\n\t\tthrow error;\n\t} finally {\n\t\tclearTimeout(timeout);\n\t}\n\n\tif (manager.listenerCount(RESTEvents.Response)) {\n\t\tmanager.emit(\n\t\t\tRESTEvents.Response,\n\t\t\t{\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\tpath: routeId.original,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\toptions,\n\t\t\t\tdata: requestData,\n\t\t\t\tretries,\n\t\t\t},\n\t\t\tres instanceof Response ? res.clone() : { ...res },\n\t\t);\n\t}\n\n\treturn res;\n}\n\n/**\n * Handles 5xx and 4xx errors (not 429's) conventionally. 429's should be handled before calling this function\n *\n * @param manager - The manager that holds options and emits informational events\n * @param res - The response received from {@link makeNetworkRequest}\n * @param method - The method used to make the request\n * @param url - The fully resolved url to make the request to\n * @param requestData - Extra data from the user's request needed for errors and additional processing\n * @param retries - The number of retries this request has already attempted (recursion occurs on the handler)\n * @returns - The response if the status code is not handled or null to request a retry\n */\nexport async function handleErrors(\n\tmanager: REST,\n\tres: ResponseLike,\n\tmethod: string,\n\turl: string,\n\trequestData: HandlerRequestData,\n\tretries: number,\n) {\n\tconst status = res.status;\n\tif (status >= 500 && status < 600) {\n\t\t// Retry the specified number of times for possible server side issues\n\t\tif (retries !== manager.options.retries) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We are out of retries, throw an error\n\t\tthrow new HTTPError(status, res.statusText, method, url, requestData);\n\t} else {\n\t\t// Handle possible malformed requests\n\t\tif (status >= 400 && status < 500) {\n\t\t\t// If we receive this status code, it means the token we had is no longer valid.\n\t\t\tif (status === 401 && requestData.auth) {\n\t\t\t\tmanager.setToken(null!);\n\t\t\t}\n\n\t\t\t// The request will not succeed for some reason, parse the error returned from the api\n\t\t\tconst data = (await parseResponse(res)) as DiscordErrorData | OAuthErrorData;\n\t\t\t// throw the API error\n\t\t\tthrow new DiscordAPIError(data, 'code' in data ? data.code : data.error, status, method, url, requestData);\n\t\t}\n\n\t\treturn res;\n\t}\n}\n","import type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\n/**\n * The structure used to handle burst requests for a given bucket.\n * Burst requests have no ratelimit handling but allow for pre- and post-processing\n * of data in the same manner as sequentially queued requests.\n *\n * @remarks\n * This queue may still emit a rate limit error if an unexpected 429 is hit\n */\nexport class BurstHandler implements IHandler {\n\t/**\n\t * {@inheritdoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic inactive = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\treturn this.runRequest(routeId, url, options, requestData);\n\t}\n\n\t/**\n\t * The method that actually makes the request to the API, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized API route with literal ids for major parameters\n\t * @param url - The fully resolved URL to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (status >= 200 && status < 300) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// Unexpected ratelimit\n\t\t\tconst isGlobal = res.headers.has('X-RateLimit-Global');\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: retryAfter,\n\t\t\t\tlimit: Number.POSITIVE_INFINITY,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${Number.POSITIVE_INFINITY}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : None`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\n\t\t\t// We are bypassing all other limits, but an encountered limit should be respected (it's probably a non-punished rate limit anyways)\n\t\t\tawait sleep(retryAfter);\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","import { AsyncQueue } from '@sapphire/async-queue';\nimport type { RequestInit } from 'undici';\nimport type { REST } from '../REST.js';\nimport type { IHandler } from '../interfaces/Handler.js';\nimport { RESTEvents } from '../utils/constants.js';\nimport type { RateLimitData, ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';\nimport { hasSublimit, onRateLimit, sleep } from '../utils/utils.js';\nimport { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';\n\nconst enum QueueType {\n\tStandard,\n\tSublimit,\n}\n\n/**\n * The structure used to handle sequential requests for a given bucket\n */\nexport class SequentialHandler implements IHandler {\n\t/**\n\t * {@inheritDoc IHandler.id}\n\t */\n\tpublic readonly id: string;\n\n\t/**\n\t * The time this rate limit bucket will reset\n\t */\n\tprivate reset = -1;\n\n\t/**\n\t * The remaining requests that can be made before we are rate limited\n\t */\n\tprivate remaining = 1;\n\n\t/**\n\t * The total number of requests that can be made before we are rate limited\n\t */\n\tprivate limit = Number.POSITIVE_INFINITY;\n\n\t/**\n\t * The interface used to sequence async requests sequentially\n\t */\n\t#asyncQueue = new AsyncQueue();\n\n\t/**\n\t * The interface used to sequence sublimited async requests sequentially\n\t */\n\t#sublimitedQueue: AsyncQueue | null = null;\n\n\t/**\n\t * A promise wrapper for when the sublimited queue is finished being processed or null when not being processed\n\t */\n\t#sublimitPromise: { promise: Promise<void>; resolve(): void } | null = null;\n\n\t/**\n\t * Whether the sublimit queue needs to be shifted in the finally block\n\t */\n\t#shiftSublimit = false;\n\n\t/**\n\t * @param manager - The request manager\n\t * @param hash - The hash that this RequestHandler handles\n\t * @param majorParameter - The major parameter for this handler\n\t */\n\tpublic constructor(\n\t\tprivate readonly manager: REST,\n\t\tprivate readonly hash: string,\n\t\tprivate readonly majorParameter: string,\n\t) {\n\t\tthis.id = `${hash}:${majorParameter}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.inactive}\n\t */\n\tpublic get inactive(): boolean {\n\t\treturn (\n\t\t\tthis.#asyncQueue.remaining === 0 &&\n\t\t\t(this.#sublimitedQueue === null || this.#sublimitedQueue.remaining === 0) &&\n\t\t\t!this.limited\n\t\t);\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by the global limit\n\t */\n\tprivate get globalLimited(): boolean {\n\t\treturn this.manager.globalRemaining <= 0 && Date.now() < this.manager.globalReset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited by its limit\n\t */\n\tprivate get localLimited(): boolean {\n\t\treturn this.remaining <= 0 && Date.now() < this.reset;\n\t}\n\n\t/**\n\t * If the rate limit bucket is currently limited\n\t */\n\tprivate get limited(): boolean {\n\t\treturn this.globalLimited || this.localLimited;\n\t}\n\n\t/**\n\t * The time until queued requests can continue\n\t */\n\tprivate get timeToReset(): number {\n\t\treturn this.reset + this.manager.options.offset - Date.now();\n\t}\n\n\t/**\n\t * Emits a debug message\n\t *\n\t * @param message - The message to debug\n\t */\n\tprivate debug(message: string) {\n\t\tthis.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);\n\t}\n\n\t/**\n\t * Delay all requests for the specified amount of time, handling global rate limits\n\t *\n\t * @param time - The amount of time to delay all requests for\n\t */\n\tprivate async globalDelayFor(time: number): Promise<void> {\n\t\tawait sleep(time);\n\t\tthis.manager.globalDelay = null;\n\t}\n\n\t/**\n\t * {@inheritDoc IHandler.queueRequest}\n\t */\n\tpublic async queueRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t): Promise<ResponseLike> {\n\t\tlet queue = this.#asyncQueue;\n\t\tlet queueType = QueueType.Standard;\n\t\t// Separate sublimited requests when already sublimited\n\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\tqueueType = QueueType.Sublimit;\n\t\t}\n\n\t\t// Wait for any previous requests to be completed before this one is run\n\t\tawait queue.wait({ signal: requestData.signal });\n\t\t// This set handles retroactively sublimiting requests\n\t\tif (queueType === QueueType.Standard) {\n\t\t\tif (this.#sublimitedQueue && hasSublimit(routeId.bucketRoute, requestData.body, options.method)) {\n\t\t\t\t/**\n\t\t\t\t * Remove the request from the standard queue, it should never be possible to get here while processing the\n\t\t\t\t * sublimit queue so there is no need to worry about shifting the wrong request\n\t\t\t\t */\n\t\t\t\tqueue = this.#sublimitedQueue!;\n\t\t\t\tconst wait = queue.wait();\n\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\tawait wait;\n\t\t\t} else if (this.#sublimitPromise) {\n\t\t\t\t// Stall requests while the sublimit queue gets processed\n\t\t\t\tawait this.#sublimitPromise.promise;\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request, and return the results\n\t\t\treturn await this.runRequest(routeId, url, options, requestData);\n\t\t} finally {\n\t\t\t// Allow the next request to fire\n\t\t\tqueue.shift();\n\t\t\tif (this.#shiftSublimit) {\n\t\t\t\tthis.#shiftSublimit = false;\n\t\t\t\tthis.#sublimitedQueue?.shift();\n\t\t\t}\n\n\t\t\t// If this request is the last request in a sublimit\n\t\t\tif (this.#sublimitedQueue?.remaining === 0) {\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitedQueue = null;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The method that actually makes the request to the api, and updates info about the bucket accordingly\n\t *\n\t * @param routeId - The generalized api route with literal ids for major parameters\n\t * @param url - The fully resolved url to make the request to\n\t * @param options - The fetch options needed to make the request\n\t * @param requestData - Extra data from the user's request needed for errors and additional processing\n\t * @param retries - The number of retries this request has already attempted (recursion)\n\t */\n\tprivate async runRequest(\n\t\trouteId: RouteData,\n\t\turl: string,\n\t\toptions: RequestInit,\n\t\trequestData: HandlerRequestData,\n\t\tretries = 0,\n\t): Promise<ResponseLike> {\n\t\t/*\n\t\t * After calculations have been done, pre-emptively stop further requests\n\t\t * Potentially loop until this task can run if e.g. the global rate limit is hit twice\n\t\t */\n\t\twhile (this.limited) {\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\t\t\tlet delay: Promise<void>;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t\t// If this is the first task to reach the global timeout, set the global delay\n\t\t\t\tif (!this.manager.globalDelay) {\n\t\t\t\t\t// The global delay function clears the global delay state when it is resolved\n\t\t\t\t\tthis.manager.globalDelay = this.globalDelayFor(timeout);\n\t\t\t\t}\n\n\t\t\t\tdelay = this.manager.globalDelay;\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t\tdelay = sleep(timeout);\n\t\t\t}\n\n\t\t\tconst rateLimitData: RateLimitData = {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod: options.method ?? 'get',\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t};\n\t\t\t// Let library users know they have hit a rate limit\n\t\t\tthis.manager.emit(RESTEvents.RateLimited, rateLimitData);\n\t\t\t// Determine whether a RateLimitError should be thrown\n\t\t\tawait onRateLimit(this.manager, rateLimitData);\n\t\t\t// When not erroring, emit debug for what is happening\n\t\t\tif (isGlobal) {\n\t\t\t\tthis.debug(`Global rate limit hit, blocking all requests for ${timeout}ms`);\n\t\t\t} else {\n\t\t\t\tthis.debug(`Waiting ${timeout}ms for rate limit to pass`);\n\t\t\t}\n\n\t\t\t// Wait the remaining time left before the rate limit resets\n\t\t\tawait delay;\n\t\t}\n\n\t\t// As the request goes out, update the global usage information\n\t\tif (!this.manager.globalReset || this.manager.globalReset < Date.now()) {\n\t\t\tthis.manager.globalReset = Date.now() + 1_000;\n\t\t\tthis.manager.globalRemaining = this.manager.options.globalRequestsPerSecond;\n\t\t}\n\n\t\tthis.manager.globalRemaining--;\n\n\t\tconst method = options.method ?? 'get';\n\n\t\tconst res = await makeNetworkRequest(this.manager, routeId, url, options, requestData, retries);\n\n\t\t// Retry requested\n\t\tif (res === null) {\n\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t}\n\n\t\tconst status = res.status;\n\t\tlet retryAfter = 0;\n\n\t\tconst limit = res.headers.get('X-RateLimit-Limit');\n\t\tconst remaining = res.headers.get('X-RateLimit-Remaining');\n\t\tconst reset = res.headers.get('X-RateLimit-Reset-After');\n\t\tconst hash = res.headers.get('X-RateLimit-Bucket');\n\t\tconst retry = res.headers.get('Retry-After');\n\n\t\t// Update the total number of requests that can be made before the rate limit resets\n\t\tthis.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY;\n\t\t// Update the number of remaining requests that can be made before the rate limit resets\n\t\tthis.remaining = remaining ? Number(remaining) : 1;\n\t\t// Update the time when this rate limit resets (reset-after is in seconds)\n\t\tthis.reset = reset ? Number(reset) * 1_000 + Date.now() + this.manager.options.offset : Date.now();\n\n\t\t// Amount of time in milliseconds until we should retry if rate limited (globally or otherwise)\n\t\tif (retry) retryAfter = Number(retry) * 1_000 + this.manager.options.offset;\n\n\t\t// Handle buckets via the hash header retroactively\n\t\tif (hash && hash !== this.hash) {\n\t\t\t// Let library users know when rate limit buckets have been updated\n\t\t\tthis.debug(['Received bucket hash update', ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join('\\n'));\n\t\t\t// This queue will eventually be eliminated via attrition\n\t\t\tthis.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() });\n\t\t} else if (hash) {\n\t\t\t// Handle the case where hash value doesn't change\n\t\t\t// Fetch the hash data from the manager\n\t\t\tconst hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`);\n\n\t\t\t// When fetched, update the last access of the hash\n\t\t\tif (hashData) {\n\t\t\t\thashData.lastAccess = Date.now();\n\t\t\t}\n\t\t}\n\n\t\t// Handle retryAfter, which means we have actually hit a rate limit\n\t\tlet sublimitTimeout: number | null = null;\n\t\tif (retryAfter > 0) {\n\t\t\tif (res.headers.has('X-RateLimit-Global')) {\n\t\t\t\tthis.manager.globalRemaining = 0;\n\t\t\t\tthis.manager.globalReset = Date.now() + retryAfter;\n\t\t\t} else if (!this.localLimited) {\n\t\t\t\t/*\n\t\t\t\t * This is a sublimit (e.g. 2 channel name changes/10 minutes) since the headers don't indicate a\n\t\t\t\t * route-wide rate limit. Don't update remaining or reset to avoid rate limiting the whole\n\t\t\t\t * endpoint, just set a reset time on the request itself to avoid retrying too soon.\n\t\t\t\t */\n\t\t\t\tsublimitTimeout = retryAfter;\n\t\t\t}\n\t\t}\n\n\t\t// Count the invalid requests\n\t\tif (status === 401 || status === 403 || status === 429) {\n\t\t\tincrementInvalidCount(this.manager);\n\t\t}\n\n\t\tif (res.ok) {\n\t\t\treturn res;\n\t\t} else if (status === 429) {\n\t\t\t// A rate limit was hit - this may happen if the route isn't associated with an official bucket hash yet, or when first globally rate limited\n\t\t\tconst isGlobal = this.globalLimited;\n\t\t\tlet limit: number;\n\t\t\tlet timeout: number;\n\n\t\t\tif (isGlobal) {\n\t\t\t\t// Set RateLimitData based on the global limit\n\t\t\t\tlimit = this.manager.options.globalRequestsPerSecond;\n\t\t\t\ttimeout = this.manager.globalReset + this.manager.options.offset - Date.now();\n\t\t\t} else {\n\t\t\t\t// Set RateLimitData based on the route-specific limit\n\t\t\t\tlimit = this.limit;\n\t\t\t\ttimeout = this.timeToReset;\n\t\t\t}\n\n\t\t\tawait onRateLimit(this.manager, {\n\t\t\t\ttimeToReset: timeout,\n\t\t\t\tlimit,\n\t\t\t\tmethod,\n\t\t\t\thash: this.hash,\n\t\t\t\turl,\n\t\t\t\troute: routeId.bucketRoute,\n\t\t\t\tmajorParameter: this.majorParameter,\n\t\t\t\tglobal: isGlobal,\n\t\t\t});\n\t\t\tthis.debug(\n\t\t\t\t[\n\t\t\t\t\t'Encountered unexpected 429 rate limit',\n\t\t\t\t\t` Global : ${isGlobal.toString()}`,\n\t\t\t\t\t` Method : ${method}`,\n\t\t\t\t\t` URL : ${url}`,\n\t\t\t\t\t` Bucket : ${routeId.bucketRoute}`,\n\t\t\t\t\t` Major parameter: ${routeId.majorParameter}`,\n\t\t\t\t\t` Hash : ${this.hash}`,\n\t\t\t\t\t` Limit : ${limit}`,\n\t\t\t\t\t` Retry After : ${retryAfter}ms`,\n\t\t\t\t\t` Sublimit : ${sublimitTimeout ? `${sublimitTimeout}ms` : 'None'}`,\n\t\t\t\t].join('\\n'),\n\t\t\t);\n\t\t\t// If caused by a sublimit, wait it out here so other requests on the route can be handled\n\t\t\tif (sublimitTimeout) {\n\t\t\t\t// Normally the sublimit queue will not exist, however, if a sublimit is hit while in the sublimit queue, it will\n\t\t\t\tconst firstSublimit = !this.#sublimitedQueue;\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\tthis.#sublimitedQueue = new AsyncQueue();\n\t\t\t\t\tvoid this.#sublimitedQueue.wait();\n\t\t\t\t\tthis.#asyncQueue.shift();\n\t\t\t\t}\n\n\t\t\t\tthis.#sublimitPromise?.resolve();\n\t\t\t\tthis.#sublimitPromise = null;\n\t\t\t\tawait sleep(sublimitTimeout);\n\t\t\t\tlet resolve: () => void;\n\t\t\t\t// eslint-disable-next-line promise/param-names, no-promise-executor-return\n\t\t\t\tconst promise = new Promise<void>((res) => (resolve = res));\n\t\t\t\tthis.#sublimitPromise = { promise, resolve: resolve! };\n\t\t\t\tif (firstSublimit) {\n\t\t\t\t\t// Re-queue this request so it can be shifted by the finally\n\t\t\t\t\tawait this.#asyncQueue.wait();\n\t\t\t\t\tthis.#shiftSublimit = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Since this is not a server side issue, the next request should pass, so we don't bump the retries counter\n\t\t\treturn this.runRequest(routeId, url, options, requestData, retries);\n\t\t} else {\n\t\t\tconst handled = await handleErrors(this.manager, res, method, url, requestData, retries);\n\t\t\tif (handled === null) {\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\treturn this.runRequest(routeId, url, options, requestData, ++retries);\n\t\t\t}\n\n\t\t\treturn handled;\n\t\t}\n\t}\n}\n","export * from './lib/CDN.js';\nexport * from './lib/errors/DiscordAPIError.js';\nexport * from './lib/errors/HTTPError.js';\nexport * from './lib/errors/RateLimitError.js';\nexport * from './lib/REST.js';\nexport * from './lib/utils/constants.js';\nexport * from './lib/utils/types.js';\nexport { calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse } from './lib/utils/utils.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\nexport const version = '2.0.1' as string;\n","import { setDefaultStrategy } from './environment.js';\n\nsetDefaultStrategy(fetch);\n\nexport * from './shared.js';\n"],"mappings":";;;;AAEA,IAAI;AAEG,SAAS,mBAAmB,aAAyC;AAC3E,oBAAkB;AACnB;AAFgB;AAIT,SAAS,qBAAqB;AACpC,SAAO;AACR;AAFgB;;;ACRhB,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAIpB,IAAM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AI,KAAK,IAAI,IAAI,YAAY,MAAQ,KAAK,KAAK,KAAK,IAAI;AACvD,sBAAc;AAAA,MACf;AAAA,IACD;AAEA,WAAO;AAAA,MACN,gBAAgB;AAAA,MAChB,aAAa,YAAY;AAAA,MACzB,UAAU;AAAA,IACX;AAAA,EACD;AACD;;;AMncO,IAAM,UAAU;;;ACZvB,mBAAmB,KAAK;","names":["RESTEvents","RequestMethod","limit","res"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/rest/package.json b/node_modules/@discordjs/rest/package.json new file mode 100644 index 0000000..00092f5 --- /dev/null +++ b/node_modules/@discordjs/rest/package.json @@ -0,0 +1,101 @@ +{ + "name": "@discordjs/rest", + "version": "2.0.1", + "description": "The REST API for discord.js", + "scripts": { + "test": "vitest run", + "build": "tsup", + "build:docs": "tsc -p tsconfig.docs.json", + "lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --format=pretty", + "format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix --format=pretty", + "fmt": "yarn format", + "docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json", + "prepack": "yarn lint && yarn test && yarn build", + "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/rest/*'", + "release": "cliff-jumper" + }, + "types": "./dist/index.d.ts", + "exports": { + ".": { + "node": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "default": { + "types": "./dist/web.d.ts", + "import": "./dist/web.mjs", + "require": "./dist/web.js" + } + }, + "./*": { + "types": "./dist/strategies/*.d.ts", + "import": "./dist/strategies/*.mjs", + "require": "./dist/strategies/*.js" + } + }, + "directories": { + "lib": "src", + "test": "__tests__" + }, + "files": [ + "dist" + ], + "contributors": [ + "Crawl <icrawltogo@gmail.com>", + "Amish Shah <amishshah.2k@gmail.com>", + "SpaceEEC <spaceeec@yahoo.com>", + "Vlad Frangu <kingdgrizzle@gmail.com>", + "Aura Román <kyradiscord@gmail.com>" + ], + "license": "Apache-2.0", + "keywords": [ + "discord", + "api", + "rest", + "discordapp", + "discordjs" + ], + "repository": { + "type": "git", + "url": "https://github.com/discordjs/discord.js.git", + "directory": "packages/rest" + }, + "bugs": { + "url": "https://github.com/discordjs/discord.js/issues" + }, + "homepage": "https://discord.js.org", + "dependencies": { + "@discordjs/collection": "^1.5.3", + "@discordjs/util": "^1.0.1", + "@sapphire/async-queue": "^1.5.0", + "@sapphire/snowflake": "^3.5.1", + "@vladfrangu/async_event_emitter": "^2.2.2", + "discord-api-types": "0.37.50", + "magic-bytes.js": "^1.0.15", + "tslib": "^2.6.1", + "undici": "5.22.1" + }, + "devDependencies": { + "@favware/cliff-jumper": "^2.1.1", + "@microsoft/api-extractor": "^7.36.4", + "@types/node": "18.17.5", + "@vitest/coverage-v8": "^0.34.2", + "cross-env": "^7.0.3", + "esbuild-plugin-version-injector": "^1.2.0", + "eslint": "^8.47.0", + "eslint-config-neon": "^0.1.47", + "eslint-formatter-pretty": "^5.0.0", + "prettier": "^2.8.8", + "tsup": "^7.2.0", + "turbo": "^1.10.12", + "typescript": "^5.1.6", + "vitest": "^0.34.2" + }, + "engines": { + "node": ">=16.11.0" + }, + "publishConfig": { + "access": "public" + } +}
\ No newline at end of file diff --git a/node_modules/@discordjs/util/CHANGELOG.md b/node_modules/@discordjs/util/CHANGELOG.md new file mode 100644 index 0000000..93756ea --- /dev/null +++ b/node_modules/@discordjs/util/CHANGELOG.md @@ -0,0 +1,137 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +# [@discordjs/util@1.0.1](https://github.com/discordjs/discord.js/compare/@discordjs/util@1.0.0...@discordjs/util@1.0.1) - (2023-08-17) + +## Documentation + +- Update Node.js requirement to 16.11.0 (#9764) ([188877c](https://github.com/discordjs/discord.js/commit/188877c50af70f0d5cffb246620fa277435c6ce6)) + +# [@discordjs/util@1.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.3.1...@discordjs/util@1.0.0) - (2023-07-31) + +## Features + +- No-de-no-de, now with extra buns (#9683) ([386f206](https://github.com/discordjs/discord.js/commit/386f206caf74a04c426799af9796ca96dcb37056)) + - **BREAKING CHANGE:** The REST and RequestManager classes now extend AsyncEventEmitter
+from `@vladfrangu/async_event_emitter`, which aids in cross-compatibility
+between Node, Deno, Bun, CF Workers, Vercel Functions, etc. + - **BREAKING CHANGE:** DefaultUserAgentAppendix has been adapted to support multiple
+different platforms (previously mentioned Deno, Bun, CF Workers, etc) + - **BREAKING CHANGE:** the entry point for `@discordjs/rest` will now differ
+in non-node-like environments (CF Workers, etc.) + - **Co-authored-by:** Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> + - **Co-authored-by:** Jiralite <33201955+Jiralite@users.noreply.github.com> + - **Co-authored-by:** suneettipirneni <suneettipirneni@icloud.com> + +# [@discordjs/util@0.3.1](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.3.0...@discordjs/util@0.3.1) - (2023-05-01) + +## Refactor + +- **ShardClientUtil:** Logic de-duplication (#9491) ([a9f2bff](https://github.com/discordjs/discord.js/commit/a9f2bff82a18c6a3afdee99e5830e1d7b4da65dc)) + +# [@discordjs/util@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.2.0...@discordjs/util@0.3.0) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/util@1.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.3.1...@discordjs/util@1.0.0) - (2023-07-31) + +## Features + +- No-de-no-de, now with extra buns (#9683) ([386f206](https://github.com/discordjs/discord.js/commit/386f206caf74a04c426799af9796ca96dcb37056)) + - **BREAKING CHANGE:** The REST and RequestManager classes now extend AsyncEventEmitter
+from `@vladfrangu/async_event_emitter`, which aids in cross-compatibility
+between Node, Deno, Bun, CF Workers, Vercel Functions, etc. + - **BREAKING CHANGE:** DefaultUserAgentAppendix has been adapted to support multiple
+different platforms (previously mentioned Deno, Bun, CF Workers, etc) + - **BREAKING CHANGE:** the entry point for `@discordjs/rest` will now differ
+in non-node-like environments (CF Workers, etc.) + - **Co-authored-by:** Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> + - **Co-authored-by:** Jiralite <33201955+Jiralite@users.noreply.github.com> + - **Co-authored-by:** suneettipirneni <suneettipirneni@icloud.com> + +# [@discordjs/util@0.3.1](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.3.0...@discordjs/util@0.3.1) - (2023-05-01) + +## Refactor + +- **ShardClientUtil:** Logic de-duplication (#9491) ([a9f2bff](https://github.com/discordjs/discord.js/commit/a9f2bff82a18c6a3afdee99e5830e1d7b4da65dc)) + +# [@discordjs/util@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.2.0...@discordjs/util@0.3.0) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/util@0.3.1](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.3.0...@discordjs/util@0.3.1) - (2023-05-01) + +## Refactor + +- **ShardClientUtil:** Logic de-duplication (#9491) ([a9f2bff](https://github.com/discordjs/discord.js/commit/a9f2bff82a18c6a3afdee99e5830e1d7b4da65dc)) + +# [@discordjs/util@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.2.0...@discordjs/util@0.3.0) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/util@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.2.0...@discordjs/util@0.3.0) - (2023-05-01) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/util@0.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/util@0.1.0...@discordjs/util@0.2.0) - (2023-03-12) + +## Bug Fixes + +- Pin @types/node version ([9d8179c](https://github.com/discordjs/discord.js/commit/9d8179c6a78e1c7f9976f852804055964d5385d4)) + +## Features + +- **website:** Add support for source file links (#9048) ([f6506e9](https://github.com/discordjs/discord.js/commit/f6506e99c496683ee0ab67db0726b105b929af38)) +- **core:** Implement some ws send events (#8941) ([816aed4](https://github.com/discordjs/discord.js/commit/816aed478e3035060697092d52ad2b58106be0ee)) +- Web-components (#8715) ([0ac3e76](https://github.com/discordjs/discord.js/commit/0ac3e766bd9dbdeb106483fa4bb085d74de346a2)) + +# [@discordjs/util@0.1.0](https://github.com/discordjs/discord.js/tree/@discordjs/util@0.1.0) - (2022-10-03) + +## Features + +- Add `@discordjs/util` (#8591) ([b2ec865](https://github.com/discordjs/discord.js/commit/b2ec865765bf94181473864a627fb63ea8173fd3)) diff --git a/node_modules/@discordjs/util/LICENSE b/node_modules/@discordjs/util/LICENSE new file mode 100644 index 0000000..e2822e9 --- /dev/null +++ b/node_modules/@discordjs/util/LICENSE @@ -0,0 +1,190 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "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 2022 Noel Buechler + + 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. diff --git a/node_modules/@discordjs/util/README.md b/node_modules/@discordjs/util/README.md new file mode 100644 index 0000000..999ae89 --- /dev/null +++ b/node_modules/@discordjs/util/README.md @@ -0,0 +1,64 @@ +<div align="center"> + <br /> + <p> + <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a> + </p> + <br /> + <p> + <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a> + <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a> + </p> + <p> + <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a> + <a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a> + </p> +</div> + +## About + +`@discordjs/util` is a collection of utility functions for use with discord.js. + +## Installation + +**Node.js 16.11.0 or newer is required.** + +```sh +npm install @discordjs/util +yarn add @discordjs/util +pnpm add @discordjs/util +``` + +## Links + +- [Website][website] ([source][website-source]) +- [Documentation][documentation] +- [Guide][guide] ([source][guide-source]) + Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library. +- [discord.js Discord server][discord] +- [Discord API Discord server][discord-api] +- [GitHub][source] +- [npm][npm] +- [Related libraries][related-libs] + +## Contributing + +Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the +[documentation][documentation]. +See [the contribution guide][contributing] if you'd like to submit a PR. + +## Help + +If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord]. + +[website]: https://discord.js.org +[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website +[documentation]: https://discord.js.org/docs/packages/util/stable +[guide]: https://discordjs.guide/ +[guide-source]: https://github.com/discordjs/guide +[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html +[discord]: https://discord.gg/djs +[discord-api]: https://discord.gg/discord-api +[source]: https://github.com/discordjs/discord.js/tree/main/packages/util +[npm]: https://www.npmjs.com/package/@discordjs/util +[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries +[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md diff --git a/node_modules/@discordjs/util/dist/index.d.mts b/node_modules/@discordjs/util/dist/index.d.mts new file mode 100644 index 0000000..cef642f --- /dev/null +++ b/node_modules/@discordjs/util/dist/index.d.mts @@ -0,0 +1,117 @@ +/** + * Represents a type that may or may not be a promise + */ +type Awaitable<T> = PromiseLike<T> | T; + +/** + * Lazy is a wrapper around a value that is computed lazily. It is useful for + * cases where the value is expensive to compute and the computation may not + * be needed at all. + * + * @param cb - The callback to lazily evaluate + * @typeParam T - The type of the value + * @example + * ```ts + * const value = lazy(() => computeExpensiveValue()); + * ``` + */ +declare function lazy<T>(cb: () => T): () => T; + +/** + * Options for creating a range + */ +interface RangeOptions { + /** + * The end of the range (exclusive) + */ + end: number; + /** + * The start of the range (inclusive) + */ + start: number; + /** + * The amount to increment by + * + * @defaultValue `1` + */ + step?: number; +} +/** + * A generator to yield numbers in a given range + * + * @remarks + * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you + * prefer for the end to be included add 1 to the range or `end` option. + * @param range - A number representing the the range to yield (exclusive) or an object with start, end and step + * @example + * Basic range + * ```ts + * for (const number of range(5)) { + * console.log(number); + * } + * // Prints 0, 1, 2, 3, 4 + * ``` + * @example + * Range with a step + * ```ts + * for (const number of range({ start: 3, end: 10, step: 2 })) { + * console.log(number); + * } + * // Prints 3, 5, 7, 9 + * ``` + */ +declare function range(range: RangeOptions | number): Generator<number, void, unknown>; + +/** + * Calculates the shard id for a given guild id. + * + * @param guildId - The guild id to calculate the shard id for + * @param shardCount - The total number of shards + */ +declare function calculateShardId(guildId: string, shardCount: number): number; + +declare function shouldUseGlobalFetchAndWebSocket(): boolean; + +/** + * Resolves the user agent appendix string for the current environment. + */ +declare function getUserAgentAppendix(): string; + +/** + * Represents an object capable of representing itself as a JSON object + * + * @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs. + */ +interface JSONEncodable<T> { + /** + * Transforms this object to its JSON format + */ + toJSON(): T; +} +/** + * Indicates if an object is encodable or not. + * + * @param maybeEncodable - The object to check against + */ +declare function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown>; + +/** + * Represents a structure that can be checked against another + * given structure for equality + * + * @typeParam T - The type of object to compare the current object to + */ +interface Equatable<T> { + /** + * Whether or not this is equal to another structure + */ + equals(other: T): boolean; +} +/** + * Indicates if an object is equatable or not. + * + * @param maybeEquatable - The object to check against + */ +declare function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown>; + +export { Awaitable, Equatable, JSONEncodable, RangeOptions, calculateShardId, getUserAgentAppendix, isEquatable, isJSONEncodable, lazy, range, shouldUseGlobalFetchAndWebSocket }; diff --git a/node_modules/@discordjs/util/dist/index.d.ts b/node_modules/@discordjs/util/dist/index.d.ts new file mode 100644 index 0000000..cef642f --- /dev/null +++ b/node_modules/@discordjs/util/dist/index.d.ts @@ -0,0 +1,117 @@ +/** + * Represents a type that may or may not be a promise + */ +type Awaitable<T> = PromiseLike<T> | T; + +/** + * Lazy is a wrapper around a value that is computed lazily. It is useful for + * cases where the value is expensive to compute and the computation may not + * be needed at all. + * + * @param cb - The callback to lazily evaluate + * @typeParam T - The type of the value + * @example + * ```ts + * const value = lazy(() => computeExpensiveValue()); + * ``` + */ +declare function lazy<T>(cb: () => T): () => T; + +/** + * Options for creating a range + */ +interface RangeOptions { + /** + * The end of the range (exclusive) + */ + end: number; + /** + * The start of the range (inclusive) + */ + start: number; + /** + * The amount to increment by + * + * @defaultValue `1` + */ + step?: number; +} +/** + * A generator to yield numbers in a given range + * + * @remarks + * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you + * prefer for the end to be included add 1 to the range or `end` option. + * @param range - A number representing the the range to yield (exclusive) or an object with start, end and step + * @example + * Basic range + * ```ts + * for (const number of range(5)) { + * console.log(number); + * } + * // Prints 0, 1, 2, 3, 4 + * ``` + * @example + * Range with a step + * ```ts + * for (const number of range({ start: 3, end: 10, step: 2 })) { + * console.log(number); + * } + * // Prints 3, 5, 7, 9 + * ``` + */ +declare function range(range: RangeOptions | number): Generator<number, void, unknown>; + +/** + * Calculates the shard id for a given guild id. + * + * @param guildId - The guild id to calculate the shard id for + * @param shardCount - The total number of shards + */ +declare function calculateShardId(guildId: string, shardCount: number): number; + +declare function shouldUseGlobalFetchAndWebSocket(): boolean; + +/** + * Resolves the user agent appendix string for the current environment. + */ +declare function getUserAgentAppendix(): string; + +/** + * Represents an object capable of representing itself as a JSON object + * + * @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs. + */ +interface JSONEncodable<T> { + /** + * Transforms this object to its JSON format + */ + toJSON(): T; +} +/** + * Indicates if an object is encodable or not. + * + * @param maybeEncodable - The object to check against + */ +declare function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown>; + +/** + * Represents a structure that can be checked against another + * given structure for equality + * + * @typeParam T - The type of object to compare the current object to + */ +interface Equatable<T> { + /** + * Whether or not this is equal to another structure + */ + equals(other: T): boolean; +} +/** + * Indicates if an object is equatable or not. + * + * @param maybeEquatable - The object to check against + */ +declare function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown>; + +export { Awaitable, Equatable, JSONEncodable, RangeOptions, calculateShardId, getUserAgentAppendix, isEquatable, isJSONEncodable, lazy, range, shouldUseGlobalFetchAndWebSocket }; diff --git a/node_modules/@discordjs/util/dist/index.js b/node_modules/@discordjs/util/dist/index.js new file mode 100644 index 0000000..ce50bf1 --- /dev/null +++ b/node_modules/@discordjs/util/dist/index.js @@ -0,0 +1,130 @@ +"use strict"; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + calculateShardId: () => calculateShardId, + getUserAgentAppendix: () => getUserAgentAppendix, + isEquatable: () => isEquatable, + isJSONEncodable: () => isJSONEncodable, + lazy: () => lazy, + range: () => range, + shouldUseGlobalFetchAndWebSocket: () => shouldUseGlobalFetchAndWebSocket +}); +module.exports = __toCommonJS(src_exports); + +// src/functions/lazy.ts +function lazy(cb) { + let defaultValue; + return () => defaultValue ??= cb(); +} +__name(lazy, "lazy"); + +// src/functions/range.ts +function* range(range2) { + let rangeEnd; + let start = 0; + let step = 1; + if (typeof range2 === "number") { + rangeEnd = range2; + } else { + start = range2.start; + rangeEnd = range2.end; + step = range2.step ?? 1; + } + for (let index = start; index < rangeEnd; index += step) { + yield index; + } +} +__name(range, "range"); + +// src/functions/calculateShardId.ts +function calculateShardId(guildId, shardCount) { + return Number(BigInt(guildId) >> 22n) % shardCount; +} +__name(calculateShardId, "calculateShardId"); + +// src/functions/runtime.ts +function shouldUseGlobalFetchAndWebSocket() { + if (typeof globalThis.process === "undefined") { + return "fetch" in globalThis && "WebSocket" in globalThis; + } + if ("versions" in globalThis.process) { + return "deno" in globalThis.process.versions || "bun" in globalThis.process.versions; + } + return false; +} +__name(shouldUseGlobalFetchAndWebSocket, "shouldUseGlobalFetchAndWebSocket"); + +// src/functions/userAgentAppendix.ts +function getUserAgentAppendix() { + if (typeof globalThis.EdgeRuntime !== "undefined") { + return "Vercel-Edge-Functions"; + } + if (typeof globalThis.R2 !== "undefined" && typeof globalThis.WebSocketPair !== "undefined") { + return "Cloudflare-Workers"; + } + if (typeof globalThis.Netlify !== "undefined") { + return "Netlify-Edge-Functions"; + } + if (typeof globalThis.process !== "object") { + if (typeof globalThis.navigator === "object") { + return globalThis.navigator.userAgent; + } + return "UnknownEnvironment"; + } + if ("versions" in globalThis.process) { + if ("deno" in globalThis.process.versions) { + return `Deno/${globalThis.process.versions.deno}`; + } + if ("bun" in globalThis.process.versions) { + return `Bun/${globalThis.process.versions.bun}`; + } + if ("node" in globalThis.process.versions) { + return `Node.js/${globalThis.process.versions.node}`; + } + } + return "UnknownEnvironment"; +} +__name(getUserAgentAppendix, "getUserAgentAppendix"); + +// src/JSONEncodable.ts +function isJSONEncodable(maybeEncodable) { + return maybeEncodable !== null && typeof maybeEncodable === "object" && "toJSON" in maybeEncodable; +} +__name(isJSONEncodable, "isJSONEncodable"); + +// src/Equatable.ts +function isEquatable(maybeEquatable) { + return maybeEquatable !== null && typeof maybeEquatable === "object" && "equals" in maybeEquatable; +} +__name(isEquatable, "isEquatable"); +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + calculateShardId, + getUserAgentAppendix, + isEquatable, + isJSONEncodable, + lazy, + range, + shouldUseGlobalFetchAndWebSocket +}); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/util/dist/index.js.map b/node_modules/@discordjs/util/dist/index.js.map new file mode 100644 index 0000000..14f7b9f --- /dev/null +++ b/node_modules/@discordjs/util/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/functions/lazy.ts","../src/functions/range.ts","../src/functions/calculateShardId.ts","../src/functions/runtime.ts","../src/functions/userAgentAppendix.ts","../src/JSONEncodable.ts","../src/Equatable.ts"],"sourcesContent":["export * from './types.js';\nexport * from './functions/index.js';\nexport * from './JSONEncodable.js';\nexport * from './Equatable.js';\n","/**\n * Lazy is a wrapper around a value that is computed lazily. It is useful for\n * cases where the value is expensive to compute and the computation may not\n * be needed at all.\n *\n * @param cb - The callback to lazily evaluate\n * @typeParam T - The type of the value\n * @example\n * ```ts\n * const value = lazy(() => computeExpensiveValue());\n * ```\n */\n// eslint-disable-next-line promise/prefer-await-to-callbacks\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\treturn () => (defaultValue ??= cb());\n}\n","/**\n * Options for creating a range\n */\nexport interface RangeOptions {\n\t/**\n\t * The end of the range (exclusive)\n\t */\n\tend: number;\n\t/**\n\t * The start of the range (inclusive)\n\t */\n\tstart: number;\n\t/**\n\t * The amount to increment by\n\t *\n\t * @defaultValue `1`\n\t */\n\tstep?: number;\n}\n\n/**\n * A generator to yield numbers in a given range\n *\n * @remarks\n * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you\n * prefer for the end to be included add 1 to the range or `end` option.\n * @param range - A number representing the the range to yield (exclusive) or an object with start, end and step\n * @example\n * Basic range\n * ```ts\n * for (const number of range(5)) {\n * console.log(number);\n * }\n * // Prints 0, 1, 2, 3, 4\n * ```\n * @example\n * Range with a step\n * ```ts\n * for (const number of range({ start: 3, end: 10, step: 2 })) {\n * \tconsole.log(number);\n * }\n * // Prints 3, 5, 7, 9\n * ```\n */\nexport function* range(range: RangeOptions | number) {\n\tlet rangeEnd: number;\n\tlet start = 0;\n\tlet step = 1;\n\n\tif (typeof range === 'number') {\n\t\trangeEnd = range;\n\t} else {\n\t\tstart = range.start;\n\t\trangeEnd = range.end;\n\t\tstep = range.step ?? 1;\n\t}\n\n\tfor (let index = start; index < rangeEnd; index += step) {\n\t\tyield index;\n\t}\n}\n","/**\n * Calculates the shard id for a given guild id.\n *\n * @param guildId - The guild id to calculate the shard id for\n * @param shardCount - The total number of shards\n */\nexport function calculateShardId(guildId: string, shardCount: number) {\n\treturn Number(BigInt(guildId) >> 22n) % shardCount;\n}\n","export function shouldUseGlobalFetchAndWebSocket() {\n\t// Browser env and deno when ran directly\n\tif (typeof globalThis.process === 'undefined') {\n\t\treturn 'fetch' in globalThis && 'WebSocket' in globalThis;\n\t}\n\n\tif ('versions' in globalThis.process) {\n\t\treturn 'deno' in globalThis.process.versions || 'bun' in globalThis.process.versions;\n\t}\n\n\treturn false;\n}\n","/* eslint-disable n/prefer-global/process */\n/* eslint-disable no-restricted-globals */\n\n/**\n * Resolves the user agent appendix string for the current environment.\n */\nexport function getUserAgentAppendix(): string {\n\t// https://vercel.com/docs/concepts/functions/edge-functions/edge-runtime#check-if-you're-running-on-the-edge-runtime\n\t// @ts-expect-error Vercel Edge functions\n\tif (typeof globalThis.EdgeRuntime !== 'undefined') {\n\t\treturn 'Vercel-Edge-Functions';\n\t}\n\n\t// @ts-expect-error Cloudflare Workers\n\tif (typeof globalThis.R2 !== 'undefined' && typeof globalThis.WebSocketPair !== 'undefined') {\n\t\t// https://developers.cloudflare.com/workers/runtime-apis/web-standards/#navigatoruseragent\n\t\treturn 'Cloudflare-Workers';\n\t}\n\n\t// https://docs.netlify.com/edge-functions/api/#netlify-global-object\n\t// @ts-expect-error Netlify Edge functions\n\tif (typeof globalThis.Netlify !== 'undefined') {\n\t\treturn 'Netlify-Edge-Functions';\n\t}\n\n\t// Most (if not all) edge environments will have `process` defined. Within a web browser we'll extract it using `navigator.userAgent`.\n\tif (typeof globalThis.process !== 'object') {\n\t\t// @ts-expect-error web env\n\t\tif (typeof globalThis.navigator === 'object') {\n\t\t\t// @ts-expect-error web env\n\t\t\treturn globalThis.navigator.userAgent;\n\t\t}\n\n\t\treturn 'UnknownEnvironment';\n\t}\n\n\tif ('versions' in globalThis.process) {\n\t\tif ('deno' in globalThis.process.versions) {\n\t\t\treturn `Deno/${globalThis.process.versions.deno}`;\n\t\t}\n\n\t\tif ('bun' in globalThis.process.versions) {\n\t\t\treturn `Bun/${globalThis.process.versions.bun}`;\n\t\t}\n\n\t\tif ('node' in globalThis.process.versions) {\n\t\t\treturn `Node.js/${globalThis.process.versions.node}`;\n\t\t}\n\t}\n\n\treturn 'UnknownEnvironment';\n}\n","/**\n * Represents an object capable of representing itself as a JSON object\n *\n * @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.\n */\nexport interface JSONEncodable<T> {\n\t/**\n\t * Transforms this object to its JSON format\n\t */\n\ttoJSON(): T;\n}\n\n/**\n * Indicates if an object is encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nexport function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {\n\treturn maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable;\n}\n","/**\n * Represents a structure that can be checked against another\n * given structure for equality\n *\n * @typeParam T - The type of object to compare the current object to\n */\nexport interface Equatable<T> {\n\t/**\n\t * Whether or not this is equal to another structure\n\t */\n\tequals(other: T): boolean;\n}\n\n/**\n * Indicates if an object is equatable or not.\n *\n * @param maybeEquatable - The object to check against\n */\nexport function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown> {\n\treturn maybeEquatable !== null && typeof maybeEquatable === 'object' && 'equals' in maybeEquatable;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,KAAQ,IAAsB;AAC7C,MAAI;AAEJ,SAAO,MAAO,iBAAiB,GAAG;AACnC;AAJgB;;;AC+BT,UAAU,MAAMA,QAA8B;AACpD,MAAI;AACJ,MAAI,QAAQ;AACZ,MAAI,OAAO;AAEX,MAAI,OAAOA,WAAU,UAAU;AAC9B,eAAWA;AAAA,EACZ,OAAO;AACN,YAAQA,OAAM;AACd,eAAWA,OAAM;AACjB,WAAOA,OAAM,QAAQ;AAAA,EACtB;AAEA,WAAS,QAAQ,OAAO,QAAQ,UAAU,SAAS,MAAM;AACxD,UAAM;AAAA,EACP;AACD;AAhBiB;;;ACtCV,SAAS,iBAAiB,SAAiB,YAAoB;AACrE,SAAO,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI;AACzC;AAFgB;;;ACNT,SAAS,mCAAmC;AAElD,MAAI,OAAO,WAAW,YAAY,aAAa;AAC9C,WAAO,WAAW,cAAc,eAAe;AAAA,EAChD;AAEA,MAAI,cAAc,WAAW,SAAS;AACrC,WAAO,UAAU,WAAW,QAAQ,YAAY,SAAS,WAAW,QAAQ;AAAA,EAC7E;AAEA,SAAO;AACR;AAXgB;;;ACMT,SAAS,uBAA+B;AAG9C,MAAI,OAAO,WAAW,gBAAgB,aAAa;AAClD,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,WAAW,OAAO,eAAe,OAAO,WAAW,kBAAkB,aAAa;AAE5F,WAAO;AAAA,EACR;AAIA,MAAI,OAAO,WAAW,YAAY,aAAa;AAC9C,WAAO;AAAA,EACR;AAGA,MAAI,OAAO,WAAW,YAAY,UAAU;AAE3C,QAAI,OAAO,WAAW,cAAc,UAAU;AAE7C,aAAO,WAAW,UAAU;AAAA,IAC7B;AAEA,WAAO;AAAA,EACR;AAEA,MAAI,cAAc,WAAW,SAAS;AACrC,QAAI,UAAU,WAAW,QAAQ,UAAU;AAC1C,aAAO,QAAQ,WAAW,QAAQ,SAAS,IAAI;AAAA,IAChD;AAEA,QAAI,SAAS,WAAW,QAAQ,UAAU;AACzC,aAAO,OAAO,WAAW,QAAQ,SAAS,GAAG;AAAA,IAC9C;AAEA,QAAI,UAAU,WAAW,QAAQ,UAAU;AAC1C,aAAO,WAAW,WAAW,QAAQ,SAAS,IAAI;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AACR;AA7CgB;;;ACWT,SAAS,gBAAgB,gBAAmE;AAClG,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;;;ACCT,SAAS,YAAY,gBAA+D;AAC1F,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;","names":["range"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/util/dist/index.mjs b/node_modules/@discordjs/util/dist/index.mjs new file mode 100644 index 0000000..6030649 --- /dev/null +++ b/node_modules/@discordjs/util/dist/index.mjs @@ -0,0 +1,99 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); + +// src/functions/lazy.ts +function lazy(cb) { + let defaultValue; + return () => defaultValue ??= cb(); +} +__name(lazy, "lazy"); + +// src/functions/range.ts +function* range(range2) { + let rangeEnd; + let start = 0; + let step = 1; + if (typeof range2 === "number") { + rangeEnd = range2; + } else { + start = range2.start; + rangeEnd = range2.end; + step = range2.step ?? 1; + } + for (let index = start; index < rangeEnd; index += step) { + yield index; + } +} +__name(range, "range"); + +// src/functions/calculateShardId.ts +function calculateShardId(guildId, shardCount) { + return Number(BigInt(guildId) >> 22n) % shardCount; +} +__name(calculateShardId, "calculateShardId"); + +// src/functions/runtime.ts +function shouldUseGlobalFetchAndWebSocket() { + if (typeof globalThis.process === "undefined") { + return "fetch" in globalThis && "WebSocket" in globalThis; + } + if ("versions" in globalThis.process) { + return "deno" in globalThis.process.versions || "bun" in globalThis.process.versions; + } + return false; +} +__name(shouldUseGlobalFetchAndWebSocket, "shouldUseGlobalFetchAndWebSocket"); + +// src/functions/userAgentAppendix.ts +function getUserAgentAppendix() { + if (typeof globalThis.EdgeRuntime !== "undefined") { + return "Vercel-Edge-Functions"; + } + if (typeof globalThis.R2 !== "undefined" && typeof globalThis.WebSocketPair !== "undefined") { + return "Cloudflare-Workers"; + } + if (typeof globalThis.Netlify !== "undefined") { + return "Netlify-Edge-Functions"; + } + if (typeof globalThis.process !== "object") { + if (typeof globalThis.navigator === "object") { + return globalThis.navigator.userAgent; + } + return "UnknownEnvironment"; + } + if ("versions" in globalThis.process) { + if ("deno" in globalThis.process.versions) { + return `Deno/${globalThis.process.versions.deno}`; + } + if ("bun" in globalThis.process.versions) { + return `Bun/${globalThis.process.versions.bun}`; + } + if ("node" in globalThis.process.versions) { + return `Node.js/${globalThis.process.versions.node}`; + } + } + return "UnknownEnvironment"; +} +__name(getUserAgentAppendix, "getUserAgentAppendix"); + +// src/JSONEncodable.ts +function isJSONEncodable(maybeEncodable) { + return maybeEncodable !== null && typeof maybeEncodable === "object" && "toJSON" in maybeEncodable; +} +__name(isJSONEncodable, "isJSONEncodable"); + +// src/Equatable.ts +function isEquatable(maybeEquatable) { + return maybeEquatable !== null && typeof maybeEquatable === "object" && "equals" in maybeEquatable; +} +__name(isEquatable, "isEquatable"); +export { + calculateShardId, + getUserAgentAppendix, + isEquatable, + isJSONEncodable, + lazy, + range, + shouldUseGlobalFetchAndWebSocket +}; +//# sourceMappingURL=index.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/util/dist/index.mjs.map b/node_modules/@discordjs/util/dist/index.mjs.map new file mode 100644 index 0000000..482f14f --- /dev/null +++ b/node_modules/@discordjs/util/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/functions/lazy.ts","../src/functions/range.ts","../src/functions/calculateShardId.ts","../src/functions/runtime.ts","../src/functions/userAgentAppendix.ts","../src/JSONEncodable.ts","../src/Equatable.ts"],"sourcesContent":["/**\n * Lazy is a wrapper around a value that is computed lazily. It is useful for\n * cases where the value is expensive to compute and the computation may not\n * be needed at all.\n *\n * @param cb - The callback to lazily evaluate\n * @typeParam T - The type of the value\n * @example\n * ```ts\n * const value = lazy(() => computeExpensiveValue());\n * ```\n */\n// eslint-disable-next-line promise/prefer-await-to-callbacks\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\treturn () => (defaultValue ??= cb());\n}\n","/**\n * Options for creating a range\n */\nexport interface RangeOptions {\n\t/**\n\t * The end of the range (exclusive)\n\t */\n\tend: number;\n\t/**\n\t * The start of the range (inclusive)\n\t */\n\tstart: number;\n\t/**\n\t * The amount to increment by\n\t *\n\t * @defaultValue `1`\n\t */\n\tstep?: number;\n}\n\n/**\n * A generator to yield numbers in a given range\n *\n * @remarks\n * This method is end-exclusive, for example the last number yielded by `range(5)` is 4. If you\n * prefer for the end to be included add 1 to the range or `end` option.\n * @param range - A number representing the the range to yield (exclusive) or an object with start, end and step\n * @example\n * Basic range\n * ```ts\n * for (const number of range(5)) {\n * console.log(number);\n * }\n * // Prints 0, 1, 2, 3, 4\n * ```\n * @example\n * Range with a step\n * ```ts\n * for (const number of range({ start: 3, end: 10, step: 2 })) {\n * \tconsole.log(number);\n * }\n * // Prints 3, 5, 7, 9\n * ```\n */\nexport function* range(range: RangeOptions | number) {\n\tlet rangeEnd: number;\n\tlet start = 0;\n\tlet step = 1;\n\n\tif (typeof range === 'number') {\n\t\trangeEnd = range;\n\t} else {\n\t\tstart = range.start;\n\t\trangeEnd = range.end;\n\t\tstep = range.step ?? 1;\n\t}\n\n\tfor (let index = start; index < rangeEnd; index += step) {\n\t\tyield index;\n\t}\n}\n","/**\n * Calculates the shard id for a given guild id.\n *\n * @param guildId - The guild id to calculate the shard id for\n * @param shardCount - The total number of shards\n */\nexport function calculateShardId(guildId: string, shardCount: number) {\n\treturn Number(BigInt(guildId) >> 22n) % shardCount;\n}\n","export function shouldUseGlobalFetchAndWebSocket() {\n\t// Browser env and deno when ran directly\n\tif (typeof globalThis.process === 'undefined') {\n\t\treturn 'fetch' in globalThis && 'WebSocket' in globalThis;\n\t}\n\n\tif ('versions' in globalThis.process) {\n\t\treturn 'deno' in globalThis.process.versions || 'bun' in globalThis.process.versions;\n\t}\n\n\treturn false;\n}\n","/* eslint-disable n/prefer-global/process */\n/* eslint-disable no-restricted-globals */\n\n/**\n * Resolves the user agent appendix string for the current environment.\n */\nexport function getUserAgentAppendix(): string {\n\t// https://vercel.com/docs/concepts/functions/edge-functions/edge-runtime#check-if-you're-running-on-the-edge-runtime\n\t// @ts-expect-error Vercel Edge functions\n\tif (typeof globalThis.EdgeRuntime !== 'undefined') {\n\t\treturn 'Vercel-Edge-Functions';\n\t}\n\n\t// @ts-expect-error Cloudflare Workers\n\tif (typeof globalThis.R2 !== 'undefined' && typeof globalThis.WebSocketPair !== 'undefined') {\n\t\t// https://developers.cloudflare.com/workers/runtime-apis/web-standards/#navigatoruseragent\n\t\treturn 'Cloudflare-Workers';\n\t}\n\n\t// https://docs.netlify.com/edge-functions/api/#netlify-global-object\n\t// @ts-expect-error Netlify Edge functions\n\tif (typeof globalThis.Netlify !== 'undefined') {\n\t\treturn 'Netlify-Edge-Functions';\n\t}\n\n\t// Most (if not all) edge environments will have `process` defined. Within a web browser we'll extract it using `navigator.userAgent`.\n\tif (typeof globalThis.process !== 'object') {\n\t\t// @ts-expect-error web env\n\t\tif (typeof globalThis.navigator === 'object') {\n\t\t\t// @ts-expect-error web env\n\t\t\treturn globalThis.navigator.userAgent;\n\t\t}\n\n\t\treturn 'UnknownEnvironment';\n\t}\n\n\tif ('versions' in globalThis.process) {\n\t\tif ('deno' in globalThis.process.versions) {\n\t\t\treturn `Deno/${globalThis.process.versions.deno}`;\n\t\t}\n\n\t\tif ('bun' in globalThis.process.versions) {\n\t\t\treturn `Bun/${globalThis.process.versions.bun}`;\n\t\t}\n\n\t\tif ('node' in globalThis.process.versions) {\n\t\t\treturn `Node.js/${globalThis.process.versions.node}`;\n\t\t}\n\t}\n\n\treturn 'UnknownEnvironment';\n}\n","/**\n * Represents an object capable of representing itself as a JSON object\n *\n * @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.\n */\nexport interface JSONEncodable<T> {\n\t/**\n\t * Transforms this object to its JSON format\n\t */\n\ttoJSON(): T;\n}\n\n/**\n * Indicates if an object is encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nexport function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {\n\treturn maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable;\n}\n","/**\n * Represents a structure that can be checked against another\n * given structure for equality\n *\n * @typeParam T - The type of object to compare the current object to\n */\nexport interface Equatable<T> {\n\t/**\n\t * Whether or not this is equal to another structure\n\t */\n\tequals(other: T): boolean;\n}\n\n/**\n * Indicates if an object is equatable or not.\n *\n * @param maybeEquatable - The object to check against\n */\nexport function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown> {\n\treturn maybeEquatable !== null && typeof maybeEquatable === 'object' && 'equals' in maybeEquatable;\n}\n"],"mappings":";;;;AAaO,SAAS,KAAQ,IAAsB;AAC7C,MAAI;AAEJ,SAAO,MAAO,iBAAiB,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9C;AAEA,QAAI,UAAU,WAAW,QAAQ,UAAU;AAC1C,aAAO,WAAW,WAAW,QAAQ,SAAS,IAAI;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AACR;AA7CgB;;;ACWT,SAAS,gBAAgB,gBAAmE;AAClG,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;;;ACCT,SAAS,YAAY,gBAA+D;AAC1F,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;","names":["range"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/util/package.json b/node_modules/@discordjs/util/package.json new file mode 100644 index 0000000..85e258a --- /dev/null +++ b/node_modules/@discordjs/util/package.json @@ -0,0 +1,80 @@ +{ + "name": "@discordjs/util", + "version": "1.0.1", + "description": "Utilities shared across Discord.js packages", + "scripts": { + "build": "tsup", + "build:docs": "tsc -p tsconfig.docs.json", + "test": "vitest run && tsd", + "lint": "prettier --check . && TIMING=1 eslint src --ext .mjs,.js,.ts --format=pretty", + "format": "prettier --write . && TIMING=1 eslint src --ext .mjs,.js,.ts --fix --format=pretty", + "fmt": "yarn format", + "docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json", + "prepack": "yarn lint && yarn test && yarn build", + "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/util/*'", + "release": "cliff-jumper" + }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "directories": { + "lib": "src" + }, + "files": [ + "dist" + ], + "contributors": [ + "Crawl <icrawltogo@gmail.com>", + "Amish Shah <amishshah.2k@gmail.com>", + "Vlad Frangu <kingdgrizzle@gmail.com>", + "SpaceEEC <spaceeec@yahoo.com>", + "Aura Román <kyradiscord@gmail.com>" + ], + "license": "Apache-2.0", + "keywords": [ + "api", + "bot", + "client", + "node", + "discordjs" + ], + "repository": { + "type": "git", + "url": "https://github.com/discordjs/discord.js.git", + "directory": "packages/util" + }, + "bugs": { + "url": "https://github.com/discordjs/discord.js/issues" + }, + "homepage": "https://discord.js.org", + "devDependencies": { + "@favware/cliff-jumper": "^2.1.1", + "@microsoft/api-extractor": "^7.36.4", + "@types/node": "16.18.40", + "@vitest/coverage-v8": "^0.34.2", + "cross-env": "^7.0.3", + "eslint": "^8.47.0", + "eslint-config-neon": "^0.1.47", + "eslint-formatter-pretty": "^5.0.0", + "prettier": "^2.8.8", + "tsd": "^0.28.1", + "tsup": "^7.2.0", + "turbo": "^1.10.12", + "typescript": "^5.1.6", + "vitest": "^0.34.2" + }, + "engines": { + "node": ">=16.11.0" + }, + "publishConfig": { + "access": "public" + }, + "tsd": { + "directory": "__tests__/types" + } +}
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/CHANGELOG.md b/node_modules/@discordjs/ws/CHANGELOG.md new file mode 100644 index 0000000..f7e4442 --- /dev/null +++ b/node_modules/@discordjs/ws/CHANGELOG.md @@ -0,0 +1,317 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +# [@discordjs/ws@1.0.1](https://github.com/discordjs/discord.js/compare/@discordjs/ws@1.0.0...@discordjs/ws@1.0.1) - (2023-08-17) + +## Documentation + +- Update Node.js requirement to 16.11.0 (#9764) ([188877c](https://github.com/discordjs/discord.js/commit/188877c50af70f0d5cffb246620fa277435c6ce6)) + +# [@discordjs/ws@1.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.3...@discordjs/ws@1.0.0) - (2023-07-31) + +## Bug Fixes + +- **WebSocketShard:** Close errors not being catchable (#9704) ([8c782bf](https://github.com/discordjs/discord.js/commit/8c782bfd52b1d7bbfbf1dfd39d0c45828298e285)) +- **WebSocketManager:** Always cache result of fetchGatewayInformation (#9611) ([df8b6e9](https://github.com/discordjs/discord.js/commit/df8b6e9934af5b21aa2701ce54244c38a5f133e0)) +- **WebSocketShard:** Handle initial connect being a resume (#9549) ([4dcc9c5](https://github.com/discordjs/discord.js/commit/4dcc9c50f83cd234cb2c2ede47fb505ffb75eef2)) + +## Features + +- No-de-no-de, now with extra buns (#9683) ([386f206](https://github.com/discordjs/discord.js/commit/386f206caf74a04c426799af9796ca96dcb37056)) + - **BREAKING CHANGE:** The REST and RequestManager classes now extend AsyncEventEmitter
+from `@vladfrangu/async_event_emitter`, which aids in cross-compatibility
+between Node, Deno, Bun, CF Workers, Vercel Functions, etc. + - **BREAKING CHANGE:** DefaultUserAgentAppendix has been adapted to support multiple
+different platforms (previously mentioned Deno, Bun, CF Workers, etc) + - **BREAKING CHANGE:** the entry point for `@discordjs/rest` will now differ
+in non-node-like environments (CF Workers, etc.) + - **Co-authored-by:** Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> + - **Co-authored-by:** Jiralite <33201955+Jiralite@users.noreply.github.com> + - **Co-authored-by:** suneettipirneni <suneettipirneni@icloud.com> + +## Refactor + +- **WebSocketShard:** Throttling error handling (#9701) ([ceab07b](https://github.com/discordjs/discord.js/commit/ceab07bec85c8d678958b8023a9c1902136f9f83)) +- **rest:** Switch api to fetch-like and provide strategies (#9416) ([cdaa0a3](https://github.com/discordjs/discord.js/commit/cdaa0a36f586459f1e5ede868c4250c7da90455c)) + - **BREAKING CHANGE:** NodeJS v18+ is required when using node due to the use of global `fetch` + - **BREAKING CHANGE:** The raw method of REST now returns a web compatible `Respone` object. + - **BREAKING CHANGE:** The `parseResponse` utility method has been updated to operate on a web compatible `Response` object. + - **BREAKING CHANGE:** Many underlying internals have changed, some of which were exported. + - **BREAKING CHANGE:** `DefaultRestOptions` used to contain a default `agent`, which is now set to `null` instead. + +# [@discordjs/ws@0.8.3](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.2...@discordjs/ws@0.8.3) - (2023-05-06) + +## Bug Fixes + +- **WebSocketShard:** Wait a little before reconnecting (#9517) ([00da44a](https://github.com/discordjs/discord.js/commit/00da44a120fb0eeb2bdc3a03670836a544dc5418)) + +## Testing + +- **ws:** Fix tests (#9520) ([3e80f0b](https://github.com/discordjs/discord.js/commit/3e80f0b384ea2dc14c1b60b5897e90040cab9a24)) + +# [@discordjs/ws@0.8.2](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.1...@discordjs/ws@0.8.2) - (2023-05-01) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/ws@0.8.1](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.0...@discordjs/ws@0.8.1) - (2023-04-16) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Refactor + +- Abstract identify throttling and correct max_concurrency handling (#9375) ([02dfaf1](https://github.com/discordjs/discord.js/commit/02dfaf1aa2c798315d0dd7f809cc469771b36ffc)) +- **WebSocketShard:** WaitForEvent and its error handling (#9282) ([dcf58d8](https://github.com/discordjs/discord.js/commit/dcf58d81401387a5e157b20829aa56638e106e9d)) + +# [@discordjs/ws@1.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.3...@discordjs/ws@1.0.0) - (2023-07-31) + +## Bug Fixes + +- **WebSocketShard:** Close errors not being catchable (#9704) ([8c782bf](https://github.com/discordjs/discord.js/commit/8c782bfd52b1d7bbfbf1dfd39d0c45828298e285)) +- **WebSocketManager:** Always cache result of fetchGatewayInformation (#9611) ([df8b6e9](https://github.com/discordjs/discord.js/commit/df8b6e9934af5b21aa2701ce54244c38a5f133e0)) +- **WebSocketShard:** Handle initial connect being a resume (#9549) ([4dcc9c5](https://github.com/discordjs/discord.js/commit/4dcc9c50f83cd234cb2c2ede47fb505ffb75eef2)) + +## Features + +- No-de-no-de, now with extra buns (#9683) ([386f206](https://github.com/discordjs/discord.js/commit/386f206caf74a04c426799af9796ca96dcb37056)) + - **BREAKING CHANGE:** The REST and RequestManager classes now extend AsyncEventEmitter
+from `@vladfrangu/async_event_emitter`, which aids in cross-compatibility
+between Node, Deno, Bun, CF Workers, Vercel Functions, etc. + - **BREAKING CHANGE:** DefaultUserAgentAppendix has been adapted to support multiple
+different platforms (previously mentioned Deno, Bun, CF Workers, etc) + - **BREAKING CHANGE:** the entry point for `@discordjs/rest` will now differ
+in non-node-like environments (CF Workers, etc.) + - **Co-authored-by:** Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> + - **Co-authored-by:** Jiralite <33201955+Jiralite@users.noreply.github.com> + - **Co-authored-by:** suneettipirneni <suneettipirneni@icloud.com> + +## Refactor + +- **WebSocketShard:** Throttling error handling (#9701) ([ceab07b](https://github.com/discordjs/discord.js/commit/ceab07bec85c8d678958b8023a9c1902136f9f83)) +- **rest:** Switch api to fetch-like and provide strategies (#9416) ([cdaa0a3](https://github.com/discordjs/discord.js/commit/cdaa0a36f586459f1e5ede868c4250c7da90455c)) + - **BREAKING CHANGE:** NodeJS v18+ is required when using node due to the use of global `fetch` + - **BREAKING CHANGE:** The raw method of REST now returns a web compatible `Respone` object. + - **BREAKING CHANGE:** The `parseResponse` utility method has been updated to operate on a web compatible `Response` object. + - **BREAKING CHANGE:** Many underlying internals have changed, some of which were exported. + - **BREAKING CHANGE:** `DefaultRestOptions` used to contain a default `agent`, which is now set to `null` instead. + +# [@discordjs/ws@0.8.3](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.2...@discordjs/ws@0.8.3) - (2023-05-06) + +## Bug Fixes + +- **WebSocketShard:** Wait a little before reconnecting (#9517) ([00da44a](https://github.com/discordjs/discord.js/commit/00da44a120fb0eeb2bdc3a03670836a544dc5418)) + +## Testing + +- **ws:** Fix tests (#9520) ([3e80f0b](https://github.com/discordjs/discord.js/commit/3e80f0b384ea2dc14c1b60b5897e90040cab9a24)) + +# [@discordjs/ws@0.8.2](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.1...@discordjs/ws@0.8.2) - (2023-05-01) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/ws@0.8.1](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.0...@discordjs/ws@0.8.1) - (2023-04-16) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Refactor + +- Abstract identify throttling and correct max_concurrency handling (#9375) ([02dfaf1](https://github.com/discordjs/discord.js/commit/02dfaf1aa2c798315d0dd7f809cc469771b36ffc)) +- **WebSocketShard:** WaitForEvent and its error handling (#9282) ([dcf58d8](https://github.com/discordjs/discord.js/commit/dcf58d81401387a5e157b20829aa56638e106e9d)) + +# [@discordjs/ws@0.8.3](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.2...@discordjs/ws@0.8.3) - (2023-05-06) + +## Bug Fixes + +- **WebSocketShard:** Wait a little before reconnecting (#9517) ([00da44a](https://github.com/discordjs/discord.js/commit/00da44a120fb0eeb2bdc3a03670836a544dc5418)) + +## Testing + +- **ws:** Fix tests (#9520) ([3e80f0b](https://github.com/discordjs/discord.js/commit/3e80f0b384ea2dc14c1b60b5897e90040cab9a24)) + +# [@discordjs/ws@0.8.2](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.1...@discordjs/ws@0.8.2) - (2023-05-01) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/ws@0.8.1](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.0...@discordjs/ws@0.8.1) - (2023-04-16) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Refactor + +- Abstract identify throttling and correct max_concurrency handling (#9375) ([02dfaf1](https://github.com/discordjs/discord.js/commit/02dfaf1aa2c798315d0dd7f809cc469771b36ffc)) +- **WebSocketShard:** WaitForEvent and its error handling (#9282) ([dcf58d8](https://github.com/discordjs/discord.js/commit/dcf58d81401387a5e157b20829aa56638e106e9d)) + +# [@discordjs/ws@0.8.2](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.1...@discordjs/ws@0.8.2) - (2023-05-01) + +## Documentation + +- Generate static imports for types with api-extractor ([98a76db](https://github.com/discordjs/discord.js/commit/98a76db482879f79d6bb2fb2e5fc65ac2c34e2d9)) + +# [@discordjs/ws@0.8.1](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.0...@discordjs/ws@0.8.1) - (2023-04-16) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Refactor + +- Abstract identify throttling and correct max_concurrency handling (#9375) ([02dfaf1](https://github.com/discordjs/discord.js/commit/02dfaf1aa2c798315d0dd7f809cc469771b36ffc)) +- **WebSocketShard:** WaitForEvent and its error handling (#9282) ([dcf58d8](https://github.com/discordjs/discord.js/commit/dcf58d81401387a5e157b20829aa56638e106e9d)) + +# [@discordjs/ws@0.8.1](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.8.0...@discordjs/ws@0.8.1) - (2023-04-16) + +## Bug Fixes + +- Fix external links (#9313) ([a7425c2](https://github.com/discordjs/discord.js/commit/a7425c29c4f23f1b31f4c6a463107ca9eb7fd7e2)) + +## Refactor + +- Abstract identify throttling and correct max_concurrency handling (#9375) ([02dfaf1](https://github.com/discordjs/discord.js/commit/02dfaf1aa2c798315d0dd7f809cc469771b36ffc)) +- **WebSocketShard:** WaitForEvent and its error handling (#9282) ([dcf58d8](https://github.com/discordjs/discord.js/commit/dcf58d81401387a5e157b20829aa56638e106e9d)) + +# [@discordjs/ws@0.8.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.7.0...@discordjs/ws@0.8.0) - (2023-04-01) + +## Bug Fixes + +- **scripts:** Accessing tsComment ([d8d5f31](https://github.com/discordjs/discord.js/commit/d8d5f31d3927fd1de62f1fa3a1a6e454243ad87b)) +- **WebSocketShard:** Don't await #destroy in error bubbling logic (#9276) ([519825a](https://github.com/discordjs/discord.js/commit/519825a651fe22042a73046824d12f03f56ca9e2)) +- **WebSocketShard:** Don't close in #destroy when status is connecting (#9254) ([c76b17d](https://github.com/discordjs/discord.js/commit/c76b17d3b327fb55ef76770d4825e02ab8f26ad1)) +- **WebSocketShard:** Cancel initial heartbeat in destroy (#9244) ([9842082](https://github.com/discordjs/discord.js/commit/98420826bc2296fc392f17e8254cf4ad743ff5af)) + +## Features + +- **website:** Render syntax and mdx on the server (#9086) ([ee5169e](https://github.com/discordjs/discord.js/commit/ee5169e0aadd7bbfcd752aae614ec0f69602b68b)) + +# [@discordjs/ws@0.7.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.6.0...@discordjs/ws@0.7.0) - (2023-03-12) + +## Bug Fixes + +- **WebSocketShard:** #send race condition due to ready state (#9226) ([a99fc64](https://github.com/discordjs/discord.js/commit/a99fc64e3f73c3976617a7ed825fa7d6e9fb3b53)) +- **WebSocketShard:** Wait for hello rather than ready in connect (#9178) ([27e0b32](https://github.com/discordjs/discord.js/commit/27e0b32c5f0fe605f152e6ba67ce3f596137ff01)) +- **WebSocketShard:** Proper error bubbling (#9119) ([9681f34](https://github.com/discordjs/discord.js/commit/9681f348770b0e2ff9b7c96b1c30575dd950e2ed)) +- Ws typo (#9056) ([05a1cbf](https://github.com/discordjs/discord.js/commit/05a1cbfe5479195b0bc9b6f0971fe39f6af6fd77)) + +## Documentation + +- Fix typos (#9127) ([1ba1f23](https://github.com/discordjs/discord.js/commit/1ba1f238f04221ec890fc921678909b5b7d92c26)) +- Fix version export (#9049) ([8b70f49](https://github.com/discordjs/discord.js/commit/8b70f497a1207e30edebdecd12b926c981c13d28)) +- Updated @discordjs/ws README.md to include optional packages (#8973) ([4ee00b6](https://github.com/discordjs/discord.js/commit/4ee00b6534fad39da1fe54fb2c1766b264a020ca)) + +## Features + +- **WebSocketShard:** Heartbeat jitter (#9223) ([6ecff26](https://github.com/discordjs/discord.js/commit/6ecff26ec65ce1d559a3406b396b3190868b1961)) +- **website:** Add support for source file links (#9048) ([f6506e9](https://github.com/discordjs/discord.js/commit/f6506e99c496683ee0ab67db0726b105b929af38)) +- **ws:** Custom workers (#9004) ([828a13b](https://github.com/discordjs/discord.js/commit/828a13b526dde1334e8879e76e664584bdb5db73)) +- **ws:** Metrics (#9005) ([0ff67d8](https://github.com/discordjs/discord.js/commit/0ff67d8e7adee43ff82bbf072dac9a4c7c9fe8c2)) + +## Refactor + +- **WebSocketManager:** Passing in strategy (#9122) ([5c5a583](https://github.com/discordjs/discord.js/commit/5c5a5832b94cd4d371cc99c4f9c3384523dabeeb)) + +## Styling + +- Run prettier (#9041) ([2798ba1](https://github.com/discordjs/discord.js/commit/2798ba1eb3d734f0cf2eeccd2e16cfba6804873b)) + +# [@discordjs/ws@0.6.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.5.0...@discordjs/ws@0.6.0) - (2022-12-16) + +## Bug Fixes + +- **WebSocketShard:** Send ratelimit handling (#8887) ([40b504a](https://github.com/discordjs/discord.js/commit/40b504a2088effc6a467f40ac3cf2a6d736ab209)) + +## Features + +- **core:** Add support for role connections (#8930) ([3d6fa24](https://github.com/discordjs/discord.js/commit/3d6fa248c07b2278504bbe8bafa17a3294971fd9)) + +## Refactor + +- **WebSocketShard:** Identify throttling (#8888) ([8f552a0](https://github.com/discordjs/discord.js/commit/8f552a0e17c0eca71063e7a4353b9b351bcdf9fd)) + +# [@discordjs/ws@0.5.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.4.1...@discordjs/ws@0.5.0) - (2022-11-28) + +## Bug Fixes + +- Pin @types/node version ([9d8179c](https://github.com/discordjs/discord.js/commit/9d8179c6a78e1c7f9976f852804055964d5385d4)) + +## Documentation + +- Remove unused imports (#8744) ([179392d](https://github.com/discordjs/discord.js/commit/179392d6d7d634c6d10f6abb20c072516c1c1d43)) + +## Features + +- New select menus (#8793) ([5152abf](https://github.com/discordjs/discord.js/commit/5152abf7285581abf7689e9050fdc56c4abb1e2b)) + +# [@discordjs/ws@0.4.1](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.4.0...@discordjs/ws@0.4.1) - (2022-10-10) + +## Bug Fixes + +- **WebSocketShard:** Dispatch race condition (#8731) ([c2b6777](https://github.com/discordjs/discord.js/commit/c2b677759b905d6eb3ebcefcec2cb04eb38436bb)) + +# [@discordjs/ws@0.4.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.3.0...@discordjs/ws@0.4.0) - (2022-10-08) + +## Bug Fixes + +- Ws package.json path (#8720) ([7af3c3b](https://github.com/discordjs/discord.js/commit/7af3c3b6f1517a5d14372b5aa0ef3a2ed8633f6f)) +- **WebSocketShard:** Add ready data parameter to ready event (#8705) ([a7eab50](https://github.com/discordjs/discord.js/commit/a7eab50ee3e286ca10e37107d695385251bd044d)) +- Footer / sidebar / deprecation alert ([ba3e0ed](https://github.com/discordjs/discord.js/commit/ba3e0ed348258fe8e51eefb4aa7379a1230616a9)) + +## Documentation + +- Change name (#8604) ([dd5a089](https://github.com/discordjs/discord.js/commit/dd5a08944c258a847fc4377f1d5e953264ab47d0)) + +## Features + +- Web-components (#8715) ([0ac3e76](https://github.com/discordjs/discord.js/commit/0ac3e766bd9dbdeb106483fa4bb085d74de346a2)) +- Add `@discordjs/util` (#8591) ([b2ec865](https://github.com/discordjs/discord.js/commit/b2ec865765bf94181473864a627fb63ea8173fd3)) + +## Refactor + +- Website components (#8600) ([c334157](https://github.com/discordjs/discord.js/commit/c3341570d983aea9ecc419979d5a01de658c9d67)) +- Use `eslint-config-neon` for packages. (#8579) ([edadb9f](https://github.com/discordjs/discord.js/commit/edadb9fe5dfd9ff51a3cfc9b25cb242d3f9f5241)) + +# [@discordjs/ws@0.3.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@0.2.0...@discordjs/ws@0.3.0) - (2022-08-22) + +## Bug Fixes + +- **WebSocketShard#destroy:** Wait for close and cleanup listeners (#8479) ([acdafe6](https://github.com/discordjs/discord.js/commit/acdafe60c7aa1ac5a3d358934c055c297080a944)) +- **WebSocketManager#connect:** Check if we have enough sessions (#8481) ([4fd4252](https://github.com/discordjs/discord.js/commit/4fd42528fea6127e6468a651f9544913c19ade4d)) +- **WebSocketShard:** Always reconnect on disconnected with 1000 (#8405) ([359f688](https://github.com/discordjs/discord.js/commit/359f6885558fcfb3151971ab589077a89ee71a01)) +- **WebSocketShard:** Emit errors directly instead of objects (#8406) ([3161e1a](https://github.com/discordjs/discord.js/commit/3161e1a1acfbf929ecf33958fa1657553dd9bc1e)) + +## Documentation + +- Fence examples in codeblocks ([193b252](https://github.com/discordjs/discord.js/commit/193b252672440a860318d3c2968aedd9cb88e0ce)) + +## Features + +- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007)) +- **website:** Render `@defaultValue` blocks (#8527) ([8028813](https://github.com/discordjs/discord.js/commit/8028813825e7708915ea892760c1003afd60df2f)) +- **website:** Render tsdoc examples (#8494) ([7116647](https://github.com/discordjs/discord.js/commit/7116647947e413da59fbf493ed5251ddcd710ce7)) +- **WebSocketShard:** Support new resume url (#8480) ([bc06cc6](https://github.com/discordjs/discord.js/commit/bc06cc638d2f57ab5c600e8cdb6afc8eb2180166)) + +## Refactor + +- **website:** Adjust typography (#8503) ([0f83402](https://github.com/discordjs/discord.js/commit/0f834029850d2448981596cf082ff59917018d66)) +- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e)) + +# [@discordjs/ws@0.2.0](https://github.com/discordjs/discord.js/tree/@discordjs/ws@0.2.0) - (2022-07-30) + +## Bug Fixes + +- **WebSocketShard:** Account code 1000 with no prior indication (#8399) ([5137bfc](https://github.com/discordjs/discord.js/commit/5137bfc17d763488083b76ee9008611df333272a)) +- **WebSocketShard:** Use correct import (#8357) ([78d4295](https://github.com/discordjs/discord.js/commit/78d4295a40b83ea4f7cc830ff81927cba2d1d3f0)) + +## Features + +- @discordjs/ws (#8260) ([748d727](https://github.com/discordjs/discord.js/commit/748d7271c45796479a29d8ed3101421de09ef867)) diff --git a/node_modules/@discordjs/ws/LICENSE b/node_modules/@discordjs/ws/LICENSE new file mode 100644 index 0000000..f9786ff --- /dev/null +++ b/node_modules/@discordjs/ws/LICENSE @@ -0,0 +1,191 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "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 2022 Noel Buechler + Copyright 2022 Charlotte Cristea + + 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. diff --git a/node_modules/@discordjs/ws/README.md b/node_modules/@discordjs/ws/README.md new file mode 100644 index 0000000..b75c1b2 --- /dev/null +++ b/node_modules/@discordjs/ws/README.md @@ -0,0 +1,196 @@ +<div align="center"> + <br /> + <p> + <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a> + </p> + <br /> + <p> + <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a> + <a href="https://www.npmjs.com/package/@discordjs/ws"><img src="https://img.shields.io/npm/v/@discordjs/ws.svg?maxAge=3600" alt="npm version" /></a> + <a href="https://www.npmjs.com/package/@discordjs/ws"><img src="https://img.shields.io/npm/dt/@discordjs/ws.svg?maxAge=3600" alt="npm downloads" /></a> + <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a> + <a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=ws" alt="Code coverage" /></a> + </p> + <p> + <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a> + <a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a> + </p> +</div> + +## About + +`@discordjs/ws` is a powerful wrapper around Discord's gateway. + +## Installation + +**Node.js 16.11.0 or newer is required.** + +```sh +npm install @discordjs/ws +yarn add @discordjs/ws +pnpm add @discordjs/ws +``` + +### Optional packages + +- [zlib-sync](https://www.npmjs.com/package/zlib-sync) for WebSocket data compression and inflation (`npm install zlib-sync`) +- [bufferutil](https://www.npmjs.com/package/bufferutil) for a much faster WebSocket connection (`npm install bufferutil`) +- [utf-8-validate](https://www.npmjs.com/package/utf-8-validate) in combination with `bufferutil` for much faster WebSocket processing (`npm install utf-8-validate`) + +## Example usage + +```ts +import { WebSocketManager, WebSocketShardEvents, CompressionMethod } from '@discordjs/ws'; +import { REST } from '@discordjs/rest'; + +const rest = new REST().setToken(process.env.DISCORD_TOKEN); +// This example will spawn Discord's recommended shard count, all under the current process. +const manager = new WebSocketManager({ + token: process.env.DISCORD_TOKEN, + intents: 0, // for no intents + rest, + // uncomment if you have zlib-sync installed and want to use compression + // compression: CompressionMethod.ZlibStream, +}); + +manager.on(WebSocketShardEvents.Dispatch, (event) => { + // Process gateway events here. +}); + +await manager.connect(); +``` + +### Specify shards + +```ts +// Spawn 4 shards +const manager = new WebSocketManager({ + token: process.env.DISCORD_TOKEN, + intents: 0, + rest, + shardCount: 4, +}); + +// The manager also supports being responsible for only a subset of your shards: + +// Your bot will run 8 shards overall +// This manager will only take care of 0, 2, 4, and 6 +const manager = new WebSocketManager({ + token: process.env.DISCORD_TOKEN, + intents: 0, + rest, + shardCount: 8, + shardIds: [0, 2, 4, 6], +}); + +// Alternatively, if your shards are consecutive, you can pass in a range +const manager = new WebSocketManager({ + token: process.env.DISCORD_TOKEN, + intents: 0, + rest, + shardCount: 8, + shardIds: { + start: 0, + end: 4, + }, +}); +``` + +### Specify `worker_threads` + +You can also have the shards spawn in worker threads: + +```ts +import { WebSocketManager, WorkerShardingStrategy } from '@discordjs/ws'; +import { REST } from '@discordjs/rest'; + +const rest = new REST().setToken(process.env.DISCORD_TOKEN); +const manager = new WebSocketManager({ + token: process.env.DISCORD_TOKEN, + intents: 0, + rest, + shardCount: 6, + // This will cause 3 workers to spawn, 2 shards per each + buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 }), + // Or maybe you want all your shards under a single worker + buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 'all' }), +}); +``` + +**Note**: By default, this will cause the workers to effectively only be responsible for the WebSocket connection, they simply pass up all the events back to the main process for the manager to emit. If you want to have the workers handle events as well, you can pass in a `workerPath` option to the `WorkerShardingStrategy` constructor: + +```ts +import { WebSocketManager, WorkerShardingStrategy } from '@discordjs/ws'; +import { REST } from '@discordjs/rest'; + +const rest = new REST().setToken(process.env.DISCORD_TOKEN); +const manager = new WebSocketManager({ + token: process.env.DISCORD_TOKEN, + intents: 0, + rest, + buildStrategy: (manager) => + new WorkerShardingStrategy(manager, { + shardsPerWorker: 2, + workerPath: './worker.js', + }), +}); +``` + +And your `worker.ts` file: + +```ts +import { WorkerBootstrapper, WebSocketShardEvents } from '@discordjs/ws'; + +const bootstrapper = new WorkerBootstrapper(); +void bootstrapper.bootstrap({ + // Those will be sent to the main thread for the manager to emit + forwardEvents: [ + WebSocketShardEvents.Closed, + WebSocketShardEvents.Debug, + WebSocketShardEvents.Hello, + WebSocketShardEvents.Ready, + WebSocketShardEvents.Resumed, + ], + shardCallback: (shard) => { + shard.on(WebSocketShardEvents.Dispatch, (event) => { + // Process gateway events here however you want (e.g. send them through a message broker) + // You also have access to shard.id if you need it + }); + }, +}); +``` + +## Links + +- [Website][website] ([source][website-source]) +- [Documentation][documentation] +- [Guide][guide] ([source][guide-source]) + Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library. +- [discord.js Discord server][discord] +- [Discord API Discord server][discord-api] +- [GitHub][source] +- [npm][npm] +- [Related libraries][related-libs] + +## Contributing + +Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the +[documentation][documentation]. +See [the contribution guide][contributing] if you'd like to submit a PR. + +## Help + +If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord]. + +[website]: https://discord.js.org +[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website +[documentation]: https://discord.js.org/docs/packages/ws/stable +[guide]: https://discordjs.guide/ +[guide-source]: https://github.com/discordjs/guide +[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html +[discord]: https://discord.gg/djs +[discord-api]: https://discord.gg/discord-api +[source]: https://github.com/discordjs/discord.js/tree/main/packages/ws +[npm]: https://www.npmjs.com/package/@discordjs/ws +[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries +[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md diff --git a/node_modules/@discordjs/ws/dist/defaultWorker.d.mts b/node_modules/@discordjs/ws/dist/defaultWorker.d.mts new file mode 100644 index 0000000..c9247d4 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/defaultWorker.d.mts @@ -0,0 +1,2 @@ + +export { } diff --git a/node_modules/@discordjs/ws/dist/defaultWorker.d.ts b/node_modules/@discordjs/ws/dist/defaultWorker.d.ts new file mode 100644 index 0000000..c9247d4 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/defaultWorker.d.ts @@ -0,0 +1,2 @@ + +export { } diff --git a/node_modules/@discordjs/ws/dist/defaultWorker.js b/node_modules/@discordjs/ws/dist/defaultWorker.js new file mode 100644 index 0000000..4e19dff --- /dev/null +++ b/node_modules/@discordjs/ws/dist/defaultWorker.js @@ -0,0 +1,1051 @@ +"use strict"; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); + +// src/utils/WorkerBootstrapper.ts +var import_node_worker_threads3 = require("worker_threads"); +var import_collection7 = require("@discordjs/collection"); + +// src/strategies/context/WorkerContextFetchingStrategy.ts +var import_node_worker_threads2 = require("worker_threads"); +var import_collection2 = require("@discordjs/collection"); + +// src/strategies/sharding/WorkerShardingStrategy.ts +var import_node_events = require("events"); +var import_node_path = require("path"); +var import_node_worker_threads = require("worker_threads"); +var import_collection = require("@discordjs/collection"); + +// src/strategies/context/IContextFetchingStrategy.ts +async function managerToFetchingStrategyOptions(manager) { + const { + buildIdentifyThrottler, + buildStrategy, + retrieveSessionInfo, + updateSessionInfo, + shardCount, + shardIds, + rest, + ...managerOptions + } = manager.options; + return { + ...managerOptions, + gatewayInformation: await manager.fetchGatewayInformation(), + shardCount: await manager.getShardCount() + }; +} +__name(managerToFetchingStrategyOptions, "managerToFetchingStrategyOptions"); + +// src/strategies/context/WorkerContextFetchingStrategy.ts +var WorkerContextFetchingStrategy = class { + constructor(options) { + this.options = options; + if (import_node_worker_threads2.isMainThread) { + throw new Error("Cannot instantiate WorkerContextFetchingStrategy on the main thread"); + } + import_node_worker_threads2.parentPort.on("message", (payload) => { + if (payload.op === 3 /* SessionInfoResponse */) { + this.sessionPromises.get(payload.nonce)?.(payload.session); + this.sessionPromises.delete(payload.nonce); + } + if (payload.op === 4 /* ShardIdentifyResponse */) { + const promise = this.waitForIdentifyPromises.get(payload.nonce); + if (payload.ok) { + promise?.resolve(); + } else { + promise?.reject(promise.signal.reason); + } + this.waitForIdentifyPromises.delete(payload.nonce); + } + }); + } + static { + __name(this, "WorkerContextFetchingStrategy"); + } + sessionPromises = new import_collection2.Collection(); + waitForIdentifyPromises = new import_collection2.Collection(); + async retrieveSessionInfo(shardId) { + const nonce = Math.random(); + const payload = { + op: 3 /* RetrieveSessionInfo */, + shardId, + nonce + }; + const promise = new Promise((resolve2) => this.sessionPromises.set(nonce, resolve2)); + import_node_worker_threads2.parentPort.postMessage(payload); + return promise; + } + updateSessionInfo(shardId, sessionInfo) { + const payload = { + op: 4 /* UpdateSessionInfo */, + shardId, + session: sessionInfo + }; + import_node_worker_threads2.parentPort.postMessage(payload); + } + async waitForIdentify(shardId, signal) { + const nonce = Math.random(); + const payload = { + op: 5 /* WaitForIdentify */, + nonce, + shardId + }; + const promise = new Promise( + (resolve2, reject) => ( + // eslint-disable-next-line no-promise-executor-return + this.waitForIdentifyPromises.set(nonce, { signal, resolve: resolve2, reject }) + ) + ); + import_node_worker_threads2.parentPort.postMessage(payload); + const listener = /* @__PURE__ */ __name(() => { + const payload2 = { + op: 8 /* CancelIdentify */, + nonce + }; + import_node_worker_threads2.parentPort.postMessage(payload2); + }, "listener"); + signal.addEventListener("abort", listener); + try { + await promise; + } finally { + signal.removeEventListener("abort", listener); + } + } +}; + +// src/ws/WebSocketShard.ts +var import_node_buffer = require("buffer"); +var import_node_events2 = require("events"); +var import_node_timers = require("timers"); +var import_promises2 = require("timers/promises"); +var import_node_url = require("url"); +var import_node_util = require("util"); +var import_node_zlib = require("zlib"); +var import_collection6 = require("@discordjs/collection"); +var import_util2 = require("@discordjs/util"); +var import_async_queue2 = require("@sapphire/async-queue"); +var import_async_event_emitter = require("@vladfrangu/async_event_emitter"); +var import_v102 = require("discord-api-types/v10"); +var import_ws = require("ws"); + +// src/utils/constants.ts +var import_node_process = __toESM(require("process")); +var import_collection5 = require("@discordjs/collection"); +var import_util = require("@discordjs/util"); +var import_v10 = require("discord-api-types/v10"); + +// src/strategies/sharding/SimpleShardingStrategy.ts +var import_collection3 = require("@discordjs/collection"); + +// src/strategies/context/SimpleContextFetchingStrategy.ts +var SimpleContextFetchingStrategy = class _SimpleContextFetchingStrategy { + constructor(manager, options) { + this.manager = manager; + this.options = options; + } + static { + __name(this, "SimpleContextFetchingStrategy"); + } + // This strategy assumes every shard is running under the same process - therefore we need a single + // IdentifyThrottler per manager. + static throttlerCache = /* @__PURE__ */ new WeakMap(); + static async ensureThrottler(manager) { + const throttler = _SimpleContextFetchingStrategy.throttlerCache.get(manager); + if (throttler) { + return throttler; + } + const newThrottler = await manager.options.buildIdentifyThrottler(manager); + _SimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler); + return newThrottler; + } + async retrieveSessionInfo(shardId) { + return this.manager.options.retrieveSessionInfo(shardId); + } + updateSessionInfo(shardId, sessionInfo) { + return this.manager.options.updateSessionInfo(shardId, sessionInfo); + } + async waitForIdentify(shardId, signal) { + const throttler = await _SimpleContextFetchingStrategy.ensureThrottler(this.manager); + await throttler.waitForIdentify(shardId, signal); + } +}; + +// src/strategies/sharding/SimpleShardingStrategy.ts +var SimpleShardingStrategy = class { + static { + __name(this, "SimpleShardingStrategy"); + } + manager; + shards = new import_collection3.Collection(); + constructor(manager) { + this.manager = manager; + } + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + async spawn(shardIds) { + const strategyOptions = await managerToFetchingStrategyOptions(this.manager); + for (const shardId of shardIds) { + const strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions); + const shard = new WebSocketShard(strategy, shardId); + for (const event of Object.values(WebSocketShardEvents)) { + shard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId })); + } + this.shards.set(shardId, shard); + } + } + /** + * {@inheritDoc IShardingStrategy.connect} + */ + async connect() { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.connect()); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + async destroy(options) { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.destroy(options)); + } + await Promise.all(promises); + this.shards.clear(); + } + /** + * {@inheritDoc IShardingStrategy.send} + */ + async send(shardId, payload) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} not found`); + } + return shard.send(payload); + } + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + async fetchStatus() { + return this.shards.mapValues((shard) => shard.status); + } +}; + +// src/throttling/SimpleIdentifyThrottler.ts +var import_promises = require("timers/promises"); +var import_collection4 = require("@discordjs/collection"); +var import_async_queue = require("@sapphire/async-queue"); +var SimpleIdentifyThrottler = class { + constructor(maxConcurrency) { + this.maxConcurrency = maxConcurrency; + } + static { + __name(this, "SimpleIdentifyThrottler"); + } + states = new import_collection4.Collection(); + /** + * {@inheritDoc IIdentifyThrottler.waitForIdentify} + */ + async waitForIdentify(shardId, signal) { + const key = shardId % this.maxConcurrency; + const state = this.states.ensure(key, () => { + return { + queue: new import_async_queue.AsyncQueue(), + resetsAt: Number.POSITIVE_INFINITY + }; + }); + await state.queue.wait({ signal }); + try { + const diff = state.resetsAt - Date.now(); + if (diff <= 5e3) { + const time = diff + Math.random() * 1500; + await (0, import_promises.setTimeout)(time); + } + state.resetsAt = Date.now() + 5e3; + } finally { + state.queue.shift(); + } + } +}; + +// src/utils/constants.ts +var DefaultDeviceProperty = `@discordjs/ws 1.0.1`; +var getDefaultSessionStore = (0, import_util.lazy)(() => new import_collection5.Collection()); +var DefaultWebSocketManagerOptions = { + async buildIdentifyThrottler(manager) { + const info = await manager.fetchGatewayInformation(); + return new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency); + }, + buildStrategy: (manager) => new SimpleShardingStrategy(manager), + shardCount: null, + shardIds: null, + largeThreshold: null, + initialPresence: null, + identifyProperties: { + browser: DefaultDeviceProperty, + device: DefaultDeviceProperty, + os: import_node_process.default.platform + }, + version: import_v10.APIVersion, + encoding: "json" /* JSON */, + compression: null, + retrieveSessionInfo(shardId) { + const store = getDefaultSessionStore(); + return store.get(shardId) ?? null; + }, + updateSessionInfo(shardId, info) { + const store = getDefaultSessionStore(); + if (info) { + store.set(shardId, info); + } else { + store.delete(shardId); + } + }, + handshakeTimeout: 3e4, + helloTimeout: 6e4, + readyTimeout: 15e3 +}; +var ImportantGatewayOpcodes = /* @__PURE__ */ new Set([ + import_v10.GatewayOpcodes.Heartbeat, + import_v10.GatewayOpcodes.Identify, + import_v10.GatewayOpcodes.Resume +]); +function getInitialSendRateLimitState() { + return { + remaining: 120, + resetAt: Date.now() + 6e4 + }; +} +__name(getInitialSendRateLimitState, "getInitialSendRateLimitState"); + +// src/ws/WebSocketShard.ts +var getZlibSync = (0, import_util2.lazy)(async () => import("zlib-sync").then((mod) => mod.default).catch(() => null)); +var WebSocketShardEvents = /* @__PURE__ */ ((WebSocketShardEvents2) => { + WebSocketShardEvents2["Closed"] = "closed"; + WebSocketShardEvents2["Debug"] = "debug"; + WebSocketShardEvents2["Dispatch"] = "dispatch"; + WebSocketShardEvents2["Error"] = "error"; + WebSocketShardEvents2["HeartbeatComplete"] = "heartbeat"; + WebSocketShardEvents2["Hello"] = "hello"; + WebSocketShardEvents2["Ready"] = "ready"; + WebSocketShardEvents2["Resumed"] = "resumed"; + return WebSocketShardEvents2; +})(WebSocketShardEvents || {}); +var WebSocketShardDestroyRecovery = /* @__PURE__ */ ((WebSocketShardDestroyRecovery2) => { + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Reconnect"] = 0] = "Reconnect"; + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Resume"] = 1] = "Resume"; + return WebSocketShardDestroyRecovery2; +})(WebSocketShardDestroyRecovery || {}); +var WebSocketConstructor = import_ws.WebSocket; +var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter { + static { + __name(this, "WebSocketShard"); + } + connection = null; + useIdentifyCompress = false; + inflate = null; + textDecoder = new import_node_util.TextDecoder(); + replayedEvents = 0; + isAck = true; + sendRateLimitState = getInitialSendRateLimitState(); + initialHeartbeatTimeoutController = null; + heartbeatInterval = null; + lastHeartbeatAt = -1; + // Indicates whether the shard has already resolved its original connect() call + initialConnectResolved = false; + // Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET) + failedToConnectDueToNetworkError = false; + sendQueue = new import_async_queue2.AsyncQueue(); + timeoutAbortControllers = new import_collection6.Collection(); + strategy; + id; + #status = 0 /* Idle */; + get status() { + return this.#status; + } + constructor(strategy, id) { + super(); + this.strategy = strategy; + this.id = id; + } + async connect() { + const controller = new AbortController(); + let promise; + if (!this.initialConnectResolved) { + promise = Promise.race([ + (0, import_node_events2.once)(this, "ready" /* Ready */, { signal: controller.signal }), + (0, import_node_events2.once)(this, "resumed" /* Resumed */, { signal: controller.signal }) + ]); + } + void this.internalConnect(); + try { + await promise; + } catch ({ error }) { + throw error; + } finally { + controller.abort(); + } + this.initialConnectResolved = true; + } + async internalConnect() { + if (this.#status !== 0 /* Idle */) { + throw new Error("Tried to connect a shard that wasn't idle"); + } + const { version, encoding, compression } = this.strategy.options; + const params = new import_node_url.URLSearchParams({ v: version, encoding }); + if (compression) { + const zlib = await getZlibSync(); + if (zlib) { + params.append("compress", compression); + this.inflate = new zlib.Inflate({ + chunkSize: 65535, + to: "string" + }); + } else if (!this.useIdentifyCompress) { + this.useIdentifyCompress = true; + console.warn( + "WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress" + ); + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + const url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`; + this.debug([`Connecting to ${url}`]); + const connection = new WebSocketConstructor(url, { + handshakeTimeout: this.strategy.options.handshakeTimeout ?? void 0 + }); + connection.binaryType = "arraybuffer"; + connection.onmessage = (event) => { + void this.onMessage(event.data, event.data instanceof ArrayBuffer); + }; + connection.onerror = (event) => { + this.onError(event.error); + }; + connection.onclose = (event) => { + void this.onClose(event.code); + }; + this.connection = connection; + this.#status = 1 /* Connecting */; + this.sendRateLimitState = getInitialSendRateLimitState(); + const { ok } = await this.waitForEvent("hello" /* Hello */, this.strategy.options.helloTimeout); + if (!ok) { + return; + } + if (session?.shardCount === this.strategy.options.shardCount) { + await this.resume(session); + } else { + await this.identify(); + } + } + async destroy(options = {}) { + if (this.#status === 0 /* Idle */) { + this.debug(["Tried to destroy a shard that was idle"]); + return; + } + if (!options.code) { + options.code = options.recover === 1 /* Resume */ ? 4200 /* Resuming */ : 1e3 /* Normal */; + } + this.debug([ + "Destroying shard", + `Reason: ${options.reason ?? "none"}`, + `Code: ${options.code}`, + `Recover: ${options.recover === void 0 ? "none" : WebSocketShardDestroyRecovery[options.recover]}` + ]); + this.isAck = true; + if (this.heartbeatInterval) { + (0, import_node_timers.clearInterval)(this.heartbeatInterval); + } + if (this.initialHeartbeatTimeoutController) { + this.initialHeartbeatTimeoutController.abort(); + this.initialHeartbeatTimeoutController = null; + } + this.lastHeartbeatAt = -1; + for (const controller of this.timeoutAbortControllers.values()) { + controller.abort(); + } + this.timeoutAbortControllers.clear(); + this.failedToConnectDueToNetworkError = false; + if (options.recover !== 1 /* Resume */) { + await this.strategy.updateSessionInfo(this.id, null); + } + if (this.connection) { + this.connection.onmessage = null; + this.connection.onclose = null; + const shouldClose = this.connection.readyState === import_ws.WebSocket.OPEN; + this.debug([ + "Connection status during destroy", + `Needs closing: ${shouldClose}`, + `Ready state: ${this.connection.readyState}` + ]); + if (shouldClose) { + let outerResolve; + const promise = new Promise((resolve2) => { + outerResolve = resolve2; + }); + this.connection.onclose = outerResolve; + this.connection.close(options.code, options.reason); + await promise; + this.emit("closed" /* Closed */, { code: options.code }); + } + this.connection.onerror = null; + } else { + this.debug(["Destroying a shard that has no connection; please open an issue on GitHub"]); + } + this.#status = 0 /* Idle */; + if (options.recover !== void 0) { + await (0, import_promises2.setTimeout)(500); + return this.internalConnect(); + } + } + async waitForEvent(event, timeoutDuration) { + this.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : "indefinitely"}`]); + const timeoutController = new AbortController(); + const timeout = timeoutDuration ? (0, import_node_timers.setTimeout)(() => timeoutController.abort(), timeoutDuration).unref() : null; + this.timeoutAbortControllers.set(event, timeoutController); + const closeController = new AbortController(); + try { + const closed = await Promise.race([ + (0, import_node_events2.once)(this, event, { signal: timeoutController.signal }).then(() => false), + (0, import_node_events2.once)(this, "closed" /* Closed */, { signal: closeController.signal }).then(() => true) + ]); + return { ok: !closed }; + } catch { + void this.destroy({ + code: 1e3 /* Normal */, + reason: "Something timed out or went wrong while waiting for an event", + recover: 0 /* Reconnect */ + }); + return { ok: false }; + } finally { + if (timeout) { + (0, import_node_timers.clearTimeout)(timeout); + } + this.timeoutAbortControllers.delete(event); + if (!closeController.signal.aborted) { + closeController.abort(); + } + } + } + async send(payload) { + if (!this.connection) { + throw new Error("WebSocketShard wasn't connected"); + } + if (this.#status !== 3 /* Ready */ && !ImportantGatewayOpcodes.has(payload.op)) { + this.debug(["Tried to send a non-crucial payload before the shard was ready, waiting"]); + try { + await (0, import_node_events2.once)(this, "ready" /* Ready */); + } catch { + return this.send(payload); + } + } + await this.sendQueue.wait(); + if (--this.sendRateLimitState.remaining <= 0) { + const now = Date.now(); + if (this.sendRateLimitState.resetAt > now) { + const sleepFor = this.sendRateLimitState.resetAt - now; + this.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]); + const controller = new AbortController(); + const interrupted = await Promise.race([ + (0, import_promises2.setTimeout)(sleepFor).then(() => false), + (0, import_node_events2.once)(this, "closed" /* Closed */, { signal: controller.signal }).then(() => true) + ]); + if (interrupted) { + this.debug(["Connection closed while waiting for the send rate limit to reset, re-queueing payload"]); + this.sendQueue.shift(); + return this.send(payload); + } + controller.abort(); + } + this.sendRateLimitState = getInitialSendRateLimitState(); + } + this.sendQueue.shift(); + this.connection.send(JSON.stringify(payload)); + } + async identify() { + this.debug(["Waiting for identify throttle"]); + const controller = new AbortController(); + const closeHandler = /* @__PURE__ */ __name(() => { + controller.abort(); + }, "closeHandler"); + this.on("closed" /* Closed */, closeHandler); + try { + await this.strategy.waitForIdentify(this.id, controller.signal); + } catch { + if (controller.signal.aborted) { + this.debug(["Was waiting for an identify, but the shard closed in the meantime"]); + return; + } + this.debug([ + "IContextFetchingStrategy#waitForIdentify threw an unknown error.", + "If you're using a custom strategy, this is probably nothing to worry about.", + "If you're not, please open an issue on GitHub." + ]); + await this.destroy({ + reason: "Identify throttling logic failed", + recover: 1 /* Resume */ + }); + } finally { + this.off("closed" /* Closed */, closeHandler); + } + this.debug([ + "Identifying", + `shard id: ${this.id.toString()}`, + `shard count: ${this.strategy.options.shardCount}`, + `intents: ${this.strategy.options.intents}`, + `compression: ${this.inflate ? "zlib-stream" : this.useIdentifyCompress ? "identify" : "none"}` + ]); + const d = { + token: this.strategy.options.token, + properties: this.strategy.options.identifyProperties, + intents: this.strategy.options.intents, + compress: this.useIdentifyCompress, + shard: [this.id, this.strategy.options.shardCount] + }; + if (this.strategy.options.largeThreshold) { + d.large_threshold = this.strategy.options.largeThreshold; + } + if (this.strategy.options.initialPresence) { + d.presence = this.strategy.options.initialPresence; + } + await this.send({ + op: import_v102.GatewayOpcodes.Identify, + d + }); + await this.waitForEvent("ready" /* Ready */, this.strategy.options.readyTimeout); + } + async resume(session) { + this.debug([ + "Resuming session", + `resume url: ${session.resumeURL}`, + `sequence: ${session.sequence}`, + `shard id: ${this.id.toString()}` + ]); + this.#status = 2 /* Resuming */; + this.replayedEvents = 0; + return this.send({ + op: import_v102.GatewayOpcodes.Resume, + d: { + token: this.strategy.options.token, + seq: session.sequence, + session_id: session.sessionId + } + }); + } + async heartbeat(requested = false) { + if (!this.isAck && !requested) { + return this.destroy({ reason: "Zombie connection", recover: 1 /* Resume */ }); + } + const session = await this.strategy.retrieveSessionInfo(this.id); + await this.send({ + op: import_v102.GatewayOpcodes.Heartbeat, + d: session?.sequence ?? null + }); + this.lastHeartbeatAt = Date.now(); + this.isAck = false; + } + async unpackMessage(data, isBinary) { + if (!isBinary) { + try { + return JSON.parse(data); + } catch { + return null; + } + } + const decompressable = new Uint8Array(data); + if (this.useIdentifyCompress) { + return new Promise((resolve2, reject) => { + (0, import_node_zlib.inflate)(decompressable, { chunkSize: 65535 }, (err, result) => { + if (err) { + reject(err); + return; + } + resolve2(JSON.parse(this.textDecoder.decode(result))); + }); + }); + } + if (this.inflate) { + const l = decompressable.length; + const flush = l >= 4 && decompressable[l - 4] === 0 && decompressable[l - 3] === 0 && decompressable[l - 2] === 255 && decompressable[l - 1] === 255; + const zlib = await getZlibSync(); + this.inflate.push(import_node_buffer.Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH); + if (this.inflate.err) { + this.emit("error" /* Error */, { + error: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ""}`) + }); + } + if (!flush) { + return null; + } + const { result } = this.inflate; + if (!result) { + return null; + } + return JSON.parse(typeof result === "string" ? result : this.textDecoder.decode(result)); + } + this.debug([ + "Received a message we were unable to decompress", + `isBinary: ${isBinary.toString()}`, + `useIdentifyCompress: ${this.useIdentifyCompress.toString()}`, + `inflate: ${Boolean(this.inflate).toString()}` + ]); + return null; + } + async onMessage(data, isBinary) { + const payload = await this.unpackMessage(data, isBinary); + if (!payload) { + return; + } + switch (payload.op) { + case import_v102.GatewayOpcodes.Dispatch: { + if (this.#status === 2 /* Resuming */) { + this.replayedEvents++; + } + switch (payload.t) { + case import_v102.GatewayDispatchEvents.Ready: { + this.#status = 3 /* Ready */; + const session2 = { + sequence: payload.s, + sessionId: payload.d.session_id, + shardId: this.id, + shardCount: this.strategy.options.shardCount, + resumeURL: payload.d.resume_gateway_url + }; + await this.strategy.updateSessionInfo(this.id, session2); + this.emit("ready" /* Ready */, { data: payload.d }); + break; + } + case import_v102.GatewayDispatchEvents.Resumed: { + this.#status = 3 /* Ready */; + this.debug([`Resumed and replayed ${this.replayedEvents} events`]); + this.emit("resumed" /* Resumed */); + break; + } + default: { + break; + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + if (session) { + if (payload.s > session.sequence) { + await this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s }); + } + } else { + this.debug([ + `Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect` + ]); + } + this.emit("dispatch" /* Dispatch */, { data: payload }); + break; + } + case import_v102.GatewayOpcodes.Heartbeat: { + await this.heartbeat(true); + break; + } + case import_v102.GatewayOpcodes.Reconnect: { + await this.destroy({ + reason: "Told to reconnect by Discord", + recover: 1 /* Resume */ + }); + break; + } + case import_v102.GatewayOpcodes.InvalidSession: { + this.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]); + const session = await this.strategy.retrieveSessionInfo(this.id); + if (payload.d && session) { + await this.resume(session); + } else { + await this.destroy({ + reason: "Invalid session", + recover: 0 /* Reconnect */ + }); + } + break; + } + case import_v102.GatewayOpcodes.Hello: { + this.emit("hello" /* Hello */); + const jitter = Math.random(); + const firstWait = Math.floor(payload.d.heartbeat_interval * jitter); + this.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]); + try { + const controller = new AbortController(); + this.initialHeartbeatTimeoutController = controller; + await (0, import_promises2.setTimeout)(firstWait, void 0, { signal: controller.signal }); + } catch { + this.debug(["Cancelled initial heartbeat due to #destroy being called"]); + return; + } finally { + this.initialHeartbeatTimeoutController = null; + } + await this.heartbeat(); + this.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]); + this.heartbeatInterval = (0, import_node_timers.setInterval)(() => void this.heartbeat(), payload.d.heartbeat_interval); + break; + } + case import_v102.GatewayOpcodes.HeartbeatAck: { + this.isAck = true; + const ackAt = Date.now(); + this.emit("heartbeat" /* HeartbeatComplete */, { + ackAt, + heartbeatAt: this.lastHeartbeatAt, + latency: ackAt - this.lastHeartbeatAt + }); + break; + } + } + } + onError(error) { + if ("code" in error && ["ECONNRESET", "ECONNREFUSED"].includes(error.code)) { + this.debug(["Failed to connect to the gateway URL specified due to a network error"]); + this.failedToConnectDueToNetworkError = true; + return; + } + this.emit("error" /* Error */, { error }); + } + async onClose(code) { + this.emit("closed" /* Closed */, { code }); + switch (code) { + case 1e3 /* Normal */: { + return this.destroy({ + code, + reason: "Got disconnected by Discord", + recover: 0 /* Reconnect */ + }); + } + case 4200 /* Resuming */: { + break; + } + case import_v102.GatewayCloseCodes.UnknownError: { + this.debug([`An unknown error occurred: ${code}`]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.UnknownOpcode: { + this.debug(["An invalid opcode was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.DecodeError: { + this.debug(["An invalid payload was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.NotAuthenticated: { + this.debug(["A request was somehow sent before the identify/resume payload."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.AuthenticationFailed: { + this.emit("error" /* Error */, { + error: new Error("Authentication failed") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.AlreadyAuthenticated: { + this.debug(["More than one auth payload was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.InvalidSeq: { + this.debug(["An invalid sequence was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.RateLimited: { + this.debug(["The WebSocket rate limit has been hit, this should never happen"]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.SessionTimedOut: { + this.debug(["Session timed out."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.InvalidShard: { + this.emit("error" /* Error */, { + error: new Error("Invalid shard") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.ShardingRequired: { + this.emit("error" /* Error */, { + error: new Error("Sharding is required") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.InvalidAPIVersion: { + this.emit("error" /* Error */, { + error: new Error("Used an invalid API version") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.InvalidIntents: { + this.emit("error" /* Error */, { + error: new Error("Used invalid intents") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.DisallowedIntents: { + this.emit("error" /* Error */, { + error: new Error("Used disallowed intents") + }); + return this.destroy({ code }); + } + default: { + this.debug([ + `The gateway closed with an unexpected code ${code}, attempting to ${this.failedToConnectDueToNetworkError ? "reconnect" : "resume"}.` + ]); + return this.destroy({ + code, + recover: this.failedToConnectDueToNetworkError ? 0 /* Reconnect */ : 1 /* Resume */ + }); + } + } + } + debug(messages) { + const message = `${messages[0]}${messages.length > 1 ? ` +${messages.slice(1).map((m) => ` ${m}`).join("\n")}` : ""}`; + this.emit("debug" /* Debug */, { message }); + } +}; + +// src/utils/WorkerBootstrapper.ts +var WorkerBootstrapper = class { + static { + __name(this, "WorkerBootstrapper"); + } + /** + * The data passed to the worker thread + */ + data = import_node_worker_threads3.workerData; + /** + * The shards that are managed by this worker + */ + shards = new import_collection7.Collection(); + constructor() { + if (import_node_worker_threads3.isMainThread) { + throw new Error("Expected WorkerBootstrap to not be used within the main thread"); + } + } + /** + * Helper method to initiate a shard's connection process + */ + async connect(shardId) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.connect(); + } + /** + * Helper method to destroy a shard + */ + async destroy(shardId, options) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.destroy(options); + } + /** + * Helper method to attach event listeners to the parentPort + */ + setupThreadEvents() { + import_node_worker_threads3.parentPort.on("messageerror", (err) => { + throw err; + }).on("message", async (payload) => { + switch (payload.op) { + case 0 /* Connect */: { + await this.connect(payload.shardId); + const response = { + op: 0 /* Connected */, + shardId: payload.shardId + }; + import_node_worker_threads3.parentPort.postMessage(response); + break; + } + case 1 /* Destroy */: { + await this.destroy(payload.shardId, payload.options); + const response = { + op: 1 /* Destroyed */, + shardId: payload.shardId + }; + import_node_worker_threads3.parentPort.postMessage(response); + break; + } + case 2 /* Send */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new RangeError(`Shard ${payload.shardId} does not exist`); + } + await shard.send(payload.payload); + break; + } + case 3 /* SessionInfoResponse */: { + break; + } + case 4 /* ShardIdentifyResponse */: { + break; + } + case 5 /* FetchStatus */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new Error(`Shard ${payload.shardId} does not exist`); + } + const response = { + op: 6 /* FetchStatusResponse */, + status: shard.status, + nonce: payload.nonce + }; + import_node_worker_threads3.parentPort.postMessage(response); + break; + } + } + }); + } + /** + * Bootstraps the worker thread with the provided options + */ + async bootstrap(options = {}) { + for (const shardId of this.data.shardIds) { + const shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId); + for (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) { + shard.on(event, (data) => { + const payload = { + op: 2 /* Event */, + event, + data, + shardId + }; + import_node_worker_threads3.parentPort.postMessage(payload); + }); + } + await options.shardCallback?.(shard); + this.shards.set(shardId, shard); + } + this.setupThreadEvents(); + const message = { + op: 7 /* WorkerReady */ + }; + import_node_worker_threads3.parentPort.postMessage(message); + } +}; + +// src/strategies/sharding/defaultWorker.ts +var bootstrapper = new WorkerBootstrapper(); +void bootstrapper.bootstrap(); +//# sourceMappingURL=defaultWorker.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/dist/defaultWorker.js.map b/node_modules/@discordjs/ws/dist/defaultWorker.js.map new file mode 100644 index 0000000..1daa8d6 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/defaultWorker.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/utils/WorkerBootstrapper.ts","../src/strategies/context/WorkerContextFetchingStrategy.ts","../src/strategies/sharding/WorkerShardingStrategy.ts","../src/strategies/context/IContextFetchingStrategy.ts","../src/ws/WebSocketShard.ts","../src/utils/constants.ts","../src/strategies/sharding/SimpleShardingStrategy.ts","../src/strategies/context/SimpleContextFetchingStrategy.ts","../src/throttling/SimpleIdentifyThrottler.ts","../src/strategies/sharding/defaultWorker.ts"],"sourcesContent":["import { isMainThread, parentPort, workerData } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { Awaitable } from '@discordjs/util';\nimport { WorkerContextFetchingStrategy } from '../strategies/context/WorkerContextFetchingStrategy.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerData,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../strategies/sharding/WorkerShardingStrategy.js';\nimport type { WebSocketShardDestroyOptions } from '../ws/WebSocketShard.js';\nimport { WebSocketShardEvents, WebSocketShard } from '../ws/WebSocketShard.js';\n\n/**\n * Options for bootstrapping the worker\n */\nexport interface BootstrapOptions {\n\t/**\n\t * Shard events to just arbitrarily forward to the parent thread for the manager to emit\n\t * Note: By default, this will include ALL events\n\t * you most likely want to handle dispatch within the worker itself\n\t */\n\tforwardEvents?: WebSocketShardEvents[];\n\t/**\n\t * Function to call when a shard is created for additional setup\n\t */\n\tshardCallback?(shard: WebSocketShard): Awaitable<void>;\n}\n\n/**\n * Utility class for bootstrapping a worker thread to be used for sharding\n */\nexport class WorkerBootstrapper {\n\t/**\n\t * The data passed to the worker thread\n\t */\n\tprotected readonly data = workerData as WorkerData;\n\n\t/**\n\t * The shards that are managed by this worker\n\t */\n\tprotected readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor() {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Expected WorkerBootstrap to not be used within the main thread');\n\t\t}\n\t}\n\n\t/**\n\t * Helper method to initiate a shard's connection process\n\t */\n\tprotected async connect(shardId: number): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.connect();\n\t}\n\n\t/**\n\t * Helper method to destroy a shard\n\t */\n\tprotected async destroy(shardId: number, options?: WebSocketShardDestroyOptions): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.destroy(options);\n\t}\n\n\t/**\n\t * Helper method to attach event listeners to the parentPort\n\t */\n\tprotected setupThreadEvents(): void {\n\t\tparentPort!\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerSendPayload) => {\n\t\t\t\tswitch (payload.op) {\n\t\t\t\t\tcase WorkerSendPayloadOp.Connect: {\n\t\t\t\t\t\tawait this.connect(payload.shardId);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Connected,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Destroy: {\n\t\t\t\t\t\tawait this.destroy(payload.shardId, payload.options);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Destroyed,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Send: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new RangeError(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait shard.send(payload.payload);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.SessionInfoResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.ShardIdentifyResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.FetchStatus: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new Error(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.FetchStatusResponse,\n\t\t\t\t\t\t\tstatus: shard.status,\n\t\t\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\t/**\n\t * Bootstraps the worker thread with the provided options\n\t */\n\tpublic async bootstrap(options: Readonly<BootstrapOptions> = {}): Promise<void> {\n\t\t// Start by initializing the shards\n\t\tfor (const shardId of this.data.shardIds) {\n\t\t\tconst shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId);\n\t\t\tfor (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Event types incompatible\n\t\t\t\tshard.on(event, (data) => {\n\t\t\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\t\t\top: WorkerReceivePayloadOp.Event,\n\t\t\t\t\t\tevent,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tshardId,\n\t\t\t\t\t};\n\t\t\t\t\tparentPort!.postMessage(payload);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Any additional setup the user might want to do\n\t\t\tawait options.shardCallback?.(shard);\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\n\t\t// Lastly, start listening to messages from the parent thread\n\t\tthis.setupThreadEvents();\n\n\t\tconst message: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WorkerReady,\n\t\t};\n\t\tparentPort!.postMessage(message);\n\t}\n}\n","import { isMainThread, parentPort } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { SessionInfo } from '../../ws/WebSocketManager.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../sharding/WorkerShardingStrategy.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class WorkerContextFetchingStrategy implements IContextFetchingStrategy {\n\tprivate readonly sessionPromises = new Collection<number, (session: SessionInfo | null) => void>();\n\n\tprivate readonly waitForIdentifyPromises = new Collection<\n\t\tnumber,\n\t\t{ reject(error: unknown): void; resolve(): void; signal: AbortSignal }\n\t>();\n\n\tpublic constructor(public readonly options: FetchingStrategyOptions) {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Cannot instantiate WorkerContextFetchingStrategy on the main thread');\n\t\t}\n\n\t\tparentPort!.on('message', (payload: WorkerSendPayload) => {\n\t\t\tif (payload.op === WorkerSendPayloadOp.SessionInfoResponse) {\n\t\t\t\tthis.sessionPromises.get(payload.nonce)?.(payload.session);\n\t\t\t\tthis.sessionPromises.delete(payload.nonce);\n\t\t\t}\n\n\t\t\tif (payload.op === WorkerSendPayloadOp.ShardIdentifyResponse) {\n\t\t\t\tconst promise = this.waitForIdentifyPromises.get(payload.nonce);\n\t\t\t\tif (payload.ok) {\n\t\t\t\t\tpromise?.resolve();\n\t\t\t\t} else {\n\t\t\t\t\t// We need to make sure we reject with an abort error\n\t\t\t\t\tpromise?.reject(promise.signal.reason);\n\t\t\t\t}\n\n\t\t\t\tthis.waitForIdentifyPromises.delete(payload.nonce);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\tconst nonce = Math.random();\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.RetrieveSessionInfo,\n\t\t\tshardId,\n\t\t\tnonce,\n\t\t};\n\t\t// eslint-disable-next-line no-promise-executor-return\n\t\tconst promise = new Promise<SessionInfo | null>((resolve) => this.sessionPromises.set(nonce, resolve));\n\t\tparentPort!.postMessage(payload);\n\t\treturn promise;\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.UpdateSessionInfo,\n\t\t\tshardId,\n\t\t\tsession: sessionInfo,\n\t\t};\n\t\tparentPort!.postMessage(payload);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst nonce = Math.random();\n\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WaitForIdentify,\n\t\t\tnonce,\n\t\t\tshardId,\n\t\t};\n\t\tconst promise = new Promise<void>((resolve, reject) =>\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tthis.waitForIdentifyPromises.set(nonce, { signal, resolve, reject }),\n\t\t);\n\n\t\tparentPort!.postMessage(payload);\n\n\t\tconst listener = () => {\n\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\top: WorkerReceivePayloadOp.CancelIdentify,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\tparentPort!.postMessage(payload);\n\t\t};\n\n\t\tsignal.addEventListener('abort', listener);\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} finally {\n\t\t\tsignal.removeEventListener('abort', listener);\n\t\t}\n\t}\n}\n","import { once } from 'node:events';\nimport { join, isAbsolute, resolve } from 'node:path';\nimport { Worker } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type {\n\tWebSocketShardDestroyOptions,\n\tWebSocketShardEvents,\n\tWebSocketShardStatus,\n} from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions, type FetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\nexport interface WorkerData extends FetchingStrategyOptions {\n\tshardIds: number[];\n}\n\nexport enum WorkerSendPayloadOp {\n\tConnect,\n\tDestroy,\n\tSend,\n\tSessionInfoResponse,\n\tShardIdentifyResponse,\n\tFetchStatus,\n}\n\nexport type WorkerSendPayload =\n\t| { nonce: number; ok: boolean; op: WorkerSendPayloadOp.ShardIdentifyResponse }\n\t| { nonce: number; op: WorkerSendPayloadOp.FetchStatus; shardId: number }\n\t| { nonce: number; op: WorkerSendPayloadOp.SessionInfoResponse; session: SessionInfo | null }\n\t| { op: WorkerSendPayloadOp.Connect; shardId: number }\n\t| { op: WorkerSendPayloadOp.Destroy; options?: WebSocketShardDestroyOptions; shardId: number }\n\t| { op: WorkerSendPayloadOp.Send; payload: GatewaySendPayload; shardId: number };\n\nexport enum WorkerReceivePayloadOp {\n\tConnected,\n\tDestroyed,\n\tEvent,\n\tRetrieveSessionInfo,\n\tUpdateSessionInfo,\n\tWaitForIdentify,\n\tFetchStatusResponse,\n\tWorkerReady,\n\tCancelIdentify,\n}\n\nexport type WorkerReceivePayload =\n\t// Can't seem to get a type-safe union based off of the event, so I'm sadly leaving data as any for now\n\t| { data: any; event: WebSocketShardEvents; op: WorkerReceivePayloadOp.Event; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.CancelIdentify }\n\t| { nonce: number; op: WorkerReceivePayloadOp.FetchStatusResponse; status: WebSocketShardStatus }\n\t| { nonce: number; op: WorkerReceivePayloadOp.RetrieveSessionInfo; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.WaitForIdentify; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Connected; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Destroyed; shardId: number }\n\t| { op: WorkerReceivePayloadOp.UpdateSessionInfo; session: SessionInfo | null; shardId: number }\n\t| { op: WorkerReceivePayloadOp.WorkerReady };\n\n/**\n * Options for a {@link WorkerShardingStrategy}\n */\nexport interface WorkerShardingStrategyOptions {\n\t/**\n\t * Dictates how many shards should be spawned per worker thread.\n\t */\n\tshardsPerWorker: number | 'all';\n\t/**\n\t * Path to the worker file to use. The worker requires quite a bit of setup, it is recommended you leverage the {@link WorkerBootstrapper} class.\n\t */\n\tworkerPath?: string;\n}\n\n/**\n * Strategy used to spawn threads in worker_threads\n */\nexport class WorkerShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly options: WorkerShardingStrategyOptions;\n\n\t#workers: Worker[] = [];\n\n\treadonly #workerByShardId = new Collection<number, Worker>();\n\n\tprivate readonly connectPromises = new Collection<number, () => void>();\n\n\tprivate readonly destroyPromises = new Collection<number, () => void>();\n\n\tprivate readonly fetchStatusPromises = new Collection<number, (status: WebSocketShardStatus) => void>();\n\n\tprivate readonly waitForIdentifyControllers = new Collection<number, AbortController>();\n\n\tprivate throttler?: IIdentifyThrottler;\n\n\tpublic constructor(manager: WebSocketManager, options: WorkerShardingStrategyOptions) {\n\t\tthis.manager = manager;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst shardsPerWorker = this.options.shardsPerWorker === 'all' ? shardIds.length : this.options.shardsPerWorker;\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tconst loops = Math.ceil(shardIds.length / shardsPerWorker);\n\t\tconst promises: Promise<void>[] = [];\n\n\t\tfor (let idx = 0; idx < loops; idx++) {\n\t\t\tconst slice = shardIds.slice(idx * shardsPerWorker, (idx + 1) * shardsPerWorker);\n\t\t\tconst workerData: WorkerData = {\n\t\t\t\t...strategyOptions,\n\t\t\t\tshardIds: slice,\n\t\t\t};\n\n\t\t\tpromises.push(this.setupWorker(workerData));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Connect,\n\t\t\t\tshardId,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<void>((resolve) => this.connectPromises.set(shardId, resolve));\n\t\t\tworker.postMessage(payload);\n\t\t\tpromises.push(promise);\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options: Omit<WebSocketShardDestroyOptions, 'recover'> = {}) {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Destroy,\n\t\t\t\tshardId,\n\t\t\t\toptions,\n\t\t\t};\n\n\t\t\tpromises.push(\n\t\t\t\t// eslint-disable-next-line no-promise-executor-return, promise/prefer-await-to-then\n\t\t\t\tnew Promise<void>((resolve) => this.destroyPromises.set(shardId, resolve)).then(async () => worker.terminate()),\n\t\t\t);\n\t\t\tworker.postMessage(payload);\n\t\t}\n\n\t\tthis.#workers = [];\n\t\tthis.#workerByShardId.clear();\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic send(shardId: number, data: GatewaySendPayload) {\n\t\tconst worker = this.#workerByShardId.get(shardId);\n\t\tif (!worker) {\n\t\t\tthrow new Error(`No worker found for shard ${shardId}`);\n\t\t}\n\n\t\tconst payload: WorkerSendPayload = {\n\t\t\top: WorkerSendPayloadOp.Send,\n\t\t\tshardId,\n\t\t\tpayload: data,\n\t\t};\n\t\tworker.postMessage(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\tconst statuses = new Collection<number, WebSocketShardStatus>();\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst nonce = Math.random();\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.FetchStatus,\n\t\t\t\tshardId,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<WebSocketShardStatus>((resolve) => this.fetchStatusPromises.set(nonce, resolve));\n\t\t\tworker.postMessage(payload);\n\n\t\t\tconst status = await promise;\n\t\t\tstatuses.set(shardId, status);\n\t\t}\n\n\t\treturn statuses;\n\t}\n\n\tprivate async setupWorker(workerData: WorkerData) {\n\t\tconst worker = new Worker(this.resolveWorkerPath(), { workerData });\n\n\t\tawait once(worker, 'online');\n\t\t// We do this in case the user has any potentially long running code in their worker\n\t\tawait this.waitForWorkerReady(worker);\n\n\t\tworker\n\t\t\t.on('error', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerReceivePayload) => this.onMessage(worker, payload));\n\n\t\tthis.#workers.push(worker);\n\t\tfor (const shardId of workerData.shardIds) {\n\t\t\tthis.#workerByShardId.set(shardId, worker);\n\t\t}\n\t}\n\n\tprivate resolveWorkerPath(): string {\n\t\tconst path = this.options.workerPath;\n\n\t\tif (!path) {\n\t\t\treturn join(__dirname, 'defaultWorker.js');\n\t\t}\n\n\t\tif (isAbsolute(path)) {\n\t\t\treturn path;\n\t\t}\n\n\t\tif (/^\\.\\.?[/\\\\]/.test(path)) {\n\t\t\treturn resolve(path);\n\t\t}\n\n\t\ttry {\n\t\t\treturn require.resolve(path);\n\t\t} catch {\n\t\t\treturn resolve(path);\n\t\t}\n\t}\n\n\tprivate async waitForWorkerReady(worker: Worker): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst handler = (payload: WorkerReceivePayload) => {\n\t\t\t\tif (payload.op === WorkerReceivePayloadOp.WorkerReady) {\n\t\t\t\t\tresolve();\n\t\t\t\t\tworker.off('message', handler);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tworker.on('message', handler);\n\t\t});\n\t}\n\n\tprivate async onMessage(worker: Worker, payload: WorkerReceivePayload) {\n\t\tswitch (payload.op) {\n\t\t\tcase WorkerReceivePayloadOp.Connected: {\n\t\t\t\tthis.connectPromises.get(payload.shardId)?.();\n\t\t\t\tthis.connectPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Destroyed: {\n\t\t\t\tthis.destroyPromises.get(payload.shardId)?.();\n\t\t\t\tthis.destroyPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Event: {\n\t\t\t\tthis.manager.emit(payload.event, { ...payload.data, shardId: payload.shardId });\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.RetrieveSessionInfo: {\n\t\t\t\tconst session = await this.manager.options.retrieveSessionInfo(payload.shardId);\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.SessionInfoResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tsession,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.UpdateSessionInfo: {\n\t\t\t\tawait this.manager.options.updateSessionInfo(payload.shardId, payload.session);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WaitForIdentify: {\n\t\t\t\tconst throttler = await this.ensureThrottler();\n\n\t\t\t\t// If this rejects it means we aborted, in which case we reply elsewhere.\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.waitForIdentifyControllers.set(payload.nonce, controller);\n\t\t\t\t\tawait throttler.waitForIdentify(payload.shardId, controller.signal);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: true,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.FetchStatusResponse: {\n\t\t\t\tthis.fetchStatusPromises.get(payload.nonce)?.(payload.status);\n\t\t\t\tthis.fetchStatusPromises.delete(payload.nonce);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WorkerReady: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.CancelIdentify: {\n\t\t\t\tthis.waitForIdentifyControllers.get(payload.nonce)?.abort();\n\t\t\t\tthis.waitForIdentifyControllers.delete(payload.nonce);\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: false,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async ensureThrottler(): Promise<IIdentifyThrottler> {\n\t\tthis.throttler ??= await this.manager.options.buildIdentifyThrottler(this.manager);\n\t\treturn this.throttler;\n\t}\n}\n","import type { Awaitable } from '@discordjs/util';\nimport type { APIGatewayBotInfo } from 'discord-api-types/v10';\nimport type { SessionInfo, WebSocketManager, WebSocketManagerOptions } from '../../ws/WebSocketManager.js';\n\nexport interface FetchingStrategyOptions\n\textends Omit<\n\t\tWebSocketManagerOptions,\n\t\t| 'buildIdentifyThrottler'\n\t\t| 'buildStrategy'\n\t\t| 'rest'\n\t\t| 'retrieveSessionInfo'\n\t\t| 'shardCount'\n\t\t| 'shardIds'\n\t\t| 'updateSessionInfo'\n\t> {\n\treadonly gatewayInformation: APIGatewayBotInfo;\n\treadonly shardCount: number;\n}\n\n/**\n * Strategies responsible solely for making manager information accessible\n */\nexport interface IContextFetchingStrategy {\n\treadonly options: FetchingStrategyOptions;\n\tretrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>;\n\tupdateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>;\n\t/**\n\t * Resolves once the given shard should be allowed to identify\n\t * This should correctly handle the signal and reject with an abort error if the operation is aborted.\n\t * Other errors will cause the shard to reconnect.\n\t */\n\twaitForIdentify(shardId: number, signal: AbortSignal): Promise<void>;\n}\n\nexport async function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions> {\n\t/* eslint-disable @typescript-eslint/unbound-method */\n\tconst {\n\t\tbuildIdentifyThrottler,\n\t\tbuildStrategy,\n\t\tretrieveSessionInfo,\n\t\tupdateSessionInfo,\n\t\tshardCount,\n\t\tshardIds,\n\t\trest,\n\t\t...managerOptions\n\t} = manager.options;\n\t/* eslint-enable @typescript-eslint/unbound-method */\n\n\treturn {\n\t\t...managerOptions,\n\t\tgatewayInformation: await manager.fetchGatewayInformation(),\n\t\tshardCount: await manager.getShardCount(),\n\t};\n}\n","/* eslint-disable id-length */\nimport { Buffer } from 'node:buffer';\nimport { once } from 'node:events';\nimport { clearInterval, clearTimeout, setInterval, setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { URLSearchParams } from 'node:url';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayOpcodes,\n\ttype GatewayDispatchPayload,\n\ttype GatewayIdentifyData,\n\ttype GatewayReadyDispatchData,\n\ttype GatewayReceivePayload,\n\ttype GatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { WebSocket, type Data } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy.js';\nimport { ImportantGatewayOpcodes, getInitialSendRateLimitState } from '../utils/constants.js';\nimport type { SessionInfo } from './WebSocketManager.js';\n\n// eslint-disable-next-line promise/prefer-await-to-then\nconst getZlibSync = lazy(async () => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tClosed = 'closed',\n\tDebug = 'debug',\n\tDispatch = 'dispatch',\n\tError = 'error',\n\tHeartbeatComplete = 'heartbeat',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Closed]: [{ code: number }];\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n\t[WebSocketShardEvents.Error]: [payload: { error: Error }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [payload: { data: GatewayReadyDispatchData }];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.HeartbeatComplete]: [payload: { ackAt: number; heartbeatAt: number; latency: number }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\tcode?: number;\n\treason?: string;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1_000,\n\tResuming = 4_200,\n}\n\nexport interface SendRateLimitState {\n\tremaining: number;\n\tresetAt: number;\n}\n\n// TODO(vladfrangu): enable this once https://github.com/oven-sh/bun/issues/3392 is solved\n// const WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket()\n// \t? (globalThis as any).WebSocket\n// \t: WebSocket;\nconst WebSocketConstructor: typeof WebSocket = WebSocket;\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState: SendRateLimitState = getInitialSendRateLimitState();\n\n\tprivate initialHeartbeatTimeoutController: AbortController | null = null;\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\n\tprivate lastHeartbeatAt = -1;\n\n\t// Indicates whether the shard has already resolved its original connect() call\n\tprivate initialConnectResolved = false;\n\n\t// Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET)\n\tprivate failedToConnectDueToNetworkError = false;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeoutAbortControllers = new Collection<WebSocketShardEvents, AbortController>();\n\n\tprivate readonly strategy: IContextFetchingStrategy;\n\n\tpublic readonly id: number;\n\n\t#status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tpublic get status(): WebSocketShardStatus {\n\t\treturn this.#status;\n\t}\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tconst controller = new AbortController();\n\t\tlet promise;\n\n\t\tif (!this.initialConnectResolved) {\n\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\tpromise = Promise.race([\n\t\t\t\tonce(this, WebSocketShardEvents.Ready, { signal: controller.signal }),\n\t\t\t\tonce(this, WebSocketShardEvents.Resumed, { signal: controller.signal }),\n\t\t\t]);\n\t\t}\n\n\t\tvoid this.internalConnect();\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} catch ({ error }: any) {\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// cleanup hanging listeners\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.initialConnectResolved = true;\n\t}\n\n\tprivate async internalConnect() {\n\t\tif (this.#status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65_535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\n\t\tthis.debug([`Connecting to ${url}`]);\n\n\t\tconst connection = new WebSocketConstructor(url, {\n\t\t\thandshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined,\n\t\t});\n\n\t\tconnection.binaryType = 'arraybuffer';\n\n\t\tconnection.onmessage = (event) => {\n\t\t\tvoid this.onMessage(event.data, event.data instanceof ArrayBuffer);\n\t\t};\n\n\t\tconnection.onerror = (event) => {\n\t\t\tthis.onError(event.error);\n\t\t};\n\n\t\tconnection.onclose = (event) => {\n\t\t\tvoid this.onClose(event.code);\n\t\t};\n\n\t\tthis.connection = connection;\n\n\t\tthis.#status = WebSocketShardStatus.Connecting;\n\n\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\n\t\tconst { ok } = await this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\t\tif (!ok) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.#status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\n\t\tif (this.initialHeartbeatTimeoutController) {\n\t\t\tthis.initialHeartbeatTimeoutController.abort();\n\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t}\n\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\tfor (const controller of this.timeoutAbortControllers.values()) {\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.timeoutAbortControllers.clear();\n\n\t\tthis.failedToConnectDueToNetworkError = false;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume) {\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (this.connection) {\n\t\t\t// No longer need to listen to messages\n\t\t\tthis.connection.onmessage = null;\n\t\t\t// Prevent a reconnection loop by unbinding the main close event\n\t\t\tthis.connection.onclose = null;\n\n\t\t\tconst shouldClose = this.connection.readyState === WebSocket.OPEN;\n\n\t\t\tthis.debug([\n\t\t\t\t'Connection status during destroy',\n\t\t\t\t`Needs closing: ${shouldClose}`,\n\t\t\t\t`Ready state: ${this.connection.readyState}`,\n\t\t\t]);\n\n\t\t\tif (shouldClose) {\n\t\t\t\tlet outerResolve: () => void;\n\t\t\t\tconst promise = new Promise<void>((resolve) => {\n\t\t\t\t\touterResolve = resolve;\n\t\t\t\t});\n\n\t\t\t\tthis.connection.onclose = outerResolve!;\n\n\t\t\t\tthis.connection.close(options.code, options.reason);\n\n\t\t\t\tawait promise;\n\t\t\t\tthis.emit(WebSocketShardEvents.Closed, { code: options.code });\n\t\t\t}\n\n\t\t\t// Lastly, remove the error event.\n\t\t\t// Doing this earlier would cause a hard crash in case an error event fired on our `close` call\n\t\t\tthis.connection.onerror = null;\n\t\t} else {\n\t\t\tthis.debug(['Destroying a shard that has no connection; please open an issue on GitHub']);\n\t\t}\n\n\t\tthis.#status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\t// There's cases (like no internet connection) where we immediately fail to connect,\n\t\t\t// causing a very fast and draining reconnection loop.\n\t\t\tawait sleep(500);\n\t\t\treturn this.internalConnect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null): Promise<{ ok: boolean }> {\n\t\tthis.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst timeoutController = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => timeoutController.abort(), timeoutDuration).unref() : null;\n\n\t\tthis.timeoutAbortControllers.set(event, timeoutController);\n\n\t\tconst closeController = new AbortController();\n\n\t\ttry {\n\t\t\t// If the first promise resolves, all is well. If the 2nd promise resolves,\n\t\t\t// the shard has meanwhile closed. In that case, a destroy is already ongoing, so we just need to\n\t\t\t// return false. Meanwhile, if something rejects (error event) or the first controller is aborted,\n\t\t\t// we enter the catch block and trigger a destroy there.\n\t\t\tconst closed = await Promise.race<boolean>([\n\t\t\t\tonce(this, event, { signal: timeoutController.signal }).then(() => false),\n\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: closeController.signal }).then(() => true),\n\t\t\t]);\n\n\t\t\treturn { ok: !closed };\n\t\t} catch {\n\t\t\t// If we're here because of other reasons, we need to destroy the shard\n\t\t\tvoid this.destroy({\n\t\t\t\tcode: CloseCodes.Normal,\n\t\t\t\treason: 'Something timed out or went wrong while waiting for an event',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t});\n\n\t\t\treturn { ok: false };\n\t\t} finally {\n\t\t\tif (timeout) {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t}\n\n\t\t\tthis.timeoutAbortControllers.delete(event);\n\n\t\t\t// Clean up the close listener to not leak memory\n\t\t\tif (!closeController.signal.aborted) {\n\t\t\t\tcloseController.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload): Promise<void> {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.#status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tthis.debug(['Tried to send a non-crucial payload before the shard was ready, waiting']);\n\t\t\t// This will throw if the shard throws an error event in the meantime, just requeue the payload\n\t\t\ttry {\n\t\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t\t} catch {\n\t\t\t\treturn this.send(payload);\n\t\t\t}\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tconst now = Date.now();\n\n\t\t\tif (this.sendRateLimitState.resetAt > now) {\n\t\t\t\tconst sleepFor = this.sendRateLimitState.resetAt - now;\n\n\t\t\t\tthis.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]);\n\t\t\t\tconst controller = new AbortController();\n\n\t\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\t\tconst interrupted = await Promise.race([\n\t\t\t\t\tsleep(sleepFor).then(() => false),\n\t\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: controller.signal }).then(() => true),\n\t\t\t\t]);\n\n\t\t\t\tif (interrupted) {\n\t\t\t\t\tthis.debug(['Connection closed while waiting for the send rate limit to reset, re-queueing payload']);\n\t\t\t\t\tthis.sendQueue.shift();\n\t\t\t\t\treturn this.send(payload);\n\t\t\t\t}\n\n\t\t\t\t// This is so the listener from the `once` call is removed\n\t\t\t\tcontroller.abort();\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug(['Waiting for identify throttle']);\n\n\t\tconst controller = new AbortController();\n\t\tconst closeHandler = () => {\n\t\t\tcontroller.abort();\n\t\t};\n\n\t\tthis.on(WebSocketShardEvents.Closed, closeHandler);\n\n\t\ttry {\n\t\t\tawait this.strategy.waitForIdentify(this.id, controller.signal);\n\t\t} catch {\n\t\t\tif (controller.signal.aborted) {\n\t\t\t\tthis.debug(['Was waiting for an identify, but the shard closed in the meantime']);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.debug([\n\t\t\t\t'IContextFetchingStrategy#waitForIdentify threw an unknown error.',\n\t\t\t\t\"If you're using a custom strategy, this is probably nothing to worry about.\",\n\t\t\t\t\"If you're not, please open an issue on GitHub.\",\n\t\t\t]);\n\n\t\t\tawait this.destroy({\n\t\t\t\treason: 'Identify throttling logic failed',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.off(WebSocketShardEvents.Closed, closeHandler);\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t}\n\n\tprivate async resume(session: SessionInfo) {\n\t\tthis.debug([\n\t\t\t'Resuming session',\n\t\t\t`resume url: ${session.resumeURL}`,\n\t\t\t`sequence: ${session.sequence}`,\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t]);\n\n\t\tthis.#status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Data, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(data as string) as GatewayReceivePayload;\n\t\t\t} catch {\n\t\t\t\t// This is a non-JSON payload / (at the time of writing this comment) emitted by bun wrongly interpreting custom close codes https://github.com/oven-sh/bun/issues/3392\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tconst decompressable = new Uint8Array(data as ArrayBuffer);\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\t\t\t\tinflate(decompressable, { chunkSize: 65_535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: Data, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.#status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line sonarjs/no-nested-switch\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\n\t\t\t\t\t\tconst session = {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, session);\n\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready, { data: payload.d });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (session) {\n\t\t\t\t\tif (payload.s > session.sequence) {\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.debug([\n\t\t\t\t\t\t`Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect`,\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tconst jitter = Math.random();\n\t\t\t\tconst firstWait = Math.floor(payload.d.heartbeat_interval * jitter);\n\t\t\t\tthis.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]);\n\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = controller;\n\t\t\t\t\tawait sleep(firstWait, undefined, { signal: controller.signal });\n\t\t\t\t} catch {\n\t\t\t\t\tthis.debug(['Cancelled initial heartbeat due to #destroy being called']);\n\t\t\t\t\treturn;\n\t\t\t\t} finally {\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t\t\t}\n\n\t\t\t\tawait this.heartbeat();\n\n\t\t\t\tthis.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\n\t\t\t\tconst ackAt = Date.now();\n\t\t\t\tthis.emit(WebSocketShardEvents.HeartbeatComplete, {\n\t\t\t\t\tackAt,\n\t\t\t\t\theartbeatAt: this.lastHeartbeatAt,\n\t\t\t\t\tlatency: ackAt - this.lastHeartbeatAt,\n\t\t\t\t});\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(error: Error) {\n\t\tif ('code' in error && ['ECONNRESET', 'ECONNREFUSED'].includes(error.code as string)) {\n\t\t\tthis.debug(['Failed to connect to the gateway URL specified due to a network error']);\n\t\t\tthis.failedToConnectDueToNetworkError = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.emit(WebSocketShardEvents.Error, { error });\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tthis.emit(WebSocketShardEvents.Closed, { code });\n\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occurred: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Authentication failed'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Invalid shard'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Sharding is required'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used an invalid API version'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used invalid intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used disallowed intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([\n\t\t\t\t\t`The gateway closed with an unexpected code ${code}, attempting to ${\n\t\t\t\t\t\tthis.failedToConnectDueToNetworkError ? 'reconnect' : 'resume'\n\t\t\t\t\t}.`,\n\t\t\t\t]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\trecover: this.failedToConnectDueToNetworkError\n\t\t\t\t\t\t? WebSocketShardDestroyRecovery.Reconnect\n\t\t\t\t\t\t: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n","import process from 'node:process';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { APIVersion, GatewayOpcodes } from 'discord-api-types/v10';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy.js';\nimport { SimpleIdentifyThrottler } from '../throttling/SimpleIdentifyThrottler.js';\nimport type { SessionInfo, OptionalWebSocketManagerOptions, WebSocketManager } from '../ws/WebSocketManager.js';\nimport type { SendRateLimitState } from '../ws/WebSocketShard.js';\n\n/**\n * Valid encoding types\n */\nexport enum Encoding {\n\tJSON = 'json',\n}\n\n/**\n * Valid compression methods\n */\nexport enum CompressionMethod {\n\tZlibStream = 'zlib-stream',\n}\n\nexport const DefaultDeviceProperty = `@discordjs/ws 1.0.1` as `@discordjs/ws ${string}`;\n\nconst getDefaultSessionStore = lazy(() => new Collection<number, SessionInfo | null>());\n\n/**\n * Default options used by the manager\n */\nexport const DefaultWebSocketManagerOptions = {\n\tasync buildIdentifyThrottler(manager: WebSocketManager) {\n\t\tconst info = await manager.fetchGatewayInformation();\n\t\treturn new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency);\n\t},\n\tbuildStrategy: (manager) => new SimpleShardingStrategy(manager),\n\tshardCount: null,\n\tshardIds: null,\n\tlargeThreshold: null,\n\tinitialPresence: null,\n\tidentifyProperties: {\n\t\tbrowser: DefaultDeviceProperty,\n\t\tdevice: DefaultDeviceProperty,\n\t\tos: process.platform,\n\t},\n\tversion: APIVersion,\n\tencoding: Encoding.JSON,\n\tcompression: null,\n\tretrieveSessionInfo(shardId) {\n\t\tconst store = getDefaultSessionStore();\n\t\treturn store.get(shardId) ?? null;\n\t},\n\tupdateSessionInfo(shardId: number, info: SessionInfo | null) {\n\t\tconst store = getDefaultSessionStore();\n\t\tif (info) {\n\t\t\tstore.set(shardId, info);\n\t\t} else {\n\t\t\tstore.delete(shardId);\n\t\t}\n\t},\n\thandshakeTimeout: 30_000,\n\thelloTimeout: 60_000,\n\treadyTimeout: 15_000,\n} as const satisfies OptionalWebSocketManagerOptions;\n\nexport const ImportantGatewayOpcodes = new Set([\n\tGatewayOpcodes.Heartbeat,\n\tGatewayOpcodes.Identify,\n\tGatewayOpcodes.Resume,\n]);\n\nexport function getInitialSendRateLimitState(): SendRateLimitState {\n\treturn {\n\t\tremaining: 120,\n\t\tresetAt: Date.now() + 60_000,\n\t};\n}\n","import { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { WebSocketManager } from '../../ws/WebSocketManager.js';\nimport { WebSocketShard, WebSocketShardEvents, type WebSocketShardDestroyOptions } from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport { SimpleContextFetchingStrategy } from '../context/SimpleContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\n/**\n * Simple strategy that just spawns shards in the current process\n */\nexport class SimpleShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor(manager: WebSocketManager) {\n\t\tthis.manager = manager;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tfor (const shardId of shardIds) {\n\t\t\tconst strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions);\n\t\t\tconst shard = new WebSocketShard(strategy, shardId);\n\t\t\tfor (const event of Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Intentional\n\t\t\t\tshard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId }));\n\t\t\t}\n\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.connect());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.destroy(options));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t\tthis.shards.clear();\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic async send(shardId: number, payload: GatewaySendPayload) {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} not found`);\n\t\t}\n\n\t\treturn shard.send(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\treturn this.shards.mapValues((shard) => shard.status);\n\t}\n}\n","import type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class SimpleContextFetchingStrategy implements IContextFetchingStrategy {\n\t// This strategy assumes every shard is running under the same process - therefore we need a single\n\t// IdentifyThrottler per manager.\n\tprivate static throttlerCache = new WeakMap<WebSocketManager, IIdentifyThrottler>();\n\n\tprivate static async ensureThrottler(manager: WebSocketManager): Promise<IIdentifyThrottler> {\n\t\tconst throttler = SimpleContextFetchingStrategy.throttlerCache.get(manager);\n\t\tif (throttler) {\n\t\t\treturn throttler;\n\t\t}\n\n\t\tconst newThrottler = await manager.options.buildIdentifyThrottler(manager);\n\t\tSimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler);\n\n\t\treturn newThrottler;\n\t}\n\n\tpublic constructor(private readonly manager: WebSocketManager, public readonly options: FetchingStrategyOptions) {}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\treturn this.manager.options.retrieveSessionInfo(shardId);\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\treturn this.manager.options.updateSessionInfo(shardId, sessionInfo);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst throttler = await SimpleContextFetchingStrategy.ensureThrottler(this.manager);\n\t\tawait throttler.waitForIdentify(shardId, signal);\n\t}\n}\n","import { setTimeout as sleep } from 'node:timers/promises';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport type { IIdentifyThrottler } from './IIdentifyThrottler.js';\n\n/**\n * The state of a rate limit key's identify queue.\n */\nexport interface IdentifyState {\n\tqueue: AsyncQueue;\n\tresetsAt: number;\n}\n\n/**\n * Local, in-memory identify throttler.\n */\nexport class SimpleIdentifyThrottler implements IIdentifyThrottler {\n\tprivate readonly states = new Collection<number, IdentifyState>();\n\n\tpublic constructor(private readonly maxConcurrency: number) {}\n\n\t/**\n\t * {@inheritDoc IIdentifyThrottler.waitForIdentify}\n\t */\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst key = shardId % this.maxConcurrency;\n\n\t\tconst state = this.states.ensure(key, () => {\n\t\t\treturn {\n\t\t\t\tqueue: new AsyncQueue(),\n\t\t\t\tresetsAt: Number.POSITIVE_INFINITY,\n\t\t\t};\n\t\t});\n\n\t\tawait state.queue.wait({ signal });\n\n\t\ttry {\n\t\t\tconst diff = state.resetsAt - Date.now();\n\t\t\tif (diff <= 5_000) {\n\t\t\t\t// To account for the latency the IDENTIFY payload goes through, we add a bit more wait time\n\t\t\t\tconst time = diff + Math.random() * 1_500;\n\t\t\t\tawait sleep(time);\n\t\t\t}\n\n\t\t\tstate.resetsAt = Date.now() + 5_000;\n\t\t} finally {\n\t\t\tstate.queue.shift();\n\t\t}\n\t}\n}\n","import { WorkerBootstrapper } from '../../utils/WorkerBootstrapper.js';\n\nconst bootstrapper = new WorkerBootstrapper();\nvoid bootstrapper.bootstrap();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,8BAAqD;AACrD,IAAAC,qBAA2B;;;ACD3B,IAAAC,8BAAyC;AAC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A,MACF;AAGA,YAAM,QAAQ,gBAAgB,KAAK;AACnC,WAAK,OAAO,IAAI,SAAS,KAAK;AAAA,IAC/B;AAGA,SAAK,kBAAkB;AAEvB,UAAM,UAAgC;AAAA,MACrC;AAAA,IACD;AACA,2CAAY,YAAY,OAAO;AAAA,EAChC;AACD;;;AS7KA,IAAM,eAAe,IAAI,mBAAmB;AAC5C,KAAK,aAAa,UAAU;","names":["import_node_worker_threads","import_collection","import_node_worker_threads","import_collection","resolve","payload","import_node_events","import_promises","import_collection","import_util","import_async_queue","import_v10","import_collection","import_collection","import_collection","sleep","process","WebSocketShardEvents","WebSocketShardDestroyRecovery","resolve","sleep","session"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/dist/defaultWorker.mjs b/node_modules/@discordjs/ws/dist/defaultWorker.mjs new file mode 100644 index 0000000..9f90978 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/defaultWorker.mjs @@ -0,0 +1,1033 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); + +// src/utils/WorkerBootstrapper.ts +import { isMainThread as isMainThread2, parentPort as parentPort2, workerData } from "node:worker_threads"; +import { Collection as Collection7 } from "@discordjs/collection"; + +// src/strategies/context/WorkerContextFetchingStrategy.ts +import { isMainThread, parentPort } from "node:worker_threads"; +import { Collection as Collection2 } from "@discordjs/collection"; + +// src/strategies/sharding/WorkerShardingStrategy.ts +import { once } from "node:events"; +import { join, isAbsolute, resolve } from "node:path"; +import { Worker } from "node:worker_threads"; +import { Collection } from "@discordjs/collection"; + +// src/strategies/context/IContextFetchingStrategy.ts +async function managerToFetchingStrategyOptions(manager) { + const { + buildIdentifyThrottler, + buildStrategy, + retrieveSessionInfo, + updateSessionInfo, + shardCount, + shardIds, + rest, + ...managerOptions + } = manager.options; + return { + ...managerOptions, + gatewayInformation: await manager.fetchGatewayInformation(), + shardCount: await manager.getShardCount() + }; +} +__name(managerToFetchingStrategyOptions, "managerToFetchingStrategyOptions"); + +// src/strategies/context/WorkerContextFetchingStrategy.ts +var WorkerContextFetchingStrategy = class { + constructor(options) { + this.options = options; + if (isMainThread) { + throw new Error("Cannot instantiate WorkerContextFetchingStrategy on the main thread"); + } + parentPort.on("message", (payload) => { + if (payload.op === 3 /* SessionInfoResponse */) { + this.sessionPromises.get(payload.nonce)?.(payload.session); + this.sessionPromises.delete(payload.nonce); + } + if (payload.op === 4 /* ShardIdentifyResponse */) { + const promise = this.waitForIdentifyPromises.get(payload.nonce); + if (payload.ok) { + promise?.resolve(); + } else { + promise?.reject(promise.signal.reason); + } + this.waitForIdentifyPromises.delete(payload.nonce); + } + }); + } + static { + __name(this, "WorkerContextFetchingStrategy"); + } + sessionPromises = new Collection2(); + waitForIdentifyPromises = new Collection2(); + async retrieveSessionInfo(shardId) { + const nonce = Math.random(); + const payload = { + op: 3 /* RetrieveSessionInfo */, + shardId, + nonce + }; + const promise = new Promise((resolve2) => this.sessionPromises.set(nonce, resolve2)); + parentPort.postMessage(payload); + return promise; + } + updateSessionInfo(shardId, sessionInfo) { + const payload = { + op: 4 /* UpdateSessionInfo */, + shardId, + session: sessionInfo + }; + parentPort.postMessage(payload); + } + async waitForIdentify(shardId, signal) { + const nonce = Math.random(); + const payload = { + op: 5 /* WaitForIdentify */, + nonce, + shardId + }; + const promise = new Promise( + (resolve2, reject) => ( + // eslint-disable-next-line no-promise-executor-return + this.waitForIdentifyPromises.set(nonce, { signal, resolve: resolve2, reject }) + ) + ); + parentPort.postMessage(payload); + const listener = /* @__PURE__ */ __name(() => { + const payload2 = { + op: 8 /* CancelIdentify */, + nonce + }; + parentPort.postMessage(payload2); + }, "listener"); + signal.addEventListener("abort", listener); + try { + await promise; + } finally { + signal.removeEventListener("abort", listener); + } + } +}; + +// src/ws/WebSocketShard.ts +import { Buffer as Buffer2 } from "node:buffer"; +import { once as once2 } from "node:events"; +import { clearInterval, clearTimeout, setInterval, setTimeout } from "node:timers"; +import { setTimeout as sleep2 } from "node:timers/promises"; +import { URLSearchParams } from "node:url"; +import { TextDecoder } from "node:util"; +import { inflate } from "node:zlib"; +import { Collection as Collection6 } from "@discordjs/collection"; +import { lazy as lazy2 } from "@discordjs/util"; +import { AsyncQueue as AsyncQueue2 } from "@sapphire/async-queue"; +import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter"; +import { + GatewayCloseCodes, + GatewayDispatchEvents, + GatewayOpcodes as GatewayOpcodes2 +} from "discord-api-types/v10"; +import { WebSocket } from "ws"; + +// src/utils/constants.ts +import process from "node:process"; +import { Collection as Collection5 } from "@discordjs/collection"; +import { lazy } from "@discordjs/util"; +import { APIVersion, GatewayOpcodes } from "discord-api-types/v10"; + +// src/strategies/sharding/SimpleShardingStrategy.ts +import { Collection as Collection3 } from "@discordjs/collection"; + +// src/strategies/context/SimpleContextFetchingStrategy.ts +var SimpleContextFetchingStrategy = class _SimpleContextFetchingStrategy { + constructor(manager, options) { + this.manager = manager; + this.options = options; + } + static { + __name(this, "SimpleContextFetchingStrategy"); + } + // This strategy assumes every shard is running under the same process - therefore we need a single + // IdentifyThrottler per manager. + static throttlerCache = /* @__PURE__ */ new WeakMap(); + static async ensureThrottler(manager) { + const throttler = _SimpleContextFetchingStrategy.throttlerCache.get(manager); + if (throttler) { + return throttler; + } + const newThrottler = await manager.options.buildIdentifyThrottler(manager); + _SimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler); + return newThrottler; + } + async retrieveSessionInfo(shardId) { + return this.manager.options.retrieveSessionInfo(shardId); + } + updateSessionInfo(shardId, sessionInfo) { + return this.manager.options.updateSessionInfo(shardId, sessionInfo); + } + async waitForIdentify(shardId, signal) { + const throttler = await _SimpleContextFetchingStrategy.ensureThrottler(this.manager); + await throttler.waitForIdentify(shardId, signal); + } +}; + +// src/strategies/sharding/SimpleShardingStrategy.ts +var SimpleShardingStrategy = class { + static { + __name(this, "SimpleShardingStrategy"); + } + manager; + shards = new Collection3(); + constructor(manager) { + this.manager = manager; + } + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + async spawn(shardIds) { + const strategyOptions = await managerToFetchingStrategyOptions(this.manager); + for (const shardId of shardIds) { + const strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions); + const shard = new WebSocketShard(strategy, shardId); + for (const event of Object.values(WebSocketShardEvents)) { + shard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId })); + } + this.shards.set(shardId, shard); + } + } + /** + * {@inheritDoc IShardingStrategy.connect} + */ + async connect() { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.connect()); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + async destroy(options) { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.destroy(options)); + } + await Promise.all(promises); + this.shards.clear(); + } + /** + * {@inheritDoc IShardingStrategy.send} + */ + async send(shardId, payload) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} not found`); + } + return shard.send(payload); + } + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + async fetchStatus() { + return this.shards.mapValues((shard) => shard.status); + } +}; + +// src/throttling/SimpleIdentifyThrottler.ts +import { setTimeout as sleep } from "node:timers/promises"; +import { Collection as Collection4 } from "@discordjs/collection"; +import { AsyncQueue } from "@sapphire/async-queue"; +var SimpleIdentifyThrottler = class { + constructor(maxConcurrency) { + this.maxConcurrency = maxConcurrency; + } + static { + __name(this, "SimpleIdentifyThrottler"); + } + states = new Collection4(); + /** + * {@inheritDoc IIdentifyThrottler.waitForIdentify} + */ + async waitForIdentify(shardId, signal) { + const key = shardId % this.maxConcurrency; + const state = this.states.ensure(key, () => { + return { + queue: new AsyncQueue(), + resetsAt: Number.POSITIVE_INFINITY + }; + }); + await state.queue.wait({ signal }); + try { + const diff = state.resetsAt - Date.now(); + if (diff <= 5e3) { + const time = diff + Math.random() * 1500; + await sleep(time); + } + state.resetsAt = Date.now() + 5e3; + } finally { + state.queue.shift(); + } + } +}; + +// src/utils/constants.ts +var DefaultDeviceProperty = `@discordjs/ws 1.0.1`; +var getDefaultSessionStore = lazy(() => new Collection5()); +var DefaultWebSocketManagerOptions = { + async buildIdentifyThrottler(manager) { + const info = await manager.fetchGatewayInformation(); + return new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency); + }, + buildStrategy: (manager) => new SimpleShardingStrategy(manager), + shardCount: null, + shardIds: null, + largeThreshold: null, + initialPresence: null, + identifyProperties: { + browser: DefaultDeviceProperty, + device: DefaultDeviceProperty, + os: process.platform + }, + version: APIVersion, + encoding: "json" /* JSON */, + compression: null, + retrieveSessionInfo(shardId) { + const store = getDefaultSessionStore(); + return store.get(shardId) ?? null; + }, + updateSessionInfo(shardId, info) { + const store = getDefaultSessionStore(); + if (info) { + store.set(shardId, info); + } else { + store.delete(shardId); + } + }, + handshakeTimeout: 3e4, + helloTimeout: 6e4, + readyTimeout: 15e3 +}; +var ImportantGatewayOpcodes = /* @__PURE__ */ new Set([ + GatewayOpcodes.Heartbeat, + GatewayOpcodes.Identify, + GatewayOpcodes.Resume +]); +function getInitialSendRateLimitState() { + return { + remaining: 120, + resetAt: Date.now() + 6e4 + }; +} +__name(getInitialSendRateLimitState, "getInitialSendRateLimitState"); + +// src/ws/WebSocketShard.ts +var getZlibSync = lazy2(async () => import("zlib-sync").then((mod) => mod.default).catch(() => null)); +var WebSocketShardEvents = /* @__PURE__ */ ((WebSocketShardEvents2) => { + WebSocketShardEvents2["Closed"] = "closed"; + WebSocketShardEvents2["Debug"] = "debug"; + WebSocketShardEvents2["Dispatch"] = "dispatch"; + WebSocketShardEvents2["Error"] = "error"; + WebSocketShardEvents2["HeartbeatComplete"] = "heartbeat"; + WebSocketShardEvents2["Hello"] = "hello"; + WebSocketShardEvents2["Ready"] = "ready"; + WebSocketShardEvents2["Resumed"] = "resumed"; + return WebSocketShardEvents2; +})(WebSocketShardEvents || {}); +var WebSocketShardDestroyRecovery = /* @__PURE__ */ ((WebSocketShardDestroyRecovery2) => { + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Reconnect"] = 0] = "Reconnect"; + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Resume"] = 1] = "Resume"; + return WebSocketShardDestroyRecovery2; +})(WebSocketShardDestroyRecovery || {}); +var WebSocketConstructor = WebSocket; +var WebSocketShard = class extends AsyncEventEmitter { + static { + __name(this, "WebSocketShard"); + } + connection = null; + useIdentifyCompress = false; + inflate = null; + textDecoder = new TextDecoder(); + replayedEvents = 0; + isAck = true; + sendRateLimitState = getInitialSendRateLimitState(); + initialHeartbeatTimeoutController = null; + heartbeatInterval = null; + lastHeartbeatAt = -1; + // Indicates whether the shard has already resolved its original connect() call + initialConnectResolved = false; + // Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET) + failedToConnectDueToNetworkError = false; + sendQueue = new AsyncQueue2(); + timeoutAbortControllers = new Collection6(); + strategy; + id; + #status = 0 /* Idle */; + get status() { + return this.#status; + } + constructor(strategy, id) { + super(); + this.strategy = strategy; + this.id = id; + } + async connect() { + const controller = new AbortController(); + let promise; + if (!this.initialConnectResolved) { + promise = Promise.race([ + once2(this, "ready" /* Ready */, { signal: controller.signal }), + once2(this, "resumed" /* Resumed */, { signal: controller.signal }) + ]); + } + void this.internalConnect(); + try { + await promise; + } catch ({ error }) { + throw error; + } finally { + controller.abort(); + } + this.initialConnectResolved = true; + } + async internalConnect() { + if (this.#status !== 0 /* Idle */) { + throw new Error("Tried to connect a shard that wasn't idle"); + } + const { version, encoding, compression } = this.strategy.options; + const params = new URLSearchParams({ v: version, encoding }); + if (compression) { + const zlib = await getZlibSync(); + if (zlib) { + params.append("compress", compression); + this.inflate = new zlib.Inflate({ + chunkSize: 65535, + to: "string" + }); + } else if (!this.useIdentifyCompress) { + this.useIdentifyCompress = true; + console.warn( + "WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress" + ); + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + const url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`; + this.debug([`Connecting to ${url}`]); + const connection = new WebSocketConstructor(url, { + handshakeTimeout: this.strategy.options.handshakeTimeout ?? void 0 + }); + connection.binaryType = "arraybuffer"; + connection.onmessage = (event) => { + void this.onMessage(event.data, event.data instanceof ArrayBuffer); + }; + connection.onerror = (event) => { + this.onError(event.error); + }; + connection.onclose = (event) => { + void this.onClose(event.code); + }; + this.connection = connection; + this.#status = 1 /* Connecting */; + this.sendRateLimitState = getInitialSendRateLimitState(); + const { ok } = await this.waitForEvent("hello" /* Hello */, this.strategy.options.helloTimeout); + if (!ok) { + return; + } + if (session?.shardCount === this.strategy.options.shardCount) { + await this.resume(session); + } else { + await this.identify(); + } + } + async destroy(options = {}) { + if (this.#status === 0 /* Idle */) { + this.debug(["Tried to destroy a shard that was idle"]); + return; + } + if (!options.code) { + options.code = options.recover === 1 /* Resume */ ? 4200 /* Resuming */ : 1e3 /* Normal */; + } + this.debug([ + "Destroying shard", + `Reason: ${options.reason ?? "none"}`, + `Code: ${options.code}`, + `Recover: ${options.recover === void 0 ? "none" : WebSocketShardDestroyRecovery[options.recover]}` + ]); + this.isAck = true; + if (this.heartbeatInterval) { + clearInterval(this.heartbeatInterval); + } + if (this.initialHeartbeatTimeoutController) { + this.initialHeartbeatTimeoutController.abort(); + this.initialHeartbeatTimeoutController = null; + } + this.lastHeartbeatAt = -1; + for (const controller of this.timeoutAbortControllers.values()) { + controller.abort(); + } + this.timeoutAbortControllers.clear(); + this.failedToConnectDueToNetworkError = false; + if (options.recover !== 1 /* Resume */) { + await this.strategy.updateSessionInfo(this.id, null); + } + if (this.connection) { + this.connection.onmessage = null; + this.connection.onclose = null; + const shouldClose = this.connection.readyState === WebSocket.OPEN; + this.debug([ + "Connection status during destroy", + `Needs closing: ${shouldClose}`, + `Ready state: ${this.connection.readyState}` + ]); + if (shouldClose) { + let outerResolve; + const promise = new Promise((resolve2) => { + outerResolve = resolve2; + }); + this.connection.onclose = outerResolve; + this.connection.close(options.code, options.reason); + await promise; + this.emit("closed" /* Closed */, { code: options.code }); + } + this.connection.onerror = null; + } else { + this.debug(["Destroying a shard that has no connection; please open an issue on GitHub"]); + } + this.#status = 0 /* Idle */; + if (options.recover !== void 0) { + await sleep2(500); + return this.internalConnect(); + } + } + async waitForEvent(event, timeoutDuration) { + this.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : "indefinitely"}`]); + const timeoutController = new AbortController(); + const timeout = timeoutDuration ? setTimeout(() => timeoutController.abort(), timeoutDuration).unref() : null; + this.timeoutAbortControllers.set(event, timeoutController); + const closeController = new AbortController(); + try { + const closed = await Promise.race([ + once2(this, event, { signal: timeoutController.signal }).then(() => false), + once2(this, "closed" /* Closed */, { signal: closeController.signal }).then(() => true) + ]); + return { ok: !closed }; + } catch { + void this.destroy({ + code: 1e3 /* Normal */, + reason: "Something timed out or went wrong while waiting for an event", + recover: 0 /* Reconnect */ + }); + return { ok: false }; + } finally { + if (timeout) { + clearTimeout(timeout); + } + this.timeoutAbortControllers.delete(event); + if (!closeController.signal.aborted) { + closeController.abort(); + } + } + } + async send(payload) { + if (!this.connection) { + throw new Error("WebSocketShard wasn't connected"); + } + if (this.#status !== 3 /* Ready */ && !ImportantGatewayOpcodes.has(payload.op)) { + this.debug(["Tried to send a non-crucial payload before the shard was ready, waiting"]); + try { + await once2(this, "ready" /* Ready */); + } catch { + return this.send(payload); + } + } + await this.sendQueue.wait(); + if (--this.sendRateLimitState.remaining <= 0) { + const now = Date.now(); + if (this.sendRateLimitState.resetAt > now) { + const sleepFor = this.sendRateLimitState.resetAt - now; + this.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]); + const controller = new AbortController(); + const interrupted = await Promise.race([ + sleep2(sleepFor).then(() => false), + once2(this, "closed" /* Closed */, { signal: controller.signal }).then(() => true) + ]); + if (interrupted) { + this.debug(["Connection closed while waiting for the send rate limit to reset, re-queueing payload"]); + this.sendQueue.shift(); + return this.send(payload); + } + controller.abort(); + } + this.sendRateLimitState = getInitialSendRateLimitState(); + } + this.sendQueue.shift(); + this.connection.send(JSON.stringify(payload)); + } + async identify() { + this.debug(["Waiting for identify throttle"]); + const controller = new AbortController(); + const closeHandler = /* @__PURE__ */ __name(() => { + controller.abort(); + }, "closeHandler"); + this.on("closed" /* Closed */, closeHandler); + try { + await this.strategy.waitForIdentify(this.id, controller.signal); + } catch { + if (controller.signal.aborted) { + this.debug(["Was waiting for an identify, but the shard closed in the meantime"]); + return; + } + this.debug([ + "IContextFetchingStrategy#waitForIdentify threw an unknown error.", + "If you're using a custom strategy, this is probably nothing to worry about.", + "If you're not, please open an issue on GitHub." + ]); + await this.destroy({ + reason: "Identify throttling logic failed", + recover: 1 /* Resume */ + }); + } finally { + this.off("closed" /* Closed */, closeHandler); + } + this.debug([ + "Identifying", + `shard id: ${this.id.toString()}`, + `shard count: ${this.strategy.options.shardCount}`, + `intents: ${this.strategy.options.intents}`, + `compression: ${this.inflate ? "zlib-stream" : this.useIdentifyCompress ? "identify" : "none"}` + ]); + const d = { + token: this.strategy.options.token, + properties: this.strategy.options.identifyProperties, + intents: this.strategy.options.intents, + compress: this.useIdentifyCompress, + shard: [this.id, this.strategy.options.shardCount] + }; + if (this.strategy.options.largeThreshold) { + d.large_threshold = this.strategy.options.largeThreshold; + } + if (this.strategy.options.initialPresence) { + d.presence = this.strategy.options.initialPresence; + } + await this.send({ + op: GatewayOpcodes2.Identify, + d + }); + await this.waitForEvent("ready" /* Ready */, this.strategy.options.readyTimeout); + } + async resume(session) { + this.debug([ + "Resuming session", + `resume url: ${session.resumeURL}`, + `sequence: ${session.sequence}`, + `shard id: ${this.id.toString()}` + ]); + this.#status = 2 /* Resuming */; + this.replayedEvents = 0; + return this.send({ + op: GatewayOpcodes2.Resume, + d: { + token: this.strategy.options.token, + seq: session.sequence, + session_id: session.sessionId + } + }); + } + async heartbeat(requested = false) { + if (!this.isAck && !requested) { + return this.destroy({ reason: "Zombie connection", recover: 1 /* Resume */ }); + } + const session = await this.strategy.retrieveSessionInfo(this.id); + await this.send({ + op: GatewayOpcodes2.Heartbeat, + d: session?.sequence ?? null + }); + this.lastHeartbeatAt = Date.now(); + this.isAck = false; + } + async unpackMessage(data, isBinary) { + if (!isBinary) { + try { + return JSON.parse(data); + } catch { + return null; + } + } + const decompressable = new Uint8Array(data); + if (this.useIdentifyCompress) { + return new Promise((resolve2, reject) => { + inflate(decompressable, { chunkSize: 65535 }, (err, result) => { + if (err) { + reject(err); + return; + } + resolve2(JSON.parse(this.textDecoder.decode(result))); + }); + }); + } + if (this.inflate) { + const l = decompressable.length; + const flush = l >= 4 && decompressable[l - 4] === 0 && decompressable[l - 3] === 0 && decompressable[l - 2] === 255 && decompressable[l - 1] === 255; + const zlib = await getZlibSync(); + this.inflate.push(Buffer2.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH); + if (this.inflate.err) { + this.emit("error" /* Error */, { + error: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ""}`) + }); + } + if (!flush) { + return null; + } + const { result } = this.inflate; + if (!result) { + return null; + } + return JSON.parse(typeof result === "string" ? result : this.textDecoder.decode(result)); + } + this.debug([ + "Received a message we were unable to decompress", + `isBinary: ${isBinary.toString()}`, + `useIdentifyCompress: ${this.useIdentifyCompress.toString()}`, + `inflate: ${Boolean(this.inflate).toString()}` + ]); + return null; + } + async onMessage(data, isBinary) { + const payload = await this.unpackMessage(data, isBinary); + if (!payload) { + return; + } + switch (payload.op) { + case GatewayOpcodes2.Dispatch: { + if (this.#status === 2 /* Resuming */) { + this.replayedEvents++; + } + switch (payload.t) { + case GatewayDispatchEvents.Ready: { + this.#status = 3 /* Ready */; + const session2 = { + sequence: payload.s, + sessionId: payload.d.session_id, + shardId: this.id, + shardCount: this.strategy.options.shardCount, + resumeURL: payload.d.resume_gateway_url + }; + await this.strategy.updateSessionInfo(this.id, session2); + this.emit("ready" /* Ready */, { data: payload.d }); + break; + } + case GatewayDispatchEvents.Resumed: { + this.#status = 3 /* Ready */; + this.debug([`Resumed and replayed ${this.replayedEvents} events`]); + this.emit("resumed" /* Resumed */); + break; + } + default: { + break; + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + if (session) { + if (payload.s > session.sequence) { + await this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s }); + } + } else { + this.debug([ + `Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect` + ]); + } + this.emit("dispatch" /* Dispatch */, { data: payload }); + break; + } + case GatewayOpcodes2.Heartbeat: { + await this.heartbeat(true); + break; + } + case GatewayOpcodes2.Reconnect: { + await this.destroy({ + reason: "Told to reconnect by Discord", + recover: 1 /* Resume */ + }); + break; + } + case GatewayOpcodes2.InvalidSession: { + this.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]); + const session = await this.strategy.retrieveSessionInfo(this.id); + if (payload.d && session) { + await this.resume(session); + } else { + await this.destroy({ + reason: "Invalid session", + recover: 0 /* Reconnect */ + }); + } + break; + } + case GatewayOpcodes2.Hello: { + this.emit("hello" /* Hello */); + const jitter = Math.random(); + const firstWait = Math.floor(payload.d.heartbeat_interval * jitter); + this.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]); + try { + const controller = new AbortController(); + this.initialHeartbeatTimeoutController = controller; + await sleep2(firstWait, void 0, { signal: controller.signal }); + } catch { + this.debug(["Cancelled initial heartbeat due to #destroy being called"]); + return; + } finally { + this.initialHeartbeatTimeoutController = null; + } + await this.heartbeat(); + this.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]); + this.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval); + break; + } + case GatewayOpcodes2.HeartbeatAck: { + this.isAck = true; + const ackAt = Date.now(); + this.emit("heartbeat" /* HeartbeatComplete */, { + ackAt, + heartbeatAt: this.lastHeartbeatAt, + latency: ackAt - this.lastHeartbeatAt + }); + break; + } + } + } + onError(error) { + if ("code" in error && ["ECONNRESET", "ECONNREFUSED"].includes(error.code)) { + this.debug(["Failed to connect to the gateway URL specified due to a network error"]); + this.failedToConnectDueToNetworkError = true; + return; + } + this.emit("error" /* Error */, { error }); + } + async onClose(code) { + this.emit("closed" /* Closed */, { code }); + switch (code) { + case 1e3 /* Normal */: { + return this.destroy({ + code, + reason: "Got disconnected by Discord", + recover: 0 /* Reconnect */ + }); + } + case 4200 /* Resuming */: { + break; + } + case GatewayCloseCodes.UnknownError: { + this.debug([`An unknown error occurred: ${code}`]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.UnknownOpcode: { + this.debug(["An invalid opcode was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.DecodeError: { + this.debug(["An invalid payload was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.NotAuthenticated: { + this.debug(["A request was somehow sent before the identify/resume payload."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.AuthenticationFailed: { + this.emit("error" /* Error */, { + error: new Error("Authentication failed") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.AlreadyAuthenticated: { + this.debug(["More than one auth payload was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.InvalidSeq: { + this.debug(["An invalid sequence was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.RateLimited: { + this.debug(["The WebSocket rate limit has been hit, this should never happen"]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.SessionTimedOut: { + this.debug(["Session timed out."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.InvalidShard: { + this.emit("error" /* Error */, { + error: new Error("Invalid shard") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.ShardingRequired: { + this.emit("error" /* Error */, { + error: new Error("Sharding is required") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.InvalidAPIVersion: { + this.emit("error" /* Error */, { + error: new Error("Used an invalid API version") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.InvalidIntents: { + this.emit("error" /* Error */, { + error: new Error("Used invalid intents") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.DisallowedIntents: { + this.emit("error" /* Error */, { + error: new Error("Used disallowed intents") + }); + return this.destroy({ code }); + } + default: { + this.debug([ + `The gateway closed with an unexpected code ${code}, attempting to ${this.failedToConnectDueToNetworkError ? "reconnect" : "resume"}.` + ]); + return this.destroy({ + code, + recover: this.failedToConnectDueToNetworkError ? 0 /* Reconnect */ : 1 /* Resume */ + }); + } + } + } + debug(messages) { + const message = `${messages[0]}${messages.length > 1 ? ` +${messages.slice(1).map((m) => ` ${m}`).join("\n")}` : ""}`; + this.emit("debug" /* Debug */, { message }); + } +}; + +// src/utils/WorkerBootstrapper.ts +var WorkerBootstrapper = class { + static { + __name(this, "WorkerBootstrapper"); + } + /** + * The data passed to the worker thread + */ + data = workerData; + /** + * The shards that are managed by this worker + */ + shards = new Collection7(); + constructor() { + if (isMainThread2) { + throw new Error("Expected WorkerBootstrap to not be used within the main thread"); + } + } + /** + * Helper method to initiate a shard's connection process + */ + async connect(shardId) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.connect(); + } + /** + * Helper method to destroy a shard + */ + async destroy(shardId, options) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.destroy(options); + } + /** + * Helper method to attach event listeners to the parentPort + */ + setupThreadEvents() { + parentPort2.on("messageerror", (err) => { + throw err; + }).on("message", async (payload) => { + switch (payload.op) { + case 0 /* Connect */: { + await this.connect(payload.shardId); + const response = { + op: 0 /* Connected */, + shardId: payload.shardId + }; + parentPort2.postMessage(response); + break; + } + case 1 /* Destroy */: { + await this.destroy(payload.shardId, payload.options); + const response = { + op: 1 /* Destroyed */, + shardId: payload.shardId + }; + parentPort2.postMessage(response); + break; + } + case 2 /* Send */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new RangeError(`Shard ${payload.shardId} does not exist`); + } + await shard.send(payload.payload); + break; + } + case 3 /* SessionInfoResponse */: { + break; + } + case 4 /* ShardIdentifyResponse */: { + break; + } + case 5 /* FetchStatus */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new Error(`Shard ${payload.shardId} does not exist`); + } + const response = { + op: 6 /* FetchStatusResponse */, + status: shard.status, + nonce: payload.nonce + }; + parentPort2.postMessage(response); + break; + } + } + }); + } + /** + * Bootstraps the worker thread with the provided options + */ + async bootstrap(options = {}) { + for (const shardId of this.data.shardIds) { + const shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId); + for (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) { + shard.on(event, (data) => { + const payload = { + op: 2 /* Event */, + event, + data, + shardId + }; + parentPort2.postMessage(payload); + }); + } + await options.shardCallback?.(shard); + this.shards.set(shardId, shard); + } + this.setupThreadEvents(); + const message = { + op: 7 /* WorkerReady */ + }; + parentPort2.postMessage(message); + } +}; + +// src/strategies/sharding/defaultWorker.ts +var bootstrapper = new WorkerBootstrapper(); +void bootstrapper.bootstrap(); +//# sourceMappingURL=defaultWorker.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/dist/defaultWorker.mjs.map b/node_modules/@discordjs/ws/dist/defaultWorker.mjs.map new file mode 100644 index 0000000..8ef3f02 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/defaultWorker.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/utils/WorkerBootstrapper.ts","../src/strategies/context/WorkerContextFetchingStrategy.ts","../src/strategies/sharding/WorkerShardingStrategy.ts","../src/strategies/context/IContextFetchingStrategy.ts","../src/ws/WebSocketShard.ts","../src/utils/constants.ts","../src/strategies/sharding/SimpleShardingStrategy.ts","../src/strategies/context/SimpleContextFetchingStrategy.ts","../src/throttling/SimpleIdentifyThrottler.ts","../src/strategies/sharding/defaultWorker.ts"],"sourcesContent":["import { isMainThread, parentPort, workerData } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { Awaitable } from '@discordjs/util';\nimport { WorkerContextFetchingStrategy } from '../strategies/context/WorkerContextFetchingStrategy.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerData,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../strategies/sharding/WorkerShardingStrategy.js';\nimport type { WebSocketShardDestroyOptions } from '../ws/WebSocketShard.js';\nimport { WebSocketShardEvents, WebSocketShard } from '../ws/WebSocketShard.js';\n\n/**\n * Options for bootstrapping the worker\n */\nexport interface BootstrapOptions {\n\t/**\n\t * Shard events to just arbitrarily forward to the parent thread for the manager to emit\n\t * Note: By default, this will include ALL events\n\t * you most likely want to handle dispatch within the worker itself\n\t */\n\tforwardEvents?: WebSocketShardEvents[];\n\t/**\n\t * Function to call when a shard is created for additional setup\n\t */\n\tshardCallback?(shard: WebSocketShard): Awaitable<void>;\n}\n\n/**\n * Utility class for bootstrapping a worker thread to be used for sharding\n */\nexport class WorkerBootstrapper {\n\t/**\n\t * The data passed to the worker thread\n\t */\n\tprotected readonly data = workerData as WorkerData;\n\n\t/**\n\t * The shards that are managed by this worker\n\t */\n\tprotected readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor() {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Expected WorkerBootstrap to not be used within the main thread');\n\t\t}\n\t}\n\n\t/**\n\t * Helper method to initiate a shard's connection process\n\t */\n\tprotected async connect(shardId: number): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.connect();\n\t}\n\n\t/**\n\t * Helper method to destroy a shard\n\t */\n\tprotected async destroy(shardId: number, options?: WebSocketShardDestroyOptions): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.destroy(options);\n\t}\n\n\t/**\n\t * Helper method to attach event listeners to the parentPort\n\t */\n\tprotected setupThreadEvents(): void {\n\t\tparentPort!\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerSendPayload) => {\n\t\t\t\tswitch (payload.op) {\n\t\t\t\t\tcase WorkerSendPayloadOp.Connect: {\n\t\t\t\t\t\tawait this.connect(payload.shardId);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Connected,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Destroy: {\n\t\t\t\t\t\tawait this.destroy(payload.shardId, payload.options);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Destroyed,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Send: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new RangeError(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait shard.send(payload.payload);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.SessionInfoResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.ShardIdentifyResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.FetchStatus: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new Error(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.FetchStatusResponse,\n\t\t\t\t\t\t\tstatus: shard.status,\n\t\t\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\t/**\n\t * Bootstraps the worker thread with the provided options\n\t */\n\tpublic async bootstrap(options: Readonly<BootstrapOptions> = {}): Promise<void> {\n\t\t// Start by initializing the shards\n\t\tfor (const shardId of this.data.shardIds) {\n\t\t\tconst shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId);\n\t\t\tfor (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Event types incompatible\n\t\t\t\tshard.on(event, (data) => {\n\t\t\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\t\t\top: WorkerReceivePayloadOp.Event,\n\t\t\t\t\t\tevent,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tshardId,\n\t\t\t\t\t};\n\t\t\t\t\tparentPort!.postMessage(payload);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Any additional setup the user might want to do\n\t\t\tawait options.shardCallback?.(shard);\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\n\t\t// Lastly, start listening to messages from the parent thread\n\t\tthis.setupThreadEvents();\n\n\t\tconst message: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WorkerReady,\n\t\t};\n\t\tparentPort!.postMessage(message);\n\t}\n}\n","import { isMainThread, parentPort } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { SessionInfo } from '../../ws/WebSocketManager.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../sharding/WorkerShardingStrategy.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class WorkerContextFetchingStrategy implements IContextFetchingStrategy {\n\tprivate readonly sessionPromises = new Collection<number, (session: SessionInfo | null) => void>();\n\n\tprivate readonly waitForIdentifyPromises = new Collection<\n\t\tnumber,\n\t\t{ reject(error: unknown): void; resolve(): void; signal: AbortSignal }\n\t>();\n\n\tpublic constructor(public readonly options: FetchingStrategyOptions) {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Cannot instantiate WorkerContextFetchingStrategy on the main thread');\n\t\t}\n\n\t\tparentPort!.on('message', (payload: WorkerSendPayload) => {\n\t\t\tif (payload.op === WorkerSendPayloadOp.SessionInfoResponse) {\n\t\t\t\tthis.sessionPromises.get(payload.nonce)?.(payload.session);\n\t\t\t\tthis.sessionPromises.delete(payload.nonce);\n\t\t\t}\n\n\t\t\tif (payload.op === WorkerSendPayloadOp.ShardIdentifyResponse) {\n\t\t\t\tconst promise = this.waitForIdentifyPromises.get(payload.nonce);\n\t\t\t\tif (payload.ok) {\n\t\t\t\t\tpromise?.resolve();\n\t\t\t\t} else {\n\t\t\t\t\t// We need to make sure we reject with an abort error\n\t\t\t\t\tpromise?.reject(promise.signal.reason);\n\t\t\t\t}\n\n\t\t\t\tthis.waitForIdentifyPromises.delete(payload.nonce);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\tconst nonce = Math.random();\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.RetrieveSessionInfo,\n\t\t\tshardId,\n\t\t\tnonce,\n\t\t};\n\t\t// eslint-disable-next-line no-promise-executor-return\n\t\tconst promise = new Promise<SessionInfo | null>((resolve) => this.sessionPromises.set(nonce, resolve));\n\t\tparentPort!.postMessage(payload);\n\t\treturn promise;\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.UpdateSessionInfo,\n\t\t\tshardId,\n\t\t\tsession: sessionInfo,\n\t\t};\n\t\tparentPort!.postMessage(payload);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst nonce = Math.random();\n\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WaitForIdentify,\n\t\t\tnonce,\n\t\t\tshardId,\n\t\t};\n\t\tconst promise = new Promise<void>((resolve, reject) =>\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tthis.waitForIdentifyPromises.set(nonce, { signal, resolve, reject }),\n\t\t);\n\n\t\tparentPort!.postMessage(payload);\n\n\t\tconst listener = () => {\n\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\top: WorkerReceivePayloadOp.CancelIdentify,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\tparentPort!.postMessage(payload);\n\t\t};\n\n\t\tsignal.addEventListener('abort', listener);\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} finally {\n\t\t\tsignal.removeEventListener('abort', listener);\n\t\t}\n\t}\n}\n","import { once } from 'node:events';\nimport { join, isAbsolute, resolve } from 'node:path';\nimport { Worker } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type {\n\tWebSocketShardDestroyOptions,\n\tWebSocketShardEvents,\n\tWebSocketShardStatus,\n} from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions, type FetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\nexport interface WorkerData extends FetchingStrategyOptions {\n\tshardIds: number[];\n}\n\nexport enum WorkerSendPayloadOp {\n\tConnect,\n\tDestroy,\n\tSend,\n\tSessionInfoResponse,\n\tShardIdentifyResponse,\n\tFetchStatus,\n}\n\nexport type WorkerSendPayload =\n\t| { nonce: number; ok: boolean; op: WorkerSendPayloadOp.ShardIdentifyResponse }\n\t| { nonce: number; op: WorkerSendPayloadOp.FetchStatus; shardId: number }\n\t| { nonce: number; op: WorkerSendPayloadOp.SessionInfoResponse; session: SessionInfo | null }\n\t| { op: WorkerSendPayloadOp.Connect; shardId: number }\n\t| { op: WorkerSendPayloadOp.Destroy; options?: WebSocketShardDestroyOptions; shardId: number }\n\t| { op: WorkerSendPayloadOp.Send; payload: GatewaySendPayload; shardId: number };\n\nexport enum WorkerReceivePayloadOp {\n\tConnected,\n\tDestroyed,\n\tEvent,\n\tRetrieveSessionInfo,\n\tUpdateSessionInfo,\n\tWaitForIdentify,\n\tFetchStatusResponse,\n\tWorkerReady,\n\tCancelIdentify,\n}\n\nexport type WorkerReceivePayload =\n\t// Can't seem to get a type-safe union based off of the event, so I'm sadly leaving data as any for now\n\t| { data: any; event: WebSocketShardEvents; op: WorkerReceivePayloadOp.Event; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.CancelIdentify }\n\t| { nonce: number; op: WorkerReceivePayloadOp.FetchStatusResponse; status: WebSocketShardStatus }\n\t| { nonce: number; op: WorkerReceivePayloadOp.RetrieveSessionInfo; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.WaitForIdentify; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Connected; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Destroyed; shardId: number }\n\t| { op: WorkerReceivePayloadOp.UpdateSessionInfo; session: SessionInfo | null; shardId: number }\n\t| { op: WorkerReceivePayloadOp.WorkerReady };\n\n/**\n * Options for a {@link WorkerShardingStrategy}\n */\nexport interface WorkerShardingStrategyOptions {\n\t/**\n\t * Dictates how many shards should be spawned per worker thread.\n\t */\n\tshardsPerWorker: number | 'all';\n\t/**\n\t * Path to the worker file to use. The worker requires quite a bit of setup, it is recommended you leverage the {@link WorkerBootstrapper} class.\n\t */\n\tworkerPath?: string;\n}\n\n/**\n * Strategy used to spawn threads in worker_threads\n */\nexport class WorkerShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly options: WorkerShardingStrategyOptions;\n\n\t#workers: Worker[] = [];\n\n\treadonly #workerByShardId = new Collection<number, Worker>();\n\n\tprivate readonly connectPromises = new Collection<number, () => void>();\n\n\tprivate readonly destroyPromises = new Collection<number, () => void>();\n\n\tprivate readonly fetchStatusPromises = new Collection<number, (status: WebSocketShardStatus) => void>();\n\n\tprivate readonly waitForIdentifyControllers = new Collection<number, AbortController>();\n\n\tprivate throttler?: IIdentifyThrottler;\n\n\tpublic constructor(manager: WebSocketManager, options: WorkerShardingStrategyOptions) {\n\t\tthis.manager = manager;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst shardsPerWorker = this.options.shardsPerWorker === 'all' ? shardIds.length : this.options.shardsPerWorker;\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tconst loops = Math.ceil(shardIds.length / shardsPerWorker);\n\t\tconst promises: Promise<void>[] = [];\n\n\t\tfor (let idx = 0; idx < loops; idx++) {\n\t\t\tconst slice = shardIds.slice(idx * shardsPerWorker, (idx + 1) * shardsPerWorker);\n\t\t\tconst workerData: WorkerData = {\n\t\t\t\t...strategyOptions,\n\t\t\t\tshardIds: slice,\n\t\t\t};\n\n\t\t\tpromises.push(this.setupWorker(workerData));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Connect,\n\t\t\t\tshardId,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<void>((resolve) => this.connectPromises.set(shardId, resolve));\n\t\t\tworker.postMessage(payload);\n\t\t\tpromises.push(promise);\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options: Omit<WebSocketShardDestroyOptions, 'recover'> = {}) {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Destroy,\n\t\t\t\tshardId,\n\t\t\t\toptions,\n\t\t\t};\n\n\t\t\tpromises.push(\n\t\t\t\t// eslint-disable-next-line no-promise-executor-return, promise/prefer-await-to-then\n\t\t\t\tnew Promise<void>((resolve) => this.destroyPromises.set(shardId, resolve)).then(async () => worker.terminate()),\n\t\t\t);\n\t\t\tworker.postMessage(payload);\n\t\t}\n\n\t\tthis.#workers = [];\n\t\tthis.#workerByShardId.clear();\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic send(shardId: number, data: GatewaySendPayload) {\n\t\tconst worker = this.#workerByShardId.get(shardId);\n\t\tif (!worker) {\n\t\t\tthrow new Error(`No worker found for shard ${shardId}`);\n\t\t}\n\n\t\tconst payload: WorkerSendPayload = {\n\t\t\top: WorkerSendPayloadOp.Send,\n\t\t\tshardId,\n\t\t\tpayload: data,\n\t\t};\n\t\tworker.postMessage(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\tconst statuses = new Collection<number, WebSocketShardStatus>();\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst nonce = Math.random();\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.FetchStatus,\n\t\t\t\tshardId,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<WebSocketShardStatus>((resolve) => this.fetchStatusPromises.set(nonce, resolve));\n\t\t\tworker.postMessage(payload);\n\n\t\t\tconst status = await promise;\n\t\t\tstatuses.set(shardId, status);\n\t\t}\n\n\t\treturn statuses;\n\t}\n\n\tprivate async setupWorker(workerData: WorkerData) {\n\t\tconst worker = new Worker(this.resolveWorkerPath(), { workerData });\n\n\t\tawait once(worker, 'online');\n\t\t// We do this in case the user has any potentially long running code in their worker\n\t\tawait this.waitForWorkerReady(worker);\n\n\t\tworker\n\t\t\t.on('error', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerReceivePayload) => this.onMessage(worker, payload));\n\n\t\tthis.#workers.push(worker);\n\t\tfor (const shardId of workerData.shardIds) {\n\t\t\tthis.#workerByShardId.set(shardId, worker);\n\t\t}\n\t}\n\n\tprivate resolveWorkerPath(): string {\n\t\tconst path = this.options.workerPath;\n\n\t\tif (!path) {\n\t\t\treturn join(__dirname, 'defaultWorker.js');\n\t\t}\n\n\t\tif (isAbsolute(path)) {\n\t\t\treturn path;\n\t\t}\n\n\t\tif (/^\\.\\.?[/\\\\]/.test(path)) {\n\t\t\treturn resolve(path);\n\t\t}\n\n\t\ttry {\n\t\t\treturn require.resolve(path);\n\t\t} catch {\n\t\t\treturn resolve(path);\n\t\t}\n\t}\n\n\tprivate async waitForWorkerReady(worker: Worker): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst handler = (payload: WorkerReceivePayload) => {\n\t\t\t\tif (payload.op === WorkerReceivePayloadOp.WorkerReady) {\n\t\t\t\t\tresolve();\n\t\t\t\t\tworker.off('message', handler);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tworker.on('message', handler);\n\t\t});\n\t}\n\n\tprivate async onMessage(worker: Worker, payload: WorkerReceivePayload) {\n\t\tswitch (payload.op) {\n\t\t\tcase WorkerReceivePayloadOp.Connected: {\n\t\t\t\tthis.connectPromises.get(payload.shardId)?.();\n\t\t\t\tthis.connectPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Destroyed: {\n\t\t\t\tthis.destroyPromises.get(payload.shardId)?.();\n\t\t\t\tthis.destroyPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Event: {\n\t\t\t\tthis.manager.emit(payload.event, { ...payload.data, shardId: payload.shardId });\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.RetrieveSessionInfo: {\n\t\t\t\tconst session = await this.manager.options.retrieveSessionInfo(payload.shardId);\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.SessionInfoResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tsession,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.UpdateSessionInfo: {\n\t\t\t\tawait this.manager.options.updateSessionInfo(payload.shardId, payload.session);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WaitForIdentify: {\n\t\t\t\tconst throttler = await this.ensureThrottler();\n\n\t\t\t\t// If this rejects it means we aborted, in which case we reply elsewhere.\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.waitForIdentifyControllers.set(payload.nonce, controller);\n\t\t\t\t\tawait throttler.waitForIdentify(payload.shardId, controller.signal);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: true,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.FetchStatusResponse: {\n\t\t\t\tthis.fetchStatusPromises.get(payload.nonce)?.(payload.status);\n\t\t\t\tthis.fetchStatusPromises.delete(payload.nonce);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WorkerReady: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.CancelIdentify: {\n\t\t\t\tthis.waitForIdentifyControllers.get(payload.nonce)?.abort();\n\t\t\t\tthis.waitForIdentifyControllers.delete(payload.nonce);\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: false,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async ensureThrottler(): Promise<IIdentifyThrottler> {\n\t\tthis.throttler ??= await this.manager.options.buildIdentifyThrottler(this.manager);\n\t\treturn this.throttler;\n\t}\n}\n","import type { Awaitable } from '@discordjs/util';\nimport type { APIGatewayBotInfo } from 'discord-api-types/v10';\nimport type { SessionInfo, WebSocketManager, WebSocketManagerOptions } from '../../ws/WebSocketManager.js';\n\nexport interface FetchingStrategyOptions\n\textends Omit<\n\t\tWebSocketManagerOptions,\n\t\t| 'buildIdentifyThrottler'\n\t\t| 'buildStrategy'\n\t\t| 'rest'\n\t\t| 'retrieveSessionInfo'\n\t\t| 'shardCount'\n\t\t| 'shardIds'\n\t\t| 'updateSessionInfo'\n\t> {\n\treadonly gatewayInformation: APIGatewayBotInfo;\n\treadonly shardCount: number;\n}\n\n/**\n * Strategies responsible solely for making manager information accessible\n */\nexport interface IContextFetchingStrategy {\n\treadonly options: FetchingStrategyOptions;\n\tretrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>;\n\tupdateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>;\n\t/**\n\t * Resolves once the given shard should be allowed to identify\n\t * This should correctly handle the signal and reject with an abort error if the operation is aborted.\n\t * Other errors will cause the shard to reconnect.\n\t */\n\twaitForIdentify(shardId: number, signal: AbortSignal): Promise<void>;\n}\n\nexport async function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions> {\n\t/* eslint-disable @typescript-eslint/unbound-method */\n\tconst {\n\t\tbuildIdentifyThrottler,\n\t\tbuildStrategy,\n\t\tretrieveSessionInfo,\n\t\tupdateSessionInfo,\n\t\tshardCount,\n\t\tshardIds,\n\t\trest,\n\t\t...managerOptions\n\t} = manager.options;\n\t/* eslint-enable @typescript-eslint/unbound-method */\n\n\treturn {\n\t\t...managerOptions,\n\t\tgatewayInformation: await manager.fetchGatewayInformation(),\n\t\tshardCount: await manager.getShardCount(),\n\t};\n}\n","/* eslint-disable id-length */\nimport { Buffer } from 'node:buffer';\nimport { once } from 'node:events';\nimport { clearInterval, clearTimeout, setInterval, setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { URLSearchParams } from 'node:url';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayOpcodes,\n\ttype GatewayDispatchPayload,\n\ttype GatewayIdentifyData,\n\ttype GatewayReadyDispatchData,\n\ttype GatewayReceivePayload,\n\ttype GatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { WebSocket, type Data } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy.js';\nimport { ImportantGatewayOpcodes, getInitialSendRateLimitState } from '../utils/constants.js';\nimport type { SessionInfo } from './WebSocketManager.js';\n\n// eslint-disable-next-line promise/prefer-await-to-then\nconst getZlibSync = lazy(async () => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tClosed = 'closed',\n\tDebug = 'debug',\n\tDispatch = 'dispatch',\n\tError = 'error',\n\tHeartbeatComplete = 'heartbeat',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Closed]: [{ code: number }];\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n\t[WebSocketShardEvents.Error]: [payload: { error: Error }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [payload: { data: GatewayReadyDispatchData }];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.HeartbeatComplete]: [payload: { ackAt: number; heartbeatAt: number; latency: number }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\tcode?: number;\n\treason?: string;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1_000,\n\tResuming = 4_200,\n}\n\nexport interface SendRateLimitState {\n\tremaining: number;\n\tresetAt: number;\n}\n\n// TODO(vladfrangu): enable this once https://github.com/oven-sh/bun/issues/3392 is solved\n// const WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket()\n// \t? (globalThis as any).WebSocket\n// \t: WebSocket;\nconst WebSocketConstructor: typeof WebSocket = WebSocket;\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState: SendRateLimitState = getInitialSendRateLimitState();\n\n\tprivate initialHeartbeatTimeoutController: AbortController | null = null;\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\n\tprivate lastHeartbeatAt = -1;\n\n\t// Indicates whether the shard has already resolved its original connect() call\n\tprivate initialConnectResolved = false;\n\n\t// Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET)\n\tprivate failedToConnectDueToNetworkError = false;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeoutAbortControllers = new Collection<WebSocketShardEvents, AbortController>();\n\n\tprivate readonly strategy: IContextFetchingStrategy;\n\n\tpublic readonly id: number;\n\n\t#status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tpublic get status(): WebSocketShardStatus {\n\t\treturn this.#status;\n\t}\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tconst controller = new AbortController();\n\t\tlet promise;\n\n\t\tif (!this.initialConnectResolved) {\n\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\tpromise = Promise.race([\n\t\t\t\tonce(this, WebSocketShardEvents.Ready, { signal: controller.signal }),\n\t\t\t\tonce(this, WebSocketShardEvents.Resumed, { signal: controller.signal }),\n\t\t\t]);\n\t\t}\n\n\t\tvoid this.internalConnect();\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} catch ({ error }: any) {\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// cleanup hanging listeners\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.initialConnectResolved = true;\n\t}\n\n\tprivate async internalConnect() {\n\t\tif (this.#status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65_535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\n\t\tthis.debug([`Connecting to ${url}`]);\n\n\t\tconst connection = new WebSocketConstructor(url, {\n\t\t\thandshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined,\n\t\t});\n\n\t\tconnection.binaryType = 'arraybuffer';\n\n\t\tconnection.onmessage = (event) => {\n\t\t\tvoid this.onMessage(event.data, event.data instanceof ArrayBuffer);\n\t\t};\n\n\t\tconnection.onerror = (event) => {\n\t\t\tthis.onError(event.error);\n\t\t};\n\n\t\tconnection.onclose = (event) => {\n\t\t\tvoid this.onClose(event.code);\n\t\t};\n\n\t\tthis.connection = connection;\n\n\t\tthis.#status = WebSocketShardStatus.Connecting;\n\n\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\n\t\tconst { ok } = await this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\t\tif (!ok) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.#status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\n\t\tif (this.initialHeartbeatTimeoutController) {\n\t\t\tthis.initialHeartbeatTimeoutController.abort();\n\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t}\n\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\tfor (const controller of this.timeoutAbortControllers.values()) {\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.timeoutAbortControllers.clear();\n\n\t\tthis.failedToConnectDueToNetworkError = false;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume) {\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (this.connection) {\n\t\t\t// No longer need to listen to messages\n\t\t\tthis.connection.onmessage = null;\n\t\t\t// Prevent a reconnection loop by unbinding the main close event\n\t\t\tthis.connection.onclose = null;\n\n\t\t\tconst shouldClose = this.connection.readyState === WebSocket.OPEN;\n\n\t\t\tthis.debug([\n\t\t\t\t'Connection status during destroy',\n\t\t\t\t`Needs closing: ${shouldClose}`,\n\t\t\t\t`Ready state: ${this.connection.readyState}`,\n\t\t\t]);\n\n\t\t\tif (shouldClose) {\n\t\t\t\tlet outerResolve: () => void;\n\t\t\t\tconst promise = new Promise<void>((resolve) => {\n\t\t\t\t\touterResolve = resolve;\n\t\t\t\t});\n\n\t\t\t\tthis.connection.onclose = outerResolve!;\n\n\t\t\t\tthis.connection.close(options.code, options.reason);\n\n\t\t\t\tawait promise;\n\t\t\t\tthis.emit(WebSocketShardEvents.Closed, { code: options.code });\n\t\t\t}\n\n\t\t\t// Lastly, remove the error event.\n\t\t\t// Doing this earlier would cause a hard crash in case an error event fired on our `close` call\n\t\t\tthis.connection.onerror = null;\n\t\t} else {\n\t\t\tthis.debug(['Destroying a shard that has no connection; please open an issue on GitHub']);\n\t\t}\n\n\t\tthis.#status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\t// There's cases (like no internet connection) where we immediately fail to connect,\n\t\t\t// causing a very fast and draining reconnection loop.\n\t\t\tawait sleep(500);\n\t\t\treturn this.internalConnect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null): Promise<{ ok: boolean }> {\n\t\tthis.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst timeoutController = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => timeoutController.abort(), timeoutDuration).unref() : null;\n\n\t\tthis.timeoutAbortControllers.set(event, timeoutController);\n\n\t\tconst closeController = new AbortController();\n\n\t\ttry {\n\t\t\t// If the first promise resolves, all is well. If the 2nd promise resolves,\n\t\t\t// the shard has meanwhile closed. In that case, a destroy is already ongoing, so we just need to\n\t\t\t// return false. Meanwhile, if something rejects (error event) or the first controller is aborted,\n\t\t\t// we enter the catch block and trigger a destroy there.\n\t\t\tconst closed = await Promise.race<boolean>([\n\t\t\t\tonce(this, event, { signal: timeoutController.signal }).then(() => false),\n\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: closeController.signal }).then(() => true),\n\t\t\t]);\n\n\t\t\treturn { ok: !closed };\n\t\t} catch {\n\t\t\t// If we're here because of other reasons, we need to destroy the shard\n\t\t\tvoid this.destroy({\n\t\t\t\tcode: CloseCodes.Normal,\n\t\t\t\treason: 'Something timed out or went wrong while waiting for an event',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t});\n\n\t\t\treturn { ok: false };\n\t\t} finally {\n\t\t\tif (timeout) {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t}\n\n\t\t\tthis.timeoutAbortControllers.delete(event);\n\n\t\t\t// Clean up the close listener to not leak memory\n\t\t\tif (!closeController.signal.aborted) {\n\t\t\t\tcloseController.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload): Promise<void> {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.#status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tthis.debug(['Tried to send a non-crucial payload before the shard was ready, waiting']);\n\t\t\t// This will throw if the shard throws an error event in the meantime, just requeue the payload\n\t\t\ttry {\n\t\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t\t} catch {\n\t\t\t\treturn this.send(payload);\n\t\t\t}\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tconst now = Date.now();\n\n\t\t\tif (this.sendRateLimitState.resetAt > now) {\n\t\t\t\tconst sleepFor = this.sendRateLimitState.resetAt - now;\n\n\t\t\t\tthis.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]);\n\t\t\t\tconst controller = new AbortController();\n\n\t\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\t\tconst interrupted = await Promise.race([\n\t\t\t\t\tsleep(sleepFor).then(() => false),\n\t\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: controller.signal }).then(() => true),\n\t\t\t\t]);\n\n\t\t\t\tif (interrupted) {\n\t\t\t\t\tthis.debug(['Connection closed while waiting for the send rate limit to reset, re-queueing payload']);\n\t\t\t\t\tthis.sendQueue.shift();\n\t\t\t\t\treturn this.send(payload);\n\t\t\t\t}\n\n\t\t\t\t// This is so the listener from the `once` call is removed\n\t\t\t\tcontroller.abort();\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug(['Waiting for identify throttle']);\n\n\t\tconst controller = new AbortController();\n\t\tconst closeHandler = () => {\n\t\t\tcontroller.abort();\n\t\t};\n\n\t\tthis.on(WebSocketShardEvents.Closed, closeHandler);\n\n\t\ttry {\n\t\t\tawait this.strategy.waitForIdentify(this.id, controller.signal);\n\t\t} catch {\n\t\t\tif (controller.signal.aborted) {\n\t\t\t\tthis.debug(['Was waiting for an identify, but the shard closed in the meantime']);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.debug([\n\t\t\t\t'IContextFetchingStrategy#waitForIdentify threw an unknown error.',\n\t\t\t\t\"If you're using a custom strategy, this is probably nothing to worry about.\",\n\t\t\t\t\"If you're not, please open an issue on GitHub.\",\n\t\t\t]);\n\n\t\t\tawait this.destroy({\n\t\t\t\treason: 'Identify throttling logic failed',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.off(WebSocketShardEvents.Closed, closeHandler);\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t}\n\n\tprivate async resume(session: SessionInfo) {\n\t\tthis.debug([\n\t\t\t'Resuming session',\n\t\t\t`resume url: ${session.resumeURL}`,\n\t\t\t`sequence: ${session.sequence}`,\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t]);\n\n\t\tthis.#status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Data, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(data as string) as GatewayReceivePayload;\n\t\t\t} catch {\n\t\t\t\t// This is a non-JSON payload / (at the time of writing this comment) emitted by bun wrongly interpreting custom close codes https://github.com/oven-sh/bun/issues/3392\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tconst decompressable = new Uint8Array(data as ArrayBuffer);\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\t\t\t\tinflate(decompressable, { chunkSize: 65_535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: Data, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.#status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line sonarjs/no-nested-switch\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\n\t\t\t\t\t\tconst session = {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, session);\n\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready, { data: payload.d });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (session) {\n\t\t\t\t\tif (payload.s > session.sequence) {\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.debug([\n\t\t\t\t\t\t`Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect`,\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tconst jitter = Math.random();\n\t\t\t\tconst firstWait = Math.floor(payload.d.heartbeat_interval * jitter);\n\t\t\t\tthis.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]);\n\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = controller;\n\t\t\t\t\tawait sleep(firstWait, undefined, { signal: controller.signal });\n\t\t\t\t} catch {\n\t\t\t\t\tthis.debug(['Cancelled initial heartbeat due to #destroy being called']);\n\t\t\t\t\treturn;\n\t\t\t\t} finally {\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t\t\t}\n\n\t\t\t\tawait this.heartbeat();\n\n\t\t\t\tthis.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\n\t\t\t\tconst ackAt = Date.now();\n\t\t\t\tthis.emit(WebSocketShardEvents.HeartbeatComplete, {\n\t\t\t\t\tackAt,\n\t\t\t\t\theartbeatAt: this.lastHeartbeatAt,\n\t\t\t\t\tlatency: ackAt - this.lastHeartbeatAt,\n\t\t\t\t});\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(error: Error) {\n\t\tif ('code' in error && ['ECONNRESET', 'ECONNREFUSED'].includes(error.code as string)) {\n\t\t\tthis.debug(['Failed to connect to the gateway URL specified due to a network error']);\n\t\t\tthis.failedToConnectDueToNetworkError = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.emit(WebSocketShardEvents.Error, { error });\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tthis.emit(WebSocketShardEvents.Closed, { code });\n\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occurred: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Authentication failed'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Invalid shard'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Sharding is required'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used an invalid API version'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used invalid intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used disallowed intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([\n\t\t\t\t\t`The gateway closed with an unexpected code ${code}, attempting to ${\n\t\t\t\t\t\tthis.failedToConnectDueToNetworkError ? 'reconnect' : 'resume'\n\t\t\t\t\t}.`,\n\t\t\t\t]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\trecover: this.failedToConnectDueToNetworkError\n\t\t\t\t\t\t? WebSocketShardDestroyRecovery.Reconnect\n\t\t\t\t\t\t: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n","import process from 'node:process';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { APIVersion, GatewayOpcodes } from 'discord-api-types/v10';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy.js';\nimport { SimpleIdentifyThrottler } from '../throttling/SimpleIdentifyThrottler.js';\nimport type { SessionInfo, OptionalWebSocketManagerOptions, WebSocketManager } from '../ws/WebSocketManager.js';\nimport type { SendRateLimitState } from '../ws/WebSocketShard.js';\n\n/**\n * Valid encoding types\n */\nexport enum Encoding {\n\tJSON = 'json',\n}\n\n/**\n * Valid compression methods\n */\nexport enum CompressionMethod {\n\tZlibStream = 'zlib-stream',\n}\n\nexport const DefaultDeviceProperty = `@discordjs/ws 1.0.1` as `@discordjs/ws ${string}`;\n\nconst getDefaultSessionStore = lazy(() => new Collection<number, SessionInfo | null>());\n\n/**\n * Default options used by the manager\n */\nexport const DefaultWebSocketManagerOptions = {\n\tasync buildIdentifyThrottler(manager: WebSocketManager) {\n\t\tconst info = await manager.fetchGatewayInformation();\n\t\treturn new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency);\n\t},\n\tbuildStrategy: (manager) => new SimpleShardingStrategy(manager),\n\tshardCount: null,\n\tshardIds: null,\n\tlargeThreshold: null,\n\tinitialPresence: null,\n\tidentifyProperties: {\n\t\tbrowser: DefaultDeviceProperty,\n\t\tdevice: DefaultDeviceProperty,\n\t\tos: process.platform,\n\t},\n\tversion: APIVersion,\n\tencoding: Encoding.JSON,\n\tcompression: null,\n\tretrieveSessionInfo(shardId) {\n\t\tconst store = getDefaultSessionStore();\n\t\treturn store.get(shardId) ?? null;\n\t},\n\tupdateSessionInfo(shardId: number, info: SessionInfo | null) {\n\t\tconst store = getDefaultSessionStore();\n\t\tif (info) {\n\t\t\tstore.set(shardId, info);\n\t\t} else {\n\t\t\tstore.delete(shardId);\n\t\t}\n\t},\n\thandshakeTimeout: 30_000,\n\thelloTimeout: 60_000,\n\treadyTimeout: 15_000,\n} as const satisfies OptionalWebSocketManagerOptions;\n\nexport const ImportantGatewayOpcodes = new Set([\n\tGatewayOpcodes.Heartbeat,\n\tGatewayOpcodes.Identify,\n\tGatewayOpcodes.Resume,\n]);\n\nexport function getInitialSendRateLimitState(): SendRateLimitState {\n\treturn {\n\t\tremaining: 120,\n\t\tresetAt: Date.now() + 60_000,\n\t};\n}\n","import { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { WebSocketManager } from '../../ws/WebSocketManager.js';\nimport { WebSocketShard, WebSocketShardEvents, type WebSocketShardDestroyOptions } from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport { SimpleContextFetchingStrategy } from '../context/SimpleContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\n/**\n * Simple strategy that just spawns shards in the current process\n */\nexport class SimpleShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor(manager: WebSocketManager) {\n\t\tthis.manager = manager;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tfor (const shardId of shardIds) {\n\t\t\tconst strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions);\n\t\t\tconst shard = new WebSocketShard(strategy, shardId);\n\t\t\tfor (const event of Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Intentional\n\t\t\t\tshard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId }));\n\t\t\t}\n\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.connect());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.destroy(options));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t\tthis.shards.clear();\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic async send(shardId: number, payload: GatewaySendPayload) {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} not found`);\n\t\t}\n\n\t\treturn shard.send(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\treturn this.shards.mapValues((shard) => shard.status);\n\t}\n}\n","import type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class SimpleContextFetchingStrategy implements IContextFetchingStrategy {\n\t// This strategy assumes every shard is running under the same process - therefore we need a single\n\t// IdentifyThrottler per manager.\n\tprivate static throttlerCache = new WeakMap<WebSocketManager, IIdentifyThrottler>();\n\n\tprivate static async ensureThrottler(manager: WebSocketManager): Promise<IIdentifyThrottler> {\n\t\tconst throttler = SimpleContextFetchingStrategy.throttlerCache.get(manager);\n\t\tif (throttler) {\n\t\t\treturn throttler;\n\t\t}\n\n\t\tconst newThrottler = await manager.options.buildIdentifyThrottler(manager);\n\t\tSimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler);\n\n\t\treturn newThrottler;\n\t}\n\n\tpublic constructor(private readonly manager: WebSocketManager, public readonly options: FetchingStrategyOptions) {}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\treturn this.manager.options.retrieveSessionInfo(shardId);\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\treturn this.manager.options.updateSessionInfo(shardId, sessionInfo);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst throttler = await SimpleContextFetchingStrategy.ensureThrottler(this.manager);\n\t\tawait throttler.waitForIdentify(shardId, signal);\n\t}\n}\n","import { setTimeout as sleep } from 'node:timers/promises';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport type { IIdentifyThrottler } from './IIdentifyThrottler.js';\n\n/**\n * The state of a rate limit key's identify queue.\n */\nexport interface IdentifyState {\n\tqueue: AsyncQueue;\n\tresetsAt: number;\n}\n\n/**\n * Local, in-memory identify throttler.\n */\nexport class SimpleIdentifyThrottler implements IIdentifyThrottler {\n\tprivate readonly states = new Collection<number, IdentifyState>();\n\n\tpublic constructor(private readonly maxConcurrency: number) {}\n\n\t/**\n\t * {@inheritDoc IIdentifyThrottler.waitForIdentify}\n\t */\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst key = shardId % this.maxConcurrency;\n\n\t\tconst state = this.states.ensure(key, () => {\n\t\t\treturn {\n\t\t\t\tqueue: new AsyncQueue(),\n\t\t\t\tresetsAt: Number.POSITIVE_INFINITY,\n\t\t\t};\n\t\t});\n\n\t\tawait state.queue.wait({ signal });\n\n\t\ttry {\n\t\t\tconst diff = state.resetsAt - Date.now();\n\t\t\tif (diff <= 5_000) {\n\t\t\t\t// To account for the latency the IDENTIFY payload goes through, we add a bit more wait time\n\t\t\t\tconst time = diff + Math.random() * 1_500;\n\t\t\t\tawait sleep(time);\n\t\t\t}\n\n\t\t\tstate.resetsAt = Date.now() + 5_000;\n\t\t} finally {\n\t\t\tstate.queue.shift();\n\t\t}\n\t}\n}\n","import { WorkerBootstrapper } from '../../utils/WorkerBootstrapper.js';\n\nconst bootstrapper = new WorkerBootstrapper();\nvoid bootstrapper.bootstrap();\n"],"mappings":";;;;AAAA,SAAS,gBAAAA,eAAc,cAAAC,aAAY,kBAAkB;AACrD,SAAS,cAAAC,mBAAkB;;;ACD3B,SAAS,cAAc,kBAAkB;AACzC,SAAS,cAAAC,mBAAkB;;;ACD3B,SAAS,YAAY;AACrB,SAAS,MAAM,YAAY,eAAe;AAC1C,SAAS,cAAc;AACvB,SAAS,kBAAkB;;;AC+B3B,eAAsB,iCAAiC,SAA6D;AAEnH,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACJ,IAAI,QAAQ;AAGZ,SAAO;AAAA,IACN,GAAG;AAAA,IACH,oBAAoB,MAAM,QAAQ,wBAAwB;AAAA,IAC1D,YAAY,MAAM,QAAQ,cAAc;AAAA,EACzC;AACD;AAnBsB;;;AFvBf,IAAM,gCAAN,MAAwE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,aAAa,UAAU;","names":["isMainThread","parentPort","Collection","Collection","Collection","resolve","payload","Buffer","once","sleep","Collection","lazy","AsyncQueue","GatewayOpcodes","Collection","Collection","Collection","Collection","Collection","Collection","lazy","WebSocketShardEvents","WebSocketShardDestroyRecovery","AsyncQueue","Collection","once","resolve","sleep","GatewayOpcodes","Buffer","session","Collection","isMainThread","parentPort"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/dist/index.d.mts b/node_modules/@discordjs/ws/dist/index.d.mts new file mode 100644 index 0000000..cf7bb7c --- /dev/null +++ b/node_modules/@discordjs/ws/dist/index.d.mts @@ -0,0 +1,669 @@ +import * as _discordjs_util from '@discordjs/util'; +import { Awaitable } from '@discordjs/util'; +import { GatewayDispatchPayload, GatewayReadyDispatchData, GatewaySendPayload, GatewayOpcodes, GatewayIntentBits, GatewayIdentifyProperties, GatewayPresenceUpdateData, APIGatewayBotInfo } from 'discord-api-types/v10'; +import * as _discordjs_collection from '@discordjs/collection'; +import { Collection } from '@discordjs/collection'; +import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; +import { REST } from '@discordjs/rest'; +import { AsyncQueue } from '@sapphire/async-queue'; + +declare enum WebSocketShardEvents { + Closed = "closed", + Debug = "debug", + Dispatch = "dispatch", + Error = "error", + HeartbeatComplete = "heartbeat", + Hello = "hello", + Ready = "ready", + Resumed = "resumed" +} +declare enum WebSocketShardStatus { + Idle = 0, + Connecting = 1, + Resuming = 2, + Ready = 3 +} +declare enum WebSocketShardDestroyRecovery { + Reconnect = 0, + Resume = 1 +} +type WebSocketShardEventsMap = { + [WebSocketShardEvents.Closed]: [{ + code: number; + }]; + [WebSocketShardEvents.Debug]: [payload: { + message: string; + }]; + [WebSocketShardEvents.Dispatch]: [payload: { + data: GatewayDispatchPayload; + }]; + [WebSocketShardEvents.Error]: [payload: { + error: Error; + }]; + [WebSocketShardEvents.Hello]: []; + [WebSocketShardEvents.Ready]: [payload: { + data: GatewayReadyDispatchData; + }]; + [WebSocketShardEvents.Resumed]: []; + [WebSocketShardEvents.HeartbeatComplete]: [payload: { + ackAt: number; + heartbeatAt: number; + latency: number; + }]; +}; +interface WebSocketShardDestroyOptions { + code?: number; + reason?: string; + recover?: WebSocketShardDestroyRecovery; +} +declare enum CloseCodes { + Normal = 1000, + Resuming = 4200 +} +interface SendRateLimitState { + remaining: number; + resetAt: number; +} +declare class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> { + #private; + private connection; + private useIdentifyCompress; + private inflate; + private readonly textDecoder; + private replayedEvents; + private isAck; + private sendRateLimitState; + private initialHeartbeatTimeoutController; + private heartbeatInterval; + private lastHeartbeatAt; + private initialConnectResolved; + private failedToConnectDueToNetworkError; + private readonly sendQueue; + private readonly timeoutAbortControllers; + private readonly strategy; + readonly id: number; + get status(): WebSocketShardStatus; + constructor(strategy: IContextFetchingStrategy, id: number); + connect(): Promise<void>; + private internalConnect; + destroy(options?: WebSocketShardDestroyOptions): Promise<void>; + private waitForEvent; + send(payload: GatewaySendPayload): Promise<void>; + private identify; + private resume; + private heartbeat; + private unpackMessage; + private onMessage; + private onError; + private onClose; + private debug; +} + +/** + * Strategies responsible for spawning, initializing connections, destroying shards, and relaying events + */ +interface IShardingStrategy { + /** + * Initializes all the shards + */ + connect(): Awaitable<void>; + /** + * Destroys all the shards + */ + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Awaitable<void>; + /** + * Fetches the status of all the shards + */ + fetchStatus(): Awaitable<Collection<number, WebSocketShardStatus>>; + /** + * Sends a payload to a shard + */ + send(shardId: number, payload: GatewaySendPayload): Awaitable<void>; + /** + * Spawns all the shards + */ + spawn(shardIds: number[]): Awaitable<void>; +} + +/** + * IdentifyThrottlers are responsible for dictating when a shard is allowed to identify. + * + * @see {@link https://discord.com/developers/docs/topics/gateway#sharding-max-concurrency} + */ +interface IIdentifyThrottler { + /** + * Resolves once the given shard should be allowed to identify, or rejects if the operation was aborted. + */ + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +/** + * Simple strategy that just spawns shards in the current process + */ +declare class SimpleShardingStrategy implements IShardingStrategy { + private readonly manager; + private readonly shards; + constructor(manager: WebSocketManager); + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + spawn(shardIds: number[]): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.connect} + */ + connect(): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.send} + */ + send(shardId: number, payload: GatewaySendPayload): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + fetchStatus(): Promise<Collection<number, WebSocketShardStatus>>; +} + +/** + * The state of a rate limit key's identify queue. + */ +interface IdentifyState { + queue: AsyncQueue; + resetsAt: number; +} +/** + * Local, in-memory identify throttler. + */ +declare class SimpleIdentifyThrottler implements IIdentifyThrottler { + private readonly maxConcurrency; + private readonly states; + constructor(maxConcurrency: number); + /** + * {@inheritDoc IIdentifyThrottler.waitForIdentify} + */ + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +/** + * Valid encoding types + */ +declare enum Encoding { + JSON = "json" +} +/** + * Valid compression methods + */ +declare enum CompressionMethod { + ZlibStream = "zlib-stream" +} +declare const DefaultDeviceProperty: `@discordjs/ws ${string}`; +/** + * Default options used by the manager + */ +declare const DefaultWebSocketManagerOptions: { + readonly buildIdentifyThrottler: (manager: WebSocketManager) => Promise<SimpleIdentifyThrottler>; + readonly buildStrategy: (manager: WebSocketManager) => SimpleShardingStrategy; + readonly shardCount: null; + readonly shardIds: null; + readonly largeThreshold: null; + readonly initialPresence: null; + readonly identifyProperties: { + readonly browser: `@discordjs/ws ${string}`; + readonly device: `@discordjs/ws ${string}`; + readonly os: NodeJS.Platform; + }; + readonly version: "10"; + readonly encoding: Encoding; + readonly compression: null; + readonly retrieveSessionInfo: (shardId: number) => SessionInfo | null; + readonly updateSessionInfo: (shardId: number, info: SessionInfo | null) => void; + readonly handshakeTimeout: 30000; + readonly helloTimeout: 60000; + readonly readyTimeout: 15000; +}; +declare const ImportantGatewayOpcodes: Set<GatewayOpcodes>; +declare function getInitialSendRateLimitState(): SendRateLimitState; + +/** + * Represents a range of shard ids + */ +interface ShardRange { + end: number; + start: number; +} +/** + * Session information for a given shard, used to resume a session + */ +interface SessionInfo { + /** + * URL to use when resuming + */ + resumeURL: string; + /** + * The sequence number of the last message sent by the shard + */ + sequence: number; + /** + * Session id for this shard + */ + sessionId: string; + /** + * The total number of shards at the time of this shard identifying + */ + shardCount: number; + /** + * The id of the shard + */ + shardId: number; +} +/** + * Required options for the WebSocketManager + */ +interface RequiredWebSocketManagerOptions { + /** + * The intents to request + */ + intents: GatewayIntentBits | 0; + /** + * The REST instance to use for fetching gateway information + */ + rest: REST; + /** + * The token to use for identifying with the gateway + */ + token: string; +} +/** + * Optional additional configuration for the WebSocketManager + */ +interface OptionalWebSocketManagerOptions { + /** + * Builds an identify throttler to use for this manager's shards + */ + buildIdentifyThrottler(manager: WebSocketManager): Awaitable<IIdentifyThrottler>; + /** + * Builds the strategy to use for sharding + * + * @example + * ```ts + * const manager = new WebSocketManager({ + * token: process.env.DISCORD_TOKEN, + * intents: 0, // for no intents + * rest, + * buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 }), + * }); + * ``` + */ + buildStrategy(manager: WebSocketManager): IShardingStrategy; + /** + * The compression method to use + * + * @defaultValue `null` (no compression) + */ + compression: CompressionMethod | null; + /** + * The encoding to use + * + * @defaultValue `'json'` + */ + encoding: Encoding; + /** + * How long to wait for a shard to connect before giving up + */ + handshakeTimeout: number | null; + /** + * How long to wait for a shard's HELLO packet before giving up + */ + helloTimeout: number | null; + /** + * Properties to send to the gateway when identifying + */ + identifyProperties: GatewayIdentifyProperties; + /** + * Initial presence data to send to the gateway when identifying + */ + initialPresence: GatewayPresenceUpdateData | null; + /** + * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list + */ + largeThreshold: number | null; + /** + * How long to wait for a shard's READY packet before giving up + */ + readyTimeout: number | null; + /** + * Function used to retrieve session information (and attempt to resume) for a given shard + * + * @example + * ```ts + * const manager = new WebSocketManager({ + * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> { + * // Fetch this info from redis or similar + * return { sessionId: string, sequence: number }; + * // Return null if no information is found + * }, + * }); + * ``` + */ + retrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>; + /** + * The total number of shards across all WebsocketManagers you intend to instantiate. + * Use `null` to use Discord's recommended shard count + */ + shardCount: number | null; + /** + * The ids of the shards this WebSocketManager should manage. + * Use `null` to simply spawn 0 through `shardCount - 1` + * + * @example + * ```ts + * const manager = new WebSocketManager({ + * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else + * }); + * ``` + * @example + * ```ts + * const manager = new WebSocketManager({ + * shardIds: { + * start: 3, + * end: 6, + * }, // spawns shards 3, 4, 5, and 6 + * }); + * ``` + */ + shardIds: number[] | ShardRange | null; + /** + * Function used to store session information for a given shard + */ + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>; + /** + * The gateway version to use + * + * @defaultValue `'10'` + */ + version: string; +} +type WebSocketManagerOptions = OptionalWebSocketManagerOptions & RequiredWebSocketManagerOptions; +type ManagerShardEventsMap = { + [K in keyof WebSocketShardEventsMap]: [ + WebSocketShardEventsMap[K] extends [] ? { + shardId: number; + } : WebSocketShardEventsMap[K][0] & { + shardId: number; + } + ]; +}; +declare class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> { + /** + * The options being used by this manager + */ + readonly options: WebSocketManagerOptions; + /** + * Internal cache for a GET /gateway/bot result + */ + private gatewayInformation; + /** + * Internal cache for the shard ids + */ + private shardIds; + /** + * Strategy used to manage shards + * + * @defaultValue `SimpleShardingStrategy` + */ + private readonly strategy; + constructor(options: Partial<OptionalWebSocketManagerOptions> & RequiredWebSocketManagerOptions); + /** + * Fetches the gateway information from Discord - or returns it from cache if available + * + * @param force - Whether to ignore the cache and force a fresh fetch + */ + fetchGatewayInformation(force?: boolean): Promise<APIGatewayBotInfo>; + /** + * Updates your total shard count on-the-fly, spawning shards as needed + * + * @param shardCount - The new shard count to use + */ + updateShardCount(shardCount: number | null): Promise<this>; + /** + * Yields the total number of shards across for your bot, accounting for Discord recommendations + */ + getShardCount(): Promise<number>; + /** + * Yields the ids of the shards this manager should manage + */ + getShardIds(force?: boolean): Promise<number[]>; + connect(): Promise<void>; + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Awaitable<void>; + send(shardId: number, payload: GatewaySendPayload): Awaitable<void>; + fetchStatus(): Awaitable<_discordjs_collection.Collection<number, WebSocketShardStatus>>; +} + +interface FetchingStrategyOptions extends Omit<WebSocketManagerOptions, 'buildIdentifyThrottler' | 'buildStrategy' | 'rest' | 'retrieveSessionInfo' | 'shardCount' | 'shardIds' | 'updateSessionInfo'> { + readonly gatewayInformation: APIGatewayBotInfo; + readonly shardCount: number; +} +/** + * Strategies responsible solely for making manager information accessible + */ +interface IContextFetchingStrategy { + readonly options: FetchingStrategyOptions; + retrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>; + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>; + /** + * Resolves once the given shard should be allowed to identify + * This should correctly handle the signal and reject with an abort error if the operation is aborted. + * Other errors will cause the shard to reconnect. + */ + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} +declare function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions>; + +declare class SimpleContextFetchingStrategy implements IContextFetchingStrategy { + private readonly manager; + readonly options: FetchingStrategyOptions; + private static throttlerCache; + private static ensureThrottler; + constructor(manager: WebSocketManager, options: FetchingStrategyOptions); + retrieveSessionInfo(shardId: number): Promise<SessionInfo | null>; + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): _discordjs_util.Awaitable<void>; + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +declare class WorkerContextFetchingStrategy implements IContextFetchingStrategy { + readonly options: FetchingStrategyOptions; + private readonly sessionPromises; + private readonly waitForIdentifyPromises; + constructor(options: FetchingStrategyOptions); + retrieveSessionInfo(shardId: number): Promise<SessionInfo | null>; + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): void; + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +interface WorkerData extends FetchingStrategyOptions { + shardIds: number[]; +} +declare enum WorkerSendPayloadOp { + Connect = 0, + Destroy = 1, + Send = 2, + SessionInfoResponse = 3, + ShardIdentifyResponse = 4, + FetchStatus = 5 +} +type WorkerSendPayload = { + nonce: number; + ok: boolean; + op: WorkerSendPayloadOp.ShardIdentifyResponse; +} | { + nonce: number; + op: WorkerSendPayloadOp.FetchStatus; + shardId: number; +} | { + nonce: number; + op: WorkerSendPayloadOp.SessionInfoResponse; + session: SessionInfo | null; +} | { + op: WorkerSendPayloadOp.Connect; + shardId: number; +} | { + op: WorkerSendPayloadOp.Destroy; + options?: WebSocketShardDestroyOptions; + shardId: number; +} | { + op: WorkerSendPayloadOp.Send; + payload: GatewaySendPayload; + shardId: number; +}; +declare enum WorkerReceivePayloadOp { + Connected = 0, + Destroyed = 1, + Event = 2, + RetrieveSessionInfo = 3, + UpdateSessionInfo = 4, + WaitForIdentify = 5, + FetchStatusResponse = 6, + WorkerReady = 7, + CancelIdentify = 8 +} +type WorkerReceivePayload = { + data: any; + event: WebSocketShardEvents; + op: WorkerReceivePayloadOp.Event; + shardId: number; +} | { + nonce: number; + op: WorkerReceivePayloadOp.CancelIdentify; +} | { + nonce: number; + op: WorkerReceivePayloadOp.FetchStatusResponse; + status: WebSocketShardStatus; +} | { + nonce: number; + op: WorkerReceivePayloadOp.RetrieveSessionInfo; + shardId: number; +} | { + nonce: number; + op: WorkerReceivePayloadOp.WaitForIdentify; + shardId: number; +} | { + op: WorkerReceivePayloadOp.Connected; + shardId: number; +} | { + op: WorkerReceivePayloadOp.Destroyed; + shardId: number; +} | { + op: WorkerReceivePayloadOp.UpdateSessionInfo; + session: SessionInfo | null; + shardId: number; +} | { + op: WorkerReceivePayloadOp.WorkerReady; +}; +/** + * Options for a {@link WorkerShardingStrategy} + */ +interface WorkerShardingStrategyOptions { + /** + * Dictates how many shards should be spawned per worker thread. + */ + shardsPerWorker: number | 'all'; + /** + * Path to the worker file to use. The worker requires quite a bit of setup, it is recommended you leverage the {@link WorkerBootstrapper} class. + */ + workerPath?: string; +} +/** + * Strategy used to spawn threads in worker_threads + */ +declare class WorkerShardingStrategy implements IShardingStrategy { + #private; + private readonly manager; + private readonly options; + private readonly connectPromises; + private readonly destroyPromises; + private readonly fetchStatusPromises; + private readonly waitForIdentifyControllers; + private throttler?; + constructor(manager: WebSocketManager, options: WorkerShardingStrategyOptions); + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + spawn(shardIds: number[]): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.connect} + */ + connect(): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.send} + */ + send(shardId: number, data: GatewaySendPayload): void; + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + fetchStatus(): Promise<Collection<number, WebSocketShardStatus>>; + private setupWorker; + private resolveWorkerPath; + private waitForWorkerReady; + private onMessage; + private ensureThrottler; +} + +/** + * Options for bootstrapping the worker + */ +interface BootstrapOptions { + /** + * Shard events to just arbitrarily forward to the parent thread for the manager to emit + * Note: By default, this will include ALL events + * you most likely want to handle dispatch within the worker itself + */ + forwardEvents?: WebSocketShardEvents[]; + /** + * Function to call when a shard is created for additional setup + */ + shardCallback?(shard: WebSocketShard): Awaitable<void>; +} +/** + * Utility class for bootstrapping a worker thread to be used for sharding + */ +declare class WorkerBootstrapper { + /** + * The data passed to the worker thread + */ + protected readonly data: WorkerData; + /** + * The shards that are managed by this worker + */ + protected readonly shards: Collection<number, WebSocketShard>; + constructor(); + /** + * Helper method to initiate a shard's connection process + */ + protected connect(shardId: number): Promise<void>; + /** + * Helper method to destroy a shard + */ + protected destroy(shardId: number, options?: WebSocketShardDestroyOptions): Promise<void>; + /** + * Helper method to attach event listeners to the parentPort + */ + protected setupThreadEvents(): void; + /** + * Bootstraps the worker thread with the provided options + */ + bootstrap(options?: Readonly<BootstrapOptions>): Promise<void>; +} + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/ws/#readme | @discordjs/ws} version + * that you are currently using. + */ +declare const version: string; + +export { BootstrapOptions, CloseCodes, CompressionMethod, DefaultDeviceProperty, DefaultWebSocketManagerOptions, Encoding, FetchingStrategyOptions, IContextFetchingStrategy, IIdentifyThrottler, IShardingStrategy, IdentifyState, ImportantGatewayOpcodes, ManagerShardEventsMap, OptionalWebSocketManagerOptions, RequiredWebSocketManagerOptions, SendRateLimitState, SessionInfo, ShardRange, SimpleContextFetchingStrategy, SimpleIdentifyThrottler, SimpleShardingStrategy, WebSocketManager, WebSocketManagerOptions, WebSocketShard, WebSocketShardDestroyOptions, WebSocketShardDestroyRecovery, WebSocketShardEvents, WebSocketShardEventsMap, WebSocketShardStatus, WorkerBootstrapper, WorkerContextFetchingStrategy, WorkerData, WorkerReceivePayload, WorkerReceivePayloadOp, WorkerSendPayload, WorkerSendPayloadOp, WorkerShardingStrategy, WorkerShardingStrategyOptions, getInitialSendRateLimitState, managerToFetchingStrategyOptions, version }; diff --git a/node_modules/@discordjs/ws/dist/index.d.ts b/node_modules/@discordjs/ws/dist/index.d.ts new file mode 100644 index 0000000..cf7bb7c --- /dev/null +++ b/node_modules/@discordjs/ws/dist/index.d.ts @@ -0,0 +1,669 @@ +import * as _discordjs_util from '@discordjs/util'; +import { Awaitable } from '@discordjs/util'; +import { GatewayDispatchPayload, GatewayReadyDispatchData, GatewaySendPayload, GatewayOpcodes, GatewayIntentBits, GatewayIdentifyProperties, GatewayPresenceUpdateData, APIGatewayBotInfo } from 'discord-api-types/v10'; +import * as _discordjs_collection from '@discordjs/collection'; +import { Collection } from '@discordjs/collection'; +import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; +import { REST } from '@discordjs/rest'; +import { AsyncQueue } from '@sapphire/async-queue'; + +declare enum WebSocketShardEvents { + Closed = "closed", + Debug = "debug", + Dispatch = "dispatch", + Error = "error", + HeartbeatComplete = "heartbeat", + Hello = "hello", + Ready = "ready", + Resumed = "resumed" +} +declare enum WebSocketShardStatus { + Idle = 0, + Connecting = 1, + Resuming = 2, + Ready = 3 +} +declare enum WebSocketShardDestroyRecovery { + Reconnect = 0, + Resume = 1 +} +type WebSocketShardEventsMap = { + [WebSocketShardEvents.Closed]: [{ + code: number; + }]; + [WebSocketShardEvents.Debug]: [payload: { + message: string; + }]; + [WebSocketShardEvents.Dispatch]: [payload: { + data: GatewayDispatchPayload; + }]; + [WebSocketShardEvents.Error]: [payload: { + error: Error; + }]; + [WebSocketShardEvents.Hello]: []; + [WebSocketShardEvents.Ready]: [payload: { + data: GatewayReadyDispatchData; + }]; + [WebSocketShardEvents.Resumed]: []; + [WebSocketShardEvents.HeartbeatComplete]: [payload: { + ackAt: number; + heartbeatAt: number; + latency: number; + }]; +}; +interface WebSocketShardDestroyOptions { + code?: number; + reason?: string; + recover?: WebSocketShardDestroyRecovery; +} +declare enum CloseCodes { + Normal = 1000, + Resuming = 4200 +} +interface SendRateLimitState { + remaining: number; + resetAt: number; +} +declare class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> { + #private; + private connection; + private useIdentifyCompress; + private inflate; + private readonly textDecoder; + private replayedEvents; + private isAck; + private sendRateLimitState; + private initialHeartbeatTimeoutController; + private heartbeatInterval; + private lastHeartbeatAt; + private initialConnectResolved; + private failedToConnectDueToNetworkError; + private readonly sendQueue; + private readonly timeoutAbortControllers; + private readonly strategy; + readonly id: number; + get status(): WebSocketShardStatus; + constructor(strategy: IContextFetchingStrategy, id: number); + connect(): Promise<void>; + private internalConnect; + destroy(options?: WebSocketShardDestroyOptions): Promise<void>; + private waitForEvent; + send(payload: GatewaySendPayload): Promise<void>; + private identify; + private resume; + private heartbeat; + private unpackMessage; + private onMessage; + private onError; + private onClose; + private debug; +} + +/** + * Strategies responsible for spawning, initializing connections, destroying shards, and relaying events + */ +interface IShardingStrategy { + /** + * Initializes all the shards + */ + connect(): Awaitable<void>; + /** + * Destroys all the shards + */ + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Awaitable<void>; + /** + * Fetches the status of all the shards + */ + fetchStatus(): Awaitable<Collection<number, WebSocketShardStatus>>; + /** + * Sends a payload to a shard + */ + send(shardId: number, payload: GatewaySendPayload): Awaitable<void>; + /** + * Spawns all the shards + */ + spawn(shardIds: number[]): Awaitable<void>; +} + +/** + * IdentifyThrottlers are responsible for dictating when a shard is allowed to identify. + * + * @see {@link https://discord.com/developers/docs/topics/gateway#sharding-max-concurrency} + */ +interface IIdentifyThrottler { + /** + * Resolves once the given shard should be allowed to identify, or rejects if the operation was aborted. + */ + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +/** + * Simple strategy that just spawns shards in the current process + */ +declare class SimpleShardingStrategy implements IShardingStrategy { + private readonly manager; + private readonly shards; + constructor(manager: WebSocketManager); + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + spawn(shardIds: number[]): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.connect} + */ + connect(): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.send} + */ + send(shardId: number, payload: GatewaySendPayload): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + fetchStatus(): Promise<Collection<number, WebSocketShardStatus>>; +} + +/** + * The state of a rate limit key's identify queue. + */ +interface IdentifyState { + queue: AsyncQueue; + resetsAt: number; +} +/** + * Local, in-memory identify throttler. + */ +declare class SimpleIdentifyThrottler implements IIdentifyThrottler { + private readonly maxConcurrency; + private readonly states; + constructor(maxConcurrency: number); + /** + * {@inheritDoc IIdentifyThrottler.waitForIdentify} + */ + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +/** + * Valid encoding types + */ +declare enum Encoding { + JSON = "json" +} +/** + * Valid compression methods + */ +declare enum CompressionMethod { + ZlibStream = "zlib-stream" +} +declare const DefaultDeviceProperty: `@discordjs/ws ${string}`; +/** + * Default options used by the manager + */ +declare const DefaultWebSocketManagerOptions: { + readonly buildIdentifyThrottler: (manager: WebSocketManager) => Promise<SimpleIdentifyThrottler>; + readonly buildStrategy: (manager: WebSocketManager) => SimpleShardingStrategy; + readonly shardCount: null; + readonly shardIds: null; + readonly largeThreshold: null; + readonly initialPresence: null; + readonly identifyProperties: { + readonly browser: `@discordjs/ws ${string}`; + readonly device: `@discordjs/ws ${string}`; + readonly os: NodeJS.Platform; + }; + readonly version: "10"; + readonly encoding: Encoding; + readonly compression: null; + readonly retrieveSessionInfo: (shardId: number) => SessionInfo | null; + readonly updateSessionInfo: (shardId: number, info: SessionInfo | null) => void; + readonly handshakeTimeout: 30000; + readonly helloTimeout: 60000; + readonly readyTimeout: 15000; +}; +declare const ImportantGatewayOpcodes: Set<GatewayOpcodes>; +declare function getInitialSendRateLimitState(): SendRateLimitState; + +/** + * Represents a range of shard ids + */ +interface ShardRange { + end: number; + start: number; +} +/** + * Session information for a given shard, used to resume a session + */ +interface SessionInfo { + /** + * URL to use when resuming + */ + resumeURL: string; + /** + * The sequence number of the last message sent by the shard + */ + sequence: number; + /** + * Session id for this shard + */ + sessionId: string; + /** + * The total number of shards at the time of this shard identifying + */ + shardCount: number; + /** + * The id of the shard + */ + shardId: number; +} +/** + * Required options for the WebSocketManager + */ +interface RequiredWebSocketManagerOptions { + /** + * The intents to request + */ + intents: GatewayIntentBits | 0; + /** + * The REST instance to use for fetching gateway information + */ + rest: REST; + /** + * The token to use for identifying with the gateway + */ + token: string; +} +/** + * Optional additional configuration for the WebSocketManager + */ +interface OptionalWebSocketManagerOptions { + /** + * Builds an identify throttler to use for this manager's shards + */ + buildIdentifyThrottler(manager: WebSocketManager): Awaitable<IIdentifyThrottler>; + /** + * Builds the strategy to use for sharding + * + * @example + * ```ts + * const manager = new WebSocketManager({ + * token: process.env.DISCORD_TOKEN, + * intents: 0, // for no intents + * rest, + * buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 }), + * }); + * ``` + */ + buildStrategy(manager: WebSocketManager): IShardingStrategy; + /** + * The compression method to use + * + * @defaultValue `null` (no compression) + */ + compression: CompressionMethod | null; + /** + * The encoding to use + * + * @defaultValue `'json'` + */ + encoding: Encoding; + /** + * How long to wait for a shard to connect before giving up + */ + handshakeTimeout: number | null; + /** + * How long to wait for a shard's HELLO packet before giving up + */ + helloTimeout: number | null; + /** + * Properties to send to the gateway when identifying + */ + identifyProperties: GatewayIdentifyProperties; + /** + * Initial presence data to send to the gateway when identifying + */ + initialPresence: GatewayPresenceUpdateData | null; + /** + * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list + */ + largeThreshold: number | null; + /** + * How long to wait for a shard's READY packet before giving up + */ + readyTimeout: number | null; + /** + * Function used to retrieve session information (and attempt to resume) for a given shard + * + * @example + * ```ts + * const manager = new WebSocketManager({ + * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> { + * // Fetch this info from redis or similar + * return { sessionId: string, sequence: number }; + * // Return null if no information is found + * }, + * }); + * ``` + */ + retrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>; + /** + * The total number of shards across all WebsocketManagers you intend to instantiate. + * Use `null` to use Discord's recommended shard count + */ + shardCount: number | null; + /** + * The ids of the shards this WebSocketManager should manage. + * Use `null` to simply spawn 0 through `shardCount - 1` + * + * @example + * ```ts + * const manager = new WebSocketManager({ + * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else + * }); + * ``` + * @example + * ```ts + * const manager = new WebSocketManager({ + * shardIds: { + * start: 3, + * end: 6, + * }, // spawns shards 3, 4, 5, and 6 + * }); + * ``` + */ + shardIds: number[] | ShardRange | null; + /** + * Function used to store session information for a given shard + */ + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>; + /** + * The gateway version to use + * + * @defaultValue `'10'` + */ + version: string; +} +type WebSocketManagerOptions = OptionalWebSocketManagerOptions & RequiredWebSocketManagerOptions; +type ManagerShardEventsMap = { + [K in keyof WebSocketShardEventsMap]: [ + WebSocketShardEventsMap[K] extends [] ? { + shardId: number; + } : WebSocketShardEventsMap[K][0] & { + shardId: number; + } + ]; +}; +declare class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> { + /** + * The options being used by this manager + */ + readonly options: WebSocketManagerOptions; + /** + * Internal cache for a GET /gateway/bot result + */ + private gatewayInformation; + /** + * Internal cache for the shard ids + */ + private shardIds; + /** + * Strategy used to manage shards + * + * @defaultValue `SimpleShardingStrategy` + */ + private readonly strategy; + constructor(options: Partial<OptionalWebSocketManagerOptions> & RequiredWebSocketManagerOptions); + /** + * Fetches the gateway information from Discord - or returns it from cache if available + * + * @param force - Whether to ignore the cache and force a fresh fetch + */ + fetchGatewayInformation(force?: boolean): Promise<APIGatewayBotInfo>; + /** + * Updates your total shard count on-the-fly, spawning shards as needed + * + * @param shardCount - The new shard count to use + */ + updateShardCount(shardCount: number | null): Promise<this>; + /** + * Yields the total number of shards across for your bot, accounting for Discord recommendations + */ + getShardCount(): Promise<number>; + /** + * Yields the ids of the shards this manager should manage + */ + getShardIds(force?: boolean): Promise<number[]>; + connect(): Promise<void>; + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Awaitable<void>; + send(shardId: number, payload: GatewaySendPayload): Awaitable<void>; + fetchStatus(): Awaitable<_discordjs_collection.Collection<number, WebSocketShardStatus>>; +} + +interface FetchingStrategyOptions extends Omit<WebSocketManagerOptions, 'buildIdentifyThrottler' | 'buildStrategy' | 'rest' | 'retrieveSessionInfo' | 'shardCount' | 'shardIds' | 'updateSessionInfo'> { + readonly gatewayInformation: APIGatewayBotInfo; + readonly shardCount: number; +} +/** + * Strategies responsible solely for making manager information accessible + */ +interface IContextFetchingStrategy { + readonly options: FetchingStrategyOptions; + retrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>; + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>; + /** + * Resolves once the given shard should be allowed to identify + * This should correctly handle the signal and reject with an abort error if the operation is aborted. + * Other errors will cause the shard to reconnect. + */ + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} +declare function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions>; + +declare class SimpleContextFetchingStrategy implements IContextFetchingStrategy { + private readonly manager; + readonly options: FetchingStrategyOptions; + private static throttlerCache; + private static ensureThrottler; + constructor(manager: WebSocketManager, options: FetchingStrategyOptions); + retrieveSessionInfo(shardId: number): Promise<SessionInfo | null>; + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): _discordjs_util.Awaitable<void>; + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +declare class WorkerContextFetchingStrategy implements IContextFetchingStrategy { + readonly options: FetchingStrategyOptions; + private readonly sessionPromises; + private readonly waitForIdentifyPromises; + constructor(options: FetchingStrategyOptions); + retrieveSessionInfo(shardId: number): Promise<SessionInfo | null>; + updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): void; + waitForIdentify(shardId: number, signal: AbortSignal): Promise<void>; +} + +interface WorkerData extends FetchingStrategyOptions { + shardIds: number[]; +} +declare enum WorkerSendPayloadOp { + Connect = 0, + Destroy = 1, + Send = 2, + SessionInfoResponse = 3, + ShardIdentifyResponse = 4, + FetchStatus = 5 +} +type WorkerSendPayload = { + nonce: number; + ok: boolean; + op: WorkerSendPayloadOp.ShardIdentifyResponse; +} | { + nonce: number; + op: WorkerSendPayloadOp.FetchStatus; + shardId: number; +} | { + nonce: number; + op: WorkerSendPayloadOp.SessionInfoResponse; + session: SessionInfo | null; +} | { + op: WorkerSendPayloadOp.Connect; + shardId: number; +} | { + op: WorkerSendPayloadOp.Destroy; + options?: WebSocketShardDestroyOptions; + shardId: number; +} | { + op: WorkerSendPayloadOp.Send; + payload: GatewaySendPayload; + shardId: number; +}; +declare enum WorkerReceivePayloadOp { + Connected = 0, + Destroyed = 1, + Event = 2, + RetrieveSessionInfo = 3, + UpdateSessionInfo = 4, + WaitForIdentify = 5, + FetchStatusResponse = 6, + WorkerReady = 7, + CancelIdentify = 8 +} +type WorkerReceivePayload = { + data: any; + event: WebSocketShardEvents; + op: WorkerReceivePayloadOp.Event; + shardId: number; +} | { + nonce: number; + op: WorkerReceivePayloadOp.CancelIdentify; +} | { + nonce: number; + op: WorkerReceivePayloadOp.FetchStatusResponse; + status: WebSocketShardStatus; +} | { + nonce: number; + op: WorkerReceivePayloadOp.RetrieveSessionInfo; + shardId: number; +} | { + nonce: number; + op: WorkerReceivePayloadOp.WaitForIdentify; + shardId: number; +} | { + op: WorkerReceivePayloadOp.Connected; + shardId: number; +} | { + op: WorkerReceivePayloadOp.Destroyed; + shardId: number; +} | { + op: WorkerReceivePayloadOp.UpdateSessionInfo; + session: SessionInfo | null; + shardId: number; +} | { + op: WorkerReceivePayloadOp.WorkerReady; +}; +/** + * Options for a {@link WorkerShardingStrategy} + */ +interface WorkerShardingStrategyOptions { + /** + * Dictates how many shards should be spawned per worker thread. + */ + shardsPerWorker: number | 'all'; + /** + * Path to the worker file to use. The worker requires quite a bit of setup, it is recommended you leverage the {@link WorkerBootstrapper} class. + */ + workerPath?: string; +} +/** + * Strategy used to spawn threads in worker_threads + */ +declare class WorkerShardingStrategy implements IShardingStrategy { + #private; + private readonly manager; + private readonly options; + private readonly connectPromises; + private readonly destroyPromises; + private readonly fetchStatusPromises; + private readonly waitForIdentifyControllers; + private throttler?; + constructor(manager: WebSocketManager, options: WorkerShardingStrategyOptions); + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + spawn(shardIds: number[]): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.connect} + */ + connect(): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>): Promise<void>; + /** + * {@inheritDoc IShardingStrategy.send} + */ + send(shardId: number, data: GatewaySendPayload): void; + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + fetchStatus(): Promise<Collection<number, WebSocketShardStatus>>; + private setupWorker; + private resolveWorkerPath; + private waitForWorkerReady; + private onMessage; + private ensureThrottler; +} + +/** + * Options for bootstrapping the worker + */ +interface BootstrapOptions { + /** + * Shard events to just arbitrarily forward to the parent thread for the manager to emit + * Note: By default, this will include ALL events + * you most likely want to handle dispatch within the worker itself + */ + forwardEvents?: WebSocketShardEvents[]; + /** + * Function to call when a shard is created for additional setup + */ + shardCallback?(shard: WebSocketShard): Awaitable<void>; +} +/** + * Utility class for bootstrapping a worker thread to be used for sharding + */ +declare class WorkerBootstrapper { + /** + * The data passed to the worker thread + */ + protected readonly data: WorkerData; + /** + * The shards that are managed by this worker + */ + protected readonly shards: Collection<number, WebSocketShard>; + constructor(); + /** + * Helper method to initiate a shard's connection process + */ + protected connect(shardId: number): Promise<void>; + /** + * Helper method to destroy a shard + */ + protected destroy(shardId: number, options?: WebSocketShardDestroyOptions): Promise<void>; + /** + * Helper method to attach event listeners to the parentPort + */ + protected setupThreadEvents(): void; + /** + * Bootstraps the worker thread with the provided options + */ + bootstrap(options?: Readonly<BootstrapOptions>): Promise<void>; +} + +/** + * The {@link https://github.com/discordjs/discord.js/blob/main/packages/ws/#readme | @discordjs/ws} version + * that you are currently using. + */ +declare const version: string; + +export { BootstrapOptions, CloseCodes, CompressionMethod, DefaultDeviceProperty, DefaultWebSocketManagerOptions, Encoding, FetchingStrategyOptions, IContextFetchingStrategy, IIdentifyThrottler, IShardingStrategy, IdentifyState, ImportantGatewayOpcodes, ManagerShardEventsMap, OptionalWebSocketManagerOptions, RequiredWebSocketManagerOptions, SendRateLimitState, SessionInfo, ShardRange, SimpleContextFetchingStrategy, SimpleIdentifyThrottler, SimpleShardingStrategy, WebSocketManager, WebSocketManagerOptions, WebSocketShard, WebSocketShardDestroyOptions, WebSocketShardDestroyRecovery, WebSocketShardEvents, WebSocketShardEventsMap, WebSocketShardStatus, WorkerBootstrapper, WorkerContextFetchingStrategy, WorkerData, WorkerReceivePayload, WorkerReceivePayloadOp, WorkerSendPayload, WorkerSendPayloadOp, WorkerShardingStrategy, WorkerShardingStrategyOptions, getInitialSendRateLimitState, managerToFetchingStrategyOptions, version }; diff --git a/node_modules/@discordjs/ws/dist/index.js b/node_modules/@discordjs/ws/dist/index.js new file mode 100644 index 0000000..9931550 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/index.js @@ -0,0 +1,1482 @@ +"use strict"; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.ts +var src_exports = {}; +__export(src_exports, { + CloseCodes: () => CloseCodes, + CompressionMethod: () => CompressionMethod, + DefaultDeviceProperty: () => DefaultDeviceProperty, + DefaultWebSocketManagerOptions: () => DefaultWebSocketManagerOptions, + Encoding: () => Encoding, + ImportantGatewayOpcodes: () => ImportantGatewayOpcodes, + SimpleContextFetchingStrategy: () => SimpleContextFetchingStrategy, + SimpleIdentifyThrottler: () => SimpleIdentifyThrottler, + SimpleShardingStrategy: () => SimpleShardingStrategy, + WebSocketManager: () => WebSocketManager, + WebSocketShard: () => WebSocketShard, + WebSocketShardDestroyRecovery: () => WebSocketShardDestroyRecovery, + WebSocketShardEvents: () => WebSocketShardEvents, + WebSocketShardStatus: () => WebSocketShardStatus, + WorkerBootstrapper: () => WorkerBootstrapper, + WorkerContextFetchingStrategy: () => WorkerContextFetchingStrategy, + WorkerReceivePayloadOp: () => WorkerReceivePayloadOp, + WorkerSendPayloadOp: () => WorkerSendPayloadOp, + WorkerShardingStrategy: () => WorkerShardingStrategy, + getInitialSendRateLimitState: () => getInitialSendRateLimitState, + managerToFetchingStrategyOptions: () => managerToFetchingStrategyOptions, + version: () => version +}); +module.exports = __toCommonJS(src_exports); + +// src/strategies/context/IContextFetchingStrategy.ts +async function managerToFetchingStrategyOptions(manager) { + const { + buildIdentifyThrottler, + buildStrategy, + retrieveSessionInfo, + updateSessionInfo, + shardCount, + shardIds, + rest, + ...managerOptions + } = manager.options; + return { + ...managerOptions, + gatewayInformation: await manager.fetchGatewayInformation(), + shardCount: await manager.getShardCount() + }; +} +__name(managerToFetchingStrategyOptions, "managerToFetchingStrategyOptions"); + +// src/strategies/context/SimpleContextFetchingStrategy.ts +var SimpleContextFetchingStrategy = class _SimpleContextFetchingStrategy { + constructor(manager, options) { + this.manager = manager; + this.options = options; + } + static { + __name(this, "SimpleContextFetchingStrategy"); + } + // This strategy assumes every shard is running under the same process - therefore we need a single + // IdentifyThrottler per manager. + static throttlerCache = /* @__PURE__ */ new WeakMap(); + static async ensureThrottler(manager) { + const throttler = _SimpleContextFetchingStrategy.throttlerCache.get(manager); + if (throttler) { + return throttler; + } + const newThrottler = await manager.options.buildIdentifyThrottler(manager); + _SimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler); + return newThrottler; + } + async retrieveSessionInfo(shardId) { + return this.manager.options.retrieveSessionInfo(shardId); + } + updateSessionInfo(shardId, sessionInfo) { + return this.manager.options.updateSessionInfo(shardId, sessionInfo); + } + async waitForIdentify(shardId, signal) { + const throttler = await _SimpleContextFetchingStrategy.ensureThrottler(this.manager); + await throttler.waitForIdentify(shardId, signal); + } +}; + +// src/strategies/context/WorkerContextFetchingStrategy.ts +var import_node_worker_threads2 = require("worker_threads"); +var import_collection2 = require("@discordjs/collection"); + +// src/strategies/sharding/WorkerShardingStrategy.ts +var import_node_events = require("events"); +var import_node_path = require("path"); +var import_node_worker_threads = require("worker_threads"); +var import_collection = require("@discordjs/collection"); +var WorkerSendPayloadOp = /* @__PURE__ */ ((WorkerSendPayloadOp2) => { + WorkerSendPayloadOp2[WorkerSendPayloadOp2["Connect"] = 0] = "Connect"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["Destroy"] = 1] = "Destroy"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["Send"] = 2] = "Send"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["SessionInfoResponse"] = 3] = "SessionInfoResponse"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["ShardIdentifyResponse"] = 4] = "ShardIdentifyResponse"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["FetchStatus"] = 5] = "FetchStatus"; + return WorkerSendPayloadOp2; +})(WorkerSendPayloadOp || {}); +var WorkerReceivePayloadOp = /* @__PURE__ */ ((WorkerReceivePayloadOp2) => { + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["Connected"] = 0] = "Connected"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["Destroyed"] = 1] = "Destroyed"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["Event"] = 2] = "Event"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["RetrieveSessionInfo"] = 3] = "RetrieveSessionInfo"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["UpdateSessionInfo"] = 4] = "UpdateSessionInfo"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["WaitForIdentify"] = 5] = "WaitForIdentify"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["FetchStatusResponse"] = 6] = "FetchStatusResponse"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["WorkerReady"] = 7] = "WorkerReady"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["CancelIdentify"] = 8] = "CancelIdentify"; + return WorkerReceivePayloadOp2; +})(WorkerReceivePayloadOp || {}); +var WorkerShardingStrategy = class { + static { + __name(this, "WorkerShardingStrategy"); + } + manager; + options; + #workers = []; + #workerByShardId = new import_collection.Collection(); + connectPromises = new import_collection.Collection(); + destroyPromises = new import_collection.Collection(); + fetchStatusPromises = new import_collection.Collection(); + waitForIdentifyControllers = new import_collection.Collection(); + throttler; + constructor(manager, options) { + this.manager = manager; + this.options = options; + } + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + async spawn(shardIds) { + const shardsPerWorker = this.options.shardsPerWorker === "all" ? shardIds.length : this.options.shardsPerWorker; + const strategyOptions = await managerToFetchingStrategyOptions(this.manager); + const loops = Math.ceil(shardIds.length / shardsPerWorker); + const promises = []; + for (let idx = 0; idx < loops; idx++) { + const slice = shardIds.slice(idx * shardsPerWorker, (idx + 1) * shardsPerWorker); + const workerData2 = { + ...strategyOptions, + shardIds: slice + }; + promises.push(this.setupWorker(workerData2)); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.connect} + */ + async connect() { + const promises = []; + for (const [shardId, worker] of this.#workerByShardId.entries()) { + const payload = { + op: 0 /* Connect */, + shardId + }; + const promise = new Promise((resolve2) => this.connectPromises.set(shardId, resolve2)); + worker.postMessage(payload); + promises.push(promise); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + async destroy(options = {}) { + const promises = []; + for (const [shardId, worker] of this.#workerByShardId.entries()) { + const payload = { + op: 1 /* Destroy */, + shardId, + options + }; + promises.push( + // eslint-disable-next-line no-promise-executor-return, promise/prefer-await-to-then + new Promise((resolve2) => this.destroyPromises.set(shardId, resolve2)).then(async () => worker.terminate()) + ); + worker.postMessage(payload); + } + this.#workers = []; + this.#workerByShardId.clear(); + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.send} + */ + send(shardId, data) { + const worker = this.#workerByShardId.get(shardId); + if (!worker) { + throw new Error(`No worker found for shard ${shardId}`); + } + const payload = { + op: 2 /* Send */, + shardId, + payload: data + }; + worker.postMessage(payload); + } + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + async fetchStatus() { + const statuses = new import_collection.Collection(); + for (const [shardId, worker] of this.#workerByShardId.entries()) { + const nonce = Math.random(); + const payload = { + op: 5 /* FetchStatus */, + shardId, + nonce + }; + const promise = new Promise((resolve2) => this.fetchStatusPromises.set(nonce, resolve2)); + worker.postMessage(payload); + const status = await promise; + statuses.set(shardId, status); + } + return statuses; + } + async setupWorker(workerData2) { + const worker = new import_node_worker_threads.Worker(this.resolveWorkerPath(), { workerData: workerData2 }); + await (0, import_node_events.once)(worker, "online"); + await this.waitForWorkerReady(worker); + worker.on("error", (err) => { + throw err; + }).on("messageerror", (err) => { + throw err; + }).on("message", async (payload) => this.onMessage(worker, payload)); + this.#workers.push(worker); + for (const shardId of workerData2.shardIds) { + this.#workerByShardId.set(shardId, worker); + } + } + resolveWorkerPath() { + const path = this.options.workerPath; + if (!path) { + return (0, import_node_path.join)(__dirname, "defaultWorker.js"); + } + if ((0, import_node_path.isAbsolute)(path)) { + return path; + } + if (/^\.\.?[/\\]/.test(path)) { + return (0, import_node_path.resolve)(path); + } + try { + return require.resolve(path); + } catch { + return (0, import_node_path.resolve)(path); + } + } + async waitForWorkerReady(worker) { + return new Promise((resolve2) => { + const handler = /* @__PURE__ */ __name((payload) => { + if (payload.op === 7 /* WorkerReady */) { + resolve2(); + worker.off("message", handler); + } + }, "handler"); + worker.on("message", handler); + }); + } + async onMessage(worker, payload) { + switch (payload.op) { + case 0 /* Connected */: { + this.connectPromises.get(payload.shardId)?.(); + this.connectPromises.delete(payload.shardId); + break; + } + case 1 /* Destroyed */: { + this.destroyPromises.get(payload.shardId)?.(); + this.destroyPromises.delete(payload.shardId); + break; + } + case 2 /* Event */: { + this.manager.emit(payload.event, { ...payload.data, shardId: payload.shardId }); + break; + } + case 3 /* RetrieveSessionInfo */: { + const session = await this.manager.options.retrieveSessionInfo(payload.shardId); + const response = { + op: 3 /* SessionInfoResponse */, + nonce: payload.nonce, + session + }; + worker.postMessage(response); + break; + } + case 4 /* UpdateSessionInfo */: { + await this.manager.options.updateSessionInfo(payload.shardId, payload.session); + break; + } + case 5 /* WaitForIdentify */: { + const throttler = await this.ensureThrottler(); + try { + const controller = new AbortController(); + this.waitForIdentifyControllers.set(payload.nonce, controller); + await throttler.waitForIdentify(payload.shardId, controller.signal); + } catch { + return; + } + const response = { + op: 4 /* ShardIdentifyResponse */, + nonce: payload.nonce, + ok: true + }; + worker.postMessage(response); + break; + } + case 6 /* FetchStatusResponse */: { + this.fetchStatusPromises.get(payload.nonce)?.(payload.status); + this.fetchStatusPromises.delete(payload.nonce); + break; + } + case 7 /* WorkerReady */: { + break; + } + case 8 /* CancelIdentify */: { + this.waitForIdentifyControllers.get(payload.nonce)?.abort(); + this.waitForIdentifyControllers.delete(payload.nonce); + const response = { + op: 4 /* ShardIdentifyResponse */, + nonce: payload.nonce, + ok: false + }; + worker.postMessage(response); + break; + } + } + } + async ensureThrottler() { + this.throttler ??= await this.manager.options.buildIdentifyThrottler(this.manager); + return this.throttler; + } +}; + +// src/strategies/context/WorkerContextFetchingStrategy.ts +var WorkerContextFetchingStrategy = class { + constructor(options) { + this.options = options; + if (import_node_worker_threads2.isMainThread) { + throw new Error("Cannot instantiate WorkerContextFetchingStrategy on the main thread"); + } + import_node_worker_threads2.parentPort.on("message", (payload) => { + if (payload.op === 3 /* SessionInfoResponse */) { + this.sessionPromises.get(payload.nonce)?.(payload.session); + this.sessionPromises.delete(payload.nonce); + } + if (payload.op === 4 /* ShardIdentifyResponse */) { + const promise = this.waitForIdentifyPromises.get(payload.nonce); + if (payload.ok) { + promise?.resolve(); + } else { + promise?.reject(promise.signal.reason); + } + this.waitForIdentifyPromises.delete(payload.nonce); + } + }); + } + static { + __name(this, "WorkerContextFetchingStrategy"); + } + sessionPromises = new import_collection2.Collection(); + waitForIdentifyPromises = new import_collection2.Collection(); + async retrieveSessionInfo(shardId) { + const nonce = Math.random(); + const payload = { + op: 3 /* RetrieveSessionInfo */, + shardId, + nonce + }; + const promise = new Promise((resolve2) => this.sessionPromises.set(nonce, resolve2)); + import_node_worker_threads2.parentPort.postMessage(payload); + return promise; + } + updateSessionInfo(shardId, sessionInfo) { + const payload = { + op: 4 /* UpdateSessionInfo */, + shardId, + session: sessionInfo + }; + import_node_worker_threads2.parentPort.postMessage(payload); + } + async waitForIdentify(shardId, signal) { + const nonce = Math.random(); + const payload = { + op: 5 /* WaitForIdentify */, + nonce, + shardId + }; + const promise = new Promise( + (resolve2, reject) => ( + // eslint-disable-next-line no-promise-executor-return + this.waitForIdentifyPromises.set(nonce, { signal, resolve: resolve2, reject }) + ) + ); + import_node_worker_threads2.parentPort.postMessage(payload); + const listener = /* @__PURE__ */ __name(() => { + const payload2 = { + op: 8 /* CancelIdentify */, + nonce + }; + import_node_worker_threads2.parentPort.postMessage(payload2); + }, "listener"); + signal.addEventListener("abort", listener); + try { + await promise; + } finally { + signal.removeEventListener("abort", listener); + } + } +}; + +// src/strategies/sharding/SimpleShardingStrategy.ts +var import_collection6 = require("@discordjs/collection"); + +// src/ws/WebSocketShard.ts +var import_node_buffer = require("buffer"); +var import_node_events2 = require("events"); +var import_node_timers = require("timers"); +var import_promises2 = require("timers/promises"); +var import_node_url = require("url"); +var import_node_util = require("util"); +var import_node_zlib = require("zlib"); +var import_collection5 = require("@discordjs/collection"); +var import_util2 = require("@discordjs/util"); +var import_async_queue2 = require("@sapphire/async-queue"); +var import_async_event_emitter = require("@vladfrangu/async_event_emitter"); +var import_v102 = require("discord-api-types/v10"); +var import_ws = require("ws"); + +// src/utils/constants.ts +var import_node_process = __toESM(require("process")); +var import_collection4 = require("@discordjs/collection"); +var import_util = require("@discordjs/util"); +var import_v10 = require("discord-api-types/v10"); + +// src/throttling/SimpleIdentifyThrottler.ts +var import_promises = require("timers/promises"); +var import_collection3 = require("@discordjs/collection"); +var import_async_queue = require("@sapphire/async-queue"); +var SimpleIdentifyThrottler = class { + constructor(maxConcurrency) { + this.maxConcurrency = maxConcurrency; + } + static { + __name(this, "SimpleIdentifyThrottler"); + } + states = new import_collection3.Collection(); + /** + * {@inheritDoc IIdentifyThrottler.waitForIdentify} + */ + async waitForIdentify(shardId, signal) { + const key = shardId % this.maxConcurrency; + const state = this.states.ensure(key, () => { + return { + queue: new import_async_queue.AsyncQueue(), + resetsAt: Number.POSITIVE_INFINITY + }; + }); + await state.queue.wait({ signal }); + try { + const diff = state.resetsAt - Date.now(); + if (diff <= 5e3) { + const time = diff + Math.random() * 1500; + await (0, import_promises.setTimeout)(time); + } + state.resetsAt = Date.now() + 5e3; + } finally { + state.queue.shift(); + } + } +}; + +// src/utils/constants.ts +var Encoding = /* @__PURE__ */ ((Encoding2) => { + Encoding2["JSON"] = "json"; + return Encoding2; +})(Encoding || {}); +var CompressionMethod = /* @__PURE__ */ ((CompressionMethod2) => { + CompressionMethod2["ZlibStream"] = "zlib-stream"; + return CompressionMethod2; +})(CompressionMethod || {}); +var DefaultDeviceProperty = `@discordjs/ws 1.0.1`; +var getDefaultSessionStore = (0, import_util.lazy)(() => new import_collection4.Collection()); +var DefaultWebSocketManagerOptions = { + async buildIdentifyThrottler(manager) { + const info = await manager.fetchGatewayInformation(); + return new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency); + }, + buildStrategy: (manager) => new SimpleShardingStrategy(manager), + shardCount: null, + shardIds: null, + largeThreshold: null, + initialPresence: null, + identifyProperties: { + browser: DefaultDeviceProperty, + device: DefaultDeviceProperty, + os: import_node_process.default.platform + }, + version: import_v10.APIVersion, + encoding: "json" /* JSON */, + compression: null, + retrieveSessionInfo(shardId) { + const store = getDefaultSessionStore(); + return store.get(shardId) ?? null; + }, + updateSessionInfo(shardId, info) { + const store = getDefaultSessionStore(); + if (info) { + store.set(shardId, info); + } else { + store.delete(shardId); + } + }, + handshakeTimeout: 3e4, + helloTimeout: 6e4, + readyTimeout: 15e3 +}; +var ImportantGatewayOpcodes = /* @__PURE__ */ new Set([ + import_v10.GatewayOpcodes.Heartbeat, + import_v10.GatewayOpcodes.Identify, + import_v10.GatewayOpcodes.Resume +]); +function getInitialSendRateLimitState() { + return { + remaining: 120, + resetAt: Date.now() + 6e4 + }; +} +__name(getInitialSendRateLimitState, "getInitialSendRateLimitState"); + +// src/ws/WebSocketShard.ts +var getZlibSync = (0, import_util2.lazy)(async () => import("zlib-sync").then((mod) => mod.default).catch(() => null)); +var WebSocketShardEvents = /* @__PURE__ */ ((WebSocketShardEvents2) => { + WebSocketShardEvents2["Closed"] = "closed"; + WebSocketShardEvents2["Debug"] = "debug"; + WebSocketShardEvents2["Dispatch"] = "dispatch"; + WebSocketShardEvents2["Error"] = "error"; + WebSocketShardEvents2["HeartbeatComplete"] = "heartbeat"; + WebSocketShardEvents2["Hello"] = "hello"; + WebSocketShardEvents2["Ready"] = "ready"; + WebSocketShardEvents2["Resumed"] = "resumed"; + return WebSocketShardEvents2; +})(WebSocketShardEvents || {}); +var WebSocketShardStatus = /* @__PURE__ */ ((WebSocketShardStatus2) => { + WebSocketShardStatus2[WebSocketShardStatus2["Idle"] = 0] = "Idle"; + WebSocketShardStatus2[WebSocketShardStatus2["Connecting"] = 1] = "Connecting"; + WebSocketShardStatus2[WebSocketShardStatus2["Resuming"] = 2] = "Resuming"; + WebSocketShardStatus2[WebSocketShardStatus2["Ready"] = 3] = "Ready"; + return WebSocketShardStatus2; +})(WebSocketShardStatus || {}); +var WebSocketShardDestroyRecovery = /* @__PURE__ */ ((WebSocketShardDestroyRecovery2) => { + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Reconnect"] = 0] = "Reconnect"; + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Resume"] = 1] = "Resume"; + return WebSocketShardDestroyRecovery2; +})(WebSocketShardDestroyRecovery || {}); +var CloseCodes = /* @__PURE__ */ ((CloseCodes2) => { + CloseCodes2[CloseCodes2["Normal"] = 1e3] = "Normal"; + CloseCodes2[CloseCodes2["Resuming"] = 4200] = "Resuming"; + return CloseCodes2; +})(CloseCodes || {}); +var WebSocketConstructor = import_ws.WebSocket; +var WebSocketShard = class extends import_async_event_emitter.AsyncEventEmitter { + static { + __name(this, "WebSocketShard"); + } + connection = null; + useIdentifyCompress = false; + inflate = null; + textDecoder = new import_node_util.TextDecoder(); + replayedEvents = 0; + isAck = true; + sendRateLimitState = getInitialSendRateLimitState(); + initialHeartbeatTimeoutController = null; + heartbeatInterval = null; + lastHeartbeatAt = -1; + // Indicates whether the shard has already resolved its original connect() call + initialConnectResolved = false; + // Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET) + failedToConnectDueToNetworkError = false; + sendQueue = new import_async_queue2.AsyncQueue(); + timeoutAbortControllers = new import_collection5.Collection(); + strategy; + id; + #status = 0 /* Idle */; + get status() { + return this.#status; + } + constructor(strategy, id) { + super(); + this.strategy = strategy; + this.id = id; + } + async connect() { + const controller = new AbortController(); + let promise; + if (!this.initialConnectResolved) { + promise = Promise.race([ + (0, import_node_events2.once)(this, "ready" /* Ready */, { signal: controller.signal }), + (0, import_node_events2.once)(this, "resumed" /* Resumed */, { signal: controller.signal }) + ]); + } + void this.internalConnect(); + try { + await promise; + } catch ({ error }) { + throw error; + } finally { + controller.abort(); + } + this.initialConnectResolved = true; + } + async internalConnect() { + if (this.#status !== 0 /* Idle */) { + throw new Error("Tried to connect a shard that wasn't idle"); + } + const { version: version2, encoding, compression } = this.strategy.options; + const params = new import_node_url.URLSearchParams({ v: version2, encoding }); + if (compression) { + const zlib = await getZlibSync(); + if (zlib) { + params.append("compress", compression); + this.inflate = new zlib.Inflate({ + chunkSize: 65535, + to: "string" + }); + } else if (!this.useIdentifyCompress) { + this.useIdentifyCompress = true; + console.warn( + "WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress" + ); + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + const url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`; + this.debug([`Connecting to ${url}`]); + const connection = new WebSocketConstructor(url, { + handshakeTimeout: this.strategy.options.handshakeTimeout ?? void 0 + }); + connection.binaryType = "arraybuffer"; + connection.onmessage = (event) => { + void this.onMessage(event.data, event.data instanceof ArrayBuffer); + }; + connection.onerror = (event) => { + this.onError(event.error); + }; + connection.onclose = (event) => { + void this.onClose(event.code); + }; + this.connection = connection; + this.#status = 1 /* Connecting */; + this.sendRateLimitState = getInitialSendRateLimitState(); + const { ok } = await this.waitForEvent("hello" /* Hello */, this.strategy.options.helloTimeout); + if (!ok) { + return; + } + if (session?.shardCount === this.strategy.options.shardCount) { + await this.resume(session); + } else { + await this.identify(); + } + } + async destroy(options = {}) { + if (this.#status === 0 /* Idle */) { + this.debug(["Tried to destroy a shard that was idle"]); + return; + } + if (!options.code) { + options.code = options.recover === 1 /* Resume */ ? 4200 /* Resuming */ : 1e3 /* Normal */; + } + this.debug([ + "Destroying shard", + `Reason: ${options.reason ?? "none"}`, + `Code: ${options.code}`, + `Recover: ${options.recover === void 0 ? "none" : WebSocketShardDestroyRecovery[options.recover]}` + ]); + this.isAck = true; + if (this.heartbeatInterval) { + (0, import_node_timers.clearInterval)(this.heartbeatInterval); + } + if (this.initialHeartbeatTimeoutController) { + this.initialHeartbeatTimeoutController.abort(); + this.initialHeartbeatTimeoutController = null; + } + this.lastHeartbeatAt = -1; + for (const controller of this.timeoutAbortControllers.values()) { + controller.abort(); + } + this.timeoutAbortControllers.clear(); + this.failedToConnectDueToNetworkError = false; + if (options.recover !== 1 /* Resume */) { + await this.strategy.updateSessionInfo(this.id, null); + } + if (this.connection) { + this.connection.onmessage = null; + this.connection.onclose = null; + const shouldClose = this.connection.readyState === import_ws.WebSocket.OPEN; + this.debug([ + "Connection status during destroy", + `Needs closing: ${shouldClose}`, + `Ready state: ${this.connection.readyState}` + ]); + if (shouldClose) { + let outerResolve; + const promise = new Promise((resolve2) => { + outerResolve = resolve2; + }); + this.connection.onclose = outerResolve; + this.connection.close(options.code, options.reason); + await promise; + this.emit("closed" /* Closed */, { code: options.code }); + } + this.connection.onerror = null; + } else { + this.debug(["Destroying a shard that has no connection; please open an issue on GitHub"]); + } + this.#status = 0 /* Idle */; + if (options.recover !== void 0) { + await (0, import_promises2.setTimeout)(500); + return this.internalConnect(); + } + } + async waitForEvent(event, timeoutDuration) { + this.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : "indefinitely"}`]); + const timeoutController = new AbortController(); + const timeout = timeoutDuration ? (0, import_node_timers.setTimeout)(() => timeoutController.abort(), timeoutDuration).unref() : null; + this.timeoutAbortControllers.set(event, timeoutController); + const closeController = new AbortController(); + try { + const closed = await Promise.race([ + (0, import_node_events2.once)(this, event, { signal: timeoutController.signal }).then(() => false), + (0, import_node_events2.once)(this, "closed" /* Closed */, { signal: closeController.signal }).then(() => true) + ]); + return { ok: !closed }; + } catch { + void this.destroy({ + code: 1e3 /* Normal */, + reason: "Something timed out or went wrong while waiting for an event", + recover: 0 /* Reconnect */ + }); + return { ok: false }; + } finally { + if (timeout) { + (0, import_node_timers.clearTimeout)(timeout); + } + this.timeoutAbortControllers.delete(event); + if (!closeController.signal.aborted) { + closeController.abort(); + } + } + } + async send(payload) { + if (!this.connection) { + throw new Error("WebSocketShard wasn't connected"); + } + if (this.#status !== 3 /* Ready */ && !ImportantGatewayOpcodes.has(payload.op)) { + this.debug(["Tried to send a non-crucial payload before the shard was ready, waiting"]); + try { + await (0, import_node_events2.once)(this, "ready" /* Ready */); + } catch { + return this.send(payload); + } + } + await this.sendQueue.wait(); + if (--this.sendRateLimitState.remaining <= 0) { + const now = Date.now(); + if (this.sendRateLimitState.resetAt > now) { + const sleepFor = this.sendRateLimitState.resetAt - now; + this.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]); + const controller = new AbortController(); + const interrupted = await Promise.race([ + (0, import_promises2.setTimeout)(sleepFor).then(() => false), + (0, import_node_events2.once)(this, "closed" /* Closed */, { signal: controller.signal }).then(() => true) + ]); + if (interrupted) { + this.debug(["Connection closed while waiting for the send rate limit to reset, re-queueing payload"]); + this.sendQueue.shift(); + return this.send(payload); + } + controller.abort(); + } + this.sendRateLimitState = getInitialSendRateLimitState(); + } + this.sendQueue.shift(); + this.connection.send(JSON.stringify(payload)); + } + async identify() { + this.debug(["Waiting for identify throttle"]); + const controller = new AbortController(); + const closeHandler = /* @__PURE__ */ __name(() => { + controller.abort(); + }, "closeHandler"); + this.on("closed" /* Closed */, closeHandler); + try { + await this.strategy.waitForIdentify(this.id, controller.signal); + } catch { + if (controller.signal.aborted) { + this.debug(["Was waiting for an identify, but the shard closed in the meantime"]); + return; + } + this.debug([ + "IContextFetchingStrategy#waitForIdentify threw an unknown error.", + "If you're using a custom strategy, this is probably nothing to worry about.", + "If you're not, please open an issue on GitHub." + ]); + await this.destroy({ + reason: "Identify throttling logic failed", + recover: 1 /* Resume */ + }); + } finally { + this.off("closed" /* Closed */, closeHandler); + } + this.debug([ + "Identifying", + `shard id: ${this.id.toString()}`, + `shard count: ${this.strategy.options.shardCount}`, + `intents: ${this.strategy.options.intents}`, + `compression: ${this.inflate ? "zlib-stream" : this.useIdentifyCompress ? "identify" : "none"}` + ]); + const d = { + token: this.strategy.options.token, + properties: this.strategy.options.identifyProperties, + intents: this.strategy.options.intents, + compress: this.useIdentifyCompress, + shard: [this.id, this.strategy.options.shardCount] + }; + if (this.strategy.options.largeThreshold) { + d.large_threshold = this.strategy.options.largeThreshold; + } + if (this.strategy.options.initialPresence) { + d.presence = this.strategy.options.initialPresence; + } + await this.send({ + op: import_v102.GatewayOpcodes.Identify, + d + }); + await this.waitForEvent("ready" /* Ready */, this.strategy.options.readyTimeout); + } + async resume(session) { + this.debug([ + "Resuming session", + `resume url: ${session.resumeURL}`, + `sequence: ${session.sequence}`, + `shard id: ${this.id.toString()}` + ]); + this.#status = 2 /* Resuming */; + this.replayedEvents = 0; + return this.send({ + op: import_v102.GatewayOpcodes.Resume, + d: { + token: this.strategy.options.token, + seq: session.sequence, + session_id: session.sessionId + } + }); + } + async heartbeat(requested = false) { + if (!this.isAck && !requested) { + return this.destroy({ reason: "Zombie connection", recover: 1 /* Resume */ }); + } + const session = await this.strategy.retrieveSessionInfo(this.id); + await this.send({ + op: import_v102.GatewayOpcodes.Heartbeat, + d: session?.sequence ?? null + }); + this.lastHeartbeatAt = Date.now(); + this.isAck = false; + } + async unpackMessage(data, isBinary) { + if (!isBinary) { + try { + return JSON.parse(data); + } catch { + return null; + } + } + const decompressable = new Uint8Array(data); + if (this.useIdentifyCompress) { + return new Promise((resolve2, reject) => { + (0, import_node_zlib.inflate)(decompressable, { chunkSize: 65535 }, (err, result) => { + if (err) { + reject(err); + return; + } + resolve2(JSON.parse(this.textDecoder.decode(result))); + }); + }); + } + if (this.inflate) { + const l = decompressable.length; + const flush = l >= 4 && decompressable[l - 4] === 0 && decompressable[l - 3] === 0 && decompressable[l - 2] === 255 && decompressable[l - 1] === 255; + const zlib = await getZlibSync(); + this.inflate.push(import_node_buffer.Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH); + if (this.inflate.err) { + this.emit("error" /* Error */, { + error: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ""}`) + }); + } + if (!flush) { + return null; + } + const { result } = this.inflate; + if (!result) { + return null; + } + return JSON.parse(typeof result === "string" ? result : this.textDecoder.decode(result)); + } + this.debug([ + "Received a message we were unable to decompress", + `isBinary: ${isBinary.toString()}`, + `useIdentifyCompress: ${this.useIdentifyCompress.toString()}`, + `inflate: ${Boolean(this.inflate).toString()}` + ]); + return null; + } + async onMessage(data, isBinary) { + const payload = await this.unpackMessage(data, isBinary); + if (!payload) { + return; + } + switch (payload.op) { + case import_v102.GatewayOpcodes.Dispatch: { + if (this.#status === 2 /* Resuming */) { + this.replayedEvents++; + } + switch (payload.t) { + case import_v102.GatewayDispatchEvents.Ready: { + this.#status = 3 /* Ready */; + const session2 = { + sequence: payload.s, + sessionId: payload.d.session_id, + shardId: this.id, + shardCount: this.strategy.options.shardCount, + resumeURL: payload.d.resume_gateway_url + }; + await this.strategy.updateSessionInfo(this.id, session2); + this.emit("ready" /* Ready */, { data: payload.d }); + break; + } + case import_v102.GatewayDispatchEvents.Resumed: { + this.#status = 3 /* Ready */; + this.debug([`Resumed and replayed ${this.replayedEvents} events`]); + this.emit("resumed" /* Resumed */); + break; + } + default: { + break; + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + if (session) { + if (payload.s > session.sequence) { + await this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s }); + } + } else { + this.debug([ + `Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect` + ]); + } + this.emit("dispatch" /* Dispatch */, { data: payload }); + break; + } + case import_v102.GatewayOpcodes.Heartbeat: { + await this.heartbeat(true); + break; + } + case import_v102.GatewayOpcodes.Reconnect: { + await this.destroy({ + reason: "Told to reconnect by Discord", + recover: 1 /* Resume */ + }); + break; + } + case import_v102.GatewayOpcodes.InvalidSession: { + this.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]); + const session = await this.strategy.retrieveSessionInfo(this.id); + if (payload.d && session) { + await this.resume(session); + } else { + await this.destroy({ + reason: "Invalid session", + recover: 0 /* Reconnect */ + }); + } + break; + } + case import_v102.GatewayOpcodes.Hello: { + this.emit("hello" /* Hello */); + const jitter = Math.random(); + const firstWait = Math.floor(payload.d.heartbeat_interval * jitter); + this.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]); + try { + const controller = new AbortController(); + this.initialHeartbeatTimeoutController = controller; + await (0, import_promises2.setTimeout)(firstWait, void 0, { signal: controller.signal }); + } catch { + this.debug(["Cancelled initial heartbeat due to #destroy being called"]); + return; + } finally { + this.initialHeartbeatTimeoutController = null; + } + await this.heartbeat(); + this.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]); + this.heartbeatInterval = (0, import_node_timers.setInterval)(() => void this.heartbeat(), payload.d.heartbeat_interval); + break; + } + case import_v102.GatewayOpcodes.HeartbeatAck: { + this.isAck = true; + const ackAt = Date.now(); + this.emit("heartbeat" /* HeartbeatComplete */, { + ackAt, + heartbeatAt: this.lastHeartbeatAt, + latency: ackAt - this.lastHeartbeatAt + }); + break; + } + } + } + onError(error) { + if ("code" in error && ["ECONNRESET", "ECONNREFUSED"].includes(error.code)) { + this.debug(["Failed to connect to the gateway URL specified due to a network error"]); + this.failedToConnectDueToNetworkError = true; + return; + } + this.emit("error" /* Error */, { error }); + } + async onClose(code) { + this.emit("closed" /* Closed */, { code }); + switch (code) { + case 1e3 /* Normal */: { + return this.destroy({ + code, + reason: "Got disconnected by Discord", + recover: 0 /* Reconnect */ + }); + } + case 4200 /* Resuming */: { + break; + } + case import_v102.GatewayCloseCodes.UnknownError: { + this.debug([`An unknown error occurred: ${code}`]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.UnknownOpcode: { + this.debug(["An invalid opcode was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.DecodeError: { + this.debug(["An invalid payload was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.NotAuthenticated: { + this.debug(["A request was somehow sent before the identify/resume payload."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.AuthenticationFailed: { + this.emit("error" /* Error */, { + error: new Error("Authentication failed") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.AlreadyAuthenticated: { + this.debug(["More than one auth payload was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.InvalidSeq: { + this.debug(["An invalid sequence was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.RateLimited: { + this.debug(["The WebSocket rate limit has been hit, this should never happen"]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case import_v102.GatewayCloseCodes.SessionTimedOut: { + this.debug(["Session timed out."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case import_v102.GatewayCloseCodes.InvalidShard: { + this.emit("error" /* Error */, { + error: new Error("Invalid shard") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.ShardingRequired: { + this.emit("error" /* Error */, { + error: new Error("Sharding is required") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.InvalidAPIVersion: { + this.emit("error" /* Error */, { + error: new Error("Used an invalid API version") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.InvalidIntents: { + this.emit("error" /* Error */, { + error: new Error("Used invalid intents") + }); + return this.destroy({ code }); + } + case import_v102.GatewayCloseCodes.DisallowedIntents: { + this.emit("error" /* Error */, { + error: new Error("Used disallowed intents") + }); + return this.destroy({ code }); + } + default: { + this.debug([ + `The gateway closed with an unexpected code ${code}, attempting to ${this.failedToConnectDueToNetworkError ? "reconnect" : "resume"}.` + ]); + return this.destroy({ + code, + recover: this.failedToConnectDueToNetworkError ? 0 /* Reconnect */ : 1 /* Resume */ + }); + } + } + } + debug(messages) { + const message = `${messages[0]}${messages.length > 1 ? ` +${messages.slice(1).map((m) => ` ${m}`).join("\n")}` : ""}`; + this.emit("debug" /* Debug */, { message }); + } +}; + +// src/strategies/sharding/SimpleShardingStrategy.ts +var SimpleShardingStrategy = class { + static { + __name(this, "SimpleShardingStrategy"); + } + manager; + shards = new import_collection6.Collection(); + constructor(manager) { + this.manager = manager; + } + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + async spawn(shardIds) { + const strategyOptions = await managerToFetchingStrategyOptions(this.manager); + for (const shardId of shardIds) { + const strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions); + const shard = new WebSocketShard(strategy, shardId); + for (const event of Object.values(WebSocketShardEvents)) { + shard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId })); + } + this.shards.set(shardId, shard); + } + } + /** + * {@inheritDoc IShardingStrategy.connect} + */ + async connect() { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.connect()); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + async destroy(options) { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.destroy(options)); + } + await Promise.all(promises); + this.shards.clear(); + } + /** + * {@inheritDoc IShardingStrategy.send} + */ + async send(shardId, payload) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} not found`); + } + return shard.send(payload); + } + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + async fetchStatus() { + return this.shards.mapValues((shard) => shard.status); + } +}; + +// src/utils/WorkerBootstrapper.ts +var import_node_worker_threads3 = require("worker_threads"); +var import_collection7 = require("@discordjs/collection"); +var WorkerBootstrapper = class { + static { + __name(this, "WorkerBootstrapper"); + } + /** + * The data passed to the worker thread + */ + data = import_node_worker_threads3.workerData; + /** + * The shards that are managed by this worker + */ + shards = new import_collection7.Collection(); + constructor() { + if (import_node_worker_threads3.isMainThread) { + throw new Error("Expected WorkerBootstrap to not be used within the main thread"); + } + } + /** + * Helper method to initiate a shard's connection process + */ + async connect(shardId) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.connect(); + } + /** + * Helper method to destroy a shard + */ + async destroy(shardId, options) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.destroy(options); + } + /** + * Helper method to attach event listeners to the parentPort + */ + setupThreadEvents() { + import_node_worker_threads3.parentPort.on("messageerror", (err) => { + throw err; + }).on("message", async (payload) => { + switch (payload.op) { + case 0 /* Connect */: { + await this.connect(payload.shardId); + const response = { + op: 0 /* Connected */, + shardId: payload.shardId + }; + import_node_worker_threads3.parentPort.postMessage(response); + break; + } + case 1 /* Destroy */: { + await this.destroy(payload.shardId, payload.options); + const response = { + op: 1 /* Destroyed */, + shardId: payload.shardId + }; + import_node_worker_threads3.parentPort.postMessage(response); + break; + } + case 2 /* Send */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new RangeError(`Shard ${payload.shardId} does not exist`); + } + await shard.send(payload.payload); + break; + } + case 3 /* SessionInfoResponse */: { + break; + } + case 4 /* ShardIdentifyResponse */: { + break; + } + case 5 /* FetchStatus */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new Error(`Shard ${payload.shardId} does not exist`); + } + const response = { + op: 6 /* FetchStatusResponse */, + status: shard.status, + nonce: payload.nonce + }; + import_node_worker_threads3.parentPort.postMessage(response); + break; + } + } + }); + } + /** + * Bootstraps the worker thread with the provided options + */ + async bootstrap(options = {}) { + for (const shardId of this.data.shardIds) { + const shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId); + for (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) { + shard.on(event, (data) => { + const payload = { + op: 2 /* Event */, + event, + data, + shardId + }; + import_node_worker_threads3.parentPort.postMessage(payload); + }); + } + await options.shardCallback?.(shard); + this.shards.set(shardId, shard); + } + this.setupThreadEvents(); + const message = { + op: 7 /* WorkerReady */ + }; + import_node_worker_threads3.parentPort.postMessage(message); + } +}; + +// src/ws/WebSocketManager.ts +var import_util3 = require("@discordjs/util"); +var import_async_event_emitter2 = require("@vladfrangu/async_event_emitter"); +var import_v103 = require("discord-api-types/v10"); +var WebSocketManager = class extends import_async_event_emitter2.AsyncEventEmitter { + static { + __name(this, "WebSocketManager"); + } + /** + * The options being used by this manager + */ + options; + /** + * Internal cache for a GET /gateway/bot result + */ + gatewayInformation = null; + /** + * Internal cache for the shard ids + */ + shardIds = null; + /** + * Strategy used to manage shards + * + * @defaultValue `SimpleShardingStrategy` + */ + strategy; + constructor(options) { + super(); + this.options = { ...DefaultWebSocketManagerOptions, ...options }; + this.strategy = this.options.buildStrategy(this); + } + /** + * Fetches the gateway information from Discord - or returns it from cache if available + * + * @param force - Whether to ignore the cache and force a fresh fetch + */ + async fetchGatewayInformation(force = false) { + if (this.gatewayInformation) { + if (this.gatewayInformation.expiresAt <= Date.now()) { + this.gatewayInformation = null; + } else if (!force) { + return this.gatewayInformation.data; + } + } + const data = await this.options.rest.get(import_v103.Routes.gatewayBot()); + this.gatewayInformation = { data, expiresAt: Date.now() + (data.session_start_limit.reset_after || 5e3) }; + return this.gatewayInformation.data; + } + /** + * Updates your total shard count on-the-fly, spawning shards as needed + * + * @param shardCount - The new shard count to use + */ + async updateShardCount(shardCount) { + await this.strategy.destroy({ reason: "User is adjusting their shards" }); + this.options.shardCount = shardCount; + const shardIds = await this.getShardIds(true); + await this.strategy.spawn(shardIds); + return this; + } + /** + * Yields the total number of shards across for your bot, accounting for Discord recommendations + */ + async getShardCount() { + if (this.options.shardCount) { + return this.options.shardCount; + } + const shardIds = await this.getShardIds(); + return Math.max(...shardIds) + 1; + } + /** + * Yields the ids of the shards this manager should manage + */ + async getShardIds(force = false) { + if (this.shardIds && !force) { + return this.shardIds; + } + let shardIds; + if (this.options.shardIds) { + if (Array.isArray(this.options.shardIds)) { + shardIds = this.options.shardIds; + } else { + const { start, end } = this.options.shardIds; + shardIds = [...(0, import_util3.range)({ start, end: end + 1 })]; + } + } else { + const data = await this.fetchGatewayInformation(); + shardIds = [...(0, import_util3.range)(this.options.shardCount ?? data.shards)]; + } + this.shardIds = shardIds; + return shardIds; + } + async connect() { + const shardCount = await this.getShardCount(); + const data = await this.fetchGatewayInformation(); + if (data.session_start_limit.remaining < shardCount) { + throw new Error( + `Not enough sessions remaining to spawn ${shardCount} shards; only ${data.session_start_limit.remaining} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}` + ); + } + await this.updateShardCount(shardCount); + await this.strategy.connect(); + } + destroy(options) { + return this.strategy.destroy(options); + } + send(shardId, payload) { + return this.strategy.send(shardId, payload); + } + fetchStatus() { + return this.strategy.fetchStatus(); + } +}; + +// src/index.ts +var version = "1.0.1"; +// Annotate the CommonJS export names for ESM import in node: +0 && (module.exports = { + CloseCodes, + CompressionMethod, + DefaultDeviceProperty, + DefaultWebSocketManagerOptions, + Encoding, + ImportantGatewayOpcodes, + SimpleContextFetchingStrategy, + SimpleIdentifyThrottler, + SimpleShardingStrategy, + WebSocketManager, + WebSocketShard, + WebSocketShardDestroyRecovery, + WebSocketShardEvents, + WebSocketShardStatus, + WorkerBootstrapper, + WorkerContextFetchingStrategy, + WorkerReceivePayloadOp, + WorkerSendPayloadOp, + WorkerShardingStrategy, + getInitialSendRateLimitState, + managerToFetchingStrategyOptions, + version +}); +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/dist/index.js.map b/node_modules/@discordjs/ws/dist/index.js.map new file mode 100644 index 0000000..b89bb50 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.ts","../src/strategies/context/IContextFetchingStrategy.ts","../src/strategies/context/SimpleContextFetchingStrategy.ts","../src/strategies/context/WorkerContextFetchingStrategy.ts","../src/strategies/sharding/WorkerShardingStrategy.ts","../src/strategies/sharding/SimpleShardingStrategy.ts","../src/ws/WebSocketShard.ts","../src/utils/constants.ts","../src/throttling/SimpleIdentifyThrottler.ts","../src/utils/WorkerBootstrapper.ts","../src/ws/WebSocketManager.ts"],"sourcesContent":["export * from './strategies/context/IContextFetchingStrategy.js';\nexport * from './strategies/context/SimpleContextFetchingStrategy.js';\nexport * from './strategies/context/WorkerContextFetchingStrategy.js';\n\nexport * from './strategies/sharding/IShardingStrategy.js';\nexport * from './strategies/sharding/SimpleShardingStrategy.js';\nexport * from './strategies/sharding/WorkerShardingStrategy.js';\n\nexport * from './throttling/IIdentifyThrottler.js';\nexport * from './throttling/SimpleIdentifyThrottler.js';\n\nexport * from './utils/constants.js';\nexport * from './utils/WorkerBootstrapper.js';\n\nexport * from './ws/WebSocketManager.js';\nexport * from './ws/WebSocketShard.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/ws/#readme | @discordjs/ws} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\nexport const version = '1.0.1' as string;\n","import type { Awaitable } from '@discordjs/util';\nimport type { APIGatewayBotInfo } from 'discord-api-types/v10';\nimport type { SessionInfo, WebSocketManager, WebSocketManagerOptions } from '../../ws/WebSocketManager.js';\n\nexport interface FetchingStrategyOptions\n\textends Omit<\n\t\tWebSocketManagerOptions,\n\t\t| 'buildIdentifyThrottler'\n\t\t| 'buildStrategy'\n\t\t| 'rest'\n\t\t| 'retrieveSessionInfo'\n\t\t| 'shardCount'\n\t\t| 'shardIds'\n\t\t| 'updateSessionInfo'\n\t> {\n\treadonly gatewayInformation: APIGatewayBotInfo;\n\treadonly shardCount: number;\n}\n\n/**\n * Strategies responsible solely for making manager information accessible\n */\nexport interface IContextFetchingStrategy {\n\treadonly options: FetchingStrategyOptions;\n\tretrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>;\n\tupdateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>;\n\t/**\n\t * Resolves once the given shard should be allowed to identify\n\t * This should correctly handle the signal and reject with an abort error if the operation is aborted.\n\t * Other errors will cause the shard to reconnect.\n\t */\n\twaitForIdentify(shardId: number, signal: AbortSignal): Promise<void>;\n}\n\nexport async function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions> {\n\t/* eslint-disable @typescript-eslint/unbound-method */\n\tconst {\n\t\tbuildIdentifyThrottler,\n\t\tbuildStrategy,\n\t\tretrieveSessionInfo,\n\t\tupdateSessionInfo,\n\t\tshardCount,\n\t\tshardIds,\n\t\trest,\n\t\t...managerOptions\n\t} = manager.options;\n\t/* eslint-enable @typescript-eslint/unbound-method */\n\n\treturn {\n\t\t...managerOptions,\n\t\tgatewayInformation: await manager.fetchGatewayInformation(),\n\t\tshardCount: await manager.getShardCount(),\n\t};\n}\n","import type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class SimpleContextFetchingStrategy implements IContextFetchingStrategy {\n\t// This strategy assumes every shard is running under the same process - therefore we need a single\n\t// IdentifyThrottler per manager.\n\tprivate static throttlerCache = new WeakMap<WebSocketManager, IIdentifyThrottler>();\n\n\tprivate static async ensureThrottler(manager: WebSocketManager): Promise<IIdentifyThrottler> {\n\t\tconst throttler = SimpleContextFetchingStrategy.throttlerCache.get(manager);\n\t\tif (throttler) {\n\t\t\treturn throttler;\n\t\t}\n\n\t\tconst newThrottler = await manager.options.buildIdentifyThrottler(manager);\n\t\tSimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler);\n\n\t\treturn newThrottler;\n\t}\n\n\tpublic constructor(private readonly manager: WebSocketManager, public readonly options: FetchingStrategyOptions) {}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\treturn this.manager.options.retrieveSessionInfo(shardId);\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\treturn this.manager.options.updateSessionInfo(shardId, sessionInfo);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst throttler = await SimpleContextFetchingStrategy.ensureThrottler(this.manager);\n\t\tawait throttler.waitForIdentify(shardId, signal);\n\t}\n}\n","import { isMainThread, parentPort } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { SessionInfo } from '../../ws/WebSocketManager.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../sharding/WorkerShardingStrategy.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class WorkerContextFetchingStrategy implements IContextFetchingStrategy {\n\tprivate readonly sessionPromises = new Collection<number, (session: SessionInfo | null) => void>();\n\n\tprivate readonly waitForIdentifyPromises = new Collection<\n\t\tnumber,\n\t\t{ reject(error: unknown): void; resolve(): void; signal: AbortSignal }\n\t>();\n\n\tpublic constructor(public readonly options: FetchingStrategyOptions) {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Cannot instantiate WorkerContextFetchingStrategy on the main thread');\n\t\t}\n\n\t\tparentPort!.on('message', (payload: WorkerSendPayload) => {\n\t\t\tif (payload.op === WorkerSendPayloadOp.SessionInfoResponse) {\n\t\t\t\tthis.sessionPromises.get(payload.nonce)?.(payload.session);\n\t\t\t\tthis.sessionPromises.delete(payload.nonce);\n\t\t\t}\n\n\t\t\tif (payload.op === WorkerSendPayloadOp.ShardIdentifyResponse) {\n\t\t\t\tconst promise = this.waitForIdentifyPromises.get(payload.nonce);\n\t\t\t\tif (payload.ok) {\n\t\t\t\t\tpromise?.resolve();\n\t\t\t\t} else {\n\t\t\t\t\t// We need to make sure we reject with an abort error\n\t\t\t\t\tpromise?.reject(promise.signal.reason);\n\t\t\t\t}\n\n\t\t\t\tthis.waitForIdentifyPromises.delete(payload.nonce);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\tconst nonce = Math.random();\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.RetrieveSessionInfo,\n\t\t\tshardId,\n\t\t\tnonce,\n\t\t};\n\t\t// eslint-disable-next-line no-promise-executor-return\n\t\tconst promise = new Promise<SessionInfo | null>((resolve) => this.sessionPromises.set(nonce, resolve));\n\t\tparentPort!.postMessage(payload);\n\t\treturn promise;\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.UpdateSessionInfo,\n\t\t\tshardId,\n\t\t\tsession: sessionInfo,\n\t\t};\n\t\tparentPort!.postMessage(payload);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst nonce = Math.random();\n\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WaitForIdentify,\n\t\t\tnonce,\n\t\t\tshardId,\n\t\t};\n\t\tconst promise = new Promise<void>((resolve, reject) =>\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tthis.waitForIdentifyPromises.set(nonce, { signal, resolve, reject }),\n\t\t);\n\n\t\tparentPort!.postMessage(payload);\n\n\t\tconst listener = () => {\n\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\top: WorkerReceivePayloadOp.CancelIdentify,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\tparentPort!.postMessage(payload);\n\t\t};\n\n\t\tsignal.addEventListener('abort', listener);\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} finally {\n\t\t\tsignal.removeEventListener('abort', listener);\n\t\t}\n\t}\n}\n","import { once } from 'node:events';\nimport { join, isAbsolute, resolve } from 'node:path';\nimport { Worker } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type {\n\tWebSocketShardDestroyOptions,\n\tWebSocketShardEvents,\n\tWebSocketShardStatus,\n} from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions, type FetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\nexport interface WorkerData extends FetchingStrategyOptions {\n\tshardIds: number[];\n}\n\nexport enum WorkerSendPayloadOp {\n\tConnect,\n\tDestroy,\n\tSend,\n\tSessionInfoResponse,\n\tShardIdentifyResponse,\n\tFetchStatus,\n}\n\nexport type WorkerSendPayload =\n\t| { nonce: number; ok: boolean; op: WorkerSendPayloadOp.ShardIdentifyResponse }\n\t| { nonce: number; op: WorkerSendPayloadOp.FetchStatus; shardId: number }\n\t| { nonce: number; op: WorkerSendPayloadOp.SessionInfoResponse; session: SessionInfo | null }\n\t| { op: WorkerSendPayloadOp.Connect; shardId: number }\n\t| { op: WorkerSendPayloadOp.Destroy; options?: WebSocketShardDestroyOptions; shardId: number }\n\t| { op: WorkerSendPayloadOp.Send; payload: GatewaySendPayload; shardId: number };\n\nexport enum WorkerReceivePayloadOp {\n\tConnected,\n\tDestroyed,\n\tEvent,\n\tRetrieveSessionInfo,\n\tUpdateSessionInfo,\n\tWaitForIdentify,\n\tFetchStatusResponse,\n\tWorkerReady,\n\tCancelIdentify,\n}\n\nexport type WorkerReceivePayload =\n\t// Can't seem to get a type-safe union based off of the event, so I'm sadly leaving data as any for now\n\t| { data: any; event: WebSocketShardEvents; op: WorkerReceivePayloadOp.Event; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.CancelIdentify }\n\t| { nonce: number; op: WorkerReceivePayloadOp.FetchStatusResponse; status: WebSocketShardStatus }\n\t| { nonce: number; op: WorkerReceivePayloadOp.RetrieveSessionInfo; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.WaitForIdentify; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Connected; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Destroyed; shardId: number }\n\t| { op: WorkerReceivePayloadOp.UpdateSessionInfo; session: SessionInfo | null; shardId: number }\n\t| { op: WorkerReceivePayloadOp.WorkerReady };\n\n/**\n * Options for a {@link WorkerShardingStrategy}\n */\nexport interface WorkerShardingStrategyOptions {\n\t/**\n\t * Dictates how many shards should be spawned per worker thread.\n\t */\n\tshardsPerWorker: number | 'all';\n\t/**\n\t * Path to the worker file to use. The worker requires quite a bit of setup, it is recommended you leverage the {@link WorkerBootstrapper} class.\n\t */\n\tworkerPath?: string;\n}\n\n/**\n * Strategy used to spawn threads in worker_threads\n */\nexport class WorkerShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly options: WorkerShardingStrategyOptions;\n\n\t#workers: Worker[] = [];\n\n\treadonly #workerByShardId = new Collection<number, Worker>();\n\n\tprivate readonly connectPromises = new Collection<number, () => void>();\n\n\tprivate readonly destroyPromises = new Collection<number, () => void>();\n\n\tprivate readonly fetchStatusPromises = new Collection<number, (status: WebSocketShardStatus) => void>();\n\n\tprivate readonly waitForIdentifyControllers = new Collection<number, AbortController>();\n\n\tprivate throttler?: IIdentifyThrottler;\n\n\tpublic constructor(manager: WebSocketManager, options: WorkerShardingStrategyOptions) {\n\t\tthis.manager = manager;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst shardsPerWorker = this.options.shardsPerWorker === 'all' ? shardIds.length : this.options.shardsPerWorker;\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tconst loops = Math.ceil(shardIds.length / shardsPerWorker);\n\t\tconst promises: Promise<void>[] = [];\n\n\t\tfor (let idx = 0; idx < loops; idx++) {\n\t\t\tconst slice = shardIds.slice(idx * shardsPerWorker, (idx + 1) * shardsPerWorker);\n\t\t\tconst workerData: WorkerData = {\n\t\t\t\t...strategyOptions,\n\t\t\t\tshardIds: slice,\n\t\t\t};\n\n\t\t\tpromises.push(this.setupWorker(workerData));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Connect,\n\t\t\t\tshardId,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<void>((resolve) => this.connectPromises.set(shardId, resolve));\n\t\t\tworker.postMessage(payload);\n\t\t\tpromises.push(promise);\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options: Omit<WebSocketShardDestroyOptions, 'recover'> = {}) {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Destroy,\n\t\t\t\tshardId,\n\t\t\t\toptions,\n\t\t\t};\n\n\t\t\tpromises.push(\n\t\t\t\t// eslint-disable-next-line no-promise-executor-return, promise/prefer-await-to-then\n\t\t\t\tnew Promise<void>((resolve) => this.destroyPromises.set(shardId, resolve)).then(async () => worker.terminate()),\n\t\t\t);\n\t\t\tworker.postMessage(payload);\n\t\t}\n\n\t\tthis.#workers = [];\n\t\tthis.#workerByShardId.clear();\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic send(shardId: number, data: GatewaySendPayload) {\n\t\tconst worker = this.#workerByShardId.get(shardId);\n\t\tif (!worker) {\n\t\t\tthrow new Error(`No worker found for shard ${shardId}`);\n\t\t}\n\n\t\tconst payload: WorkerSendPayload = {\n\t\t\top: WorkerSendPayloadOp.Send,\n\t\t\tshardId,\n\t\t\tpayload: data,\n\t\t};\n\t\tworker.postMessage(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\tconst statuses = new Collection<number, WebSocketShardStatus>();\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst nonce = Math.random();\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.FetchStatus,\n\t\t\t\tshardId,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<WebSocketShardStatus>((resolve) => this.fetchStatusPromises.set(nonce, resolve));\n\t\t\tworker.postMessage(payload);\n\n\t\t\tconst status = await promise;\n\t\t\tstatuses.set(shardId, status);\n\t\t}\n\n\t\treturn statuses;\n\t}\n\n\tprivate async setupWorker(workerData: WorkerData) {\n\t\tconst worker = new Worker(this.resolveWorkerPath(), { workerData });\n\n\t\tawait once(worker, 'online');\n\t\t// We do this in case the user has any potentially long running code in their worker\n\t\tawait this.waitForWorkerReady(worker);\n\n\t\tworker\n\t\t\t.on('error', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerReceivePayload) => this.onMessage(worker, payload));\n\n\t\tthis.#workers.push(worker);\n\t\tfor (const shardId of workerData.shardIds) {\n\t\t\tthis.#workerByShardId.set(shardId, worker);\n\t\t}\n\t}\n\n\tprivate resolveWorkerPath(): string {\n\t\tconst path = this.options.workerPath;\n\n\t\tif (!path) {\n\t\t\treturn join(__dirname, 'defaultWorker.js');\n\t\t}\n\n\t\tif (isAbsolute(path)) {\n\t\t\treturn path;\n\t\t}\n\n\t\tif (/^\\.\\.?[/\\\\]/.test(path)) {\n\t\t\treturn resolve(path);\n\t\t}\n\n\t\ttry {\n\t\t\treturn require.resolve(path);\n\t\t} catch {\n\t\t\treturn resolve(path);\n\t\t}\n\t}\n\n\tprivate async waitForWorkerReady(worker: Worker): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst handler = (payload: WorkerReceivePayload) => {\n\t\t\t\tif (payload.op === WorkerReceivePayloadOp.WorkerReady) {\n\t\t\t\t\tresolve();\n\t\t\t\t\tworker.off('message', handler);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tworker.on('message', handler);\n\t\t});\n\t}\n\n\tprivate async onMessage(worker: Worker, payload: WorkerReceivePayload) {\n\t\tswitch (payload.op) {\n\t\t\tcase WorkerReceivePayloadOp.Connected: {\n\t\t\t\tthis.connectPromises.get(payload.shardId)?.();\n\t\t\t\tthis.connectPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Destroyed: {\n\t\t\t\tthis.destroyPromises.get(payload.shardId)?.();\n\t\t\t\tthis.destroyPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Event: {\n\t\t\t\tthis.manager.emit(payload.event, { ...payload.data, shardId: payload.shardId });\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.RetrieveSessionInfo: {\n\t\t\t\tconst session = await this.manager.options.retrieveSessionInfo(payload.shardId);\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.SessionInfoResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tsession,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.UpdateSessionInfo: {\n\t\t\t\tawait this.manager.options.updateSessionInfo(payload.shardId, payload.session);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WaitForIdentify: {\n\t\t\t\tconst throttler = await this.ensureThrottler();\n\n\t\t\t\t// If this rejects it means we aborted, in which case we reply elsewhere.\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.waitForIdentifyControllers.set(payload.nonce, controller);\n\t\t\t\t\tawait throttler.waitForIdentify(payload.shardId, controller.signal);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: true,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.FetchStatusResponse: {\n\t\t\t\tthis.fetchStatusPromises.get(payload.nonce)?.(payload.status);\n\t\t\t\tthis.fetchStatusPromises.delete(payload.nonce);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WorkerReady: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.CancelIdentify: {\n\t\t\t\tthis.waitForIdentifyControllers.get(payload.nonce)?.abort();\n\t\t\t\tthis.waitForIdentifyControllers.delete(payload.nonce);\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: false,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async ensureThrottler(): Promise<IIdentifyThrottler> {\n\t\tthis.throttler ??= await this.manager.options.buildIdentifyThrottler(this.manager);\n\t\treturn this.throttler;\n\t}\n}\n","import { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { WebSocketManager } from '../../ws/WebSocketManager.js';\nimport { WebSocketShard, WebSocketShardEvents, type WebSocketShardDestroyOptions } from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport { SimpleContextFetchingStrategy } from '../context/SimpleContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\n/**\n * Simple strategy that just spawns shards in the current process\n */\nexport class SimpleShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor(manager: WebSocketManager) {\n\t\tthis.manager = manager;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tfor (const shardId of shardIds) {\n\t\t\tconst strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions);\n\t\t\tconst shard = new WebSocketShard(strategy, shardId);\n\t\t\tfor (const event of Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Intentional\n\t\t\t\tshard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId }));\n\t\t\t}\n\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.connect());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.destroy(options));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t\tthis.shards.clear();\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic async send(shardId: number, payload: GatewaySendPayload) {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} not found`);\n\t\t}\n\n\t\treturn shard.send(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\treturn this.shards.mapValues((shard) => shard.status);\n\t}\n}\n","/* eslint-disable id-length */\nimport { Buffer } from 'node:buffer';\nimport { once } from 'node:events';\nimport { clearInterval, clearTimeout, setInterval, setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { URLSearchParams } from 'node:url';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayOpcodes,\n\ttype GatewayDispatchPayload,\n\ttype GatewayIdentifyData,\n\ttype GatewayReadyDispatchData,\n\ttype GatewayReceivePayload,\n\ttype GatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { WebSocket, type Data } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy.js';\nimport { ImportantGatewayOpcodes, getInitialSendRateLimitState } from '../utils/constants.js';\nimport type { SessionInfo } from './WebSocketManager.js';\n\n// eslint-disable-next-line promise/prefer-await-to-then\nconst getZlibSync = lazy(async () => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tClosed = 'closed',\n\tDebug = 'debug',\n\tDispatch = 'dispatch',\n\tError = 'error',\n\tHeartbeatComplete = 'heartbeat',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Closed]: [{ code: number }];\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n\t[WebSocketShardEvents.Error]: [payload: { error: Error }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [payload: { data: GatewayReadyDispatchData }];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.HeartbeatComplete]: [payload: { ackAt: number; heartbeatAt: number; latency: number }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\tcode?: number;\n\treason?: string;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1_000,\n\tResuming = 4_200,\n}\n\nexport interface SendRateLimitState {\n\tremaining: number;\n\tresetAt: number;\n}\n\n// TODO(vladfrangu): enable this once https://github.com/oven-sh/bun/issues/3392 is solved\n// const WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket()\n// \t? (globalThis as any).WebSocket\n// \t: WebSocket;\nconst WebSocketConstructor: typeof WebSocket = WebSocket;\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState: SendRateLimitState = getInitialSendRateLimitState();\n\n\tprivate initialHeartbeatTimeoutController: AbortController | null = null;\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\n\tprivate lastHeartbeatAt = -1;\n\n\t// Indicates whether the shard has already resolved its original connect() call\n\tprivate initialConnectResolved = false;\n\n\t// Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET)\n\tprivate failedToConnectDueToNetworkError = false;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeoutAbortControllers = new Collection<WebSocketShardEvents, AbortController>();\n\n\tprivate readonly strategy: IContextFetchingStrategy;\n\n\tpublic readonly id: number;\n\n\t#status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tpublic get status(): WebSocketShardStatus {\n\t\treturn this.#status;\n\t}\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tconst controller = new AbortController();\n\t\tlet promise;\n\n\t\tif (!this.initialConnectResolved) {\n\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\tpromise = Promise.race([\n\t\t\t\tonce(this, WebSocketShardEvents.Ready, { signal: controller.signal }),\n\t\t\t\tonce(this, WebSocketShardEvents.Resumed, { signal: controller.signal }),\n\t\t\t]);\n\t\t}\n\n\t\tvoid this.internalConnect();\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} catch ({ error }: any) {\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// cleanup hanging listeners\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.initialConnectResolved = true;\n\t}\n\n\tprivate async internalConnect() {\n\t\tif (this.#status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65_535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\n\t\tthis.debug([`Connecting to ${url}`]);\n\n\t\tconst connection = new WebSocketConstructor(url, {\n\t\t\thandshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined,\n\t\t});\n\n\t\tconnection.binaryType = 'arraybuffer';\n\n\t\tconnection.onmessage = (event) => {\n\t\t\tvoid this.onMessage(event.data, event.data instanceof ArrayBuffer);\n\t\t};\n\n\t\tconnection.onerror = (event) => {\n\t\t\tthis.onError(event.error);\n\t\t};\n\n\t\tconnection.onclose = (event) => {\n\t\t\tvoid this.onClose(event.code);\n\t\t};\n\n\t\tthis.connection = connection;\n\n\t\tthis.#status = WebSocketShardStatus.Connecting;\n\n\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\n\t\tconst { ok } = await this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\t\tif (!ok) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.#status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\n\t\tif (this.initialHeartbeatTimeoutController) {\n\t\t\tthis.initialHeartbeatTimeoutController.abort();\n\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t}\n\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\tfor (const controller of this.timeoutAbortControllers.values()) {\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.timeoutAbortControllers.clear();\n\n\t\tthis.failedToConnectDueToNetworkError = false;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume) {\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (this.connection) {\n\t\t\t// No longer need to listen to messages\n\t\t\tthis.connection.onmessage = null;\n\t\t\t// Prevent a reconnection loop by unbinding the main close event\n\t\t\tthis.connection.onclose = null;\n\n\t\t\tconst shouldClose = this.connection.readyState === WebSocket.OPEN;\n\n\t\t\tthis.debug([\n\t\t\t\t'Connection status during destroy',\n\t\t\t\t`Needs closing: ${shouldClose}`,\n\t\t\t\t`Ready state: ${this.connection.readyState}`,\n\t\t\t]);\n\n\t\t\tif (shouldClose) {\n\t\t\t\tlet outerResolve: () => void;\n\t\t\t\tconst promise = new Promise<void>((resolve) => {\n\t\t\t\t\touterResolve = resolve;\n\t\t\t\t});\n\n\t\t\t\tthis.connection.onclose = outerResolve!;\n\n\t\t\t\tthis.connection.close(options.code, options.reason);\n\n\t\t\t\tawait promise;\n\t\t\t\tthis.emit(WebSocketShardEvents.Closed, { code: options.code });\n\t\t\t}\n\n\t\t\t// Lastly, remove the error event.\n\t\t\t// Doing this earlier would cause a hard crash in case an error event fired on our `close` call\n\t\t\tthis.connection.onerror = null;\n\t\t} else {\n\t\t\tthis.debug(['Destroying a shard that has no connection; please open an issue on GitHub']);\n\t\t}\n\n\t\tthis.#status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\t// There's cases (like no internet connection) where we immediately fail to connect,\n\t\t\t// causing a very fast and draining reconnection loop.\n\t\t\tawait sleep(500);\n\t\t\treturn this.internalConnect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null): Promise<{ ok: boolean }> {\n\t\tthis.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst timeoutController = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => timeoutController.abort(), timeoutDuration).unref() : null;\n\n\t\tthis.timeoutAbortControllers.set(event, timeoutController);\n\n\t\tconst closeController = new AbortController();\n\n\t\ttry {\n\t\t\t// If the first promise resolves, all is well. If the 2nd promise resolves,\n\t\t\t// the shard has meanwhile closed. In that case, a destroy is already ongoing, so we just need to\n\t\t\t// return false. Meanwhile, if something rejects (error event) or the first controller is aborted,\n\t\t\t// we enter the catch block and trigger a destroy there.\n\t\t\tconst closed = await Promise.race<boolean>([\n\t\t\t\tonce(this, event, { signal: timeoutController.signal }).then(() => false),\n\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: closeController.signal }).then(() => true),\n\t\t\t]);\n\n\t\t\treturn { ok: !closed };\n\t\t} catch {\n\t\t\t// If we're here because of other reasons, we need to destroy the shard\n\t\t\tvoid this.destroy({\n\t\t\t\tcode: CloseCodes.Normal,\n\t\t\t\treason: 'Something timed out or went wrong while waiting for an event',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t});\n\n\t\t\treturn { ok: false };\n\t\t} finally {\n\t\t\tif (timeout) {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t}\n\n\t\t\tthis.timeoutAbortControllers.delete(event);\n\n\t\t\t// Clean up the close listener to not leak memory\n\t\t\tif (!closeController.signal.aborted) {\n\t\t\t\tcloseController.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload): Promise<void> {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.#status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tthis.debug(['Tried to send a non-crucial payload before the shard was ready, waiting']);\n\t\t\t// This will throw if the shard throws an error event in the meantime, just requeue the payload\n\t\t\ttry {\n\t\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t\t} catch {\n\t\t\t\treturn this.send(payload);\n\t\t\t}\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tconst now = Date.now();\n\n\t\t\tif (this.sendRateLimitState.resetAt > now) {\n\t\t\t\tconst sleepFor = this.sendRateLimitState.resetAt - now;\n\n\t\t\t\tthis.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]);\n\t\t\t\tconst controller = new AbortController();\n\n\t\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\t\tconst interrupted = await Promise.race([\n\t\t\t\t\tsleep(sleepFor).then(() => false),\n\t\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: controller.signal }).then(() => true),\n\t\t\t\t]);\n\n\t\t\t\tif (interrupted) {\n\t\t\t\t\tthis.debug(['Connection closed while waiting for the send rate limit to reset, re-queueing payload']);\n\t\t\t\t\tthis.sendQueue.shift();\n\t\t\t\t\treturn this.send(payload);\n\t\t\t\t}\n\n\t\t\t\t// This is so the listener from the `once` call is removed\n\t\t\t\tcontroller.abort();\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug(['Waiting for identify throttle']);\n\n\t\tconst controller = new AbortController();\n\t\tconst closeHandler = () => {\n\t\t\tcontroller.abort();\n\t\t};\n\n\t\tthis.on(WebSocketShardEvents.Closed, closeHandler);\n\n\t\ttry {\n\t\t\tawait this.strategy.waitForIdentify(this.id, controller.signal);\n\t\t} catch {\n\t\t\tif (controller.signal.aborted) {\n\t\t\t\tthis.debug(['Was waiting for an identify, but the shard closed in the meantime']);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.debug([\n\t\t\t\t'IContextFetchingStrategy#waitForIdentify threw an unknown error.',\n\t\t\t\t\"If you're using a custom strategy, this is probably nothing to worry about.\",\n\t\t\t\t\"If you're not, please open an issue on GitHub.\",\n\t\t\t]);\n\n\t\t\tawait this.destroy({\n\t\t\t\treason: 'Identify throttling logic failed',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.off(WebSocketShardEvents.Closed, closeHandler);\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t}\n\n\tprivate async resume(session: SessionInfo) {\n\t\tthis.debug([\n\t\t\t'Resuming session',\n\t\t\t`resume url: ${session.resumeURL}`,\n\t\t\t`sequence: ${session.sequence}`,\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t]);\n\n\t\tthis.#status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Data, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(data as string) as GatewayReceivePayload;\n\t\t\t} catch {\n\t\t\t\t// This is a non-JSON payload / (at the time of writing this comment) emitted by bun wrongly interpreting custom close codes https://github.com/oven-sh/bun/issues/3392\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tconst decompressable = new Uint8Array(data as ArrayBuffer);\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\t\t\t\tinflate(decompressable, { chunkSize: 65_535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: Data, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.#status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line sonarjs/no-nested-switch\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\n\t\t\t\t\t\tconst session = {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, session);\n\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready, { data: payload.d });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (session) {\n\t\t\t\t\tif (payload.s > session.sequence) {\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.debug([\n\t\t\t\t\t\t`Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect`,\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tconst jitter = Math.random();\n\t\t\t\tconst firstWait = Math.floor(payload.d.heartbeat_interval * jitter);\n\t\t\t\tthis.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]);\n\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = controller;\n\t\t\t\t\tawait sleep(firstWait, undefined, { signal: controller.signal });\n\t\t\t\t} catch {\n\t\t\t\t\tthis.debug(['Cancelled initial heartbeat due to #destroy being called']);\n\t\t\t\t\treturn;\n\t\t\t\t} finally {\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t\t\t}\n\n\t\t\t\tawait this.heartbeat();\n\n\t\t\t\tthis.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\n\t\t\t\tconst ackAt = Date.now();\n\t\t\t\tthis.emit(WebSocketShardEvents.HeartbeatComplete, {\n\t\t\t\t\tackAt,\n\t\t\t\t\theartbeatAt: this.lastHeartbeatAt,\n\t\t\t\t\tlatency: ackAt - this.lastHeartbeatAt,\n\t\t\t\t});\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(error: Error) {\n\t\tif ('code' in error && ['ECONNRESET', 'ECONNREFUSED'].includes(error.code as string)) {\n\t\t\tthis.debug(['Failed to connect to the gateway URL specified due to a network error']);\n\t\t\tthis.failedToConnectDueToNetworkError = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.emit(WebSocketShardEvents.Error, { error });\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tthis.emit(WebSocketShardEvents.Closed, { code });\n\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occurred: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Authentication failed'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Invalid shard'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Sharding is required'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used an invalid API version'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used invalid intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used disallowed intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([\n\t\t\t\t\t`The gateway closed with an unexpected code ${code}, attempting to ${\n\t\t\t\t\t\tthis.failedToConnectDueToNetworkError ? 'reconnect' : 'resume'\n\t\t\t\t\t}.`,\n\t\t\t\t]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\trecover: this.failedToConnectDueToNetworkError\n\t\t\t\t\t\t? WebSocketShardDestroyRecovery.Reconnect\n\t\t\t\t\t\t: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n","import process from 'node:process';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { APIVersion, GatewayOpcodes } from 'discord-api-types/v10';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy.js';\nimport { SimpleIdentifyThrottler } from '../throttling/SimpleIdentifyThrottler.js';\nimport type { SessionInfo, OptionalWebSocketManagerOptions, WebSocketManager } from '../ws/WebSocketManager.js';\nimport type { SendRateLimitState } from '../ws/WebSocketShard.js';\n\n/**\n * Valid encoding types\n */\nexport enum Encoding {\n\tJSON = 'json',\n}\n\n/**\n * Valid compression methods\n */\nexport enum CompressionMethod {\n\tZlibStream = 'zlib-stream',\n}\n\nexport const DefaultDeviceProperty = `@discordjs/ws 1.0.1` as `@discordjs/ws ${string}`;\n\nconst getDefaultSessionStore = lazy(() => new Collection<number, SessionInfo | null>());\n\n/**\n * Default options used by the manager\n */\nexport const DefaultWebSocketManagerOptions = {\n\tasync buildIdentifyThrottler(manager: WebSocketManager) {\n\t\tconst info = await manager.fetchGatewayInformation();\n\t\treturn new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency);\n\t},\n\tbuildStrategy: (manager) => new SimpleShardingStrategy(manager),\n\tshardCount: null,\n\tshardIds: null,\n\tlargeThreshold: null,\n\tinitialPresence: null,\n\tidentifyProperties: {\n\t\tbrowser: DefaultDeviceProperty,\n\t\tdevice: DefaultDeviceProperty,\n\t\tos: process.platform,\n\t},\n\tversion: APIVersion,\n\tencoding: Encoding.JSON,\n\tcompression: null,\n\tretrieveSessionInfo(shardId) {\n\t\tconst store = getDefaultSessionStore();\n\t\treturn store.get(shardId) ?? null;\n\t},\n\tupdateSessionInfo(shardId: number, info: SessionInfo | null) {\n\t\tconst store = getDefaultSessionStore();\n\t\tif (info) {\n\t\t\tstore.set(shardId, info);\n\t\t} else {\n\t\t\tstore.delete(shardId);\n\t\t}\n\t},\n\thandshakeTimeout: 30_000,\n\thelloTimeout: 60_000,\n\treadyTimeout: 15_000,\n} as const satisfies OptionalWebSocketManagerOptions;\n\nexport const ImportantGatewayOpcodes = new Set([\n\tGatewayOpcodes.Heartbeat,\n\tGatewayOpcodes.Identify,\n\tGatewayOpcodes.Resume,\n]);\n\nexport function getInitialSendRateLimitState(): SendRateLimitState {\n\treturn {\n\t\tremaining: 120,\n\t\tresetAt: Date.now() + 60_000,\n\t};\n}\n","import { setTimeout as sleep } from 'node:timers/promises';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport type { IIdentifyThrottler } from './IIdentifyThrottler.js';\n\n/**\n * The state of a rate limit key's identify queue.\n */\nexport interface IdentifyState {\n\tqueue: AsyncQueue;\n\tresetsAt: number;\n}\n\n/**\n * Local, in-memory identify throttler.\n */\nexport class SimpleIdentifyThrottler implements IIdentifyThrottler {\n\tprivate readonly states = new Collection<number, IdentifyState>();\n\n\tpublic constructor(private readonly maxConcurrency: number) {}\n\n\t/**\n\t * {@inheritDoc IIdentifyThrottler.waitForIdentify}\n\t */\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst key = shardId % this.maxConcurrency;\n\n\t\tconst state = this.states.ensure(key, () => {\n\t\t\treturn {\n\t\t\t\tqueue: new AsyncQueue(),\n\t\t\t\tresetsAt: Number.POSITIVE_INFINITY,\n\t\t\t};\n\t\t});\n\n\t\tawait state.queue.wait({ signal });\n\n\t\ttry {\n\t\t\tconst diff = state.resetsAt - Date.now();\n\t\t\tif (diff <= 5_000) {\n\t\t\t\t// To account for the latency the IDENTIFY payload goes through, we add a bit more wait time\n\t\t\t\tconst time = diff + Math.random() * 1_500;\n\t\t\t\tawait sleep(time);\n\t\t\t}\n\n\t\t\tstate.resetsAt = Date.now() + 5_000;\n\t\t} finally {\n\t\t\tstate.queue.shift();\n\t\t}\n\t}\n}\n","import { isMainThread, parentPort, workerData } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { Awaitable } from '@discordjs/util';\nimport { WorkerContextFetchingStrategy } from '../strategies/context/WorkerContextFetchingStrategy.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerData,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../strategies/sharding/WorkerShardingStrategy.js';\nimport type { WebSocketShardDestroyOptions } from '../ws/WebSocketShard.js';\nimport { WebSocketShardEvents, WebSocketShard } from '../ws/WebSocketShard.js';\n\n/**\n * Options for bootstrapping the worker\n */\nexport interface BootstrapOptions {\n\t/**\n\t * Shard events to just arbitrarily forward to the parent thread for the manager to emit\n\t * Note: By default, this will include ALL events\n\t * you most likely want to handle dispatch within the worker itself\n\t */\n\tforwardEvents?: WebSocketShardEvents[];\n\t/**\n\t * Function to call when a shard is created for additional setup\n\t */\n\tshardCallback?(shard: WebSocketShard): Awaitable<void>;\n}\n\n/**\n * Utility class for bootstrapping a worker thread to be used for sharding\n */\nexport class WorkerBootstrapper {\n\t/**\n\t * The data passed to the worker thread\n\t */\n\tprotected readonly data = workerData as WorkerData;\n\n\t/**\n\t * The shards that are managed by this worker\n\t */\n\tprotected readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor() {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Expected WorkerBootstrap to not be used within the main thread');\n\t\t}\n\t}\n\n\t/**\n\t * Helper method to initiate a shard's connection process\n\t */\n\tprotected async connect(shardId: number): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.connect();\n\t}\n\n\t/**\n\t * Helper method to destroy a shard\n\t */\n\tprotected async destroy(shardId: number, options?: WebSocketShardDestroyOptions): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.destroy(options);\n\t}\n\n\t/**\n\t * Helper method to attach event listeners to the parentPort\n\t */\n\tprotected setupThreadEvents(): void {\n\t\tparentPort!\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerSendPayload) => {\n\t\t\t\tswitch (payload.op) {\n\t\t\t\t\tcase WorkerSendPayloadOp.Connect: {\n\t\t\t\t\t\tawait this.connect(payload.shardId);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Connected,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Destroy: {\n\t\t\t\t\t\tawait this.destroy(payload.shardId, payload.options);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Destroyed,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Send: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new RangeError(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait shard.send(payload.payload);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.SessionInfoResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.ShardIdentifyResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.FetchStatus: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new Error(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.FetchStatusResponse,\n\t\t\t\t\t\t\tstatus: shard.status,\n\t\t\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\t/**\n\t * Bootstraps the worker thread with the provided options\n\t */\n\tpublic async bootstrap(options: Readonly<BootstrapOptions> = {}): Promise<void> {\n\t\t// Start by initializing the shards\n\t\tfor (const shardId of this.data.shardIds) {\n\t\t\tconst shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId);\n\t\t\tfor (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Event types incompatible\n\t\t\t\tshard.on(event, (data) => {\n\t\t\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\t\t\top: WorkerReceivePayloadOp.Event,\n\t\t\t\t\t\tevent,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tshardId,\n\t\t\t\t\t};\n\t\t\t\t\tparentPort!.postMessage(payload);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Any additional setup the user might want to do\n\t\t\tawait options.shardCallback?.(shard);\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\n\t\t// Lastly, start listening to messages from the parent thread\n\t\tthis.setupThreadEvents();\n\n\t\tconst message: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WorkerReady,\n\t\t};\n\t\tparentPort!.postMessage(message);\n\t}\n}\n","import type { REST } from '@discordjs/rest';\nimport { range, type Awaitable } from '@discordjs/util';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tRoutes,\n\ttype APIGatewayBotInfo,\n\ttype GatewayIdentifyProperties,\n\ttype GatewayPresenceUpdateData,\n\ttype RESTGetAPIGatewayBotResult,\n\ttype GatewayIntentBits,\n\ttype GatewaySendPayload,\n} from 'discord-api-types/v10';\nimport type { IShardingStrategy } from '../strategies/sharding/IShardingStrategy.js';\nimport type { IIdentifyThrottler } from '../throttling/IIdentifyThrottler.js';\nimport { DefaultWebSocketManagerOptions, type CompressionMethod, type Encoding } from '../utils/constants.js';\nimport type { WebSocketShardDestroyOptions, WebSocketShardEventsMap } from './WebSocketShard.js';\n\n/**\n * Represents a range of shard ids\n */\nexport interface ShardRange {\n\tend: number;\n\tstart: number;\n}\n\n/**\n * Session information for a given shard, used to resume a session\n */\nexport interface SessionInfo {\n\t/**\n\t * URL to use when resuming\n\t */\n\tresumeURL: string;\n\t/**\n\t * The sequence number of the last message sent by the shard\n\t */\n\tsequence: number;\n\t/**\n\t * Session id for this shard\n\t */\n\tsessionId: string;\n\t/**\n\t * The total number of shards at the time of this shard identifying\n\t */\n\tshardCount: number;\n\t/**\n\t * The id of the shard\n\t */\n\tshardId: number;\n}\n\n/**\n * Required options for the WebSocketManager\n */\nexport interface RequiredWebSocketManagerOptions {\n\t/**\n\t * The intents to request\n\t */\n\tintents: GatewayIntentBits | 0;\n\t/**\n\t * The REST instance to use for fetching gateway information\n\t */\n\trest: REST;\n\t/**\n\t * The token to use for identifying with the gateway\n\t */\n\ttoken: string;\n}\n\n/**\n * Optional additional configuration for the WebSocketManager\n */\nexport interface OptionalWebSocketManagerOptions {\n\t/**\n\t * Builds an identify throttler to use for this manager's shards\n\t */\n\tbuildIdentifyThrottler(manager: WebSocketManager): Awaitable<IIdentifyThrottler>;\n\t/**\n\t * Builds the strategy to use for sharding\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * token: process.env.DISCORD_TOKEN,\n\t * intents: 0, // for no intents\n\t * rest,\n\t * buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 }),\n\t * });\n\t * ```\n\t */\n\tbuildStrategy(manager: WebSocketManager): IShardingStrategy;\n\t/**\n\t * The compression method to use\n\t *\n\t * @defaultValue `null` (no compression)\n\t */\n\tcompression: CompressionMethod | null;\n\t/**\n\t * The encoding to use\n\t *\n\t * @defaultValue `'json'`\n\t */\n\tencoding: Encoding;\n\t/**\n\t * How long to wait for a shard to connect before giving up\n\t */\n\thandshakeTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's HELLO packet before giving up\n\t */\n\thelloTimeout: number | null;\n\t/**\n\t * Properties to send to the gateway when identifying\n\t */\n\tidentifyProperties: GatewayIdentifyProperties;\n\t/**\n\t * Initial presence data to send to the gateway when identifying\n\t */\n\tinitialPresence: GatewayPresenceUpdateData | null;\n\t/**\n\t * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list\n\t */\n\tlargeThreshold: number | null;\n\t/**\n\t * How long to wait for a shard's READY packet before giving up\n\t */\n\treadyTimeout: number | null;\n\t/**\n\t * Function used to retrieve session information (and attempt to resume) for a given shard\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {\n\t * // Fetch this info from redis or similar\n\t * return { sessionId: string, sequence: number };\n\t * // Return null if no information is found\n\t * },\n\t * });\n\t * ```\n\t */\n\tretrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>;\n\t/**\n\t * The total number of shards across all WebsocketManagers you intend to instantiate.\n\t * Use `null` to use Discord's recommended shard count\n\t */\n\tshardCount: number | null;\n\t/**\n\t * The ids of the shards this WebSocketManager should manage.\n\t * Use `null` to simply spawn 0 through `shardCount - 1`\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else\n\t * });\n\t * ```\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: {\n\t * start: 3,\n\t * end: 6,\n\t * }, // spawns shards 3, 4, 5, and 6\n\t * });\n\t * ```\n\t */\n\tshardIds: number[] | ShardRange | null;\n\t/**\n\t * Function used to store session information for a given shard\n\t */\n\tupdateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>;\n\t/**\n\t * The gateway version to use\n\t *\n\t * @defaultValue `'10'`\n\t */\n\tversion: string;\n}\n\nexport type WebSocketManagerOptions = OptionalWebSocketManagerOptions & RequiredWebSocketManagerOptions;\n\nexport type ManagerShardEventsMap = {\n\t[K in keyof WebSocketShardEventsMap]: [\n\t\tWebSocketShardEventsMap[K] extends [] ? { shardId: number } : WebSocketShardEventsMap[K][0] & { shardId: number },\n\t];\n};\n\nexport class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {\n\t/**\n\t * The options being used by this manager\n\t */\n\tpublic readonly options: WebSocketManagerOptions;\n\n\t/**\n\t * Internal cache for a GET /gateway/bot result\n\t */\n\tprivate gatewayInformation: {\n\t\tdata: APIGatewayBotInfo;\n\t\texpiresAt: number;\n\t} | null = null;\n\n\t/**\n\t * Internal cache for the shard ids\n\t */\n\tprivate shardIds: number[] | null = null;\n\n\t/**\n\t * Strategy used to manage shards\n\t *\n\t * @defaultValue `SimpleShardingStrategy`\n\t */\n\tprivate readonly strategy: IShardingStrategy;\n\n\tpublic constructor(options: Partial<OptionalWebSocketManagerOptions> & RequiredWebSocketManagerOptions) {\n\t\tsuper();\n\t\tthis.options = { ...DefaultWebSocketManagerOptions, ...options };\n\t\tthis.strategy = this.options.buildStrategy(this);\n\t}\n\n\t/**\n\t * Fetches the gateway information from Discord - or returns it from cache if available\n\t *\n\t * @param force - Whether to ignore the cache and force a fresh fetch\n\t */\n\tpublic async fetchGatewayInformation(force = false) {\n\t\tif (this.gatewayInformation) {\n\t\t\tif (this.gatewayInformation.expiresAt <= Date.now()) {\n\t\t\t\tthis.gatewayInformation = null;\n\t\t\t} else if (!force) {\n\t\t\t\treturn this.gatewayInformation.data;\n\t\t\t}\n\t\t}\n\n\t\tconst data = (await this.options.rest.get(Routes.gatewayBot())) as RESTGetAPIGatewayBotResult;\n\n\t\t// For single sharded bots session_start_limit.reset_after will be 0, use 5 seconds as a minimum expiration time\n\t\tthis.gatewayInformation = { data, expiresAt: Date.now() + (data.session_start_limit.reset_after || 5_000) };\n\t\treturn this.gatewayInformation.data;\n\t}\n\n\t/**\n\t * Updates your total shard count on-the-fly, spawning shards as needed\n\t *\n\t * @param shardCount - The new shard count to use\n\t */\n\tpublic async updateShardCount(shardCount: number | null) {\n\t\tawait this.strategy.destroy({ reason: 'User is adjusting their shards' });\n\t\tthis.options.shardCount = shardCount;\n\n\t\tconst shardIds = await this.getShardIds(true);\n\t\tawait this.strategy.spawn(shardIds);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Yields the total number of shards across for your bot, accounting for Discord recommendations\n\t */\n\tpublic async getShardCount(): Promise<number> {\n\t\tif (this.options.shardCount) {\n\t\t\treturn this.options.shardCount;\n\t\t}\n\n\t\tconst shardIds = await this.getShardIds();\n\t\treturn Math.max(...shardIds) + 1;\n\t}\n\n\t/**\n\t * Yields the ids of the shards this manager should manage\n\t */\n\tpublic async getShardIds(force = false): Promise<number[]> {\n\t\tif (this.shardIds && !force) {\n\t\t\treturn this.shardIds;\n\t\t}\n\n\t\tlet shardIds: number[];\n\t\tif (this.options.shardIds) {\n\t\t\tif (Array.isArray(this.options.shardIds)) {\n\t\t\t\tshardIds = this.options.shardIds;\n\t\t\t} else {\n\t\t\t\tconst { start, end } = this.options.shardIds;\n\t\t\t\tshardIds = [...range({ start, end: end + 1 })];\n\t\t\t}\n\t\t} else {\n\t\t\tconst data = await this.fetchGatewayInformation();\n\t\t\tshardIds = [...range(this.options.shardCount ?? data.shards)];\n\t\t}\n\n\t\tthis.shardIds = shardIds;\n\t\treturn shardIds;\n\t}\n\n\tpublic async connect() {\n\t\tconst shardCount = await this.getShardCount();\n\n\t\tconst data = await this.fetchGatewayInformation();\n\t\tif (data.session_start_limit.remaining < shardCount) {\n\t\t\tthrow new Error(\n\t\t\t\t`Not enough sessions remaining to spawn ${shardCount} shards; only ${\n\t\t\t\t\tdata.session_start_limit.remaining\n\t\t\t\t} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`,\n\t\t\t);\n\t\t}\n\n\t\t// First, make sure all our shards are spawned\n\t\tawait this.updateShardCount(shardCount);\n\t\tawait this.strategy.connect();\n\t}\n\n\tpublic destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\treturn this.strategy.destroy(options);\n\t}\n\n\tpublic send(shardId: number, payload: GatewaySendPayload) {\n\t\treturn this.strategy.send(shardId, payload);\n\t}\n\n\tpublic fetchStatus() {\n\t\treturn this.strategy.fetchStatus();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkCA,eAAsB,iCAAiC,SAA6D;AAEnH,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACJ,IAAI,QAAQ;AAGZ,SAAO;AAAA,IACN,GAAG;AAAA,IACH,oBAAoB,MAAM,QAAQ,wBAAwB;AAAA,IAC1D,YAAY,MAAM,QAAQ,cAAc;AAAA,EACzC;AACD;AAnBsB;;;AC9Bf,IAAM,gCAAN,MAAM,+BAAkE;AAAA,EAiBvE,YAA6B,SAA2C,SAAkC;AAA7E;AAA2C;AAAA,EAAmC;AAAA,EArBnH,OAI+E;AAAA;AAAA;AAAA;AAAA;AAAA,EAG9E,OAAe,iBAAiB,oBAAI,QAA8C;AAAA,EAElF,aAAqB,gBAAgB,SAAwD;AAC5F,UAAM,YAAY,+BAA8B,eAAe,IAAI,OAAO;AAC1E,QAAI,WAAW;AACd,aAAO;AAAA,IACR;AAEA,UAAM,eAAe,MAAM,QAAQ,QAAQ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,MAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;AACzC,mBAAW,KAAK,QAAQ;AAAA,MACzB,OAAO;AACN,cAAM,EAAE,OAAO,IAAI,IAAI,KAAK,QAAQ;AACpC,mBAAW,CAAC,OAAG,oBAAM,EAAE,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC;AAAA,MAC9C;AAAA,IACD,OAAO;AACN,YAAM,OAAO,MAAM,KAAK,wBAAwB;AAChD,iBAAW,CAAC,OAAG,oBAAM,KAAK,QAAQ,cAAc,KAAK,MAAM,CAAC;AAAA,IAC7D;AAEA,SAAK,WAAW;AAChB,WAAO;AAAA,EACR;AAAA,EAEA,MAAa,UAAU;AACtB,UAAM,aAAa,MAAM,KAAK,cAAc;AAE5C,UAAM,OAAO,MAAM,KAAK,wBAAwB;AAChD,QAAI,KAAK,oBAAoB,YAAY,YAAY;AACpD,YAAM,IAAI;AAAA,QACT,0CAA0C,UAAU,iBACnD,KAAK,oBAAoB,SAC1B,yBAAyB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,oBAAoB,WAAW,EAAE,YAAY,CAAC;AAAA,MACnG;AAAA,IACD;AAGA,UAAM,KAAK,iBAAiB,UAAU;AACtC,UAAM,KAAK,SAAS,QAAQ;AAAA,EAC7B;AAAA,EAEO,QAAQ,SAAyD;AACvE,WAAO,KAAK,SAAS,QAAQ,OAAO;AAAA,EACrC;AAAA,EAEO,KAAK,SAAiB,SAA6B;AACzD,WAAO,KAAK,SAAS,KAAK,SAAS,OAAO;AAAA,EAC3C;AAAA,EAEO,cAAc;AACpB,WAAO,KAAK,SAAS,YAAY;AAAA,EAClC;AACD;;;AV3SO,IAAM,UAAU;","names":["import_node_worker_threads","import_collection","WorkerSendPayloadOp","WorkerReceivePayloadOp","workerData","resolve","resolve","payload","import_collection","import_node_events","import_promises","import_collection","import_util","import_async_queue","import_v10","import_collection","import_collection","sleep","Encoding","CompressionMethod","process","WebSocketShardEvents","WebSocketShardStatus","WebSocketShardDestroyRecovery","CloseCodes","version","resolve","sleep","session","import_node_worker_threads","import_collection","import_util","import_async_event_emitter","import_v10"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/dist/index.mjs b/node_modules/@discordjs/ws/dist/index.mjs new file mode 100644 index 0000000..56e44e6 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/index.mjs @@ -0,0 +1,1446 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") + return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); + +// ../../node_modules/tsup/assets/esm_shims.js +import { fileURLToPath } from "url"; +import path from "path"; +var getFilename = /* @__PURE__ */ __name(() => fileURLToPath(import.meta.url), "getFilename"); +var getDirname = /* @__PURE__ */ __name(() => path.dirname(getFilename()), "getDirname"); +var __dirname = /* @__PURE__ */ getDirname(); + +// src/strategies/context/IContextFetchingStrategy.ts +async function managerToFetchingStrategyOptions(manager) { + const { + buildIdentifyThrottler, + buildStrategy, + retrieveSessionInfo, + updateSessionInfo, + shardCount, + shardIds, + rest, + ...managerOptions + } = manager.options; + return { + ...managerOptions, + gatewayInformation: await manager.fetchGatewayInformation(), + shardCount: await manager.getShardCount() + }; +} +__name(managerToFetchingStrategyOptions, "managerToFetchingStrategyOptions"); + +// src/strategies/context/SimpleContextFetchingStrategy.ts +var SimpleContextFetchingStrategy = class _SimpleContextFetchingStrategy { + constructor(manager, options) { + this.manager = manager; + this.options = options; + } + static { + __name(this, "SimpleContextFetchingStrategy"); + } + // This strategy assumes every shard is running under the same process - therefore we need a single + // IdentifyThrottler per manager. + static throttlerCache = /* @__PURE__ */ new WeakMap(); + static async ensureThrottler(manager) { + const throttler = _SimpleContextFetchingStrategy.throttlerCache.get(manager); + if (throttler) { + return throttler; + } + const newThrottler = await manager.options.buildIdentifyThrottler(manager); + _SimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler); + return newThrottler; + } + async retrieveSessionInfo(shardId) { + return this.manager.options.retrieveSessionInfo(shardId); + } + updateSessionInfo(shardId, sessionInfo) { + return this.manager.options.updateSessionInfo(shardId, sessionInfo); + } + async waitForIdentify(shardId, signal) { + const throttler = await _SimpleContextFetchingStrategy.ensureThrottler(this.manager); + await throttler.waitForIdentify(shardId, signal); + } +}; + +// src/strategies/context/WorkerContextFetchingStrategy.ts +import { isMainThread, parentPort } from "node:worker_threads"; +import { Collection as Collection2 } from "@discordjs/collection"; + +// src/strategies/sharding/WorkerShardingStrategy.ts +import { once } from "node:events"; +import { join, isAbsolute, resolve } from "node:path"; +import { Worker } from "node:worker_threads"; +import { Collection } from "@discordjs/collection"; +var WorkerSendPayloadOp = /* @__PURE__ */ ((WorkerSendPayloadOp2) => { + WorkerSendPayloadOp2[WorkerSendPayloadOp2["Connect"] = 0] = "Connect"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["Destroy"] = 1] = "Destroy"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["Send"] = 2] = "Send"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["SessionInfoResponse"] = 3] = "SessionInfoResponse"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["ShardIdentifyResponse"] = 4] = "ShardIdentifyResponse"; + WorkerSendPayloadOp2[WorkerSendPayloadOp2["FetchStatus"] = 5] = "FetchStatus"; + return WorkerSendPayloadOp2; +})(WorkerSendPayloadOp || {}); +var WorkerReceivePayloadOp = /* @__PURE__ */ ((WorkerReceivePayloadOp2) => { + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["Connected"] = 0] = "Connected"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["Destroyed"] = 1] = "Destroyed"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["Event"] = 2] = "Event"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["RetrieveSessionInfo"] = 3] = "RetrieveSessionInfo"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["UpdateSessionInfo"] = 4] = "UpdateSessionInfo"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["WaitForIdentify"] = 5] = "WaitForIdentify"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["FetchStatusResponse"] = 6] = "FetchStatusResponse"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["WorkerReady"] = 7] = "WorkerReady"; + WorkerReceivePayloadOp2[WorkerReceivePayloadOp2["CancelIdentify"] = 8] = "CancelIdentify"; + return WorkerReceivePayloadOp2; +})(WorkerReceivePayloadOp || {}); +var WorkerShardingStrategy = class { + static { + __name(this, "WorkerShardingStrategy"); + } + manager; + options; + #workers = []; + #workerByShardId = new Collection(); + connectPromises = new Collection(); + destroyPromises = new Collection(); + fetchStatusPromises = new Collection(); + waitForIdentifyControllers = new Collection(); + throttler; + constructor(manager, options) { + this.manager = manager; + this.options = options; + } + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + async spawn(shardIds) { + const shardsPerWorker = this.options.shardsPerWorker === "all" ? shardIds.length : this.options.shardsPerWorker; + const strategyOptions = await managerToFetchingStrategyOptions(this.manager); + const loops = Math.ceil(shardIds.length / shardsPerWorker); + const promises = []; + for (let idx = 0; idx < loops; idx++) { + const slice = shardIds.slice(idx * shardsPerWorker, (idx + 1) * shardsPerWorker); + const workerData2 = { + ...strategyOptions, + shardIds: slice + }; + promises.push(this.setupWorker(workerData2)); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.connect} + */ + async connect() { + const promises = []; + for (const [shardId, worker] of this.#workerByShardId.entries()) { + const payload = { + op: 0 /* Connect */, + shardId + }; + const promise = new Promise((resolve2) => this.connectPromises.set(shardId, resolve2)); + worker.postMessage(payload); + promises.push(promise); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + async destroy(options = {}) { + const promises = []; + for (const [shardId, worker] of this.#workerByShardId.entries()) { + const payload = { + op: 1 /* Destroy */, + shardId, + options + }; + promises.push( + // eslint-disable-next-line no-promise-executor-return, promise/prefer-await-to-then + new Promise((resolve2) => this.destroyPromises.set(shardId, resolve2)).then(async () => worker.terminate()) + ); + worker.postMessage(payload); + } + this.#workers = []; + this.#workerByShardId.clear(); + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.send} + */ + send(shardId, data) { + const worker = this.#workerByShardId.get(shardId); + if (!worker) { + throw new Error(`No worker found for shard ${shardId}`); + } + const payload = { + op: 2 /* Send */, + shardId, + payload: data + }; + worker.postMessage(payload); + } + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + async fetchStatus() { + const statuses = new Collection(); + for (const [shardId, worker] of this.#workerByShardId.entries()) { + const nonce = Math.random(); + const payload = { + op: 5 /* FetchStatus */, + shardId, + nonce + }; + const promise = new Promise((resolve2) => this.fetchStatusPromises.set(nonce, resolve2)); + worker.postMessage(payload); + const status = await promise; + statuses.set(shardId, status); + } + return statuses; + } + async setupWorker(workerData2) { + const worker = new Worker(this.resolveWorkerPath(), { workerData: workerData2 }); + await once(worker, "online"); + await this.waitForWorkerReady(worker); + worker.on("error", (err) => { + throw err; + }).on("messageerror", (err) => { + throw err; + }).on("message", async (payload) => this.onMessage(worker, payload)); + this.#workers.push(worker); + for (const shardId of workerData2.shardIds) { + this.#workerByShardId.set(shardId, worker); + } + } + resolveWorkerPath() { + const path2 = this.options.workerPath; + if (!path2) { + return join(__dirname, "defaultWorker.js"); + } + if (isAbsolute(path2)) { + return path2; + } + if (/^\.\.?[/\\]/.test(path2)) { + return resolve(path2); + } + try { + return __require.resolve(path2); + } catch { + return resolve(path2); + } + } + async waitForWorkerReady(worker) { + return new Promise((resolve2) => { + const handler = /* @__PURE__ */ __name((payload) => { + if (payload.op === 7 /* WorkerReady */) { + resolve2(); + worker.off("message", handler); + } + }, "handler"); + worker.on("message", handler); + }); + } + async onMessage(worker, payload) { + switch (payload.op) { + case 0 /* Connected */: { + this.connectPromises.get(payload.shardId)?.(); + this.connectPromises.delete(payload.shardId); + break; + } + case 1 /* Destroyed */: { + this.destroyPromises.get(payload.shardId)?.(); + this.destroyPromises.delete(payload.shardId); + break; + } + case 2 /* Event */: { + this.manager.emit(payload.event, { ...payload.data, shardId: payload.shardId }); + break; + } + case 3 /* RetrieveSessionInfo */: { + const session = await this.manager.options.retrieveSessionInfo(payload.shardId); + const response = { + op: 3 /* SessionInfoResponse */, + nonce: payload.nonce, + session + }; + worker.postMessage(response); + break; + } + case 4 /* UpdateSessionInfo */: { + await this.manager.options.updateSessionInfo(payload.shardId, payload.session); + break; + } + case 5 /* WaitForIdentify */: { + const throttler = await this.ensureThrottler(); + try { + const controller = new AbortController(); + this.waitForIdentifyControllers.set(payload.nonce, controller); + await throttler.waitForIdentify(payload.shardId, controller.signal); + } catch { + return; + } + const response = { + op: 4 /* ShardIdentifyResponse */, + nonce: payload.nonce, + ok: true + }; + worker.postMessage(response); + break; + } + case 6 /* FetchStatusResponse */: { + this.fetchStatusPromises.get(payload.nonce)?.(payload.status); + this.fetchStatusPromises.delete(payload.nonce); + break; + } + case 7 /* WorkerReady */: { + break; + } + case 8 /* CancelIdentify */: { + this.waitForIdentifyControllers.get(payload.nonce)?.abort(); + this.waitForIdentifyControllers.delete(payload.nonce); + const response = { + op: 4 /* ShardIdentifyResponse */, + nonce: payload.nonce, + ok: false + }; + worker.postMessage(response); + break; + } + } + } + async ensureThrottler() { + this.throttler ??= await this.manager.options.buildIdentifyThrottler(this.manager); + return this.throttler; + } +}; + +// src/strategies/context/WorkerContextFetchingStrategy.ts +var WorkerContextFetchingStrategy = class { + constructor(options) { + this.options = options; + if (isMainThread) { + throw new Error("Cannot instantiate WorkerContextFetchingStrategy on the main thread"); + } + parentPort.on("message", (payload) => { + if (payload.op === 3 /* SessionInfoResponse */) { + this.sessionPromises.get(payload.nonce)?.(payload.session); + this.sessionPromises.delete(payload.nonce); + } + if (payload.op === 4 /* ShardIdentifyResponse */) { + const promise = this.waitForIdentifyPromises.get(payload.nonce); + if (payload.ok) { + promise?.resolve(); + } else { + promise?.reject(promise.signal.reason); + } + this.waitForIdentifyPromises.delete(payload.nonce); + } + }); + } + static { + __name(this, "WorkerContextFetchingStrategy"); + } + sessionPromises = new Collection2(); + waitForIdentifyPromises = new Collection2(); + async retrieveSessionInfo(shardId) { + const nonce = Math.random(); + const payload = { + op: 3 /* RetrieveSessionInfo */, + shardId, + nonce + }; + const promise = new Promise((resolve2) => this.sessionPromises.set(nonce, resolve2)); + parentPort.postMessage(payload); + return promise; + } + updateSessionInfo(shardId, sessionInfo) { + const payload = { + op: 4 /* UpdateSessionInfo */, + shardId, + session: sessionInfo + }; + parentPort.postMessage(payload); + } + async waitForIdentify(shardId, signal) { + const nonce = Math.random(); + const payload = { + op: 5 /* WaitForIdentify */, + nonce, + shardId + }; + const promise = new Promise( + (resolve2, reject) => ( + // eslint-disable-next-line no-promise-executor-return + this.waitForIdentifyPromises.set(nonce, { signal, resolve: resolve2, reject }) + ) + ); + parentPort.postMessage(payload); + const listener = /* @__PURE__ */ __name(() => { + const payload2 = { + op: 8 /* CancelIdentify */, + nonce + }; + parentPort.postMessage(payload2); + }, "listener"); + signal.addEventListener("abort", listener); + try { + await promise; + } finally { + signal.removeEventListener("abort", listener); + } + } +}; + +// src/strategies/sharding/SimpleShardingStrategy.ts +import { Collection as Collection6 } from "@discordjs/collection"; + +// src/ws/WebSocketShard.ts +import { Buffer as Buffer2 } from "node:buffer"; +import { once as once2 } from "node:events"; +import { clearInterval, clearTimeout, setInterval, setTimeout } from "node:timers"; +import { setTimeout as sleep2 } from "node:timers/promises"; +import { URLSearchParams } from "node:url"; +import { TextDecoder } from "node:util"; +import { inflate } from "node:zlib"; +import { Collection as Collection5 } from "@discordjs/collection"; +import { lazy as lazy2 } from "@discordjs/util"; +import { AsyncQueue as AsyncQueue2 } from "@sapphire/async-queue"; +import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter"; +import { + GatewayCloseCodes, + GatewayDispatchEvents, + GatewayOpcodes as GatewayOpcodes2 +} from "discord-api-types/v10"; +import { WebSocket } from "ws"; + +// src/utils/constants.ts +import process from "node:process"; +import { Collection as Collection4 } from "@discordjs/collection"; +import { lazy } from "@discordjs/util"; +import { APIVersion, GatewayOpcodes } from "discord-api-types/v10"; + +// src/throttling/SimpleIdentifyThrottler.ts +import { setTimeout as sleep } from "node:timers/promises"; +import { Collection as Collection3 } from "@discordjs/collection"; +import { AsyncQueue } from "@sapphire/async-queue"; +var SimpleIdentifyThrottler = class { + constructor(maxConcurrency) { + this.maxConcurrency = maxConcurrency; + } + static { + __name(this, "SimpleIdentifyThrottler"); + } + states = new Collection3(); + /** + * {@inheritDoc IIdentifyThrottler.waitForIdentify} + */ + async waitForIdentify(shardId, signal) { + const key = shardId % this.maxConcurrency; + const state = this.states.ensure(key, () => { + return { + queue: new AsyncQueue(), + resetsAt: Number.POSITIVE_INFINITY + }; + }); + await state.queue.wait({ signal }); + try { + const diff = state.resetsAt - Date.now(); + if (diff <= 5e3) { + const time = diff + Math.random() * 1500; + await sleep(time); + } + state.resetsAt = Date.now() + 5e3; + } finally { + state.queue.shift(); + } + } +}; + +// src/utils/constants.ts +var Encoding = /* @__PURE__ */ ((Encoding2) => { + Encoding2["JSON"] = "json"; + return Encoding2; +})(Encoding || {}); +var CompressionMethod = /* @__PURE__ */ ((CompressionMethod2) => { + CompressionMethod2["ZlibStream"] = "zlib-stream"; + return CompressionMethod2; +})(CompressionMethod || {}); +var DefaultDeviceProperty = `@discordjs/ws 1.0.1`; +var getDefaultSessionStore = lazy(() => new Collection4()); +var DefaultWebSocketManagerOptions = { + async buildIdentifyThrottler(manager) { + const info = await manager.fetchGatewayInformation(); + return new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency); + }, + buildStrategy: (manager) => new SimpleShardingStrategy(manager), + shardCount: null, + shardIds: null, + largeThreshold: null, + initialPresence: null, + identifyProperties: { + browser: DefaultDeviceProperty, + device: DefaultDeviceProperty, + os: process.platform + }, + version: APIVersion, + encoding: "json" /* JSON */, + compression: null, + retrieveSessionInfo(shardId) { + const store = getDefaultSessionStore(); + return store.get(shardId) ?? null; + }, + updateSessionInfo(shardId, info) { + const store = getDefaultSessionStore(); + if (info) { + store.set(shardId, info); + } else { + store.delete(shardId); + } + }, + handshakeTimeout: 3e4, + helloTimeout: 6e4, + readyTimeout: 15e3 +}; +var ImportantGatewayOpcodes = /* @__PURE__ */ new Set([ + GatewayOpcodes.Heartbeat, + GatewayOpcodes.Identify, + GatewayOpcodes.Resume +]); +function getInitialSendRateLimitState() { + return { + remaining: 120, + resetAt: Date.now() + 6e4 + }; +} +__name(getInitialSendRateLimitState, "getInitialSendRateLimitState"); + +// src/ws/WebSocketShard.ts +var getZlibSync = lazy2(async () => import("zlib-sync").then((mod) => mod.default).catch(() => null)); +var WebSocketShardEvents = /* @__PURE__ */ ((WebSocketShardEvents2) => { + WebSocketShardEvents2["Closed"] = "closed"; + WebSocketShardEvents2["Debug"] = "debug"; + WebSocketShardEvents2["Dispatch"] = "dispatch"; + WebSocketShardEvents2["Error"] = "error"; + WebSocketShardEvents2["HeartbeatComplete"] = "heartbeat"; + WebSocketShardEvents2["Hello"] = "hello"; + WebSocketShardEvents2["Ready"] = "ready"; + WebSocketShardEvents2["Resumed"] = "resumed"; + return WebSocketShardEvents2; +})(WebSocketShardEvents || {}); +var WebSocketShardStatus = /* @__PURE__ */ ((WebSocketShardStatus2) => { + WebSocketShardStatus2[WebSocketShardStatus2["Idle"] = 0] = "Idle"; + WebSocketShardStatus2[WebSocketShardStatus2["Connecting"] = 1] = "Connecting"; + WebSocketShardStatus2[WebSocketShardStatus2["Resuming"] = 2] = "Resuming"; + WebSocketShardStatus2[WebSocketShardStatus2["Ready"] = 3] = "Ready"; + return WebSocketShardStatus2; +})(WebSocketShardStatus || {}); +var WebSocketShardDestroyRecovery = /* @__PURE__ */ ((WebSocketShardDestroyRecovery2) => { + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Reconnect"] = 0] = "Reconnect"; + WebSocketShardDestroyRecovery2[WebSocketShardDestroyRecovery2["Resume"] = 1] = "Resume"; + return WebSocketShardDestroyRecovery2; +})(WebSocketShardDestroyRecovery || {}); +var CloseCodes = /* @__PURE__ */ ((CloseCodes2) => { + CloseCodes2[CloseCodes2["Normal"] = 1e3] = "Normal"; + CloseCodes2[CloseCodes2["Resuming"] = 4200] = "Resuming"; + return CloseCodes2; +})(CloseCodes || {}); +var WebSocketConstructor = WebSocket; +var WebSocketShard = class extends AsyncEventEmitter { + static { + __name(this, "WebSocketShard"); + } + connection = null; + useIdentifyCompress = false; + inflate = null; + textDecoder = new TextDecoder(); + replayedEvents = 0; + isAck = true; + sendRateLimitState = getInitialSendRateLimitState(); + initialHeartbeatTimeoutController = null; + heartbeatInterval = null; + lastHeartbeatAt = -1; + // Indicates whether the shard has already resolved its original connect() call + initialConnectResolved = false; + // Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET) + failedToConnectDueToNetworkError = false; + sendQueue = new AsyncQueue2(); + timeoutAbortControllers = new Collection5(); + strategy; + id; + #status = 0 /* Idle */; + get status() { + return this.#status; + } + constructor(strategy, id) { + super(); + this.strategy = strategy; + this.id = id; + } + async connect() { + const controller = new AbortController(); + let promise; + if (!this.initialConnectResolved) { + promise = Promise.race([ + once2(this, "ready" /* Ready */, { signal: controller.signal }), + once2(this, "resumed" /* Resumed */, { signal: controller.signal }) + ]); + } + void this.internalConnect(); + try { + await promise; + } catch ({ error }) { + throw error; + } finally { + controller.abort(); + } + this.initialConnectResolved = true; + } + async internalConnect() { + if (this.#status !== 0 /* Idle */) { + throw new Error("Tried to connect a shard that wasn't idle"); + } + const { version: version2, encoding, compression } = this.strategy.options; + const params = new URLSearchParams({ v: version2, encoding }); + if (compression) { + const zlib = await getZlibSync(); + if (zlib) { + params.append("compress", compression); + this.inflate = new zlib.Inflate({ + chunkSize: 65535, + to: "string" + }); + } else if (!this.useIdentifyCompress) { + this.useIdentifyCompress = true; + console.warn( + "WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress" + ); + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + const url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`; + this.debug([`Connecting to ${url}`]); + const connection = new WebSocketConstructor(url, { + handshakeTimeout: this.strategy.options.handshakeTimeout ?? void 0 + }); + connection.binaryType = "arraybuffer"; + connection.onmessage = (event) => { + void this.onMessage(event.data, event.data instanceof ArrayBuffer); + }; + connection.onerror = (event) => { + this.onError(event.error); + }; + connection.onclose = (event) => { + void this.onClose(event.code); + }; + this.connection = connection; + this.#status = 1 /* Connecting */; + this.sendRateLimitState = getInitialSendRateLimitState(); + const { ok } = await this.waitForEvent("hello" /* Hello */, this.strategy.options.helloTimeout); + if (!ok) { + return; + } + if (session?.shardCount === this.strategy.options.shardCount) { + await this.resume(session); + } else { + await this.identify(); + } + } + async destroy(options = {}) { + if (this.#status === 0 /* Idle */) { + this.debug(["Tried to destroy a shard that was idle"]); + return; + } + if (!options.code) { + options.code = options.recover === 1 /* Resume */ ? 4200 /* Resuming */ : 1e3 /* Normal */; + } + this.debug([ + "Destroying shard", + `Reason: ${options.reason ?? "none"}`, + `Code: ${options.code}`, + `Recover: ${options.recover === void 0 ? "none" : WebSocketShardDestroyRecovery[options.recover]}` + ]); + this.isAck = true; + if (this.heartbeatInterval) { + clearInterval(this.heartbeatInterval); + } + if (this.initialHeartbeatTimeoutController) { + this.initialHeartbeatTimeoutController.abort(); + this.initialHeartbeatTimeoutController = null; + } + this.lastHeartbeatAt = -1; + for (const controller of this.timeoutAbortControllers.values()) { + controller.abort(); + } + this.timeoutAbortControllers.clear(); + this.failedToConnectDueToNetworkError = false; + if (options.recover !== 1 /* Resume */) { + await this.strategy.updateSessionInfo(this.id, null); + } + if (this.connection) { + this.connection.onmessage = null; + this.connection.onclose = null; + const shouldClose = this.connection.readyState === WebSocket.OPEN; + this.debug([ + "Connection status during destroy", + `Needs closing: ${shouldClose}`, + `Ready state: ${this.connection.readyState}` + ]); + if (shouldClose) { + let outerResolve; + const promise = new Promise((resolve2) => { + outerResolve = resolve2; + }); + this.connection.onclose = outerResolve; + this.connection.close(options.code, options.reason); + await promise; + this.emit("closed" /* Closed */, { code: options.code }); + } + this.connection.onerror = null; + } else { + this.debug(["Destroying a shard that has no connection; please open an issue on GitHub"]); + } + this.#status = 0 /* Idle */; + if (options.recover !== void 0) { + await sleep2(500); + return this.internalConnect(); + } + } + async waitForEvent(event, timeoutDuration) { + this.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : "indefinitely"}`]); + const timeoutController = new AbortController(); + const timeout = timeoutDuration ? setTimeout(() => timeoutController.abort(), timeoutDuration).unref() : null; + this.timeoutAbortControllers.set(event, timeoutController); + const closeController = new AbortController(); + try { + const closed = await Promise.race([ + once2(this, event, { signal: timeoutController.signal }).then(() => false), + once2(this, "closed" /* Closed */, { signal: closeController.signal }).then(() => true) + ]); + return { ok: !closed }; + } catch { + void this.destroy({ + code: 1e3 /* Normal */, + reason: "Something timed out or went wrong while waiting for an event", + recover: 0 /* Reconnect */ + }); + return { ok: false }; + } finally { + if (timeout) { + clearTimeout(timeout); + } + this.timeoutAbortControllers.delete(event); + if (!closeController.signal.aborted) { + closeController.abort(); + } + } + } + async send(payload) { + if (!this.connection) { + throw new Error("WebSocketShard wasn't connected"); + } + if (this.#status !== 3 /* Ready */ && !ImportantGatewayOpcodes.has(payload.op)) { + this.debug(["Tried to send a non-crucial payload before the shard was ready, waiting"]); + try { + await once2(this, "ready" /* Ready */); + } catch { + return this.send(payload); + } + } + await this.sendQueue.wait(); + if (--this.sendRateLimitState.remaining <= 0) { + const now = Date.now(); + if (this.sendRateLimitState.resetAt > now) { + const sleepFor = this.sendRateLimitState.resetAt - now; + this.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]); + const controller = new AbortController(); + const interrupted = await Promise.race([ + sleep2(sleepFor).then(() => false), + once2(this, "closed" /* Closed */, { signal: controller.signal }).then(() => true) + ]); + if (interrupted) { + this.debug(["Connection closed while waiting for the send rate limit to reset, re-queueing payload"]); + this.sendQueue.shift(); + return this.send(payload); + } + controller.abort(); + } + this.sendRateLimitState = getInitialSendRateLimitState(); + } + this.sendQueue.shift(); + this.connection.send(JSON.stringify(payload)); + } + async identify() { + this.debug(["Waiting for identify throttle"]); + const controller = new AbortController(); + const closeHandler = /* @__PURE__ */ __name(() => { + controller.abort(); + }, "closeHandler"); + this.on("closed" /* Closed */, closeHandler); + try { + await this.strategy.waitForIdentify(this.id, controller.signal); + } catch { + if (controller.signal.aborted) { + this.debug(["Was waiting for an identify, but the shard closed in the meantime"]); + return; + } + this.debug([ + "IContextFetchingStrategy#waitForIdentify threw an unknown error.", + "If you're using a custom strategy, this is probably nothing to worry about.", + "If you're not, please open an issue on GitHub." + ]); + await this.destroy({ + reason: "Identify throttling logic failed", + recover: 1 /* Resume */ + }); + } finally { + this.off("closed" /* Closed */, closeHandler); + } + this.debug([ + "Identifying", + `shard id: ${this.id.toString()}`, + `shard count: ${this.strategy.options.shardCount}`, + `intents: ${this.strategy.options.intents}`, + `compression: ${this.inflate ? "zlib-stream" : this.useIdentifyCompress ? "identify" : "none"}` + ]); + const d = { + token: this.strategy.options.token, + properties: this.strategy.options.identifyProperties, + intents: this.strategy.options.intents, + compress: this.useIdentifyCompress, + shard: [this.id, this.strategy.options.shardCount] + }; + if (this.strategy.options.largeThreshold) { + d.large_threshold = this.strategy.options.largeThreshold; + } + if (this.strategy.options.initialPresence) { + d.presence = this.strategy.options.initialPresence; + } + await this.send({ + op: GatewayOpcodes2.Identify, + d + }); + await this.waitForEvent("ready" /* Ready */, this.strategy.options.readyTimeout); + } + async resume(session) { + this.debug([ + "Resuming session", + `resume url: ${session.resumeURL}`, + `sequence: ${session.sequence}`, + `shard id: ${this.id.toString()}` + ]); + this.#status = 2 /* Resuming */; + this.replayedEvents = 0; + return this.send({ + op: GatewayOpcodes2.Resume, + d: { + token: this.strategy.options.token, + seq: session.sequence, + session_id: session.sessionId + } + }); + } + async heartbeat(requested = false) { + if (!this.isAck && !requested) { + return this.destroy({ reason: "Zombie connection", recover: 1 /* Resume */ }); + } + const session = await this.strategy.retrieveSessionInfo(this.id); + await this.send({ + op: GatewayOpcodes2.Heartbeat, + d: session?.sequence ?? null + }); + this.lastHeartbeatAt = Date.now(); + this.isAck = false; + } + async unpackMessage(data, isBinary) { + if (!isBinary) { + try { + return JSON.parse(data); + } catch { + return null; + } + } + const decompressable = new Uint8Array(data); + if (this.useIdentifyCompress) { + return new Promise((resolve2, reject) => { + inflate(decompressable, { chunkSize: 65535 }, (err, result) => { + if (err) { + reject(err); + return; + } + resolve2(JSON.parse(this.textDecoder.decode(result))); + }); + }); + } + if (this.inflate) { + const l = decompressable.length; + const flush = l >= 4 && decompressable[l - 4] === 0 && decompressable[l - 3] === 0 && decompressable[l - 2] === 255 && decompressable[l - 1] === 255; + const zlib = await getZlibSync(); + this.inflate.push(Buffer2.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH); + if (this.inflate.err) { + this.emit("error" /* Error */, { + error: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ""}`) + }); + } + if (!flush) { + return null; + } + const { result } = this.inflate; + if (!result) { + return null; + } + return JSON.parse(typeof result === "string" ? result : this.textDecoder.decode(result)); + } + this.debug([ + "Received a message we were unable to decompress", + `isBinary: ${isBinary.toString()}`, + `useIdentifyCompress: ${this.useIdentifyCompress.toString()}`, + `inflate: ${Boolean(this.inflate).toString()}` + ]); + return null; + } + async onMessage(data, isBinary) { + const payload = await this.unpackMessage(data, isBinary); + if (!payload) { + return; + } + switch (payload.op) { + case GatewayOpcodes2.Dispatch: { + if (this.#status === 2 /* Resuming */) { + this.replayedEvents++; + } + switch (payload.t) { + case GatewayDispatchEvents.Ready: { + this.#status = 3 /* Ready */; + const session2 = { + sequence: payload.s, + sessionId: payload.d.session_id, + shardId: this.id, + shardCount: this.strategy.options.shardCount, + resumeURL: payload.d.resume_gateway_url + }; + await this.strategy.updateSessionInfo(this.id, session2); + this.emit("ready" /* Ready */, { data: payload.d }); + break; + } + case GatewayDispatchEvents.Resumed: { + this.#status = 3 /* Ready */; + this.debug([`Resumed and replayed ${this.replayedEvents} events`]); + this.emit("resumed" /* Resumed */); + break; + } + default: { + break; + } + } + const session = await this.strategy.retrieveSessionInfo(this.id); + if (session) { + if (payload.s > session.sequence) { + await this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s }); + } + } else { + this.debug([ + `Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect` + ]); + } + this.emit("dispatch" /* Dispatch */, { data: payload }); + break; + } + case GatewayOpcodes2.Heartbeat: { + await this.heartbeat(true); + break; + } + case GatewayOpcodes2.Reconnect: { + await this.destroy({ + reason: "Told to reconnect by Discord", + recover: 1 /* Resume */ + }); + break; + } + case GatewayOpcodes2.InvalidSession: { + this.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]); + const session = await this.strategy.retrieveSessionInfo(this.id); + if (payload.d && session) { + await this.resume(session); + } else { + await this.destroy({ + reason: "Invalid session", + recover: 0 /* Reconnect */ + }); + } + break; + } + case GatewayOpcodes2.Hello: { + this.emit("hello" /* Hello */); + const jitter = Math.random(); + const firstWait = Math.floor(payload.d.heartbeat_interval * jitter); + this.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]); + try { + const controller = new AbortController(); + this.initialHeartbeatTimeoutController = controller; + await sleep2(firstWait, void 0, { signal: controller.signal }); + } catch { + this.debug(["Cancelled initial heartbeat due to #destroy being called"]); + return; + } finally { + this.initialHeartbeatTimeoutController = null; + } + await this.heartbeat(); + this.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]); + this.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval); + break; + } + case GatewayOpcodes2.HeartbeatAck: { + this.isAck = true; + const ackAt = Date.now(); + this.emit("heartbeat" /* HeartbeatComplete */, { + ackAt, + heartbeatAt: this.lastHeartbeatAt, + latency: ackAt - this.lastHeartbeatAt + }); + break; + } + } + } + onError(error) { + if ("code" in error && ["ECONNRESET", "ECONNREFUSED"].includes(error.code)) { + this.debug(["Failed to connect to the gateway URL specified due to a network error"]); + this.failedToConnectDueToNetworkError = true; + return; + } + this.emit("error" /* Error */, { error }); + } + async onClose(code) { + this.emit("closed" /* Closed */, { code }); + switch (code) { + case 1e3 /* Normal */: { + return this.destroy({ + code, + reason: "Got disconnected by Discord", + recover: 0 /* Reconnect */ + }); + } + case 4200 /* Resuming */: { + break; + } + case GatewayCloseCodes.UnknownError: { + this.debug([`An unknown error occurred: ${code}`]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.UnknownOpcode: { + this.debug(["An invalid opcode was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.DecodeError: { + this.debug(["An invalid payload was sent to Discord."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.NotAuthenticated: { + this.debug(["A request was somehow sent before the identify/resume payload."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.AuthenticationFailed: { + this.emit("error" /* Error */, { + error: new Error("Authentication failed") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.AlreadyAuthenticated: { + this.debug(["More than one auth payload was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.InvalidSeq: { + this.debug(["An invalid sequence was sent."]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.RateLimited: { + this.debug(["The WebSocket rate limit has been hit, this should never happen"]); + return this.destroy({ code, recover: 0 /* Reconnect */ }); + } + case GatewayCloseCodes.SessionTimedOut: { + this.debug(["Session timed out."]); + return this.destroy({ code, recover: 1 /* Resume */ }); + } + case GatewayCloseCodes.InvalidShard: { + this.emit("error" /* Error */, { + error: new Error("Invalid shard") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.ShardingRequired: { + this.emit("error" /* Error */, { + error: new Error("Sharding is required") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.InvalidAPIVersion: { + this.emit("error" /* Error */, { + error: new Error("Used an invalid API version") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.InvalidIntents: { + this.emit("error" /* Error */, { + error: new Error("Used invalid intents") + }); + return this.destroy({ code }); + } + case GatewayCloseCodes.DisallowedIntents: { + this.emit("error" /* Error */, { + error: new Error("Used disallowed intents") + }); + return this.destroy({ code }); + } + default: { + this.debug([ + `The gateway closed with an unexpected code ${code}, attempting to ${this.failedToConnectDueToNetworkError ? "reconnect" : "resume"}.` + ]); + return this.destroy({ + code, + recover: this.failedToConnectDueToNetworkError ? 0 /* Reconnect */ : 1 /* Resume */ + }); + } + } + } + debug(messages) { + const message = `${messages[0]}${messages.length > 1 ? ` +${messages.slice(1).map((m) => ` ${m}`).join("\n")}` : ""}`; + this.emit("debug" /* Debug */, { message }); + } +}; + +// src/strategies/sharding/SimpleShardingStrategy.ts +var SimpleShardingStrategy = class { + static { + __name(this, "SimpleShardingStrategy"); + } + manager; + shards = new Collection6(); + constructor(manager) { + this.manager = manager; + } + /** + * {@inheritDoc IShardingStrategy.spawn} + */ + async spawn(shardIds) { + const strategyOptions = await managerToFetchingStrategyOptions(this.manager); + for (const shardId of shardIds) { + const strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions); + const shard = new WebSocketShard(strategy, shardId); + for (const event of Object.values(WebSocketShardEvents)) { + shard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId })); + } + this.shards.set(shardId, shard); + } + } + /** + * {@inheritDoc IShardingStrategy.connect} + */ + async connect() { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.connect()); + } + await Promise.all(promises); + } + /** + * {@inheritDoc IShardingStrategy.destroy} + */ + async destroy(options) { + const promises = []; + for (const shard of this.shards.values()) { + promises.push(shard.destroy(options)); + } + await Promise.all(promises); + this.shards.clear(); + } + /** + * {@inheritDoc IShardingStrategy.send} + */ + async send(shardId, payload) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} not found`); + } + return shard.send(payload); + } + /** + * {@inheritDoc IShardingStrategy.fetchStatus} + */ + async fetchStatus() { + return this.shards.mapValues((shard) => shard.status); + } +}; + +// src/utils/WorkerBootstrapper.ts +import { isMainThread as isMainThread2, parentPort as parentPort2, workerData } from "node:worker_threads"; +import { Collection as Collection7 } from "@discordjs/collection"; +var WorkerBootstrapper = class { + static { + __name(this, "WorkerBootstrapper"); + } + /** + * The data passed to the worker thread + */ + data = workerData; + /** + * The shards that are managed by this worker + */ + shards = new Collection7(); + constructor() { + if (isMainThread2) { + throw new Error("Expected WorkerBootstrap to not be used within the main thread"); + } + } + /** + * Helper method to initiate a shard's connection process + */ + async connect(shardId) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.connect(); + } + /** + * Helper method to destroy a shard + */ + async destroy(shardId, options) { + const shard = this.shards.get(shardId); + if (!shard) { + throw new RangeError(`Shard ${shardId} does not exist`); + } + await shard.destroy(options); + } + /** + * Helper method to attach event listeners to the parentPort + */ + setupThreadEvents() { + parentPort2.on("messageerror", (err) => { + throw err; + }).on("message", async (payload) => { + switch (payload.op) { + case 0 /* Connect */: { + await this.connect(payload.shardId); + const response = { + op: 0 /* Connected */, + shardId: payload.shardId + }; + parentPort2.postMessage(response); + break; + } + case 1 /* Destroy */: { + await this.destroy(payload.shardId, payload.options); + const response = { + op: 1 /* Destroyed */, + shardId: payload.shardId + }; + parentPort2.postMessage(response); + break; + } + case 2 /* Send */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new RangeError(`Shard ${payload.shardId} does not exist`); + } + await shard.send(payload.payload); + break; + } + case 3 /* SessionInfoResponse */: { + break; + } + case 4 /* ShardIdentifyResponse */: { + break; + } + case 5 /* FetchStatus */: { + const shard = this.shards.get(payload.shardId); + if (!shard) { + throw new Error(`Shard ${payload.shardId} does not exist`); + } + const response = { + op: 6 /* FetchStatusResponse */, + status: shard.status, + nonce: payload.nonce + }; + parentPort2.postMessage(response); + break; + } + } + }); + } + /** + * Bootstraps the worker thread with the provided options + */ + async bootstrap(options = {}) { + for (const shardId of this.data.shardIds) { + const shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId); + for (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) { + shard.on(event, (data) => { + const payload = { + op: 2 /* Event */, + event, + data, + shardId + }; + parentPort2.postMessage(payload); + }); + } + await options.shardCallback?.(shard); + this.shards.set(shardId, shard); + } + this.setupThreadEvents(); + const message = { + op: 7 /* WorkerReady */ + }; + parentPort2.postMessage(message); + } +}; + +// src/ws/WebSocketManager.ts +import { range } from "@discordjs/util"; +import { AsyncEventEmitter as AsyncEventEmitter2 } from "@vladfrangu/async_event_emitter"; +import { + Routes +} from "discord-api-types/v10"; +var WebSocketManager = class extends AsyncEventEmitter2 { + static { + __name(this, "WebSocketManager"); + } + /** + * The options being used by this manager + */ + options; + /** + * Internal cache for a GET /gateway/bot result + */ + gatewayInformation = null; + /** + * Internal cache for the shard ids + */ + shardIds = null; + /** + * Strategy used to manage shards + * + * @defaultValue `SimpleShardingStrategy` + */ + strategy; + constructor(options) { + super(); + this.options = { ...DefaultWebSocketManagerOptions, ...options }; + this.strategy = this.options.buildStrategy(this); + } + /** + * Fetches the gateway information from Discord - or returns it from cache if available + * + * @param force - Whether to ignore the cache and force a fresh fetch + */ + async fetchGatewayInformation(force = false) { + if (this.gatewayInformation) { + if (this.gatewayInformation.expiresAt <= Date.now()) { + this.gatewayInformation = null; + } else if (!force) { + return this.gatewayInformation.data; + } + } + const data = await this.options.rest.get(Routes.gatewayBot()); + this.gatewayInformation = { data, expiresAt: Date.now() + (data.session_start_limit.reset_after || 5e3) }; + return this.gatewayInformation.data; + } + /** + * Updates your total shard count on-the-fly, spawning shards as needed + * + * @param shardCount - The new shard count to use + */ + async updateShardCount(shardCount) { + await this.strategy.destroy({ reason: "User is adjusting their shards" }); + this.options.shardCount = shardCount; + const shardIds = await this.getShardIds(true); + await this.strategy.spawn(shardIds); + return this; + } + /** + * Yields the total number of shards across for your bot, accounting for Discord recommendations + */ + async getShardCount() { + if (this.options.shardCount) { + return this.options.shardCount; + } + const shardIds = await this.getShardIds(); + return Math.max(...shardIds) + 1; + } + /** + * Yields the ids of the shards this manager should manage + */ + async getShardIds(force = false) { + if (this.shardIds && !force) { + return this.shardIds; + } + let shardIds; + if (this.options.shardIds) { + if (Array.isArray(this.options.shardIds)) { + shardIds = this.options.shardIds; + } else { + const { start, end } = this.options.shardIds; + shardIds = [...range({ start, end: end + 1 })]; + } + } else { + const data = await this.fetchGatewayInformation(); + shardIds = [...range(this.options.shardCount ?? data.shards)]; + } + this.shardIds = shardIds; + return shardIds; + } + async connect() { + const shardCount = await this.getShardCount(); + const data = await this.fetchGatewayInformation(); + if (data.session_start_limit.remaining < shardCount) { + throw new Error( + `Not enough sessions remaining to spawn ${shardCount} shards; only ${data.session_start_limit.remaining} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}` + ); + } + await this.updateShardCount(shardCount); + await this.strategy.connect(); + } + destroy(options) { + return this.strategy.destroy(options); + } + send(shardId, payload) { + return this.strategy.send(shardId, payload); + } + fetchStatus() { + return this.strategy.fetchStatus(); + } +}; + +// src/index.ts +var version = "1.0.1"; +export { + CloseCodes, + CompressionMethod, + DefaultDeviceProperty, + DefaultWebSocketManagerOptions, + Encoding, + ImportantGatewayOpcodes, + SimpleContextFetchingStrategy, + SimpleIdentifyThrottler, + SimpleShardingStrategy, + WebSocketManager, + WebSocketShard, + WebSocketShardDestroyRecovery, + WebSocketShardEvents, + WebSocketShardStatus, + WorkerBootstrapper, + WorkerContextFetchingStrategy, + WorkerReceivePayloadOp, + WorkerSendPayloadOp, + WorkerShardingStrategy, + getInitialSendRateLimitState, + managerToFetchingStrategyOptions, + version +}; +//# sourceMappingURL=index.mjs.map
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/dist/index.mjs.map b/node_modules/@discordjs/ws/dist/index.mjs.map new file mode 100644 index 0000000..5c18bd5 --- /dev/null +++ b/node_modules/@discordjs/ws/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../node_modules/tsup/assets/esm_shims.js","../src/strategies/context/IContextFetchingStrategy.ts","../src/strategies/context/SimpleContextFetchingStrategy.ts","../src/strategies/context/WorkerContextFetchingStrategy.ts","../src/strategies/sharding/WorkerShardingStrategy.ts","../src/strategies/sharding/SimpleShardingStrategy.ts","../src/ws/WebSocketShard.ts","../src/utils/constants.ts","../src/throttling/SimpleIdentifyThrottler.ts","../src/utils/WorkerBootstrapper.ts","../src/ws/WebSocketManager.ts","../src/index.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport { fileURLToPath } from 'url'\nimport path from 'path'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","import type { Awaitable } from '@discordjs/util';\nimport type { APIGatewayBotInfo } from 'discord-api-types/v10';\nimport type { SessionInfo, WebSocketManager, WebSocketManagerOptions } from '../../ws/WebSocketManager.js';\n\nexport interface FetchingStrategyOptions\n\textends Omit<\n\t\tWebSocketManagerOptions,\n\t\t| 'buildIdentifyThrottler'\n\t\t| 'buildStrategy'\n\t\t| 'rest'\n\t\t| 'retrieveSessionInfo'\n\t\t| 'shardCount'\n\t\t| 'shardIds'\n\t\t| 'updateSessionInfo'\n\t> {\n\treadonly gatewayInformation: APIGatewayBotInfo;\n\treadonly shardCount: number;\n}\n\n/**\n * Strategies responsible solely for making manager information accessible\n */\nexport interface IContextFetchingStrategy {\n\treadonly options: FetchingStrategyOptions;\n\tretrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>;\n\tupdateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>;\n\t/**\n\t * Resolves once the given shard should be allowed to identify\n\t * This should correctly handle the signal and reject with an abort error if the operation is aborted.\n\t * Other errors will cause the shard to reconnect.\n\t */\n\twaitForIdentify(shardId: number, signal: AbortSignal): Promise<void>;\n}\n\nexport async function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions> {\n\t/* eslint-disable @typescript-eslint/unbound-method */\n\tconst {\n\t\tbuildIdentifyThrottler,\n\t\tbuildStrategy,\n\t\tretrieveSessionInfo,\n\t\tupdateSessionInfo,\n\t\tshardCount,\n\t\tshardIds,\n\t\trest,\n\t\t...managerOptions\n\t} = manager.options;\n\t/* eslint-enable @typescript-eslint/unbound-method */\n\n\treturn {\n\t\t...managerOptions,\n\t\tgatewayInformation: await manager.fetchGatewayInformation(),\n\t\tshardCount: await manager.getShardCount(),\n\t};\n}\n","import type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class SimpleContextFetchingStrategy implements IContextFetchingStrategy {\n\t// This strategy assumes every shard is running under the same process - therefore we need a single\n\t// IdentifyThrottler per manager.\n\tprivate static throttlerCache = new WeakMap<WebSocketManager, IIdentifyThrottler>();\n\n\tprivate static async ensureThrottler(manager: WebSocketManager): Promise<IIdentifyThrottler> {\n\t\tconst throttler = SimpleContextFetchingStrategy.throttlerCache.get(manager);\n\t\tif (throttler) {\n\t\t\treturn throttler;\n\t\t}\n\n\t\tconst newThrottler = await manager.options.buildIdentifyThrottler(manager);\n\t\tSimpleContextFetchingStrategy.throttlerCache.set(manager, newThrottler);\n\n\t\treturn newThrottler;\n\t}\n\n\tpublic constructor(private readonly manager: WebSocketManager, public readonly options: FetchingStrategyOptions) {}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\treturn this.manager.options.retrieveSessionInfo(shardId);\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\treturn this.manager.options.updateSessionInfo(shardId, sessionInfo);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst throttler = await SimpleContextFetchingStrategy.ensureThrottler(this.manager);\n\t\tawait throttler.waitForIdentify(shardId, signal);\n\t}\n}\n","import { isMainThread, parentPort } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { SessionInfo } from '../../ws/WebSocketManager.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../sharding/WorkerShardingStrategy.js';\nimport type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';\n\nexport class WorkerContextFetchingStrategy implements IContextFetchingStrategy {\n\tprivate readonly sessionPromises = new Collection<number, (session: SessionInfo | null) => void>();\n\n\tprivate readonly waitForIdentifyPromises = new Collection<\n\t\tnumber,\n\t\t{ reject(error: unknown): void; resolve(): void; signal: AbortSignal }\n\t>();\n\n\tpublic constructor(public readonly options: FetchingStrategyOptions) {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Cannot instantiate WorkerContextFetchingStrategy on the main thread');\n\t\t}\n\n\t\tparentPort!.on('message', (payload: WorkerSendPayload) => {\n\t\t\tif (payload.op === WorkerSendPayloadOp.SessionInfoResponse) {\n\t\t\t\tthis.sessionPromises.get(payload.nonce)?.(payload.session);\n\t\t\t\tthis.sessionPromises.delete(payload.nonce);\n\t\t\t}\n\n\t\t\tif (payload.op === WorkerSendPayloadOp.ShardIdentifyResponse) {\n\t\t\t\tconst promise = this.waitForIdentifyPromises.get(payload.nonce);\n\t\t\t\tif (payload.ok) {\n\t\t\t\t\tpromise?.resolve();\n\t\t\t\t} else {\n\t\t\t\t\t// We need to make sure we reject with an abort error\n\t\t\t\t\tpromise?.reject(promise.signal.reason);\n\t\t\t\t}\n\n\t\t\t\tthis.waitForIdentifyPromises.delete(payload.nonce);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic async retrieveSessionInfo(shardId: number): Promise<SessionInfo | null> {\n\t\tconst nonce = Math.random();\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.RetrieveSessionInfo,\n\t\t\tshardId,\n\t\t\tnonce,\n\t\t};\n\t\t// eslint-disable-next-line no-promise-executor-return\n\t\tconst promise = new Promise<SessionInfo | null>((resolve) => this.sessionPromises.set(nonce, resolve));\n\t\tparentPort!.postMessage(payload);\n\t\treturn promise;\n\t}\n\n\tpublic updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null) {\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.UpdateSessionInfo,\n\t\t\tshardId,\n\t\t\tsession: sessionInfo,\n\t\t};\n\t\tparentPort!.postMessage(payload);\n\t}\n\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst nonce = Math.random();\n\n\t\tconst payload: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WaitForIdentify,\n\t\t\tnonce,\n\t\t\tshardId,\n\t\t};\n\t\tconst promise = new Promise<void>((resolve, reject) =>\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tthis.waitForIdentifyPromises.set(nonce, { signal, resolve, reject }),\n\t\t);\n\n\t\tparentPort!.postMessage(payload);\n\n\t\tconst listener = () => {\n\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\top: WorkerReceivePayloadOp.CancelIdentify,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\tparentPort!.postMessage(payload);\n\t\t};\n\n\t\tsignal.addEventListener('abort', listener);\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} finally {\n\t\t\tsignal.removeEventListener('abort', listener);\n\t\t}\n\t}\n}\n","import { once } from 'node:events';\nimport { join, isAbsolute, resolve } from 'node:path';\nimport { Worker } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { IIdentifyThrottler } from '../../throttling/IIdentifyThrottler.js';\nimport type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';\nimport type {\n\tWebSocketShardDestroyOptions,\n\tWebSocketShardEvents,\n\tWebSocketShardStatus,\n} from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions, type FetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\nexport interface WorkerData extends FetchingStrategyOptions {\n\tshardIds: number[];\n}\n\nexport enum WorkerSendPayloadOp {\n\tConnect,\n\tDestroy,\n\tSend,\n\tSessionInfoResponse,\n\tShardIdentifyResponse,\n\tFetchStatus,\n}\n\nexport type WorkerSendPayload =\n\t| { nonce: number; ok: boolean; op: WorkerSendPayloadOp.ShardIdentifyResponse }\n\t| { nonce: number; op: WorkerSendPayloadOp.FetchStatus; shardId: number }\n\t| { nonce: number; op: WorkerSendPayloadOp.SessionInfoResponse; session: SessionInfo | null }\n\t| { op: WorkerSendPayloadOp.Connect; shardId: number }\n\t| { op: WorkerSendPayloadOp.Destroy; options?: WebSocketShardDestroyOptions; shardId: number }\n\t| { op: WorkerSendPayloadOp.Send; payload: GatewaySendPayload; shardId: number };\n\nexport enum WorkerReceivePayloadOp {\n\tConnected,\n\tDestroyed,\n\tEvent,\n\tRetrieveSessionInfo,\n\tUpdateSessionInfo,\n\tWaitForIdentify,\n\tFetchStatusResponse,\n\tWorkerReady,\n\tCancelIdentify,\n}\n\nexport type WorkerReceivePayload =\n\t// Can't seem to get a type-safe union based off of the event, so I'm sadly leaving data as any for now\n\t| { data: any; event: WebSocketShardEvents; op: WorkerReceivePayloadOp.Event; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.CancelIdentify }\n\t| { nonce: number; op: WorkerReceivePayloadOp.FetchStatusResponse; status: WebSocketShardStatus }\n\t| { nonce: number; op: WorkerReceivePayloadOp.RetrieveSessionInfo; shardId: number }\n\t| { nonce: number; op: WorkerReceivePayloadOp.WaitForIdentify; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Connected; shardId: number }\n\t| { op: WorkerReceivePayloadOp.Destroyed; shardId: number }\n\t| { op: WorkerReceivePayloadOp.UpdateSessionInfo; session: SessionInfo | null; shardId: number }\n\t| { op: WorkerReceivePayloadOp.WorkerReady };\n\n/**\n * Options for a {@link WorkerShardingStrategy}\n */\nexport interface WorkerShardingStrategyOptions {\n\t/**\n\t * Dictates how many shards should be spawned per worker thread.\n\t */\n\tshardsPerWorker: number | 'all';\n\t/**\n\t * Path to the worker file to use. The worker requires quite a bit of setup, it is recommended you leverage the {@link WorkerBootstrapper} class.\n\t */\n\tworkerPath?: string;\n}\n\n/**\n * Strategy used to spawn threads in worker_threads\n */\nexport class WorkerShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly options: WorkerShardingStrategyOptions;\n\n\t#workers: Worker[] = [];\n\n\treadonly #workerByShardId = new Collection<number, Worker>();\n\n\tprivate readonly connectPromises = new Collection<number, () => void>();\n\n\tprivate readonly destroyPromises = new Collection<number, () => void>();\n\n\tprivate readonly fetchStatusPromises = new Collection<number, (status: WebSocketShardStatus) => void>();\n\n\tprivate readonly waitForIdentifyControllers = new Collection<number, AbortController>();\n\n\tprivate throttler?: IIdentifyThrottler;\n\n\tpublic constructor(manager: WebSocketManager, options: WorkerShardingStrategyOptions) {\n\t\tthis.manager = manager;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst shardsPerWorker = this.options.shardsPerWorker === 'all' ? shardIds.length : this.options.shardsPerWorker;\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tconst loops = Math.ceil(shardIds.length / shardsPerWorker);\n\t\tconst promises: Promise<void>[] = [];\n\n\t\tfor (let idx = 0; idx < loops; idx++) {\n\t\t\tconst slice = shardIds.slice(idx * shardsPerWorker, (idx + 1) * shardsPerWorker);\n\t\t\tconst workerData: WorkerData = {\n\t\t\t\t...strategyOptions,\n\t\t\t\tshardIds: slice,\n\t\t\t};\n\n\t\t\tpromises.push(this.setupWorker(workerData));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Connect,\n\t\t\t\tshardId,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<void>((resolve) => this.connectPromises.set(shardId, resolve));\n\t\t\tworker.postMessage(payload);\n\t\t\tpromises.push(promise);\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options: Omit<WebSocketShardDestroyOptions, 'recover'> = {}) {\n\t\tconst promises = [];\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.Destroy,\n\t\t\t\tshardId,\n\t\t\t\toptions,\n\t\t\t};\n\n\t\t\tpromises.push(\n\t\t\t\t// eslint-disable-next-line no-promise-executor-return, promise/prefer-await-to-then\n\t\t\t\tnew Promise<void>((resolve) => this.destroyPromises.set(shardId, resolve)).then(async () => worker.terminate()),\n\t\t\t);\n\t\t\tworker.postMessage(payload);\n\t\t}\n\n\t\tthis.#workers = [];\n\t\tthis.#workerByShardId.clear();\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic send(shardId: number, data: GatewaySendPayload) {\n\t\tconst worker = this.#workerByShardId.get(shardId);\n\t\tif (!worker) {\n\t\t\tthrow new Error(`No worker found for shard ${shardId}`);\n\t\t}\n\n\t\tconst payload: WorkerSendPayload = {\n\t\t\top: WorkerSendPayloadOp.Send,\n\t\t\tshardId,\n\t\t\tpayload: data,\n\t\t};\n\t\tworker.postMessage(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\tconst statuses = new Collection<number, WebSocketShardStatus>();\n\n\t\tfor (const [shardId, worker] of this.#workerByShardId.entries()) {\n\t\t\tconst nonce = Math.random();\n\t\t\tconst payload: WorkerSendPayload = {\n\t\t\t\top: WorkerSendPayloadOp.FetchStatus,\n\t\t\t\tshardId,\n\t\t\t\tnonce,\n\t\t\t};\n\n\t\t\t// eslint-disable-next-line no-promise-executor-return\n\t\t\tconst promise = new Promise<WebSocketShardStatus>((resolve) => this.fetchStatusPromises.set(nonce, resolve));\n\t\t\tworker.postMessage(payload);\n\n\t\t\tconst status = await promise;\n\t\t\tstatuses.set(shardId, status);\n\t\t}\n\n\t\treturn statuses;\n\t}\n\n\tprivate async setupWorker(workerData: WorkerData) {\n\t\tconst worker = new Worker(this.resolveWorkerPath(), { workerData });\n\n\t\tawait once(worker, 'online');\n\t\t// We do this in case the user has any potentially long running code in their worker\n\t\tawait this.waitForWorkerReady(worker);\n\n\t\tworker\n\t\t\t.on('error', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerReceivePayload) => this.onMessage(worker, payload));\n\n\t\tthis.#workers.push(worker);\n\t\tfor (const shardId of workerData.shardIds) {\n\t\t\tthis.#workerByShardId.set(shardId, worker);\n\t\t}\n\t}\n\n\tprivate resolveWorkerPath(): string {\n\t\tconst path = this.options.workerPath;\n\n\t\tif (!path) {\n\t\t\treturn join(__dirname, 'defaultWorker.js');\n\t\t}\n\n\t\tif (isAbsolute(path)) {\n\t\t\treturn path;\n\t\t}\n\n\t\tif (/^\\.\\.?[/\\\\]/.test(path)) {\n\t\t\treturn resolve(path);\n\t\t}\n\n\t\ttry {\n\t\t\treturn require.resolve(path);\n\t\t} catch {\n\t\t\treturn resolve(path);\n\t\t}\n\t}\n\n\tprivate async waitForWorkerReady(worker: Worker): Promise<void> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst handler = (payload: WorkerReceivePayload) => {\n\t\t\t\tif (payload.op === WorkerReceivePayloadOp.WorkerReady) {\n\t\t\t\t\tresolve();\n\t\t\t\t\tworker.off('message', handler);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tworker.on('message', handler);\n\t\t});\n\t}\n\n\tprivate async onMessage(worker: Worker, payload: WorkerReceivePayload) {\n\t\tswitch (payload.op) {\n\t\t\tcase WorkerReceivePayloadOp.Connected: {\n\t\t\t\tthis.connectPromises.get(payload.shardId)?.();\n\t\t\t\tthis.connectPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Destroyed: {\n\t\t\t\tthis.destroyPromises.get(payload.shardId)?.();\n\t\t\t\tthis.destroyPromises.delete(payload.shardId);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.Event: {\n\t\t\t\tthis.manager.emit(payload.event, { ...payload.data, shardId: payload.shardId });\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.RetrieveSessionInfo: {\n\t\t\t\tconst session = await this.manager.options.retrieveSessionInfo(payload.shardId);\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.SessionInfoResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tsession,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.UpdateSessionInfo: {\n\t\t\t\tawait this.manager.options.updateSessionInfo(payload.shardId, payload.session);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WaitForIdentify: {\n\t\t\t\tconst throttler = await this.ensureThrottler();\n\n\t\t\t\t// If this rejects it means we aborted, in which case we reply elsewhere.\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.waitForIdentifyControllers.set(payload.nonce, controller);\n\t\t\t\t\tawait throttler.waitForIdentify(payload.shardId, controller.signal);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: true,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.FetchStatusResponse: {\n\t\t\t\tthis.fetchStatusPromises.get(payload.nonce)?.(payload.status);\n\t\t\t\tthis.fetchStatusPromises.delete(payload.nonce);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.WorkerReady: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase WorkerReceivePayloadOp.CancelIdentify: {\n\t\t\t\tthis.waitForIdentifyControllers.get(payload.nonce)?.abort();\n\t\t\t\tthis.waitForIdentifyControllers.delete(payload.nonce);\n\n\t\t\t\tconst response: WorkerSendPayload = {\n\t\t\t\t\top: WorkerSendPayloadOp.ShardIdentifyResponse,\n\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\tok: false,\n\t\t\t\t};\n\t\t\t\tworker.postMessage(response);\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async ensureThrottler(): Promise<IIdentifyThrottler> {\n\t\tthis.throttler ??= await this.manager.options.buildIdentifyThrottler(this.manager);\n\t\treturn this.throttler;\n\t}\n}\n","import { Collection } from '@discordjs/collection';\nimport type { GatewaySendPayload } from 'discord-api-types/v10';\nimport type { WebSocketManager } from '../../ws/WebSocketManager.js';\nimport { WebSocketShard, WebSocketShardEvents, type WebSocketShardDestroyOptions } from '../../ws/WebSocketShard.js';\nimport { managerToFetchingStrategyOptions } from '../context/IContextFetchingStrategy.js';\nimport { SimpleContextFetchingStrategy } from '../context/SimpleContextFetchingStrategy.js';\nimport type { IShardingStrategy } from './IShardingStrategy.js';\n\n/**\n * Simple strategy that just spawns shards in the current process\n */\nexport class SimpleShardingStrategy implements IShardingStrategy {\n\tprivate readonly manager: WebSocketManager;\n\n\tprivate readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor(manager: WebSocketManager) {\n\t\tthis.manager = manager;\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.spawn}\n\t */\n\tpublic async spawn(shardIds: number[]) {\n\t\tconst strategyOptions = await managerToFetchingStrategyOptions(this.manager);\n\n\t\tfor (const shardId of shardIds) {\n\t\t\tconst strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions);\n\t\t\tconst shard = new WebSocketShard(strategy, shardId);\n\t\t\tfor (const event of Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Intentional\n\t\t\t\tshard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId }));\n\t\t\t}\n\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.connect}\n\t */\n\tpublic async connect() {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.connect());\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.destroy}\n\t */\n\tpublic async destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\tconst promises = [];\n\n\t\tfor (const shard of this.shards.values()) {\n\t\t\tpromises.push(shard.destroy(options));\n\t\t}\n\n\t\tawait Promise.all(promises);\n\t\tthis.shards.clear();\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.send}\n\t */\n\tpublic async send(shardId: number, payload: GatewaySendPayload) {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} not found`);\n\t\t}\n\n\t\treturn shard.send(payload);\n\t}\n\n\t/**\n\t * {@inheritDoc IShardingStrategy.fetchStatus}\n\t */\n\tpublic async fetchStatus() {\n\t\treturn this.shards.mapValues((shard) => shard.status);\n\t}\n}\n","/* eslint-disable id-length */\nimport { Buffer } from 'node:buffer';\nimport { once } from 'node:events';\nimport { clearInterval, clearTimeout, setInterval, setTimeout } from 'node:timers';\nimport { setTimeout as sleep } from 'node:timers/promises';\nimport { URLSearchParams } from 'node:url';\nimport { TextDecoder } from 'node:util';\nimport { inflate } from 'node:zlib';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tGatewayCloseCodes,\n\tGatewayDispatchEvents,\n\tGatewayOpcodes,\n\ttype GatewayDispatchPayload,\n\ttype GatewayIdentifyData,\n\ttype GatewayReadyDispatchData,\n\ttype GatewayReceivePayload,\n\ttype GatewaySendPayload,\n} from 'discord-api-types/v10';\nimport { WebSocket, type Data } from 'ws';\nimport type { Inflate } from 'zlib-sync';\nimport type { IContextFetchingStrategy } from '../strategies/context/IContextFetchingStrategy.js';\nimport { ImportantGatewayOpcodes, getInitialSendRateLimitState } from '../utils/constants.js';\nimport type { SessionInfo } from './WebSocketManager.js';\n\n// eslint-disable-next-line promise/prefer-await-to-then\nconst getZlibSync = lazy(async () => import('zlib-sync').then((mod) => mod.default).catch(() => null));\n\nexport enum WebSocketShardEvents {\n\tClosed = 'closed',\n\tDebug = 'debug',\n\tDispatch = 'dispatch',\n\tError = 'error',\n\tHeartbeatComplete = 'heartbeat',\n\tHello = 'hello',\n\tReady = 'ready',\n\tResumed = 'resumed',\n}\n\nexport enum WebSocketShardStatus {\n\tIdle,\n\tConnecting,\n\tResuming,\n\tReady,\n}\n\nexport enum WebSocketShardDestroyRecovery {\n\tReconnect,\n\tResume,\n}\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type WebSocketShardEventsMap = {\n\t[WebSocketShardEvents.Closed]: [{ code: number }];\n\t[WebSocketShardEvents.Debug]: [payload: { message: string }];\n\t[WebSocketShardEvents.Dispatch]: [payload: { data: GatewayDispatchPayload }];\n\t[WebSocketShardEvents.Error]: [payload: { error: Error }];\n\t[WebSocketShardEvents.Hello]: [];\n\t[WebSocketShardEvents.Ready]: [payload: { data: GatewayReadyDispatchData }];\n\t[WebSocketShardEvents.Resumed]: [];\n\t[WebSocketShardEvents.HeartbeatComplete]: [payload: { ackAt: number; heartbeatAt: number; latency: number }];\n};\n\nexport interface WebSocketShardDestroyOptions {\n\tcode?: number;\n\treason?: string;\n\trecover?: WebSocketShardDestroyRecovery;\n}\n\nexport enum CloseCodes {\n\tNormal = 1_000,\n\tResuming = 4_200,\n}\n\nexport interface SendRateLimitState {\n\tremaining: number;\n\tresetAt: number;\n}\n\n// TODO(vladfrangu): enable this once https://github.com/oven-sh/bun/issues/3392 is solved\n// const WebSocketConstructor: typeof WebSocket = shouldUseGlobalFetchAndWebSocket()\n// \t? (globalThis as any).WebSocket\n// \t: WebSocket;\nconst WebSocketConstructor: typeof WebSocket = WebSocket;\n\nexport class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {\n\tprivate connection: WebSocket | null = null;\n\n\tprivate useIdentifyCompress = false;\n\n\tprivate inflate: Inflate | null = null;\n\n\tprivate readonly textDecoder = new TextDecoder();\n\n\tprivate replayedEvents = 0;\n\n\tprivate isAck = true;\n\n\tprivate sendRateLimitState: SendRateLimitState = getInitialSendRateLimitState();\n\n\tprivate initialHeartbeatTimeoutController: AbortController | null = null;\n\n\tprivate heartbeatInterval: NodeJS.Timer | null = null;\n\n\tprivate lastHeartbeatAt = -1;\n\n\t// Indicates whether the shard has already resolved its original connect() call\n\tprivate initialConnectResolved = false;\n\n\t// Indicates if we failed to connect to the ws url (ECONNREFUSED/ECONNRESET)\n\tprivate failedToConnectDueToNetworkError = false;\n\n\tprivate readonly sendQueue = new AsyncQueue();\n\n\tprivate readonly timeoutAbortControllers = new Collection<WebSocketShardEvents, AbortController>();\n\n\tprivate readonly strategy: IContextFetchingStrategy;\n\n\tpublic readonly id: number;\n\n\t#status: WebSocketShardStatus = WebSocketShardStatus.Idle;\n\n\tpublic get status(): WebSocketShardStatus {\n\t\treturn this.#status;\n\t}\n\n\tpublic constructor(strategy: IContextFetchingStrategy, id: number) {\n\t\tsuper();\n\t\tthis.strategy = strategy;\n\t\tthis.id = id;\n\t}\n\n\tpublic async connect() {\n\t\tconst controller = new AbortController();\n\t\tlet promise;\n\n\t\tif (!this.initialConnectResolved) {\n\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\tpromise = Promise.race([\n\t\t\t\tonce(this, WebSocketShardEvents.Ready, { signal: controller.signal }),\n\t\t\t\tonce(this, WebSocketShardEvents.Resumed, { signal: controller.signal }),\n\t\t\t]);\n\t\t}\n\n\t\tvoid this.internalConnect();\n\n\t\ttry {\n\t\t\tawait promise;\n\t\t} catch ({ error }: any) {\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// cleanup hanging listeners\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.initialConnectResolved = true;\n\t}\n\n\tprivate async internalConnect() {\n\t\tif (this.#status !== WebSocketShardStatus.Idle) {\n\t\t\tthrow new Error(\"Tried to connect a shard that wasn't idle\");\n\t\t}\n\n\t\tconst { version, encoding, compression } = this.strategy.options;\n\t\tconst params = new URLSearchParams({ v: version, encoding });\n\t\tif (compression) {\n\t\t\tconst zlib = await getZlibSync();\n\t\t\tif (zlib) {\n\t\t\t\tparams.append('compress', compression);\n\t\t\t\tthis.inflate = new zlib.Inflate({\n\t\t\t\t\tchunkSize: 65_535,\n\t\t\t\t\tto: 'string',\n\t\t\t\t});\n\t\t\t} else if (!this.useIdentifyCompress) {\n\t\t\t\tthis.useIdentifyCompress = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'WebSocketShard: Compression is enabled but zlib-sync is not installed, falling back to identify compress',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\n\t\tthis.debug([`Connecting to ${url}`]);\n\n\t\tconst connection = new WebSocketConstructor(url, {\n\t\t\thandshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined,\n\t\t});\n\n\t\tconnection.binaryType = 'arraybuffer';\n\n\t\tconnection.onmessage = (event) => {\n\t\t\tvoid this.onMessage(event.data, event.data instanceof ArrayBuffer);\n\t\t};\n\n\t\tconnection.onerror = (event) => {\n\t\t\tthis.onError(event.error);\n\t\t};\n\n\t\tconnection.onclose = (event) => {\n\t\t\tvoid this.onClose(event.code);\n\t\t};\n\n\t\tthis.connection = connection;\n\n\t\tthis.#status = WebSocketShardStatus.Connecting;\n\n\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\n\t\tconst { ok } = await this.waitForEvent(WebSocketShardEvents.Hello, this.strategy.options.helloTimeout);\n\t\tif (!ok) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (session?.shardCount === this.strategy.options.shardCount) {\n\t\t\tawait this.resume(session);\n\t\t} else {\n\t\t\tawait this.identify();\n\t\t}\n\t}\n\n\tpublic async destroy(options: WebSocketShardDestroyOptions = {}) {\n\t\tif (this.#status === WebSocketShardStatus.Idle) {\n\t\t\tthis.debug(['Tried to destroy a shard that was idle']);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!options.code) {\n\t\t\toptions.code = options.recover === WebSocketShardDestroyRecovery.Resume ? CloseCodes.Resuming : CloseCodes.Normal;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Destroying shard',\n\t\t\t`Reason: ${options.reason ?? 'none'}`,\n\t\t\t`Code: ${options.code}`,\n\t\t\t`Recover: ${options.recover === undefined ? 'none' : WebSocketShardDestroyRecovery[options.recover]!}`,\n\t\t]);\n\n\t\t// Reset state\n\t\tthis.isAck = true;\n\t\tif (this.heartbeatInterval) {\n\t\t\tclearInterval(this.heartbeatInterval);\n\t\t}\n\n\t\tif (this.initialHeartbeatTimeoutController) {\n\t\t\tthis.initialHeartbeatTimeoutController.abort();\n\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t}\n\n\t\tthis.lastHeartbeatAt = -1;\n\n\t\tfor (const controller of this.timeoutAbortControllers.values()) {\n\t\t\tcontroller.abort();\n\t\t}\n\n\t\tthis.timeoutAbortControllers.clear();\n\n\t\tthis.failedToConnectDueToNetworkError = false;\n\n\t\t// Clear session state if applicable\n\t\tif (options.recover !== WebSocketShardDestroyRecovery.Resume) {\n\t\t\tawait this.strategy.updateSessionInfo(this.id, null);\n\t\t}\n\n\t\tif (this.connection) {\n\t\t\t// No longer need to listen to messages\n\t\t\tthis.connection.onmessage = null;\n\t\t\t// Prevent a reconnection loop by unbinding the main close event\n\t\t\tthis.connection.onclose = null;\n\n\t\t\tconst shouldClose = this.connection.readyState === WebSocket.OPEN;\n\n\t\t\tthis.debug([\n\t\t\t\t'Connection status during destroy',\n\t\t\t\t`Needs closing: ${shouldClose}`,\n\t\t\t\t`Ready state: ${this.connection.readyState}`,\n\t\t\t]);\n\n\t\t\tif (shouldClose) {\n\t\t\t\tlet outerResolve: () => void;\n\t\t\t\tconst promise = new Promise<void>((resolve) => {\n\t\t\t\t\touterResolve = resolve;\n\t\t\t\t});\n\n\t\t\t\tthis.connection.onclose = outerResolve!;\n\n\t\t\t\tthis.connection.close(options.code, options.reason);\n\n\t\t\t\tawait promise;\n\t\t\t\tthis.emit(WebSocketShardEvents.Closed, { code: options.code });\n\t\t\t}\n\n\t\t\t// Lastly, remove the error event.\n\t\t\t// Doing this earlier would cause a hard crash in case an error event fired on our `close` call\n\t\t\tthis.connection.onerror = null;\n\t\t} else {\n\t\t\tthis.debug(['Destroying a shard that has no connection; please open an issue on GitHub']);\n\t\t}\n\n\t\tthis.#status = WebSocketShardStatus.Idle;\n\n\t\tif (options.recover !== undefined) {\n\t\t\t// There's cases (like no internet connection) where we immediately fail to connect,\n\t\t\t// causing a very fast and draining reconnection loop.\n\t\t\tawait sleep(500);\n\t\t\treturn this.internalConnect();\n\t\t}\n\t}\n\n\tprivate async waitForEvent(event: WebSocketShardEvents, timeoutDuration?: number | null): Promise<{ ok: boolean }> {\n\t\tthis.debug([`Waiting for event ${event} ${timeoutDuration ? `for ${timeoutDuration}ms` : 'indefinitely'}`]);\n\t\tconst timeoutController = new AbortController();\n\t\tconst timeout = timeoutDuration ? setTimeout(() => timeoutController.abort(), timeoutDuration).unref() : null;\n\n\t\tthis.timeoutAbortControllers.set(event, timeoutController);\n\n\t\tconst closeController = new AbortController();\n\n\t\ttry {\n\t\t\t// If the first promise resolves, all is well. If the 2nd promise resolves,\n\t\t\t// the shard has meanwhile closed. In that case, a destroy is already ongoing, so we just need to\n\t\t\t// return false. Meanwhile, if something rejects (error event) or the first controller is aborted,\n\t\t\t// we enter the catch block and trigger a destroy there.\n\t\t\tconst closed = await Promise.race<boolean>([\n\t\t\t\tonce(this, event, { signal: timeoutController.signal }).then(() => false),\n\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: closeController.signal }).then(() => true),\n\t\t\t]);\n\n\t\t\treturn { ok: !closed };\n\t\t} catch {\n\t\t\t// If we're here because of other reasons, we need to destroy the shard\n\t\t\tvoid this.destroy({\n\t\t\t\tcode: CloseCodes.Normal,\n\t\t\t\treason: 'Something timed out or went wrong while waiting for an event',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t});\n\n\t\t\treturn { ok: false };\n\t\t} finally {\n\t\t\tif (timeout) {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t}\n\n\t\t\tthis.timeoutAbortControllers.delete(event);\n\n\t\t\t// Clean up the close listener to not leak memory\n\t\t\tif (!closeController.signal.aborted) {\n\t\t\t\tcloseController.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async send(payload: GatewaySendPayload): Promise<void> {\n\t\tif (!this.connection) {\n\t\t\tthrow new Error(\"WebSocketShard wasn't connected\");\n\t\t}\n\n\t\tif (this.#status !== WebSocketShardStatus.Ready && !ImportantGatewayOpcodes.has(payload.op)) {\n\t\t\tthis.debug(['Tried to send a non-crucial payload before the shard was ready, waiting']);\n\t\t\t// This will throw if the shard throws an error event in the meantime, just requeue the payload\n\t\t\ttry {\n\t\t\t\tawait once(this, WebSocketShardEvents.Ready);\n\t\t\t} catch {\n\t\t\t\treturn this.send(payload);\n\t\t\t}\n\t\t}\n\n\t\tawait this.sendQueue.wait();\n\n\t\tif (--this.sendRateLimitState.remaining <= 0) {\n\t\t\tconst now = Date.now();\n\n\t\t\tif (this.sendRateLimitState.resetAt > now) {\n\t\t\t\tconst sleepFor = this.sendRateLimitState.resetAt - now;\n\n\t\t\t\tthis.debug([`Was about to hit the send rate limit, sleeping for ${sleepFor}ms`]);\n\t\t\t\tconst controller = new AbortController();\n\n\t\t\t\t// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn\n\t\t\t\tconst interrupted = await Promise.race([\n\t\t\t\t\tsleep(sleepFor).then(() => false),\n\t\t\t\t\tonce(this, WebSocketShardEvents.Closed, { signal: controller.signal }).then(() => true),\n\t\t\t\t]);\n\n\t\t\t\tif (interrupted) {\n\t\t\t\t\tthis.debug(['Connection closed while waiting for the send rate limit to reset, re-queueing payload']);\n\t\t\t\t\tthis.sendQueue.shift();\n\t\t\t\t\treturn this.send(payload);\n\t\t\t\t}\n\n\t\t\t\t// This is so the listener from the `once` call is removed\n\t\t\t\tcontroller.abort();\n\t\t\t}\n\n\t\t\tthis.sendRateLimitState = getInitialSendRateLimitState();\n\t\t}\n\n\t\tthis.sendQueue.shift();\n\t\tthis.connection.send(JSON.stringify(payload));\n\t}\n\n\tprivate async identify() {\n\t\tthis.debug(['Waiting for identify throttle']);\n\n\t\tconst controller = new AbortController();\n\t\tconst closeHandler = () => {\n\t\t\tcontroller.abort();\n\t\t};\n\n\t\tthis.on(WebSocketShardEvents.Closed, closeHandler);\n\n\t\ttry {\n\t\t\tawait this.strategy.waitForIdentify(this.id, controller.signal);\n\t\t} catch {\n\t\t\tif (controller.signal.aborted) {\n\t\t\t\tthis.debug(['Was waiting for an identify, but the shard closed in the meantime']);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.debug([\n\t\t\t\t'IContextFetchingStrategy#waitForIdentify threw an unknown error.',\n\t\t\t\t\"If you're using a custom strategy, this is probably nothing to worry about.\",\n\t\t\t\t\"If you're not, please open an issue on GitHub.\",\n\t\t\t]);\n\n\t\t\tawait this.destroy({\n\t\t\t\treason: 'Identify throttling logic failed',\n\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.off(WebSocketShardEvents.Closed, closeHandler);\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Identifying',\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t\t`shard count: ${this.strategy.options.shardCount}`,\n\t\t\t`intents: ${this.strategy.options.intents}`,\n\t\t\t`compression: ${this.inflate ? 'zlib-stream' : this.useIdentifyCompress ? 'identify' : 'none'}`,\n\t\t]);\n\n\t\tconst d: GatewayIdentifyData = {\n\t\t\ttoken: this.strategy.options.token,\n\t\t\tproperties: this.strategy.options.identifyProperties,\n\t\t\tintents: this.strategy.options.intents,\n\t\t\tcompress: this.useIdentifyCompress,\n\t\t\tshard: [this.id, this.strategy.options.shardCount],\n\t\t};\n\n\t\tif (this.strategy.options.largeThreshold) {\n\t\t\td.large_threshold = this.strategy.options.largeThreshold;\n\t\t}\n\n\t\tif (this.strategy.options.initialPresence) {\n\t\t\td.presence = this.strategy.options.initialPresence;\n\t\t}\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Identify,\n\t\t\td,\n\t\t});\n\n\t\tawait this.waitForEvent(WebSocketShardEvents.Ready, this.strategy.options.readyTimeout);\n\t}\n\n\tprivate async resume(session: SessionInfo) {\n\t\tthis.debug([\n\t\t\t'Resuming session',\n\t\t\t`resume url: ${session.resumeURL}`,\n\t\t\t`sequence: ${session.sequence}`,\n\t\t\t`shard id: ${this.id.toString()}`,\n\t\t]);\n\n\t\tthis.#status = WebSocketShardStatus.Resuming;\n\t\tthis.replayedEvents = 0;\n\t\treturn this.send({\n\t\t\top: GatewayOpcodes.Resume,\n\t\t\td: {\n\t\t\t\ttoken: this.strategy.options.token,\n\t\t\t\tseq: session.sequence,\n\t\t\t\tsession_id: session.sessionId,\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate async heartbeat(requested = false) {\n\t\tif (!this.isAck && !requested) {\n\t\t\treturn this.destroy({ reason: 'Zombie connection', recover: WebSocketShardDestroyRecovery.Resume });\n\t\t}\n\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tawait this.send({\n\t\t\top: GatewayOpcodes.Heartbeat,\n\t\t\td: session?.sequence ?? null,\n\t\t});\n\n\t\tthis.lastHeartbeatAt = Date.now();\n\t\tthis.isAck = false;\n\t}\n\n\tprivate async unpackMessage(data: Data, isBinary: boolean): Promise<GatewayReceivePayload | null> {\n\t\t// Deal with no compression\n\t\tif (!isBinary) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(data as string) as GatewayReceivePayload;\n\t\t\t} catch {\n\t\t\t\t// This is a non-JSON payload / (at the time of writing this comment) emitted by bun wrongly interpreting custom close codes https://github.com/oven-sh/bun/issues/3392\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tconst decompressable = new Uint8Array(data as ArrayBuffer);\n\n\t\t// Deal with identify compress\n\t\tif (this.useIdentifyCompress) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\t\t\t\tinflate(decompressable, { chunkSize: 65_535 }, (err, result) => {\n\t\t\t\t\tif (err) {\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(JSON.parse(this.textDecoder.decode(result)) as GatewayReceivePayload);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// Deal with gw wide zlib-stream compression\n\t\tif (this.inflate) {\n\t\t\tconst l = decompressable.length;\n\t\t\tconst flush =\n\t\t\t\tl >= 4 &&\n\t\t\t\tdecompressable[l - 4] === 0x00 &&\n\t\t\t\tdecompressable[l - 3] === 0x00 &&\n\t\t\t\tdecompressable[l - 2] === 0xff &&\n\t\t\t\tdecompressable[l - 1] === 0xff;\n\n\t\t\tconst zlib = (await getZlibSync())!;\n\t\t\tthis.inflate.push(Buffer.from(decompressable), flush ? zlib.Z_SYNC_FLUSH : zlib.Z_NO_FLUSH);\n\n\t\t\tif (this.inflate.err) {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error(`${this.inflate.err}${this.inflate.msg ? `: ${this.inflate.msg}` : ''}`),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!flush) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { result } = this.inflate;\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn JSON.parse(typeof result === 'string' ? result : this.textDecoder.decode(result)) as GatewayReceivePayload;\n\t\t}\n\n\t\tthis.debug([\n\t\t\t'Received a message we were unable to decompress',\n\t\t\t`isBinary: ${isBinary.toString()}`,\n\t\t\t`useIdentifyCompress: ${this.useIdentifyCompress.toString()}`,\n\t\t\t`inflate: ${Boolean(this.inflate).toString()}`,\n\t\t]);\n\n\t\treturn null;\n\t}\n\n\tprivate async onMessage(data: Data, isBinary: boolean) {\n\t\tconst payload = await this.unpackMessage(data, isBinary);\n\t\tif (!payload) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (payload.op) {\n\t\t\tcase GatewayOpcodes.Dispatch: {\n\t\t\t\tif (this.#status === WebSocketShardStatus.Resuming) {\n\t\t\t\t\tthis.replayedEvents++;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line sonarjs/no-nested-switch\n\t\t\t\tswitch (payload.t) {\n\t\t\t\t\tcase GatewayDispatchEvents.Ready: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\n\t\t\t\t\t\tconst session = {\n\t\t\t\t\t\t\tsequence: payload.s,\n\t\t\t\t\t\t\tsessionId: payload.d.session_id,\n\t\t\t\t\t\t\tshardId: this.id,\n\t\t\t\t\t\t\tshardCount: this.strategy.options.shardCount,\n\t\t\t\t\t\t\tresumeURL: payload.d.resume_gateway_url,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, session);\n\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Ready, { data: payload.d });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase GatewayDispatchEvents.Resumed: {\n\t\t\t\t\t\tthis.#status = WebSocketShardStatus.Ready;\n\t\t\t\t\t\tthis.debug([`Resumed and replayed ${this.replayedEvents} events`]);\n\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Resumed);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (session) {\n\t\t\t\t\tif (payload.s > session.sequence) {\n\t\t\t\t\t\tawait this.strategy.updateSessionInfo(this.id, { ...session, sequence: payload.s });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.debug([\n\t\t\t\t\t\t`Received a ${payload.t} event but no session is available. Session information cannot be re-constructed in this state without a full reconnect`,\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\tthis.emit(WebSocketShardEvents.Dispatch, { data: payload });\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Heartbeat: {\n\t\t\t\tawait this.heartbeat(true);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Reconnect: {\n\t\t\t\tawait this.destroy({\n\t\t\t\t\treason: 'Told to reconnect by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.InvalidSession: {\n\t\t\t\tthis.debug([`Invalid session; will attempt to resume: ${payload.d.toString()}`]);\n\t\t\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\t\t\t\tif (payload.d && session) {\n\t\t\t\t\tawait this.resume(session);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.destroy({\n\t\t\t\t\t\treason: 'Invalid session',\n\t\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.Hello: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Hello);\n\t\t\t\tconst jitter = Math.random();\n\t\t\t\tconst firstWait = Math.floor(payload.d.heartbeat_interval * jitter);\n\t\t\t\tthis.debug([`Preparing first heartbeat of the connection with a jitter of ${jitter}; waiting ${firstWait}ms`]);\n\n\t\t\t\ttry {\n\t\t\t\t\tconst controller = new AbortController();\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = controller;\n\t\t\t\t\tawait sleep(firstWait, undefined, { signal: controller.signal });\n\t\t\t\t} catch {\n\t\t\t\t\tthis.debug(['Cancelled initial heartbeat due to #destroy being called']);\n\t\t\t\t\treturn;\n\t\t\t\t} finally {\n\t\t\t\t\tthis.initialHeartbeatTimeoutController = null;\n\t\t\t\t}\n\n\t\t\t\tawait this.heartbeat();\n\n\t\t\t\tthis.debug([`First heartbeat sent, starting to beat every ${payload.d.heartbeat_interval}ms`]);\n\t\t\t\tthis.heartbeatInterval = setInterval(() => void this.heartbeat(), payload.d.heartbeat_interval);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayOpcodes.HeartbeatAck: {\n\t\t\t\tthis.isAck = true;\n\n\t\t\t\tconst ackAt = Date.now();\n\t\t\t\tthis.emit(WebSocketShardEvents.HeartbeatComplete, {\n\t\t\t\t\tackAt,\n\t\t\t\t\theartbeatAt: this.lastHeartbeatAt,\n\t\t\t\t\tlatency: ackAt - this.lastHeartbeatAt,\n\t\t\t\t});\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onError(error: Error) {\n\t\tif ('code' in error && ['ECONNRESET', 'ECONNREFUSED'].includes(error.code as string)) {\n\t\t\tthis.debug(['Failed to connect to the gateway URL specified due to a network error']);\n\t\t\tthis.failedToConnectDueToNetworkError = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.emit(WebSocketShardEvents.Error, { error });\n\t}\n\n\tprivate async onClose(code: number) {\n\t\tthis.emit(WebSocketShardEvents.Closed, { code });\n\n\t\tswitch (code) {\n\t\t\tcase CloseCodes.Normal: {\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\treason: 'Got disconnected by Discord',\n\t\t\t\t\trecover: WebSocketShardDestroyRecovery.Reconnect,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcase CloseCodes.Resuming: {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownError: {\n\t\t\t\tthis.debug([`An unknown error occurred: ${code}`]);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.UnknownOpcode: {\n\t\t\t\tthis.debug(['An invalid opcode was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DecodeError: {\n\t\t\t\tthis.debug(['An invalid payload was sent to Discord.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.NotAuthenticated: {\n\t\t\t\tthis.debug(['A request was somehow sent before the identify/resume payload.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AuthenticationFailed: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Authentication failed'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.AlreadyAuthenticated: {\n\t\t\t\tthis.debug(['More than one auth payload was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidSeq: {\n\t\t\t\tthis.debug(['An invalid sequence was sent.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.RateLimited: {\n\t\t\t\tthis.debug(['The WebSocket rate limit has been hit, this should never happen']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Reconnect });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.SessionTimedOut: {\n\t\t\t\tthis.debug(['Session timed out.']);\n\t\t\t\treturn this.destroy({ code, recover: WebSocketShardDestroyRecovery.Resume });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidShard: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Invalid shard'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.ShardingRequired: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Sharding is required'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidAPIVersion: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used an invalid API version'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.InvalidIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used invalid intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tcase GatewayCloseCodes.DisallowedIntents: {\n\t\t\t\tthis.emit(WebSocketShardEvents.Error, {\n\t\t\t\t\terror: new Error('Used disallowed intents'),\n\t\t\t\t});\n\t\t\t\treturn this.destroy({ code });\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tthis.debug([\n\t\t\t\t\t`The gateway closed with an unexpected code ${code}, attempting to ${\n\t\t\t\t\t\tthis.failedToConnectDueToNetworkError ? 'reconnect' : 'resume'\n\t\t\t\t\t}.`,\n\t\t\t\t]);\n\t\t\t\treturn this.destroy({\n\t\t\t\t\tcode,\n\t\t\t\t\trecover: this.failedToConnectDueToNetworkError\n\t\t\t\t\t\t? WebSocketShardDestroyRecovery.Reconnect\n\t\t\t\t\t\t: WebSocketShardDestroyRecovery.Resume,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate debug(messages: [string, ...string[]]) {\n\t\tconst message = `${messages[0]}${\n\t\t\tmessages.length > 1\n\t\t\t\t? `\\n${messages\n\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t.map((m) => `\t${m}`)\n\t\t\t\t\t\t.join('\\n')}`\n\t\t\t\t: ''\n\t\t}`;\n\n\t\tthis.emit(WebSocketShardEvents.Debug, { message });\n\t}\n}\n","import process from 'node:process';\nimport { Collection } from '@discordjs/collection';\nimport { lazy } from '@discordjs/util';\nimport { APIVersion, GatewayOpcodes } from 'discord-api-types/v10';\nimport { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy.js';\nimport { SimpleIdentifyThrottler } from '../throttling/SimpleIdentifyThrottler.js';\nimport type { SessionInfo, OptionalWebSocketManagerOptions, WebSocketManager } from '../ws/WebSocketManager.js';\nimport type { SendRateLimitState } from '../ws/WebSocketShard.js';\n\n/**\n * Valid encoding types\n */\nexport enum Encoding {\n\tJSON = 'json',\n}\n\n/**\n * Valid compression methods\n */\nexport enum CompressionMethod {\n\tZlibStream = 'zlib-stream',\n}\n\nexport const DefaultDeviceProperty = `@discordjs/ws 1.0.1` as `@discordjs/ws ${string}`;\n\nconst getDefaultSessionStore = lazy(() => new Collection<number, SessionInfo | null>());\n\n/**\n * Default options used by the manager\n */\nexport const DefaultWebSocketManagerOptions = {\n\tasync buildIdentifyThrottler(manager: WebSocketManager) {\n\t\tconst info = await manager.fetchGatewayInformation();\n\t\treturn new SimpleIdentifyThrottler(info.session_start_limit.max_concurrency);\n\t},\n\tbuildStrategy: (manager) => new SimpleShardingStrategy(manager),\n\tshardCount: null,\n\tshardIds: null,\n\tlargeThreshold: null,\n\tinitialPresence: null,\n\tidentifyProperties: {\n\t\tbrowser: DefaultDeviceProperty,\n\t\tdevice: DefaultDeviceProperty,\n\t\tos: process.platform,\n\t},\n\tversion: APIVersion,\n\tencoding: Encoding.JSON,\n\tcompression: null,\n\tretrieveSessionInfo(shardId) {\n\t\tconst store = getDefaultSessionStore();\n\t\treturn store.get(shardId) ?? null;\n\t},\n\tupdateSessionInfo(shardId: number, info: SessionInfo | null) {\n\t\tconst store = getDefaultSessionStore();\n\t\tif (info) {\n\t\t\tstore.set(shardId, info);\n\t\t} else {\n\t\t\tstore.delete(shardId);\n\t\t}\n\t},\n\thandshakeTimeout: 30_000,\n\thelloTimeout: 60_000,\n\treadyTimeout: 15_000,\n} as const satisfies OptionalWebSocketManagerOptions;\n\nexport const ImportantGatewayOpcodes = new Set([\n\tGatewayOpcodes.Heartbeat,\n\tGatewayOpcodes.Identify,\n\tGatewayOpcodes.Resume,\n]);\n\nexport function getInitialSendRateLimitState(): SendRateLimitState {\n\treturn {\n\t\tremaining: 120,\n\t\tresetAt: Date.now() + 60_000,\n\t};\n}\n","import { setTimeout as sleep } from 'node:timers/promises';\nimport { Collection } from '@discordjs/collection';\nimport { AsyncQueue } from '@sapphire/async-queue';\nimport type { IIdentifyThrottler } from './IIdentifyThrottler.js';\n\n/**\n * The state of a rate limit key's identify queue.\n */\nexport interface IdentifyState {\n\tqueue: AsyncQueue;\n\tresetsAt: number;\n}\n\n/**\n * Local, in-memory identify throttler.\n */\nexport class SimpleIdentifyThrottler implements IIdentifyThrottler {\n\tprivate readonly states = new Collection<number, IdentifyState>();\n\n\tpublic constructor(private readonly maxConcurrency: number) {}\n\n\t/**\n\t * {@inheritDoc IIdentifyThrottler.waitForIdentify}\n\t */\n\tpublic async waitForIdentify(shardId: number, signal: AbortSignal): Promise<void> {\n\t\tconst key = shardId % this.maxConcurrency;\n\n\t\tconst state = this.states.ensure(key, () => {\n\t\t\treturn {\n\t\t\t\tqueue: new AsyncQueue(),\n\t\t\t\tresetsAt: Number.POSITIVE_INFINITY,\n\t\t\t};\n\t\t});\n\n\t\tawait state.queue.wait({ signal });\n\n\t\ttry {\n\t\t\tconst diff = state.resetsAt - Date.now();\n\t\t\tif (diff <= 5_000) {\n\t\t\t\t// To account for the latency the IDENTIFY payload goes through, we add a bit more wait time\n\t\t\t\tconst time = diff + Math.random() * 1_500;\n\t\t\t\tawait sleep(time);\n\t\t\t}\n\n\t\t\tstate.resetsAt = Date.now() + 5_000;\n\t\t} finally {\n\t\t\tstate.queue.shift();\n\t\t}\n\t}\n}\n","import { isMainThread, parentPort, workerData } from 'node:worker_threads';\nimport { Collection } from '@discordjs/collection';\nimport type { Awaitable } from '@discordjs/util';\nimport { WorkerContextFetchingStrategy } from '../strategies/context/WorkerContextFetchingStrategy.js';\nimport {\n\tWorkerReceivePayloadOp,\n\tWorkerSendPayloadOp,\n\ttype WorkerData,\n\ttype WorkerReceivePayload,\n\ttype WorkerSendPayload,\n} from '../strategies/sharding/WorkerShardingStrategy.js';\nimport type { WebSocketShardDestroyOptions } from '../ws/WebSocketShard.js';\nimport { WebSocketShardEvents, WebSocketShard } from '../ws/WebSocketShard.js';\n\n/**\n * Options for bootstrapping the worker\n */\nexport interface BootstrapOptions {\n\t/**\n\t * Shard events to just arbitrarily forward to the parent thread for the manager to emit\n\t * Note: By default, this will include ALL events\n\t * you most likely want to handle dispatch within the worker itself\n\t */\n\tforwardEvents?: WebSocketShardEvents[];\n\t/**\n\t * Function to call when a shard is created for additional setup\n\t */\n\tshardCallback?(shard: WebSocketShard): Awaitable<void>;\n}\n\n/**\n * Utility class for bootstrapping a worker thread to be used for sharding\n */\nexport class WorkerBootstrapper {\n\t/**\n\t * The data passed to the worker thread\n\t */\n\tprotected readonly data = workerData as WorkerData;\n\n\t/**\n\t * The shards that are managed by this worker\n\t */\n\tprotected readonly shards = new Collection<number, WebSocketShard>();\n\n\tpublic constructor() {\n\t\tif (isMainThread) {\n\t\t\tthrow new Error('Expected WorkerBootstrap to not be used within the main thread');\n\t\t}\n\t}\n\n\t/**\n\t * Helper method to initiate a shard's connection process\n\t */\n\tprotected async connect(shardId: number): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.connect();\n\t}\n\n\t/**\n\t * Helper method to destroy a shard\n\t */\n\tprotected async destroy(shardId: number, options?: WebSocketShardDestroyOptions): Promise<void> {\n\t\tconst shard = this.shards.get(shardId);\n\t\tif (!shard) {\n\t\t\tthrow new RangeError(`Shard ${shardId} does not exist`);\n\t\t}\n\n\t\tawait shard.destroy(options);\n\t}\n\n\t/**\n\t * Helper method to attach event listeners to the parentPort\n\t */\n\tprotected setupThreadEvents(): void {\n\t\tparentPort!\n\t\t\t.on('messageerror', (err) => {\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.on('message', async (payload: WorkerSendPayload) => {\n\t\t\t\tswitch (payload.op) {\n\t\t\t\t\tcase WorkerSendPayloadOp.Connect: {\n\t\t\t\t\t\tawait this.connect(payload.shardId);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Connected,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Destroy: {\n\t\t\t\t\t\tawait this.destroy(payload.shardId, payload.options);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Destroyed,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Send: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new RangeError(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait shard.send(payload.payload);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.SessionInfoResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.ShardIdentifyResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.FetchStatus: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new Error(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.FetchStatusResponse,\n\t\t\t\t\t\t\tstatus: shard.status,\n\t\t\t\t\t\t\tnonce: payload.nonce,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\t/**\n\t * Bootstraps the worker thread with the provided options\n\t */\n\tpublic async bootstrap(options: Readonly<BootstrapOptions> = {}): Promise<void> {\n\t\t// Start by initializing the shards\n\t\tfor (const shardId of this.data.shardIds) {\n\t\t\tconst shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId);\n\t\t\tfor (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) {\n\t\t\t\t// @ts-expect-error: Event types incompatible\n\t\t\t\tshard.on(event, (data) => {\n\t\t\t\t\tconst payload: WorkerReceivePayload = {\n\t\t\t\t\t\top: WorkerReceivePayloadOp.Event,\n\t\t\t\t\t\tevent,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tshardId,\n\t\t\t\t\t};\n\t\t\t\t\tparentPort!.postMessage(payload);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Any additional setup the user might want to do\n\t\t\tawait options.shardCallback?.(shard);\n\t\t\tthis.shards.set(shardId, shard);\n\t\t}\n\n\t\t// Lastly, start listening to messages from the parent thread\n\t\tthis.setupThreadEvents();\n\n\t\tconst message: WorkerReceivePayload = {\n\t\t\top: WorkerReceivePayloadOp.WorkerReady,\n\t\t};\n\t\tparentPort!.postMessage(message);\n\t}\n}\n","import type { REST } from '@discordjs/rest';\nimport { range, type Awaitable } from '@discordjs/util';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport {\n\tRoutes,\n\ttype APIGatewayBotInfo,\n\ttype GatewayIdentifyProperties,\n\ttype GatewayPresenceUpdateData,\n\ttype RESTGetAPIGatewayBotResult,\n\ttype GatewayIntentBits,\n\ttype GatewaySendPayload,\n} from 'discord-api-types/v10';\nimport type { IShardingStrategy } from '../strategies/sharding/IShardingStrategy.js';\nimport type { IIdentifyThrottler } from '../throttling/IIdentifyThrottler.js';\nimport { DefaultWebSocketManagerOptions, type CompressionMethod, type Encoding } from '../utils/constants.js';\nimport type { WebSocketShardDestroyOptions, WebSocketShardEventsMap } from './WebSocketShard.js';\n\n/**\n * Represents a range of shard ids\n */\nexport interface ShardRange {\n\tend: number;\n\tstart: number;\n}\n\n/**\n * Session information for a given shard, used to resume a session\n */\nexport interface SessionInfo {\n\t/**\n\t * URL to use when resuming\n\t */\n\tresumeURL: string;\n\t/**\n\t * The sequence number of the last message sent by the shard\n\t */\n\tsequence: number;\n\t/**\n\t * Session id for this shard\n\t */\n\tsessionId: string;\n\t/**\n\t * The total number of shards at the time of this shard identifying\n\t */\n\tshardCount: number;\n\t/**\n\t * The id of the shard\n\t */\n\tshardId: number;\n}\n\n/**\n * Required options for the WebSocketManager\n */\nexport interface RequiredWebSocketManagerOptions {\n\t/**\n\t * The intents to request\n\t */\n\tintents: GatewayIntentBits | 0;\n\t/**\n\t * The REST instance to use for fetching gateway information\n\t */\n\trest: REST;\n\t/**\n\t * The token to use for identifying with the gateway\n\t */\n\ttoken: string;\n}\n\n/**\n * Optional additional configuration for the WebSocketManager\n */\nexport interface OptionalWebSocketManagerOptions {\n\t/**\n\t * Builds an identify throttler to use for this manager's shards\n\t */\n\tbuildIdentifyThrottler(manager: WebSocketManager): Awaitable<IIdentifyThrottler>;\n\t/**\n\t * Builds the strategy to use for sharding\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * token: process.env.DISCORD_TOKEN,\n\t * intents: 0, // for no intents\n\t * rest,\n\t * buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 }),\n\t * });\n\t * ```\n\t */\n\tbuildStrategy(manager: WebSocketManager): IShardingStrategy;\n\t/**\n\t * The compression method to use\n\t *\n\t * @defaultValue `null` (no compression)\n\t */\n\tcompression: CompressionMethod | null;\n\t/**\n\t * The encoding to use\n\t *\n\t * @defaultValue `'json'`\n\t */\n\tencoding: Encoding;\n\t/**\n\t * How long to wait for a shard to connect before giving up\n\t */\n\thandshakeTimeout: number | null;\n\t/**\n\t * How long to wait for a shard's HELLO packet before giving up\n\t */\n\thelloTimeout: number | null;\n\t/**\n\t * Properties to send to the gateway when identifying\n\t */\n\tidentifyProperties: GatewayIdentifyProperties;\n\t/**\n\t * Initial presence data to send to the gateway when identifying\n\t */\n\tinitialPresence: GatewayPresenceUpdateData | null;\n\t/**\n\t * Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list\n\t */\n\tlargeThreshold: number | null;\n\t/**\n\t * How long to wait for a shard's READY packet before giving up\n\t */\n\treadyTimeout: number | null;\n\t/**\n\t * Function used to retrieve session information (and attempt to resume) for a given shard\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {\n\t * // Fetch this info from redis or similar\n\t * return { sessionId: string, sequence: number };\n\t * // Return null if no information is found\n\t * },\n\t * });\n\t * ```\n\t */\n\tretrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>;\n\t/**\n\t * The total number of shards across all WebsocketManagers you intend to instantiate.\n\t * Use `null` to use Discord's recommended shard count\n\t */\n\tshardCount: number | null;\n\t/**\n\t * The ids of the shards this WebSocketManager should manage.\n\t * Use `null` to simply spawn 0 through `shardCount - 1`\n\t *\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else\n\t * });\n\t * ```\n\t * @example\n\t * ```ts\n\t * const manager = new WebSocketManager({\n\t * shardIds: {\n\t * start: 3,\n\t * end: 6,\n\t * }, // spawns shards 3, 4, 5, and 6\n\t * });\n\t * ```\n\t */\n\tshardIds: number[] | ShardRange | null;\n\t/**\n\t * Function used to store session information for a given shard\n\t */\n\tupdateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>;\n\t/**\n\t * The gateway version to use\n\t *\n\t * @defaultValue `'10'`\n\t */\n\tversion: string;\n}\n\nexport type WebSocketManagerOptions = OptionalWebSocketManagerOptions & RequiredWebSocketManagerOptions;\n\nexport type ManagerShardEventsMap = {\n\t[K in keyof WebSocketShardEventsMap]: [\n\t\tWebSocketShardEventsMap[K] extends [] ? { shardId: number } : WebSocketShardEventsMap[K][0] & { shardId: number },\n\t];\n};\n\nexport class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {\n\t/**\n\t * The options being used by this manager\n\t */\n\tpublic readonly options: WebSocketManagerOptions;\n\n\t/**\n\t * Internal cache for a GET /gateway/bot result\n\t */\n\tprivate gatewayInformation: {\n\t\tdata: APIGatewayBotInfo;\n\t\texpiresAt: number;\n\t} | null = null;\n\n\t/**\n\t * Internal cache for the shard ids\n\t */\n\tprivate shardIds: number[] | null = null;\n\n\t/**\n\t * Strategy used to manage shards\n\t *\n\t * @defaultValue `SimpleShardingStrategy`\n\t */\n\tprivate readonly strategy: IShardingStrategy;\n\n\tpublic constructor(options: Partial<OptionalWebSocketManagerOptions> & RequiredWebSocketManagerOptions) {\n\t\tsuper();\n\t\tthis.options = { ...DefaultWebSocketManagerOptions, ...options };\n\t\tthis.strategy = this.options.buildStrategy(this);\n\t}\n\n\t/**\n\t * Fetches the gateway information from Discord - or returns it from cache if available\n\t *\n\t * @param force - Whether to ignore the cache and force a fresh fetch\n\t */\n\tpublic async fetchGatewayInformation(force = false) {\n\t\tif (this.gatewayInformation) {\n\t\t\tif (this.gatewayInformation.expiresAt <= Date.now()) {\n\t\t\t\tthis.gatewayInformation = null;\n\t\t\t} else if (!force) {\n\t\t\t\treturn this.gatewayInformation.data;\n\t\t\t}\n\t\t}\n\n\t\tconst data = (await this.options.rest.get(Routes.gatewayBot())) as RESTGetAPIGatewayBotResult;\n\n\t\t// For single sharded bots session_start_limit.reset_after will be 0, use 5 seconds as a minimum expiration time\n\t\tthis.gatewayInformation = { data, expiresAt: Date.now() + (data.session_start_limit.reset_after || 5_000) };\n\t\treturn this.gatewayInformation.data;\n\t}\n\n\t/**\n\t * Updates your total shard count on-the-fly, spawning shards as needed\n\t *\n\t * @param shardCount - The new shard count to use\n\t */\n\tpublic async updateShardCount(shardCount: number | null) {\n\t\tawait this.strategy.destroy({ reason: 'User is adjusting their shards' });\n\t\tthis.options.shardCount = shardCount;\n\n\t\tconst shardIds = await this.getShardIds(true);\n\t\tawait this.strategy.spawn(shardIds);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Yields the total number of shards across for your bot, accounting for Discord recommendations\n\t */\n\tpublic async getShardCount(): Promise<number> {\n\t\tif (this.options.shardCount) {\n\t\t\treturn this.options.shardCount;\n\t\t}\n\n\t\tconst shardIds = await this.getShardIds();\n\t\treturn Math.max(...shardIds) + 1;\n\t}\n\n\t/**\n\t * Yields the ids of the shards this manager should manage\n\t */\n\tpublic async getShardIds(force = false): Promise<number[]> {\n\t\tif (this.shardIds && !force) {\n\t\t\treturn this.shardIds;\n\t\t}\n\n\t\tlet shardIds: number[];\n\t\tif (this.options.shardIds) {\n\t\t\tif (Array.isArray(this.options.shardIds)) {\n\t\t\t\tshardIds = this.options.shardIds;\n\t\t\t} else {\n\t\t\t\tconst { start, end } = this.options.shardIds;\n\t\t\t\tshardIds = [...range({ start, end: end + 1 })];\n\t\t\t}\n\t\t} else {\n\t\t\tconst data = await this.fetchGatewayInformation();\n\t\t\tshardIds = [...range(this.options.shardCount ?? data.shards)];\n\t\t}\n\n\t\tthis.shardIds = shardIds;\n\t\treturn shardIds;\n\t}\n\n\tpublic async connect() {\n\t\tconst shardCount = await this.getShardCount();\n\n\t\tconst data = await this.fetchGatewayInformation();\n\t\tif (data.session_start_limit.remaining < shardCount) {\n\t\t\tthrow new Error(\n\t\t\t\t`Not enough sessions remaining to spawn ${shardCount} shards; only ${\n\t\t\t\t\tdata.session_start_limit.remaining\n\t\t\t\t} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`,\n\t\t\t);\n\t\t}\n\n\t\t// First, make sure all our shards are spawned\n\t\tawait this.updateShardCount(shardCount);\n\t\tawait this.strategy.connect();\n\t}\n\n\tpublic destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {\n\t\treturn this.strategy.destroy(options);\n\t}\n\n\tpublic send(shardId: number, payload: GatewaySendPayload) {\n\t\treturn this.strategy.send(shardId, payload);\n\t}\n\n\tpublic fetchStatus() {\n\t\treturn this.strategy.fetchStatus();\n\t}\n}\n","export * from './strategies/context/IContextFetchingStrategy.js';\nexport * from './strategies/context/SimpleContextFetchingStrategy.js';\nexport * from './strategies/context/WorkerContextFetchingStrategy.js';\n\nexport * from './strategies/sharding/IShardingStrategy.js';\nexport * from './strategies/sharding/SimpleShardingStrategy.js';\nexport * from './strategies/sharding/WorkerShardingStrategy.js';\n\nexport * from './throttling/IIdentifyThrottler.js';\nexport * from './throttling/SimpleIdentifyThrottler.js';\n\nexport * from './utils/constants.js';\nexport * from './utils/WorkerBootstrapper.js';\n\nexport * from './ws/WebSocketManager.js';\nexport * from './ws/WebSocketShard.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/ws/#readme | @discordjs/ws} version\n * that you are currently using.\n */\n// This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild\nexport const version = '1.0.1' as string;\n"],"mappings":";;;;;;;;;;;AACA,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAEj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MAC9C;AAAA,IACD,OAAO;AACN,YAAM,OAAO,MAAM,KAAK,wBAAwB;AAChD,iBAAW,CAAC,GAAG,MAAM,KAAK,QAAQ,cAAc,KAAK,MAAM,CAAC;AAAA,IAC7D;AAEA,SAAK,WAAW;AAChB,WAAO;AAAA,EACR;AAAA,EAEA,MAAa,UAAU;AACtB,UAAM,aAAa,MAAM,KAAK,cAAc;AAE5C,UAAM,OAAO,MAAM,KAAK,wBAAwB;AAChD,QAAI,KAAK,oBAAoB,YAAY,YAAY;AACpD,YAAM,IAAI;AAAA,QACT,0CAA0C,UAAU,iBACnD,KAAK,oBAAoB,SAC1B,yBAAyB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,oBAAoB,WAAW,EAAE,YAAY,CAAC;AAAA,MACnG;AAAA,IACD;AAGA,UAAM,KAAK,iBAAiB,UAAU;AACtC,UAAM,KAAK,SAAS,QAAQ;AAAA,EAC7B;AAAA,EAEO,QAAQ,SAAyD;AACvE,WAAO,KAAK,SAAS,QAAQ,OAAO;AAAA,EACrC;AAAA,EAEO,KAAK,SAAiB,SAA6B;AACzD,WAAO,KAAK,SAAS,KAAK,SAAS,OAAO;AAAA,EAC3C;AAAA,EAEO,cAAc;AACpB,WAAO,KAAK,SAAS,YAAY;AAAA,EAClC;AACD;;;AC3SO,IAAM,UAAU;","names":["Collection","WorkerSendPayloadOp","WorkerReceivePayloadOp","workerData","resolve","path","Collection","resolve","payload","Collection","Buffer","once","sleep","Collection","lazy","AsyncQueue","GatewayOpcodes","Collection","Collection","Collection","Encoding","CompressionMethod","Collection","lazy","WebSocketShardEvents","WebSocketShardStatus","WebSocketShardDestroyRecovery","CloseCodes","AsyncQueue","Collection","once","version","resolve","sleep","GatewayOpcodes","Buffer","session","Collection","isMainThread","parentPort","Collection","Collection","isMainThread","parentPort","AsyncEventEmitter","AsyncEventEmitter"]}
\ No newline at end of file diff --git a/node_modules/@discordjs/ws/package.json b/node_modules/@discordjs/ws/package.json new file mode 100644 index 0000000..46ba7d4 --- /dev/null +++ b/node_modules/@discordjs/ws/package.json @@ -0,0 +1,99 @@ +{ + "name": "@discordjs/ws", + "version": "1.0.1", + "description": "Wrapper around Discord's gateway", + "scripts": { + "test": "vitest run", + "build": "tsup", + "build:docs": "tsc -p tsconfig.docs.json", + "lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --format=pretty", + "format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix --format=pretty", + "docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json", + "prepack": "yarn build && yarn lint", + "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/ws/*'", + "release": "cliff-jumper" + }, + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "typings": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "./defaultWorker": { + "types": null, + "import": "./dist/defaultWorker.mjs", + "require": "./dist/defaultWorker.js" + } + }, + "directories": { + "lib": "src", + "test": "__tests__" + }, + "files": [ + "dist" + ], + "contributors": [ + "Crawl <icrawltogo@gmail.com>", + "Amish Shah <amishshah.2k@gmail.com>", + "SpaceEEC <spaceeec@yahoo.com>", + "Vlad Frangu <kingdgrizzle@gmail.com>", + "Aura Román <kyradiscord@gmail.com>", + "DD <didinele.dev@gmail.com>" + ], + "license": "Apache-2.0", + "keywords": [ + "discord", + "api", + "gateway", + "discordapp", + "discordjs" + ], + "repository": { + "type": "git", + "url": "https://github.com/discordjs/discord.js.git", + "directory": "packages/ws" + }, + "bugs": { + "url": "https://github.com/discordjs/discord.js/issues" + }, + "homepage": "https://discord.js.org", + "dependencies": { + "@discordjs/collection": "^1.5.3", + "@discordjs/rest": "^2.0.1", + "@discordjs/util": "^1.0.1", + "@sapphire/async-queue": "^1.5.0", + "@types/ws": "^8.5.5", + "@vladfrangu/async_event_emitter": "^2.2.2", + "discord-api-types": "0.37.50", + "tslib": "^2.6.1", + "ws": "^8.13.0" + }, + "devDependencies": { + "@favware/cliff-jumper": "^2.1.1", + "@microsoft/api-extractor": "^7.36.4", + "@types/node": "18.17.5", + "@vitest/coverage-v8": "^0.34.2", + "cross-env": "^7.0.3", + "esbuild-plugin-version-injector": "^1.2.0", + "eslint": "^8.47.0", + "eslint-config-neon": "^0.1.47", + "eslint-formatter-pretty": "^5.0.0", + "mock-socket": "^9.2.1", + "prettier": "^2.8.8", + "tsup": "^7.2.0", + "turbo": "^1.10.12", + "typescript": "^5.1.6", + "undici": "5.22.1", + "vitest": "^0.34.2", + "zlib-sync": "^0.1.8" + }, + "engines": { + "node": ">=16.11.0" + }, + "publishConfig": { + "access": "public" + } +}
\ No newline at end of file |