Files
wow-weakauras/FreshShit/Spotter/init.lua
2024-11-28 20:07:59 +01:00

93 lines
2.5 KiB
Lua

local channelId = nil
---@class Message
---@field message string
---@field channel string
---@field data string
---@type Message[]
aura_env.messageQueue = {}
---@type table<string, string>
aura_env.raceMap = {
["Orc"] = "Horde",
["Undead"] = "Horde",
["Tauren"] = "Horde",
["Troll"] = "Horde",
["Blood Elf"] = "Horde",
["Goblin"] = "Horde",
["Human"] = "Alliance",
["Dwarf"] = "Alliance",
["Night Elf"] = "Alliance",
["Gnome"] = "Alliance",
["Draenei"] = "Alliance",
["Worgen"] = "Alliance",
["Vulpera"] = "Horde",
["Nightborne"] = "Horde",
["Zandalari Troll"] = "Horde",
["Kul Tiran"] = "Alliance",
["Dark Iron Dwarf"] = "Alliance",
["Void Elf"] = "Alliance",
["Lightforged Draenei"] = "Alliance",
["Mechagnome"] = "Alliance",
["Mag'har Orc"] = "Horde"
}
-- CHANNEL fuckery
local channel = aura_env.config.channel or "foobar"
local password = aura_env.config.channelPassword
local function FindOrJoinChannel(channelName, password)
local function GetChannelId(channelName)
local channels = {GetChannelList()}
for i = 1, #channels, 2 do
local id = channels[i]
local name = channels[i + 1]
if name == channelName then
return id
end
end
end
channelId = GetChannelId(channelName)
if not channelId then
print(string.format("channel %s not found, joining", channelName))
if password then
JoinPermanentChannel(channelName, password)
else
JoinPermanentChannel(channelName)
end
end
channelId = GetChannelId(channelName)
return channelId
end
channelId = FindOrJoinChannel(channel, password)
print(string.format("channel %s resolved to id %d", channel, channelId))
local zone = aura_env.config.zone
local throttleTimer = aura_env.config.throttle or 10
local throttleMap = {}
---@param playerName string
---@param race string
---@return nil
aura_env.NotifySpotted = function(playerName, race)
local now = GetTime()
local throttleTime = throttleMap[playerName] or 0
if now - throttleTime < throttleTimer then
return
end
throttleMap[playerName] = now
local zone = aura_env.config.zone
if not zone then
zone = GetZoneText() .. " " .. GetSubZoneText()
end
local message = {
channel = "CHANNEL",
data = channelId,
message = string.format("I see %s at %s!", playerName, zone)
}
table.insert(WeakAurasSaved.Cyka.MessageQueue, message)
end