Skip to content

Commit

Permalink
feat: add CommandDeployer#setCommands()
Browse files Browse the repository at this point in the history
  • Loading branch information
Amgelo563 committed Aug 23, 2024
1 parent e487b88 commit 7086561
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/features/command/deploy/CommandDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ import type { TopLevelCommand } from '../commands/TopLevelCommand';

export interface CommandDeployer extends IterableIterator<ApplicationCommand> {
/**
* Deploys the commands.
* Deploys pending commands, or all of them it the deployer hasn't started.
*
* @throws {IllegalStateError} If the deployer has already started.
* @throws {Error} If there was an error while deploying the commands.
*/
deploy(): Awaitable<ReadonlyCollection<string, ApplicationCommand>>;

/**
* Sets this deployer's commands, or the pending ones if it hasn't started.
*
* @throws {Error} If there was an error while deploying the commands.
*/
setCommands(...commands: TopLevelCommand[]): Awaitable<this>;

/**
* Registers commands on Discord if the deployer has started, otherwise
* saves them for later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ import type { CommandDeployer } from './CommandDeployer';

export type ReadonlyCommandDeployer = Omit<
CommandDeployer,
'addCommands' | 'removeCommands' | 'start' | 'editCommands'
'addCommands' | 'removeCommands' | 'start' | 'editCommands' | 'setCommands'
>;
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ export class DefaultCommandDeployer implements CommandDeployer {
return this.mappings;
}

public async setCommands(...commands: TopLevelCommand[]): Promise<this> {
if (this.pendingAdd === null) {
this.mappings.clear();
await this.deployOnly(...commands);

return this;
}

this.pendingAdd = commands;
return this;
}

public async deployCommands(...commands: TopLevelCommand[]): Promise<this> {
if (this.pendingAdd === null) {
await this.deployOnly(...commands);
Expand Down

0 comments on commit 7086561

Please sign in to comment.