mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 03:33:06 +01:00
Add strictnamespace registry key
This commit is contained in:
parent
dd520e0346
commit
81dcc3bee1
@ -175,7 +175,7 @@ sub find_index {
|
||||
}
|
||||
|
||||
sub levenshtein_matches {
|
||||
my ($self, $primary_index_key, $secondary_index_key, $distance) = @_;
|
||||
my ($self, $primary_index_key, $secondary_index_key, $distance, $strictnamespace) = @_;
|
||||
my $comma = '';
|
||||
my $result = "";
|
||||
|
||||
@ -207,6 +207,10 @@ sub levenshtein_matches {
|
||||
$header = "[$index1] ";
|
||||
$header = "[global channel] " if $header eq "[.*] ";
|
||||
|
||||
if ($strictnamespace) {
|
||||
next unless $index1 eq '.*' or $index1 eq $primary;
|
||||
}
|
||||
|
||||
foreach my $index2 (sort keys %{ $self->hash->{$index1} }) {
|
||||
my $distance_result = fastdistance($secondary_index_key, $index2);
|
||||
my $length = (length($secondary_index_key) > length($index2)) ? length $secondary_index_key : length $index2;
|
||||
|
@ -1356,12 +1356,12 @@ sub factfind {
|
||||
$regex .= ($arguments =~ m/\w$/) ? '\b' : '\B';
|
||||
|
||||
foreach my $chan (sort keys %{ $factoids }) {
|
||||
next if defined $channel and $chan !~ /$channel/i;
|
||||
next if defined $channel and $chan !~ /^$channel$/i;
|
||||
foreach my $trigger (sort keys %{ $factoids->{$chan} }) {
|
||||
if($factoids->{$chan}->{$trigger}->{type} eq 'text' or $factoids->{$chan}->{$trigger}->{type} eq 'regex') {
|
||||
if($factoids->{$chan}->{$trigger}->{owner} =~ /$owner/i
|
||||
&& $factoids->{$chan}->{$trigger}->{ref_user} =~ /$refby/i
|
||||
&& (exists $factoids->{$chan}->{$trigger}->{edited_by} ? $factoids->{$chan}->{$trigger}->{edited_by} =~ /$editby/i : 1)) {
|
||||
if($factoids->{$chan}->{$trigger}->{owner} =~ /^$owner$/i
|
||||
&& $factoids->{$chan}->{$trigger}->{ref_user} =~ /^$refby$/i
|
||||
&& (exists $factoids->{$chan}->{$trigger}->{edited_by} ? $factoids->{$chan}->{$trigger}->{edited_by} =~ /^$editby$/i : 1)) {
|
||||
next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$regex/i && $trigger !~ /$regex/i);
|
||||
|
||||
$i++;
|
||||
|
@ -792,6 +792,12 @@ sub interpreter {
|
||||
|
||||
$stuff->{from} = lc $stuff->{from};
|
||||
|
||||
my $strictnamespace = $self->{pbot}->{registry}->get_value($stuff->{from}, 'strictnamespace');
|
||||
|
||||
if (not defined $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 = $stuff->{keyword};
|
||||
#$self->{pbot}->{logger}->log("calling find_factoid in Factoids.pm, interpreter() to search for factoid against global/current\n");
|
||||
@ -849,7 +855,15 @@ sub interpreter {
|
||||
# if a non-nick argument was supplied, e.g., a sentence using the bot's nick, don't say anything
|
||||
return undef if length $stuff->{arguments} and not $self->{pbot}->{nicklist}->is_present($stuff->{from}, $stuff->{arguments});
|
||||
|
||||
my $matches = $self->{commands}->factfind($stuff->{from}, $stuff->{nick}, $stuff->{user}, $stuff->{host}, quotemeta $original_keyword);
|
||||
my $namespace = $strictnamespace ? $stuff->{from} : '.*';
|
||||
$namespace = '.*' if $namespace !~ /^#/;
|
||||
|
||||
my $namespace_regex = $namespace;
|
||||
if ($strictnamespace) {
|
||||
$namespace_regex = "(?:" . (quotemeta $namespace) . '|\\.\\*)';
|
||||
}
|
||||
|
||||
my $matches = $self->{commands}->factfind($stuff->{from}, $stuff->{nick}, $stuff->{user}, $stuff->{host}, quotemeta($original_keyword) . " -channel $namespace_regex");
|
||||
|
||||
# found factfind matches
|
||||
if ($matches !~ m/^No factoids/) {
|
||||
@ -857,8 +871,8 @@ sub interpreter {
|
||||
return "No such factoid '$original_keyword'; $matches";
|
||||
}
|
||||
|
||||
# otherwise find levenshtein closest matches from all channels
|
||||
$matches = $self->{factoids}->levenshtein_matches('.*', lc $original_keyword);
|
||||
# otherwise find levenshtein closest matches
|
||||
$matches = $self->{factoids}->levenshtein_matches($namespace, lc $original_keyword, 0.50, $strictnamespace);
|
||||
|
||||
# don't say anything if nothing similiar was found
|
||||
return undef if $matches eq 'none';
|
||||
|
Loading…
Reference in New Issue
Block a user