@fluxerjs/core 2.0.2 → 2.0.3
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/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +311 -277
- package/dist/client.mjs +285 -251
- package/dist/cluster.d.mts +1 -1
- package/dist/cluster.d.ts +1 -1
- package/dist/cluster.js +313 -277
- package/dist/cluster.mjs +287 -251
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +311 -277
- package/dist/index.mjs +285 -251
- package/dist/message.d.mts +1 -1
- package/dist/message.d.ts +1 -1
- package/dist/message.js +119 -29
- package/dist/message.mjs +118 -28
- package/dist/{subpath-message-CoDItxh0.d.mts → subpath-message-CWiBEUUV.d.mts} +7 -1
- package/dist/{subpath-message-CoDItxh0.d.ts → subpath-message-CWiBEUUV.d.ts} +7 -1
- package/package.json +4 -4
package/dist/message.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-
|
|
1
|
+
export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-CWiBEUUV.mjs';
|
|
2
2
|
import '@fluxerjs/collection';
|
|
3
3
|
import '@fluxerjs/types';
|
|
4
4
|
import 'events';
|
package/dist/message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-
|
|
1
|
+
export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-CWiBEUUV.js';
|
|
2
2
|
import '@fluxerjs/collection';
|
|
3
3
|
import '@fluxerjs/types';
|
|
4
4
|
import 'events';
|
package/dist/message.js
CHANGED
|
@@ -27,7 +27,7 @@ module.exports = __toCommonJS(subpath_message_exports);
|
|
|
27
27
|
// src/structures/message/Message.ts
|
|
28
28
|
var import_collection2 = require("@fluxerjs/collection");
|
|
29
29
|
var import_builders3 = require("@fluxerjs/builders");
|
|
30
|
-
var
|
|
30
|
+
var import_types6 = require("@fluxerjs/types");
|
|
31
31
|
|
|
32
32
|
// src/client/sdkOptions.ts
|
|
33
33
|
function toMessageAttachmentEditWire(attachments) {
|
|
@@ -233,6 +233,68 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
233
233
|
var import_events = require("events");
|
|
234
234
|
var import_collection = require("@fluxerjs/collection");
|
|
235
235
|
|
|
236
|
+
// src/structures/MessageReaction.ts
|
|
237
|
+
var import_types3 = require("@fluxerjs/types");
|
|
238
|
+
var import_rest = require("@fluxerjs/rest");
|
|
239
|
+
|
|
240
|
+
// src/structures/Base.ts
|
|
241
|
+
var Base = class {
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/structures/MessageReaction.ts
|
|
245
|
+
var MessageReaction = class extends Base {
|
|
246
|
+
client;
|
|
247
|
+
messageId;
|
|
248
|
+
channelId;
|
|
249
|
+
guildId;
|
|
250
|
+
emoji;
|
|
251
|
+
/** Raw gateway payload for low-level access. */
|
|
252
|
+
_data;
|
|
253
|
+
constructor(client, data) {
|
|
254
|
+
super();
|
|
255
|
+
this.client = client;
|
|
256
|
+
this._data = data;
|
|
257
|
+
this.messageId = data.message_id;
|
|
258
|
+
this.channelId = data.channel_id;
|
|
259
|
+
this.guildId = data.guild_id ?? null;
|
|
260
|
+
this.emoji = {
|
|
261
|
+
name: data.emoji.name,
|
|
262
|
+
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
263
|
+
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/** Emoji as a string: unicode or "name:id" for custom. */
|
|
267
|
+
get emojiIdentifier() {
|
|
268
|
+
return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
269
|
+
}
|
|
270
|
+
/** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
|
|
271
|
+
get guild() {
|
|
272
|
+
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Fetch the message this reaction belongs to.
|
|
276
|
+
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
277
|
+
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
278
|
+
*/
|
|
279
|
+
async fetchMessage() {
|
|
280
|
+
try {
|
|
281
|
+
const data = await this.client.rest.get(
|
|
282
|
+
import_types3.Routes.channelMessage(this.channelId, this.messageId)
|
|
283
|
+
);
|
|
284
|
+
return new Message(this.client, data);
|
|
285
|
+
} 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}`, {
|
|
289
|
+
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 });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
|
|
236
298
|
// src/util/Events.ts
|
|
237
299
|
var Events = {
|
|
238
300
|
Ready: "ready",
|
|
@@ -296,7 +358,8 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
296
358
|
collected = new import_collection.Collection();
|
|
297
359
|
_timeout = null;
|
|
298
360
|
_ended = false;
|
|
299
|
-
|
|
361
|
+
_onAdd;
|
|
362
|
+
_onAddMany;
|
|
300
363
|
constructor(client, messageId, channelId, options = {}) {
|
|
301
364
|
super();
|
|
302
365
|
this.client = client;
|
|
@@ -307,27 +370,58 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
307
370
|
time: options.time ?? 0,
|
|
308
371
|
max: options.max ?? 0
|
|
309
372
|
};
|
|
310
|
-
this.
|
|
373
|
+
this._onAdd = (payload) => {
|
|
311
374
|
if (this._ended || payload.reaction.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
312
375
|
return;
|
|
313
376
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
this.
|
|
318
|
-
|
|
319
|
-
|
|
377
|
+
this._collect(payload.reaction, payload.user, payload.userId);
|
|
378
|
+
};
|
|
379
|
+
this._onAddMany = (payload) => {
|
|
380
|
+
if (this._ended || payload.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
for (const entry of payload.reactions) {
|
|
384
|
+
if (this._ended) return;
|
|
385
|
+
const reaction = new MessageReaction(this.client, {
|
|
386
|
+
message_id: payload.messageId,
|
|
387
|
+
channel_id: payload.channelId,
|
|
388
|
+
guild_id: payload.guildId ?? void 0,
|
|
389
|
+
user_id: entry.userId,
|
|
390
|
+
emoji: {
|
|
391
|
+
name: entry.emoji.name,
|
|
392
|
+
...entry.emoji.id !== void 0 ? { id: entry.emoji.id } : {},
|
|
393
|
+
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
|
|
397
|
+
id: entry.userId,
|
|
398
|
+
username: "Unknown",
|
|
399
|
+
discriminator: "0"
|
|
400
|
+
});
|
|
401
|
+
this._collect(reaction, user, entry.userId);
|
|
320
402
|
}
|
|
321
403
|
};
|
|
322
|
-
this.client.on(Events.MessageReactionAdd, this.
|
|
404
|
+
this.client.on(Events.MessageReactionAdd, this._onAdd);
|
|
405
|
+
this.client.on(Events.MessageReactionAddMany, this._onAddMany);
|
|
323
406
|
if (this.options.time > 0) {
|
|
324
407
|
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
325
408
|
}
|
|
326
409
|
}
|
|
410
|
+
_collect(reaction, user, userId) {
|
|
411
|
+
if (this._ended) return;
|
|
412
|
+
if (!this.options.filter(reaction, user)) return;
|
|
413
|
+
const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
|
|
414
|
+
this.collected.set(key, { reaction, user });
|
|
415
|
+
this.emit("collect", reaction, user);
|
|
416
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
417
|
+
this.stop("limit");
|
|
418
|
+
}
|
|
419
|
+
}
|
|
327
420
|
stop(reason = "user") {
|
|
328
421
|
if (this._ended) return;
|
|
329
422
|
this._ended = true;
|
|
330
|
-
this.client.off(Events.MessageReactionAdd, this.
|
|
423
|
+
this.client.off(Events.MessageReactionAdd, this._onAdd);
|
|
424
|
+
this.client.off(Events.MessageReactionAddMany, this._onAddMany);
|
|
331
425
|
if (this._timeout) {
|
|
332
426
|
clearTimeout(this._timeout);
|
|
333
427
|
this._timeout = null;
|
|
@@ -342,30 +436,26 @@ var ReactionCollector = class extends import_events.EventEmitter {
|
|
|
342
436
|
}
|
|
343
437
|
};
|
|
344
438
|
|
|
345
|
-
// src/structures/Base.ts
|
|
346
|
-
var Base = class {
|
|
347
|
-
};
|
|
348
|
-
|
|
349
439
|
// src/structures/message/reactions.ts
|
|
350
|
-
var
|
|
440
|
+
var import_types4 = require("@fluxerjs/types");
|
|
351
441
|
async function emojiPath(message, emoji) {
|
|
352
442
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
353
443
|
}
|
|
354
444
|
async function reactToMessage(message, emoji) {
|
|
355
445
|
const e = await emojiPath(message, emoji);
|
|
356
|
-
await message.client.rest.put(
|
|
446
|
+
await message.client.rest.put(import_types4.Routes.channelMessageReactionMe(message.channelId, message.id, e));
|
|
357
447
|
}
|
|
358
448
|
async function removeMessageReaction(message, emoji, userId) {
|
|
359
449
|
const e = await emojiPath(message, emoji);
|
|
360
|
-
const route = userId ?
|
|
450
|
+
const route = userId ? import_types4.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types4.Routes.channelMessageReactionMe(message.channelId, message.id, e);
|
|
361
451
|
await message.client.rest.delete(route);
|
|
362
452
|
}
|
|
363
453
|
async function removeAllMessageReactions(message) {
|
|
364
|
-
await message.client.rest.delete(
|
|
454
|
+
await message.client.rest.delete(import_types4.Routes.channelMessageReactions(message.channelId, message.id));
|
|
365
455
|
}
|
|
366
456
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
367
457
|
const e = await emojiPath(message, emoji);
|
|
368
|
-
await message.client.rest.delete(
|
|
458
|
+
await message.client.rest.delete(import_types4.Routes.channelMessageReaction(message.channelId, message.id, e));
|
|
369
459
|
}
|
|
370
460
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
371
461
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -376,7 +466,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
376
466
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
377
467
|
if (options?.after) params.set("after", options.after);
|
|
378
468
|
const qs = params.toString();
|
|
379
|
-
const route =
|
|
469
|
+
const route = import_types4.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
|
|
380
470
|
const data = await message.client.rest.get(route);
|
|
381
471
|
if (Array.isArray(data)) {
|
|
382
472
|
return {
|
|
@@ -395,7 +485,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
395
485
|
|
|
396
486
|
// src/structures/message/send.ts
|
|
397
487
|
var import_builders2 = require("@fluxerjs/builders");
|
|
398
|
-
var
|
|
488
|
+
var import_types5 = require("@fluxerjs/types");
|
|
399
489
|
function toReplyTarget(ref) {
|
|
400
490
|
return {
|
|
401
491
|
channelId: ref.channel_id,
|
|
@@ -429,7 +519,7 @@ function asReplyTarget(value) {
|
|
|
429
519
|
}
|
|
430
520
|
async function sendPrepared(message, payload) {
|
|
431
521
|
const data = await message.client.rest.post(
|
|
432
|
-
|
|
522
|
+
import_types5.Routes.channelMessages(message.channelId),
|
|
433
523
|
payload
|
|
434
524
|
);
|
|
435
525
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -548,7 +638,7 @@ var Message = class _Message extends Base {
|
|
|
548
638
|
this.pinned = data.pinned;
|
|
549
639
|
this.attachments = new import_collection2.Collection();
|
|
550
640
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
551
|
-
this.type = data.type ??
|
|
641
|
+
this.type = data.type ?? import_types6.MessageType.Default;
|
|
552
642
|
this.flags = data.flags ?? 0;
|
|
553
643
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
554
644
|
this.tts = data.tts ?? false;
|
|
@@ -606,7 +696,7 @@ var Message = class _Message extends Base {
|
|
|
606
696
|
if (options.attachments !== void 0) {
|
|
607
697
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
608
698
|
}
|
|
609
|
-
const data = await this.client.rest.patch(
|
|
699
|
+
const data = await this.client.rest.patch(import_types6.Routes.channelMessage(this.channelId, this.id), {
|
|
610
700
|
body
|
|
611
701
|
});
|
|
612
702
|
const updated = new _Message(this.client, data);
|
|
@@ -623,25 +713,25 @@ var Message = class _Message extends Base {
|
|
|
623
713
|
}
|
|
624
714
|
/** Delete this message. */
|
|
625
715
|
async delete() {
|
|
626
|
-
await this.client.rest.delete(
|
|
716
|
+
await this.client.rest.delete(import_types6.Routes.channelMessage(this.channelId, this.id));
|
|
627
717
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
628
718
|
}
|
|
629
719
|
/** Delete a specific attachment from this message. */
|
|
630
720
|
async deleteAttachment(attachmentId) {
|
|
631
721
|
await this.client.rest.delete(
|
|
632
|
-
|
|
722
|
+
import_types6.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
633
723
|
{ auth: true }
|
|
634
724
|
);
|
|
635
725
|
this.attachments.delete(attachmentId);
|
|
636
726
|
}
|
|
637
727
|
/** Pin this message in the channel. */
|
|
638
728
|
async pin() {
|
|
639
|
-
await this.client.rest.put(
|
|
729
|
+
await this.client.rest.put(import_types6.Routes.channelPinMessage(this.channelId, this.id));
|
|
640
730
|
this.pinned = true;
|
|
641
731
|
}
|
|
642
732
|
/** Unpin this message from the channel. */
|
|
643
733
|
async unpin() {
|
|
644
|
-
await this.client.rest.delete(
|
|
734
|
+
await this.client.rest.delete(import_types6.Routes.channelPinMessage(this.channelId, this.id));
|
|
645
735
|
this.pinned = false;
|
|
646
736
|
}
|
|
647
737
|
/** React to this message with an emoji. */
|
package/dist/message.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
|
3
3
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
4
4
|
import {
|
|
5
5
|
MessageType,
|
|
6
|
-
Routes as
|
|
6
|
+
Routes as Routes4
|
|
7
7
|
} from "@fluxerjs/types";
|
|
8
8
|
|
|
9
9
|
// src/client/sdkOptions.ts
|
|
@@ -210,6 +210,68 @@ async function prepareMessagePostPayload(options, defaults) {
|
|
|
210
210
|
import { EventEmitter } from "events";
|
|
211
211
|
import { Collection } from "@fluxerjs/collection";
|
|
212
212
|
|
|
213
|
+
// src/structures/MessageReaction.ts
|
|
214
|
+
import { Routes } from "@fluxerjs/types";
|
|
215
|
+
import { FluxerAPIError, RateLimitError } from "@fluxerjs/rest";
|
|
216
|
+
|
|
217
|
+
// src/structures/Base.ts
|
|
218
|
+
var Base = class {
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// src/structures/MessageReaction.ts
|
|
222
|
+
var MessageReaction = class extends Base {
|
|
223
|
+
client;
|
|
224
|
+
messageId;
|
|
225
|
+
channelId;
|
|
226
|
+
guildId;
|
|
227
|
+
emoji;
|
|
228
|
+
/** Raw gateway payload for low-level access. */
|
|
229
|
+
_data;
|
|
230
|
+
constructor(client, data) {
|
|
231
|
+
super();
|
|
232
|
+
this.client = client;
|
|
233
|
+
this._data = data;
|
|
234
|
+
this.messageId = data.message_id;
|
|
235
|
+
this.channelId = data.channel_id;
|
|
236
|
+
this.guildId = data.guild_id ?? null;
|
|
237
|
+
this.emoji = {
|
|
238
|
+
name: data.emoji.name,
|
|
239
|
+
...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
|
|
240
|
+
...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** Emoji as a string: unicode or "name:id" for custom. */
|
|
244
|
+
get emojiIdentifier() {
|
|
245
|
+
return this.emoji.id ? `${this.emoji.name}:${this.emoji.id}` : this.emoji.name;
|
|
246
|
+
}
|
|
247
|
+
/** Guild where this reaction was added. Resolved from cache; null for DMs or if not cached. */
|
|
248
|
+
get guild() {
|
|
249
|
+
return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Fetch the message this reaction belongs to.
|
|
253
|
+
* Use when you need to edit, delete, or otherwise interact with the message.
|
|
254
|
+
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
255
|
+
*/
|
|
256
|
+
async fetchMessage() {
|
|
257
|
+
try {
|
|
258
|
+
const data = await this.client.rest.get(
|
|
259
|
+
Routes.channelMessage(this.channelId, this.messageId)
|
|
260
|
+
);
|
|
261
|
+
return new Message(this.client, data);
|
|
262
|
+
} 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}`, {
|
|
266
|
+
code: ErrorCodes.MessageNotFound,
|
|
267
|
+
cause: err
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
213
275
|
// src/util/Events.ts
|
|
214
276
|
var Events = {
|
|
215
277
|
Ready: "ready",
|
|
@@ -273,7 +335,8 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
273
335
|
collected = new Collection();
|
|
274
336
|
_timeout = null;
|
|
275
337
|
_ended = false;
|
|
276
|
-
|
|
338
|
+
_onAdd;
|
|
339
|
+
_onAddMany;
|
|
277
340
|
constructor(client, messageId, channelId, options = {}) {
|
|
278
341
|
super();
|
|
279
342
|
this.client = client;
|
|
@@ -284,27 +347,58 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
284
347
|
time: options.time ?? 0,
|
|
285
348
|
max: options.max ?? 0
|
|
286
349
|
};
|
|
287
|
-
this.
|
|
350
|
+
this._onAdd = (payload) => {
|
|
288
351
|
if (this._ended || payload.reaction.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
289
352
|
return;
|
|
290
353
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
this.
|
|
295
|
-
|
|
296
|
-
|
|
354
|
+
this._collect(payload.reaction, payload.user, payload.userId);
|
|
355
|
+
};
|
|
356
|
+
this._onAddMany = (payload) => {
|
|
357
|
+
if (this._ended || payload.messageId !== this.messageId || payload.channelId !== this.channelId) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
for (const entry of payload.reactions) {
|
|
361
|
+
if (this._ended) return;
|
|
362
|
+
const reaction = new MessageReaction(this.client, {
|
|
363
|
+
message_id: payload.messageId,
|
|
364
|
+
channel_id: payload.channelId,
|
|
365
|
+
guild_id: payload.guildId ?? void 0,
|
|
366
|
+
user_id: entry.userId,
|
|
367
|
+
emoji: {
|
|
368
|
+
name: entry.emoji.name,
|
|
369
|
+
...entry.emoji.id !== void 0 ? { id: entry.emoji.id } : {},
|
|
370
|
+
...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
|
|
374
|
+
id: entry.userId,
|
|
375
|
+
username: "Unknown",
|
|
376
|
+
discriminator: "0"
|
|
377
|
+
});
|
|
378
|
+
this._collect(reaction, user, entry.userId);
|
|
297
379
|
}
|
|
298
380
|
};
|
|
299
|
-
this.client.on(Events.MessageReactionAdd, this.
|
|
381
|
+
this.client.on(Events.MessageReactionAdd, this._onAdd);
|
|
382
|
+
this.client.on(Events.MessageReactionAddMany, this._onAddMany);
|
|
300
383
|
if (this.options.time > 0) {
|
|
301
384
|
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
302
385
|
}
|
|
303
386
|
}
|
|
387
|
+
_collect(reaction, user, userId) {
|
|
388
|
+
if (this._ended) return;
|
|
389
|
+
if (!this.options.filter(reaction, user)) return;
|
|
390
|
+
const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
|
|
391
|
+
this.collected.set(key, { reaction, user });
|
|
392
|
+
this.emit("collect", reaction, user);
|
|
393
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
394
|
+
this.stop("limit");
|
|
395
|
+
}
|
|
396
|
+
}
|
|
304
397
|
stop(reason = "user") {
|
|
305
398
|
if (this._ended) return;
|
|
306
399
|
this._ended = true;
|
|
307
|
-
this.client.off(Events.MessageReactionAdd, this.
|
|
400
|
+
this.client.off(Events.MessageReactionAdd, this._onAdd);
|
|
401
|
+
this.client.off(Events.MessageReactionAddMany, this._onAddMany);
|
|
308
402
|
if (this._timeout) {
|
|
309
403
|
clearTimeout(this._timeout);
|
|
310
404
|
this._timeout = null;
|
|
@@ -319,30 +413,26 @@ var ReactionCollector = class extends EventEmitter {
|
|
|
319
413
|
}
|
|
320
414
|
};
|
|
321
415
|
|
|
322
|
-
// src/structures/Base.ts
|
|
323
|
-
var Base = class {
|
|
324
|
-
};
|
|
325
|
-
|
|
326
416
|
// src/structures/message/reactions.ts
|
|
327
|
-
import { Routes } from "@fluxerjs/types";
|
|
417
|
+
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
328
418
|
async function emojiPath(message, emoji) {
|
|
329
419
|
return message.client.resolveEmoji(emoji, message.guildId);
|
|
330
420
|
}
|
|
331
421
|
async function reactToMessage(message, emoji) {
|
|
332
422
|
const e = await emojiPath(message, emoji);
|
|
333
|
-
await message.client.rest.put(
|
|
423
|
+
await message.client.rest.put(Routes2.channelMessageReactionMe(message.channelId, message.id, e));
|
|
334
424
|
}
|
|
335
425
|
async function removeMessageReaction(message, emoji, userId) {
|
|
336
426
|
const e = await emojiPath(message, emoji);
|
|
337
|
-
const route = userId ?
|
|
427
|
+
const route = userId ? Routes2.channelMessageReactionUser(message.channelId, message.id, e, userId) : Routes2.channelMessageReactionMe(message.channelId, message.id, e);
|
|
338
428
|
await message.client.rest.delete(route);
|
|
339
429
|
}
|
|
340
430
|
async function removeAllMessageReactions(message) {
|
|
341
|
-
await message.client.rest.delete(
|
|
431
|
+
await message.client.rest.delete(Routes2.channelMessageReactions(message.channelId, message.id));
|
|
342
432
|
}
|
|
343
433
|
async function removeMessageReactionEmoji(message, emoji) {
|
|
344
434
|
const e = await emojiPath(message, emoji);
|
|
345
|
-
await message.client.rest.delete(
|
|
435
|
+
await message.client.rest.delete(Routes2.channelMessageReaction(message.channelId, message.id, e));
|
|
346
436
|
}
|
|
347
437
|
async function fetchMessageReactionUsers(message, emoji, options) {
|
|
348
438
|
return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
|
|
@@ -353,7 +443,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
353
443
|
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
354
444
|
if (options?.after) params.set("after", options.after);
|
|
355
445
|
const qs = params.toString();
|
|
356
|
-
const route =
|
|
446
|
+
const route = Routes2.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
|
|
357
447
|
const data = await message.client.rest.get(route);
|
|
358
448
|
if (Array.isArray(data)) {
|
|
359
449
|
return {
|
|
@@ -372,7 +462,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
|
|
|
372
462
|
|
|
373
463
|
// src/structures/message/send.ts
|
|
374
464
|
import { MessagePayload as MessagePayloadBuilder } from "@fluxerjs/builders";
|
|
375
|
-
import { Routes as
|
|
465
|
+
import { Routes as Routes3 } from "@fluxerjs/types";
|
|
376
466
|
function toReplyTarget(ref) {
|
|
377
467
|
return {
|
|
378
468
|
channelId: ref.channel_id,
|
|
@@ -406,7 +496,7 @@ function asReplyTarget(value) {
|
|
|
406
496
|
}
|
|
407
497
|
async function sendPrepared(message, payload) {
|
|
408
498
|
const data = await message.client.rest.post(
|
|
409
|
-
|
|
499
|
+
Routes3.channelMessages(message.channelId),
|
|
410
500
|
payload
|
|
411
501
|
);
|
|
412
502
|
message.client._addMessageToCache(message.channelId, data);
|
|
@@ -583,7 +673,7 @@ var Message = class _Message extends Base {
|
|
|
583
673
|
if (options.attachments !== void 0) {
|
|
584
674
|
body.attachments = toMessageAttachmentEditWire(options.attachments);
|
|
585
675
|
}
|
|
586
|
-
const data = await this.client.rest.patch(
|
|
676
|
+
const data = await this.client.rest.patch(Routes4.channelMessage(this.channelId, this.id), {
|
|
587
677
|
body
|
|
588
678
|
});
|
|
589
679
|
const updated = new _Message(this.client, data);
|
|
@@ -600,25 +690,25 @@ var Message = class _Message extends Base {
|
|
|
600
690
|
}
|
|
601
691
|
/** Delete this message. */
|
|
602
692
|
async delete() {
|
|
603
|
-
await this.client.rest.delete(
|
|
693
|
+
await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id));
|
|
604
694
|
this.client._removeMessageFromCache(this.channelId, this.id);
|
|
605
695
|
}
|
|
606
696
|
/** Delete a specific attachment from this message. */
|
|
607
697
|
async deleteAttachment(attachmentId) {
|
|
608
698
|
await this.client.rest.delete(
|
|
609
|
-
|
|
699
|
+
Routes4.channelMessageAttachment(this.channelId, this.id, attachmentId),
|
|
610
700
|
{ auth: true }
|
|
611
701
|
);
|
|
612
702
|
this.attachments.delete(attachmentId);
|
|
613
703
|
}
|
|
614
704
|
/** Pin this message in the channel. */
|
|
615
705
|
async pin() {
|
|
616
|
-
await this.client.rest.put(
|
|
706
|
+
await this.client.rest.put(Routes4.channelPinMessage(this.channelId, this.id));
|
|
617
707
|
this.pinned = true;
|
|
618
708
|
}
|
|
619
709
|
/** Unpin this message from the channel. */
|
|
620
710
|
async unpin() {
|
|
621
|
-
await this.client.rest.delete(
|
|
711
|
+
await this.client.rest.delete(Routes4.channelPinMessage(this.channelId, this.id));
|
|
622
712
|
this.pinned = false;
|
|
623
713
|
}
|
|
624
714
|
/** React to this message with an emoji. */
|
|
@@ -1595,6 +1595,10 @@ interface ReactionCollectorEvents {
|
|
|
1595
1595
|
}
|
|
1596
1596
|
/**
|
|
1597
1597
|
* Collects reactions on a message. Use message.createReactionCollector().
|
|
1598
|
+
*
|
|
1599
|
+
* Listens to both {@link Events.MessageReactionAdd} and {@link Events.MessageReactionAddMany}
|
|
1600
|
+
* (gateway may batch rapid reactions into ADD_MANY instead of individual ADD events).
|
|
1601
|
+
*
|
|
1598
1602
|
* @example
|
|
1599
1603
|
* const collector = message.createReactionCollector({ filter: (r, u) => u.id === userId, time: 10000 });
|
|
1600
1604
|
* collector.on('collect', (reaction, user) => console.log(user.username, 'reacted', reaction.emoji.name));
|
|
@@ -1608,8 +1612,10 @@ declare class ReactionCollector extends EventEmitter {
|
|
|
1608
1612
|
readonly collected: Collection<string, CollectedReaction>;
|
|
1609
1613
|
private _timeout;
|
|
1610
1614
|
private _ended;
|
|
1611
|
-
private
|
|
1615
|
+
private readonly _onAdd;
|
|
1616
|
+
private readonly _onAddMany;
|
|
1612
1617
|
constructor(client: Client, messageId: string, channelId: string, options?: ReactionCollectorOptions);
|
|
1618
|
+
private _collect;
|
|
1613
1619
|
stop(reason?: ReactionCollectorEndReason): void;
|
|
1614
1620
|
on<K extends keyof ReactionCollectorEvents>(event: K, listener: (...args: ReactionCollectorEvents[K]) => void): this;
|
|
1615
1621
|
emit<K extends keyof ReactionCollectorEvents>(event: K, ...args: ReactionCollectorEvents[K]): boolean;
|
|
@@ -1595,6 +1595,10 @@ interface ReactionCollectorEvents {
|
|
|
1595
1595
|
}
|
|
1596
1596
|
/**
|
|
1597
1597
|
* Collects reactions on a message. Use message.createReactionCollector().
|
|
1598
|
+
*
|
|
1599
|
+
* Listens to both {@link Events.MessageReactionAdd} and {@link Events.MessageReactionAddMany}
|
|
1600
|
+
* (gateway may batch rapid reactions into ADD_MANY instead of individual ADD events).
|
|
1601
|
+
*
|
|
1598
1602
|
* @example
|
|
1599
1603
|
* const collector = message.createReactionCollector({ filter: (r, u) => u.id === userId, time: 10000 });
|
|
1600
1604
|
* collector.on('collect', (reaction, user) => console.log(user.username, 'reacted', reaction.emoji.name));
|
|
@@ -1608,8 +1612,10 @@ declare class ReactionCollector extends EventEmitter {
|
|
|
1608
1612
|
readonly collected: Collection<string, CollectedReaction>;
|
|
1609
1613
|
private _timeout;
|
|
1610
1614
|
private _ended;
|
|
1611
|
-
private
|
|
1615
|
+
private readonly _onAdd;
|
|
1616
|
+
private readonly _onAddMany;
|
|
1612
1617
|
constructor(client: Client, messageId: string, channelId: string, options?: ReactionCollectorOptions);
|
|
1618
|
+
private _collect;
|
|
1613
1619
|
stop(reason?: ReactionCollectorEndReason): void;
|
|
1614
1620
|
on<K extends keyof ReactionCollectorEvents>(event: K, listener: (...args: ReactionCollectorEvents[K]) => void): this;
|
|
1615
1621
|
emit<K extends keyof ReactionCollectorEvents>(event: K, ...args: ReactionCollectorEvents[K]): boolean;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.0.
|
|
6
|
+
"version": "2.0.3",
|
|
7
7
|
"description": "A fully-featured SDK for Fluxer bots",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@fluxerjs/rest": "2.0.2",
|
|
58
58
|
"@fluxerjs/ws": "2.0.1",
|
|
59
|
-
"@fluxerjs/builders": "2.0.0",
|
|
60
59
|
"@fluxerjs/collection": "2.0.0",
|
|
61
|
-
"@fluxerjs/
|
|
62
|
-
"@fluxerjs/
|
|
60
|
+
"@fluxerjs/types": "2.0.0",
|
|
61
|
+
"@fluxerjs/builders": "2.0.0",
|
|
62
|
+
"@fluxerjs/util": "2.0.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/node": "^20.0.0",
|