use strict;
use vars qw($VERSION %IRSSI);

use Irssi;

$VERSION = '1.00';
%IRSSI = (
    authors	=> 'David O\'Rourke',
    contact	=> 'irssi@null-routed.com',
    name	=> 'banregexp',
    description	=> 'ban anyone who joins specified channel and matches the regexp provided',
    license	=> 'Public Domain',
    url		=> 'http://irssi.org/scripts/',
    changed	=> 'GMT',
);

my $regexp = "[a-z][A-Z0-9]{8,8}";
my $active_chan = '#channel';
my $reason = "Get out";

sub banregexp_joined {
	my ($server, $channel, $nick, $addr) = @_;
	return unless ($channel eq $active_chan);
	
	my $chanrec = $server->channel_find($active_chan);
	return unless $chanrec;
	#Irssi::print "$nick joined $channel";
	
	if ($nick =~ /^$regexp$/) {
		Irssi::print "$nick on $channel matches banned regexp \^$regexp\$, kickbanning...";
		$chanrec->command("KICKBAN $nick $reason");
	}
}

Irssi::signal_add('message join', 'banregexp_joined');

