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 }