Finished star board!

This commit is contained in:
Keyemail 2024-05-10 22:39:11 -07:00
parent fbc61f65a3
commit f7b59e3866
2946 changed files with 303079 additions and 18 deletions

5
.gitignore vendored
View file

@ -1,3 +1,6 @@
# IGNORED FILES
# IGNORED FOLDERS
node_modules
# IGNORED FILES
config.json
*.env

3
config.json Normal file
View file

@ -0,0 +1,3 @@
{
"token": "MTIwMTYwMjAxMzE0MjcxMjQzMQ.Gi0l5n.tldSN9fnBzxoWAgtdFBVr8jdXyOxaQKJ2_OOZk"
}

51
main.js
View file

@ -76,29 +76,48 @@ client.on(Events.InteractionCreate, async interaction => {
});
client.on(Events.MessageReactionAdd, async (reaction, user) => {
if (reaction.partial) {
try {
await reaction.fetch();
try {
await reaction.fetch();
console.log(informationStatus + "Reaction noticed!");
const starChannel = client.channels.cache.get(starChannelID);
const starChannel = client.channels.cache.get(starChannelID);
starChannel.send(reaction.message.attachments);
if (reaction.emoji.name == '⭐') {
if (reaction.count <= 1) {
const starEmbed = {
color: 0x0F3061,
author: {
name: reaction.message.author.tag,
icon_url: reaction.message.author.displayAvatarURL(),
},
footer: {
text: new Date().toLocaleString(),
},
};
if (reaction.emoji.name == '⭐') {
const starEmbed = new EmbedBuilder()
//.setImage()
.setDescription(reaction.message.content)
.setAuthor({ name: `${reaction.message.author.tag}` });
starChannel.send({ embeds: [starEmbed] });
if(reaction.message.attachments.first()){
starEmbed.image = {
url: reaction.message.attachments.first().url,
};
}
if(!reaction.message.content == '') {
starEmbed.description = reaction.message.content;
}
starChannel.send({ embeds: [starEmbed] });
console.log(informationStatus + "Star message has been added!");
} else {
return;
}
} catch (error) {
console.log(errorStatus + 'Something wrong happend while fetching reactions for message! Please use information below to debug.');
console.error(error);
}}
} else {
return;
}
} catch(error) {
console.log(errorStatus + 'Something wrong happend while fetching reactions for message! Please use information below to debug.');
console.error(error);
}
);
});
client.login(token);

310
node_modules/.package-lock.json generated vendored Normal file
View file

