Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- IRCDIR="$HOME/botbotirc"
- IRCSERV=irc.freenode.net
- IRCPORT=6667
- IRCCHANS='##altslashdot ##SlashTest'
- #IRCCHANS='##botbottest ##botbottest2'
- IRCNAME='Bazbot`s_BotBot'
- IRCPASSWD='Bazbot`s_BotBot:xxxxxxxxxxxxxxx'
- IRCLOGDIR="$HOME/irclog"
- RSSURL=http://li694-22.members.linode.com/index.rss
- TMPPREFIX="$HOME/.botbot_rss_tmp"
- mkdir -p $IRCLOGDIR
- cat >"$TMPPREFIX.xls" <<E_O_F
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="text" />
- <xsl:template match="node()[local-name()!='item' and local-name()!='RDF']"/>
- <xsl:template match="*[local-name()='item']">
- <xsl:value-of select="*[local-name()='creator']" />
- <xsl:text> posted: </xsl:text>
- <xsl:value-of select="*[local-name()='title']" />
- <xsl:text>, from the </xsl:text>
- <xsl:value-of select="*[local-name()='department']" />
- <xsl:text> department
- </xsl:text>
- </xsl:template>
- </xsl:stylesheet>
- E_O_F
- #force channels lowercase
- IRCCHANS="$(echo $IRCCHANS|tr '[A-Z]' '[a-z]')"
- echo IRCCHANS=$IRCCHANS
- #start respawning ii
- (while true ; do
- if [ $(ii -h 2>&1 |awk 'NR==1 {print int($NF*1000+0.5)}') -lt 1700 ] ; then
- ii -i "$IRCDIR" -s "$IRCSERV" -p "$IRCPORT" -n "$IRCNAME" -k "$IRCPASSWD" &
- iipid=$!
- else
- export IRCPASSWD=$IRCPASSWD
- ii -i "$IRCDIR" -s "$IRCSERV" -p "$IRCPORT" -n "$IRCNAME" -k IRCPASSWD &
- iipid=$!
- fi
- trap "echo /QUIT >\"$IRCDIR/$IRCSERV/in\"; sleep 1; kill $iipid ;
- for chan in \$IRCCHANS ; do echo cleaning \$chan ; cp \"$IRCDIR/$IRCSERV/\$chan/out\" \"$IRCLOGDIR/\$chan.\$(date -Iseconds)\"; rm \"$IRCDIR/$IRCSERV/\$chan/in\"; done
- rm \"$IRCDIR/$IRCSERV/in\"
- exit" TERM
- echo iipid=$iipid
- timeout=0
- until [ -e "$IRCDIR/$IRCSERV/in" -o $timeout -gt 10 ] ; do
- timeout=`expr $timout + 1`
- sleep 1
- done
- if [ -e "$IRCDIR/$IRCSERV/in" ] ; then
- for chan in $IRCCHANS ; do
- echo joining $chan...
- echo "/j $chan" > "$IRCDIR/$IRCSERV/in"
- done
- fi
- wait $iipid
- for chan in $IRCCHANS ; do
- echo cleaning $chan
- cp "$IRCDIR/$IRCSERV/$chan/out" "$IRCLOGDIR/$chan.$(date -Iseconds)";
- rm "$IRCDIR/$IRCSERV/$chan/in"
- done
- rm "$IRCDIR/$IRCSERV/in"
- done) &
- subshpid=$!
- echo subshpid=$subshpid
- trap "kill $subshpid;exit" INT EXIT
- #watchdog
- (while sleep 60; do
- if [ $(find "$IRCDIR/$IRCSERV/" -name out -mmin -10|wc -l) -eq 0 ] ; then
- echo /QUIT >"$IRCDIR/$IRCSERV/in"
- fi
- done)&
- subshpid=$! $subshpid
- echo subshpid=$subshpid
- trap "kill $subshpid;exit" INT EXIT
- #bot reactions
- for chan in $IRCCHANS ; do
- (until [ -e "$IRCDIR/$IRCSERV/$chan/in" ] ; do sleep 1 ; done ;
- tail -Fn1 "$IRCDIR/$IRCSERV/$chan/out" |
- awk 'BEGIN {
- action_count=30;
- for(i=0;i<action_count;i+=5) {
- action[i+0]="flickers its indicator lights";
- action[i+1]="whistles softly";
- action[i+2]="stares ominously";
- action[i+3]="computes trajectories";
- action[i+4]="oscillates its antenna";
- }
- action[action_count-1]="kills all humans";
- srand();
- }
- (/'"$IRCNAME"'/ || /[bB][oO][tT][bB][oO][tT]/) && $3!="<'"$IRCNAME"'>" {
- print "\001ACTION " action[int(rand()*action_count)] "\001" > "'"$IRCDIR/$IRCSERV/$chan/in"'";
- close("'"$IRCDIR/$IRCSERV/$chan/in"'");
- if(i>=action_count) i=0;
- }')&
- monpid="$! $monpid"
- echo monpid=$monpid
- trap "for pid in $monpid; do pkill -P \$pid; done; kill $subshpid $monpid;exit" INT EXIT
- done
- #channel monitoring -- good for debugging, but can be removed
- color=0
- for chan in $IRCCHANS ; do
- #choose colors 1-6, no white or black
- color=$(expr $color % 6 + 1)
- until [ -e "$IRCDIR/$IRCSERV/$chan/in" ] ; do sleep 2 ; done
- tput setaf $color; echo monitoring $chan...; tput sgr0
- (tail -F "$IRCDIR/$IRCSERV/$chan/out"|
- awk "{print \"$(tput setaf $color)\" \$0 \"$(tput sgr0)\"}")&
- tailpid="$! $tailpid"
- echo tailpid=$tailpid
- trap "for pid in $monpid $tailpid; do pkill -P \$pid; done; kill $subshpid $monpid $tailpid;exit" INT EXIT
- done
- sleep 10;
- #rss wrangling
- while true ; do
- [ $(wc -l <"$TMPPREFIX.new") -gt 1 ] && mv "$TMPPREFIX.new" "$TMPPREFIX.old"
- wget -O - "$RSSURL" |
- sed 's/&amp;\(#[0-9]\+;\)/\&\1/g' |
- xsltproc $TMPPREFIX.xsl - |
- tee "$TMPPREFIX.new" |
- tee "$TMPPREFIX.$(date -Iseconds)" |
- diff - "$TMPPREFIX.old" |
- awk '/^</{print substr($0,3)}/^>/{quit}' |
- tac |
- tee $(for chan in $IRCCHANS; do echo "$IRCDIR/$IRCSERV/$chan/in"; done)
- sleep 60
- done
Add Comment
Please, Sign In to add comment