J.A.R.V.I.S-rust/resources/commands/routines/good_night.lua

50 lines
2 KiB
Lua
Raw Permalink Normal View History

-- "Good night" routine:
-- 1. switch active profile to "sleep" (so idle-banter shuts up overnight)
-- 2. clear any one-shot pending reminders that would wake the user up
-- after midnight — daily ones stay (those are intentional)
-- 3. wish good night with a varied line
-- We deliberately DO NOT lock the PC / power off displays / sleep — too
-- destructive without explicit user confirmation, easy to misfire.
local lang = jarvis.context.language
-- 1) Switch to "sleep" profile (best effort)
pcall(function() jarvis.profile.set("sleep") end)
-- 2) Cancel one-shot timers that look user-set (anything starting with
-- "Таймер:" or "Timer:" — the prefix our reminders/set.lua uses).
local cancelled = 0
for _, task in ipairs(jarvis.scheduler.list() or {}) do
local n = task.name or ""
if n:find("^Таймер:") or n:find("^Timer:") or n:find("^Кухня:")
or n:find("^Cooking:") then
jarvis.scheduler.remove(task.id)
cancelled = cancelled + 1
end
end
local lines_ru = {
"Спокойной ночи, сэр. Я остаюсь на связи.",
"Доброй ночи, сэр. Системы переведены в тихий режим.",
"Спите крепко, сэр. Утром доложу о всём важном.",
"Хорошо, сэр. Не отвлекаю до утра.",
"Спокойной ночи. Завтра ещё один день.",
}
local lines_en = {
"Good night, sir. I'll be on standby.",
"Sleep well, sir. Systems set to quiet.",
"Good night, sir. I'll brief you in the morning.",
"Very well, sir. Quiet mode until dawn.",
"Good night. Tomorrow's another day.",
}
local pool = (lang == "ru") and lines_ru or lines_en
local line = pool[math.random(#pool)]
if cancelled > 0 then
line = line .. (lang == "ru"
and (" Отменил " .. tostring(cancelled) .. " одноразовых таймеров.")
or (" Cancelled " .. tostring(cancelled) .. " one-shot timers."))
end
return jarvis.cmd.ok(line)