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 =~ /^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 # todo: simplify this select (use a diff function)
50 my %from = &::dbGetCol("botmail", "srcwho",
51 "dstwho=".&::dbQuote(lc $recipient),2);
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 = &::dbGetColNiceHash("botmail", "*",
68 "dstwho=".&::dbQuote(lc $recipient)
71 if (scalar (keys %hash) <= 1) {
72 &::msg($recipient, "You have no botmail.");
74 my $ago = &::Time2String(time() - $hash{'time'});
75 &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $hash{time} [$ago]:");
76 &::msg($recipient, $hash{'msg'});
77 &::dbDel("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}});
82 # Usage: botmail::add($recipient, $msg)
84 my($recipient, $msg) = @_;
85 &::DEBUG("botmail::add(@_)");
87 if (lc $recipient eq $::who) {
88 &::msg($::who, "well... a botmail to oneself is stupid!");
92 # only support 1 botmail with unique dstwho/srcwho to have same
93 # functionality as botmail from infobot.
94 my %hash = &::dbGetColNiceHash("botmail", "*",
95 "srcwho=".&::dbQuote(lc $::who)." AND ".
96 "dstwho=".&::dbQuote(lc $recipient)
99 if (scalar (keys %hash) > 1) {
100 &::msg($::who, "$recipient already has a message queued from you");
104 &::dbSet("botmail", {
105 'dstwho' => lc $recipient,
106 'srcwho' => lc $::who,
108 'srcuh' => $::nuh, # will this work?
113 &::msg($::who, "OK, $::who, I'll let $recipient know.");