-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.lua
More file actions
113 lines (92 loc) · 2.82 KB
/
Copy pathMain.lua
File metadata and controls
113 lines (92 loc) · 2.82 KB
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
-- Main.lua
local _, ns = ...
-- WoW API
local SlashCmdList = SlashCmdList
local CreateFrame = CreateFrame
local UnitClass = UnitClass
local debugprofilestop = debugprofilestop
local Ruilhenn = CreateFrame("Frame", "RuilhennFrame")
RuilhennDB = RuilhennDB or {}
Ruilhenn.command = {
["debug"] = function(subcommand)
if subcommand == "status" then
if ns.Config.debugMode then
ns.Log:Message(ns.L["DEBUG_ACTIVATED"])
else
ns.Log:Message(ns.L["DEBUG_DEACTIVATED"])
end
return
end
ns.Config.debugMode = not ns.Config.debugMode
ns.Config:SaveSetting("debugMode", ns.Config.debugMode)
if ns.Config.debugMode then
ns.Log:Message(ns.L["DEBUG_ACTIVATED"])
else
ns.Log:Message(ns.L["DEBUG_DEACTIVATED"])
end
end,
["help"] = function()
Ruilhenn:CommandUsage()
end
}
function Ruilhenn:Command(msg)
local lmsg = msg:lower()
local cmd, args = ns.Utils:UnpackFirst(ns.Utils:SplitWhitespace(lmsg))
local func = self.command[cmd]
if type(func) ~= "function" then
self:CommandUsage()
return
end
local success, err = pcall(func, unpack(args))
if not success then
ns.Log:Debug("Command execution error: " .. err)
end
end
function Ruilhenn:PrintGreetings()
local version = '0.1.0'
ns.Log:Message(ns.L["LOADED"]:format(version))
ns.Log:Message(ns.L["STARTED"])
end
function Ruilhenn:CommandUsage()
ns.Log:Message("Usage: /ruil <command>")
ns.Log:Message("Available commands:")
local cmds = {}
for cmd in pairs(self.command) do
table.insert(cmds, cmd)
end
table.sort(cmds)
for _, cmd in ipairs(cmds) do
local helpKey = "COMMAND_" .. cmd:upper() .. "_HELP"
local helpMsg = ns.L[helpKey]
if helpMsg then
ns.Log:Message(" - " .. cmd .. " - " .. helpMsg)
else
ns.Log:Message(" - " .. cmd)
end
end
end
function Ruilhenn:OnEvent(event, ...)
self[event](self, event, ...)
end
function Ruilhenn:RegisterCommands()
ns.Log:Debug("RegisterCommands => " .. ns.Utils:DumpTable(ns.Commands))
for cmd, func in pairs(ns.Commands) do
self.command[cmd] = func
ns.Log:Debug("Registered command: " .. cmd)
end
end
function Ruilhenn:ADDON_LOADED(event, addon)
if addon ~= "Ruilhenn" then return end
ns.Config:LoadSavedVariables()
self:PrintGreetings()
self:RegisterCommands()
local endTime = debugprofilestop()
ns.Log:Debug(ns.L["LOADED_TIMER"]:format(endTime - ns.startTime))
end
Ruilhenn:RegisterEvent("ADDON_LOADED")
Ruilhenn:SetScript("OnEvent", Ruilhenn.OnEvent)
SLASH_RUILHENN1 = "/ruil"
SLASH_RUILHENN2 = "/ruilhenn"
SlashCmdList["RUILHENN"] = function(msg)
Ruilhenn:Command(msg)
end