All pastes #120183 Raw Edit

Someone

public text v1 · immutable
·published 2006-08-07 05:34 UTC
rendered paste body
#!/usr/bin/perl -w

use IO::Socket;

my ($nick, $user, $real, $channel, $server) = ("blaxpinger", "pls", "srs", "#psitest", "us.undernet.org");
my ($target, $delay) = ($ARGV[0], $ARGV[1]);

connect_to_irc();
my $last_time = time();
while(<$sock>) {
	s/[\r\n]//g;
        print("IN: $_\n");
	@in = split(/\s+/);
	os ("PONG $1")		if (/PING :(.+)/);
	on_376()		if ($in[1] eq 376);
	on_422()		if ($in[1] eq 422);
	on_privmsg($_)		if ($in[1] eq "PRIVMSG");


}


sub on_376 {
	os("JOIN $channel") if ($channel =~ /^#.+/);
}

sub on_422 {
	os("JOIN $channel") if ($channel =~ /^#.+/);
}

sub on_privmsg
{
    my $last_time = time();
    while (1) {
        if (time() - $last_time > $delay ) {
            os("PRIVMSG \ $target test");
            $last_time = time();
        }
        sleep 1;
    }
    return 0;
}


sub connect_to_irc {
	$sock = IO::Socket::INET->new(	PeerHost	=> "$server",
					PeerPort	=> 6667) or return(1);
	os("USER $user . . :$real");
	os("NICK $nick");
}

sub os {
	print $sock ("@_\n");
}


END {
	print $sock ("QUIT : Bye\n");
	sleep(1);
	exit(1);
}