@fluxerjs/core 3.1.0 → 3.3.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/{SubpathMessage-DaimQAd9.d.ts → SubpathMessage-CNJlnR6y.d.mts} +2391 -2134
- package/dist/{SubpathMessage-Cj_U0V19.d.mts → SubpathMessage-DjLo6il5.d.ts} +2391 -2134
- package/dist/Sudo-mzPLv6YU.d.mts +802 -0
- package/dist/Sudo-mzPLv6YU.d.ts +802 -0
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2378 -1407
- package/dist/client.mjs +2346 -1369
- package/dist/cluster.d.mts +2 -2
- package/dist/cluster.d.ts +2 -2
- package/dist/cluster.js +2378 -1407
- package/dist/cluster.mjs +2346 -1369
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1227 -230
- package/dist/index.mjs +1129 -134
- package/dist/internal.d.mts +3 -2
- package/dist/internal.d.ts +3 -2
- package/dist/internal.js +53 -0
- package/dist/internal.mjs +55 -0
- package/dist/message.d.mts +2 -2
- package/dist/message.d.ts +2 -2
- package/dist/message.js +717 -34
- package/dist/message.mjs +708 -23
- package/package.json +4 -4
- package/dist/Sudo-fOKSPbxN.d.mts +0 -461
- package/dist/Sudo-fOKSPbxN.d.ts +0 -461
package/dist/message.js
CHANGED
|
@@ -27,9 +27,9 @@ module.exports = __toCommonJS(SubpathMessage_exports);
|
|
|
27
27
|
|
|
28
28
|
// src/Domain/Message/Message.ts
|
|
29
29
|
var import_builders3 = require("@fluxerjs/builders");
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
30
|
+
var import_collection5 = require("@fluxerjs/collection");
|
|
31
|
+
var import_types9 = require("@fluxerjs/types");
|
|
32
|
+
var import_util5 = require("@fluxerjs/util");
|
|
33
33
|
|
|
34
34
|
// src/ClientCore/SdkOptions/Attachments.ts
|
|
35
35
|
function toMessageAttachmentEditWire(attachments) {
|
|
@@ -45,6 +45,77 @@ function toMessageAttachmentEditWire(attachments) {
|
|
|
45
45
|
return out;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
+
function toAttachmentUploadPlanBody(attachments) {
|
|
49
|
+
return {
|
|
50
|
+
attachments: attachments.map((a) => ({
|
|
51
|
+
id: a.id,
|
|
52
|
+
filename: a.filename,
|
|
53
|
+
file_size: a.fileSize,
|
|
54
|
+
content_type: a.contentType
|
|
55
|
+
}))
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function toAttachmentUploadCompleteBody(uploads) {
|
|
59
|
+
return {
|
|
60
|
+
uploads: uploads.map((u) => ({
|
|
61
|
+
upload_filename: u.uploadFilename,
|
|
62
|
+
upload_id: u.uploadId
|
|
63
|
+
}))
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function toAttachmentUploadPlanResponse(data) {
|
|
67
|
+
return {
|
|
68
|
+
attachments: data.attachments.map((item) => {
|
|
69
|
+
const base = {
|
|
70
|
+
id: item.id,
|
|
71
|
+
filename: item.filename,
|
|
72
|
+
uploadFilename: item.upload_filename,
|
|
73
|
+
fileSize: item.file_size,
|
|
74
|
+
contentType: item.content_type
|
|
75
|
+
};
|
|
76
|
+
if (item.upload_mode === "multipart") {
|
|
77
|
+
const parts = (item.parts ?? []).map((p) => ({
|
|
78
|
+
partNumber: p.part_number,
|
|
79
|
+
uploadUrl: p.upload_url
|
|
80
|
+
}));
|
|
81
|
+
return {
|
|
82
|
+
...base,
|
|
83
|
+
uploadMode: "multipart",
|
|
84
|
+
uploadId: item.upload_id ?? "",
|
|
85
|
+
partSize: item.part_size ?? 0,
|
|
86
|
+
parts
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...base,
|
|
91
|
+
uploadMode: "singlepart",
|
|
92
|
+
uploadUrl: item.upload_url ?? ""
|
|
93
|
+
};
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/ClientCore/SdkOptions/Threads.ts
|
|
99
|
+
var import_types = require("@fluxerjs/types");
|
|
100
|
+
function toStartThreadFromMessageBody(options) {
|
|
101
|
+
const body = { name: options.name };
|
|
102
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
103
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
104
|
+
}
|
|
105
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
106
|
+
return body;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/ClientCore/SdkOptions/Sudo.ts
|
|
110
|
+
function toSudoBody(options) {
|
|
111
|
+
const body = {};
|
|
112
|
+
if (options.password !== void 0) body.password = options.password;
|
|
113
|
+
if (options.mfaMethod !== void 0) body.mfa_method = options.mfaMethod;
|
|
114
|
+
if (options.mfaCode !== void 0) body.mfa_code = options.mfaCode;
|
|
115
|
+
if (options.webauthnResponse !== void 0) body.webauthn_response = options.webauthnResponse;
|
|
116
|
+
if (options.webauthnChallenge !== void 0) body.webauthn_challenge = options.webauthnChallenge;
|
|
117
|
+
return body;
|
|
118
|
+
}
|
|
48
119
|
|
|
49
120
|
// src/Helpers/AuditReason.ts
|
|
50
121
|
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
@@ -55,7 +126,7 @@ function auditReasonHeaders(reason) {
|
|
|
55
126
|
|
|
56
127
|
// src/Helpers/MessageUtils/Body.ts
|
|
57
128
|
var import_builders = require("@fluxerjs/builders");
|
|
58
|
-
var
|
|
129
|
+
var import_types2 = require("@fluxerjs/types");
|
|
59
130
|
|
|
60
131
|
// src/LibErrors/ErrorCodes.ts
|
|
61
132
|
var import_util = require("@fluxerjs/util");
|
|
@@ -138,7 +209,7 @@ function normalizeSendFiles(files) {
|
|
|
138
209
|
id: i,
|
|
139
210
|
filename: file.filename,
|
|
140
211
|
...file.description != null ? { description: file.description } : {},
|
|
141
|
-
...file.spoiler ? { flags:
|
|
212
|
+
...file.spoiler ? { flags: import_types2.MessageAttachmentFlags.IS_SPOILER } : {}
|
|
142
213
|
};
|
|
143
214
|
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
144
215
|
metaFromBuilders.push(meta);
|
|
@@ -188,8 +259,8 @@ function toMessageReference(target, forceForward = false) {
|
|
|
188
259
|
message_id: target.messageId
|
|
189
260
|
};
|
|
190
261
|
if (target.guildId) ref.guild_id = target.guildId;
|
|
191
|
-
const type = forceForward ?
|
|
192
|
-
if (type !==
|
|
262
|
+
const type = forceForward ? import_types2.MessageReferenceType.Forward : target.type ?? import_types2.MessageReferenceType.Default;
|
|
263
|
+
if (type !== import_types2.MessageReferenceType.Default) ref.type = type;
|
|
193
264
|
if (target.attachmentIds?.length) ref.attachment_ids = target.attachmentIds;
|
|
194
265
|
if (target.embedIndices?.length) ref.embed_indices = target.embedIndices;
|
|
195
266
|
return ref;
|
|
@@ -278,7 +349,7 @@ var import_node_events = require("events");
|
|
|
278
349
|
var import_collection = require("@fluxerjs/collection");
|
|
279
350
|
|
|
280
351
|
// src/Domain/Message/MessageReaction.ts
|
|
281
|
-
var
|
|
352
|
+
var import_types3 = require("@fluxerjs/types");
|
|
282
353
|
|
|
283
354
|
// src/Helpers/HttpErrors.ts
|
|
284
355
|
var import_rest = require("@fluxerjs/rest");
|
|
@@ -387,7 +458,7 @@ var MessageReaction = class _MessageReaction extends Base {
|
|
|
387
458
|
if (cached) return cached;
|
|
388
459
|
try {
|
|
389
460
|
const data = await this.client.rest.get(
|
|
390
|
-
|
|
461
|
+
import_types3.Routes.channelMessage(this.channelId, this.messageId)
|
|
391
462
|
);
|
|
392
463
|
return new Message(this.client, data);
|
|
393
464
|
} catch (err) {
|
|
@@ -436,6 +507,14 @@ var Events = {
|
|
|
436
507
|
ChannelCreate: "channelCreate",
|
|
437
508
|
ChannelUpdate: "channelUpdate",
|
|
438
509
|
ChannelDelete: "channelDelete",
|
|
510
|
+
ThreadCreate: "threadCreate",
|
|
511
|
+
ThreadUpdate: "threadUpdate",
|
|
512
|
+
ThreadDelete: "threadDelete",
|
|
513
|
+
ThreadListSync: "threadListSync",
|
|
514
|
+
ThreadMemberUpdate: "threadMemberUpdate",
|
|
515
|
+
ThreadMembersUpdate: "threadMembersUpdate",
|
|
516
|
+
ThreadMemberListUpdate: "threadMemberListUpdate",
|
|
517
|
+
ForumUnreads: "forumUnreads",
|
|
439
518
|
ChannelPinsUpdate: "channelPinsUpdate",
|
|
440
519
|
ChannelRecipientAdd: "channelRecipientAdd",
|
|
441
520
|
ChannelRecipientRemove: "channelRecipientRemove",
|
|
@@ -573,6 +652,589 @@ var ReactionCollector = class _ReactionCollector extends import_node_events.Even
|
|
|
573
652
|
}
|
|
574
653
|
};
|
|
575
654
|
|
|
655
|
+
// src/Domain/Channel/Base.ts
|
|
656
|
+
var import_types6 = require("@fluxerjs/types");
|
|
657
|
+
var import_util3 = require("@fluxerjs/util");
|
|
658
|
+
|
|
659
|
+
// src/ClientCore/MessageManager.ts
|
|
660
|
+
var import_collection2 = require("@fluxerjs/collection");
|
|
661
|
+
var import_types4 = require("@fluxerjs/types");
|
|
662
|
+
var MessageManager = class {
|
|
663
|
+
constructor(client, channelId) {
|
|
664
|
+
this.client = client;
|
|
665
|
+
this.channelId = channelId;
|
|
666
|
+
}
|
|
667
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
668
|
+
_structures = new import_collection2.Collection();
|
|
669
|
+
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
670
|
+
get(messageId) {
|
|
671
|
+
const data = this.client._getMessageCache(this.channelId)?.get(messageId);
|
|
672
|
+
if (!data) {
|
|
673
|
+
this._structures.delete(messageId);
|
|
674
|
+
return void 0;
|
|
675
|
+
}
|
|
676
|
+
const existing = this._structures.get(messageId);
|
|
677
|
+
if (existing) return existing;
|
|
678
|
+
const message = new Message(this.client, data);
|
|
679
|
+
this._structures.set(messageId, message);
|
|
680
|
+
return message;
|
|
681
|
+
}
|
|
682
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
683
|
+
async resolve(messageId) {
|
|
684
|
+
return this.get(messageId) ?? this.fetch(messageId);
|
|
685
|
+
}
|
|
686
|
+
async fetch(idOrOptions) {
|
|
687
|
+
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
688
|
+
}
|
|
689
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
690
|
+
wrap(data) {
|
|
691
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
692
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
693
|
+
const existing = this._structures.get(data.id);
|
|
694
|
+
if (existing) {
|
|
695
|
+
existing._patch(cached);
|
|
696
|
+
return existing;
|
|
697
|
+
}
|
|
698
|
+
const message = new Message(this.client, cached);
|
|
699
|
+
this._structures.set(data.id, message);
|
|
700
|
+
return message;
|
|
701
|
+
}
|
|
702
|
+
/** Fetch a single message from the API. */
|
|
703
|
+
async fetchOne(messageId) {
|
|
704
|
+
try {
|
|
705
|
+
const data = await this.client.rest.get(
|
|
706
|
+
import_types4.Routes.channelMessage(this.channelId, messageId)
|
|
707
|
+
);
|
|
708
|
+
return this.wrap(data);
|
|
709
|
+
} catch (err) {
|
|
710
|
+
rethrowMapped(err, {
|
|
711
|
+
notFound: {
|
|
712
|
+
code: import_util.ErrorCodes.MessageNotFound,
|
|
713
|
+
message: `Message ${messageId} not found in channel ${this.channelId}`
|
|
714
|
+
},
|
|
715
|
+
fallback: `Failed to fetch message ${messageId}`
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
/** Fetch multiple messages from the API with pagination/filtering. */
|
|
720
|
+
async fetchMany(options) {
|
|
721
|
+
if (options.limit != null && (options.limit < 1 || options.limit > 100)) {
|
|
722
|
+
throw new import_util2.FluxerError("limit must be between 1 and 100", {
|
|
723
|
+
code: import_util.ErrorCodes.InvalidFetchLimit
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
const qs = new URLSearchParams();
|
|
727
|
+
for (const key of ["limit", "before", "after", "around"]) {
|
|
728
|
+
const value = options[key];
|
|
729
|
+
if (value != null && value !== "") qs.set(key, String(value));
|
|
730
|
+
}
|
|
731
|
+
const base = import_types4.Routes.channelMessages(this.channelId);
|
|
732
|
+
const data = await this.client.rest.get(qs.size > 0 ? `${base}?${qs}` : base);
|
|
733
|
+
const collection = new import_collection2.Collection();
|
|
734
|
+
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
735
|
+
return collection;
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
// src/Helpers/MessageCollector.ts
|
|
740
|
+
var import_node_events2 = require("events");
|
|
741
|
+
var import_collection3 = require("@fluxerjs/collection");
|
|
742
|
+
function requireCollectorBounds(options) {
|
|
743
|
+
const time = options.time ?? 0;
|
|
744
|
+
const max = options.max ?? 0;
|
|
745
|
+
if (time <= 0 && max <= 0) {
|
|
746
|
+
throw new import_util2.FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
747
|
+
code: import_util.ErrorCodes.CollectorOptionsRequired
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
var MessageCollector = class _MessageCollector extends import_node_events2.EventEmitter {
|
|
752
|
+
client;
|
|
753
|
+
channelId;
|
|
754
|
+
options;
|
|
755
|
+
collected = new import_collection3.Collection();
|
|
756
|
+
_timeout = null;
|
|
757
|
+
_ended = false;
|
|
758
|
+
_listener;
|
|
759
|
+
constructor(client, channelId, options = {}) {
|
|
760
|
+
super();
|
|
761
|
+
requireCollectorBounds(options);
|
|
762
|
+
this.client = client;
|
|
763
|
+
this.channelId = channelId;
|
|
764
|
+
this.options = {
|
|
765
|
+
filter: options.filter ?? (() => true),
|
|
766
|
+
time: options.time ?? 0,
|
|
767
|
+
max: options.max ?? 0
|
|
768
|
+
};
|
|
769
|
+
this._listener = (message) => {
|
|
770
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
771
|
+
if (!this.options.filter(message)) return;
|
|
772
|
+
this.collected.set(message.id, message);
|
|
773
|
+
this.emit("collect", message);
|
|
774
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
775
|
+
this.stop("limit");
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
779
|
+
if (this.options.time > 0) {
|
|
780
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
stop(reason = "user") {
|
|
784
|
+
if (this._ended) return;
|
|
785
|
+
this._ended = true;
|
|
786
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
787
|
+
if (this._timeout) {
|
|
788
|
+
clearTimeout(this._timeout);
|
|
789
|
+
this._timeout = null;
|
|
790
|
+
}
|
|
791
|
+
this.emit("end", this.collected, reason);
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
795
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
796
|
+
* the end reason is not listed in `errors`).
|
|
797
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
798
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
799
|
+
*/
|
|
800
|
+
static awaitMessages(client, channelId, options) {
|
|
801
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
802
|
+
return new Promise((resolve, reject) => {
|
|
803
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
804
|
+
collector.on("end", (collected, reason) => {
|
|
805
|
+
if (!errors.includes(reason)) {
|
|
806
|
+
resolve(collected);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
if (reason === "time") {
|
|
810
|
+
reject(
|
|
811
|
+
new import_util2.FluxerError("Message collector timed out", {
|
|
812
|
+
code: import_util.ErrorCodes.CollectorIdle
|
|
813
|
+
})
|
|
814
|
+
);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (reason === "limit") {
|
|
818
|
+
reject(
|
|
819
|
+
new import_util2.FluxerError("Message collector reached max", {
|
|
820
|
+
code: import_util.ErrorCodes.CollectorMax
|
|
821
|
+
})
|
|
822
|
+
);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
reject(collected);
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
on(event, listener) {
|
|
830
|
+
return super.on(event, listener);
|
|
831
|
+
}
|
|
832
|
+
emit(event, ...args) {
|
|
833
|
+
return super.emit(event, ...args);
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
// src/Domain/Channel/Attachments.ts
|
|
838
|
+
var import_types5 = require("@fluxerjs/types");
|
|
839
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
840
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
841
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
842
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
843
|
+
if (!rules?.length) return null;
|
|
844
|
+
const snapshot = {};
|
|
845
|
+
for (const rule of rules) {
|
|
846
|
+
Object.assign(snapshot, rule.overrides);
|
|
847
|
+
}
|
|
848
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
849
|
+
}
|
|
850
|
+
function assertBotAttachmentLimits(client, files) {
|
|
851
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
852
|
+
for (const file of files) {
|
|
853
|
+
const size = file.data.byteLength;
|
|
854
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
855
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
856
|
+
throw new import_util2.FluxerError(
|
|
857
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
858
|
+
{ code: import_util.ErrorCodes.AttachmentTooLarge }
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function asBytes(data) {
|
|
863
|
+
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
864
|
+
const out = new Uint8Array(src.byteLength);
|
|
865
|
+
out.set(src);
|
|
866
|
+
return out;
|
|
867
|
+
}
|
|
868
|
+
async function putBlob(url, body, contentType) {
|
|
869
|
+
const res = await fetch(url, {
|
|
870
|
+
method: "PUT",
|
|
871
|
+
headers: contentType ? { "Content-Type": contentType } : void 0,
|
|
872
|
+
body
|
|
873
|
+
});
|
|
874
|
+
if (!res.ok) {
|
|
875
|
+
throw new import_util2.FluxerError(`Presigned upload failed: ${res.status}`, {
|
|
876
|
+
code: import_util.ErrorCodes.AttachmentUploadFailed
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
881
|
+
assertBotAttachmentLimits(client, files);
|
|
882
|
+
const plan = await client.rest.post(
|
|
883
|
+
import_types5.Routes.channelAttachments(channelId),
|
|
884
|
+
{
|
|
885
|
+
body: {
|
|
886
|
+
attachments: files.map((f) => ({
|
|
887
|
+
id: f.id,
|
|
888
|
+
filename: f.filename,
|
|
889
|
+
file_size: f.data.byteLength,
|
|
890
|
+
content_type: f.contentType
|
|
891
|
+
}))
|
|
892
|
+
},
|
|
893
|
+
auth: true
|
|
894
|
+
}
|
|
895
|
+
);
|
|
896
|
+
const multipart = [];
|
|
897
|
+
const uploaded = [];
|
|
898
|
+
for (const item of plan.attachments) {
|
|
899
|
+
const file = files.find((f) => f.id === item.id);
|
|
900
|
+
if (!file) {
|
|
901
|
+
throw new import_util2.FluxerError(`No file data for planned attachment id ${item.id}`, {
|
|
902
|
+
code: import_util.ErrorCodes.InvalidAttachmentInput
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
const bytes = asBytes(file.data);
|
|
906
|
+
if (item.upload_mode === "singlepart") {
|
|
907
|
+
await putBlob(
|
|
908
|
+
item.upload_url,
|
|
909
|
+
new Blob([bytes], { type: file.contentType }),
|
|
910
|
+
item.content_type
|
|
911
|
+
);
|
|
912
|
+
} else {
|
|
913
|
+
for (const part of item.parts) {
|
|
914
|
+
const start = (part.part_number - 1) * item.part_size;
|
|
915
|
+
const chunk = bytes.subarray(start, Math.min(start + item.part_size, bytes.byteLength));
|
|
916
|
+
await putBlob(part.upload_url, new Blob([asBytes(chunk)]));
|
|
917
|
+
}
|
|
918
|
+
multipart.push({ upload_filename: item.upload_filename, upload_id: item.upload_id });
|
|
919
|
+
}
|
|
920
|
+
uploaded.push({
|
|
921
|
+
id: item.id,
|
|
922
|
+
filename: item.filename,
|
|
923
|
+
upload_filename: item.upload_filename,
|
|
924
|
+
file_size: item.file_size,
|
|
925
|
+
content_type: item.content_type
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
if (multipart.length) {
|
|
929
|
+
await client.rest.post(import_types5.Routes.channelAttachmentsComplete(channelId), {
|
|
930
|
+
body: { uploads: multipart },
|
|
931
|
+
auth: true
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
return uploaded;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// src/Domain/Channel/Base.ts
|
|
938
|
+
var Channel = class extends Base {
|
|
939
|
+
#messages;
|
|
940
|
+
/** The {@link Client} that instantiated this channel. */
|
|
941
|
+
client;
|
|
942
|
+
/** Snowflake ID of this channel. */
|
|
943
|
+
id;
|
|
944
|
+
/** Channel type (text, voice, category, etc.). */
|
|
945
|
+
type;
|
|
946
|
+
/** Channel name (null for some channel types). */
|
|
947
|
+
name;
|
|
948
|
+
/** Channel icon hash (null for most channel types). */
|
|
949
|
+
icon;
|
|
950
|
+
/** ISO8601 timestamp of the last pinned message update. */
|
|
951
|
+
lastPinTimestamp;
|
|
952
|
+
constructor(client, data) {
|
|
953
|
+
super();
|
|
954
|
+
this.client = client;
|
|
955
|
+
this.id = data.id;
|
|
956
|
+
this.type = data.type;
|
|
957
|
+
this.name = data.name ?? null;
|
|
958
|
+
this.icon = data.icon ?? null;
|
|
959
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
960
|
+
}
|
|
961
|
+
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
962
|
+
get createdTimestamp() {
|
|
963
|
+
return import_util3.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
964
|
+
}
|
|
965
|
+
/** Date when this channel was created, derived from its snowflake ID. */
|
|
966
|
+
get createdAt() {
|
|
967
|
+
return import_util3.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
971
|
+
* @internal
|
|
972
|
+
*/
|
|
973
|
+
_patch(data) {
|
|
974
|
+
if (data.type !== void 0) this.type = data.type;
|
|
975
|
+
if (data.name !== void 0) this.name = data.name ?? null;
|
|
976
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
977
|
+
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
978
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
/** @internal Factory wired after subclasses load. */
|
|
982
|
+
static from(_c, _d) {
|
|
983
|
+
throw new Error("Channel.from not initialized");
|
|
984
|
+
}
|
|
985
|
+
/** @internal Factory wired after subclasses load. */
|
|
986
|
+
static fromOrCreate(_c, _d) {
|
|
987
|
+
throw new Error("Channel.fromOrCreate not initialized");
|
|
988
|
+
}
|
|
989
|
+
/** @internal Factory wired after subclasses load. */
|
|
990
|
+
static createDM(_c, _d) {
|
|
991
|
+
throw new Error("Channel.createDM not initialized");
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
|
|
995
|
+
* Forum and media channels contain threads and do not accept `send`.
|
|
996
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
997
|
+
*/
|
|
998
|
+
isTextBased() {
|
|
999
|
+
return this.type === import_types6.ChannelType.GuildText || this.type === import_types6.ChannelType.GuildAnnouncement || this.type === import_types6.ChannelType.GuildVoice || this.type === import_types6.ChannelType.DM || this.type === import_types6.ChannelType.GroupDM || this.type === import_types6.ChannelType.DMPersonalNotes || this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread;
|
|
1000
|
+
}
|
|
1001
|
+
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
1002
|
+
isGuild() {
|
|
1003
|
+
return this.type === import_types6.ChannelType.GuildText || this.type === import_types6.ChannelType.GuildAnnouncement || this.type === import_types6.ChannelType.GuildVoice || this.type === import_types6.ChannelType.GuildCategory || this.type === import_types6.ChannelType.GuildLink || this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread || this.type === import_types6.ChannelType.GuildForum || this.type === import_types6.ChannelType.GuildMedia;
|
|
1004
|
+
}
|
|
1005
|
+
/** Check if this is a thread (public, private, or announcement). */
|
|
1006
|
+
isThread() {
|
|
1007
|
+
return this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread;
|
|
1008
|
+
}
|
|
1009
|
+
/** Check if this is a forum channel. */
|
|
1010
|
+
isForum() {
|
|
1011
|
+
return this.type === import_types6.ChannelType.GuildForum;
|
|
1012
|
+
}
|
|
1013
|
+
/** Check if this is a media channel. */
|
|
1014
|
+
isMedia() {
|
|
1015
|
+
return this.type === import_types6.ChannelType.GuildMedia;
|
|
1016
|
+
}
|
|
1017
|
+
/** Check if this is a guild text channel. */
|
|
1018
|
+
isText() {
|
|
1019
|
+
return this.type === import_types6.ChannelType.GuildText;
|
|
1020
|
+
}
|
|
1021
|
+
/** Check if this is a guild announcement channel. */
|
|
1022
|
+
isAnnouncement() {
|
|
1023
|
+
return this.type === import_types6.ChannelType.GuildAnnouncement;
|
|
1024
|
+
}
|
|
1025
|
+
/** Check if this is a category channel. */
|
|
1026
|
+
isCategory() {
|
|
1027
|
+
return this.type === import_types6.ChannelType.GuildCategory;
|
|
1028
|
+
}
|
|
1029
|
+
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1030
|
+
isDM() {
|
|
1031
|
+
return this.type === import_types6.ChannelType.DM || this.type === import_types6.ChannelType.GroupDM || this.type === import_types6.ChannelType.DMPersonalNotes;
|
|
1032
|
+
}
|
|
1033
|
+
/** Check if this is a personal notes channel. */
|
|
1034
|
+
isPersonalNotes() {
|
|
1035
|
+
return this.type === import_types6.ChannelType.DMPersonalNotes;
|
|
1036
|
+
}
|
|
1037
|
+
/** Check if this is a voice channel. */
|
|
1038
|
+
isVoice() {
|
|
1039
|
+
return this.type === import_types6.ChannelType.GuildVoice;
|
|
1040
|
+
}
|
|
1041
|
+
/** Check if this is a link channel. */
|
|
1042
|
+
isLink() {
|
|
1043
|
+
return this.type === import_types6.ChannelType.GuildLink;
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Delete recent messages or an explicit ID list.
|
|
1047
|
+
* - `bulkDelete(5)` — fetch last 5 via {@link MessageManager} then delete (1–100)
|
|
1048
|
+
* - `bulkDelete(['id1'])` — single DELETE; 2–100 uses bulk-delete route
|
|
1049
|
+
*/
|
|
1050
|
+
async bulkDelete(countOrIds) {
|
|
1051
|
+
let ids;
|
|
1052
|
+
if (typeof countOrIds === "number") {
|
|
1053
|
+
if (!Number.isInteger(countOrIds) || countOrIds < 1 || countOrIds > 100) {
|
|
1054
|
+
throw new import_util2.FluxerError("bulkDelete count must be between 1 and 100", {
|
|
1055
|
+
code: import_util.ErrorCodes.InvalidBulkDelete
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
ids = [
|
|
1059
|
+
...(await new MessageManager(this.client, this.id).fetch({ limit: countOrIds })).keys()
|
|
1060
|
+
];
|
|
1061
|
+
} else {
|
|
1062
|
+
ids = [...countOrIds];
|
|
1063
|
+
}
|
|
1064
|
+
if (ids.length === 0) return [];
|
|
1065
|
+
if (ids.length === 1) {
|
|
1066
|
+
await this.client.rest.delete(import_types6.Routes.channelMessage(this.id, ids[0]), { auth: true });
|
|
1067
|
+
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
1068
|
+
return ids;
|
|
1069
|
+
}
|
|
1070
|
+
if (ids.length > 100) {
|
|
1071
|
+
throw new import_util2.FluxerError("bulkDelete requires at most 100 message IDs", {
|
|
1072
|
+
code: import_util.ErrorCodes.InvalidBulkDelete
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
await this.client.rest.post(import_types6.Routes.channelBulkDelete(this.id), {
|
|
1076
|
+
body: { message_ids: ids },
|
|
1077
|
+
auth: true
|
|
1078
|
+
});
|
|
1079
|
+
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1080
|
+
return ids;
|
|
1081
|
+
}
|
|
1082
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1083
|
+
async bulkDeleteMyMessages(options) {
|
|
1084
|
+
const body = options ? toSudoBody(options) : void 0;
|
|
1085
|
+
await this.client.rest.post(import_types6.Routes.channelBulkDeleteMine(this.id), {
|
|
1086
|
+
body: body && Object.keys(body).length ? body : void 0,
|
|
1087
|
+
auth: true
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Mark all pinned messages as read in this channel.
|
|
1092
|
+
* Session-token helper; bots usually skip this.
|
|
1093
|
+
*/
|
|
1094
|
+
async acknowledgePins() {
|
|
1095
|
+
await this.client.rest.post(import_types6.Routes.channelPinsAck(this.id), { auth: true });
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Clear the read state for this channel.
|
|
1099
|
+
* Session-token helper; bots usually skip this.
|
|
1100
|
+
*/
|
|
1101
|
+
async clearReadState() {
|
|
1102
|
+
await this.client.rest.delete(import_types6.Routes.channelMessagesAck(this.id), { auth: true });
|
|
1103
|
+
}
|
|
1104
|
+
/** Request upload URLs for attachments before sending a message. */
|
|
1105
|
+
async requestAttachmentUploads(attachments) {
|
|
1106
|
+
const data = await this.client.rest.post(
|
|
1107
|
+
import_types6.Routes.channelAttachments(this.id),
|
|
1108
|
+
{
|
|
1109
|
+
body: toAttachmentUploadPlanBody(attachments),
|
|
1110
|
+
auth: true
|
|
1111
|
+
}
|
|
1112
|
+
);
|
|
1113
|
+
return toAttachmentUploadPlanResponse(data);
|
|
1114
|
+
}
|
|
1115
|
+
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
1116
|
+
async completeAttachmentUploads(uploads) {
|
|
1117
|
+
const data = await this.client.rest.post(
|
|
1118
|
+
import_types6.Routes.channelAttachmentsComplete(this.id),
|
|
1119
|
+
{
|
|
1120
|
+
body: toAttachmentUploadCompleteBody(uploads),
|
|
1121
|
+
auth: true
|
|
1122
|
+
}
|
|
1123
|
+
);
|
|
1124
|
+
return {
|
|
1125
|
+
uploads: data.uploads.map((u) => ({ uploadFilename: u.upload_filename }))
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
/** Upload files for sending in a message (helper). */
|
|
1129
|
+
async uploadAttachmentsForSend(files) {
|
|
1130
|
+
return uploadAttachmentsForSend(this.client, this.id, files);
|
|
1131
|
+
}
|
|
1132
|
+
/** Trigger the typing indicator in this channel. */
|
|
1133
|
+
async sendTyping() {
|
|
1134
|
+
await this.client.rest.post(import_types6.Routes.channelTyping(this.id), { auth: true });
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Fetch available RTC regions for voice channels.
|
|
1138
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
1139
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
1140
|
+
*/
|
|
1141
|
+
async fetchRtcRegions() {
|
|
1142
|
+
const data = await this.client.rest.get(import_types6.Routes.channelRtcRegions(this.id), {
|
|
1143
|
+
auth: true
|
|
1144
|
+
});
|
|
1145
|
+
return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
|
|
1146
|
+
}
|
|
1147
|
+
/** Fetch slowmode state for this channel. */
|
|
1148
|
+
async fetchSlowmode() {
|
|
1149
|
+
const data = await this.client.rest.get(
|
|
1150
|
+
import_types6.Routes.channelSlowmode(this.id),
|
|
1151
|
+
{ auth: true }
|
|
1152
|
+
);
|
|
1153
|
+
return {
|
|
1154
|
+
rateLimitPerUser: data.rate_limit_per_user,
|
|
1155
|
+
retryAfterMs: data.retry_after_ms,
|
|
1156
|
+
nextSendAllowedAt: data.next_send_allowed_at
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1160
|
+
canSendMessage() {
|
|
1161
|
+
return this.isTextBased();
|
|
1162
|
+
}
|
|
1163
|
+
/** Per-channel message cache + fetch. */
|
|
1164
|
+
get messages() {
|
|
1165
|
+
if (!this.#messages) {
|
|
1166
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1167
|
+
}
|
|
1168
|
+
return this.#messages;
|
|
1169
|
+
}
|
|
1170
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
1171
|
+
createMessageCollector(options) {
|
|
1172
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
1176
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1177
|
+
* @example
|
|
1178
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
1179
|
+
*/
|
|
1180
|
+
awaitMessages(options) {
|
|
1181
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Delete this channel (or close it if it is a DM).
|
|
1185
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
1186
|
+
* @example
|
|
1187
|
+
* const channel = await client.channels.fetch(channelId);
|
|
1188
|
+
* await channel.delete();
|
|
1189
|
+
*/
|
|
1190
|
+
async delete(options) {
|
|
1191
|
+
const params = new URLSearchParams();
|
|
1192
|
+
if (options?.silent) params.set("silent", "true");
|
|
1193
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
1194
|
+
const qs = params.toString();
|
|
1195
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
1196
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
1197
|
+
await this.client.rest.delete(import_types6.Routes.channel(this.id) + (qs ? `?${qs}` : ""), {
|
|
1198
|
+
body,
|
|
1199
|
+
auth: true,
|
|
1200
|
+
...auditReasonHeaders(_reason)
|
|
1201
|
+
});
|
|
1202
|
+
this.client.channels.delete(this.id);
|
|
1203
|
+
this.client._clearMessageCache(this.id);
|
|
1204
|
+
if (this.isGuild() && this.guildId) {
|
|
1205
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
/** Channel mention (`<#id>`). */
|
|
1209
|
+
toString() {
|
|
1210
|
+
return `<#${this.id}>`;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// src/Domain/Channel/ThreadCache.ts
|
|
1215
|
+
function cacheThread(client, data) {
|
|
1216
|
+
const existing = client.channels.get(data.id);
|
|
1217
|
+
if (existing?.isThread() && existing.type === data.type) {
|
|
1218
|
+
existing._patch(data);
|
|
1219
|
+
placeThread(client, existing);
|
|
1220
|
+
return existing;
|
|
1221
|
+
}
|
|
1222
|
+
const created = Channel.from(client, data);
|
|
1223
|
+
if (!created.isThread()) {
|
|
1224
|
+
throw new import_util2.FluxerError(`Channel ${data.id} is not a thread`, {
|
|
1225
|
+
code: import_util.ErrorCodes.InvalidChannelType
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
placeThread(client, created);
|
|
1229
|
+
return created;
|
|
1230
|
+
}
|
|
1231
|
+
function placeThread(client, thread) {
|
|
1232
|
+
client.channels.set(thread.id, thread);
|
|
1233
|
+
if (!thread.guildId) return;
|
|
1234
|
+
const guild = client.guilds.get(thread.guildId);
|
|
1235
|
+
if (guild) guild.channels.set(thread.id, thread);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
576
1238
|
// src/Domain/Message/Attachment.ts
|
|
577
1239
|
function toMessageAttachment(data) {
|
|
578
1240
|
return {
|
|
@@ -657,12 +1319,12 @@ function toMessageEmbed(data) {
|
|
|
657
1319
|
}
|
|
658
1320
|
|
|
659
1321
|
// src/Domain/Message/MessageReactionManager.ts
|
|
660
|
-
var
|
|
1322
|
+
var import_collection4 = require("@fluxerjs/collection");
|
|
661
1323
|
var MessageReactionManager = class {
|
|
662
1324
|
constructor(message) {
|
|
663
1325
|
this.message = message;
|
|
664
1326
|
}
|
|
665
|
-
_cache = new
|
|
1327
|
+
_cache = new import_collection4.Collection();
|
|
666
1328
|
/** Reactions keyed by unicode name or `name:id`. */
|
|
667
1329
|
get cache() {
|
|
668
1330
|
return this._cache;
|
|
@@ -684,7 +1346,7 @@ var MessageReactionManager = class {
|
|
|
684
1346
|
};
|
|
685
1347
|
|
|
686
1348
|
// src/Domain/Message/MessageSticker.ts
|
|
687
|
-
var
|
|
1349
|
+
var import_util4 = require("@fluxerjs/util");
|
|
688
1350
|
|
|
689
1351
|
// src/Helpers/Constants.ts
|
|
690
1352
|
var import_rest2 = require("@fluxerjs/rest");
|
|
@@ -791,36 +1453,36 @@ var MessageSticker = class extends Base {
|
|
|
791
1453
|
}
|
|
792
1454
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
793
1455
|
get createdTimestamp() {
|
|
794
|
-
return
|
|
1456
|
+
return import_util4.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
795
1457
|
}
|
|
796
1458
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
797
1459
|
get createdAt() {
|
|
798
|
-
return
|
|
1460
|
+
return import_util4.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
799
1461
|
}
|
|
800
1462
|
};
|
|
801
1463
|
|
|
802
1464
|
// src/Domain/Message/Reactions.ts
|
|
803
|
-
var
|
|
1465
|
+
var import_types7 = require("@fluxerjs/types");
|
|
804
1466
|
async function emojiPath(message, emoji) {
|
|
805
1467
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
806
1468
|
}
|
|
807
1469
|
async function reactToMessage(message, emoji) {
|
|
808
1470
|
const wire = await emojiPath(message, emoji);
|
|
809
1471
|
await message.client.rest.put(
|
|
810
|
-
|
|
1472
|
+
import_types7.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
811
1473
|
);
|
|
812
1474
|
}
|
|
813
1475
|
async function removeMessageReaction(message, emoji, userId) {
|
|
814
1476
|
const e = await emojiPath(message, emoji);
|
|
815
|
-
const route = userId ?
|
|
1477
|
+
const route = userId ? import_types7.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types7.Routes.channelMessageReactionMe(message.channelId, message.id, e);
|
|
816
1478
|
await message.client.rest.delete(route);
|
|
817
1479
|
}
|
|
818
1480
|
async function removeAllMessageReactions(message) {
|
|
819
|
-
await message.client.rest.delete(
|
|
1481
|
+
await message.client.rest.delete(import_types7.Routes.channelMessageReactions(message.channelId, message.id));
|
|
820
1482
|
}
|
|
821
1483
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
822
1484
|
const e = await emojiPath(message, emoji);
|
|
823
|
-
await message.client.rest.delete(
|
|
1485
|
+
await message.client.rest.delete(import_types7.Routes.channelMessageReaction(message.channelId, message.id, e));
|
|
824
1486
|
}
|
|
825
1487
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
826
1488
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -831,7 +1493,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
831
1493
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
832
1494
|
if (options?.after) params.set("after", options.after);
|
|
833
1495
|
const qs = params.toString();
|
|
834
|
-
const route =
|
|
1496
|
+
const route = import_types7.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
|
|
835
1497
|
const data = await message.client.rest.get(route);
|
|
836
1498
|
if (Array.isArray(data)) {
|
|
837
1499
|
return {
|
|
@@ -850,7 +1512,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
850
1512
|
|
|
851
1513
|
// src/Domain/Message/Send.ts
|
|
852
1514
|
var import_builders2 = require("@fluxerjs/builders");
|
|
853
|
-
var
|
|
1515
|
+
var import_types8 = require("@fluxerjs/types");
|
|
854
1516
|
function toReplyTarget(ref) {
|
|
855
1517
|
return {
|
|
856
1518
|
channelId: ref.channel_id,
|
|
@@ -884,7 +1546,7 @@ function asReplyTarget(value) {
|
|
|
884
1546
|
}
|
|
885
1547
|
async function sendPrepared(message, payload) {
|
|
886
1548
|
const data = await message.client.rest.post(
|
|
887
|
-
|
|
1549
|
+
import_types8.Routes.channelMessages(message.channelId),
|
|
888
1550
|
payload
|
|
889
1551
|
);
|
|
890
1552
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -936,7 +1598,7 @@ function toMessageSnapshot(client, data) {
|
|
|
936
1598
|
function resolveMessageFlags(flags) {
|
|
937
1599
|
if (flags === void 0) return void 0;
|
|
938
1600
|
if (typeof flags === "number") return flags;
|
|
939
|
-
return Number(
|
|
1601
|
+
return Number(import_util5.MessageFlagsBitField.resolve(flags));
|
|
940
1602
|
}
|
|
941
1603
|
var Message = class _Message extends Base {
|
|
942
1604
|
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
@@ -993,6 +1655,8 @@ var Message = class _Message extends Base {
|
|
|
993
1655
|
nonce;
|
|
994
1656
|
/** IDs of custom emojis in the message classified as explicit. */
|
|
995
1657
|
nsfwEmojis;
|
|
1658
|
+
/** Thread started from this message, when the payload included one. */
|
|
1659
|
+
thread;
|
|
996
1660
|
/**
|
|
997
1661
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
998
1662
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1044,10 +1708,10 @@ var Message = class _Message extends Base {
|
|
|
1044
1708
|
this.createdAt = new Date(data.timestamp);
|
|
1045
1709
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1046
1710
|
this.pinned = data.pinned;
|
|
1047
|
-
this.attachments = new
|
|
1711
|
+
this.attachments = new import_collection5.Collection();
|
|
1048
1712
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1049
|
-
this.type = data.type ??
|
|
1050
|
-
this.flags = new
|
|
1713
|
+
this.type = data.type ?? import_types9.MessageType.Default;
|
|
1714
|
+
this.flags = new import_util5.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1051
1715
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1052
1716
|
this.tts = data.tts ?? false;
|
|
1053
1717
|
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
@@ -1068,6 +1732,7 @@ var Message = class _Message extends Base {
|
|
|
1068
1732
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1069
1733
|
this.nonce = data.nonce ?? null;
|
|
1070
1734
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1735
|
+
this.thread = data.thread ? cacheThread(client, data.thread) : null;
|
|
1071
1736
|
}
|
|
1072
1737
|
/**
|
|
1073
1738
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
@@ -1079,7 +1744,7 @@ var Message = class _Message extends Base {
|
|
|
1079
1744
|
this.pinned = data.pinned;
|
|
1080
1745
|
this.attachments.clear();
|
|
1081
1746
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1082
|
-
this.flags = new
|
|
1747
|
+
this.flags = new import_util5.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1083
1748
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1084
1749
|
this.tts = data.tts ?? false;
|
|
1085
1750
|
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
@@ -1101,6 +1766,7 @@ var Message = class _Message extends Base {
|
|
|
1101
1766
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1102
1767
|
this.nonce = data.nonce ?? null;
|
|
1103
1768
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1769
|
+
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1104
1770
|
}
|
|
1105
1771
|
/**
|
|
1106
1772
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1161,7 +1827,7 @@ var Message = class _Message extends Base {
|
|
|
1161
1827
|
if (options.attachments !== void 0) {
|
|
1162
1828
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
1163
1829
|
}
|
|
1164
|
-
const data = await this.client.rest.patch(
|
|
1830
|
+
const data = await this.client.rest.patch(import_types9.Routes.channelMessage(this.channelId, this.id), {
|
|
1165
1831
|
body
|
|
1166
1832
|
});
|
|
1167
1833
|
const updated = new _Message(this.client, data);
|
|
@@ -1179,13 +1845,30 @@ var Message = class _Message extends Base {
|
|
|
1179
1845
|
awaitReactions(options) {
|
|
1180
1846
|
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1181
1847
|
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Start a thread from this message.
|
|
1850
|
+
* Fluxer chooses a public or announcement thread from the parent channel.
|
|
1851
|
+
*/
|
|
1852
|
+
async startThread(options) {
|
|
1853
|
+
const data = await this.client.rest.post(
|
|
1854
|
+
import_types9.Routes.channelMessageThreads(this.channelId, this.id),
|
|
1855
|
+
{
|
|
1856
|
+
body: toStartThreadFromMessageBody(options),
|
|
1857
|
+
auth: true,
|
|
1858
|
+
...auditReasonHeaders(options.reason)
|
|
1859
|
+
}
|
|
1860
|
+
);
|
|
1861
|
+
const thread = cacheThread(this.client, data);
|
|
1862
|
+
this.thread = thread;
|
|
1863
|
+
return thread;
|
|
1864
|
+
}
|
|
1182
1865
|
/** Fetch the latest version of this message from the API. */
|
|
1183
1866
|
async fetch() {
|
|
1184
1867
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1185
1868
|
}
|
|
1186
1869
|
/** Delete this message. */
|
|
1187
1870
|
async delete(reason) {
|
|
1188
|
-
await this.client.rest.delete(
|
|
1871
|
+
await this.client.rest.delete(import_types9.Routes.channelMessage(this.channelId, this.id), {
|
|
1189
1872
|
...auditReasonHeaders(reason)
|
|
1190
1873
|
});
|
|
1191
1874
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
@@ -1193,19 +1876,19 @@ var Message = class _Message extends Base {
|
|
|
1193
1876
|
/** Delete a specific attachment from this message. */
|
|
1194
1877
|
async deleteAttachment(attachmentId) {
|
|
1195
1878
|
await this.client.rest.delete(
|
|
1196
|
-
|
|
1879
|
+
import_types9.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
1197
1880
|
{ auth: true }
|
|
1198
1881
|
);
|
|
1199
1882
|
this.attachments.delete(attachmentId);
|
|
1200
1883
|
}
|
|
1201
1884
|
/** Pin this message in the channel. */
|
|
1202
1885
|
async pin() {
|
|
1203
|
-
await this.client.rest.put(
|
|
1886
|
+
await this.client.rest.put(import_types9.Routes.channelPinMessage(this.channelId, this.id));
|
|
1204
1887
|
this.pinned = true;
|
|
1205
1888
|
}
|
|
1206
1889
|
/** Unpin this message from the channel. */
|
|
1207
1890
|
async unpin() {
|
|
1208
|
-
await this.client.rest.delete(
|
|
1891
|
+
await this.client.rest.delete(import_types9.Routes.channelPinMessage(this.channelId, this.id));
|
|
1209
1892
|
this.pinned = false;
|
|
1210
1893
|
}
|
|
1211
1894
|
/** React to this message with an emoji. */
|
|
@@ -1235,7 +1918,7 @@ var Message = class _Message extends Base {
|
|
|
1235
1918
|
};
|
|
1236
1919
|
|
|
1237
1920
|
// src/Domain/Message/PartialMessage.ts
|
|
1238
|
-
var
|
|
1921
|
+
var import_util6 = require("@fluxerjs/util");
|
|
1239
1922
|
var PartialMessage = class {
|
|
1240
1923
|
partial = true;
|
|
1241
1924
|
client;
|
|
@@ -1254,7 +1937,7 @@ var PartialMessage = class {
|
|
|
1254
1937
|
this.content = data.content ?? null;
|
|
1255
1938
|
this.authorId = data.authorId ?? null;
|
|
1256
1939
|
this.author = data.author ?? null;
|
|
1257
|
-
this.createdAt = data.createdAt ?? (
|
|
1940
|
+
this.createdAt = data.createdAt ?? (import_util6.SnowflakeUtil.isValid(data.id) ? import_util6.SnowflakeUtil.dateFromSnowflake(data.id) : null);
|
|
1258
1941
|
}
|
|
1259
1942
|
/**
|
|
1260
1943
|
* Live text-capable channel from cache, or null if uncached / not text-based.
|