Add Russian localization who (kto) for our russian friends

This commit is contained in:
2025-05-25 11:09:43 +02:00
parent 263cf8e2e4
commit 7eee3a13a6

View File

@@ -1,390 +1,438 @@
local _, shared = ... local _, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
local ModuleName = "Commander" local ModuleName = "Commander"
---@class HeimdallCommanderConfig ---@class HeimdallCommanderConfig
---@field enabled boolean ---@field enabled boolean
---@field debug boolean ---@field debug boolean
---@field channels string[] ---@field channels string[]
---@field commander string ---@field commander string
---@field commands table<string, boolean> ---@field commands table<string, boolean>
local helpMessages = { local helpMessages = {
ru = { ru = {
"1) who - пишет вам никнеймы текущих врагов и локу.", "1) who - пишет вам никнеймы текущих врагов и локу.",
"2) classes - покажет классы врагов и число.", "2) classes - покажет классы врагов и число.",
"3) howmany - общее число врагов (дурик 4 . огри 2 ) ", "3) howmany - общее число врагов (дурик 4 . огри 2 ) ",
"4) + - атоинвайт в сбор пати и сброса кд.", "4) + - атоинвайт в сбор пати и сброса кд.",
"5) ++ -автоинвайт в пати аликов (если нужен рефрак)", "5) ++ -автоинвайт в пати аликов (если нужен рефрак)",
"6 ) note Никнейм текст - добавление заметки.", "6 ) note Никнейм текст - добавление заметки.",
"7) note Никнейм - посмотреть последние заметки.", "7) note Никнейм - посмотреть последние заметки.",
"8) note Никнейм 5 - посмотреть конкретную заметку.", "8) note Никнейм 5 - посмотреть конкретную заметку.",
"9) note Никнейм 1..5 - посмотреть заметки от 1 до 5", "9) note Никнейм 1..5 - посмотреть заметки от 1 до 5",
"10) note Никнейм delete 1 - удалить заметку номер 1", "10) note Никнейм delete 1 - удалить заметку номер 1",
"11) note Никнейм delete 1..5 - удалить заметки 1 до 5", "11) note Никнейм delete 1..5 - удалить заметки 1 до 5",
}, },
en = { en = {
"1) who - reports currently tracked stinkies in orgrimmar and durotar", "1) who - reports currently tracked stinkies in orgrimmar and durotar",
"2) classes - reports stinkies grouped by class", "2) classes - reports stinkies grouped by class",
"3) howmany - reports stinkies grouped by zone", "3) howmany - reports stinkies grouped by zone",
"4) + - automatically invites to group with duel rogue for cd reset", "4) + - automatically invites to group with duel rogue for cd reset",
"5) ++ - automatically invites to alliance group", "5) ++ - automatically invites to alliance group",
"6) note <name> <note> - adds a note for the specified character.", "6) note <name> <note> - adds a note for the specified character.",
"7) note <name> - lists the last N notes for the character.", "7) note <name> - lists the last N notes for the character.",
"8) note <name> i - lists the i-th note for the character.", "8) note <name> i - lists the i-th note for the character.",
"9) note <name> i..j - lists notes from i to j for the character.", "9) note <name> i..j - lists notes from i to j for the character.",
"10) note <name> delete i - deletes the i-th note for the character.", "10) note <name> delete i - deletes the i-th note for the character.",
"11) note <name> delete i..j - deletes notes from i to j for the character.", "11) note <name> delete i..j - deletes notes from i to j for the character.",
}, },
} }
---@class Commander ---@class Commander
shared.Commander = { shared.Commander = {
Init = function() Init = function()
---@param text string ---@param text string
---@param size number ---@param size number
---@return string[] ---@return string[]
local function Partition(text, size) local function Partition(text, size)
local words = {} local words = {}
for word in text:gmatch("[^,]+") do for word in text:gmatch("[^,]+") do
words[#words + 1] = word words[#words + 1] = word
end end
local ret = {} local ret = {}
local currentChunk = "" local currentChunk = ""
for _, word in ipairs(words) do for _, word in ipairs(words) do
if #currentChunk + #word + 1 <= size then if #currentChunk + #word + 1 <= size then
currentChunk = currentChunk .. (currentChunk == "" and word or " " .. word) currentChunk = currentChunk .. (currentChunk == "" and word or " " .. word)
else else
if #currentChunk > 0 then ret[#ret + 1] = currentChunk end if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
currentChunk = word currentChunk = word
end end
end end
if #currentChunk > 0 then ret[#ret + 1] = currentChunk end if #currentChunk > 0 then ret[#ret + 1] = currentChunk end
return ret return ret
end end
---@param arr table<string, Player> ---@param arr table<string, Player>
---@return string[] ---@return string[]
local function Count(arr) local function Count(arr)
local ret = {} local ret = {}
for _, player in pairs(arr) do for _, player in pairs(arr) do
if shared.Whoer.ShouldNotifyForZone(player.zone) then ret[player.zone] = (ret[player.zone] or 0) + 1 end if shared.Whoer.ShouldNotifyForZone(player.zone) then ret[player.zone] = (ret[player.zone] or 0) + 1 end
end end
local text = {} local text = {}
for zone, count in pairs(ret) do for zone, count in pairs(ret) do
text[#text + 1] = string.format("%s: %d", zone, count) text[#text + 1] = string.format("%s: %d", zone, count)
end end
return text return text
end end
---@param arr table<string, Player> ---@param arr table<string, Player>
---@return string[] ---@return string[]
local function CountPartitioned(arr) local function CountPartitioned(arr)
local count = Count(arr) local count = Count(arr)
local text = {} local text = {}
---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack ---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack
for _, line in pairs(Partition(strjoin(", ", unpack(count)), 200)) do for _, line in pairs(Partition(strjoin(", ", unpack(count)), 200)) do
text[#text + 1] = line text[#text + 1] = line
end end
return text return text
end end
---@param arr table<string, Player> ---@param arr table<string, Player>
---@return string[] ---@return string[]
local function Who(arr) local function Who(arr)
local ret = {} local ret = {}
for _, player in pairs(arr) do for _, player in pairs(arr) do
if shared.Whoer.ShouldNotifyForZone(player.zone) then if shared.Whoer.ShouldNotifyForZone(player.zone) then
ret[#ret + 1] = string.format( ret[#ret + 1] = string.format(
"%s/%s (%s) %s", "%s/%s (%s) %s",
player.name, player.name,
player.class, player.class,
player.zone, player.zone,
player.stinky and "(!!!!)" or "" player.stinky and "(!!!!)" or ""
) )
end end
end end
if Heimdall_Data.config.commander.debug then if Heimdall_Data.config.commander.debug then
print(string.format("[%s] Command result: %s", ModuleName, strjoin(", ", unpack(ret)))) print(string.format("[%s] Command result: %s", ModuleName, strjoin(", ", unpack(ret))))
end end
return ret return ret
end end
---@param arr table<string, Player> -- This is really ugly, duplicating methods like this
---@return string[] -- But I have no better idea
local function WhoPartitioned(arr) -- We would have to drag reference channel all the way here
local who = Who(arr) -- And then in here do some kind of deciding based on the fucking channel locale
local text = {} -- That's also a nasty solution... I guess adding "kto" is better
---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack ---@param arr table<string, Player>
for _, line in pairs(Partition(strjoin(", ", unpack(who)), 200)) do ---@return string[]
text[#text + 1] = "who: " .. line local function WhoRu(arr)
end local ret = {}
return text for _, player in pairs(arr) do
end if shared.Whoer.ShouldNotifyForZone(player.zone) then
---@param arr table<string, Player> shared.dump(player)
---@return string[] ret[#ret + 1] = string.format(
local function CountClass(arr) "%s/%s (%s) %s",
local ret = {} player.name,
for _, player in pairs(arr) do shared._L(player.class, "ru"),
if shared.Whoer.ShouldNotifyForZone(player.zone) then shared._L(player.zone, "ru"),
ret[player.class] = (ret[player.class] or 0) + 1 player.stinky and "(!!!!)" or ""
end )
end end
local text = {} end
for class, count in pairs(ret) do if Heimdall_Data.config.commander.debug then
text[#text + 1] = string.format("%s: %d", class, count) print(string.format("[%s] Command result: %s", ModuleName, strjoin(", ", unpack(ret))))
end end
if Heimdall_Data.config.commander.debug then return ret
print(string.format("[%s] Message text: %s", ModuleName, strjoin(", ", unpack(text)))) end
end ---@param arr table<string, Player>
return text ---@return string[]
end local function WhoPartitioned(arr)
---@param arr table<string, Player> local who = Who(arr)
---@return string[] local text = {}
local function CountClassPartitioned(arr) ---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack
local countClass = CountClass(arr) for _, line in pairs(Partition(strjoin(", ", unpack(who)), 200)) do
local text = {} text[#text + 1] = "who: " .. line
---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack end
for _, line in pairs(Partition(strjoin(", ", unpack(countClass)), 200)) do return text
text[#text + 1] = line end
end ---@param arr table<string, Player>
return text ---@return string[]
end local function WhoPartitionedRu(arr)
local function CountClassPartitionedStinkies() local who = WhoRu(arr)
if Heimdall_Data.config.commander.debug then local text = {}
print(string.format("[%s] Executing: CountClassPartitionedStinkies", ModuleName)) ---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack
end for _, line in pairs(Partition(strjoin(", ", unpack(who)), 200)) do
local res = CountClassPartitioned(HeimdallStinkies) text[#text + 1] = "кто: " .. line
if #res == 0 then return { "No stinkies found" } end end
return res return text
end end
local function WhoPartitionedStinkies() ---@param arr table<string, Player>
if Heimdall_Data.config.commander.debug then ---@return string[]
print(string.format("[%s] Executing: WhoPartitionedStinkies", ModuleName)) local function CountClass(arr)
shared.dump(HeimdallStinkies) local ret = {}
end for _, player in pairs(arr) do
local res = WhoPartitioned(HeimdallStinkies) if shared.Whoer.ShouldNotifyForZone(player.zone) then
if #res == 0 then return { "No stinkies found" } end ret[player.class] = (ret[player.class] or 0) + 1
return res end
end end
local function CountPartitionedStinkies() local text = {}
if Heimdall_Data.config.commander.debug then for class, count in pairs(ret) do
print(string.format("[%s] Executing: CountPartitionedStinkies", ModuleName)) text[#text + 1] = string.format("%s: %d", class, count)
end end
local res = CountPartitioned(HeimdallStinkies) if Heimdall_Data.config.commander.debug then
if #res == 0 then return { "No stinkies found" } end print(string.format("[%s] Message text: %s", ModuleName, strjoin(", ", unpack(text))))
return res end
end return text
local function HelpRu() end
if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: HelpRu", ModuleName)) end ---@param arr table<string, Player>
return helpMessages.ru ---@return string[]
end local function CountClassPartitioned(arr)
local function HelpEn() local countClass = CountClass(arr)
if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: HelpEn", ModuleName)) end local text = {}
return helpMessages.en ---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack
end for _, line in pairs(Partition(strjoin(", ", unpack(countClass)), 200)) do
local groupInviteFrame = CreateFrame("Frame") text[#text + 1] = line
groupInviteFrame:SetScript("OnEvent", function(self, event, ...) end
if Heimdall_Data.config.commander.debug then print(string.format("[%s] Event received", ModuleName)) end return text
AcceptGroup() end
groupInviteFrame:UnregisterEvent("PARTY_INVITE_REQUEST") local function CountClassPartitionedStinkies()
C_Timer.NewTimer(0.1, function() if Heimdall_Data.config.commander.debug then
if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: CountClassPartitionedStinkies", ModuleName))
print(string.format("[%s] Click event triggered", ModuleName)) end
end local res = CountClassPartitioned(HeimdallStinkies)
_G["StaticPopup1Button1"]:Click() if #res == 0 then return { "No stinkies found" } end
end, 1) return res
end) end
local function JoinGroup() local function WhoPartitionedStinkies()
if Heimdall_Data.config.commander.debug then if Heimdall_Data.config.commander.debug then
print(string.format("[%s] JoinGroup command received", ModuleName)) print(string.format("[%s] Executing: WhoPartitionedStinkies", ModuleName))
end shared.dump(HeimdallStinkies)
groupInviteFrame:RegisterEvent("PARTY_INVITE_REQUEST") end
C_Timer.NewTimer(10, function() groupInviteFrame:UnregisterEvent("PARTY_INVITE_REQUEST") end, 1) local res = WhoPartitioned(HeimdallStinkies)
return { "+" } if #res == 0 then return { "No stinkies found" } end
end return res
local function LeaveGroup() end
if Heimdall_Data.config.commander.debug then local function WhoPartitionedStinkiesRu()
print(string.format("[%s] LeaveGroup command received", ModuleName)) if Heimdall_Data.config.commander.debug then
end print(string.format("[%s] Executing: WhoPartitionedStinkies", ModuleName))
LeaveParty() shared.dump(HeimdallStinkies)
return {} end
end local res = WhoPartitionedRu(HeimdallStinkies)
---@param target string if #res == 0 then return { "No stinkies found" } end
local function FollowTarget(target) return res
if Heimdall_Data.config.commander.debug then end
print(string.format("[%s] Following target: %s", ModuleName, target)) local function CountPartitionedStinkies()
end if Heimdall_Data.config.commander.debug then
if not target then return end print(string.format("[%s] Executing: CountPartitionedStinkies", ModuleName))
FollowUnit(target) end
return {} local res = CountPartitioned(HeimdallStinkies)
end if #res == 0 then return { "No stinkies found" } end
return res
---@param args string[] end
local function MacroTarget(args) local function HelpRu()
if Heimdall_Data.config.commander.debug then if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: HelpRu", ModuleName)) end
---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack return helpMessages.ru
print(string.format("[%s] Macroing: %s", ModuleName, strjoin(" ", unpack(args)))) end
end local function HelpEn()
if #args < 2 or #args % 2 ~= 0 then if Heimdall_Data.config.commander.debug then print(string.format("[%s] Executing: HelpEn", ModuleName)) end
if #args < 2 or #args % 2 ~= 0 then return helpMessages.en
if Heimdall_Data.config.commander.debug then end
print(string.format("[%s] Invalid number of arguments for MacroTarget", ModuleName)) local groupInviteFrame = CreateFrame("Frame")
end groupInviteFrame:SetScript("OnEvent", function(self, event, ...)
return {} if Heimdall_Data.config.commander.debug then print(string.format("[%s] Event received", ModuleName)) end
end AcceptGroup()
end groupInviteFrame:UnregisterEvent("PARTY_INVITE_REQUEST")
table.remove(args, 1) C_Timer.NewTimer(0.1, function()
if Heimdall_Data.config.commander.debug then
for i = 1, #args do print(string.format("[%s] Click event triggered", ModuleName))
local stinky = strtrim(args[i]) end
local name = stinky:match("([^/]+)") _G["StaticPopup1Button1"]:Click()
local class = stinky:match("/([^ $]+)") end, 1)
if Heimdall_Data.config.commander.debug then end)
print(string.format("[%s] Adding stinky: %s/%s", ModuleName, name, tostring(class))) local function JoinGroup()
end if Heimdall_Data.config.commander.debug then
shared.StinkyTracker.Track({ print(string.format("[%s] JoinGroup command received", ModuleName))
name = name, end
class = class or "unknown", groupInviteFrame:RegisterEvent("PARTY_INVITE_REQUEST")
seenAt = GetTime(), C_Timer.NewTimer(10, function() groupInviteFrame:UnregisterEvent("PARTY_INVITE_REQUEST") end, 1)
hostile = true, return { "+" }
}) end
if Heimdall_Data.config.commander.debug then local function LeaveGroup()
print(string.format("[%s] Added stinky: %s/%s", ModuleName, name, tostring(class))) if Heimdall_Data.config.commander.debug then
end print(string.format("[%s] LeaveGroup command received", ModuleName))
end end
return {} LeaveParty()
end return {}
end
---@param args string[] ---@param target string
local function IgnoreMacroTarget(args) local function FollowTarget(target)
if Heimdall_Data.config.commander.debug then if Heimdall_Data.config.commander.debug then
---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack print(string.format("[%s] Following target: %s", ModuleName, target))
print(string.format("[%s] Macroing: %s", ModuleName, strjoin(" ", unpack(args)))) end
end if not target then return end
if #args < 1 then FollowUnit(target)
if Heimdall_Data.config.commander.debug then return {}
print(string.format("[%s] Invalid number of arguments for IgnoreMacroTarget", ModuleName)) end
end
return {} ---@param args string[]
end local function MacroTarget(args)
table.remove(args, 1) if Heimdall_Data.config.commander.debug then
---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack
for i = 1, #args do print(string.format("[%s] Macroing: %s", ModuleName, strjoin(" ", unpack(args))))
local stinky = strtrim(args[i]) end
local name = stinky:match("([^/]+)") if #args < 2 or #args % 2 ~= 0 then
if Heimdall_Data.config.commander.debug then if #args < 2 or #args % 2 ~= 0 then
print(string.format("[%s] Ignoring stinky: %s", ModuleName, name)) if Heimdall_Data.config.commander.debug then
end print(string.format("[%s] Invalid number of arguments for MacroTarget", ModuleName))
shared.StinkyTracker.Ignore(name) end
end return {}
return {} end
end end
table.remove(args, 1)
---@class Command
---@field keywordRe string for i = 1, #args do
---@field commanderOnly boolean local stinky = strtrim(args[i])
---@field callback fun(...: any): string[] local name = stinky:match("([^/]+)")
local class = stinky:match("/([^ $]+)")
local commands = { if Heimdall_Data.config.commander.debug then
{ keywordRe = "^who$", commanderOnly = false, callback = WhoPartitionedStinkies }, print(string.format("[%s] Adding stinky: %s/%s", ModuleName, name, tostring(class)))
{ keywordRe = "^howmany$", commanderOnly = false, callback = CountPartitionedStinkies }, end
{ keywordRe = "^classes$", commanderOnly = false, callback = CountClassPartitionedStinkies }, shared.StinkyTracker.Track({
{ keywordRe = "^help$", commanderOnly = false, callback = HelpRu }, name = name,
{ keywordRe = "^helpen$", commanderOnly = false, callback = HelpEn }, class = class or "unknown",
{ keywordRe = "^joingroup$", commanderOnly = false, callback = JoinGroup }, seenAt = GetTime(),
{ keywordRe = "^leavegroup$", commanderOnly = false, callback = LeaveGroup }, hostile = true,
{ keywordRe = "^follow$", commanderOnly = false, callback = FollowTarget }, })
{ keywordRe = "^macro", commanderOnly = false, callback = MacroTarget }, if Heimdall_Data.config.commander.debug then
{ keywordRe = "^ignore", commanderOnly = false, callback = IgnoreMacroTarget }, print(string.format("[%s] Added stinky: %s/%s", ModuleName, name, tostring(class)))
} end
end
local commanderChannelFrame = CreateFrame("Frame") return {}
commanderChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL") end
commanderChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
--if Heimdall_Data.config.commander.debug then ---@param args string[]
-- print(string.format("[%s] Event received", ModuleName)) local function IgnoreMacroTarget(args)
-- shared.dump(Heimdall_Data.config.commander) if Heimdall_Data.config.commander.debug then
--end ---@diagnostic disable-next-line: param-type-mismatch something wrong with luals, it's picking up the "wrong" unpack
if not Heimdall_Data.config.commander.enabled then print(string.format("[%s] Macroing: %s", ModuleName, strjoin(" ", unpack(args))))
--if Heimdall_Data.config.commander.debug then end
-- print(string.format("[%s] Module disabled, ignoring event", ModuleName)) if #args < 1 then
--end if Heimdall_Data.config.commander.debug then
return print(string.format("[%s] Invalid number of arguments for IgnoreMacroTarget", ModuleName))
end end
local channelId = select(6, ...) return {}
local _, channelname = GetChannelName(channelId) end
local ok = false table.remove(args, 1)
for _, channel in pairs(Heimdall_Data.config.commander.channels) do
if channel == channelname then for i = 1, #args do
ok = true local stinky = strtrim(args[i])
break local name = stinky:match("([^/]+)")
end if Heimdall_Data.config.commander.debug then
end print(string.format("[%s] Ignoring stinky: %s", ModuleName, name))
if not ok then end
if Heimdall_Data.config.commander.debug then shared.StinkyTracker.Ignore(name)
print( end
string.format( return {}
"[%s] Channel name '%s' does not match any of the channels '%s'", end
ModuleName,
channelname, ---@class Command
table.concat(Heimdall_Data.config.commander.channels, ", ") ---@field keywordRe string
) ---@field commanderOnly boolean
) ---@field callback fun(...: any): string[]
end
return local commands = {
end { keywordRe = "^who$", commanderOnly = false, callback = WhoPartitionedStinkies },
{ keywordRe = "^кто$", commanderOnly = false, callback = WhoPartitionedStinkiesRu },
sender = string.match(sender, "^[^-]+") { keywordRe = "^howmany$", commanderOnly = false, callback = CountPartitionedStinkies },
if Heimdall_Data.config.commander.debug then { keywordRe = "^classes$", commanderOnly = false, callback = CountClassPartitionedStinkies },
print(string.format("[%s] Message from: %s", ModuleName, sender)) { keywordRe = "^help$", commanderOnly = false, callback = HelpRu },
shared.dump(Heimdall_Data.config.commander) { keywordRe = "^helpen$", commanderOnly = false, callback = HelpEn },
end { keywordRe = "^joingroup$", commanderOnly = false, callback = JoinGroup },
{ keywordRe = "^leavegroup$", commanderOnly = false, callback = LeaveGroup },
for _, command in ipairs(commands) do { keywordRe = "^follow$", commanderOnly = false, callback = FollowTarget },
local enabled = Heimdall_Data.config.commander.commands[command.keywordRe] == true or false { keywordRe = "^macro", commanderOnly = false, callback = MacroTarget },
if Heimdall_Data.config.commander.debug then { keywordRe = "^ignore", commanderOnly = false, callback = IgnoreMacroTarget },
print( }
string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled))
) local commanderChannelFrame = CreateFrame("Frame")
end commanderChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL")
if commanderChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
enabled --if Heimdall_Data.config.commander.debug then
and ( -- print(string.format("[%s] Event received", ModuleName))
not command.commanderOnly -- shared.dump(Heimdall_Data.config.commander)
-- if Heimdall_Data.config.commander.debug then print(string.format("[%s] Ignoring command, sender %s not commander %s", ModuleName, sender, Heimdall_Data.config.commander.commander)) end --end
if not Heimdall_Data.config.commander.enabled then
or (command.commanderOnly and sender == Heimdall_Data.config.commander.commander) --if Heimdall_Data.config.commander.debug then
) -- print(string.format("[%s] Module disabled, ignoring event", ModuleName))
then --end
if msg:match(command.keywordRe) then return
---@diagnostic disable-next-line: redundant-parameter Currently luals does not support variadic functions as a @field end
local messages = command.callback({ strsplit(",", msg) }) local channelId = select(6, ...)
if Heimdall_Data.config.commander.debug then local _, channelname = GetChannelName(channelId)
print(string.format("[%s] Messages to send: %s", ModuleName, #messages)) local ok = false
shared.dump(messages) for _, channel in pairs(Heimdall_Data.config.commander.channels) do
end if channel == channelname then
for _, message in ipairs(messages) do ok = true
---@type Message break
local returnmsg = { end
channel = "C", end
data = channelname, if not ok then
message = message, if Heimdall_Data.config.commander.debug then
} print(
if Heimdall_Data.config.commander.debug then string.format(
print(string.format("[%s] Queuing message", ModuleName)) "[%s] Channel name '%s' does not match any of the channels '%s'",
shared.dump(msg) ModuleName,
end channelname,
if Heimdall_Data.config.networkMessenger.enabled then table.concat(Heimdall_Data.config.commander.channels, ", ")
shared.NetworkMessenger.Enqueue(returnmsg) )
elseif Heimdall_Data.config.messenger.enabled then )
shared.Messenger.Enqueue(returnmsg) end
end return
end end
end
end sender = string.match(sender, "^[^-]+")
end if Heimdall_Data.config.commander.debug then
end) print(string.format("[%s] Message from: %s", ModuleName, sender))
shared.dump(Heimdall_Data.config.commander)
print(string.format("[%s] Module initialized", ModuleName)) end
end,
for _, command in ipairs(commands) do
local enabled = Heimdall_Data.config.commander.commands[command.keywordRe] == true or false
if Heimdall_Data.config.commander.debug then
print(
string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled))
)
end
if
enabled
and (
not command.commanderOnly
-- if Heimdall_Data.config.commander.debug then print(string.format("[%s] Ignoring command, sender %s not commander %s", ModuleName, sender, Heimdall_Data.config.commander.commander)) end
or (command.commanderOnly and sender == Heimdall_Data.config.commander.commander)
)
then
if msg:match(command.keywordRe) then
---@diagnostic disable-next-line: redundant-parameter Currently luals does not support variadic functions as a @field
local messages = command.callback({ strsplit(",", msg) })
if Heimdall_Data.config.commander.debug then
print(string.format("[%s] Messages to send: %s", ModuleName, #messages))
shared.dump(messages)
end
for _, message in ipairs(messages) do
---@type Message
local returnmsg = {
channel = "C",
data = channelname,
message = message,
}
if Heimdall_Data.config.commander.debug then
print(string.format("[%s] Queuing message", ModuleName))
shared.dump(msg)
end
if Heimdall_Data.config.networkMessenger.enabled then
shared.NetworkMessenger.Enqueue(returnmsg)
elseif Heimdall_Data.config.messenger.enabled then
shared.Messenger.Enqueue(returnmsg)
end
end
end
end
end
end)
print(string.format("[%s] Module initialized", ModuleName))
end,
}