@fluxerjs/core 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +338 -202
- package/dist/client.mjs +213 -75
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +354 -206
- package/dist/index.mjs +229 -76
- package/dist/message.d.mts +1 -1
- package/dist/message.d.ts +1 -1
- package/dist/message.js +97 -36
- package/dist/message.mjs +85 -24
- package/dist/{subpath-message-b43enjDT.d.mts → subpath-message-DSs_mdc4.d.mts} +148 -24
- package/dist/{subpath-message-b43enjDT.d.ts → subpath-message-DSs_mdc4.d.ts} +148 -24
- package/package.json +7 -7
package/dist/client.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@fluxerjs/types";
|
|
8
8
|
|
|
9
9
|
// src/client/ChannelManager.ts
|
|
10
|
-
import { Collection as
|
|
10
|
+
import { Collection as Collection5 } from "@fluxerjs/collection";
|
|
11
11
|
import { Routes as Routes6 } from "@fluxerjs/types";
|
|
12
12
|
import { emitDeprecationWarning as emitDeprecationWarning2 } from "@fluxerjs/util";
|
|
13
13
|
import { FluxerAPIError as FluxerAPIError2, RateLimitError as RateLimitError2 } from "@fluxerjs/rest";
|
|
@@ -19,12 +19,14 @@ import { FluxerError } from "@fluxerjs/util";
|
|
|
19
19
|
import { ErrorCodes } from "@fluxerjs/util";
|
|
20
20
|
|
|
21
21
|
// src/util/messageUtils.ts
|
|
22
|
+
import { MessageFlags } from "@fluxerjs/types";
|
|
22
23
|
import { EmbedBuilder } from "@fluxerjs/builders";
|
|
23
24
|
var FILE_FETCH_TIMEOUT_MS = 3e4;
|
|
24
25
|
async function resolveMessageFiles(files) {
|
|
25
26
|
const result = [];
|
|
26
27
|
for (let i = 0; i < files.length; i++) {
|
|
27
28
|
const f = files[i];
|
|
29
|
+
if (!f) continue;
|
|
28
30
|
const filename = f.filename ?? f.name;
|
|
29
31
|
if ("url" in f && f.url) {
|
|
30
32
|
if (!URL.canParse(f.url)) {
|
|
@@ -63,6 +65,21 @@ async function resolveMessageFiles(files) {
|
|
|
63
65
|
}
|
|
64
66
|
return result;
|
|
65
67
|
}
|
|
68
|
+
function toAPIAllowedMentions(options) {
|
|
69
|
+
const result = {};
|
|
70
|
+
if (options.parse?.length) result.parse = options.parse;
|
|
71
|
+
if (options.users?.length) result.users = options.users;
|
|
72
|
+
if (options.roles?.length) result.roles = options.roles;
|
|
73
|
+
if (options.repliedUser !== void 0) result.replied_user = options.repliedUser;
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function applyReplyPingSuppression(body) {
|
|
77
|
+
body.flags = (body.flags ?? 0) | MessageFlags.SuppressNotifications;
|
|
78
|
+
body.allowed_mentions = {
|
|
79
|
+
...body.allowed_mentions ?? {},
|
|
80
|
+
replied_user: false
|
|
81
|
+
};
|
|
82
|
+
}
|
|
66
83
|
function buildSendBody(options) {
|
|
67
84
|
const body = typeof options === "string" ? { content: options } : options;
|
|
68
85
|
const result = {};
|
|
@@ -84,12 +101,43 @@ function buildSendBody(options) {
|
|
|
84
101
|
filename: f.filename ?? f.name
|
|
85
102
|
}));
|
|
86
103
|
}
|
|
104
|
+
if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
|
|
105
|
+
if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
|
|
106
|
+
if (body.nonce !== void 0) result.nonce = body.nonce;
|
|
107
|
+
if (body.favoriteMemeId !== void 0) result.favorite_meme_id = body.favoriteMemeId;
|
|
108
|
+
if (body.tts !== void 0) result.tts = body.tts;
|
|
87
109
|
if (body.flags !== void 0) result.flags = body.flags;
|
|
88
110
|
return result;
|
|
89
111
|
}
|
|
112
|
+
function toMessageReference(target) {
|
|
113
|
+
const ref = {
|
|
114
|
+
channel_id: target.channelId,
|
|
115
|
+
message_id: target.messageId
|
|
116
|
+
};
|
|
117
|
+
if (target.guildId != null && target.guildId !== "") ref.guild_id = target.guildId;
|
|
118
|
+
return ref;
|
|
119
|
+
}
|
|
120
|
+
async function prepareMessagePostPayload(options) {
|
|
121
|
+
if (typeof options === "string") {
|
|
122
|
+
if (options.length === 0) throw new RangeError("Cannot send an empty message");
|
|
123
|
+
options = { content: options };
|
|
124
|
+
}
|
|
125
|
+
const { replyTo, ping, files, allowedMentions, ...sendFields } = options;
|
|
126
|
+
const body = buildSendBody({ ...sendFields, files, allowedMentions });
|
|
127
|
+
if (replyTo) {
|
|
128
|
+
body.message_reference = toMessageReference(replyTo);
|
|
129
|
+
const suppressPing = ping === false || allowedMentions?.repliedUser === false || body.allowed_mentions?.replied_user === false;
|
|
130
|
+
if (suppressPing) applyReplyPingSuppression(body);
|
|
131
|
+
} else if (allowedMentions?.repliedUser === false) {
|
|
132
|
+
applyReplyPingSuppression(body);
|
|
133
|
+
}
|
|
134
|
+
const resolvedFiles = files?.length ? await resolveMessageFiles(files) : void 0;
|
|
135
|
+
return { body, files: resolvedFiles };
|
|
136
|
+
}
|
|
90
137
|
|
|
91
138
|
// src/client/MessageManager.ts
|
|
92
139
|
import { Routes as Routes2 } from "@fluxerjs/types";
|
|
140
|
+
import { Collection as Collection3 } from "@fluxerjs/collection";
|
|
93
141
|
import { FluxerAPIError, RateLimitError } from "@fluxerjs/rest";
|
|
94
142
|
|
|
95
143
|
// src/structures/Base.ts
|
|
@@ -98,7 +146,7 @@ var Base = class {
|
|
|
98
146
|
|
|
99
147
|
// src/structures/Message.ts
|
|
100
148
|
import { Collection as Collection2 } from "@fluxerjs/collection";
|
|
101
|
-
import { MessageType,
|
|
149
|
+
import { MessageType, Routes } from "@fluxerjs/types";
|
|
102
150
|
import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
|
|
103
151
|
|
|
104
152
|
// src/util/ReactionCollector.ts
|
|
@@ -302,7 +350,7 @@ var Message = class _Message extends Base {
|
|
|
302
350
|
* await message.send({ content: 'File', files: [{ name: 'data.txt', data }] });
|
|
303
351
|
*/
|
|
304
352
|
async send(options) {
|
|
305
|
-
const payload = await
|
|
353
|
+
const payload = await prepareMessagePostPayload(options);
|
|
306
354
|
return this._send(payload);
|
|
307
355
|
}
|
|
308
356
|
/**
|
|
@@ -323,42 +371,53 @@ var Message = class _Message extends Base {
|
|
|
323
371
|
* await message.reply('Pong!');
|
|
324
372
|
* await message.reply({ embeds: [embed] });
|
|
325
373
|
* await message.reply('No ping!', { ping: false });
|
|
374
|
+
* await message.reply({ content: 'Silent reply', allowedMentions: AllowedMentions.suppressReplyPing });
|
|
326
375
|
* await message.reply({ content: 'Reply to other', replyTo: otherMessage });
|
|
327
376
|
*/
|
|
328
377
|
async reply(options, replyOptions) {
|
|
329
378
|
const opts = typeof options === "string" ? { content: options } : options;
|
|
330
379
|
const mergedReply = replyOptions ?? (opts.ping !== void 0 || opts.replyTo !== void 0) ? { ping: opts.ping, replyTo: opts.replyTo } : void 0;
|
|
331
380
|
const refMessage = mergedReply?.replyTo ?? this;
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
} :
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
381
|
+
const replyTo = refMessage instanceof _Message ? {
|
|
382
|
+
channelId: refMessage.channelId,
|
|
383
|
+
messageId: refMessage.id,
|
|
384
|
+
guildId: refMessage.guildId
|
|
385
|
+
} : refMessage;
|
|
386
|
+
const { replyTo: _ignored, ping: _ping, ...sendOpts } = opts;
|
|
387
|
+
const payload = await prepareMessagePostPayload({
|
|
388
|
+
...sendOpts,
|
|
389
|
+
replyTo,
|
|
390
|
+
ping: mergedReply?.ping
|
|
391
|
+
});
|
|
342
392
|
return this._send(payload);
|
|
343
393
|
}
|
|
344
|
-
/** Exposed for testing
|
|
394
|
+
/** Exposed for testing — prefer `message.reply()` / `prepareMessagePostPayload()`. */
|
|
345
395
|
static async _createMessageBody(content, referenced_message, ping) {
|
|
396
|
+
if (typeof content === "string" && content.length === 0) {
|
|
397
|
+
throw new RangeError("Cannot send an empty message");
|
|
398
|
+
}
|
|
346
399
|
if (typeof content === "string") {
|
|
347
|
-
|
|
348
|
-
|
|
400
|
+
const opts2 = { content };
|
|
401
|
+
if (referenced_message) {
|
|
402
|
+
opts2.replyTo = {
|
|
403
|
+
channelId: referenced_message.channel_id,
|
|
404
|
+
messageId: referenced_message.message_id,
|
|
405
|
+
...referenced_message.guild_id != null ? { guildId: referenced_message.guild_id } : {}
|
|
406
|
+
};
|
|
407
|
+
if (ping !== void 0) opts2.ping = ping;
|
|
349
408
|
}
|
|
350
|
-
|
|
409
|
+
return prepareMessagePostPayload(opts2);
|
|
351
410
|
}
|
|
352
|
-
const
|
|
353
|
-
const files = content.files?.length ? await resolveMessageFiles(content.files) : void 0;
|
|
354
|
-
const body = { ...base };
|
|
411
|
+
const opts = { ...content };
|
|
355
412
|
if (referenced_message) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
413
|
+
opts.replyTo = {
|
|
414
|
+
channelId: referenced_message.channel_id,
|
|
415
|
+
messageId: referenced_message.message_id,
|
|
416
|
+
...referenced_message.guild_id != null ? { guildId: referenced_message.guild_id } : {}
|
|
417
|
+
};
|
|
418
|
+
if (ping !== void 0) opts.ping = ping;
|
|
360
419
|
}
|
|
361
|
-
return
|
|
420
|
+
return prepareMessagePostPayload(opts);
|
|
362
421
|
}
|
|
363
422
|
async _send(payload) {
|
|
364
423
|
const data = await this.client.rest.post(
|
|
@@ -378,6 +437,9 @@ var Message = class _Message extends Base {
|
|
|
378
437
|
if (options.embeds?.length) {
|
|
379
438
|
body.embeds = options.embeds.map((e) => e instanceof EmbedBuilder2 ? e.toJSON() : e);
|
|
380
439
|
}
|
|
440
|
+
if (options.allowedMentions) {
|
|
441
|
+
body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
|
|
442
|
+
}
|
|
381
443
|
const data = await this.client.rest.patch(Routes.channelMessage(this.channelId, this.id), {
|
|
382
444
|
body
|
|
383
445
|
});
|
|
@@ -511,14 +573,13 @@ var MessageManager = class {
|
|
|
511
573
|
const data = this.client._getMessageCache(this.channelId)?.get(messageId);
|
|
512
574
|
return data ? new Message(this.client, data) : void 0;
|
|
513
575
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
async fetch(messageId) {
|
|
576
|
+
async fetch(messageIdOrOptions) {
|
|
577
|
+
if (typeof messageIdOrOptions === "string") {
|
|
578
|
+
return this.fetchOne(messageIdOrOptions);
|
|
579
|
+
}
|
|
580
|
+
return this.fetchMany(messageIdOrOptions);
|
|
581
|
+
}
|
|
582
|
+
async fetchOne(messageId) {
|
|
522
583
|
try {
|
|
523
584
|
const data = await this.client.rest.get(
|
|
524
585
|
Routes2.channelMessage(this.channelId, messageId)
|
|
@@ -536,16 +597,37 @@ var MessageManager = class {
|
|
|
536
597
|
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
537
598
|
}
|
|
538
599
|
}
|
|
600
|
+
async fetchMany(options) {
|
|
601
|
+
const params = new URLSearchParams();
|
|
602
|
+
if (options.limit != null) {
|
|
603
|
+
if (options.limit < 1 || options.limit > 100) {
|
|
604
|
+
throw new RangeError("limit must be between 1 and 100");
|
|
605
|
+
}
|
|
606
|
+
params.set("limit", String(options.limit));
|
|
607
|
+
}
|
|
608
|
+
if (options.before) params.set("before", options.before);
|
|
609
|
+
if (options.after) params.set("after", options.after);
|
|
610
|
+
if (options.around) params.set("around", options.around);
|
|
611
|
+
const qs = params.toString();
|
|
612
|
+
const route = Routes2.channelMessages(this.channelId) + (qs ? `?${qs}` : "");
|
|
613
|
+
const data = await this.client.rest.get(route);
|
|
614
|
+
const collection = new Collection3();
|
|
615
|
+
for (const msg of data) {
|
|
616
|
+
this.client._addMessageToCache(this.channelId, msg);
|
|
617
|
+
collection.set(msg.id, new Message(this.client, msg));
|
|
618
|
+
}
|
|
619
|
+
return collection;
|
|
620
|
+
}
|
|
539
621
|
};
|
|
540
622
|
|
|
541
623
|
// src/util/MessageCollector.ts
|
|
542
624
|
import { EventEmitter as EventEmitter2 } from "events";
|
|
543
|
-
import { Collection as
|
|
625
|
+
import { Collection as Collection4 } from "@fluxerjs/collection";
|
|
544
626
|
var MessageCollector = class extends EventEmitter2 {
|
|
545
627
|
client;
|
|
546
628
|
channelId;
|
|
547
629
|
options;
|
|
548
|
-
collected = new
|
|
630
|
+
collected = new Collection4();
|
|
549
631
|
_timeout = null;
|
|
550
632
|
_ended = false;
|
|
551
633
|
_listener;
|
|
@@ -724,7 +806,6 @@ var Webhook = class _Webhook extends Base {
|
|
|
724
806
|
const body = buildSendBody(opts);
|
|
725
807
|
if (opts.username !== void 0) body.username = opts.username;
|
|
726
808
|
if (opts.avatar_url !== void 0) body.avatar_url = opts.avatar_url;
|
|
727
|
-
if (opts.tts !== void 0) body.tts = opts.tts;
|
|
728
809
|
const route = Routes3.webhookExecute(this.id, this.token) + (wait ? "?wait=true" : "");
|
|
729
810
|
const files = opts.files?.length ? await resolveMessageFiles(opts.files) : void 0;
|
|
730
811
|
const postOptions = files?.length ? { body, files, auth: false } : { body, auth: false };
|
|
@@ -995,6 +1076,20 @@ var Channel = class _Channel extends Base {
|
|
|
995
1076
|
async sendTyping() {
|
|
996
1077
|
await this.client.rest.post(Routes5.channelTyping(this.id), { auth: true });
|
|
997
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Fetch available RTC regions for voice/video in this channel.
|
|
1081
|
+
* GET /channels/{id}/rtc-regions
|
|
1082
|
+
*/
|
|
1083
|
+
async fetchRtcRegions() {
|
|
1084
|
+
return this.client.rest.get(Routes5.channelRtcRegions(this.id), { auth: true });
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Fetch the current user's slowmode state in this channel.
|
|
1088
|
+
* GET /channels/{id}/slowmode
|
|
1089
|
+
*/
|
|
1090
|
+
async fetchSlowmode() {
|
|
1091
|
+
return this.client.rest.get(Routes5.channelSlowmode(this.id), { auth: true });
|
|
1092
|
+
}
|
|
998
1093
|
/**
|
|
999
1094
|
* Whether the bot can send messages in this channel.
|
|
1000
1095
|
* For DMs: always true (when the channel exists).
|
|
@@ -1105,11 +1200,8 @@ var GuildChannel = class extends Channel {
|
|
|
1105
1200
|
* Works for text and announcement channels. Voice/category/link channels will fail at the API.
|
|
1106
1201
|
*/
|
|
1107
1202
|
async send(options) {
|
|
1108
|
-
const
|
|
1109
|
-
const
|
|
1110
|
-
const files = opts.files?.length ? await resolveMessageFiles(opts.files) : void 0;
|
|
1111
|
-
const postOptions = files?.length ? { body, files } : { body };
|
|
1112
|
-
const data = await this.client.rest.post(Routes5.channelMessages(this.id), postOptions);
|
|
1203
|
+
const payload = await prepareMessagePostPayload(options);
|
|
1204
|
+
const data = await this.client.rest.post(Routes5.channelMessages(this.id), payload);
|
|
1113
1205
|
this.client._addMessageToCache(this.id, data);
|
|
1114
1206
|
return new Message(this.client, data);
|
|
1115
1207
|
}
|
|
@@ -1171,11 +1263,8 @@ var TextChannel = class extends GuildChannel {
|
|
|
1171
1263
|
* @param options - Text content or object with content, embeds, and/or files
|
|
1172
1264
|
*/
|
|
1173
1265
|
async send(options) {
|
|
1174
|
-
const
|
|
1175
|
-
const
|
|
1176
|
-
const files = opts.files?.length ? await resolveMessageFiles(opts.files) : void 0;
|
|
1177
|
-
const postOptions = files?.length ? { body, files } : { body };
|
|
1178
|
-
const data = await this.client.rest.post(Routes5.channelMessages(this.id), postOptions);
|
|
1266
|
+
const payload = await prepareMessagePostPayload(options);
|
|
1267
|
+
const data = await this.client.rest.post(Routes5.channelMessages(this.id), payload);
|
|
1179
1268
|
this.client._addMessageToCache(this.id, data);
|
|
1180
1269
|
return new Message(this.client, data);
|
|
1181
1270
|
}
|
|
@@ -1263,11 +1352,8 @@ var DMChannel = class extends Channel {
|
|
|
1263
1352
|
* @param options - Text content or object with content, embeds, and/or files
|
|
1264
1353
|
*/
|
|
1265
1354
|
async send(options) {
|
|
1266
|
-
const
|
|
1267
|
-
const
|
|
1268
|
-
const files = opts.files?.length ? await resolveMessageFiles(opts.files) : void 0;
|
|
1269
|
-
const postOptions = files?.length ? { body, files } : { body };
|
|
1270
|
-
const data = await this.client.rest.post(Routes5.channelMessages(this.id), postOptions);
|
|
1355
|
+
const payload = await prepareMessagePostPayload(options);
|
|
1356
|
+
const data = await this.client.rest.post(Routes5.channelMessages(this.id), payload);
|
|
1271
1357
|
this.client._addMessageToCache(this.id, data);
|
|
1272
1358
|
return new Message(this.client, data);
|
|
1273
1359
|
}
|
|
@@ -1330,7 +1416,7 @@ var DMChannel = class extends Channel {
|
|
|
1330
1416
|
};
|
|
1331
1417
|
|
|
1332
1418
|
// src/client/ChannelManager.ts
|
|
1333
|
-
var ChannelManager = class extends
|
|
1419
|
+
var ChannelManager = class extends Collection5 {
|
|
1334
1420
|
constructor(client) {
|
|
1335
1421
|
super();
|
|
1336
1422
|
this.client = client;
|
|
@@ -1438,18 +1524,15 @@ var ChannelManager = class extends Collection4 {
|
|
|
1438
1524
|
* await client.channels.send(channelId, { content: 'Report', files: [{ name: 'log.txt', data }] });
|
|
1439
1525
|
*/
|
|
1440
1526
|
async send(channelId, payload) {
|
|
1441
|
-
const
|
|
1442
|
-
const
|
|
1443
|
-
const files = opts.files?.length ? await resolveMessageFiles(opts.files) : void 0;
|
|
1444
|
-
const postOptions = files?.length ? { body, files } : { body };
|
|
1445
|
-
const data = await this.client.rest.post(Routes6.channelMessages(channelId), postOptions);
|
|
1527
|
+
const postPayload = await prepareMessagePostPayload(payload);
|
|
1528
|
+
const data = await this.client.rest.post(Routes6.channelMessages(channelId), postPayload);
|
|
1446
1529
|
this.client._addMessageToCache(channelId, data);
|
|
1447
1530
|
return new Message(this.client, data);
|
|
1448
1531
|
}
|
|
1449
1532
|
};
|
|
1450
1533
|
|
|
1451
1534
|
// src/client/GuildManager.ts
|
|
1452
|
-
import { Collection as
|
|
1535
|
+
import { Collection as Collection9 } from "@fluxerjs/collection";
|
|
1453
1536
|
import { Routes as Routes15 } from "@fluxerjs/types";
|
|
1454
1537
|
|
|
1455
1538
|
// src/structures/Guild.ts
|
|
@@ -1458,11 +1541,13 @@ import {
|
|
|
1458
1541
|
resolvePermissionsToBitfield as resolvePermissionsToBitfield2
|
|
1459
1542
|
} from "@fluxerjs/util";
|
|
1460
1543
|
import { FluxerAPIError as FluxerAPIError3 } from "@fluxerjs/rest";
|
|
1461
|
-
import { Collection as
|
|
1544
|
+
import { Collection as Collection8 } from "@fluxerjs/collection";
|
|
1462
1545
|
|
|
1463
1546
|
// src/client/GuildMemberManager.ts
|
|
1464
|
-
import { Collection as
|
|
1465
|
-
import {
|
|
1547
|
+
import { Collection as Collection7 } from "@fluxerjs/collection";
|
|
1548
|
+
import {
|
|
1549
|
+
Routes as Routes9
|
|
1550
|
+
} from "@fluxerjs/types";
|
|
1466
1551
|
|
|
1467
1552
|
// src/structures/GuildMember.ts
|
|
1468
1553
|
import { BitField } from "@fluxerjs/util";
|
|
@@ -1485,7 +1570,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
|
|
|
1485
1570
|
}
|
|
1486
1571
|
|
|
1487
1572
|
// src/structures/GuildMemberRoleManager.ts
|
|
1488
|
-
import { Collection as
|
|
1573
|
+
import { Collection as Collection6 } from "@fluxerjs/collection";
|
|
1489
1574
|
import { Routes as Routes7 } from "@fluxerjs/types";
|
|
1490
1575
|
var GuildMemberRoleManager = class {
|
|
1491
1576
|
constructor(member, initialRoleIds = []) {
|
|
@@ -1507,7 +1592,7 @@ var GuildMemberRoleManager = class {
|
|
|
1507
1592
|
* @discordJsCompat https://discord.js.org/docs/packages/discord.js/main/GuildMemberRoleManager
|
|
1508
1593
|
*/
|
|
1509
1594
|
get cache() {
|
|
1510
|
-
const coll = new
|
|
1595
|
+
const coll = new Collection6();
|
|
1511
1596
|
for (const id of this._roleIds) {
|
|
1512
1597
|
const role = this.member.guild.roles.get(id);
|
|
1513
1598
|
if (role) coll.set(id, role);
|
|
@@ -1740,7 +1825,7 @@ var GuildMember = class extends Base {
|
|
|
1740
1825
|
};
|
|
1741
1826
|
|
|
1742
1827
|
// src/client/GuildMemberManager.ts
|
|
1743
|
-
var GuildMemberManager = class extends
|
|
1828
|
+
var GuildMemberManager = class extends Collection7 {
|
|
1744
1829
|
constructor(guild) {
|
|
1745
1830
|
super();
|
|
1746
1831
|
this.guild = guild;
|
|
@@ -1815,6 +1900,19 @@ var GuildMemberManager = class extends Collection6 {
|
|
|
1815
1900
|
}
|
|
1816
1901
|
return members;
|
|
1817
1902
|
}
|
|
1903
|
+
/**
|
|
1904
|
+
* Search guild members. POST /guilds/{id}/members-search.
|
|
1905
|
+
* @param options - Search query, filters, and pagination
|
|
1906
|
+
* @returns Search results with matching members
|
|
1907
|
+
* @example
|
|
1908
|
+
* const { members } = await guild.members.search({ query: 'alex', limit: 25 });
|
|
1909
|
+
*/
|
|
1910
|
+
async search(options) {
|
|
1911
|
+
return this.guild.client.rest.post(Routes9.guildMembersSearch(this.guild.id), {
|
|
1912
|
+
body: options,
|
|
1913
|
+
auth: true
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1818
1916
|
};
|
|
1819
1917
|
|
|
1820
1918
|
// src/structures/Role.ts
|
|
@@ -2078,10 +2176,10 @@ var Guild = class extends Base {
|
|
|
2078
2176
|
/** Splash image height. Optional. */
|
|
2079
2177
|
splashHeight;
|
|
2080
2178
|
members;
|
|
2081
|
-
channels = new
|
|
2082
|
-
roles = new
|
|
2083
|
-
emojis = new
|
|
2084
|
-
stickers = new
|
|
2179
|
+
channels = new Collection8();
|
|
2180
|
+
roles = new Collection8();
|
|
2181
|
+
emojis = new Collection8();
|
|
2182
|
+
stickers = new Collection8();
|
|
2085
2183
|
/** @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE */
|
|
2086
2184
|
constructor(client, data) {
|
|
2087
2185
|
super();
|
|
@@ -2621,7 +2719,7 @@ var Guild = class extends Base {
|
|
|
2621
2719
|
};
|
|
2622
2720
|
|
|
2623
2721
|
// src/client/GuildManager.ts
|
|
2624
|
-
var GuildManager = class extends
|
|
2722
|
+
var GuildManager = class extends Collection9 {
|
|
2625
2723
|
constructor(client) {
|
|
2626
2724
|
super();
|
|
2627
2725
|
this.client = client;
|
|
@@ -2818,9 +2916,9 @@ import {
|
|
|
2818
2916
|
} from "@fluxerjs/util";
|
|
2819
2917
|
|
|
2820
2918
|
// src/client/UsersManager.ts
|
|
2821
|
-
import { Collection as
|
|
2919
|
+
import { Collection as Collection10 } from "@fluxerjs/collection";
|
|
2822
2920
|
import { Routes as Routes18 } from "@fluxerjs/types";
|
|
2823
|
-
var UsersManager = class extends
|
|
2921
|
+
var UsersManager = class extends Collection10 {
|
|
2824
2922
|
constructor(client) {
|
|
2825
2923
|
super();
|
|
2826
2924
|
this.client = client;
|
|
@@ -2940,9 +3038,12 @@ var ChatInputCommandInteraction = class extends BaseInteraction {
|
|
|
2940
3038
|
constructor(client, raw) {
|
|
2941
3039
|
super(client, raw);
|
|
2942
3040
|
if (raw.data?.name == null) {
|
|
2943
|
-
throw new FluxerError(
|
|
2944
|
-
|
|
2945
|
-
|
|
3041
|
+
throw new FluxerError(
|
|
3042
|
+
"ChatInputCommandInteraction requires interaction data with a command name",
|
|
3043
|
+
{
|
|
3044
|
+
code: ErrorCodes.InteractionInvalidPayload
|
|
3045
|
+
}
|
|
3046
|
+
);
|
|
2946
3047
|
}
|
|
2947
3048
|
}
|
|
2948
3049
|
/** Command name (e.g. `ping`). */
|
|
@@ -3531,6 +3632,11 @@ var Client = class extends EventEmitter3 {
|
|
|
3531
3632
|
_pendingGuildIds = null;
|
|
3532
3633
|
/** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
|
|
3533
3634
|
_guildStreamSettleTimeout = null;
|
|
3635
|
+
/**
|
|
3636
|
+
* When waitForGuilds delays Ready, gateway dispatches (except GUILD_CREATE) are queued and replayed after Ready.
|
|
3637
|
+
* Ensures user handlers that assume post-Ready setup (e.g. DB in Ready) do not run during the guild sync window.
|
|
3638
|
+
*/
|
|
3639
|
+
_deferredGatewayDispatches = [];
|
|
3534
3640
|
/** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
|
|
3535
3641
|
_messageCaches = null;
|
|
3536
3642
|
on(event, listener) {
|
|
@@ -3728,13 +3834,32 @@ var Client = class extends EventEmitter3 {
|
|
|
3728
3834
|
sendToGateway(shardId, payload) {
|
|
3729
3835
|
this.ws.send(shardId, payload);
|
|
3730
3836
|
}
|
|
3837
|
+
/**
|
|
3838
|
+
* While {@link ClientOptions.waitForGuilds} delays Ready, defer user-facing dispatch handling until Ready fires.
|
|
3839
|
+
* GUILD_CREATE must still run immediately so guild cache and {@link Client._onGuildReceived} can finish the handshake.
|
|
3840
|
+
*/
|
|
3841
|
+
_shouldDeferGatewayDispatchUntilReady(payload) {
|
|
3842
|
+
if (this.options.waitForGuilds !== true || this.readyAt !== null) return false;
|
|
3843
|
+
if (payload.op !== 0 || !payload.t) return false;
|
|
3844
|
+
if (payload.t === "GUILD_CREATE") return false;
|
|
3845
|
+
return true;
|
|
3846
|
+
}
|
|
3731
3847
|
/**
|
|
3732
3848
|
* Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
|
|
3733
3849
|
* macrotask so user code does not block the WebSocket `message` callback.
|
|
3734
3850
|
*/
|
|
3735
3851
|
handleDispatch(payload) {
|
|
3736
3852
|
if (payload.op !== 0 || !payload.t) return Promise.resolve();
|
|
3737
|
-
|
|
3853
|
+
if (this._shouldDeferGatewayDispatchUntilReady(payload)) {
|
|
3854
|
+
this._deferredGatewayDispatches.push(payload);
|
|
3855
|
+
return Promise.resolve();
|
|
3856
|
+
}
|
|
3857
|
+
return this._dispatchGatewayPayload(payload);
|
|
3858
|
+
}
|
|
3859
|
+
_dispatchGatewayPayload(payload) {
|
|
3860
|
+
const event = payload.t;
|
|
3861
|
+
if (!event) return Promise.resolve();
|
|
3862
|
+
const { d } = payload;
|
|
3738
3863
|
const handler = eventHandlers.get(event);
|
|
3739
3864
|
if (!handler) return Promise.resolve();
|
|
3740
3865
|
const run = async () => {
|
|
@@ -3758,6 +3883,15 @@ var Client = class extends EventEmitter3 {
|
|
|
3758
3883
|
}
|
|
3759
3884
|
});
|
|
3760
3885
|
}
|
|
3886
|
+
async _flushDeferredGatewayDispatches() {
|
|
3887
|
+
while (this._deferredGatewayDispatches.length > 0) {
|
|
3888
|
+
const batch = this._deferredGatewayDispatches;
|
|
3889
|
+
this._deferredGatewayDispatches = [];
|
|
3890
|
+
for (const p of batch) {
|
|
3891
|
+
await this._dispatchGatewayPayload(p);
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3761
3895
|
/**
|
|
3762
3896
|
* Connect to the Fluxer gateway and authenticate.
|
|
3763
3897
|
* @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
|
|
@@ -3856,6 +3990,9 @@ var Client = class extends EventEmitter3 {
|
|
|
3856
3990
|
this._pendingGuildIds = null;
|
|
3857
3991
|
this.readyAt = /* @__PURE__ */ new Date();
|
|
3858
3992
|
this.emit(Events.Ready);
|
|
3993
|
+
void this._flushDeferredGatewayDispatches().catch(
|
|
3994
|
+
(err) => this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)))
|
|
3995
|
+
);
|
|
3859
3996
|
}
|
|
3860
3997
|
/**
|
|
3861
3998
|
* Called by GUILD_CREATE handler when waitForGuilds is enabled.
|
|
@@ -3873,6 +4010,7 @@ var Client = class extends EventEmitter3 {
|
|
|
3873
4010
|
clearTimeout(this._guildStreamSettleTimeout);
|
|
3874
4011
|
this._guildStreamSettleTimeout = null;
|
|
3875
4012
|
}
|
|
4013
|
+
this._deferredGatewayDispatches = [];
|
|
3876
4014
|
if (this._ws) {
|
|
3877
4015
|
this._ws.destroy();
|
|
3878
4016
|
this._ws = null;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { A as AnyInteraction, B as Base,
|
|
1
|
+
export { A as AllowedMentions, a as AllowedMentionsOptions, b as AnyInteraction, B as Base, c as BaseInteraction, C as CacheSizeLimits, d as CategoryChannel, e as Channel, f as ChannelManager, g as ChatInputCommandInteraction, h as Client, i as ClientEventMethods, j as ClientEvents, k as ClientOptions, l as ClientUser, m as CollectedReaction, D as DMChannel, E as Events, F as FetchMessagesOptions, n as FetchedUserWithProfile, G as Guild, o as GuildBan, p as GuildChannel, q as GuildEmoji, r as GuildMember, s as GuildMemberManager, t as GuildMemberRoleManager, u as GuildSticker, I as Invite, L as LinkChannel, M as Message, v as MessageCollector, w as MessageCollectorEndReason, x as MessageCollectorOptions, y as MessageEditOptions, z as MessageManager, H as MessageReaction, J as MessageReplyTarget, K as MessageSendOptions, P as PartialMessage, R as ReactionCollector, N as ReactionCollectorEndReason, O as ReactionCollectorOptions, Q as ReplyOptions, S as Role, T as RoleResolvable, U as TextChannel, V as User, W as UsersManager, X as VoiceChannel, Y as Webhook, Z as WebhookMessageEditOptions, _ as WebhookSendOptions, $ as createInteraction, a0 as isChatInputCommandInteraction } from './subpath-message-DSs_mdc4.mjs';
|
|
2
2
|
export { ErrorCodes, FluxerError, FluxerErrorOptions, PermissionFlags, PermissionResolvable, PermissionString, PermissionsBitField, UserFlagsBitField, UserFlagsBits, UserFlagsResolvable, UserFlagsString, parsePrefixCommand, parseUserMention, resolvePermissionsToBitfield, resolveTenorToImageUrl } from '@fluxerjs/util';
|
|
3
3
|
export { AttachmentBuilder, EmbedBuilder, MessagePayload } from '@fluxerjs/builders';
|
|
4
|
-
export { GatewayOpcodes, MessageAttachmentFlags, Routes } from '@fluxerjs/types';
|
|
4
|
+
export { APIAllowedMentions, APIChannelSlowmodeState, APIGuildMemberSearchRequest, APIGuildMemberSearchResponse, APIRtcRegion, AllowedMentionType, GatewayOpcodes, MessageAttachmentFlags, MessageFlags, Routes } from '@fluxerjs/types';
|
|
5
5
|
import 'events';
|
|
6
6
|
import '@fluxerjs/rest';
|
|
7
7
|
import '@fluxerjs/ws';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { A as AnyInteraction, B as Base,
|
|
1
|
+
export { A as AllowedMentions, a as AllowedMentionsOptions, b as AnyInteraction, B as Base, c as BaseInteraction, C as CacheSizeLimits, d as CategoryChannel, e as Channel, f as ChannelManager, g as ChatInputCommandInteraction, h as Client, i as ClientEventMethods, j as ClientEvents, k as ClientOptions, l as ClientUser, m as CollectedReaction, D as DMChannel, E as Events, F as FetchMessagesOptions, n as FetchedUserWithProfile, G as Guild, o as GuildBan, p as GuildChannel, q as GuildEmoji, r as GuildMember, s as GuildMemberManager, t as GuildMemberRoleManager, u as GuildSticker, I as Invite, L as LinkChannel, M as Message, v as MessageCollector, w as MessageCollectorEndReason, x as MessageCollectorOptions, y as MessageEditOptions, z as MessageManager, H as MessageReaction, J as MessageReplyTarget, K as MessageSendOptions, P as PartialMessage, R as ReactionCollector, N as ReactionCollectorEndReason, O as ReactionCollectorOptions, Q as ReplyOptions, S as Role, T as RoleResolvable, U as TextChannel, V as User, W as UsersManager, X as VoiceChannel, Y as Webhook, Z as WebhookMessageEditOptions, _ as WebhookSendOptions, $ as createInteraction, a0 as isChatInputCommandInteraction } from './subpath-message-DSs_mdc4.js';
|
|
2
2
|
export { ErrorCodes, FluxerError, FluxerErrorOptions, PermissionFlags, PermissionResolvable, PermissionString, PermissionsBitField, UserFlagsBitField, UserFlagsBits, UserFlagsResolvable, UserFlagsString, parsePrefixCommand, parseUserMention, resolvePermissionsToBitfield, resolveTenorToImageUrl } from '@fluxerjs/util';
|
|
3
3
|
export { AttachmentBuilder, EmbedBuilder, MessagePayload } from '@fluxerjs/builders';
|
|
4
|
-
export { GatewayOpcodes, MessageAttachmentFlags, Routes } from '@fluxerjs/types';
|
|
4
|
+
export { APIAllowedMentions, APIChannelSlowmodeState, APIGuildMemberSearchRequest, APIGuildMemberSearchResponse, APIRtcRegion, AllowedMentionType, GatewayOpcodes, MessageAttachmentFlags, MessageFlags, Routes } from '@fluxerjs/types';
|
|
5
5
|
import 'events';
|
|
6
6
|
import '@fluxerjs/rest';
|
|
7
7
|
import '@fluxerjs/ws';
|