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 API[]
You can initialize multiple slash commands for the same DongleObject. Each of these returns a DongleSlashObject.
DongleObject:InitializeSlashCommand(desc, name, ...)[]
Initializes a slash command object and returns it
Arguments[]
- 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 "/".
Returns[]
- slashcmd (table) - The SlashCommand Object encapsulating the new slash command
Example[]
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 API[]
Each SlashCommand Object has access to the following methods:
SlashCommandObject:RegisterSlashHandler(desc, pattern, handler)[]
Registers a slash command handler for a given lua string pattern.
Arguments[]
- 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.
Behavior[]
- 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.
Example[]
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, ... )[]
Registers easy to use slash commands to manipulate or set profiles
Arguments[]
- db (table) - Dongle Database for the profiles you want to be manipulated
- ... - Slash commands to inject, can be "copy", "delete", "list", "reset" or "set"
Behavior[]
- Injects the passed slash commands for profile management which can be accessed through /slashCmd profile <command>
Example[]
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()[]
Prints the usage statement of the given slash command.