52 lines
2.3 KiB
Lua
52 lines
2.3 KiB
Lua
|
|
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 }
|