From: dms Date: Thu, 21 Nov 2002 19:28:40 +0000 (+0000) Subject: - added new botmail feature (inspired by botmail from infobot) X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b9996d6838fad355adf849957a5183b50fc7536f;p=infobot.git - added new botmail feature (inspired by botmail from infobot) initial version (not tested) intended to be simple as possible. full fledged version might become Notes.pl ? - added two SQL functions that are very useful to access full column and row data. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@661 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/blootbot/src/CommandStubs.pl b/blootbot/src/CommandStubs.pl index eebe323..5651c71 100644 --- a/blootbot/src/CommandStubs.pl +++ b/blootbot/src/CommandStubs.pl @@ -247,6 +247,8 @@ sub parseCmdHook { &addCmdHook("extra", '(ex)?change', ('CODEREF' => 'Exchange::query', 'Identifier' => 'exchange', 'Cmdstats' => 'exchange', 'Forker' => 1) ); +&addCmdHook("extra", 'botmail', ('CODEREF' => 'botmail::parse', + 'Identifier' => 'botmail' ) ); ### ### END OF ADDING HOOKS. diff --git a/blootbot/src/IRC/IrcHooks.pl b/blootbot/src/IRC/IrcHooks.pl index 8f6d021..fbf99ba 100644 --- a/blootbot/src/IRC/IrcHooks.pl +++ b/blootbot/src/IRC/IrcHooks.pl @@ -582,6 +582,11 @@ sub on_join { } } + ### botmail: + if (&IsChanConf("botmail")) { + &botmail::check(lc $who); + } + ### wingate: &wingateCheck(); } diff --git a/blootbot/src/Modules/botmail.pl b/blootbot/src/Modules/botmail.pl new file mode 100644 index 0000000..1547f18 --- /dev/null +++ b/blootbot/src/Modules/botmail.pl @@ -0,0 +1,109 @@ +# +# botmail.pl: Botmail (ala in infobot) +# Author: dms +# Version: v0.1 (20021122). +# Created: 20021122 +# NOTE: Motivated by BZFlag. +# TODO: full-fledged notes services (optional auth, etc) +# + +package botmail; + +use strict; + +sub parse { + my($what) = @_; + + if (!defined $what or $what =~ /^\s*$/) { + &::help("botmail"); + return; + } + + if ($what =~ /^add(\s+(.*))?$/i) { + &add( split(/\s+/, $1, 2) ); + + } elsif ($what =~ /^next$/i) { + # todo: read specific items? nah, will make this too complex. + &read($::who); + + } +} + +##### +# Usage: botmail::check($who) +sub check { + my($w) = @_; + + # todo: simplify this select (use a diff function) + my @from = &::dbGet("botmail", "srcwho" + "dstwho=".&::dbQuote(lc $w) + ); + my $t = scalar @from; + my $from = join(", ", @from); + + if ($t == 0) { + &::msg($w, "You have no botmail."); + } else { + &::msg($w, "You have $t messages awaiting, from: $from"); + } +} + +##### +# Usage: botmail::read($who) +sub read { + my($w) = @_; + + # todo: simplify this select (use a diff function) + my $H = &::dbSelectHashref("*", "botmail", "srcwho", + "dstwho=".&::dbQuote(lc $w) + ); + + my $t = $H->total; # possible? + + if ($t == 0) { + &::msg($w, "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}); + &::dbDel("botmail", "id", $H->{id}); + } +} + +##### +# Usage: botmail::add($who, $msg) +sub add { + my($w, $msg) = @_; + + # 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? + + # 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; + } + + if (lc $w == $::who) { + &::msg($::who, "well... a botmail to oneself is stupid!"); + return; + } + + &::dbSetRow("botmail", { + dstwho => lc $w, + srcwho => lc $::who, + srcuh => $::nuh{lc $w}, # will this work? + -time => "NOW()", # todo: add '-' support. + # dbUpdate() supports it. + } ); + + &::msg($::who, "OK, $::who, I'll let $w know."); +} + +1; diff --git a/blootbot/src/dbi.pl b/blootbot/src/dbi.pl index 8d38b6a..144e894 100644 --- a/blootbot/src/dbi.pl +++ b/blootbot/src/dbi.pl @@ -211,6 +211,40 @@ sub dbGetColInfo { return @cols; } +##### NOTE: not used yet. +# Usage: &dbSelectHashref($select, $from, $where, $other) +sub dbSelectHashref { + my $c = dbSelectManyHash(@_); + my $H = $c->fetchrow_hashref; + $c->finish; + return $H; +} + +##### NOTE: not used yet. +# Usage: &dbSelectHashref($select, $from, $where, $other) +sub dbSelectManyHash { + my($select, $from, $where, $other) = @_; + my $sql; + + $sql = "SELECT $select "; + $sql .= "FROM $from " if $from; + $sql .= "WHERE $where " if $where; + $sql .= "$other" if $other; + $debug_sql = $sql; + + sqlConnect(); + my $c = $I{dbh}->prepare($sql); + # $c->execute or print "\n

SQL Hashref Error
\n"; + + unless ($c->execute) { + apacheLog($sql); + #kill 9,$$; + } + + return $c; +} + + ##### # Usage: &dbSet($table, $primhash_ref, $hash_ref); # Note: dbSet does dbQuote. diff --git a/blootbot/src/modules.pl b/blootbot/src/modules.pl index a199b44..babaec0 100644 --- a/blootbot/src/modules.pl +++ b/blootbot/src/modules.pl @@ -55,6 +55,7 @@ if ($@) { "zfi" => "zfi.pl", "zippy" => "Zippy.pl", "zsi" => "zsi.pl", + "botmail" => "botmail.pl", ); ### THIS IS NOT LOADED ON RELOAD :( my @myModulesLoadNow;