UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 5.7 kB
{"version":3,"sources":["../../../../src/lib/structures/CommandStore.ts"],"names":[],"mappings":";;;;;;;;AAiBO,IAAM,aAAA,GAAN,MAAM,aAAA,SAAqB,UAAgC,CAAA;AAAA,EAC1D,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,UAAA,EAAY,CAAA;AAAA;AACpC;AAAA;AAAA;AAAA,EAKA,IAAW,UAAuB,GAAA;AACjC,IAAM,MAAA,UAAA,GAAa,IAAI,GAAI,CAAA,IAAA,CAAK,IAAI,CAAC,OAAA,KAAY,OAAQ,CAAA,QAAQ,CAAC,CAAA;AAClE,IAAA,UAAA,CAAW,OAAO,IAAI,CAAA;AACtB,IAAO,OAAA,CAAC,GAAG,UAAU,CAAA;AAAA;AACtB,EAEgB,OAAO,IAAiE,EAAA;AACvF,IAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,IAAI,CAAA;AAG/B,IAAW,KAAA,MAAA,QAAA,IAAY,KAAM,CAAA,0BAAA,CAA2B,iBAAmB,EAAA;AAC1E,MAAA,MAAM,YAAe,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA;AAC9C,MAAA,IAAI,iBAAiB,KAAO,EAAA;AAC3B,QAAK,IAAA,CAAA,OAAA,CAAQ,OAAO,QAAQ,CAAA;AAAA;AAC7B;AAGD,IAAW,KAAA,MAAA,QAAA,IAAY,KAAM,CAAA,0BAAA,CAA2B,mBAAqB,EAAA;AAC5E,MAAA,MAAM,YAAe,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA;AAC9C,MAAA,IAAI,iBAAiB,KAAO,EAAA;AAC3B,QAAK,IAAA,CAAA,OAAA,CAAQ,OAAO,QAAQ,CAAA;AAAA;AAC7B;AAID,IAAW,UAAA,CAAA,MAAA,CAAO,MAAM,IAAI,CAA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AAA;AACnC;AACD;AAEF,CAAA;AA9EkE,MAAA,CAAA,aAAA,EAAA,cAAA,CAAA;AAA3D,IAAM,YAAN,GAAA","file":"CommandStore.mjs","sourcesContent":["import { AliasStore } from '@sapphire/pieces';\nimport type { Args } from '../parsers/Args';\nimport { RegisterBehavior } from '../types/Enums';\nimport {\n\tallGuildIdsToFetchCommandsFor,\n\tgetDefaultBehaviorWhenNotIdentical,\n\thandleBulkOverwrite,\n\tregistries\n} from '../utils/application-commands/ApplicationCommandRegistries';\nimport { getNeededRegistryParameters } from '../utils/application-commands/getNeededParameters';\nimport { emitPerRegistryError } from '../utils/application-commands/registriesErrors';\nimport { Command } from './Command';\n\n/**\n * Stores all Command pieces\n * @since 1.0.0\n */\nexport class CommandStore extends AliasStore<Command, 'commands'> {\n\tpublic constructor() {\n\t\tsuper(Command, { name: 'commands' });\n\t}\n\n\t/**\n\t * Get all the command categories.\n\t */\n\tpublic get categories(): string[] {\n\t\tconst categories = new Set(this.map((command) => command.category));\n\t\tcategories.delete(null);\n\t\treturn [...categories] as string[];\n\t}\n\n\tpublic override unload(name: string | Command): Promise<Command<Args, Command.Options>> {\n\t\tconst piece = this.resolve(name);\n\n\t\t// Remove the aliases from the store\n\t\tfor (const nameOrId of piece.applicationCommandRegistry.chatInputCommands) {\n\t\t\tconst aliasedPiece = this.aliases.get(nameOrId);\n\t\t\tif (aliasedPiece === piece) {\n\t\t\t\tthis.aliases.delete(nameOrId);\n\t\t\t}\n\t\t}\n\n\t\tfor (const nameOrId of piece.applicationCommandRegistry.contextMenuCommands) {\n\t\t\tconst aliasedPiece = this.aliases.get(nameOrId);\n\t\t\tif (aliasedPiece === piece) {\n\t\t\t\tthis.aliases.delete(nameOrId);\n\t\t\t}\n\t\t}\n\n\t\t// Remove the registry from the application command registries\n\t\tregistries.delete(piece.name);\n\n\t\treturn super.unload(name);\n\t}\n\n\tpublic override async loadAll() {\n\t\tawait super.loadAll();\n\n\t\t// If we don't have an application, that means this was called on login...\n\t\tif (!this.container.client.application) return;\n\n\t\t// super.loadAll() currently deletes all application command registries while unloading old pieces,\n\t\t// re-register application commands to ensure allGuildIdsToFetchCommandsFor has new guild ids for getNeededRegistryParameters\n\t\tfor (const command of this.values()) {\n\t\t\tif (command.registerApplicationCommands) {\n\t\t\t\ttry {\n\t\t\t\t\tawait command.registerApplicationCommands(command.applicationCommandRegistry);\n\t\t\t\t} catch (error) {\n\t\t\t\t\temitPerRegistryError(error, command);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If the default behavior is set to bulk overwrite, handle it as such and return.\n\t\tif (getDefaultBehaviorWhenNotIdentical() === RegisterBehavior.BulkOverwrite) {\n\t\t\tawait handleBulkOverwrite(this, this.container.client.application.commands);\n\t\t\treturn;\n\t\t}\n\n\t\tconst { applicationCommands, globalCommands, guildCommands } = await getNeededRegistryParameters(allGuildIdsToFetchCommandsFor);\n\n\t\tfor (const command of this.values()) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\t\t\tawait command.applicationCommandRegistry['runAPICalls'](applicationCommands, globalCommands, guildCommands);\n\n\t\t\t// Reinitialize the aliases\n\t\t\tfor (const nameOrId of command.applicationCommandRegistry.chatInputCommands) {\n\t\t\t\tthis.aliases.set(nameOrId, command);\n\t\t\t}\n\n\t\t\tfor (const nameOrId of command.applicationCommandRegistry.contextMenuCommands) {\n\t\t\t\tthis.aliases.set(nameOrId, command);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}