From 94fbb81bdacb632172a4aa0bf0ec384c7d22af9e Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 21 Oct 2025 12:50:09 -0700 Subject: [PATCH] Interpreter: improve arguments processing --- lib/PBot/Core/Factoids/Interpreter.pm | 5 ++--- lib/PBot/Core/Factoids/Variables.pm | 2 +- lib/PBot/Core/Interpreter.pm | 6 ++++++ lib/PBot/VERSION.pm | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/PBot/Core/Factoids/Interpreter.pm b/lib/PBot/Core/Factoids/Interpreter.pm index e62e0711..cfda7577 100644 --- a/lib/PBot/Core/Factoids/Interpreter.pm +++ b/lib/PBot/Core/Factoids/Interpreter.pm @@ -338,8 +338,7 @@ sub handle_action($self, $context, $action) { $action = $self->{pbot}->{factoids}->{variables}->expand_action_arguments($context, $action, $context->{arguments}, $context->{nick}); } - $context->{arguments} = ''; - $context->{original_arguments} = ''; + $context->{arguments_processed} = 1; $context->{nickprefix_disabled} = 1; } else { # set nickprefix if args is a present nick and factoid action doesn't have $nick or $args @@ -388,7 +387,7 @@ sub handle_action($self, $context, $action) { unless ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'require_explicit_args')) { my $args = $context->{arguments}; - $command .= " $args" if length $args and not $context->{special}->{$context->{stack_depth}} eq 'code-factoid'; + $command .= " $args" if length $args && !$context->{arguments_processed} && $context->{special}->{$context->{stack_depth}} ne 'code-factoid'; $context->{arguments} = ''; } diff --git a/lib/PBot/Core/Factoids/Variables.pm b/lib/PBot/Core/Factoids/Variables.pm index 41e9c20b..b970f248 100644 --- a/lib/PBot/Core/Factoids/Variables.pm +++ b/lib/PBot/Core/Factoids/Variables.pm @@ -259,7 +259,7 @@ sub expand_action_arguments($self, $context, $action, $input = '', $nick = '') { $action = validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length')); $input = validate_string($input, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length')); - my @args = $self->{pbot}->{interpreter}->split_line($input); + my @args = $self->{pbot}->{interpreter}->split_line($input, preserve_escapes => 1); $action =~ s/\$arglen\b|\$\{arglen\}/scalar @args/eg; diff --git a/lib/PBot/Core/Interpreter.pm b/lib/PBot/Core/Interpreter.pm index d64251f6..1d437ca4 100644 --- a/lib/PBot/Core/Interpreter.pm +++ b/lib/PBot/Core/Interpreter.pm @@ -264,6 +264,7 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma delete $context->{special}; delete $context->{code}; delete $context->{lang}; + delete $context->{arguments_processed}; } # return number of commands processed @@ -274,7 +275,12 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma # takes a $context object containing contextual information about the # command such as the channel, nick, user, host, command, etc. sub interpret($self, $context) { + # resume processing new arguments + delete $context->{arguments_processed}; + + # ensure stack_depth is defined $context->{stack_depth} //= 0; + # log command invocation $self->{pbot}->{logger}->log("=== [$context->{interpret_depth} ($context->{stack_depth})] Got command: " . "($context->{from}) $context->{hostmask}: $context->{command}\n"); diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 097fb87d..090ef6b0 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4915, + BUILD_REVISION => 4916, BUILD_DATE => "2025-10-21", };