@fluxerjs/core 3.2.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-DW9TgPNl.d.mts → SubpathMessage-CNJlnR6y.d.mts} +2174 -1928
- package/dist/{SubpathMessage-DHo7ltTz.d.ts → SubpathMessage-DjLo6il5.d.ts} +2174 -1928
- 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 +2376 -1413
- package/dist/client.mjs +2346 -1377
- package/dist/cluster.d.mts +2 -2
- package/dist/cluster.d.ts +2 -2
- package/dist/cluster.js +2376 -1413
- package/dist/cluster.mjs +2346 -1377
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1219 -232
- package/dist/index.mjs +1122 -136
- 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 +717 -34
- package/dist/message.mjs +708 -23
- package/package.json +4 -4
package/dist/message.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/Domain/Message/Message.ts
|
|
2
2
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
3
|
-
import { Collection as
|
|
3
|
+
import { Collection as Collection5 } from "@fluxerjs/collection";
|
|
4
4
|
import {
|
|
5
5
|
MessageType,
|
|
6
|
-
Routes as
|
|
6
|
+
Routes as Routes7
|
|
7
7
|
} from "@fluxerjs/types";
|
|
8
8
|
import { MessageFlagsBitField } from "@fluxerjs/util";
|
|
9
9
|
|
|
@@ -21,6 +21,79 @@ function toMessageAttachmentEditWire(attachments) {
|
|
|
21
21
|
return out;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
function toAttachmentUploadPlanBody(attachments) {
|
|
25
|
+
return {
|
|
26
|
+
attachments: attachments.map((a) => ({
|
|
27
|
+
id: a.id,
|
|
28
|
+
filename: a.filename,
|
|
29
|
+
file_size: a.fileSize,
|
|
30
|
+
content_type: a.contentType
|
|
31
|
+
}))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function toAttachmentUploadCompleteBody(uploads) {
|
|
35
|
+
return {
|
|
36
|
+
uploads: uploads.map((u) => ({
|
|
37
|
+
upload_filename: u.uploadFilename,
|
|
38
|
+
upload_id: u.uploadId
|
|
39
|
+
}))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function toAttachmentUploadPlanResponse(data) {
|
|
43
|
+
return {
|
|
44
|
+
attachments: data.attachments.map((item) => {
|
|
45
|
+
const base = {
|
|
46
|
+
id: item.id,
|
|
47
|
+
filename: item.filename,
|
|
48
|
+
uploadFilename: item.upload_filename,
|
|
49
|
+
fileSize: item.file_size,
|
|
50
|
+
contentType: item.content_type
|
|
51
|
+
};
|
|
52
|
+
if (item.upload_mode === "multipart") {
|
|
53
|
+
const parts = (item.parts ?? []).map((p) => ({
|
|
54
|
+
partNumber: p.part_number,
|
|
55
|
+
uploadUrl: p.upload_url
|
|
56
|
+
}));
|
|
57
|
+
return {
|
|
58
|
+
...base,
|
|
59
|
+
uploadMode: "multipart",
|
|
60
|
+
uploadId: item.upload_id ?? "",
|
|
61
|
+
partSize: item.part_size ?? 0,
|
|
62
|
+
parts
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...base,
|
|
67
|
+
uploadMode: "singlepart",
|
|
68
|
+
uploadUrl: item.upload_url ?? ""
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/ClientCore/SdkOptions/Threads.ts
|
|
75
|
+
import {
|
|
76
|
+
ChannelType
|
|
77
|
+
} from "@fluxerjs/types";
|
|
78
|
+
function toStartThreadFromMessageBody(options) {
|
|
79
|
+
const body = { name: options.name };
|
|
80
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
81
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
82
|
+
}
|
|
83
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
84
|
+
return body;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/ClientCore/SdkOptions/Sudo.ts
|
|
88
|
+
function toSudoBody(options) {
|
|
89
|
+
const body = {};
|
|
90
|
+
if (options.password !== void 0) body.password = options.password;
|
|
91
|
+
if (options.mfaMethod !== void 0) body.mfa_method = options.mfaMethod;
|
|
92
|
+
if (options.mfaCode !== void 0) body.mfa_code = options.mfaCode;
|
|
93
|
+
if (options.webauthnResponse !== void 0) body.webauthn_response = options.webauthnResponse;
|
|
94
|
+
if (options.webauthnChallenge !== void 0) body.webauthn_challenge = options.webauthnChallenge;
|
|
95
|
+
return body;
|
|
96
|
+
}
|
|
24
97
|
|
|
25
98
|
// src/Helpers/AuditReason.ts
|
|
26
99
|
var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
|
|
@@ -412,6 +485,14 @@ var Events = {
|
|
|
412
485
|
ChannelCreate: "channelCreate",
|
|
413
486
|
ChannelUpdate: "channelUpdate",
|
|
414
487
|
ChannelDelete: "channelDelete",
|
|
488
|
+
ThreadCreate: "threadCreate",
|
|
489
|
+
ThreadUpdate: "threadUpdate",
|
|
490
|
+
ThreadDelete: "threadDelete",
|
|
491
|
+
ThreadListSync: "threadListSync",
|
|
492
|
+
ThreadMemberUpdate: "threadMemberUpdate",
|
|
493
|
+
ThreadMembersUpdate: "threadMembersUpdate",
|
|
494
|
+
ThreadMemberListUpdate: "threadMemberListUpdate",
|
|
495
|
+
ForumUnreads: "forumUnreads",
|
|
415
496
|
ChannelPinsUpdate: "channelPinsUpdate",
|
|
416
497
|
ChannelRecipientAdd: "channelRecipientAdd",
|
|
417
498
|
ChannelRecipientRemove: "channelRecipientRemove",
|
|
@@ -549,6 +630,589 @@ var ReactionCollector = class _ReactionCollector extends EventEmitter {
|
|
|
549
630
|
}
|
|
550
631
|
};
|
|
551
632
|
|
|
633
|
+
// src/Domain/Channel/Base.ts
|
|
634
|
+
import { ChannelType as ChannelType2, Routes as Routes4 } from "@fluxerjs/types";
|
|
635
|
+
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
636
|
+
|
|
637
|
+
// src/ClientCore/MessageManager.ts
|
|
638
|
+
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
639
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
640
|
+
var MessageManager = class {
|
|
641
|
+
constructor(client, channelId) {
|
|
642
|
+
this.client = client;
|
|
643
|
+
this.channelId = channelId;
|
|
644
|
+
}
|
|
645
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
646
|
+
_structures = new Collection2();
|
|
647
|
+
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
648
|
+
get(messageId) {
|
|
649
|
+
const data = this.client._getMessageCache(this.channelId)?.get(messageId);
|
|
650
|
+
if (!data) {
|
|
651
|
+
this._structures.delete(messageId);
|
|
652
|
+
return void 0;
|
|
653
|
+
}
|
|
654
|
+
const existing = this._structures.get(messageId);
|
|
655
|
+
if (existing) return existing;
|
|
656
|
+
const message = new Message(this.client, data);
|
|
657
|
+
this._structures.set(messageId, message);
|
|
658
|
+
return message;
|
|
659
|
+
}
|
|
660
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
661
|
+
async resolve(messageId) {
|
|
662
|
+
return this.get(messageId) ?? this.fetch(messageId);
|
|
663
|
+
}
|
|
664
|
+
async fetch(idOrOptions) {
|
|
665
|
+
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
666
|
+
}
|
|
667
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
668
|
+
wrap(data) {
|
|
669
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
670
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
671
|
+
const existing = this._structures.get(data.id);
|
|
672
|
+
if (existing) {
|
|
673
|
+
existing._patch(cached);
|
|
674
|
+
return existing;
|
|
675
|
+
}
|
|
676
|
+
const message = new Message(this.client, cached);
|
|
677
|
+
this._structures.set(data.id, message);
|
|
678
|
+
return message;
|
|
679
|
+
}
|
|
680
|
+
/** Fetch a single message from the API. */
|
|
681
|
+
async fetchOne(messageId) {
|
|
682
|
+
try {
|
|
683
|
+
const data = await this.client.rest.get(
|
|
684
|
+
Routes2.channelMessage(this.channelId, messageId)
|
|
685
|
+
);
|
|
686
|
+
return this.wrap(data);
|
|
687
|
+
} catch (err) {
|
|
688
|
+
rethrowMapped(err, {
|
|
689
|
+
notFound: {
|
|
690
|
+
code: ErrorCodes.MessageNotFound,
|
|
691
|
+
message: `Message ${messageId} not found in channel ${this.channelId}`
|
|
692
|
+
},
|
|
693
|
+
fallback: `Failed to fetch message ${messageId}`
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
/** Fetch multiple messages from the API with pagination/filtering. */
|
|
698
|
+
async fetchMany(options) {
|
|
699
|
+
if (options.limit != null && (options.limit < 1 || options.limit > 100)) {
|
|
700
|
+
throw new FluxerError("limit must be between 1 and 100", {
|
|
701
|
+
code: ErrorCodes.InvalidFetchLimit
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
const qs = new URLSearchParams();
|
|
705
|
+
for (const key of ["limit", "before", "after", "around"]) {
|
|
706
|
+
const value = options[key];
|
|
707
|
+
if (value != null && value !== "") qs.set(key, String(value));
|
|
708
|
+
}
|
|
709
|
+
const base = Routes2.channelMessages(this.channelId);
|
|
710
|
+
const data = await this.client.rest.get(qs.size > 0 ? `${base}?${qs}` : base);
|
|
711
|
+
const collection = new Collection2();
|
|
712
|
+
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
713
|
+
return collection;
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// src/Helpers/MessageCollector.ts
|
|
718
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
719
|
+
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
720
|
+
function requireCollectorBounds(options) {
|
|
721
|
+
const time = options.time ?? 0;
|
|
722
|
+
const max = options.max ?? 0;
|
|
723
|
+
if (time <= 0 && max <= 0) {
|
|
724
|
+
throw new FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
725
|
+
code: ErrorCodes.CollectorOptionsRequired
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
var MessageCollector = class _MessageCollector extends EventEmitter2 {
|
|
730
|
+
client;
|
|
731
|
+
channelId;
|
|
732
|
+
options;
|
|
733
|
+
collected = new Collection3();
|
|
734
|
+
_timeout = null;
|
|
735
|
+
_ended = false;
|
|
736
|
+
_listener;
|
|
737
|
+
constructor(client, channelId, options = {}) {
|
|
738
|
+
super();
|
|
739
|
+
requireCollectorBounds(options);
|
|
740
|
+
this.client = client;
|
|
741
|
+
this.channelId = channelId;
|
|
742
|
+
this.options = {
|
|
743
|
+
filter: options.filter ?? (() => true),
|
|
744
|
+
time: options.time ?? 0,
|
|
745
|
+
max: options.max ?? 0
|
|
746
|
+
};
|
|
747
|
+
this._listener = (message) => {
|
|
748
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
749
|
+
if (!this.options.filter(message)) return;
|
|
750
|
+
this.collected.set(message.id, message);
|
|
751
|
+
this.emit("collect", message);
|
|
752
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
753
|
+
this.stop("limit");
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
757
|
+
if (this.options.time > 0) {
|
|
758
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
stop(reason = "user") {
|
|
762
|
+
if (this._ended) return;
|
|
763
|
+
this._ended = true;
|
|
764
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
765
|
+
if (this._timeout) {
|
|
766
|
+
clearTimeout(this._timeout);
|
|
767
|
+
this._timeout = null;
|
|
768
|
+
}
|
|
769
|
+
this.emit("end", this.collected, reason);
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
773
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
774
|
+
* the end reason is not listed in `errors`).
|
|
775
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
776
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
777
|
+
*/
|
|
778
|
+
static awaitMessages(client, channelId, options) {
|
|
779
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
780
|
+
return new Promise((resolve, reject) => {
|
|
781
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
782
|
+
collector.on("end", (collected, reason) => {
|
|
783
|
+
if (!errors.includes(reason)) {
|
|
784
|
+
resolve(collected);
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (reason === "time") {
|
|
788
|
+
reject(
|
|
789
|
+
new FluxerError("Message collector timed out", {
|
|
790
|
+
code: ErrorCodes.CollectorIdle
|
|
791
|
+
})
|
|
792
|
+
);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (reason === "limit") {
|
|
796
|
+
reject(
|
|
797
|
+
new FluxerError("Message collector reached max", {
|
|
798
|
+
code: ErrorCodes.CollectorMax
|
|
799
|
+
})
|
|
800
|
+
);
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
reject(collected);
|
|
804
|
+
});
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
on(event, listener) {
|
|
808
|
+
return super.on(event, listener);
|
|
809
|
+
}
|
|
810
|
+
emit(event, ...args) {
|
|
811
|
+
return super.emit(event, ...args);
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
// src/Domain/Channel/Attachments.ts
|
|
816
|
+
import { Routes as Routes3 } from "@fluxerjs/types";
|
|
817
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
818
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
819
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
820
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
821
|
+
if (!rules?.length) return null;
|
|
822
|
+
const snapshot = {};
|
|
823
|
+
for (const rule of rules) {
|
|
824
|
+
Object.assign(snapshot, rule.overrides);
|
|
825
|
+
}
|
|
826
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
827
|
+
}
|
|
828
|
+
function assertBotAttachmentLimits(client, files) {
|
|
829
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
830
|
+
for (const file of files) {
|
|
831
|
+
const size = file.data.byteLength;
|
|
832
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
833
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
834
|
+
throw new FluxerError(
|
|
835
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
836
|
+
{ code: ErrorCodes.AttachmentTooLarge }
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
function asBytes(data) {
|
|
841
|
+
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
842
|
+
const out = new Uint8Array(src.byteLength);
|
|
843
|
+
out.set(src);
|
|
844
|
+
return out;
|
|
845
|
+
}
|
|
846
|
+
async function putBlob(url, body, contentType) {
|
|
847
|
+
const res = await fetch(url, {
|
|
848
|
+
method: "PUT",
|
|
849
|
+
headers: contentType ? { "Content-Type": contentType } : void 0,
|
|
850
|
+
body
|
|
851
|
+
});
|
|
852
|
+
if (!res.ok) {
|
|
853
|
+
throw new FluxerError(`Presigned upload failed: ${res.status}`, {
|
|
854
|
+
code: ErrorCodes.AttachmentUploadFailed
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
859
|
+
assertBotAttachmentLimits(client, files);
|
|
860
|
+
const plan = await client.rest.post(
|
|
861
|
+
Routes3.channelAttachments(channelId),
|
|
862
|
+
{
|
|
863
|
+
body: {
|
|
864
|
+
attachments: files.map((f) => ({
|
|
865
|
+
id: f.id,
|
|
866
|
+
filename: f.filename,
|
|
867
|
+
file_size: f.data.byteLength,
|
|
868
|
+
content_type: f.contentType
|
|
869
|
+
}))
|
|
870
|
+
},
|
|
871
|
+
auth: true
|
|
872
|
+
}
|
|
873
|
+
);
|
|
874
|
+
const multipart = [];
|
|
875
|
+
const uploaded = [];
|
|
876
|
+
for (const item of plan.attachments) {
|
|
877
|
+
const file = files.find((f) => f.id === item.id);
|
|
878
|
+
if (!file) {
|
|
879
|
+
throw new FluxerError(`No file data for planned attachment id ${item.id}`, {
|
|
880
|
+
code: ErrorCodes.InvalidAttachmentInput
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
const bytes = asBytes(file.data);
|
|
884
|
+
if (item.upload_mode === "singlepart") {
|
|
885
|
+
await putBlob(
|
|
886
|
+
item.upload_url,
|
|
887
|
+
new Blob([bytes], { type: file.contentType }),
|
|
888
|
+
item.content_type
|
|
889
|
+
);
|
|
890
|
+
} else {
|
|
891
|
+
for (const part of item.parts) {
|
|
892
|
+
const start = (part.part_number - 1) * item.part_size;
|
|
893
|
+
const chunk = bytes.subarray(start, Math.min(start + item.part_size, bytes.byteLength));
|
|
894
|
+
await putBlob(part.upload_url, new Blob([asBytes(chunk)]));
|
|
895
|
+
}
|
|
896
|
+
multipart.push({ upload_filename: item.upload_filename, upload_id: item.upload_id });
|
|
897
|
+
}
|
|
898
|
+
uploaded.push({
|
|
899
|
+
id: item.id,
|
|
900
|
+
filename: item.filename,
|
|
901
|
+
upload_filename: item.upload_filename,
|
|
902
|
+
file_size: item.file_size,
|
|
903
|
+
content_type: item.content_type
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
if (multipart.length) {
|
|
907
|
+
await client.rest.post(Routes3.channelAttachmentsComplete(channelId), {
|
|
908
|
+
body: { uploads: multipart },
|
|
909
|
+
auth: true
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
return uploaded;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// src/Domain/Channel/Base.ts
|
|
916
|
+
var Channel = class extends Base {
|
|
917
|
+
#messages;
|
|
918
|
+
/** The {@link Client} that instantiated this channel. */
|
|
919
|
+
client;
|
|
920
|
+
/** Snowflake ID of this channel. */
|
|
921
|
+
id;
|
|
922
|
+
/** Channel type (text, voice, category, etc.). */
|
|
923
|
+
type;
|
|
924
|
+
/** Channel name (null for some channel types). */
|
|
925
|
+
name;
|
|
926
|
+
/** Channel icon hash (null for most channel types). */
|
|
927
|
+
icon;
|
|
928
|
+
/** ISO8601 timestamp of the last pinned message update. */
|
|
929
|
+
lastPinTimestamp;
|
|
930
|
+
constructor(client, data) {
|
|
931
|
+
super();
|
|
932
|
+
this.client = client;
|
|
933
|
+
this.id = data.id;
|
|
934
|
+
this.type = data.type;
|
|
935
|
+
this.name = data.name ?? null;
|
|
936
|
+
this.icon = data.icon ?? null;
|
|
937
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
938
|
+
}
|
|
939
|
+
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
940
|
+
get createdTimestamp() {
|
|
941
|
+
return SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
942
|
+
}
|
|
943
|
+
/** Date when this channel was created, derived from its snowflake ID. */
|
|
944
|
+
get createdAt() {
|
|
945
|
+
return SnowflakeUtil.dateFromSnowflake(this.id);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
949
|
+
* @internal
|
|
950
|
+
*/
|
|
951
|
+
_patch(data) {
|
|
952
|
+
if (data.type !== void 0) this.type = data.type;
|
|
953
|
+
if (data.name !== void 0) this.name = data.name ?? null;
|
|
954
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
955
|
+
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
956
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
/** @internal Factory wired after subclasses load. */
|
|
960
|
+
static from(_c, _d) {
|
|
961
|
+
throw new Error("Channel.from not initialized");
|
|
962
|
+
}
|
|
963
|
+
/** @internal Factory wired after subclasses load. */
|
|
964
|
+
static fromOrCreate(_c, _d) {
|
|
965
|
+
throw new Error("Channel.fromOrCreate not initialized");
|
|
966
|
+
}
|
|
967
|
+
/** @internal Factory wired after subclasses load. */
|
|
968
|
+
static createDM(_c, _d) {
|
|
969
|
+
throw new Error("Channel.createDM not initialized");
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
|
|
973
|
+
* Forum and media channels contain threads and do not accept `send`.
|
|
974
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
975
|
+
*/
|
|
976
|
+
isTextBased() {
|
|
977
|
+
return this.type === ChannelType2.GuildText || this.type === ChannelType2.GuildAnnouncement || this.type === ChannelType2.GuildVoice || this.type === ChannelType2.DM || this.type === ChannelType2.GroupDM || this.type === ChannelType2.DMPersonalNotes || this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread;
|
|
978
|
+
}
|
|
979
|
+
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
980
|
+
isGuild() {
|
|
981
|
+
return this.type === ChannelType2.GuildText || this.type === ChannelType2.GuildAnnouncement || this.type === ChannelType2.GuildVoice || this.type === ChannelType2.GuildCategory || this.type === ChannelType2.GuildLink || this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread || this.type === ChannelType2.GuildForum || this.type === ChannelType2.GuildMedia;
|
|
982
|
+
}
|
|
983
|
+
/** Check if this is a thread (public, private, or announcement). */
|
|
984
|
+
isThread() {
|
|
985
|
+
return this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread;
|
|
986
|
+
}
|
|
987
|
+
/** Check if this is a forum channel. */
|
|
988
|
+
isForum() {
|
|
989
|
+
return this.type === ChannelType2.GuildForum;
|
|
990
|
+
}
|
|
991
|
+
/** Check if this is a media channel. */
|
|
992
|
+
isMedia() {
|
|
993
|
+
return this.type === ChannelType2.GuildMedia;
|
|
994
|
+
}
|
|
995
|
+
/** Check if this is a guild text channel. */
|
|
996
|
+
isText() {
|
|
997
|
+
return this.type === ChannelType2.GuildText;
|
|
998
|
+
}
|
|
999
|
+
/** Check if this is a guild announcement channel. */
|
|
1000
|
+
isAnnouncement() {
|
|
1001
|
+
return this.type === ChannelType2.GuildAnnouncement;
|
|
1002
|
+
}
|
|
1003
|
+
/** Check if this is a category channel. */
|
|
1004
|
+
isCategory() {
|
|
1005
|
+
return this.type === ChannelType2.GuildCategory;
|
|
1006
|
+
}
|
|
1007
|
+
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1008
|
+
isDM() {
|
|
1009
|
+
return this.type === ChannelType2.DM || this.type === ChannelType2.GroupDM || this.type === ChannelType2.DMPersonalNotes;
|
|
1010
|
+
}
|
|
1011
|
+
/** Check if this is a personal notes channel. */
|
|
1012
|
+
isPersonalNotes() {
|
|
1013
|
+
return this.type === ChannelType2.DMPersonalNotes;
|
|
1014
|
+
}
|
|
1015
|
+
/** Check if this is a voice channel. */
|
|
1016
|
+
isVoice() {
|
|
1017
|
+
return this.type === ChannelType2.GuildVoice;
|
|
1018
|
+
}
|
|
1019
|
+
/** Check if this is a link channel. */
|
|
1020
|
+
isLink() {
|
|
1021
|
+
return this.type === ChannelType2.GuildLink;
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Delete recent messages or an explicit ID list.
|
|
1025
|
+
* - `bulkDelete(5)` — fetch last 5 via {@link MessageManager} then delete (1–100)
|
|
1026
|
+
* - `bulkDelete(['id1'])` — single DELETE; 2–100 uses bulk-delete route
|
|
1027
|
+
*/
|
|
1028
|
+
async bulkDelete(countOrIds) {
|
|
1029
|
+
let ids;
|
|
1030
|
+
if (typeof countOrIds === "number") {
|
|
1031
|
+
if (!Number.isInteger(countOrIds) || countOrIds < 1 || countOrIds > 100) {
|
|
1032
|
+
throw new FluxerError("bulkDelete count must be between 1 and 100", {
|
|
1033
|
+
code: ErrorCodes.InvalidBulkDelete
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
ids = [
|
|
1037
|
+
...(await new MessageManager(this.client, this.id).fetch({ limit: countOrIds })).keys()
|
|
1038
|
+
];
|
|
1039
|
+
} else {
|
|
1040
|
+
ids = [...countOrIds];
|
|
1041
|
+
}
|
|
1042
|
+
if (ids.length === 0) return [];
|
|
1043
|
+
if (ids.length === 1) {
|
|
1044
|
+
await this.client.rest.delete(Routes4.channelMessage(this.id, ids[0]), { auth: true });
|
|
1045
|
+
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
1046
|
+
return ids;
|
|
1047
|
+
}
|
|
1048
|
+
if (ids.length > 100) {
|
|
1049
|
+
throw new FluxerError("bulkDelete requires at most 100 message IDs", {
|
|
1050
|
+
code: ErrorCodes.InvalidBulkDelete
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
await this.client.rest.post(Routes4.channelBulkDelete(this.id), {
|
|
1054
|
+
body: { message_ids: ids },
|
|
1055
|
+
auth: true
|
|
1056
|
+
});
|
|
1057
|
+
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1058
|
+
return ids;
|
|
1059
|
+
}
|
|
1060
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1061
|
+
async bulkDeleteMyMessages(options) {
|
|
1062
|
+
const body = options ? toSudoBody(options) : void 0;
|
|
1063
|
+
await this.client.rest.post(Routes4.channelBulkDeleteMine(this.id), {
|
|
1064
|
+
body: body && Object.keys(body).length ? body : void 0,
|
|
1065
|
+
auth: true
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Mark all pinned messages as read in this channel.
|
|
1070
|
+
* Session-token helper; bots usually skip this.
|
|
1071
|
+
*/
|
|
1072
|
+
async acknowledgePins() {
|
|
1073
|
+
await this.client.rest.post(Routes4.channelPinsAck(this.id), { auth: true });
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Clear the read state for this channel.
|
|
1077
|
+
* Session-token helper; bots usually skip this.
|
|
1078
|
+
*/
|
|
1079
|
+
async clearReadState() {
|
|
1080
|
+
await this.client.rest.delete(Routes4.channelMessagesAck(this.id), { auth: true });
|
|
1081
|
+
}
|
|
1082
|
+
/** Request upload URLs for attachments before sending a message. */
|
|
1083
|
+
async requestAttachmentUploads(attachments) {
|
|
1084
|
+
const data = await this.client.rest.post(
|
|
1085
|
+
Routes4.channelAttachments(this.id),
|
|
1086
|
+
{
|
|
1087
|
+
body: toAttachmentUploadPlanBody(attachments),
|
|
1088
|
+
auth: true
|
|
1089
|
+
}
|
|
1090
|
+
);
|
|
1091
|
+
return toAttachmentUploadPlanResponse(data);
|
|
1092
|
+
}
|
|
1093
|
+
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
1094
|
+
async completeAttachmentUploads(uploads) {
|
|
1095
|
+
const data = await this.client.rest.post(
|
|
1096
|
+
Routes4.channelAttachmentsComplete(this.id),
|
|
1097
|
+
{
|
|
1098
|
+
body: toAttachmentUploadCompleteBody(uploads),
|
|
1099
|
+
auth: true
|
|
1100
|
+
}
|
|
1101
|
+
);
|
|
1102
|
+
return {
|
|
1103
|
+
uploads: data.uploads.map((u) => ({ uploadFilename: u.upload_filename }))
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
/** Upload files for sending in a message (helper). */
|
|
1107
|
+
async uploadAttachmentsForSend(files) {
|
|
1108
|
+
return uploadAttachmentsForSend(this.client, this.id, files);
|
|
1109
|
+
}
|
|
1110
|
+
/** Trigger the typing indicator in this channel. */
|
|
1111
|
+
async sendTyping() {
|
|
1112
|
+
await this.client.rest.post(Routes4.channelTyping(this.id), { auth: true });
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Fetch available RTC regions for voice channels.
|
|
1116
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
1117
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
1118
|
+
*/
|
|
1119
|
+
async fetchRtcRegions() {
|
|
1120
|
+
const data = await this.client.rest.get(Routes4.channelRtcRegions(this.id), {
|
|
1121
|
+
auth: true
|
|
1122
|
+
});
|
|
1123
|
+
return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
|
|
1124
|
+
}
|
|
1125
|
+
/** Fetch slowmode state for this channel. */
|
|
1126
|
+
async fetchSlowmode() {
|
|
1127
|
+
const data = await this.client.rest.get(
|
|
1128
|
+
Routes4.channelSlowmode(this.id),
|
|
1129
|
+
{ auth: true }
|
|
1130
|
+
);
|
|
1131
|
+
return {
|
|
1132
|
+
rateLimitPerUser: data.rate_limit_per_user,
|
|
1133
|
+
retryAfterMs: data.retry_after_ms,
|
|
1134
|
+
nextSendAllowedAt: data.next_send_allowed_at
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1138
|
+
canSendMessage() {
|
|
1139
|
+
return this.isTextBased();
|
|
1140
|
+
}
|
|
1141
|
+
/** Per-channel message cache + fetch. */
|
|
1142
|
+
get messages() {
|
|
1143
|
+
if (!this.#messages) {
|
|
1144
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1145
|
+
}
|
|
1146
|
+
return this.#messages;
|
|
1147
|
+
}
|
|
1148
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
1149
|
+
createMessageCollector(options) {
|
|
1150
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
1154
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1155
|
+
* @example
|
|
1156
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
1157
|
+
*/
|
|
1158
|
+
awaitMessages(options) {
|
|
1159
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Delete this channel (or close it if it is a DM).
|
|
1163
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
1164
|
+
* @example
|
|
1165
|
+
* const channel = await client.channels.fetch(channelId);
|
|
1166
|
+
* await channel.delete();
|
|
1167
|
+
*/
|
|
1168
|
+
async delete(options) {
|
|
1169
|
+
const params = new URLSearchParams();
|
|
1170
|
+
if (options?.silent) params.set("silent", "true");
|
|
1171
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
1172
|
+
const qs = params.toString();
|
|
1173
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
1174
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
1175
|
+
await this.client.rest.delete(Routes4.channel(this.id) + (qs ? `?${qs}` : ""), {
|
|
1176
|
+
body,
|
|
1177
|
+
auth: true,
|
|
1178
|
+
...auditReasonHeaders(_reason)
|
|
1179
|
+
});
|
|
1180
|
+
this.client.channels.delete(this.id);
|
|
1181
|
+
this.client._clearMessageCache(this.id);
|
|
1182
|
+
if (this.isGuild() && this.guildId) {
|
|
1183
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
/** Channel mention (`<#id>`). */
|
|
1187
|
+
toString() {
|
|
1188
|
+
return `<#${this.id}>`;
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
// src/Domain/Channel/ThreadCache.ts
|
|
1193
|
+
function cacheThread(client, data) {
|
|
1194
|
+
const existing = client.channels.get(data.id);
|
|
1195
|
+
if (existing?.isThread() && existing.type === data.type) {
|
|
1196
|
+
existing._patch(data);
|
|
1197
|
+
placeThread(client, existing);
|
|
1198
|
+
return existing;
|
|
1199
|
+
}
|
|
1200
|
+
const created = Channel.from(client, data);
|
|
1201
|
+
if (!created.isThread()) {
|
|
1202
|
+
throw new FluxerError(`Channel ${data.id} is not a thread`, {
|
|
1203
|
+
code: ErrorCodes.InvalidChannelType
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
placeThread(client, created);
|
|
1207
|
+
return created;
|
|
1208
|
+
}
|
|
1209
|
+
function placeThread(client, thread) {
|
|
1210
|
+
client.channels.set(thread.id, thread);
|
|
1211
|
+
if (!thread.guildId) return;
|
|
1212
|
+
const guild = client.guilds.get(thread.guildId);
|
|
1213
|
+
if (guild) guild.channels.set(thread.id, thread);
|
|
1214
|
+
}
|
|
1215
|
+
|
|
552
1216
|
// src/Domain/Message/Attachment.ts
|
|
553
1217
|
function toMessageAttachment(data) {
|
|
554
1218
|
return {
|
|
@@ -633,12 +1297,12 @@ function toMessageEmbed(data) {
|
|
|
633
1297
|
}
|
|
634
1298
|
|
|
635
1299
|
// src/Domain/Message/MessageReactionManager.ts
|
|
636
|
-
import { Collection as
|
|
1300
|
+
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
637
1301
|
var MessageReactionManager = class {
|
|
638
1302
|
constructor(message) {
|
|
639
1303
|
this.message = message;
|
|
640
1304
|
}
|
|
641
|
-
_cache = new
|
|
1305
|
+
_cache = new Collection4();
|
|
642
1306
|
/** Reactions keyed by unicode name or `name:id`. */
|
|
643
1307
|
get cache() {
|
|
644
1308
|
return this._cache;
|
|
@@ -660,7 +1324,7 @@ var MessageReactionManager = class {
|
|
|
660
1324
|
};
|
|
661
1325
|
|
|
662
1326
|
// src/Domain/Message/MessageSticker.ts
|
|
663
|
-
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
1327
|
+
import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
|
|
664
1328
|
|
|
665
1329
|
// src/Helpers/Constants.ts
|
|
666
1330
|
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
@@ -767,36 +1431,36 @@ var MessageSticker = class extends Base {
|
|
|
767
1431
|
}
|
|
768
1432
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
769
1433
|
get createdTimestamp() {
|
|
770
|
-
return
|
|
1434
|
+
return SnowflakeUtil2.timestampFromSnowflake(this.id);
|
|
771
1435
|
}
|
|
772
1436
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
773
1437
|
get createdAt() {
|
|
774
|
-
return
|
|
1438
|
+
return SnowflakeUtil2.dateFromSnowflake(this.id);
|
|
775
1439
|
}
|
|
776
1440
|
};
|
|
777
1441
|
|
|
778
1442
|
// src/Domain/Message/Reactions.ts
|
|
779
|
-
import { Routes as
|
|
1443
|
+
import { Routes as Routes5 } from "@fluxerjs/types";
|
|
780
1444
|
async function emojiPath(message, emoji) {
|
|
781
1445
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
782
1446
|
}
|
|
783
1447
|
async function reactToMessage(message, emoji) {
|
|
784
1448
|
const wire = await emojiPath(message, emoji);
|
|
785
1449
|
await message.client.rest.put(
|
|
786
|
-
|
|
1450
|
+
Routes5.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
787
1451
|
);
|
|
788
1452
|
}
|
|
789
1453
|
async function removeMessageReaction(message, emoji, userId) {
|
|
790
1454
|
const e = await emojiPath(message, emoji);
|
|
791
|
-
const route = userId ?
|
|
1455
|
+
const route = userId ? Routes5.channelMessageReactionUser(message.channelId, message.id, e, userId) : Routes5.channelMessageReactionMe(message.channelId, message.id, e);
|
|
792
1456
|
await message.client.rest.delete(route);
|
|
793
1457
|
}
|
|
794
1458
|
async function removeAllMessageReactions(message) {
|
|
795
|
-
await message.client.rest.delete(
|
|
1459
|
+
await message.client.rest.delete(Routes5.channelMessageReactions(message.channelId, message.id));
|
|
796
1460
|
}
|
|
797
1461
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
798
1462
|
const e = await emojiPath(message, emoji);
|
|
799
|
-
await message.client.rest.delete(
|
|
1463
|
+
await message.client.rest.delete(Routes5.channelMessageReaction(message.channelId, message.id, e));
|
|
800
1464
|
}
|
|
801
1465
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
802
1466
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -807,7 +1471,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
807
1471
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
808
1472
|
if (options?.after) params.set("after", options.after);
|
|
809
1473
|
const qs = params.toString();
|
|
810
|
-
const route =
|
|
1474
|
+
const route = Routes5.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
|
|
811
1475
|
const data = await message.client.rest.get(route);
|
|
812
1476
|
if (Array.isArray(data)) {
|
|
813
1477
|
return {
|
|
@@ -826,7 +1490,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
826
1490
|
|
|
827
1491
|
// src/Domain/Message/Send.ts
|
|
828
1492
|
import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
|
|
829
|
-
import { Routes as
|
|
1493
|
+
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
830
1494
|
function toReplyTarget(ref) {
|
|
831
1495
|
return {
|
|
832
1496
|
channelId: ref.channel_id,
|
|
@@ -860,7 +1524,7 @@ function asReplyTarget(value) {
|
|
|
860
1524
|
}
|
|
861
1525
|
async function sendPrepared(message, payload) {
|
|
862
1526
|
const data = await message.client.rest.post(
|
|
863
|
-
|
|
1527
|
+
Routes6.channelMessages(message.channelId),
|
|
864
1528
|
payload
|
|
865
1529
|
);
|
|
866
1530
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -969,6 +1633,8 @@ var Message = class _Message extends Base {
|
|
|
969
1633
|
nonce;
|
|
970
1634
|
/** IDs of custom emojis in the message classified as explicit. */
|
|
971
1635
|
nsfwEmojis;
|
|
1636
|
+
/** Thread started from this message, when the payload included one. */
|
|
1637
|
+
thread;
|
|
972
1638
|
/**
|
|
973
1639
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
974
1640
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1020,7 +1686,7 @@ var Message = class _Message extends Base {
|
|
|
1020
1686
|
this.createdAt = new Date(data.timestamp);
|
|
1021
1687
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1022
1688
|
this.pinned = data.pinned;
|
|
1023
|
-
this.attachments = new
|
|
1689
|
+
this.attachments = new Collection5();
|
|
1024
1690
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1025
1691
|
this.type = data.type ?? MessageType.Default;
|
|
1026
1692
|
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
@@ -1044,6 +1710,7 @@ var Message = class _Message extends Base {
|
|
|
1044
1710
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1045
1711
|
this.nonce = data.nonce ?? null;
|
|
1046
1712
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1713
|
+
this.thread = data.thread ? cacheThread(client, data.thread) : null;
|
|
1047
1714
|
}
|
|
1048
1715
|
/**
|
|
1049
1716
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
@@ -1077,6 +1744,7 @@ var Message = class _Message extends Base {
|
|
|
1077
1744
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1078
1745
|
this.nonce = data.nonce ?? null;
|
|
1079
1746
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1747
|
+
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1080
1748
|
}
|
|
1081
1749
|
/**
|
|
1082
1750
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1137,7 +1805,7 @@ var Message = class _Message extends Base {
|
|
|
1137
1805
|
if (options.attachments !== void 0) {
|
|
1138
1806
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
1139
1807
|
}
|
|
1140
|
-
const data = await this.client.rest.patch(
|
|
1808
|
+
const data = await this.client.rest.patch(Routes7.channelMessage(this.channelId, this.id), {
|
|
1141
1809
|
body
|
|
1142
1810
|
});
|
|
1143
1811
|
const updated = new _Message(this.client, data);
|
|
@@ -1155,13 +1823,30 @@ var Message = class _Message extends Base {
|
|
|
1155
1823
|
awaitReactions(options) {
|
|
1156
1824
|
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1157
1825
|
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Start a thread from this message.
|
|
1828
|
+
* Fluxer chooses a public or announcement thread from the parent channel.
|
|
1829
|
+
*/
|
|
1830
|
+
async startThread(options) {
|
|
1831
|
+
const data = await this.client.rest.post(
|
|
1832
|
+
Routes7.channelMessageThreads(this.channelId, this.id),
|
|
1833
|
+
{
|
|
1834
|
+
body: toStartThreadFromMessageBody(options),
|
|
1835
|
+
auth: true,
|
|
1836
|
+
...auditReasonHeaders(options.reason)
|
|
1837
|
+
}
|
|
1838
|
+
);
|
|
1839
|
+
const thread = cacheThread(this.client, data);
|
|
1840
|
+
this.thread = thread;
|
|
1841
|
+
return thread;
|
|
1842
|
+
}
|
|
1158
1843
|
/** Fetch the latest version of this message from the API. */
|
|
1159
1844
|
async fetch() {
|
|
1160
1845
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1161
1846
|
}
|
|
1162
1847
|
/** Delete this message. */
|
|
1163
1848
|
async delete(reason) {
|
|
1164
|
-
await this.client.rest.delete(
|
|
1849
|
+
await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
|
|
1165
1850
|
...auditReasonHeaders(reason)
|
|
1166
1851
|
});
|
|
1167
1852
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
@@ -1169,19 +1854,19 @@ var Message = class _Message extends Base {
|
|
|
1169
1854
|
/** Delete a specific attachment from this message. */
|
|
1170
1855
|
async deleteAttachment(attachmentId) {
|
|
1171
1856
|
await this.client.rest.delete(
|
|
1172
|
-
|
|
1857
|
+
Routes7.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
1173
1858
|
{ auth: true }
|
|
1174
1859
|
);
|
|
1175
1860
|
this.attachments.delete(attachmentId);
|
|
1176
1861
|
}
|
|
1177
1862
|
/** Pin this message in the channel. */
|
|
1178
1863
|
async pin() {
|
|
1179
|
-
await this.client.rest.put(
|
|
1864
|
+
await this.client.rest.put(Routes7.channelPinMessage(this.channelId, this.id));
|
|
1180
1865
|
this.pinned = true;
|
|
1181
1866
|
}
|
|
1182
1867
|
/** Unpin this message from the channel. */
|
|
1183
1868
|
async unpin() {
|
|
1184
|
-
await this.client.rest.delete(
|
|
1869
|
+
await this.client.rest.delete(Routes7.channelPinMessage(this.channelId, this.id));
|
|
1185
1870
|
this.pinned = false;
|
|
1186
1871
|
}
|
|
1187
1872
|
/** React to this message with an emoji. */
|
|
@@ -1211,7 +1896,7 @@ var Message = class _Message extends Base {
|
|
|
1211
1896
|
};
|
|
1212
1897
|
|
|
1213
1898
|
// src/Domain/Message/PartialMessage.ts
|
|
1214
|
-
import { SnowflakeUtil as
|
|
1899
|
+
import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
|
|
1215
1900
|
var PartialMessage = class {
|
|
1216
1901
|
partial = true;
|
|
1217
1902
|
client;
|
|
@@ -1230,7 +1915,7 @@ var PartialMessage = class {
|
|
|
1230
1915
|
this.content = data.content ?? null;
|
|
1231
1916
|
this.authorId = data.authorId ?? null;
|
|
1232
1917
|
this.author = data.author ?? null;
|
|
1233
|
-
this.createdAt = data.createdAt ?? (
|
|
1918
|
+
this.createdAt = data.createdAt ?? (SnowflakeUtil3.isValid(data.id) ? SnowflakeUtil3.dateFromSnowflake(data.id) : null);
|
|
1234
1919
|
}
|
|
1235
1920
|
/**
|
|
1236
1921
|
* Live text-capable channel from cache, or null if uncached / not text-based.
|