Skip to content

Commit 0d3612b

Browse files
committed
Added an option to disable keyword replacements in chat
1 parent 1843520 commit 0d3612b

File tree

4 files changed

+163
-153
lines changed

4 files changed

+163
-153
lines changed

Config.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ function Config:GetOptions()
3535
width = "full",
3636
type = "toggle",
3737
},
38+
replaceKeywordsInChatMessages = {
39+
order = increment(),
40+
name = "Replace keywords in chat messages",
41+
desc = "Replace keywords in chat messages with the corresponding achievement link. Such as 'EDGE' or 'CURVE'.",
42+
descStyle = 'inline',
43+
width = "full",
44+
type = "toggle",
45+
},
3846
whisperOnApply = {
3947
order = increment(),
4048
name = "Enable auto-linking on LFG application",

LazyCurve.lua

Lines changed: 146 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -27,73 +27,71 @@ LazyCurve.lastMsgTime = 0
2727

2828
--- @private
2929
function 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
3333
end
3434

3535
--- @private
36+
--- @param SignUpButton LFGListApplicationDialog_SignUpButton|LFGListApplicationDialog_CancelButton
3637
function 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
9490
end
9591

9692
--- @private
93+
--- @param owner table
94+
--- @param rootDescription RootMenuDescriptionProxy
9795
function LazyCurve:OnMenuOpen(owner, rootDescription)
9896
local resultID = owner.resultID
9997
if not resultID then return end
@@ -102,122 +100,118 @@ end
102100

103101
--- @private
104102
function 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
108106
end
109107

110108
--- @private
111109
function 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
141143
end
142144

143145
--- @private
144146
function LazyCurve:BNSendWhisper(id, msg)
145-
self.hooks.BNSendWhisper(id, self:ProcessMsg(msg))
147+
self.hooks.BNSendWhisper(id, self:ProcessMsg(msg))
146148
end
147149

148150
--- @private
149151
function 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);
151153
end
152154

153155
--- @private
154156
function 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)
164166
end
165167

166168
--- @private
167169
function 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)
195194
end
196195

197196
--- @private
198197
function 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
223217
end

Utils_SearchEntryMenu.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ local function tableInsertChildren(target, tableToInsert)
1414
end
1515

1616
--- @param resultID number
17+
--- @param rootDescription RootMenuDescriptionProxy
1718
function SearchEntryMenuUtil:ExtendMenu(resultID, rootDescription)
1819
local resultTable = C_LFGList.GetSearchResultInfo(resultID);
1920
local activityInfo = C_LFGList.GetActivityInfoTable(resultTable.activityID or resultTable.activityIDs[1])
@@ -30,6 +31,11 @@ function SearchEntryMenuUtil:ExtendMenu(resultID, rootDescription)
3031
end
3132
end
3233

34+
--- @param elementDescription ElementMenuDescriptionProxy|RootMenuDescriptionProxy
35+
--- @param achievementId number
36+
--- @param leaderName string
37+
--- @param textPrefix string?
38+
--- @return ElementMenuDescriptionProxy button
3339
function SearchEntryMenuUtil:AddAchievementItem(elementDescription, achievementId, leaderName, textPrefix)
3440
local _, achievementName, _ = GetAchievementInfo(achievementId)
3541
textPrefix = textPrefix or ''
@@ -42,6 +48,7 @@ function SearchEntryMenuUtil:AddAchievementItem(elementDescription, achievementI
4248
return button
4349
end
4450

51+
--- @param rootDescription RootMenuDescriptionProxy
4552
--- @param infoTable LazyCurveActivityTable_enriched[]
4653
--- @param leaderName string?
4754
--- @return boolean # true if any achievement was added, false otherwise
@@ -58,7 +65,7 @@ function SearchEntryMenuUtil:AppendAchievements(rootDescription, infoTable, lead
5865
else
5966
local subMenuItems = {}
6067
for _, achievementID in ipairs(earnedAchievements) do
61-
table.insert(subMenuItems,achievementID)
68+
table.insert(subMenuItems, achievementID)
6269
end
6370
local subMenu = {
6471
text = activityTable.longName,

0 commit comments

Comments
 (0)