@fluxerjs/core 2.1.0 → 2.2.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.
@@ -1,8 +1,8 @@
1
- export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-CWiBEUUV.mjs';
1
+ export { ae as Message, ak as MessageEditOptions, at as MessageSendOptions, aF as PartialMessage, aR as ReplyOptions } from './SubpathMessage-D70lAT7N.mjs';
2
2
  import '@fluxerjs/collection';
3
3
  import '@fluxerjs/types';
4
- import 'events';
4
+ import 'node:events';
5
5
  import '@fluxerjs/rest';
6
+ import '@fluxerjs/util';
6
7
  import '@fluxerjs/ws';
7
8
  import '@fluxerjs/builders';
8
- import '@fluxerjs/util';
package/dist/message.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-CWiBEUUV.js';
1
+ export { ae as Message, ak as MessageEditOptions, at as MessageSendOptions, aF as PartialMessage, aR as ReplyOptions } from './SubpathMessage-D70lAT7N.js';
2
2
  import '@fluxerjs/collection';
3
3
  import '@fluxerjs/types';
4
- import 'events';
4
+ import 'node:events';
5
5
  import '@fluxerjs/rest';
6
+ import '@fluxerjs/util';
6
7
  import '@fluxerjs/ws';
7
8
  import '@fluxerjs/builders';
