@fluxerjs/core 1.1.0 → 1.1.2
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/LICENSE +203 -0
- package/dist/{Channel-WJZZSNML.mjs → Channel-YB3LWDHZ.mjs} +2 -1
- package/dist/{ClientUser-DJO2FS7P.mjs → ClientUser-QQXLZ5WP.mjs} +1 -1
- package/dist/{Guild-2P77HBQM.mjs → Guild-MDW7KF33.mjs} +3 -2
- package/dist/{MessageReaction-V4UZ7OXE.mjs → MessageReaction-GYQNJ6GX.mjs} +2 -1
- package/dist/{Role-5MWSGL66.mjs → Role-N2ZEMRUQ.mjs} +1 -1
- package/dist/chunk-5I54OXBG.mjs +111 -0
- package/dist/{chunk-JHNKZIHY.mjs → chunk-G2YVDCRB.mjs} +2 -2
- package/dist/{chunk-4XJIM6SC.mjs → chunk-KOTF4TTZ.mjs} +117 -29
- package/dist/chunk-PU73YRKJ.mjs +27 -0
- package/dist/{chunk-CEABHTAF.mjs → chunk-YL5S4W6R.mjs} +22 -1
- package/dist/{chunk-LU2SNC5G.mjs → chunk-ZKKBIQBA.mjs} +33 -12
- package/dist/index.d.mts +134 -6
- package/dist/index.d.ts +134 -6
- package/dist/index.js +548 -254
- package/dist/index.mjs +130 -38
- package/package.json +8 -8
- package/dist/chunk-DQ4TNBPG.mjs +0 -63
package/dist/index.js
CHANGED
|
@@ -49,7 +49,8 @@ var init_ErrorCodes = __esm({
|
|
|
49
49
|
ChannelNotFound: "CHANNEL_NOT_FOUND",
|
|
50
50
|
MessageNotFound: "MESSAGE_NOT_FOUND",
|
|
51
51
|
GuildNotFound: "GUILD_NOT_FOUND",
|
|
52
|
-
MemberNotFound: "MEMBER_NOT_FOUND"
|
|
52
|
+
MemberNotFound: "MEMBER_NOT_FOUND",
|
|
53
|
+
RoleNotFound: "ROLE_NOT_FOUND"
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
});
|
|
@@ -86,25 +87,12 @@ var init_messageUtils = __esm({
|
|
|
86
87
|
}
|
|
87
88
|
});
|
|
88
89
|
|
|
89
|
-
// src/
|
|
90
|
-
var
|
|
91
|
-
var
|
|
92
|
-
"src/
|
|
90
|
+
// src/structures/Base.ts
|
|
91
|
+
var Base;
|
|
92
|
+
var init_Base = __esm({
|
|
93
|
+
"src/structures/Base.ts"() {
|
|
93
94
|
"use strict";
|
|
94
|
-
|
|
95
|
-
constructor(client, channelId) {
|
|
96
|
-
this.client = client;
|
|
97
|
-
this.channelId = channelId;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Fetch a message by ID from this channel.
|
|
101
|
-
* @param messageId - Snowflake of the message
|
|
102
|
-
* @returns The message
|
|
103
|
-
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
104
|
-
*/
|
|
105
|
-
async fetch(messageId) {
|
|
106
|
-
return this.client.channels.fetchMessage(this.channelId, messageId);
|
|
107
|
-
}
|
|
95
|
+
Base = class {
|
|
108
96
|
};
|
|
109
97
|
}
|
|
110
98
|
});
|
|
@@ -162,145 +150,20 @@ var init_Events = __esm({
|
|
|
162
150
|
}
|
|
163
151
|
});
|
|
164
152
|
|
|
165
|
-
// src/util/MessageCollector.ts
|
|
166
|
-
var import_events, import_collection, MessageCollector;
|
|
167
|
-
var init_MessageCollector = __esm({
|
|
168
|
-
"src/util/MessageCollector.ts"() {
|
|
169
|
-
"use strict";
|
|
170
|
-
import_events = require("events");
|
|
171
|
-
import_collection = require("@fluxerjs/collection");
|
|
172
|
-
init_Events();
|
|
173
|
-
MessageCollector = class extends import_events.EventEmitter {
|
|
174
|
-
client;
|
|
175
|
-
channelId;
|
|
176
|
-
options;
|
|
177
|
-
collected = new import_collection.Collection();
|
|
178
|
-
_timeout = null;
|
|
179
|
-
_ended = false;
|
|
180
|
-
_listener;
|
|
181
|
-
constructor(client, channelId, options = {}) {
|
|
182
|
-
super();
|
|
183
|
-
this.client = client;
|
|
184
|
-
this.channelId = channelId;
|
|
185
|
-
this.options = {
|
|
186
|
-
filter: options.filter ?? (() => true),
|
|
187
|
-
time: options.time ?? 0,
|
|
188
|
-
max: options.max ?? 0
|
|
189
|
-
};
|
|
190
|
-
this._listener = (message) => {
|
|
191
|
-
if (this._ended || message.channelId !== this.channelId) return;
|
|
192
|
-
if (!this.options.filter(message)) return;
|
|
193
|
-
this.collected.set(message.id, message);
|
|
194
|
-
this.emit("collect", message);
|
|
195
|
-
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
196
|
-
this.stop("limit");
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
this.client.on(Events.MessageCreate, this._listener);
|
|
200
|
-
if (this.options.time > 0) {
|
|
201
|
-
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
stop(reason = "user") {
|
|
205
|
-
if (this._ended) return;
|
|
206
|
-
this._ended = true;
|
|
207
|
-
this.client.off(Events.MessageCreate, this._listener);
|
|
208
|
-
if (this._timeout) {
|
|
209
|
-
clearTimeout(this._timeout);
|
|
210
|
-
this._timeout = null;
|
|
211
|
-
}
|
|
212
|
-
this.emit("end", this.collected, reason);
|
|
213
|
-
}
|
|
214
|
-
on(event, listener) {
|
|
215
|
-
return super.on(event, listener);
|
|
216
|
-
}
|
|
217
|
-
emit(event, ...args) {
|
|
218
|
-
return super.emit(event, ...args);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
// src/structures/Base.ts
|
|
225
|
-
var Base;
|
|
226
|
-
var init_Base = __esm({
|
|
227
|
-
"src/structures/Base.ts"() {
|
|
228
|
-
"use strict";
|
|
229
|
-
Base = class {
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// src/util/Constants.ts
|
|
235
|
-
var CDN_URL;
|
|
236
|
-
var init_Constants = __esm({
|
|
237
|
-
"src/util/Constants.ts"() {
|
|
238
|
-
"use strict";
|
|
239
|
-
CDN_URL = "https://fluxerusercontent.com";
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// src/util/cdn.ts
|
|
244
|
-
function getExtension(hash, options) {
|
|
245
|
-
const ext = options?.extension ?? "png";
|
|
246
|
-
if (hash?.startsWith("a_")) return "gif";
|
|
247
|
-
return ext;
|
|
248
|
-
}
|
|
249
|
-
function appendSize(options) {
|
|
250
|
-
return options?.size ? `?size=${options.size}` : "";
|
|
251
|
-
}
|
|
252
|
-
function cdnAvatarURL(userId, avatarHash, options) {
|
|
253
|
-
if (!avatarHash) return null;
|
|
254
|
-
const ext = getExtension(avatarHash, options);
|
|
255
|
-
const size = appendSize(options);
|
|
256
|
-
return `${CDN_URL}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
257
|
-
}
|
|
258
|
-
function cdnDisplayAvatarURL(userId, avatarHash, options) {
|
|
259
|
-
return cdnAvatarURL(userId, avatarHash, options) ?? `${CDN_URL}/avatars/0/0.png`;
|
|
260
|
-
}
|
|
261
|
-
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
262
|
-
if (!bannerHash) return null;
|
|
263
|
-
const ext = getExtension(bannerHash, options);
|
|
264
|
-
const size = appendSize(options);
|
|
265
|
-
return `${CDN_URL}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
266
|
-
}
|
|
267
|
-
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
268
|
-
if (!avatarHash) return null;
|
|
269
|
-
const ext = getExtension(avatarHash, options);
|
|
270
|
-
const size = appendSize(options);
|
|
271
|
-
return `${CDN_URL}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
272
|
-
}
|
|
273
|
-
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
274
|
-
if (!bannerHash) return null;
|
|
275
|
-
const ext = getExtension(bannerHash, options);
|
|
276
|
-
const size = appendSize(options);
|
|
277
|
-
return `${CDN_URL}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
278
|
-
}
|
|
279
|
-
function cdnDefaultAvatarURL(discriminatorIndex) {
|
|
280
|
-
const index = discriminatorIndex != null ? discriminatorIndex % 5 : 0;
|
|
281
|
-
return `${CDN_URL}/avatars/0/${index}.png`;
|
|
282
|
-
}
|
|
283
|
-
var init_cdn = __esm({
|
|
284
|
-
"src/util/cdn.ts"() {
|
|
285
|
-
"use strict";
|
|
286
|
-
init_Constants();
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
|
|
290
153
|
// src/util/ReactionCollector.ts
|
|
291
|
-
var
|
|
154
|
+
var import_events, import_collection, ReactionCollector;
|
|
292
155
|
var init_ReactionCollector = __esm({
|
|
293
156
|
"src/util/ReactionCollector.ts"() {
|
|
294
157
|
"use strict";
|
|
295
|
-
|
|
296
|
-
|
|
158
|
+
import_events = require("events");
|
|
159
|
+
import_collection = require("@fluxerjs/collection");
|
|
297
160
|
init_Events();
|
|
298
|
-
ReactionCollector = class extends
|
|
161
|
+
ReactionCollector = class extends import_events.EventEmitter {
|
|
299
162
|
client;
|
|
300
163
|
messageId;
|
|
301
164
|
channelId;
|
|
302
165
|
options;
|
|
303
|
-
collected = new
|
|
166
|
+
collected = new import_collection.Collection();
|
|
304
167
|
_timeout = null;
|
|
305
168
|
_ended = false;
|
|
306
169
|
_listener;
|
|
@@ -354,12 +217,12 @@ var Message_exports = {};
|
|
|
354
217
|
__export(Message_exports, {
|
|
355
218
|
Message: () => Message
|
|
356
219
|
});
|
|
357
|
-
var
|
|
220
|
+
var import_collection2, import_types, import_builders2, Message;
|
|
358
221
|
var init_Message = __esm({
|
|
359
222
|
"src/structures/Message.ts"() {
|
|
360
223
|
"use strict";
|
|
361
224
|
init_Base();
|
|
362
|
-
|
|
225
|
+
import_collection2 = require("@fluxerjs/collection");
|
|
363
226
|
import_types = require("@fluxerjs/types");
|
|
364
227
|
import_builders2 = require("@fluxerjs/builders");
|
|
365
228
|
init_messageUtils();
|
|
@@ -414,7 +277,7 @@ var init_Message = __esm({
|
|
|
414
277
|
this.createdAt = new Date(data.timestamp);
|
|
415
278
|
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
416
279
|
this.pinned = data.pinned;
|
|
417
|
-
this.attachments = new
|
|
280
|
+
this.attachments = new import_collection2.Collection();
|
|
418
281
|
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
419
282
|
this.type = data.type ?? import_types.MessageType.Default;
|
|
420
283
|
this.flags = data.flags ?? 0;
|
|
@@ -596,17 +459,174 @@ var init_Message = __esm({
|
|
|
596
459
|
}
|
|
597
460
|
});
|
|
598
461
|
|
|
462
|
+
// src/client/MessageManager.ts
|
|
463
|
+
var import_types2, import_rest, MessageManager;
|
|
464
|
+
var init_MessageManager = __esm({
|
|
465
|
+
"src/client/MessageManager.ts"() {
|
|
466
|
+
"use strict";
|
|
467
|
+
import_types2 = require("@fluxerjs/types");
|
|
468
|
+
import_rest = require("@fluxerjs/rest");
|
|
469
|
+
init_FluxerError();
|
|
470
|
+
init_ErrorCodes();
|
|
471
|
+
MessageManager = class {
|
|
472
|
+
constructor(client, channelId) {
|
|
473
|
+
this.client = client;
|
|
474
|
+
this.channelId = channelId;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Fetch a message by ID from this channel.
|
|
478
|
+
* @param messageId - Snowflake of the message
|
|
479
|
+
* @returns The message
|
|
480
|
+
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
481
|
+
*/
|
|
482
|
+
async fetch(messageId) {
|
|
483
|
+
try {
|
|
484
|
+
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
485
|
+
const data = await this.client.rest.get(
|
|
486
|
+
import_types2.Routes.channelMessage(this.channelId, messageId)
|
|
487
|
+
);
|
|
488
|
+
return new Message2(this.client, data);
|
|
489
|
+
} catch (err) {
|
|
490
|
+
if (err instanceof import_rest.RateLimitError) throw err;
|
|
491
|
+
if (err instanceof import_rest.FluxerAPIError && err.statusCode === 404) {
|
|
492
|
+
throw new FluxerError(`Message ${messageId} not found in channel ${this.channelId}`, {
|
|
493
|
+
code: ErrorCodes.MessageNotFound,
|
|
494
|
+
cause: err
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// src/util/MessageCollector.ts
|
|
505
|
+
var import_events2, import_collection3, MessageCollector;
|
|
506
|
+
var init_MessageCollector = __esm({
|
|
507
|
+
"src/util/MessageCollector.ts"() {
|
|
508
|
+
"use strict";
|
|
509
|
+
import_events2 = require("events");
|
|
510
|
+
import_collection3 = require("@fluxerjs/collection");
|
|
511
|
+
init_Events();
|
|
512
|
+
MessageCollector = class extends import_events2.EventEmitter {
|
|
513
|
+
client;
|
|
514
|
+
channelId;
|
|
515
|
+
options;
|
|
516
|
+
collected = new import_collection3.Collection();
|
|
517
|
+
_timeout = null;
|
|
518
|
+
_ended = false;
|
|
519
|
+
_listener;
|
|
520
|
+
constructor(client, channelId, options = {}) {
|
|
521
|
+
super();
|
|
522
|
+
this.client = client;
|
|
523
|
+
this.channelId = channelId;
|
|
524
|
+
this.options = {
|
|
525
|
+
filter: options.filter ?? (() => true),
|
|
526
|
+
time: options.time ?? 0,
|
|
527
|
+
max: options.max ?? 0
|
|
528
|
+
};
|
|
529
|
+
this._listener = (message) => {
|
|
530
|
+
if (this._ended || message.channelId !== this.channelId) return;
|
|
531
|
+
if (!this.options.filter(message)) return;
|
|
532
|
+
this.collected.set(message.id, message);
|
|
533
|
+
this.emit("collect", message);
|
|
534
|
+
if (this.options.max > 0 && this.collected.size >= this.options.max) {
|
|
535
|
+
this.stop("limit");
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
this.client.on(Events.MessageCreate, this._listener);
|
|
539
|
+
if (this.options.time > 0) {
|
|
540
|
+
this._timeout = setTimeout(() => this.stop("time"), this.options.time);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
stop(reason = "user") {
|
|
544
|
+
if (this._ended) return;
|
|
545
|
+
this._ended = true;
|
|
546
|
+
this.client.off(Events.MessageCreate, this._listener);
|
|
547
|
+
if (this._timeout) {
|
|
548
|
+
clearTimeout(this._timeout);
|
|
549
|
+
this._timeout = null;
|
|
550
|
+
}
|
|
551
|
+
this.emit("end", this.collected, reason);
|
|
552
|
+
}
|
|
553
|
+
on(event, listener) {
|
|
554
|
+
return super.on(event, listener);
|
|
555
|
+
}
|
|
556
|
+
emit(event, ...args) {
|
|
557
|
+
return super.emit(event, ...args);
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
// src/util/Constants.ts
|
|
564
|
+
var CDN_URL;
|
|
565
|
+
var init_Constants = __esm({
|
|
566
|
+
"src/util/Constants.ts"() {
|
|
567
|
+
"use strict";
|
|
568
|
+
CDN_URL = "https://fluxerusercontent.com";
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
// src/util/cdn.ts
|
|
573
|
+
function getExtension(hash, options) {
|
|
574
|
+
const ext = options?.extension ?? "png";
|
|
575
|
+
if (hash?.startsWith("a_")) return "gif";
|
|
576
|
+
return ext;
|
|
577
|
+
}
|
|
578
|
+
function appendSize(options) {
|
|
579
|
+
return options?.size ? `?size=${options.size}` : "";
|
|
580
|
+
}
|
|
581
|
+
function cdnAvatarURL(userId, avatarHash, options) {
|
|
582
|
+
if (!avatarHash) return null;
|
|
583
|
+
const ext = getExtension(avatarHash, options);
|
|
584
|
+
const size = appendSize(options);
|
|
585
|
+
return `${CDN_URL}/avatars/${userId}/${avatarHash}.${ext}${size}`;
|
|
586
|
+
}
|
|
587
|
+
function cdnDisplayAvatarURL(userId, avatarHash, options) {
|
|
588
|
+
return cdnAvatarURL(userId, avatarHash, options) ?? `${CDN_URL}/avatars/0/0.png`;
|
|
589
|
+
}
|
|
590
|
+
function cdnBannerURL(resourceId, bannerHash, options) {
|
|
591
|
+
if (!bannerHash) return null;
|
|
592
|
+
const ext = getExtension(bannerHash, options);
|
|
593
|
+
const size = appendSize(options);
|
|
594
|
+
return `${CDN_URL}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
|
|
595
|
+
}
|
|
596
|
+
function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
|
|
597
|
+
if (!avatarHash) return null;
|
|
598
|
+
const ext = getExtension(avatarHash, options);
|
|
599
|
+
const size = appendSize(options);
|
|
600
|
+
return `${CDN_URL}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
|
|
601
|
+
}
|
|
602
|
+
function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
|
|
603
|
+
if (!bannerHash) return null;
|
|
604
|
+
const ext = getExtension(bannerHash, options);
|
|
605
|
+
const size = appendSize(options);
|
|
606
|
+
return `${CDN_URL}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
|
|
607
|
+
}
|
|
608
|
+
function cdnDefaultAvatarURL(discriminatorIndex) {
|
|
609
|
+
const index = discriminatorIndex != null ? discriminatorIndex % 5 : 0;
|
|
610
|
+
return `${CDN_URL}/avatars/0/${index}.png`;
|
|
611
|
+
}
|
|
612
|
+
var init_cdn = __esm({
|
|
613
|
+
"src/util/cdn.ts"() {
|
|
614
|
+
"use strict";
|
|
615
|
+
init_Constants();
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
|
|
599
619
|
// src/structures/Webhook.ts
|
|
600
620
|
var Webhook_exports = {};
|
|
601
621
|
__export(Webhook_exports, {
|
|
602
622
|
Webhook: () => Webhook
|
|
603
623
|
});
|
|
604
|
-
var
|
|
624
|
+
var import_types3, Webhook;
|
|
605
625
|
var init_Webhook = __esm({
|
|
606
626
|
"src/structures/Webhook.ts"() {
|
|
607
627
|
"use strict";
|
|
608
628
|
init_Base();
|
|
609
|
-
|
|
629
|
+
import_types3 = require("@fluxerjs/types");
|
|
610
630
|
init_messageUtils();
|
|
611
631
|
init_cdn();
|
|
612
632
|
Webhook = class _Webhook extends Base {
|
|
@@ -641,7 +661,7 @@ var init_Webhook = __esm({
|
|
|
641
661
|
}
|
|
642
662
|
/** Delete this webhook. Requires bot token with Manage Webhooks permission. */
|
|
643
663
|
async delete() {
|
|
644
|
-
await this.client.rest.delete(
|
|
664
|
+
await this.client.rest.delete(import_types3.Routes.webhook(this.id), { auth: true });
|
|
645
665
|
}
|
|
646
666
|
/**
|
|
647
667
|
* Edit this webhook. With token: name and avatar only. Without token (bot auth): name, avatar, and channel_id.
|
|
@@ -656,7 +676,7 @@ var init_Webhook = __esm({
|
|
|
656
676
|
body.channel_id = options.channel_id;
|
|
657
677
|
}
|
|
658
678
|
if (this.token) {
|
|
659
|
-
const data2 = await this.client.rest.patch(
|
|
679
|
+
const data2 = await this.client.rest.patch(import_types3.Routes.webhookExecute(this.id, this.token), {
|
|
660
680
|
body,
|
|
661
681
|
auth: false
|
|
662
682
|
});
|
|
@@ -665,7 +685,7 @@ var init_Webhook = __esm({
|
|
|
665
685
|
this.avatar = w2.avatar ?? null;
|
|
666
686
|
return this;
|
|
667
687
|
}
|
|
668
|
-
const data = await this.client.rest.patch(
|
|
688
|
+
const data = await this.client.rest.patch(import_types3.Routes.webhook(this.id), {
|
|
669
689
|
body,
|
|
670
690
|
auth: true
|
|
671
691
|
});
|
|
@@ -697,7 +717,7 @@ var init_Webhook = __esm({
|
|
|
697
717
|
if (opts.username !== void 0) body.username = opts.username;
|
|
698
718
|
if (opts.avatar_url !== void 0) body.avatar_url = opts.avatar_url;
|
|
699
719
|
if (opts.tts !== void 0) body.tts = opts.tts;
|
|
700
|
-
const route =
|
|
720
|
+
const route = import_types3.Routes.webhookExecute(this.id, this.token) + (wait ? "?wait=true" : "");
|
|
701
721
|
const postOptions = opts.files?.length ? { body, files: opts.files, auth: false } : { body, auth: false };
|
|
702
722
|
const data = await this.client.rest.post(
|
|
703
723
|
route,
|
|
@@ -716,7 +736,7 @@ var init_Webhook = __esm({
|
|
|
716
736
|
* @returns Webhook without token (cannot send)
|
|
717
737
|
*/
|
|
718
738
|
static async fetch(client, webhookId) {
|
|
719
|
-
const data = await client.rest.get(
|
|
739
|
+
const data = await client.rest.get(import_types3.Routes.webhook(webhookId));
|
|
720
740
|
return new _Webhook(client, data);
|
|
721
741
|
}
|
|
722
742
|
/**
|
|
@@ -746,12 +766,12 @@ var Invite_exports = {};
|
|
|
746
766
|
__export(Invite_exports, {
|
|
747
767
|
Invite: () => Invite
|
|
748
768
|
});
|
|
749
|
-
var
|
|
769
|
+
var import_types4, Invite;
|
|
750
770
|
var init_Invite = __esm({
|
|
751
771
|
"src/structures/Invite.ts"() {
|
|
752
772
|
"use strict";
|
|
753
773
|
init_Base();
|
|
754
|
-
|
|
774
|
+
import_types4 = require("@fluxerjs/types");
|
|
755
775
|
Invite = class extends Base {
|
|
756
776
|
client;
|
|
757
777
|
code;
|
|
@@ -801,7 +821,7 @@ var init_Invite = __esm({
|
|
|
801
821
|
* Requires Manage Guild or Create Instant Invite permission.
|
|
802
822
|
*/
|
|
803
823
|
async delete() {
|
|
804
|
-
await this.client.rest.delete(
|
|
824
|
+
await this.client.rest.delete(import_types4.Routes.invite(this.code), { auth: true });
|
|
805
825
|
}
|
|
806
826
|
};
|
|
807
827
|
}
|
|
@@ -818,7 +838,7 @@ __export(Channel_exports, {
|
|
|
818
838
|
TextChannel: () => TextChannel,
|
|
819
839
|
VoiceChannel: () => VoiceChannel
|
|
820
840
|
});
|
|
821
|
-
var
|
|
841
|
+
var import_types5, import_util, Channel, GuildChannel, TextChannel, CategoryChannel, VoiceChannel, LinkChannel, DMChannel;
|
|
822
842
|
var init_Channel = __esm({
|
|
823
843
|
"src/structures/Channel.ts"() {
|
|
824
844
|
"use strict";
|
|
@@ -826,7 +846,7 @@ var init_Channel = __esm({
|
|
|
826
846
|
init_MessageCollector();
|
|
827
847
|
init_Base();
|
|
828
848
|
init_messageUtils();
|
|
829
|
-
|
|
849
|
+
import_types5 = require("@fluxerjs/types");
|
|
830
850
|
import_util = require("@fluxerjs/util");
|
|
831
851
|
Channel = class _Channel extends Base {
|
|
832
852
|
/** Whether this channel has a send method (TextChannel, DMChannel). */
|
|
@@ -835,7 +855,7 @@ var init_Channel = __esm({
|
|
|
835
855
|
}
|
|
836
856
|
/** Whether this channel is a DM or Group DM. */
|
|
837
857
|
isDM() {
|
|
838
|
-
return this.type ===
|
|
858
|
+
return this.type === import_types5.ChannelType.DM || this.type === import_types5.ChannelType.GroupDM;
|
|
839
859
|
}
|
|
840
860
|
/** Whether this channel is voice-based (VoiceChannel). */
|
|
841
861
|
isVoice() {
|
|
@@ -871,10 +891,10 @@ var init_Channel = __esm({
|
|
|
871
891
|
*/
|
|
872
892
|
static from(client, data) {
|
|
873
893
|
const type = data.type ?? 0;
|
|
874
|
-
if (type ===
|
|
875
|
-
if (type ===
|
|
876
|
-
if (type ===
|
|
877
|
-
if (type ===
|
|
894
|
+
if (type === import_types5.ChannelType.GuildText) return new TextChannel(client, data);
|
|
895
|
+
if (type === import_types5.ChannelType.GuildCategory) return new CategoryChannel(client, data);
|
|
896
|
+
if (type === import_types5.ChannelType.GuildVoice) return new VoiceChannel(client, data);
|
|
897
|
+
if (type === import_types5.ChannelType.GuildLink || type === import_types5.ChannelType.GuildLinkExtended)
|
|
878
898
|
return new LinkChannel(client, data);
|
|
879
899
|
return new GuildChannel(client, data);
|
|
880
900
|
}
|
|
@@ -884,7 +904,7 @@ var init_Channel = __esm({
|
|
|
884
904
|
*/
|
|
885
905
|
static fromOrCreate(client, data) {
|
|
886
906
|
const type = data.type ?? 0;
|
|
887
|
-
if (type ===
|
|
907
|
+
if (type === import_types5.ChannelType.DM || type === import_types5.ChannelType.GroupDM)
|
|
888
908
|
return _Channel.createDM(client, data);
|
|
889
909
|
return _Channel.from(client, data);
|
|
890
910
|
}
|
|
@@ -893,7 +913,7 @@ var init_Channel = __esm({
|
|
|
893
913
|
* @param messageIds - Array of message IDs to delete (2–100)
|
|
894
914
|
*/
|
|
895
915
|
async bulkDeleteMessages(messageIds) {
|
|
896
|
-
await this.client.rest.post(
|
|
916
|
+
await this.client.rest.post(import_types5.Routes.channelBulkDelete(this.id), {
|
|
897
917
|
body: { message_ids: messageIds },
|
|
898
918
|
auth: true
|
|
899
919
|
});
|
|
@@ -902,7 +922,7 @@ var init_Channel = __esm({
|
|
|
902
922
|
* Send a typing indicator to the channel. Lasts ~10 seconds.
|
|
903
923
|
*/
|
|
904
924
|
async sendTyping() {
|
|
905
|
-
await this.client.rest.post(
|
|
925
|
+
await this.client.rest.post(import_types5.Routes.channelTyping(this.id), { auth: true });
|
|
906
926
|
}
|
|
907
927
|
};
|
|
908
928
|
GuildChannel = class extends Channel {
|
|
@@ -927,7 +947,7 @@ var init_Channel = __esm({
|
|
|
927
947
|
*/
|
|
928
948
|
async createWebhook(options) {
|
|
929
949
|
const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
|
|
930
|
-
const data = await this.client.rest.post(
|
|
950
|
+
const data = await this.client.rest.post(import_types5.Routes.channelWebhooks(this.id), {
|
|
931
951
|
body: options,
|
|
932
952
|
auth: true
|
|
933
953
|
});
|
|
@@ -939,7 +959,7 @@ var init_Channel = __esm({
|
|
|
939
959
|
*/
|
|
940
960
|
async fetchWebhooks() {
|
|
941
961
|
const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
|
|
942
|
-
const data = await this.client.rest.get(
|
|
962
|
+
const data = await this.client.rest.get(import_types5.Routes.channelWebhooks(this.id));
|
|
943
963
|
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
944
964
|
return list.map((w) => new Webhook2(this.client, w));
|
|
945
965
|
}
|
|
@@ -955,7 +975,7 @@ var init_Channel = __esm({
|
|
|
955
975
|
if (options?.max_age != null) body.max_age = options.max_age;
|
|
956
976
|
if (options?.unique != null) body.unique = options.unique;
|
|
957
977
|
if (options?.temporary != null) body.temporary = options.temporary;
|
|
958
|
-
const data = await this.client.rest.post(
|
|
978
|
+
const data = await this.client.rest.post(import_types5.Routes.channelInvites(this.id), {
|
|
959
979
|
body: Object.keys(body).length ? body : void 0,
|
|
960
980
|
auth: true
|
|
961
981
|
});
|
|
@@ -967,7 +987,7 @@ var init_Channel = __esm({
|
|
|
967
987
|
*/
|
|
968
988
|
async fetchInvites() {
|
|
969
989
|
const { Invite: Invite2 } = await Promise.resolve().then(() => (init_Invite(), Invite_exports));
|
|
970
|
-
const data = await this.client.rest.get(
|
|
990
|
+
const data = await this.client.rest.get(import_types5.Routes.channelInvites(this.id));
|
|
971
991
|
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
972
992
|
return list.map((i) => new Invite2(this.client, i));
|
|
973
993
|
}
|
|
@@ -993,7 +1013,7 @@ var init_Channel = __esm({
|
|
|
993
1013
|
const body = buildSendBody(options);
|
|
994
1014
|
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
995
1015
|
const postOptions = opts.files?.length ? { body, files: opts.files } : { body };
|
|
996
|
-
const data = await this.client.rest.post(
|
|
1016
|
+
const data = await this.client.rest.post(import_types5.Routes.channelMessages(this.id), postOptions);
|
|
997
1017
|
return new Message2(this.client, data);
|
|
998
1018
|
}
|
|
999
1019
|
/** Message manager for this channel. Use channel.messages.fetch(messageId). */
|
|
@@ -1018,7 +1038,7 @@ var init_Channel = __esm({
|
|
|
1018
1038
|
*/
|
|
1019
1039
|
async fetchPinnedMessages() {
|
|
1020
1040
|
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
1021
|
-
const data = await this.client.rest.get(
|
|
1041
|
+
const data = await this.client.rest.get(import_types5.Routes.channelPins(this.id));
|
|
1022
1042
|
const list = Array.isArray(data) ? data : data?.items ?? [];
|
|
1023
1043
|
return list.map((item) => {
|
|
1024
1044
|
const msg = typeof item === "object" && item && "message" in item ? item.message : item;
|
|
@@ -1085,7 +1105,7 @@ var init_Channel = __esm({
|
|
|
1085
1105
|
const body = buildSendBody(options);
|
|
1086
1106
|
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
1087
1107
|
const postOptions = opts.files?.length ? { body, files: opts.files } : { body };
|
|
1088
|
-
const data = await this.client.rest.post(
|
|
1108
|
+
const data = await this.client.rest.post(import_types5.Routes.channelMessages(this.id), postOptions);
|
|
1089
1109
|
return new Message2(this.client, data);
|
|
1090
1110
|
}
|
|
1091
1111
|
/** Message manager for this channel. Use channel.messages.fetch(messageId). */
|
|
@@ -1105,7 +1125,7 @@ var init_Channel = __esm({
|
|
|
1105
1125
|
*/
|
|
1106
1126
|
async fetchPinnedMessages() {
|
|
1107
1127
|
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
1108
|
-
const data = await this.client.rest.get(
|
|
1128
|
+
const data = await this.client.rest.get(import_types5.Routes.channelPins(this.id));
|
|
1109
1129
|
const list = Array.isArray(data) ? data : data?.items ?? [];
|
|
1110
1130
|
return list.map((item) => {
|
|
1111
1131
|
const msg = typeof item === "object" && item && "message" in item ? item.message : item;
|
|
@@ -1129,12 +1149,56 @@ var init_Channel = __esm({
|
|
|
1129
1149
|
}
|
|
1130
1150
|
});
|
|
1131
1151
|
|
|
1152
|
+
// src/client/GuildMemberManager.ts
|
|
1153
|
+
var import_collection5, GuildMemberManager;
|
|
1154
|
+
var init_GuildMemberManager = __esm({
|
|
1155
|
+
"src/client/GuildMemberManager.ts"() {
|
|
1156
|
+
"use strict";
|
|
1157
|
+
import_collection5 = require("@fluxerjs/collection");
|
|
1158
|
+
GuildMemberManager = class extends import_collection5.Collection {
|
|
1159
|
+
constructor(guild) {
|
|
1160
|
+
super();
|
|
1161
|
+
this.guild = guild;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* The current bot user as a GuildMember in this guild.
|
|
1165
|
+
* Returns null if the bot's member is not cached or client.user is null.
|
|
1166
|
+
* Use fetchMe() to load the bot's member when not cached.
|
|
1167
|
+
*
|
|
1168
|
+
* @example
|
|
1169
|
+
* const perms = guild.members.me?.permissions;
|
|
1170
|
+
* if (perms?.has(PermissionFlags.BanMembers)) { ... }
|
|
1171
|
+
*/
|
|
1172
|
+
get me() {
|
|
1173
|
+
const userId = this.guild.client.user?.id;
|
|
1174
|
+
return userId ? this.get(userId) ?? null : null;
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Fetch the current bot user as a GuildMember in this guild.
|
|
1178
|
+
* Caches the result in guild.members.
|
|
1179
|
+
*
|
|
1180
|
+
* @throws Error if client.user is null (client not ready)
|
|
1181
|
+
* @example
|
|
1182
|
+
* const me = await guild.members.fetchMe();
|
|
1183
|
+
* console.log(me.displayName);
|
|
1184
|
+
*/
|
|
1185
|
+
async fetchMe() {
|
|
1186
|
+
const userId = this.guild.client.user?.id;
|
|
1187
|
+
if (!userId) {
|
|
1188
|
+
throw new Error("Cannot fetch me: client.user is null (client not ready)");
|
|
1189
|
+
}
|
|
1190
|
+
return this.guild.fetchMember(userId);
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1132
1196
|
// src/util/permissions.ts
|
|
1133
1197
|
function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
|
|
1134
1198
|
if (isOwner) return import_util3.ALL_PERMISSIONS_BIGINT;
|
|
1135
1199
|
let perms = basePermissions;
|
|
1136
1200
|
for (const overwrite of overwrites ?? []) {
|
|
1137
|
-
const applies = overwrite.type ===
|
|
1201
|
+
const applies = overwrite.type === import_types7.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types7.OverwriteType.Member && overwrite.id === memberId;
|
|
1138
1202
|
if (!applies) continue;
|
|
1139
1203
|
const allow = BigInt(overwrite.allow || "0");
|
|
1140
1204
|
const deny = BigInt(overwrite.deny || "0");
|
|
@@ -1147,11 +1211,11 @@ function hasPermission(bitfield, permission) {
|
|
|
1147
1211
|
if ((bitfield & Administrator) !== 0n) return true;
|
|
1148
1212
|
return (bitfield & permission) === permission;
|
|
1149
1213
|
}
|
|
1150
|
-
var
|
|
1214
|
+
var import_types7, import_util3;
|
|
1151
1215
|
var init_permissions = __esm({
|
|
1152
1216
|
"src/util/permissions.ts"() {
|
|
1153
1217
|
"use strict";
|
|
1154
|
-
|
|
1218
|
+
import_types7 = require("@fluxerjs/types");
|
|
1155
1219
|
import_util3 = require("@fluxerjs/util");
|
|
1156
1220
|
}
|
|
1157
1221
|
});
|
|
@@ -1161,13 +1225,13 @@ var GuildMember_exports = {};
|
|
|
1161
1225
|
__export(GuildMember_exports, {
|
|
1162
1226
|
GuildMember: () => GuildMember
|
|
1163
1227
|
});
|
|
1164
|
-
var import_util4,
|
|
1228
|
+
var import_util4, import_types8, GuildMember;
|
|
1165
1229
|
var init_GuildMember = __esm({
|
|
1166
1230
|
"src/structures/GuildMember.ts"() {
|
|
1167
1231
|
"use strict";
|
|
1168
1232
|
init_Base();
|
|
1169
1233
|
import_util4 = require("@fluxerjs/util");
|
|
1170
|
-
|
|
1234
|
+
import_types8 = require("@fluxerjs/types");
|
|
1171
1235
|
init_cdn();
|
|
1172
1236
|
init_permissions();
|
|
1173
1237
|
GuildMember = class extends Base {
|
|
@@ -1234,7 +1298,7 @@ var init_GuildMember = __esm({
|
|
|
1234
1298
|
* Requires Manage Roles permission.
|
|
1235
1299
|
*/
|
|
1236
1300
|
async addRole(roleId) {
|
|
1237
|
-
await this.client.rest.put(
|
|
1301
|
+
await this.client.rest.put(import_types8.Routes.guildMemberRole(this.guild.id, this.id, roleId));
|
|
1238
1302
|
}
|
|
1239
1303
|
/**
|
|
1240
1304
|
* Remove a role from this member.
|
|
@@ -1242,7 +1306,7 @@ var init_GuildMember = __esm({
|
|
|
1242
1306
|
* Requires Manage Roles permission.
|
|
1243
1307
|
*/
|
|
1244
1308
|
async removeRole(roleId) {
|
|
1245
|
-
await this.client.rest.delete(
|
|
1309
|
+
await this.client.rest.delete(import_types8.Routes.guildMemberRole(this.guild.id, this.id, roleId));
|
|
1246
1310
|
}
|
|
1247
1311
|
/**
|
|
1248
1312
|
* Get the member's guild-level permissions (from roles only, no channel overwrites).
|
|
@@ -1313,11 +1377,12 @@ var Role_exports = {};
|
|
|
1313
1377
|
__export(Role_exports, {
|
|
1314
1378
|
Role: () => Role
|
|
1315
1379
|
});
|
|
1316
|
-
var import_util5, Role;
|
|
1380
|
+
var import_types9, import_util5, Role;
|
|
1317
1381
|
var init_Role = __esm({
|
|
1318
1382
|
"src/structures/Role.ts"() {
|
|
1319
1383
|
"use strict";
|
|
1320
1384
|
init_Base();
|
|
1385
|
+
import_types9 = require("@fluxerjs/types");
|
|
1321
1386
|
import_util5 = require("@fluxerjs/util");
|
|
1322
1387
|
Role = class extends Base {
|
|
1323
1388
|
client;
|
|
@@ -1349,6 +1414,17 @@ var init_Role = __esm({
|
|
|
1349
1414
|
this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
1350
1415
|
this.hoistPosition = data.hoist_position ?? null;
|
|
1351
1416
|
}
|
|
1417
|
+
/** Update mutable fields from fresh API data. Used by edit and gateway events. */
|
|
1418
|
+
_patch(data) {
|
|
1419
|
+
if (data.name !== void 0) this.name = data.name;
|
|
1420
|
+
if (data.color !== void 0) this.color = data.color;
|
|
1421
|
+
if (data.position !== void 0) this.position = data.position;
|
|
1422
|
+
if (data.permissions !== void 0) this.permissions = data.permissions;
|
|
1423
|
+
if (data.hoist !== void 0) this.hoist = !!data.hoist;
|
|
1424
|
+
if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
|
|
1425
|
+
if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
|
|
1426
|
+
if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
|
|
1427
|
+
}
|
|
1352
1428
|
/** Returns a mention string (e.g. `<@&123456>`). */
|
|
1353
1429
|
toString() {
|
|
1354
1430
|
return `<@&${this.id}>`;
|
|
@@ -1371,6 +1447,42 @@ var init_Role = __esm({
|
|
|
1371
1447
|
if ((rolePerms & BigInt(import_util5.PermissionFlags.Administrator)) !== 0n) return true;
|
|
1372
1448
|
return (rolePerms & permBig) === permBig;
|
|
1373
1449
|
}
|
|
1450
|
+
/**
|
|
1451
|
+
* Edit this role.
|
|
1452
|
+
* Requires Manage Roles permission.
|
|
1453
|
+
* @param options - Role updates (permissions accepts PermissionResolvable for convenience)
|
|
1454
|
+
* @returns This role (updated in place)
|
|
1455
|
+
* @example
|
|
1456
|
+
* await role.edit({ name: 'Moderator', permissions: ['BanMembers', 'KickMembers'] });
|
|
1457
|
+
*/
|
|
1458
|
+
async edit(options) {
|
|
1459
|
+
const body = {};
|
|
1460
|
+
if (options.name !== void 0) body.name = options.name;
|
|
1461
|
+
if (options.permissions !== void 0) {
|
|
1462
|
+
body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util5.resolvePermissionsToBitfield)(options.permissions);
|
|
1463
|
+
}
|
|
1464
|
+
if (options.color !== void 0) body.color = options.color;
|
|
1465
|
+
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
1466
|
+
if (options.mentionable !== void 0) body.mentionable = options.mentionable;
|
|
1467
|
+
if (options.unicode_emoji !== void 0) body.unicode_emoji = options.unicode_emoji;
|
|
1468
|
+
if (options.position !== void 0) body.position = options.position;
|
|
1469
|
+
if (options.hoist_position !== void 0) body.hoist_position = options.hoist_position;
|
|
1470
|
+
const data = await this.client.rest.patch(import_types9.Routes.guildRole(this.guildId, this.id), {
|
|
1471
|
+
body: Object.keys(body).length ? body : void 0,
|
|
1472
|
+
auth: true
|
|
1473
|
+
});
|
|
1474
|
+
this._patch(data);
|
|
1475
|
+
return this;
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Delete this role.
|
|
1479
|
+
* Requires Manage Roles permission.
|
|
1480
|
+
*/
|
|
1481
|
+
async delete() {
|
|
1482
|
+
await this.client.rest.delete(import_types9.Routes.guildRole(this.guildId, this.id), { auth: true });
|
|
1483
|
+
const guild = this.client.guilds.get(this.guildId);
|
|
1484
|
+
if (guild) guild.roles.delete(this.id);
|
|
1485
|
+
}
|
|
1374
1486
|
};
|
|
1375
1487
|
}
|
|
1376
1488
|
});
|
|
@@ -1380,12 +1492,12 @@ var GuildBan_exports = {};
|
|
|
1380
1492
|
__export(GuildBan_exports, {
|
|
1381
1493
|
GuildBan: () => GuildBan
|
|
1382
1494
|
});
|
|
1383
|
-
var
|
|
1495
|
+
var import_types10, GuildBan;
|
|
1384
1496
|
var init_GuildBan = __esm({
|
|
1385
1497
|
"src/structures/GuildBan.ts"() {
|
|
1386
1498
|
"use strict";
|
|
1387
1499
|
init_Base();
|
|
1388
|
-
|
|
1500
|
+
import_types10 = require("@fluxerjs/types");
|
|
1389
1501
|
GuildBan = class extends Base {
|
|
1390
1502
|
client;
|
|
1391
1503
|
guildId;
|
|
@@ -1407,7 +1519,7 @@ var init_GuildBan = __esm({
|
|
|
1407
1519
|
* Requires Ban Members permission.
|
|
1408
1520
|
*/
|
|
1409
1521
|
async unban() {
|
|
1410
|
-
await this.client.rest.delete(
|
|
1522
|
+
await this.client.rest.delete(import_types10.Routes.guildBan(this.guildId, this.user.id), {
|
|
1411
1523
|
auth: true
|
|
1412
1524
|
});
|
|
1413
1525
|
}
|
|
@@ -1420,20 +1532,21 @@ var Guild_exports = {};
|
|
|
1420
1532
|
__export(Guild_exports, {
|
|
1421
1533
|
Guild: () => Guild
|
|
1422
1534
|
});
|
|
1423
|
-
var import_util6,
|
|
1535
|
+
var import_util6, import_rest3, import_collection6, import_types11, Guild;
|
|
1424
1536
|
var init_Guild = __esm({
|
|
1425
1537
|
"src/structures/Guild.ts"() {
|
|
1426
1538
|
"use strict";
|
|
1427
1539
|
import_util6 = require("@fluxerjs/util");
|
|
1428
|
-
|
|
1540
|
+
import_rest3 = require("@fluxerjs/rest");
|
|
1541
|
+
import_collection6 = require("@fluxerjs/collection");
|
|
1429
1542
|
init_Base();
|
|
1430
1543
|
init_FluxerError();
|
|
1431
1544
|
init_ErrorCodes();
|
|
1432
|
-
|
|
1545
|
+
init_GuildMemberManager();
|
|
1433
1546
|
init_GuildMember();
|
|
1434
1547
|
init_Role();
|
|
1435
1548
|
init_Constants();
|
|
1436
|
-
|
|
1549
|
+
import_types11 = require("@fluxerjs/types");
|
|
1437
1550
|
Guild = class extends Base {
|
|
1438
1551
|
client;
|
|
1439
1552
|
id;
|
|
@@ -1468,14 +1581,15 @@ var init_Guild = __esm({
|
|
|
1468
1581
|
splashWidth;
|
|
1469
1582
|
/** Splash image height. Optional. */
|
|
1470
1583
|
splashHeight;
|
|
1471
|
-
members
|
|
1472
|
-
channels = new
|
|
1473
|
-
roles = new
|
|
1584
|
+
members;
|
|
1585
|
+
channels = new import_collection6.Collection();
|
|
1586
|
+
roles = new import_collection6.Collection();
|
|
1474
1587
|
/** @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE */
|
|
1475
1588
|
constructor(client, data) {
|
|
1476
1589
|
super();
|
|
1477
1590
|
this.client = client;
|
|
1478
1591
|
this.id = data.id;
|
|
1592
|
+
this.members = new GuildMemberManager(this);
|
|
1479
1593
|
this.name = data.name;
|
|
1480
1594
|
this.icon = data.icon ?? null;
|
|
1481
1595
|
this.banner = data.banner ?? null;
|
|
@@ -1525,7 +1639,7 @@ var init_Guild = __esm({
|
|
|
1525
1639
|
* Requires Manage Roles permission.
|
|
1526
1640
|
*/
|
|
1527
1641
|
async addRoleToMember(userId, roleId) {
|
|
1528
|
-
await this.client.rest.put(
|
|
1642
|
+
await this.client.rest.put(import_types11.Routes.guildMemberRole(this.id, userId, roleId));
|
|
1529
1643
|
}
|
|
1530
1644
|
/**
|
|
1531
1645
|
* Remove a role from a member by user ID. Does not require fetching the member first.
|
|
@@ -1534,7 +1648,75 @@ var init_Guild = __esm({
|
|
|
1534
1648
|
* Requires Manage Roles permission.
|
|
1535
1649
|
*/
|
|
1536
1650
|
async removeRoleFromMember(userId, roleId) {
|
|
1537
|
-
await this.client.rest.delete(
|
|
1651
|
+
await this.client.rest.delete(import_types11.Routes.guildMemberRole(this.id, userId, roleId));
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Create a role in this guild.
|
|
1655
|
+
* Requires Manage Roles permission.
|
|
1656
|
+
* @param options - Role data (permissions accepts PermissionResolvable for convenience)
|
|
1657
|
+
* @returns The created role
|
|
1658
|
+
* @example
|
|
1659
|
+
* const role = await guild.createRole({ name: 'Mod', permissions: ['KickMembers', 'BanMembers'] });
|
|
1660
|
+
*/
|
|
1661
|
+
async createRole(options) {
|
|
1662
|
+
const body = {};
|
|
1663
|
+
if (options.name !== void 0) body.name = options.name;
|
|
1664
|
+
if (options.permissions !== void 0) {
|
|
1665
|
+
body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util6.resolvePermissionsToBitfield)(options.permissions);
|
|
1666
|
+
}
|
|
1667
|
+
if (options.color !== void 0) body.color = options.color;
|
|
1668
|
+
if (options.hoist !== void 0) body.hoist = options.hoist;
|
|
1669
|
+
if (options.mentionable !== void 0) body.mentionable = options.mentionable;
|
|
1670
|
+
if (options.unicode_emoji !== void 0) body.unicode_emoji = options.unicode_emoji;
|
|
1671
|
+
if (options.position !== void 0) body.position = options.position;
|
|
1672
|
+
if (options.hoist_position !== void 0) body.hoist_position = options.hoist_position;
|
|
1673
|
+
const data = await this.client.rest.post(import_types11.Routes.guildRoles(this.id), {
|
|
1674
|
+
body: Object.keys(body).length ? body : void 0,
|
|
1675
|
+
auth: true
|
|
1676
|
+
});
|
|
1677
|
+
const role = new Role(this.client, data, this.id);
|
|
1678
|
+
this.roles.set(role.id, role);
|
|
1679
|
+
return role;
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Fetch all roles in this guild.
|
|
1683
|
+
* @returns Array of Role objects (cached in guild.roles)
|
|
1684
|
+
*/
|
|
1685
|
+
async fetchRoles() {
|
|
1686
|
+
const data = await this.client.rest.get(
|
|
1687
|
+
import_types11.Routes.guildRoles(this.id)
|
|
1688
|
+
);
|
|
1689
|
+
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
1690
|
+
const roles = [];
|
|
1691
|
+
for (const r of list) {
|
|
1692
|
+
const role = new Role(this.client, r, this.id);
|
|
1693
|
+
this.roles.set(role.id, role);
|
|
1694
|
+
roles.push(role);
|
|
1695
|
+
}
|
|
1696
|
+
return roles;
|
|
1697
|
+
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Fetch a role by ID.
|
|
1700
|
+
* @param roleId - The role ID to fetch
|
|
1701
|
+
* @returns The role
|
|
1702
|
+
* @throws FluxerError with ROLE_NOT_FOUND if role does not exist (404)
|
|
1703
|
+
*/
|
|
1704
|
+
async fetchRole(roleId) {
|
|
1705
|
+
try {
|
|
1706
|
+
const data = await this.client.rest.get(import_types11.Routes.guildRole(this.id, roleId));
|
|
1707
|
+
const role = new Role(this.client, data, this.id);
|
|
1708
|
+
this.roles.set(role.id, role);
|
|
1709
|
+
return role;
|
|
1710
|
+
} catch (err) {
|
|
1711
|
+
const statusCode = err instanceof import_rest3.FluxerAPIError ? err.statusCode : err?.statusCode;
|
|
1712
|
+
if (statusCode === 404) {
|
|
1713
|
+
throw new FluxerError(`Role ${roleId} not found in guild`, {
|
|
1714
|
+
code: ErrorCodes.RoleNotFound,
|
|
1715
|
+
cause: err
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
throw err instanceof FluxerError ? err : new FluxerError("Failed to fetch guild role", { cause: err });
|
|
1719
|
+
}
|
|
1538
1720
|
}
|
|
1539
1721
|
/**
|
|
1540
1722
|
* Resolve a role ID from an argument (role mention, raw ID, or name).
|
|
@@ -1550,7 +1732,7 @@ var init_Guild = __esm({
|
|
|
1550
1732
|
(r) => !!(r.name && r.name.toLowerCase() === arg.trim().toLowerCase())
|
|
1551
1733
|
);
|
|
1552
1734
|
if (cached) return cached.id;
|
|
1553
|
-
const roles = await this.client.rest.get(
|
|
1735
|
+
const roles = await this.client.rest.get(import_types11.Routes.guildRoles(this.id));
|
|
1554
1736
|
const list = Array.isArray(roles) ? roles : Object.values(roles ?? {});
|
|
1555
1737
|
const role = list.find((r) => !!(r.name && r.name.toLowerCase() === arg.trim().toLowerCase()));
|
|
1556
1738
|
if (role) {
|
|
@@ -1573,7 +1755,7 @@ var init_Guild = __esm({
|
|
|
1573
1755
|
body.delete_message_days = options.delete_message_days;
|
|
1574
1756
|
if (options?.ban_duration_seconds != null)
|
|
1575
1757
|
body.ban_duration_seconds = options.ban_duration_seconds;
|
|
1576
|
-
await this.client.rest.put(
|
|
1758
|
+
await this.client.rest.put(import_types11.Routes.guildBan(this.id, userId), {
|
|
1577
1759
|
body: Object.keys(body).length ? body : void 0,
|
|
1578
1760
|
auth: true
|
|
1579
1761
|
});
|
|
@@ -1584,7 +1766,7 @@ var init_Guild = __esm({
|
|
|
1584
1766
|
*/
|
|
1585
1767
|
async fetchBans() {
|
|
1586
1768
|
const { GuildBan: GuildBan2 } = await Promise.resolve().then(() => (init_GuildBan(), GuildBan_exports));
|
|
1587
|
-
const data = await this.client.rest.get(
|
|
1769
|
+
const data = await this.client.rest.get(import_types11.Routes.guildBans(this.id));
|
|
1588
1770
|
const list = Array.isArray(data) ? data : data?.bans ?? [];
|
|
1589
1771
|
return list.map((b) => new GuildBan2(this.client, { ...b, guild_id: this.id }, this.id));
|
|
1590
1772
|
}
|
|
@@ -1594,7 +1776,7 @@ var init_Guild = __esm({
|
|
|
1594
1776
|
* Requires Ban Members permission.
|
|
1595
1777
|
*/
|
|
1596
1778
|
async unban(userId) {
|
|
1597
|
-
await this.client.rest.delete(
|
|
1779
|
+
await this.client.rest.delete(import_types11.Routes.guildBan(this.id, userId), { auth: true });
|
|
1598
1780
|
}
|
|
1599
1781
|
/**
|
|
1600
1782
|
* Kick a member from this guild.
|
|
@@ -1602,7 +1784,7 @@ var init_Guild = __esm({
|
|
|
1602
1784
|
* Requires Kick Members permission.
|
|
1603
1785
|
*/
|
|
1604
1786
|
async kick(userId) {
|
|
1605
|
-
await this.client.rest.delete(
|
|
1787
|
+
await this.client.rest.delete(import_types11.Routes.guildMember(this.id, userId), { auth: true });
|
|
1606
1788
|
}
|
|
1607
1789
|
/**
|
|
1608
1790
|
* Fetch a guild member by user ID.
|
|
@@ -1614,13 +1796,13 @@ var init_Guild = __esm({
|
|
|
1614
1796
|
async fetchMember(userId) {
|
|
1615
1797
|
try {
|
|
1616
1798
|
const data = await this.client.rest.get(
|
|
1617
|
-
|
|
1799
|
+
import_types11.Routes.guildMember(this.id, userId)
|
|
1618
1800
|
);
|
|
1619
1801
|
const member = new GuildMember(this.client, { ...data, guild_id: this.id }, this);
|
|
1620
1802
|
this.members.set(member.id, member);
|
|
1621
1803
|
return member;
|
|
1622
1804
|
} catch (err) {
|
|
1623
|
-
const statusCode = err instanceof
|
|
1805
|
+
const statusCode = err instanceof import_rest3.FluxerAPIError ? err.statusCode : err?.statusCode;
|
|
1624
1806
|
if (statusCode === 404) {
|
|
1625
1807
|
throw new FluxerError(`Member ${userId} not found in guild`, {
|
|
1626
1808
|
code: ErrorCodes.MemberNotFound,
|
|
@@ -1642,13 +1824,13 @@ var init_Guild = __esm({
|
|
|
1642
1824
|
if (options?.userId) params.set("user_id", options.userId);
|
|
1643
1825
|
if (options?.actionType != null) params.set("action_type", String(options.actionType));
|
|
1644
1826
|
const qs = params.toString();
|
|
1645
|
-
const url =
|
|
1827
|
+
const url = import_types11.Routes.guildAuditLogs(this.id) + (qs ? `?${qs}` : "");
|
|
1646
1828
|
return this.client.rest.get(url);
|
|
1647
1829
|
}
|
|
1648
1830
|
/** Fetch all webhooks in this guild. Returned webhooks do not include the token (cannot send). */
|
|
1649
1831
|
async fetchWebhooks() {
|
|
1650
1832
|
const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
|
|
1651
|
-
const data = await this.client.rest.get(
|
|
1833
|
+
const data = await this.client.rest.get(import_types11.Routes.guildWebhooks(this.id));
|
|
1652
1834
|
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
1653
1835
|
return list.map((w) => new Webhook2(this.client, w));
|
|
1654
1836
|
}
|
|
@@ -1659,7 +1841,7 @@ var init_Guild = __esm({
|
|
|
1659
1841
|
*/
|
|
1660
1842
|
async createChannel(data) {
|
|
1661
1843
|
const { Channel: Channel2 } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
|
|
1662
|
-
const created = await this.client.rest.post(
|
|
1844
|
+
const created = await this.client.rest.post(import_types11.Routes.guildChannels(this.id), {
|
|
1663
1845
|
body: data,
|
|
1664
1846
|
auth: true
|
|
1665
1847
|
});
|
|
@@ -1676,7 +1858,7 @@ var init_Guild = __esm({
|
|
|
1676
1858
|
*/
|
|
1677
1859
|
async fetchChannels() {
|
|
1678
1860
|
const { Channel: Channel2 } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
|
|
1679
|
-
const data = await this.client.rest.get(
|
|
1861
|
+
const data = await this.client.rest.get(import_types11.Routes.guildChannels(this.id));
|
|
1680
1862
|
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
1681
1863
|
const channels = [];
|
|
1682
1864
|
for (const ch of list) {
|
|
@@ -1695,7 +1877,7 @@ var init_Guild = __esm({
|
|
|
1695
1877
|
* Requires Manage Channels permission.
|
|
1696
1878
|
*/
|
|
1697
1879
|
async setChannelPositions(updates) {
|
|
1698
|
-
await this.client.rest.patch(
|
|
1880
|
+
await this.client.rest.patch(import_types11.Routes.guildChannels(this.id), {
|
|
1699
1881
|
body: updates,
|
|
1700
1882
|
auth: true
|
|
1701
1883
|
});
|
|
@@ -1705,12 +1887,12 @@ var init_Guild = __esm({
|
|
|
1705
1887
|
});
|
|
1706
1888
|
|
|
1707
1889
|
// src/structures/User.ts
|
|
1708
|
-
var
|
|
1890
|
+
var import_types13, User;
|
|
1709
1891
|
var init_User = __esm({
|
|
1710
1892
|
"src/structures/User.ts"() {
|
|
1711
1893
|
"use strict";
|
|
1712
1894
|
init_Base();
|
|
1713
|
-
|
|
1895
|
+
import_types13 = require("@fluxerjs/types");
|
|
1714
1896
|
init_Constants();
|
|
1715
1897
|
User = class extends Base {
|
|
1716
1898
|
client;
|
|
@@ -1788,7 +1970,7 @@ var init_User = __esm({
|
|
|
1788
1970
|
*/
|
|
1789
1971
|
async createDM() {
|
|
1790
1972
|
const { DMChannel: DMChannelClass } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
|
|
1791
|
-
const data = await this.client.rest.post(
|
|
1973
|
+
const data = await this.client.rest.post(import_types13.Routes.userMeChannels(), {
|
|
1792
1974
|
body: { recipient_id: this.id },
|
|
1793
1975
|
auth: true
|
|
1794
1976
|
});
|
|
@@ -1811,10 +1993,14 @@ var MessageReaction_exports = {};
|
|
|
1811
1993
|
__export(MessageReaction_exports, {
|
|
1812
1994
|
MessageReaction: () => MessageReaction
|
|
1813
1995
|
});
|
|
1814
|
-
var MessageReaction;
|
|
1996
|
+
var import_types15, import_rest4, MessageReaction;
|
|
1815
1997
|
var init_MessageReaction = __esm({
|
|
1816
1998
|
"src/structures/MessageReaction.ts"() {
|
|
1817
1999
|
"use strict";
|
|
2000
|
+
import_types15 = require("@fluxerjs/types");
|
|
2001
|
+
import_rest4 = require("@fluxerjs/rest");
|
|
2002
|
+
init_FluxerError();
|
|
2003
|
+
init_ErrorCodes();
|
|
1818
2004
|
init_Base();
|
|
1819
2005
|
MessageReaction = class extends Base {
|
|
1820
2006
|
client;
|
|
@@ -1847,7 +2033,22 @@ var init_MessageReaction = __esm({
|
|
|
1847
2033
|
* @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
|
|
1848
2034
|
*/
|
|
1849
2035
|
async fetchMessage() {
|
|
1850
|
-
|
|
2036
|
+
try {
|
|
2037
|
+
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
2038
|
+
const data = await this.client.rest.get(
|
|
2039
|
+
import_types15.Routes.channelMessage(this.channelId, this.messageId)
|
|
2040
|
+
);
|
|
2041
|
+
return new Message2(this.client, data);
|
|
2042
|
+
} catch (err) {
|
|
2043
|
+
if (err instanceof import_rest4.RateLimitError) throw err;
|
|
2044
|
+
if (err instanceof import_rest4.FluxerAPIError && err.statusCode === 404) {
|
|
2045
|
+
throw new FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
|
|
2046
|
+
code: ErrorCodes.MessageNotFound,
|
|
2047
|
+
cause: err
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
|
|
2051
|
+
}
|
|
1851
2052
|
}
|
|
1852
2053
|
};
|
|
1853
2054
|
}
|
|
@@ -1858,12 +2059,12 @@ var ClientUser_exports = {};
|
|
|
1858
2059
|
__export(ClientUser_exports, {
|
|
1859
2060
|
ClientUser: () => ClientUser
|
|
1860
2061
|
});
|
|
1861
|
-
var
|
|
2062
|
+
var import_types16, ClientUser;
|
|
1862
2063
|
var init_ClientUser = __esm({
|
|
1863
2064
|
"src/client/ClientUser.ts"() {
|
|
1864
2065
|
"use strict";
|
|
1865
2066
|
init_User();
|
|
1866
|
-
|
|
2067
|
+
import_types16 = require("@fluxerjs/types");
|
|
1867
2068
|
ClientUser = class extends User {
|
|
1868
2069
|
constructor(client, data) {
|
|
1869
2070
|
super(client, { ...data });
|
|
@@ -1874,7 +2075,7 @@ var init_ClientUser = __esm({
|
|
|
1874
2075
|
*/
|
|
1875
2076
|
async fetchGuilds() {
|
|
1876
2077
|
const { Guild: Guild2 } = await Promise.resolve().then(() => (init_Guild(), Guild_exports));
|
|
1877
|
-
const data = await this.client.rest.get(
|
|
2078
|
+
const data = await this.client.rest.get(import_types16.Routes.currentUserGuilds());
|
|
1878
2079
|
const list = Array.isArray(data) ? data : data?.guilds ?? [];
|
|
1879
2080
|
const guilds = [];
|
|
1880
2081
|
for (const g of list) {
|
|
@@ -1889,7 +2090,7 @@ var init_ClientUser = __esm({
|
|
|
1889
2090
|
* @param guildId - The guild ID to leave
|
|
1890
2091
|
*/
|
|
1891
2092
|
async leaveGuild(guildId) {
|
|
1892
|
-
await this.client.rest.delete(
|
|
2093
|
+
await this.client.rest.delete(import_types16.Routes.leaveGuild(guildId), { auth: true });
|
|
1893
2094
|
this.client.guilds.delete(guildId);
|
|
1894
2095
|
}
|
|
1895
2096
|
};
|
|
@@ -1911,17 +2112,18 @@ __export(index_exports, {
|
|
|
1911
2112
|
ErrorCodes: () => ErrorCodes,
|
|
1912
2113
|
Events: () => Events,
|
|
1913
2114
|
FluxerError: () => FluxerError,
|
|
1914
|
-
GatewayOpcodes: () =>
|
|
2115
|
+
GatewayOpcodes: () => import_types20.GatewayOpcodes,
|
|
1915
2116
|
Guild: () => Guild,
|
|
1916
2117
|
GuildBan: () => GuildBan,
|
|
1917
2118
|
GuildChannel: () => GuildChannel,
|
|
1918
2119
|
GuildEmoji: () => GuildEmoji,
|
|
1919
2120
|
GuildMember: () => GuildMember,
|
|
2121
|
+
GuildMemberManager: () => GuildMemberManager,
|
|
1920
2122
|
GuildSticker: () => GuildSticker,
|
|
1921
2123
|
Invite: () => Invite,
|
|
1922
2124
|
LinkChannel: () => LinkChannel,
|
|
1923
2125
|
Message: () => Message,
|
|
1924
|
-
MessageAttachmentFlags: () =>
|
|
2126
|
+
MessageAttachmentFlags: () => import_types20.MessageAttachmentFlags,
|
|
1925
2127
|
MessageCollector: () => MessageCollector,
|
|
1926
2128
|
MessageManager: () => MessageManager,
|
|
1927
2129
|
MessagePayload: () => import_builders3.MessagePayload,
|
|
@@ -1930,9 +2132,12 @@ __export(index_exports, {
|
|
|
1930
2132
|
PermissionsBitField: () => import_util9.PermissionsBitField,
|
|
1931
2133
|
ReactionCollector: () => ReactionCollector,
|
|
1932
2134
|
Role: () => Role,
|
|
1933
|
-
Routes: () =>
|
|
2135
|
+
Routes: () => import_types20.Routes,
|
|
1934
2136
|
TextChannel: () => TextChannel,
|
|
1935
2137
|
User: () => User,
|
|
2138
|
+
UserFlagsBitField: () => import_util9.UserFlagsBitField,
|
|
2139
|
+
UserFlagsBits: () => import_util9.UserFlagsBits,
|
|
2140
|
+
UsersManager: () => UsersManager,
|
|
1936
2141
|
VoiceChannel: () => VoiceChannel,
|
|
1937
2142
|
Webhook: () => Webhook,
|
|
1938
2143
|
cdnAvatarURL: () => cdnAvatarURL,
|
|
@@ -1941,22 +2146,22 @@ __export(index_exports, {
|
|
|
1941
2146
|
cdnDisplayAvatarURL: () => cdnDisplayAvatarURL,
|
|
1942
2147
|
cdnMemberAvatarURL: () => cdnMemberAvatarURL,
|
|
1943
2148
|
cdnMemberBannerURL: () => cdnMemberBannerURL,
|
|
2149
|
+
resolvePermissionsToBitfield: () => import_util9.resolvePermissionsToBitfield,
|
|
1944
2150
|
resolveTenorToImageUrl: () => import_util8.resolveTenorToImageUrl
|
|
1945
2151
|
});
|
|
1946
2152
|
module.exports = __toCommonJS(index_exports);
|
|
1947
2153
|
|
|
1948
2154
|
// src/client/Client.ts
|
|
1949
2155
|
var import_events3 = require("events");
|
|
1950
|
-
var
|
|
2156
|
+
var import_rest5 = require("@fluxerjs/rest");
|
|
1951
2157
|
var import_ws = require("@fluxerjs/ws");
|
|
1952
|
-
var
|
|
1953
|
-
var import_collection7 = require("@fluxerjs/collection");
|
|
2158
|
+
var import_types17 = require("@fluxerjs/types");
|
|
1954
2159
|
|
|
1955
2160
|
// src/client/ChannelManager.ts
|
|
1956
2161
|
var import_collection4 = require("@fluxerjs/collection");
|
|
1957
|
-
var
|
|
2162
|
+
var import_types6 = require("@fluxerjs/types");
|
|
1958
2163
|
var import_util2 = require("@fluxerjs/util");
|
|
1959
|
-
var
|
|
2164
|
+
var import_rest2 = require("@fluxerjs/rest");
|
|
1960
2165
|
init_FluxerError();
|
|
1961
2166
|
init_ErrorCodes();
|
|
1962
2167
|
init_messageUtils();
|
|
@@ -1980,7 +2185,7 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
1980
2185
|
try {
|
|
1981
2186
|
const { Channel: Channel2 } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
|
|
1982
2187
|
const data = await this.client.rest.get(
|
|
1983
|
-
|
|
2188
|
+
import_types6.Routes.channel(channelId)
|
|
1984
2189
|
);
|
|
1985
2190
|
const channel = Channel2.fromOrCreate(this.client, data);
|
|
1986
2191
|
if (!channel) {
|
|
@@ -1991,8 +2196,8 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
1991
2196
|
this.set(channel.id, channel);
|
|
1992
2197
|
return channel;
|
|
1993
2198
|
} catch (err) {
|
|
1994
|
-
if (err instanceof
|
|
1995
|
-
if (err instanceof
|
|
2199
|
+
if (err instanceof import_rest2.RateLimitError) throw err;
|
|
2200
|
+
if (err instanceof import_rest2.FluxerAPIError && err.statusCode === 404) {
|
|
1996
2201
|
throw new FluxerError(`Channel ${channelId} not found`, {
|
|
1997
2202
|
code: ErrorCodes.ChannelNotFound,
|
|
1998
2203
|
cause: err
|
|
@@ -2020,12 +2225,12 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
2020
2225
|
try {
|
|
2021
2226
|
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
2022
2227
|
const data = await this.client.rest.get(
|
|
2023
|
-
|
|
2228
|
+
import_types6.Routes.channelMessage(channelId, messageId)
|
|
2024
2229
|
);
|
|
2025
2230
|
return new Message2(this.client, data);
|
|
2026
2231
|
} catch (err) {
|
|
2027
|
-
if (err instanceof
|
|
2028
|
-
if (err instanceof
|
|
2232
|
+
if (err instanceof import_rest2.RateLimitError) throw err;
|
|
2233
|
+
if (err instanceof import_rest2.FluxerAPIError && err.statusCode === 404) {
|
|
2029
2234
|
throw new FluxerError(`Message ${messageId} not found in channel ${channelId}`, {
|
|
2030
2235
|
code: ErrorCodes.MessageNotFound,
|
|
2031
2236
|
cause: err
|
|
@@ -2050,15 +2255,15 @@ var ChannelManager = class extends import_collection4.Collection {
|
|
|
2050
2255
|
const body = buildSendBody(payload);
|
|
2051
2256
|
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
2052
2257
|
const postOptions = opts.files?.length ? { body, files: opts.files } : { body };
|
|
2053
|
-
const data = await this.client.rest.post(
|
|
2258
|
+
const data = await this.client.rest.post(import_types6.Routes.channelMessages(channelId), postOptions);
|
|
2054
2259
|
return new Message2(this.client, data);
|
|
2055
2260
|
}
|
|
2056
2261
|
};
|
|
2057
2262
|
|
|
2058
2263
|
// src/client/GuildManager.ts
|
|
2059
|
-
var
|
|
2060
|
-
var
|
|
2061
|
-
var GuildManager = class extends
|
|
2264
|
+
var import_collection7 = require("@fluxerjs/collection");
|
|
2265
|
+
var import_types12 = require("@fluxerjs/types");
|
|
2266
|
+
var GuildManager = class extends import_collection7.Collection {
|
|
2062
2267
|
constructor(client) {
|
|
2063
2268
|
super();
|
|
2064
2269
|
this.client = client;
|
|
@@ -2077,7 +2282,7 @@ var GuildManager = class extends import_collection6.Collection {
|
|
|
2077
2282
|
try {
|
|
2078
2283
|
const { Guild: Guild2 } = await Promise.resolve().then(() => (init_Guild(), Guild_exports));
|
|
2079
2284
|
const data = await this.client.rest.get(
|
|
2080
|
-
|
|
2285
|
+
import_types12.Routes.guild(guildId)
|
|
2081
2286
|
);
|
|
2082
2287
|
const guild = new Guild2(this.client, data);
|
|
2083
2288
|
this.set(guild.id, guild);
|
|
@@ -2095,6 +2300,77 @@ init_Events();
|
|
|
2095
2300
|
var import_util7 = require("@fluxerjs/util");
|
|
2096
2301
|
init_User();
|
|
2097
2302
|
|
|
2303
|
+
// src/client/UsersManager.ts
|
|
2304
|
+
var import_collection8 = require("@fluxerjs/collection");
|
|
2305
|
+
var import_types14 = require("@fluxerjs/types");
|
|
2306
|
+
init_GuildMember();
|
|
2307
|
+
var UsersManager = class extends import_collection8.Collection {
|
|
2308
|
+
constructor(client) {
|
|
2309
|
+
super();
|
|
2310
|
+
this.client = client;
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Fetch a user by ID from the API.
|
|
2314
|
+
* Updates cache if user already exists.
|
|
2315
|
+
* @param userId - Snowflake of the user
|
|
2316
|
+
* @returns The user
|
|
2317
|
+
* @throws FluxerError (or REST error) if user not found
|
|
2318
|
+
* @example
|
|
2319
|
+
* const user = await client.users.fetch(userId);
|
|
2320
|
+
* console.log(user.username);
|
|
2321
|
+
*/
|
|
2322
|
+
async fetch(userId) {
|
|
2323
|
+
const data = await this.client.rest.get(import_types14.Routes.user(userId));
|
|
2324
|
+
return this.client.getOrCreateUser(data);
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Fetch a user with full profile and optional guild context.
|
|
2328
|
+
* Returns user, global profile, server profile (when guildId), and member (when guildId).
|
|
2329
|
+
* Ideal for userinfo commands.
|
|
2330
|
+
* @param userId - Snowflake of the user
|
|
2331
|
+
* @param options - Optional guildId for server profile and member data
|
|
2332
|
+
* @returns User, raw data, profiles, and member (when in guild)
|
|
2333
|
+
* @throws FluxerError (or REST error) if user not found
|
|
2334
|
+
* @example
|
|
2335
|
+
* const { user, globalProfile, serverProfile, member } = await client.users.fetchWithProfile(
|
|
2336
|
+
* userId,
|
|
2337
|
+
* { guildId: message.guildId ?? undefined },
|
|
2338
|
+
* );
|
|
2339
|
+
*/
|
|
2340
|
+
async fetchWithProfile(userId, options) {
|
|
2341
|
+
const guildId = options?.guildId ?? void 0;
|
|
2342
|
+
const [userData, globalProfileData, serverProfileData, memberData] = await Promise.all([
|
|
2343
|
+
this.client.rest.get(import_types14.Routes.user(userId)),
|
|
2344
|
+
this.client.rest.get(import_types14.Routes.userProfile(userId)).catch(() => null),
|
|
2345
|
+
guildId ? this.client.rest.get(import_types14.Routes.userProfile(userId, guildId)).catch(() => null) : Promise.resolve(null),
|
|
2346
|
+
guildId ? this.client.rest.get(import_types14.Routes.guildMember(guildId, userId)).catch(() => null) : Promise.resolve(null)
|
|
2347
|
+
]);
|
|
2348
|
+
const user = this.client.getOrCreateUser(userData);
|
|
2349
|
+
const globalProfile = globalProfileData && typeof globalProfileData === "object" ? globalProfileData : null;
|
|
2350
|
+
const serverProfile = serverProfileData && typeof serverProfileData === "object" ? serverProfileData : null;
|
|
2351
|
+
let member = null;
|
|
2352
|
+
if (memberData && guildId) {
|
|
2353
|
+
const guild = this.client.guilds.get(guildId) ?? await this.client.guilds.fetch(guildId);
|
|
2354
|
+
if (guild) {
|
|
2355
|
+
member = new GuildMember(
|
|
2356
|
+
this.client,
|
|
2357
|
+
{ ...memberData, guild_id: guildId },
|
|
2358
|
+
guild
|
|
2359
|
+
);
|
|
2360
|
+
guild.members.set(member.id, member);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
return {
|
|
2364
|
+
user,
|
|
2365
|
+
userData,
|
|
2366
|
+
globalProfile,
|
|
2367
|
+
serverProfile,
|
|
2368
|
+
member,
|
|
2369
|
+
memberData
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
|
|
2098
2374
|
// src/client/EventHandlerRegistry.ts
|
|
2099
2375
|
init_Events();
|
|
2100
2376
|
var handlers = /* @__PURE__ */ new Map();
|
|
@@ -2310,8 +2586,13 @@ handlers.set("GUILD_ROLE_UPDATE", async (client, d) => {
|
|
|
2310
2586
|
const data = d;
|
|
2311
2587
|
const guild = client.guilds.get(data.guild_id);
|
|
2312
2588
|
if (guild) {
|
|
2313
|
-
const
|
|
2314
|
-
|
|
2589
|
+
const existing = guild.roles.get(data.role.id);
|
|
2590
|
+
if (existing) {
|
|
2591
|
+
existing._patch(data.role);
|
|
2592
|
+
} else {
|
|
2593
|
+
const { Role: Role2 } = await Promise.resolve().then(() => (init_Role(), Role_exports));
|
|
2594
|
+
guild.roles.set(data.role.id, new Role2(client, data.role, guild.id));
|
|
2595
|
+
}
|
|
2315
2596
|
}
|
|
2316
2597
|
client.emit(Events.GuildRoleUpdate, data);
|
|
2317
2598
|
});
|
|
@@ -2388,7 +2669,11 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
2388
2669
|
get: () => this.guilds,
|
|
2389
2670
|
configurable: true
|
|
2390
2671
|
});
|
|
2391
|
-
this.
|
|
2672
|
+
Object.defineProperty(this.users, "cache", {
|
|
2673
|
+
get: () => this.users,
|
|
2674
|
+
configurable: true
|
|
2675
|
+
});
|
|
2676
|
+
this.rest = new import_rest5.REST({
|
|
2392
2677
|
api: options.rest?.api ?? "https://api.fluxer.app",
|
|
2393
2678
|
version: options.rest?.version ?? "1",
|
|
2394
2679
|
...options.rest
|
|
@@ -2397,7 +2682,7 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
2397
2682
|
rest;
|
|
2398
2683
|
guilds = new GuildManager(this);
|
|
2399
2684
|
channels = new ChannelManager(this);
|
|
2400
|
-
users = new
|
|
2685
|
+
users = new UsersManager(this);
|
|
2401
2686
|
/** Typed event handlers. Use client.events.MessageReactionAdd((reaction, user, messageId, channelId, emoji, userId) => {...}) or client.on(Events.MessageReactionAdd, ...). */
|
|
2402
2687
|
events;
|
|
2403
2688
|
/** The authenticated bot user. Null until READY is received. */
|
|
@@ -2417,11 +2702,14 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
2417
2702
|
if (typeof emoji === "object" && emoji.id) {
|
|
2418
2703
|
return (0, import_util7.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
|
|
2419
2704
|
}
|
|
2420
|
-
const parsed = (0, import_util7.parseEmoji)(
|
|
2705
|
+
const parsed = (0, import_util7.parseEmoji)(
|
|
2706
|
+
typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
|
|
2707
|
+
);
|
|
2421
2708
|
if (!parsed) throw new Error("Invalid emoji");
|
|
2422
2709
|
if (parsed.id) return (0, import_util7.formatEmoji)(parsed);
|
|
2710
|
+
if (!/^\w+$/.test(parsed.name)) return encodeURIComponent(parsed.name);
|
|
2423
2711
|
if (guildId) {
|
|
2424
|
-
const emojis = await this.rest.get(
|
|
2712
|
+
const emojis = await this.rest.get(import_types17.Routes.guildEmojis(guildId));
|
|
2425
2713
|
const list = Array.isArray(emojis) ? emojis : Object.values(emojis ?? {});
|
|
2426
2714
|
const found = list.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
|
|
2427
2715
|
if (found) return (0, import_util7.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
|
|
@@ -2588,11 +2876,12 @@ var Client = class extends import_events3.EventEmitter {
|
|
|
2588
2876
|
return this.readyAt !== null && this.user !== null;
|
|
2589
2877
|
}
|
|
2590
2878
|
static get Routes() {
|
|
2591
|
-
return
|
|
2879
|
+
return import_types17.Routes;
|
|
2592
2880
|
}
|
|
2593
2881
|
};
|
|
2594
2882
|
|
|
2595
2883
|
// src/index.ts
|
|
2884
|
+
init_GuildMemberManager();
|
|
2596
2885
|
init_MessageManager();
|
|
2597
2886
|
init_ClientUser();
|
|
2598
2887
|
init_Base();
|
|
@@ -2609,7 +2898,7 @@ init_GuildBan();
|
|
|
2609
2898
|
|
|
2610
2899
|
// src/structures/GuildEmoji.ts
|
|
2611
2900
|
init_Base();
|
|
2612
|
-
var
|
|
2901
|
+
var import_types18 = require("@fluxerjs/types");
|
|
2613
2902
|
init_Constants();
|
|
2614
2903
|
var GuildEmoji = class extends Base {
|
|
2615
2904
|
client;
|
|
@@ -2637,7 +2926,7 @@ var GuildEmoji = class extends Base {
|
|
|
2637
2926
|
}
|
|
2638
2927
|
/** Delete this emoji. Requires Manage Emojis and Stickers permission. */
|
|
2639
2928
|
async delete() {
|
|
2640
|
-
await this.client.rest.delete(
|
|
2929
|
+
await this.client.rest.delete(import_types18.Routes.guildEmoji(this.guildId, this.id), {
|
|
2641
2930
|
auth: true
|
|
2642
2931
|
});
|
|
2643
2932
|
}
|
|
@@ -2646,7 +2935,7 @@ var GuildEmoji = class extends Base {
|
|
|
2646
2935
|
* Requires Manage Emojis and Stickers permission.
|
|
2647
2936
|
*/
|
|
2648
2937
|
async edit(options) {
|
|
2649
|
-
const data = await this.client.rest.patch(
|
|
2938
|
+
const data = await this.client.rest.patch(import_types18.Routes.guildEmoji(this.guildId, this.id), {
|
|
2650
2939
|
body: options,
|
|
2651
2940
|
auth: true
|
|
2652
2941
|
});
|
|
@@ -2657,7 +2946,7 @@ var GuildEmoji = class extends Base {
|
|
|
2657
2946
|
|
|
2658
2947
|
// src/structures/GuildSticker.ts
|
|
2659
2948
|
init_Base();
|
|
2660
|
-
var
|
|
2949
|
+
var import_types19 = require("@fluxerjs/types");
|
|
2661
2950
|
init_Constants();
|
|
2662
2951
|
var GuildSticker = class extends Base {
|
|
2663
2952
|
client;
|
|
@@ -2685,7 +2974,7 @@ var GuildSticker = class extends Base {
|
|
|
2685
2974
|
}
|
|
2686
2975
|
/** Delete this sticker. Requires Manage Emojis and Stickers permission. */
|
|
2687
2976
|
async delete() {
|
|
2688
|
-
await this.client.rest.delete(
|
|
2977
|
+
await this.client.rest.delete(import_types19.Routes.guildSticker(this.guildId, this.id), {
|
|
2689
2978
|
auth: true
|
|
2690
2979
|
});
|
|
2691
2980
|
}
|
|
@@ -2694,7 +2983,7 @@ var GuildSticker = class extends Base {
|
|
|
2694
2983
|
* Requires Manage Emojis and Stickers permission.
|
|
2695
2984
|
*/
|
|
2696
2985
|
async edit(options) {
|
|
2697
|
-
const data = await this.client.rest.patch(
|
|
2986
|
+
const data = await this.client.rest.patch(import_types19.Routes.guildSticker(this.guildId, this.id), {
|
|
2698
2987
|
body: options,
|
|
2699
2988
|
auth: true
|
|
2700
2989
|
});
|
|
@@ -2712,7 +3001,7 @@ init_ReactionCollector();
|
|
|
2712
3001
|
init_FluxerError();
|
|
2713
3002
|
init_ErrorCodes();
|
|
2714
3003
|
var import_builders3 = require("@fluxerjs/builders");
|
|
2715
|
-
var
|
|
3004
|
+
var import_types20 = require("@fluxerjs/types");
|
|
2716
3005
|
var import_util8 = require("@fluxerjs/util");
|
|
2717
3006
|
var import_util9 = require("@fluxerjs/util");
|
|
2718
3007
|
init_cdn();
|
|
@@ -2736,6 +3025,7 @@ init_cdn();
|
|
|
2736
3025
|
GuildChannel,
|
|
2737
3026
|
GuildEmoji,
|
|
2738
3027
|
GuildMember,
|
|
3028
|
+
GuildMemberManager,
|
|
2739
3029
|
GuildSticker,
|
|
2740
3030
|
Invite,
|
|
2741
3031
|
LinkChannel,
|
|
@@ -2752,6 +3042,9 @@ init_cdn();
|
|
|
2752
3042
|
Routes,
|
|
2753
3043
|
TextChannel,
|
|
2754
3044
|
User,
|
|
3045
|
+
UserFlagsBitField,
|
|
3046
|
+
UserFlagsBits,
|
|
3047
|
+
UsersManager,
|
|
2755
3048
|
VoiceChannel,
|
|
2756
3049
|
Webhook,
|
|
2757
3050
|
cdnAvatarURL,
|
|
@@ -2760,5 +3053,6 @@ init_cdn();
|
|
|
2760
3053
|
cdnDisplayAvatarURL,
|
|
2761
3054
|
cdnMemberAvatarURL,
|
|
2762
3055
|
cdnMemberBannerURL,
|
|
3056
|
+
resolvePermissionsToBitfield,
|
|
2763
3057
|
resolveTenorToImageUrl
|
|
2764
3058
|
});
|