3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 10:59:29 +01:00

Nick-floods are now once again detected

This commit is contained in:
Pragmatic Software 2016-12-04 22:00:50 -08:00
parent 4d2a89987b
commit c2a2debf3e
2 changed files with 49 additions and 14 deletions

View File

@ -373,8 +373,7 @@ sub check_flood {
my $channels; my $channels;
if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
$channels = $self->{pbot}->{nicklist}->get_channels($nick); $channels = $self->{pbot}->{nicklist}->get_channels($oldnick);
$self->{pbot}->{logger}->log("Nick changes for $ancestor: $self->{nickflood}->{$ancestor}->{changes}\n");
} else { } else {
$self->update_join_watch($account, $channel, $text, $mode); $self->update_join_watch($account, $channel, $text, $mode);
push @$channels, $channel; push @$channels, $channel;
@ -476,11 +475,12 @@ sub check_flood {
return; return;
} }
my $last = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} ? $ancestor : $account, $channel, 0); my $last;
if ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
#$self->{pbot}->{logger}->log(" msg: [$msg->{timestamp}] $msg->{msg}\n"); $last = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($ancestor, $channel, 0, undef, $nick);
#$self->{pbot}->{logger}->log("last: [$last->{timestamp}] $last->{msg}\n"); } else {
#$self->{pbot}->{logger}->log("Comparing message timestamps $last->{timestamp} - $msg->{timestamp} = " . ($last->{timestamp} - $msg->{timestamp}) . " against max_time $max_time\n"); $last = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($account, $channel, 0);
}
if ($last->{timestamp} - $msg->{timestamp} <= $max_time) { if ($last->{timestamp} - $msg->{timestamp} <= $max_time) {
if($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) { if($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) {

View File

@ -944,18 +944,53 @@ sub get_message_context {
} }
sub recall_message_by_count { sub recall_message_by_count {
my ($self, $id, $channel, $count, $ignore_command) = @_; my ($self, $id, $channel, $count, $ignore_command, $use_aliases) = @_;
my $messages; my $messages;
if(defined $id) { if(defined $id) {
$messages = eval { $messages = eval {
if (defined $use_aliases) {
my %akas = $self->get_also_known_as($use_aliases);
my %seen_id;
my $ids;
my $or = '';
foreach my $aka (keys %akas) {
next if $akas{$aka}->{type} == $self->{alias_type}->{WEAK};
next if $akas{$aka}->{nickchange} == 1;
next if exists $seen_id{$akas{$aka}->{id}};
$seen_id{$akas{$aka}->{id}} = 1;
$ids .= "${or}id = ?";
$or = ' OR ';
}
my $sql = "SELECT id, msg, mode, timestamp, channel FROM Messages WHERE ($ids) AND channel = ? ORDER BY timestamp DESC LIMIT 10 OFFSET ?";
my $sth = $self->{dbh}->prepare($sql);
my $param = 1;
%seen_id = ();
foreach my $aka (keys %akas) {
next if $akas{$aka}->{type} == $self->{alias_type}->{WEAK};
next if $akas{$aka}->{nickchange} == 1;
next if exists $seen_id{$akas{$aka}->{id}};
$seen_id{$akas{$aka}->{id}} = 1;
$sth->bind_param($param++, $akas{$aka}->{id});
}
$sth->bind_param($param++, $channel);
$sth->bind_param($param++, $count);
$sth->execute();
return $sth->fetchall_arrayref({});
} else {
my $sth = $self->{dbh}->prepare('SELECT id, msg, mode, timestamp, channel FROM Messages WHERE id = ? AND channel = ? ORDER BY timestamp DESC LIMIT 10 OFFSET ?'); my $sth = $self->{dbh}->prepare('SELECT id, msg, mode, timestamp, channel FROM Messages WHERE id = ? AND channel = ? ORDER BY timestamp DESC LIMIT 10 OFFSET ?');
$sth->bind_param(1, $id); $sth->bind_param(1, $id);
$sth->bind_param(2, $channel); $sth->bind_param(2, $channel);
$sth->bind_param(3, $count); $sth->bind_param(3, $count);
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref({}); return $sth->fetchall_arrayref({});
}
}; };
} else { } else {
$messages = eval { $messages = eval {