mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
Factoids: do not prepend $ref_from if pipe or subcmd exists; misc clean-ups
This commit is contained in:
parent
bd04feda81
commit
2efd91d382
@ -233,10 +233,8 @@ sub interpreter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unless ($self->get_meta($keyword, 'dont-replace-pronouns')) {
|
unless ($self->get_meta($keyword, 'dont-replace-pronouns')) {
|
||||||
$context->{action} = $context->{arguments};
|
$context->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($context, $context->{arguments});
|
||||||
$context->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($context);
|
|
||||||
$context->{arglist} = $self->{pbot}->{interpreter}->make_args($context->{arguments});
|
$context->{arglist} = $self->{pbot}->{interpreter}->make_args($context->{arguments});
|
||||||
delete $context->{action};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$context->{no_nickoverride} = 1;
|
$context->{no_nickoverride} = 1;
|
||||||
|
@ -425,32 +425,6 @@ sub find_factoid {
|
|||||||
return @result;
|
return @result;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub escape_json {
|
|
||||||
my ($self, $text) = @_;
|
|
||||||
my $thing = {thing => $text};
|
|
||||||
my $json = encode_json $thing;
|
|
||||||
$json =~ s/^{".*":"//;
|
|
||||||
$json =~ s/"}$//;
|
|
||||||
return $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/(?<!\\)\$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;
|
|
||||||
|
|
||||||
return validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
|
|
||||||
}
|
|
||||||
|
|
||||||
sub parse_expansion_modifiers {
|
sub parse_expansion_modifiers {
|
||||||
my ($self, $modifier) = @_;
|
my ($self, $modifier) = @_;
|
||||||
|
|
||||||
@ -994,6 +968,32 @@ sub expand_action_arguments {
|
|||||||
return $action;
|
return $action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub escape_json {
|
||||||
|
my ($self, $text) = @_;
|
||||||
|
my $thing = {thing => $text};
|
||||||
|
my $json = encode_json $thing;
|
||||||
|
$json =~ s/^{".*":"//;
|
||||||
|
$json =~ s/"}$//;
|
||||||
|
return $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/(?<!\\)\$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;
|
||||||
|
|
||||||
|
return validate_string($action, $self->{pbot}->{registry}->get_value('factoids', 'max_content_length'));
|
||||||
|
}
|
||||||
|
|
||||||
sub execute_code_factoid_using_vm {
|
sub execute_code_factoid_using_vm {
|
||||||
my ($self, $context) = @_;
|
my ($self, $context) = @_;
|
||||||
|
|
||||||
@ -1006,8 +1006,7 @@ sub execute_code_factoid_using_vm {
|
|||||||
$context->{no_nickoverride} = 0;
|
$context->{no_nickoverride} = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$context->{action} = $context->{code};
|
$context->{code} = $self->expand_factoid_vars($context, $context->{code});
|
||||||
$context->{code} = $self->expand_factoid_vars($context);
|
|
||||||
|
|
||||||
if ($self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'allow_empty_args')) {
|
if ($self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'allow_empty_args')) {
|
||||||
$context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, '');
|
$context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, '');
|
||||||
@ -1246,7 +1245,12 @@ sub handle_action {
|
|||||||
|
|
||||||
my ($channel, $keyword) = ($context->{channel}, $context->{trigger});
|
my ($channel, $keyword) = ($context->{channel}, $context->{trigger});
|
||||||
my ($channel_name, $trigger_name) = ($context->{channel_name}, $context->{trigger_name});
|
my ($channel_name, $trigger_name) = ($context->{channel_name}, $context->{trigger_name});
|
||||||
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
|
|
||||||
|
my $ref_from = '';
|
||||||
|
|
||||||
|
unless ($context->{pipe} or $context->{subcmd}) {
|
||||||
|
$ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : '';
|
||||||
|
}
|
||||||
|
|
||||||
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') {
|
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') {
|
||||||
my ($root_channel, $root_keyword) =
|
my ($root_channel, $root_keyword) =
|
||||||
@ -1258,8 +1262,7 @@ sub handle_action {
|
|||||||
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
|
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
|
||||||
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
|
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
|
||||||
}
|
}
|
||||||
$context->{action} = $action;
|
$action = $self->expand_factoid_vars($context, $action);
|
||||||
$action = $self->expand_factoid_vars($context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length $context->{arguments}) {
|
if (length $context->{arguments}) {
|
||||||
@ -1345,18 +1348,23 @@ sub handle_action {
|
|||||||
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') {
|
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') {
|
||||||
my ($root_channel, $root_keyword) =
|
my ($root_channel, $root_keyword) =
|
||||||
$self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1);
|
$self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1);
|
||||||
|
|
||||||
if (not defined $root_channel or not defined $root_keyword) {
|
if (not defined $root_channel or not defined $root_keyword) {
|
||||||
$root_channel = $channel;
|
$root_channel = $channel;
|
||||||
$root_keyword = $keyword;
|
$root_keyword = $keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
|
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
|
||||||
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
|
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
|
||||||
}
|
}
|
||||||
$context->{action} = $action;
|
|
||||||
$action = $self->expand_factoid_vars($context);
|
|
||||||
|
|
||||||
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) { $action = $self->expand_action_arguments($action, $context->{arguments}, ''); }
|
$action = $self->expand_factoid_vars($context, $action);
|
||||||
else { $action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick}); }
|
|
||||||
|
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) {
|
||||||
|
$action = $self->expand_action_arguments($action, $context->{arguments}, '');
|
||||||
|
} else {
|
||||||
|
$action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $action if $context->{special} eq 'code-factoid';
|
return $action if $context->{special} eq 'code-factoid';
|
||||||
@ -1370,8 +1378,12 @@ sub handle_action {
|
|||||||
$context->{root_channel} = $channel;
|
$context->{root_channel} = $channel;
|
||||||
|
|
||||||
my $result = $self->{pbot}->{modules}->execute_module($context);
|
my $result = $self->{pbot}->{modules}->execute_module($context);
|
||||||
if (length $result) { return $ref_from . $result; }
|
|
||||||
else { return ""; }
|
if (length $result) {
|
||||||
|
return $ref_from . $result;
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
} elsif ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'text') {
|
} elsif ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'text') {
|
||||||
# Don't allow user-custom /msg factoids, unless factoid triggered by admin
|
# Don't allow user-custom /msg factoids, unless factoid triggered by admin
|
||||||
if ($action =~ m/^\/msg/i) {
|
if ($action =~ m/^\/msg/i) {
|
||||||
|
@ -86,9 +86,7 @@ sub launch_module {
|
|||||||
. "): $context->{nick}!$context->{user}\@$context->{host}: Executing module [$context->{command}] $module $context->{arguments}\n"
|
. "): $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, $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');
|
my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir');
|
||||||
if (not chdir $module_dir) {
|
if (not chdir $module_dir) {
|
||||||
|
Loading…
Reference in New Issue
Block a user