On Mon, Oct 19, 2009 at 04:04:12PM -0400, Josh Rickmar wrote:
I would like to (re)write an irc bot using sic, but the formatted output
is making this harder then it could/should be. For example, the first
field, the channel or irc server, is cut off at 12 characters by a
colon. This becomes a problem when trying to parse the output because
longer field names can be cut off. It can also cause the number of
fields (seperated by whitespace) to change since a field with >=12
characters will be missing a space between the name and the colon.
To make this program more useful, wouldn't it be better if all the
information was presented to the user? Doing so would make writing bots
much easier and would allow the user to easily format the output any way
he/she wants to by passing sic's output to awk.
I've written IRC bots with sic before, and made the same
modification. Try kris/sic.c from the hg repo.
--
Kris Maglione
He hoped and prayed that there wasn't an afterlife. Then he realized
there was a contradiction involved here and merely hoped that there
wasn't an afterlife.
--Douglas Adams
#!/usr/local/plan9/bin/rc
path = (/usr/local/plan9/bin $path)
nick = eris
server = irc.oftc.net
port = 6667
fn sic { $home/bin/sic $* }
fifo = $home/.irc_fifo
dir = $home/sl_logger
channels = ('#wmii')
test -e $fifo || mkfifo $fifo
'$'='$'
loggers=()
ifs=() for(chan in $channels) {
ifs=`{echo} { file = `{echo -n $chan | sed 's/#//g'} }
loggers = ($loggers `{cat <<! | sed s/CHAN/$"chan/g';
's/FILE/^$"file^'/g'})
}
>{grep '^CHAN ' | httplog -s '$dir/FILE.current.log' '$dir/FILE.%Y%m%d.log'} \
>{awk '/^CHAN [^>]+> +BUG/ {
sub("^[^:]+: *", "")
print
fflush()
}' | { while(l=`{read}) { echo $$l >> '$dir/FILE.bugs' } }} \
!
{
while (true) {
chan=<{ for(chan in $channels)
echo :j $chan
while(true)
cat $fifo }
sic -h $server -p $port -n $nick <$chan
}
} | eval tee $loggers >$dir/sic.log