Migrate the commands from whoer to commander
This commit is contained in:
10
Heimdall.lua
10
Heimdall.lua
@@ -36,6 +36,7 @@ local function init()
|
|||||||
---@field Emoter InitTable
|
---@field Emoter InitTable
|
||||||
---@field Echoer InitTable
|
---@field Echoer InitTable
|
||||||
---@field Macroer InitTable
|
---@field Macroer InitTable
|
||||||
|
---@field Commander InitTable
|
||||||
|
|
||||||
--- Config ---
|
--- Config ---
|
||||||
---@class HeimdallConfig
|
---@class HeimdallConfig
|
||||||
@@ -50,6 +51,7 @@ local function init()
|
|||||||
---@field emoter HeimdallEmoterConfig
|
---@field emoter HeimdallEmoterConfig
|
||||||
---@field echoer HeimdallEchoerConfig
|
---@field echoer HeimdallEchoerConfig
|
||||||
---@field macroer HeimdallMacroerConfig
|
---@field macroer HeimdallMacroerConfig
|
||||||
|
---@field commander HeimdallCommanderConfig
|
||||||
---@field whisperNotify table<string, string>
|
---@field whisperNotify table<string, string>
|
||||||
---@field stinkies table<string, boolean>
|
---@field stinkies table<string, boolean>
|
||||||
---@field agents table<string, string>
|
---@field agents table<string, string>
|
||||||
@@ -117,6 +119,10 @@ local function init()
|
|||||||
---@field enabled boolean
|
---@field enabled boolean
|
||||||
---@field priority string[]
|
---@field priority string[]
|
||||||
|
|
||||||
|
---@class HeimdallCommanderConfig
|
||||||
|
---@field enabled boolean
|
||||||
|
---@field masterChannel string
|
||||||
|
|
||||||
--- Data ---
|
--- Data ---
|
||||||
---@class HeimdallMessengerData
|
---@class HeimdallMessengerData
|
||||||
---@field queue table<string, Message>
|
---@field queue table<string, Message>
|
||||||
@@ -229,6 +235,10 @@ local function init()
|
|||||||
priority = shared.GetOrDefault(Heimdall_Data, { "config", "macroer", "priority" }, {}),
|
priority = shared.GetOrDefault(Heimdall_Data, { "config", "macroer", "priority" }, {}),
|
||||||
},
|
},
|
||||||
agents = shared.GetOrDefault(Heimdall_Data, { "config", "agents" }, {}),
|
agents = shared.GetOrDefault(Heimdall_Data, { "config", "agents" }, {}),
|
||||||
|
commander = {
|
||||||
|
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "commander", "enabled" }, false),
|
||||||
|
masterChannel = shared.GetOrDefault(Heimdall_Data, { "config", "commander", "masterChannel" }, "Agent"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
shared.raceMap = {
|
shared.raceMap = {
|
||||||
|
@@ -18,4 +18,5 @@ Modules/AgentTracker.lua
|
|||||||
Modules/Emoter.lua
|
Modules/Emoter.lua
|
||||||
Modules/Echoer.lua
|
Modules/Echoer.lua
|
||||||
Modules/Macroer.lua
|
Modules/Macroer.lua
|
||||||
|
Modules/Commander.lua
|
||||||
Heimdall.lua
|
Heimdall.lua
|
223
Modules/Commander.lua
Normal file
223
Modules/Commander.lua
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
local addonname, shared = ...
|
||||||
|
---@cast shared HeimdallShared
|
||||||
|
---@cast addonname string
|
||||||
|
|
||||||
|
local helpMessages = {
|
||||||
|
ru = {
|
||||||
|
"1) who - пишет вам никнеймы текущих врагов в отслеживаемых локациях по порядку и локацию.",
|
||||||
|
"2) classes = пишет какие классы. (например 1 паладин 1 прист 1 рога.",
|
||||||
|
"3) howmany - общее число врагов (например дуротар 4 . оргримар 2 ) ",
|
||||||
|
"4) + - автоматическое приглашение в группу с дуельным рогой для сброса кд и общего сбора. ",
|
||||||
|
"5) ++ - автоматическое приглашение в группу альянса. (если нужен рефрак)",
|
||||||
|
},
|
||||||
|
en = {
|
||||||
|
"1) who - reports currently tracked stinkies in orgrimmar and durotar",
|
||||||
|
"2) classes - reports stinkies grouped by class",
|
||||||
|
"3) howmany - reports stinkies grouped by zone",
|
||||||
|
"4) + - automatically invites to group with duel rogue for cd reset",
|
||||||
|
"5) ++ - automatically invites to alliance group",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: missing-fields
|
||||||
|
shared.Commander = {}
|
||||||
|
function shared.Commander.Init()
|
||||||
|
---@param text string
|
||||||
|
---@param size number
|
||||||
|
---@return string[]
|
||||||
|
local function Partition(text, size)
|
||||||
|
local words = {}
|
||||||
|
for word in text:gmatch("[^,]+") do
|
||||||
|
words[#words + 1] = word
|
||||||
|
end
|
||||||
|
|
||||||
|
local ret = {}
|
||||||
|
local currentChunk = ""
|
||||||
|
|
||||||
|
for _, word in ipairs(words) do
|
||||||
|
if #currentChunk + #word + 1 <= size then
|
||||||
|
currentChunk = currentChunk .. (currentChunk == "" and word or " " .. word)
|
||||||
|
else
|
||||||
|
if #currentChunk > 0 then
|
||||||
|
ret[#ret + 1] = currentChunk
|
||||||
|
end
|
||||||
|
currentChunk = word
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #currentChunk > 0 then
|
||||||
|
ret[#ret + 1] = currentChunk
|
||||||
|
end
|
||||||
|
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
---@param arr table<string, Player>
|
||||||
|
---@return string[]
|
||||||
|
local function Count(arr)
|
||||||
|
local ret = {}
|
||||||
|
for _, player in pairs(arr) do
|
||||||
|
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||||
|
ret[player.zone] = (ret[player.zone] or 0) + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local text = {}
|
||||||
|
for zone, count in pairs(ret) do
|
||||||
|
text[#text + 1] = string.format("%s: %d", zone, count)
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
---@param arr table<string, Player>
|
||||||
|
---@return string[]
|
||||||
|
local function CountPartitioned(arr)
|
||||||
|
local count = Count(arr)
|
||||||
|
local text = {}
|
||||||
|
for _, line in pairs(Partition(strjoin(", ", unpack(count)), 200)) do
|
||||||
|
text[#text + 1] = line
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
---@param arr table<string, Player>
|
||||||
|
---@return string[]
|
||||||
|
local function Who(arr)
|
||||||
|
local ret = {}
|
||||||
|
for _, player in pairs(arr) do
|
||||||
|
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||||
|
ret[#ret + 1] = string.format("%s/%s (%s) %s", player.name, player.class, player.zone,
|
||||||
|
player.stinky and "(!!!!)" or "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
---@param arr table<string, Player>
|
||||||
|
---@return string[]
|
||||||
|
local function WhoPartitioned(arr)
|
||||||
|
local who = Who(arr)
|
||||||
|
local text = {}
|
||||||
|
for _, line in pairs(Partition(strjoin(", ", unpack(who)), 200)) do
|
||||||
|
text[#text + 1] = line
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
---@param arr table<string, Player>
|
||||||
|
---@return string[]
|
||||||
|
local function CountClass(arr)
|
||||||
|
local ret = {}
|
||||||
|
for _, player in pairs(arr) do
|
||||||
|
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
||||||
|
ret[player.class] = (ret[player.class] or 0) + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local text = {}
|
||||||
|
for class, count in pairs(ret) do
|
||||||
|
text[#text + 1] = string.format("%s: %d", class, count)
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
---@param arr table<string, Player>
|
||||||
|
---@return string[]
|
||||||
|
local function CountClassPartitioned(arr)
|
||||||
|
local countClass = CountClass(arr)
|
||||||
|
local text = {}
|
||||||
|
for _, line in pairs(Partition(strjoin(", ", unpack(countClass)), 200)) do
|
||||||
|
text[#text + 1] = line
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
local commanderChannelFrame = CreateFrame("Frame")
|
||||||
|
commanderChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||||
|
commanderChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||||
|
if not Heimdall_Data.config.commander.enabled then return end
|
||||||
|
local channelId = select(6, ...)
|
||||||
|
local _, channelname = GetChannelName(channelId)
|
||||||
|
if channelname ~= Heimdall_Data.config.commander.masterChannel then return end
|
||||||
|
|
||||||
|
if msg == "who" then
|
||||||
|
local messages = WhoPartitioned(HeimdallStinkies)
|
||||||
|
if #messages == 0 then
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = "who: No stinkies found"
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
for _, message in ipairs(messages) do
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = "who: " .. message
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if msg == "howmany" then
|
||||||
|
local messages = CountPartitioned(HeimdallStinkies)
|
||||||
|
if #messages == 0 then
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = "howmany: No stinkies found"
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
for _, message in ipairs(messages) do
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = "howmany: " .. message
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if msg == "classes" then
|
||||||
|
local messages = CountClassPartitioned(HeimdallStinkies)
|
||||||
|
if #messages == 0 then
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = "classes: No stinkies found"
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
for _, message in ipairs(messages) do
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = "classes: " .. message
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if msg == "help" then
|
||||||
|
for _, helpMessage in ipairs(helpMessages.ru) do
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = helpMessage
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if msg == "helpen" then
|
||||||
|
for _, helpMessage in ipairs(helpMessages.en) do
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = helpMessage
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
print("Heimdall - Commander loaded")
|
||||||
|
end
|
@@ -7,22 +7,6 @@ shared.Whoer = {}
|
|||||||
function shared.Whoer.Init()
|
function shared.Whoer.Init()
|
||||||
if not Heimdall_Data.who then Heimdall_Data.who = {} end
|
if not Heimdall_Data.who then Heimdall_Data.who = {} end
|
||||||
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
|
if not Heimdall_Data.who.data then Heimdall_Data.who.data = {} end
|
||||||
local helpMessages = {
|
|
||||||
ru = {
|
|
||||||
"1) who - пишет вам никнеймы текущих врагов в отслеживаемых локациях по порядку и локацию.",
|
|
||||||
"2) classes = пишет какие классы. (например 1 паладин 1 прист 1 рога.",
|
|
||||||
"3) howmany - общее число врагов (например дуротар 4 . оргримар 2 ) ",
|
|
||||||
"4) + - автоматическое приглашение в группу с дуельным рогой для сброса кд и общего сбора. ",
|
|
||||||
"5) ++ - автоматическое приглашение в группу альянса. (если нужен рефрак)",
|
|
||||||
},
|
|
||||||
en = {
|
|
||||||
"1) who - reports currently tracked stinkies in orgrimmar and durotar",
|
|
||||||
"2) classes - reports stinkies grouped by class",
|
|
||||||
"3) howmany - reports stinkies grouped by zone",
|
|
||||||
"4) + - automatically invites to group with duel rogue for cd reset",
|
|
||||||
"5) ++ - automatically invites to alliance group",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
---@type table<string, Player>
|
---@type table<string, Player>
|
||||||
HeimdallStinkies = {}
|
HeimdallStinkies = {}
|
||||||
@@ -379,214 +363,5 @@ function shared.Whoer.Init()
|
|||||||
Tick()
|
Tick()
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param text string
|
|
||||||
---@param size number
|
|
||||||
---@return string[]
|
|
||||||
local function Partition(text, size)
|
|
||||||
local words = {}
|
|
||||||
for word in text:gmatch("[^,]+") do
|
|
||||||
words[#words + 1] = word
|
|
||||||
end
|
|
||||||
|
|
||||||
local ret = {}
|
|
||||||
local currentChunk = ""
|
|
||||||
|
|
||||||
for _, word in ipairs(words) do
|
|
||||||
if #currentChunk + #word + 1 <= size then
|
|
||||||
currentChunk = currentChunk .. (currentChunk == "" and word or " " .. word)
|
|
||||||
else
|
|
||||||
if #currentChunk > 0 then
|
|
||||||
ret[#ret + 1] = currentChunk
|
|
||||||
end
|
|
||||||
currentChunk = word
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if #currentChunk > 0 then
|
|
||||||
ret[#ret + 1] = currentChunk
|
|
||||||
end
|
|
||||||
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
---@param arr table<string, Player>
|
|
||||||
---@return string[]
|
|
||||||
local function Count(arr)
|
|
||||||
local ret = {}
|
|
||||||
for _, player in pairs(arr) do
|
|
||||||
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
|
||||||
ret[player.zone] = (ret[player.zone] or 0) + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local text = {}
|
|
||||||
for zone, count in pairs(ret) do
|
|
||||||
text[#text + 1] = string.format("%s: %d", zone, count)
|
|
||||||
end
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
---@param arr table<string, Player>
|
|
||||||
---@return string[]
|
|
||||||
local function CountPartitioned(arr)
|
|
||||||
local count = Count(arr)
|
|
||||||
local text = {}
|
|
||||||
for _, line in pairs(Partition(strjoin(", ", unpack(count)), 200)) do
|
|
||||||
text[#text + 1] = line
|
|
||||||
end
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
---@param arr table<string, Player>
|
|
||||||
---@return string[]
|
|
||||||
local function Who(arr)
|
|
||||||
local ret = {}
|
|
||||||
for _, player in pairs(arr) do
|
|
||||||
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
|
||||||
ret[#ret + 1] = string.format("%s/%s (%s) %s", player.name, player.class, player.zone,
|
|
||||||
player.stinky and "(!!!!)" or "")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
---@param arr table<string, Player>
|
|
||||||
---@return string[]
|
|
||||||
local function WhoPartitioned(arr)
|
|
||||||
local who = Who(arr)
|
|
||||||
local text = {}
|
|
||||||
for _, line in pairs(Partition(strjoin(", ", unpack(who)), 200)) do
|
|
||||||
text[#text + 1] = line
|
|
||||||
end
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
---@param arr table<string, Player>
|
|
||||||
---@return string[]
|
|
||||||
local function CountClass(arr)
|
|
||||||
local ret = {}
|
|
||||||
for _, player in pairs(arr) do
|
|
||||||
if Heimdall_Data.config.who.zoneNotifyFor[player.zone] then
|
|
||||||
ret[player.class] = (ret[player.class] or 0) + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local text = {}
|
|
||||||
for class, count in pairs(ret) do
|
|
||||||
text[#text + 1] = string.format("%s: %d", class, count)
|
|
||||||
end
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
---@param arr table<string, Player>
|
|
||||||
---@return string[]
|
|
||||||
local function CountClassPartitioned(arr)
|
|
||||||
local countClass = CountClass(arr)
|
|
||||||
local text = {}
|
|
||||||
for _, line in pairs(Partition(strjoin(", ", unpack(countClass)), 200)) do
|
|
||||||
text[#text + 1] = line
|
|
||||||
end
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
|
|
||||||
local whoQueryChannelFrame = CreateFrame("Frame")
|
|
||||||
whoQueryChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL")
|
|
||||||
whoQueryChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
|
||||||
if not Heimdall_Data.config.who.enabled then return end
|
|
||||||
local channelId = select(6, ...)
|
|
||||||
local channelname = ""
|
|
||||||
---@type any[]
|
|
||||||
local channels = { GetChannelList() }
|
|
||||||
for i = 1, #channels, 2 do
|
|
||||||
---@type number
|
|
||||||
local id = channels[i]
|
|
||||||
---@type string
|
|
||||||
local name = channels[i + 1]
|
|
||||||
if id == channelId then
|
|
||||||
channelname = name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if channelname ~= Heimdall_Data.config.who.notifyChannel then return end
|
|
||||||
|
|
||||||
if msg == "who" then
|
|
||||||
local messages = WhoPartitioned(HeimdallStinkies)
|
|
||||||
if #messages == 0 then
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = "who: No stinkies found"
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
for _, message in ipairs(messages) do
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = "who: " .. message
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if msg == "howmany" then
|
|
||||||
local messages = CountPartitioned(HeimdallStinkies)
|
|
||||||
if #messages == 0 then
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = "howmany: No stinkies found"
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
for _, message in ipairs(messages) do
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = "howmany: " .. message
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if msg == "classes" then
|
|
||||||
local messages = CountClassPartitioned(HeimdallStinkies)
|
|
||||||
if #messages == 0 then
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = "classes: No stinkies found"
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
for _, message in ipairs(messages) do
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = "classes: " .. message
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if msg == "help" then
|
|
||||||
for _, helpMessage in ipairs(helpMessages.ru) do
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = helpMessage
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if msg == "helpen" then
|
|
||||||
for _, helpMessage in ipairs(helpMessages.en) do
|
|
||||||
---@type Message
|
|
||||||
local msg = {
|
|
||||||
channel = "CHANNEL",
|
|
||||||
data = channelname,
|
|
||||||
message = helpMessage
|
|
||||||
}
|
|
||||||
table.insert(shared.messenger.queue, msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
print("Heimdall - Whoer loaded")
|
print("Heimdall - Whoer loaded")
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user