@fluxerjs/core 2.1.0 → 3.0.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/README.md +32 -7
- package/dist/Expressions-Bdgo72qI.d.mts +34 -0
- package/dist/Expressions-Bdgo72qI.d.ts +34 -0
- package/dist/{subpath-message-CWiBEUUV.d.mts → SubpathMessage-CjQBbVmb.d.mts} +2236 -1713
- package/dist/{subpath-message-CWiBEUUV.d.ts → SubpathMessage-DNlKq2Nj.d.ts} +2236 -1713
- package/dist/Sudo-CFfbmis3.d.mts +453 -0
- package/dist/Sudo-CFfbmis3.d.ts +453 -0
- package/dist/client.d.mts +5 -4
- package/dist/client.d.ts +5 -4
- package/dist/client.js +4500 -2940
- package/dist/client.mjs +4355 -2793
- package/dist/cluster.d.mts +5 -4
- package/dist/cluster.d.ts +5 -4
- package/dist/cluster.js +4435 -2875
- package/dist/cluster.mjs +4200 -2638
- package/dist/errors.js +8 -8
- package/dist/errors.mjs +4 -4
- package/dist/index.d.mts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +5739 -4201
- package/dist/index.mjs +5379 -3820
- package/dist/internal.d.mts +12 -0
- package/dist/internal.d.ts +12 -0
- package/dist/internal.js +449 -0
- package/dist/internal.mjs +398 -0
- package/dist/message.d.mts +5 -4
- package/dist/message.d.ts +5 -4
- package/dist/message.js +533 -87
- package/dist/message.mjs +510 -65
- package/package.json +14 -9
package/dist/message.js
CHANGED
|
@@ -17,19 +17,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
Message: () => Message
|
|
20
|
+
// src/SubpathMessage.ts
|
|
21
|
+
var SubpathMessage_exports = {};
|
|
22
|
+
__export(SubpathMessage_exports, {
|
|
23
|
+
Message: () => Message,
|
|
24
|
+
PartialMessage: () => PartialMessage
|
|
24
25
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(SubpathMessage_exports);
|
|
26
27
|
|
|
27
|
-
// src/
|
|
28
|
-
var import_collection2 = require("@fluxerjs/collection");
|
|
28
|
+
// src/Domain/Message/Message.ts
|
|
29
29
|
var import_builders3 = require("@fluxerjs/builders");
|
|
30
|
-
var
|
|
30
|
+
var import_collection3 = require("@fluxerjs/collection");
|
|
31
|
+
var import_types5 = require("@fluxerjs/types");
|
|
32
|
+
var import_util4 = require("@fluxerjs/util");
|
|
31
33
|
|
|
32
|
-
// src/
|
|
34
|
+
// src/ClientCore/SdkOptions/Attachments.ts
|
|
33
35
|
function toMessageAttachmentEditWire(attachments) {
|
|
34
36
|
return attachments.map((a) => {
|
|
35
37
|
const out = { id: a.id };
|
|
@@ -44,13 +46,17 @@ function toMessageAttachmentEditWire(attachments) {
|
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
// src/
|
|
49
|
+
// src/Helpers/MessageUtils/Body.ts
|
|
50
|
+
var import_builders = require("@fluxerjs/builders");
|
|
51
|
+
var import_types = require("@fluxerjs/types");
|
|
52
|
+
|
|
53
|
+
// src/LibErrors/ErrorCodes.ts
|
|
48
54
|
var import_util = require("@fluxerjs/util");
|
|
49
55
|
|
|
50
|
-
// src/
|
|
56
|
+
// src/LibErrors/FluxerError.ts
|
|
51
57
|
var import_util2 = require("@fluxerjs/util");
|
|
52
58
|
|
|
53
|
-
// src/
|
|
59
|
+
// src/Helpers/MessageUtils/Files.ts
|
|
54
60
|
var FILE_FETCH_TIMEOUT_MS = 3e4;
|
|
55
61
|
async function fetchFileBuffer(url, index) {
|
|
56
62
|
if (!URL.canParse(url)) {
|
|
@@ -93,9 +99,7 @@ async function resolveMessageFiles(files) {
|
|
|
93
99
|
return result;
|
|
94
100
|
}
|
|
95
101
|
|
|
96
|
-
// src/
|
|
97
|
-
var import_types = require("@fluxerjs/types");
|
|
98
|
-
var import_builders = require("@fluxerjs/builders");
|
|
102
|
+
// src/Helpers/MessageUtils/Body.ts
|
|
99
103
|
function toAPIAllowedMentions(options) {
|
|
100
104
|
const result = {};
|
|
101
105
|
if (options.parse !== void 0) result.parse = options.parse;
|
|
@@ -113,6 +117,37 @@ function applyReplyPingSuppression(body) {
|
|
|
113
117
|
function assignIfDefined(target, key, value) {
|
|
114
118
|
if (value !== void 0) target[key] = value;
|
|
115
119
|
}
|
|
120
|
+
function normalizeSendFiles(files) {
|
|
121
|
+
if (!files?.length) return void 0;
|
|
122
|
+
const normalized = [];
|
|
123
|
+
const metaFromBuilders = [];
|
|
124
|
+
let anyBuilderMeta = false;
|
|
125
|
+
for (let i = 0; i < files.length; i++) {
|
|
126
|
+
const file = files[i];
|
|
127
|
+
if (!file) continue;
|
|
128
|
+
if (file instanceof import_builders.AttachmentBuilder) {
|
|
129
|
+
normalized.push(file.toFileData());
|
|
130
|
+
const meta = {
|
|
131
|
+
id: i,
|
|
132
|
+
filename: file.filename,
|
|
133
|
+
...file.description != null ? { description: file.description } : {},
|
|
134
|
+
...file.spoiler ? { flags: import_types.MessageAttachmentFlags.IS_SPOILER } : {}
|
|
135
|
+
};
|
|
136
|
+
if (file.description != null || file.spoiler) anyBuilderMeta = true;
|
|
137
|
+
metaFromBuilders.push(meta);
|
|
138
|
+
} else {
|
|
139
|
+
normalized.push(file);
|
|
140
|
+
metaFromBuilders.push({
|
|
141
|
+
id: i,
|
|
142
|
+
filename: file.filename ?? file.name
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
files: normalized,
|
|
148
|
+
metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
|
|
149
|
+
};
|
|
150
|
+
}
|
|
116
151
|
function buildSendBody(options) {
|
|
117
152
|
const body = typeof options === "string" ? { content: options } : options;
|
|
118
153
|
const result = {};
|
|
@@ -120,16 +155,17 @@ function buildSendBody(options) {
|
|
|
120
155
|
if (body.embeds?.length) {
|
|
121
156
|
result.embeds = body.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
|
|
122
157
|
}
|
|
158
|
+
const normalizedFiles = normalizeSendFiles(body.files);
|
|
123
159
|
if (body.uploadedAttachments?.length) {
|
|
124
160
|
result.attachments = body.uploadedAttachments;
|
|
125
|
-
} else if (
|
|
161
|
+
} else if (normalizedFiles?.files.length) {
|
|
126
162
|
result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
|
|
127
163
|
id: a.id,
|
|
128
164
|
filename: a.filename,
|
|
129
165
|
...a.title != null && { title: a.title },
|
|
130
166
|
...a.description != null && { description: a.description },
|
|
131
167
|
...a.flags != null && { flags: a.flags }
|
|
132
|
-
})) :
|
|
168
|
+
})) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
|
|
133
169
|
}
|
|
134
170
|
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
135
171
|
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
@@ -223,32 +259,66 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
223
259
|
} else if (allowedMentions?.repliedUser === false) {
|
|
224
260
|
applyReplyPingSuppression(body);
|
|
225
261
|
}
|
|
262
|
+
const resolvedFiles = normalizeSendFiles(files);
|
|
226
263
|
return {
|
|
227
264
|
body,
|
|
228
|
-
files: !uploadedAttachments?.length && files
|
|
265
|
+
files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
|
|
229
266
|
};
|
|
230
267
|
}
|
|
231
268
|
|
|
232
|
-
// src/
|
|
233
|
-
var
|
|
269
|
+
// src/Helpers/ReactionCollector.ts
|
|
270
|
+
var import_node_events = require("events");
|
|
234
271
|
var import_collection = require("@fluxerjs/collection");
|
|
235
272
|
|
|
236
|
-
// src/
|
|
237
|
-
var
|
|
273
|
+
// src/Domain/Message/MessageReaction.ts
|
|
274
|
+
var import_types2 = require("@fluxerjs/types");
|
|
275
|
+
|
|
276
|
+
// src/Helpers/HttpErrors.ts
|
|
238
277
|
var import_rest = require("@fluxerjs/rest");
|
|
278
|
+
function httpStatus(err) {
|
|
279
|
+
if (err instanceof import_rest.FluxerAPIError) return err.statusCode;
|
|
280
|
+
if (typeof err === "object" && err !== null && "statusCode" in err) {
|
|
281
|
+
const code = err.statusCode;
|
|
282
|
+
return typeof code === "number" ? code : void 0;
|
|
283
|
+
}
|
|
284
|
+
return void 0;
|
|
285
|
+
}
|
|
286
|
+
function errorMessage(err, fallback) {
|
|
287
|
+
if (err instanceof Error && err.message) return err.message;
|
|
288
|
+
if (typeof err === "string" && err.length > 0) return err;
|
|
289
|
+
return fallback;
|
|
290
|
+
}
|
|
291
|
+
function rethrowMapped(err, options) {
|
|
292
|
+
if (err instanceof import_rest.RateLimitError) throw err;
|
|
293
|
+
if (err instanceof import_util2.FluxerError) throw err;
|
|
294
|
+
if (options.notFound && httpStatus(err) === 404) {
|
|
295
|
+
throw new import_util2.FluxerError(options.notFound.message, {
|
|
296
|
+
code: options.notFound.code,
|
|
297
|
+
cause: err
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
throw new import_util2.FluxerError(errorMessage(err, options.fallback), {
|
|
301
|
+
code: options.code,
|
|
302
|
+
cause: err
|
|
303
|
+
});
|
|
304
|
+
}
|
|
239
305
|
|
|
240
|
-
// src/
|
|
306
|
+
// src/Domain/Base.ts
|
|
241
307
|
var Base = class {
|
|
242
308
|
};
|
|
243
309
|
|
|
244
|
-
// src/
|
|
245
|
-
var MessageReaction = class extends Base {
|
|
310
|
+
// src/Domain/Message/MessageReaction.ts
|
|
311
|
+
var MessageReaction = class _MessageReaction extends Base {
|
|
246
312
|
client;
|
|
247
313
|
messageId;
|
|
248
314
|
channelId;
|
|
249
315
|
guildId;
|
|
250
316
|
emoji;
|
|
251
|
-
/**
|
|
317
|
+
/** Total count when hydrated from a message payload; `1` for gateway add events. */
|
|
318
|
+
count;
|
|
319
|
+
/** Whether the current user reacted (message payload); false for gateway remove. */
|
|
320
|
+
me;
|
|
321
|
+
/** Raw gateway payload for low-level access (null when built from a message aggregate). */
|
|
252
322
|
_data;
|
|
253
323
|
constructor(client, data) {
|
|
254
324
|
super();
|
|
@@ -262,40 +332,70 @@ var MessageReaction = class extends Base {
|
|
|
262
332
|
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
263
333
|
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
264
334
|
};
|
|
335
|
+
this.count = 1;
|
|
336
|
+
this.me = false;
|
|
337
|
+
}
|
|
338
|
+
/** Build a reaction aggregate from a message's `reactions` array entry. */
|
|
339
|
+
static fromMessage(message, data) {
|
|
340
|
+
const reaction = new _MessageReaction(message.client, {
|
|
341
|
+
user_id: message.client.user?.id ?? "0",
|
|
342
|
+
message_id: message.id,
|
|
343
|
+
channel_id: message.channelId,
|
|
344
|
+
guild_id: message.guildId ?? void 0,
|
|
345
|
+
emoji: {
|
|
346
|
+
name: data.emoji.name,
|
|
347
|
+
id: data.emoji.id ?? void 0,
|
|
348
|
+
animated: data.emoji.animated ?? void 0
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
Object.defineProperty(reaction, "_data", { value: null });
|
|
352
|
+
reaction.count = data.count;
|
|
353
|
+
reaction.me = data.me ?? false;
|
|
354
|
+
return reaction;
|
|
265
355
|
}
|
|
266
|
-
/** Emoji as a string: unicode or
|
|
356
|
+
/** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
|
|
267
357
|
get emojiIdentifier() {
|
|
268
|
-
return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
358
|
+
return this.emoji.id ? this.emoji.animated ? `a:${this.emoji.name}:${this.emoji.id}` : `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
269
359
|
}
|
|
270
360
|
/** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
|
|
271
361
|
get guild() {
|
|
272
362
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
273
363
|
}
|
|
364
|
+
/** Cached message this reaction belongs to, or null if the message was not cached. */
|
|
365
|
+
get message() {
|
|
366
|
+
const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
|
|
367
|
+
return cached ? new Message(this.client, cached) : null;
|
|
368
|
+
}
|
|
369
|
+
/** Cached text-capable channel, or null if uncached / not text-based. */
|
|
370
|
+
get channel() {
|
|
371
|
+
const channel = this.client.channels.get(this.channelId);
|
|
372
|
+
return channel?.isTextBased() ? channel : null;
|
|
373
|
+
}
|
|
274
374
|
/**
|
|
275
|
-
* Fetch the message this reaction belongs to.
|
|
276
|
-
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
375
|
+
* Fetch the message this reaction belongs to (cache first, then REST).
|
|
277
376
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
278
377
|
*/
|
|
279
378
|
async fetchMessage() {
|
|
379
|
+
const cached = this.message;
|
|
380
|
+
if (cached) return cached;
|
|
280
381
|
try {
|
|
281
382
|
const data = await this.client.rest.get(
|
|
282
|
-
|
|
383
|
+
import_types2.Routes.channelMessage(this.channelId, this.messageId)
|
|
283
384
|
);
|
|
284
385
|
return new Message(this.client, data);
|
|
285
386
|
} catch (err) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
throw new import_util2.FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
387
|
+
rethrowMapped(err, {
|
|
388
|
+
notFound: {
|
|
289
389
|
code: import_util.ErrorCodes.MessageNotFound,
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
390
|
+
message: `Message ${this.messageId} not found in channel ${this.channelId}`
|
|
391
|
+
},
|
|
392
|
+
fallback: `Failed to fetch message ${this.messageId}`
|
|
393
|
+
});
|
|
294
394
|
}
|
|
295
395
|
}
|
|
296
396
|
};
|
|
297
397
|
|
|
298
|
-
// src/
|
|
398
|
+
// src/Helpers/Events.ts
|
|
299
399
|
var Events = {
|
|
300
400
|
Ready: "ready",
|
|
301
401
|
MessageCreate: "messageCreate",
|
|
@@ -330,6 +430,8 @@ var Events = {
|
|
|
330
430
|
ChannelUpdate: "channelUpdate",
|
|
331
431
|
ChannelDelete: "channelDelete",
|
|
332
432
|
ChannelPinsUpdate: "channelPinsUpdate",
|
|
433
|
+
ChannelRecipientAdd: "channelRecipientAdd",
|
|
434
|
+
ChannelRecipientRemove: "channelRecipientRemove",
|
|
333
435
|
InviteCreate: "inviteCreate",
|
|
334
436
|
InviteDelete: "inviteDelete",
|
|
335
437
|
TypingStart: "typingStart",
|
|
@@ -346,11 +448,17 @@ var Events = {
|
|
|
346
448
|
WebhooksUpdate: "webhooksUpdate",
|
|
347
449
|
Resumed: "resumed",
|
|
348
450
|
Error: "error",
|
|
349
|
-
Debug: "debug"
|
|
451
|
+
Debug: "debug",
|
|
452
|
+
ShardReady: "shardReady",
|
|
453
|
+
ShardResumed: "shardResumed",
|
|
454
|
+
ShardDisconnect: "shardDisconnect",
|
|
455
|
+
ShardReconnecting: "shardReconnecting",
|
|
456
|
+
ShardError: "shardError",
|
|
457
|
+
ShardingRequired: "shardingRequired"
|
|
350
458
|
};
|
|
351
459
|
|
|
352
|
-
// src/
|
|
353
|
-
var ReactionCollector = class extends
|
|
460
|
+
// src/Helpers/ReactionCollector.ts
|
|
461
|
+
var ReactionCollector = class _ReactionCollector extends import_node_events.EventEmitter {
|
|
354
462
|
client;
|
|
355
463
|
messageId;
|
|
356
464
|
channelId;
|
|
@@ -393,11 +501,17 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
393
501
|
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
394
502
|
}
|
|
395
503
|
});
|
|
396
|
-
const
|
|
504
|
+
const cached = this.client.users.get(entry.userId);
|
|
505
|
+
const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
|
|
506
|
+
{
|
|
397
507
|
id: entry.userId,
|
|
398
508
|
username: "Unknown",
|
|
399
|
-
discriminator: "0"
|
|
400
|
-
|
|
509
|
+
discriminator: "0",
|
|
510
|
+
globalName: null,
|
|
511
|
+
avatar: null,
|
|
512
|
+
bot: false,
|
|
513
|
+
system: false
|
|
514
|
+
};
|
|
401
515
|
this._collect(reaction, user, entry.userId);
|
|
402
516
|
}
|
|
403
517
|
};
|
|
@@ -411,6 +525,7 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
411
525
|
if (this._ended) return;
|
|
412
526
|
if (!this.options.filter(reaction, user)) return;
|
|
413
527
|
const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
|
|
528
|
+
if (this.collected.has(key)) return;
|
|
414
529
|
this.collected.set(key, { reaction, user });
|
|
415
530
|
this.emit("collect", reaction, user);
|
|
416
531
|
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
@@ -428,6 +543,21 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
428
543
|
}
|
|
429
544
|
this.emit("end", this.collected, reason);
|
|
430
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* One-shot helper used by {@link Message.awaitReactions}.
|
|
548
|
+
* Resolves with the collected reactions when the collector ends.
|
|
549
|
+
* Rejects if `options.errors` includes the end reason.
|
|
550
|
+
*/
|
|
551
|
+
static awaitReactions(client, messageId, channelId, options) {
|
|
552
|
+
const errors = options?.errors ?? [];
|
|
553
|
+
return new Promise((resolve, reject) => {
|
|
554
|
+
const collector = new _ReactionCollector(client, messageId, channelId, options);
|
|
555
|
+
collector.on("end", (collected, reason) => {
|
|
556
|
+
if (errors.includes(reason)) reject(collected);
|
|
557
|
+
else resolve(collected);
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
}
|
|
431
561
|
on(event, listener) {
|
|
432
562
|
return super.on(event, listener);
|
|
433
563
|
}
|
|
@@ -436,26 +566,187 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
436
566
|
}
|
|
437
567
|
};
|
|
438
568
|
|
|
439
|
-
// src/
|
|
440
|
-
|
|
569
|
+
// src/Domain/Message/Attachment.ts
|
|
570
|
+
function toMessageAttachment(data) {
|
|
571
|
+
return {
|
|
572
|
+
id: data.id,
|
|
573
|
+
filename: data.filename,
|
|
574
|
+
title: data.title ?? null,
|
|
575
|
+
description: data.description ?? null,
|
|
576
|
+
contentType: data.content_type ?? null,
|
|
577
|
+
contentHash: data.content_hash ?? null,
|
|
578
|
+
size: data.size,
|
|
579
|
+
url: data.url ?? null,
|
|
580
|
+
proxyUrl: data.proxy_url ?? null,
|
|
581
|
+
width: data.width ?? null,
|
|
582
|
+
height: data.height ?? null,
|
|
583
|
+
placeholder: data.placeholder ?? null,
|
|
584
|
+
flags: data.flags ?? 0,
|
|
585
|
+
nsfw: data.nsfw ?? false,
|
|
586
|
+
duration: data.duration ?? null,
|
|
587
|
+
waveform: data.waveform ?? null,
|
|
588
|
+
expiresAt: data.expires_at ? new Date(data.expires_at) : null,
|
|
589
|
+
expired: data.expired ?? false
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/Domain/Message/Embed.ts
|
|
594
|
+
function toMessageEmbedAuthor(data) {
|
|
595
|
+
return {
|
|
596
|
+
name: data.name ?? null,
|
|
597
|
+
url: data.url ?? null,
|
|
598
|
+
iconUrl: data.icon_url ?? null,
|
|
599
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
function toMessageEmbedFooter(data) {
|
|
603
|
+
return {
|
|
604
|
+
text: data.text,
|
|
605
|
+
iconUrl: data.icon_url ?? null,
|
|
606
|
+
proxyIconUrl: data.proxy_icon_url ?? null
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
function toMessageEmbedMedia(data) {
|
|
610
|
+
return {
|
|
611
|
+
url: data.url,
|
|
612
|
+
proxyUrl: data.proxy_url ?? null,
|
|
613
|
+
contentType: data.content_type ?? null,
|
|
614
|
+
contentHash: data.content_hash ?? null,
|
|
615
|
+
width: data.width ?? null,
|
|
616
|
+
height: data.height ?? null,
|
|
617
|
+
description: data.description ?? null,
|
|
618
|
+
placeholder: data.placeholder ?? null,
|
|
619
|
+
duration: data.duration ?? null,
|
|
620
|
+
flags: data.flags ?? null
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function toMessageEmbed(data) {
|
|
624
|
+
const full = data;
|
|
625
|
+
return {
|
|
626
|
+
type: data.type ?? "rich",
|
|
627
|
+
url: data.url ?? null,
|
|
628
|
+
title: data.title ?? null,
|
|
629
|
+
color: data.color ?? null,
|
|
630
|
+
timestamp: data.timestamp ? new Date(data.timestamp) : null,
|
|
631
|
+
description: data.description ?? null,
|
|
632
|
+
author: data.author ? toMessageEmbedAuthor(data.author) : null,
|
|
633
|
+
image: data.image ? toMessageEmbedMedia(data.image) : null,
|
|
634
|
+
thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
|
|
635
|
+
footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
|
|
636
|
+
fields: (data.fields ?? []).map((f) => ({
|
|
637
|
+
name: f.name,
|
|
638
|
+
value: f.value,
|
|
639
|
+
inline: f.inline ?? false
|
|
640
|
+
})),
|
|
641
|
+
provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
|
|
642
|
+
video: data.video ? toMessageEmbedMedia(data.video) : null,
|
|
643
|
+
audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
|
|
644
|
+
nsfw: data.nsfw ?? false,
|
|
645
|
+
children: (full.children ?? []).map(toMessageEmbed),
|
|
646
|
+
html: full.html ?? null,
|
|
647
|
+
htmlWidth: full.html_width ?? null,
|
|
648
|
+
htmlHeight: full.html_height ?? null
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// src/Domain/Message/MessageReactionManager.ts
|
|
653
|
+
var import_collection2 = require("@fluxerjs/collection");
|
|
654
|
+
var MessageReactionManager = class {
|
|
655
|
+
constructor(message) {
|
|
656
|
+
this.message = message;
|
|
657
|
+
}
|
|
658
|
+
_cache = new import_collection2.Collection();
|
|
659
|
+
/** Reactions keyed by unicode name or `name:id`. */
|
|
660
|
+
get cache() {
|
|
661
|
+
return this._cache;
|
|
662
|
+
}
|
|
663
|
+
get size() {
|
|
664
|
+
return this._cache.size;
|
|
665
|
+
}
|
|
666
|
+
[Symbol.iterator]() {
|
|
667
|
+
return this._cache.values();
|
|
668
|
+
}
|
|
669
|
+
/** @internal Sync from an API message payload. */
|
|
670
|
+
_patch(reactions) {
|
|
671
|
+
this._cache.clear();
|
|
672
|
+
for (const data of reactions ?? []) {
|
|
673
|
+
const reaction = MessageReaction.fromMessage(this.message, data);
|
|
674
|
+
this._cache.set(reaction.emojiIdentifier, reaction);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
// src/Domain/Message/MessageSticker.ts
|
|
680
|
+
var import_util3 = require("@fluxerjs/util");
|
|
681
|
+
|
|
682
|
+
// src/Helpers/Constants.ts
|
|
683
|
+
var import_rest2 = require("@fluxerjs/rest");
|
|
684
|
+
var CDN_URL = "https://fluxerusercontent.com";
|
|
685
|
+
|
|
686
|
+
// src/Helpers/Cdn.ts
|
|
687
|
+
function mediaBase(options) {
|
|
688
|
+
return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
|
|
689
|
+
}
|
|
690
|
+
function cdnStickerURL(stickerId, animated, options) {
|
|
691
|
+
const ext = animated ? "gif" : "png";
|
|
692
|
+
return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// src/Domain/Message/MessageSticker.ts
|
|
696
|
+
var MessageSticker = class extends Base {
|
|
697
|
+
client;
|
|
698
|
+
id;
|
|
699
|
+
name;
|
|
700
|
+
description;
|
|
701
|
+
tags;
|
|
702
|
+
animated;
|
|
703
|
+
constructor(client, data) {
|
|
704
|
+
super();
|
|
705
|
+
this.client = client;
|
|
706
|
+
this.id = data.id;
|
|
707
|
+
this.name = data.name;
|
|
708
|
+
this.description = data.description ?? "";
|
|
709
|
+
this.tags = data.tags ?? [];
|
|
710
|
+
this.animated = data.animated ?? false;
|
|
711
|
+
}
|
|
712
|
+
/** CDN URL for this sticker image. */
|
|
713
|
+
get url() {
|
|
714
|
+
return cdnStickerURL(this.id, this.animated, {
|
|
715
|
+
mediaBase: this.client.instance.endpoints.media
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
/** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
|
|
719
|
+
get createdTimestamp() {
|
|
720
|
+
return import_util3.SnowflakeUtil.timestampFromSnowflake(this.id);
|
|
721
|
+
}
|
|
722
|
+
/** Date when this sticker was created, derived from its snowflake ID. */
|
|
723
|
+
get createdAt() {
|
|
724
|
+
return import_util3.SnowflakeUtil.dateFromSnowflake(this.id);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
// src/Domain/Message/Reactions.ts
|
|
729
|
+
var import_types3 = require("@fluxerjs/types");
|
|
441
730
|
async function emojiPath(message, emoji) {
|
|
442
731
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
443
732
|
}
|
|
444
733
|
async function reactToMessage(message, emoji) {
|
|
445
|
-
const
|
|
446
|
-
await message.client.rest.put(
|
|
734
|
+
const wire = await emojiPath(message, emoji);
|
|
735
|
+
await message.client.rest.put(
|
|
736
|
+
import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
|
|
737
|
+
);
|
|
447
738
|
}
|
|
448
739
|
async function removeMessageReaction(message, emoji, userId) {
|
|
449
740
|
const e = await emojiPath(message, emoji);
|
|
450
|
-
const route = userId ?
|
|
741
|
+
const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
|
|
451
742
|
await message.client.rest.delete(route);
|
|
452
743
|
}
|
|
453
744
|
async function removeAllMessageReactions(message) {
|
|
454
|
-
await message.client.rest.delete(
|
|
745
|
+
await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
|
|
455
746
|
}
|
|
456
747
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
457
748
|
const e = await emojiPath(message, emoji);
|
|
458
|
-
await message.client.rest.delete(
|
|
749
|
+
await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
|
|
459
750
|
}
|
|
460
751
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
461
752
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -466,7 +757,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
466
757
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
467
758
|
if (options?.after) params.set("after", options.after);
|
|
468
759
|
const qs = params.toString();
|
|
469
|
-
const route =
|
|
760
|
+
const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
|
|
470
761
|
const data = await message.client.rest.get(route);
|
|
471
762
|
if (Array.isArray(data)) {
|
|
472
763
|
return {
|
|
@@ -483,9 +774,9 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
483
774
|
};
|
|
484
775
|
}
|
|
485
776
|
|
|
486
|
-
// src/
|
|
777
|
+
// src/Domain/Message/Send.ts
|
|
487
778
|
var import_builders2 = require("@fluxerjs/builders");
|
|
488
|
-
var
|
|
779
|
+
var import_types4 = require("@fluxerjs/types");
|
|
489
780
|
function toReplyTarget(ref) {
|
|
490
781
|
return {
|
|
491
782
|
channelId: ref.channel_id,
|
|
@@ -519,7 +810,7 @@ function asReplyTarget(value) {
|
|
|
519
810
|
}
|
|
520
811
|
async function sendPrepared(message, payload) {
|
|
521
812
|
const data = await message.client.rest.post(
|
|
522
|
-
|
|
813
|
+
import_types4.Routes.channelMessages(message.channelId),
|
|
523
814
|
payload
|
|
524
815
|
);
|
|
525
816
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -548,8 +839,34 @@ async function replyToMessage(message, options, replyOptions) {
|
|
|
548
839
|
);
|
|
549
840
|
}
|
|
550
841
|
|
|
551
|
-
// src/
|
|
842
|
+
// src/Domain/Message/Message.ts
|
|
843
|
+
function toMessageCall(data) {
|
|
844
|
+
return {
|
|
845
|
+
participants: data.participants,
|
|
846
|
+
endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function toMessageSnapshot(client, data) {
|
|
850
|
+
return {
|
|
851
|
+
content: data.content ?? null,
|
|
852
|
+
createdAt: new Date(data.timestamp),
|
|
853
|
+
editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
|
|
854
|
+
mentionUserIds: data.mentions ?? [],
|
|
855
|
+
mentionRoles: data.mention_roles ?? [],
|
|
856
|
+
embeds: (data.embeds ?? []).map(toMessageEmbed),
|
|
857
|
+
attachments: (data.attachments ?? []).map(toMessageAttachment),
|
|
858
|
+
stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
|
|
859
|
+
...data.type !== void 0 ? { type: data.type } : {}
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
function resolveMessageFlags(flags) {
|
|
863
|
+
if (flags === void 0) return void 0;
|
|
864
|
+
if (typeof flags === "number") return flags;
|
|
865
|
+
return Number(import_util4.MessageFlagsBitField.resolve(flags));
|
|
866
|
+
}
|
|
552
867
|
var Message = class _Message extends Base {
|
|
868
|
+
/** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
|
|
869
|
+
partial = false;
|
|
553
870
|
/** The {@link Client} that instantiated this message. */
|
|
554
871
|
client;
|
|
555
872
|
/** Snowflake ID of this message. */
|
|
@@ -578,7 +895,7 @@ var Message = class _Message extends Base {
|
|
|
578
895
|
mentionEveryone;
|
|
579
896
|
/** Whether this is a text-to-speech message. */
|
|
580
897
|
tts;
|
|
581
|
-
/** Embedded content (
|
|
898
|
+
/** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
|
|
582
899
|
embeds;
|
|
583
900
|
/** Stickers sent with the message. */
|
|
584
901
|
stickers;
|
|
@@ -600,26 +917,41 @@ var Message = class _Message extends Base {
|
|
|
600
917
|
mentionRoles;
|
|
601
918
|
/** Client-side nonce for deduplication. */
|
|
602
919
|
nonce;
|
|
603
|
-
/**
|
|
920
|
+
/**
|
|
921
|
+
* Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
|
|
922
|
+
* Narrowed type has {@link Channel.send} and {@link Channel.delete}.
|
|
923
|
+
*/
|
|
604
924
|
get channel() {
|
|
605
|
-
|
|
925
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
926
|
+
return channel?.isTextBased() ? channel : null;
|
|
606
927
|
}
|
|
607
928
|
/** Cached guild, or null for DMs / uncached. */
|
|
608
929
|
get guild() {
|
|
609
930
|
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
610
931
|
}
|
|
611
|
-
/**
|
|
932
|
+
/** Cached guild member for the author, or null in DMs / if uncached. */
|
|
933
|
+
get member() {
|
|
934
|
+
return this.guild?.members.get(this.author.id) ?? null;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
938
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
939
|
+
* @example
|
|
940
|
+
* const channel = await message.resolveChannel();
|
|
941
|
+
* await channel.delete();
|
|
942
|
+
*/
|
|
612
943
|
async resolveChannel() {
|
|
613
944
|
return this.client.channels.resolve(this.channelId);
|
|
614
945
|
}
|
|
615
|
-
/**
|
|
946
|
+
/**
|
|
947
|
+
* Fetch and resolve the guild, or null if a DM.
|
|
948
|
+
* Propagates network/auth errors; only returns null when there is no guildId.
|
|
949
|
+
* @example
|
|
950
|
+
* const guild = await message.resolveGuild();
|
|
951
|
+
*/
|
|
616
952
|
async resolveGuild() {
|
|
617
953
|
if (!this.guildId) return null;
|
|
618
|
-
|
|
619
|
-
return await this.client.guilds.resolve(this.guildId);
|
|
620
|
-
} catch {
|
|
621
|
-
return null;
|
|
622
|
-
}
|
|
954
|
+
return this.client.guilds.resolve(this.guildId);
|
|
623
955
|
}
|
|
624
956
|
/**
|
|
625
957
|
* Construct a message from API data.
|
|
@@ -636,29 +968,73 @@ var Message = class _Message extends Base {
|
|
|
636
968
|
this.createdAt = new Date(data.timestamp);
|
|
637
969
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
638
970
|
this.pinned = data.pinned;
|
|
639
|
-
this.attachments = new
|
|
640
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
641
|
-
this.type = data.type ??
|
|
642
|
-
this.flags = data.flags ?? 0;
|
|
971
|
+
this.attachments = new import_collection3.Collection();
|
|
972
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
973
|
+
this.type = data.type ?? import_types5.MessageType.Default;
|
|
974
|
+
this.flags = new import_util4.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
643
975
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
644
976
|
this.tts = data.tts ?? false;
|
|
645
|
-
this.embeds = data.embeds ?? [];
|
|
646
|
-
this.stickers = data.stickers ?? [];
|
|
647
|
-
this.reactions =
|
|
648
|
-
this.
|
|
649
|
-
this.
|
|
650
|
-
|
|
977
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
978
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
|
|
979
|
+
this.reactions = new MessageReactionManager(this);
|
|
980
|
+
this.reactions._patch(data.reactions);
|
|
981
|
+
this.messageReference = data.message_reference ? {
|
|
982
|
+
channelId: data.message_reference.channel_id,
|
|
983
|
+
messageId: data.message_reference.message_id,
|
|
984
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
985
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
986
|
+
} : null;
|
|
987
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
|
|
988
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
651
989
|
this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
|
|
652
990
|
this.webhookId = data.webhook_id ?? null;
|
|
653
991
|
this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
|
|
654
992
|
this.mentionRoles = data.mention_roles ?? [];
|
|
655
993
|
this.nonce = data.nonce ?? null;
|
|
656
994
|
}
|
|
657
|
-
/**
|
|
995
|
+
/**
|
|
996
|
+
* Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
|
|
997
|
+
* @internal
|
|
998
|
+
*/
|
|
999
|
+
_patch(data) {
|
|
1000
|
+
this.content = data.content;
|
|
1001
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
1002
|
+
this.pinned = data.pinned;
|
|
1003
|
+
this.attachments.clear();
|
|
1004
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
|
|
1005
|
+
this.flags = new import_util4.MessageFlagsBitField(BigInt(data.flags ?? 0));
|
|
1006
|
+
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1007
|
+
this.tts = data.tts ?? false;
|
|
1008
|
+
this.embeds = (data.embeds ?? []).map(toMessageEmbed);
|
|
1009
|
+
this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
|
|
1010
|
+
this.reactions._patch(data.reactions);
|
|
1011
|
+
this.messageReference = data.message_reference ? {
|
|
1012
|
+
channelId: data.message_reference.channel_id,
|
|
1013
|
+
messageId: data.message_reference.message_id,
|
|
1014
|
+
guildId: data.message_reference.guild_id ?? null,
|
|
1015
|
+
...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
|
|
1016
|
+
} : null;
|
|
1017
|
+
this.messageSnapshots = (data.message_snapshots ?? []).map(
|
|
1018
|
+
(s) => toMessageSnapshot(this.client, s)
|
|
1019
|
+
);
|
|
1020
|
+
this.call = data.call ? toMessageCall(data.call) : null;
|
|
1021
|
+
this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
|
|
1022
|
+
this.webhookId = data.webhook_id ?? null;
|
|
1023
|
+
this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
|
|
1024
|
+
this.mentionRoles = data.mention_roles ?? [];
|
|
1025
|
+
this.nonce = data.nonce ?? null;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Send a standalone message in this channel (not a reply).
|
|
1029
|
+
* Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
|
|
1030
|
+
*/
|
|
658
1031
|
async send(options) {
|
|
659
1032
|
return sendMessage(this, options);
|
|
660
1033
|
}
|
|
661
|
-
/**
|
|
1034
|
+
/**
|
|
1035
|
+
* Send a message to another channel by ID.
|
|
1036
|
+
* Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
|
|
1037
|
+
*/
|
|
662
1038
|
async sendTo(channelId, options) {
|
|
663
1039
|
return sendMessageTo(this, channelId, options);
|
|
664
1040
|
}
|
|
@@ -672,6 +1048,16 @@ var Message = class _Message extends Base {
|
|
|
672
1048
|
async reply(options, replyOptions) {
|
|
673
1049
|
return replyToMessage(this, options, replyOptions);
|
|
674
1050
|
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Hydrate a partial message, or return the message as-is.
|
|
1053
|
+
* @example
|
|
1054
|
+
* client.on(Events.MessageUpdate, async (_old, msg) => {
|
|
1055
|
+
* const message = await Message.resolve(msg);
|
|
1056
|
+
* });
|
|
1057
|
+
*/
|
|
1058
|
+
static async resolve(message) {
|
|
1059
|
+
return message.partial ? message.fetch() : message;
|
|
1060
|
+
}
|
|
675
1061
|
/** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
|
|
676
1062
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
677
1063
|
return createMessageBody(content, referenced_message, ping);
|
|
@@ -684,7 +1070,7 @@ var Message = class _Message extends Base {
|
|
|
684
1070
|
async edit(options) {
|
|
685
1071
|
const body = {};
|
|
686
1072
|
if (options.content !== void 0) body.content = options.content;
|
|
687
|
-
if (options.embeds
|
|
1073
|
+
if (options.embeds !== void 0) {
|
|
688
1074
|
body.embeds = options.embeds.map(
|
|
689
1075
|
(e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e
|
|
690
1076
|
);
|
|
@@ -692,11 +1078,12 @@ var Message = class _Message extends Base {
|
|
|
692
1078
|
if (options.allowedMentions) {
|
|
693
1079
|
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
694
1080
|
}
|
|
695
|
-
|
|
1081
|
+
const flags = resolveMessageFlags(options.flags);
|
|
1082
|
+
if (flags !== void 0) body.flags = flags;
|
|
696
1083
|
if (options.attachments !== void 0) {
|
|
697
1084
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
698
1085
|
}
|
|
699
|
-
const data = await this.client.rest.patch(
|
|
1086
|
+
const data = await this.client.rest.patch(import_types5.Routes.channelMessage(this.channelId, this.id), {
|
|
700
1087
|
body
|
|
701
1088
|
});
|
|
702
1089
|
const updated = new _Message(this.client, data);
|
|
@@ -707,31 +1094,38 @@ var Message = class _Message extends Base {
|
|
|
707
1094
|
createReactionCollector(options) {
|
|
708
1095
|
return new ReactionCollector(this.client, this.id, this.channelId, options);
|
|
709
1096
|
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Wait for reactions matching the filter, then resolve the collected set.
|
|
1099
|
+
* Pass `errors: ['time']` to reject when the timer fires instead of resolving.
|
|
1100
|
+
*/
|
|
1101
|
+
awaitReactions(options) {
|
|
1102
|
+
return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
|
|
1103
|
+
}
|
|
710
1104
|
/** Fetch the latest version of this message from the API. */
|
|
711
1105
|
async fetch() {
|
|
712
1106
|
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
713
1107
|
}
|
|
714
1108
|
/** Delete this message. */
|
|
715
1109
|
async delete() {
|
|
716
|
-
await this.client.rest.delete(
|
|
1110
|
+
await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id));
|
|
717
1111
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
718
1112
|
}
|
|
719
1113
|
/** Delete a specific attachment from this message. */
|
|
720
1114
|
async deleteAttachment(attachmentId) {
|
|
721
1115
|
await this.client.rest.delete(
|
|
722
|
-
|
|
1116
|
+
import_types5.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
723
1117
|
{ auth: true }
|
|
724
1118
|
);
|
|
725
1119
|
this.attachments.delete(attachmentId);
|
|
726
1120
|
}
|
|
727
1121
|
/** Pin this message in the channel. */
|
|
728
1122
|
async pin() {
|
|
729
|
-
await this.client.rest.put(
|
|
1123
|
+
await this.client.rest.put(import_types5.Routes.channelPinMessage(this.channelId, this.id));
|
|
730
1124
|
this.pinned = true;
|
|
731
1125
|
}
|
|
732
1126
|
/** Unpin this message from the channel. */
|
|
733
1127
|
async unpin() {
|
|
734
|
-
await this.client.rest.delete(
|
|
1128
|
+
await this.client.rest.delete(import_types5.Routes.channelPinMessage(this.channelId, this.id));
|
|
735
1129
|
this.pinned = false;
|
|
736
1130
|
}
|
|
737
1131
|
/** React to this message with an emoji. */
|
|
@@ -759,7 +1153,59 @@ var Message = class _Message extends Base {
|
|
|
759
1153
|
return fetchMessageReactionUsersPage(this, emoji, options);
|
|
760
1154
|
}
|
|
761
1155
|
};
|
|
1156
|
+
|
|
1157
|
+
// src/Domain/Message/PartialMessage.ts
|
|
1158
|
+
var import_util5 = require("@fluxerjs/util");
|
|
1159
|
+
var PartialMessage = class {
|
|
1160
|
+
partial = true;
|
|
1161
|
+
client;
|
|
1162
|
+
id;
|
|
1163
|
+
channelId;
|
|
1164
|
+
guildId;
|
|
1165
|
+
content;
|
|
1166
|
+
authorId;
|
|
1167
|
+
author;
|
|
1168
|
+
createdAt;
|
|
1169
|
+
constructor(client, data) {
|
|
1170
|
+
this.client = client;
|
|
1171
|
+
this.id = data.id;
|
|
1172
|
+
this.channelId = data.channelId;
|
|
1173
|
+
this.guildId = data.guildId ?? null;
|
|
1174
|
+
this.content = data.content ?? null;
|
|
1175
|
+
this.authorId = data.authorId ?? null;
|
|
1176
|
+
this.author = data.author ?? null;
|
|
1177
|
+
this.createdAt = data.createdAt ?? (import_util5.SnowflakeUtil.isValid(data.id) ? import_util5.SnowflakeUtil.dateFromSnowflake(data.id) : null);
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Live text-capable channel from cache, or null if uncached / not text-based.
|
|
1181
|
+
* Same contract as {@link Message.channel}.
|
|
1182
|
+
*/
|
|
1183
|
+
get channel() {
|
|
1184
|
+
const channel = this.client.channels.get(this.channelId) ?? null;
|
|
1185
|
+
return channel?.isTextBased() ? channel : null;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Fetch this message's channel (cache first). The returned {@link Channel}
|
|
1189
|
+
* has {@link Channel.delete} and {@link Channel.send}.
|
|
1190
|
+
* @example
|
|
1191
|
+
* const channel = await message.resolveChannel();
|
|
1192
|
+
* await channel.delete();
|
|
1193
|
+
*/
|
|
1194
|
+
async resolveChannel() {
|
|
1195
|
+
return this.client.channels.resolve(this.channelId);
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Fetch the full message from the API.
|
|
1199
|
+
* @example
|
|
1200
|
+
* const message = await partial.fetch();
|
|
1201
|
+
* await message.reply('Pong!');
|
|
1202
|
+
*/
|
|
1203
|
+
async fetch() {
|
|
1204
|
+
return this.client.channels.fetchMessage(this.channelId, this.id);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
762
1207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
763
1208
|
0 && (module.exports = {
|
|
764
|
-
Message
|
|
1209
|
+
Message,
|
|
1210
|
+
PartialMessage
|
|
765
1211
|
});
|