X-Git-Url: https://git.donarmstrong.com/?p=irc.git;a=blobdiff_plain;f=.irssi%2Fscripts%2Fauto_bleh.pl;h=0a8316ea830757c6d7a61b1a9e602c5001760dfc;hp=e279987a63bbedb1a301e92814e8341d40c2a934;hb=506178958eebde48304e60c62450f391742e6427;hpb=a92395ba40effe44c593deb8d4a5454be6125342 diff --git a/.irssi/scripts/auto_bleh.pl b/.irssi/scripts/auto_bleh.pl index e279987..0a8316e 100644 --- a/.irssi/scripts/auto_bleh.pl +++ b/.irssi/scripts/auto_bleh.pl @@ -7,12 +7,12 @@ use vars qw($VERSION %IRSSI $DEBUG); # 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; @@ -24,6 +24,7 @@ my ($actions, %defaults); 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', @@ -45,21 +46,21 @@ my %bans_to_remove; 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{ @@ -67,18 +68,18 @@ 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); } @@ -87,25 +88,25 @@ sub cmd_amr{ 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); } @@ -122,6 +123,36 @@ sub do_auto_bleh { 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', + # OFTC now supports +q/-q. + #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 @@ -178,33 +209,39 @@ sub get_op { sub i_want { my $action = shift; - return "I've wanted to $action->{type} $action->{nick} off $action->{channel} on $action->{network} since $action->{inserted}"; + return "I've wanted to ".join(',', keys %{$action->{type}||{'do something to'=>undef}}). + " $action->{nick} off $action->{channel} on $action->{network} since $action->{inserted}"; } 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}) { - $server->send_raw("MODE $action->{channel} +b %*!*@".$action->{hostname}) if $action->{hostname} ne ''; #quiet hostname + $server->send_raw("MODE $action->{channel} +q *!*@".$action->{hostname}) if $action->{hostname} ne ''; #quiet 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}"); @@ -213,7 +250,7 @@ sub take_action { $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}"); @@ -222,15 +259,21 @@ sub take_action { $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. } @@ -260,7 +303,7 @@ sub sig_mode_change { # 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; @@ -282,11 +325,17 @@ sub attempt_actions { Irssi::print(i_want($actions->{$_})) if $DEBUG; # Find the server to take action on my $server = Irssi::server_find_chatnet($actions->{$_}->{network}); - Irssi::print("Unable to find server for chatnet: $actions->{$_}->{network}") and return if not defined $server; + if (not defined $server) { + Irssi::print("Unable to find server for chatnet: $actions->{$_}->{network}"); + return; + } Irssi::print("Found server for chatnet: $actions->{$_}->{network}") if $DEBUG; # Find the channel to take action on my $s_channel = $server->channel_find($actions->{$_}->{channel}); - Irssi::print("Unable to find channel for channel: $actions->{$_}->{channel}") and return if not defined $s_channel; + if (not defined $s_channel){ + Irssi::print("Unable to find channel for channel: $actions->{$_}->{channel}"); + return; + } Irssi::print("Found channel for channel: $actions->{$_}->{channel}") if $DEBUG; # Are we opped on that channel? if ($s_channel->{chanop}) { # Yes? Take the action against the user. @@ -309,7 +358,7 @@ sub try_to_remove_bans { 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};