3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Factoids/FactoidCommands: properly preserve quotes when splitting arguments

This commit is contained in:
Pragmatic Software 2020-02-01 22:19:53 -08:00
parent 20159ad929
commit 5e0a3a7035
2 changed files with 9 additions and 10 deletions

View File

@ -57,7 +57,6 @@ sub new {
sub initialize { sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to FactoidCommands"); $self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to FactoidCommands");
$self->{pbot}->{registry}->add_default('text', 'general', 'module_repo', $conf{module_repo} // 'https://github.com/pragma-/pbot/blob/master/modules/'); $self->{pbot}->{registry}->add_default('text', 'general', 'module_repo', $conf{module_repo} // 'https://github.com/pragma-/pbot/blob/master/modules/');
@ -92,7 +91,7 @@ sub initialize {
sub call_factoid { sub call_factoid {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($chan, $keyword, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3); my ($chan, $keyword, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3, 0, 1);
if (not defined $chan or not defined $keyword) { if (not defined $chan or not defined $keyword) {
return "Usage: fact <channel> <keyword> [arguments]"; return "Usage: fact <channel> <keyword> [arguments]";
@ -178,7 +177,7 @@ sub find_factoid_with_optional_channel {
%opts = (%default_opts, %opts); %opts = (%default_opts, %opts);
my $arglist = $self->{pbot}->{interpreter}->make_args($arguments); my $arglist = $self->{pbot}->{interpreter}->make_args($arguments);
my ($from_chan, $from_trigger, $remaining_args) = $self->{pbot}->{interpreter}->split_args($arglist, 3); my ($from_chan, $from_trigger, $remaining_args) = $self->{pbot}->{interpreter}->split_args($arglist, 3, 0, 1);
if (not defined $from_chan or (not defined $from_chan and not defined $from_trigger)) { if (not defined $from_chan or (not defined $from_chan and not defined $from_trigger)) {
return "Usage: $command [channel] <keyword>" if not $opts{usage}; return "Usage: $command [channel] <keyword>" if not $opts{usage};
@ -200,7 +199,7 @@ sub find_factoid_with_optional_channel {
my $keyword = $from_chan; my $keyword = $from_chan;
$from_chan = $from; $from_chan = $from;
$from_trigger = $keyword; $from_trigger = $keyword;
(undef, $remaining_args) = $self->{pbot}->{interpreter}->split_args($arglist, 2); (undef, $remaining_args) = $self->{pbot}->{interpreter}->split_args($arglist, 2, 0, 1);
} }
} }
@ -828,7 +827,7 @@ sub factalias {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($chan, $alias, $command) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3); my ($chan, $alias, $command) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3, 0, 1);
if (defined $chan and not ($chan eq '.*' or $chan =~ m/^#/)) { if (defined $chan and not ($chan eq '.*' or $chan =~ m/^#/)) {
# $chan doesn't look like a channel, so shift everything to the right # $chan doesn't look like a channel, so shift everything to the right
@ -981,7 +980,7 @@ sub factadd {
} }
# and the text is the remaining arguments with quotes preserved # and the text is the remaining arguments with quotes preserved
($text) = $self->{pbot}->{interpreter}->split_args(\@arglist, 1); ($text) = $self->{pbot}->{interpreter}->split_args(\@arglist, 1, 0, 1);
} }
} }
@ -1557,13 +1556,13 @@ sub factchange {
$delim = $1; $delim = $1;
$channel = $args->[0]; $channel = $args->[0];
$keyword = $args->[1]; $keyword = $args->[1];
($sub) = $self->{pbot}->{interpreter}->split_args($args, 1, 2); ($sub) = $self->{pbot}->{interpreter}->split_args($args, 1, 2, 1);
$needs_disambig = 0; $needs_disambig = 0;
} elsif ($arg_count >= 2 and $args->[1] =~ m/^s([[:punct:]])/) { } elsif ($arg_count >= 2 and $args->[1] =~ m/^s([[:punct:]])/) {
$delim = $1; $delim = $1;
$keyword = $args->[0]; $keyword = $args->[0];
$channel = $from; $channel = $from;
($sub) = $self->{pbot}->{interpreter}->split_args($args, 1, 1); ($sub) = $self->{pbot}->{interpreter}->split_args($args, 1, 1, 1);
$needs_disambig = 1; $needs_disambig = 1;
} }

View File

@ -317,7 +317,7 @@ sub find_factoid {
$command = $1; $command = $1;
} }
my $arglist = $self->{pbot}->{interpreter}->make_args($command); my $arglist = $self->{pbot}->{interpreter}->make_args($command);
($keyword, $arguments) = $self->{pbot}->{interpreter}->split_args($arglist, 2); ($keyword, $arguments) = $self->{pbot}->{interpreter}->split_args($arglist, 2, 0, 1);
goto NEXT_DEPTH; goto NEXT_DEPTH;
} }
@ -347,7 +347,7 @@ sub find_factoid {
if ($opts{find_alias}) { if ($opts{find_alias}) {
my $command = $self->{factoids}->{hash}->{$channel}->{$trigger}->{action}; my $command = $self->{factoids}->{hash}->{$channel}->{$trigger}->{action};
my $arglist = $self->{pbot}->{interpreter}->make_args($command); my $arglist = $self->{pbot}->{interpreter}->make_args($command);
($keyword, $arguments) = $self->{pbot}->{interpreter}->split_args($arglist, 2); ($keyword, $arguments) = $self->{pbot}->{interpreter}->split_args($arglist, 2, 0, 1);
$string = $keyword . (length $arguments ? " $arguments" : ""); $string = $keyword . (length $arguments ? " $arguments" : "");
goto NEXT_DEPTH; goto NEXT_DEPTH;
} }