- Joined
- Jul 31, 2008
- Sythe Gold
- 0
- Messages
- 57
Code:
use IO::Socket;
$server = "irc.not-a-bot.net";
$port = 1337;
$channel = "#test";
$nick = "perlbot";
$sock = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "$server", PeerPort => "$port") || die "Failed to connect to $server:$port\n";
print $sock "NICK $nick\r\n";
print $sock "USER $nick $server $nick $nick\r\n";
print $sock "JOIN $channel\r\n";
print $sock "PRIVMSG $channel :Hello\r\n";
while(<$sock>) {
print $_;
if(/PING/) {
$line = $_;
$line =~ s/PING/PONG/;
print $sock $line;
} elsif(/PRIVMSG/) {
$line = $_;
$line =~ s/\r\n//; # Remove \r\n
@tokens = split /:/, $line; # Split line into tokens
@command = split / /, @tokens[1]; # Split second token (first is just blank in this case)
@message = split / /, @tokens[2]; # Split third token
@user = split /!/, @command[0]; # Split first command token, which is USERNAME!USERHOST
if($message[0] =~ m/.exit/) {
print $sock "PRIVMSG $command[2] :Exit command sent by $user[0] ($user[1])\r\n";
print $sock "QUIT :$message[1]\r\n";
close $sock;
}
if($message[0] =~ m/.join/) {
print $sock "PRIVMSG $command[2] :Join command sent by $user[0] ($user[1])\r\n";
print $sock "JOIN $message[1]\r\n";
}
if($message[0] =~ m/.msg/) {
print $sock "PRIVMSG $command[2] :Message command sent by $user[0] ($user[1])\r\n";
print $sock "PRIVMSG $message[1] :$message[2]\r\n";
}
}
}
Simple IRC Bot - Enjoy!


