Files
wow_channeler/Channeler.lua
2024-12-27 16:42:27 +01:00

133 lines
3.9 KiB
Lua

---@class Channel
---@field name string
---@field password string|nil
local debug = false
---@type Channel[]
local channels = {
{ name = "Horde", password = "garrosh" },
{ name = "world_ru", password = nil }
}
---@type string
---@type string[]
local subscribedMessageGroups = {
"SAY",
"YELL",
"EMOTE",
"PARTY",
"PARTY_LEADER",
"RAID",
"RAID_LEADER",
"RAID_WARNING",
"BATTLEGROUND",
"BATTLEGROUND_LEADER",
"INSTANCE_CHAT",
"INSTANCE_CHAT_LEADER",
"WHISPER"
}
---@type string[]
local subscribedChannels = {
"Agent",
"Horde",
"Foobar"
}
local function JoinChannels()
for _, channel in ipairs(channels) do
if channel.password then
JoinPermanentChannel(channel.name, channel.password)
else
JoinPermanentChannel(channel.name)
end
end
end
---@param chatFrameName string
---@param groups string[]
---@param channels string[]
local function FindOrCreateChatFrame(chatFrameName, groups, channels)
local chatFrame = nil
if debug then print(string.format("Searching for chat window %s", chatFrameName)) end
for i = 1, NUM_CHAT_WINDOWS do
local name = GetChatWindowInfo(i)
if name == chatFrameName then
if debug then print(string.format("Found chat window %s", chatFrameName)) end
local frame = _G["ChatFrame" .. i]
if FCF_IsValidChatFrame(frame) then
if debug then print(string.format("Frame %s is valid", chatFrameName)) end
chatFrame = frame
else
if debug then print(string.format("Frame %s is invalid", chatFrameName)) end
end
end
end
if not chatFrame then
if debug then print(string.format("Creating new chat window %s", chatFrameName)) end
FCF_OpenNewWindow(chatFrameName)
for i = 1, NUM_CHAT_WINDOWS do
local name = GetChatWindowInfo(i)
if name == chatFrameName then
if debug then print(string.format("Found chat window %s", chatFrameName)) end
local frame = _G["ChatFrame" .. i]
if FCF_IsValidChatFrame(frame) then
if debug then print(string.format("Frame %s is valid", chatFrameName)) end
chatFrame = frame
else
if debug then print(string.format("Frame %s is invalid", chatFrameName)) end
end
end
end
end
if debug then print(string.format("Removing all message groups to %s", chatFrameName)) end
ChatFrame_RemoveAllMessageGroups(chatFrame)
if debug then print(string.format("Removing all channels to %s", chatFrameName)) end
ChatFrame_RemoveAllChannels(chatFrame)
if debug then print(string.format("Adding message groups to %s", chatFrameName)) end
for _, messageGroup in ipairs(groups) do
if debug then print(string.format("Adding message group: %s to %s", messageGroup, chatFrameName)) end
ChatFrame_AddMessageGroup(chatFrame, strtrim(messageGroup))
ChatFrame_RemoveMessageGroup(ChatFrame1, strtrim(messageGroup))
end
if debug then print(string.format("Adding channels to %s", chatFrameName)) end
for _, channel in ipairs(channels) do
if debug then print(string.format("Adding channel: %s to %s", channel, chatFrameName)) end
ChatFrame_AddChannel(chatFrame, strtrim(channel))
ChatFrame_RemoveChannel(ChatFrame1, strtrim(channel))
end
if debug then print(string.format("Chat window %s configured", chatFrameName)) end
return chatFrame
end
local function Configure()
JoinChannels()
FindOrCreateChatFrame("Auto", subscribedMessageGroups, subscribedChannels)
--FindOrCreateChatFrame("Horde", {}, { "Horde" })
--FindOrCreateChatFrame("world_ru", {}, { "world_ru" })
--FindOrCreateChatFrame("Agent", {}, { "Agent" })
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, ...)
Configure()
C_Timer.After(1, function()
Configure()
end)
end)
--Configure()
SlashCmdList["CHANNELER"] = function(msg)
Configure()
end
SLASH_CHANNELER1 = "/fix"
SLASH_CHANNELER2 = "/f"