J.A.R.V.I.S-rust/resources/commands/unit_convert/temperature.lua

22 lines
946 B
Lua
Raw Normal View History

2026-05-15 18:41:44 +03:00
-- Температура: Цельсий ↔ Фаренгейт
local phrase = (jarvis.context.phrase or ""):lower()
local n_str = phrase:match("(%-?[%d%.,]+)")
if not n_str then return jarvis.cmd.error("Не понял число.") end
local n = tonumber((n_str:gsub(",", ".")))
if not n then return jarvis.cmd.error("Не понял число.") end
local result, unit_out
if phrase:find("в фаренгейт") or phrase:find("to fahrenheit") then
result = n * 9.0 / 5.0 + 32.0
unit_out = "по Фаренгейту"
elseif phrase:find("в цельси") or phrase:find("to celsius") then
result = (n - 32.0) * 5.0 / 9.0
unit_out = "по Цельсию"
else
return jarvis.cmd.error("Скажите в чём перевести: в фаренгейт или в цельсий.")
end
local rounded = math.floor(result * 10 + 0.5) / 10
return jarvis.cmd.ok(string.format("%g градусов %s.", rounded, unit_out))