@ -0,0 +1,310 @@
{
"name": "mbot",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/@discordjs/builders": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.8.1.tgz",
"integrity": "sha512-GkF+HM01FHy+NSoTaUPR8z44otfQgJ1AIsRxclYGUZDyUbdZEFyD/5QVv2Y1Flx6M+B0bQLzg2M9CJv5lGTqpA==",
"dependencies": {
"@discordjs/formatters": "^0.4.0",
"@discordjs/util": "^1.1.0",
"@sapphire/shapeshift": "^3.9.7",
"discord-api-types": "0.37.83",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.4",
"tslib": "^2.6.2"
},
"engines": {
"node": ">=16.11.0"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/collection": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-1.5.3.tgz",
"integrity": "sha512-SVb428OMd3WO1paV3rm6tSjM4wC+Kecaa1EUGX7vc6/fddvw/6lg90z4QtCqm21zvVe92vMMDt9+DkIvjXImQQ==",
"engines": {
"node": ">=16.11.0"
}
},
"node_modules/@discordjs/formatters": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@discordjs/formatters/-/formatters-0.4.0.tgz",
"integrity": "sha512-fJ06TLC1NiruF35470q3Nr1bi95BdvKFAF+T5bNfZJ4bNdqZ3VZ+Ttg6SThqTxm6qumSG3choxLBHMC69WXNXQ==",
"dependencies": {
"discord-api-types": "0.37.83"
},
"engines": {
"node": ">=16.11.0"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/rest": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.3.0.tgz",
"integrity": "sha512-C1kAJK8aSYRv3ZwMG8cvrrW4GN0g5eMdP8AuN8ODH5DyOCbHgJspze1my3xHOAgwLJdKUbWNVyAeJ9cEdduqIg==",
"dependencies": {
"@discordjs/collection": "^2.1.0",
"@discordjs/util": "^1.1.0",
"@sapphire/async-queue": "^1.5.2",
"@sapphire/snowflake": "^3.5.3",
"@vladfrangu/async_event_emitter": "^2.2.4",
"discord-api-types": "0.37.83",
"magic-bytes.js": "^1.10.0",
"tslib": "^2.6.2",
"undici": "6.13.0"
},
"engines": {
"node": ">=16.11.0"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/rest/node_modules/@discordjs/collection": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-2.1.0.tgz",
"integrity": "sha512-mLcTACtXUuVgutoznkh6hS3UFqYirDYAg5Dc1m8xn6OvPjetnUlf/xjtqnnc47OwWdaoCQnHmHh9KofhD6uRqw==",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/util": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@discordjs/util/-/util-1.1.0.tgz",
"integrity": "sha512-IndcI5hzlNZ7GS96RV3Xw1R2kaDuXEp7tRIy/KlhidpN/BQ1qh1NZt3377dMLTa44xDUNKT7hnXkA/oUAzD/lg==",
"engines": {
"node": ">=16.11.0"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/ws": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@discordjs/ws/-/ws-1.1.0.tgz",
"integrity": "sha512-O97DIeSvfNTn5wz5vaER6ciyUsr7nOqSEtsLoMhhIgeFkhnxLRqSr00/Fpq2/ppLgjDGLbQCDzIK7ilGoB/M7A==",
"dependencies": {
"@discordjs/collection": "^2.1.0",
"@discordjs/rest": "^2.3.0",
"@discordjs/util": "^1.1.0",
"@sapphire/async-queue": "^1.5.2",
"@types/ws": "^8.5.10",
"@vladfrangu/async_event_emitter": "^2.2.4",
"discord-api-types": "0.37.83",
"tslib": "^2.6.2",
"ws": "^8.16.0"
},
"engines": {
"node": ">=16.11.0"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/ws/node_modules/@discordjs/collection": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-2.1.0.tgz",
"integrity": "sha512-mLcTACtXUuVgutoznkh6hS3UFqYirDYAg5Dc1m8xn6OvPjetnUlf/xjtqnnc47OwWdaoCQnHmHh9KofhD6uRqw==",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@sapphire/async-queue": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.2.tgz",
"integrity": "sha512-7X7FFAA4DngXUl95+hYbUF19bp1LGiffjJtu7ygrZrbdCSsdDDBaSjB7Akw0ZbOu6k0xpXyljnJ6/RZUvLfRdg==",
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/@sapphire/shapeshift": {
"version": "3.9.7",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.9.7.tgz",
"integrity": "sha512-4It2mxPSr4OGn4HSQWGmhFMsNFGfFVhWeRPCRwbH972Ek2pzfGRZtb0pJ4Ze6oIzcyh2jw7nUDa6qGlWofgd9g==",
"dependencies": {
"fast-deep-equal": "^3.1.3",
"lodash": "^4.17.21"
},
"engines": {
"node": ">=v16"
}
},
"node_modules/@sapphire/snowflake": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.5.3.tgz",
"integrity": "sha512-jjmJywLAFoWeBi1W7994zZyiNWPIiqRRNAmSERxyg93xRGzNYvGjlZ0gR6x0F4gPRi2+0O6S71kOZYyr3cxaIQ==",
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/@types/node": {
"version": "20.12.11",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.11.tgz",
"integrity": "sha512-vDg9PZ/zi+Nqp6boSOT7plNuthRugEKixDv5sFTIpkE89MmNtEArAShI4mxuX2+UrLEe9pxC1vm2cjm9YlWbJw==",
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/@types/ws": {
"version": "8.5.10",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz",
"integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@vladfrangu/async_event_emitter": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@vladfrangu/async_event_emitter/-/async_event_emitter-2.2.4.tgz",
"integrity": "sha512-ButUPz9E9cXMLgvAW8aLAKKJJsPu1dY1/l/E8xzLFuysowXygs6GBcyunK9rnGC4zTsnIc2mQo71rGw9U+Ykug==",
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/discord-api-types": {
"version": "0.37.83",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.83.tgz",
"integrity": "sha512-urGGYeWtWNYMKnYlZnOnDHm8fVRffQs3U0SpE8RHeiuLKb/u92APS8HoQnPTFbnXmY1vVnXjXO4dOxcAn3J+DA=="
},
"node_modules/discord.js": {
"version": "14.15.2",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.15.2.tgz",
"integrity": "sha512-wGD37YCaTUNprtpqMIRuNiswwsvSWXrHykBSm2SAosoTYut0VUDj9yo9t4iLtMKvuhI49zYkvKc2TNdzdvpJhg==",
"dependencies": {
"@discordjs/builders": "^1.8.1",
"@discordjs/collection": "1.5.3",
"@discordjs/formatters": "^0.4.0",
"@discordjs/rest": "^2.3.0",
"@discordjs/util": "^1.1.0",
"@discordjs/ws": "^1.1.0",
"@sapphire/snowflake": "3.5.3",
"discord-api-types": "0.37.83",
"fast-deep-equal": "3.1.3",
"lodash.snakecase": "4.1.1",
"tslib": "2.6.2",
"undici": "6.13.0"
},
"engines": {
"node": ">=16.11.0"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
},
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"node_modules/inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/lodash.snakecase": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz",
"integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw=="
},
"node_modules/magic-bytes.js": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.10.0.tgz",
"integrity": "sha512-/k20Lg2q8LE5xiaaSkMXk4sfvI+9EGEykFS4b0CHHGWqDYU0bGUFSwchNOMA56D7TCs9GwVTkqe9als1/ns8UQ=="
},
"node_modules/path": {
"version": "0.12.7",
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
"integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==",
"dependencies": {
"process": "^0.11.1",
"util": "^0.10.3"
}
},
"node_modules/process": {
"version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
"engines": {
"node": ">= 0.6.0"
}
},
"node_modules/ts-mixer": {
"version": "6.0.4",
"resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.4.tgz",
"integrity": "sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA=="
},
"node_modules/tslib": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
},
"node_modules/undici": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-6.13.0.tgz",
"integrity": "sha512-Q2rtqmZWrbP8nePMq7mOJIN98M0fYvSgV89vwl/BQRT4mDOeY2GXZngfGpcBBhtky3woM7G24wZV3Q304Bv6cw==",
"engines": {
"node": ">=18.0"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
},
"node_modules/util": {
"version": "0.10.4",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
"integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==",
"dependencies": {
"inherits": "2.0.3"
}
},
"node_modules/ws": {
"version": "8.17.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz",
"integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

191
node_modules/@discordjs/builders/LICENSE generated vendored Normal file
View file

@ -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.

72
node_modules/@discordjs/builders/README.md generated vendored Normal file
View file

@ -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

1971
node_modules/@discordjs/builders/dist/index.d.mts generated vendored Normal file

File diff suppressed because it is too large Load diff

1971
node_modules/@discordjs/builders/dist/index.d.ts generated vendored Normal file

File diff suppressed because it is too large Load diff

2811
node_modules/@discordjs/builders/dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/builders/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

2748
node_modules/@discordjs/builders/dist/index.mjs generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/builders/dist/index.mjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

99
node_modules/@discordjs/builders/package.json generated vendored Normal file
View file

@ -0,0 +1,99 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/builders",
"version": "1.8.1",
"description": "A set of builders that you can use when creating your bot",
"exports": {
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"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",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"dependencies": {
"@sapphire/shapeshift": "^3.9.7",
"discord-api-types": "0.37.83",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.4",
"tslib": "^2.6.2",
"@discordjs/formatters": "^0.4.0",
"@discordjs/util": "^1.1.0"
},
"devDependencies": {
"@favware/cliff-jumper": "^3.0.2",
"@types/node": "16.18.60",
"@vitest/coverage-v8": "^1.5.0",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0",
"@discordjs/api-extractor": "^7.38.1",
"@discordjs/scripts": "^0.1.0"
},
"engines": {
"node": ">=16.11.0"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"test": "vitest run",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/builders/*'",
"release": "cliff-jumper"
}
}

190
node_modules/@discordjs/collection/CHANGELOG.md generated vendored Normal file
View file

@ -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))

191
node_modules/@discordjs/collection/LICENSE generated vendored Normal file
View file

@ -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.

67
node_modules/@discordjs/collection/README.md generated vendored Normal file
View file

@ -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

457
node_modules/@discordjs/collection/dist/index.d.mts generated vendored Normal file
View file

@ -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 };

457
node_modules/@discordjs/collection/dist/index.d.ts generated vendored Normal file
View file

@ -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 };

543
node_modules/@discordjs/collection/dist/index.js generated vendored Normal file
View file

@ -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

1
node_modules/@discordjs/collection/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

517
node_modules/@discordjs/collection/dist/index.mjs generated vendored Normal file
View file

@ -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

File diff suppressed because one or more lines are too long

76
node_modules/@discordjs/collection/package.json generated vendored Normal file
View file

@ -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"
}
}

191
node_modules/@discordjs/formatters/LICENSE generated vendored Normal file
View file

@ -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.

82
node_modules/@discordjs/formatters/README.md generated vendored Normal file
View file

@ -0,0 +1,82 @@
<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
bun 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

650
node_modules/@discordjs/formatters/dist/index.d.mts generated vendored Normal file
View file

@ -0,0 +1,650 @@
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 Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function codeBlock<Content extends string>(content: Content): `\`\`\`\n${Content}\n\`\`\``;
/**
* Wraps the content inside a code block with the specified language.
*
* @typeParam Language - This is inferred by the supplied language
* @typeParam Content - This is inferred by the supplied content
* @param language - The language for the code block
* @param content - The content to wrap
*/
declare function codeBlock<Language extends string, Content extends string>(language: Language, content: Content): `\`\`\`${Language}\n${Content}\n\`\`\``;
/**
* Wraps the content inside \`backticks\` which formats it as inline code.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function inlineCode<Content extends string>(content: Content): `\`${Content}\``;
/**
* Formats the content into italic text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function italic<Content extends string>(content: Content): `_${Content}_`;
/**
* Formats the content into bold text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function bold<Content extends string>(content: Content): `**${Content}**`;
/**
* Formats the content into underscored text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @deprecated Use {@link underline} instead.
*/
declare function underscore<Content extends string>(content: Content): `__${Content}__`;
/**
* Formats the content into underlined text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function underline<Content extends string>(content: Content): `__${Content}__`;
/**
* Formats the content into strike-through text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function strikethrough<Content extends string>(content: Content): `~~${Content}~~`;
/**
* Formats the content into a quote.
*
* @remarks This needs to be at the start of the line for Discord to format it.
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function quote<Content extends string>(content: Content): `> ${Content}`;
/**
* Formats the content into a block quote.
*
* @remarks This needs to be at the start of the line for Discord to format it.
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function blockQuote<Content extends string>(content: Content): `>>> ${Content}`;
/**
* Wraps the URL into `<>` which stops it from embedding.
*
* @typeParam Content - This is inferred by the supplied content
* @param url - The URL to wrap
*/
declare function hideLinkEmbed<Content extends string>(url: Content): `<${Content}>`;
/**
* 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 Content - This is inferred by the supplied content
* @param content - The content to display
* @param url - The URL the content links to
*/
declare function hyperlink<Content extends string>(content: Content, url: URL): `[${Content}](${string})`;
/**
* Formats the content and the URL into a masked URL.
*
* @typeParam Content - This is inferred by the supplied content
* @typeParam Url - This is inferred by the supplied URL
* @param content - The content to display
* @param url - The URL the content links to
*/
declare function hyperlink<Content extends string, Url extends string>(content: Content, url: Url): `[${Content}](${Url})`;
/**
* Formats the content and the URL into a masked URL with a custom tooltip.
*
* @typeParam Content - This is inferred by the supplied content
* @typeParam Title - 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<Content extends string, Title extends string>(content: Content, url: URL, title: Title): `[${Content}](${string} "${Title}")`;
/**
* Formats the content and the URL into a masked URL with a custom tooltip.
*
* @typeParam Content - This is inferred by the supplied content
* @typeParam Url - This is inferred by the supplied URL
* @typeParam Title - 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<Content extends string, Url extends string, Title extends string>(content: Content, url: Url, title: Title): `[${Content}](${Url} "${Title}")`;
/**
* Formats the content into a spoiler.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function spoiler<Content extends string>(content: Content): `||${Content}||`;
/**
* Formats a user id into a user mention.
*
* @typeParam UserId - This is inferred by the supplied user id
* @param userId - The user id to format
*/
declare function userMention<UserId extends Snowflake>(userId: UserId): `<@${UserId}>`;
/**
* Formats a channel id into a channel mention.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @param channelId - The channel id to format
*/
declare function channelMention<ChannelId extends Snowflake>(channelId: ChannelId): `<#${ChannelId}>`;
/**
* Formats a role id into a role mention.
*
* @typeParam RoleId - This is inferred by the supplied role id
* @param roleId - The role id to format
*/
declare function roleMention<RoleId extends Snowflake>(roleId: RoleId): `<@&${RoleId}>`;
/**
* Formats an application command name, subcommand group name, subcommand name, and id into an application command mention.
*
* @typeParam CommandName - This is inferred by the supplied command name
* @typeParam SubcommandGroupName - This is inferred by the supplied subcommand group name
* @typeParam SubcommandName - This is inferred by the supplied subcommand name
* @typeParam CommandId - 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<CommandName extends string, SubcommandGroupName extends string, SubcommandName extends string, CommandId extends Snowflake>(commandName: CommandName, subcommandGroupName: SubcommandGroupName, subcommandName: SubcommandName, commandId: CommandId): `</${CommandName} ${SubcommandGroupName} ${SubcommandName}:${CommandId}>`;
/**
* Formats an application command name, subcommand name, and id into an application command mention.
*
* @typeParam CommandName - This is inferred by the supplied command name
* @typeParam SubcommandName - This is inferred by the supplied subcommand name
* @typeParam CommandId - 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<CommandName extends string, SubcommandName extends string, CommandId extends Snowflake>(commandName: CommandName, subcommandName: SubcommandName, commandId: CommandId): `</${CommandName} ${SubcommandName}:${CommandId}>`;
/**
* Formats an application command name and id into an application command mention.
*
* @typeParam CommandName - This is inferred by the supplied command name
* @typeParam CommandId - 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<CommandName extends string, CommandId extends Snowflake>(commandName: CommandName, commandId: CommandId): `</${CommandName}:${CommandId}>`;
/**
* Formats a non-animated emoji id into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @param emojiId - The emoji id to format
*/
declare function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: false): `<:_:${EmojiId}>`;
/**
* Formats an animated emoji id into a fully qualified emoji identifier.
*
* @typeParam EmojiId - 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<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: true): `<a:_:${EmojiId}>`;
/**
* Formats an emoji id into a fully qualified emoji identifier.
*
* @typeParam EmojiId - 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<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: boolean): `<:_:${EmojiId}>` | `<a:_:${EmojiId}>`;
/**
* Formats a non-animated emoji id and name into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied name
* @param options - The options for formatting an emoji
*/
declare function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(options: FormatEmojiOptions<EmojiId, EmojiName> & {
animated: true;
}): `<a:${EmojiName}:${EmojiId}>`;
/**
* Formats an animated emoji id and name into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied name
* @param options - The options for formatting an emoji
*/
declare function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(options: FormatEmojiOptions<EmojiId, EmojiName> & {
animated?: false;
}): `<:${EmojiName}:${EmojiId}>`;
/**
* Formats an emoji id and name into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied emoji name
* @param options - The options for formatting an emoji
*/
declare function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(options: FormatEmojiOptions<EmojiId, EmojiName>): `<:${EmojiName}:${EmojiId}>` | `<a:${EmojiName}:${EmojiId}>`;
/**
* The options for formatting an emoji.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied emoji name
*/
interface FormatEmojiOptions<EmojiId extends Snowflake, EmojiName extends string> {
/**
* Whether the emoji is animated
*/
animated?: boolean;
/**
* The emoji id to format
*/
id: EmojiId;
/**
* The name of the emoji
*/
name?: EmojiName;
}
/**
* Formats a channel link for a direct message channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @param channelId - The channel's id
*/
declare function channelLink<ChannelId extends Snowflake>(channelId: ChannelId): `https://discord.com/channels/@me/${ChannelId}`;
/**
* Formats a channel link for a guild channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @typeParam GuildId - This is inferred by the supplied guild id
* @param channelId - The channel's id
* @param guildId - The guild's id
*/
declare function channelLink<ChannelId extends Snowflake, GuildId extends Snowflake>(channelId: ChannelId, guildId: GuildId): `https://discord.com/channels/${GuildId}/${ChannelId}`;
/**
* Formats a message link for a direct message channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @typeParam MessageId - This is inferred by the supplied message id
* @param channelId - The channel's id
* @param messageId - The message's id
*/
declare function messageLink<ChannelId extends Snowflake, MessageId extends Snowflake>(channelId: ChannelId, messageId: MessageId): `https://discord.com/channels/@me/${ChannelId}/${MessageId}`;
/**
* Formats a message link for a guild channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @typeParam MessageId - This is inferred by the supplied message id
* @typeParam GuildId - 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<ChannelId extends Snowflake, MessageId extends Snowflake, GuildId extends Snowflake>(channelId: ChannelId, messageId: MessageId, guildId: GuildId): `https://discord.com/channels/${GuildId}/${ChannelId}/${MessageId}`;
/**
* The heading levels for expanded markdown.
*/
declare enum HeadingLevel {
/**
* The first heading level.
*/
One = 1,
/**
* The second heading level.
*/
Two = 2,
/**
* The third heading level.
*/
Three = 3
}
/**
* Formats the content into a heading level.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @param level - The heading level
*/
declare function heading<Content extends string>(content: Content, level?: HeadingLevel.One): `# ${Content}`;
/**
* Formats the content into a heading level.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @param level - The heading level
*/
declare function heading<Content extends string>(content: Content, level: HeadingLevel.Two): `## ${Content}`;
/**
* Formats the content into a heading level.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @param level - The heading level
*/
declare function heading<Content extends string>(content: Content, level: HeadingLevel.Three): `### ${Content}`;
/**
* A type that recursively traverses into arrays.
*/
type RecursiveArray<ItemType> = readonly (ItemType | RecursiveArray<ItemType>)[];
/**
* Formats the elements in the array to an ordered list.
*
* @param list - The array of elements to list
* @param startNumber - The starting number for the list
*/
declare function orderedList(list: RecursiveArray<string>, startNumber?: number): string;
/**
* Formats the elements in the array to an unordered list.
*
* @param list - The array of elements to list
*/
declare function unorderedList(list: RecursiveArray<string>): string;
/**
* 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 Style - This is inferred by the supplied {@link TimestampStylesString}
* @param date - The date to format
* @param style - The style to use
*/
declare function time<Style extends TimestampStylesString>(date: Date, style: Style): `<t:${bigint}:${Style}>`;
/**
* Formats the given timestamp into a short date-time string.
*
* @typeParam Seconds - This is inferred by the supplied timestamp
* @param seconds - A Unix timestamp in seconds
*/
declare function time<Seconds extends number>(seconds: Seconds): `<t:${Seconds}>`;
/**
* Formats the given timestamp into a short date-time string.
*
* @typeParam Seconds - This is inferred by the supplied timestamp
* @typeParam Style - This is inferred by the supplied {@link TimestampStylesString}
* @param seconds - A Unix timestamp in seconds
* @param style - The style to use
*/
declare function time<Seconds extends number, Style extends TimestampStylesString>(seconds: Seconds, style: Style): `<t:${Seconds}:${Style}>`;
/**
* 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)"
}
/**
* All the available guild navigation mentions.
*/
declare enum GuildNavigationMentions {
/**
* Browse Channels tab.
*/
Browse = "<id:browse>",
/**
* Customize tab with the server's {@link https://discord.com/developers/docs/resources/guild#guild-onboarding-object | onboarding prompts}.
*/
Customize = "<id:customize>",
/**
* {@link https://support.discord.com/hc/articles/13497665141655 | Server Guide} tab.
*/
Guide = "<id:guide>"
}
/**
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/formatters#readme | @discordjs/formatters} 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 { type EscapeMarkdownOptions, Faces, type FormatEmojiOptions, GuildNavigationMentions, HeadingLevel, type RecursiveArray, TimestampStyles, type TimestampStylesString, blockQuote, bold, channelLink, channelMention, chatInputApplicationCommandMention, codeBlock, escapeBold, escapeBulletedList, escapeCodeBlock, escapeEscape, escapeHeading, escapeInlineCode, escapeItalic, escapeMarkdown, escapeMaskedLink, escapeNumberedList, escapeSpoiler, escapeStrikethrough, escapeUnderline, formatEmoji, heading, hideLinkEmbed, hyperlink, inlineCode, italic, messageLink, orderedList, quote, roleMention, spoiler, strikethrough, time, underline, underscore, unorderedList, userMention, version };

650
node_modules/@discordjs/formatters/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,650 @@
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 Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function codeBlock<Content extends string>(content: Content): `\`\`\`\n${Content}\n\`\`\``;
/**
* Wraps the content inside a code block with the specified language.
*
* @typeParam Language - This is inferred by the supplied language
* @typeParam Content - This is inferred by the supplied content
* @param language - The language for the code block
* @param content - The content to wrap
*/
declare function codeBlock<Language extends string, Content extends string>(language: Language, content: Content): `\`\`\`${Language}\n${Content}\n\`\`\``;
/**
* Wraps the content inside \`backticks\` which formats it as inline code.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function inlineCode<Content extends string>(content: Content): `\`${Content}\``;
/**
* Formats the content into italic text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function italic<Content extends string>(content: Content): `_${Content}_`;
/**
* Formats the content into bold text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function bold<Content extends string>(content: Content): `**${Content}**`;
/**
* Formats the content into underscored text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @deprecated Use {@link underline} instead.
*/
declare function underscore<Content extends string>(content: Content): `__${Content}__`;
/**
* Formats the content into underlined text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function underline<Content extends string>(content: Content): `__${Content}__`;
/**
* Formats the content into strike-through text.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function strikethrough<Content extends string>(content: Content): `~~${Content}~~`;
/**
* Formats the content into a quote.
*
* @remarks This needs to be at the start of the line for Discord to format it.
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function quote<Content extends string>(content: Content): `> ${Content}`;
/**
* Formats the content into a block quote.
*
* @remarks This needs to be at the start of the line for Discord to format it.
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function blockQuote<Content extends string>(content: Content): `>>> ${Content}`;
/**
* Wraps the URL into `<>` which stops it from embedding.
*
* @typeParam Content - This is inferred by the supplied content
* @param url - The URL to wrap
*/
declare function hideLinkEmbed<Content extends string>(url: Content): `<${Content}>`;
/**
* 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 Content - This is inferred by the supplied content
* @param content - The content to display
* @param url - The URL the content links to
*/
declare function hyperlink<Content extends string>(content: Content, url: URL): `[${Content}](${string})`;
/**
* Formats the content and the URL into a masked URL.
*
* @typeParam Content - This is inferred by the supplied content
* @typeParam Url - This is inferred by the supplied URL
* @param content - The content to display
* @param url - The URL the content links to
*/
declare function hyperlink<Content extends string, Url extends string>(content: Content, url: Url): `[${Content}](${Url})`;
/**
* Formats the content and the URL into a masked URL with a custom tooltip.
*
* @typeParam Content - This is inferred by the supplied content
* @typeParam Title - 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<Content extends string, Title extends string>(content: Content, url: URL, title: Title): `[${Content}](${string} "${Title}")`;
/**
* Formats the content and the URL into a masked URL with a custom tooltip.
*
* @typeParam Content - This is inferred by the supplied content
* @typeParam Url - This is inferred by the supplied URL
* @typeParam Title - 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<Content extends string, Url extends string, Title extends string>(content: Content, url: Url, title: Title): `[${Content}](${Url} "${Title}")`;
/**
* Formats the content into a spoiler.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
*/
declare function spoiler<Content extends string>(content: Content): `||${Content}||`;
/**
* Formats a user id into a user mention.
*
* @typeParam UserId - This is inferred by the supplied user id
* @param userId - The user id to format
*/
declare function userMention<UserId extends Snowflake>(userId: UserId): `<@${UserId}>`;
/**
* Formats a channel id into a channel mention.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @param channelId - The channel id to format
*/
declare function channelMention<ChannelId extends Snowflake>(channelId: ChannelId): `<#${ChannelId}>`;
/**
* Formats a role id into a role mention.
*
* @typeParam RoleId - This is inferred by the supplied role id
* @param roleId - The role id to format
*/
declare function roleMention<RoleId extends Snowflake>(roleId: RoleId): `<@&${RoleId}>`;
/**
* Formats an application command name, subcommand group name, subcommand name, and id into an application command mention.
*
* @typeParam CommandName - This is inferred by the supplied command name
* @typeParam SubcommandGroupName - This is inferred by the supplied subcommand group name
* @typeParam SubcommandName - This is inferred by the supplied subcommand name
* @typeParam CommandId - 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<CommandName extends string, SubcommandGroupName extends string, SubcommandName extends string, CommandId extends Snowflake>(commandName: CommandName, subcommandGroupName: SubcommandGroupName, subcommandName: SubcommandName, commandId: CommandId): `</${CommandName} ${SubcommandGroupName} ${SubcommandName}:${CommandId}>`;
/**
* Formats an application command name, subcommand name, and id into an application command mention.
*
* @typeParam CommandName - This is inferred by the supplied command name
* @typeParam SubcommandName - This is inferred by the supplied subcommand name
* @typeParam CommandId - 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<CommandName extends string, SubcommandName extends string, CommandId extends Snowflake>(commandName: CommandName, subcommandName: SubcommandName, commandId: CommandId): `</${CommandName} ${SubcommandName}:${CommandId}>`;
/**
* Formats an application command name and id into an application command mention.
*
* @typeParam CommandName - This is inferred by the supplied command name
* @typeParam CommandId - 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<CommandName extends string, CommandId extends Snowflake>(commandName: CommandName, commandId: CommandId): `</${CommandName}:${CommandId}>`;
/**
* Formats a non-animated emoji id into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @param emojiId - The emoji id to format
*/
declare function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: false): `<:_:${EmojiId}>`;
/**
* Formats an animated emoji id into a fully qualified emoji identifier.
*
* @typeParam EmojiId - 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<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: true): `<a:_:${EmojiId}>`;
/**
* Formats an emoji id into a fully qualified emoji identifier.
*
* @typeParam EmojiId - 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<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: boolean): `<:_:${EmojiId}>` | `<a:_:${EmojiId}>`;
/**
* Formats a non-animated emoji id and name into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied name
* @param options - The options for formatting an emoji
*/
declare function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(options: FormatEmojiOptions<EmojiId, EmojiName> & {
animated: true;
}): `<a:${EmojiName}:${EmojiId}>`;
/**
* Formats an animated emoji id and name into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied name
* @param options - The options for formatting an emoji
*/
declare function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(options: FormatEmojiOptions<EmojiId, EmojiName> & {
animated?: false;
}): `<:${EmojiName}:${EmojiId}>`;
/**
* Formats an emoji id and name into a fully qualified emoji identifier.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied emoji name
* @param options - The options for formatting an emoji
*/
declare function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(options: FormatEmojiOptions<EmojiId, EmojiName>): `<:${EmojiName}:${EmojiId}>` | `<a:${EmojiName}:${EmojiId}>`;
/**
* The options for formatting an emoji.
*
* @typeParam EmojiId - This is inferred by the supplied emoji id
* @typeParam EmojiName - This is inferred by the supplied emoji name
*/
interface FormatEmojiOptions<EmojiId extends Snowflake, EmojiName extends string> {
/**
* Whether the emoji is animated
*/
animated?: boolean;
/**
* The emoji id to format
*/
id: EmojiId;
/**
* The name of the emoji
*/
name?: EmojiName;
}
/**
* Formats a channel link for a direct message channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @param channelId - The channel's id
*/
declare function channelLink<ChannelId extends Snowflake>(channelId: ChannelId): `https://discord.com/channels/@me/${ChannelId}`;
/**
* Formats a channel link for a guild channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @typeParam GuildId - This is inferred by the supplied guild id
* @param channelId - The channel's id
* @param guildId - The guild's id
*/
declare function channelLink<ChannelId extends Snowflake, GuildId extends Snowflake>(channelId: ChannelId, guildId: GuildId): `https://discord.com/channels/${GuildId}/${ChannelId}`;
/**
* Formats a message link for a direct message channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @typeParam MessageId - This is inferred by the supplied message id
* @param channelId - The channel's id
* @param messageId - The message's id
*/
declare function messageLink<ChannelId extends Snowflake, MessageId extends Snowflake>(channelId: ChannelId, messageId: MessageId): `https://discord.com/channels/@me/${ChannelId}/${MessageId}`;
/**
* Formats a message link for a guild channel.
*
* @typeParam ChannelId - This is inferred by the supplied channel id
* @typeParam MessageId - This is inferred by the supplied message id
* @typeParam GuildId - 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<ChannelId extends Snowflake, MessageId extends Snowflake, GuildId extends Snowflake>(channelId: ChannelId, messageId: MessageId, guildId: GuildId): `https://discord.com/channels/${GuildId}/${ChannelId}/${MessageId}`;
/**
* The heading levels for expanded markdown.
*/
declare enum HeadingLevel {
/**
* The first heading level.
*/
One = 1,
/**
* The second heading level.
*/
Two = 2,
/**
* The third heading level.
*/
Three = 3
}
/**
* Formats the content into a heading level.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @param level - The heading level
*/
declare function heading<Content extends string>(content: Content, level?: HeadingLevel.One): `# ${Content}`;
/**
* Formats the content into a heading level.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @param level - The heading level
*/
declare function heading<Content extends string>(content: Content, level: HeadingLevel.Two): `## ${Content}`;
/**
* Formats the content into a heading level.
*
* @typeParam Content - This is inferred by the supplied content
* @param content - The content to wrap
* @param level - The heading level
*/
declare function heading<Content extends string>(content: Content, level: HeadingLevel.Three): `### ${Content}`;
/**
* A type that recursively traverses into arrays.
*/
type RecursiveArray<ItemType> = readonly (ItemType | RecursiveArray<ItemType>)[];
/**
* Formats the elements in the array to an ordered list.
*
* @param list - The array of elements to list
* @param startNumber - The starting number for the list
*/
declare function orderedList(list: RecursiveArray<string>, startNumber?: number): string;
/**
* Formats the elements in the array to an unordered list.
*
* @param list - The array of elements to list
*/
declare function unorderedList(list: RecursiveArray<string>): string;
/**
* 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 Style - This is inferred by the supplied {@link TimestampStylesString}
* @param date - The date to format
* @param style - The style to use
*/
declare function time<Style extends TimestampStylesString>(date: Date, style: Style): `<t:${bigint}:${Style}>`;
/**
* Formats the given timestamp into a short date-time string.
*
* @typeParam Seconds - This is inferred by the supplied timestamp
* @param seconds - A Unix timestamp in seconds
*/
declare function time<Seconds extends number>(seconds: Seconds): `<t:${Seconds}>`;
/**
* Formats the given timestamp into a short date-time string.
*
* @typeParam Seconds - This is inferred by the supplied timestamp
* @typeParam Style - This is inferred by the supplied {@link TimestampStylesString}
* @param seconds - A Unix timestamp in seconds
* @param style - The style to use
*/
declare function time<Seconds extends number, Style extends TimestampStylesString>(seconds: Seconds, style: Style): `<t:${Seconds}:${Style}>`;
/**
* 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)"
}
/**
* All the available guild navigation mentions.
*/
declare enum GuildNavigationMentions {
/**
* Browse Channels tab.
*/
Browse = "<id:browse>",
/**
* Customize tab with the server's {@link https://discord.com/developers/docs/resources/guild#guild-onboarding-object | onboarding prompts}.
*/
Customize = "<id:customize>",
/**
* {@link https://support.discord.com/hc/articles/13497665141655 | Server Guide} tab.
*/
Guide = "<id:guide>"
}
/**
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/formatters#readme | @discordjs/formatters} 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 { type EscapeMarkdownOptions, Faces, type FormatEmojiOptions, GuildNavigationMentions, HeadingLevel, type RecursiveArray, TimestampStyles, type TimestampStylesString, blockQuote, bold, channelLink, channelMention, chatInputApplicationCommandMention, codeBlock, escapeBold, escapeBulletedList, escapeCodeBlock, escapeEscape, escapeHeading, escapeInlineCode, escapeItalic, escapeMarkdown, escapeMaskedLink, escapeNumberedList, escapeSpoiler, escapeStrikethrough, escapeUnderline, formatEmoji, heading, hideLinkEmbed, hyperlink, inlineCode, italic, messageLink, orderedList, quote, roleMention, spoiler, strikethrough, time, underline, underscore, unorderedList, userMention, version };

457
node_modules/@discordjs/formatters/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,457 @@
"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,
GuildNavigationMentions: () => GuildNavigationMentions,
HeadingLevel: () => HeadingLevel,
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,
heading: () => heading,
hideLinkEmbed: () => hideLinkEmbed,
hyperlink: () => hyperlink,
inlineCode: () => inlineCode,
italic: () => italic,
messageLink: () => messageLink,
orderedList: () => orderedList,
quote: () => quote,
roleMention: () => roleMention,
spoiler: () => spoiler,
strikethrough: () => strikethrough,
time: () => time,
underline: () => underline,
underscore: () => underscore,
unorderedList: () => unorderedList,
userMention: () => userMention,
version: () => version
});
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: underline2 = true,
strikethrough: strikethrough2 = true,
spoiler: spoiler2 = true,
codeBlockContent = true,
inlineCodeContent = true,
escape = true,
heading: heading2 = 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: underline2,
strikethrough: strikethrough2,
spoiler: spoiler2,
inlineCodeContent,
escape,
heading: heading2,
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: underline2,
strikethrough: strikethrough2,
spoiler: spoiler2,
escape,
heading: heading2,
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 (underline2)
res = escapeUnderline(res);
if (strikethrough2)
res = escapeStrikethrough(res);
if (spoiler2)
res = escapeSpoiler(res);
if (heading2)
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?:.+|https?:\/\/\S+)_(?!:\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?:.+|https?:\/\/\S+)__(_)?(?!:\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 underline(content);
}
__name(underscore, "underscore");
function underline(content) {
return `__${content}__`;
}
__name(underline, "underline");
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(emojiIdOrOptions, animated) {
const options = typeof emojiIdOrOptions === "string" ? {
id: emojiIdOrOptions,
animated: animated ?? false
} : emojiIdOrOptions;
const { id, animated: isAnimated, name: emojiName } = options;
return `<${isAnimated ? "a" : ""}:${emojiName ?? "_"}:${id}>`;
}
__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");
var HeadingLevel = /* @__PURE__ */ ((HeadingLevel2) => {
HeadingLevel2[HeadingLevel2["One"] = 1] = "One";
HeadingLevel2[HeadingLevel2["Two"] = 2] = "Two";
HeadingLevel2[HeadingLevel2["Three"] = 3] = "Three";
return HeadingLevel2;
})(HeadingLevel || {});
function heading(content, level) {
switch (level) {
case 3 /* Three */:
return `### ${content}`;
case 2 /* Two */:
return `## ${content}`;
default:
return `# ${content}`;
}
}
__name(heading, "heading");
function listCallback(element, startNumber, depth = 0) {
if (Array.isArray(element)) {
return element.map((element2) => listCallback(element2, startNumber, depth + 1)).join("\n");
}
return `${" ".repeat(depth - 1)}${startNumber ? `${startNumber}.` : "-"} ${element}`;
}
__name(listCallback, "listCallback");
function orderedList(list, startNumber = 1) {
return listCallback(list, Math.max(startNumber, 1));
}
__name(orderedList, "orderedList");
function unorderedList(list) {
return listCallback(list);
}
__name(unorderedList, "unorderedList");
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 || {});
var GuildNavigationMentions = /* @__PURE__ */ ((GuildNavigationMentions2) => {
GuildNavigationMentions2["Browse"] = "<id:browse>";
GuildNavigationMentions2["Customize"] = "<id:customize>";
GuildNavigationMentions2["Guide"] = "<id:guide>";
return GuildNavigationMentions2;
})(GuildNavigationMentions || {});
// src/index.ts
var version = "0.4.0";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Faces,
GuildNavigationMentions,
HeadingLevel,
TimestampStyles,
blockQuote,
bold,
channelLink,
channelMention,
chatInputApplicationCommandMention,
codeBlock,
escapeBold,
escapeBulletedList,
escapeCodeBlock,
escapeEscape,
escapeHeading,
escapeInlineCode,
escapeItalic,
escapeMarkdown,
escapeMaskedLink,
escapeNumberedList,
escapeSpoiler,
escapeStrikethrough,
escapeUnderline,
formatEmoji,
heading,
hideLinkEmbed,
hyperlink,
inlineCode,
italic,
messageLink,
orderedList,
quote,
roleMention,
spoiler,
strikethrough,
time,
underline,
underscore,
unorderedList,
userMention,
version
});
//# sourceMappingURL=index.js.map

