# 0.05 -- Add IPv6 support
-$VERSION = q$Revision: 1.1 $;
+$VERSION = q$Revision$;
%IRSSI = (authors => 'Don Armstrong',
name => 'auto_bleh',
description => 'Provides /ak /aq /ab /abr /abrn /arn /amb /amr /at',
license => 'GPL',
- changed => q$Id: auto_bleh.pl,v 1.1 2005/03/17 08:19:53 don Exp $,
+ changed => q$Id$,
);
$DEBUG = 1 unless defined $DEBUG;
EXPIRE => 6000, # Do not try to do anything if the action is more than 6000 seconds old.
DEOP => 1, # Automatically deop after we've done whatever we were supposed to do.
TIMEOUT => 10, # Timeout /at bans after 10 minutes
+ SMELLSLIKEFN => qr/freenode.net/,
);
my %command_bindings = (ak => 'cmd_ak',
sub cmd_at {
my ($data, $server, $witem) = @_;
- return do_auto_bleh('timeout',$data,$server,$witem);
+ return do_auto_bleh([qw(timeout)],$data,$server,$witem);
}
sub cmd_ak {
my ($data, $server, $witem) = @_;
- return do_auto_bleh('kick',$data,$server,$witem);
+ return do_auto_bleh([qw(kick)],$data,$server,$witem);
}
sub cmd_abk {
my ($data, $server, $witem) = @_;
- return do_auto_bleh('kick,ban',$data,$server,$witem);
+ return do_auto_bleh([qw(kick ban)],$data,$server,$witem);
}
sub cmd_abkn {
my ($data, $server, $witem) = @_;
- return do_auto_bleh('kick,ban,notice',$data,$server,$witem);
+ return do_auto_bleh([qw(kick ban notice)],$data,$server,$witem);
}
sub cmd_amb{
my @nicks = split /\s+/, $data;
for (@nicks) {
next unless /\w/;
- do_auto_bleh('ban',$_,$server,$witem);
+ do_auto_bleh([qw(ban)],$_,$server,$witem);
}
}
sub cmd_ab {
my ($data, $server, $witem) = @_;
- return do_auto_bleh('ban',$data,$server,$witem);
+ return do_auto_bleh([qw(ban)],$data,$server,$witem);
}
sub cmd_aq {
my ($data, $server, $witem) = @_;
- return do_auto_bleh('quiet',$data,$server,$witem);
+ return do_auto_bleh([qw(quiet)],$data,$server,$witem);
}
my @nicks = split /\s+/, $data;
for (@nicks) {
next unless /\w/;
- do_auto_bleh('remove',$_,$server,$witem);
+ do_auto_bleh([qw(remove)],$_,$server,$witem);
}
}
sub cmd_ar {
my ($data, $server, $witem) = @_;
- return do_auto_bleh('remove',$data,$server,$witem);
+ return do_auto_bleh([qw(remove)],$data,$server,$witem);
}
sub cmd_abr{
my ($data, $server, $witem) =@_;
- return do_auto_bleh('remove,ban',$data,$server,$witem);
+ return do_auto_bleh([qw(remove ban)],$data,$server,$witem);
}
sub cmd_abrn{
my ($data, $server, $witem) =@_;
- return do_auto_bleh('remove,ban,notice',$data,$server,$witem);
+ return do_auto_bleh([qw(remove ban notice)],$data,$server,$witem);
}
sub cmd_arn{
my ($data, $server, $witem) =@_;
- return do_auto_bleh('remove,notice',$data,$server,$witem);
+ return do_auto_bleh([qw(remove,notice)],$data,$server,$witem);
}
return;
}
+ if (ref($cmd) eq 'HASH') {
+ # do nothing
+ }
+ elsif (ref($cmd) eq 'ARRAY') {
+ $cmd = {map {$_,1} @$cmd};
+ }
+ elsif (not ref($cmd)) {
+ $cmd = {map {$_,1} split /\s*,\s*/, $cmd};
+ }
+ else {
+ die "Cmd: $cmd option to do_auto_bleh is not a supported type";
+ }
+
+ # Fix up options for opn which doesn't do quiet or remove;
+ # turn them into ban and kick, respectively.
+ if ($server->{address} !~ $defaults{SMELLSLIKEFN}) {
+ my %fn_mapping = (remove => 'kick',
+ quiet => 'ban',
+ unquiet => 'unban',
+ timeout => 'btimeout',
+ );
+ for my $key (keys %fn_mapping) {
+ if ($$cmd{$key}) {
+ delete $$cmd{$key};
+ $$cmd{$fn_mapping{$key}} = 1;
+ }
+ }
+ }
+
# use Data::Dumper;
# Irssi::print(Dumper($data,$server,$witem));
# set the network that we're on, the channel and the nick to kick
sub take_action {
my ($action,$server,$channel) = @_;
- local $_ = $action->{type};
+ my $type = $action->{type};
# Now support multiple actions against a single nick (to FE, kick
# ban, or remove ban). See /abr foo
- if (/timeout/) {
+ if ($type->{timeout}) {
Irssi::print("Quieting $action->{nick} on $action->{channel} with hostname $action->{hostname} for $action->{timeout} minutes");
$server->send_raw("MODE $action->{channel} +q *!*@".$action->{hostname}) if $action->{hostname} ne ''; #quiet hostname
$bans_to_remove{"$action->{nick}$action->{inserted}"} = $action;
}
- if (/quiet/) {
+ if ($type->{btimeout}) {
+ Irssi::print("Quieting $action->{nick} on $action->{channel} with hostname $action->{hostname} for $action->{timeout} minutes");
+ $server->send_raw("MODE $action->{channel} +b *!*@".$action->{hostname}) if $action->{hostname} ne ''; #quiet hostname
+ $bans_to_remove{"$action->{nick}$action->{inserted}"} = $action;
+ }
+ if ($type->{quiet}) {
Irssi::print("Quieting $action->{nick} on $action->{channel} with hostname $action->{hostname}") if $DEBUG;
# Find hostname
if ($action->{hostname}) {
}
}
- if (/ban/) {
+ if ($type->{ban}) {
Irssi::print("Banning $action->{nick} from $action->{channel} with hostname $action->{hostname}") if $DEBUG;
$server->send_raw("MODE $action->{channel} +b *!*@".$action->{hostname}) if $action->{hostname} ne ''; # ban hostname
}
- if (/kick/) {
+ if ($type->{kick}) {
Irssi::print("Kicking $action->{nick} from $action->{channel}") if $DEBUG;
if ($action->{reason} =~ /\s/) {
$server->send_raw("KICK $action->{channel} $action->{nick} :$action->{reason}");
$server->send_raw("KICK $action->{channel} $action->{nick} $action->{reason}");
}
}
- if (/remove/) {
+ if ($type->{remove}) {
Irssi::print("Removing $action->{nick} from $action->{channel}") if $DEBUG;
if ($action->{reason} =~ /\s/) {
$server->send_raw("REMOVE $action->{channel} $action->{nick} :$action->{reason}");
$server->send_raw("REMOVE $action->{channel} $action->{nick} $action->{reason}");
}
}
- if (/notice/) {
+ if ($type->{notice}) {
Irssi::print("Noticing $action->{nick} with $action->{reason}") if $DEBUG;
$server->command("NOTICE $action->{nick} $action->{reason}");
}
- # unquiet. This is crap, and needs to be changed to something sane.
- if (/teiuq/) {
+ # unquiet
+ if ($type->{unquiet}) {
Irssi::print("Unquieting $action->{nick} on $action->{channel} with hostname $action->{hostname}") if $DEBUG;
$server->command("MODE $action->{channel} -q *!*@".$action->{hostname});
}
+ # unban
+ if ($type->{unban}) {
+ Irssi::print("Unbanning $action->{nick} on $action->{channel} with hostname $action->{hostname}") if $DEBUG;
+ $server->command("MODE $action->{channel} -b *!*@".$action->{hostname});
+ }
+
return; #for now.
}
# Ok, we've been opped, or we are opped now, so do whatever we're supposed to do.
Irssi::print("We've been opped") if $DEBUG;
# We seem to need some sort of delay here for the chanop stuff to catch up
- Irssi::timeout_add_once(250,'attempt_actions',undef);
+ Irssi::timeout_add_once(400,'attempt_actions',undef);
}
else {
Irssi::print("Fooey. Not opped.") if $DEBUG;
return unless keys %bans_to_remove;
for my $key (keys %bans_to_remove) {
if (($bans_to_remove{$key}{inserted} + $bans_to_remove{$key}{timeout}*60) < time) {
- $bans_to_remove{$key}{type} = 'teiuq'; #unquiet
+ $bans_to_remove{$key}{type} = {unquiet => 1}; #unquiet
$actions->{$key} = $bans_to_remove{$key};
delete $bans_to_remove{$key};
get_op($actions->{$key}{server}, $actions->{$key}{channel}) if $defaults{GET_OP};