Просмотр исходного кода

* Make FoulWords, ViolentWords, and IgnoreWords configurable per channel
(required quite some black regexp magic; SF tracker #1066103 by jjp3).
* wordlist_regexp uses quotemeta.

Christoph Berg 21 лет назад
Родитель
Сommit
6dcc2d3258
5 измененных файлов с 26 добавлено и 21 удалено
  1. 2 0
      docs/CREDITS
  2. 4 1
      docs/Changelog
  3. 6 12
      modules/Pisg.pm
  4. 4 3
      modules/Pisg/Common.pm
  5. 10 5
      modules/Pisg/Parser/Logfile.pm

+ 2 - 0
docs/CREDITS

@@ -110,6 +110,8 @@ Other contributors:
    | pisg(1) manpage
  * Torbjörn Svensson <azoff@se.linux.org>
    | ShowFoulDecimals option
+ * coaster
+   | improved mirc6hack.mrc
 
 I probably forgot a lot of people here, _PLEASE_ notify me if I left you
 out.. because I have a bad habit of forgetting to maintain this list :)

+ 4 - 1
docs/Changelog

@@ -1,7 +1,10 @@
 pisg (0.62) - ??
    Changes by Christoph Berg:
-   * Update mIRC script for the mIRC6hack format.
+   * Update mIRC script for the mIRC6hack format (thanks, coaster).
    * Warnings about missing Text::Iconv are suppressed by 'silent'.
+   * Make FoulWords, ViolentWords, and IgnoreWords configurable per channel
+     (required quite some black regexp magic; SF tracker #1066103 by jjp3).
+   * wordlist_regexp uses quotemeta.
 
 pisg (0.61) - Sat Oct, 30th 2004
    Changes by Christoph Berg:

+ 6 - 12
modules/Pisg.pm

@@ -65,9 +65,6 @@ sub run
     print "Using config file: $self->{cfg}->{configfile}\n\n"
         if ($r && !$self->{cfg}->{silent});
 
-    $self->init_words()       # Init words. (Foulwords, ignorewords, etc.)
-        if ($self->{use_configfile});
-
     # Get translations from langfile
     $self->get_language_templates();
 
@@ -246,14 +243,6 @@ sub get_language_templates
     close(FILE);
 }
 
-sub init_words
-{
-    my $self = shift;
-    $self->{cfg}->{foulwords} = wordlist_regexp($self->{cfg}->{foulwords}, $self->{cfg}->{regexpaliases});
-    $self->{cfg}->{ignorewords} = wordlist_regexp($self->{cfg}->{ignorewords}, $self->{cfg}->{regexpaliases});
-    $self->{cfg}->{violentwords} = wordlist_regexp($self->{cfg}->{violentwords}, $self->{cfg}->{regexpaliases});
-}
-
 sub init_config
 {
     my $self = shift;
@@ -411,6 +400,11 @@ sub init_pisg
     }
     $self->{cfg}->{timestamp} = $timestamp;
 
+    # convert wordlists
+    $self->{cfg}->{foulwords} = wordlist_regexp($self->{cfg}->{foulwords}, $self->{cfg}->{regexpaliases});
+    $self->{cfg}->{ignorewords} = wordlist_regexp($self->{cfg}->{ignorewords}, $self->{cfg}->{regexpaliases});
+    $self->{cfg}->{violentwords} = wordlist_regexp($self->{cfg}->{violentwords}, $self->{cfg}->{regexpaliases});
+
     # Add trailing slash when it's not there..
     $self->{cfg}->{imagepath} =~ s/([^\/])$/$1\//;
     # Set ImageGlobPath default
@@ -514,7 +508,7 @@ sub parse_channels
             print STDERR "Channel $channel not in config file, ignoring\n";
             next;
         }
-        foreach (keys %{ $self->{chans}->{$channel} }) {
+        foreach (keys %{ $self->{chans}->{$channel} }) { # import channel specific config
             $self->{cfg}->{$_} = $self->{chans}->{$channel}{$_};
         }
         $self->do_channel();

+ 4 - 3
modules/Pisg/Common.pm

@@ -205,9 +205,10 @@ sub wordlist_regexp
     my $regexpaliases = shift;
     unless($regexpaliases) {
         map {
-            $_ = /^\*(.*)/ ? $1 : "\\b$_";
-            $_ = /(.*)\*$/ ? $1 : "$_\\b";
-            s/\*/.*/g;
+            $_ = quotemeta; # quote everything
+            s/\\\*/\\S*/g; # replace \*
+            s/^\\S\*// or $_ = "\\b$_"; # ... but remote it at beginning/end of word
+            s/\\S\*$// or $_ = "$_\\b";
         } @words;
     }
     return join '|', @words;

+ 10 - 5
modules/Pisg/Parser/Logfile.pm

@@ -52,6 +52,11 @@ sub new
         }
     }
 
+    # precompile the regexps used (we can't use /o since the config might be different per channel)
+    $self->{foulwords_regexp} = qr/($self->{cfg}->{foulwords})/i;
+    $self->{ignorewords_regexp} = qr/$self->{cfg}->{ignorewords}/i;
+    $self->{violentwords_regexp} = qr/^($self->{cfg}->{violentwords}) (\S+)(.*)/i;
+
     return $self;
 }
 
@@ -365,7 +370,7 @@ sub _parse_file
                         }
                     }
 
-                    if (my @foul = $saying =~ /($self->{cfg}->{foulwords})/io) {
+                    if (my @foul = $saying =~ /($self->{foulwords_regexp})/) {
                         $stats->{foul}{$nick} += scalar @foul;
                         push @{ $lines->{foullines}{$nick} }, $line;
                     }
@@ -392,7 +397,7 @@ sub _parse_file
                         }
                     }
 
-                    _parse_words($stats, $saying, $nick, $self->{cfg}->{ignorewords}, $hour);
+                    _parse_words($stats, $saying, $nick, $self->{ignorewords_regexp}, $hour);
                 }
             }
             $lastnormal = $line;
@@ -433,7 +438,7 @@ sub _parse_file
                 $stats->{lastvisited}{$nick} = $stats->{days};
                 $stats->{line_times}{$nick}[int($hour/6)]++;
 
-                if ($saying =~ /^($self->{cfg}->{violentwords}) (\S+)(.*)/o) {
+                if ($saying =~ /$self->{violentwords_regexp}/) {
                     my $victim;
                     unless ($victim = is_nick($2)) {
                         foreach my $trynick (split(/\s+/, $3)) {
@@ -454,7 +459,7 @@ sub _parse_file
 
                 $stats->{lengths}{$nick} += length($saying);
 
-                _parse_words($stats, $saying, $nick, $self->{cfg}->{ignorewords}, $hour);
+                _parse_words($stats, $saying, $nick, $self->{ignorewords_regexp}, $hour);
             }
         }
 
@@ -619,7 +624,7 @@ sub _random_line
 {
     my ($self, $stats, $lines, $key, $nick, $count) = @_;
     my $random = ${ $lines->{$key}{$nick} }[rand@{ $lines->{$key}{$nick} }];
-    if ($self->{cfg}->{noignoredquotes} && $random =~ /$self->{cfg}->{ignorewords}/io) {
+    if ($self->{cfg}->{noignoredquotes} && $random =~ /$self->{ignorewords_regexp}/i) {
         return '' if ($count > 20);
         return $self->_random_line($stats, $lines, $key, $nick, ++$count);
     } else {