marvvin

IRC bot
Log | Files | Refs | README | LICENSE

commit 8026bb63909c7ac44ff10bb530c215b8c7173834
parent 74cef5396ca42a4e3201742e4c5fc190e2534b19
Author: hhvn <hayden@hhvn.uk>
Date:   Mon, 12 Apr 2021 04:53:45 +0100

functions.sh: add family of functions for notices

Diffstat:
Mfunctions.sh | 49+++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+), 0 deletions(-)

diff --git a/functions.sh b/functions.sh @@ -104,6 +104,55 @@ prepl_msg(){ done } +# match_notice(regex, command...) +match_notice(){ + regex="$1" && shift + cmd="$@" + set -- $LINE + + [ "$2" = "NOTICE" ] && { + sline=$(echo "$@" | sed 's/:[^:]*://' | tr -d '\r') + echo "$sline" | grep -Ei "$regex" >/dev/null && { + echo "$3" | grep '^[#!&]' >/dev/null && REPL="$3" || REPL="$NICK" + export REPL + echo "$sline" | $cmd + undefine_match + } + } +} + +# send_notice(dest, line) +send_notice(){ + dest=$(echo "$1" | tr -d '\r\n') + shift + sline=$(echo "$@" | tr -d '\r\n') + printf "NOTICE %s :%s\r\n" "$dest" "$sline" >> $input +} + +# | psend_notice(dest) +psend_notice(){ + dest=$(echo "$1" | tr -d '\r\n') + while IFS= read -r pline + do + printf "NOTICE %s :%s\r\n" "$dest" "$pline" >> $input + done +} + +# repl_notice(line) +repl_notice(){ + sline=$(echo "$@" | tr -d '\r\n') + printf "NOTICE %s :%s\r\n" "$REPL" "$sline" >> $input +} + +# | prepl_notice(void) +prepl_notice(){ + while IFS= read -r pline + do + sline=$(echo "$pline" | tr -d '\r\n') + printf "NOTICE %s :%s\r\n" "$REPL" "$sline" >> $input + done +} + # match_action(regex, command...) match_action(){ regex="$1" && shift