Skip to content

Commit

Permalink
return false when halt is not handled
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed May 30, 2024
1 parent 7e93efd commit 256bc05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/classes/managers/CommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class CommandManager {
return this.addHalts(normalizeArray(data));
}

public async executeHalts<T extends AnyCommandHaltTriggerData = AnyCommandHaltTriggerData>(trigger: T): Promise<CommandHaltResultData<T['commandType']>|null> {
public async executeHalts<T extends AnyCommandHaltTriggerData = AnyCommandHaltTriggerData>(trigger: T): Promise<CommandHaltResultData<T['commandType']>|boolean> {
const halts: CommandHalt<T['commandType']>[] = [];
const disabledHalts = trigger.executeData.builder.disabled_halts;

Expand All @@ -103,15 +103,19 @@ export class CommandManager {

halts.push(...this.halts.values());

let handled = false;

for (const halt of halts) {
if (halt.disabled || disabledHalts.some(p => p === halt.id) || !halt.commandTypes.includes(trigger.commandType)) continue;

const data = await halt.execute(trigger);
if (data === null) continue;
if (!data.successful) return data;

handled = true;
}

return null;
return handled;
}

public get(command: string, type: CommandType.ContextMenuCommand): ContextMenuCommandBuilder|undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/classes/structures/RecipleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class RecipleClient<Ready extends boolean = boolean> extends Client<Ready
return null;
});

if (haltData !== null && !haltData.successful) this._throwError(new RecipleError(RecipleError.createCommandExecuteErrorOptions(data.builder, haltData.message || error)))
if (haltData === false) this._throwError(new RecipleError(RecipleError.createCommandExecuteErrorOptions(data.builder, error)))
}

return false;
Expand Down

0 comments on commit 256bc05

Please sign in to comment.