Repository navigation
Expand file tree
/
Copy pathLazyCurve.lua
More file actions
241 lines (207 loc) · 8.1 KB
/
Copy pathLazyCurve.lua
File metadata and controls
241 lines (207 loc) · 8.1 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
-- upvalue the globals
local LibStub = _G.LibStub
local C_LFGList = _G.C_LFGList
local ipairs = _G.ipairs
local pairs = _G.pairs
local GetTime = _G.GetTime
local GetAchievementLink = _G.GetAchievementLink
local C_Timer = _G.C_Timer
local LFGListApplicationDialog = _G.LFGListApplicationDialog
local LE_EXPANSION_WAR_WITHIN = _G.LE_EXPANSION_WAR_WITHIN
local name = ...
--- @class LazyCurve: AceAddon, AceConsole-3.0, AceHook-3.0, NumyAceEvent-3.0
local LazyCurve = LibStub('AceAddon-3.0'):NewAddon(name, 'AceConsole-3.0', 'AceHook-3.0', 'NumyAceEvent-3.0');
if not LazyCurve then return end
_G.LazyCurve = LazyCurve
LazyCurve.PREFIX = '<LazyCurve>'
LazyCurve.CURRENT_EXPANSION = LE_EXPANSION_WAR_WITHIN
LazyCurve.MODULE_TYPE_RAID = 'raid'
LazyCurve.MODULE_TYPE_OTHER = 'other'
LazyCurve.utils = {}
--- @private
LazyCurve.lastMsgTime = 0
--- @private
function LazyCurve:OnCancel(CancelButton)
if (self.DB.enableSimulation) then
LazyCurve:OnSignUp(CancelButton)
end
end
--- @private
--- @param SignUpButton LFGListApplicationDialog_SignUpButton|LFGListApplicationDialog_CancelButton
function LazyCurve:OnSignUp(SignUpButton)
if (self.DB.whisperOnApply ~= true) then
return
end
--- @type LFGListApplicationDialog
local dialog = SignUpButton:GetParent()
local resultID = dialog.resultID
local resultInfo = C_LFGList.GetSearchResultInfo(resultID)
if (resultInfo) then
local leaderName = resultInfo.leaderName
local activityInfo = C_LFGList.GetActivityInfoTable(resultInfo.activityID or resultInfo.activityIDs[1])
local infoTable = activityInfo
and activityInfo.groupFinderActivityGroupID
and LazyCurve.utils.searchEntryMenu:GetInfoTableByActivityGroup(activityInfo.groupFinderActivityGroupID, true)
if (infoTable) then
local achievementList = {}
for _, activityTable in ipairs(infoTable) do
local earnedAchievements = LazyCurve.utils.achievement:GetHighestEarnedAchievement(activityTable, true)
if #earnedAchievements > 0 then
for _, achievementId in ipairs(earnedAchievements) do
achievementList[achievementId] = achievementId
end
end
end
local message = '';
for _, achievementId in pairs(achievementList) do
message = message .. ' ' .. GetAchievementLink(achievementId)
end
if message == '' then
if (self.DB.enableSimulation) then self:SimulationPrint('no achievements found to whisper') end
return
end
if (self.DB.advertise) then
message = self.PREFIX .. message;
end
if (self.DB.enableSimulation) then
self:SimulationPrint('Intent to whisper "', leaderName, '" with message:', message)
return
end
self:SendChatMessageRaw(message, 'WHISPER', nil, leaderName)
if (GetTime() - LazyCurve.lastMsgTime) > 30000 and not self.DB.disableAutolinkReminder then -- 30 secs
LazyCurve.lastMsgTime = GetTime()
self:Print('To disable automatically whispering achievements, type \'/lazycurve\' and toggle off auto-linking on LFG application')
end
end
end
end
--- @private
--- @param owner table
--- @param rootDescription RootMenuDescriptionProxy
function LazyCurve:OnMenuOpen(owner, rootDescription)
local resultID = owner.resultID
if not resultID then return end
self.utils.searchEntryMenu:ExtendMenu(resultID, rootDescription)
end
--- @private
function LazyCurve:SimulationPrint(...)
if (self.DB.enableSimulation) then
self:Print('[sim active]', ...)
end
end
--- @private
function LazyCurve:ProcessMsg(message)
if not self.DB.replaceKeywordsInChatMessages then
return message
end
local original = message
local curve, edge;
for keyword, achievementId in pairs(self.utils.achievement:GetAchievementKeywordMap()) do
if keyword == 'curve' then
curve = achievementId;
elseif keyword == 'edge' then
edge = achievementId;
else
message = self.utils.achievement.ReplaceKeywordWithAchievementLink(self, message, keyword, achievementId)
end
end
if curve then
message = self.utils.achievement.ReplaceKeywordWithAchievementLink(self, message, 'curve', curve);
end
if edge then
message = self.utils.achievement.ReplaceKeywordWithAchievementLink(self, message, 'edge', edge);
end
if (original ~= message and self.DB.advertise) then
message = self.PREFIX .. message
end
if (original ~= message and self.DB.enableSimulation) then
self:SimulationPrint('Intent to replace message with:', message)
return original
end
return message
end
--- @private
function LazyCurve:BNSendWhisper(id, msg)
if C_BattleNet.SendWhisper then
self.hooks[C_BattleNet].SendWhisper(id, self:ProcessMsg(msg))
else
self.hooks.BNSendWhisper(id, self:ProcessMsg(msg))
end
end
--- @private
function LazyCurve:SendChatMessage(msg, chatType, language, channel)
self:SendChatMessageRaw(self:ProcessMsg(msg), chatType, language, channel)
end
--- @private
function LazyCurve:SendChatMessageRaw(msg, chatType, language, channel)
if C_ChatInfo.SendChatMessage then
self.hooks[C_ChatInfo].SendChatMessage(msg, chatType, language, channel);
else
self.hooks.SendChatMessage(msg, chatType, language, channel);
end
end
--- @private
function LazyCurve:SendAchievement(leaderName, achievementId)
local message = GetAchievementLink(achievementId)
if (self.DB.advertise) then
message = self.PREFIX .. message
end
if (self.DB.enableSimulation) then
self:SimulationPrint('Intent to whisper "', leaderName, '" with message:', message)
return
end
self:SendChatMessageRaw(message, 'WHISPER', nil, leaderName)
end
--- @private
function LazyCurve:OnInitialize()
LazyCurveDB = LazyCurveDB or {}
self.DB = LazyCurveDB --[[@as LazyCurveDB]]
self:InitDefaults()
self.Config:Initialize()
local toc = select(4, GetBuildInfo())
-- 12.0 made SendChatMessage protected in certain situations, so we can't raw hook it
if toc > 110000 and toc < 120000 then
if C_ChatInfo.SendChatMessage then
self:RawHook(C_ChatInfo, 'SendChatMessage', true)
else
self:RawHook('SendChatMessage', true)
end
if C_BattleNet.SendWhisper then
self:RawHook(C_BattleNet, 'SendWhisper', 'BNSendWhisper', true)
else
self:RawHook('BNSendWhisper', 'BNSendWhisper', true)
end
end
Menu.ModifyMenu('MENU_LFG_FRAME_SEARCH_ENTRY', function(owner, rootDescription)
self:OnMenuOpen(owner, rootDescription)
end)
LFGListApplicationDialog.SignUpButton:HookScript('OnClick', function(button) self:OnSignUp(button) end)
LFGListApplicationDialog.CancelButton:HookScript('OnClick', function(button) self:OnCancel(button) end)
self:RegisterChatCommand('lc', function() self.Config:OpenConfig(); end);
self:RegisterChatCommand('lazycurve', function() self.Config:OpenConfig(); end);
self:RegisterEvent('ACHIEVEMENT_EARNED', function() self.utils.achievement:BuildAchievementKeywordMap() end);
self.utils.achievement:BuildAchievementKeywordMap()
C_Timer.NewTicker(3, function()
-- achievements aren't loaded on login; so delay it, too lazy to find the proper event though :)
self.utils.achievement:BuildAchievementKeywordMap()
end, 5)
end
--- @private
function LazyCurve:InitDefaults()
--- @type LazyCurveDB
local defaults = {
advertise = true,
replaceKeywordsInChatMessages = true,
whisperOnApply = true,
disableAutolinkReminder = false,
mythicThreshold = 2,
devMode = false,
enableSimulation = false,
simulatedAchievements = {},
}
for property, value in pairs(defaults) do
if self.DB[property] == nil then
self.DB[property] = value
end
end
end