@discordjs/structures 0.2.0-dev.1752365789-3cff4d741

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/index.js ADDED
@@ -0,0 +1,1951 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ AnnouncementChannel: () => AnnouncementChannel,
25
+ AnnouncementThreadChannel: () => AnnouncementThreadChannel,
26
+ AppliedTagsMixin: () => AppliedTagsMixin,
27
+ AvatarDecorationData: () => AvatarDecorationData,
28
+ BitField: () => BitField,
29
+ CategoryChannel: () => CategoryChannel,
30
+ Channel: () => Channel,
31
+ ChannelFlagsBitField: () => ChannelFlagsBitField,
32
+ ChannelOwnerMixin: () => ChannelOwnerMixin,
33
+ ChannelParentMixin: () => ChannelParentMixin,
34
+ ChannelPermissionMixin: () => ChannelPermissionMixin,
35
+ ChannelPinMixin: () => ChannelPinMixin,
36
+ ChannelSlowmodeMixin: () => ChannelSlowmodeMixin,
37
+ ChannelTopicMixin: () => ChannelTopicMixin,
38
+ ChannelWebhookMixin: () => ChannelWebhookMixin,
39
+ Connection: () => Connection,
40
+ DMChannel: () => DMChannel,
41
+ DMChannelMixin: () => DMChannelMixin,
42
+ DataTemplatePropertyName: () => DataTemplatePropertyName,
43
+ ForumChannel: () => ForumChannel,
44
+ ForumTag: () => ForumTag,
45
+ GroupDMChannel: () => GroupDMChannel,
46
+ GroupDMMixin: () => GroupDMMixin,
47
+ GuildChannelMixin: () => GuildChannelMixin,
48
+ Invite: () => Invite,
49
+ MediaChannel: () => MediaChannel,
50
+ Mixin: () => Mixin,
51
+ OptimizeDataPropertyName: () => OptimizeDataPropertyName,
52
+ PermissionOverwrite: () => PermissionOverwrite,
53
+ PermissionsBitField: () => PermissionsBitField,
54
+ PrivateThreadChannel: () => PrivateThreadChannel,
55
+ PublicThreadChannel: () => PublicThreadChannel,
56
+ StageChannel: () => StageChannel,
57
+ Structure: () => Structure,
58
+ TextChannel: () => TextChannel,
59
+ TextChannelMixin: () => TextChannelMixin,
60
+ ThreadChannelMixin: () => ThreadChannelMixin,
61
+ ThreadMetadata: () => ThreadMetadata,
62
+ ThreadOnlyChannelMixin: () => ThreadOnlyChannelMixin,
63
+ User: () => User,
64
+ VoiceChannel: () => VoiceChannel,
65
+ VoiceChannelMixin: () => VoiceChannelMixin,
66
+ extendTemplate: () => extendTemplate
67
+ });
68
+ module.exports = __toCommonJS(index_exports);
69
+
70
+ // src/bitfields/BitField.ts
71
+ var BitField = class _BitField {
72
+ static {
73
+ __name(this, "BitField");
74
+ }
75
+ /**
76
+ * Numeric bit field flags.
77
+ *
78
+ * @remarks Defined in extension classes
79
+ */
80
+ static Flags = {};
81
+ static DefaultBit = 0n;
82
+ /**
83
+ * Bitfield of the packed bits
84
+ */
85
+ bitField;
86
+ /**
87
+ * @param bits - Bit(s) to read from
88
+ */
89
+ constructor(bits = this.constructor.DefaultBit) {
90
+ this.bitField = this.constructor.resolve(bits);
91
+ }
92
+ /**
93
+ * Checks whether the bit field has a bit, or any of multiple bits.
94
+ *
95
+ * @param bit - Bit(s) to check for
96
+ * @returns Whether the bit field has the bit(s)
97
+ */
98
+ any(bit) {
99
+ return (this.bitField & this.constructor.resolve(bit)) !== this.constructor.DefaultBit;
100
+ }
101
+ /**
102
+ * Checks if this bit field equals another
103
+ *
104
+ * @param bit - Bit(s) to check for
105
+ * @returns Whether this bit field equals the other
106
+ */
107
+ equals(bit) {
108
+ return this.bitField === this.constructor.resolve(bit);
109
+ }
110
+ /**
111
+ * Checks whether the bit field has a bit, or multiple bits.
112
+ *
113
+ * @param bit - Bit(s) to check for
114
+ * @returns Whether the bit field has the bit(s)
115
+ */
116
+ has(bit, ..._hasParams) {
117
+ const resolvedBit = this.constructor.resolve(bit);
118
+ return (this.bitField & resolvedBit) === resolvedBit;
119
+ }
120
+ /**
121
+ * Gets all given bits that are missing from the bit field.
122
+ *
123
+ * @param bits - Bit(s) to check for
124
+ * @param hasParams - Additional parameters for the has method, if any
125
+ * @returns A bit field containing the missing bits
126
+ */
127
+ missing(bits, ...hasParams) {
128
+ return new this.constructor(bits).remove(this).toArray(...hasParams);
129
+ }
130
+ /**
131
+ * Freezes these bits, making them immutable.
132
+ *
133
+ * @returns This bit field but frozen
134
+ */
135
+ freeze() {
136
+ return Object.freeze(this);
137
+ }
138
+ /**
139
+ * Adds bits to these ones.
140
+ *
141
+ * @param bits - Bits to add
142
+ * @returns These bits or new BitField if the instance is frozen.
143
+ */
144
+ add(...bits) {
145
+ let total = this.constructor.DefaultBit;
146
+ for (const bit of bits) {
147
+ total |= this.constructor.resolve(bit);
148
+ }
149
+ if (Object.isFrozen(this)) return new this.constructor(this.bitField | total);
150
+ this.bitField |= total;
151
+ return this;
152
+ }
153
+ /**
154
+ * Removes bits from these.
155
+ *
156
+ * @param bits - Bits to remove
157
+ * @returns These bits or new BitField if the instance is frozen.
158
+ */
159
+ remove(...bits) {
160
+ let total = this.constructor.DefaultBit;
161
+ for (const bit of bits) {
162
+ total |= this.constructor.resolve(bit);
163
+ }
164
+ if (Object.isFrozen(this)) return new this.constructor(this.bitField & ~total);
165
+ this.bitField &= ~total;
166
+ return this;
167
+ }
168
+ /**
169
+ * Gets an object mapping field names to a boolean indicating whether the bit is available.
170
+ *
171
+ * @param hasParams - Additional parameters for the has method, if any
172
+ * @returns An object mapping field names to a boolean indicating whether the bit is available
173
+ */
174
+ serialize(...hasParams) {
175
+ const serialized = {};
176
+ for (const [flag, bit] of Object.entries(this.constructor.Flags)) {
177
+ if (Number.isNaN(Number(flag))) serialized[flag] = this.has(bit, ...hasParams);
178
+ }
179
+ return serialized;
180
+ }
181
+ /**
182
+ * Gets an Array of bit field names based on the bits available.
183
+ *
184
+ * @param hasParams - Additional parameters for the has method, if any
185
+ * @returns An Array of bit field names
186
+ */
187
+ toArray(...hasParams) {
188
+ return [...this[Symbol.iterator](...hasParams)];
189
+ }
190
+ toJSON(asNumber) {
191
+ if (asNumber) {
192
+ if (this.bitField > Number.MAX_SAFE_INTEGER) {
193
+ throw new RangeError(
194
+ `Cannot convert bitfield value ${this.bitField} to number, as it is bigger than ${Number.MAX_SAFE_INTEGER} (the maximum safe integer)`
195
+ );
196
+ }
197
+ return Number(this.bitField);
198
+ }
199
+ return this.bitField.toString();
200
+ }
201
+ valueOf() {
202
+ return this.bitField;
203
+ }
204
+ *[Symbol.iterator](...hasParams) {
205
+ for (const bitName of Object.keys(this.constructor.Flags)) {
206
+ if (Number.isNaN(Number(bitName)) && this.has(bitName, ...hasParams)) yield bitName;
207
+ }
208
+ }
209
+ /**
210
+ * Resolves bit fields to their numeric form.
211
+ *
212
+ * @param bit - bit(s) to resolve
213
+ * @returns the numeric value of the bit fields
214
+ */
215
+ static resolve(bit) {
216
+ const DefaultBit = this.DefaultBit;
217
+ if (typeof bit === "bigint" && bit >= DefaultBit) return bit;
218
+ if (typeof bit === "number" && BigInt(bit) >= DefaultBit) return BigInt(bit);
219
+ if (bit instanceof _BitField) return bit.bitField;
220
+ if (Array.isArray(bit)) {
221
+ return bit.map((bit_) => this.resolve(bit_)).reduce((prev, bit_) => prev | bit_, DefaultBit);
222
+ }
223
+ if (typeof bit === "string") {
224
+ if (!Number.isNaN(Number(bit))) return BigInt(bit);
225
+ if (bit in this.Flags) return this.Flags[bit];
226
+ }
227
+ throw new Error(`BitFieldInvalid: ${JSON.stringify(bit)}`);
228
+ }
229
+ };
230
+
231
+ // src/bitfields/ChannelFlagsBitField.ts
232
+ var import_v10 = require("discord-api-types/v10");
233
+ var ChannelFlagsBitField = class extends BitField {
234
+ static {
235
+ __name(this, "ChannelFlagsBitField");
236
+ }
237
+ /**
238
+ * Numeric guild channel flags.
239
+ */
240
+ static Flags = import_v10.ChannelFlags;
241
+ toJSON() {
242
+ return super.toJSON(true);
243
+ }
244
+ };
245
+
246
+ // src/bitfields/PermissionsBitField.ts
247
+ var import_v102 = require("discord-api-types/v10");
248
+ var PermissionsBitField = class extends BitField {
249
+ static {
250
+ __name(this, "PermissionsBitField");
251
+ }
252
+ /**
253
+ * Numeric permission flags.
254
+ *
255
+ * @see {@link https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags}
256
+ */
257
+ static Flags = import_v102.PermissionFlagsBits;
258
+ /**
259
+ * Bit field representing every permission combined
260
+ */
261
+ static All = Object.values(import_v102.PermissionFlagsBits).reduce((all, perm) => all | perm, 0n);
262
+ /**
263
+ * Bit field representing the default permissions for users
264
+ */
265
+ static Default = 104324673n;
266
+ /**
267
+ * Bit field representing the permissions required for moderators of stage channels
268
+ */
269
+ static StageModerator = import_v102.PermissionFlagsBits.ManageChannels | import_v102.PermissionFlagsBits.MuteMembers | import_v102.PermissionFlagsBits.MoveMembers;
270
+ /**
271
+ * Gets all given bits that are missing from the bit field.
272
+ *
273
+ * @param bits - Bit(s) to check for
274
+ * @param checkAdmin - Whether to allow the administrator permission to override
275
+ * @returns A bit field containing the missing permissions
276
+ */
277
+ missing(bits, checkAdmin = true) {
278
+ return checkAdmin && this.has(import_v102.PermissionFlagsBits.Administrator) ? [] : super.missing(bits);
279
+ }
280
+ /**
281
+ * Checks whether the bit field has a permission, or any of multiple permissions.
282
+ *
283
+ * @param permission - Permission(s) to check for
284
+ * @param checkAdmin - Whether to allow the administrator permission to override
285
+ * @returns Whether the bit field has the permission(s)
286
+ */
287
+ any(permission, checkAdmin = true) {
288
+ return checkAdmin && super.has(import_v102.PermissionFlagsBits.Administrator) || super.any(permission);
289
+ }
290
+ /**
291
+ * Checks whether the bit field has a permission, or multiple permissions.
292
+ *
293
+ * @param permission - Permission(s) to check for
294
+ * @param checkAdmin - Whether to allow the administrator permission to override
295
+ * @returns Whether the bit field has the permission(s)
296
+ */
297
+ has(permission, checkAdmin = true) {
298
+ return checkAdmin && super.has(import_v102.PermissionFlagsBits.Administrator) || super.has(permission);
299
+ }
300
+ /**
301
+ * Gets an Array of bitfield names based on the permissions available.
302
+ *
303
+ * @returns An Array of permission names
304
+ */
305
+ toArray() {
306
+ return super.toArray(false);
307
+ }
308
+ };
309
+
310
+ // src/utils/symbols.ts
311
+ var kData = Symbol.for("djs.structures.data");
312
+ var kClone = Symbol.for("djs.structures.clone");
313
+ var kPatch = Symbol.for("djs.structures.patch");
314
+ var kExpiresTimestamp = Symbol.for("djs.structures.expiresTimestamp");
315
+ var kCreatedTimestamp = Symbol.for("djs.structures.createdTimestamp");
316
+ var kEditedTimestamp = Symbol.for("djs.structures.editedTimestamp");
317
+ var kArchiveTimestamp = Symbol.for("djs.structures.archiveTimestamp");
318
+ var kAllow = Symbol.for("djs.structures.allow");
319
+ var kDeny = Symbol.for("djs.structures.deny");
320
+ var kLastPinTimestamp = Symbol.for("djs.structures.lastPinTimestamp");
321
+ var kMixinConstruct = Symbol.for("djs.structures.mixin.construct");
322
+ var kMixinToJSON = Symbol.for("djs.structures.mixin.toJSON");
323
+
324
+ // src/channels/mixins/AppliedTagsMixin.ts
325
+ var AppliedTagsMixin = class {
326
+ static {
327
+ __name(this, "AppliedTagsMixin");
328
+ }
329
+ /**
330
+ * The ids of the set of tags that have been applied to a thread in a {@link (ForumChannel:class)} or a {@link (MediaChannel:class)}.
331
+ */
332
+ get appliedTags() {
333
+ return Array.isArray(this[kData].applied_tags) ? this[kData].applied_tags : null;
334
+ }
335
+ };
336
+
337
+ // src/channels/mixins/ChannelOwnerMixin.ts
338
+ var ChannelOwnerMixin = class {
339
+ static {
340
+ __name(this, "ChannelOwnerMixin");
341
+ }
342
+ /**
343
+ * The id of the creator of the group DM or thread
344
+ */
345
+ get ownerId() {
346
+ return this[kData].owner_id;
347
+ }
348
+ };
349
+
350
+ // src/channels/mixins/GuildChannelMixin.ts
351
+ var import_formatters = require("@discordjs/formatters");
352
+ var GuildChannelMixin = class {
353
+ static {
354
+ __name(this, "GuildChannelMixin");
355
+ }
356
+ /**
357
+ * The flags that are applied to the channel.
358
+ *
359
+ * @privateRemarks The type of `flags` can be narrowed in Guild Channels and DMChannel to ChannelFlags, and in GroupDM channel
360
+ * to null, respecting Omit behaviors
361
+ */
362
+ get flags() {
363
+ return this[kData].flags ? new ChannelFlagsBitField(this[kData].flags) : null;
364
+ }
365
+ /**
366
+ * THe id of the guild this channel is in.
367
+ */
368
+ get guildId() {
369
+ return this[kData].guild_id;
370
+ }
371
+ /**
372
+ * The URL to this channel.
373
+ */
374
+ get url() {
375
+ return (0, import_formatters.channelLink)(this.id, this.guildId);
376
+ }
377
+ /**
378
+ * Indicates whether this channel is in a guild
379
+ */
380
+ isGuildBased() {
381
+ return true;
382
+ }
383
+ };
384
+
385
+ // src/channels/mixins/ChannelParentMixin.ts
386
+ var ChannelParentMixin = class extends GuildChannelMixin {
387
+ static {
388
+ __name(this, "ChannelParentMixin");
389
+ }
390
+ /**
391
+ * The id of the parent category for a channel (each parent category can contain up to 50 channels) or id of the parent channel for a thread
392
+ */
393
+ get parentId() {
394
+ return this[kData].parent_id;
395
+ }
396
+ /**
397
+ * Whether the channel is nsfw
398
+ */
399
+ get nsfw() {
400
+ return this[kData].nsfw;
401
+ }
402
+ };
403
+
404
+ // src/channels/mixins/ChannelPermissionMixin.ts
405
+ var ChannelPermissionMixin = class {
406
+ static {
407
+ __name(this, "ChannelPermissionMixin");
408
+ }
409
+ /**
410
+ * The sorting position of the channel
411
+ */
412
+ get position() {
413
+ return this[kData].position;
414
+ }
415
+ /**
416
+ * Indicates whether this channel can have permission overwrites
417
+ */
418
+ isPermissionCapable() {
419
+ return true;
420
+ }
421
+ };
422
+
423
+ // src/channels/mixins/ChannelPinMixin.ts
424
+ var ChannelPinMixin = class {
425
+ static {
426
+ __name(this, "ChannelPinMixin");
427
+ }
428
+ /**
429
+ * The template used for removing data from the raw data stored for each Channel.
430
+ */
431
+ static DataTemplate = {
432
+ set last_pin_timestamp(_) {
433
+ }
434
+ };
435
+ [kMixinConstruct]() {
436
+ this[kLastPinTimestamp] ??= null;
437
+ }
438
+ /**
439
+ * {@inheritDoc Structure.optimizeData}
440
+ */
441
+ optimizeData(data) {
442
+ if (data.last_pin_timestamp) {
443
+ this[kLastPinTimestamp] = Date.parse(data.last_pin_timestamp);
444
+ }
445
+ }
446
+ /**
447
+ * The timestamp of when the last pin in the channel happened.
448
+ */
449
+ get lastPinTimestamp() {
450
+ return this[kLastPinTimestamp];
451
+ }
452
+ /**
453
+ * The Date of when the last pin in the channel happened
454
+ */
455
+ get lastPinAt() {
456
+ const lastPinTimestamp = this.lastPinTimestamp;
457
+ return lastPinTimestamp ? new Date(lastPinTimestamp) : null;
458
+ }
459
+ /**
460
+ * Adds data from optimized properties omitted from [kData].
461
+ *
462
+ * @param data - the result of {@link (Structure:class).toJSON}
463
+ */
464
+ [kMixinToJSON](data) {
465
+ data.last_pin_timestamp = this[kLastPinTimestamp] ? new Date(this[kLastPinTimestamp]).toISOString() : null;
466
+ }
467
+ };
468
+
469
+ // src/channels/mixins/TextChannelMixin.ts
470
+ var TextChannelMixin = class {
471
+ static {
472
+ __name(this, "TextChannelMixin");
473
+ }
474
+ /**
475
+ * The id of the last message sent in this channel.
476
+ */
477
+ get lastMessageId() {
478
+ return this[kData].last_message_id;
479
+ }
480
+ /**
481
+ * Indicates whether this channel can contain messages
482
+ */
483
+ isTextBased() {
484
+ return true;
485
+ }
486
+ };
487
+
488
+ // src/channels/mixins/ChannelSlowmodeMixin.ts
489
+ var ChannelSlowmodeMixin = class extends TextChannelMixin {
490
+ static {
491
+ __name(this, "ChannelSlowmodeMixin");
492
+ }
493
+ /**
494
+ * The rate limit per user (slowmode) of this channel.
495
+ */
496
+ get rateLimitPerUser() {
497
+ return this[kData].rate_limit_per_user;
498
+ }
499
+ };
500
+
501
+ // src/channels/mixins/ChannelWebhookMixin.ts
502
+ var ChannelWebhookMixin = class {
503
+ static {
504
+ __name(this, "ChannelWebhookMixin");
505
+ }
506
+ /**
507
+ * Indicates whether this channel can have webhooks
508
+ */
509
+ isWebhookCapable() {
510
+ return true;
511
+ }
512
+ };
513
+
514
+ // src/channels/mixins/ChannelTopicMixin.ts
515
+ var ChannelTopicMixin = class extends ChannelWebhookMixin {
516
+ static {
517
+ __name(this, "ChannelTopicMixin");
518
+ }
519
+ /**
520
+ * The topic of this channel.
521
+ */
522
+ get topic() {
523
+ return this[kData].topic;
524
+ }
525
+ /**
526
+ * The duration after which new threads get archived by default on this channel.
527
+ */
528
+ get defaultAutoArchiveDuration() {
529
+ return this[kData].default_auto_archive_duration;
530
+ }
531
+ /**
532
+ * The default value for rate limit per user (slowmode) on new threads in this channel.
533
+ */
534
+ get defaultThreadRateLimitPerUser() {
535
+ return this[kData].default_thread_rate_limit_per_user;
536
+ }
537
+ };
538
+
539
+ // src/channels/mixins/DMChannelMixin.ts
540
+ var import_formatters2 = require("@discordjs/formatters");
541
+ var DMChannelMixin = class {
542
+ static {
543
+ __name(this, "DMChannelMixin");
544
+ }
545
+ /**
546
+ * The URL to this channel.
547
+ */
548
+ get url() {
549
+ return (0, import_formatters2.channelLink)(this.id);
550
+ }
551
+ /**
552
+ * Indicates whether this channel is a DM or DM Group
553
+ */
554
+ isDMBased() {
555
+ return true;
556
+ }
557
+ };
558
+
559
+ // src/channels/mixins/GroupDMMixin.ts
560
+ var GroupDMMixin = class {
561
+ static {
562
+ __name(this, "GroupDMMixin");
563
+ }
564
+ /**
565
+ * The icon hash of the group DM.
566
+ */
567
+ get icon() {
568
+ return this[kData].icon;
569
+ }
570
+ /**
571
+ * Whether the channel is managed by an application via the `gdm.join` OAuth2 scope.
572
+ */
573
+ get managed() {
574
+ return this[kData].managed;
575
+ }
576
+ /**
577
+ * The application id of the group DM creator if it is bot-created.
578
+ */
579
+ get applicationId() {
580
+ return this[kData].application_id;
581
+ }
582
+ };
583
+
584
+ // src/channels/mixins/ThreadChannelMixin.ts
585
+ var ThreadChannelMixin = class {
586
+ static {
587
+ __name(this, "ThreadChannelMixin");
588
+ }
589
+ /**
590
+ * The approximate count of users in a thread, stops counting at 50
591
+ */
592
+ get memberCount() {
593
+ return this[kData].member_count;
594
+ }
595
+ /**
596
+ * The number of messages (not including the initial message or deleted messages) in a thread.
597
+ */
598
+ get messageCount() {
599
+ return this[kData].message_count;
600
+ }
601
+ /**
602
+ * The number of messages ever sent in a thread, it's similar to message_count on message creation,
603
+ * but will not decrement the number when a message is deleted.
604
+ */
605
+ get totalMessageSent() {
606
+ return this[kData].total_message_sent;
607
+ }
608
+ /**
609
+ * Indicates whether this channel is a thread channel
610
+ */
611
+ isThread() {
612
+ return true;
613
+ }
614
+ };
615
+
616
+ // src/channels/mixins/ThreadOnlyChannelMixin.ts
617
+ var ThreadOnlyChannelMixin = class {
618
+ static {
619
+ __name(this, "ThreadOnlyChannelMixin");
620
+ }
621
+ /**
622
+ * The emoji to show in the add reaction button on a thread in this channel.
623
+ */
624
+ get defaultReactionEmoji() {
625
+ return this[kData].default_reaction_emoji;
626
+ }
627
+ /**
628
+ * The default sort order type used to order posts in this channel.
629
+ *
630
+ * @defaultValue `null` – indicates a preferred sort order hasn't been set.
631
+ */
632
+ get defaultSortOrder() {
633
+ return this[kData].default_sort_order;
634
+ }
635
+ /**
636
+ * Indicates whether this channel only allows thread creation
637
+ */
638
+ isThreadOnly() {
639
+ return true;
640
+ }
641
+ };
642
+
643
+ // src/channels/mixins/VoiceChannelMixin.ts
644
+ var VoiceChannelMixin = class extends TextChannelMixin {
645
+ static {
646
+ __name(this, "VoiceChannelMixin");
647
+ }
648
+ /**
649
+ * The bitrate (in bits) of the voice channel.
650
+ */
651
+ get bitrate() {
652
+ return this[kData].bitrate;
653
+ }
654
+ /**
655
+ * The voice region id for this channel, automatic when set to null.
656
+ */
657
+ get rtcRegion() {
658
+ return this[kData].rtc_region;
659
+ }
660
+ /**
661
+ * The camera video quality mode of the voice channel, {@link discord-api-types/v10#(VideoQualityMode:enum) | Auto} when not present.
662
+ */
663
+ get videoQualityMode() {
664
+ return this[kData].video_quality_mode;
665
+ }
666
+ /**
667
+ * The user limit of the voice channel.
668
+ */
669
+ get userLimit() {
670
+ return this[kData].user_limit;
671
+ }
672
+ /**
673
+ * Indicates whether this channel has voice connection capabilities
674
+ */
675
+ isVoiceBased() {
676
+ return true;
677
+ }
678
+ };
679
+
680
+ // src/Structure.ts
681
+ var DataTemplatePropertyName = "DataTemplate";
682
+ var OptimizeDataPropertyName = "optimizeData";
683
+ var Structure = class {
684
+ static {
685
+ __name(this, "Structure");
686
+ }
687
+ /**
688
+ * The template used for removing data from the raw data stored for each Structure.
689
+ *
690
+ * @remarks This template should be overridden in all subclasses to provide more accurate type information.
691
+ * The template in the base {@link Structure} class will have no effect on most subclasses for this reason.
692
+ */
693
+ static DataTemplate = {};
694
+ /**
695
+ * @returns A cloned version of the data template, ready to create a new data object.
696
+ */
697
+ getDataTemplate() {
698
+ return Object.create(this.constructor.DataTemplate);
699
+ }
700
+ /**
701
+ * The raw data from the API for this structure
702
+ *
703
+ * @internal
704
+ */
705
+ [kData];
706
+ /**
707
+ * Creates a new structure to represent API data
708
+ *
709
+ * @param data - the data from the API that this structure will represent
710
+ * @remarks To be made public in subclasses
711
+ * @internal
712
+ */
713
+ constructor(data, ..._rest) {
714
+ this[kData] = Object.assign(this.getDataTemplate(), data);
715
+ this[kMixinConstruct]?.(data);
716
+ }
717
+ /**
718
+ * Patches the raw data of this object in place
719
+ *
720
+ * @param data - the updated data from the API to patch with
721
+ * @remarks To be made public in subclasses
722
+ * @returns this
723
+ * @internal
724
+ */
725
+ [kPatch](data) {
726
+ this[kData] = Object.assign(this.getDataTemplate(), this[kData], data);
727
+ this.optimizeData(data);
728
+ return this;
729
+ }
730
+ /**
731
+ * Creates a clone of this structure
732
+ *
733
+ * @returns a clone of this
734
+ * @internal
735
+ */
736
+ [kClone](patchPayload) {
737
+ const clone = this.toJSON();
738
+ return new this.constructor(
739
+ // Ensure the ts-expect-error only applies to the constructor call
740
+ patchPayload ? Object.assign(clone, patchPayload) : clone
741
+ );
742
+ }
743
+ /**
744
+ * Function called to ensure stored raw data is in optimized formats, used in tandem with a data template
745
+ *
746
+ * @example created_timestamp is an ISO string, this can be stored in optimized form as a number
747
+ * @param _data - the raw data received from the API to optimize
748
+ * @remarks Implementation to be done in subclasses and mixins where needed.
749
+ * For typescript users, mixins must use the closest ancestors access modifier.
750
+ * @remarks Automatically called in Structure[kPatch] but must be called manually in the constructor
751
+ * of any class implementing this method.
752
+ * @remarks Additionally, when implementing, ensure to call `super._optimizeData` if any class in the super chain aside
753
+ * from Structure contains an implementation.
754
+ * Note: mixins do not need to call super ever as the process of mixing walks the prototype chain.
755
+ * @virtual
756
+ * @internal
757
+ */
758
+ optimizeData(_data) {
759
+ }
760
+ /**
761
+ * Transforms this object to its JSON format with raw API data (or close to it),
762
+ * automatically called by `JSON.stringify()` when this structure is stringified
763
+ *
764
+ * @remarks
765
+ * The type of this data is determined by omissions at runtime and is only guaranteed for default omissions
766
+ * @privateRemarks
767
+ * When omitting properties at the library level, this must be overridden to re-add those properties
768
+ */
769
+ toJSON() {
770
+ const data = (
771
+ // Spread is way faster than structuredClone, but is shallow. So use it only if there is no nested objects
772
+ Object.values(this[kData]).some((value) => typeof value === "object" && value !== null) ? structuredClone(this[kData]) : { ...this[kData] }
773
+ );
774
+ this[kMixinToJSON]?.(data);
775
+ return data;
776
+ }
777
+ };
778
+
779
+ // src/channels/ForumTag.ts
780
+ var ForumTag = class extends Structure {
781
+ static {
782
+ __name(this, "ForumTag");
783
+ }
784
+ constructor(data) {
785
+ super(data);
786
+ }
787
+ /**
788
+ * The id of the tag.
789
+ */
790
+ get id() {
791
+ return this[kData].id;
792
+ }
793
+ /**
794
+ * The name of the tag.
795
+ */
796
+ get name() {
797
+ return this[kData].name;
798
+ }
799
+ /**
800
+ * Whether this tag can only be added to or removed from threads by a member with the {@link discord-api-types/v10#(PermissionFlagsBits:variable) | ManageThreads} permission.
801
+ */
802
+ get moderated() {
803
+ return this[kData].moderated;
804
+ }
805
+ /**
806
+ * The id of a guild's custom emoji.
807
+ */
808
+ get emojiId() {
809
+ return this[kData].emoji_id;
810
+ }
811
+ /**
812
+ * The unicode character of the emoji.
813
+ */
814
+ get emojiName() {
815
+ return this[kData].emoji_name;
816
+ }
817
+ /**
818
+ * The textual representation of this tag's emoji. Either a unicode character or a guild emoji mention.
819
+ */
820
+ get emoji() {
821
+ return this.emojiName ?? `<:_:${this.emojiId}>`;
822
+ }
823
+ };
824
+
825
+ // src/channels/PermissionOverwrite.ts
826
+ var PermissionOverwrite = class extends Structure {
827
+ static {
828
+ __name(this, "PermissionOverwrite");
829
+ }
830
+ [kAllow] = null;
831
+ [kDeny] = null;
832
+ constructor(data) {
833
+ super(data);
834
+ this.optimizeData(data);
835
+ }
836
+ /**
837
+ * The template used for removing data from the raw data stored for each ThreadMetadata
838
+ *
839
+ * @remarks This template has defaults, if you want to remove additional data and keep the defaults,
840
+ * use `Object.defineProperties`. To override the defaults, set this value directly.
841
+ */
842
+ static DataTemplate = {
843
+ set allow(_) {
844
+ },
845
+ set deny(_) {
846
+ }
847
+ };
848
+ /**
849
+ * {@inheritDoc Structure.optimizeData}
850
+ */
851
+ optimizeData(data) {
852
+ if (data.allow) {
853
+ this[kAllow] = BigInt(data.allow);
854
+ }
855
+ if (data.deny) {
856
+ this[kDeny] = BigInt(data.deny);
857
+ }
858
+ }
859
+ /**
860
+ * The permission bit set allowed by this overwrite.
861
+ */
862
+ get allow() {
863
+ const allow = this[kAllow];
864
+ return typeof allow === "bigint" ? new PermissionsBitField(allow) : null;
865
+ }
866
+ /**
867
+ * The permission bit set denied by this overwrite.
868
+ */
869
+ get deny() {
870
+ const deny = this[kDeny];
871
+ return typeof deny === "bigint" ? new PermissionsBitField(deny) : null;
872
+ }
873
+ /**
874
+ * The role or user id for this overwrite.
875
+ */
876
+ get id() {
877
+ return this[kData].id;
878
+ }
879
+ /**
880
+ * The type of this overwrite.
881
+ */
882
+ get type() {
883
+ return this[kData].type;
884
+ }
885
+ /**
886
+ * {@inheritDoc Structure.toJSON}
887
+ */
888
+ toJSON() {
889
+ const clone = super.toJSON();
890
+ if (this[kAllow]) {
891
+ clone.allow = this[kAllow].toString();
892
+ }
893
+ if (this[kDeny]) {
894
+ clone.deny = this[kDeny].toString();
895
+ }
896
+ return clone;
897
+ }
898
+ };
899
+
900
+ // src/channels/ThreadMetadata.ts
901
+ var ThreadMetadata = class extends Structure {
902
+ static {
903
+ __name(this, "ThreadMetadata");
904
+ }
905
+ [kArchiveTimestamp] = null;
906
+ [kCreatedTimestamp] = null;
907
+ constructor(data) {
908
+ super(data);
909
+ this.optimizeData(data);
910
+ }
911
+ /**
912
+ * The template used for removing data from the raw data stored for each ThreadMetadata
913
+ *
914
+ * @remarks This template has defaults, if you want to remove additional data and keep the defaults,
915
+ * use `Object.defineProperties`. To override the defaults, set this value directly.
916
+ */
917
+ static DataTemplate = {
918
+ set create_timestamp(_) {
919
+ },
920
+ set archive_timestamp(_) {
921
+ }
922
+ };
923
+ /**
924
+ * {@inheritDoc Structure.optimizeData}
925
+ */
926
+ optimizeData(data) {
927
+ if (data.create_timestamp) {
928
+ this[kCreatedTimestamp] = Date.parse(data.create_timestamp);
929
+ }
930
+ if (data.archive_timestamp) {
931
+ this[kArchiveTimestamp] = Date.parse(data.archive_timestamp);
932
+ }
933
+ }
934
+ /**
935
+ * Whether the thread is archived.
936
+ */
937
+ get archived() {
938
+ return this[kData].archived;
939
+ }
940
+ /**
941
+ * The timestamp when the thread's archive status was last changed, used for calculating recent activity.
942
+ */
943
+ get archivedTimestamp() {
944
+ return this[kArchiveTimestamp];
945
+ }
946
+ /**
947
+ * The timestamp when the thread was created; only populated for threads created after 2022-01-09.
948
+ */
949
+ get createdTimestamp() {
950
+ return this[kCreatedTimestamp];
951
+ }
952
+ /**
953
+ * The thread will stop showing in the channel list after auto_archive_duration minutes of inactivity,
954
+ */
955
+ get autoArchiveDuration() {
956
+ return this[kData].auto_archive_duration;
957
+ }
958
+ /**
959
+ * Whether non-moderators can add other non-moderators to a thread; only available on private threads.
960
+ */
961
+ get invitable() {
962
+ return this[kData].invitable;
963
+ }
964
+ /**
965
+ * Whether the thread is locked; when a thread is locked, only users with {@link discord-api-types/v10#(PermissionFlagsBits:variable) | ManageThreads} can unarchive it.
966
+ */
967
+ get locked() {
968
+ return this[kData].locked;
969
+ }
970
+ /**
971
+ * The time the thread was archived at
972
+ */
973
+ get archivedAt() {
974
+ const archivedTimestamp = this.archivedTimestamp;
975
+ return archivedTimestamp ? new Date(archivedTimestamp) : null;
976
+ }
977
+ /**
978
+ * The time the thread was created at
979
+ */
980
+ get createdAt() {
981
+ const createdTimestamp = this.createdTimestamp;
982
+ return createdTimestamp ? new Date(createdTimestamp) : null;
983
+ }
984
+ /**
985
+ * {@inheritDoc Structure.toJSON}
986
+ */
987
+ toJSON() {
988
+ const data = super.toJSON();
989
+ if (this[kArchiveTimestamp]) {
990
+ data.archive_timestamp = new Date(this[kArchiveTimestamp]).toISOString();
991
+ }
992
+ if (this[kCreatedTimestamp]) {
993
+ data.create_timestamp = new Date(this[kCreatedTimestamp]).toISOString();
994
+ }
995
+ return data;
996
+ }
997
+ };
998
+
999
+ // src/channels/Channel.ts
1000
+ var import_snowflake = require("@sapphire/snowflake");
1001
+
1002
+ // src/utils/type-guards.ts
1003
+ function isIdSet(id) {
1004
+ return typeof id === "string" || typeof id === "bigint";
1005
+ }
1006
+ __name(isIdSet, "isIdSet");
1007
+
1008
+ // src/channels/Channel.ts
1009
+ var Channel = class extends Structure {
1010
+ static {
1011
+ __name(this, "Channel");
1012
+ }
1013
+ /**
1014
+ * The template used for removing data from the raw data stored for each Channel.
1015
+ *
1016
+ * @remarks This template is only guaranteed to apply to channels constructed directly via `new Channel()`.
1017
+ * Use the appropriate subclass template to remove data from that channel type.
1018
+ */
1019
+ static DataTemplate = {};
1020
+ /**
1021
+ * @param data - The raw data received from the API for the channel
1022
+ */
1023
+ constructor(data) {
1024
+ super(data);
1025
+ }
1026
+ /**
1027
+ * {@inheritDoc Structure.[kPatch]}
1028
+ *
1029
+ * @internal
1030
+ */
1031
+ [kPatch](data) {
1032
+ return super[kPatch](data);
1033
+ }
1034
+ /**
1035
+ * The id of the channel
1036
+ */
1037
+ get id() {
1038
+ return this[kData].id;
1039
+ }
1040
+ /**
1041
+ * The type of the channel
1042
+ */
1043
+ get type() {
1044
+ return this[kData].type;
1045
+ }
1046
+ /**
1047
+ * The name of the channel, null for DMs
1048
+ *
1049
+ * @privateRemarks The type of `name` can be narrowed in Guild Channels and DM channels to string and null respectively,
1050
+ * respecting Omit behaviors
1051
+ */
1052
+ get name() {
1053
+ return this[kData].name;
1054
+ }
1055
+ /**
1056
+ * The flags that are applied to the channel.
1057
+ *
1058
+ * @privateRemarks The type of `flags` can be narrowed in Guild Channels and DMChannel to ChannelFlags, and in GroupDM channel
1059
+ * to null, respecting Omit behaviors
1060
+ */
1061
+ get flags() {
1062
+ const flags = "flags" in this[kData] && typeof this[kData].flags === "number" ? this[kData].flags : null;
1063
+ return flags ? new ChannelFlagsBitField(flags) : null;
1064
+ }
1065
+ /**
1066
+ * The timestamp the channel was created at
1067
+ */
1068
+ get createdTimestamp() {
1069
+ return isIdSet(this.id) ? import_snowflake.DiscordSnowflake.timestampFrom(this.id) : null;
1070
+ }
1071
+ /**
1072
+ * The time the channel was created at
1073
+ */
1074
+ get createdAt() {
1075
+ const createdTimestamp = this.createdTimestamp;
1076
+ return createdTimestamp ? new Date(createdTimestamp) : null;
1077
+ }
1078
+ /**
1079
+ * Indicates whether this channel is a thread channel
1080
+ *
1081
+ * @privateRemarks Overridden to `true` on `ThreadChannelMixin`
1082
+ */
1083
+ isThread() {
1084
+ return false;
1085
+ }
1086
+ /**
1087
+ * Indicates whether this channel can contain messages
1088
+ *
1089
+ * @privateRemarks Overridden to `true` on `TextChannelMixin`
1090
+ */
1091
+ isTextBased() {
1092
+ return false;
1093
+ }
1094
+ /**
1095
+ * Indicates whether this channel is in a guild
1096
+ *
1097
+ * @privateRemarks Overridden to `true` on `GuildChannelMixin`
1098
+ */
1099
+ isGuildBased() {
1100
+ return false;
1101
+ }
1102
+ /**
1103
+ * Indicates whether this channel is a DM or DM Group
1104
+ *
1105
+ * @privateRemarks Overridden to `true` on `DMChannelMixin`
1106
+ */
1107
+ isDMBased() {
1108
+ return false;
1109
+ }
1110
+ /**
1111
+ * Indicates whether this channel has voice connection capabilities
1112
+ *
1113
+ * @privateRemarks Overridden to `true` on `VoiceChannelMixin`
1114
+ */
1115
+ isVoiceBased() {
1116
+ return false;
1117
+ }
1118
+ /**
1119
+ * Indicates whether this channel only allows thread creation
1120
+ *
1121
+ * @privateRemarks Overridden to `true` on `ThreadOnlyChannelMixin`
1122
+ */
1123
+ isThreadOnly() {
1124
+ return false;
1125
+ }
1126
+ /**
1127
+ * Indicates whether this channel can have permission overwrites
1128
+ *
1129
+ * @privateRemarks Overridden to `true` on `ChannelPermissionsMixin`
1130
+ */
1131
+ isPermissionCapable() {
1132
+ return false;
1133
+ }
1134
+ /**
1135
+ * Indicates whether this channel can have webhooks
1136
+ *
1137
+ * @privateRemarks Overridden to `true` on `ChannelWebhooksMixin`
1138
+ */
1139
+ isWebhookCapable() {
1140
+ return false;
1141
+ }
1142
+ };
1143
+
1144
+ // src/Mixin.ts
1145
+ function Mixin(destination, mixins) {
1146
+ const dataTemplates = [];
1147
+ const dataOptimizations = [];
1148
+ const enrichToJSONs = [];
1149
+ const constructors = [];
1150
+ for (const mixin of mixins) {
1151
+ const prototypeChain = [];
1152
+ let extendedClass = mixin;
1153
+ while (extendedClass.prototype !== void 0) {
1154
+ if (DataTemplatePropertyName in extendedClass && typeof extendedClass.DataTemplate === "object" && // eslint-disable-next-line no-eq-null, eqeqeq
1155
+ extendedClass.DataTemplate != null) {
1156
+ dataTemplates.push(extendedClass.DataTemplate);
1157
+ }
1158
+ prototypeChain.unshift(extendedClass.prototype);
1159
+ extendedClass = Object.getPrototypeOf(extendedClass);
1160
+ }
1161
+ for (const prototype of prototypeChain) {
1162
+ if (prototype[kMixinConstruct]) {
1163
+ constructors.push(prototype[kMixinConstruct]);
1164
+ }
1165
+ if (prototype[kMixinToJSON]) {
1166
+ enrichToJSONs.push(prototype[kMixinToJSON]);
1167
+ }
1168
+ const originalDescriptors = Object.getOwnPropertyDescriptors(prototype);
1169
+ const usingDescriptors = {};
1170
+ for (const [prop, descriptor] of Object.entries(originalDescriptors)) {
1171
+ if (["constructor"].includes(prop)) {
1172
+ continue;
1173
+ }
1174
+ if (prop === OptimizeDataPropertyName) {
1175
+ if (typeof descriptor.value !== "function")
1176
+ throw new RangeError(`Expected ${prop} to be a function, received ${typeof descriptor.value} instead.`);
1177
+ dataOptimizations.push(descriptor.value);
1178
+ continue;
1179
+ }
1180
+ if (typeof descriptor.get !== "undefined" || typeof descriptor.set !== "undefined" || typeof descriptor.value === "function") {
1181
+ usingDescriptors[prop] = descriptor;
1182
+ }
1183
+ }
1184
+ Object.defineProperties(destination.prototype, usingDescriptors);
1185
+ }
1186
+ }
1187
+ if (constructors.length > 0) {
1188
+ Object.defineProperty(destination.prototype, kMixinConstruct, {
1189
+ writable: true,
1190
+ enumerable: false,
1191
+ configurable: true,
1192
+ // eslint-disable-next-line func-name-matching
1193
+ value: /* @__PURE__ */ __name(function _mixinConstructors(data) {
1194
+ for (const construct of constructors) {
1195
+ construct.call(this, data);
1196
+ }
1197
+ }, "_mixinConstructors")
1198
+ });
1199
+ }
1200
+ const baseOptimize = Object.getOwnPropertyDescriptor(destination, OptimizeDataPropertyName);
1201
+ if (baseOptimize && typeof baseOptimize.value === "function") {
1202
+ dataOptimizations.push(baseOptimize.value);
1203
+ }
1204
+ const superOptimize = Object.getOwnPropertyDescriptor(
1205
+ Object.getPrototypeOf(destination).prototype,
1206
+ OptimizeDataPropertyName
1207
+ );
1208
+ if (!baseOptimize && superOptimize && typeof superOptimize.value === "function") {
1209
+ dataOptimizations.unshift(superOptimize.value);
1210
+ }
1211
+ if (dataOptimizations.length > 1 || dataOptimizations.length === 1 && !baseOptimize) {
1212
+ Object.defineProperty(destination.prototype, OptimizeDataPropertyName, {
1213
+ writable: true,
1214
+ enumerable: false,
1215
+ configurable: true,
1216
+ // eslint-disable-next-line func-name-matching
1217
+ value: /* @__PURE__ */ __name(function _mixinOptimizeData(data) {
1218
+ for (const optimization of dataOptimizations) {
1219
+ optimization.call(this, data);
1220
+ }
1221
+ }, "_mixinOptimizeData")
1222
+ });
1223
+ }
1224
+ if (enrichToJSONs.length > 0) {
1225
+ Object.defineProperty(destination.prototype, kMixinToJSON, {
1226
+ writable: true,
1227
+ enumerable: false,
1228
+ configurable: true,
1229
+ // eslint-disable-next-line func-name-matching
1230
+ value: /* @__PURE__ */ __name(function _mixinToJSON(data) {
1231
+ for (const enricher of enrichToJSONs) {
1232
+ enricher.call(this, data);
1233
+ }
1234
+ }, "_mixinToJSON")
1235
+ });
1236
+ }
1237
+ if (dataTemplates.length > 0) {
1238
+ if (!Object.getOwnPropertyDescriptor(destination, DataTemplatePropertyName)) {
1239
+ Object.defineProperty(destination, DataTemplatePropertyName, {
1240
+ value: Object.defineProperties({}, Object.getOwnPropertyDescriptors(destination[DataTemplatePropertyName])),
1241
+ writable: true,
1242
+ enumerable: true,
1243
+ configurable: true
1244
+ });
1245
+ }
1246
+ for (const template of dataTemplates) {
1247
+ Object.defineProperties(destination[DataTemplatePropertyName], Object.getOwnPropertyDescriptors(template));
1248
+ }
1249
+ }
1250
+ }
1251
+ __name(Mixin, "Mixin");
1252
+
1253
+ // src/channels/AnnouncementChannel.ts
1254
+ var AnnouncementChannel = class extends Channel {
1255
+ static {
1256
+ __name(this, "AnnouncementChannel");
1257
+ }
1258
+ constructor(data) {
1259
+ super(data);
1260
+ this.optimizeData(data);
1261
+ }
1262
+ };
1263
+ Mixin(AnnouncementChannel, [
1264
+ TextChannelMixin,
1265
+ ChannelParentMixin,
1266
+ ChannelPermissionMixin,
1267
+ ChannelPinMixin,
1268
+ ChannelSlowmodeMixin,
1269
+ ChannelTopicMixin
1270
+ ]);
1271
+
1272
+ // src/channels/AnnouncementThreadChannel.ts
1273
+ var AnnouncementThreadChannel = class extends Channel {
1274
+ static {
1275
+ __name(this, "AnnouncementThreadChannel");
1276
+ }
1277
+ constructor(data) {
1278
+ super(data);
1279
+ this.optimizeData?.(data);
1280
+ }
1281
+ };
1282
+ Mixin(AnnouncementThreadChannel, [
1283
+ TextChannelMixin,
1284
+ ChannelOwnerMixin,
1285
+ ChannelParentMixin,
1286
+ ChannelPinMixin,
1287
+ ChannelSlowmodeMixin,
1288
+ GuildChannelMixin,
1289
+ ThreadChannelMixin
1290
+ ]);
1291
+
1292
+ // src/channels/CategoryChannel.ts
1293
+ var CategoryChannel = class extends Channel {
1294
+ static {
1295
+ __name(this, "CategoryChannel");
1296
+ }
1297
+ constructor(data) {
1298
+ super(data);
1299
+ this.optimizeData(data);
1300
+ }
1301
+ };
1302
+ Mixin(CategoryChannel, [ChannelPermissionMixin, GuildChannelMixin]);
1303
+
1304
+ // src/channels/DMChannel.ts
1305
+ var DMChannel = class extends Channel {
1306
+ static {
1307
+ __name(this, "DMChannel");
1308
+ }
1309
+ constructor(data) {
1310
+ super(data);
1311
+ this.optimizeData(data);
1312
+ }
1313
+ };
1314
+ Mixin(DMChannel, [DMChannelMixin, TextChannelMixin, ChannelPinMixin]);
1315
+
1316
+ // src/channels/ForumChannel.ts
1317
+ var ForumChannel = class extends Channel {
1318
+ static {
1319
+ __name(this, "ForumChannel");
1320
+ }
1321
+ constructor(data) {
1322
+ super(data);
1323
+ this.optimizeData(data);
1324
+ }
1325
+ /**
1326
+ * The default forum layout view used to display posts in this channel.
1327
+ * Defaults to 0, which indicates a layout view has not been set by a channel admin.
1328
+ */
1329
+ get defaultForumLayout() {
1330
+ return this[kData].default_forum_layout;
1331
+ }
1332
+ };
1333
+ Mixin(ForumChannel, [ChannelParentMixin, ChannelPermissionMixin, ChannelTopicMixin, ThreadOnlyChannelMixin]);
1334
+
1335
+ // src/channels/GroupDMChannel.ts
1336
+ var GroupDMChannel = class extends Channel {
1337
+ static {
1338
+ __name(this, "GroupDMChannel");
1339
+ }
1340
+ constructor(data) {
1341
+ super(data);
1342
+ this.optimizeData(data);
1343
+ }
1344
+ };
1345
+ Mixin(GroupDMChannel, [DMChannelMixin, TextChannelMixin, ChannelOwnerMixin, GroupDMMixin]);
1346
+
1347
+ // src/channels/MediaChannel.ts
1348
+ var MediaChannel = class extends Channel {
1349
+ static {
1350
+ __name(this, "MediaChannel");
1351
+ }
1352
+ constructor(data) {
1353
+ super(data);
1354
+ this.optimizeData(data);
1355
+ }
1356
+ };
1357
+ Mixin(MediaChannel, [ChannelParentMixin, ChannelPermissionMixin, ChannelTopicMixin, ThreadOnlyChannelMixin]);
1358
+
1359
+ // src/channels/PrivateThreadChannel.ts
1360
+ var PrivateThreadChannel = class extends Channel {
1361
+ static {
1362
+ __name(this, "PrivateThreadChannel");
1363
+ }
1364
+ constructor(data) {
1365
+ super(data);
1366
+ this.optimizeData(data);
1367
+ }
1368
+ };
1369
+ Mixin(PrivateThreadChannel, [
1370
+ TextChannelMixin,
1371
+ ChannelOwnerMixin,
1372
+ ChannelParentMixin,
1373
+ ChannelPinMixin,
1374
+ ChannelSlowmodeMixin,
1375
+ ThreadChannelMixin
1376
+ ]);
1377
+
1378
+ // src/channels/PublicThreadChannel.ts
1379
+ var PublicThreadChannel = class extends Channel {
1380
+ static {
1381
+ __name(this, "PublicThreadChannel");
1382
+ }
1383
+ constructor(data) {
1384
+ super(data);
1385
+ this.optimizeData(data);
1386
+ }
1387
+ };
1388
+ Mixin(PublicThreadChannel, [
1389
+ TextChannelMixin,
1390
+ ChannelOwnerMixin,
1391
+ ChannelParentMixin,
1392
+ ChannelPinMixin,
1393
+ ChannelSlowmodeMixin,
1394
+ ThreadChannelMixin,
1395
+ AppliedTagsMixin
1396
+ ]);
1397
+
1398
+ // src/channels/StageChannel.ts
1399
+ var StageChannel = class extends Channel {
1400
+ static {
1401
+ __name(this, "StageChannel");
1402
+ }
1403
+ constructor(data) {
1404
+ super(data);
1405
+ this.optimizeData(data);
1406
+ }
1407
+ };
1408
+ Mixin(StageChannel, [
1409
+ ChannelParentMixin,
1410
+ ChannelPermissionMixin,
1411
+ ChannelSlowmodeMixin,
1412
+ ChannelWebhookMixin,
1413
+ VoiceChannelMixin
1414
+ ]);
1415
+
1416
+ // src/channels/TextChannel.ts
1417
+ var TextChannel = class extends Channel {
1418
+ static {
1419
+ __name(this, "TextChannel");
1420
+ }
1421
+ constructor(data) {
1422
+ super(data);
1423
+ this.optimizeData(data);
1424
+ }
1425
+ };
1426
+ Mixin(TextChannel, [
1427
+ TextChannelMixin,
1428
+ ChannelParentMixin,
1429
+ ChannelPermissionMixin,
1430
+ ChannelPinMixin,
1431
+ ChannelSlowmodeMixin,
1432
+ ChannelTopicMixin
1433
+ ]);
1434
+
1435
+ // src/channels/VoiceChannel.ts
1436
+ var VoiceChannel = class extends Channel {
1437
+ static {
1438
+ __name(this, "VoiceChannel");
1439
+ }
1440
+ constructor(data) {
1441
+ super(data);
1442
+ this.optimizeData(data);
1443
+ }
1444
+ };
1445
+ Mixin(VoiceChannel, [
1446
+ ChannelParentMixin,
1447
+ ChannelPermissionMixin,
1448
+ ChannelSlowmodeMixin,
1449
+ ChannelWebhookMixin,
1450
+ VoiceChannelMixin
1451
+ ]);
1452
+
1453
+ // src/invites/Invite.ts
1454
+ var import_v103 = require("discord-api-types/v10");
1455
+ var Invite = class extends Structure {
1456
+ static {
1457
+ __name(this, "Invite");
1458
+ }
1459
+ /**
1460
+ * The template used for removing data from the raw data stored for each Invite
1461
+ *
1462
+ * @remarks This template has defaults, if you want to remove additional data and keep the defaults,
1463
+ * use `Object.defineProperties`. To override the defaults, set this value directly.
1464
+ */
1465
+ static DataTemplate = {
1466
+ set created_at(_) {
1467
+ },
1468
+ set expires_at(_) {
1469
+ }
1470
+ };
1471
+ /**
1472
+ * Optimized storage of {@link discord-api-types/v10#(APIActualInvite:interface).expires_at}
1473
+ *
1474
+ * @internal
1475
+ */
1476
+ [kExpiresTimestamp] = null;
1477
+ /**
1478
+ * Optimized storage of {@link discord-api-types/v10#(APIActualInvite:interface).created_at}
1479
+ *
1480
+ * @internal
1481
+ */
1482
+ [kCreatedTimestamp] = null;
1483
+ /**
1484
+ * @param data - The raw data received from the API for the invite
1485
+ */
1486
+ constructor(data) {
1487
+ super(data);
1488
+ this.optimizeData(data);
1489
+ }
1490
+ /**
1491
+ * {@inheritDoc Structure.[kPatch]}
1492
+ *
1493
+ * @internal
1494
+ */
1495
+ [kPatch](data) {
1496
+ super[kPatch](data);
1497
+ return this;
1498
+ }
1499
+ /**
1500
+ * {@inheritDoc Structure.optimizeData}
1501
+ *
1502
+ * @internal
1503
+ */
1504
+ optimizeData(data) {
1505
+ if (data.expires_at) {
1506
+ this[kExpiresTimestamp] = Date.parse(data.expires_at);
1507
+ }
1508
+ if (data.created_at) {
1509
+ this[kCreatedTimestamp] = Date.parse(data.created_at);
1510
+ }
1511
+ }
1512
+ /**
1513
+ * The code for this invite
1514
+ */
1515
+ get code() {
1516
+ return this[kData].code;
1517
+ }
1518
+ /**
1519
+ * The target type (for voice channel invites)
1520
+ */
1521
+ get targetType() {
1522
+ return this[kData].target_type;
1523
+ }
1524
+ /**
1525
+ * The type of this invite
1526
+ */
1527
+ get type() {
1528
+ return this[kData].type;
1529
+ }
1530
+ /**
1531
+ * The approximate number of online members of the guild this invite is for
1532
+ *
1533
+ * @remarks Only available when the invite was fetched from `GET /invites/<code>` with counts
1534
+ */
1535
+ get approximatePresenceCount() {
1536
+ return this[kData].approximate_presence_count;
1537
+ }
1538
+ /**
1539
+ * The approximate total number of members of the guild this invite is for
1540
+ *
1541
+ * @remarks Only available when the invite was fetched from `GET /invites/<code>` with counts
1542
+ */
1543
+ get approximateMemberCount() {
1544
+ return this[kData].approximate_member_count;
1545
+ }
1546
+ /**
1547
+ * The timestamp this invite will expire at
1548
+ */
1549
+ get expiresTimestamp() {
1550
+ if (this[kExpiresTimestamp]) {
1551
+ return this[kExpiresTimestamp];
1552
+ }
1553
+ const createdTimestamp = this.createdTimestamp;
1554
+ const maxAge = this.maxAge;
1555
+ if (createdTimestamp && maxAge) {
1556
+ this[kExpiresTimestamp] = createdTimestamp + maxAge * 1e3;
1557
+ }
1558
+ return this[kExpiresTimestamp];
1559
+ }
1560
+ /**
1561
+ * The time the invite will expire at
1562
+ */
1563
+ get expiresAt() {
1564
+ const expiresTimestamp = this.expiresTimestamp;
1565
+ return expiresTimestamp ? new Date(expiresTimestamp) : null;
1566
+ }
1567
+ /**
1568
+ * The number of times this invite has been used
1569
+ */
1570
+ get uses() {
1571
+ return this[kData].uses;
1572
+ }
1573
+ /**
1574
+ * The maximum number of times this invite can be used
1575
+ */
1576
+ get maxUses() {
1577
+ return this[kData].max_uses;
1578
+ }
1579
+ /**
1580
+ * The maximum age of the invite, in seconds, 0 for non-expiring
1581
+ */
1582
+ get maxAge() {
1583
+ return this[kData].max_age;
1584
+ }
1585
+ /**
1586
+ * Whether this invite only grants temporary membership
1587
+ */
1588
+ get temporary() {
1589
+ return this[kData].temporary;
1590
+ }
1591
+ /**
1592
+ * The timestamp this invite was created at
1593
+ */
1594
+ get createdTimestamp() {
1595
+ return this[kCreatedTimestamp];
1596
+ }
1597
+ /**
1598
+ * The time the invite was created at
1599
+ */
1600
+ get createdAt() {
1601
+ const createdTimestamp = this.createdTimestamp;
1602
+ return createdTimestamp ? new Date(createdTimestamp) : null;
1603
+ }
1604
+ /**
1605
+ * The URL to the invite
1606
+ */
1607
+ get url() {
1608
+ return this.code ? `${import_v103.RouteBases.invite}/${this.code}` : null;
1609
+ }
1610
+ /**
1611
+ * When concatenated with a string, this automatically concatenates the invite's URL instead of the object.
1612
+ *
1613
+ * @returns The URL to the invite or an empty string if it doesn't have a code
1614
+ */
1615
+ toString() {
1616
+ return this.url ?? "";
1617
+ }
1618
+ /**
1619
+ * {@inheritDoc Structure.toJSON}
1620
+ */
1621
+ toJSON() {
1622
+ const clone = super.toJSON();
1623
+ if (this[kExpiresTimestamp]) {
1624
+ clone.expires_at = new Date(this[kExpiresTimestamp]).toISOString();
1625
+ }
1626
+ if (this[kCreatedTimestamp]) {
1627
+ clone.created_at = new Date(this[kCreatedTimestamp]).toISOString();
1628
+ }
1629
+ return clone;
1630
+ }
1631
+ /**
1632
+ * Returns the primitive value of the specified object.
1633
+ */
1634
+ valueOf() {
1635
+ return this.code ?? super.valueOf();
1636
+ }
1637
+ };
1638
+
1639
+ // src/users/AvatarDecorationData.ts
1640
+ var AvatarDecorationData = class extends Structure {
1641
+ static {
1642
+ __name(this, "AvatarDecorationData");
1643
+ }
1644
+ /**
1645
+ * The template used for removing data from the raw data stored for each Connection
1646
+ */
1647
+ static DataTemplate = {};
1648
+ /**
1649
+ * @param data - The raw data received from the API for the connection
1650
+ */
1651
+ constructor(data) {
1652
+ super(data);
1653
+ }
1654
+ /**
1655
+ * The id of the SKU this avatar decoration is part of.
1656
+ */
1657
+ get skuId() {
1658
+ return this[kData].sku_id;
1659
+ }
1660
+ /**
1661
+ * The asset of this avatar decoration.
1662
+ */
1663
+ get asset() {
1664
+ return this[kData].asset;
1665
+ }
1666
+ };
1667
+
1668
+ // src/users/User.ts
1669
+ var import_snowflake2 = require("@sapphire/snowflake");
1670
+ var User = class extends Structure {
1671
+ static {
1672
+ __name(this, "User");
1673
+ }
1674
+ /**
1675
+ * The template used for removing data from the raw data stored for each User
1676
+ */
1677
+ static DataTemplate = {};
1678
+ /**
1679
+ * @param data - The raw data received from the API for the user
1680
+ */
1681
+ constructor(data) {
1682
+ super(data);
1683
+ }
1684
+ /**
1685
+ * {@inheritDoc Structure.[kPatch]}
1686
+ *
1687
+ * @internal
1688
+ */
1689
+ [kPatch](data) {
1690
+ return super[kPatch](data);
1691
+ }
1692
+ /**
1693
+ * The user's id
1694
+ */
1695
+ get id() {
1696
+ return this[kData].id;
1697
+ }
1698
+ /**
1699
+ * The username of the user
1700
+ */
1701
+ get username() {
1702
+ return this[kData].username;
1703
+ }
1704
+ /**
1705
+ * The user's 4 digit tag, if a bot
1706
+ */
1707
+ get discriminator() {
1708
+ return this[kData].discriminator;
1709
+ }
1710
+ /**
1711
+ * The user's display name, the application name for bots
1712
+ */
1713
+ get globalName() {
1714
+ return this[kData].global_name;
1715
+ }
1716
+ /**
1717
+ * The name displayed in the client for this user when no nickname is set
1718
+ */
1719
+ get displayName() {
1720
+ return this.globalName ?? this.username;
1721
+ }
1722
+ /**
1723
+ * The user avatar's hash
1724
+ */
1725
+ get avatar() {
1726
+ return this[kData].avatar;
1727
+ }
1728
+ /**
1729
+ * Whether the user is a bot
1730
+ */
1731
+ get bot() {
1732
+ return this[kData].bot ?? false;
1733
+ }
1734
+ /**
1735
+ * Whether the user is an Official Discord System user
1736
+ */
1737
+ get system() {
1738
+ return this[kData].system ?? false;
1739
+ }
1740
+ /**
1741
+ * Whether the user has mfa enabled
1742
+ *
1743
+ * @remarks This property is only set when the user was fetched with an OAuth2 token and the `identify` scope
1744
+ */
1745
+ get mfaEnabled() {
1746
+ return this[kData].mfa_enabled;
1747
+ }
1748
+ /**
1749
+ * The user's banner hash
1750
+ *
1751
+ * @remarks This property is only set when the user was manually fetched
1752
+ */
1753
+ get banner() {
1754
+ return this[kData].banner;
1755
+ }
1756
+ /**
1757
+ * The base 10 accent color of the user's banner
1758
+ *
1759
+ * @remarks This property is only set when the user was manually fetched
1760
+ */
1761
+ get accentColor() {
1762
+ return this[kData].accent_color;
1763
+ }
1764
+ /**
1765
+ * The user's primary Discord language
1766
+ *
1767
+ * @remarks This property is only set when the user was fetched with an Oauth2 token and the `identify` scope
1768
+ */
1769
+ get locale() {
1770
+ return this[kData].locale;
1771
+ }
1772
+ /**
1773
+ * Whether the email on the user's account has been verified
1774
+ *
1775
+ * @remarks This property is only set when the user was fetched with an OAuth2 token and the `email` scope
1776
+ */
1777
+ get verified() {
1778
+ return this[kData].verified;
1779
+ }
1780
+ /**
1781
+ * The user's email
1782
+ *
1783
+ * @remarks This property is only set when the user was fetched with an OAuth2 token and the `email` scope
1784
+ */
1785
+ get email() {
1786
+ return this[kData].email;
1787
+ }
1788
+ /**
1789
+ * The type of nitro subscription on the user's account
1790
+ *
1791
+ * @remarks This property is only set when the user was fetched with an OAuth2 token and the `identify` scope
1792
+ */
1793
+ get premiumType() {
1794
+ return this[kData].premium_type;
1795
+ }
1796
+ /**
1797
+ * The timestamp the user was created at
1798
+ */
1799
+ get createdTimestamp() {
1800
+ return isIdSet(this.id) ? import_snowflake2.DiscordSnowflake.timestampFrom(this.id) : null;
1801
+ }
1802
+ /**
1803
+ * The time the user was created at
1804
+ */
1805
+ get createdAt() {
1806
+ const createdTimestamp = this.createdTimestamp;
1807
+ return createdTimestamp ? new Date(createdTimestamp) : null;
1808
+ }
1809
+ /**
1810
+ * The hexadecimal version of the user accent color, with a leading hash
1811
+ *
1812
+ * @remarks This property is only set when the user was manually fetched
1813
+ */
1814
+ get hexAccentColor() {
1815
+ const accentColor = this.accentColor;
1816
+ if (typeof accentColor !== "number") return accentColor;
1817
+ return `#${accentColor.toString(16).padStart(6, "0")}`;
1818
+ }
1819
+ };
1820
+
1821
+ // src/users/Connection.ts
1822
+ var Connection = class extends Structure {
1823
+ static {
1824
+ __name(this, "Connection");
1825
+ }
1826
+ /**
1827
+ * The template used for removing data from the raw data stored for each Connection
1828
+ */
1829
+ static DataTemplate = {};
1830
+ /**
1831
+ * @param data - The raw data received from the API for the connection
1832
+ */
1833
+ constructor(data) {
1834
+ super(data);
1835
+ }
1836
+ /**
1837
+ * {@inheritDoc Structure.[kPatch]}
1838
+ *
1839
+ * @internal
1840
+ */
1841
+ [kPatch](data) {
1842
+ return super[kPatch](data);
1843
+ }
1844
+ /**
1845
+ * The id of the connection account
1846
+ */
1847
+ get id() {
1848
+ return this[kData].id;
1849
+ }
1850
+ /**
1851
+ * The username of the connection account
1852
+ */
1853
+ get name() {
1854
+ return this[kData].name;
1855
+ }
1856
+ /**
1857
+ * The type of service this connection is for
1858
+ */
1859
+ get type() {
1860
+ return this[kData].type;
1861
+ }
1862
+ /**
1863
+ * Whether the connection is revoked
1864
+ */
1865
+ get revoked() {
1866
+ return this[kData].revoked ?? false;
1867
+ }
1868
+ /**
1869
+ * Whether the connection is verified
1870
+ */
1871
+ get verified() {
1872
+ return this[kData].verified;
1873
+ }
1874
+ /**
1875
+ * Whether friend sync is enabled for this connection
1876
+ */
1877
+ get friendSync() {
1878
+ return this[kData].friend_sync;
1879
+ }
1880
+ /**
1881
+ * Whether activities related to this connection are shown in the users presence
1882
+ */
1883
+ get showActivity() {
1884
+ return this[kData].show_activity;
1885
+ }
1886
+ /**
1887
+ * Whether this connection has an Oauth2 token for console voice transfer
1888
+ */
1889
+ get twoWayLink() {
1890
+ return this[kData].two_way_link;
1891
+ }
1892
+ /**
1893
+ * The visibility state for this connection
1894
+ */
1895
+ get visibility() {
1896
+ return this[kData].visibility;
1897
+ }
1898
+ };
1899
+
1900
+ // src/utils/optimization.ts
1901
+ function extendTemplate(superTemplate, additions) {
1902
+ return Object.defineProperties(additions, Object.getOwnPropertyDescriptors(superTemplate));
1903
+ }
1904
+ __name(extendTemplate, "extendTemplate");
1905
+ // Annotate the CommonJS export names for ESM import in node:
1906
+ 0 && (module.exports = {
1907
+ AnnouncementChannel,
1908
+ AnnouncementThreadChannel,
1909
+ AppliedTagsMixin,
1910
+ AvatarDecorationData,
1911
+ BitField,
1912
+ CategoryChannel,
1913
+ Channel,
1914
+ ChannelFlagsBitField,
1915
+ ChannelOwnerMixin,
1916
+ ChannelParentMixin,
1917
+ ChannelPermissionMixin,
1918
+ ChannelPinMixin,
1919
+ ChannelSlowmodeMixin,
1920
+ ChannelTopicMixin,
1921
+ ChannelWebhookMixin,
1922
+ Connection,
1923
+ DMChannel,
1924
+ DMChannelMixin,
1925
+ DataTemplatePropertyName,
1926
+ ForumChannel,
1927
+ ForumTag,
1928
+ GroupDMChannel,
1929
+ GroupDMMixin,
1930
+ GuildChannelMixin,
1931
+ Invite,
1932
+ MediaChannel,
1933
+ Mixin,
1934
+ OptimizeDataPropertyName,
1935
+ PermissionOverwrite,
1936
+ PermissionsBitField,
1937
+ PrivateThreadChannel,
1938
+ PublicThreadChannel,
1939
+ StageChannel,
1940
+ Structure,
1941
+ TextChannel,
1942
+ TextChannelMixin,
1943
+ ThreadChannelMixin,
1944
+ ThreadMetadata,
1945
+ ThreadOnlyChannelMixin,
1946
+ User,
1947
+ VoiceChannel,
1948
+ VoiceChannelMixin,
1949
+ extendTemplate
1950
+ });
1951
+ //# sourceMappingURL=index.js.map