2 # botmail.pl: Botmail (ala in infobot)
4 # Version: v0.1 (20021122).
6 # NOTE: Motivated by TimRiker.
7 # TODO: full-fledged notes services (optional auth, etc)
17 if ( !defined $what or $what =~ /^\s*$/ ) {
22 if ( $what =~ /^(to|for|add)\s+(.*)$/i ) {
23 &add( split( /\s+/, $2, 2 ) );
26 elsif ( $what =~ /^stats?$/i ) {
30 elsif ( $what =~ /^check?$/i ) {
34 elsif ( $what =~ /^(read|next)$/i ) {
36 # TODO: read specific items? nah, will make this too complex.
43 my $botmail = &::countKeys('botmail');
45 "I have \002$botmail\002 "
46 . &::fixPlural( 'message', $botmail )
51 # Usage: botmail::check($recipient, [$always])
53 my ( $recipient, $always ) = @_;
54 $recipient ||= $::who;
57 &::sqlSelectColHash( 'botmail', "srcwho,time",
58 { dstwho => lc $recipient } );
60 my $from = join( ", ", keys %from );
63 &::msg( $recipient, "You have no botmail." ) if ($always);
67 "You have $t messages awaiting, from: $from (botmail read)" );
72 # Usage: botmail::next($recipient)
77 &::sqlSelectRowHash( 'botmail', '*', { dstwho => lc $recipient } );
79 if ( scalar( keys %hash ) <= 1 ) {
80 &::msg( $recipient, "You have no botmail." );
83 my $date = scalar( gmtime $hash{'time'} );
84 my $ago = &::Time2String( time() - $hash{'time'} );
86 "From $hash{srcwho} ($hash{srcuh}) on $date ($ago ago):" );
87 &::msg( $recipient, $hash{'msg'} );
88 &::sqlDelete( 'botmail',
89 { 'dstwho' => $hash{dstwho}, 'srcwho' => $hash{srcwho} } );
94 # Usage: botmail::add($recipient, $msg)
96 my ( $recipient, $msg ) = @_;
97 &::DEBUG("botmail::add(@_)");
99 # allow optional trailing : ie: botmail for foo[:] hello
100 $recipient =~ s/:$//;
102 # only support 1 botmail with unique dstwho/srcwho to have same
103 # functionality as botmail from infobot.
104 # Note: I removed the &::sqlQuote reference. Seems to be working and inserting fine without it here. -- troubled
105 my %hash = &::sqlSelectRowHash(
110 dstwho => lc $recipient
114 if ( scalar( keys %hash ) > 1 ) {
115 &::msg( $::who, "$recipient already has a message queued from you" );
122 'dstwho' => lc $recipient,
123 'srcwho' => lc $::who,
130 &::msg( $::who, "OK, $::who, I'll let $recipient know." );
135 # vim:ts=4:sw=4:expandtab:tw=80