Implement note delete
Weird start, I know
This commit is contained in:
@@ -48,8 +48,8 @@ function shared.Noter.Init()
|
|||||||
-- Saying "note <name>" will list last N notes
|
-- Saying "note <name>" will list last N notes
|
||||||
-- Saying "note <name> i" will list the i-th note
|
-- Saying "note <name> i" will list the i-th note
|
||||||
-- Saying "note <name> i..j" will list notes from i to j
|
-- 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 <name> delete i" will delete the i-th note
|
||||||
-- Saying "note delete <name> i..j" will delete notes from i to j
|
-- Saying "note <name> delete i..j" will delete notes from i to j
|
||||||
local noterChannelFrame = CreateFrame("Frame")
|
local noterChannelFrame = CreateFrame("Frame")
|
||||||
noterChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL")
|
noterChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL")
|
||||||
noterChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
noterChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
|
||||||
@@ -81,28 +81,69 @@ function shared.Noter.Init()
|
|||||||
shared.dumpTable(Heimdall_Data.config.noter)
|
shared.dumpTable(Heimdall_Data.config.noter)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, command in ipairs(commands) do
|
if not msg or msg == "" then
|
||||||
local enabled = Heimdall_Data.config.noter.commands[command.keywordRe] == true or false
|
|
||||||
if Heimdall_Data.config.noter.debug then
|
if Heimdall_Data.config.noter.debug then
|
||||||
print(string.format("[%s] Command match: %s = %s", ModuleName, command.keywordRe, tostring(enabled)))
|
print(string.format("[%s] Empty message, ignoring", ModuleName))
|
||||||
end
|
end
|
||||||
if enabled and
|
return
|
||||||
(not command.commanderOnly
|
end
|
||||||
or (command.commanderOnly
|
|
||||||
and sender == Heimdall_Data.config.noter.commander)) then
|
local args = { strsplit(" ", msg) }
|
||||||
if msg:match(command.keywordRe) then
|
if Heimdall_Data.config.noter.debug then
|
||||||
local messages = command.callback({ strsplit(",", msg) })
|
print(string.format("[%s] Arguments received: %s", ModuleName, table.concat(args, ", ")))
|
||||||
|
shared.dumpTable(args)
|
||||||
|
end
|
||||||
|
local command = args[1]
|
||||||
|
if command == "note" then
|
||||||
|
local name = strtrim(string.lower(args[2]))
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Note command received for: %s", ModuleName, name))
|
||||||
|
end
|
||||||
|
local note = strtrim(args[3])
|
||||||
|
if note == "delete" then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Delete note command received for: %s", ModuleName, name))
|
||||||
|
end
|
||||||
|
local range = args[4]
|
||||||
|
if range then
|
||||||
if Heimdall_Data.config.noter.debug then
|
if Heimdall_Data.config.noter.debug then
|
||||||
print(string.format("[%s] Messages to send: %s", ModuleName, strjoin(", ", unpack(messages))))
|
print(string.format("[%s] Range received for delete note: %s", ModuleName, range))
|
||||||
end
|
end
|
||||||
for _, message in ipairs(messages) do
|
local indices = shared.Split(range, "..")
|
||||||
---@type Message
|
if Heimdall_Data.config.noter.debug then
|
||||||
local msg = {
|
print(string.format("[%s] Indices for range deletion: %s", ModuleName,
|
||||||
channel = "CHANNEL",
|
table.concat(indices, ", ")))
|
||||||
data = channelname,
|
shared.dumpTable(indices)
|
||||||
message = message
|
end
|
||||||
}
|
local start = tonumber(indices[1])
|
||||||
table.insert(shared.messenger.queue, msg)
|
local finish = tonumber(indices[2])
|
||||||
|
|
||||||
|
if not start then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Invalid start range for delete note: %s", ModuleName,
|
||||||
|
tostring(start)))
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not finish then finish = start end
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Deleting note range %s to %s for: %s", ModuleName, start, finish, name))
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = start, finish do
|
||||||
|
if not Heimdall_Data.config.notes[name] then Heimdall_Data.config.notes[name] = {} end
|
||||||
|
if not Heimdall_Data.config.notes[name][i] then
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Note at index %s does not exist", ModuleName, i))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if Heimdall_Data.config.noter.debug then
|
||||||
|
print(string.format("[%s] Deleting note %s at index %s", ModuleName, name, i))
|
||||||
|
shared.dumpTable(Heimdall_Data.config.notes[name][i])
|
||||||
|
end
|
||||||
|
Heimdall_Data.config.notes[name][i] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user