-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCue.lua
More file actions
executable file
·195 lines (169 loc) · 5.53 KB
/
Cue.lua
File metadata and controls
executable file
·195 lines (169 loc) · 5.53 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
local addonName, ns, _ = ...
-- GLOBALS: _G, LibStub, GameTooltip, CueDB, SlashCmdList, SLASH_CUE1, SLASH_CUE2
-- GLOBALS: ToggleFrame, IsShiftKeyDown, RegisterAddonMessagePrefix, InterfaceOptionsFrame_OpenToCategory, JoinTemporaryChannel, LeaveChannelByName
-- GLOBALS: type, tostringall, assert, pairs, print
local join, format = string.join, string.format
--[[
possible settings: /run CueDB[mySetting] = myValue
- stayQueuedOnInvite: if you're in several queues when an invite pops, setting this to <true> will prevent Cue from automatically leaving all other queues
--]]
-- ================================================
-- Event Handling
-- ================================================
local frame, eventHooks = CreateFrame("Frame", addonName.."EventHandler"), {}
local function eventHandler(frame, event, arg1, ...)
if event == 'ADDON_LOADED' and arg1 == addonName then
-- make sure we always init before any other module
ns.Initialize()
if not eventHooks[event] or ns.Count(eventHooks[event]) < 1 then
frame:UnregisterEvent(event)
end
end
if eventHooks[event] then
for id, listener in pairs(eventHooks[event]) do
listener(frame, event, arg1, ...)
end
end
end
frame:SetScript("OnEvent", eventHandler)
frame:RegisterEvent("ADDON_LOADED")
function ns.RegisterEvent(event, callback, id, silentFail)
assert(callback and event and id, format("Usage: RegisterEvent(event, callback, id[, silentFail])"))
if not eventHooks[event] then
eventHooks[event] = {}
frame:RegisterEvent(event)
end
assert(silentFail or not eventHooks[event][id], format("Event %s already registered by id %s.", event, id))
eventHooks[event][id] = callback
end
function ns.UnregisterEvent(event, id)
if not eventHooks[event] or not eventHooks[event][id] then return end
eventHooks[event][id] = nil
if ns.Count(eventHooks[event]) < 1 then
eventHooks[event] = nil
frame:UnregisterEvent(event)
end
end
-- ================================================
-- Basic Setup
-- ================================================
function ns.Initialize()
local LDB = LibStub("LibDataBroker-1.1")
local ldb = LDB:GetDataObjectByName(addonName)
if not ldb then
ldb = LDB:NewDataObject(addonName, {
type = "launcher",
icon = "Interface\\Icons\\Achievement_BG_KillXEnemies_GeneralsRoom",
label = addonName
})
end
ldb.OnClick = function(self, button)
if button == "RightButton" then
-- open config
InterfaceOptionsFrame_OpenToCategory(addonName)
elseif IsShiftKeyDown() then
ns.Toggle()
else
ns.InitUI()
ToggleFrame(_G["CueFrame"])
ns.UpdateUI()
end
end
RegisterAddonMessagePrefix("OQ")
-- ns.PreventBnetSpam()
local realmName = GetRealmName()
ns.playerName = UnitName("player") .. '-' .. realmName
ns.playerRealm = ns.GetRealmInfoByName(realmName)
ns.playerFaction = UnitFactionGroup("player") == 'Horde' and 'H' or 'A' -- TODO: we don't care about indecisive Pandaren
_, ns.playerBattleTag = BNGetInfo()
ns.playerBattleTag = string.lower(ns.playerBattleTag)
if not CueDB then CueDB = {} end
ns.db = CueDB
if not ns.db.queued then ns.db.queued = {} end -- tracks groups we've requested to join
if not ns.db.blacklist then ns.db.blacklist = {} end -- tracks leaders' battletags we don't want to group with
if not ns.db.bntracking then ns.db.bntracking = {} end -- tracks requests sent as BN friend invite so we can set notes
if not ns.db.premadeCache then ns.db.premadeCache = {} end -- tracks groups that are currently available
if not ns.db.tokens then ns.db.tokens = {} end -- tracks generated, sent request tokens
SLASH_CUE1 = '/cue'
SLASH_CUE2 = '/queue'
SlashCmdList['CUE'] = function(msg)
ns.InitUI()
ns.UpdateUI()
ToggleFrame(_G["CueFrame"])
end
ns.Enable()
-- expose
_G[addonName] = ns
end
local AceTimer = LibStub("AceTimer-3.0")
local pruneData
local enabled = nil
function ns.Enable()
JoinTemporaryChannel(ns.OQchannel)
JoinTemporaryChannel('oqgeneral')
frame:Show() -- start listening for events
enabled = true
ns.PruneData()
pruneData = AceTimer:ScheduleRepeatingTimer(ns.PruneData, 60)
end
function ns.Disable()
LeaveChannelByName(ns.OQchannel)
LeaveChannelByName('oqgeneral')
frame:Hide()
enabled = nil
AceTimer:CancelTimer(pruneData)
end
function ns.Toggle()
if enabled then
ns.Print('is disabled')
ns.Disable()
else
ns.Print('is enabled')
ns.Enable()
end
end
-- ================================================
-- Little Helpers
-- ================================================
function ns.Print(text, ...)
if ... and text:find("%%[ds123456789]+") then
text = format(text, ...)
elseif ... then
text = join(", ", tostringall(text, ...))
end
print("|cffE01B5D"..addonName.."|r "..text)
end
-- counts table entries. for numerically indexed tables, use #table
function ns.Count(table)
if not table or type(table) ~= "table" then return 0 end
local i = 0
for _ in pairs(table) do
i = i + 1
end
return i
end
function ns.Find(where, what)
for k, v in pairs(where) do
if v == what then
return k
end
end
end
function ns.ShowTooltip(self)
if not self.tiptext and not self.link then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:ClearLines()
if self.link then
GameTooltip:SetHyperlink(self.link)
elseif type(self.tiptext) == "string" and self.tiptext ~= "" then
GameTooltip:SetText(self.tiptext, nil, nil, nil, nil, true)
elseif type(self.tiptext) == "function" then
self.tiptext(self, GameTooltip)
end
GameTooltip:Show()
end
function ns.HideTooltip() GameTooltip:Hide() end
function ns.utc()
-- TODO: FIXME: only works on MacOS
return date('!%s')
end