UNPKG

sheweny

Version:

The powerful framework for create discord bots

227 lines 7.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShewenyClient = void 0; const path_1 = require("path"); const promises_1 = require("fs/promises"); const discord_js_1 = require("discord.js"); const ClientUtil_js_1 = require("./ClientUtil.js"); const index_js_1 = require("../managers/index.js"); const index_js_2 = require("../helpers/index.js"); const constants_js_1 = require("../constants/constants.js"); /** * Sheweny framework client */ class ShewenyClient extends discord_js_1.Client { /** * Set options and your client is ready * @param {ShewenyClientOptions} [options] Client framework options * @param {ClientOptions} [clientOptions] Client discord.js options */ constructor(options, clientOptions) { super(clientOptions || options); /** * The ID of the bot admins * @type {Snowflake[]} */ Object.defineProperty(this, "admins", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * The collections of handlers * @type {ManagersCollections} */ Object.defineProperty(this, "collections", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * The cooldowns of the client * @type {Cooldowns} */ Object.defineProperty(this, "cooldowns", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * If the client is ready * @type {boolean} */ Object.defineProperty(this, "connected", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * If the cooldown should be desactivated for admins * @type {boolean} */ Object.defineProperty(this, "disableCooldownsForAdmins", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * If the client joins threads when created * @type {boolean} */ Object.defineProperty(this, "joinThreadsOnCreate", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * The mode of the application (developement or production) * @type {string} */ Object.defineProperty(this, "mode", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * The manager of client * @type {Managers} */ Object.defineProperty(this, "managers", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * A util tool to resolve and get informations * @type {ClientUtil} */ Object.defineProperty(this, "util", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.admins = options.admins || []; this.collections = { commands: new discord_js_1.Collection(), events: new discord_js_1.Collection(), buttons: new discord_js_1.Collection(), inhibitors: new discord_js_1.Collection(), modals: new discord_js_1.Collection(), selectMenus: new discord_js_1.Collection(), }; this.cooldowns = { commands: new discord_js_1.Collection(), buttons: new discord_js_1.Collection(), selectMenus: new discord_js_1.Collection(), modals: new discord_js_1.Collection(), }; this.connected = false; this.disableCooldownsForAdmins = options.disableCooldownsForAdmins || false; this.joinThreadsOnCreate = options.joinThreadsOnCreate || false; /** **** MANAGERS ******/ this.managers = {}; // BUTTONS if (options.managers?.buttons) { this.managers.buttons = new index_js_1.ButtonsManager(this, { ...options.managers.buttons, }); this.managers.buttons.loadAll().then(buttons => { if (buttons) this.collections.buttons = buttons; }); } // COMMANDS if (options.managers?.commands) { this.managers.commands = new index_js_1.CommandsManager(this, { ...options.managers.commands, autoRegisterApplicationCommands: options.managers.commands.autoRegisterApplicationCommands ?? true, }); this.managers.commands.loadAll().then(commands => { if (commands) this.collections.commands = commands; }); } // EVENTS if (options.managers?.events) { this.managers.events = new index_js_1.EventsManager(this, { ...options.managers.events, }); this.managers.events.loadAll().then(events => { if (events) this.collections.events = events; }); } // INHIBITORS if (options.managers?.inhibitors) { this.managers.inhibitors = new index_js_1.InhibitorsManager(this, { ...options.managers.inhibitors, }); this.managers.inhibitors.loadAll().then(inhibitors => { if (inhibitors) this.collections.inhibitors = inhibitors; }); } // MODALS if (options.managers?.modals) { this.managers.modals = new index_js_1.ModalsManager(this, { ...options.managers.modals, }); this.managers.modals.loadAll().then(modals => { if (modals) this.collections.modals = modals; }); } // SELECT MENUS if (options.managers?.selectMenus) { this.managers.selectMenus = new index_js_1.SelectMenusManager(this, { ...options.managers.selectMenus, }); this.managers.selectMenus.loadAll().then(selectmenus => { if (selectmenus) this.collections.selectMenus = selectmenus; }); } this.mode = options.mode || constants_js_1.CLIENT_MODE.dev; this.util = new ClientUtil_js_1.ClientUtil(this); if (options.mode === constants_js_1.CLIENT_MODE.dev) new index_js_2.ShewenyWarning(this, 'START'); // Load framework events (async () => { // if(require) const dir = (0, path_1.resolve)(__dirname, '../events'); const files = await (0, promises_1.readdir)(dir); for (const file of files) { if (!file?.endsWith('.js')) continue; const evtName = file.split('.')[0]; const event = await Promise.resolve().then(() => __importStar(require(`${dir}/${file}`))).then(e => e.default); if (evtName) this.on(evtName, (...args) => event(this, ...args)); } })(); } /** * Return true when the client is ready * @returns {Promise<boolean>} */ awaitReady() { return new Promise(resolve => { if (this.connected) return resolve(true); this.once('ready', () => { return resolve(true); }); }); } } exports.ShewenyClient = ShewenyClient; //# sourceMappingURL=Client.js.map