]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Factoids.pl
take a few more things literally
[infobot.git] / src / Modules / Factoids.pl
index 7b1ac1446010d76c9d3aebb3593cf1004e4a7419..89a693498cfc95c07a1246656a534be7a6f420b0 100644 (file)
@@ -15,14 +15,16 @@ use vars qw(%param);
 sub CmdFactInfo {
     my ($faqtoid, $query) = (lc $_[0], $_[1]);
     my @array;
-    my $string = "";
+    my $string = '';
 
-    if ($faqtoid eq "") {
-       &help("factinfo");
+    if ($faqtoid eq '') {
+       &help('factinfo');
        return;
     }
 
-    my %factinfo = &dbGetColNiceHash("factoids", "*", "factoid_key=".&dbQuote($faqtoid));
+    my %factinfo = &sqlSelectRowHash('factoids', '*',
+       { factoid_key => $faqtoid }
+    );
 
     # factoid does not exist.
     if (scalar (keys %factinfo) <= 1) {
@@ -45,7 +47,7 @@ sub CmdFactInfo {
     if ($factinfo{'created_by'}) {
 
        $factinfo{'created_by'} =~ s/\!/ </;
-       $factinfo{'created_by'} .= ">";
+       $factinfo{'created_by'} .= '>';
        $string  = "created by $factinfo{'created_by'}";
 
        my $time = $factinfo{'created_time'};
@@ -55,34 +57,28 @@ sub CmdFactInfo {
                $string .= " at \037". scalar(gmtime $time). "\037" .
                                " ($days days)";
            } else {
-               $string .= " ".&Time2String(time() - $time)." ago";
+               $string .= ' '.&Time2String(time() - $time).' ago';
            }
        }
 
        push(@array,$string);
     }
 
-    # modified:
+    # modified: (TimRiker asks: why do you keep turning this off?)
     if ($factinfo{'modified_by'}) {
-       $string = "last modified";
+       $string = 'last modified';
 
        my $time = $factinfo{'modified_time'};
        if ($time) {
            if (time() - $time > 60*60*24*7) {
                $string .= " at \037". scalar(gmtime $time). "\037";
            } else {
-               $string .= " ".&Time2String(time() - $time)." ago ";
+               $string .= ' '.&Time2String(time() - $time).' ago ';
            }
        }
 
-       my @x;
-       foreach (split ",", $factinfo{'modified_by'}) {
-           /\!/;
-           push(@x, $`);
-       }
-       $string .= "by ".&IJoin(@x);
+       $string .= ' by '.(split ',', $factinfo{'modified_by'})[0];
 
-       $i++;
        push(@array,$string);
     }
 
@@ -91,31 +87,31 @@ sub CmdFactInfo {
        my $requested_count = $factinfo{'requested_count'};
 
        if ($requested_count) {
-           $string  = "it has been requested ";
+           $string  = 'it has been requested ';
            if ($requested_count == 1) {
                $string .= "\002once\002";
            } else {
                $string .= "\002". $requested_count. "\002 ".
-                       &fixPlural("time", $requested_count);
+                       &fixPlural('time', $requested_count);
            }
-       }
-
-       $string .= ", " if ($string ne "");
 
-       my $requested_by = $factinfo{'requested_by'};
-       $requested_by =~ /\!/;
-       $string .= "last by $`";
+           my $requested_by = $factinfo{'requested_by'};
+           $requested_by =~ /\!/;
+           $string .= ", last by $`";
 
-       my $requested_time = $factinfo{'requested_time'};
-       if ($requested_time) {
-           if (time() - $requested_time > 60*60*24*7) {
-               $string .= " at \037". scalar(gmtime $requested_time). "\037";
-           } else {
-               $string .= ", ".&Time2String(time() - $requested_time)." ago";
+           my $requested_time = $factinfo{'requested_time'};
+           if ($requested_time) {
+               if (time() - $requested_time > 60*60*24*7) {
+                   $string .= " at \037". scalar(localtime $requested_time). "\037";
+               } else {
+                   $string .= ', '.&Time2String(time() - $requested_time).' ago';
+               }
            }
+       } else {
+           $string  = 'has not been requested yet';
        }
 
-       push(@array,$string);
+       push(@array, $string);
     }
 
     # locked:
@@ -132,7 +128,7 @@ sub CmdFactInfo {
        return;
     }
 
-    &performStrictReply("$factinfo{'factoid_key'} -- ". join("; ", @array) .".");
+    &performStrictReply("$factinfo{'factoid_key'} -- ". join('; ', @array) .'.');
     return;
 }
 
@@ -140,11 +136,14 @@ sub CmdFactStats {
     my ($type) = @_;
 
     if ($type =~ /^author$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key,created_by", "created_by IS NOT NULL");
+       my %hash = &sqlSelectColHash('factoids',
+               'factoid_key,created_by', undef,
+               'WHERE created_by IS NOT NULL'
+       );
        my %author;
 
-       foreach (keys %hash) {
-           my $thisnuh = $hash{$_};
+       foreach my $factoid (keys %hash) {
+           my $thisnuh = $hash{$factoid};
 
            $thisnuh =~ /^(\S+)!\S+@\S+$/;
            $author{lc $1}++;
@@ -164,21 +163,24 @@ sub CmdFactStats {
        my $count;
        my @list;
        foreach $count (sort { $b <=> $a } keys %count) {
-           my $author = join(", ", sort keys %{ $count{$count} });
+           my $author = join(', ', sort keys %{ $count{$count} });
            push(@list, "$count by $author");
        }
 
-       my $prefix = "factoid statistics by author: ";
+       my $prefix = 'factoid statistics by author: ';
        return &formListReply(0, $prefix, @list);
 
     } elsif ($type =~ /^vandalism$/i) {
-        &status("factstats(vandalism): starting...");
+       &status('factstats(vandalism): starting...');
        my $start_time  = &timeget();
-       my %data        = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL");
+       my %data        = &sqlSelectColHash('factoids',
+               'factoid_key,factoid_value', undef,
+               'WHERE factoid_value IS NOT NULL'
+       );
        my @list;
 
        my $delta_time  = &timedelta($start_time);
-        &status(sprintf("factstats(vandalismbroken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
+       &status(sprintf('factstats(vandalism): %.02f sec to retreive all factoids.', $delta_time)) if ($delta_time > 0);
        $start_time     = &timeget();
 
        # parse the factoids.
@@ -190,7 +192,7 @@ sub CmdFactStats {
        }
 
        $delta_time     = &timedelta($start_time);
-        &status(sprintf("factstats(vandalism): %.02f sec to complete.", $delta_time)) if ($delta_time > 0);
+       &status(sprintf('factstats(vandalism): %.02f sec to complete.', $delta_time)) if ($delta_time > 0);
 
        # bail out on no results.
        if (scalar @list == 0) {
@@ -198,11 +200,11 @@ sub CmdFactStats {
        }
 
        # parse the results.
-       my $prefix = "Vandalised factoid ";
+       my $prefix = 'Vandalised factoid ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^total$/i) {
-        &status("factstats(total): starting...");
+       &status('factstats(total): starting...');
        my $start_time  = &timeget();
        my @list;
        my $str;
@@ -211,49 +213,50 @@ sub CmdFactStats {
 
        ### lets do it.
        # total factoids requests.
-       $i = &sumKey("factoids", "requested_count");
+       $i = &sumKey('factoids', 'requested_count');
        push(@list, "total requests - $i");
 
        # total factoids modified.
-       $str = &countKeys("factoids", "modified_by");
+       $str = &countKeys('factoids', 'modified_by');
        push(@list, "total modified - $str");
 
        # total factoids modified.
-       $j      = &countKeys("factoids", "requested_count");
-       $str    = &countKeys("factoids", "factoid_key");
-       push(@list, "total non-requested - ".($str - $i));
+       $j      = &countKeys('factoids', 'requested_count');
+       $str    = &countKeys('factoids', 'factoid_key');
+       push(@list, 'total non-requested - '.($str - $i));
 
        # average request/factoid.
        # i/j == total(requested_count)/count(requested_count)
-       $str = sprintf("%.01f", $i/$j);
+       $str = sprintf('%.01f', $i/$j);
        push(@list, "average requested per factoid - $str");
 
        # total prepared for deletion.
-       $str    = scalar( &searchTable("factoids", "factoid_key", "factoid_value", " #DEL") );
+       $str    = scalar( &searchTable('factoids', 'factoid_key', 'factoid_value', ' #DEL') );
        push(@list, "total prepared for deletion - $str");
 
        # total unique authors.
-       foreach ( &dbRawReturn("SELECT created_by FROM factoids WHERE created_by IS NOT NULL") ) {
+       # TODO: convert to sqlSelectColHash ? (or ColArray?)
+       foreach ( &sqlRawReturn('SELECT created_by FROM factoids WHERE created_by IS NOT NULL') ) {
            /^(\S+)!/;
            my $nick = lc $1;
            $hash{$nick}++;
        }
-       push(@list, "total unique authors - ".(scalar keys %hash) );
+       push(@list, 'total unique authors - '.(scalar keys %hash) );
        undef %hash;
 
        # total unique requesters.
-       foreach ( &dbRawReturn("SELECT requested_by FROM factoids WHERE requested_by IS NOT NULL") ) {
+       foreach ( &sqlRawReturn('SELECT requested_by FROM factoids WHERE requested_by IS NOT NULL') ) {
            /^(\S+)!/;
            my $nick = lc $1;
            $hash{$nick}++;
        }
-       push(@list, "total unique requesters - ".(scalar keys %hash) );
+       push(@list, 'total unique requesters - '.(scalar keys %hash) );
        undef %hash;
 
-       ### end of "job".
+       ### end of 'job'.
 
        my $delta_time  = &timedelta($start_time);
-        &status(sprintf("factstats(broken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
+       &status(sprintf('factstats(broken): %.02f sec to retreive all factoids.', $delta_time)) if ($delta_time > 0);
        $start_time     = &timeget();
 
        # bail out on no results.
@@ -262,21 +265,21 @@ sub CmdFactStats {
        }
 
        # parse the results.
-       my $prefix = "General factoid stiatistics ";
+       my $prefix = 'General factoid statistics ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^deadredir$/i) {
-       my @list = &searchTable("factoids", "factoid_key",
-                       "factoid_value", "^<REPLY> see ");
+       my @list = &searchTable('factoids', 'factoid_key',
+                       'factoid_value', '^<REPLY> see ');
        my %redir;
        my $f;
 
        for (@list) {
            my $factoid = $_;
-           my $val = &getFactInfo($factoid, "factoid_value");
+           my $val = &getFactInfo($factoid, 'factoid_value');
            if ($val =~ /^<REPLY> ?see( also)? (.*?)\.?$/i) {
                my $redirf = lc $2;
-               my $redir = &getFactInfo($redirf, "factoid_value");
+               my $redir = &getFactInfo($redirf, 'factoid_value');
                next if (defined $redir);
                next if (length $val > 50);
 
@@ -295,13 +298,16 @@ sub CmdFactStats {
        }
 
        # parse the results.
-       my $prefix = "Loose link (dead) redirections in factoids ";
+       my $prefix = 'Loose link (dead) redirections in factoids ';
        return &formListReply(1, $prefix, @newlist);
 
     } elsif ($type =~ /^dup(licate|e)$/i) {
-        &status("factstats(dupe): starting...");
+       &status('factstats(dupe): starting...');
        my $start_time  = &timeget();
-       my %hash        = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL", 1);
+       my %hash        = &sqlSelectColHash('factoids',
+               'factoid_key,factoid_value', undef,
+               'WHERE factoid_value IS NOT NULL', 1
+       );
        my $refs        = 0;
        my @list;
        my $v;
@@ -318,8 +324,8 @@ sub CmdFactStats {
                }
 
                s/([\,\;]+)/\037$1\037/g;
-               if ($_ eq "") {
-                   &WARN("dupe: _ = NULL. should never happen!.");
+               if ($_ eq '') {
+                   &WARN('dupe: _ = NULL. should never happen!.');
                    next;
                }
                push(@sublist, $_);
@@ -327,20 +333,20 @@ sub CmdFactStats {
 
            next unless (scalar @sublist);
 
-           push(@list, join(", ", @sublist));
+           push(@list, join(', ', @sublist));
        }
 
        &status("factstats(dupe): (good) dupe refs: $refs.");
        my $delta_time  = &timedelta($start_time);
-        &status(sprintf("factstats(dupe): %.02f sec to complete", $delta_time)) if ($delta_time > 0);
+       &status(sprintf('factstats(dupe): %.02f sec to complete', $delta_time)) if ($delta_time > 0);
 
        # bail out on no results.
        if (scalar @list == 0) {
-           return "no duplicate factoids... woohoo.";
+           return 'no duplicate factoids... woohoo.';
        }
 
        # parse the results.
-       my $prefix = "dupe factoid ";
+       my $prefix = 'dupe factoid ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^nullfactoids$/i) {
@@ -350,7 +356,7 @@ sub CmdFactStats {
 
        my @list;
        while (my @row = $sth->fetchrow_array) {
-           if ($row[1] ne "") {
+           if ($row[1] ne '') {
                &DEBUG("row[1] != NULL for $row[0].");
                next;
            }
@@ -361,12 +367,12 @@ sub CmdFactStats {
        $sth->finish;
 
        # parse the results.
-       my $prefix = "NULL factoids (not deleted yet) ";
+       my $prefix = 'NULL factoids (not deleted yet) ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^(2|too)short$/i) {
        # Custom select statement.
-       my $query = "SELECT factoid_key,factoid_value FROM factoids WHERE length(factoid_value) <= 40";
+       my $query = 'SELECT factoid_key,factoid_value FROM factoids WHERE length(factoid_value) <= 40';
        my $sth = $dbh->prepare($query);
        &ERROR("factstats(lame): => '$query'.") unless $sth->execute;
 
@@ -388,12 +394,12 @@ sub CmdFactStats {
        $sth->finish;
 
        # parse the results.
-       my $prefix = "Lame factoids ";
+       my $prefix = 'Lame factoids ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^listfix$/i) {
        # Custom select statement.
-       my $query = "SELECT factoid_key,factoid_value FROM factoids";
+       my $query = 'SELECT factoid_key,factoid_value FROM factoids';
        my $sth = $dbh->prepare($query);
        &ERROR("factstats(listfix): => '$query'.") unless $sth->execute;
 
@@ -408,16 +414,19 @@ sub CmdFactStats {
            push(@list, $key);
            $val =~ s/,? or /, /g;
            &DEBUG("fixed: => $val.");
-           &setFactInfo($key,"factoid_value", $val);
+           &setFactInfo($key,'factoid_value', $val);
        }
        $sth->finish;
 
        # parse the results.
-       my $prefix = "Inefficient lists fixed ";
+       my $prefix = 'Inefficient lists fixed ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^locked$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key,locked_by", "locked_by IS NOT NULL");
+       my %hash = &sqlSelectColHash('factoids',
+               'factoid_key,locked_by', undef,
+               'WHERE locked_by IS NOT NULL'
+       );
        my @list = keys %hash;
 
        for (@list) {
@@ -428,7 +437,10 @@ sub CmdFactStats {
        return &formListReply(0, $prefix, @list);
 
     } elsif ($type =~ /^new$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key,created_time", "created_time IS NOT NULL");
+       my %hash = &sqlSelectColHash('factoids',
+               'factoid_key,created_time', undef,
+               'WHERE created_time IS NOT NULL'
+       );
        my %age;
 
        foreach (keys %hash) {
@@ -440,24 +452,24 @@ sub CmdFactStats {
        }
 
        if (scalar keys %age == 0) {
-           return "sorry, no new factoids.";
+           return 'sorry, no new factoids.';
        }
 
        my @list;
        foreach (sort {$a <=> $b} keys %age) {
-           push(@list, join(",", keys %{ $age{$_} }));
+           push(@list, join(',', keys %{ $age{$_} }));
        }
 
-       my $prefix = "new factoids in the last 24hours ";
+       my $prefix = 'new factoids in the last 24hours ';
        return &formListReply(0, $prefix, @list);
 
     } elsif ($type =~ /^part(ial)?dupe$/i) {
-       ### requires "custom" select statement... oh well...
+       ### requires 'custom' select statement... oh well...
        my $start_time  = &timeget();
 
        # form length|key and key=length hash list.
-       &status("factstats(partdupe): forming length hash list.");
-       my $query = "SELECT factoid_key,factoid_value,length(factoid_value) AS length FROM factoids WHERE length(factoid_value) >= 192 ORDER BY length";
+       &status('factstats(partdupe): forming length hash list.');
+       my $query = 'SELECT factoid_key,factoid_value,length(factoid_value) AS length FROM factoids WHERE length(factoid_value) >= 192 ORDER BY length';
        my $sth = $dbh->prepare($query);
        &ERROR("factstats(partdupe): => '$query'.") unless $sth->execute;
 
@@ -470,7 +482,7 @@ sub CmdFactStats {
        }
        $sth->finish;
        &status("factstats(partdupe): total keys => '". scalar(@key) ."'.");
-       &status("factstats(partdupe): now deciphering data gathered");
+       &status('factstats(partdupe): now deciphering data gathered');
 
        my @length = sort { $a <=> $b } keys %length;
        my $key;
@@ -486,53 +498,58 @@ sub CmdFactStats {
                    if ($key{$_} =~ /^$val/i) {
                        s/([\,\;]+)/\037$1\037/g;
                        s/( and|and )/\037$1\037/g;
-                       push(@sublist,$key." and ".$_);
+                       push(@sublist,$key.' and '.$_);
                    }
                }
            }
-           push(@list, join(" ,",@sublist)) if (scalar @sublist);
+           push(@list, join(' ,',@sublist)) if (scalar @sublist);
        }
 
-       my $delta_time = sprintf("%.02fs", &timedelta($start_time) );
-        &status("factstats(partdupe): $delta_time sec to complete.") if ($delta_time > 0);
+       my $delta_time = sprintf('%.02fs', &timedelta($start_time) );
+       &status("factstats(partdupe): $delta_time sec to complete.") if ($delta_time > 0);
 
        # bail out on no results.
        if (scalar @list == 0) {
-           return "no initial partial duplicate factoids... woohoo.";
+           return 'no initial partial duplicate factoids... woohoo.';
        }
 
        # parse the results.
-       my $prefix = "initial partial dupe factoid ";
+       my $prefix = 'initial partial dupe factoid ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^profanity$/i) {
-       my %data = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL");
+       my %data = &sqlSelectColHash('factoids',
+               'factoid_key,factoid_value', undef,
+               'WHERE factoid_value IS NOT NULL'
+       );
        my @list;
 
        foreach (keys %data) {
-           push(@list, $_) if (&hasProfanity($_." ".$data{$_}));
+           push(@list, $_) if (&hasProfanity($_.' '.$data{$_}));
        }
 
        # parse the results.
-       my $prefix = "Profanity in factoids ";
+       my $prefix = 'Profanity in factoids ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^redir(ection)?$/i) {
-       my @list = &searchTable("factoids", "factoid_key",
-                       "factoid_value", "^<REPLY> see ");
+       my @list = &searchTable('factoids', 'factoid_key',
+                       'factoid_value', '^<REPLY> see ');
        my %redir;
        my $f;
+       my $dangling = 0;
 
        for (@list) {
            my $factoid = $_;
-           my $val = &getFactInfo($factoid, "factoid_value");
+           my $val = &getFactInfo($factoid, 'factoid_value');
            if ($val =~ /^<REPLY> see( also)? (.*?)\.?$/i) {
                my $redir       = lc $2;
-               my $redirval    = &getFactInfo($redir, "factoid_value");
+               my $redirval    = &getFactInfo($redir, 'factoid_value');
                if (defined $redirval) {
                    $redir{$redir}{$factoid} = 1;
                } else {
-                   &WARN("factstats(redir): '$factoid' has loose link => '$redir'.");
+                   &DEBUG("factstats(redir): '$factoid' has loose link => '$redir'.");
+                   $dangling++;
                }
            }
        }
@@ -548,11 +565,14 @@ sub CmdFactStats {
        }
 
        # parse the results.
-       my $prefix = "Redirections in factoids ";
+       my $prefix = "Redirections in factoids, $dangling dangling ";
        return &formListReply(1, $prefix, @newlist);
 
     } elsif ($type =~ /^request(ed)?$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key,requested_count", "requested_count IS NOT NULL", 1);
+       my %hash = &sqlSelectColHash('factoids',
+               'factoid_key,requested_count', undef,
+               'WHERE requested_count IS NOT NULL', 1
+       );
 
        if (!scalar keys %hash) {
            return 'sorry, no factoids have been questioned.';
@@ -569,7 +589,7 @@ sub CmdFactStats {
            }
            $total      += $count * scalar(@faqtoids);
 
-           push(@list, "$count - ". join(", ", @faqtoids));
+           push(@list, "$count - ". join(', ', @faqtoids));
        }
        unshift(@list, "\037$total - TOTAL\037");
 
@@ -577,16 +597,17 @@ sub CmdFactStats {
        return &formListReply(0, $prefix, @list);
 
     } elsif ($type =~ /^reqrate$/i) {
-       my %hash = &dbGetCol("factoids",
-               "factoid_key,(unix_timestamp() - created_time)/requested_count as rate",
-               "requested_by IS NOT NULL and created_time IS NOT NULL ORDER BY rate LIMIT 15", 1);
+       my %hash = &sqlSelectColHash('factoids',
+               "factoid_key,(unix_timestamp() - created_time)/requested_count as rate", undef,
+               'WHERE requested_by IS NOT NULL and created_time IS NOT NULL ORDER BY rate LIMIT 15', 1
+       );
 
        my $rate;
        my @list;
        my $total       = 0;
        my $users       = 0;
        foreach $rate (sort { $b <=> $a } keys %hash) {
-           my $f       = join(", ", sort keys %{ $hash{$rate} });
+           my $f       = join(', ', sort keys %{ $hash{$rate} });
            my $str     = "$f - ".&Time2String($rate);
            $str        =~ s/\002//g;
            push(@list, $str);
@@ -596,7 +617,10 @@ sub CmdFactStats {
        return &formListReply(0, $prefix, @list);
 
     } elsif ($type =~ /^requesters?$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key,requested_by", "requested_by IS NOT NULL");
+       my %hash = &sqlSelectColHash('factoids',
+               'factoid_key,requested_by', undef,
+               'WHERE requested_by IS NOT NULL'
+       );
        my %requester;
 
        foreach (keys %hash) {
@@ -622,7 +646,7 @@ sub CmdFactStats {
        my $total       = 0;
        my $users       = 0;
        foreach $count (sort { $b <=> $a } keys %count) {
-           my $requester = join(", ", sort keys %{ $count{$count} });
+           my $requester = join(', ', sort keys %{ $count{$count} });
            $total      += $count * scalar(keys %{ $count{$count} });
            $users      += scalar(keys %{ $count{$count} });
            push(@list, "$count by $requester");
@@ -631,12 +655,12 @@ sub CmdFactStats {
        # should not the above value be the same as collected by
        # 'requested'? soemthing weird is going on!
 
-       my $prefix = "rank of top factoid requesters: ";
+       my $prefix = 'rank of top factoid requesters: ';
        return &formListReply(0, $prefix, @list);
 
     } elsif ($type =~ /^seefix$/i) {
-       my @list = &searchTable("factoids", "factoid_key",
-                       "factoid_value", "^see ");
+       my @list = &searchTable('factoids', 'factoid_key',
+                       'factoid_value', '^see ');
        my @newlist;
        my $fixed = 0;
        my %loop;
@@ -644,12 +668,12 @@ sub CmdFactStats {
 
        for (@list) {
            my $factoid = $_;
-           my $val = &getFactInfo($factoid, "factoid_value");
-       
+           my $val = &getFactInfo($factoid, 'factoid_value');
+
            next unless ($val =~ /^see( also)? (.*?)\.?$/i);
 
            my $redirf  = lc $2;
-           my $redir   = &getFactInfo($redirf, "factoid_value");
+           my $redir   = &getFactInfo($redirf, 'factoid_value');
 
            if ($redirf =~ /^\Q$factoid\W$/i) {
                &delFactoid($factoid);
@@ -657,7 +681,7 @@ sub CmdFactStats {
            }
 
            if (defined $redir) {       # good.
-               &setFactInfo($factoid,"factoid_value","<REPLY> see $redir");
+               &setFactInfo($factoid,'factoid_value',"<REPLY> see $redir");
                $fixed++;
            } else {
                push(@newlist, $redirf);
@@ -666,8 +690,7 @@ sub CmdFactStats {
 
        # parse the results.
        &msg($who, "Fixed $fixed factoids.");
-       &msg($who, "Self looped factoids removed: ".
-               sort(keys %loop) ) if (scalar keys %loop);
+       &msg($who, 'Self looped factoids removed: '. keys %loop ) if (scalar keys %loop);
 
        my $prefix = "Loose link (dead) redirections in factoids ";
        return &formListReply(1, $prefix, @newlist);
@@ -695,22 +718,18 @@ sub CmdFactStats {
        $sth->finish;
 
        if (scalar @list == 0) {
-           return "good. no factoids exceed length.";
+           return 'good. no factoids exceed length.';
        }
 
        # parse the results.
-       my $prefix = "factoid key||value exceeding length ";
+       my $prefix = 'factoid key||value exceeding length ';
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^unrequest(ed)?$/i) {
-       my @list = &dbRawReturn("SELECT factoid_key FROM factoids WHERE requested_count IS NULL");
-
-       for (@list) {
-           s/([\,\;]+)/\037$1\037/g;
-       }
+       # TODO: use sqlSelect()
+       my ($count) = &sqlRawReturn("SELECT COUNT(*) FROM factoids WHERE requested_count = '0'");
 
-       my $prefix = "Unrequested factoids ";
-       return &formListReply(0, $prefix, @list);
+       return "Unrequested factoids: $count";
     }
 
     return "error: invalid type => '$type'.";
@@ -718,7 +737,9 @@ sub CmdFactStats {
 
 sub CmdListAuth {
     my ($query) = @_;
-    my @list = &searchTable("factoids","factoid_key", "created_by", "^$query!");
+    my $maxshow = &::getChanConfDefault('maxListReplyCount', 15, $chan);
+    my @list = &searchTable('factoids','factoid_key', 'created_by', "^$query!");
+    @list=grep(!/\#DEL\#$/,@list) if (scalar(@list) > $maxshow);
 
     my $prefix = "factoid author list by '$query' ";
     &performStrictReply( &formListReply(1, $prefix, @list) );