]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Factoids.pl
- forgot to set forked{}{PID} in addForked
[infobot.git] / src / Modules / Factoids.pl
index 2c8e9c7418aab1d762c1deefcc219bba6ccb2971..b2e36461bf329ca395293f74bdd649f02f04961f 100644 (file)
@@ -16,7 +16,7 @@ sub CmdFactInfo {
 
     if ($faqtoid eq "") {
        &help("factinfo");
-       return $noreply;
+       return;
     }
 
     my $i = 0;
@@ -30,7 +30,7 @@ sub CmdFactInfo {
     # factoid does not exist.
     if (scalar @factinfo <= 1) {
        &performReply("there's no such factoid as \002$faqtoid\002");
-       return $noreply;
+       return;
     }
 
     # fix for problem observed by asuffield.
@@ -41,7 +41,7 @@ sub CmdFactInfo {
            &DEBUG("factinfo{$_} => '$factinfo{$_}'.");
        }
 ###    &delFactoid($faqtoid);
-       return $noreply;
+       return;
     }
 
     # created:
@@ -54,9 +54,9 @@ sub CmdFactInfo {
        my $time = $factinfo{'created_time'};
        if ($time) {
            if (time() - $time > 60*60*24*7) {
-               my $days = int( (time() - $time)*60*60*24 );
+               my $days = int( (time() - $time)/60/60/24 );
                $string .= " at \037". scalar(localtime $time). "\037" .
-                               " ($days days) ";
+                               " ($days days)";
            } else {
                $string .= " ".&Time2String(time() - $time)." ago";
            }
@@ -132,11 +132,11 @@ sub CmdFactInfo {
     # factoid was inserted not through the bot.
     if (!scalar @array) {
        &performReply("no extra info on \002$faqtoid\002");
-       return $noreply;
+       return;
     }
 
     &performStrictReply("$factinfo{'factoid_key'} -- ". join("; ", @array) .".");
-    return $noreply;
+    return;
 }
 
 sub CmdFactStats {
@@ -167,7 +167,7 @@ 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");
        }
 
@@ -225,7 +225,7 @@ sub CmdFactStats {
 
        my @newlist;
        foreach $f (keys %redir) {
-           my @sublist = keys %{$redir{$f}};
+           my @sublist = keys %{ $redir{$f} };
            for (@sublist) {
                s/([\,\;]+)/\037$1\037/g;
            }
@@ -246,11 +246,11 @@ sub CmdFactStats {
        my $v;
 
        foreach $v (keys %hash) {
-           my $count = scalar(keys %{$hash{$v}});
+           my $count = scalar(keys %{ $hash{$v} });
            next if ($count == 1);
 
            my @sublist;
-           foreach (keys %{$hash{$v}}) {
+           foreach (keys %{ $hash{$v} }) {
                if ($v =~ /^<REPLY> see /i) {
                    $refs++;
                    next;
@@ -316,6 +316,11 @@ sub CmdFactStats {
            $match++ if ($val =~ /\s{3,}/);
            next unless ($match);
 
+           my $v = &getFactoid($val);
+           if (defined $v) {
+               &DEBUG("key $key => $val => $v");
+           }
+
            $key =~ s/\,/\037\,\037/g;
            push(@list, $key);
        }
@@ -379,7 +384,7 @@ sub CmdFactStats {
 
        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 ";
@@ -416,7 +421,7 @@ sub CmdFactStats {
            my @sublist;
            my $length;
            foreach $length (@length) {
-               foreach (keys %{$length{$length}}) {
+               foreach (keys %{ $length{$length} }) {
                    if ($key{$_} =~ /^$val/i) {
                        s/([\,\;]+)/\037$1\037/g;
                        s/( and|and )/\037$1\037/g;
@@ -473,7 +478,7 @@ sub CmdFactStats {
 
        my @newlist;
        foreach $f (keys %redir) {
-           my @sublist = keys %{$redir{$f}};
+           my @sublist = keys %{ $redir{$f} };
            for (@sublist) {
                s/([\,\;]+)/\037$1\037/g;
            }
@@ -494,15 +499,18 @@ sub CmdFactStats {
 
        my $count;
        my @list;
+       my $total       = 0;
        foreach $count (sort {$b <=> $a} keys %hash) {
-           my @faqtoids = sort keys %{$hash{$count}};
+           my @faqtoids = sort keys %{ $hash{$count} };
 
            for (@faqtoids) {
                s/([\,\;]+)/\037$1\037/g;
            }
+           $total      += $count * scalar(@faqtoids);
 
            push(@list, "$count - ". join(", ", @faqtoids));
        }
+       unshift(@list, "\037$total - TOTAL\037");
 
        my $prefix = "factoid statistics on $type ";
        return &formListReply(0, $prefix, @list);
@@ -525,16 +533,23 @@ sub CmdFactStats {
        # work-around.
        my %count;
        foreach (keys %requester) {
-           $count{$requester{$_}}{$_} = 1;
+           $count{ $requester{$_} }{$_} = 1;
        }
        undef %requester;
 
        my $count;
        my @list;
+       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");
        }
+       unshift(@list, "\037$total TOTAL REQUESTS; $users UNIQUE REQUESTERS\037");
+       # should not the above value be the same as collected by
+       # 'requested'? soemthing weird is going on!
 
        my $prefix = "rank of top factoid requesters: ";
        return &formListReply(0, $prefix, @list);
@@ -550,21 +565,22 @@ sub CmdFactStats {
        for (@list) {
            my $factoid = $_;
            my $val = &getFactInfo($factoid, "factoid_value");
-           if ($val =~ /^see( also)? (.*?)\.?$/i) {
-               my $redirf = lc $2;
-               my $redir = &getFactInfo($redirf, "factoid_value");
+       
+           next unless ($val =~ /^see( also)? (.*?)\.?$/i);
 
-               if ($redirf =~ /^\Q$factoid\W$/i) {
-                   &delFactoid($factoid);
-                   $loop{$factoid} = 1;
-               }
+           my $redirf  = lc $2;
+           my $redir   = &getFactInfo($redirf, "factoid_value");
 
-               if (defined $redir) {   # good.
-                   &setFactInfo($factoid,"factoid_value","<REPLY> see $redir");
-                   $fixed++;
-               } else {
-                   push(@newlist, $redirf);
-               }
+           if ($redirf =~ /^\Q$factoid\W$/i) {
+               &delFactoid($factoid);
+               $loop{$factoid} = 1;
+           }
+
+           if (defined $redir) {       # good.
+               &setFactInfo($factoid,"factoid_value","<REPLY> see $redir");
+               $fixed++;
+           } else {
+               push(@newlist, $redirf);
            }
        }