1
node_modules/@discordjs/formatters/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

392
node_modules/@discordjs/formatters/dist/index.mjs generated vendored Normal file
View file

@ -0,0 +1,392 @@
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: underline2 = true,
strikethrough: strikethrough2 = true,
spoiler: spoiler2 = true,
codeBlockContent = true,
inlineCodeContent = true,
escape = true,
heading: heading2 = 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: underline2,
strikethrough: strikethrough2,
spoiler: spoiler2,
inlineCodeContent,
escape,
heading: heading2,
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: underline2,
strikethrough: strikethrough2,
spoiler: spoiler2,
escape,
heading: heading2,
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 (underline2)
res = escapeUnderline(res);
if (strikethrough2)
res = escapeStrikethrough(res);
if (spoiler2)
res = escapeSpoiler(res);
if (heading2)
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?:.+|https?:\/\/\S+)_(?!:\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?:.+|https?:\/\/\S+)__(_)?(?!:\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 underline(content);
}
__name(underscore, "underscore");
function underline(content) {
return `__${content}__`;
}
__name(underline, "underline");
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(emojiIdOrOptions, animated) {
const options = typeof emojiIdOrOptions === "string" ? {
id: emojiIdOrOptions,
animated: animated ?? false
} : emojiIdOrOptions;
const { id, animated: isAnimated, name: emojiName } = options;
return `<${isAnimated ? "a" : ""}:${emojiName ?? "_"}:${id}>`;
}
__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");
var HeadingLevel = /* @__PURE__ */ ((HeadingLevel2) => {
HeadingLevel2[HeadingLevel2["One"] = 1] = "One";
HeadingLevel2[HeadingLevel2["Two"] = 2] = "Two";
HeadingLevel2[HeadingLevel2["Three"] = 3] = "Three";
return HeadingLevel2;
})(HeadingLevel || {});
function heading(content, level) {
switch (level) {
case 3 /* Three */:
return `### ${content}`;
case 2 /* Two */:
return `## ${content}`;
default:
return `# ${content}`;
}
}
__name(heading, "heading");
function listCallback(element, startNumber, depth = 0) {
if (Array.isArray(element)) {
return element.map((element2) => listCallback(element2, startNumber, depth + 1)).join("\n");
}
return `${" ".repeat(depth - 1)}${startNumber ? `${startNumber}.` : "-"} ${element}`;
}
__name(listCallback, "listCallback");
function orderedList(list, startNumber = 1) {
return listCallback(list, Math.max(startNumber, 1));
}
__name(orderedList, "orderedList");
function unorderedList(list) {
return listCallback(list);
}
__name(unorderedList, "unorderedList");
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 || {});
var GuildNavigationMentions = /* @__PURE__ */ ((GuildNavigationMentions2) => {
GuildNavigationMentions2["Browse"] = "<id:browse>";
GuildNavigationMentions2["Customize"] = "<id:customize>";
GuildNavigationMentions2["Guide"] = "<id:guide>";
return GuildNavigationMentions2;
})(GuildNavigationMentions || {});
// src/index.ts
var version = "0.4.0";
export {
Faces,
GuildNavigationMentions,
HeadingLevel,
TimestampStyles,
blockQuote,
bold,
channelLink,
channelMention,
chatInputApplicationCommandMention,
codeBlock,
escapeBold,
escapeBulletedList,
escapeCodeBlock,
escapeEscape,
escapeHeading,
escapeInlineCode,
escapeItalic,
escapeMarkdown,
escapeMaskedLink,
escapeNumberedList,
escapeSpoiler,
escapeStrikethrough,
escapeUnderline,
formatEmoji,
heading,
hideLinkEmbed,
hyperlink,
inlineCode,
italic,
messageLink,
orderedList,
quote,
roleMention,
spoiler,
strikethrough,
time,
underline,
underscore,
unorderedList,
userMention,
version
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

83
node_modules/@discordjs/formatters/package.json generated vendored Normal file
View file

@ -0,0 +1,83 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/formatters",
"version": "0.4.0",
"description": "A set of functions to format strings for Discord.",
"exports": {
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"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",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"dependencies": {
"discord-api-types": "0.37.83"
},
"devDependencies": {
"@favware/cliff-jumper": "^3.0.2",
"@types/node": "16.18.60",
"@vitest/coverage-v8": "^1.5.0",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0",
"@discordjs/scripts": "^0.1.0",
"@discordjs/api-extractor": "^7.38.1"
},
"engines": {
"node": ">=16.11.0"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"test": "vitest run",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/formatters/*'",
"release": "cliff-jumper"
}
}

192
node_modules/@discordjs/rest/LICENSE generated vendored Normal file
View file

@ -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.

139
node_modules/@discordjs/rest/README.md generated vendored Normal file
View file

@ -0,0 +1,139 @@
<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
bun 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
bun 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

904
node_modules/@discordjs/rest/dist/index.d.mts generated vendored Normal file
View file

@ -0,0 +1,904 @@
import * as url from 'url';
import { Snowflake } from 'discord-api-types/v10';
import { Readable } from 'node:stream';
import { ReadableStream } from 'node:stream/web';
import { Collection } from '@discordjs/collection';
import { Awaitable } from '@discordjs/util';
import * as undici from 'undici';
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
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];
}
interface RestEventsMap extends RestEvents {
}
/**
* 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: GetRateLimitOffsetFunction | 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 time, in milliseconds, that will need to pass before this specific request can be retried
*/
retryAfter: number;
/**
* The route being hit in this request
*/
route: string;
/**
* The scope of the rate limit that was hit.
*
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
* are shared per resource.
*/
scope: 'global' | 'shared' | 'user';
/**
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
* can be retried
*
* This is only present on certain sublimits, and `0` otherwise
*/
sublimitTimeout: number;
/**
* The time, in milliseconds, until the route's 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) => Awaitable<boolean>;
/**
* A function that determines the rate limit offset for a given request.
*/
type GetRateLimitOffsetFunction = (route: string) => number;
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;
}
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";
/**
* Prefix for deprecation warnings.
*
* @internal
*/
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
/**
* 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 options - Optional options for the emoji
*/
emoji(emojiId: 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
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
*/
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;
retryAfter: number;
sublimitTimeout: number;
scope: RateLimitData['scope'];
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
/**
* The name of the error
*/
get name(): string;
}
/**
* Represents the class that manages handlers for endpoints
*/
declare class REST extends AsyncEventEmitter<RestEvents> {
#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<OptionsType extends object>(options?: Readonly<OptionsType>): 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, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };

904
node_modules/@discordjs/rest/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,904 @@
import * as url from 'url';
import { Snowflake } from 'discord-api-types/v10';
import { Readable } from 'node:stream';
import { ReadableStream } from 'node:stream/web';
import { Collection } from '@discordjs/collection';
import { Awaitable } from '@discordjs/util';
import * as undici from 'undici';
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
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];
}
interface RestEventsMap extends RestEvents {
}
/**
* 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: GetRateLimitOffsetFunction | 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 time, in milliseconds, that will need to pass before this specific request can be retried
*/
retryAfter: number;
/**
* The route being hit in this request
*/
route: string;
/**
* The scope of the rate limit that was hit.
*
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
* are shared per resource.
*/
scope: 'global' | 'shared' | 'user';
/**
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
* can be retried
*
* This is only present on certain sublimits, and `0` otherwise
*/
sublimitTimeout: number;
/**
* The time, in milliseconds, until the route's 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) => Awaitable<boolean>;
/**
* A function that determines the rate limit offset for a given request.
*/
type GetRateLimitOffsetFunction = (route: string) => number;
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;
}
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";
/**
* Prefix for deprecation warnings.
*
* @internal
*/
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
/**
* 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 options - Optional options for the emoji
*/
emoji(emojiId: 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
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
*/
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;
retryAfter: number;
sublimitTimeout: number;
scope: RateLimitData['scope'];
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
/**
* The name of the error
*/
get name(): string;
}
/**
* Represents the class that manages handlers for endpoints
*/
declare class REST extends AsyncEventEmitter<RestEvents> {
#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<OptionsType extends object>(options?: Readonly<OptionsType>): 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, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };

1486
node_modules/@discordjs/rest/dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/rest/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1444
node_modules/@discordjs/rest/dist/index.mjs generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/rest/dist/index.mjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,13 @@
import { Response, request, RequestInit } from 'undici';
import { Readable } from 'node:stream';
import { ReadableStream } from 'node:stream/web';
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
body: Readable | ReadableStream | null;
}
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 { type RequestOptions, makeRequest, resolveBody };

