@fluxerjs/core 3.2.0 → 3.4.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-DHo7ltTz.d.ts → SubpathMessage-BAwFSagN.d.mts} +2426 -2104
- package/dist/{SubpathMessage-DW9TgPNl.d.mts → SubpathMessage-Dq-1tI7E.d.ts} +2426 -2104
- package/dist/{Sudo-DwxTf-jj.d.mts → Sudo-mzPLv6YU.d.mts} +339 -3
- package/dist/{Sudo-DwxTf-jj.d.ts → Sudo-mzPLv6YU.d.ts} +339 -3
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2787 -1424
- package/dist/client.mjs +2738 -1369
- package/dist/cluster.d.mts +2 -2
- package/dist/cluster.d.ts +2 -2
- package/dist/cluster.js +2787 -1424
- package/dist/cluster.mjs +2738 -1369
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1750 -365
- package/dist/index.mjs +1654 -270
- package/dist/internal.d.mts +3 -2
- package/dist/internal.d.ts +3 -2
- package/dist/internal.js +52 -0
- package/dist/internal.mjs +54 -0
- package/dist/message.d.mts +2 -2
- package/dist/message.d.ts +2 -2
- package/dist/message.js +846 -63
- package/dist/message.mjs +838 -53
- package/package.json +7 -7
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) {
|
|
@@ -425,6 +496,7 @@ var Events = {
|
|
|
425
496
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
426
497
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
427
498
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
499
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
428
500
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
429
501
|
GuildMemberAdd: "guildMemberAdd",
|
|
430
502
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -436,6 +508,14 @@ var Events = {
|
|
|
436
508
|
ChannelCreate: "channelCreate",
|
|
437
509
|
ChannelUpdate: "channelUpdate",
|
|
438
510
|
ChannelDelete: "channelDelete",
|
|
511
|
+
ThreadCreate: "threadCreate",
|
|
512
|
+
ThreadUpdate: "threadUpdate",
|
|
513
|
+
ThreadDelete: "threadDelete",
|
|
514
|
+
ThreadListSync: "threadListSync",
|
|
515
|
+
ThreadMemberUpdate: "threadMemberUpdate",
|
|
516
|
+
ThreadMembersUpdate: "threadMembersUpdate",
|
|
517
|
+
ThreadMemberListUpdate: "threadMemberListUpdate",
|
|
518
|
+
ForumUnreads: "forumUnreads",
|
|
439
519
|
ChannelPinsUpdate: "channelPinsUpdate",
|
|
440
520
|
ChannelRecipientAdd: "channelRecipientAdd",
|
|
441
521
|
ChannelRecipientRemove: "channelRecipientRemove",
|
|
@@ -451,6 +531,8 @@ var Events = {
|
|
|
451
531
|
VoiceStateAck: "voiceStateAck",
|
|
452
532
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
453
533
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
534
|
+
VoiceSignal: "voiceSignal",
|
|
535
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
454
536
|
VoiceStatesSync: "voiceStatesSync",
|
|
455
537
|
WebhooksUpdate: "webhooksUpdate",
|
|
456
538
|
Resumed: "resumed",
|
|
@@ -573,6 +655,655 @@ var ReactionCollector = class _ReactionCollector extends import_node_events.Even
|
|
|
573
655
|
}
|
|
574
656
|
};
|
|
575
657
|
|
|
658
|
+
// src/Domain/Channel/Base.ts
|
|
659
|
+
var import_types6 = require("@fluxerjs/types");
|
|
660
|
+
var import_util3 = require("@fluxerjs/util");
|
|
661
|
+
|
|
662
|
+
// src/ClientCore/MessageManager.ts
|
|
663
|
+
var import_collection2 = require("@fluxerjs/collection");
|
|
664
|
+
var import_types4 = require("@fluxerjs/types");
|
|
665
|
+
|
|
666
|
+
// src/ClientCore/Resolve.ts
|
|
667
|
+
function normalizeSnowflakeId(value, label) {
|
|
668
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
669
|
+
throw new TypeError(
|
|
670
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
674
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
675
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
676
|
+
}
|
|
677
|
+
return id;
|
|
678
|
+
}
|
|
679
|
+
function assertApiObjectWithId(data, label) {
|
|
680
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
681
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
682
|
+
}
|
|
683
|
+
return data;
|
|
684
|
+
}
|
|
685
|
+
function assertApiArray(data, label) {
|
|
686
|
+
if (!Array.isArray(data)) {
|
|
687
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
688
|
+
}
|
|
689
|
+
return data;
|
|
690
|
+
}
|
|
691
|
+
async function dedupeFetch(pending, key, fn) {
|
|
692
|
+
const existing = pending.get(key);
|
|
693
|
+
if (existing) return existing;
|
|
694
|
+
const request = fn();
|
|
695
|
+
pending.set(key, request);
|
|
696
|
+
try {
|
|
697
|
+
return await request;
|
|
698
|
+
} finally {
|
|
699
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// src/ClientCore/MessageManager.ts
|
|
704
|
+
var MessageManager = class {
|
|
705
|
+
constructor(client, channelId) {
|
|
706
|
+
this.client = client;
|
|
707
|
+
this.channelId = channelId;
|
|
708
|
+
}
|
|
709
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
710
|
+
_structures = new import_collection2.Collection();
|
|
711
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
712
|
+
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
713
|
+
get(messageId) {
|
|
714
|
+
const id = String(messageId ?? "").trim();
|
|
715
|
+
if (!id) return void 0;
|
|
716
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
717
|
+
if (!data) {
|
|
718
|
+
this._structures.delete(id);
|
|
719
|
+
return void 0;
|
|
720
|
+
}
|
|
721
|
+
const existing = this._structures.get(id);
|
|
722
|
+
if (existing) {
|
|
723
|
+
existing._patch(data);
|
|
724
|
+
return existing;
|
|
725
|
+
}
|
|
726
|
+
const message = new Message(this.client, data);
|
|
727
|
+
this._structures.set(id, message);
|
|
728
|
+
return message;
|
|
729
|
+
}
|
|
730
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
731
|
+
async resolve(messageId) {
|
|
732
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
733
|
+
return this.get(id) ?? this.fetch(id);
|
|
734
|
+
}
|
|
735
|
+
async fetch(idOrOptions) {
|
|
736
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
737
|
+
}
|
|
738
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
739
|
+
wrap(data) {
|
|
740
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
741
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
742
|
+
const existing = this._structures.get(data.id);
|
|
743
|
+
if (existing) {
|
|
744
|
+
existing._patch(cached);
|
|
745
|
+
return existing;
|
|
746
|
+
}
|
|
747
|
+
const message = new Message(this.client, cached);
|
|
748
|
+
this._structures.set(data.id, message);
|
|
749
|
+
return message;
|
|
750
|
+
}
|
|
751
|
+
/** Fetch a single message from the API. */
|
|
752
|
+
async fetchOne(messageId) {
|
|
753
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
754
|
+
}
|
|
755
|
+
async fetchOneFresh(messageId) {
|
|
756
|
+
try {
|
|
757
|
+
const data = assertApiObjectWithId(
|
|
758
|
+
await this.client.rest.get(import_types4.Routes.channelMessage(this.channelId, messageId)),
|
|
759
|
+
"messages.fetch()"
|
|
760
|
+
);
|
|
761
|
+
return this.wrap(data);
|
|
762
|
+
} catch (err) {
|
|
763
|
+
rethrowMapped(err, {
|
|
764
|
+
notFound: {
|
|
765
|
+
code: import_util.ErrorCodes.MessageNotFound,
|
|
766
|
+
message: `Message ${messageId} not found in channel ${this.channelId}`
|
|
767
|
+
},
|
|
768
|
+
fallback: `Failed to fetch message ${messageId}`
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
/** Fetch multiple messages from the API with pagination/filtering. */
|
|
773
|
+
async fetchMany(options) {
|
|
774
|
+
if (options.limit != null && (options.limit < 1 || options.limit > 100)) {
|
|
775
|
+
throw new import_util2.FluxerError("limit must be between 1 and 100", {
|
|
776
|
+
code: import_util.ErrorCodes.InvalidFetchLimit
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
const qs = new URLSearchParams();
|
|
780
|
+
for (const key of ["limit", "before", "after", "around"]) {
|
|
781
|
+
const value = options[key];
|
|
782
|
+
if (value != null && value !== "") qs.set(key, String(value));
|
|
783
|
+
}
|
|
784
|
+
const base = import_types4.Routes.channelMessages(this.channelId);
|
|
785
|
+
const data = assertApiArray(
|
|
786
|
+
await this.client.rest.get(qs.size > 0 ? `${base}?${qs}` : base),
|
|
787
|
+
"messages.fetch()"
|
|
788
|
+
);
|
|
789
|
+
const collection = new import_collection2.Collection();
|
|
790
|
+
for (const msg of data) {
|
|
791
|
+
if (!msg?.id) continue;
|
|
792
|
+
collection.set(msg.id, this.wrap(msg));
|
|
793
|
+
}
|
|
794
|
+
return collection;
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
// src/Helpers/MessageCollector.ts
|
|
799
|
+
var import_node_events2 = require("events");
|
|
800
|
+
var import_collection3 = require("@fluxerjs/collection");
|
|
801
|
+
function requireCollectorBounds(options) {
|
|
802
|
+
const time = options.time ?? 0;
|
|
803
|
+
const max = options.max ?? 0;
|
|
804
|
+
if (time <= 0 && max <= 0) {
|
|
805
|
+
throw new import_util2.FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
806
|
+
code: import_util.ErrorCodes.CollectorOptionsRequired
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
var MessageCollector = class _MessageCollector extends import_node_events2.EventEmitter {
|
|
811
|
+
client;
|
|
812
|
+
channelId;
|
|
813
|
+
options;
|
|
814
|
+
collected = new import_collection3.Collection();
|
|
815
|
+
_timeout = null;
|
|
816
|
+
_ended = false;
|
|
817
|
+
_listener;
|
|
818
|
+
constructor(client, channelId, options = {}) {
|
|
819
|
+
super();
|
|
820
|
+
requireCollectorBounds(options);
|
|
821
|
+
this.client = client;
|
|
822
|
+
this.channelId = channelId;
|
|
823
|
+
this.options = {
|
|
824
|
+
filter: options.filter ?? (() => true),
|
|
825
|
+
time: options.time ?? 0,
|
|
826
|
+
max: options.max ?? 0
|
|
827
|
+
};
|
|
828
|
+
this._listener = (message) => {
|
|
829
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
830
|
+
if (!this.options.filter(message)) return;
|
|
831
|
+
this.collected.set(message.id, message);
|
|
832
|
+
this.emit("collect", message);
|
|
833
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
834
|
+
this.stop("limit");
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
838
|
+
if (this.options.time > 0) {
|
|
839
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
stop(reason = "user") {
|
|
843
|
+
if (this._ended) return;
|
|
844
|
+
this._ended = true;
|
|
845
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
846
|
+
if (this._timeout) {
|
|
847
|
+
clearTimeout(this._timeout);
|
|
848
|
+
this._timeout = null;
|
|
849
|
+
}
|
|
850
|
+
this.emit("end", this.collected, reason);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
854
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
855
|
+
* the end reason is not listed in `errors`).
|
|
856
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
857
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
858
|
+
*/
|
|
859
|
+
static awaitMessages(client, channelId, options) {
|
|
860
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
861
|
+
return new Promise((resolve, reject) => {
|
|
862
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
863
|
+
collector.on("end", (collected, reason) => {
|
|
864
|
+
if (!errors.includes(reason)) {
|
|
865
|
+
resolve(collected);
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
if (reason === "time") {
|
|
869
|
+
reject(
|
|
870
|
+
new import_util2.FluxerError("Message collector timed out", {
|
|
871
|
+
code: import_util.ErrorCodes.CollectorIdle
|
|
872
|
+
})
|
|
873
|
+
);
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
if (reason === "limit") {
|
|
877
|
+
reject(
|
|
878
|
+
new import_util2.FluxerError("Message collector reached max", {
|
|
879
|
+
code: import_util.ErrorCodes.CollectorMax
|
|
880
|
+
})
|
|
881
|
+
);
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
reject(collected);
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
on(event, listener) {
|
|
889
|
+
return super.on(event, listener);
|
|
890
|
+
}
|
|
891
|
+
emit(event, ...args) {
|
|
892
|
+
return super.emit(event, ...args);
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
// src/Domain/Channel/Attachments.ts
|
|
897
|
+
var import_types5 = require("@fluxerjs/types");
|
|
898
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
899
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
900
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
901
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
902
|
+
if (!rules?.length) return null;
|
|
903
|
+
const snapshot = {};
|
|
904
|
+
for (const rule of rules) {
|
|
905
|
+
Object.assign(snapshot, rule.overrides);
|
|
906
|
+
}
|
|
907
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
908
|
+
}
|
|
909
|
+
function assertBotAttachmentLimits(client, files) {
|
|
910
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
911
|
+
for (const file of files) {
|
|
912
|
+
const size = file.data.byteLength;
|
|
913
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
914
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
915
|
+
throw new import_util2.FluxerError(
|
|
916
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
917
|
+
{ code: import_util.ErrorCodes.AttachmentTooLarge }
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
function asBytes(data) {
|
|
922
|
+
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
923
|
+
const out = new Uint8Array(src.byteLength);
|
|
924
|
+
out.set(src);
|
|
925
|
+
return out;
|
|
926
|
+
}
|
|
927
|
+
async function putBlob(url, body, contentType) {
|
|
928
|
+
const res = await fetch(url, {
|
|
929
|
+
method: "PUT",
|
|
930
|
+
headers: contentType ? { "Content-Type": contentType } : void 0,
|
|
931
|
+
body
|
|
932
|
+
});
|
|
933
|
+
if (!res.ok) {
|
|
934
|
+
throw new import_util2.FluxerError(`Presigned upload failed: ${res.status}`, {
|
|
935
|
+
code: import_util.ErrorCodes.AttachmentUploadFailed
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
940
|
+
assertBotAttachmentLimits(client, files);
|
|
941
|
+
const plan = await client.rest.post(
|
|
942
|
+
import_types5.Routes.channelAttachments(channelId),
|
|
943
|
+
{
|
|
944
|
+
body: {
|
|
945
|
+
attachments: files.map((f) => ({
|
|
946
|
+
id: f.id,
|
|
947
|
+
filename: f.filename,
|
|
948
|
+
file_size: f.data.byteLength,
|
|
949
|
+
content_type: f.contentType
|
|
950
|
+
}))
|
|
951
|
+
},
|
|
952
|
+
auth: true
|
|
953
|
+
}
|
|
954
|
+
);
|
|
955
|
+
const multipart = [];
|
|
956
|
+
const uploaded = [];
|
|
957
|
+
for (const item of plan.attachments) {
|
|
958
|
+
const file = files.find((f) => f.id === item.id);
|
|
959
|
+
if (!file) {
|
|
960
|
+
throw new import_util2.FluxerError(`No file data for planned attachment id ${item.id}`, {
|
|
961
|
+
code: import_util.ErrorCodes.InvalidAttachmentInput
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
const bytes = asBytes(file.data);
|
|
965
|
+
if (item.upload_mode === "singlepart") {
|
|
966
|
+
await putBlob(
|
|
967
|
+
item.upload_url,
|
|
968
|
+
new Blob([bytes], { type: file.contentType }),
|
|
969
|
+
item.content_type
|
|
970
|
+
);
|
|
971
|
+
} else {
|
|
972
|
+
for (const part of item.parts) {
|
|
973
|
+
const start = (part.part_number - 1) * item.part_size;
|
|
974
|
+
const chunk = bytes.subarray(start, Math.min(start + item.part_size, bytes.byteLength));
|
|
975
|
+
await putBlob(part.upload_url, new Blob([asBytes(chunk)]));
|
|
976
|
+
}
|
|
977
|
+
multipart.push({ upload_filename: item.upload_filename, upload_id: item.upload_id });
|
|
978
|
+
}
|
|
979
|
+
uploaded.push({
|
|
980
|
+
id: item.id,
|
|
981
|
+
filename: item.filename,
|
|
982
|
+
upload_filename: item.upload_filename,
|
|
983
|
+
file_size: item.file_size,
|
|
984
|
+
content_type: item.content_type
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
if (multipart.length) {
|
|
988
|
+
await client.rest.post(import_types5.Routes.channelAttachmentsComplete(channelId), {
|
|
989
|
+
body: { uploads: multipart },
|
|
990
|
+
auth: true
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
return uploaded;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// src/Domain/Channel/Base.ts
|
|
997
|
+
function isFullChannelData(data) {
|
|
998
|
+
return "guild_id" in data || "permission_overwrites" in data || "position" in data || "last_message_id" in data || "topic" in data || "thread_metadata" in data || "available_tags" in data;
|
|
999
|
+
}
|
|
1000
|
+
var Channel = class extends Base {
|
|
1001
|
+
#messages;
|
|
1002
|
+
/** The {@link Client} that instantiated this channel. */
|
|
1003
|
+
client;
|
|
1004
|
+
/** Snowflake ID of this channel. */
|
|
1005
|
+
id;
|
|
1006
|
+
/** Channel type (text, voice, category, etc.). */
|
|
1007
|
+
type;
|
|
1008
|
+
/** Channel name (null for some channel types). */
|
|
1009
|
+
name;
|
|
1010
|
+
/** Channel icon hash (null for most channel types). */
|
|
1011
|
+
icon;
|
|
1012
|
+
/** ISO8601 timestamp of the last pinned message update. */
|
|
1013
|
+
lastPinTimestamp;
|
|
1014
|
+
/**
|
|
1015
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
1016
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
1017
|
+
*/
|
|
1018
|
+
partial;
|
|
1019
|
+
constructor(client, data) {
|
|
1020
|
+
super();
|
|
1021
|
+
this.client = client;
|
|
1022
|
+
this.id = data.id;
|
|
1023
|
+
this.type = data.type;
|
|
1024
|
+
this.name = data.name ?? null;
|
|
1025
|
+
this.icon = data.icon ?? null;
|
|
1026
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1027
|
+
this.partial = !isFullChannelData(data);
|
|
1028
|
+
}
|
|
1029
|
+
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1030
|
+
get createdTimestamp() {
|
|
1031
|
+
return import_util3.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1032
|
+
}
|
|
1033
|
+
/** Date when this channel was created, derived from its snowflake ID. */
|
|
1034
|
+
get createdAt() {
|
|
1035
|
+
return import_util3.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
1039
|
+
* @internal
|
|
1040
|
+
*/
|
|
1041
|
+
_patch(data) {
|
|
1042
|
+
if (data.type !== void 0) this.type = data.type;
|
|
1043
|
+
if (data.name !== void 0) this.name = data.name ?? null;
|
|
1044
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
1045
|
+
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1046
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1047
|
+
}
|
|
1048
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
1049
|
+
}
|
|
1050
|
+
/** @internal Factory wired after subclasses load. */
|
|
1051
|
+
static from(_c, _d) {
|
|
1052
|
+
throw new Error("Channel.from not initialized");
|
|
1053
|
+
}
|
|
1054
|
+
/** @internal Factory wired after subclasses load. */
|
|
1055
|
+
static fromOrCreate(_c, _d) {
|
|
1056
|
+
throw new Error("Channel.fromOrCreate not initialized");
|
|
1057
|
+
}
|
|
1058
|
+
/** @internal Factory wired after subclasses load. */
|
|
1059
|
+
static createDM(_c, _d) {
|
|
1060
|
+
throw new Error("Channel.createDM not initialized");
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
|
|
1064
|
+
* Forum and media channels contain threads and do not accept `send`.
|
|
1065
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
1066
|
+
*/
|
|
1067
|
+
isTextBased() {
|
|
1068
|
+
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;
|
|
1069
|
+
}
|
|
1070
|
+
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
1071
|
+
isGuild() {
|
|
1072
|
+
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;
|
|
1073
|
+
}
|
|
1074
|
+
/** Check if this is a thread (public, private, or announcement). */
|
|
1075
|
+
isThread() {
|
|
1076
|
+
return this.type === import_types6.ChannelType.AnnouncementThread || this.type === import_types6.ChannelType.PublicThread || this.type === import_types6.ChannelType.PrivateThread;
|
|
1077
|
+
}
|
|
1078
|
+
/** Check if this is a forum channel. */
|
|
1079
|
+
isForum() {
|
|
1080
|
+
return this.type === import_types6.ChannelType.GuildForum;
|
|
1081
|
+
}
|
|
1082
|
+
/** Check if this is a media channel. */
|
|
1083
|
+
isMedia() {
|
|
1084
|
+
return this.type === import_types6.ChannelType.GuildMedia;
|
|
1085
|
+
}
|
|
1086
|
+
/** Check if this is a guild text channel. */
|
|
1087
|
+
isText() {
|
|
1088
|
+
return this.type === import_types6.ChannelType.GuildText;
|
|
1089
|
+
}
|
|
1090
|
+
/** Check if this is a guild announcement channel. */
|
|
1091
|
+
isAnnouncement() {
|
|
1092
|
+
return this.type === import_types6.ChannelType.GuildAnnouncement;
|
|
1093
|
+
}
|
|
1094
|
+
/** Check if this is a category channel. */
|
|
1095
|
+
isCategory() {
|
|
1096
|
+
return this.type === import_types6.ChannelType.GuildCategory;
|
|
1097
|
+
}
|
|
1098
|
+
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1099
|
+
isDM() {
|
|
1100
|
+
return this.type === import_types6.ChannelType.DM || this.type === import_types6.ChannelType.GroupDM || this.type === import_types6.ChannelType.DMPersonalNotes;
|
|
1101
|
+
}
|
|
1102
|
+
/** Check if this is a personal notes channel. */
|
|
1103
|
+
isPersonalNotes() {
|
|
1104
|
+
return this.type === import_types6.ChannelType.DMPersonalNotes;
|
|
1105
|
+
}
|
|
1106
|
+
/** Check if this is a voice channel. */
|
|
1107
|
+
isVoice() {
|
|
1108
|
+
return this.type === import_types6.ChannelType.GuildVoice;
|
|
1109
|
+
}
|
|
1110
|
+
/** Check if this is a link channel. */
|
|
1111
|
+
isLink() {
|
|
1112
|
+
return this.type === import_types6.ChannelType.GuildLink;
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Delete recent messages or an explicit ID list.
|
|
1116
|
+
* - `bulkDelete(5)` — fetch last 5 via {@link MessageManager} then delete (1–100)
|
|
1117
|
+
* - `bulkDelete(['id1'])` — single DELETE; 2–100 uses bulk-delete route
|
|
1118
|
+
*/
|
|
1119
|
+
async bulkDelete(countOrIds) {
|
|
1120
|
+
let ids;
|
|
1121
|
+
if (typeof countOrIds === "number") {
|
|
1122
|
+
if (!Number.isInteger(countOrIds) || countOrIds < 1 || countOrIds > 100) {
|
|
1123
|
+
throw new import_util2.FluxerError("bulkDelete count must be between 1 and 100", {
|
|
1124
|
+
code: import_util.ErrorCodes.InvalidBulkDelete
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
ids = [
|
|
1128
|
+
...(await new MessageManager(this.client, this.id).fetch({ limit: countOrIds })).keys()
|
|
1129
|
+
];
|
|
1130
|
+
} else {
|
|
1131
|
+
ids = [...countOrIds];
|
|
1132
|
+
}
|
|
1133
|
+
if (ids.length === 0) return [];
|
|
1134
|
+
if (ids.length === 1) {
|
|
1135
|
+
await this.client.rest.delete(import_types6.Routes.channelMessage(this.id, ids[0]), { auth: true });
|
|
1136
|
+
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
1137
|
+
return ids;
|
|
1138
|
+
}
|
|
1139
|
+
if (ids.length > 100) {
|
|
1140
|
+
throw new import_util2.FluxerError("bulkDelete requires at most 100 message IDs", {
|
|
1141
|
+
code: import_util.ErrorCodes.InvalidBulkDelete
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
await this.client.rest.post(import_types6.Routes.channelBulkDelete(this.id), {
|
|
1145
|
+
body: { message_ids: ids },
|
|
1146
|
+
auth: true
|
|
1147
|
+
});
|
|
1148
|
+
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1149
|
+
return ids;
|
|
1150
|
+
}
|
|
1151
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1152
|
+
async bulkDeleteMyMessages(options) {
|
|
1153
|
+
const body = options ? toSudoBody(options) : void 0;
|
|
1154
|
+
await this.client.rest.post(import_types6.Routes.channelBulkDeleteMine(this.id), {
|
|
1155
|
+
body: body && Object.keys(body).length ? body : void 0,
|
|
1156
|
+
auth: true
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Mark all pinned messages as read in this channel.
|
|
1161
|
+
* Session-token helper; bots usually skip this.
|
|
1162
|
+
*/
|
|
1163
|
+
async acknowledgePins() {
|
|
1164
|
+
await this.client.rest.post(import_types6.Routes.channelPinsAck(this.id), { auth: true });
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Clear the read state for this channel.
|
|
1168
|
+
* Session-token helper; bots usually skip this.
|
|
1169
|
+
*/
|
|
1170
|
+
async clearReadState() {
|
|
1171
|
+
await this.client.rest.delete(import_types6.Routes.channelMessagesAck(this.id), { auth: true });
|
|
1172
|
+
}
|
|
1173
|
+
/** Request upload URLs for attachments before sending a message. */
|
|
1174
|
+
async requestAttachmentUploads(attachments) {
|
|
1175
|
+
const data = await this.client.rest.post(
|
|
1176
|
+
import_types6.Routes.channelAttachments(this.id),
|
|
1177
|
+
{
|
|
1178
|
+
body: toAttachmentUploadPlanBody(attachments),
|
|
1179
|
+
auth: true
|
|
1180
|
+
}
|
|
1181
|
+
);
|
|
1182
|
+
return toAttachmentUploadPlanResponse(data);
|
|
1183
|
+
}
|
|
1184
|
+
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
1185
|
+
async completeAttachmentUploads(uploads) {
|
|
1186
|
+
const data = await this.client.rest.post(
|
|
1187
|
+
import_types6.Routes.channelAttachmentsComplete(this.id),
|
|
1188
|
+
{
|
|
1189
|
+
body: toAttachmentUploadCompleteBody(uploads),
|
|
1190
|
+
auth: true
|
|
1191
|
+
}
|
|
1192
|
+
);
|
|
1193
|
+
return {
|
|
1194
|
+
uploads: data.uploads.map((u) => ({ uploadFilename: u.upload_filename }))
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
/** Upload files for sending in a message (helper). */
|
|
1198
|
+
async uploadAttachmentsForSend(files) {
|
|
1199
|
+
return uploadAttachmentsForSend(this.client, this.id, files);
|
|
1200
|
+
}
|
|
1201
|
+
/** Trigger the typing indicator in this channel. */
|
|
1202
|
+
async sendTyping() {
|
|
1203
|
+
await this.client.rest.post(import_types6.Routes.channelTyping(this.id), { auth: true });
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Fetch available RTC regions for voice channels.
|
|
1207
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
1208
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
1209
|
+
*/
|
|
1210
|
+
async fetchRtcRegions() {
|
|
1211
|
+
const data = await this.client.rest.get(import_types6.Routes.channelRtcRegions(this.id), {
|
|
1212
|
+
auth: true
|
|
1213
|
+
});
|
|
1214
|
+
return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
|
|
1215
|
+
}
|
|
1216
|
+
/** Fetch slowmode state for this channel. */
|
|
1217
|
+
async fetchSlowmode() {
|
|
1218
|
+
const data = await this.client.rest.get(
|
|
1219
|
+
import_types6.Routes.channelSlowmode(this.id),
|
|
1220
|
+
{ auth: true }
|
|
1221
|
+
);
|
|
1222
|
+
return {
|
|
1223
|
+
rateLimitPerUser: data.rate_limit_per_user,
|
|
1224
|
+
retryAfterMs: data.retry_after_ms,
|
|
1225
|
+
nextSendAllowedAt: data.next_send_allowed_at
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1229
|
+
canSendMessage() {
|
|
1230
|
+
return this.isTextBased();
|
|
1231
|
+
}
|
|
1232
|
+
/** Per-channel message cache + fetch. */
|
|
1233
|
+
get messages() {
|
|
1234
|
+
if (!this.#messages) {
|
|
1235
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1236
|
+
}
|
|
1237
|
+
return this.#messages;
|
|
1238
|
+
}
|
|
1239
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
1240
|
+
createMessageCollector(options) {
|
|
1241
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
1245
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1246
|
+
* @example
|
|
1247
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
1248
|
+
*/
|
|
1249
|
+
awaitMessages(options) {
|
|
1250
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Delete this channel (or close it if it is a DM).
|
|
1254
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
1255
|
+
* @example
|
|
1256
|
+
* const channel = await client.channels.fetch(channelId);
|
|
1257
|
+
* await channel.delete();
|
|
1258
|
+
*/
|
|
1259
|
+
async delete(options) {
|
|
1260
|
+
const params = new URLSearchParams();
|
|
1261
|
+
if (options?.silent) params.set("silent", "true");
|
|
1262
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
1263
|
+
const qs = params.toString();
|
|
1264
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
1265
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
1266
|
+
await this.client.rest.delete(import_types6.Routes.channel(this.id) + (qs ? `?${qs}` : ""), {
|
|
1267
|
+
body,
|
|
1268
|
+
auth: true,
|
|
1269
|
+
...auditReasonHeaders(_reason)
|
|
1270
|
+
});
|
|
1271
|
+
this.client.channels.delete(this.id);
|
|
1272
|
+
this.client._clearMessageCache(this.id);
|
|
1273
|
+
if (this.isGuild() && this.guildId) {
|
|
1274
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
/** Channel mention (`<#id>`). */
|
|
1278
|
+
toString() {
|
|
1279
|
+
return `<#${this.id}>`;
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
// src/Domain/Channel/ThreadCache.ts
|
|
1284
|
+
function cacheThread(client, data) {
|
|
1285
|
+
const existing = client.channels.get(data.id);
|
|
1286
|
+
if (existing?.isThread() && existing.type === data.type) {
|
|
1287
|
+
existing._patch(data);
|
|
1288
|
+
placeThread(client, existing);
|
|
1289
|
+
return existing;
|
|
1290
|
+
}
|
|
1291
|
+
const created = Channel.from(client, data);
|
|
1292
|
+
if (!created.isThread()) {
|
|
1293
|
+
throw new import_util2.FluxerError(`Channel ${data.id} is not a thread`, {
|
|
1294
|
+
code: import_util.ErrorCodes.InvalidChannelType
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
placeThread(client, created);
|
|
1298
|
+
return created;
|
|
1299
|
+
}
|
|
1300
|
+
function placeThread(client, thread) {
|
|
1301
|
+
client.channels.set(thread.id, thread);
|
|
1302
|
+
if (!thread.guildId) return;
|
|
1303
|
+
const guild = client.guilds.get(thread.guildId);
|
|
1304
|
+
if (guild) guild.channels.set(thread.id, thread);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
576
1307
|
// src/Domain/Message/Attachment.ts
|
|
577
1308
|
function toMessageAttachment(data) {
|
|
578
1309
|
return {
|
|
@@ -657,12 +1388,12 @@ function toMessageEmbed(data) {
|
|
|
657
1388
|
}
|
|
658
1389
|
|
|
659
1390
|
// src/Domain/Message/MessageReactionManager.ts
|
|
660
|
-
var
|
|
1391
|
+
var import_collection4 = require("@fluxerjs/collection");
|
|
661
1392
|
var MessageReactionManager = class {
|
|
662
1393
|
constructor(message) {
|
|
663
1394
|
this.message = message;
|
|
664
1395
|
}
|
|
665
|
-
_cache = new
|
|
1396
|
+
_cache = new import_collection4.Collection();
|
|
666
1397
|
/** Reactions keyed by unicode name or `name:id`. */
|
|
667
1398
|
get cache() {
|
|
668
1399
|
return this._cache;
|
|
@@ -684,7 +1415,7 @@ var MessageReactionManager = class {
|
|
|
684
1415
|
};
|
|
685
1416
|
|
|
686
1417
|
// src/Domain/Message/MessageSticker.ts
|
|
687
|
-
var
|
|
1418
|
+
var import_util4 = require("@fluxerjs/util");
|
|
688
1419
|
|
|
689
1420
|
// src/Helpers/Constants.ts
|
|
690
1421
|
var import_rest2 = require("@fluxerjs/rest");
|
|
@@ -791,36 +1522,36 @@ var MessageSticker = class extends Base {
|
|
|
791
1522
|
}
|
|
792
1523
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
793
1524
|
get createdTimestamp() {
|
|
794
|
-
return
|
|
1525
|
+
return import_util4.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
795
1526
|
}
|
|
796
1527
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
797
1528
|
get createdAt() {
|
|
798
|
-
return
|
|
1529
|
+
return import_util4.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
799
1530
|
}
|
|
800
1531
|
};
|
|
801
1532
|
|
|
802
1533
|
// src/Domain/Message/Reactions.ts
|
|
803
|
-
var
|
|
1534
|
+
var import_types7 = require("@fluxerjs/types");
|
|
804
1535
|
async function emojiPath(message, emoji) {
|
|
805
1536
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
806
1537
|
}
|
|
807
1538
|
async function reactToMessage(message, emoji) {
|
|
808
1539
|
const wire = await emojiPath(message, emoji);
|
|
809
1540
|
await message.client.rest.put(
|
|
810
|
-
|
|
1541
|
+
import_types7.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
811
1542
|
);
|
|
812
1543
|
}
|
|
813
1544
|
async function removeMessageReaction(message, emoji, userId) {
|
|
814
1545
|
const e = await emojiPath(message, emoji);
|
|
815
|
-
const route = userId ?
|
|
1546
|
+
const route = userId ? import_types7.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types7.Routes.channelMessageReactionMe(message.channelId, message.id, e);
|
|
816
1547
|
await message.client.rest.delete(route);
|
|
817
1548
|
}
|
|
818
1549
|
async function removeAllMessageReactions(message) {
|
|
819
|
-
await message.client.rest.delete(
|
|
1550
|
+
await message.client.rest.delete(import_types7.Routes.channelMessageReactions(message.channelId, message.id));
|
|
820
1551
|
}
|
|
821
1552
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
822
1553
|
const e = await emojiPath(message, emoji);
|
|
823
|
-
await message.client.rest.delete(
|
|
1554
|
+
await message.client.rest.delete(import_types7.Routes.channelMessageReaction(message.channelId, message.id, e));
|
|
824
1555
|
}
|
|
825
1556
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
826
1557
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -831,7 +1562,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
831
1562
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
832
1563
|
if (options?.after) params.set("after", options.after);
|
|
833
1564
|
const qs = params.toString();
|
|
834
|
-
const route =
|
|
1565
|
+
const route = import_types7.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
|
|
835
1566
|
const data = await message.client.rest.get(route);
|
|
836
1567
|
if (Array.isArray(data)) {
|
|
837
1568
|
return {
|
|
@@ -850,7 +1581,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
850
1581
|
|
|
851
1582
|
// src/Domain/Message/Send.ts
|
|
852
1583
|
var import_builders2 = require("@fluxerjs/builders");
|
|
853
|
-
var
|
|
1584
|
+
var import_types8 = require("@fluxerjs/types");
|
|
854
1585
|
function toReplyTarget(ref) {
|
|
855
1586
|
return {
|
|
856
1587
|
channelId: ref.channel_id,
|
|
@@ -884,7 +1615,7 @@ function asReplyTarget(value) {
|
|
|
884
1615
|
}
|
|
885
1616
|
async function sendPrepared(message, payload) {
|
|
886
1617
|
const data = await message.client.rest.post(
|
|
887
|
-
|
|
1618
|
+
import_types8.Routes.channelMessages(message.channelId),
|
|
888
1619
|
payload
|
|
889
1620
|
);
|
|
890
1621
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -936,7 +1667,7 @@ function toMessageSnapshot(client, data) {
|
|
|
936
1667
|
function resolveMessageFlags(flags) {
|
|
937
1668
|
if (flags === void 0) return void 0;
|
|
938
1669
|
if (typeof flags === "number") return flags;
|
|
939
|
-
return Number(
|
|
1670
|
+
return Number(import_util5.MessageFlagsBitField.resolve(flags));
|
|
940
1671
|
}
|
|
941
1672
|
var Message = class _Message extends Base {
|
|
942
1673
|
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
@@ -993,6 +1724,8 @@ var Message = class _Message extends Base {
|
|
|
993
1724
|
nonce;
|
|
994
1725
|
/** IDs of custom emojis in the message classified as explicit. */
|
|
995
1726
|
nsfwEmojis;
|
|
1727
|
+
/** Thread started from this message, when the payload included one. */
|
|
1728
|
+
thread;
|
|
996
1729
|
/**
|
|
997
1730
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
998
1731
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1040,14 +1773,14 @@ var Message = class _Message extends Base {
|
|
|
1040
1773
|
this.channelId = data.channel_id;
|
|
1041
1774
|
this.guildId = data.guild_id ?? null;
|
|
1042
1775
|
this.author = client.getOrCreateUser(data.author);
|
|
1043
|
-
this.content = data.content;
|
|
1044
|
-
this.createdAt = new Date(data.timestamp);
|
|
1776
|
+
this.content = data.content ?? "";
|
|
1777
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
1045
1778
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1046
|
-
this.pinned = data.pinned;
|
|
1047
|
-
this.attachments = new
|
|
1779
|
+
this.pinned = data.pinned ?? false;
|
|
1780
|
+
this.attachments = new import_collection5.Collection();
|
|
1048
1781
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1049
|
-
this.type = data.type ??
|
|
1050
|
-
this.flags = new
|
|
1782
|
+
this.type = data.type ?? import_types9.MessageType.Default;
|
|
1783
|
+
this.flags = new import_util5.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1051
1784
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1052
1785
|
this.tts = data.tts ?? false;
|
|
1053
1786
|
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
@@ -1068,39 +1801,55 @@ var Message = class _Message extends Base {
|
|
|
1068
1801
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1069
1802
|
this.nonce = data.nonce ?? null;
|
|
1070
1803
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1804
|
+
this.thread = data.thread ? cacheThread(client, data.thread) : null;
|
|
1071
1805
|
}
|
|
1072
1806
|
/**
|
|
1073
1807
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
1074
1808
|
* @internal
|
|
1075
1809
|
*/
|
|
1076
1810
|
_patch(data) {
|
|
1077
|
-
this.content = data.content;
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
this.
|
|
1088
|
-
this.
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1811
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
1812
|
+
if (data.edited_timestamp !== void 0) {
|
|
1813
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1814
|
+
}
|
|
1815
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
1816
|
+
if (data.attachments !== void 0) {
|
|
1817
|
+
this.attachments.clear();
|
|
1818
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1819
|
+
}
|
|
1820
|
+
if (data.flags !== void 0) this.flags = new import_util5.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1821
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
1822
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
1823
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1824
|
+
if (data.stickers !== void 0) {
|
|
1825
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1826
|
+
}
|
|
1827
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
1828
|
+
if (data.message_reference !== void 0) {
|
|
1829
|
+
this.messageReference = data.message_reference ? {
|
|
1830
|
+
channelId: data.message_reference.channel_id,
|
|
1831
|
+
messageId: data.message_reference.message_id,
|
|
1832
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1833
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1834
|
+
} : null;
|
|
1835
|
+
}
|
|
1836
|
+
if (data.message_snapshots !== void 0) {
|
|
1837
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1838
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
1842
|
+
if (data.referenced_message !== void 0) {
|
|
1843
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1844
|
+
}
|
|
1845
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
1846
|
+
if (data.mentions !== void 0) {
|
|
1847
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1848
|
+
}
|
|
1849
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
1850
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
1851
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1852
|
+
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1104
1853
|
}
|
|
1105
1854
|
/**
|
|
1106
1855
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1161,7 +1910,7 @@ var Message = class _Message extends Base {
|
|
|
1161
1910
|
if (options.attachments !== void 0) {
|
|
1162
1911
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
1163
1912
|
}
|
|
1164
|
-
const data = await this.client.rest.patch(
|
|
1913
|
+
const data = await this.client.rest.patch(import_types9.Routes.channelMessage(this.channelId, this.id), {
|
|
1165
1914
|
body
|
|
1166
1915
|
});
|
|
1167
1916
|
const updated = new _Message(this.client, data);
|
|
@@ -1179,13 +1928,47 @@ var Message = class _Message extends Base {
|
|
|
1179
1928
|
awaitReactions(options) {
|
|
1180
1929
|
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1181
1930
|
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Start a thread from this message.
|
|
1933
|
+
* Fluxer chooses a public or announcement thread from the parent channel.
|
|
1934
|
+
*/
|
|
1935
|
+
async startThread(options) {
|
|
1936
|
+
const data = await this.client.rest.post(
|
|
1937
|
+
import_types9.Routes.channelMessageThreads(this.channelId, this.id),
|
|
1938
|
+
{
|
|
1939
|
+
body: toStartThreadFromMessageBody(options),
|
|
1940
|
+
auth: true,
|
|
1941
|
+
...auditReasonHeaders(options.reason)
|
|
1942
|
+
}
|
|
1943
|
+
);
|
|
1944
|
+
const thread = cacheThread(this.client, data);
|
|
1945
|
+
this.thread = thread;
|
|
1946
|
+
return thread;
|
|
1947
|
+
}
|
|
1182
1948
|
/** Fetch the latest version of this message from the API. */
|
|
1183
1949
|
async fetch() {
|
|
1184
1950
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1185
1951
|
}
|
|
1952
|
+
/** Publish this announcement message to channels following its channel. */
|
|
1953
|
+
async crosspost() {
|
|
1954
|
+
const data = await this.client.rest.post(
|
|
1955
|
+
import_types9.Routes.channelMessageCrosspost(this.channelId, this.id),
|
|
1956
|
+
{ auth: true }
|
|
1957
|
+
);
|
|
1958
|
+
const published = new _Message(this.client, data);
|
|
1959
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
1960
|
+
return published;
|
|
1961
|
+
}
|
|
1962
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
1963
|
+
async fetchCrosspostSource() {
|
|
1964
|
+
return this.client.rest.get(
|
|
1965
|
+
import_types9.Routes.channelMessageCrosspostSource(this.channelId, this.id),
|
|
1966
|
+
{ auth: true }
|
|
1967
|
+
);
|
|
1968
|
+
}
|
|
1186
1969
|
/** Delete this message. */
|
|
1187
1970
|
async delete(reason) {
|
|
1188
|
-
await this.client.rest.delete(
|
|
1971
|
+
await this.client.rest.delete(import_types9.Routes.channelMessage(this.channelId, this.id), {
|
|
1189
1972
|
...auditReasonHeaders(reason)
|
|
1190
1973
|
});
|
|
1191
1974
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
@@ -1193,19 +1976,19 @@ var Message = class _Message extends Base {
|
|
|
1193
1976
|
/** Delete a specific attachment from this message. */
|
|
1194
1977
|
async deleteAttachment(attachmentId) {
|
|
1195
1978
|
await this.client.rest.delete(
|
|
1196
|
-
|
|
1979
|
+
import_types9.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
1197
1980
|
{ auth: true }
|
|
1198
1981
|
);
|
|
1199
1982
|
this.attachments.delete(attachmentId);
|
|
1200
1983
|
}
|
|
1201
1984
|
/** Pin this message in the channel. */
|
|
1202
1985
|
async pin() {
|
|
1203
|
-
await this.client.rest.put(
|
|
1986
|
+
await this.client.rest.put(import_types9.Routes.channelPinMessage(this.channelId, this.id));
|
|
1204
1987
|
this.pinned = true;
|
|
1205
1988
|
}
|
|
1206
1989
|
/** Unpin this message from the channel. */
|
|
1207
1990
|
async unpin() {
|
|
1208
|
-
await this.client.rest.delete(
|
|
1991
|
+
await this.client.rest.delete(import_types9.Routes.channelPinMessage(this.channelId, this.id));
|
|
1209
1992
|
this.pinned = false;
|
|
1210
1993
|
}
|
|
1211
1994
|
/** React to this message with an emoji. */
|
|
@@ -1235,7 +2018,7 @@ var Message = class _Message extends Base {
|
|
|
1235
2018
|
};
|
|
1236
2019
|
|
|
1237
2020
|
// src/Domain/Message/PartialMessage.ts
|
|
1238
|
-
var
|
|
2021
|
+
var import_util6 = require("@fluxerjs/util");
|
|
1239
2022
|
var PartialMessage = class {
|
|
1240
2023
|
partial = true;
|
|
1241
2024
|
client;
|
|
@@ -1254,7 +2037,7 @@ var PartialMessage = class {
|
|
|
1254
2037
|
this.content = data.content ?? null;
|
|
1255
2038
|
this.authorId = data.authorId ?? null;
|
|
1256
2039
|
this.author = data.author ?? null;
|
|
1257
|
-
this.createdAt = data.createdAt ?? (
|
|
2040
|
+
this.createdAt = data.createdAt ?? (import_util6.SnowflakeUtil.isValid(data.id) ? import_util6.SnowflakeUtil.dateFromSnowflake(data.id) : null);
|
|
1258
2041
|
}
|
|
1259
2042
|
/**
|
|
1260
2043
|
* Live text-capable channel from cache, or null if uncached / not text-based.
|