#!/bin/rc # bot: irc bot rfork e dir=$home/lib/bot phrases=$dir/phrases triggers=$dir/triggers pipe=/n/bot srv=bot lastspoken=() ok='' lastn=() cont=0 fn phrase{ if(test -r $phrases) fortune $phrases } fn delay{ sleep `{fortune <{seq 2 0.2 15}} } fn oktospeak{ if(~ $ok no && test `{echo `{date -n} - $lastspoken | bc} -gt 10800) ok='' status=$ok } fn send{ echo $* >>/srv/$srv } fn speak{ target=$1 to=$2 p=`{phrase} if(! ~ $#p 0){ delay if(~ $#to 1) send 'PRIVMSG '$target' :'$to': '$"p if not send 'PRIVMSG '$target' :'$"p lastspoken=`{date -n} ok=no lastn=() cont=0 } } fn heads{ # to remove random behavior change to # status='' ~ `{fortune <{seq 0 1}} 0 } fn nick{ echo $1 | sed 's/!.*//; s/://' } fn maxcont{ fortune <{seq 1 3; echo 100} } if(~ $#* 0 1){ echo 'usage: bot nick addr [channel ...]' >[1=2] exit usage } nick=$1 addr=$2 shift 2 if(~ $#* 0) chans=() if not chans='#'^$* # needed by rss and title if(! test -e /mnt/web/ctl) webfs bind '#|' $pipe ircs -rT -s $srv -f $pipe/data1 $nick!bot $addr stat=$status if(! ~ $stat '') exit $stat <$pipe/data \ while(line=`{read}){ echo $line if(~ $line(2) PRIVMSG && ~ $line(3) $chans){ c=$line(3) for(s in `{echo $line(4-) | sed 's/^://' | tr -d \xd}){ if(~ $s http*){ t=`{title $s >[2]/dev/null} if(! ~ $#t 0) send 'PRIVMSG '$c' :'$"t } } } if(oktospeak && test -r $phrases){ switch($line(2)){ case PRIVMSG c=$line(3) n=`{nick $line(1)} if(~ $c $chans){ if(~ $n $lastn){ if(~ $cont $maxcont){ #if(heads) n=() speak $c $n } if not cont=`{echo $cont + 1 | bc} } if not{ lastn=$n cont=0 maxcont=`{maxcont} } if(oktospeak) if(heads) if(test -r $triggers) if(echo $line | grep -sif $triggers){ #if(heads) n=() speak $c $n } } case JOIN c=`{echo $line(3) | tr -d :\xd} n=`{nick $line(1)} if(~ $c $chans){ #if(~ $n $nick || heads) n=() speak $c $n } } } } & { for(c in $chans) send JOIN $c sleep 20 while(){ urls=`{rss >[2]/dev/null} for(u in $urls) for(c in $chans){ send 'PRIVMSG '$c' :'$u sleep 2 } sleep 3600 } } &