You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
960 B

local addonName, addon = ...
--[[ namespace:RegisterSlash(_command_[, _commandN,..._], _callback_)
Registers chat slash `command`(s) with a `callback` function.
Usage:
```lua
namespace:RegisterSlash('/hello', '/hi', function(input)
print('Hi')
end)
```
--]]
function addon:RegisterSlash(...)
local name = addonName .. 'Slash' .. math.random()
local failed
local numArgs = select('#', ...)
local callback = select(numArgs, ...)
if type(callback) ~= 'function' or numArgs < 2 then
failed = true
else
for index = 1, numArgs - 1 do
local slash = select(index, ...)
if type(slash) ~= 'string' then
failed = true
break
elseif not slash:match('^/%a+$') then
failed = true
break
else
_G['SLASH_' .. name .. index] = slash
end
end
end
if failed then
error('Syntax: RegisterSlash("/slash1"[, "/slash2"[, ...]], callback)')
else
SlashCmdList[name] = callback
end
end