]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
[kicks][crit] use strict; open
authorbw1 <redacted>
Sat, 1 Apr 2017 13:19:21 +0000 (15:19 +0200)
committerbw1 <redacted>
Sat, 1 Apr 2017 13:19:21 +0000 (15:19 +0200)
_testing/config.yml
scripts/kicks.pl

index 34c9c6d2e4a478bddfe0814e0391a231ed044456..6263fde4e154cda10e4e2ebd9fab19f7746ccfdf 100644 (file)
@@ -44,7 +44,6 @@ whitelist:
   - irssiq
   - isdn
   - ixmmsa
-  - kicks
   - l33tmusic
   - localize
   - log2ansi
index 9df93143b356cb73dcff56920609c2d0629a2eae..af9f56790c279c069b89cf7a15b31149becd4257 100644 (file)
@@ -4,76 +4,77 @@
 #    - http://www.penguin-breeder.org/irssi/
 
 #<scriptinfo>
+use strict;
 use vars qw($VERSION %IRSSI);
 
 use Irssi 20020120;
-$VERSION = "0.26";
+$VERSION = "0.27";
 %IRSSI = (
-    authors    => "c0ffee",
-    contact    => "c0ffee\@penguin-breeder.org",
-    name       => "Various kick and ban commands",
-    description        => "Enhances /k /kb and /kn with some nice options.",
-    license    => "Public Domain",
-    url                => "http://www.penguin-breeder.org/irssi/",
-    changed    => "Tue Nov 14 23:19:19 CET 2006",
+    authors => "c0ffee",
+    contact => "c0ffee\@penguin-breeder.org",
+    name    => "Various kick and ban commands",
+    description => "Enhances /k /kb and /kn with some nice options.",
+    license => "Public Domain",
+    url     => "http://www.penguin-breeder.org/irssi/",
+    changed => "2017-03-31",
 );
 #</scriptinfo>
 
 my %kickreasons  = (
-       default => ["random kick victim",
-                   "no",
-                   "are you stupid?",
-                   "i don't like you, go away!",
-                   "oh, fsck off",
-                   "waste other ppls time, elsewhere",
-                   "get out and STAY OUT",
-                   "don't come back",
-                   "no thanks",
-                   "on popular demand, you are now leaving the channel",
-                   "\$N",
-                   "*void*",
-                   "/part is the command you're looking for",
-                   "this is the irssi of borg. your mIRC will be assimilated. resistance is futile.",
-                   "Autokick! mwahahahah!"
-                  ],
-       none    => [""],
-       topic   => ["\$topic"],
+    default => ["random kick victim",
+            "no",
+            "are you stupid?",
+            "i don't like you, go away!",
+            "oh, fsck off",
+            "waste other ppls time, elsewhere",
+            "get out and STAY OUT",
+            "don't come back",
+            "no thanks",
+            "on popular demand, you are now leaving the channel",
+            "\$N",
+            "*void*",
+            "/part is the command you're looking for",
+            "this is the irssi of borg. your mIRC will be assimilated. resistance is futile.",
+            "Autokick! mwahahahah!"
+           ],
+    none    => [""],
+    topic   => ["\$topic"],
 );
 
 
 # fine tune the script for different chatnets
