From: dms Date: Mon, 18 Sep 2000 11:47:17 +0000 (+0000) Subject: minor cleanup. X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6ed75cb9daa767dea29acfe75db8bbc7b6fd082c;p=infobot.git minor cleanup. Preliminary command hooks (event handlers) working! git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@116 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/blootbot/src/CommandStubs.pl b/blootbot/src/CommandStubs.pl index 35a9b3e..f11394a 100644 --- a/blootbot/src/CommandStubs.pl +++ b/blootbot/src/CommandStubs.pl @@ -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;