@impulsedev/chameleon 1.7.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,911 @@
1
+ // src/builders/embed.ts
2
+ var Colors = {
3
+ Blue: 2003199,
4
+ Purple: 10181046,
5
+ Orange: 16744272,
6
+ Pink: 16739201,
7
+ White: 16777215,
8
+ Blurple: 5793266,
9
+ Green: 5763719,
10
+ Yellow: 16705372,
11
+ Fuchsia: 15418782,
12
+ Red: 15548997,
13
+ Black: 2303786,
14
+ Transparent: 3092790
15
+ };
16
+ var EmbedBuilder = class {
17
+ data = {};
18
+ constructor(data) {
19
+ if (data) Object.assign(this.data, data);
20
+ }
21
+ setTitle(title) {
22
+ this.data.title = title;
23
+ return this;
24
+ }
25
+ setDescription(description) {
26
+ this.data.description = description;
27
+ return this;
28
+ }
29
+ setColor(color) {
30
+ this.data.color = color;
31
+ return this;
32
+ }
33
+ setURL(url) {
34
+ this.data.url = url;
35
+ return this;
36
+ }
37
+ setTimestamp(ts = Date.now()) {
38
+ this.data.timestamp = ts instanceof Date ? ts.getTime() : ts;
39
+ return this;
40
+ }
41
+ setFooter(text, iconUrl) {
42
+ this.data.footer = {
43
+ text,
44
+ ...iconUrl ? { iconUrl } : {}
45
+ };
46
+ return this;
47
+ }
48
+ setAuthor(name, iconUrl, url) {
49
+ this.data.author = {
50
+ name,
51
+ ...iconUrl ? { iconUrl } : {},
52
+ ...url ? { url } : {}
53
+ };
54
+ return this;
55
+ }
56
+ setImage(url) {
57
+ this.data.image = { url };
58
+ return this;
59
+ }
60
+ setThumbnail(url) {
61
+ this.data.thumbnail = { url };
62
+ return this;
63
+ }
64
+ addField(name, value, inline = false) {
65
+ if (!this.data.fields) this.data.fields = [];
66
+ this.data.fields.push({ name, value, inline });
67
+ return this;
68
+ }
69
+ addFields(...fields) {
70
+ if (!this.data.fields) this.data.fields = [];
71
+ this.data.fields.push(...fields);
72
+ return this;
73
+ }
74
+ build() {
75
+ return this.data;
76
+ }
77
+ toJSON() {
78
+ const e = this.data;
79
+ const payload = {};
80
+ if (typeof e.title === "string") payload.title = e.title;
81
+ if (typeof e.description === "string") payload.description = e.description;
82
+ if (typeof e.color === "number") payload.color = e.color;
83
+ if (typeof e.url === "string") payload.url = e.url;
84
+ if (typeof e.timestamp === "number" && !Number.isNaN(e.timestamp)) {
85
+ payload.timestamp = new Date(e.timestamp).toISOString();
86
+ }
87
+ if (e.author) {
88
+ const author = {
89
+ name: e.author.name
90
+ };
91
+ if (typeof e.author.url === "string") {
92
+ author.url = e.author.url;
93
+ }
94
+ if (typeof e.author.iconUrl === "string") {
95
+ author.icon_url = e.author.iconUrl;
96
+ }
97
+ if (typeof e.author.proxyIconUrl === "string") {
98
+ author.proxy_icon_url = e.author.proxyIconUrl;
99
+ }
100
+ payload.author = author;
101
+ }
102
+ if (e.footer) {
103
+ const footer = {
104
+ text: e.footer.text
105
+ };
106
+ if (typeof e.footer.iconUrl === "string") {
107
+ footer.icon_url = e.footer.iconUrl;
108
+ }
109
+ if (typeof e.footer.proxyIconUrl === "string") {
110
+ footer.proxy_icon_url = e.footer.proxyIconUrl;
111
+ }
112
+ payload.footer = footer;
113
+ }
114
+ if (e.image?.url) {
115
+ payload.image = {
116
+ url: e.image.url,
117
+ ...e.image.proxyUrl ? { proxy_url: e.image.proxyUrl } : {},
118
+ ...typeof e.image.width === "number" ? { width: e.image.width } : {},
119
+ ...typeof e.image.height === "number" ? { height: e.image.height } : {}
120
+ };
121
+ }
122
+ if (e.thumbnail?.url) {
123
+ payload.thumbnail = {
124
+ url: e.thumbnail.url,
125
+ ...e.thumbnail.proxyUrl ? { proxy_url: e.thumbnail.proxyUrl } : {},
126
+ ...typeof e.thumbnail.width === "number" ? { width: e.thumbnail.width } : {},
127
+ ...typeof e.thumbnail.height === "number" ? { height: e.thumbnail.height } : {}
128
+ };
129
+ }
130
+ if (Array.isArray(e.fields) && e.fields.length > 0) {
131
+ payload.fields = e.fields.map((f) => ({
132
+ name: f.name,
133
+ value: f.value,
134
+ inline: !!f.inline
135
+ }));
136
+ }
137
+ return payload;
138
+ }
139
+ };
140
+
141
+ // src/types/components/index.ts
142
+ var ComponentType = {
143
+ ACTION_ROW: 1,
144
+ BUTTON: 2,
145
+ STRING_SELECT: 3,
146
+ TEXT_INPUT: 4,
147
+ USER_SELECT: 5,
148
+ ROLE_SELECT: 6,
149
+ MENTIONABLE_SELECT: 7,
150
+ CHANNEL_SELECT: 8
151
+ };
152
+ var ButtonStyle = {
153
+ PRIMARY: 1,
154
+ SECONDARY: 2,
155
+ SUCCESS: 3,
156
+ DANGER: 4,
157
+ LINK: 5,
158
+ PREMIUM: 6
159
+ };
160
+
161
+ // src/utils/object.ts
162
+ function toSnakeCase(obj) {
163
+ if (Array.isArray(obj)) {
164
+ return obj.map((v) => toSnakeCase(v));
165
+ } else if (obj !== null && typeof obj === "object") {
166
+ if (typeof obj.toJSON === "function") {
167
+ return obj.toJSON();
168
+ }
169
+ return Object.keys(obj).reduce((result, key) => {
170
+ const snakeKey = key.replace(/([A-Z])/g, "_$1").toLowerCase();
171
+ result[snakeKey] = toSnakeCase(obj[key]);
172
+ return result;
173
+ }, {});
174
+ }
175
+ return obj;
176
+ }
177
+ function toCamelCase(obj) {
178
+ if (Array.isArray(obj)) {
179
+ return obj.map((v) => toCamelCase(v));
180
+ } else if (obj !== null && typeof obj === "object") {
181
+ return Object.keys(obj).reduce((result, key) => {
182
+ const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
183
+ result[camelKey] = toCamelCase(obj[key]);
184
+ return result;
185
+ }, {});
186
+ }
187
+ return obj;
188
+ }
189
+
190
+ // src/builders/components.ts
191
+ function serializeEmoji(emoji) {
192
+ if (!emoji) return void 0;
193
+ return {
194
+ id: emoji.id,
195
+ name: emoji.name,
196
+ animated: emoji.animated
197
+ };
198
+ }
199
+ var ButtonBuilder = class {
200
+ data = {
201
+ type: ComponentType.BUTTON
202
+ };
203
+ setCustomId(id) {
204
+ this.data.customId = id;
205
+ return this;
206
+ }
207
+ setLabel(label) {
208
+ this.data.label = label;
209
+ return this;
210
+ }
211
+ setStyle(style) {
212
+ this.data.style = style;
213
+ return this;
214
+ }
215
+ setEmoji(emoji) {
216
+ this.data.emoji = emoji;
217
+ return this;
218
+ }
219
+ setDisabled(disabled = true) {
220
+ this.data.disabled = disabled;
221
+ return this;
222
+ }
223
+ setURL(url) {
224
+ this.data.url = url;
225
+ this.data.style = ButtonStyle.LINK;
226
+ return this;
227
+ }
228
+ build() {
229
+ return {
230
+ ...this.data
231
+ };
232
+ }
233
+ toJSON() {
234
+ return {
235
+ type: ComponentType.BUTTON,
236
+ custom_id: this.data.customId,
237
+ label: this.data.label,
238
+ style: this.data.style,
239
+ disabled: this.data.disabled,
240
+ url: this.data.url,
241
+ emoji: serializeEmoji(this.data.emoji)
242
+ };
243
+ }
244
+ };
245
+ var SelectMenuBuilder = class {
246
+ data = {
247
+ type: ComponentType.STRING_SELECT
248
+ };
249
+ setCustomId(id) {
250
+ this.data.customId = id;
251
+ return this;
252
+ }
253
+ setPlaceholder(placeholder) {
254
+ this.data.placeholder = placeholder;
255
+ return this;
256
+ }
257
+ setMinValues(min) {
258
+ this.data.minValues = min;
259
+ return this;
260
+ }
261
+ setMaxValues(max) {
262
+ this.data.maxValues = max;
263
+ return this;
264
+ }
265
+ setDisabled(disabled = true) {
266
+ this.data.disabled = disabled;
267
+ return this;
268
+ }
269
+ setType(type) {
270
+ this.data.type = type;
271
+ return this;
272
+ }
273
+ addOption(option) {
274
+ if (!this.data.options) {
275
+ this.data.options = [];
276
+ }
277
+ this.data.options.push(option);
278
+ return this;
279
+ }
280
+ addOptions(...options) {
281
+ if (!this.data.options) {
282
+ this.data.options = [];
283
+ }
284
+ this.data.options.push(...options);
285
+ return this;
286
+ }
287
+ build() {
288
+ return {
289
+ ...this.data
290
+ };
291
+ }
292
+ toJSON() {
293
+ return {
294
+ type: this.data.type ?? ComponentType.STRING_SELECT,
295
+ custom_id: this.data.customId,
296
+ placeholder: this.data.placeholder,
297
+ min_values: this.data.minValues,
298
+ max_values: this.data.maxValues,
299
+ disabled: this.data.disabled,
300
+ options: this.data.options?.map((option) => ({
301
+ label: option.label,
302
+ value: option.value,
303
+ description: option.description,
304
+ emoji: serializeEmoji(option.emoji),
305
+ default: option.default
306
+ }))
307
+ };
308
+ }
309
+ };
310
+ var TextInputBuilder = class {
311
+ data = {
312
+ type: ComponentType.TEXT_INPUT
313
+ };
314
+ _minLength;
315
+ _maxLength;
316
+ _required;
317
+ _value;
318
+ setCustomId(id) {
319
+ this.data.customId = id;
320
+ return this;
321
+ }
322
+ setLabel(label) {
323
+ this.data.label = label;
324
+ return this;
325
+ }
326
+ setStyle(style) {
327
+ this.data.style = style;
328
+ return this;
329
+ }
330
+ setPlaceholder(placeholder) {
331
+ this.data.placeholder = placeholder;
332
+ return this;
333
+ }
334
+ setMinLength(length) {
335
+ this._minLength = length;
336
+ return this;
337
+ }
338
+ setMaxLength(length) {
339
+ this._maxLength = length;
340
+ return this;
341
+ }
342
+ setRequired(required = true) {
343
+ this._required = required;
344
+ return this;
345
+ }
346
+ setValue(value) {
347
+ this._value = value;
348
+ return this;
349
+ }
350
+ build() {
351
+ return {
352
+ ...this.data,
353
+ minLength: this._minLength,
354
+ maxLength: this._maxLength,
355
+ required: this._required,
356
+ value: this._value
357
+ };
358
+ }
359
+ toJSON() {
360
+ return {
361
+ type: ComponentType.TEXT_INPUT,
362
+ custom_id: this.data.customId,
363
+ style: this.data.style,
364
+ label: this.data.label,
365
+ placeholder: this.data.placeholder,
366
+ min_length: this._minLength,
367
+ max_length: this._maxLength,
368
+ required: this._required,
369
+ value: this._value
370
+ };
371
+ }
372
+ };
373
+ var ActionRowBuilder = class {
374
+ data = {
375
+ type: ComponentType.ACTION_ROW,
376
+ components: []
377
+ };
378
+ addComponent(component) {
379
+ this.data.components.push(component);
380
+ return this;
381
+ }
382
+ addComponents(...components) {
383
+ for (const component of components) {
384
+ this.addComponent(component);
385
+ }
386
+ return this;
387
+ }
388
+ build() {
389
+ return {
390
+ ...this.data,
391
+ components: this.data.components.map((component) => {
392
+ if (component && typeof component.build === "function") {
393
+ return component.build();
394
+ }
395
+ return component;
396
+ })
397
+ };
398
+ }
399
+ toJSON() {
400
+ return {
401
+ type: ComponentType.ACTION_ROW,
402
+ components: this.data.components?.map((component) => {
403
+ if (component && typeof component.toJSON === "function") {
404
+ return component.toJSON();
405
+ }
406
+ return component;
407
+ })
408
+ };
409
+ }
410
+ };
411
+ var ModalBuilder = class {
412
+ _title = "";
413
+ _customId = "";
414
+ _components = [];
415
+ setTitle(title) {
416
+ this._title = title;
417
+ return this;
418
+ }
419
+ setCustomId(id) {
420
+ this._customId = id;
421
+ return this;
422
+ }
423
+ addComponent(component) {
424
+ this._components.push(component);
425
+ return this;
426
+ }
427
+ addComponents(...components) {
428
+ for (const component of components) {
429
+ this.addComponent(component);
430
+ }
431
+ return this;
432
+ }
433
+ build() {
434
+ return {
435
+ title: this._title,
436
+ custom_id: this._customId,
437
+ components: this._components.map((component) => {
438
+ if (component && typeof component.build === "function") {
439
+ return component.build();
440
+ }
441
+ return component;
442
+ })
443
+ };
444
+ }
445
+ toJSON() {
446
+ return {
447
+ title: this._title,
448
+ custom_id: this._customId,
449
+ components: this._components.map((component) => {
450
+ if (component && typeof component.toJSON === "function") {
451
+ return component.toJSON();
452
+ }
453
+ return component;
454
+ })
455
+ };
456
+ }
457
+ };
458
+ function serializeComponent(component) {
459
+ if (!component) return {};
460
+ if (typeof component.toJSON === "function") {
461
+ return component.toJSON();
462
+ }
463
+ if (typeof component.build === "function") {
464
+ return toSnakeCase(component.build());
465
+ }
466
+ return toSnakeCase(component);
467
+ }
468
+
469
+ // src/builders/entities.ts
470
+ function buildStageInstance(raw) {
471
+ return {
472
+ id: raw.id,
473
+ guildId: raw.guild_id ?? "",
474
+ channelId: raw.channel_id ?? "",
475
+ topic: raw.topic ?? "",
476
+ privacyLevel: raw.privacy_level ?? 2,
477
+ discoverableDisabled: raw.discoverable_disabled ?? false,
478
+ guildScheduledEventId: raw.guild_scheduled_event_id ?? null
479
+ };
480
+ }
481
+ function buildScheduledEvent(raw) {
482
+ let creator;
483
+ if (raw.creator) {
484
+ creator = buildUser(raw.creator);
485
+ }
486
+ return {
487
+ id: raw.id,
488
+ guildId: raw.guild_id ?? "",
489
+ channelId: raw.channel_id ?? null,
490
+ creatorId: raw.creator_id ?? null,
491
+ name: raw.name ?? "",
492
+ description: raw.description ?? null,
493
+ scheduledStartTime: raw.scheduled_start_time ? Date.parse(raw.scheduled_start_time) : 0,
494
+ scheduledEndTime: raw.scheduled_end_time ? Date.parse(raw.scheduled_end_time) : null,
495
+ privacyLevel: raw.privacy_level ?? 2,
496
+ status: raw.status ?? 1,
497
+ entityType: raw.entity_type ?? 1,
498
+ entityId: raw.entity_id ?? null,
499
+ entityMetadata: raw.entity_metadata ? { ...raw.entity_metadata.location !== void 0 ? { location: raw.entity_metadata.location } : {} } : null,
500
+ ...creator ? { creator } : {},
501
+ ...raw.user_count !== void 0 ? { userCount: raw.user_count } : {},
502
+ ...raw.image !== void 0 ? { image: raw.image } : {}
503
+ };
504
+ }
505
+ function buildAutoModActionMetadata(raw) {
506
+ return {
507
+ ...raw.channel_id !== void 0 ? { channelId: raw.channel_id } : {},
508
+ ...raw.duration_seconds !== void 0 ? { durationSeconds: raw.duration_seconds } : {},
509
+ ...raw.custom_message !== void 0 ? { customMessage: raw.custom_message } : {}
510
+ };
511
+ }
512
+ function buildAutoModAction(raw) {
513
+ return {
514
+ type: raw.type,
515
+ ...raw.metadata ? { metadata: buildAutoModActionMetadata(raw.metadata) } : {}
516
+ };
517
+ }
518
+ function buildAutoModTriggerMetadata(raw) {
519
+ return {
520
+ ...raw.keyword_filter !== void 0 ? { keywordFilter: raw.keyword_filter } : {},
521
+ ...raw.regex_patterns !== void 0 ? { regexPatterns: raw.regex_patterns } : {},
522
+ ...raw.presets !== void 0 ? { presets: raw.presets } : {},
523
+ ...raw.allow_list !== void 0 ? { allowList: raw.allow_list } : {},
524
+ ...raw.mention_total_limit !== void 0 ? { mentionTotalLimit: raw.mention_total_limit } : {},
525
+ ...raw.mention_raid_protection_enabled !== void 0 ? { mentionRaidProtectionEnabled: raw.mention_raid_protection_enabled } : {}
526
+ };
527
+ }
528
+ function buildAutoModRule(raw) {
529
+ return {
530
+ id: raw.id,
531
+ guildId: raw.guild_id ?? "",
532
+ name: raw.name ?? "",
533
+ creatorId: raw.creator_id ?? "",
534
+ eventType: raw.event_type ?? 1,
535
+ triggerType: raw.trigger_type ?? 1,
536
+ triggerMetadata: raw.trigger_metadata ? buildAutoModTriggerMetadata(raw.trigger_metadata) : {},
537
+ actions: Array.isArray(raw.actions) ? raw.actions.map((a) => buildAutoModAction(a)) : [],
538
+ enabled: raw.enabled ?? false,
539
+ exemptRoles: raw.exempt_roles ?? [],
540
+ exemptChannels: raw.exempt_channels ?? []
541
+ };
542
+ }
543
+ function buildIntegration(raw) {
544
+ let user;
545
+ if (raw.user) {
546
+ user = buildUser(raw.user);
547
+ }
548
+ return {
549
+ id: raw.id,
550
+ name: raw.name ?? "",
551
+ type: raw.type ?? "",
552
+ enabled: raw.enabled ?? false,
553
+ ...raw.syncing !== void 0 ? { syncing: raw.syncing } : {},
554
+ ...raw.role_id !== void 0 ? { roleId: raw.role_id } : {},
555
+ ...raw.enable_emoticons !== void 0 ? { enableEmoticons: raw.enable_emoticons } : {},
556
+ ...raw.expire_behavior !== void 0 ? { expireBehavior: raw.expire_behavior } : {},
557
+ ...raw.expire_grace_period !== void 0 ? { expireGracePeriod: raw.expire_grace_period } : {},
558
+ ...user ? { user } : {},
559
+ account: raw.account ? { id: raw.account.id, name: raw.account.name } : { id: "", name: "" },
560
+ ...raw.synced_at ? { syncedAt: Date.parse(raw.synced_at) } : {},
561
+ ...raw.subscriber_count !== void 0 ? { subscriberCount: raw.subscriber_count } : {},
562
+ ...raw.revoked !== void 0 ? { revoked: raw.revoked } : {},
563
+ ...raw.application !== void 0 ? { application: raw.application } : {},
564
+ ...raw.scopes !== void 0 ? { scopes: raw.scopes } : {}
565
+ };
566
+ }
567
+ function buildEmoji(raw) {
568
+ let user;
569
+ if (raw.user) {
570
+ user = buildUser(raw.user);
571
+ }
572
+ return {
573
+ id: raw.id ?? null,
574
+ name: raw.name ?? null,
575
+ ...raw.roles !== void 0 ? { roles: raw.roles } : {},
576
+ ...user ? { user } : {},
577
+ ...raw.require_colons !== void 0 ? { requireColons: raw.require_colons } : {},
578
+ ...raw.managed !== void 0 ? { managed: raw.managed } : {},
579
+ ...raw.animated !== void 0 ? { animated: raw.animated } : {},
580
+ ...raw.available !== void 0 ? { available: raw.available } : {}
581
+ };
582
+ }
583
+ function buildSticker(raw) {
584
+ let user;
585
+ if (raw.user) {
586
+ user = buildUser(raw.user);
587
+ }
588
+ return {
589
+ id: raw.id,
590
+ ...raw.pack_id !== void 0 ? { packId: raw.pack_id } : {},
591
+ name: raw.name ?? "",
592
+ description: raw.description ?? null,
593
+ tags: raw.tags ?? "",
594
+ type: raw.type ?? 1,
595
+ formatType: raw.format_type ?? 1,
596
+ ...raw.available !== void 0 ? { available: raw.available } : {},
597
+ ...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
598
+ ...user ? { user } : {},
599
+ ...raw.sort_value !== void 0 ? { sortValue: raw.sort_value } : {}
600
+ };
601
+ }
602
+ function buildStickerItem(raw) {
603
+ return {
604
+ id: raw.id,
605
+ name: raw.name ?? "",
606
+ formatType: raw.format_type ?? 1
607
+ };
608
+ }
609
+ function buildVoiceState(raw, cache) {
610
+ let member;
611
+ if (raw.member && cache && raw.guild_id) {
612
+ member = buildMember(raw.member, raw.guild_id, cache);
613
+ }
614
+ return {
615
+ ...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
616
+ channelId: raw.channel_id ?? "",
617
+ userId: raw.user_id ?? "",
618
+ ...member ? { member } : {},
619
+ sessionId: raw.session_id ?? "",
620
+ deaf: raw.deaf ?? false,
621
+ mute: raw.mute ?? false,
622
+ selfDeaf: raw.self_deaf ?? false,
623
+ selfMute: raw.self_mute ?? false,
624
+ selfStream: raw.self_stream ?? false,
625
+ selfVideo: raw.self_video ?? false,
626
+ suppress: raw.suppress ?? false,
627
+ requestToSpeakTimestamp: raw.request_to_speak_timestamp ? Date.parse(raw.request_to_speak_timestamp) : null
628
+ };
629
+ }
630
+ function buildEntitlement(raw) {
631
+ return {
632
+ id: raw.id,
633
+ skuId: raw.sku_id ?? "",
634
+ applicationId: raw.application_id ?? "",
635
+ ...raw.user_id !== void 0 ? { userId: raw.user_id } : {},
636
+ type: raw.type ?? 1,
637
+ deleted: raw.deleted ?? false,
638
+ ...raw.starts_at !== void 0 ? { startsAt: raw.starts_at ? Date.parse(raw.starts_at) : null } : {},
639
+ ...raw.ends_at !== void 0 ? { endsAt: raw.ends_at ? Date.parse(raw.ends_at) : null } : {},
640
+ ...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
641
+ ...raw.consumed !== void 0 ? { consumed: raw.consumed } : {}
642
+ };
643
+ }
644
+ function buildInteraction(raw, cache) {
645
+ let user;
646
+ let member;
647
+ if (raw.member && raw.guild_id) {
648
+ const memberRaw = raw.member;
649
+ if (cache) {
650
+ member = buildMember(memberRaw, raw.guild_id, cache);
651
+ }
652
+ if (memberRaw.user) {
653
+ user = buildUser(memberRaw.user);
654
+ }
655
+ }
656
+ if (!user && raw.user) {
657
+ user = buildUser(raw.user);
658
+ }
659
+ return {
660
+ id: raw.id,
661
+ applicationId: raw.application_id ?? "",
662
+ type: raw.type ?? 1,
663
+ ...raw.data !== void 0 ? { data: raw.data } : {},
664
+ ...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
665
+ ...raw.channel_id !== void 0 ? { channelId: raw.channel_id } : {},
666
+ ...member ? { member } : {},
667
+ ...user ? { user } : {},
668
+ token: raw.token ?? "",
669
+ version: raw.version ?? 1,
670
+ ...raw.message !== void 0 ? { message: raw.message } : {},
671
+ ...raw.app_permissions !== void 0 ? { appPermissions: raw.app_permissions } : {},
672
+ ...raw.locale !== void 0 ? { locale: raw.locale } : {},
673
+ ...raw.guild_locale !== void 0 ? { guildLocale: raw.guild_locale } : {},
674
+ entitlements: Array.isArray(raw.entitlements) ? raw.entitlements.map((e) => buildEntitlement(e)) : [],
675
+ authorizingIntegrationOwners: raw.authorizing_integration_owners ?? {},
676
+ ...raw.context !== void 0 ? { context: raw.context } : {}
677
+ };
678
+ }
679
+ function buildInvite(raw) {
680
+ let inviter;
681
+ let targetUser;
682
+ if (raw.inviter) {
683
+ inviter = buildUser(raw.inviter);
684
+ }
685
+ if (raw.target_user) {
686
+ targetUser = buildUser(raw.target_user);
687
+ }
688
+ return {
689
+ type: raw.type ?? 0,
690
+ code: raw.code,
691
+ ...raw.guild ? { guild: buildGuild(raw.guild) } : {},
692
+ channel: raw.channel ? buildChannel(raw.channel) : null,
693
+ ...inviter ? { inviter } : {},
694
+ ...raw.target_type !== void 0 ? { targetType: raw.target_type } : {},
695
+ ...targetUser ? { targetUser } : {},
696
+ ...raw.target_application !== void 0 ? { targetApplication: raw.target_application } : {},
697
+ ...raw.approximate_presence_count !== void 0 ? { approximatePresenceCount: raw.approximate_presence_count } : {},
698
+ ...raw.approximate_member_count !== void 0 ? { approximateMemberCount: raw.approximate_member_count } : {},
699
+ expiresAt: raw.expires_at ? Date.parse(raw.expires_at) : null,
700
+ ...raw.guild_scheduled_event !== void 0 ? { guildScheduledEvent: buildScheduledEvent(raw.guild_scheduled_event) } : {},
701
+ ...raw.flags !== void 0 ? { flags: raw.flags } : {},
702
+ ...raw.roles !== void 0 ? { roles: raw.roles } : {}
703
+ };
704
+ }
705
+ function buildWebhook(raw) {
706
+ let user;
707
+ if (raw.user) {
708
+ user = buildUser(raw.user);
709
+ }
710
+ return {
711
+ id: raw.id,
712
+ type: raw.type ?? 1,
713
+ ...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
714
+ ...raw.channel_id !== void 0 ? { channelId: raw.channel_id } : {},
715
+ ...user ? { user } : {},
716
+ name: raw.name ?? null,
717
+ avatar: raw.avatar ?? null,
718
+ ...raw.token !== void 0 ? { token: raw.token } : {},
719
+ applicationId: raw.application_id ?? null,
720
+ ...raw.source_guild ? { sourceGuild: buildGuild(raw.source_guild) } : {},
721
+ ...raw.source_channel ? { sourceChannel: buildChannel(raw.source_channel) } : {},
722
+ ...raw.url !== void 0 ? { url: raw.url } : {}
723
+ };
724
+ }
725
+
726
+ // src/builders/index.ts
727
+ function buildUser(raw) {
728
+ return {
729
+ id: raw.id,
730
+ username: raw.username,
731
+ discriminator: raw.discriminator,
732
+ globalName: raw.global_name ?? null,
733
+ avatar: raw.avatar ?? null,
734
+ bot: raw.bot ?? false,
735
+ system: raw.system ?? false,
736
+ mfaEnabled: raw.mfa_enabled ?? false,
737
+ banner: raw.banner ?? null,
738
+ accentColor: raw.accent_color ?? null,
739
+ locale: raw.locale ?? void 0,
740
+ flags: raw.flags ?? 0,
741
+ premiumType: raw.premium_type ?? 0,
742
+ publicFlags: raw.public_flags ?? 0
743
+ };
744
+ }
745
+ function buildChannel(raw, guildId) {
746
+ return {
747
+ id: raw.id,
748
+ type: raw.type,
749
+ guildId: raw.guild_id ?? guildId ?? void 0,
750
+ name: raw.name ?? null,
751
+ position: raw.position ?? 0,
752
+ parentId: raw.parent_id ?? null,
753
+ topic: raw.topic ?? null,
754
+ nsfw: raw.nsfw ?? false,
755
+ lastMessageId: raw.last_message_id ?? null,
756
+ bitrate: raw.bitrate ?? void 0,
757
+ userLimit: raw.user_limit ?? void 0,
758
+ rateLimitPerUser: raw.rate_limit_per_user ?? 0,
759
+ permissionOverwrites: raw.permission_overwrites ?? []
760
+ };
761
+ }
762
+ function buildGuild(raw) {
763
+ return {
764
+ id: raw.id,
765
+ name: raw.name,
766
+ icon: raw.icon ?? null,
767
+ splash: raw.splash ?? null,
768
+ discoverySplash: raw.discovery_splash ?? null,
769
+ ownerId: raw.owner_id,
770
+ afkChannelId: raw.afk_channel_id ?? null,
771
+ afkTimeout: raw.afk_timeout ?? 0,
772
+ verificationLevel: raw.verification_level ?? 0,
773
+ defaultMessageNotifications: raw.default_message_notifications ?? 0,
774
+ explicitContentFilter: raw.explicit_content_filter ?? 0,
775
+ features: raw.features ?? [],
776
+ mfaLevel: raw.mfa_level ?? 0,
777
+ systemChannelId: raw.system_channel_id ?? null,
778
+ systemChannelFlags: raw.system_channel_flags ?? 0,
779
+ rulesChannelId: raw.rules_channel_id ?? null,
780
+ memberCount: raw.member_count ?? 0,
781
+ vanityUrlCode: raw.vanity_url_code ?? null,
782
+ description: raw.description ?? null,
783
+ banner: raw.banner ?? null,
784
+ premiumTier: raw.premium_tier ?? 0,
785
+ premiumSubscriptionCount: raw.premium_subscription_count ?? 0,
786
+ preferredLocale: raw.preferred_locale ?? "en-US",
787
+ publicUpdatesChannelId: raw.public_updates_channel_id ?? null,
788
+ nsfwLevel: raw.nsfw_level ?? 0,
789
+ premiumProgressBarEnabled: raw.premium_progress_bar_enabled ?? false,
790
+ roles: Array.isArray(raw.roles) ? raw.roles.map((r) => buildRole(r)) : [],
791
+ emojis: raw.emojis ?? [],
792
+ applicationId: raw.application_id ?? null,
793
+ large: raw.large ?? false
794
+ };
795
+ }
796
+ function buildRole(raw) {
797
+ return {
798
+ id: raw.id,
799
+ name: raw.name,
800
+ color: raw.color ?? 0,
801
+ hoist: raw.hoist ?? false,
802
+ position: raw.position ?? 0,
803
+ permissions: raw.permissions,
804
+ managed: raw.managed ?? false,
805
+ mentionable: raw.mentionable ?? false,
806
+ icon: raw.icon ?? null,
807
+ unicodeEmoji: raw.unicode_emoji ?? null,
808
+ flags: raw.flags ?? 0
809
+ };
810
+ }
811
+ function buildMember(raw, guildId, cache) {
812
+ let userObj;
813
+ if (raw.user) {
814
+ const user = buildUser(raw.user);
815
+ cache.users.set(user.id, user);
816
+ userObj = user;
817
+ }
818
+ return {
819
+ ...userObj ? { user: userObj } : {},
820
+ nick: raw.nick ?? null,
821
+ avatar: raw.avatar ?? null,
822
+ roles: raw.roles ?? [],
823
+ joinedAt: raw.joined_at ? Date.parse(raw.joined_at) : 0,
824
+ premiumSince: raw.premium_since ? Date.parse(raw.premium_since) : null,
825
+ deaf: raw.deaf ?? false,
826
+ mute: raw.mute ?? false,
827
+ pending: raw.pending ?? false,
828
+ flags: raw.flags ?? 0,
829
+ communicationDisabledUntil: raw.communication_disabled_until ? Date.parse(raw.communication_disabled_until) : null
830
+ };
831
+ }
832
+ function buildMessage(raw, cache, oldMessage) {
833
+ const authorRaw = raw.author;
834
+ const author = authorRaw ? buildUser(authorRaw) : oldMessage?.author ?? {};
835
+ if (authorRaw && author.id) {
836
+ cache.users.set(author.id, author);
837
+ }
838
+ const msgId = raw.id ?? oldMessage?.id;
839
+ const channelId = raw.channel_id ?? oldMessage?.channelId;
840
+ const guildId = raw.guild_id ? raw.guild_id : oldMessage?.guildId;
841
+ const msg = {
842
+ id: msgId,
843
+ channelId,
844
+ author,
845
+ ...guildId ? { guildId } : {},
846
+ url: `https://discord.com/channels/${guildId ?? "@me"}/${channelId}/${msgId}`,
847
+ content: raw.content ?? oldMessage?.content ?? "",
848
+ timestamp: raw.timestamp ? Date.parse(raw.timestamp) : oldMessage?.timestamp ?? Date.now(),
849
+ editedTimestamp: raw.edited_timestamp ? Date.parse(raw.edited_timestamp) : oldMessage?.editedTimestamp ?? null,
850
+ tts: raw.tts ?? oldMessage?.tts ?? false,
851
+ mentionEveryone: raw.mention_everyone ?? oldMessage?.mentionEveryone ?? false,
852
+ mentions: raw.mentions ? raw.mentions.map((m) => buildUser(m)) : oldMessage?.mentions ?? [],
853
+ mentionRoles: raw.mention_roles ?? oldMessage?.mentionRoles ?? [],
854
+ attachments: raw.attachments ?? oldMessage?.attachments ?? [],
855
+ embeds: raw.embeds ?? oldMessage?.embeds ?? [],
856
+ pinned: raw.pinned ?? oldMessage?.pinned ?? false,
857
+ type: raw.type ?? oldMessage?.type ?? 0
858
+ };
859
+ return msg;
860
+ }
861
+ function resolveChannel(channelId, client) {
862
+ return client.cache.channels.get(channelId) ?? { id: channelId, fetch: () => client.channels.fetch(channelId) };
863
+ }
864
+ function resolveGuild(guildId, client) {
865
+ return client.cache.guilds.get(guildId) ?? { id: guildId, fetch: () => client.guilds.fetch(guildId) };
866
+ }
867
+ function resolveUser(userId, client) {
868
+ return client.cache.users.get(userId) ?? { id: userId, fetch: () => client.users.fetch(userId) };
869
+ }
870
+ function resolveRole(roleId, client, guildId) {
871
+ const stub = { id: roleId };
872
+ if (guildId) stub.fetch = () => client.guilds.roles(guildId).fetch(roleId);
873
+ return client.cache.roles.get(roleId) ?? stub;
874
+ }
875
+
876
+ export {
877
+ ComponentType,
878
+ ButtonStyle,
879
+ Colors,
880
+ EmbedBuilder,
881
+ toSnakeCase,
882
+ toCamelCase,
883
+ ButtonBuilder,
884
+ SelectMenuBuilder,
885
+ TextInputBuilder,
886
+ ActionRowBuilder,
887
+ ModalBuilder,
888
+ serializeComponent,
889
+ buildStageInstance,
890
+ buildScheduledEvent,
891
+ buildAutoModRule,
892
+ buildIntegration,
893
+ buildEmoji,
894
+ buildSticker,
895
+ buildStickerItem,
896
+ buildVoiceState,
897
+ buildEntitlement,
898
+ buildInteraction,
899
+ buildInvite,
900
+ buildWebhook,
901
+ buildUser,
902
+ buildChannel,
903
+ buildGuild,
904
+ buildRole,
905
+ buildMember,
906
+ buildMessage,
907
+ resolveChannel,
908
+ resolveGuild,
909
+ resolveUser,
910
+ resolveRole
911
+ };