@fluxerjs/core 2.0.1 → 2.0.3
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/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +376 -287
- package/dist/client.mjs +350 -261
- package/dist/cluster.d.mts +1 -1
- package/dist/cluster.d.ts +1 -1
- package/dist/cluster.js +378 -287
- package/dist/cluster.mjs +352 -261
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +376 -287
- package/dist/index.mjs +350 -261
- package/dist/message.d.mts +1 -1
- package/dist/message.d.ts +1 -1
- package/dist/message.js +121 -29
- package/dist/message.mjs +120 -28
- package/dist/{subpath-message-Acbzr5HA.d.mts → subpath-message-CWiBEUUV.d.mts} +15 -3
- package/dist/{subpath-message-Acbzr5HA.d.ts → subpath-message-CWiBEUUV.d.ts} +15 -3
- package/package.json +3 -3
package/dist/client.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import { Routes as Routes34 } from "@fluxerjs/types";
|
|
|
5
5
|
|
|
6
6
|
// src/client/ChannelManager.ts
|
|
7
7
|
import { Collection as Collection5 } from "@fluxerjs/collection";
|
|
8
|
-
import { Routes as
|
|
9
|
-
import { FluxerAPIError as
|
|
8
|
+
import { Routes as Routes13 } from "@fluxerjs/types";
|
|
9
|
+
import { FluxerAPIError as FluxerAPIError3, RateLimitError as RateLimitError3 } from "@fluxerjs/rest";
|
|
10
10
|
|
|
11
11
|
// src/errors/FluxerError.ts
|
|
12
12
|
import { FluxerError } from "@fluxerjs/util";
|
|
@@ -194,19 +194,19 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
// src/structures/channel/base.ts
|
|
197
|
-
import { ChannelType, Routes as
|
|
197
|
+
import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
|
|
198
198
|
|
|
199
199
|
// src/client/MessageManager.ts
|
|
200
|
-
import { Routes as
|
|
200
|
+
import { Routes as Routes5 } from "@fluxerjs/types";
|
|
201
201
|
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
202
|
-
import { FluxerAPIError, RateLimitError } from "@fluxerjs/rest";
|
|
202
|
+
import { FluxerAPIError as FluxerAPIError2, RateLimitError as RateLimitError2 } from "@fluxerjs/rest";
|
|
203
203
|
|
|
204
204
|
// src/structures/message/Message.ts
|
|
205
205
|
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
206
206
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
207
207
|
import {
|
|
208
208
|
MessageType,
|
|
209
|
-
Routes as
|
|
209
|
+
Routes as Routes4
|
|
210
210
|
} from "@fluxerjs/types";
|
|
211
211
|
|
|
212
212
|
// src/client/sdkOptions.ts
|
|
@@ -448,6 +448,68 @@ function toProfilePayload(data) {
|
|
|
448
448
|
import { EventEmitter } from "events";
|
|
449
449
|
import { Collection } from "@fluxerjs/collection";
|
|
450
450
|
|
|
451
|
+
// src/structures/MessageReaction.ts
|
|
452
|
+
import { Routes } from "@fluxerjs/types";
|
|
453
|
+
import { FluxerAPIError, RateLimitError } from "@fluxerjs/rest";
|
|
454
|
+
|
|
455
|
+
// src/structures/Base.ts
|
|
456
|
+
var Base = class {
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// src/structures/MessageReaction.ts
|
|
460
|
+
var MessageReaction = class extends Base {
|
|
461
|
+
client;
|
|
462
|
+
messageId;
|
|
463
|
+
channelId;
|
|
464
|
+
guildId;
|
|
465
|
+
emoji;
|
|
466
|
+
/** Raw gateway payload for low-level access. */
|
|
467
|
+
_data;
|
|
468
|
+
constructor(client, data) {
|
|
469
|
+
super();
|
|
470
|
+
this.client = client;
|
|
471
|
+
this._data = data;
|
|
472
|
+
this.messageId = data.message_id;
|
|
473
|
+
this.channelId = data.channel_id;
|
|
474
|
+
this.guildId = data.guild_id ?? null;
|
|
475
|
+
this.emoji = {
|
|
476
|
+
name: data.emoji.name,
|
|
477
|
+
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
478
|
+
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
/** Emoji as a string: unicode or "name:id" for custom. */
|
|
482
|
+
get emojiIdentifier() {
|
|
483
|
+
return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
484
|
+
}
|
|
485
|
+
/** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
|
|
486
|
+
get guild() {
|
|
487
|
+
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Fetch the message this reaction belongs to.
|
|
491
|
+
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
492
|
+
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
493
|
+
*/
|
|
494
|
+
async fetchMessage() {
|
|
495
|
+
try {
|
|
496
|
+
const data = await this.client.rest.get(
|
|
497
|
+
Routes.channelMessage(this.channelId, this.messageId)
|
|
498
|
+
);
|
|
499
|
+
return new Message(this.client, data);
|
|
500
|
+
} catch (err) {
|
|
501
|
+
if (err instanceof RateLimitError) throw err;
|
|
502
|
+
if (err instanceof FluxerAPIError && err.statusCode === 404) {
|
|
503
|
+
throw new FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
504
|
+
code: ErrorCodes.MessageNotFound,
|
|
505
|
+
cause: err
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
|
|
451
513
|
// src/util/Events.ts
|
|
452
514
|
var Events = {
|
|
453
515
|
Ready: "ready",
|
|
@@ -461,6 +523,8 @@ var Events = {
|
|
|
461
523
|
MessageReactionRemoveAll: "messageReactionRemoveAll",
|
|
462
524
|
MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
|
|
463
525
|
GuildCreate: "guildCreate",
|
|
526
|
+
GuildAvailable: "guildAvailable",
|
|
527
|
+
GuildUnavailable: "guildUnavailable",
|
|
464
528
|
GuildUpdate: "guildUpdate",
|
|
465
529
|
GuildDelete: "guildDelete",
|
|
466
530
|
GuildBanAdd: "guildBanAdd",
|
|
@@ -509,7 +573,8 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
509
573
|
collected = new Collection();
|
|
510
574
|
_timeout = null;
|
|
511
575
|
_ended = false;
|
|
512
|
-
|
|
576
|
+
_onAdd;
|
|
577
|
+
_onAddMany;
|
|
513
578
|
constructor(client, messageId, channelId, options = {}) {
|
|
514
579
|
super();
|
|
515
580
|
this.client = client;
|
|
@@ -520,27 +585,58 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
520
585
|
time: options.time ?? 0,
|
|
521
586
|
max: options.max ?? 0
|
|
522
587
|
};
|
|
523
|
-
this.
|
|
588
|
+
this._onAdd = (payload) => {
|
|
524
589
|
if (this._ended || payload.reaction.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
525
590
|
return;
|
|
526
591
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
this.
|
|
531
|
-
|
|
532
|
-
|
|
592
|
+
this._collect(payload.reaction, payload.user, payload.userId);
|
|
593
|
+
};
|
|
594
|
+
this._onAddMany = (payload) => {
|
|
595
|
+
if (this._ended || payload.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
for (const entry of payload.reactions) {
|
|
599
|
+
if (this._ended) return;
|
|
600
|
+
const reaction = new MessageReaction(this.client, {
|
|
601
|
+
message_id: payload.messageId,
|
|
602
|
+
channel_id: payload.channelId,
|
|
603
|
+
guild_id: payload.guildId ?? void 0,
|
|
604
|
+
user_id: entry.userId,
|
|
605
|
+
emoji: {
|
|
606
|
+
name: entry.emoji.name,
|
|
607
|
+
...entry.emoji.id !== void 0 ? { id: entry.emoji.id } : {},
|
|
608
|
+
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
|
|
612
|
+
id: entry.userId,
|
|
613
|
+
username: "Unknown",
|
|
614
|
+
discriminator: "0"
|
|
615
|
+
});
|
|
616
|
+
this._collect(reaction, user, entry.userId);
|
|
533
617
|
}
|
|
534
618
|
};
|
|
535
|
-
this.client.on(Events.MessageReactionAdd, this.
|
|
619
|
+
this.client.on(Events.MessageReactionAdd, this._onAdd);
|
|
620
|
+
this.client.on(Events.MessageReactionAddMany, this._onAddMany);
|
|
536
621
|
if (this.options.time > 0) {
|
|
537
622
|
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
538
623
|
}
|
|
539
624
|
}
|
|
625
|
+
_collect(reaction, user, userId) {
|
|
626
|
+
if (this._ended) return;
|
|
627
|
+
if (!this.options.filter(reaction, user)) return;
|
|
628
|
+
const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
|
|
629
|
+
this.collected.set(key, { reaction, user });
|
|
630
|
+
this.emit("collect", reaction, user);
|
|
631
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
632
|
+
this.stop("limit");
|
|
633
|
+
}
|
|
634
|
+
}
|
|
540
635
|
stop(reason = "user") {
|
|
541
636
|
if (this._ended) return;
|
|
542
637
|
this._ended = true;
|
|
543
|
-
this.client.off(Events.MessageReactionAdd, this.
|
|
638
|
+
this.client.off(Events.MessageReactionAdd, this._onAdd);
|
|
639
|
+
this.client.off(Events.MessageReactionAddMany, this._onAddMany);
|
|
544
640
|
if (this._timeout) {
|
|
545
641
|
clearTimeout(this._timeout);
|
|
546
642
|
this._timeout = null;
|
|
@@ -555,30 +651,26 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
555
651
|
}
|
|
556
652
|
};
|
|
557
653
|
|
|
558
|
-
// src/structures/Base.ts
|
|
559
|
-
var Base = class {
|
|
560
|
-
};
|
|
561
|
-
|
|
562
654
|
// src/structures/message/reactions.ts
|
|
563
|
-
import { Routes } from "@fluxerjs/types";
|
|
655
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
564
656
|
async function emojiPath(message, emoji) {
|
|
565
657
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
566
658
|
}
|
|
567
659
|
async function reactToMessage(message, emoji) {
|
|
568
660
|
const e = await emojiPath(message, emoji);
|
|
569
|
-
await message.client.rest.put(
|
|
661
|
+
await message.client.rest.put(Routes2.channelMessageReactionMe(message.channelId, message.id, e));
|
|
570
662
|
}
|
|
571
663
|
async function removeMessageReaction(message, emoji, userId) {
|
|
572
664
|
const e = await emojiPath(message, emoji);
|
|
573
|
-
const route = userId ?
|
|
665
|
+
const route = userId ? Routes2.channelMessageReactionUser(message.channelId, message.id, e, userId) : Routes2.channelMessageReactionMe(message.channelId, message.id, e);
|
|
574
666
|
await message.client.rest.delete(route);
|
|
575
667
|
}
|
|
576
668
|
async function removeAllMessageReactions(message) {
|
|
577
|
-
await message.client.rest.delete(
|
|
669
|
+
await message.client.rest.delete(Routes2.channelMessageReactions(message.channelId, message.id));
|
|
578
670
|
}
|
|
579
671
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
580
672
|
const e = await emojiPath(message, emoji);
|
|
581
|
-
await message.client.rest.delete(
|
|
673
|
+
await message.client.rest.delete(Routes2.channelMessageReaction(message.channelId, message.id, e));
|
|
582
674
|
}
|
|
583
675
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
584
676
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -589,7 +681,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
589
681
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
590
682
|
if (options?.after) params.set("after", options.after);
|
|
591
683
|
const qs2 = params.toString();
|
|
592
|
-
const route =
|
|
684
|
+
const route = Routes2.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
|
|
593
685
|
const data = await message.client.rest.get(route);
|
|
594
686
|
if (Array.isArray(data)) {
|
|
595
687
|
return {
|
|
@@ -608,7 +700,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
608
700
|
|
|
609
701
|
// src/structures/message/send.ts
|
|
610
702
|
import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
|
|
611
|
-
import { Routes as
|
|
703
|
+
import { Routes as Routes3 } from "@fluxerjs/types";
|
|
612
704
|
function toReplyTarget(ref) {
|
|
613
705
|
return {
|
|
614
706
|
channelId: ref.channel_id,
|
|
@@ -642,7 +734,7 @@ function asReplyTarget(value) {
|
|
|
642
734
|
}
|
|
643
735
|
async function sendPrepared(message, payload) {
|
|
644
736
|
const data = await message.client.rest.post(
|
|
645
|
-
|
|
737
|
+
Routes3.channelMessages(message.channelId),
|
|
646
738
|
payload
|
|
647
739
|
);
|
|
648
740
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -819,7 +911,7 @@ var Message = class _Message extends Base {
|
|
|
819
911
|
if (options.attachments !== void 0) {
|
|
820
912
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
821
913
|
}
|
|
822
|
-
const data = await this.client.rest.patch(
|
|
914
|
+
const data = await this.client.rest.patch(Routes4.channelMessage(this.channelId, this.id), {
|
|
823
915
|
body
|
|
824
916
|
});
|
|
825
917
|
const updated = new _Message(this.client, data);
|
|
@@ -836,25 +928,25 @@ var Message = class _Message extends Base {
|
|
|
836
928
|
}
|
|
837
929
|
/** Delete this message. */
|
|
838
930
|
async delete() {
|
|
839
|
-
await this.client.rest.delete(
|
|
931
|
+
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id));
|
|
840
932
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
841
933
|
}
|
|
842
934
|
/** Delete a specific attachment from this message. */
|
|
843
935
|
async deleteAttachment(attachmentId) {
|
|
844
936
|
await this.client.rest.delete(
|
|
845
|
-
|
|
937
|
+
Routes4.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
846
938
|
{ auth: true }
|
|
847
939
|
);
|
|
848
940
|
this.attachments.delete(attachmentId);
|
|
849
941
|
}
|
|
850
942
|
/** Pin this message in the channel. */
|
|
851
943
|
async pin() {
|
|
852
|
-
await this.client.rest.put(
|
|
944
|
+
await this.client.rest.put(Routes4.channelPinMessage(this.channelId, this.id));
|
|
853
945
|
this.pinned = true;
|
|
854
946
|
}
|
|
855
947
|
/** Unpin this message from the channel. */
|
|
856
948
|
async unpin() {
|
|
857
|
-
await this.client.rest.delete(
|
|
949
|
+
await this.client.rest.delete(Routes4.channelPinMessage(this.channelId, this.id));
|
|
858
950
|
this.pinned = false;
|
|
859
951
|
}
|
|
860
952
|
/** React to this message with an emoji. */
|
|
@@ -935,12 +1027,12 @@ var MessageManager = class {
|
|
|
935
1027
|
async fetchOne(messageId) {
|
|
936
1028
|
try {
|
|
937
1029
|
const data = await this.client.rest.get(
|
|
938
|
-
|
|
1030
|
+
Routes5.channelMessage(this.channelId, messageId)
|
|
939
1031
|
);
|
|
940
1032
|
return this.wrap(data);
|
|
941
1033
|
} catch (err) {
|
|
942
|
-
if (err instanceof
|
|
943
|
-
if (err instanceof
|
|
1034
|
+
if (err instanceof RateLimitError2) throw err;
|
|
1035
|
+
if (err instanceof FluxerAPIError2 && err.statusCode === 404) {
|
|
944
1036
|
throw new FluxerError(`Message ${messageId} not found in channel ${this.channelId}`, {
|
|
945
1037
|
code: ErrorCodes.MessageNotFound,
|
|
946
1038
|
cause: err
|
|
@@ -961,7 +1053,7 @@ var MessageManager = class {
|
|
|
961
1053
|
const value = options[key];
|
|
962
1054
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
963
1055
|
}
|
|
964
|
-
const base =
|
|
1056
|
+
const base = Routes5.channelMessages(this.channelId);
|
|
965
1057
|
const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
|
|
966
1058
|
const collection = new Collection3();
|
|
967
1059
|
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
@@ -970,7 +1062,7 @@ var MessageManager = class {
|
|
|
970
1062
|
};
|
|
971
1063
|
|
|
972
1064
|
// src/structures/channel/attachments.ts
|
|
973
|
-
import { Routes as
|
|
1065
|
+
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
974
1066
|
function asBytes(data) {
|
|
975
1067
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
976
1068
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -991,7 +1083,7 @@ async function putBlob(url, body, contentType) {
|
|
|
991
1083
|
}
|
|
992
1084
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
993
1085
|
const plan = await client.rest.post(
|
|
994
|
-
|
|
1086
|
+
Routes6.channelAttachments(channelId),
|
|
995
1087
|
{
|
|
996
1088
|
body: {
|
|
997
1089
|
attachments: files.map((f) => ({
|
|
@@ -1037,7 +1129,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1037
1129
|
});
|
|
1038
1130
|
}
|
|
1039
1131
|
if (multipart.length) {
|
|
1040
|
-
await client.rest.post(
|
|
1132
|
+
await client.rest.post(Routes6.channelAttachmentsComplete(channelId), {
|
|
1041
1133
|
body: { uploads: multipart },
|
|
1042
1134
|
auth: true
|
|
1043
1135
|
});
|
|
@@ -1131,7 +1223,7 @@ var Channel = class extends Base {
|
|
|
1131
1223
|
}
|
|
1132
1224
|
if (ids.length === 0) return [];
|
|
1133
1225
|
if (ids.length === 1) {
|
|
1134
|
-
await this.client.rest.delete(
|
|
1226
|
+
await this.client.rest.delete(Routes7.channelMessage(this.id, ids[0]), { auth: true });
|
|
1135
1227
|
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
1136
1228
|
return ids;
|
|
1137
1229
|
}
|
|
@@ -1140,7 +1232,7 @@ var Channel = class extends Base {
|
|
|
1140
1232
|
code: ErrorCodes.InvalidBulkDelete
|
|
1141
1233
|
});
|
|
1142
1234
|
}
|
|
1143
|
-
await this.client.rest.post(
|
|
1235
|
+
await this.client.rest.post(Routes7.channelBulkDelete(this.id), {
|
|
1144
1236
|
body: { message_ids: ids },
|
|
1145
1237
|
auth: true
|
|
1146
1238
|
});
|
|
@@ -1150,23 +1242,23 @@ var Channel = class extends Base {
|
|
|
1150
1242
|
/** Delete all messages sent by the bot in this channel (user account feature). */
|
|
1151
1243
|
async bulkDeleteMyMessages(options) {
|
|
1152
1244
|
const body = options ? toSudoBody(options) : void 0;
|
|
1153
|
-
await this.client.rest.post(
|
|
1245
|
+
await this.client.rest.post(Routes7.channelBulkDeleteMine(this.id), {
|
|
1154
1246
|
body: body && Object.keys(body).length ? body : void 0,
|
|
1155
1247
|
auth: true
|
|
1156
1248
|
});
|
|
1157
1249
|
}
|
|
1158
1250
|
/** Mark all pinned messages as read in this channel. */
|
|
1159
1251
|
async acknowledgePins() {
|
|
1160
|
-
await this.client.rest.post(
|
|
1252
|
+
await this.client.rest.post(Routes7.channelPinsAck(this.id), { auth: true });
|
|
1161
1253
|
}
|
|
1162
1254
|
/** Clear the read state for this channel. */
|
|
1163
1255
|
async clearReadState() {
|
|
1164
|
-
await this.client.rest.delete(
|
|
1256
|
+
await this.client.rest.delete(Routes7.channelMessagesAck(this.id), { auth: true });
|
|
1165
1257
|
}
|
|
1166
1258
|
/** Request upload URLs for attachments before sending a message. */
|
|
1167
1259
|
async requestAttachmentUploads(attachments) {
|
|
1168
1260
|
const data = await this.client.rest.post(
|
|
1169
|
-
|
|
1261
|
+
Routes7.channelAttachments(this.id),
|
|
1170
1262
|
{
|
|
1171
1263
|
body: toAttachmentUploadPlanBody(attachments),
|
|
1172
1264
|
auth: true
|
|
@@ -1177,7 +1269,7 @@ var Channel = class extends Base {
|
|
|
1177
1269
|
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
1178
1270
|
async completeAttachmentUploads(uploads) {
|
|
1179
1271
|
const data = await this.client.rest.post(
|
|
1180
|
-
|
|
1272
|
+
Routes7.channelAttachmentsComplete(this.id),
|
|
1181
1273
|
{
|
|
1182
1274
|
body: toAttachmentUploadCompleteBody(uploads),
|
|
1183
1275
|
auth: true
|
|
@@ -1193,11 +1285,11 @@ var Channel = class extends Base {
|
|
|
1193
1285
|
}
|
|
1194
1286
|
/** Trigger the typing indicator in this channel. */
|
|
1195
1287
|
async sendTyping() {
|
|
1196
|
-
await this.client.rest.post(
|
|
1288
|
+
await this.client.rest.post(Routes7.channelTyping(this.id), { auth: true });
|
|
1197
1289
|
}
|
|
1198
1290
|
/** Fetch available RTC regions for voice channels. */
|
|
1199
1291
|
async fetchRtcRegions() {
|
|
1200
|
-
const data = await this.client.rest.get(
|
|
1292
|
+
const data = await this.client.rest.get(Routes7.channelRtcRegions(this.id), {
|
|
1201
1293
|
auth: true
|
|
1202
1294
|
});
|
|
1203
1295
|
return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
|
|
@@ -1205,7 +1297,7 @@ var Channel = class extends Base {
|
|
|
1205
1297
|
/** Fetch slowmode state for this channel. */
|
|
1206
1298
|
async fetchSlowmode() {
|
|
1207
1299
|
const data = await this.client.rest.get(
|
|
1208
|
-
|
|
1300
|
+
Routes7.channelSlowmode(this.id),
|
|
1209
1301
|
{ auth: true }
|
|
1210
1302
|
);
|
|
1211
1303
|
return {
|
|
@@ -1221,7 +1313,7 @@ var Channel = class extends Base {
|
|
|
1221
1313
|
};
|
|
1222
1314
|
|
|
1223
1315
|
// src/structures/channel/guild.ts
|
|
1224
|
-
import { Routes as
|
|
1316
|
+
import { Routes as Routes11 } from "@fluxerjs/types";
|
|
1225
1317
|
import { PermissionFlags } from "@fluxerjs/util";
|
|
1226
1318
|
|
|
1227
1319
|
// src/structures/Invite.ts
|
|
@@ -1230,7 +1322,7 @@ import {
|
|
|
1230
1322
|
isGroupDmInvite,
|
|
1231
1323
|
isGuildInvite,
|
|
1232
1324
|
isPackInvite,
|
|
1233
|
-
Routes as
|
|
1325
|
+
Routes as Routes8
|
|
1234
1326
|
} from "@fluxerjs/types";
|
|
1235
1327
|
|
|
1236
1328
|
// src/util/Constants.ts
|
|
@@ -1450,19 +1542,19 @@ var Invite = class _Invite extends Base {
|
|
|
1450
1542
|
}
|
|
1451
1543
|
/** Fetch invite metadata by code or URL (does not join). */
|
|
1452
1544
|
static async fetch(client, codeOrUrl) {
|
|
1453
|
-
const data = await client.rest.get(
|
|
1545
|
+
const data = await client.rest.get(Routes8.invite(parseInviteCode(codeOrUrl)));
|
|
1454
1546
|
return new _Invite(client, data);
|
|
1455
1547
|
}
|
|
1456
1548
|
/** Delete this invite. Requires Manage Guild or Create Instant Invite. */
|
|
1457
1549
|
async delete() {
|
|
1458
|
-
await this.client.rest.delete(
|
|
1550
|
+
await this.client.rest.delete(Routes8.invite(this.code), { auth: true });
|
|
1459
1551
|
}
|
|
1460
1552
|
};
|
|
1461
1553
|
|
|
1462
1554
|
// src/structures/Webhook.ts
|
|
1463
1555
|
import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
|
|
1464
1556
|
import {
|
|
1465
|
-
Routes as
|
|
1557
|
+
Routes as Routes9
|
|
1466
1558
|
} from "@fluxerjs/types";
|
|
1467
1559
|
|
|
1468
1560
|
// src/util/cdn.ts
|
|
@@ -1555,10 +1647,10 @@ var Webhook = class _Webhook extends Base {
|
|
|
1555
1647
|
/** Delete this webhook (token auth when available, otherwise bot auth). */
|
|
1556
1648
|
async delete() {
|
|
1557
1649
|
if (this.token) {
|
|
1558
|
-
await this.client.rest.delete(
|
|
1650
|
+
await this.client.rest.delete(Routes9.webhookExecute(this.id, this.token), { auth: false });
|
|
1559
1651
|
return;
|
|
1560
1652
|
}
|
|
1561
|
-
await this.client.rest.delete(
|
|
1653
|
+
await this.client.rest.delete(Routes9.webhook(this.id), { auth: true });
|
|
1562
1654
|
}
|
|
1563
1655
|
/**
|
|
1564
1656
|
* Edit name/avatar. With bot auth (no token), `channelId` may also be set.
|
|
@@ -1570,10 +1662,10 @@ var Webhook = class _Webhook extends Base {
|
|
|
1570
1662
|
if (!this.token && options.channelId !== void 0) {
|
|
1571
1663
|
body.channel_id = options.channelId;
|
|
1572
1664
|
}
|
|
1573
|
-
const data = this.token ? await this.client.rest.patch(
|
|
1665
|
+
const data = this.token ? await this.client.rest.patch(Routes9.webhookExecute(this.id, this.token), {
|
|
1574
1666
|
body,
|
|
1575
1667
|
auth: false
|
|
1576
|
-
}) : await this.client.rest.patch(
|
|
1668
|
+
}) : await this.client.rest.patch(Routes9.webhook(this.id), { body, auth: true });
|
|
1577
1669
|
this.name = data.name ?? this.name;
|
|
1578
1670
|
this.avatar = data.avatar ?? null;
|
|
1579
1671
|
if (!this.token) this.channelId = data.channel_id ?? this.channelId;
|
|
@@ -1594,7 +1686,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
1594
1686
|
if (overrides.avatarUrl !== void 0) {
|
|
1595
1687
|
body.avatar_url = overrides.avatarUrl;
|
|
1596
1688
|
}
|
|
1597
|
-
const route = `${
|
|
1689
|
+
const route = `${Routes9.webhookExecute(this.id, token)}${wait ? "?wait=true" : ""}`;
|
|
1598
1690
|
const data = await this.client.rest.post(route, {
|
|
1599
1691
|
body,
|
|
1600
1692
|
...files?.length ? { files } : {},
|
|
@@ -1635,7 +1727,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
1635
1727
|
}
|
|
1636
1728
|
/** Fetch a webhook by ID (bot auth; no token). */
|
|
1637
1729
|
static async fetch(client, webhookId) {
|
|
1638
|
-
const data = await client.rest.get(
|
|
1730
|
+
const data = await client.rest.get(Routes9.webhook(webhookId));
|
|
1639
1731
|
return new _Webhook(client, data);
|
|
1640
1732
|
}
|
|
1641
1733
|
/** Build a webhook from a stored id + token (e.g. webhook URL). */
|
|
@@ -1660,12 +1752,12 @@ var Webhook = class _Webhook extends Base {
|
|
|
1660
1752
|
return this.token;
|
|
1661
1753
|
}
|
|
1662
1754
|
messageRoute(messageId) {
|
|
1663
|
-
return
|
|
1755
|
+
return Routes9.webhookMessage(this.id, this.requireToken(), messageId);
|
|
1664
1756
|
}
|
|
1665
1757
|
};
|
|
1666
1758
|
|
|
1667
1759
|
// src/structures/channel/textCapable.ts
|
|
1668
|
-
import { Routes as
|
|
1760
|
+
import { Routes as Routes10 } from "@fluxerjs/types";
|
|
1669
1761
|
|
|
1670
1762
|
// src/util/MessageCollector.ts
|
|
1671
1763
|
import { EventEmitter as EventEmitter2 } from "events";
|
|
@@ -1726,7 +1818,7 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
|
1726
1818
|
if (options?.before) params.set("before", options.before);
|
|
1727
1819
|
const qs2 = params.toString();
|
|
1728
1820
|
const data = await client.rest.get(
|
|
1729
|
-
|
|
1821
|
+
Routes10.channelPins(channelId) + (qs2 ? `?${qs2}` : "")
|
|
1730
1822
|
);
|
|
1731
1823
|
const items = data.items ?? [];
|
|
1732
1824
|
return {
|
|
@@ -1742,7 +1834,7 @@ function TextCapable(Base2) {
|
|
|
1742
1834
|
const payload = await prepareMessagePostPayload(options, {
|
|
1743
1835
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
1744
1836
|
});
|
|
1745
|
-
const data = await this.client.rest.post(
|
|
1837
|
+
const data = await this.client.rest.post(Routes10.channelMessages(this.id), payload);
|
|
1746
1838
|
this.client._addMessageToCache(this.id, data);
|
|
1747
1839
|
return new Message(this.client, data);
|
|
1748
1840
|
}
|
|
@@ -1799,7 +1891,7 @@ var GuildChannel = class extends Channel {
|
|
|
1799
1891
|
}
|
|
1800
1892
|
/** Create a webhook for this channel. Requires Manage Webhooks. */
|
|
1801
1893
|
async createWebhook(options) {
|
|
1802
|
-
const data = await this.client.rest.post(
|
|
1894
|
+
const data = await this.client.rest.post(Routes11.channelWebhooks(this.id), {
|
|
1803
1895
|
body: options,
|
|
1804
1896
|
auth: true
|
|
1805
1897
|
});
|
|
@@ -1807,13 +1899,13 @@ var GuildChannel = class extends Channel {
|
|
|
1807
1899
|
}
|
|
1808
1900
|
/** Fetch all webhooks in this channel. Requires Manage Webhooks. */
|
|
1809
1901
|
async fetchWebhooks() {
|
|
1810
|
-
const data = await this.client.rest.get(
|
|
1902
|
+
const data = await this.client.rest.get(Routes11.channelWebhooks(this.id));
|
|
1811
1903
|
return data.map((w) => new Webhook(this.client, w));
|
|
1812
1904
|
}
|
|
1813
1905
|
/** Create an invite for this channel. Requires Create Instant Invite. */
|
|
1814
1906
|
async createInvite(options) {
|
|
1815
1907
|
const body = options ? toChannelInviteBody(options) : {};
|
|
1816
|
-
const data = await this.client.rest.post(
|
|
1908
|
+
const data = await this.client.rest.post(Routes11.channelInvites(this.id), {
|
|
1817
1909
|
body: Object.keys(body).length ? body : void 0,
|
|
1818
1910
|
auth: true
|
|
1819
1911
|
});
|
|
@@ -1821,12 +1913,12 @@ var GuildChannel = class extends Channel {
|
|
|
1821
1913
|
}
|
|
1822
1914
|
/** Fetch all invites for this channel. Requires Manage Channels. */
|
|
1823
1915
|
async fetchInvites() {
|
|
1824
|
-
const data = await this.client.rest.get(
|
|
1916
|
+
const data = await this.client.rest.get(Routes11.channelInvites(this.id));
|
|
1825
1917
|
return data.map((i) => new Invite(this.client, i));
|
|
1826
1918
|
}
|
|
1827
1919
|
/** Edit or create a permission overwrite. Requires Manage Roles. */
|
|
1828
1920
|
async editPermission(overwriteId, options) {
|
|
1829
|
-
await this.client.rest.put(
|
|
1921
|
+
await this.client.rest.put(Routes11.channelPermission(this.id, overwriteId), {
|
|
1830
1922
|
body: options,
|
|
1831
1923
|
auth: true
|
|
1832
1924
|
});
|
|
@@ -1842,7 +1934,7 @@ var GuildChannel = class extends Channel {
|
|
|
1842
1934
|
}
|
|
1843
1935
|
/** Delete a permission overwrite. Requires Manage Roles. */
|
|
1844
1936
|
async deletePermission(overwriteId) {
|
|
1845
|
-
await this.client.rest.delete(
|
|
1937
|
+
await this.client.rest.delete(Routes11.channelPermission(this.id, overwriteId), { auth: true });
|
|
1846
1938
|
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
1847
1939
|
if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
|
|
1848
1940
|
}
|
|
@@ -1855,7 +1947,7 @@ var GuildChannel = class extends Channel {
|
|
|
1855
1947
|
}
|
|
1856
1948
|
/** Edit this channel's settings. Requires Manage Channels. */
|
|
1857
1949
|
async edit(options) {
|
|
1858
|
-
const data = await this.client.rest.patch(
|
|
1950
|
+
const data = await this.client.rest.patch(Routes11.channel(this.id), {
|
|
1859
1951
|
body: toChannelEditBody(options),
|
|
1860
1952
|
auth: true
|
|
1861
1953
|
});
|
|
@@ -1875,7 +1967,7 @@ var GuildChannel = class extends Channel {
|
|
|
1875
1967
|
const qs2 = params.toString();
|
|
1876
1968
|
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
1877
1969
|
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
1878
|
-
await this.client.rest.delete(
|
|
1970
|
+
await this.client.rest.delete(Routes11.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
1879
1971
|
body,
|
|
1880
1972
|
auth: true
|
|
1881
1973
|
});
|
|
@@ -1937,7 +2029,7 @@ var LinkChannel = class extends GuildChannel {
|
|
|
1937
2029
|
};
|
|
1938
2030
|
|
|
1939
2031
|
// src/structures/channel/dm.ts
|
|
1940
|
-
import { ChannelType as ChannelType2, Routes as
|
|
2032
|
+
import { ChannelType as ChannelType2, Routes as Routes12 } from "@fluxerjs/types";
|
|
1941
2033
|
var DMChannel = class extends TextCapable(Channel) {
|
|
1942
2034
|
/** ID of the last message sent in this channel. */
|
|
1943
2035
|
lastMessageId;
|
|
@@ -1963,28 +2055,28 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
1963
2055
|
});
|
|
1964
2056
|
}
|
|
1965
2057
|
const data = await this.client.rest.post(
|
|
1966
|
-
|
|
2058
|
+
Routes12.channelMessagesPurge(this.id),
|
|
1967
2059
|
{ auth: true }
|
|
1968
2060
|
);
|
|
1969
2061
|
return data.deleted_count;
|
|
1970
2062
|
}
|
|
1971
2063
|
/** Pin this DM channel to the top of the DM list. */
|
|
1972
2064
|
async pinInList() {
|
|
1973
|
-
await this.client.rest.put(
|
|
2065
|
+
await this.client.rest.put(Routes12.userMeChannelPin(this.id), { auth: true });
|
|
1974
2066
|
}
|
|
1975
2067
|
/** Unpin this DM channel from the DM list. */
|
|
1976
2068
|
async unpinFromList() {
|
|
1977
|
-
await this.client.rest.delete(
|
|
2069
|
+
await this.client.rest.delete(Routes12.userMeChannelPin(this.id), { auth: true });
|
|
1978
2070
|
}
|
|
1979
2071
|
/** Add a user to this group DM. */
|
|
1980
2072
|
async addRecipient(userId) {
|
|
1981
|
-
await this.client.rest.put(
|
|
2073
|
+
await this.client.rest.put(Routes12.channelRecipient(this.id, userId), { auth: true });
|
|
1982
2074
|
const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
|
|
1983
2075
|
if (user) this.recipients.push(user);
|
|
1984
2076
|
}
|
|
1985
2077
|
/** Remove a user from this group DM. */
|
|
1986
2078
|
async removeRecipient(userId, options) {
|
|
1987
|
-
const url =
|
|
2079
|
+
const url = Routes12.channelRecipient(this.id, userId) + (options?.silent ? "?silent=true" : "");
|
|
1988
2080
|
await this.client.rest.delete(url, { auth: true });
|
|
1989
2081
|
const idx = this.recipients.findIndex((u) => u.id === userId);
|
|
1990
2082
|
if (idx >= 0) this.recipients.splice(idx, 1);
|
|
@@ -2022,8 +2114,8 @@ Channel.createDM = createDM;
|
|
|
2022
2114
|
|
|
2023
2115
|
// src/client/ChannelManager.ts
|
|
2024
2116
|
function rethrowNotFound(err, message, code) {
|
|
2025
|
-
if (err instanceof
|
|
2026
|
-
if (err instanceof
|
|
2117
|
+
if (err instanceof RateLimitError3) throw err;
|
|
2118
|
+
if (err instanceof FluxerAPIError3 && err.statusCode === 404) {
|
|
2027
2119
|
throw new FluxerError(message, { code, cause: err });
|
|
2028
2120
|
}
|
|
2029
2121
|
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
@@ -2055,7 +2147,7 @@ var ChannelManager = class extends Collection5 {
|
|
|
2055
2147
|
const cached = this.get(channelId);
|
|
2056
2148
|
if (cached) return cached;
|
|
2057
2149
|
try {
|
|
2058
|
-
const data = await this.client.rest.get(
|
|
2150
|
+
const data = await this.client.rest.get(Routes13.channel(channelId));
|
|
2059
2151
|
const channel = Channel.fromOrCreate(this.client, data);
|
|
2060
2152
|
if (!channel) {
|
|
2061
2153
|
throw new FluxerError("Channel data invalid or unsupported type", {
|
|
@@ -2088,7 +2180,7 @@ var ChannelManager = class extends Collection5 {
|
|
|
2088
2180
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
2089
2181
|
});
|
|
2090
2182
|
const data = await this.client.rest.post(
|
|
2091
|
-
|
|
2183
|
+
Routes13.channelMessages(channelId),
|
|
2092
2184
|
postPayload
|
|
2093
2185
|
);
|
|
2094
2186
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -2098,8 +2190,8 @@ var ChannelManager = class extends Collection5 {
|
|
|
2098
2190
|
|
|
2099
2191
|
// src/client/GuildManager.ts
|
|
2100
2192
|
import { Collection as Collection9 } from "@fluxerjs/collection";
|
|
2101
|
-
import { Routes as
|
|
2102
|
-
import { FluxerAPIError as
|
|
2193
|
+
import { Routes as Routes28 } from "@fluxerjs/types";
|
|
2194
|
+
import { FluxerAPIError as FluxerAPIError5, RateLimitError as RateLimitError4 } from "@fluxerjs/rest";
|
|
2103
2195
|
|
|
2104
2196
|
// src/structures/guild/Guild.ts
|
|
2105
2197
|
import { Collection as Collection8 } from "@fluxerjs/collection";
|
|
@@ -2107,10 +2199,10 @@ import { GuildNSFWLevel } from "@fluxerjs/types";
|
|
|
2107
2199
|
|
|
2108
2200
|
// src/client/GuildMemberManager.ts
|
|
2109
2201
|
import { Collection as Collection7 } from "@fluxerjs/collection";
|
|
2110
|
-
import { Routes as
|
|
2202
|
+
import { Routes as Routes16 } from "@fluxerjs/types";
|
|
2111
2203
|
|
|
2112
2204
|
// src/structures/GuildMember.ts
|
|
2113
|
-
import { Routes as
|
|
2205
|
+
import { Routes as Routes15 } from "@fluxerjs/types";
|
|
2114
2206
|
import { PermissionsBitField } from "@fluxerjs/util";
|
|
2115
2207
|
|
|
2116
2208
|
// src/util/permissions.ts
|
|
@@ -2131,7 +2223,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
2131
2223
|
|
|
2132
2224
|
// src/structures/GuildMemberRoleManager.ts
|
|
2133
2225
|
import { Collection as Collection6 } from "@fluxerjs/collection";
|
|
2134
|
-
import { Routes as
|
|
2226
|
+
import { Routes as Routes14 } from "@fluxerjs/types";
|
|
2135
2227
|
function roleId(roleOrId) {
|
|
2136
2228
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
2137
2229
|
}
|
|
@@ -2160,7 +2252,7 @@ var GuildMemberRoleManager = class {
|
|
|
2160
2252
|
const id = roleId(roleOrId);
|
|
2161
2253
|
if (this.ids.includes(id)) return;
|
|
2162
2254
|
await this.member.client.rest.put(
|
|
2163
|
-
|
|
2255
|
+
Routes14.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2164
2256
|
);
|
|
2165
2257
|
this.ids.push(id);
|
|
2166
2258
|
}
|
|
@@ -2169,13 +2261,13 @@ var GuildMemberRoleManager = class {
|
|
|
2169
2261
|
const idx = this.ids.indexOf(id);
|
|
2170
2262
|
if (idx === -1) return;
|
|
2171
2263
|
await this.member.client.rest.delete(
|
|
2172
|
-
|
|
2264
|
+
Routes14.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2173
2265
|
);
|
|
2174
2266
|
this.ids.splice(idx, 1);
|
|
2175
2267
|
}
|
|
2176
2268
|
async set(roleIds) {
|
|
2177
2269
|
const data = await this.member.client.rest.patch(
|
|
2178
|
-
|
|
2270
|
+
Routes14.guildMember(this.member.guild.id, this.member.id),
|
|
2179
2271
|
{ body: { roles: roleIds }, auth: true }
|
|
2180
2272
|
);
|
|
2181
2273
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -2302,7 +2394,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2302
2394
|
/** PATCH member (`/members/@me` when editing the bot). */
|
|
2303
2395
|
async edit(options) {
|
|
2304
2396
|
const isMe = this.client.user?.id === this.id;
|
|
2305
|
-
const route = isMe ?
|
|
2397
|
+
const route = isMe ? Routes15.guildMemberMe(this.guild.id) : Routes15.guildMember(this.guild.id, this.id);
|
|
2306
2398
|
const data = await this.client.rest.patch(route, {
|
|
2307
2399
|
body: toMemberEditBody(options),
|
|
2308
2400
|
auth: true
|
|
@@ -2431,7 +2523,7 @@ var GuildMemberManager = class extends Collection7 {
|
|
|
2431
2523
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
2432
2524
|
if (options?.after) params.set("after", options.after);
|
|
2433
2525
|
const qs2 = params.toString();
|
|
2434
|
-
const url =
|
|
2526
|
+
const url = Routes16.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
2435
2527
|
const data = await this.guild.client.rest.get(url, { auth: true });
|
|
2436
2528
|
const members = [];
|
|
2437
2529
|
for (const m of data) {
|
|
@@ -2454,7 +2546,7 @@ var GuildMemberManager = class extends Collection7 {
|
|
|
2454
2546
|
*/
|
|
2455
2547
|
async search(options = {}) {
|
|
2456
2548
|
const data = await this.guild.client.rest.post(
|
|
2457
|
-
|
|
2549
|
+
Routes16.guildMembersSearch(this.guild.id),
|
|
2458
2550
|
{ body: toMemberSearchBody(options), auth: true }
|
|
2459
2551
|
);
|
|
2460
2552
|
const offset = options.offset ?? 0;
|
|
@@ -2480,7 +2572,7 @@ var GuildMemberManager = class extends Collection7 {
|
|
|
2480
2572
|
};
|
|
2481
2573
|
|
|
2482
2574
|
// src/structures/Role.ts
|
|
2483
|
-
import { Routes as
|
|
2575
|
+
import { Routes as Routes17 } from "@fluxerjs/types";
|
|
2484
2576
|
import { ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2, PermissionFlags as PermissionFlags4, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
|
|
2485
2577
|
|
|
2486
2578
|
// src/structures/roleOptions.ts
|
|
@@ -2593,7 +2685,7 @@ var Role = class _Role extends Base {
|
|
|
2593
2685
|
*/
|
|
2594
2686
|
async edit(options) {
|
|
2595
2687
|
const body = toRoleRequestBody(options);
|
|
2596
|
-
const data = await this.client.rest.patch(
|
|
2688
|
+
const data = await this.client.rest.patch(Routes17.guildRole(this.guildId, this.id), {
|
|
2597
2689
|
body: Object.keys(body).length ? body : void 0,
|
|
2598
2690
|
auth: true
|
|
2599
2691
|
});
|
|
@@ -2604,18 +2696,18 @@ var Role = class _Role extends Base {
|
|
|
2604
2696
|
* DELETE role. Requires Manage Roles.
|
|
2605
2697
|
*/
|
|
2606
2698
|
async delete() {
|
|
2607
|
-
await this.client.rest.delete(
|
|
2699
|
+
await this.client.rest.delete(Routes17.guildRole(this.guildId, this.id), { auth: true });
|
|
2608
2700
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
2609
2701
|
}
|
|
2610
2702
|
};
|
|
2611
2703
|
|
|
2612
2704
|
// src/structures/guild/admin.ts
|
|
2613
|
-
import { Routes as
|
|
2705
|
+
import { Routes as Routes18 } from "@fluxerjs/types";
|
|
2614
2706
|
|
|
2615
2707
|
// src/structures/guild/http.ts
|
|
2616
|
-
import { FluxerAPIError as
|
|
2708
|
+
import { FluxerAPIError as FluxerAPIError4 } from "@fluxerjs/rest";
|
|
2617
2709
|
function httpStatus(err) {
|
|
2618
|
-
if (err instanceof
|
|
2710
|
+
if (err instanceof FluxerAPIError4) return err.statusCode;
|
|
2619
2711
|
if (typeof err === "object" && err !== null && "statusCode" in err) {
|
|
2620
2712
|
const code = err.statusCode;
|
|
2621
2713
|
return typeof code === "number" ? code : void 0;
|
|
@@ -2715,7 +2807,7 @@ function toVanityPayload(data) {
|
|
|
2715
2807
|
return { code: data.code ?? null, uses: data.uses };
|
|
2716
2808
|
}
|
|
2717
2809
|
async function fetchAuditLogs(guild, options) {
|
|
2718
|
-
const url =
|
|
2810
|
+
const url = Routes18.guildAuditLogs(guild.id) + qs({
|
|
2719
2811
|
limit: options?.limit,
|
|
2720
2812
|
before: options?.before,
|
|
2721
2813
|
after: options?.after,
|
|
@@ -2736,7 +2828,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
2736
2828
|
};
|
|
2737
2829
|
}
|
|
2738
2830
|
async function editGuild(guild, options) {
|
|
2739
|
-
const data = await guild.client.rest.patch(
|
|
2831
|
+
const data = await guild.client.rest.patch(Routes18.guild(guild.id), {
|
|
2740
2832
|
body: toGuildEditBody(options),
|
|
2741
2833
|
auth: true
|
|
2742
2834
|
});
|
|
@@ -2744,13 +2836,13 @@ async function editGuild(guild, options) {
|
|
|
2744
2836
|
return guild;
|
|
2745
2837
|
}
|
|
2746
2838
|
async function fetchVanityURL(guild) {
|
|
2747
|
-
const data = await guild.client.rest.get(
|
|
2839
|
+
const data = await guild.client.rest.get(Routes18.guildVanityUrl(guild.id), {
|
|
2748
2840
|
auth: true
|
|
2749
2841
|
});
|
|
2750
2842
|
return toVanityPayload(data);
|
|
2751
2843
|
}
|
|
2752
2844
|
async function editVanityURL(guild, code) {
|
|
2753
|
-
const data = await guild.client.rest.patch(
|
|
2845
|
+
const data = await guild.client.rest.patch(Routes18.guildVanityUrl(guild.id), {
|
|
2754
2846
|
body: { code },
|
|
2755
2847
|
auth: true
|
|
2756
2848
|
});
|
|
@@ -2758,14 +2850,14 @@ async function editVanityURL(guild, code) {
|
|
|
2758
2850
|
return toVanityPayload(data);
|
|
2759
2851
|
}
|
|
2760
2852
|
async function fetchDiscoveryStatus(guild) {
|
|
2761
|
-
const data = await guild.client.rest.get(
|
|
2853
|
+
const data = await guild.client.rest.get(Routes18.guildDiscovery(guild.id), {
|
|
2762
2854
|
auth: true
|
|
2763
2855
|
});
|
|
2764
2856
|
return toDiscoveryStatusPayload(data);
|
|
2765
2857
|
}
|
|
2766
2858
|
async function applyForDiscovery(guild, options) {
|
|
2767
2859
|
const data = await guild.client.rest.post(
|
|
2768
|
-
|
|
2860
|
+
Routes18.guildDiscovery(guild.id),
|
|
2769
2861
|
{
|
|
2770
2862
|
body: toDiscoveryBody(options),
|
|
2771
2863
|
auth: true
|
|
@@ -2775,7 +2867,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
2775
2867
|
}
|
|
2776
2868
|
async function editDiscoveryApplication(guild, options) {
|
|
2777
2869
|
const data = await guild.client.rest.patch(
|
|
2778
|
-
|
|
2870
|
+
Routes18.guildDiscovery(guild.id),
|
|
2779
2871
|
{
|
|
2780
2872
|
body: toDiscoveryBody(options),
|
|
2781
2873
|
auth: true
|
|
@@ -2784,28 +2876,28 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
2784
2876
|
return toDiscoveryApplicationPayload(data);
|
|
2785
2877
|
}
|
|
2786
2878
|
async function withdrawDiscoveryApplication(guild) {
|
|
2787
|
-
await guild.client.rest.delete(
|
|
2879
|
+
await guild.client.rest.delete(Routes18.guildDiscovery(guild.id), { auth: true });
|
|
2788
2880
|
}
|
|
2789
2881
|
async function deleteGuild(guild, options) {
|
|
2790
2882
|
const body = options ? toSudoBody(options) : {};
|
|
2791
|
-
await guild.client.rest.post(
|
|
2883
|
+
await guild.client.rest.post(Routes18.guildDelete(guild.id), {
|
|
2792
2884
|
body,
|
|
2793
2885
|
auth: true
|
|
2794
2886
|
});
|
|
2795
2887
|
guild.client.guilds.delete(guild.id);
|
|
2796
2888
|
}
|
|
2797
2889
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
2798
|
-
await guild.client.rest.post(
|
|
2890
|
+
await guild.client.rest.post(Routes18.guildTransferOwnership(guild.id), {
|
|
2799
2891
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
2800
2892
|
auth: true
|
|
2801
2893
|
});
|
|
2802
2894
|
}
|
|
2803
2895
|
|
|
2804
2896
|
// src/structures/guild/channels.ts
|
|
2805
|
-
import { Routes as
|
|
2897
|
+
import { Routes as Routes21 } from "@fluxerjs/types";
|
|
2806
2898
|
|
|
2807
2899
|
// src/structures/GuildEmoji.ts
|
|
2808
|
-
import { Routes as
|
|
2900
|
+
import { Routes as Routes19 } from "@fluxerjs/types";
|
|
2809
2901
|
var GuildEmoji = class extends Base {
|
|
2810
2902
|
client;
|
|
2811
2903
|
id;
|
|
@@ -2833,7 +2925,7 @@ var GuildEmoji = class extends Base {
|
|
|
2833
2925
|
}
|
|
2834
2926
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
2835
2927
|
async delete() {
|
|
2836
|
-
await this.client.rest.delete(
|
|
2928
|
+
await this.client.rest.delete(Routes19.guildEmoji(this.guildId, this.id), {
|
|
2837
2929
|
auth: true
|
|
2838
2930
|
});
|
|
2839
2931
|
const guild = this.client.guilds.get(this.guildId);
|
|
@@ -2844,7 +2936,7 @@ var GuildEmoji = class extends Base {
|
|
|
2844
2936
|
* Requires Manage Emojis and Stickers permission.
|
|
2845
2937
|
*/
|
|
2846
2938
|
async edit(options) {
|
|
2847
|
-
const data = await this.client.rest.patch(
|
|
2939
|
+
const data = await this.client.rest.patch(Routes19.guildEmoji(this.guildId, this.id), {
|
|
2848
2940
|
body: options,
|
|
2849
2941
|
auth: true
|
|
2850
2942
|
});
|
|
@@ -2854,7 +2946,7 @@ var GuildEmoji = class extends Base {
|
|
|
2854
2946
|
};
|
|
2855
2947
|
|
|
2856
2948
|
// src/structures/GuildSticker.ts
|
|
2857
|
-
import { Routes as
|
|
2949
|
+
import { Routes as Routes20 } from "@fluxerjs/types";
|
|
2858
2950
|
var GuildSticker = class extends Base {
|
|
2859
2951
|
client;
|
|
2860
2952
|
id;
|
|
@@ -2885,7 +2977,7 @@ var GuildSticker = class extends Base {
|
|
|
2885
2977
|
}
|
|
2886
2978
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
2887
2979
|
async delete() {
|
|
2888
|
-
await this.client.rest.delete(
|
|
2980
|
+
await this.client.rest.delete(Routes20.guildSticker(this.guildId, this.id), {
|
|
2889
2981
|
auth: true
|
|
2890
2982
|
});
|
|
2891
2983
|
}
|
|
@@ -2894,7 +2986,7 @@ var GuildSticker = class extends Base {
|
|
|
2894
2986
|
* Requires Manage Emojis and Stickers permission.
|
|
2895
2987
|
*/
|
|
2896
2988
|
async edit(options) {
|
|
2897
|
-
const data = await this.client.rest.patch(
|
|
2989
|
+
const data = await this.client.rest.patch(Routes20.guildSticker(this.guildId, this.id), {
|
|
2898
2990
|
body: options,
|
|
2899
2991
|
auth: true
|
|
2900
2992
|
});
|
|
@@ -2949,14 +3041,14 @@ function cacheSticker(guild, data) {
|
|
|
2949
3041
|
|
|
2950
3042
|
// src/structures/guild/channels.ts
|
|
2951
3043
|
async function createChannel(guild, data) {
|
|
2952
|
-
const created = await guild.client.rest.post(
|
|
3044
|
+
const created = await guild.client.rest.post(Routes21.guildChannels(guild.id), {
|
|
2953
3045
|
body: data,
|
|
2954
3046
|
auth: true
|
|
2955
3047
|
});
|
|
2956
3048
|
return cacheChannel(guild, created);
|
|
2957
3049
|
}
|
|
2958
3050
|
async function fetchChannels(guild) {
|
|
2959
|
-
const data = await guild.client.rest.get(
|
|
3051
|
+
const data = await guild.client.rest.get(Routes21.guildChannels(guild.id));
|
|
2960
3052
|
const channels = [];
|
|
2961
3053
|
for (const ch of data) {
|
|
2962
3054
|
const channel = cacheChannel(guild, ch);
|
|
@@ -2965,17 +3057,17 @@ async function fetchChannels(guild) {
|
|
|
2965
3057
|
return channels;
|
|
2966
3058
|
}
|
|
2967
3059
|
async function setChannelPositions(guild, updates) {
|
|
2968
|
-
await guild.client.rest.patch(
|
|
3060
|
+
await guild.client.rest.patch(Routes21.guildChannels(guild.id), {
|
|
2969
3061
|
body: toChannelPositionBody(updates),
|
|
2970
3062
|
auth: true
|
|
2971
3063
|
});
|
|
2972
3064
|
}
|
|
2973
3065
|
async function fetchWebhooks(guild) {
|
|
2974
|
-
const data = await guild.client.rest.get(
|
|
3066
|
+
const data = await guild.client.rest.get(Routes21.guildWebhooks(guild.id));
|
|
2975
3067
|
return data.map((w) => new Webhook(guild.client, w));
|
|
2976
3068
|
}
|
|
2977
3069
|
async function fetchInvites(guild) {
|
|
2978
|
-
const data = await guild.client.rest.get(
|
|
3070
|
+
const data = await guild.client.rest.get(Routes21.guildInvites(guild.id));
|
|
2979
3071
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
2980
3072
|
}
|
|
2981
3073
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -2983,14 +3075,14 @@ async function fetchInvite(guild, codeOrUrl) {
|
|
|
2983
3075
|
}
|
|
2984
3076
|
|
|
2985
3077
|
// src/structures/guild/emojis.ts
|
|
2986
|
-
import { Routes as
|
|
3078
|
+
import { Routes as Routes22 } from "@fluxerjs/types";
|
|
2987
3079
|
async function fetchEmojis(guild) {
|
|
2988
|
-
const data = await guild.client.rest.get(
|
|
3080
|
+
const data = await guild.client.rest.get(Routes22.guildEmojis(guild.id));
|
|
2989
3081
|
return data.map((e) => cacheEmoji(guild, e));
|
|
2990
3082
|
}
|
|
2991
3083
|
async function fetchEmoji(guild, emojiId) {
|
|
2992
3084
|
try {
|
|
2993
|
-
const data = await guild.client.rest.get(
|
|
3085
|
+
const data = await guild.client.rest.get(Routes22.guildEmoji(guild.id, emojiId));
|
|
2994
3086
|
return cacheEmoji(guild, data);
|
|
2995
3087
|
} catch (err) {
|
|
2996
3088
|
rethrowNotFound2(
|
|
@@ -3001,14 +3093,14 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
3001
3093
|
}
|
|
3002
3094
|
}
|
|
3003
3095
|
async function createEmoji(guild, options) {
|
|
3004
|
-
const data = await guild.client.rest.post(
|
|
3096
|
+
const data = await guild.client.rest.post(Routes22.guildEmojis(guild.id), {
|
|
3005
3097
|
body: options,
|
|
3006
3098
|
auth: true
|
|
3007
3099
|
});
|
|
3008
3100
|
return cacheEmoji(guild, data);
|
|
3009
3101
|
}
|
|
3010
3102
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
3011
|
-
const data = await guild.client.rest.post(
|
|
3103
|
+
const data = await guild.client.rest.post(Routes22.guildEmojisClone(guild.id), {
|
|
3012
3104
|
body: { source_emoji_id: sourceEmojiId },
|
|
3013
3105
|
auth: true
|
|
3014
3106
|
});
|
|
@@ -3016,18 +3108,18 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
3016
3108
|
}
|
|
3017
3109
|
async function createEmojisBulk(guild, emojis) {
|
|
3018
3110
|
const data = await guild.client.rest.post(
|
|
3019
|
-
|
|
3111
|
+
Routes22.guildEmojisBulk(guild.id),
|
|
3020
3112
|
{ body: { emojis }, auth: true }
|
|
3021
3113
|
);
|
|
3022
3114
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
3023
3115
|
}
|
|
3024
3116
|
|
|
3025
3117
|
// src/structures/guild/members.ts
|
|
3026
|
-
import { Routes as
|
|
3118
|
+
import { Routes as Routes23 } from "@fluxerjs/types";
|
|
3027
3119
|
async function fetchMember(guild, userId) {
|
|
3028
3120
|
try {
|
|
3029
3121
|
const data = await guild.client.rest.get(
|
|
3030
|
-
|
|
3122
|
+
Routes23.guildMember(guild.id, userId)
|
|
3031
3123
|
);
|
|
3032
3124
|
return cacheMember(guild, data);
|
|
3033
3125
|
} catch (err) {
|
|
@@ -3040,17 +3132,17 @@ async function fetchMember(guild, userId) {
|
|
|
3040
3132
|
}
|
|
3041
3133
|
async function fetchMe(guild) {
|
|
3042
3134
|
const data = await guild.client.rest.get(
|
|
3043
|
-
|
|
3135
|
+
Routes23.guildMemberMe(guild.id),
|
|
3044
3136
|
{ auth: true }
|
|
3045
3137
|
);
|
|
3046
3138
|
return cacheMember(guild, data);
|
|
3047
3139
|
}
|
|
3048
3140
|
|
|
3049
3141
|
// src/structures/guild/moderation.ts
|
|
3050
|
-
import { Routes as
|
|
3142
|
+
import { Routes as Routes25 } from "@fluxerjs/types";
|
|
3051
3143
|
|
|
3052
3144
|
// src/structures/GuildBan.ts
|
|
3053
|
-
import { Routes as
|
|
3145
|
+
import { Routes as Routes24 } from "@fluxerjs/types";
|
|
3054
3146
|
var GuildBan = class extends Base {
|
|
3055
3147
|
client;
|
|
3056
3148
|
guildId;
|
|
@@ -3072,7 +3164,7 @@ var GuildBan = class extends Base {
|
|
|
3072
3164
|
* Requires Ban Members permission.
|
|
3073
3165
|
*/
|
|
3074
3166
|
async unban() {
|
|
3075
|
-
await this.client.rest.delete(
|
|
3167
|
+
await this.client.rest.delete(Routes24.guildBan(this.guildId, this.user.id), {
|
|
3076
3168
|
auth: true
|
|
3077
3169
|
});
|
|
3078
3170
|
}
|
|
@@ -3081,40 +3173,40 @@ var GuildBan = class extends Base {
|
|
|
3081
3173
|
// src/structures/guild/moderation.ts
|
|
3082
3174
|
async function ban(guild, userId, options) {
|
|
3083
3175
|
const body = options ? toGuildBanBody(options) : {};
|
|
3084
|
-
await guild.client.rest.put(
|
|
3176
|
+
await guild.client.rest.put(Routes25.guildBan(guild.id, userId), {
|
|
3085
3177
|
body: Object.keys(body).length ? body : void 0,
|
|
3086
3178
|
auth: true
|
|
3087
3179
|
});
|
|
3088
3180
|
}
|
|
3089
3181
|
async function fetchBans(guild) {
|
|
3090
|
-
const data = await guild.client.rest.get(
|
|
3182
|
+
const data = await guild.client.rest.get(Routes25.guildBans(guild.id));
|
|
3091
3183
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
3092
3184
|
}
|
|
3093
3185
|
async function unban(guild, userId) {
|
|
3094
|
-
await guild.client.rest.delete(
|
|
3186
|
+
await guild.client.rest.delete(Routes25.guildBan(guild.id, userId), { auth: true });
|
|
3095
3187
|
}
|
|
3096
3188
|
async function kick(guild, userId) {
|
|
3097
|
-
await guild.client.rest.delete(
|
|
3189
|
+
await guild.client.rest.delete(Routes25.guildMember(guild.id, userId), { auth: true });
|
|
3098
3190
|
}
|
|
3099
3191
|
|
|
3100
3192
|
// src/structures/guild/roles.ts
|
|
3101
|
-
import { Routes as
|
|
3193
|
+
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
3102
3194
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
3103
3195
|
async function createRole(guild, options = {}) {
|
|
3104
3196
|
const body = toRoleRequestBody(options);
|
|
3105
|
-
const data = await guild.client.rest.post(
|
|
3197
|
+
const data = await guild.client.rest.post(Routes26.guildRoles(guild.id), {
|
|
3106
3198
|
body: Object.keys(body).length ? body : void 0,
|
|
3107
3199
|
auth: true
|
|
3108
3200
|
});
|
|
3109
3201
|
return cacheRole(guild, data);
|
|
3110
3202
|
}
|
|
3111
3203
|
async function fetchRoles(guild) {
|
|
3112
|
-
const data = await guild.client.rest.get(
|
|
3204
|
+
const data = await guild.client.rest.get(Routes26.guildRoles(guild.id));
|
|
3113
3205
|
return data.map((r) => cacheRole(guild, r));
|
|
3114
3206
|
}
|
|
3115
3207
|
async function fetchRole(guild, roleId2) {
|
|
3116
3208
|
try {
|
|
3117
|
-
const data = await guild.client.rest.get(
|
|
3209
|
+
const data = await guild.client.rest.get(Routes26.guildRole(guild.id, roleId2));
|
|
3118
3210
|
return cacheRole(guild, data);
|
|
3119
3211
|
} catch (err) {
|
|
3120
3212
|
rethrowNotFound2(
|
|
@@ -3132,7 +3224,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3132
3224
|
const needle = trimmed.toLowerCase();
|
|
3133
3225
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3134
3226
|
if (cached) return cached.id;
|
|
3135
|
-
const roles = await guild.client.rest.get(
|
|
3227
|
+
const roles = await guild.client.rest.get(Routes26.guildRoles(guild.id));
|
|
3136
3228
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3137
3229
|
if (!role) return null;
|
|
3138
3230
|
cacheRole(guild, role);
|
|
@@ -3141,7 +3233,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3141
3233
|
async function setRolePositions(guild, updates) {
|
|
3142
3234
|
return replaceRoles(
|
|
3143
3235
|
guild,
|
|
3144
|
-
await guild.client.rest.patch(
|
|
3236
|
+
await guild.client.rest.patch(Routes26.guildRoles(guild.id), {
|
|
3145
3237
|
body: updates,
|
|
3146
3238
|
auth: true
|
|
3147
3239
|
})
|
|
@@ -3150,7 +3242,7 @@ async function setRolePositions(guild, updates) {
|
|
|
3150
3242
|
async function setRoleHoistPositions(guild, updates) {
|
|
3151
3243
|
return replaceRoles(
|
|
3152
3244
|
guild,
|
|
3153
|
-
await guild.client.rest.patch(
|
|
3245
|
+
await guild.client.rest.patch(Routes26.guildRolesHoistPositions(guild.id), {
|
|
3154
3246
|
body: updates.map((u) => ({
|
|
3155
3247
|
id: u.id,
|
|
3156
3248
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -3162,23 +3254,23 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
3162
3254
|
async function resetRoleHoistPositions(guild) {
|
|
3163
3255
|
return replaceRoles(
|
|
3164
3256
|
guild,
|
|
3165
|
-
await guild.client.rest.delete(
|
|
3257
|
+
await guild.client.rest.delete(Routes26.guildRolesHoistPositions(guild.id), {
|
|
3166
3258
|
auth: true
|
|
3167
3259
|
})
|
|
3168
3260
|
);
|
|
3169
3261
|
}
|
|
3170
3262
|
|
|
3171
3263
|
// src/structures/guild/stickers.ts
|
|
3172
|
-
import { Routes as
|
|
3264
|
+
import { Routes as Routes27 } from "@fluxerjs/types";
|
|
3173
3265
|
async function createSticker(guild, options) {
|
|
3174
|
-
const data = await guild.client.rest.post(
|
|
3266
|
+
const data = await guild.client.rest.post(Routes27.guildStickers(guild.id), {
|
|
3175
3267
|
body: options,
|
|
3176
3268
|
auth: true
|
|
3177
3269
|
});
|
|
3178
3270
|
return cacheSticker(guild, data);
|
|
3179
3271
|
}
|
|
3180
3272
|
async function cloneSticker(guild, sourceStickerId) {
|
|
3181
|
-
const data = await guild.client.rest.post(
|
|
3273
|
+
const data = await guild.client.rest.post(Routes27.guildStickersClone(guild.id), {
|
|
3182
3274
|
body: { source_sticker_id: sourceStickerId },
|
|
3183
3275
|
auth: true
|
|
3184
3276
|
});
|
|
@@ -3186,17 +3278,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
3186
3278
|
}
|
|
3187
3279
|
async function createStickersBulk(guild, stickers) {
|
|
3188
3280
|
const data = await guild.client.rest.post(
|
|
3189
|
-
|
|
3281
|
+
Routes27.guildStickersBulk(guild.id),
|
|
3190
3282
|
{ body: { stickers }, auth: true }
|
|
3191
3283
|
);
|
|
3192
3284
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
3193
3285
|
}
|
|
3194
3286
|
async function fetchStickers(guild) {
|
|
3195
|
-
const data = await guild.client.rest.get(
|
|
3287
|
+
const data = await guild.client.rest.get(Routes27.guildStickers(guild.id));
|
|
3196
3288
|
return data.map((s) => cacheSticker(guild, s));
|
|
3197
3289
|
}
|
|
3198
3290
|
async function fetchSticker(guild, stickerId) {
|
|
3199
|
-
const data = await guild.client.rest.get(
|
|
3291
|
+
const data = await guild.client.rest.get(Routes27.guildSticker(guild.id, stickerId));
|
|
3200
3292
|
return cacheSticker(guild, data);
|
|
3201
3293
|
}
|
|
3202
3294
|
|
|
@@ -3206,6 +3298,8 @@ var Guild = class extends Base {
|
|
|
3206
3298
|
client;
|
|
3207
3299
|
/** Snowflake ID of this guild. */
|
|
3208
3300
|
id;
|
|
3301
|
+
/** Whether the guild is currently available through the gateway. */
|
|
3302
|
+
available = true;
|
|
3209
3303
|
/** Guild name. */
|
|
3210
3304
|
name;
|
|
3211
3305
|
/** Icon hash (use {@link iconURL} to get full CDN URL). */
|
|
@@ -3541,13 +3635,13 @@ var GuildManager = class extends Collection9 {
|
|
|
3541
3635
|
const cached = this.get(guildId);
|
|
3542
3636
|
if (cached) return cached;
|
|
3543
3637
|
try {
|
|
3544
|
-
const data = await this.client.rest.get(
|
|
3638
|
+
const data = await this.client.rest.get(Routes28.guild(guildId));
|
|
3545
3639
|
const guild = new Guild(this.client, data);
|
|
3546
3640
|
this.set(guild.id, guild);
|
|
3547
3641
|
return guild;
|
|
3548
3642
|
} catch (err) {
|
|
3549
|
-
if (err instanceof
|
|
3550
|
-
if (err instanceof
|
|
3643
|
+
if (err instanceof RateLimitError4) throw err;
|
|
3644
|
+
if (err instanceof FluxerAPIError5 && err.statusCode === 404) {
|
|
3551
3645
|
throw new FluxerError(`Guild ${guildId} not found`, {
|
|
3552
3646
|
code: ErrorCodes.GuildNotFound,
|
|
3553
3647
|
cause: err
|
|
@@ -3568,7 +3662,7 @@ var DEFAULT_CACHE_LIMITS = {
|
|
|
3568
3662
|
};
|
|
3569
3663
|
|
|
3570
3664
|
// src/structures/User.ts
|
|
3571
|
-
import { Routes as
|
|
3665
|
+
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
3572
3666
|
var User = class extends Base {
|
|
3573
3667
|
/** Parent client instance. */
|
|
3574
3668
|
client;
|
|
@@ -3658,7 +3752,7 @@ var User = class extends Base {
|
|
|
3658
3752
|
* @returns DM channel instance (cached if already open)
|
|
3659
3753
|
*/
|
|
3660
3754
|
async createDM() {
|
|
3661
|
-
const data = await this.client.rest.post(
|
|
3755
|
+
const data = await this.client.rest.post(Routes29.userMeChannels(), {
|
|
3662
3756
|
body: { recipient_id: this.id },
|
|
3663
3757
|
auth: true
|
|
3664
3758
|
});
|
|
@@ -3668,7 +3762,7 @@ var User = class extends Base {
|
|
|
3668
3762
|
}
|
|
3669
3763
|
/**
|
|
3670
3764
|
* Send a DM to this user.
|
|
3671
|
-
* @param options -
|
|
3765
|
+
* @param options - {@link MessagePrepareInput}
|
|
3672
3766
|
* @returns Sent message
|
|
3673
3767
|
*/
|
|
3674
3768
|
async send(options) {
|
|
@@ -3679,7 +3773,7 @@ var User = class extends Base {
|
|
|
3679
3773
|
// src/client/UserManager.ts
|
|
3680
3774
|
import { Collection as Collection10 } from "@fluxerjs/collection";
|
|
3681
3775
|
import {
|
|
3682
|
-
Routes as
|
|
3776
|
+
Routes as Routes30
|
|
3683
3777
|
} from "@fluxerjs/types";
|
|
3684
3778
|
var soft = (p) => p.catch(() => null);
|
|
3685
3779
|
var UserManager = class extends Collection10 {
|
|
@@ -3711,7 +3805,7 @@ var UserManager = class extends Collection10 {
|
|
|
3711
3805
|
}
|
|
3712
3806
|
/** Fetch a user by ID and update cache. */
|
|
3713
3807
|
async fetch(userId) {
|
|
3714
|
-
const data = await this.client.rest.get(
|
|
3808
|
+
const data = await this.client.rest.get(Routes30.user(userId));
|
|
3715
3809
|
return this.client.getOrCreateUser(data);
|
|
3716
3810
|
}
|
|
3717
3811
|
/**
|
|
@@ -3725,10 +3819,10 @@ var UserManager = class extends Collection10 {
|
|
|
3725
3819
|
async fetchWithProfile(userId, options) {
|
|
3726
3820
|
const guildId = options?.guildId ?? void 0;
|
|
3727
3821
|
const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
|
|
3728
|
-
this.client.rest.get(
|
|
3729
|
-
soft(this.client.rest.get(
|
|
3730
|
-
guildId ? soft(this.client.rest.get(
|
|
3731
|
-
guildId ? soft(this.client.rest.get(
|
|
3822
|
+
this.client.rest.get(Routes30.user(userId)),
|
|
3823
|
+
soft(this.client.rest.get(Routes30.userProfile(userId))),
|
|
3824
|
+
guildId ? soft(this.client.rest.get(Routes30.userProfile(userId, guildId))) : null,
|
|
3825
|
+
guildId ? soft(this.client.rest.get(Routes30.guildMember(guildId, userId))) : null
|
|
3732
3826
|
]);
|
|
3733
3827
|
const user = this.client.getOrCreateUser(userData);
|
|
3734
3828
|
let member = null;
|
|
@@ -3758,7 +3852,7 @@ var UserManager = class extends Collection10 {
|
|
|
3758
3852
|
|
|
3759
3853
|
// src/client/PackManager.ts
|
|
3760
3854
|
import {
|
|
3761
|
-
Routes as
|
|
3855
|
+
Routes as Routes31
|
|
3762
3856
|
} from "@fluxerjs/types";
|
|
3763
3857
|
function toPackSummaryPayload(data) {
|
|
3764
3858
|
return {
|
|
@@ -3814,7 +3908,7 @@ var PackManager = class {
|
|
|
3814
3908
|
}
|
|
3815
3909
|
/** Fetch the current user's pack dashboard (camelCase summaries). */
|
|
3816
3910
|
async fetchDashboard() {
|
|
3817
|
-
const data = await this.client.rest.get(
|
|
3911
|
+
const data = await this.client.rest.get(Routes31.packs());
|
|
3818
3912
|
return {
|
|
3819
3913
|
emoji: mapDashboardSection(data.emoji),
|
|
3820
3914
|
sticker: mapDashboardSection(data.sticker)
|
|
@@ -3822,49 +3916,49 @@ var PackManager = class {
|
|
|
3822
3916
|
}
|
|
3823
3917
|
/** Create a pack. */
|
|
3824
3918
|
async create(packType, body) {
|
|
3825
|
-
const data = await this.client.rest.post(
|
|
3919
|
+
const data = await this.client.rest.post(Routes31.packsByType(packType), {
|
|
3826
3920
|
body
|
|
3827
3921
|
});
|
|
3828
3922
|
return toPackSummaryPayload(data);
|
|
3829
3923
|
}
|
|
3830
3924
|
/** Edit a pack. */
|
|
3831
3925
|
async edit(packId, body) {
|
|
3832
|
-
const data = await this.client.rest.patch(
|
|
3926
|
+
const data = await this.client.rest.patch(Routes31.pack(packId), { body });
|
|
3833
3927
|
return toPackSummaryPayload(data);
|
|
3834
3928
|
}
|
|
3835
3929
|
/** Delete a pack. */
|
|
3836
3930
|
async delete(packId) {
|
|
3837
|
-
await this.client.rest.delete(
|
|
3931
|
+
await this.client.rest.delete(Routes31.pack(packId));
|
|
3838
3932
|
}
|
|
3839
3933
|
/** Install a pack for the current user. */
|
|
3840
3934
|
async install(packId) {
|
|
3841
|
-
await this.client.rest.post(
|
|
3935
|
+
await this.client.rest.post(Routes31.packInstall(packId));
|
|
3842
3936
|
}
|
|
3843
3937
|
/** Uninstall a pack for the current user. */
|
|
3844
3938
|
async uninstall(packId) {
|
|
3845
|
-
await this.client.rest.delete(
|
|
3939
|
+
await this.client.rest.delete(Routes31.packInstall(packId));
|
|
3846
3940
|
}
|
|
3847
3941
|
/** List invites for a pack. */
|
|
3848
3942
|
async listInvites(packId) {
|
|
3849
|
-
const data = await this.client.rest.get(
|
|
3943
|
+
const data = await this.client.rest.get(Routes31.packInvites(packId));
|
|
3850
3944
|
return data.map(toInvitePayload);
|
|
3851
3945
|
}
|
|
3852
3946
|
/** Create an invite for a pack. */
|
|
3853
3947
|
async createInvite(packId, options = {}) {
|
|
3854
3948
|
const body = toPackInviteBody(options);
|
|
3855
|
-
const data = await this.client.rest.post(
|
|
3949
|
+
const data = await this.client.rest.post(Routes31.packInvites(packId), {
|
|
3856
3950
|
body: Object.keys(body).length ? body : void 0
|
|
3857
3951
|
});
|
|
3858
3952
|
return toInvitePayload(data);
|
|
3859
3953
|
}
|
|
3860
3954
|
/** List emojis in a pack. */
|
|
3861
3955
|
async listEmojis(packId) {
|
|
3862
|
-
const data = await this.client.rest.get(
|
|
3956
|
+
const data = await this.client.rest.get(Routes31.packEmojis(packId));
|
|
3863
3957
|
return data.map(toEmojiPayload);
|
|
3864
3958
|
}
|
|
3865
3959
|
/** Create an emoji in a pack. */
|
|
3866
3960
|
async createEmoji(packId, options) {
|
|
3867
|
-
const data = await this.client.rest.post(
|
|
3961
|
+
const data = await this.client.rest.post(Routes31.packEmojis(packId), {
|
|
3868
3962
|
body: toEmojiCreateBody(options)
|
|
3869
3963
|
});
|
|
3870
3964
|
return toEmojiPayload(data);
|
|
@@ -3872,7 +3966,7 @@ var PackManager = class {
|
|
|
3872
3966
|
/** Bulk-create emojis in a pack. */
|
|
3873
3967
|
async createEmojisBulk(packId, emojis) {
|
|
3874
3968
|
const data = await this.client.rest.post(
|
|
3875
|
-
|
|
3969
|
+
Routes31.packEmojisBulk(packId),
|
|
3876
3970
|
{ body: { emojis: emojis.map(toEmojiCreateBody) } }
|
|
3877
3971
|
);
|
|
3878
3972
|
return {
|
|
@@ -3882,23 +3976,23 @@ var PackManager = class {
|
|
|
3882
3976
|
}
|
|
3883
3977
|
/** Edit an emoji in a pack. */
|
|
3884
3978
|
async editEmoji(packId, emojiId, options) {
|
|
3885
|
-
const data = await this.client.rest.patch(
|
|
3979
|
+
const data = await this.client.rest.patch(Routes31.packEmoji(packId, emojiId), {
|
|
3886
3980
|
body: toEmojiEditBody(options)
|
|
3887
3981
|
});
|
|
3888
3982
|
return toEmojiPayload(data);
|
|
3889
3983
|
}
|
|
3890
3984
|
/** Delete an emoji from a pack. */
|
|
3891
3985
|
async deleteEmoji(packId, emojiId) {
|
|
3892
|
-
await this.client.rest.delete(
|
|
3986
|
+
await this.client.rest.delete(Routes31.packEmoji(packId, emojiId));
|
|
3893
3987
|
}
|
|
3894
3988
|
/** List stickers in a pack. */
|
|
3895
3989
|
async listStickers(packId) {
|
|
3896
|
-
const data = await this.client.rest.get(
|
|
3990
|
+
const data = await this.client.rest.get(Routes31.packStickers(packId));
|
|
3897
3991
|
return data.map(toStickerPayload);
|
|
3898
3992
|
}
|
|
3899
3993
|
/** Create a sticker in a pack. */
|
|
3900
3994
|
async createSticker(packId, options) {
|
|
3901
|
-
const data = await this.client.rest.post(
|
|
3995
|
+
const data = await this.client.rest.post(Routes31.packStickers(packId), {
|
|
3902
3996
|
body: toStickerCreateBody(options)
|
|
3903
3997
|
});
|
|
3904
3998
|
return toStickerPayload(data);
|
|
@@ -3906,7 +4000,7 @@ var PackManager = class {
|
|
|
3906
4000
|
/** Bulk-create stickers in a pack. */
|
|
3907
4001
|
async createStickersBulk(packId, stickers) {
|
|
3908
4002
|
const data = await this.client.rest.post(
|
|
3909
|
-
|
|
4003
|
+
Routes31.packStickersBulk(packId),
|
|
3910
4004
|
{ body: { stickers: stickers.map(toStickerCreateBody) } }
|
|
3911
4005
|
);
|
|
3912
4006
|
return {
|
|
@@ -3916,14 +4010,14 @@ var PackManager = class {
|
|
|
3916
4010
|
}
|
|
3917
4011
|
/** Edit a sticker in a pack. */
|
|
3918
4012
|
async editSticker(packId, stickerId, options) {
|
|
3919
|
-
const data = await this.client.rest.patch(
|
|
4013
|
+
const data = await this.client.rest.patch(Routes31.packSticker(packId, stickerId), {
|
|
3920
4014
|
body: toStickerEditBody(options)
|
|
3921
4015
|
});
|
|
3922
4016
|
return toStickerPayload(data);
|
|
3923
4017
|
}
|
|
3924
4018
|
/** Delete a sticker from a pack. */
|
|
3925
4019
|
async deleteSticker(packId, stickerId) {
|
|
3926
|
-
await this.client.rest.delete(
|
|
4020
|
+
await this.client.rest.delete(Routes31.packSticker(packId, stickerId));
|
|
3927
4021
|
}
|
|
3928
4022
|
};
|
|
3929
4023
|
|
|
@@ -3942,10 +4036,10 @@ function createEventMethods(client) {
|
|
|
3942
4036
|
|
|
3943
4037
|
// src/client/clientEmoji.ts
|
|
3944
4038
|
import { Collection as Collection11 } from "@fluxerjs/collection";
|
|
3945
|
-
import { Routes as
|
|
4039
|
+
import { Routes as Routes32 } from "@fluxerjs/types";
|
|
3946
4040
|
import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
|
|
3947
4041
|
async function assertEmojiInGuild(client, emojiId, guildId) {
|
|
3948
|
-
const emojis = await client.rest.get(
|
|
4042
|
+
const emojis = await client.rest.get(Routes32.guildEmojis(guildId));
|
|
3949
4043
|
if (!emojis.some((e) => e.id === emojiId)) {
|
|
3950
4044
|
throw new FluxerError("Custom emoji is from another server. Use an emoji from this server.", {
|
|
3951
4045
|
code: ErrorCodes.EmojiNotInGuild
|
|
@@ -3971,7 +4065,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
3971
4065
|
const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
|
|
3972
4066
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
3973
4067
|
if (guildId) {
|
|
3974
|
-
const emojis = await client.rest.get(
|
|
4068
|
+
const emojis = await client.rest.get(Routes32.guildEmojis(guildId));
|
|
3975
4069
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
3976
4070
|
if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
|
|
3977
4071
|
throw new FluxerError(
|
|
@@ -3988,28 +4082,28 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
3988
4082
|
return parsed.name;
|
|
3989
4083
|
}
|
|
3990
4084
|
async function fetchInstance(client) {
|
|
3991
|
-
const raw = await client.rest.get(
|
|
4085
|
+
const raw = await client.rest.get(Routes32.instanceDiscovery(), { auth: false });
|
|
3992
4086
|
return parseInstanceDiscovery(raw);
|
|
3993
4087
|
}
|
|
3994
4088
|
function fetchGatewayInfo(client) {
|
|
3995
|
-
return client.rest.get(
|
|
4089
|
+
return client.rest.get(Routes32.gatewayBot());
|
|
3996
4090
|
}
|
|
3997
4091
|
function fetchEmojiMetadata(client, emojiId) {
|
|
3998
|
-
return client.rest.get(
|
|
4092
|
+
return client.rest.get(Routes32.emojiMetadata(emojiId), { auth: true });
|
|
3999
4093
|
}
|
|
4000
4094
|
function fetchStickerMetadata(client, stickerId) {
|
|
4001
|
-
return client.rest.get(
|
|
4095
|
+
return client.rest.get(Routes32.stickerMetadata(stickerId), { auth: true });
|
|
4002
4096
|
}
|
|
4003
4097
|
function fetchApplication(client) {
|
|
4004
|
-
return client.rest.get(
|
|
4098
|
+
return client.rest.get(Routes32.applicationsMe(), { auth: true });
|
|
4005
4099
|
}
|
|
4006
4100
|
async function fetchOAuthApplications(client) {
|
|
4007
|
-
const data = await client.rest.get(
|
|
4101
|
+
const data = await client.rest.get(Routes32.oauth2ApplicationsMe(), { auth: true });
|
|
4008
4102
|
return Array.isArray(data) ? data : data.applications ?? [];
|
|
4009
4103
|
}
|
|
4010
4104
|
function checkUsernameTag(client, username, discriminator) {
|
|
4011
4105
|
const params = new URLSearchParams({ username, discriminator });
|
|
4012
|
-
return client.rest.get(`${
|
|
4106
|
+
return client.rest.get(`${Routes32.checkUsernameTag()}?${params}`, { auth: true });
|
|
4013
4107
|
}
|
|
4014
4108
|
function assertChannelIdBatch(name, channelIds) {
|
|
4015
4109
|
if (channelIds.length < 1 || channelIds.length > 100) {
|
|
@@ -4020,14 +4114,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
4020
4114
|
}
|
|
4021
4115
|
function preloadMessages(client, channelIds) {
|
|
4022
4116
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
4023
|
-
return client.rest.post(
|
|
4117
|
+
return client.rest.post(Routes32.preloadMessages(), {
|
|
4024
4118
|
body: { channels: channelIds },
|
|
4025
4119
|
auth: true
|
|
4026
4120
|
});
|
|
4027
4121
|
}
|
|
4028
4122
|
function preloadMessagesAlt(client, channelIds) {
|
|
4029
4123
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
4030
|
-
return client.rest.post(
|
|
4124
|
+
return client.rest.post(Routes32.preloadMessagesAlt(), {
|
|
4031
4125
|
body: { channels: channelIds },
|
|
4032
4126
|
auth: true
|
|
4033
4127
|
});
|
|
@@ -4035,7 +4129,7 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
4035
4129
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
4036
4130
|
validateBulkMessageFetchRequests(requests);
|
|
4037
4131
|
const wire = toBulkFetchWire(requests);
|
|
4038
|
-
const data = await client.rest.post(
|
|
4132
|
+
const data = await client.rest.post(Routes32.channelsMessagesBulk(), {
|
|
4039
4133
|
body: { requests: wire },
|
|
4040
4134
|
auth: true
|
|
4041
4135
|
});
|
|
@@ -4122,62 +4216,6 @@ function buildRegistry(...maps) {
|
|
|
4122
4216
|
return registry;
|
|
4123
4217
|
}
|
|
4124
4218
|
|
|
4125
|
-
// src/structures/MessageReaction.ts
|
|
4126
|
-
import { Routes as Routes32 } from "@fluxerjs/types";
|
|
4127
|
-
import { FluxerAPIError as FluxerAPIError5, RateLimitError as RateLimitError4 } from "@fluxerjs/rest";
|
|
4128
|
-
var MessageReaction = class extends Base {
|
|
4129
|
-
client;
|
|
4130
|
-
messageId;
|
|
4131
|
-
channelId;
|
|
4132
|
-
guildId;
|
|
4133
|
-
emoji;
|
|
4134
|
-
/** Raw gateway payload for low-level access. */
|
|
4135
|
-
_data;
|
|
4136
|
-
constructor(client, data) {
|
|
4137
|
-
super();
|
|
4138
|
-
this.client = client;
|
|
4139
|
-
this._data = data;
|
|
4140
|
-
this.messageId = data.message_id;
|
|
4141
|
-
this.channelId = data.channel_id;
|
|
4142
|
-
this.guildId = data.guild_id ?? null;
|
|
4143
|
-
this.emoji = {
|
|
4144
|
-
name: data.emoji.name,
|
|
4145
|
-
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
4146
|
-
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
4147
|
-
};
|
|
4148
|
-
}
|
|
4149
|
-
/** Emoji as a string: unicode or "name:id" for custom. */
|
|
4150
|
-
get emojiIdentifier() {
|
|
4151
|
-
return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
4152
|
-
}
|
|
4153
|
-
/** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
|
|
4154
|
-
get guild() {
|
|
4155
|
-
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
4156
|
-
}
|
|
4157
|
-
/**
|
|
4158
|
-
* Fetch the message this reaction belongs to.
|
|
4159
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
4160
|
-
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
4161
|
-
*/
|
|
4162
|
-
async fetchMessage() {
|
|
4163
|
-
try {
|
|
4164
|
-
const data = await this.client.rest.get(
|
|
4165
|
-
Routes32.channelMessage(this.channelId, this.messageId)
|
|
4166
|
-
);
|
|
4167
|
-
return new Message(this.client, data);
|
|
4168
|
-
} catch (err) {
|
|
4169
|
-
if (err instanceof RateLimitError4) throw err;
|
|
4170
|
-
if (err instanceof FluxerAPIError5 && err.statusCode === 404) {
|
|
4171
|
-
throw new FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
4172
|
-
code: ErrorCodes.MessageNotFound,
|
|
4173
|
-
cause: err
|
|
4174
|
-
});
|
|
4175
|
-
}
|
|
4176
|
-
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
4177
|
-
}
|
|
4178
|
-
}
|
|
4179
|
-
};
|
|
4180
|
-
|
|
4181
4219
|
// src/client/eventHandlers/helpers.ts
|
|
4182
4220
|
function unknownUser(id) {
|
|
4183
4221
|
return { id, username: "Unknown", discriminator: "0" };
|
|
@@ -4348,13 +4386,50 @@ function normalizeGuildPayload(raw) {
|
|
|
4348
4386
|
}
|
|
4349
4387
|
|
|
4350
4388
|
// src/client/eventHandlers/guilds.ts
|
|
4389
|
+
function markGuildUnavailable(client, id) {
|
|
4390
|
+
const guild = client.guilds.get(id);
|
|
4391
|
+
if (!guild || guild.available === false) return;
|
|
4392
|
+
guild.available = false;
|
|
4393
|
+
client.emit(Events.GuildUnavailable, guild);
|
|
4394
|
+
}
|
|
4395
|
+
function refreshRecoveredGuild(guild, data) {
|
|
4396
|
+
guild._patch(data);
|
|
4397
|
+
if (data.roles !== void 0) {
|
|
4398
|
+
guild.roles.clear();
|
|
4399
|
+
for (const role of data.roles) {
|
|
4400
|
+
guild.roles.set(role.id, new Role(guild.client, role, guild.id));
|
|
4401
|
+
}
|
|
4402
|
+
}
|
|
4403
|
+
if (data.channels !== void 0) {
|
|
4404
|
+
const recoveredChannelIds = new Set(data.channels.map((channel) => channel.id));
|
|
4405
|
+
for (const channel of guild.channels.values()) {
|
|
4406
|
+
guild.client.channels.delete(channel.id);
|
|
4407
|
+
if (!recoveredChannelIds.has(channel.id)) guild.client._clearMessageCache(channel.id);
|
|
4408
|
+
}
|
|
4409
|
+
guild.channels.clear();
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4351
4412
|
var guildHandlers = {
|
|
4352
4413
|
GUILD_CREATE(client, d) {
|
|
4414
|
+
const raw = d;
|
|
4415
|
+
if (raw.unavailable === true) {
|
|
4416
|
+
if (typeof raw.id === "string") {
|
|
4417
|
+
try {
|
|
4418
|
+
markGuildUnavailable(client, raw.id);
|
|
4419
|
+
} finally {
|
|
4420
|
+
client._onGuildReceived(raw.id);
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4423
|
+
return;
|
|
4424
|
+
}
|
|
4353
4425
|
const guildData = normalizeGuildPayload(d);
|
|
4354
4426
|
if (!guildData) return;
|
|
4355
|
-
const guild = new Guild(client, guildData);
|
|
4356
|
-
client.guilds.set(guild.id, guild);
|
|
4357
4427
|
const g = d;
|
|
4428
|
+
const existing = client.guilds.get(guildData.id);
|
|
4429
|
+
const recovered = existing?.available === false;
|
|
4430
|
+
const guild = recovered && existing ? existing : new Guild(client, guildData);
|
|
4431
|
+
if (recovered) refreshRecoveredGuild(guild, g);
|
|
4432
|
+
client.guilds.set(guild.id, guild);
|
|
4358
4433
|
for (const ch of g.channels ?? []) {
|
|
4359
4434
|
const channel = Channel.from(client, ch);
|
|
4360
4435
|
if (channel) {
|
|
@@ -4363,7 +4438,8 @@ var guildHandlers = {
|
|
|
4363
4438
|
}
|
|
4364
4439
|
}
|
|
4365
4440
|
for (const m of g.members ?? []) cacheMember2(client, guild, m);
|
|
4366
|
-
|
|
4441
|
+
if (recovered) guild.available = true;
|
|
4442
|
+
client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
|
|
4367
4443
|
if (g.voice_states?.length) {
|
|
4368
4444
|
client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
|
|
4369
4445
|
}
|
|
@@ -4384,11 +4460,19 @@ var guildHandlers = {
|
|
|
4384
4460
|
client.emit(Events.GuildUpdate, updated, updated);
|
|
4385
4461
|
},
|
|
4386
4462
|
GUILD_DELETE(client, d) {
|
|
4387
|
-
const { id } = d;
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4463
|
+
const { id, unavailable } = d;
|
|
4464
|
+
try {
|
|
4465
|
+
if (unavailable === true) {
|
|
4466
|
+
markGuildUnavailable(client, id);
|
|
4467
|
+
return;
|
|
4468
|
+
}
|
|
4469
|
+
const guild = client.guilds.get(id);
|
|
4470
|
+
if (!guild) return;
|
|
4471
|
+
client.guilds.delete(id);
|
|
4472
|
+
client.emit(Events.GuildDelete, guild);
|
|
4473
|
+
} finally {
|
|
4474
|
+
client._onGuildReceived(id);
|
|
4475
|
+
}
|
|
4392
4476
|
}
|
|
4393
4477
|
};
|
|
4394
4478
|
|
|
@@ -4810,7 +4894,12 @@ function emitClientError(client, err) {
|
|
|
4810
4894
|
function shouldDeferGatewayDispatchUntilReady(client, payload) {
|
|
4811
4895
|
if (client.options.waitForGuilds !== true || client.readyAt !== null) return false;
|
|
4812
4896
|
if (payload.op !== 0 || !payload.t) return false;
|
|
4813
|
-
|
|
4897
|
+
if (payload.t === "GUILD_CREATE") return false;
|
|
4898
|
+
if (payload.t === "GUILD_DELETE") {
|
|
4899
|
+
const data = payload.d;
|
|
4900
|
+
if (typeof data?.id === "string" && client._pendingGuildIds?.has(data.id)) return false;
|
|
4901
|
+
}
|
|
4902
|
+
return true;
|
|
4814
4903
|
}
|
|
4815
4904
|
function handleGatewayDispatch(client, payload, deferred) {
|
|
4816
4905
|
if (payload.op !== 0 || !payload.t) return Promise.resolve();
|