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

Add config option "NoIgnoredQuotes" - will not output quotes containing ignored words if this is set. Will output a blank line after trying 20 random quotes if all 20 random quotes were ignored.

sbingner 23 лет назад
Родитель
Сommit
562e233697
4 измененных файлов с 57 добавлено и 8 удалено
  1. 3 0
      docs/Changelog
  2. 29 0
      docs/pisg-doc.sgml
  3. 10 4
      modules/Pisg.pm
  4. 15 4
      modules/Pisg/Parser/Logfile.pm

+ 3 - 0
docs/Changelog

@@ -13,6 +13,9 @@ pisg (x.xx)
      each word.
    * Add note to lang.txt that the <set lang=""> line should be inserted into
      the configuration file. Some users were confused about this.
+   * Add config option "NoIgnoredQuotes" - will not output quotes containing
+     ignored words if this is set.  Will output a blank line after trying 20
+     random quotes if all 20 random quotes were ignored.
 
 pisg (0.46) - Tue Feb, 11th 2003
    * Fix serious bug which caused garbled output i "Latest topics" and other

+ 29 - 0
docs/pisg-doc.sgml

@@ -1831,6 +1831,35 @@
     </refsect1>
     </refentry>
 
+    <!-- *** NOIGNOREDQUOTES *** -->
+    <refentry id="NoIgnoredQuotes">
+
+    <refmeta> <refentrytitle>NoIgnoredQuotes</refentrytitle> </refmeta>
+
+    <refnamediv>
+    <refname>NoIgnoredQuotes</refname>
+    <refpurpose>Control random quote output</refpurpose>
+    </refnamediv>
+
+    <refsynopsisdiv><programlisting>
+      <![CDATA[
+        <set NoIgnoredQuotes="1">
+      ]]>
+    </programlisting></refsynopsisdiv>
+
+    <refsect1>
+    <title>Description</title>
+    <para>
+     When set to "1", pisg will not output quotes containing ignored words.
+     Pisg will output a blank line after trying 20 random quotes if all 20 random quotes were ignored.
+    </para>
+    </refsect1>
+    <refsect1>
+    <title>Default</title>
+    <para> 0 </para>
+    </refsect1>
+    </refentry>
+
     <!-- *** FOULWORDS *** -->
     <refentry id="FoulWords">
 

+ 10 - 4
modules/Pisg.pm

@@ -186,6 +186,7 @@ sub get_default_config_settings
         foulwords => 'ass fuck bitch shit scheisse scheiße kacke arsch ficker ficken schlampe',
         violentwords => 'slaps beats smacks',
         ignorewords => '',
+        noignoredquotes => 0,
         tablewidth => 614,
         regexpaliases => 0,
 
@@ -271,13 +272,18 @@ sub init_words
 {
     my $self = shift;
     $self->{cfg}->{foulwords} =~ s/(^\s+|\s+$)//g;
-    my $foultemp = $self->{cfg}->{foulwords};
-    $self->{cfg}->{foulwords} =~ s/\s+/|\b/g;
-    $self->{cfg}->{foulwords} = '\b' . $self->{cfg}->{foulwords} . '|' . $foultemp . '\b';
-    $self->{cfg}->{foulwords} =~ s/\s+/\b|/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;
 }

+ 15 - 4
modules/Pisg/Parser/Logfile.pm

@@ -74,7 +74,7 @@ sub analyze
             $self->_parse_file(\%stats, \%lines, $self->{cfg}->{logfile}, \%state);
         }
 
-        _pick_random_lines(\%stats, \%lines);
+        $self->_pick_random_lines(\%stats, \%lines);
         _uniquify_nicks(\%stats);
 
         my ($sec,$min,$hour) = gmtime(time() - $starttime);
@@ -512,16 +512,27 @@ sub _parse_words
 
 sub _pick_random_lines
 {
-    my ($stats, $lines) = @_;
+    my ($self, $stats, $lines) = @_;
 
     foreach my $key (keys %{ $lines }) {
         foreach my $nick (keys %{ $lines->{$key} }) {
-            $stats->{$key}{$nick} = 
-            @{ $lines->{$key}{$nick} }[rand@{ $lines->{$key}{$nick} }];
+            $stats->{$key}{$nick} = $self->_random_line($stats, $lines, $key, $nick, 0);
         }
     }
 }
 
+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) {
+        return '' if ($count > 20);
+        return $self->_random_line($stats, $lines, $key, $nick, ++$count);
+    } else {
+        return $random;
+    }
+}
+
 sub _uniquify_nicks {
     my ($stats) = @_;