Difference between revisions of "Command object"

From StealthBot Wiki Backup
Jump to: navigation, search
 
m (1 revision imported)
 
(No difference)

Latest revision as of 08:20, 1 December 2017

The Command object allows you to handle an issued command. Every time any user issues a command, a new Command object is created containing the information required to respond to the command.

History

This object was added in StealthBot version 2.7 by Eric to create an object-oriented experience in scripting.

How to use

Example: Get the user who executed the command.

Value = CommandObj.Username

Example: Store a response to the command.

CommandObj.Respond "The response"

Properties

List of properties

Username property

Returns the username of the person issuing the command, as a string. This is not affected by naming conventions.

Name property

Returns the name of the command, as a string. This is the name of the command as defined by the XML, not an alias if that was used.

Args property

Returns all of the arguments that are included with command message, as a string. This does not include the trigger, command word, or the first space. This is not parsed in any special way.

Arguments property

Returns all of the arguments that are included with command message, as a collection.

The bot parses a command message according to the CommandDocsObj.Parameters defined in the XML. Each element in the returned collection is a string from the command message. It is of the type of the parameter at that index.

IsLocal property

Returns whether the command is being issued from the bot console, as a boolean.

PublicOutput property

Returns whether the command response will be a public output, as a boolean.

IsValid property

Returns whether the command syntax is correct according to the information provided by the XML, as a boolean.

HasAccess property

Returns whether the user issuing the command has enough access and/or flags to use the command, as a boolean. If this command object is the parameter of your Event_Command event, this will always return True. If it were False, the event is not called.

WasWhispered property

Returns whether the user issued the command via whisper, as a boolean.

Source property

Numerical value of where the command is coming from and going to (this is compatible with the Dsp function):

  • 1 - All Chat
  • 2 - Emote
  • 3 - Whisper
  • 4 - Bot console

Usually, the .Respond function should be called and not the Dsp function. Dsp is provided for backwards compatibility.

Functions

List of functions

Argument function

Returns the value of the specified argument used in the command from the same collection returned by the Arguments property. Pass the name of the parameter as defined in the XML.

Restriction function

Returns a boolean value telling whether an argument failed an XML restriction test. It returns true on success (the argument passed did not violate the rule imposed by the XML restriction) and false on failure. Pass the name of the restriction as defined in the XML.

Respond function

Stores a response to the command. When Event_Command completes execution, the bot will call SendResponse() automatically to send the response to the destination.

GetResponse function

Returns a collection of the responses already stored for this command.

SendResponse function

Call this to send all of the stored responses, if for example the command does something asynchronous and the script writer wishes to send something after Event_Command has exited.

ClearResponse function

Call this to clear the stored responses.

See also