]> git.donarmstrong.com Git - infobot.git/commitdiff
minor cleanup.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Mon, 18 Sep 2000 11:47:17 +0000 (11:47 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Mon, 18 Sep 2000 11:47:17 +0000 (11:47 +0000)
Preliminary command hooks (event handlers) working!

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@116 c11ca15a-4712-0410-83d8-924469b57eb5

src/CommandStubs.pl

index 35a9b3e9cd4a322afe18566e6940d6916db02714..f11394a3e831c1368b9c7dbdb912ce2f69272c89 100644 (file)
@@ -13,6 +13,7 @@ $babel::lang_regex = "";      # lame fix.
 ### PROPOSED COMMAND HOOK IMPLEMENTATION.
 # addCmdHook('TEXT_HOOK', $code_ref,
 #      (Forker         => 1,
+#      CheckModule     => 1,
 #      Identifier      => 'config_label',
 #      Help            => 'help_label',
 #      Cmdstats        => 'text_label',)
@@ -20,7 +21,8 @@ $babel::lang_regex = "";      # lame fix.
 ### EXAMPLE
 # addCmdHook('d?find', (
 #      CODEREF => \&debianFind(),
-#      Forker => 1,
+#      CheckModule => 1,
+#      Forker => 1,            # if simple function.
 #      Identifier => "debian",
 #      Help => "dfind",
 #      Cmdstats => "Debian Search",) );
@@ -37,17 +39,44 @@ sub addCmdHook {
 
 # RUN IF ADDRESSED.
 sub parseCmdHook {
+    my @args = split(' ', $message);
+
     foreach (keys %cmdhooks) {
-       &DEBUG("cmdhooks{$_} => ...");
-       my %hash = \%{ $cmdhooks{$_} };
+       my $ident = $_;
+       &DEBUG("cmdhooks{$ident} => ...");
+
+       next unless ($args[0] =~ /^$ident$/i);
+
+       &DEBUG("pCH: MATCHED!");
+       my %hash = %{ $cmdhooks{$ident} };
+
+       ### DEBUG.
        foreach (keys %hash) {
-           &DEBUG("   '$_' => '$hash{$_}'.");
+           &DEBUG(" $ident->$_ => '$hash{$_}'.");
+       }
+
+       ### IDENTIFIER.
+       if (exists $hash{'Identifier'}) {
+           return $noreply unless (&hasParam($hash{'Identifier'}));
+       }
+
+       ### FORKER,IDENTIFIER,CODEREF.
+       if (exists $hash{'Forker'}) {
+           &Forker($hash{'Identifier'}, \&{$hash{'CODEREF'}});
+       }
+
+       ### CMDSTATS.
+       if (exists $hash{'Cmdstats'}) {
+           $cmdstats{$hash{'Cmdstats'}}++;
        }
     }
 
     &DEBUG("pCH: ended.");
 }
 
+&addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
+       'Forker' => 1, 'Identifier' => 'debianExtra', 'Cmdstats' => 1) );
+
 sub Modules {
     if (!defined $message) {
        &WARN("Modules: message is undefined. should never happen.");
@@ -375,10 +404,7 @@ sub Modules {
            return $noreply;
        }
 
-       ### chews up to 4megs => use forker :)
        &Forker("search", sub { &Search::Search($thiscmd, $args); } );
-#      &loadMyModule($myModules{'search'});
-#      &Search::Search($thiscmd, $args);
 
        $cmdstats{'Factoid Search'}++;
        return $noreply;