@@ -27,73 +27,71 @@ LazyCurve.lastMsgTime = 0
2727
2828--- @private
2929function LazyCurve :OnCancel (CancelButton )
30- if (self .DB .enableSimulation ) then
31- LazyCurve :OnSignUp (CancelButton )
32- end
30+ if (self .DB .enableSimulation ) then
31+ LazyCurve :OnSignUp (CancelButton )
32+ end
3333end
3434
3535--- @private
36+ --- @param SignUpButton LFGListApplicationDialog_SignUpButton | LFGListApplicationDialog_CancelButton
3637function LazyCurve :OnSignUp (SignUpButton )
37- if (self .DB .whisperOnApply ~= true ) then
38- return
39- end
40- local dialog = SignUpButton :GetParent ()
41- local resultID = dialog .resultID
42- local resultInfo = C_LFGList .GetSearchResultInfo (resultID )
43-
44- if (resultInfo ) then
45- local leaderName = resultInfo .leaderName
46- local activityInfo = C_LFGList .GetActivityInfoTable (resultInfo .activityID or resultInfo .activityIDs [1 ])
47- local infoTable = activityInfo
48- and activityInfo .groupFinderActivityGroupID
49- and LazyCurve .utils .searchEntryMenu :GetInfoTableByActivityGroup (activityInfo .groupFinderActivityGroupID , true )
50-
51- if (infoTable ) then
52- local achievementList = {}
53-
54- for _ , activityTable in ipairs (infoTable ) do
55- local earnedAchievements = LazyCurve .utils .achievement :GetHighestEarnedAchievement (activityTable , true )
56- if # earnedAchievements > 0 then
57- for _ , achievementId in ipairs (earnedAchievements ) do
58- achievementList [achievementId ] = achievementId
59- end
60- end
61- end
62-
63- local message = ' ' ;
64- for _ , achievementId in pairs (achievementList ) do
65- message = message .. ' ' .. GetAchievementLink (achievementId )
66- end
67- if message == ' ' then
68- if (self .DB .enableSimulation ) then self :SimulationPrint (' no achievements found to whisper' ) end
69- return
70- end
71-
72- if (self .DB .advertise ) then
73- message = self .PREFIX .. message ;
74- end
75-
76- if (self .DB .enableSimulation ) then
77- self :SimulationPrint (' Intent to whisper "' , leaderName , ' " with message:' , message )
78- return
79- end
80- self .hooks .SendChatMessage (message , ' WHISPER' , nil , leaderName )
81-
82- if (GetTime () - LazyCurve .lastMsgTime ) > 30000 and not self .DB .disableAutolinkReminder then -- 30 secs
83- LazyCurve .lastMsgTime = GetTime ()
84- self :Print (' To disable automatically whispering achievements, type \' /lazycurve\' and toggle off auto-linking on LFG application' )
85- end
86- end
87- end
88- end
89-
90- --- @private
91- --- @todo remove in TWW
92- function LazyCurve :LFGListUtil_GetSearchEntryMenu (resultID )
93- return self .utils .searchEntryMenu :GetSearchEntryMenu (resultID )
38+ if (self .DB .whisperOnApply ~= true ) then
39+ return
40+ end
41+ --- @type LFGListApplicationDialog
42+ local dialog = SignUpButton :GetParent ()
43+ local resultID = dialog .resultID
44+ local resultInfo = C_LFGList .GetSearchResultInfo (resultID )
45+
46+ if (resultInfo ) then
47+ local leaderName = resultInfo .leaderName
48+ local activityInfo = C_LFGList .GetActivityInfoTable (resultInfo .activityID or resultInfo .activityIDs [1 ])
49+ local infoTable = activityInfo
50+ and activityInfo .groupFinderActivityGroupID
51+ and LazyCurve .utils .searchEntryMenu :GetInfoTableByActivityGroup (activityInfo .groupFinderActivityGroupID , true )
52+
53+ if (infoTable ) then
54+ local achievementList = {}
55+
56+ for _ , activityTable in ipairs (infoTable ) do
57+ local earnedAchievements = LazyCurve .utils .achievement :GetHighestEarnedAchievement (activityTable , true )
58+ if # earnedAchievements > 0 then
59+ for _ , achievementId in ipairs (earnedAchievements ) do
60+ achievementList [achievementId ] = achievementId
61+ end
62+ end
63+ end
64+
65+ local message = ' ' ;
66+ for _ , achievementId in pairs (achievementList ) do
67+ message = message .. ' ' .. GetAchievementLink (achievementId )
68+ end
69+ if message == ' ' then
70+ if (self .DB .enableSimulation ) then self :SimulationPrint (' no achievements found to whisper' ) end
71+ return
72+ end
73+
74+ if (self .DB .advertise ) then
75+ message = self .PREFIX .. message ;
76+ end
77+
78+ if (self .DB .enableSimulation ) then
79+ self :SimulationPrint (' Intent to whisper "' , leaderName , ' " with message:' , message )
80+ return
81+ end
82+ self .hooks .SendChatMessage (message , ' WHISPER' , nil , leaderName )
83+
84+ if (GetTime () - LazyCurve .lastMsgTime ) > 30000 and not self .DB .disableAutolinkReminder then -- 30 secs
85+ LazyCurve .lastMsgTime = GetTime ()
86+ self :Print (' To disable automatically whispering achievements, type \' /lazycurve\' and toggle off auto-linking on LFG application' )
87+ end
88+ end
89+ end
9490end
9591
9692--- @private
93+ --- @param owner table
94+ --- @param rootDescription RootMenuDescriptionProxy
9795function LazyCurve :OnMenuOpen (owner , rootDescription )
9896 local resultID = owner .resultID
9997 if not resultID then return end
@@ -102,122 +100,118 @@ end
102100
103101--- @private
104102function LazyCurve :SimulationPrint (...)
105- if (self .DB .enableSimulation ) then
106- self :Print (' [sim active]' , ... )
107- end
103+ if (self .DB .enableSimulation ) then
104+ self :Print (' [sim active]' , ... )
105+ end
108106end
109107
110108--- @private
111109function LazyCurve :ProcessMsg (message )
112- local original = message
113-
114- local curve , edge ;
115- for keyword , achievementId in pairs (self .utils .achievement :GetAchievementKeywordMap ()) do
116- if keyword == ' curve' then
117- curve = achievementId ;
118- elseif keyword == ' edge' then
119- edge = achievementId ;
120- else
121- message = self .utils .achievement .ReplaceKeywordWithAchievementLink (self , message , keyword , achievementId )
122- end
123- end
124- if curve then
125- message = self .utils .achievement .ReplaceKeywordWithAchievementLink (self , message , ' curve' , curve );
126- end
127- if edge then
128- message = self .utils .achievement .ReplaceKeywordWithAchievementLink (self , message , ' edge' , edge );
129- end
130-
131- if (original ~= message and self .DB .advertise ) then
132- message = self .PREFIX .. message
133- end
134-
135- if (original ~= message and self .DB .enableSimulation ) then
136- self :SimulationPrint (' Intent to replace message with:' , message )
137- return original
138- end
139-
140- return message
110+ if not self .DB .replaceKeywordsInChatMessages then
111+ return message
112+ end
113+
114+ local original = message
115+
116+ local curve , edge ;
117+ for keyword , achievementId in pairs (self .utils .achievement :GetAchievementKeywordMap ()) do
118+ if keyword == ' curve' then
119+ curve = achievementId ;
120+ elseif keyword == ' edge' then
121+ edge = achievementId ;
122+ else
123+ message = self .utils .achievement .ReplaceKeywordWithAchievementLink (self , message , keyword , achievementId )
124+ end
125+ end
126+ if curve then
127+ message = self .utils .achievement .ReplaceKeywordWithAchievementLink (self , message , ' curve' , curve );
128+ end
129+ if edge then
130+ message = self .utils .achievement .ReplaceKeywordWithAchievementLink (self , message , ' edge' , edge );
131+ end
132+
133+ if (original ~= message and self .DB .advertise ) then
134+ message = self .PREFIX .. message
135+ end
136+
137+ if (original ~= message and self .DB .enableSimulation ) then
138+ self :SimulationPrint (' Intent to replace message with:' , message )
139+ return original
140+ end
141+
142+ return message
141143end
142144
143145--- @private
144146function LazyCurve :BNSendWhisper (id , msg )
145- self .hooks .BNSendWhisper (id , self :ProcessMsg (msg ))
147+ self .hooks .BNSendWhisper (id , self :ProcessMsg (msg ))
146148end
147149
148150--- @private
149151function LazyCurve :SendChatMessage (msg , chatType , language , channel )
150- self .hooks .SendChatMessage (self :ProcessMsg (msg ), chatType , language , channel );
152+ self .hooks .SendChatMessage (self :ProcessMsg (msg ), chatType , language , channel );
151153end
152154
153155--- @private
154156function LazyCurve :SendAchievement (leaderName , achievementId )
155- local message = GetAchievementLink (achievementId )
156- if (self .DB .advertise ) then
157- message = self .PREFIX .. message
158- end
159- if (self .DB .enableSimulation ) then
160- self :SimulationPrint (' Intent to whisper "' , leaderName , ' " with message:' , message )
161- return
162- end
163- self .hooks .SendChatMessage (message , ' WHISPER' , nil , leaderName )
157+ local message = GetAchievementLink (achievementId )
158+ if (self .DB .advertise ) then
159+ message = self .PREFIX .. message
160+ end
161+ if (self .DB .enableSimulation ) then
162+ self :SimulationPrint (' Intent to whisper "' , leaderName , ' " with message:' , message )
163+ return
164+ end
165+ self .hooks .SendChatMessage (message , ' WHISPER' , nil , leaderName )
164166end
165167
166168--- @private
167169function LazyCurve :OnInitialize ()
168170 LazyCurveDB = LazyCurveDB or {}
169- self .DB = LazyCurveDB --[[ @as LazyCurveDB]]
170- self :InitDefaults ()
171-
172- self .Config :Initialize ()
173-
174- self :RawHook (' SendChatMessage' , true )
175- self :RawHook (' BNSendWhisper' , true )
176- if LFGListUtil_GetSearchEntryMenu then --- @todo remove in TWW
177- self :RawHook (' LFGListUtil_GetSearchEntryMenu' , true )
178- elseif Menu and Menu .ModifyMenu then
179- Menu .ModifyMenu (' MENU_LFG_FRAME_SEARCH_ENTRY' , function (owner , rootDescription )
180- self :OnMenuOpen (owner , rootDescription )
181- end )
182- end
183- LFGListApplicationDialog .SignUpButton :HookScript (' OnClick' , function (button ) self :OnSignUp (button ) end )
184- LFGListApplicationDialog .CancelButton :HookScript (' OnClick' , function (button ) self :OnCancel (button ) end )
185-
186- self :RegisterChatCommand (' lc' , self .Config .OpenConfig )
187- self :RegisterChatCommand (' lazycurve' , self .Config .OpenConfig )
188-
189- self :RegisterEvent (' ACHIEVEMENT_EARNED' , function () self .utils .achievement :BuildAchievementKeywordMap () end );
190-
191- C_Timer .After (15 , function ()
192- -- achievements aren't loaded on login; so delay it, too lazy to find the proper event though :)
193- self .utils .achievement :BuildAchievementKeywordMap ()
194- end )
171+ self .DB = LazyCurveDB --[[ @as LazyCurveDB]]
172+ self :InitDefaults ()
173+
174+ self .Config :Initialize ()
175+
176+ self :RawHook (' SendChatMessage' , true )
177+ self :RawHook (' BNSendWhisper' , true )
178+ Menu .ModifyMenu (' MENU_LFG_FRAME_SEARCH_ENTRY' , function (owner , rootDescription )
179+ self :OnMenuOpen (owner , rootDescription )
180+ end )
181+ LFGListApplicationDialog .SignUpButton :HookScript (' OnClick' , function (button ) self :OnSignUp (button ) end )
182+ LFGListApplicationDialog .CancelButton :HookScript (' OnClick' , function (button ) self :OnCancel (button ) end )
183+
184+ self :RegisterChatCommand (' lc' , self .Config .OpenConfig )
185+ self :RegisterChatCommand (' lazycurve' , self .Config .OpenConfig )
186+
187+ self :RegisterEvent (' ACHIEVEMENT_EARNED' , function () self .utils .achievement :BuildAchievementKeywordMap () end );
188+
189+ self .utils .achievement :BuildAchievementKeywordMap ()
190+ C_Timer .NewTicker (3 , function ()
191+ -- achievements aren't loaded on login; so delay it, too lazy to find the proper event though :)
192+ self .utils .achievement :BuildAchievementKeywordMap ()
193+ end , 5 )
195194end
196195
197196--- @private
198197function LazyCurve :InitDefaults ()
199198 --- @type LazyCurveDB
200- local defaults = {
201- advertise = true ,
202-
203- whisperOnApply = true ,
204- disableAutolinkReminder = false ,
205- mythicThreshold = 2 ,
206-
207- devMode = false ,
208- enableSimulation = false ,
209- simulatedAchievements = {},
210- }
211- local configChanged = false
212-
213- for property , value in pairs (defaults ) do
214- if self .DB [property ] == nil then
215- self .DB [property ] = value
216- configChanged = true
217- end
218- end
219-
220- if configChanged then
221- C_Timer .After (4 , function () self .Config :OpenConfig () end )
222- end
199+ local defaults = {
200+ advertise = true ,
201+
202+ replaceKeywordsInChatMessages = true ,
203+ whisperOnApply = true ,
204+ disableAutolinkReminder = false ,
205+ mythicThreshold = 2 ,
206+
207+ devMode = false ,
208+ enableSimulation = false ,
209+ simulatedAchievements = {},
210+ }
211+
212+ for property , value in pairs (defaults ) do
213+ if self .DB [property ] == nil then
214+ self .DB [property ] = value
215+ end
216+ end
223217end
0 commit comments