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