mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-20 10:59:29 +01:00
Repeatedly expand factoid variables for sub-expansions
This commit is contained in:
parent
51019a17ab
commit
6e0456940b
@ -367,58 +367,66 @@ sub find_factoid {
|
|||||||
sub expand_factoid_vars {
|
sub expand_factoid_vars {
|
||||||
my ($self, $from, $action) = @_;
|
my ($self, $from, $action) = @_;
|
||||||
|
|
||||||
while ($action =~ /(?<!\\)\$([a-zA-Z0-9_:\-#]+)/g) {
|
my $depth = 0;
|
||||||
my $v = $1;
|
while (1) {
|
||||||
next if $v =~ m/^(nick|channel|randomnick|args|arg\[.+\])$/; # don't override special variables
|
last if ++$depth >= 10;
|
||||||
|
my $matches = 0;
|
||||||
|
my $const_action = $action;
|
||||||
|
while ($const_action =~ /(?<!\\)\$([a-zA-Z0-9_:\-#]+)/g) {
|
||||||
|
my $v = $1;
|
||||||
|
next if $v =~ m/^(nick|channel|randomnick|args|arg\[.+\])$/; # don't override special variables
|
||||||
|
|
||||||
my $modifier = '';
|
$matches++;
|
||||||
if ($v =~ s/(:.*)$//) {
|
|
||||||
$modifier = $1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($modifier =~ m/^:(#[^:]+|global)/i) {
|
my $modifier = '';
|
||||||
$from = $1;
|
if ($v =~ s/(:.*)$//) {
|
||||||
$from = '.*' if lc $from eq 'global';
|
$modifier = $1;
|
||||||
}
|
|
||||||
|
|
||||||
my @factoids = $self->find_factoid($from, $v, undef, 2, 2);
|
|
||||||
next if not @factoids or not $factoids[0];
|
|
||||||
|
|
||||||
my ($var_chan, $var) = ($factoids[0]->[0], $factoids[0]->[1]);
|
|
||||||
|
|
||||||
if ($self->{factoids}->hash->{$var_chan}->{$var}->{type} eq 'text') {
|
|
||||||
my $change = $self->{factoids}->hash->{$var_chan}->{$var}->{action};
|
|
||||||
my @list = split(/\s|(".*?")/, $change);
|
|
||||||
my @mylist;
|
|
||||||
for (my $i = 0; $i <= $#list; $i++) {
|
|
||||||
push @mylist, $list[$i] if $list[$i];
|
|
||||||
}
|
}
|
||||||
my $line = int(rand($#mylist + 1));
|
|
||||||
$mylist[$line] =~ s/"//g;
|
|
||||||
|
|
||||||
foreach my $mod (split /:/, $modifier) {
|
if ($modifier =~ m/^:(#[^:]+|global)/i) {
|
||||||
given ($mod) {
|
$from = $1;
|
||||||
when ('uc') {
|
$from = '.*' if lc $from eq 'global';
|
||||||
$mylist[$line] = uc $mylist[$line];
|
}
|
||||||
}
|
|
||||||
when ('lc') {
|
my @factoids = $self->find_factoid($from, $v, undef, 2, 2);
|
||||||
$mylist[$line] = lc $mylist[$line];
|
next if not @factoids or not $factoids[0];
|
||||||
}
|
|
||||||
when ('ucfirst') {
|
my ($var_chan, $var) = ($factoids[0]->[0], $factoids[0]->[1]);
|
||||||
$mylist[$line] = ucfirst $mylist[$line];
|
|
||||||
}
|
if ($self->{factoids}->hash->{$var_chan}->{$var}->{type} eq 'text') {
|
||||||
when ('title') {
|
my $change = $self->{factoids}->hash->{$var_chan}->{$var}->{action};
|
||||||
$mylist[$line] = ucfirst lc $mylist[$line];
|
my @list = split(/\s|(".*?")/, $change);
|
||||||
|
my @mylist;
|
||||||
|
for (my $i = 0; $i <= $#list; $i++) {
|
||||||
|
push @mylist, $list[$i] if $list[$i];
|
||||||
|
}
|
||||||
|
my $line = int(rand($#mylist + 1));
|
||||||
|
$mylist[$line] =~ s/"//g;
|
||||||
|
|
||||||
|
foreach my $mod (split /:/, $modifier) {
|
||||||
|
given ($mod) {
|
||||||
|
when ('uc') {
|
||||||
|
$mylist[$line] = uc $mylist[$line];
|
||||||
|
}
|
||||||
|
when ('lc') {
|
||||||
|
$mylist[$line] = lc $mylist[$line];
|
||||||
|
}
|
||||||
|
when ('ucfirst') {
|
||||||
|
$mylist[$line] = ucfirst $mylist[$line];
|
||||||
|
}
|
||||||
|
when ('title') {
|
||||||
|
$mylist[$line] = ucfirst lc $mylist[$line];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$action =~ s/\$$var$modifier/$mylist[$line]/;
|
$action =~ s/\$$var$modifier/$mylist[$line]/;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
last if $matches == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$action =~ s/\\\$/\$/g;
|
$action =~ s/\\\$/\$/g;
|
||||||
|
|
||||||
return $action;
|
return $action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user