mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-23 12:00:09 +00:00
Compare commits
884 Commits
@discordjs
...
@discordjs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c69f512450 | ||
|
|
4a07f9eaa1 | ||
|
|
64cd53c4c2 | ||
|
|
d79aa2d0d0 | ||
|
|
822b7f234a | ||
|
|
8ca407e089 | ||
|
|
0126d9b810 | ||
|
|
e9931229ae | ||
|
|
1486bc9336 | ||
|
|
16fcdc3687 | ||
|
|
8622939229 | ||
|
|
2487e3bf76 | ||
|
|
578bc951bd | ||
|
|
1244854e13 | ||
|
|
b1e190c4f0 | ||
|
|
fc8ed816e6 | ||
|
|
abb7226af3 | ||
|
|
30ceaf7e47 | ||
|
|
9b40a79b3e | ||
|
|
0b12d6fa10 | ||
|
|
b106956308 | ||
|
|
6f1f465a77 | ||
|
|
eb98372dcd | ||
|
|
5048a3d17a | ||
|
|
f0497343f1 | ||
|
|
f6f15d8e87 | ||
|
|
14bbc9150a | ||
|
|
a7f816eeb7 | ||
|
|
802b2394b0 | ||
|
|
c446a84570 | ||
|
|
9cf0a4904b | ||
|
|
25dc146247 | ||
|
|
a2b08aaf3b | ||
|
|
eba9cc6038 | ||
|
|
145eb2fc5d | ||
|
|
8444576f45 | ||
|
|
6d43e26676 | ||
|
|
2fc3d86f56 | ||
|
|
8a8d519c9c | ||
|
|
669c3cd256 | ||
|
|
678ceaa014 | ||
|
|
0785353efe | ||
|
|
8323926304 | ||
|
|
bccc2c8e89 | ||
|
|
1d72663e92 | ||
|
|
d0a2a6227d | ||
|
|
735e0bf52e | ||
|
|
1c5b78fd21 | ||
|
|
053da5bc91 | ||
|
|
fc9653f5ae | ||
|
|
22ac6b4660 | ||
|
|
d14d47b62f | ||
|
|
a9f003ac9b | ||
|
|
1d4cdee321 | ||
|
|
8e1afaebdb | ||
|
|
32523325c6 | ||
|
|
7a9e52e63a | ||
|
|
d11edc6397 | ||
|
|
96304d7cc8 | ||
|
|
f9e9bfdedc | ||
|
|
ce1f5c8d47 | ||
|
|
03fb5b0a2f | ||
|
|
ce991dd1d8 | ||
|
|
dbca93098c | ||
|
|
dd5a08944c | ||
|
|
8e98ba94d2 | ||
|
|
74dc8c10d5 | ||
|
|
8d07ea9a62 | ||
|
|
d8e774138d | ||
|
|
55c3ee20ae | ||
|
|
c3341570d9 | ||
|
|
f3ce4a75d0 | ||
|
|
4ffdada4f7 | ||
|
|
8b3d006118 | ||
|
|
d08a57cadd | ||
|
|
0dc68445a1 | ||
|
|
a7ad7e75ce | ||
|
|
f79ccb4971 | ||
|
|
6f2b223c8b | ||
|
|
a4777aa9b0 | ||
|
|
f072d3d916 | ||
|
|
0238588067 | ||
|
|
1d460e0434 | ||
|
|
b9c62ac0f0 | ||
|
|
df46ab8061 | ||
|
|
b7eb96d456 | ||
|
|
f77612a55e | ||
|
|
9b4116b659 | ||
|
|
8a91d7c256 | ||
|
|
3b7ba4062e | ||
|
|
edadb9fe5d | ||
|
|
4bdb0593ae | ||
|
|
fd97da9b6c | ||
|
|
d5dcddd350 | ||
|
|
40324574eb | ||
|
|
1398af66f0 | ||
|
|
682e0e1802 | ||
|
|
13baf75cae | ||
|
|
1d6b31b78d | ||
|
|
5f093dde24 | ||
|
|
b58e6a65ad | ||
|
|
204f4dd7c4 | ||
|
|
249ba0a9a6 | ||
|
|
92933c2b61 | ||
|
|
abd3fc8ceb | ||
|
|
84059b6b25 | ||
|
|
6da405668f | ||
|
|
58d2a1e6d7 | ||
|
|
7b5c688844 | ||
|
|
28bc4f42c6 | ||
|
|
5b4672bad3 | ||
|
|
a57b9ba5c4 | ||
|
|
32da9b3868 | ||
|
|
70806b401e | ||
|
|
0674820723 | ||
|
|
2d5bce274c | ||
|
|
331dedcb9d | ||
|
|
103e1bd843 | ||
|
|
ffafde0b6b | ||
|
|
28422eea58 | ||
|
|
c826ad3ade | ||
|
|
17559becef | ||
|
|
b31a23b37c | ||
|
|
8e4f77a63b | ||
|
|
b16ab8c69f | ||
|
|
cf8570c19c | ||
|
|
f0ab393411 | ||
|
|
11e02f1e5d | ||
|
|
206523587a | ||
|
|
ac3bc6a2db | ||
|
|
af295acedc | ||
|
|
caa5c0332f | ||
|
|
434f696397 | ||
|
|
6062d361fb | ||
|
|
2ecb862e76 | ||
|
|
360936140b | ||
|
|
0b56184ba7 | ||
|
|
a55545850a | ||
|
|
f16b11a91d | ||
|
|
0fb2694871 | ||
|
|
ee030003ec | ||
|
|
29c51be1f4 | ||
|
|
43a78be70b | ||
|
|
92c0c60519 | ||
|
|
ba3e0ed348 | ||
|
|
f7ce9f8533 | ||
|
|
00990c93ae | ||
|
|
c076b0d8cb | ||
|
|
d297fb0b69 | ||
|
|
24c128d649 | ||
|
|
ec7c6e3d3e | ||
|
|
6dfb9bbc48 | ||
|
|
4644e45e85 | ||
|
|
1e001601c8 | ||
|
|
1aec243b1d | ||
|
|
191951ac28 | ||
|
|
4fb4492b17 | ||
|
|
abb968de81 | ||
|
|
d9e53093f5 | ||
|
|
e5678f4656 | ||
|
|
9f18036078 | ||
|
|
474eae0afc | ||
|
|
caeb66e150 | ||
|
|
7623fc552e | ||
|
|
230c43e97d | ||
|
|
4e3fa586b5 | ||
|
|
6bb1474d20 | ||
|
|
27bbc8fe68 | ||
|
|
e2cde5daa0 | ||
|
|
0960457108 | ||
|
|
cd6b365b17 | ||
|
|
19e1f5d0ca | ||
|
|
3621e5efbd | ||
|
|
d2f5b5b539 | ||
|
|
9ed11a4c19 | ||
|
|
e42fd16369 | ||
|
|
dd44e8b6ec | ||
|
|
3bef9018c0 | ||
|
|
23a0b6ccf2 | ||
|
|
b3f7c32f7f | ||
|
|
0dba8adbd2 | ||
|
|
2b8074dd12 | ||
|
|
16bbc8aa20 | ||
|
|
7a3d18dd6d | ||
|
|
4882b17a77 | ||
|
|
8028813825 | ||
|
|
47f2990b89 | ||
|
|
e475b63f25 | ||
|
|
673262d38c | ||
|
|
7f415a2502 | ||
|
|
cda3f005b1 | ||
|
|
f9c25ddcfe | ||
|
|
74740260a7 | ||
|
|
1008e3d4a7 | ||
|
|
17ab0e652c | ||
|
|
872ce801a0 | ||
|
|
0bf3df30da | ||
|
|
20680efbc9 | ||
|
|
7701331b1c | ||
|
|
0be85fd101 | ||
|
|
e147c5bd64 | ||
|
|
2f1ec7401c | ||
|
|
0f83402985 | ||
|
|
d97cd936fd | ||
|
|
812f7f1ea8 | ||
|
|
7d2507279c | ||
|
|
c31a5cfcc8 | ||
|
|
acdafe60c7 | ||
|
|
4fd42528fe | ||
|
|
ebaf158006 | ||
|
|
7116647947 | ||
|
|
c99b808882 | ||
|
|
a1dddd6b2c | ||
|
|
b3db9eef32 | ||
|
|
501945215b | ||
|
|
e82b2e49f5 | ||
|
|
5f42b5af30 | ||
|
|
35e79b389d | ||
|
|
5dc7946df2 | ||
|
|
1e00f5789e | ||
|
|
85cb0f25c7 | ||
|
|
3cc893a282 | ||
|
|
fc99bf431a | ||
|
|
4ab1d09997 | ||
|
|
d09ef1e425 | ||
|
|
d56590a11d | ||
|
|
c052f56f3e | ||
|
|
cb856860b7 | ||
|
|
4cf265c7c6 | ||
|
|
3ec7ef07a0 | ||
|
|
90e7aea443 | ||
|
|
1211c7fc10 | ||
|
|
84a4b1f58a | ||
|
|
193b252672 | ||
|
|
bc06cc638d | ||
|
|
d08da8a212 | ||
|
|
5360099e5f | ||
|
|
fd4844ddb9 | ||
|
|
8e69efde04 | ||
|
|
2447165c82 | ||
|
|
c97977a3e8 | ||
|
|
7666a6c341 | ||
|
|
9d8966fe24 | ||
|
|
4d128acac5 | ||
|
|
831d6506cb | ||
|
|
c5b96a185c | ||
|
|
afa27b15c5 | ||
|
|
4d7283933d | ||
|
|
452e94fd3e | ||
|
|
6c6fe74dd8 | ||
|
|
0e2a09571c | ||
|
|
0fab869e51 | ||
|
|
64a4041a05 | ||
|
|
38275fc53d | ||
|
|
aac8acc22b | ||
|
|
6ef4754d40 | ||
|
|
b8a31360a2 | ||
|
|
5b053cf82e | ||
|
|
e72b986939 | ||
|
|
3a96ce7970 | ||
|
|
359f688555 | ||
|
|
3161e1a1ac | ||
|
|
4d8361c711 | ||
|
|
d6e4d149fd | ||
|
|
480c85c9c3 | ||
|
|
b45b99f92b | ||
|
|
5137bfc17d | ||
|
|
fca3dada2a | ||
|
|
d070de6da7 | ||
|
|
a3183cfad4 | ||
|
|
aba307341d | ||
|
|
c479d39a6b | ||
|
|
52c2818b25 | ||
|
|
d03cf6176c | ||
|
|
11e77f7f86 | ||
|
|
2b1e88b5fa | ||
|
|
e5bfe2c7c2 | ||
|
|
a7deb8f898 | ||
|
|
b4e2c0c4d5 | ||
|
|
33113614e0 | ||
|
|
26556390a3 | ||
|
|
5494791313 | ||
|
|
c258bdf083 | ||
|
|
ff5dd1fcb4 | ||
|
|
a38c58dbd0 | ||
|
|
ec43c184fe | ||
|
|
c25e8ad78b | ||
|
|
3f17ff23bf | ||
|
|
a7dc588d9f | ||
|
|
2291429d30 | ||
|
|
bf7326729d | ||
|
|
124d8123b8 | ||
|
|
0b61dbf720 | ||
|
|
ba6797e742 | ||
|
|
7fd9ed8f13 | ||
|
|
b6bba9901b | ||
|
|
2130aae321 | ||
|
|
80b9738957 | ||
|
|
5d8bd030d6 | ||
|
|
e9920a9c98 | ||
|
|
6d248051cf | ||
|
|
798466a696 | ||
|
|
1275918ca8 | ||
|
|
a7d49e56fc | ||
|
|
34ba9d1c4c | ||
|
|
77ed407f6a | ||
|
|
4fc2c60a3b | ||
|
|
9f4446b10f | ||
|
|
78d4295a40 | ||
|
|
5a3c9996e0 | ||
|
|
4fff6076e7 | ||
|
|
4bda24678a | ||
|
|
9ae461d84d | ||
|
|
160487d866 | ||
|
|
41e4e10b48 | ||
|
|
200ab91f52 | ||
|
|
3839958e3f | ||
|
|
58c1b51c5c | ||
|
|
6a2d0d8e96 | ||
|
|
335695c698 | ||
|
|
8e520f946a | ||
|
|
59a7e52224 | ||
|
|
af837debe3 | ||
|
|
df42fdfc42 | ||
|
|
5f667c0c82 | ||
|
|
90cbd2bbd5 | ||
|
|
f50382e1ce | ||
|
|
1b03631205 | ||
|
|
a490adfe36 | ||
|
|
f097f0bc1f | ||
|
|
1d63d3ce1c | ||
|
|
6d25fb8856 | ||
|
|
86a9be7d33 | ||
|
|
82165d4f80 | ||
|
|
ee455c812e | ||
|
|
0d687b5606 | ||
|
|
748d7271c4 | ||
|
|
830c670c61 | ||
|
|
74ec7be346 | ||
|
|
96b62b6539 | ||
|
|
8a6ee906a7 | ||
|
|
1fb7b30963 | ||
|
|
45c9659080 | ||
|
|
07a5cd7048 | ||
|
|
d0e3c972b4 | ||
|
|
a05386a46c | ||
|
|
3b0197bd8e | ||
|
|
d1245418f9 | ||
|
|
e7d4d41640 | ||
|
|
ce1807dc80 | ||
|
|
34d3917a28 | ||
|
|
9e624abf1a | ||
|
|
8c4b9865e1 | ||
|
|
dbad1c468b | ||
|
|
4ffd7f9f80 | ||
|
|
660e212e83 | ||
|
|
70dd757ec3 | ||
|
|
b5d4b2d78b | ||
|
|
78d013f87c | ||
|
|
21d61ca260 | ||
|
|
b316ac7cc4 | ||
|
|
ed94b3d9ec | ||
|
|
dcbbecfed2 | ||
|
|
0c5e37d515 | ||
|
|
656e9550db | ||
|
|
3a7e93df57 | ||
|
|
66092cad8b | ||
|
|
ec230faa4d | ||
|
|
cd13a4a902 | ||
|
|
dda2895bfb | ||
|
|
f0b77348d3 | ||
|
|
b0a9131b1c | ||
|
|
29be5b570b | ||
|
|
d677c31161 | ||
|
|
f6ef92ad6a | ||
|
|
52a9e213c2 | ||
|
|
b7e62380f2 | ||
|
|
cafde77d73 | ||
|
|
b7d4e55419 | ||
|
|
5aeed99350 | ||
|
|
452dec57ca | ||
|
|
64f814066c | ||
|
|
33a7a5cbdc | ||
|
|
edf83f02ea | ||
|
|
25bd771559 | ||
|
|
f2ca0ca6f9 | ||
|
|
6712de9752 | ||
|
|
28cd293f14 | ||
|
|
3f5690afe1 | ||
|
|
015ab69956 | ||
|
|
caecc574f0 | ||
|
|
3bf30b1e6d | ||
|
|
103a3584c9 | ||
|
|
bf65b37d1a | ||
|
|
7e6dbaaed9 | ||
|
|
1a6ddbbe7b | ||
|
|
32f9056b15 | ||
|
|
3648f6d567 | ||
|
|
bddb6a461c | ||
|
|
fe34f48efb | ||
|
|
30a8d3231f | ||
|
|
1ed605eaa4 | ||
|
|
787654816d | ||
|
|
f0b68d5736 | ||
|
|
75256153a9 | ||
|
|
33ae7df000 | ||
|
|
feb3bdda0a | ||
|
|
e78c9c9ee9 | ||
|
|
43f62bb667 | ||
|
|
96c8d21f95 | ||
|
|
10ba0080cc | ||
|
|
0b979b04f2 | ||
|
|
a4d1862982 | ||
|
|
34531c45e3 | ||
|
|
8198da5cd0 | ||
|
|
ba10637529 | ||
|
|
68c3d8743e | ||
|
|
a51f7215ec | ||
|
|
c271e05223 | ||
|
|
d2e74003d5 | ||
|
|
fd1c24036f | ||
|
|
eb9ad46d4f | ||
|
|
5bd6b28b3e | ||
|
|
f6db285c07 | ||
|
|
68ade870f8 | ||
|
|
c7a205f7b9 | ||
|
|
c5750d59f5 | ||
|
|
31d5930464 | ||
|
|
cdd9214212 | ||
|
|
fa010b5162 | ||
|
|
6b20645740 | ||
|
|
50d55bd6b8 | ||
|
|
2d9dfa3c6e | ||
|
|
ab238a9046 | ||
|
|
94ee60d3d4 | ||
|
|
f10f4cdcd8 | ||
|
|
d95197cc78 | ||
|
|
e0c8282490 | ||
|
|
741b3c8e27 | ||
|
|
819a1fdf7d | ||
|
|
ce9afbb8e4 | ||
|
|
b2776c22d4 | ||
|
|
525bf031a5 | ||
|
|
27d8deb471 | ||
|
|
11b1739319 | ||
|
|
b83e0c0caf | ||
|
|
8421f9203b | ||
|
|
cb3dca4ae0 | ||
|
|
002d6a5aed | ||
|
|
c4653f97b1 | ||
|
|
e24970e3c3 | ||
|
|
65dc8d677e | ||
|
|
0ffbef506a | ||
|
|
5d3dd55a26 | ||
|
|
70b42bb64a | ||
|
|
af04992ed3 | ||
|
|
bbdb5d980b | ||
|
|
7279f9c31b | ||
|
|
5e5853a4e8 | ||
|
|
cd17aad720 | ||
|
|
ee36d60dc6 | ||
|
|
c34c02ab8d | ||
|
|
31f658247f | ||
|
|
a3799f9ebb | ||
|
|
a061233510 | ||
|
|
203bc4a2cf | ||
|
|
65d1879c0a | ||
|
|
c6f285b7b0 | ||
|
|
2eeaad6f27 | ||
|
|
f1ac17c961 | ||
|
|
db2b0333d9 | ||
|
|
94f7ca9474 | ||
|
|
e68effa822 | ||
|
|
358c3f4a46 | ||
|
|
268a9b4be5 | ||
|
|
95e6d6ede0 | ||
|
|
17867f9154 | ||
|
|
3a77ce0b18 | ||
|
|
23e183a9ac | ||
|
|
b3c3a94d5d | ||
|
|
8610700c87 | ||
|
|
db663a55c2 | ||
|
|
0673ea377a | ||
|
|
2681929e42 | ||
|
|
0a138dab95 | ||
|
|
415513696c | ||
|
|
90a98fee16 | ||
|
|
386c41f24f | ||
|
|
d54bf5d286 | ||
|
|
e5ec1c4dbc | ||
|
|
ad9ab2b177 | ||
|
|
4df491ce85 | ||
|
|
0a44b05db8 | ||
|
|
b4e28a8ff6 | ||
|
|
9c0f190de1 | ||
|
|
093117d938 | ||
|
|
e53d162198 | ||
|
|
51eadf3737 | ||
|
|
552ec72542 | ||
|
|
ac7bf692bf | ||
|
|
9964454c29 | ||
|
|
476b7d519c | ||
|
|
10a6c4287d | ||
|
|
a2eebf6c66 | ||
|
|
96053babe1 | ||
|
|
f527dea36e | ||
|
|
c7391db11b | ||
|
|
c5176be14b | ||
|
|
fbe67e1025 | ||
|
|
3bb9c0e5c3 | ||
|
|
9c8b3102ce | ||
|
|
2392a6f5de | ||
|
|
c0f079d232 | ||
|
|
d8077c6839 | ||
|
|
d4b41dd081 | ||
|
|
0415300243 | ||
|
|
caee94897f | ||
|
|
b3346f4b9b | ||
|
|
2791c86cdf | ||
|
|
c8f1690896 | ||
|
|
da9107c007 | ||
|
|
f57d6768ad | ||
|
|
d7b8357dcb | ||
|
|
16810f3e41 | ||
|
|
598f61b992 | ||
|
|
50401453e7 | ||
|
|
94bdcaca62 | ||
|
|
eea139b346 | ||
|
|
50822f5254 | ||
|
|
f2b267c079 | ||
|
|
b2eea1c900 | ||
|
|
3ae2633c3f | ||
|
|
3937b402c0 | ||
|
|
256c4f955c | ||
|
|
33cdcdbb7a | ||
|
|
bc466a5997 | ||
|
|
127931d1df | ||
|
|
5259639c2c | ||
|
|
5de9b80814 | ||
|
|
bc4fbcef2e | ||
|
|
3279b40912 | ||
|
|
1afae909d7 | ||
|
|
65cb36166f | ||
|
|
ecc6600df2 | ||
|
|
314d76e907 | ||
|
|
769ea0bfe7 | ||
|
|
8b979c0245 | ||
|
|
5475767c2c | ||
|
|
86d8fbc023 | ||
|
|
fba9710fc9 | ||
|
|
5ca3974301 | ||
|
|
3202c91c5a | ||
|
|
f3f34f07b3 | ||
|
|
f8ed71bfca | ||
|
|
e1176faa27 | ||
|
|
aa59a409b3 | ||
|
|
7fa698d23e | ||
|
|
b9df37a89f | ||
|
|
ad75be9a9c | ||
|
|
70c733bb9a | ||
|
|
a3287782b5 | ||
|
|
0ccc243c8f | ||
|
|
0a7953e463 | ||
|
|
6aa623240e | ||
|
|
6266b0c1e3 | ||
|
|
9720e55534 | ||
|
|
ad36c0be77 | ||
|
|
5987dbe5cf | ||
|
|
5244fe3c1c | ||
|
|
349766dd69 | ||
|
|
7a1095b66b | ||
|
|
10009a43ee | ||
|
|
8d8e6c03de | ||
|
|
dfadcbc2fd | ||
|
|
546d48655f | ||
|
|
f8739bd9c0 | ||
|
|
f2ae1f9348 | ||
|
|
3401fd4eb6 | ||
|
|
fdbd229832 | ||
|
|
9e8e2411c1 | ||
|
|
c02ced9a22 | ||
|
|
8c5a7f80ef | ||
|
|
14018b0118 | ||
|
|
8095723604 | ||
|
|
e17bb54c85 | ||
|
|
e92d937bcc | ||
|
|
091f1bd170 | ||
|
|
bd2cf20ecb | ||
|
|
8af916dba0 | ||
|
|
781a6e013c | ||
|
|
2172a00c50 | ||
|
|
271b1c8e5d | ||
|
|
6b8ef20cb3 | ||
|
|
a45bef4cad | ||
|
|
1ba2d2a898 | ||
|
|
e518c8a137 | ||
|
|
80cd4a4a43 | ||
|
|
8a7cd10554 | ||
|
|
251862ea57 | ||
|
|
2f03f9ad3f | ||
|
|
db81127886 | ||
|
|
cdd2ba036a | ||
|
|
97eaab35d7 | ||
|
|
d60c464e61 | ||
|
|
643dab3b1b | ||
|
|
68d5169f66 | ||
|
|
7f4d411e73 | ||
|
|
636d4f263b | ||
|
|
fdeac9d9fb | ||
|
|
adf461baf4 | ||
|
|
191510b7f8 | ||
|
|
e2f5a4a494 | ||
|
|
993eb74475 | ||
|
|
dfe449c253 | ||
|
|
5e9b757a37 | ||
|
|
28172ca7b5 | ||
|
|
7ce641d33a | ||
|
|
e92b17d855 | ||
|
|
d1504f2ae1 | ||
|
|
b1a3aa97ea | ||
|
|
d522320aa4 | ||
|
|
76694c1497 | ||
|
|
de3f1573f0 | ||
|
|
aed687b09f | ||
|
|
e07b910e68 | ||
|
|
d1ec8c37ff | ||
|
|
4515a1ea80 | ||
|
|
c1b5e731da | ||
|
|
64bdf53116 | ||
|
|
d308c66eec | ||
|
|
dfd9eb20b2 | ||
|
|
19eaed6390 | ||
|
|
4ba0f56b6a | ||
|
|
5eeef3f708 | ||
|
|
679dcda970 | ||
|
|
df64d3ea38 | ||
|
|
6239d83c4d | ||
|
|
0c18dab128 | ||
|
|
ece628986c | ||
|
|
f4ccc6772c | ||
|
|
5ba7740fcf | ||
|
|
bfeaf856f7 | ||
|
|
361709332b | ||
|
|
61a44c509c | ||
|
|
4ac91c61d0 | ||
|
|
4972bd87c1 | ||
|
|
a1b145e0ce | ||
|
|
29293d7bbb | ||
|
|
f22245e9d0 | ||
|
|
585169f2f0 | ||
|
|
ec8d87f932 | ||
|
|
440ac243ca | ||
|
|
c5fb548529 | ||
|
|
a6d9ce57c6 | ||
|
|
08574763eb | ||
|
|
9ef7ffdc6d | ||
|
|
9fa92ac0f9 | ||
|
|
2c2f88cd43 | ||
|
|
93defeccce | ||
|
|
443533ba99 | ||
|
|
3cc96d7940 | ||
|
|
b94a8761f8 | ||
|
|
9bf2a0d5cb | ||
|
|
9917981f24 | ||
|
|
ab8b946276 | ||
|
|
bcf7f1cfad | ||
|
|
a58556adc0 | ||
|
|
40b9a1d67d | ||
|
|
ab4c608b97 | ||
|
|
1b2d8decb6 | ||
|
|
a674f64e1d | ||
|
|
54e5629986 | ||
|
|
75b6770933 | ||
|
|
c2866504a3 | ||
|
|
f1d0084da2 | ||
|
|
b01f4147d4 | ||
|
|
fc2a8bb675 | ||
|
|
f094e33861 | ||
|
|
446eb390ce | ||
|
|
96a0d83a13 | ||
|
|
01a423d110 | ||
|
|
f0d0242c76 | ||
|
|
b577bcc1df | ||
|
|
0faac04b69 | ||
|
|
9ff54254d8 | ||
|
|
fd1dc72c0a | ||
|
|
29f8807955 | ||
|
|
6f4e97bfaf | ||
|
|
3582fe917d | ||
|
|
78a3afcd7f | ||
|
|
3db20abdd2 | ||
|
|
ebb4dfa262 | ||
|
|
8eaec114a9 | ||
|
|
8625d81714 | ||
|
|
3037fca196 | ||
|
|
e4f27051ca | ||
|
|
25fdb3894d | ||
|
|
a1329bd3eb | ||
|
|
3c0bbac82f | ||
|
|
3f3e4327c8 | ||
|
|
6fec25239d | ||
|
|
aedddb875e | ||
|
|
402514ff32 | ||
|
|
3b3dabf3da | ||
|
|
eb6b472f72 | ||
|
|
f88e1ac4be | ||
|
|
905a6a1166 | ||
|
|
5748dbe087 | ||
|
|
ac4bc3a6c8 | ||
|
|
520f471ac5 | ||
|
|
6708533376 | ||
|
|
9afc03054e | ||
|
|
74bf7d57ab | ||
|
|
8e3b2d7abd | ||
|
|
8880de0cec | ||
|
|
cedd0536ba | ||
|
|
85e531f22d | ||
|
|
07b23a99c7 | ||
|
|
0c32332a5a | ||
|
|
d5369a56e3 | ||
|
|
9a6e691eaa | ||
|
|
4d2b55955d | ||
|
|
cd79bef254 | ||
|
|
c684ac55e1 | ||
|
|
fb9a9c2211 | ||
|
|
daf2829cb5 | ||
|
|
98177aa38d | ||
|
|
b1d63d919a | ||
|
|
b520c3df3c | ||
|
|
e805777a7a | ||
|
|
72577c4bfd | ||
|
|
9b0d8cb2d8 | ||
|
|
8fb98165a9 | ||
|
|
f4729759f6 | ||
|
|
2297c2b947 | ||
|
|
87a6b8445b | ||
|
|
549716e4fc | ||
|
|
230c0c4cb1 | ||
|
|
dcd479767b | ||
|
|
3dff31f63f | ||
|
|
cbdb408dff | ||
|
|
e787cd5fa5 | ||
|
|
b162f27e46 | ||
|
|
b9ff7b0573 | ||
|
|
c12d61a342 | ||
|
|
e71c76c7f7 | ||
|
|
851f380eb1 | ||
|
|
10607dbdaf | ||
|
|
79d6c0489c | ||
|
|
89073903a2 | ||
|
|
8f1986a6aa | ||
|
|
0d7e4edd96 | ||
|
|
fac55bcfd1 | ||
|
|
4b08d9b376 | ||
|
|
93854a8013 | ||
|
|
cb566c8b6a | ||
|
|
6f7a366956 | ||
|
|
ed92015634 | ||
|
|
53defb82e3 | ||
|
|
8478d2f4de | ||
|
|
2d4971b032 | ||
|
|
c6cb5e9ebb | ||
|
|
a8321d8026 | ||
|
|
1a14c0ca56 | ||
|
|
44a57a1b0c | ||
|
|
0aa48516a4 | ||
|
|
83460037be | ||
|
|
8203c5d843 | ||
|
|
51583320d3 | ||
|
|
cf669301c7 | ||
|
|
d1d1b076be | ||
|
|
00728f72b3 | ||
|
|
4f306521d8 | ||
|
|
6a2fa70b8e | ||
|
|
46b53f4365 | ||
|
|
78aa36f9f5 | ||
|
|
3baa340821 | ||
|
|
ba31203a0a | ||
|
|
8dbd34544c | ||
|
|
942ea1acbf | ||
|
|
b3fa2ece40 | ||
|
|
ffecf08495 | ||
|
|
3e105a0bbb | ||
|
|
b12214922c | ||
|
|
71f4fa82ed | ||
|
|
f7257f0765 | ||
|
|
395a68ff49 | ||
|
|
dee27db35a | ||
|
|
d32db8833e | ||
|
|
5cf5071061 | ||
|
|
2d4554440e | ||
|
|
7959a68d8e | ||
|
|
d2bc9d444f | ||
|
|
868e2f3230 | ||
|
|
c1b27f8eed | ||
|
|
9311fa7b42 | ||
|
|
6d3da226d3 | ||
|
|
a8106f7c58 | ||
|
|
32985109c3 | ||
|
|
2d2de1d3fd | ||
|
|
d1bb36256f | ||
|
|
36173590a7 | ||
|
|
003439671d | ||
|
|
0dfdb2cf11 | ||
|
|
ae0f35f51d | ||
|
|
0af9bc841f | ||
|
|
e8252ed3b9 | ||
|
|
3ae6f3c313 | ||
|
|
6ce906a02f | ||
|
|
532846b1f8 | ||
|
|
94bf727cc3 | ||
|
|
f4953647ff | ||
|
|
861f0e2134 | ||
|
|
81d8b54ff6 | ||
|
|
fa97a31504 | ||
|
|
55b388a763 | ||
|
|
fbc71ef6b6 | ||
|
|
b97aedd8e1 | ||
|
|
298b22604b | ||
|
|
fe11ff5f6e | ||
|
|
dd751ae19d | ||
|
|
f59d6305cb | ||
|
|
09098240bf | ||
|
|
cc25455d2c | ||
|
|
3d8c77600b | ||
|
|
83458ff7c7 | ||
|
|
b936103395 | ||
|
|
a921ec7dc5 | ||
|
|
aadfbda586 | ||
|
|
538e9cef45 | ||
|
|
f2a7a9f1b3 | ||
|
|
2800e07e59 | ||
|
|
d8184f94dd | ||
|
|
cd2f566052 | ||
|
|
8bb3751340 | ||
|
|
733ac82d5d | ||
|
|
a7b80b9d9b | ||
|
|
5f4b44d580 | ||
|
|
c15100574b | ||
|
|
1c186fabeb | ||
|
|
6faeddcd0d | ||
|
|
87ca2854c2 | ||
|
|
741452b9be | ||
|
|
37c1cb4495 | ||
|
|
cd5c7fa20e | ||
|
|
6b6222bf51 | ||
|
|
04502ce702 | ||
|
|
51beda56f7 | ||
|
|
92a04f4d98 | ||
|
|
0b866c9fb2 | ||
|
|
4abb28c0a1 | ||
|
|
34120bba97 | ||
|
|
088394367b | ||
|
|
0803665183 | ||
|
|
875c86a4ef | ||
|
|
e6a26d25b3 | ||
|
|
388f53550c | ||
|
|
567db60475 | ||
|
|
fbb1d0328b | ||
|
|
74f627c379 | ||
|
|
3a5ab2c4e5 | ||
|
|
00ce1c56ac | ||
|
|
72767a1059 | ||
|
|
1a6c5ab145 | ||
|
|
355f579771 | ||
|
|
e4bd07b239 | ||
|
|
e1ecc1a80a | ||
|
|
11e5e5ac5b | ||
|
|
ec0fba1ed0 | ||
|
|
ac26d9b130 | ||
|
|
2db0cdd357 | ||
|
|
9a566e8068 | ||
|
|
d6b56d0080 | ||
|
|
b6402723c3 | ||
|
|
706db9228a | ||
|
|
47633f0fd2 | ||
|
|
67250382f9 | ||
|
|
5ccdb0ab26 | ||
|
|
9a1623425a | ||
|
|
c05b38873b | ||
|
|
31768fcd69 | ||
|
|
bcc5cda8a9 | ||
|
|
d2d3a80c55 | ||
|
|
2f16f879aa |
@@ -5,6 +5,7 @@
|
||||
2,
|
||||
"always",
|
||||
["chore", "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "types", "typings"]
|
||||
]
|
||||
],
|
||||
"scope-case": [0]
|
||||
}
|
||||
}
|
||||
|
||||
38
.dockerignore
Normal file
38
.dockerignore
Normal file
@@ -0,0 +1,38 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist/
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
!.vscode/settings.json
|
||||
.idea/
|
||||
.DS_Store
|
||||
.turbo
|
||||
tsconfig.tsbuildinfo
|
||||
|
||||
# yarn
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/cache
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
14
.eslintrc.json
Normal file
14
.eslintrc.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.eslint.json"
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/consistent-type-definitions": ["error", "interface"]
|
||||
},
|
||||
"ignorePatterns": ["**/dist/*"],
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
11
.github/.kodiak.toml
vendored
Normal file
11
.github/.kodiak.toml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
version = 1
|
||||
|
||||
[merge]
|
||||
require_automerge_label = false
|
||||
blocking_labels = ['blocked']
|
||||
method = 'squash'
|
||||
|
||||
[merge.message]
|
||||
title = 'pull_request_title'
|
||||
strip_html_comments = true
|
||||
include_coauthors = true
|
||||
8
.github/COMMIT_CONVENTION.md
vendored
8
.github/COMMIT_CONVENTION.md
vendored
@@ -15,13 +15,13 @@ Messages must be matched by the following regex:
|
||||
Appears under "Features" header, `GuildMember` subheader:
|
||||
|
||||
```
|
||||
feat(guildmember): add 'tag' method
|
||||
feat(GuildMember): add 'tag' method
|
||||
```
|
||||
|
||||
Appears under "Bug Fixes" header, `Guild` subheader, with a link to issue #28:
|
||||
|
||||
```
|
||||
fix(guild): handle events correctly
|
||||
fix(Guild): handle events correctly
|
||||
|
||||
close #28
|
||||
```
|
||||
@@ -37,7 +37,7 @@ BREAKING CHANGE: The 'bar' option has been removed.
|
||||
The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.
|
||||
|
||||
```
|
||||
revert: feat(managers): add Managers
|
||||
revert: feat(Managers): add Managers
|
||||
|
||||
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
|
||||
```
|
||||
@@ -68,7 +68,7 @@ Other prefixes are up to your discretion. Suggested prefixes are `docs`, `chore`
|
||||
|
||||
### Scope
|
||||
|
||||
The scope could be anything specifying the place of the commit change. For example `GuildMember`, `Guild`, `Message`, `MessageEmbed` etc...
|
||||
The scope could be anything specifying the place of the commit change. For example `GuildMember`, `Guild`, `Message`, `TextChannel` etc...
|
||||
|
||||
### Subject
|
||||
|
||||
|
||||
9
.github/CONTRIBUTING.md
vendored
9
.github/CONTRIBUTING.md
vendored
@@ -11,7 +11,8 @@ is a great boon to your development process.
|
||||
To get ready to work on the codebase, please do the following:
|
||||
|
||||
1. Fork & clone the repository, and make sure you're on the **main** branch
|
||||
2. Run `npm ci`
|
||||
3. Code your heart out!
|
||||
4. Run `npm test` to run ESLint and ensure any JSDoc changes are valid
|
||||
5. [Submit a pull request](https://github.com/discordjs/discord.js/compare) (Make sure you follow the [conventional commit format](https://github.com/discordjs/discord.js/blob/main/.github/COMMIT_CONVENTION.md))
|
||||
2. Run `yarn --immutable` ([install](https://yarnpkg.com/getting-started/install))
|
||||
3. Run `yarn build` to build local packages
|
||||
4. Code your heart out!
|
||||
5. Run `yarn test` to run ESLint and ensure any JSDoc changes are valid
|
||||
6. [Submit a pull request](https://github.com/discordjs/discord.js/compare) (Make sure you follow the [conventional commit format](https://github.com/discordjs/discord.js/blob/main/.github/COMMIT_CONVENTION.md))
|
||||
|
||||
51
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
51
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -15,7 +15,10 @@ body:
|
||||
- builders
|
||||
- collection
|
||||
- rest
|
||||
- proxy
|
||||
- proxy-container
|
||||
- voice
|
||||
- ws
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -49,7 +52,7 @@ body:
|
||||
id: djs-version
|
||||
attributes:
|
||||
label: Package version
|
||||
description: Which version of are you using? Run `npm list <package>` in your project directory and paste the output.
|
||||
description: Which version of the package are you using? Run `npm list <package>` in your project directory and paste the output.
|
||||
placeholder: We no longer support version 12 or earlier of discord.js
|
||||
validations:
|
||||
required: true
|
||||
@@ -90,12 +93,13 @@ body:
|
||||
options:
|
||||
- Not applicable (subpackage bug)
|
||||
- No Partials
|
||||
- USER
|
||||
- CHANNEL
|
||||
- GUILD_MEMBER
|
||||
- MESSAGE
|
||||
- REACTION
|
||||
- GUILD_SCHEDULED_EVENT
|
||||
- User
|
||||
- Channel
|
||||
- GuildMember
|
||||
- Message
|
||||
- Reaction
|
||||
- GuildScheduledEvent
|
||||
- ThreadMember
|
||||
multiple: true
|
||||
validations:
|
||||
required: true
|
||||
@@ -110,22 +114,23 @@ body:
|
||||
options:
|
||||
- Not applicable (subpackage bug)
|
||||
- No Intents
|
||||
- GUILDS
|
||||
- GUILD_MEMBERS
|
||||
- GUILD_BANS
|
||||
- GUILD_EMOJIS_AND_STICKERS
|
||||
- GUILD_INTEGRATIONS
|
||||
- GUILD_WEBHOOKS
|
||||
- GUILD_INVITES
|
||||
- GUILD_VOICE_STATES
|
||||
- GUILD_PRESENCES
|
||||
- GUILD_MESSAGES
|
||||
- GUILD_MESSAGE_REACTIONS
|
||||
- GUILD_MESSAGE_TYPING
|
||||
- DIRECT_MESSAGES
|
||||
- DIRECT_MESSAGE_REACTIONS
|
||||
- DIRECT_MESSAGE_TYPING
|
||||
- GUILD_SCHEDULED_EVENTS
|
||||
- Guilds
|
||||
- GuildMembers
|
||||
- GuildBans
|
||||
- GuildEmojisAndStickers
|
||||
- GuildIntegrations
|
||||
- GuildWebhooks
|
||||
- GuildInvites
|
||||
- GuildVoiceStates
|
||||
- GuildPresences
|
||||
- GuildMessages
|
||||
- GuildMessageReactions
|
||||
- GuildMessageTyping
|
||||
- DirectMessages
|
||||
- DirectMessageReactions
|
||||
- DirectMessageTyping
|
||||
- MessageContent
|
||||
- GuildScheduledEvents
|
||||
multiple: true
|
||||
validations:
|
||||
required: true
|
||||
|
||||
5
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
5
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@@ -5,7 +5,7 @@ body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
We can only implement features that Discord publishes, documents and merges into the Discord API documentation.
|
||||
We can only implement features that Discord publishes, documents, and merges into the Discord API documentation.
|
||||
We do not implement unreleased features.
|
||||
Use Discord for questions: https://discord.gg/djs
|
||||
- type: dropdown
|
||||
@@ -17,7 +17,10 @@ body:
|
||||
- builders
|
||||
- collection
|
||||
- rest
|
||||
- proxy
|
||||
- proxy-container
|
||||
- voice
|
||||
- ws
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
|
||||
1
.github/auto_assign.yml
vendored
1
.github/auto_assign.yml
vendored
@@ -5,3 +5,4 @@ reviewers:
|
||||
- kyranet
|
||||
- vladfrangu
|
||||
numberOfReviewers: 0
|
||||
runOnDraft: true
|
||||
|
||||
20
.github/labeler.yml
vendored
20
.github/labeler.yml
vendored
@@ -1,7 +1,3 @@
|
||||
chore:
|
||||
- any: ['*']
|
||||
all: ['!packages/*', '!packages/**/*']
|
||||
|
||||
'packages:builders':
|
||||
- packages/builders/*
|
||||
- packages/builders/**/*
|
||||
@@ -14,6 +10,18 @@ chore:
|
||||
- packages/discord.js/*
|
||||
- packages/discord.js/**/*
|
||||
|
||||
'packages:docgen':
|
||||
- packages/docgen/*
|
||||
- packages/docgen/**/*
|
||||
|
||||
'packages:proxy':
|
||||
- packages/proxy/*
|
||||
- packages/proxy/**/*
|
||||
|
||||
'packages:proxy-container':
|
||||
- packages/proxy-container/*
|
||||
- packages/proxy-container/**/*
|
||||
|
||||
'packages:rest':
|
||||
- packages/rest/*
|
||||
- packages/rest/**/*
|
||||
@@ -22,6 +30,10 @@ chore:
|
||||
- packages/voice/*
|
||||
- packages/voice/**/*
|
||||
|
||||
'packages:website':
|
||||
- packages/website/*
|
||||
- packages/website/**/*
|
||||
|
||||
'packages:ws':
|
||||
- packages/ws/*
|
||||
- packages/ws/**/*
|
||||
|
||||
10
.github/labels.yml
vendored
10
.github/labels.yml
vendored
@@ -4,6 +4,8 @@
|
||||
color: '5663e9'
|
||||
- name: 'backlog'
|
||||
color: '7ef7ef'
|
||||
- name: 'blocked'
|
||||
color: 'fc1423'
|
||||
- name: 'bug'
|
||||
color: 'd73a4a'
|
||||
- name: 'caching'
|
||||
@@ -50,10 +52,18 @@
|
||||
color: 'fbca04'
|
||||
- name: 'packages:discord.js'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:docgen'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:proxy'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:proxy-container'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:rest'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:voice'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:website'
|
||||
color: 'fbca04'
|
||||
- name: 'packages:ws'
|
||||
color: 'fbca04'
|
||||
- name: 'performance'
|
||||
|
||||
6
.github/powered-by-vercel.svg
vendored
Normal file
6
.github/powered-by-vercel.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.2 KiB |
119
.github/workflows/documentation.yml
vendored
119
.github/workflows/documentation.yml
vendored
@@ -3,51 +3,68 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'stable'
|
||||
- '!docs'
|
||||
tags:
|
||||
- '*'
|
||||
- '**'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
ref:
|
||||
description: 'The branch, tag or SHA to checkout'
|
||||
required: true
|
||||
ref_type:
|
||||
type: choice
|
||||
description: 'Branch or tag'
|
||||
options:
|
||||
- branch
|
||||
- tag
|
||||
required: true
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
build:
|
||||
name: Build documentation
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository_owner == 'discordjs'
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
outputs:
|
||||
BRANCH_NAME: ${{ steps.env.outputs.BRANCH_NAME }}
|
||||
BRANCH_OR_TAG: ${{ steps.env.outputs.BRANCH_OR_TAG }}
|
||||
SHA: ${{ steps.env.outputs.SHA }}
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.event.inputs.ref || '' }}
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Turbo cache
|
||||
id: turbo-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: .turbo
|
||||
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
turbo-${{ github.job }}-${{ github.ref_name }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Build docs
|
||||
run: yarn docs --cache-dir=".turbo"
|
||||
- name: Build dependencies
|
||||
run: yarn build
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
- name: Build docs
|
||||
run: yarn docs
|
||||
|
||||
- name: Upload docgen artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: docs
|
||||
name: docgen
|
||||
path: packages/*/docs/docs.json
|
||||
|
||||
- name: Upload api-extractor artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: api-extractor
|
||||
path: packages/*/docs/docs.api.json
|
||||
|
||||
- name: Set outputs for upload job
|
||||
id: env
|
||||
run: |
|
||||
@@ -62,32 +79,78 @@ jobs:
|
||||
max-parallel: 1
|
||||
fail-fast: false
|
||||
matrix:
|
||||
package: ['builders', 'collection', 'discord.js', 'rest', 'voice']
|
||||
package: ['builders', 'collection', 'discord.js', 'proxy', 'rest', 'voice', 'ws']
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
BRANCH_NAME: ${{ needs.build.outputs.BRANCH_NAME }}
|
||||
BRANCH_OR_TAG: ${{ needs.build.outputs.BRANCH_OR_TAG }}
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
BRANCH_NAME: ${{ github.event.inputs.ref || needs.build.outputs.BRANCH_NAME }}
|
||||
BRANCH_OR_TAG: ${{ github.event.inputs.ref_type || needs.build.outputs.BRANCH_OR_TAG }}
|
||||
SHA: ${{ needs.build.outputs.SHA }}
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
name: docs
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Build actions
|
||||
run: yarn workspace @discordjs/actions build
|
||||
|
||||
- name: Download docgen artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: docgen
|
||||
path: docs
|
||||
|
||||
- name: Download api-extractor artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: api-extractor
|
||||
path: docs
|
||||
|
||||
- name: Checkout docs repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: 'discordjs/docs'
|
||||
token: ${{ secrets.DJS_DOCS }}
|
||||
path: 'out'
|
||||
|
||||
- name: Extract package and semver from tag
|
||||
if: ${{ env.BRANCH_OR_TAG == 'tag' }}
|
||||
id: extract-tag
|
||||
uses: ./packages/actions/src/formatTag
|
||||
with:
|
||||
tag: ${{ env.BRANCH_NAME }}
|
||||
|
||||
- name: Move docs to correct directory
|
||||
if: ${{ env.BRANCH_OR_TAG == 'tag' && matrix.package == steps.extract-tag.outputs.package }}
|
||||
env:
|
||||
PACKAGE: ${{ steps.extract-tag.outputs.package }}
|
||||
SEMVER: ${{ steps.extract-tag.outputs.semver }}
|
||||
run: |
|
||||
mkdir -p out/${PACKAGE}
|
||||
mv docs/${PACKAGE}/docs/docs.json out/${PACKAGE}/${SEMVER}.json
|
||||
if [[ $PACKAGE != "discord.js" ]]; then
|
||||
mv docs/${PACKAGE}/docs/docs.api.json out/${PACKAGE}/${SEMVER}.api.json
|
||||
fi
|
||||
|
||||
- name: Move docs to correct directory
|
||||
if: ${{ env.BRANCH_OR_TAG == 'branch' }}
|
||||
env:
|
||||
PACKAGE: ${{ matrix.package }}
|
||||
run: |
|
||||
mkdir -p out/${PACKAGE}
|
||||
mv docs/${PACKAGE}/docs/docs.json out/${PACKAGE}/${BRANCH_NAME}.json
|
||||
if [[ $PACKAGE != "discord.js" ]]; then
|
||||
mv docs/${PACKAGE}/docs/docs.api.json out/${PACKAGE}/${BRANCH_NAME}.api.json
|
||||
fi
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Label Sync
|
||||
name: Label sync
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
@@ -9,14 +9,15 @@ on:
|
||||
paths:
|
||||
- '.github/labels.yml'
|
||||
jobs:
|
||||
labelsync:
|
||||
label-sync:
|
||||
name: Label sync
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Label sync
|
||||
uses: crazy-max/ghaction-github-labeler@v3
|
||||
uses: crazy-max/ghaction-github-labeler@v4
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,28 +1,27 @@
|
||||
name: npm auto deprecate
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 1 * * *'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
auto-deprecate:
|
||||
npm-auto-deprecate:
|
||||
name: npm auto deprecate
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Deprecate versions
|
||||
run: 'yarn npm-deprecate --name "*dev*" --package "discord.js"'
|
||||
run: 'yarn npm-deprecate --name "*dev*" --package @discordjs/builders @discordjs/collection discord.js @discordjs/proxy @discordjs/rest @discordjs/voice'
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
@@ -1,16 +1,17 @@
|
||||
name: 'PR Automation'
|
||||
name: 'PR Triage'
|
||||
on:
|
||||
pull_request_target:
|
||||
jobs:
|
||||
triage:
|
||||
pr-triage:
|
||||
name: PR Triage
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Automatically label PR
|
||||
uses: actions/labeler@v3
|
||||
uses: actions/labeler@v4
|
||||
with:
|
||||
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
||||
sync-labels: true
|
||||
|
||||
- name: Automatically assign reviewers
|
||||
if: ${{ github.event.action == 'opened' }}
|
||||
uses: kentaro-m/auto-assign-action@v1.1.2
|
||||
if: github.event.action == 'opened'
|
||||
uses: kentaro-m/auto-assign-action@v1.2.1
|
||||
25
.github/workflows/publish-dev-docker.yml
vendored
Normal file
25
.github/workflows/publish-dev-docker.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Publish dev docker images
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 */12 * * *'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
docker-publish:
|
||||
name: Docker publish
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
run: echo ${{ secrets.DOCKER_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
|
||||
|
||||
- name: Build the image
|
||||
run: docker build -t discordjs/proxy:latest -f packages/proxy-container/Dockerfile .
|
||||
|
||||
- name: Push image to DockerHub
|
||||
run: docker push discordjs/proxy:latest
|
||||
67
.github/workflows/publish-dev.yml
vendored
67
.github/workflows/publish-dev.yml
vendored
@@ -1,59 +1,54 @@
|
||||
name: Publish dev
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 */12 * * *'
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
npm:
|
||||
name: npm
|
||||
npm-publish:
|
||||
name: npm publish
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- package: '@discordjs/builders'
|
||||
folder: 'builders'
|
||||
- package: '@discordjs/collection'
|
||||
folder: 'collection'
|
||||
- package: 'discord.js'
|
||||
folder: 'discord.js'
|
||||
- package: '@discordjs/proxy'
|
||||
folder: 'proxy'
|
||||
- package: '@discordjs/rest'
|
||||
folder: 'rest'
|
||||
- package: '@discordjs/voice'
|
||||
folder: 'voice'
|
||||
- package: '@discordjs/ws'
|
||||
folder: 'ws'
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
registry-url: https://registry.npmjs.org/
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Turbo cache
|
||||
id: turbo-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: .turbo
|
||||
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
turbo-${{ github.job }}-${{ github.ref_name }}-
|
||||
|
||||
- name: Check previous released version
|
||||
id: pre-release
|
||||
run: |
|
||||
if [[ $(npm view discord.js@dev version | grep -e "$(jq --raw-output '.version' packages/discord.js/package.json).*.$(git rev-parse --short HEAD | cut -b1-3)") ]]; \
|
||||
then echo '::set-output name=release::false'; \
|
||||
else echo '::set-output name=release::true'; fi
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.pre-release.outputs.release == 'true'
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Build dependencies
|
||||
if: steps.pre-release.outputs.release == 'true'
|
||||
run: yarn build --cache-dir=".turbo"
|
||||
run: yarn build
|
||||
|
||||
- name: Deprecate old versions
|
||||
if: steps.pre-release.outputs.release == 'true'
|
||||
run: npm deprecate discord.js@"~$(jq --raw-output '.version' packages/discord.js/package.json)" "no longer supported" || true
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
|
||||
- name: Publish
|
||||
if: steps.pre-release.outputs.release == 'true'
|
||||
- name: Publish package
|
||||
run: |
|
||||
yarn workspace discord.js version --no-git-tag-version --new-version $(jq --raw-output '.version' packages/discord.js/package.json).$(date +%s).$(git rev-parse --short HEAD)
|
||||
yarn workspace discord.js publish --tag dev || true
|
||||
yarn workspace ${{ matrix.package }} release --preid "dev.$(date +%s)-$(git rev-parse --short HEAD)"
|
||||
yarn workspace ${{ matrix.package }} npm publish --tag dev || true
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
|
||||
25
.github/workflows/publish-docker.yml
vendored
Normal file
25
.github/workflows/publish-docker.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Publish docker images
|
||||
on:
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
docker-publish:
|
||||
name: Docker publish
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
run: echo ${{ secrets.DOCKER_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
|
||||
|
||||
- name: Build docker image
|
||||
run: docker build -t discordjs/proxy:latest -f packages/proxy-container/Dockerfile .
|
||||
|
||||
- name: Tag image with major
|
||||
run: docker tag discordjs/proxy discordjs/proxy:$(cut -d '.' -f1 <<< $(jq --raw-output '.version' packages/proxy-container/package.json))
|
||||
|
||||
- name: Push image to DockerHub
|
||||
run: docker push --all-tags discordjs/proxy
|
||||
37
.github/workflows/test.yml
vendored
37
.github/workflows/test.yml
vendored
@@ -1,37 +0,0 @@
|
||||
name: Tests
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Turbo cache
|
||||
id: turbo-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: .turbo
|
||||
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
turbo-${{ github.job }}-${{ github.ref_name }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: ESLint
|
||||
run: yarn lint --cache-dir=".turbo"
|
||||
|
||||
- name: Tests
|
||||
run: yarn test --cache-dir=".turbo"
|
||||
|
||||
- name: Build
|
||||
run: yarn build --cache-dir=".turbo"
|
||||
40
.github/workflows/tests.yml
vendored
Normal file
40
.github/workflows/tests.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: Tests
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
tests:
|
||||
name: Tests
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
NEXT_PUBLIC_LOCAL_DEV: true
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install --immutable
|
||||
|
||||
- name: Build dependencies
|
||||
run: yarn build
|
||||
|
||||
- name: ESLint
|
||||
run: yarn lint
|
||||
|
||||
- name: Tests
|
||||
run: yarn test
|
||||
|
||||
- name: Upload Coverage
|
||||
if: github.repository_owner == 'discordjs'
|
||||
uses: ./packages/actions/src/uploadCoverage
|
||||
14
.gitignore
vendored
14
.gitignore
vendored
@@ -26,3 +26,17 @@ dist/
|
||||
.DS_Store
|
||||
.turbo
|
||||
tsconfig.tsbuildinfo
|
||||
coverage/
|
||||
|
||||
# yarn
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
|
||||
# Cache
|
||||
.prettiercache
|
||||
.eslintcache
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn format
|
||||
yarn build && yarn workspace @discordjs/website run build:local && yarn lint-staged
|
||||
|
||||
5
.lintstagedrc.json
Normal file
5
.lintstagedrc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"*": "prettier --ignore-unknown --write",
|
||||
"{src/**,__tests__/**}.{mjs,js,ts}": "eslint --ext mjs,js,ts --fix",
|
||||
"src/**.ts": "vitest related --run"
|
||||
}
|
||||
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
@@ -7,6 +7,7 @@
|
||||
"codezombiech.gitignore",
|
||||
"eamodio.gitlens",
|
||||
"christian-kohler.npm-intellisense",
|
||||
"christian-kohler.path-intellisense"
|
||||
"christian-kohler.path-intellisense",
|
||||
"antfu.unocss"
|
||||
]
|
||||
}
|
||||
|
||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -5,5 +5,7 @@
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll": true,
|
||||
"source.organizeImports": false
|
||||
}
|
||||
},
|
||||
"unocss.root": "./packages/website",
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
diff --git a/lib/TSDocConfigFile.js b/lib/TSDocConfigFile.js
|
||||
index caf3515d60fd386c5909db5a0aa8b4180b10d602..6fa4f1984b6ba6b3a7aecd05e54477ebf141af94 100644
|
||||
--- a/lib/TSDocConfigFile.js
|
||||
+++ b/lib/TSDocConfigFile.js
|
||||
@@ -31,8 +31,7 @@ const ajv_1 = __importDefault(require("ajv"));
|
||||
const jju = __importStar(require("jju"));
|
||||
const ajv = new ajv_1.default({ verbose: true });
|
||||
function initializeSchemaValidator() {
|
||||
- const jsonSchemaPath = resolve.sync('@microsoft/tsdoc/schemas/tsdoc.schema.json', { basedir: __dirname });
|
||||
- const jsonSchemaContent = fs.readFileSync(jsonSchemaPath).toString();
|
||||
+ const jsonSchemaContent = "{\"title\":\"TSDoc Configuration\",\"description\":\"Describes the TSDoc configuration for a TypeScript project\",\"type\":\"object\",\"properties\":{\"$schema\":{\"description\":\"Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.\",\"type\":\"string\"},\"extends\":{\"description\":\"Optionally specifies one or more JSON config files that will be combined with this file. This provides a way for standard settings to be shared across multiple projects. Important: The \\\"extends\\\" paths are resolved using NodeJS module resolution, so a path to a local file MUST be prefixed with \\\"./\\\".\",\"type\":\"array\",\"items\":{\"type\":\"string\"}},\"noStandardTags\":{\"description\":\"By default, the config file loader will predefine all of the standardized TSDoc tags. To disable this and start with a completely empty configuration, set \\\"noStandardTags\\\"=true.\",\"type\":\"boolean\"},\"tagDefinitions\":{\"description\":\"Additional tags to support when parsing documentation comments with TSDoc.\",\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/tsdocTagDefinition\"}},\"supportedHtmlElements\":{\"description\":\"The HTML element names that are supported in this configuration. Used in conjunction with the \\\"reportUnsupportedHtmlElements\\\" setting.\",\"type\":\"array\",\"items\":{\"type\":\"string\",\"pattern\":\"^[a-zA-Z0-9-]+$\"}},\"reportUnsupportedHtmlElements\":{\"description\":\"Whether an error should be reported when an unsupported HTML element is encountered in a doc comment. Defaults to \\\"true\\\" if the \\\"supportedHtmlElements\\\" field is present in this file, \\\"false\\\" if not.\",\"type\":\"boolean\"},\"supportForTags\":{\"description\":\"A collection of key/value pairs. The key is a TSDoc tag name (e.g. \\\"@myTag\\\") that must be defined in this configuration. The value is a boolean indicating whether the tag is supported. The TSDoc parser may report warnings when unsupported tags are encountered. If \\\"supportForTags\\\" is specified for at least one tag, then the \\\"reportUnsupportedTags\\\" validation check is enabled by default.\",\"type\":\"object\",\"patternProperties\":{\"@[a-zA-Z][a-zA-Z0-9]*$\":{\"type\":\"boolean\"}},\"additionalItems\":false}},\"required\":[\"$schema\"],\"additionalProperties\":false,\"definitions\":{\"tsdocTagDefinition\":{\"description\":\"Configuration for a custom supported TSDoc tag.\",\"type\":\"object\",\"properties\":{\"tagName\":{\"description\":\"Name of the custom tag. TSDoc tag names start with an at-sign (@) followed by ASCII letters using camelCase capitalization.\",\"type\":\"string\"},\"syntaxKind\":{\"description\":\"Syntax kind of the custom tag. \\\"inline\\\" means that this tag can appear inside other documentation sections (example: {@link}). \\\"block\\\" means that this tag starts a new documentation section (example: @remarks). \\\"modifier\\\" means that this tag's presence indicates an aspect of the associated API item (example: @internal).\",\"type\":\"string\",\"enum\":[\"inline\",\"block\",\"modifier\"]},\"allowMultiple\":{\"description\":\"If true, then this tag may appear multiple times in a doc comment. By default, a tag may only appear once.\",\"type\":\"boolean\"}},\"required\":[\"tagName\",\"syntaxKind\"],\"additionalProperties\":false}}}";
|
||||
const jsonSchema = jju.parse(jsonSchemaContent, { mode: 'cjson' });
|
||||
return ajv.compile(jsonSchema);
|
||||
}
|
||||
363
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
Normal file
363
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
550
.yarn/plugins/@yarnpkg/plugin-version.cjs
vendored
Normal file
550
.yarn/plugins/@yarnpkg/plugin-version.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
28
.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
vendored
Normal file
28
.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
786
.yarn/releases/yarn-3.2.1.cjs
vendored
Executable file
786
.yarn/releases/yarn-3.2.1.cjs
vendored
Executable file
File diff suppressed because one or more lines are too long
11
.yarnrc.yml
Normal file
11
.yarnrc.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
nodeLinker: node-modules
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
|
||||
spec: "@yarnpkg/plugin-workspace-tools"
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||
spec: "@yarnpkg/plugin-version"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.2.1.cjs
|
||||
191
LICENSE
Normal file
191
LICENSE
Normal 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.
|
||||
51
README.md
51
README.md
@@ -1,15 +1,19 @@
|
||||
<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/discord.js"><img src="https://img.shields.io/npm/v/discord.js.svg?maxAge=3600" alt="npm version" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/dt/discord.js.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>
|
||||
</p>
|
||||
<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/discord.js"><img src="https://img.shields.io/npm/v/discord.js.svg?maxAge=3600" alt="npm version" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/dt/discord.js.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" 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>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## About
|
||||
@@ -42,19 +46,18 @@ pnpm add discord.js
|
||||
|
||||
## Example usage
|
||||
|
||||
Install all required dependencies:
|
||||
Install discord.js:
|
||||
|
||||
```sh-session
|
||||
npm install discord.js @discordjs/rest discord-api-types
|
||||
yarn add discord.js @discordjs/rest discord-api-types
|
||||
pnpm add discord.js @discordjs/rest discord-api-types
|
||||
npm install discord.js
|
||||
yarn add discord.js
|
||||
pnpm add discord.js
|
||||
```
|
||||
|
||||
Register a slash command against the Discord API:
|
||||
|
||||
```js
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
const { REST, Routes } = require('discord.js');
|
||||
|
||||
const commands = [
|
||||
{
|
||||
@@ -63,13 +66,13 @@ const commands = [
|
||||
},
|
||||
];
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken('token');
|
||||
const rest = new REST({ version: '10' }).setToken('token');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
|
||||
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
@@ -81,15 +84,15 @@ const rest = new REST({ version: '9' }).setToken('token');
|
||||
Afterwards we can create a quite simple example bot:
|
||||
|
||||
```js
|
||||
const { Client, Intents } = require('discord.js');
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||
const { Client, GatewayIntentBits } = require('discord.js');
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on('interactionCreate', async (interaction) => {
|
||||
if (!interaction.isCommand()) return;
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
if (interaction.commandName === 'ping') {
|
||||
await interaction.reply('Pong!');
|
||||
@@ -101,10 +104,10 @@ client.login('token');
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/discord.js/tree/main/packages/website))
|
||||
- [Documentation](https://discord.js.org/#/docs)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v13.html), including updated and removed items in the library.
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v14.html), including updated and removed items in the library.
|
||||
- [discord.js Discord server](https://discord.gg/djs)
|
||||
- [Discord API Discord server](https://discord.gg/discord-api)
|
||||
- [GitHub](https://github.com/discordjs/discord.js)
|
||||
|
||||
26
codecov.yml
Normal file
26
codecov.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
codecov:
|
||||
notify:
|
||||
after_n_builds: 6
|
||||
strict_yaml_branch: main
|
||||
|
||||
coverage:
|
||||
range: '50...90'
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
target: auto
|
||||
threshold: 5%
|
||||
informational: true
|
||||
patch: off
|
||||
|
||||
flag_management:
|
||||
default_rules:
|
||||
statuses:
|
||||
- type: project
|
||||
target: auto
|
||||
threshold: 2%
|
||||
informational: true
|
||||
|
||||
comment:
|
||||
require_changes: true
|
||||
after_n_builds: 6
|
||||
82
package.json
82
package.json
@@ -5,21 +5,20 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "turbo run build",
|
||||
"test": "turbo run test",
|
||||
"lint": "turbo run lint",
|
||||
"format": "turbo run format",
|
||||
"fmt": "turbo run format",
|
||||
"test": "turbo run test --parallel",
|
||||
"lint": "turbo run lint --parallel",
|
||||
"format": "turbo run format --parallel",
|
||||
"fmt": "turbo run format --parallel",
|
||||
"postinstall": "is-ci || husky install",
|
||||
"docs": "turbo run docs",
|
||||
"changelog": "turbo run changelog",
|
||||
"update": "yarn upgrade-interactive --latest"
|
||||
"docs": "turbo run docs --parallel",
|
||||
"update": "yarn upgrade-interactive"
|
||||
},
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Antonio Roman <kyradiscord@gmail.com>"
|
||||
"Aura Román <kyradiscord@gmail.com>"
|
||||
],
|
||||
"keywords": [
|
||||
"discord",
|
||||
@@ -38,13 +37,20 @@
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^16.1.0",
|
||||
"@commitlint/config-angular": "^16.0.0",
|
||||
"@favware/npm-deprecate": "^1.0.4",
|
||||
"@commitlint/cli": "^17.1.2",
|
||||
"@commitlint/config-angular": "^17.1.0",
|
||||
"@favware/cliff-jumper": "^1.8.7",
|
||||
"@favware/npm-deprecate": "^1.0.5",
|
||||
"conventional-changelog-cli": "^2.2.2",
|
||||
"husky": "^7.0.4",
|
||||
"prettier": "^2.5.1",
|
||||
"turbo": "1.0.28"
|
||||
"husky": "^8.0.1",
|
||||
"is-ci": "^3.0.1",
|
||||
"lint-staged": "^13.0.3",
|
||||
"tsup": "^6.2.3",
|
||||
"turbo": "^1.5.3",
|
||||
"typescript": "^4.8.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"@microsoft/tsdoc-config": "patch:@microsoft/tsdoc-config@npm:0.16.1#.yarn/patches/@microsoft-tsdoc-config-npm-0.16.1-81031b1bbf.patch"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
@@ -52,51 +58,5 @@
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"turbo": {
|
||||
"baseBranch": "origin/main",
|
||||
"pipeline": {
|
||||
"build": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": [
|
||||
"dist/**",
|
||||
"docs/docs.json"
|
||||
]
|
||||
},
|
||||
"test": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": [
|
||||
"coverage/**"
|
||||
]
|
||||
},
|
||||
"lint": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
"format": {
|
||||
"outputs": []
|
||||
},
|
||||
"docs": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": [
|
||||
"docs/docs.json"
|
||||
]
|
||||
},
|
||||
"changelog": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": [
|
||||
"CHANGELOG.md"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
"packageManager": "yarn@3.2.1"
|
||||
}
|
||||
|
||||
3
packages/actions/.eslintrc.json
Normal file
3
packages/actions/.eslintrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../.eslintrc.json"
|
||||
}
|
||||
29
packages/actions/.gitignore
vendored
Normal file
29
packages/actions/.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist/
|
||||
typings/
|
||||
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
!docs/examples/
|
||||
!docs/examples/*.md
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
coverage/
|
||||
1
packages/actions/.lintstagedrc.js
Normal file
1
packages/actions/.lintstagedrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.lintstagedrc.json');
|
||||
8
packages/actions/.prettierignore
Normal file
8
packages/actions/.prettierignore
Normal file
@@ -0,0 +1,8 @@
|
||||
# Autogenerated
|
||||
CHANGELOG.md
|
||||
.turbo
|
||||
dist/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
coverage/
|
||||
1
packages/actions/.prettierrc.js
Normal file
1
packages/actions/.prettierrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.prettierrc.json');
|
||||
190
packages/actions/LICENSE
Normal file
190
packages/actions/LICENSE
Normal 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.
|
||||
34
packages/actions/README.md
Normal file
34
packages/actions/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
<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>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/discord.js/tree/main/packages/website))
|
||||
- [Documentation](https://discord.js.org/#/docs)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v14.html), including updated and removed items in the library.
|
||||
- [discord.js Discord server](https://discord.gg/djs)
|
||||
- [Discord API Discord server](https://discord.gg/discord-api)
|
||||
- [GitHub](https://github.com/discordjs/discord.js/tree/main/packages/scripts)
|
||||
- [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
|
||||
|
||||
## Contributing
|
||||
|
||||
See [the contribution guide](https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md) 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](https://discord.gg/djs).
|
||||
22
packages/actions/__tests__/formatTag.test.ts
Normal file
22
packages/actions/__tests__/formatTag.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { formatTag } from '../src/index.js';
|
||||
|
||||
describe('Format Tag', () => {
|
||||
test('GIVEN tag with a prefix THEN format tag to not contain the prefix', () => {
|
||||
expect(formatTag('@discordjs/rest@0.4.0')).toEqual({ package: 'rest', semver: '0.4.0' });
|
||||
expect(formatTag('@discordjs/collection@0.6.0')).toEqual({ package: 'collection', semver: '0.6.0' });
|
||||
expect(formatTag('@discordjs/proxy@0.1.0')).toEqual({ package: 'proxy', semver: '0.1.0' });
|
||||
expect(formatTag('@discordjs/builders@0.13.0')).toEqual({ package: 'builders', semver: '0.13.0' });
|
||||
expect(formatTag('@discordjs/voice@0.9.0')).toEqual({ package: 'voice', semver: '0.9.0' });
|
||||
});
|
||||
|
||||
test('GIVEN tag with no prefix THEN return tag', () => {
|
||||
expect(formatTag('13.5.1')).toEqual({ package: 'discord.js', semver: '13.5.1' });
|
||||
expect(formatTag('13.7.0')).toEqual({ package: 'discord.js', semver: '13.7.0' });
|
||||
});
|
||||
|
||||
test('GIVEN no or invalid tag THEN return null', () => {
|
||||
expect(formatTag('')).toEqual(null);
|
||||
expect(formatTag('abc')).toEqual(null);
|
||||
});
|
||||
});
|
||||
59
packages/actions/package.json
Normal file
59
packages/actions/package.json
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "@discordjs/actions",
|
||||
"version": "0.1.0",
|
||||
"description": "A set of actions that we use for our workflows",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"build": "tsup",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext mjs,js,ts",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext mjs,js,ts --fix",
|
||||
"fmt": "yarn format"
|
||||
},
|
||||
"main": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "__tests__"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordjs"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.9.1",
|
||||
"tslib": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.60",
|
||||
"@vitest/coverage-c8": "^0.23.4",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-neon": "^0.1.33",
|
||||
"prettier": "^2.7.1",
|
||||
"tsup": "^6.2.3",
|
||||
"typescript": "^4.8.3",
|
||||
"vitest": "^0.23.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
}
|
||||
}
|
||||
14
packages/actions/src/formatTag/action.yml
Normal file
14
packages/actions/src/formatTag/action.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
name: 'Format Tag'
|
||||
description: 'Formats a git tag to remove potentially prefixes'
|
||||
inputs:
|
||||
tag:
|
||||
description: 'The input tag'
|
||||
required: true
|
||||
outputs:
|
||||
package:
|
||||
description: 'The package string that was extracted from this tag'
|
||||
semver:
|
||||
description: 'The semver string that was extracted from this tag'
|
||||
runs:
|
||||
using: node16
|
||||
main: ../../dist/index.mjs
|
||||
13
packages/actions/src/formatTag/formatTag.ts
Normal file
13
packages/actions/src/formatTag/formatTag.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export function formatTag(tag: string) {
|
||||
// eslint-disable-next-line unicorn/no-unsafe-regex, prefer-named-capture-group
|
||||
const parsed = /(^@.*\/(?<package>.*)@v?)?(?<semver>\d+.\d+.\d+)-?.*/.exec(tag);
|
||||
|
||||
if (parsed?.groups) {
|
||||
return {
|
||||
package: parsed.groups.package ?? 'discord.js',
|
||||
semver: parsed.groups.semver,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
10
packages/actions/src/formatTag/index.ts
Normal file
10
packages/actions/src/formatTag/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { getInput, setOutput } from '@actions/core';
|
||||
import { formatTag } from './formatTag.js';
|
||||
|
||||
const tag = getInput('tag', { required: true });
|
||||
const parsed = formatTag(tag);
|
||||
|
||||
if (parsed) {
|
||||
setOutput('package', parsed.package);
|
||||
setOutput('semver', parsed.semver);
|
||||
}
|
||||
1
packages/actions/src/index.ts
Normal file
1
packages/actions/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './formatTag/formatTag.js';
|
||||
58
packages/actions/src/uploadCoverage/action.yml
Normal file
58
packages/actions/src/uploadCoverage/action.yml
Normal file
@@ -0,0 +1,58 @@
|
||||
name: 'Upload Coverage'
|
||||
description: 'Uploads code coverage reports to codecov with separate flags for separate packages'
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Upload Builders Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/builders/coverage/cobertura-coverage.xml
|
||||
flags: builders
|
||||
|
||||
- name: Upload Collection Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/collection/coverage/cobertura-coverage.xml
|
||||
flags: collection
|
||||
|
||||
- name: Upload Discord.js Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/discord.js/coverage/cobertura-coverage.xml
|
||||
flags: discord.js
|
||||
|
||||
- name: Upload Proxy Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/proxy/coverage/cobertura-coverage.xml
|
||||
flags: proxy
|
||||
|
||||
- name: Upload Rest Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/rest/coverage/cobertura-coverage.xml
|
||||
flags: rest
|
||||
|
||||
- name: Upload Voice Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/voice/coverage/cobertura-coverage.xml
|
||||
flags: voice
|
||||
|
||||
- name: Upload Website Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/website/coverage/cobertura-coverage.xml
|
||||
flags: website
|
||||
|
||||
- name: Upload WS Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/ws/coverage/cobertura-coverage.xml
|
||||
flags: ws
|
||||
|
||||
- name: Upload Utilities Coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/actions/coverage/cobertura-coverage.xml, ./packages/scripts/coverage/cobertura-coverage.xml
|
||||
flags: utilities
|
||||
20
packages/actions/tsconfig.eslint.json
Normal file
20
packages/actions/tsconfig.eslint.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.mjs",
|
||||
"**/*.jsx",
|
||||
"**/*.test.ts",
|
||||
"**/*.test.js",
|
||||
"**/*.test.mjs",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.js",
|
||||
"**/*.spec.mjs"
|
||||
],
|
||||
"exclude": []
|
||||
}
|
||||
4
packages/actions/tsconfig.json
Normal file
4
packages/actions/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
7
packages/actions/tsup.config.js
Normal file
7
packages/actions/tsup.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { createTsupConfig } from '../../tsup.config.js';
|
||||
|
||||
export default createTsupConfig({
|
||||
entry: ['src/index.ts', 'src/formatTag/index.ts'],
|
||||
format: ['esm'],
|
||||
minify: true,
|
||||
});
|
||||
3
packages/api-extractor-utils/.eslintrc.json
Normal file
3
packages/api-extractor-utils/.eslintrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../.eslintrc.json"
|
||||
}
|
||||
27
packages/api-extractor-utils/.gitignore
vendored
Normal file
27
packages/api-extractor-utils/.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist/
|
||||
typings/
|
||||
docs/**/*
|
||||
!docs/index.json
|
||||
!docs/README.md
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
coverage/
|
||||
tsconfig.tsbuildinfo
|
||||
1
packages/api-extractor-utils/.lintstagedrc.js
Normal file
1
packages/api-extractor-utils/.lintstagedrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.lintstagedrc.json');
|
||||
8
packages/api-extractor-utils/.prettierignore
Normal file
8
packages/api-extractor-utils/.prettierignore
Normal file
@@ -0,0 +1,8 @@
|
||||
# Autogenerated
|
||||
CHANGELOG.md
|
||||
.turbo
|
||||
dist/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
coverage/
|
||||
1
packages/api-extractor-utils/.prettierrc.js
Normal file
1
packages/api-extractor-utils/.prettierrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.prettierrc.json');
|
||||
190
packages/api-extractor-utils/LICENSE
Normal file
190
packages/api-extractor-utils/LICENSE
Normal 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.
|
||||
34
packages/api-extractor-utils/README.md
Normal file
34
packages/api-extractor-utils/README.md
Normal file
@@ -0,0 +1,34 @@
|
||||
<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>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/discord.js/tree/main/packages/website))
|
||||
- [Documentation](https://discord.js.org/#/docs)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v14.html), including updated and removed items in the library.
|
||||
- [discord.js Discord server](https://discord.gg/djs)
|
||||
- [Discord API Discord server](https://discord.gg/discord-api)
|
||||
- [GitHub](https://github.com/discordjs/discord.js/tree/main/packages/scripts)
|
||||
- [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
|
||||
|
||||
## Contributing
|
||||
|
||||
See [the contribution guide](https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md) 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](https://discord.gg/djs).
|
||||
52
packages/api-extractor-utils/package.json
Normal file
52
packages/api-extractor-utils/package.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "@discordjs/api-extractor-utils",
|
||||
"version": "1.0.0",
|
||||
"description": "Utilities for api-extractor",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"lint": "prettier --check . && cross-env TIMING=1 eslint src --ext mjs,js,ts",
|
||||
"format": "prettier --write . && cross-env TIMING=1 eslint src --ext mjs,js,ts --fix",
|
||||
"fmt": "yarn format"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"directories": {
|
||||
"lib": "src"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"contributors": [
|
||||
"Suneet Tipirneni <suneettipirneni@icloud.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@microsoft/api-extractor-model": "7.24.0",
|
||||
"@microsoft/tsdoc": "0.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.60",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-neon": "^0.1.33",
|
||||
"prettier": "^2.7.1",
|
||||
"tsup": "^6.2.3",
|
||||
"typescript": "^4.8.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
416
packages/api-extractor-utils/src/ApiNodeJSONEncoder.ts
Normal file
416
packages/api-extractor-utils/src/ApiNodeJSONEncoder.ts
Normal file
@@ -0,0 +1,416 @@
|
||||
import type { ApiReturnTypeMixin } from '@microsoft/api-extractor-model';
|
||||
import {
|
||||
type ApiModel,
|
||||
ApiDeclaredItem,
|
||||
type ApiPropertyItem,
|
||||
type ApiMethod,
|
||||
type ApiParameterListMixin,
|
||||
type ApiTypeParameterListMixin,
|
||||
type ApiClass,
|
||||
type ApiFunction,
|
||||
ApiItemKind,
|
||||
type ApiTypeAlias,
|
||||
type ApiEnum,
|
||||
type ApiInterface,
|
||||
type ApiMethodSignature,
|
||||
type ApiPropertySignature,
|
||||
type ApiVariable,
|
||||
type ApiItem,
|
||||
type ApiConstructor,
|
||||
type ApiItemContainerMixin,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import { generateTypeParamData } from './TypeParameterJSONEncoder.js';
|
||||
import { type TokenDocumentation, resolveName, genReference, genToken, genParameter, generatePath } from './parse.js';
|
||||
import type { DocBlockJSON } from './tsdoc/CommentBlock.js';
|
||||
import type { AnyDocNodeJSON } from './tsdoc/CommentNode.js';
|
||||
import { type DocNodeContainerJSON, nodeContainer } from './tsdoc/CommentNodeContainer.js';
|
||||
import { createCommentNode } from './tsdoc/index.js';
|
||||
|
||||
export interface ReferenceData {
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface InheritanceData {
|
||||
parentKey: string;
|
||||
parentName: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface ApiInheritableJSON {
|
||||
inheritanceData: InheritanceData | null;
|
||||
}
|
||||
|
||||
export interface ApiItemJSON {
|
||||
comment: AnyDocNodeJSON | null;
|
||||
containerKey: string;
|
||||
deprecated: DocNodeContainerJSON | null;
|
||||
excerpt: string;
|
||||
excerptTokens: TokenDocumentation[];
|
||||
kind: string;
|
||||
name: string;
|
||||
path: string[];
|
||||
referenceData: ReferenceData;
|
||||
remarks: DocNodeContainerJSON | null;
|
||||
summary: DocNodeContainerJSON | null;
|
||||
}
|
||||
|
||||
export interface ApiPropertyItemJSON extends ApiItemJSON, ApiInheritableJSON {
|
||||
optional: boolean;
|
||||
propertyTypeTokens: TokenDocumentation[];
|
||||
readonly: boolean;
|
||||
}
|
||||
|
||||
export interface ApiTypeParameterListJSON {
|
||||
typeParameters: ApiTypeParameterJSON[];
|
||||
}
|
||||
|
||||
export interface ApiTypeParameterJSON {
|
||||
commentBlock: DocBlockJSON | null;
|
||||
constraintTokens: TokenDocumentation[];
|
||||
defaultTokens: TokenDocumentation[];
|
||||
name: string;
|
||||
optional: boolean;
|
||||
}
|
||||
|
||||
export interface ApiParameterListJSON {
|
||||
parameters: ApiParameterJSON[];
|
||||
}
|
||||
|
||||
export interface ApiMethodSignatureJSON
|
||||
extends ApiItemJSON,
|
||||
ApiTypeParameterListJSON,
|
||||
ApiParameterListJSON,
|
||||
ApiInheritableJSON {
|
||||
mergedSiblings: ApiMethodSignatureJSON[];
|
||||
optional: boolean;
|
||||
overloadIndex: number;
|
||||
returnTypeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiMethodJSON extends ApiMethodSignatureJSON {
|
||||
mergedSiblings: ApiMethodJSON[];
|
||||
protected: boolean;
|
||||
static: boolean;
|
||||
}
|
||||
|
||||
export interface ApiParameterJSON {
|
||||
isOptional: boolean;
|
||||
name: string;
|
||||
paramCommentBlock: DocBlockJSON | null;
|
||||
tokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiClassJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
constructor: ApiConstructorJSON | null;
|
||||
extendsTokens: TokenDocumentation[];
|
||||
implementsTokens: TokenDocumentation[][];
|
||||
methods: ApiMethodJSON[];
|
||||
properties: ApiPropertyItemJSON[];
|
||||
}
|
||||
|
||||
export interface ApiTypeAliasJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
typeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface EnumMemberData {
|
||||
initializerTokens: TokenDocumentation[];
|
||||
name: string;
|
||||
summary: DocNodeContainerJSON | null;
|
||||
}
|
||||
|
||||
export interface ApiEnumJSON extends ApiItemJSON {
|
||||
members: EnumMemberData[];
|
||||
}
|
||||
|
||||
export interface ApiInterfaceJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
extendsTokens: TokenDocumentation[][] | null;
|
||||
methods: ApiMethodSignatureJSON[];
|
||||
properties: ApiPropertyItemJSON[];
|
||||
}
|
||||
|
||||
export interface ApiVariableJSON extends ApiItemJSON {
|
||||
readonly: boolean;
|
||||
typeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiFunctionJSON extends ApiItemJSON, ApiTypeParameterListJSON, ApiParameterListJSON {
|
||||
mergedSiblings: ApiFunctionJSON[];
|
||||
overloadIndex: number;
|
||||
returnTypeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface ApiConstructorJSON extends ApiItemJSON, ApiParameterListJSON {
|
||||
protected: boolean;
|
||||
}
|
||||
|
||||
export type FunctionLike = ApiDeclaredItem & ApiParameterListMixin & ApiReturnTypeMixin & ApiTypeParameterListMixin;
|
||||
|
||||
export class ApiNodeJSONEncoder {
|
||||
public static encode(model: ApiModel, node: ApiItem, version: string) {
|
||||
if (!(node instanceof ApiDeclaredItem)) {
|
||||
console.log(`Cannot serialize node of type ${node.kind}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case ApiItemKind.Class:
|
||||
return this.encodeClass(model, node as ApiClass, version);
|
||||
case ApiItemKind.Function:
|
||||
return this.encodeFunction(model, node as ApiFunction, version);
|
||||
case ApiItemKind.Interface:
|
||||
return this.encodeInterface(model, node as ApiInterface, version);
|
||||
case ApiItemKind.TypeAlias:
|
||||
return this.encodeTypeAlias(model, node as ApiTypeAlias, version);
|
||||
case ApiItemKind.Enum:
|
||||
return this.encodeEnum(model, node as ApiEnum, version);
|
||||
case ApiItemKind.Variable:
|
||||
return this.encodeVariable(model, node as ApiVariable, version);
|
||||
default:
|
||||
// console.log(`Unknown API item kind: ${node.kind}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public static encodeItem(model: ApiModel, item: ApiDeclaredItem, version: string): ApiItemJSON {
|
||||
const path = [];
|
||||
for (const _item of item.getHierarchy()) {
|
||||
switch (_item.kind) {
|
||||
case 'None':
|
||||
case 'EntryPoint':
|
||||
case 'Model':
|
||||
break;
|
||||
default:
|
||||
path.push(resolveName(_item));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
kind: item.kind,
|
||||
name: resolveName(item),
|
||||
referenceData: genReference(item, version),
|
||||
excerpt: item.excerpt.text,
|
||||
excerptTokens: item.excerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
remarks: item.tsdocComment?.remarksBlock
|
||||
? (createCommentNode(item.tsdocComment.remarksBlock, model, version, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
summary: item.tsdocComment?.summarySection
|
||||
? (createCommentNode(item.tsdocComment.summarySection, model, version, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
deprecated: item.tsdocComment?.deprecatedBlock
|
||||
? (createCommentNode(item.tsdocComment.deprecatedBlock, model, version, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
path,
|
||||
containerKey: item.containerKey,
|
||||
comment: item.tsdocComment ? createCommentNode(item.tsdocComment, model, version, item.parent) : null,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeParameterList(
|
||||
model: ApiModel,
|
||||
item: ApiDeclaredItem & ApiParameterListMixin,
|
||||
version: string,
|
||||
): { parameters: ApiParameterJSON[] } {
|
||||
return {
|
||||
parameters: item.parameters.map((param) => genParameter(model, param, version)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeTypeParameterList(
|
||||
model: ApiModel,
|
||||
item: ApiDeclaredItem & ApiTypeParameterListMixin,
|
||||
version: string,
|
||||
): ApiTypeParameterListJSON {
|
||||
return {
|
||||
typeParameters: item.typeParameters.map((param) => generateTypeParamData(model, param, version, item.parent)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeProperty(
|
||||
model: ApiModel,
|
||||
item: ApiPropertyItem,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
): ApiPropertyItemJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeInheritanceData(item, parent, version),
|
||||
propertyTypeTokens: item.propertyTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
readonly: item.isReadonly,
|
||||
optional: item.isOptional,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeInheritanceData(
|
||||
item: ApiDeclaredItem,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
): ApiInheritableJSON {
|
||||
return {
|
||||
inheritanceData:
|
||||
item.parent && item.parent.containerKey !== parent.containerKey
|
||||
? {
|
||||
parentKey: item.parent.containerKey,
|
||||
parentName: item.parent.displayName,
|
||||
path: generatePath(item.parent.getHierarchy(), version),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeFunctionLike(model: ApiModel, item: FunctionLike, version: string) {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeParameterList(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
returnTypeTokens: item.returnTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
overloadIndex: item.overloadIndex,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeFunction(model: ApiModel, item: FunctionLike, version: string, nested = false): ApiFunctionJSON {
|
||||
return {
|
||||
...this.encodeFunctionLike(model, item, version),
|
||||
mergedSiblings: nested
|
||||
? []
|
||||
: item.getMergedSiblings().map((item) => this.encodeFunction(model, item as ApiFunction, version, true)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeMethodSignature(
|
||||
model: ApiModel,
|
||||
item: ApiMethodSignature,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
nested = false,
|
||||
): ApiMethodSignatureJSON {
|
||||
return {
|
||||
...this.encodeFunctionLike(model, item, version),
|
||||
...this.encodeInheritanceData(item, parent, version),
|
||||
optional: item.isOptional,
|
||||
mergedSiblings: nested
|
||||
? []
|
||||
: item
|
||||
.getMergedSiblings()
|
||||
.map((item) => this.encodeMethodSignature(model, item as ApiMethodSignature, parent, version, true)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeMethod(
|
||||
model: ApiModel,
|
||||
item: ApiMethod,
|
||||
parent: ApiItemContainerMixin,
|
||||
version: string,
|
||||
nested = false,
|
||||
): ApiMethodJSON {
|
||||
return {
|
||||
...this.encodeMethodSignature(model, item, parent, version),
|
||||
static: item.isStatic,
|
||||
protected: item.isProtected,
|
||||
mergedSiblings: nested
|
||||
? []
|
||||
: item.getMergedSiblings().map((item) => this.encodeMethod(model, item as ApiMethod, parent, version, true)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeClass(model: ApiModel, item: ApiClass, version: string): ApiClassJSON {
|
||||
const extendsExcerpt = item.extendsType?.excerpt;
|
||||
|
||||
const methods: ApiMethodJSON[] = [];
|
||||
const properties: ApiPropertyItemJSON[] = [];
|
||||
|
||||
let constructor: ApiConstructor | undefined;
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.Method:
|
||||
methods.push(this.encodeMethod(model, member as ApiMethod, item, version));
|
||||
break;
|
||||
case ApiItemKind.Property:
|
||||
properties.push(this.encodeProperty(model, member as ApiPropertyItem, item, version));
|
||||
break;
|
||||
case ApiItemKind.Constructor:
|
||||
constructor = member as ApiConstructor;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
constructor: constructor ? this.encodeConstructor(model, constructor, version) : null,
|
||||
extendsTokens: extendsExcerpt ? extendsExcerpt.spannedTokens.map((token) => genToken(model, token, version)) : [],
|
||||
implementsTokens: item.implementsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
),
|
||||
methods,
|
||||
properties,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeTypeAlias(model: ApiModel, item: ApiTypeAlias, version: string): ApiTypeAliasJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
typeTokens: item.typeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeEnum(model: ApiModel, item: ApiEnum, version: string): ApiEnumJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
members: item.members.map((member) => ({
|
||||
name: member.name,
|
||||
initializerTokens:
|
||||
member.initializerExcerpt?.spannedTokens.map((token) => genToken(model, token, version)) ?? [],
|
||||
summary: member.tsdocComment ? nodeContainer(member.tsdocComment.summarySection, model, version, member) : null,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeInterface(model: ApiModel, item: ApiInterface, version: string): ApiInterfaceJSON {
|
||||
const methods: ApiMethodSignatureJSON[] = [];
|
||||
const properties: ApiPropertyItemJSON[] = [];
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.MethodSignature:
|
||||
methods.push(this.encodeMethodSignature(model, member as ApiMethodSignature, item, version));
|
||||
break;
|
||||
case ApiItemKind.PropertySignature:
|
||||
properties.push(this.encodeProperty(model, member as ApiPropertySignature, item, version));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeTypeParameterList(model, item, version),
|
||||
extendsTokens: item.extendsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
),
|
||||
methods,
|
||||
properties,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeVariable(model: ApiModel, item: ApiVariable, version: string): ApiVariableJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
typeTokens: item.variableTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
readonly: item.isReadonly,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeConstructor(model: ApiModel, item: ApiConstructor, version: string): ApiConstructorJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item, version),
|
||||
...this.encodeParameterList(model, item, version),
|
||||
protected: item.isProtected,
|
||||
};
|
||||
}
|
||||
}
|
||||
31
packages/api-extractor-utils/src/TypeParameterJSONEncoder.ts
Normal file
31
packages/api-extractor-utils/src/TypeParameterJSONEncoder.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { TypeParameter, ApiModel, ApiItem } from '@microsoft/api-extractor-model';
|
||||
import { type TokenDocumentation, genToken } from './parse.js';
|
||||
import { type DocBlockJSON, block } from './tsdoc/CommentBlock.js';
|
||||
|
||||
export interface TypeParameterData {
|
||||
commentBlock: DocBlockJSON | null;
|
||||
constraintTokens: TokenDocumentation[];
|
||||
defaultTokens: TokenDocumentation[];
|
||||
name: string;
|
||||
optional: boolean;
|
||||
}
|
||||
|
||||
export function generateTypeParamData(
|
||||
model: ApiModel,
|
||||
typeParam: TypeParameter,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): TypeParameterData {
|
||||
const constraintTokens = typeParam.constraintExcerpt.spannedTokens.map((token) => genToken(model, token, version));
|
||||
const defaultTokens = typeParam.defaultTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version));
|
||||
|
||||
return {
|
||||
name: typeParam.name,
|
||||
constraintTokens,
|
||||
defaultTokens,
|
||||
optional: typeParam.isOptional,
|
||||
commentBlock: typeParam.tsdocTypeParamBlock
|
||||
? block(typeParam.tsdocTypeParamBlock, model, version, parentItem)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
4
packages/api-extractor-utils/src/index.ts
Normal file
4
packages/api-extractor-utils/src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './ApiNodeJSONEncoder.js';
|
||||
export * from './parse.js';
|
||||
export * from './tsdoc/index.js';
|
||||
export * from './TypeParameterJSONEncoder.js';
|
||||
222
packages/api-extractor-utils/src/parse.ts
Normal file
222
packages/api-extractor-utils/src/parse.ts
Normal file
@@ -0,0 +1,222 @@
|
||||
import {
|
||||
type ApiModel,
|
||||
type ApiPackage,
|
||||
type ApiItem,
|
||||
ApiItemKind,
|
||||
ApiDocumentedItem,
|
||||
type Excerpt,
|
||||
ExcerptTokenKind,
|
||||
ApiNameMixin,
|
||||
type ApiPropertyItem,
|
||||
type ExcerptToken,
|
||||
type Parameter,
|
||||
type ApiFunction,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import type { DocNode, DocParagraph, DocPlainText } from '@microsoft/tsdoc';
|
||||
import { type Meaning, ModuleSource } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';
|
||||
import type { DocBlockJSON } from './tsdoc/CommentBlock.js';
|
||||
import { createCommentNode } from './tsdoc/index.js';
|
||||
|
||||
export function findPackage(model: ApiModel, name: string): ApiPackage | undefined {
|
||||
return (model.findMembersByName(name)[0] ?? model.findMembersByName(`@discordjs/${name}`)[0]) as
|
||||
| ApiPackage
|
||||
| undefined;
|
||||
}
|
||||
|
||||
export function generatePath(items: readonly ApiItem[], version: string) {
|
||||
let path = '/docs/packages';
|
||||
|
||||
for (const item of items) {
|
||||
switch (item.kind) {
|
||||
case ApiItemKind.Model:
|
||||
case ApiItemKind.EntryPoint:
|
||||
case ApiItemKind.EnumMember:
|
||||
break;
|
||||
case ApiItemKind.Package:
|
||||
path += `/${item.displayName}`;
|
||||
break;
|
||||
case ApiItemKind.Function:
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const functionItem = item as ApiFunction;
|
||||
path += `/${functionItem.displayName}${
|
||||
functionItem.overloadIndex && functionItem.overloadIndex > 1 ? `:${functionItem.overloadIndex}` : ''
|
||||
}:${item.kind}`;
|
||||
break;
|
||||
case ApiItemKind.Property:
|
||||
case ApiItemKind.Method:
|
||||
case ApiItemKind.MethodSignature:
|
||||
case ApiItemKind.PropertySignature:
|
||||
// TODO: Take overloads into account
|
||||
path += `#${item.displayName}`;
|
||||
break;
|
||||
default:
|
||||
path += `/${item.displayName}:${item.kind}`;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line prefer-named-capture-group, unicorn/no-unsafe-regex
|
||||
return path.replace(/@discordjs\/(.*)\/(.*)?/, `$1/${version}/$2`);
|
||||
}
|
||||
|
||||
export function resolveDocComment(item: ApiDocumentedItem) {
|
||||
if (!(item instanceof ApiDocumentedItem)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { tsdocComment } = item;
|
||||
|
||||
if (!tsdocComment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { summarySection } = tsdocComment;
|
||||
|
||||
function recurseNodes(node: DocNode | undefined): string | null {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case 'Paragraph':
|
||||
return recurseNodes(node as DocParagraph);
|
||||
case 'PlainText':
|
||||
return (node as DocPlainText).text;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return recurseNodes(summarySection);
|
||||
}
|
||||
|
||||
export function findReferences(model: ApiModel, excerpt: Excerpt) {
|
||||
const retVal: Set<ApiItem> = new Set();
|
||||
|
||||
for (const token of excerpt.spannedTokens) {
|
||||
switch (token.kind) {
|
||||
case ExcerptTokenKind.Reference: {
|
||||
const item = model.resolveDeclarationReference(token.canonicalReference!, undefined).resolvedApiItem;
|
||||
if (!item) {
|
||||
break;
|
||||
}
|
||||
|
||||
retVal.add(item);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
export function resolveName(item: ApiItem) {
|
||||
if (ApiNameMixin.isBaseClassOf(item)) {
|
||||
return item.name;
|
||||
}
|
||||
|
||||
return item.displayName;
|
||||
}
|
||||
|
||||
export function getProperties(item: ApiItem) {
|
||||
const properties: ApiPropertyItem[] = [];
|
||||
for (const member of item.members) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.Property:
|
||||
case ApiItemKind.PropertySignature:
|
||||
case ApiItemKind.Method:
|
||||
case ApiItemKind.MethodSignature:
|
||||
properties.push(member as ApiPropertyItem);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
export interface TokenDocumentation {
|
||||
kind: string;
|
||||
path: string | null;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface ParameterDocumentation {
|
||||
isOptional: boolean;
|
||||
name: string;
|
||||
paramCommentBlock: DocBlockJSON | null;
|
||||
tokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
function createDapiTypesURL(meaning: Meaning, name: string) {
|
||||
const base = 'https://discord-api-types.dev/api/discord-api-types-v10';
|
||||
|
||||
switch (meaning) {
|
||||
case 'type':
|
||||
return `${base}#${name}`;
|
||||
default:
|
||||
return `${base}/${meaning}/${name}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function genReference(item: ApiItem, version: string) {
|
||||
return {
|
||||
name: resolveName(item),
|
||||
path: generatePath(item.getHierarchy(), version),
|
||||
};
|
||||
}
|
||||
|
||||
export function genToken(model: ApiModel, token: ExcerptToken, version: string) {
|
||||
if (token.canonicalReference) {
|
||||
// @ts-expect-error: Symbol is not publicly accessible
|
||||
token.canonicalReference._navigation = '.';
|
||||
}
|
||||
|
||||
if (
|
||||
token.canonicalReference?.source instanceof ModuleSource &&
|
||||
token.canonicalReference.symbol &&
|
||||
token.canonicalReference.source.packageName === 'discord-api-types' &&
|
||||
token.canonicalReference.symbol.meaning
|
||||
) {
|
||||
return {
|
||||
kind: token.kind,
|
||||
text: token.text,
|
||||
path: createDapiTypesURL(token.canonicalReference.symbol.meaning, token.text),
|
||||
};
|
||||
}
|
||||
|
||||
const item = token.canonicalReference
|
||||
? model.resolveDeclarationReference(token.canonicalReference, undefined).resolvedApiItem ?? null
|
||||
: null;
|
||||
|
||||
return {
|
||||
kind: token.kind,
|
||||
text: token.text,
|
||||
path: item ? generatePath(item.getHierarchy(), version) : null,
|
||||
};
|
||||
}
|
||||
|
||||
export function genParameter(model: ApiModel, param: Parameter, version: string): ParameterDocumentation {
|
||||
return {
|
||||
name: param.name,
|
||||
isOptional: param.isOptional,
|
||||
tokens: param.parameterTypeExcerpt.spannedTokens.map((token) => genToken(model, token, version)),
|
||||
paramCommentBlock: param.tsdocParamBlock
|
||||
? (createCommentNode(param.tsdocParamBlock, model, version) as DocBlockJSON)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function getMembers(pkg: ApiPackage, version: string) {
|
||||
return pkg.members[0]!.members.map((member) => ({
|
||||
name: member.displayName,
|
||||
kind: member.kind as string,
|
||||
path: generatePath(member.getHierarchy(), version),
|
||||
containerKey: member.containerKey,
|
||||
overloadIndex: member.kind === 'Function' ? (member as ApiFunction).overloadIndex : null,
|
||||
}));
|
||||
}
|
||||
18
packages/api-extractor-utils/src/tsdoc/CommentBlock.ts
Normal file
18
packages/api-extractor-utils/src/tsdoc/CommentBlock.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { ApiModel, ApiItem } from '@microsoft/api-extractor-model';
|
||||
import type { DocBlock } from '@microsoft/tsdoc';
|
||||
import { blockTag, type DocBlockTagJSON } from './CommentBlockTag.js';
|
||||
import { type AnyDocNodeJSON, type DocNodeJSON, node } from './CommentNode.js';
|
||||
import { createCommentNode } from '.';
|
||||
|
||||
export interface DocBlockJSON extends DocNodeJSON {
|
||||
content: AnyDocNodeJSON[];
|
||||
tag: DocBlockTagJSON;
|
||||
}
|
||||
|
||||
export function block(block: DocBlock, model: ApiModel, version: string, parentItem?: ApiItem) {
|
||||
return {
|
||||
...node(block),
|
||||
content: block.content.nodes.map((node) => createCommentNode(node, model, version, parentItem)),
|
||||
tag: blockTag(block.blockTag),
|
||||
};
|
||||
}
|
||||
13
packages/api-extractor-utils/src/tsdoc/CommentBlockTag.ts
Normal file
13
packages/api-extractor-utils/src/tsdoc/CommentBlockTag.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { DocBlockTag } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocBlockTagJSON extends DocNodeJSON {
|
||||
tagName: string;
|
||||
}
|
||||
|
||||
export function blockTag(blockTag: DocBlockTag): DocBlockTagJSON {
|
||||
return {
|
||||
...node(blockTag),
|
||||
tagName: blockTag.tagName,
|
||||
};
|
||||
}
|
||||
13
packages/api-extractor-utils/src/tsdoc/CommentCodeSpan.ts
Normal file
13
packages/api-extractor-utils/src/tsdoc/CommentCodeSpan.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { DocCodeSpan } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocCodeSpanJSON extends DocNodeJSON {
|
||||
code: string;
|
||||
}
|
||||
|
||||
export function codeSpan(codeSpan: DocCodeSpan): DocCodeSpanJSON {
|
||||
return {
|
||||
...node(codeSpan),
|
||||
code: codeSpan.code,
|
||||
};
|
||||
}
|
||||
28
packages/api-extractor-utils/src/tsdoc/CommentNode.ts
Normal file
28
packages/api-extractor-utils/src/tsdoc/CommentNode.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { DocNode, DocNodeKind } from '@microsoft/tsdoc';
|
||||
import type { DocBlockJSON } from './CommentBlock.js';
|
||||
import type { DocCodeSpanJSON } from './CommentCodeSpan.js';
|
||||
import type { DocNodeContainerJSON } from './CommentNodeContainer.js';
|
||||
import type { DocFencedCodeJSON } from './FencedCodeCommentNode.js';
|
||||
import type { DocLinkTagJSON } from './LinkTagCommentNode.js';
|
||||
import type { DocPlainTextJSON } from './PlainTextCommentNode.js';
|
||||
import type { DocCommentJSON } from './RootComment.js';
|
||||
|
||||
export interface DocNodeJSON {
|
||||
kind: DocNodeKind;
|
||||
}
|
||||
|
||||
export type AnyDocNodeJSON =
|
||||
| DocBlockJSON
|
||||
| DocCodeSpanJSON
|
||||
| DocCommentJSON
|
||||
| DocFencedCodeJSON
|
||||
| DocLinkTagJSON
|
||||
| DocNodeContainerJSON
|
||||
| DocNodeJSON
|
||||
| DocPlainTextJSON;
|
||||
|
||||
export function node(node: DocNode): DocNodeJSON {
|
||||
return {
|
||||
kind: node.kind as DocNodeKind,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocNodeContainer } from '@microsoft/tsdoc';
|
||||
import { type AnyDocNodeJSON, type DocNodeJSON, node } from './CommentNode.js';
|
||||
import { createCommentNode } from '.';
|
||||
|
||||
export interface DocNodeContainerJSON extends DocNodeJSON {
|
||||
nodes: AnyDocNodeJSON[];
|
||||
}
|
||||
|
||||
export function nodeContainer(
|
||||
container: DocNodeContainer,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): DocNodeContainerJSON {
|
||||
return {
|
||||
...node(container),
|
||||
nodes: container.nodes.map((node) => createCommentNode(node, model, version, parentItem)),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { DocFencedCode } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocFencedCodeJSON extends DocNodeJSON {
|
||||
code: string;
|
||||
language: string;
|
||||
}
|
||||
|
||||
export function fencedCode(fencedCode: DocFencedCode) {
|
||||
return {
|
||||
...node(fencedCode),
|
||||
language: fencedCode.language,
|
||||
code: fencedCode.code,
|
||||
};
|
||||
}
|
||||
60
packages/api-extractor-utils/src/tsdoc/LinkTagCommentNode.ts
Normal file
60
packages/api-extractor-utils/src/tsdoc/LinkTagCommentNode.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocDeclarationReference, DocLinkTag } from '@microsoft/tsdoc';
|
||||
import { resolveName, generatePath } from '../parse.js';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
interface LinkTagCodeLink {
|
||||
kind: string;
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface DocLinkTagJSON extends DocNodeJSON {
|
||||
codeDestination: LinkTagCodeLink | null;
|
||||
text: string | null;
|
||||
urlDestination: string | null;
|
||||
}
|
||||
|
||||
export function genLinkToken(
|
||||
model: ApiModel,
|
||||
ref: DocDeclarationReference,
|
||||
context: ApiItem | null,
|
||||
version: string,
|
||||
): LinkTagCodeLink | null {
|
||||
const item = model.resolveDeclarationReference(ref, context ?? undefined).resolvedApiItem ?? null;
|
||||
|
||||
if (!item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
name: resolveName(item),
|
||||
kind: item.kind,
|
||||
path: generatePath(item.getHierarchy(), version),
|
||||
};
|
||||
}
|
||||
|
||||
export function linkTagNode(
|
||||
linkNode: DocLinkTag,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): DocLinkTagJSON {
|
||||
// If we weren't provided a parent object, fallback to the package entrypoint.
|
||||
const packageEntryPoint = linkNode.codeDestination?.importPath
|
||||
? model.getAssociatedPackage()?.findEntryPointsByPath(linkNode.codeDestination.importPath)[0]
|
||||
: null;
|
||||
|
||||
const codeDestination = linkNode.codeDestination
|
||||
? genLinkToken(model, linkNode.codeDestination, parentItem ?? packageEntryPoint ?? null, version)
|
||||
: null;
|
||||
const text = linkNode.linkText ?? null;
|
||||
const urlDestination = linkNode.urlDestination ?? null;
|
||||
|
||||
return {
|
||||
...node(linkNode),
|
||||
text,
|
||||
codeDestination,
|
||||
urlDestination,
|
||||
};
|
||||
}
|
||||
19
packages/api-extractor-utils/src/tsdoc/ParamBlock.ts
Normal file
19
packages/api-extractor-utils/src/tsdoc/ParamBlock.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocParamBlock } from '@microsoft/tsdoc';
|
||||
import { block, type DocBlockJSON } from './CommentBlock.js';
|
||||
|
||||
interface DocParamBlockJSON extends DocBlockJSON {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function paramBlock(
|
||||
paramBlock: DocParamBlock,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): DocParamBlockJSON {
|
||||
return {
|
||||
...block(paramBlock, model, version, parentItem),
|
||||
name: paramBlock.parameterName,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { DocPlainText } from '@microsoft/tsdoc';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
|
||||
export interface DocPlainTextJSON extends DocNodeJSON {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export function plainTextNode(plainTextNode: DocPlainText): DocPlainTextJSON {
|
||||
return {
|
||||
...node(plainTextNode),
|
||||
text: plainTextNode.text,
|
||||
};
|
||||
}
|
||||
24
packages/api-extractor-utils/src/tsdoc/RootComment.ts
Normal file
24
packages/api-extractor-utils/src/tsdoc/RootComment.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { ApiItem, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import type { DocComment } from '@microsoft/tsdoc';
|
||||
import { block, type DocBlockJSON } from './CommentBlock.js';
|
||||
import { type DocNodeJSON, node } from './CommentNode.js';
|
||||
import { createCommentNode } from '.';
|
||||
|
||||
export interface DocCommentJSON extends DocNodeJSON {
|
||||
customBlocks: DocBlockJSON[];
|
||||
deprecated: DocNodeJSON[];
|
||||
remarks: DocNodeJSON[];
|
||||
summary: DocNodeJSON[];
|
||||
}
|
||||
|
||||
export function comment(comment: DocComment, model: ApiModel, version: string, parentItem?: ApiItem): DocCommentJSON {
|
||||
return {
|
||||
...node(comment),
|
||||
summary: comment.summarySection.nodes.map((node) => createCommentNode(node, model, version, parentItem)),
|
||||
remarks:
|
||||
comment.remarksBlock?.content.nodes.map((node) => createCommentNode(node, model, version, parentItem)) ?? [],
|
||||
deprecated:
|
||||
comment.deprecatedBlock?.content.nodes.map((node) => createCommentNode(node, model, version, parentItem)) ?? [],
|
||||
customBlocks: comment.customBlocks.map((_block) => block(_block, model, version, parentItem)),
|
||||
};
|
||||
}
|
||||
62
packages/api-extractor-utils/src/tsdoc/index.ts
Normal file
62
packages/api-extractor-utils/src/tsdoc/index.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { ApiModel, ApiItem } from '@microsoft/api-extractor-model';
|
||||
import {
|
||||
type DocNode,
|
||||
type DocPlainText,
|
||||
type DocLinkTag,
|
||||
type DocParagraph,
|
||||
type DocFencedCode,
|
||||
DocNodeKind,
|
||||
type DocBlock,
|
||||
type DocComment,
|
||||
type DocCodeSpan,
|
||||
type DocParamBlock,
|
||||
} from '@microsoft/tsdoc';
|
||||
import { block } from './CommentBlock.js';
|
||||
import { codeSpan } from './CommentCodeSpan.js';
|
||||
import { node as _node, type AnyDocNodeJSON } from './CommentNode.js';
|
||||
import { nodeContainer } from './CommentNodeContainer.js';
|
||||
import { fencedCode } from './FencedCodeCommentNode.js';
|
||||
import { linkTagNode } from './LinkTagCommentNode.js';
|
||||
import { paramBlock } from './ParamBlock.js';
|
||||
import { plainTextNode } from './PlainTextCommentNode.js';
|
||||
import { comment } from './RootComment.js';
|
||||
|
||||
export function createCommentNode(
|
||||
node: DocNode,
|
||||
model: ApiModel,
|
||||
version: string,
|
||||
parentItem?: ApiItem,
|
||||
): AnyDocNodeJSON {
|
||||
switch (node.kind) {
|
||||
case DocNodeKind.PlainText:
|
||||
return plainTextNode(node as DocPlainText);
|
||||
case DocNodeKind.LinkTag:
|
||||
return linkTagNode(node as DocLinkTag, model, version, parentItem);
|
||||
case DocNodeKind.Paragraph:
|
||||
case DocNodeKind.Section:
|
||||
return nodeContainer(node as DocParagraph, model, version, parentItem);
|
||||
case DocNodeKind.FencedCode:
|
||||
return fencedCode(node as DocFencedCode);
|
||||
case DocNodeKind.CodeSpan:
|
||||
return codeSpan(node as DocCodeSpan);
|
||||
case DocNodeKind.Block:
|
||||
return block(node as DocBlock, model, version, parentItem);
|
||||
case DocNodeKind.ParamBlock:
|
||||
return paramBlock(node as DocParamBlock, model, version, parentItem);
|
||||
case DocNodeKind.Comment:
|
||||
return comment(node as DocComment, model, version, parentItem);
|
||||
default:
|
||||
return _node(node);
|
||||
}
|
||||
}
|
||||
|
||||
export * from './CommentNode.js';
|
||||
export * from './CommentNodeContainer.js';
|
||||
export * from './CommentBlock.js';
|
||||
export * from './CommentBlockTag.js';
|
||||
export * from './CommentCodeSpan.js';
|
||||
export * from './FencedCodeCommentNode.js';
|
||||
export * from './LinkTagCommentNode.js';
|
||||
export * from './ParamBlock.js';
|
||||
export * from './PlainTextCommentNode.js';
|
||||
export * from './RootComment.js';
|
||||
20
packages/api-extractor-utils/tsconfig.eslint.json
Normal file
20
packages/api-extractor-utils/tsconfig.eslint.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.mjs",
|
||||
"**/*.jsx",
|
||||
"**/*.test.ts",
|
||||
"**/*.test.js",
|
||||
"**/*.test.mjs",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.js",
|
||||
"**/*.spec.mjs"
|
||||
],
|
||||
"exclude": []
|
||||
}
|
||||
8
packages/api-extractor-utils/tsconfig.json
Normal file
8
packages/api-extractor-utils/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"skipDefaultLibCheck": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
5
packages/api-extractor-utils/tsup.config.js
Normal file
5
packages/api-extractor-utils/tsup.config.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createTsupConfig } from '../../tsup.config.js';
|
||||
|
||||
export default createTsupConfig({
|
||||
minify: true,
|
||||
});
|
||||
5
packages/builders/.cliff-jumperrc.json
Normal file
5
packages/builders/.cliff-jumperrc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "builders",
|
||||
"org": "discordjs",
|
||||
"packagePath": "packages/builders"
|
||||
}
|
||||
@@ -1,12 +1,3 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": "marine/prettier/node",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.eslint.json",
|
||||
"extraFileExtensions": [".mjs"]
|
||||
},
|
||||
"ignorePatterns": ["**/dist/*"],
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
"extends": "../../.eslintrc.json"
|
||||
}
|
||||
|
||||
5
packages/builders/.gitignore
vendored
5
packages/builders/.gitignore
vendored
@@ -17,9 +17,12 @@ pids
|
||||
# Dist
|
||||
dist/
|
||||
typings/
|
||||
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/index.json
|
||||
!docs/README.md
|
||||
!docs/examples/
|
||||
!docs/examples/*.md
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
|
||||
1
packages/builders/.lintstagedrc.js
Normal file
1
packages/builders/.lintstagedrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.lintstagedrc.json');
|
||||
@@ -5,4 +5,4 @@ dist/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
coverage/
|
||||
coverage/
|
||||
1
packages/builders/.prettierrc.js
Normal file
1
packages/builders/.prettierrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('../../.prettierrc.json');
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"releaseCommitMessageFormat": "chore(Release): publish"
|
||||
}
|
||||
@@ -2,7 +2,162 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [0.12.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.11.0...@discordjs/builders@0.12.0) (2021-12-08)
|
||||
# [@discordjs/builders@1.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.1.0...@discordjs/builders@1.2.0) - (2022-08-22)
|
||||
|
||||
## Features
|
||||
|
||||
- **website:** Show `constructor` information (#8540) ([e42fd16](https://github.com/discordjs/discord.js/commit/e42fd1636973b10dd7ed6fb4280ee1a4a8f82007))
|
||||
- **website:** Show descriptions for `@typeParam` blocks (#8523) ([e475b63](https://github.com/discordjs/discord.js/commit/e475b63f257f6261d73cb89fee9ecbcdd84e2a6b))
|
||||
- **website:** Show parameter descriptions (#8519) ([7f415a2](https://github.com/discordjs/discord.js/commit/7f415a2502bf7ce2025dbcfed9017b0635a19966))
|
||||
- **WebSocketShard:** Support new resume url (#8480) ([bc06cc6](https://github.com/discordjs/discord.js/commit/bc06cc638d2f57ab5c600e8cdb6afc8eb2180166))
|
||||
|
||||
## Refactor
|
||||
|
||||
- Docs design (#8487) ([4ab1d09](https://github.com/discordjs/discord.js/commit/4ab1d09997a18879a9eb9bda39df6f15aa22557e))
|
||||
|
||||
# [@discordjs/builders@1.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@1.0.0...@discordjs/builders@1.1.0) - (2022-07-29)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- Use proper format for `@link` text (#8384) ([2655639](https://github.com/discordjs/discord.js/commit/26556390a3800e954974a00c1328ff47d3e67e9a))
|
||||
- **Formatters:** Add newline in `codeBlock` (#8369) ([5d8bd03](https://github.com/discordjs/discord.js/commit/5d8bd030d60ef364de3ef5f9963da8bda5c4efd4))
|
||||
- **selectMenu:** Allow json to be used for select menu options (#8322) ([6a2d0d8](https://github.com/discordjs/discord.js/commit/6a2d0d8e96d157d5b85cee7f17bffdfff4240074))
|
||||
|
||||
## Documentation
|
||||
|
||||
- Use link tags (#8382) ([5494791](https://github.com/discordjs/discord.js/commit/549479131318c659f86f0eb18578d597e22522d3))
|
||||
|
||||
## Features
|
||||
|
||||
- Add channel & message URL formatters (#8371) ([a7deb8f](https://github.com/discordjs/discord.js/commit/a7deb8f89830ead6185c5fb46a49688b6d209ed1))
|
||||
|
||||
# [@discordjs/builders@1.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.16.0...@discordjs/builders@1.0.0) - (2022-07-17)
|
||||
|
||||
## Info
|
||||
|
||||
- 1.0.0 release bump, no new features.
|
||||
|
||||
# [@discordjs/builders@0.16.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.15.0...@discordjs/builders@0.16.0) - (2022-07-17)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- Slash command name regex (#8265) ([32f9056](https://github.com/discordjs/discord.js/commit/32f9056b15edede3bab07de96afb4b56d3a9ecca))
|
||||
- **TextInputBuilder:** Parse `custom_id`, `label`, and `style` (#8216) ([2d9dfa3](https://github.com/discordjs/discord.js/commit/2d9dfa3c6ea4bb972da2f7e088d148b798c866d9))
|
||||
|
||||
## Documentation
|
||||
|
||||
- Add codecov coverage badge to readmes (#8226) ([f6db285](https://github.com/discordjs/discord.js/commit/f6db285c073898a749fe4591cbd4463d1896daf5))
|
||||
|
||||
## Features
|
||||
|
||||
- **builder:** Add max min length in string option (#8214) ([96c8d21](https://github.com/discordjs/discord.js/commit/96c8d21f95eb366c46ae23505ba9054f44821b25))
|
||||
- Codecov (#8219) ([f10f4cd](https://github.com/discordjs/discord.js/commit/f10f4cdcd88ca6be7ec735ed3a415ba13da83db0))
|
||||
- **docgen:** Update typedoc ([b3346f4](https://github.com/discordjs/discord.js/commit/b3346f4b9b3d4f96443506643d4631dc1c6d7b21))
|
||||
- Website (#8043) ([127931d](https://github.com/discordjs/discord.js/commit/127931d1df7a2a5c27923c2f2151dbf3824e50cc))
|
||||
- **docgen:** Typescript support ([3279b40](https://github.com/discordjs/discord.js/commit/3279b40912e6aa61507bedb7db15a2b8668de44b))
|
||||
- Docgen package (#8029) ([8b979c0](https://github.com/discordjs/discord.js/commit/8b979c0245c42fd824d8e98745ee869f5360fc86))
|
||||
|
||||
## Refactor
|
||||
|
||||
- **builder:** Remove `unsafe*Builder`s (#8074) ([a4d1862](https://github.com/discordjs/discord.js/commit/a4d18629828234f43f03d1bd4851d4b727c6903b))
|
||||
- Remove @sindresorhus/is as it's now esm only (#8133) ([c6f285b](https://github.com/discordjs/discord.js/commit/c6f285b7b089b004776fbeb444fe973a68d158d8))
|
||||
- Move all the config files to root (#8033) ([769ea0b](https://github.com/discordjs/discord.js/commit/769ea0bfe78c4f1d413c6b397c604ffe91e39c6a))
|
||||
|
||||
## Typings
|
||||
|
||||
- Remove expect error (#8242) ([7e6dbaa](https://github.com/discordjs/discord.js/commit/7e6dbaaed900c07d1a04e23bbbf9cd0d1b0501c5))
|
||||
- **builder:** Remove casting (#8241) ([8198da5](https://github.com/discordjs/discord.js/commit/8198da5cd0898e06954615a2287853321e7ebbd4))
|
||||
|
||||
# [@discordjs/builders@0.15.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.14.0...@discordjs/builders@0.15.0) - (2022-06-06)
|
||||
|
||||
## Features
|
||||
|
||||
- Allow builders to accept rest params and arrays (#7874) ([ad75be9](https://github.com/discordjs/discord.js/commit/ad75be9a9cf90c8624495df99b75177e6c24022f))
|
||||
- Use vitest instead of jest for more speed ([8d8e6c0](https://github.com/discordjs/discord.js/commit/8d8e6c03decd7352a2aa180f6e5bc1a13602539b))
|
||||
- Add scripts package for locally used scripts ([f2ae1f9](https://github.com/discordjs/discord.js/commit/f2ae1f9348bfd893332a9060f71a8a5f272a1b8b))
|
||||
|
||||
# [@discordjs/builders@0.15.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.14.0...@discordjs/builders@0.15.0) - (2022-06-05)
|
||||
|
||||
## Features
|
||||
|
||||
- Allow builders to accept rest params and arrays (#7874) ([ad75be9](https://github.com/discordjs/discord.js/commit/ad75be9a9cf90c8624495df99b75177e6c24022f))
|
||||
- Use vitest instead of jest for more speed ([8d8e6c0](https://github.com/discordjs/discord.js/commit/8d8e6c03decd7352a2aa180f6e5bc1a13602539b))
|
||||
- Add scripts package for locally used scripts ([f2ae1f9](https://github.com/discordjs/discord.js/commit/f2ae1f9348bfd893332a9060f71a8a5f272a1b8b))
|
||||
|
||||
# [@discordjs/builders@0.14.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.13.0...@discordjs/builders@0.14.0) - (2022-06-04)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **builders:** Leftover invalid null type ([8a7cd10](https://github.com/discordjs/discord.js/commit/8a7cd10554a2a71cd2fe7f6a177b5f4f43464348))
|
||||
- **SlashCommandBuilder:** Import `Permissions` correctly (#7921) ([7ce641d](https://github.com/discordjs/discord.js/commit/7ce641d33a4af6586d5e7beffbe7d38619dcf1a2))
|
||||
- Add localizations for subcommand builders and option choices (#7862) ([c1b5e73](https://github.com/discordjs/discord.js/commit/c1b5e731daa9cbbfca03a046e47cb1221ee1ed7c))
|
||||
|
||||
## Features
|
||||
|
||||
- Export types from `interactions/slashCommands/mixins` (#7942) ([68d5169](https://github.com/discordjs/discord.js/commit/68d5169f66c96f8fe5be17a1c01cdd5155607ab2))
|
||||
- **builders:** Add new command permissions v2 (#7861) ([de3f157](https://github.com/discordjs/discord.js/commit/de3f1573f07dda294cc0fbb1ca4b659eb2388a12))
|
||||
- **builders:** Improve embed errors and predicates (#7795) ([ec8d87f](https://github.com/discordjs/discord.js/commit/ec8d87f93272cc9987f9613735c0361680c4ed1e))
|
||||
|
||||
## Refactor
|
||||
|
||||
- Use arrays instead of rest parameters for builders (#7759) ([29293d7](https://github.com/discordjs/discord.js/commit/29293d7bbb5ed463e52e5a5853817e5a09cf265b))
|
||||
|
||||
## Styling
|
||||
|
||||
- Cleanup tests and tsup configs ([6b8ef20](https://github.com/discordjs/discord.js/commit/6b8ef20cb3af5b5cfd176dd0aa0a1a1e98551629))
|
||||
|
||||
# [@discordjs/builders@0.13.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.12.0...@discordjs/builders@0.13.0) - (2022-04-17)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- Validate select menu options (#7566) ([b1d63d9](https://github.com/discordjs/discord.js/commit/b1d63d919a61f309ac89f27016b0f148678dac2b))
|
||||
- **SelectMenu:** Set `placeholder` max to 150 (#7538) ([dcd4797](https://github.com/discordjs/discord.js/commit/dcd479767b6ec980a373f2ea1f22754f41661c1e))
|
||||
- Only check `instanceof Component` once (#7546) ([0aa4851](https://github.com/discordjs/discord.js/commit/0aa48516a4e33497e8e8dc50da164a57cdee09d3))
|
||||
- **builders:** Allow negative min/max value of number/integer option (#7484) ([3baa340](https://github.com/discordjs/discord.js/commit/3baa340821b8ecf8a16253bc0917a1033250d7c9))
|
||||
- **components:** SetX should take rest parameters (#7461) ([3617359](https://github.com/discordjs/discord.js/commit/36173590a712f041b087b7882054805a8bd42dae))
|
||||
- Unsafe embed builder field normalization (#7418) ([b936103](https://github.com/discordjs/discord.js/commit/b936103395121cb21a8c616f669ddab1d2efb0f1))
|
||||
- Fix some typos (#7393) ([92a04f4](https://github.com/discordjs/discord.js/commit/92a04f4d98f6c6760214034cc8f5a1eaa78893c7))
|
||||
- **builders:** Make type optional in constructor (#7391) ([4abb28c](https://github.com/discordjs/discord.js/commit/4abb28c0a1256c57a60369a6b8ec9e98c265b489))
|
||||
- Don't create new instances of builders classes (#7343) ([d6b56d0](https://github.com/discordjs/discord.js/commit/d6b56d0080c4c5f8ace731f1e8bcae0c9d3fb5a5))
|
||||
|
||||
## Documentation
|
||||
|
||||
- Completely fix builders example link (#7543) ([1a14c0c](https://github.com/discordjs/discord.js/commit/1a14c0ca562ea173d363a770a0437209f461fd23))
|
||||
- Add slash command builders example, fixes #7338 (#7339) ([3ae6f3c](https://github.com/discordjs/discord.js/commit/3ae6f3c313091151245d6e6b52337b459ecfc765))
|
||||
|
||||
## Features
|
||||
|
||||
- Slash command localization for builders (#7683) ([40b9a1d](https://github.com/discordjs/discord.js/commit/40b9a1d67d0b508ec593e030913acd8161cd17f8))
|
||||
- Add API v10 support (#7477) ([72577c4](https://github.com/discordjs/discord.js/commit/72577c4bfd02524a27afb6ff4aebba9301a690d3))
|
||||
- Add support for module: NodeNext in TS and ESM (#7598) ([8f1986a](https://github.com/discordjs/discord.js/commit/8f1986a6aa98365e09b00e84ad5f9f354ab61f3d))
|
||||
- Add Modals and Text Inputs (#7023) ([ed92015](https://github.com/discordjs/discord.js/commit/ed920156344233241a21b0c0b99736a3a855c23c))
|
||||
- Add missing `v13` component methods (#7466) ([f7257f0](https://github.com/discordjs/discord.js/commit/f7257f07655076eabfe355cb6a53260b39ca9670))
|
||||
- **builders:** Add attachment command option type (#7203) ([ae0f35f](https://github.com/discordjs/discord.js/commit/ae0f35f51d68dfa5a7dc43d161ef9365171debdb))
|
||||
- **components:** Add unsafe message component builders (#7387) ([6b6222b](https://github.com/discordjs/discord.js/commit/6b6222bf513d1ee8cd98fba0ad313def560b864f))
|
||||
- **embed:** Add setFields (#7322) ([bcc5cda](https://github.com/discordjs/discord.js/commit/bcc5cda8a902ddb28c7e3578e0f29b4272832624))
|
||||
|
||||
## Refactor
|
||||
|
||||
- Remove nickname parsing (#7736) ([78a3afc](https://github.com/discordjs/discord.js/commit/78a3afcd7fdac358e06764cc0d675e1215c785f3))
|
||||
- Replace zod with shapeshift (#7547) ([3c0bbac](https://github.com/discordjs/discord.js/commit/3c0bbac82fa9988af4a62ff00c66d149fbe6b921))
|
||||
- Remove store channels (#7634) ([aedddb8](https://github.com/discordjs/discord.js/commit/aedddb875e740e1f1bd77f06ce1b361fd3b7bc36))
|
||||
- Allow builders to accept emoji strings (#7616) ([fb9a9c2](https://github.com/discordjs/discord.js/commit/fb9a9c221121ee1c7986f9c775b77b9691a0ae15))
|
||||
- Don't return builders from API data (#7584) ([549716e](https://github.com/discordjs/discord.js/commit/549716e4fcec89ca81216a6d22aa8e623175e37a))
|
||||
- Remove obsolete builder methods (#7590) ([10607db](https://github.com/discordjs/discord.js/commit/10607dbdafe257c5cbf5b952b7eecec4919e8b4a))
|
||||
- **Embed:** Remove add field (#7522) ([8478d2f](https://github.com/discordjs/discord.js/commit/8478d2f4de9ac013733850cbbc67902f7c5abc55))
|
||||
- Make `data` public in builders (#7486) ([ba31203](https://github.com/discordjs/discord.js/commit/ba31203a0ad96e0a00f8312c397889351e4c5cfd))
|
||||
- **embed:** Remove array support in favor of rest params (#7498) ([b3fa2ec](https://github.com/discordjs/discord.js/commit/b3fa2ece402839008738ad3adce3db958445838d))
|
||||
- **components:** Default set boolean methods to true (#7502) ([b122149](https://github.com/discordjs/discord.js/commit/b12214922cea2f43afbe6b1555a74a3c8e16f798))
|
||||
- Make public builder props getters (#7422) ([e8252ed](https://github.com/discordjs/discord.js/commit/e8252ed3b981a4b7e4013f12efadd2f5d9318d3e))
|
||||
- **builders-methods:** Make methods consistent (#7395) ([f495364](https://github.com/discordjs/discord.js/commit/f4953647ff9f39127978c73bf8a62c08462802ca))
|
||||
- Remove conditional autocomplete option return types (#7396) ([0909824](https://github.com/discordjs/discord.js/commit/09098240bfb13b8afafa4ab549f06d236e0ff1c9))
|
||||
- **embed:** Mark properties as readonly (#7332) ([31768fc](https://github.com/discordjs/discord.js/commit/31768fcd69ed5b4566a340bda89ce881418e8272))
|
||||
|
||||
## Typings
|
||||
|
||||
- Fix regressions (#7649) ([5748dbe](https://github.com/discordjs/discord.js/commit/5748dbe08783beb80c526de38ccd105eb0e82664))
|
||||
|
||||
# [@discordjs/builders@0.12.0](https://github.com/discordjs/discord.js/compare/@discordjs/builders@0.11.0...@discordjs/builders@0.12.0) - (2022-01-24)
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
<a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<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/builders"><img src="https://codecov.io/gh/discordjs/builders/branch/main/graph/badge.svg" alt="Code coverage" /></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>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -27,14 +30,14 @@ pnpm add @discordjs/builders
|
||||
|
||||
Here are some examples for the builders and utilities you can find in this package:
|
||||
|
||||
- [Slash Command Builders](./docs/examples/Slash%20Command%20Builders.md)
|
||||
- [Slash Command Builders](https://github.com/discordjs/discord.js/blob/main/packages/builders/docs/examples/Slash%20Command%20Builders.md)
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/discord.js/tree/main/packages/website))
|
||||
- [Documentation](https://discord.js.org/#/docs/builders)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v13.html), including updated and removed items in the library.
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v14.html), including updated and removed items in the library.
|
||||
- [discord.js Discord server](https://discord.gg/djs)
|
||||
- [Discord API Discord server](https://discord.gg/discord-api)
|
||||
- [GitHub](https://github.com/discordjs/discord.js/tree/main/packages/builders)
|
||||
|
||||
@@ -1,15 +1,63 @@
|
||||
import { APIActionRowComponent, ButtonStyle, ComponentType } from 'discord-api-types/v9';
|
||||
import { ActionRow, ButtonComponent, createComponent, SelectMenuComponent, SelectMenuOption } from '../../src';
|
||||
import {
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
type APIActionRowComponent,
|
||||
type APIMessageActionRowComponent,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
createComponentBuilder,
|
||||
SelectMenuBuilder,
|
||||
SelectMenuOptionBuilder,
|
||||
} from '../../src/index.js';
|
||||
|
||||
const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
type: ComponentType.Button,
|
||||
label: 'test',
|
||||
custom_id: '123',
|
||||
style: ButtonStyle.Primary,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const rowWithSelectMenuData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
type: ComponentType.SelectMenu,
|
||||
custom_id: '1234',
|
||||
options: [
|
||||
{
|
||||
label: 'one',
|
||||
value: 'one',
|
||||
},
|
||||
{
|
||||
label: 'two',
|
||||
value: 'two',
|
||||
},
|
||||
],
|
||||
max_values: 10,
|
||||
min_values: 12,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe('Action Row Components', () => {
|
||||
describe('Assertion Tests', () => {
|
||||
test('GIVEN valid components THEN do not throw', () => {
|
||||
expect(() => new ActionRow().addComponents(new ButtonComponent())).not.toThrowError();
|
||||
expect(() => new ActionRow().setComponents([new ButtonComponent()])).not.toThrowError();
|
||||
expect(() => new ActionRowBuilder().addComponents(new ButtonBuilder())).not.toThrowError();
|
||||
expect(() => new ActionRowBuilder().setComponents(new ButtonBuilder())).not.toThrowError();
|
||||
expect(() => new ActionRowBuilder().addComponents([new ButtonBuilder()])).not.toThrowError();
|
||||
expect(() => new ActionRowBuilder().setComponents([new ButtonBuilder()])).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid JSON input THEN valid JSON output is given', () => {
|
||||
const actionRowData: APIActionRowComponent = {
|
||||
const actionRowData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
@@ -38,14 +86,13 @@ describe('Action Row Components', () => {
|
||||
],
|
||||
};
|
||||
|
||||
expect(new ActionRow(actionRowData).toJSON()).toEqual(actionRowData);
|
||||
expect(new ActionRow().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
|
||||
expect(() => createComponent({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
|
||||
// @ts-expect-error
|
||||
expect(() => createComponent({ type: 42, components: [] })).toThrowError();
|
||||
expect(new ActionRowBuilder(actionRowData).toJSON()).toEqual(actionRowData);
|
||||
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
|
||||
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid builder options THEN valid JSON output is given', () => {
|
||||
const rowWithButtonData: APIActionRowComponent = {
|
||||
const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
@@ -57,7 +104,7 @@ describe('Action Row Components', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const rowWithSelectMenuData: APIActionRowComponent = {
|
||||
const rowWithSelectMenuData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
@@ -79,18 +126,31 @@ describe('Action Row Components', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const button = new ButtonComponent().setLabel('test').setStyle(ButtonStyle.Primary).setCustomId('123');
|
||||
const selectMenu = new SelectMenuComponent()
|
||||
expect(new ActionRowBuilder(rowWithButtonData).toJSON()).toEqual(rowWithButtonData);
|
||||
expect(new ActionRowBuilder(rowWithSelectMenuData).toJSON()).toEqual(rowWithSelectMenuData);
|
||||
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
|
||||
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid builder options THEN valid JSON output is given 2', () => {
|
||||
const button = new ButtonBuilder().setLabel('test').setStyle(ButtonStyle.Primary).setCustomId('123');
|
||||
const selectMenu = new SelectMenuBuilder()
|
||||
.setCustomId('1234')
|
||||
.setMaxValues(10)
|
||||
.setMinValues(12)
|
||||
.setOptions(
|
||||
new SelectMenuOptionBuilder().setLabel('one').setValue('one'),
|
||||
new SelectMenuOptionBuilder().setLabel('two').setValue('two'),
|
||||
)
|
||||
.setOptions([
|
||||
new SelectMenuOption().setLabel('one').setValue('one'),
|
||||
new SelectMenuOption().setLabel('two').setValue('two'),
|
||||
new SelectMenuOptionBuilder().setLabel('one').setValue('one'),
|
||||
new SelectMenuOptionBuilder().setLabel('two').setValue('two'),
|
||||
]);
|
||||
|
||||
expect(new ActionRow().addComponents(button).toJSON()).toEqual(rowWithButtonData);
|
||||
expect(new ActionRow().addComponents(selectMenu).toJSON()).toEqual(rowWithSelectMenuData);
|
||||
expect(new ActionRowBuilder().addComponents(button).toJSON()).toEqual(rowWithButtonData);
|
||||
expect(new ActionRowBuilder().addComponents(selectMenu).toJSON()).toEqual(rowWithSelectMenuData);
|
||||
expect(new ActionRowBuilder().addComponents([button]).toJSON()).toEqual(rowWithButtonData);
|
||||
expect(new ActionRowBuilder().addComponents([selectMenu]).toJSON()).toEqual(rowWithSelectMenuData);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import {
|
||||
APIButtonComponentWithCustomId,
|
||||
APIButtonComponentWithURL,
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
} from 'discord-api-types/v9';
|
||||
import { buttonLabelValidator, buttonStyleValidator } from '../../src/components/Assertions';
|
||||
import { ButtonComponent } from '../../src/components/Button';
|
||||
type APIButtonComponentWithCustomId,
|
||||
type APIButtonComponentWithURL,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { buttonLabelValidator, buttonStyleValidator } from '../../src/components/Assertions.js';
|
||||
import { ButtonBuilder } from '../../src/components/button/Button.js';
|
||||
|
||||
const buttonComponent = () => new ButtonComponent();
|
||||
const buttonComponent = () => new ButtonBuilder();
|
||||
|
||||
const longStr =
|
||||
'looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong';
|
||||
@@ -30,7 +31,7 @@ describe('Button Components', () => {
|
||||
expect(() => buttonStyleValidator.parse(ButtonStyle.Secondary)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid style THEN validator does not throw', () => {
|
||||
test('GIVEN invalid style THEN validator does throw', () => {
|
||||
expect(() => buttonStyleValidator.parse(7)).toThrowError();
|
||||
});
|
||||
|
||||
@@ -70,7 +71,7 @@ describe('Button Components', () => {
|
||||
}).toThrowError();
|
||||
|
||||
expect(() => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid emoji
|
||||
const button = buttonComponent().setEmoji('test');
|
||||
button.toJSON();
|
||||
}).toThrowError();
|
||||
@@ -102,9 +103,9 @@ describe('Button Components', () => {
|
||||
|
||||
expect(() => buttonComponent().setStyle(24)).toThrowError();
|
||||
expect(() => buttonComponent().setLabel(longStr)).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid parameter for disabled
|
||||
expect(() => buttonComponent().setDisabled(0)).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid emoji
|
||||
expect(() => buttonComponent().setEmoji('foo')).toThrowError();
|
||||
|
||||
expect(() => buttonComponent().setURL('foobar')).toThrowError();
|
||||
@@ -119,12 +120,12 @@ describe('Button Components', () => {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
expect(new ButtonComponent(interactionData).toJSON()).toEqual(interactionData);
|
||||
expect(new ButtonBuilder(interactionData).toJSON()).toEqual(interactionData);
|
||||
|
||||
expect(
|
||||
buttonComponent()
|
||||
.setCustomId(interactionData.custom_id)
|
||||
.setLabel(interactionData.label)
|
||||
.setLabel(interactionData.label!)
|
||||
.setStyle(interactionData.style)
|
||||
.setDisabled(interactionData.disabled)
|
||||
.toJSON(),
|
||||
@@ -138,9 +139,9 @@ describe('Button Components', () => {
|
||||
url: 'https://google.com',
|
||||
};
|
||||
|
||||
expect(new ButtonComponent(linkData).toJSON()).toEqual(linkData);
|
||||
expect(new ButtonBuilder(linkData).toJSON()).toEqual(linkData);
|
||||
|
||||
expect(buttonComponent().setLabel(linkData.label).setDisabled(true).setURL(linkData.url));
|
||||
expect(buttonComponent().setLabel(linkData.label!).setDisabled(true).setURL(linkData.url));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
73
packages/builders/__tests__/components/components.test.ts
Normal file
73
packages/builders/__tests__/components/components.test.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
TextInputStyle,
|
||||
type APIButtonComponent,
|
||||
type APIMessageActionRowComponent,
|
||||
type APISelectMenuComponent,
|
||||
type APITextInputComponent,
|
||||
type APIActionRowComponent,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
createComponentBuilder,
|
||||
SelectMenuBuilder,
|
||||
TextInputBuilder,
|
||||
} from '../../src/index.js';
|
||||
|
||||
describe('createComponentBuilder', () => {
|
||||
test.each([ButtonBuilder, SelectMenuBuilder, TextInputBuilder])(
|
||||
'passing an instance of %j should return itself',
|
||||
(Builder) => {
|
||||
const builder = new Builder();
|
||||
expect(createComponentBuilder(builder)).toBe(builder);
|
||||
},
|
||||
);
|
||||
|
||||
test('GIVEN an action row component THEN returns a ActionRowBuilder', () => {
|
||||
const actionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
components: [],
|
||||
type: ComponentType.ActionRow,
|
||||
};
|
||||
|
||||
expect(createComponentBuilder(actionRow)).toBeInstanceOf(ActionRowBuilder);
|
||||
});
|
||||
|
||||
test('GIVEN a button component THEN returns a ButtonBuilder', () => {
|
||||
const button: APIButtonComponent = {
|
||||
custom_id: 'abc',
|
||||
style: ButtonStyle.Primary,
|
||||
type: ComponentType.Button,
|
||||
};
|
||||
|
||||
expect(createComponentBuilder(button)).toBeInstanceOf(ButtonBuilder);
|
||||
});
|
||||
|
||||
test('GIVEN a select menu component THEN returns a SelectMenuBuilder', () => {
|
||||
const selectMenu: APISelectMenuComponent = {
|
||||
custom_id: 'abc',
|
||||
options: [],
|
||||
type: ComponentType.SelectMenu,
|
||||
};
|
||||
|
||||
expect(createComponentBuilder(selectMenu)).toBeInstanceOf(SelectMenuBuilder);
|
||||
});
|
||||
|
||||
test('GIVEN a text input component THEN returns a TextInputBuilder', () => {
|
||||
const textInput: APITextInputComponent = {
|
||||
custom_id: 'abc',
|
||||
label: 'abc',
|
||||
style: TextInputStyle.Short,
|
||||
type: ComponentType.TextInput,
|
||||
};
|
||||
|
||||
expect(createComponentBuilder(textInput)).toBeInstanceOf(TextInputBuilder);
|
||||
});
|
||||
|
||||
test('GIVEN an unknown component type THEN throws error', () => {
|
||||
// @ts-expect-error: Unknown component type
|
||||
expect(() => createComponentBuilder({ type: 'invalid' })).toThrowError();
|
||||
});
|
||||
});
|
||||
@@ -1,21 +1,43 @@
|
||||
import { APISelectMenuComponent, APISelectMenuOption, ComponentType } from 'discord-api-types/v9';
|
||||
import { SelectMenuComponent, SelectMenuOption } from '../../src/index';
|
||||
import { ComponentType, type APISelectMenuComponent, type APISelectMenuOption } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { SelectMenuBuilder, SelectMenuOptionBuilder } from '../../src/index.js';
|
||||
|
||||
const selectMenu = () => new SelectMenuComponent();
|
||||
const selectMenuOption = () => new SelectMenuOption();
|
||||
const selectMenu = () => new SelectMenuBuilder();
|
||||
const selectMenuOption = () => new SelectMenuOptionBuilder();
|
||||
|
||||
const longStr =
|
||||
'looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong';
|
||||
const longStr = 'a'.repeat(256);
|
||||
|
||||
describe('Button Components', () => {
|
||||
const selectMenuOptionData: APISelectMenuOption = {
|
||||
label: 'test',
|
||||
value: 'test',
|
||||
emoji: { name: 'test' },
|
||||
default: true,
|
||||
description: 'test',
|
||||
};
|
||||
|
||||
const selectMenuDataWithoutOptions = {
|
||||
type: ComponentType.SelectMenu,
|
||||
custom_id: 'test',
|
||||
max_values: 10,
|
||||
min_values: 3,
|
||||
disabled: true,
|
||||
placeholder: 'test',
|
||||
} as const;
|
||||
|
||||
const selectMenuData: APISelectMenuComponent = {
|
||||
...selectMenuDataWithoutOptions,
|
||||
options: [selectMenuOptionData],
|
||||
};
|
||||
|
||||
describe('Select Menu Components', () => {
|
||||
describe('Assertion Tests', () => {
|
||||
test('GIVEN valid inputs THEN Select Menu does not throw', () => {
|
||||
expect(() => selectMenu().setCustomId('foo')).not.toThrowError();
|
||||
expect(() => selectMenu().setMaxValues(10)).not.toThrowError();
|
||||
expect(() => selectMenu().setMinValues(3)).not.toThrowError();
|
||||
expect(() => selectMenu().setDisabled(true)).not.toThrowError();
|
||||
expect(() => selectMenu().setDisabled()).not.toThrowError();
|
||||
expect(() => selectMenu().setPlaceholder('description')).not.toThrowError();
|
||||
|
||||
const option = selectMenuOption()
|
||||
.setLabel('test')
|
||||
.setValue('test')
|
||||
@@ -23,50 +45,136 @@ describe('Button Components', () => {
|
||||
.setEmoji({ name: 'test' })
|
||||
.setDescription('description');
|
||||
expect(() => selectMenu().addOptions(option)).not.toThrowError();
|
||||
expect(() => selectMenu().setOptions(option)).not.toThrowError();
|
||||
expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError();
|
||||
expect(() => selectMenu().addOptions([option])).not.toThrowError();
|
||||
expect(() => selectMenu().setOptions([option])).not.toThrowError();
|
||||
expect(() => selectMenu().setOptions([{ label: 'test', value: 'test' }])).not.toThrowError();
|
||||
expect(() =>
|
||||
selectMenu()
|
||||
.addOptions({
|
||||
label: 'test',
|
||||
value: 'test',
|
||||
emoji: {
|
||||
id: '123',
|
||||
name: 'test',
|
||||
animated: true,
|
||||
},
|
||||
})
|
||||
.addOptions([
|
||||
{
|
||||
label: 'test',
|
||||
value: 'test',
|
||||
emoji: {
|
||||
id: '123',
|
||||
name: 'test',
|
||||
animated: true,
|
||||
},
|
||||
},
|
||||
]),
|
||||
).not.toThrowError();
|
||||
|
||||
const options = Array.from<APISelectMenuOption>({ length: 25 }).fill({ label: 'test', value: 'test' });
|
||||
|
||||
expect(() => selectMenu().addOptions(...options)).not.toThrowError();
|
||||
expect(() => selectMenu().setOptions(...options)).not.toThrowError();
|
||||
expect(() => selectMenu().addOptions(options)).not.toThrowError();
|
||||
expect(() => selectMenu().setOptions(options)).not.toThrowError();
|
||||
|
||||
expect(() =>
|
||||
selectMenu()
|
||||
.addOptions({ label: 'test', value: 'test' })
|
||||
|
||||
.addOptions(...Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' })),
|
||||
).not.toThrowError();
|
||||
expect(() =>
|
||||
selectMenu()
|
||||
.addOptions([{ label: 'test', value: 'test' }])
|
||||
.addOptions(Array.from<APISelectMenuOption>({ length: 24 }).fill({ label: 'test', value: 'test' })),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid inputs THEN Select Menu does throw', () => {
|
||||
expect(() => selectMenu().setCustomId(longStr)).toThrowError();
|
||||
expect(() => selectMenu().setMaxValues(30)).toThrowError();
|
||||
expect(() => selectMenu().setMinValues(-20)).toThrowError();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid disabled value
|
||||
expect(() => selectMenu().setDisabled(0)).toThrowError();
|
||||
expect(() => selectMenu().setPlaceholder(longStr)).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ label: 'test' })).toThrowError();
|
||||
expect(() => selectMenu().addOptions({ label: longStr, value: 'test' })).toThrowError();
|
||||
expect(() => selectMenu().addOptions({ value: longStr, label: 'test' })).toThrowError();
|
||||
expect(() => selectMenu().addOptions({ label: 'test', value: 'test', description: longStr })).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ label: 'test', value: 'test', default: 100 })).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ value: 'test' })).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions({ default: true })).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ label: 'test' }])).toThrowError();
|
||||
expect(() => selectMenu().addOptions([{ label: longStr, value: 'test' }])).toThrowError();
|
||||
expect(() => selectMenu().addOptions([{ value: longStr, label: 'test' }])).toThrowError();
|
||||
expect(() => selectMenu().addOptions([{ label: 'test', value: 'test', description: longStr }])).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ label: 'test', value: 'test', default: 100 }])).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ value: 'test' }])).toThrowError();
|
||||
// @ts-expect-error: Invalid option
|
||||
expect(() => selectMenu().addOptions([{ default: true }])).toThrowError();
|
||||
|
||||
const tooManyOptions = Array.from<APISelectMenuOption>({ length: 26 }).fill({ label: 'test', value: 'test' });
|
||||
|
||||
expect(() => selectMenu().setOptions(...tooManyOptions)).toThrowError();
|
||||
expect(() => selectMenu().setOptions(tooManyOptions)).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
selectMenu()
|
||||
.addOptions({ label: 'test', value: 'test' })
|
||||
.addOptions(...tooManyOptions),
|
||||
).toThrowError();
|
||||
expect(() =>
|
||||
selectMenu()
|
||||
.addOptions([{ label: 'test', value: 'test' }])
|
||||
.addOptions(tooManyOptions),
|
||||
).toThrowError();
|
||||
|
||||
expect(() => {
|
||||
selectMenuOption()
|
||||
.setLabel(longStr)
|
||||
.setValue(longStr)
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid default value
|
||||
.setDefault(-1)
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid emoji
|
||||
.setEmoji({ name: 1 })
|
||||
.setDescription(longStr);
|
||||
}).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid option types THEN does not throw', () => {
|
||||
expect(() =>
|
||||
selectMenu().addOptions({
|
||||
label: 'test',
|
||||
value: 'test',
|
||||
}),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() => selectMenu().addOptions(selectMenuOption().setLabel('test').setValue('test'))).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid JSON input THEN valid JSON history is correct', () => {
|
||||
const selectMenuOptionData: APISelectMenuOption = {
|
||||
label: 'test',
|
||||
value: 'test',
|
||||
emoji: { name: 'test' },
|
||||
default: true,
|
||||
description: 'test',
|
||||
};
|
||||
|
||||
const selectMenuData: APISelectMenuComponent = {
|
||||
type: ComponentType.SelectMenu,
|
||||
custom_id: 'test',
|
||||
max_values: 10,
|
||||
min_values: 3,
|
||||
disabled: true,
|
||||
options: [selectMenuOptionData],
|
||||
placeholder: 'test',
|
||||
};
|
||||
|
||||
expect(new SelectMenuComponent(selectMenuData).toJSON()).toEqual(selectMenuData);
|
||||
expect(new SelectMenuOption(selectMenuOptionData).toJSON()).toEqual(selectMenuOptionData);
|
||||
expect(
|
||||
new SelectMenuBuilder(selectMenuDataWithoutOptions)
|
||||
.addOptions(new SelectMenuOptionBuilder(selectMenuOptionData))
|
||||
.toJSON(),
|
||||
).toEqual(selectMenuData);
|
||||
expect(
|
||||
new SelectMenuBuilder(selectMenuDataWithoutOptions)
|
||||
.addOptions([new SelectMenuOptionBuilder(selectMenuOptionData)])
|
||||
.toJSON(),
|
||||
).toEqual(selectMenuData);
|
||||
expect(new SelectMenuOptionBuilder(selectMenuOptionData).toJSON()).toEqual(selectMenuOptionData);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
133
packages/builders/__tests__/components/textInput.test.ts
Normal file
133
packages/builders/__tests__/components/textInput.test.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import { ComponentType, TextInputStyle, type APITextInputComponent } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
labelValidator,
|
||||
maxLengthValidator,
|
||||
minLengthValidator,
|
||||
placeholderValidator,
|
||||
valueValidator,
|
||||
textInputStyleValidator,
|
||||
} from '../../src/components/textInput/Assertions.js';
|
||||
import { TextInputBuilder } from '../../src/components/textInput/TextInput.js';
|
||||
|
||||
const superLongStr = 'a'.repeat(5_000);
|
||||
|
||||
const textInputComponent = () => new TextInputBuilder();
|
||||
|
||||
describe('Text Input Components', () => {
|
||||
describe('Assertion Tests', () => {
|
||||
test('GIVEN valid label THEN validator does not throw', () => {
|
||||
expect(() => labelValidator.parse('foobar')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid label THEN validator does throw', () => {
|
||||
expect(() => labelValidator.parse(24)).toThrowError();
|
||||
expect(() => labelValidator.parse(undefined)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid style THEN validator does not throw', () => {
|
||||
expect(() => textInputStyleValidator.parse(TextInputStyle.Paragraph)).not.toThrowError();
|
||||
expect(() => textInputStyleValidator.parse(TextInputStyle.Short)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid style THEN validator does throw', () => {
|
||||
expect(() => textInputStyleValidator.parse(24)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid min length THEN validator does not throw', () => {
|
||||
expect(() => minLengthValidator.parse(10)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid min length THEN validator does throw', () => {
|
||||
expect(() => minLengthValidator.parse(-1)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid max length THEN validator does not throw', () => {
|
||||
expect(() => maxLengthValidator.parse(10)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid min length THEN validator does throw 2', () => {
|
||||
expect(() => maxLengthValidator.parse(4_001)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid value THEN validator does not throw', () => {
|
||||
expect(() => valueValidator.parse('foobar')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid value THEN validator does throw', () => {
|
||||
expect(() => valueValidator.parse(superLongStr)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid placeholder THEN validator does not throw', () => {
|
||||
expect(() => placeholderValidator.parse('foobar')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid value THEN validator does throw 2', () => {
|
||||
expect(() => placeholderValidator.parse(superLongStr)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid fields THEN builder does not throw', () => {
|
||||
expect(() => {
|
||||
textInputComponent().setCustomId('foobar').setLabel('test').setStyle(TextInputStyle.Paragraph).toJSON();
|
||||
}).not.toThrowError();
|
||||
|
||||
expect(() => {
|
||||
textInputComponent()
|
||||
.setCustomId('foobar')
|
||||
.setLabel('test')
|
||||
.setMaxLength(100)
|
||||
.setMinLength(1)
|
||||
.setPlaceholder('bar')
|
||||
.setRequired(true)
|
||||
.setStyle(TextInputStyle.Paragraph)
|
||||
.toJSON();
|
||||
}).not.toThrowError();
|
||||
|
||||
expect(() => {
|
||||
// Issue #8107
|
||||
// @ts-expect-error: Shapeshift maps the enum key to the value when parsing
|
||||
textInputComponent().setCustomId('Custom').setLabel('Guess').setStyle('Short').toJSON();
|
||||
}).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN invalid fields THEN builder throws', () => {
|
||||
expect(() => textInputComponent().toJSON()).toThrowError();
|
||||
expect(() => {
|
||||
textInputComponent()
|
||||
.setCustomId('test')
|
||||
.setMaxLength(100)
|
||||
.setPlaceholder('hello')
|
||||
.setStyle(TextInputStyle.Paragraph)
|
||||
.toJSON();
|
||||
}).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid input THEN valid JSON outputs are given', () => {
|
||||
const textInputData: APITextInputComponent = {
|
||||
type: ComponentType.TextInput,
|
||||
label: 'label',
|
||||
custom_id: 'custom id',
|
||||
placeholder: 'placeholder',
|
||||
max_length: 100,
|
||||
min_length: 10,
|
||||
value: 'value',
|
||||
required: false,
|
||||
style: TextInputStyle.Paragraph,
|
||||
};
|
||||
|
||||
expect(new TextInputBuilder(textInputData).toJSON()).toEqual(textInputData);
|
||||
expect(
|
||||
textInputComponent()
|
||||
.setCustomId(textInputData.custom_id)
|
||||
.setLabel(textInputData.label)
|
||||
.setPlaceholder(textInputData.placeholder!)
|
||||
.setMaxLength(textInputData.max_length!)
|
||||
.setMinLength(textInputData.min_length!)
|
||||
.setValue(textInputData.value!)
|
||||
.setRequired(textInputData.required)
|
||||
.setStyle(textInputData.style)
|
||||
.toJSON(),
|
||||
).toEqual(textInputData);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,6 @@
|
||||
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index';
|
||||
import { PermissionFlagsBits } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index.js';
|
||||
|
||||
const getBuilder = () => new ContextMenuCommandBuilder();
|
||||
|
||||
@@ -84,6 +86,63 @@ describe('Context Menu Commands', () => {
|
||||
test('GIVEN valid builder with defaultPermission false THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('foo').setDefaultPermission(false)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid builder with dmPermission false THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('foo').setDMPermission(false)).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Context menu command localizations', () => {
|
||||
const expectedSingleLocale = { 'en-US': 'foobar' };
|
||||
const expectedMultipleLocales = {
|
||||
...expectedSingleLocale,
|
||||
bg: 'test',
|
||||
};
|
||||
|
||||
test('GIVEN valid name localizations THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setNameLocalization('en-US', 'foobar')).not.toThrowError();
|
||||
expect(() => getBuilder().setNameLocalizations({ 'en-US': 'foobar' })).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid name localizations THEN does throw error', () => {
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalization('en-U', 'foobar')).toThrowError();
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalizations({ 'en-U': 'foobar' })).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid name localizations THEN valid data is stored', () => {
|
||||
expect(getBuilder().setNameLocalization('en-US', 'foobar').name_localizations).toEqual(expectedSingleLocale);
|
||||
expect(getBuilder().setNameLocalizations({ 'en-US': 'foobar', bg: 'test' }).name_localizations).toEqual(
|
||||
expectedMultipleLocales,
|
||||
);
|
||||
expect(getBuilder().setNameLocalizations(null).name_localizations).toBeNull();
|
||||
expect(getBuilder().setNameLocalization('en-US', null).name_localizations).toEqual({
|
||||
'en-US': null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('permissions', () => {
|
||||
test('GIVEN valid permission string THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setDefaultMemberPermissions('1')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid permission bitfield THEN does not throw error', () => {
|
||||
expect(() =>
|
||||
getBuilder().setDefaultMemberPermissions(PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN null permissions THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setDefaultMemberPermissions(null)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid inputs THEN does throw error', () => {
|
||||
expect(() => getBuilder().setDefaultMemberPermissions('1.1')).toThrowError();
|
||||
|
||||
expect(() => getBuilder().setDefaultMemberPermissions(1.1)).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import {
|
||||
APIApplicationCommandBooleanOption,
|
||||
APIApplicationCommandChannelOption,
|
||||
APIApplicationCommandIntegerOption,
|
||||
APIApplicationCommandMentionableOption,
|
||||
APIApplicationCommandNumberOption,
|
||||
APIApplicationCommandRoleOption,
|
||||
APIApplicationCommandStringOption,
|
||||
APIApplicationCommandUserOption,
|
||||
ApplicationCommandOptionType,
|
||||
ChannelType,
|
||||
} from 'discord-api-types/v9';
|
||||
type APIApplicationCommandAttachmentOption,
|
||||
type APIApplicationCommandBooleanOption,
|
||||
type APIApplicationCommandChannelOption,
|
||||
type APIApplicationCommandIntegerOption,
|
||||
type APIApplicationCommandMentionableOption,
|
||||
type APIApplicationCommandNumberOption,
|
||||
type APIApplicationCommandRoleOption,
|
||||
type APIApplicationCommandStringOption,
|
||||
type APIApplicationCommandUserOption,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
SlashCommandAttachmentOption,
|
||||
SlashCommandBooleanOption,
|
||||
SlashCommandChannelOption,
|
||||
SlashCommandIntegerOption,
|
||||
@@ -19,7 +22,7 @@ import {
|
||||
SlashCommandRoleOption,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandUserOption,
|
||||
} from '../../../src/index';
|
||||
} from '../../../src/index.js';
|
||||
|
||||
const getBooleanOption = () =>
|
||||
new SlashCommandBooleanOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
@@ -29,7 +32,7 @@ const getChannelOption = () =>
|
||||
.setName('owo')
|
||||
.setDescription('Testing 123')
|
||||
.setRequired(true)
|
||||
.addChannelType(ChannelType.GuildText);
|
||||
.addChannelTypes(ChannelType.GuildText);
|
||||
|
||||
const getStringOption = () =>
|
||||
new SlashCommandStringOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
@@ -39,7 +42,7 @@ const getIntegerOption = () =>
|
||||
.setName('owo')
|
||||
.setDescription('Testing 123')
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
.setMinValue(-1)
|
||||
.setMaxValue(10);
|
||||
|
||||
const getNumberOption = () =>
|
||||
@@ -47,7 +50,7 @@ const getNumberOption = () =>
|
||||
.setName('owo')
|
||||
.setDescription('Testing 123')
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
.setMinValue(-1.23)
|
||||
.setMaxValue(10);
|
||||
|
||||
const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
@@ -57,6 +60,9 @@ const getRoleOption = () => new SlashCommandRoleOption().setName('owo').setDescr
|
||||
const getMentionableOption = () =>
|
||||
new SlashCommandMentionableOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
|
||||
const getAttachmentOption = () =>
|
||||
new SlashCommandAttachmentOption().setName('attachment').setDescription('attachment').setRequired(true);
|
||||
|
||||
describe('Application Command toJSON() results', () => {
|
||||
test('GIVEN a boolean option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getBooleanOption().toJSON()).toEqual<APIApplicationCommandBooleanOption>({
|
||||
@@ -84,30 +90,31 @@ describe('Application Command toJSON() results', () => {
|
||||
type: ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
min_value: -1,
|
||||
});
|
||||
|
||||
expect(getIntegerOption().setAutocomplete(true).setChoices().toJSON()).toEqual<APIApplicationCommandIntegerOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: -1,
|
||||
autocomplete: true,
|
||||
// TODO
|
||||
// @ts-expect-error You *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
expect(
|
||||
getIntegerOption().setAutocomplete(true).setChoices([]).toJSON(),
|
||||
getIntegerOption().addChoices({ name: 'uwu', value: 1 }).toJSON(),
|
||||
).toEqual<APIApplicationCommandIntegerOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
expect(getIntegerOption().addChoice('uwu', 1).toJSON()).toEqual<APIApplicationCommandIntegerOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
min_value: -1,
|
||||
choices: [{ name: 'uwu', value: 1 }],
|
||||
});
|
||||
});
|
||||
@@ -128,30 +135,33 @@ describe('Application Command toJSON() results', () => {
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
min_value: -1.23,
|
||||
});
|
||||
|
||||
expect(getNumberOption().setAutocomplete(true).setChoices([]).toJSON()).toEqual<APIApplicationCommandNumberOption>({
|
||||
expect(getNumberOption().setAutocomplete(true).setChoices().toJSON()).toEqual<APIApplicationCommandNumberOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
min_value: -1.23,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
// TODO
|
||||
// @ts-expect-error You *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
expect(getNumberOption().addChoice('uwu', 1).toJSON()).toEqual<APIApplicationCommandNumberOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
choices: [{ name: 'uwu', value: 1 }],
|
||||
});
|
||||
expect(getNumberOption().addChoices({ name: 'uwu', value: 1 }).toJSON()).toEqual<APIApplicationCommandNumberOption>(
|
||||
{
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: -1.23,
|
||||
choices: [{ name: 'uwu', value: 1 }],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN a role option THEN calling toJSON should return a valid JSON', () => {
|
||||
@@ -164,24 +174,29 @@ describe('Application Command toJSON() results', () => {
|
||||
});
|
||||
|
||||
test('GIVEN a string option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getStringOption().toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
expect(getStringOption().setMinLength(1).setMaxLength(10).toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
max_length: 10,
|
||||
min_length: 1,
|
||||
});
|
||||
|
||||
expect(getStringOption().setAutocomplete(true).setChoices([]).toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
expect(getStringOption().setAutocomplete(true).setChoices().toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
// TODO
|
||||
// @ts-expect-error you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
expect(getStringOption().addChoice('uwu', '1').toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
expect(
|
||||
getStringOption().addChoices({ name: 'uwu', value: '1' }).toJSON(),
|
||||
).toEqual<APIApplicationCommandStringOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
@@ -198,4 +213,13 @@ describe('Application Command toJSON() results', () => {
|
||||
required: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an attachment option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getAttachmentOption().toJSON()).toEqual<APIApplicationCommandAttachmentOption>({
|
||||
name: 'attachment',
|
||||
description: 'attachment',
|
||||
type: ApplicationCommandOptionType.Attachment,
|
||||
required: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { APIApplicationCommandOptionChoice, ChannelType } from 'discord-api-types/v9';
|
||||
import { ChannelType, PermissionFlagsBits, type APIApplicationCommandOptionChoice } from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
SlashCommandAssertions,
|
||||
SlashCommandBooleanOption,
|
||||
@@ -8,11 +9,12 @@ import {
|
||||
SlashCommandMentionableOption,
|
||||
SlashCommandNumberOption,
|
||||
SlashCommandRoleOption,
|
||||
SlashCommandAttachmentOption,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
SlashCommandUserOption,
|
||||
} from '../../../src/index';
|
||||
} from '../../../src/index.js';
|
||||
|
||||
const largeArray = Array.from({ length: 26 }, () => 1 as unknown as APIApplicationCommandOptionChoice);
|
||||
|
||||
@@ -25,20 +27,21 @@ const getBooleanOption = () => new SlashCommandBooleanOption().setName('owo').se
|
||||
const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123');
|
||||
const getChannelOption = () => new SlashCommandChannelOption().setName('owo').setDescription('Testing 123');
|
||||
const getRoleOption = () => new SlashCommandRoleOption().setName('owo').setDescription('Testing 123');
|
||||
const getAttachmentOption = () => new SlashCommandAttachmentOption().setName('owo').setDescription('Testing 123');
|
||||
const getMentionableOption = () => new SlashCommandMentionableOption().setName('owo').setDescription('Testing 123');
|
||||
const getSubcommandGroup = () => new SlashCommandSubcommandGroupBuilder().setName('owo').setDescription('Testing 123');
|
||||
const getSubcommand = () => new SlashCommandSubcommandBuilder().setName('owo').setDescription('Testing 123');
|
||||
|
||||
class Collection {
|
||||
public get [Symbol.toStringTag]() {
|
||||
return 'Map';
|
||||
}
|
||||
public readonly [Symbol.toStringTag] = 'Map';
|
||||
}
|
||||
|
||||
describe('Slash Commands', () => {
|
||||
describe('Assertions tests', () => {
|
||||
test('GIVEN valid name THEN does not throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateName('ping')).not.toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateName('hello-world_command')).not.toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateName('aˇ㐆1٢〣²अก')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid name THEN throw error', () => {
|
||||
@@ -48,7 +51,10 @@ describe('Slash Commands', () => {
|
||||
expect(() => SlashCommandAssertions.validateName('')).toThrowError();
|
||||
|
||||
// Invalid characters used
|
||||
expect(() => SlashCommandAssertions.validateName('ABC')).toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateName('ABC123$%^&')).toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateName('help ping')).toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateName('🦦')).toThrowError();
|
||||
|
||||
// Too long of a name
|
||||
expect(() =>
|
||||
@@ -85,18 +91,17 @@ describe('Slash Commands', () => {
|
||||
test('GIVEN valid array of options or choices THEN does not throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateMaxOptionsLength([])).not.toThrowError();
|
||||
|
||||
expect(() => SlashCommandAssertions.validateMaxChoicesLength([])).not.toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateChoicesLength(25)).not.toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateChoicesLength(25, [])).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid options or choices THEN throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateMaxOptionsLength(null)).toThrowError();
|
||||
|
||||
expect(() => SlashCommandAssertions.validateMaxChoicesLength(null)).toThrowError();
|
||||
|
||||
// Given an array that's too big
|
||||
expect(() => SlashCommandAssertions.validateMaxOptionsLength(largeArray)).toThrowError();
|
||||
|
||||
expect(() => SlashCommandAssertions.validateMaxChoicesLength(largeArray)).toThrowError();
|
||||
expect(() => SlashCommandAssertions.validateChoicesLength(1, largeArray)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid required parameters THEN does not throw error', () => {
|
||||
@@ -127,6 +132,7 @@ describe('Slash Commands', () => {
|
||||
getBuilder()
|
||||
.setName('example')
|
||||
.setDescription('Example command')
|
||||
.setDMPermission(false)
|
||||
.addBooleanOption((boolean) =>
|
||||
boolean.setName('iscool').setDescription('Are we cool or what?').setRequired(true),
|
||||
)
|
||||
@@ -138,23 +144,23 @@ describe('Slash Commands', () => {
|
||||
integer
|
||||
.setName('iscool')
|
||||
.setDescription('Are we cool or what?')
|
||||
.addChoices([['Very cool', 1_000]]),
|
||||
.addChoices({ name: 'Very cool', value: 1_000 }),
|
||||
)
|
||||
.addNumberOption((number) =>
|
||||
number
|
||||
.setName('iscool')
|
||||
.setDescription('Are we cool or what?')
|
||||
.addChoices([['Very cool', 1.5]]),
|
||||
.addChoices({ name: 'Very cool', value: 1.5 }),
|
||||
)
|
||||
.addStringOption((string) =>
|
||||
string
|
||||
.setName('iscool')
|
||||
.setDescription('Are we cool or what?')
|
||||
.addChoices([
|
||||
['Fancy Pants', 'fp_1'],
|
||||
['Fancy Shoes', 'fs_1'],
|
||||
['The Whole shebang', 'all'],
|
||||
]),
|
||||
.addChoices(
|
||||
{ name: 'Fancy Pants', value: 'fp_1' },
|
||||
{ name: 'Fancy Shoes', value: 'fs_1' },
|
||||
{ name: 'The Whole shebang', value: 'all' },
|
||||
),
|
||||
)
|
||||
.addIntegerOption((integer) =>
|
||||
integer.setName('iscool').setDescription('Are we cool or what?').setAutocomplete(true),
|
||||
@@ -170,38 +176,32 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid autocomplete THEN does throw an error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addStringOption(getStringOption().setAutocomplete('not a boolean'))).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with both choices and autocomplete THEN does throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
||||
getStringOption().setAutocomplete(true).addChoice('Fancy Pants', 'fp_1'),
|
||||
getStringOption().setAutocomplete(true).addChoices({ name: 'Fancy Pants', value: 'fp_1' }),
|
||||
),
|
||||
).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
||||
getStringOption()
|
||||
.setAutocomplete(true)
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
.addChoices([
|
||||
['Fancy Pants', 'fp_1'],
|
||||
['Fancy Shoes', 'fs_1'],
|
||||
['The Whole shebang', 'all'],
|
||||
]),
|
||||
.addChoices(
|
||||
{ name: 'Fancy Pants', value: 'fp_1' },
|
||||
{ name: 'Fancy Shoes', value: 'fs_1' },
|
||||
{ name: 'The Whole shebang', value: 'all' },
|
||||
),
|
||||
),
|
||||
).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
||||
getStringOption().addChoice('Fancy Pants', 'fp_1').setAutocomplete(true),
|
||||
getStringOption().addChoices({ name: 'Fancy Pants', value: 'fp_1' }).setAutocomplete(true),
|
||||
),
|
||||
).toThrowError();
|
||||
|
||||
@@ -229,33 +229,33 @@ describe('Slash Commands', () => {
|
||||
|
||||
test('GIVEN a builder with valid channel options and channel_types THEN does not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addChannelOption(getChannelOption().addChannelType(ChannelType.GuildText)),
|
||||
getBuilder().addChannelOption(getChannelOption().addChannelTypes(ChannelType.GuildText)),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() => {
|
||||
getBuilder().addChannelOption(
|
||||
getChannelOption().addChannelTypes([ChannelType.GuildNews, ChannelType.GuildText]),
|
||||
getChannelOption().addChannelTypes(ChannelType.GuildAnnouncement, ChannelType.GuildText),
|
||||
);
|
||||
}).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with valid channel options and channel_types THEN does throw an error', () => {
|
||||
expect(() => getBuilder().addChannelOption(getChannelOption().addChannelType(100))).toThrowError();
|
||||
expect(() => getBuilder().addChannelOption(getChannelOption().addChannelTypes(100))).toThrowError();
|
||||
|
||||
expect(() => getBuilder().addChannelOption(getChannelOption().addChannelTypes([100, 200]))).toThrowError();
|
||||
expect(() => getBuilder().addChannelOption(getChannelOption().addChannelTypes(100, 200))).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid number min/max options THEN does throw an error', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid max value
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMaxValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid max value
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMaxValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid min value
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMinValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid min value
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMinValue('test'))).toThrowError();
|
||||
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMinValue(1.5))).toThrowError();
|
||||
@@ -286,14 +286,16 @@ describe('Slash Commands', () => {
|
||||
|
||||
expect(() => getBuilder().addRoleOption(getRoleOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addAttachmentOption(getAttachmentOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addMentionableOption(getMentionableOption())).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN no valid return for an addOption method THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(getRoleOption())).toThrowError();
|
||||
});
|
||||
|
||||
@@ -314,16 +316,18 @@ describe('Slash Commands', () => {
|
||||
});
|
||||
|
||||
test('GIVEN invalid returns for builder THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(true)).toThrowError();
|
||||
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(null)).toThrowError();
|
||||
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(undefined)).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(() => SlashCommandStringOption)).toThrowError();
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(() => new Collection())).toThrowError();
|
||||
});
|
||||
|
||||
@@ -331,24 +335,24 @@ describe('Slash Commands', () => {
|
||||
expect(() => getBuilder().setName('foo').setDescription('foo').setDefaultPermission(false)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an option that is autocompletable and has choices, THEN setting choices to an empty array should not throw an error', () => {
|
||||
test('GIVEN an option that is autocompletable and has choices, THEN passing nothing to setChoices should not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(getStringOption().setAutocomplete(true).setChoices([])),
|
||||
getBuilder().addStringOption(getStringOption().setAutocomplete(true).setChoices()),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an option that is autocompletable, THEN setting choices should throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
getStringOption()
|
||||
.setAutocomplete(true)
|
||||
.setChoices([['owo', 'uwu']]),
|
||||
getStringOption().setAutocomplete(true).setChoices({ name: 'owo', value: 'uwu' }),
|
||||
),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an option, THEN setting choices should not throw an error', () => {
|
||||
expect(() => getBuilder().addStringOption(getStringOption().setChoices([['owo', 'uwu']]))).not.toThrowError();
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(getStringOption().setChoices({ name: 'owo', value: 'uwu' })),
|
||||
).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -367,6 +371,18 @@ describe('Slash Commands', () => {
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with subcommand THEN has regular slash command fields', () => {
|
||||
expect(() =>
|
||||
getBuilder()
|
||||
.setName('name')
|
||||
.setDescription('description')
|
||||
.addSubcommand((option) => option.setName('ye').setDescription('ye'))
|
||||
.addSubcommand((option) => option.setName('no').setDescription('no'))
|
||||
.setDMPermission(false)
|
||||
.setDefaultMemberPermissions(1n),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with already built subcommand group THEN does not throw error', () => {
|
||||
expect(() => getNamedBuilder().addSubcommandGroup(getSubcommandGroup())).not.toThrowError();
|
||||
});
|
||||
@@ -383,30 +399,29 @@ describe('Slash Commands', () => {
|
||||
|
||||
test('GIVEN builder with a subcommand that tries to add an invalid result THEN throw error', () => {
|
||||
expect(() =>
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
||||
// @ts-expect-error: Checking if check works JS-side too
|
||||
getNamedBuilder().addSubcommand(getSubcommand()).addInteger(getInteger()),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN no valid return for an addSubcommand(Group) method THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommandGroup()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommand()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommand(getSubcommandGroup())).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subcommand group builder', () => {
|
||||
test('GIVEN no valid subcommand THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getSubcommandGroup().addSubcommand()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
// @ts-expect-error: Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getSubcommandGroup().addSubcommand(getSubcommandGroup())).toThrowError();
|
||||
});
|
||||
|
||||
@@ -424,5 +439,83 @@ describe('Slash Commands', () => {
|
||||
expect(() => getSubcommand().addBooleanOption(getBooleanOption()).toJSON()).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Slash command localizations', () => {
|
||||
const expectedSingleLocale = { 'en-US': 'foobar' };
|
||||
const expectedMultipleLocales = {
|
||||
...expectedSingleLocale,
|
||||
bg: 'test',
|
||||
};
|
||||
|
||||
test('GIVEN valid name localizations THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setNameLocalization('en-US', 'foobar')).not.toThrowError();
|
||||
expect(() => getBuilder().setNameLocalizations({ 'en-US': 'foobar' })).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid name localizations THEN does throw error', () => {
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalization('en-U', 'foobar')).toThrowError();
|
||||
// @ts-expect-error: Invalid localization
|
||||
expect(() => getBuilder().setNameLocalizations({ 'en-U': 'foobar' })).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid name localizations THEN valid data is stored', () => {
|
||||
expect(getBuilder().setNameLocalization('en-US', 'foobar').name_localizations).toEqual(expectedSingleLocale);
|
||||
expect(getBuilder().setNameLocalizations({ 'en-US': 'foobar', bg: 'test' }).name_localizations).toEqual(
|
||||
expectedMultipleLocales,
|
||||
);
|
||||
expect(getBuilder().setNameLocalizations(null).name_localizations).toBeNull();
|
||||
expect(getBuilder().setNameLocalization('en-US', null).name_localizations).toEqual({
|
||||
'en-US': null,
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN valid description localizations THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setDescriptionLocalization('en-US', 'foobar')).not.toThrowError();
|
||||
expect(() => getBuilder().setDescriptionLocalizations({ 'en-US': 'foobar' })).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid description localizations THEN does throw error', () => {
|
||||
// @ts-expect-error: Invalid localization description
|
||||
expect(() => getBuilder().setDescriptionLocalization('en-U', 'foobar')).toThrowError();
|
||||
// @ts-expect-error: Invalid localization description
|
||||
expect(() => getBuilder().setDescriptionLocalizations({ 'en-U': 'foobar' })).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid description localizations THEN valid data is stored', () => {
|
||||
expect(getBuilder().setDescriptionLocalization('en-US', 'foobar').description_localizations).toEqual(
|
||||
expectedSingleLocale,
|
||||
);
|
||||
expect(
|
||||
getBuilder().setDescriptionLocalizations({ 'en-US': 'foobar', bg: 'test' }).description_localizations,
|
||||
).toEqual(expectedMultipleLocales);
|
||||
expect(getBuilder().setDescriptionLocalizations(null).description_localizations).toBeNull();
|
||||
expect(getBuilder().setDescriptionLocalization('en-US', null).description_localizations).toEqual({
|
||||
'en-US': null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('permissions', () => {
|
||||
test('GIVEN valid permission string THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setDefaultMemberPermissions('1')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid permission bitfield THEN does not throw error', () => {
|
||||
expect(() =>
|
||||
getBuilder().setDefaultMemberPermissions(PermissionFlagsBits.AddReactions | PermissionFlagsBits.AttachFiles),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN null permissions THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setDefaultMemberPermissions(null)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid inputs THEN does throw error', () => {
|
||||
expect(() => getBuilder().setDefaultMemberPermissions('1.1')).toThrowError();
|
||||
|
||||
expect(() => getBuilder().setDefaultMemberPermissions(1.1)).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
173
packages/builders/__tests__/interactions/modal.test.ts
Normal file
173
packages/builders/__tests__/interactions/modal.test.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
import {
|
||||
ComponentType,
|
||||
TextInputStyle,
|
||||
type APIModalInteractionResponseCallbackData,
|
||||
type APITextInputComponent,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ModalBuilder,
|
||||
TextInputBuilder,
|
||||
type ModalActionRowComponentBuilder,
|
||||
} from '../../src/index.js';
|
||||
import {
|
||||
componentsValidator,
|
||||
titleValidator,
|
||||
validateRequiredParameters,
|
||||
} from '../../src/interactions/modals/Assertions.js';
|
||||
|
||||
const modal = () => new ModalBuilder();
|
||||
|
||||
describe('Modals', () => {
|
||||
describe('Assertion Tests', () => {
|
||||
test('GIVEN valid title THEN validator does not throw', () => {
|
||||
expect(() => titleValidator.parse('foobar')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid title THEN validator does throw', () => {
|
||||
expect(() => titleValidator.parse(42)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid components THEN validator does not throw', () => {
|
||||
expect(() => componentsValidator.parse([new ActionRowBuilder(), new ActionRowBuilder()])).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid components THEN validator does throw', () => {
|
||||
expect(() => componentsValidator.parse([new ButtonBuilder(), new TextInputBuilder()])).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid required parameters THEN validator does not throw', () => {
|
||||
expect(() =>
|
||||
validateRequiredParameters('123', 'title', [new ActionRowBuilder(), new ActionRowBuilder()]),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid required parameters THEN validator does throw', () => {
|
||||
expect(() =>
|
||||
// @ts-expect-error: Missing required parameter
|
||||
validateRequiredParameters('123', undefined, [new ActionRowBuilder(), new ButtonBuilder()]),
|
||||
).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN valid fields THEN builder does not throw', () => {
|
||||
expect(() =>
|
||||
modal().setTitle('test').setCustomId('foobar').setComponents(new ActionRowBuilder()),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() =>
|
||||
// @ts-expect-error: You can pass a TextInputBuilder and it will add it to an action row
|
||||
modal().setTitle('test').setCustomId('foobar').addComponents(new TextInputBuilder()),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid fields THEN builder does throw', () => {
|
||||
expect(() => modal().setTitle('test').setCustomId('foobar').toJSON()).toThrowError();
|
||||
|
||||
// @ts-expect-error: CustomId is invalid
|
||||
expect(() => modal().setTitle('test').setCustomId(42).toJSON()).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid input THEN valid JSON outputs are given', () => {
|
||||
const modalData: APIModalInteractionResponseCallbackData = {
|
||||
title: 'title',
|
||||
custom_id: 'custom id',
|
||||
components: [
|
||||
{
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
type: ComponentType.TextInput,
|
||||
label: 'label',
|
||||
style: TextInputStyle.Paragraph,
|
||||
custom_id: 'custom id',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
type: ComponentType.TextInput,
|
||||
label: 'label',
|
||||
style: TextInputStyle.Paragraph,
|
||||
custom_id: 'custom id',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(new ModalBuilder(modalData).toJSON()).toEqual(modalData);
|
||||
|
||||
expect(
|
||||
modal()
|
||||
.setTitle(modalData.title)
|
||||
.setCustomId('custom id')
|
||||
.setComponents(
|
||||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
||||
new TextInputBuilder().setCustomId('custom id').setLabel('label').setStyle(TextInputStyle.Paragraph),
|
||||
),
|
||||
)
|
||||
.addComponents([
|
||||
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
|
||||
new TextInputBuilder().setCustomId('custom id').setLabel('label').setStyle(TextInputStyle.Paragraph),
|
||||
),
|
||||
])
|
||||
.toJSON(),
|
||||
).toEqual(modalData);
|
||||
});
|
||||
|
||||
describe('equals()', () => {
|
||||
const textInput1 = new TextInputBuilder()
|
||||
.setCustomId('custom id')
|
||||
.setLabel('label')
|
||||
.setStyle(TextInputStyle.Paragraph);
|
||||
|
||||
const textInput2: APITextInputComponent = {
|
||||
type: ComponentType.TextInput,
|
||||
custom_id: 'custom id',
|
||||
label: 'label',
|
||||
style: TextInputStyle.Paragraph,
|
||||
};
|
||||
|
||||
test('GIVEN equal builders THEN returns true', () => {
|
||||
const equalTextInput = new TextInputBuilder()
|
||||
.setCustomId('custom id')
|
||||
.setLabel('label')
|
||||
.setStyle(TextInputStyle.Paragraph);
|
||||
|
||||
expect(textInput1.equals(equalTextInput)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('GIVEN the same builder THEN returns true', () => {
|
||||
expect(textInput1.equals(textInput1)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('GIVEN equal builder and data THEN returns true', () => {
|
||||
expect(textInput1.equals(textInput2)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('GIVEN different builders THEN returns false', () => {
|
||||
const diffTextInput = new TextInputBuilder()
|
||||
.setCustomId('custom id')
|
||||
.setLabel('label 2')
|
||||
.setStyle(TextInputStyle.Paragraph);
|
||||
|
||||
expect(textInput1.equals(diffTextInput)).toBeFalsy();
|
||||
});
|
||||
|
||||
test('GIVEN different text input builder and data THEN returns false', () => {
|
||||
const diffTextInputData: APITextInputComponent = {
|
||||
type: ComponentType.TextInput,
|
||||
custom_id: 'custom id',
|
||||
label: 'label 2',
|
||||
style: TextInputStyle.Short,
|
||||
};
|
||||
|
||||
expect(textInput1.equals(diffTextInputData)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,26 +1,12 @@
|
||||
import { Embed } from '../../src';
|
||||
import type { APIEmbed } from 'discord-api-types/v9';
|
||||
|
||||
const emptyEmbed: APIEmbed = {
|
||||
author: undefined,
|
||||
color: undefined,
|
||||
description: undefined,
|
||||
fields: [],
|
||||
footer: undefined,
|
||||
image: undefined,
|
||||
provider: undefined,
|
||||
thumbnail: undefined,
|
||||
title: undefined,
|
||||
url: undefined,
|
||||
video: undefined,
|
||||
};
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { EmbedBuilder, embedLength } from '../../src/index.js';
|
||||
|
||||
const alpha = 'abcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
describe('Embed', () => {
|
||||
describe('Embed getters', () => {
|
||||
test('GIVEN an embed with specific amount of characters THEN returns amount of characters', () => {
|
||||
const embed = new Embed({
|
||||
const embed = new EmbedBuilder({
|
||||
title: alpha,
|
||||
description: alpha,
|
||||
fields: [{ name: alpha, value: alpha }],
|
||||
@@ -28,38 +14,38 @@ describe('Embed', () => {
|
||||
footer: { text: alpha },
|
||||
});
|
||||
|
||||
expect(embed.length).toBe(alpha.length * 6);
|
||||
expect(embedLength(embed.data)).toEqual(alpha.length * 6);
|
||||
});
|
||||
|
||||
test('GIVEN an embed with zero characters THEN returns amount of characters', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(embed.length).toBe(0);
|
||||
expect(embedLength(embed.data)).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed title', () => {
|
||||
test('GIVEN an embed with a pre-defined title THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ title: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, title: 'foo' });
|
||||
const embed = new EmbedBuilder({ title: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ title: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setTitle THEN return valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setTitle('foo');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, title: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ title: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined title THEN unset title THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ title: 'foo' });
|
||||
const embed = new EmbedBuilder({ title: 'foo' });
|
||||
embed.setTitle(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ title: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid title THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setTitle('a'.repeat(257))).toThrowError();
|
||||
});
|
||||
@@ -67,89 +53,88 @@ describe('Embed', () => {
|
||||
|
||||
describe('Embed description', () => {
|
||||
test('GIVEN an embed with a pre-defined description THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ ...emptyEmbed, description: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, description: 'foo' });
|
||||
const embed = new EmbedBuilder({ description: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ description: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setDescription THEN return valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setDescription('foo');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, description: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ description: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined description THEN unset description THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ description: 'foo' });
|
||||
const embed = new EmbedBuilder({ description: 'foo' });
|
||||
embed.setDescription(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ description: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid description THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setDescription('a'.repeat(4097))).toThrowError();
|
||||
expect(() => embed.setDescription('a'.repeat(4_097))).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed URL', () => {
|
||||
test('GIVEN an embed with a pre-defined url THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ url: 'https://discord.js.org/' });
|
||||
const embed = new EmbedBuilder({ url: 'https://discord.js.org/' });
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
url: 'https://discord.js.org/',
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setURL THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setURL('https://discord.js.org/');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
url: 'https://discord.js.org/',
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined title THEN unset title THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ url: 'https://discord.js.org' });
|
||||
const embed = new EmbedBuilder({ url: 'https://discord.js.org' });
|
||||
embed.setURL(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ url: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid URL THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
test.each(['owo', 'discord://user'])('GIVEN an embed with an invalid URL THEN throws error', (input) => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setURL('owo')).toThrowError();
|
||||
expect(() => embed.setURL(input)).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Color', () => {
|
||||
test('GIVEN an embed with a pre-defined color THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ color: 0xff0000 });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, color: 0xff0000 });
|
||||
const embed = new EmbedBuilder({ color: 0xff0000 });
|
||||
expect(embed.toJSON()).toStrictEqual({ color: 0xff0000 });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setColor THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setColor(0xff0000);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, color: 0xff0000 });
|
||||
expect(new EmbedBuilder().setColor(0xff0000).toJSON()).toStrictEqual({ color: 0xff0000 });
|
||||
expect(new EmbedBuilder().setColor([242, 66, 245]).toJSON()).toStrictEqual({ color: 0xf242f5 });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined color THEN unset color THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ color: 0xff0000 });
|
||||
const embed = new EmbedBuilder({ color: 0xff0000 });
|
||||
embed.setColor(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ color: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid color THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Invalid color
|
||||
expect(() => embed.setColor('RED')).toThrowError();
|
||||
// @ts-expect-error: Invalid color
|
||||
expect(() => embed.setColor([42, 36])).toThrowError();
|
||||
expect(() => embed.setColor([42, 36, 1_000])).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -157,67 +142,65 @@ describe('Embed', () => {
|
||||
const now = new Date();
|
||||
|
||||
test('GIVEN an embed with a pre-defined timestamp THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ timestamp: now.toISOString() });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: now.toISOString() });
|
||||
const embed = new EmbedBuilder({ timestamp: now.toISOString() });
|
||||
expect(embed.toJSON()).toStrictEqual({ timestamp: now.toISOString() });
|
||||
});
|
||||
|
||||
test('given an embed using Embed#setTimestamp (with Date) THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setTimestamp(now);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: now.toISOString() });
|
||||
expect(embed.toJSON()).toStrictEqual({ timestamp: now.toISOString() });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setTimestamp (with int) THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setTimestamp(now.getTime());
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: now.toISOString() });
|
||||
expect(embed.toJSON()).toStrictEqual({ timestamp: now.toISOString() });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setTimestamp (default) THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setTimestamp();
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: embed.timestamp });
|
||||
expect(embed.toJSON()).toStrictEqual({ timestamp: embed.data.timestamp });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined timestamp THEN unset timestamp THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ timestamp: now.toISOString() });
|
||||
const embed = new EmbedBuilder({ timestamp: now.toISOString() });
|
||||
embed.setTimestamp(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: undefined });
|
||||
expect(embed.toJSON()).toStrictEqual({ timestamp: undefined });
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Thumbnail', () => {
|
||||
test('GIVEN an embed with a pre-defined thumbnail THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ thumbnail: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
const embed = new EmbedBuilder({ thumbnail: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
thumbnail: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setThumbnail THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setThumbnail('https://discord.js.org/static/logo.svg');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
thumbnail: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined thumbnail THEN unset thumbnail THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ thumbnail: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
const embed = new EmbedBuilder({ thumbnail: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
embed.setThumbnail(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ thumbnail: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid thumbnail THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setThumbnail('owo')).toThrowError();
|
||||
});
|
||||
@@ -225,32 +208,30 @@ describe('Embed', () => {
|
||||
|
||||
describe('Embed Image', () => {
|
||||
test('GIVEN an embed with a pre-defined image THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ image: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
const embed = new EmbedBuilder({ image: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
image: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setImage THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setImage('https://discord.js.org/static/logo.svg');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
image: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined image THEN unset image THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ image: { url: 'https://discord.js/org/static/logo.svg' } });
|
||||
const embed = new EmbedBuilder({ image: { url: 'https://discord.js/org/static/logo.svg' } });
|
||||
embed.setImage(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ image: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid image THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setImage('owo')).toThrowError();
|
||||
});
|
||||
@@ -258,17 +239,16 @@ describe('Embed', () => {
|
||||
|
||||
describe('Embed Author', () => {
|
||||
test('GIVEN an embed with a pre-defined author THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
const embed = new EmbedBuilder({
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setAuthor THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setAuthor({
|
||||
name: 'Wumpus',
|
||||
iconURL: 'https://discord.js.org/static/logo.svg',
|
||||
@@ -276,22 +256,21 @@ describe('Embed', () => {
|
||||
});
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined author THEN unset author THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
const embed = new EmbedBuilder({
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
embed.setAuthor(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ author: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid author name THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setAuthor({ name: 'a'.repeat(257) })).toThrowError();
|
||||
});
|
||||
@@ -299,82 +278,73 @@ describe('Embed', () => {
|
||||
|
||||
describe('Embed Footer', () => {
|
||||
test('GIVEN an embed with a pre-defined footer THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
const embed = new EmbedBuilder({
|
||||
footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setAuthor THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setFooter({ text: 'Wumpus', iconURL: 'https://discord.js.org/static/logo.svg' });
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined footer THEN unset footer THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' } });
|
||||
const embed = new EmbedBuilder({
|
||||
footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
embed.setFooter(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
expect(embed.toJSON()).toStrictEqual({ footer: undefined });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with invalid footer text THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.setFooter({ text: 'a'.repeat(2049) })).toThrowError();
|
||||
expect(() => embed.setFooter({ text: 'a'.repeat(2_049) })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Fields', () => {
|
||||
test('GIVEN an embed with a pre-defined field THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
const embed = new EmbedBuilder({
|
||||
fields: [{ name: 'foo', value: 'bar' }],
|
||||
});
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#addField THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.addField({ name: 'foo', value: 'bar' });
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
fields: [{ name: 'foo', value: 'bar' }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#addFields THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.addFields({ name: 'foo', value: 'bar' });
|
||||
embed.addFields([{ name: 'foo', value: 'bar' }]);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
fields: [
|
||||
{ name: 'foo', value: 'bar' },
|
||||
{ name: 'foo', value: 'bar' },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#spliceFields THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.addFields({ name: 'foo', value: 'bar' }, { name: 'foo', value: 'baz' });
|
||||
|
||||
expect(embed.spliceFields(0, 1).toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'baz', inline: undefined }],
|
||||
fields: [{ name: 'foo', value: 'baz' }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#spliceFields THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
test('GIVEN an embed using Embed#spliceFields THEN returns valid toJSON data 2', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
embed.addFields(...Array.from({ length: 23 }, () => ({ name: 'foo', value: 'bar' })));
|
||||
|
||||
expect(() =>
|
||||
@@ -383,7 +353,7 @@ describe('Embed', () => {
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#spliceFields that adds additional fields resulting in fields > 25 THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
const embed = new EmbedBuilder();
|
||||
embed.addFields(...Array.from({ length: 23 }, () => ({ name: 'foo', value: 'bar' })));
|
||||
|
||||
expect(() =>
|
||||
@@ -391,9 +361,29 @@ describe('Embed', () => {
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setFields THEN returns valid toJSON data', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() =>
|
||||
embed.setFields(...Array.from({ length: 25 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||
).not.toThrowError();
|
||||
expect(() =>
|
||||
embed.setFields(Array.from({ length: 25 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setFields that sets more than 25 fields THEN throws error', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() =>
|
||||
embed.setFields(...Array.from({ length: 26 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||
).toThrowError();
|
||||
expect(() => embed.setFields(Array.from({ length: 26 }, () => ({ name: 'foo', value: 'bar' })))).toThrowError();
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field amount THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
test('1', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() =>
|
||||
embed.addFields(...Array.from({ length: 26 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||
@@ -402,26 +392,26 @@ describe('Embed', () => {
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field name THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
test('2', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.addFields({ name: '', value: 'bar' })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field name length THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
test('3', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.addFields({ name: 'a'.repeat(257), value: 'bar' })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field value length THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
test('4', () => {
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
expect(() => embed.addFields({ name: '', value: 'a'.repeat(1025) })).toThrowError();
|
||||
expect(() => embed.addFields({ name: '', value: 'a'.repeat(1_025) })).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
import { URL } from 'node:url';
|
||||
import { describe, test, expect, vitest } from 'vitest';
|
||||
import {
|
||||
chatInputApplicationCommandMention,
|
||||
blockQuote,
|
||||
bold,
|
||||
channelLink,
|
||||
channelMention,
|
||||
codeBlock,
|
||||
Faces,
|
||||
@@ -9,7 +14,7 @@ import {
|
||||
hyperlink,
|
||||
inlineCode,
|
||||
italic,
|
||||
memberNicknameMention,
|
||||
messageLink,
|
||||
quote,
|
||||
roleMention,
|
||||
spoiler,
|
||||
@@ -18,80 +23,80 @@ import {
|
||||
TimestampStyles,
|
||||
underscore,
|
||||
userMention,
|
||||
} from '../../src';
|
||||
} from '../../src/index.js';
|
||||
|
||||
describe('Message formatters', () => {
|
||||
describe('codeBlock', () => {
|
||||
test('GIVEN "discord.js" with no language THEN returns "```\\ndiscord.js```"', () => {
|
||||
expect<'```\ndiscord.js```'>(codeBlock('discord.js')).toBe('```\ndiscord.js```');
|
||||
expect<'```\ndiscord.js\n```'>(codeBlock('discord.js')).toEqual('```\ndiscord.js\n```');
|
||||
});
|
||||
|
||||
test('GIVEN "discord.js" with "js" as language THEN returns "```js\\ndiscord.js```"', () => {
|
||||
expect<'```js\ndiscord.js```'>(codeBlock('js', 'discord.js')).toBe('```js\ndiscord.js```');
|
||||
expect<'```js\ndiscord.js\n```'>(codeBlock('js', 'discord.js')).toEqual('```js\ndiscord.js\n```');
|
||||
});
|
||||
});
|
||||
|
||||
describe('inlineCode', () => {
|
||||
test('GIVEN "discord.js" THEN returns "`discord.js`"', () => {
|
||||
expect<'`discord.js`'>(inlineCode('discord.js')).toBe('`discord.js`');
|
||||
expect<'`discord.js`'>(inlineCode('discord.js')).toEqual('`discord.js`');
|
||||
});
|
||||
});
|
||||
|
||||
describe('italic', () => {
|
||||
test('GIVEN "discord.js" THEN returns "_discord.js_"', () => {
|
||||
expect<'_discord.js_'>(italic('discord.js')).toBe('_discord.js_');
|
||||
expect<'_discord.js_'>(italic('discord.js')).toEqual('_discord.js_');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bold', () => {
|
||||
test('GIVEN "discord.js" THEN returns "**discord.js**"', () => {
|
||||
expect<'**discord.js**'>(bold('discord.js')).toBe('**discord.js**');
|
||||
expect<'**discord.js**'>(bold('discord.js')).toEqual('**discord.js**');
|
||||
});
|
||||
});
|
||||
|
||||
describe('underscore', () => {
|
||||
test('GIVEN "discord.js" THEN returns "__discord.js__"', () => {
|
||||
expect<'__discord.js__'>(underscore('discord.js')).toBe('__discord.js__');
|
||||
expect<'__discord.js__'>(underscore('discord.js')).toEqual('__discord.js__');
|
||||
});
|
||||
});
|
||||
|
||||
describe('strikethrough', () => {
|
||||
test('GIVEN "discord.js" THEN returns "~~discord.js~~"', () => {
|
||||
expect<'~~discord.js~~'>(strikethrough('discord.js')).toBe('~~discord.js~~');
|
||||
expect<'~~discord.js~~'>(strikethrough('discord.js')).toEqual('~~discord.js~~');
|
||||
});
|
||||
});
|
||||
|
||||
describe('quote', () => {
|
||||
test('GIVEN "discord.js" THEN returns "> discord.js"', () => {
|
||||
expect<'> discord.js'>(quote('discord.js')).toBe('> discord.js');
|
||||
expect<'> discord.js'>(quote('discord.js')).toEqual('> discord.js');
|
||||
});
|
||||
});
|
||||
|
||||
describe('blockQuote', () => {
|
||||
test('GIVEN "discord.js" THEN returns ">>> discord.js"', () => {
|
||||
expect<'>>> discord.js'>(blockQuote('discord.js')).toBe('>>> discord.js');
|
||||
expect<'>>> discord.js'>(blockQuote('discord.js')).toEqual('>>> discord.js');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hideLinkEmbed', () => {
|
||||
test('GIVEN "https://discord.js.org" THEN returns "<https://discord.js.org>"', () => {
|
||||
expect<'<https://discord.js.org>'>(hideLinkEmbed('https://discord.js.org')).toBe('<https://discord.js.org>');
|
||||
expect<'<https://discord.js.org>'>(hideLinkEmbed('https://discord.js.org')).toEqual('<https://discord.js.org>');
|
||||
});
|
||||
|
||||
test('GIVEN new URL("https://discord.js.org") THEN returns "<https://discord.js.org>"', () => {
|
||||
expect<`<${string}>`>(hideLinkEmbed(new URL('https://discord.js.org/'))).toBe('<https://discord.js.org/>');
|
||||
expect<`<${string}>`>(hideLinkEmbed(new URL('https://discord.js.org/'))).toEqual('<https://discord.js.org/>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hyperlink', () => {
|
||||
test('GIVEN content and string URL THEN returns "[content](url)"', () => {
|
||||
expect<'[discord.js](https://discord.js.org)'>(hyperlink('discord.js', 'https://discord.js.org')).toBe(
|
||||
expect<'[discord.js](https://discord.js.org)'>(hyperlink('discord.js', 'https://discord.js.org')).toEqual(
|
||||
'[discord.js](https://discord.js.org)',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN content and URL THEN returns "[content](url)"', () => {
|
||||
expect<`[discord.js](${string})`>(hyperlink('discord.js', new URL('https://discord.js.org'))).toBe(
|
||||
expect<`[discord.js](${string})`>(hyperlink('discord.js', new URL('https://discord.js.org'))).toEqual(
|
||||
'[discord.js](https://discord.js.org/)',
|
||||
);
|
||||
});
|
||||
@@ -99,108 +104,152 @@ describe('Message formatters', () => {
|
||||
test('GIVEN content, string URL, and title THEN returns "[content](url "title")"', () => {
|
||||
expect<'[discord.js](https://discord.js.org "Official Documentation")'>(
|
||||
hyperlink('discord.js', 'https://discord.js.org', 'Official Documentation'),
|
||||
).toBe('[discord.js](https://discord.js.org "Official Documentation")');
|
||||
).toEqual('[discord.js](https://discord.js.org "Official Documentation")');
|
||||
});
|
||||
|
||||
test('GIVEN content, URL, and title THEN returns "[content](url "title")"', () => {
|
||||
expect<`[discord.js](${string} "Official Documentation")`>(
|
||||
hyperlink('discord.js', new URL('https://discord.js.org'), 'Official Documentation'),
|
||||
).toBe('[discord.js](https://discord.js.org/ "Official Documentation")');
|
||||
).toEqual('[discord.js](https://discord.js.org/ "Official Documentation")');
|
||||
});
|
||||
});
|
||||
|
||||
describe('spoiler', () => {
|
||||
test('GIVEN "discord.js" THEN returns "||discord.js||"', () => {
|
||||
expect<'||discord.js||'>(spoiler('discord.js')).toBe('||discord.js||');
|
||||
expect<'||discord.js||'>(spoiler('discord.js')).toEqual('||discord.js||');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mentions', () => {
|
||||
describe('userMention', () => {
|
||||
test('GIVEN userId THEN returns "<@[userId]>"', () => {
|
||||
expect(userMention('139836912335716352')).toBe('<@139836912335716352>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('memberNicknameMention', () => {
|
||||
test('GIVEN memberId THEN returns "<@![memberId]>"', () => {
|
||||
expect(memberNicknameMention('139836912335716352')).toBe('<@!139836912335716352>');
|
||||
expect(userMention('139836912335716352')).toEqual('<@139836912335716352>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('channelMention', () => {
|
||||
test('GIVEN channelId THEN returns "<#[channelId]>"', () => {
|
||||
expect(channelMention('829924760309334087')).toBe('<#829924760309334087>');
|
||||
expect(channelMention('829924760309334087')).toEqual('<#829924760309334087>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('roleMention', () => {
|
||||
test('GIVEN roleId THEN returns "<&[roleId]>"', () => {
|
||||
expect(roleMention('815434166602170409')).toBe('<@&815434166602170409>');
|
||||
expect(roleMention('815434166602170409')).toEqual('<@&815434166602170409>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('chatInputApplicationCommandMention', () => {
|
||||
test('GIVEN commandName and commandId THEN returns "</[commandName]:[commandId]>"', () => {
|
||||
expect(chatInputApplicationCommandMention('airhorn', '815434166602170409')).toEqual(
|
||||
'</airhorn:815434166602170409>',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN commandName, subcommandName, and commandId THEN returns "</[commandName] [subcommandName]:[commandId]>"', () => {
|
||||
expect(chatInputApplicationCommandMention('airhorn', 'sub', '815434166602170409')).toEqual(
|
||||
'</airhorn sub:815434166602170409>',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN commandName, subcommandGroupName, subcommandName, and commandId THEN returns "</[commandName] [subcommandGroupName] [subcommandName]:[commandId]>"', () => {
|
||||
expect(chatInputApplicationCommandMention('airhorn', 'group', 'sub', '815434166602170409')).toEqual(
|
||||
'</airhorn group sub:815434166602170409>',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatEmoji', () => {
|
||||
test('GIVEN static emojiId THEN returns "<:_:${emojiId}>"', () => {
|
||||
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952')).toBe('<:_:851461487498493952>');
|
||||
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952')).toEqual('<:_:851461487498493952>');
|
||||
});
|
||||
|
||||
test('GIVEN static emojiId WITH animated explicitly false THEN returns "<:_:[emojiId]>"', () => {
|
||||
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952', false)).toBe('<:_:851461487498493952>');
|
||||
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952', false)).toEqual('<:_:851461487498493952>');
|
||||
});
|
||||
|
||||
test('GIVEN animated emojiId THEN returns "<a:_:${emojiId}>"', () => {
|
||||
expect<`<a:_:827220205352255549>`>(formatEmoji('827220205352255549', true)).toBe('<a:_:827220205352255549>');
|
||||
expect<`<a:_:827220205352255549>`>(formatEmoji('827220205352255549', true)).toEqual('<a:_:827220205352255549>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('channelLink', () => {
|
||||
test('GIVEN channelId THEN returns "https://discord.com/channels/@me/${channelId}"', () => {
|
||||
expect<'https://discord.com/channels/@me/123456789012345678'>(channelLink('123456789012345678')).toEqual(
|
||||
'https://discord.com/channels/@me/123456789012345678',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN channelId WITH guildId THEN returns "https://discord.com/channels/${guildId}/${channelId}"', () => {
|
||||
expect<'https://discord.com/channels/987654321987654/123456789012345678'>(
|
||||
channelLink('123456789012345678', '987654321987654'),
|
||||
).toEqual('https://discord.com/channels/987654321987654/123456789012345678');
|
||||
});
|
||||
});
|
||||
|
||||
describe('messageLink', () => {
|
||||
test('GIVEN channelId AND messageId THEN returns "https://discord.com/channels/@me/${channelId}/${messageId}"', () => {
|
||||
expect<'https://discord.com/channels/@me/123456789012345678/102938475657483'>(
|
||||
messageLink('123456789012345678', '102938475657483'),
|
||||
).toEqual('https://discord.com/channels/@me/123456789012345678/102938475657483');
|
||||
});
|
||||
|
||||
test('GIVEN channelId AND messageId WITH guildId THEN returns "https://discord.com/channels/${guildId}/${channelId}/${messageId}"', () => {
|
||||
expect<'https://discord.com/channels/987654321987654/123456789012345678/102938475657483'>(
|
||||
messageLink('123456789012345678', '102938475657483', '987654321987654'),
|
||||
).toEqual('https://discord.com/channels/987654321987654/123456789012345678/102938475657483');
|
||||
});
|
||||
});
|
||||
|
||||
describe('time', () => {
|
||||
test('GIVEN no arguments THEN returns "<t:${bigint}>"', () => {
|
||||
jest.useFakeTimers('modern');
|
||||
jest.setSystemTime(1566424897579);
|
||||
vitest.useFakeTimers();
|
||||
vitest.setSystemTime(1_566_424_897_579);
|
||||
|
||||
expect<`<t:${bigint}>`>(time()).toBe('<t:1566424897>');
|
||||
expect<`<t:${bigint}>`>(time()).toEqual('<t:1566424897>');
|
||||
|
||||
jest.useRealTimers();
|
||||
vitest.useRealTimers();
|
||||
});
|
||||
|
||||
test('GIVEN a date THEN returns "<t:${bigint}>"', () => {
|
||||
expect<`<t:${bigint}>`>(time(new Date(1867424897579))).toBe('<t:1867424897>');
|
||||
expect<`<t:${bigint}>`>(time(new Date(1_867_424_897_579))).toEqual('<t:1867424897>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a style from string THEN returns "<t:${bigint}:${style}>"', () => {
|
||||
expect<`<t:${bigint}:d>`>(time(new Date(1867424897579), 'd')).toBe('<t:1867424897:d>');
|
||||
expect<`<t:${bigint}:d>`>(time(new Date(1_867_424_897_579), 'd')).toEqual('<t:1867424897:d>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a format from enum THEN returns "<t:${bigint}:${style}>"', () => {
|
||||
expect<`<t:${bigint}:R>`>(time(new Date(1867424897579), TimestampStyles.RelativeTime)).toBe('<t:1867424897:R>');
|
||||
expect<`<t:${bigint}:R>`>(time(new Date(1_867_424_897_579), TimestampStyles.RelativeTime)).toEqual(
|
||||
'<t:1867424897:R>',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN a date THEN returns "<t:${time}>"', () => {
|
||||
expect<'<t:1867424897>'>(time(1867424897)).toBe('<t:1867424897>');
|
||||
expect<'<t:1867424897>'>(time(1_867_424_897)).toEqual('<t:1867424897>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a style from string THEN returns "<t:${time}:${style}>"', () => {
|
||||
expect<'<t:1867424897:d>'>(time(1867424897, 'd')).toBe('<t:1867424897:d>');
|
||||
expect<'<t:1867424897:d>'>(time(1_867_424_897, 'd')).toEqual('<t:1867424897:d>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a format from enum THEN returns "<t:${time}:${style}>"', () => {
|
||||
expect<'<t:1867424897:R>'>(time(1867424897, TimestampStyles.RelativeTime)).toBe('<t:1867424897:R>');
|
||||
expect<'<t:1867424897:R>'>(time(1_867_424_897, TimestampStyles.RelativeTime)).toEqual('<t:1867424897:R>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Faces', () => {
|
||||
test('GIVEN Faces.Shrug THEN returns "¯\\_(ツ)\\_/¯"', () => {
|
||||
expect<'¯\\_(ツ)\\_/¯'>(Faces.Shrug).toBe('¯\\_(ツ)\\_/¯');
|
||||
expect<'¯\\_(ツ)\\_/¯'>(Faces.Shrug).toEqual('¯\\_(ツ)\\_/¯');
|
||||
});
|
||||
|
||||
test('GIVEN Faces.Tableflip THEN returns "(╯°□°)╯︵ ┻━┻"', () => {
|
||||
expect<'(╯°□°)╯︵ ┻━┻'>(Faces.Tableflip).toBe('(╯°□°)╯︵ ┻━┻');
|
||||
expect<'(╯°□°)╯︵ ┻━┻'>(Faces.Tableflip).toEqual('(╯°□°)╯︵ ┻━┻');
|
||||
});
|
||||
|
||||
test('GIVEN Faces.Unflip THEN returns "┬─┬ ノ( ゜-゜ノ)"', () => {
|
||||
expect<'┬─┬ ノ( ゜-゜ノ)'>(Faces.Unflip).toBe('┬─┬ ノ( ゜-゜ノ)');
|
||||
expect<'┬─┬ ノ( ゜-゜ノ)'>(Faces.Unflip).toEqual('┬─┬ ノ( ゜-゜ノ)');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user