Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TextPrompt

A class to handle argument collection and parameter resolution

Hierarchy

Index

Constructors

constructor

Properties

Private #currentUsage

#currentUsage: Tag | null = null

A cache of the current usage while validating

since

0.0.1

Private #prompted

#prompted: number = 0

How many time this class has reprompted

since

0.0.1

Private #repeat

#repeat: boolean = false

Whether the current usage is a repeating arg

since

0.0.1

Private #required

#required: TagRequirement = TagRequirement.Optional

Whether the current usage is required

since

0.0.1

args

args: (undefined | null | string)[] = []

The string arguments derived from the usageDelim of the command

since

0.0.1

channel

channel: TextBasedChannel

The channel to prompt in

since

0.5.0

Readonly client

client: Client

The client this TextPrompt was created with

since

0.5.0

flagSupport

flagSupport: boolean

Whether this prompt should respect flags

since

0.5.0

flags

flags: Record<string, string>

The flag arguments resolved by this class

since

0.5.0

limit

limit: number

The number of re-prompts before this TextPrompt gives up

since

0.5.0

message

message: Message

The message this prompt is for

since

0.5.0

params

params: unknown[] = []

The parameters resolved by this class

since

0.0.1

quotedStringSupport

quotedStringSupport: boolean

Whether this prompt should respect quoted strings

since

0.5.0

reprompted

reprompted: boolean = false

If the command reprompted for missing args

since

0.0.1

target

target: User

The target this prompt is for

since

0.5.0

time

time: number

The time-limit for re-prompting

since

0.5.0

Protected typing

typing: boolean

The typing state of this CommandPrompt

since

0.5.0

usage

The usage for this prompt

since

0.5.0

Static delims

delims: Cache<string, RegExp> = new Cache<string, RegExp>()

Map of RegExps caching usageDelim's RegExps.

since

0.5.0

Static flagRegex

flagRegex: RegExp = new RegExp(`(?:--|—)(\\w[\\w-]+)(?:=(?:${quotes.map(qu => `[${qu}]((?:[^${qu}\\\\]|\\\\.)*)[${qu}]`).join('|')}|([\\w<>@#&!-]+)))?`, 'g')

Regular Expression to match flags with quoted string support.

since

0.5.0

Methods

Private _setup

  • _setup(original: string): void
  • Splits the original message string into arguments.

    since

    0.5.0

    Parameters

    • original: string

      The original message string

    Returns void

Private finalize

  • finalize(): unknown[]

Private handleError

  • handleError(err: string): Promise<unknown[]>
  • Decides if the prompter should reprompt or throw the error found while validating.

    since

    0.5.0

    Parameters

    • err: string

      The error found while validating

    Returns Promise<unknown[]>

Private multiPossibles

  • multiPossibles(index: number): Promise<unknown[]>
  • Validates and resolves args into parameters, when multiple types of usage is defined

    since

    0.0.1

    Parameters

    • index: number

      The id of the possible usage currently being checked

    Returns Promise<unknown[]>

    The resolved parameters

Private prompt

  • prompt(data: MessageOptions): Promise<Message>
  • prompt(data: (message: MessageBuilder) => MessageBuilder | Promise<MessageBuilder>): Promise<Message>
  • Prompts the target for a response

    since

    0.5.0

    Parameters

    • data: MessageOptions

      The message to prompt with

    Returns Promise<Message>

  • Prompts the target for a response

    since

    0.5.0

    Parameters

    • data: (message: MessageBuilder) => MessageBuilder | Promise<MessageBuilder>
        • (message: MessageBuilder): MessageBuilder | Promise<MessageBuilder>
        • Parameters

          • message: MessageBuilder

          Returns MessageBuilder | Promise<MessageBuilder>

    Returns Promise<Message>

Private pushParam

  • pushParam(param: unknown): Promise<unknown[]>
  • Pushes a parameter into this.params, and resets the re-prompt count.

    since

    0.5.0

    Parameters

    • param: unknown

      The resolved parameter

    Returns Promise<unknown[]>

Private repeatingPrompt

  • repeatingPrompt(): Promise<unknown[]>

reprompt

  • reprompt(prompt: string): Promise<unknown[]>
  • Collects missing required arguments.

    since

    0.5.0

    Parameters

    • prompt: string

      The reprompt error

    Returns Promise<unknown[]>

run

  • run(prompt: MessageOptions): Promise<unknown[]>
  • run(prompt: (message: MessageBuilder) => MessageBuilder | Promise<MessageBuilder>): Promise<unknown[]>
  • Runs the custom prompt.

    since

    0.5.0

    Parameters

    • prompt: MessageOptions

      The message to initially prompt with

    Returns Promise<unknown[]>

    The parameters resolved

  • Runs the custom prompt.

    since

    0.5.0

    Parameters

    • prompt: (message: MessageBuilder) => MessageBuilder | Promise<MessageBuilder>
        • (message: MessageBuilder): MessageBuilder | Promise<MessageBuilder>
        • Parameters

          • message: MessageBuilder

          Returns MessageBuilder | Promise<MessageBuilder>

    Returns Promise<unknown[]>

    The parameters resolved

Protected validateArgs

  • validateArgs(): Promise<unknown[]>

Static Private generateNewDelim

  • generateNewDelim(delim: string): RegExp
  • Generate a new delimiter's RegExp and cache it

    since

    0.5.0

    Parameters

    • delim: string

      The delimiter

    Returns RegExp

Static Private getArgs

  • getArgs(content: string, delim: string): string[]
  • Parses a message into string args

    since

    0.0.1

    Parameters

    • content: string

      The remaining content

    • delim: string

      The delimiter

    Returns string[]

Static Private getFlags

  • getFlags(content: string, delim: string): { content: string; flags: Record<string, string> }
  • Parses a message into string args

    since

    0.5.0

    Parameters

    • content: string

      The remaining content

    • delim: string

      The delimiter

    Returns { content: string; flags: Record<string, string> }

    • content: string
    • flags: Record<string, string>

Static Private getQuotedStringArgs

  • getQuotedStringArgs(content: string, delim: string): string[]
  • Parses a message into string args taking into account quoted strings

    since

    0.0.1

    Parameters

    • content: string

      The remaining content

    • delim: string

      The delimiter

    Returns string[]

Generated using TypeDoc