2010-03-22 08:33:44 +01:00
# File: AntiFlood.pm
2010-03-24 07:47:40 +01:00
# Author: pragma_
2010-03-17 07:36:54 +01:00
#
2014-05-13 12:15:52 +02:00
# Purpose: Tracks message and nickserv statistics to enforce anti-flooding and
# ban-evasion detection.
2013-10-26 04:39:54 +02:00
#
2014-05-13 12:15:52 +02:00
# The nickserv/ban-evasion stuff probably ought to be in BanTracker or some
# such suitable class.
2010-03-17 07:36:54 +01:00
package PBot::AntiFlood ;
use warnings ;
use strict ;
2010-06-18 06:17:30 +02:00
use feature 'switch' ;
2010-03-24 07:47:40 +01:00
use vars qw( $VERSION ) ;
$ VERSION = $ PBot:: PBot:: VERSION ;
2010-03-17 07:36:54 +01:00
2011-12-11 23:56:57 +01:00
use PBot::DualIndexHashObject ;
2011-01-25 00:56:55 +01:00
use PBot::LagChecker ;
2011-01-22 10:26:04 +01:00
use Time::HiRes qw( gettimeofday tv_interval ) ;
2010-06-27 07:36:58 +02:00
use Time::Duration ;
2010-03-22 08:33:44 +01:00
use Carp ( ) ;
sub new {
if ( ref ( $ _ [ 1 ] ) eq 'HASH' ) {
2014-05-13 12:15:52 +02:00
Carp:: croak ( "Options to " . __FILE__ . " should be key/value pairs, not hash reference" ) ;
2010-03-22 08:33:44 +01:00
}
2010-03-17 07:36:54 +01:00
2010-03-22 08:33:44 +01:00
my ( $ class , % conf ) = @ _ ;
2010-03-17 07:36:54 +01:00
2010-03-22 08:33:44 +01:00
my $ self = bless { } , $ class ;
$ self - > initialize ( % conf ) ;
return $ self ;
}
2010-03-17 07:36:54 +01:00
2010-03-22 08:33:44 +01:00
sub initialize {
my ( $ self , % conf ) = @ _ ;
2010-03-17 07:36:54 +01:00
2014-05-13 12:15:52 +02:00
$ self - > { pbot } = delete $ conf { pbot } // Carp:: croak ( "Missing pbot reference to " . __FILE__ ) ;
2010-03-22 08:33:44 +01:00
2014-05-13 12:15:52 +02:00
# flags for 'validated' field
$ self - > { NICKSERV_VALIDATED } = ( 1 << 0 ) ;
$ self - > { NEEDS_CHECKBAN } = ( 1 << 1 ) ;
2010-03-22 08:33:44 +01:00
2014-05-13 12:15:52 +02:00
$ self - > { ENTER_ABUSE_MAX_LINES } = 4 ;
2014-03-12 23:13:05 +01:00
$ self - > { ENTER_ABUSE_MAX_OFFENSES } = 3 ;
2014-05-13 12:15:52 +02:00
$ self - > { ENTER_ABUSE_MAX_SECONDS } = 20 ;
2014-03-12 23:13:05 +01:00
2014-05-13 12:15:52 +02:00
$ self - > { channels } = { } ; # per-channel statistics, e.g. for optimized tracking of last spoken nick for enter-abuse detection, etc
2010-03-23 19:24:02 +01:00
2014-05-13 12:15:52 +02:00
my $ filename = delete $ conf { banwhitelist_file } // $ self - > { pbot } - > { data_dir } . '/ban_whitelist' ;
2011-12-11 23:56:57 +01:00
$ self - > { ban_whitelist } = PBot::DualIndexHashObject - > new ( name = > 'BanWhitelist' , filename = > $ filename ) ;
$ self - > { ban_whitelist } - > load ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > timer - > register ( sub { $ self - > adjust_offenses } , 60 * 60 * 1 ) ;
2010-06-16 03:55:29 +02:00
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > commands - > register ( sub { return $ self - > unbanme ( @ _ ) } , "unbanme" , 0 ) ;
$ self - > { pbot } - > commands - > register ( sub { return $ self - > whitelist ( @ _ ) } , "whitelist" , 10 ) ;
2011-12-11 23:56:57 +01:00
}
sub ban_whitelisted {
2011-12-12 06:39:38 +01:00
my ( $ self , $ channel , $ mask ) = @ _ ;
$ channel = lc $ channel ;
$ mask = lc $ mask ;
2011-12-11 23:56:57 +01:00
2011-12-12 05:17:03 +01:00
$ self - > { pbot } - > logger - > log ( "whitelist check: $channel, $mask\n" ) ;
2013-09-13 23:48:19 +02:00
return ( exists $ self - > { ban_whitelist } - > hash - > { $ channel } - > { $ mask } and defined $ self - > { ban_whitelist } - > hash - > { $ channel } - > { $ mask } - > { ban_whitelisted } ) ? 1 : 0 ;
2011-12-11 23:56:57 +01:00
}
sub whitelist {
my ( $ self , $ from , $ nick , $ user , $ host , $ arguments ) = @ _ ;
$ arguments = lc $ arguments ;
my ( $ command , $ args ) = split / / , $ arguments , 2 ;
return "Usage: whitelist <command>, where commands are: list/show, add, remove" if not defined $ command ;
given ( $ command ) {
when ( $ _ eq "list" or $ _ eq "show" ) {
my $ text = "Ban whitelist:\n" ;
my $ entries = 0 ;
foreach my $ channel ( keys % { $ self - > { ban_whitelist } - > hash } ) {
$ text . = " $channel:\n" ;
foreach my $ mask ( keys % { $ self - > { ban_whitelist } - > hash - > { $ channel } } ) {
$ text . = " $mask,\n" ;
$ entries + + ;
}
}
$ text . = "none" if $ entries == 0 ;
return $ text ;
}
when ( "add" ) {
my ( $ channel , $ mask ) = split / / , $ args , 2 ;
return "Usage: whitelist add <channel> <mask>" if not defined $ channel or not defined $ mask ;
$ self - > { ban_whitelist } - > hash - > { $ channel } - > { $ mask } - > { ban_whitelisted } = 1 ;
$ self - > { ban_whitelist } - > hash - > { $ channel } - > { $ mask } - > { owner } = "$nick!$user\@$host" ;
$ self - > { ban_whitelist } - > hash - > { $ channel } - > { $ mask } - > { created_on } = gettimeofday ;
$ self - > { ban_whitelist } - > save ;
return "$mask whitelisted in channel $channel" ;
}
when ( "remove" ) {
my ( $ channel , $ mask ) = split / / , $ args , 2 ;
return "Usage: whitelist remove <channel> <mask>" if not defined $ channel or not defined $ mask ;
if ( not defined $ self - > { ban_whitelist } - > hash - > { $ channel } ) {
return "No whitelists for channel $channel" ;
}
if ( not defined $ self - > { ban_whitelist } - > hash - > { $ channel } - > { $ mask } ) {
return "No such whitelist $mask for channel $channel" ;
}
delete $ self - > { ban_whitelist } - > hash - > { $ channel } - > { $ mask } ;
delete $ self - > { ban_whitelist } - > hash - > { $ channel } if keys % { $ self - > { ban_whitelist } - > hash - > { $ channel } } == 0 ;
$ self - > { ban_whitelist } - > save ;
return "$mask whitelist removed from channel $channel" ;
}
default {
return "Unknown command '$command'; commands are: list/show, add, remove" ;
}
}
2010-03-22 08:33:44 +01:00
}
2010-03-17 07:36:54 +01:00
2014-05-13 12:15:52 +02:00
sub check_join_watch {
2010-06-19 21:19:56 +02:00
my ( $ self , $ account , $ channel , $ text , $ mode ) = @ _ ;
2010-06-21 05:18:39 +02:00
2014-05-13 12:15:52 +02:00
return if $ channel =~ /[@!]/ ; # ignore QUIT messages from nick!user@host channels
2010-06-19 21:19:56 +02:00
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'join_watch' ) ;
2010-06-21 05:18:39 +02:00
2014-05-13 12:15:52 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) {
2010-06-21 05:18:39 +02:00
if ( $ text =~ /^JOIN/ ) {
2014-05-13 12:15:52 +02:00
$ channel_data - > { join_watch } + + ;
$ self - > { pbot } - > logger - > log ( "Join watch incremented to $channel_data->{join_watch} for $account\n" ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2010-06-21 05:18:39 +02:00
} else {
# PART or QUIT
2014-05-13 12:15:52 +02:00
# check QUIT message for netsplits, and decrement joinwatch to allow a free rejoin
2010-06-21 05:18:39 +02:00
if ( $ text =~ /^QUIT .*\.net .*\.split/ ) {
2014-05-13 12:15:52 +02:00
if ( $ channel_data - > { join_watch } > 0 ) {
$ channel_data - > { join_watch } - - ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
2010-06-21 05:18:39 +02:00
}
2011-01-22 05:17:35 +01:00
# check QUIT message for Ping timeout or Excess Flood
elsif ( $ text =~ /^QUIT Ping timeout/ or $ text =~ /^QUIT Excess Flood/ ) {
2011-02-11 03:46:35 +01:00
# ignore these (used to treat aggressively)
2010-06-21 05:18:39 +02:00
} else {
# some other type of QUIT or PART
}
}
2014-05-13 12:15:52 +02:00
} elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) {
2010-06-21 05:18:39 +02:00
# reset joinwatch if they send a message
2014-05-13 12:15:52 +02:00
if ( $ channel_data - > { join_watch } > 0 ) {
$ channel_data - > { join_watch } = 0 ;
$ self - > { pbot } - > logger - > log ( "Join watch reset for $account\n" ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
2010-06-19 21:19:56 +02:00
}
}
2010-03-17 07:36:54 +01:00
sub check_flood {
2010-06-05 08:07:15 +02:00
my ( $ self , $ channel , $ nick , $ user , $ host , $ text , $ max_messages , $ max_time , $ mode ) = @ _ ;
2012-10-27 23:03:10 +02:00
$ channel = lc $ channel ;
2010-03-17 07:36:54 +01:00
2014-05-13 12:15:52 +02:00
my $ mask = "$nick!$user\@$host" ;
2012-10-27 23:03:10 +02:00
$ self - > { pbot } - > logger - > log ( sprintf ( "%-14s | %-65s | %s\n" , $ channel eq $ mask ? "QUIT" : $ channel , $ mask , $ text ) ) ;
2010-06-05 08:07:15 +02:00
2014-05-13 12:15:52 +02:00
my $ account = $ self - > { pbot } - > { messagehistory } - > get_message_account ( $ nick , $ user , $ host ) ;
2010-06-05 08:07:15 +02:00
2010-06-21 05:18:39 +02:00
# handle QUIT events
# (these events come from $channel nick!user@host, not a specific channel or nick,
2014-03-09 07:56:48 +01:00
# so they need to be dispatched to all channels the nick has been seen on)
2014-05-13 12:15:52 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } and $ text =~ /^QUIT/ ) {
my @ channels = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channels ( $ account ) ;
foreach my $ chan ( @ channels ) {
$ self - > check_join_watch ( $ account , $ chan , $ text , $ mode ) ;
2010-06-10 22:26:09 +02:00
}
2010-06-21 05:18:39 +02:00
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > devalidate_all_channels ( $ account ) ;
2011-02-11 03:46:35 +01:00
# don't do flood processing for QUIT events
2010-06-21 05:18:39 +02:00
return ;
2010-06-12 06:27:58 +02:00
}
2010-06-10 22:26:09 +02:00
2014-05-13 12:15:52 +02:00
$ self - > check_join_watch ( $ account , $ channel , $ text , $ mode ) ;
2010-06-21 05:18:39 +02:00
2013-10-22 20:57:08 +02:00
# do not do flood processing for bot messages
2014-03-12 23:13:05 +01:00
if ( $ nick eq $ self - > { pbot } - > botnick ) {
$ self - > { channels } - > { $ channel } - > { last_spoken_nick } = $ nick ;
return ;
}
2013-10-22 20:57:08 +02:00
2010-06-21 05:18:39 +02:00
# do not do flood processing if channel is not in bot's channel list or bot is not set as chanop for the channel
return if ( $ channel =~ /^#/ ) and ( not exists $ self - > { pbot } - > channels - > channels - > hash - > { $ channel } or $ self - > { pbot } - > channels - > channels - > hash - > { $ channel } { chanop } == 0 ) ;
2014-05-13 12:15:52 +02:00
if ( $ channel =~ /^#/ and $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } and $ text =~ /^PART/ ) {
2013-09-14 03:56:00 +02:00
# remove validation on PART so we check for ban-evasion when user returns at a later time
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'validated' ) ;
if ( $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
2013-09-14 03:56:00 +02:00
}
2010-06-12 09:48:01 +02:00
if ( $ max_messages > $ self - > { pbot } - > { MAX_NICK_MESSAGES } ) {
$ self - > { pbot } - > logger - > log ( "Warning: max_messages greater than MAX_NICK_MESSAGES; truncating.\n" ) ;
$ max_messages = $ self - > { pbot } - > { MAX_NICK_MESSAGES } ;
}
2013-07-28 12:31:12 +02:00
# check for ban evasion if channel begins with # (not private message) and hasn't yet been validated against ban evasion
2014-05-13 12:15:52 +02:00
if ( $ channel =~ m/^#/ and not $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'validated' ) - > { 'validated' } & $ self - > { NICKSERV_VALIDATED } ) {
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } and $ text =~ /^PART/ ) {
2013-07-28 16:12:57 +02:00
# don't check for evasion on PARTs
} else {
2014-03-09 08:15:50 +01:00
$ self - > { pbot } - > conn - > whois ( $ nick ) ;
2014-05-13 12:15:52 +02:00
$ self - > check_bans ( $ account , $ mask , $ channel ) ;
2013-07-28 16:12:57 +02:00
}
2013-07-28 12:31:12 +02:00
}
2014-05-13 12:15:52 +02:00
# do not do flood enforcement for this event if bot is lagging
if ( $ self - > { pbot } - > lagchecker - > lagging ) {
$ self - > { pbot } - > logger - > log ( "Disregarding enforcement of anti-flood due to lag: " . $ self - > { pbot } - > lagchecker - > lagstring . "\n" ) ;
return ;
}
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } and $ channel =~ m/^#/ ) {
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'enter_abuse' , 'enter_abuses' ) ;
2014-03-12 23:13:05 +01:00
if ( defined $ self - > { channels } - > { $ channel } - > { last_spoken_nick } and $ nick eq $ self - > { channels } - > { $ channel } - > { last_spoken_nick } ) {
2014-05-13 12:15:52 +02:00
my $ messages = $ self - > { pbot } - > { messagehistory } - > { database } - > get_recent_messages ( $ account , $ channel , 2 , $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) ;
if ( $ messages - > [ 1 ] - > { timestamp } - $ messages - > [ 0 ] - > { timestamp } <= $ self - > { ENTER_ABUSE_MAX_SECONDS } ) {
if ( + + $ channel_data - > { enter_abuse } >= $ self - > { ENTER_ABUSE_MAX_LINES } - 1 ) {
$ channel_data - > { enter_abuse } = $ self - > { ENTER_ABUSE_MAX_LINES } / 2 - 1 ;
if ( + + $ channel_data - > { enter_abuses } >= $ self - > { ENTER_ABUSE_MAX_OFFENSES } ) {
my $ offenses = $ channel_data - > { enter_abuses } - $ self - > { ENTER_ABUSE_MAX_OFFENSES } + 1 ;
2014-03-13 13:00:28 +01:00
my $ ban_length = $ offenses ** $ offenses * $ offenses * 30 ;
$ self - > { pbot } - > chanops - > ban_user_timed ( "*!$user\@$host" , $ channel , $ ban_length ) ;
$ ban_length = duration ( $ ban_length ) ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "$nick $channel enter abuse offense " . $ channel_data - > { enter_abuses } . " earned $ban_length ban\n" ) ;
2014-03-13 13:00:28 +01:00
$ self - > { pbot } - > conn - > privmsg ( $ nick , "You have been muted due to abusing the enter key. Please do not split your sentences over multiple messages. You will be allowed to speak again in $ban_length." ) ;
2014-04-19 12:38:16 +02:00
} else {
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "$nick $channel enter abuses counter incremented to " . $ channel_data - > { enter_abuses } . "\n" ) ;
2014-03-13 13:00:28 +01:00
}
2014-04-19 12:38:16 +02:00
} else {
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "$nick $channel enter abuse counter incremented to " . $ channel_data - > { enter_abuse } . "\n" ) ;
2014-03-12 23:13:05 +01:00
}
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2014-03-13 13:00:28 +01:00
} else {
2014-05-13 12:15:52 +02:00
if ( $ channel_data - > { enter_abuse } > 0 ) {
2014-04-19 12:38:16 +02:00
$ self - > { pbot } - > logger - > log ( "$nick $channel more than $self->{ENTER_ABUSE_MAX_SECONDS} seconds since last message, enter abuse counter reset\n" ) ;
2014-05-13 12:15:52 +02:00
$ channel_data - > { enter_abuse } = 0 ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
2014-03-12 23:13:05 +01:00
}
} else {
$ self - > { channels } - > { $ channel } - > { last_spoken_nick } = $ nick ;
2014-05-13 12:15:52 +02:00
if ( $ channel_data - > { enter_abuse } > 0 ) {
$ self - > { pbot } - > logger - > log ( "$nick $channel enter abuse counter reset\n" ) ;
$ channel_data - > { enter_abuse } = 0 ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
2014-03-12 23:13:05 +01:00
}
}
2014-05-13 12:15:52 +02:00
if ( $ max_messages > 0 and $ self - > { pbot } - > { messagehistory } - > { database } - > get_max_messages ( $ account , $ channel ) >= $ max_messages ) {
my $ msg ;
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) {
$ msg = $ self - > { pbot } - > { messagehistory } - > { database } - > recall_message_by_count ( $ account , $ channel , $ max_messages - 1 )
2011-02-11 03:46:35 +01:00
}
2014-05-13 12:15:52 +02:00
elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) {
my $ joins = $ self - > { pbot } - > { messagehistory } - > { database } - > get_recent_messages ( $ account , $ channel , $ max_messages , $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) ;
$ msg = $ joins - > [ 0 ] ;
2011-02-11 03:46:35 +01:00
}
else {
$ self - > { pbot } - > logger - > log ( "Unknown flood mode [$mode] ... aborting flood enforcement.\n" ) ;
return ;
2010-06-19 21:19:56 +02:00
}
2014-05-13 12:15:52 +02:00
my $ last = $ self - > { pbot } - > { messagehistory } - > { database } - > recall_message_by_count ( $ account , $ channel , 0 ) ;
$ self - > { pbot } - > logger - > log ( " msg: [$msg->{timestamp}] $msg->{msg}\n" ) ;
$ self - > { pbot } - > logger - > log ( "last: [$last->{timestamp}] $last->{msg}\n" ) ;
$ self - > { pbot } - > logger - > log ( "Comparing message timestamps $last->{timestamp} - $msg->{timestamp} = " . ( $ last - > { timestamp } - $ msg - > { timestamp } ) . " against max_time $max_time\n" ) ;
2010-06-05 08:07:15 +02:00
2014-05-13 12:15:52 +02:00
if ( $ last - > { timestamp } - $ msg - > { timestamp } <= $ max_time && not $ self - > { pbot } - > admins - > loggedin ( $ channel , "$nick!$user\@$host" ) ) {
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) {
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'offenses' , 'last_offense' , 'join_watch' ) ;
$ self - > { pbot } - > { logger } - > log ( "$account offenses $channel_data->{offenses}, join watch $channel_data->{join_watch}, max messages $max_messages\n" ) ;
if ( $ channel_data - > { join_watch } >= $ max_messages ) {
$ channel_data - > { offenses } + + ;
$ channel_data - > { last_offense } = gettimeofday ;
2010-06-18 06:15:28 +02:00
2014-05-13 12:15:52 +02:00
my $ timeout = ( 2 ** ( ( $ channel_data - > { offenses } + 2 ) < 10 ? $ channel_data - > { offenses } + 2 : 10 ) ) ;
2010-06-18 06:15:28 +02:00
my $ banmask = address_to_mask ( $ host ) ;
2010-06-16 03:55:29 +02:00
2014-03-12 23:13:05 +01:00
$ self - > { pbot } - > chanops - > ban_user_timed ( "*!$user\@$banmask\$##stop_join_flood" , $ channel , $ timeout * 60 * 60 ) ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "$nick!$user\@$banmask banned for $timeout hours due to join flooding (offense #" . $ channel_data - > { offenses } . ").\n" ) ;
2014-03-05 15:32:24 +01:00
$ self - > { pbot } - > conn - > privmsg ( $ nick , "You have been banned from $channel due to join flooding. If your connection issues have been fixed, or this was an accident, you may request an unban at any time by responding to this message with: unbanme $channel, otherwise you will be automatically unbanned in $timeout hours." ) ;
2014-05-13 12:15:52 +02:00
$ channel_data - > { join_watch } = $ max_messages - 2 ; # give them a chance to rejoin
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2010-06-12 06:27:58 +02:00
}
2014-05-13 12:15:52 +02:00
} elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) {
if ( $ channel =~ /^#/ ) { #channel flood (opposed to private message or otherwise)
# don't increment offenses again if already banned
return if $ self - > { pbot } - > chanops - > { unban_timeout } - > find_index ( $ channel , "*!$user\@$host" ) ;
2012-07-22 21:22:30 +02:00
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'offenses' , 'last_offense' ) ;
$ channel_data - > { offenses } + + ;
$ channel_data - > { last_offense } = gettimeofday ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
my $ length = $ channel_data - > { offenses } ** $ channel_data - > { offenses } * $ channel_data - > { offenses } * 30 ;
2011-02-11 03:46:35 +01:00
$ self - > { pbot } - > chanops - > ban_user_timed ( "*!$user\@$host" , $ channel , $ length ) ;
2014-03-12 23:13:05 +01:00
$ length = duration ( $ length ) ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "$nick $channel flood offense " . $ channel_data - > { offenses } . " earned $length ban\n" ) ;
2011-02-11 03:46:35 +01:00
$ self - > { pbot } - > conn - > privmsg ( $ nick , "You have been muted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in $length." ) ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2011-02-11 03:46:35 +01:00
}
else { # private message flood
2012-09-06 12:09:44 +02:00
return if exists $ { $ self - > { pbot } - > ignorelist - > { ignore_list } } { "$nick!$user\@$host" } { $ channel } ;
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'offenses' , 'last_offense' ) ;
$ channel_data - > { offenses } + + ;
$ channel_data - > { last_offense } = gettimeofday ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
my $ length = $ channel_data - > { offenses } ** $ channel_data - > { offenses } * $ channel_data - > { offenses } * 30 ;
2010-06-12 06:27:58 +02:00
$ self - > { pbot } - > { ignorelistcmds } - > ignore_user ( "" , "floodcontrol" , "" , "" , "$nick!$user\@$host $channel $length" ) ;
2014-03-12 23:13:05 +01:00
$ length = duration ( $ length ) ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "$nick msg flood offense " . $ channel_data - > { offenses } . " earned $length ignore\n" ) ;
2010-06-12 06:27:58 +02:00
$ self - > { pbot } - > conn - > privmsg ( $ nick , "You have used too many commands in too short a time period, you have been ignored for $length." ) ;
2010-03-17 07:36:54 +01:00
}
}
}
}
}
2010-06-16 03:55:29 +02:00
sub unbanme {
my ( $ self , $ from , $ nick , $ user , $ host , $ arguments ) = @ _ ;
2010-06-22 05:01:02 +02:00
my $ channel = lc $ arguments ;
2010-06-16 03:55:29 +02:00
2011-12-17 12:43:21 +01:00
if ( not defined $ arguments or not defined $ channel ) {
2010-06-18 13:12:55 +02:00
return "/msg $nick Usage: unbanme <channel>" ;
2010-06-16 03:55:29 +02:00
}
2013-11-17 18:05:20 +01:00
my $ banmask = address_to_mask ( $ host ) ;
2010-06-18 06:15:28 +02:00
2013-07-24 14:35:40 +02:00
my $ mask = "*!$user\@$banmask\$##stop_join_flood" ;
2010-06-16 03:55:29 +02:00
2013-07-24 14:35:40 +02:00
if ( not $ self - > { pbot } - > { chanops } - > { unban_timeout } - > find_index ( $ channel , $ mask ) ) {
2010-06-16 03:55:29 +02:00
return "/msg $nick There is no temporary ban set for $mask in channel $channel." ;
}
2014-05-13 12:15:52 +02:00
my $ message_account = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account ( $ nick , $ user , $ host ) ;
my @ nickserv_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > get_nickserv_accounts ( $ message_account ) ;
2011-12-17 12:43:21 +01:00
2014-05-13 12:15:52 +02:00
foreach my $ nickserv_account ( @ nickserv_accounts ) {
2014-03-10 04:50:02 +01:00
my $ baninfos = $ self - > { pbot } - > bantracker - > get_baninfo ( "$nick!$user\@$host" , $ channel , $ nickserv_account ) ;
if ( defined $ baninfos ) {
foreach my $ baninfo ( @$ baninfos ) {
if ( $ self - > ban_whitelisted ( $ baninfo - > { channel } , $ baninfo - > { banmask } ) ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [unbanme] $nick!$user\@$host banned as $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n" ) ;
} else {
if ( $ channel eq lc $ baninfo - > { channel } ) {
my $ mode = $ baninfo - > { type } eq "+b" ? "banned" : "quieted" ;
$ self - > { pbot } - > logger - > log ( "anti-flood: [unbanme] $nick!$user\@$host $mode as $baninfo->{banmask} in $baninfo->{channel} by $baninfo->{owner}, unbanme rejected\n" ) ;
return "/msg $nick You have been $mode as $baninfo->{banmask} by $baninfo->{owner}, unbanme will not work until it is removed." ;
}
2013-07-28 12:31:12 +02:00
}
2011-12-17 12:43:21 +01:00
}
}
}
2012-09-06 12:09:44 +02:00
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'offenses' ) ;
if ( $ channel_data - > { offenses } > 2 ) {
2012-09-06 12:09:44 +02:00
return "/msg $nick You may only use unbanme for the first two offenses. You will be automatically unbanned in a few hours, and your offense counter will decrement once every 24 hours." ;
}
2010-06-18 09:03:16 +02:00
$ self - > { pbot } - > chanops - > unban_user ( $ mask , $ channel ) ;
2010-06-16 03:55:29 +02:00
return "/msg $nick You have been unbanned from $channel." ;
}
2010-06-18 06:15:28 +02:00
sub address_to_mask {
my $ address = shift ;
my $ banmask ;
if ( $ address =~ m/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) {
my ( $ a , $ b , $ c , $ d ) = ( $ 1 , $ 2 , $ 3 , $ 4 ) ;
given ( $ a ) {
when ( $ _ <= 127 ) { $ banmask = "$a.*" ; }
when ( $ _ <= 191 ) { $ banmask = "$a.$b.*" ; }
default { $ banmask = "$a.$b.$c.*" ; }
}
} elsif ( $ address =~ m/[^.]+\.([^.]+\.[^.]+)$/ ) {
$ banmask = "*.$1" ;
} else {
$ banmask = $ address ;
}
return $ banmask ;
}
2013-09-13 23:48:19 +02:00
sub devalidate_accounts {
# remove validation on accounts in $channel that match a ban/quiet $mask
my ( $ self , $ mask , $ channel ) = @ _ ;
2014-05-13 12:15:52 +02:00
my @ message_accounts ;
$ self - > { pbot } - > logger - > log ( "Devalidating accounts for $mask in $channel\n" ) ;
2013-09-13 23:48:19 +02:00
if ( $ mask =~ m/^\$a:(.*)/ ) {
2014-05-13 12:15:52 +02:00
my $ ban_account = lc $ 1 ;
@ message_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_nickserv ( $ ban_account ) ;
2013-09-13 23:48:19 +02:00
} else {
2014-05-13 12:15:52 +02:00
@ message_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_mask ( $ mask ) ;
2013-09-13 23:48:19 +02:00
}
2014-05-13 12:15:52 +02:00
foreach my $ account ( @ message_accounts ) {
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'validated' ) ;
if ( defined $ channel_data and $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > logger - > log ( "Devalidating account $account\n" ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2013-09-13 23:48:19 +02:00
}
}
}
2011-12-17 12:43:21 +01:00
sub check_bans {
2014-05-13 12:15:52 +02:00
my ( $ self , $ message_account , $ mask , $ channel ) = @ _ ;
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] checking for bans on $mask in $channel\n" ) ;
2013-08-03 19:26:49 +02:00
2014-05-13 12:15:52 +02:00
my @ nickserv_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > get_nickserv_accounts ( $ message_account ) ;
my $ current_nickserv_account = $ self - > { pbot } - > { messagehistory } - > { database } - > get_current_nickserv_account ( $ message_account ) ;
2011-12-17 12:43:21 +01:00
2014-05-13 12:15:52 +02:00
if ( $ current_nickserv_account ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] current nickserv [$current_nickserv_account] found for $mask\n" ) ;
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
if ( $ channel_data - > { validated } & $ self - > { NEEDS_CHECKBAN } ) {
$ channel_data - > { validated } & = ~ $ self - > { NEEDS_CHECKBAN } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
2014-03-10 04:50:02 +01:00
}
2013-08-03 19:26:49 +02:00
} else {
# mark this account as needing check-bans when nickserv account is identified
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
if ( not $ channel_data - > { validated } & $ self - > { NEEDS_CHECKBAN } ) {
$ channel_data - > { validated } |= $ self - > { NEEDS_CHECKBAN } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
}
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] no account for $mask; marking for later validation\n" ) ;
2013-07-28 12:31:12 +02:00
}
2013-07-24 14:35:40 +02:00
2014-05-13 12:15:52 +02:00
my ( $ nick , $ host ) = $ mask =~ m/^([^!]+)![^@]+\@(.*)$/ ;
2013-07-28 12:31:12 +02:00
2014-05-13 12:15:52 +02:00
my $ hostmasks = $ self - > { pbot } - > { messagehistory } - > { database } - > get_hostmasks_for_channel ( $ channel ) ;
2011-12-17 12:43:21 +01:00
2014-05-13 12:15:52 +02:00
my ( $ do_not_validate , $ bans ) ;
foreach my $ hostmask ( @$ hostmasks ) {
my @ hostmask_nickserv_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > get_nickserv_accounts ( $ hostmask - > { id } ) ;
my $ check_ban = 0 ;
2013-08-03 19:26:49 +02:00
2014-05-13 12:15:52 +02:00
# check if nickserv accounts match
foreach my $ nickserv_account ( @ nickserv_accounts ) {
foreach my $ key ( @ hostmask_nickserv_accounts ) {
if ( $ key eq $ nickserv_account ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] nickserv account for $hostmask->{hostmask} matches $nickserv_account\n" ) ;
$ check_ban = 1 ;
goto CHECKBAN ;
2013-08-03 19:26:49 +02:00
}
}
2014-05-13 12:15:52 +02:00
}
2013-08-03 19:26:49 +02:00
2014-05-13 12:15:52 +02:00
# check if hosts match
my ( $ account_host ) = $ hostmask - > { hostmask } =~ m/\@(.*)$/ ;
if ( $ host eq $ account_host ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] host for $hostmask->{hostmask} matches $mask\n" ) ;
$ check_ban = 1 ;
goto CHECKBAN ;
}
2013-07-28 12:31:12 +02:00
2014-05-13 12:15:52 +02:00
# check if nicks match
my ( $ account_nick ) = $ hostmask - > { hostmask } =~ m/^([^!]+)/ ;
if ( $ nick eq $ account_nick ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] nick for $hostmask->{hostmask} matches $mask\n" ) ;
$ check_ban = 1 ;
goto CHECKBAN ;
}
CHECKBAN:
if ( $ check_ban ) {
if ( not @ hostmask_nickserv_accounts ) {
push @ hostmask_nickserv_accounts , - 1 ;
}
2014-03-10 04:50:02 +01:00
2014-05-13 12:15:52 +02:00
foreach my $ target_nickserv_account ( @ hostmask_nickserv_accounts ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] checking for bans in $channel on $hostmask->{hostmask} using $target_nickserv_account\n" ) ;
my $ baninfos = $ self - > { pbot } - > bantracker - > get_baninfo ( $ hostmask - > { hostmask } , $ channel , $ target_nickserv_account ) ;
if ( defined $ baninfos ) {
foreach my $ baninfo ( @$ baninfos ) {
if ( time - $ baninfo - > { when } < 5 ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] $mask evaded $baninfo->{banmask} in $baninfo->{channel}, but within 5 seconds of establishing ban; giving another chance\n" ) ;
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
if ( $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
}
$ do_not_validate = 1 ;
next ;
}
2014-03-10 04:50:02 +01:00
2014-05-13 12:15:52 +02:00
if ( $ self - > ban_whitelisted ( $ baninfo - > { channel } , $ baninfo - > { banmask } ) ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] $mask evaded $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n" ) ;
next ;
}
2014-03-10 04:50:02 +01:00
2014-05-13 12:15:52 +02:00
if ( $ baninfo - > { type } eq '+b' and $ baninfo - > { banmask } =~ m/!\*@\*$/ ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] Disregarding generic nick ban\n" ) ;
next ;
}
2014-03-10 04:50:02 +01:00
2014-05-13 12:15:52 +02:00
my $ banmask_regex = quotemeta $ baninfo - > { banmask } ;
$ banmask_regex =~ s/\\\*/.*/g ;
$ banmask_regex =~ s/\\\?/./g ;
2014-03-10 04:50:02 +01:00
2014-05-13 12:15:52 +02:00
if ( $ baninfo - > { type } eq '+q' and $ mask =~ /^$banmask_regex$/i ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] Hostmask ($mask) matches quiet banmask ($banmask_regex), disregarding\n" ) ;
next ;
}
2013-07-28 12:31:12 +02:00
2014-05-13 12:15:52 +02:00
my $ skip_quiet_nickserv_mask = 0 ;
foreach my $ nickserv_account ( @ nickserv_accounts ) {
if ( $ baninfo - > { type } eq '+q' and $ baninfo - > { banmask } =~ /^\$a:(.*)/ and lc $ 1 eq $ nickserv_account and $ nickserv_account eq $ current_nickserv_account ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] Hostmask ($mask) matches quiet on account ($nickserv_account), disregarding\n" ) ;
$ skip_quiet_nickserv_mask = 1 ;
} elsif ( $ baninfo - > { type } eq '+b' and $ baninfo - > { banmask } =~ /^\$a:(.*)/ and lc $ 1 eq $ nickserv_account ) {
$ skip_quiet_nickserv_mask = 0 ;
last ;
2014-03-10 04:50:02 +01:00
}
2014-05-13 12:15:52 +02:00
}
next if $ skip_quiet_nickserv_mask ;
2013-07-28 12:31:12 +02:00
2014-05-13 12:15:52 +02:00
if ( not defined $ bans ) {
$ bans = [] ;
2014-03-04 11:50:12 +01:00
}
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] Hostmask ($mask) matches $baninfo->{type} $baninfo->{banmask}, adding ban\n" ) ;
push @$ bans , $ baninfo ;
next ;
2013-07-28 12:31:12 +02:00
}
}
}
2011-12-17 12:43:21 +01:00
}
2013-07-28 12:31:12 +02:00
}
2011-12-17 12:43:21 +01:00
2013-07-28 12:31:12 +02:00
if ( defined $ bans ) {
2013-08-06 21:56:28 +02:00
$ mask =~ m/[^!]+!([^@]+)@(.*)/ ;
my $ banmask = "*!$1@" . address_to_mask ( $ 2 ) ;
2013-07-28 12:31:12 +02:00
foreach my $ baninfo ( @$ bans ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-bans] $mask evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}, banning $banmask\n" ) ;
2014-04-21 09:26:06 +02:00
my ( $ bannick ) = $ mask =~ m/^([^!]+)/ ;
$ self - > { pbot } - > chanops - > add_op_command ( $ baninfo - > { channel } , "kick $baninfo->{channel} $bannick Ban evasion" ) ;
2013-08-06 21:56:28 +02:00
$ self - > { pbot } - > chanops - > ban_user_timed ( $ banmask , $ baninfo - > { channel } , 60 * 60 * 12 ) ;
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
if ( $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
}
2013-07-28 12:31:12 +02:00
return ;
}
2011-12-17 12:43:21 +01:00
}
2013-07-28 12:31:12 +02:00
2014-05-13 12:15:52 +02:00
unless ( $ do_not_validate ) {
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
if ( not $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
$ channel_data - > { validated } |= $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
}
}
2011-12-17 12:43:21 +01:00
}
2011-02-11 03:46:35 +01:00
sub check_nickserv_accounts {
2014-03-10 07:28:56 +01:00
my ( $ self , $ nick , $ account , $ hostmask ) = @ _ ;
my $ force_validation = 0 ;
2014-05-13 12:15:52 +02:00
my $ message_account ;
$ self - > { pbot } - > logger - > log ( "Checking nickserv accounts for nick $nick with account $account and hostmask " . ( defined $ hostmask ? $ hostmask : 'undef' ) . "\n" ) ;
2011-02-11 03:46:35 +01:00
2014-03-10 04:50:02 +01:00
$ account = lc $ account ;
2014-03-10 07:28:56 +01:00
if ( not defined $ hostmask ) {
2014-05-13 12:15:52 +02:00
( $ message_account , $ hostmask ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_account_by_nick ( $ nick ) ;
if ( not defined $ message_account ) {
$ self - > { pbot } - > logger - > log ( "No message account found for nick $nick.\n" ) ;
( $ message_account ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_nickserv ( $ account ) ;
if ( not $ message_account ) {
$ self - > { pbot } - > logger - > log ( "No message account found for nickserv $account.\n" ) ;
return ;
2011-02-11 03:46:35 +01:00
}
}
2014-03-10 07:28:56 +01:00
} else {
2014-05-13 12:15:52 +02:00
( $ message_account ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_mask ( $ hostmask ) ;
if ( not $ message_account ) {
$ self - > { pbot } - > logger - > log ( "No message account found for hostmask $hostmask.\n" ) ;
return ;
}
2014-03-10 07:28:56 +01:00
$ force_validation = 1 ;
}
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "anti-flood: $message_account: setting nickserv account to [$account]\n" ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_nickserv_account ( $ message_account , $ account , scalar gettimeofday ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > set_current_nickserv_account ( $ message_account , $ account ) ;
2014-03-10 07:28:56 +01:00
# check to see if any channels need check-ban validation
2014-05-13 12:15:52 +02:00
$ hostmask = $ self - > { pbot } - > { messagehistory } - > { database } - > find_most_recent_hostmask ( $ message_account ) ;
my @ channels = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channels ( $ message_account ) ;
foreach my $ channel ( @ channels ) {
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
if ( $ force_validation or $ channel_data - > { validated } & $ self - > { NEEDS_CHECKBAN } ) {
$ self - > { pbot } - > logger - > log ( "anti-flood: [check-account] $nick [nickserv: $account] needs check-ban validation for $hostmask in $channel.\n" ) ;
$ self - > check_bans ( $ message_account , $ hostmask , $ channel ) ;
2014-03-10 07:28:56 +01:00
}
2011-02-11 03:46:35 +01:00
}
}
sub on_whoisaccount {
my ( $ self , $ conn , $ event ) = @ _ ;
my $ nick = $ event - > { args } [ 1 ] ;
2014-03-10 04:50:02 +01:00
my $ account = lc $ event - > { args } [ 2 ] ;
2011-02-11 03:46:35 +01:00
$ self - > { pbot } - > logger - > log ( "$nick is using NickServ account [$account]\n" ) ;
$ self - > check_nickserv_accounts ( $ nick , $ account ) ;
}
2014-05-13 12:15:52 +02:00
sub adjust_offenses {
2014-02-05 02:10:56 +01:00
my $ self = shift ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > logger - > log ( "Adjusting offenses . . .\n" ) ;
# decrease offenses counter if 24 hours have elapsed since latest offense
my $ channel_datas = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_datas_where_last_offense_older_than ( gettimeofday - 60 * 60 * 24 ) ;
foreach my $ channel_data ( @$ channel_datas ) {
if ( $ channel_data - > { offenses } > 0 ) {
my $ id = delete $ channel_data - > { id } ;
my $ channel = delete $ channel_data - > { channel } ;
$ channel_data - > { offenses } - - ;
$ channel_data - > { last_offense } = gettimeofday ;
$ self - > { pbot } - > logger - > log ( "[adjust-offenses] [$id][$channel] 24 hours since last offense/decrease -- decreasing offenses to $channel_data->{offenses}\n" ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ id , $ channel , $ channel_data ) ;
}
2014-02-05 02:10:56 +01:00
}
2014-05-13 12:15:52 +02:00
$ channel_datas = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_datas_with_enter_abuses ( ) ;
foreach my $ channel_data ( @$ channel_datas ) {
my $ id = delete $ channel_data - > { id } ;
my $ channel = delete $ channel_data - > { channel } ;
$ channel_data - > { enter_abuses } - - ;
$ self - > { pbot } - > logger - > log ( "[adjust-offenses] [$id][$channel] decreasing enter abuse offenses to $channel_data->{enter_abuses}\n" ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ id , $ channel , $ channel_data ) ;
}
2014-02-05 02:10:56 +01:00
}
2010-03-17 07:36:54 +01:00
1 ;