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).
This commit is contained in:
parent
dcee98bddf
commit
9d8b917149
14 changed files with 749 additions and 0 deletions
27
resources/commands/crypto/command.toml
Normal file
27
resources/commands/crypto/command.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[[commands]]
|
||||
id = "crypto_price"
|
||||
type = "lua"
|
||||
script = "price.lua"
|
||||
sandbox = "full"
|
||||
timeout = 10000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"сколько биткоин",
|
||||
"цена биткоина",
|
||||
"курс биткоина",
|
||||
"цена эфира",
|
||||
"сколько эфир",
|
||||
"цена крипты",
|
||||
"цена соланы",
|
||||
]
|
||||
en = [
|
||||
"bitcoin price",
|
||||
"ethereum price",
|
||||
"crypto price",
|
||||
"btc price",
|
||||
]
|
||||
ua = [
|
||||
"ціна біткоїна",
|
||||
"курс біткоїна",
|
||||
]
|
||||
51
resources/commands/crypto/price.lua
Normal file
51
resources/commands/crypto/price.lua
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
local phrase = (jarvis.context.phrase or ""):lower()
|
||||
|
||||
local coin_id, label
|
||||
if phrase:find("эфир") or phrase:find("eth") or phrase:find("ethereum") then
|
||||
coin_id, label = "ethereum", "Эфир"
|
||||
elseif phrase:find("солан") or phrase:find("sol") then
|
||||
coin_id, label = "solana", "Солана"
|
||||
elseif phrase:find("doge") or phrase:find("дог") then
|
||||
coin_id, label = "dogecoin", "Догикоин"
|
||||
elseif phrase:find("ton") or phrase:find("тон") then
|
||||
coin_id, label = "the-open-network", "TON"
|
||||
else
|
||||
coin_id, label = "bitcoin", "Биткоин"
|
||||
end
|
||||
|
||||
local url = "https://api.coingecko.com/api/v3/simple/price?ids=" .. coin_id .. "&vs_currencies=usd,rub&include_24hr_change=true"
|
||||
local res = jarvis.http.json(url)
|
||||
if not res or type(res) ~= "table" or not res[coin_id] then
|
||||
jarvis.system.notify("Crypto", "CoinGecko не ответил")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local data = res[coin_id]
|
||||
local usd = data.usd
|
||||
local rub = data.rub
|
||||
local ch = data.usd_24h_change or 0
|
||||
|
||||
local title = string.format("%s: $%s | %s ₽", label, tostring(usd), tostring(math.floor(rub or 0)))
|
||||
local detail = string.format("за 24 часа %+.2f%%", ch)
|
||||
jarvis.system.notify(title, detail)
|
||||
jarvis.log("info", title .. " | " .. detail)
|
||||
|
||||
local say
|
||||
if ch > 1 then
|
||||
say = string.format("%s стоит %s долларов, за сутки вырос на %.1f процентов.", label, tostring(math.floor(usd)), ch)
|
||||
elseif ch < -1 then
|
||||
say = string.format("%s стоит %s долларов, за сутки упал на %.1f процентов.", label, tostring(math.floor(usd)), math.abs(ch))
|
||||
else
|
||||
say = string.format("%s стоит %s долларов, без существенных изменений.", label, tostring(math.floor(usd)))
|
||||
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 }
|
||||
29
resources/commands/currency/command.toml
Normal file
29
resources/commands/currency/command.toml
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
[[commands]]
|
||||
id = "currency_rate"
|
||||
type = "lua"
|
||||
script = "rate.lua"
|
||||
sandbox = "full"
|
||||
timeout = 10000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"курс доллара",
|
||||
"курс евро",
|
||||
"сколько стоит доллар",
|
||||
"сколько стоит евро",
|
||||
"курс юаня",
|
||||
"курс валют",
|
||||
"что с долларом",
|
||||
"что с евро",
|
||||
]
|
||||
en = [
|
||||
"dollar rate",
|
||||
"euro rate",
|
||||
"currency rate",
|
||||
"what is dollar",
|
||||
]
|
||||
ua = [
|
||||
"курс долара",
|
||||
"курс євро",
|
||||
"що з доларом",
|
||||
]
|
||||
59
resources/commands/currency/rate.lua
Normal file
59
resources/commands/currency/rate.lua
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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 }
|
||||
70
resources/commands/fun/ask.lua
Normal file
70
resources/commands/fun/ask.lua
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
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 }
|
||||
50
resources/commands/fun/command.toml
Normal file
50
resources/commands/fun/command.toml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
[[commands]]
|
||||
id = "joke"
|
||||
type = "lua"
|
||||
script = "ask.lua"
|
||||
sandbox = "full"
|
||||
timeout = 15000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["расскажи шутку", "пошути", "анекдот", "рассмеши меня"]
|
||||
en = ["tell a joke", "make me laugh", "joke"]
|
||||
ua = ["розкажи жарт", "пожартуй"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "fact"
|
||||
type = "lua"
|
||||
script = "ask.lua"
|
||||
sandbox = "full"
|
||||
timeout = 15000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["расскажи факт", "интересный факт", "поделись фактом"]
|
||||
en = ["tell a fact", "interesting fact"]
|
||||
ua = ["цікавий факт"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "quote"
|
||||
type = "lua"
|
||||
script = "ask.lua"
|
||||
sandbox = "full"
|
||||
timeout = 15000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["вдохнови меня", "цитата дня", "мотивируй", "процитируй кого-нибудь"]
|
||||
en = ["inspire me", "quote of the day", "motivate me"]
|
||||
ua = ["надихни", "цитата дня"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "compliment"
|
||||
type = "lua"
|
||||
script = "ask.lua"
|
||||
sandbox = "full"
|
||||
timeout = 15000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["сделай комплимент", "похвали меня"]
|
||||
en = ["compliment me", "say something nice"]
|
||||
ua = ["зроби комплімент"]
|
||||
28
resources/commands/help/command.toml
Normal file
28
resources/commands/help/command.toml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[[commands]]
|
||||
id = "help"
|
||||
type = "lua"
|
||||
script = "help.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"что ты умеешь",
|
||||
"какие команды",
|
||||
"список команд",
|
||||
"помощь",
|
||||
"помоги",
|
||||
"что можешь",
|
||||
]
|
||||
en = [
|
||||
"what can you do",
|
||||
"list commands",
|
||||
"help",
|
||||
"show commands",
|
||||
]
|
||||
ua = [
|
||||
"що ти вмієш",
|
||||
"які команди",
|
||||
"список команд",
|
||||
"допоможи",
|
||||
]
|
||||
75
resources/commands/help/help.lua
Normal file
75
resources/commands/help/help.lua
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
local lang = jarvis.context.language
|
||||
|
||||
local commands_dir = jarvis.context.command_path:match("^(.*[/\\])[^/\\]+[/\\]?$")
|
||||
if not commands_dir then
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local entries = jarvis.fs.list(commands_dir)
|
||||
local packs = {}
|
||||
for _, e in ipairs(entries) do
|
||||
if e.is_dir then table.insert(packs, e.name) end
|
||||
end
|
||||
table.sort(packs)
|
||||
|
||||
local descriptions = {
|
||||
apps = lang == "ru" and "браузер, блокнот, калькулятор, проводник, терминал, настройки, диспетчер задач, блокировка, скриншот" or "browser, notepad, calculator, explorer, terminal, settings, taskmgr, lock, screenshot",
|
||||
volume = lang == "ru" and "громче, тише, mute, максимум" or "louder, quieter, mute, max",
|
||||
media = lang == "ru" and "пауза, play, следующий/предыдущий трек, стоп" or "pause/play, next/prev track, stop",
|
||||
file_search = lang == "ru" and "найди файл X" or "find file X",
|
||||
output_device = lang == "ru" and "список устройств вывода, переключи" or "list/cycle audio out",
|
||||
sysinfo = lang == "ru" and "время, заряд, CPU, RAM, диск, статус системы" or "time, battery, cpu, ram, disk",
|
||||
window = lang == "ru" and "сверни/разверни/закрой окно, snap влево/вправо, рабочий стол" or "min/max/close window, snap, desktop",
|
||||
clipboard_read = lang == "ru" and "прочитай буфер" or "read clipboard",
|
||||
notes = lang == "ru" and "запиши/покажи заметки" or "write/show notes",
|
||||
process_kill = lang == "ru" and "закрой программу X" or "kill process X",
|
||||
websearch = lang == "ru" and "загугли / ютуб / вики / яндекс" or "search google/youtube/wiki/yandex",
|
||||
translate = lang == "ru" and "переведи на X" or "translate to X",
|
||||
math = lang == "ru" and "посчитай X" or "calculate X",
|
||||
theme = lang == "ru" and "тёмная/светлая тема" or "dark/light theme",
|
||||
projects = lang == "ru" and "открой/список проектов" or "open/list projects",
|
||||
sound_panel = lang == "ru" and "панель звука" or "sound panel",
|
||||
codegen = lang == "ru" and "напиши код X" or "write code X",
|
||||
ocr = lang == "ru" and "прочитай экран" or "read screen",
|
||||
reminders = lang == "ru" and "напомни через N минут X" or "remind me in N min X",
|
||||
date_query = lang == "ru" and "что сегодня / завтра / вчера" or "today/tomorrow/yesterday",
|
||||
voice_type = lang == "ru" and "напечатай X" or "type X",
|
||||
dice = lang == "ru" and "монетка, кубик, случайное число" or "coin, dice, random",
|
||||
stopwatch = lang == "ru" and "засеки время / стоп секундомер" or "start/stop stopwatch",
|
||||
news = lang == "ru" and "что нового" or "what's new",
|
||||
currency = lang == "ru" and "курс доллара / евро / юаня" or "USD/EUR/CNY rate",
|
||||
crypto = lang == "ru" and "цена биткоина / эфира" or "BTC/ETH price",
|
||||
fun = lang == "ru" and "шутка, факт, цитата, комплимент" or "joke, fact, quote, compliment",
|
||||
wiki = lang == "ru" and "что такое / кто такой X" or "what/who is X",
|
||||
power = lang == "ru" and "выключи / перезагрузи / усыпи / гибернация" or "shutdown / restart / sleep / hibernate",
|
||||
weather = lang == "ru" and "какая погода" or "what's the weather",
|
||||
counter = lang == "ru" and "счётчик" or "counter",
|
||||
help = lang == "ru" and "что ты умеешь" or "what can you do",
|
||||
}
|
||||
|
||||
local lines = {}
|
||||
for _, p in ipairs(packs) do
|
||||
local desc = descriptions[p] or ""
|
||||
if desc ~= "" then
|
||||
table.insert(lines, "• " .. p .. ": " .. desc)
|
||||
end
|
||||
end
|
||||
|
||||
local title = string.format(lang == "ru" and "Команды (%d пакетов)" or "Commands (%d packs)", #packs)
|
||||
local body = table.concat(lines, "\n")
|
||||
jarvis.system.clipboard.set(body)
|
||||
jarvis.system.notify(title, body:sub(1, 800))
|
||||
|
||||
local say = lang == "ru"
|
||||
and string.format("Загружено %d пакетов команд. Полный список скопирован в буфер.", #packs)
|
||||
or string.format("Loaded %d command packs. Full list is on the clipboard.", #packs)
|
||||
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 }
|
||||
27
resources/commands/news/command.toml
Normal file
27
resources/commands/news/command.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[[commands]]
|
||||
id = "news_headlines"
|
||||
type = "lua"
|
||||
script = "news.lua"
|
||||
sandbox = "full"
|
||||
timeout = 25000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"что нового",
|
||||
"новости",
|
||||
"что в мире",
|
||||
"последние новости",
|
||||
"расскажи новости",
|
||||
"топ новостей",
|
||||
]
|
||||
en = [
|
||||
"what's new",
|
||||
"latest news",
|
||||
"headlines",
|
||||
"top news",
|
||||
]
|
||||
ua = [
|
||||
"що нового",
|
||||
"новини",
|
||||
"останні новини",
|
||||
]
|
||||
82
resources/commands/news/news.lua
Normal file
82
resources/commands/news/news.lua
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
local lang = jarvis.context.language
|
||||
|
||||
local feed = lang == "en"
|
||||
and "https://feeds.bbci.co.uk/news/rss.xml"
|
||||
or "https://lenta.ru/rss/news"
|
||||
|
||||
local res = jarvis.http.get(feed)
|
||||
if not res.ok then
|
||||
jarvis.system.notify("News", "Не получил RSS: " .. tostring(res.status))
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local titles = {}
|
||||
for title in res.body:gmatch("<title>%s*<!%[CDATA%[(.-)%]%]>%s*</title>") do
|
||||
if title ~= "" and title:lower():find("rss") == nil and title:lower():find("новости") ~= 1 then
|
||||
table.insert(titles, title)
|
||||
end
|
||||
if #titles >= 7 then break end
|
||||
end
|
||||
if #titles == 0 then
|
||||
for title in res.body:gmatch("<title>%s*(.-)%s*</title>") do
|
||||
if title ~= "" then
|
||||
table.insert(titles, title)
|
||||
end
|
||||
if #titles >= 7 then break end
|
||||
end
|
||||
end
|
||||
|
||||
if #titles <= 1 then
|
||||
jarvis.system.notify("News", lang == "ru" and "Не получилось распарсить" or "Could not parse feed")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local top = {}
|
||||
for i = 2, math.min(6, #titles) do table.insert(top, titles[i]) end
|
||||
local joined = table.concat(top, " | ")
|
||||
|
||||
jarvis.system.clipboard.set(joined)
|
||||
jarvis.system.notify(lang == "ru" and "Новости" or "News", joined:sub(1, 280))
|
||||
|
||||
local token = jarvis.system.env("GROQ_TOKEN")
|
||||
local say_text
|
||||
if token and token ~= "" then
|
||||
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
|
||||
local sys = lang == "ru"
|
||||
and "Ты диктор. Дам список заголовков новостей. Сжато перескажи 3 главные темы простым языком, 2-3 предложения суммарно. Не упоминай номера и не повторяй заголовки дословно."
|
||||
or "You are a news anchor. Summarise the top 3 headlines in 2-3 sentences. No numbering, no verbatim repeats."
|
||||
local payload = {
|
||||
model = model,
|
||||
messages = {
|
||||
{ role = "system", content = sys },
|
||||
{ role = "user", content = joined },
|
||||
},
|
||||
max_tokens = 220,
|
||||
temperature = 0.4,
|
||||
}
|
||||
local lr = jarvis.http.post_json(base .. "/chat/completions", payload, { Authorization = "Bearer " .. token })
|
||||
if lr.ok then
|
||||
local c = (lr.body or ""):match('"content"%s*:%s*"(.-[^\\])"')
|
||||
if c then
|
||||
c = c:gsub('\\n', ' '):gsub('\\"', '"'):gsub('\\\\', '\\')
|
||||
say_text = c
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not say_text then
|
||||
say_text = (lang == "ru" and "Главные новости: " or "Top news: ") .. (top[1] or "") .. ". " .. (top[2] or "") .. ". " .. (top[3] or "")
|
||||
end
|
||||
|
||||
local sapi = say_text: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 }
|
||||
45
resources/commands/power/act.lua
Normal file
45
resources/commands/power/act.lua
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
local cmd_id = jarvis.context.command_id
|
||||
local lang = jarvis.context.language
|
||||
|
||||
local actions = {
|
||||
shutdown_pc = { cmd = 'shutdown.exe /s /t 30 /c "J.A.R.V.I.S.: shutdown in 30s. Say cancel to abort."', label = lang == "ru" and "Выключение через 30 секунд" or "Shutdown in 30 sec" },
|
||||
restart_pc = { cmd = 'shutdown.exe /r /t 30 /c "J.A.R.V.I.S.: restart in 30s. Say cancel to abort."', label = lang == "ru" and "Перезагрузка через 30 секунд" or "Restart in 30 sec" },
|
||||
logoff_user = { cmd = 'shutdown.exe /l', label = lang == "ru" and "Выход из системы" or "Sign out" },
|
||||
sleep_pc = { cmd = 'rundll32.exe powrprof.dll,SetSuspendState 0,1,0', label = lang == "ru" and "Сон" or "Sleep" },
|
||||
hibernate_pc = { cmd = 'shutdown.exe /h', label = lang == "ru" and "Гибернация" or "Hibernate" },
|
||||
cancel_shutdown = { cmd = 'shutdown.exe /a', label = lang == "ru" and "Выключение отменено" or "Shutdown cancelled" },
|
||||
}
|
||||
|
||||
local a = actions[cmd_id]
|
||||
if not a then
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local res = jarvis.system.exec(a.cmd)
|
||||
local ok = res.success
|
||||
|
||||
if not ok and cmd_id == "cancel_shutdown" then
|
||||
ok = true
|
||||
end
|
||||
|
||||
if ok then
|
||||
jarvis.system.notify("Power", a.label)
|
||||
jarvis.log("info", "power: " .. cmd_id .. " -> " .. a.label)
|
||||
local say = a.label .. ". " .. (cmd_id == "shutdown_pc" or cmd_id == "restart_pc"
|
||||
and (lang == "ru" and "Скажи отмени если передумал, сэр." or "Say cancel to abort, sir.")
|
||||
or "")
|
||||
local sapi = say: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()
|
||||
else
|
||||
jarvis.log("error", "power " .. cmd_id .. " failed: " .. tostring(res.stderr):sub(1, 200))
|
||||
jarvis.system.notify("Power", (lang == "ru" and "Не получилось: " or "Failed: ") .. cmd_id)
|
||||
jarvis.audio.play_error()
|
||||
end
|
||||
|
||||
return { chain = false }
|
||||
76
resources/commands/power/command.toml
Normal file
76
resources/commands/power/command.toml
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
[[commands]]
|
||||
id = "shutdown_pc"
|
||||
type = "lua"
|
||||
script = "act.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["выключи компьютер", "выключи пк", "выключи комп"]
|
||||
en = ["shutdown pc", "shut down computer"]
|
||||
ua = ["вимкни комп'ютер", "вимкни пк"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "restart_pc"
|
||||
type = "lua"
|
||||
script = "act.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["перезагрузи компьютер", "перезагрузи пк", "ребутни", "ребут"]
|
||||
en = ["restart pc", "reboot computer"]
|
||||
ua = ["перезавантаж комп'ютер"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "sleep_pc"
|
||||
type = "lua"
|
||||
script = "act.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["усыпи компьютер", "усыпи пк", "режим сна", "перейди в сон"]
|
||||
en = ["sleep pc", "put computer to sleep"]
|
||||
ua = ["приспи комп'ютер"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "hibernate_pc"
|
||||
type = "lua"
|
||||
script = "act.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["гибернация", "переведи в гибернацию", "режим гибернации"]
|
||||
en = ["hibernate pc"]
|
||||
ua = ["гібернація"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "logoff_user"
|
||||
type = "lua"
|
||||
script = "act.lua"
|
||||
sandbox = "full"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["выйди из системы", "разлогинь", "выйди из учётки", "сеанс закончи"]
|
||||
en = ["log off", "sign out"]
|
||||
ua = ["вийди з системи"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "cancel_shutdown"
|
||||
type = "lua"
|
||||
script = "act.lua"
|
||||
sandbox = "full"
|
||||
timeout = 3000
|
||||
|
||||
[commands.phrases]
|
||||
ru = ["отмени выключение", "отмени ребут", "отмени перезагрузку", "стой не выключай"]
|
||||
en = ["cancel shutdown", "abort shutdown"]
|
||||
ua = ["скасуй вимкнення"]
|
||||
27
resources/commands/wiki/command.toml
Normal file
27
resources/commands/wiki/command.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[[commands]]
|
||||
id = "wiki_lookup"
|
||||
type = "lua"
|
||||
script = "wiki.lua"
|
||||
sandbox = "full"
|
||||
timeout = 25000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"что такое",
|
||||
"кто такой",
|
||||
"кто такая",
|
||||
"расскажи про",
|
||||
"википедия про",
|
||||
"найди в википедии про",
|
||||
]
|
||||
en = [
|
||||
"what is",
|
||||
"who is",
|
||||
"tell me about",
|
||||
"wikipedia about",
|
||||
]
|
||||
ua = [
|
||||
"що таке",
|
||||
"хто такий",
|
||||
"розкажи про",
|
||||
]
|
||||
103
resources/commands/wiki/wiki.lua
Normal file
103
resources/commands/wiki/wiki.lua
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
local lang = jarvis.context.language
|
||||
local phrase = (jarvis.context.phrase or ""):lower()
|
||||
|
||||
local triggers = {
|
||||
"найди в википедии про", "википедия про", "расскажи про",
|
||||
"кто такая", "кто такой", "что такое",
|
||||
"tell me about", "wikipedia about", "who is", "what is",
|
||||
"розкажи про", "хто такий", "що таке",
|
||||
}
|
||||
local query = phrase
|
||||
for _, t in ipairs(triggers) do
|
||||
local s, e = string.find(query, t, 1, true)
|
||||
if s == 1 then
|
||||
query = query:sub(e + 1)
|
||||
break
|
||||
end
|
||||
end
|
||||
query = query:gsub("^%s+", ""):gsub("%s+$", "")
|
||||
|
||||
if query == "" then
|
||||
jarvis.system.notify("Wiki", lang == "ru" and "О чём рассказать?" or "What to look up?")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local function url_encode(s)
|
||||
return (s:gsub("([^%w%-_%.~])", function(c) return string.format("%%%02X", string.byte(c)) end))
|
||||
end
|
||||
|
||||
local host = lang == "en" and "en.wikipedia.org" or "ru.wikipedia.org"
|
||||
|
||||
local search_url = string.format(
|
||||
"https://%s/w/api.php?action=opensearch&search=%s&limit=1&format=json",
|
||||
host, url_encode(query)
|
||||
)
|
||||
local search = jarvis.http.get(search_url)
|
||||
if not search.ok then
|
||||
jarvis.system.notify("Wiki", "Поиск не удался")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local title = search.body:match('%["[^"]+",%s*%["([^"]+)"')
|
||||
if not title or title == "" then
|
||||
jarvis.system.notify("Wiki", (lang == "ru" and "Не нашёл: " or "Not found: ") .. query)
|
||||
jarvis.audio.play_not_found()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local summary_url = string.format(
|
||||
"https://%s/api/rest_v1/page/summary/%s",
|
||||
host, url_encode(title)
|
||||
)
|
||||
local summary = jarvis.http.json(summary_url)
|
||||
if not summary or type(summary) ~= "table" or not summary.extract then
|
||||
jarvis.system.notify("Wiki", "Не получил конспект")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
local extract = summary.extract
|
||||
local article_title = summary.title or title
|
||||
|
||||
local token = jarvis.system.env("GROQ_TOKEN")
|
||||
local say_text = extract:sub(1, 400)
|
||||
|
||||
if token and token ~= "" and #extract > 350 then
|
||||
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
|
||||
local sys = lang == "ru"
|
||||
and "Тебе дана статья из Википедии. Перескажи суть простым разговорным языком в 2-3 предложения. Без 'википедия гласит' и подобных вступлений."
|
||||
or "Summarise this Wikipedia text in 2-3 plain-language sentences. No 'wikipedia says' preambles."
|
||||
local payload = {
|
||||
model = model,
|
||||
messages = {
|
||||
{ role = "system", content = sys },
|
||||
{ role = "user", content = extract:sub(1, 2500) },
|
||||
},
|
||||
max_tokens = 220,
|
||||
temperature = 0.3,
|
||||
}
|
||||
local lr = jarvis.http.post_json(base .. "/chat/completions", payload, { Authorization = "Bearer " .. token })
|
||||
if lr.ok then
|
||||
local c = (lr.body or ""):match('"content"%s*:%s*"(.-[^\\])"')
|
||||
if c then
|
||||
c = c:gsub('\\n', ' '):gsub('\\"', '"'):gsub('\\\\', '\\'):gsub("%s+", " ")
|
||||
say_text = c:gsub("^%s+", ""):gsub("%s+$", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
jarvis.system.clipboard.set(article_title .. "\n\n" .. extract)
|
||||
jarvis.system.notify(article_title, say_text:sub(1, 240))
|
||||
|
||||
local sapi = say_text: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 }
|
||||
Loading…
Add table
Add a link
Reference in a new issue