Files
wow_channeler/Channeler.lua

223 lines
6.7 KiB
Lua

---@class Channel
---@field name string
---@field password string|nil
local debug = false
---@type Channel[]
local ourchannels = {
{ name = "Horde", password = "durotaner" },
{ name = "world_ru", password = nil },
{ name = "Agent", password = "agents42" },
{ name = "AgentRU", password = "42agents" },
{ name = "EssenceAgent", 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(channels)
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)
---@type Frame
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 Privjet(channelname)
local channels = { GetChannelList() }
for i = 1, #channels, 2 do
local id = channels[i]
local name = channels[i + 1]
if name == channelname then
SendChatMessage("Zdravstvuyte ljudi!", "CHANNEL", nil, id)
return
end
end
end
local function Configure()
JoinChannels(ourchannels)
FindOrCreateChatFrame("Auto", subscribedMessageGroups, subscribedChannels)
FindOrCreateChatFrame("world_ru", {}, { "world_ru" })
FindOrCreateChatFrame("AgentRU", {}, { "AgentRU" })
C_Timer.After(1, function() Privjet("Agent") end)
for i = 1, NUM_CHAT_WINDOWS do
SetChatWindowSize(i, 14)
end
end
local function ConfigureColor()
print("[Channeler] Configuring colors")
local firstChatTab = _G["ChatFrame1Tab"]
if firstChatTab == nil then
print("[Channeler] ChatFrame1Tab is nil")
return
end
firstChatTab:Click("RightButton")
local ok = false
for i = 1, 10 do
local dropdownButton = _G["DropDownList1Button" .. i]
if dropdownButton ~= nil and dropdownButton:GetText() == "Settings" then
print(string.format("[Channeler] Clicking on %s", dropdownButton:GetText()))
dropdownButton:Click()
ok = true
break
end
end
if not ok then
print("[Channeler] Settings button not found")
return
end
local firstConfig = _G["ChatConfigCategoryFrameButton1"]
if firstConfig == nil then
print("[Channeler] First config button not found")
return
end
print(string.format("[Channeler] Clicking on %s", firstConfig:GetText()))
firstConfig:Click()
for i = 1, 16 do
local buttonName = string.format("ChatConfigChatSettingsLeftCheckBox%dColorClasses", i)
local classColorButton = _G[buttonName]
if classColorButton ~= nil and classColorButton:GetChecked() == false then
print(string.format("[Channeler] Clicking on %s", buttonName))
classColorButton:Click()
end
end
local secondConfig = _G["ChatConfigCategoryFrameButton3"]
if secondConfig == nil then
print("[Channeler] Second config button not found")
return
end
print(string.format("[Channeler] Clicking on %s", secondConfig:GetText()))
secondConfig:Click()
for i = 1, 16 do
local buttonName = string.format("ChatConfigChannelSettingsLeftCheckBox%dColorClasses", i)
local classColorButton = _G[buttonName]
if classColorButton ~= nil and classColorButton:GetChecked() == false then
print(string.format("[Channeler] Clicking on %s", buttonName))
classColorButton:Click()
end
end
local okButton = _G["ChatConfigFrameOkayButton"]
if okButton == nil then
print("[Channeler] Ok button not found")
return
end
print(string.format("[Channeler] Clicking on %s", okButton:GetText()))
okButton:Click()
print("[Channeler] Colors configured")
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"
-- /run SlashCmdList["CHANNELER_COLORS"]()
SlashCmdList["CHANNELER_COLORS"] = function(msg) ConfigureColor() end
SLASH_CHANNELER1 = "/fixcolors"
SLASH_CHANNELER2 = "/fc"