57 lines
1.7 KiB
Lua
57 lines
1.7 KiB
Lua
|
|
local lang = jarvis.context.language
|
|||
|
|
local phrase = (jarvis.context.phrase or ""):lower()
|
|||
|
|
|
|||
|
|
local triggers = {
|
|||
|
|
"запиши заметку", "запиши идею", "сделай заметку", "запомни идею",
|
|||
|
|
"запиши", "запомни",
|
|||
|
|
"write down", "take a note", "remember this", "note down",
|
|||
|
|
"запиши ідею", "зроби нотатку",
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
local body = phrase
|
|||
|
|
for _, t in ipairs(triggers) do
|
|||
|
|
local s, e = string.find(body, t, 1, true)
|
|||
|
|
if s == 1 then
|
|||
|
|
body = body:sub(e + 1)
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
body = body:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
|
|||
|
|
|
|||
|
|
if body == "" then
|
|||
|
|
jarvis.system.notify(
|
|||
|
|
lang == "ru" and "Заметка" or "Note",
|
|||
|
|
lang == "ru" and "Что записать?" or "What to write?"
|
|||
|
|
)
|
|||
|
|
jarvis.audio.play_error()
|
|||
|
|
return { chain = false }
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
|||
|
|
local notes_path = userprofile .. "\\Documents\\jarvis-notes.txt"
|
|||
|
|
|
|||
|
|
local t = jarvis.context.time
|
|||
|
|
local stamp = string.format("%s-%s-%s %s:%s",
|
|||
|
|
t.year, t.month, t.day, t.hour, t.minute)
|
|||
|
|
|
|||
|
|
local line = string.format("[%s] %s\n", stamp, body)
|
|||
|
|
|
|||
|
|
local ok, err = pcall(function()
|
|||
|
|
jarvis.fs.append(notes_path, line)
|
|||
|
|
end)
|
|||
|
|
|
|||
|
|
if not ok then
|
|||
|
|
jarvis.log("error", "notes append failed: " .. tostring(err))
|
|||
|
|
jarvis.system.notify("Заметка", lang == "ru" and "Не удалось записать" or "Append failed")
|
|||
|
|
jarvis.audio.play_error()
|
|||
|
|
return { chain = false }
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
jarvis.log("info", "note appended: " .. body)
|
|||
|
|
jarvis.system.notify(
|
|||
|
|
lang == "ru" and "Заметка записана" or "Note saved",
|
|||
|
|
body:sub(1, 120)
|
|||
|
|
)
|
|||
|
|
jarvis.audio.play_ok()
|
|||
|
|
return { chain = false }
|