3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-23 04:19:27 +01:00

Message history improvements

This commit is contained in:
Pragmatic Software 2017-08-01 21:36:31 -07:00
parent b932fe73eb
commit 85d74f53b1

View File

@ -17,6 +17,7 @@ use Carp qw(shortmess);
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use Text::CSV; use Text::CSV;
use Text::Levenshtein qw/fastdistance/; use Text::Levenshtein qw/fastdistance/;
use Time::Duration;
sub new { sub new {
if(ref($_[1]) eq 'HASH') { if(ref($_[1]) eq 'HASH') {
@ -397,6 +398,22 @@ sub get_message_account {
my $orig_id = $self->get_message_account_id("$orig_nick!$user\@$host"); my $orig_id = $self->get_message_account_id("$orig_nick!$user\@$host");
my @orig_nickserv_accounts = $self->get_nickserv_accounts($orig_id); my @orig_nickserv_accounts = $self->get_nickserv_accounts($orig_id);
if ($nick =~ m/^Guest\d+$/) {
$sth = $self->{dbh}->prepare('SELECT id, hostmask, last_seen FROM Hostmasks WHERE user = ? and host = ? ORDER BY last_seen DESC');
$sth->execute($user, $host);
my $rows = $sth->fetchall_arrayref({});
if (defined $rows->[0]) {
my $link_type = $self->{alias_type}->{STRONG};
if (gettimeofday - $rows->[0]->{last_seen} > 60 * 60 * 48) {
$link_type = $self->{alias_type}->{WEAK};
$self->{pbot}->{logger}->log("Longer than 48 hours (" . concise duration(gettimeofday - $rows->[0]->{last_seen}) . ") for $rows->[0]->{hostmask} for $nick!$user\@$host, degrading to weak link\n");
}
$self->{pbot}->{logger}->log("6: nick-change guest match: $rows->[0]->{id}: $rows->[0]->{hostmask}\n");
$orig_nick = undef;
return ($rows, $link_type);
}
}
$sth = $self->{dbh}->prepare('SELECT id, hostmask, last_seen FROM Hostmasks WHERE nick = ? ORDER BY last_seen DESC'); $sth = $self->{dbh}->prepare('SELECT id, hostmask, last_seen FROM Hostmasks WHERE nick = ? ORDER BY last_seen DESC');
$sth->execute($nick); $sth->execute($nick);
my $rows = $sth->fetchall_arrayref({}); my $rows = $sth->fetchall_arrayref({});
@ -537,6 +554,22 @@ sub get_message_account {
} }
} }
# guests
if ($nick =~ m/^Guest\d+$/) {
$sth = $self->{dbh}->prepare('SELECT id, hostmask, last_seen FROM Hostmasks WHERE user = ? and host = ? ORDER BY last_seen DESC');
$sth->execute($user, $host);
my $rows = $sth->fetchall_arrayref({});
if (defined $rows->[0]) {
my $link_type = $self->{alias_type}->{STRONG};
if (gettimeofday - $rows->[0]->{last_seen} > 60 * 60 * 48) {
$link_type = $self->{alias_type}->{WEAK};
$self->{pbot}->{logger}->log("Longer than 48 hours (" . concise duration(gettimeofday - $rows->[0]->{last_seen}) . ") for $rows->[0]->{hostmask} for $nick!$user\@$host, degrading to weak link\n");
}
$self->{pbot}->{logger}->log("6: guest match: $rows->[0]->{id}: $rows->[0]->{hostmask}\n");
return ($rows, $link_type);
}
}
$sth = $self->{dbh}->prepare('SELECT id, hostmask, last_seen FROM Hostmasks WHERE nick = ? ORDER BY last_seen DESC'); $sth = $self->{dbh}->prepare('SELECT id, hostmask, last_seen FROM Hostmasks WHERE nick = ? ORDER BY last_seen DESC');
$sth->execute($nick); $sth->execute($nick);
my $rows = $sth->fetchall_arrayref({}); my $rows = $sth->fetchall_arrayref({});
@ -620,7 +653,7 @@ sub get_message_account {
if (defined $rows->[0] and gettimeofday - $rows->[0]->{last_seen} > 60 * 60 * 48) { if (defined $rows->[0] and gettimeofday - $rows->[0]->{last_seen} > 60 * 60 * 48) {
$link_type = $self->{alias_type}->{WEAK}; $link_type = $self->{alias_type}->{WEAK};
$self->{pbot}->{logger}->log("Longer than 48 hours (" . (gettimeofday - $rows->[0]->{last_seen}) . ") for $rows->[0]->{hostmask} for $nick!$user\@$host, degrading to weak link\n"); $self->{pbot}->{logger}->log("Longer than 48 hours (" . concise duration(gettimeofday - $rows->[0]->{last_seen}) . ") for $rows->[0]->{hostmask} for $nick!$user\@$host, degrading to weak link\n");
} }
=cut =cut
@ -639,7 +672,7 @@ sub get_message_account {
return $rows->[0]->{id} if $do_nothing; return $rows->[0]->{id} if $do_nothing;
if (defined $rows->[0]) { if (defined $rows->[0] and not defined $orig_nick) {
if ($link_type == $self->{alias_type}->{STRONG}) { if ($link_type == $self->{alias_type}->{STRONG}) {
my $host1 = lc "$nick!$user\@$host"; my $host1 = lc "$nick!$user\@$host";
my $host2 = lc $rows->[0]->{hostmask}; my $host2 = lc $rows->[0]->{hostmask};
@ -650,7 +683,6 @@ sub get_message_account {
if ($distance > 1 && ($nick1 !~ /^guest/ && $nick2 !~ /^guest/) && ($host1 !~ /unaffiliated/ || $host2 !~ /unaffiliated/)) { if ($distance > 1 && ($nick1 !~ /^guest/ && $nick2 !~ /^guest/) && ($host1 !~ /unaffiliated/ || $host2 !~ /unaffiliated/)) {
my $id = $rows->[0]->{id}; my $id = $rows->[0]->{id};
$self->{pbot}->{logger}->log("[$nick1][$nick2] $distance / $length\n"); $self->{pbot}->{logger}->log("[$nick1][$nick2] $distance / $length\n");
$self->{pbot}->{conn}->privmsg("pragma-", "Possible bogus account: ($id) $host1 vs ($id) $host2");
$self->{pbot}->{logger}->log("Possible bogus account: ($id) $host1 vs ($id) $host2\n"); $self->{pbot}->{logger}->log("Possible bogus account: ($id) $host1 vs ($id) $host2\n");
} }
} }
@ -1401,7 +1433,6 @@ sub link_alias {
my $length = (length $nick1 > length $nick2) ? length $nick1 : length $nick2; my $length = (length $nick1 > length $nick2) ? length $nick1 : length $nick2;
if ($distance > 1 && ($nick1 !~ /^guest/ && $nick2 !~ /^guest/) && ($host1 !~ /unaffiliated/ || $host2 !~ /unaffiliated/)) { if ($distance > 1 && ($nick1 !~ /^guest/ && $nick2 !~ /^guest/) && ($host1 !~ /unaffiliated/ || $host2 !~ /unaffiliated/)) {
$self->{pbot}->{logger}->log("[$nick1][$nick2] $distance / $length\n"); $self->{pbot}->{logger}->log("[$nick1][$nick2] $distance / $length\n");
$self->{pbot}->{conn}->privmsg("pragma-", "Possible bogus link: ($id) $host1 vs ($alias) $host2");
$self->{pbot}->{logger}->log("Possible bogus link: ($id) $host1 vs ($alias) $host2\n"); $self->{pbot}->{logger}->log("Possible bogus link: ($id) $host1 vs ($alias) $host2\n");
} }
} }