]> git.donarmstrong.com Git - infobot.git/commitdiff
- added new botmail feature (inspired by botmail from infobot)
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Thu, 21 Nov 2002 19:28:40 +0000 (19:28 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Thu, 21 Nov 2002 19:28:40 +0000 (19:28 +0000)
  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/blootbot@661 c11ca15a-4712-0410-83d8-924469b57eb5

src/CommandStubs.pl
src/IRC/IrcHooks.pl
src/Modules/botmail.pl [new file with mode: 0644]
src/dbi.pl
src/modules.pl

index eebe3239bf450646152b218abe31d460a34c9bef..5651c715b4ab57f51149bee6670e22e3048c97d2 100644 (file)
@@ -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.
index 8f6d0214ea99a1e124fa6ed3a923dbe2b382f8bb..fbf99ba931f1d6f4f0d2536ea56e27b8ec6e17d4 100644 (file)
@@ -582,6 +582,11 @@ sub on_join {
        }
     }
 
+    ### botmail:
+    if (&IsChanConf("botmail")) {
+       &botmail::check(lc $who);
+    }
+
     ### wingate:
     &wingateCheck();
 }
diff --git a/src/Modules/botmail.pl b/src/Modules/botmail.pl
new file mode 100644 (file)
index 0000000..1547f18
--- /dev/null
@@ -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;
index 8d38b6a8f16eb134dfcdd0f94e60ef1fec118f25..144e89458cbf48064a28a41e642d6da931eceb3d 100644 (file)
@@ -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<P><B>SQL Hashref Error</B><BR>\n";
+
+    unless ($c->execute) {
+        apacheLog($sql);
+        #kill 9,$$;
+    }
+
+    return $c;
+}
+
+
 #####
 # Usage: &dbSet($table, $primhash_ref, $hash_ref);
 #  Note: dbSet does dbQuote.
index a199b4441149bd5a4f08e89b88dc744007c0ce14..babaec00891db7a143de7e227d07cb47176661f7 100644 (file)
@@ -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;