Skip to content

Commit

Permalink
fix null permission validation
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed Jul 15, 2024
1 parent c916752 commit f178da9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export class ContextMenuCommandBuilder extends Mixin(DiscordJsContextMenuCommand
}

public setDefaultMemberPermissions(permissions?: string|number|bigint|null): this {
return super.setRequiredMemberPermissions(permissions ? BigInt(permissions) : null);
return super.setRequiredMemberPermissions(permissions !== undefined && permissions !== null ? BigInt(permissions) : null);
}

public setRequiredMemberPermissions(permissions: PermissionResolvable|null): this {
const bigint = permissions ? PermissionsBitField.resolve(permissions) : null;
const bigint = permissions !== null ? PermissionsBitField.resolve(permissions) : null;

this.required_member_permissions = bigint ?? undefined;
Reflect.set(this, 'default_member_permissions', String(bigint));
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/classes/builders/SlashCommandBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ export class SlashCommandBuilder extends Mixin(DiscordJsSlashCommandBuilder, Bas
}

public setDefaultMemberPermissions(permissions?: string|number|bigint|null): this {
return super.setRequiredMemberPermissions(permissions ? BigInt(permissions) : null);
return super.setRequiredMemberPermissions(permissions !== undefined && permissions !== null ? BigInt(permissions) : null);
}

public setRequiredMemberPermissions(permissions: PermissionResolvable|null): this {
const bigint = permissions ? PermissionsBitField.resolve(permissions) : null;
const bigint = permissions !== null ? PermissionsBitField.resolve(permissions) : null;

this.required_member_permissions = bigint ?? undefined;
Reflect.set(this, 'default_member_permissions', String(bigint));
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/classes/validators/BaseCommandValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export class BaseCommandValidators extends Validators {
}

public static isValidRequiredBotPermissions(permissions: unknown): asserts permissions is BaseCommandBuilderData['required_bot_permissions'] {
BaseCommandValidators.required_bot_permissions.setValidationEnabled(BaseCommandValidators.isValidationEnabled).parse(permissions);
BaseCommandValidators.required_bot_permissions.nullable().setValidationEnabled(BaseCommandValidators.isValidationEnabled).parse(permissions);
}

public static isValidRequiredMemberPermissions(permissions: unknown): asserts permissions is BaseCommandBuilderData['required_member_permissions'] {
BaseCommandValidators.required_member_permissions.setValidationEnabled(BaseCommandValidators.isValidationEnabled).parse(permissions);
BaseCommandValidators.required_member_permissions.nullable().setValidationEnabled(BaseCommandValidators.isValidationEnabled).parse(permissions);
}

public static isValidPreconditions(preconditions: unknown): asserts preconditions is BaseCommandBuilderData['preconditions'] {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/classes/validators/Validators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BitField, PermissionFlagsBits, PermissionsBitField, isValidationEnabled } from 'discord.js';
import { PermissionFlagsBits, PermissionsBitField, isValidationEnabled } from 'discord.js';
import { Shapes, s } from '@sapphire/shapeshift';

export class Validators {
Expand All @@ -20,7 +20,7 @@ export class Validators {
public static permissionStringPredicate = Validators.s.enum<keyof typeof PermissionFlagsBits>(Object.keys(PermissionFlagsBits) as (keyof typeof PermissionFlagsBits)[]);
public static permissionResolvable = Validators.s.union([
Validators.s.instance(PermissionsBitField),
Validators.s.instance(BitField),
Validators.s.string(),
Validators.permissionStringPredicate.array(),
Validators.permissionStringPredicate,
Validators.s.bigint(),
Expand Down

0 comments on commit f178da9

Please sign in to comment.