-- "Выключи музыку через 30 минут" → scheduler one-shot фраза-команда "пауза" local phrase = (jarvis.context.phrase or ""):lower() local n_str, unit = phrase:match("(%d+)%s+(%S+)") if not n_str then return jarvis.cmd.error("Не понял через сколько.") end local n = tonumber(n_str) local secs if unit:match("^минут") then secs = "in " .. n .. " minutes" elseif unit:match("^час") then secs = "in " .. n .. " hours" elseif unit:match("^секунд") then secs = "in " .. n .. " seconds" else return jarvis.cmd.error("Не понял единицу.") end -- Build path to media_keys/_media.ps1 (lives next door) local cmd_path = jarvis.context.command_path local helper = cmd_path:gsub("sleep_timer$", "media_keys") .. "\\_media.ps1" helper = helper:gsub("/", "\\") -- VK_MEDIA_PLAY_PAUSE = 0xB3 = 179 local lua_path = cmd_path:gsub("\\", "/") .. "/_pause_lua.lua" -- Simpler: just speak "пауза" and let agent router handle it? No — agent -- router only fires for unmatched commands. Better: directly invoke media key -- via a one-shot Lua script. local script_path = cmd_path .. "\\_fire_pause.lua" script_path = script_path:gsub("/", "\\") -- Write the helper script once local exists = jarvis.fs.is_file(script_path) if not exists then jarvis.fs.write(script_path, string.format([[ local helper = "%s" jarvis.system.exec(string.format( 'powershell -NoProfile -ExecutionPolicy Bypass -File "%%s" 179', helper )) return { chain = false } ]], helper:gsub("\\", "\\\\"))) end local ok, err = pcall(function() jarvis.scheduler.remove("sleep_timer_pause") jarvis.scheduler.add({ id = "sleep_timer_pause", name = "Sleep timer: pause music", schedule = secs, action = { type = "lua", script_path = script_path }, }) end) if not ok then jarvis.log("warn", "sleep_timer.pause_in: " .. tostring(err)) return jarvis.cmd.error("Не получилось.") end return jarvis.cmd.ok("Поставлю на паузу через " .. n_str .. " " .. unit .. ".")