UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

55 lines (53 loc) 2.44 kB
import { RegisterBehavior } from "../types/Enums.mjs"; import { getNeededRegistryParameters } from "../utils/application-commands/getNeededParameters.mjs"; import { emitPerRegistryError } from "../utils/application-commands/registriesErrors.mjs"; import { allGuildIdsToFetchCommandsFor, getDefaultBehaviorWhenNotIdentical, handleBulkOverwrite, registries } from "../utils/application-commands/ApplicationCommandRegistries.mjs"; import { Command } from "./Command.mjs"; import { AliasStore } from "@sapphire/pieces"; //#region src/lib/structures/CommandStore.ts /** * Stores all Command pieces * @since 1.0.0 */ var CommandStore = class extends AliasStore { constructor() { super(Command, { name: "commands" }); } /** * Get all the command categories. */ get categories() { const categories = new Set(this.map((command) => command.category)); categories.delete(null); return [...categories]; } unload(name) { const piece = this.resolve(name); for (const nameOrId of piece.applicationCommandRegistry.chatInputCommands) if (this.aliases.get(nameOrId) === piece) this.aliases.delete(nameOrId); for (const nameOrId of piece.applicationCommandRegistry.contextMenuCommands) if (this.aliases.get(nameOrId) === piece) this.aliases.delete(nameOrId); registries.delete(piece.name); return super.unload(name); } async loadAll() { await super.loadAll(); if (!this.container.client.application) return; for (const command of this.values()) if (command.registerApplicationCommands) try { await command.registerApplicationCommands(command.applicationCommandRegistry); } catch (error) { emitPerRegistryError(error, command); } if (getDefaultBehaviorWhenNotIdentical() === RegisterBehavior.BulkOverwrite) { await handleBulkOverwrite(this, this.container.client.application.commands); return; } const { applicationCommands, globalCommands, guildCommands } = await getNeededRegistryParameters(allGuildIdsToFetchCommandsFor); for (const command of this.values()) { await command.applicationCommandRegistry["runAPICalls"](applicationCommands, globalCommands, guildCommands); for (const nameOrId of command.applicationCommandRegistry.chatInputCommands) this.aliases.set(nameOrId, command); for (const nameOrId of command.applicationCommandRegistry.contextMenuCommands) this.aliases.set(nameOrId, command); } } }; //#endregion export { CommandStore }; //# sourceMappingURL=CommandStore.mjs.map