Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit fe46f27a29be7dd196466aa90737736e51b1ebcd
parent 536b189bdaaeebc12ffe3ffadd6218f3fdc3c204
Author: Danny <23189912+danyisill@users.noreply.github.com>
Date:   Mon, 19 Apr 2021 17:27:24 +0300

Add failsafes for fluorinated amphetamines and arycyclohexylamines

Diffstat:
Mlib/commands/metric.ts | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/commands/metric.ts b/lib/commands/metric.ts @@ -1,5 +1,5 @@ const noop = (..._) => undefined; -const ftoc = n => 5/9 * (n - 32); +const ftoc = n => [5/9 * (n - 32), "C"]; const ftom = n => [0.3048 * n, "m"]; const UNITS = { @@ -21,7 +21,7 @@ const UNITS = { "lb": n => [0.453 * n, "kg"] }; -const QUANTITY_REGEX = /[\d.]+(F|\s(mile|inch|feet|foot|ft|ounce|gallon|yard|oz|fl.?.?oz|yd|acre|pint|quart|pound|lb|fahrenheit))/gi; +const QUANTITY_REGEX = /[\d.]+(F |F$|\s(mile|inch|feet|foot|ft|ounce|gallon|yard|oz|fl.?.?oz|yd|acre|pint|quart|pound|lb|fahrenheit))/gi; export default async (homescope: HomeScope) => { const { message, args } = homescope; @@ -29,13 +29,16 @@ export default async (homescope: HomeScope) => { const msg = args.join(" ").match(QUANTITY_REGEX).map(s => { s = s.toLowerCase(); if (s[s.length - 1] === "f") { - return Math.round(ftoc(s.slice(0, -1))) + "C"; + let c = Math.round(ftoc(s.slice(0, -1))[0]); + if(c){ + return s + " = " + c + "C"; + } } if (s.split(" ")[1].startsWith("fl")) { - return Math.round(29.573 * Number(s.split(" ")[0])) + " ml" + return s + " = " + Math.round(29.573 * Number(s.split(" ")[0])) + " ml" } const out = (UNITS[s.split(" ")[1]] || noop)(Number(s.split(" ")[0])); - if (out) { + if (out && !isNaN(out[0])) { return `${s} = ${Math.round(out[0] * 10) / 10} ${out[1]}`; } else { return "";