whosniffer Notify on detection

This commit is contained in:
2024-10-18 17:18:08 +02:00
parent ca1f3ac546
commit 863eebdcaf
3 changed files with 77 additions and 25 deletions

View File

@@ -18,6 +18,7 @@ function()
["zone"] = zone,
}
PlaySoundFile("Interface\\Sounds\\Cloak.ogg", "Master")
aura_env.Notify(player)
end
player:Touch()
player.zone = zone

View File

@@ -0,0 +1,9 @@
-- TICKER_200
function()
---@type WHOMessage
local message = aura_env.messageQueue[1]
if message == nil then return end
table.remove(aura_env.messageQueue, 1)
SendChatMessage(message.message, "WHISPER", nil, message.to)
end

View File

@@ -7,30 +7,36 @@ if not WeakAurasSaved.Cyka.WhoSniffer then WeakAurasSaved.Cyka.WhoSniffer = {} e
---@field classColors table<string, string>
---@field whoQuery string
---@field ttl number
---@field messageQueue WHOMessage[]
---@field UpdateMacro fun()
---@field Notify fun(string)
---@class WHOMessage
---@field message string
---@field to string
---@param input string
---@return number
local function utf8len(input)
local len = 0
local i = 1
local n = #input
while i <= n do
local c = input:byte(i)
if c >= 0 and c <= 127 then
i = i + 1
elseif c >= 194 and c <= 223 then
i = i + 2
elseif c >= 224 and c <= 239 then
i = i + 3
elseif c >= 240 and c <= 244 then
i = i + 4
else
i = i + 1
end
len = len + 1
end
return len
local len = 0
local i = 1
local n = #input
while i <= n do
local c = input:byte(i)
if c >= 0 and c <= 127 then
i = i + 1
elseif c >= 194 and c <= 223 then
i = i + 2
elseif c >= 224 and c <= 239 then
i = i + 3
elseif c >= 240 and c <= 244 then
i = i + 4
else
i = i + 1
end
len = len + 1
end
return len
end
---@param input string
---@param targetLength number
@@ -38,17 +44,18 @@ end
---@return string
local function padString(input, targetLength, left)
left = left or false
local len = utf8len(input)
if len < targetLength then
local len = utf8len(input)
if len < targetLength then
if left then
input = input .. string.rep(" ", targetLength - len)
else
input = string.rep(" ", targetLength - len) .. input
end
end
return input
end
return input
end
aura_env.messageQueue = {}
aura_env.ttl = 60
aura_env.whoQuery =
"z-\"Orgrimmar\" z-\"Durotar\" 110 r-\"Human\" r-\"Dwarf\" r-\"Night Elf\" r-\"Gnome\" r-\"Draenei\" r-\"Worgen\" r-\"Kul Tiran\" r-\"Dark Iron Dwarf\" r-\"Void Elf\" r-\"Lightforged Draenei\" r-\"Mechagnome\""
@@ -108,7 +115,8 @@ Player = {
self.lastSeen = GetTime()
end,
ToString = function(self)
local out = string.format("%s %s %s", padString(self.name, 16, true), padString(self.guild, 26, false), padString(self.zone, 26, false))
local out = string.format("%s %s %s", padString(self.name, 16, true), padString(self.guild, 26, false),
padString(self.zone, 26, false))
return string.format("|cFF%s%s|r", aura_env.classColors[self.class], out)
end
}
@@ -134,4 +142,38 @@ aura_env.UpdateMacro = function()
table.insert(body, string.format("/tar %s", v.name))
end
EditMacro("tar", nil, nil, string.join("\n", body))
end
end
---@param input string
---@param deliminer string
---@return string[], string|nil
local function StrSplit(input, deliminer)
if not deliminer then return {}, "deliminer is nil" end
if not input then return {}, "input is nil" end
local parts = {}
for part in string.gmatch(input, "([^" .. deliminer .. "]+)") do
table.insert(parts, strtrim(part))
end
return parts, nil
end
---@type string[]
local toNotify = StrSplit(aura_env.config.notify, ",")
for i, part in ipairs(toNotify) do
toNotify[i] = strtrim(part)
end
---@type table<string, boolean>
local notifyFor = {}
local notifyForD = StrSplit(aura_env.config.notifyFor, ",")
for i, part in ipairs(notifyForD) do
notifyFor[part] = true
end
---@param player Player
aura_env.Notify = function(player)
if not notifyFor[player.zone] then return end
local msg = string.format("%s of class %s and guild %s in %s", player.name, player.class, player.guild, player.zone)
for _, rec in ipairs(toNotify) do
table.insert(aura_env.messageQueue, {to = rec, message = msg})
end
end