mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 23:39:24 +01:00
Interpreter: improve and optimize dehighlight_nicks()
This commit is contained in:
parent
864e6853ea
commit
1cadd1d87d
@ -877,17 +877,26 @@ sub dehighlight_nicks {
|
|||||||
return $line if $self->{pbot}->{registry}->get_value('general', 'no_dehighlight_nicks');
|
return $line if $self->{pbot}->{registry}->get_value('general', 'no_dehighlight_nicks');
|
||||||
my @nicks = $self->{pbot}->{nicklist}->get_nicks($channel);
|
my @nicks = $self->{pbot}->{nicklist}->get_nicks($channel);
|
||||||
return $line if not @nicks;
|
return $line if not @nicks;
|
||||||
foreach my $nick (@nicks) {
|
|
||||||
next if length $nick == 1;
|
my %nick_table = map { $_ => 1 } @nicks;
|
||||||
$nick = quotemeta $nick;
|
|
||||||
my $const_line = $line;
|
my @tokens = split / /, $line;
|
||||||
while ($const_line =~ m/(?<![^\W_\.\\])($nick)(?![^\W_:])/gi) {
|
|
||||||
my $match = $1;
|
foreach my $token (@tokens) {
|
||||||
$match =~ s/^(.)/$1\x{200b}/;
|
my $potential_nick = $token;
|
||||||
$line =~ s/$nick(?!:)/$match/i;
|
$potential_nick =~ s/^[^\w\[\]\<\>\-\\\^\{\}]+//;
|
||||||
}
|
$potential_nick =~ s/[^\w\[\]\<\>\-\\\^\{\}]+$//;
|
||||||
|
|
||||||
|
next if length $potential_nick == 1;
|
||||||
|
next if not $nick_table{$potential_nick};
|
||||||
|
|
||||||
|
my $dehighlighted_nick = $potential_nick;
|
||||||
|
$dehighlighted_nick =~ s/(.)/$1\x{200b}/;
|
||||||
|
|
||||||
|
$token =~ s/\Q$potential_nick\E(?!:)/$dehighlighted_nick/;
|
||||||
}
|
}
|
||||||
return $line;
|
|
||||||
|
return join ' ', @tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub output_result {
|
sub output_result {
|
||||||
|
Loading…
Reference in New Issue
Block a user