mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-02 07:24:09 +01:00
Factoids: fix behavior of factoid look-up
This commit is contained in:
parent
0023790fec
commit
a170b28a8b
@ -149,6 +149,7 @@ sub interpreter {
|
||||
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
|
||||
use Data::Dumper;
|
||||
$Data::Dumper::Sortkeys = 1;
|
||||
$Data::Dumper::Indent = 2;
|
||||
$self->{pbot}->{logger}->log("Commands::interpreter\n");
|
||||
$self->{pbot}->{logger}->log(Dumper $context);
|
||||
}
|
||||
|
@ -38,34 +38,8 @@ sub interpreter {
|
||||
}
|
||||
|
||||
my $strictnamespace = $self->{pbot}->{registry}->get_value($context->{from}, 'strictnamespace');
|
||||
|
||||
$strictnamespace //= $self->{pbot}->{registry}->get_value('general', 'strictnamespace');
|
||||
|
||||
# search for factoid against global channel and current channel (from unless ref_from is defined)
|
||||
my $original_keyword = $context->{keyword};
|
||||
|
||||
my ($channel, $keyword) =
|
||||
$self->{pbot}->{factoids}->{data}->find(
|
||||
$context->{ref_from} ? $context->{ref_from} : $context->{from},
|
||||
$context->{keyword},
|
||||
arguments => $context->{arguments},
|
||||
exact_channel => 1,
|
||||
);
|
||||
|
||||
# determine if we prepend [channel] to factoid output
|
||||
if (not defined $context->{ref_from}
|
||||
or $context->{ref_from} eq '.*'
|
||||
or $context->{ref_from} eq $context->{from})
|
||||
{
|
||||
$context->{ref_from} = '';
|
||||
}
|
||||
|
||||
if (defined $channel and not $channel eq '.*'
|
||||
and not $channel eq lc $context->{from})
|
||||
{
|
||||
$context->{ref_from} = $channel;
|
||||
}
|
||||
|
||||
# factoid > nick redirection
|
||||
my $nick_regex = $self->{pbot}->{registry}->get_value('regex', 'nickname');
|
||||
|
||||
@ -79,6 +53,31 @@ sub interpreter {
|
||||
}
|
||||
}
|
||||
|
||||
my $original_keyword = $context->{keyword};
|
||||
|
||||
# search for exact match of factoid
|
||||
my ($channel, $keyword) =
|
||||
$self->{pbot}->{factoids}->{data}->find(
|
||||
$context->{ref_from} ? $context->{ref_from} : $context->{from},
|
||||
$context->{keyword},
|
||||
arguments => $context->{arguments},
|
||||
exact_channel => 1,
|
||||
exact_trigger => 2,
|
||||
);
|
||||
|
||||
# determine if we prepend [channel] to factoid output
|
||||
if (defined $channel and $channel ne '.*'
|
||||
and $channel ne lc $context->{from})
|
||||
{
|
||||
$context->{ref_from} = $channel;
|
||||
}
|
||||
elsif (not defined $context->{ref_from}
|
||||
or $context->{ref_from} eq '.*'
|
||||
or $context->{ref_from} eq $context->{from})
|
||||
{
|
||||
$context->{ref_from} = '';
|
||||
}
|
||||
|
||||
# if no match found, attempt to call factoid from another channel if it exists there
|
||||
if (not defined $keyword) {
|
||||
my $string = "$original_keyword $context->{arguments}";
|
||||
@ -96,12 +95,9 @@ sub interpreter {
|
||||
}
|
||||
}
|
||||
|
||||
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : '';
|
||||
|
||||
# if multiple channels have this keyword, then ask user to disambiguate
|
||||
if (@chanlist> 1) {
|
||||
return if $context->{embedded};
|
||||
return $ref_from . "Factoid `$original_keyword` exists in " . join(', ', @chanlist) . "; use `fact <channel> $original_keyword` to choose one.";
|
||||
return "Factoid `$original_keyword` exists in " . join(', ', @chanlist) . "; use `fact <channel> $original_keyword` to choose one.";
|
||||
}
|
||||
|
||||
# if there's just one other channel that has this keyword, trigger that instance
|
||||
@ -113,8 +109,17 @@ sub interpreter {
|
||||
return $self->interpreter($context);
|
||||
}
|
||||
|
||||
# otherwise keyword hasn't been found, display similiar matches for all channels
|
||||
else {
|
||||
# keyword still not found, try regex factoids
|
||||
($channel, $keyword) =
|
||||
$self->{pbot}->{factoids}->{data}->find(
|
||||
$context->{ref_from} ? $context->{ref_from} : $context->{from},
|
||||
$context->{keyword},
|
||||
arguments => $context->{arguments},
|
||||
exact_channel => 1,
|
||||
);
|
||||
|
||||
# no such keyword, display similiar matches for all channels
|
||||
if (not defined $keyword) {
|
||||
my $namespace = $context->{from};
|
||||
$namespace = '.*' if $namespace !~ /^#/;
|
||||
|
||||
@ -126,7 +131,6 @@ sub interpreter {
|
||||
|
||||
# found factfind matches
|
||||
if ($matches !~ m/^No factoids/) {
|
||||
return if $context->{embedded};
|
||||
return "No such factoid '$original_keyword'; $matches";
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4550,
|
||||
BUILD_DATE => "2022-07-04",
|
||||
BUILD_REVISION => 4551,
|
||||
BUILD_DATE => "2022-07-05",
|
||||
};
|
||||
|
||||
sub initialize {}
|
||||
|
Loading…
Reference in New Issue
Block a user