From 04cbc39f45159b26c806633842fb568719e2ff0e Mon Sep 17 00:00:00 2001 From: timriker Date: Thu, 21 Nov 2002 21:10:17 +0000 Subject: [PATCH] more botmail git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@668 c11ca15a-4712-0410-83d8-924469b57eb5 --- setup/botmail.sql | 9 ++++++ src/Modules/botmail.pl | 69 +++++++++++++++++++++--------------------- src/modules.pl | 2 +- 3 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 setup/botmail.sql diff --git a/setup/botmail.sql b/setup/botmail.sql new file mode 100644 index 0000000..1efdd9b --- /dev/null +++ b/setup/botmail.sql @@ -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) +); diff --git a/src/Modules/botmail.pl b/src/Modules/botmail.pl index 1547f18..b348695 100644 --- a/src/Modules/botmail.pl +++ b/src/Modules/botmail.pl @@ -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; diff --git a/src/modules.pl b/src/modules.pl index 2ecdf50..5a8a209 100644 --- a/src/modules.pl +++ b/src/modules.pl @@ -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'); } -- 2.39.5