]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/botmail.pl
* Merged r1666:1760 from src-cleanup branch
[infobot.git] / src / Modules / botmail.pl
index 587cc55f47f6c1c097d6ae9da43e4849f022d5ef..778252f8e0cdc397cc6baa15fdeefb419c132292 100644 (file)
@@ -12,104 +12,122 @@ package botmail;
 use strict;
 
 sub parse {
-    my($what) = @_;
+    my ($what) = @_;
 
-    if (!defined $what or $what =~ /^\s*$/) {
-       &::help('botmail');
-       return;
+    if ( !defined $what or $what =~ /^\s*$/ ) {
+        &::help('botmail');
+        return;
     }
 
-    if ($what =~ /^(to|for|add)\s+(.*)$/i) {
-       &add( split(/\s+/, $2, 2) );
+    if ( $what =~ /^(to|for|add)\s+(.*)$/i ) {
+        &add( split( /\s+/, $2, 2 ) );
 
-    } elsif ($what =~ /^stats?$/i) {
-       &stats();
+    }
+    elsif ( $what =~ /^stats?$/i ) {
+        &stats();
 
-    } elsif ($what =~ /^check?$/i) {
-       &check( $1, 1);
+    }
+    elsif ( $what =~ /^check?$/i ) {
+        &check( $1, 1 );
 
-    } elsif ($what =~ /^(read|next)$/i) {
-       # TODO: read specific items? nah, will make this too complex.
-       &next($::who);
+    }
+    elsif ( $what =~ /^(read|next)$/i ) {
+
+        # TODO: read specific items? nah, will make this too complex.
+        &next($::who);
 
     }
 }
 
 sub stats {
-    my $botmail        = &::countKeys('botmail');
-    &::msg($::who, "I have \002$botmail\002 ". &::fixPlural('message', $botmail). ".");
+    my $botmail = &::countKeys('botmail');
+    &::msg( $::who,
+            "I have \002$botmail\002 "
+          . &::fixPlural( 'message', $botmail )
+          . "." );
 }
 
 #####
 # Usage: botmail::check($recipient, [$always])
 sub check {
-    my($recipient, $always) = @_;
+    my ( $recipient, $always ) = @_;
     $recipient ||= $::who;
 
-    my %from = &::sqlSelectColHash('botmail', "srcwho,time", {
-       dstwho => lc $recipient
-    } );
-    my $t      = keys %from;
-    my $from   = join(", ", keys %from);
+    my %from =
+      &::sqlSelectColHash( 'botmail', "srcwho,time",
+        { dstwho => lc $recipient } );
+    my $t = keys %from;
+    my $from = join( ", ", keys %from );
 
-    if ($t == 0) {
-       &::msg($recipient, "You have no botmail.") if ($always);
-    } else {
-       &::msg($recipient, "You have $t messages awaiting, from: $from (botmail read)");
+    if ( $t == 0 ) {
+        &::msg( $recipient, "You have no botmail." ) if ($always);
+    }
+    else {
+        &::msg( $recipient,
+            "You have $t messages awaiting, from: $from (botmail read)" );
     }
 }
 
 #####
 # Usage: botmail::next($recipient)
 sub next {
-    my($recipient) = @_;
-
-    my %hash = &::sqlSelectRowHash('botmail', '*', {
-       dstwho => lc $recipient
-    } );
-
-    if (scalar (keys %hash) <= 1) {
-       &::msg($recipient, "You have no botmail.");
-    } else {
-       my $date = scalar(gmtime $hash{'time'});
-       my $ago = &::Time2String(time() - $hash{'time'});
-       &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $date ($ago ago):");
-       &::msg($recipient, $hash{'msg'});
-       &::sqlDelete('botmail', { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}});
+    my ($recipient) = @_;
+
+    my %hash =
+      &::sqlSelectRowHash( 'botmail', '*', { dstwho => lc $recipient } );
+
+    if ( scalar( keys %hash ) <= 1 ) {
+        &::msg( $recipient, "You have no botmail." );
+    }
+    else {
+        my $date = scalar( gmtime $hash{'time'} );
+        my $ago  = &::Time2String( time() - $hash{'time'} );
+        &::msg( $recipient,
+            "From $hash{srcwho} ($hash{srcuh}) on $date ($ago ago):" );
+        &::msg( $recipient, $hash{'msg'} );
+        &::sqlDelete( 'botmail',
+            { 'dstwho' => $hash{dstwho}, 'srcwho' => $hash{srcwho} } );
     }
 }
 
 #####
 # Usage: botmail::add($recipient, $msg)
 sub add {
-    my($recipient, $msg) = @_;
+    my ( $recipient, $msg ) = @_;
     &::DEBUG("botmail::add(@_)");
 
     # allow optional trailing : ie: botmail for foo[:] hello
     $recipient =~ s/:$//;
 
-    # only support 1 botmail with unique dstwho/srcwho to have same
-    # functionality as botmail from infobot.
-    # Note: I removed the &::sqlQuote reference. Seems to be working and inserting fine without it here. -- troubled
-    my %hash = &::sqlSelectRowHash('botmail', '*', {
-       srcwho => lc $::who,
-       dstwho => lc $recipient
-    } );
-
-    if (scalar (keys %hash) > 1) {
-       &::msg($::who, "$recipient already has a message queued from you");
-       return;
+# only support 1 botmail with unique dstwho/srcwho to have same
+# functionality as botmail from infobot.
+# Note: I removed the &::sqlQuote reference. Seems to be working and inserting fine without it here. -- troubled
+    my %hash = &::sqlSelectRowHash(
+        'botmail',
+        '*',
+        {
+            srcwho => lc $::who,
+            dstwho => lc $recipient
+        }
+    );
+
+    if ( scalar( keys %hash ) > 1 ) {
+        &::msg( $::who, "$recipient already has a message queued from you" );
+        return;
     }
 
-    &::sqlInsert('botmail', {
-       'dstwho'        => lc $recipient,
-       'srcwho'        => lc $::who,
-       'srcuh'         => $::nuh,
-       'time'          => time(),
-       'msg'           => $msg,
-    } );
-
-    &::msg($::who, "OK, $::who, I'll let $recipient know.");
+    &::sqlInsert(
+        'botmail',
+        {
+            'dstwho' => lc $recipient,
+            'srcwho' => lc $::who,
+            'srcuh'  => $::nuh,
+            'time'   => time(),
+            'msg'    => $msg,
+        }
+    );
+
+    &::msg( $::who, "OK, $::who, I'll let $recipient know." );
 }
 
 1;