View file

@ -0,0 +1,13 @@
import { Response, request, RequestInit } from 'undici';
import { Readable } from 'node:stream';
import { ReadableStream } from 'node:stream/web';
interface ResponseLike extends Pick<Response, 'arrayBuffer' | 'bodyUsed' | 'headers' | 'json' | 'ok' | 'status' | 'statusText' | 'text'> {
body: Readable | ReadableStream | null;
}
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 { type RequestOptions, makeRequest, resolveBody };

View file

@ -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

View file

@ -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":[]}

View file

@ -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

View file

@ -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,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;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,OAAO,SAAS,UAAU;AACpC,WAAO;AAAA,EACR,WAAW,MAAM,aAAa,IAAI,GAAG;AACpC,WAAO;AAAA,EACR,WAAW,MAAM,cAAc,IAAI,GAAG;AACrC,WAAO,IAAI,WAAW,IAAI;AAAA,EAC3B,WAAW,gBAAgB,iBAAiB;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":[]}

904
node_modules/@discordjs/rest/dist/web.d.mts generated vendored Normal file
View file

@ -0,0 +1,904 @@
import * as url from 'url';
import { Snowflake } from 'discord-api-types/v10';
import { Readable } from 'node:stream';
import { ReadableStream } from 'node:stream/web';
import { Collection } from '@discordjs/collection';
import { Awaitable } from '@discordjs/util';
import * as undici from 'undici';
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
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];
}
interface RestEventsMap extends RestEvents {
}
/**
* 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: GetRateLimitOffsetFunction | 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 time, in milliseconds, that will need to pass before this specific request can be retried
*/
retryAfter: number;
/**
* The route being hit in this request
*/
route: string;
/**
* The scope of the rate limit that was hit.
*
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
* are shared per resource.
*/
scope: 'global' | 'shared' | 'user';
/**
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
* can be retried
*
* This is only present on certain sublimits, and `0` otherwise
*/
sublimitTimeout: number;
/**
* The time, in milliseconds, until the route's 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) => Awaitable<boolean>;
/**
* A function that determines the rate limit offset for a given request.
*/
type GetRateLimitOffsetFunction = (route: string) => number;
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;
}
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";
/**
* Prefix for deprecation warnings.
*
* @internal
*/
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
/**
* 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 options - Optional options for the emoji
*/
emoji(emojiId: 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
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
*/
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;
retryAfter: number;
sublimitTimeout: number;
scope: RateLimitData['scope'];
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
/**
* The name of the error
*/
get name(): string;
}
/**
* Represents the class that manages handlers for endpoints
*/
declare class REST extends AsyncEventEmitter<RestEvents> {
#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<OptionsType extends object>(options?: Readonly<OptionsType>): 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, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };

904
node_modules/@discordjs/rest/dist/web.d.ts generated vendored Normal file
View file

@ -0,0 +1,904 @@
import * as url from 'url';
import { Snowflake } from 'discord-api-types/v10';
import { Readable } from 'node:stream';
import { ReadableStream } from 'node:stream/web';
import { Collection } from '@discordjs/collection';
import { Awaitable } from '@discordjs/util';
import * as undici from 'undici';
import { RequestInit, Dispatcher, Response, BodyInit, Agent } from 'undici';
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
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];
}
interface RestEventsMap extends RestEvents {
}
/**
* 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: GetRateLimitOffsetFunction | 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 time, in milliseconds, that will need to pass before this specific request can be retried
*/
retryAfter: number;
/**
* The route being hit in this request
*/
route: string;
/**
* The scope of the rate limit that was hit.
*
* This can be `user` for rate limits that are per client, `global` for rate limits that affect all clients or `shared` for rate limits that
* are shared per resource.
*/
scope: 'global' | 'shared' | 'user';
/**
* The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
* can be retried
*
* This is only present on certain sublimits, and `0` otherwise
*/
sublimitTimeout: number;
/**
* The time, in milliseconds, until the route's 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) => Awaitable<boolean>;
/**
* A function that determines the rate limit offset for a given request.
*/
type GetRateLimitOffsetFunction = (route: string) => number;
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;
}
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";
/**
* Prefix for deprecation warnings.
*
* @internal
*/
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
/**
* 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 options - Optional options for the emoji
*/
emoji(emojiId: 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
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
*/
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;
retryAfter: number;
sublimitTimeout: number;
scope: RateLimitData['scope'];
constructor({ timeToReset, limit, method, hash, url, route, majorParameter, global, retryAfter, sublimitTimeout, scope, }: RateLimitData);
/**
* The name of the error
*/
get name(): string;
}
/**
* Represents the class that manages handlers for endpoints
*/
declare class REST extends AsyncEventEmitter<RestEvents> {
#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<OptionsType extends object>(options?: Readonly<OptionsType>): 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, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DEPRECATION_WARNING_PREFIX, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };

1418
node_modules/@discordjs/rest/dist/web.js generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/rest/dist/web.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1374
node_modules/@discordjs/rest/dist/web.mjs generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/rest/dist/web.mjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -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.

View file

@ -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 18 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

View file

@ -0,0 +1,535 @@
/**
* @internal
*/
interface CollectionConstructor {
new (): Collection<unknown, unknown>;
new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
readonly prototype: Collection<unknown, unknown>;
readonly [Symbol.species]: CollectionConstructor;
}
/**
* Represents an immutable version of a collection
*/
type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
/**
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
*
* @internal
*/
interface Collection<Key, Value> extends Map<Key, Value> {
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 Key - The key type this collection holds
* @typeParam Value - The value type this collection holds
*/
declare class Collection<Key, Value> extends Map<Key, Value> {
/**
* 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: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
/**
* 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: Key[]): 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: Key[]): 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(): Value | undefined;
first(amount: number): Value[];
/**
* 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(): Key | undefined;
firstKey(amount: number): Key[];
/**
* 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(): Value | undefined;
last(amount: number): Value[];
/**
* 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(): Key | undefined;
lastKey(amount: number): Key[];
/**
* 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): Value | 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): Key | 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(): Value | undefined;
random(amount: number): Value[];
/**
* 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(): Key | undefined;
randomKey(amount: number): Key[];
/**
* 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.find(user => user.username === 'Bob');
* ```
*/
find<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
find(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
find<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
find<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.findKey(user => user.username === 'Bob');
* ```
*/
findKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
/**
* Searches for a last 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/findLast | Array.findLast()}.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLast<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
findLast(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
findLast<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
findLast<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
/**
* Searches for the key of a last 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/findLastIndex | Array.findLastIndex()},
* but returns the key rather than the positional index.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLastKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findLastKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findLastKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findLastKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | 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 the function
* @returns The number of removed entries
*/
sweep(fn: (value: Value, key: Key, collection: this) => unknown): number;
sweep<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.filter(user => user.username === 'Bob');
* ```
*/
filter<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): Collection<NewKey, Value>;
filter<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): Collection<Key, NewValue>;
filter(fn: (value: Value, key: Key, collection: this) => unknown): Collection<Key, Value>;
filter<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): Collection<NewKey, Value>;
filter<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): Collection<Key, NewValue>;
filter<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Collection<Key, Value>;
/**
* 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 the function
* @example
* ```ts
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
* ```
*/
partition<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition(fn: (value: Value, key: Key, collection: this) => unknown): [Collection<Key, Value>, Collection<Key, Value>];
partition<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): [Collection<Key, Value>, Collection<Key, Value>];
/**
* 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 the function
* @example
* ```ts
* collection.flatMap(guild => guild.members.cache);
* ```
*/
flatMap<NewValue>(fn: (value: Value, key: Key, collection: this) => Collection<Key, NewValue>): Collection<Key, NewValue>;
flatMap<NewValue, This>(fn: (this: This, value: Value, key: Key, collection: this) => Collection<Key, NewValue>, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.map(user => user.tag);
* ```
*/
map<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): NewValue[];
map<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): NewValue[];
/**
* 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 the function
* @example
* ```ts
* collection.mapValues(user => user.tag);
* ```
*/
mapValues<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): Collection<Key, NewValue>;
mapValues<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.some(user => user.discriminator === '0000');
* ```
*/
some(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
some<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 the function
* @example
* ```ts
* collection.every(user => !user.bot);
* ```
*/
every<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): this is Collection<NewKey, Value>;
every<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): this is Collection<Key, NewValue>;
every(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
every<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): this is Collection<NewKey, Value>;
every<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): this is Collection<Key, NewValue>;
every<This>(fn: (this: This, value: Value, key: Key, 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<InitialValue = Value>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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 the function
* @example
* ```ts
* collection
* .each(user => console.log(user.username))
* .filter(user => user.bot)
* .each(user => console.log(user.username));
* ```
*/
each(fn: (value: Value, key: Key, collection: this) => void): this;
each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): 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 the 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<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
/**
* Creates an identical shallow copy of this collection.
*
* @example
* ```ts
* const newColl = someColl.clone();
* ```
*/
clone(): Collection<Key, Value>;
/**
* 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<Key, Value>[]): Collection<Key, Value>;
/**
* 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<Key, Value>): 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<Key, Value>): this;
/**
* The intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* 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<OtherValue, ResultValue>(other: ReadonlyCollection<Key, OtherValue>, whenInSelf: (value: Value, key: Key) => Keep<ResultValue>, whenInOther: (valueOther: OtherValue, key: Key) => Keep<ResultValue>, whenInBoth: (value: Value, valueOther: OtherValue, key: Key) => Keep<ResultValue>): Collection<Key, ResultValue>;
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed(): Collection<Key, Value>;
/**
* 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);
* ```
*/
toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
toJSON(): [Key, Value][];
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<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
}
/**
* @internal
*/
type Keep<Value> = {
keep: false;
} | {
keep: true;
value: Value;
};
/**
* @internal
*/
type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => 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, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };

View file

