- if ($type =~ /^author$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key,created_by", "created_by IS NOT NULL");
- my %author;
-
- foreach (keys %hash) {
- my $thisnuh = $hash{$_};
-
- $thisnuh =~ /^(\S+)!\S+@\S+$/;
- $author{lc $1}++;
- }
-
- if (!scalar keys %author) {
- return 'sorry, no factoids with created_by field.';
- }
-
- # work-around.
- my %count;
- foreach (keys %author) {
- $count{ $author{$_} }{$_} = 1;
- }
- undef %author;
-
- my $count;
- my @list;
- foreach $count (sort { $b <=> $a } keys %count) {
- my $author = join(", ", sort keys %{ $count{$count} });
- push(@list, "$count by $author");
- }
-
- my $prefix = "factoid statistics by author: ";
- return &formListReply(0, $prefix, @list);
-
- } elsif ($type =~ /^vandalism$/i) {
- &status("factstats(vandalism): starting...");
- my $start_time = &timeget();
- my %data = &dbGetCol("factoids", "factoid_key,factoid_value", "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);
- $start_time = &timeget();
-
- # parse the factoids.
- foreach (keys %data) {
- if (&validFactoid($_, $data{$_}) == 0) {
- s/([\,\;]+)/\037$1\037/g; # highlight chars.
- push(@list, $_); # push it.
- }
- }
-
- $delta_time = &timedelta($start_time);
- &status(sprintf("factstats(vandalism): %.02f sec to complete.", $delta_time)) if ($delta_time > 0);
-
- # bail out on no results.
- if (scalar @list == 0) {
- return 'no vandalised factoids... wooohoo.';
- }
-
- # parse the results.
- my $prefix = "Vandalised factoid ";
- return &formListReply(1, $prefix, @list);
-
- } elsif ($type =~ /^total$/i) {
- &status("factstats(total): starting...");
- my $start_time = &timeget();
- my @list;
- my $str;
- my($i,$j);
- my %hash;
-
- ### lets do it.
- # total factoids requests.
- $i = &sumKey("factoids", "requested_count");
- push(@list, "total requests - $i");
-
- # total factoids modified.
- $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));
-
- # average request/factoid.
- # i/j == total(requested_count)/count(requested_count)
- $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") );
- push(@list, "total prepared for deletion - $str");
-
- # total unique authors.
- foreach ( &dbRawReturn("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) );
- undef %hash;
-
- # total unique requesters.
- foreach ( &dbRawReturn("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) );
- undef %hash;
-
- ### 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);
- $start_time = &timeget();
-
- # bail out on no results.
- if (scalar @list == 0) {
- return 'no broken factoids... wooohoo.';
- }
-
- # parse the results.
- my $prefix = "General factoid stiatistics ";
- return &formListReply(1, $prefix, @list);
-
- } elsif ($type =~ /^deadredir$/i) {
- my @list = &searchTable("factoids", "factoid_key",
- "factoid_value", "^<REPLY> see ");
- my %redir;
- my $f;
-
- for (@list) {
- my $factoid = $_;
- my $val = &getFactInfo($factoid, "factoid_value");
- if ($val =~ /^<REPLY> ?see( also)? (.*?)\.?$/i) {
- my $redirf = lc $2;
- my $redir = &getFactInfo($redirf, "factoid_value");
- next if (defined $redir);
- next if (length $val > 50);
-
- $redir{$redirf}{$factoid} = 1;
- }
- }
-
- my @newlist;
- foreach $f (keys %redir) {
- my @sublist = keys %{ $redir{$f} };
- for (@sublist) {
- s/([\,\;]+)/\037$1\037/g;
- }
+ if ( $type =~ /^author$/i ) {
+ my %hash = &sqlSelectColHash(
+ 'factoids', 'factoid_key,created_by',
+ undef, 'WHERE created_by IS NOT NULL'
+ );
+ my %author;
+
+ foreach my $factoid ( keys %hash ) {
+ my $thisnuh = $hash{$factoid};
+
+ $thisnuh =~ /^(\S+)!\S+@\S+$/;
+ $author{ lc $1 }++;
+ }
+
+ if ( !scalar keys %author ) {
+ return 'sorry, no factoids with created_by field.';
+ }
+
+ # work-around.
+ my %count;
+ foreach ( keys %author ) {
+ $count{ $author{$_} }{$_} = 1;
+ }
+ undef %author;
+
+ my $count;
+ my @list;
+ foreach $count ( sort { $b <=> $a } keys %count ) {
+ my $author = join( ', ', sort keys %{ $count{$count} } );
+ push( @list, "$count by $author" );
+ }
+
+ my $prefix = 'factoid statistics by author: ';
+ return &formListReply( 0, $prefix, @list );