J.A.R.V.I.S-rust/resources/commands/currency/rate.lua
Bossiara13 9d8b917149 feat(commands): analog-inspired tier-2 — news, currency, crypto, fun, wiki, power, help (33 packs)
Seven more portable Lua packs lifted from common voice-assistant
playbooks (Siri/Alexa/Алиса/Cortana). All sandbox=full, jarvis.http
+ jarvis.system.exec, zero new Rust code. cargo test still 3/3.

news/ — pulls Lenta.ru RSS (en switches to BBC), regex-extracts the
top 5 <title> entries (skipping the channel header), drops them into
the clipboard, then asks Groq for a 2-3 sentence summary at temp 0.4
and speaks it via SAPI. If GROQ_TOKEN is missing it falls back to
just reading the first three headlines.

currency/ — cbr-xml-daily.ru/daily_json.js. Picks USD/EUR/CNY/GBP/
JPY/KZT by keyword in the phrase, computes value / nominal, diffs
against Valute.Previous, says "X стоит N рублей, поднялся/опустился
на M" with ▲/▼ in the notify body.

crypto/ — CoinGecko simple/price with usd,rub and 24hr_change.
Recognises bitcoin / ethereum / solana / dogecoin / the-open-network.
Reports price + direction in plain Russian.

fun/ — joke / fact / quote / compliment, single ask.lua dispatched by
command_id. Per-command system prompt at temp 1.0; seeds with a
random integer so consecutive calls don't repeat.

wiki/ — ru.wikipedia opensearch → REST summary endpoint. If Groq is
available and extract > 350 chars, asks for a 2-3 sentence retell;
otherwise speaks the first 400 chars verbatim. Full extract goes to
clipboard.

power/ — shutdown_pc / restart_pc / sleep_pc / hibernate_pc /
logoff_user / cancel_shutdown. Single act.lua keyed by command_id.
shutdown/restart use shutdown.exe /s|/r /t 30 with a /c message —
30-second grace window so "отмени выключение" actually works.
sleep uses rundll32 powrprof,SetSuspendState, hibernate uses
shutdown.exe /h.

help/ — "что ты умеешь". Reads the parent commands/ dir via
jarvis.fs.list, sorts subdirs (pack names), pairs each with a
hardcoded Russian/English one-liner description, copies the full
list to clipboard and speaks a count + "see clipboard for full list".

Total command packs is now 33 (was 26).
2026-05-15 12:43:09 +03:00

59 lines
2.5 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local phrase = (jarvis.context.phrase or ""):lower()
local target = "usd"
if phrase:find("евро") or phrase:find("eur") then target = "eur"
elseif phrase:find("юан") or phrase:find("cny") or phrase:find("yuan") then target = "cny"
elseif phrase:find("фунт") or phrase:find("gbp") then target = "gbp"
elseif phrase:find("йен") or phrase:find("jpy") then target = "jpy"
elseif phrase:find("тенге") or phrase:find("kzt") then target = "kzt"
end
local res = jarvis.http.json("https://www.cbr-xml-daily.ru/daily_json.js")
if not res or type(res) ~= "table" or not res.Valute then
jarvis.system.notify("Курс", "Не получил данные ЦБ")
jarvis.audio.play_error()
return { chain = false }
end
local labels = {
usd = "Доллар", eur = "Евро", cny = "Юань",
gbp = "Фунт", jpy = "Йена", kzt = "Тенге",
}
local code = target:upper()
local v = res.Valute[code]
if not v then
jarvis.system.notify("Курс", "Нет данных по " .. code)
jarvis.audio.play_not_found()
return { chain = false }
end
local value = v.Value
local prev = v.Previous or value
local diff = value - prev
local arrow = diff > 0 and "" or (diff < 0 and "" or "=")
local nominal = v.Nominal or 1
local title = string.format("%s: %.2f ₽ %s", labels[target] or code, value / nominal, arrow)
local detail = string.format("вчера %.2f, изменение %+.2f", prev / nominal, diff / nominal)
jarvis.system.notify(title, detail)
jarvis.log("info", title .. " | " .. detail)
local say
if diff > 0 then
say = string.format("%s стоит %.2f рубля, поднялся на %.2f.", labels[target] or code, value / nominal, math.abs(diff) / nominal)
elseif diff < 0 then
say = string.format("%s стоит %.2f рубля, опустился на %.2f.", labels[target] or code, value / nominal, math.abs(diff) / nominal)
else
say = string.format("%s стоит %.2f рубля, без изменений.", labels[target] or code, value / nominal)
end
local sapi = say:gsub("'", "''")
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()
return { chain = false }