@impulsedev/chameleon 1.6.0 → 2.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.
- package/README.md +7 -7
- package/diff.txt +3086 -0
- package/dist/builders-CCZQJXF6.js +60 -0
- package/dist/chunk-F2RRJ7OJ.js +850 -0
- package/dist/index.d.ts +171 -142
- package/dist/index.js +451 -925
- package/media/discordchameleon.png +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,850 @@
|
|
|
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
|
+
|
|
178
|
+
// src/builders/components.ts
|
|
179
|
+
function serializeEmoji(emoji) {
|
|
180
|
+
if (!emoji) return void 0;
|
|
181
|
+
return {
|
|
182
|
+
id: emoji.id,
|
|
183
|
+
name: emoji.name,
|
|
184
|
+
animated: emoji.animated
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
var ButtonBuilder = class {
|
|
188
|
+
data = {
|
|
189
|
+
type: ComponentType.BUTTON
|
|
190
|
+
};
|
|
191
|
+
setCustomId(id) {
|
|
192
|
+
this.data.customId = id;
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
setLabel(label) {
|
|
196
|
+
this.data.label = label;
|
|
197
|
+
return this;
|
|
198
|
+
}
|
|
199
|
+
setStyle(style) {
|
|
200
|
+
this.data.style = style;
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
setEmoji(emoji) {
|
|
204
|
+
this.data.emoji = emoji;
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
setDisabled(disabled = true) {
|
|
208
|
+
this.data.disabled = disabled;
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
setURL(url) {
|
|
212
|
+
this.data.url = url;
|
|
213
|
+
this.data.style = ButtonStyle.LINK;
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
build() {
|
|
217
|
+
return {
|
|
218
|
+
...this.data
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
toJSON() {
|
|
222
|
+
return {
|
|
223
|
+
type: ComponentType.BUTTON,
|
|
224
|
+
custom_id: this.data.customId,
|
|
225
|
+
label: this.data.label,
|
|
226
|
+
style: this.data.style,
|
|
227
|
+
disabled: this.data.disabled,
|
|
228
|
+
url: this.data.url,
|
|
229
|
+
emoji: serializeEmoji(this.data.emoji)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var SelectMenuBuilder = class {
|
|
234
|
+
data = {
|
|
235
|
+
type: ComponentType.STRING_SELECT
|
|
236
|
+
};
|
|
237
|
+
setCustomId(id) {
|
|
238
|
+
this.data.customId = id;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
setPlaceholder(placeholder) {
|
|
242
|
+
this.data.placeholder = placeholder;
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
setMinValues(min) {
|
|
246
|
+
this.data.minValues = min;
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
setMaxValues(max) {
|
|
250
|
+
this.data.maxValues = max;
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
setDisabled(disabled = true) {
|
|
254
|
+
this.data.disabled = disabled;
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
setType(type) {
|
|
258
|
+
this.data.type = type;
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
addOption(option) {
|
|
262
|
+
if (!this.data.options) {
|
|
263
|
+
this.data.options = [];
|
|
264
|
+
}
|
|
265
|
+
this.data.options.push(option);
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
addOptions(...options) {
|
|
269
|
+
if (!this.data.options) {
|
|
270
|
+
this.data.options = [];
|
|
271
|
+
}
|
|
272
|
+
this.data.options.push(...options);
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
build() {
|
|
276
|
+
return {
|
|
277
|
+
...this.data
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
toJSON() {
|
|
281
|
+
return {
|
|
282
|
+
type: this.data.type ?? ComponentType.STRING_SELECT,
|
|
283
|
+
custom_id: this.data.customId,
|
|
284
|
+
placeholder: this.data.placeholder,
|
|
285
|
+
min_values: this.data.minValues,
|
|
286
|
+
max_values: this.data.maxValues,
|
|
287
|
+
disabled: this.data.disabled,
|
|
288
|
+
options: this.data.options?.map((option) => ({
|
|
289
|
+
label: option.label,
|
|
290
|
+
value: option.value,
|
|
291
|
+
description: option.description,
|
|
292
|
+
emoji: serializeEmoji(option.emoji),
|
|
293
|
+
default: option.default
|
|
294
|
+
}))
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var TextInputBuilder = class {
|
|
299
|
+
data = {
|
|
300
|
+
type: ComponentType.TEXT_INPUT
|
|
301
|
+
};
|
|
302
|
+
_minLength;
|
|
303
|
+
_maxLength;
|
|
304
|
+
_required;
|
|
305
|
+
_value;
|
|
306
|
+
setCustomId(id) {
|
|
307
|
+
this.data.customId = id;
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
setLabel(label) {
|
|
311
|
+
this.data.label = label;
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
setStyle(style) {
|
|
315
|
+
this.data.style = style;
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
setPlaceholder(placeholder) {
|
|
319
|
+
this.data.placeholder = placeholder;
|
|
320
|
+
return this;
|
|
321
|
+
}
|
|
322
|
+
setMinLength(length) {
|
|
323
|
+
this._minLength = length;
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
setMaxLength(length) {
|
|
327
|
+
this._maxLength = length;
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
330
|
+
setRequired(required = true) {
|
|
331
|
+
this._required = required;
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
setValue(value) {
|
|
335
|
+
this._value = value;
|
|
336
|
+
return this;
|
|
337
|
+
}
|
|
338
|
+
build() {
|
|
339
|
+
return {
|
|
340
|
+
...this.data,
|
|
341
|
+
minLength: this._minLength,
|
|
342
|
+
maxLength: this._maxLength,
|
|
343
|
+
required: this._required,
|
|
344
|
+
value: this._value
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
toJSON() {
|
|
348
|
+
return {
|
|
349
|
+
type: ComponentType.TEXT_INPUT,
|
|
350
|
+
custom_id: this.data.customId,
|
|
351
|
+
style: this.data.style,
|
|
352
|
+
label: this.data.label,
|
|
353
|
+
placeholder: this.data.placeholder,
|
|
354
|
+
min_length: this._minLength,
|
|
355
|
+
max_length: this._maxLength,
|
|
356
|
+
required: this._required,
|
|
357
|
+
value: this._value
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var ActionRowBuilder = class {
|
|
362
|
+
data = {
|
|
363
|
+
type: ComponentType.ACTION_ROW,
|
|
364
|
+
components: []
|
|
365
|
+
};
|
|
366
|
+
addComponent(component) {
|
|
367
|
+
this.data.components.push(component);
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
addComponents(...components) {
|
|
371
|
+
for (const component of components) {
|
|
372
|
+
this.addComponent(component);
|
|
373
|
+
}
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
build() {
|
|
377
|
+
return {
|
|
378
|
+
...this.data,
|
|
379
|
+
components: this.data.components.map((component) => {
|
|
380
|
+
if (component && typeof component.build === "function") {
|
|
381
|
+
return component.build();
|
|
382
|
+
}
|
|
383
|
+
return component;
|
|
384
|
+
})
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
toJSON() {
|
|
388
|
+
return {
|
|
389
|
+
type: ComponentType.ACTION_ROW,
|
|
390
|
+
components: this.data.components?.map((component) => {
|
|
391
|
+
if (component && typeof component.toJSON === "function") {
|
|
392
|
+
return component.toJSON();
|
|
393
|
+
}
|
|
394
|
+
return component;
|
|
395
|
+
})
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
var ModalBuilder = class {
|
|
400
|
+
_title = "";
|
|
401
|
+
_customId = "";
|
|
402
|
+
_components = [];
|
|
403
|
+
setTitle(title) {
|
|
404
|
+
this._title = title;
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
setCustomId(id) {
|
|
408
|
+
this._customId = id;
|
|
409
|
+
return this;
|
|
410
|
+
}
|
|
411
|
+
addComponent(component) {
|
|
412
|
+
this._components.push(component);
|
|
413
|
+
return this;
|
|
414
|
+
}
|
|
415
|
+
addComponents(...components) {
|
|
416
|
+
for (const component of components) {
|
|
417
|
+
this.addComponent(component);
|
|
418
|
+
}
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
build() {
|
|
422
|
+
return {
|
|
423
|
+
title: this._title,
|
|
424
|
+
custom_id: this._customId,
|
|
425
|
+
components: this._components.map((component) => {
|
|
426
|
+
if (component && typeof component.build === "function") {
|
|
427
|
+
return component.build();
|
|
428
|
+
}
|
|
429
|
+
return component;
|
|
430
|
+
})
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
toJSON() {
|
|
434
|
+
return {
|
|
435
|
+
title: this._title,
|
|
436
|
+
custom_id: this._customId,
|
|
437
|
+
components: this._components.map((component) => {
|
|
438
|
+
if (component && typeof component.toJSON === "function") {
|
|
439
|
+
return component.toJSON();
|
|
440
|
+
}
|
|
441
|
+
return component;
|
|
442
|
+
})
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
function serializeComponent(component) {
|
|
447
|
+
if (!component) return {};
|
|
448
|
+
if (typeof component.toJSON === "function") {
|
|
449
|
+
return component.toJSON();
|
|
450
|
+
}
|
|
451
|
+
if (typeof component.build === "function") {
|
|
452
|
+
return toSnakeCase(component.build());
|
|
453
|
+
}
|
|
454
|
+
return toSnakeCase(component);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/builders/entities.ts
|
|
458
|
+
function buildStageInstance(raw) {
|
|
459
|
+
return {
|
|
460
|
+
id: raw.id,
|
|
461
|
+
guildId: raw.guild_id ?? "",
|
|
462
|
+
channelId: raw.channel_id ?? "",
|
|
463
|
+
topic: raw.topic ?? "",
|
|
464
|
+
privacyLevel: raw.privacy_level ?? 2,
|
|
465
|
+
discoverableDisabled: raw.discoverable_disabled ?? false,
|
|
466
|
+
guildScheduledEventId: raw.guild_scheduled_event_id ?? null
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function buildScheduledEvent(raw) {
|
|
470
|
+
let creator;
|
|
471
|
+
if (raw.creator) {
|
|
472
|
+
creator = buildUser(raw.creator);
|
|
473
|
+
}
|
|
474
|
+
return {
|
|
475
|
+
id: raw.id,
|
|
476
|
+
guildId: raw.guild_id ?? "",
|
|
477
|
+
channelId: raw.channel_id ?? null,
|
|
478
|
+
creatorId: raw.creator_id ?? null,
|
|
479
|
+
name: raw.name ?? "",
|
|
480
|
+
description: raw.description ?? null,
|
|
481
|
+
scheduledStartTime: raw.scheduled_start_time ? Date.parse(raw.scheduled_start_time) : 0,
|
|
482
|
+
scheduledEndTime: raw.scheduled_end_time ? Date.parse(raw.scheduled_end_time) : null,
|
|
483
|
+
privacyLevel: raw.privacy_level ?? 2,
|
|
484
|
+
status: raw.status ?? 1,
|
|
485
|
+
entityType: raw.entity_type ?? 1,
|
|
486
|
+
entityId: raw.entity_id ?? null,
|
|
487
|
+
entityMetadata: raw.entity_metadata ? { ...raw.entity_metadata.location !== void 0 ? { location: raw.entity_metadata.location } : {} } : null,
|
|
488
|
+
...creator ? { creator } : {},
|
|
489
|
+
...raw.user_count !== void 0 ? { userCount: raw.user_count } : {},
|
|
490
|
+
...raw.image !== void 0 ? { image: raw.image } : {}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function buildAutoModActionMetadata(raw) {
|
|
494
|
+
return {
|
|
495
|
+
...raw.channel_id !== void 0 ? { channelId: raw.channel_id } : {},
|
|
496
|
+
...raw.duration_seconds !== void 0 ? { durationSeconds: raw.duration_seconds } : {},
|
|
497
|
+
...raw.custom_message !== void 0 ? { customMessage: raw.custom_message } : {}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function buildAutoModAction(raw) {
|
|
501
|
+
return {
|
|
502
|
+
type: raw.type,
|
|
503
|
+
...raw.metadata ? { metadata: buildAutoModActionMetadata(raw.metadata) } : {}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function buildAutoModTriggerMetadata(raw) {
|
|
507
|
+
return {
|
|
508
|
+
...raw.keyword_filter !== void 0 ? { keywordFilter: raw.keyword_filter } : {},
|
|
509
|
+
...raw.regex_patterns !== void 0 ? { regexPatterns: raw.regex_patterns } : {},
|
|
510
|
+
...raw.presets !== void 0 ? { presets: raw.presets } : {},
|
|
511
|
+
...raw.allow_list !== void 0 ? { allowList: raw.allow_list } : {},
|
|
512
|
+
...raw.mention_total_limit !== void 0 ? { mentionTotalLimit: raw.mention_total_limit } : {},
|
|
513
|
+
...raw.mention_raid_protection_enabled !== void 0 ? { mentionRaidProtectionEnabled: raw.mention_raid_protection_enabled } : {}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function buildAutoModRule(raw) {
|
|
517
|
+
return {
|
|
518
|
+
id: raw.id,
|
|
519
|
+
guildId: raw.guild_id ?? "",
|
|
520
|
+
name: raw.name ?? "",
|
|
521
|
+
creatorId: raw.creator_id ?? "",
|
|
522
|
+
eventType: raw.event_type ?? 1,
|
|
523
|
+
triggerType: raw.trigger_type ?? 1,
|
|
524
|
+
triggerMetadata: raw.trigger_metadata ? buildAutoModTriggerMetadata(raw.trigger_metadata) : {},
|
|
525
|
+
actions: Array.isArray(raw.actions) ? raw.actions.map((a) => buildAutoModAction(a)) : [],
|
|
526
|
+
enabled: raw.enabled ?? false,
|
|
527
|
+
exemptRoles: raw.exempt_roles ?? [],
|
|
528
|
+
exemptChannels: raw.exempt_channels ?? []
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function buildIntegration(raw) {
|
|
532
|
+
let user;
|
|
533
|
+
if (raw.user) {
|
|
534
|
+
user = buildUser(raw.user);
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
id: raw.id,
|
|
538
|
+
name: raw.name ?? "",
|
|
539
|
+
type: raw.type ?? "",
|
|
540
|
+
enabled: raw.enabled ?? false,
|
|
541
|
+
...raw.syncing !== void 0 ? { syncing: raw.syncing } : {},
|
|
542
|
+
...raw.role_id !== void 0 ? { roleId: raw.role_id } : {},
|
|
543
|
+
...raw.enable_emoticons !== void 0 ? { enableEmoticons: raw.enable_emoticons } : {},
|
|
544
|
+
...raw.expire_behavior !== void 0 ? { expireBehavior: raw.expire_behavior } : {},
|
|
545
|
+
...raw.expire_grace_period !== void 0 ? { expireGracePeriod: raw.expire_grace_period } : {},
|
|
546
|
+
...user ? { user } : {},
|
|
547
|
+
account: raw.account ? { id: raw.account.id, name: raw.account.name } : { id: "", name: "" },
|
|
548
|
+
...raw.synced_at ? { syncedAt: Date.parse(raw.synced_at) } : {},
|
|
549
|
+
...raw.subscriber_count !== void 0 ? { subscriberCount: raw.subscriber_count } : {},
|
|
550
|
+
...raw.revoked !== void 0 ? { revoked: raw.revoked } : {},
|
|
551
|
+
...raw.application !== void 0 ? { application: raw.application } : {},
|
|
552
|
+
...raw.scopes !== void 0 ? { scopes: raw.scopes } : {}
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function buildEmoji(raw) {
|
|
556
|
+
let user;
|
|
557
|
+
if (raw.user) {
|
|
558
|
+
user = buildUser(raw.user);
|
|
559
|
+
}
|
|
560
|
+
return {
|
|
561
|
+
id: raw.id ?? null,
|
|
562
|
+
name: raw.name ?? null,
|
|
563
|
+
...raw.roles !== void 0 ? { roles: raw.roles } : {},
|
|
564
|
+
...user ? { user } : {},
|
|
565
|
+
...raw.require_colons !== void 0 ? { requireColons: raw.require_colons } : {},
|
|
566
|
+
...raw.managed !== void 0 ? { managed: raw.managed } : {},
|
|
567
|
+
...raw.animated !== void 0 ? { animated: raw.animated } : {},
|
|
568
|
+
...raw.available !== void 0 ? { available: raw.available } : {}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function buildSticker(raw) {
|
|
572
|
+
let user;
|
|
573
|
+
if (raw.user) {
|
|
574
|
+
user = buildUser(raw.user);
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
id: raw.id,
|
|
578
|
+
...raw.pack_id !== void 0 ? { packId: raw.pack_id } : {},
|
|
579
|
+
name: raw.name ?? "",
|
|
580
|
+
description: raw.description ?? null,
|
|
581
|
+
tags: raw.tags ?? "",
|
|
582
|
+
type: raw.type ?? 1,
|
|
583
|
+
formatType: raw.format_type ?? 1,
|
|
584
|
+
...raw.available !== void 0 ? { available: raw.available } : {},
|
|
585
|
+
...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
|
|
586
|
+
...user ? { user } : {},
|
|
587
|
+
...raw.sort_value !== void 0 ? { sortValue: raw.sort_value } : {}
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function buildStickerItem(raw) {
|
|
591
|
+
return {
|
|
592
|
+
id: raw.id,
|
|
593
|
+
name: raw.name ?? "",
|
|
594
|
+
formatType: raw.format_type ?? 1
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function buildVoiceState(raw, cache) {
|
|
598
|
+
let member;
|
|
599
|
+
if (raw.member && cache && raw.guild_id) {
|
|
600
|
+
member = buildMember(raw.member, raw.guild_id, cache);
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
|
|
604
|
+
channelId: raw.channel_id ?? "",
|
|
605
|
+
userId: raw.user_id ?? "",
|
|
606
|
+
...member ? { member } : {},
|
|
607
|
+
sessionId: raw.session_id ?? "",
|
|
608
|
+
deaf: raw.deaf ?? false,
|
|
609
|
+
mute: raw.mute ?? false,
|
|
610
|
+
selfDeaf: raw.self_deaf ?? false,
|
|
611
|
+
selfMute: raw.self_mute ?? false,
|
|
612
|
+
selfStream: raw.self_stream ?? false,
|
|
613
|
+
selfVideo: raw.self_video ?? false,
|
|
614
|
+
suppress: raw.suppress ?? false,
|
|
615
|
+
requestToSpeakTimestamp: raw.request_to_speak_timestamp ? Date.parse(raw.request_to_speak_timestamp) : null
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function buildEntitlement(raw) {
|
|
619
|
+
return {
|
|
620
|
+
id: raw.id,
|
|
621
|
+
skuId: raw.sku_id ?? "",
|
|
622
|
+
applicationId: raw.application_id ?? "",
|
|
623
|
+
...raw.user_id !== void 0 ? { userId: raw.user_id } : {},
|
|
624
|
+
type: raw.type ?? 1,
|
|
625
|
+
deleted: raw.deleted ?? false,
|
|
626
|
+
...raw.starts_at !== void 0 ? { startsAt: raw.starts_at ? Date.parse(raw.starts_at) : null } : {},
|
|
627
|
+
...raw.ends_at !== void 0 ? { endsAt: raw.ends_at ? Date.parse(raw.ends_at) : null } : {},
|
|
628
|
+
...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
|
|
629
|
+
...raw.consumed !== void 0 ? { consumed: raw.consumed } : {}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function buildInteraction(raw, cache) {
|
|
633
|
+
let user;
|
|
634
|
+
let member;
|
|
635
|
+
if (raw.member && raw.guild_id) {
|
|
636
|
+
const memberRaw = raw.member;
|
|
637
|
+
if (cache) {
|
|
638
|
+
member = buildMember(memberRaw, raw.guild_id, cache);
|
|
639
|
+
}
|
|
640
|
+
if (memberRaw.user) {
|
|
641
|
+
user = buildUser(memberRaw.user);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (!user && raw.user) {
|
|
645
|
+
user = buildUser(raw.user);
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
id: raw.id,
|
|
649
|
+
applicationId: raw.application_id ?? "",
|
|
650
|
+
type: raw.type ?? 1,
|
|
651
|
+
...raw.data !== void 0 ? { data: raw.data } : {},
|
|
652
|
+
...raw.guild_id !== void 0 ? { guildId: raw.guild_id } : {},
|
|
653
|
+
...raw.channel_id !== void 0 ? { channelId: raw.channel_id } : {},
|
|
654
|
+
...member ? { member } : {},
|
|
655
|
+
...user ? { user } : {},
|
|
656
|
+
token: raw.token ?? "",
|
|
657
|
+
version: raw.version ?? 1,
|
|
658
|
+
...raw.message !== void 0 ? { message: raw.message } : {},
|
|
659
|
+
...raw.app_permissions !== void 0 ? { appPermissions: raw.app_permissions } : {},
|
|
660
|
+
...raw.locale !== void 0 ? { locale: raw.locale } : {},
|
|
661
|
+
...raw.guild_locale !== void 0 ? { guildLocale: raw.guild_locale } : {},
|
|
662
|
+
entitlements: Array.isArray(raw.entitlements) ? raw.entitlements.map((e) => buildEntitlement(e)) : [],
|
|
663
|
+
authorizingIntegrationOwners: raw.authorizing_integration_owners ?? {},
|
|
664
|
+
...raw.context !== void 0 ? { context: raw.context } : {}
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// src/builders/index.ts
|
|
669
|
+
function buildUser(raw) {
|
|
670
|
+
return {
|
|
671
|
+
id: raw.id,
|
|
672
|
+
username: raw.username,
|
|
673
|
+
discriminator: raw.discriminator,
|
|
674
|
+
globalName: raw.global_name ?? null,
|
|
675
|
+
avatar: raw.avatar ?? null,
|
|
676
|
+
bot: raw.bot ?? false,
|
|
677
|
+
system: raw.system ?? false,
|
|
678
|
+
mfaEnabled: raw.mfa_enabled ?? false,
|
|
679
|
+
banner: raw.banner ?? null,
|
|
680
|
+
accentColor: raw.accent_color ?? null,
|
|
681
|
+
locale: raw.locale ?? void 0,
|
|
682
|
+
flags: raw.flags ?? 0,
|
|
683
|
+
premiumType: raw.premium_type ?? 0,
|
|
684
|
+
publicFlags: raw.public_flags ?? 0
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
function buildChannel(raw, guildId) {
|
|
688
|
+
return {
|
|
689
|
+
id: raw.id,
|
|
690
|
+
type: raw.type,
|
|
691
|
+
guildId: raw.guild_id ?? guildId ?? void 0,
|
|
692
|
+
name: raw.name ?? null,
|
|
693
|
+
position: raw.position ?? 0,
|
|
694
|
+
parentId: raw.parent_id ?? null,
|
|
695
|
+
topic: raw.topic ?? null,
|
|
696
|
+
nsfw: raw.nsfw ?? false,
|
|
697
|
+
lastMessageId: raw.last_message_id ?? null,
|
|
698
|
+
bitrate: raw.bitrate ?? void 0,
|
|
699
|
+
userLimit: raw.user_limit ?? void 0,
|
|
700
|
+
rateLimitPerUser: raw.rate_limit_per_user ?? 0,
|
|
701
|
+
permissionOverwrites: raw.permission_overwrites ?? []
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function buildGuild(raw) {
|
|
705
|
+
return {
|
|
706
|
+
id: raw.id,
|
|
707
|
+
name: raw.name,
|
|
708
|
+
icon: raw.icon ?? null,
|
|
709
|
+
splash: raw.splash ?? null,
|
|
710
|
+
discoverySplash: raw.discovery_splash ?? null,
|
|
711
|
+
ownerId: raw.owner_id,
|
|
712
|
+
afkChannelId: raw.afk_channel_id ?? null,
|
|
713
|
+
afkTimeout: raw.afk_timeout ?? 0,
|
|
714
|
+
verificationLevel: raw.verification_level ?? 0,
|
|
715
|
+
defaultMessageNotifications: raw.default_message_notifications ?? 0,
|
|
716
|
+
explicitContentFilter: raw.explicit_content_filter ?? 0,
|
|
717
|
+
features: raw.features ?? [],
|
|
718
|
+
mfaLevel: raw.mfa_level ?? 0,
|
|
719
|
+
systemChannelId: raw.system_channel_id ?? null,
|
|
720
|
+
systemChannelFlags: raw.system_channel_flags ?? 0,
|
|
721
|
+
rulesChannelId: raw.rules_channel_id ?? null,
|
|
722
|
+
memberCount: raw.member_count ?? 0,
|
|
723
|
+
vanityUrlCode: raw.vanity_url_code ?? null,
|
|
724
|
+
description: raw.description ?? null,
|
|
725
|
+
banner: raw.banner ?? null,
|
|
726
|
+
premiumTier: raw.premium_tier ?? 0,
|
|
727
|
+
premiumSubscriptionCount: raw.premium_subscription_count ?? 0,
|
|
728
|
+
preferredLocale: raw.preferred_locale ?? "en-US",
|
|
729
|
+
publicUpdatesChannelId: raw.public_updates_channel_id ?? null,
|
|
730
|
+
nsfwLevel: raw.nsfw_level ?? 0,
|
|
731
|
+
premiumProgressBarEnabled: raw.premium_progress_bar_enabled ?? false,
|
|
732
|
+
roles: Array.isArray(raw.roles) ? raw.roles.map((r) => buildRole(r)) : [],
|
|
733
|
+
emojis: raw.emojis ?? [],
|
|
734
|
+
applicationId: raw.application_id ?? null,
|
|
735
|
+
large: raw.large ?? false
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function buildRole(raw) {
|
|
739
|
+
return {
|
|
740
|
+
id: raw.id,
|
|
741
|
+
name: raw.name,
|
|
742
|
+
color: raw.color ?? 0,
|
|
743
|
+
hoist: raw.hoist ?? false,
|
|
744
|
+
position: raw.position ?? 0,
|
|
745
|
+
permissions: raw.permissions,
|
|
746
|
+
managed: raw.managed ?? false,
|
|
747
|
+
mentionable: raw.mentionable ?? false,
|
|
748
|
+
icon: raw.icon ?? null,
|
|
749
|
+
unicodeEmoji: raw.unicode_emoji ?? null,
|
|
750
|
+
flags: raw.flags ?? 0
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function buildMember(raw, guildId, cache) {
|
|
754
|
+
let userObj;
|
|
755
|
+
if (raw.user) {
|
|
756
|
+
const user = buildUser(raw.user);
|
|
757
|
+
cache.users.set(user.id, user);
|
|
758
|
+
userObj = user;
|
|
759
|
+
}
|
|
760
|
+
return {
|
|
761
|
+
...userObj ? { user: userObj } : {},
|
|
762
|
+
nick: raw.nick ?? null,
|
|
763
|
+
avatar: raw.avatar ?? null,
|
|
764
|
+
roles: raw.roles ?? [],
|
|
765
|
+
joinedAt: raw.joined_at ? Date.parse(raw.joined_at) : 0,
|
|
766
|
+
premiumSince: raw.premium_since ? Date.parse(raw.premium_since) : null,
|
|
767
|
+
deaf: raw.deaf ?? false,
|
|
768
|
+
mute: raw.mute ?? false,
|
|
769
|
+
pending: raw.pending ?? false,
|
|
770
|
+
flags: raw.flags ?? 0,
|
|
771
|
+
communicationDisabledUntil: raw.communication_disabled_until ? Date.parse(raw.communication_disabled_until) : null
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
function buildMessage(raw, cache, oldMessage) {
|
|
775
|
+
const authorRaw = raw.author;
|
|
776
|
+
const author = authorRaw ? buildUser(authorRaw) : oldMessage?.author ?? {};
|
|
777
|
+
if (authorRaw && author.id) {
|
|
778
|
+
cache.users.set(author.id, author);
|
|
779
|
+
}
|
|
780
|
+
const msgId = raw.id ?? oldMessage?.id;
|
|
781
|
+
const channelId = raw.channel_id ?? oldMessage?.channelId;
|
|
782
|
+
const guildId = raw.guild_id ? raw.guild_id : oldMessage?.guildId;
|
|
783
|
+
const msg = {
|
|
784
|
+
id: msgId,
|
|
785
|
+
channelId,
|
|
786
|
+
author,
|
|
787
|
+
...guildId ? { guildId } : {},
|
|
788
|
+
url: `https://discord.com/channels/${guildId ?? "@me"}/${channelId}/${msgId}`,
|
|
789
|
+
content: raw.content ?? oldMessage?.content ?? "",
|
|
790
|
+
timestamp: raw.timestamp ? Date.parse(raw.timestamp) : oldMessage?.timestamp ?? Date.now(),
|
|
791
|
+
editedTimestamp: raw.edited_timestamp ? Date.parse(raw.edited_timestamp) : oldMessage?.editedTimestamp ?? null,
|
|
792
|
+
tts: raw.tts ?? oldMessage?.tts ?? false,
|
|
793
|
+
mentionEveryone: raw.mention_everyone ?? oldMessage?.mentionEveryone ?? false,
|
|
794
|
+
mentions: raw.mentions ? raw.mentions.map((m) => buildUser(m)) : oldMessage?.mentions ?? [],
|
|
795
|
+
mentionRoles: raw.mention_roles ?? oldMessage?.mentionRoles ?? [],
|
|
796
|
+
attachments: raw.attachments ?? oldMessage?.attachments ?? [],
|
|
797
|
+
embeds: raw.embeds ?? oldMessage?.embeds ?? [],
|
|
798
|
+
pinned: raw.pinned ?? oldMessage?.pinned ?? false,
|
|
799
|
+
type: raw.type ?? oldMessage?.type ?? 0
|
|
800
|
+
};
|
|
801
|
+
return msg;
|
|
802
|
+
}
|
|
803
|
+
function resolveChannel(channelId, client) {
|
|
804
|
+
return client.cache.channels.get(channelId) ?? { id: channelId, fetch: () => client.channels.fetch(channelId) };
|
|
805
|
+
}
|
|
806
|
+
function resolveGuild(guildId, client) {
|
|
807
|
+
return client.cache.guilds.get(guildId) ?? { id: guildId, fetch: () => client.guilds.fetch(guildId) };
|
|
808
|
+
}
|
|
809
|
+
function resolveUser(userId, client) {
|
|
810
|
+
return client.cache.users.get(userId) ?? { id: userId, fetch: () => client.users.fetch(userId) };
|
|
811
|
+
}
|
|
812
|
+
function resolveRole(roleId, client, guildId) {
|
|
813
|
+
const stub = { id: roleId };
|
|
814
|
+
if (guildId) stub.fetch = () => client.guilds.roles(guildId).fetch(roleId);
|
|
815
|
+
return client.cache.roles.get(roleId) ?? stub;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
export {
|
|
819
|
+
ComponentType,
|
|
820
|
+
ButtonStyle,
|
|
821
|
+
Colors,
|
|
822
|
+
EmbedBuilder,
|
|
823
|
+
toSnakeCase,
|
|
824
|
+
ButtonBuilder,
|
|
825
|
+
SelectMenuBuilder,
|
|
826
|
+
TextInputBuilder,
|
|
827
|
+
ActionRowBuilder,
|
|
828
|
+
ModalBuilder,
|
|
829
|
+
serializeComponent,
|
|
830
|
+
buildStageInstance,
|
|
831
|
+
buildScheduledEvent,
|
|
832
|
+
buildAutoModRule,
|
|
833
|
+
buildIntegration,
|
|
834
|
+
buildEmoji,
|
|
835
|
+
buildSticker,
|
|
836
|
+
buildStickerItem,
|
|
837
|
+
buildVoiceState,
|
|
838
|
+
buildEntitlement,
|
|
839
|
+
buildInteraction,
|
|
840
|
+
buildUser,
|
|
841
|
+
buildChannel,
|
|
842
|
+
buildGuild,
|
|
843
|
+
buildRole,
|
|
844
|
+
buildMember,
|
|
845
|
+
buildMessage,
|
|
846
|
+
resolveChannel,
|
|
847
|
+
resolveGuild,
|
|
848
|
+
resolveUser,
|
|
849
|
+
resolveRole
|
|
850
|
+
};
|