diff --git a/Modules/Spotter.lua b/Modules/Spotter.lua index cd133b7..da7727e 100644 --- a/Modules/Spotter.lua +++ b/Modules/Spotter.lua @@ -136,16 +136,11 @@ function shared.Spotter.Init() local class = UnitClass(unit) if not class then return string.format("Could not find class for unit %s", tostring(unit)) end - local location = Heimdall_Data.config.spotter.zoneOverride - if not location or location == "" then - local zone = GetZoneText() - if not zone then return string.format("Could not find zone for unit %s", tostring(unit)) end - local subzone = GetSubZoneText() - if not subzone then subzone = "" end - if Heimdall_Data.config.spotter.debug then - print(string.format("[%s] Player %s location: %s (%s)", ModuleName, name, zone, subzone)) - end - location = string.format("%s (%s)", zone, subzone) + ---@type string, string + local zone, subzone = GetZoneText() or "Unknown", GetSubZoneText() or "Unknown" + if Heimdall_Data.config.spotter.zoneOverride then + zone = Heimdall_Data.config.spotter.zoneOverride or "" + subzone = "" end local x, y = GetPlayerMapPosition("player") @@ -157,80 +152,38 @@ function shared.Spotter.Init() local stinky = shared.IsStinky(name) or false SetMapToCurrentZone() SetMapByID(GetCurrentMapAreaID()) - local text = string.format(shared.L.en.spotterSpotted, - hostile and shared.L.en.tidbits.hostile or shared.L.en.tidbits.friendly, - name, - class, - stinky and string.format("(%s)", "!!!!") or "", - race, - faction, - pvpOn and shared.L.en.tidbits.pvpOn or shared.L.en.tidbits.pvpOff, - string.gsub(FormatHP(hp), "M", "kk"), - string.gsub(FormatHP(maxHp), "M", "kk"), - location, - tostring(GetCurrentMapAreaID()), - x * 100, y * 100) + local areaId = tostring(GetCurrentMapAreaID()) - if Heimdall_Data.config.spotter.debug then - print(string.format("[%s] Sending notification: %s", ModuleName, text)) - end + for _, channel in pairs(Heimdall_Data.config.spotter.channels) do + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Processing channel: %s", ModuleName, channel)) + end + local locale = shared.GetLocaleForChannel(channel) + local text = string.format(shared._L("spotterSpotted", locale), + hostile and shared._L("hostile", locale) or shared._L("friendly", locale), + name, + shared._L(class, locale), + stinky and string.format("(%s)", "!!!!") or "", + shared._L(race, locale), + shared._L(faction, locale), + pvpOn and shared._L("pvpOn", locale) or shared._L("pvpOff", locale), + string.gsub(FormatHP(hp), "M", "kk"), + string.gsub(FormatHP(maxHp), "M", "kk"), + shared._L(zone, locale), shared._L(subzone, locale), + areaId, + x * 100, y * 100) - ---@type Message - local msg = { - channel = "C", - data = Heimdall_Data.config.spotter.notifyChannel, - message = text - } - table.insert(shared.messenger.queue, msg) - - local ruClass = shared.L.ru.classes[class] - if not ruClass then - print(string.format("[%s] Class %s not found in ru.classes", ModuleName, class)) - end - local ruRace = shared.L.ru.races[race] - if not ruRace then - print(string.format("[%s] Race %s not found in ru.races", ModuleName, race)) - end - local ruFaction = shared.L.ru.factions[faction] - if not ruFaction then - print(string.format("[%s] Faction %s not found in ru.factions", ModuleName, faction)) - end - local zone, subzone = GetZoneText(), GetSubZoneText() - local ruZone = shared.L.ru.zones[zone] - if not ruZone then - print(string.format("[%s] Zone %s not found in ru.zones", ModuleName, zone)) - end - local ruSubzone = shared.L.ru.zones[subzone] - if not ruSubzone then - print(string.format("[%s] Subzone %s not found in ru.zones", ModuleName, subzone)) - end - - text = string.format(shared.L.ru.spotterSpotted, - hostile and shared.L.ru.tidbits.hostile or shared.L.ru.tidbits.friendly, - name, - ruClass or class, - stinky and string.format("(%s)", "!!!!") or "", - ruRace or race, - ruFaction or faction, - pvpOn and shared.L.ru.tidbits.pvpOn or shared.L.ru.tidbits.pvpOff, - string.gsub(FormatHP(hp), "M", "kk"), - string.gsub(FormatHP(maxHp), "M", "kk"), - string.format("%s (%s)", ruZone or zone, ruSubzone or subzone), - tostring(GetCurrentMapAreaID()), - x * 100, y * 100) - - if Heimdall_Data.config.spotter.debug then - print(string.format("[%s] Sending notification: %s", ModuleName, text)) - end - - if Heimdall_Data.config.echoToRussian then - -- Russian message - local ruMsg = { + ---@type Message + local msg = { channel = "C", - data = Heimdall_Data.config.spotter.notifyChannel .. "ru", + data = channel, message = text } - table.insert(shared.messenger.queue, ruMsg) + if Heimdall_Data.config.spotter.debug then + print(string.format("[%s] Queuing spotter message", ModuleName)) + shared.dumpTable(msg) + end + table.insert(shared.messenger.queue, msg) end end