From 43d227d1a982bf025b89d1bea9b6e6a48fd059eb Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 4 Dec 2017 18:34:34 -0800 Subject: [PATCH] Support command substitution --- PBot/Interpreter.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index e4bd79bf..a82265c9 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -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/(?{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/(?{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});