-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCore.lua
More file actions
147 lines (124 loc) · 4.05 KB
/
Copy pathCore.lua
File metadata and controls
147 lines (124 loc) · 4.05 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-------------------------------------
-- Slacker's Tweak Suite: Core.lua --
-------------------------------------
local appName, app = ...
app.locales = {}
app.api = {}
SlackersTweakSuite = app.api
local api = app.api
local L = app.locales
---------------------------
-- WOW API EVENT HANDLER --
---------------------------
app.Event = CreateFrame("Frame")
app.Event.handlers = {}
function app.Event:Register(eventName, func)
if not self.handlers[eventName] then
self.handlers[eventName] = {}
self:RegisterEvent(eventName)
end
table.insert(self.handlers[eventName], func)
end
app.Event:SetScript("OnEvent", function(self, event, ...)
if self.handlers[event] then
for _, handler in ipairs(self.handlers[event]) do
handler(...)
end
end
end)
-------------
-- ON LOAD --
-------------
app.Event:Register("ADDON_LOADED", function(addOnName, containsBindings)
if addOnName == appName then
app.Flag = {}
C_ChatInfo.RegisterAddonMessagePrefix("SlackTweakSuite")
app:CreateSlashCommands()
end
end)
-------------------
-- VERSION COMMS --
-------------------
function app:SendAddonMessage(message)
if IsInRaid(2) or IsInGroup(2) then
ChatThrottleLib:SendAddonMessage("NORMAL", app.NamePrefix, message, "INSTANCE_CHAT")
elseif IsInGroup() or IsInRaid() then
ChatThrottleLib:SendAddonMessage("NORMAL", app.NamePrefix, message, "RAID")
elseif IsInGuild() then
ChatThrottleLib:SendAddonMessage("NORMAL", app.NamePrefix, message, "GUILD")
end
end
app.Event:Register("GROUP_ROSTER_UPDATE", function(category, partyGUID)
app:SendAddonMessage("version:" .. C_AddOns.GetAddOnMetadata(appName, "Version"))
end)
app.Event:Register("PLAYER_ENTERING_WORLD", function(isInitialLogin, isReloadingUi)
if isInitialLogin or isReloadingUi then
app:SendAddonMessage("version:" .. C_AddOns.GetAddOnMetadata(appName, "Version"))
end
end)
app.Event:Register("CHAT_MSG_ADDON", function(prefix, text, channel, sender, target, zoneChannelID, localID, name, instanceID)
if prefix == app.NamePrefix then
local version = text:match("version:(.+)")
if version and not app.Flag.VersionCheck then
local expansion, major, minor, iteration = version:match("v(%d+)%.(%d+)%.(%d+)%-(%d+)")
if expansion then
expansion = string.format("%02d", expansion)
major = string.format("%02d", major)
minor = string.format("%02d", minor)
local otherGameVersion = tonumber(expansion .. major .. minor)
local otherAddonVersion = tonumber(iteration)
local localVersion = C_AddOns.GetAddOnMetadata(appName, "Version")
local expansion2, major2, minor2, iteration2 = localVersion:match("v(%d+)%.(%d+)%.(%d+)%-(%d+)")
if expansion2 then
expansion2 = string.format("%02d", expansion2)
major2 = string.format("%02d", major2)
minor2 = string.format("%02d", minor2)
local localGameVersion = tonumber(expansion2 .. major2 .. minor2)
local localAddonVersion = tonumber(iteration2)
if otherGameVersion > localGameVersion or (otherGameVersion == localGameVersion and otherAddonVersion > localAddonVersion) then
app:Print(L.NEW_VERSION_AVAILABLE, version)
app.Flag.VersionCheck = true
end
end
end
end
end
end)
--------------------
-- SLASH COMMANDS --
--------------------
function app:CreateSlashCommands()
SLASH_RELOADUI1 = "/rl"
SlashCmdList.RELOADUI = ReloadUI
SLASH_SlackersTweakSuite1 = "/sts"
function SlashCmdList.SlackersTweakSuite(msg, editBox)
local command, rest = msg:match("^(%S*)%s*(.-)$")
if command == "settings" then
app:OpenSettings()
elseif command == "debug" then
if app.Settings["debug"] then
app.Settings["debug"] = false
app:Print(L.DEBUG_DISABLED)
else
app.Settings["debug"] = true
app:Print(L.DEBUG_ENABLED)
end
else
app:Print(L.INVALID_COMMAND)
end
end
end
----------------------
-- HELPER FUNCTIONS --
----------------------
function app:Colour(string)
return "|cff3FC7EB" .. string .. "|r"
end
function app:Debug(...)
if app.Settings["debug"] then
print(app.NameShort .. app:Colour(" Debug") .. ":", ...)
end
end
function app:Print(...)
print(app.NameShort .. ":", ...)
end