3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

factchange: limit repetitions for /g modifier

This commit is contained in:
Pragmatic Software 2018-02-19 13:45:24 -08:00
parent 5688d09851
commit cc11bb4526

View File

@ -1475,10 +1475,42 @@ sub factchange {
my $action = $factoids->{$channel}->{$trigger}->{action}; my $action = $factoids->{$channel}->{$trigger}->{action};
my $changed; my $changed;
if ($modifier eq 'gi' or $modifier eq 'ig') { if ($modifier eq 'gi' or $modifier eq 'ig' or $modifier eq 'g') {
$changed = $action =~ s|$tochange|$changeto|gi; my @chars = ("A".."Z", "a".."z", "0".."9");
} elsif ($modifier eq 'g') { my $magic = '';
$changed = $action =~ s|$tochange|$changeto|g; $magic .= $chars[rand @chars] for 1..(10 * rand) + 10;
my $insensitive = index ($modifier, 'i') + 1;
my $count = 0;
my $max = 50;
while (1) {
if ($count == 0) {
if ($insensitive) {
$changed = $action =~ s|$tochange|$changeto$magic|i;
} else {
$changed = $action =~ s|$tochange|$changeto$magic|;
}
} else {
if ($insensitive) {
$changed = $action =~ s|$tochange|$1$changeto$magic|i;
} else {
$changed = $action =~ s|$tochange|$1$changeto$magic|;
}
}
if ($changed) {
$count++;
if ($count == $max) {
$action =~ s/$magic//;
last;
}
$tochange = "$magic(.*?)$tochange" if $count == 1;
} else {
$changed = $count;
$action =~ s/$magic// if $changed;
last;
}
}
} elsif ($modifier eq 'i') { } elsif ($modifier eq 'i') {
$changed = $action =~ s|$tochange|$changeto|i; $changed = $action =~ s|$tochange|$changeto|i;
} else { } else {