Skip to content

Commit

Permalink
resolve option values
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed Jun 14, 2024
1 parent aee326f commit 8933e30
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions } from '@reciple/core';
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionManager } from '@reciple/core';
import { boolean, isBooleanable } from 'boolean';
import { BaseMessageCommandOptionBuilder } from '../structures/BaseMessageCommandOptionBuilder.js';

Expand All @@ -17,4 +17,11 @@ export class MessageCommandBooleanOptionBuilder extends BaseMessageCommandOption
if (!isBooleanable(options.value)) return new Error('Value is not booleanable');
return true;
}

public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: false): Promise<boolean|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: true): Promise<boolean>
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<boolean|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<boolean|null> {
return super.resolveOption(name, options, required);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions } from '@reciple/core';
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionManager } from '@reciple/core';
import { Mentions } from '@reciple/utils';
import { Channel, ChannelType, normalizeArray, RestOrArray } from 'discord.js';
import { BaseMessageCommandOptionBuilder } from '../structures/BaseMessageCommandOptionBuilder.js';
Expand Down Expand Up @@ -51,4 +51,8 @@ export class MessageCommandChannelOptionBuilder extends BaseMessageCommandOption

return true;
}

public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<Channel|null> {
return super.resolveOption(name, options, required);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions } from '@reciple/core';
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionManager } from '@reciple/core';
import { BaseMessageCommandOptionBuilder } from '../structures/BaseMessageCommandOptionBuilder.js';

export interface MessageCommandIntegerOptionBuilderData extends MessageCommandOptionBuilderData<number> {
Expand Down Expand Up @@ -39,4 +39,11 @@ export class MessageCommandIntegerOptionBuilder extends BaseMessageCommandOption

return true;
}

public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: false): Promise<number|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: true): Promise<number>
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<number|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<number|null> {
return super.resolveOption(name, options, required);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions } from '@reciple/core';
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionManager } from '@reciple/core';
import { BaseMessageCommandOptionBuilder } from '../structures/BaseMessageCommandOptionBuilder.js';

export interface MessageCommandNumberOptionBuilderData extends MessageCommandOptionBuilderData<number> {
Expand Down Expand Up @@ -39,4 +39,11 @@ export class MessageCommandNumberOptionBuilder extends BaseMessageCommandOptionB

return true;
}

public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: false): Promise<number|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: true): Promise<number>
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<number|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<number|null> {
return super.resolveOption(name, options, required);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions } from '@reciple/core';
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionManager } from '@reciple/core';
import { Mentions } from '@reciple/utils';
import { Role } from 'discord.js';
import { BaseMessageCommandOptionBuilder } from '../structures/BaseMessageCommandOptionBuilder.js';
Expand Down Expand Up @@ -33,4 +33,8 @@ export class MessageCommandRoleOptionBuilder extends BaseMessageCommandOptionBui
if (!role) return new Error(`Role ${options.value} not found`);
return true;
}

public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<Role|null> {
return super.resolveOption(name, options, required);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions } from '@reciple/core';
import { MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionManager } from '@reciple/core';
import { Mentions } from '@reciple/utils';
import { User } from 'discord.js';
import { BaseMessageCommandOptionBuilder } from '../structures/BaseMessageCommandOptionBuilder.js';
Expand Down Expand Up @@ -34,4 +34,11 @@ export class MessageCommandUserOptionBuilder extends BaseMessageCommandOptionBui
if (!this.allow_bots && user.bot) return new Error(`User ${options.value} is a bot`);
return true;
}

public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: false): Promise<User|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: true): Promise<User>
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<User|null>;
public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<User|null> {
return super.resolveOption(name, options, required);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageCommandOptionBuilder, MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionValidators } from '@reciple/core';
import { MessageCommandOptionBuilder, MessageCommandOptionBuilderData, MessageCommandOptionBuilderResolveValueOptions, MessageCommandOptionManager, MessageCommandOptionValidators } from '@reciple/core';

export abstract class BaseMessageCommandOptionBuilder<T extends any = any> extends (MessageCommandOptionBuilder as (new <T extends any>(options?: MessageCommandOptionBuilderData<T>) => Omit<MessageCommandOptionBuilder<T>, 'setName'|'setDescription'|'setRequired'|'setResolveValue'|'setValidate'>))<T> {
constructor(data?: MessageCommandOptionBuilderData<T>) {
Expand Down Expand Up @@ -37,4 +37,14 @@ export abstract class BaseMessageCommandOptionBuilder<T extends any = any> exten

public abstract readonly resolve_value?: ((options: MessageCommandOptionBuilderResolveValueOptions<T>) => any) | undefined;
public abstract readonly validate?: ((options: MessageCommandOptionBuilderResolveValueOptions<T>) => any) | undefined;

public static async resolveOption(name: string, options: MessageCommandOptionManager, required?: boolean): Promise<any|null> {
switch (required) {
case true:
return options.getOptionValue(name, { resolveValue: true, required: true });
case false:
case undefined:
return options.getOptionValue(name, { resolveValue: true, required: false });
}
}
}

0 comments on commit 8933e30

Please sign in to comment.