UNPKG

hennus-api

Version:

Esta es una libreria para el bot Hennus

184 lines (183 loc) 5.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InteractionCommands = void 0; const v10_1 = require("discord-api-types/v10"); const interaction_1 = require("../base/interaction"); class InteractionCommands extends interaction_1.BasedInteraction { constructor(data, client) { super(data, client); this.options = new Options(this); this.cmdData = data.data; this.commandName = this.cmdData.name; this.commandId = this.cmdData.id; this.commandType = this.cmdData.type; } ; toString() { if (this.commandName && this.commandId) return `</${this.commandName}:${this.commandId}>`; else return ""; } ; } exports.InteractionCommands = InteractionCommands; ; class Options { constructor(data) { Object.defineProperty(this, "data", { value: data }); } ; get(name, required) { const data = this.datas("null"); const find = data.find((d) => d.name == name); if (required && find) return find; else return find; } ; getString(name, required) { const data = this.find("string", name); if (required) return data; else return (data ?? undefined); } ; getInteger(name, required) { const data = this.find("integer", name); if (required) return data; else return (data ?? undefined); } ; getNumber(name, required) { const data = this.find("number", name); if (required) return data; else return (data ?? undefined); } ; getBoolean(name, required) { const data = this.find("boolean", name); if (required) return data; else return (data ?? undefined); } ; getUser(name, required) { const data = this.find("user", name); if (required) return data; else return (data ?? undefined); } ; getChannel(name, required) { const data = this.find("channel", name); if (required) return data; else return (data ?? undefined); } ; getRole(name, required) { const data = this.find("role", name); if (required) return data; else return (data ?? undefined); } ; getMentionable(name, required) { const data = this.find("mentionable", name); if (required) return data; else return (data ?? undefined); } ; getAttachment(name, required) { const data = this.find("attachment", name); if (required) return data; else return (data ?? undefined); } ; get subCommand() { return this.find("subcommand"); } ; get subCommandGroup() { return this.find("subcommandGroup"); } ; find(type, find) { const typeMapping = { number: v10_1.ApplicationCommandOptionType.Number, integer: v10_1.ApplicationCommandOptionType.Integer, string: v10_1.ApplicationCommandOptionType.String, boolean: v10_1.ApplicationCommandOptionType.Boolean, attachment: v10_1.ApplicationCommandOptionType.Attachment, channel: v10_1.ApplicationCommandOptionType.Channel, role: v10_1.ApplicationCommandOptionType.Role, mentionable: v10_1.ApplicationCommandOptionType.Mentionable, user: v10_1.ApplicationCommandOptionType.User, subcommand: v10_1.ApplicationCommandOptionType.Subcommand, subcommandGroup: v10_1.ApplicationCommandOptionType.SubcommandGroup }; if (type === "subcommandGroup") return this.datas("subcommandGroup"); else if (type === "subcommand") return (this.datas("subcommand") ?? []); const data = this.datas("null") ?? []; const finds = data.find((s) => s.name === find); if (!type || !finds || finds.type !== typeMapping[type]) return undefined; if (type === "channel") { const channel = this.data.client.channels.resolve(finds.value); return { id: finds.value, channel, name: finds.name, type: finds.type }; } else if (type === "role") { const role = this.data.guild.roles.cache.get(finds.value); return { id: finds.value, role, name: finds.name, type: finds.type }; } else if (type === "user") { const user = this.data.client.users.resolve(finds.value); return { id: finds.value, user, name: finds.name, type: finds.type }; } return { name: finds.name, type: finds.type, value: finds.value }; } ; datas(type) { const data = this.data.cmdData; if (data.type !== v10_1.ApplicationCommandType.ChatInput) return []; let datos = data.options ?? []; if (datos[0].type === v10_1.ApplicationCommandOptionType.SubcommandGroup) { if (type === "subcommandGroup") return [datos[0].name, datos[0].options]; datos = datos[0].options; } ; if (datos[0].type === v10_1.ApplicationCommandOptionType.Subcommand) { if (type === "subcommand") return [datos[0].name, datos[0].options ?? []]; return (datos[0].options ?? []); } ; if (type === "subcommand" || type === "subcommandGroup") return []; return datos; } ; } ; ; ; ;