UNPKG

discord-vatron

Version:

Módulo para facilitar la interacción con la API de Discord

55 lines (46 loc) 1.92 kB
const request = require('request-promise-native'); const { errores } = require('../../props'); module.exports = class Emoji { constructor(datos, bot) { this._datos = datos; this._bot = bot; this.nombre = datos.name; this.id = datos.id; this.animado = datos.animated || false; } eliminar() { const promesa = new Promise((resolve, reject) => { const emoji = this; request.delete({ url: `https://discord.com/api/v9/guilds/${this.servidor.id}/emojis/${this.id}`, headers: { Authorization: 'Bot ' + this._bot.token } }) .then(() => { resolve(emoji); }) .catch((err) => { reject('[DISCORD-VATRON] ' + errores[err.statusCode] || err.message); }); }); return promesa; } editar(opciones) { const promesa = new Promise((resolve, reject) => { const opc = { name: opciones.nombre || this.nombre }; request.patch({ url: `https://discord.com/api/v9/guilds/${this.servidor.id}/emojis/${this.id}`, headers: { Authorization: 'Bot ' + this._bot.token, 'Content-Type': 'application/json' }, body: JSON.stringify(opc) }) .then(e => { this._bot.emojis._setEmoji(JSON.parse(e), this._bot, this.servidor); resolve(new Emoji(JSON.parse(e), this._bot)); }) .catch(err => { reject('[DISCORD-VATRON] ' + errores[err.statusCode] || err.message); }); }); return promesa; } get servidor() { return this._bot.servidores.has(this._datos.guild_id) ? this._bot.servidores.get(this._datos.guild_id) : null; } toString() { return `<${this.animado?'a':''}:${this.nombre}:${this.id}>`; } }