3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-07 20:49:31 +01:00

Interpreter: find factoid channel for dont-replace-pronouns metadata

This commit is contained in:
Pragmatic Software 2021-07-28 18:05:14 -07:00
parent 12cedcd60e
commit 7c4c5847ab
3 changed files with 27 additions and 11 deletions

View File

@ -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;
};

View File

@ -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') {

View File

@ -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",
};