@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
71 lines (69 loc) • 2.82 kB
JavaScript
import { __name } from '../../chunk-PAWJFY3S.mjs';
import { AliasStore } from '@sapphire/pieces';
import { RegisterBehavior } from '../types/Enums.mjs';
import { registries, getDefaultBehaviorWhenNotIdentical, handleBulkOverwrite, allGuildIdsToFetchCommandsFor } from '../utils/application-commands/ApplicationCommandRegistries.mjs';
import { getNeededRegistryParameters } from '../utils/application-commands/getNeededParameters.mjs';
import { emitPerRegistryError } from '../utils/application-commands/registriesErrors.mjs';
import { Command } from './Command.mjs';
var _CommandStore = class _CommandStore 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) {
const aliasedPiece = this.aliases.get(nameOrId);
if (aliasedPiece === piece) {
this.aliases.delete(nameOrId);
}
}
for (const nameOrId of piece.applicationCommandRegistry.contextMenuCommands) {
const aliasedPiece = this.aliases.get(nameOrId);
if (aliasedPiece === 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);
}
}
}
};
__name(_CommandStore, "CommandStore");
var CommandStore = _CommandStore;
export { CommandStore };
//# sourceMappingURL=CommandStore.mjs.map
//# sourceMappingURL=CommandStore.mjs.map