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

24 lines
950 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 pound") then
-- kg → lbs
result = n * 2.20462
unit_out = result < 2 and "фунт" or (result < 5 and "фунта" or "фунтов")
elseif phrase:find("в кг") or phrase:find("в килограм") or phrase:find("to kg") then
-- lbs → kg
result = n / 2.20462
unit_out = "килограмм"
else
return jarvis.cmd.error("Скажите в чём перевести: в фунты или в кг.")
end
local rounded = math.floor(result * 100 + 0.5) / 100
return jarvis.cmd.ok(string.format("%g %s.", rounded, unit_out))