]> git.donarmstrong.com Git - infobot.git/blobdiff - src/UserExtra.pl
dbm -> sql
[infobot.git] / src / UserExtra.pl
index 105c22ef99f64df04e41961e6d6b1976b723f29e..e39fa2a740ad8a7650b9556122fdec1a53ebd812 100644 (file)
@@ -5,9 +5,11 @@
 #      Created: 20000107
 #
 
-#use strict;
-use vars qw($message $arg $qWord $verb $lobotomized);
-use vars qw(%channels %chanstats %cmdstats);
+use strict;
+use vars qw($message $arg $qWord $verb $lobotomized $who $result $chan
+       $conn $msgType $query $talkchannel $ident $memusage);
+use vars qw(%channels %chanstats %cmdstats %count %ircstats %param
+       %cache %mask %userstats %hooks_main);
 
 ###
 ### Start of command hooks for UserExtra.
@@ -18,7 +20,7 @@ use vars qw(%channels %chanstats %cmdstats);
 &addCmdHook("main", 'factinfo', ('CODEREF' => 'factinfo', 
        'Cmdstats' => 'Factoid Info', Module => 'factoids', ) );
 &addCmdHook("main", 'factstats?', ('CODEREF' => 'factstats', 
-       'Cmdstats' => 'Factoid Statistics', Help => "factstats", 
+       'Cmdstats' => 'Factoid Stats', Help => "factstats", 
        Forker => 1, 'Identifier' => 'factoids', ) );
 &addCmdHook("main", 'help', ('CODEREF' => 'help', 
        'Cmdstats' => 'Help', ) );
@@ -219,8 +221,8 @@ sub factstats {
 
 sub karma {
     my $target = lc( shift || $who );
-    my $karma  = &dbGet("stats", "counter", "nick=".
-                       &dbQuote($target)." AND type='karma'") || 0; 
+    my $karma  = &sqlSelect("stats", "counter",
+       { nick => $target, type => "karma" }) || 0; 
 
     if ($karma != 0) {
        &pSReply("$target has karma of $karma");
@@ -347,7 +349,7 @@ sub tell {
     $who               = $oldwho;
 
     # no such factoid.
-    if ($result =~ /^0?$/) {
+    if (!defined $result || $result =~ /^0?$/) {
        $who            = $target;
        $msgType        = "private";
 
@@ -443,7 +445,7 @@ sub countryStats {
        return;
     }
 
-    &rawout("WHO $chan");
+    $conn->who($chan);
     $cache{countryStats}{chan} = $chan;
     $cache{countryStats}{mtype}        = $msgType;
     $cache{countryStats}{who}  = $who;
@@ -611,6 +613,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"));
@@ -777,9 +790,9 @@ sub userCommands {
 
     # status.
     if ($message =~ /^statu?s$/i) {
-       my $startString = scalar(localtime $^T);
+       my $startString = scalar(gmtime $^T);
        my $upString    = &Time2String(time() - $^T);
-       my $count       = &countKeys("factoids");
+       my $factoids    = &countKeys("factoids");
 
        $count{'Commands'}      = 0;
        foreach (keys %cmdstats) {
@@ -799,16 +812,19 @@ sub userCommands {
          " and \002$count{'Commands'}\002 ".
                &fixPlural("command",$count{'Commands'}).
          ".  I have been awake for $upString this session, and ".
-         "currently reference \002$count\002 factoids.  ".
+         "currently reference \002$factoids\002 factoids.  ".
          "I'm using about \002$memusage\002 ".
          "kB of memory."
        );
 
-       # todo: make dbGetColNiceHash().
-       my %hash = &dbGetCol("stats", "nick,counter", "type='cmdstats'".
-#                      " ORDER BY counter DESC LIMIT 3", 1);
-                       " ORDER BY counter DESC", 1);
+       return;
+
+       my %hash = &sqlSelectColHash("stats", "nick,counter",
+               { type => "cmdstats" }, 1);
+# ORDER won't be retained in a hash
+#                      " ORDER BY counter DESC", 1);
 
+if (0) {
        foreach (keys %hash) {
            my $i = $_;
            foreach (keys %{ $hash{$i} }) {
@@ -816,6 +832,7 @@ sub userCommands {
            }
        }
        &DEBUG("end of cmdstats.");
+}
 
        return;
     }