sub parseCmdHook {
my ($hashname, $line) = @_;
$line =~ /^(\S+)( (.*))?$/;
- my @args = split(' ', $3 || '');
- my $flatarg = $3;
my $cmd = $1; # command name is whitespaceless.
+ my $flatarg = $3;
+ my @args = split(/\s+/, $flatarg || '');
my $done = 0;
&shmFlush();
next;
}
- &DEBUG("pCH(hooks_$hashname): $cmd matched $ident");
+ &status("hooks($hashname): $cmd matched '$ident'");
my %hash = %{ ${"hooks_$hashname"}{$ident} };
if (!scalar keys %hash) {
return 1;
}
+ if ($hash{NoArgs} and $flatarg) {
+ &DEBUG("cmd $ident does not take args; skipping.");
+ next;
+ }
+
if (!exists $hash{CODEREF}) {
&ERROR("CODEREF undefined for $cmd or $ident.");
return 1;
### DEBUG.
foreach (keys %hash) {
- &DEBUG(" $cmd->$_ => '$hash{$_}'.");
+ &VERB(" $cmd->$_ => '$hash{$_}'.",2);
}
### HELP.
if (exists $hash{'Forker'}) {
$hash{'Identifier'} .= "-" if ($hash{'Forker'} eq "NULL");
- ### FLAT_ARG / ARRAY option.
+ if (exists $hash{'ArrayArgs'}) {
+ &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
+ } else {
+ &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}($flatarg) } );
+ }
- &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
} else {
if (exists $hash{'Module'}) {
&loadMyModule($myModules{ $hash{'Module'} });
}
- ### TODO: check if CODEREF exists.
+ # check if CODEREF exists.
+ if (!defined &{ $hash{'CODEREF'} }) {
+ &WARN("coderef $hash{'CODEREF'} don't exist.");
+ return 1;
+ }
- if (exists $hash{'FlatArg'} and $hash{'FlatArg'} == 0) {
- &status("CmdHook: using args as array.");
+ if (exists $hash{'ArrayArgs'}) {
&{$hash{'CODEREF'}}(@args);
} else {
&{$hash{'CODEREF'}}($flatarg);
$cmdstats{ $hash{'Cmdstats'} }++;
}
- &DEBUG("pCH: ended.");
+ &VERB("hooks: End of command.",2);
$done = 1;
}
'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
&addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
'Forker' => 1, 'Identifier' => 'kernel',
- 'Cmdstats' => 'Kernel') );
+ 'Cmdstats' => 'Kernel', 'NoArgs' => 1) );
&addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
'Identifier' => 'search', Module => 'factoids',
'Help' => 'listauth') );
&addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
'Cmdstats' => 'Uptime') );
&addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
- sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
&addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
'Forker' => 1, 'Help' => 'freshmeat') );
my $thiscmd = lc($1);
my $args = $3;
+ $args =~ s/\s+$//g;
+ # suggested by asuffield nad \broken.
+ if ($args =~ /^["']/ and $args =~ /["']$/) {
+ &DEBUG("list*: removed quotes.");
+ $args =~ s/^["']|["']$//g;
+ }
$thiscmd =~ s/^vals$/values/;
return if ($thiscmd ne "keys" && $thiscmd ne "values");
return unless (&hasParam("topic"));
my $chan = $talkchannel;
- my @args = split(/ /, $2);
+ my @args = split / /, $2 || "";
if (!scalar @args) {
&msg($who,"Try 'help topic'");
&msg($who, "Sending CTCP VERSION...");
$conn->ctcp("VERSION", $chan);
- $cache{verstats} = $chan;
+ $cache{verstats}{chan} = $chan;
+ $cache{verstats}{who} = $who;
+ $cache{verstats}{msgType} = $msgType;
$conn->schedule(60, sub {
my $vtotal = 0;
- my $c = lc $cache{verstats};
+ my $c = lc $cache{verstats}{chan};
my $total = keys %{ $channels{$c}{''} };
- delete $cache{verstats};
$chan = $c;
+ $who = $cache{verstats}{who};
+ $msgType = $cache{verstats}{msgType};
+ delete $cache{verstats}; # sufficient?
foreach (keys %ver) {
$vtotal += scalar keys %{ $ver{$_} };
return;
}
+sub nullski { my ($arg) = @_; return unless (defined $arg);
+ foreach (`$arg`) { &msg($who,$_); } }
+
1;