1
0
Fork 0
AllTheLittleThings/modules/miscellaneous.lua

205 lines
5.4 KiB
Lua
Raw Normal View History

2011-05-30 14:38:32 -04:00
local core = LibStub("AceAddon-3.0"):GetAddon("AllTheLittleThings")
local mod = core:NewModule("Miscellaneous", "AceEvent-3.0", "AceConsole-3.0", "AceHook-3.0", "AceTimer-3.0")
local db = core.db.profile[mod:GetName()]
local defaults = {
rollTally = true,
nixAFK = true,
achieveFilter = true,
markMsgFilter = true,
officerPhone = 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 <player>",
type = 'toggle',
},
}
function mod:OnInitialize()
core:RegisterOptions(options, defaults)
core:RegisterSlashCommand("RollTally", "rt", "rolltally")
core:RegisterSlashCommand("FindPhones", "phone")
core:RegisterSlashCommand("ActiveTally", "at", "activetally")
-- allow max camera zoom
ConsoleExec("cameradistancemaxfactor 5")
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");
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 ------------------------------------------------------------------
function core:CHAT_MSG_RAID_WARNING(_, message)
if self.db.profile.rollTally and string.find(message:lower(), "roll") then
if self.rollTimer then
-- Stop current roll
self:CancelTimer(self.rollTimer)
self:RollFinish()
end
self.rollTally = {}
self.rollTimer = self:ScheduleTimer("RollFinish", 10)
end
end
-- Officer Phone ---------------------------------------------------------------
function core:CHAT_MSG_OFFICER(_, msg)
local _,_,numA,numB,numC = msg:find("!phone %(?(%d+)%)?.(%d+).(%d+)");
local _,_,name = msg:find("!phone (%w+)");
if (not (numA and numB and numC) and not name) then
return;
end
local setting = GetGuildRosterShowOffline();
SetGuildRosterShowOffline(1);
for i=1,GetNumGuildMembers() do
local p, n = self:CheckPhone(i);
if ((name and p and p:lower():find(name:lower())) or
(numA and n and format("%s-%s-%s", numA, numB, numC)==n)) then
if (n) then
SendChatMessage(format("%s: %s", p, n), "officer");
else
SendChatMessage(format("No %s for %s.", (numA and "name") or "number", p), "officer");
end
end
end
SetGuildRosterShowOffline(setting);
end
function core:CheckPhone(index)
local name, rank, _, _, _, _, _, onote = GetGuildRosterInfo(index);
local a, b, c = onote:match("%(?(%d%d%d)%)?.(%d%d%d).(%d%d%d%d)");
if (not rank:find("Alt") and not rank:find("Non")) then
if (a) then
return name, format("%s-%s-%s", a, b, c);
end
return name, nil;
end
return nil, nil;
end