@ -0,0 +1,535 @@
/**
* @internal
*/
interface CollectionConstructor {
new (): Collection<unknown, unknown>;
new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
readonly prototype: Collection<unknown, unknown>;
readonly [Symbol.species]: CollectionConstructor;
}
/**
* Represents an immutable version of a collection
*/
type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
/**
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
*
* @internal
*/
interface Collection<Key, Value> extends Map<Key, Value> {
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 Key - The key type this collection holds
* @typeParam Value - The value type this collection holds
*/
declare class Collection<Key, Value> extends Map<Key, Value> {
/**
* 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: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
/**
* 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: Key[]): 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: Key[]): 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(): Value | undefined;
first(amount: number): Value[];
/**
* 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(): Key | undefined;
firstKey(amount: number): Key[];
/**
* 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(): Value | undefined;
last(amount: number): Value[];
/**
* 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(): Key | undefined;
lastKey(amount: number): Key[];
/**
* 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): Value | 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): Key | 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(): Value | undefined;
random(amount: number): Value[];
/**
* 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(): Key | undefined;
randomKey(amount: number): Key[];
/**
* 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.find(user => user.username === 'Bob');
* ```
*/
find<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
find(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
find<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
find<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.findKey(user => user.username === 'Bob');
* ```
*/
findKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
/**
* Searches for a last 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/findLast | Array.findLast()}.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLast<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
findLast(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
findLast<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
findLast<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
/**
* Searches for the key of a last 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/findLastIndex | Array.findLastIndex()},
* but returns the key rather than the positional index.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLastKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findLastKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findLastKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findLastKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | 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 the function
* @returns The number of removed entries
*/
sweep(fn: (value: Value, key: Key, collection: this) => unknown): number;
sweep<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.filter(user => user.username === 'Bob');
* ```
*/
filter<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): Collection<NewKey, Value>;
filter<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): Collection<Key, NewValue>;
filter(fn: (value: Value, key: Key, collection: this) => unknown): Collection<Key, Value>;
filter<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): Collection<NewKey, Value>;
filter<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): Collection<Key, NewValue>;
filter<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Collection<Key, Value>;
/**
* 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 the function
* @example
* ```ts
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
* ```
*/
partition<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition(fn: (value: Value, key: Key, collection: this) => unknown): [Collection<Key, Value>, Collection<Key, Value>];
partition<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): [Collection<Key, Value>, Collection<Key, Value>];
/**
* 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 the function
* @example
* ```ts
* collection.flatMap(guild => guild.members.cache);
* ```
*/
flatMap<NewValue>(fn: (value: Value, key: Key, collection: this) => Collection<Key, NewValue>): Collection<Key, NewValue>;
flatMap<NewValue, This>(fn: (this: This, value: Value, key: Key, collection: this) => Collection<Key, NewValue>, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.map(user => user.tag);
* ```
*/
map<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): NewValue[];
map<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): NewValue[];
/**
* 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 the function
* @example
* ```ts
* collection.mapValues(user => user.tag);
* ```
*/
mapValues<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): Collection<Key, NewValue>;
mapValues<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.some(user => user.discriminator === '0000');
* ```
*/
some(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
some<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 the function
* @example
* ```ts
* collection.every(user => !user.bot);
* ```
*/
every<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): this is Collection<NewKey, Value>;
every<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): this is Collection<Key, NewValue>;
every(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
every<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): this is Collection<NewKey, Value>;
every<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): this is Collection<Key, NewValue>;
every<This>(fn: (this: This, value: Value, key: Key, 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<InitialValue = Value>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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 the function
* @example
* ```ts
* collection
* .each(user => console.log(user.username))
* .filter(user => user.bot)
* .each(user => console.log(user.username));
* ```
*/
each(fn: (value: Value, key: Key, collection: this) => void): this;
each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): 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 the 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<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
/**
* Creates an identical shallow copy of this collection.
*
* @example
* ```ts
* const newColl = someColl.clone();
* ```
*/
clone(): Collection<Key, Value>;
/**
* 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<Key, Value>[]): Collection<Key, Value>;
/**
* 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<Key, Value>): 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<Key, Value>): this;
/**
* The intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* 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<OtherValue, ResultValue>(other: ReadonlyCollection<Key, OtherValue>, whenInSelf: (value: Value, key: Key) => Keep<ResultValue>, whenInOther: (valueOther: OtherValue, key: Key) => Keep<ResultValue>, whenInBoth: (value: Value, valueOther: OtherValue, key: Key) => Keep<ResultValue>): Collection<Key, ResultValue>;
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed(): Collection<Key, Value>;
/**
* 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);
* ```
*/
toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
toJSON(): [Key, Value][];
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<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
}
/**
* @internal
*/
type Keep<Value> = {
keep: false;
} | {
keep: true;
value: Value;
};
/**
* @internal
*/
type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => 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, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };

View file

