2023-04-14 16:52:56 -04:00
|
|
|
import { Interaction } from "./interaction.js";
|
|
|
|
|
|
2023-04-25 17:34:01 -04:00
|
|
|
/** @enum {number} */
|
|
|
|
|
export const textInputStyle = Object.freeze({
|
|
|
|
|
Short: 1,
|
|
|
|
|
paragraph: 2
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export class ModalComponent {
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
custom_id;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
label;
|
|
|
|
|
|
|
|
|
|
/** @type {Boolean} */
|
|
|
|
|
required;
|
|
|
|
|
|
|
|
|
|
/** @type {number} */
|
|
|
|
|
min_length;
|
|
|
|
|
|
|
|
|
|
/** @type {number} */
|
|
|
|
|
max_length;
|
|
|
|
|
|
|
|
|
|
/** @type {textInputStyle} */
|
|
|
|
|
style;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
value;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
placeholder;
|
|
|
|
|
|
|
|
|
|
toObj() {
|
|
|
|
|
if (this.style != 1 && this.style != 2) throw `MODAL TEXT INPUT STYLE MUST BE 1 OR 2 BUT WAS '${this.style}'`;
|
|
|
|
|
const obj = {type: 4};
|
|
|
|
|
for (const k in this) {
|
|
|
|
|
if (this[k]) obj[k] = this[k];
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(obj) {
|
|
|
|
|
for (const k in this) {
|
|
|
|
|
if (obj[k] != undefined) {
|
|
|
|
|
this[k] = obj[k];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 16:52:56 -04:00
|
|
|
|
|
|
|
|
export class Modal extends Interaction {
|
2023-04-25 17:34:01 -04:00
|
|
|
/** @type {String} */
|
|
|
|
|
title;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
custom_id;
|
|
|
|
|
|
|
|
|
|
/** @type {ModalComponent[]} */
|
|
|
|
|
components;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {ModalComponent} c
|
|
|
|
|
*/
|
|
|
|
|
addComponent(c) {
|
|
|
|
|
this.components.push(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toObj() {
|
|
|
|
|
const obj = {title: this.title, custom_id: this.custom_id, components: []};
|
|
|
|
|
for (const comp of this.components) {
|
|
|
|
|
obj.components.push(comp.toObj());
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 16:52:56 -04:00
|
|
|
constructor(intRaw, client) {
|
|
|
|
|
super(intRaw, client);
|
2023-04-25 17:34:01 -04:00
|
|
|
this.components = [];
|
|
|
|
|
|
|
|
|
|
if (!intRaw) return;
|
|
|
|
|
|
|
|
|
|
// [ { value: 'nnnnnnnnnnnnn', type: 4, custom_id: 'nonononononono' } ]
|
|
|
|
|
for (const opt of intRaw.data.components) {
|
|
|
|
|
//These are nested
|
|
|
|
|
// this.components.push(new ModalComponent());
|
|
|
|
|
}
|
2023-04-14 16:52:56 -04:00
|
|
|
}
|
|
|
|
|
}
|