Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.31 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3. use IO::Socket::INET6;
  4.  
  5. our $server     = "irc.freenode.net";
  6. our $port       = "6667";
  7. our $channel        = "#ubuntu";
  8. our $nick       = "GaryNiger";
  9. our $phrases        = "autism.txt";
  10. our $chatdelay      = 500; #base chat delay, modified by "chattiness" of a channel
  11. our $delaymodifier  = 10; #time subtracted from chatdelay every time a line is chatted
  12.  
  13. open FILE, "<$phrases" or die "Could not open $phrases: $!\n";
  14. our @chats=<FILE>;
  15. close FILE;
  16.  
  17. print "*** Connecting to ".$server.":".$port."...\r\n";
  18.  
  19. our $sock = IO::Socket::INET6->new(PeerAddr => $server,
  20. PeerPort => $port,
  21. Proto    => 'tcp');
  22.  
  23. print "*** Connected!\r\n";
  24.  
  25.  
  26. print "*** Registering as ".$nick."...\r\n";
  27.  
  28. print $sock "NICK ".$nick."\r\n";
  29. print $sock "USER ".$nick." 8 * :".$nick.".\r\n";
  30.  
  31. while ( my $input = <$sock> ) {
  32.     if ( $input =~ /004/ ) {
  33.         last;
  34.     }
  35.     elsif ( $input =~ /433/ ) {
  36.         die "Nickname is already in use.";
  37.     }
  38. }
  39.  
  40. print "*** Joining ".$channel." and resetting timers...\r\n";
  41.  
  42. print $sock "JOIN $channel\r\n";
  43. our $lastchat = time();
  44.  
  45. while ( my $input = <$sock> ) {
  46.     chop $input;
  47.     our $interval = ($chatdelay-(time()-$lastchat));   
  48.     our $Hours = int($interval/3600);
  49.     our $Minutes = int(($interval - $Hours * 3600) / 60);
  50.     our $Seconds = $interval % 60;
  51.     print "-> [Delay: ".$Hours."h".$Minutes."m".$Seconds."s] ".$input."\n";
  52.     if ( $input =~ /^PING(.*)$/i ) {
  53.         print $sock "PONG $1\r\n";
  54.         print "<- PONG ".$1." \r\n";
  55.     }
  56.  
  57.     if ( $input =~ /bot.do/ ) {
  58.         chop $input;
  59.         our @dongmax = split('bot.do ', $input);
  60.         print $sock $dongmax[1]."\r\n";
  61.         print "<- ".$dongmax[1]."\r\n";
  62.     }
  63.    
  64.     if ( $input !~ /freenode\/staff/ ) {
  65.         if ( $input =~ /PRIVMSG/ ) {
  66.             if ( time()-$lastchat > $chatdelay ) {
  67.                 our @loljews = split(':', $input);
  68.                 our @chatter = split('!',$loljews[1]);
  69.                 our $delay = int(rand(15)+5);
  70.                 our $randomline=$chats[rand @chats];
  71.                 chop $randomline;
  72.                 print "*** Replying to ".$chatter[0]." in ".$delay." seconds with '".$randomline."'.\r\n";
  73.                 sleep $delay;
  74.                 print $sock "PRIVMSG ".$channel." :".$chatter[0].": ".$randomline."\r\n";
  75.                 print "<- PRIVMSG ".$channel." :".$chatter[0].": ".$randomline."\r\n";
  76.                 $lastchat = time();
  77.             } else {
  78.                 $lastchat = $lastchat-$delaymodifier;
  79.             }
  80.            
  81.         }
  82.     }
  83.     if ( $input =~ /bot.fire/ ) {
  84.         $lastchat = 0;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement