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

Add interpolate factoid metadata to control interpolation

This commit is contained in:
Pragmatic Software 2017-08-31 03:10:20 -07:00
parent d20ea65155
commit 678d82676d
2 changed files with 30 additions and 10 deletions

View File

@ -49,6 +49,7 @@ our %factoid_metadata_levels = (
nooverride => 10, nooverride => 10,
'effective-level' => 20, 'effective-level' => 20,
'persist-key' => 20, 'persist-key' => 20,
'interpolate' => 10,
# all others are allowed to be factset by anybody/default to level 0 # all others are allowed to be factset by anybody/default to level 0
); );

View File

@ -453,10 +453,12 @@ sub expand_factoid_vars {
$action =~ s/\\\$/\$/g; $action =~ s/\\\$/\$/g;
$action =~ s/\$nick/$nick/g; unless (@exclude) {
$action =~ s/\$channel/$from/g; $action =~ s/\$nick/$nick/g;
$action =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge; $action =~ s/\$channel/$from/g;
$action =~ s/\$0\b/$root_keyword/g; $action =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge;
$action =~ s/\$0\b/$root_keyword/g;
}
return $action; return $action;
} }
@ -547,11 +549,18 @@ sub execute_code_factoid {
my $ppi = PPI::Document->new(\$code, readonly => 1); my $ppi = PPI::Document->new(\$code, readonly => 1);
return "/say $nick: I don't feel so good." if not $ppi; return "/say $nick: I don't feel so good." if not $ppi;
my $vars = $ppi->find(sub { $_[1]->isa('PPI::Token::Symbol') }); my $vars = $ppi->find(sub { $_[1]->isa('PPI::Token::Symbol') });
use Data::Dumper;
print "got vars: ", Dumper $vars;
my @names = map { $_->symbol =~ /^[\%\@\$]+(.*)/; $1 } @$vars if $vars; my @names = map { $_->symbol =~ /^[\%\@\$]+(.*)/; $1 } @$vars if $vars;
my %uniq = map { $_, 1 } @names; my %uniq = map { $_, 1 } @names;
@names = keys %uniq; @names = keys %uniq;
$code = $self->expand_factoid_vars($from, $tonick ? $tonick : $nick, $root_keyword, $code, @names); unless ($self->{factoids}->hash->{$chan}->{$keyword}->{interpolate} eq '0') {
$code = $self->expand_factoid_vars($from, $tonick ? $tonick : $nick, $root_keyword, $code, @names);
}
my %signals = %SIG; my %signals = %SIG;
alarm 0; alarm 0;
@ -616,8 +625,10 @@ sub execute_code_factoid {
%SIG = %signals; %SIG = %signals;
alarm 1; alarm 1;
$action = $self->expand_factoid_vars($from, $tonick ? $tonick : $nick, $root_keyword, $action); unless ($self->{factoids}->hash->{$chan}->{$keyword}->{interpolate} eq '0') {
$action = $self->expand_action_arguments($action, $arguments, $tonick ? $tonick : $nick); $action = $self->expand_factoid_vars($from, $tonick ? $tonick : $nick, $root_keyword, $action);
$action = $self->expand_action_arguments($action, $arguments, $tonick ? $tonick : $nick);
}
return $action; return $action;
} }
@ -743,9 +754,15 @@ sub interpreter {
return "" if not length $action; return "" if not length $action;
unless ($self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} eq '0') {
$action = $self->expand_factoid_vars($from, $tonick ? $tonick : $nick, $root_keyword, $action);
}
if (length $arguments) { if (length $arguments) {
if ($action =~ m/\$args/ or $action =~ m/\$arg\[/) { if ($action =~ m/\$args/ or $action =~ m/\$arg\[/) {
$action = $self->expand_action_arguments($action, $arguments, defined $tonick ? $tonick : $nick); unless ($self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} eq '0') {
$action = $self->expand_action_arguments($action, $arguments, defined $tonick ? $tonick : $nick);
}
$arguments = ""; $arguments = "";
} else { } else {
if ($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'text') { if ($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'text') {
@ -816,8 +833,10 @@ sub interpreter {
return "/msg $nick $ref_from$keyword is currently disabled."; return "/msg $nick $ref_from$keyword is currently disabled.";
} }
$action = $self->expand_factoid_vars($from, $tonick ? $tonick : $nick, $root_keyword, $action); unless ($self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} eq '0') {
$action = $self->expand_action_arguments($action, $arguments, $tonick ? $tonick : $nick); $action = $self->expand_factoid_vars($from, $tonick ? $tonick : $nick, $root_keyword, $action);
$action = $self->expand_action_arguments($action, $arguments, $tonick ? $tonick : $nick);
}
if($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'module') { if($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'module') {
my $preserve_whitespace = $self->{factoids}->hash->{$channel}->{$keyword}->{preserve_whitespace}; my $preserve_whitespace = $self->{factoids}->hash->{$channel}->{$keyword}->{preserve_whitespace};