lunibee 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -23
- package/dist/builders/components.d.ts +108 -0
- package/dist/builders/index.d.ts +1 -1
- package/dist/builders/index.js +178 -2
- package/dist/builders/index.js.map +3 -3
- package/dist/collection/index.d.ts +6 -0
- package/dist/collection/index.js +33 -2
- package/dist/collection/index.js.map +4 -4
- package/dist/core/events.d.ts +67 -3
- package/dist/core/index.d.ts +120 -90
- package/dist/core/index.js +816 -1021
- package/dist/core/index.js.map +20 -21
- package/dist/formatters/index.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2215 -1392
- package/dist/index.js.map +29 -26
- package/dist/managers/guild.d.ts +30 -0
- package/dist/managers/index.d.ts +56 -75
- package/dist/managers/index.js +339 -48
- package/dist/managers/index.js.map +16 -12
- package/dist/managers/message.d.ts +7 -12
- package/dist/managers/user.d.ts +20 -0
- package/dist/rest/index.d.ts +83 -1
- package/dist/rest/index.js +48 -8
- package/dist/rest/index.js.map +4 -4
- package/dist/rest/routes.d.ts +4 -1
- package/dist/sharding/index.js +4 -1
- package/dist/sharding/index.js.map +4 -4
- package/dist/structures/base.d.ts +99 -48
- package/dist/structures/embed.d.ts +65 -0
- package/dist/structures/index.d.ts +45 -25
- package/dist/structures/index.js +569 -36
- package/dist/structures/index.js.map +10 -8
- package/dist/structures/interactions.d.ts +72 -17
- package/dist/structures/resources.d.ts +9 -5
- package/dist/types/index.d.ts +530 -85
- package/dist/types/index.js +71 -1
- package/dist/types/index.js.map +3 -3
- package/dist/voice/index.js.map +1 -1
- package/dist/ws/index.js +4 -1
- package/dist/ws/index.js.map +4 -4
- package/package.json +15 -15
package/dist/core/index.js
CHANGED
|
@@ -420,6 +420,156 @@ class PermissionsBitField extends PermissionSet {
|
|
|
420
420
|
super(value);
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
+
// packages/core/src/events.ts
|
|
424
|
+
var ClientEvent;
|
|
425
|
+
((ClientEvent2) => {
|
|
426
|
+
ClientEvent2["Ready"] = "ready";
|
|
427
|
+
ClientEvent2["Raw"] = "raw";
|
|
428
|
+
ClientEvent2["Error"] = "error";
|
|
429
|
+
ClientEvent2["Open"] = "open";
|
|
430
|
+
ClientEvent2["Close"] = "close";
|
|
431
|
+
ClientEvent2["MessageCreate"] = "messageCreate";
|
|
432
|
+
ClientEvent2["MessageUpdate"] = "messageUpdate";
|
|
433
|
+
ClientEvent2["MessageDelete"] = "messageDelete";
|
|
434
|
+
ClientEvent2["MessageDeleteBulk"] = "messageDeleteBulk";
|
|
435
|
+
ClientEvent2["MessageReactionAdd"] = "messageReactionAdd";
|
|
436
|
+
ClientEvent2["MessageReactionRemove"] = "messageReactionRemove";
|
|
437
|
+
ClientEvent2["MessageReactionRemoveAll"] = "messageReactionRemoveAll";
|
|
438
|
+
ClientEvent2["MessageReactionRemoveEmoji"] = "messageReactionRemoveEmoji";
|
|
439
|
+
ClientEvent2["MessagePollVoteAdd"] = "messagePollVoteAdd";
|
|
440
|
+
ClientEvent2["MessagePollVoteRemove"] = "messagePollVoteRemove";
|
|
441
|
+
ClientEvent2["GuildCreate"] = "guildCreate";
|
|
442
|
+
ClientEvent2["GuildUpdate"] = "guildUpdate";
|
|
443
|
+
ClientEvent2["GuildDelete"] = "guildDelete";
|
|
444
|
+
ClientEvent2["GuildAvailable"] = "guildAvailable";
|
|
445
|
+
ClientEvent2["GuildUnavailable"] = "guildUnavailable";
|
|
446
|
+
ClientEvent2["GuildMemberAdd"] = "guildMemberAdd";
|
|
447
|
+
ClientEvent2["GuildMemberUpdate"] = "guildMemberUpdate";
|
|
448
|
+
ClientEvent2["GuildMemberRemove"] = "guildMemberRemove";
|
|
449
|
+
ClientEvent2["GuildMembersChunk"] = "guildMembersChunk";
|
|
450
|
+
ClientEvent2["GuildBanAdd"] = "guildBanAdd";
|
|
451
|
+
ClientEvent2["GuildBanRemove"] = "guildBanRemove";
|
|
452
|
+
ClientEvent2["GuildRoleCreate"] = "guildRoleCreate";
|
|
453
|
+
ClientEvent2["GuildRoleUpdate"] = "guildRoleUpdate";
|
|
454
|
+
ClientEvent2["GuildRoleDelete"] = "guildRoleDelete";
|
|
455
|
+
ClientEvent2["GuildEmojisUpdate"] = "guildEmojisUpdate";
|
|
456
|
+
ClientEvent2["GuildStickersUpdate"] = "guildStickersUpdate";
|
|
457
|
+
ClientEvent2["GuildIntegrationsUpdate"] = "guildIntegrationsUpdate";
|
|
458
|
+
ClientEvent2["GuildScheduledEventCreate"] = "guildScheduledEventCreate";
|
|
459
|
+
ClientEvent2["GuildScheduledEventUpdate"] = "guildScheduledEventUpdate";
|
|
460
|
+
ClientEvent2["GuildScheduledEventDelete"] = "guildScheduledEventDelete";
|
|
461
|
+
ClientEvent2["GuildScheduledEventUserAdd"] = "guildScheduledEventUserAdd";
|
|
462
|
+
ClientEvent2["GuildScheduledEventUserRemove"] = "guildScheduledEventUserRemove";
|
|
463
|
+
ClientEvent2["AutoModerationRuleCreate"] = "autoModerationRuleCreate";
|
|
464
|
+
ClientEvent2["AutoModerationRuleUpdate"] = "autoModerationRuleUpdate";
|
|
465
|
+
ClientEvent2["AutoModerationRuleDelete"] = "autoModerationRuleDelete";
|
|
466
|
+
ClientEvent2["AutoModerationActionExecution"] = "autoModerationActionExecution";
|
|
467
|
+
ClientEvent2["ChannelCreate"] = "channelCreate";
|
|
468
|
+
ClientEvent2["ChannelUpdate"] = "channelUpdate";
|
|
469
|
+
ClientEvent2["ChannelDelete"] = "channelDelete";
|
|
470
|
+
ClientEvent2["ChannelPinsUpdate"] = "channelPinsUpdate";
|
|
471
|
+
ClientEvent2["ThreadCreate"] = "threadCreate";
|
|
472
|
+
ClientEvent2["ThreadUpdate"] = "threadUpdate";
|
|
473
|
+
ClientEvent2["ThreadDelete"] = "threadDelete";
|
|
474
|
+
ClientEvent2["ThreadListSync"] = "threadListSync";
|
|
475
|
+
ClientEvent2["ThreadMembersUpdate"] = "threadMembersUpdate";
|
|
476
|
+
ClientEvent2["ThreadMemberUpdate"] = "threadMemberUpdate";
|
|
477
|
+
ClientEvent2["StageInstanceCreate"] = "stageInstanceCreate";
|
|
478
|
+
ClientEvent2["StageInstanceUpdate"] = "stageInstanceUpdate";
|
|
479
|
+
ClientEvent2["StageInstanceDelete"] = "stageInstanceDelete";
|
|
480
|
+
ClientEvent2["InviteCreate"] = "inviteCreate";
|
|
481
|
+
ClientEvent2["InviteDelete"] = "inviteDelete";
|
|
482
|
+
ClientEvent2["WebhooksUpdate"] = "webhooksUpdate";
|
|
483
|
+
ClientEvent2["VoiceStateUpdate"] = "voiceStateUpdate";
|
|
484
|
+
ClientEvent2["VoiceServerUpdate"] = "voiceServerUpdate";
|
|
485
|
+
ClientEvent2["PresenceUpdate"] = "presenceUpdate";
|
|
486
|
+
ClientEvent2["TypingStart"] = "typingStart";
|
|
487
|
+
ClientEvent2["InteractionCreate"] = "interactionCreate";
|
|
488
|
+
})(ClientEvent ||= {});
|
|
489
|
+
// packages/types/src/index.ts
|
|
490
|
+
var GatewayIntentBits = {
|
|
491
|
+
Guilds: 1 << 0,
|
|
492
|
+
GuildMembers: 1 << 1,
|
|
493
|
+
GuildModeration: 1 << 2,
|
|
494
|
+
GuildExpressions: 1 << 3,
|
|
495
|
+
GuildIntegrations: 1 << 4,
|
|
496
|
+
GuildWebhooks: 1 << 5,
|
|
497
|
+
GuildInvites: 1 << 6,
|
|
498
|
+
GuildVoiceStates: 1 << 7,
|
|
499
|
+
GuildPresences: 1 << 8,
|
|
500
|
+
GuildMessages: 1 << 9,
|
|
501
|
+
GuildMessageReactions: 1 << 10,
|
|
502
|
+
GuildMessageTyping: 1 << 11,
|
|
503
|
+
DirectMessages: 1 << 12,
|
|
504
|
+
DirectMessageReactions: 1 << 13,
|
|
505
|
+
DirectMessageTyping: 1 << 14,
|
|
506
|
+
MessageContent: 1 << 15,
|
|
507
|
+
GuildScheduledEvents: 1 << 16,
|
|
508
|
+
AutoModerationConfiguration: 1 << 20,
|
|
509
|
+
AutoModerationExecution: 1 << 21,
|
|
510
|
+
GuildMessagePolls: 1 << 24,
|
|
511
|
+
DirectMessagePolls: 1 << 25
|
|
512
|
+
};
|
|
513
|
+
var IntentBits = {
|
|
514
|
+
guild: 1 << 0,
|
|
515
|
+
guilds: 1 << 0,
|
|
516
|
+
guildMembers: 1 << 1,
|
|
517
|
+
guildModeration: 1 << 2,
|
|
518
|
+
guildBans: 1 << 2,
|
|
519
|
+
guildExpressions: 1 << 3,
|
|
520
|
+
guildEmojis: 1 << 3,
|
|
521
|
+
guildEmojisAndStickers: 1 << 3,
|
|
522
|
+
guildIntegrations: 1 << 4,
|
|
523
|
+
guildWebhooks: 1 << 5,
|
|
524
|
+
guildInvites: 1 << 6,
|
|
525
|
+
guildVoiceStates: 1 << 7,
|
|
526
|
+
guildPresences: 1 << 8,
|
|
527
|
+
guildMessages: 1 << 9,
|
|
528
|
+
guildMessage: 1 << 9,
|
|
529
|
+
guildMessageReactions: 1 << 10,
|
|
530
|
+
guildMessageTyping: 1 << 11,
|
|
531
|
+
directMessages: 1 << 12,
|
|
532
|
+
directMessageReactions: 1 << 13,
|
|
533
|
+
directMessageTyping: 1 << 14,
|
|
534
|
+
messageContent: 1 << 15,
|
|
535
|
+
guildScheduledEvents: 1 << 16,
|
|
536
|
+
autoModerationConfiguration: 1 << 20,
|
|
537
|
+
autoModerationExecution: 1 << 21,
|
|
538
|
+
guildMessagePolls: 1 << 24,
|
|
539
|
+
directMessagePolls: 1 << 25
|
|
540
|
+
};
|
|
541
|
+
var Intents = IntentBits;
|
|
542
|
+
function resolveGatewayIntents(intents) {
|
|
543
|
+
if (typeof intents === "number")
|
|
544
|
+
return intents;
|
|
545
|
+
if (Array.isArray(intents)) {
|
|
546
|
+
return intents.reduce((acc, intent) => {
|
|
547
|
+
return acc | resolveGatewayIntents(intent);
|
|
548
|
+
}, 0);
|
|
549
|
+
}
|
|
550
|
+
if (typeof intents === "string") {
|
|
551
|
+
if (intents in GatewayIntentBits)
|
|
552
|
+
return GatewayIntentBits[intents];
|
|
553
|
+
if (intents in IntentBits)
|
|
554
|
+
return IntentBits[intents];
|
|
555
|
+
const lower = intents.charAt(0).toLowerCase() + intents.slice(1);
|
|
556
|
+
if (lower in IntentBits)
|
|
557
|
+
return IntentBits[lower];
|
|
558
|
+
const num = Number(intents);
|
|
559
|
+
if (!Number.isNaN(num))
|
|
560
|
+
return num;
|
|
561
|
+
}
|
|
562
|
+
return 0;
|
|
563
|
+
}
|
|
564
|
+
var InteractionResponseType = {
|
|
565
|
+
Pong: 1,
|
|
566
|
+
ChannelMessage: 4,
|
|
567
|
+
DeferredChannelMessage: 5,
|
|
568
|
+
DeferredMessageUpdate: 6,
|
|
569
|
+
MessageUpdate: 7,
|
|
570
|
+
Autocomplete: 8,
|
|
571
|
+
Modal: 9
|
|
572
|
+
};
|
|
423
573
|
// packages/collection/src/index.ts
|
|
424
574
|
class Collection extends Map {
|
|
425
575
|
first() {
|
|
@@ -544,6 +694,28 @@ class Collection extends Map {
|
|
|
544
694
|
entry = [item[0], item[1]];
|
|
545
695
|
return entry;
|
|
546
696
|
}
|
|
697
|
+
union(other) {
|
|
698
|
+
const result = this.clone();
|
|
699
|
+
for (const [key, value] of other)
|
|
700
|
+
result.set(key, value);
|
|
701
|
+
return result;
|
|
702
|
+
}
|
|
703
|
+
intersection(other) {
|
|
704
|
+
const result = new Collection;
|
|
705
|
+
for (const [key, value] of this) {
|
|
706
|
+
if (other.has(key))
|
|
707
|
+
result.set(key, value);
|
|
708
|
+
}
|
|
709
|
+
return result;
|
|
710
|
+
}
|
|
711
|
+
difference(other) {
|
|
712
|
+
const result = new Collection;
|
|
713
|
+
for (const [key, value] of this) {
|
|
714
|
+
if (!other.has(key))
|
|
715
|
+
result.set(key, value);
|
|
716
|
+
}
|
|
717
|
+
return result;
|
|
718
|
+
}
|
|
547
719
|
}
|
|
548
720
|
|
|
549
721
|
// packages/managers/src/base.ts
|
|
@@ -612,11 +784,27 @@ class ResourceManager extends Manager {
|
|
|
612
784
|
return this.upsert(resource);
|
|
613
785
|
}
|
|
614
786
|
}
|
|
787
|
+
// packages/rest/package.json
|
|
788
|
+
var package_default = {
|
|
789
|
+
name: "@lunibee/rest",
|
|
790
|
+
version: "0.1.6",
|
|
791
|
+
type: "module",
|
|
792
|
+
module: "./src/index.ts",
|
|
793
|
+
types: "./src/index.ts",
|
|
794
|
+
exports: {
|
|
795
|
+
".": "./src/index.ts"
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
|
|
615
799
|
// packages/rest/src/routes.ts
|
|
616
800
|
var Routes = {
|
|
617
801
|
user: () => "/users/@me",
|
|
618
802
|
userById: (userId) => `/users/${snowflake(userId, "User ID")}`,
|
|
619
803
|
guild: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}`,
|
|
804
|
+
guildPreview: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/preview`,
|
|
805
|
+
guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
|
|
806
|
+
guildWebhooks: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/webhooks`,
|
|
807
|
+
guildInvites: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/invites`,
|
|
620
808
|
guildChannels: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/channels`,
|
|
621
809
|
guildMember: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/${snowflake(userId, "User ID")}`,
|
|
622
810
|
guildRoles: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/roles`,
|
|
@@ -644,7 +832,6 @@ var Routes = {
|
|
|
644
832
|
guildApplicationCommand: (applicationId, guildId, commandId) => `/applications/${snowflake(applicationId, "Application ID")}/guilds/${snowflake(guildId, "Guild ID")}/commands/${snowflake(commandId, "Command ID")}`,
|
|
645
833
|
interactionCallback: (interactionId, token) => `/interactions/${snowflake(interactionId, "Interaction ID")}/${encodeURIComponent(token)}/callback`,
|
|
646
834
|
interactionOriginalResponse: (applicationId, token) => `/webhooks/${snowflake(applicationId, "Application ID")}/${encodeURIComponent(token)}/messages/@original`,
|
|
647
|
-
guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
|
|
648
835
|
channelPublicArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/public`,
|
|
649
836
|
channelPrivateArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/private`,
|
|
650
837
|
threadMembers: (threadId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members`,
|
|
@@ -679,6 +866,9 @@ class RESTError extends Error {
|
|
|
679
866
|
this.path = options.path;
|
|
680
867
|
}
|
|
681
868
|
}
|
|
869
|
+
var LIBRARY_VERSION = package_default.version;
|
|
870
|
+
var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
|
|
871
|
+
var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${package_default.version})`;
|
|
682
872
|
function createRetryPolicy(maxRetries = 2) {
|
|
683
873
|
if (!Number.isFinite(maxRetries) || maxRetries < 0)
|
|
684
874
|
throw new TypeError("maxRetries must be a non-negative finite number.");
|
|
@@ -745,15 +935,19 @@ class REST {
|
|
|
745
935
|
throw this.#abortError(path, options.signal.reason);
|
|
746
936
|
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
747
937
|
const timer = setTimeout(() => controller.abort(new DOMException("REST request timeout", "TimeoutError")), this.#timeout);
|
|
938
|
+
const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
|
|
939
|
+
const headers = {
|
|
940
|
+
...this.#token ? { Authorization: `Bot ${this.#token}` } : {},
|
|
941
|
+
"User-Agent": USER_AGENT
|
|
942
|
+
};
|
|
943
|
+
if (!isFormData)
|
|
944
|
+
headers["Content-Type"] = "application/json";
|
|
945
|
+
const fetchBody = isFormData ? body : body === undefined ? undefined : JSON.stringify(body);
|
|
748
946
|
try {
|
|
749
947
|
const response = await fetch(`${this.#baseURL}${path}`, {
|
|
750
948
|
method: normalizedMethod,
|
|
751
|
-
headers
|
|
752
|
-
|
|
753
|
-
"Content-Type": "application/json",
|
|
754
|
-
"User-Agent": "Lunibee/0.1.0"
|
|
755
|
-
},
|
|
756
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
949
|
+
headers,
|
|
950
|
+
body: fetchBody,
|
|
757
951
|
signal: controller.signal
|
|
758
952
|
});
|
|
759
953
|
bucket = this.#update(response, bucket, route, bucketKey);
|
|
@@ -806,6 +1000,24 @@ class REST {
|
|
|
806
1000
|
delete(path, options) {
|
|
807
1001
|
return this.request("DELETE", path, undefined, options);
|
|
808
1002
|
}
|
|
1003
|
+
#fileForm(payload, files) {
|
|
1004
|
+
const form = new FormData;
|
|
1005
|
+
form.append("payload_json", JSON.stringify(payload));
|
|
1006
|
+
for (let i = 0;i < files.length; i++) {
|
|
1007
|
+
const file = files[i];
|
|
1008
|
+
const blob = file.data instanceof Blob ? file.data : new Blob([file.data], {
|
|
1009
|
+
type: file.contentType ?? "application/octet-stream"
|
|
1010
|
+
});
|
|
1011
|
+
form.append(`files[${i}]`, blob, file.name);
|
|
1012
|
+
}
|
|
1013
|
+
return form;
|
|
1014
|
+
}
|
|
1015
|
+
postWithFiles(path, payload, files, options) {
|
|
1016
|
+
return this.request("POST", path, this.#fileForm(payload, files), options);
|
|
1017
|
+
}
|
|
1018
|
+
patchWithFiles(path, payload, files, options) {
|
|
1019
|
+
return this.request("PATCH", path, this.#fileForm(payload, files), options);
|
|
1020
|
+
}
|
|
809
1021
|
async#wait(bucket, signal, path) {
|
|
810
1022
|
const delay = bucket.resetAt - Date.now();
|
|
811
1023
|
if (bucket.remaining <= 0 && delay > 0)
|
|
@@ -920,6 +1132,16 @@ class BaseStructure {
|
|
|
920
1132
|
toString() {
|
|
921
1133
|
return this.id;
|
|
922
1134
|
}
|
|
1135
|
+
get createdAt() {
|
|
1136
|
+
return new Date(Number((BigInt(this.id) >> 22n) + 1420070400000n));
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
var CDN_BASE = "https://cdn.discordapp.com";
|
|
1140
|
+
function cdnURL(path, hash, options = {}) {
|
|
1141
|
+
const isAnimated = hash.startsWith("a_") && !options.forceStatic;
|
|
1142
|
+
const ext = options.extension ?? (isAnimated ? "gif" : "png");
|
|
1143
|
+
const size = options.size ? `?size=${options.size}` : "";
|
|
1144
|
+
return `${CDN_BASE}${path}/${hash}.${ext}${size}`;
|
|
923
1145
|
}
|
|
924
1146
|
|
|
925
1147
|
class User extends BaseStructure {
|
|
@@ -929,6 +1151,7 @@ class User extends BaseStructure {
|
|
|
929
1151
|
bot;
|
|
930
1152
|
system;
|
|
931
1153
|
flags;
|
|
1154
|
+
discriminator;
|
|
932
1155
|
constructor(data) {
|
|
933
1156
|
super(data.id);
|
|
934
1157
|
if (!data.username)
|
|
@@ -939,6 +1162,7 @@ class User extends BaseStructure {
|
|
|
939
1162
|
this.bot = data.bot ?? false;
|
|
940
1163
|
this.system = data.system ?? false;
|
|
941
1164
|
this.flags = data.public_flags ?? 0;
|
|
1165
|
+
this.discriminator = data.discriminator && data.discriminator !== "0" ? data.discriminator : null;
|
|
942
1166
|
}
|
|
943
1167
|
get displayName() {
|
|
944
1168
|
return this.globalName ?? this.username;
|
|
@@ -946,21 +1170,29 @@ class User extends BaseStructure {
|
|
|
946
1170
|
avatarURL(options = {}) {
|
|
947
1171
|
if (!this.avatar)
|
|
948
1172
|
return null;
|
|
949
|
-
|
|
950
|
-
return `https://cdn.discordapp.com/avatars/${this.id}/${this.avatar}.${extension}${options.size ? `?size=${options.size}` : ""}`;
|
|
1173
|
+
return cdnURL(`/avatars/${this.id}`, this.avatar, options);
|
|
951
1174
|
}
|
|
952
1175
|
defaultAvatarURL() {
|
|
953
|
-
|
|
1176
|
+
const index = this.discriminator ? Number(this.discriminator) % 5 : Number((BigInt(this.id) >> 22n) % 6n);
|
|
1177
|
+
return `${CDN_BASE}/embed/avatars/${index}.png`;
|
|
954
1178
|
}
|
|
955
1179
|
displayAvatarURL(options = {}) {
|
|
956
1180
|
return this.avatarURL(options) ?? this.defaultAvatarURL();
|
|
957
1181
|
}
|
|
1182
|
+
toString() {
|
|
1183
|
+
return `<@${this.id}>`;
|
|
1184
|
+
}
|
|
958
1185
|
}
|
|
959
1186
|
|
|
960
1187
|
class Channel extends BaseStructure {
|
|
961
1188
|
type;
|
|
962
1189
|
name;
|
|
963
1190
|
guildId;
|
|
1191
|
+
topic;
|
|
1192
|
+
parentId;
|
|
1193
|
+
nsfw;
|
|
1194
|
+
rateLimitPerUser;
|
|
1195
|
+
position;
|
|
964
1196
|
#context;
|
|
965
1197
|
constructor(data, context) {
|
|
966
1198
|
super(data.id);
|
|
@@ -969,6 +1201,11 @@ class Channel extends BaseStructure {
|
|
|
969
1201
|
this.type = data.type;
|
|
970
1202
|
this.name = data.name;
|
|
971
1203
|
this.guildId = data.guild_id;
|
|
1204
|
+
this.topic = data.topic;
|
|
1205
|
+
this.parentId = data.parent_id;
|
|
1206
|
+
this.nsfw = data.nsfw;
|
|
1207
|
+
this.rateLimitPerUser = data.rate_limit_per_user;
|
|
1208
|
+
this.position = data.position;
|
|
972
1209
|
this.#context = context;
|
|
973
1210
|
}
|
|
974
1211
|
sendMessage(options) {
|
|
@@ -976,19 +1213,112 @@ class Channel extends BaseStructure {
|
|
|
976
1213
|
throw new Error("This channel is not attached to a client.");
|
|
977
1214
|
return this.#context.sendMessage(this.id, options);
|
|
978
1215
|
}
|
|
1216
|
+
send(options) {
|
|
1217
|
+
return this.sendMessage(options);
|
|
1218
|
+
}
|
|
1219
|
+
edit(options) {
|
|
1220
|
+
if (!this.#context?.editChannel)
|
|
1221
|
+
throw new Error("This channel is not attached to a client.");
|
|
1222
|
+
return this.#context.editChannel(this.id, options);
|
|
1223
|
+
}
|
|
1224
|
+
editName(name) {
|
|
1225
|
+
if (!name.trim())
|
|
1226
|
+
throw new TypeError("Channel name cannot be empty.");
|
|
1227
|
+
return this.edit({ name });
|
|
1228
|
+
}
|
|
1229
|
+
editTopic(topic) {
|
|
1230
|
+
return this.edit({ topic });
|
|
1231
|
+
}
|
|
1232
|
+
editParent(parentId) {
|
|
1233
|
+
return this.edit({ parent_id: parentId });
|
|
1234
|
+
}
|
|
1235
|
+
delete() {
|
|
1236
|
+
if (!this.#context?.deleteChannel)
|
|
1237
|
+
throw new Error("This channel is not attached to a client.");
|
|
1238
|
+
return this.#context.deleteChannel(this.id);
|
|
1239
|
+
}
|
|
1240
|
+
update(options) {
|
|
1241
|
+
return this.edit(options);
|
|
1242
|
+
}
|
|
1243
|
+
toString() {
|
|
1244
|
+
return `<#${this.id}>`;
|
|
1245
|
+
}
|
|
979
1246
|
}
|
|
980
1247
|
|
|
981
1248
|
class Guild extends BaseStructure {
|
|
982
1249
|
name;
|
|
1250
|
+
icon;
|
|
1251
|
+
splash;
|
|
1252
|
+
banner;
|
|
1253
|
+
description;
|
|
983
1254
|
preferredLocale;
|
|
984
1255
|
ownerId;
|
|
1256
|
+
features;
|
|
1257
|
+
verificationLevel;
|
|
1258
|
+
premiumTier;
|
|
1259
|
+
premiumSubscriptionCount;
|
|
1260
|
+
memberCount;
|
|
1261
|
+
approximateMemberCount;
|
|
1262
|
+
approximatePresenceCount;
|
|
1263
|
+
vanityUrlCode;
|
|
1264
|
+
nsfwLevel;
|
|
1265
|
+
discoverySplash;
|
|
985
1266
|
constructor(data) {
|
|
986
1267
|
super(data.id);
|
|
987
1268
|
if (!data.name)
|
|
988
1269
|
throw new TypeError("A Discord guild requires a name.");
|
|
989
1270
|
this.name = data.name;
|
|
990
|
-
this.
|
|
1271
|
+
this.icon = data.icon ?? null;
|
|
1272
|
+
this.splash = data.splash ?? null;
|
|
1273
|
+
this.banner = data.banner ?? null;
|
|
1274
|
+
this.description = data.description ?? null;
|
|
1275
|
+
this.preferredLocale = data.preferred_locale ?? "en-US";
|
|
991
1276
|
this.ownerId = data.owner_id;
|
|
1277
|
+
this.features = data.features ?? [];
|
|
1278
|
+
this.verificationLevel = data.verification_level ?? 0;
|
|
1279
|
+
this.premiumTier = data.premium_tier ?? 0;
|
|
1280
|
+
this.premiumSubscriptionCount = data.premium_subscription_count ?? 0;
|
|
1281
|
+
this.memberCount = data.member_count ?? data.approximate_member_count;
|
|
1282
|
+
this.approximateMemberCount = data.approximate_member_count;
|
|
1283
|
+
this.approximatePresenceCount = data.approximate_presence_count;
|
|
1284
|
+
this.vanityUrlCode = data.vanity_url_code ?? null;
|
|
1285
|
+
this.nsfwLevel = data.nsfw_level ?? 0;
|
|
1286
|
+
this.discoverySplash = data.discovery_splash ?? null;
|
|
1287
|
+
}
|
|
1288
|
+
iconURL(options = {}) {
|
|
1289
|
+
if (!this.icon)
|
|
1290
|
+
return null;
|
|
1291
|
+
return cdnURL(`/icons/${this.id}`, this.icon, options);
|
|
1292
|
+
}
|
|
1293
|
+
splashURL(options = {}) {
|
|
1294
|
+
if (!this.splash)
|
|
1295
|
+
return null;
|
|
1296
|
+
return cdnURL(`/splashes/${this.id}`, this.splash, options);
|
|
1297
|
+
}
|
|
1298
|
+
bannerURL(options = {}) {
|
|
1299
|
+
if (!this.banner)
|
|
1300
|
+
return null;
|
|
1301
|
+
return cdnURL(`/banners/${this.id}`, this.banner, options);
|
|
1302
|
+
}
|
|
1303
|
+
discoverySplashURL(options = {}) {
|
|
1304
|
+
if (!this.discoverySplash)
|
|
1305
|
+
return null;
|
|
1306
|
+
return cdnURL(`/discovery-splashes/${this.id}`, this.discoverySplash, options);
|
|
1307
|
+
}
|
|
1308
|
+
hasFeature(feature) {
|
|
1309
|
+
return this.features.includes(feature);
|
|
1310
|
+
}
|
|
1311
|
+
get isCommunity() {
|
|
1312
|
+
return this.hasFeature("COMMUNITY");
|
|
1313
|
+
}
|
|
1314
|
+
get hasVanityUrl() {
|
|
1315
|
+
return this.vanityUrlCode !== null;
|
|
1316
|
+
}
|
|
1317
|
+
get vanityURL() {
|
|
1318
|
+
return this.vanityUrlCode ? `https://discord.gg/${this.vanityUrlCode}` : null;
|
|
1319
|
+
}
|
|
1320
|
+
toString() {
|
|
1321
|
+
return this.name;
|
|
992
1322
|
}
|
|
993
1323
|
}
|
|
994
1324
|
// packages/structures/src/permissions.ts
|
|
@@ -1051,16 +1381,167 @@ var InteractionType = {
|
|
|
1051
1381
|
ApplicationCommandAutocomplete: 4,
|
|
1052
1382
|
ModalSubmit: 5
|
|
1053
1383
|
};
|
|
1054
|
-
var
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1384
|
+
var OptionType = {
|
|
1385
|
+
SubCommand: 1,
|
|
1386
|
+
SubCommandGroup: 2,
|
|
1387
|
+
String: 3,
|
|
1388
|
+
Integer: 4,
|
|
1389
|
+
Boolean: 5,
|
|
1390
|
+
User: 6,
|
|
1391
|
+
Channel: 7,
|
|
1392
|
+
Role: 8,
|
|
1393
|
+
Mentionable: 9,
|
|
1394
|
+
Number: 10,
|
|
1395
|
+
Attachment: 11
|
|
1062
1396
|
};
|
|
1063
1397
|
|
|
1398
|
+
class CommandOptions {
|
|
1399
|
+
#options;
|
|
1400
|
+
#resolved;
|
|
1401
|
+
constructor(options, resolved = {}) {
|
|
1402
|
+
let currentOptions = options;
|
|
1403
|
+
let group = null;
|
|
1404
|
+
let sub = null;
|
|
1405
|
+
while (currentOptions.length === 1) {
|
|
1406
|
+
const opt = currentOptions[0];
|
|
1407
|
+
if (opt.type === OptionType.SubCommandGroup) {
|
|
1408
|
+
group = opt.name;
|
|
1409
|
+
currentOptions = opt.options ?? [];
|
|
1410
|
+
} else if (opt.type === OptionType.SubCommand) {
|
|
1411
|
+
sub = opt.name;
|
|
1412
|
+
currentOptions = opt.options ?? [];
|
|
1413
|
+
} else {
|
|
1414
|
+
break;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
this.#options = currentOptions;
|
|
1418
|
+
this.#resolved = resolved;
|
|
1419
|
+
this.#subcommandGroup = group;
|
|
1420
|
+
this.#subcommand = sub;
|
|
1421
|
+
}
|
|
1422
|
+
#subcommandGroup;
|
|
1423
|
+
#subcommand;
|
|
1424
|
+
#get(name) {
|
|
1425
|
+
return this.#options.find((o) => o.name.toLowerCase() === name.toLowerCase());
|
|
1426
|
+
}
|
|
1427
|
+
getSubcommand(required = false) {
|
|
1428
|
+
if (!this.#subcommand && required) {
|
|
1429
|
+
throw new TypeError("No subcommand was provided.");
|
|
1430
|
+
}
|
|
1431
|
+
return this.#subcommand;
|
|
1432
|
+
}
|
|
1433
|
+
getSubcommandGroup(required = false) {
|
|
1434
|
+
if (!this.#subcommandGroup && required) {
|
|
1435
|
+
throw new TypeError("No subcommand group was provided.");
|
|
1436
|
+
}
|
|
1437
|
+
return this.#subcommandGroup;
|
|
1438
|
+
}
|
|
1439
|
+
getString(name, required = false) {
|
|
1440
|
+
const opt = this.#get(name);
|
|
1441
|
+
if (!opt || opt.type !== OptionType.String) {
|
|
1442
|
+
if (required)
|
|
1443
|
+
throw new TypeError(`Required option "${name}" (string) is missing.`);
|
|
1444
|
+
return null;
|
|
1445
|
+
}
|
|
1446
|
+
return typeof opt.value === "string" ? opt.value : null;
|
|
1447
|
+
}
|
|
1448
|
+
getInteger(name, required = false) {
|
|
1449
|
+
const opt = this.#get(name);
|
|
1450
|
+
if (!opt || opt.type !== OptionType.Integer) {
|
|
1451
|
+
if (required)
|
|
1452
|
+
throw new TypeError(`Required option "${name}" (integer) is missing.`);
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
return typeof opt.value === "number" ? Math.trunc(opt.value) : null;
|
|
1456
|
+
}
|
|
1457
|
+
getNumber(name, required = false) {
|
|
1458
|
+
const opt = this.#get(name);
|
|
1459
|
+
if (!opt || opt.type !== OptionType.Number) {
|
|
1460
|
+
if (required)
|
|
1461
|
+
throw new TypeError(`Required option "${name}" (number) is missing.`);
|
|
1462
|
+
return null;
|
|
1463
|
+
}
|
|
1464
|
+
return typeof opt.value === "number" ? opt.value : null;
|
|
1465
|
+
}
|
|
1466
|
+
getBoolean(name, required = false) {
|
|
1467
|
+
const opt = this.#get(name);
|
|
1468
|
+
if (!opt || opt.type !== OptionType.Boolean) {
|
|
1469
|
+
if (required)
|
|
1470
|
+
throw new TypeError(`Required option "${name}" (boolean) is missing.`);
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1473
|
+
return typeof opt.value === "boolean" ? opt.value : null;
|
|
1474
|
+
}
|
|
1475
|
+
getUser(name, required = false) {
|
|
1476
|
+
const opt = this.#get(name);
|
|
1477
|
+
if (!opt || opt.type !== OptionType.User) {
|
|
1478
|
+
if (required)
|
|
1479
|
+
throw new TypeError(`Required option "${name}" (user) is missing.`);
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1482
|
+
const userId = String(opt.value);
|
|
1483
|
+
const resolved = this.#resolved?.users?.[userId] ?? null;
|
|
1484
|
+
if (!resolved && required)
|
|
1485
|
+
throw new TypeError(`Resolved user for option "${name}" is missing.`);
|
|
1486
|
+
return resolved;
|
|
1487
|
+
}
|
|
1488
|
+
getChannel(name, required = false) {
|
|
1489
|
+
const opt = this.#get(name);
|
|
1490
|
+
if (!opt || opt.type !== OptionType.Channel) {
|
|
1491
|
+
if (required)
|
|
1492
|
+
throw new TypeError(`Required option "${name}" (channel) is missing.`);
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1495
|
+
const channelId = String(opt.value);
|
|
1496
|
+
const resolved = this.#resolved?.channels?.[channelId] ?? null;
|
|
1497
|
+
if (!resolved && required)
|
|
1498
|
+
throw new TypeError(`Resolved channel for option "${name}" is missing.`);
|
|
1499
|
+
return resolved;
|
|
1500
|
+
}
|
|
1501
|
+
getRole(name, required = false) {
|
|
1502
|
+
const opt = this.#get(name);
|
|
1503
|
+
if (!opt || opt.type !== OptionType.Role) {
|
|
1504
|
+
if (required)
|
|
1505
|
+
throw new TypeError(`Required option "${name}" (role) is missing.`);
|
|
1506
|
+
return null;
|
|
1507
|
+
}
|
|
1508
|
+
const roleId = String(opt.value);
|
|
1509
|
+
const resolved = this.#resolved?.roles?.[roleId] ?? null;
|
|
1510
|
+
if (!resolved && required)
|
|
1511
|
+
throw new TypeError(`Resolved role for option "${name}" is missing.`);
|
|
1512
|
+
return resolved;
|
|
1513
|
+
}
|
|
1514
|
+
getMentionable(name, required = false) {
|
|
1515
|
+
const opt = this.#get(name);
|
|
1516
|
+
if (!opt || opt.type !== OptionType.Mentionable) {
|
|
1517
|
+
if (required)
|
|
1518
|
+
throw new TypeError(`Required option "${name}" (mentionable) is missing.`);
|
|
1519
|
+
return null;
|
|
1520
|
+
}
|
|
1521
|
+
const id = String(opt.value);
|
|
1522
|
+
const resolved = this.#resolved?.users?.[id] ?? this.#resolved?.roles?.[id] ?? null;
|
|
1523
|
+
if (!resolved && required)
|
|
1524
|
+
throw new TypeError(`Resolved mentionable for option "${name}" is missing.`);
|
|
1525
|
+
return resolved;
|
|
1526
|
+
}
|
|
1527
|
+
getAttachment(name, required = false) {
|
|
1528
|
+
const opt = this.#get(name);
|
|
1529
|
+
if (!opt || opt.type !== OptionType.Attachment) {
|
|
1530
|
+
if (required)
|
|
1531
|
+
throw new TypeError(`Required option "${name}" (attachment) is missing.`);
|
|
1532
|
+
return null;
|
|
1533
|
+
}
|
|
1534
|
+
const attachmentId = String(opt.value);
|
|
1535
|
+
const resolved = this.#resolved?.attachments?.[attachmentId] ?? null;
|
|
1536
|
+
if (!resolved && required)
|
|
1537
|
+
throw new TypeError(`Resolved attachment for option "${name}" is missing.`);
|
|
1538
|
+
return resolved;
|
|
1539
|
+
}
|
|
1540
|
+
get raw() {
|
|
1541
|
+
return this.#options;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1064
1545
|
class InteractionResponse {
|
|
1065
1546
|
type;
|
|
1066
1547
|
data;
|
|
@@ -1174,9 +1655,17 @@ class Interaction {
|
|
|
1174
1655
|
}
|
|
1175
1656
|
|
|
1176
1657
|
class CommandInteraction extends Interaction {
|
|
1658
|
+
options;
|
|
1177
1659
|
get commandName() {
|
|
1178
1660
|
return typeof this.data.data?.name === "string" ? this.data.data.name : "";
|
|
1179
1661
|
}
|
|
1662
|
+
constructor(client, data) {
|
|
1663
|
+
super(client, data);
|
|
1664
|
+
const rawOptions = data.data?.options ?? [];
|
|
1665
|
+
const resolved = data.data?.resolved ?? {};
|
|
1666
|
+
const sub = rawOptions.find((o) => o.type === 1 || o.type === 2);
|
|
1667
|
+
this.options = new CommandOptions(sub?.options ?? rawOptions, resolved);
|
|
1668
|
+
}
|
|
1180
1669
|
}
|
|
1181
1670
|
|
|
1182
1671
|
class ComponentInteraction extends Interaction {
|
|
@@ -1202,14 +1691,67 @@ class ComponentInteraction extends Interaction {
|
|
|
1202
1691
|
return result;
|
|
1203
1692
|
}
|
|
1204
1693
|
}
|
|
1694
|
+
|
|
1695
|
+
class ModalSubmitInteraction extends Interaction {
|
|
1696
|
+
get customId() {
|
|
1697
|
+
return this.data?.data?.custom_id ?? "";
|
|
1698
|
+
}
|
|
1699
|
+
getInputValue(customId) {
|
|
1700
|
+
const rows = this.data?.data?.components ?? [];
|
|
1701
|
+
for (const row of rows) {
|
|
1702
|
+
for (const comp of row.components ?? []) {
|
|
1703
|
+
if (comp.custom_id === customId)
|
|
1704
|
+
return comp.value;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
getRequiredInputValue(customId) {
|
|
1710
|
+
const value = this.getInputValue(customId);
|
|
1711
|
+
if (value === undefined)
|
|
1712
|
+
throw new TypeError(`Modal input "${customId}" was not found in the submission.`);
|
|
1713
|
+
return value;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
class AutocompleteInteraction extends Interaction {
|
|
1718
|
+
get commandName() {
|
|
1719
|
+
return this.data?.data?.name ?? "";
|
|
1720
|
+
}
|
|
1721
|
+
get focusedOption() {
|
|
1722
|
+
const options = this.data?.data?.options ?? [];
|
|
1723
|
+
return findFocused(options);
|
|
1724
|
+
}
|
|
1725
|
+
async respond(choices) {
|
|
1726
|
+
if (!Array.isArray(choices))
|
|
1727
|
+
throw new TypeError("Autocomplete choices must be an array.");
|
|
1728
|
+
const response = new InteractionResponse(InteractionResponseType.Autocomplete, { choices });
|
|
1729
|
+
await this.postResponse(response);
|
|
1730
|
+
this.replied = true;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
function findFocused(options) {
|
|
1734
|
+
for (const opt of options) {
|
|
1735
|
+
if (opt.focused)
|
|
1736
|
+
return { name: opt.name, value: opt.value, type: opt.type };
|
|
1737
|
+
if (Array.isArray(opt.options)) {
|
|
1738
|
+
const found = findFocused(opt.options);
|
|
1739
|
+
if (found)
|
|
1740
|
+
return found;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1205
1745
|
function createInteraction(client, data) {
|
|
1206
1746
|
switch (data.type) {
|
|
1207
1747
|
case InteractionType.ApplicationCommand:
|
|
1208
|
-
case InteractionType.ApplicationCommandAutocomplete:
|
|
1209
1748
|
return new CommandInteraction(client, data);
|
|
1749
|
+
case InteractionType.ApplicationCommandAutocomplete:
|
|
1750
|
+
return new AutocompleteInteraction(client, data);
|
|
1210
1751
|
case InteractionType.MessageComponent:
|
|
1211
|
-
case InteractionType.ModalSubmit:
|
|
1212
1752
|
return new ComponentInteraction(client, data);
|
|
1753
|
+
case InteractionType.ModalSubmit:
|
|
1754
|
+
return new ModalSubmitInteraction(client, data);
|
|
1213
1755
|
default:
|
|
1214
1756
|
return new Interaction(client, data);
|
|
1215
1757
|
}
|
|
@@ -1223,7 +1765,7 @@ class Message extends BaseStructure {
|
|
|
1223
1765
|
channel;
|
|
1224
1766
|
guildId;
|
|
1225
1767
|
flags;
|
|
1226
|
-
|
|
1768
|
+
timestamp;
|
|
1227
1769
|
attachments;
|
|
1228
1770
|
embeds;
|
|
1229
1771
|
mentions;
|
|
@@ -1232,6 +1774,7 @@ class Message extends BaseStructure {
|
|
|
1232
1774
|
mentionEveryone;
|
|
1233
1775
|
type;
|
|
1234
1776
|
reference;
|
|
1777
|
+
components;
|
|
1235
1778
|
referencedMessage;
|
|
1236
1779
|
#context;
|
|
1237
1780
|
constructor(data, context) {
|
|
@@ -1243,9 +1786,10 @@ class Message extends BaseStructure {
|
|
|
1243
1786
|
this.channelId = data.channel_id;
|
|
1244
1787
|
this.guildId = data.guild_id;
|
|
1245
1788
|
this.flags = data.flags ?? 0;
|
|
1246
|
-
this.
|
|
1789
|
+
this.timestamp = new Date(data.timestamp ?? Number((BigInt(this.id) >> 22n) + 1420070400000n));
|
|
1247
1790
|
this.attachments = data.attachments ?? [];
|
|
1248
1791
|
this.embeds = data.embeds ?? [];
|
|
1792
|
+
this.components = data.components ?? [];
|
|
1249
1793
|
this.mentions = (data.mentions ?? []).map((user) => new User(user));
|
|
1250
1794
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1251
1795
|
this.pinned = data.pinned ?? false;
|
|
@@ -1264,16 +1808,14 @@ class Message extends BaseStructure {
|
|
|
1264
1808
|
throw new Error("This message is not attached to a client.");
|
|
1265
1809
|
return this.#context.editMessage(this.channelId, this.id, options);
|
|
1266
1810
|
}
|
|
1811
|
+
update(options) {
|
|
1812
|
+
return this.edit(options);
|
|
1813
|
+
}
|
|
1267
1814
|
delete() {
|
|
1268
1815
|
if (!this.#context)
|
|
1269
1816
|
throw new Error("This message is not attached to a client.");
|
|
1270
1817
|
return this.#context.deleteMessage(this.channelId, this.id);
|
|
1271
1818
|
}
|
|
1272
|
-
crosspost() {
|
|
1273
|
-
if (!this.#context)
|
|
1274
|
-
throw new Error("This message is not attached to a client.");
|
|
1275
|
-
return this.#context.crosspostMessage(this.channelId, this.id);
|
|
1276
|
-
}
|
|
1277
1819
|
reply(options) {
|
|
1278
1820
|
if (!this.#context)
|
|
1279
1821
|
throw new Error("This message is not attached to a client.");
|
|
@@ -1285,6 +1827,36 @@ class Message extends BaseStructure {
|
|
|
1285
1827
|
};
|
|
1286
1828
|
return this.#context.sendMessage(this.channelId, payload);
|
|
1287
1829
|
}
|
|
1830
|
+
crosspost() {
|
|
1831
|
+
if (!this.#context)
|
|
1832
|
+
throw new Error("This message is not attached to a client.");
|
|
1833
|
+
return this.#context.crosspostMessage(this.channelId, this.id);
|
|
1834
|
+
}
|
|
1835
|
+
react(emoji) {
|
|
1836
|
+
if (!this.#context?.addReaction)
|
|
1837
|
+
throw new Error("This message is not attached to a client.");
|
|
1838
|
+
return this.#context.addReaction(this.channelId, this.id, emoji);
|
|
1839
|
+
}
|
|
1840
|
+
removeReaction(emoji, userId) {
|
|
1841
|
+
if (!this.#context)
|
|
1842
|
+
throw new Error("This message is not attached to a client.");
|
|
1843
|
+
return userId ? this.#context.removeReaction?.(this.channelId, this.id, emoji, userId) ?? Promise.reject(new Error("Reaction operations are unavailable.")) : this.#context.removeOwnReaction?.(this.channelId, this.id, emoji) ?? Promise.reject(new Error("Reaction operations are unavailable."));
|
|
1844
|
+
}
|
|
1845
|
+
removeAllReactions() {
|
|
1846
|
+
if (!this.#context?.removeAllReactions)
|
|
1847
|
+
throw new Error("This message is not attached to a client.");
|
|
1848
|
+
return this.#context.removeAllReactions(this.channelId, this.id);
|
|
1849
|
+
}
|
|
1850
|
+
pin() {
|
|
1851
|
+
if (!this.#context?.pinMessage)
|
|
1852
|
+
throw new Error("This message is not attached to a client.");
|
|
1853
|
+
return this.#context.pinMessage(this.channelId, this.id);
|
|
1854
|
+
}
|
|
1855
|
+
unpin() {
|
|
1856
|
+
if (!this.#context?.unpinMessage)
|
|
1857
|
+
throw new Error("This message is not attached to a client.");
|
|
1858
|
+
return this.#context.unpinMessage(this.channelId, this.id);
|
|
1859
|
+
}
|
|
1288
1860
|
}
|
|
1289
1861
|
|
|
1290
1862
|
// packages/managers/src/message.ts
|
|
@@ -1309,10 +1881,7 @@ class MessageManager {
|
|
|
1309
1881
|
}
|
|
1310
1882
|
async fetch(messageId) {
|
|
1311
1883
|
const data = await this.#rest.get(Routes.message(this.#channelId, messageId));
|
|
1312
|
-
|
|
1313
|
-
if (!message)
|
|
1314
|
-
throw new Error("Discord returned no message payload.");
|
|
1315
|
-
return this.upsert(message);
|
|
1884
|
+
return this.upsert(data);
|
|
1316
1885
|
}
|
|
1317
1886
|
fetchMany(messageIds) {
|
|
1318
1887
|
return Promise.all(Array.from(messageIds, (messageId) => this.fetch(messageId)));
|
|
@@ -1353,19 +1922,75 @@ class ThreadManager {
|
|
|
1353
1922
|
return new Channel(data, this.#context);
|
|
1354
1923
|
}
|
|
1355
1924
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1925
|
+
|
|
1926
|
+
// packages/managers/src/user.ts
|
|
1927
|
+
class UserManager extends ResourceManager {
|
|
1358
1928
|
#rest;
|
|
1359
|
-
|
|
1360
|
-
|
|
1929
|
+
constructor(rest) {
|
|
1930
|
+
super(async (id) => new User(await rest.get(Routes.userById(id))), (user) => user.id);
|
|
1361
1931
|
this.#rest = rest;
|
|
1362
|
-
this.#applicationId = applicationId;
|
|
1363
1932
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1933
|
+
async fetchMe() {
|
|
1934
|
+
const data = await this.#rest.get("/users/@me");
|
|
1935
|
+
return this.upsert(new User(data));
|
|
1366
1936
|
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1937
|
+
async editMe(options) {
|
|
1938
|
+
const data = await this.#rest.patch("/users/@me", options);
|
|
1939
|
+
return this.upsert(new User(data));
|
|
1940
|
+
}
|
|
1941
|
+
async leaveGuild(guildId) {
|
|
1942
|
+
await this.#rest.delete(`/users/@me/guilds/${guildId}`);
|
|
1943
|
+
}
|
|
1944
|
+
async createDM(userId) {
|
|
1945
|
+
return this.#rest.post("/users/@me/channels", {
|
|
1946
|
+
recipient_id: userId
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
// packages/managers/src/guild.ts
|
|
1951
|
+
class GuildManager extends ResourceManager {
|
|
1952
|
+
#rest;
|
|
1953
|
+
constructor(rest) {
|
|
1954
|
+
super(async (id) => new Guild(await rest.get(Routes.guild(id))), (guild) => guild.id);
|
|
1955
|
+
this.#rest = rest;
|
|
1956
|
+
}
|
|
1957
|
+
async create(options) {
|
|
1958
|
+
const data = await this.#rest.post("/guilds", options);
|
|
1959
|
+
return this.upsert(new Guild(data));
|
|
1960
|
+
}
|
|
1961
|
+
async edit(id, options) {
|
|
1962
|
+
const data = await this.#rest.patch(Routes.guild(id), options);
|
|
1963
|
+
return this.upsert(new Guild(data));
|
|
1964
|
+
}
|
|
1965
|
+
async deleteGuild(id) {
|
|
1966
|
+
await this.#rest.delete(Routes.guild(id));
|
|
1967
|
+
}
|
|
1968
|
+
async fetchPreview(id) {
|
|
1969
|
+
return this.#rest.get(Routes.guildPreview(id));
|
|
1970
|
+
}
|
|
1971
|
+
async fetchActiveThreads(id) {
|
|
1972
|
+
return this.#rest.get(Routes.guildActiveThreads(id));
|
|
1973
|
+
}
|
|
1974
|
+
async fetchWebhooks(id) {
|
|
1975
|
+
return this.#rest.get(Routes.guildWebhooks(id));
|
|
1976
|
+
}
|
|
1977
|
+
async fetchInvites(id) {
|
|
1978
|
+
return this.#rest.get(Routes.guildInvites(id));
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
// packages/managers/src/application.ts
|
|
1982
|
+
class ApplicationCommandManager {
|
|
1983
|
+
#rest;
|
|
1984
|
+
#applicationId;
|
|
1985
|
+
constructor(rest, applicationId) {
|
|
1986
|
+
this.#rest = rest;
|
|
1987
|
+
this.#applicationId = applicationId;
|
|
1988
|
+
}
|
|
1989
|
+
fetch() {
|
|
1990
|
+
return this.#rest.get(Routes.applicationCommands(this.#applicationId));
|
|
1991
|
+
}
|
|
1992
|
+
create(data) {
|
|
1993
|
+
return this.#rest.post(Routes.applicationCommands(this.#applicationId), data);
|
|
1369
1994
|
}
|
|
1370
1995
|
set(commands) {
|
|
1371
1996
|
return this.#rest.put(Routes.applicationCommands(this.#applicationId), commands);
|
|
@@ -1394,23 +2019,6 @@ class ApplicationCommandManager {
|
|
|
1394
2019
|
}
|
|
1395
2020
|
|
|
1396
2021
|
// packages/managers/src/index.ts
|
|
1397
|
-
class UserManager extends ResourceManager {
|
|
1398
|
-
constructor(rest) {
|
|
1399
|
-
super(async (id) => new User(await rest.get(Routes.userById(id))), (user) => user.id);
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
class GuildManager extends ResourceManager {
|
|
1404
|
-
constructor(rest) {
|
|
1405
|
-
super(async (id) => new Guild(await rest.get(Routes.guild(id))), (guild) => guild.id);
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
var MessageCreateOptions = undefined;
|
|
1409
|
-
var MessageEditOptions = undefined;
|
|
1410
|
-
var MessageFetchOptions = undefined;
|
|
1411
|
-
var MessageThreadOptions = undefined;
|
|
1412
|
-
var ReactionFetchOptions = undefined;
|
|
1413
|
-
|
|
1414
2022
|
class ChannelManager extends Manager {
|
|
1415
2023
|
#rest;
|
|
1416
2024
|
#context;
|
|
@@ -1422,7 +2030,15 @@ class ChannelManager extends Manager {
|
|
|
1422
2030
|
sendMessage: (channelId, options) => this.send(channelId, options),
|
|
1423
2031
|
editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
|
|
1424
2032
|
deleteMessage: (channelId, messageId) => this.deleteMessage(channelId, messageId),
|
|
1425
|
-
crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId)
|
|
2033
|
+
crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId),
|
|
2034
|
+
editChannel: (channelId, options) => this.edit(channelId, options),
|
|
2035
|
+
deleteChannel: (channelId) => this.deleteChannel(channelId),
|
|
2036
|
+
addReaction: (channelId, messageId, emoji) => this.addReaction(channelId, messageId, emoji),
|
|
2037
|
+
removeOwnReaction: (channelId, messageId, emoji) => this.removeOwnReaction(channelId, messageId, emoji),
|
|
2038
|
+
removeReaction: (channelId, messageId, emoji, userId) => this.removeReaction(channelId, messageId, emoji, userId),
|
|
2039
|
+
removeAllReactions: (channelId, messageId) => this.removeAllReactions(channelId, messageId),
|
|
2040
|
+
pinMessage: (channelId, messageId) => this.pinMessage(channelId, messageId),
|
|
2041
|
+
unpinMessage: (channelId, messageId) => this.unpinMessage(channelId, messageId)
|
|
1426
2042
|
};
|
|
1427
2043
|
}
|
|
1428
2044
|
messages(channelId) {
|
|
@@ -1437,8 +2053,7 @@ class ChannelManager extends Manager {
|
|
|
1437
2053
|
return new ThreadManager(this.#rest, this.#context, channelId);
|
|
1438
2054
|
}
|
|
1439
2055
|
async fetch(channelId) {
|
|
1440
|
-
|
|
1441
|
-
return this.upsert(data);
|
|
2056
|
+
return this.upsert(await this.#rest.get(Routes.channel(channelId)));
|
|
1442
2057
|
}
|
|
1443
2058
|
async resolve(channelId) {
|
|
1444
2059
|
return this.get(channelId) ?? this.fetch(channelId);
|
|
@@ -1456,6 +2071,17 @@ class ChannelManager extends Manager {
|
|
|
1456
2071
|
update(channel) {
|
|
1457
2072
|
return this.set(channel.id, channel);
|
|
1458
2073
|
}
|
|
2074
|
+
async create(guildId, options) {
|
|
2075
|
+
return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), options));
|
|
2076
|
+
}
|
|
2077
|
+
async edit(channelId, options) {
|
|
2078
|
+
return this.upsert(await this.#rest.patch(Routes.channel(channelId), options));
|
|
2079
|
+
}
|
|
2080
|
+
async deleteChannel(channelId) {
|
|
2081
|
+
await this.#rest.delete(Routes.channel(channelId));
|
|
2082
|
+
this.#messageManagers.delete(channelId);
|
|
2083
|
+
super.delete(channelId);
|
|
2084
|
+
}
|
|
1459
2085
|
send(channelId, options) {
|
|
1460
2086
|
return this.messages(channelId).send(options);
|
|
1461
2087
|
}
|
|
@@ -1485,8 +2111,7 @@ class ChannelManager extends Manager {
|
|
|
1485
2111
|
return this.messages(data.channel_id).upsert(data);
|
|
1486
2112
|
}
|
|
1487
2113
|
async editMessage(channelId, messageId, options) {
|
|
1488
|
-
|
|
1489
|
-
return this.messages(channelId).upsert(data);
|
|
2114
|
+
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), options));
|
|
1490
2115
|
}
|
|
1491
2116
|
async deleteMessage(channelId, messageId) {
|
|
1492
2117
|
await this.#rest.delete(Routes.message(channelId, messageId));
|
|
@@ -1496,8 +2121,7 @@ class ChannelManager extends Manager {
|
|
|
1496
2121
|
return this.messages(channelId).delete(messageId);
|
|
1497
2122
|
}
|
|
1498
2123
|
async crosspostMessage(channelId, messageId) {
|
|
1499
|
-
|
|
1500
|
-
return this.messages(channelId).upsert(data);
|
|
2124
|
+
return this.messages(channelId).upsert(await this.#rest.post(Routes.crosspostMessage(channelId, messageId)));
|
|
1501
2125
|
}
|
|
1502
2126
|
async bulkDeleteMessages(channelId, messageIds) {
|
|
1503
2127
|
const ids = [...messageIds];
|
|
@@ -1521,7 +2145,7 @@ class ChannelManager extends Manager {
|
|
|
1521
2145
|
return data.map((user) => new User(user));
|
|
1522
2146
|
}
|
|
1523
2147
|
async removeOwnReaction(channelId, messageId, emoji) {
|
|
1524
|
-
await this.#rest.delete(Routes.messageReactions(channelId, messageId, emoji)
|
|
2148
|
+
await this.#rest.delete(`${Routes.messageReactions(channelId, messageId, emoji)}/@me`);
|
|
1525
2149
|
}
|
|
1526
2150
|
async removeReaction(channelId, messageId, emoji, userId) {
|
|
1527
2151
|
await this.#rest.delete(`${Routes.messageReactions(channelId, messageId, emoji)}/${userId}`);
|
|
@@ -1555,126 +2179,6 @@ function isMessageQuery(value) {
|
|
|
1555
2179
|
return typeof value === "object" && value !== null && !(Symbol.iterator in value);
|
|
1556
2180
|
}
|
|
1557
2181
|
|
|
1558
|
-
// packages/types/src/index.ts
|
|
1559
|
-
var GatewayIntentBits = {
|
|
1560
|
-
Guilds: 1 << 0,
|
|
1561
|
-
GuildMembers: 1 << 1,
|
|
1562
|
-
GuildModeration: 1 << 2,
|
|
1563
|
-
GuildExpressions: 1 << 3,
|
|
1564
|
-
GuildIntegrations: 1 << 4,
|
|
1565
|
-
GuildWebhooks: 1 << 5,
|
|
1566
|
-
GuildInvites: 1 << 6,
|
|
1567
|
-
GuildVoiceStates: 1 << 7,
|
|
1568
|
-
GuildPresences: 1 << 8,
|
|
1569
|
-
GuildMessages: 1 << 9,
|
|
1570
|
-
GuildMessageReactions: 1 << 10,
|
|
1571
|
-
GuildMessageTyping: 1 << 11,
|
|
1572
|
-
DirectMessages: 1 << 12,
|
|
1573
|
-
DirectMessageReactions: 1 << 13,
|
|
1574
|
-
DirectMessageTyping: 1 << 14,
|
|
1575
|
-
MessageContent: 1 << 15,
|
|
1576
|
-
GuildScheduledEvents: 1 << 16,
|
|
1577
|
-
AutoModerationConfiguration: 1 << 20,
|
|
1578
|
-
AutoModerationExecution: 1 << 21,
|
|
1579
|
-
GuildMessagePolls: 1 << 24,
|
|
1580
|
-
DirectMessagePolls: 1 << 25
|
|
1581
|
-
};
|
|
1582
|
-
var IntentBits = {
|
|
1583
|
-
guild: 1 << 0,
|
|
1584
|
-
guilds: 1 << 0,
|
|
1585
|
-
guildMembers: 1 << 1,
|
|
1586
|
-
guildModeration: 1 << 2,
|
|
1587
|
-
guildBans: 1 << 2,
|
|
1588
|
-
guildExpressions: 1 << 3,
|
|
1589
|
-
guildEmojis: 1 << 3,
|
|
1590
|
-
guildEmojisAndStickers: 1 << 3,
|
|
1591
|
-
guildIntegrations: 1 << 4,
|
|
1592
|
-
guildWebhooks: 1 << 5,
|
|
1593
|
-
guildInvites: 1 << 6,
|
|
1594
|
-
guildVoiceStates: 1 << 7,
|
|
1595
|
-
guildPresences: 1 << 8,
|
|
1596
|
-
guildMessages: 1 << 9,
|
|
1597
|
-
guildMessage: 1 << 9,
|
|
1598
|
-
guildMessageReactions: 1 << 10,
|
|
1599
|
-
guildMessageTyping: 1 << 11,
|
|
1600
|
-
directMessages: 1 << 12,
|
|
1601
|
-
directMessageReactions: 1 << 13,
|
|
1602
|
-
directMessageTyping: 1 << 14,
|
|
1603
|
-
messageContent: 1 << 15,
|
|
1604
|
-
guildScheduledEvents: 1 << 16,
|
|
1605
|
-
autoModerationConfiguration: 1 << 20,
|
|
1606
|
-
autoModerationExecution: 1 << 21,
|
|
1607
|
-
guildMessagePolls: 1 << 24,
|
|
1608
|
-
directMessagePolls: 1 << 25
|
|
1609
|
-
};
|
|
1610
|
-
var Intents = IntentBits;
|
|
1611
|
-
function resolveGatewayIntents(intents) {
|
|
1612
|
-
if (typeof intents === "number")
|
|
1613
|
-
return intents;
|
|
1614
|
-
if (Array.isArray(intents)) {
|
|
1615
|
-
return intents.reduce((acc, intent) => {
|
|
1616
|
-
return acc | resolveGatewayIntents(intent);
|
|
1617
|
-
}, 0);
|
|
1618
|
-
}
|
|
1619
|
-
if (typeof intents === "string") {
|
|
1620
|
-
if (intents in GatewayIntentBits)
|
|
1621
|
-
return GatewayIntentBits[intents];
|
|
1622
|
-
if (intents in IntentBits)
|
|
1623
|
-
return IntentBits[intents];
|
|
1624
|
-
const lower = intents.charAt(0).toLowerCase() + intents.slice(1);
|
|
1625
|
-
if (lower in IntentBits)
|
|
1626
|
-
return IntentBits[lower];
|
|
1627
|
-
const num = Number(intents);
|
|
1628
|
-
if (!Number.isNaN(num))
|
|
1629
|
-
return num;
|
|
1630
|
-
}
|
|
1631
|
-
return 0;
|
|
1632
|
-
}
|
|
1633
|
-
var MessageFlags = {
|
|
1634
|
-
Crossposted: 1,
|
|
1635
|
-
IsCrosspost: 2,
|
|
1636
|
-
SuppressEmbeds: 4,
|
|
1637
|
-
SourceMessageDeleted: 8,
|
|
1638
|
-
Urgent: 16,
|
|
1639
|
-
HasThread: 32,
|
|
1640
|
-
Ephemeral: 64,
|
|
1641
|
-
Loading: 128,
|
|
1642
|
-
IsComponentsV2: 32768
|
|
1643
|
-
};
|
|
1644
|
-
var ChannelType = {
|
|
1645
|
-
GuildText: 0,
|
|
1646
|
-
DM: 1,
|
|
1647
|
-
GuildVoice: 2,
|
|
1648
|
-
GroupDM: 3,
|
|
1649
|
-
GuildCategory: 4,
|
|
1650
|
-
GuildAnnouncement: 5,
|
|
1651
|
-
AnnouncementThread: 10,
|
|
1652
|
-
PublicThread: 11,
|
|
1653
|
-
PrivateThread: 12,
|
|
1654
|
-
GuildStageVoice: 13,
|
|
1655
|
-
GuildDirectory: 14,
|
|
1656
|
-
GuildForum: 15,
|
|
1657
|
-
GuildMedia: 16
|
|
1658
|
-
};
|
|
1659
|
-
var ApplicationCommandOptionType = {
|
|
1660
|
-
SubCommand: 1,
|
|
1661
|
-
SubCommandGroup: 2,
|
|
1662
|
-
String: 3,
|
|
1663
|
-
Integer: 4,
|
|
1664
|
-
Boolean: 5,
|
|
1665
|
-
User: 6,
|
|
1666
|
-
Channel: 7,
|
|
1667
|
-
Role: 8,
|
|
1668
|
-
Mentionable: 9,
|
|
1669
|
-
Number: 10,
|
|
1670
|
-
Attachment: 11
|
|
1671
|
-
};
|
|
1672
|
-
var ApplicationCommandType = {
|
|
1673
|
-
ChatInput: 1,
|
|
1674
|
-
User: 2,
|
|
1675
|
-
Message: 3
|
|
1676
|
-
};
|
|
1677
|
-
|
|
1678
2182
|
// packages/ws/src/index.ts
|
|
1679
2183
|
var GatewayOpcodes = {
|
|
1680
2184
|
Dispatch: 0,
|
|
@@ -1958,6 +2462,9 @@ class Gateway {
|
|
|
1958
2462
|
this.#setState("READY" /* Ready */);
|
|
1959
2463
|
this.#emit("ready", data);
|
|
1960
2464
|
}
|
|
2465
|
+
this.#emit("RAW", { event: event ?? "UNKNOWN", data });
|
|
2466
|
+
if (this.#closed)
|
|
2467
|
+
return;
|
|
1961
2468
|
this.#emit(event ?? "dispatch", data);
|
|
1962
2469
|
}
|
|
1963
2470
|
#handleHello(data) {
|
|
@@ -2160,694 +2667,9 @@ class Gateway {
|
|
|
2160
2667
|
this.#emit("stateChange", { previous, next });
|
|
2161
2668
|
}
|
|
2162
2669
|
}
|
|
2163
|
-
// packages/builders/src/embed.ts
|
|
2164
|
-
class EmbedBuilder {
|
|
2165
|
-
#data = {};
|
|
2166
|
-
setTitle(value) {
|
|
2167
|
-
this.#data.title = validate(value, 256, "Embed title");
|
|
2168
|
-
return this;
|
|
2169
|
-
}
|
|
2170
|
-
setDescription(value) {
|
|
2171
|
-
this.#data.description = validate(value, 4096, "Embed description");
|
|
2172
|
-
return this;
|
|
2173
|
-
}
|
|
2174
|
-
setURL(value) {
|
|
2175
|
-
this.#data.url = url(value, "Embed URL");
|
|
2176
|
-
return this;
|
|
2177
|
-
}
|
|
2178
|
-
setColor(value) {
|
|
2179
|
-
if (!Number.isInteger(value) || value < 0 || value > 16777215)
|
|
2180
|
-
throw new RangeError("Embed color must be an integer between 0 and 16777215.");
|
|
2181
|
-
this.#data.color = value;
|
|
2182
|
-
return this;
|
|
2183
|
-
}
|
|
2184
|
-
setTimestamp(value = new Date) {
|
|
2185
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
2186
|
-
if (Number.isNaN(date.getTime()))
|
|
2187
|
-
throw new RangeError("Embed timestamp must be a valid date.");
|
|
2188
|
-
this.#data.timestamp = date.toISOString();
|
|
2189
|
-
return this;
|
|
2190
|
-
}
|
|
2191
|
-
setFooter(value) {
|
|
2192
|
-
this.#data.footer = {
|
|
2193
|
-
text: validate(value.text, 2048, "Footer text"),
|
|
2194
|
-
...value.icon_url ? { icon_url: url(value.icon_url, "Footer icon URL") } : {}
|
|
2195
|
-
};
|
|
2196
|
-
return this;
|
|
2197
|
-
}
|
|
2198
|
-
setAuthor(value) {
|
|
2199
|
-
this.#data.author = {
|
|
2200
|
-
name: validate(value.name, 256, "Author name"),
|
|
2201
|
-
...value.url ? { url: url(value.url, "Author URL") } : {},
|
|
2202
|
-
...value.icon_url ? { icon_url: url(value.icon_url, "Author icon URL") } : {}
|
|
2203
|
-
};
|
|
2204
|
-
return this;
|
|
2205
|
-
}
|
|
2206
|
-
setThumbnail(value) {
|
|
2207
|
-
const valueURL = typeof value === "string" ? value : value.url;
|
|
2208
|
-
this.#data.thumbnail = { url: url(valueURL, "Thumbnail URL") };
|
|
2209
|
-
return this;
|
|
2210
|
-
}
|
|
2211
|
-
setImage(value) {
|
|
2212
|
-
const valueURL = typeof value === "string" ? value : value.url;
|
|
2213
|
-
this.#data.image = { url: url(valueURL, "Image URL") };
|
|
2214
|
-
return this;
|
|
2215
|
-
}
|
|
2216
|
-
addFields(...fields) {
|
|
2217
|
-
if (!fields.length)
|
|
2218
|
-
throw new TypeError("At least one embed field is required.");
|
|
2219
|
-
const current = this.#data.fields ?? [];
|
|
2220
|
-
if (current.length + fields.length > 25)
|
|
2221
|
-
throw new RangeError("An embed cannot contain more than 25 fields.");
|
|
2222
|
-
for (const field of fields) {
|
|
2223
|
-
validate(field.name, 256, "Embed field name");
|
|
2224
|
-
validate(field.value, 1024, "Embed field value");
|
|
2225
|
-
}
|
|
2226
|
-
this.#data.fields = [...current, ...fields.map((field) => ({ ...field }))];
|
|
2227
|
-
return this;
|
|
2228
|
-
}
|
|
2229
|
-
setFields(fields) {
|
|
2230
|
-
this.#data.fields = [];
|
|
2231
|
-
return this.addFields(...fields);
|
|
2232
|
-
}
|
|
2233
|
-
spliceFields(index, deleteCount, ...fields) {
|
|
2234
|
-
const current = [...this.#data.fields ?? []];
|
|
2235
|
-
if (!Number.isInteger(index) || !Number.isInteger(deleteCount) || index < 0 || deleteCount < 0)
|
|
2236
|
-
throw new RangeError("Field index and delete count must be non-negative integers.");
|
|
2237
|
-
current.splice(index, deleteCount, ...fields);
|
|
2238
|
-
if (current.length > 25)
|
|
2239
|
-
throw new RangeError("An embed cannot contain more than 25 fields.");
|
|
2240
|
-
this.#data.fields = current;
|
|
2241
|
-
return this;
|
|
2242
|
-
}
|
|
2243
|
-
clearFields() {
|
|
2244
|
-
delete this.#data.fields;
|
|
2245
|
-
return this;
|
|
2246
|
-
}
|
|
2247
|
-
clearTitle() {
|
|
2248
|
-
delete this.#data.title;
|
|
2249
|
-
return this;
|
|
2250
|
-
}
|
|
2251
|
-
clearDescription() {
|
|
2252
|
-
delete this.#data.description;
|
|
2253
|
-
return this;
|
|
2254
|
-
}
|
|
2255
|
-
get data() {
|
|
2256
|
-
return this.toJSON();
|
|
2257
|
-
}
|
|
2258
|
-
toJSON() {
|
|
2259
|
-
return structuredClone(this.#data);
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
function validate(value, max, field) {
|
|
2263
|
-
if (typeof value !== "string" || value.length === 0 || value.length > max)
|
|
2264
|
-
throw new RangeError(`${field} must contain 1-${max} characters.`);
|
|
2265
|
-
return value;
|
|
2266
|
-
}
|
|
2267
|
-
function url(value, field) {
|
|
2268
|
-
try {
|
|
2269
|
-
return new URL(value).toString();
|
|
2270
|
-
} catch (error) {
|
|
2271
|
-
throw new TypeError(`${field} must be a valid URL.`, { cause: error });
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
// packages/builders/src/components.ts
|
|
2275
|
-
var ComponentType = {
|
|
2276
|
-
ActionRow: 1,
|
|
2277
|
-
Button: 2,
|
|
2278
|
-
StringSelect: 3,
|
|
2279
|
-
TextInput: 4,
|
|
2280
|
-
UserSelect: 5,
|
|
2281
|
-
RoleSelect: 6,
|
|
2282
|
-
MentionableSelect: 7,
|
|
2283
|
-
ChannelSelect: 8
|
|
2284
|
-
};
|
|
2285
|
-
var ButtonStyle = {
|
|
2286
|
-
Primary: 1,
|
|
2287
|
-
Secondary: 2,
|
|
2288
|
-
Success: 3,
|
|
2289
|
-
Danger: 4,
|
|
2290
|
-
Link: 5
|
|
2291
|
-
};
|
|
2292
|
-
class ActionRowBuilder {
|
|
2293
|
-
#components = [];
|
|
2294
|
-
addComponents(...components) {
|
|
2295
|
-
if (!components.length)
|
|
2296
|
-
throw new TypeError("At least one component is required.");
|
|
2297
|
-
if (this.#components.length + components.length > 5)
|
|
2298
|
-
throw new RangeError("An action row cannot contain more than 5 components.");
|
|
2299
|
-
this.#components.push(...components);
|
|
2300
|
-
return this;
|
|
2301
|
-
}
|
|
2302
|
-
clearComponents() {
|
|
2303
|
-
this.#components.length = 0;
|
|
2304
|
-
return this;
|
|
2305
|
-
}
|
|
2306
|
-
toJSON() {
|
|
2307
|
-
return {
|
|
2308
|
-
type: ComponentType.ActionRow,
|
|
2309
|
-
components: this.#components.map((component) => component.toJSON())
|
|
2310
|
-
};
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
class StringSelectBuilder {
|
|
2315
|
-
#data = {
|
|
2316
|
-
type: ComponentType.StringSelect
|
|
2317
|
-
};
|
|
2318
|
-
setCustomId(value) {
|
|
2319
|
-
validateText(value, 100, "Component custom ID");
|
|
2320
|
-
this.#data.custom_id = value;
|
|
2321
|
-
return this;
|
|
2322
|
-
}
|
|
2323
|
-
setPlaceholder(value) {
|
|
2324
|
-
validateText(value, 150, "Component placeholder");
|
|
2325
|
-
this.#data.placeholder = value;
|
|
2326
|
-
return this;
|
|
2327
|
-
}
|
|
2328
|
-
setMinValues(value) {
|
|
2329
|
-
validateCount(value, "min_values", 0);
|
|
2330
|
-
this.#data.min_values = value;
|
|
2331
|
-
return this;
|
|
2332
|
-
}
|
|
2333
|
-
setMaxValues(value) {
|
|
2334
|
-
validateCount(value, "max_values", 1);
|
|
2335
|
-
this.#data.max_values = value;
|
|
2336
|
-
return this;
|
|
2337
|
-
}
|
|
2338
|
-
setRequired(value = true) {
|
|
2339
|
-
this.#data.required = value;
|
|
2340
|
-
return this;
|
|
2341
|
-
}
|
|
2342
|
-
setDisabled(value = true) {
|
|
2343
|
-
this.#data.disabled = value;
|
|
2344
|
-
return this;
|
|
2345
|
-
}
|
|
2346
|
-
addOptions(...options) {
|
|
2347
|
-
if (!options.length)
|
|
2348
|
-
throw new TypeError("At least one select option is required.");
|
|
2349
|
-
const current = this.#data.options ?? [];
|
|
2350
|
-
if (current.length + options.length > 25)
|
|
2351
|
-
throw new RangeError("A string select cannot contain more than 25 options.");
|
|
2352
|
-
for (const option of options) {
|
|
2353
|
-
validateText(option.label, 100, "Select option label");
|
|
2354
|
-
validateText(option.value, 100, "Select option value");
|
|
2355
|
-
if (option.description)
|
|
2356
|
-
validateText(option.description, 100, "Select option description");
|
|
2357
|
-
}
|
|
2358
|
-
this.#data.options = [
|
|
2359
|
-
...current,
|
|
2360
|
-
...options.map((option) => ({ ...option }))
|
|
2361
|
-
];
|
|
2362
|
-
return this;
|
|
2363
|
-
}
|
|
2364
|
-
toJSON() {
|
|
2365
|
-
return structuredClone(this.#data);
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
|
|
2369
|
-
class ButtonBuilder {
|
|
2370
|
-
#data = {
|
|
2371
|
-
type: ComponentType.Button,
|
|
2372
|
-
style: ButtonStyle.Secondary
|
|
2373
|
-
};
|
|
2374
|
-
setStyle(style) {
|
|
2375
|
-
this.#data.style = style;
|
|
2376
|
-
if (style === ButtonStyle.Link)
|
|
2377
|
-
delete this.#data.custom_id;
|
|
2378
|
-
return this;
|
|
2379
|
-
}
|
|
2380
|
-
setCustomId(value) {
|
|
2381
|
-
validateText(value, 100, "Button custom ID");
|
|
2382
|
-
if (this.#data.style === ButtonStyle.Link)
|
|
2383
|
-
throw new TypeError("Link buttons cannot use custom IDs.");
|
|
2384
|
-
this.#data.custom_id = value;
|
|
2385
|
-
return this;
|
|
2386
|
-
}
|
|
2387
|
-
setLabel(value) {
|
|
2388
|
-
validateText(value, 80, "Button label");
|
|
2389
|
-
this.#data.label = value;
|
|
2390
|
-
return this;
|
|
2391
|
-
}
|
|
2392
|
-
setURL(value) {
|
|
2393
|
-
validateText(value, 512, "Button URL");
|
|
2394
|
-
let url2;
|
|
2395
|
-
try {
|
|
2396
|
-
url2 = new URL(value);
|
|
2397
|
-
} catch (error) {
|
|
2398
|
-
throw new TypeError("Button URL must be a valid URL.", { cause: error });
|
|
2399
|
-
}
|
|
2400
|
-
this.#data.style = ButtonStyle.Link;
|
|
2401
|
-
delete this.#data.custom_id;
|
|
2402
|
-
this.#data.url = url2.toString();
|
|
2403
|
-
return this;
|
|
2404
|
-
}
|
|
2405
|
-
setEmoji(emoji) {
|
|
2406
|
-
this.#data.emoji = typeof emoji === "string" ? { name: emoji } : { ...emoji };
|
|
2407
|
-
return this;
|
|
2408
|
-
}
|
|
2409
|
-
setDisabled(value = true) {
|
|
2410
|
-
this.#data.disabled = value;
|
|
2411
|
-
return this;
|
|
2412
|
-
}
|
|
2413
|
-
toJSON() {
|
|
2414
|
-
return structuredClone(this.#data);
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
function validateText(value, max, field) {
|
|
2418
|
-
if (typeof value !== "string")
|
|
2419
|
-
throw new TypeError(`${field} must be a string.`);
|
|
2420
|
-
if (!value.trim())
|
|
2421
|
-
throw new RangeError(`${field} must be a non-empty string.`);
|
|
2422
|
-
if (value.length > max)
|
|
2423
|
-
throw new RangeError(`${field} cannot exceed ${max} characters.`);
|
|
2424
|
-
}
|
|
2425
|
-
function validateCount(value, field, min, max = 25) {
|
|
2426
|
-
if (!Number.isInteger(value) || value < min || value > max)
|
|
2427
|
-
throw new RangeError(`${field} must be an integer between ${min} and ${max}.`);
|
|
2428
|
-
}
|
|
2429
|
-
// packages/builders/src/commands.ts
|
|
2430
|
-
var ApplicationCommandOptionType2 = {
|
|
2431
|
-
Subcommand: 1,
|
|
2432
|
-
SubcommandGroup: 2,
|
|
2433
|
-
String: 3,
|
|
2434
|
-
Integer: 4,
|
|
2435
|
-
Boolean: 5,
|
|
2436
|
-
User: 6,
|
|
2437
|
-
Channel: 7,
|
|
2438
|
-
Role: 8,
|
|
2439
|
-
Mentionable: 9,
|
|
2440
|
-
Number: 10,
|
|
2441
|
-
Attachment: 11
|
|
2442
|
-
};
|
|
2443
|
-
|
|
2444
|
-
class SlashCommandBuilder {
|
|
2445
|
-
#data = { type: 1 };
|
|
2446
|
-
setName(name) {
|
|
2447
|
-
validateName(name, "Command name");
|
|
2448
|
-
this.#data.name = name;
|
|
2449
|
-
return this;
|
|
2450
|
-
}
|
|
2451
|
-
setDescription(description) {
|
|
2452
|
-
validateText2(description, "Command description", 100);
|
|
2453
|
-
this.#data.description = description;
|
|
2454
|
-
return this;
|
|
2455
|
-
}
|
|
2456
|
-
setDMPermission(enabled) {
|
|
2457
|
-
this.#data.dm_permission = enabled;
|
|
2458
|
-
return this;
|
|
2459
|
-
}
|
|
2460
|
-
setNSFW(nsfw = true) {
|
|
2461
|
-
this.#data.nsfw = nsfw;
|
|
2462
|
-
return this;
|
|
2463
|
-
}
|
|
2464
|
-
setNsfw(nsfw = true) {
|
|
2465
|
-
return this.setNSFW(nsfw);
|
|
2466
|
-
}
|
|
2467
|
-
setDefaultMemberPermissions(permissions) {
|
|
2468
|
-
this.#data.default_member_permissions = permissions === null ? null : BigInt(permissions).toString();
|
|
2469
|
-
return this;
|
|
2470
|
-
}
|
|
2471
|
-
setIntegrationTypes(...types) {
|
|
2472
|
-
this.#data.integration_types = [...types];
|
|
2473
|
-
return this;
|
|
2474
|
-
}
|
|
2475
|
-
addStringOption(configure) {
|
|
2476
|
-
return this.addOption(configure(new StringOptionBuilder));
|
|
2477
|
-
}
|
|
2478
|
-
addIntegerOption(configure) {
|
|
2479
|
-
return this.addOption(configure(new IntegerOptionBuilder));
|
|
2480
|
-
}
|
|
2481
|
-
addNumberOption(configure) {
|
|
2482
|
-
return this.addOption(configure(new NumberOptionBuilder));
|
|
2483
|
-
}
|
|
2484
|
-
addBooleanOption(configure) {
|
|
2485
|
-
return this.addOption(configure(new BooleanOptionBuilder));
|
|
2486
|
-
}
|
|
2487
|
-
addUserOption(configure) {
|
|
2488
|
-
return this.addOption(configure(new UserOptionBuilder));
|
|
2489
|
-
}
|
|
2490
|
-
addChannelOption(configure) {
|
|
2491
|
-
return this.addOption(configure(new ChannelOptionBuilder));
|
|
2492
|
-
}
|
|
2493
|
-
addRoleOption(configure) {
|
|
2494
|
-
return this.addOption(configure(new RoleOptionBuilder));
|
|
2495
|
-
}
|
|
2496
|
-
addMentionableOption(configure) {
|
|
2497
|
-
return this.addOption(configure(new MentionableOptionBuilder));
|
|
2498
|
-
}
|
|
2499
|
-
addAttachmentOption(configure) {
|
|
2500
|
-
return this.addOption(configure(new AttachmentOptionBuilder));
|
|
2501
|
-
}
|
|
2502
|
-
addSubcommand(configure) {
|
|
2503
|
-
return this.addOption(configure(new SubcommandBuilder));
|
|
2504
|
-
}
|
|
2505
|
-
addSubcommandGroup(configure) {
|
|
2506
|
-
return this.addOption(configure(new SubcommandGroupBuilder));
|
|
2507
|
-
}
|
|
2508
|
-
toJSON() {
|
|
2509
|
-
return structuredClone(this.#data);
|
|
2510
|
-
}
|
|
2511
|
-
addOption(option) {
|
|
2512
|
-
const options = this.#data.options ?? [];
|
|
2513
|
-
if (options.length >= 25)
|
|
2514
|
-
throw new RangeError("An application command cannot contain more than 25 options.");
|
|
2515
|
-
const payload = option.toJSON();
|
|
2516
|
-
if (options.some((existing) => existing.name === payload.name))
|
|
2517
|
-
throw new RangeError(`Duplicate option name: ${String(payload.name)}.`);
|
|
2518
|
-
if (payload.required === true && options.some((existing) => existing.required !== true))
|
|
2519
|
-
throw new RangeError("Required application command options must be placed before optional options.");
|
|
2520
|
-
options.push(payload);
|
|
2521
|
-
this.#data.options = options;
|
|
2522
|
-
return this;
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
|
|
2526
|
-
class CommandOptionBuilder {
|
|
2527
|
-
data;
|
|
2528
|
-
constructor(type) {
|
|
2529
|
-
this.data = { type };
|
|
2530
|
-
}
|
|
2531
|
-
setName(name) {
|
|
2532
|
-
validateName(name, "Option name");
|
|
2533
|
-
this.data.name = name;
|
|
2534
|
-
return this;
|
|
2535
|
-
}
|
|
2536
|
-
setDescription(description) {
|
|
2537
|
-
validateText2(description, "Option description", 100);
|
|
2538
|
-
this.data.description = description;
|
|
2539
|
-
return this;
|
|
2540
|
-
}
|
|
2541
|
-
setRequired(required = true) {
|
|
2542
|
-
this.data.required = required;
|
|
2543
|
-
return this;
|
|
2544
|
-
}
|
|
2545
|
-
setAutocomplete(enabled = true) {
|
|
2546
|
-
this.data.autocomplete = enabled;
|
|
2547
|
-
return this;
|
|
2548
|
-
}
|
|
2549
|
-
toJSON() {
|
|
2550
|
-
return structuredClone(this.data);
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
|
-
class StringOptionBuilder extends CommandOptionBuilder {
|
|
2555
|
-
constructor() {
|
|
2556
|
-
super(ApplicationCommandOptionType2.String);
|
|
2557
|
-
}
|
|
2558
|
-
addChoices(...choices) {
|
|
2559
|
-
const current = this.data.choices ?? [];
|
|
2560
|
-
if (!choices.length)
|
|
2561
|
-
throw new TypeError("At least one choice is required.");
|
|
2562
|
-
if (this.data.autocomplete === true)
|
|
2563
|
-
throw new RangeError("Autocomplete options cannot define choices.");
|
|
2564
|
-
if (current.length + choices.length > 25)
|
|
2565
|
-
throw new RangeError("An option cannot contain more than 25 choices.");
|
|
2566
|
-
for (const choice of choices) {
|
|
2567
|
-
validateText2(choice.name, "Choice name", 100);
|
|
2568
|
-
validateText2(choice.value, "Choice value", 100);
|
|
2569
|
-
}
|
|
2570
|
-
this.data.choices = [
|
|
2571
|
-
...current,
|
|
2572
|
-
...choices.map((choice) => ({ ...choice }))
|
|
2573
|
-
];
|
|
2574
|
-
return this;
|
|
2575
|
-
}
|
|
2576
|
-
setMinLength(value) {
|
|
2577
|
-
validateIntegerRange(value, 0, 6000, "min_length");
|
|
2578
|
-
this.data.min_length = value;
|
|
2579
|
-
return this;
|
|
2580
|
-
}
|
|
2581
|
-
setMaxLength(value) {
|
|
2582
|
-
validateIntegerRange(value, 1, 6000, "max_length");
|
|
2583
|
-
if (this.data.min_length !== undefined && this.data.min_length > value)
|
|
2584
|
-
throw new RangeError("min_length cannot exceed max_length.");
|
|
2585
|
-
this.data.max_length = value;
|
|
2586
|
-
return this;
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
class IntegerOptionBuilder extends CommandOptionBuilder {
|
|
2591
|
-
constructor() {
|
|
2592
|
-
super(ApplicationCommandOptionType2.Integer);
|
|
2593
|
-
}
|
|
2594
|
-
setMinValue(value) {
|
|
2595
|
-
validateNumberRange(value, -9007199254740991, 9007199254740991, "min_value", true);
|
|
2596
|
-
this.data.min_value = value;
|
|
2597
|
-
return this;
|
|
2598
|
-
}
|
|
2599
|
-
setMaxValue(value) {
|
|
2600
|
-
validateNumberRange(value, -9007199254740991, 9007199254740991, "max_value", true);
|
|
2601
|
-
if (this.data.min_value !== undefined && this.data.min_value > value)
|
|
2602
|
-
throw new RangeError("min_value cannot exceed max_value.");
|
|
2603
|
-
this.data.max_value = value;
|
|
2604
|
-
return this;
|
|
2605
|
-
}
|
|
2606
|
-
setAutocomplete(enabled = true) {
|
|
2607
|
-
if (enabled && Array.isArray(this.data.choices) && this.data.choices.length)
|
|
2608
|
-
throw new RangeError("Autocomplete options cannot define choices.");
|
|
2609
|
-
this.data.autocomplete = enabled;
|
|
2610
|
-
return this;
|
|
2611
|
-
}
|
|
2612
|
-
addChoices(...choices) {
|
|
2613
|
-
const current = this.data.choices ?? [];
|
|
2614
|
-
if (!choices.length)
|
|
2615
|
-
throw new TypeError("At least one choice is required.");
|
|
2616
|
-
if (this.data.autocomplete === true)
|
|
2617
|
-
throw new RangeError("Autocomplete options cannot define choices.");
|
|
2618
|
-
if (current.length + choices.length > 25)
|
|
2619
|
-
throw new RangeError("An option cannot contain more than 25 choices.");
|
|
2620
|
-
this.data.choices = [...current, ...choices];
|
|
2621
|
-
return this;
|
|
2622
|
-
}
|
|
2623
|
-
}
|
|
2624
|
-
|
|
2625
|
-
class NumberOptionBuilder extends CommandOptionBuilder {
|
|
2626
|
-
constructor() {
|
|
2627
|
-
super(ApplicationCommandOptionType2.Number);
|
|
2628
|
-
}
|
|
2629
|
-
setMinValue(value) {
|
|
2630
|
-
validateNumberRange(value, -9007199254740991, 9007199254740991, "min_value", false);
|
|
2631
|
-
this.data.min_value = value;
|
|
2632
|
-
return this;
|
|
2633
|
-
}
|
|
2634
|
-
setMaxValue(value) {
|
|
2635
|
-
validateNumberRange(value, -9007199254740991, 9007199254740991, "max_value", false);
|
|
2636
|
-
if (this.data.min_value !== undefined && this.data.min_value > value)
|
|
2637
|
-
throw new RangeError("min_value cannot exceed max_value.");
|
|
2638
|
-
this.data.max_value = value;
|
|
2639
|
-
return this;
|
|
2640
|
-
}
|
|
2641
|
-
setAutocomplete(enabled = true) {
|
|
2642
|
-
if (enabled && Array.isArray(this.data.choices) && this.data.choices.length)
|
|
2643
|
-
throw new RangeError("Autocomplete options cannot define choices.");
|
|
2644
|
-
this.data.autocomplete = enabled;
|
|
2645
|
-
return this;
|
|
2646
|
-
}
|
|
2647
|
-
addChoices(...choices) {
|
|
2648
|
-
const current = this.data.choices ?? [];
|
|
2649
|
-
if (!choices.length)
|
|
2650
|
-
throw new TypeError("At least one choice is required.");
|
|
2651
|
-
if (this.data.autocomplete === true)
|
|
2652
|
-
throw new RangeError("Autocomplete options cannot define choices.");
|
|
2653
|
-
if (current.length + choices.length > 25)
|
|
2654
|
-
throw new RangeError("An option cannot contain more than 25 choices.");
|
|
2655
|
-
this.data.choices = [...current, ...choices];
|
|
2656
|
-
return this;
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
|
-
class BooleanOptionBuilder extends CommandOptionBuilder {
|
|
2661
|
-
constructor() {
|
|
2662
|
-
super(ApplicationCommandOptionType2.Boolean);
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
|
|
2666
|
-
class UserOptionBuilder extends CommandOptionBuilder {
|
|
2667
|
-
constructor() {
|
|
2668
|
-
super(ApplicationCommandOptionType2.User);
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
|
|
2672
|
-
class RoleOptionBuilder extends CommandOptionBuilder {
|
|
2673
|
-
constructor() {
|
|
2674
|
-
super(ApplicationCommandOptionType2.Role);
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
|
|
2678
|
-
class MentionableOptionBuilder extends CommandOptionBuilder {
|
|
2679
|
-
constructor() {
|
|
2680
|
-
super(ApplicationCommandOptionType2.Mentionable);
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
|
|
2684
|
-
class AttachmentOptionBuilder extends CommandOptionBuilder {
|
|
2685
|
-
constructor() {
|
|
2686
|
-
super(ApplicationCommandOptionType2.Attachment);
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
|
|
2690
|
-
class ChannelOptionBuilder extends CommandOptionBuilder {
|
|
2691
|
-
constructor() {
|
|
2692
|
-
super(ApplicationCommandOptionType2.Channel);
|
|
2693
|
-
}
|
|
2694
|
-
addChannelTypes(...types) {
|
|
2695
|
-
if (types.some((type) => !Number.isInteger(type) || type < 0))
|
|
2696
|
-
throw new RangeError("Channel types must be non-negative integers.");
|
|
2697
|
-
this.data.channel_types = [...new Set(types)];
|
|
2698
|
-
return this;
|
|
2699
|
-
}
|
|
2700
|
-
}
|
|
2701
|
-
|
|
2702
|
-
class SubcommandBuilder extends CommandOptionBuilder {
|
|
2703
|
-
constructor() {
|
|
2704
|
-
super(ApplicationCommandOptionType2.Subcommand);
|
|
2705
|
-
}
|
|
2706
|
-
addStringOption(configure) {
|
|
2707
|
-
return this.addChildOption(configure(new StringOptionBuilder));
|
|
2708
|
-
}
|
|
2709
|
-
addIntegerOption(configure) {
|
|
2710
|
-
return this.addChildOption(configure(new IntegerOptionBuilder));
|
|
2711
|
-
}
|
|
2712
|
-
addNumberOption(configure) {
|
|
2713
|
-
return this.addChildOption(configure(new NumberOptionBuilder));
|
|
2714
|
-
}
|
|
2715
|
-
addBooleanOption(configure) {
|
|
2716
|
-
return this.addChildOption(configure(new BooleanOptionBuilder));
|
|
2717
|
-
}
|
|
2718
|
-
addUserOption(configure) {
|
|
2719
|
-
return this.addChildOption(configure(new UserOptionBuilder));
|
|
2720
|
-
}
|
|
2721
|
-
addChannelOption(configure) {
|
|
2722
|
-
return this.addChildOption(configure(new ChannelOptionBuilder));
|
|
2723
|
-
}
|
|
2724
|
-
addRoleOption(configure) {
|
|
2725
|
-
return this.addChildOption(configure(new RoleOptionBuilder));
|
|
2726
|
-
}
|
|
2727
|
-
addMentionableOption(configure) {
|
|
2728
|
-
return this.addChildOption(configure(new MentionableOptionBuilder));
|
|
2729
|
-
}
|
|
2730
|
-
addAttachmentOption(configure) {
|
|
2731
|
-
return this.addChildOption(configure(new AttachmentOptionBuilder));
|
|
2732
|
-
}
|
|
2733
|
-
addChildOption(option) {
|
|
2734
|
-
const options = this.data.options ?? [];
|
|
2735
|
-
if (options.length >= 25)
|
|
2736
|
-
throw new RangeError("A subcommand cannot contain more than 25 options.");
|
|
2737
|
-
const payload = option.toJSON();
|
|
2738
|
-
if (options.some((existing) => existing.name === payload.name))
|
|
2739
|
-
throw new RangeError(`Duplicate option name: ${String(payload.name)}.`);
|
|
2740
|
-
if (payload.required === true && options.some((existing) => existing.required !== true))
|
|
2741
|
-
throw new RangeError("Required subcommand options must be placed before optional options.");
|
|
2742
|
-
if (options.some((existing) => existing.type === ApplicationCommandOptionType2.Subcommand))
|
|
2743
|
-
throw new RangeError("Subcommands cannot contain nested subcommands.");
|
|
2744
|
-
options.push(payload);
|
|
2745
|
-
this.data.options = options;
|
|
2746
|
-
return this;
|
|
2747
|
-
}
|
|
2748
|
-
}
|
|
2749
|
-
|
|
2750
|
-
class SubcommandGroupBuilder extends CommandOptionBuilder {
|
|
2751
|
-
constructor() {
|
|
2752
|
-
super(ApplicationCommandOptionType2.SubcommandGroup);
|
|
2753
|
-
}
|
|
2754
|
-
addSubcommand(configure) {
|
|
2755
|
-
const options = this.data.options ?? [];
|
|
2756
|
-
if (options.length >= 25)
|
|
2757
|
-
throw new RangeError("A subcommand group cannot contain more than 25 subcommands.");
|
|
2758
|
-
const payload = configure(new SubcommandBuilder).toJSON();
|
|
2759
|
-
if (options.some((existing) => existing.name === payload.name))
|
|
2760
|
-
throw new RangeError(`Duplicate subcommand name: ${String(payload.name)}.`);
|
|
2761
|
-
if (payload.type !== ApplicationCommandOptionType2.Subcommand)
|
|
2762
|
-
throw new TypeError("Subcommand group children must be subcommands.");
|
|
2763
|
-
options.push(payload);
|
|
2764
|
-
this.data.options = options;
|
|
2765
|
-
return this;
|
|
2766
|
-
}
|
|
2767
|
-
}
|
|
2768
|
-
function validateName(value, field) {
|
|
2769
|
-
if (!/^[\p{L}\p{N}_-]{1,32}$/u.test(value) || value !== value.toLowerCase())
|
|
2770
|
-
throw new RangeError(`${field} must contain 1-32 lowercase letters, numbers, underscores, or hyphens.`);
|
|
2771
|
-
}
|
|
2772
|
-
function validateText2(value, field, max) {
|
|
2773
|
-
if (typeof value !== "string" || !value.trim() || value.length > max)
|
|
2774
|
-
throw new RangeError(`${field} must contain 1-${max} characters.`);
|
|
2775
|
-
}
|
|
2776
|
-
function validateIntegerRange(value, minimum, maximum, field) {
|
|
2777
|
-
if (!Number.isInteger(value) || value < minimum || value > maximum)
|
|
2778
|
-
throw new RangeError(`${field} must be an integer between ${minimum} and ${maximum}.`);
|
|
2779
|
-
}
|
|
2780
|
-
function validateNumberRange(value, minimum, maximum, field, integerOnly = true) {
|
|
2781
|
-
if (!Number.isFinite(value) || integerOnly && !Number.isInteger(value) || value < minimum || value > maximum)
|
|
2782
|
-
throw new RangeError(`${field} must be ${integerOnly ? "an integer" : "a number"} between ${minimum} and ${maximum}.`);
|
|
2783
|
-
}
|
|
2784
|
-
// packages/core/src/collector.ts
|
|
2785
|
-
import { EventEmitter } from "events";
|
|
2786
|
-
|
|
2787
|
-
class Collector extends EventEmitter {
|
|
2788
|
-
collected = new Map;
|
|
2789
|
-
options;
|
|
2790
|
-
ended = false;
|
|
2791
|
-
endReason;
|
|
2792
|
-
totalProcessed = 0;
|
|
2793
|
-
#timeoutTimer;
|
|
2794
|
-
constructor(options = {}) {
|
|
2795
|
-
super();
|
|
2796
|
-
this.options = options;
|
|
2797
|
-
if (options.time && options.time > 0) {
|
|
2798
|
-
this.#timeoutTimer = setTimeout(() => {
|
|
2799
|
-
this.stop("time");
|
|
2800
|
-
}, options.time);
|
|
2801
|
-
}
|
|
2802
|
-
}
|
|
2803
|
-
async handle(key, item) {
|
|
2804
|
-
if (this.ended)
|
|
2805
|
-
return false;
|
|
2806
|
-
this.totalProcessed++;
|
|
2807
|
-
if (this.options.filter) {
|
|
2808
|
-
const passed = await this.options.filter(item);
|
|
2809
|
-
if (!passed)
|
|
2810
|
-
return false;
|
|
2811
|
-
}
|
|
2812
|
-
this.collected.set(key, item);
|
|
2813
|
-
this.emit("collect", item);
|
|
2814
|
-
if (this.options.max && this.collected.size >= this.options.max) {
|
|
2815
|
-
this.stop("limit");
|
|
2816
|
-
return true;
|
|
2817
|
-
}
|
|
2818
|
-
if (this.options.maxProcessed && this.totalProcessed >= this.options.maxProcessed) {
|
|
2819
|
-
this.stop("processedLimit");
|
|
2820
|
-
return true;
|
|
2821
|
-
}
|
|
2822
|
-
return true;
|
|
2823
|
-
}
|
|
2824
|
-
stop(reason = "user") {
|
|
2825
|
-
if (this.ended)
|
|
2826
|
-
return;
|
|
2827
|
-
this.ended = true;
|
|
2828
|
-
this.endReason = reason;
|
|
2829
|
-
if (this.#timeoutTimer)
|
|
2830
|
-
clearTimeout(this.#timeoutTimer);
|
|
2831
|
-
this.emit("end", this.collected, reason);
|
|
2832
|
-
this.removeAllListeners();
|
|
2833
|
-
}
|
|
2834
|
-
next() {
|
|
2835
|
-
return new Promise((resolve, reject) => {
|
|
2836
|
-
if (this.ended) {
|
|
2837
|
-
return reject(new Error(`Collector already ended: ${this.endReason ?? "unknown"}`));
|
|
2838
|
-
}
|
|
2839
|
-
this.once("collect", (item) => {
|
|
2840
|
-
resolve(item);
|
|
2841
|
-
});
|
|
2842
|
-
this.once("end", (_collected, reason) => {
|
|
2843
|
-
reject(new Error(`Collector ended before item was collected: ${reason}`));
|
|
2844
|
-
});
|
|
2845
|
-
});
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
2670
|
|
|
2849
2671
|
// packages/core/src/index.ts
|
|
2850
|
-
class
|
|
2672
|
+
class EventEmitter {
|
|
2851
2673
|
#listeners = new Map;
|
|
2852
2674
|
on(event, listener) {
|
|
2853
2675
|
if (typeof listener !== "function")
|
|
@@ -2892,11 +2714,11 @@ class EventEmitter2 {
|
|
|
2892
2714
|
return true;
|
|
2893
2715
|
}
|
|
2894
2716
|
#handleError(event, error) {
|
|
2895
|
-
if (event === "error")
|
|
2717
|
+
if (event === "error" /* Error */)
|
|
2896
2718
|
return;
|
|
2897
2719
|
const normalized = error instanceof Error ? error : new Error(String(error), { cause: error });
|
|
2898
2720
|
for (const listener of [
|
|
2899
|
-
...this.#listeners.get("error") ?? []
|
|
2721
|
+
...this.#listeners.get("error" /* Error */) ?? []
|
|
2900
2722
|
]) {
|
|
2901
2723
|
try {
|
|
2902
2724
|
listener(normalized);
|
|
@@ -2905,7 +2727,7 @@ class EventEmitter2 {
|
|
|
2905
2727
|
}
|
|
2906
2728
|
}
|
|
2907
2729
|
|
|
2908
|
-
class Client extends
|
|
2730
|
+
class Client extends EventEmitter {
|
|
2909
2731
|
options;
|
|
2910
2732
|
rest;
|
|
2911
2733
|
users;
|
|
@@ -2924,6 +2746,12 @@ class Client extends EventEmitter2 {
|
|
|
2924
2746
|
get uptime() {
|
|
2925
2747
|
return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
|
|
2926
2748
|
}
|
|
2749
|
+
isReady() {
|
|
2750
|
+
return this.state === "ready";
|
|
2751
|
+
}
|
|
2752
|
+
setPresence(data) {
|
|
2753
|
+
return this.#gateway.setPresence?.(data) ?? false;
|
|
2754
|
+
}
|
|
2927
2755
|
#gateway;
|
|
2928
2756
|
#resourceContext;
|
|
2929
2757
|
constructor(options) {
|
|
@@ -2941,7 +2769,15 @@ class Client extends EventEmitter2 {
|
|
|
2941
2769
|
sendMessage: (channelId, options2) => this.channels.send(channelId, options2),
|
|
2942
2770
|
editMessage: (channelId, messageId, options2) => this.channels.editMessage(channelId, messageId, options2),
|
|
2943
2771
|
deleteMessage: (channelId, messageId) => this.channels.deleteMessage(channelId, messageId),
|
|
2944
|
-
crosspostMessage: (channelId, messageId) => this.channels.crosspostMessage(channelId, messageId)
|
|
2772
|
+
crosspostMessage: (channelId, messageId) => this.channels.crosspostMessage(channelId, messageId),
|
|
2773
|
+
editChannel: (channelId, options2) => this.channels.edit(channelId, options2),
|
|
2774
|
+
deleteChannel: (channelId) => this.channels.deleteChannel(channelId),
|
|
2775
|
+
addReaction: (channelId, messageId, emoji) => this.channels.addReaction(channelId, messageId, emoji),
|
|
2776
|
+
removeOwnReaction: (channelId, messageId, emoji) => this.channels.removeOwnReaction(channelId, messageId, emoji),
|
|
2777
|
+
removeReaction: (channelId, messageId, emoji, userId) => this.channels.removeReaction(channelId, messageId, emoji, userId),
|
|
2778
|
+
removeAllReactions: (channelId, messageId) => this.channels.removeAllReactions(channelId, messageId),
|
|
2779
|
+
pinMessage: (channelId, messageId) => this.channels.pinMessage(channelId, messageId),
|
|
2780
|
+
unpinMessage: (channelId, messageId) => this.channels.unpinMessage(channelId, messageId)
|
|
2945
2781
|
};
|
|
2946
2782
|
this.#gateway = new Gateway({
|
|
2947
2783
|
token: options.token,
|
|
@@ -2956,233 +2792,192 @@ class Client extends EventEmitter2 {
|
|
|
2956
2792
|
this.state = "ready";
|
|
2957
2793
|
const appId = ready.application?.id ?? this.user.id;
|
|
2958
2794
|
this.application.commands = new ApplicationCommandManager(this.rest, appId);
|
|
2959
|
-
this.emit("ready"
|
|
2795
|
+
this.emit("ready" /* Ready */, this.user);
|
|
2960
2796
|
});
|
|
2961
|
-
this.#gateway.on("open", () => this.emit("open"));
|
|
2797
|
+
this.#gateway.on("open", () => this.emit("open" /* Open */));
|
|
2962
2798
|
this.#gateway.on("close", (data) => {
|
|
2963
2799
|
if (this.state !== "destroyed")
|
|
2964
2800
|
this.state = "idle";
|
|
2965
|
-
this.emit("close"
|
|
2801
|
+
this.emit("close" /* Close */, data);
|
|
2966
2802
|
});
|
|
2967
2803
|
this.#gateway.on("MESSAGE_CREATE", (data) => {
|
|
2968
2804
|
const message = new Message(data, this.#resourceContext);
|
|
2969
2805
|
this.channels.set(message.channelId, message.channel);
|
|
2970
2806
|
this.users.set(message.author.id, message.author);
|
|
2971
|
-
this.emit("messageCreate"
|
|
2807
|
+
this.emit("messageCreate" /* MessageCreate */, message);
|
|
2972
2808
|
});
|
|
2973
2809
|
this.#gateway.on("MESSAGE_UPDATE", (data) => {
|
|
2974
2810
|
const message = new Message(data, this.#resourceContext);
|
|
2975
2811
|
this.channels.set(message.channelId, message.channel);
|
|
2976
2812
|
this.users.set(message.author.id, message.author);
|
|
2977
|
-
this.emit("messageUpdate"
|
|
2813
|
+
this.emit("messageUpdate" /* MessageUpdate */, message);
|
|
2978
2814
|
});
|
|
2979
|
-
this.#gateway.on("MESSAGE_DELETE", (data) => this.emit("messageDelete"
|
|
2980
|
-
this.#gateway.on("MESSAGE_DELETE_BULK", (data) => this.emit("messageDeleteBulk"
|
|
2815
|
+
this.#gateway.on("MESSAGE_DELETE", (data) => this.emit("messageDelete" /* MessageDelete */, data));
|
|
2816
|
+
this.#gateway.on("MESSAGE_DELETE_BULK", (data) => this.emit("messageDeleteBulk" /* MessageDeleteBulk */, data));
|
|
2817
|
+
this.#gateway.on("MESSAGE_REACTION_ADD", (data) => this.emit("messageReactionAdd" /* MessageReactionAdd */, data));
|
|
2818
|
+
this.#gateway.on("MESSAGE_REACTION_REMOVE", (data) => this.emit("messageReactionRemove" /* MessageReactionRemove */, data));
|
|
2819
|
+
this.#gateway.on("MESSAGE_REACTION_REMOVE_ALL", (data) => this.emit("messageReactionRemoveAll" /* MessageReactionRemoveAll */, data));
|
|
2820
|
+
this.#gateway.on("MESSAGE_REACTION_REMOVE_EMOJI", (data) => this.emit("messageReactionRemoveEmoji" /* MessageReactionRemoveEmoji */, data));
|
|
2821
|
+
this.#gateway.on("MESSAGE_POLL_VOTE_ADD", (data) => this.emit("messagePollVoteAdd" /* MessagePollVoteAdd */, data));
|
|
2822
|
+
this.#gateway.on("MESSAGE_POLL_VOTE_REMOVE", (data) => this.emit("messagePollVoteRemove" /* MessagePollVoteRemove */, data));
|
|
2981
2823
|
this.#gateway.on("GUILD_CREATE", (data) => {
|
|
2982
|
-
const guild = new Guild(data);
|
|
2983
|
-
this.guilds.set(guild.id, guild);
|
|
2984
2824
|
const payload = data;
|
|
2825
|
+
if (payload.unavailable) {
|
|
2826
|
+
this.emit("guildUnavailable" /* GuildUnavailable */, payload);
|
|
2827
|
+
return;
|
|
2828
|
+
}
|
|
2829
|
+
const guild = new Guild(payload);
|
|
2830
|
+
this.guilds.set(guild.id, guild);
|
|
2985
2831
|
for (const member of payload.members ?? [])
|
|
2986
2832
|
this.users.set(member.user.id, new User(member.user));
|
|
2987
2833
|
for (const channelData of [
|
|
2988
2834
|
...payload.channels ?? [],
|
|
2989
2835
|
...payload.threads ?? []
|
|
2990
|
-
])
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
}
|
|
2994
|
-
this.emit("guildCreate", data);
|
|
2836
|
+
])
|
|
2837
|
+
this.channels.set(channelData.id, new Channel(channelData, this.#resourceContext));
|
|
2838
|
+
this.emit("guildCreate" /* GuildCreate */, payload);
|
|
2995
2839
|
});
|
|
2996
2840
|
this.#gateway.on("GUILD_UPDATE", (data) => {
|
|
2997
2841
|
const guild = new Guild(data);
|
|
2998
2842
|
this.guilds.update(guild);
|
|
2999
|
-
this.emit("guildUpdate"
|
|
2843
|
+
this.emit("guildUpdate" /* GuildUpdate */, data);
|
|
3000
2844
|
});
|
|
3001
2845
|
this.#gateway.on("GUILD_DELETE", (data) => {
|
|
3002
2846
|
const payload = data;
|
|
3003
|
-
if (
|
|
3004
|
-
this.
|
|
3005
|
-
|
|
2847
|
+
if (payload.unavailable) {
|
|
2848
|
+
this.emit("guildUnavailable" /* GuildUnavailable */, payload);
|
|
2849
|
+
return;
|
|
2850
|
+
}
|
|
2851
|
+
this.guilds.delete(payload.id);
|
|
2852
|
+
this.emit("guildDelete" /* GuildDelete */, payload);
|
|
2853
|
+
});
|
|
2854
|
+
this.#gateway.on("GUILD_MEMBER_ADD", (data) => {
|
|
2855
|
+
const member = data;
|
|
2856
|
+
this.users.set(member.user.id, new User(member.user));
|
|
2857
|
+
this.emit("guildMemberAdd" /* GuildMemberAdd */, member);
|
|
3006
2858
|
});
|
|
2859
|
+
this.#gateway.on("GUILD_MEMBER_UPDATE", (data) => {
|
|
2860
|
+
const member = data;
|
|
2861
|
+
this.users.set(member.user.id, new User(member.user));
|
|
2862
|
+
this.emit("guildMemberUpdate" /* GuildMemberUpdate */, member);
|
|
2863
|
+
});
|
|
2864
|
+
this.#gateway.on("GUILD_MEMBER_REMOVE", (data) => this.emit("guildMemberRemove" /* GuildMemberRemove */, data));
|
|
2865
|
+
this.#gateway.on("GUILD_MEMBERS_CHUNK", (data) => this.emit("guildMembersChunk" /* GuildMembersChunk */, data));
|
|
2866
|
+
this.#gateway.on("GUILD_BAN_ADD", (data) => this.emit("guildBanAdd" /* GuildBanAdd */, data));
|
|
2867
|
+
this.#gateway.on("GUILD_BAN_REMOVE", (data) => this.emit("guildBanRemove" /* GuildBanRemove */, data));
|
|
2868
|
+
this.#gateway.on("GUILD_ROLE_CREATE", (data) => this.emit("guildRoleCreate" /* GuildRoleCreate */, data));
|
|
2869
|
+
this.#gateway.on("GUILD_ROLE_UPDATE", (data) => this.emit("guildRoleUpdate" /* GuildRoleUpdate */, data));
|
|
2870
|
+
this.#gateway.on("GUILD_ROLE_DELETE", (data) => this.emit("guildRoleDelete" /* GuildRoleDelete */, data));
|
|
2871
|
+
this.#gateway.on("GUILD_EMOJIS_UPDATE", (data) => this.emit("guildEmojisUpdate" /* GuildEmojisUpdate */, data));
|
|
2872
|
+
this.#gateway.on("GUILD_STICKERS_UPDATE", (data) => this.emit("guildStickersUpdate" /* GuildStickersUpdate */, data));
|
|
2873
|
+
this.#gateway.on("GUILD_INTEGRATIONS_UPDATE", (data) => this.emit("guildIntegrationsUpdate" /* GuildIntegrationsUpdate */, data));
|
|
2874
|
+
this.#gateway.on("GUILD_SCHEDULED_EVENT_CREATE", (data) => this.emit("guildScheduledEventCreate" /* GuildScheduledEventCreate */, data));
|
|
2875
|
+
this.#gateway.on("GUILD_SCHEDULED_EVENT_UPDATE", (data) => this.emit("guildScheduledEventUpdate" /* GuildScheduledEventUpdate */, data));
|
|
2876
|
+
this.#gateway.on("GUILD_SCHEDULED_EVENT_DELETE", (data) => this.emit("guildScheduledEventDelete" /* GuildScheduledEventDelete */, data));
|
|
2877
|
+
this.#gateway.on("GUILD_SCHEDULED_EVENT_USER_ADD", (data) => this.emit("guildScheduledEventUserAdd" /* GuildScheduledEventUserAdd */, data));
|
|
2878
|
+
this.#gateway.on("GUILD_SCHEDULED_EVENT_USER_REMOVE", (data) => this.emit("guildScheduledEventUserRemove" /* GuildScheduledEventUserRemove */, data));
|
|
2879
|
+
this.#gateway.on("AUTO_MODERATION_RULE_CREATE", (data) => this.emit("autoModerationRuleCreate" /* AutoModerationRuleCreate */, data));
|
|
2880
|
+
this.#gateway.on("AUTO_MODERATION_RULE_UPDATE", (data) => this.emit("autoModerationRuleUpdate" /* AutoModerationRuleUpdate */, data));
|
|
2881
|
+
this.#gateway.on("AUTO_MODERATION_RULE_DELETE", (data) => this.emit("autoModerationRuleDelete" /* AutoModerationRuleDelete */, data));
|
|
2882
|
+
this.#gateway.on("AUTO_MODERATION_ACTION_EXECUTION", (data) => this.emit("autoModerationActionExecution" /* AutoModerationActionExecution */, data));
|
|
3007
2883
|
this.#gateway.on("CHANNEL_CREATE", (data) => {
|
|
3008
2884
|
const channel = new Channel(data, this.#resourceContext);
|
|
3009
2885
|
this.channels.update(channel);
|
|
3010
|
-
this.emit("channelCreate"
|
|
2886
|
+
this.emit("channelCreate" /* ChannelCreate */, channel);
|
|
3011
2887
|
});
|
|
3012
2888
|
this.#gateway.on("CHANNEL_UPDATE", (data) => {
|
|
3013
2889
|
const channel = new Channel(data, this.#resourceContext);
|
|
3014
2890
|
this.channels.update(channel);
|
|
3015
|
-
this.emit("channelUpdate"
|
|
2891
|
+
this.emit("channelUpdate" /* ChannelUpdate */, channel);
|
|
3016
2892
|
});
|
|
3017
2893
|
this.#gateway.on("CHANNEL_DELETE", (data) => {
|
|
3018
2894
|
const payload = data;
|
|
3019
2895
|
this.channels.delete(payload.id);
|
|
3020
|
-
this.emit("channelDelete"
|
|
2896
|
+
this.emit("channelDelete" /* ChannelDelete */, payload);
|
|
3021
2897
|
});
|
|
2898
|
+
this.#gateway.on("CHANNEL_PINS_UPDATE", (data) => this.emit("channelPinsUpdate" /* ChannelPinsUpdate */, data));
|
|
3022
2899
|
this.#gateway.on("THREAD_CREATE", (data) => {
|
|
3023
2900
|
const channel = new Channel(data, this.#resourceContext);
|
|
3024
2901
|
this.channels.update(channel);
|
|
3025
|
-
this.emit("threadCreate"
|
|
2902
|
+
this.emit("threadCreate" /* ThreadCreate */, channel);
|
|
3026
2903
|
});
|
|
3027
2904
|
this.#gateway.on("THREAD_UPDATE", (data) => {
|
|
3028
2905
|
const channel = new Channel(data, this.#resourceContext);
|
|
3029
2906
|
this.channels.update(channel);
|
|
3030
|
-
this.emit("threadUpdate"
|
|
2907
|
+
this.emit("threadUpdate" /* ThreadUpdate */, channel);
|
|
3031
2908
|
});
|
|
3032
2909
|
this.#gateway.on("THREAD_DELETE", (data) => {
|
|
3033
2910
|
const payload = data;
|
|
3034
2911
|
this.channels.delete(payload.id);
|
|
3035
|
-
this.emit("threadDelete"
|
|
3036
|
-
});
|
|
3037
|
-
this.#gateway.on("GUILD_MEMBER_ADD", (data) => {
|
|
3038
|
-
const member = data;
|
|
3039
|
-
this.users.set(member.user.id, new User(member.user));
|
|
3040
|
-
this.emit("guildMemberAdd", member);
|
|
2912
|
+
this.emit("threadDelete" /* ThreadDelete */, payload);
|
|
3041
2913
|
});
|
|
3042
|
-
this.#gateway.on("
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
this.#gateway.on("
|
|
3048
|
-
this.#gateway.on("
|
|
3049
|
-
this.#gateway.on("
|
|
3050
|
-
this.#gateway.on("
|
|
3051
|
-
this.#gateway.on("
|
|
3052
|
-
this.#gateway.on("
|
|
3053
|
-
this.#gateway.on("
|
|
3054
|
-
this.#gateway.on("
|
|
3055
|
-
this.#gateway.on("
|
|
3056
|
-
this.#gateway.on("
|
|
3057
|
-
this.#gateway.on("
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
"MESSAGE_CREATE",
|
|
3061
|
-
"MESSAGE_UPDATE",
|
|
3062
|
-
"MESSAGE_DELETE",
|
|
3063
|
-
"MESSAGE_DELETE_BULK",
|
|
3064
|
-
"GUILD_CREATE",
|
|
3065
|
-
"GUILD_UPDATE",
|
|
3066
|
-
"GUILD_DELETE",
|
|
3067
|
-
"CHANNEL_CREATE",
|
|
3068
|
-
"CHANNEL_UPDATE",
|
|
3069
|
-
"CHANNEL_DELETE",
|
|
3070
|
-
"THREAD_CREATE",
|
|
3071
|
-
"THREAD_UPDATE",
|
|
3072
|
-
"THREAD_DELETE",
|
|
3073
|
-
"GUILD_MEMBER_ADD",
|
|
3074
|
-
"GUILD_MEMBER_UPDATE",
|
|
3075
|
-
"GUILD_MEMBER_REMOVE",
|
|
3076
|
-
"MESSAGE_REACTION_ADD",
|
|
3077
|
-
"MESSAGE_REACTION_REMOVE",
|
|
3078
|
-
"MESSAGE_REACTION_REMOVE_ALL",
|
|
3079
|
-
"INTERACTION_CREATE",
|
|
3080
|
-
"GUILD_ROLE_CREATE",
|
|
3081
|
-
"GUILD_ROLE_UPDATE",
|
|
3082
|
-
"GUILD_ROLE_DELETE",
|
|
3083
|
-
"GUILD_BAN_ADD",
|
|
3084
|
-
"GUILD_BAN_REMOVE",
|
|
3085
|
-
"GUILD_EMOJIS_UPDATE"
|
|
3086
|
-
])
|
|
3087
|
-
this.#gateway.on(event, (data) => this.emit("raw", { event, data }));
|
|
3088
|
-
this.#gateway.on("error", (data) => this.emit("error", data));
|
|
3089
|
-
}
|
|
3090
|
-
isReady() {
|
|
3091
|
-
return this.state === "ready" && this.user !== undefined && this.readyAt !== undefined;
|
|
3092
|
-
}
|
|
3093
|
-
async login() {
|
|
2914
|
+
this.#gateway.on("THREAD_LIST_SYNC", (data) => this.emit("threadListSync" /* ThreadListSync */, data));
|
|
2915
|
+
this.#gateway.on("THREAD_MEMBERS_UPDATE", (data) => this.emit("threadMembersUpdate" /* ThreadMembersUpdate */, data));
|
|
2916
|
+
this.#gateway.on("THREAD_MEMBER_UPDATE", (data) => this.emit("threadMemberUpdate" /* ThreadMemberUpdate */, data));
|
|
2917
|
+
this.#gateway.on("STAGE_INSTANCE_CREATE", (data) => this.emit("stageInstanceCreate" /* StageInstanceCreate */, data));
|
|
2918
|
+
this.#gateway.on("STAGE_INSTANCE_UPDATE", (data) => this.emit("stageInstanceUpdate" /* StageInstanceUpdate */, data));
|
|
2919
|
+
this.#gateway.on("STAGE_INSTANCE_DELETE", (data) => this.emit("stageInstanceDelete" /* StageInstanceDelete */, data));
|
|
2920
|
+
this.#gateway.on("INVITE_CREATE", (data) => this.emit("inviteCreate" /* InviteCreate */, data));
|
|
2921
|
+
this.#gateway.on("INVITE_DELETE", (data) => this.emit("inviteDelete" /* InviteDelete */, data));
|
|
2922
|
+
this.#gateway.on("WEBHOOKS_UPDATE", (data) => this.emit("webhooksUpdate" /* WebhooksUpdate */, data));
|
|
2923
|
+
this.#gateway.on("VOICE_STATE_UPDATE", (data) => this.emit("voiceStateUpdate" /* VoiceStateUpdate */, data));
|
|
2924
|
+
this.#gateway.on("VOICE_SERVER_UPDATE", (data) => this.emit("voiceServerUpdate" /* VoiceServerUpdate */, data));
|
|
2925
|
+
this.#gateway.on("PRESENCE_UPDATE", (data) => this.emit("presenceUpdate" /* PresenceUpdate */, data));
|
|
2926
|
+
this.#gateway.on("TYPING_START", (data) => this.emit("typingStart" /* TypingStart */, data));
|
|
2927
|
+
this.#gateway.on("INTERACTION_CREATE", (data) => this.emit("interactionCreate" /* InteractionCreate */, createInteraction(this, data)));
|
|
2928
|
+
this.#gateway.on("RAW", (data) => this.emit("raw" /* Raw */, data));
|
|
2929
|
+
this.#gateway.on("error", (error) => this.emit("error" /* Error */, error));
|
|
2930
|
+
}
|
|
2931
|
+
async login(token) {
|
|
3094
2932
|
if (this.state === "destroyed")
|
|
3095
2933
|
throw new Error("Cannot login a destroyed client.");
|
|
3096
|
-
if (
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
try {
|
|
3100
|
-
this.user = await this.rest.get(Routes.user());
|
|
3101
|
-
this.users.set(this.user.id, new User(this.user));
|
|
3102
|
-
await this.#gateway.connect();
|
|
3103
|
-
} catch (error) {
|
|
3104
|
-
this.state = "idle";
|
|
3105
|
-
throw error;
|
|
2934
|
+
if (token?.trim()) {
|
|
2935
|
+
this.rest.setToken(token);
|
|
2936
|
+
this.options.token = token;
|
|
3106
2937
|
}
|
|
2938
|
+
const usedToken = this.options.token;
|
|
2939
|
+
if (!usedToken?.trim())
|
|
2940
|
+
throw new TypeError("A bot token is required to log in.");
|
|
2941
|
+
this.state = "connecting";
|
|
2942
|
+
await this.#gateway.connect();
|
|
2943
|
+
return usedToken;
|
|
3107
2944
|
}
|
|
3108
2945
|
destroy() {
|
|
3109
|
-
if (this.state === "destroyed")
|
|
3110
|
-
return;
|
|
3111
|
-
this.#gateway.close();
|
|
3112
|
-
this.users.clear();
|
|
3113
|
-
this.guilds.clear();
|
|
3114
|
-
this.channels.clear();
|
|
3115
2946
|
this.state = "destroyed";
|
|
3116
|
-
this.
|
|
3117
|
-
this.user = undefined;
|
|
2947
|
+
this.#gateway.close();
|
|
3118
2948
|
}
|
|
3119
2949
|
postInteractionResponse(id, token, response) {
|
|
3120
2950
|
return this.rest.post(Routes.interactionCallback(id, token), response.toJSON());
|
|
3121
2951
|
}
|
|
3122
2952
|
editInteractionReply(token, data) {
|
|
3123
|
-
if (!this.user
|
|
3124
|
-
|
|
2953
|
+
if (!this.user)
|
|
2954
|
+
return Promise.reject(new Error("Client is unauthenticated."));
|
|
3125
2955
|
return this.rest.patch(Routes.interactionOriginalResponse(this.user.id, token), data);
|
|
3126
2956
|
}
|
|
3127
|
-
|
|
3128
|
-
if (!this.user
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
}
|
|
3132
|
-
setPresence(presence) {
|
|
3133
|
-
return this.#gateway.setPresence(presence);
|
|
2957
|
+
deleteInteractionReply(token) {
|
|
2958
|
+
if (!this.user)
|
|
2959
|
+
return Promise.reject(new Error("Client is unauthenticated."));
|
|
2960
|
+
return this.rest.delete(Routes.interactionOriginalResponse(this.user.id, token));
|
|
3134
2961
|
}
|
|
3135
2962
|
followUpInteraction(token, data) {
|
|
3136
|
-
if (!this.user
|
|
3137
|
-
|
|
3138
|
-
return this.rest.post(
|
|
2963
|
+
if (!this.user)
|
|
2964
|
+
return Promise.reject(new Error("Client is unauthenticated."));
|
|
2965
|
+
return this.rest.post(`/webhooks/${this.user.id}/${token}`, data);
|
|
3139
2966
|
}
|
|
3140
2967
|
}
|
|
3141
2968
|
export {
|
|
3142
|
-
ActionRowBuilder,
|
|
3143
|
-
ApplicationCommandManager,
|
|
3144
|
-
ApplicationCommandOptionType,
|
|
3145
|
-
ApplicationCommandType,
|
|
3146
|
-
ButtonBuilder,
|
|
3147
|
-
Channel,
|
|
3148
|
-
ChannelManager,
|
|
3149
|
-
ChannelType,
|
|
3150
2969
|
Client,
|
|
3151
|
-
|
|
3152
|
-
Collector,
|
|
3153
|
-
EmbedBuilder,
|
|
3154
|
-
Gateway,
|
|
3155
|
-
GatewayError,
|
|
2970
|
+
ClientEvent,
|
|
3156
2971
|
GatewayIntentBits,
|
|
3157
|
-
GatewayOpcodes,
|
|
3158
|
-
Guild,
|
|
3159
|
-
GuildManager,
|
|
3160
2972
|
IntentBits,
|
|
3161
2973
|
Intents,
|
|
3162
|
-
Manager,
|
|
3163
|
-
Message,
|
|
3164
|
-
MessageCreateOptions,
|
|
3165
|
-
MessageEditOptions,
|
|
3166
|
-
MessageFetchOptions,
|
|
3167
|
-
MessageFlags,
|
|
3168
|
-
MessageThreadOptions,
|
|
3169
2974
|
Permission,
|
|
3170
2975
|
PermissionFlagsBits,
|
|
3171
2976
|
PermissionOverwriteType,
|
|
3172
2977
|
PermissionSet,
|
|
3173
2978
|
Permissions,
|
|
3174
2979
|
PermissionsBitField,
|
|
3175
|
-
REST,
|
|
3176
|
-
RESTError,
|
|
3177
|
-
ReactionFetchOptions,
|
|
3178
|
-
ResourceManager,
|
|
3179
|
-
Routes,
|
|
3180
|
-
SlashCommandBuilder,
|
|
3181
|
-
StringOptionBuilder,
|
|
3182
|
-
StringSelectBuilder,
|
|
3183
|
-
User,
|
|
3184
|
-
UserManager,
|
|
3185
2980
|
resolveGatewayIntents
|
|
3186
2981
|
};
|
|
3187
2982
|
|
|
3188
|
-
//# debugId=
|
|
2983
|
+
//# debugId=813519968046205864756E2164756E21
|