From 863eebdcaf915afceeed1acaf8f5003d45fc3bdf Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 18 Oct 2024 17:18:08 +0200 Subject: [PATCH] whosniffer Notify on detection --- FreshShit/WhoSniffer/event.lua | 1 + FreshShit/WhoSniffer/event4.lua | 9 ++++ FreshShit/WhoSniffer/init.lua | 92 ++++++++++++++++++++++++--------- 3 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 FreshShit/WhoSniffer/event4.lua diff --git a/FreshShit/WhoSniffer/event.lua b/FreshShit/WhoSniffer/event.lua index 982fff3..3234df9 100644 --- a/FreshShit/WhoSniffer/event.lua +++ b/FreshShit/WhoSniffer/event.lua @@ -18,6 +18,7 @@ function() ["zone"] = zone, } PlaySoundFile("Interface\\Sounds\\Cloak.ogg", "Master") + aura_env.Notify(player) end player:Touch() player.zone = zone diff --git a/FreshShit/WhoSniffer/event4.lua b/FreshShit/WhoSniffer/event4.lua new file mode 100644 index 0000000..ca39d64 --- /dev/null +++ b/FreshShit/WhoSniffer/event4.lua @@ -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 \ No newline at end of file diff --git a/FreshShit/WhoSniffer/init.lua b/FreshShit/WhoSniffer/init.lua index 24fb78d..0f53e25 100644 --- a/FreshShit/WhoSniffer/init.lua +++ b/FreshShit/WhoSniffer/init.lua @@ -7,30 +7,36 @@ if not WeakAurasSaved.Cyka.WhoSniffer then WeakAurasSaved.Cyka.WhoSniffer = {} e ---@field classColors table ---@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 \ No newline at end of file +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 +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