Rework addon loading to properly load on ADDON_LOADED
insteaad of immediately
This commit is contained in:
8
DeathReporter.lua
Normal file
8
DeathReporter.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
local addonname, data = ...
|
||||||
|
---@cast data HeimdallData
|
||||||
|
---@cast addonname string
|
||||||
|
|
||||||
|
data.DeathReporter = {}
|
||||||
|
function data.DeathReporter.Init()
|
||||||
|
end
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
local _, data = ...
|
local addonname, data = ...
|
||||||
---@cast data HeimdallData
|
---@cast data HeimdallData
|
||||||
|
---@cast addonname string
|
||||||
|
|
||||||
if not data.dumpTable then
|
if not data.dumpTable then
|
||||||
---@param table table
|
---@param table table
|
||||||
|
|||||||
239
Heimdall.lua
239
Heimdall.lua
@@ -1,118 +1,152 @@
|
|||||||
local _, data = ...
|
local addonname, data = ...
|
||||||
---@cast data HeimdallData
|
---@cast data HeimdallData
|
||||||
|
---@cast addonname string
|
||||||
|
|
||||||
---@class Heimdall_Data
|
local function init()
|
||||||
---@field who { data: table<string, Player> }
|
---@class Heimdall_Data
|
||||||
if not Heimdall_Data then Heimdall_Data = {} end
|
---@field who { data: table<string, Player> }
|
||||||
|
if not Heimdall_Data then Heimdall_Data = {} end
|
||||||
|
if not Heimdall_Data.config then Heimdall_Data.config = {} end
|
||||||
|
|
||||||
-- We don't care about these persisting
|
-- We don't care about these persisting
|
||||||
-- Actually we don't want some of them to persist
|
-- Actually we don't want some of them to persist
|
||||||
-- For those we DO we use (global) Heimdall_Data
|
-- For those we DO we use (global) Heimdall_Data
|
||||||
|
|
||||||
---@class HeimdallData
|
---@class HeimdallData
|
||||||
---@field config HeimdallConfig
|
---@field config HeimdallConfig
|
||||||
---@field raceMap table<string, string>
|
---@field raceMap table<string, string>
|
||||||
---@field classColors table<string, string>
|
---@field classColors table<string, string>
|
||||||
---@field stinkies table<string, Player>
|
---@field stinkies table<string, Player>
|
||||||
---@field messenger HeimdallMessengerData
|
---@field messenger HeimdallMessengerData
|
||||||
---@field who HeimdallWhoData
|
---@field who HeimdallWhoData
|
||||||
---@field dumpTable fun(table: any, depth?: number): nil
|
---@field dumpTable fun(table: any, depth?: number): nil
|
||||||
---@field utf8len fun(input: string): number
|
---@field utf8len fun(input: string): number
|
||||||
---@field padString fun(input: string, targetLength: number, left?: boolean): string
|
---@field padString fun(input: string, targetLength: number, left?: boolean): string
|
||||||
|
---@field GetOrDefault fun(table: table<any, any>, keys: string[], default: any): any
|
||||||
|
---@field Whoer { Init: fun() }
|
||||||
|
---@field Messenger { Init: fun() }
|
||||||
|
---@field Spotter { Init: fun() }
|
||||||
|
---@field DeathReporter { Init: fun() }
|
||||||
|
|
||||||
--- Config ---
|
--- Config ---
|
||||||
---@class HeimdallConfig
|
---@class HeimdallConfig
|
||||||
---@field spotter HeimdallSpotterConfig
|
---@field spotter HeimdallSpotterConfig
|
||||||
---@field who HeimdallWhoConfig
|
---@field who HeimdallWhoConfig
|
||||||
---@field messenger HeimdallMessengerConfig
|
---@field messenger HeimdallMessengerConfig
|
||||||
---@field whisperNotify table<string, string>
|
---@field whisperNotify table<string, string>
|
||||||
|
|
||||||
---@class HeimdallSpotterConfig
|
---@class HeimdallSpotterConfig
|
||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
---@field everyone boolean
|
---@field everyone boolean
|
||||||
---@field hostile boolean
|
---@field hostile boolean
|
||||||
---@field alliance boolean
|
---@field alliance boolean
|
||||||
---@field stinky boolean
|
---@field stinky boolean
|
||||||
---@field notifyChannel string
|
---@field notifyChannel string
|
||||||
---@field zoneOverride string?
|
---@field zoneOverride string?
|
||||||
---@field throttleTime number
|
---@field throttleTime number
|
||||||
|
|
||||||
---@class HeimdallWhoConfig
|
---@class HeimdallWhoConfig
|
||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
---@field ignored table<string, boolean>
|
---@field ignored table<string, boolean>
|
||||||
---@field notifyChannel string
|
---@field notifyChannel string
|
||||||
---@field ttl number
|
---@field ttl number
|
||||||
---@field doWhisper boolean
|
---@field doWhisper boolean
|
||||||
---@field zoneNotifyFor table<string, boolean>
|
---@field zoneNotifyFor table<string, boolean>
|
||||||
|
|
||||||
---@class HeimdallMessengerConfig
|
---@class HeimdallMessengerConfig
|
||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
|
|
||||||
--- Data ---
|
--- Data ---
|
||||||
---@class HeimdallMessengerData
|
---@class HeimdallMessengerData
|
||||||
---@field queue table<string, Message>
|
---@field queue table<string, Message>
|
||||||
---@field ticker number?
|
---@field ticker number?
|
||||||
|
|
||||||
---@class HeimdallWhoData
|
---@class HeimdallWhoData
|
||||||
---@field updateTicker number?
|
---@field updateTicker number?
|
||||||
---@field whoTicker number?
|
---@field whoTicker number?
|
||||||
---@field ignored table<string, boolean>
|
---@field ignored table<string, boolean>
|
||||||
|
|
||||||
data.messenger = {
|
data.GetOrDefault = function(table, keys, default)
|
||||||
|
local value = default
|
||||||
|
if not table then return value end
|
||||||
|
if not keys then return value end
|
||||||
|
|
||||||
|
local traverse = table
|
||||||
|
for i = 1, #keys do
|
||||||
|
local key = keys[i]
|
||||||
|
if traverse[key] then
|
||||||
|
traverse = traverse[key]
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
if i == #keys then
|
||||||
|
value = traverse
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
|
data.messenger = {
|
||||||
queue = {}
|
queue = {}
|
||||||
}
|
}
|
||||||
data.who = {
|
data.who = {
|
||||||
ignored = {},
|
ignored = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
data.config = {
|
data.config = {
|
||||||
spotter = {
|
spotter = {
|
||||||
enabled = true,
|
enabled = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "enabled" }, true),
|
||||||
everyone = false,
|
everyone = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "everyone" }, false),
|
||||||
hostile = true,
|
hostile = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "hostile" }, true),
|
||||||
alliance = false,
|
alliance = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "alliance" }, false),
|
||||||
stinky = false,
|
stinky = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "stinky" }, false),
|
||||||
notifyChannel = "Foobar",
|
notifyChannel = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "notifyChannel" }, "Foobar"),
|
||||||
zoneOverride = nil,
|
zoneOverride = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "zoneOverride" }, nil),
|
||||||
throttleTime = 1
|
throttleTime = data.GetOrDefault(Heimdall_Data, { "config", "spotter", "throttleTime" }, 1)
|
||||||
},
|
},
|
||||||
who = {
|
who = {
|
||||||
enabled = true,
|
enabled = data.GetOrDefault(Heimdall_Data, { "config", "who", "enabled" }, true),
|
||||||
ignored = {},
|
ignored = data.GetOrDefault(Heimdall_Data, { "config", "who", "ignored" }, {}),
|
||||||
notifyChannel = "Foobar",
|
notifyChannel = data.GetOrDefault(Heimdall_Data, { "config", "who", "notifyChannel" }, "Foobar"),
|
||||||
ttl = 10,
|
ttl = data.GetOrDefault(Heimdall_Data, { "config", "who", "ttl" }, 10),
|
||||||
doWhisper = true,
|
doWhisper = data.GetOrDefault(Heimdall_Data, { "config", "who", "doWhisper" }, true),
|
||||||
zoneNotifyFor = {
|
zoneNotifyFor = data.GetOrDefault(Heimdall_Data, { "config", "who", "zoneNotifyFor" }, {
|
||||||
["Orgrimmar"] = true,
|
["Orgrimmar"] = true,
|
||||||
["Thunder Bluff"] = true,
|
["Thunder Bluff"] = true,
|
||||||
["Undercity"] = true,
|
["Undercity"] = true,
|
||||||
["Durotar"] = true,
|
["Durotar"] = true,
|
||||||
["Echo Isles"] = true,
|
["Echo Isles"] = true,
|
||||||
["Valley of Trials"] = true,
|
["Valley of Trials"] = true,
|
||||||
}
|
}),
|
||||||
},
|
},
|
||||||
messenger = {
|
messenger = {
|
||||||
enabled = true
|
enabled = data.GetOrDefault(Heimdall_Data, { "config", "messenger", "enabled" }, true),
|
||||||
},
|
},
|
||||||
whisperNotify = {
|
whisperNotify = data.GetOrDefault(Heimdall_Data, { "config", "whisperNotify" }, {
|
||||||
"Extazyk",
|
-- "Extazyk",
|
||||||
"Smokefire",
|
-- "Smokefire",
|
||||||
"Smokemantra",
|
-- "Smokemantra",
|
||||||
"Хихихантер",
|
-- "Хихихантер",
|
||||||
"Муркот",
|
-- "Муркот",
|
||||||
"Растафаркрай",
|
-- "Растафаркрай",
|
||||||
"Frosstmorn",
|
-- "Frosstmorn",
|
||||||
"Pulsjkee",
|
-- "Pulsjkee",
|
||||||
"Paskoo",
|
-- "Paskoo",
|
||||||
"Totleta",
|
"Totleta",
|
||||||
"Healleta",
|
"Healleta",
|
||||||
"Deathleta",
|
"Deathleta",
|
||||||
"Shootleta",
|
"Shootleta",
|
||||||
"Stableta"
|
"Stableta"
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
--/run Heimdall_Data = {config = {who = {enabled = false}}}
|
||||||
|
--/dump Heimdall_Data
|
||||||
|
print("138 " .. tostring(Heimdall_Data.config.who.enabled))
|
||||||
|
print("139 " .. tostring(data.GetOrDefault(Heimdall_Data, { "config", "who", "enabled" }, true)))
|
||||||
|
print("140 " .. tostring(data.config.who.enabled))
|
||||||
|
|
||||||
data.raceMap = {
|
data.raceMap = {
|
||||||
["Orc"] = "Horde",
|
["Orc"] = "Horde",
|
||||||
["Undead"] = "Horde",
|
["Undead"] = "Horde",
|
||||||
["Tauren"] = "Horde",
|
["Tauren"] = "Horde",
|
||||||
@@ -134,10 +168,9 @@ data.raceMap = {
|
|||||||
["Lightforged Draenei"] = "Alliance",
|
["Lightforged Draenei"] = "Alliance",
|
||||||
["Mechagnome"] = "Alliance",
|
["Mechagnome"] = "Alliance",
|
||||||
["Mag'har Orc"] = "Horde"
|
["Mag'har Orc"] = "Horde"
|
||||||
}
|
}
|
||||||
|
|
||||||
---@type table<string, string>
|
data.classColors = {
|
||||||
data.classColors = {
|
|
||||||
["Warrior"] = "C69B6D",
|
["Warrior"] = "C69B6D",
|
||||||
["Paladin"] = "F48CBA",
|
["Paladin"] = "F48CBA",
|
||||||
["Hunter"] = "AAD372",
|
["Hunter"] = "AAD372",
|
||||||
@@ -150,13 +183,13 @@ data.classColors = {
|
|||||||
["Monk"] = "00FF98",
|
["Monk"] = "00FF98",
|
||||||
["Druid"] = "FF7C0A",
|
["Druid"] = "FF7C0A",
|
||||||
["Demon Hunter"] = "A330C9"
|
["Demon Hunter"] = "A330C9"
|
||||||
}
|
}
|
||||||
|
|
||||||
data.stinkies = {}
|
data.stinkies = {}
|
||||||
|
|
||||||
---@param input string
|
---@param input string
|
||||||
---@return number
|
---@return number
|
||||||
data.utf8len = function(input)
|
data.utf8len = function(input)
|
||||||
if not input then
|
if not input then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
@@ -179,12 +212,12 @@ data.utf8len = function(input)
|
|||||||
len = len + 1
|
len = len + 1
|
||||||
end
|
end
|
||||||
return len
|
return len
|
||||||
end
|
end
|
||||||
---@param input string
|
---@param input string
|
||||||
---@param targetLength number
|
---@param targetLength number
|
||||||
---@param left boolean
|
---@param left boolean
|
||||||
---@return string
|
---@return string
|
||||||
data.padString = function(input, targetLength, left)
|
data.padString = function(input, targetLength, left)
|
||||||
left = left or false
|
left = left or false
|
||||||
local len = data.utf8len(input)
|
local len = data.utf8len(input)
|
||||||
if len < targetLength then
|
if len < targetLength then
|
||||||
@@ -195,4 +228,18 @@ data.padString = function(input, targetLength, left)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return input
|
return input
|
||||||
|
end
|
||||||
|
|
||||||
|
data.Whoer.Init()
|
||||||
|
data.Messenger.Init()
|
||||||
|
data.Spotter.Init()
|
||||||
|
data.DeathReporter.Init()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local loadedFrame = CreateFrame("Frame")
|
||||||
|
loadedFrame:RegisterEvent("ADDON_LOADED")
|
||||||
|
loadedFrame:SetScript("OnEvent", function(self, event, addonName)
|
||||||
|
if addonName == addonname then
|
||||||
|
init()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
## SavedVariables: Heimdall_Data
|
## SavedVariables: Heimdall_Data
|
||||||
|
|
||||||
#core
|
#core
|
||||||
Heimdall.lua
|
|
||||||
CLEUParser.lua
|
CLEUParser.lua
|
||||||
|
DumpTable.lua
|
||||||
Spotter.lua
|
Spotter.lua
|
||||||
Whoer.lua
|
Whoer.lua
|
||||||
Messenger.lua
|
Messenger.lua
|
||||||
DumpTable.lua
|
Heimdall.lua
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
local _, data = ...
|
local addonname, data = ...
|
||||||
---@cast data HeimdallData
|
---@cast data HeimdallData
|
||||||
|
---@cast addonname string
|
||||||
|
|
||||||
if not data.config.messenger.enabled then return end
|
data.Messenger = {}
|
||||||
|
function data.Messenger.Init()
|
||||||
|
if not data.config.messenger.enabled then return end
|
||||||
|
|
||||||
---@class Message
|
---@class Message
|
||||||
---@field message string
|
---@field message string
|
||||||
---@field channel string
|
---@field channel string
|
||||||
---@field data string
|
---@field data string
|
||||||
|
|
||||||
---@type table<string, number>
|
---@type table<string, number>
|
||||||
local channelIdMap = {}
|
local channelIdMap = {}
|
||||||
|
|
||||||
local FindOrJoinChannel = function(channelName, password)
|
local FindOrJoinChannel = function(channelName, password)
|
||||||
local function GetChannelId(channelName)
|
local function GetChannelId(channelName)
|
||||||
local channels = { GetChannelList() }
|
local channels = { GetChannelList() }
|
||||||
for i = 1, #channels, 2 do
|
for i = 1, #channels, 2 do
|
||||||
@@ -35,20 +38,20 @@ local FindOrJoinChannel = function(channelName, password)
|
|||||||
channelId = GetChannelId(channelName)
|
channelId = GetChannelId(channelName)
|
||||||
channelIdMap[channelName] = channelId
|
channelIdMap[channelName] = channelId
|
||||||
return channelId
|
return channelId
|
||||||
end
|
end
|
||||||
|
|
||||||
local ScanChannels = function()
|
local ScanChannels = function()
|
||||||
local channels = { GetChannelList() }
|
local channels = { GetChannelList() }
|
||||||
for i = 1, #channels, 2 do
|
for i = 1, #channels, 2 do
|
||||||
local id = channels[i]
|
local id = channels[i]
|
||||||
local name = channels[i + 1]
|
local name = channels[i + 1]
|
||||||
channelIdMap[name] = id
|
channelIdMap[name] = id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not data.messenger then data.messenger = {} end
|
if not data.messenger then data.messenger = {} end
|
||||||
if not data.messenger.queue then data.messenger.queue = {} end
|
if not data.messenger.queue then data.messenger.queue = {} end
|
||||||
if not data.messenger.ticker then
|
if not data.messenger.ticker then
|
||||||
data.messenger.ticker = C_Timer.NewTicker(0.2, function()
|
data.messenger.ticker = C_Timer.NewTicker(0.2, function()
|
||||||
---@type Message
|
---@type Message
|
||||||
local message = data.messenger.queue[1]
|
local message = data.messenger.queue[1]
|
||||||
@@ -79,13 +82,14 @@ if not data.messenger.ticker then
|
|||||||
if not message.data or message.data == "" then return end
|
if not message.data or message.data == "" then return end
|
||||||
SendChatMessage(message.message, message.channel, nil, message.data)
|
SendChatMessage(message.message, message.channel, nil, message.data)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--C_Timer.NewTicker(2, function()
|
--C_Timer.NewTicker(2, function()
|
||||||
-- print("Q")
|
-- print("Q")
|
||||||
-- table.insert(data.messenger.queue, {
|
-- table.insert(data.messenger.queue, {
|
||||||
-- channel = "CHANNEL",
|
-- channel = "CHANNEL",
|
||||||
-- data = "Foobar",
|
-- data = "Foobar",
|
||||||
-- message = "TEST"
|
-- message = "TEST"
|
||||||
-- })
|
-- })
|
||||||
--end)
|
--end)
|
||||||
|
end
|
||||||
|
|||||||
51
Spotter.lua
51
Spotter.lua
@@ -1,9 +1,11 @@
|
|||||||
local _, data = ...
|
local addonname, data = ...
|
||||||
---@cast data HeimdallData
|
---@cast data HeimdallData
|
||||||
|
---@cast addonname string
|
||||||
|
|
||||||
if not data.config.spotter.enabled then return end
|
data.Spotter = {}
|
||||||
|
function data.Spotter.Init()
|
||||||
local function FormatHP(hp)
|
if not data.config.spotter.enabled then return end
|
||||||
|
local function FormatHP(hp)
|
||||||
if hp > 1e9 then
|
if hp > 1e9 then
|
||||||
return string.format("%.1fB", hp / 1e9)
|
return string.format("%.1fB", hp / 1e9)
|
||||||
elseif hp > 1e6 then
|
elseif hp > 1e6 then
|
||||||
@@ -13,18 +15,18 @@ local function FormatHP(hp)
|
|||||||
else
|
else
|
||||||
return hp
|
return hp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type table<string, number>
|
---@type table<string, number>
|
||||||
local throttleTable = {}
|
local throttleTable = {}
|
||||||
|
|
||||||
---@param unit string
|
---@param unit string
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param faction string
|
---@param faction string
|
||||||
---@param hostile boolean
|
---@param hostile boolean
|
||||||
---@return boolean
|
---@return boolean
|
||||||
---@return string? error
|
---@return string? error
|
||||||
local function ShouldNotify(unit, name, faction, hostile)
|
local function ShouldNotify(unit, name, faction, hostile)
|
||||||
if data.config.spotter.stinky then
|
if data.config.spotter.stinky then
|
||||||
if data.stinkies[name] then return true end
|
if data.stinkies[name] then return true end
|
||||||
end
|
end
|
||||||
@@ -35,11 +37,11 @@ local function ShouldNotify(unit, name, faction, hostile)
|
|||||||
if hostile then return true end
|
if hostile then return true end
|
||||||
end
|
end
|
||||||
return data.config.spotter.everyone
|
return data.config.spotter.everyone
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param unit string
|
---@param unit string
|
||||||
---@return string?
|
---@return string?
|
||||||
local function NotifySpotted(unit)
|
local function NotifySpotted(unit)
|
||||||
if not unit then return string.format("Could not find unit %s", tostring(unit)) end
|
if not unit then return string.format("Could not find unit %s", tostring(unit)) end
|
||||||
if not UnitIsPlayer(unit) then return nil end
|
if not UnitIsPlayer(unit) then return nil end
|
||||||
|
|
||||||
@@ -92,14 +94,15 @@ local function NotifySpotted(unit)
|
|||||||
}
|
}
|
||||||
data.dumpTable(msg)
|
data.dumpTable(msg)
|
||||||
table.insert(data.messenger.queue, msg)
|
table.insert(data.messenger.queue, msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local frame = CreateFrame("Frame")
|
local frame = CreateFrame("Frame")
|
||||||
frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
|
frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
|
||||||
frame:RegisterEvent("TARGET_UNIT_CHANGED")
|
frame:RegisterEvent("TARGET_UNIT_CHANGED")
|
||||||
frame:SetScript("OnEvent", function(self, event, unit)
|
frame:SetScript("OnEvent", function(self, event, unit)
|
||||||
local err = NotifySpotted(unit)
|
local err = NotifySpotted(unit)
|
||||||
if err then
|
if err then
|
||||||
print(string.format("Error notifying %s: %s", tostring(unit), tostring(err)))
|
print(string.format("Error notifying %s: %s", tostring(unit), tostring(err)))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|||||||
144
Whoer.lua
144
Whoer.lua
@@ -1,27 +1,27 @@
|
|||||||
local _, data = ...
|
local addonname, data = ...
|
||||||
---@cast data HeimdallData
|
---@cast data HeimdallData
|
||||||
|
---@cast addonname string
|
||||||
|
|
||||||
if not data.config.who.enabled then return end
|
data.Whoer = {}
|
||||||
if not Heimdall_Data.who then Heimdall_Data.who = {} end
|
function data.Whoer.Init()
|
||||||
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
|
if not data.config.who.enabled then return end
|
||||||
print(Heimdall_Data)
|
if not Heimdall_Data.who then Heimdall_Data.who = {} end
|
||||||
print(Heimdall_Data.who)
|
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
|
||||||
print(Heimdall_Data.who.data)
|
|
||||||
|
|
||||||
---@type table<string, Player>
|
---@type table<string, Player>
|
||||||
local players = {}
|
local players = {}
|
||||||
|
|
||||||
---@class Player
|
---@class Player
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field guild string
|
---@field guild string
|
||||||
---@field race string
|
---@field race string
|
||||||
---@field class string
|
---@field class string
|
||||||
---@field zone string
|
---@field zone string
|
||||||
---@field lastSeenInternal number
|
---@field lastSeenInternal number
|
||||||
---@field lastSeen string
|
---@field lastSeen string
|
||||||
---@field firstSeen string
|
---@field firstSeen string
|
||||||
---@field seenCount number
|
---@field seenCount number
|
||||||
Player = {
|
Player = {
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param guild string
|
---@param guild string
|
||||||
---@param race string
|
---@param race string
|
||||||
@@ -56,7 +56,8 @@ Player = {
|
|||||||
end,
|
end,
|
||||||
---@return string
|
---@return string
|
||||||
NotifyMessage = function(self)
|
NotifyMessage = function(self)
|
||||||
local text = string.format("%s of class %s and guild %s in %s, first seen: %s, last seen: %s, times seen: %d",
|
local text = string.format(
|
||||||
|
"%s of class %s and guild %s in %s, first seen: %s, last seen: %s, times seen: %d",
|
||||||
self.name,
|
self.name,
|
||||||
self.class,
|
self.class,
|
||||||
self.guild,
|
self.guild,
|
||||||
@@ -66,12 +67,12 @@ Player = {
|
|||||||
self.seenCount)
|
self.seenCount)
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
---@class WHOQuery
|
---@class WHOQuery
|
||||||
---@field query string
|
---@field query string
|
||||||
---@field filters WHOFilter[]
|
---@field filters WHOFilter[]
|
||||||
WHOQuery = {
|
WHOQuery = {
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param filters WHOFilter[]
|
---@param filters WHOFilter[]
|
||||||
---@return WHOQuery
|
---@return WHOQuery
|
||||||
@@ -83,18 +84,18 @@ WHOQuery = {
|
|||||||
self.filters = filters
|
self.filters = filters
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
---@alias WHOFilter fun(name: string, guild: string, level: number, race: string, class: string, zone: string): boolean
|
---@alias WHOFilter fun(name: string, guild: string, level: number, race: string, class: string, zone: string): boolean
|
||||||
---@type WHOFilter
|
---@type WHOFilter
|
||||||
local NotSiegeOfOrgrimmarFilter = function(name, guild, level, race, class, zone)
|
local NotSiegeOfOrgrimmarFilter = function(name, guild, level, race, class, zone)
|
||||||
if not zone then
|
if not zone then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return zone ~= "Siege of Orgrimmar"
|
return zone ~= "Siege of Orgrimmar"
|
||||||
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
|
return false
|
||||||
end
|
end
|
||||||
@@ -102,11 +103,11 @@ local AllianceFilter = function(name, guild, level, race, class, zone)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return data.raceMap[race] == "Alliance"
|
return data.raceMap[race] == "Alliance"
|
||||||
end
|
end
|
||||||
|
|
||||||
local whoQueryIdx = 1
|
local whoQueryIdx = 1
|
||||||
---@type table<number, WHOQuery>
|
---@type table<number, WHOQuery>
|
||||||
local whoQueries = {
|
local whoQueries = {
|
||||||
WHOQuery.new("g-\"БеспредеЛ\"", {}),
|
WHOQuery.new("g-\"БеспредеЛ\"", {}),
|
||||||
WHOQuery.new(
|
WHOQuery.new(
|
||||||
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" z-\"Echo Isles\" r-\"Human\" r-\"Dwarf\" r-\"Night Elf\"",
|
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" z-\"Echo Isles\" r-\"Human\" r-\"Dwarf\" r-\"Night Elf\"",
|
||||||
@@ -121,15 +122,15 @@ local whoQueries = {
|
|||||||
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" z-\"Echo Isles\" r-\"Lightforged Draenei\" r-\"Mechagnome\"",
|
"z-\"Orgrimmar\" z-\"Durotar\" z-\"Valley of Trials\" z-\"Echo Isles\" r-\"Lightforged Draenei\" r-\"Mechagnome\"",
|
||||||
{ NotSiegeOfOrgrimmarFilter, AllianceFilter }),
|
{ NotSiegeOfOrgrimmarFilter, AllianceFilter }),
|
||||||
WHOQuery.new("Kekv Demonboo Dotmada Firobot Verminal", {})
|
WHOQuery.new("Kekv Demonboo Dotmada Firobot Verminal", {})
|
||||||
}
|
}
|
||||||
local queryPending = false
|
local queryPending = false
|
||||||
local ttl = #whoQueries * 2
|
local ttl = #whoQueries * 2
|
||||||
---@type WHOQuery?
|
---@type WHOQuery?
|
||||||
local lastQuery = nil
|
local lastQuery = nil
|
||||||
|
|
||||||
---@param player Player
|
---@param player Player
|
||||||
---@return string?
|
---@return string?
|
||||||
local function Notify(player)
|
local function Notify(player)
|
||||||
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 data.config.who.zoneNotifyFor[player.zone] then
|
||||||
return string.format("Not notifying for zone %s",
|
return string.format("Not notifying for zone %s",
|
||||||
@@ -158,11 +159,11 @@ local function Notify(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
---@param player Player
|
---@param player Player
|
||||||
---@param zone string
|
---@param zone string
|
||||||
---@return string?
|
---@return string?
|
||||||
local function NotifyZoneChanged(player, zone)
|
local function NotifyZoneChanged(player, zone)
|
||||||
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 data.config.who.zoneNotifyFor[zone]
|
||||||
and not data.config.who.zoneNotifyFor[player.zone] then
|
and not data.config.who.zoneNotifyFor[player.zone] then
|
||||||
@@ -195,10 +196,10 @@ local function NotifyZoneChanged(player, zone)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
---@param player Player
|
---@param player Player
|
||||||
---@return string?
|
---@return string?
|
||||||
local function NotifyGone(player)
|
local function NotifyGone(player)
|
||||||
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 data.config.who.zoneNotifyFor[player.zone] then
|
||||||
return string.format("Not notifying for zone %s",
|
return string.format("Not notifying for zone %s",
|
||||||
@@ -232,11 +233,11 @@ local function NotifyGone(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
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, ...)
|
||||||
---@type WHOQuery?
|
---@type WHOQuery?
|
||||||
local query = lastQuery
|
local query = lastQuery
|
||||||
if not query then
|
if not query then
|
||||||
@@ -314,9 +315,9 @@ frame:SetScript("OnEvent", function(self, event, ...)
|
|||||||
_G["FriendsFrameCloseButton"]:Click()
|
_G["FriendsFrameCloseButton"]:Click()
|
||||||
queryPending = false
|
queryPending = false
|
||||||
print(queryPending)
|
print(queryPending)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not data.who.updateTicker then
|
if not data.who.updateTicker then
|
||||||
data.who.updateTicker = C_Timer.NewTicker(0.5, function()
|
data.who.updateTicker = C_Timer.NewTicker(0.5, function()
|
||||||
for name, player in pairs(players) do
|
for name, player in pairs(players) do
|
||||||
if player.lastSeenInternal + data.config.who.ttl < GetTime() then
|
if player.lastSeenInternal + data.config.who.ttl < GetTime() then
|
||||||
@@ -326,9 +327,9 @@ if not data.who.updateTicker then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not data.who.whoTicker then
|
if not data.who.whoTicker then
|
||||||
data.who.whoTicker = C_Timer.NewTicker(1, function()
|
data.who.whoTicker = C_Timer.NewTicker(1, function()
|
||||||
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:")
|
||||||
@@ -347,11 +348,11 @@ if not data.who.whoTicker then
|
|||||||
SetWhoToUI(1)
|
SetWhoToUI(1)
|
||||||
SendWho(query.query)
|
SendWho(query.query)
|
||||||
end)
|
end)
|
||||||
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 msg == "who" then
|
if msg == "who" then
|
||||||
for _, player in pairs(players) do
|
for _, player in pairs(players) do
|
||||||
local text = player:NotifyMessage()
|
local text = player:NotifyMessage()
|
||||||
@@ -364,11 +365,11 @@ whoQueryWhisperFrame:SetScript("OnEvent", function(self, event, msg, sender)
|
|||||||
table.insert(data.messenger.queue, msg)
|
table.insert(data.messenger.queue, msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
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, ...)
|
||||||
local channelId = select(6, ...)
|
local channelId = select(6, ...)
|
||||||
local channelname = ""
|
local channelname = ""
|
||||||
---@type any[]
|
---@type any[]
|
||||||
@@ -399,4 +400,5 @@ whoQueryChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...
|
|||||||
table.insert(data.messenger.queue, msg)
|
table.insert(data.messenger.queue, msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user