3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 09:58:42 +02:00

FactoidCommands: factchange is now aware of quoted keywords; factchange and factshow now preserve spaces in output

This commit is contained in:
Pragmatic Software 2019-06-09 13:57:52 -07:00
parent 0f81584d8f
commit 22f899612b

View File

@ -1097,6 +1097,8 @@ sub factshow {
my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
$stuff->{preserve_whitespace} = 1;
my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
if (not defined $trig) { if (not defined $trig) {
@ -1460,27 +1462,37 @@ sub factfind {
sub factchange { sub factchange {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier); my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier);
$stuff->{preserve_whitespace} = 1;
my $needs_disambig; my $needs_disambig;
if (defined $arguments) { if (length $arguments) {
if ($arguments =~ /^([^\s]+)\s+s(.)/) { my $args = $stuff->{arglist};
$keyword = $1; my $sub;
$delim = $2;
$channel = $from; my $arg_count = $self->{pbot}->{interpreter}->arglist_size($args);
$needs_disambig = 1;
} elsif ($arguments =~ /^([^\s]+) ([^\s]+)\s+s(.)/) { if ($arg_count >= 3 and ($args->[0] =~ m/^#/ or $args->[0] eq '.*' or lc $args->[0] eq 'global') and ($args->[2] =~ m/^s([[:punct:]])/)) {
$channel = $1; $delim = $1;
$keyword = $2; $channel = $args->[0];
$delim = $3; $keyword = $args->[1];
($sub) = $self->{pbot}->{interpreter}->split_args($args, 1, 2);
$needs_disambig = 0; $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; $delim = quotemeta $delim;
if ($arguments =~ /\Q$keyword\E s$delim(.*?)$delim(.*)$delim(.*)$/) { if ($sub =~ /^s$delim(.*?)$delim(.*)$delim(.*)$/) {
$tochange = $1; $tochange = $1;
$changeto = $2; $changeto = $2;
$modifier = $3; $modifier = $3;