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) );
25 } elsif ($what =~ /^stats?$/i) {
28 } elsif ($what =~ /^check?$/i) {
31 } elsif ($what =~ /^(read|next)$/i) {
32 # TODO: read specific items? nah, will make this too complex.
39 my $botmail = &::countKeys("botmail");
40 &::msg($::who, "I have \002$botmail\002 ". &::fixPlural("message", $botmail). ".");
44 # Usage: botmail::check($recipient, [$always])
46 my($recipient, $always) = @_;
47 $recipient ||= $::who;
49 my %from = &::sqlSelectColHash("botmail", "srcwho,time", {
50 dstwho => lc $recipient
53 my $from = join(", ", keys %from);
56 &::msg($recipient, "You have no botmail.") if ($always);
58 &::msg($recipient, "You have $t messages awaiting, from: $from (botmail read)");
63 # Usage: botmail::next($recipient)
67 my %hash = &::sqlSelectRowHash("botmail", "*", {
68 dstwho => lc $recipient
71 if (scalar (keys %hash) <= 1) {
72 &::msg($recipient, "You have no botmail.");
74 my $date = scalar(gmtime $hash{'time'});
75 my $ago = &::Time2String(time() - $hash{'time'});
76 &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $date ($ago ago):");
77 &::msg($recipient, $hash{'msg'});
78 &::sqlDelete("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}});
83 # Usage: botmail::add($recipient, $msg)
85 my($recipient, $msg) = @_;
86 &::DEBUG("botmail::add(@_)");
88 # allow optional trailing : ie: botmail for foo[:] hello
91 # only support 1 botmail with unique dstwho/srcwho to have same
92 # functionality as botmail from infobot.
93 my %hash = &::sqlSelectRowHash("botmail", "*", {
94 srcwho => &::sqlQuote(lc $::who),
95 dstwho => &::sqlQuote(lc $recipient)
98 if (scalar (keys %hash) > 1) {
99 &::msg($::who, "$recipient already has a message queued from you");
103 &::sqlReplace("botmail", {
104 'dstwho' => lc $recipient,
105 'srcwho' => lc $::who,
111 &::msg($::who, "OK, $::who, I'll let $recipient know.");