]> git.donarmstrong.com Git - infobot.git/blobdiff - src/UserExtra.pl
- fixed "news #debian latest" - how did I break it?
[infobot.git] / src / UserExtra.pl
index 184a3f03a53adb39c213fbdebe81d682f7c84b2d..067370bf861739b88093dee1d38a6f0753ed61a5 100644 (file)
@@ -152,10 +152,15 @@ sub chaninfo {
     my %new;
     foreach (keys %userstats) {
        next unless (exists $userstats{$_}{'Count'});
+       if ($userstats{$_}{'Count'} =~ /^\D+$/) {
+           &WARN("userstats{$_}{Count} is non-digit.");
+           next;
+       }
+
        $new{$_} = $userstats{$_}{'Count'};
     }
 
-    my($count) = (sort { $b <=> $a } keys %new)[0];
+    my($count) = (sort { $a <=> $b } keys %new)[0];
     if ($count) {
        $reply .= ".  \002$count\002 has said the most with a total of \002$new{$count}\002 messages";
     }
@@ -214,7 +219,7 @@ sub factstats {
 
 sub karma {
     my $target = lc( shift || $who );
-    my $karma  = &dbGet("karma", "nick",$target,"karma") || 0;
+    my $karma  = &dbGet("stats", "counter", "nick='$target' and type='karma'") || 0;
 
     if ($karma != 0) {
        &pSReply("$target has karma of $karma");
@@ -319,12 +324,10 @@ sub tell {
     &status("tell: target = $target, query = $query");  
 
     # "intrusive".
-    if ($target !~ /^$mask{chan}$/ and !&IsNickInAnyChan($target)) {
-       &msg($who, "No, $target is not in any of my chans.");
-       return;
-    }
-
-    ### TODO: don't "tell" if sender is not in target's channel.
+#    if ($target !~ /^$mask{chan}$/ and !&IsNickInAnyChan($target)) {
+#      &msg($who, "No, $target is not in any of my chans.");
+#      return;
+#    }
 
     # self.
     if ($target eq $ident) {   # lc?
@@ -352,7 +355,7 @@ sub tell {
        $message        = $tell_obj;
        $done++ unless (&Modules());
 
-       &DEBUG("setting old values of who and msgType.");
+       &VERB("tell: setting old values of who and msgType.",2);
        $who            = $oldwho;
        $msgType        = $oldmtype;
 
@@ -386,10 +389,12 @@ sub DNS {
     my $dns = shift;
     my($match, $x, $y, $result);
     my $pid;
+    $dns =~ s/^\s+|\s+$//g;
 
     if ($dns =~ /(\d+\.\d+\.\d+\.\d+)/) {
        &status("DNS query by IP address: $in");
        $match = $1;
+
        $y = pack('C4', split(/\./, $match));
        $x = (gethostbyaddr($y, &AF_INET));
 
@@ -398,12 +403,14 @@ sub DNS {
        } else {
            $result = "I can't seem to find that address in DNS";
         }
+
     } else {
-       &status("DNS query by name: $in");
-       $x = join('.',unpack('C4',(gethostbyname($in))[4]));
+
+       &status("DNS query by name: $dns");
+       $x = join('.',unpack('C4',(gethostbyname($dns))[4]));
 
        if ($x !~ /^\s*$/) {
-           $result = $in." is ".$x;
+           $result = $dns." is ".$x;
        } else {
            $result = "I can\'t find that machine name";
        }
@@ -678,21 +685,26 @@ sub userCommands {
 
        # utime(13) + stime(14).
        my $cpu_usage   = sprintf("%.01f", ($data[13]+$data[14]) / 100 );
+       # cutime(15) + cstime (16).
+       my $cpu_usage2  = sprintf("%.01f", ($data[15]+$data[16]) / 100 );
        my $time        = time() - $^T;
        my $raw_perc    = $cpu_usage*100/$time;
+       my $raw_perc2   = $cpu_usage2*100/$time;
        my $perc;
+       my $perc2;
 
        if ($raw_perc > 1) {
            $perc       = sprintf("%.01f", $raw_perc);
+           $perc2      = sprintf("%.01f", $raw_perc2);
        } elsif ($raw_perc > 0.1) {
            $perc       = sprintf("%.02f", $raw_perc);
+           $perc2      = sprintf("%.02f", $raw_perc2);
        } else {                        # <=0.1
            $perc       = sprintf("%.03f", $raw_perc);
+           $perc2      = sprintf("%.03f", $raw_perc2);
        }
 
-       &pSReply("Total CPU usage: $cpu_usage s ... Percentage CPU used: $perc %");
-       &DEBUG("15 => $data[15] (cutime)");
-       &DEBUG("16 => $data[16] (cstime)");
+       &pSReply("Total CPU usage: $cpu_usage s ... Percentage CPU used: $perc % (+childs: $perc2 %)");
 
        return;
     }
@@ -750,6 +762,10 @@ sub userCommands {
        my $startString = scalar(localtime $^T);
        my $upString    = &Time2String(time() - $^T);
        my $count       = &countKeys("factoids");
+       $count{'Commands'}      = 0;
+       foreach (keys %cmdstats) {
+           $count{'Commands'} += $cmdstats{$_};
+       }
 
        &pSReply(
        "Since $startString, there have been".
@@ -761,6 +777,8 @@ sub userCommands {
                &fixPlural("dunno",$count{'Dunno'}).
          " and \002$count{'Moron'}\002 ".
                &fixPlural("moron",$count{'Moron'}).
+         " and \002$count{'Commands'}\002 ".
+               &fixPlural("command",$count{'Commands'}).
          ".  I have been awake for $upString this session, and ".
          "currently reference \002$count\002 factoids.  ".
          "I'm using about \002$memusage\002 ".