local core = LibStub("AceAddon-3.0"):GetAddon("AllTheLittleThings") local mod = core:NewModule("Miscellaneous", "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0") local db local defaults = { rollTally = true, nixAFK = true, achieveFilter = true, markMsgFilter = true, officerPhone = true, clickToPaste = true, } local options = { rollTally = { name = "Roll Tally", desc = "Tallies rolls for 8s after a raid warning with 'roll' in the message. Can also activate with /atlt rt.", type = "toggle", }, nixAFK = { name = "Remove AFK Responses", desc = "Removes AFK responses when whispering AFK players.", type = "toggle", }, achieveFilter = { name = "Achievement Filter", desc = "Sets achievement filter to Incomplete automatically.", type = "toggle", }, markMsgFilter = { name = "Mark Message Filter", desc = "Filters mark messages caused by the player.", type = 'toggle', }, officerPhone = { name = "Officer Phone Records", desc = "Allows !phone ", type = 'toggle', }, clickToPaste = { name = "Quick Paste to Officer Chat", desc = "Ctrl+Click on a chat line name to paste to Officer Chat", type = 'toggle', }, } function mod:OnInitialize() self:RegisterOptions(options, defaults, function(d) db=d end) self:RegisterSlashCommand("RollTally", "rt", "rolltally") self:RegisterSlashCommand("FindPhones", "phone") self:RegisterSlashCommand("ActiveTally", "at", "activetally") -- allow max camera zoom ConsoleExec("cameradistancemaxfactor 5") CompactRaidFrameContainer.Show = CompactRaidFrameContainer.Hide -- Fix guild crafters: must be in OnInitialize because ADDON_LOADED is buggy otherwise self:RegisterEvent("ADDON_LOADED", function(_, name) if name == "Blizzard_TradeSkillUI" then for i=1, TRADE_SKILL_GUILD_CRAFTERS_DISPLAYED do _G["TradeSkillGuildCrafter"..i.."Text"].SetTextColor = function() end end end end) end function mod:OnEnable() -- allow split with tradeskill SetModifiedClick("TRADESEARCHADD", nil) -- roll tally self:RegisterEvent("CHAT_MSG_RAID_WARNING") self:RegisterEvent("CHAT_MSG_SYSTEM") -- nix afk ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", function(...) return self:NixAFK(...) end) -- achieve filter self:RawHook("AchievementFrame_LoadUI", true) -- target icons self:SecureHook("TargetUnit") -- filter self targets ChatFrame_AddMessageEventFilter("CHAT_MSG_TARGETICONS", function(_,_,msg) if (msg:find("%["..UnitName("player").."%]")) then return true end end) -- officer phone self:RegisterEvent("CHAT_MSG_OFFICER"); -- louder LFD sound self:RegisterEvent("LFG_PROPOSAL_SHOW"); -- item level self:SecureHook("PaperDollFrame_SetItemLevel") end -- Slash Commands -------------------------------------------------------------- function mod:RollTally() self:CHAT_MSG_RAID_WARNING(nil, "roll") end function mod:FindPhones() local found = false; for i=1,GetNumGuildMembers() do local player, num = self:CheckPhone(i); if (player and not num) then if (not found) then self:Print("Players without phone numbers:"); found = true; end self:Print(player); end end if (not found) then self:Print("All players have a phone number."); end end function mod:ActiveTally(mode) local showTotal = mode=="t" or mode=="total" local function printInfo(msg) -- self:Print(msg) SendChatMessage(msg, "guild") end local mains = {} local alts = {} -- really a table of the mains as the key, alt totals as the value, but we'll merge later once we can confirm local capped = {} -- table of mains who hit cap for i=1,GetNumGuildMembers() do local name, rank, _, _, _, _, note = GetGuildRosterInfo(i) local xp, total = GetGuildRosterContribution(i) local tbl = mains if showTotal then xp = total end if rank:find("Alt") then name, tbl = note, alts end if rank ~= "Non-raider" or name == "Ariik" then if not tbl[name] then tbl[name] = 0 end tbl[name] = tbl[name] + xp if xp == 1575002 then -- don't think there is a weekly cap -- capped[name] = true end end end -- total and merge alts local total = 0 for k,v in pairs(mains) do mains[k] = mains[k] + (alts[k] or 0) total = total + mains[k] end -- print using selection sort printInfo("Top contributors for the week; alts included:") while next(mains) ~= nil do local max, maxVal = "-", -1 for k,v in pairs(mains) do if v > maxVal then max, maxVal = k, v end end printInfo(format("%s%s - %d (%.1f%%)", (capped[max] and "*" or ""), max, maxVal, maxVal/total*100)) mains[max] = nil end end -- Roll Tally ------------------------------------------------------------------ local rollTally = {} local rollTimer = false function mod:CHAT_MSG_RAID_WARNING(_, message) if db.rollTally and string.find(message:lower(), "roll") then if rollTimer then -- Stop current roll self:CancelTimer(rollTimer) self:RollFinish() end rollTally = {} rollTimer = self:ScheduleTimer("RollFinish", 10) end end function mod:CHAT_MSG_SYSTEM(_, message, source) if db.rollTally and rollTimer then local name, roll, min, max = string.match(message, "(%S+) rolls (%d+) %((%d+)%-(%d+)%)") if name and roll and min and max then if min ~= "1" or max ~= "100" then self:Print(string.format("%s is rolling out of bounds (%d-%d).", name, min, max)) return end if not rollTally then rollTally = {} end if rollTally[name] then self:Print(string.format("%s is rolling again (first: %d, this: %d).", name, rollTally[name], roll)) return end rollTally[name] = roll end end end function mod:RollFinish() local winner local ties = {} for i,v in pairs(rollTally) do if (not winner) or (tonumber(rollTally[winner]) with auto complete --------------------------------- -- change our OnEscapePressed to Reset function ChatEdit_OnEscapePressed(editBox) ChatEdit_ResetChatTypeToSticky(editBox); if ( not editBox.isGM and (GetCVar("chatStyle") ~= "im" or editBox == MacroEditBox) ) then editBox:SetText(""); editBox:Hide(); else ChatEdit_DeactivateChat(editBox); end end -- change the editbox's OnEscape to a real OnEscape for i=1,NUM_CHAT_WINDOWS do local f = _G["ChatFrame"..i.."EditBox"] if f then f:SetScript("OnEscapePressed", function(editBox) if ( not AutoCompleteEditBox_OnEscapePressed(editBox) ) then ChatEdit_OnEscapePressed(editBox) end end) end end -- LFD Louder Noise ------------------------------------------------------------ function mod:LFG_PROPOSAL_SHOW() PlaySound("ReadyCheck", "Master"); end -- Officer Chat Link ----------------------------------------------------------- local SetItemRefHook = SetItemRef function SetItemRef(id, text, button, chatFrame, ...) if IsControlKeyDown() and db.clickToPaste then local name = id:match("player:(.-):") local prefix, message for i=1,select("#", chatFrame:GetRegions()) do local r = select(i, chatFrame:GetRegions()) if r:GetObjectType() == "FontString" and r:GetText():find(id) then -- found the line, extract the message prefix, message = r:GetText():match("(.-%S:%s)(.+)") -- nasty hack to change player name in during whisper if id:find(":WHISPER:") and prefix:lower():find("%Wto%W") then name = UnitName("player") end break end end if name and message then message = message:gsub("|c%x%x%x%x%x%x%x%x([^|].-)|r", "%1") SendChatMessage(("%s: %s"):format(name, message), "officer") return end end SetItemRefHook(id, text, button, chatFrame, ...) end -- Equipped Item Level in Paper Doll ------------------------------------------- function mod:PaperDollFrame_SetItemLevel(frame, unit) local itemLevel, currentItemLevel, itemCount = 0, 0, 0 local itemLevelText if unit ~= 'player' then return end itemLevel = GetAverageItemLevel() for slot = 1, 18 do local item = GetInventoryItemLink("player", slot) if item ~= nil then _, _, quality, iLevel = GetItemInfo(item) if quality > 3 then currentItemLevel = currentItemLevel + iLevel elseif quality > 2 then currentItemLevel = currentItemLevel + iLevel - 13 end itemCount = itemCount + 1 end end itemLevelText = _G[frame:GetName()..'StatText'] itemLevelText:SetText(floor(currentItemLevel / itemCount) .. ' (' .. floor(itemLevel) .. ')') end