From 13202d4ebdc9da3c3136cdd3e42c3bfe66de2bd5 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 16 Dec 2010 21:13:34 -0700 Subject: [PATCH] Add whuffie --- cobalt-handler | 9 +++++++-- infobot | 6 +----- whuffie | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100755 whuffie diff --git a/cobalt-handler b/cobalt-handler index 5b3f425..513ed4a 100755 --- a/cobalt-handler +++ b/cobalt-handler @@ -14,8 +14,13 @@ case $command in printf '\aJOIN #bot\n' ;; PRIVMSG) - ./firebot "$text" || \ - ./infobot woozle.cdb "$text" + case "$forum" in + \#woozle|\#foozle) + ./firebot "$text" || \ + ./whuffie woozle.whuffie.cdb "$text" || \ + ./infobot woozle.factoids.cdb "$text" + ;; + esac ;; INVITE) printf '\aJOIN %s\n' "$forum" diff --git a/infobot b/infobot index d48b64e..c017b5e 100755 --- a/infobot +++ b/infobot @@ -1,10 +1,6 @@ #! /bin/sh -if [ $# -gt 1 ]; then - db=$1; shift -else - db=info.cdb -fi +db=$1; shift text="$1" args=$(echo "$text" | cut -d\ -f2-) diff --git a/whuffie b/whuffie new file mode 100755 index 0000000..ab35b46 --- /dev/null +++ b/whuffie @@ -0,0 +1,41 @@ +#! /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 $amt whuffie" + ;; + *++) + adj + + ;; + *--) + adj - + ;; + *) + exit 1 + ;; +esac +