use IO::Socket::INET; use strict; sub fix_raw($) { if (m/:([^!]+) (#[^\s]+) :(.*)/) { return $1, $2, $3; } } my($server, $port, $channel) = ('irc.p2pchat.net', '6667', '#j-bots'); { my $sock = IO::Socket::INET->new( PeerAddr => $server, PeerPort => $port, PeerProto => 'tcp' ) or dir("Couldn't bind socket. ($!)"); print "Connected.\n"; while (1) { while (my($data) = <$sock>) { chomp($data); if ($data =~ /(Looking up your hostname|Found your hostname)/i) { print "Logging in.\n"; print $sock "NICK ControlBot\r\n"; print $sock "USER ControlBot ControlBot * :ControlBot\r\n"; } elsif ($data =~ /^PING(.*)/i) { print "Ping? Pong.\n"; print $sock "PONG$1\r\n"; } elsif ($data =~ /^(376|422)/) { print "Joining $channel.\n"; print $sock "JOIN $channel\r\n"; last; } print "$data\n"; } sleep(1); } while (1) { while (my($data) = <$sock>) { if ($data =~ /^PING(.*)/i) { print $sock "PONG$1\r\n"; } else { if (my($nick, $chan, $text) = fix_raw($data)) { if (($nick eq 'julie-su') && ($text =~ /^!(.*)/)) { print $sock "PRIVMSG $chan :".`$1`."\r\n"; } } } print "$data\n"; } sleep(1); } }