]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/botmail.pl
agreed
[infobot.git] / src / Modules / botmail.pl
index aee241990c1036d7c921e6fd2bb3dd155b7726d0..c0ecab5e49e1b960bc6b9e60684ec45e0c168d53 100644 (file)
@@ -14,6 +14,11 @@ use strict;
 sub parse {
     my($what) = @_;
 
+    if ($::param{'DBType'} =~ /^dbm/i) {
+       # FIXME multi field indexed tables not supported under dbm
+       &::msg($::who, "botmail disabled for $::param{'DBType'}");
+       return;
+    }  
     if (!defined $what or $what =~ /^\s*$/) {
        &::help("botmail");
        return;
@@ -22,8 +27,11 @@ sub parse {
     if ($what =~ /^(for|add)\s+(.*)$/i) {
        &add( split(/\s+/, $2, 2) );
 
-    } elsif ($what =~ /^check(\s+(.*))?$/i) {
-       &check( split(/\s+/, $1, 2) );
+    } elsif ($what =~ /^stats?$/i) {
+       &stats();
+
+    } elsif ($what =~ /^check?$/i) {
+       &check( $1, 1);
 
     } elsif ($what =~ /^(read|next)$/i) {
        # TODO: read specific items? nah, will make this too complex.
@@ -32,23 +40,27 @@ sub parse {
     }
 }
 
+sub stats {
+    my $botmail        = &::countKeys("botmail");
+    &::msg($::who, "I have \002$botmail\002 ". &::fixPlural("message", $botmail). ".");
+}
+
 #####
-# Usage: botmail::check($recipient)
+# Usage: botmail::check($recipient, [$always])
 sub check {
-    my($recipient) = @_;
+    my($recipient, $always) = @_;
     $recipient ||= $::who;
 
     # todo: simplify this select (use a diff function)
-    my @from = &::dbGet("botmail", "srcwho",
-       "dstwho=".&::dbQuote(lc $recipient)
-    );
-    my $t      = scalar @from;
-    my $from   = join(", ", @from);
+    my %from = &::dbGetCol("botmail", "srcwho",
+       "dstwho=".&::dbQuote(lc $recipient),2);
+    my $t      = keys %from;
+    my $from   = join(", ", keys %from);
 
     if ($t == 0) {
-       &::msg($recipient, "You have no botmail.");
+       &::msg($recipient, "You have no botmail.") if ($always);
     } else {
-       &::msg($recipient, "You have $t messages awaiting, from: $from");
+       &::msg($recipient, "You have $t messages awaiting, from: $from (botmail read)");
     }
 }
 
@@ -67,7 +79,7 @@ sub next {
        my $ago = &::Time2String(time() - $hash{'time'});
        &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $hash{time} [$ago]:");
        &::msg($recipient, $hash{'msg'});
-       #&::dbDel("botmail", "id", $hash{id});
+       &::dbDel("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}});
     }
 }
 
@@ -89,7 +101,7 @@ sub add {
        "dstwho=".&::dbQuote(lc $recipient)
     );
 
-    if (scalar (keys %hash) <= 1) {
+    if (scalar (keys %hash) > 1) {
        &::msg($::who, "$recipient already has a message queued from you");
        return;
     }