UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

70 lines (68 loc) 3.01 kB
"use strict"; const require_lib_types_Events = require('../types/Events.cjs'); const require_lib_structures_InteractionHandler = require('./InteractionHandler.cjs'); let __sapphire_pieces = require("@sapphire/pieces"); let __sapphire_result = require("@sapphire/result"); //#region src/lib/structures/InteractionHandlerStore.ts var InteractionHandlerStore = class extends __sapphire_pieces.Store { constructor() { super(require_lib_structures_InteractionHandler.InteractionHandler, { name: "interaction-handlers" }); } async run(interaction) { if (this.size === 0) return false; const promises = []; for (const handler of this.values()) { if (!InteractionHandlerFilters.get(handler.interactionHandlerType)?.(interaction)) continue; (await __sapphire_result.Result.fromAsync(() => handler.parse(interaction))).match({ ok: (option) => { this.container.client.emit(require_lib_types_Events.Events.InteractionHandlerParseSuccess, option, { interaction, handler }); option.match({ some: (value) => { this.container.client.emit(require_lib_types_Events.Events.InteractionHandlerParseSome, option, { interaction, handler, value }); const promise = __sapphire_result.Result.fromAsync(() => handler.run(interaction, value)).then((res) => res.mapErr((error) => ({ handler, error }))); promises.push(promise); }, none: () => this.container.client.emit(require_lib_types_Events.Events.InteractionHandlerParseNone, option, { interaction, handler }) }); }, err: (error) => { this.container.client.emit(require_lib_types_Events.Events.InteractionHandlerParseError, error, { interaction, handler }); } }); } if (promises.length === 0) return false; const results = await Promise.allSettled(promises); for (const result of results) result.value.inspectErr((value) => this.container.client.emit(require_lib_types_Events.Events.InteractionHandlerError, value.error, { interaction, handler: value.handler })); return true; } }; const InteractionHandlerFilters = new Map([ [require_lib_structures_InteractionHandler.InteractionHandlerTypes.Button, (interaction) => interaction.isButton()], [require_lib_structures_InteractionHandler.InteractionHandlerTypes.SelectMenu, (interaction) => interaction.isAnySelectMenu()], [require_lib_structures_InteractionHandler.InteractionHandlerTypes.ModalSubmit, (interaction) => interaction.isModalSubmit()], [require_lib_structures_InteractionHandler.InteractionHandlerTypes.MessageComponent, (interaction) => interaction.isMessageComponent()], [require_lib_structures_InteractionHandler.InteractionHandlerTypes.Autocomplete, (Interaction) => Interaction.isAutocomplete()] ]); //#endregion exports.InteractionHandlerFilters = InteractionHandlerFilters; exports.InteractionHandlerStore = InteractionHandlerStore; //# sourceMappingURL=InteractionHandlerStore.cjs.map