UNPKG

discord-vatron

Version:

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

93 lines (80 loc) 3.58 kB
const request = require("request-promise-native"); const { errores } = require("../../props"); const Mensaje = require("./Mensaje"); module.exports = class Interaccion { constructor(datos, bot) { this._datos = datos; this._bot = bot; } responder(opciones = {}) { if(!opciones.contenido && !opciones.embeds) return console.log('[DISCORD-VATRON] No hay contenido ni embeds en lo que quieres responder'); const promesa = new Promise((resolve, reject) => { request.post({ url: `https://discord.com/api/v9/interactions/${this._datos.id}/${this._datos.token}/callback`, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ type: 4, data: { content: opciones.contenido || '', embeds: opciones.embeds && Array.isArray(opciones.embeds) ? opciones.embeds : [], flags: opciones.propio ? 1 << 6 : false } }) }) .then((r) => { resolve(this); }) .catch((err) => { reject('[DISCORD-VATRON] ' + errores[err.statusCode] || err.message); }); }); return promesa; } aplazar(opciones = {}) { const promesa = new Promise((resolve, reject) => { request.post({ url: `https://discord.com/api/v9/interactions/${this._datos.id}/${this._datos.token}/callback`, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ type: 6, data: { flags: opciones.propio ? 1 << 6 : false } }) }) .then(() => { resolve(this); }) .catch((err) => { reject('[DISCORD-VATRON] ' + errores[err.statusCode] || err.message); }); }); return promesa; } pensar(opciones = {}) { const promesa = new Promise((resolve, reject) => { request.post({ url: `https://discord.com/api/v9/interactions/${this._datos.id}/${this._datos.token}/callback`, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ type: 5, data: { flags: opciones.propio ? 1 << 6 : false } }) }) .then(() => { resolve(this); }) .catch((err) => { reject('[DISCORD-VATRON] ' + errores[err.statusCode] || err.message); }); }); return promesa; } get mensaje() { this._datos.message.guild_id = this._datos.guild_id; this._datos.message.channel_id = this._datos.channel_id; return new Mensaje(this._datos.message, this._bot); } get servidor() { return this._bot.servidores.has(this._datos.guild_id) ? this._bot.servidores.get(this._datos.guild_id) : null; } get canal() { return this._bot.canales.has(this._datos.channel_id) ? this._bot.canales.get(this._datos.channel_id) : null; } get miembro() { return this._bot.servidores.has(this._datos.guild_id) ? this._bot.servidores.get(this._datos.guild_id).miembros.has(this._datos.member.user.id) ? this._bot.servidores.get(this._datos.guild_id).miembros.get(this._datos.member.user.id) : null : null; } get idBoton() { return this._datos.data ? (this._datos.data.custom_id || null) : null; } }