3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-10-22 02:57:27 +02:00

Interpreter: improve arguments processing

This commit is contained in:
Pragmatic Software 2025-10-21 12:50:09 -07:00
parent fce337e695
commit 94fbb81bda
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
4 changed files with 10 additions and 5 deletions

View File

@ -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} = '';
}

View File

@ -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;

View File

@ -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");

View File

@ -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",
};