SHARE
TWEET

Untitled

a guest Jul 17th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #############################################################
  2.  
  3. #IRC Bot: receives and sends input to and fro the IRC server.                        
  4.  
  5. #############################################################
  6.  
  7.  
  8.  
  9. #!/usr/bin/perl
  10.  
  11. use warnings;
  12.  
  13. use threads;
  14.  
  15. use IO::Socket::INET;
  16.  
  17.  
  18. $serv = "your.server.here";
  19. $chan = "#yourChannel";
  20. $ident = "yourIdent";
  21. $nick = "yourNick";
  22. $IRC = new IO::Socket::INET(
  23.  
  24.                             PeerAddr => $serv,
  25.  
  26.                             PeerPort => '6667',
  27.  
  28.                             Proto => 'tcp')
  29.  or die "Could not establish connection to IRC server: $!\n";
  30. print $IRC "USER $ident $ident $ident $ident : $nick\n";
  31.  
  32. print $IRC "NICK $nick\n";
  33.  
  34. print $IRC "JOIN $chan\n";
  35.  
  36.  
  37.  
  38. $thread = threads->new(\&getInput); #Start thread (get input)
  39.  
  40.  
  41.  
  42. $in;
  43.  
  44.  
  45.  
  46. ##########MAIN LOOP START#################
  47.  
  48. while($in = <$IRC> ) {
  49.  
  50.     print "$in\n";
  51.  
  52.     if($in =~ /PING(.*)/) {
  53.  
  54.         print $IRC "PONG $1\n";
  55.  
  56.     }
  57.  
  58. }
  59.  
  60. ###########MAIN LOOP END##################
  61.  
  62. sub getInput {
  63.  
  64.     while(true) {
  65.  
  66.         $input = <STDIN>;
  67.  
  68.         if($input =~ /QUIT\b/) {
  69.  
  70.             print "Quiting!";
  71.  
  72.             close($IRC);
  73.  
  74.             die "Quit on user command.";
  75.  
  76.         }
  77.  
  78.         print $IRC "PRIVMSG $chan : $input";
  79.  
  80.     }
  81.  
  82. }
RAW Paste Data
Top