J.A.R.V.I.S-rust/resources/commands/unit_convert/weight.lua
Bossiara13 84d3b57ddc feat: unit conversion + random generators packs (7 new commands)
Two pure-Lua packs that don't need network or LLM — pure offline utilities.

unit_convert (resources/commands/unit_convert/, 4 commands)
  - convert.length      "переведи 100 метров в футы" / "сколько 5 миль в км"
                        meters↔feet, km↔miles. Pluralises russian unit names.
  - convert.weight      "переведи 70 кг в фунты"
                        kg↔lbs.
  - convert.temperature "переведи 100 цельсий в фаренгейт" / "минус 40 в цельсий"
                        Handles negative numbers. C↔F formulas inline.
  - convert.speed       "переведи 100 км в час в мили в час"
                        km/h↔mph.
  - All round results to 1-2 decimal places, speak with proper Russian
    grammatical number (фут/фута/футов).

generators (resources/commands/generators/, 3 commands)
  - gen.coin       "подбрось монету" / "орёл или решка"
                   → "Орёл!" or "Решка!" (math.random with time+minute seed)
  - gen.password   "сгенерируй пароль 16 символов"
                   → cryptographically-ish 6..64-char password,
                   alphanumeric + !@#$%^&*-_=+, copies to clipboard,
                   SPEAKS LENGTH ONLY (never echoes the password).
                   Default 16 chars if no number in phrase.
  - gen.uuid       "сгенерируй uuid" / "юид"
                   → v4 UUID, copies to clipboard, speaks last 4 chars
                   (confirmation without 32-char monologue).

Tests: 112/112 pass (commands::tests auto-validates).
Pack count: 62 → 64.
2026-05-15 18:41:44 +03:00

23 lines
950 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Вес: кг ↔ фунты
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))