2 # botmail.pl: Botmail (ala in infobot)
4 # Version: v0.1 (20021122).
6 # NOTE: Motivated by BZFlag.
7 # TODO: full-fledged notes services (optional auth, etc)
17 if (!defined $what or $what =~ /^\s*$/) {
22 if ($what =~ /^(for|add)\s+(.*)$/i) {
23 &add( split(/\s+/, $2, 2) );
25 } elsif ($what =~ /^check(\s+(.*))?$/i) {
26 &check( split(/\s+/, $1, 2) );
28 } elsif ($what =~ /^(read|next)$/i) {
29 # TODO: read specific items? nah, will make this too complex.
36 # Usage: botmail::check($recipient)
39 $recipient ||= $::who;
41 # todo: simplify this select (use a diff function)
42 my @from = &::dbGet("botmail", "srcwho",
43 "dstwho=".&::dbQuote(lc $recipient)
46 my $from = join(", ", @from);
49 &::msg($recipient, "You have no botmail.");
51 &::msg($recipient, "You have $t messages awaiting, from: $from");
56 # Usage: botmail::next($recipient)
60 my %hash = &::dbGetColNiceHash("botmail", "*",
61 "dstwho=".&::dbQuote(lc $recipient)
64 if (scalar (keys %hash) <= 1) {
65 &::msg($recipient, "You have no botmail.");
67 my $ago = &::Time2String(time() - $hash{'time'});
68 &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $hash{time} [$ago]:");
69 &::msg($recipient, $hash{'msg'});
70 #&::dbDel("botmail", "id", $hash{id});
75 # Usage: botmail::add($recipient, $msg)
77 my($recipient, $msg) = @_;
78 &::DEBUG("botmail::add(@_)");
80 if (lc $recipient eq $::who) {
81 &::msg($::who, "well... a botmail to oneself is stupid!");
85 # only support 1 botmail with unique dstwho/srcwho to have same
86 # functionality as botmail from infobot.
87 my %hash = &::dbGetColNiceHash("botmail", "*",
88 "srcwho=".&::dbQuote(lc $::who)." AND ".
89 "dstwho=".&::dbQuote(lc $recipient)
92 if (scalar (keys %hash) > 1) {
93 &::msg($::who, "$recipient already has a message queued from you");
98 'dstwho' => lc $recipient,
99 'srcwho' => lc $::who,
101 'srcuh' => $::nuh, # will this work?
106 &::msg($::who, "OK, $::who, I'll let $recipient know.");