diff --git a/lib/PBot/Core/Factoids/Data.pm b/lib/PBot/Core/Factoids/Data.pm index b3680a5f..354e75d7 100644 --- a/lib/PBot/Core/Factoids/Data.pm +++ b/lib/PBot/Core/Factoids/Data.pm @@ -129,7 +129,7 @@ sub find { my $debug = 0; - $from = '.*' if not defined $from or $from !~ /^#/; + $from = '.*' if $from !~ /^#/; $from = lc $from; $keyword = lc $keyword; @@ -138,9 +138,12 @@ sub find { my @result = eval { my @results; my ($channel, $trigger); + for (my $depth = 0; $depth < 15; $depth++) { my $action; + my $string = $keyword . (length $arguments ? " $arguments" : ''); + $self->{pbot}->{logger}->log("string: $string\n") if $debug; if ($opts{exact_channel} and $opts{exact_trigger}) { @@ -187,6 +190,7 @@ sub find { CHECK_ALIAS: if ($opts{find_alias}) { $action = $self->{storage}->get_data($channel, $trigger, 'action') if not defined $action; + if ($action =~ m{^/call\s+(.*)$}ms) { my $command; if (length $arguments) { @@ -233,8 +237,11 @@ sub find { goto NEXT_DEPTH; } - if ($opts{exact_channel} == 1) { return ($channel, $trigger); } - else { push @results, [$channel, $trigger]; } + if ($opts{exact_channel} == 1) { + return ($channel, $trigger); + } else { + push @results, [$channel, $trigger]; + } } } } @@ -247,11 +254,13 @@ sub find { } if ($debug) { - if (not @results) { $self->{pbot}->{logger}->log("Factoids: find: no match\n"); } - else { + if (not @results) { + $self->{pbot}->{logger}->log("Factoids: find: no match\n"); + } else { $self->{pbot}->{logger}->log("Factoids: find: got results: " . (join ', ', map { "$_->[0] -> $_->[1]" } @results) . "\n"); } } + return @results; }; diff --git a/lib/PBot/Core/Interpreter.pm b/lib/PBot/Core/Interpreter.pm index 69c9429f..7b8426fb 100644 --- a/lib/PBot/Core/Interpreter.pm +++ b/lib/PBot/Core/Interpreter.pm @@ -416,20 +416,27 @@ sub interpret { # unescape any escaped pipes $arguments =~ s/\\\|\s*\{/| {/g; - my $from = $context->{from}; + # find factoid channel for dont-replace-pronouns metadata + my ($fact_channel, $fact_trigger); + my @factoids = $self->{pbot}->{factoids}->{data}->find($context->{from}, $keyword, exact_trigger => 1); - $from = '.*' unless $from =~ /^#/; + if (@factoids == 1) { + # found the factoid's channel + ($fact_channel, $fact_trigger) = $factoids[0]; + } else { + # more than one factoid found, normally we would prompt to disambiguate + # but in this case we'll just go ahead and assume global + ($fact_channel, $fact_trigger) = ('.*', $keyword); + } if ($self->{pbot}->{commands}->get_meta($keyword, 'dont-replace-pronouns') - or $self->{pbot}->{factoids}->{data}->get_meta($from, $keyword, 'dont-replace-pronouns')) + or $self->{pbot}->{factoids}->{data}->get_meta($fact_channel, $fact_trigger, 'dont-replace-pronouns')) { $context->{'dont-replace-pronouns'} = 1; } # replace pronouns like "i", "my", etc, with "nick", "nick's", etc if (not $context->{'dont-replace-pronouns'}) { - $self->{pbot}->{logger}->log("Replacing pronouns for $context->{from}.$keyword\n"); - # if command recipient is "me" then replace it with invoker's nick # e.g., "!tell me about date" or "!give me date", etc if (defined $context->{nickprefix} and lc $context->{nickprefix} eq 'me') { diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 380f4c1f..1a8927b2 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4325, + BUILD_REVISION => 4326, BUILD_DATE => "2021-07-28", };