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 ($::param{'DBType'} =~ /^dbm/i) {
18 # FIXME multi field indexed tables not supported under dbm
19 &::msg($::who, "botmail disabled for $::param{'DBType'}");
22 if (!defined $what or $what =~ /^\s*$/) {
27 if ($what =~ /^(for|add)\s+(.*)$/i) {
28 &add( split(/\s+/, $2, 2) );
30 } elsif ($what =~ /^stats?$/i) {
33 } elsif ($what =~ /^check?$/i) {
36 } elsif ($what =~ /^(read|next)$/i) {
37 # TODO: read specific items? nah, will make this too complex.
44 my $botmail = &::countKeys("botmail");
45 &::msg($::who, "I have \002$botmail\002 ". &::fixPlural("message", $botmail). ".");
49 # Usage: botmail::check($recipient, [$always])
51 my($recipient, $always) = @_;
52 $recipient ||= $::who;
54 # todo: simplify this select (use a diff function)
55 my %from = &::dbGetCol("botmail", "srcwho",
56 "dstwho=".&::dbQuote(lc $recipient),2);
58 my $from = join(", ", keys %from);
61 &::msg($recipient, "You have no botmail.") if ($always);
63 &::msg($recipient, "You have $t messages awaiting, from: $from (botmail read)");
68 # Usage: botmail::next($recipient)
72 my %hash = &::dbGetColNiceHash("botmail", "*",
73 "dstwho=".&::dbQuote(lc $recipient)
76 if (scalar (keys %hash) <= 1) {
77 &::msg($recipient, "You have no botmail.");
79 my $ago = &::Time2String(time() - $hash{'time'});
80 &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $hash{time} [$ago]:");
81 &::msg($recipient, $hash{'msg'});
82 &::dbDel("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}});
87 # Usage: botmail::add($recipient, $msg)
89 my($recipient, $msg) = @_;
90 &::DEBUG("botmail::add(@_)");
92 if (lc $recipient eq $::who) {
93 &::msg($::who, "well... a botmail to oneself is stupid!");
97 # only support 1 botmail with unique dstwho/srcwho to have same
98 # functionality as botmail from infobot.
99 my %hash = &::dbGetColNiceHash("botmail", "*",
100 "srcwho=".&::dbQuote(lc $::who)." AND ".
101 "dstwho=".&::dbQuote(lc $recipient)
104 if (scalar (keys %hash) > 1) {
105 &::msg($::who, "$recipient already has a message queued from you");
109 &::dbSet("botmail", {
110 'dstwho' => lc $recipient,
111 'srcwho' => lc $::who,
113 'srcuh' => $::nuh, # will this work?
118 &::msg($::who, "OK, $::who, I'll let $recipient know.");