From 3b36634fa9221351ed3471bc01bd02364fa2e61a Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 27 Nov 2017 02:14:34 -0800 Subject: [PATCH] Fix factoid case duplication; enable me/my for pipes --- PBot/FactoidModuleLauncher.pm | 6 +++--- PBot/Factoids.pm | 23 +++++++++++------------ PBot/Interpreter.pm | 8 ++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/PBot/FactoidModuleLauncher.pm b/PBot/FactoidModuleLauncher.pm index 73b66a2d..26906bdb 100644 --- a/PBot/FactoidModuleLauncher.pm +++ b/PBot/FactoidModuleLauncher.pm @@ -78,7 +78,7 @@ sub execute_module { $stuff->{arguments} = $self->{pbot}->{factoids}->expand_special_vars($stuff->{from}, $stuff->{nick}, $stuff->{root_keyword}, $stuff->{arguments}); $stuff->{arguments} = quotemeta $stuff->{arguments}; - if ($stuff->{command} eq 'code-factoid' or exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{unquote_spaces}) { + if ($stuff->{special} eq 'code-factoid' or exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{unquote_spaces}) { $stuff->{arguments} =~ s/\\ / /g; } @@ -194,7 +194,7 @@ sub module_pipe_reader { return if $stuff->{result} =~ m/(?:no results)/i; } - if ($stuff->{command} eq 'code-factoid') { + if ($stuff->{special} eq 'code-factoid') { $stuff->{result} =~ s/\s+$//g; $self->{pbot}->{logger}->log("No text result from code-factoid.\n") and return if not length $stuff->{result}; @@ -209,7 +209,7 @@ sub module_pipe_reader { $self->{pbot}->{interpreter}->handle_result($stuff, $stuff->{result}); } else { # don't override nick if already set - if ($stuff->{command} ne 'code-factoid' and exists $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} and $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} != 0) { + if ($stuff->{special} ne 'code-factoid' and exists $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} and $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} != 0) { $stuff->{nickoverride} = $stuff->{nick}; } else { # extract nick-like thing from module result diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 88d55f53..0441ac6a 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -684,7 +684,6 @@ sub execute_code_factoid_using_safe { } sub execute_code_factoid_using_vm { -# my ($self, $nick, $user, $host, $from, $chan, $root_keyword, $keyword, $arguments, $lang, $code, $tonick) = @_; my ($self, $stuff) = @_; unless (exists $self->{factoids}->hash->{$stuff->{channel}}->{$stuff->{keyword}}->{interpolate} and $self->{factoids}->hash->{$stuff->{channel}}->{$stuff->{keyword}}->{interpolate} eq '0') { @@ -700,7 +699,7 @@ sub execute_code_factoid_using_vm { my $json = encode_json \%h; - $stuff->{command} = 'code-factoid'; + $stuff->{special} = 'code-factoid'; $stuff->{root_channel} = $stuff->{channel}; $stuff->{keyword} = 'compiler'; $stuff->{arguments} = $json; @@ -710,7 +709,8 @@ sub execute_code_factoid_using_vm { } sub execute_code_factoid { - return execute_code_factoid_using_vm(@_); + my ($self, @args) = @_; + return $self->execute_code_factoid_using_vm(@args); } sub interpreter { @@ -728,8 +728,7 @@ sub interpreter { return undef if not length $stuff->{keyword} or $stuff->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion'); $stuff->{from} = lc $stuff->{from}; - - #$self->{pbot}->{logger}->log("factoids interpreter: kw: [$keyword] args: [$arguments] from: [$from], ref_from: [" . (defined $ref_from ? $ref_from : "undef") . "]\n"); + $self->{special} = ""; # search for factoid against global channel and current channel (from unless ref_from is defined) my $original_keyword = $stuff->{keyword}; @@ -807,6 +806,11 @@ sub interpreter { } } + $stuff->{keyword} = $keyword; + $stuff->{trigger} = $keyword; + $stuff->{channel} = $channel; + $stuff->{original_keyword} = $original_keyword; + return undef if $stuff->{referenced} and $self->{factoids}->hash->{$channel}->{$keyword}->{noembed}; if (exists $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on}) { @@ -836,17 +840,12 @@ sub interpreter { if ($action =~ m{^/code\s+([^\s]+)\s+(.+)$}i) { my ($lang, $code) = ($1, $2); - $stuff->{channel} = $channel; $stuff->{lang} = $lang; $stuff->{code} = $code; $self->execute_code_factoid($stuff); return ""; } - $stuff->{channel} = $channel; - $stuff->{keyword} = $keyword; - $stuff->{original_keyword} = $original_keyword; - return $self->handle_action($stuff, $action); } @@ -862,7 +861,7 @@ sub handle_action { return "" if not length $action; - my ($channel, $keyword) = ($stuff->{channel}, $stuff->{keyword}); + my ($channel, $keyword) = ($stuff->{channel}, $stuff->{trigger}); unless (exists $self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} and $self->{factoids}->hash->{$channel}->{$keyword}->{interpolate} eq '0') { $action = $self->expand_factoid_vars($stuff->{from}, $stuff->{nick}, $stuff->{root_keyword}, $action); @@ -914,7 +913,7 @@ sub handle_action { $action = $self->expand_action_arguments($action, $stuff->{arguments}, $stuff->{nick}); } - return $action if $stuff->{command} eq 'code-factoid'; + return $action if $stuff->{special} eq 'code-factoid'; if ($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'module') { my $preserve_whitespace = $self->{factoids}->hash->{$channel}->{$keyword}->{preserve_whitespace}; diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index 64e72f17..5c5d0aa1 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -262,7 +262,7 @@ sub interpret { $stuff->{prepend} = '/say ' unless exists $self->{pipe}; - $stuff->{arguments} = $args; + $arguments = $args; $stuff->{pipe} = $pipe; $stuff->{pipe_rest} = $rest; $got_pipe = 1; @@ -273,7 +273,7 @@ sub interpret { $stuff->{nickoverride} = $stuff->{nick} if defined $stuff->{nickoverride} and lc $stuff->{nickoverride} eq 'me'; - if ((not exists $stuff->{pipe}) and $keyword !~ /^(?:factrem|forget|set|factdel|factadd|add|factfind|find|factshow|show|forget|factdel|factset|factchange|change|msg|tell|cc|eval|u|udict|ud|actiontrigger|urban|perl)$/) { + if ($keyword !~ /^(?:factrem|forget|set|factdel|factadd|add|factfind|find|factshow|show|forget|factdel|factset|factchange|change|msg|tell|cc|eval|u|udict|ud|actiontrigger|urban|perl)$/) { $keyword =~ s/(\w+)([?!.]+)$/$1/; $arguments =~ s/(?{nick}/gi if defined $arguments && $stuff->{interpret_depth} <= 2; $arguments =~ s/(?{nick}'s/gi if defined $arguments && $stuff->{interpret_depth} <= 2; @@ -300,12 +300,12 @@ sub interpret { return undef; } - $stuff->{keyword} = $keyword; if (not exists $stuff->{root_keyword}) { $stuff->{root_keyword} = $keyword; } - $stuff->{arguments} = $arguments unless $got_pipe; + $stuff->{keyword} = $keyword; + $stuff->{arguments} = $arguments; return $self->SUPER::execute_all($stuff); }