Hello, I'm trying to write a simple IRC Bot, but it keeps on disconnecting after it connects (i think i need a loop.). Here is what I have so far (please leave the critizism to a minimun :P):
#!/usr/bin/perl ################################################# # Name: Pollux v1.0b # # Author: Jasper # # Description: Simple IRC Bot. # # E-Mail: jasper@wintermarket.org # # WWW: http://wintermarket.org:81/~jasper/ # ################################################# use IO::Socket; use IO::Select; use IO::Handle; use Time::localtime; require 'pollux.lib'; $SIG{CHLD} = sub {wait()}; srand; ################## #bot configuration $nick = "botnick"; #bot nick $pass = "pw"; #password $realname = "name"; #bot name $user = int(rand(10000) + 1); #ident username (default: random numbers +) $server = "some.server.net"; #connect to server $sport = 6667; #server port (default: 6667) $spass = ""; #server password (if none, leave empty) $channel = "#channel"; #on connect join channel $chanpass = ""; #channel password (if none, leave empty) print "Pollux IRC Bot v1.0b Written By: Jasper <jasper\@wintermarket.o +rg>\nUSAGE: perl pollux10b.pl\n"; print "\nBot Nick: $nick *$realname* Username: $user\nServer: $serv +er:$sport Channel: $channel\n"; $sock = IO::Socket::INET->new ( PeerAddr => $server, PeerPort => $sport, Proto => "tcp" ); if($sock==undef) { print "Could not connect to Host!\n"; exit; } print $sock &makeusrid($sport,$realname); print $sock &makepass($pass); print $sock &makenick($nick); print $sock &makeusr($user,$hostname,$server,$realname); $buff; $sock->recv($buff,15000); print $buff; #$chan = &chanparse($buff); #no complete! $chan =$channel; $rnick = &nickparse($buff); $cmd = &cmdparse($buff); if (index($buff,"376")) { print $sock "JOIN $channel\r\n"; print $sock "PRIVMSG $channel :0Hello, My name is $ni +ck.\r\n"; #lame greeting } if (index($buff,"372")) { print $sock "JOIN $channel\r\n"; } if (index($buff,"PING")) { $loc=index($buff,":"); $num=substr($buff,$loc++); print $sock "PONG $num\r\n"; } if (index($cmd,".md5")) { $md5 = &md5hash($buff); print $sock $md5; } if (index($cmd,".join")) { $jchan = &paraparse($buff); print $sock "JOIN $jchan\r\n"; } if (index($cmd,".die")) { print $sock "QUIT :0...and there wa +s much rejoicing0"; } if (index($cmd,".nick")) { $newnick = &paraparse($buff); if ($newnick ne "") { print $sock "NICK $newnick\r\n"; } else { print $sock "NICK $nick\r\n"; } } if (index($cmd,".rndnick")) { $newnick = &rndstr(6); print $sock "NICK $newnick\r\n"; } if (index($cmd,".v")) { print $sock "PRIVMSG $chan :0Pollux S +cript v1.0b By: Jasper\r\n"; } if (index($cmd,".part")) { print $sock "PART $chan 0...and th +ere was much rejoicing0\r\n"; } if (index($cmd,".time")) { print $sock "PRIVMSG $chan 0Curren +t Day/Time: ctime()\r\n"; } if (index($cmd,".mode")) { print $sock "MODE $chan &paraparse( +$buff)\r\n"; } if (index($cmd,".action")) { print $sock "NOTICE $chan &parap +arse($data)\r\n"; } if (index($cmd,".lastseen")) { print $sock "PRIVMSG $chan 0no +t quite yet...\r\n"; } if (index($cmd,".google")) { print $sock "PRIVMSG $chan 0not +quite yet...\r\n"; } if (index($cmd,".kill")) { print $sock "KILL &nickparse($data) + :0Anger is a tool, only for one's opponents\r\n"; } if (index($cmd,".away")) { print $sock "AWAY :0out...0\r\n"; + } if (index($data,"KICK")) { print $sock "PRIVMSG $chan :0haha +:P0\r\n"; } print $sock "QUIT 0...and there was much rejoicing\r\n"; close $sock;

Edit by tye to use <code> tags


In reply to Socket Client Disconnect by Jaspersan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.