Support command substitution

This commit is contained in:
Pragmatic Software 2017-12-04 18:34:34 -08:00
parent 8b2f64bf84
commit 43d227d1a9
1 changed files with 27 additions and 0 deletions

View File

@ -254,6 +254,17 @@ sub interpret {
$self->{pbot}->{logger}->log("Truncating keyword to 30 chars: $keyword\n");
}
# parse out a substituted command
if (defined $arguments && $arguments =~ s/(?<!\\)&\{\s*([^}]+)\}/&{subcmd}/) {
my $command = $1;
push @{$stuff->{subcmd}}, "$keyword $arguments";
$stuff->{command} = $command;
my $result = $self->interpret($stuff);
$stuff->{result} = $result;
return $result;
}
# parse out a pipe unless escaped
if (defined $arguments && $arguments =~ m/(?<!\\)\|\s*\{\s*[^}]+\}\s*$/) {
$arguments =~ m/(.*?)\s*(?<!\\)\|\s*\{\s*([^}]+)\}(.*)/s;
@ -364,6 +375,22 @@ sub handle_result {
return 0;
}
if (exists $stuff->{subcmd}) {
my $command = pop @{$stuff->{subcmd}};
if (@{$stuff->{subcmd}} == 0) {
delete $stuff->{subcmd};
}
$command =~ s/&\{subcmd\}/$result/;
$stuff->{command} = $command;
$result = $self->interpret($stuff);
$stuff->{result}= $result;
$self->handle_result($stuff);
return 0;
}
if ($stuff->{pipe} and not $stuff->{authorized}) {
my ($pipe, $pipe_rest) = ($stuff->{pipe}, $stuff->{pipe_rest});