UNPKG

@discord-rahmen/discord.js-layer

Version:

Discord.js compatibility layer for the discord-rahmen framework

127 lines (126 loc) 4.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DRClient = void 0; const v10_1 = require("discord-api-types/v10"); const discord_js_1 = require("discord.js"); class DRClient { wrapperClient; constructor(options) { this.wrapperClient = new discord_js_1.Client(options.clientOptions); // Setting Presence if given if (options.precense) { this.wrapperClient.once("ready", () => { this.wrapperClient.user.setPresence(options.precense); }); } this.wrapperClient.login(options.token).then(); } // Making data universal available get application() { return this.wrapperClient.application; } fetchUser(id) { if (id === "all") return this.wrapperClient.users.cache; return this.wrapperClient.users.fetch(id); } fetchGuild(id) { if (id === "all") return this.wrapperClient.guilds.cache; return this.wrapperClient.guilds.fetch(id); } fetchEmoji(id) { if (id === "all") return this.wrapperClient.guilds.cache; return this.wrapperClient.emojis.cache.get(id); } // Adding application-command management createCommand(command, guildID) { return this.wrapperClient.application.commands.create(command, guildID); } fetchCommand(id, options) { return this.wrapperClient.application.commands.fetch(id, options); } deleteCommand(command, guildID) { return this.wrapperClient.application.commands.delete(command, guildID); } editCommand(command, data, guildID) { return this.wrapperClient.application.commands.edit(command, data, guildID); } setCommand(commands, guildID) { return this.wrapperClient.application.commands.set(commands, guildID); } // Converting Applicationcommand types to Discord.js Options convertOptionType(option) { const data = { "STRING": v10_1.ApplicationCommandOptionType.String, "NUMBER": v10_1.ApplicationCommandOptionType.Number, "BOOLEAN": v10_1.ApplicationCommandOptionType.Boolean, "SUB_COMMAND": v10_1.ApplicationCommandOptionType.Subcommand, "SUB_COMMAND_GROUP": v10_1.ApplicationCommandOptionType.SubcommandGroup, "USER": v10_1.ApplicationCommandOptionType.User, "CHANNEL": v10_1.ApplicationCommandOptionType.Channel, "ROLE": v10_1.ApplicationCommandOptionType.Role, "MENTIONABLE": v10_1.ApplicationCommandOptionType.Mentionable, "INTEGER": v10_1.ApplicationCommandOptionType.Integer, "ATTACHMENT": v10_1.ApplicationCommandOptionType.Attachment, }; if (typeof option === 'string') { return data[option] ?? data["STRING"]; } return option; } convertCommandType(type) { const data = { "CHAT_INPUT": v10_1.ApplicationCommandType.ChatInput, "USER": v10_1.ApplicationCommandType.User, "MESSAGE": v10_1.ApplicationCommandType.Message, }; if (typeof data === 'string') { return data[type] ?? data["CHAT_INPUT"]; } return data; } // Running Events universally newInteractionListener(once, listener) { if (once) { this.wrapperClient.once("interactionCreate", listener); } else { this.wrapperClient.on("interactionCreate", listener); } } newMessageListener(once, listener) { if (once) { this.wrapperClient.once("messageCreate", listener); } else { this.wrapperClient.on("messageCreate", listener); } } debugListener(once, listener) { if (once) { this.wrapperClient.once("debug", listener); } else { this.wrapperClient.on("debug", listener); } } warnListener(once, listener) { if (once) { this.wrapperClient.once("warn", listener); } else { this.wrapperClient.on("warn", listener); } } errorListener(once, listener) { if (once) { this.wrapperClient.once("error", listener); } else { this.wrapperClient.on("error", listener); } } } exports.DRClient = DRClient;