Home Manual Reference Source Repository
import BotUtil from 'discord-graf/src/bot/util.js'
public class | source

BotUtil

Contains general utility methods

Static Member Summary

Static Public Members
public static get

Static Method Summary

Static Public Methods
public static

disambiguation(items: Object[], label: string, property: string): string

Build a disambiguation list - useful for telling a user to be more specific when finding partial matches from a command

public static

Escapes Markdown in the string

public static

nbsp(text: string): string

Convert spaces to non-breaking spaces

public static

paginate(items: Object[], page: number, pageLength: number): Object

Paginate an array of items

public static

search(items: Object[], searchString: string, options: SearchOptions): Object[]

Search for matches in a list of items

public static

split(text: string, maxLength: number, splitOn: string, prepend: string, append: string): string[]

Splits a string using specified characters into multiple strings of a maximum length

public static

usage(client: Client, settings: SettingStorage, config: BotConfig, command: string, guild: Guild | string, onlyMention: boolean): string

Build a command usage string

Constructor Summary

Public Constructor
public

constructor(client: Client, settings: SettingStorage, config: BotConfig)

Member Summary

Public Members
public
public
public
public

Method Summary

Public Methods
public

disambiguation(items: Object[], label: string, property: string): string

Build a disambiguation list - useful for telling a user to be more specific when finding partial matches from a command

public

Escapes Markdown in the string

public

nbsp(text: string): string

Convert spaces to non-breaking spaces

public

paginate(items: Object[], page: number, pageLength: number): Object

Paginate an array of items

public

search(items: Object[], searchString: string, options: SearchOptions): Object[]

Search for matches in a list of items

public

split(text: string, maxLength: number, splitOn: string, prepend: string, append: string): string[]

Splits a string using specified characters into multiple strings of a maximum length

public

usage(command: string, guild: Guild | string, onlyMention: boolean): string

Build a command usage string

Static Public Members

public static get patterns: PatternConstants source

See:

Static Public Methods

public static disambiguation(items: Object[], label: string, property: string): string source

Build a disambiguation list - useful for telling a user to be more specific when finding partial matches from a command

Params:

NameTypeAttributeDescription
items Object[]

An array of items to make the disambiguation list for

label string

The text to refer to the items as (ex. "characters")

property string
  • optional
  • default: name

The property on items to display in the list

Return:

string

The disambiguation list

See:

public static escapeMarkdown(text: string): string source

Escapes Markdown in the string

Params:

NameTypeAttributeDescription
text string

The text to escape

Return:

string

The escaped text

See:

public static nbsp(text: string): string source

Convert spaces to non-breaking spaces

Params:

NameTypeAttributeDescription
text string

The text to convert

Return:

string

The converted text

See:

public static paginate(items: Object[], page: number, pageLength: number): Object source

Paginate an array of items

Params:

NameTypeAttributeDescription
items Object[]

An array of items to paginate

page number
  • optional
  • default: 1

The page to select

pageLength number
  • optional
  • default: 10

The number of items per page

Return:

Object

The resulting paginated object

Return Properties:

NameTypeAttributeDescription
items Object[]

The chunk of items for the current page

page number

The current page

maxPage number

The maximum page

pageLength number

The numer of items per page

pageText string

The current page string ("page x of y")

See:

Search for matches in a list of items

Params:

NameTypeAttributeDescription
items Object[]

An array of items to search in

searchString string

The string to search for

options SearchOptions

An options object

Return:

Object[]

The matched items

See:

public static split(text: string, maxLength: number, splitOn: string, prepend: string, append: string): string[] source

Splits a string using specified characters into multiple strings of a maximum length

Params:

NameTypeAttributeDescription
text string

The string to split

maxLength number
  • optional
  • default: 1925

The maximum length of each split string

splitOn string
  • optional
  • default: \n

The characters to split the string with

prepend string
  • optional

String to prepend to every split message

append string
  • optional

String to append to every split message

Return:

string[]

The split strings

See:

public static usage(client: Client, settings: SettingStorage, config: BotConfig, command: string, guild: Guild | string, onlyMention: boolean): string source

Build a command usage string

Params:

NameTypeAttributeDescription
client Client

The client to use

settings SettingStorage

The setting storage to use

config BotConfig

The bot config to use

command string

The short command string (ex. "roll d20")

guild Guild | string
  • optional

The guild or guild ID to use the prefix of

onlyMention boolean
  • optional
  • default: false

Whether or not the usage string should only show the mention form

Return:

string

The command usage string

See:

Public Constructors

public constructor(client: Client, settings: SettingStorage, config: BotConfig) source

Params:

NameTypeAttributeDescription
client Client

The client to use

settings SettingStorage

The setting storage to use

config BotConfig

The bot config to use

Public Members

public client: Client source

public config: BotConfig source

public settings: SettingStorage source

Public Methods

public disambiguation(items: Object[], label: string, property: string): string source

Build a disambiguation list - useful for telling a user to be more specific when finding partial matches from a command

Params:

NameTypeAttributeDescription
items Object[]

An array of items to make the disambiguation list for

label string

The text to refer to the items as (ex. "characters")

property string
  • optional
  • default: name

The property on items to display in the list

Return:

string

The disambiguation list

See:

public escapeMarkdown(text: string): string source

Escapes Markdown in the string

Params:

NameTypeAttributeDescription
text string

The text to escape

Return:

string

The escaped text

See:

public nbsp(text: string): string source

Convert spaces to non-breaking spaces

Params:

NameTypeAttributeDescription
text string

The text to convert

Return:

string

The converted text

See:

public paginate(items: Object[], page: number, pageLength: number): Object source

Paginate an array of items

Params:

NameTypeAttributeDescription
items Object[]

An array of items to paginate

page number
  • optional
  • default: 1

The page to select

pageLength number
  • optional
  • default: 10

The number of items per page

Return:

Object

The resulting paginated object

Return Properties:

NameTypeAttributeDescription
items Object[]

The chunk of items for the current page

page number

The current page

maxPage number

The maximum page

pageLength number

The numer of items per page

pageText string

The current page string ("page x of y")

See:

Search for matches in a list of items

Params:

NameTypeAttributeDescription
items Object[]

An array of items to search in

searchString string

The string to search for

options SearchOptions

An options object

Return:

Object[]

The matched items

See:

public split(text: string, maxLength: number, splitOn: string, prepend: string, append: string): string[] source

Splits a string using specified characters into multiple strings of a maximum length

Params:

NameTypeAttributeDescription
text string

The string to split

maxLength number
  • optional
  • default: 1925

The maximum length of each split string

splitOn string
  • optional
  • default: \n

The characters to split the string with

prepend string
  • optional

String to prepend to every split message

append string
  • optional

String to append to every split message

Return:

string[]

The split strings

See:

public usage(command: string, guild: Guild | string, onlyMention: boolean): string source

Build a command usage string

Params:

NameTypeAttributeDescription
command string

The short command string (ex. "roll d20")

guild Guild | string
  • optional

The guild or guild ID to use the prefix of

onlyMention boolean
  • optional
  • default: false

Whether or not the usage string should only show the mention form

Return:

string

The command usage string

See: