#!/usr/bin/env perl use warnings; use IO::Socket; use threads; use threads::shared; #---------------------------------------------------------------------- # configuration #---------------------------------------------------------------------- my $server : shared = "irc.example.com"; my $nick : shared = "NICKNAME"; my $chan : shared = "#CHANNEL"; my $sourcefile : shared = "getlow.txt"; my $delay : shared = 1.5; #---------------------------------------------------------------------- my @lines; my $sock; # read the source file open(my $file, $sourcefile) or die("Could not open $sourcefile"); while (my $line = <$file>) { chomp($line); push(@lines, $line); } close($file) or die("Could not close $sourcefile"); # connect print "Connecting...\n"; $sock = new IO::Socket::INET( PeerAddr => $server, PeerPort => "6667", Proto => 'tcp' ) or die "Could not open socket"; # log in my $login = $nick; print "Logging in...\n"; print $sock "NICK $nick\r\n" or die "NICK command failed"; print $sock "USER $login $login $login $nick\r\n" or die "USER command failed"; while (my $msg = <$sock>) { if ($msg =~ /004\s$nick/) { last; # now logged in } elsif ($msg =~ /433 $nick/) { die "Nickname $nick already in use"; } } # join the channel print "Joining $chan...\n"; print $sock "JOIN $chan\r\n" or die "Cannot join $chan"; while (my $msg = <$sock>) { chomp $msg; print "$msg\n"; if ($msg =~ /366\s$nick/) { last; # end of /names } } # watch for PING messages, and reply with a PONG to avoid disconnection sub pingpong { while (my $msg = <$sock>) { chomp $msg; print "$msg\n"; if ($msg =~ /^PING(.*)$/i) { print $sock "PONG $1\r\n"; } } } # speak lines at regular intervals sub speak { sleep ($delay + $delay); foreach my $line (@lines) { if ($line) { sleep ($delay + 0.2*sqrt(length($line))); print "> $line\n"; print $sock "PRIVMSG $chan :$line\r\n"; } } sleep ($delay + $delay); print "Quitting...\n"; print $sock "QUIT :YEAH\r\n"; } threads->new(\&pingpong)->detach; threads->new(\&speak)->join;