]> git.donarmstrong.com Git - infobot.git/blob - blootbot/src/Modules/botmail.pl
- added new botmail feature (inspired by botmail from infobot)
[infobot.git] / blootbot / src / Modules / botmail.pl
1 #
2 #  botmail.pl: Botmail (ala in infobot)
3 #      Author: dms
4 #     Version: v0.1 (20021122).
5 #     Created: 20021122
6 #        NOTE: Motivated by BZFlag.
7 #        TODO: full-fledged notes services (optional auth, etc)
8 #
9
10 package botmail;
11
12 use strict;
13
14 sub parse {
15     my($what) = @_;
16
17     if (!defined $what or $what =~ /^\s*$/) {
18         &::help("botmail");
19         return;
20     }
21
22     if ($what =~ /^add(\s+(.*))?$/i) {
23         &add( split(/\s+/, $1, 2) );
24
25     } elsif ($what =~ /^next$/i) {
26         # todo: read specific items? nah, will make this too complex.
27         &read($::who);
28
29     }
30 }
31
32 #####
33 # Usage: botmail::check($who)
34 sub check {
35     my($w) = @_;
36
37     # todo: simplify this select (use a diff function)
38     my @from = &::dbGet("botmail", "srcwho"
39         "dstwho=".&::dbQuote(lc $w)
40     );
41     my $t       = scalar @from;
42     my $from    = join(", ", @from);
43
44     if ($t == 0) {
45         &::msg($w, "You have no botmail.");
46     } else {
47         &::msg($w, "You have $t messages awaiting, from: $from");
48     }
49 }
50
51 #####
52 # Usage: botmail::read($who)
53 sub read {
54     my($w) = @_;
55
56     # todo: simplify this select (use a diff function)
57     my $H = &::dbSelectHashref("*", "botmail", "srcwho",
58         "dstwho=".&::dbQuote(lc $w)
59     );
60
61     my $t = $H->total;  # possible?
62
63     if ($t == 0) {
64         &::msg($w, "You have no botmail.");
65     } else {
66         my $ago = &::Time2String(time() - $H->{time});
67         &::msg($w, "From $H->{srcwho} ($H->{srcuh}) on $H->{time} [$ago]:");
68         &::msg($w, $H->{message});
69         &::dbDel("botmail", "id", $H->{id});
70     }
71 }
72
73 #####
74 # Usage: botmail::add($who, $msg)
75 sub add {
76     my($w, $msg) = @_;
77
78     # todo: simplify this select (use a diff function)
79     my $H = &::dbSelectHashref("*", "botmail", "srcwho",
80         "srcwho=".&::dbQuote(lc $::who)." AND ".
81         "dstwho=".&::dbQuote(lc $w)
82     );
83
84     my $t = $H->total;  # possible?
85
86     # only support 1 botmail with unique dstwho/srcwho to have same
87     # functionality as botmail from infobot.
88     if ($t == 1) {
89         &::msg($::who, "$w already has a message queued from you");
90         return;
91     }
92
93     if (lc $w == $::who) {
94         &::msg($::who, "well... a botmail to oneself is stupid!");
95         return;
96     }
97
98     &::dbSetRow("botmail", {
99         dstwho  => lc $w,
100         srcwho  => lc $::who,
101         srcuh   => $::nuh{lc $w},       # will this work?
102         -time   => "NOW()",             # todo: add '-' support.
103                                         # dbUpdate() supports it.
104     } );
105
106     &::msg($::who, "OK, $::who, I'll let $w know.");
107 }
108
109 1;