8
- import '@fluxerjs/util';
package/dist/message.js CHANGED
@@ -17,19 +17,19 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/subpath-message.ts
21
- var subpath_message_exports = {};
22
- __export(subpath_message_exports, {
20
+ // src/SubpathMessage.ts
21
+ var SubpathMessage_exports = {};
22
+ __export(SubpathMessage_exports, {
23
23
  Message: () => Message
24
24
  });
25
- module.exports = __toCommonJS(subpath_message_exports);
25
+ module.exports = __toCommonJS(SubpathMessage_exports);
26
26
 
27
- // src/structures/message/Message.ts
28
- var import_collection2 = require("@fluxerjs/collection");
27
+ // src/Domain/Message/Message.ts
29
28
  var import_builders3 = require("@fluxerjs/builders");
30
- var import_types6 = require("@fluxerjs/types");
29
+ var import_collection2 = require("@fluxerjs/collection");
30
+ var import_types5 = require("@fluxerjs/types");
31
31
 
32
- // src/client/sdkOptions.ts
32
+ // src/ClientCore/SdkOptions/Attachments.ts
33
33
  function toMessageAttachmentEditWire(attachments) {
34
34
  return attachments.map((a) => {
35
35
  const out = { id: a.id };
@@ -44,13 +44,17 @@ function toMessageAttachmentEditWire(attachments) {
44
44
  });
45
45
  }
46
46
 
47
- // src/errors/ErrorCodes.ts
47
+ // src/Helpers/MessageUtils/Body.ts
48
+ var import_builders = require("@fluxerjs/builders");
49
+ var import_types = require("@fluxerjs/types");
50
+
51
+ // src/LibErrors/ErrorCodes.ts
48
52
  var import_util = require("@fluxerjs/util");
49
53
 
50
- // src/errors/FluxerError.ts
54
+ // src/LibErrors/FluxerError.ts
51
55
  var import_util2 = require("@fluxerjs/util");
52
56
 
53
- // src/util/messageUtils/files.ts
57
+ // src/Helpers/MessageUtils/Files.ts
54
58
  var FILE_FETCH_TIMEOUT_MS = 3e4;
55
59
  async function fetchFileBuffer(url, index) {
56
60
  if (!URL.canParse(url)) {
@@ -93,9 +97,7 @@ async function resolveMessageFiles(files) {
93
97
  return result;
94
98
  }
95
99
 
96
- // src/util/messageUtils/body.ts
97
- var import_types = require("@fluxerjs/types");
98
- var import_builders = require("@fluxerjs/builders");
100
+ // src/Helpers/MessageUtils/Body.ts
99
101
  function toAPIAllowedMentions(options) {
100
102
  const result = {};
101
103
  if (options.parse !== void 0) result.parse = options.parse;
@@ -229,19 +231,48 @@ async function prepareMessagePostPayload(options, defaults) {
229
231
  };
230
232
  }
231
233
 
232
- // src/util/ReactionCollector.ts
233
- var import_events = require("events");
234
+ // src/Helpers/ReactionCollector.ts
235
+ var import_node_events = require("events");
234
236
  var import_collection = require("@fluxerjs/collection");
235
237
 
236
- // src/structures/MessageReaction.ts
237
- var import_types3 = require("@fluxerjs/types");
238
+ // src/Domain/Message/MessageReaction.ts
239
+ var import_types2 = require("@fluxerjs/types");
240
+
241
+ // src/Helpers/HttpErrors.ts
238
242
  var import_rest = require("@fluxerjs/rest");
243
+ function httpStatus(err) {
244
+ if (err instanceof import_rest.FluxerAPIError) return err.statusCode;
245
+ if (typeof err === "object" && err !== null && "statusCode" in err) {
246
+ const code = err.statusCode;
247
+ return typeof code === "number" ? code : void 0;
248
+ }
249
+ return void 0;
250
+ }
251
+ function errorMessage(err, fallback) {
252
+ if (err instanceof Error && err.message) return err.message;
253
+ if (typeof err === "string" && err.length > 0) return err;
254
+ return fallback;
255
+ }
256
+ function rethrowMapped(err, options) {
257
+ if (err instanceof import_rest.RateLimitError) throw err;
258
+ if (err instanceof import_util2.FluxerError) throw err;
259
+ if (options.notFound && httpStatus(err) === 404) {
260
+ throw new import_util2.FluxerError(options.notFound.message, {
261
+ code: options.notFound.code,
262
+ cause: err
263
+ });
264
+ }
265
+ throw new import_util2.FluxerError(errorMessage(err, options.fallback), {
266
+ code: options.code,
267
+ cause: err
268
+ });
269
+ }
239
270
 
240
- // src/structures/Base.ts
271
+ // src/Domain/Base.ts
241
272
  var Base = class {
242
273
  };
243
274
 
244
- // src/structures/MessageReaction.ts
275
+ // src/Domain/Message/MessageReaction.ts
245
276
  var MessageReaction = class extends Base {
246
277
  client;
247
278
  messageId;
@@ -263,9 +294,9 @@ var MessageReaction = class extends Base {
263
294
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
264
295
  };
265
296
  }
266
- /** Emoji as a string: unicode or "name:id" for custom. */
297
+ /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
267
298
  get emojiIdentifier() {
268
- return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
299
+ return this.emoji.id ? this.emoji.animated ? `a:${this.emoji.name}:${this.emoji.id}` : `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
269
300
  }
270
301
  /** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
271
302
  get guild() {
@@ -279,23 +310,22 @@ var MessageReaction = class extends Base {
279
310
  async fetchMessage() {
280
311
  try {
281
312
  const data = await this.client.rest.get(
282
- import_types3.Routes.channelMessage(this.channelId, this.messageId)
313
+ import_types2.Routes.channelMessage(this.channelId, this.messageId)
283
314
  );
284
315
  return new Message(this.client, data);
285
316
  } catch (err) {
286
- if (err instanceof import_rest.RateLimitError) throw err;
287
- if (err instanceof import_rest.FluxerAPIError && err.statusCode === 404) {
288
- throw new import_util2.FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
317
+ rethrowMapped(err, {
318
+ notFound: {
289
319
  code: import_util.ErrorCodes.MessageNotFound,
290
- cause: err
291
- });
292
- }
293
- throw err instanceof import_util2.FluxerError ? err : new import_util2.FluxerError(String(err), { cause: err });
320
+ message: `Message ${this.messageId} not found in channel ${this.channelId}`
321
+ },
322
+ fallback: `Failed to fetch message ${this.messageId}`
323
+ });
294
324
  }
295
325
  }
296
326
  };
297
327
 
298
- // src/util/Events.ts
328
+ // src/Helpers/Events.ts
299
329
  var Events = {
300
330
  Ready: "ready",
301
331
  MessageCreate: "messageCreate",
@@ -330,6 +360,8 @@ var Events = {
330
360
  ChannelUpdate: "channelUpdate",
331
361
  ChannelDelete: "channelDelete",
332
362
  ChannelPinsUpdate: "channelPinsUpdate",
363
+ ChannelRecipientAdd: "channelRecipientAdd",
364
+ ChannelRecipientRemove: "channelRecipientRemove",
333
365
  InviteCreate: "inviteCreate",
334
366
  InviteDelete: "inviteDelete",
335
367
  TypingStart: "typingStart",
@@ -349,8 +381,8 @@ var Events = {
349
381
  Debug: "debug"
350
382
  };
351
383
 
352
- // src/util/ReactionCollector.ts
353
- var ReactionCollector = class extends import_events.EventEmitter {
384
+ // src/Helpers/ReactionCollector.ts
385
+ var ReactionCollector = class extends import_node_events.EventEmitter {
354
386
  client;
355
387
  messageId;
356
388
  channelId;
@@ -396,7 +428,11 @@ var ReactionCollector = class extends import_events.EventEmitter {
396
428
  const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
397
429
  id: entry.userId,
398
430
  username: "Unknown",
399
- discriminator: "0"
431
+ discriminator: "0",
432
+ global_name: null,
433
+ avatar: null,
434
+ avatar_color: null,
435
+ flags: 0
400
436
  });
401
437
  this._collect(reaction, user, entry.userId);
402
438
  }
@@ -411,6 +447,7 @@ var ReactionCollector = class extends import_events.EventEmitter {
411
447
  if (this._ended) return;
412
448
  if (!this.options.filter(reaction, user)) return;
413
449
  const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
450
+ if (this.collected.has(key)) return;
414
451
  this.collected.set(key, { reaction, user });
415
452
  this.emit("collect", reaction, user);
416
453
  if (this.options.max > 0 && this.collected.size >= this.options.max) {
@@ -436,26 +473,82 @@ var ReactionCollector = class extends import_events.EventEmitter {
436
473
  }
437
474
  };
438
475
 
439
- // src/structures/message/reactions.ts
440
- var import_types4 = require("@fluxerjs/types");
476
+ // src/Domain/Message/Reactions.ts
477
+ var import_types3 = require("@fluxerjs/types");
478
+ var import_util3 = require("@fluxerjs/util");
441
479
  async function emojiPath(message, emoji) {
442
480
  return message.client.resolveEmoji(emoji, message.guildId);
443
481
  }
482
+ function toReactionEmoji(emoji) {
483
+ if (typeof emoji !== "string") {
484
+ return {
485
+ name: emoji.name,
486
+ ...emoji.id !== void 0 ? { id: emoji.id } : {},
487
+ ...emoji.animated !== void 0 ? { animated: emoji.animated } : {}
488
+ };
489
+ }
490
+ const animatedWire = /^a:(\w+):(\d+)$/.exec(emoji);
491
+ if (animatedWire) {
492
+ return { name: animatedWire[1], id: animatedWire[2], animated: true };
493
+ }
494
+ const parsed = (0, import_util3.parseEmoji)(emoji);
495
+ if (parsed?.id) {
496
+ return {
497
+ name: parsed.name,
498
+ id: parsed.id,
499
+ ...parsed.animated ? { animated: true } : {}
500
+ };
501
+ }
502
+ let name = emoji;
503
+ try {
504
+ name = decodeURIComponent(emoji);
505
+ } catch {
506
+ }
507
+ return { name: parsed?.name ?? name };
508
+ }
509
+ function emitOwnReactionAdd(message, wireOrInput) {
510
+ const user = message.client.user;
511
+ if (!user) return;
512
+ const emojiPayload = toReactionEmoji(wireOrInput);
513
+ const reaction = new MessageReaction(message.client, {
514
+ user_id: user.id,
515
+ channel_id: message.channelId,
516
+ message_id: message.id,
517
+ guild_id: message.guildId ?? void 0,
518
+ emoji: {
519
+ name: emojiPayload.name,
520
+ ...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
521
+ ...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
522
+ }
523
+ });
524
+ const payload = {
525
+ reaction,
526
+ user,
527
+ messageId: message.id,
528
+ channelId: message.channelId,
529
+ emoji: emojiPayload,
530
+ userId: user.id
531
+ };
532
+ message.client.emit(Events.MessageReactionAdd, payload);
533
+ }
444
534
  async function reactToMessage(message, emoji) {
445
- const e = await emojiPath(message, emoji);
446
- await message.client.rest.put(import_types4.Routes.channelMessageReactionMe(message.channelId, message.id, e));
535
+ const wire = await emojiPath(message, emoji);
536
+ await message.client.rest.put(
537
+ import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
538
+ );
539
+ emitOwnReactionAdd(message, wire);
447
540
  }
448
541
  async function removeMessageReaction(message, emoji, userId) {
449
542
  const e = await emojiPath(message, emoji);
450
- const route = userId ? import_types4.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types4.Routes.channelMessageReactionMe(message.channelId, message.id, e);
543
+ const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
451
544
  await message.client.rest.delete(route);
452
545
  }
453
546
  async function removeAllMessageReactions(message) {
454
- await message.client.rest.delete(import_types4.Routes.channelMessageReactions(message.channelId, message.id));
547
+ await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
455
548
  }
456
549
  async function removeMessageReactionEmoji(message, emoji) {
457
550
  const e = await emojiPath(message, emoji);
458
- await message.client.rest.delete(import_types4.Routes.channelMessageReaction(message.channelId, message.id, e));
551
+ await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
459
552
  }
460
553
  async function fetchMessageReactionUsers(message, emoji, options) {
461
554
  return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
@@ -466,7 +559,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
466
559
  if (options?.limit != null) params.set("limit", String(options.limit));
467
560
  if (options?.after) params.set("after", options.after);
468
561
  const qs = params.toString();
469
- const route = import_types4.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
562
+ const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
470
563
  const data = await message.client.rest.get(route);
471
564
  if (Array.isArray(data)) {
472
565
  return {
@@ -483,9 +576,9 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
483
576
  };
484
577
  }
485
578
 
486
- // src/structures/message/send.ts
579
+ // src/Domain/Message/Send.ts
487
580
  var import_builders2 = require("@fluxerjs/builders");
488
- var import_types5 = require("@fluxerjs/types");
581
+ var import_types4 = require("@fluxerjs/types");
489
582
  function toReplyTarget(ref) {
490
583
  return {
491
584
  channelId: ref.channel_id,
@@ -519,7 +612,7 @@ function asReplyTarget(value) {
519
612
  }
520
613
  async function sendPrepared(message, payload) {
521
614
  const data = await message.client.rest.post(
522
- import_types5.Routes.channelMessages(message.channelId),
615
+ import_types4.Routes.channelMessages(message.channelId),
523
616
  payload
524
617
  );
525
618
  message.client._addMessageToCache(message.channelId, data);
@@ -548,7 +641,7 @@ async function replyToMessage(message, options, replyOptions) {
548
641
  );
549
642
  }
550
643
 
551
- // src/structures/message/Message.ts
644
+ // src/Domain/Message/Message.ts
552
645
  var Message = class _Message extends Base {
553
646
  /** The {@link Client} that instantiated this message. */
554
647
  client;
@@ -638,7 +731,7 @@ var Message = class _Message extends Base {
638
731
  this.pinned = data.pinned;
639
732
  this.attachments = new import_collection2.Collection();
640
733
  for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
641
- this.type = data.type ?? import_types6.MessageType.Default;
734
+ this.type = data.type ?? import_types5.MessageType.Default;
642
735
  this.flags = data.flags ?? 0;
643
736
  this.mentionEveryone = data.mention_everyone ?? false;
644
737
  this.tts = data.tts ?? false;
@@ -696,7 +789,7 @@ var Message = class _Message extends Base {
696
789
  if (options.attachments !== void 0) {
697
790
  body.attachments = toMessageAttachmentEditWire(options.attachments);
698
791
  }
699
- const data = await this.client.rest.patch(import_types6.Routes.channelMessage(this.channelId, this.id), {
792
+ const data = await this.client.rest.patch(import_types5.Routes.channelMessage(this.channelId, this.id), {
700
793
  body
701
794
  });
702
795
  const updated = new _Message(this.client, data);
@@ -713,25 +806,25 @@ var Message = class _Message extends Base {
713
806
  }
714
807
  /** Delete this message. */
715
808
  async delete() {
716
- await this.client.rest.delete(import_types6.Routes.channelMessage(this.channelId, this.id));
809
+ await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id));
717
810
  this.client._removeMessageFromCache(this.channelId, this.id);
718
811
  }
719
812
  /** Delete a specific attachment from this message. */
720
813
  async deleteAttachment(attachmentId) {
721
814
  await this.client.rest.delete(
722
- import_types6.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
815
+ import_types5.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
723
816
  { auth: true }
724
817
  );
725
818
  this.attachments.delete(attachmentId);
726
819
  }
727
820
  /** Pin this message in the channel. */
728
821
  async pin() {
729
- await this.client.rest.put(import_types6.Routes.channelPinMessage(this.channelId, this.id));
822
+ await this.client.rest.put(import_types5.Routes.channelPinMessage(this.channelId, this.id));
730
823
  this.pinned = true;
731
824
  }
732
825
  /** Unpin this message from the channel. */
733
826
  async unpin() {
734
- await this.client.rest.delete(import_types6.Routes.channelPinMessage(this.channelId, this.id));
827
+ await this.client.rest.delete(import_types5.Routes.channelPinMessage(this.channelId, this.id));
735
828
  this.pinned = false;
736
829
  }
737
830
  /** React to this message with an emoji. */
package/dist/message.mjs CHANGED
@@ -1,12 +1,12 @@
1
- // src/structures/message/Message.ts
2
- import { Collection as Collection2 } from "@fluxerjs/collection";
1
+ // src/Domain/Message/Message.ts
3
2
  import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
3
+ import { Collection as Collection2 } from "@fluxerjs/collection";
4
4
  import {
5
5
  MessageType,
6
6
  Routes as Routes4
7
7
  } from "@fluxerjs/types";
8
8
 
9
- // src/client/sdkOptions.ts
9
+ // src/ClientCore/SdkOptions/Attachments.ts
10
10
  function toMessageAttachmentEditWire(attachments) {
11
11
  return attachments.map((a) => {
12
12
  const out = { id: a.id };
@@ -21,13 +21,17 @@ function toMessageAttachmentEditWire(attachments) {
21
21
  });
22
22
  }
23
23
 
24
- // src/errors/ErrorCodes.ts
24
+ // src/Helpers/MessageUtils/Body.ts
25
+ import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
26
+ import { MessageReferenceType } from "@fluxerjs/types";
27
+
28
+ // src/LibErrors/ErrorCodes.ts
25
29
  import { ErrorCodes } from "@fluxerjs/util";
26
30
 
27
- // src/errors/FluxerError.ts
31
+ // src/LibErrors/FluxerError.ts
28
32
  import { FluxerError } from "@fluxerjs/util";
29
33
 
30
- // src/util/messageUtils/files.ts
34
+ // src/Helpers/MessageUtils/Files.ts
31
35
  var FILE_FETCH_TIMEOUT_MS = 3e4;
32
36
  async function fetchFileBuffer(url, index) {
33
37
  if (!URL.canParse(url)) {
@@ -70,9 +74,7 @@ async function resolveMessageFiles(files) {
70
74
  return result;
71
75
  }
72
76
 
73
- // src/util/messageUtils/body.ts
74
- import { MessageReferenceType } from "@fluxerjs/types";
75
- import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
77
+ // src/Helpers/MessageUtils/Body.ts
76
78
  function toAPIAllowedMentions(options) {
77
79
  const result = {};
78
80
  if (options.parse !== void 0) result.parse = options.parse;
@@ -206,19 +208,48 @@ async function prepareMessagePostPayload(options, defaults) {
206
208
  };
207
209
  }
208
210
 
209
- // src/util/ReactionCollector.ts
211
+ // src/Helpers/ReactionCollector.ts
210
212
  import { EventEmitter } from "events";
211
213
  import { Collection } from "@fluxerjs/collection";
212
214
 
213
- // src/structures/MessageReaction.ts
215
+ // src/Domain/Message/MessageReaction.ts
214
216
  import { Routes } from "@fluxerjs/types";
217
+
218
+ // src/Helpers/HttpErrors.ts
215
219
  import { FluxerAPIError, RateLimitError } from "@fluxerjs/rest";
220
+ function httpStatus(err) {
221
+ if (err instanceof FluxerAPIError) return err.statusCode;
222
+ if (typeof err === "object" && err !== null && "statusCode" in err) {
223
+ const code = err.statusCode;
224
+ return typeof code === "number" ? code : void 0;
225
+ }
226
+ return void 0;
227
+ }
228
+ function errorMessage(err, fallback) {
229
+ if (err instanceof Error && err.message) return err.message;
230
+ if (typeof err === "string" && err.length > 0) return err;
231
+ return fallback;
232
+ }
233
+ function rethrowMapped(err, options) {
234
+ if (err instanceof RateLimitError) throw err;
235
+ if (err instanceof FluxerError) throw err;
236
+ if (options.notFound && httpStatus(err) === 404) {
237
+ throw new FluxerError(options.notFound.message, {
238
+ code: options.notFound.code,
239
+ cause: err
240
+ });
241
+ }
242
+ throw new FluxerError(errorMessage(err, options.fallback), {
243
+ code: options.code,
244
+ cause: err
245
+ });
246
+ }
216
247
 
217
- // src/structures/Base.ts
248
+ // src/Domain/Base.ts
218
249
  var Base = class {
219
250
  };
220
251
 
221
- // src/structures/MessageReaction.ts
252
+ // src/Domain/Message/MessageReaction.ts
222
253
  var MessageReaction = class extends Base {
223
254
  client;
224
255
  messageId;
@@ -240,9 +271,9 @@ var MessageReaction = class extends Base {
240
271
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
241
272
  };
242
273
  }
243
- /** Emoji as a string: unicode or "name:id" for custom. */
274
+ /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
244
275
  get emojiIdentifier() {
245
- return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
276
+ return this.emoji.id ? this.emoji.animated ? `a:${this.emoji.name}:${this.emoji.id}` : `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
246
277
  }
247
278
  /** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
248
279
  get guild() {
@@ -260,19 +291,18 @@ var MessageReaction = class extends Base {
260
291
  );
261
292
  return new Message(this.client, data);
262
293
  } catch (err) {
263
- if (err instanceof RateLimitError) throw err;
264
- if (err instanceof FluxerAPIError && err.statusCode === 404) {
265
- throw new FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
294
+ rethrowMapped(err, {
295
+ notFound: {
266
296
  code: ErrorCodes.MessageNotFound,
267
- cause: err
268
- });
269
- }
270
- throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
297
+ message: `Message ${this.messageId} not found in channel ${this.channelId}`
298
+ },
299
+ fallback: `Failed to fetch message ${this.messageId}`
300
+ });
271
301
  }
272
302
  }
273
303
  };
274
304
 
275
- // src/util/Events.ts
305
+ // src/Helpers/Events.ts
276
306
  var Events = {
277
307
  Ready: "ready",
278
308
  MessageCreate: "messageCreate",
@@ -307,6 +337,8 @@ var Events = {
307
337
  ChannelUpdate: "channelUpdate",
308
338
  ChannelDelete: "channelDelete",
309
339
  ChannelPinsUpdate: "channelPinsUpdate",
340
+ ChannelRecipientAdd: "channelRecipientAdd",
341
+ ChannelRecipientRemove: "channelRecipientRemove",
310
342
  InviteCreate: "inviteCreate",
311
343
  InviteDelete: "inviteDelete",
312
344
  TypingStart: "typingStart",
@@ -326,7 +358,7 @@ var Events = {
326
358
  Debug: "debug"
327
359
  };
328
360
 
329
- // src/util/ReactionCollector.ts
361
+ // src/Helpers/ReactionCollector.ts
330
362
  var ReactionCollector = class extends EventEmitter {
331
363
  client;
332
364
  messageId;
@@ -373,7 +405,11 @@ var ReactionCollector = class extends EventEmitter {
373
405
  const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
374
406
  id: entry.userId,
375
407
  username: "Unknown",
376
- discriminator: "0"
408
+ discriminator: "0",
409
+ global_name: null,
410
+ avatar: null,
411
+ avatar_color: null,
412
+ flags: 0
377
413
  });
378
414
  this._collect(reaction, user, entry.userId);
379
415
  }
@@ -388,6 +424,7 @@ var ReactionCollector = class extends EventEmitter {
388
424
  if (this._ended) return;
389
425
  if (!this.options.filter(reaction, user)) return;
390
426
  const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
427
+ if (this.collected.has(key)) return;
391
428
  this.collected.set(key, { reaction, user });
392
429
  this.emit("collect", reaction, user);
393
430
  if (this.options.max > 0 && this.collected.size >= this.options.max) {
@@ -413,14 +450,70 @@ var ReactionCollector = class extends EventEmitter {
413
450
  }
414
451
  };
415
452
 
416
- // src/structures/message/reactions.ts
453
+ // src/Domain/Message/Reactions.ts
417
454
  import { Routes as Routes2 } from "@fluxerjs/types";
455
+ import { parseEmoji } from "@fluxerjs/util";
418
456
  async function emojiPath(message, emoji) {
419
457
  return message.client.resolveEmoji(emoji, message.guildId);
420
458
  }
459
+ function toReactionEmoji(emoji) {
460
+ if (typeof emoji !== "string") {
461
+ return {
462
+ name: emoji.name,
463
+ ...emoji.id !== void 0 ? { id: emoji.id } : {},
464
+ ...emoji.animated !== void 0 ? { animated: emoji.animated } : {}
465
+ };
466
+ }
467
+ const animatedWire = /^a:(\w+):(\d+)$/.exec(emoji);
468
+ if (animatedWire) {
469
+ return { name: animatedWire[1], id: animatedWire[2], animated: true };
470
+ }
471
+ const parsed = parseEmoji(emoji);
472
+ if (parsed?.id) {
473
+ return {
474
+ name: parsed.name,
475
+ id: parsed.id,
476
+ ...parsed.animated ? { animated: true } : {}
477
+ };
478
+ }
479
+ let name = emoji;
480
+ try {
481
+ name = decodeURIComponent(emoji);
482
+ } catch {
483
+ }
484
+ return { name: parsed?.name ?? name };
485
+ }
486
+ function emitOwnReactionAdd(message, wireOrInput) {
487
+ const user = message.client.user;
488
+ if (!user) return;
489
+ const emojiPayload = toReactionEmoji(wireOrInput);
490
+ const reaction = new MessageReaction(message.client, {
491
+ user_id: user.id,
492
+ channel_id: message.channelId,
493
+ message_id: message.id,
494
+ guild_id: message.guildId ?? void 0,
495
+ emoji: {
496
+ name: emojiPayload.name,
497
+ ...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
498
+ ...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
499
+ }
500
+ });
501
+ const payload = {
502
+ reaction,
503
+ user,
504
+ messageId: message.id,
505
+ channelId: message.channelId,
506
+ emoji: emojiPayload,
507
+ userId: user.id
508
+ };
509
+ message.client.emit(Events.MessageReactionAdd, payload);
510
+ }
421
511
  async function reactToMessage(message, emoji) {
422
- const e = await emojiPath(message, emoji);
423
- await message.client.rest.put(Routes2.channelMessageReactionMe(message.channelId, message.id, e));
512
+ const wire = await emojiPath(message, emoji);
513
+ await message.client.rest.put(
514
+ Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
515
+ );
516
+ emitOwnReactionAdd(message, wire);
424
517
  }
425
518
  async function removeMessageReaction(message, emoji, userId) {
426
519
  const e = await emojiPath(message, emoji);
@@ -460,7 +553,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
460
553
  };
461
554
  }
462
555
 
463
- // src/structures/message/send.ts
556
+ // src/Domain/Message/Send.ts
464
557
  import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
465
558
  import { Routes as Routes3 } from "@fluxerjs/types";
466
559
  function toReplyTarget(ref) {
@@ -525,7 +618,7 @@ async function replyToMessage(message, options, replyOptions) {
525
618
  );
526
619
  }
527
620
 
528
- // src/structures/message/Message.ts
621
+ // src/Domain/Message/Message.ts
529
622
  var Message = class _Message extends Base {
530
623
  /** The {@link Client} that instantiated this message. */
531
624
  client;