46 lines
2.6 KiB
Lua
46 lines
2.6 KiB
Lua
|
|
local cmd_id = jarvis.context.command_id
|
|||
|
|
local lang = jarvis.context.language
|
|||
|
|
|
|||
|
|
local actions = {
|
|||
|
|
shutdown_pc = { cmd = 'shutdown.exe /s /t 30 /c "J.A.R.V.I.S.: shutdown in 30s. Say cancel to abort."', label = lang == "ru" and "Выключение через 30 секунд" or "Shutdown in 30 sec" },
|
|||
|
|
restart_pc = { cmd = 'shutdown.exe /r /t 30 /c "J.A.R.V.I.S.: restart in 30s. Say cancel to abort."', label = lang == "ru" and "Перезагрузка через 30 секунд" or "Restart in 30 sec" },
|
|||
|
|
logoff_user = { cmd = 'shutdown.exe /l', label = lang == "ru" and "Выход из системы" or "Sign out" },
|
|||
|
|
sleep_pc = { cmd = 'rundll32.exe powrprof.dll,SetSuspendState 0,1,0', label = lang == "ru" and "Сон" or "Sleep" },
|
|||
|
|
hibernate_pc = { cmd = 'shutdown.exe /h', label = lang == "ru" and "Гибернация" or "Hibernate" },
|
|||
|
|
cancel_shutdown = { cmd = 'shutdown.exe /a', label = lang == "ru" and "Выключение отменено" or "Shutdown cancelled" },
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
local a = actions[cmd_id]
|
|||
|
|
if not a then
|
|||
|
|
jarvis.audio.play_error()
|
|||
|
|
return { chain = false }
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local res = jarvis.system.exec(a.cmd)
|
|||
|
|
local ok = res.success
|
|||
|
|
|
|||
|
|
if not ok and cmd_id == "cancel_shutdown" then
|
|||
|
|
ok = true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if ok then
|
|||
|
|
jarvis.system.notify("Power", a.label)
|
|||
|
|
jarvis.log("info", "power: " .. cmd_id .. " -> " .. a.label)
|
|||
|
|
local say = a.label .. ". " .. (cmd_id == "shutdown_pc" or cmd_id == "restart_pc"
|
|||
|
|
and (lang == "ru" and "Скажи отмени если передумал, сэр." or "Say cancel to abort, sir.")
|
|||
|
|
or "")
|
|||
|
|
local sapi = say:gsub("'", "''"):gsub("\r?\n", " ")
|
|||
|
|
local ps = string.format(
|
|||
|
|
[[Add-Type -AssemblyName System.Speech; $s = New-Object System.Speech.Synthesis.SpeechSynthesizer; foreach ($v in $s.GetInstalledVoices()) { if ($v.VoiceInfo.Culture.TwoLetterISOLanguageName -eq 'ru') { try { $s.SelectVoice($v.VoiceInfo.Name); break } catch {} } } $s.Speak('%s')]],
|
|||
|
|
sapi
|
|||
|
|
)
|
|||
|
|
jarvis.system.exec(string.format('powershell -NoProfile -Command "%s"', ps:gsub('"', '\\"')))
|
|||
|
|
jarvis.audio.play_ok()
|
|||
|
|
else
|
|||
|
|
jarvis.log("error", "power " .. cmd_id .. " failed: " .. tostring(res.stderr):sub(1, 200))
|
|||
|
|
jarvis.system.notify("Power", (lang == "ru" and "Не получилось: " or "Failed: ") .. cmd_id)
|
|||
|
|
jarvis.audio.play_error()
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return { chain = false }
|