]> git.donarmstrong.com Git - infobot.git/blobdiff - src/UserExtra.pl
- added support/hack for channel +o as "+o" in bot user file.
[infobot.git] / src / UserExtra.pl
index 7079f6a7b96b4b13d7b6676d8b1e3756090d66c8..2e2dc643fa8ffd1229e9a4e0aee1e23e89fdb99b 100644 (file)
@@ -5,8 +5,7 @@
 #      Created: 20000107
 #
 
-if (&IsParam("useStrict")) { use strict; }
-
+#use strict;
 use vars qw($message $arg $qWord $verb $lobotomized);
 use vars qw(%channels %chanstats %cmdstats);
 
@@ -160,7 +159,8 @@ sub chaninfo {
        $new{$_} = $userstats{$_}{'Count'};
     }
 
-    my($count) = (sort { $a <=> $b } keys %new)[0];
+    # todo: show top 3 with percentages?
+    my($count) = (sort { $new{$a} <=> $new{$b} } keys %new)[0];
     if ($count) {
        $reply .= ".  \002$count\002 has said the most with a total of \002$new{$count}\002 messages";
     }
@@ -232,7 +232,7 @@ sub karma {
 sub ispell {
     my $query = shift;
 
-    if (! -x "/usr/bin/spell") {
+    if (! -x "/usr/bin/ispell") {
        &msg($who, "no binary found.");
        return;
     }
@@ -262,6 +262,9 @@ sub ispell {
        } elsif (/^\+/) {
            &DEBUG("spell: '+' found => '$_'.");
            last;
+       } elsif (/^# (.*?) 0$/) {
+           # none found.
+           last;
        } else {
            &DEBUG("spell: unknown: '$_'.");
        }
@@ -392,6 +395,11 @@ sub DNS {
     my $pid;
     $dns =~ s/^\s+|\s+$//g;
 
+    if (!defined $dns or $dns =~ /^\s*$/ or $dns =~ / /) {
+       &help("dns");
+       return;
+    }
+
     if ($dns =~ /(\d+\.\d+\.\d+\.\d+)/) {
        $match = $1;
        &status("DNS query by IP address: $match");
@@ -435,7 +443,7 @@ sub countryStats {
        return;
     }
 
-    &rawout("WHO $chan");
+    $conn->who($chan);
     $cache{countryStats}{chan} = $chan;
     $cache{countryStats}{mtype}        = $msgType;
     $cache{countryStats}{who}  = $who;
@@ -603,6 +611,17 @@ sub userCommands {
        return;
     }
 
+    # reload.
+    if ($message =~ /^reload$/i) {
+       return unless (&hasFlag("n"));
+
+       &status("USER reload $who");
+       &pSReply("reloading...");
+       &reloadAllModules();
+       &pSReply("reloaded.");
+       return;
+    }
+
     # redir.
     if ($message =~ /^redir(\s+(.*))?/i) {
        return unless (&hasFlag("o"));
@@ -693,19 +712,28 @@ sub userCommands {
        my $raw_perc2   = $cpu_usage2*100/$time;
        my $perc;
        my $perc2;
+       my $total;
+       my $ratio;
 
        if ($raw_perc > 1) {
            $perc       = sprintf("%.01f", $raw_perc);
            $perc2      = sprintf("%.01f", $raw_perc2);
+           $total      = sprintf("%.01f", $raw_perc+$raw_perc2);
        } elsif ($raw_perc > 0.1) {
            $perc       = sprintf("%.02f", $raw_perc);
            $perc2      = sprintf("%.02f", $raw_perc2);
+           $total      = sprintf("%.02f", $raw_perc+$raw_perc2);
        } else {                        # <=0.1
            $perc       = sprintf("%.03f", $raw_perc);
            $perc2      = sprintf("%.03f", $raw_perc2);
+           $total      = sprintf("%.03f", $raw_perc+$raw_perc2);
        }
+       $ratio  = sprintf("%.01f", 100*$perc/($perc+$perc2) );
 
-       &pSReply("Total CPU usage: $cpu_usage s ... Percentage CPU used: $perc % (+childs: $perc2 %)");
+       &pSReply("Total CPU usage: \002$cpu_usage\002 s ... ".
+               "Total used: \002$total\002 % ".
+               "(parent/child ratio: $ratio %)"
+       );
 
        return;
     }
@@ -793,7 +821,10 @@ sub userCommands {
                        " ORDER BY counter DESC", 1);
 
        foreach (keys %hash) {
-           &DEBUG("cmdstats: hash{$_} => $hash{$_}");
+           my $i = $_;
+           foreach (keys %{ $hash{$i} }) {
+               &DEBUG("cmdstats: $hash{$i}{$_} = $_");
+           }
        }
        &DEBUG("end of cmdstats.");
 
@@ -805,6 +836,8 @@ sub userCommands {
        if ($param{'ircNick'} eq $ident) {
            &msg($who, "I hope you're right. I'll try anyway.");
        }
+       &DEBUG("ircNick => $param{'ircNick'}");
+       &DEBUG("ident => $ident");
 
        if (! &IsNickInAnyChan( $param{ircNick} ) ) {
            my $str = "attempting to change nick to $param{'ircNick'}";
@@ -812,8 +845,9 @@ sub userCommands {
            &msg($who, $str);
            &nick($param{'ircNick'});
        } else {
-           &msg($who, "hrm... can't do it");
+           &msg($who, "hrm.. I shouldn't do it (BUG?) but doing it anyway!");
            &DEBUG("wN: nick is somewhere... should try later.");
+           &nick($param{'ircNick'});
        }
 
        return;