From ca36ee00cdbf01ac2480a46a6ec5a072c6a4647b Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 13 Dec 2016 15:42:50 -0800 Subject: [PATCH] Ignore nicks that have not had activity in the last 1 hour when looking for similar nicks; add nicks to NickList when updating activity if they do not exist yet --- PBot/NickList.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PBot/NickList.pm b/PBot/NickList.pm index 68f47518..94320e62 100644 --- a/PBot/NickList.pm +++ b/PBot/NickList.pm @@ -59,11 +59,15 @@ sub dumpnicks { sub update_timestamp { my ($self, $channel, $nick) = @_; + my $orig_nick = $nick; $channel = lc $channel; $nick = lc $nick; if (exists $self->{nicklist}->{$channel} and exists $self->{nicklist}->{$channel}->{$nick}) { $self->{nicklist}->{$channel}->{$nick}->{timestamp} = gettimeofday; + } else { + $self->{pbot}->{logger}->log("Adding nick '$orig_nick' to channel '$channel'\n") if $self->{pbot}->{registry}->get_value('nicklist', 'debug'); + $self->{nicklist}->{$channel}->{$nick} = { nick => $orig_nick, timestamp => gettimeofday }; } } @@ -131,7 +135,9 @@ sub is_present_similar { my $percentage = $self->{pbot}->{registry}->get_value('interpreter', 'nick_similarity'); $percentage = 0.20 if not defined $percentage; + my $now = gettimeofday; foreach my $person (sort { $self->{nicklist}->{$channel}->{$b}->{timestamp} <=> $self->{nicklist}->{$channel}->{$a}->{timestamp} } keys $self->{nicklist}->{$channel}) { + return 0 if $now - $self->{nicklist}->{$channel}->{$person}->{timestamp} > 3600; # 1 hour my $distance = fastdistance($nick, $person); my $length = length $nick > length $person ? length $nick : length $person;