Aliases
An alias rewrites what you type before it goes to the server. Two decisions define one: how it matches (a leading command phrase matched literally, or a regex over the whole line) and what it does (a string to send, or a Lua function to run).
The simplest form is a word that expands, with anything you typed after it carried along:
rune.alias.exact("gc", "get all from corpse")Type gc and the server receives get all from corpse. Type gc bag and
it receives get all from corpse bag. Arguments are appended.
When the alias needs logic, such as a target variable or a condition, the action is a function instead:
rune.alias.exact("heal", function(args) rune.send("cast 'heal' " .. (args ~= "" and args or "self"))end)Both forms register the same way and are managed the same way.
Literal aliases can contain more than one word. The phrase matches the leading words of the input, and anything after it remains available as arguments:
rune.alias.exact("chat off", "chatlog off")-- "chat off now" -> chatlog off nowCreating
Section titled “Creating”rune.alias.exact(phrase, action, opts?) -- matches leading words literallyrune.alias.regex(pattern, action, opts?) -- Go regexp against the whole lineExact aliases match literal words at the start of what you type. If phrases
overlap, the longest active phrase wins. Whitespace separates phrase words,
so chat off also matches chat off. Regex aliases see the entire input
line and can capture pieces of it. They run in priority order before exact
aliases are tried.
Regex patterns are validated at registration: a bad pattern raises immediately instead of failing silently at match time.
Actions
Section titled “Actions”A string is a plain expansion.
- For
exactaliases, whatever you typed after the matched phrase is appended:rune.alias.exact("k", "kill")turnsk ratintokill rat. - For
regexaliases,%1,%2, and so on are substituted from the pattern’s captures. This is how you reorder or reuse arguments:
rune.alias.regex("^gr (.+)$", "get %1;wear %1")-- "gr helmet" -> get helmet;wear helmetA function runs instead of sending anything. Send what you want with
rune.send. Return a string to feed it back through expansion (so aliases
can build on other aliases), or return nothing to consume the input
entirely.
The function’s first argument depends on the match type:
-- exact: (args, ctx). args is the text after the matched phrase.rune.alias.exact("heal", function(args, ctx) if args == "" then rune.echo(rune.style.yellow("heal who?")) else rune.send("cast 'heal' " .. args) endend)
-- regex: (matches, ctx). matches is the array of captures.rune.alias.regex("^kk (\\w+)$", function(matches, ctx) rune.send("kill " .. matches[1])end)ctx carries line (the full input), plus name, group, and type.
Start with a string. Switch to a function when you need state or a condition.
Options
Section titled “Options”Aliases take the common options: group,
priority (order among regex aliases), and once. No alias-specific
extras.
The two constructors are named differently.
An exact alias is named for its phrase, so rune.alias.disable("gc")
works without you naming anything, and a name in opts is ignored with
a notice. A regex alias is a matcher rather than a phrase, and several can
match one line, so it takes name like a trigger does.
rune.alias.exact and rune.trigger.exact
do not mean the same thing here. An alias phrase is something you type, so
it names the alias. A trigger’s exact line is something you match, and
several triggers can match it, so a trigger still needs a name.
Examples
Section titled “Examples”Name a command sequence, then repeat the alias:
rune.alias.exact("round", "kill rat;loot")rune.alias.exact("farm", "#6 round") -- six kill/loot roundsCaptures beyond the first:
-- "g 20 bob" -> "give 20 gold bob"rune.alias.regex("^g (\\d+) (\\w+)$", "give %1 gold %2")State shared between two aliases:
local last_targetrune.alias.regex("^kk (\\w+)$", function(matches) last_target = matches[1] rune.send("kill " .. last_target)end)rune.alias.exact("again", function() if last_target then rune.send("kill " .. last_target) endend)Grouped, so a pack can be switched off mid-fight:
rune.alias.exact("n", "sneak north", { group = "sneaky" })rune.alias.exact("s", "sneak south", { group = "sneaky" })-- /group sneaky off -> n and s pass through unchangedManaging
Section titled “Managing”Every constructor returns a handle:
local h = rune.alias.exact("k", "kill")h:disable() h:enable() h:remove()By name: rune.alias.disable/enable/remove(name). The full list is in
the API reference. In the client,
/aliases shows every alias with its state, group, and the file:line
that registered it.
Gotchas
Section titled “Gotchas”%Ncapture substitution only works in regex aliases. An exact alias’s string action gets the arguments appended at the end; to place them in the middle, useregexor a function.- Patterns are Go regexp (RE2), not Lua patterns:
\\dand\\wwork, backreferences do not. Test a pattern with/lua rune.echo(tostring(rune.regex.match("^k (.+)$", "k rat")[1])). - An alias that errors three times in a row is quarantined.
- Alias expansion recurses (an alias can produce another alias’s input) with a depth limit of 100 to catch loops.
Related: rune.alias reference, Triggers, Groups