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

* Foul words no longer matches at the beginning or the end of the word. Eg.
"ass" won't match "assembler" or "asshole" anymore. (thanks, Christoph
Berg)
* Support for wildcards/asterix in IgnoreWords, FoulWords and ViolentWords
has been implemented. Eg. use "ass*" to accomplish the behaviour that was
changed in the above entry. (thanks, Christoph Berg)
* RegexpAliases now also applies to IgnoreWords, FoulWords and
ViolentWords. (thanks, Christoph Berg)

Morten Brix Pedersen 22 лет назад
Родитель
Сommit
ceadeaca88
6 измененных файлов с 47 добавлено и 29 удалено
  1. 2 1
      docs/CREDITS
  2. 8 0
      docs/Changelog
  3. 10 6
      docs/pisg-doc.sgml
  4. 5 16
      modules/Pisg.pm
  5. 17 1
      modules/Pisg/Common.pm
  6. 5 5
      modules/Pisg/Parser/Logfile.pm

+ 2 - 1
docs/CREDITS

@@ -100,7 +100,8 @@ And all the other contributors:
  * "Travis Roy" <travis@scootz.net>
    | perlbot logfile support
  * Christoph Berg <cb@df7cb.de>
-   | NFiles and UserPics options, wildcards for random user pictures
+   | NFiles and UserPics options, wildcards for random user pictures,
+   | wildcard and regexp support for IgnoreWords, FoulWords, ViolentWords.
  * Nathan Poznick
    | Ability to specify multiple LogFiles and LogDirs.
 

+ 8 - 0
docs/Changelog

@@ -7,6 +7,14 @@ pisg (x.xx)
    fixed.
    * Multiple LogDirs and LogFiles can now be specified (thanks, Nathan
    Poznick)
+   * Foul words no longer matches at the beginning or the end of the word. Eg.
+   "ass" won't match "assembler" or "asshole" anymore. (thanks, Christoph
+   Berg)
+   * Support for wildcards/asterix in IgnoreWords, FoulWords and ViolentWords
+   has been implemented. Eg. use "ass*" to accomplish the behaviour that was
+   changed in the above entry. (thanks, Christoph Berg)
+   * RegexpAliases now also applies to IgnoreWords, FoulWords and
+   ViolentWords. (thanks, Christoph Berg)
 
 pisg (0.51) - Wed Jan, 21st 2004
    * Fixed a bug in the irssi format where an action could be recognized as a

+ 10 - 6
docs/pisg-doc.sgml

@@ -1949,7 +1949,7 @@
 
     <refsynopsisdiv><programlisting>
       <![CDATA[
-        <set IgnoreWords="you me">
+        <set IgnoreWords="there about">
       ]]>
     </programlisting></refsynopsisdiv>
 
@@ -1958,7 +1958,8 @@
     <para>
     Sometimes words in the "most used words" appears which you don't want to
     see, with this option you can ignore these words. It also applies to the
-    "most referenced nicks" section. It's a space seperated list of words.
+    "most referenced nicks" section. It's a space separated list of words.
+    You can use * like in nick aliases.
     Can not be used in a channel-only context.
     </para>
     </refsect1>
@@ -2018,7 +2019,8 @@
     <para>
     There is a section in the "Most interesting numbers" which tells who had
     a "dirty mouth" - here you can define which words are considered being
-    bad/foul. It is a space seperated list of words.
+    bad/foul. It is a space separated list of words.
+    You can use * like in nick aliases.
     Can not be used in a channel-only context.
     </para>
     </refsect1>
@@ -2049,8 +2051,8 @@
     <para>
     There is a section in the "Most interesting numbers" which tells who is
     most "aggressive" - here you can define which words are considered being
-    "violent". It is a space seperated list of words.  Can not be used in a
-    channel-only context.
+    "violent". It is a space separated list of words. You can use * like in
+    nick aliases. Can not be used in a channel-only context.
     </para>
     </refsect1>
     <refsect1>
@@ -2942,7 +2944,9 @@
     <title>Description</title>
     <para>
     Enabling this option will make all aliases in &lt;user&gt; lines be
-    parsed as regular expressions.
+    parsed as regular expressions; this setting also applies to the
+    <command>IgnoreWords<command>, </command>FoulWords</command>, and
+    <command>ViolentWords</command> settings.
     </para>
     </refsect1>
     <refsect1>

+ 5 - 16
modules/Pisg.pm

