@fluxerjs/core 2.0.2 → 2.1.0
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 +363 -310
- package/dist/client.mjs +337 -284
- package/dist/cluster.d.mts +1 -1
- package/dist/cluster.d.ts +1 -1
- package/dist/cluster.js +365 -310
- package/dist/cluster.mjs +339 -284
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +363 -310
- package/dist/index.mjs +337 -284
- package/dist/message.d.mts +1 -1
- package/dist/message.d.ts +1 -1
- package/dist/message.js +119 -29
- package/dist/message.mjs +118 -28
- package/dist/{subpath-message-CoDItxh0.d.mts → subpath-message-CWiBEUUV.d.mts} +7 -1
- package/dist/{subpath-message-CoDItxh0.d.ts → subpath-message-CWiBEUUV.d.ts} +7 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -134,8 +134,8 @@ var import_types46 = require("@fluxerjs/types");
|
|
|
134
134
|
|
|
135
135
|
// src/client/ChannelManager.ts
|
|
136
136
|
var import_collection5 = require("@fluxerjs/collection");
|
|
137
|
-
var
|
|
138
|
-
var
|
|
137
|
+
var import_types17 = require("@fluxerjs/types");
|
|
138
|
+
var import_rest4 = require("@fluxerjs/rest");
|
|
139
139
|
|
|
140
140
|
// src/errors/FluxerError.ts
|
|
141
141
|
var import_util = require("@fluxerjs/util");
|
|
@@ -330,17 +330,17 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
// src/structures/channel/base.ts
|
|
333
|
-
var
|
|
333
|
+
var import_types10 = require("@fluxerjs/types");
|
|
334
334
|
|
|
335
335
|
// src/client/MessageManager.ts
|
|
336
|
-
var
|
|
336
|
+
var import_types8 = require("@fluxerjs/types");
|
|
337
337
|
var import_collection3 = require("@fluxerjs/collection");
|
|
338
|
-
var
|
|
338
|
+
var import_rest2 = require("@fluxerjs/rest");
|
|
339
339
|
|
|
340
340
|
// src/structures/message/Message.ts
|
|
341
341
|
var import_collection2 = require("@fluxerjs/collection");
|
|
342
342
|
var import_builders3 = require("@fluxerjs/builders");
|
|
343
|
-
var
|
|
343
|
+
var import_types6 = require("@fluxerjs/types");
|
|
344
344
|
|
|
345
345
|
// src/client/sdkOptions.ts
|
|
346
346
|
function toMemberSearchBody(options) {
|
|
@@ -581,6 +581,68 @@ function toProfilePayload(data) {
|
|
|
581
581
|
var import_events = require("events");
|
|
582
582
|
var import_collection = require("@fluxerjs/collection");
|
|
583
583
|
|
|
584
|
+
// src/structures/MessageReaction.ts
|
|
585
|
+
var import_types3 = require("@fluxerjs/types");
|
|
586
|
+
var import_rest = require("@fluxerjs/rest");
|
|
587
|
+
|
|
588
|
+
// src/structures/Base.ts
|
|
589
|
+
var Base = class {
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// src/structures/MessageReaction.ts
|
|
593
|
+
var MessageReaction = class extends Base {
|
|
594
|
+
client;
|
|
595
|
+
messageId;
|
|
596
|
+
channelId;
|
|
597
|
+
guildId;
|
|
598
|
+
emoji;
|
|
599
|
+
/** Raw gateway payload for low-level access. */
|
|
600
|
+
_data;
|
|
601
|
+
constructor(client, data) {
|
|
602
|
+
super();
|
|
603
|
+
this.client = client;
|
|
604
|
+
this._data = data;
|
|
605
|
+
this.messageId = data.message_id;
|
|
606
|
+
this.channelId = data.channel_id;
|
|
607
|
+
this.guildId = data.guild_id ?? null;
|
|
608
|
+
this.emoji = {
|
|
609
|
+
name: data.emoji.name,
|
|
610
|
+
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
611
|
+
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/** Emoji as a string: unicode or "name:id" for custom. */
|
|
615
|
+
get emojiIdentifier() {
|
|
616
|
+
return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
617
|
+
}
|
|
618
|
+
/** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
|
|
619
|
+
get guild() {
|
|
620
|
+
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Fetch the message this reaction belongs to.
|
|
624
|
+
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
625
|
+
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
626
|
+
*/
|
|
627
|
+
async fetchMessage() {
|
|
628
|
+
try {
|
|
629
|
+
const data = await this.client.rest.get(
|
|
630
|
+
import_types3.Routes.channelMessage(this.channelId, this.messageId)
|
|
631
|
+
);
|
|
632
|
+
return new Message(this.client, data);
|
|
633
|
+
} catch (err) {
|
|
634
|
+
if (err instanceof import_rest.RateLimitError) throw err;
|
|
635
|
+
if (err instanceof import_rest.FluxerAPIError && err.statusCode === 404) {
|
|
636
|
+
throw new import_util.FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
637
|
+
code: import_util2.ErrorCodes.MessageNotFound,
|
|
638
|
+
cause: err
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError(String(err), { cause: err });
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
|
|
584
646
|
// src/util/Events.ts
|
|
585
647
|
var Events = {
|
|
586
648
|
Ready: "ready",
|
|
@@ -644,7 +706,8 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
644
706
|
collected = new import_collection.Collection();
|
|
645
707
|
_timeout = null;
|
|
646
708
|
_ended = false;
|
|
647
|
-
|
|
709
|
+
_onAdd;
|
|
710
|
+
_onAddMany;
|
|
648
711
|
constructor(client, messageId, channelId, options = {}) {
|
|
649
712
|
super();
|
|
650
713
|
this.client = client;
|
|
@@ -655,27 +718,58 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
655
718
|
time: options.time ?? 0,
|
|
656
719
|
max: options.max ?? 0
|
|
657
720
|
};
|
|
658
|
-
this.
|
|
721
|
+
this._onAdd = (payload) => {
|
|
659
722
|
if (this._ended || payload.reaction.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
660
723
|
return;
|
|
661
724
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
this.
|
|
666
|
-
|
|
667
|
-
|
|
725
|
+
this._collect(payload.reaction, payload.user, payload.userId);
|
|
726
|
+
};
|
|
727
|
+
this._onAddMany = (payload) => {
|
|
728
|
+
if (this._ended || payload.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
for (const entry of payload.reactions) {
|
|
732
|
+
if (this._ended) return;
|
|
733
|
+
const reaction = new MessageReaction(this.client, {
|
|
734
|
+
message_id: payload.messageId,
|
|
735
|
+
channel_id: payload.channelId,
|
|
736
|
+
guild_id: payload.guildId ?? void 0,
|
|
737
|
+
user_id: entry.userId,
|
|
738
|
+
emoji: {
|
|
739
|
+
name: entry.emoji.name,
|
|
740
|
+
...entry.emoji.id !== void 0 ? { id: entry.emoji.id } : {},
|
|
741
|
+
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
|
|
745
|
+
id: entry.userId,
|
|
746
|
+
username: "Unknown",
|
|
747
|
+
discriminator: "0"
|
|
748
|
+
});
|
|
749
|
+
this._collect(reaction, user, entry.userId);
|
|
668
750
|
}
|
|
669
751
|
};
|
|
670
|
-
this.client.on(Events.MessageReactionAdd, this.
|
|
752
|
+
this.client.on(Events.MessageReactionAdd, this._onAdd);
|
|
753
|
+
this.client.on(Events.MessageReactionAddMany, this._onAddMany);
|
|
671
754
|
if (this.options.time > 0) {
|
|
672
755
|
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
673
756
|
}
|
|
674
757
|
}
|
|
758
|
+
_collect(reaction, user, userId) {
|
|
759
|
+
if (this._ended) return;
|
|
760
|
+
if (!this.options.filter(reaction, user)) return;
|
|
761
|
+
const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
|
|
762
|
+
this.collected.set(key, { reaction, user });
|
|
763
|
+
this.emit("collect", reaction, user);
|
|
764
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
765
|
+
this.stop("limit");
|
|
766
|
+
}
|
|
767
|
+
}
|
|
675
768
|
stop(reason = "user") {
|
|
676
769
|
if (this._ended) return;
|
|
677
770
|
this._ended = true;
|
|
678
|
-
this.client.off(Events.MessageReactionAdd, this.
|
|
771
|
+
this.client.off(Events.MessageReactionAdd, this._onAdd);
|
|
772
|
+
this.client.off(Events.MessageReactionAddMany, this._onAddMany);
|
|
679
773
|
if (this._timeout) {
|
|
680
774
|
clearTimeout(this._timeout);
|
|
681
775
|
this._timeout = null;
|
|
@@ -690,30 +784,26 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
690
784
|
}
|
|
691
785
|
};
|
|
692
786
|
|
|
693
|
-
// src/structures/Base.ts
|
|
694
|
-
var Base = class {
|
|
695
|
-
};
|
|
696
|
-
|
|
697
787
|
// src/structures/message/reactions.ts
|
|
698
|
-
var
|
|
788
|
+
var import_types4 = require("@fluxerjs/types");
|
|
699
789
|
async function emojiPath(message, emoji) {
|
|
700
790
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
701
791
|
}
|
|
702
792
|
async function reactToMessage(message, emoji) {
|
|
703
793
|
const e = await emojiPath(message, emoji);
|
|
704
|
-
await message.client.rest.put(
|
|
794
|
+
await message.client.rest.put(import_types4.Routes.channelMessageReactionMe(message.channelId, message.id, e));
|
|
705
795
|
}
|
|
706
796
|
async function removeMessageReaction(message, emoji, userId) {
|
|
707
797
|
const e = await emojiPath(message, emoji);
|
|
708
|
-
const route = userId ?
|
|
798
|
+
const route = userId ? import_types4.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types4.Routes.channelMessageReactionMe(message.channelId, message.id, e);
|
|
709
799
|
await message.client.rest.delete(route);
|
|
710
800
|
}
|
|
711
801
|
async function removeAllMessageReactions(message) {
|
|
712
|
-
await message.client.rest.delete(
|
|
802
|
+
await message.client.rest.delete(import_types4.Routes.channelMessageReactions(message.channelId, message.id));
|
|
713
803
|
}
|
|
714
804
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
715
805
|
const e = await emojiPath(message, emoji);
|
|
716
|
-
await message.client.rest.delete(
|
|
806
|
+
await message.client.rest.delete(import_types4.Routes.channelMessageReaction(message.channelId, message.id, e));
|
|
717
807
|
}
|
|
718
808
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
719
809
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -724,7 +814,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
724
814
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
725
815
|
if (options?.after) params.set("after", options.after);
|
|
726
816
|
const qs2 = params.toString();
|
|
727
|
-
const route =
|
|
817
|
+
const route = import_types4.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
|
|
728
818
|
const data = await message.client.rest.get(route);
|
|
729
819
|
if (Array.isArray(data)) {
|
|
730
820
|
return {
|
|
@@ -743,7 +833,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
743
833
|
|
|
744
834
|
// src/structures/message/send.ts
|
|
745
835
|
var import_builders2 = require("@fluxerjs/builders");
|
|
746
|
-
var
|
|
836
|
+
var import_types5 = require("@fluxerjs/types");
|
|
747
837
|
function toReplyTarget(ref) {
|
|
748
838
|
return {
|
|
749
839
|
channelId: ref.channel_id,
|
|
@@ -777,7 +867,7 @@ function asReplyTarget(value) {
|
|
|
777
867
|
}
|
|
778
868
|
async function sendPrepared(message, payload) {
|
|
779
869
|
const data = await message.client.rest.post(
|
|
780
|
-
|
|
870
|
+
import_types5.Routes.channelMessages(message.channelId),
|
|
781
871
|
payload
|
|
782
872
|
);
|
|
783
873
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -896,7 +986,7 @@ var Message = class _Message extends Base {
|
|
|
896
986
|
this.pinned = data.pinned;
|
|
897
987
|
this.attachments = new import_collection2.Collection();
|
|
898
988
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
899
|
-
this.type = data.type ??
|
|
989
|
+
this.type = data.type ?? import_types6.MessageType.Default;
|
|
900
990
|
this.flags = data.flags ?? 0;
|
|
901
991
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
902
992
|
this.tts = data.tts ?? false;
|
|
@@ -954,7 +1044,7 @@ var Message = class _Message extends Base {
|
|
|
954
1044
|
if (options.attachments !== void 0) {
|
|
955
1045
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
956
1046
|
}
|
|
957
|
-
const data = await this.client.rest.patch(
|
|
1047
|
+
const data = await this.client.rest.patch(import_types6.Routes.channelMessage(this.channelId, this.id), {
|
|
958
1048
|
body
|
|
959
1049
|
});
|
|
960
1050
|
const updated = new _Message(this.client, data);
|
|
@@ -971,25 +1061,25 @@ var Message = class _Message extends Base {
|
|
|
971
1061
|
}
|
|
972
1062
|
/** Delete this message. */
|
|
973
1063
|
async delete() {
|
|
974
|
-
await this.client.rest.delete(
|
|
1064
|
+
await this.client.rest.delete(import_types6.Routes.channelMessage(this.channelId, this.id));
|
|
975
1065
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
976
1066
|
}
|
|
977
1067
|
/** Delete a specific attachment from this message. */
|
|
978
1068
|
async deleteAttachment(attachmentId) {
|
|
979
1069
|
await this.client.rest.delete(
|
|
980
|
-
|
|
1070
|
+
import_types6.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
981
1071
|
{ auth: true }
|
|
982
1072
|
);
|
|
983
1073
|
this.attachments.delete(attachmentId);
|
|
984
1074
|
}
|
|
985
1075
|
/** Pin this message in the channel. */
|
|
986
1076
|
async pin() {
|
|
987
|
-
await this.client.rest.put(
|
|
1077
|
+
await this.client.rest.put(import_types6.Routes.channelPinMessage(this.channelId, this.id));
|
|
988
1078
|
this.pinned = true;
|
|
989
1079
|
}
|
|
990
1080
|
/** Unpin this message from the channel. */
|
|
991
1081
|
async unpin() {
|
|
992
|
-
await this.client.rest.delete(
|
|
1082
|
+
await this.client.rest.delete(import_types6.Routes.channelPinMessage(this.channelId, this.id));
|
|
993
1083
|
this.pinned = false;
|
|
994
1084
|
}
|
|
995
1085
|
/** React to this message with an emoji. */
|
|
@@ -1070,12 +1160,12 @@ var MessageManager = class {
|
|
|
1070
1160
|
async fetchOne(messageId) {
|
|
1071
1161
|
try {
|
|
1072
1162
|
const data = await this.client.rest.get(
|
|
1073
|
-
|
|
1163
|
+
import_types8.Routes.channelMessage(this.channelId, messageId)
|
|
1074
1164
|
);
|
|
1075
1165
|
return this.wrap(data);
|
|
1076
1166
|
} catch (err) {
|
|
1077
|
-
if (err instanceof
|
|
1078
|
-
if (err instanceof
|
|
1167
|
+
if (err instanceof import_rest2.RateLimitError) throw err;
|
|
1168
|
+
if (err instanceof import_rest2.FluxerAPIError && err.statusCode === 404) {
|
|
1079
1169
|
throw new import_util.FluxerError(`Message ${messageId} not found in channel ${this.channelId}`, {
|
|
1080
1170
|
code: import_util2.ErrorCodes.MessageNotFound,
|
|
1081
1171
|
cause: err
|
|
@@ -1096,7 +1186,7 @@ var MessageManager = class {
|
|
|
1096
1186
|
const value = options[key];
|
|
1097
1187
|
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1098
1188
|
}
|
|
1099
|
-
const base =
|
|
1189
|
+
const base = import_types8.Routes.channelMessages(this.channelId);
|
|
1100
1190
|
const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
|
|
1101
1191
|
const collection = new import_collection3.Collection();
|
|
1102
1192
|
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
@@ -1105,7 +1195,7 @@ var MessageManager = class {
|
|
|
1105
1195
|
};
|
|
1106
1196
|
|
|
1107
1197
|
// src/structures/channel/attachments.ts
|
|
1108
|
-
var
|
|
1198
|
+
var import_types9 = require("@fluxerjs/types");
|
|
1109
1199
|
function asBytes(data) {
|
|
1110
1200
|
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
1111
1201
|
const out = new Uint8Array(src.byteLength);
|
|
@@ -1126,7 +1216,7 @@ async function putBlob(url, body, contentType) {
|
|
|
1126
1216
|
}
|
|
1127
1217
|
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
1128
1218
|
const plan = await client.rest.post(
|
|
1129
|
-
|
|
1219
|
+
import_types9.Routes.channelAttachments(channelId),
|
|
1130
1220
|
{
|
|
1131
1221
|
body: {
|
|
1132
1222
|
attachments: files.map((f) => ({
|
|
@@ -1172,7 +1262,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
|
|
|
1172
1262
|
});
|
|
1173
1263
|
}
|
|
1174
1264
|
if (multipart.length) {
|
|
1175
|
-
await client.rest.post(
|
|
1265
|
+
await client.rest.post(import_types9.Routes.channelAttachmentsComplete(channelId), {
|
|
1176
1266
|
body: { uploads: multipart },
|
|
1177
1267
|
auth: true
|
|
1178
1268
|
});
|
|
@@ -1231,11 +1321,11 @@ var Channel = class extends Base {
|
|
|
1231
1321
|
}
|
|
1232
1322
|
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1233
1323
|
isDM() {
|
|
1234
|
-
return this.type ===
|
|
1324
|
+
return this.type === import_types10.ChannelType.DM || this.type === import_types10.ChannelType.GroupDM || this.type === import_types10.ChannelType.DMPersonalNotes;
|
|
1235
1325
|
}
|
|
1236
1326
|
/** Check if this is a personal notes channel. */
|
|
1237
1327
|
isPersonalNotes() {
|
|
1238
|
-
return this.type ===
|
|
1328
|
+
return this.type === import_types10.ChannelType.DMPersonalNotes;
|
|
1239
1329
|
}
|
|
1240
1330
|
/** Check if this is a voice channel. */
|
|
1241
1331
|
isVoice() {
|
|
@@ -1266,7 +1356,7 @@ var Channel = class extends Base {
|
|
|
1266
1356
|
}
|
|
1267
1357
|
if (ids.length === 0) return [];
|
|
1268
1358
|
if (ids.length === 1) {
|
|
1269
|
-
await this.client.rest.delete(
|
|
1359
|
+
await this.client.rest.delete(import_types10.Routes.channelMessage(this.id, ids[0]), { auth: true });
|
|
1270
1360
|
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
1271
1361
|
return ids;
|
|
1272
1362
|
}
|
|
@@ -1275,7 +1365,7 @@ var Channel = class extends Base {
|
|
|
1275
1365
|
code: import_util2.ErrorCodes.InvalidBulkDelete
|
|
1276
1366
|
});
|
|
1277
1367
|
}
|
|
1278
|
-
await this.client.rest.post(
|
|
1368
|
+
await this.client.rest.post(import_types10.Routes.channelBulkDelete(this.id), {
|
|
1279
1369
|
body: { message_ids: ids },
|
|
1280
1370
|
auth: true
|
|
1281
1371
|
});
|
|
@@ -1285,23 +1375,23 @@ var Channel = class extends Base {
|
|
|
1285
1375
|
/** Delete all messages sent by the bot in this channel (user account feature). */
|
|
1286
1376
|
async bulkDeleteMyMessages(options) {
|
|
1287
1377
|
const body = options ? toSudoBody(options) : void 0;
|
|
1288
|
-
await this.client.rest.post(
|
|
1378
|
+
await this.client.rest.post(import_types10.Routes.channelBulkDeleteMine(this.id), {
|
|
1289
1379
|
body: body && Object.keys(body).length ? body : void 0,
|
|
1290
1380
|
auth: true
|
|
1291
1381
|
});
|
|
1292
1382
|
}
|
|
1293
1383
|
/** Mark all pinned messages as read in this channel. */
|
|
1294
1384
|
async acknowledgePins() {
|
|
1295
|
-
await this.client.rest.post(
|
|
1385
|
+
await this.client.rest.post(import_types10.Routes.channelPinsAck(this.id), { auth: true });
|
|
1296
1386
|
}
|
|
1297
1387
|
/** Clear the read state for this channel. */
|
|
1298
1388
|
async clearReadState() {
|
|
1299
|
-
await this.client.rest.delete(
|
|
1389
|
+
await this.client.rest.delete(import_types10.Routes.channelMessagesAck(this.id), { auth: true });
|
|
1300
1390
|
}
|
|
1301
1391
|
/** Request upload URLs for attachments before sending a message. */
|
|
1302
1392
|
async requestAttachmentUploads(attachments) {
|
|
1303
1393
|
const data = await this.client.rest.post(
|
|
1304
|
-
|
|
1394
|
+
import_types10.Routes.channelAttachments(this.id),
|
|
1305
1395
|
{
|
|
1306
1396
|
body: toAttachmentUploadPlanBody(attachments),
|
|
1307
1397
|
auth: true
|
|
@@ -1312,7 +1402,7 @@ var Channel = class extends Base {
|
|
|
1312
1402
|
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
1313
1403
|
async completeAttachmentUploads(uploads) {
|
|
1314
1404
|
const data = await this.client.rest.post(
|
|
1315
|
-
|
|
1405
|
+
import_types10.Routes.channelAttachmentsComplete(this.id),
|
|
1316
1406
|
{
|
|
1317
1407
|
body: toAttachmentUploadCompleteBody(uploads),
|
|
1318
1408
|
auth: true
|
|
@@ -1328,11 +1418,11 @@ var Channel = class extends Base {
|
|
|
1328
1418
|
}
|
|
1329
1419
|
/** Trigger the typing indicator in this channel. */
|
|
1330
1420
|
async sendTyping() {
|
|
1331
|
-
await this.client.rest.post(
|
|
1421
|
+
await this.client.rest.post(import_types10.Routes.channelTyping(this.id), { auth: true });
|
|
1332
1422
|
}
|
|
1333
1423
|
/** Fetch available RTC regions for voice channels. */
|
|
1334
1424
|
async fetchRtcRegions() {
|
|
1335
|
-
const data = await this.client.rest.get(
|
|
1425
|
+
const data = await this.client.rest.get(import_types10.Routes.channelRtcRegions(this.id), {
|
|
1336
1426
|
auth: true
|
|
1337
1427
|
});
|
|
1338
1428
|
return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
|
|
@@ -1340,7 +1430,7 @@ var Channel = class extends Base {
|
|
|
1340
1430
|
/** Fetch slowmode state for this channel. */
|
|
1341
1431
|
async fetchSlowmode() {
|
|
1342
1432
|
const data = await this.client.rest.get(
|
|
1343
|
-
|
|
1433
|
+
import_types10.Routes.channelSlowmode(this.id),
|
|
1344
1434
|
{ auth: true }
|
|
1345
1435
|
);
|
|
1346
1436
|
return {
|
|
@@ -1356,14 +1446,14 @@ var Channel = class extends Base {
|
|
|
1356
1446
|
};
|
|
1357
1447
|
|
|
1358
1448
|
// src/structures/channel/guild.ts
|
|
1359
|
-
var
|
|
1449
|
+
var import_types14 = require("@fluxerjs/types");
|
|
1360
1450
|
var import_util3 = require("@fluxerjs/util");
|
|
1361
1451
|
|
|
1362
1452
|
// src/structures/Invite.ts
|
|
1363
|
-
var
|
|
1453
|
+
var import_types11 = require("@fluxerjs/types");
|
|
1364
1454
|
|
|
1365
1455
|
// src/util/Constants.ts
|
|
1366
|
-
var
|
|
1456
|
+
var import_rest3 = require("@fluxerjs/rest");
|
|
1367
1457
|
var CDN_URL = "https://fluxerusercontent.com";
|
|
1368
1458
|
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1369
1459
|
|
|
@@ -1547,12 +1637,12 @@ var Invite = class _Invite extends Base {
|
|
|
1547
1637
|
this.client = client;
|
|
1548
1638
|
this.code = data.code;
|
|
1549
1639
|
this.type = data.type;
|
|
1550
|
-
this.guild = (0,
|
|
1551
|
-
this.channel = (0,
|
|
1552
|
-
this.pack = (0,
|
|
1640
|
+
this.guild = (0, import_types11.isGuildInvite)(data) ? data.guild : null;
|
|
1641
|
+
this.channel = (0, import_types11.isGuildInvite)(data) || (0, import_types11.isGroupDmInvite)(data) ? data.channel : null;
|
|
1642
|
+
this.pack = (0, import_types11.isPackInvite)(data) ? data.pack : null;
|
|
1553
1643
|
this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
|
|
1554
|
-
this.memberCount = (0,
|
|
1555
|
-
this.presenceCount = (0,
|
|
1644
|
+
this.memberCount = (0, import_types11.isPackInvite)(data) ? null : data.member_count ?? null;
|
|
1645
|
+
this.presenceCount = (0, import_types11.isGuildInvite)(data) ? data.presence_count ?? null : null;
|
|
1556
1646
|
this.expiresAt = data.expires_at ?? null;
|
|
1557
1647
|
this.temporary = data.temporary ?? null;
|
|
1558
1648
|
this.createdAt = data.created_at ?? null;
|
|
@@ -1561,13 +1651,13 @@ var Invite = class _Invite extends Base {
|
|
|
1561
1651
|
this.maxAge = data.max_age ?? null;
|
|
1562
1652
|
}
|
|
1563
1653
|
isGuild() {
|
|
1564
|
-
return this.type ===
|
|
1654
|
+
return this.type === import_types11.InviteType.Guild;
|
|
1565
1655
|
}
|
|
1566
1656
|
isGroupDM() {
|
|
1567
|
-
return this.type ===
|
|
1657
|
+
return this.type === import_types11.InviteType.GroupDM;
|
|
1568
1658
|
}
|
|
1569
1659
|
isPack() {
|
|
1570
|
-
return this.type ===
|
|
1660
|
+
return this.type === import_types11.InviteType.EmojiPack || this.type === import_types11.InviteType.StickerPack;
|
|
1571
1661
|
}
|
|
1572
1662
|
/** Full invite URL (uses this client's instance invite base). */
|
|
1573
1663
|
get url() {
|
|
@@ -1579,18 +1669,18 @@ var Invite = class _Invite extends Base {
|
|
|
1579
1669
|
}
|
|
1580
1670
|
/** Fetch invite metadata by code or URL (does not join). */
|
|
1581
1671
|
static async fetch(client, codeOrUrl) {
|
|
1582
|
-
const data = await client.rest.get(
|
|
1672
|
+
const data = await client.rest.get(import_types11.Routes.invite(parseInviteCode(codeOrUrl)));
|
|
1583
1673
|
return new _Invite(client, data);
|
|
1584
1674
|
}
|
|
1585
1675
|
/** Delete this invite. Requires Manage Guild or Create Instant Invite. */
|
|
1586
1676
|
async delete() {
|
|
1587
|
-
await this.client.rest.delete(
|
|
1677
|
+
await this.client.rest.delete(import_types11.Routes.invite(this.code), { auth: true });
|
|
1588
1678
|
}
|
|
1589
1679
|
};
|
|
1590
1680
|
|
|
1591
1681
|
// src/structures/Webhook.ts
|
|
1592
1682
|
var import_builders4 = require("@fluxerjs/builders");
|
|
1593
|
-
var
|
|
1683
|
+
var import_types12 = require("@fluxerjs/types");
|
|
1594
1684
|
|
|
1595
1685
|
// src/util/cdn.ts
|
|
1596
1686
|
function mediaBase(options) {
|
|
@@ -1690,10 +1780,10 @@ var Webhook = class _Webhook extends Base {
|
|
|
1690
1780
|
/** Delete this webhook (token auth when available, otherwise bot auth). */
|
|
1691
1781
|
async delete() {
|
|
1692
1782
|
if (this.token) {
|
|
1693
|
-
await this.client.rest.delete(
|
|
1783
|
+
await this.client.rest.delete(import_types12.Routes.webhookExecute(this.id, this.token), { auth: false });
|
|
1694
1784
|
return;
|
|
1695
1785
|
}
|
|
1696
|
-
await this.client.rest.delete(
|
|
1786
|
+
await this.client.rest.delete(import_types12.Routes.webhook(this.id), { auth: true });
|
|
1697
1787
|
}
|
|
1698
1788
|
/**
|
|
1699
1789
|
* Edit name/avatar. With bot auth (no token), `channelId` may also be set.
|
|
@@ -1705,10 +1795,10 @@ var Webhook = class _Webhook extends Base {
|
|
|
1705
1795
|
if (!this.token && options.channelId !== void 0) {
|
|
1706
1796
|
body.channel_id = options.channelId;
|
|
1707
1797
|
}
|
|
1708
|
-
const data = this.token ? await this.client.rest.patch(
|
|
1798
|
+
const data = this.token ? await this.client.rest.patch(import_types12.Routes.webhookExecute(this.id, this.token), {
|
|
1709
1799
|
body,
|
|
1710
1800
|
auth: false
|
|
1711
|
-
}) : await this.client.rest.patch(
|
|
1801
|
+
}) : await this.client.rest.patch(import_types12.Routes.webhook(this.id), { body, auth: true });
|
|
1712
1802
|
this.name = data.name ?? this.name;
|
|
1713
1803
|
this.avatar = data.avatar ?? null;
|
|
1714
1804
|
if (!this.token) this.channelId = data.channel_id ?? this.channelId;
|
|
@@ -1729,7 +1819,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
1729
1819
|
if (overrides.avatarUrl !== void 0) {
|
|
1730
1820
|
body.avatar_url = overrides.avatarUrl;
|
|
1731
1821
|
}
|
|
1732
|
-
const route = `${
|
|
1822
|
+
const route = `${import_types12.Routes.webhookExecute(this.id, token)}${wait ? "?wait=true" : ""}`;
|
|
1733
1823
|
const data = await this.client.rest.post(route, {
|
|
1734
1824
|
body,
|
|
1735
1825
|
...files?.length ? { files } : {},
|
|
@@ -1770,7 +1860,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
1770
1860
|
}
|
|
1771
1861
|
/** Fetch a webhook by ID (bot auth; no token). */
|
|
1772
1862
|
static async fetch(client, webhookId) {
|
|
1773
|
-
const data = await client.rest.get(
|
|
1863
|
+
const data = await client.rest.get(import_types12.Routes.webhook(webhookId));
|
|
1774
1864
|
return new _Webhook(client, data);
|
|
1775
1865
|
}
|
|
1776
1866
|
/** Build a webhook from a stored id + token (e.g. webhook URL). */
|
|
@@ -1795,12 +1885,12 @@ var Webhook = class _Webhook extends Base {
|
|
|
1795
1885
|
return this.token;
|
|
1796
1886
|
}
|
|
1797
1887
|
messageRoute(messageId) {
|
|
1798
|
-
return
|
|
1888
|
+
return import_types12.Routes.webhookMessage(this.id, this.requireToken(), messageId);
|
|
1799
1889
|
}
|
|
1800
1890
|
};
|
|
1801
1891
|
|
|
1802
1892
|
// src/structures/channel/textCapable.ts
|
|
1803
|
-
var
|
|
1893
|
+
var import_types13 = require("@fluxerjs/types");
|
|
1804
1894
|
|
|
1805
1895
|
// src/util/MessageCollector.ts
|
|
1806
1896
|
var import_events2 = require("events");
|
|
@@ -1861,7 +1951,7 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
|
|
|
1861
1951
|
if (options?.before) params.set("before", options.before);
|
|
1862
1952
|
const qs2 = params.toString();
|
|
1863
1953
|
const data = await client.rest.get(
|
|
1864
|
-
|
|
1954
|
+
import_types13.Routes.channelPins(channelId) + (qs2 ? `?${qs2}` : "")
|
|
1865
1955
|
);
|
|
1866
1956
|
const items = data.items ?? [];
|
|
1867
1957
|
return {
|
|
@@ -1877,7 +1967,7 @@ function TextCapable(Base2) {
|
|
|
1877
1967
|
const payload = await prepareMessagePostPayload(options, {
|
|
1878
1968
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
1879
1969
|
});
|
|
1880
|
-
const data = await this.client.rest.post(
|
|
1970
|
+
const data = await this.client.rest.post(import_types13.Routes.channelMessages(this.id), payload);
|
|
1881
1971
|
this.client._addMessageToCache(this.id, data);
|
|
1882
1972
|
return new Message(this.client, data);
|
|
1883
1973
|
}
|
|
@@ -1934,7 +2024,7 @@ var GuildChannel = class extends Channel {
|
|
|
1934
2024
|
}
|
|
1935
2025
|
/** Create a webhook for this channel. Requires Manage Webhooks. */
|
|
1936
2026
|
async createWebhook(options) {
|
|
1937
|
-
const data = await this.client.rest.post(
|
|
2027
|
+
const data = await this.client.rest.post(import_types14.Routes.channelWebhooks(this.id), {
|
|
1938
2028
|
body: options,
|
|
1939
2029
|
auth: true
|
|
1940
2030
|
});
|
|
@@ -1942,13 +2032,13 @@ var GuildChannel = class extends Channel {
|
|
|
1942
2032
|
}
|
|
1943
2033
|
/** Fetch all webhooks in this channel. Requires Manage Webhooks. */
|
|
1944
2034
|
async fetchWebhooks() {
|
|
1945
|
-
const data = await this.client.rest.get(
|
|
2035
|
+
const data = await this.client.rest.get(import_types14.Routes.channelWebhooks(this.id));
|
|
1946
2036
|
return data.map((w) => new Webhook(this.client, w));
|
|
1947
2037
|
}
|
|
1948
2038
|
/** Create an invite for this channel. Requires Create Instant Invite. */
|
|
1949
2039
|
async createInvite(options) {
|
|
1950
2040
|
const body = options ? toChannelInviteBody(options) : {};
|
|
1951
|
-
const data = await this.client.rest.post(
|
|
2041
|
+
const data = await this.client.rest.post(import_types14.Routes.channelInvites(this.id), {
|
|
1952
2042
|
body: Object.keys(body).length ? body : void 0,
|
|
1953
2043
|
auth: true
|
|
1954
2044
|
});
|
|
@@ -1956,12 +2046,12 @@ var GuildChannel = class extends Channel {
|
|
|
1956
2046
|
}
|
|
1957
2047
|
/** Fetch all invites for this channel. Requires Manage Channels. */
|
|
1958
2048
|
async fetchInvites() {
|
|
1959
|
-
const data = await this.client.rest.get(
|
|
2049
|
+
const data = await this.client.rest.get(import_types14.Routes.channelInvites(this.id));
|
|
1960
2050
|
return data.map((i) => new Invite(this.client, i));
|
|
1961
2051
|
}
|
|
1962
2052
|
/** Edit or create a permission overwrite. Requires Manage Roles. */
|
|
1963
2053
|
async editPermission(overwriteId, options) {
|
|
1964
|
-
await this.client.rest.put(
|
|
2054
|
+
await this.client.rest.put(import_types14.Routes.channelPermission(this.id, overwriteId), {
|
|
1965
2055
|
body: options,
|
|
1966
2056
|
auth: true
|
|
1967
2057
|
});
|
|
@@ -1977,7 +2067,7 @@ var GuildChannel = class extends Channel {
|
|
|
1977
2067
|
}
|
|
1978
2068
|
/** Delete a permission overwrite. Requires Manage Roles. */
|
|
1979
2069
|
async deletePermission(overwriteId) {
|
|
1980
|
-
await this.client.rest.delete(
|
|
2070
|
+
await this.client.rest.delete(import_types14.Routes.channelPermission(this.id, overwriteId), { auth: true });
|
|
1981
2071
|
const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
|
|
1982
2072
|
if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
|
|
1983
2073
|
}
|
|
@@ -1990,7 +2080,7 @@ var GuildChannel = class extends Channel {
|
|
|
1990
2080
|
}
|
|
1991
2081
|
/** Edit this channel's settings. Requires Manage Channels. */
|
|
1992
2082
|
async edit(options) {
|
|
1993
|
-
const data = await this.client.rest.patch(
|
|
2083
|
+
const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
|
|
1994
2084
|
body: toChannelEditBody(options),
|
|
1995
2085
|
auth: true
|
|
1996
2086
|
});
|
|
@@ -2010,7 +2100,7 @@ var GuildChannel = class extends Channel {
|
|
|
2010
2100
|
const qs2 = params.toString();
|
|
2011
2101
|
const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
|
|
2012
2102
|
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2013
|
-
await this.client.rest.delete(
|
|
2103
|
+
await this.client.rest.delete(import_types14.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2014
2104
|
body,
|
|
2015
2105
|
auth: true
|
|
2016
2106
|
});
|
|
@@ -2072,7 +2162,7 @@ var LinkChannel = class extends GuildChannel {
|
|
|
2072
2162
|
};
|
|
2073
2163
|
|
|
2074
2164
|
// src/structures/channel/dm.ts
|
|
2075
|
-
var
|
|
2165
|
+
var import_types15 = require("@fluxerjs/types");
|
|
2076
2166
|
var DMChannel = class extends TextCapable(Channel) {
|
|
2077
2167
|
/** ID of the last message sent in this channel. */
|
|
2078
2168
|
lastMessageId;
|
|
@@ -2092,34 +2182,34 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2092
2182
|
}
|
|
2093
2183
|
/** Purge all messages from personal notes. Only works on personal notes channels. */
|
|
2094
2184
|
async purgeMessages() {
|
|
2095
|
-
if (this.type !==
|
|
2185
|
+
if (this.type !== import_types15.ChannelType.DMPersonalNotes) {
|
|
2096
2186
|
throw new import_util.FluxerError("purgeMessages is only available on personal notes channels", {
|
|
2097
2187
|
code: import_util2.ErrorCodes.InvalidChannelType
|
|
2098
2188
|
});
|
|
2099
2189
|
}
|
|
2100
2190
|
const data = await this.client.rest.post(
|
|
2101
|
-
|
|
2191
|
+
import_types15.Routes.channelMessagesPurge(this.id),
|
|
2102
2192
|
{ auth: true }
|
|
2103
2193
|
);
|
|
2104
2194
|
return data.deleted_count;
|
|
2105
2195
|
}
|
|
2106
2196
|
/** Pin this DM channel to the top of the DM list. */
|
|
2107
2197
|
async pinInList() {
|
|
2108
|
-
await this.client.rest.put(
|
|
2198
|
+
await this.client.rest.put(import_types15.Routes.userMeChannelPin(this.id), { auth: true });
|
|
2109
2199
|
}
|
|
2110
2200
|
/** Unpin this DM channel from the DM list. */
|
|
2111
2201
|
async unpinFromList() {
|
|
2112
|
-
await this.client.rest.delete(
|
|
2202
|
+
await this.client.rest.delete(import_types15.Routes.userMeChannelPin(this.id), { auth: true });
|
|
2113
2203
|
}
|
|
2114
2204
|
/** Add a user to this group DM. */
|
|
2115
2205
|
async addRecipient(userId) {
|
|
2116
|
-
await this.client.rest.put(
|
|
2206
|
+
await this.client.rest.put(import_types15.Routes.channelRecipient(this.id, userId), { auth: true });
|
|
2117
2207
|
const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
|
|
2118
2208
|
if (user) this.recipients.push(user);
|
|
2119
2209
|
}
|
|
2120
2210
|
/** Remove a user from this group DM. */
|
|
2121
2211
|
async removeRecipient(userId, options) {
|
|
2122
|
-
const url =
|
|
2212
|
+
const url = import_types15.Routes.channelRecipient(this.id, userId) + (options?.silent ? "?silent=true" : "");
|
|
2123
2213
|
await this.client.rest.delete(url, { auth: true });
|
|
2124
2214
|
const idx = this.recipients.findIndex((u) => u.id === userId);
|
|
2125
2215
|
if (idx >= 0) this.recipients.splice(idx, 1);
|
|
@@ -2127,17 +2217,17 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2127
2217
|
};
|
|
2128
2218
|
|
|
2129
2219
|
// src/structures/channel/factory.ts
|
|
2130
|
-
var
|
|
2220
|
+
var import_types16 = require("@fluxerjs/types");
|
|
2131
2221
|
var GUILD_FACTORIES = {
|
|
2132
|
-
[
|
|
2133
|
-
[
|
|
2134
|
-
[
|
|
2135
|
-
[
|
|
2222
|
+
[import_types16.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
|
|
2223
|
+
[import_types16.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
2224
|
+
[import_types16.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
2225
|
+
[import_types16.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
|
|
2136
2226
|
};
|
|
2137
2227
|
var DM_TYPES = /* @__PURE__ */ new Set([
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2228
|
+
import_types16.ChannelType.DM,
|
|
2229
|
+
import_types16.ChannelType.GroupDM,
|
|
2230
|
+
import_types16.ChannelType.DMPersonalNotes
|
|
2141
2231
|
]);
|
|
2142
2232
|
function createDM(client, data) {
|
|
2143
2233
|
return new DMChannel(client, data);
|
|
@@ -2157,8 +2247,8 @@ Channel.createDM = createDM;
|
|
|
2157
2247
|
|
|
2158
2248
|
// src/client/ChannelManager.ts
|
|
2159
2249
|
function rethrowNotFound(err, message, code) {
|
|
2160
|
-
if (err instanceof
|
|
2161
|
-
if (err instanceof
|
|
2250
|
+
if (err instanceof import_rest4.RateLimitError) throw err;
|
|
2251
|
+
if (err instanceof import_rest4.FluxerAPIError && err.statusCode === 404) {
|
|
2162
2252
|
throw new import_util.FluxerError(message, { code, cause: err });
|
|
2163
2253
|
}
|
|
2164
2254
|
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError(String(err), { cause: err });
|
|
@@ -2190,7 +2280,7 @@ var ChannelManager = class extends import_collection5.Collection {
|
|
|
2190
2280
|
const cached = this.get(channelId);
|
|
2191
2281
|
if (cached) return cached;
|
|
2192
2282
|
try {
|
|
2193
|
-
const data = await this.client.rest.get(
|
|
2283
|
+
const data = await this.client.rest.get(import_types17.Routes.channel(channelId));
|
|
2194
2284
|
const channel = Channel.fromOrCreate(this.client, data);
|
|
2195
2285
|
if (!channel) {
|
|
2196
2286
|
throw new import_util.FluxerError("Channel data invalid or unsupported type", {
|
|
@@ -2223,7 +2313,7 @@ var ChannelManager = class extends import_collection5.Collection {
|
|
|
2223
2313
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
2224
2314
|
});
|
|
2225
2315
|
const data = await this.client.rest.post(
|
|
2226
|
-
|
|
2316
|
+
import_types17.Routes.channelMessages(channelId),
|
|
2227
2317
|
postPayload
|
|
2228
2318
|
);
|
|
2229
2319
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -2233,29 +2323,29 @@ var ChannelManager = class extends import_collection5.Collection {
|
|
|
2233
2323
|
|
|
2234
2324
|
// src/client/GuildManager.ts
|
|
2235
2325
|
var import_collection9 = require("@fluxerjs/collection");
|
|
2236
|
-
var
|
|
2237
|
-
var
|
|
2326
|
+
var import_types37 = require("@fluxerjs/types");
|
|
2327
|
+
var import_rest6 = require("@fluxerjs/rest");
|
|
2238
2328
|
|
|
2239
2329
|
// src/structures/guild/Guild.ts
|
|
2240
2330
|
var import_collection8 = require("@fluxerjs/collection");
|
|
2241
|
-
var
|
|
2331
|
+
var import_types36 = require("@fluxerjs/types");
|
|
2242
2332
|
|
|
2243
2333
|
// src/client/GuildMemberManager.ts
|
|
2244
2334
|
var import_collection7 = require("@fluxerjs/collection");
|
|
2245
|
-
var
|
|
2335
|
+
var import_types21 = require("@fluxerjs/types");
|
|
2246
2336
|
|
|
2247
2337
|
// src/structures/GuildMember.ts
|
|
2248
|
-
var
|
|
2338
|
+
var import_types20 = require("@fluxerjs/types");
|
|
2249
2339
|
var import_util5 = require("@fluxerjs/util");
|
|
2250
2340
|
|
|
2251
2341
|
// src/util/permissions.ts
|
|
2252
|
-
var
|
|
2342
|
+
var import_types18 = require("@fluxerjs/types");
|
|
2253
2343
|
var import_util4 = require("@fluxerjs/util");
|
|
2254
2344
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
2255
2345
|
if (isOwner) return import_util4.ALL_PERMISSIONS_BIGINT;
|
|
2256
2346
|
let perms = basePermissions;
|
|
2257
2347
|
for (const overwrite of overwrites ?? []) {
|
|
2258
|
-
const applies = overwrite.type ===
|
|
2348
|
+
const applies = overwrite.type === import_types18.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types18.OverwriteType.Member && overwrite.id === memberId;
|
|
2259
2349
|
if (!applies) continue;
|
|
2260
2350
|
const allow = BigInt(overwrite.allow || "0");
|
|
2261
2351
|
const deny = BigInt(overwrite.deny || "0");
|
|
@@ -2266,7 +2356,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
2266
2356
|
|
|
2267
2357
|
// src/structures/GuildMemberRoleManager.ts
|
|
2268
2358
|
var import_collection6 = require("@fluxerjs/collection");
|
|
2269
|
-
var
|
|
2359
|
+
var import_types19 = require("@fluxerjs/types");
|
|
2270
2360
|
function roleId(roleOrId) {
|
|
2271
2361
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
2272
2362
|
}
|
|
@@ -2295,7 +2385,7 @@ var GuildMemberRoleManager = class {
|
|
|
2295
2385
|
const id = roleId(roleOrId);
|
|
2296
2386
|
if (this.ids.includes(id)) return;
|
|
2297
2387
|
await this.member.client.rest.put(
|
|
2298
|
-
|
|
2388
|
+
import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2299
2389
|
);
|
|
2300
2390
|
this.ids.push(id);
|
|
2301
2391
|
}
|
|
@@ -2304,13 +2394,13 @@ var GuildMemberRoleManager = class {
|
|
|
2304
2394
|
const idx = this.ids.indexOf(id);
|
|
2305
2395
|
if (idx === -1) return;
|
|
2306
2396
|
await this.member.client.rest.delete(
|
|
2307
|
-
|
|
2397
|
+
import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
2308
2398
|
);
|
|
2309
2399
|
this.ids.splice(idx, 1);
|
|
2310
2400
|
}
|
|
2311
2401
|
async set(roleIds) {
|
|
2312
2402
|
const data = await this.member.client.rest.patch(
|
|
2313
|
-
|
|
2403
|
+
import_types19.Routes.guildMember(this.member.guild.id, this.member.id),
|
|
2314
2404
|
{ body: { roles: roleIds }, auth: true }
|
|
2315
2405
|
);
|
|
2316
2406
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -2437,7 +2527,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
2437
2527
|
/** PATCH member (`/members/@me` when editing the bot). */
|
|
2438
2528
|
async edit(options) {
|
|
2439
2529
|
const isMe = this.client.user?.id === this.id;
|
|
2440
|
-
const route = isMe ?
|
|
2530
|
+
const route = isMe ? import_types20.Routes.guildMemberMe(this.guild.id) : import_types20.Routes.guildMember(this.guild.id, this.id);
|
|
2441
2531
|
const data = await this.client.rest.patch(route, {
|
|
2442
2532
|
body: toMemberEditBody(options),
|
|
2443
2533
|
auth: true
|
|
@@ -2566,7 +2656,7 @@ var GuildMemberManager = class extends import_collection7.Collection {
|
|
|
2566
2656
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
2567
2657
|
if (options?.after) params.set("after", options.after);
|
|
2568
2658
|
const qs2 = params.toString();
|
|
2569
|
-
const url =
|
|
2659
|
+
const url = import_types21.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
2570
2660
|
const data = await this.guild.client.rest.get(url, { auth: true });
|
|
2571
2661
|
const members = [];
|
|
2572
2662
|
for (const m of data) {
|
|
@@ -2589,7 +2679,7 @@ var GuildMemberManager = class extends import_collection7.Collection {
|
|
|
2589
2679
|
*/
|
|
2590
2680
|
async search(options = {}) {
|
|
2591
2681
|
const data = await this.guild.client.rest.post(
|
|
2592
|
-
|
|
2682
|
+
import_types21.Routes.guildMembersSearch(this.guild.id),
|
|
2593
2683
|
{ body: toMemberSearchBody(options), auth: true }
|
|
2594
2684
|
);
|
|
2595
2685
|
const offset = options.offset ?? 0;
|
|
@@ -2615,7 +2705,7 @@ var GuildMemberManager = class extends import_collection7.Collection {
|
|
|
2615
2705
|
};
|
|
2616
2706
|
|
|
2617
2707
|
// src/structures/Role.ts
|
|
2618
|
-
var
|
|
2708
|
+
var import_types22 = require("@fluxerjs/types");
|
|
2619
2709
|
var import_util7 = require("@fluxerjs/util");
|
|
2620
2710
|
|
|
2621
2711
|
// src/structures/roleOptions.ts
|
|
@@ -2728,7 +2818,7 @@ var Role = class _Role extends Base {
|
|
|
2728
2818
|
*/
|
|
2729
2819
|
async edit(options) {
|
|
2730
2820
|
const body = toRoleRequestBody(options);
|
|
2731
|
-
const data = await this.client.rest.patch(
|
|
2821
|
+
const data = await this.client.rest.patch(import_types22.Routes.guildRole(this.guildId, this.id), {
|
|
2732
2822
|
body: Object.keys(body).length ? body : void 0,
|
|
2733
2823
|
auth: true
|
|
2734
2824
|
});
|
|
@@ -2739,18 +2829,18 @@ var Role = class _Role extends Base {
|
|
|
2739
2829
|
* DELETE role. Requires Manage Roles.
|
|
2740
2830
|
*/
|
|
2741
2831
|
async delete() {
|
|
2742
|
-
await this.client.rest.delete(
|
|
2832
|
+
await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), { auth: true });
|
|
2743
2833
|
this.client.guilds.get(this.guildId)?.roles.delete(this.id);
|
|
2744
2834
|
}
|
|
2745
2835
|
};
|
|
2746
2836
|
|
|
2747
2837
|
// src/structures/guild/admin.ts
|
|
2748
|
-
var
|
|
2838
|
+
var import_types23 = require("@fluxerjs/types");
|
|
2749
2839
|
|
|
2750
2840
|
// src/structures/guild/http.ts
|
|
2751
|
-
var
|
|
2841
|
+
var import_rest5 = require("@fluxerjs/rest");
|
|
2752
2842
|
function httpStatus(err) {
|
|
2753
|
-
if (err instanceof
|
|
2843
|
+
if (err instanceof import_rest5.FluxerAPIError) return err.statusCode;
|
|
2754
2844
|
if (typeof err === "object" && err !== null && "statusCode" in err) {
|
|
2755
2845
|
const code = err.statusCode;
|
|
2756
2846
|
return typeof code === "number" ? code : void 0;
|
|
@@ -2850,7 +2940,7 @@ function toVanityPayload(data) {
|
|
|
2850
2940
|
return { code: data.code ?? null, uses: data.uses };
|
|
2851
2941
|
}
|
|
2852
2942
|
async function fetchAuditLogs(guild, options) {
|
|
2853
|
-
const url =
|
|
2943
|
+
const url = import_types23.Routes.guildAuditLogs(guild.id) + qs({
|
|
2854
2944
|
limit: options?.limit,
|
|
2855
2945
|
before: options?.before,
|
|
2856
2946
|
after: options?.after,
|
|
@@ -2871,7 +2961,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
2871
2961
|
};
|
|
2872
2962
|
}
|
|
2873
2963
|
async function editGuild(guild, options) {
|
|
2874
|
-
const data = await guild.client.rest.patch(
|
|
2964
|
+
const data = await guild.client.rest.patch(import_types23.Routes.guild(guild.id), {
|
|
2875
2965
|
body: toGuildEditBody(options),
|
|
2876
2966
|
auth: true
|
|
2877
2967
|
});
|
|
@@ -2879,13 +2969,13 @@ async function editGuild(guild, options) {
|
|
|
2879
2969
|
return guild;
|
|
2880
2970
|
}
|
|
2881
2971
|
async function fetchVanityURL(guild) {
|
|
2882
|
-
const data = await guild.client.rest.get(
|
|
2972
|
+
const data = await guild.client.rest.get(import_types23.Routes.guildVanityUrl(guild.id), {
|
|
2883
2973
|
auth: true
|
|
2884
2974
|
});
|
|
2885
2975
|
return toVanityPayload(data);
|
|
2886
2976
|
}
|
|
2887
2977
|
async function editVanityURL(guild, code) {
|
|
2888
|
-
const data = await guild.client.rest.patch(
|
|
2978
|
+
const data = await guild.client.rest.patch(import_types23.Routes.guildVanityUrl(guild.id), {
|
|
2889
2979
|
body: { code },
|
|
2890
2980
|
auth: true
|
|
2891
2981
|
});
|
|
@@ -2893,14 +2983,14 @@ async function editVanityURL(guild, code) {
|
|
|
2893
2983
|
return toVanityPayload(data);
|
|
2894
2984
|
}
|
|
2895
2985
|
async function fetchDiscoveryStatus(guild) {
|
|
2896
|
-
const data = await guild.client.rest.get(
|
|
2986
|
+
const data = await guild.client.rest.get(import_types23.Routes.guildDiscovery(guild.id), {
|
|
2897
2987
|
auth: true
|
|
2898
2988
|
});
|
|
2899
2989
|
return toDiscoveryStatusPayload(data);
|
|
2900
2990
|
}
|
|
2901
2991
|
async function applyForDiscovery(guild, options) {
|
|
2902
2992
|
const data = await guild.client.rest.post(
|
|
2903
|
-
|
|
2993
|
+
import_types23.Routes.guildDiscovery(guild.id),
|
|
2904
2994
|
{
|
|
2905
2995
|
body: toDiscoveryBody(options),
|
|
2906
2996
|
auth: true
|
|
@@ -2910,7 +3000,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
2910
3000
|
}
|
|
2911
3001
|
async function editDiscoveryApplication(guild, options) {
|
|
2912
3002
|
const data = await guild.client.rest.patch(
|
|
2913
|
-
|
|
3003
|
+
import_types23.Routes.guildDiscovery(guild.id),
|
|
2914
3004
|
{
|
|
2915
3005
|
body: toDiscoveryBody(options),
|
|
2916
3006
|
auth: true
|
|
@@ -2919,28 +3009,28 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
2919
3009
|
return toDiscoveryApplicationPayload(data);
|
|
2920
3010
|
}
|
|
2921
3011
|
async function withdrawDiscoveryApplication(guild) {
|
|
2922
|
-
await guild.client.rest.delete(
|
|
3012
|
+
await guild.client.rest.delete(import_types23.Routes.guildDiscovery(guild.id), { auth: true });
|
|
2923
3013
|
}
|
|
2924
3014
|
async function deleteGuild(guild, options) {
|
|
2925
3015
|
const body = options ? toSudoBody(options) : {};
|
|
2926
|
-
await guild.client.rest.post(
|
|
3016
|
+
await guild.client.rest.post(import_types23.Routes.guildDelete(guild.id), {
|
|
2927
3017
|
body,
|
|
2928
3018
|
auth: true
|
|
2929
3019
|
});
|
|
2930
3020
|
guild.client.guilds.delete(guild.id);
|
|
2931
3021
|
}
|
|
2932
3022
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
2933
|
-
await guild.client.rest.post(
|
|
3023
|
+
await guild.client.rest.post(import_types23.Routes.guildTransferOwnership(guild.id), {
|
|
2934
3024
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
2935
3025
|
auth: true
|
|
2936
3026
|
});
|
|
2937
3027
|
}
|
|
2938
3028
|
|
|
2939
3029
|
// src/structures/guild/channels.ts
|
|
2940
|
-
var
|
|
3030
|
+
var import_types27 = require("@fluxerjs/types");
|
|
2941
3031
|
|
|
2942
3032
|
// src/structures/GuildEmoji.ts
|
|
2943
|
-
var
|
|
3033
|
+
var import_types25 = require("@fluxerjs/types");
|
|
2944
3034
|
var GuildEmoji = class extends Base {
|
|
2945
3035
|
client;
|
|
2946
3036
|
id;
|
|
@@ -2968,7 +3058,7 @@ var GuildEmoji = class extends Base {
|
|
|
2968
3058
|
}
|
|
2969
3059
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
2970
3060
|
async delete() {
|
|
2971
|
-
await this.client.rest.delete(
|
|
3061
|
+
await this.client.rest.delete(import_types25.Routes.guildEmoji(this.guildId, this.id), {
|
|
2972
3062
|
auth: true
|
|
2973
3063
|
});
|
|
2974
3064
|
const guild = this.client.guilds.get(this.guildId);
|
|
@@ -2979,7 +3069,7 @@ var GuildEmoji = class extends Base {
|
|
|
2979
3069
|
* Requires Manage Emojis and Stickers permission.
|
|
2980
3070
|
*/
|
|
2981
3071
|
async edit(options) {
|
|
2982
|
-
const data = await this.client.rest.patch(
|
|
3072
|
+
const data = await this.client.rest.patch(import_types25.Routes.guildEmoji(this.guildId, this.id), {
|
|
2983
3073
|
body: options,
|
|
2984
3074
|
auth: true
|
|
2985
3075
|
});
|
|
@@ -2989,7 +3079,7 @@ var GuildEmoji = class extends Base {
|
|
|
2989
3079
|
};
|
|
2990
3080
|
|
|
2991
3081
|
// src/structures/GuildSticker.ts
|
|
2992
|
-
var
|
|
3082
|
+
var import_types26 = require("@fluxerjs/types");
|
|
2993
3083
|
var GuildSticker = class extends Base {
|
|
2994
3084
|
client;
|
|
2995
3085
|
id;
|
|
@@ -3020,7 +3110,7 @@ var GuildSticker = class extends Base {
|
|
|
3020
3110
|
}
|
|
3021
3111
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
3022
3112
|
async delete() {
|
|
3023
|
-
await this.client.rest.delete(
|
|
3113
|
+
await this.client.rest.delete(import_types26.Routes.guildSticker(this.guildId, this.id), {
|
|
3024
3114
|
auth: true
|
|
3025
3115
|
});
|
|
3026
3116
|
}
|
|
@@ -3029,7 +3119,7 @@ var GuildSticker = class extends Base {
|
|
|
3029
3119
|
* Requires Manage Emojis and Stickers permission.
|
|
3030
3120
|
*/
|
|
3031
3121
|
async edit(options) {
|
|
3032
|
-
const data = await this.client.rest.patch(
|
|
3122
|
+
const data = await this.client.rest.patch(import_types26.Routes.guildSticker(this.guildId, this.id), {
|
|
3033
3123
|
body: options,
|
|
3034
3124
|
auth: true
|
|
3035
3125
|
});
|
|
@@ -3084,14 +3174,14 @@ function cacheSticker(guild, data) {
|
|
|
3084
3174
|
|
|
3085
3175
|
// src/structures/guild/channels.ts
|
|
3086
3176
|
async function createChannel(guild, data) {
|
|
3087
|
-
const created = await guild.client.rest.post(
|
|
3177
|
+
const created = await guild.client.rest.post(import_types27.Routes.guildChannels(guild.id), {
|
|
3088
3178
|
body: data,
|
|
3089
3179
|
auth: true
|
|
3090
3180
|
});
|
|
3091
3181
|
return cacheChannel(guild, created);
|
|
3092
3182
|
}
|
|
3093
3183
|
async function fetchChannels(guild) {
|
|
3094
|
-
const data = await guild.client.rest.get(
|
|
3184
|
+
const data = await guild.client.rest.get(import_types27.Routes.guildChannels(guild.id));
|
|
3095
3185
|
const channels = [];
|
|
3096
3186
|
for (const ch of data) {
|
|
3097
3187
|
const channel = cacheChannel(guild, ch);
|
|
@@ -3100,17 +3190,17 @@ async function fetchChannels(guild) {
|
|
|
3100
3190
|
return channels;
|
|
3101
3191
|
}
|
|
3102
3192
|
async function setChannelPositions(guild, updates) {
|
|
3103
|
-
await guild.client.rest.patch(
|
|
3193
|
+
await guild.client.rest.patch(import_types27.Routes.guildChannels(guild.id), {
|
|
3104
3194
|
body: toChannelPositionBody(updates),
|
|
3105
3195
|
auth: true
|
|
3106
3196
|
});
|
|
3107
3197
|
}
|
|
3108
3198
|
async function fetchWebhooks(guild) {
|
|
3109
|
-
const data = await guild.client.rest.get(
|
|
3199
|
+
const data = await guild.client.rest.get(import_types27.Routes.guildWebhooks(guild.id));
|
|
3110
3200
|
return data.map((w) => new Webhook(guild.client, w));
|
|
3111
3201
|
}
|
|
3112
3202
|
async function fetchInvites(guild) {
|
|
3113
|
-
const data = await guild.client.rest.get(
|
|
3203
|
+
const data = await guild.client.rest.get(import_types27.Routes.guildInvites(guild.id));
|
|
3114
3204
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
3115
3205
|
}
|
|
3116
3206
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -3118,14 +3208,14 @@ async function fetchInvite(guild, codeOrUrl) {
|
|
|
3118
3208
|
}
|
|
3119
3209
|
|
|
3120
3210
|
// src/structures/guild/emojis.ts
|
|
3121
|
-
var
|
|
3211
|
+
var import_types29 = require("@fluxerjs/types");
|
|
3122
3212
|
async function fetchEmojis(guild) {
|
|
3123
|
-
const data = await guild.client.rest.get(
|
|
3213
|
+
const data = await guild.client.rest.get(import_types29.Routes.guildEmojis(guild.id));
|
|
3124
3214
|
return data.map((e) => cacheEmoji(guild, e));
|
|
3125
3215
|
}
|
|
3126
3216
|
async function fetchEmoji(guild, emojiId) {
|
|
3127
3217
|
try {
|
|
3128
|
-
const data = await guild.client.rest.get(
|
|
3218
|
+
const data = await guild.client.rest.get(import_types29.Routes.guildEmoji(guild.id, emojiId));
|
|
3129
3219
|
return cacheEmoji(guild, data);
|
|
3130
3220
|
} catch (err) {
|
|
3131
3221
|
rethrowNotFound2(
|
|
@@ -3136,14 +3226,14 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
3136
3226
|
}
|
|
3137
3227
|
}
|
|
3138
3228
|
async function createEmoji(guild, options) {
|
|
3139
|
-
const data = await guild.client.rest.post(
|
|
3229
|
+
const data = await guild.client.rest.post(import_types29.Routes.guildEmojis(guild.id), {
|
|
3140
3230
|
body: options,
|
|
3141
3231
|
auth: true
|
|
3142
3232
|
});
|
|
3143
3233
|
return cacheEmoji(guild, data);
|
|
3144
3234
|
}
|
|
3145
3235
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
3146
|
-
const data = await guild.client.rest.post(
|
|
3236
|
+
const data = await guild.client.rest.post(import_types29.Routes.guildEmojisClone(guild.id), {
|
|
3147
3237
|
body: { source_emoji_id: sourceEmojiId },
|
|
3148
3238
|
auth: true
|
|
3149
3239
|
});
|
|
@@ -3151,18 +3241,18 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
3151
3241
|
}
|
|
3152
3242
|
async function createEmojisBulk(guild, emojis) {
|
|
3153
3243
|
const data = await guild.client.rest.post(
|
|
3154
|
-
|
|
3244
|
+
import_types29.Routes.guildEmojisBulk(guild.id),
|
|
3155
3245
|
{ body: { emojis }, auth: true }
|
|
3156
3246
|
);
|
|
3157
3247
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
3158
3248
|
}
|
|
3159
3249
|
|
|
3160
3250
|
// src/structures/guild/members.ts
|
|
3161
|
-
var
|
|
3251
|
+
var import_types30 = require("@fluxerjs/types");
|
|
3162
3252
|
async function fetchMember(guild, userId) {
|
|
3163
3253
|
try {
|
|
3164
3254
|
const data = await guild.client.rest.get(
|
|
3165
|
-
|
|
3255
|
+
import_types30.Routes.guildMember(guild.id, userId)
|
|
3166
3256
|
);
|
|
3167
3257
|
return cacheMember(guild, data);
|
|
3168
3258
|
} catch (err) {
|
|
@@ -3175,17 +3265,17 @@ async function fetchMember(guild, userId) {
|
|
|
3175
3265
|
}
|
|
3176
3266
|
async function fetchMe(guild) {
|
|
3177
3267
|
const data = await guild.client.rest.get(
|
|
3178
|
-
|
|
3268
|
+
import_types30.Routes.guildMemberMe(guild.id),
|
|
3179
3269
|
{ auth: true }
|
|
3180
3270
|
);
|
|
3181
3271
|
return cacheMember(guild, data);
|
|
3182
3272
|
}
|
|
3183
3273
|
|
|
3184
3274
|
// src/structures/guild/moderation.ts
|
|
3185
|
-
var
|
|
3275
|
+
var import_types32 = require("@fluxerjs/types");
|
|
3186
3276
|
|
|
3187
3277
|
// src/structures/GuildBan.ts
|
|
3188
|
-
var
|
|
3278
|
+
var import_types31 = require("@fluxerjs/types");
|
|
3189
3279
|
var GuildBan = class extends Base {
|
|
3190
3280
|
client;
|
|
3191
3281
|
guildId;
|
|
@@ -3207,7 +3297,7 @@ var GuildBan = class extends Base {
|
|
|
3207
3297
|
* Requires Ban Members permission.
|
|
3208
3298
|
*/
|
|
3209
3299
|
async unban() {
|
|
3210
|
-
await this.client.rest.delete(
|
|
3300
|
+
await this.client.rest.delete(import_types31.Routes.guildBan(this.guildId, this.user.id), {
|
|
3211
3301
|
auth: true
|
|
3212
3302
|
});
|
|
3213
3303
|
}
|
|
@@ -3216,40 +3306,40 @@ var GuildBan = class extends Base {
|
|
|
3216
3306
|
// src/structures/guild/moderation.ts
|
|
3217
3307
|
async function ban(guild, userId, options) {
|
|
3218
3308
|
const body = options ? toGuildBanBody(options) : {};
|
|
3219
|
-
await guild.client.rest.put(
|
|
3309
|
+
await guild.client.rest.put(import_types32.Routes.guildBan(guild.id, userId), {
|
|
3220
3310
|
body: Object.keys(body).length ? body : void 0,
|
|
3221
3311
|
auth: true
|
|
3222
3312
|
});
|
|
3223
3313
|
}
|
|
3224
3314
|
async function fetchBans(guild) {
|
|
3225
|
-
const data = await guild.client.rest.get(
|
|
3315
|
+
const data = await guild.client.rest.get(import_types32.Routes.guildBans(guild.id));
|
|
3226
3316
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
3227
3317
|
}
|
|
3228
3318
|
async function unban(guild, userId) {
|
|
3229
|
-
await guild.client.rest.delete(
|
|
3319
|
+
await guild.client.rest.delete(import_types32.Routes.guildBan(guild.id, userId), { auth: true });
|
|
3230
3320
|
}
|
|
3231
3321
|
async function kick(guild, userId) {
|
|
3232
|
-
await guild.client.rest.delete(
|
|
3322
|
+
await guild.client.rest.delete(import_types32.Routes.guildMember(guild.id, userId), { auth: true });
|
|
3233
3323
|
}
|
|
3234
3324
|
|
|
3235
3325
|
// src/structures/guild/roles.ts
|
|
3236
|
-
var
|
|
3326
|
+
var import_types34 = require("@fluxerjs/types");
|
|
3237
3327
|
var import_util8 = require("@fluxerjs/util");
|
|
3238
3328
|
async function createRole(guild, options = {}) {
|
|
3239
3329
|
const body = toRoleRequestBody(options);
|
|
3240
|
-
const data = await guild.client.rest.post(
|
|
3330
|
+
const data = await guild.client.rest.post(import_types34.Routes.guildRoles(guild.id), {
|
|
3241
3331
|
body: Object.keys(body).length ? body : void 0,
|
|
3242
3332
|
auth: true
|
|
3243
3333
|
});
|
|
3244
3334
|
return cacheRole(guild, data);
|
|
3245
3335
|
}
|
|
3246
3336
|
async function fetchRoles(guild) {
|
|
3247
|
-
const data = await guild.client.rest.get(
|
|
3337
|
+
const data = await guild.client.rest.get(import_types34.Routes.guildRoles(guild.id));
|
|
3248
3338
|
return data.map((r) => cacheRole(guild, r));
|
|
3249
3339
|
}
|
|
3250
3340
|
async function fetchRole(guild, roleId2) {
|
|
3251
3341
|
try {
|
|
3252
|
-
const data = await guild.client.rest.get(
|
|
3342
|
+
const data = await guild.client.rest.get(import_types34.Routes.guildRole(guild.id, roleId2));
|
|
3253
3343
|
return cacheRole(guild, data);
|
|
3254
3344
|
} catch (err) {
|
|
3255
3345
|
rethrowNotFound2(
|
|
@@ -3267,7 +3357,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3267
3357
|
const needle = trimmed.toLowerCase();
|
|
3268
3358
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3269
3359
|
if (cached) return cached.id;
|
|
3270
|
-
const roles = await guild.client.rest.get(
|
|
3360
|
+
const roles = await guild.client.rest.get(import_types34.Routes.guildRoles(guild.id));
|
|
3271
3361
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
3272
3362
|
if (!role) return null;
|
|
3273
3363
|
cacheRole(guild, role);
|
|
@@ -3276,7 +3366,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
3276
3366
|
async function setRolePositions(guild, updates) {
|
|
3277
3367
|
return replaceRoles(
|
|
3278
3368
|
guild,
|
|
3279
|
-
await guild.client.rest.patch(
|
|
3369
|
+
await guild.client.rest.patch(import_types34.Routes.guildRoles(guild.id), {
|
|
3280
3370
|
body: updates,
|
|
3281
3371
|
auth: true
|
|
3282
3372
|
})
|
|
@@ -3285,7 +3375,7 @@ async function setRolePositions(guild, updates) {
|
|
|
3285
3375
|
async function setRoleHoistPositions(guild, updates) {
|
|
3286
3376
|
return replaceRoles(
|
|
3287
3377
|
guild,
|
|
3288
|
-
await guild.client.rest.patch(
|
|
3378
|
+
await guild.client.rest.patch(import_types34.Routes.guildRolesHoistPositions(guild.id), {
|
|
3289
3379
|
body: updates.map((u) => ({
|
|
3290
3380
|
id: u.id,
|
|
3291
3381
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -3297,23 +3387,23 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
3297
3387
|
async function resetRoleHoistPositions(guild) {
|
|
3298
3388
|
return replaceRoles(
|
|
3299
3389
|
guild,
|
|
3300
|
-
await guild.client.rest.delete(
|
|
3390
|
+
await guild.client.rest.delete(import_types34.Routes.guildRolesHoistPositions(guild.id), {
|
|
3301
3391
|
auth: true
|
|
3302
3392
|
})
|
|
3303
3393
|
);
|
|
3304
3394
|
}
|
|
3305
3395
|
|
|
3306
3396
|
// src/structures/guild/stickers.ts
|
|
3307
|
-
var
|
|
3397
|
+
var import_types35 = require("@fluxerjs/types");
|
|
3308
3398
|
async function createSticker(guild, options) {
|
|
3309
|
-
const data = await guild.client.rest.post(
|
|
3399
|
+
const data = await guild.client.rest.post(import_types35.Routes.guildStickers(guild.id), {
|
|
3310
3400
|
body: options,
|
|
3311
3401
|
auth: true
|
|
3312
3402
|
});
|
|
3313
3403
|
return cacheSticker(guild, data);
|
|
3314
3404
|
}
|
|
3315
3405
|
async function cloneSticker(guild, sourceStickerId) {
|
|
3316
|
-
const data = await guild.client.rest.post(
|
|
3406
|
+
const data = await guild.client.rest.post(import_types35.Routes.guildStickersClone(guild.id), {
|
|
3317
3407
|
body: { source_sticker_id: sourceStickerId },
|
|
3318
3408
|
auth: true
|
|
3319
3409
|
});
|
|
@@ -3321,17 +3411,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
3321
3411
|
}
|
|
3322
3412
|
async function createStickersBulk(guild, stickers) {
|
|
3323
3413
|
const data = await guild.client.rest.post(
|
|
3324
|
-
|
|
3414
|
+
import_types35.Routes.guildStickersBulk(guild.id),
|
|
3325
3415
|
{ body: { stickers }, auth: true }
|
|
3326
3416
|
);
|
|
3327
3417
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
3328
3418
|
}
|
|
3329
3419
|
async function fetchStickers(guild) {
|
|
3330
|
-
const data = await guild.client.rest.get(
|
|
3420
|
+
const data = await guild.client.rest.get(import_types35.Routes.guildStickers(guild.id));
|
|
3331
3421
|
return data.map((s) => cacheSticker(guild, s));
|
|
3332
3422
|
}
|
|
3333
3423
|
async function fetchSticker(guild, stickerId) {
|
|
3334
|
-
const data = await guild.client.rest.get(
|
|
3424
|
+
const data = await guild.client.rest.get(import_types35.Routes.guildSticker(guild.id, stickerId));
|
|
3335
3425
|
return cacheSticker(guild, data);
|
|
3336
3426
|
}
|
|
3337
3427
|
|
|
@@ -3416,7 +3506,7 @@ var Guild = class extends Base {
|
|
|
3416
3506
|
this.afkTimeout = data.afk_timeout ?? 0;
|
|
3417
3507
|
this.systemChannelId = data.system_channel_id ?? null;
|
|
3418
3508
|
this.rulesChannelId = data.rules_channel_id ?? null;
|
|
3419
|
-
this.nsfwLevel = data.nsfw_level ??
|
|
3509
|
+
this.nsfwLevel = data.nsfw_level ?? import_types36.GuildNSFWLevel.Safe;
|
|
3420
3510
|
this.mfaLevel = data.mfa_level ?? 0;
|
|
3421
3511
|
this.bannerWidth = data.banner_width ?? null;
|
|
3422
3512
|
this.bannerHeight = data.banner_height ?? null;
|
|
@@ -3449,7 +3539,7 @@ var Guild = class extends Base {
|
|
|
3449
3539
|
if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
|
|
3450
3540
|
if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
|
|
3451
3541
|
if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
|
|
3452
|
-
if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ??
|
|
3542
|
+
if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types36.GuildNSFWLevel.Safe;
|
|
3453
3543
|
if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
|
|
3454
3544
|
if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
|
|
3455
3545
|
if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
|
|
@@ -3678,13 +3768,13 @@ var GuildManager = class extends import_collection9.Collection {
|
|
|
3678
3768
|
const cached = this.get(guildId);
|
|
3679
3769
|
if (cached) return cached;
|
|
3680
3770
|
try {
|
|
3681
|
-
const data = await this.client.rest.get(
|
|
3771
|
+
const data = await this.client.rest.get(import_types37.Routes.guild(guildId));
|
|
3682
3772
|
const guild = new Guild(this.client, data);
|
|
3683
3773
|
this.set(guild.id, guild);
|
|
3684
3774
|
return guild;
|
|
3685
3775
|
} catch (err) {
|
|
3686
|
-
if (err instanceof
|
|
3687
|
-
if (err instanceof
|
|
3776
|
+
if (err instanceof import_rest6.RateLimitError) throw err;
|
|
3777
|
+
if (err instanceof import_rest6.FluxerAPIError && err.statusCode === 404) {
|
|
3688
3778
|
throw new import_util.FluxerError(`Guild ${guildId} not found`, {
|
|
3689
3779
|
code: import_util2.ErrorCodes.GuildNotFound,
|
|
3690
3780
|
cause: err
|
|
@@ -3705,7 +3795,7 @@ var DEFAULT_CACHE_LIMITS = {
|
|
|
3705
3795
|
};
|
|
3706
3796
|
|
|
3707
3797
|
// src/structures/User.ts
|
|
3708
|
-
var
|
|
3798
|
+
var import_types38 = require("@fluxerjs/types");
|
|
3709
3799
|
var User = class extends Base {
|
|
3710
3800
|
/** Parent client instance. */
|
|
3711
3801
|
client;
|
|
@@ -3795,7 +3885,7 @@ var User = class extends Base {
|
|
|
3795
3885
|
* @returns DM channel instance (cached if already open)
|
|
3796
3886
|
*/
|
|
3797
3887
|
async createDM() {
|
|
3798
|
-
const data = await this.client.rest.post(
|
|
3888
|
+
const data = await this.client.rest.post(import_types38.Routes.userMeChannels(), {
|
|
3799
3889
|
body: { recipient_id: this.id },
|
|
3800
3890
|
auth: true
|
|
3801
3891
|
});
|
|
@@ -3815,7 +3905,7 @@ var User = class extends Base {
|
|
|
3815
3905
|
|
|
3816
3906
|
// src/client/UserManager.ts
|
|
3817
3907
|
var import_collection10 = require("@fluxerjs/collection");
|
|
3818
|
-
var
|
|
3908
|
+
var import_types39 = require("@fluxerjs/types");
|
|
3819
3909
|
var soft = (p) => p.catch(() => null);
|
|
3820
3910
|
var UserManager = class extends import_collection10.Collection {
|
|
3821
3911
|
constructor(client) {
|
|
@@ -3846,7 +3936,7 @@ var UserManager = class extends import_collection10.Collection {
|
|
|
3846
3936
|
}
|
|
3847
3937
|
/** Fetch a user by ID and update cache. */
|
|
3848
3938
|
async fetch(userId) {
|
|
3849
|
-
const data = await this.client.rest.get(
|
|
3939
|
+
const data = await this.client.rest.get(import_types39.Routes.user(userId));
|
|
3850
3940
|
return this.client.getOrCreateUser(data);
|
|
3851
3941
|
}
|
|
3852
3942
|
/**
|
|
@@ -3860,10 +3950,10 @@ var UserManager = class extends import_collection10.Collection {
|
|
|
3860
3950
|
async fetchWithProfile(userId, options) {
|
|
3861
3951
|
const guildId = options?.guildId ?? void 0;
|
|
3862
3952
|
const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
|
|
3863
|
-
this.client.rest.get(
|
|
3864
|
-
soft(this.client.rest.get(
|
|
3865
|
-
guildId ? soft(this.client.rest.get(
|
|
3866
|
-
guildId ? soft(this.client.rest.get(
|
|
3953
|
+
this.client.rest.get(import_types39.Routes.user(userId)),
|
|
3954
|
+
soft(this.client.rest.get(import_types39.Routes.userProfile(userId))),
|
|
3955
|
+
guildId ? soft(this.client.rest.get(import_types39.Routes.userProfile(userId, guildId))) : null,
|
|
3956
|
+
guildId ? soft(this.client.rest.get(import_types39.Routes.guildMember(guildId, userId))) : null
|
|
3867
3957
|
]);
|
|
3868
3958
|
const user = this.client.getOrCreateUser(userData);
|
|
3869
3959
|
let member = null;
|
|
@@ -3892,7 +3982,7 @@ var UserManager = class extends import_collection10.Collection {
|
|
|
3892
3982
|
};
|
|
3893
3983
|
|
|
3894
3984
|
// src/client/PackManager.ts
|
|
3895
|
-
var
|
|
3985
|
+
var import_types40 = require("@fluxerjs/types");
|
|
3896
3986
|
function toPackSummaryPayload(data) {
|
|
3897
3987
|
return {
|
|
3898
3988
|
id: data.id,
|
|
@@ -3947,7 +4037,7 @@ var PackManager = class {
|
|
|
3947
4037
|
}
|
|
3948
4038
|
/** Fetch the current user's pack dashboard (camelCase summaries). */
|
|
3949
4039
|
async fetchDashboard() {
|
|
3950
|
-
const data = await this.client.rest.get(
|
|
4040
|
+
const data = await this.client.rest.get(import_types40.Routes.packs());
|
|
3951
4041
|
return {
|
|
3952
4042
|
emoji: mapDashboardSection(data.emoji),
|
|
3953
4043
|
sticker: mapDashboardSection(data.sticker)
|
|
@@ -3955,49 +4045,49 @@ var PackManager = class {
|
|
|
3955
4045
|
}
|
|
3956
4046
|
/** Create a pack. */
|
|
3957
4047
|
async create(packType, body) {
|
|
3958
|
-
const data = await this.client.rest.post(
|
|
4048
|
+
const data = await this.client.rest.post(import_types40.Routes.packsByType(packType), {
|
|
3959
4049
|
body
|
|
3960
4050
|
});
|
|
3961
4051
|
return toPackSummaryPayload(data);
|
|
3962
4052
|
}
|
|
3963
4053
|
/** Edit a pack. */
|
|
3964
4054
|
async edit(packId, body) {
|
|
3965
|
-
const data = await this.client.rest.patch(
|
|
4055
|
+
const data = await this.client.rest.patch(import_types40.Routes.pack(packId), { body });
|
|
3966
4056
|
return toPackSummaryPayload(data);
|
|
3967
4057
|
}
|
|
3968
4058
|
/** Delete a pack. */
|
|
3969
4059
|
async delete(packId) {
|
|
3970
|
-
await this.client.rest.delete(
|
|
4060
|
+
await this.client.rest.delete(import_types40.Routes.pack(packId));
|
|
3971
4061
|
}
|
|
3972
4062
|
/** Install a pack for the current user. */
|
|
3973
4063
|
async install(packId) {
|
|
3974
|
-
await this.client.rest.post(
|
|
4064
|
+
await this.client.rest.post(import_types40.Routes.packInstall(packId));
|
|
3975
4065
|
}
|
|
3976
4066
|
/** Uninstall a pack for the current user. */
|
|
3977
4067
|
async uninstall(packId) {
|
|
3978
|
-
await this.client.rest.delete(
|
|
4068
|
+
await this.client.rest.delete(import_types40.Routes.packInstall(packId));
|
|
3979
4069
|
}
|
|
3980
4070
|
/** List invites for a pack. */
|
|
3981
4071
|
async listInvites(packId) {
|
|
3982
|
-
const data = await this.client.rest.get(
|
|
4072
|
+
const data = await this.client.rest.get(import_types40.Routes.packInvites(packId));
|
|
3983
4073
|
return data.map(toInvitePayload);
|
|
3984
4074
|
}
|
|
3985
4075
|
/** Create an invite for a pack. */
|
|
3986
4076
|
async createInvite(packId, options = {}) {
|
|
3987
4077
|
const body = toPackInviteBody(options);
|
|
3988
|
-
const data = await this.client.rest.post(
|
|
4078
|
+
const data = await this.client.rest.post(import_types40.Routes.packInvites(packId), {
|
|
3989
4079
|
body: Object.keys(body).length ? body : void 0
|
|
3990
4080
|
});
|
|
3991
4081
|
return toInvitePayload(data);
|
|
3992
4082
|
}
|
|
3993
4083
|
/** List emojis in a pack. */
|
|
3994
4084
|
async listEmojis(packId) {
|
|
3995
|
-
const data = await this.client.rest.get(
|
|
4085
|
+
const data = await this.client.rest.get(import_types40.Routes.packEmojis(packId));
|
|
3996
4086
|
return data.map(toEmojiPayload);
|
|
3997
4087
|
}
|
|
3998
4088
|
/** Create an emoji in a pack. */
|
|
3999
4089
|
async createEmoji(packId, options) {
|
|
4000
|
-
const data = await this.client.rest.post(
|
|
4090
|
+
const data = await this.client.rest.post(import_types40.Routes.packEmojis(packId), {
|
|
4001
4091
|
body: toEmojiCreateBody(options)
|
|
4002
4092
|
});
|
|
4003
4093
|
return toEmojiPayload(data);
|
|
@@ -4005,7 +4095,7 @@ var PackManager = class {
|
|
|
4005
4095
|
/** Bulk-create emojis in a pack. */
|
|
4006
4096
|
async createEmojisBulk(packId, emojis) {
|
|
4007
4097
|
const data = await this.client.rest.post(
|
|
4008
|
-
|
|
4098
|
+
import_types40.Routes.packEmojisBulk(packId),
|
|
4009
4099
|
{ body: { emojis: emojis.map(toEmojiCreateBody) } }
|
|
4010
4100
|
);
|
|
4011
4101
|
return {
|
|
@@ -4015,23 +4105,23 @@ var PackManager = class {
|
|
|
4015
4105
|
}
|
|
4016
4106
|
/** Edit an emoji in a pack. */
|
|
4017
4107
|
async editEmoji(packId, emojiId, options) {
|
|
4018
|
-
const data = await this.client.rest.patch(
|
|
4108
|
+
const data = await this.client.rest.patch(import_types40.Routes.packEmoji(packId, emojiId), {
|
|
4019
4109
|
body: toEmojiEditBody(options)
|
|
4020
4110
|
});
|
|
4021
4111
|
return toEmojiPayload(data);
|
|
4022
4112
|
}
|
|
4023
4113
|
/** Delete an emoji from a pack. */
|
|
4024
4114
|
async deleteEmoji(packId, emojiId) {
|
|
4025
|
-
await this.client.rest.delete(
|
|
4115
|
+
await this.client.rest.delete(import_types40.Routes.packEmoji(packId, emojiId));
|
|
4026
4116
|
}
|
|
4027
4117
|
/** List stickers in a pack. */
|
|
4028
4118
|
async listStickers(packId) {
|
|
4029
|
-
const data = await this.client.rest.get(
|
|
4119
|
+
const data = await this.client.rest.get(import_types40.Routes.packStickers(packId));
|
|
4030
4120
|
return data.map(toStickerPayload);
|
|
4031
4121
|
}
|
|
4032
4122
|
/** Create a sticker in a pack. */
|
|
4033
4123
|
async createSticker(packId, options) {
|
|
4034
|
-
const data = await this.client.rest.post(
|
|
4124
|
+
const data = await this.client.rest.post(import_types40.Routes.packStickers(packId), {
|
|
4035
4125
|
body: toStickerCreateBody(options)
|
|
4036
4126
|
});
|
|
4037
4127
|
return toStickerPayload(data);
|
|
@@ -4039,7 +4129,7 @@ var PackManager = class {
|
|
|
4039
4129
|
/** Bulk-create stickers in a pack. */
|
|
4040
4130
|
async createStickersBulk(packId, stickers) {
|
|
4041
4131
|
const data = await this.client.rest.post(
|
|
4042
|
-
|
|
4132
|
+
import_types40.Routes.packStickersBulk(packId),
|
|
4043
4133
|
{ body: { stickers: stickers.map(toStickerCreateBody) } }
|
|
4044
4134
|
);
|
|
4045
4135
|
return {
|
|
@@ -4049,14 +4139,14 @@ var PackManager = class {
|
|
|
4049
4139
|
}
|
|
4050
4140
|
/** Edit a sticker in a pack. */
|
|
4051
4141
|
async editSticker(packId, stickerId, options) {
|
|
4052
|
-
const data = await this.client.rest.patch(
|
|
4142
|
+
const data = await this.client.rest.patch(import_types40.Routes.packSticker(packId, stickerId), {
|
|
4053
4143
|
body: toStickerEditBody(options)
|
|
4054
4144
|
});
|
|
4055
4145
|
return toStickerPayload(data);
|
|
4056
4146
|
}
|
|
4057
4147
|
/** Delete a sticker from a pack. */
|
|
4058
4148
|
async deleteSticker(packId, stickerId) {
|
|
4059
|
-
await this.client.rest.delete(
|
|
4149
|
+
await this.client.rest.delete(import_types40.Routes.packSticker(packId, stickerId));
|
|
4060
4150
|
}
|
|
4061
4151
|
};
|
|
4062
4152
|
|
|
@@ -4075,19 +4165,10 @@ function createEventMethods(client) {
|
|
|
4075
4165
|
|
|
4076
4166
|
// src/client/clientEmoji.ts
|
|
4077
4167
|
var import_collection11 = require("@fluxerjs/collection");
|
|
4078
|
-
var
|
|
4168
|
+
var import_types41 = require("@fluxerjs/types");
|
|
4079
4169
|
var import_util9 = require("@fluxerjs/util");
|
|
4080
|
-
async function assertEmojiInGuild(client, emojiId, guildId) {
|
|
4081
|
-
const emojis = await client.rest.get(import_types40.Routes.guildEmojis(guildId));
|
|
4082
|
-
if (!emojis.some((e) => e.id === emojiId)) {
|
|
4083
|
-
throw new import_util.FluxerError("Custom emoji is from another server. Use an emoji from this server.", {
|
|
4084
|
-
code: import_util2.ErrorCodes.EmojiNotInGuild
|
|
4085
|
-
});
|
|
4086
|
-
}
|
|
4087
|
-
}
|
|
4088
4170
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
4089
4171
|
if (typeof emoji === "object" && emoji.id) {
|
|
4090
|
-
if (guildId) await assertEmojiInGuild(client, emoji.id, guildId);
|
|
4091
4172
|
return (0, import_util9.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
|
|
4092
4173
|
}
|
|
4093
4174
|
const parsed = (0, import_util9.parseEmoji)(
|
|
@@ -4097,14 +4178,13 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4097
4178
|
throw new import_util.FluxerError("Invalid emoji", { code: import_util2.ErrorCodes.InvalidEmoji });
|
|
4098
4179
|
}
|
|
4099
4180
|
if (parsed.id) {
|
|
4100
|
-
if (guildId) await assertEmojiInGuild(client, parsed.id, guildId);
|
|
4101
4181
|
return (0, import_util9.formatEmoji)(parsed);
|
|
4102
4182
|
}
|
|
4103
4183
|
if (!/^\w+$/.test(parsed.name)) return parsed.name;
|
|
4104
4184
|
const unicodeFromShortcode = (0, import_util9.getUnicodeFromShortcode)(parsed.name);
|
|
4105
4185
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
4106
4186
|
if (guildId) {
|
|
4107
|
-
const emojis = await client.rest.get(
|
|
4187
|
+
const emojis = await client.rest.get(import_types41.Routes.guildEmojis(guildId));
|
|
4108
4188
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
4109
4189
|
if (found) return (0, import_util9.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
|
|
4110
4190
|
throw new import_util.FluxerError(
|
|
@@ -4121,28 +4201,28 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4121
4201
|
return parsed.name;
|
|
4122
4202
|
}
|
|
4123
4203
|
async function fetchInstance(client) {
|
|
4124
|
-
const raw = await client.rest.get(
|
|
4204
|
+
const raw = await client.rest.get(import_types41.Routes.instanceDiscovery(), { auth: false });
|
|
4125
4205
|
return parseInstanceDiscovery(raw);
|
|
4126
4206
|
}
|
|
4127
4207
|
function fetchGatewayInfo(client) {
|
|
4128
|
-
return client.rest.get(
|
|
4208
|
+
return client.rest.get(import_types41.Routes.gatewayBot());
|
|
4129
4209
|
}
|
|
4130
4210
|
function fetchEmojiMetadata(client, emojiId) {
|
|
4131
|
-
return client.rest.get(
|
|
4211
|
+
return client.rest.get(import_types41.Routes.emojiMetadata(emojiId), { auth: true });
|
|
4132
4212
|
}
|
|
4133
4213
|
function fetchStickerMetadata(client, stickerId) {
|
|
4134
|
-
return client.rest.get(
|
|
4214
|
+
return client.rest.get(import_types41.Routes.stickerMetadata(stickerId), { auth: true });
|
|
4135
4215
|
}
|
|
4136
4216
|
function fetchApplication(client) {
|
|
4137
|
-
return client.rest.get(
|
|
4217
|
+
return client.rest.get(import_types41.Routes.applicationsMe(), { auth: true });
|
|
4138
4218
|
}
|
|
4139
4219
|
async function fetchOAuthApplications(client) {
|
|
4140
|
-
const data = await client.rest.get(
|
|
4220
|
+
const data = await client.rest.get(import_types41.Routes.oauth2ApplicationsMe(), { auth: true });
|
|
4141
4221
|
return Array.isArray(data) ? data : data.applications ?? [];
|
|
4142
4222
|
}
|
|
4143
4223
|
function checkUsernameTag(client, username, discriminator) {
|
|
4144
4224
|
const params = new URLSearchParams({ username, discriminator });
|
|
4145
|
-
return client.rest.get(`${
|
|
4225
|
+
return client.rest.get(`${import_types41.Routes.checkUsernameTag()}?${params}`, { auth: true });
|
|
4146
4226
|
}
|
|
4147
4227
|
function assertChannelIdBatch(name, channelIds) {
|
|
4148
4228
|
if (channelIds.length < 1 || channelIds.length > 100) {
|
|
@@ -4153,14 +4233,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
4153
4233
|
}
|
|
4154
4234
|
function preloadMessages(client, channelIds) {
|
|
4155
4235
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
4156
|
-
return client.rest.post(
|
|
4236
|
+
return client.rest.post(import_types41.Routes.preloadMessages(), {
|
|
4157
4237
|
body: { channels: channelIds },
|
|
4158
4238
|
auth: true
|
|
4159
4239
|
});
|
|
4160
4240
|
}
|
|
4161
4241
|
function preloadMessagesAlt(client, channelIds) {
|
|
4162
4242
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
4163
|
-
return client.rest.post(
|
|
4243
|
+
return client.rest.post(import_types41.Routes.preloadMessagesAlt(), {
|
|
4164
4244
|
body: { channels: channelIds },
|
|
4165
4245
|
auth: true
|
|
4166
4246
|
});
|
|
@@ -4168,7 +4248,7 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
4168
4248
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
4169
4249
|
validateBulkMessageFetchRequests(requests);
|
|
4170
4250
|
const wire = toBulkFetchWire(requests);
|
|
4171
|
-
const data = await client.rest.post(
|
|
4251
|
+
const data = await client.rest.post(import_types41.Routes.channelsMessagesBulk(), {
|
|
4172
4252
|
body: { requests: wire },
|
|
4173
4253
|
auth: true
|
|
4174
4254
|
});
|
|
@@ -4255,62 +4335,6 @@ function buildRegistry(...maps) {
|
|
|
4255
4335
|
return registry;
|
|
4256
4336
|
}
|
|
4257
4337
|
|
|
4258
|
-
// src/structures/MessageReaction.ts
|
|
4259
|
-
var import_types41 = require("@fluxerjs/types");
|
|
4260
|
-
var import_rest6 = require("@fluxerjs/rest");
|
|
4261
|
-
var MessageReaction = class extends Base {
|
|
4262
|
-
client;
|
|
4263
|
-
messageId;
|
|
4264
|
-
channelId;
|
|
4265
|
-
guildId;
|
|
4266
|
-
emoji;
|
|
4267
|
-
/** Raw gateway payload for low-level access. */
|
|
4268
|
-
_data;
|
|
4269
|
-
constructor(client, data) {
|
|
4270
|
-
super();
|
|
4271
|
-
this.client = client;
|
|
4272
|
-
this._data = data;
|
|
4273
|
-
this.messageId = data.message_id;
|
|
4274
|
-
this.channelId = data.channel_id;
|
|
4275
|
-
this.guildId = data.guild_id ?? null;
|
|
4276
|
-
this.emoji = {
|
|
4277
|
-
name: data.emoji.name,
|
|
4278
|
-
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
4279
|
-
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
4280
|
-
};
|
|
4281
|
-
}
|
|
4282
|
-
/** Emoji as a string: unicode or "name:id" for custom. */
|
|
4283
|
-
get emojiIdentifier() {
|
|
4284
|
-
return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
4285
|
-
}
|
|
4286
|
-
/** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
|
|
4287
|
-
get guild() {
|
|
4288
|
-
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
4289
|
-
}
|
|
4290
|
-
/**
|
|
4291
|
-
* Fetch the message this reaction belongs to.
|
|
4292
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
4293
|
-
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
4294
|
-
*/
|
|
4295
|
-
async fetchMessage() {
|
|
4296
|
-
try {
|
|
4297
|
-
const data = await this.client.rest.get(
|
|
4298
|
-
import_types41.Routes.channelMessage(this.channelId, this.messageId)
|
|
4299
|
-
);
|
|
4300
|
-
return new Message(this.client, data);
|
|
4301
|
-
} catch (err) {
|
|
4302
|
-
if (err instanceof import_rest6.RateLimitError) throw err;
|
|
4303
|
-
if (err instanceof import_rest6.FluxerAPIError && err.statusCode === 404) {
|
|
4304
|
-
throw new import_util.FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
4305
|
-
code: import_util2.ErrorCodes.MessageNotFound,
|
|
4306
|
-
cause: err
|
|
4307
|
-
});
|
|
4308
|
-
}
|
|
4309
|
-
throw err instanceof import_util.FluxerError ? err : new import_util.FluxerError(String(err), { cause: err });
|
|
4310
|
-
}
|
|
4311
|
-
}
|
|
4312
|
-
};
|
|
4313
|
-
|
|
4314
4338
|
// src/client/eventHandlers/helpers.ts
|
|
4315
4339
|
function unknownUser(id) {
|
|
4316
4340
|
return { id, username: "Unknown", discriminator: "0" };
|
|
@@ -4348,7 +4372,9 @@ function emitReaction(event) {
|
|
|
4348
4372
|
return (client, d) => {
|
|
4349
4373
|
const data = d;
|
|
4350
4374
|
const reaction = new MessageReaction(client, data);
|
|
4351
|
-
const
|
|
4375
|
+
const guild = data.guild_id ? client.guilds.get(data.guild_id) : void 0;
|
|
4376
|
+
const member = guild && data.member ? cacheMember2(client, guild, { ...data.member, guild_id: data.guild_id }) : null;
|
|
4377
|
+
const user = member?.user ?? client.users.get(data.user_id) ?? client.getOrCreateUser(unknownUser(data.user_id));
|
|
4352
4378
|
const payload = {
|
|
4353
4379
|
reaction,
|
|
4354
4380
|
user,
|
|
@@ -4458,14 +4484,15 @@ var messageHandlers = {
|
|
|
4458
4484
|
};
|
|
4459
4485
|
|
|
4460
4486
|
// src/util/guildUtils.ts
|
|
4461
|
-
function
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
if ("
|
|
4466
|
-
if ("
|
|
4467
|
-
if ("
|
|
4468
|
-
if ("
|
|
4487
|
+
function isRecord2(value) {
|
|
4488
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4489
|
+
}
|
|
4490
|
+
function isValidGuildPayload(o) {
|
|
4491
|
+
if (!Object.hasOwn(o, "id") || typeof o.id !== "string" || o.id.length === 0) return false;
|
|
4492
|
+
if ("name" in o && typeof o.name !== "string") return false;
|
|
4493
|
+
if ("owner_id" in o && typeof o.owner_id !== "string") return false;
|
|
4494
|
+
if ("features" in o && !Array.isArray(o.features)) return false;
|
|
4495
|
+
if ("afk_timeout" in o && typeof o.afk_timeout !== "number") return false;
|
|
4469
4496
|
for (const key of [
|
|
4470
4497
|
"verification_level",
|
|
4471
4498
|
"mfa_level",
|
|
@@ -4473,10 +4500,32 @@ function normalizeGuildPayload(raw) {
|
|
|
4473
4500
|
"explicit_content_filter",
|
|
4474
4501
|
"default_message_notifications"
|
|
4475
4502
|
]) {
|
|
4476
|
-
if (key in o && typeof o[key] !== "number") return
|
|
4503
|
+
if (key in o && typeof o[key] !== "number") return false;
|
|
4477
4504
|
}
|
|
4478
|
-
if ("icon" in o && o.icon !== null && typeof o.icon !== "string") return
|
|
4479
|
-
if ("banner" in o && o.banner !== null && typeof o.banner !== "string") return
|
|
4505
|
+
if ("icon" in o && o.icon !== null && typeof o.icon !== "string") return false;
|
|
4506
|
+
if ("banner" in o && o.banner !== null && typeof o.banner !== "string") return false;
|
|
4507
|
+
return true;
|
|
4508
|
+
}
|
|
4509
|
+
function isHydratableGuildPayload(o) {
|
|
4510
|
+
return isValidGuildPayload(o) && Object.hasOwn(o, "name") && typeof o.name === "string" && Object.hasOwn(o, "owner_id") && typeof o.owner_id === "string";
|
|
4511
|
+
}
|
|
4512
|
+
function normalizeGuildSnapshotPayload(raw) {
|
|
4513
|
+
if (!isRecord2(raw)) return null;
|
|
4514
|
+
const flatPayload = isHydratableGuildPayload(raw) && (raw.roles === void 0 || Array.isArray(raw.roles)) ? raw : null;
|
|
4515
|
+
let nestedPayload = null;
|
|
4516
|
+
if (Object.hasOwn(raw, "properties") && isRecord2(raw.properties)) {
|
|
4517
|
+
const properties = raw.properties;
|
|
4518
|
+
const rolesValid = raw.roles === void 0 || Array.isArray(raw.roles);
|
|
4519
|
+
if (rolesValid && isHydratableGuildPayload(properties) && raw.id === properties.id) {
|
|
4520
|
+
nestedPayload = { ...properties };
|
|
4521
|
+
if (raw.roles !== void 0) nestedPayload.roles = raw.roles;
|
|
4522
|
+
}
|
|
4523
|
+
}
|
|
4524
|
+
if (flatPayload === null === (nestedPayload === null)) return null;
|
|
4525
|
+
return flatPayload ?? nestedPayload;
|
|
4526
|
+
}
|
|
4527
|
+
function normalizeGuildUpdatePayload(raw) {
|
|
4528
|
+
if (!isRecord2(raw) || !isValidGuildPayload(raw)) return null;
|
|
4480
4529
|
return raw;
|
|
4481
4530
|
}
|
|
4482
4531
|
|
|
@@ -4488,7 +4537,6 @@ function markGuildUnavailable(client, id) {
|
|
|
4488
4537
|
client.emit(Events.GuildUnavailable, guild);
|
|
4489
4538
|
}
|
|
4490
4539
|
function refreshRecoveredGuild(guild, data) {
|
|
4491
|
-
guild._patch(data);
|
|
4492
4540
|
if (data.roles !== void 0) {
|
|
4493
4541
|
guild.roles.clear();
|
|
4494
4542
|
for (const role of data.roles) {
|
|
@@ -4517,13 +4565,16 @@ var guildHandlers = {
|
|
|
4517
4565
|
}
|
|
4518
4566
|
return;
|
|
4519
4567
|
}
|
|
4520
|
-
const guildData =
|
|
4568
|
+
const guildData = normalizeGuildSnapshotPayload(d);
|
|
4521
4569
|
if (!guildData) return;
|
|
4522
4570
|
const g = d;
|
|
4523
4571
|
const existing = client.guilds.get(guildData.id);
|
|
4524
4572
|
const recovered = existing?.available === false;
|
|
4525
4573
|
const guild = recovered && existing ? existing : new Guild(client, guildData);
|
|
4526
|
-
if (recovered)
|
|
4574
|
+
if (recovered) {
|
|
4575
|
+
guild._patch(guildData);
|
|
4576
|
+
refreshRecoveredGuild(guild, g);
|
|
4577
|
+
}
|
|
4527
4578
|
client.guilds.set(guild.id, guild);
|
|
4528
4579
|
for (const ch of g.channels ?? []) {
|
|
4529
4580
|
const channel = Channel.from(client, ch);
|
|
@@ -4541,7 +4592,7 @@ var guildHandlers = {
|
|
|
4541
4592
|
client._onGuildReceived(guild.id);
|
|
4542
4593
|
},
|
|
4543
4594
|
GUILD_UPDATE(client, d) {
|
|
4544
|
-
const guildData =
|
|
4595
|
+
const guildData = normalizeGuildUpdatePayload(d);
|
|
4545
4596
|
if (!guildData) return;
|
|
4546
4597
|
const existing = client.guilds.get(guildData.id);
|
|
4547
4598
|
if (existing) {
|
|
@@ -5085,22 +5136,21 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
|
|
|
5085
5136
|
if (pending !== null && g.id) pending.add(g.id);
|
|
5086
5137
|
continue;
|
|
5087
5138
|
}
|
|
5088
|
-
const guildData =
|
|
5139
|
+
const guildData = normalizeGuildSnapshotPayload(g);
|
|
5089
5140
|
if (!guildData) continue;
|
|
5090
5141
|
const guild = new Guild(client, guildData);
|
|
5091
5142
|
client.guilds.set(guild.id, guild);
|
|
5092
|
-
const
|
|
5093
|
-
for (const ch of withCh.channels ?? []) {
|
|
5143
|
+
for (const ch of g.channels ?? []) {
|
|
5094
5144
|
const channel = Channel.from(client, ch);
|
|
5095
5145
|
if (channel) {
|
|
5096
5146
|
client.channels.set(channel.id, channel);
|
|
5097
5147
|
guild.channels.set(channel.id, channel);
|
|
5098
5148
|
}
|
|
5099
5149
|
}
|
|
5100
|
-
if (
|
|
5150
|
+
if (g.voice_states?.length) {
|
|
5101
5151
|
client.emit(Events.VoiceStatesSync, {
|
|
5102
5152
|
guildId: guild.id,
|
|
5103
|
-
voiceStates:
|
|
5153
|
+
voiceStates: g.voice_states
|
|
5104
5154
|
});
|
|
5105
5155
|
}
|
|
5106
5156
|
}
|
|
@@ -5216,11 +5266,11 @@ var Client = class _Client extends import_events3.EventEmitter {
|
|
|
5216
5266
|
*/
|
|
5217
5267
|
instance;
|
|
5218
5268
|
/** Guild cache and manager. */
|
|
5219
|
-
guilds
|
|
5269
|
+
guilds;
|
|
5220
5270
|
/** Channel cache and manager. */
|
|
5221
|
-
channels
|
|
5271
|
+
channels;
|
|
5222
5272
|
/** User cache and manager. */
|
|
5223
|
-
users
|
|
5273
|
+
users;
|
|
5224
5274
|
/** Emoji/sticker pack REST wrappers (`/packs/*`). */
|
|
5225
5275
|
packs = new PackManager(this);
|
|
5226
5276
|
/** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
|
|
@@ -5247,6 +5297,9 @@ var Client = class _Client extends import_events3.EventEmitter {
|
|
|
5247
5297
|
cache: { ...DEFAULT_CACHE_LIMITS, ...options.cache },
|
|
5248
5298
|
defaultReplyPing: options.defaultReplyPing ?? true
|
|
5249
5299
|
};
|
|
5300
|
+
this.guilds = new GuildManager(this);
|
|
5301
|
+
this.channels = new ChannelManager(this);
|
|
5302
|
+
this.users = new UserManager(this);
|
|
5250
5303
|
const restApi = options.rest?.api;
|
|
5251
5304
|
if (options.instance !== void 0) {
|
|
5252
5305
|
this.instance = resolveInstanceEndpoints(options.instance);
|