|
| 1 | +-- upvalue the globals |
| 2 | +local _G = getfenv(0) |
| 3 | +local LibStub = _G.LibStub |
| 4 | +local C_LFGList = _G.C_LFGList |
| 5 | +local ipairs = _G.ipairs |
| 6 | +local pairs = _G.pairs |
| 7 | +local GetTime = _G.GetTime |
| 8 | +local GetAchievementLink = _G.GetAchievementLink |
| 9 | +local LFGListApplicationDialog = _G.LFGListApplicationDialog |
| 10 | +local LE_EXPANSION_LEVEL_CURRENT = _G.LE_EXPANSION_LEVEL_CURRENT |
| 11 | + |
| 12 | +local name = ... |
| 13 | +local LazyCurve = LibStub('AceAddon-3.0'):NewAddon(name, 'AceConsole-3.0', 'AceHook-3.0', 'AceEvent-3.0'); |
| 14 | +if not LazyCurve then return end |
| 15 | + |
| 16 | +LazyCurve.PREFIX = '<LazyCurve>' |
| 17 | +LazyCurve.ACTIVITY_CATEGORY_RAID = 3 |
| 18 | +LazyCurve.CURRENT_EXPANSION = LE_EXPANSION_LEVEL_CURRENT |
| 19 | + |
| 20 | +LazyCurve.utils = {} |
| 21 | +LazyCurve.lastMsgTime = 0 |
| 22 | + |
| 23 | +function LazyCurve:IsActivityActive(activityTable) |
| 24 | + local searchGroupId = activityTable.groupId |
| 25 | + for _, groupId in ipairs(C_LFGList.GetAvailableActivityGroups(self.ACTIVITY_CATEGORY_RAID)) do |
| 26 | + if groupId == searchGroupId then |
| 27 | + return true |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + return false |
| 32 | +end |
| 33 | + |
| 34 | +function LazyCurve:OnSignUp(SignUpButton) |
| 35 | + if(self.DB.whisperOnApply ~= true) then |
| 36 | + return |
| 37 | + end |
| 38 | + local dialog = SignUpButton:GetParent() |
| 39 | + local resultID = dialog.resultID |
| 40 | + local resultInfo = C_LFGList.GetSearchResultInfo(resultID) |
| 41 | + |
| 42 | + |
| 43 | + if(resultInfo) then |
| 44 | + local leaderName = resultInfo.leaderName |
| 45 | + local _, _, _, groupId, _ = C_LFGList.GetActivityInfo(resultInfo.activityID) |
| 46 | + local infoTable = LazyCurve.utils.searchEntryMenu:GetInfoTableByActivityGroup(groupId, true) |
| 47 | + |
| 48 | + if(infoTable) then |
| 49 | + local achievementList = {} |
| 50 | + |
| 51 | + for _, activityTable in ipairs(infoTable) do |
| 52 | + local earnedAchievements = LazyCurve.utils.achievement:GetHighestEarnedAchievement(activityTable) |
| 53 | + if #earnedAchievements > 0 then |
| 54 | + for _, achievementId in ipairs(earnedAchievements) do |
| 55 | + achievementList[achievementId] = achievementId |
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + local msg = ''; |
| 61 | + if(self.DB.advertise) then |
| 62 | + msg = self.PREFIX .. msg; |
| 63 | + end |
| 64 | + for _, achievementId in pairs(achievementList) do |
| 65 | + msg = msg .. ' ' .. GetAchievementLink(achievementId) |
| 66 | + end |
| 67 | + self.hooks.SendChatMessage(msg, 'WHISPER', nil, leaderName) |
| 68 | + |
| 69 | + if (GetTime() - LazyCurve.lastMsgTime) > 30000 and not self.DB.disableAutolinkReminder then -- 30 secs |
| 70 | + LazyCurve.lastMsgTime = GetTime() |
| 71 | + self:Print('To disable automatically whispering achievements, type \'/lazycurve\' and toggle off auto-linking on LFG application') |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | +end |
| 76 | + |
| 77 | +function LazyCurve:LFGListUtil_GetSearchEntryMenu(resultID) |
| 78 | + return self.utils.searchEntryMenu:GetSearchEntryMenu(resultID) |
| 79 | +end |
| 80 | + |
| 81 | +function LazyCurve:processMsg(message) |
| 82 | + local original = message |
| 83 | + |
| 84 | + for keyword, achievementId in pairs(self.utils.achievement:GetAchievementKeywordMap()) do |
| 85 | + message = self.utils.achievement.ReplaceKeywordWithAchievementLink(self, message, keyword, achievementId) |
| 86 | + end |
| 87 | + |
| 88 | + if(original ~= message and self.DB.advertise) then |
| 89 | + message = self.PREFIX .. message |
| 90 | + end |
| 91 | + return message |
| 92 | +end |
| 93 | + |
| 94 | +function LazyCurve:BNSendWhisper(id, msg) |
| 95 | + self.hooks.BNSendWhisper(id, self:processMsg(msg)) |
| 96 | +end |
| 97 | + |
| 98 | +function LazyCurve:SendChatMessage(msg, chatType, language, channel) |
| 99 | + self.hooks.SendChatMessage(self:processMsg(msg), chatType, language, channel); |
| 100 | +end |
| 101 | + |
| 102 | +function LazyCurve:SendAchievement(leaderName, achievementId) |
| 103 | + local message = GetAchievementLink(achievementId) |
| 104 | + if(self.DB.advertise) then |
| 105 | + message = self.PREFIX .. message |
| 106 | + end |
| 107 | + self.hooks.SendChatMessage(message, 'WHISPER', nil, leaderName) |
| 108 | +end |
| 109 | + |
| 110 | +function LazyCurve:ACHIEVEMENT_EARNED() |
| 111 | + self.utils.achievement:BuildAchievementKeywordMap() |
| 112 | +end |
| 113 | + |
| 114 | +function LazyCurve:OnInitialize() |
| 115 | + self.DB = LazyCurveDB |
| 116 | + self:InitDefaults() |
| 117 | + |
| 118 | + self.Config:Initialize() |
| 119 | + |
| 120 | + self:RawHook('SendChatMessage', true) |
| 121 | + self:RawHook('BNSendWhisper', true) |
| 122 | + self:RawHook('LFGListUtil_GetSearchEntryMenu', true) |
| 123 | + LFGListApplicationDialog.SignUpButton:HookScript('OnClick', function(button) self:OnSignUp(button) end) |
| 124 | + |
| 125 | + self:RegisterChatCommand('lc', self.Config.OpenConfig) |
| 126 | + self:RegisterChatCommand('lazycurve', self.Config.OpenConfig) |
| 127 | + |
| 128 | + self:RegisterEvent('ACHIEVEMENT_EARNED'); |
| 129 | + |
| 130 | + C_Timer.After(15, function() |
| 131 | + --for some reason, some achievements don't properly load the first time you log in; so maybe delaying it helps |
| 132 | + self.utils.achievement:BuildAchievementKeywordMap() |
| 133 | + end) |
| 134 | +end |
| 135 | + |
| 136 | +function LazyCurve:InitDefaults() |
| 137 | + local defaults = { |
| 138 | + advertise = true, |
| 139 | + |
| 140 | + whisperOnApply = true, |
| 141 | + disableAutolinkReminder = false, |
| 142 | + mythicThreshold = 2, |
| 143 | + } |
| 144 | + local configChanged = false |
| 145 | + |
| 146 | + for property, value in pairs(defaults) do |
| 147 | + if self.DB[property] == nil then |
| 148 | + self.DB[property] = value |
| 149 | + configChanged = true |
| 150 | + end |
| 151 | + end |
| 152 | + |
| 153 | + if configChanged then |
| 154 | + C_Timer.After(4, function() self.Config:OpenConfig() end) |
| 155 | + end |
| 156 | + self:Print('loaded version', self.Config.version) |
| 157 | + |
| 158 | +end |
0 commit comments