diff --git a/resources/commands/media/_media_helper.ps1 b/resources/commands/media/_media_helper.ps1 new file mode 100644 index 0000000..130aedc --- /dev/null +++ b/resources/commands/media/_media_helper.ps1 @@ -0,0 +1,20 @@ +param( + [Parameter(Mandatory=$true)] + [ValidateSet("play_pause","next","prev","stop")] + [string]$Action +) + +Add-Type -Name MediaKey -Namespace Win32 -MemberDefinition @' +[DllImport("user32.dll")] +public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, System.UIntPtr dwExtraInfo); +'@ + +$vk = switch ($Action) { + "play_pause" { 0xB3 } + "next" { 0xB0 } + "prev" { 0xB1 } + "stop" { 0xB2 } +} + +[Win32.MediaKey]::keybd_event($vk, 0, 0, [UIntPtr]::Zero) +[Win32.MediaKey]::keybd_event($vk, 0, 2, [UIntPtr]::Zero) diff --git a/resources/commands/media/command.toml b/resources/commands/media/command.toml new file mode 100644 index 0000000..f73838e --- /dev/null +++ b/resources/commands/media/command.toml @@ -0,0 +1,103 @@ +[[commands]] +id = "media_play_pause" +type = "lua" +script = "play_pause.lua" +sandbox = "full" +timeout = 3000 + +[commands.phrases] +ru = [ + "пауза", + "поставь на паузу", + "продолжи", + "включи музыку", + "запусти музыку", + "плей", +] +en = [ + "pause", + "play", + "resume", + "play music", +] +ua = [ + "пауза", + "продовж", + "включи музику", +] + + +[[commands]] +id = "media_next" +type = "lua" +script = "next_track.lua" +sandbox = "full" +timeout = 3000 + +[commands.phrases] +ru = [ + "следующий трек", + "следующая песня", + "переключи трек", + "следующая", + "дальше", +] +en = [ + "next track", + "next song", + "skip", + "next", +] +ua = [ + "наступний трек", + "наступна пісня", + "далі", +] + + +[[commands]] +id = "media_prev" +type = "lua" +script = "prev_track.lua" +sandbox = "full" +timeout = 3000 + +[commands.phrases] +ru = [ + "предыдущий трек", + "предыдущая песня", + "верни песню", + "назад", +] +en = [ + "previous track", + "previous song", + "back", +] +ua = [ + "попередній трек", + "назад", +] + + +[[commands]] +id = "media_stop" +type = "lua" +script = "stop_media.lua" +sandbox = "full" +timeout = 3000 + +[commands.phrases] +ru = [ + "стоп музыка", + "останови музыку", + "выключи музыку", +] +en = [ + "stop music", + "stop playback", +] +ua = [ + "стоп музика", + "вимкни музику", +] diff --git a/resources/commands/media/next_track.lua b/resources/commands/media/next_track.lua new file mode 100644 index 0000000..7a8eeb7 --- /dev/null +++ b/resources/commands/media/next_track.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_media_helper.ps1" +local cmd = string.format( + 'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action next', + helper +) +local res = jarvis.system.exec(cmd) +if res.success then + jarvis.audio.play_ok() +else + jarvis.log("error", "media next failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/media/play_pause.lua b/resources/commands/media/play_pause.lua new file mode 100644 index 0000000..d54358a --- /dev/null +++ b/resources/commands/media/play_pause.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_media_helper.ps1" +local cmd = string.format( + 'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action play_pause', + helper +) +local res = jarvis.system.exec(cmd) +if res.success then + jarvis.audio.play_ok() +else + jarvis.log("error", "play/pause failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/media/prev_track.lua b/resources/commands/media/prev_track.lua new file mode 100644 index 0000000..16da444 --- /dev/null +++ b/resources/commands/media/prev_track.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_media_helper.ps1" +local cmd = string.format( + 'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action prev', + helper +) +local res = jarvis.system.exec(cmd) +if res.success then + jarvis.audio.play_ok() +else + jarvis.log("error", "media prev failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/media/stop_media.lua b/resources/commands/media/stop_media.lua new file mode 100644 index 0000000..d458b24 --- /dev/null +++ b/resources/commands/media/stop_media.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_media_helper.ps1" +local cmd = string.format( + 'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action stop', + helper +) +local res = jarvis.system.exec(cmd) +if res.success then + jarvis.audio.play_ok() +else + jarvis.log("error", "media stop failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/sysinfo/_sysinfo.ps1 b/resources/commands/sysinfo/_sysinfo.ps1 new file mode 100644 index 0000000..ae020a3 --- /dev/null +++ b/resources/commands/sysinfo/_sysinfo.ps1 @@ -0,0 +1,69 @@ +param( + [Parameter(Mandatory=$true)] + [ValidateSet("battery","time","cpu","ram","disk","all")] + [string]$Topic +) + +$ErrorActionPreference = 'SilentlyContinue' + +function Get-BatteryInfo { + $b = Get-CimInstance -ClassName Win32_Battery + if (-not $b) { return "Батарея не обнаружена (видимо, десктоп)" } + $pct = [int]$b.EstimatedChargeRemaining + $status = switch ($b.BatteryStatus) { + 1 { "разряжается" } + 2 { "от сети" } + 3 { "заряжена" } + 4 { "низкий заряд" } + 5 { "критический заряд" } + default { "статус $($b.BatteryStatus)" } + } + return "Батарея: $pct%, $status" +} + +function Get-TimeInfo { + $ru = [System.Globalization.CultureInfo]::GetCultureInfo("ru-RU") + $now = Get-Date + return "Сейчас: " + $now.ToString("HH:mm, dd MMMM, dddd", $ru) +} + +function Get-CpuInfo { + $cpu = Get-CimInstance -ClassName Win32_Processor | Select-Object -First 1 + $load = (Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Processor -Filter "Name='_Total'" -ErrorAction SilentlyContinue).PercentProcessorTime + if ($null -eq $load) { $load = $cpu.LoadPercentage } + return "CPU: $($cpu.Name.Trim()), загрузка $load%" +} + +function Get-RamInfo { + $os = Get-CimInstance -ClassName Win32_OperatingSystem + $totalGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 1) + $freeGB = [math]::Round($os.FreePhysicalMemory / 1MB, 1) + $usedGB = [math]::Round($totalGB - $freeGB, 1) + $pct = [int](($usedGB / $totalGB) * 100) + return "RAM: $usedGB из $totalGB ГБ ($pct% занято)" +} + +function Get-DiskInfo { + $sys = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='$($env:SystemDrive)'" + if (-not $sys) { + $sys = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | Select-Object -First 1 + } + $freeGB = [math]::Round($sys.FreeSpace / 1GB, 1) + $totalGB = [math]::Round($sys.Size / 1GB, 1) + return "Диск $($sys.DeviceID): свободно $freeGB из $totalGB ГБ" +} + +switch ($Topic) { + "battery" { Get-BatteryInfo } + "time" { Get-TimeInfo } + "cpu" { Get-CpuInfo } + "ram" { Get-RamInfo } + "disk" { Get-DiskInfo } + "all" { + Get-TimeInfo + Get-BatteryInfo + Get-CpuInfo + Get-RamInfo + Get-DiskInfo + } +} diff --git a/resources/commands/sysinfo/all.lua b/resources/commands/sysinfo/all.lua new file mode 100644 index 0000000..2529e41 --- /dev/null +++ b/resources/commands/sysinfo/all.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_sysinfo.ps1" +local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic all', helper) +local res = jarvis.system.exec(cmd) +local text = (res.stdout or ""):gsub("[\r\n]+$", "") +if res.success and text ~= "" then + jarvis.system.notify("Статус системы", text) + jarvis.log("info", text) + jarvis.audio.play_ok() +else + jarvis.log("error", "sysinfo all failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/sysinfo/battery.lua b/resources/commands/sysinfo/battery.lua new file mode 100644 index 0000000..0ae2f2c --- /dev/null +++ b/resources/commands/sysinfo/battery.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_sysinfo.ps1" +local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic battery', helper) +local res = jarvis.system.exec(cmd) +local text = (res.stdout or ""):gsub("[\r\n]+$", "") +if res.success and text ~= "" then + jarvis.system.notify("Батарея", text) + jarvis.log("info", text) + jarvis.audio.play_ok() +else + jarvis.log("error", "battery info failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/sysinfo/command.toml b/resources/commands/sysinfo/command.toml new file mode 100644 index 0000000..59e3430 --- /dev/null +++ b/resources/commands/sysinfo/command.toml @@ -0,0 +1,152 @@ +[[commands]] +id = "sysinfo_battery" +type = "lua" +script = "battery.lua" +sandbox = "full" +timeout = 5000 + +[commands.phrases] +ru = [ + "сколько заряда", + "сколько батарея", + "заряд батареи", + "сколько процентов", +] +en = [ + "battery level", + "how much battery", + "battery status", +] +ua = [ + "скільки заряду", + "заряд батареї", +] + + +[[commands]] +id = "sysinfo_time" +type = "lua" +script = "time.lua" +sandbox = "full" +timeout = 3000 + +[commands.phrases] +ru = [ + "сколько времени", + "который час", + "сколько сейчас времени", + "какой день", + "какое сегодня число", +] +en = [ + "what time is it", + "current time", + "what day is it", + "what is the date", +] +ua = [ + "котра година", + "скільки часу", + "який сьогодні день", +] + + +[[commands]] +id = "sysinfo_cpu" +type = "lua" +script = "cpu.lua" +sandbox = "full" +timeout = 8000 + +[commands.phrases] +ru = [ + "загрузка процессора", + "сколько процессор", + "нагрузка цпу", + "что с процессором", +] +en = [ + "cpu load", + "cpu usage", + "how is cpu", +] +ua = [ + "завантаження процесора", + "як процесор", +] + + +[[commands]] +id = "sysinfo_ram" +type = "lua" +script = "ram.lua" +sandbox = "full" +timeout = 5000 + +[commands.phrases] +ru = [ + "сколько памяти", + "сколько оперативки", + "загрузка оперативки", + "сколько свободной памяти", +] +en = [ + "how much ram", + "ram usage", + "memory usage", +] +ua = [ + "скільки пам'яті", + "скільки оперативки", +] + + +[[commands]] +id = "sysinfo_disk" +type = "lua" +script = "disk.lua" +sandbox = "full" +timeout = 5000 + +[commands.phrases] +ru = [ + "сколько свободно на диске", + "сколько места на диске", + "сколько места на жёстком", + "сколько свободно", +] +en = [ + "free disk space", + "how much disk space", + "disk usage", +] +ua = [ + "скільки вільно на диску", + "скільки місця на диску", +] + + +[[commands]] +id = "sysinfo_all" +type = "lua" +script = "all.lua" +sandbox = "full" +timeout = 10000 + +[commands.phrases] +ru = [ + "статус системы", + "что с компьютером", + "состояние пк", + "что по системе", + "статус", +] +en = [ + "system status", + "how is the system", + "pc status", +] +ua = [ + "статус системи", + "стан пк", +] diff --git a/resources/commands/sysinfo/cpu.lua b/resources/commands/sysinfo/cpu.lua new file mode 100644 index 0000000..5590376 --- /dev/null +++ b/resources/commands/sysinfo/cpu.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_sysinfo.ps1" +local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic cpu', helper) +local res = jarvis.system.exec(cmd) +local text = (res.stdout or ""):gsub("[\r\n]+$", "") +if res.success and text ~= "" then + jarvis.system.notify("CPU", text) + jarvis.log("info", text) + jarvis.audio.play_ok() +else + jarvis.log("error", "cpu info failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/sysinfo/disk.lua b/resources/commands/sysinfo/disk.lua new file mode 100644 index 0000000..813172f --- /dev/null +++ b/resources/commands/sysinfo/disk.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_sysinfo.ps1" +local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic disk', helper) +local res = jarvis.system.exec(cmd) +local text = (res.stdout or ""):gsub("[\r\n]+$", "") +if res.success and text ~= "" then + jarvis.system.notify("Диск", text) + jarvis.log("info", text) + jarvis.audio.play_ok() +else + jarvis.log("error", "disk info failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/sysinfo/ram.lua b/resources/commands/sysinfo/ram.lua new file mode 100644 index 0000000..1ad8208 --- /dev/null +++ b/resources/commands/sysinfo/ram.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_sysinfo.ps1" +local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic ram', helper) +local res = jarvis.system.exec(cmd) +local text = (res.stdout or ""):gsub("[\r\n]+$", "") +if res.success and text ~= "" then + jarvis.system.notify("Память", text) + jarvis.log("info", text) + jarvis.audio.play_ok() +else + jarvis.log("error", "ram info failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false } diff --git a/resources/commands/sysinfo/time.lua b/resources/commands/sysinfo/time.lua new file mode 100644 index 0000000..de4e2b6 --- /dev/null +++ b/resources/commands/sysinfo/time.lua @@ -0,0 +1,13 @@ +local helper = jarvis.context.command_path .. "\\_sysinfo.ps1" +local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Topic time', helper) +local res = jarvis.system.exec(cmd) +local text = (res.stdout or ""):gsub("[\r\n]+$", "") +if res.success and text ~= "" then + jarvis.system.notify("Время", text) + jarvis.log("info", text) + jarvis.audio.play_ok() +else + jarvis.log("error", "time info failed: " .. tostring(res.stderr)) + jarvis.audio.play_error() +end +return { chain = false }