[PERL]Simple IRC Bot

Discussion in 'Web Programming' started by Emperos, Jul 31, 2008.

[PERL]Simple IRC Bot
  1. Unread #1 - Jul 31, 2008 at 1:27 AM
  2. Emperos
    Joined:
    Jul 31, 2008
    Posts:
    57
    Referrals:
    0
    Sythe Gold:
    0

    Emperos Member
    Banned

    [PERL]Simple IRC Bot

    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!
     
  3. Unread #2 - Aug 6, 2008 at 3:11 AM
  4. Evan_Duh2
    Joined:
    Jun 19, 2007
    Posts:
    958
    Referrals:
    1
    Sythe Gold:
    0

    Evan_Duh2 Apprentice
    Banned

    [PERL]Simple IRC Bot

    Thanks man needed this for my Rs clan. <3
     
< buying template custom made for me | the best language of all >

Users viewing this thread
1 guest


 
 
Adblock breaks this site