marvvin

IRC bot
Log | Files | Refs | README | LICENSE

commit 3194f1e50dbce10eedf0fb01bbc38f856e1e36d5
parent 19c8e3da51ed83eed3178a3c0e399e692017463b
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 15 May 2022 19:32:03 +0100

Improve conversion handler: unify usage, backend details

Diffstat:
Actl.rc | 30++++++++++++++++++++++++++++++
Dctl.sh | 28----------------------------
Mhandler.rc | 20+++++++++++++++++---
3 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/ctl.rc b/ctl.rc @@ -0,0 +1,30 @@ +#!/bin/rc + +cd `{dirname $0} + +fn needsv { + if (!~ `{id -u} 0) { + printf 'You need root to start/stop services..' + exit 1 + } + sv $1 marvvin +} + +switch ($1) { +case start + needsv start +case quit + shift + printf 'QUIT :%s\r\n' $^* > ./input.fifo + needsv stop +case join + shift + for (c in $*) { + printf 'JOIN %s\r\n' $c > ./input.fifo + } +case part + shift + for (c in $*) { + printf 'PART %s\r\n' $c > ./input.fifo + } +} diff --git a/ctl.sh b/ctl.sh @@ -1,28 +0,0 @@ -#!/bin/sh - -cd $(dirname $0) - -case "$1" in - start) - nohup ./main.sh & - ;; - join) - shift - for channel in "$@" - do - printf "JOIN %s\r\n" "$channel" > ./input.fifo - done - ;; - part) - shift - for channel in "$@" - do - printf "PART %s\r\n" "$channel" > ./input.fifo - done - ;; - quit) - shift - printf "QUIT :$@\r\n" > ./input.fifo - touch ./stop - ;; -esac diff --git a/handler.rc b/handler.rc @@ -159,13 +159,26 @@ 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') { +} else if (match_hilight -iE '^(convert|exchange|currency)( |$)') { + VERB = `{echo $PARAMS(3)} + VERB = $VERB(2) 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))' + if (~ $VERB convert) { + backend = 'GNU units(1), ' + noun = 'unit/currency' + } else { + noun = 'currency' + } + backend = $backend ^ 'cryptocompare.com (regular currencies too)' + send_msg $TARGET 'usage: ' ^ $VERB ^ ' [amount] <' ^ $noun ^ '> [to] <' ^ $noun ^ '>' + send_msg $TARGET 'Backend: ' ^ $backend return } + + if (!~ $ARGS(1) [0-9]*) { + ARGS = (1 $ARGS) + } 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)( |$)//'} @@ -175,6 +188,7 @@ if (~ $PARAMS(1) 'PING') { return } } + data = `$nl{./bin/currency $ARGS} if (~ $bqstatus(1) 0) { send_msg $TARGET $data