Make notes its own script

This commit is contained in:
Neale Pickett 2010-12-16 22:02:43 -07:00
parent a2b4bfdba5
commit 8a55ad119b
4 changed files with 34 additions and 22 deletions

View File

@ -20,9 +20,10 @@ case $command in
PRIVMSG) PRIVMSG)
case "$forum" in case "$forum" in
\#*) \#*)
./notes woozle/notes "$text"
./firebot "$text" || \ ./firebot "$text" || \
./whuffie woozle.whuffie.cdb "$text" || \ ./whuffie woozle/whuffie.cdb "$text" || \
./infobot woozle.factoids.cdb "$text" ./infobot woozle/factoids.cdb "$text"
;; ;;
esac esac
;; ;;

13
firebot
View File

@ -12,25 +12,12 @@ firebot () {
dst=$(printf "%s" "$args" | sed 's/.*-> //') dst=$(printf "%s" "$args" | sed 's/.*-> //')
units -1 -v -- "$src" "$dst" 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 exit 1
;; ;;
esac esac
} }
if [ -f notes/$sender ]; then
echo "Welcome back, $sender. Your messages:"
cat notes/$sender
rm notes/$sender
fi
echo "$1" | firebot echo "$1" | firebot

16
infobot
View File

@ -2,7 +2,6 @@
db=$1; shift db=$1; shift
text="$1" text="$1"
args=$(echo "$text" | cut -d\ -f2-)
lookup () { lookup () {
if ! cdb -q -m $db "$1"; then if ! cdb -q -m $db "$1"; then
@ -31,12 +30,13 @@ EOF
cdb -s $db | head -n 1 cdb -s $db | head -n 1
;; ;;
!l*) !l*)
printf "%s" "$args" args=$(echo "$text" | cut -d\ -f2-)
cdb -q -m $db "$args" | \ printf "factoids for \"%s\": " "$args"
awk '{printf("|%s", $0);}' cdb -q -m $db "$args" | awk '{printf("|%s", $0);}'
echo echo
;; ;;
!a*) !a*)
args=$(echo "$text" | cut -d\ -f2-)
key=$(printf "%s" "$args" | sed 's/ +=.*//') key=$(printf "%s" "$args" | sed 's/ +=.*//')
val=$(printf "%s" "$args" | sed 's/.*+= //') val=$(printf "%s" "$args" | sed 's/.*+= //')
(printf "+%d,%d:%s->%s\n" ${#key} ${#val} "$key" "$val"; (printf "+%d,%d:%s->%s\n" ${#key} ${#val} "$key" "$val";
@ -44,6 +44,7 @@ EOF
echo "Okay, $sender, I added a factoid to $key" echo "Okay, $sender, I added a factoid to $key"
;; ;;
!r*) !r*)
args=$(echo "$text" | cut -d\ -f2-)
key=$(printf "%s" "$args" | sed 's/ -=.*//') key=$(printf "%s" "$args" | sed 's/ -=.*//')
val=$(printf "%s" "$args" | sed 's/.*-= //') val=$(printf "%s" "$args" | sed 's/.*-= //')
re=":$key->.*$val" re=":$key->.*$val"
@ -55,7 +56,8 @@ EOF
echo "Nothing matched, $sender." echo "Nothing matched, $sender."
fi fi
;; ;;
!f*) !forget\ *)
args=$(echo "$text" | cut -d\ -f2-)
cdb -d $db | grep -a -F -v ":$args->" | cdb -c $db cdb -d $db | grep -a -F -v ":$args->" | cdb -c $db
echo "I removed all factoids from $args" echo "I removed all factoids from $args"
;; ;;
@ -69,10 +71,10 @@ EOF
echo "Someone's up to no good!" 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" echo "It's been said that $text is $resp"

22
notes Executable file
View File

@ -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