Skip to content

Commit

Permalink
refactor(preconditions): make IPreconditionContainer#run's context op…
Browse files Browse the repository at this point in the history
…tional (#167)

BREAKING CHANGE: Changed PreconditionContext.command to external
  • Loading branch information
kyranet committed Feb 7, 2021
1 parent 3dbcffd commit 57ad8d2
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/events/command-handler/CorePreCommandRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class CoreEvent extends Event<Events.PreCommandRun> {
return;
}

const result = await command.preconditions.run(message, command, { command });
const result = await command.preconditions.run(message, command);
if (isErr(result)) {
message.client.emit(Events.CommandDenied, result.error, payload);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/structures/Precondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export abstract class Precondition extends Piece {
}

export interface PreconditionContext extends Record<PropertyKey, unknown> {
command: Command;
external?: boolean;
}
2 changes: 1 addition & 1 deletion src/lib/utils/preconditions/IPreconditionContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export interface IPreconditionContainer {
* @param message The message that ran this precondition.
* @param command The command the message invoked.
*/
run(message: Message, command: Command, context: PreconditionContext): PreconditionContainerReturn;
run(message: Message, command: Command, context?: PreconditionContext): PreconditionContainerReturn;
}
2 changes: 1 addition & 1 deletion src/lib/utils/preconditions/PreconditionContainerArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class PreconditionContainerArray implements IPreconditionContainer {
* @param message The message that ran this precondition.
* @param command The command the message invoked.
*/
public run(message: Message, command: Command, context: PreconditionContext): PreconditionContainerReturn {
public run(message: Message, command: Command, context: PreconditionContext = {}): PreconditionContainerReturn {
return this.mode === PreconditionRunMode.Sequential
? this.condition.sequential(message, command, this.entries, context)
: this.condition.parallel(message, command, this.entries, context);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/preconditions/PreconditionContainerSingle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class PreconditionContainerSingle implements IPreconditionContainer {
* @param message The message that ran this precondition.
* @param command The command the message invoked.
*/
public run(message: Message, command: Command, context: PreconditionContext) {
public run(message: Message, command: Command, context: PreconditionContext = {}) {
const precondition = Store.injectedContext.stores.get('preconditions').get(this.name);
if (precondition) return precondition.run(message, command, { ...context, ...this.context });
throw new Error(`The precondition "${this.name}" is not available.`);
Expand Down
2 changes: 1 addition & 1 deletion src/preconditions/Cooldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CorePrecondition extends Precondition {

public run(message: Message, command: Command, context: CooldownContext) {
// If the command it is testing for is not this one, return ok:
if (context.command !== command) return this.ok();
if (context.external) return this.ok();

// If there is no delay (undefined, null, 0), return ok:
if (!context.delay) return this.ok();
Expand Down

0 comments on commit 57ad8d2

Please sign in to comment.