-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathchatcommand.lua
137 lines (127 loc) · 3.43 KB
/
chatcommand.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
-- some usefull namespace to locals
local addon, ns = ...
local C, L = ns.LC.color, ns.L
local ACD = LibStub("AceConfigDialog-3.0");
--
-- Chat command handler
--
local spacer = "||"
local commands = {
options = {
desc = L["Option panel"],
func = ns.ToggleBlizzOptionPanel
},
broker = "options",
config = "options",
reset = {
desc = L["CmdResetInfo"],
func = ns.resetConfigs
},
list = {
desc = L["CmdStatusInfo"],
func = function()
ns:print(spacer, L["Modules"])
for k, v in ns.pairsByKeys(ns.modules) do
if v and ns.profile[k] then
local c,s = "red",OFF;
if ns.profile[k].enabled==true then
c,s = "green",L["On"];
end
ns:print(spacer, (k==L[k] and "%s | %s" or "%s | %s - ( %s )"):format(C(c,s),C("ltyellow",k),L[k]))
end
end
end,
},
toggle = {
desc = L["CmdToggleInfo"],
func = function(arg)
--cmd = cmd:gsub("^%l", string.upper);
if not ns.modules[arg] then
local lArg = arg:lower();
for k in pairs(ns.modules)do
if k:lower() == lArg then
arg = k;
break;
end
end
end
if ns.modules[arg] then
ns.profile[arg].enabled = not ns.profile[arg].enabled;
if ns.profile[arg].enabled then
ns.moduleInit(arg);
ns:print(spacer,arg,ADDON_ENABLED);
else
ns:print(spacer,arg,ADDON_DISABLED,L["CmdNeedReload"]);
end
end
end
},
equip = {
desc = L["CmdEquipInfo"],
func = function(cmd)
local num = C_EquipmentSet.GetNumEquipmentSets()
if cmd == nil then
ns:print(spacer,L["CmdEquipUsage"]);
ns:print(spacer,L["CmdEquipSets"]);
if num>0 then
for i=0, num-1 do -- very rare in wow... equipment set index starts with 0 instead of 1
local eName, _, _, isEquipped, _, _, _, missingItems = C_EquipmentSet.GetEquipmentSetInfo(i);
ns:print(spacer,C((isEquipped and "yellow") or (missingItems>0 and "red") or "ltblue",eName),missingItems>0 and " - "..C("ltyellow",L["CmdEquipMiss"]:format(missingItems)) or nil);
end
else
ns:print(spacer,L["No sets found"]);
end
else
local validEquipment
for i=1, C_EquipmentSet.GetNumEquipmentSets() do
local eName, _, _, _, _, _, _, _ = C_EquipmentSet.GetEquipmentSetInfo(i)
if cmd==eName then validEquipment = true end
end
if (not validEquipment) then
ns:print(spacer,L["CmdEquipInvalid"])
else
ns.toggleEquipment(cmd)
end
end
end
},
version = {
desc = L["CmdVersion"],
func = function()
ns:print(GAME_VERSION_LABEL,"@project-version@");
end
}
}
function ns.AddChatCommand(key,data)
if not commands[key] then
commands[key] = data;
end
end
function ns.RegisterSlashCommand()
SlashCmdList["BROKER_EVERYTHING"] = function(cmd)
local cmd, arg = strsplit(" ", cmd, 2)
cmd = cmd:lower()
if cmd=="" then
ns:print(spacer, L["CmdUsage"])
for name,obj in ns.pairsByKeys(commands) do
if type(obj)=="string" and commands[obj] and commands[obj].desc then
obj = commands[obj];
end
if obj.desc then
ns:print(spacer, ("%s - %s"):format(C("yellow",name),obj.desc))
end
end
ns:print(C("orange",L["CmdInfoOptional"]));
return;
end
if commands[cmd]~=nil and type(commands[cmd])=="string" then
cmd = commands[cmd];
end
if commands[cmd]~=nil and type(commands[cmd].func)=="function" then
commands[cmd].func(arg);
ns:print(C("orange",L["CmdInfoOptional"]));
end
end
SLASH_BROKER_EVERYTHING1 = "/broker_everything"
SLASH_BROKER_EVERYTHING2 = "/be"
end