Rework whoer
This commit is contained in:
128
Whoer.lua
128
Whoer.lua
@@ -1,13 +1,14 @@
|
||||
local addonname, data = ...
|
||||
---@cast data HeimdallData
|
||||
local addonname, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
---@cast addonname string
|
||||
|
||||
data.Whoer = {}
|
||||
function data.Whoer.Init()
|
||||
if not data.config.who.enabled then
|
||||
print("Heimdall - Whoer disabled")
|
||||
return
|
||||
end
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
shared.Whoer = {}
|
||||
function shared.Whoer.Init()
|
||||
-- if not Heimdall_Data.config.who.enabled then
|
||||
-- print("Heimdall - Whoer disabled")
|
||||
-- return
|
||||
-- end
|
||||
|
||||
if not Heimdall_Data.who then Heimdall_Data.who = {} end
|
||||
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
|
||||
@@ -51,13 +52,13 @@ function data.Whoer.Init()
|
||||
---@return string
|
||||
ToString = function(self)
|
||||
local out = string.format("%s %s %s\nFirst: %s Last: %s Seen: %3d",
|
||||
data.padString(self.name, 16, true),
|
||||
data.padString(self.guild, 26, false),
|
||||
data.padString(self.zone, 26, false),
|
||||
data.padString(self.firstSeen, 10, true),
|
||||
data.padString(self.lastSeen, 10, true),
|
||||
shared.padString(self.name, 16, true),
|
||||
shared.padString(self.guild, 26, false),
|
||||
shared.padString(self.zone, 26, false),
|
||||
shared.padString(self.firstSeen, 10, true),
|
||||
shared.padString(self.lastSeen, 10, true),
|
||||
self.seenCount)
|
||||
return string.format("|cFF%s%s|r", data.classColors[self.class], out)
|
||||
return string.format("|cFF%s%s|r", shared.classColors[self.class], out)
|
||||
end,
|
||||
---@return string
|
||||
NotifyMessage = function(self)
|
||||
@@ -67,7 +68,7 @@ function data.Whoer.Init()
|
||||
self.stinky and "(!!!!)" or "",
|
||||
self.class,
|
||||
self.race,
|
||||
tostring(data.raceMap[self.race]),
|
||||
tostring(shared.raceMap[self.race]),
|
||||
self.guild,
|
||||
self.zone,
|
||||
self.firstSeen,
|
||||
@@ -104,17 +105,13 @@ function data.Whoer.Init()
|
||||
end
|
||||
---@type WHOFilter
|
||||
local AllianceFilter = function(name, guild, level, race, class, zone)
|
||||
if not race then
|
||||
return false
|
||||
end
|
||||
if not data.raceMap[race] then
|
||||
return false
|
||||
end
|
||||
return data.raceMap[race] == "Alliance"
|
||||
if not race then return false end
|
||||
if not shared.raceMap[race] then return false end
|
||||
return shared.raceMap[race] == "Alliance"
|
||||
end
|
||||
|
||||
local whoQueryIdx = 1
|
||||
---@type table<number, WHOQuery>
|
||||
---@type WHOQuery[]
|
||||
local whoQueries = {
|
||||
WHOQuery.new("g-\"БеспредеЛ\"", {}),
|
||||
WHOQuery.new(
|
||||
@@ -139,8 +136,9 @@ function data.Whoer.Init()
|
||||
---@param player Player
|
||||
---@return string?
|
||||
local function Notify(player)
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
|
||||
if not data.config.who.zoneNotifyFor[player.zone] then
|
||||
if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||
return string.format("Not notifying for zone %s",
|
||||
tostring(player.zone))
|
||||
end
|
||||
@@ -149,20 +147,20 @@ function data.Whoer.Init()
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = data.config.who.notifyChannel,
|
||||
data = Heimdall_Data.config.who.notifyChannel,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
|
||||
if data.config.who.doWhisper then
|
||||
for _, name in pairs(data.config.whisperNotify) do
|
||||
if Heimdall_Data.config.who.doWhisper then
|
||||
for _, name in pairs(Heimdall_Data.config.whisperNotify) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = name,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -172,36 +170,37 @@ function data.Whoer.Init()
|
||||
---@param zone string
|
||||
---@return string?
|
||||
local function NotifyZoneChanged(player, zone)
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
|
||||
if not data.config.who.zoneNotifyFor[zone]
|
||||
and not data.config.who.zoneNotifyFor[player.zone] then
|
||||
if not Heimdall_Data.config.who.zoneNotifyFor[zone]
|
||||
and not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||
return string.format("Not notifying for zones %s and %s", tostring(zone), tostring(player.zone))
|
||||
end
|
||||
local text = string.format("%s of class %s (%s - %s) and guild %s moved to %s",
|
||||
player.name,
|
||||
player.class,
|
||||
player.race,
|
||||
data.raceMap[player.race] or "Unknown",
|
||||
shared.raceMap[player.race] or "Unknown",
|
||||
player.guild,
|
||||
zone)
|
||||
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = data.config.who.notifyChannel,
|
||||
data = Heimdall_Data.config.who.notifyChannel,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
|
||||
if data.config.who.doWhisper then
|
||||
for _, name in pairs(data.config.whisperNotify) do
|
||||
if Heimdall_Data.config.who.doWhisper then
|
||||
for _, name in pairs(Heimdall_Data.config.whisperNotify) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = name,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -210,8 +209,9 @@ function data.Whoer.Init()
|
||||
---@param player Player
|
||||
---@return string?
|
||||
local function NotifyGone(player)
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
if not player then return string.format("Cannot notify for nil player %s", tostring(player)) end
|
||||
if not data.config.who.zoneNotifyFor[player.zone] then
|
||||
if not Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||
return string.format("Not notifying for zone %s",
|
||||
tostring(player.zone))
|
||||
end
|
||||
@@ -225,20 +225,20 @@ function data.Whoer.Init()
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "CHANNEL",
|
||||
data = data.config.who.notifyChannel,
|
||||
data = Heimdall_Data.config.who.notifyChannel,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
|
||||
if data.config.who.doWhisper then
|
||||
for _, name in pairs(data.config.whisperNotify) do
|
||||
if Heimdall_Data.config.who.doWhisper then
|
||||
for _, name in pairs(Heimdall_Data.config.whisperNotify) do
|
||||
---@type Message
|
||||
local msg = {
|
||||
channel = "WHISPER",
|
||||
data = name,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -248,6 +248,7 @@ function data.Whoer.Init()
|
||||
local frame = CreateFrame("Frame")
|
||||
frame:RegisterEvent("WHO_LIST_UPDATE")
|
||||
frame:SetScript("OnEvent", function(self, event, ...)
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
---@type WHOQuery?
|
||||
local query = lastQuery
|
||||
if not query then
|
||||
@@ -257,7 +258,7 @@ function data.Whoer.Init()
|
||||
|
||||
for i = 1, GetNumWhoResults() do
|
||||
local name, guild, level, race, class, zone = GetWhoInfo(i)
|
||||
if data.who.ignored[name] then return end
|
||||
if Heimdall_Data.who.ignored[name] then return end
|
||||
local continue = false
|
||||
|
||||
---@type WHOFilter[]
|
||||
@@ -288,7 +289,7 @@ function data.Whoer.Init()
|
||||
player.firstSeen = timestamp
|
||||
end
|
||||
|
||||
local stinky = data.config.stinkies[name]
|
||||
local stinky = Heimdall_Data.config.stinkies[name]
|
||||
if stinky then
|
||||
player.stinky = true
|
||||
PlaySoundFile("Interface\\Sounds\\Domination.ogg", "Master")
|
||||
@@ -327,23 +328,29 @@ function data.Whoer.Init()
|
||||
queryPending = false
|
||||
end)
|
||||
|
||||
if not data.who.updateTicker then
|
||||
data.who.updateTicker = C_Timer.NewTicker(0.5, function()
|
||||
do
|
||||
local function UpdateStinkies()
|
||||
for name, player in pairs(HeimdallStinkies) do
|
||||
if player.lastSeenInternal + data.config.who.ttl < GetTime() then
|
||||
if player.lastSeenInternal + Heimdall_Data.config.who.ttl < GetTime() then
|
||||
NotifyGone(player)
|
||||
--PlaySoundFile("Interface\\Sounds\\Uncloak.ogg", "Master")
|
||||
HeimdallStinkies[name] = nil
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
local function Tick()
|
||||
UpdateStinkies()
|
||||
C_Timer.NewTimer(0.5, Tick, 1)
|
||||
end
|
||||
Tick()
|
||||
end
|
||||
|
||||
if not data.who.whoTicker then
|
||||
data.who.whoTicker = C_Timer.NewTicker(1, function()
|
||||
do
|
||||
local function DoQuery()
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
if queryPending then
|
||||
print("Tried running a who query while one is already pending, previous query:")
|
||||
data.dumpTable(lastQuery)
|
||||
shared.dumpTable(lastQuery)
|
||||
return
|
||||
end
|
||||
queryPending = true
|
||||
@@ -357,12 +364,18 @@ function data.Whoer.Init()
|
||||
--print(string.format("Running who query: %s", tostring(query.query)))
|
||||
SetWhoToUI(1)
|
||||
SendWho(query.query)
|
||||
end)
|
||||
end
|
||||
local function Tick()
|
||||
DoQuery()
|
||||
C_Timer.NewTimer(1, Tick, 1)
|
||||
end
|
||||
Tick()
|
||||
end
|
||||
|
||||
local whoQueryWhisperFrame = CreateFrame("Frame")
|
||||
whoQueryWhisperFrame:RegisterEvent("CHAT_MSG_WHISPER")
|
||||
whoQueryWhisperFrame:SetScript("OnEvent", function(self, event, msg, sender)
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
if msg == "who" then
|
||||
for _, player in pairs(HeimdallStinkies) do
|
||||
local text = player:NotifyMessage()
|
||||
@@ -372,7 +385,7 @@ function data.Whoer.Init()
|
||||
data = sender,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -380,6 +393,7 @@ function data.Whoer.Init()
|
||||
local whoQueryChannelFrame = CreateFrame("Frame")
|
||||
whoQueryChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||
whoQueryChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||
if not Heimdall_Data.config.who.enabled then return end
|
||||
local channelId = select(6, ...)
|
||||
local channelname = ""
|
||||
---@type any[]
|
||||
@@ -394,9 +408,7 @@ function data.Whoer.Init()
|
||||
end
|
||||
end
|
||||
|
||||
if channelname ~= data.config.who.notifyChannel then
|
||||
return
|
||||
end
|
||||
if channelname ~= Heimdall_Data.config.who.notifyChannel then return end
|
||||
|
||||
if msg == "who" then
|
||||
for _, player in pairs(HeimdallStinkies) do
|
||||
@@ -407,7 +419,7 @@ function data.Whoer.Init()
|
||||
data = channelname,
|
||||
message = text
|
||||
}
|
||||
table.insert(data.messenger.queue, msg)
|
||||
table.insert(shared.messenger.queue, msg)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
Reference in New Issue
Block a user