]> git.donarmstrong.com Git - infobot.git/commitdiff
more botmail
authortimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Thu, 21 Nov 2002 21:10:17 +0000 (21:10 +0000)
committertimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Thu, 21 Nov 2002 21:10:17 +0000 (21:10 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@668 c11ca15a-4712-0410-83d8-924469b57eb5

setup/botmail.sql [new file with mode: 0644]
src/Modules/botmail.pl
src/modules.pl

diff --git a/setup/botmail.sql b/setup/botmail.sql
new file mode 100644 (file)
index 0000000..1efdd9b
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE botmail (
+       srcwho VARCHAR(20) NOT NULL,
+       dstwho VARCHAR(20) NOT NULL,
+       srcuh VARCHAR(80) NOT NULL,
+       time INT UNSIGNED DEFAULT 'UNIX_TIMESTAMP()',
+       msg TEXT NOT NULL,
+
+       PRIMARY KEY (srcwho,dstwho)
+);
index 1547f18b37efc149f0ef0368985c94e71aa96fd7..b34869535f9266c35863a6443fdfa51b8c68029e 100644 (file)
@@ -19,7 +19,7 @@ sub parse {
        return;
     }
 
-    if ($what =~ /^add(\s+(.*))?$/i) {
+    if ($what =~ /^add\s+(.*)$/i) {
        &add( split(/\s+/, $1, 2) );
 
     } elsif ($what =~ /^next$/i) {
@@ -30,80 +30,79 @@ sub parse {
 }
 
 #####
-# Usage: botmail::check($who)
+# Usage: botmail::check($recipient)
 sub check {
-    my($w) = @_;
+    my($recipient) = @_;
 
     # todo: simplify this select (use a diff function)
-    my @from = &::dbGet("botmail", "srcwho"
-       "dstwho=".&::dbQuote(lc $w)
+    my @from = &::dbGet("botmail", "srcwho",
+       "dstwho=".&::dbQuote(lc $recipient)
     );
     my $t      = scalar @from;
     my $from   = join(", ", @from);
 
     if ($t == 0) {
-       &::msg($w, "You have no botmail.");
+       &::msg($recipient, "You have no botmail.");
     } else {
-       &::msg($w, "You have $t messages awaiting, from: $from");
+       &::msg($recipient, "You have $t messages awaiting, from: $from");
     }
 }
 
 #####
-# Usage: botmail::read($who)
+# Usage: botmail::read($recipient)
 sub read {
-    my($w) = @_;
+    my($recipient) = @_;
 
     # todo: simplify this select (use a diff function)
     my $H = &::dbSelectHashref("*", "botmail", "srcwho",
-       "dstwho=".&::dbQuote(lc $w)
+       "dstwho=".&::dbQuote(lc $recipient)
     );
 
     my $t = $H->total; # possible?
 
     if ($t == 0) {
-       &::msg($w, "You have no botmail.");
+       &::msg($recipient, "You have no botmail.");
     } else {
        my $ago = &::Time2String(time() - $H->{time});
-       &::msg($w, "From $H->{srcwho} ($H->{srcuh}) on $H->{time} [$ago]:");
-       &::msg($w, $H->{message});
+       &::msg($recipient, "From $H->{srcwho} ($H->{srcuh}) on $H->{time} [$ago]:");
+       &::msg($recipient, $H->{message});
        &::dbDel("botmail", "id", $H->{id});
     }
 }
 
 #####
-# Usage: botmail::add($who, $msg)
+# Usage: botmail::add($recipient, $msg)
 sub add {
-    my($w, $msg) = @_;
+    my($recipient, $msg) = @_;
+    &::DEBUG("botmail::add(@_)");
 
-    # todo: simplify this select (use a diff function)
-    my $H = &::dbSelectHashref("*", "botmail", "srcwho",
-       "srcwho=".&::dbQuote(lc $::who)." AND ".
-       "dstwho=".&::dbQuote(lc $w)
-    );
-
-    my $t = $H->total; # possible?
+    if (lc $recipient eq $::who) {
+       &::msg($::who, "well... a botmail to oneself is stupid!");
+       return;
+    }
 
     # only support 1 botmail with unique dstwho/srcwho to have same
     # functionality as botmail from infobot.
-    if ($t == 1) {
-       &::msg($::who, "$w already has a message queued from you");
-       return;
-    }
+    my %hash = &::dbGetColNiceHash("botmail", "*",
+       "srcwho=".&::dbQuote(lc $::who)." AND ".
+       "dstwho=".&::dbQuote(lc $recipient)
+    );
 
-    if (lc $w == $::who) {
-       &::msg($::who, "well... a botmail to oneself is stupid!");
+    if (%hash) {
+       &::msg($::who, "$recipient already has a message queued from you");
        return;
     }
 
-    &::dbSetRow("botmail", {
-       dstwho  => lc $w,
-       srcwho  => lc $::who,
-       srcuh   => $::nuh{lc $w},       # will this work?
-       -time   => "NOW()",             # todo: add '-' support.
-                                       # dbUpdate() supports it.
+    &::dbSet("botmail", {
+       'dstwho'        => lc $recipient,
+       'srcwho'        => lc $::who,
+    }, {
+       'srcuh' => $::nuh,      # will this work?
+       'time'  => time(),
+       'msg'   => $msg,
     } );
 
-    &::msg($::who, "OK, $::who, I'll let $w know.");
+    &::msg($::who, "OK, $::who, I'll let $recipient know.");
 }
 
 1;
index 2ecdf507ad476233852fff154c14d787892ae28a..5a8a20980200687fe7349d4ae162efb57c419270 100644 (file)
@@ -61,7 +61,7 @@ if ($@) {
 my @myModulesLoadNow;
 my @myModulesReloadNot;
 BEGIN {
-    @myModulesLoadNow  = ('topic', 'uptime', 'news', 'rootWarn', 'symdump');
+    @myModulesLoadNow  = ('topic', 'uptime', 'news', 'rootWarn', 'symdump', 'botmail');
     @myModulesReloadNot        = ('IRC/Irc.pl','IRC/Schedulers.pl');
 }