Wikia

WoWWiki

Dongle/Slash API

Talk0
101,351pages on
this wiki

< Dongle

Dongle allows you to easily register slash commands using a very unique syntax. This allows you to define complex patterns to call methods and anonymous functions quite rapidly.

This API was introduced with Dongle-1.0

DongleObject Slash APIEdit

You can initialize multiple slash commands for the same DongleObject. Each of these returns a DongleSlashObject.

DongleObject:InitializeSlashCommand(desc, name, ...)Edit

Initializes a slash command object and returns it

ArgumentsEdit

  • desc (string) - The root description of the slash command
  • name (string) - A unique constant for your slash command. Historically this has been "ADDONNAME" in caps.
  • ... - A list of actual slash commands you'd like to use for this command. These strings should not begin with "/".

ReturnsEdit

ExampleEdit

The following creates the two slash commands, /praid and /perfectraid with the given description, tied to the constant "PERFECTRAID".

DongleObject:InitializeSlashCommand("PerfectRaid Slash Command", "PERFECTRAID", "praid", "perfectraid")

Dongle SlashCommand Object APIEdit

Each SlashCommand Object has access to the following methods:

SlashCommandObject:RegisterSlashHandler(desc, pattern, handler)Edit

Registers a slash command handler for a given lua string pattern.

ArgumentsEdit

  • desc (string) - The usage description for this pattern
  • pattern (string) - A lua pattern expression to match the arguments to the slash command
  • handler (function, string) - A callback function, or a string representing a method name.

BehaviorEdit

  • If handler is specified as a string, the parser will look in the parent of the slash command for the handler. If the method isn't found, the slash command silently fails.

ExampleEdit

local cmd = DongleObject:InitializeSlashCommand("Hello World", "HELLOWORLD", "hellow")
cmd:RegisterSlashHandler("Say Hello World!", "^$", "HelloWorld")
cmd:RegisterSlashHandler("Say a custom hello message", "custom (%s+)", "HelloWorld")

function DongleObject:HelloWorld(message)
  message = message or "Hello World"
  SendChatMessage(message, "SAY")
end

We can now call /hellow and it will say "Hello World" in game. We could also call /hellow Hello Azeroth! and it will instead say "Hello Azeroth!" in game.

SlashCommandObject:InjectDBCommands(db, ... )Edit

Registers easy to use slash commands to manipulate or set profiles

ArgumentsEdit

  • db (table) - Dongle Database for the profiles you want to be manipulated
  • ... - Slash commands to inject, can be "copy", "delete", "list", "reset" or "set"

BehaviorEdit

  • Injects the passed slash commands for profile management which can be accessed through /slashCmd profile <command>

ExampleEdit

local cmd = DongleObject:InitializeSlashCommand("Hello World", "HELLOWORLD", "hellow")
local db = DongleObject:InitializeDB( "HelloWorldDB", defaults );
cmd:InjectDBCommands( db, "copy", "list", "set" );

Adds /hellow profile copy, /hellow profile list and /hellow profile set to the list of slash command options.

SlashCommandObject:PrintUsage()Edit

Prints the usage statement of the given slash command.

Around Wikia's network

Random Wiki