-#    cmdline_k         regular expr that matches a correct cmdline for /k
-#    req_chan          0/1 whether the channel is always part of the cmdline
-#    num_nicks         number of nicks ... (-1 = inf)
-#    start_with_dash   0/1 whether the normal cmdline may start with a dash
-#    match_chn         matches channels
-#    match_n           match nicks
-#    match_reason      matches reasons
-#    default_reason    reason to give as "no reason"
+#    cmdline_k      regular expr that matches a correct cmdline for /k
+#    req_chan       0/1 whether the channel is always part of the cmdline
+#    num_nicks      number of nicks ... (-1 = inf)
+#    start_with_dash    0/1 whether the normal cmdline may start with a dash
+#    match_chn      matches channels
+#    match_n        match nicks
+#    match_reason   matches reasons
+#    default_reason reason to give as "no reason"
 my %cfg = (
-       IRC     => {
-                       cmdline_k       => '\s*([!#+&][^\x0\a\n\r ]*)\s+[-\[\]\\\\\`{}\w_|^\'~]+(,[-\[\]\\\\\`{}\w_|^\'~]+)*\s+\S.*',
-                       req_chan        => 0,
-                       num_nicks       => 3, # actually, /k takes more, but
-                                             # normal irc servers only take
-                                             # three in a row
-                       start_with_dash => 1,
-                       match_chn       => '([!#+&][^\x0\a\n\r ]*)\s',
-                       match_n         => '(?:^|\s+)([-\[\]\\\\\`{}\w_|^\'~]+(?:,[-\[\]\\\\\`{}\w_|^\']+)*)',
-                       match_reason    => '^\s*[!#+&][^\x0\a\n\r ]*\s+[-\[\]\\\\\`{}\w_|^\'~]+(?:,[-\[\]\\\\\`{}\w_|^\'~]+)*\s+(\S.*)$',
-                       default_reason  => '$N'
-               },
-
-       SILC    => {
-                       cmdline_k       => '\s*[^\x0-\x20\*\?,@!]+\s+[^\x0-\x20\*\?,@!]+\s+\S.*',
-                       req_chan        => 1,
-                       num_nicks       => 1,
-                       start_with_dash => 0,
-                       match_chn       => '\s*([^\x0-\x20\*\?,@!]+)\s+[^\x0-\x20\*\?,@!]+(?:,[^\x0-\x20\*\?,@!]+)*',
-                       match_n         => '\s*(?:[^\x0-\x20\*\?,@!]+\s+)?([^\x0-\x20\*\?,@!]+(?:,[^\x0-\x20\*\?,@!]+)*)',
-                       match_reason    => '\s*[^\x0-\x20\*\?,@!]+\s+[^\x0-\x20\*\?,@!]+(?:,[^\x0-\x20\*\?,@!]+)*\s+(\S.*)',
-                       default_reason  => '$N'
-               }
+    IRC => {
+            cmdline_k       => '\s*([!#+&][^\x0\a\n\r ]*)\s+[-\[\]\\\\\`{}\w_|^\'~]+(,[-\[\]\\\\\`{}\w_|^\'~]+)*\s+\S.*',
+            req_chan        => 0,
+            num_nicks       => 3, # actually, /k takes more, but
+                                  # normal irc servers only take
+                          # three in a row
+            start_with_dash => 1,
+            match_chn       => '([!#+&][^\x0\a\n\r ]*)\s',
+            match_n         => '(?:^|\s+)([-\[\]\\\\\`{}\w_|^\'~]+(?:,[-\[\]\\\\\`{}\w_|^\']+)*)',
+            match_reason    => '^\s*[!#+&][^\x0\a\n\r ]*\s+[-\[\]\\\\\`{}\w_|^\'~]+(?:,[-\[\]\\\\\`{}\w_|^\'~]+)*\s+(\S.*)$',
+            default_reason  => '$N'
+        },
+
+    SILC    => {
+            cmdline_k   => '\s*[^\x0-\x20\*\?,@!]+\s+[^\x0-\x20\*\?,@!]+\s+\S.*',
+            req_chan    => 1,
+            num_nicks   => 1,
+            start_with_dash => 0,
+            match_chn   => '\s*([^\x0-\x20\*\?,@!]+)\s+[^\x0-\x20\*\?,@!]+(?:,[^\x0-\x20\*\?,@!]+)*',
+            match_n     => '\s*(?:[^\x0-\x20\*\?,@!]+\s+)?([^\x0-\x20\*\?,@!]+(?:,[^\x0-\x20\*\?,@!]+)*)',
+            match_reason    => '\s*[^\x0-\x20\*\?,@!]+\s+[^\x0-\x20\*\?,@!]+(?:,[^\x0-\x20\*\?,@!]+)*\s+(\S.*)',
+            default_reason  => '$N'
+        }
 );
 
 sub initialize {
@@ -83,51 +84,53 @@ sub initialize {
     my ($basedir) = $conf_file =~ /^(.*\/).*?/;
 
     if (-f $conf_file) {
-       open CONF, $conf_file;
-       
-       while (<CONF>) {
-           $line++;
-
-           next if /^\s*#/;
-
-           chomp;
-           ($key, $reasons) = /^(\S+)\s+(.+)\s*$/ or next;
-
-           if ($reasons =~ /\`([^\s]+).*?\`/) {
-               $kickreasons{$key} = "$reasons";
-               Irssi::print("Added executable $1 as $key...");
-               next;
-           }
-
-           $reasons =~ s/^"(.*)"$/$1/;
-           $reasons =~ s/~/$ENV{HOME}/;
-           $reasons =~ s/^([^\/])/$basedir$1/;
-           
-           if (-f $reasons) {
-
-               $kickreasons{$key} = [];
-
-               open REASON, $reasons;
-
-               while (<REASON>) {
-                   chomp;
-                   push @{$kickreasons{$key}}, $_;
-               }
-
-               close REASON;
-               Irssi::print("Loaded $reasons as $key...");
-           } else {
-               Irssi::print("can't parse config line $line...");
-           }
-       }
-       close CONF;
+        open CONF, '<', $conf_file;
+
+        my $line=0;
+        
+        while (<CONF>) {
+            $line++;
+
+            next if /^\s*#/;
+
+            chomp;
+            (my $key, my $reasons) = /^(\S+)\s+(.+)\s*$/ or next;
+
+            if ($reasons =~ /\`([^\s]+).*?\`/) {
+                $kickreasons{$key} = "$reasons";
+                Irssi::print("Added executable $1 as $key...");
+                next;
+            }
+
+            $reasons =~ s/^"(.*)"$/$1/;
+            $reasons =~ s/~/$ENV{HOME}/;
+            $reasons =~ s/^([^\/])/$basedir$1/;
+            
+            if (-f $reasons) {
+
+                $kickreasons{$key} = [];
+
+                open REASON, '<',  $reasons;
+
+                while (<REASON>) {
+                    chomp;
+                    push @{$kickreasons{$key}}, $_;
+                }
+
+                close REASON;
+                Irssi::print("Loaded $reasons as $key...");
+            } else {
+                Irssi::print("can't parse config line $line...");
+            }
+        }
+        close CONF;
     } else {
         Irssi::print("Could not find configuration file for kicks...");
-       Irssi::print("... use /set kicks_configuration <file>");
+        Irssi::print("... use /set kicks_configuration <file>");
     }
 }
 
-                       
+            
 sub get_a_reason {
     my ($topic) = @_;
 
@@ -142,20 +145,22 @@ sub get_a_reason {
 }
 
 sub cmd_realkick {
-    my ($data, $server, $channel, $cmd) = @_;
+    (my $data, my $server, my $channel, my $cmd) = @_;
     my $reasons = "default";
 
     return if not $server
               or not defined $cfg{$server->{chat_type}}
-             or not $channel
-             or $data =~ /^$cfg{$server->{chat_type}}{cmdline_k}$/;
+          or not $channel
+              or $data =~ /^$cfg{$server->{chat_type}}{cmdline_k}$/;
 
     Irssi::signal_stop();
 
     # let's see whether some options where supplied
-    $default = Irssi::settings_get_str("default_kick_options");
+    my $default = Irssi::settings_get_str("default_kick_options");
     $data = "$default $data" if not $default =~ /^\s*$/;
-    @opts = split /\s+/, $data;
+    my @opts = split /\s+/, $data;
+    my $opt;
+    my $fail=0;
 
     while (($opt) = (shift @opts) =~ /^\s*-(\S+)/) {
       
@@ -163,18 +168,18 @@ sub cmd_realkick {
       
         $data =~ s/^\s*-$opt\s+//, 
             $reasons = lc $opt,
-           next if defined $kickreasons{lc $opt};
+        next if defined $kickreasons{lc $opt};
 
         last if $cfg{$server->{chat_type}}{start_with_dash};
 
         Irssi::print("Unknown option -$opt");
-        $fail = true;
+        $fail = 1;
 
     }
 
     return if $fail;
 
-    $chn = "";
+    my $chn = "";
     ($chn) = $data =~ /^$cfg{$server->{chat_type}}{match_chn}/;
 
     if ($cfg{$server->{chat_type}}{req_chan} && ($chn eq "")) {
@@ -184,37 +189,39 @@ sub cmd_realkick {
 
     # do we need to add a channel?
     if ($chn eq "") {
-       Irssi::print("Not joined to any channel"), return 
-           if $channel->{type} ne "CHANNEL";
+    Irssi::print("Not joined to any channel"), return 
+        if $channel->{type} ne "CHANNEL";
         $chn = $channel->{name};
 
-       $data = "$chn $data";
+    $data = "$chn $data";
     }
 
     # is a reason already supplied?
+    my $reason;
     $reason = get_a_reason($reasons)
         if not (($reason) = $data =~ /$cfg{$server->{chat_type}}{match_reason}/);
 
     $reason = $cfg{$server->{chat_type}}{default_reason}
         if $reason =~ /^\s*$/;
     
-    @nicks = split /,/, ($data =~ /$cfg{$server->{chat_type}}{match_n}/)[0];
-    $num_nicks = $cfg{$server->{chat_type}}{num_nicks};
+    my @nicks = split /,/, ($data =~ /$cfg{$server->{chat_type}}{match_n}/)[0];
+    my $num_nicks = $cfg{$server->{chat_type}}{num_nicks};
     $num_nicks = @nicks if $num_nicks <= 0;
 
+    my @commands;
     undef @commands;
 
     while (@nicks) {
-        $tmp = ($chn ne "" ? "$chn " : "") .
+        my $tmp = ($chn ne "" ? "$chn " : "") .
                join ",", (splice @nicks,0,$num_nicks);
-       $tmp =~ s/([;\\\$])/\\$1/g;
-       push @commands, "$tmp $reason";
+        $tmp =~ s/([;\\\$])/\\$1/g;
+        push @commands, "$tmp $reason";
     }
     
     foreach (@commands) {
       if ($_ =~ /^$cfg{$server->{chat_type}}{cmdline_k}$/) {
         s/\s+$//;
-        $channel->command("EVAL $cmd $_") 
+        $channel->command("EVAL $cmd $_");
       } else {
         Irssi::print("BUG: generated invalid $cmd command: $_");
       }
@@ -237,7 +244,7 @@ sub cmd_kickban {
 
 Irssi::settings_add_str("misc", "default_kick_options", "");
 Irssi::settings_add_str("misc", "kicks_configuration",
-                               Irssi::get_irssi_dir() . "/kicks.conf");
+                Irssi::get_irssi_dir() . "/kicks.conf");
 
 Irssi::command_bind("kick", "cmd_kick");
 Irssi::command_bind("kickban", "cmd_kickban");
git clone https://git.99rst.org/PROJECT