command.js

1.0.0

Changelog

1.3.3 - ?

  • show alias inside man command
  • teamspeak now sends less seperat chat commands when using the help command

1.3.1 - 03.08.2019

  • added new possibility to create arguments
  createCommand("foo")
    .addArgument(args => args.number.setName("bar").positive())

1.3.0 - 11.06.2019

  • added better support for message events from discord

1.2.3 - 14.04.2019

  • fixed GroupArguments

1.2.2 - 10.02.2019

  • reworked responses especially for discord
  • ClientArgument should now work with discord

1.2.1 - 09.02.2019

  • improved error handling messages
  • improved man command (the command !man !help will now resolve to the help command aswell)

1.2.0 - 05.02.2019

  • implemented command throttling
  • added method #getVersion() to retrieve the current semantic version string

1.1.3 - 04.02.2018

  • changed help output for discord

1.1.2 - 30.01.2018

  • changed error handling for PermissionError

1.1.1 - 17.01.2019

  • changed error handling for failing permission checks
  • fixed client object not passed to the checkPermission Parent of a CommandGroup

1.1.0 - 17.01.2019

  • added createCommandGroup to create a CommandGroup with multiple SubCommands for simpler handling of complex commands
  • refactored command handling
  • set default config value for NOT_FOUND_MESSAGE to "1"
  • moved getCommandByName to CommandCollector
  • moved getAvailableCommands to CommandCollector
  • moved multiple log messages to VERBOSE logging
  • fixed documentation
  • removed alias from commands for the sake of simplicity
  • removed method ignoreOptionalArgs to enforce a more strict parsing

1.0.1 - 14.01.2019

  • fixed a bug when the prefix has been removed from the instance settings

1.0.0 - 10.12.2018

  • initial release

Examples

Examples
Static Members
How to load the library
Command come
Command ping [amount]
Command mass [chat|poke] [message]
Command greet [client]
Async example
parse args by yourself
CommandGroup example

Classes

Definition for Classes

Command

Class representing a Command

Command
Parameters
cmd (string) The Command which should be used
Instance Members
_cmd
_alias
_enabled
_help
_prefix
_throttle
_args
_manual
_fncs
hasCommand(name)
getCommandName()
getFullCommandName()
alias(alias)
getAlias()
forcePrefix(prefix)
getPrefix()
help(text)
hasHelp()
getHelp()
throttle(throttle)
disable()
enable()
isEnabled()
exec(fnc)
dispatchCommand(args, ev)
manual(text)
hasManual()
getManual()
getUsage()
checkPermission(fnc)
isAllowed(client)
run(args, ev)
validate(args)
validateArgs(args)
addArgument(arg)
getArguments()

CommandGroup

Class representing a CommandGroup

CommandGroup

Extends Command

Parameters
cmd (string) The Command which should be used
Instance Members
addArgument()
addCommand(name)
findSubCommandByName(name)
getAvailableSubCommands(client?, cmd?)
isAllowed(client)
run(args, ev)

SubCommand

Class representing a SubCommand which will be used within CommandGroups

SubCommand

Extends Command

Parameters
cmd (string) The Command Name which should be used
Instance Members
getPrefix()
setPrefix()
getUsage()

CommandCollector

A collection of registered commands in this library

CommandCollector
Static Members
validateCommandName(name)
Instance Members
isSaveCommand(cmd)
getAvailableCommandsWithPrefix(cmd)
isPossibleCommand(cmd)
registerCommand(cmd)
getAvailableCommands(client?, cmd?)
getCommandByName(name)

Throttle

Class representing a Command

Throttle
Instance Members
tickRate(duration)
penaltyPerCommand(amount)
restorePerTick(amount)
initialPoints(initial)
throttle(client)
isThrottled(client)
timeTillNextCommand(client)

Argument Types

Available Argument Types which can be added to a Command

Argument

Class representing an Argument

Argument
Static Members
createArgumentLayer()
Instance Members
optional(fallback?, displayDefault)
getDefault()
hasDefault()
getManual()
isOptional()
setName(name, display?)
getName()

NumberArgument

Class representing a NumberArgument this will try to parse a number

NumberArgument

Extends Argument

Instance Members
min(min)
max(max)
integer()
positive()
negative()

StringArgument

Class representing a StringArgument

StringArgument

Extends Argument

Instance Members
match(regex)
max(len)
min(len)
forceUpperCase()
forceLowerCase()
whitelist(words)

ClientArgument

Class representing a ClientArgument this Argument is capable to parse a Client UID or a simple UID inside the exec function it will resolve the found uid

ClientArgument

Extends Argument

RestArgument

Class representing a RestArgument this will parse everything remaining you can use all methods from the StringArgument here

RestArgument

Extends StringArgument

GroupArgument

Class representing a GroupArgument

GroupArgument

Extends Argument

Parameters
type (string) the type of the Argument, should be "and" or "or"
Instance Members
argument(args)

execFunction

execFunction(fnc: MessageEvent)

Type: Function

Since: 1.2.3
Parameters
fnc (MessageEvent)

MessageEvent

MessageEvent

Type: object

Properties
text (string) : Text of the message
channel (Channel) : Channel (if given) this message has been sent on
client (Client) : Client that sent the message
mode (number) : Number representing the way this message has been sent (1 = private, 2 = channel, 3 = server)
message (DiscordMessage?) : When backend is discord this will be the callback parameter of the message event, otherwise undefined. Available since v1.3.0

Exports

These Functions gets exported as object when imported through require("command.js")

createCommand

Creates a new Command Instance with the given Command Name

createCommand
Parameters
cmd (string) the command which should be added
Returns
Command: returns the created Command

createCommandGroup

Creates a new CommandsCommand Instance with the given Command Name

createCommandGroup
Parameters
cmd (string) the command which should be added
Returns
CommandGroup: returns the created CommandGroup instance

createArgument

Creates a new Argument Instance

createArgument
Parameters
type (string) the argument type which should be created
Returns
Argument: returns the created Argument

createGroupedArgument

Creates a new Argument Instance

createGroupedArgument
Parameters
type (string) the argument type which should be created either "or" or "and" allowed
Returns
GroupArgument: returns the created Group Argument

getCommandPrefix

retrieves the current Command Prefix

getCommandPrefix
Returns
string: returns the command prefix

collector

collector

Type: CommandCollector

getVersion

retrieves the semantic version of this script

getVersion
Returns
string: returns the semantic version of this script

createThrottle

Creates a new Throttle Instance

createThrottle
Returns
Throttle: returns the created Throttle