Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
fix: use zod instead of ow for max/min option validation (#66)
Browse files Browse the repository at this point in the history
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
  • Loading branch information
suneettipirneni and vladfrangu committed Dec 22, 2021
1 parent 2e1e860 commit beb35fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/interactions/slashCommands/options/integer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ApplicationCommandOptionType } from 'discord-api-types/v9';
import { ApplicationCommandNumberOptionBase } from '../mixins/CommandNumberOptionBase';
import ow from 'ow';
import { z } from 'zod';

const numberPredicate = ow.number.integer;
const numberValidator = z.number().int().nonnegative();

export class SlashCommandIntegerOption extends ApplicationCommandNumberOptionBase {
public override readonly type = ApplicationCommandOptionType.Integer as const;
Expand All @@ -12,13 +12,13 @@ export class SlashCommandIntegerOption extends ApplicationCommandNumberOptionBas
}

public setMaxValue(max: number): this {
ow(max, numberPredicate);
numberValidator.parse(max);
this.maxValue = max;
return this;
}

public setMinValue(min: number): this {
ow(min, numberPredicate);
numberValidator.parse(min);
this.minValue = min;
return this;
}
Expand Down
9 changes: 4 additions & 5 deletions src/interactions/slashCommands/options/number.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ApplicationCommandOptionType } from 'discord-api-types/v9';
import { ApplicationCommandNumberOptionBase } from '../mixins/CommandNumberOptionBase';
import { z } from 'zod';

import ow from 'ow';

const numberPredicate = ow.number;
const numberValidator = z.number().nonnegative();

export class SlashCommandNumberOption extends ApplicationCommandNumberOptionBase {
public override readonly type = ApplicationCommandOptionType.Number as const;
Expand All @@ -13,13 +12,13 @@ export class SlashCommandNumberOption extends ApplicationCommandNumberOptionBase
}

public setMaxValue(max: number): this {
ow(max, numberPredicate);
numberValidator.parse(max);
this.maxValue = max;
return this;
}

public setMinValue(min: number): this {
ow(min, numberPredicate);
numberValidator.parse(min);
this.minValue = min;
return this;
}
Expand Down

0 comments on commit beb35fb

Please sign in to comment.