Implement basic structure for noter
This commit is contained in:
16
Heimdall.lua
16
Heimdall.lua
@@ -8,7 +8,6 @@ shared.VERSION = VERSION
|
|||||||
local function init()
|
local function init()
|
||||||
---@class Heimdall_Data
|
---@class Heimdall_Data
|
||||||
---@field config HeimdallConfig
|
---@field config HeimdallConfig
|
||||||
---@field stinkies table<string, boolean>
|
|
||||||
if not Heimdall_Data then Heimdall_Data = {} end
|
if not Heimdall_Data then Heimdall_Data = {} end
|
||||||
|
|
||||||
---@class InitTable
|
---@class InitTable
|
||||||
@@ -44,6 +43,7 @@ local function init()
|
|||||||
---@field Sniffer InitTable
|
---@field Sniffer InitTable
|
||||||
---@field MinimapTagger InitTable
|
---@field MinimapTagger InitTable
|
||||||
---@field BonkDetector InitTable
|
---@field BonkDetector InitTable
|
||||||
|
---@field Noter InitTable
|
||||||
|
|
||||||
--- Config ---
|
--- Config ---
|
||||||
---@class HeimdallConfig
|
---@class HeimdallConfig
|
||||||
@@ -63,10 +63,12 @@ local function init()
|
|||||||
---@field combatAlerter HeimdallCombatAlerterConfig
|
---@field combatAlerter HeimdallCombatAlerterConfig
|
||||||
---@field sniffer HeimdallSnifferConfig
|
---@field sniffer HeimdallSnifferConfig
|
||||||
---@field bonkDetector HeimdallBonkDetectorConfig
|
---@field bonkDetector HeimdallBonkDetectorConfig
|
||||||
|
---@field noter HeimdallNoterConfig
|
||||||
---@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>
|
||||||
---@field scale number
|
---@field scale number
|
||||||
|
---@field notes table<string, Note[]>
|
||||||
---@field locale string
|
---@field locale string
|
||||||
---@field echoToRussian boolean
|
---@field echoToRussian boolean
|
||||||
|
|
||||||
@@ -207,6 +209,11 @@ local function init()
|
|||||||
---@field notifyChannel string
|
---@field notifyChannel string
|
||||||
---@field throttle number
|
---@field throttle number
|
||||||
|
|
||||||
|
---@class HeimdallNoterConfig
|
||||||
|
---@field enabled boolean
|
||||||
|
---@field debug boolean
|
||||||
|
---@field masterChannel string
|
||||||
|
|
||||||
--- Data ---
|
--- Data ---
|
||||||
---@class HeimdallMessengerData
|
---@class HeimdallMessengerData
|
||||||
---@field queue table<string, Message>
|
---@field queue table<string, Message>
|
||||||
@@ -405,6 +412,7 @@ local function init()
|
|||||||
},
|
},
|
||||||
whisperNotify = shared.GetOrDefault(Heimdall_Data, { "config", "whisperNotify" }, {}),
|
whisperNotify = shared.GetOrDefault(Heimdall_Data, { "config", "whisperNotify" }, {}),
|
||||||
stinkies = shared.GetOrDefault(Heimdall_Data, { "config", "stinkies" }, {}),
|
stinkies = shared.GetOrDefault(Heimdall_Data, { "config", "stinkies" }, {}),
|
||||||
|
notes = shared.GetOrDefault(Heimdall_Data, { "config", "notes" }, {}),
|
||||||
scale = shared.GetOrDefault(Heimdall_Data, { "config", "scale" }, 1),
|
scale = shared.GetOrDefault(Heimdall_Data, { "config", "scale" }, 1),
|
||||||
locale = shared.GetOrDefault(Heimdall_Data, { "config", "locale" }, "en"),
|
locale = shared.GetOrDefault(Heimdall_Data, { "config", "locale" }, "en"),
|
||||||
echoToRussian = shared.GetOrDefault(Heimdall_Data, { "config", "echoToRussian" }, false),
|
echoToRussian = shared.GetOrDefault(Heimdall_Data, { "config", "echoToRussian" }, false),
|
||||||
@@ -414,6 +422,11 @@ local function init()
|
|||||||
notifyChannel = shared.GetOrDefault(Heimdall_Data, { "config", "bonkDetector", "notifyChannel" }, "Agent"),
|
notifyChannel = shared.GetOrDefault(Heimdall_Data, { "config", "bonkDetector", "notifyChannel" }, "Agent"),
|
||||||
throttle = shared.GetOrDefault(Heimdall_Data, { "config", "bonkDetector", "throttle" }, 5),
|
throttle = shared.GetOrDefault(Heimdall_Data, { "config", "bonkDetector", "throttle" }, 5),
|
||||||
},
|
},
|
||||||
|
noter = {
|
||||||
|
enabled = shared.GetOrDefault(Heimdall_Data, { "config", "noter", "enabled" }, false),
|
||||||
|
debug = shared.GetOrDefault(Heimdall_Data, { "config", "noter", "debug" }, false),
|
||||||
|
masterChannel = shared.GetOrDefault(Heimdall_Data, { "config", "noter", "masterChannel" }, "Agent"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
shared.raceMap = {
|
shared.raceMap = {
|
||||||
@@ -514,6 +527,7 @@ local function init()
|
|||||||
shared.MinimapTagger.Init()
|
shared.MinimapTagger.Init()
|
||||||
shared.BonkDetector.Init()
|
shared.BonkDetector.Init()
|
||||||
shared.Sniffer.Init()
|
shared.Sniffer.Init()
|
||||||
|
shared.Noter.Init()
|
||||||
print("Heimdall loaded!")
|
print("Heimdall loaded!")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -28,4 +28,5 @@ Modules/MinimapTagger.lua
|
|||||||
Modules/Config.lua
|
Modules/Config.lua
|
||||||
Modules/BonkDetector.lua
|
Modules/BonkDetector.lua
|
||||||
Modules/Sniffer.lua
|
Modules/Sniffer.lua
|
||||||
|
Modules/Noter.lua
|
||||||
Heimdall.lua
|
Heimdall.lua
|
@@ -1836,6 +1836,51 @@ function shared.Config.Init()
|
|||||||
--endregion
|
--endregion
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Noter
|
||||||
|
do
|
||||||
|
local r, g, b, a = GetNextColor()
|
||||||
|
local noterConfigFrame = GridFrame.new("HeimdallNoterConfig",
|
||||||
|
UIParent, 12, 20)
|
||||||
|
noterConfigFrame.frame:SetBackdropColor(r, g, b, 0.3)
|
||||||
|
configFrame:Add(noterConfigFrame, 5, 3)
|
||||||
|
|
||||||
|
local title = CreateFancyText("HeimdallNoterConfigTitle", noterConfigFrame.frame,
|
||||||
|
shared.L[Heimdall_Data.config.locale].config.noter,
|
||||||
|
{ r, g, b, a })
|
||||||
|
noterConfigFrame:Add(title, 1, 8)
|
||||||
|
|
||||||
|
local debugButton = CreateBasicButton("HeimdallNoterConfigDebugButton",
|
||||||
|
noterConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.debug, function()
|
||||||
|
Heimdall_Data.config.noter.debug = not Heimdall_Data.config.noter.debug
|
||||||
|
return Heimdall_Data.config.noter.debug
|
||||||
|
end)
|
||||||
|
debugButton:UpdateColor(Heimdall_Data.config.noter.debug)
|
||||||
|
noterConfigFrame:Add(debugButton, 1, 4)
|
||||||
|
|
||||||
|
local enableButton = CreateBasicButton("HeimdallNoterConfigEnableButton",
|
||||||
|
noterConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.enabled, function()
|
||||||
|
Heimdall_Data.config.noter.enabled = not Heimdall_Data.config.noter.enabled
|
||||||
|
return Heimdall_Data.config.noter.enabled
|
||||||
|
end)
|
||||||
|
enableButton:UpdateColor(Heimdall_Data.config.noter.enabled)
|
||||||
|
noterConfigFrame:Add(enableButton, 2, 6)
|
||||||
|
|
||||||
|
local masterChannel = CreateBasicSmallEditBox("HeimdallNoterConfigMasterChannel",
|
||||||
|
noterConfigFrame.frame, shared.L[Heimdall_Data.config.locale].config.masterChannel,
|
||||||
|
Heimdall_Data.config.noter.masterChannel,
|
||||||
|
function(self)
|
||||||
|
local text = self:GetText()
|
||||||
|
if string.match(text, "%S+") then
|
||||||
|
Heimdall_Data.config.noter.masterChannel = text
|
||||||
|
print("Master channel set to", tostring(text))
|
||||||
|
else
|
||||||
|
print("Invalid master channel", tostring(text))
|
||||||
|
self:SetText(Heimdall_Data.config.noter.masterChannel)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
noterConfigFrame:Add(masterChannel, 2, 6)
|
||||||
|
end
|
||||||
|
|
||||||
-- Whisper Notify
|
-- Whisper Notify
|
||||||
do
|
do
|
||||||
local r, g, b, a = GetNextColor()
|
local r, g, b, a = GetNextColor()
|
||||||
|
113
Modules/Noter.lua
Normal file
113
Modules/Noter.lua
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
local addonname, shared = ...
|
||||||
|
---@cast shared HeimdallShared
|
||||||
|
---@cast addonname string
|
||||||
|
local ModuleName = "Noter"
|
||||||
|
|
||||||
|
---@class Note
|
||||||
|
---@field source string
|
||||||
|
---@field for string
|
||||||
|
---@field date string
|
||||||
|
---@field note string
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: missing-fields
|
||||||
|
shared.Noter = {}
|
||||||
|
function shared.Noter.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
|
||||||
|
|
||||||
|
-- Here's the plan:
|
||||||
|
-- Implement a "note" command, that will do everything
|
||||||
|
-- Saying "note <name> <note>" will add a note to the list for the character
|
||||||
|
-- Saying "note <name>" will list last N notes
|
||||||
|
-- Saying "note <name> i" will list the i-th note
|
||||||
|
-- Saying "note <name> i..j" will list notes from i to j
|
||||||
|
-- Saying "note delete <name> i" will delete the i-th note
|
||||||
|
-- Saying "note delete <name> i..j" will delete notes from i to j
|
||||||
|
local noterChannelFrame = CreateFrame("Frame")
|
||||||
|
noterChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||||
|
noterChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||||
|
--if Heimdall_Data.config.noter.debug then
|
||||||
|
-- print(string.format("[%s] Event received", ModuleName))
|
||||||
|
-- shared.dumpTable(Heimdall_Data.config.noter)
|
||||||
|
--end
|
||||||
|
if not Heimdall_Data.config.noter.enabled then
|
||||||
|
--if Heimdall_Data.config.noter.debug then
|
||||||
|
-- print(string.format("[%s] Module disabled, ignoring event", ModuleName))
|
||||||
|
--end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local channelId = select(6, ...)
|
||||||
|
local _, channelname = GetChannelName(channelId)
|
||||||
|
--if Heimdall_Data.config.noter.debug then
|
||||||
|
-- print(string.format("[%s] Channel received: %s", ModuleName, channelname))
|
||||||
|
--end
|
||||||
|
if channelname ~= Heimdall_Data.config.noter.masterChannel then
|
||||||
|
--if Heimdall_Data.config.noter.debug then
|
||||||
|
-- print(string.format("[%s] Channel %s does not match master channel %s", ModuleName, channelname, Heimdall_Data.config.noter.masterChannel))
|
||||||
|
--end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
sender = string.match(sender, "^[^-]+")
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Message from: %s", ModuleName, sender))
|
||||||
|
shared.dumpTable(Heimdall_Data.config.noter)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, command in ipairs(commands) do
|
||||||
|
local enabled = Heimdall_Data.config.noter.commands[command.keywordRe] == true or false
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled)))
|
||||||
|
end
|
||||||
|
if enabled and
|
||||||
|
(not command.commanderOnly
|
||||||
|
or (command.commanderOnly
|
||||||
|
and sender == Heimdall_Data.config.noter.commander)) then
|
||||||
|
if msg:match(command.keywordRe) then
|
||||||
|
local messages = command.callback({ strsplit(",", msg) })
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Messages to send: %s", ModuleName, strjoin(", ", unpack(messages))))
|
||||||
|
end
|
||||||
|
for _, message in ipairs(messages) do
|
||||||
|
---@type Message
|
||||||
|
local msg = {
|
||||||
|
channel = "CHANNEL",
|
||||||
|
data = channelname,
|
||||||
|
message = message
|
||||||
|
}
|
||||||
|
table.insert(shared.messenger.queue, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
print("[Heimdall] Commander module loaded")
|
||||||
|
end
|
2
_L.lua
2
_L.lua
@@ -72,6 +72,7 @@ shared.L = {
|
|||||||
throttle = "Throttle",
|
throttle = "Throttle",
|
||||||
ttl = "TTL",
|
ttl = "TTL",
|
||||||
whisperNotify = "Whisper Notify",
|
whisperNotify = "Whisper Notify",
|
||||||
|
noter = "Noter",
|
||||||
whoer = "Whoer",
|
whoer = "Whoer",
|
||||||
zoneNotifyFor = "Zone Notify For",
|
zoneNotifyFor = "Zone Notify For",
|
||||||
zoneOverride = "Zone Override",
|
zoneOverride = "Zone Override",
|
||||||
@@ -146,6 +147,7 @@ shared.L = {
|
|||||||
stinkies = "Неприятные Запахи",
|
stinkies = "Неприятные Запахи",
|
||||||
stinky = "Неприятный",
|
stinky = "Неприятный",
|
||||||
stinkyTracker = "Трекер Неприятных Запахов",
|
stinkyTracker = "Трекер Неприятных Запахов",
|
||||||
|
noter = "Нотер",
|
||||||
throttle = "Тхроттлер",
|
throttle = "Тхроттлер",
|
||||||
ttl = "TTL",
|
ttl = "TTL",
|
||||||
whisperNotify = "Уведомление Шепотом",
|
whisperNotify = "Уведомление Шепотом",
|
||||||
|
Reference in New Issue
Block a user