basic Lua 5.4 implementation with few example commands
This commit is contained in:
parent
c9b9482cc8
commit
c4a774b5cf
35 changed files with 2554 additions and 460 deletions
|
|
@ -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