]> git.donarmstrong.com Git - infobot.git/blobdiff - src/CommandStubs.pl
- added support of ircTextCounters - works! thanks to #perl@OPN.
[infobot.git] / src / CommandStubs.pl
index 7b2ca5d37f198d9c6a29668a16000596ce0bb5b4..1a583dd4399af473c8f20b2ea17b6d44cf9a557b 100644 (file)
@@ -267,28 +267,66 @@ sub Modules {
        return;
     }
 
+    # text counters.
+    if ($_ = &getChanConf("ircTextCounters")) {
+       s/([^\w\s])/\\$1/g;
+       my $z = join '|', split ' ';
+
+       if ($message =~ /^($z)stats(\s+(\S+))?$/i) {
+           my $type    = $1;
+           my $arg     = $3;
+
+           if (!defined $arg or $arg =~ /^\s*$/) {
+               my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".&dbQuote($type) ))[0];
+
+               if (defined $x) {
+                   &pSReply("total count of '$type': $x");
+               } else {
+                   &pSReply("zero counter for '$type'.");
+               }
+           } else {
+               my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".
+                       &dbQuote($type)." AND nick=".&dbQuote($arg) ))[0];
+
+               if (defined $x) {       # defined.
+                   &pSReply("$arg has said $type $x times");
+               } else {                # !defined.
+                   &pSReply("$arg has not said $type yet.");
+               }
+           }
+
+           return;
+       }
+
+       if ($@) {
+           &DEBUG("regex failed: $@");
+           return;
+       }
+    }
+
     # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
     if ($message =~ /^list(\S+)( (.*))?$/i) {
        return unless (&hasParam("search"));
 
        my $thiscmd     = lc($1);
-       my $args        = $3;
-       $args           =~ s/\s+$//g;
-       # suggested by asuffield nad \broken.
-       if ($args =~ /^["']/ and $args =~ /["']$/) {
-           &DEBUG("list*: removed quotes.");
-           $args       =~ s/^["']|["']$//g;
-       }
-
-       $thiscmd =~ s/^vals$/values/;
+       $thiscmd        =~ s/^vals$/values/;
        return if ($thiscmd ne "keys" && $thiscmd ne "values");
 
+       my $args        = $3 || "";
+       $args           =~ s/\s+$//g;
+
        # Usage:
-       if (!defined $args) {
+       if (!defined $args or $args =~ /^\s*$/) {
            &help("list". $thiscmd);
            return;
        }
 
+       # suggested by asuffield and \broken.
+       if ($args =~ /^["']/ and $args =~ /["']$/) {
+           &DEBUG("list*: removed quotes.");
+           $args       =~ s/^["']|["']$//g;
+       }
+
        if (length $args == 1) {
            &msg($who,"search string is too short.");
            return;
@@ -484,7 +522,7 @@ sub seen {
     if ($person eq "random") {
        @seen = &randKey("seen", $select);
     } else {
-       @seen = &dbGet("seen", "nick", $person, $select);
+       @seen = &dbGet("seen", $select, "nick='$person'");
     }
 
     if (scalar @seen < 2) {