@ -0,0 +1,654 @@
"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;
}
findLast(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const val = entries[index][1];
const key = entries[index][0];
if (fn(val, key, this))
return val;
}
return void 0;
}
findLastKey(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const key = entries[index][0];
const val = entries[index][1];
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;
}
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight(fn, initialValue) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
const entries = [...this.entries()];
let accumulator;
let index;
if (initialValue === void 0) {
if (entries.length === 0)
throw new TypeError("Reduce of empty collection with no initial value");
accumulator = entries[entries.length - 1][1];
index = entries.length - 1;
} else {
accumulator = initialValue;
index = entries.length;
}
while (--index >= 0) {
const key = entries[index][0];
const val = entries[index][1];
accumulator = fn(accumulator, val, 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 intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union(other) {
const coll = new this.constructor[Symbol.species](this);
for (const [key, value] of other) {
if (!coll.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
for (const [key, value] of other) {
if (!this.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;
}
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed() {
return new this.constructor[Symbol.species](this).reverse();
}
/**
* 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);
* ```
*/
toSorted(compareFunction = _Collection.defaultSort) {
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
}
toJSON() {
return [...this.entries()];
}
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 = "2.1.0";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Collection,
version
});
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,628 @@
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;
}
findLast(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const val = entries[index][1];
const key = entries[index][0];
if (fn(val, key, this))
return val;
}
return void 0;
}
findLastKey(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const key = entries[index][0];
const val = entries[index][1];
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;
}
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight(fn, initialValue) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
const entries = [...this.entries()];
let accumulator;
let index;
if (initialValue === void 0) {
if (entries.length === 0)
throw new TypeError("Reduce of empty collection with no initial value");
accumulator = entries[entries.length - 1][1];
index = entries.length - 1;
} else {
accumulator = initialValue;
index = entries.length;
}
while (--index >= 0) {
const key = entries[index][0];
const val = entries[index][1];
accumulator = fn(accumulator, val, 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 intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union(other) {
const coll = new this.constructor[Symbol.species](this);
for (const [key, value] of other) {
if (!coll.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
for (const [key, value] of other) {
if (!this.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;
}
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed() {
return new this.constructor[Symbol.species](this).reverse();
}
/**
* 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);
* ```
*/
toSorted(compareFunction = _Collection.defaultSort) {
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
}
toJSON() {
return [...this.entries()];
}
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 = "2.1.0";
export {
Collection,
version
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,86 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/collection",
"version": "2.1.0",
"description": "Utility data structure used in discord.js",
"exports": {
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"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",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"devDependencies": {
"@favware/cliff-jumper": "^3.0.2",
"@types/node": "18.18.8",
"@vitest/coverage-v8": "^1.5.0",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0",
"@discordjs/api-extractor": "^7.38.1",
"@discordjs/scripts": "^0.1.0"
},
"engines": {
"node": ">=18"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"test": "vitest run",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'",
"release": "cliff-jumper"
}
}

119
node_modules/@discordjs/rest/package.json generated vendored Normal file
View file

@ -0,0 +1,119 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/rest",
"version": "2.3.0",
"description": "The REST API for discord.js",
"exports": {
".": {
"node": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"default": {
"require": {
"types": "./dist/web.d.ts",
"default": "./dist/web.js"
},
"import": {
"types": "./dist/web.d.mts",
"default": "./dist/web.mjs"
}
}
},
"./*": {
"require": {
"types": "./dist/strategies/*.d.ts",
"default": "./dist/strategies/*.js"
},
"import": {
"types": "./dist/strategies/*.d.mts",
"default": "./dist/strategies/*.mjs"
}
}
},
"types": "./dist/index.d.ts",
"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",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"dependencies": {
"@sapphire/async-queue": "^1.5.2",
"@sapphire/snowflake": "^3.5.3",
"@vladfrangu/async_event_emitter": "^2.2.4",
"discord-api-types": "0.37.83",
"magic-bytes.js": "^1.10.0",
"tslib": "^2.6.2",
"undici": "6.13.0",
"@discordjs/collection": "^2.1.0",
"@discordjs/util": "^1.1.0"
},
"devDependencies": {
"@favware/cliff-jumper": "^3.0.2",
"@types/node": "18.17.9",
"@vitest/coverage-v8": "^1.5.0",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0",
"@discordjs/scripts": "^0.1.0",
"@discordjs/api-extractor": "^7.38.1"
},
"engines": {
"node": ">=16.11.0"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"test": "vitest run",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/rest/*'",
"release": "cliff-jumper"
}
}

190
node_modules/@discordjs/util/LICENSE generated vendored Normal file
View file

@ -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.

65
node_modules/@discordjs/util/README.md generated vendored Normal file
View file

@ -0,0 +1,65 @@
<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
bun 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

132
node_modules/@discordjs/util/dist/index.d.mts generated vendored Normal file
View file

@ -0,0 +1,132 @@
/**
* Represents a type that may or may not be a promise
*/
type Awaitable<Value> = PromiseLike<Value> | Value;
/**
* 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 Value - The type of the value
* @example
* ```ts
* const value = lazy(() => computeExpensiveValue());
* ```
*/
declare function lazy<Value>(cb: () => Value): () => Value;
/**
* 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 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;
/**
* Polyfill for `Symbol.dispose` and `Symbol.asyncDispose` which is used as a part of
* {@link https://github.com/tc39/proposal-explicit-resource-management}. Node versions below 18.x
* don't have these symbols by default, so we need to polyfill them.
*/
declare function polyfillDispose(): void;
/**
* Represents an object capable of representing itself as a JSON object
*
* @typeParam Value - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.
*/
interface JSONEncodable<Value> {
/**
* Transforms this object to its JSON format
*/
toJSON(): Value;
}
/**
* 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 Value - The type of object to compare the current object to
*/
interface Equatable<Value> {
/**
* Whether or not this is equal to another structure
*/
equals(other: Value): 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>;
/**
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/util#readme | @discordjs/util} 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 { type Awaitable, type Equatable, type JSONEncodable, type RangeOptions, calculateShardId, getUserAgentAppendix, isEquatable, isJSONEncodable, lazy, polyfillDispose, range, shouldUseGlobalFetchAndWebSocket, version };

132
node_modules/@discordjs/util/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,132 @@
/**
* Represents a type that may or may not be a promise
*/
type Awaitable<Value> = PromiseLike<Value> | Value;
/**
* 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 Value - The type of the value
* @example
* ```ts
* const value = lazy(() => computeExpensiveValue());
* ```
*/
declare function lazy<Value>(cb: () => Value): () => Value;
/**
* 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 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;
/**
* Polyfill for `Symbol.dispose` and `Symbol.asyncDispose` which is used as a part of
* {@link https://github.com/tc39/proposal-explicit-resource-management}. Node versions below 18.x
* don't have these symbols by default, so we need to polyfill them.
*/
declare function polyfillDispose(): void;
/**
* Represents an object capable of representing itself as a JSON object
*
* @typeParam Value - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.
*/
interface JSONEncodable<Value> {
/**
* Transforms this object to its JSON format
*/
toJSON(): Value;
}
/**
* 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 Value - The type of object to compare the current object to
*/
interface Equatable<Value> {
/**
* Whether or not this is equal to another structure
*/
equals(other: Value): 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>;
/**
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/util#readme | @discordjs/util} 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 { type Awaitable, type Equatable, type JSONEncodable, type RangeOptions, calculateShardId, getUserAgentAppendix, isEquatable, isJSONEncodable, lazy, polyfillDispose, range, shouldUseGlobalFetchAndWebSocket, version };

144
node_modules/@discordjs/util/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,144 @@
"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,
polyfillDispose: () => polyfillDispose,
range: () => range,
shouldUseGlobalFetchAndWebSocket: () => shouldUseGlobalFetchAndWebSocket,
version: () => version
});
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/functions/polyfillDispose.ts
function polyfillDispose() {
Symbol.dispose ??= Symbol("Symbol.dispose");
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
}
__name(polyfillDispose, "polyfillDispose");
// 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");
// src/index.ts
var version = "1.1.0";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
calculateShardId,
getUserAgentAppendix,
isEquatable,
isJSONEncodable,
lazy,
polyfillDispose,
range,
shouldUseGlobalFetchAndWebSocket,
version
});
//# sourceMappingURL=index.js.map

1
node_modules/@discordjs/util/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

111
node_modules/@discordjs/util/dist/index.mjs generated vendored Normal file
View file

@ -0,0 +1,111 @@
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/functions/polyfillDispose.ts
function polyfillDispose() {
Symbol.dispose ??= Symbol("Symbol.dispose");
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
}
__name(polyfillDispose, "polyfillDispose");
// 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");
// src/index.ts
var version = "1.1.0";
export {
calculateShardId,
getUserAgentAppendix,
isEquatable,
isJSONEncodable,
lazy,
polyfillDispose,
range,
shouldUseGlobalFetchAndWebSocket,
version
};
//# sourceMappingURL=index.mjs.map

1
node_modules/@discordjs/util/dist/index.mjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

91
node_modules/@discordjs/util/package.json generated vendored Normal file
View file

@ -0,0 +1,91 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/util",
"version": "1.1.0",
"description": "Utilities shared across Discord.js packages",
"exports": {
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"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",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"devDependencies": {
"@favware/cliff-jumper": "^3.0.2",
"@types/node": "16.18.60",
"@vitest/coverage-v8": "^1.5.0",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"prettier": "^3.2.5",
"tsd": "^0.30.7",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0",
"@discordjs/api-extractor": "^7.38.1",
"@discordjs/scripts": "^0.1.0"
},
"engines": {
"node": ">=16.11.0"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"tsd": {
"directory": "__tests__/types"
},
"scripts": {
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"test": "vitest run && tsd",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/util/*'",
"release": "cliff-jumper"
}
}

191
node_modules/@discordjs/ws/LICENSE generated vendored Normal file
View file

@ -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 Denis 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.

204
node_modules/@discordjs/ws/README.md generated vendored Normal file
View file

@ -0,0 +1,204 @@
<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
bun 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`)
## 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',
// Optionally, if you have custom messaging, like for analytic collection, you can use this:
async unknownPayloadHandler(data: any) {
// handle data here :3
},
}),
});
```
And your `worker.ts` file:
```ts
import { WorkerBootstrapper, WebSocketShardEvents } from '@discordjs/ws';
import { parentPort } from 'node:worker_threads';
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
});
},
});
// This will go to `unknownPayloadHandler` in the main thread, or be ignored if not provided
parentPort!.postMessage({ custom: 'data' });
```
## 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

2
node_modules/@discordjs/ws/dist/defaultWorker.d.mts generated vendored Normal file
View file

@ -0,0 +1,2 @@
export { }

2
node_modules/@discordjs/ws/dist/defaultWorker.d.ts generated vendored Normal file
View file

@ -0,0 +1,2 @@
export { }

1058
node_modules/@discordjs/ws/dist/defaultWorker.js generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/ws/dist/defaultWorker.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1040
node_modules/@discordjs/ws/dist/defaultWorker.mjs generated vendored Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

704
node_modules/@discordjs/ws/dist/index.d.mts generated vendored Normal file
View file

@ -0,0 +1,704 @@
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
}
interface 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 {
resetAt: number;
sent: 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;
}
interface WebSocketManagerOptions extends OptionalWebSocketManagerOptions, RequiredWebSocketManagerOptions {
}
interface CreateWebSocketManagerOptions extends Partial<OptionalWebSocketManagerOptions>, RequiredWebSocketManagerOptions {
}
interface ManagerShardEventsMap {
[WebSocketShardEvents.Closed]: [{
code: number;
shardId: number;
}];
[WebSocketShardEvents.Debug]: [payload: {
message: string;
shardId: number;
}];
[WebSocketShardEvents.Dispatch]: [payload: {
data: GatewayDispatchPayload;
shardId: number;
}];
[WebSocketShardEvents.Error]: [payload: {
error: Error;
shardId: number;
}];
[WebSocketShardEvents.Hello]: [{
shardId: number;
}];
[WebSocketShardEvents.Ready]: [payload: {
data: GatewayReadyDispatchData;
shardId: number;
}];
[WebSocketShardEvents.Resumed]: [{
shardId: number;
}];
[WebSocketShardEvents.HeartbeatComplete]: [
payload: {
ackAt: number;
heartbeatAt: number;
latency: number;
shardId: number;
}
];
}
declare class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> implements AsyncDisposable {
/**
* 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: CreateWebSocketManagerOptions);
/**
* 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>>;
[Symbol.asyncDispose](): Promise<void>;
}
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';
/**
* Handles a payload not recognized by the handler.
*/
unknownPayloadHandler?(payload: any): unknown;
/**
* 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 { type BootstrapOptions, CloseCodes, CompressionMethod, type CreateWebSocketManagerOptions, DefaultDeviceProperty, DefaultWebSocketManagerOptions, Encoding, type FetchingStrategyOptions, type IContextFetchingStrategy, type IIdentifyThrottler, type IShardingStrategy, type IdentifyState, ImportantGatewayOpcodes, type ManagerShardEventsMap, type OptionalWebSocketManagerOptions, type RequiredWebSocketManagerOptions, type SendRateLimitState, type SessionInfo, type ShardRange, SimpleContextFetchingStrategy, SimpleIdentifyThrottler, SimpleShardingStrategy, WebSocketManager, type WebSocketManagerOptions, WebSocketShard, type WebSocketShardDestroyOptions, WebSocketShardDestroyRecovery, WebSocketShardEvents, type WebSocketShardEventsMap, WebSocketShardStatus, WorkerBootstrapper, WorkerContextFetchingStrategy, type WorkerData, type WorkerReceivePayload, WorkerReceivePayloadOp, type WorkerSendPayload, WorkerSendPayloadOp, WorkerShardingStrategy, type WorkerShardingStrategyOptions, getInitialSendRateLimitState, managerToFetchingStrategyOptions, version };

704
node_modules/@discordjs/ws/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,704 @@
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
}
interface 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 {
resetAt: number;
sent: 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;
}
interface WebSocketManagerOptions extends OptionalWebSocketManagerOptions, RequiredWebSocketManagerOptions {
}
interface CreateWebSocketManagerOptions extends Partial<OptionalWebSocketManagerOptions>, RequiredWebSocketManagerOptions {
}
interface ManagerShardEventsMap {
[WebSocketShardEvents.Closed]: [{
code: number;
shardId: number;
}];
[WebSocketShardEvents.Debug]: [payload: {
message: string;
shardId: number;
}];
[WebSocketShardEvents.Dispatch]: [payload: {
data: GatewayDispatchPayload;
shardId: number;
}];
[WebSocketShardEvents.Error]: [payload: {
error: Error;
shardId: number;
}];
[WebSocketShardEvents.Hello]: [{
shardId: number;
}];
[WebSocketShardEvents.Ready]: [payload: {
data: GatewayReadyDispatchData;
shardId: number;
}];
[WebSocketShardEvents.Resumed]: [{
shardId: number;
}];
[WebSocketShardEvents.HeartbeatComplete]: [
payload: {
ackAt: number;
heartbeatAt: number;
latency: number;
shardId: number;
}
];
}
declare class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> implements AsyncDisposable {
/**
* 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: CreateWebSocketManagerOptions);
/**
* 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>>;
[Symbol.asyncDispose](): Promise<void>;
}
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';
/**
* Handles a payload not recognized by the handler.
*/
unknownPayloadHandler?(payload: any): unknown;
/**
* 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 { type BootstrapOptions, CloseCodes, CompressionMethod, type CreateWebSocketManagerOptions, DefaultDeviceProperty, DefaultWebSocketManagerOptions, Encoding, type FetchingStrategyOptions, type IContextFetchingStrategy, type IIdentifyThrottler, type IShardingStrategy, type IdentifyState, ImportantGatewayOpcodes, type ManagerShardEventsMap, type OptionalWebSocketManagerOptions, type RequiredWebSocketManagerOptions, type SendRateLimitState, type SessionInfo, type ShardRange, SimpleContextFetchingStrategy, SimpleIdentifyThrottler, SimpleShardingStrategy, WebSocketManager, type WebSocketManagerOptions, WebSocketShard, type WebSocketShardDestroyOptions, WebSocketShardDestroyRecovery, WebSocketShardEvents, type WebSocketShardEventsMap, WebSocketShardStatus, WorkerBootstrapper, WorkerContextFetchingStrategy, type WorkerData, type WorkerReceivePayload, WorkerReceivePayloadOp, type WorkerSendPayload, WorkerSendPayloadOp, WorkerShardingStrategy, type WorkerShardingStrategyOptions, getInitialSendRateLimitState, managerToFetchingStrategyOptions, version };

1505
node_modules/@discordjs/ws/dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/ws/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1469
node_modules/@discordjs/ws/dist/index.mjs generated vendored Normal file

File diff suppressed because it is too large Load diff

1
node_modules/@discordjs/ws/dist/index.mjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -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.

View file

@ -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 18 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

View file

@ -0,0 +1,535 @@
/**
* @internal
*/
interface CollectionConstructor {
new (): Collection<unknown, unknown>;
new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
readonly prototype: Collection<unknown, unknown>;
readonly [Symbol.species]: CollectionConstructor;
}
/**
* Represents an immutable version of a collection
*/
type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
/**
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
*
* @internal
*/
interface Collection<Key, Value> extends Map<Key, Value> {
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 Key - The key type this collection holds
* @typeParam Value - The value type this collection holds
*/
declare class Collection<Key, Value> extends Map<Key, Value> {
/**
* 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: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
/**
* 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: Key[]): 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: Key[]): 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(): Value | undefined;
first(amount: number): Value[];
/**
* 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(): Key | undefined;
firstKey(amount: number): Key[];
/**
* 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(): Value | undefined;
last(amount: number): Value[];
/**
* 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(): Key | undefined;
lastKey(amount: number): Key[];
/**
* 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): Value | 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): Key | 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(): Value | undefined;
random(amount: number): Value[];
/**
* 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(): Key | undefined;
randomKey(amount: number): Key[];
/**
* 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.find(user => user.username === 'Bob');
* ```
*/
find<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
find(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
find<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
find<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.findKey(user => user.username === 'Bob');
* ```
*/
findKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
/**
* Searches for a last 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/findLast | Array.findLast()}.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLast<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
findLast(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
findLast<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
findLast<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
/**
* Searches for the key of a last 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/findLastIndex | Array.findLastIndex()},
* but returns the key rather than the positional index.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLastKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findLastKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findLastKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findLastKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | 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 the function
* @returns The number of removed entries
*/
sweep(fn: (value: Value, key: Key, collection: this) => unknown): number;
sweep<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.filter(user => user.username === 'Bob');
* ```
*/
filter<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): Collection<NewKey, Value>;
filter<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): Collection<Key, NewValue>;
filter(fn: (value: Value, key: Key, collection: this) => unknown): Collection<Key, Value>;
filter<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): Collection<NewKey, Value>;
filter<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): Collection<Key, NewValue>;
filter<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Collection<Key, Value>;
/**
* 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 the function
* @example
* ```ts
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
* ```
*/
partition<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition(fn: (value: Value, key: Key, collection: this) => unknown): [Collection<Key, Value>, Collection<Key, Value>];
partition<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): [Collection<Key, Value>, Collection<Key, Value>];
/**
* 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 the function
* @example
* ```ts
* collection.flatMap(guild => guild.members.cache);
* ```
*/
flatMap<NewValue>(fn: (value: Value, key: Key, collection: this) => Collection<Key, NewValue>): Collection<Key, NewValue>;
flatMap<NewValue, This>(fn: (this: This, value: Value, key: Key, collection: this) => Collection<Key, NewValue>, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.map(user => user.tag);
* ```
*/
map<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): NewValue[];
map<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): NewValue[];
/**
* 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 the function
* @example
* ```ts
* collection.mapValues(user => user.tag);
* ```
*/
mapValues<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): Collection<Key, NewValue>;
mapValues<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.some(user => user.discriminator === '0000');
* ```
*/
some(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
some<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 the function
* @example
* ```ts
* collection.every(user => !user.bot);
* ```
*/
every<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): this is Collection<NewKey, Value>;
every<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): this is Collection<Key, NewValue>;
every(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
every<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): this is Collection<NewKey, Value>;
every<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): this is Collection<Key, NewValue>;
every<This>(fn: (this: This, value: Value, key: Key, 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<InitialValue = Value>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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 the function
* @example
* ```ts
* collection
* .each(user => console.log(user.username))
* .filter(user => user.bot)
* .each(user => console.log(user.username));
* ```
*/
each(fn: (value: Value, key: Key, collection: this) => void): this;
each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): 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 the 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<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
/**
* Creates an identical shallow copy of this collection.
*
* @example
* ```ts
* const newColl = someColl.clone();
* ```
*/
clone(): Collection<Key, Value>;
/**
* 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<Key, Value>[]): Collection<Key, Value>;
/**
* 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<Key, Value>): 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<Key, Value>): this;
/**
* The intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* 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<OtherValue, ResultValue>(other: ReadonlyCollection<Key, OtherValue>, whenInSelf: (value: Value, key: Key) => Keep<ResultValue>, whenInOther: (valueOther: OtherValue, key: Key) => Keep<ResultValue>, whenInBoth: (value: Value, valueOther: OtherValue, key: Key) => Keep<ResultValue>): Collection<Key, ResultValue>;
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed(): Collection<Key, Value>;
/**
* 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);
* ```
*/
toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
toJSON(): [Key, Value][];
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<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
}
/**
* @internal
*/
type Keep<Value> = {
keep: false;
} | {
keep: true;
value: Value;
};
/**
* @internal
*/
type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => 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, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };

View file

@ -0,0 +1,535 @@
/**
* @internal
*/
interface CollectionConstructor {
new (): Collection<unknown, unknown>;
new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
readonly prototype: Collection<unknown, unknown>;
readonly [Symbol.species]: CollectionConstructor;
}
/**
* Represents an immutable version of a collection
*/
type ReadonlyCollection<Key, Value> = Omit<Collection<Key, Value>, 'clear' | 'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'> & ReadonlyMap<Key, Value>;
/**
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
*
* @internal
*/
interface Collection<Key, Value> extends Map<Key, Value> {
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 Key - The key type this collection holds
* @typeParam Value - The value type this collection holds
*/
declare class Collection<Key, Value> extends Map<Key, Value> {
/**
* 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: Key, defaultValueGenerator: (key: Key, collection: this) => Value): Value;
/**
* 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: Key[]): 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: Key[]): 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(): Value | undefined;
first(amount: number): Value[];
/**
* 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(): Key | undefined;
firstKey(amount: number): Key[];
/**
* 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(): Value | undefined;
last(amount: number): Value[];
/**
* 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(): Key | undefined;
lastKey(amount: number): Key[];
/**
* 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): Value | 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): Key | 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(): Value | undefined;
random(amount: number): Value[];
/**
* 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(): Key | undefined;
randomKey(amount: number): Key[];
/**
* 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.find(user => user.username === 'Bob');
* ```
*/
find<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
find(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
find<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
find<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.findKey(user => user.username === 'Bob');
* ```
*/
findKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | undefined;
/**
* Searches for a last 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/findLast | Array.findLast()}.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLast<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): NewValue | undefined;
findLast(fn: (value: Value, key: Key, collection: this) => unknown): Value | undefined;
findLast<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): NewValue | undefined;
findLast<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Value | undefined;
/**
* Searches for the key of a last 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/findLastIndex | Array.findLastIndex()},
* but returns the key rather than the positional index.
*
* @param fn - The function to test with (should return a boolean)
* @param thisArg - Value to use as `this` when executing the function
*/
findLastKey<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): NewKey | undefined;
findLastKey(fn: (value: Value, key: Key, collection: this) => unknown): Key | undefined;
findLastKey<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): NewKey | undefined;
findLastKey<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Key | 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 the function
* @returns The number of removed entries
*/
sweep(fn: (value: Value, key: Key, collection: this) => unknown): number;
sweep<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 a boolean)
* @param thisArg - Value to use as `this` when executing the function
* @example
* ```ts
* collection.filter(user => user.username === 'Bob');
* ```
*/
filter<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): Collection<NewKey, Value>;
filter<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): Collection<Key, NewValue>;
filter(fn: (value: Value, key: Key, collection: this) => unknown): Collection<Key, Value>;
filter<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): Collection<NewKey, Value>;
filter<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): Collection<Key, NewValue>;
filter<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): Collection<Key, Value>;
/**
* 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 the function
* @example
* ```ts
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
* ```
*/
partition<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition(fn: (value: Value, key: Key, collection: this) => unknown): [Collection<Key, Value>, Collection<Key, Value>];
partition<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): [Collection<NewKey, Value>, Collection<Exclude<Key, NewKey>, Value>];
partition<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): [Collection<Key, NewValue>, Collection<Key, Exclude<Value, NewValue>>];
partition<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): [Collection<Key, Value>, Collection<Key, Value>];
/**
* 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 the function
* @example
* ```ts
* collection.flatMap(guild => guild.members.cache);
* ```
*/
flatMap<NewValue>(fn: (value: Value, key: Key, collection: this) => Collection<Key, NewValue>): Collection<Key, NewValue>;
flatMap<NewValue, This>(fn: (this: This, value: Value, key: Key, collection: this) => Collection<Key, NewValue>, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.map(user => user.tag);
* ```
*/
map<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): NewValue[];
map<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): NewValue[];
/**
* 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 the function
* @example
* ```ts
* collection.mapValues(user => user.tag);
* ```
*/
mapValues<NewValue>(fn: (value: Value, key: Key, collection: this) => NewValue): Collection<Key, NewValue>;
mapValues<This, NewValue>(fn: (this: This, value: Value, key: Key, collection: this) => NewValue, thisArg: This): Collection<Key, NewValue>;
/**
* 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 the function
* @example
* ```ts
* collection.some(user => user.discriminator === '0000');
* ```
*/
some(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
some<This>(fn: (this: This, value: Value, key: Key, collection: this) => unknown, thisArg: This): 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 the function
* @example
* ```ts
* collection.every(user => !user.bot);
* ```
*/
every<NewKey extends Key>(fn: (value: Value, key: Key, collection: this) => key is NewKey): this is Collection<NewKey, Value>;
every<NewValue extends Value>(fn: (value: Value, key: Key, collection: this) => value is NewValue): this is Collection<Key, NewValue>;
every(fn: (value: Value, key: Key, collection: this) => unknown): boolean;
every<This, NewKey extends Key>(fn: (this: This, value: Value, key: Key, collection: this) => key is NewKey, thisArg: This): this is Collection<NewKey, Value>;
every<This, NewValue extends Value>(fn: (this: This, value: Value, key: Key, collection: this) => value is NewValue, thisArg: This): this is Collection<Key, NewValue>;
every<This>(fn: (this: This, value: Value, key: Key, 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<InitialValue = Value>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight<InitialValue>(fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue, initialValue?: InitialValue): InitialValue;
/**
* 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 the function
* @example
* ```ts
* collection
* .each(user => console.log(user.username))
* .filter(user => user.bot)
* .each(user => console.log(user.username));
* ```
*/
each(fn: (value: Value, key: Key, collection: this) => void): this;
each<This>(fn: (this: This, value: Value, key: Key, collection: this) => void, thisArg: This): 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 the 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<This>(fn: (this: This, collection: this) => void, thisArg: This): this;
/**
* Creates an identical shallow copy of this collection.
*
* @example
* ```ts
* const newColl = someColl.clone();
* ```
*/
clone(): Collection<Key, Value>;
/**
* 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<Key, Value>[]): Collection<Key, Value>;
/**
* 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<Key, Value>): 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<Key, Value>): this;
/**
* The intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other: ReadonlyCollection<Key, any>): Collection<Key, Value>;
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference<OtherValue>(other: ReadonlyCollection<Key, OtherValue>): Collection<Key, OtherValue | Value>;
/**
* 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<OtherValue, ResultValue>(other: ReadonlyCollection<Key, OtherValue>, whenInSelf: (value: Value, key: Key) => Keep<ResultValue>, whenInOther: (valueOther: OtherValue, key: Key) => Keep<ResultValue>, whenInBoth: (value: Value, valueOther: OtherValue, key: Key) => Keep<ResultValue>): Collection<Key, ResultValue>;
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed(): Collection<Key, Value>;
/**
* 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);
* ```
*/
toSorted(compareFunction?: Comparator<Key, Value>): Collection<Key, Value>;
toJSON(): [Key, Value][];
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<Key, Value>(entries: Iterable<[Key, Value]>, combine: (firstValue: Value, secondValue: Value, key: Key) => Value): Collection<Key, Value>;
}
/**
* @internal
*/
type Keep<Value> = {
keep: false;
} | {
keep: true;
value: Value;
};
/**
* @internal
*/
type Comparator<Key, Value> = (firstValue: Value, secondValue: Value, firstKey: Key, secondKey: Key) => 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, type CollectionConstructor, type Comparator, type Keep, type ReadonlyCollection, version };

View file

@ -0,0 +1,654 @@
"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;
}
findLast(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const val = entries[index][1];
const key = entries[index][0];
if (fn(val, key, this))
return val;
}
return void 0;
}
findLastKey(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const key = entries[index][0];
const val = entries[index][1];
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;
}
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight(fn, initialValue) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
const entries = [...this.entries()];
let accumulator;
let index;
if (initialValue === void 0) {
if (entries.length === 0)
throw new TypeError("Reduce of empty collection with no initial value");
accumulator = entries[entries.length - 1][1];
index = entries.length - 1;
} else {
accumulator = initialValue;
index = entries.length;
}
while (--index >= 0) {
const key = entries[index][0];
const val = entries[index][1];
accumulator = fn(accumulator, val, 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 intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union(other) {
const coll = new this.constructor[Symbol.species](this);
for (const [key, value] of other) {
if (!coll.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
for (const [key, value] of other) {
if (!this.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;
}
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed() {
return new this.constructor[Symbol.species](this).reverse();
}
/**
* 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);
* ```
*/
toSorted(compareFunction = _Collection.defaultSort) {
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
}
toJSON() {
return [...this.entries()];
}
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 = "2.1.0";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Collection,
version
});
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,628 @@
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;
}
findLast(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const val = entries[index][1];
const key = entries[index][0];
if (fn(val, key, this))
return val;
}
return void 0;
}
findLastKey(fn, thisArg) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
if (thisArg !== void 0)
fn = fn.bind(thisArg);
const entries = [...this.entries()];
for (let index = entries.length - 1; index >= 0; index--) {
const key = entries[index][0];
const val = entries[index][1];
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;
}
/**
* 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/reduceRight | Array.reduceRight()}.
*
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
reduceRight(fn, initialValue) {
if (typeof fn !== "function")
throw new TypeError(`${fn} is not a function`);
const entries = [...this.entries()];
let accumulator;
let index;
if (initialValue === void 0) {
if (entries.length === 0)
throw new TypeError("Reduce of empty collection with no initial value");
accumulator = entries[entries.length - 1][1];
index = entries.length - 1;
} else {
accumulator = initialValue;
index = entries.length;
}
while (--index >= 0) {
const key = entries[index][0];
const val = entries[index][1];
accumulator = fn(accumulator, val, 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 intersection method returns a new collection containing the items where the key is present in both collections.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const intersection = col1.intersection(col2);
* console.log(col1.intersection(col2));
* // => Collection { 'a' => 1 }
* ```
*/
intersection(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in either of the collections.
*
* @remarks
*
* If the collections have any items with the same key, the value from the first collection will be used.
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['b', 3], ['c', 3]]);
* const union = col1.union(col2);
* console.log(union);
* // => Collection { 'a' => 1, 'b' => 2, 'c' => 3 }
* ```
*/
union(other) {
const coll = new this.constructor[Symbol.species](this);
for (const [key, value] of other) {
if (!coll.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing the items where the key is present in this collection but not the other.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* console.log(col1.difference(col2));
* // => Collection { 'b' => 2 }
* console.log(col2.difference(col1));
* // => Collection { 'c' => 3 }
* ```
*/
difference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
return coll;
}
/**
* Returns a new collection containing only the items where the keys are present in either collection, but not both.
*
* @param other - The other Collection to filter against
* @example
* ```ts
* const col1 = new Collection([['a', 1], ['b', 2]]);
* const col2 = new Collection([['a', 1], ['c', 3]]);
* const symmetricDifference = col1.symmetricDifference(col2);
* console.log(col1.symmetricDifference(col2));
* // => Collection { 'b' => 2, 'c' => 3 }
* ```
*/
symmetricDifference(other) {
const coll = new this.constructor[Symbol.species]();
for (const [key, value] of this) {
if (!other.has(key))
coll.set(key, value);
}
for (const [key, value] of other) {
if (!this.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;
}
/**
* Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed | Array.toReversed()}
* but returns a Collection instead of an Array.
*/
toReversed() {
return new this.constructor[Symbol.species](this).reverse();
}
/**
* 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);
* ```
*/
toSorted(compareFunction = _Collection.defaultSort) {
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
}
toJSON() {
return [...this.entries()];
}
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 = "2.1.0";
export {
Collection,
version
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,86 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/collection",
"version": "2.1.0",
"description": "Utility data structure used in discord.js",
"exports": {
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"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",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"devDependencies": {
"@favware/cliff-jumper": "^3.0.2",
"@types/node": "18.18.8",
"@vitest/coverage-v8": "^1.5.0",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0",
"@discordjs/api-extractor": "^7.38.1",
"@discordjs/scripts": "^0.1.0"
},
"engines": {
"node": ">=18"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"test": "vitest run",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'",
"release": "cliff-jumper"
}
}

113
node_modules/@discordjs/ws/package.json generated vendored Normal file
View file

@ -0,0 +1,113 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/ws",
"version": "1.1.0",
"description": "Wrapper around Discord's gateway",
"exports": {
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"./defaultWorker": {
"require": {
"types": null,
"default": "./dist/defaultWorker.js"
},
"import": {
"types": null,
"default": "./dist/defaultWorker.mjs"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"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",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"dependencies": {
"@sapphire/async-queue": "^1.5.2",
"@types/ws": "^8.5.10",
"@vladfrangu/async_event_emitter": "^2.2.4",
"discord-api-types": "0.37.83",
"tslib": "^2.6.2",
"ws": "^8.16.0",
"@discordjs/rest": "^2.3.0",
"@discordjs/collection": "^2.1.0",
"@discordjs/util": "^1.1.0"
},
"devDependencies": {
"@favware/cliff-jumper": "^3.0.2",
"@types/node": "18.17.9",
"@vitest/coverage-v8": "^1.5.0",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"mock-socket": "^9.3.1",
"prettier": "^3.2.5",
"tsd": "^0.30.7",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"undici": "6.13.0",
"vitest": "^1.5.0",
"zlib-sync": "^0.1.9",
"@discordjs/api-extractor": "^7.38.1",
"@discordjs/scripts": "^0.1.0"
},
"engines": {
"node": ">=16.11.0"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"test": "vitest run",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/ws/*'",
"release": "cliff-jumper"
}
}

190
node_modules/@sapphire/async-queue/CHANGELOG.md generated vendored Normal file
View file

@ -0,0 +1,190 @@
# Changelog
All notable changes to this project will be documented in this file.
# [@sapphire/async-queue@1.5.2](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.5.2...@sapphire/async-queue@1.5.2) - (2024-01-19)
## 🐛 Bug Fixes
- Fixed commonjs typings export mapping (#707) ([216ff02](https://github.com/sapphiredev/utilities/commit/216ff0260d63a9590357f9a5069f1ae2b34eaf5d))
# [@sapphire/async-queue@1.5.1](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.5.1...@sapphire/async-queue@1.5.1) - (2023-12-04)
## 🏠 Refactor
- Split `@sapphire/time-utilities` into 4 sub-packages (#462) ([574299a](https://github.com/sapphiredev/utilities/commit/574299a99e658f6500a2a7efa587a0919b2d1313))
## 🐛 Bug Fixes
- **async-queue:** Properly split CJS, ESM and IIFE ([75f215c](https://github.com/sapphiredev/utilities/commit/75f215cd8b42b3c57a92f2fe01dff59b7edb02d6))
- Update export mapping for proper ESM/CJS split ([dd0cff8](https://github.com/sapphiredev/utilities/commit/dd0cff8e9b03a15812f25f7a1180501a92422629))
- **deps:** Update all non-major dependencies (#607) ([9cc8bd0](https://github.com/sapphiredev/utilities/commit/9cc8bd0d4b5d650deab2c913e6c3d713861bae28))
- **deps:** Update all non-major dependencies (#577) ([291dd67](https://github.com/sapphiredev/utilities/commit/291dd6783e57d8f075ce566218ba076ef6c4bbbd))
- **deps:** Update all non-major dependencies (#545) ([40ca040](https://github.com/sapphiredev/utilities/commit/40ca040a21d8a0949682051a3a974538183a400e))
- **deps:** Update all non-major dependencies (#544) ([cc78f17](https://github.com/sapphiredev/utilities/commit/cc78f17390c7f3db08af92bf46a5a70a9c11dd5f))
- **deps:** Update all non-major dependencies (#532) ([8033d1f](https://github.com/sapphiredev/utilities/commit/8033d1ff7a5a1974134c61f424f171cccb2915e1))
- **deps:** Update all non-major dependencies (#514) ([21b07d5](https://github.com/sapphiredev/utilities/commit/21b07d5db529a0d982647a60de98e46f36f1ac93))
- **deps:** Update all non-major dependencies (#505) ([6178296](https://github.com/sapphiredev/utilities/commit/617829649e1e4deeee02b14533b5377cd5bc1fb3))
- **deps:** Update all non-major dependencies (#466) ([dc08606](https://github.com/sapphiredev/utilities/commit/dc08606a97154e47c65536123ac5f8b1262f7bd2))
- **deps:** Update all non-major dependencies ([e20f299](https://github.com/sapphiredev/utilities/commit/e20f29906e83cee000aaba9c6827e3bec5173d28))
## 📝 Documentation
- Add @06000208 as a contributor ([fa3349e](https://github.com/sapphiredev/utilities/commit/fa3349e55ce4ad008785211dec7bf8e2b5d933df))
- Add @didinele as a contributor ([42ef7b6](https://github.com/sapphiredev/utilities/commit/42ef7b656c48fd0e720119db1d622c8bba2791e9))
- Add @goestav as a contributor ([0e56a92](https://github.com/sapphiredev/utilities/commit/0e56a92a4e2d0942bfa207f81a8cb03b32312034))
- Add @CitTheDev as a contributor ([34169ea](https://github.com/sapphiredev/utilities/commit/34169eae1dc0476ccf5a6c4f36e28602a204829e))
- Add @legendhimslef as a contributor ([059b6f1](https://github.com/sapphiredev/utilities/commit/059b6f1ab5362d46d58624d06c1aa39192b0716f))
- Add @r-priyam as a contributor ([fb278ba](https://github.com/sapphiredev/utilities/commit/fb278bacf627ec6fc88752eafeb12df5f3177a2c))
- Change name of @kyranet (#451) ([df4fdef](https://github.com/sapphiredev/utilities/commit/df4fdefce18659975a4ebc224723638507d02d35))
- Update @RealShadowNova as a contributor ([a869ba0](https://github.com/sapphiredev/utilities/commit/a869ba0abfad041610b9115187d426aebe671af6))
## 🧪 Testing
- Update vitest to coverage v8 ([a4bc6e4](https://github.com/sapphiredev/utilities/commit/a4bc6e4f24ea60143a150ecc76fda6484f172ab9))
- Cleanup tests ([aec1bb2](https://github.com/sapphiredev/utilities/commit/aec1bb290d0f3c00a1ae4f4c86302ebbb161d348))
# [@sapphire/async-queue@1.5.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.4.0...@sapphire/async-queue@1.5.0) - (2022-08-16)
## 🐛 Bug Fixes
- **deps:** Update all non-major dependencies ([2308bd7](https://github.com/sapphiredev/utilities/commit/2308bd74356b6b2e0c12995b25f4d8ade4803fe9))
## 🚀 Features
- Add `AsyncQueue#abortAll` (#429) ([b351e70](https://github.com/sapphiredev/utilities/commit/b351e70ebef329009daaebba89729ee84bb5704c))
# [@sapphire/async-queue@1.4.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.3.1...@sapphire/async-queue@1.4.0) - (2022-08-07)
## 🐛 Bug Fixes
- **deps:** Update all non-major dependencies ([84af0db](https://github.com/sapphiredev/utilities/commit/84af0db2db749223b036aa99fe19a2e9af5681c6))
- **deps:** Update all non-major dependencies ([50cd8de](https://github.com/sapphiredev/utilities/commit/50cd8dea593b6f5ae75571209456b3421e2ca59a))
## 📝 Documentation
- Add @muchnameless as a contributor ([a1221fe](https://github.com/sapphiredev/utilities/commit/a1221fea68506e99591d5d00ec552a07c26833f9))
- Add @enxg as a contributor ([d2382f0](https://github.com/sapphiredev/utilities/commit/d2382f04e3909cb4ad11798a0a10e683f6cf5383))
- Add @EvolutionX-10 as a contributor ([efc3a32](https://github.com/sapphiredev/utilities/commit/efc3a320a72ae258996dd62866d206c33f8d4961))
- Add @MajesticString as a contributor ([295b3e9](https://github.com/sapphiredev/utilities/commit/295b3e9849a4b0fe64074bae02f6426378a303c3))
- Add @Mzato0001 as a contributor ([c790ef2](https://github.com/sapphiredev/utilities/commit/c790ef25df2d7e22888fa9f8169167aa555e9e19))
- Add @NotKaskus as a contributor ([00da8f1](https://github.com/sapphiredev/utilities/commit/00da8f199137b9277119823f322d1f2d168d928a))
- Add @imranbarbhuiya as a contributor ([fb674c2](https://github.com/sapphiredev/utilities/commit/fb674c2c5594d41e71662263553dcb4bac9e37f4))
- Add @axisiscool as a contributor ([ce1aa31](https://github.com/sapphiredev/utilities/commit/ce1aa316871a88d3663efbdf2a42d3d8dfe6a27f))
- Add @dhruv-kaushikk as a contributor ([ebbf43f](https://github.com/sapphiredev/utilities/commit/ebbf43f63617daba96e72c50a234bf8b64f6ddc4))
- Add @Commandtechno as a contributor ([f1d69fa](https://github.com/sapphiredev/utilities/commit/f1d69fabe1ee0abe4be08b19e63dbec03102f7ce))
- Fix typedoc causing OOM crashes ([63ba41c](https://github.com/sapphiredev/utilities/commit/63ba41c4b6678554b1c7043a22d3296db4f59360))
## 🚀 Features
- **AsyncQueue:** Add AbortSignal support (#417) ([c0629e7](https://github.com/sapphiredev/utilities/commit/c0629e781ebc3f48e496a0851191b32e91f62fe9))
## 🧪 Testing
- Migrate to vitest (#380) ([075ec73](https://github.com/sapphiredev/utilities/commit/075ec73c7a8e3374fad3ada612d37eb4ac36ec8d))
## [1.3.1](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.3.0...@sapphire/async-queue@1.3.1) (2022-04-01)
**Note:** Version bump only for package @sapphire/async-queue
# [1.3.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.2.0...@sapphire/async-queue@1.3.0) (2022-03-06)
### Features
- allow module: NodeNext ([#306](https://github.com/sapphiredev/utilities/issues/306)) ([9dc6dd6](https://github.com/sapphiredev/utilities/commit/9dc6dd619efab879bb2b0b3c9e64304e10a67ed6))
- **ts-config:** add multi-config structure ([#281](https://github.com/sapphiredev/utilities/issues/281)) ([b5191d7](https://github.com/sapphiredev/utilities/commit/b5191d7f2416dc5838590c4ff221454925553e37))
# [1.2.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.9...@sapphire/async-queue@1.2.0) (2022-01-28)
### Features
- change build system to tsup ([#270](https://github.com/sapphiredev/utilities/issues/270)) ([365a53a](https://github.com/sapphiredev/utilities/commit/365a53a5517a01a0926cf28a83c96b63f32ed9f8))
## [1.1.9](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.8...@sapphire/async-queue@1.1.9) (2021-11-06)
**Note:** Version bump only for package @sapphire/async-queue
## [1.1.8](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.7...@sapphire/async-queue@1.1.8) (2021-10-26)
**Note:** Version bump only for package @sapphire/async-queue
## [1.1.7](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.6...@sapphire/async-queue@1.1.7) (2021-10-17)
### Bug Fixes
- allow more node & npm versions in engines field ([5977d2a](https://github.com/sapphiredev/utilities/commit/5977d2a30a4b2cfdf84aff3f33af03ffde1bbec5))
## [1.1.6](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.5...@sapphire/async-queue@1.1.6) (2021-10-11)
**Note:** Version bump only for package @sapphire/async-queue
## [1.1.5](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.4...@sapphire/async-queue@1.1.5) (2021-10-04)
**Note:** Version bump only for package @sapphire/async-queue
## [1.1.4](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.3...@sapphire/async-queue@1.1.4) (2021-06-27)
**Note:** Version bump only for package @sapphire/async-queue
## [1.1.3](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.2...@sapphire/async-queue@1.1.3) (2021-06-06)
### Bug Fixes
- remove peer deps, update dev deps, update READMEs ([#124](https://github.com/sapphiredev/utilities/issues/124)) ([67256ed](https://github.com/sapphiredev/utilities/commit/67256ed43b915b02a8b5c68230ba82d6210c5032))
## [1.1.2](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.1...@sapphire/async-queue@1.1.2) (2021-05-20)
### Bug Fixes
- **async-queue:** mark package as side effect free ([1c4b901](https://github.com/sapphiredev/utilities/commit/1c4b901cda3d14bd085c35cc74e160f844567ba7))
## [1.1.1](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.0...@sapphire/async-queue@1.1.1) (2021-05-02)
### Bug Fixes
- drop the `www.` from the SapphireJS URL ([494d89f](https://github.com/sapphiredev/utilities/commit/494d89ffa04f78c195b93d7905b3232884f7d7e2))
- update all the SapphireJS URLs from `.com` to `.dev` ([f59b46d](https://github.com/sapphiredev/utilities/commit/f59b46d1a0ebd39cad17b17d71cd3b9da808d5fd))
# [1.1.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.7...@sapphire/async-queue@1.1.0) (2021-04-21)
### Features
- add @sapphire/embed-jsx ([#100](https://github.com/sapphiredev/utilities/issues/100)) ([7277a23](https://github.com/sapphiredev/utilities/commit/7277a236015236ed8e81b7882875410facc4ce17))
## [1.0.7](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.6...@sapphire/async-queue@1.0.7) (2021-04-19)
### Bug Fixes
- change all Sapphire URLs from "project"->"community" & use our domain where applicable 👨‍🌾🚜 ([#102](https://github.com/sapphiredev/utilities/issues/102)) ([835b408](https://github.com/sapphiredev/utilities/commit/835b408e8e57130c3787aca2e32613346ff23e4d))
## [1.0.6](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.5...@sapphire/async-queue@1.0.6) (2021-04-03)
**Note:** Version bump only for package @sapphire/async-queue
## [1.0.5](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.4...@sapphire/async-queue@1.0.5) (2021-03-16)
### Bug Fixes
- remove terser from all packages ([#79](https://github.com/sapphiredev/utilities/issues/79)) ([1cfe4e7](https://github.com/sapphiredev/utilities/commit/1cfe4e7c804e62c142495686d2b83b81d0026c02))
## [1.0.4](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.3...@sapphire/async-queue@1.0.4) (2021-02-16)
**Note:** Version bump only for package @sapphire/async-queue
## [1.0.3](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.2...@sapphire/async-queue@1.0.3) (2021-02-13)
**Note:** Version bump only for package @sapphire/async-queue
## [1.0.2](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.1...@sapphire/async-queue@1.0.2) (2021-01-25)
**Note:** Version bump only for package @sapphire/async-queue
## [1.0.1](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.0...@sapphire/async-queue@1.0.1) (2021-01-16)
**Note:** Version bump only for package @sapphire/async-queue
# 1.0.0 (2021-01-13)
### Features
- **async-queue:** add async-queue package ([#56](https://github.com/sapphiredev/utilities/issues/56)) ([ba81832](https://github.com/sapphiredev/utilities/commit/ba8183287dbbc3f3d7d79af6d5a2d3dd8d62f63e))

60
node_modules/@sapphire/async-queue/README.md generated vendored Normal file
View file

@ -0,0 +1,60 @@
<div align="center">
![Sapphire Logo](https://raw.githubusercontent.com/sapphiredev/assets/main/banners/SapphireCommunity.png)
# @sapphire/async-queue
**Sequential asynchronous lock-based queue for promises.**
[![GitHub](https://img.shields.io/github/license/sapphiredev/utilities)](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
[![codecov](https://codecov.io/gh/sapphiredev/utilities/branch/main/graph/badge.svg?token=OEGIV6RFDO)](https://codecov.io/gh/sapphiredev/utilities)
[![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/async-queue?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/async-queue)
[![npm](https://img.shields.io/npm/v/@sapphire/async-queue?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/async-queue)
</div>
## Description
Ever needed a queue for a set of promises? This is the package for you.
## Features
- Written in TypeScript
- Bundled with esbuild so it can be used in NodeJS and browsers
- Offers CommonJS, ESM and UMD bundles
- Fully tested
## Installation
You can use the following command to install this package, or replace `npm install` with your package manager of choice.
```sh
npm install @sapphire/async-queue
```
---
## Buy us some doughnuts
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
| Donate With | Address |
| :-------------: | :-------------------------------------------------: |
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
| Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
| Patreon | [Click Here](https://sapphirejs.dev/patreon) |
| PayPal | [Click Here](https://sapphirejs.dev/paypal) |
## Contributors
Please make sure to read the [Contributing Guide][contributing] before making a pull request.
Thank you to all the people who already contributed to Sapphire!
<a href="https://github.com/sapphiredev/utilities/graphs/contributors">
<img src="https://contrib.rocks/image?repo=sapphiredev/utilities" />
</a>
[contributing]: https://github.com/sapphiredev/.github/blob/main/.github/CONTRIBUTING.md

145
node_modules/@sapphire/async-queue/dist/cjs/index.cjs generated vendored Normal file
View file

@ -0,0 +1,145 @@
'use strict';
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
// src/lib/AsyncQueueEntry.ts
var _AsyncQueueEntry = class _AsyncQueueEntry {
constructor(queue) {
__publicField(this, "promise");
__publicField(this, "resolve");
__publicField(this, "reject");
__publicField(this, "queue");
__publicField(this, "signal", null);
__publicField(this, "signalListener", null);
this.queue = queue;
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
setSignal(signal) {
if (signal.aborted)
return this;
this.signal = signal;
this.signalListener = () => {
const index = this.queue["promises"].indexOf(this);
if (index !== -1)
this.queue["promises"].splice(index, 1);
this.reject(new Error("Request aborted manually"));
};
this.signal.addEventListener("abort", this.signalListener);
return this;
}
use() {
this.dispose();
this.resolve();
return this;
}
abort() {
this.dispose();
this.reject(new Error("Request aborted manually"));
return this;
}
dispose() {
if (this.signal) {
this.signal.removeEventListener("abort", this.signalListener);
this.signal = null;
this.signalListener = null;
}
}
};
__name(_AsyncQueueEntry, "AsyncQueueEntry");
var AsyncQueueEntry = _AsyncQueueEntry;
// src/lib/AsyncQueue.ts
var _AsyncQueue = class _AsyncQueue {
constructor() {
/**
* The promises array
*/
__publicField(this, "promises", []);
}
/**
* The amount of entries in the queue, including the head.
* @seealso {@link queued} for the queued count.
*/
get remaining() {
return this.promises.length;
}
/**
* The amount of queued entries.
* @seealso {@link remaining} for the count with the head.
*/
get queued() {
return this.remaining === 0 ? 0 : this.remaining - 1;
}
/**
* Waits for last promise and queues a new one
* @example
* ```typescript
* const queue = new AsyncQueue();
* async function request(url, options) {
* await queue.wait({ signal: options.signal });
* try {
* const result = await fetch(url, options);
* // Do some operations with 'result'
* } finally {
* // Remove first entry from the queue and resolve for the next entry
* queue.shift();
* }
* }
*
* request(someUrl1, someOptions1); // Will call fetch() immediately
* request(someUrl2, someOptions2); // Will call fetch() after the first finished
* request(someUrl3, someOptions3); // Will call fetch() after the second finished
* ```
*/
wait(options) {
const entry = new AsyncQueueEntry(this);
if (this.promises.length === 0) {
this.promises.push(entry);
return Promise.resolve();
}
this.promises.push(entry);
if (options?.signal)
entry.setSignal(options.signal);
return entry.promise;
}
/**
* Unlocks the head lock and transfers the next lock (if any) to the head.
*/
shift() {
if (this.promises.length === 0)
return;
if (this.promises.length === 1) {
this.promises.shift();
return;
}
this.promises.shift();
this.promises[0].use();
}
/**
* Aborts all the pending promises.
* @note To avoid race conditions, this does **not** unlock the head lock.
*/
abortAll() {
if (this.queued === 0)
return;
for (let i = 1; i < this.promises.length; ++i) {
this.promises[i].abort();
}
this.promises.length = 1;
}
};
__name(_AsyncQueue, "AsyncQueue");
var AsyncQueue = _AsyncQueue;
exports.AsyncQueue = AsyncQueue;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.cjs.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,55 @@
/**
* The AsyncQueue class used to sequentialize burst requests
*/
declare class AsyncQueue {
/**
* The amount of entries in the queue, including the head.
* @seealso {@link queued} for the queued count.
*/
get remaining(): number;
/**
* The amount of queued entries.
* @seealso {@link remaining} for the count with the head.
*/
get queued(): number;
/**
* The promises array
*/
private promises;
/**
* Waits for last promise and queues a new one
* @example
* ```typescript
* const queue = new AsyncQueue();
* async function request(url, options) {
* await queue.wait({ signal: options.signal });
* try {
* const result = await fetch(url, options);
* // Do some operations with 'result'
* } finally {
* // Remove first entry from the queue and resolve for the next entry
* queue.shift();
* }
* }
*
* request(someUrl1, someOptions1); // Will call fetch() immediately
* request(someUrl2, someOptions2); // Will call fetch() after the first finished
* request(someUrl3, someOptions3); // Will call fetch() after the second finished
* ```
*/
wait(options?: Readonly<AsyncQueueWaitOptions>): Promise<void>;
/**
* Unlocks the head lock and transfers the next lock (if any) to the head.
*/
shift(): void;
/**
* Aborts all the pending promises.
* @note To avoid race conditions, this does **not** unlock the head lock.
*/
abortAll(): void;
}
interface AsyncQueueWaitOptions {
signal?: AbortSignal | undefined | null;
}
export { AsyncQueue, type AsyncQueueWaitOptions };

Some files were not shown because too many files have changed in this diff Show more