3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-27 06:19:25 +01:00

Factoids: Fix expansions again

This commit is contained in:
Pragmatic Software 2018-04-01 15:03:04 -07:00
parent 8dfd015505
commit 8dc7db0857

View File

@ -407,13 +407,16 @@ sub expand_factoid_vars {
$root_keyword = lc $root_keyword; $root_keyword = lc $root_keyword;
my $debug = 0;
my $depth = 0; my $depth = 0;
while (1) { while (1) {
last if ++$depth >= 100; last if ++$depth >= 100;
my $offset = 0;
my $matches = 0; my $matches = 0;
$action =~ s/\$0/$root_keyword/g; $action =~ s/\$0/$root_keyword/g;
my $const_action = $action; my $const_action = $action;
my $offset = 0;
while ($const_action =~ /(\ba\s*|\ban\s*)?(?<!\\)\$([a-zA-Z0-9_:#]+)/gi) { while ($const_action =~ /(\ba\s*|\ban\s*)?(?<!\\)\$([a-zA-Z0-9_:#]+)/gi) {
my ($a, $v) = ($1, $2); my ($a, $v) = ($1, $2);
$a = '' if not defined $a; $a = '' if not defined $a;
@ -423,6 +426,8 @@ sub expand_factoid_vars {
next if @exclude && grep { $v =~ m/^\Q$_\E$/i } @exclude; next if @exclude && grep { $v =~ m/^\Q$_\E$/i } @exclude;
last if ++$depth >= 100; last if ++$depth >= 100;
$self->{pbot}->{logger}->log("v: [$v]\n") if $debug;
$matches++; $matches++;
my $modifier = ''; my $modifier = '';
@ -486,11 +491,23 @@ sub expand_factoid_vars {
} }
if (not length $mylist[$line]) { if (not length $mylist[$line]) {
$self->{pbot}->{logger}->log("No length!\n") if $debug;
substr($action, $offset) =~ s/\s*$a\$$v$modifier//; substr($action, $offset) =~ s/\s*$a\$$v$modifier//;
$offset += $-[0];
if ($debug) {
$self->{pbot}->{logger}->log("after: \$-[0]: $-[0], offset: $offset\n");
$self->{pbot}->{logger}->log("$action\n");
$self->{pbot}->{logger}->log((" " x $offset) . "^\n");
}
} else { } else {
substr($action, $offset) =~ s/$a\$$v$modifier/$mylist[$line]/; substr($action, $offset) =~ s/$a\$$v$modifier/$mylist[$line]/;
$offset += $-[0];
if ($debug) {
$self->{pbot}->{logger}->log("after: \$-[0]: $-[0], offset: $offset\n");
$self->{pbot}->{logger}->log("$action\n");
$self->{pbot}->{logger}->log((" " x $offset) . "^\n");
}
} }
$offset = $-[0];
} }
} }
last if $matches == 0; last if $matches == 0;