diff --git a/PBot/AntiFlood.pm b/PBot/AntiFlood.pm index 39078ec5..220356ff 100644 --- a/PBot/AntiFlood.pm +++ b/PBot/AntiFlood.pm @@ -28,7 +28,7 @@ use Text::CSV; use Carp (); sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference"); } @@ -236,11 +236,11 @@ sub whitelist { my ($channel, $mask) = $self->{pbot}->{interpreter}->split_args($arglist, 2); return "Usage: whitelist remove " if not defined $channel or not defined $mask; - if(not defined $self->{whitelist}->hash->{$channel}) { + if (not defined $self->{whitelist}->hash->{$channel}) { return "No whitelists for channel $channel"; } - if(not defined $self->{whitelist}->hash->{$channel}->{$mask}) { + if (not defined $self->{whitelist}->hash->{$channel}->{$mask}) { return "No such whitelist $mask for channel $channel"; } @@ -262,29 +262,29 @@ sub update_join_watch { my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'join_watch'); - if($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) { + if ($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) { $channel_data->{join_watch}++; $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); - } elsif($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { + } elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { # PART or QUIT # check QUIT message for netsplits, and decrement joinwatch to allow a free rejoin - if($text =~ /^QUIT .*\.net .*\.split/) { - if($channel_data->{join_watch} > 0) { + if ($text =~ /^QUIT .*\.net .*\.split/) { + if ($channel_data->{join_watch} > 0) { $channel_data->{join_watch}--; $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); } } # check QUIT message for Ping timeout or Excess Flood - elsif($text =~ /^QUIT Excess Flood/ or $text =~ /^QUIT Max SendQ exceeded/ or $text =~ /^QUIT Ping timeout/) { + elsif ($text =~ /^QUIT Excess Flood/ or $text =~ /^QUIT Max SendQ exceeded/ or $text =~ /^QUIT Ping timeout/) { # treat these as an extra join so they're snagged more quickly since these usually will keep flooding $channel_data->{join_watch}++; $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); } else { # some other type of QUIT or PART } - } elsif($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) { + } elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) { # reset joinwatch if they send a message - if($channel_data->{join_watch} > 0) { + if ($channel_data->{join_watch} > 0) { $channel_data->{join_watch} = 0; $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); } @@ -329,7 +329,7 @@ sub check_flood { $self->{pbot}->{messagehistory}->{database}->update_hostmask_data($mask, { last_seen => scalar gettimeofday }); - if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { + if ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { $self->{pbot}->{logger}->log(sprintf("%-18s | %-65s | %s\n", "NICKCHANGE", $mask, $text)); my ($newnick) = $text =~ m/NICKCHANGE (.*)/; @@ -341,7 +341,7 @@ sub check_flood { } # do not do flood processing for bot messages - if($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { + if ($nick eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { $self->{channels}->{$channel}->{last_spoken_nick} = $nick; return; } @@ -362,7 +362,7 @@ sub check_flood { # handle QUIT events # (these events come from $channel nick!user@host, not a specific channel or nick, # so they need to be dispatched to all channels the nick has been seen on) - if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE} and $text =~ /^QUIT/) { + if ($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE} and $text =~ /^QUIT/) { my $channels = $self->{pbot}->{nicklist}->get_channels($nick); foreach my $chan (@$channels) { next if $chan !~ m/^#/; @@ -382,7 +382,7 @@ sub check_flood { my $channels; - if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { + if ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { $channels = $self->{pbot}->{nicklist}->get_channels($oldnick); } else { $self->update_join_watch($account, $channel, $text, $mode); @@ -394,31 +394,31 @@ sub check_flood { # do not do flood processing if channel is not in bot's channel list or bot is not set as chanop for the channel next if $channel =~ /^#/ and not $self->{pbot}->{chanops}->can_gain_ops($channel); - if($channel =~ /^#/ and $mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { + if ($channel =~ /^#/ and $mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { # remove validation on PART or KICK so we check for ban-evasion when user returns at a later time my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated'); - if($channel_data->{validated} & $self->{NICKSERV_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); } next; } - if($self->whitelisted($channel, "$nick!$user\@$host", 'antiflood')) { + if ($self->whitelisted($channel, "$nick!$user\@$host", 'antiflood')) { next; } - if($max_messages > $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages')) { + if ($max_messages > $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages')) { $self->{pbot}->{logger}->log("Warning: max_messages greater than max_messages limit; truncating.\n"); $max_messages = $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages'); } # check for ban evasion if channel begins with # (not private message) and hasn't yet been validated against ban evasion - if($channel =~ m/^#/) { + if ($channel =~ m/^#/) { my $validated = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated')->{'validated'}; if ($validated & $self->{NEEDS_CHECKBAN} or not $validated & $self->{NICKSERV_VALIDATED}) { - if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { + if ($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { # don't check for evasion on PART/KICK } elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { if (not exists $self->{whois_pending}->{$nick}) { @@ -444,7 +444,7 @@ sub check_flood { } # do not do flood enforcement for this event if bot is lagging - if($self->{pbot}->{lagchecker}->lagging) { + if ($self->{pbot}->{lagchecker}->lagging) { $self->{pbot}->{logger}->log("Disregarding enforcement of anti-flood due to lag: " . $self->{pbot}->{lagchecker}->lagstring . "\n"); $self->{channels}->{$channel}->{last_spoken_nick} = $nick; return; @@ -463,20 +463,20 @@ sub check_flood { } # check for chat/join/private message flooding - if($max_messages > 0 and $self->{pbot}->{messagehistory}->{database}->get_max_messages($account, $channel, $mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} ? $nick : undef) >= $max_messages) { + if ($max_messages > 0 and $self->{pbot}->{messagehistory}->{database}->get_max_messages($account, $channel, $mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} ? $nick : undef) >= $max_messages) { my $msg; - if($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) { + if ($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) { $msg = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($account, $channel, $max_messages - 1) } - elsif($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) { + 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]; } - elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { + elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { my $nickchanges = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($ancestor, $channel, $max_messages, $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}, $nick); $msg = $nickchanges->[0]; } - elsif($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { + elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { # no flood checks to be done for departure events next; } @@ -493,14 +493,14 @@ sub check_flood { } if ($last->{timestamp} - $msg->{timestamp} <= $max_time) { - if($mode == $self->{pbot}->{messagehistory}->{MSG_JOIN}) { + 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) { + if ($channel_data->{join_watch} >= $max_messages) { $channel_data->{offenses}++; $channel_data->{last_offense} = gettimeofday; - if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { + if ($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { my $timeout = $self->{pbot}->{registry}->get_array_value('antiflood', 'join_flood_punishment', $channel_data->{offenses} - 1); my $duration = duration($timeout); my $banmask = address_to_mask($host); @@ -516,8 +516,8 @@ sub check_flood { $channel_data->{join_watch} = $max_messages - 2; # give them a chance to rejoin $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); } - } elsif($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) { - if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise) + } 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 if ($self->{pbot}->{chanops}->has_ban_timeout($channel, "*!$user\@" . address_to_mask($host))) { $self->{pbot}->{logger}->log("$nick $channel flood offense disregarded due to existing ban\n"); @@ -529,7 +529,7 @@ sub check_flood { $channel_data->{last_offense} = gettimeofday; $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); - if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { + if ($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'chat_flood_punishment', $channel_data->{offenses} - 1); $self->{pbot}->{chanops}->ban_user_timed("*!$user\@" . address_to_mask($host), $channel, $length); @@ -557,7 +557,7 @@ sub check_flood { $self->{pbot}->{conn}->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length."); } next; - } elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} and $self->{nickflood}->{$ancestor}->{changes} >= $max_messages) { + } elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} and $self->{nickflood}->{$ancestor}->{changes} >= $max_messages) { next if $channel !~ /^#/; ($nick) = $text =~ m/NICKCHANGE (.*)/; @@ -565,7 +565,7 @@ sub check_flood { $self->{nickflood}->{$ancestor}->{changes} = $max_messages - 2; # allow 1 more change (to go back to original nick) $self->{nickflood}->{$ancestor}->{timestamp} = gettimeofday; - if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { + if ($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'nick_flood_punishment', $self->{nickflood}->{$ancestor}->{offenses} - 1); $self->{pbot}->{chanops}->ban_user_timed("*!$user\@" . address_to_mask($host), $channel, $length); $length = duration($length); @@ -577,12 +577,12 @@ sub check_flood { } # check for enter abuse - if($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT} and $channel =~ m/^#/) { + 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', 'offenses'); my $other_offenses = delete $channel_data->{offenses}; my $debug_enter_abuse = $self->{pbot}->{registry}->get_value('antiflood', 'debug_enter_abuse'); - if(defined $self->{channels}->{$channel}->{last_spoken_nick} and $nick eq $self->{channels}->{$channel}->{last_spoken_nick}) { + if (defined $self->{channels}->{$channel}->{last_spoken_nick} and $nick eq $self->{channels}->{$channel}->{last_spoken_nick}) { my $messages = $self->{pbot}->{messagehistory}->{database}->get_recent_messages($account, $channel, 2, $self->{pbot}->{messagehistory}->{MSG_CHAT}); my $enter_abuse_threshold = $self->{pbot}->{registry}->get_value($channel, 'enter_abuse_threshold'); @@ -593,12 +593,12 @@ sub check_flood { $enter_abuse_time_threshold = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_time_threshold') if not defined $enter_abuse_time_threshold; $enter_abuse_max_offenses = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_max_offenses') if not defined $enter_abuse_max_offenses; - if($messages->[1]->{timestamp} - $messages->[0]->{timestamp} <= $enter_abuse_time_threshold) { - if(++$channel_data->{enter_abuse} >= $enter_abuse_threshold - 1) { + if ($messages->[1]->{timestamp} - $messages->[0]->{timestamp} <= $enter_abuse_time_threshold) { + if (++$channel_data->{enter_abuse} >= $enter_abuse_threshold - 1) { $channel_data->{enter_abuse} = $enter_abuse_threshold / 2 - 1; $channel_data->{enter_abuses}++; - if($channel_data->{enter_abuses} >= $enter_abuse_max_offenses) { - if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { + if ($channel_data->{enter_abuses} >= $enter_abuse_max_offenses) { + if ($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { if ($self->{pbot}->{chanops}->has_ban_timeout($channel, "*!$user\@" . address_to_mask($host))) { $self->{pbot}->{logger}->log("$nick $channel enter abuse offense disregarded due to existing ban\n"); next; @@ -617,7 +617,7 @@ sub check_flood { } else { $self->{pbot}->{logger}->log("$nick $channel enter abuses counter incremented to " . $channel_data->{enter_abuses} . "\n") if $debug_enter_abuse; if ($channel_data->{enter_abuses} == $enter_abuse_max_offenses - 1 && $channel_data->{enter_abuse} == $enter_abuse_threshold / 2 - 1) { - if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { + if ($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { $self->{pbot}->{conn}->privmsg($channel, "$nick: Please stop abusing the enter key. Feel free to type longer messages and to take a moment to think of anything else to say before you hit that enter key."); } } @@ -627,7 +627,7 @@ sub check_flood { } $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); } else { - if($channel_data->{enter_abuse} > 0) { + if ($channel_data->{enter_abuse} > 0) { $self->{pbot}->{logger}->log("$nick $channel more than $enter_abuse_time_threshold seconds since last message, enter abuse counter reset\n") if $debug_enter_abuse; $channel_data->{enter_abuse} = 0; $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); @@ -636,7 +636,7 @@ sub check_flood { } else { $self->{channels}->{$channel}->{last_spoken_nick} = $nick; $self->{pbot}->{logger}->log("last spoken nick set to $nick\n") if $debug_enter_abuse; - if($channel_data->{enter_abuse} > 0) { + if ($channel_data->{enter_abuse} > 0) { $self->{pbot}->{logger}->log("$nick $channel enter abuse counter reset\n") if $debug_enter_abuse; $channel_data->{enter_abuse} = 0; $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); @@ -674,12 +674,12 @@ sub unbanme { foreach my $nickserv_account (@nickserv_accounts) { my $baninfos = $self->{pbot}->{bantracker}->get_baninfo("$anick!$auser\@$ahost", $channel, $nickserv_account); - if(defined $baninfos) { + if (defined $baninfos) { foreach my $baninfo (@$baninfos) { - if($self->whitelisted($baninfo->{channel}, $baninfo->{banmask}, 'ban') || $self->whitelisted($baninfo->{channel}, "$nick!$user\@$host", 'user')) { + if ($self->whitelisted($baninfo->{channel}, $baninfo->{banmask}, 'ban') || $self->whitelisted($baninfo->{channel}, "$nick!$user\@$host", 'user')) { $self->{pbot}->{logger}->log("anti-flood: [unbanme] $anick!$auser\@$ahost banned as $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n"); } else { - if($channel eq lc $baninfo->{channel}) { + if ($channel eq lc $baninfo->{channel}) { my $mode = $baninfo->{type} eq "+b" ? "banned" : "quieted"; $self->{pbot}->{logger}->log("anti-flood: [unbanme] $anick!$auser\@$ahost $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."; @@ -758,20 +758,20 @@ sub address_to_mask { my $address = shift; my $banmask; - if($address =~ m/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) { + 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{^gateway/([^/]+)/([^/]+)/}) { + } elsif ($address =~ m{^gateway/([^/]+)/([^/]+)/}) { $banmask = "gateway/$1/$2/*"; - } elsif($address =~ m{^nat/([^/]+)/}) { + } elsif ($address =~ m{^nat/([^/]+)/}) { $banmask = "nat/$1/*"; - } elsif($address =~ m/^([^:]+):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)$/) { + } elsif ($address =~ m/^([^:]+):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)$/) { $banmask = "$1:$2:*"; - } elsif($address =~ m/[^.]+\.([^.]+\.[a-zA-Z]+)$/) { + } elsif ($address =~ m/[^.]+\.([^.]+\.[a-zA-Z]+)$/) { $banmask = "*.$1"; } else { $banmask = $address; @@ -787,7 +787,7 @@ sub devalidate_accounts { #$self->{pbot}->{logger}->log("Devalidating accounts for $mask in $channel\n"); - if($mask =~ m/^\$a:(.*)/) { + if ($mask =~ m/^\$a:(.*)/) { my $ban_account = lc $1; @message_accounts = $self->{pbot}->{messagehistory}->{database}->find_message_accounts_by_nickserv($ban_account); } else { @@ -796,7 +796,7 @@ sub devalidate_accounts { 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}) { + 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); @@ -833,7 +833,7 @@ sub check_bans { if (not exists $self->{pbot}->{capabilities}->{'account-notify'}) { # mark this account as needing check-bans when nickserv account is identified my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated'); - if(not $channel_data->{validated} & $self->{NEEDS_CHECKBAN}) { + 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); } @@ -880,7 +880,7 @@ sub check_bans { my $tnickserv = defined $nickserv ? $nickserv : "[undefined]"; $self->{pbot}->{logger}->log("anti-flood: [check-bans] checking blacklist for $alias in channel $channel using gecos '$tgecos' and nickserv '$tnickserv'\n") if $debug_checkban >= 5; if ($self->{pbot}->{blacklist}->check_blacklist($alias, $channel, $nickserv, $gecos)) { - if($self->whitelisted($channel, $mask, 'user')) { + if ($self->whitelisted($channel, $mask, 'user')) { $self->{pbot}->{logger}->log("anti-flood: [check-bans] $mask [$alias] blacklisted in $channel, but allowed through whitelist\n"); next; } @@ -899,12 +899,12 @@ sub check_bans { $self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans in $channel on $alias using nickserv " . (defined $nickserv ? $nickserv : "[undefined]") . "\n") if $debug_checkban >= 2; my $baninfos = $self->{pbot}->{bantracker}->get_baninfo($alias, $channel, $nickserv); - if(defined $baninfos) { + if (defined $baninfos) { foreach my $baninfo (@$baninfos) { - if(time - $baninfo->{when} < 5) { + if (time - $baninfo->{when} < 5) { $self->{pbot}->{logger}->log("anti-flood: [check-bans] $mask [$alias] 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}) { + 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); } @@ -912,7 +912,7 @@ sub check_bans { next; } - if($self->whitelisted($baninfo->{channel}, $baninfo->{banmask}, 'ban') || $self->whitelisted($baninfo->{channel}, $mask, 'user')) { + if ($self->whitelisted($baninfo->{channel}, $baninfo->{banmask}, 'ban') || $self->whitelisted($baninfo->{channel}, $mask, 'user')) { #$self->{pbot}->{logger}->log("anti-flood: [check-bans] $mask [$alias] evaded $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n"); next; } @@ -927,17 +927,17 @@ sub check_bans { $banmask_regex =~ s/\\\*/.*/g; $banmask_regex =~ s/\\\?/./g; - if($mask =~ /^$banmask_regex$/i) { + if ($mask =~ /^$banmask_regex$/i) { $self->{pbot}->{logger}->log("anti-flood: [check-bans] Hostmask ($mask) matches $baninfo->{type} banmask ($banmask_regex), disregarding\n"); next; } - if(defined $nickserv and $baninfo->{type} eq '+q' and $baninfo->{banmask} =~ /^\$a:(.*)/ and lc $1 eq $nickserv and $nickserv eq $current_nickserv_account) { + if (defined $nickserv and $baninfo->{type} eq '+q' and $baninfo->{banmask} =~ /^\$a:(.*)/ and lc $1 eq $nickserv and $nickserv eq $current_nickserv_account) { $self->{pbot}->{logger}->log("anti-flood: [check-bans] Hostmask ($mask) matches quiet on account ($nickserv), disregarding\n"); next; } - if(not defined $bans) { + if (not defined $bans) { $bans = []; } @@ -950,7 +950,7 @@ sub check_bans { } GOT_BAN: - if(defined $bans) { + if (defined $bans) { foreach my $baninfo (@$bans) { my $banmask; @@ -972,7 +972,7 @@ sub check_bans { $self->{pbot}->{logger}->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}, banning $banmask\n"); my ($bannick) = $mask =~ m/^([^!]+)/; - if($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { + if ($self->{pbot}->{registry}->get_value('antiflood', 'enforce')) { if ($self->{pbot}->{chanops}->has_ban_timeout($baninfo->{channel}, $banmask)) { $self->{pbot}->{logger}->log("anti-flood: [check-bans] $banmask already banned in $channel, disregarding\n"); return; @@ -1001,7 +1001,7 @@ sub check_bans { $self->{pbot}->{chanops}->ban_user_timed($banmask, $baninfo->{channel}, 60 * 60 * 24 * 14); } my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated'); - if($channel_data->{validated} & $self->{NICKSERV_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); } @@ -1011,7 +1011,7 @@ sub check_bans { 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}) { + 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); } @@ -1026,21 +1026,21 @@ sub check_nickserv_accounts { $account = lc $account; - if(not defined $hostmask) { + if (not defined $hostmask) { ($message_account, $hostmask) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($nick); - if(not defined $message_account) { + 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) { + if (not $message_account) { $self->{pbot}->{logger}->log("No message account found for nickserv $account.\n"); return; } } } else { ($message_account) = $self->{pbot}->{messagehistory}->{database}->find_message_accounts_by_mask($hostmask); - if(not $message_account) { + if (not $message_account) { $self->{pbot}->{logger}->log("No message account found for hostmask $hostmask.\n"); return; } @@ -1168,7 +1168,7 @@ sub adjust_offenses { my $id = delete $channel_data->{id}; my $channel = delete $channel_data->{channel}; my $last_offense = delete $channel_data->{last_offense}; - if(gettimeofday - $last_offense >= 60 * 60 * 3) { + if (gettimeofday - $last_offense >= 60 * 60 * 3) { $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); @@ -1176,10 +1176,10 @@ sub adjust_offenses { } foreach my $account (keys %{ $self->{nickflood} }) { - if($self->{nickflood}->{$account}->{offenses} and gettimeofday - $self->{nickflood}->{$account}->{timestamp} >= 60 * 60) { + if ($self->{nickflood}->{$account}->{offenses} and gettimeofday - $self->{nickflood}->{$account}->{timestamp} >= 60 * 60) { $self->{nickflood}->{$account}->{offenses}--; - if($self->{nickflood}->{$account}->{offenses} <= 0) { + if ($self->{nickflood}->{$account}->{offenses} <= 0) { delete $self->{nickflood}->{$account}; } else { $self->{nickflood}->{$account}->{timestamp} = gettimeofday; diff --git a/PBot/AntiSpam.pm b/PBot/AntiSpam.pm index 36eb89aa..0635e171 100644 --- a/PBot/AntiSpam.pm +++ b/PBot/AntiSpam.pm @@ -163,11 +163,11 @@ sub antispam_cmd { my ($namespace, $keyword) = $self->{pbot}->{interpreter}->split_args($arglist, 2); return "Usage: antispam remove " if not defined $namespace or not defined $keyword; - if(not defined $self->{keywords}->hash->{$namespace}) { + if (not defined $self->{keywords}->hash->{$namespace}) { return "No entries for namespace $namespace"; } - if(not defined $self->{keywords}->hash->{$namespace}->{$keyword}) { + if (not defined $self->{keywords}->hash->{$namespace}->{$keyword}) { return "No such entry for namespace $namespace"; } diff --git a/PBot/BanTracker.pm b/PBot/BanTracker.pm index f01ba951..b0c770e8 100644 --- a/PBot/BanTracker.pm +++ b/PBot/BanTracker.pm @@ -22,7 +22,7 @@ $Data::Dumper::Sortkeys = 1; use Carp (); sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to BanTracker should be key/value pairs, not hash reference"); } @@ -130,7 +130,7 @@ sub get_baninfo { foreach my $mode (keys %{ $self->{banlist}->{$channel} }) { foreach my $banmask (keys %{ $self->{banlist}->{$channel}->{$mode} }) { - if($banmask =~ m/^\$a:(.*)/) { + if ($banmask =~ m/^\$a:(.*)/) { $ban_account = lc $1; } else { $ban_account = ""; @@ -155,7 +155,7 @@ sub get_baninfo { } if ($banned) { - if(not defined $bans) { + if (not defined $bans) { $bans = []; } @@ -214,25 +214,25 @@ sub track_mode { $target = lc $target; $channel = lc $channel; - if($mode eq "+b" or $mode eq "+q") { + if ($mode eq "+b" or $mode eq "+q") { $self->{pbot}->{logger}->log("ban-tracker: $target " . ($mode eq '+b' ? 'banned' : 'quieted') . " by $source in $channel.\n"); $self->{banlist}->{$channel}->{$mode}->{$target} = [ $source, gettimeofday ]; $self->{pbot}->{antiflood}->devalidate_accounts($target, $channel); } - elsif($mode eq "-b" or $mode eq "-q") { + elsif ($mode eq "-b" or $mode eq "-q") { $self->{pbot}->{logger}->log("ban-tracker: $target " . ($mode eq '-b' ? 'unbanned' : 'unquieted') . " by $source in $channel.\n"); delete $self->{banlist}->{$channel}->{$mode eq "-b" ? "+b" : "+q"}->{$target}; - if($mode eq "-b") { - if($self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, $target)) { + if ($mode eq "-b") { + if ($self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, $target)) { $self->{pbot}->{chanops}->{unban_timeout}->remove($channel, $target); - } elsif($self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, "$target\$##stop_join_flood")) { + } elsif ($self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, "$target\$##stop_join_flood")) { # freenode strips channel forwards from unban result if no ban exists with a channel forward $self->{pbot}->{chanops}->{unban_timeout}->remove($channel, "$target\$##stop_join_flood"); } } - elsif($mode eq "-q") { - if($self->{pbot}->{chanops}->{unmute_timeout}->find_index($channel, $target)) { + elsif ($mode eq "-q") { + if ($self->{pbot}->{chanops}->{unmute_timeout}->find_index($channel, $target)) { $self->{pbot}->{chanops}->{unmute_timeout}->remove($channel, $target); } } diff --git a/PBot/BlackList.pm b/PBot/BlackList.pm index a87f67f7..89afd732 100644 --- a/PBot/BlackList.pm +++ b/PBot/BlackList.pm @@ -19,7 +19,7 @@ use Carp (); use Time::HiRes qw(gettimeofday); sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference"); } @@ -77,9 +77,9 @@ sub load_blacklist { my $self = shift; my $filename; - if(@_) { $filename = shift; } else { $filename = $self->{filename}; } + if (@_) { $filename = shift; } else { $filename = $self->{filename}; } - if(not defined $filename) { + if (not defined $filename) { Carp::carp "No blacklist path specified -- skipping loading of blacklist"; return; } @@ -98,11 +98,11 @@ sub load_blacklist { my ($channel, $hostmask) = split(/\s+/, $line); - if(not defined $hostmask || not defined $channel) { + if (not defined $hostmask || not defined $channel) { Carp::croak "Syntax error around line $i of $filename\n"; } - if(exists $self->{blacklist}->{$channel}->{$hostmask}) { + if (exists $self->{blacklist}->{$channel}->{$hostmask}) { Carp::croak "Duplicate blacklist entry [$hostmask][$channel] found in $filename around line $i\n"; } @@ -117,9 +117,9 @@ sub save_blacklist { my $self = shift; my $filename; - if(@_) { $filename = shift; } else { $filename = $self->{filename}; } + if (@_) { $filename = shift; } else { $filename = $self->{filename}; } - if(not defined $filename) { + if (not defined $filename) { Carp::carp "No blacklist path specified -- skipping saving of blacklist\n"; return; } @@ -213,7 +213,7 @@ sub blacklist { $channel = '.*' if not defined $channel; - if(exists $self->{blacklist}->{$channel} and not exists $self->{blacklist}->{$channel}->{$mask}) { + if (exists $self->{blacklist}->{$channel} and not exists $self->{blacklist}->{$channel}->{$mask}) { $self->{pbot}->{logger}->log("$nick attempt to remove nonexistent [$mask][$channel] from blacklist\n"); return "/say $mask not found in blacklist for channel $channel (use `blacklist list` to display blacklist)"; } diff --git a/PBot/BotAdminCommands.pm b/PBot/BotAdminCommands.pm index 11149c48..19d82cd0 100644 --- a/PBot/BotAdminCommands.pm +++ b/PBot/BotAdminCommands.pm @@ -18,7 +18,7 @@ no if $] >= 5.018, warnings => "experimental::smartmatch"; use Carp (); sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to BotAdminCommands should be key/value pairs, not hash reference"); } @@ -33,7 +33,7 @@ sub initialize { my ($self, %conf) = @_; my $pbot = delete $conf{pbot}; - if(not defined $pbot) { + if (not defined $pbot) { Carp::croak("Missing pbot reference to BotAdminCommands"); } @@ -94,7 +94,7 @@ sub login { $arguments = $2; } - if($self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host")) { + if ($self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host")) { return "/msg $nick You are already logged into channel $channel."; } @@ -105,7 +105,7 @@ sub login { sub logout { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; - return "/msg $nick Uh, you aren't logged into channel $from." if(not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host")); + return "/msg $nick Uh, you aren't logged into channel $from." if (not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host")); $self->{pbot}->{admins}->logout($from, "$nick!$user\@$host"); return "/msg $nick Good-bye, $nick."; } @@ -116,7 +116,7 @@ sub adminadd { my ($name, $channel, $hostmask, $level, $password) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 5); - if(not defined $name or not defined $channel or not defined $hostmask or not defined $level + if (not defined $name or not defined $channel or not defined $hostmask or not defined $level or not defined $password) { return "/msg $nick Usage: adminadd "; } @@ -143,7 +143,7 @@ sub adminrem { my ($channel, $hostmask) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); - if(not defined $channel or not defined $hostmask) { + if (not defined $channel or not defined $hostmask) { return "/msg $nick Usage: adminrem "; } @@ -163,7 +163,7 @@ sub adminrem { } } - if($self->{pbot}->{admins}->remove_admin($channel, $hostmask)) { + if ($self->{pbot}->{admins}->remove_admin($channel, $hostmask)) { return "Admin removed."; } else { return "No such admin found."; @@ -175,7 +175,7 @@ sub adminset { my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my ($channel, $hostmask, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 4); - if(not defined $channel or not defined $hostmask) { + if (not defined $channel or not defined $hostmask) { return "Usage: adminset [key] [value]"; } @@ -222,7 +222,7 @@ sub adminunset { my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my ($channel, $hostmask, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3); - if(not defined $channel or not defined $hostmask) { + if (not defined $channel or not defined $hostmask) { return "Usage: adminunset "; } @@ -286,19 +286,19 @@ sub export { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; - if(not defined $arguments) { + if (not defined $arguments) { return "/msg $nick Usage: export "; } - if($arguments =~ /^modules$/i) { + if ($arguments =~ /^modules$/i) { return "/msg $nick Coming soon."; } - if($arguments =~ /^factoids$/i) { + if ($arguments =~ /^factoids$/i) { return $self->{pbot}->{factoids}->export_factoids; } - if($arguments =~ /^admins$/i) { + if ($arguments =~ /^admins$/i) { return "/msg $nick Coming soon."; } } diff --git a/PBot/BotAdmins.pm b/PBot/BotAdmins.pm index ce67fecf..e4745aa9 100644 --- a/PBot/BotAdmins.pm +++ b/PBot/BotAdmins.pm @@ -18,7 +18,7 @@ use PBot::BotAdminCommands; use Carp (); sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference"); } @@ -37,8 +37,8 @@ sub initialize { my $export_site = delete $conf{export_site}; my $export_timeout = delete $conf{export_timeout}; - if(not defined $export_timeout) { - if(defined $export_path) { + if (not defined $export_timeout) { + if (defined $export_path) { $export_timeout = 300; # every 5 minutes } else { $export_timeout = -1; @@ -81,7 +81,7 @@ sub remove_admin { delete $self->{admins}->hash->{$channel}; } - if(defined $admin) { + if (defined $admin) { $self->{pbot}->{logger}->log("Removed level $admin->{level} admin [$admin->{name}] [$hostmask] from channel [$channel]\n"); $self->save_admins; return 1; @@ -95,9 +95,9 @@ sub load_admins { my $self = shift; my $filename; - if(@_) { $filename = shift; } else { $filename = $self->{admins}->filename; } + if (@_) { $filename = shift; } else { $filename = $self->{admins}->filename; } - if(not defined $filename) { + if (not defined $filename) { Carp::carp "No admins path specified -- skipping loading of admins"; return; } @@ -116,7 +116,7 @@ sub load_admins { my $level = $self->{admins}->hash->{$channel}->{$hostmask}->{level}; my $password = $self->{admins}->hash->{$channel}->{$hostmask}->{password}; - if(not defined $name or not defined $level or not defined $password) { + if (not defined $name or not defined $level or not defined $password) { Carp::croak "Syntax error around line $i of $filename\n"; } @@ -139,7 +139,7 @@ sub export_admins { my $self = shift; my $filename; - if(@_) { $filename = shift; } else { $filename = $self->export_path; } + if (@_) { $filename = shift; } else { $filename = $self->export_path; } return if not defined $filename; return; @@ -163,7 +163,7 @@ sub find_admin { return undef; }; - if($@) { + if ($@) { $self->{pbot}->{logger}->log("Error in find_admin parameters: $@\n"); } @@ -175,7 +175,7 @@ sub loggedin { my $admin = $self->find_admin($channel, $hostmask); - if(defined $admin && $admin->{loggedin}) { + if (defined $admin && $admin->{loggedin}) { return $admin; } else { return undef; @@ -187,12 +187,12 @@ sub login { my $admin = $self->find_admin($channel, $hostmask); - if(not defined $admin) { + if (not defined $admin) { $self->{pbot}->{logger}->log("Attempt to login non-existent [$channel][$hostmask] failed\n"); return "You do not have an account in $channel."; } - if($admin->{password} ne $password) { + if ($admin->{password} ne $password) { $self->{pbot}->{logger}->log("Bad login password for [$channel][$hostmask]\n"); return "I don't think so."; } @@ -215,20 +215,20 @@ sub logout { sub export_path { my $self = shift; - if(@_) { $self->{export_path} = shift; } + if (@_) { $self->{export_path} = shift; } return $self->{export_path}; } sub export_timeout { my $self = shift; - if(@_) { $self->{export_timeout} = shift; } + if (@_) { $self->{export_timeout} = shift; } return $self->{export_timeout}; } sub export_site { my $self = shift; - if(@_) { $self->{export_site} = shift; } + if (@_) { $self->{export_site} = shift; } return $self->{export_site}; } @@ -240,7 +240,7 @@ sub admins { sub filename { my $self = shift; - if(@_) { $self->{filename} = shift; } + if (@_) { $self->{filename} = shift; } return $self->{filename}; } diff --git a/PBot/ChanOpCommands.pm b/PBot/ChanOpCommands.pm index d7ed5b6e..13820289 100644 --- a/PBot/ChanOpCommands.pm +++ b/PBot/ChanOpCommands.pm @@ -122,7 +122,7 @@ sub unban_user { $channel = $temp; } - if(not defined $target) { + if (not defined $target) { return "/msg $nick Usage: unban [[channel] [false value to use unban queue]]"; } @@ -230,7 +230,7 @@ sub unmute_user { $channel = $temp; } - if(not defined $target) { + if (not defined $target) { return "/msg $nick Usage: unmute [[channel] [false value to use unban queue]]"; } diff --git a/PBot/ChanOps.pm b/PBot/ChanOps.pm index fecea4a0..2778c8e2 100644 --- a/PBot/ChanOps.pm +++ b/PBot/ChanOps.pm @@ -16,7 +16,7 @@ use PBot::ChanOpCommands; use Time::HiRes qw(gettimeofday); sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference"); } @@ -80,7 +80,7 @@ sub gain_ops { return if exists $self->{op_requested}->{$channel}; return if not $self->can_gain_ops($channel); - if(not exists $self->{is_opped}->{$channel}) { + if (not exists $self->{is_opped}->{$channel}) { $self->{pbot}->{conn}->privmsg("chanserv", "op $channel"); $self->{op_requested}->{$channel} = scalar gettimeofday; } else { @@ -109,11 +109,11 @@ sub perform_op_commands { my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); $self->{pbot}->{logger}->log("Performing op commands...\n"); - while(my $command = shift @{ $self->{op_commands}->{$channel} }) { - if($command =~ /^mode (.*?) (.*)/i) { + while (my $command = shift @{ $self->{op_commands}->{$channel} }) { + if ($command =~ /^mode (.*?) (.*)/i) { $self->{pbot}->{conn}->mode($1, $2); $self->{pbot}->{logger}->log(" executing mode [$1] [$2]\n"); - } elsif($command =~ /^kick (.*?) (.*?) (.*)/i) { + } elsif ($command =~ /^kick (.*?) (.*?) (.*)/i) { $self->{pbot}->{conn}->kick($1, $2, $3) unless $1 =~ /\Q$botnick\E/i; $self->{pbot}->{logger}->log(" executing kick on $1 $2 $3\n"); } @@ -421,7 +421,7 @@ sub check_unban_timeouts { foreach my $channel (keys %{ $self->{unban_timeout}->hash }) { foreach my $mask (keys %{ $self->{unban_timeout}->hash->{$channel} }) { - if($self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} < $now) { + if ($self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} < $now) { $self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = $now + 7200; $self->unban_user($mask, $channel); } @@ -438,7 +438,7 @@ sub check_unmute_timeouts { foreach my $channel (keys %{ $self->{unmute_timeout}->hash }) { foreach my $mask (keys %{ $self->{unmute_timeout}->hash->{$channel} }) { - if($self->{unmute_timeout}->hash->{$channel}->{$mask}{timeout} < $now) { + if ($self->{unmute_timeout}->hash->{$channel}->{$mask}{timeout} < $now) { $self->{unmute_timeout}->hash->{$channel}->{$mask}{timeout} = $now + 7200; $self->unmute_user($mask, $channel); } @@ -451,7 +451,7 @@ sub check_opped_timeouts { my $now = gettimeofday(); foreach my $channel (keys %{ $self->{is_opped} }) { - if($self->{is_opped}->{$channel}{timeout} < $now) { + if ($self->{is_opped}->{$channel}{timeout} < $now) { unless (exists $self->{pbot}->{channels}->{channels}->hash->{$channel} and exists $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop} and $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop}) { diff --git a/PBot/Channels.pm b/PBot/Channels.pm index ef37277f..49871360 100644 --- a/PBot/Channels.pm +++ b/PBot/Channels.pm @@ -16,7 +16,7 @@ use Carp (); use PBot::HashObject; sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak ("Options to " . __FILE__ . " should be key/value pairs, not hash reference"); } @@ -46,7 +46,7 @@ sub set { my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($channel, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3); - if(not defined $channel) { + if (not defined $channel) { return "Usage: chanset [key [value]]"; } @@ -57,7 +57,7 @@ sub unset { my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($channel, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); - if(not defined $channel or not defined $key) { + if (not defined $channel or not defined $key) { return "Usage: chanunset "; } @@ -67,7 +67,7 @@ sub unset { sub add { my ($self, $from, $nick, $user, $host, $arguments) = @_; - if(not defined $arguments or not length $arguments) { + if (not defined $arguments or not length $arguments) { return "Usage: chanadd "; } @@ -82,7 +82,7 @@ sub add { sub remove { my ($self, $from, $nick, $user, $host, $arguments) = @_; - if(not defined $arguments or not length $arguments) { + if (not defined $arguments or not length $arguments) { return "Usage: chanrem "; } diff --git a/PBot/Commands.pm b/PBot/Commands.pm index 7e333af8..019d95c3 100644 --- a/PBot/Commands.pm +++ b/PBot/Commands.pm @@ -21,7 +21,7 @@ use Carp (); use Text::ParseWords qw(shellwords); sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to Commands should be key/value pairs, not hash reference"); } @@ -38,7 +38,7 @@ sub initialize { $self->SUPER::initialize(%conf); my $pbot = delete $conf{pbot}; - if(not defined $pbot) { + if (not defined $pbot) { Carp::croak("Missing pbot reference to PBot::Commands"); } @@ -50,7 +50,7 @@ sub initialize { sub register { my ($self, $subref, $name, $level) = @_; - if((not defined $subref) || (not defined $name) || (not defined $level)) { + if ((not defined $subref) || (not defined $name) || (not defined $level)) { Carp::croak("Missing parameters to Commands::register"); } @@ -67,7 +67,7 @@ sub register { sub unregister { my ($self, $name) = @_; - if(not defined $name) { + if (not defined $name) { Carp::croak("Missing name parameter to Commands::unregister"); } diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index 7ad20350..e8ebc1f5 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -22,7 +22,7 @@ use Storable; use PBot::Utils::SafeFilename; sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to FactoidCommands should be key/value pairs, not hash reference"); } @@ -59,7 +59,7 @@ sub initialize { my ($self, %conf) = @_; my $pbot = delete $conf{pbot}; - if(not defined $pbot) { + if (not defined $pbot) { Carp::croak("Missing pbot reference to FactoidCommands"); } @@ -100,13 +100,13 @@ sub call_factoid { my ($from, $nick, $user, $host, $arguments, $stuff) = @_; my ($chan, $keyword, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3); - if(not defined $chan or not defined $keyword) { + if (not defined $chan or not defined $keyword) { return "Usage: fact [arguments]"; } my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $keyword, $args, 1, 1); - if(not defined $trigger) { + if (not defined $trigger) { return "No such factoid '$keyword' exists for channel '$chan'"; } @@ -538,19 +538,19 @@ sub factset { my $level = 0; my $meta_level = 0; - if(defined $admininfo) { + if (defined $admininfo) { $level = $admininfo->{level}; } - if(defined $key) { - if(defined $factoid_metadata_levels{$key}) { + if (defined $key) { + if (defined $factoid_metadata_levels{$key}) { $meta_level = $factoid_metadata_levels{$key}; } - if($meta_level > 0) { - if($level == 0) { + if ($meta_level > 0) { + if ($level == 0) { return "You must login to set '$key'"; - } elsif($level < $meta_level) { + } elsif ($level < $meta_level) { return "You must be at least level $meta_level to set '$key'"; } } @@ -622,18 +622,18 @@ sub factunset { my $level = 0; my $meta_level = 0; - if(defined $admininfo) { + if (defined $admininfo) { $level = $admininfo->{level}; } - if(defined $factoid_metadata_levels{$key}) { + if (defined $factoid_metadata_levels{$key}) { $meta_level = $factoid_metadata_levels{$key}; } - if($meta_level > 0) { - if($level == 0) { + if ($meta_level > 0) { + if ($level == 0) { return "You must login to unset '$key'"; - } elsif($level < $meta_level) { + } elsif ($level < $meta_level) { return "You must be at least level $meta_level to unset '$key'"; } } @@ -654,12 +654,12 @@ sub factunset { my $oldvalue; - if(defined $owner_channel) { + if (defined $owner_channel) { my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger}; my ($owner) = $factoid->{'owner'} =~ m/([^!]+)/; - if(lc $nick ne lc $owner and $level == 0) { + if (lc $nick ne lc $owner and $level == 0) { return "You are not the owner of $trigger."; } $oldvalue = $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{$key}; @@ -681,16 +681,16 @@ sub list { my ($from, $nick, $user, $host, $arguments) = @_; my $text; - if(not defined $arguments) { + if (not defined $arguments) { return "Usage: list "; } - if($arguments =~ /^modules$/i) { + if ($arguments =~ /^modules$/i) { $from = '.*' if not defined $from or $from !~ /^#/; $text = "Loaded modules for channel $from: "; foreach my $channel (sort keys %{ $self->{pbot}->{factoids}->{factoids}->hash }) { foreach my $command (sort keys %{ $self->{pbot}->{factoids}->{factoids}->hash->{$channel} }) { - if($self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$command}->{type} eq 'module') { + if ($self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$command}->{type} eq 'module') { $text .= "$command "; } } @@ -698,7 +698,7 @@ sub list { return $text; } - if($arguments =~ /^commands$/i) { + if ($arguments =~ /^commands$/i) { $text = "Registered commands: "; foreach my $command (sort { $a->{name} cmp $b->{name} } @{ $self->{pbot}->{commands}->{handlers} }) { $text .= "$command->{name} "; @@ -707,16 +707,16 @@ sub list { return $text; } - if($arguments =~ /^factoids$/i) { + if ($arguments =~ /^factoids$/i) { return "For a list of factoids see " . $self->{pbot}->{factoids}->export_site; } - if($arguments =~ /^admins$/i) { + if ($arguments =~ /^admins$/i) { $text = "Admins: "; my $last_channel = ""; my $sep = ""; foreach my $channel (sort keys %{ $self->{pbot}->{admins}->{admins}->hash }) { - if($last_channel ne $channel) { + if ($last_channel ne $channel) { $text .= $sep . "Channel " . ($channel eq ".*" ? "all" : $channel) . ": "; $last_channel = $channel; $sep = ""; @@ -740,19 +740,19 @@ sub factmove { my $usage = "Usage: factmove [target factoid]"; - if(not defined $target_channel) { + if (not defined $target_channel) { return $usage; } - if($target_channel !~ /^#/ and $target_channel ne '.*') { - if(defined $target) { + if ($target_channel !~ /^#/ and $target_channel ne '.*') { + if (defined $target) { return "Unexpected argument '$target' when renaming to '$target_channel'. Perhaps '$target_channel' is missing #s? $usage"; } $target = $target_channel; $target_channel = $src_channel; } else { - if(not defined $target) { + if (not defined $target) { $target = $source; } } @@ -767,7 +767,7 @@ sub factmove { my ($found_src_channel, $found_source) = $self->{pbot}->{factoids}->find_factoid($src_channel, $source, undef, 1, 1); - if(not defined $found_src_channel) { + if (not defined $found_src_channel) { return "Source factoid $source not found in channel $src_channel"; } @@ -775,24 +775,24 @@ sub factmove { my ($owner) = $factoids->{$found_src_channel}->{$found_source}->{'owner'} =~ m/([^!]+)/; - if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($found_src_channel, "$nick!$user\@$host"))) { + if ((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($found_src_channel, "$nick!$user\@$host"))) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to move [$found_src_channel] $found_source (not owner)\n"); my $chan = ($found_src_channel eq '.*' ? 'the global channel' : $found_src_channel); return "You are not the owner of $found_source for $chan"; } - if($factoids->{$found_src_channel}->{$found_source}->{'locked'}) { + if ($factoids->{$found_src_channel}->{$found_source}->{'locked'}) { return "/say $found_source is locked; unlock before moving."; } my ($found_target_channel, $found_target) = $self->{pbot}->{factoids}->find_factoid($target_channel, $target, undef, 1, 1); - if(defined $found_target_channel) { + if (defined $found_target_channel) { return "Target factoid $target already exists in channel $target_channel"; } my ($overchannel, $overtrigger) = $self->{pbot}->{factoids}->find_factoid('.*', $target, undef, 1, 1); - if(defined $overtrigger and $self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{$overtrigger}->{'nooverride'}) { + if (defined $overtrigger and $self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{$overtrigger}->{'nooverride'}) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to override $target\n"); return "/say $target already exists for the global channel and cannot be overridden for " . ($target_channel eq '.*' ? 'the global channel' : $target_channel) . "."; } @@ -812,7 +812,7 @@ sub factmove { $found_src_channel = 'global' if $found_src_channel eq '.*'; $target_channel = 'global' if $target_channel eq '.*'; - if($src_channel eq $target_channel) { + if ($src_channel eq $target_channel) { $self->log_factoid($target_channel, $target, "$nick!$user\@$host", "renamed from $found_source to $target"); return "[$found_src_channel] $found_source renamed to $target"; } else { @@ -856,13 +856,13 @@ sub factalias { my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $alias, undef, 1, 1); - if(defined $alias_trigger) { + if (defined $alias_trigger) { $self->{pbot}->{logger}->log("attempt to overwrite existing command\n"); return "'$alias_trigger' already exists for channel $channel"; } my ($overchannel, $overtrigger) = $self->{pbot}->{factoids}->find_factoid('.*', $alias, undef, 1, 1); - if(defined $overtrigger and $self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{$overtrigger}->{'nooverride'}) { + if (defined $overtrigger and $self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{$overtrigger}->{'nooverride'}) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to override $alias\n"); return "/say $alias already exists for the global channel and cannot be overridden for " . ($chan eq '.*' ? 'the global channel' : $chan) . "."; } @@ -886,23 +886,23 @@ sub add_regex { $from = '.*' if not defined $from or $from !~ /^#/; - if(not defined $keyword) { + if (not defined $keyword) { $text = ""; foreach my $trigger (sort keys %{ $factoids->{$from} }) { - if($factoids->{$from}->{$trigger}->{type} eq 'regex') { + if ($factoids->{$from}->{$trigger}->{type} eq 'regex') { $text .= $trigger . " "; } } return "Stored regexs for channel $from: $text"; } - if(not defined $text) { + if (not defined $text) { return "Usage: regex "; } my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $keyword, undef, 1, 1); - if(defined $trigger) { + if (defined $trigger) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $trigger\n"); return "/say $trigger already exists for channel $channel."; } @@ -930,7 +930,7 @@ sub factadd { } } - if(not defined $from_chan or not defined $text or not defined $keyword) { + if (not defined $from_chan or not defined $text or not defined $keyword) { return "Usage: factadd [channel] "; } @@ -950,13 +950,13 @@ sub factadd { my $keyword_text = $keyword =~ / / ? "\"$keyword\"" : $keyword; my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $keyword, undef, 1, 1); - if(defined $trigger) { + if (defined $trigger) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $keyword\n"); return "/say $keyword_text already exists for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; } ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid('.*', $keyword, undef, 1, 1); - if(defined $trigger and $self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{$trigger}->{'nooverride'}) { + if (defined $trigger and $self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{$trigger}->{'nooverride'}) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to override $keyword_text\n"); return "/say $keyword_text already exists for the global channel and cannot be overridden for " . ($from_chan eq '.*' ? 'the global channel' : $from_chan) . "."; } @@ -991,7 +991,7 @@ sub factrem { my $trigger_text = $trigger =~ / / ? "\"$trigger\"" : $trigger;; - if($factoids->{$channel}->{$trigger}->{type} eq 'module') { + if ($factoids->{$channel}->{$trigger}->{type} eq 'module') { $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger_text [not factoid]\n"); return "/say $trigger_text is not a factoid."; } @@ -1002,13 +1002,13 @@ sub factrem { my ($owner) = $factoids->{$channel}->{$trigger}->{'owner'} =~ m/([^!]+)/; - if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host"))) { + if ((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host"))) { $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger_text [not owner]\n"); my $chan = ($channel eq '.*' ? 'the global channel' : $channel); return "You are not the owner of $trigger_text for $chan"; } - if($factoids->{$channel}->{$trigger}->{'locked'}) { + if ($factoids->{$channel}->{$trigger}->{'locked'}) { return "/say $trigger_text is locked; unlock before deleting."; } @@ -1027,7 +1027,7 @@ sub histogram { foreach my $channel (keys %$factoids) { foreach my $command (keys %{ $factoids->{$channel} }) { - if($factoids->{$channel}->{$command}->{type} eq 'text') { + if ($factoids->{$channel}->{$command}->{type} eq 'text') { $hash{$factoids->{$channel}->{$command}->{owner}}++; $factoid_count++; } @@ -1065,7 +1065,7 @@ sub factshow { my $result = "$trigger_text: " . $factoids->{$channel}->{$trigger}->{action}; - if($factoids->{$channel}->{$trigger}->{type} eq 'module') { + if ($factoids->{$channel}->{$trigger}->{type} eq 'module') { $result .= ' [module]'; } @@ -1170,19 +1170,19 @@ sub factinfo { $chan = ($channel eq '.*' ? 'global channel' : $channel); # factoid - if($factoids->{$channel}->{$trigger}->{type} eq 'text') { + if ($factoids->{$channel}->{$trigger}->{type} eq 'text') { return "/say $trigger: Factoid submitted by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], " . (defined $factoids->{$channel}->{$trigger}->{edited_by} ? "last edited by $factoids->{$channel}->{$trigger}->{edited_by} on " . localtime($factoids->{$channel}->{$trigger}->{edited_on}) . " [" . ago(gettimeofday - $factoids->{$channel}->{$trigger}->{edited_on}) . "], " : "") . "referenced " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; } # module - if($factoids->{$channel}->{$trigger}->{type} eq 'module') { + if ($factoids->{$channel}->{$trigger}->{type} eq 'module') { my $module_repo = $self->{pbot}->{registry}->get_value('general', 'module_repo'); $module_repo .= "$factoids->{$channel}->{$trigger}->{workdir}/" if exists $factoids->{$channel}->{$trigger}->{workdir}; return "/say $trigger: Module loaded by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago] -> $module_repo" . $factoids->{$channel}->{$trigger}->{action} . ", used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; } # regex - if($factoids->{$channel}->{$trigger}->{type} eq 'regex') { + if ($factoids->{$channel}->{$trigger}->{type} eq 'regex') { return "/say $trigger: Regex created by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], " . (defined $factoids->{$channel}->{$trigger}->{edited_by} ? "last edited by $factoids->{$channel}->{$trigger}->{edited_by} on " . localtime($factoids->{$channel}->{$trigger}->{edited_on}) . " [" . ago(gettimeofday - $factoids->{$channel}->{$trigger}->{edited_on}) . "], " : "") . " used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; } @@ -1199,15 +1199,15 @@ sub top20 { my ($channel, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); - if(not defined $channel) { + if (not defined $channel) { return "Usage: top20 [nick or 'recent']"; } - if(not defined $args) { + if (not defined $args) { foreach my $chan (sort keys %{ $factoids }) { next if lc $chan ne lc $channel; foreach my $command (sort {$factoids->{$chan}->{$b}{ref_count} <=> $factoids->{$chan}->{$a}{ref_count}} keys %{ $factoids->{$chan} }) { - if($factoids->{$chan}->{$command}{ref_count} > 0 and $factoids->{$chan}->{$command}{type} eq 'text') { + if ($factoids->{$chan}->{$command}{ref_count} > 0 and $factoids->{$chan}->{$command}{type} eq 'text') { $text .= "$command ($factoids->{$chan}->{$command}{ref_count}) "; $i++; last if $i >= 20; @@ -1218,7 +1218,7 @@ sub top20 { return $text; } } else { - if(lc $args eq "recent") { + if (lc $args eq "recent") { foreach my $chan (sort keys %{ $factoids }) { next if lc $chan ne lc $channel; foreach my $command (sort { $factoids->{$chan}->{$b}{created_on} <=> $factoids->{$chan}->{$a}{created_on} } keys %{ $factoids->{$chan} }) { @@ -1239,8 +1239,8 @@ sub top20 { foreach my $chan (sort keys %{ $factoids }) { next if lc $chan ne lc $channel; foreach my $command (sort { ($factoids->{$chan}->{$b}{last_referenced_on} || 0) <=> ($factoids->{$chan}->{$a}{last_referenced_on} || 0) } keys %{ $factoids->{$chan} }) { - if($factoids->{$chan}->{$command}{ref_user} =~ /\Q$args\E/i) { - if($user ne lc $factoids->{$chan}->{$command}{ref_user} && not $user =~ /$factoids->{$chan}->{$command}{ref_user}/i) { + if ($factoids->{$chan}->{$command}{ref_user} =~ /\Q$args\E/i) { + if ($user ne lc $factoids->{$chan}->{$command}{ref_user} && not $user =~ /$factoids->{$chan}->{$command}{ref_user}/i) { $user .= " ($factoids->{$chan}->{$command}{ref_user})"; } my $ago = $factoids->{$chan}->{$command}{last_referenced_on} ? ago(gettimeofday - $factoids->{$chan}->{$command}{last_referenced_on}) : "unknown"; @@ -1266,14 +1266,14 @@ sub count { return "Usage: count "; } - $arguments = ".*" if($arguments =~ /^factoids$/); + $arguments = ".*" if ($arguments =~ /^factoids$/); eval { foreach my $channel (keys %{ $factoids }) { foreach my $command (keys %{ $factoids->{$channel} }) { next if $factoids->{$channel}->{$command}->{type} ne 'text'; $total++; - if($factoids->{$channel}->{$command}->{owner} =~ /^\Q$arguments\E$/i) { + if ($factoids->{$channel}->{$command}->{owner} =~ /^\Q$arguments\E$/i) { $i++; } } @@ -1283,7 +1283,7 @@ sub count { return "I have $i factoids." if $arguments eq ".*"; - if($i > 0) { + if ($i > 0) { my $percent = int($i / $total * 100); $percent = 1 if $percent == 0; return "/say $arguments has submitted $i factoids out of $total ($percent"."%)"; @@ -1299,7 +1299,7 @@ sub factfind { my $usage = "Usage: factfind [-channel channel] [-owner regex] [-editby regex] [-refby regex] [-regex] [text]"; - if(not defined $arguments) { + if (not defined $arguments) { return $usage; } @@ -1323,38 +1323,38 @@ sub factfind { my $argtype = undef; - if($owner ne '.*') { + if ($owner ne '.*') { $argtype = "owned by $owner"; } - if($refby ne '.*') { - if(not defined $argtype) { + if ($refby ne '.*') { + if (not defined $argtype) { $argtype = "last referenced by $refby"; } else { $argtype .= " and last referenced by $refby"; } } - if($editby ne '.*') { - if(not defined $argtype) { + if ($editby ne '.*') { + if (not defined $argtype) { $argtype = "last edited by $editby"; } else { $argtype .= " and last edited by $editby"; } } - if($arguments ne "") { + if ($arguments ne "") { my $unquoted_args = $arguments; $unquoted_args =~ s/(?:\\(?!\\))//g; $unquoted_args =~ s/(?:\\\\)/\\/g; - if(not defined $argtype) { + if (not defined $argtype) { $argtype = "with text containing '$unquoted_args'"; } else { $argtype .= " and with text containing '$unquoted_args'"; } } - if(not defined $argtype) { + if (not defined $argtype) { return $usage; } @@ -1375,15 +1375,15 @@ sub factfind { foreach my $chan (sort keys %{ $factoids }) { next if defined $channel and $chan !~ /^$channel$/i; foreach my $trigger (sort keys %{ $factoids->{$chan} }) { - if($factoids->{$chan}->{$trigger}->{type} eq 'text' or $factoids->{$chan}->{$trigger}->{type} eq 'regex') { - if($factoids->{$chan}->{$trigger}->{owner} =~ /^$owner$/i + if ($factoids->{$chan}->{$trigger}->{type} eq 'text' or $factoids->{$chan}->{$trigger}->{type} eq 'regex') { + if ($factoids->{$chan}->{$trigger}->{owner} =~ /^$owner$/i && $factoids->{$chan}->{$trigger}->{ref_user} =~ /^$refby$/i && (exists $factoids->{$chan}->{$trigger}->{edited_by} ? $factoids->{$chan}->{$trigger}->{edited_by} =~ /^$editby$/i : 1)) { - next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$regex/i && $trigger !~ /$regex/i); + next if ($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$regex/i && $trigger !~ /$regex/i); $i++; - if($chan ne $last_chan) { + if ($chan ne $last_chan) { $text .= $chan eq '.*' ? "[global channel] " : "[$chan] "; $last_chan = $chan; } @@ -1401,7 +1401,7 @@ sub factfind { return "/msg $nick $arguments: $@" if $@; - if($i == 1) { + if ($i == 1) { chop $text; return "Found one factoid submitted for " . ($last_chan eq '.*' ? 'global channel' : $last_chan) . " " . $argtype . ": $last_trigger is $factoids->{$last_chan}->{$last_trigger}->{action}"; } else { @@ -1568,11 +1568,11 @@ sub load_module { my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; my ($keyword, $module) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments; - if(not defined $module) { + if (not defined $module) { return "Usage: load "; } - if(not exists($factoids->{'.*'}->{$keyword})) { + if (not exists($factoids->{'.*'}->{$keyword})) { $self->{pbot}->{factoids}->add_factoid('module', '.*', "$nick!$user\@$host", $keyword, $module); $factoids->{'.*'}->{$keyword}->{add_nick} = 1; $factoids->{'.*'}->{$keyword}->{nooverride} = 1; @@ -1589,11 +1589,11 @@ sub unload_module { my ($from, $nick, $user, $host, $arguments) = @_; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; - if(not defined $arguments) { + if (not defined $arguments) { return "Usage: unload "; - } elsif(not exists $factoids->{'.*'}->{$arguments}) { + } elsif (not exists $factoids->{'.*'}->{$arguments}) { return "/say $arguments not found."; - } elsif($factoids->{'.*'}->{$arguments}{type} ne 'module') { + } elsif ($factoids->{'.*'}->{$arguments}{type} ne 'module') { return "/say $arguments is not a module."; } else { delete $factoids->{'.*'}->{$arguments}; diff --git a/PBot/FactoidModuleLauncher.pm b/PBot/FactoidModuleLauncher.pm index e6689fd7..a3d83cb5 100644 --- a/PBot/FactoidModuleLauncher.pm +++ b/PBot/FactoidModuleLauncher.pm @@ -18,10 +18,10 @@ use Text::Balanced qw(extract_delimited); use JSON; # automatically reap children processes in background -$SIG{CHLD} = sub { while(waitpid(-1, WNOHANG) > 0) {} }; +$SIG{CHLD} = sub { while (waitpid(-1, WNOHANG) > 0) {} }; sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to Commands should be key/value pairs, not hash reference"); } @@ -36,7 +36,7 @@ sub initialize { my ($self, %conf) = @_; my $pbot = delete $conf{pbot}; - if(not defined $pbot) { + if (not defined $pbot) { Carp::croak("Missing pbot reference to PBot::FactoidModuleLauncher"); } @@ -58,7 +58,7 @@ sub execute_module { my @factoids = $self->{pbot}->{factoids}->find_factoid($stuff->{from}, $stuff->{keyword}, undef, 2, 2); - if(not @factoids or not $factoids[0]) { + if (not @factoids or not $factoids[0]) { $stuff->{checkflood} = 1; $self->{pbot}->{interpreter}->handle_result($stuff, "/msg $stuff->{nick} Failed to find module for '$stuff->{keyword}' in channel $stuff->{from}\n"); return; @@ -86,7 +86,7 @@ sub execute_module { if ($self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{modulelauncher_subpattern} =~ m/s\/(.*?)\/(.*)\/(.*)/) { my ($p1, $p2, $p3) = ($1, $2, $3); my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $before, $after); - if($p3 eq 'g') { + if ($p3 eq 'g') { $stuff->{arguments} =~ s/$p1/$p2/g; ($a, $b, $c, $d, $e, $f, $g, $h, $i, $before, $after) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $`, $'); } else { @@ -113,12 +113,12 @@ sub execute_module { $self->{arguments} = ""; my $lr; - while(1) { + while (1) { my ($e, $r, $p) = extract_delimited($argsbuf, "'", "[^']+"); $lr = $r if not defined $lr; - if(defined $e) { + if (defined $e) { $e =~ s/\\([^\w])/$1/g; $e =~ s/'/'\\''/g; $e =~ s/^'\\''/'/; @@ -135,7 +135,7 @@ sub execute_module { pipe(my $reader, my $writer); my $pid = fork; - if(not defined $pid) { + if (not defined $pid) { $self->{pbot}->{logger}->log("Could not fork module: $!\n"); close $reader; close $writer; @@ -146,7 +146,7 @@ sub execute_module { # FIXME -- add check to ensure $module exists - if($pid == 0) { # start child block + if ($pid == 0) { # start child block close $reader; # don't quit the IRC client when the child dies @@ -154,12 +154,12 @@ sub execute_module { *PBot::IRC::Connection::DESTROY = sub { return; }; use warnings; - if(not chdir $module_dir) { + if (not chdir $module_dir) { $self->{pbot}->{logger}->log("Could not chdir to '$module_dir': $!\n"); Carp::croak("Could not chdir to '$module_dir': $!"); } - if(exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{workdir}) { + if (exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{workdir}) { chdir $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{workdir}; } diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 837c1409..6143c209 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -35,7 +35,7 @@ use PBot::Utils::Indefinite; use PBot::Utils::ValidateString; sub new { - if(ref($_[1]) eq 'HASH') { + if (ref($_[1]) eq 'HASH') { Carp::croak("Options to Factoids should be key/value pairs, not hash reference"); } @@ -144,7 +144,7 @@ sub remove_factoid { delete $self->{factoids}->hash->{$channel}->{$trigger}; - if(not scalar keys %{ $self->{factoids}->hash->{$channel} }) { + if (not scalar keys %{ $self->{factoids}->hash->{$channel} }) { delete $self->{factoids}->hash->{$channel}; } @@ -155,7 +155,7 @@ sub export_factoids { my $self = shift; my $filename; - if(@_) { $filename = shift; } else { $filename = $self->export_path; } + if (@_) { $filename = shift; } else { $filename = $self->export_path; } return if not defined $filename; open FILE, "> $filename" or return "Could not open export path."; @@ -197,9 +197,9 @@ sub export_factoids { $table_id++; foreach my $trigger (sort keys %{ $self->{factoids}->hash->{$channel} }) { - if($self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'text') { + if ($self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'text') { $i++; - if($i % 2) { + if ($i % 2) { print FILE "\n"; } else { print FILE "\n"; @@ -219,7 +219,7 @@ sub export_factoids { $action = encode_entities($action); } - if(exists $self->{factoids}->hash->{$channel}->{$trigger}->{action_with_args}) { + if (exists $self->{factoids}->hash->{$channel}->{$trigger}->{action_with_args}) { my $with_args = $self->{factoids}->hash->{$channel}->{$trigger}->{action_with_args}; $with_args =~ s/(.*?)http(s?:\/\/[^ ]+)/encode_entities($1) . "http" . encode_entities($2) . "<\/a>"/ge; $with_args =~ s/(.*)<\/a>(.*$)/"$1<\/a>" . encode_entities($2)/e; @@ -228,7 +228,7 @@ sub export_factoids { print FILE "" . encode_entities($trigger) . " is $action\n"; } - if(exists $self->{factoids}->hash->{$channel}->{$trigger}->{edited_by}) { + if (exists $self->{factoids}->hash->{$channel}->{$trigger}->{edited_by}) { print FILE "" . $self->{factoids}->hash->{$channel}->{$trigger}->{edited_by} . "\n"; print FILE "" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->{factoids}->hash->{$channel}->{$trigger}->{edited_on}) . "\n"; } else { @@ -238,7 +238,7 @@ sub export_factoids { print FILE "" . encode_entities($self->{factoids}->hash->{$channel}->{$trigger}->{ref_user}) . "\n"; - if(exists $self->{factoids}->hash->{$channel}->{$trigger}->{last_referenced_on}) { + if (exists $self->{factoids}->hash->{$channel}->{$trigger}->{last_referenced_on}) { print FILE "" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->{factoids}->hash->{$channel}->{$trigger}->{last_referenced_on}) . "\n"; } else { print FILE "\n"; @@ -256,7 +256,7 @@ sub export_factoids { print FILE "