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 =~ /^check?$/i) {
33 } elsif ($what =~ /^(read|next)$/i) {
34 # TODO: read specific items? nah, will make this too complex.
41 # Usage: botmail::check($recipient, [$always])
43 my($recipient, $always) = @_;
44 $recipient ||= $::who;
46 # todo: simplify this select (use a diff function)
47 my %from = &::dbGetCol("botmail", "srcwho",
48 "dstwho=".&::dbQuote(lc $recipient),2);
50 my $from = join(", ", keys %from);
53 &::msg($recipient, "You have no botmail.") if ($always);
55 &::msg($recipient, "You have $t messages awaiting, from: $from (botmail read)");
60 # Usage: botmail::next($recipient)
64 my %hash = &::dbGetColNiceHash("botmail", "*",
65 "dstwho=".&::dbQuote(lc $recipient)
68 if (scalar (keys %hash) <= 1) {
69 &::msg($recipient, "You have no botmail.");
71 my $ago = &::Time2String(time() - $hash{'time'});
72 &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $hash{time} [$ago]:");
73 &::msg($recipient, $hash{'msg'});
74 &::dbDel("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}});
79 # Usage: botmail::add($recipient, $msg)
81 my($recipient, $msg) = @_;
82 &::DEBUG("botmail::add(@_)");
84 if (lc $recipient eq $::who) {
85 &::msg($::who, "well... a botmail to oneself is stupid!");
89 # only support 1 botmail with unique dstwho/srcwho to have same
90 # functionality as botmail from infobot.
91 my %hash = &::dbGetColNiceHash("botmail", "*",
92 "srcwho=".&::dbQuote(lc $::who)." AND ".
93 "dstwho=".&::dbQuote(lc $recipient)
96 if (scalar (keys %hash) > 1) {
97 &::msg($::who, "$recipient already has a message queued from you");
101 &::dbSet("botmail", {
102 'dstwho' => lc $recipient,
103 'srcwho' => lc $::who,
105 'srcuh' => $::nuh, # will this work?
110 &::msg($::who, "OK, $::who, I'll let $recipient know.");