irc-bot/whuffie

42 lines
612 B
Bash
Executable File

#! /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 () {
who=${text%%$1$1*}
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")
echo "$who has whuffie score of $amt"
;;
*++|*++\ *)
adj +
;;
*--|*--\ *)
adj -
;;
*)
exit 1
;;
esac