mirror of
https://github.com/pragma-/pbot.git
synced 2025-10-14 06:57:25 +02:00
Core/Interpreter: process cmd-pipes at correct stack-depth
This commit is contained in:
parent
55831b3d4a
commit
4e69444be0
@ -243,6 +243,9 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma
|
|||||||
# reset $context's interpreter recursion depth counter
|
# reset $context's interpreter recursion depth counter
|
||||||
$context->{interpret_depth} = 0;
|
$context->{interpret_depth} = 0;
|
||||||
|
|
||||||
|
# reset $context's interpreter stack depth counter
|
||||||
|
$context->{stack_depth} = 0;
|
||||||
|
|
||||||
# interpet this command
|
# interpet this command
|
||||||
$context->{result} = $self->interpret($context);
|
$context->{result} = $self->interpret($context);
|
||||||
|
|
||||||
@ -269,7 +272,7 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma
|
|||||||
# command such as the channel, nick, user, host, command, etc.
|
# command such as the channel, nick, user, host, command, etc.
|
||||||
sub interpret($self, $context) {
|
sub interpret($self, $context) {
|
||||||
# log command invocation
|
# log command invocation
|
||||||
$self->{pbot}->{logger}->log("=== [$context->{interpret_depth}] Got command: "
|
$self->{pbot}->{logger}->log("=== [$context->{interpret_depth} ($context->{stack_depth})] Got command: "
|
||||||
. "($context->{from}) $context->{hostmask}: $context->{command}\n");
|
. "($context->{from}) $context->{hostmask}: $context->{command}\n");
|
||||||
|
|
||||||
# debug flag to trace $context location and contents
|
# debug flag to trace $context location and contents
|
||||||
@ -297,6 +300,7 @@ sub interpret($self, $context) {
|
|||||||
if ($context->{command} =~ m/^(.*?)\s*(?<!\\);;;\s*(.*)/ms) {
|
if ($context->{command} =~ m/^(.*?)\s*(?<!\\);;;\s*(.*)/ms) {
|
||||||
$context->{command} = $1; # command is the first half of the split
|
$context->{command} = $1; # command is the first half of the split
|
||||||
push @{$context->{cmdstack}}, $2; # store the rest of the split, potentially containing more splits
|
push @{$context->{cmdstack}}, $2; # store the rest of the split, potentially containing more splits
|
||||||
|
$context->{stack_depth}++;
|
||||||
push @{$context->{outq}}, []; # add output queue to stack
|
push @{$context->{outq}}, []; # add output queue to stack
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,6 +455,7 @@ sub interpret($self, $context) {
|
|||||||
|
|
||||||
# add it to the command stack
|
# add it to the command stack
|
||||||
push @{$context->{cmdstack}}, "$keyword $arguments";
|
push @{$context->{cmdstack}}, "$keyword $arguments";
|
||||||
|
$context->{stack_depth}++;
|
||||||
|
|
||||||
# add output queue to stack
|
# add output queue to stack
|
||||||
push @{$context->{outq}}, [];
|
push @{$context->{outq}}, [];
|
||||||
@ -486,14 +491,16 @@ sub interpret($self, $context) {
|
|||||||
# trim surrounding whitespace
|
# trim surrounding whitespace
|
||||||
$pipe =~ s/^\s+|\s+$//g;
|
$pipe =~ s/^\s+|\s+$//g;
|
||||||
|
|
||||||
|
my $depth = $context->{stack_depth};
|
||||||
|
|
||||||
# update contextual pipe data
|
# update contextual pipe data
|
||||||
if (exists $context->{pipe}) {
|
if (exists $context->{pipe}->{$depth}) {
|
||||||
$context->{pipe_rest} = "$rest | { $context->{pipe} }$context->{pipe_rest}";
|
$context->{pipe_rest}->{$depth} = "$rest | { $context->{pipe}->{$depth} }$context->{pipe_rest}->{$depth}";
|
||||||
} else {
|
} else {
|
||||||
$context->{pipe_rest} = $rest;
|
$context->{pipe_rest}->{$depth} = $rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
$context->{pipe} = $pipe;
|
$context->{pipe}->{$depth} = $pipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
# unescape any escaped command splits
|
# unescape any escaped command splits
|
||||||
@ -626,10 +633,10 @@ sub handle_result($self, $context, $result = $context->{result}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# finish piping
|
# finish piping
|
||||||
if (exists $context->{pipe}) {
|
if (exists $context->{pipe}->{$context->{stack_depth}}) {
|
||||||
my ($pipe, $pipe_rest) = (
|
my ($pipe, $pipe_rest) = (
|
||||||
delete $context->{pipe},
|
delete $context->{pipe}->{$context->{stack_depth}},
|
||||||
delete $context->{pipe_rest}
|
delete $context->{pipe_rest}->{$context->{stack_depth}}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (not $context->{alldone}) {
|
if (not $context->{alldone}) {
|
||||||
@ -644,6 +651,7 @@ sub handle_result($self, $context, $result = $context->{result}) {
|
|||||||
# process next command in stack
|
# process next command in stack
|
||||||
if (exists $context->{cmdstack}) {
|
if (exists $context->{cmdstack}) {
|
||||||
my $command = pop @{$context->{cmdstack}};
|
my $command = pop @{$context->{cmdstack}};
|
||||||
|
$context->{stack_depth}--;
|
||||||
|
|
||||||
if (@{$context->{cmdstack}} == 0 or $context->{alldone}) {
|
if (@{$context->{cmdstack}} == 0 or $context->{alldone}) {
|
||||||
delete $context->{cmdstack};
|
delete $context->{cmdstack};
|
||||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4881,
|
BUILD_REVISION => 4882,
|
||||||
BUILD_DATE => "2025-08-25",
|
BUILD_DATE => "2025-08-25",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user