commit ef338223ff3266a970925703cf2d408d06cc03ae parent cfa162bd26a0730393ca5d8a993bd8a92804d5ba Author: hhvn <dev@hhvn.uk> Date: Wed, 13 Apr 2022 18:03:14 +0100 Add convert command to generalize between bin/currency and other units Diffstat:
M | handler.rc | | | 23 | +++++++++++++++++++++++ |
1 file changed, 23 insertions(+), 0 deletions(-)
diff --git a/handler.rc b/handler.rc @@ -159,6 +159,29 @@ if (~ $PARAMS(1) 'PING') { } else if (match_hilight -i '^topic') { send_raw 'TOPIC #hlircnet :--== #hlircnet ==-- ::: --== gopher://hlirc.net/0/metachannel.txt ==-- ::: --== <%s> %s ==--\r\n' \ $NICK `$nl{echo $MSG | sed 's/[^ ]* *//'} +} else if (match_hilight -iE '^convert') { + ARGS = `{echo $MSG | sed 's/[^ ]*//'} + if (~ $ARGS ()) { + send_msg $TARGET 'usage: convert <amount> <currency> [to] <currency> (via currency API)' + send_msg $TARGET ' convert [amount] <unit> [to] <unit> (via GNU units(1))' + return + } + if (~ $ARGS to into as in) { + from = `$nl{echo $^ARGS | sed -E 's/(^| )(to|into|as|in)( |$).*//'} + to = `$nl{echo $^ARGS | sed -E 's/.*(^| )(to|into|as|in)( |$)//'} + data = `$nl{units $from $to >[2]/dev/null} + if (~ $bqstatus(1) 0) { + send_msg $TARGET `{echo $data(1) | sed -E 's/[[:space:]]*(\*[[:space:]]*|)//'} ^ ' ' ^ $to + return + } + } + data = `$nl{./bin/currency $ARGS} + if (~ $bqstatus(1) 0) { + send_msg $TARGET $data + return + } + + send_msg $TARGET 'Unknown units or values' } else if (match_hilight -iE '^(' ^ `$nl{builtin ls bin/ | tr '\n' '|' | sed 's/|*$//'} ^ ')') { CMD = `{echo $MSG | sed 's/ .*//'} ARGS = `{echo $MSG | sed 's/[^ ]*//'}