@@ -244,21 +244,9 @@ sub get_language_templates
 sub init_words
 {
     my $self = shift;
-    $self->{cfg}->{foulwords} =~ s/(^\s+|\s+$)//g;
-    my @foulwords = split(/\s+/, $self->{cfg}->{foulwords});
-    $self->{cfg}->{foulwords} = '\b' . join('|\b', @foulwords) . '|' . join('\b|', @foulwords) . '\b';
-    $self->{cfg}->{ignorewords} =~ s/(^\s+|\s+$)//g;
-    foreach (split(/\s+/, $self->{cfg}->{ignorewords})) {
-        $self->{cfg}->{ignoreword}{$_} = 1;
-    }
-    if ($self->{cfg}->{noignoredquotes}) {
-        my $igntmp = $self->{cfg}->{ignorewords};
-        $igntmp =~ s/(\[|\]|\(|\)|\/|\\)/\\$1/g;
-        my @ignorewords = split(/\s+/, $igntmp);
-        $self->{cfg}->{ignorewordsregex} = '\b' . join('|\b', @ignorewords) . '|' . join('\b|', @ignorewords) . '\b';
-    }
-    $self->{cfg}->{violentwords} =~ s/(^\s+|\s+$)//g;
-    $self->{cfg}->{violentwords} =~ s/\s+/|/g;
+    $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
@@ -267,7 +255,7 @@ sub init_config
     my $fh   = shift;
     while (my $line = <$fh>)
     {
-        next if ($line =~ /^#/);
+        next if ($line =~ /^\s*#/);
         chomp $line;
 
         if ($line =~ /<user.*>/) {
@@ -359,6 +347,7 @@ sub init_config
                 }
             }
             while (<$fh>) {
+                next if /^\s*#/;
                 last if ($_ =~ /<\/*channel>/i);
                 if ($_ =~ /^\s*(\w+)\s*=\s*(["'])(.+?)\2/) {
                     my $var = lc($1);

+ 17 - 1
modules/Pisg/Common.pm

@@ -8,7 +8,7 @@ Pisg::Common - some common functions of pisg.
 
 use Exporter;
 @ISA = ('Exporter');
-@EXPORT = qw(add_alias add_aliaswild add_ignore add_url_ignore is_ignored url_is_ignored find_alias store_aliases restore_aliases match_urls match_email htmlentities is_nick randomglob);
+@EXPORT = qw(add_alias add_aliaswild add_ignore add_url_ignore is_ignored url_is_ignored find_alias store_aliases restore_aliases match_urls match_email htmlentities is_nick randomglob wordlist_regexp);
 
 use strict;
 $^W = 1;
@@ -224,4 +224,20 @@ sub randomglob
     return $return;
 }
 
+sub wordlist_regexp
+{
+    my $list = shift;
+    $list =~ s/^\s+//; # split ignores trailing empty fields
+    my @words = split(/\s+/, $list);
+    my $regexpaliases = shift;
+    unless($regexpaliases) {
+        map {
+            $_ = /^\*(.*)/ ? $1 : "\\b$_";
+            $_ = /(.*)\*$/ ? $1 : "$_\\b";
+            s/\*/.*/g;
+        } @words;
+    }
+    return join '|', @words;
+}
+
 1;

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

@@ -351,7 +351,7 @@ sub _parse_file
                         }
                     }
 
-                    _parse_words($stats, $saying, $nick, $self->{cfg}->{ignoreword}, $hour);
+                    _parse_words($stats, $saying, $nick, $self->{cfg}->{ignorewords}, $hour);
                 }
             }
             $lastnormal = $line;
@@ -413,7 +413,7 @@ sub _parse_file
 
                 $stats->{lengths}{$nick} += length($saying);
 
-                _parse_words($stats, $saying, $nick, $self->{cfg}->{ignoreword}, $hour);
+                _parse_words($stats, $saying, $nick, $self->{cfg}->{ignorewords}, $hour);
             }
         }
 
@@ -536,7 +536,7 @@ sub _modechanges
 
 sub _parse_words
 {
-    my ($stats, $saying, $nick, $ignoreword, $hour) = @_;
+    my ($stats, $saying, $nick, $ignorewords, $hour) = @_;
     # Cache time of day
     my $tod = int($hour/6);
 
@@ -544,7 +544,7 @@ sub _parse_words
         $stats->{words}{$nick}++;
         $stats->{word_times}{$nick}[$tod]++;
         # remove uninteresting words
-        next if ($ignoreword->{$word});
+        next if $ignorewords and $word =~ m/$ignorewords/i;
 
         # ignore contractions
         next if ($word =~ m/'.{1,2}$/o);
@@ -572,7 +572,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}->{ignorewordsregex}/io) {
+    if ($self->{cfg}->{noignoredquotes} && $random =~ /$self->{cfg}->{ignorewords}/io) {
         return '' if ($count > 20);
         return $self->_random_line($stats, $lines, $key, $nick, ++$count);
     } else {