mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +01:00
Use proper lookbehind to prevent expansion of escaped variables
Remove adlib recursion loop since using $action already enables recursion since subsitution on $action resets the regex position
This commit is contained in:
parent
d2711956d6
commit
d1341ab4bd
@ -481,26 +481,24 @@ sub interpreter {
|
|||||||
$action =~ s/\$nick/$nick/g;
|
$action =~ s/\$nick/$nick/g;
|
||||||
$action =~ s/\$channel/$from/g;
|
$action =~ s/\$channel/$from/g;
|
||||||
|
|
||||||
my $adlib_recursion = 0;
|
while ($action =~ /(?<!\\)\$([a-zA-Z0-9_\-]+)/g) {
|
||||||
while ($action =~ /[^\\]\$([a-zA-Z0-9_\-]+)/ and ++$adlib_recursion < 5) {
|
my $v = $1;
|
||||||
while ($action =~ /[^\\]\$([a-zA-Z0-9_\-]+)/g) {
|
print "v = [$v]\n";
|
||||||
my $v = $1;
|
next if $v =~ m/^[0-9]+$/;
|
||||||
next if $v =~ m/^[0-9]+$/;
|
my ($var_chan, $var) = $self->find_factoid($from, $v, undef, 0, 1);
|
||||||
my ($var_chan, $var) = $self->find_factoid($from, $v, undef, 0, 1);
|
|
||||||
|
|
||||||
if(defined $var && $self->{factoids}->hash->{$var_chan}->{$var}->{type} eq 'text') {
|
if(defined $var && $self->{factoids}->hash->{$var_chan}->{$var}->{type} eq 'text') {
|
||||||
my $change = $self->{factoids}->hash->{$var_chan}->{$var}->{action};
|
my $change = $self->{factoids}->hash->{$var_chan}->{$var}->{action};
|
||||||
my @list = split(/\s|(".*?")/, $change);
|
my @list = split(/\s|(".*?")/, $change);
|
||||||
my @mylist;
|
my @mylist;
|
||||||
for(my $i = 0; $i <= $#list; $i++) {
|
for(my $i = 0; $i <= $#list; $i++) {
|
||||||
push @mylist, $list[$i] if $list[$i];
|
push @mylist, $list[$i] if $list[$i];
|
||||||
}
|
|
||||||
my $line = int(rand($#mylist + 1));
|
|
||||||
$mylist[$line] =~ s/"//g;
|
|
||||||
$action =~ s/\$$var/$mylist[$line]/;
|
|
||||||
} else {
|
|
||||||
$action =~ s/\$$var/$var/g;
|
|
||||||
}
|
}
|
||||||
|
my $line = int(rand($#mylist + 1));
|
||||||
|
$mylist[$line] =~ s/"//g;
|
||||||
|
$action =~ s/\$$var/$mylist[$line]/;
|
||||||
|
} else {
|
||||||
|
$action =~ s/\$$var/$var/g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user