in reply to perl bot problems

Hello

There are several problems in your code. I'll list them below. But first, why are you not using Net::IRC? If you want to reinvent the wheel, then why are you not using IO::Socket::INET? Why are you doing all the dirty work yourself?

Here are the things that are causing the problems:

  1. $botnick is used but never defined.
  2. $name also is used but never defined.
  3. You are using sysread to read from the socket, however, IRC is not a binary protocol. You should use <SOCK> instead.
  4. You are reading one char at a time which is not what you should do.
  5. This segment will always return an empty string:
     if ($inchar eq "\n") # $inchar is one char long
            {
              chop $inline; # remove it
              return $inline; # return empty.
            }
  6. You are defining the function connec which does the connect but never actually calling it.
  7. It works after fixing all the above points.

Now back to using IO::Socket::INET, the above code can be shortened to:

use IO::Socket; my $server = 'irc.openprojects.net'; my $port = 6667; my $nick = 'aziz'; my $name = 'Abdulaziz Ghuloum'; my $sock = IO::Socket::INET->new( PeerAddr => $server, PeerPort => $port) or die "Cannot connect: $!\n"; print $sock "USER $nick buf buf :$name\r\n"; print $sock "NICK $nick\r\n"; while(<$sock>){ print; my ($pingchk,$rest)=split(/ /,$_,2); if ($pingchk eq 'PING') { print $sock "PONG $rest\r\n"; } }
Hope this helps,,,

Aziz,,,

Replies are listed 'Best First'.
Re: Re: perl bot problems
by Anonymous Monk on Aug 10, 2001 at 23:58 UTC
    Isn't there another way using vec() select()? I found some other perl irc bots and they all seem to use some form of select() or IO::Select??
      Hello again

      I suggest that you start with the basics first. IO::Select and select are only used when you need to handle multiple connections at the same time. Write your simple bot that does one thing first, add features as you go. Read the docs carefully. Just because someone used select does not mean that you should. Know why you need it before deciding that you do. After reading all the docs, understanding them, hanging them in your bathroom, then if you get stumbled, ask again :-) I think it's simple :-)

      Aziz,,,