From 8a55ad119bde0f8dbc8dfe53c650211ad875cd7b Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 16 Dec 2010 22:02:43 -0700 Subject: [PATCH] Make notes its own script --- cobalt-handler | 5 +++-- firebot | 13 ------------- infobot | 16 +++++++++------- notes | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 22 deletions(-) create mode 100755 notes diff --git a/cobalt-handler b/cobalt-handler index 0d5c712..1648240 100755 --- a/cobalt-handler +++ b/cobalt-handler @@ -20,9 +20,10 @@ case $command in PRIVMSG) case "$forum" in \#*) + ./notes woozle/notes "$text" ./firebot "$text" || \ - ./whuffie woozle.whuffie.cdb "$text" || \ - ./infobot woozle.factoids.cdb "$text" + ./whuffie woozle/whuffie.cdb "$text" || \ + ./infobot woozle/factoids.cdb "$text" ;; esac ;; diff --git a/firebot b/firebot index 38b2281..845ab66 100755 --- a/firebot +++ b/firebot @@ -12,25 +12,12 @@ firebot () { dst=$(printf "%s" "$args" | sed 's/.*-> //') units -1 -v -- "$src" "$dst" ;; - .note) - who=$(printf "%s" "$args" | sed 's/ .*//;s/[^-A-Za-z0-9]/./') - what=$(printf "%s" "$args" | cut -d\ -f2-) - when=$(date) - echo "($when) <$sender> $what" > notes/$who - echo "I've left $who a note, $sender." - ;; *) exit 1 ;; esac } -if [ -f notes/$sender ]; then - echo "Welcome back, $sender. Your messages:" - cat notes/$sender - rm notes/$sender -fi - echo "$1" | firebot diff --git a/infobot b/infobot index d7dbfa0..591480f 100755 --- a/infobot +++ b/infobot @@ -2,7 +2,6 @@ db=$1; shift text="$1" -args=$(echo "$text" | cut -d\ -f2-) lookup () { if ! cdb -q -m $db "$1"; then @@ -31,12 +30,13 @@ EOF cdb -s $db | head -n 1 ;; !l*) - printf "%s" "$args" - cdb -q -m $db "$args" | \ - awk '{printf("|%s", $0);}' + args=$(echo "$text" | cut -d\ -f2-) + printf "factoids for \"%s\": " "$args" + cdb -q -m $db "$args" | awk '{printf("|%s", $0);}' echo ;; !a*) + args=$(echo "$text" | cut -d\ -f2-) key=$(printf "%s" "$args" | sed 's/ +=.*//') val=$(printf "%s" "$args" | sed 's/.*+= //') (printf "+%d,%d:%s->%s\n" ${#key} ${#val} "$key" "$val"; @@ -44,6 +44,7 @@ EOF echo "Okay, $sender, I added a factoid to $key" ;; !r*) + args=$(echo "$text" | cut -d\ -f2-) key=$(printf "%s" "$args" | sed 's/ -=.*//') val=$(printf "%s" "$args" | sed 's/.*-= //') re=":$key->.*$val" @@ -55,7 +56,8 @@ EOF echo "Nothing matched, $sender." fi ;; - !f*) + !forget\ *) + args=$(echo "$text" | cut -d\ -f2-) cdb -d $db | grep -a -F -v ":$args->" | cdb -c $db echo "I removed all factoids from $args" ;; @@ -69,10 +71,10 @@ EOF echo "Someone's up to no good!" ;; \\*) - printf "%s" "$resp" | cut -b2- + printf "%s" "${resp#\\}" ;; :*) - printf '\001ACTION %s\001\n' "$(echo "$resp" | cut -b2-)" + printf '\001ACTION %s\001\n' "${resp#:}" ;; *) echo "It's been said that $text is $resp" diff --git a/notes b/notes new file mode 100755 index 0000000..e9c5de2 --- /dev/null +++ b/notes @@ -0,0 +1,22 @@ +#! /bin/sh + +db=$1; shift +text=$1 + +if [ -f $db/$sender ]; then + echo "Welcome back, $sender. Your messages:" + cat $db/$sender + rm $db/$sender +fi + +case "$text" in + .note\ *) + args=${text#.note } + who=${args%% *} + what=${args#* } + when=$(date) + + echo "($when) <$sender> $what" >> $db/$who + echo "Okay, $sender, I've left $who a note." + ;; +esac