mirror of
https://github.com/pragma-/pbot.git
synced 2025-11-13 04:57:26 +01:00
Interpreter: improve arguments processing
This commit is contained in:
parent
fce337e695
commit
94fbb81bda
@ -338,8 +338,7 @@ sub handle_action($self, $context, $action) {
|
|||||||
$action = $self->{pbot}->{factoids}->{variables}->expand_action_arguments($context, $action, $context->{arguments}, $context->{nick});
|
$action = $self->{pbot}->{factoids}->{variables}->expand_action_arguments($context, $action, $context->{arguments}, $context->{nick});
|
||||||
}
|
}
|
||||||
|
|
||||||
$context->{arguments} = '';
|
$context->{arguments_processed} = 1;
|
||||||
$context->{original_arguments} = '';
|
|
||||||
$context->{nickprefix_disabled} = 1;
|
$context->{nickprefix_disabled} = 1;
|
||||||
} else {
|
} else {
|
||||||
# set nickprefix if args is a present nick and factoid action doesn't have $nick or $args
|
# 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')) {
|
unless ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'require_explicit_args')) {
|
||||||
my $args = $context->{arguments};
|
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} = '';
|
$context->{arguments} = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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'));
|
$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'));
|
$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;
|
$action =~ s/\$arglen\b|\$\{arglen\}/scalar @args/eg;
|
||||||
|
|
||||||
|
|||||||
@ -264,6 +264,7 @@ sub process_line($self, $from, $nick, $user, $host, $text, $tags = '', $is_comma
|
|||||||
delete $context->{special};
|
delete $context->{special};
|
||||||
delete $context->{code};
|
delete $context->{code};
|
||||||
delete $context->{lang};
|
delete $context->{lang};
|
||||||
|
delete $context->{arguments_processed};
|
||||||
}
|
}
|
||||||
|
|
||||||
# return number of commands 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
|
# takes a $context object containing contextual information about the
|
||||||
# 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) {
|
||||||
|
# resume processing new arguments
|
||||||
|
delete $context->{arguments_processed};
|
||||||
|
|
||||||
|
# ensure stack_depth is defined
|
||||||
$context->{stack_depth} //= 0;
|
$context->{stack_depth} //= 0;
|
||||||
|
|
||||||
# log command invocation
|
# log command invocation
|
||||||
$self->{pbot}->{logger}->log("=== [$context->{interpret_depth} ($context->{stack_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");
|
||||||
|
|||||||
@ -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 => 4915,
|
BUILD_REVISION => 4916,
|
||||||
BUILD_DATE => "2025-10-21",
|
BUILD_DATE => "2025-10-21",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user