60 lines
2.0 KiB
Lua
60 lines
2.0 KiB
Lua
local addonname, shared = ...
|
|
---@cast shared HeimdallShared
|
|
---@cast addonname string
|
|
local ModuleName = "Echoer"
|
|
|
|
---@diagnostic disable-next-line: missing-fields
|
|
shared.Echoer = {}
|
|
function shared.Echoer.Init()
|
|
local frame = CreateFrame("Frame")
|
|
frame:RegisterEvent("CHAT_MSG_CHANNEL")
|
|
frame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
|
--if Heimdall_Data.config.echoer.debug then
|
|
-- print(string.format("[%s] Channel message received from: %s", ModuleName, sender))
|
|
--end
|
|
|
|
if not Heimdall_Data.config.echoer.enabled then
|
|
--if Heimdall_Data.config.echoer.debug then
|
|
-- print(string.format("[%s] Module disabled, ignoring message", ModuleName))
|
|
--end
|
|
return
|
|
end
|
|
|
|
local channelId = select(6, ...)
|
|
local _, channelname = GetChannelName(channelId)
|
|
local ok = false
|
|
for _, channel in pairs(Heimdall_Data.config.echoer.channels) do
|
|
if channel == channelname then
|
|
ok = true
|
|
break
|
|
end
|
|
end
|
|
if not ok then
|
|
if Heimdall_Data.config.echoer.debug then
|
|
print(string.format("[%s] Channel name does not match any of the channels", ModuleName))
|
|
end
|
|
return
|
|
end
|
|
if Heimdall_Data.config.echoer.debug then
|
|
print(string.format("[%s] Processing message from master channel: %s", ModuleName, sender))
|
|
shared.dumpTable(Heimdall_Data.config.echoer)
|
|
end
|
|
|
|
if string.find(msg, "^" .. Heimdall_Data.config.echoer.prefix) then
|
|
if Heimdall_Data.config.echoer.debug then
|
|
print(string.format("[%s] Found echo command in message: %s", ModuleName, msg))
|
|
end
|
|
local msg = string.sub(msg, string.len(Heimdall_Data.config.echoer.prefix) + 1)
|
|
if Heimdall_Data.config.echoer.debug then
|
|
print(string.format("[%s] Echoing message: %s", ModuleName, msg))
|
|
end
|
|
SendChatMessage(msg, "SAY")
|
|
elseif Heimdall_Data.config.echoer.debug then
|
|
print(string.format("[%s] Message does not start with echo prefix", ModuleName))
|
|
end
|
|
end)
|
|
|
|
if Heimdall_Data.config.echoer.debug then print(string.format("[%s] Module initialized", ModuleName)) end
|
|
print("[Heimdall] Echoer loaded")
|
|
end
|