@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.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";
|
|
@@ -401,6 +474,7 @@ var Events = {
|
|
|
401
474
|
GuildEmojisUpdate: "guildEmojisUpdate",
|
|
402
475
|
GuildStickersUpdate: "guildStickersUpdate",
|
|
403
476
|
GuildCountsUpdate: "guildCountsUpdate",
|
|
477
|
+
GuildHealthUpdate: "guildHealthUpdate",
|
|
404
478
|
ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
|
|
405
479
|
GuildMemberAdd: "guildMemberAdd",
|
|
406
480
|
GuildMemberUpdate: "guildMemberUpdate",
|
|
@@ -412,6 +486,14 @@ var Events = {
|
|
|
412
486
|
ChannelCreate: "channelCreate",
|
|
413
487
|
ChannelUpdate: "channelUpdate",
|
|
414
488
|
ChannelDelete: "channelDelete",
|
|
489
|
+
ThreadCreate: "threadCreate",
|
|
490
|
+
ThreadUpdate: "threadUpdate",
|
|
491
|
+
ThreadDelete: "threadDelete",
|
|
492
|
+
ThreadListSync: "threadListSync",
|
|
493
|
+
ThreadMemberUpdate: "threadMemberUpdate",
|
|
494
|
+
ThreadMembersUpdate: "threadMembersUpdate",
|
|
495
|
+
ThreadMemberListUpdate: "threadMemberListUpdate",
|
|
496
|
+
ForumUnreads: "forumUnreads",
|
|
415
497
|
ChannelPinsUpdate: "channelPinsUpdate",
|
|
416
498
|
ChannelRecipientAdd: "channelRecipientAdd",
|
|
417
499
|
ChannelRecipientRemove: "channelRecipientRemove",
|
|
@@ -427,6 +509,8 @@ var Events = {
|
|
|
427
509
|
VoiceStateAck: "voiceStateAck",
|
|
428
510
|
VoiceServerUpdate: "voiceServerUpdate",
|
|
429
511
|
EntranceSoundPlay: "entranceSoundPlay",
|
|
512
|
+
VoiceSignal: "voiceSignal",
|
|
513
|
+
OperatorPassUpdate: "operatorPassUpdate",
|
|
430
514
|
VoiceStatesSync: "voiceStatesSync",
|
|
431
515
|
WebhooksUpdate: "webhooksUpdate",
|
|
432
516
|
Resumed: "resumed",
|
|
@@ -549,6 +633,655 @@ var ReactionCollector = class _ReactionCollector extends EventEmitter {
|
|
|
549
633
|
}
|
|
550
634
|
};
|
|
551
635
|
|
|
636
|
+
// src/Domain/Channel/Base.ts
|
|
637
|
+
import { ChannelType as ChannelType2, Routes as Routes4 } from "@fluxerjs/types";
|
|
638
|
+
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
639
|
+
|
|
640
|
+
// src/ClientCore/MessageManager.ts
|
|
641
|
+
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
642
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
643
|
+
|
|
644
|
+
// src/ClientCore/Resolve.ts
|
|
645
|
+
function normalizeSnowflakeId(value, label) {
|
|
646
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
647
|
+
throw new TypeError(
|
|
648
|
+
`${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
|
|
652
|
+
if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
|
|
653
|
+
throw new TypeError(`${label} requires a non-empty ID`);
|
|
654
|
+
}
|
|
655
|
+
return id;
|
|
656
|
+
}
|
|
657
|
+
function assertApiObjectWithId(data, label) {
|
|
658
|
+
if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
|
|
659
|
+
throw new TypeError(`${label} received an invalid API payload (missing string id)`);
|
|
660
|
+
}
|
|
661
|
+
return data;
|
|
662
|
+
}
|
|
663
|
+
function assertApiArray(data, label) {
|
|
664
|
+
if (!Array.isArray(data)) {
|
|
665
|
+
throw new TypeError(`${label} received an invalid API payload (expected an array)`);
|
|
666
|
+
}
|
|
667
|
+
return data;
|
|
668
|
+
}
|
|
669
|
+
async function dedupeFetch(pending, key, fn) {
|
|
670
|
+
const existing = pending.get(key);
|
|
671
|
+
if (existing) return existing;
|
|
672
|
+
const request = fn();
|
|
673
|
+
pending.set(key, request);
|
|
674
|
+
try {
|
|
675
|
+
return await request;
|
|
676
|
+
} finally {
|
|
677
|
+
if (pending.get(key) === request) pending.delete(key);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/ClientCore/MessageManager.ts
|
|
682
|
+
var MessageManager = class {
|
|
683
|
+
constructor(client, channelId) {
|
|
684
|
+
this.client = client;
|
|
685
|
+
this.channelId = channelId;
|
|
686
|
+
}
|
|
687
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
688
|
+
_structures = new Collection2();
|
|
689
|
+
pendingFetches = /* @__PURE__ */ new Map();
|
|
690
|
+
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
691
|
+
get(messageId) {
|
|
692
|
+
const id = String(messageId ?? "").trim();
|
|
693
|
+
if (!id) return void 0;
|
|
694
|
+
const data = this.client._getMessageCache(this.channelId)?.get(id);
|
|
695
|
+
if (!data) {
|
|
696
|
+
this._structures.delete(id);
|
|
697
|
+
return void 0;
|
|
698
|
+
}
|
|
699
|
+
const existing = this._structures.get(id);
|
|
700
|
+
if (existing) {
|
|
701
|
+
existing._patch(data);
|
|
702
|
+
return existing;
|
|
703
|
+
}
|
|
704
|
+
const message = new Message(this.client, data);
|
|
705
|
+
this._structures.set(id, message);
|
|
706
|
+
return message;
|
|
707
|
+
}
|
|
708
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
709
|
+
async resolve(messageId) {
|
|
710
|
+
const id = normalizeSnowflakeId(messageId, "messages.resolve()");
|
|
711
|
+
return this.get(id) ?? this.fetch(id);
|
|
712
|
+
}
|
|
713
|
+
async fetch(idOrOptions) {
|
|
714
|
+
return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
|
|
715
|
+
}
|
|
716
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
717
|
+
wrap(data) {
|
|
718
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
719
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
720
|
+
const existing = this._structures.get(data.id);
|
|
721
|
+
if (existing) {
|
|
722
|
+
existing._patch(cached);
|
|
723
|
+
return existing;
|
|
724
|
+
}
|
|
725
|
+
const message = new Message(this.client, cached);
|
|
726
|
+
this._structures.set(data.id, message);
|
|
727
|
+
return message;
|
|
728
|
+
}
|
|
729
|
+
/** Fetch a single message from the API. */
|
|
730
|
+
async fetchOne(messageId) {
|
|
731
|
+
return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
|
|
732
|
+
}
|
|
733
|
+
async fetchOneFresh(messageId) {
|
|
734
|
+
try {
|
|
735
|
+
const data = assertApiObjectWithId(
|
|
736
|
+
await this.client.rest.get(Routes2.channelMessage(this.channelId, messageId)),
|
|
737
|
+
"messages.fetch()"
|
|
738
|
+
);
|
|
739
|
+
return this.wrap(data);
|
|
740
|
+
} catch (err) {
|
|
741
|
+
rethrowMapped(err, {
|
|
742
|
+
notFound: {
|
|
743
|
+
code: ErrorCodes.MessageNotFound,
|
|
744
|
+
message: `Message ${messageId} not found in channel ${this.channelId}`
|
|
745
|
+
},
|
|
746
|
+
fallback: `Failed to fetch message ${messageId}`
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/** Fetch multiple messages from the API with pagination/filtering. */
|
|
751
|
+
async fetchMany(options) {
|
|
752
|
+
if (options.limit != null && (options.limit < 1 || options.limit > 100)) {
|
|
753
|
+
throw new FluxerError("limit must be between 1 and 100", {
|
|
754
|
+
code: ErrorCodes.InvalidFetchLimit
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
const qs = new URLSearchParams();
|
|
758
|
+
for (const key of ["limit", "before", "after", "around"]) {
|
|
759
|
+
const value = options[key];
|
|
760
|
+
if (value != null && value !== "") qs.set(key, String(value));
|
|
761
|
+
}
|
|
762
|
+
const base = Routes2.channelMessages(this.channelId);
|
|
763
|
+
const data = assertApiArray(
|
|
764
|
+
await this.client.rest.get(qs.size > 0 ? `${base}?${qs}` : base),
|
|
765
|
+
"messages.fetch()"
|
|
766
|
+
);
|
|
767
|
+
const collection = new Collection2();
|
|
768
|
+
for (const msg of data) {
|
|
769
|
+
if (!msg?.id) continue;
|
|
770
|
+
collection.set(msg.id, this.wrap(msg));
|
|
771
|
+
}
|
|
772
|
+
return collection;
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
// src/Helpers/MessageCollector.ts
|
|
777
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
778
|
+
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
779
|
+
function requireCollectorBounds(options) {
|
|
780
|
+
const time = options.time ?? 0;
|
|
781
|
+
const max = options.max ?? 0;
|
|
782
|
+
if (time <= 0 && max <= 0) {
|
|
783
|
+
throw new FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
784
|
+
code: ErrorCodes.CollectorOptionsRequired
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
var MessageCollector = class _MessageCollector extends EventEmitter2 {
|
|
789
|
+
client;
|
|
790
|
+
channelId;
|
|
791
|
+
options;
|
|
792
|
+
collected = new Collection3();
|
|
793
|
+
_timeout = null;
|
|
794
|
+
_ended = false;
|
|
795
|
+
_listener;
|
|
796
|
+
constructor(client, channelId, options = {}) {
|
|
797
|
+
super();
|
|
798
|
+
requireCollectorBounds(options);
|
|
799
|
+
this.client = client;
|
|
800
|
+
this.channelId = channelId;
|
|
801
|
+
this.options = {
|
|
802
|
+
filter: options.filter ?? (() => true),
|
|
803
|
+
time: options.time ?? 0,
|
|
804
|
+
max: options.max ?? 0
|
|
805
|
+
};
|
|
806
|
+
this._listener = (message) => {
|
|
807
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
808
|
+
if (!this.options.filter(message)) return;
|
|
809
|
+
this.collected.set(message.id, message);
|
|
810
|
+
this.emit("collect", message);
|
|
811
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
812
|
+
this.stop("limit");
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
816
|
+
if (this.options.time > 0) {
|
|
817
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
stop(reason = "user") {
|
|
821
|
+
if (this._ended) return;
|
|
822
|
+
this._ended = true;
|
|
823
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
824
|
+
if (this._timeout) {
|
|
825
|
+
clearTimeout(this._timeout);
|
|
826
|
+
this._timeout = null;
|
|
827
|
+
}
|
|
828
|
+
this.emit("end", this.collected, reason);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
832
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
833
|
+
* the end reason is not listed in `errors`).
|
|
834
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
835
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
836
|
+
*/
|
|
837
|
+
static awaitMessages(client, channelId, options) {
|
|
838
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
839
|
+
return new Promise((resolve, reject) => {
|
|
840
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
841
|
+
collector.on("end", (collected, reason) => {
|
|
842
|
+
if (!errors.includes(reason)) {
|
|
843
|
+
resolve(collected);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
if (reason === "time") {
|
|
847
|
+
reject(
|
|
848
|
+
new FluxerError("Message collector timed out", {
|
|
849
|
+
code: ErrorCodes.CollectorIdle
|
|
850
|
+
})
|
|
851
|
+
);
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
if (reason === "limit") {
|
|
855
|
+
reject(
|
|
856
|
+
new FluxerError("Message collector reached max", {
|
|
857
|
+
code: ErrorCodes.CollectorMax
|
|
858
|
+
})
|
|
859
|
+
);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
reject(collected);
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
on(event, listener) {
|
|
867
|
+
return super.on(event, listener);
|
|
868
|
+
}
|
|
869
|
+
emit(event, ...args) {
|
|
870
|
+
return super.emit(event, ...args);
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
// src/Domain/Channel/Attachments.ts
|
|
875
|
+
import { Routes as Routes3 } from "@fluxerjs/types";
|
|
876
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
877
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
878
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
879
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
880
|
+
if (!rules?.length) return null;
|
|
881
|
+
const snapshot = {};
|
|
882
|
+
for (const rule of rules) {
|
|
883
|
+
Object.assign(snapshot, rule.overrides);
|
|
884
|
+
}
|
|
885
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
886
|
+
}
|
|
887
|
+
function assertBotAttachmentLimits(client, files) {
|
|
888
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
889
|
+
for (const file of files) {
|
|
890
|
+
const size = file.data.byteLength;
|
|
891
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
892
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
893
|
+
throw new FluxerError(
|
|
894
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
895
|
+
{ code: ErrorCodes.AttachmentTooLarge }
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
function asBytes(data) {
|
|
900
|
+
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
901
|
+
const out = new Uint8Array(src.byteLength);
|
|
902
|
+
out.set(src);
|
|
903
|
+
return out;
|
|
904
|
+
}
|
|
905
|
+
async function putBlob(url, body, contentType) {
|
|
906
|
+
const res = await fetch(url, {
|
|
907
|
+
method: "PUT",
|
|
908
|
+
headers: contentType ? { "Content-Type": contentType } : void 0,
|
|
909
|
+
body
|
|
910
|
+
});
|
|
911
|
+
if (!res.ok) {
|
|
912
|
+
throw new FluxerError(`Presigned upload failed: ${res.status}`, {
|
|
913
|
+
code: ErrorCodes.AttachmentUploadFailed
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
918
|
+
assertBotAttachmentLimits(client, files);
|
|
919
|
+
const plan = await client.rest.post(
|
|
920
|
+
Routes3.channelAttachments(channelId),
|
|
921
|
+
{
|
|
922
|
+
body: {
|
|
923
|
+
attachments: files.map((f) => ({
|
|
924
|
+
id: f.id,
|
|
925
|
+
filename: f.filename,
|
|
926
|
+
file_size: f.data.byteLength,
|
|
927
|
+
content_type: f.contentType
|
|
928
|
+
}))
|
|
929
|
+
},
|
|
930
|
+
auth: true
|
|
931
|
+
}
|
|
932
|
+
);
|
|
933
|
+
const multipart = [];
|
|
934
|
+
const uploaded = [];
|
|
935
|
+
for (const item of plan.attachments) {
|
|
936
|
+
const file = files.find((f) => f.id === item.id);
|
|
937
|
+
if (!file) {
|
|
938
|
+
throw new FluxerError(`No file data for planned attachment id ${item.id}`, {
|
|
939
|
+
code: ErrorCodes.InvalidAttachmentInput
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
const bytes = asBytes(file.data);
|
|
943
|
+
if (item.upload_mode === "singlepart") {
|
|
944
|
+
await putBlob(
|
|
945
|
+
item.upload_url,
|
|
946
|
+
new Blob([bytes], { type: file.contentType }),
|
|
947
|
+
item.content_type
|
|
948
|
+
);
|
|
949
|
+
} else {
|
|
950
|
+
for (const part of item.parts) {
|
|
951
|
+
const start = (part.part_number - 1) * item.part_size;
|
|
952
|
+
const chunk = bytes.subarray(start, Math.min(start + item.part_size, bytes.byteLength));
|
|
953
|
+
await putBlob(part.upload_url, new Blob([asBytes(chunk)]));
|
|
954
|
+
}
|
|
955
|
+
multipart.push({ upload_filename: item.upload_filename, upload_id: item.upload_id });
|
|
956
|
+
}
|
|
957
|
+
uploaded.push({
|
|
958
|
+
id: item.id,
|
|
959
|
+
filename: item.filename,
|
|
960
|
+
upload_filename: item.upload_filename,
|
|
961
|
+
file_size: item.file_size,
|
|
962
|
+
content_type: item.content_type
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
if (multipart.length) {
|
|
966
|
+
await client.rest.post(Routes3.channelAttachmentsComplete(channelId), {
|
|
967
|
+
body: { uploads: multipart },
|
|
968
|
+
auth: true
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
return uploaded;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// src/Domain/Channel/Base.ts
|
|
975
|
+
function isFullChannelData(data) {
|
|
976
|
+
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;
|
|
977
|
+
}
|
|
978
|
+
var Channel = class extends Base {
|
|
979
|
+
#messages;
|
|
980
|
+
/** The {@link Client} that instantiated this channel. */
|
|
981
|
+
client;
|
|
982
|
+
/** Snowflake ID of this channel. */
|
|
983
|
+
id;
|
|
984
|
+
/** Channel type (text, voice, category, etc.). */
|
|
985
|
+
type;
|
|
986
|
+
/** Channel name (null for some channel types). */
|
|
987
|
+
name;
|
|
988
|
+
/** Channel icon hash (null for most channel types). */
|
|
989
|
+
icon;
|
|
990
|
+
/** ISO8601 timestamp of the last pinned message update. */
|
|
991
|
+
lastPinTimestamp;
|
|
992
|
+
/**
|
|
993
|
+
* True when built from a partial payload (e.g. a DM stub) and not yet hydrated
|
|
994
|
+
* with a full channel object. `channels.resolve()` refetches partial channels.
|
|
995
|
+
*/
|
|
996
|
+
partial;
|
|
997
|
+
constructor(client, data) {
|
|
998
|
+
super();
|
|
999
|
+
this.client = client;
|
|
1000
|
+
this.id = data.id;
|
|
1001
|
+
this.type = data.type;
|
|
1002
|
+
this.name = data.name ?? null;
|
|
1003
|
+
this.icon = data.icon ?? null;
|
|
1004
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1005
|
+
this.partial = !isFullChannelData(data);
|
|
1006
|
+
}
|
|
1007
|
+
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1008
|
+
get createdTimestamp() {
|
|
1009
|
+
return SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1010
|
+
}
|
|
1011
|
+
/** Date when this channel was created, derived from its snowflake ID. */
|
|
1012
|
+
get createdAt() {
|
|
1013
|
+
return SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
1017
|
+
* @internal
|
|
1018
|
+
*/
|
|
1019
|
+
_patch(data) {
|
|
1020
|
+
if (data.type !== void 0) this.type = data.type;
|
|
1021
|
+
if (data.name !== void 0) this.name = data.name ?? null;
|
|
1022
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
1023
|
+
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1024
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1025
|
+
}
|
|
1026
|
+
if (isFullChannelData(data)) this.partial = false;
|
|
1027
|
+
}
|
|
1028
|
+
/** @internal Factory wired after subclasses load. */
|
|
1029
|
+
static from(_c, _d) {
|
|
1030
|
+
throw new Error("Channel.from not initialized");
|
|
1031
|
+
}
|
|
1032
|
+
/** @internal Factory wired after subclasses load. */
|
|
1033
|
+
static fromOrCreate(_c, _d) {
|
|
1034
|
+
throw new Error("Channel.fromOrCreate not initialized");
|
|
1035
|
+
}
|
|
1036
|
+
/** @internal Factory wired after subclasses load. */
|
|
1037
|
+
static createDM(_c, _d) {
|
|
1038
|
+
throw new Error("Channel.createDM not initialized");
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
|
|
1042
|
+
* Forum and media channels contain threads and do not accept `send`.
|
|
1043
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
1044
|
+
*/
|
|
1045
|
+
isTextBased() {
|
|
1046
|
+
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;
|
|
1047
|
+
}
|
|
1048
|
+
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
1049
|
+
isGuild() {
|
|
1050
|
+
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;
|
|
1051
|
+
}
|
|
1052
|
+
/** Check if this is a thread (public, private, or announcement). */
|
|
1053
|
+
isThread() {
|
|
1054
|
+
return this.type === ChannelType2.AnnouncementThread || this.type === ChannelType2.PublicThread || this.type === ChannelType2.PrivateThread;
|
|
1055
|
+
}
|
|
1056
|
+
/** Check if this is a forum channel. */
|
|
1057
|
+
isForum() {
|
|
1058
|
+
return this.type === ChannelType2.GuildForum;
|
|
1059
|
+
}
|
|
1060
|
+
/** Check if this is a media channel. */
|
|
1061
|
+
isMedia() {
|
|
1062
|
+
return this.type === ChannelType2.GuildMedia;
|
|
1063
|
+
}
|
|
1064
|
+
/** Check if this is a guild text channel. */
|
|
1065
|
+
isText() {
|
|
1066
|
+
return this.type === ChannelType2.GuildText;
|
|
1067
|
+
}
|
|
1068
|
+
/** Check if this is a guild announcement channel. */
|
|
1069
|
+
isAnnouncement() {
|
|
1070
|
+
return this.type === ChannelType2.GuildAnnouncement;
|
|
1071
|
+
}
|
|
1072
|
+
/** Check if this is a category channel. */
|
|
1073
|
+
isCategory() {
|
|
1074
|
+
return this.type === ChannelType2.GuildCategory;
|
|
1075
|
+
}
|
|
1076
|
+
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1077
|
+
isDM() {
|
|
1078
|
+
return this.type === ChannelType2.DM || this.type === ChannelType2.GroupDM || this.type === ChannelType2.DMPersonalNotes;
|
|
1079
|
+
}
|
|
1080
|
+
/** Check if this is a personal notes channel. */
|
|
1081
|
+
isPersonalNotes() {
|
|
1082
|
+
return this.type === ChannelType2.DMPersonalNotes;
|
|
1083
|
+
}
|
|
1084
|
+
/** Check if this is a voice channel. */
|
|
1085
|
+
isVoice() {
|
|
1086
|
+
return this.type === ChannelType2.GuildVoice;
|
|
1087
|
+
}
|
|
1088
|
+
/** Check if this is a link channel. */
|
|
1089
|
+
isLink() {
|
|
1090
|
+
return this.type === ChannelType2.GuildLink;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Delete recent messages or an explicit ID list.
|
|
1094
|
+
* - `bulkDelete(5)` — fetch last 5 via {@link MessageManager} then delete (1–100)
|
|
1095
|
+
* - `bulkDelete(['id1'])` — single DELETE; 2–100 uses bulk-delete route
|
|
1096
|
+
*/
|
|
1097
|
+
async bulkDelete(countOrIds) {
|
|
1098
|
+
let ids;
|
|
1099
|
+
if (typeof countOrIds === "number") {
|
|
1100
|
+
if (!Number.isInteger(countOrIds) || countOrIds < 1 || countOrIds > 100) {
|
|
1101
|
+
throw new FluxerError("bulkDelete count must be between 1 and 100", {
|
|
1102
|
+
code: ErrorCodes.InvalidBulkDelete
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
ids = [
|
|
1106
|
+
...(await new MessageManager(this.client, this.id).fetch({ limit: countOrIds })).keys()
|
|
1107
|
+
];
|
|
1108
|
+
} else {
|
|
1109
|
+
ids = [...countOrIds];
|
|
1110
|
+
}
|
|
1111
|
+
if (ids.length === 0) return [];
|
|
1112
|
+
if (ids.length === 1) {
|
|
1113
|
+
await this.client.rest.delete(Routes4.channelMessage(this.id, ids[0]), { auth: true });
|
|
1114
|
+
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
1115
|
+
return ids;
|
|
1116
|
+
}
|
|
1117
|
+
if (ids.length > 100) {
|
|
1118
|
+
throw new FluxerError("bulkDelete requires at most 100 message IDs", {
|
|
1119
|
+
code: ErrorCodes.InvalidBulkDelete
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
await this.client.rest.post(Routes4.channelBulkDelete(this.id), {
|
|
1123
|
+
body: { message_ids: ids },
|
|
1124
|
+
auth: true
|
|
1125
|
+
});
|
|
1126
|
+
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1127
|
+
return ids;
|
|
1128
|
+
}
|
|
1129
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1130
|
+
async bulkDeleteMyMessages(options) {
|
|
1131
|
+
const body = options ? toSudoBody(options) : void 0;
|
|
1132
|
+
await this.client.rest.post(Routes4.channelBulkDeleteMine(this.id), {
|
|
1133
|
+
body: body && Object.keys(body).length ? body : void 0,
|
|
1134
|
+
auth: true
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Mark all pinned messages as read in this channel.
|
|
1139
|
+
* Session-token helper; bots usually skip this.
|
|
1140
|
+
*/
|
|
1141
|
+
async acknowledgePins() {
|
|
1142
|
+
await this.client.rest.post(Routes4.channelPinsAck(this.id), { auth: true });
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Clear the read state for this channel.
|
|
1146
|
+
* Session-token helper; bots usually skip this.
|
|
1147
|
+
*/
|
|
1148
|
+
async clearReadState() {
|
|
1149
|
+
await this.client.rest.delete(Routes4.channelMessagesAck(this.id), { auth: true });
|
|
1150
|
+
}
|
|
1151
|
+
/** Request upload URLs for attachments before sending a message. */
|
|
1152
|
+
async requestAttachmentUploads(attachments) {
|
|
1153
|
+
const data = await this.client.rest.post(
|
|
1154
|
+
Routes4.channelAttachments(this.id),
|
|
1155
|
+
{
|
|
1156
|
+
body: toAttachmentUploadPlanBody(attachments),
|
|
1157
|
+
auth: true
|
|
1158
|
+
}
|
|
1159
|
+
);
|
|
1160
|
+
return toAttachmentUploadPlanResponse(data);
|
|
1161
|
+
}
|
|
1162
|
+
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
1163
|
+
async completeAttachmentUploads(uploads) {
|
|
1164
|
+
const data = await this.client.rest.post(
|
|
1165
|
+
Routes4.channelAttachmentsComplete(this.id),
|
|
1166
|
+
{
|
|
1167
|
+
body: toAttachmentUploadCompleteBody(uploads),
|
|
1168
|
+
auth: true
|
|
1169
|
+
}
|
|
1170
|
+
);
|
|
1171
|
+
return {
|
|
1172
|
+
uploads: data.uploads.map((u) => ({ uploadFilename: u.upload_filename }))
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
/** Upload files for sending in a message (helper). */
|
|
1176
|
+
async uploadAttachmentsForSend(files) {
|
|
1177
|
+
return uploadAttachmentsForSend(this.client, this.id, files);
|
|
1178
|
+
}
|
|
1179
|
+
/** Trigger the typing indicator in this channel. */
|
|
1180
|
+
async sendTyping() {
|
|
1181
|
+
await this.client.rest.post(Routes4.channelTyping(this.id), { auth: true });
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Fetch available RTC regions for voice channels.
|
|
1185
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
1186
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
1187
|
+
*/
|
|
1188
|
+
async fetchRtcRegions() {
|
|
1189
|
+
const data = await this.client.rest.get(Routes4.channelRtcRegions(this.id), {
|
|
1190
|
+
auth: true
|
|
1191
|
+
});
|
|
1192
|
+
return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
|
|
1193
|
+
}
|
|
1194
|
+
/** Fetch slowmode state for this channel. */
|
|
1195
|
+
async fetchSlowmode() {
|
|
1196
|
+
const data = await this.client.rest.get(
|
|
1197
|
+
Routes4.channelSlowmode(this.id),
|
|
1198
|
+
{ auth: true }
|
|
1199
|
+
);
|
|
1200
|
+
return {
|
|
1201
|
+
rateLimitPerUser: data.rate_limit_per_user,
|
|
1202
|
+
retryAfterMs: data.retry_after_ms,
|
|
1203
|
+
nextSendAllowedAt: data.next_send_allowed_at
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1207
|
+
canSendMessage() {
|
|
1208
|
+
return this.isTextBased();
|
|
1209
|
+
}
|
|
1210
|
+
/** Per-channel message cache + fetch. */
|
|
1211
|
+
get messages() {
|
|
1212
|
+
if (!this.#messages) {
|
|
1213
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1214
|
+
}
|
|
1215
|
+
return this.#messages;
|
|
1216
|
+
}
|
|
1217
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
1218
|
+
createMessageCollector(options) {
|
|
1219
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
1223
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1224
|
+
* @example
|
|
1225
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
1226
|
+
*/
|
|
1227
|
+
awaitMessages(options) {
|
|
1228
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Delete this channel (or close it if it is a DM).
|
|
1232
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
1233
|
+
* @example
|
|
1234
|
+
* const channel = await client.channels.fetch(channelId);
|
|
1235
|
+
* await channel.delete();
|
|
1236
|
+
*/
|
|
1237
|
+
async delete(options) {
|
|
1238
|
+
const params = new URLSearchParams();
|
|
1239
|
+
if (options?.silent) params.set("silent", "true");
|
|
1240
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
1241
|
+
const qs = params.toString();
|
|
1242
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
1243
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
1244
|
+
await this.client.rest.delete(Routes4.channel(this.id) + (qs ? `?${qs}` : ""), {
|
|
1245
|
+
body,
|
|
1246
|
+
auth: true,
|
|
1247
|
+
...auditReasonHeaders(_reason)
|
|
1248
|
+
});
|
|
1249
|
+
this.client.channels.delete(this.id);
|
|
1250
|
+
this.client._clearMessageCache(this.id);
|
|
1251
|
+
if (this.isGuild() && this.guildId) {
|
|
1252
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
/** Channel mention (`<#id>`). */
|
|
1256
|
+
toString() {
|
|
1257
|
+
return `<#${this.id}>`;
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
// src/Domain/Channel/ThreadCache.ts
|
|
1262
|
+
function cacheThread(client, data) {
|
|
1263
|
+
const existing = client.channels.get(data.id);
|
|
1264
|
+
if (existing?.isThread() && existing.type === data.type) {
|
|
1265
|
+
existing._patch(data);
|
|
1266
|
+
placeThread(client, existing);
|
|
1267
|
+
return existing;
|
|
1268
|
+
}
|
|
1269
|
+
const created = Channel.from(client, data);
|
|
1270
|
+
if (!created.isThread()) {
|
|
1271
|
+
throw new FluxerError(`Channel ${data.id} is not a thread`, {
|
|
1272
|
+
code: ErrorCodes.InvalidChannelType
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
placeThread(client, created);
|
|
1276
|
+
return created;
|
|
1277
|
+
}
|
|
1278
|
+
function placeThread(client, thread) {
|
|
1279
|
+
client.channels.set(thread.id, thread);
|
|
1280
|
+
if (!thread.guildId) return;
|
|
1281
|
+
const guild = client.guilds.get(thread.guildId);
|
|
1282
|
+
if (guild) guild.channels.set(thread.id, thread);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
552
1285
|
// src/Domain/Message/Attachment.ts
|
|
553
1286
|
function toMessageAttachment(data) {
|
|
554
1287
|
return {
|
|
@@ -633,12 +1366,12 @@ function toMessageEmbed(data) {
|
|
|
633
1366
|
}
|
|
634
1367
|
|
|
635
1368
|
// src/Domain/Message/MessageReactionManager.ts
|
|
636
|
-
import { Collection as
|
|
1369
|
+
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
637
1370
|
var MessageReactionManager = class {
|
|
638
1371
|
constructor(message) {
|
|
639
1372
|
this.message = message;
|
|
640
1373
|
}
|
|
641
|
-
_cache = new
|
|
1374
|
+
_cache = new Collection4();
|
|
642
1375
|
/** Reactions keyed by unicode name or `name:id`. */
|
|
643
1376
|
get cache() {
|
|
644
1377
|
return this._cache;
|
|
@@ -660,7 +1393,7 @@ var MessageReactionManager = class {
|
|
|
660
1393
|
};
|
|
661
1394
|
|
|
662
1395
|
// src/Domain/Message/MessageSticker.ts
|
|
663
|
-
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
1396
|
+
import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
|
|
664
1397
|
|
|
665
1398
|
// src/Helpers/Constants.ts
|
|
666
1399
|
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
@@ -767,36 +1500,36 @@ var MessageSticker = class extends Base {
|
|
|
767
1500
|
}
|
|
768
1501
|
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
769
1502
|
get createdTimestamp() {
|
|
770
|
-
return
|
|
1503
|
+
return SnowflakeUtil2.timestampFromSnowflake(this.id);
|
|
771
1504
|
}
|
|
772
1505
|
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
773
1506
|
get createdAt() {
|
|
774
|
-
return
|
|
1507
|
+
return SnowflakeUtil2.dateFromSnowflake(this.id);
|
|
775
1508
|
}
|
|
776
1509
|
};
|
|
777
1510
|
|
|
778
1511
|
// src/Domain/Message/Reactions.ts
|
|
779
|
-
import { Routes as
|
|
1512
|
+
import { Routes as Routes5 } from "@fluxerjs/types";
|
|
780
1513
|
async function emojiPath(message, emoji) {
|
|
781
1514
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
782
1515
|
}
|
|
783
1516
|
async function reactToMessage(message, emoji) {
|
|
784
1517
|
const wire = await emojiPath(message, emoji);
|
|
785
1518
|
await message.client.rest.put(
|
|
786
|
-
|
|
1519
|
+
Routes5.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
787
1520
|
);
|
|
788
1521
|
}
|
|
789
1522
|
async function removeMessageReaction(message, emoji, userId) {
|
|
790
1523
|
const e = await emojiPath(message, emoji);
|
|
791
|
-
const route = userId ?
|
|
1524
|
+
const route = userId ? Routes5.channelMessageReactionUser(message.channelId, message.id, e, userId) : Routes5.channelMessageReactionMe(message.channelId, message.id, e);
|
|
792
1525
|
await message.client.rest.delete(route);
|
|
793
1526
|
}
|
|
794
1527
|
async function removeAllMessageReactions(message) {
|
|
795
|
-
await message.client.rest.delete(
|
|
1528
|
+
await message.client.rest.delete(Routes5.channelMessageReactions(message.channelId, message.id));
|
|
796
1529
|
}
|
|
797
1530
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
798
1531
|
const e = await emojiPath(message, emoji);
|
|
799
|
-
await message.client.rest.delete(
|
|
1532
|
+
await message.client.rest.delete(Routes5.channelMessageReaction(message.channelId, message.id, e));
|
|
800
1533
|
}
|
|
801
1534
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
802
1535
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -807,7 +1540,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
807
1540
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
808
1541
|
if (options?.after) params.set("after", options.after);
|
|
809
1542
|
const qs = params.toString();
|
|
810
|
-
const route =
|
|
1543
|
+
const route = Routes5.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
|
|
811
1544
|
const data = await message.client.rest.get(route);
|
|
812
1545
|
if (Array.isArray(data)) {
|
|
813
1546
|
return {
|
|
@@ -826,7 +1559,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
826
1559
|
|
|
827
1560
|
// src/Domain/Message/Send.ts
|
|
828
1561
|
import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
|
|
829
|
-
import { Routes as
|
|
1562
|
+
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
830
1563
|
function toReplyTarget(ref) {
|
|
831
1564
|
return {
|
|
832
1565
|
channelId: ref.channel_id,
|
|
@@ -860,7 +1593,7 @@ function asReplyTarget(value) {
|
|
|
860
1593
|
}
|
|
861
1594
|
async function sendPrepared(message, payload) {
|
|
862
1595
|
const data = await message.client.rest.post(
|
|
863
|
-
|
|
1596
|
+
Routes6.channelMessages(message.channelId),
|
|
864
1597
|
payload
|
|
865
1598
|
);
|
|
866
1599
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -969,6 +1702,8 @@ var Message = class _Message extends Base {
|
|
|
969
1702
|
nonce;
|
|
970
1703
|
/** IDs of custom emojis in the message classified as explicit. */
|
|
971
1704
|
nsfwEmojis;
|
|
1705
|
+
/** Thread started from this message, when the payload included one. */
|
|
1706
|
+
thread;
|
|
972
1707
|
/**
|
|
973
1708
|
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
974
1709
|
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
@@ -1016,11 +1751,11 @@ var Message = class _Message extends Base {
|
|
|
1016
1751
|
this.channelId = data.channel_id;
|
|
1017
1752
|
this.guildId = data.guild_id ?? null;
|
|
1018
1753
|
this.author = client.getOrCreateUser(data.author);
|
|
1019
|
-
this.content = data.content;
|
|
1020
|
-
this.createdAt = new Date(data.timestamp);
|
|
1754
|
+
this.content = data.content ?? "";
|
|
1755
|
+
this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
|
|
1021
1756
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1022
|
-
this.pinned = data.pinned;
|
|
1023
|
-
this.attachments = new
|
|
1757
|
+
this.pinned = data.pinned ?? false;
|
|
1758
|
+
this.attachments = new Collection5();
|
|
1024
1759
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1025
1760
|
this.type = data.type ?? MessageType.Default;
|
|
1026
1761
|
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
@@ -1044,39 +1779,55 @@ var Message = class _Message extends Base {
|
|
|
1044
1779
|
this.mentionRoles = data.mention_roles ?? [];
|
|
1045
1780
|
this.nonce = data.nonce ?? null;
|
|
1046
1781
|
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1782
|
+
this.thread = data.thread ? cacheThread(client, data.thread) : null;
|
|
1047
1783
|
}
|
|
1048
1784
|
/**
|
|
1049
1785
|
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
1050
1786
|
* @internal
|
|
1051
1787
|
*/
|
|
1052
1788
|
_patch(data) {
|
|
1053
|
-
this.content = data.content;
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
this.
|
|
1064
|
-
this.
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1789
|
+
if (data.content !== void 0) this.content = data.content ?? "";
|
|
1790
|
+
if (data.edited_timestamp !== void 0) {
|
|
1791
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1792
|
+
}
|
|
1793
|
+
if (data.pinned !== void 0) this.pinned = data.pinned;
|
|
1794
|
+
if (data.attachments !== void 0) {
|
|
1795
|
+
this.attachments.clear();
|
|
1796
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1797
|
+
}
|
|
1798
|
+
if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1799
|
+
if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
|
|
1800
|
+
if (data.tts !== void 0) this.tts = data.tts;
|
|
1801
|
+
if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1802
|
+
if (data.stickers !== void 0) {
|
|
1803
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1804
|
+
}
|
|
1805
|
+
if (data.reactions !== void 0) this.reactions._patch(data.reactions);
|
|
1806
|
+
if (data.message_reference !== void 0) {
|
|
1807
|
+
this.messageReference = data.message_reference ? {
|
|
1808
|
+
channelId: data.message_reference.channel_id,
|
|
1809
|
+
messageId: data.message_reference.message_id,
|
|
1810
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1811
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1812
|
+
} : null;
|
|
1813
|
+
}
|
|
1814
|
+
if (data.message_snapshots !== void 0) {
|
|
1815
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1816
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1817
|
+
);
|
|
1818
|
+
}
|
|
1819
|
+
if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
|
|
1820
|
+
if (data.referenced_message !== void 0) {
|
|
1821
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1822
|
+
}
|
|
1823
|
+
if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
|
|
1824
|
+
if (data.mentions !== void 0) {
|
|
1825
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1826
|
+
}
|
|
1827
|
+
if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
|
|
1828
|
+
if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
|
|
1829
|
+
if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1830
|
+
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
1080
1831
|
}
|
|
1081
1832
|
/**
|
|
1082
1833
|
* Send a standalone message in this channel (not a reply).
|
|
@@ -1137,7 +1888,7 @@ var Message = class _Message extends Base {
|
|
|
1137
1888
|
if (options.attachments !== void 0) {
|
|
1138
1889
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
1139
1890
|
}
|
|
1140
|
-
const data = await this.client.rest.patch(
|
|
1891
|
+
const data = await this.client.rest.patch(Routes7.channelMessage(this.channelId, this.id), {
|
|
1141
1892
|
body
|
|
1142
1893
|
});
|
|
1143
1894
|
const updated = new _Message(this.client, data);
|
|
@@ -1155,13 +1906,47 @@ var Message = class _Message extends Base {
|
|
|
1155
1906
|
awaitReactions(options) {
|
|
1156
1907
|
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1157
1908
|
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Start a thread from this message.
|
|
1911
|
+
* Fluxer chooses a public or announcement thread from the parent channel.
|
|
1912
|
+
*/
|
|
1913
|
+
async startThread(options) {
|
|
1914
|
+
const data = await this.client.rest.post(
|
|
1915
|
+
Routes7.channelMessageThreads(this.channelId, this.id),
|
|
1916
|
+
{
|
|
1917
|
+
body: toStartThreadFromMessageBody(options),
|
|
1918
|
+
auth: true,
|
|
1919
|
+
...auditReasonHeaders(options.reason)
|
|
1920
|
+
}
|
|
1921
|
+
);
|
|
1922
|
+
const thread = cacheThread(this.client, data);
|
|
1923
|
+
this.thread = thread;
|
|
1924
|
+
return thread;
|
|
1925
|
+
}
|
|
1158
1926
|
/** Fetch the latest version of this message from the API. */
|
|
1159
1927
|
async fetch() {
|
|
1160
1928
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1161
1929
|
}
|
|
1930
|
+
/** Publish this announcement message to channels following its channel. */
|
|
1931
|
+
async crosspost() {
|
|
1932
|
+
const data = await this.client.rest.post(
|
|
1933
|
+
Routes7.channelMessageCrosspost(this.channelId, this.id),
|
|
1934
|
+
{ auth: true }
|
|
1935
|
+
);
|
|
1936
|
+
const published = new _Message(this.client, data);
|
|
1937
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
1938
|
+
return published;
|
|
1939
|
+
}
|
|
1940
|
+
/** Fetch the source guild of a crossposted (followed-channel) message. */
|
|
1941
|
+
async fetchCrosspostSource() {
|
|
1942
|
+
return this.client.rest.get(
|
|
1943
|
+
Routes7.channelMessageCrosspostSource(this.channelId, this.id),
|
|
1944
|
+
{ auth: true }
|
|
1945
|
+
);
|
|
1946
|
+
}
|
|
1162
1947
|
/** Delete this message. */
|
|
1163
1948
|
async delete(reason) {
|
|
1164
|
-
await this.client.rest.delete(
|
|
1949
|
+
await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
|
|
1165
1950
|
...auditReasonHeaders(reason)
|
|
1166
1951
|
});
|
|
1167
1952
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
@@ -1169,19 +1954,19 @@ var Message = class _Message extends Base {
|
|
|
1169
1954
|
/** Delete a specific attachment from this message. */
|
|
1170
1955
|
async deleteAttachment(attachmentId) {
|
|
1171
1956
|
await this.client.rest.delete(
|
|
1172
|
-
|
|
1957
|
+
Routes7.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
1173
1958
|
{ auth: true }
|
|
1174
1959
|
);
|
|
1175
1960
|
this.attachments.delete(attachmentId);
|
|
1176
1961
|
}
|
|
1177
1962
|
/** Pin this message in the channel. */
|
|
1178
1963
|
async pin() {
|
|
1179
|
-
await this.client.rest.put(
|
|
1964
|
+
await this.client.rest.put(Routes7.channelPinMessage(this.channelId, this.id));
|
|
1180
1965
|
this.pinned = true;
|
|
1181
1966
|
}
|
|
1182
1967
|
/** Unpin this message from the channel. */
|
|
1183
1968
|
async unpin() {
|
|
1184
|
-
await this.client.rest.delete(
|
|
1969
|
+
await this.client.rest.delete(Routes7.channelPinMessage(this.channelId, this.id));
|
|
1185
1970
|
this.pinned = false;
|
|
1186
1971
|
}
|
|
1187
1972
|
/** React to this message with an emoji. */
|
|
@@ -1211,7 +1996,7 @@ var Message = class _Message extends Base {
|
|
|
1211
1996
|
};
|
|
1212
1997
|
|
|
1213
1998
|
// src/Domain/Message/PartialMessage.ts
|
|
1214
|
-
import { SnowflakeUtil as
|
|
1999
|
+
import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
|
|
1215
2000
|
var PartialMessage = class {
|
|
1216
2001
|
partial = true;
|
|
1217
2002
|
client;
|
|
@@ -1230,7 +2015,7 @@ var PartialMessage = class {
|
|
|
1230
2015
|
this.content = data.content ?? null;
|
|
1231
2016
|
this.authorId = data.authorId ?? null;
|
|
1232
2017
|
this.author = data.author ?? null;
|
|
1233
|
-
this.createdAt = data.createdAt ?? (
|
|
2018
|
+
this.createdAt = data.createdAt ?? (SnowflakeUtil3.isValid(data.id) ? SnowflakeUtil3.dateFromSnowflake(data.id) : null);
|
|
1234
2019
|
}
|
|
1235
2020
|
/**
|
|
1236
2021
|
* Live text-capable channel from cache, or null if uncached / not text-based.
|