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).
70 lines
3.3 KiB
Lua
70 lines
3.3 KiB
Lua
local lang = jarvis.context.language
|
|
local cmd_id = jarvis.context.command_id
|
|
|
|
local prompts = {
|
|
joke = lang == "ru"
|
|
and "Расскажи одну короткую шутку на русском, 1-3 предложения. Без вступления и без 'вот шутка'. Просто шутка."
|
|
or "Tell one short joke in 1-3 sentences. No preamble.",
|
|
fact = lang == "ru"
|
|
and "Расскажи один интересный, неочевидный факт по любой теме. 1-3 предложения. Без 'вот факт'."
|
|
or "Tell one surprising fact in 1-3 sentences. No preamble.",
|
|
quote = lang == "ru"
|
|
and "Дай вдохновляющую цитату известного человека и автора. Без 'вот цитата'. Формат: <цитата> — <автор>."
|
|
or "Give one inspiring quote with author. Format: <quote> — <author>.",
|
|
compliment = lang == "ru"
|
|
and "Сделай искренний короткий комплимент пользователю, как британский дворецкий Джарвис. 1-2 предложения, обращение «сэр»."
|
|
or "Compliment the user briefly, in JARVIS-the-butler tone.",
|
|
}
|
|
|
|
local sys = prompts[cmd_id] or prompts.joke
|
|
|
|
local token = jarvis.system.env("GROQ_TOKEN")
|
|
if not token or token == "" then
|
|
jarvis.system.notify("Fun", "GROQ_TOKEN не задан")
|
|
jarvis.audio.play_error()
|
|
return { chain = false }
|
|
end
|
|
|
|
local base = jarvis.system.env("GROQ_BASE_URL"); if not base or base == "" then base = "https://api.groq.com/openai/v1" end
|
|
local model = jarvis.system.env("GROQ_MODEL"); if not model or model == "" then model = "llama-3.3-70b-versatile" end
|
|
|
|
math.randomseed(os.time() + jarvis.context.time.second * 7919)
|
|
local seed_word = (math.random(1, 9999)) .. ""
|
|
|
|
local payload = {
|
|
model = model,
|
|
messages = {
|
|
{ role = "system", content = sys },
|
|
{ role = "user", content = "seed " .. seed_word },
|
|
},
|
|
max_tokens = 220,
|
|
temperature = 1.0,
|
|
}
|
|
local res = jarvis.http.post_json(base .. "/chat/completions", payload, { Authorization = "Bearer " .. token })
|
|
|
|
if not res.ok then
|
|
jarvis.system.notify("Fun", "Groq не ответил")
|
|
jarvis.audio.play_error()
|
|
return { chain = false }
|
|
end
|
|
|
|
local content = (res.body or ""):match('"content"%s*:%s*"(.-[^\\])"')
|
|
if not content then
|
|
jarvis.audio.play_error()
|
|
return { chain = false }
|
|
end
|
|
content = content:gsub('\\n', ' '):gsub('\\"', '"'):gsub('\\\\', '\\'):gsub("%s+", " ")
|
|
content = content:gsub("^%s+", ""):gsub("%s+$", "")
|
|
|
|
local titles = { joke = "Анекдот", fact = "Факт", quote = "Цитата", compliment = "Комплимент" }
|
|
jarvis.system.notify(titles[cmd_id] or "Fun", content:sub(1, 240))
|
|
|
|
local sapi = content: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()
|
|
return { chain = false }
|