mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +01:00
Variables such as $0 can now be escaped, e.g. in factset
, etc
This commit is contained in:
parent
7645dce361
commit
beef46f120
@ -234,7 +234,6 @@ sub interpreter {
|
||||
|
||||
$context->{action} = $context->{arguments};
|
||||
$context->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($context);
|
||||
$context->{arguments} = $self->{pbot}->{factoids}->expand_special_vars($context->{from}, $context->{nick}, $context->{keyword}, $context->{arguments});
|
||||
delete $context->{action};
|
||||
|
||||
$context->{no_nickoverride} = 1;
|
||||
|
@ -436,16 +436,16 @@ sub escape_json {
|
||||
sub expand_special_vars {
|
||||
my ($self, $from, $nick, $root_keyword, $action) = @_;
|
||||
|
||||
$action =~ s/\$nick:json|\$\{nick:json\}/$self->escape_json($nick)/ge;
|
||||
$action =~ s/\$channel:json|\$\{channel:json\}/$self->escape_json($from)/ge;
|
||||
$action =~ s/(?<!\\)\$nick:json|(?<!\\)\$\{nick:json\}/$self->escape_json($nick)/ge;
|
||||
$action =~ s/(?<!\\)\$channel:json|(?<!\\)\$\{channel:json\}/$self->escape_json($from)/ge;
|
||||
$action =~
|
||||
s/\$randomnick:json|\$\{randomnick:json\}/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $self->escape_json($random) : $self->escape_json($nick)/ge;
|
||||
$action =~ s/\$0:json|\$\{0:json\}/$self->escape_json($root_keyword)/ge;
|
||||
s/(?<!\\)\$randomnick:json|(?<!\\)\$\{randomnick:json\}/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $self->escape_json($random) : $self->escape_json($nick)/ge;
|
||||
$action =~ s/(?<!\\)\$0:json|(?<!\\)\$\{0:json\}/$self->escape_json($root_keyword)/ge;
|
||||
|
||||
$action =~ s/\$nick|\$\{nick\}/$nick/g;
|
||||
$action =~ s/\$channel|\$\{channel\}/$from/g;
|
||||
$action =~ s/\$randomnick|\$\{randomnick\}/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge;
|
||||
$action =~ s/\$0\b|\$\{0\}\b/$root_keyword/g;
|
||||
$action =~ s/(?<!\\)\$nick|(?<!\\)\$\{nick\}/$nick/g;
|
||||
$action =~ s/(?<!\\)\$channel|(?<!\\)\$\{channel\}/$from/g;
|
||||
$action =~ s/(?<!\\)\$randomnick|(?<!\\)\$\{randomnick\}/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge;
|
||||
$action =~ s/(?<!\\)\$0\b|(?<!\\)\$\{0\}\b/$root_keyword/g;
|
||||
|
||||
return validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
|
||||
}
|
||||
@ -475,7 +475,7 @@ sub expand_factoid_vars {
|
||||
my $offset = 0;
|
||||
my $matches = 0;
|
||||
my $expansions = 0;
|
||||
$action =~ s/\$0/$root_keyword/g;
|
||||
$action =~ s/(?<!\\)\$0/$root_keyword/g;
|
||||
my $const_action = $action;
|
||||
|
||||
$self->{pbot}->{logger}->log("action: $const_action\n") if $debug;
|
||||
@ -609,10 +609,10 @@ sub expand_factoid_vars {
|
||||
last if $matches == 0 or $expansions == 0;
|
||||
}
|
||||
|
||||
$action =~ s/\\\$/\$/g;
|
||||
|
||||
unless (@exclude) { $action = $self->expand_special_vars($from, $nick, $root_keyword, $action); }
|
||||
|
||||
$action =~ s/\\\$/\$/g;
|
||||
|
||||
return validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
|
||||
}
|
||||
|
||||
@ -897,7 +897,7 @@ sub interpreter {
|
||||
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $context->{arguments} and $self->{factoids}->get_data($channel, $keyword, 'requires_arguments')) {
|
||||
$context->{alldone} = 1;
|
||||
my $usage = $self->{factoids}->get_data($channel, $keyword, 'usage');
|
||||
$usage =~ s/\$0|\$\{0\}/$trigger_name/g;
|
||||
$usage =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g;
|
||||
return $usage;
|
||||
}
|
||||
|
||||
@ -913,7 +913,7 @@ sub interpreter {
|
||||
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $context->{arguments}) {
|
||||
$context->{alldone} = 1;
|
||||
my $usage = $self->{factoids}->get_data($channel, $keyword, 'usage');
|
||||
$usage =~ s/\$0|\$\{0\}/$trigger_name/g;
|
||||
$usage =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g;
|
||||
return $usage;
|
||||
}
|
||||
|
||||
@ -992,7 +992,7 @@ sub handle_action {
|
||||
# no arguments supplied, replace $args with $nick/$tonick, etc
|
||||
if ($self->{factoids}->exists($channel, $keyword, 'usage')) {
|
||||
$action = "/say " . $self->{factoids}->get_data($channel, $keyword, 'usage');
|
||||
$action =~ s/\$0|\$\{0\}/$trigger_name/g;
|
||||
$action =~ s/(?<!\\)\$0|(?<!\\)\$\{0\}/$trigger_name/g;
|
||||
$context->{alldone} = 1;
|
||||
} else {
|
||||
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) { $action = $self->expand_action_arguments($action, undef, ''); }
|
||||
|
@ -81,10 +81,14 @@ sub launch_module {
|
||||
$context->{trigger} = $trigger;
|
||||
|
||||
my $module = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, 'action');
|
||||
$self->{pbot}->{logger}->log("("
|
||||
. (defined $context->{from} ? $context->{from} : "(undef)")
|
||||
. "): $context->{nick}!$context->{user}\@$context->{host}: Executing module [$context->{command}] $module $context->{arguments}\n");
|
||||
$context->{arguments} = $self->{pbot}->{factoids}->expand_special_vars($context->{from}, $context->{nick}, $context->{root_keyword}, $context->{arguments});
|
||||
$self->{pbot}->{logger}->log(
|
||||
"(" . (defined $context->{from} ? $context->{from} : "(undef)")
|
||||
. "): $context->{nick}!$context->{user}\@$context->{host}: Executing module [$context->{command}] $module $context->{arguments}\n"
|
||||
);
|
||||
|
||||
$context->{action} = $context->{arguments};
|
||||
$context->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($context);
|
||||
delete $context->{action};
|
||||
|
||||
my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir');
|
||||
if (not chdir $module_dir) {
|
||||
|
Loading…
Reference in New Issue
Block a user