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 =~ /^(add|for)\s+(.*)$/i) {
23 &add( split(/\s+/, $2, 2) );
25 } elsif ($what =~ /^check(\s+(.*))?$/i) {
26 &check( split(/\s+/, $1, 2) );
28 } elsif ($what =~ /^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::read($recipient)
60 # todo: simplify this select (use a diff function)
61 my $H = &::dbSelectHashref("*", "botmail", "srcwho",
62 "dstwho=".&::dbQuote(lc $recipient)
65 my $t = $H->total; # possible?
68 &::msg($recipient, "You have no botmail.");
70 my $ago = &::Time2String(time() - $H->{time});
71 &::msg($recipient, "From $H->{srcwho} ($H->{srcuh}) on $H->{time} [$ago]:");
72 &::msg($recipient, $H->{message});
73 &::dbDel("botmail", "id", $H->{id});
78 # Usage: botmail::add($recipient, $msg)
80 my($recipient, $msg) = @_;
81 &::DEBUG("botmail::add(@_)");
83 if (lc $recipient eq $::who) {
84 &::msg($::who, "well... a botmail to oneself is stupid!");
88 # only support 1 botmail with unique dstwho/srcwho to have same
89 # functionality as botmail from infobot.
90 my %hash = &::dbGetColNiceHash("botmail", "*",
91 "srcwho=".&::dbQuote(lc $::who)." AND ".
92 "dstwho=".&::dbQuote(lc $recipient)
96 &::msg($::who, "$recipient already has a message queued from you");
100 &::dbSet("botmail", {
101 'dstwho' => lc $recipient,
102 'srcwho' => lc $::who,
104 'srcuh' => $::nuh, # will this work?
109 &::msg($::who, "OK, $::who, I'll let $recipient know.");