9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] ircbot Chugly comes along
@ 2001-06-13 21:09 Matt
  0 siblings, 0 replies; only message in thread
From: Matt @ 2001-06-13 21:09 UTC (permalink / raw)
  To: 9fans

okay here it is

I've gone for the eval risk here. I know it's ill advised but this was a
demonstration rather than a piece of suggested daily code.
I've not used command line parameters either so that the code isn't too
cluttered with parameter checking

if you copy and paste it, this code won't work because I've used tr to strip
the cr character from the input. I've replaced it here with $cr

The script will join the irc server and join $defaultchannel.
It outputs the tcp dir on stdout
It will then output the irc messages on stdout
To make it eval some code do :
chug command to execute

for instance
chug cat /usr/matt/bin/rc/chugly

will print the source code

BUGS
If it get's disconnected it prints 'no match' on stderr

I've uploaded it in raw to
http://www.proweb.co.uk/~matt/chugly.rc

#!/bin/rc
clonefile = /net/tcp/clone
dialstring = 192.168.1.9!6667  # replace with your irc server :)
defaultchannel = '#test'
botname = Chugly
$cr = "\n" # this isn't true it's the cr that I can't type here
<[4] $clonefile {
    netdir=`{basename -d $clonefile} ^ / ^  `{cat /fd/4}
    echo connect $dialstring to $netdir/ctl
    echo connect $dialstring >$netdir/ctl || exit 'cannot connect'
    inchan = no


        while (~ `{cat $netdir/status} Established*) {
            line=(`{read})
            switch ($line(4)) {
            case Checking
                echo USER $botname www.surfnet-is.com irc.server.com
ChuglyV1.0 > $netdir/data
                echo NICK $botname > $netdir/data
            case :chug
                oldifs = $ifs
                ifs='
'
                ev = `{echo $line | tr -d $cr | awk '{for(i=5; i<=NF; i++)
printf "%s ", $i; printf "\n"}'}
                for (k in `{eval $ev})
                    echo PRIVMSG $defaultchannel :$k > $netdir/data
                ifs = $oldifs
            }
            if(~ $line(1) PING)

                echo PONG $line(2) > $netdir/data
                if (~ $inchan no) {
                    echo JOIN $defaultchannel > $netdir/data
                    inchan = yes
                }
            }
            echo $line
        }
    } < $netdir/data
}



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-06-13 21:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-13 21:09 [9fans] ircbot Chugly comes along Matt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).