@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
74 lines (71 loc) • 3.04 kB
JavaScript
;
var pieces = require('@sapphire/pieces');
var Enums_cjs = require('../types/Enums.cjs');
var ApplicationCommandRegistries_cjs = require('../utils/application-commands/ApplicationCommandRegistries.cjs');
var getNeededParameters_cjs = require('../utils/application-commands/getNeededParameters.cjs');
var registriesErrors_cjs = require('../utils/application-commands/registriesErrors.cjs');
var Command_cjs = require('./Command.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var _CommandStore = class _CommandStore extends pieces.AliasStore {
constructor() {
super(Command_cjs.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);
}
}
ApplicationCommandRegistries_cjs.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) {
registriesErrors_cjs.emitPerRegistryError(error, command);
}
}
}
if (ApplicationCommandRegistries_cjs.getDefaultBehaviorWhenNotIdentical() === Enums_cjs.RegisterBehavior.BulkOverwrite) {
await ApplicationCommandRegistries_cjs.handleBulkOverwrite(this, this.container.client.application.commands);
return;
}
const { applicationCommands, globalCommands, guildCommands } = await getNeededParameters_cjs.getNeededRegistryParameters(ApplicationCommandRegistries_cjs.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;
exports.CommandStore = CommandStore;
//# sourceMappingURL=CommandStore.cjs.map
//# sourceMappingURL=CommandStore.cjs.map