@fluxerjs/core 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SubpathMessage-DaimQAd9.d.ts → SubpathMessage-CNJlnR6y.d.mts} +2391 -2134
- package/dist/{SubpathMessage-Cj_U0V19.d.mts → SubpathMessage-DjLo6il5.d.ts} +2391 -2134
- package/dist/Sudo-mzPLv6YU.d.mts +802 -0
- package/dist/Sudo-mzPLv6YU.d.ts +802 -0
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2378 -1407
- package/dist/client.mjs +2346 -1369
- package/dist/cluster.d.mts +2 -2
- package/dist/cluster.d.ts +2 -2
- package/dist/cluster.js +2378 -1407
- package/dist/cluster.mjs +2346 -1369
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1227 -230
- package/dist/index.mjs +1129 -134
- package/dist/internal.d.mts +3 -2
- package/dist/internal.d.ts +3 -2
- package/dist/internal.js +53 -0
- package/dist/internal.mjs +55 -0
- package/dist/message.d.mts +2 -2
- package/dist/message.d.ts +2 -2
- package/dist/message.js +717 -34
- package/dist/message.mjs +708 -23
- package/package.json +4 -4
- package/dist/Sudo-fOKSPbxN.d.mts +0 -461
- package/dist/Sudo-fOKSPbxN.d.ts +0 -461
package/dist/client.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/ClientCore/Client.ts
|
|
2
2
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
3
3
|
import { REST } from "@fluxerjs/rest";
|
|
4
|
-
import { GatewayOpcodes as GatewayOpcodes2, Routes as
|
|
4
|
+
import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes37 } from "@fluxerjs/types";
|
|
5
5
|
import { createLogger } from "@fluxerjs/util";
|
|
6
6
|
|
|
7
7
|
// src/Domain/Message/Message.ts
|
|
8
8
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
9
|
-
import { Collection as
|
|
9
|
+
import { Collection as Collection5 } from "@fluxerjs/collection";
|
|
10
10
|
import {
|
|
11
11
|
MessageType,
|
|
12
|
-
Routes as
|
|
12
|
+
Routes as Routes7
|
|
13
13
|
} from "@fluxerjs/types";
|
|
14
14
|
import { MessageFlagsBitField } from "@fluxerjs/util";
|
|
15
15
|
|
|
@@ -78,7 +78,132 @@ function toAttachmentUploadPlanResponse(data) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// src/ClientCore/SdkOptions/Channels.ts
|
|
81
|
+
import { ChannelType as ChannelType2 } from "@fluxerjs/types";
|
|
81
82
|
import { resolvePermissionsToBitfield } from "@fluxerjs/util";
|
|
83
|
+
|
|
84
|
+
// src/ClientCore/SdkOptions/Threads.ts
|
|
85
|
+
import {
|
|
86
|
+
ChannelType
|
|
87
|
+
} from "@fluxerjs/types";
|
|
88
|
+
function toThreadEditBody(type, options) {
|
|
89
|
+
const body = {};
|
|
90
|
+
if (options.name !== void 0) body.name = options.name;
|
|
91
|
+
if (options.archived !== void 0) body.archived = options.archived;
|
|
92
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
93
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
94
|
+
}
|
|
95
|
+
if (options.locked !== void 0) body.locked = options.locked;
|
|
96
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
97
|
+
if (options.flags !== void 0) body.flags = options.flags;
|
|
98
|
+
if (options.appliedTags !== void 0 && type !== ChannelType.PrivateThread) {
|
|
99
|
+
body.applied_tags = options.appliedTags;
|
|
100
|
+
}
|
|
101
|
+
if (options.invitable !== void 0 && type === ChannelType.PrivateThread) {
|
|
102
|
+
body.invitable = options.invitable;
|
|
103
|
+
}
|
|
104
|
+
return body;
|
|
105
|
+
}
|
|
106
|
+
function toThreadParentEditBody(options) {
|
|
107
|
+
const body = {};
|
|
108
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
109
|
+
body.default_auto_archive_duration = options.autoArchiveDuration;
|
|
110
|
+
}
|
|
111
|
+
if (options.rateLimitPerUser !== void 0) {
|
|
112
|
+
body.default_thread_rate_limit_per_user = options.rateLimitPerUser;
|
|
113
|
+
}
|
|
114
|
+
return body;
|
|
115
|
+
}
|
|
116
|
+
function toStartThreadBody(channelType, options) {
|
|
117
|
+
const type = options.type ?? (channelType === ChannelType.GuildAnnouncement ? ChannelType.AnnouncementThread : ChannelType.PublicThread);
|
|
118
|
+
const body = { name: options.name, type };
|
|
119
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
120
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
121
|
+
}
|
|
122
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
123
|
+
if (options.invitable !== void 0) body.invitable = options.invitable;
|
|
124
|
+
return body;
|
|
125
|
+
}
|
|
126
|
+
function toStartThreadFromMessageBody(options) {
|
|
127
|
+
const body = { name: options.name };
|
|
128
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
129
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
130
|
+
}
|
|
131
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
132
|
+
return body;
|
|
133
|
+
}
|
|
134
|
+
function toForumThreadMessage(body) {
|
|
135
|
+
const message = {};
|
|
136
|
+
if (body.content !== void 0) message.content = body.content;
|
|
137
|
+
if (body.embeds !== void 0) message.embeds = body.embeds;
|
|
138
|
+
if (body.attachments !== void 0) message.attachments = body.attachments;
|
|
139
|
+
if (body.allowed_mentions !== void 0) message.allowed_mentions = body.allowed_mentions;
|
|
140
|
+
if (body.flags !== void 0) message.flags = body.flags;
|
|
141
|
+
if (body.sticker_ids !== void 0) message.sticker_ids = body.sticker_ids;
|
|
142
|
+
return message;
|
|
143
|
+
}
|
|
144
|
+
function toForumTagBody(options) {
|
|
145
|
+
const body = { name: options.name };
|
|
146
|
+
if ("id" in options && options.id !== void 0) body.id = options.id;
|
|
147
|
+
if (options.moderated !== void 0) body.moderated = options.moderated;
|
|
148
|
+
if (options.emojiId !== void 0) body.emoji_id = options.emojiId;
|
|
149
|
+
if (options.emojiName !== void 0) body.emoji_name = options.emojiName;
|
|
150
|
+
return body;
|
|
151
|
+
}
|
|
152
|
+
function forumParentWire(options, includeLayout) {
|
|
153
|
+
const body = {};
|
|
154
|
+
if (options.availableTags !== void 0) {
|
|
155
|
+
body.available_tags = options.availableTags.map((tag) => toForumTagBody(tag));
|
|
156
|
+
}
|
|
157
|
+
if (options.defaultReactionEmoji !== void 0) {
|
|
158
|
+
body.default_reaction_emoji = options.defaultReactionEmoji === null ? null : reactionEmojiWire(options.defaultReactionEmoji);
|
|
159
|
+
}
|
|
160
|
+
if (options.defaultSortOrder !== void 0) body.default_sort_order = options.defaultSortOrder;
|
|
161
|
+
if (options.defaultTagSetting !== void 0) body.default_tag_setting = options.defaultTagSetting;
|
|
162
|
+
if (options.flags !== void 0) body.flags = options.flags;
|
|
163
|
+
if (options.defaultAutoArchiveDuration !== void 0) {
|
|
164
|
+
body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
|
|
165
|
+
}
|
|
166
|
+
if (options.defaultThreadRateLimitPerUser !== void 0) {
|
|
167
|
+
body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
|
|
168
|
+
}
|
|
169
|
+
if (includeLayout && options.defaultForumLayout !== void 0) {
|
|
170
|
+
body.default_forum_layout = options.defaultForumLayout;
|
|
171
|
+
}
|
|
172
|
+
return body;
|
|
173
|
+
}
|
|
174
|
+
function reactionEmojiWire(emoji) {
|
|
175
|
+
const body = {};
|
|
176
|
+
if (emoji.emojiId !== void 0) body.emoji_id = emoji.emojiId;
|
|
177
|
+
if (emoji.emojiName !== void 0) body.emoji_name = emoji.emojiName;
|
|
178
|
+
return body;
|
|
179
|
+
}
|
|
180
|
+
function toThreadMemberSettingsBody(options) {
|
|
181
|
+
const body = {};
|
|
182
|
+
if (options.flags !== void 0) body.flags = options.flags;
|
|
183
|
+
if (options.muted !== void 0) body.muted = options.muted;
|
|
184
|
+
if (options.muteConfig !== void 0) {
|
|
185
|
+
body.mute_config = options.muteConfig === null ? null : {
|
|
186
|
+
...options.muteConfig.endTime !== void 0 ? { end_time: options.muteConfig.endTime } : {},
|
|
187
|
+
selected_time_window: options.muteConfig.selectedTimeWindow
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return body;
|
|
191
|
+
}
|
|
192
|
+
function withQuery(path, params) {
|
|
193
|
+
const query = new URLSearchParams();
|
|
194
|
+
for (const [key, value] of Object.entries(params)) {
|
|
195
|
+
if (value === void 0) continue;
|
|
196
|
+
if (Array.isArray(value)) {
|
|
197
|
+
for (const item of value) query.append(key, item);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
query.set(key, String(value));
|
|
201
|
+
}
|
|
202
|
+
const text = query.toString();
|
|
203
|
+
return text ? `${path}?${text}` : path;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/ClientCore/SdkOptions/Channels.ts
|
|
82
207
|
function toOverwriteWire(overwrite) {
|
|
83
208
|
return {
|
|
84
209
|
id: overwrite.id,
|
|
@@ -89,6 +214,7 @@ function toOverwriteWire(overwrite) {
|
|
|
89
214
|
}
|
|
90
215
|
function toChannelEditBody(options) {
|
|
91
216
|
const body = {};
|
|
217
|
+
if (options.type !== void 0) body.type = options.type;
|
|
92
218
|
if (options.name !== void 0) body.name = options.name;
|
|
93
219
|
if (options.topic !== void 0) body.topic = options.topic;
|
|
94
220
|
if (options.url !== void 0) body.url = options.url;
|
|
@@ -138,6 +264,16 @@ function toChannelCreateBody(options) {
|
|
|
138
264
|
body.content_warning_text = options.contentWarningText;
|
|
139
265
|
}
|
|
140
266
|
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
267
|
+
if (options.defaultAutoArchiveDuration !== void 0) {
|
|
268
|
+
body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
|
|
269
|
+
}
|
|
270
|
+
if (options.defaultThreadRateLimitPerUser !== void 0) {
|
|
271
|
+
body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
|
|
272
|
+
}
|
|
273
|
+
const forumParent = options.type === ChannelType2.GuildForum || options.type === ChannelType2.GuildMedia;
|
|
274
|
+
if (forumParent) {
|
|
275
|
+
Object.assign(body, forumParentWire(options, options.type === ChannelType2.GuildForum));
|
|
276
|
+
}
|
|
141
277
|
return body;
|
|
142
278
|
}
|
|
143
279
|
function toChannelInviteBody(options) {
|
|
@@ -822,6 +958,14 @@ var Events = {
|
|
|
822
958
|
ChannelCreate: "channelCreate",
|
|
823
959
|
ChannelUpdate: "channelUpdate",
|
|
824
960
|
ChannelDelete: "channelDelete",
|
|
961
|
+
ThreadCreate: "threadCreate",
|
|
962
|
+
ThreadUpdate: "threadUpdate",
|
|
963
|
+
ThreadDelete: "threadDelete",
|
|
964
|
+
ThreadListSync: "threadListSync",
|
|
965
|
+
ThreadMemberUpdate: "threadMemberUpdate",
|
|
966
|
+
ThreadMembersUpdate: "threadMembersUpdate",
|
|
967
|
+
ThreadMemberListUpdate: "threadMemberListUpdate",
|
|
968
|
+
ForumUnreads: "forumUnreads",
|
|
825
969
|
ChannelPinsUpdate: "channelPinsUpdate",
|
|
826
970
|
ChannelRecipientAdd: "channelRecipientAdd",
|
|
827
971
|
ChannelRecipientRemove: "channelRecipientRemove",
|
|
@@ -959,1342 +1103,1404 @@ var ReactionCollector = class _ReactionCollector extends EventEmitter {
|
|
|
959
1103
|
}
|
|
960
1104
|
};
|
|
961
1105
|
|
|
962
|
-
// src/Domain/
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
id: data.id,
|
|
966
|
-
filename: data.filename,
|
|
967
|
-
title: data.title ?? null,
|
|
968
|
-
description: data.description ?? null,
|
|
969
|
-
contentType: data.content_type ?? null,
|
|
970
|
-
contentHash: data.content_hash ?? null,
|
|
971
|
-
size: data.size,
|
|
972
|
-
url: data.url ?? null,
|
|
973
|
-
proxyUrl: data.proxy_url ?? null,
|
|
974
|
-
width: data.width ?? null,
|
|
975
|
-
height: data.height ?? null,
|
|
976
|
-
placeholder: data.placeholder ?? null,
|
|
977
|
-
flags: data.flags ?? 0,
|
|
978
|
-
nsfw: data.nsfw ?? false,
|
|
979
|
-
duration: data.duration ?? null,
|
|
980
|
-
waveform: data.waveform ?? null,
|
|
981
|
-
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
982
|
-
expired: data.expired ?? false
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
// src/Domain/Message/Embed.ts
|
|
987
|
-
function toMessageEmbedAuthor(data) {
|
|
988
|
-
return {
|
|
989
|
-
name: data.name ?? null,
|
|
990
|
-
url: data.url ?? null,
|
|
991
|
-
iconUrl: data.icon_url ?? null,
|
|
992
|
-
proxyIconUrl: data.proxy_icon_url ?? null
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
function toMessageEmbedFooter(data) {
|
|
996
|
-
return {
|
|
997
|
-
text: data.text,
|
|
998
|
-
iconUrl: data.icon_url ?? null,
|
|
999
|
-
proxyIconUrl: data.proxy_icon_url ?? null
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
function toMessageEmbedMedia(data) {
|
|
1003
|
-
return {
|
|
1004
|
-
url: data.url,
|
|
1005
|
-
proxyUrl: data.proxy_url ?? null,
|
|
1006
|
-
contentType: data.content_type ?? null,
|
|
1007
|
-
contentHash: data.content_hash ?? null,
|
|
1008
|
-
width: data.width ?? null,
|
|
1009
|
-
height: data.height ?? null,
|
|
1010
|
-
description: data.description ?? null,
|
|
1011
|
-
placeholder: data.placeholder ?? null,
|
|
1012
|
-
duration: data.duration ?? null,
|
|
1013
|
-
flags: data.flags ?? null
|
|
1014
|
-
};
|
|
1015
|
-
}
|
|
1016
|
-
function toMessageEmbed(data) {
|
|
1017
|
-
const full = data;
|
|
1018
|
-
return {
|
|
1019
|
-
type: data.type ?? "rich",
|
|
1020
|
-
url: data.url ?? null,
|
|
1021
|
-
title: data.title ?? null,
|
|
1022
|
-
color: data.color ?? null,
|
|
1023
|
-
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
1024
|
-
description: data.description ?? null,
|
|
1025
|
-
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
1026
|
-
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
1027
|
-
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
1028
|
-
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
1029
|
-
fields: (data.fields ?? []).map((f) => ({
|
|
1030
|
-
name: f.name,
|
|
1031
|
-
value: f.value,
|
|
1032
|
-
inline: f.inline ?? false
|
|
1033
|
-
})),
|
|
1034
|
-
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
1035
|
-
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
1036
|
-
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
1037
|
-
nsfw: data.nsfw ?? false,
|
|
1038
|
-
children: (full.children ?? []).map(toMessageEmbed),
|
|
1039
|
-
html: full.html ?? null,
|
|
1040
|
-
htmlWidth: full.html_width ?? null,
|
|
1041
|
-
htmlHeight: full.html_height ?? null
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1106
|
+
// src/Domain/Channel/Base.ts
|
|
1107
|
+
import { ChannelType as ChannelType3, Routes as Routes4 } from "@fluxerjs/types";
|
|
1108
|
+
import { SnowflakeUtil } from "@fluxerjs/util";
|
|
1044
1109
|
|
|
1045
|
-
// src/
|
|
1110
|
+
// src/ClientCore/MessageManager.ts
|
|
1046
1111
|
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1112
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
1113
|
+
var BULK = {
|
|
1114
|
+
requests: { min: 1, max: 25 },
|
|
1115
|
+
limit: { min: 1, max: 25 },
|
|
1116
|
+
totalMax: 250
|
|
1117
|
+
};
|
|
1118
|
+
function validateBulkMessageFetchRequests(requests) {
|
|
1119
|
+
const { requests: req, limit, totalMax } = BULK;
|
|
1120
|
+
if (requests.length < req.min || requests.length > req.max) {
|
|
1121
|
+
throw new FluxerError(`bulkFetchMessages requires between ${req.min} and ${req.max} requests`, {
|
|
1122
|
+
code: ErrorCodes.InvalidFetchLimit
|
|
1123
|
+
});
|
|
1050
1124
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1125
|
+
let total = 0;
|
|
1126
|
+
for (const request of requests) {
|
|
1127
|
+
if (request.limit < limit.min || request.limit > limit.max) {
|
|
1128
|
+
throw new FluxerError(
|
|
1129
|
+
`limit must be between ${limit.min} and ${limit.max} for channel ${request.channelId}`,
|
|
1130
|
+
{ code: ErrorCodes.InvalidFetchLimit }
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
total += request.limit;
|
|
1055
1134
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1135
|
+
if (total > totalMax) {
|
|
1136
|
+
throw new FluxerError(`bulkFetchMessages total message limit must not exceed ${totalMax}`, {
|
|
1137
|
+
code: ErrorCodes.InvalidFetchLimit
|
|
1138
|
+
});
|
|
1058
1139
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1140
|
+
}
|
|
1141
|
+
var MessageManager = class {
|
|
1142
|
+
constructor(client, channelId) {
|
|
1143
|
+
this.client = client;
|
|
1144
|
+
this.channelId = channelId;
|
|
1061
1145
|
}
|
|
1062
|
-
/**
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1146
|
+
/** Structure cache keyed by message id (identity for {@link get}). */
|
|
1147
|
+
_structures = new Collection2();
|
|
1148
|
+
/** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
|
|
1149
|
+
get(messageId) {
|
|
1150
|
+
const data = this.client._getMessageCache(this.channelId)?.get(messageId);
|
|
1151
|
+
if (!data) {
|
|
1152
|
+
this._structures.delete(messageId);
|
|
1153
|
+
return void 0;
|
|
1154
|
+
}
|
|
1155
|
+
const existing = this._structures.get(messageId);
|
|
1156
|
+
if (existing) return existing;
|
|
1157
|
+
const message = new Message(this.client, data);
|
|
1158
|
+
this._structures.set(messageId, message);
|
|
1159
|
+
return message;
|
|
1160
|
+
}
|
|
1161
|
+
/** Retrieve from cache, otherwise {@link fetch}. */
|
|
1162
|
+
async resolve(messageId) {
|
|
1163
|
+
return this.get(messageId) ?? this.fetch(messageId);
|
|
1164
|
+
}
|
|
1165
|
+
async fetch(idOrOptions) {
|
|
1166
|
+
return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
|
|
1167
|
+
}
|
|
1168
|
+
/** Cache API data and return a {@link Message} (reusing identity when present). */
|
|
1169
|
+
wrap(data) {
|
|
1170
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
1171
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
|
|
1172
|
+
const existing = this._structures.get(data.id);
|
|
1173
|
+
if (existing) {
|
|
1174
|
+
existing._patch(cached);
|
|
1175
|
+
return existing;
|
|
1176
|
+
}
|
|
1177
|
+
const message = new Message(this.client, cached);
|
|
1178
|
+
this._structures.set(data.id, message);
|
|
1179
|
+
return message;
|
|
1180
|
+
}
|
|
1181
|
+
/** Fetch a single message from the API. */
|
|
1182
|
+
async fetchOne(messageId) {
|
|
1183
|
+
try {
|
|
1184
|
+
const data = await this.client.rest.get(
|
|
1185
|
+
Routes2.channelMessage(this.channelId, messageId)
|
|
1186
|
+
);
|
|
1187
|
+
return this.wrap(data);
|
|
1188
|
+
} catch (err) {
|
|
1189
|
+
rethrowMapped(err, {
|
|
1190
|
+
notFound: {
|
|
1191
|
+
code: ErrorCodes.MessageNotFound,
|
|
1192
|
+
message: `Message ${messageId} not found in channel ${this.channelId}`
|
|
1193
|
+
},
|
|
1194
|
+
fallback: `Failed to fetch message ${messageId}`
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
/** Fetch multiple messages from the API with pagination/filtering. */
|
|
1199
|
+
async fetchMany(options) {
|
|
1200
|
+
if (options.limit != null && (options.limit < 1 || options.limit > 100)) {
|
|
1201
|
+
throw new FluxerError("limit must be between 1 and 100", {
|
|
1202
|
+
code: ErrorCodes.InvalidFetchLimit
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
const qs2 = new URLSearchParams();
|
|
1206
|
+
for (const key of ["limit", "before", "after", "around"]) {
|
|
1207
|
+
const value = options[key];
|
|
1208
|
+
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1068
1209
|
}
|
|
1210
|
+
const base = Routes2.channelMessages(this.channelId);
|
|
1211
|
+
const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
|
|
1212
|
+
const collection = new Collection2();
|
|
1213
|
+
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
1214
|
+
return collection;
|
|
1069
1215
|
}
|
|
1070
1216
|
};
|
|
1071
1217
|
|
|
1072
|
-
// src/
|
|
1073
|
-
import {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
16,
|
|
1083
|
-
20,
|
|
1084
|
-
22,
|
|
1085
|
-
24,
|
|
1086
|
-
28,
|
|
1087
|
-
32,
|
|
1088
|
-
40,
|
|
1089
|
-
44,
|
|
1090
|
-
48,
|
|
1091
|
-
56,
|
|
1092
|
-
60,
|
|
1093
|
-
64,
|
|
1094
|
-
80,
|
|
1095
|
-
96,
|
|
1096
|
-
100,
|
|
1097
|
-
128,
|
|
1098
|
-
160,
|
|
1099
|
-
240,
|
|
1100
|
-
256,
|
|
1101
|
-
300,
|
|
1102
|
-
320,
|
|
1103
|
-
480,
|
|
1104
|
-
512,
|
|
1105
|
-
600,
|
|
1106
|
-
640,
|
|
1107
|
-
1024,
|
|
1108
|
-
1280,
|
|
1109
|
-
1536,
|
|
1110
|
-
2048,
|
|
1111
|
-
3072,
|
|
1112
|
-
4096,
|
|
1113
|
-
8192,
|
|
1114
|
-
16384
|
|
1115
|
-
];
|
|
1116
|
-
var CDN_ASSET_CLASS_RANGE = {
|
|
1117
|
-
icon: { min: 128, max: 1024 },
|
|
1118
|
-
banner: { min: 480, max: 2400 },
|
|
1119
|
-
emoji: { min: 32, max: 512 },
|
|
1120
|
-
sticker: { min: 128, max: 512 }
|
|
1121
|
-
};
|
|
1122
|
-
function nearestSize(requested, candidates) {
|
|
1123
|
-
let best = candidates[0];
|
|
1124
|
-
let bestDist = Math.abs(requested - best);
|
|
1125
|
-
for (let i = 1; i < candidates.length; i++) {
|
|
1126
|
-
const step = candidates[i];
|
|
1127
|
-
const dist = Math.abs(requested - step);
|
|
1128
|
-
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1129
|
-
best = step;
|
|
1130
|
-
bestDist = dist;
|
|
1131
|
-
}
|
|
1218
|
+
// src/Helpers/MessageCollector.ts
|
|
1219
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
1220
|
+
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
1221
|
+
function requireCollectorBounds(options) {
|
|
1222
|
+
const time = options.time ?? 0;
|
|
1223
|
+
const max = options.max ?? 0;
|
|
1224
|
+
if (time <= 0 && max <= 0) {
|
|
1225
|
+
throw new FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
1226
|
+
code: ErrorCodes.CollectorOptionsRequired
|
|
1227
|
+
});
|
|
1132
1228
|
}
|
|
1133
|
-
return best;
|
|
1134
|
-
}
|
|
1135
|
-
function snapCdnSize(requested, assetClass) {
|
|
1136
|
-
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1137
|
-
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1138
|
-
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1139
|
-
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1140
|
-
return nearestSize(clamped, allowed);
|
|
1141
|
-
}
|
|
1142
|
-
function mediaBase(options) {
|
|
1143
|
-
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1144
|
-
}
|
|
1145
|
-
function staticBase(options) {
|
|
1146
|
-
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
1147
|
-
}
|
|
1148
|
-
function getExtension(hash, options) {
|
|
1149
|
-
const ext = options?.extension ?? "png";
|
|
1150
|
-
if (hash?.startsWith("a_")) return "gif";
|
|
1151
|
-
return ext;
|
|
1152
|
-
}
|
|
1153
|
-
function appendSize(options, assetClass) {
|
|
1154
|
-
const size = options?.size;
|
|
1155
|
-
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1156
|
-
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1157
|
-
}
|
|
1158
|
-
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1159
|
-
if (!avatarHash) return null;
|
|
1160
|
-
const ext = getExtension(avatarHash, options);
|
|
1161
|
-
const size = appendSize(options, "icon");
|
|
1162
|
-
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1163
|
-
}
|
|
1164
|
-
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1165
|
-
if (!bannerHash) return null;
|
|
1166
|
-
const ext = getExtension(bannerHash, options);
|
|
1167
|
-
const size = appendSize(options, "banner");
|
|
1168
|
-
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1169
|
-
}
|
|
1170
|
-
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1171
|
-
if (!avatarHash) return null;
|
|
1172
|
-
const ext = getExtension(avatarHash, options);
|
|
1173
|
-
const size = appendSize(options, "icon");
|
|
1174
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1175
|
-
}
|
|
1176
|
-
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1177
|
-
if (!bannerHash) return null;
|
|
1178
|
-
const ext = getExtension(bannerHash, options);
|
|
1179
|
-
const size = appendSize(options, "banner");
|
|
1180
|
-
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1181
|
-
}
|
|
1182
|
-
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
1183
|
-
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
1184
|
-
return `${staticBase(options)}/avatars/${index}.png`;
|
|
1185
|
-
}
|
|
1186
|
-
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1187
|
-
if (!hash) return null;
|
|
1188
|
-
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1189
|
-
const size = appendSize(options, assetClass);
|
|
1190
|
-
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1191
|
-
}
|
|
1192
|
-
function cdnEmojiURL(emojiId, animated, options) {
|
|
1193
|
-
const ext = animated ? "gif" : "png";
|
|
1194
|
-
const size = appendSize(options, "emoji");
|
|
1195
|
-
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1196
1229
|
}
|
|
1197
|
-
|
|
1198
|
-
const ext = animated ? "gif" : "png";
|
|
1199
|
-
const size = appendSize(options, "sticker");
|
|
1200
|
-
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
// src/Domain/Message/MessageSticker.ts
|
|
1204
|
-
var MessageSticker = class extends Base {
|
|
1230
|
+
var MessageCollector = class _MessageCollector extends EventEmitter2 {
|
|
1205
1231
|
client;
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1232
|
+
channelId;
|
|
1233
|
+
options;
|
|
1234
|
+
collected = new Collection3();
|
|
1235
|
+
_timeout = null;
|
|
1236
|
+
_ended = false;
|
|
1237
|
+
_listener;
|
|
1238
|
+
constructor(client, channelId, options = {}) {
|
|
1212
1239
|
super();
|
|
1240
|
+
requireCollectorBounds(options);
|
|
1213
1241
|
this.client = client;
|
|
1214
|
-
this.
|
|
1215
|
-
this.
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1242
|
+
this.channelId = channelId;
|
|
1243
|
+
this.options = {
|
|
1244
|
+
filter: options.filter ?? (() => true),
|
|
1245
|
+
time: options.time ?? 0,
|
|
1246
|
+
max: options.max ?? 0
|
|
1247
|
+
};
|
|
1248
|
+
this._listener = (message) => {
|
|
1249
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
1250
|
+
if (!this.options.filter(message)) return;
|
|
1251
|
+
this.collected.set(message.id, message);
|
|
1252
|
+
this.emit("collect", message);
|
|
1253
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
1254
|
+
this.stop("limit");
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
1258
|
+
if (this.options.time > 0) {
|
|
1259
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
1260
|
+
}
|
|
1219
1261
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1262
|
+
stop(reason = "user") {
|
|
1263
|
+
if (this._ended) return;
|
|
1264
|
+
this._ended = true;
|
|
1265
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
1266
|
+
if (this._timeout) {
|
|
1267
|
+
clearTimeout(this._timeout);
|
|
1268
|
+
this._timeout = null;
|
|
1269
|
+
}
|
|
1270
|
+
this.emit("end", this.collected, reason);
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* One-shot helper used by {@link Channel.awaitMessages}.
|
|
1274
|
+
* Resolves with the collected messages when the collector ends for `user` (or when
|
|
1275
|
+
* the end reason is not listed in `errors`).
|
|
1276
|
+
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
1277
|
+
* (`CollectorIdle` / `CollectorMax`).
|
|
1278
|
+
*/
|
|
1279
|
+
static awaitMessages(client, channelId, options) {
|
|
1280
|
+
const errors = options?.errors ?? ["time", "limit"];
|
|
1281
|
+
return new Promise((resolve, reject) => {
|
|
1282
|
+
const collector = new _MessageCollector(client, channelId, options);
|
|
1283
|
+
collector.on("end", (collected, reason) => {
|
|
1284
|
+
if (!errors.includes(reason)) {
|
|
1285
|
+
resolve(collected);
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
if (reason === "time") {
|
|
1289
|
+
reject(
|
|
1290
|
+
new FluxerError("Message collector timed out", {
|
|
1291
|
+
code: ErrorCodes.CollectorIdle
|
|
1292
|
+
})
|
|
1293
|
+
);
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (reason === "limit") {
|
|
1297
|
+
reject(
|
|
1298
|
+
new FluxerError("Message collector reached max", {
|
|
1299
|
+
code: ErrorCodes.CollectorMax
|
|
1300
|
+
})
|
|
1301
|
+
);
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
reject(collected);
|
|
1305
|
+
});
|
|
1224
1306
|
});
|
|
1225
1307
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
return SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1308
|
+
on(event, listener) {
|
|
1309
|
+
return super.on(event, listener);
|
|
1229
1310
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
return SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1311
|
+
emit(event, ...args) {
|
|
1312
|
+
return super.emit(event, ...args);
|
|
1233
1313
|
}
|
|
1234
1314
|
};
|
|
1235
1315
|
|
|
1236
|
-
// src/Domain/
|
|
1237
|
-
import { Routes as
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1316
|
+
// src/Domain/Channel/Attachments.ts
|
|
1317
|
+
import { Routes as Routes3 } from "@fluxerjs/types";
|
|
1318
|
+
var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
|
|
1319
|
+
var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
1320
|
+
function instanceLimitOverridesSnapshot(client) {
|
|
1321
|
+
const rules = client.instance.discovery?.limits?.rules;
|
|
1322
|
+
if (!rules?.length) return null;
|
|
1323
|
+
const snapshot = {};
|
|
1324
|
+
for (const rule of rules) {
|
|
1325
|
+
Object.assign(snapshot, rule.overrides);
|
|
1326
|
+
}
|
|
1327
|
+
return Object.keys(snapshot).length ? snapshot : null;
|
|
1246
1328
|
}
|
|
1247
|
-
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
await message.client.rest.delete(Routes2.channelMessageReaction(message.channelId, message.id, e));
|
|
1258
|
-
}
|
|
1259
|
-
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
1260
|
-
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
1261
|
-
}
|
|
1262
|
-
async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
1263
|
-
const e = await emojiPath(message, emoji);
|
|
1264
|
-
const params = new URLSearchParams();
|
|
1265
|
-
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
1266
|
-
if (options?.after) params.set("after", options.after);
|
|
1267
|
-
const qs2 = params.toString();
|
|
1268
|
-
const route = Routes2.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
|
|
1269
|
-
const data = await message.client.rest.get(route);
|
|
1270
|
-
if (Array.isArray(data)) {
|
|
1271
|
-
return {
|
|
1272
|
-
users: data.map((u) => message.client.getOrCreateUser(u)),
|
|
1273
|
-
hasMore: false,
|
|
1274
|
-
nextAfter: null
|
|
1275
|
-
};
|
|
1329
|
+
function assertBotAttachmentLimits(client, files) {
|
|
1330
|
+
const snapshot = instanceLimitOverridesSnapshot(client);
|
|
1331
|
+
for (const file of files) {
|
|
1332
|
+
const size = file.data.byteLength;
|
|
1333
|
+
if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
|
|
1334
|
+
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
1335
|
+
throw new FluxerError(
|
|
1336
|
+
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
1337
|
+
{ code: ErrorCodes.AttachmentTooLarge }
|
|
1338
|
+
);
|
|
1276
1339
|
}
|
|
1277
|
-
const list = data.items ?? data.users ?? [];
|
|
1278
|
-
return {
|
|
1279
|
-
users: list.map((u) => message.client.getOrCreateUser(u)),
|
|
1280
|
-
hasMore: data.has_more ?? false,
|
|
1281
|
-
nextAfter: data.next_after ?? null
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
// src/Domain/Message/Send.ts
|
|
1286
|
-
import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
|
|
1287
|
-
import { Routes as Routes3 } from "@fluxerjs/types";
|
|
1288
|
-
function toReplyTarget(ref) {
|
|
1289
|
-
return {
|
|
1290
|
-
channelId: ref.channel_id,
|
|
1291
|
-
messageId: ref.message_id,
|
|
1292
|
-
...ref.guild_id != null ? { guildId: ref.guild_id } : {}
|
|
1293
|
-
};
|
|
1294
1340
|
}
|
|
1295
|
-
function
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1341
|
+
function asBytes(data) {
|
|
1342
|
+
const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
|
|
1343
|
+
const out = new Uint8Array(src.byteLength);
|
|
1344
|
+
out.set(src);
|
|
1345
|
+
return out;
|
|
1299
1346
|
}
|
|
1300
|
-
async function
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1347
|
+
async function putBlob(url, body, contentType) {
|
|
1348
|
+
const res = await fetch(url, {
|
|
1349
|
+
method: "PUT",
|
|
1350
|
+
headers: contentType ? { "Content-Type": contentType } : void 0,
|
|
1351
|
+
body
|
|
1352
|
+
});
|
|
1353
|
+
if (!res.ok) {
|
|
1354
|
+
throw new FluxerError(`Presigned upload failed: ${res.status}`, {
|
|
1355
|
+
code: ErrorCodes.AttachmentUploadFailed
|
|
1356
|
+
});
|
|
1308
1357
|
}
|
|
1309
|
-
return prepareMessagePostPayload(opts);
|
|
1310
|
-
}
|
|
1311
|
-
function asReplyTarget(value) {
|
|
1312
|
-
if ("messageId" in value) return value;
|
|
1313
|
-
return {
|
|
1314
|
-
channelId: value.channelId,
|
|
1315
|
-
messageId: value.id,
|
|
1316
|
-
guildId: value.guildId
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
async function sendPrepared(message, payload) {
|
|
1320
|
-
const data = await message.client.rest.post(
|
|
1321
|
-
Routes3.channelMessages(message.channelId),
|
|
1322
|
-
payload
|
|
1323
|
-
);
|
|
1324
|
-
message.client._addMessageToCache(message.channelId, data);
|
|
1325
|
-
return new message.constructor(message.client, data);
|
|
1326
|
-
}
|
|
1327
|
-
async function sendMessage(message, options) {
|
|
1328
|
-
return message._send(
|
|
1329
|
-
await prepareMessagePostPayload(options, {
|
|
1330
|
-
defaultAllowedMentions: message.client.options.defaultAllowedMentions
|
|
1331
|
-
})
|
|
1332
|
-
);
|
|
1333
1358
|
}
|
|
1334
|
-
async function
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1359
|
+
async function uploadAttachmentsForSend(client, channelId, files) {
|
|
1360
|
+
assertBotAttachmentLimits(client, files);
|
|
1361
|
+
const plan = await client.rest.post(
|
|
1362
|
+
Routes3.channelAttachments(channelId),
|
|
1363
|
+
{
|
|
1364
|
+
body: {
|
|
1365
|
+
attachments: files.map((f) => ({
|
|
1366
|
+
id: f.id,
|
|
1367
|
+
filename: f.filename,
|
|
1368
|
+
file_size: f.data.byteLength,
|
|
1369
|
+
content_type: f.contentType
|
|
1370
|
+
}))
|
|
1371
|
+
},
|
|
1372
|
+
auth: true
|
|
1373
|
+
}
|
|
1347
1374
|
);
|
|
1375
|
+
const multipart = [];
|
|
1376
|
+
const uploaded = [];
|
|
1377
|
+
for (const item of plan.attachments) {
|
|
1378
|
+
const file = files.find((f) => f.id === item.id);
|
|
1379
|
+
if (!file) {
|
|
1380
|
+
throw new FluxerError(`No file data for planned attachment id ${item.id}`, {
|
|
1381
|
+
code: ErrorCodes.InvalidAttachmentInput
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
const bytes = asBytes(file.data);
|
|
1385
|
+
if (item.upload_mode === "singlepart") {
|
|
1386
|
+
await putBlob(
|
|
1387
|
+
item.upload_url,
|
|
1388
|
+
new Blob([bytes], { type: file.contentType }),
|
|
1389
|
+
item.content_type
|
|
1390
|
+
);
|
|
1391
|
+
} else {
|
|
1392
|
+
for (const part of item.parts) {
|
|
1393
|
+
const start = (part.part_number - 1) * item.part_size;
|
|
1394
|
+
const chunk = bytes.subarray(start, Math.min(start + item.part_size, bytes.byteLength));
|
|
1395
|
+
await putBlob(part.upload_url, new Blob([asBytes(chunk)]));
|
|
1396
|
+
}
|
|
1397
|
+
multipart.push({ upload_filename: item.upload_filename, upload_id: item.upload_id });
|
|
1398
|
+
}
|
|
1399
|
+
uploaded.push({
|
|
1400
|
+
id: item.id,
|
|
1401
|
+
filename: item.filename,
|
|
1402
|
+
upload_filename: item.upload_filename,
|
|
1403
|
+
file_size: item.file_size,
|
|
1404
|
+
content_type: item.content_type
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
if (multipart.length) {
|
|
1408
|
+
await client.rest.post(Routes3.channelAttachmentsComplete(channelId), {
|
|
1409
|
+
body: { uploads: multipart },
|
|
1410
|
+
auth: true
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
return uploaded;
|
|
1348
1414
|
}
|
|
1349
1415
|
|
|
1350
|
-
// src/Domain/
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
1355
|
-
};
|
|
1356
|
-
}
|
|
1357
|
-
function toMessageSnapshot(client, data) {
|
|
1358
|
-
return {
|
|
1359
|
-
content: data.content ?? null,
|
|
1360
|
-
createdAt: new Date(data.timestamp),
|
|
1361
|
-
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
1362
|
-
mentionUserIds: data.mentions ?? [],
|
|
1363
|
-
mentionRoles: data.mention_roles ?? [],
|
|
1364
|
-
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
1365
|
-
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
1366
|
-
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
1367
|
-
...data.type !== void 0 ? { type: data.type } : {}
|
|
1368
|
-
};
|
|
1369
|
-
}
|
|
1370
|
-
function resolveMessageFlags(flags) {
|
|
1371
|
-
if (flags === void 0) return void 0;
|
|
1372
|
-
if (typeof flags === "number") return flags;
|
|
1373
|
-
return Number(MessageFlagsBitField.resolve(flags));
|
|
1374
|
-
}
|
|
1375
|
-
var Message = class _Message extends Base {
|
|
1376
|
-
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
1377
|
-
partial = false;
|
|
1378
|
-
/** The {@link Client} that instantiated this message. */
|
|
1416
|
+
// src/Domain/Channel/Base.ts
|
|
1417
|
+
var Channel = class extends Base {
|
|
1418
|
+
#messages;
|
|
1419
|
+
/** The {@link Client} that instantiated this channel. */
|
|
1379
1420
|
client;
|
|
1380
|
-
/** Snowflake ID of this
|
|
1421
|
+
/** Snowflake ID of this channel. */
|
|
1381
1422
|
id;
|
|
1382
|
-
/** Channel
|
|
1383
|
-
channelId;
|
|
1384
|
-
/** Guild ID if in a guild channel, null for DMs. */
|
|
1385
|
-
guildId;
|
|
1386
|
-
/** The user who sent this message. */
|
|
1387
|
-
author;
|
|
1388
|
-
/** Text content of the message. */
|
|
1389
|
-
content;
|
|
1390
|
-
/** When the message was created. */
|
|
1391
|
-
createdAt;
|
|
1392
|
-
/** When the message was last edited, or null if never edited. */
|
|
1393
|
-
editedAt;
|
|
1394
|
-
/** Whether the message is pinned. */
|
|
1395
|
-
pinned;
|
|
1396
|
-
/** Attached files (images, videos, etc.). */
|
|
1397
|
-
attachments;
|
|
1398
|
-
/** Message type (Default, Reply, etc.). */
|
|
1423
|
+
/** Channel type (text, voice, category, etc.). */
|
|
1399
1424
|
type;
|
|
1400
|
-
/**
|
|
1401
|
-
|
|
1402
|
-
/**
|
|
1403
|
-
|
|
1404
|
-
/**
|
|
1405
|
-
|
|
1406
|
-
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
1407
|
-
embeds;
|
|
1408
|
-
/** Stickers sent with the message. */
|
|
1409
|
-
stickers;
|
|
1410
|
-
/** Reactions on the message. */
|
|
1411
|
-
reactions;
|
|
1412
|
-
/** Reference to a replied-to message, if any. */
|
|
1413
|
-
messageReference;
|
|
1414
|
-
/** Message snapshots for forwarded messages. */
|
|
1415
|
-
messageSnapshots;
|
|
1416
|
-
/** Call data if this message represents a call event. */
|
|
1417
|
-
call;
|
|
1418
|
-
/** The full referenced (replied-to) message, or null. */
|
|
1419
|
-
referencedMessage;
|
|
1420
|
-
/** Webhook ID if sent by a webhook. */
|
|
1421
|
-
webhookId;
|
|
1422
|
-
/** Users mentioned in the message. */
|
|
1423
|
-
mentions;
|
|
1424
|
-
/** Role IDs mentioned in the message. */
|
|
1425
|
-
mentionRoles;
|
|
1426
|
-
/** Client-side nonce for deduplication. */
|
|
1427
|
-
nonce;
|
|
1428
|
-
/** IDs of custom emojis in the message classified as explicit. */
|
|
1429
|
-
nsfwEmojis;
|
|
1430
|
-
/**
|
|
1431
|
-
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
1432
|
-
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
1433
|
-
*/
|
|
1434
|
-
get channel() {
|
|
1435
|
-
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1436
|
-
return channel?.isTextBased() ? channel : null;
|
|
1437
|
-
}
|
|
1438
|
-
/** Cached guild, or null for DMs / uncached. */
|
|
1439
|
-
get guild() {
|
|
1440
|
-
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
1441
|
-
}
|
|
1442
|
-
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
1443
|
-
get member() {
|
|
1444
|
-
return this.guild?.members.get(this.author.id) ?? null;
|
|
1445
|
-
}
|
|
1446
|
-
/**
|
|
1447
|
-
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1448
|
-
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1449
|
-
* @example
|
|
1450
|
-
* const channel = await message.resolveChannel();
|
|
1451
|
-
* await channel.delete();
|
|
1452
|
-
*/
|
|
1453
|
-
async resolveChannel() {
|
|
1454
|
-
return this.client.channels.resolve(this.channelId);
|
|
1455
|
-
}
|
|
1456
|
-
/**
|
|
1457
|
-
* Fetch and resolve the guild, or null if a DM.
|
|
1458
|
-
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
1459
|
-
* @example
|
|
1460
|
-
* const guild = await message.resolveGuild();
|
|
1461
|
-
*/
|
|
1462
|
-
async resolveGuild() {
|
|
1463
|
-
if (!this.guildId) return null;
|
|
1464
|
-
return this.client.guilds.resolve(this.guildId);
|
|
1465
|
-
}
|
|
1466
|
-
/**
|
|
1467
|
-
* Construct a message from API data.
|
|
1468
|
-
* @param data - API message from REST or MESSAGE_CREATE
|
|
1469
|
-
*/
|
|
1425
|
+
/** Channel name (null for some channel types). */
|
|
1426
|
+
name;
|
|
1427
|
+
/** Channel icon hash (null for most channel types). */
|
|
1428
|
+
icon;
|
|
1429
|
+
/** ISO8601 timestamp of the last pinned message update. */
|
|
1430
|
+
lastPinTimestamp;
|
|
1470
1431
|
constructor(client, data) {
|
|
1471
1432
|
super();
|
|
1472
1433
|
this.client = client;
|
|
1473
1434
|
this.id = data.id;
|
|
1474
|
-
this.
|
|
1475
|
-
this.
|
|
1476
|
-
this.
|
|
1477
|
-
this.
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
this.
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
this.
|
|
1486
|
-
this.tts = data.tts ?? false;
|
|
1487
|
-
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1488
|
-
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
1489
|
-
this.reactions = new MessageReactionManager(this);
|
|
1490
|
-
this.reactions._patch(data.reactions);
|
|
1491
|
-
this.messageReference = data.message_reference ? {
|
|
1492
|
-
channelId: data.message_reference.channel_id,
|
|
1493
|
-
messageId: data.message_reference.message_id,
|
|
1494
|
-
guildId: data.message_reference.guild_id ?? null,
|
|
1495
|
-
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1496
|
-
} : null;
|
|
1497
|
-
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
1498
|
-
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1499
|
-
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
1500
|
-
this.webhookId = data.webhook_id ?? null;
|
|
1501
|
-
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
1502
|
-
this.mentionRoles = data.mention_roles ?? [];
|
|
1503
|
-
this.nonce = data.nonce ?? null;
|
|
1504
|
-
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1435
|
+
this.type = data.type;
|
|
1436
|
+
this.name = data.name ?? null;
|
|
1437
|
+
this.icon = data.icon ?? null;
|
|
1438
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1439
|
+
}
|
|
1440
|
+
/** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
|
|
1441
|
+
get createdTimestamp() {
|
|
1442
|
+
return SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
1443
|
+
}
|
|
1444
|
+
/** Date when this channel was created, derived from its snowflake ID. */
|
|
1445
|
+
get createdAt() {
|
|
1446
|
+
return SnowflakeUtil.dateFromSnowflake(this.id);
|
|
1505
1447
|
}
|
|
1506
1448
|
/**
|
|
1507
|
-
* Apply
|
|
1449
|
+
* Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
|
|
1508
1450
|
* @internal
|
|
1509
1451
|
*/
|
|
1510
1452
|
_patch(data) {
|
|
1511
|
-
this.
|
|
1512
|
-
|
|
1513
|
-
this.
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1518
|
-
this.tts = data.tts ?? false;
|
|
1519
|
-
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1520
|
-
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1521
|
-
this.reactions._patch(data.reactions);
|
|
1522
|
-
this.messageReference = data.message_reference ? {
|
|
1523
|
-
channelId: data.message_reference.channel_id,
|
|
1524
|
-
messageId: data.message_reference.message_id,
|
|
1525
|
-
guildId: data.message_reference.guild_id ?? null,
|
|
1526
|
-
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1527
|
-
} : null;
|
|
1528
|
-
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1529
|
-
(s) => toMessageSnapshot(this.client, s)
|
|
1530
|
-
);
|
|
1531
|
-
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1532
|
-
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1533
|
-
this.webhookId = data.webhook_id ?? null;
|
|
1534
|
-
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1535
|
-
this.mentionRoles = data.mention_roles ?? [];
|
|
1536
|
-
this.nonce = data.nonce ?? null;
|
|
1537
|
-
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
1453
|
+
if (data.type !== void 0) this.type = data.type;
|
|
1454
|
+
if (data.name !== void 0) this.name = data.name ?? null;
|
|
1455
|
+
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
1456
|
+
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
1457
|
+
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
1458
|
+
}
|
|
1538
1459
|
}
|
|
1539
|
-
/**
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
*/
|
|
1543
|
-
async send(options) {
|
|
1544
|
-
return sendMessage(this, options);
|
|
1460
|
+
/** @internal Factory wired after subclasses load. */
|
|
1461
|
+
static from(_c, _d) {
|
|
1462
|
+
throw new Error("Channel.from not initialized");
|
|
1545
1463
|
}
|
|
1546
|
-
/**
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
*/
|
|
1550
|
-
async sendTo(channelId, options) {
|
|
1551
|
-
return sendMessageTo(this, channelId, options);
|
|
1464
|
+
/** @internal Factory wired after subclasses load. */
|
|
1465
|
+
static fromOrCreate(_c, _d) {
|
|
1466
|
+
throw new Error("Channel.fromOrCreate not initialized");
|
|
1552
1467
|
}
|
|
1553
|
-
/**
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
* await message.reply('Pong!');
|
|
1557
|
-
* await message.reply('No ping!', { ping: false });
|
|
1558
|
-
* await message.reply({ content: 'Silent', allowedMentions: AllowedMentions.suppressReplyPing });
|
|
1559
|
-
*/
|
|
1560
|
-
async reply(options, replyOptions) {
|
|
1561
|
-
return replyToMessage(this, options, replyOptions);
|
|
1468
|
+
/** @internal Factory wired after subclasses load. */
|
|
1469
|
+
static createDM(_c, _d) {
|
|
1470
|
+
throw new Error("Channel.createDM not initialized");
|
|
1562
1471
|
}
|
|
1563
1472
|
/**
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
1567
|
-
* const message = await Message.resolve(msg);
|
|
1568
|
-
* });
|
|
1473
|
+
* Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
|
|
1474
|
+
* Forum and media channels contain threads and do not accept `send`.
|
|
1475
|
+
* Checks {@link ChannelType}, not whether `send` exists on the instance.
|
|
1569
1476
|
*/
|
|
1570
|
-
|
|
1571
|
-
return
|
|
1477
|
+
isTextBased() {
|
|
1478
|
+
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
|
|
1572
1479
|
}
|
|
1573
|
-
/**
|
|
1574
|
-
|
|
1575
|
-
return
|
|
1480
|
+
/** Check if this is a guild channel, including threads, forums, and media channels. */
|
|
1481
|
+
isGuild() {
|
|
1482
|
+
return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildCategory || this.type === ChannelType3.GuildLink || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread || this.type === ChannelType3.GuildForum || this.type === ChannelType3.GuildMedia;
|
|
1576
1483
|
}
|
|
1577
|
-
/**
|
|
1578
|
-
|
|
1579
|
-
return
|
|
1484
|
+
/** Check if this is a thread (public, private, or announcement). */
|
|
1485
|
+
isThread() {
|
|
1486
|
+
return this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
|
|
1580
1487
|
}
|
|
1581
|
-
/**
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1488
|
+
/** Check if this is a forum channel. */
|
|
1489
|
+
isForum() {
|
|
1490
|
+
return this.type === ChannelType3.GuildForum;
|
|
1491
|
+
}
|
|
1492
|
+
/** Check if this is a media channel. */
|
|
1493
|
+
isMedia() {
|
|
1494
|
+
return this.type === ChannelType3.GuildMedia;
|
|
1495
|
+
}
|
|
1496
|
+
/** Check if this is a guild text channel. */
|
|
1497
|
+
isText() {
|
|
1498
|
+
return this.type === ChannelType3.GuildText;
|
|
1499
|
+
}
|
|
1500
|
+
/** Check if this is a guild announcement channel. */
|
|
1501
|
+
isAnnouncement() {
|
|
1502
|
+
return this.type === ChannelType3.GuildAnnouncement;
|
|
1503
|
+
}
|
|
1504
|
+
/** Check if this is a category channel. */
|
|
1505
|
+
isCategory() {
|
|
1506
|
+
return this.type === ChannelType3.GuildCategory;
|
|
1507
|
+
}
|
|
1508
|
+
/** Check if this is a DM, group DM, or personal notes channel. */
|
|
1509
|
+
isDM() {
|
|
1510
|
+
return this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes;
|
|
1511
|
+
}
|
|
1512
|
+
/** Check if this is a personal notes channel. */
|
|
1513
|
+
isPersonalNotes() {
|
|
1514
|
+
return this.type === ChannelType3.DMPersonalNotes;
|
|
1515
|
+
}
|
|
1516
|
+
/** Check if this is a voice channel. */
|
|
1517
|
+
isVoice() {
|
|
1518
|
+
return this.type === ChannelType3.GuildVoice;
|
|
1519
|
+
}
|
|
1520
|
+
/** Check if this is a link channel. */
|
|
1521
|
+
isLink() {
|
|
1522
|
+
return this.type === ChannelType3.GuildLink;
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Delete recent messages or an explicit ID list.
|
|
1526
|
+
* - `bulkDelete(5)` — fetch last 5 via {@link MessageManager} then delete (1–100)
|
|
1527
|
+
* - `bulkDelete(['id1'])` — single DELETE; 2–100 uses bulk-delete route
|
|
1528
|
+
*/
|
|
1529
|
+
async bulkDelete(countOrIds) {
|
|
1530
|
+
let ids;
|
|
1531
|
+
if (typeof countOrIds === "number") {
|
|
1532
|
+
if (!Number.isInteger(countOrIds) || countOrIds < 1 || countOrIds > 100) {
|
|
1533
|
+
throw new FluxerError("bulkDelete count must be between 1 and 100", {
|
|
1534
|
+
code: ErrorCodes.InvalidBulkDelete
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
ids = [
|
|
1538
|
+
...(await new MessageManager(this.client, this.id).fetch({ limit: countOrIds })).keys()
|
|
1539
|
+
];
|
|
1540
|
+
} else {
|
|
1541
|
+
ids = [...countOrIds];
|
|
1589
1542
|
}
|
|
1590
|
-
if (
|
|
1591
|
-
|
|
1543
|
+
if (ids.length === 0) return [];
|
|
1544
|
+
if (ids.length === 1) {
|
|
1545
|
+
await this.client.rest.delete(Routes4.channelMessage(this.id, ids[0]), { auth: true });
|
|
1546
|
+
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
1547
|
+
return ids;
|
|
1592
1548
|
}
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1549
|
+
if (ids.length > 100) {
|
|
1550
|
+
throw new FluxerError("bulkDelete requires at most 100 message IDs", {
|
|
1551
|
+
code: ErrorCodes.InvalidBulkDelete
|
|
1552
|
+
});
|
|
1597
1553
|
}
|
|
1598
|
-
|
|
1599
|
-
body
|
|
1554
|
+
await this.client.rest.post(Routes4.channelBulkDelete(this.id), {
|
|
1555
|
+
body: { message_ids: ids },
|
|
1556
|
+
auth: true
|
|
1557
|
+
});
|
|
1558
|
+
for (const id of ids) this.client._removeMessageFromCache(this.id, id);
|
|
1559
|
+
return ids;
|
|
1560
|
+
}
|
|
1561
|
+
/** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
|
|
1562
|
+
async bulkDeleteMyMessages(options) {
|
|
1563
|
+
const body = options ? toSudoBody(options) : void 0;
|
|
1564
|
+
await this.client.rest.post(Routes4.channelBulkDeleteMine(this.id), {
|
|
1565
|
+
body: body && Object.keys(body).length ? body : void 0,
|
|
1566
|
+
auth: true
|
|
1600
1567
|
});
|
|
1601
|
-
const updated = new _Message(this.client, data);
|
|
1602
|
-
this.client._addMessageToCache(this.channelId, data);
|
|
1603
|
-
return updated;
|
|
1604
1568
|
}
|
|
1605
|
-
/**
|
|
1606
|
-
|
|
1607
|
-
|
|
1569
|
+
/**
|
|
1570
|
+
* Mark all pinned messages as read in this channel.
|
|
1571
|
+
* Session-token helper; bots usually skip this.
|
|
1572
|
+
*/
|
|
1573
|
+
async acknowledgePins() {
|
|
1574
|
+
await this.client.rest.post(Routes4.channelPinsAck(this.id), { auth: true });
|
|
1608
1575
|
}
|
|
1609
1576
|
/**
|
|
1610
|
-
*
|
|
1611
|
-
*
|
|
1577
|
+
* Clear the read state for this channel.
|
|
1578
|
+
* Session-token helper; bots usually skip this.
|
|
1612
1579
|
*/
|
|
1613
|
-
|
|
1614
|
-
|
|
1580
|
+
async clearReadState() {
|
|
1581
|
+
await this.client.rest.delete(Routes4.channelMessagesAck(this.id), { auth: true });
|
|
1615
1582
|
}
|
|
1616
|
-
/**
|
|
1617
|
-
async
|
|
1618
|
-
|
|
1583
|
+
/** Request upload URLs for attachments before sending a message. */
|
|
1584
|
+
async requestAttachmentUploads(attachments) {
|
|
1585
|
+
const data = await this.client.rest.post(
|
|
1586
|
+
Routes4.channelAttachments(this.id),
|
|
1587
|
+
{
|
|
1588
|
+
body: toAttachmentUploadPlanBody(attachments),
|
|
1589
|
+
auth: true
|
|
1590
|
+
}
|
|
1591
|
+
);
|
|
1592
|
+
return toAttachmentUploadPlanResponse(data);
|
|
1619
1593
|
}
|
|
1620
|
-
/**
|
|
1621
|
-
async
|
|
1622
|
-
await this.client.rest.
|
|
1623
|
-
|
|
1594
|
+
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
1595
|
+
async completeAttachmentUploads(uploads) {
|
|
1596
|
+
const data = await this.client.rest.post(
|
|
1597
|
+
Routes4.channelAttachmentsComplete(this.id),
|
|
1598
|
+
{
|
|
1599
|
+
body: toAttachmentUploadCompleteBody(uploads),
|
|
1600
|
+
auth: true
|
|
1601
|
+
}
|
|
1602
|
+
);
|
|
1603
|
+
return {
|
|
1604
|
+
uploads: data.uploads.map((u) => ({ uploadFilename: u.upload_filename }))
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
/** Upload files for sending in a message (helper). */
|
|
1608
|
+
async uploadAttachmentsForSend(files) {
|
|
1609
|
+
return uploadAttachmentsForSend(this.client, this.id, files);
|
|
1610
|
+
}
|
|
1611
|
+
/** Trigger the typing indicator in this channel. */
|
|
1612
|
+
async sendTyping() {
|
|
1613
|
+
await this.client.rest.post(Routes4.channelTyping(this.id), { auth: true });
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Fetch available RTC regions for voice channels.
|
|
1617
|
+
* User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
|
|
1618
|
+
* Bots should skip this and join voice with `@fluxerjs/voice` instead.
|
|
1619
|
+
*/
|
|
1620
|
+
async fetchRtcRegions() {
|
|
1621
|
+
const data = await this.client.rest.get(Routes4.channelRtcRegions(this.id), {
|
|
1622
|
+
auth: true
|
|
1624
1623
|
});
|
|
1625
|
-
|
|
1624
|
+
return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
|
|
1626
1625
|
}
|
|
1627
|
-
/**
|
|
1628
|
-
async
|
|
1629
|
-
await this.client.rest.
|
|
1630
|
-
Routes4.
|
|
1626
|
+
/** Fetch slowmode state for this channel. */
|
|
1627
|
+
async fetchSlowmode() {
|
|
1628
|
+
const data = await this.client.rest.get(
|
|
1629
|
+
Routes4.channelSlowmode(this.id),
|
|
1631
1630
|
{ auth: true }
|
|
1632
1631
|
);
|
|
1633
|
-
|
|
1632
|
+
return {
|
|
1633
|
+
rateLimitPerUser: data.rate_limit_per_user,
|
|
1634
|
+
retryAfterMs: data.retry_after_ms,
|
|
1635
|
+
nextSendAllowedAt: data.next_send_allowed_at
|
|
1636
|
+
};
|
|
1634
1637
|
}
|
|
1635
|
-
/**
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
this.pinned = true;
|
|
1638
|
+
/** Whether this channel type can carry messages (does not check permissions). */
|
|
1639
|
+
canSendMessage() {
|
|
1640
|
+
return this.isTextBased();
|
|
1639
1641
|
}
|
|
1640
|
-
/**
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1642
|
+
/** Per-channel message cache + fetch. */
|
|
1643
|
+
get messages() {
|
|
1644
|
+
if (!this.#messages) {
|
|
1645
|
+
this.#messages = new MessageManager(this.client, this.id);
|
|
1646
|
+
}
|
|
1647
|
+
return this.#messages;
|
|
1644
1648
|
}
|
|
1645
|
-
/**
|
|
1646
|
-
|
|
1647
|
-
return
|
|
1649
|
+
/** Collect messages in this channel until time/max/stop. */
|
|
1650
|
+
createMessageCollector(options) {
|
|
1651
|
+
return new MessageCollector(this.client, this.id, options);
|
|
1648
1652
|
}
|
|
1649
|
-
/**
|
|
1650
|
-
|
|
1651
|
-
|
|
1653
|
+
/**
|
|
1654
|
+
* Wait for messages matching the filter, then resolve the collected set.
|
|
1655
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1656
|
+
* @example
|
|
1657
|
+
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
1658
|
+
*/
|
|
1659
|
+
awaitMessages(options) {
|
|
1660
|
+
return MessageCollector.awaitMessages(this.client, this.id, options);
|
|
1652
1661
|
}
|
|
1653
|
-
/**
|
|
1654
|
-
|
|
1655
|
-
|
|
1662
|
+
/**
|
|
1663
|
+
* Delete this channel (or close it if it is a DM).
|
|
1664
|
+
* Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
|
|
1665
|
+
* @example
|
|
1666
|
+
* const channel = await client.channels.fetch(channelId);
|
|
1667
|
+
* await channel.delete();
|
|
1668
|
+
*/
|
|
1669
|
+
async delete(options) {
|
|
1670
|
+
const params = new URLSearchParams();
|
|
1671
|
+
if (options?.silent) params.set("silent", "true");
|
|
1672
|
+
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
1673
|
+
const qs2 = params.toString();
|
|
1674
|
+
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
1675
|
+
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
1676
|
+
await this.client.rest.delete(Routes4.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
1677
|
+
body,
|
|
1678
|
+
auth: true,
|
|
1679
|
+
...auditReasonHeaders(_reason)
|
|
1680
|
+
});
|
|
1681
|
+
this.client.channels.delete(this.id);
|
|
1682
|
+
this.client._clearMessageCache(this.id);
|
|
1683
|
+
if (this.isGuild() && this.guildId) {
|
|
1684
|
+
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
1685
|
+
}
|
|
1656
1686
|
}
|
|
1657
|
-
/**
|
|
1658
|
-
|
|
1659
|
-
return
|
|
1687
|
+
/** Channel mention (`<#id>`). */
|
|
1688
|
+
toString() {
|
|
1689
|
+
return `<#${this.id}>`;
|
|
1660
1690
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
// src/Domain/Channel/ThreadCache.ts
|
|
1694
|
+
function cacheThread(client, data) {
|
|
1695
|
+
const existing = client.channels.get(data.id);
|
|
1696
|
+
if (existing?.isThread() && existing.type === data.type) {
|
|
1697
|
+
existing._patch(data);
|
|
1698
|
+
placeThread(client, existing);
|
|
1699
|
+
return existing;
|
|
1664
1700
|
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1701
|
+
const created = Channel.from(client, data);
|
|
1702
|
+
if (!created.isThread()) {
|
|
1703
|
+
throw new FluxerError(`Channel ${data.id} is not a thread`, {
|
|
1704
|
+
code: ErrorCodes.InvalidChannelType
|
|
1705
|
+
});
|
|
1668
1706
|
}
|
|
1669
|
-
|
|
1707
|
+
placeThread(client, created);
|
|
1708
|
+
return created;
|
|
1709
|
+
}
|
|
1710
|
+
function placeThread(client, thread) {
|
|
1711
|
+
client.channels.set(thread.id, thread);
|
|
1712
|
+
if (!thread.guildId) return;
|
|
1713
|
+
const guild = client.guilds.get(thread.guildId);
|
|
1714
|
+
if (guild) guild.channels.set(thread.id, thread);
|
|
1715
|
+
}
|
|
1670
1716
|
|
|
1671
|
-
// src/Domain/Message/
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1717
|
+
// src/Domain/Message/Attachment.ts
|
|
1718
|
+
function toMessageAttachment(data) {
|
|
1719
|
+
return {
|
|
1720
|
+
id: data.id,
|
|
1721
|
+
filename: data.filename,
|
|
1722
|
+
title: data.title ?? null,
|
|
1723
|
+
description: data.description ?? null,
|
|
1724
|
+
contentType: data.content_type ?? null,
|
|
1725
|
+
contentHash: data.content_hash ?? null,
|
|
1726
|
+
size: data.size,
|
|
1727
|
+
url: data.url ?? null,
|
|
1728
|
+
proxyUrl: data.proxy_url ?? null,
|
|
1729
|
+
width: data.width ?? null,
|
|
1730
|
+
height: data.height ?? null,
|
|
1731
|
+
placeholder: data.placeholder ?? null,
|
|
1732
|
+
flags: data.flags ?? 0,
|
|
1733
|
+
nsfw: data.nsfw ?? false,
|
|
1734
|
+
duration: data.duration ?? null,
|
|
1735
|
+
waveform: data.waveform ?? null,
|
|
1736
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
1737
|
+
expired: data.expired ?? false
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
// src/Domain/Message/Embed.ts
|
|
1742
|
+
function toMessageEmbedAuthor(data) {
|
|
1743
|
+
return {
|
|
1744
|
+
name: data.name ?? null,
|
|
1745
|
+
url: data.url ?? null,
|
|
1746
|
+
iconUrl: data.icon_url ?? null,
|
|
1747
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
function toMessageEmbedFooter(data) {
|
|
1751
|
+
return {
|
|
1752
|
+
text: data.text,
|
|
1753
|
+
iconUrl: data.icon_url ?? null,
|
|
1754
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
function toMessageEmbedMedia(data) {
|
|
1758
|
+
return {
|
|
1759
|
+
url: data.url,
|
|
1760
|
+
proxyUrl: data.proxy_url ?? null,
|
|
1761
|
+
contentType: data.content_type ?? null,
|
|
1762
|
+
contentHash: data.content_hash ?? null,
|
|
1763
|
+
width: data.width ?? null,
|
|
1764
|
+
height: data.height ?? null,
|
|
1765
|
+
description: data.description ?? null,
|
|
1766
|
+
placeholder: data.placeholder ?? null,
|
|
1767
|
+
duration: data.duration ?? null,
|
|
1768
|
+
flags: data.flags ?? null
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
function toMessageEmbed(data) {
|
|
1772
|
+
const full = data;
|
|
1773
|
+
return {
|
|
1774
|
+
type: data.type ?? "rich",
|
|
1775
|
+
url: data.url ?? null,
|
|
1776
|
+
title: data.title ?? null,
|
|
1777
|
+
color: data.color ?? null,
|
|
1778
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
1779
|
+
description: data.description ?? null,
|
|
1780
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
1781
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
1782
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
1783
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
1784
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
1785
|
+
name: f.name,
|
|
1786
|
+
value: f.value,
|
|
1787
|
+
inline: f.inline ?? false
|
|
1788
|
+
})),
|
|
1789
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
1790
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
1791
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
1792
|
+
nsfw: data.nsfw ?? false,
|
|
1793
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
1794
|
+
html: full.html ?? null,
|
|
1795
|
+
htmlWidth: full.html_width ?? null,
|
|
1796
|
+
htmlHeight: full.html_height ?? null
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
1801
|
+
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
1802
|
+
var MessageReactionManager = class {
|
|
1803
|
+
constructor(message) {
|
|
1804
|
+
this.message = message;
|
|
1692
1805
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
get channel() {
|
|
1698
|
-
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1699
|
-
return channel?.isTextBased() ? channel : null;
|
|
1806
|
+
_cache = new Collection4();
|
|
1807
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
1808
|
+
get cache() {
|
|
1809
|
+
return this._cache;
|
|
1700
1810
|
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1704
|
-
* @example
|
|
1705
|
-
* const channel = await message.resolveChannel();
|
|
1706
|
-
* await channel.delete();
|
|
1707
|
-
*/
|
|
1708
|
-
async resolveChannel() {
|
|
1709
|
-
return this.client.channels.resolve(this.channelId);
|
|
1811
|
+
get size() {
|
|
1812
|
+
return this._cache.size;
|
|
1710
1813
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1814
|
+
[Symbol.iterator]() {
|
|
1815
|
+
return this._cache.values();
|
|
1816
|
+
}
|
|
1817
|
+
/** @internal Sync from an API message payload. */
|
|
1818
|
+
_patch(reactions) {
|
|
1819
|
+
this._cache.clear();
|
|
1820
|
+
for (const data of reactions ?? []) {
|
|
1821
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
1822
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
1823
|
+
}
|
|
1719
1824
|
}
|
|
1720
1825
|
};
|
|
1721
1826
|
|
|
1722
|
-
// src/Domain/
|
|
1723
|
-
import {
|
|
1724
|
-
import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
|
|
1827
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1828
|
+
import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
|
|
1725
1829
|
|
|
1726
|
-
// src/
|
|
1727
|
-
import {
|
|
1728
|
-
|
|
1830
|
+
// src/Helpers/Constants.ts
|
|
1831
|
+
import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
|
|
1832
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
1833
|
+
var STATIC_CDN_URL = "https://fluxerstatic.com";
|
|
1729
1834
|
|
|
1730
|
-
// src/
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1835
|
+
// src/Helpers/Cdn.ts
|
|
1836
|
+
var CDN_SIZE_LADDER = [
|
|
1837
|
+
16,
|
|
1838
|
+
20,
|
|
1839
|
+
22,
|
|
1840
|
+
24,
|
|
1841
|
+
28,
|
|
1842
|
+
32,
|
|
1843
|
+
40,
|
|
1844
|
+
44,
|
|
1845
|
+
48,
|
|
1846
|
+
56,
|
|
1847
|
+
60,
|
|
1848
|
+
64,
|
|
1849
|
+
80,
|
|
1850
|
+
96,
|
|
1851
|
+
100,
|
|
1852
|
+
128,
|
|
1853
|
+
160,
|
|
1854
|
+
240,
|
|
1855
|
+
256,
|
|
1856
|
+
300,
|
|
1857
|
+
320,
|
|
1858
|
+
480,
|
|
1859
|
+
512,
|
|
1860
|
+
600,
|
|
1861
|
+
640,
|
|
1862
|
+
1024,
|
|
1863
|
+
1280,
|
|
1864
|
+
1536,
|
|
1865
|
+
2048,
|
|
1866
|
+
3072,
|
|
1867
|
+
4096,
|
|
1868
|
+
8192,
|
|
1869
|
+
16384
|
|
1870
|
+
];
|
|
1871
|
+
var CDN_ASSET_CLASS_RANGE = {
|
|
1872
|
+
icon: { min: 128, max: 1024 },
|
|
1873
|
+
banner: { min: 480, max: 2400 },
|
|
1874
|
+
emoji: { min: 32, max: 512 },
|
|
1875
|
+
sticker: { min: 128, max: 512 }
|
|
1737
1876
|
};
|
|
1738
|
-
function
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
if (request.limit < limit.min || request.limit > limit.max) {
|
|
1748
|
-
throw new FluxerError(
|
|
1749
|
-
`limit must be between ${limit.min} and ${limit.max} for channel ${request.channelId}`,
|
|
1750
|
-
{ code: ErrorCodes.InvalidFetchLimit }
|
|
1751
|
-
);
|
|
1877
|
+
function nearestSize(requested, candidates) {
|
|
1878
|
+
let best = candidates[0];
|
|
1879
|
+
let bestDist = Math.abs(requested - best);
|
|
1880
|
+
for (let i = 1; i < candidates.length; i++) {
|
|
1881
|
+
const step = candidates[i];
|
|
1882
|
+
const dist = Math.abs(requested - step);
|
|
1883
|
+
if (dist < bestDist || dist === bestDist && step > best) {
|
|
1884
|
+
best = step;
|
|
1885
|
+
bestDist = dist;
|
|
1752
1886
|
}
|
|
1753
|
-
total += request.limit;
|
|
1754
|
-
}
|
|
1755
|
-
if (total > totalMax) {
|
|
1756
|
-
throw new FluxerError(`bulkFetchMessages total message limit must not exceed ${totalMax}`, {
|
|
1757
|
-
code: ErrorCodes.InvalidFetchLimit
|
|
1758
|
-
});
|
|
1759
1887
|
}
|
|
1888
|
+
return best;
|
|
1760
1889
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
}
|
|
1801
|
-
/** Fetch a single message from the API. */
|
|
1802
|
-
async fetchOne(messageId) {
|
|
1803
|
-
try {
|
|
1804
|
-
const data = await this.client.rest.get(
|
|
1805
|
-
Routes5.channelMessage(this.channelId, messageId)
|
|
1806
|
-
);
|
|
1807
|
-
return this.wrap(data);
|
|
1808
|
-
} catch (err) {
|
|
1809
|
-
rethrowMapped(err, {
|
|
1810
|
-
notFound: {
|
|
1811
|
-
code: ErrorCodes.MessageNotFound,
|
|
1812
|
-
message: `Message ${messageId} not found in channel ${this.channelId}`
|
|
1813
|
-
},
|
|
1814
|
-
fallback: `Failed to fetch message ${messageId}`
|
|
1815
|
-
});
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
/** Fetch multiple messages from the API with pagination/filtering. */
|
|
1819
|
-
async fetchMany(options) {
|
|
1820
|
-
if (options.limit != null && (options.limit < 1 || options.limit > 100)) {
|
|
1821
|
-
throw new FluxerError("limit must be between 1 and 100", {
|
|
1822
|
-
code: ErrorCodes.InvalidFetchLimit
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
const qs2 = new URLSearchParams();
|
|
1826
|
-
for (const key of ["limit", "before", "after", "around"]) {
|
|
1827
|
-
const value = options[key];
|
|
1828
|
-
if (value != null && value !== "") qs2.set(key, String(value));
|
|
1829
|
-
}
|
|
1830
|
-
const base = Routes5.channelMessages(this.channelId);
|
|
1831
|
-
const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
|
|
1832
|
-
const collection = new Collection4();
|
|
1833
|
-
for (const msg of data) collection.set(msg.id, this.wrap(msg));
|
|
1834
|
-
return collection;
|
|
1835
|
-
}
|
|
1836
|
-
};
|
|
1837
|
-
|
|
1838
|
-
// src/Helpers/MessageCollector.ts
|
|
1839
|
-
import { EventEmitter as EventEmitter2 } from "events";
|
|
1840
|
-
import { Collection as Collection5 } from "@fluxerjs/collection";
|
|
1841
|
-
function requireCollectorBounds(options) {
|
|
1842
|
-
const time = options.time ?? 0;
|
|
1843
|
-
const max = options.max ?? 0;
|
|
1844
|
-
if (time <= 0 && max <= 0) {
|
|
1845
|
-
throw new FluxerError("MessageCollector requires `time` and/or `max`", {
|
|
1846
|
-
code: ErrorCodes.CollectorOptionsRequired
|
|
1847
|
-
});
|
|
1848
|
-
}
|
|
1890
|
+
function snapCdnSize(requested, assetClass) {
|
|
1891
|
+
const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
|
|
1892
|
+
const snapped = nearestSize(requested, CDN_SIZE_LADDER);
|
|
1893
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
1894
|
+
const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
|
|
1895
|
+
return nearestSize(clamped, allowed);
|
|
1896
|
+
}
|
|
1897
|
+
function mediaBase(options) {
|
|
1898
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
1899
|
+
}
|
|
1900
|
+
function staticBase(options) {
|
|
1901
|
+
return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
|
|
1902
|
+
}
|
|
1903
|
+
function getExtension(hash, options) {
|
|
1904
|
+
const ext = options?.extension ?? "png";
|
|
1905
|
+
if (hash?.startsWith("a_")) return "gif";
|
|
1906
|
+
return ext;
|
|
1907
|
+
}
|
|
1908
|
+
function appendSize(options, assetClass) {
|
|
1909
|
+
const size = options?.size;
|
|
1910
|
+
if (size == null || !Number.isFinite(size) || size <= 0) return "";
|
|
1911
|
+
return `?size=${snapCdnSize(size, assetClass)}`;
|
|
1912
|
+
}
|
|
1913
|
+
function cdnAvatarURL(userId, avatarHash, options) {
|
|
1914
|
+
if (!avatarHash) return null;
|
|
1915
|
+
const ext = getExtension(avatarHash, options);
|
|
1916
|
+
const size = appendSize(options, "icon");
|
|
1917
|
+
return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
1918
|
+
}
|
|
1919
|
+
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
1920
|
+
if (!bannerHash) return null;
|
|
1921
|
+
const ext = getExtension(bannerHash, options);
|
|
1922
|
+
const size = appendSize(options, "banner");
|
|
1923
|
+
return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
1924
|
+
}
|
|
1925
|
+
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
1926
|
+
if (!avatarHash) return null;
|
|
1927
|
+
const ext = getExtension(avatarHash, options);
|
|
1928
|
+
const size = appendSize(options, "icon");
|
|
1929
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
1849
1930
|
}
|
|
1850
|
-
|
|
1931
|
+
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
1932
|
+
if (!bannerHash) return null;
|
|
1933
|
+
const ext = getExtension(bannerHash, options);
|
|
1934
|
+
const size = appendSize(options, "banner");
|
|
1935
|
+
return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
1936
|
+
}
|
|
1937
|
+
function cdnDefaultAvatarURL(userIdOrIndex, options) {
|
|
1938
|
+
const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
|
|
1939
|
+
return `${staticBase(options)}/avatars/${index}.png`;
|
|
1940
|
+
}
|
|
1941
|
+
function cdnGuildAssetURL(kind, id, hash, options) {
|
|
1942
|
+
if (!hash) return null;
|
|
1943
|
+
const assetClass = kind === "icons" ? "icon" : "banner";
|
|
1944
|
+
const size = appendSize(options, assetClass);
|
|
1945
|
+
return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
|
|
1946
|
+
}
|
|
1947
|
+
function cdnEmojiURL(emojiId, animated, options) {
|
|
1948
|
+
const ext = animated ? "gif" : "png";
|
|
1949
|
+
const size = appendSize(options, "emoji");
|
|
1950
|
+
return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
|
|
1951
|
+
}
|
|
1952
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
1953
|
+
const ext = animated ? "gif" : "png";
|
|
1954
|
+
const size = appendSize(options, "sticker");
|
|
1955
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
// src/Domain/Message/MessageSticker.ts
|
|
1959
|
+
var MessageSticker = class extends Base {
|
|
1851
1960
|
client;
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
constructor(client, channelId, options = {}) {
|
|
1961
|
+
id;
|
|
1962
|
+
name;
|
|
1963
|
+
description;
|
|
1964
|
+
tags;
|
|
1965
|
+
animated;
|
|
1966
|
+
constructor(client, data) {
|
|
1859
1967
|
super();
|
|
1860
|
-
requireCollectorBounds(options);
|
|
1861
1968
|
this.client = client;
|
|
1862
|
-
this.
|
|
1863
|
-
this.
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
};
|
|
1868
|
-
this._listener = (message) => {
|
|
1869
|
-
if (this._ended || message.channelId !== this.channelId) return;
|
|
1870
|
-
if (!this.options.filter(message)) return;
|
|
1871
|
-
this.collected.set(message.id, message);
|
|
1872
|
-
this.emit("collect", message);
|
|
1873
|
-
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
1874
|
-
this.stop("limit");
|
|
1875
|
-
}
|
|
1876
|
-
};
|
|
1877
|
-
this.client.on(Events.MessageCreate, this._listener);
|
|
1878
|
-
if (this.options.time > 0) {
|
|
1879
|
-
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
stop(reason = "user") {
|
|
1883
|
-
if (this._ended) return;
|
|
1884
|
-
this._ended = true;
|
|
1885
|
-
this.client.off(Events.MessageCreate, this._listener);
|
|
1886
|
-
if (this._timeout) {
|
|
1887
|
-
clearTimeout(this._timeout);
|
|
1888
|
-
this._timeout = null;
|
|
1889
|
-
}
|
|
1890
|
-
this.emit("end", this.collected, reason);
|
|
1969
|
+
this.id = data.id;
|
|
1970
|
+
this.name = data.name;
|
|
1971
|
+
this.description = data.description ?? "";
|
|
1972
|
+
this.tags = data.tags ?? [];
|
|
1973
|
+
this.animated = data.animated ?? false;
|
|
1891
1974
|
}
|
|
1892
|
-
/**
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
* By default, `time` and `limit` reject with {@link FluxerError}
|
|
1897
|
-
* (`CollectorIdle` / `CollectorMax`).
|
|
1898
|
-
*/
|
|
1899
|
-
static awaitMessages(client, channelId, options) {
|
|
1900
|
-
const errors = options?.errors ?? ["time", "limit"];
|
|
1901
|
-
return new Promise((resolve, reject) => {
|
|
1902
|
-
const collector = new _MessageCollector(client, channelId, options);
|
|
1903
|
-
collector.on("end", (collected, reason) => {
|
|
1904
|
-
if (!errors.includes(reason)) {
|
|
1905
|
-
resolve(collected);
|
|
1906
|
-
return;
|
|
1907
|
-
}
|
|
1908
|
-
if (reason === "time") {
|
|
1909
|
-
reject(
|
|
1910
|
-
new FluxerError("Message collector timed out", {
|
|
1911
|
-
code: ErrorCodes.CollectorIdle
|
|
1912
|
-
})
|
|
1913
|
-
);
|
|
1914
|
-
return;
|
|
1915
|
-
}
|
|
1916
|
-
if (reason === "limit") {
|
|
1917
|
-
reject(
|
|
1918
|
-
new FluxerError("Message collector reached max", {
|
|
1919
|
-
code: ErrorCodes.CollectorMax
|
|
1920
|
-
})
|
|
1921
|
-
);
|
|
1922
|
-
return;
|
|
1923
|
-
}
|
|
1924
|
-
reject(collected);
|
|
1925
|
-
});
|
|
1975
|
+
/** CDN URL for this sticker image. */
|
|
1976
|
+
get url() {
|
|
1977
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
1978
|
+
mediaBase: this.client.instance.endpoints.media
|
|
1926
1979
|
});
|
|
1927
1980
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1981
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
1982
|
+
get createdTimestamp() {
|
|
1983
|
+
return SnowflakeUtil2.timestampFromSnowflake(this.id);
|
|
1930
1984
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1985
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
1986
|
+
get createdAt() {
|
|
1987
|
+
return SnowflakeUtil2.dateFromSnowflake(this.id);
|
|
1933
1988
|
}
|
|
1934
1989
|
};
|
|
1935
1990
|
|
|
1936
|
-
// src/Domain/
|
|
1937
|
-
import { Routes as
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
function instanceLimitOverridesSnapshot(client) {
|
|
1941
|
-
const rules = client.instance.discovery?.limits?.rules;
|
|
1942
|
-
if (!rules?.length) return null;
|
|
1943
|
-
const snapshot = {};
|
|
1944
|
-
for (const rule of rules) {
|
|
1945
|
-
Object.assign(snapshot, rule.overrides);
|
|
1946
|
-
}
|
|
1947
|
-
return Object.keys(snapshot).length ? snapshot : null;
|
|
1991
|
+
// src/Domain/Message/Reactions.ts
|
|
1992
|
+
import { Routes as Routes5 } from "@fluxerjs/types";
|
|
1993
|
+
async function emojiPath(message, emoji) {
|
|
1994
|
+
return message.client.resolveEmoji(emoji, message.guildId);
|
|
1948
1995
|
}
|
|
1949
|
-
function
|
|
1950
|
-
const
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
|
|
1955
|
-
throw new FluxerError(
|
|
1956
|
-
`Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
|
|
1957
|
-
{ code: ErrorCodes.AttachmentTooLarge }
|
|
1958
|
-
);
|
|
1959
|
-
}
|
|
1996
|
+
async function reactToMessage(message, emoji) {
|
|
1997
|
+
const wire = await emojiPath(message, emoji);
|
|
1998
|
+
await message.client.rest.put(
|
|
1999
|
+
Routes5.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
2000
|
+
);
|
|
1960
2001
|
}
|
|
1961
|
-
function
|
|
1962
|
-
const
|
|
1963
|
-
const
|
|
1964
|
-
|
|
1965
|
-
return out;
|
|
2002
|
+
async function removeMessageReaction(message, emoji, userId) {
|
|
2003
|
+
const e = await emojiPath(message, emoji);
|
|
2004
|
+
const route = userId ? Routes5.channelMessageReactionUser(message.channelId, message.id, e, userId) : Routes5.channelMessageReactionMe(message.channelId, message.id, e);
|
|
2005
|
+
await message.client.rest.delete(route);
|
|
1966
2006
|
}
|
|
1967
|
-
async function
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
2007
|
+
async function removeAllMessageReactions(message) {
|
|
2008
|
+
await message.client.rest.delete(Routes5.channelMessageReactions(message.channelId, message.id));
|
|
2009
|
+
}
|
|
2010
|
+
async function removeMessageReactionEmoji(message, emoji) {
|
|
2011
|
+
const e = await emojiPath(message, emoji);
|
|
2012
|
+
await message.client.rest.delete(Routes5.channelMessageReaction(message.channelId, message.id, e));
|
|
2013
|
+
}
|
|
2014
|
+
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
2015
|
+
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
2016
|
+
}
|
|
2017
|
+
async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
2018
|
+
const e = await emojiPath(message, emoji);
|
|
2019
|
+
const params = new URLSearchParams();
|
|
2020
|
+
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
2021
|
+
if (options?.after) params.set("after", options.after);
|
|
2022
|
+
const qs2 = params.toString();
|
|
2023
|
+
const route = Routes5.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
|
|
2024
|
+
const data = await message.client.rest.get(route);
|
|
2025
|
+
if (Array.isArray(data)) {
|
|
2026
|
+
return {
|
|
2027
|
+
users: data.map((u) => message.client.getOrCreateUser(u)),
|
|
2028
|
+
hasMore: false,
|
|
2029
|
+
nextAfter: null
|
|
2030
|
+
};
|
|
1977
2031
|
}
|
|
2032
|
+
const list = data.items ?? data.users ?? [];
|
|
2033
|
+
return {
|
|
2034
|
+
users: list.map((u) => message.client.getOrCreateUser(u)),
|
|
2035
|
+
hasMore: data.has_more ?? false,
|
|
2036
|
+
nextAfter: data.next_after ?? null
|
|
2037
|
+
};
|
|
1978
2038
|
}
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
const file = files.find((f) => f.id === item.id);
|
|
1999
|
-
if (!file) {
|
|
2000
|
-
throw new FluxerError(`No file data for planned attachment id ${item.id}`, {
|
|
2001
|
-
code: ErrorCodes.InvalidAttachmentInput
|
|
2002
|
-
});
|
|
2003
|
-
}
|
|
2004
|
-
const bytes = asBytes(file.data);
|
|
2005
|
-
if (item.upload_mode === "singlepart") {
|
|
2006
|
-
await putBlob(
|
|
2007
|
-
item.upload_url,
|
|
2008
|
-
new Blob([bytes], { type: file.contentType }),
|
|
2009
|
-
item.content_type
|
|
2010
|
-
);
|
|
2011
|
-
} else {
|
|
2012
|
-
for (const part of item.parts) {
|
|
2013
|
-
const start = (part.part_number - 1) * item.part_size;
|
|
2014
|
-
const chunk = bytes.subarray(start, Math.min(start + item.part_size, bytes.byteLength));
|
|
2015
|
-
await putBlob(part.upload_url, new Blob([asBytes(chunk)]));
|
|
2016
|
-
}
|
|
2017
|
-
multipart.push({ upload_filename: item.upload_filename, upload_id: item.upload_id });
|
|
2018
|
-
}
|
|
2019
|
-
uploaded.push({
|
|
2020
|
-
id: item.id,
|
|
2021
|
-
filename: item.filename,
|
|
2022
|
-
upload_filename: item.upload_filename,
|
|
2023
|
-
file_size: item.file_size,
|
|
2024
|
-
content_type: item.content_type
|
|
2025
|
-
});
|
|
2039
|
+
|
|
2040
|
+
// src/Domain/Message/Send.ts
|
|
2041
|
+
import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
|
|
2042
|
+
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
2043
|
+
function toReplyTarget(ref) {
|
|
2044
|
+
return {
|
|
2045
|
+
channelId: ref.channel_id,
|
|
2046
|
+
messageId: ref.message_id,
|
|
2047
|
+
...ref.guild_id != null ? { guildId: ref.guild_id } : {}
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
function toSendOptions(content) {
|
|
2051
|
+
if (typeof content === "string") return { content };
|
|
2052
|
+
if (content instanceof MessagePayloadBuilder) return messagePayloadToSendOptions(content);
|
|
2053
|
+
return { ...content };
|
|
2054
|
+
}
|
|
2055
|
+
async function createMessageBody(content, referenced_message, ping) {
|
|
2056
|
+
if (typeof content === "string" && content.length === 0) {
|
|
2057
|
+
throw new FluxerError("Cannot send an empty message", { code: ErrorCodes.EmptyMessage });
|
|
2026
2058
|
}
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
});
|
|
2059
|
+
const opts = toSendOptions(content);
|
|
2060
|
+
if (referenced_message) {
|
|
2061
|
+
opts.replyTo = toReplyTarget(referenced_message);
|
|
2062
|
+
if (ping !== void 0) opts.ping = ping;
|
|
2032
2063
|
}
|
|
2033
|
-
return
|
|
2064
|
+
return prepareMessagePostPayload(opts);
|
|
2065
|
+
}
|
|
2066
|
+
function asReplyTarget(value) {
|
|
2067
|
+
if ("messageId" in value) return value;
|
|
2068
|
+
return {
|
|
2069
|
+
channelId: value.channelId,
|
|
2070
|
+
messageId: value.id,
|
|
2071
|
+
guildId: value.guildId
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
async function sendPrepared(message, payload) {
|
|
2075
|
+
const data = await message.client.rest.post(
|
|
2076
|
+
Routes6.channelMessages(message.channelId),
|
|
2077
|
+
payload
|
|
2078
|
+
);
|
|
2079
|
+
message.client._addMessageToCache(message.channelId, data);
|
|
2080
|
+
return new message.constructor(message.client, data);
|
|
2081
|
+
}
|
|
2082
|
+
async function sendMessage(message, options) {
|
|
2083
|
+
return message._send(
|
|
2084
|
+
await prepareMessagePostPayload(options, {
|
|
2085
|
+
defaultAllowedMentions: message.client.options.defaultAllowedMentions
|
|
2086
|
+
})
|
|
2087
|
+
);
|
|
2088
|
+
}
|
|
2089
|
+
async function sendMessageTo(message, channelId, options) {
|
|
2090
|
+
return message.client.channels.send(channelId, options);
|
|
2091
|
+
}
|
|
2092
|
+
async function replyToMessage(message, options, replyOptions) {
|
|
2093
|
+
const opts = typeof options === "string" ? { content: options } : { ...options };
|
|
2094
|
+
const { replyTo: inlineReplyTo, ping: inlinePing, ...sendOpts } = opts;
|
|
2095
|
+
const ping = replyOptions?.ping ?? inlinePing ?? message.client.options.defaultReplyPing;
|
|
2096
|
+
const replyTo = asReplyTarget(replyOptions?.replyTo ?? inlineReplyTo ?? message);
|
|
2097
|
+
return message._send(
|
|
2098
|
+
await prepareMessagePostPayload(
|
|
2099
|
+
{ ...sendOpts, replyTo, ping },
|
|
2100
|
+
{ defaultAllowedMentions: message.client.options.defaultAllowedMentions }
|
|
2101
|
+
)
|
|
2102
|
+
);
|
|
2034
2103
|
}
|
|
2035
2104
|
|
|
2036
|
-
// src/Domain/
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2105
|
+
// src/Domain/Message/Message.ts
|
|
2106
|
+
function toMessageCall(data) {
|
|
2107
|
+
return {
|
|
2108
|
+
participants: data.participants,
|
|
2109
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
function toMessageSnapshot(client, data) {
|
|
2113
|
+
return {
|
|
2114
|
+
content: data.content ?? null,
|
|
2115
|
+
createdAt: new Date(data.timestamp),
|
|
2116
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
2117
|
+
mentionUserIds: data.mentions ?? [],
|
|
2118
|
+
mentionRoles: data.mention_roles ?? [],
|
|
2119
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
2120
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
2121
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
2122
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
function resolveMessageFlags(flags) {
|
|
2126
|
+
if (flags === void 0) return void 0;
|
|
2127
|
+
if (typeof flags === "number") return flags;
|
|
2128
|
+
return Number(MessageFlagsBitField.resolve(flags));
|
|
2129
|
+
}
|
|
2130
|
+
var Message = class _Message extends Base {
|
|
2131
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
2132
|
+
partial = false;
|
|
2133
|
+
/** The {@link Client} that instantiated this message. */
|
|
2040
2134
|
client;
|
|
2041
|
-
/** Snowflake ID of this
|
|
2135
|
+
/** Snowflake ID of this message. */
|
|
2042
2136
|
id;
|
|
2043
|
-
/** Channel
|
|
2137
|
+
/** Channel ID where this message was sent. */
|
|
2138
|
+
channelId;
|
|
2139
|
+
/** Guild ID if in a guild channel, null for DMs. */
|
|
2140
|
+
guildId;
|
|
2141
|
+
/** The user who sent this message. */
|
|
2142
|
+
author;
|
|
2143
|
+
/** Text content of the message. */
|
|
2144
|
+
content;
|
|
2145
|
+
/** When the message was created. */
|
|
2146
|
+
createdAt;
|
|
2147
|
+
/** When the message was last edited, or null if never edited. */
|
|
2148
|
+
editedAt;
|
|
2149
|
+
/** Whether the message is pinned. */
|
|
2150
|
+
pinned;
|
|
2151
|
+
/** Attached files (images, videos, etc.). */
|
|
2152
|
+
attachments;
|
|
2153
|
+
/** Message type (Default, Reply, etc.). */
|
|
2044
2154
|
type;
|
|
2045
|
-
/**
|
|
2046
|
-
|
|
2047
|
-
/**
|
|
2048
|
-
|
|
2049
|
-
/**
|
|
2050
|
-
|
|
2155
|
+
/** Message flags bitfield. */
|
|
2156
|
+
flags;
|
|
2157
|
+
/** Whether `@everyone` or `@here` was mentioned. */
|
|
2158
|
+
mentionEveryone;
|
|
2159
|
+
/** Whether this is a text-to-speech message. */
|
|
2160
|
+
tts;
|
|
2161
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
2162
|
+
embeds;
|
|
2163
|
+
/** Stickers sent with the message. */
|
|
2164
|
+
stickers;
|
|
2165
|
+
/** Reactions on the message. */
|
|
2166
|
+
reactions;
|
|
2167
|
+
/** Reference to a replied-to message, if any. */
|
|
2168
|
+
messageReference;
|
|
2169
|
+
/** Message snapshots for forwarded messages. */
|
|
2170
|
+
messageSnapshots;
|
|
2171
|
+
/** Call data if this message represents a call event. */
|
|
2172
|
+
call;
|
|
2173
|
+
/** The full referenced (replied-to) message, or null. */
|
|
2174
|
+
referencedMessage;
|
|
2175
|
+
/** Webhook ID if sent by a webhook. */
|
|
2176
|
+
webhookId;
|
|
2177
|
+
/** Users mentioned in the message. */
|
|
2178
|
+
mentions;
|
|
2179
|
+
/** Role IDs mentioned in the message. */
|
|
2180
|
+
mentionRoles;
|
|
2181
|
+
/** Client-side nonce for deduplication. */
|
|
2182
|
+
nonce;
|
|
2183
|
+
/** IDs of custom emojis in the message classified as explicit. */
|
|
2184
|
+
nsfwEmojis;
|
|
2185
|
+
/** Thread started from this message, when the payload included one. */
|
|
2186
|
+
thread;
|
|
2187
|
+
/**
|
|
2188
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
2189
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
2190
|
+
*/
|
|
2191
|
+
get channel() {
|
|
2192
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
2193
|
+
return channel?.isTextBased() ? channel : null;
|
|
2194
|
+
}
|
|
2195
|
+
/** Cached guild, or null for DMs / uncached. */
|
|
2196
|
+
get guild() {
|
|
2197
|
+
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
2198
|
+
}
|
|
2199
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
2200
|
+
get member() {
|
|
2201
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
2202
|
+
}
|
|
2203
|
+
/**
|
|
2204
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
2205
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
2206
|
+
* @example
|
|
2207
|
+
* const channel = await message.resolveChannel();
|
|
2208
|
+
* await channel.delete();
|
|
2209
|
+
*/
|
|
2210
|
+
async resolveChannel() {
|
|
2211
|
+
return this.client.channels.resolve(this.channelId);
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
2214
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
2215
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
2216
|
+
* @example
|
|
2217
|
+
* const guild = await message.resolveGuild();
|
|
2218
|
+
*/
|
|
2219
|
+
async resolveGuild() {
|
|
2220
|
+
if (!this.guildId) return null;
|
|
2221
|
+
return this.client.guilds.resolve(this.guildId);
|
|
2222
|
+
}
|
|
2223
|
+
/**
|
|
2224
|
+
* Construct a message from API data.
|
|
2225
|
+
* @param data - API message from REST or MESSAGE_CREATE
|
|
2226
|
+
*/
|
|
2051
2227
|
constructor(client, data) {
|
|
2052
2228
|
super();
|
|
2053
2229
|
this.client = client;
|
|
2054
2230
|
this.id = data.id;
|
|
2055
|
-
this.
|
|
2056
|
-
this.
|
|
2057
|
-
this.
|
|
2058
|
-
this.
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2231
|
+
this.channelId = data.channel_id;
|
|
2232
|
+
this.guildId = data.guild_id ?? null;
|
|
2233
|
+
this.author = client.getOrCreateUser(data.author);
|
|
2234
|
+
this.content = data.content;
|
|
2235
|
+
this.createdAt = new Date(data.timestamp);
|
|
2236
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2237
|
+
this.pinned = data.pinned;
|
|
2238
|
+
this.attachments = new Collection5();
|
|
2239
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2240
|
+
this.type = data.type ?? MessageType.Default;
|
|
2241
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
2242
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
2243
|
+
this.tts = data.tts ?? false;
|
|
2244
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
2245
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
2246
|
+
this.reactions = new MessageReactionManager(this);
|
|
2247
|
+
this.reactions._patch(data.reactions);
|
|
2248
|
+
this.messageReference = data.message_reference ? {
|
|
2249
|
+
channelId: data.message_reference.channel_id,
|
|
2250
|
+
messageId: data.message_reference.message_id,
|
|
2251
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
2252
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
2253
|
+
} : null;
|
|
2254
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
2255
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
2256
|
+
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
2257
|
+
this.webhookId = data.webhook_id ?? null;
|
|
2258
|
+
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
2259
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
2260
|
+
this.nonce = data.nonce ?? null;
|
|
2261
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
2262
|
+
this.thread = data.thread ? cacheThread(client, data.thread) : null;
|
|
2063
2263
|
}
|
|
2064
|
-
/**
|
|
2065
|
-
|
|
2066
|
-
|
|
2264
|
+
/**
|
|
2265
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
2266
|
+
* @internal
|
|
2267
|
+
*/
|
|
2268
|
+
_patch(data) {
|
|
2269
|
+
this.content = data.content;
|
|
2270
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
2271
|
+
this.pinned = data.pinned;
|
|
2272
|
+
this.attachments.clear();
|
|
2273
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
2274
|
+
this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
2275
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
2276
|
+
this.tts = data.tts ?? false;
|
|
2277
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
2278
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
2279
|
+
this.reactions._patch(data.reactions);
|
|
2280
|
+
this.messageReference = data.message_reference ? {
|
|
2281
|
+
channelId: data.message_reference.channel_id,
|
|
2282
|
+
messageId: data.message_reference.message_id,
|
|
2283
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
2284
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
2285
|
+
} : null;
|
|
2286
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
2287
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
2288
|
+
);
|
|
2289
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
2290
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
2291
|
+
this.webhookId = data.webhook_id ?? null;
|
|
2292
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
2293
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
2294
|
+
this.nonce = data.nonce ?? null;
|
|
2295
|
+
this.nsfwEmojis = data.nsfw_emojis ?? [];
|
|
2296
|
+
if (data.thread) this.thread = cacheThread(this.client, data.thread);
|
|
2067
2297
|
}
|
|
2068
2298
|
/**
|
|
2069
|
-
*
|
|
2070
|
-
* @
|
|
2299
|
+
* Send a standalone message in this channel (not a reply).
|
|
2300
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
2071
2301
|
*/
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
if (data.name !== void 0) this.name = data.name ?? null;
|
|
2075
|
-
if (data.icon !== void 0) this.icon = data.icon ?? null;
|
|
2076
|
-
if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
|
|
2077
|
-
this.lastPinTimestamp = data.last_pin_timestamp ?? null;
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
/** @internal Factory wired after subclasses load. */
|
|
2081
|
-
static from(_c, _d) {
|
|
2082
|
-
throw new Error("Channel.from not initialized");
|
|
2083
|
-
}
|
|
2084
|
-
/** @internal Factory wired after subclasses load. */
|
|
2085
|
-
static fromOrCreate(_c, _d) {
|
|
2086
|
-
throw new Error("Channel.fromOrCreate not initialized");
|
|
2087
|
-
}
|
|
2088
|
-
/** @internal Factory wired after subclasses load. */
|
|
2089
|
-
static createDM(_c, _d) {
|
|
2090
|
-
throw new Error("Channel.createDM not initialized");
|
|
2302
|
+
async send(options) {
|
|
2303
|
+
return sendMessage(this, options);
|
|
2091
2304
|
}
|
|
2092
2305
|
/**
|
|
2093
|
-
*
|
|
2094
|
-
*
|
|
2306
|
+
* Send a message to another channel by ID.
|
|
2307
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
2095
2308
|
*/
|
|
2096
|
-
|
|
2097
|
-
return this
|
|
2098
|
-
}
|
|
2099
|
-
/** Check if this is a guild channel (text, voice, category, or link). */
|
|
2100
|
-
isGuild() {
|
|
2101
|
-
return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
|
|
2102
|
-
}
|
|
2103
|
-
/** Check if this is a guild text channel. */
|
|
2104
|
-
isText() {
|
|
2105
|
-
return this.type === ChannelType.GuildText;
|
|
2106
|
-
}
|
|
2107
|
-
/** Check if this is a category channel. */
|
|
2108
|
-
isCategory() {
|
|
2109
|
-
return this.type === ChannelType.GuildCategory;
|
|
2309
|
+
async sendTo(channelId, options) {
|
|
2310
|
+
return sendMessageTo(this, channelId, options);
|
|
2110
2311
|
}
|
|
2111
|
-
/**
|
|
2112
|
-
|
|
2113
|
-
|
|
2312
|
+
/**
|
|
2313
|
+
* Reply to this message.
|
|
2314
|
+
* @example
|
|
2315
|
+
* await message.reply('Pong!');
|
|
2316
|
+
* await message.reply('No ping!', { ping: false });
|
|
2317
|
+
* await message.reply({ content: 'Silent', allowedMentions: AllowedMentions.suppressReplyPing });
|
|
2318
|
+
*/
|
|
2319
|
+
async reply(options, replyOptions) {
|
|
2320
|
+
return replyToMessage(this, options, replyOptions);
|
|
2114
2321
|
}
|
|
2115
|
-
/**
|
|
2116
|
-
|
|
2117
|
-
|
|
2322
|
+
/**
|
|
2323
|
+
* Hydrate a partial message, or return the message as-is.
|
|
2324
|
+
* @example
|
|
2325
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
2326
|
+
* const message = await Message.resolve(msg);
|
|
2327
|
+
* });
|
|
2328
|
+
*/
|
|
2329
|
+
static async resolve(message) {
|
|
2330
|
+
return message.partial ? message.fetch() : message;
|
|
2118
2331
|
}
|
|
2119
|
-
/**
|
|
2120
|
-
|
|
2121
|
-
return
|
|
2332
|
+
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
2333
|
+
static async _createMessageBody(content, referenced_message, ping) {
|
|
2334
|
+
return createMessageBody(content, referenced_message, ping);
|
|
2122
2335
|
}
|
|
2123
|
-
/**
|
|
2124
|
-
|
|
2125
|
-
return this
|
|
2336
|
+
/** Send a prepared payload (internal helper). */
|
|
2337
|
+
async _send(payload) {
|
|
2338
|
+
return sendPrepared(this, payload);
|
|
2126
2339
|
}
|
|
2127
|
-
/**
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
if (!Number.isInteger(countOrIds) || countOrIds < 1 || countOrIds > 100) {
|
|
2136
|
-
throw new FluxerError("bulkDelete count must be between 1 and 100", {
|
|
2137
|
-
code: ErrorCodes.InvalidBulkDelete
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
ids = [
|
|
2141
|
-
...(await new MessageManager(this.client, this.id).fetch({ limit: countOrIds })).keys()
|
|
2142
|
-
];
|
|
2143
|
-
} else {
|
|
2144
|
-
ids = [...countOrIds];
|
|
2340
|
+
/** Edit this message (requires author or admin permissions). */
|
|
2341
|
+
async edit(options) {
|
|
2342
|
+
const body = {};
|
|
2343
|
+
if (options.content !== void 0) body.content = options.content;
|
|
2344
|
+
if (options.embeds !== void 0) {
|
|
2345
|
+
body.embeds = options.embeds.map(
|
|
2346
|
+
(e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
|
|
2347
|
+
);
|
|
2145
2348
|
}
|
|
2146
|
-
if (
|
|
2147
|
-
|
|
2148
|
-
await this.client.rest.delete(Routes7.channelMessage(this.id, ids[0]), { auth: true });
|
|
2149
|
-
this.client._removeMessageFromCache(this.id, ids[0]);
|
|
2150
|
-
return ids;
|
|
2349
|
+
if (options.allowedMentions) {
|
|
2350
|
+
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
2151
2351
|
}
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2352
|
+
const flags = resolveMessageFlags(options.flags);
|
|
2353
|
+
if (flags !== void 0) body.flags = flags;
|
|
2354
|
+
if (options.attachments !== void 0) {
|
|
2355
|
+
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
2156
2356
|
}
|
|
2157
|
-
await this.client.rest.
|
|
2158
|
-
body
|
|
2159
|
-
auth: true
|
|
2357
|
+
const data = await this.client.rest.patch(Routes7.channelMessage(this.channelId, this.id), {
|
|
2358
|
+
body
|
|
2160
2359
|
});
|
|
2161
|
-
|
|
2162
|
-
|
|
2360
|
+
const updated = new _Message(this.client, data);
|
|
2361
|
+
this.client._addMessageToCache(this.channelId, data);
|
|
2362
|
+
return updated;
|
|
2163
2363
|
}
|
|
2164
|
-
/**
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
await this.client.rest.post(Routes7.channelBulkDeleteMine(this.id), {
|
|
2168
|
-
body: body && Object.keys(body).length ? body : void 0,
|
|
2169
|
-
auth: true
|
|
2170
|
-
});
|
|
2364
|
+
/** Create a {@link ReactionCollector} for this message. */
|
|
2365
|
+
createReactionCollector(options) {
|
|
2366
|
+
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
2171
2367
|
}
|
|
2172
2368
|
/**
|
|
2173
|
-
*
|
|
2174
|
-
*
|
|
2369
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
2370
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
2175
2371
|
*/
|
|
2176
|
-
|
|
2177
|
-
|
|
2372
|
+
awaitReactions(options) {
|
|
2373
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
2178
2374
|
}
|
|
2179
2375
|
/**
|
|
2180
|
-
*
|
|
2181
|
-
*
|
|
2376
|
+
* Start a thread from this message.
|
|
2377
|
+
* Fluxer chooses a public or announcement thread from the parent channel.
|
|
2182
2378
|
*/
|
|
2183
|
-
async
|
|
2184
|
-
await this.client.rest.delete(Routes7.channelMessagesAck(this.id), { auth: true });
|
|
2185
|
-
}
|
|
2186
|
-
/** Request upload URLs for attachments before sending a message. */
|
|
2187
|
-
async requestAttachmentUploads(attachments) {
|
|
2188
|
-
const data = await this.client.rest.post(
|
|
2189
|
-
Routes7.channelAttachments(this.id),
|
|
2190
|
-
{
|
|
2191
|
-
body: toAttachmentUploadPlanBody(attachments),
|
|
2192
|
-
auth: true
|
|
2193
|
-
}
|
|
2194
|
-
);
|
|
2195
|
-
return toAttachmentUploadPlanResponse(data);
|
|
2196
|
-
}
|
|
2197
|
-
/** Complete the attachment upload flow after uploading to the CDN. */
|
|
2198
|
-
async completeAttachmentUploads(uploads) {
|
|
2379
|
+
async startThread(options) {
|
|
2199
2380
|
const data = await this.client.rest.post(
|
|
2200
|
-
Routes7.
|
|
2381
|
+
Routes7.channelMessageThreads(this.channelId, this.id),
|
|
2201
2382
|
{
|
|
2202
|
-
body:
|
|
2203
|
-
auth: true
|
|
2383
|
+
body: toStartThreadFromMessageBody(options),
|
|
2384
|
+
auth: true,
|
|
2385
|
+
...auditReasonHeaders(options.reason)
|
|
2204
2386
|
}
|
|
2205
2387
|
);
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2388
|
+
const thread = cacheThread(this.client, data);
|
|
2389
|
+
this.thread = thread;
|
|
2390
|
+
return thread;
|
|
2209
2391
|
}
|
|
2210
|
-
/**
|
|
2211
|
-
async
|
|
2212
|
-
return
|
|
2213
|
-
}
|
|
2214
|
-
/** Trigger the typing indicator in this channel. */
|
|
2215
|
-
async sendTyping() {
|
|
2216
|
-
await this.client.rest.post(Routes7.channelTyping(this.id), { auth: true });
|
|
2392
|
+
/** Fetch the latest version of this message from the API. */
|
|
2393
|
+
async fetch() {
|
|
2394
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2217
2395
|
}
|
|
2218
|
-
/**
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
*/
|
|
2223
|
-
async fetchRtcRegions() {
|
|
2224
|
-
const data = await this.client.rest.get(Routes7.channelRtcRegions(this.id), {
|
|
2225
|
-
auth: true
|
|
2396
|
+
/** Delete this message. */
|
|
2397
|
+
async delete(reason) {
|
|
2398
|
+
await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
|
|
2399
|
+
...auditReasonHeaders(reason)
|
|
2226
2400
|
});
|
|
2227
|
-
|
|
2401
|
+
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
2228
2402
|
}
|
|
2229
|
-
/**
|
|
2230
|
-
async
|
|
2231
|
-
|
|
2232
|
-
Routes7.
|
|
2403
|
+
/** Delete a specific attachment from this message. */
|
|
2404
|
+
async deleteAttachment(attachmentId) {
|
|
2405
|
+
await this.client.rest.delete(
|
|
2406
|
+
Routes7.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
2233
2407
|
{ auth: true }
|
|
2234
2408
|
);
|
|
2235
|
-
|
|
2236
|
-
rateLimitPerUser: data.rate_limit_per_user,
|
|
2237
|
-
retryAfterMs: data.retry_after_ms,
|
|
2238
|
-
nextSendAllowedAt: data.next_send_allowed_at
|
|
2239
|
-
};
|
|
2409
|
+
this.attachments.delete(attachmentId);
|
|
2240
2410
|
}
|
|
2241
|
-
/**
|
|
2242
|
-
|
|
2243
|
-
|
|
2411
|
+
/** Pin this message in the channel. */
|
|
2412
|
+
async pin() {
|
|
2413
|
+
await this.client.rest.put(Routes7.channelPinMessage(this.channelId, this.id));
|
|
2414
|
+
this.pinned = true;
|
|
2244
2415
|
}
|
|
2245
|
-
/**
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
}
|
|
2250
|
-
return this.#messages;
|
|
2416
|
+
/** Unpin this message from the channel. */
|
|
2417
|
+
async unpin() {
|
|
2418
|
+
await this.client.rest.delete(Routes7.channelPinMessage(this.channelId, this.id));
|
|
2419
|
+
this.pinned = false;
|
|
2251
2420
|
}
|
|
2252
|
-
/**
|
|
2253
|
-
|
|
2254
|
-
return
|
|
2421
|
+
/** React to this message with an emoji. */
|
|
2422
|
+
async react(emoji) {
|
|
2423
|
+
return reactToMessage(this, emoji);
|
|
2424
|
+
}
|
|
2425
|
+
/** Remove a reaction (bot's own or a user's if ID is provided). */
|
|
2426
|
+
async removeReaction(emoji, userId) {
|
|
2427
|
+
return removeMessageReaction(this, emoji, userId);
|
|
2428
|
+
}
|
|
2429
|
+
/** Remove all reactions from this message. */
|
|
2430
|
+
async removeAllReactions() {
|
|
2431
|
+
return removeAllMessageReactions(this);
|
|
2432
|
+
}
|
|
2433
|
+
/** Remove all reactions of a specific emoji. */
|
|
2434
|
+
async removeReactionEmoji(emoji) {
|
|
2435
|
+
return removeMessageReactionEmoji(this, emoji);
|
|
2436
|
+
}
|
|
2437
|
+
/** Fetch users who reacted with a specific emoji. */
|
|
2438
|
+
async fetchReactionUsers(emoji, options) {
|
|
2439
|
+
return fetchMessageReactionUsers(this, emoji, options);
|
|
2440
|
+
}
|
|
2441
|
+
/** Fetch reaction users with pagination metadata. */
|
|
2442
|
+
async fetchReactionUsersPage(emoji, options) {
|
|
2443
|
+
return fetchMessageReactionUsersPage(this, emoji, options);
|
|
2444
|
+
}
|
|
2445
|
+
};
|
|
2446
|
+
|
|
2447
|
+
// src/Domain/Message/PartialMessage.ts
|
|
2448
|
+
import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
|
|
2449
|
+
var PartialMessage = class {
|
|
2450
|
+
partial = true;
|
|
2451
|
+
client;
|
|
2452
|
+
id;
|
|
2453
|
+
channelId;
|
|
2454
|
+
guildId;
|
|
2455
|
+
content;
|
|
2456
|
+
authorId;
|
|
2457
|
+
author;
|
|
2458
|
+
createdAt;
|
|
2459
|
+
constructor(client, data) {
|
|
2460
|
+
this.client = client;
|
|
2461
|
+
this.id = data.id;
|
|
2462
|
+
this.channelId = data.channelId;
|
|
2463
|
+
this.guildId = data.guildId ?? null;
|
|
2464
|
+
this.content = data.content ?? null;
|
|
2465
|
+
this.authorId = data.authorId ?? null;
|
|
2466
|
+
this.author = data.author ?? null;
|
|
2467
|
+
this.createdAt = data.createdAt ?? (SnowflakeUtil3.isValid(data.id) ? SnowflakeUtil3.dateFromSnowflake(data.id) : null);
|
|
2255
2468
|
}
|
|
2256
2469
|
/**
|
|
2257
|
-
*
|
|
2258
|
-
*
|
|
2259
|
-
* @example
|
|
2260
|
-
* const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
|
|
2470
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
2471
|
+
* Same contract as {@link Message.channel}.
|
|
2261
2472
|
*/
|
|
2262
|
-
|
|
2263
|
-
|
|
2473
|
+
get channel() {
|
|
2474
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
2475
|
+
return channel?.isTextBased() ? channel : null;
|
|
2264
2476
|
}
|
|
2265
2477
|
/**
|
|
2266
|
-
*
|
|
2267
|
-
*
|
|
2478
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
2479
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
2268
2480
|
* @example
|
|
2269
|
-
* const channel = await
|
|
2481
|
+
* const channel = await message.resolveChannel();
|
|
2270
2482
|
* await channel.delete();
|
|
2271
2483
|
*/
|
|
2272
|
-
async
|
|
2273
|
-
|
|
2274
|
-
if (options?.silent) params.set("silent", "true");
|
|
2275
|
-
if (options?.deleteMessages) params.set("delete_messages", "true");
|
|
2276
|
-
const qs2 = params.toString();
|
|
2277
|
-
const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
|
|
2278
|
-
const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
|
|
2279
|
-
await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
|
|
2280
|
-
body,
|
|
2281
|
-
auth: true,
|
|
2282
|
-
...auditReasonHeaders(_reason)
|
|
2283
|
-
});
|
|
2284
|
-
this.client.channels.delete(this.id);
|
|
2285
|
-
this.client._clearMessageCache(this.id);
|
|
2286
|
-
if (this.isGuild() && this.guildId) {
|
|
2287
|
-
this.client.guilds.get(this.guildId)?.channels.delete(this.id);
|
|
2288
|
-
}
|
|
2484
|
+
async resolveChannel() {
|
|
2485
|
+
return this.client.channels.resolve(this.channelId);
|
|
2289
2486
|
}
|
|
2290
|
-
/**
|
|
2291
|
-
|
|
2292
|
-
|
|
2487
|
+
/**
|
|
2488
|
+
* Fetch the full message from the API.
|
|
2489
|
+
* @example
|
|
2490
|
+
* const message = await partial.fetch();
|
|
2491
|
+
* await message.reply('Pong!');
|
|
2492
|
+
*/
|
|
2493
|
+
async fetch() {
|
|
2494
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
2293
2495
|
}
|
|
2294
2496
|
};
|
|
2295
2497
|
|
|
2498
|
+
// src/Domain/User.ts
|
|
2499
|
+
import { Routes as Routes17 } from "@fluxerjs/types";
|
|
2500
|
+
import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
|
|
2501
|
+
|
|
2296
2502
|
// src/Domain/Channel/Dm.ts
|
|
2297
|
-
import { ChannelType as
|
|
2503
|
+
import { ChannelType as ChannelType4, Routes as Routes9 } from "@fluxerjs/types";
|
|
2298
2504
|
|
|
2299
2505
|
// src/Domain/Channel/TextCapable.ts
|
|
2300
2506
|
import { Routes as Routes8 } from "@fluxerjs/types";
|
|
@@ -2386,7 +2592,7 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2386
2592
|
* Notes-only; bots usually skip this.
|
|
2387
2593
|
*/
|
|
2388
2594
|
async purgeMessages() {
|
|
2389
|
-
if (this.type !==
|
|
2595
|
+
if (this.type !== ChannelType4.DMPersonalNotes) {
|
|
2390
2596
|
throw new FluxerError("purgeMessages is only available on personal notes channels", {
|
|
2391
2597
|
code: ErrorCodes.InvalidChannelType
|
|
2392
2598
|
});
|
|
@@ -2429,6 +2635,12 @@ var DMChannel = class extends TextCapable(Channel) {
|
|
|
2429
2635
|
}
|
|
2430
2636
|
};
|
|
2431
2637
|
|
|
2638
|
+
// src/Domain/Channel/Forum.ts
|
|
2639
|
+
import {
|
|
2640
|
+
ChannelType as ChannelType7,
|
|
2641
|
+
Routes as Routes16
|
|
2642
|
+
} from "@fluxerjs/types";
|
|
2643
|
+
|
|
2432
2644
|
// src/Domain/Channel/Guild.ts
|
|
2433
2645
|
import { Routes as Routes13 } from "@fluxerjs/types";
|
|
2434
2646
|
import { PermissionFlags } from "@fluxerjs/util";
|
|
@@ -2740,7 +2952,8 @@ var Invite = class _Invite extends Base {
|
|
|
2740
2952
|
// src/Domain/Webhook.ts
|
|
2741
2953
|
import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
|
|
2742
2954
|
import {
|
|
2743
|
-
Routes as Routes11
|
|
2955
|
+
Routes as Routes11,
|
|
2956
|
+
WebhookType
|
|
2744
2957
|
} from "@fluxerjs/types";
|
|
2745
2958
|
import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
|
|
2746
2959
|
var Webhook = class _Webhook extends Base {
|
|
@@ -2760,6 +2973,8 @@ var Webhook = class _Webhook extends Base {
|
|
|
2760
2973
|
token;
|
|
2761
2974
|
/** The user that created this webhook. */
|
|
2762
2975
|
user;
|
|
2976
|
+
/** Incoming or channel-follower webhook. */
|
|
2977
|
+
type;
|
|
2763
2978
|
constructor(client, data) {
|
|
2764
2979
|
super();
|
|
2765
2980
|
this.client = client;
|
|
@@ -2770,6 +2985,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
2770
2985
|
this.avatar = data.avatar ?? null;
|
|
2771
2986
|
this.token = data.token ?? null;
|
|
2772
2987
|
this.user = client.getOrCreateUser(data.user);
|
|
2988
|
+
this.type = data.type ?? WebhookType.Incoming;
|
|
2773
2989
|
}
|
|
2774
2990
|
avatarURL(options) {
|
|
2775
2991
|
return cdnAvatarURL(this.id, this.avatar, {
|
|
@@ -2880,6 +3096,7 @@ var Webhook = class _Webhook extends Base {
|
|
|
2880
3096
|
name: options?.name ?? "Webhook",
|
|
2881
3097
|
avatar: null,
|
|
2882
3098
|
token,
|
|
3099
|
+
type: WebhookType.Incoming,
|
|
2883
3100
|
user: {
|
|
2884
3101
|
id: "",
|
|
2885
3102
|
username: "webhook",
|
|
@@ -2999,6 +3216,23 @@ var PermissionOverwriteManager = class {
|
|
|
2999
3216
|
}
|
|
3000
3217
|
};
|
|
3001
3218
|
|
|
3219
|
+
// src/Domain/Channel/ThreadBind.ts
|
|
3220
|
+
var factory;
|
|
3221
|
+
var managers = /* @__PURE__ */ new WeakMap();
|
|
3222
|
+
function bindThreadManager(next) {
|
|
3223
|
+
factory = next;
|
|
3224
|
+
}
|
|
3225
|
+
function threadManagerFor(channel) {
|
|
3226
|
+
const existing = managers.get(channel);
|
|
3227
|
+
if (existing) return existing;
|
|
3228
|
+
if (!factory) {
|
|
3229
|
+
throw new Error("ThreadManager is not initialized");
|
|
3230
|
+
}
|
|
3231
|
+
const created = factory(channel);
|
|
3232
|
+
managers.set(channel, created);
|
|
3233
|
+
return created;
|
|
3234
|
+
}
|
|
3235
|
+
|
|
3002
3236
|
// src/Domain/Channel/Guild.ts
|
|
3003
3237
|
var GuildChannel = class extends Channel {
|
|
3004
3238
|
/** Guild ID this channel belongs to, or null if missing from the payload. */
|
|
@@ -3119,6 +3353,93 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3119
3353
|
contentWarningLevel;
|
|
3120
3354
|
/** Custom content warning text. */
|
|
3121
3355
|
contentWarningText;
|
|
3356
|
+
/** Default auto-archive duration in minutes for new threads. */
|
|
3357
|
+
defaultAutoArchiveDuration;
|
|
3358
|
+
/** Slowmode in seconds copied onto new threads. */
|
|
3359
|
+
defaultThreadRateLimitPerUser;
|
|
3360
|
+
constructor(client, data) {
|
|
3361
|
+
super(client, data);
|
|
3362
|
+
this.topic = data.topic ?? null;
|
|
3363
|
+
this.nsfw = data.nsfw ?? false;
|
|
3364
|
+
this.nsfwOverride = data.nsfw_override ?? null;
|
|
3365
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3366
|
+
this.lastMessageId = data.last_message_id ?? null;
|
|
3367
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3368
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3369
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
3370
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
3371
|
+
}
|
|
3372
|
+
/** Create, list, and search threads in this channel. */
|
|
3373
|
+
get threads() {
|
|
3374
|
+
return threadManagerFor(this);
|
|
3375
|
+
}
|
|
3376
|
+
/**
|
|
3377
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3378
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3379
|
+
*/
|
|
3380
|
+
async setSlowmode(seconds) {
|
|
3381
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
3382
|
+
}
|
|
3383
|
+
applyEditPatch(data) {
|
|
3384
|
+
if ("topic" in data) this.topic = data.topic ?? null;
|
|
3385
|
+
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3386
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
3387
|
+
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3388
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3389
|
+
if ("content_warning_level" in data) {
|
|
3390
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3391
|
+
}
|
|
3392
|
+
if ("content_warning_text" in data) {
|
|
3393
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3394
|
+
}
|
|
3395
|
+
if ("default_auto_archive_duration" in data) {
|
|
3396
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
3397
|
+
}
|
|
3398
|
+
if ("default_thread_rate_limit_per_user" in data) {
|
|
3399
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
/**
|
|
3403
|
+
* Set the auto-archive and slowmode defaults copied onto new threads.
|
|
3404
|
+
* Sends only those fields. The thread-parent update body does not accept a channel rename.
|
|
3405
|
+
*/
|
|
3406
|
+
async editThreadDefaults(options) {
|
|
3407
|
+
const data = await this.client.rest.patch(Routes13.channel(this.id), {
|
|
3408
|
+
body: toThreadParentEditBody(options),
|
|
3409
|
+
auth: true,
|
|
3410
|
+
...auditReasonHeaders(options.reason)
|
|
3411
|
+
});
|
|
3412
|
+
this._patch(data);
|
|
3413
|
+
return this;
|
|
3414
|
+
}
|
|
3415
|
+
};
|
|
3416
|
+
var AnnouncementChannel = class extends TextChannel {
|
|
3417
|
+
};
|
|
3418
|
+
var CategoryChannel = class extends GuildChannel {
|
|
3419
|
+
};
|
|
3420
|
+
var VoiceChannel = class extends TextCapable(GuildChannel) {
|
|
3421
|
+
/** Channel topic. */
|
|
3422
|
+
topic;
|
|
3423
|
+
/** Whether this channel is marked as NSFW. */
|
|
3424
|
+
nsfw;
|
|
3425
|
+
/** Per-channel NSFW override (`null` inherits). */
|
|
3426
|
+
nsfwOverride;
|
|
3427
|
+
/** Slowmode rate limit in seconds. */
|
|
3428
|
+
rateLimitPerUser;
|
|
3429
|
+
/** ID of the last message sent in this channel. */
|
|
3430
|
+
lastMessageId;
|
|
3431
|
+
/** Content warning level. */
|
|
3432
|
+
contentWarningLevel;
|
|
3433
|
+
/** Custom content warning text. */
|
|
3434
|
+
contentWarningText;
|
|
3435
|
+
/** Voice bitrate. */
|
|
3436
|
+
bitrate;
|
|
3437
|
+
/** Maximum number of users allowed. */
|
|
3438
|
+
userLimit;
|
|
3439
|
+
/** Max active voice connections per user. */
|
|
3440
|
+
voiceConnectionLimit;
|
|
3441
|
+
/** RTC region override for this channel. */
|
|
3442
|
+
rtcRegion;
|
|
3122
3443
|
constructor(client, data) {
|
|
3123
3444
|
super(client, data);
|
|
3124
3445
|
this.topic = data.topic ?? null;
|
|
@@ -3128,125 +3449,566 @@ var TextChannel = class extends TextCapable(GuildChannel) {
|
|
|
3128
3449
|
this.lastMessageId = data.last_message_id ?? null;
|
|
3129
3450
|
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3130
3451
|
this.contentWarningText = data.content_warning_text ?? null;
|
|
3452
|
+
this.bitrate = data.bitrate ?? null;
|
|
3453
|
+
this.userLimit = data.user_limit ?? null;
|
|
3454
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3455
|
+
this.rtcRegion = data.rtc_region ?? null;
|
|
3456
|
+
}
|
|
3457
|
+
/**
|
|
3458
|
+
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3459
|
+
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3460
|
+
*/
|
|
3461
|
+
async setSlowmode(seconds) {
|
|
3462
|
+
return this.edit({ rateLimitPerUser: seconds });
|
|
3463
|
+
}
|
|
3464
|
+
applyEditPatch(data) {
|
|
3465
|
+
if ("topic" in data) this.topic = data.topic ?? null;
|
|
3466
|
+
if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
|
|
3467
|
+
if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
|
|
3468
|
+
if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3469
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3470
|
+
if ("content_warning_level" in data) {
|
|
3471
|
+
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3472
|
+
}
|
|
3473
|
+
if ("content_warning_text" in data) {
|
|
3474
|
+
this.contentWarningText = data.content_warning_text ?? null;
|
|
3475
|
+
}
|
|
3476
|
+
if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
|
|
3477
|
+
if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
|
|
3478
|
+
if ("voice_connection_limit" in data) {
|
|
3479
|
+
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3480
|
+
}
|
|
3481
|
+
if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
|
|
3482
|
+
}
|
|
3483
|
+
};
|
|
3484
|
+
var LinkChannel = class extends GuildChannel {
|
|
3485
|
+
/** External URL this channel links to. */
|
|
3486
|
+
url;
|
|
3487
|
+
constructor(client, data) {
|
|
3488
|
+
super(client, data);
|
|
3489
|
+
this.url = data.url ?? null;
|
|
3490
|
+
}
|
|
3491
|
+
applyEditPatch(data) {
|
|
3492
|
+
if ("url" in data) this.url = data.url ?? null;
|
|
3493
|
+
}
|
|
3494
|
+
};
|
|
3495
|
+
|
|
3496
|
+
// src/Domain/Channel/ThreadManager.ts
|
|
3497
|
+
import { ChannelType as ChannelType6, Routes as Routes15 } from "@fluxerjs/types";
|
|
3498
|
+
|
|
3499
|
+
// src/Domain/Channel/ThreadChannel.ts
|
|
3500
|
+
import { ChannelType as ChannelType5, Routes as Routes14 } from "@fluxerjs/types";
|
|
3501
|
+
var ThreadMember = class {
|
|
3502
|
+
/** Thread ID. */
|
|
3503
|
+
id;
|
|
3504
|
+
/** User ID. */
|
|
3505
|
+
userId;
|
|
3506
|
+
/** When the user last joined the thread. */
|
|
3507
|
+
joinedAt;
|
|
3508
|
+
/** Thread member flags bitfield. */
|
|
3509
|
+
flags;
|
|
3510
|
+
/** Whether the current user has muted the thread. */
|
|
3511
|
+
muted;
|
|
3512
|
+
/** ISO-8601 timestamp when the mute expires, if set. */
|
|
3513
|
+
muteEndTime;
|
|
3514
|
+
/** Selected mute duration in seconds, if set. */
|
|
3515
|
+
muteWindow;
|
|
3516
|
+
constructor(data) {
|
|
3517
|
+
this.id = data.id ?? null;
|
|
3518
|
+
this.userId = data.user_id ?? data.member?.user?.id ?? null;
|
|
3519
|
+
this.joinedAt = new Date(data.join_timestamp);
|
|
3520
|
+
this.flags = data.flags;
|
|
3521
|
+
this.muted = data.muted ?? null;
|
|
3522
|
+
this.muteEndTime = data.mute_config?.end_time ?? null;
|
|
3523
|
+
this.muteWindow = data.mute_config?.selected_time_window ?? null;
|
|
3524
|
+
}
|
|
3525
|
+
};
|
|
3526
|
+
function threadEditFields(options) {
|
|
3527
|
+
const source = options;
|
|
3528
|
+
return {
|
|
3529
|
+
name: typeof source.name === "string" ? source.name : void 0,
|
|
3530
|
+
archived: source.archived,
|
|
3531
|
+
autoArchiveDuration: source.autoArchiveDuration,
|
|
3532
|
+
locked: source.locked,
|
|
3533
|
+
rateLimitPerUser: source.rateLimitPerUser,
|
|
3534
|
+
flags: source.flags,
|
|
3535
|
+
appliedTags: source.appliedTags,
|
|
3536
|
+
invitable: source.invitable,
|
|
3537
|
+
reason: source.reason
|
|
3538
|
+
};
|
|
3539
|
+
}
|
|
3540
|
+
function readMetadata(data) {
|
|
3541
|
+
return {
|
|
3542
|
+
archived: data?.archived ?? false,
|
|
3543
|
+
autoArchiveDuration: data?.auto_archive_duration ?? 0,
|
|
3544
|
+
archiveTimestamp: data?.archive_timestamp ?? null,
|
|
3545
|
+
locked: data?.locked ?? false,
|
|
3546
|
+
invitable: data?.invitable ?? null
|
|
3547
|
+
};
|
|
3548
|
+
}
|
|
3549
|
+
var ThreadChannel = class extends TextCapable(GuildChannel) {
|
|
3550
|
+
/** User who created the thread. */
|
|
3551
|
+
ownerId;
|
|
3552
|
+
/** Whether the thread is archived. */
|
|
3553
|
+
archived;
|
|
3554
|
+
/** Minutes of inactivity before the thread archives. */
|
|
3555
|
+
autoArchiveDuration;
|
|
3556
|
+
/** ISO-8601 timestamp when the archive status last changed. */
|
|
3557
|
+
archiveTimestamp;
|
|
3558
|
+
/** Whether only moderators can unarchive the thread. */
|
|
3559
|
+
locked;
|
|
3560
|
+
/** Whether non-moderators can add other non-moderators. Private threads only. */
|
|
3561
|
+
invitable;
|
|
3562
|
+
/** Slowmode in seconds. */
|
|
3563
|
+
rateLimitPerUser;
|
|
3564
|
+
/** ID of the last message sent in this thread. */
|
|
3565
|
+
lastMessageId;
|
|
3566
|
+
/** Messages in the thread, excluding the starter and deleted messages. */
|
|
3567
|
+
messageCount;
|
|
3568
|
+
/** Messages ever sent in the thread. This count is never decremented. */
|
|
3569
|
+
totalMessageSent;
|
|
3570
|
+
/** Approximate member count, capped at 50. */
|
|
3571
|
+
memberCount;
|
|
3572
|
+
/** Tag IDs applied to a forum or media post. */
|
|
3573
|
+
appliedTags;
|
|
3574
|
+
/** Channel flags bitfield. */
|
|
3575
|
+
flags;
|
|
3576
|
+
/** The current user's membership, when the payload included it. */
|
|
3577
|
+
member;
|
|
3578
|
+
/** Add, remove, and list members of this thread. */
|
|
3579
|
+
members;
|
|
3580
|
+
constructor(client, data) {
|
|
3581
|
+
super(client, data);
|
|
3582
|
+
const metadata = readMetadata(data.thread_metadata);
|
|
3583
|
+
this.ownerId = data.owner_id ?? null;
|
|
3584
|
+
this.archived = metadata.archived;
|
|
3585
|
+
this.autoArchiveDuration = metadata.autoArchiveDuration;
|
|
3586
|
+
this.archiveTimestamp = metadata.archiveTimestamp;
|
|
3587
|
+
this.locked = metadata.locked;
|
|
3588
|
+
this.invitable = metadata.invitable;
|
|
3589
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3590
|
+
this.lastMessageId = data.last_message_id ?? null;
|
|
3591
|
+
this.messageCount = data.message_count ?? 0;
|
|
3592
|
+
this.totalMessageSent = data.total_message_sent ?? 0;
|
|
3593
|
+
this.memberCount = data.member_count ?? 0;
|
|
3594
|
+
this.appliedTags = data.applied_tags ?? [];
|
|
3595
|
+
this.flags = data.flags ?? 0;
|
|
3596
|
+
this.member = data.member ? new ThreadMember(data.member) : null;
|
|
3597
|
+
this.members = new ThreadMemberManager(this);
|
|
3598
|
+
}
|
|
3599
|
+
/** @internal */
|
|
3600
|
+
_patch(data) {
|
|
3601
|
+
super._patch(data);
|
|
3602
|
+
if (data.owner_id !== void 0) this.ownerId = data.owner_id ?? null;
|
|
3603
|
+
if (data.thread_metadata) {
|
|
3604
|
+
const metadata = readMetadata(data.thread_metadata);
|
|
3605
|
+
this.archived = metadata.archived;
|
|
3606
|
+
this.autoArchiveDuration = metadata.autoArchiveDuration;
|
|
3607
|
+
this.archiveTimestamp = metadata.archiveTimestamp;
|
|
3608
|
+
this.locked = metadata.locked;
|
|
3609
|
+
this.invitable = metadata.invitable;
|
|
3610
|
+
}
|
|
3611
|
+
if ("rate_limit_per_user" in data && data.rate_limit_per_user !== void 0) {
|
|
3612
|
+
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
3613
|
+
}
|
|
3614
|
+
if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
|
|
3615
|
+
if (data.message_count !== void 0) this.messageCount = data.message_count;
|
|
3616
|
+
if (data.total_message_sent !== void 0) this.totalMessageSent = data.total_message_sent;
|
|
3617
|
+
if (data.member_count !== void 0) this.memberCount = data.member_count;
|
|
3618
|
+
if (data.applied_tags !== void 0) this.appliedTags = data.applied_tags ?? [];
|
|
3619
|
+
if (data.flags !== void 0) this.flags = data.flags;
|
|
3620
|
+
if (data.member !== void 0) this.member = data.member ? new ThreadMember(data.member) : null;
|
|
3621
|
+
}
|
|
3622
|
+
/**
|
|
3623
|
+
* Edit this thread. Requires Manage Threads on public threads, or ownership on private ones.
|
|
3624
|
+
* `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
|
|
3625
|
+
*/
|
|
3626
|
+
async edit(options) {
|
|
3627
|
+
const data = await this.client.rest.patch(Routes14.channel(this.id), {
|
|
3628
|
+
body: toThreadEditBody(this.type, threadEditFields(options)),
|
|
3629
|
+
auth: true,
|
|
3630
|
+
...auditReasonHeaders(options.reason)
|
|
3631
|
+
});
|
|
3632
|
+
this._patch(data);
|
|
3633
|
+
return this;
|
|
3634
|
+
}
|
|
3635
|
+
/** Archive or unarchive this thread. */
|
|
3636
|
+
async setArchived(archived, reason) {
|
|
3637
|
+
return this.edit({ archived, reason });
|
|
3638
|
+
}
|
|
3639
|
+
/** Lock or unlock this thread. Locked threads can only be unarchived by moderators. */
|
|
3640
|
+
async setLocked(locked, reason) {
|
|
3641
|
+
return this.edit({ locked, reason });
|
|
3642
|
+
}
|
|
3643
|
+
/** Join this thread. */
|
|
3644
|
+
async join() {
|
|
3645
|
+
await this.client.rest.put(Routes14.channelThreadMemberMe(this.id), { auth: true });
|
|
3646
|
+
}
|
|
3647
|
+
/** Leave this thread. */
|
|
3648
|
+
async leave() {
|
|
3649
|
+
await this.client.rest.delete(Routes14.channelThreadMemberMe(this.id), { auth: true });
|
|
3650
|
+
}
|
|
3651
|
+
/** Update the current user's notification settings for this thread. */
|
|
3652
|
+
async editSelf(options) {
|
|
3653
|
+
const data = await this.client.rest.patch(
|
|
3654
|
+
Routes14.channelThreadMemberMeSettings(this.id),
|
|
3655
|
+
{ body: toThreadMemberSettingsBody(options), auth: true }
|
|
3656
|
+
);
|
|
3657
|
+
this.member = data ? new ThreadMember(data) : null;
|
|
3658
|
+
return this.member;
|
|
3659
|
+
}
|
|
3660
|
+
};
|
|
3661
|
+
var ThreadMemberManager = class {
|
|
3662
|
+
constructor(thread) {
|
|
3663
|
+
this.thread = thread;
|
|
3664
|
+
}
|
|
3665
|
+
/** List members of this thread. */
|
|
3666
|
+
async fetch(options) {
|
|
3667
|
+
const data = await this.thread.client.rest.get(
|
|
3668
|
+
withQuery(Routes14.channelThreadMembers(this.thread.id), {
|
|
3669
|
+
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
|
|
3670
|
+
after: options?.after,
|
|
3671
|
+
limit: options?.limit
|
|
3672
|
+
})
|
|
3673
|
+
);
|
|
3674
|
+
return data.map((member) => new ThreadMember(member));
|
|
3675
|
+
}
|
|
3676
|
+
/** Fetch one member of this thread. */
|
|
3677
|
+
async fetchOne(userId, options) {
|
|
3678
|
+
const data = await this.thread.client.rest.get(
|
|
3679
|
+
withQuery(Routes14.channelThreadMember(this.thread.id, userId), {
|
|
3680
|
+
with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
|
|
3681
|
+
})
|
|
3682
|
+
);
|
|
3683
|
+
return new ThreadMember(data);
|
|
3684
|
+
}
|
|
3685
|
+
/** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
|
|
3686
|
+
async add(userId) {
|
|
3687
|
+
await this.thread.client.rest.put(Routes14.channelThreadMember(this.thread.id, userId), {
|
|
3688
|
+
auth: true
|
|
3689
|
+
});
|
|
3690
|
+
}
|
|
3691
|
+
/** Remove a user from this thread. */
|
|
3692
|
+
async remove(userId) {
|
|
3693
|
+
await this.thread.client.rest.delete(Routes14.channelThreadMember(this.thread.id, userId), {
|
|
3694
|
+
auth: true
|
|
3695
|
+
});
|
|
3696
|
+
}
|
|
3697
|
+
};
|
|
3698
|
+
function isThreadType(type) {
|
|
3699
|
+
return type === ChannelType5.AnnouncementThread || type === ChannelType5.PublicThread || type === ChannelType5.PrivateThread;
|
|
3700
|
+
}
|
|
3701
|
+
|
|
3702
|
+
// src/Domain/Channel/ThreadManager.ts
|
|
3703
|
+
var ThreadManager = class {
|
|
3704
|
+
constructor(channel) {
|
|
3705
|
+
this.channel = channel;
|
|
3706
|
+
}
|
|
3707
|
+
/**
|
|
3708
|
+
* Start a thread in a text or announcement channel.
|
|
3709
|
+
* Forum and media channels must use {@link createPost}.
|
|
3710
|
+
*/
|
|
3711
|
+
async create(options) {
|
|
3712
|
+
if (this.channel.type === ChannelType6.GuildForum || this.channel.type === ChannelType6.GuildMedia) {
|
|
3713
|
+
throw new FluxerError("Forum and media channels start posts with createPost", {
|
|
3714
|
+
code: ErrorCodes.InvalidChannelType
|
|
3715
|
+
});
|
|
3716
|
+
}
|
|
3717
|
+
const data = await this.channel.client.rest.post(
|
|
3718
|
+
Routes15.channelThreads(this.channel.id),
|
|
3719
|
+
{
|
|
3720
|
+
body: toStartThreadBody(this.channel.type, options),
|
|
3721
|
+
auth: true,
|
|
3722
|
+
...auditReasonHeaders(options.reason)
|
|
3723
|
+
}
|
|
3724
|
+
);
|
|
3725
|
+
return cacheThread(this.channel.client, data);
|
|
3726
|
+
}
|
|
3727
|
+
/**
|
|
3728
|
+
* Start a post in a forum or media channel.
|
|
3729
|
+
* The post is a public thread. `message` is its first message.
|
|
3730
|
+
*/
|
|
3731
|
+
async createPost(options) {
|
|
3732
|
+
if (this.channel.type !== ChannelType6.GuildForum && this.channel.type !== ChannelType6.GuildMedia) {
|
|
3733
|
+
throw new FluxerError("createPost is for forum and media channels", {
|
|
3734
|
+
code: ErrorCodes.InvalidChannelType
|
|
3735
|
+
});
|
|
3736
|
+
}
|
|
3737
|
+
const prepared = await prepareMessagePostPayload(options.message, {
|
|
3738
|
+
defaultAllowedMentions: this.channel.client.options.defaultAllowedMentions
|
|
3739
|
+
});
|
|
3740
|
+
const body = {
|
|
3741
|
+
name: options.name,
|
|
3742
|
+
type: ChannelType6.PublicThread,
|
|
3743
|
+
message: toForumThreadMessage(prepared.body)
|
|
3744
|
+
};
|
|
3745
|
+
if (options.autoArchiveDuration !== void 0) {
|
|
3746
|
+
body.auto_archive_duration = options.autoArchiveDuration;
|
|
3747
|
+
}
|
|
3748
|
+
if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
|
|
3749
|
+
if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
|
|
3750
|
+
const data = await this.channel.client.rest.post(
|
|
3751
|
+
Routes15.channelThreads(this.channel.id),
|
|
3752
|
+
{
|
|
3753
|
+
body,
|
|
3754
|
+
files: prepared.files,
|
|
3755
|
+
auth: true,
|
|
3756
|
+
...auditReasonHeaders(options.reason)
|
|
3757
|
+
}
|
|
3758
|
+
);
|
|
3759
|
+
const thread = cacheThread(this.channel.client, data);
|
|
3760
|
+
if (data.message) {
|
|
3761
|
+
this.channel.client._addMessageToCache(data.message.channel_id, data.message);
|
|
3762
|
+
}
|
|
3763
|
+
return thread;
|
|
3764
|
+
}
|
|
3765
|
+
/**
|
|
3766
|
+
* List archived threads in this channel.
|
|
3767
|
+
* `before` is an ISO-8601 archive timestamp.
|
|
3768
|
+
*/
|
|
3769
|
+
async fetchArchived(options) {
|
|
3770
|
+
const path = options.type === "private" ? Routes15.channelThreadsArchivedPrivate(this.channel.id) : Routes15.channelThreadsArchivedPublic(this.channel.id);
|
|
3771
|
+
const data = await this.channel.client.rest.get(
|
|
3772
|
+
withQuery(path, { before: options.before, limit: options.limit })
|
|
3773
|
+
);
|
|
3774
|
+
return fetchedThreadsFrom(this.channel.client, data);
|
|
3131
3775
|
}
|
|
3132
3776
|
/**
|
|
3133
|
-
*
|
|
3134
|
-
*
|
|
3777
|
+
* List private archived threads in this channel that the current user has joined.
|
|
3778
|
+
* `before` is a thread snowflake.
|
|
3135
3779
|
*/
|
|
3136
|
-
async
|
|
3137
|
-
|
|
3780
|
+
async fetchJoinedPrivateArchived(options) {
|
|
3781
|
+
const data = await this.channel.client.rest.get(
|
|
3782
|
+
withQuery(Routes15.channelJoinedArchivedPrivateThreads(this.channel.id), {
|
|
3783
|
+
before: options?.before,
|
|
3784
|
+
limit: options?.limit
|
|
3785
|
+
})
|
|
3786
|
+
);
|
|
3787
|
+
return fetchedThreadsFrom(this.channel.client, data);
|
|
3138
3788
|
}
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3789
|
+
/**
|
|
3790
|
+
* Search threads in this channel.
|
|
3791
|
+
* Returns `{ indexing: true }` while the search index is still building.
|
|
3792
|
+
*/
|
|
3793
|
+
async search(options) {
|
|
3794
|
+
const data = await this.channel.client.rest.get(
|
|
3795
|
+
withQuery(Routes15.channelThreadSearch(this.channel.id), {
|
|
3796
|
+
name: options?.name,
|
|
3797
|
+
tag: options?.tag,
|
|
3798
|
+
tag_setting: options?.tagSetting,
|
|
3799
|
+
archived: options?.archived === void 0 ? void 0 : String(options.archived),
|
|
3800
|
+
sort_by: options?.sortBy,
|
|
3801
|
+
sort_order: options?.sortOrder,
|
|
3802
|
+
limit: options?.limit,
|
|
3803
|
+
offset: options?.offset,
|
|
3804
|
+
max_id: options?.maxId,
|
|
3805
|
+
min_id: options?.minId
|
|
3806
|
+
})
|
|
3807
|
+
);
|
|
3808
|
+
if (isSearchNotReady(data)) {
|
|
3809
|
+
return { indexing: true, retryAfter: data.retry_after, message: data.message };
|
|
3150
3810
|
}
|
|
3811
|
+
const page = fetchedThreadsFrom(this.channel.client, data);
|
|
3812
|
+
return {
|
|
3813
|
+
...page,
|
|
3814
|
+
hasMore: data.has_more,
|
|
3815
|
+
totalResults: data.total_results,
|
|
3816
|
+
firstMessages: (data.first_messages ?? []).map(
|
|
3817
|
+
(message) => new Message(this.channel.client, message)
|
|
3818
|
+
)
|
|
3819
|
+
};
|
|
3820
|
+
}
|
|
3821
|
+
/** Set the auto-archive and slowmode defaults copied onto new threads. */
|
|
3822
|
+
async editDefaults(options) {
|
|
3823
|
+
return this.channel.client.rest.patch(Routes15.channel(this.channel.id), {
|
|
3824
|
+
body: toThreadParentEditBody(options),
|
|
3825
|
+
auth: true,
|
|
3826
|
+
...auditReasonHeaders(options.reason)
|
|
3827
|
+
});
|
|
3151
3828
|
}
|
|
3152
3829
|
};
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3830
|
+
function fetchedThreadsFrom(client, data) {
|
|
3831
|
+
return {
|
|
3832
|
+
threads: (data.threads ?? []).map((thread) => cacheThread(client, thread)),
|
|
3833
|
+
members: (data.members ?? []).map((member) => new ThreadMember(member)),
|
|
3834
|
+
hasMore: data.has_more ?? false
|
|
3835
|
+
};
|
|
3836
|
+
}
|
|
3837
|
+
function isSearchNotReady(data) {
|
|
3838
|
+
return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
|
|
3839
|
+
}
|
|
3840
|
+
async function fetchActiveThreads(client, guildId) {
|
|
3841
|
+
const data = await client.rest.get(Routes15.guildActiveThreads(guildId));
|
|
3842
|
+
return fetchedThreadsFrom(client, data);
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
// src/Domain/Channel/Forum.ts
|
|
3846
|
+
function tagsFrom(data) {
|
|
3847
|
+
return data ?? [];
|
|
3848
|
+
}
|
|
3849
|
+
var ThreadOnlyChannel = class extends GuildChannel {
|
|
3850
|
+
/** Tags that can be applied to posts. */
|
|
3851
|
+
availableTags;
|
|
3852
|
+
/** Default reaction for new posts. */
|
|
3853
|
+
defaultReactionEmoji;
|
|
3854
|
+
/** Default sort order for posts. */
|
|
3855
|
+
defaultSortOrder;
|
|
3856
|
+
/** How posts are filtered when searching by several tags. */
|
|
3857
|
+
defaultTagSetting;
|
|
3858
|
+
/** Default auto-archive duration in minutes for new posts. */
|
|
3859
|
+
defaultAutoArchiveDuration;
|
|
3860
|
+
/** Slowmode in seconds copied onto new posts. */
|
|
3861
|
+
defaultThreadRateLimitPerUser;
|
|
3862
|
+
/** Channel flags bitfield. */
|
|
3863
|
+
flags;
|
|
3864
|
+
/** Create, list, and search posts in this channel. */
|
|
3865
|
+
threads;
|
|
3178
3866
|
constructor(client, data) {
|
|
3179
3867
|
super(client, data);
|
|
3180
|
-
this.
|
|
3181
|
-
this.
|
|
3182
|
-
this.
|
|
3183
|
-
this.
|
|
3184
|
-
this.
|
|
3185
|
-
this.
|
|
3186
|
-
this.
|
|
3187
|
-
this.
|
|
3188
|
-
this.userLimit = data.user_limit ?? null;
|
|
3189
|
-
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3190
|
-
this.rtcRegion = data.rtc_region ?? null;
|
|
3191
|
-
}
|
|
3192
|
-
/**
|
|
3193
|
-
* Set slowmode (seconds between messages). Pass `0` to disable.
|
|
3194
|
-
* Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
|
|
3195
|
-
*/
|
|
3196
|
-
async setSlowmode(seconds) {
|
|
3197
|
-
return this.edit({ rateLimitPerUser: seconds });
|
|
3868
|
+
this.availableTags = tagsFrom(data.available_tags);
|
|
3869
|
+
this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
|
|
3870
|
+
this.defaultSortOrder = data.default_sort_order ?? null;
|
|
3871
|
+
this.defaultTagSetting = data.default_tag_setting ?? null;
|
|
3872
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
3873
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
3874
|
+
this.flags = data.flags ?? 0;
|
|
3875
|
+
this.threads = new ThreadManager(this);
|
|
3198
3876
|
}
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
if (
|
|
3203
|
-
if ("
|
|
3204
|
-
|
|
3205
|
-
if ("content_warning_level" in data) {
|
|
3206
|
-
this.contentWarningLevel = data.content_warning_level ?? null;
|
|
3877
|
+
/** @internal */
|
|
3878
|
+
_patch(data) {
|
|
3879
|
+
super._patch(data);
|
|
3880
|
+
if (data.available_tags !== void 0) this.availableTags = tagsFrom(data.available_tags);
|
|
3881
|
+
if ("default_reaction_emoji" in data) {
|
|
3882
|
+
this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
|
|
3207
3883
|
}
|
|
3208
|
-
if ("
|
|
3209
|
-
|
|
3884
|
+
if ("default_sort_order" in data) this.defaultSortOrder = data.default_sort_order ?? null;
|
|
3885
|
+
if ("default_tag_setting" in data) this.defaultTagSetting = data.default_tag_setting ?? null;
|
|
3886
|
+
if ("default_auto_archive_duration" in data) {
|
|
3887
|
+
this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
|
|
3210
3888
|
}
|
|
3211
|
-
if ("
|
|
3212
|
-
|
|
3213
|
-
if ("voice_connection_limit" in data) {
|
|
3214
|
-
this.voiceConnectionLimit = data.voice_connection_limit ?? null;
|
|
3889
|
+
if ("default_thread_rate_limit_per_user" in data) {
|
|
3890
|
+
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
|
|
3215
3891
|
}
|
|
3216
|
-
if (
|
|
3892
|
+
if (data.flags !== void 0) this.flags = data.flags;
|
|
3893
|
+
}
|
|
3894
|
+
/**
|
|
3895
|
+
* Edit this channel.
|
|
3896
|
+
* Tag, sort, reaction, and thread-default fields are sent with the usual channel fields.
|
|
3897
|
+
* `defaultForumLayout` is sent only for forum channels.
|
|
3898
|
+
*/
|
|
3899
|
+
async edit(options) {
|
|
3900
|
+
const data = await this.client.rest.patch(Routes16.channel(this.id), {
|
|
3901
|
+
body: {
|
|
3902
|
+
...toChannelEditBody(options),
|
|
3903
|
+
...forumParentWire(options, this.type === ChannelType7.GuildForum)
|
|
3904
|
+
},
|
|
3905
|
+
auth: true,
|
|
3906
|
+
...auditReasonHeaders(options.reason)
|
|
3907
|
+
});
|
|
3908
|
+
this._patch(data);
|
|
3909
|
+
return this;
|
|
3910
|
+
}
|
|
3911
|
+
/** Replace the tags that can be applied to posts (max 20). */
|
|
3912
|
+
async setAvailableTags(tags, reason) {
|
|
3913
|
+
return this.edit({ availableTags: tags, reason });
|
|
3914
|
+
}
|
|
3915
|
+
/** Set or clear the default reaction on new posts. */
|
|
3916
|
+
async setDefaultReactionEmoji(emoji, reason) {
|
|
3917
|
+
return this.edit({ defaultReactionEmoji: emoji, reason });
|
|
3918
|
+
}
|
|
3919
|
+
/** Set or clear the default post sort order. */
|
|
3920
|
+
async setDefaultSortOrder(order, reason) {
|
|
3921
|
+
return this.edit({ defaultSortOrder: order, reason });
|
|
3922
|
+
}
|
|
3923
|
+
/** Set or clear how posts match when several tags are selected. */
|
|
3924
|
+
async setDefaultTagSetting(setting, reason) {
|
|
3925
|
+
return this.edit({ defaultTagSetting: setting, reason });
|
|
3926
|
+
}
|
|
3927
|
+
/** Set the auto-archive and slowmode defaults copied onto new posts. */
|
|
3928
|
+
async editThreadDefaults(options) {
|
|
3929
|
+
const data = await this.client.rest.patch(Routes16.channel(this.id), {
|
|
3930
|
+
body: toThreadParentEditBody(options),
|
|
3931
|
+
auth: true,
|
|
3932
|
+
...auditReasonHeaders(options.reason)
|
|
3933
|
+
});
|
|
3934
|
+
this._patch(data);
|
|
3935
|
+
return this;
|
|
3936
|
+
}
|
|
3937
|
+
/** Create a tag. The response replaces {@link availableTags}. */
|
|
3938
|
+
async createTag(options) {
|
|
3939
|
+
const data = await this.client.rest.post(Routes16.channelTags(this.id), {
|
|
3940
|
+
body: toForumTagBody(options),
|
|
3941
|
+
auth: true,
|
|
3942
|
+
...auditReasonHeaders(options.reason)
|
|
3943
|
+
});
|
|
3944
|
+
this._patch(data);
|
|
3945
|
+
return this;
|
|
3946
|
+
}
|
|
3947
|
+
/** Replace a tag. The response replaces {@link availableTags}. */
|
|
3948
|
+
async editTag(tagId, options) {
|
|
3949
|
+
const data = await this.client.rest.put(Routes16.channelTag(this.id, tagId), {
|
|
3950
|
+
body: toForumTagBody(options),
|
|
3951
|
+
auth: true,
|
|
3952
|
+
...auditReasonHeaders(options.reason)
|
|
3953
|
+
});
|
|
3954
|
+
this._patch(data);
|
|
3955
|
+
return this;
|
|
3956
|
+
}
|
|
3957
|
+
/** Delete a tag. The response replaces {@link availableTags}. */
|
|
3958
|
+
async deleteTag(tagId, reason) {
|
|
3959
|
+
const data = await this.client.rest.delete(Routes16.channelTag(this.id, tagId), {
|
|
3960
|
+
auth: true,
|
|
3961
|
+
...auditReasonHeaders(reason)
|
|
3962
|
+
});
|
|
3963
|
+
this._patch(data);
|
|
3964
|
+
return this;
|
|
3217
3965
|
}
|
|
3218
3966
|
};
|
|
3219
|
-
var
|
|
3220
|
-
/**
|
|
3221
|
-
|
|
3967
|
+
var ForumChannel = class extends ThreadOnlyChannel {
|
|
3968
|
+
/** Default layout for posts. */
|
|
3969
|
+
defaultForumLayout;
|
|
3970
|
+
/** Set or clear the default post layout. */
|
|
3971
|
+
async setDefaultForumLayout(layout, reason) {
|
|
3972
|
+
return this.edit({ defaultForumLayout: layout, reason });
|
|
3973
|
+
}
|
|
3222
3974
|
constructor(client, data) {
|
|
3223
3975
|
super(client, data);
|
|
3224
|
-
this.
|
|
3976
|
+
this.defaultForumLayout = data.default_forum_layout ?? null;
|
|
3225
3977
|
}
|
|
3226
|
-
|
|
3227
|
-
|
|
3978
|
+
/** @internal */
|
|
3979
|
+
_patch(data) {
|
|
3980
|
+
super._patch(data);
|
|
3981
|
+
if ("default_forum_layout" in data) this.defaultForumLayout = data.default_forum_layout ?? null;
|
|
3228
3982
|
}
|
|
3229
3983
|
};
|
|
3984
|
+
var MediaChannel = class extends ThreadOnlyChannel {
|
|
3985
|
+
};
|
|
3230
3986
|
|
|
3231
3987
|
// src/Domain/Channel/Factory.ts
|
|
3232
|
-
import { ChannelType as
|
|
3988
|
+
import { ChannelType as ChannelType8 } from "@fluxerjs/types";
|
|
3233
3989
|
var GUILD_FACTORIES = {
|
|
3234
|
-
[
|
|
3235
|
-
[
|
|
3236
|
-
[
|
|
3237
|
-
[
|
|
3990
|
+
[ChannelType8.GuildText]: (c, d) => new TextChannel(c, d),
|
|
3991
|
+
[ChannelType8.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
|
|
3992
|
+
[ChannelType8.GuildCategory]: (c, d) => new CategoryChannel(c, d),
|
|
3993
|
+
[ChannelType8.GuildVoice]: (c, d) => new VoiceChannel(c, d),
|
|
3994
|
+
[ChannelType8.GuildLink]: (c, d) => new LinkChannel(c, d),
|
|
3995
|
+
[ChannelType8.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
|
|
3996
|
+
[ChannelType8.PublicThread]: (c, d) => new ThreadChannel(c, d),
|
|
3997
|
+
[ChannelType8.PrivateThread]: (c, d) => new ThreadChannel(c, d),
|
|
3998
|
+
[ChannelType8.GuildForum]: (c, d) => new ForumChannel(c, d),
|
|
3999
|
+
[ChannelType8.GuildMedia]: (c, d) => new MediaChannel(c, d)
|
|
3238
4000
|
};
|
|
3239
4001
|
var DM_TYPES = /* @__PURE__ */ new Set([
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
4002
|
+
ChannelType8.DM,
|
|
4003
|
+
ChannelType8.GroupDM,
|
|
4004
|
+
ChannelType8.DMPersonalNotes
|
|
3243
4005
|
]);
|
|
3244
4006
|
function createDM(client, data) {
|
|
3245
4007
|
return new DMChannel(client, data);
|
|
3246
4008
|
}
|
|
3247
4009
|
function channelFrom(client, data) {
|
|
3248
|
-
const
|
|
3249
|
-
return
|
|
4010
|
+
const factory2 = GUILD_FACTORIES[data.type ?? 0];
|
|
4011
|
+
return factory2 ? factory2(client, data) : new GuildChannel(client, data);
|
|
3250
4012
|
}
|
|
3251
4013
|
function channelFromOrCreate(client, data) {
|
|
3252
4014
|
return DM_TYPES.has(data.type ?? 0) ? createDM(client, data) : channelFrom(client, data);
|
|
@@ -3256,6 +4018,7 @@ function channelFromOrCreate(client, data) {
|
|
|
3256
4018
|
Channel.from = channelFrom;
|
|
3257
4019
|
Channel.fromOrCreate = channelFromOrCreate;
|
|
3258
4020
|
Channel.createDM = createDM;
|
|
4021
|
+
bindThreadManager((channel) => new ThreadManager(channel));
|
|
3259
4022
|
|
|
3260
4023
|
// src/Domain/User.ts
|
|
3261
4024
|
var User = class extends Base {
|
|
@@ -3355,7 +4118,7 @@ var User = class extends Base {
|
|
|
3355
4118
|
* @returns DM channel instance (cached if already open)
|
|
3356
4119
|
*/
|
|
3357
4120
|
async createDM() {
|
|
3358
|
-
const data = await this.client.rest.post(
|
|
4121
|
+
const data = await this.client.rest.post(Routes17.userMeChannels(), {
|
|
3359
4122
|
body: { recipient_id: this.id },
|
|
3360
4123
|
auth: true
|
|
3361
4124
|
});
|
|
@@ -3572,10 +4335,13 @@ var CacheController = class {
|
|
|
3572
4335
|
|
|
3573
4336
|
// src/ClientCore/ChannelManager.ts
|
|
3574
4337
|
import { LimitedCollection } from "@fluxerjs/collection";
|
|
3575
|
-
import { Routes as
|
|
4338
|
+
import { Routes as Routes23 } from "@fluxerjs/types";
|
|
4339
|
+
|
|
4340
|
+
// src/Domain/Guild/Cache.ts
|
|
4341
|
+
import { ChannelType as ChannelType9 } from "@fluxerjs/types";
|
|
3576
4342
|
|
|
3577
4343
|
// src/Domain/Guild/GuildEmoji.ts
|
|
3578
|
-
import { Routes as
|
|
4344
|
+
import { Routes as Routes18 } from "@fluxerjs/types";
|
|
3579
4345
|
import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
|
|
3580
4346
|
var GuildEmoji = class extends Base {
|
|
3581
4347
|
client;
|
|
@@ -3624,7 +4390,7 @@ var GuildEmoji = class extends Base {
|
|
|
3624
4390
|
}
|
|
3625
4391
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
3626
4392
|
async delete(reason) {
|
|
3627
|
-
await this.client.rest.delete(
|
|
4393
|
+
await this.client.rest.delete(Routes18.guildEmoji(this.guildId, this.id), {
|
|
3628
4394
|
auth: true,
|
|
3629
4395
|
...auditReasonHeaders(reason)
|
|
3630
4396
|
});
|
|
@@ -3637,7 +4403,7 @@ var GuildEmoji = class extends Base {
|
|
|
3637
4403
|
*/
|
|
3638
4404
|
async edit(options) {
|
|
3639
4405
|
const { reason, name } = options;
|
|
3640
|
-
const data = await this.client.rest.patch(
|
|
4406
|
+
const data = await this.client.rest.patch(Routes18.guildEmoji(this.guildId, this.id), {
|
|
3641
4407
|
body: { name },
|
|
3642
4408
|
auth: true,
|
|
3643
4409
|
...auditReasonHeaders(reason)
|
|
@@ -3648,7 +4414,7 @@ var GuildEmoji = class extends Base {
|
|
|
3648
4414
|
};
|
|
3649
4415
|
|
|
3650
4416
|
// src/Domain/Guild/GuildMember.ts
|
|
3651
|
-
import { Routes as
|
|
4417
|
+
import { Routes as Routes20 } from "@fluxerjs/types";
|
|
3652
4418
|
import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
|
|
3653
4419
|
|
|
3654
4420
|
// src/Helpers/Permissions.ts
|
|
@@ -3672,7 +4438,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
3672
4438
|
|
|
3673
4439
|
// src/Domain/Guild/GuildMemberRoleManager.ts
|
|
3674
4440
|
import { Collection as Collection7 } from "@fluxerjs/collection";
|
|
3675
|
-
import { Routes as
|
|
4441
|
+
import { Routes as Routes19 } from "@fluxerjs/types";
|
|
3676
4442
|
function roleId(roleOrId) {
|
|
3677
4443
|
return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
|
|
3678
4444
|
}
|
|
@@ -3701,7 +4467,7 @@ var GuildMemberRoleManager = class {
|
|
|
3701
4467
|
const id = roleId(roleOrId);
|
|
3702
4468
|
if (this.ids.includes(id)) return;
|
|
3703
4469
|
await this.member.client.rest.put(
|
|
3704
|
-
|
|
4470
|
+
Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
3705
4471
|
);
|
|
3706
4472
|
this.ids.push(id);
|
|
3707
4473
|
}
|
|
@@ -3710,13 +4476,13 @@ var GuildMemberRoleManager = class {
|
|
|
3710
4476
|
const idx = this.ids.indexOf(id);
|
|
3711
4477
|
if (idx === -1) return;
|
|
3712
4478
|
await this.member.client.rest.delete(
|
|
3713
|
-
|
|
4479
|
+
Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
|
|
3714
4480
|
);
|
|
3715
4481
|
this.ids.splice(idx, 1);
|
|
3716
4482
|
}
|
|
3717
4483
|
async set(roleIds) {
|
|
3718
4484
|
const data = await this.member.client.rest.patch(
|
|
3719
|
-
|
|
4485
|
+
Routes19.guildMember(this.member.guild.id, this.member.id),
|
|
3720
4486
|
{ body: { roles: roleIds }, auth: true }
|
|
3721
4487
|
);
|
|
3722
4488
|
this.ids = data.roles ? [...data.roles] : [];
|
|
@@ -3870,7 +4636,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3870
4636
|
*/
|
|
3871
4637
|
async edit(options) {
|
|
3872
4638
|
const isMe = this.client.user?.id === this.id;
|
|
3873
|
-
const route = isMe ?
|
|
4639
|
+
const route = isMe ? Routes20.guildMemberMe(this.guild.id) : Routes20.guildMember(this.guild.id, this.id);
|
|
3874
4640
|
const data = await this.client.rest.patch(route, {
|
|
3875
4641
|
body: toMemberEditBody(options),
|
|
3876
4642
|
auth: true,
|
|
@@ -3983,7 +4749,7 @@ var GuildMember = class _GuildMember extends Base {
|
|
|
3983
4749
|
};
|
|
3984
4750
|
|
|
3985
4751
|
// src/Domain/Guild/GuildSticker.ts
|
|
3986
|
-
import { Routes as
|
|
4752
|
+
import { Routes as Routes21 } from "@fluxerjs/types";
|
|
3987
4753
|
import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
|
|
3988
4754
|
var GuildSticker = class extends Base {
|
|
3989
4755
|
client;
|
|
@@ -4034,7 +4800,7 @@ var GuildSticker = class extends Base {
|
|
|
4034
4800
|
}
|
|
4035
4801
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
4036
4802
|
async delete(reason) {
|
|
4037
|
-
await this.client.rest.delete(
|
|
4803
|
+
await this.client.rest.delete(Routes21.guildSticker(this.guildId, this.id), {
|
|
4038
4804
|
auth: true,
|
|
4039
4805
|
...auditReasonHeaders(reason)
|
|
4040
4806
|
});
|
|
@@ -4047,7 +4813,7 @@ var GuildSticker = class extends Base {
|
|
|
4047
4813
|
*/
|
|
4048
4814
|
async edit(options) {
|
|
4049
4815
|
const { reason, ...body } = options;
|
|
4050
|
-
const data = await this.client.rest.patch(
|
|
4816
|
+
const data = await this.client.rest.patch(Routes21.guildSticker(this.guildId, this.id), {
|
|
4051
4817
|
body,
|
|
4052
4818
|
auth: true,
|
|
4053
4819
|
...auditReasonHeaders(reason)
|
|
@@ -4060,7 +4826,7 @@ var GuildSticker = class extends Base {
|
|
|
4060
4826
|
};
|
|
4061
4827
|
|
|
4062
4828
|
// src/Domain/Guild/Role.ts
|
|
4063
|
-
import { Routes as
|
|
4829
|
+
import { Routes as Routes22 } from "@fluxerjs/types";
|
|
4064
4830
|
import {
|
|
4065
4831
|
ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
|
|
4066
4832
|
PermissionFlags as PermissionFlags4,
|
|
@@ -4175,7 +4941,7 @@ var Role = class _Role extends Base {
|
|
|
4175
4941
|
*/
|
|
4176
4942
|
async edit(options) {
|
|
4177
4943
|
const body = toRoleEditBody(options);
|
|
4178
|
-
const data = await this.client.rest.patch(
|
|
4944
|
+
const data = await this.client.rest.patch(Routes22.guildRole(this.guildId, this.id), {
|
|
4179
4945
|
body: Object.keys(body).length ? body : void 0,
|
|
4180
4946
|
auth: true,
|
|
4181
4947
|
...auditReasonHeaders(options.reason)
|
|
@@ -4188,7 +4954,7 @@ var Role = class _Role extends Base {
|
|
|
4188
4954
|
* @param reason - Audit log reason (`X-Audit-Log-Reason`)
|
|
4189
4955
|
*/
|
|
4190
4956
|
async delete(reason) {
|
|
4191
|
-
await this.client.rest.delete(
|
|
4957
|
+
await this.client.rest.delete(Routes22.guildRole(this.guildId, this.id), {
|
|
4192
4958
|
auth: true,
|
|
4193
4959
|
...auditReasonHeaders(reason)
|
|
4194
4960
|
});
|
|
@@ -4283,11 +5049,30 @@ function syncChannels(guild, channels) {
|
|
|
4283
5049
|
const keep = new Set(channels.map((c) => c.id));
|
|
4284
5050
|
for (const data of channels) cacheChannel(guild, data);
|
|
4285
5051
|
for (const [id, channel] of [...guild.channels.entries()]) {
|
|
4286
|
-
if (keep.has(id)) continue;
|
|
5052
|
+
if (keep.has(id) || channel.isThread()) continue;
|
|
4287
5053
|
Map.prototype.delete.call(guild.channels, id);
|
|
4288
5054
|
guild.client.cache.cascadeChannel(channel, "guild");
|
|
4289
5055
|
}
|
|
4290
5056
|
}
|
|
5057
|
+
function isThreadChannelType(type) {
|
|
5058
|
+
return type === ChannelType9.AnnouncementThread || type === ChannelType9.PublicThread || type === ChannelType9.PrivateThread;
|
|
5059
|
+
}
|
|
5060
|
+
function syncThreads(guild, threads, alsoKeep = /* @__PURE__ */ new Set()) {
|
|
5061
|
+
const keep = new Set(alsoKeep);
|
|
5062
|
+
for (const data of threads) {
|
|
5063
|
+
if (!isThreadChannelType(data.type)) continue;
|
|
5064
|
+
const withGuild = data.guild_id ? data : { ...data, guild_id: guild.id };
|
|
5065
|
+
cacheThread(guild.client, withGuild);
|
|
5066
|
+
keep.add(data.id);
|
|
5067
|
+
}
|
|
5068
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5069
|
+
for (const channel of [...guild.channels.values(), ...guild.client.channels.values()]) {
|
|
5070
|
+
if (seen.has(channel.id)) continue;
|
|
5071
|
+
seen.add(channel.id);
|
|
5072
|
+
if (!channel.isThread() || channel.guildId !== guild.id || keep.has(channel.id)) continue;
|
|
5073
|
+
guild.client.cache.cascadeChannel(channel);
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
4291
5076
|
function mergeMembers(guild, members) {
|
|
4292
5077
|
for (const m of members) {
|
|
4293
5078
|
if (!m.user?.id) continue;
|
|
@@ -4351,7 +5136,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4351
5136
|
const cached = this.get(channelId);
|
|
4352
5137
|
if (cached && !options?.force) return cached;
|
|
4353
5138
|
try {
|
|
4354
|
-
const data = await this.client.rest.get(
|
|
5139
|
+
const data = await this.client.rest.get(Routes23.channel(channelId));
|
|
4355
5140
|
const guildId = "guild_id" in data ? data.guild_id : void 0;
|
|
4356
5141
|
if (guildId) {
|
|
4357
5142
|
const guild = this.client.guilds.get(guildId);
|
|
@@ -4396,7 +5181,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4396
5181
|
defaultAllowedMentions: this.client.options.defaultAllowedMentions
|
|
4397
5182
|
});
|
|
4398
5183
|
const data = await this.client.rest.post(
|
|
4399
|
-
|
|
5184
|
+
Routes23.channelMessages(channelId),
|
|
4400
5185
|
postPayload
|
|
4401
5186
|
);
|
|
4402
5187
|
this.client._addMessageToCache(channelId, data);
|
|
@@ -4406,7 +5191,7 @@ var ChannelManager = class extends LimitedCollection {
|
|
|
4406
5191
|
|
|
4407
5192
|
// src/ClientCore/ClientEmoji.ts
|
|
4408
5193
|
import { Collection as Collection8 } from "@fluxerjs/collection";
|
|
4409
|
-
import { Routes as
|
|
5194
|
+
import { Routes as Routes24 } from "@fluxerjs/types";
|
|
4410
5195
|
import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
|
|
4411
5196
|
async function resolveClientEmoji(client, emoji, guildId) {
|
|
4412
5197
|
if (typeof emoji === "object" && emoji.id) {
|
|
@@ -4425,7 +5210,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4425
5210
|
const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
|
|
4426
5211
|
if (unicodeFromShortcode) return unicodeFromShortcode;
|
|
4427
5212
|
if (guildId) {
|
|
4428
|
-
const emojis = await client.rest.get(
|
|
5213
|
+
const emojis = await client.rest.get(Routes24.guildEmojis(guildId));
|
|
4429
5214
|
const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
4430
5215
|
if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
|
|
4431
5216
|
throw new FluxerError(
|
|
@@ -4442,26 +5227,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
|
|
|
4442
5227
|
return parsed.name;
|
|
4443
5228
|
}
|
|
4444
5229
|
async function fetchInstance(client) {
|
|
4445
|
-
const raw = await client.rest.get(
|
|
5230
|
+
const raw = await client.rest.get(Routes24.instanceDiscovery(), {
|
|
4446
5231
|
auth: false,
|
|
4447
5232
|
unversioned: true
|
|
4448
5233
|
});
|
|
4449
5234
|
return parseInstanceDiscovery(raw);
|
|
4450
5235
|
}
|
|
4451
5236
|
function fetchGatewayInfo(client) {
|
|
4452
|
-
return client.rest.get(
|
|
5237
|
+
return client.rest.get(Routes24.gatewayBot());
|
|
4453
5238
|
}
|
|
4454
5239
|
function fetchEmojiMetadata(client, emojiId) {
|
|
4455
|
-
return client.rest.get(
|
|
5240
|
+
return client.rest.get(Routes24.emojiMetadata(emojiId), { auth: true });
|
|
4456
5241
|
}
|
|
4457
5242
|
function fetchStickerMetadata(client, stickerId) {
|
|
4458
|
-
return client.rest.get(
|
|
5243
|
+
return client.rest.get(Routes24.stickerMetadata(stickerId), { auth: true });
|
|
4459
5244
|
}
|
|
4460
5245
|
function fetchApplication(client) {
|
|
4461
|
-
return client.rest.get(
|
|
5246
|
+
return client.rest.get(Routes24.applicationsMe(), { auth: true });
|
|
4462
5247
|
}
|
|
4463
5248
|
async function fetchOAuthApplications(client) {
|
|
4464
|
-
const data = await client.rest.get(
|
|
5249
|
+
const data = await client.rest.get(Routes24.oauth2ApplicationsMe(), { auth: true });
|
|
4465
5250
|
if (Array.isArray(data)) return data;
|
|
4466
5251
|
if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
|
|
4467
5252
|
return data.applications;
|
|
@@ -4480,14 +5265,14 @@ function assertChannelIdBatch(name, channelIds) {
|
|
|
4480
5265
|
}
|
|
4481
5266
|
function preloadMessages(client, channelIds) {
|
|
4482
5267
|
assertChannelIdBatch("preloadMessages", channelIds);
|
|
4483
|
-
return client.rest.post(
|
|
5268
|
+
return client.rest.post(Routes24.preloadMessages(), {
|
|
4484
5269
|
body: { channels: channelIds },
|
|
4485
5270
|
auth: true
|
|
4486
5271
|
});
|
|
4487
5272
|
}
|
|
4488
5273
|
function preloadMessagesAlt(client, channelIds) {
|
|
4489
5274
|
assertChannelIdBatch("preloadMessagesAlt", channelIds);
|
|
4490
|
-
return client.rest.post(
|
|
5275
|
+
return client.rest.post(Routes24.preloadMessagesAlt(), {
|
|
4491
5276
|
body: { channels: channelIds },
|
|
4492
5277
|
auth: true
|
|
4493
5278
|
});
|
|
@@ -4495,7 +5280,7 @@ function preloadMessagesAlt(client, channelIds) {
|
|
|
4495
5280
|
async function bulkFetchMessages(client, requests, options = {}) {
|
|
4496
5281
|
validateBulkMessageFetchRequests(requests);
|
|
4497
5282
|
const wire = toBulkFetchWire(requests);
|
|
4498
|
-
const data = await client.rest.post(
|
|
5283
|
+
const data = await client.rest.post(Routes24.channelsMessagesBulk(), {
|
|
4499
5284
|
body: { requests: wire },
|
|
4500
5285
|
auth: true
|
|
4501
5286
|
});
|
|
@@ -4512,7 +5297,7 @@ async function bulkFetchMessages(client, requests, options = {}) {
|
|
|
4512
5297
|
};
|
|
4513
5298
|
}
|
|
4514
5299
|
async function searchMessages(client, options = {}) {
|
|
4515
|
-
const data = await client.rest.post(
|
|
5300
|
+
const data = await client.rest.post(Routes24.searchMessages(), {
|
|
4516
5301
|
body: toMessageSearchBody(options),
|
|
4517
5302
|
auth: true
|
|
4518
5303
|
});
|
|
@@ -4542,7 +5327,7 @@ import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
|
|
|
4542
5327
|
|
|
4543
5328
|
// src/ClientCore/GuildMemberManager.ts
|
|
4544
5329
|
import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
|
|
4545
|
-
import { Routes as
|
|
5330
|
+
import { Routes as Routes25 } from "@fluxerjs/types";
|
|
4546
5331
|
var GuildMemberManager = class extends LimitedCollection2 {
|
|
4547
5332
|
constructor(guild) {
|
|
4548
5333
|
super({ maxSize: guild.client.cache.limits.members });
|
|
@@ -4599,7 +5384,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
4599
5384
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
4600
5385
|
if (options?.after) params.set("after", options.after);
|
|
4601
5386
|
const qs2 = params.toString();
|
|
4602
|
-
const url =
|
|
5387
|
+
const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
|
|
4603
5388
|
const data = await this.guild.client.rest.get(url, { auth: true });
|
|
4604
5389
|
const members = [];
|
|
4605
5390
|
for (const m of data) {
|
|
@@ -4622,7 +5407,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
4622
5407
|
*/
|
|
4623
5408
|
async search(options = {}) {
|
|
4624
5409
|
const data = await this.guild.client.rest.post(
|
|
4625
|
-
|
|
5410
|
+
Routes25.guildMembersSearch(this.guild.id),
|
|
4626
5411
|
{ body: toMemberSearchBody(options), auth: true }
|
|
4627
5412
|
);
|
|
4628
5413
|
const offset = options.offset ?? 0;
|
|
@@ -4648,7 +5433,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
|
|
|
4648
5433
|
};
|
|
4649
5434
|
|
|
4650
5435
|
// src/Domain/Guild/Admin.ts
|
|
4651
|
-
import { Routes as
|
|
5436
|
+
import { Routes as Routes26 } from "@fluxerjs/types";
|
|
4652
5437
|
function toAuditLogEntryPayload(entry, guildId) {
|
|
4653
5438
|
return {
|
|
4654
5439
|
id: entry.id,
|
|
@@ -4669,7 +5454,7 @@ function toVanityPayload(data) {
|
|
|
4669
5454
|
return { code: data.code ?? null, uses: data.uses };
|
|
4670
5455
|
}
|
|
4671
5456
|
async function fetchAuditLogs(guild, options) {
|
|
4672
|
-
const url =
|
|
5457
|
+
const url = Routes26.guildAuditLogs(guild.id) + qs({
|
|
4673
5458
|
limit: options?.limit,
|
|
4674
5459
|
before: options?.before,
|
|
4675
5460
|
after: options?.after,
|
|
@@ -4693,7 +5478,7 @@ async function fetchAuditLogs(guild, options) {
|
|
|
4693
5478
|
};
|
|
4694
5479
|
}
|
|
4695
5480
|
async function editGuild(guild, options) {
|
|
4696
|
-
const data = await guild.client.rest.patch(
|
|
5481
|
+
const data = await guild.client.rest.patch(Routes26.guild(guild.id), {
|
|
4697
5482
|
body: toGuildEditBody(options),
|
|
4698
5483
|
auth: true
|
|
4699
5484
|
});
|
|
@@ -4701,13 +5486,13 @@ async function editGuild(guild, options) {
|
|
|
4701
5486
|
return guild;
|
|
4702
5487
|
}
|
|
4703
5488
|
async function fetchVanityURL(guild) {
|
|
4704
|
-
const data = await guild.client.rest.get(
|
|
5489
|
+
const data = await guild.client.rest.get(Routes26.guildVanityUrl(guild.id), {
|
|
4705
5490
|
auth: true
|
|
4706
5491
|
});
|
|
4707
5492
|
return toVanityPayload(data);
|
|
4708
5493
|
}
|
|
4709
5494
|
async function editVanityURL(guild, code) {
|
|
4710
|
-
const data = await guild.client.rest.patch(
|
|
5495
|
+
const data = await guild.client.rest.patch(Routes26.guildVanityUrl(guild.id), {
|
|
4711
5496
|
body: { code },
|
|
4712
5497
|
auth: true
|
|
4713
5498
|
});
|
|
@@ -4715,14 +5500,14 @@ async function editVanityURL(guild, code) {
|
|
|
4715
5500
|
return toVanityPayload(data);
|
|
4716
5501
|
}
|
|
4717
5502
|
async function fetchDiscoveryStatus(guild) {
|
|
4718
|
-
const data = await guild.client.rest.get(
|
|
5503
|
+
const data = await guild.client.rest.get(Routes26.guildDiscovery(guild.id), {
|
|
4719
5504
|
auth: true
|
|
4720
5505
|
});
|
|
4721
5506
|
return toDiscoveryStatusPayload(data);
|
|
4722
5507
|
}
|
|
4723
5508
|
async function applyForDiscovery(guild, options) {
|
|
4724
5509
|
const data = await guild.client.rest.post(
|
|
4725
|
-
|
|
5510
|
+
Routes26.guildDiscovery(guild.id),
|
|
4726
5511
|
{
|
|
4727
5512
|
body: toDiscoveryBody(options),
|
|
4728
5513
|
auth: true
|
|
@@ -4732,7 +5517,7 @@ async function applyForDiscovery(guild, options) {
|
|
|
4732
5517
|
}
|
|
4733
5518
|
async function editDiscoveryApplication(guild, options) {
|
|
4734
5519
|
const data = await guild.client.rest.patch(
|
|
4735
|
-
|
|
5520
|
+
Routes26.guildDiscovery(guild.id),
|
|
4736
5521
|
{
|
|
4737
5522
|
body: toDiscoveryBody(options),
|
|
4738
5523
|
auth: true
|
|
@@ -4741,34 +5526,34 @@ async function editDiscoveryApplication(guild, options) {
|
|
|
4741
5526
|
return toDiscoveryApplicationPayload(data);
|
|
4742
5527
|
}
|
|
4743
5528
|
async function withdrawDiscoveryApplication(guild) {
|
|
4744
|
-
await guild.client.rest.delete(
|
|
5529
|
+
await guild.client.rest.delete(Routes26.guildDiscovery(guild.id), { auth: true });
|
|
4745
5530
|
}
|
|
4746
5531
|
async function deleteGuild(guild, options) {
|
|
4747
5532
|
const body = options ? toSudoBody(options) : {};
|
|
4748
|
-
await guild.client.rest.post(
|
|
5533
|
+
await guild.client.rest.post(Routes26.guildDelete(guild.id), {
|
|
4749
5534
|
body,
|
|
4750
5535
|
auth: true
|
|
4751
5536
|
});
|
|
4752
5537
|
guild.client.guilds.delete(guild.id);
|
|
4753
5538
|
}
|
|
4754
5539
|
async function transferOwnership(guild, newOwnerId, password) {
|
|
4755
|
-
await guild.client.rest.post(
|
|
5540
|
+
await guild.client.rest.post(Routes26.guildTransferOwnership(guild.id), {
|
|
4756
5541
|
body: { new_owner_id: newOwnerId, ...password != null && { password } },
|
|
4757
5542
|
auth: true
|
|
4758
5543
|
});
|
|
4759
5544
|
}
|
|
4760
5545
|
|
|
4761
5546
|
// src/Domain/Guild/Channels.ts
|
|
4762
|
-
import { Routes as
|
|
5547
|
+
import { Routes as Routes27 } from "@fluxerjs/types";
|
|
4763
5548
|
async function createChannel(guild, options) {
|
|
4764
|
-
const created = await guild.client.rest.post(
|
|
5549
|
+
const created = await guild.client.rest.post(Routes27.guildChannels(guild.id), {
|
|
4765
5550
|
body: toChannelCreateBody(options),
|
|
4766
5551
|
auth: true
|
|
4767
5552
|
});
|
|
4768
5553
|
return cacheChannel(guild, created);
|
|
4769
5554
|
}
|
|
4770
5555
|
async function fetchChannels(guild) {
|
|
4771
|
-
const data = await guild.client.rest.get(
|
|
5556
|
+
const data = await guild.client.rest.get(Routes27.guildChannels(guild.id));
|
|
4772
5557
|
const channels = [];
|
|
4773
5558
|
for (const ch of data) {
|
|
4774
5559
|
const channel = cacheChannel(guild, ch);
|
|
@@ -4777,17 +5562,17 @@ async function fetchChannels(guild) {
|
|
|
4777
5562
|
return channels;
|
|
4778
5563
|
}
|
|
4779
5564
|
async function setChannelPositions(guild, updates) {
|
|
4780
|
-
await guild.client.rest.patch(
|
|
5565
|
+
await guild.client.rest.patch(Routes27.guildChannels(guild.id), {
|
|
4781
5566
|
body: toChannelPositionBody(updates),
|
|
4782
5567
|
auth: true
|
|
4783
5568
|
});
|
|
4784
5569
|
}
|
|
4785
5570
|
async function fetchWebhooks(guild) {
|
|
4786
|
-
const data = await guild.client.rest.get(
|
|
5571
|
+
const data = await guild.client.rest.get(Routes27.guildWebhooks(guild.id));
|
|
4787
5572
|
return data.map((w) => new Webhook(guild.client, w));
|
|
4788
5573
|
}
|
|
4789
5574
|
async function fetchInvites(guild) {
|
|
4790
|
-
const data = await guild.client.rest.get(
|
|
5575
|
+
const data = await guild.client.rest.get(Routes27.guildInvites(guild.id));
|
|
4791
5576
|
return data.map((invite) => new Invite(guild.client, invite));
|
|
4792
5577
|
}
|
|
4793
5578
|
async function fetchInvite(guild, codeOrUrl) {
|
|
@@ -4807,14 +5592,14 @@ function resolveGuildOnlineCount(data) {
|
|
|
4807
5592
|
}
|
|
4808
5593
|
|
|
4809
5594
|
// src/Domain/Guild/Emojis.ts
|
|
4810
|
-
import { Routes as
|
|
5595
|
+
import { Routes as Routes28 } from "@fluxerjs/types";
|
|
4811
5596
|
async function fetchEmojis(guild) {
|
|
4812
|
-
const data = await guild.client.rest.get(
|
|
5597
|
+
const data = await guild.client.rest.get(Routes28.guildEmojis(guild.id));
|
|
4813
5598
|
return data.map((e) => cacheEmoji(guild, e));
|
|
4814
5599
|
}
|
|
4815
5600
|
async function fetchEmoji(guild, emojiId) {
|
|
4816
5601
|
try {
|
|
4817
|
-
const data = await guild.client.rest.get(
|
|
5602
|
+
const data = await guild.client.rest.get(Routes28.guildEmoji(guild.id, emojiId));
|
|
4818
5603
|
return cacheEmoji(guild, data);
|
|
4819
5604
|
} catch (err) {
|
|
4820
5605
|
rethrowMapped(err, {
|
|
@@ -4825,7 +5610,7 @@ async function fetchEmoji(guild, emojiId) {
|
|
|
4825
5610
|
}
|
|
4826
5611
|
async function createEmoji(guild, options) {
|
|
4827
5612
|
const { reason, ...body } = options;
|
|
4828
|
-
const data = await guild.client.rest.post(
|
|
5613
|
+
const data = await guild.client.rest.post(Routes28.guildEmojis(guild.id), {
|
|
4829
5614
|
body,
|
|
4830
5615
|
auth: true,
|
|
4831
5616
|
...auditReasonHeaders(reason)
|
|
@@ -4833,7 +5618,7 @@ async function createEmoji(guild, options) {
|
|
|
4833
5618
|
return cacheEmoji(guild, data);
|
|
4834
5619
|
}
|
|
4835
5620
|
async function cloneEmoji(guild, sourceEmojiId) {
|
|
4836
|
-
const data = await guild.client.rest.post(
|
|
5621
|
+
const data = await guild.client.rest.post(Routes28.guildEmojisClone(guild.id), {
|
|
4837
5622
|
body: { source_emoji_id: sourceEmojiId },
|
|
4838
5623
|
auth: true
|
|
4839
5624
|
});
|
|
@@ -4841,7 +5626,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
|
|
|
4841
5626
|
}
|
|
4842
5627
|
async function createEmojisBulk(guild, emojis) {
|
|
4843
5628
|
const data = await guild.client.rest.post(
|
|
4844
|
-
|
|
5629
|
+
Routes28.guildEmojisBulk(guild.id),
|
|
4845
5630
|
{ body: { emojis }, auth: true }
|
|
4846
5631
|
);
|
|
4847
5632
|
return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
|
|
@@ -4861,11 +5646,11 @@ var GuildRoleManager = class extends LimitedCollection3 {
|
|
|
4861
5646
|
};
|
|
4862
5647
|
|
|
4863
5648
|
// src/Domain/Guild/MemberHttp.ts
|
|
4864
|
-
import { Routes as
|
|
5649
|
+
import { Routes as Routes29 } from "@fluxerjs/types";
|
|
4865
5650
|
async function fetchMember(guild, userId) {
|
|
4866
5651
|
try {
|
|
4867
5652
|
const data = await guild.client.rest.get(
|
|
4868
|
-
|
|
5653
|
+
Routes29.guildMember(guild.id, userId)
|
|
4869
5654
|
);
|
|
4870
5655
|
return cacheMember(guild, data);
|
|
4871
5656
|
} catch (err) {
|
|
@@ -4880,17 +5665,17 @@ async function fetchMember(guild, userId) {
|
|
|
4880
5665
|
}
|
|
4881
5666
|
async function fetchMe(guild) {
|
|
4882
5667
|
const data = await guild.client.rest.get(
|
|
4883
|
-
|
|
5668
|
+
Routes29.guildMemberMe(guild.id),
|
|
4884
5669
|
{ auth: true }
|
|
4885
5670
|
);
|
|
4886
5671
|
return cacheMember(guild, data);
|
|
4887
5672
|
}
|
|
4888
5673
|
|
|
4889
5674
|
// src/Domain/Guild/Moderation.ts
|
|
4890
|
-
import { Routes as
|
|
5675
|
+
import { Routes as Routes31 } from "@fluxerjs/types";
|
|
4891
5676
|
|
|
4892
5677
|
// src/Domain/Guild/GuildBan.ts
|
|
4893
|
-
import { Routes as
|
|
5678
|
+
import { Routes as Routes30 } from "@fluxerjs/types";
|
|
4894
5679
|
function parseOptionalDate2(value) {
|
|
4895
5680
|
if (value == null || value === "") return null;
|
|
4896
5681
|
const date = new Date(value);
|
|
@@ -4917,7 +5702,7 @@ var GuildBan = class extends Base {
|
|
|
4917
5702
|
* Requires Ban Members permission.
|
|
4918
5703
|
*/
|
|
4919
5704
|
async unban(reason) {
|
|
4920
|
-
await this.client.rest.delete(
|
|
5705
|
+
await this.client.rest.delete(Routes30.guildBan(this.guildId, this.user.id), {
|
|
4921
5706
|
auth: true,
|
|
4922
5707
|
...auditReasonHeaders(reason)
|
|
4923
5708
|
});
|
|
@@ -4927,35 +5712,35 @@ var GuildBan = class extends Base {
|
|
|
4927
5712
|
// src/Domain/Guild/Moderation.ts
|
|
4928
5713
|
async function ban(guild, userId, options) {
|
|
4929
5714
|
const body = options ? toGuildBanBody(options) : {};
|
|
4930
|
-
await guild.client.rest.put(
|
|
5715
|
+
await guild.client.rest.put(Routes31.guildBan(guild.id, userId), {
|
|
4931
5716
|
body: Object.keys(body).length ? body : void 0,
|
|
4932
5717
|
auth: true,
|
|
4933
5718
|
...auditReasonHeaders(options?.reason)
|
|
4934
5719
|
});
|
|
4935
5720
|
}
|
|
4936
5721
|
async function fetchBans(guild) {
|
|
4937
|
-
const data = await guild.client.rest.get(
|
|
5722
|
+
const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
|
|
4938
5723
|
return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
|
|
4939
5724
|
}
|
|
4940
5725
|
async function unban(guild, userId, reason) {
|
|
4941
|
-
await guild.client.rest.delete(
|
|
5726
|
+
await guild.client.rest.delete(Routes31.guildBan(guild.id, userId), {
|
|
4942
5727
|
auth: true,
|
|
4943
5728
|
...auditReasonHeaders(reason)
|
|
4944
5729
|
});
|
|
4945
5730
|
}
|
|
4946
5731
|
async function kick(guild, userId, reason) {
|
|
4947
|
-
await guild.client.rest.delete(
|
|
5732
|
+
await guild.client.rest.delete(Routes31.guildMember(guild.id, userId), {
|
|
4948
5733
|
auth: true,
|
|
4949
5734
|
...auditReasonHeaders(reason)
|
|
4950
5735
|
});
|
|
4951
5736
|
}
|
|
4952
5737
|
|
|
4953
5738
|
// src/Domain/Guild/Roles.ts
|
|
4954
|
-
import { Routes as
|
|
5739
|
+
import { Routes as Routes32 } from "@fluxerjs/types";
|
|
4955
5740
|
import { parseRoleMention } from "@fluxerjs/util";
|
|
4956
5741
|
async function createRole(guild, options = {}) {
|
|
4957
5742
|
const body = toRoleCreateBody(options);
|
|
4958
|
-
const data = await guild.client.rest.post(
|
|
5743
|
+
const data = await guild.client.rest.post(Routes32.guildRoles(guild.id), {
|
|
4959
5744
|
body: Object.keys(body).length ? body : void 0,
|
|
4960
5745
|
auth: true,
|
|
4961
5746
|
...auditReasonHeaders(options.reason)
|
|
@@ -4963,12 +5748,12 @@ async function createRole(guild, options = {}) {
|
|
|
4963
5748
|
return cacheRole(guild, data);
|
|
4964
5749
|
}
|
|
4965
5750
|
async function fetchRoles(guild) {
|
|
4966
|
-
const data = await guild.client.rest.get(
|
|
5751
|
+
const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
|
|
4967
5752
|
return data.map((r) => cacheRole(guild, r));
|
|
4968
5753
|
}
|
|
4969
5754
|
async function fetchRole(guild, roleId2) {
|
|
4970
5755
|
try {
|
|
4971
|
-
const data = await guild.client.rest.get(
|
|
5756
|
+
const data = await guild.client.rest.get(Routes32.guildRole(guild.id, roleId2));
|
|
4972
5757
|
return cacheRole(guild, data);
|
|
4973
5758
|
} catch (err) {
|
|
4974
5759
|
rethrowMapped(err, {
|
|
@@ -4985,7 +5770,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
4985
5770
|
const needle = trimmed.toLowerCase();
|
|
4986
5771
|
const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
|
|
4987
5772
|
if (cached) return cached.id;
|
|
4988
|
-
const roles = await guild.client.rest.get(
|
|
5773
|
+
const roles = await guild.client.rest.get(Routes32.guildRoles(guild.id));
|
|
4989
5774
|
const role = roles.find((r) => r.name?.toLowerCase() === needle);
|
|
4990
5775
|
if (!role) return null;
|
|
4991
5776
|
cacheRole(guild, role);
|
|
@@ -4994,7 +5779,7 @@ async function resolveRoleId(guild, arg) {
|
|
|
4994
5779
|
async function setRolePositions(guild, updates) {
|
|
4995
5780
|
return replaceRoles(
|
|
4996
5781
|
guild,
|
|
4997
|
-
await guild.client.rest.patch(
|
|
5782
|
+
await guild.client.rest.patch(Routes32.guildRoles(guild.id), {
|
|
4998
5783
|
body: updates,
|
|
4999
5784
|
auth: true
|
|
5000
5785
|
})
|
|
@@ -5003,7 +5788,7 @@ async function setRolePositions(guild, updates) {
|
|
|
5003
5788
|
async function setRoleHoistPositions(guild, updates) {
|
|
5004
5789
|
return replaceRoles(
|
|
5005
5790
|
guild,
|
|
5006
|
-
await guild.client.rest.patch(
|
|
5791
|
+
await guild.client.rest.patch(Routes32.guildRolesHoistPositions(guild.id), {
|
|
5007
5792
|
body: updates.map((u) => ({
|
|
5008
5793
|
id: u.id,
|
|
5009
5794
|
...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
|
|
@@ -5015,17 +5800,17 @@ async function setRoleHoistPositions(guild, updates) {
|
|
|
5015
5800
|
async function resetRoleHoistPositions(guild) {
|
|
5016
5801
|
return replaceRoles(
|
|
5017
5802
|
guild,
|
|
5018
|
-
await guild.client.rest.delete(
|
|
5803
|
+
await guild.client.rest.delete(Routes32.guildRolesHoistPositions(guild.id), {
|
|
5019
5804
|
auth: true
|
|
5020
5805
|
})
|
|
5021
5806
|
);
|
|
5022
5807
|
}
|
|
5023
5808
|
|
|
5024
5809
|
// src/Domain/Guild/Stickers.ts
|
|
5025
|
-
import { Routes as
|
|
5810
|
+
import { Routes as Routes33 } from "@fluxerjs/types";
|
|
5026
5811
|
async function createSticker(guild, options) {
|
|
5027
5812
|
const { reason, ...body } = options;
|
|
5028
|
-
const data = await guild.client.rest.post(
|
|
5813
|
+
const data = await guild.client.rest.post(Routes33.guildStickers(guild.id), {
|
|
5029
5814
|
body,
|
|
5030
5815
|
auth: true,
|
|
5031
5816
|
...auditReasonHeaders(reason)
|
|
@@ -5033,7 +5818,7 @@ async function createSticker(guild, options) {
|
|
|
5033
5818
|
return cacheSticker(guild, data);
|
|
5034
5819
|
}
|
|
5035
5820
|
async function cloneSticker(guild, sourceStickerId) {
|
|
5036
|
-
const data = await guild.client.rest.post(
|
|
5821
|
+
const data = await guild.client.rest.post(Routes33.guildStickersClone(guild.id), {
|
|
5037
5822
|
body: { source_sticker_id: sourceStickerId },
|
|
5038
5823
|
auth: true
|
|
5039
5824
|
});
|
|
@@ -5041,17 +5826,17 @@ async function cloneSticker(guild, sourceStickerId) {
|
|
|
5041
5826
|
}
|
|
5042
5827
|
async function createStickersBulk(guild, stickers) {
|
|
5043
5828
|
const data = await guild.client.rest.post(
|
|
5044
|
-
|
|
5829
|
+
Routes33.guildStickersBulk(guild.id),
|
|
5045
5830
|
{ body: { stickers }, auth: true }
|
|
5046
5831
|
);
|
|
5047
5832
|
return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
|
|
5048
5833
|
}
|
|
5049
5834
|
async function fetchStickers(guild) {
|
|
5050
|
-
const data = await guild.client.rest.get(
|
|
5835
|
+
const data = await guild.client.rest.get(Routes33.guildStickers(guild.id));
|
|
5051
5836
|
return data.map((s) => cacheSticker(guild, s));
|
|
5052
5837
|
}
|
|
5053
5838
|
async function fetchSticker(guild, stickerId) {
|
|
5054
|
-
const data = await guild.client.rest.get(
|
|
5839
|
+
const data = await guild.client.rest.get(Routes33.guildSticker(guild.id, stickerId));
|
|
5055
5840
|
return cacheSticker(guild, data);
|
|
5056
5841
|
}
|
|
5057
5842
|
|
|
@@ -5283,7 +6068,7 @@ var Guild = class extends Base {
|
|
|
5283
6068
|
});
|
|
5284
6069
|
}
|
|
5285
6070
|
/**
|
|
5286
|
-
* Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
|
|
6071
|
+
* Create a channel. `type`: 0=text, 2=voice, 4=category, 5=announcement, 15=forum, 16=media, 998=link (set `url`).
|
|
5287
6072
|
* Requires Manage Channels.
|
|
5288
6073
|
*/
|
|
5289
6074
|
createChannel(options) {
|
|
@@ -5293,6 +6078,10 @@ var Guild = class extends Base {
|
|
|
5293
6078
|
fetchChannels() {
|
|
5294
6079
|
return fetchChannels(this);
|
|
5295
6080
|
}
|
|
6081
|
+
/** Fetch active threads in this guild. */
|
|
6082
|
+
fetchActiveThreads() {
|
|
6083
|
+
return fetchActiveThreads(this.client, this.id);
|
|
6084
|
+
}
|
|
5296
6085
|
/** Update channel positions (reordering). */
|
|
5297
6086
|
setChannelPositions(updates) {
|
|
5298
6087
|
return setChannelPositions(this, updates);
|
|
@@ -5523,6 +6312,13 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
|
|
|
5523
6312
|
client.guilds.set(guild.id, guild);
|
|
5524
6313
|
if (resources.roles !== void 0) syncRoles(guild, resources.roles);
|
|
5525
6314
|
if (resources.channels !== void 0) syncChannels(guild, resources.channels);
|
|
6315
|
+
if (resources.threads !== void 0) {
|
|
6316
|
+
syncThreads(
|
|
6317
|
+
guild,
|
|
6318
|
+
resources.threads,
|
|
6319
|
+
new Set((resources.channels ?? []).map((channel) => channel.id))
|
|
6320
|
+
);
|
|
6321
|
+
}
|
|
5526
6322
|
if (resources.members !== void 0) mergeMembers(guild, resources.members);
|
|
5527
6323
|
if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
|
|
5528
6324
|
if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
|
|
@@ -5537,7 +6333,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
5537
6333
|
channels: g.channels,
|
|
5538
6334
|
members: g.members,
|
|
5539
6335
|
emojis: g.emojis,
|
|
5540
|
-
stickers: g.stickers
|
|
6336
|
+
stickers: g.stickers,
|
|
6337
|
+
// A channel list without `threads` means this session has no viewable threads.
|
|
6338
|
+
threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
|
|
5541
6339
|
});
|
|
5542
6340
|
if (g.voice_states?.length) {
|
|
5543
6341
|
client.emit(Events.VoiceStatesSync, {
|
|
@@ -5549,7 +6347,7 @@ function applyGuildSnapshotFromGateway(client, raw) {
|
|
|
5549
6347
|
}
|
|
5550
6348
|
|
|
5551
6349
|
// src/ClientCore/ClientUser.ts
|
|
5552
|
-
import { GatewayOpcodes, Routes as
|
|
6350
|
+
import { GatewayOpcodes, Routes as Routes34 } from "@fluxerjs/types";
|
|
5553
6351
|
var ClientUser = class extends User {
|
|
5554
6352
|
/** Broadcast presence (gateway opcode 3) on all shards. */
|
|
5555
6353
|
setPresence(presence) {
|
|
@@ -5559,13 +6357,13 @@ var ClientUser = class extends User {
|
|
|
5559
6357
|
}
|
|
5560
6358
|
/** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
|
|
5561
6359
|
async fetch() {
|
|
5562
|
-
const data = await this.client.rest.get(
|
|
6360
|
+
const data = await this.client.rest.get(Routes34.currentUser(), { auth: true });
|
|
5563
6361
|
this._patch(data);
|
|
5564
6362
|
return this;
|
|
5565
6363
|
}
|
|
5566
6364
|
/** GET /users/@me/guilds — returns camelCase partial guilds. */
|
|
5567
6365
|
async fetchGuilds(options) {
|
|
5568
|
-
const path =
|
|
6366
|
+
const path = Routes34.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
|
|
5569
6367
|
const data = await this.client.rest.get(path, { auth: true });
|
|
5570
6368
|
return data.map((g) => ({
|
|
5571
6369
|
id: g.id,
|
|
@@ -5589,7 +6387,7 @@ var ClientUser = class extends User {
|
|
|
5589
6387
|
*/
|
|
5590
6388
|
async leaveGuild(guildId, options) {
|
|
5591
6389
|
const body = options ? toSudoBody(options) : void 0;
|
|
5592
|
-
await this.client.rest.delete(
|
|
6390
|
+
await this.client.rest.delete(Routes34.leaveGuild(guildId), {
|
|
5593
6391
|
body: body && Object.keys(body).length ? body : void 0,
|
|
5594
6392
|
auth: true
|
|
5595
6393
|
});
|
|
@@ -5597,7 +6395,7 @@ var ClientUser = class extends User {
|
|
|
5597
6395
|
/** Delete every message authored by the caller across a guild (sudo). */
|
|
5598
6396
|
async bulkDeleteMyMessagesInGuild(guildId, options) {
|
|
5599
6397
|
const body = options ? toSudoBody(options) : void 0;
|
|
5600
|
-
await this.client.rest.post(
|
|
6398
|
+
await this.client.rest.post(Routes34.guildBulkDeleteMine(guildId), {
|
|
5601
6399
|
body: body && Object.keys(body).length ? body : void 0,
|
|
5602
6400
|
auth: true
|
|
5603
6401
|
});
|
|
@@ -5632,6 +6430,7 @@ var channelHandlers = {
|
|
|
5632
6430
|
if (!ch) return;
|
|
5633
6431
|
indexChannel(client, ch);
|
|
5634
6432
|
client.emit(Events.ChannelCreate, ch);
|
|
6433
|
+
if (ch.isThread()) client.emit(Events.ThreadCreate, ch);
|
|
5635
6434
|
},
|
|
5636
6435
|
CHANNEL_UPDATE(client, d) {
|
|
5637
6436
|
const data = d;
|
|
@@ -5644,12 +6443,14 @@ var channelHandlers = {
|
|
|
5644
6443
|
existing._patch(data);
|
|
5645
6444
|
indexChannel(client, existing);
|
|
5646
6445
|
client.emit(Events.ChannelUpdate, oldCh, existing);
|
|
6446
|
+
if (existing.isThread()) client.emit(Events.ThreadUpdate, oldCh, existing);
|
|
5647
6447
|
return;
|
|
5648
6448
|
}
|
|
5649
6449
|
const newCh = Channel.from(client, data);
|
|
5650
6450
|
if (!newCh) return;
|
|
5651
6451
|
indexChannel(client, newCh);
|
|
5652
6452
|
client.emit(Events.ChannelUpdate, existing ?? newCh, newCh);
|
|
6453
|
+
if (newCh.isThread()) client.emit(Events.ThreadUpdate, existing ?? newCh, newCh);
|
|
5653
6454
|
},
|
|
5654
6455
|
CHANNEL_UPDATE_BULK(client, d) {
|
|
5655
6456
|
const data = d;
|
|
@@ -5671,7 +6472,11 @@ var channelHandlers = {
|
|
|
5671
6472
|
}
|
|
5672
6473
|
if (!channel) return;
|
|
5673
6474
|
client.channels.delete(id);
|
|
6475
|
+
if (channel.isGuild() && channel.guildId) {
|
|
6476
|
+
client.guilds.get(channel.guildId)?.channels.delete(id);
|
|
6477
|
+
}
|
|
5674
6478
|
client.emit(Events.ChannelDelete, channel);
|
|
6479
|
+
if (channel.isThread()) client.emit(Events.ThreadDelete, channel);
|
|
5675
6480
|
},
|
|
5676
6481
|
CHANNEL_PINS_UPDATE(client, d) {
|
|
5677
6482
|
const data = d;
|
|
@@ -5861,6 +6666,10 @@ var guildHandlers = {
|
|
|
5861
6666
|
}
|
|
5862
6667
|
client._onGuildReceived(guild.id);
|
|
5863
6668
|
},
|
|
6669
|
+
/** Same snapshot as Guild Create, including `threads`. Cache only: this is not a join. */
|
|
6670
|
+
GUILD_SYNC(client, d) {
|
|
6671
|
+
applyGuildSnapshotFromGateway(client, d);
|
|
6672
|
+
},
|
|
5864
6673
|
GUILD_UPDATE(client, d) {
|
|
5865
6674
|
const guildData = normalizeGuildUpdatePayload(d);
|
|
5866
6675
|
if (!guildData) return;
|
|
@@ -5910,7 +6719,7 @@ var guildHandlers = {
|
|
|
5910
6719
|
|
|
5911
6720
|
// src/ClientCore/EventHandlers/Invites.ts
|
|
5912
6721
|
import {
|
|
5913
|
-
ChannelType as
|
|
6722
|
+
ChannelType as ChannelType10,
|
|
5914
6723
|
InviteType as InviteType2
|
|
5915
6724
|
} from "@fluxerjs/types";
|
|
5916
6725
|
function normalizeInviteCreate(client, payload) {
|
|
@@ -5935,11 +6744,11 @@ function normalizeInviteCreate(client, payload) {
|
|
|
5935
6744
|
const guildId = str(guildObj?.id) ?? str(raw.guild_id) ?? "0";
|
|
5936
6745
|
const channelId = str(channelObj?.id) ?? str(raw.channel_id) ?? "0";
|
|
5937
6746
|
const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
|
|
5938
|
-
const
|
|
6747
|
+
const cachedChannel2 = channelId !== "0" ? client.channels.get(channelId) : null;
|
|
5939
6748
|
const channel = {
|
|
5940
6749
|
id: channelId,
|
|
5941
|
-
type: num(channelObj?.type) ??
|
|
5942
|
-
name: str(channelObj?.name) ??
|
|
6750
|
+
type: num(channelObj?.type) ?? cachedChannel2?.type ?? ChannelType10.GuildText,
|
|
6751
|
+
name: str(channelObj?.name) ?? cachedChannel2?.name ?? null,
|
|
5943
6752
|
icon: channelObj?.icon ?? null
|
|
5944
6753
|
};
|
|
5945
6754
|
if (type === InviteType2.GroupDM) return { ...shared, type, channel };
|
|
@@ -6343,6 +7152,107 @@ var passthroughHandlers = {
|
|
|
6343
7152
|
WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
|
|
6344
7153
|
};
|
|
6345
7154
|
|
|
7155
|
+
// src/ClientCore/EventHandlers/Threads.ts
|
|
7156
|
+
function cachedChannel(client, id) {
|
|
7157
|
+
const direct = client.channels.get(id);
|
|
7158
|
+
if (direct) return direct;
|
|
7159
|
+
for (const guild of client.guilds.values()) {
|
|
7160
|
+
const nested = guild.channels.get(id);
|
|
7161
|
+
if (nested) return nested;
|
|
7162
|
+
}
|
|
7163
|
+
return null;
|
|
7164
|
+
}
|
|
7165
|
+
var threadHandlers = {
|
|
7166
|
+
THREAD_CREATE(client, d) {
|
|
7167
|
+
channelHandlers.CHANNEL_CREATE(client, d);
|
|
7168
|
+
},
|
|
7169
|
+
THREAD_UPDATE(client, d) {
|
|
7170
|
+
channelHandlers.CHANNEL_UPDATE(client, d);
|
|
7171
|
+
},
|
|
7172
|
+
THREAD_DELETE(client, d) {
|
|
7173
|
+
const data = d;
|
|
7174
|
+
const existing = data.id ? cachedChannel(client, data.id) : null;
|
|
7175
|
+
if (existing?.isThread()) {
|
|
7176
|
+
channelHandlers.CHANNEL_DELETE(client, data);
|
|
7177
|
+
return;
|
|
7178
|
+
}
|
|
7179
|
+
if (!data.id || !isThreadType(data.type)) return;
|
|
7180
|
+
const thread = Channel.from(client, {
|
|
7181
|
+
id: data.id,
|
|
7182
|
+
type: data.type,
|
|
7183
|
+
guild_id: data.guild_id,
|
|
7184
|
+
parent_id: data.parent_id
|
|
7185
|
+
});
|
|
7186
|
+
if (!thread.isThread()) return;
|
|
7187
|
+
client.emit(Events.ChannelDelete, thread);
|
|
7188
|
+
client.emit(Events.ThreadDelete, thread);
|
|
7189
|
+
},
|
|
7190
|
+
THREAD_LIST_SYNC(client, d) {
|
|
7191
|
+
const data = d;
|
|
7192
|
+
const { threads } = fetchedThreadsFrom(client, {
|
|
7193
|
+
threads: data.threads ?? [],
|
|
7194
|
+
members: data.members ?? []
|
|
7195
|
+
});
|
|
7196
|
+
const payload = {
|
|
7197
|
+
guildId: data.guild_id,
|
|
7198
|
+
channelIds: data.channel_ids ?? [],
|
|
7199
|
+
threads
|
|
7200
|
+
};
|
|
7201
|
+
client.emit(Events.ThreadListSync, payload);
|
|
7202
|
+
},
|
|
7203
|
+
THREAD_MEMBER_UPDATE(client, d) {
|
|
7204
|
+
const data = d;
|
|
7205
|
+
const member = new ThreadMember(data);
|
|
7206
|
+
const thread = member.id ? client.channels.get(member.id) : void 0;
|
|
7207
|
+
if (thread?.isThread() && member.userId && member.userId === client.user?.id) {
|
|
7208
|
+
thread.member = member;
|
|
7209
|
+
}
|
|
7210
|
+
client.emit(Events.ThreadMemberUpdate, member);
|
|
7211
|
+
},
|
|
7212
|
+
THREAD_MEMBERS_UPDATE(client, d) {
|
|
7213
|
+
const data = d;
|
|
7214
|
+
const thread = client.channels.get(data.id);
|
|
7215
|
+
if (thread?.isThread()) thread.memberCount = data.member_count;
|
|
7216
|
+
const payload = {
|
|
7217
|
+
id: data.id,
|
|
7218
|
+
guildId: data.guild_id,
|
|
7219
|
+
memberCount: data.member_count,
|
|
7220
|
+
addedMembers: (data.added_members ?? []).map((member) => new ThreadMember(member)),
|
|
7221
|
+
removedMemberIds: data.removed_member_ids ?? []
|
|
7222
|
+
};
|
|
7223
|
+
client.emit(Events.ThreadMembersUpdate, payload);
|
|
7224
|
+
},
|
|
7225
|
+
THREAD_MEMBER_LIST_UPDATE(client, d) {
|
|
7226
|
+
const data = d;
|
|
7227
|
+
const guild = data.guild_id ? client.guilds.get(data.guild_id) : void 0;
|
|
7228
|
+
const payload = {
|
|
7229
|
+
guildId: data.guild_id,
|
|
7230
|
+
threadId: data.thread_id,
|
|
7231
|
+
members: (data.members ?? []).map((entry) => ({
|
|
7232
|
+
userId: entry.user_id,
|
|
7233
|
+
joinTimestamp: entry.join_timestamp,
|
|
7234
|
+
flags: entry.flags,
|
|
7235
|
+
member: guild && entry.member?.user?.id ? cacheMember(guild, entry.member) : null,
|
|
7236
|
+
presence: entry.presence ? { status: entry.presence.status ?? null } : null
|
|
7237
|
+
}))
|
|
7238
|
+
};
|
|
7239
|
+
client.emit(Events.ThreadMemberListUpdate, payload);
|
|
7240
|
+
},
|
|
7241
|
+
FORUM_UNREADS(client, d) {
|
|
7242
|
+
const data = d;
|
|
7243
|
+
const payload = {
|
|
7244
|
+
guildId: data.guild_id,
|
|
7245
|
+
channelId: data.channel_id,
|
|
7246
|
+
threads: (data.threads ?? []).map((entry) => ({
|
|
7247
|
+
threadId: entry.thread_id,
|
|
7248
|
+
count: entry.count ?? null,
|
|
7249
|
+
missing: entry.missing === true
|
|
7250
|
+
}))
|
|
7251
|
+
};
|
|
7252
|
+
client.emit(Events.ForumUnreads, payload);
|
|
7253
|
+
}
|
|
7254
|
+
};
|
|
7255
|
+
|
|
6346
7256
|
// src/ClientCore/EventHandlers/index.ts
|
|
6347
7257
|
var eventHandlers = buildRegistry(
|
|
6348
7258
|
messageHandlers,
|
|
@@ -6351,7 +7261,8 @@ var eventHandlers = buildRegistry(
|
|
|
6351
7261
|
memberHandlers,
|
|
6352
7262
|
inviteHandlers,
|
|
6353
7263
|
guildResourceHandlers,
|
|
6354
|
-
passthroughHandlers
|
|
7264
|
+
passthroughHandlers,
|
|
7265
|
+
threadHandlers
|
|
6355
7266
|
);
|
|
6356
7267
|
|
|
6357
7268
|
// src/ClientCore/GatewayDispatch.ts
|
|
@@ -6577,7 +7488,7 @@ async function connectClientGateway(client, token, signal) {
|
|
|
6577
7488
|
|
|
6578
7489
|
// src/ClientCore/GuildManager.ts
|
|
6579
7490
|
import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
|
|
6580
|
-
import { Routes as
|
|
7491
|
+
import { Routes as Routes35 } from "@fluxerjs/types";
|
|
6581
7492
|
var GuildManager = class extends LimitedCollection5 {
|
|
6582
7493
|
constructor(client) {
|
|
6583
7494
|
super({
|
|
@@ -6616,7 +7527,7 @@ var GuildManager = class extends LimitedCollection5 {
|
|
|
6616
7527
|
const cached = this.get(guildId);
|
|
6617
7528
|
if (cached && !options?.force) return cached;
|
|
6618
7529
|
try {
|
|
6619
|
-
const data = await this.client.rest.get(
|
|
7530
|
+
const data = await this.client.rest.get(Routes35.guild(guildId));
|
|
6620
7531
|
if (cached) {
|
|
6621
7532
|
cached._patch(data);
|
|
6622
7533
|
return cached;
|
|
@@ -6704,7 +7615,7 @@ var MessageCache = class {
|
|
|
6704
7615
|
// src/ClientCore/UserManager.ts
|
|
6705
7616
|
import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
|
|
6706
7617
|
import {
|
|
6707
|
-
Routes as
|
|
7618
|
+
Routes as Routes36
|
|
6708
7619
|
} from "@fluxerjs/types";
|
|
6709
7620
|
var soft = (p) => p.catch(() => null);
|
|
6710
7621
|
var UserManager = class extends LimitedCollection6 {
|
|
@@ -6729,7 +7640,7 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
6729
7640
|
async fetch(userId, options) {
|
|
6730
7641
|
const cached = this.get(userId);
|
|
6731
7642
|
if (cached && !options?.force) return cached;
|
|
6732
|
-
const data = await this.client.rest.get(
|
|
7643
|
+
const data = await this.client.rest.get(Routes36.user(userId));
|
|
6733
7644
|
return this.client.getOrCreateUser(data);
|
|
6734
7645
|
}
|
|
6735
7646
|
/** Return a cached user, otherwise {@link fetch}. */
|
|
@@ -6747,10 +7658,10 @@ var UserManager = class extends LimitedCollection6 {
|
|
|
6747
7658
|
async fetchWithProfile(userId, options) {
|
|
6748
7659
|
const guildId = options?.guildId ?? void 0;
|
|
6749
7660
|
const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
|
|
6750
|
-
this.client.rest.get(
|
|
6751
|
-
soft(this.client.rest.get(
|
|
6752
|
-
guildId ? soft(this.client.rest.get(
|
|
6753
|
-
guildId ? soft(this.client.rest.get(
|
|
7661
|
+
this.client.rest.get(Routes36.user(userId)),
|
|
7662
|
+
soft(this.client.rest.get(Routes36.userProfile(userId))),
|
|
7663
|
+
guildId ? soft(this.client.rest.get(Routes36.userProfile(userId, guildId))) : null,
|
|
7664
|
+
guildId ? soft(this.client.rest.get(Routes36.guildMember(guildId, userId))) : null
|
|
6754
7665
|
]);
|
|
6755
7666
|
const user = this.client.getOrCreateUser(userData);
|
|
6756
7667
|
let member = null;
|
|
@@ -7129,6 +8040,72 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7129
8040
|
if (options.nonce !== void 0) data.nonce = options.nonce;
|
|
7130
8041
|
this._sendToAllShards({ op: GatewayOpcodes2.RequestChannelMemberCounts, d: data });
|
|
7131
8042
|
}
|
|
8043
|
+
/**
|
|
8044
|
+
* Request unread counts for posts in one forum or media channel (opcode 28).
|
|
8045
|
+
* Listen for `forumUnreads`. The gateway keeps at most 40 posts and ignores a channel the session cannot view.
|
|
8046
|
+
*/
|
|
8047
|
+
requestForumUnreads(options) {
|
|
8048
|
+
if (!options.guildId || !options.channelId) {
|
|
8049
|
+
throw new FluxerError("requestForumUnreads requires guildId and channelId", {
|
|
8050
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8051
|
+
});
|
|
8052
|
+
}
|
|
8053
|
+
const threads = [];
|
|
8054
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8055
|
+
for (const thread of options.threads) {
|
|
8056
|
+
if (!thread.threadId || seen.has(thread.threadId)) continue;
|
|
8057
|
+
seen.add(thread.threadId);
|
|
8058
|
+
const entry = { thread_id: thread.threadId };
|
|
8059
|
+
if (thread.ackMessageId !== void 0) entry.ack_message_id = thread.ackMessageId;
|
|
8060
|
+
threads.push(entry);
|
|
8061
|
+
}
|
|
8062
|
+
if (!threads.length) {
|
|
8063
|
+
throw new FluxerError("requestForumUnreads requires at least one thread", {
|
|
8064
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8065
|
+
});
|
|
8066
|
+
}
|
|
8067
|
+
if (threads.length > 40) {
|
|
8068
|
+
throw new FluxerError("requestForumUnreads accepts at most 40 threads", {
|
|
8069
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8070
|
+
});
|
|
8071
|
+
}
|
|
8072
|
+
const data = {
|
|
8073
|
+
guild_id: options.guildId,
|
|
8074
|
+
channel_id: options.channelId,
|
|
8075
|
+
threads
|
|
8076
|
+
};
|
|
8077
|
+
this._sendToAllShards({ op: GatewayOpcodes2.RequestForumUnreads, d: data });
|
|
8078
|
+
}
|
|
8079
|
+
/**
|
|
8080
|
+
* Subscribe to thread traffic in a guild (opcode 14).
|
|
8081
|
+
* `threads: true` receives every thread event in the guild.
|
|
8082
|
+
* `threadIds` (at most 10) subscribes to those member lists. Each one arrives as `threadMemberListUpdate`.
|
|
8083
|
+
*/
|
|
8084
|
+
subscribeThreads(options) {
|
|
8085
|
+
if (!options.guildId) {
|
|
8086
|
+
throw new FluxerError("subscribeThreads requires guildId", {
|
|
8087
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8088
|
+
});
|
|
8089
|
+
}
|
|
8090
|
+
if (options.threads === void 0 && options.threadIds === void 0) {
|
|
8091
|
+
throw new FluxerError("subscribeThreads requires threads or threadIds", {
|
|
8092
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8093
|
+
});
|
|
8094
|
+
}
|
|
8095
|
+
const subscription = {};
|
|
8096
|
+
if (options.threads !== void 0) subscription.threads = options.threads;
|
|
8097
|
+
if (options.threadIds !== void 0) {
|
|
8098
|
+
const threadIds = [...new Set(options.threadIds.filter(Boolean))];
|
|
8099
|
+
if (threadIds.length > 10) {
|
|
8100
|
+
throw new FluxerError("subscribeThreads accepts at most 10 threadIds", {
|
|
8101
|
+
code: ErrorCodes.InvalidGatewayRequest
|
|
8102
|
+
});
|
|
8103
|
+
}
|
|
8104
|
+
subscription.thread_member_lists = threadIds;
|
|
8105
|
+
}
|
|
8106
|
+
const data = { subscriptions: { [options.guildId]: subscription } };
|
|
8107
|
+
this._sendToAllShards({ op: GatewayOpcodes2.LazyRequest, d: data });
|
|
8108
|
+
}
|
|
7132
8109
|
/**
|
|
7133
8110
|
* Broadcast a gateway payload to all shards.
|
|
7134
8111
|
* @param payload - Gateway send payload
|
|
@@ -7232,7 +8209,7 @@ var Client = class _Client extends EventEmitter3 {
|
|
|
7232
8209
|
* @see {@link Routes}
|
|
7233
8210
|
*/
|
|
7234
8211
|
static get Routes() {
|
|
7235
|
-
return
|
|
8212
|
+
return Routes37;
|
|
7236
8213
|
}
|
|
7237
8214
|
};
|
|
7238
8215
|
export {
|