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

Fix picking MinQuote-length quotes

Christoph Berg 21 лет назад
Родитель
Сommit
177b82d356
3 измененных файлов с 19 добавлено и 10 удалено
  1. 2 0
      docs/Changelog
  2. 6 5
      docs/pisg-doc.xml
  3. 11 5
      modules/Pisg/Parser/Logfile.pm

+ 2 - 0
docs/Changelog

@@ -8,6 +8,8 @@ pisg (0.66) - ??
      patch).
    * Complain about invalid -cfg options (closes SF tracker #1183072 by
      nandmaster).
+   * Fix picking MinQuote-length quotes (closes SF tracker #1183177 by
+     nandmaster).
 
 pisg (0.65) - Fri Apr, 15th 2005
    Christoph:

+ 6 - 5
docs/pisg-doc.xml

@@ -2427,10 +2427,11 @@
     <refsect1>
     <title>Description</title>
     <para>
-    The random quotes displayed in the "Most Active Nicks" section has a
-    certain range specified. With this option you can change the minimum
+    The random quotes displayed in the "Most Active Nicks" section will be
+    picked from a length range. With this option you can change the minimum
     number of letters required for a random quote. Also see the
-    <xref linkend="MaxQuote" /> option.
+    <xref linkend="MaxQuote" /> option. Note that pisg will still choose a
+    short quote if it cannot find a longer one.
     </para>
     </refsect1>
     <refsect1>
@@ -2464,8 +2465,8 @@
     <refsect1>
     <title>Description</title>
     <para>
-    The random quotes displayed in the "Most Active Nicks" section has a
-    certain range specified. With this option you can change the maximum
+    The random quotes displayed in the "Most Active Nicks" section will be
+    picked from a length range. With this option you can change the maximum
     number of letters required for a random quote. Also see the
     <xref linkend="MinQuote" /> option.
     </para>

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

@@ -685,13 +685,19 @@ sub _random_line
 {
     my ($self, $lines, $key, $nick) = @_;
     my $count = 0;
-    my $random;
+    my ($random, $out, $out2) = ("", "", "");
     #warn "$nick did not say anything" unless @{ $lines->{$key}{$nick} };
-    do {
+    while (++$count < 20) {
         $random = ${ $lines->{$key}{$nick} }[rand @{ $lines->{$key}{$nick} }];
-        return '' if ++$count > 20;
-    } while ($self->{cfg}->{noignoredquotes} and $self->{ignorewords_regexp} and $random =~ /$self->{ignorewords_regexp}/i);
-    return $random;
+        if (length($random) < $self->{cfg}->{minquote} or length($random) > $self->{cfg}->{maxquote}) {
+            $out2 = $random; # 2nd best choice
+            next;
+        }
+        next if ($self->{cfg}->{noignoredquotes} and $self->{ignorewords_regexp} and
+                 $random =~ /$self->{ignorewords_regexp}/i);
+        $out = $random;
+    }
+    return $out || $out2;
 }
 
 sub _uniquify_nicks {