-
Notifications
You must be signed in to change notification settings - Fork 0
/
esoTERM_slash.lua
98 lines (82 loc) · 2.98 KB
/
esoTERM_slash.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
esoTERM_slash = {}
esoTERM_slash.command_handlers = {}
local function get_about()
return "About\n" ..
"Name: " .. esoTERM.ADDON_NAME .. "\n" ..
"Author: " .. esoTERM.ADDON_AUTHOR .. " @ EU"
end
local function handle_empty_command()
return get_about()
end
local function get_help()
return "Available command for esoTERM:\n" ..
" - show about: /esoterm\n" ..
" - show help: /esoterm help\n" ..
" - show status: /esoterm status"
end
local function handle_help_command()
return get_help()
end
local function get_module_status(module)
return string.format("\n%s is %s",
module.module_name,
module.is_active and "ACTIVE" or "INACTIVE")
end
local function get_module_statuses(module_register)
local array = {}
for i, module in ipairs(module_register) do
table.insert(array, get_module_status(module))
end
return table.concat(array, "")
end
local function handle_status_command()
local register = esoTERM.module_register
if #register == 0 then
status = "\nNo registered modules"
elseif #register == 1 then
status = get_module_status(register[1])
else
status = get_module_statuses(register)
end
return "Status of modules" .. status
end
local function handle_deactivate_command(module_name)
local module = esoTERM_common.get_module(esoTERM.module_register, module_name)
if module.is_active == false then
return "Module " .. module.module_name .. " already inactive"
else
module.deactivate()
return "Module " .. module.module_name .. " deactivated"
end
end
local function handle_activate_command(module_name)
local module = esoTERM_common.get_module(esoTERM.module_register, module_name)
if module.is_active == true then
return "Module " .. module.module_name .. " already active"
else
module.activate()
return "Module " .. module.module_name .. " activated"
end
end
function esoTERM_slash.slash_command_handler(command_and_arg)
local output
local command_handlers = esoTERM_slash.command_handlers
local command = string.lower(esoTERM_common.split(command_and_arg)[1] or "")
local arg = string.lower(esoTERM_common.split(command_and_arg)[2] or "")
if command_handlers[command] == nil then
output = "Invalid slash-command: " .. command_and_arg
else
output = command_handlers[command](arg)
end
esoTERM_output.sysout(output)
end
function esoTERM_slash.initialize()
SLASH_COMMANDS["/" .. string.lower(esoTERM.ADDON_NAME)] = esoTERM_slash.slash_command_handler
local command_handlers = esoTERM_slash.command_handlers
command_handlers[""] = handle_empty_command
command_handlers["help"] = handle_help_command
command_handlers["status"] = handle_status_command
command_handlers["deactivate"] = handle_deactivate_command
command_handlers["activate"] = handle_activate_command
end
return esoTERM_slash