discord-vatron
Version:
Módulo para facilitar la interacción con la API de Discord
98 lines (82 loc) • 2.87 kB
JavaScript
const { colores } = require('../../props.js');
module.exports = class Embed {
constructor(embObj = {}) {
this.type = 'rich';
this.title = '';
this.author = {};
this.image = {};
this.description = '';
this.fields = [];
this.color = 0;
this.url = '';
this.thumbnail = {};
this.footer = {};
//this.timestamp = (new Date());
if(embObj && typeof(embObj) == 'object' && !Array.isArray(embObj)) Object.assign(this, embObj);
}
estTitulo(t) {
this.title = t || '';
return this;
}
estAutor(opciones) {
if(!opciones) return this;
if(opciones.nombre) this.author.name = opciones.nombre;
if(opciones.url) this.author.url = opciones.url;
if(opciones.icono) this.author.icon_url = opciones.icono;
if(opciones.iconoProxy) this.author.proxy_icon_url = opciones.iconoProxy;
return this;
}
estDesc(d) {
this.description = d || '';
return this;
}
estColor(c = 0) {
if(colores[c]) c = colores[c];
if(c == 'ALEATORIO') c = Object.values(colores)[Math.floor(Math.random() * Object.values(colores).length)];
c = typeof(c) == 'number' ? c : parseInt(c.replace(/\#/g, ''), 16);
this.color = c || 0;
return this;
}
estImg(opciones) {
if(!opciones) return this;
if(opciones.url) this.image.url = opciones.url;
/*if(opciones.urlProxy) this.image.proxy_url = opciones.urlProxy;
if(opciones.altura) this.image.height = opciones.altura;
if(opciones.anchura) this.image.width = opciones.anchura;*/
return this;
}
estVideo(opciones) {
if(!opciones) return this;
if(opciones.url) this.video.url = opciones.url;
return this;
}
estMarcaTiempo(t) {
t = new Date(t || Date.now()).toISOString();
this.timestamp = t;
return this;
}
anadirCampo(opciones) {
if(!opciones) return this;
let objC = {};
if(opciones.titulo) objC.name = opciones.titulo || '';
if(opciones.desc) objC.value = opciones.desc || '';
if(opciones.enLinea) objC.inline = opciones.enLinea || false;
this.fields.push(objC);
return this;
}
estUrl(url) {
this.url = url || '';
return this;
}
estMiniatura(opciones) {
if(!opciones) return this;
if(opciones.url) this.thumbnail.url = opciones.url;
return this;
}
estPie(opciones) {
if(!opciones) return this;
if(opciones.texto) this.footer.text = opciones.texto;
if(opciones.icono) this.footer.icon_url = opciones.icono;
return this;
}
}