basic Lua 5.4 implementation with few example commands
This commit is contained in:
parent
11c2500d9c
commit
7440baa1b2
35 changed files with 2554 additions and 460 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[[commands]]
|
||||
id = "browser_open"
|
||||
action = "ahk"
|
||||
type = "ahk"
|
||||
exe_path = "ahk/Run browser.exe"
|
||||
sounds.ru = ["ok1", "ok2", "ok3", "ok4"]
|
||||
sounds.en = ["ok1", "ok2", "ok3"]
|
||||
|
|
@ -36,7 +36,7 @@ phrases.ua = [
|
|||
|
||||
[[commands]]
|
||||
id = "browser_close"
|
||||
action = "ahk"
|
||||
type = "ahk"
|
||||
exe_path = "ahk/Close browser.exe"
|
||||
sounds.ru = ["ok1", "ok2", "ok3", "ok4"]
|
||||
sounds.en = ["ok1", "ok2", "ok3"]
|
||||
|
|
@ -64,7 +64,7 @@ phrases.ua = [
|
|||
|
||||
[[commands]]
|
||||
id = "open_google"
|
||||
action = "ahk"
|
||||
type = "ahk"
|
||||
exe_path = "ahk/Run website.exe"
|
||||
exe_args = ["http://google.com"]
|
||||
sounds.ru = ["ok1", "ok2", "ok3", "ok4"]
|
||||
|
|
|
|||
13
resources/commands/counter/command.toml
Normal file
13
resources/commands/counter/command.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[[commands]]
|
||||
id = "counter"
|
||||
type = "lua"
|
||||
script = "script.lua"
|
||||
sandbox = "standard"
|
||||
timeout = 5000
|
||||
phrases.ru = [
|
||||
"счётчик"
|
||||
]
|
||||
phrases.en = [
|
||||
"counter",
|
||||
"count",
|
||||
]
|
||||
16
resources/commands/counter/script.lua
Normal file
16
resources/commands/counter/script.lua
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-- simple counter demonstrating state persistence
|
||||
|
||||
local count = jarvis.state.get("count") or 0
|
||||
count = count + 1
|
||||
jarvis.state.set("count", count)
|
||||
|
||||
local lang = jarvis.context.language
|
||||
local msg = lang == "ru"
|
||||
and "Счётчик: " .. count
|
||||
or "Counter: " .. count
|
||||
|
||||
jarvis.log("info", msg)
|
||||
jarvis.system.notify("Counter", tostring(count))
|
||||
jarvis.audio.play_ok()
|
||||
|
||||
return { chain = true }
|
||||
14
resources/commands/hello/command.toml
Normal file
14
resources/commands/hello/command.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[[commands]]
|
||||
id = "hello"
|
||||
type = "lua"
|
||||
script = "script.lua"
|
||||
sandbox = "minimal"
|
||||
timeout = 5000
|
||||
phrases.ru = [
|
||||
"привет",
|
||||
"здравствуй",
|
||||
]
|
||||
phrases.en = [
|
||||
"hello",
|
||||
"hi",
|
||||
]
|
||||
21
resources/commands/hello/script.lua
Normal file
21
resources/commands/hello/script.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-- simple test hello command
|
||||
|
||||
local lang = jarvis.context.language
|
||||
local hour = tonumber(jarvis.context.time.hour)
|
||||
|
||||
-- determine greeting based on time
|
||||
local greeting
|
||||
if hour >= 5 and hour < 12 then
|
||||
greeting = lang == "ru" and "Доброе утро" or "Good morning"
|
||||
elseif hour >= 12 and hour < 17 then
|
||||
greeting = lang == "ru" and "Добрый день" or "Good afternoon"
|
||||
elseif hour >= 17 and hour < 22 then
|
||||
greeting = lang == "ru" and "Добрый вечер" or "Good evening"
|
||||
else
|
||||
greeting = lang == "ru" and "Доброй ночи" or "Good night"
|
||||
end
|
||||
|
||||
jarvis.log("info", "Greeting user: " .. greeting)
|
||||
jarvis.audio.play_reply()
|
||||
|
||||
return { chain = true }
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
[[commands]]
|
||||
id = "weather"
|
||||
action = "cli"
|
||||
cli_cmd = "weather.py"
|
||||
type = "lua"
|
||||
script = "script.lua"
|
||||
timeout = 5000
|
||||
sandbox = "standard"
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
|
|
@ -15,4 +17,18 @@ en = [
|
|||
|
||||
[commands.sounds]
|
||||
ru = ["weather_ru_1", "weather_ru_2"]
|
||||
en = ["weather_en_1", "weather_en_2"]
|
||||
en = ["weather_en_1", "weather_en_2"]
|
||||
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "set_city"
|
||||
type = "lua"
|
||||
script = "set_city.lua"
|
||||
sandbox = "standard"
|
||||
timeout = 5000
|
||||
phrases = [
|
||||
"установи город",
|
||||
"set city",
|
||||
"change city",
|
||||
]
|
||||
29
resources/commands/weather/script.lua
Normal file
29
resources/commands/weather/script.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
-- weather command using wttr.in API
|
||||
|
||||
local lang = jarvis.context.language
|
||||
|
||||
-- get saved city or use default
|
||||
local city = jarvis.state.get("city") or "Moscow"
|
||||
|
||||
jarvis.log("info", "Fetching weather for: " .. city)
|
||||
|
||||
-- build URL
|
||||
local url = "https://wttr.in/" .. city .. "?format=3&lang=" .. lang
|
||||
|
||||
-- make request
|
||||
local response = jarvis.http.get(url)
|
||||
|
||||
if response.ok then
|
||||
jarvis.log("info", "Weather: " .. response.body)
|
||||
|
||||
-- show notification
|
||||
local title = lang == "ru" and "Погода" or "Weather"
|
||||
jarvis.system.notify(title, response.body)
|
||||
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.log("error", "Failed to fetch weather: " .. (response.error or "unknown error"))
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
|
||||
return { chain = false }
|
||||
32
resources/commands/weather/set_city.lua
Normal file
32
resources/commands/weather/set_city.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-- set city for weather command
|
||||
|
||||
local phrase = jarvis.context.phrase
|
||||
local lang = jarvis.context.language
|
||||
|
||||
-- try to extract city name from phrase
|
||||
-- this is a simple example - you might want better parsing
|
||||
local city = phrase:match("город%s+(.+)") or phrase:match("city%s+(.+)")
|
||||
|
||||
if city then
|
||||
city = city:gsub("^%s*(.-)%s*$", "%1") -- trim
|
||||
|
||||
-- save to state (shared with weather command)
|
||||
jarvis.state.set("city", city)
|
||||
|
||||
local msg = lang == "ru"
|
||||
and "Город установлен: " .. city
|
||||
or "City set to: " .. city
|
||||
|
||||
jarvis.log("info", msg)
|
||||
jarvis.system.notify("Jarvis", msg)
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
local msg = lang == "ru"
|
||||
and "Не удалось определить город"
|
||||
or "Could not determine city"
|
||||
|
||||
jarvis.log("warn", msg)
|
||||
jarvis.audio.play_not_found()
|
||||
end
|
||||
|
||||
return { chain = false }
|
||||
Loading…
Add table
Add a link
Reference in a new issue