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

Pre-expand factoid variables in code-factoids

This commit is contained in:
Pragmatic Software 2017-08-25 15:32:28 -07:00
parent fad64381a4
commit 8cae7a0847

View File

@ -22,6 +22,7 @@ use Carp ();
use POSIX qw(strftime);
use Text::ParseWords;
use PPI;
use Safe;
use PBot::PBot qw($VERSION);
@ -368,7 +369,7 @@ sub find_factoid {
}
sub expand_factoid_vars {
my ($self, $from, $action) = @_;
my ($self, $from, $action, @exclude) = @_;
my $depth = 0;
while (1) {
@ -378,6 +379,7 @@ sub expand_factoid_vars {
while ($const_action =~ /(?<!\\)\$([a-zA-Z0-9_:\-#\[\]]+)/g) {
my $v = $1;
next if $v =~ m/^(nick|channel|randomnick|args|arg\[.+\]):?$/i; # don't override special variables
next if @exclude && grep { $v =~ m/^$_$/i } @exclude;
$matches++;
@ -625,6 +627,12 @@ sub interpreter {
if ($action =~ m/^\{\s*(.*)\s*\}$/) {
my $code = $1;
my $ppi = PPI::Document->new(\$code, readonly => 1);
my $vars = $ppi->find(sub { $_[1]->isa('PPI::Token::Symbol') });
my @names = map { $_->symbol =~ /^[\%\@\$]+(.*)/; $1 } @$vars if $vars;
$code = $self->expand_factoid_vars($from, $code, @names);
my %signals = %SIG;
alarm 0;