happybot/zwspcheck.sh

24 lines
825 B
Bash

#!/usr/bin/env ash
fin="irc.freenode.net/$1/in";
fout="irc.freenode.net/$1/out";
tail -n0 -f "$fout" | while read x; do
y=`echo "$x" | tr 'A-Z' 'a-z' | grep 'zwspcheck'`;
if [ ! -z "$y" ]; then
n=`echo "$x" | sed 's/^[^<]*<//' | sed 's/>.*//'`
m="your";
z=`echo "$y" | grep 'zwspcheck~[0-9][0-9]*'`
nn='';
if [ ! -z "$z" ]; then
z=`echo "$y" | sed 's/.*zwspcheck~//' | sed 's/[^0-9].*//'`
z=`echo "$z+1" | bc`
m="that";
x=`tac "$fout" | grep -E -v '^[0-9\-]+ [0-9:]+ -!-' | grep -F -A "$z" -x -e "$x" | tail -n1`
nn=`echo "$x" | sed 's/^[^<]*<//' | sed 's/>.*//'`
nn=" by $nn";
fi;
z=`echo -n "$x" | sed "s/[^$(cat ~/zwsp)]//g" | sed "s/$(cat ~/zwsp)/z/g" | wc -c`;
s='s'; if [ "$z" -eq "1" ]; then s=''; fi
echo "$(cat ~/zwsp)$n: $z zwsp$s found in $m message$nn." > "$fin";
fi;
done