#! /bin/sh prefix=$1; export prefix; shift command=$1; export command; shift sender=$1; export sender; shift forum=$1; export forum; shift text=$1; export text; shift # $* is now args # Debug output #echo '>>>' ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&2 raw () { fmt="\007$1\n"; shift printf "$fmt" "$@" } join () { raw "JOIN $1" } cobalt () { case "$1" in air) w3m -dump -cols 9999 'http://environweb.lanl.gov/Teom/teom30s.asp?MasterSiteID=211&offset=0' 2> /dev/null | \ awk '/.:..:.. .M/ {print "Los Alamos Air: " $5 "μg/m³ at " $2; exit}' ;; nachos) echo "aieeeee" ;; *) return 1 ;; esac } out=$(tempfile) case $command in 001) for i in $botdir/channels/*; do join $(basename $i) done ;; 433) raw "NICK bot_$(shuf -c 1 /usr/share/dict/words)" ;; PRIVMSG) case "$forum" in \#*) cobalt "$text" || \ $ircdir/firebot "$text" || \ $ircdir/whuffie $botdir/whuffie.cdb "$text" || \ $ircdir/infobot $botdir/factoids.cdb "$text" ;; esac $ircdir/notes $botdir/notes "$text" ;; INVITE) join "$forum" raw "PRIVMSG %s :Thanks for the invitation, %s." "$forum" "$sender" touch $botdir/channels/$forum ;; esac > $out if [ "$forum" != "$sender" ] && [ $(wc -l < $out) -gt 5 ]; then printf "PRIVMSG %s :Too many lines, sending privately.\r\n" "$forum" forum=$sender fi while read -r line; do case "$line" in *) printf "%s\r\n" "${line#}" ;; *) printf "PRIVMSG %s :%s\r\n" "$forum" "$line" ;; esac done < $out rm -f $out