irc-bot/whuffie

42 lines
611 B
Plaintext
Raw Normal View History

2010-12-16 21:13:34 -07:00
#! /bin/sh
db=$1; shift
text="$1"
get () {
cdb -q $db "$1" || echo 0
}
put () {
(printf "+%d,%d:%s->%s\n" ${#1} ${#2} "$1" $2;
cdb -d $db) | cdb -c -u $db
}
adj () {
2011-01-07 15:50:36 -07:00
who=${text%%$1$1*}
2010-12-16 21:13:34 -07:00
if [ "$who" = "$sender" ]; then
echo "Nice try, $sender."
else
put "$who" $(expr $(get "$who") $1 1)
fi
}
case "$text" in
whuffie\ *)
who=${text##whuffie }
amt=$(get "$who")
2011-01-07 15:54:07 -07:00
echo "$who has whuffie score of $amt"
2010-12-16 21:13:34 -07:00
;;
2011-01-07 15:50:36 -07:00
*++|*++\ *)
2010-12-16 21:13:34 -07:00
adj +
;;
2011-01-07 15:50:36 -07:00
*--|*--\ *)
2010-12-16 21:13:34 -07:00
adj -
;;
*)
exit 1
;;
esac