From 22f899612b802616d392c22e9fc2940a676e6678 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 9 Jun 2019 13:57:52 -0700 Subject: [PATCH] FactoidCommands: factchange is now aware of quoted keywords; factchange and factshow now preserve spaces in output --- PBot/FactoidCommands.pm | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index 5a169eca..5616dce8 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -1097,6 +1097,8 @@ sub factshow { my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; + $stuff->{preserve_whitespace} = 1; + my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); if (not defined $trig) { @@ -1460,27 +1462,37 @@ sub factfind { sub factchange { my $self = shift; - my ($from, $nick, $user, $host, $arguments) = @_; + my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier); + $stuff->{preserve_whitespace} = 1; + my $needs_disambig; - if (defined $arguments) { - if ($arguments =~ /^([^\s]+)\s+s(.)/) { - $keyword = $1; - $delim = $2; - $channel = $from; - $needs_disambig = 1; - } elsif ($arguments =~ /^([^\s]+) ([^\s]+)\s+s(.)/) { - $channel = $1; - $keyword = $2; - $delim = $3; + if (length $arguments) { + my $args = $stuff->{arglist}; + my $sub; + + my $arg_count = $self->{pbot}->{interpreter}->arglist_size($args); + + if ($arg_count >= 3 and ($args->[0] =~ m/^#/ or $args->[0] eq '.*' or lc $args->[0] eq 'global') and ($args->[2] =~ m/^s([[:punct:]])/)) { + $delim = $1; + $channel = $args->[0]; + $keyword = $args->[1]; + ($sub) = $self->{pbot}->{interpreter}->split_args($args, 1, 2); $needs_disambig = 0; + } elsif ($arg_count >= 2 and $args->[1] =~ m/^s([[:punct:]])/) { + $delim = $1; + $keyword = $args->[0]; + $channel = $from; + ($sub) = $self->{pbot}->{interpreter}->split_args($args, 1, 1); + $needs_disambig = 1; } + $delim = quotemeta $delim; - if ($arguments =~ /\Q$keyword\E s$delim(.*?)$delim(.*)$delim(.*)$/) { + if ($sub =~ /^s$delim(.*?)$delim(.*)$delim(.*)$/) { $tochange = $1; $changeto = $2; $modifier = $3;