3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

Plugins/TypoSub: be more intelligent about replacing \1 and $1 thingies

This commit is contained in:
Pragmatic Software 2020-02-22 07:19:43 -08:00
parent 4d0f477140
commit 0835342246

View File

@ -74,15 +74,23 @@ sub on_public {
else { $result = "$nick thinks $target meant to say: "; }
my $text = $message->{msg};
if ($modifiers =~ m/g/) {
$text =~ s/$rx/$replacement/g;
$text =~ s{$rx}
{
my @stuff = ($1, $2, $3, $4, $5, $6, $7, $8, $9);
my $i;
map { ++$i; $text =~ s/[\$\\]$i/$_/g; } @stuff;
my $t = $replacement;
my $i = 0;
defined $_ // last, ++$i, $t =~ s|[\$\\]$i|$_|g for @stuff;
$t
}gxe;
} else {
$text =~ s/$rx/$replacement/;
$text =~ s{$rx}
{
my $i = 0;
my @stuff = ($1, $2, $3, $4, $5, $6, $7, $8, $9);
my $i;
map { ++$i; $text =~ s/[\$\\]$i/$_/g; } @stuff;
my $t = $replacement;
defined $_ // last, ++$i, $t =~ s|[\$\\]$i|$_|g for @stuff;
$t
}xe;
}
$event->{conn}->privmsg($channel, "$result$text");
return 0;