UNPKG

sheweny

Version:

The powerful framework for create discord bots

88 lines 4.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const constants_js_1 = require("../constants/constants.js"); const index_js_1 = require("../helpers/index.js"); const discord_js_1 = require("discord.js"); async function run(client, interaction) { try { if (!client.collections.selectMenus) return; const selects = []; for (const [, structure] of client.collections.selectMenus) { if (!structure || (structure && !structure.length)) return; for (const select of structure) { for (const customId of select.customId) { if (!(customId instanceof RegExp) && customId === interaction.customId) { selects.push(select); } else if (customId instanceof RegExp && customId.test(interaction.customId)) { customId.lastIndex = 0; selects.push(select); } } } } if (!selects || (selects && !selects.length)) return; for (const selectMenu of selects) { await (async () => { if (!selectMenu) return; if (selectMenu.before) await selectMenu.before(interaction); /** * Handle inhibitors */ const inhibitorsCollection = client.collections.inhibitors?.filter((is) => { for (const i of is) { return i.type.includes(constants_js_1.INHIBITOR_TYPE.select) || i.type.includes(constants_js_1.INHIBITOR_TYPE.all); } return false; }); const inhibitorsArray = []; for (const [, inhibitors] of inhibitorsCollection) { if (inhibitors && inhibitors.length) { for (const inhibitor of inhibitors) { inhibitorsArray.push(inhibitor); } } } if (inhibitorsArray && inhibitorsArray.length) { const sorted = inhibitorsArray.sort((a, b) => b.priority - a.priority); for (const i of sorted) { if (!(await i.execute(selectMenu, interaction))) return await i.onFailure(selectMenu, interaction); } } /* ---------------COOLDOWNS--------------- */ if (!client.admins?.includes(interaction.user.id)) { if (!client.cooldowns.buttons.has(selectMenu.customId)) { client.cooldowns.buttons.set(selectMenu.customId, new discord_js_1.Collection()); } const timeNow = Date.now(); const tStamps = client.cooldowns.buttons.get(selectMenu.customId); const cdAmount = (selectMenu.cooldown || 0) * 1000; if (tStamps) { if (tStamps.has(interaction.user.id)) { const cdExpirationTime = (tStamps.get(interaction.user.id) || 0) + cdAmount; if (timeNow < cdExpirationTime) { // const timeLeft = (cdExpirationTime - timeNow) / 1000; return client.managers.buttons?.emit(constants_js_1.SELECT_EVENTS.cooldownLimit, interaction, cdExpirationTime - timeNow); } } tStamps.set(interaction.user.id, timeNow); setTimeout(() => tStamps.delete(interaction.user.id), cdAmount); } } await selectMenu.execute(interaction); })(); } } catch (err) { const e = err; new index_js_1.ShewenyError(client, e); } } exports.default = run; //# sourceMappingURL=interactionSelectMenuCreate.js.map