Remove PBot getter/setters; move anti-flood registry defaults to AntiFlood.pm

This commit is contained in:
Pragmatic Software 2014-05-18 20:09:05 +00:00
parent bf4920b866
commit 30e3c5ce35
30 changed files with 687 additions and 802 deletions

View File

@ -49,10 +49,18 @@ sub initialize {
$self->{ban_whitelist} = PBot::DualIndexHashObject->new(name => 'BanWhitelist', filename => $filename); $self->{ban_whitelist} = PBot::DualIndexHashObject->new(name => 'BanWhitelist', filename => $filename);
$self->{ban_whitelist}->load; $self->{ban_whitelist}->load;
$self->{pbot}->timer->register(sub { $self->adjust_offenses }, 60 * 60 * 1); $self->{pbot}->{timer}->register(sub { $self->adjust_offenses }, 60 * 60 * 1);
$self->{pbot}->commands->register(sub { return $self->unbanme(@_) }, "unbanme", 0); $self->{pbot}->{registry}->add_default('text', 'antiflood', 'max_join_flood', $conf{max_join_flood} // 4);
$self->{pbot}->commands->register(sub { return $self->whitelist(@_) }, "whitelist", 10); $self->{pbot}->{registry}->add_default('text', 'antiflood', 'max_chat_flood', $conf{max_chat_flood} // 4);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'max_enter_flood', $conf{max_enter_flood} // 4);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'max_nick_flood', $conf{max_nick_flood} // 3);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_lines', $conf{enter_abuse_max_lines} // 4);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_seconds', $conf{enter_abuse_max_seconds} // 20);
$self->{pbot}->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_offenses', $conf{enter_abuse_max_offenses} // 3);
$self->{pbot}->{commands}->register(sub { return $self->unbanme(@_) }, "unbanme", 0);
$self->{pbot}->{commands}->register(sub { return $self->whitelist(@_) }, "whitelist", 10);
} }
sub ban_whitelisted { sub ban_whitelisted {
@ -60,7 +68,7 @@ sub ban_whitelisted {
$channel = lc $channel; $channel = lc $channel;
$mask = lc $mask; $mask = lc $mask;
#$self->{pbot}->logger->log("whitelist check: $channel, $mask\n"); #$self->{pbot}->{logger}->log("whitelist check: $channel, $mask\n");
return (exists $self->{ban_whitelist}->hash->{$channel}->{$mask} and defined $self->{ban_whitelist}->hash->{$channel}->{$mask}->{ban_whitelisted}) ? 1 : 0; return (exists $self->{ban_whitelist}->hash->{$channel}->{$mask} and defined $self->{ban_whitelist}->hash->{$channel}->{$mask}->{ban_whitelisted}) ? 1 : 0;
} }
@ -162,7 +170,7 @@ sub check_flood {
my $account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host); my $account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host);
if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
$self->{pbot}->logger->log(sprintf("%-14s | %-65s | %s\n", "NICKCHANGE", $mask, $text)); $self->{pbot}->{logger}->log(sprintf("%-14s | %-65s | %s\n", "NICKCHANGE", $mask, $text));
my ($newnick) = $text =~ m/NICKCHANGE (.*)/; my ($newnick) = $text =~ m/NICKCHANGE (.*)/;
if($newnick =~ m/^Guest\d+$/) { if($newnick =~ m/^Guest\d+$/) {
@ -171,7 +179,7 @@ sub check_flood {
$self->{nickflood}->{$account}->{changes}++; $self->{nickflood}->{$account}->{changes}++;
} }
} else { } else {
$self->{pbot}->logger->log(sprintf("%-14s | %-65s | %s\n", $channel eq $mask ? "QUIT" : $channel, $mask, $text)); $self->{pbot}->{logger}->log(sprintf("%-14s | %-65s | %s\n", $channel eq $mask ? "QUIT" : $channel, $mask, $text));
} }
# handle QUIT events # handle QUIT events
@ -211,7 +219,7 @@ 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 # 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); return if ($channel =~ /^#/) and (not exists $self->{pbot}->{channels}->{channels}->hash->{$channel} or $self->{pbot}->{channels}->{channels}->hash->{$channel}{chanop} == 0);
if($channel =~ /^#/ and $mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { if($channel =~ /^#/ and $mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
# remove validation on PART so we check for ban-evasion when user returns at a later time # remove validation on PART so we check for ban-evasion when user returns at a later time
@ -223,7 +231,7 @@ sub check_flood {
} }
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"); $self->{pbot}->{logger}->log("Warning: max_messages greater than max_messages limit; truncating.\n");
$max_messages = $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages'); $max_messages = $self->{pbot}->{registry}->get_value('messagehistory', 'max_messages');
} }
@ -232,14 +240,14 @@ sub check_flood {
if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
# don't check for evasion on PART/KICK # don't check for evasion on PART/KICK
} else { } else {
$self->{pbot}->conn->whois($nick); $self->{pbot}->{conn}->whois($nick);
$self->check_bans($account, $mask, $channel); $self->check_bans($account, $mask, $channel);
} }
} }
# do not do flood enforcement for this event if bot is lagging # 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->{pbot}->{logger}->log("Disregarding enforcement of anti-flood due to lag: " . $self->{pbot}->{lagchecker}->lagstring . "\n");
return; return;
} }
@ -260,20 +268,20 @@ sub check_flood {
if(++$channel_data->{enter_abuses} >= $enter_abuse_max_offenses) { if(++$channel_data->{enter_abuses} >= $enter_abuse_max_offenses) {
my $offenses = $channel_data->{enter_abuses} - $enter_abuse_max_offenses + 1; my $offenses = $channel_data->{enter_abuses} - $enter_abuse_max_offenses + 1;
my $ban_length = $offenses ** $offenses * $offenses * 30; my $ban_length = $offenses ** $offenses * $offenses * 30;
$self->{pbot}->chanops->ban_user_timed("*!$user\@$host", $channel, $ban_length); $self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $ban_length);
$ban_length = duration($ban_length); $ban_length = duration($ban_length);
$self->{pbot}->logger->log("$nick $channel enter abuse offense " . $channel_data->{enter_abuses} . " earned $ban_length ban\n"); $self->{pbot}->{logger}->log("$nick $channel enter abuse offense " . $channel_data->{enter_abuses} . " earned $ban_length ban\n");
$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."); $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.");
} else { } else {
#$self->{pbot}->logger->log("$nick $channel enter abuses counter incremented to " . $channel_data->{enter_abuses} . "\n"); #$self->{pbot}->{logger}->log("$nick $channel enter abuses counter incremented to " . $channel_data->{enter_abuses} . "\n");
} }
} else { } else {
#$self->{pbot}->logger->log("$nick $channel enter abuse counter incremented to " . $channel_data->{enter_abuse} . "\n"); #$self->{pbot}->{logger}->log("$nick $channel enter abuse counter incremented to " . $channel_data->{enter_abuse} . "\n");
} }
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
} else { } else {
if($channel_data->{enter_abuse} > 0) { if($channel_data->{enter_abuse} > 0) {
#$self->{pbot}->logger->log("$nick $channel more than $enter_abuse_max_seconds seconds since last message, enter abuse counter reset\n"); #$self->{pbot}->{logger}->log("$nick $channel more than $enter_abuse_max_seconds seconds since last message, enter abuse counter reset\n");
$channel_data->{enter_abuse} = 0; $channel_data->{enter_abuse} = 0;
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
} }
@ -281,7 +289,7 @@ sub check_flood {
} else { } else {
$self->{channels}->{$channel}->{last_spoken_nick} = $nick; $self->{channels}->{$channel}->{last_spoken_nick} = $nick;
if($channel_data->{enter_abuse} > 0) { if($channel_data->{enter_abuse} > 0) {
#$self->{pbot}->logger->log("$nick $channel enter abuse counter reset\n"); #$self->{pbot}->{logger}->log("$nick $channel enter abuse counter reset\n");
$channel_data->{enter_abuse} = 0; $channel_data->{enter_abuse} = 0;
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
} }
@ -307,17 +315,17 @@ sub check_flood {
return; return;
} }
else { else {
$self->{pbot}->logger->log("Unknown flood mode [$mode] ... aborting flood enforcement.\n"); $self->{pbot}->{logger}->log("Unknown flood mode [$mode] ... aborting flood enforcement.\n");
return; return;
} }
my $last = $self->{pbot}->{messagehistory}->{database}->recall_message_by_count($account, $channel, 0); 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(" msg: [$msg->{timestamp}] $msg->{msg}\n");
#$self->{pbot}->logger->log("last: [$last->{timestamp}] $last->{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"); #$self->{pbot}->{logger}->log("Comparing message timestamps $last->{timestamp} - $msg->{timestamp} = " . ($last->{timestamp} - $msg->{timestamp}) . " against max_time $max_time\n");
if($last->{timestamp} - $msg->{timestamp} <= $max_time && not $self->{pbot}->admins->loggedin($channel, "$nick!$user\@$host")) { if($last->{timestamp} - $msg->{timestamp} <= $max_time && not $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host")) {
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'); 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"); #$self->{pbot}->{logger}->log("$account offenses $channel_data->{offenses}, join watch $channel_data->{join_watch}, max messages $max_messages\n");
@ -328,16 +336,16 @@ sub check_flood {
my $timeout = (2 ** (($channel_data->{offenses} + 2) < 10 ? $channel_data->{offenses} + 2 : 10)); my $timeout = (2 ** (($channel_data->{offenses} + 2) < 10 ? $channel_data->{offenses} + 2 : 10));
my $banmask = address_to_mask($host); my $banmask = address_to_mask($host);
$self->{pbot}->chanops->ban_user_timed("*!$user\@$banmask\$##stop_join_flood", $channel, $timeout * 60 * 60); $self->{pbot}->{chanops}->ban_user_timed("*!$user\@$banmask\$##stop_join_flood", $channel, $timeout * 60 * 60);
$self->{pbot}->logger->log("$nick!$user\@$banmask banned for $timeout hours due to join flooding (offense #" . $channel_data->{offenses} . ").\n"); $self->{pbot}->{logger}->log("$nick!$user\@$banmask banned for $timeout hours due to join flooding (offense #" . $channel_data->{offenses} . ").\n");
$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."); $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.");
$channel_data->{join_watch} = $max_messages - 2; # give them a chance to rejoin $channel_data->{join_watch} = $max_messages - 2; # give them a chance to rejoin
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
} }
} elsif($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) { } elsif($mode == $self->{pbot}->{messagehistory}->{MSG_CHAT}) {
if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise) if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise)
# don't increment offenses again if already banned # don't increment offenses again if already banned
return if $self->{pbot}->chanops->{unban_timeout}->find_index($channel, "*!$user\@$host"); return if $self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, "*!$user\@$host");
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense'); my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense');
$channel_data->{offenses}++; $channel_data->{offenses}++;
@ -346,14 +354,14 @@ sub check_flood {
my $length = $channel_data->{offenses} ** $channel_data->{offenses} * $channel_data->{offenses} * 30; my $length = $channel_data->{offenses} ** $channel_data->{offenses} * $channel_data->{offenses} * 30;
$self->{pbot}->chanops->ban_user_timed("*!$user\@$host", $channel, $length); $self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $length);
$length = duration($length); $length = duration($length);
$self->{pbot}->logger->log("$nick $channel flood offense " . $channel_data->{offenses} . " earned $length ban\n"); $self->{pbot}->{logger}->log("$nick $channel flood offense " . $channel_data->{offenses} . " earned $length ban\n");
$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."); $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.");
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
} }
else { # private message flood else { # private message flood
return if exists ${ $self->{pbot}->ignorelist->{ignore_list} }{"$nick!$user\@$host"}{$channel}; return if exists ${ $self->{pbot}->{ignorelist}->{ignore_list} }{"$nick!$user\@$host"}{$channel};
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense'); my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'offenses', 'last_offense');
$channel_data->{offenses}++; $channel_data->{offenses}++;
@ -362,10 +370,10 @@ sub check_flood {
my $length = $channel_data->{offenses} ** $channel_data->{offenses} * $channel_data->{offenses} * 30; my $length = $channel_data->{offenses} ** $channel_data->{offenses} * $channel_data->{offenses} * 30;
$self->{pbot}->ignorelist->{commands}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length"); $self->{pbot}->{ignorelist}->{commands}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");
$length = duration($length); $length = duration($length);
$self->{pbot}->logger->log("$nick msg flood offense " . $channel_data->{offenses} . " earned $length ignore\n"); $self->{pbot}->{logger}->log("$nick msg flood offense " . $channel_data->{offenses} . " earned $length ignore\n");
$self->{pbot}->conn->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length."); $self->{pbot}->{conn}->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length.");
} }
} elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} and $self->{nickflood}->{$account}->{changes} >= $max_messages) { } elsif($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE} and $self->{nickflood}->{$account}->{changes} >= $max_messages) {
($nick) = $text =~ m/NICKCHANGE (.*)/; ($nick) = $text =~ m/NICKCHANGE (.*)/;
@ -378,12 +386,12 @@ sub check_flood {
my @channels = $self->{pbot}->{messagehistory}->{database}->get_channels($account); my @channels = $self->{pbot}->{messagehistory}->{database}->get_channels($account);
foreach my $chan (@channels) { foreach my $chan (@channels) {
$self->{pbot}->chanops->ban_user_timed("*!$user\@$host", $chan, $length); $self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $chan, $length);
} }
$length = duration($length); $length = duration($length);
$self->{pbot}->logger->log("$nick nickchange flood offense " . $self->{nickflood}->{$account}->{offenses} . " earned $length ban\n"); $self->{pbot}->{logger}->log("$nick nickchange flood offense " . $self->{nickflood}->{$account}->{offenses} . " earned $length ban\n");
$self->{pbot}->conn->privmsg($nick, "You have been temporarily banned due to nick-change flooding. You will be unbanned in $length."); $self->{pbot}->{conn}->privmsg($nick, "You have been temporarily banned due to nick-change flooding. You will be unbanned in $length.");
} }
} }
} }
@ -409,16 +417,16 @@ sub unbanme {
my @nickserv_accounts = $self->{pbot}->{messagehistory}->{database}->get_nickserv_accounts($message_account); my @nickserv_accounts = $self->{pbot}->{messagehistory}->{database}->get_nickserv_accounts($message_account);
foreach my $nickserv_account (@nickserv_accounts) { foreach my $nickserv_account (@nickserv_accounts) {
my $baninfos = $self->{pbot}->bantracker->get_baninfo("$nick!$user\@$host", $channel, $nickserv_account); my $baninfos = $self->{pbot}->{bantracker}->get_baninfo("$nick!$user\@$host", $channel, $nickserv_account);
if(defined $baninfos) { if(defined $baninfos) {
foreach my $baninfo (@$baninfos) { foreach my $baninfo (@$baninfos) {
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) { 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"); $self->{pbot}->{logger}->log("anti-flood: [unbanme] $nick!$user\@$host banned as $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n");
} else { } else {
if($channel eq lc $baninfo->{channel}) { if($channel eq lc $baninfo->{channel}) {
my $mode = $baninfo->{type} eq "+b" ? "banned" : "quieted"; 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"); $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."; return "/msg $nick You have been $mode as $baninfo->{banmask} by $baninfo->{owner}, unbanme will not work until it is removed.";
} }
} }
@ -431,7 +439,7 @@ sub unbanme {
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."; 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.";
} }
$self->{pbot}->chanops->unban_user($mask, $channel); $self->{pbot}->{chanops}->unban_user($mask, $channel);
return "/msg $nick You have been unbanned from $channel."; return "/msg $nick You have been unbanned from $channel.";
} }
@ -461,7 +469,7 @@ sub devalidate_accounts {
my ($self, $mask, $channel) = @_; my ($self, $mask, $channel) = @_;
my @message_accounts; my @message_accounts;
#$self->{pbot}->logger->log("Devalidating accounts for $mask in $channel\n"); #$self->{pbot}->{logger}->log("Devalidating accounts for $mask in $channel\n");
if($mask =~ m/^\$a:(.*)/) { if($mask =~ m/^\$a:(.*)/) {
my $ban_account = lc $1; my $ban_account = lc $1;
@ -474,7 +482,7 @@ sub devalidate_accounts {
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated'); 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}; $channel_data->{validated} &= ~$self->{NICKSERV_VALIDATED};
#$self->{pbot}->logger->log("Devalidating account $account\n"); #$self->{pbot}->{logger}->log("Devalidating account $account\n");
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
} }
} }
@ -483,13 +491,13 @@ sub devalidate_accounts {
sub check_bans { sub check_bans {
my ($self, $message_account, $mask, $channel) = @_; my ($self, $message_account, $mask, $channel) = @_;
#$self->{pbot}->logger->log("anti-flood: [check-bans] checking for bans on $mask in $channel\n"); #$self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans on $mask in $channel\n");
my @nickserv_accounts = $self->{pbot}->{messagehistory}->{database}->get_nickserv_accounts($message_account); 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); my $current_nickserv_account = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account);
if($current_nickserv_account) { if($current_nickserv_account) {
#$self->{pbot}->logger->log("anti-flood: [check-bans] current nickserv [$current_nickserv_account] found for $mask\n"); #$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'); my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated');
if($channel_data->{validated} & $self->{NEEDS_CHECKBAN}) { if($channel_data->{validated} & $self->{NEEDS_CHECKBAN}) {
$channel_data->{validated} &= ~$self->{NEEDS_CHECKBAN}; $channel_data->{validated} &= ~$self->{NEEDS_CHECKBAN};
@ -502,7 +510,7 @@ sub check_bans {
$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}->{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"); #$self->{pbot}->{logger}->log("anti-flood: [check-bans] no account for $mask; marking for later validation\n");
} }
my ($nick, $host) = $mask =~ m/^([^!]+)![^@]+\@(.*)$/; my ($nick, $host) = $mask =~ m/^([^!]+)![^@]+\@(.*)$/;
@ -518,7 +526,7 @@ sub check_bans {
foreach my $nickserv_account (@nickserv_accounts) { foreach my $nickserv_account (@nickserv_accounts) {
foreach my $key (@hostmask_nickserv_accounts) { foreach my $key (@hostmask_nickserv_accounts) {
if($key eq $nickserv_account) { if($key eq $nickserv_account) {
#$self->{pbot}->logger->log("anti-flood: [check-bans] nickserv account for $hostmask->{hostmask} matches $nickserv_account\n"); #$self->{pbot}->{logger}->log("anti-flood: [check-bans] nickserv account for $hostmask->{hostmask} matches $nickserv_account\n");
$check_ban = 1; $check_ban = 1;
goto CHECKBAN; goto CHECKBAN;
} }
@ -528,7 +536,7 @@ sub check_bans {
# check if hosts match # check if hosts match
my ($account_host) = $hostmask->{hostmask} =~ m/\@(.*)$/; my ($account_host) = $hostmask->{hostmask} =~ m/\@(.*)$/;
if($host eq $account_host) { if($host eq $account_host) {
#$self->{pbot}->logger->log("anti-flood: [check-bans] host for $hostmask->{hostmask} matches $mask\n"); #$self->{pbot}->{logger}->log("anti-flood: [check-bans] host for $hostmask->{hostmask} matches $mask\n");
$check_ban = 1; $check_ban = 1;
goto CHECKBAN; goto CHECKBAN;
} }
@ -536,7 +544,7 @@ sub check_bans {
# check if nicks match # check if nicks match
my ($account_nick) = $hostmask->{hostmask} =~ m/^([^!]+)/; my ($account_nick) = $hostmask->{hostmask} =~ m/^([^!]+)/;
if($nick eq $account_nick) { if($nick eq $account_nick) {
#$self->{pbot}->logger->log("anti-flood: [check-bans] nick for $hostmask->{hostmask} matches $mask\n"); #$self->{pbot}->{logger}->log("anti-flood: [check-bans] nick for $hostmask->{hostmask} matches $mask\n");
$check_ban = 1; $check_ban = 1;
goto CHECKBAN; goto CHECKBAN;
} }
@ -548,13 +556,13 @@ sub check_bans {
} }
foreach my $target_nickserv_account (@hostmask_nickserv_accounts) { 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"); #$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); my $baninfos = $self->{pbot}->{bantracker}->get_baninfo($hostmask->{hostmask}, $channel, $target_nickserv_account);
if(defined $baninfos) { if(defined $baninfos) {
foreach my $baninfo (@$baninfos) { foreach my $baninfo (@$baninfos) {
if(time - $baninfo->{when} < 5) { 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"); $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'); 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}; $channel_data->{validated} &= ~$self->{NICKSERV_VALIDATED};
@ -565,12 +573,12 @@ sub check_bans {
} }
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) { 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"); $self->{pbot}->{logger}->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n");
next; next;
} }
if($baninfo->{type} eq '+b' and $baninfo->{banmask} =~ m/!\*@\*$/) { if($baninfo->{type} eq '+b' and $baninfo->{banmask} =~ m/!\*@\*$/) {
$self->{pbot}->logger->log("anti-flood: [check-bans] Disregarding generic nick ban\n"); $self->{pbot}->{logger}->log("anti-flood: [check-bans] Disregarding generic nick ban\n");
next; next;
} }
@ -579,14 +587,14 @@ sub check_bans {
$banmask_regex =~ s/\\\?/./g; $banmask_regex =~ s/\\\?/./g;
if($baninfo->{type} eq '+q' and $mask =~ /^$banmask_regex$/i) { 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"); $self->{pbot}->{logger}->log("anti-flood: [check-bans] Hostmask ($mask) matches quiet banmask ($banmask_regex), disregarding\n");
next; next;
} }
my $skip_quiet_nickserv_mask = 0; my $skip_quiet_nickserv_mask = 0;
foreach my $nickserv_account (@nickserv_accounts) { 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) { 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"); $self->{pbot}->{logger}->log("anti-flood: [check-bans] Hostmask ($mask) matches quiet on account ($nickserv_account), disregarding\n");
$skip_quiet_nickserv_mask = 1; $skip_quiet_nickserv_mask = 1;
} elsif($baninfo->{type} eq '+b' and $baninfo->{banmask} =~ /^\$a:(.*)/ and lc $1 eq $nickserv_account) { } elsif($baninfo->{type} eq '+b' and $baninfo->{banmask} =~ /^\$a:(.*)/ and lc $1 eq $nickserv_account) {
$skip_quiet_nickserv_mask = 0; $skip_quiet_nickserv_mask = 0;
@ -599,7 +607,7 @@ sub check_bans {
$bans = []; $bans = [];
} }
$self->{pbot}->logger->log("anti-flood: [check-bans] Hostmask ($mask) matches $baninfo->{type} $baninfo->{banmask}, adding ban\n"); $self->{pbot}->{logger}->log("anti-flood: [check-bans] Hostmask ($mask) matches $baninfo->{type} $baninfo->{banmask}, adding ban\n");
push @$bans, $baninfo; push @$bans, $baninfo;
next; next;
} }
@ -613,10 +621,10 @@ sub check_bans {
my $banmask = "*!$1@" . address_to_mask($2); my $banmask = "*!$1@" . address_to_mask($2);
foreach my $baninfo (@$bans) { 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"); $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/^([^!]+)/; my ($bannick) = $mask =~ m/^([^!]+)/;
$self->{pbot}->chanops->add_op_command($baninfo->{channel}, "kick $baninfo->{channel} $bannick Ban evasion"); $self->{pbot}->{chanops}->add_op_command($baninfo->{channel}, "kick $baninfo->{channel} $bannick Ban evasion");
$self->{pbot}->chanops->ban_user_timed($banmask, $baninfo->{channel}, 60 * 60 * 12); $self->{pbot}->{chanops}->ban_user_timed($banmask, $baninfo->{channel}, 60 * 60 * 12);
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated'); 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}; $channel_data->{validated} &= ~$self->{NICKSERV_VALIDATED};
@ -640,7 +648,7 @@ sub check_nickserv_accounts {
my $force_validation = 0; my $force_validation = 0;
my $message_account; my $message_account;
#$self->{pbot}->logger->log("Checking nickserv accounts for nick $nick with account $account and hostmask " . (defined $hostmask ? $hostmask : 'undef') . "\n"); #$self->{pbot}->{logger}->log("Checking nickserv accounts for nick $nick with account $account and hostmask " . (defined $hostmask ? $hostmask : 'undef') . "\n");
$account = lc $account; $account = lc $account;
@ -648,24 +656,24 @@ sub check_nickserv_accounts {
($message_account, $hostmask) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($nick); ($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"); $self->{pbot}->{logger}->log("No message account found for nick $nick.\n");
($message_account) = $self->{pbot}->{messagehistory}->{database}->find_message_accounts_by_nickserv($account); ($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"); $self->{pbot}->{logger}->log("No message account found for nickserv $account.\n");
return; return;
} }
} }
} else { } else {
($message_account) = $self->{pbot}->{messagehistory}->{database}->find_message_accounts_by_mask($hostmask); ($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"); $self->{pbot}->{logger}->log("No message account found for hostmask $hostmask.\n");
return; return;
} }
$force_validation = 1; $force_validation = 1;
} }
#$self->{pbot}->logger->log("anti-flood: $message_account: setting nickserv account to [$account]\n"); #$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}->update_nickserv_account($message_account, $account, scalar gettimeofday);
$self->{pbot}->{messagehistory}->{database}->set_current_nickserv_account($message_account, $account); $self->{pbot}->{messagehistory}->{database}->set_current_nickserv_account($message_account, $account);
@ -675,7 +683,7 @@ sub check_nickserv_accounts {
foreach my $channel (@channels) { foreach my $channel (@channels) {
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated'); my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated');
if($force_validation or $channel_data->{validated} & $self->{NEEDS_CHECKBAN}) { 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->{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); $self->check_bans($message_account, $hostmask, $channel);
} }
} }
@ -686,14 +694,14 @@ sub on_whoisaccount {
my $nick = $event->{args}[1]; my $nick = $event->{args}[1];
my $account = lc $event->{args}[2]; my $account = lc $event->{args}[2];
$self->{pbot}->logger->log("$nick is using NickServ account [$account]\n"); $self->{pbot}->{logger}->log("$nick is using NickServ account [$account]\n");
$self->check_nickserv_accounts($nick, $account); $self->check_nickserv_accounts($nick, $account);
} }
sub adjust_offenses { sub adjust_offenses {
my $self = shift; my $self = shift;
#$self->{pbot}->logger->log("Adjusting offenses . . .\n"); #$self->{pbot}->{logger}->log("Adjusting offenses . . .\n");
# decrease offenses counter if 24 hours have elapsed since latest offense # 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); my $channel_datas = $self->{pbot}->{messagehistory}->{database}->get_channel_datas_where_last_offense_older_than(gettimeofday - 60 * 60 * 24);
@ -703,7 +711,7 @@ sub adjust_offenses {
my $channel = delete $channel_data->{channel}; my $channel = delete $channel_data->{channel};
$channel_data->{offenses}--; $channel_data->{offenses}--;
$channel_data->{last_offense} = gettimeofday; $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}->{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); $self->{pbot}->{messagehistory}->{database}->update_channel_data($id, $channel, $channel_data);
} }
} }
@ -713,7 +721,7 @@ sub adjust_offenses {
my $id = delete $channel_data->{id}; my $id = delete $channel_data->{id};
my $channel = delete $channel_data->{channel}; my $channel = delete $channel_data->{channel};
$channel_data->{enter_abuses}--; $channel_data->{enter_abuses}--;
#$self->{pbot}->logger->log("[adjust-offenses] [$id][$channel] decreasing enter abuse offenses to $channel_data->{enter_abuses}\n"); #$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); $self->{pbot}->{messagehistory}->{database}->update_channel_data($id, $channel, $channel_data);
} }

View File

@ -36,7 +36,7 @@ sub initialize {
$self->{banlist} = {}; $self->{banlist} = {};
$pbot->commands->register(sub { return $self->dumpbans(@_) }, "dumpbans", 60); $pbot->{commands}->register(sub { return $self->dumpbans(@_) }, "dumpbans", 60);
} }
sub dumpbans { sub dumpbans {
@ -52,9 +52,9 @@ sub get_banlist {
delete $self->{banlist}->{$channel}; delete $self->{banlist}->{$channel};
$self->{pbot}->logger->log("Retrieving banlist for $channel.\n"); $self->{pbot}->{logger}->log("Retrieving banlist for $channel.\n");
$conn->sl("mode $channel +b"); ${conn}->sl("mode $channel +b");
$conn->sl("mode $channel +q"); ${conn}->sl("mode $channel +q");
} }
sub get_baninfo { sub get_baninfo {
@ -64,7 +64,7 @@ sub get_baninfo {
$account = undef if $account eq '-1'; $account = undef if $account eq '-1';
$account = lc $account if defined $account; $account = lc $account if defined $account;
$self->{pbot}->logger->log("[get-baninfo] Getting baninfo for $mask in $channel using account " . (defined $account ? $account : "[undefined]") . "\n"); $self->{pbot}->{logger}->log("[get-baninfo] Getting baninfo for $mask in $channel using account " . (defined $account ? $account : "[undefined]") . "\n");
foreach my $mode (keys %{ $self->{banlist}{$channel} }) { foreach my $mode (keys %{ $self->{banlist}{$channel} }) {
foreach my $banmask (keys %{ $self->{banlist}{$channel}{$mode} }) { foreach my $banmask (keys %{ $self->{banlist}{$channel}{$mode} }) {
@ -90,7 +90,7 @@ sub get_baninfo {
$baninfo->{owner} = $self->{banlist}{$channel}{$mode}{$banmask_key}[0]; $baninfo->{owner} = $self->{banlist}{$channel}{$mode}{$banmask_key}[0];
$baninfo->{when} = $self->{banlist}{$channel}{$mode}{$banmask_key}[1]; $baninfo->{when} = $self->{banlist}{$channel}{$mode}{$banmask_key}[1];
$baninfo->{type} = $mode; $baninfo->{type} = $mode;
$self->{pbot}->logger->log("get-baninfo: dump: " . Dumper($baninfo) . "\n"); $self->{pbot}->{logger}->log("get-baninfo: dump: " . Dumper($baninfo) . "\n");
push @$bans, $baninfo; push @$bans, $baninfo;
} }
@ -109,7 +109,7 @@ sub on_quietlist_entry {
my $ago = ago(gettimeofday - $timestamp); my $ago = ago(gettimeofday - $timestamp);
$self->{pbot}->logger->log("ban-tracker: [quietlist entry] $channel: $target quieted by $source $ago.\n"); $self->{pbot}->{logger}->log("ban-tracker: [quietlist entry] $channel: $target quieted by $source $ago.\n");
$self->{banlist}->{$channel}->{'+q'}->{$target} = [ $source, $timestamp ]; $self->{banlist}->{$channel}->{'+q'}->{$target} = [ $source, $timestamp ];
} }
@ -122,7 +122,7 @@ sub on_banlist_entry {
my $ago = ago(gettimeofday - $timestamp); my $ago = ago(gettimeofday - $timestamp);
$self->{pbot}->logger->log("ban-tracker: [banlist entry] $channel: $target banned by $source $ago.\n"); $self->{pbot}->{logger}->log("ban-tracker: [banlist entry] $channel: $target banned by $source $ago.\n");
$self->{banlist}->{$channel}->{'+b'}->{$target} = [ $source, $timestamp ]; $self->{banlist}->{$channel}->{'+b'}->{$target} = [ $source, $timestamp ];
} }
@ -131,24 +131,24 @@ sub track_mode {
my ($source, $mode, $target, $channel) = @_; my ($source, $mode, $target, $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->{pbot}->{logger}->log("ban-tracker: $target " . ($mode eq '+b' ? 'banned' : 'quieted') . " by $source in $channel.\n");
$self->{banlist}->{$channel}->{$mode}->{$target} = [ $source, gettimeofday ]; $self->{banlist}->{$channel}->{$mode}->{$target} = [ $source, gettimeofday ];
$self->{pbot}->antiflood->devalidate_accounts($target, $channel); $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"); $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}; delete $self->{banlist}->{$channel}->{$mode eq "-b" ? "+b" : "+q"}->{$target};
if($mode eq "-b") { if($mode eq "-b") {
if($self->{pbot}->chanops->{unban_timeout}->find_index($channel, $target)) { if($self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, $target)) {
$self->{pbot}->chanops->{unban_timeout}->remove($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 # 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"); $self->{pbot}->{chanops}->{unban_timeout}->remove($channel, "$target\$##stop_join_flood");
} }
} }
} else { } else {
$self->{pbot}->logger->log("BanTracker: Unknown mode '$mode'\n"); $self->{pbot}->{logger}->log("BanTracker: Unknown mode '$mode'\n");
} }
} }

View File

@ -32,24 +32,24 @@ sub initialize {
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$pbot->commands->register(sub { return $self->login(@_) }, "login", 0); $pbot->{commands}->register(sub { return $self->login(@_) }, "login", 0);
$pbot->commands->register(sub { return $self->logout(@_) }, "logout", 0); $pbot->{commands}->register(sub { return $self->logout(@_) }, "logout", 0);
$pbot->commands->register(sub { return $self->join_channel(@_) }, "join", 45); $pbot->{commands}->register(sub { return $self->join_channel(@_) }, "join", 45);
$pbot->commands->register(sub { return $self->part_channel(@_) }, "part", 45); $pbot->{commands}->register(sub { return $self->part_channel(@_) }, "part", 45);
$pbot->commands->register(sub { return $self->ack_die(@_) }, "die", 50); $pbot->{commands}->register(sub { return $self->ack_die(@_) }, "die", 50);
$pbot->commands->register(sub { return $self->adminadd(@_) }, "adminadd", 60); $pbot->{commands}->register(sub { return $self->adminadd(@_) }, "adminadd", 60);
$pbot->commands->register(sub { return $self->adminrem(@_) }, "adminrem", 60); $pbot->{commands}->register(sub { return $self->adminrem(@_) }, "adminrem", 60);
$pbot->commands->register(sub { return $self->adminset(@_) }, "adminset", 60); $pbot->{commands}->register(sub { return $self->adminset(@_) }, "adminset", 60);
$pbot->commands->register(sub { return $self->adminunset(@_) }, "adminunset", 60); $pbot->{commands}->register(sub { return $self->adminunset(@_) }, "adminunset", 60);
$pbot->commands->register(sub { return $self->sl(@_) }, "sl", 60); $pbot->{commands}->register(sub { return $self->sl(@_) }, "sl", 60);
$pbot->commands->register(sub { return $self->export(@_) }, "export", 60); $pbot->{commands}->register(sub { return $self->export(@_) }, "export", 60);
} }
sub sl { sub sl {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
$self->{pbot}->conn->sl($arguments); $self->{pbot}->{conn}->sl($arguments);
return "Sent.\n"; return "Sent.\n";
} }
@ -57,19 +57,19 @@ sub login {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
if($self->{pbot}->admins->loggedin($from, "$nick!$user\@$host")) { if($self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host")) {
return "/msg $nick You are already logged into channel $from."; return "/msg $nick You are already logged into channel $from.";
} }
my $result = $self->{pbot}->admins->login($from, "$nick!$user\@$host", $arguments); my $result = $self->{pbot}->{admins}->login($from, "$nick!$user\@$host", $arguments);
return "/msg $nick $result"; return "/msg $nick $result";
} }
sub logout { sub logout {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; 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"); $self->{pbot}->{admins}->logout($from, "$nick!$user\@$host");
return "/msg $nick Good-bye, $nick."; return "/msg $nick Good-bye, $nick.";
} }
@ -114,7 +114,7 @@ sub adminset {
return "Usage: adminset <channel> <hostmask> <key> <value>"; return "Usage: adminset <channel> <hostmask> <key> <value>";
} }
return $self->{pbot}->admins->admins->set($channel, $hostmask, $key, $value); return $self->{pbot}->{admins}->{admins}->set($channel, $hostmask, $key, $value);
} }
sub adminunset { sub adminunset {
@ -126,7 +126,7 @@ sub adminunset {
return "Usage: adminunset <channel> <hostmask> <key>"; return "Usage: adminunset <channel> <hostmask> <key>";
} }
return $self->{pbot}->admins->admins->unset($channel, $hostmask, $key); return $self->{pbot}->{admins}->{admins}->unset($channel, $hostmask, $key);
} }
@ -135,8 +135,8 @@ sub join_channel {
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
foreach my $channel (split /\s+/, $arguments) { foreach my $channel (split /\s+/, $arguments) {
$self->{pbot}->logger->log("$nick!$user\@$host made me join $channel\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host made me join $channel\n");
$self->{pbot}->conn->join($channel); $self->{pbot}->{conn}->join($channel);
} }
return "/msg $nick Joining $arguments"; return "/msg $nick Joining $arguments";
@ -149,8 +149,8 @@ sub part_channel {
$arguments = $from if not $arguments; $arguments = $from if not $arguments;
foreach my $channel (split /\s+/, $arguments) { foreach my $channel (split /\s+/, $arguments) {
$self->{pbot}->logger->log("$nick!$user\@$host made me part $channel\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host made me part $channel\n");
$self->{pbot}->conn->part($channel); $self->{pbot}->{conn}->part($channel);
} }
return "/msg $nick Parting $arguments"; return "/msg $nick Parting $arguments";
@ -159,10 +159,10 @@ sub part_channel {
sub ack_die { sub ack_die {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
$self->{pbot}->logger->log("$nick!$user\@$host made me exit.\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host made me exit.\n");
$self->{pbot}->atexit(); $self->{pbot}->atexit();
$self->{pbot}->conn->privmsg($from, "Good-bye.") if defined $from; $self->{pbot}->{conn}->privmsg($from, "Good-bye.") if defined $from;
$self->{pbot}->conn->quit("Departure requested."); $self->{pbot}->{conn}->quit("Departure requested.");
exit 0; exit 0;
} }
@ -179,11 +179,11 @@ sub export {
} }
if($arguments =~ /^quotegrabs$/i) { if($arguments =~ /^quotegrabs$/i) {
return $self->{pbot}->quotegrabs->export_quotegrabs; return $self->{pbot}->{quotegrabs}->export_quotegrabs;
} }
if($arguments =~ /^factoids$/i) { if($arguments =~ /^factoids$/i) {
return $self->{pbot}->factoids->export_factoids; return $self->{pbot}->{factoids}->export_factoids;
} }
if($arguments =~ /^admins$/i) { if($arguments =~ /^admins$/i) {

View File

@ -58,11 +58,11 @@ sub add_admin {
$channel = lc $channel; $channel = lc $channel;
$hostmask = lc $hostmask; $hostmask = lc $hostmask;
$self->admins->hash->{$channel}->{$hostmask}->{name} = $name; $self->{admins}->hash->{$channel}->{$hostmask}->{name} = $name;
$self->admins->hash->{$channel}->{$hostmask}->{level} = $level; $self->{admins}->hash->{$channel}->{$hostmask}->{level} = $level;
$self->admins->hash->{$channel}->{$hostmask}->{password} = $password; $self->{admins}->hash->{$channel}->{$hostmask}->{password} = $password;
$self->{pbot}->logger->log("Adding new level $level admin: [$name] [$hostmask] for channel [$channel]\n"); $self->{pbot}->{logger}->log("Adding new level $level admin: [$name] [$hostmask] for channel [$channel]\n");
$self->save_admins unless $dont_save; $self->save_admins unless $dont_save;
} }
@ -71,13 +71,13 @@ sub remove_admin {
my $self = shift; my $self = shift;
my ($channel, $hostmask) = @_; my ($channel, $hostmask) = @_;
my $admin = delete $self->admins->hash->{$channel}->{$hostmask}; my $admin = delete $self->{admins}->hash->{$channel}->{$hostmask};
if(defined $admin) { if(defined $admin) {
$self->{pbot}->logger->log("Removed level $admin->{level} admin [$admin->{name}] [$hostmask] from channel [$channel]\n"); $self->{pbot}->{logger}->log("Removed level $admin->{level} admin [$admin->{name}] [$hostmask] from channel [$channel]\n");
$self->save_admins; $self->save_admins;
return 1; return 1;
} else { } else {
$self->{pbot}->logger->log("Attempt to remove non-existent admin [$hostmask] from channel [$channel]\n"); $self->{pbot}->{logger}->log("Attempt to remove non-existent admin [$hostmask] from channel [$channel]\n");
return 0; return 0;
} }
} }
@ -86,43 +86,43 @@ sub load_admins {
my $self = shift; my $self = shift;
my $filename; 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"; Carp::carp "No admins path specified -- skipping loading of admins";
return; return;
} }
$self->{pbot}->logger->log("Loading admins from $filename ...\n"); $self->{pbot}->{logger}->log("Loading admins from $filename ...\n");
$self->admins->load; $self->{admins}->load;
my $i = 0; my $i = 0;
foreach my $channel (keys %{ $self->admins->hash } ) { foreach my $channel (keys %{ $self->{admins}->hash } ) {
foreach my $hostmask (keys %{ $self->admins->hash->{$channel} }) { foreach my $hostmask (keys %{ $self->{admins}->hash->{$channel} }) {
$i++; $i++;
my $name = $self->admins->hash->{$channel}->{$hostmask}->{name}; my $name = $self->{admins}->hash->{$channel}->{$hostmask}->{name};
my $level = $self->admins->hash->{$channel}->{$hostmask}->{level}; my $level = $self->{admins}->hash->{$channel}->{$hostmask}->{level};
my $password = $self->admins->hash->{$channel}->{$hostmask}->{password}; 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"; Carp::croak "Syntax error around line $i of $filename\n";
} }
$self->{pbot}->logger->log("Adding new level $level admin: [$name] [$hostmask] for channel [$channel]\n"); $self->{pbot}->{logger}->log("Adding new level $level admin: [$name] [$hostmask] for channel [$channel]\n");
} }
} }
$self->{pbot}->logger->log(" $i admins loaded.\n"); $self->{pbot}->{logger}->log(" $i admins loaded.\n");
$self->{pbot}->logger->log("Done.\n"); $self->{pbot}->{logger}->log("Done.\n");
} }
sub save_admins { sub save_admins {
my $self = shift; my $self = shift;
$self->admins->save; $self->{admins}->save;
$self->export_admins; $self->export_admins;
} }
@ -143,10 +143,10 @@ sub find_admin {
$hostmask = '.*' if not defined $hostmask; $hostmask = '.*' if not defined $hostmask;
my $result = eval { my $result = eval {
foreach my $channel_regex (keys %{ $self->admins->hash }) { foreach my $channel_regex (keys %{ $self->{admins}->hash }) {
if($from !~ m/^#/) { if($from !~ m/^#/) {
# if not from a channel, make sure that nick portion of hostmask matches $from # if not from a channel, make sure that nick portion of hostmask matches $from
foreach my $hostmask_regex (keys %{ $self->admins->hash->{$channel_regex} }) { foreach my $hostmask_regex (keys %{ $self->{admins}->hash->{$channel_regex} }) {
my $nick; my $nick;
if($hostmask_regex =~ m/^([^!]+)!.*/) { if($hostmask_regex =~ m/^([^!]+)!.*/) {
@ -155,11 +155,11 @@ sub find_admin {
$nick = $hostmask_regex; $nick = $hostmask_regex;
} }
return $self->admins->hash->{$channel_regex}->{$hostmask_regex} if($from =~ m/$nick/i and $hostmask =~ m/$hostmask_regex/i); return $self->{admins}->hash->{$channel_regex}->{$hostmask_regex} if($from =~ m/$nick/i and $hostmask =~ m/$hostmask_regex/i);
} }
} elsif($from =~ m/$channel_regex/i) { } elsif($from =~ m/$channel_regex/i) {
foreach my $hostmask_regex (keys %{ $self->admins->hash->{$channel_regex} }) { foreach my $hostmask_regex (keys %{ $self->{admins}->hash->{$channel_regex} }) {
return $self->admins->hash->{$channel_regex}->{$hostmask_regex} if $hostmask =~ m/$hostmask_regex/i; return $self->{admins}->hash->{$channel_regex}->{$hostmask_regex} if $hostmask =~ m/$hostmask_regex/i;
} }
} }
} }
@ -167,7 +167,7 @@ sub find_admin {
}; };
if($@) { if($@) {
$self->{pbot}->logger->log("Error in find_admin parameters: $@\n"); $self->{pbot}->{logger}->log("Error in find_admin parameters: $@\n");
} }
return $result; return $result;
@ -191,18 +191,18 @@ sub login {
my $admin = $self->find_admin($channel, $hostmask); 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"); $self->{pbot}->{logger}->log("Attempt to login non-existent [$channel][$hostmask] failed\n");
return "You do not have an account in $channel."; 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"); $self->{pbot}->{logger}->log("Bad login password for [$channel][$hostmask]\n");
return "I don't think so."; return "I don't think so.";
} }
$admin->{loggedin} = 1; $admin->{loggedin} = 1;
$self->{pbot}->logger->log("$hostmask logged into $channel\n"); $self->{pbot}->{logger}->log("$hostmask logged into $channel\n");
return "Logged into $channel."; return "Logged into $channel.";
} }

View File

@ -32,9 +32,9 @@ sub initialize {
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$pbot->commands->register(sub { return $self->ban_user(@_) }, "ban", 10); $pbot->{commands}->register(sub { return $self->ban_user(@_) }, "ban", 10);
$pbot->commands->register(sub { return $self->unban_user(@_) }, "unban", 10); $pbot->{commands}->register(sub { return $self->unban_user(@_) }, "unban", 10);
$pbot->commands->register(sub { return $self->kick_user(@_) }, "kick", 10); $pbot->{commands}->register(sub { return $self->kick_user(@_) }, "kick", 10);
} }
sub ban_user { sub ban_user {
@ -43,7 +43,7 @@ sub ban_user {
my ($target, $length) = split(/\s+/, $arguments); my ($target, $length) = split(/\s+/, $arguments);
if(not defined $from) { if(not defined $from) {
$self->{pbot}->logger->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
@ -62,7 +62,7 @@ sub ban_user {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
return "" if $target =~ /\Q$botnick\E/i; return "" if $target =~ /\Q$botnick\E/i;
$self->{pbot}->chanops->ban_user_timed($target, $from, $length); $self->{pbot}->{chanops}->ban_user_timed($target, $from, $length);
return "/msg $nick $target banned in $from for $length seconds"; return "/msg $nick $target banned in $from for $length seconds";
} }
@ -71,7 +71,7 @@ sub unban_user {
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
if(not defined $from) { if(not defined $from) {
$self->{pbot}->logger->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
@ -85,7 +85,7 @@ sub unban_user {
return "/msg $nick Usage for /msg: !unban $target <channel>" if $channel !~ /^#/; return "/msg $nick Usage for /msg: !unban $target <channel>" if $channel !~ /^#/;
$self->{pbot}->chanops->unban_user($target, $channel); $self->{pbot}->{chanops}->unban_user($target, $channel);
return "/msg $nick $target has been unbanned from $channel."; return "/msg $nick $target has been unbanned from $channel.";
} }
@ -94,29 +94,29 @@ sub kick_user {
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
if(not defined $from) { if(not defined $from) {
$self->{pbot}->logger->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
# used in private message # used in private message
if(not $from =~ /^#/) { if(not $from =~ /^#/) {
if(not $arguments =~ /(^#\S+) (\S+) (.*)/) { if(not $arguments =~ /(^#\S+) (\S+) (.*)/) {
$self->{pbot}->logger->log("$nick!$user\@$host: invalid arguments to kick\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host: invalid arguments to kick\n");
return "/msg $nick Usage from private message: kick <channel> <nick> <reason>"; return "/msg $nick Usage from private message: kick <channel> <nick> <reason>";
} }
$self->{pbot}->chanops->add_op_command($1, "kick $1 $2 $3"); $self->{pbot}->{chanops}->add_op_command($1, "kick $1 $2 $3");
$self->{pbot}->chanops->gain_ops($1); $self->{pbot}->{chanops}->gain_ops($1);
return "/msg $nick Kicking $2 from $1 with reason '$3'"; return "/msg $nick Kicking $2 from $1 with reason '$3'";
} }
# used in channel # used in channel
if(not $arguments =~ /(.*?) (.*)/) { if(not $arguments =~ /(.*?) (.*)/) {
$self->{pbot}->logger->log("$nick!$user\@$host: invalid arguments to kick\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host: invalid arguments to kick\n");
return "/msg $nick Usage: kick <nick> <reason>"; return "/msg $nick Usage: kick <nick> <reason>";
} }
$self->{pbot}->chanops->add_op_command($from, "kick $from $1 $2"); $self->{pbot}->{chanops}->add_op_command($from, "kick $from $1 $2");
$self->{pbot}->chanops->gain_ops($from); $self->{pbot}->{chanops}->gain_ops($from);
return "/msg $nick Kicking $1 from $from with reason '$2'"; return "/msg $nick Kicking $1 from $from with reason '$2'";
} }

View File

@ -41,8 +41,8 @@ sub initialize {
$self->{commands} = PBot::ChanOpCommands->new(pbot => $pbot); $self->{commands} = PBot::ChanOpCommands->new(pbot => $pbot);
$pbot->timer->register(sub { $self->check_opped_timeouts }, 10); $pbot->{timer}->register(sub { $self->check_opped_timeouts }, 10);
$pbot->timer->register(sub { $self->check_unban_timeouts }, 10); $pbot->{timer}->register(sub { $self->check_unban_timeouts }, 10);
} }
sub gain_ops { sub gain_ops {
@ -50,7 +50,7 @@ sub gain_ops {
my $channel = shift; my $channel = shift;
if(not exists $self->{is_opped}->{$channel}) { if(not exists $self->{is_opped}->{$channel}) {
$self->{pbot}->conn->privmsg("chanserv", "op $channel"); $self->{pbot}->{conn}->privmsg("chanserv", "op $channel");
$self->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # assume we're going to be opped $self->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # assume we're going to be opped
} else { } else {
$self->perform_op_commands($channel); $self->perform_op_commands($channel);
@ -60,7 +60,7 @@ sub gain_ops {
sub lose_ops { sub lose_ops {
my $self = shift; my $self = shift;
my $channel = shift; my $channel = shift;
$self->{pbot}->conn->privmsg("chanserv", "op $channel -" . $self->{pbot}->{registry}->get_value('irc', 'botnick')); $self->{pbot}->{conn}->privmsg("chanserv", "op $channel -" . $self->{pbot}->{registry}->get_value('irc', 'botnick'));
} }
sub add_op_command { sub add_op_command {
@ -73,17 +73,17 @@ sub perform_op_commands {
my $channel = shift; my $channel = shift;
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
$self->{pbot}->logger->log("Performing op commands...\n"); $self->{pbot}->{logger}->log("Performing op commands...\n");
while(my $command = shift @{ $self->{op_commands}->{$channel} }) { while(my $command = shift @{ $self->{op_commands}->{$channel} }) {
if($command =~ /^mode (.*?) (.*)/i) { if($command =~ /^mode (.*?) (.*)/i) {
$self->{pbot}->conn->mode($1, $2); $self->{pbot}->{conn}->mode($1, $2);
$self->{pbot}->logger->log(" executing mode $1 $2\n"); $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}->{conn}->kick($1, $2, $3) unless $1 =~ /\Q$botnick\E/i;
$self->{pbot}->logger->log(" executing kick on $1 $2 $3\n"); $self->{pbot}->{logger}->log(" executing kick on $1 $2 $3\n");
} }
} }
$self->{pbot}->logger->log("Done.\n"); $self->{pbot}->{logger}->log("Done.\n");
} }
sub ban_user { sub ban_user {
@ -97,7 +97,7 @@ sub ban_user {
sub unban_user { sub unban_user {
my $self = shift; my $self = shift;
my ($mask, $channel) = @_; my ($mask, $channel) = @_;
$self->{pbot}->logger->log("Unbanning $channel $mask\n"); $self->{pbot}->{logger}->log("Unbanning $channel $mask\n");
if($self->{unban_timeout}->find_index($channel, $mask)) { if($self->{unban_timeout}->find_index($channel, $mask)) {
$self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + 7200; # try again in 2 hours if unban doesn't immediately succeed $self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + 7200; # try again in 2 hours if unban doesn't immediately succeed
$self->{unban_timeout}->save; $self->{unban_timeout}->save;
@ -141,7 +141,7 @@ sub check_opped_timeouts {
delete $self->{is_opped}->{$channel}; # assume chanserv is alive and deop will succeed delete $self->{is_opped}->{$channel}; # assume chanserv is alive and deop will succeed
} else { } else {
# my $timediff = $self->{is_opped}->{$channel}{timeout} - $now; # my $timediff = $self->{is_opped}->{$channel}{timeout} - $now;
# $self->{pbot}->logger->log("deop $channel in $timediff seconds\n"); # $self->{pbot}->{logger}->log("deop $channel in $timediff seconds\n");
} }
} }
} }

View File

@ -31,11 +31,11 @@ sub initialize {
$self->{channels} = PBot::HashObject->new(pbot => $self->{pbot}, name => 'Channels', filename => delete $conf{filename}); $self->{channels} = PBot::HashObject->new(pbot => $self->{pbot}, name => 'Channels', filename => delete $conf{filename});
$self->load_channels; $self->load_channels;
$self->{pbot}->commands->register(sub { $self->set(@_) }, "chanset", 40); $self->{pbot}->{commands}->register(sub { $self->set(@_) }, "chanset", 40);
$self->{pbot}->commands->register(sub { $self->unset(@_) }, "chanunset", 40); $self->{pbot}->{commands}->register(sub { $self->unset(@_) }, "chanunset", 40);
$self->{pbot}->commands->register(sub { $self->add(@_) }, "chanadd", 40); $self->{pbot}->{commands}->register(sub { $self->add(@_) }, "chanadd", 40);
$self->{pbot}->commands->register(sub { $self->remove(@_) }, "chanrem", 40); $self->{pbot}->{commands}->register(sub { $self->remove(@_) }, "chanrem", 40);
$self->{pbot}->commands->register(sub { $self->list(@_) }, "chanlist", 10); $self->{pbot}->{commands}->register(sub { $self->list(@_) }, "chanlist", 10);
} }
sub set { sub set {
@ -46,7 +46,7 @@ sub set {
return "Usage: chanset <channel> [key <value>]"; return "Usage: chanset <channel> [key <value>]";
} }
return $self->channels->set($channel, $key, $value); return $self->{channels}->set($channel, $key, $value);
} }
sub unset { sub unset {
@ -57,7 +57,7 @@ sub unset {
return "Usage: chanunset <channel> <key>"; return "Usage: chanunset <channel> <key>";
} }
return "msg $nick " . $self->channels->unset($channel, $key); return "msg $nick " . $self->{channels}->unset($channel, $key);
} }
sub add { sub add {
@ -71,7 +71,7 @@ sub add {
$hash->{enabled} = 1; $hash->{enabled} = 1;
$hash->{chanop} = 0; $hash->{chanop} = 0;
return "/msg $nick " . $self->channels->add($arguments, $hash); return "/msg $nick " . $self->{channels}->add($arguments, $hash);
} }
sub remove { sub remove {
@ -81,18 +81,18 @@ sub remove {
return "/msg $nick Usage: chanrem <channel>"; return "/msg $nick Usage: chanrem <channel>";
} }
return "/msg $nick " . $self->channels->remove($arguments); return "/msg $nick " . $self->{channels}->remove($arguments);
} }
sub list { sub list {
my ($self, $from, $nick, $user, $host, $arguments) = @_; my ($self, $from, $nick, $user, $host, $arguments) = @_;
my $result; my $result;
foreach my $index (sort keys %{ $self->channels->hash }) { foreach my $index (sort keys %{ $self->{channels}->hash }) {
$result .= "$index: {"; $result .= "$index: {";
my $comma = ' '; my $comma = ' ';
foreach my $key (sort keys %{ ${ $self->channels->hash }{$index} }) { foreach my $key (sort keys %{ ${ $self->{channels}->hash }{$index} }) {
$result .= "$comma$key => ${ $self->channels->hash }{$index}{$key}"; $result .= "$comma$key => ${ $self->{channels}->hash }{$index}{$key}";
$comma = ', '; $comma = ', ';
} }
$result .= " }\n"; $result .= " }\n";
@ -103,13 +103,13 @@ sub list {
sub load_channels { sub load_channels {
my $self = shift; my $self = shift;
$self->channels->load_hash(); $self->{channels}->load_hash();
} }
sub save_channels { sub save_channels {
my $self = shift; my $self = shift;
$self->channels->save_hash(); $self->{channels}->save_hash();
} }
sub channels { sub channels {

View File

@ -80,7 +80,7 @@ sub interpreter {
my $pbot = $self->{pbot}; my $pbot = $self->{pbot};
my $admin = $pbot->admins->loggedin($from, "$nick!$user\@$host"); my $admin = $pbot->{admins}->loggedin($from, "$nick!$user\@$host");
my $level = defined $admin ? $admin->{level} : 0; my $level = defined $admin ? $admin->{level} : 0;

View File

@ -52,30 +52,30 @@ sub initialize {
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$pbot->commands->register(sub { return $self->factadd(@_) }, "learn", 0); $pbot->{commands}->register(sub { return $self->factadd(@_) }, "learn", 0);
$pbot->commands->register(sub { return $self->factadd(@_) }, "factadd", 0); $pbot->{commands}->register(sub { return $self->factadd(@_) }, "factadd", 0);
$pbot->commands->register(sub { return $self->factrem(@_) }, "forget", 0); $pbot->{commands}->register(sub { return $self->factrem(@_) }, "forget", 0);
$pbot->commands->register(sub { return $self->factrem(@_) }, "factrem", 0); $pbot->{commands}->register(sub { return $self->factrem(@_) }, "factrem", 0);
$pbot->commands->register(sub { return $self->factshow(@_) }, "factshow", 0); $pbot->{commands}->register(sub { return $self->factshow(@_) }, "factshow", 0);
$pbot->commands->register(sub { return $self->factinfo(@_) }, "factinfo", 0); $pbot->{commands}->register(sub { return $self->factinfo(@_) }, "factinfo", 0);
$pbot->commands->register(sub { return $self->factset(@_) }, "factset", 0); $pbot->{commands}->register(sub { return $self->factset(@_) }, "factset", 0);
$pbot->commands->register(sub { return $self->factunset(@_) }, "factunset", 0); $pbot->{commands}->register(sub { return $self->factunset(@_) }, "factunset", 0);
$pbot->commands->register(sub { return $self->factchange(@_) }, "factchange", 0); $pbot->{commands}->register(sub { return $self->factchange(@_) }, "factchange", 0);
$pbot->commands->register(sub { return $self->factalias(@_) }, "factalias", 0); $pbot->{commands}->register(sub { return $self->factalias(@_) }, "factalias", 0);
$pbot->commands->register(sub { return $self->call_factoid(@_) }, "fact", 0); $pbot->{commands}->register(sub { return $self->call_factoid(@_) }, "fact", 0);
$pbot->commands->register(sub { return $self->factfind(@_) }, "factfind", 0); $pbot->{commands}->register(sub { return $self->factfind(@_) }, "factfind", 0);
$pbot->commands->register(sub { return $self->list(@_) }, "list", 0); $pbot->{commands}->register(sub { return $self->list(@_) }, "list", 0);
$pbot->commands->register(sub { return $self->top20(@_) }, "top20", 0); $pbot->{commands}->register(sub { return $self->top20(@_) }, "top20", 0);
# the following commands have not yet been updated to use the new factoid structure # the following commands have not yet been updated to use the new factoid structure
# DO NOT USE!! Factoid corruption may occur. # DO NOT USE!! Factoid corruption may occur.
$pbot->commands->register(sub { return $self->add_regex(@_) }, "regex", 999); $pbot->{commands}->register(sub { return $self->add_regex(@_) }, "regex", 999);
$pbot->commands->register(sub { return $self->histogram(@_) }, "histogram", 999); $pbot->{commands}->register(sub { return $self->histogram(@_) }, "histogram", 999);
$pbot->commands->register(sub { return $self->count(@_) }, "count", 999); $pbot->{commands}->register(sub { return $self->count(@_) }, "count", 999);
$pbot->commands->register(sub { return $self->load_module(@_) }, "load", 999); $pbot->{commands}->register(sub { return $self->load_module(@_) }, "load", 999);
$pbot->commands->register(sub { return $self->unload_module(@_) }, "unload", 999); $pbot->{commands}->register(sub { return $self->unload_module(@_) }, "unload", 999);
$pbot->commands->register(sub { return $self->enable_command(@_) }, "enable", 999); $pbot->{commands}->register(sub { return $self->enable_command(@_) }, "enable", 999);
$pbot->commands->register(sub { return $self->disable_command(@_) }, "disable", 999); $pbot->{commands}->register(sub { return $self->disable_command(@_) }, "disable", 999);
} }
sub call_factoid { sub call_factoid {
@ -87,13 +87,13 @@ sub call_factoid {
return "Usage: fact <channel> <keyword> [arguments]"; return "Usage: fact <channel> <keyword> [arguments]";
} }
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $keyword, $args, 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $keyword, $args, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "No such factoid '$keyword' exists for channel '$chan'"; return "No such factoid '$keyword' exists for channel '$chan'";
} }
return $self->{pbot}->factoids->interpreter($channel, $nick, $user, $host, 1, $trigger, $args); return $self->{pbot}->{factoids}->interpreter($channel, $nick, $user, $host, 1, $trigger, $args);
} }
sub factset { sub factset {
@ -105,7 +105,7 @@ sub factset {
return "Usage: factset <channel> <factoid> [key [value]]"; return "Usage: factset <channel> <factoid> [key [value]]";
} }
my $admininfo = $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host"); my $admininfo = $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host");
my $level = 0; my $level = 0;
my $meta_level = 0; my $meta_level = 0;
@ -128,10 +128,10 @@ sub factset {
} }
} }
my ($owner_channel, $owner_trigger) = $self->{pbot}->factoids->find_factoid($channel, $trigger, undef, 1); my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1);
if(defined $owner_channel) { if(defined $owner_channel) {
my $factoid = $self->{pbot}->factoids->factoids->hash->{$owner_channel}->{$owner_trigger}; my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger};
my ($owner) = $factoid->{'owner'} =~ m/([^!]+)/; my ($owner) = $factoid->{'owner'} =~ m/([^!]+)/;
@ -140,7 +140,7 @@ sub factset {
} }
} }
return $self->{pbot}->factoids->factoids->set($channel, $trigger, $key, $value); return $self->{pbot}->{factoids}->{factoids}->set($channel, $trigger, $key, $value);
} }
sub factunset { sub factunset {
@ -152,7 +152,7 @@ sub factunset {
return "Usage: factunset <channel> <factoid> <key>" return "Usage: factunset <channel> <factoid> <key>"
} }
my $admininfo = $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host"); my $admininfo = $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host");
my $level = 0; my $level = 0;
my $meta_level = 0; my $meta_level = 0;
@ -173,10 +173,10 @@ sub factunset {
} }
} }
my ($owner_channel, $owner_trigger) = $self->{pbot}->factoids->find_factoid($channel, $trigger, undef, 1); my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1);
if(defined $owner_channel) { if(defined $owner_channel) {
my $factoid = $self->{pbot}->factoids->factoids->hash->{$owner_channel}->{$owner_trigger}; my $factoid = $self->{pbot}->{factoids}->{factoids}->hash->{$owner_channel}->{$owner_trigger};
my ($owner) = $factoid->{'owner'} =~ m/([^!]+)/; my ($owner) = $factoid->{'owner'} =~ m/([^!]+)/;
@ -185,7 +185,7 @@ sub factunset {
} }
} }
return $self->{pbot}->factoids->factoids->unset($channel, $trigger, $key); return $self->{pbot}->{factoids}->{factoids}->unset($channel, $trigger, $key);
} }
sub list { sub list {
@ -207,26 +207,26 @@ sub list {
my @results = eval { my @results = eval {
my @ret; my @ret;
foreach my $history_mask (keys %{ $self->{pbot}->antiflood->message_history }) { foreach my $history_mask (keys %{ $self->{pbot}->{antiflood}->message_history }) {
my $nickserv = "(undef)"; my $nickserv = "(undef)";
$nickserv = $self->{pbot}->antiflood->message_history->{$history_mask}->{nickserv_account} if exists $self->{pbot}->antiflood->message_history->{$history_mask}->{nickserv_account}; $nickserv = $self->{pbot}->{antiflood}->message_history->{$history_mask}->{nickserv_account} if exists $self->{pbot}->{antiflood}->message_history->{$history_mask}->{nickserv_account};
if($history_mask =~ m/$mask_search/i) { if($history_mask =~ m/$mask_search/i) {
my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger'); my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger');
foreach my $history_channel (keys %{ $self->{pbot}->antiflood->message_history->{$history_mask}->{channels} }) { foreach my $history_channel (keys %{ $self->{pbot}->{antiflood}->message_history->{$history_mask}->{channels} }) {
if($history_channel =~ m/$channel_search/i) { if($history_channel =~ m/$channel_search/i) {
my @messages = @{ $self->{pbot}->antiflood->message_history->{$history_mask}->{channels}->{$history_channel}{messages} }; my @messages = @{ $self->{pbot}->{antiflood}->message_history->{$history_mask}->{channels}->{$history_channel}{messages} };
for(my $i = 0; $i <= $#messages; $i++) { for(my $i = 0; $i <= $#messages; $i++) {
next if $messages[$i]->{msg} =~ /^\Q$bot_trigger\E?login/; # don't reveal login passwords next if $messages[$i]->{msg} =~ /^\Q$bot_trigger\E?login/; # don't reveal login passwords
print "$history_mask, $history_channel\n"; print "$history_mask, $history_channel\n";
print "joinwatch: ", $self->{pbot}->antiflood->message_history->{$history_mask}->{channels}->{$history_channel}{join_watch}, "\n"; print "joinwatch: ", $self->{pbot}->{antiflood}->message_history->{$history_mask}->{channels}->{$history_channel}{join_watch}, "\n";
push @ret, { push @ret, {
offenses => $self->{pbot}->antiflood->message_history->{$history_mask}->{channels}->{$history_channel}{offenses}, offenses => $self->{pbot}->{antiflood}->message_history->{$history_mask}->{channels}->{$history_channel}{offenses},
last_offense_timestamp => $self->{pbot}->antiflood->message_history->{$history_mask}->{channels}->{$history_channel}{last_offense_timestamp}, last_offense_timestamp => $self->{pbot}->{antiflood}->message_history->{$history_mask}->{channels}->{$history_channel}{last_offense_timestamp},
join_watch => $self->{pbot}->antiflood->message_history->{$history_mask}->{channels}->{$history_channel}{join_watch}, join_watch => $self->{pbot}->{antiflood}->message_history->{$history_mask}->{channels}->{$history_channel}{join_watch},
text => $messages[$i]->{msg}, text => $messages[$i]->{msg},
timestamp => $messages[$i]->{timestamp}, timestamp => $messages[$i]->{timestamp},
mask => $history_mask, mask => $history_mask,
@ -242,7 +242,7 @@ sub list {
}; };
if($@) { if($@) {
$self->{pbot}->logger->log("Error in search parameters: $@\n"); $self->{pbot}->{logger}->log("Error in search parameters: $@\n");
return "Error in search parameters: $@"; return "Error in search parameters: $@";
} }
@ -259,7 +259,7 @@ sub list {
$text .= "[$msg->{channel}] " . localtime($msg->{timestamp}) . " <$msg->{mask}> " . $msg->{text} . "\n"; $text .= "[$msg->{channel}] " . localtime($msg->{timestamp}) . " <$msg->{mask}> " . $msg->{text} . "\n";
} }
$self->{pbot}->logger->log($text); $self->{pbot}->{logger}->log($text);
return "Messages:\n\n$text"; return "Messages:\n\n$text";
} }
=cut =cut
@ -267,9 +267,9 @@ sub list {
if($arguments =~ /^modules$/i) { if($arguments =~ /^modules$/i) {
$from = '.*' if not defined $from or $from !~ /^#/; $from = '.*' if not defined $from or $from !~ /^#/;
$text = "Loaded modules for channel $from: "; $text = "Loaded modules for channel $from: ";
foreach my $channel (sort keys %{ $self->{pbot}->factoids->factoids->hash }) { foreach my $channel (sort keys %{ $self->{pbot}->{factoids}->{factoids}->hash }) {
foreach my $command (sort keys %{ $self->{pbot}->factoids->factoids->hash->{$channel} }) { 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 "; $text .= "$command ";
} }
} }
@ -279,7 +279,7 @@ sub list {
if($arguments =~ /^commands$/i) { if($arguments =~ /^commands$/i) {
$text = "Registered commands: "; $text = "Registered commands: ";
foreach my $command (sort { $a->{name} cmp $b->{name} } @{ $self->{pbot}->commands->{handlers} }) { foreach my $command (sort { $a->{name} cmp $b->{name} } @{ $self->{pbot}->{commands}->{handlers} }) {
$text .= "$command->{name} "; $text .= "$command->{name} ";
$text .= "($command->{level}) " if $command->{level} > 0; $text .= "($command->{level}) " if $command->{level} > 0;
} }
@ -287,23 +287,23 @@ sub list {
} }
if($arguments =~ /^factoids$/i) { if($arguments =~ /^factoids$/i) {
return "For a list of factoids see " . $self->{pbot}->factoids->export_site; return "For a list of factoids see " . $self->{pbot}->{factoids}->export_site;
} }
if($arguments =~ /^admins$/i) { if($arguments =~ /^admins$/i) {
$text = "Admins: "; $text = "Admins: ";
my $last_channel = ""; my $last_channel = "";
my $sep = ""; my $sep = "";
foreach my $channel (sort keys %{ $self->{pbot}->admins->admins->hash }) { 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) . ": "; $text .= $sep . "Channel " . ($channel eq ".*" ? "all" : $channel) . ": ";
$last_channel = $channel; $last_channel = $channel;
$sep = ""; $sep = "";
} }
foreach my $hostmask (sort keys %{ $self->{pbot}->admins->admins->hash->{$channel} }) { foreach my $hostmask (sort keys %{ $self->{pbot}->{admins}->{admins}->hash->{$channel} }) {
$text .= $sep; $text .= $sep;
$text .= "*" if exists $self->{pbot}->admins->admins->hash->{$channel}->{$hostmask}->{loggedin}; $text .= "*" if exists $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}->{loggedin};
$text .= $self->{pbot}->admins->admins->hash->{$channel}->{$hostmask}->{name} . " (" . $self->{pbot}->admins->admins->hash->{$channel}->{$hostmask}->{level} . ")"; $text .= $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}->{name} . " (" . $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}->{level} . ")";
$sep = "; "; $sep = "; ";
} }
} }
@ -323,32 +323,32 @@ sub factalias {
$chan = '.*' if $chan !~ /^#/; $chan = '.*' if $chan !~ /^#/;
my ($channel, $alias_trigger) = $self->{pbot}->factoids->find_factoid($chan, $alias, undef, 1); my ($channel, $alias_trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $alias, undef, 1);
if(defined $alias_trigger) { if(defined $alias_trigger) {
$self->{pbot}->logger->log("attempt to overwrite existing command\n"); $self->{pbot}->{logger}->log("attempt to overwrite existing command\n");
return "/msg $nick '$alias_trigger' already exists for channel $channel"; return "/msg $nick '$alias_trigger' already exists for channel $channel";
} }
$self->{pbot}->factoids->add_factoid('text', $chan, "$nick!$user\@$host", $alias, "/call $command"); $self->{pbot}->{factoids}->add_factoid('text', $chan, "$nick!$user\@$host", $alias, "/call $command");
$self->{pbot}->logger->log("$nick!$user\@$host [$chan] aliased $alias => $command\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host [$chan] aliased $alias => $command\n");
$self->{pbot}->factoids->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
return "/msg $nick '$alias' aliases '$command' for " . ($chan eq '.*' ? 'the global channel' : $chan); return "/msg $nick '$alias' aliases '$command' for " . ($chan eq '.*' ? 'the global channel' : $chan);
} }
sub add_regex { sub add_regex {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
my ($keyword, $text) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments; my ($keyword, $text) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments;
$from = '.*' if not defined $from or $from !~ /^#/; $from = '.*' if not defined $from or $from !~ /^#/;
if(not defined $keyword) { if(not defined $keyword) {
$text = ""; $text = "";
foreach my $trigger (sort keys %{ $factoids->{$from} }) { foreach my $trigger (sort keys %{ ${factoids}->{$from} }) {
if($factoids->{$from}->{$trigger}->{type} eq 'regex') { if(${factoids}->{$from}->{$trigger}->{type} eq 'regex') {
$text .= $trigger . " "; $text .= $trigger . " ";
} }
} }
@ -359,15 +359,15 @@ sub add_regex {
return "Usage: regex <regex> <command>"; return "Usage: regex <regex> <command>";
} }
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword, undef, 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $keyword, undef, 1);
if(defined $trigger) { if(defined $trigger) {
$self->{pbot}->logger->log("$nick!$user\@$host attempt to overwrite $trigger\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $trigger\n");
return "/msg $nick $trigger already exists for channel $channel."; return "/msg $nick $trigger already exists for channel $channel.";
} }
$self->{pbot}->factoids->add_factoid('regex', $from, "$nick!$user\@$host", $keyword, $text); $self->{pbot}->{factoids}->add_factoid('regex', $from, "$nick!$user\@$host", $keyword, $text);
$self->{pbot}->logger->log("$nick!$user\@$host added [$keyword] => [$text]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host added [$keyword] => [$text]\n");
return "/msg $nick $keyword added."; return "/msg $nick $keyword added.";
} }
@ -382,23 +382,23 @@ sub factadd {
$from_chan = '.*' if not $from_chan =~ m/^#/; $from_chan = '.*' if not $from_chan =~ m/^#/;
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from_chan, $keyword, undef, 1, 1); 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"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $keyword\n");
return "/msg $nick $keyword already exists for " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; return "/msg $nick $keyword already exists for " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . ".";
} }
$self->{pbot}->factoids->add_factoid('text', $from_chan, "$nick!$user\@$host", $keyword, $text); $self->{pbot}->{factoids}->add_factoid('text', $from_chan, "$nick!$user\@$host", $keyword, $text);
$self->{pbot}->logger->log("$nick!$user\@$host added [$from_chan] $keyword => $text\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host added [$from_chan] $keyword => $text\n");
return "/msg $nick '$keyword' added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; return "/msg $nick '$keyword' added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . ".";
} }
sub factrem { sub factrem {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
my ($from_chan, $from_trigger) = split / /, $arguments; my ($from_chan, $from_trigger) = split / /, $arguments;
@ -406,44 +406,44 @@ sub factrem {
return "/msg $nick Usage: factrem <channel> <keyword>"; return "/msg $nick Usage: factrem <channel> <keyword>";
} }
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from_chan, $from_trigger, undef, 1, 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $from_trigger, undef, 1, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "/msg $nick $from_trigger not found in channel $from_chan."; return "/msg $nick $from_trigger not found in channel $from_chan.";
} }
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 [not factoid]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not factoid]\n");
return "/msg $nick $trigger is not a factoid."; return "/msg $nick $trigger is not a factoid.";
} }
my ($owner) = $factoids->{$channel}->{$trigger}->{'owner'} =~ m/([^!]+)/; my ($owner) = ${factoids}->{$channel}->{$trigger}->{'owner'} =~ m/([^!]+)/;
if((lc $nick ne lc $owner) and (not $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host"))) { if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host"))) {
$self->{pbot}->logger->log("$nick!$user\@$host attempted to remove $trigger [not owner]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not owner]\n");
my $chan = ($channel eq '.*' ? 'the global channel' : $channel); my $chan = ($channel eq '.*' ? 'the global channel' : $channel);
return "/msg $nick You are not the owner of '$trigger' for $chan"; return "/msg $nick You are not the owner of '$trigger' for $chan";
} }
if(exists $factoids->{$channel}->{$trigger}->{'locked'} and $factoids->{$channel}->{$trigger}->{'locked'} != 0) { if(exists ${factoids}->{$channel}->{$trigger}->{'locked'} and ${factoids}->{$channel}->{$trigger}->{'locked'} != 0) {
return "$trigger is locked; unlock before deleting."; return "$trigger is locked; unlock before deleting.";
} }
$self->{pbot}->logger->log("$nick!$user\@$host removed [$channel][$trigger][" . $factoids->{$channel}->{$trigger}->{action} . "]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host removed [$channel][$trigger][" . ${factoids}->{$channel}->{$trigger}->{action} . "]\n");
$self->{pbot}->factoids->remove_factoid($channel, $trigger); $self->{pbot}->{factoids}->remove_factoid($channel, $trigger);
return "/msg $nick $trigger removed from " . ($channel eq '.*' ? 'the global channel' : $channel) . "."; return "/msg $nick $trigger removed from " . ($channel eq '.*' ? 'the global channel' : $channel) . ".";
} }
sub histogram { sub histogram {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids; my $factoids = $self->{pbot}->{factoids}->factoids;
my %hash; my %hash;
my $factoid_count = 0; my $factoid_count = 0;
foreach my $command (keys %{ $factoids }) { foreach my $command (keys %{ $factoids }) {
if(exists $factoids->{$command}{text}) { if(exists ${factoids}->{$command}{text}) {
$hash{$factoids->{$command}{owner}}++; $hash{${factoids}->{$command}{owner}}++;
$factoid_count++; $factoid_count++;
} }
} }
@ -464,7 +464,7 @@ sub histogram {
sub factshow { sub factshow {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
my ($chan, $trig) = split / /, $arguments; my ($chan, $trig) = split / /, $arguments;
@ -472,15 +472,15 @@ sub factshow {
return "Usage: factshow <channel> <trigger>"; return "Usage: factshow <channel> <trigger>";
} }
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig, undef, 0, 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $trig, undef, 0, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "/msg $nick '$trig' not found in channel '$chan'"; return "/msg $nick '$trig' not found in channel '$chan'";
} }
my $result = "$trigger: " . $factoids->{$channel}->{$trigger}->{action}; my $result = "$trigger: " . ${factoids}->{$channel}->{$trigger}->{action};
if($factoids->{$channel}->{$trigger}->{type} eq 'module') { if(${factoids}->{$channel}->{$trigger}->{type} eq 'module') {
$result .= ' [module]'; $result .= ' [module]';
} }
@ -490,7 +490,7 @@ sub factshow {
sub factinfo { sub factinfo {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
my ($chan, $trig) = split / /, $arguments; my ($chan, $trig) = split / /, $arguments;
@ -498,30 +498,30 @@ sub factinfo {
return "Usage: factinfo <channel> <trigger>"; return "Usage: factinfo <channel> <trigger>";
} }
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig, undef, 0, 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $trig, undef, 0, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "'$trig' not found in channel '$chan'"; return "'$trig' not found in channel '$chan'";
} }
my $created_ago = ago(gettimeofday - $factoids->{$channel}->{$trigger}->{created_on}); my $created_ago = ago(gettimeofday - ${factoids}->{$channel}->{$trigger}->{created_on});
my $ref_ago = ago(gettimeofday - $factoids->{$channel}->{$trigger}->{last_referenced_on}) if defined $factoids->{$channel}->{$trigger}->{last_referenced_on}; my $ref_ago = ago(gettimeofday - ${factoids}->{$channel}->{$trigger}->{last_referenced_on}) if defined ${factoids}->{$channel}->{$trigger}->{last_referenced_on};
$chan = ($channel eq '.*' ? 'global channel' : $channel); $chan = ($channel eq '.*' ? 'global channel' : $channel);
# factoid # factoid
if($factoids->{$channel}->{$trigger}->{type} eq 'text') { if(${factoids}->{$channel}->{$trigger}->{type} eq 'text') {
return "$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]" : "") . ")"; return "$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 # module
if($factoids->{$channel}->{$trigger}->{type} eq 'module') { if(${factoids}->{$channel}->{$trigger}->{type} eq 'module') {
return "$trigger: Module loaded by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago] -> http://code.google.com/p/pbot2-pl/source/browse/trunk/modules/" . $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]" : "") . ")"; return "$trigger: Module loaded by " . ${factoids}->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime(${factoids}->{$channel}->{$trigger}->{created_on}) . " [$created_ago] -> http://code.google.com/p/pbot2-pl/source/browse/trunk/modules/" . ${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 # regex
if($factoids->{$channel}->{$trigger}->{type} eq 'regex') { if(${factoids}->{$channel}->{$trigger}->{type} eq 'regex') {
return "$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]" : "") . ")"; return "$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]" : "") . ")";
} }
return "/msg $nick $trigger is not a factoid or a module"; return "/msg $nick $trigger is not a factoid or a module";
@ -530,7 +530,7 @@ sub factinfo {
sub top20 { sub top20 {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
my %hash = (); my %hash = ();
my $text = ""; my $text = "";
my $i = 0; my $i = 0;
@ -544,9 +544,9 @@ sub top20 {
if(not defined $args) { if(not defined $args) {
foreach my $chan (sort keys %{ $factoids }) { foreach my $chan (sort keys %{ $factoids }) {
next if lc $chan ne lc $channel; next if lc $chan ne lc $channel;
foreach my $command (sort {$factoids->{$chan}->{$b}{ref_count} <=> $factoids->{$chan}->{$a}{ref_count}} keys %{ $factoids->{$chan} }) { 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}) "; $text .= "$command (${factoids}->{$chan}->{$command}{ref_count}) ";
$i++; $i++;
last if $i >= 20; last if $i >= 20;
} }
@ -561,9 +561,9 @@ sub top20 {
if(lc $args eq "recent") { if(lc $args eq "recent") {
foreach my $chan (sort keys %{ $factoids }) { foreach my $chan (sort keys %{ $factoids }) {
next if lc $chan ne lc $channel; next if lc $chan ne lc $channel;
foreach my $command (sort { $factoids->{$chan}->{$b}{created_on} <=> $factoids->{$chan}->{$a}{created_on} } keys %{ $factoids->{$chan} }) { foreach my $command (sort { ${factoids}->{$chan}->{$b}{created_on} <=> ${factoids}->{$chan}->{$a}{created_on} } keys %{ ${factoids}->{$chan} }) {
my $ago = ago(gettimeofday - $factoids->{$chan}->{$command}->{created_on}); my $ago = ago(gettimeofday - ${factoids}->{$chan}->{$command}->{created_on});
$text .= " $command [$ago by $factoids->{$chan}->{$command}->{owner}]\n"; $text .= " $command [$ago by ${factoids}->{$chan}->{$command}->{owner}]\n";
$i++; $i++;
last if $i >= 50; last if $i >= 50;
} }
@ -576,12 +576,12 @@ sub top20 {
my $user = lc $args; my $user = lc $args;
foreach my $chan (sort keys %{ $factoids }) { foreach my $chan (sort keys %{ $factoids }) {
next if lc $chan ne lc $channel; 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} }) { 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(${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($user ne lc ${factoids}->{$chan}->{$command}{ref_user} && not $user =~ /${factoids}->{$chan}->{$command}{ref_user}/i) {
$user .= " ($factoids->{$chan}->{$command}{ref_user})"; $user .= " (${factoids}->{$chan}->{$command}{ref_user})";
} }
my $ago = $factoids->{$chan}->{$command}{last_referenced_on} ? ago(gettimeofday - $factoids->{$chan}->{$command}{last_referenced_on}) : "unknown"; my $ago = ${factoids}->{$chan}->{$command}{last_referenced_on} ? ago(gettimeofday - ${factoids}->{$chan}->{$command}{last_referenced_on}) : "unknown";
$text .= " $command [$ago]\n"; $text .= " $command [$ago]\n";
$i++; $i++;
last if $i >= 20; last if $i >= 20;
@ -596,7 +596,7 @@ sub top20 {
sub count { sub count {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids; my $factoids = $self->{pbot}->{factoids}->factoids;
my $i = 0; my $i = 0;
my $total = 0; my $total = 0;
@ -608,9 +608,9 @@ sub count {
eval { eval {
foreach my $command (keys %{ $factoids }) { foreach my $command (keys %{ $factoids }) {
$total++ if exists $factoids->{$command}{text}; $total++ if exists ${factoids}->{$command}{text};
my $regex = qr/^\Q$arguments\E$/; my $regex = qr/^\Q$arguments\E$/;
if($factoids->{$command}{owner} =~ /$regex/i && exists $factoids->{$command}{text}) { if(${factoids}->{$command}{owner} =~ /$regex/i && exists ${factoids}->{$command}{text}) {
$i++; $i++;
} }
} }
@ -631,7 +631,7 @@ sub count {
sub factfind { sub factfind {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: factfind [-channel channel] [-owner nick] [-by nick] [text]"; return "/msg $nick Usage: factfind [-channel channel] [-owner nick] [-by nick] [text]";
@ -685,10 +685,10 @@ sub factfind {
eval { eval {
foreach my $chan (sort keys %{ $factoids }) { foreach my $chan (sort keys %{ $factoids }) {
next if defined $channel and $chan !~ /$channel/i; next if defined $channel and $chan !~ /$channel/i;
foreach my $trigger (sort keys %{ $factoids->{$chan} }) { 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}->{type} eq 'text' or ${factoids}->{$chan}->{$trigger}->{type} eq 'regex') {
if($factoids->{$chan}->{$trigger}->{owner} =~ /$owner/i && $factoids->{$chan}->{$trigger}->{ref_user} =~ /$by/i) { if(${factoids}->{$chan}->{$trigger}->{owner} =~ /$owner/i && ${factoids}->{$chan}->{$trigger}->{ref_user} =~ /$by/i) {
next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$arguments/i && $trigger !~ /$arguments/i); next if($arguments ne "" && ${factoids}->{$chan}->{$trigger}->{action} !~ /$arguments/i && $trigger !~ /$arguments/i);
$i++; $i++;
@ -708,7 +708,7 @@ sub factfind {
if($i == 1) { if($i == 1) {
chop $text; 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}"; return "found one factoid submitted for " . ($last_chan eq '.*' ? 'global channel' : $last_chan) . " " . $argtype . ": $last_trigger is ${factoids}->{$last_chan}->{$last_trigger}->{action}";
} else { } else {
return "found $i factoids " . $argtype . ": $text" unless $i == 0; return "found $i factoids " . $argtype . ": $text" unless $i == 0;
@ -720,7 +720,7 @@ sub factfind {
sub factchange { sub factchange {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier); my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier);
if(defined $arguments) { if(defined $arguments) {
@ -741,27 +741,27 @@ sub factchange {
return "Usage: factchange <channel> <keyword> s/<pattern>/<replacement>/"; return "Usage: factchange <channel> <keyword> s/<pattern>/<replacement>/";
} }
($channel, $trigger) = $self->{pbot}->factoids->find_factoid($channel, $keyword, undef, 0, 1); ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $keyword, undef, 0, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "/msg $nick $keyword not found in channel $from."; return "/msg $nick $keyword not found in channel $from.";
} }
if(not $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host") and exists $factoids->{$channel}->{$trigger}->{'locked'} and $factoids->{$channel}->{$trigger}->{'locked'} != 0) { if(not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host") and exists ${factoids}->{$channel}->{$trigger}->{'locked'} and ${factoids}->{$channel}->{$trigger}->{'locked'} != 0) {
return "$trigger is locked and cannot be changed."; return "$trigger is locked and cannot be changed.";
} }
my $ret = eval { my $ret = eval {
use re::engine::RE2 -strict => 1; use re::engine::RE2 -strict => 1;
if(not $factoids->{$channel}->{$trigger}->{action} =~ s|$tochange|$changeto|) { if(not ${factoids}->{$channel}->{$trigger}->{action} =~ s|$tochange|$changeto|) {
$self->{pbot}->logger->log("($from) $nick!$user\@$host: failed to change '$trigger' 's$delim$tochange$delim$changeto$delim\n"); $self->{pbot}->{logger}->log("($from) $nick!$user\@$host: failed to change '$trigger' 's$delim$tochange$delim$changeto$delim\n");
return "/msg $nick Change $trigger failed."; return "/msg $nick Change $trigger failed.";
} else { } else {
$self->{pbot}->logger->log("($from) $nick!$user\@$host: changed '$trigger' 's/$tochange/$changeto/\n"); $self->{pbot}->{logger}->log("($from) $nick!$user\@$host: changed '$trigger' 's/$tochange/$changeto/\n");
$factoids->{$channel}->{$trigger}->{edited_by} = "$nick!$user\@$host"; ${factoids}->{$channel}->{$trigger}->{edited_by} = "$nick!$user\@$host";
$factoids->{$channel}->{$trigger}->{edited_on} = gettimeofday; ${factoids}->{$channel}->{$trigger}->{edited_on} = gettimeofday;
$self->{pbot}->factoids->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
return "Changed: $trigger is " . $factoids->{$channel}->{$trigger}->{action}; return "Changed: $trigger is " . ${factoids}->{$channel}->{$trigger}->{action};
} }
}; };
return "/msg $nick Change $trigger: $@" if $@; return "/msg $nick Change $trigger: $@" if $@;
@ -771,20 +771,20 @@ sub factchange {
sub load_module { sub load_module {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids; my $factoids = $self->{pbot}->{factoids}->factoids;
my ($keyword, $module) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments; my ($keyword, $module) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments;
if(not defined $module) { if(not defined $module) {
return "/msg $nick Usage: load <command> <module>"; return "/msg $nick Usage: load <command> <module>";
} }
if(not exists($factoids->{$keyword})) { if(not exists(${factoids}->{$keyword})) {
$factoids->{$keyword}{module} = $module; ${factoids}->{$keyword}{module} = $module;
$factoids->{$keyword}{enabled} = 1; ${factoids}->{$keyword}{enabled} = 1;
$factoids->{$keyword}{owner} = $nick; ${factoids}->{$keyword}{owner} = $nick;
$factoids->{$keyword}{created_on} = time(); ${factoids}->{$keyword}{created_on} = time();
$self->{pbot}->logger->log("$nick!$user\@$host loaded $keyword => $module\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host loaded $keyword => $module\n");
$self->{pbot}->factoids->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
return "/msg $nick Loaded $keyword => $module"; return "/msg $nick Loaded $keyword => $module";
} else { } else {
return "/msg $nick There is already a command named $keyword."; return "/msg $nick There is already a command named $keyword.";
@ -794,18 +794,18 @@ sub load_module {
sub unload_module { sub unload_module {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids; my $factoids = $self->{pbot}->{factoids}->factoids;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: unload <module>"; return "/msg $nick Usage: unload <module>";
} elsif(not exists $factoids->{$arguments}) { } elsif(not exists ${factoids}->{$arguments}) {
return "/msg $nick $arguments not found."; return "/msg $nick $arguments not found.";
} elsif(not exists $factoids->{$arguments}{module}) { } elsif(not exists ${factoids}->{$arguments}{module}) {
return "/msg $nick $arguments is not a module."; return "/msg $nick $arguments is not a module.";
} else { } else {
delete $factoids->{$arguments}; delete ${factoids}->{$arguments};
$self->{pbot}->factoids->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
$self->{pbot}->logger->log("$nick!$user\@$host unloaded module $arguments\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host unloaded module $arguments\n");
return "/msg $nick $arguments unloaded."; return "/msg $nick $arguments unloaded.";
} }
} }
@ -813,16 +813,16 @@ sub unload_module {
sub enable_command { sub enable_command {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids; my $factoids = $self->{pbot}->{factoids}->factoids;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: enable <command>"; return "/msg $nick Usage: enable <command>";
} elsif(not exists $factoids->{$arguments}) { } elsif(not exists ${factoids}->{$arguments}) {
return "/msg $nick $arguments not found."; return "/msg $nick $arguments not found.";
} else { } else {
$factoids->{$arguments}{enabled} = 1; ${factoids}->{$arguments}{enabled} = 1;
$self->{pbot}->factoids->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
$self->{pbot}->logger->log("$nick!$user\@$host enabled $arguments\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host enabled $arguments\n");
return "/msg $nick $arguments enabled."; return "/msg $nick $arguments enabled.";
} }
} }
@ -830,16 +830,16 @@ sub enable_command {
sub disable_command { sub disable_command {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;
my $factoids = $self->{pbot}->factoids->factoids; my $factoids = $self->{pbot}->{factoids}->factoids;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: disable <command>"; return "/msg $nick Usage: disable <command>";
} elsif(not exists $factoids->{$arguments}) { } elsif(not exists ${factoids}->{$arguments}) {
return "/msg $nick $arguments not found."; return "/msg $nick $arguments not found.";
} else { } else {
$factoids->{$arguments}{enabled} = 0; ${factoids}->{$arguments}{enabled} = 0;
$self->{pbot}->factoids->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
$self->{pbot}->logger->log("$nick!$user\@$host disabled $arguments\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host disabled $arguments\n");
return "/msg $nick $arguments disabled."; return "/msg $nick $arguments disabled.";
} }
} }

View File

@ -44,29 +44,29 @@ sub execute_module {
$arguments = "" if not defined $arguments; $arguments = "" if not defined $arguments;
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $keyword);
if(not defined $trigger) { if(not defined $trigger) {
$self->{pbot}->{interpreter}->handle_result($from, $nick, $user, $host, $command, "$keyword $arguments", "/msg $nick Failed to find module for '$keyword' in channel $from\n", 1, 0); $self->{pbot}->{interpreter}->handle_result($from, $nick, $user, $host, $command, "$keyword $arguments", "/msg $nick Failed to find module for '$keyword' in channel $from\n", 1, 0);
return; return;
} }
my $module = $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{action}; my $module = $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{action};
my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir'); my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir');
$self->{pbot}->logger->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host: Executing module $module $arguments\n"); $self->{pbot}->{logger}->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host: Executing module $module $arguments\n");
$arguments =~ s/\$nick/$nick/g; $arguments =~ s/\$nick/$nick/g;
$arguments =~ s/\$channel/$from/g; $arguments =~ s/\$channel/$from/g;
$arguments = quotemeta($arguments); $arguments = quotemeta($arguments);
if(exists $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{unquote_spaces}) { if(exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{unquote_spaces}) {
$arguments =~ s/\\ / /g; $arguments =~ s/\\ / /g;
} }
if(exists $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{modulelauncher_subpattern}) { if(exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{modulelauncher_subpattern}) {
if($self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{modulelauncher_subpattern} =~ m/s\/(.*?)\/(.*)\/(.*)/) { if($self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{modulelauncher_subpattern} =~ m/s\/(.*?)\/(.*)\/(.*)/) {
my ($p1, $p2, $p3) = ($1, $2, $3); my ($p1, $p2, $p3) = ($1, $2, $3);
my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $before, $after); my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $before, $after);
if($p3 eq 'g') { if($p3 eq 'g') {
@ -87,9 +87,9 @@ sub execute_module {
$arguments =~ s/\$9/$i/g if defined $i; $arguments =~ s/\$9/$i/g if defined $i;
$arguments =~ s/\$`/$before/g if defined $before; $arguments =~ s/\$`/$before/g if defined $before;
$arguments =~ s/\$'/$after/g if defined $after; $arguments =~ s/\$'/$after/g if defined $after;
#$self->{pbot}->logger->log("arguments subpattern: $arguments\n"); #$self->{pbot}->{logger}->log("arguments subpattern: $arguments\n");
} else { } else {
$self->{pbot}->logger->log("Invalid module substitution pattern [" . $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{modulelauncher_subpattern}. "], ignoring.\n"); $self->{pbot}->{logger}->log("Invalid module substitution pattern [" . $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{modulelauncher_subpattern}. "], ignoring.\n");
} }
} }
@ -120,7 +120,7 @@ sub execute_module {
my $pid = fork; my $pid = fork;
if(not defined $pid) { if(not defined $pid) {
$self->{pbot}->logger->log("Could not fork module: $!\n"); $self->{pbot}->{logger}->log("Could not fork module: $!\n");
close $reader; close $reader;
close $writer; close $writer;
$self->{pbot}->{interpreter}->handle_result($from, $nick, $user, $host, $command, "$keyword $arguments", "/me groans loudly.\n", 1, 0); $self->{pbot}->{interpreter}->handle_result($from, $nick, $user, $host, $command, "$keyword $arguments", "/me groans loudly.\n", 1, 0);
@ -138,16 +138,16 @@ sub execute_module {
use warnings; use warnings;
if(not chdir $module_dir) { if(not chdir $module_dir) {
$self->{pbot}->logger->log("Could not chdir to '$module_dir': $!\n"); $self->{pbot}->{logger}->log("Could not chdir to '$module_dir': $!\n");
Carp::croak("Could not chdir to '$module_dir': $!"); Carp::croak("Could not chdir to '$module_dir': $!");
} }
# $self->{pbot}->logger->log("module arguments: [$arguments]\n"); # $self->{pbot}->{logger}->log("module arguments: [$arguments]\n");
$text = `$module_dir/$module $arguments`; $text = `$module_dir/$module $arguments`;
if(defined $tonick) { if(defined $tonick) {
$self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n"); $self->{pbot}->{logger}->log("($from): $nick!$user\@$host) sent to $tonick\n");
if(defined $text && length $text > 0) { if(defined $text && length $text > 0) {
# get rid of original caller's nick # get rid of original caller's nick
$text =~ s/^\/([^ ]+) \Q$nick\E:\s+/\/$1 /; $text =~ s/^\/([^ ]+) \Q$nick\E:\s+/\/$1 /;
@ -158,7 +158,7 @@ sub execute_module {
} }
exit 0; exit 0;
} else { } else {
if(exists $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{add_nick} and $self->{pbot}->factoids->factoids->hash->{$channel}->{$trigger}->{add_nick} != 0) { if(exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{add_nick} and $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{add_nick} != 0) {
print $writer "$from $nick: $text"; print $writer "$from $nick: $text";
$self->{pbot}->{interpreter}->handle_result($from, $nick, $user, $host, $command, "$keyword $arguments", "$nick: $text", 0, $preserve_whitespace); $self->{pbot}->{interpreter}->handle_result($from, $nick, $user, $host, $command, "$keyword $arguments", "$nick: $text", 0, $preserve_whitespace);
} else { } else {
@ -184,8 +184,8 @@ sub module_pipe_reader {
my ($self, $buf) = @_; my ($self, $buf) = @_;
my ($channel, $text) = split / /, $buf, 2; my ($channel, $text) = split / /, $buf, 2;
return if not defined $text or not length $text; return if not defined $text or not length $text;
$text = $self->{pbot}->interpreter->truncate_result($channel, $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'undef', $text, $text, 0); $text = $self->{pbot}->{interpreter}->truncate_result($channel, $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'undef', $text, $text, 0);
$self->{pbot}->antiflood->check_flood($channel, $self->{pbot}->{registry}->get_value('irc', 'botnick'), $self->{pbot}->{registry}->get_value('irc', 'username'), 'localhost', $text, 0, 0, 0); $self->{pbot}->{antiflood}->check_flood($channel, $self->{pbot}->{registry}->get_value('irc', 'botnick'), $self->{pbot}->{registry}->get_value('irc', 'username'), 'localhost', $text, 0, 0, 0);
} }
1; 1;

View File

@ -56,28 +56,28 @@ sub initialize {
sub load_factoids { sub load_factoids {
my $self = shift; my $self = shift;
$self->{pbot}->logger->log("Loading factoids from " . $self->factoids->filename . " ...\n"); $self->{pbot}->{logger}->log("Loading factoids from " . $self->{factoids}->filename . " ...\n");
$self->factoids->load; $self->{factoids}->load;
my ($text, $regex, $modules); my ($text, $regex, $modules);
foreach my $channel (keys %{ $self->factoids->hash }) { foreach my $channel (keys %{ $self->{factoids}->hash }) {
foreach my $trigger (keys %{ $self->factoids->hash->{$channel} }) { foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) {
$text++ if $self->factoids->hash->{$channel}->{$trigger}->{type} eq 'text'; $text++ if $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'text';
$regex++ if $self->factoids->hash->{$channel}->{$trigger}->{type} eq 'regex'; $regex++ if $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'regex';
$modules++ if $self->factoids->hash->{$channel}->{$trigger}->{type} eq 'module'; $modules++ if $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'module';
} }
} }
$self->{pbot}->logger->log(" " . ($text + $regex + $modules) . " factoids loaded ($text text, $regex regexs, $modules modules).\n"); $self->{pbot}->{logger}->log(" " . ($text + $regex + $modules) . " factoids loaded ($text text, $regex regexs, $modules modules).\n");
$self->{pbot}->logger->log("Done.\n"); $self->{pbot}->{logger}->log("Done.\n");
} }
sub save_factoids { sub save_factoids {
my $self = shift; my $self = shift;
$self->factoids->save; $self->{factoids}->save;
$self->export_factoids; $self->export_factoids;
} }
@ -88,14 +88,14 @@ sub add_factoid {
$type = lc $type; $type = lc $type;
$channel = lc $channel; $channel = lc $channel;
$self->factoids->hash->{$channel}->{$trigger}->{enabled} = 1; $self->{factoids}->hash->{$channel}->{$trigger}->{enabled} = 1;
$self->factoids->hash->{$channel}->{$trigger}->{type} = $type; $self->{factoids}->hash->{$channel}->{$trigger}->{type} = $type;
$self->factoids->hash->{$channel}->{$trigger}->{action} = $action; $self->{factoids}->hash->{$channel}->{$trigger}->{action} = $action;
$self->factoids->hash->{$channel}->{$trigger}->{owner} = $owner; $self->{factoids}->hash->{$channel}->{$trigger}->{owner} = $owner;
$self->factoids->hash->{$channel}->{$trigger}->{created_on} = gettimeofday; $self->{factoids}->hash->{$channel}->{$trigger}->{created_on} = gettimeofday;
$self->factoids->hash->{$channel}->{$trigger}->{ref_count} = 0; $self->{factoids}->hash->{$channel}->{$trigger}->{ref_count} = 0;
$self->factoids->hash->{$channel}->{$trigger}->{ref_user} = "nobody"; $self->{factoids}->hash->{$channel}->{$trigger}->{ref_user} = "nobody";
$self->factoids->hash->{$channel}->{$trigger}->{rate_limit} = 15; $self->{factoids}->hash->{$channel}->{$trigger}->{rate_limit} = 15;
$self->save_factoids unless $dont_save; $self->save_factoids unless $dont_save;
} }
@ -106,10 +106,10 @@ sub remove_factoid {
$channel = lc $channel; $channel = lc $channel;
delete $self->factoids->hash->{$channel}->{$trigger}; 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}; delete $self->{factoids}->hash->{$channel};
} }
$self->save_factoids; $self->save_factoids;
@ -135,15 +135,15 @@ sub export_factoids {
my $i = 0; my $i = 0;
my $table_id = 1; my $table_id = 1;
foreach my $channel (sort keys %{ $self->factoids->hash }) { foreach my $channel (sort keys %{ $self->{factoids}->hash }) {
next if not scalar keys %{ $self->factoids->hash->{$channel} }; next if not scalar keys %{ $self->{factoids}->hash->{$channel} };
my $chan = $channel eq '.*' ? 'global' : $channel; my $chan = $channel eq '.*' ? 'global' : $channel;
print FILE "<a href='#" . $chan . "'>" . encode_entities($chan) . "</a><br>\n"; print FILE "<a href='#" . $chan . "'>" . encode_entities($chan) . "</a><br>\n";
} }
foreach my $channel (sort keys %{ $self->factoids->hash }) { foreach my $channel (sort keys %{ $self->{factoids}->hash }) {
next if not scalar keys %{ $self->factoids->hash->{$channel} }; next if not scalar keys %{ $self->{factoids}->hash->{$channel} };
my $chan = $channel eq '.*' ? 'global' : $channel; my $chan = $channel eq '.*' ? 'global' : $channel;
print FILE "<a name='$chan'></a>\n"; print FILE "<a name='$chan'></a>\n";
print FILE "<hr>\n<h3>$chan</h3>\n<hr>\n"; print FILE "<hr>\n<h3>$chan</h3>\n<hr>\n";
@ -160,8 +160,8 @@ sub export_factoids {
print FILE "</tr>\n</thead>\n<tbody>\n"; print FILE "</tr>\n</thead>\n<tbody>\n";
$table_id++; $table_id++;
foreach my $trigger (sort keys %{ $self->factoids->hash->{$channel} }) { 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++; $i++;
if($i % 2) { if($i % 2) {
print FILE "<tr bgcolor=\"#dddddd\">\n"; print FILE "<tr bgcolor=\"#dddddd\">\n";
@ -169,17 +169,17 @@ sub export_factoids {
print FILE "<tr>\n"; print FILE "<tr>\n";
} }
print FILE "<td>" . $self->factoids->hash->{$channel}->{$trigger}->{owner} . "</td>\n"; print FILE "<td>" . $self->{factoids}->hash->{$channel}->{$trigger}->{owner} . "</td>\n";
print FILE "<td>" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->factoids->hash->{$channel}->{$trigger}->{created_on}) . "</td>\n"; print FILE "<td>" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->{factoids}->hash->{$channel}->{$trigger}->{created_on}) . "</td>\n";
print FILE "<td>" . $self->factoids->hash->{$channel}->{$trigger}->{ref_count} . "</td>\n"; print FILE "<td>" . $self->{factoids}->hash->{$channel}->{$trigger}->{ref_count} . "</td>\n";
my $action = $self->factoids->hash->{$channel}->{$trigger}->{action}; my $action = $self->{factoids}->hash->{$channel}->{$trigger}->{action};
$action =~ s/(.*?)http(s?:\/\/[^ ]+)/encode_entities($1) . "<a href='http" . encode_entities($2) . "'>http" . encode_entities($2) . "<\/a>"/ge; $action =~ s/(.*?)http(s?:\/\/[^ ]+)/encode_entities($1) . "<a href='http" . encode_entities($2) . "'>http" . encode_entities($2) . "<\/a>"/ge;
$action =~ s/(.*)<\/a>(.*$)/"$1<\/a>" . encode_entities($2)/e; $action =~ s/(.*)<\/a>(.*$)/"$1<\/a>" . encode_entities($2)/e;
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}; my $with_args = $self->{factoids}->hash->{$channel}->{$trigger}->{action_with_args};
$with_args =~ s/(.*?)http(s?:\/\/[^ ]+)/encode_entities($1) . "<a href='http" . encode_entities($2) . "'>http" . encode_entities($2) . "<\/a>"/ge; $with_args =~ s/(.*?)http(s?:\/\/[^ ]+)/encode_entities($1) . "<a href='http" . encode_entities($2) . "'>http" . encode_entities($2) . "<\/a>"/ge;
$with_args =~ s/(.*)<\/a>(.*$)/"$1<\/a>" . encode_entities($2)/e; $with_args =~ s/(.*)<\/a>(.*$)/"$1<\/a>" . encode_entities($2)/e;
print FILE "<td width=100%><b>$trigger</b> is $action<br><br><b>with_args:</b> $with_args</td>\n"; print FILE "<td width=100%><b>$trigger</b> is $action<br><br><b>with_args:</b> $with_args</td>\n";
@ -187,18 +187,18 @@ sub export_factoids {
print FILE "<td width=100%><b>$trigger</b> is $action</td>\n"; print FILE "<td width=100%><b>$trigger</b> is $action</td>\n";
} }
if(exists $self->factoids->hash->{$channel}->{$trigger}->{edited_by}) { if(exists $self->{factoids}->hash->{$channel}->{$trigger}->{edited_by}) {
print FILE "<td>" . $self->factoids->hash->{$channel}->{$trigger}->{edited_by} . "</td>\n"; print FILE "<td>" . $self->{factoids}->hash->{$channel}->{$trigger}->{edited_by} . "</td>\n";
print FILE "<td>" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->factoids->hash->{$channel}->{$trigger}->{edited_on}) . "</td>\n"; print FILE "<td>" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->{factoids}->hash->{$channel}->{$trigger}->{edited_on}) . "</td>\n";
} else { } else {
print FILE "<td></td>\n"; print FILE "<td></td>\n";
print FILE "<td></td>\n"; print FILE "<td></td>\n";
} }
print FILE "<td>" . $self->factoids->hash->{$channel}->{$trigger}->{ref_user} . "</td>\n"; print FILE "<td>" . $self->{factoids}->hash->{$channel}->{$trigger}->{ref_user} . "</td>\n";
if(exists $self->factoids->hash->{$channel}->{$trigger}->{last_referenced_on}) { if(exists $self->{factoids}->hash->{$channel}->{$trigger}->{last_referenced_on}) {
print FILE "<td>" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->factoids->hash->{$channel}->{$trigger}->{last_referenced_on}) . "</td>\n"; print FILE "<td>" . encode_entities(strftime "%Y/%m/%d %H:%M:%S", localtime $self->{factoids}->hash->{$channel}->{$trigger}->{last_referenced_on}) . "</td>\n";
} else { } else {
print FILE "<td></td>\n"; print FILE "<td></td>\n";
} }
@ -226,7 +226,7 @@ sub export_factoids {
close(FILE); close(FILE);
#$self->{pbot}->logger->log("$i factoids exported to path: " . $self->export_path . ", site: " . $self->export_site . "\n"); #$self->{pbot}->{logger}->log("$i factoids exported to path: " . $self->export_path . ", site: " . $self->export_site . "\n");
return "$i factoids exported to " . $self->export_site; return "$i factoids exported to " . $self->export_site;
} }
@ -235,43 +235,43 @@ sub find_factoid {
my $debug = 0; my $debug = 0;
$self->{pbot}->logger->log("find_factoid: from: [$from], kw: [$keyword], args: [" . (defined $arguments ? $arguments : "undef") . "], " . (defined $exact_channel ? $exact_channel : "undef") . ", " . (defined $exact_trigger ? $exact_trigger : "undef") . "\n") if $debug; $self->{pbot}->{logger}->log("find_factoid: from: [$from], kw: [$keyword], args: [" . (defined $arguments ? $arguments : "undef") . "], " . (defined $exact_channel ? $exact_channel : "undef") . ", " . (defined $exact_trigger ? $exact_trigger : "undef") . "\n") if $debug;
$from = '.*' if not defined $from or $from !~ /^#/; $from = '.*' if not defined $from or $from !~ /^#/;
$self->{pbot}->logger->log("from: $from\n") if $debug; $self->{pbot}->{logger}->log("from: $from\n") if $debug;
my $string = "$keyword" . (defined $arguments ? " $arguments" : ""); my $string = "$keyword" . (defined $arguments ? " $arguments" : "");
$self->{pbot}->logger->log("string: $string\n") if $debug; $self->{pbot}->{logger}->log("string: $string\n") if $debug;
my @result = eval { my @result = eval {
foreach my $channel (sort keys %{ $self->factoids->hash }) { foreach my $channel (sort keys %{ $self->{factoids}->hash }) {
if($exact_channel) { if($exact_channel) {
next unless lc $from eq lc $channel or $from eq '.*' or $channel eq '.*'; next unless lc $from eq lc $channel or $from eq '.*' or $channel eq '.*';
} }
foreach my $trigger (keys %{ $self->factoids->hash->{$channel} }) { foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) {
if(not $exact_trigger and $self->factoids->hash->{$channel}->{$trigger}->{type} eq 'regex') { if(not $exact_trigger and $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'regex') {
if($string =~ m/$trigger/i) { if($string =~ m/$trigger/i) {
$self->{pbot}->logger->log("return regex $channel: $trigger\n") if $debug; $self->{pbot}->{logger}->log("return regex $channel: $trigger\n") if $debug;
return ($channel, $trigger); return ($channel, $trigger);
} }
} else { } else {
if($keyword =~ m/^\Q$trigger\E$/i) { if($keyword =~ m/^\Q$trigger\E$/i) {
$self->{pbot}->logger->log("return $channel: $trigger\n") if $debug; $self->{pbot}->{logger}->log("return $channel: $trigger\n") if $debug;
return ($channel, $trigger); return ($channel, $trigger);
} }
} }
} }
} }
$self->{pbot}->logger->log("find_factoid: no match\n") if $debug; $self->{pbot}->{logger}->log("find_factoid: no match\n") if $debug;
return undef; return undef;
}; };
if($@) { if($@) {
$self->{pbot}->logger->log("find_factoid: bad regex: $@\n"); $self->{pbot}->{logger}->log("find_factoid: bad regex: $@\n");
return undef; return undef;
} }
@ -288,11 +288,11 @@ sub interpreter {
$from = lc $from; $from = lc $from;
#$self->{pbot}->logger->log("factoids interpreter: from: [$from], ref_from: [" . (defined $ref_from ? $ref_from : "undef") . "]\n"); #$self->{pbot}->{logger}->log("factoids interpreter: from: [$from], ref_from: [" . (defined $ref_from ? $ref_from : "undef") . "]\n");
# search for factoid against global channel and current channel (from unless ref_from is defined) # search for factoid against global channel and current channel (from unless ref_from is defined)
my $original_keyword = $keyword; my $original_keyword = $keyword;
#$self->{pbot}->logger->log("calling find_factoid in Factoids.pm, interpreter() to search for factoid against global/current\n"); #$self->{pbot}->{logger}->log("calling find_factoid in Factoids.pm, interpreter() to search for factoid against global/current\n");
($channel, $keyword) = $self->find_factoid($ref_from ? $ref_from : $from, $keyword, $arguments, 1); ($channel, $keyword) = $self->find_factoid($ref_from ? $ref_from : $from, $keyword, $arguments, 1);
if(not defined $ref_from or $ref_from eq '.*') { if(not defined $ref_from or $ref_from eq '.*') {
@ -315,8 +315,8 @@ sub interpreter {
my ($fwd_chan, $fwd_trig); my ($fwd_chan, $fwd_trig);
# build string of which channels contain the keyword, keeping track of the last one and count # build string of which channels contain the keyword, keeping track of the last one and count
foreach my $chan (keys %{ $self->factoids->hash }) { foreach my $chan (keys %{ $self->{factoids}->hash }) {
foreach my $trig (keys %{ $self->factoids->hash->{$chan} }) { foreach my $trig (keys %{ $self->{factoids}->hash->{$chan} }) {
if(lc $trig eq lc $original_keyword) { if(lc $trig eq lc $original_keyword) {
$chans .= $comma . $chan; $chans .= $comma . $chan;
$comma = ", "; $comma = ", ";
@ -334,9 +334,9 @@ sub interpreter {
} }
# if there's just one other channel that has this keyword, trigger that instance # if there's just one other channel that has this keyword, trigger that instance
elsif($found == 1) { elsif($found == 1) {
$pbot->logger->log("Found '$original_keyword' as '$fwd_trig' in [$fwd_chan]\n"); $pbot->{logger}->log("Found '$original_keyword' as '$fwd_trig' in [$fwd_chan]\n");
return $pbot->factoids->interpreter($from, $nick, $user, $host, ++$count, $fwd_trig, $arguments, $tonick, $fwd_chan); return $pbot->{factoids}->interpreter($from, $nick, $user, $host, ++$count, $fwd_trig, $arguments, $tonick, $fwd_chan);
} }
# otherwise keyword hasn't been found, display similiar matches for all channels # otherwise keyword hasn't been found, display similiar matches for all channels
else { else {
@ -351,7 +351,7 @@ sub interpreter {
} }
# otherwise find levenshtein closest matches from all channels # otherwise find levenshtein closest matches from all channels
$matches = $self->factoids->levenshtein_matches('.*', lc $original_keyword); $matches = $self->{factoids}->levenshtein_matches('.*', lc $original_keyword);
# don't say anything if nothing similiar was found # don't say anything if nothing similiar was found
return undef if $matches eq 'none'; return undef if $matches eq 'none';
@ -360,10 +360,10 @@ sub interpreter {
} }
} }
my $type = $self->factoids->hash->{$channel}->{$keyword}->{type}; my $type = $self->{factoids}->hash->{$channel}->{$keyword}->{type};
# Check if it's an alias # Check if it's an alias
if($self->factoids->hash->{$channel}->{$keyword}->{action} =~ /^\/call\s+(.*)$/) { if($self->{factoids}->hash->{$channel}->{$keyword}->{action} =~ /^\/call\s+(.*)$/) {
my $command; my $command;
if(length $arguments) { if(length $arguments) {
$command = "$1 $arguments"; $command = "$1 $arguments";
@ -371,68 +371,68 @@ sub interpreter {
$command = $1; $command = $1;
} }
$pbot->logger->log("[" . (defined $from ? $from : "stdin") . "] ($nick!$user\@$host) [$keyword] aliased to: [$command]\n"); $pbot->{logger}->log("[" . (defined $from ? $from : "stdin") . "] ($nick!$user\@$host) [$keyword] aliased to: [$command]\n");
$self->factoids->hash->{$channel}->{$keyword}->{ref_count}++; $self->{factoids}->hash->{$channel}->{$keyword}->{ref_count}++;
$self->factoids->hash->{$channel}->{$keyword}->{ref_user} = "$nick!$user\@$host"; $self->{factoids}->hash->{$channel}->{$keyword}->{ref_user} = "$nick!$user\@$host";
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday; $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday;
return $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $command, $tonick); return $pbot->{interpreter}->interpret($from, $nick, $user, $host, $count, $command, $tonick);
} }
my $last_ref_in = 0; my $last_ref_in = 0;
if(exists $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on}) { if(exists $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on}) {
if(exists $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in}) { if(exists $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_in}) {
if($self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in} eq $from) { if($self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_in} eq $from) {
$last_ref_in = 1; $last_ref_in = 1;
} }
} }
if(($last_ref_in == 1) and (gettimeofday - $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} < $self->factoids->hash->{$channel}->{$keyword}->{rate_limit})) { if(($last_ref_in == 1) and (gettimeofday - $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on} < $self->{factoids}->hash->{$channel}->{$keyword}->{rate_limit})) {
return "/msg $nick $ref_from'$keyword' is rate-limited; try again in " . ($self->factoids->hash->{$channel}->{$keyword}->{rate_limit} - int(gettimeofday - $self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on})) . " seconds."; return "/msg $nick $ref_from'$keyword' is rate-limited; try again in " . ($self->{factoids}->hash->{$channel}->{$keyword}->{rate_limit} - int(gettimeofday - $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on})) . " seconds.";
} }
} }
if($self->factoids->hash->{$channel}->{$keyword}->{enabled} == 0) { if($self->{factoids}->hash->{$channel}->{$keyword}->{enabled} == 0) {
$self->{pbot}->logger->log("$keyword disabled.\n"); $self->{pbot}->{logger}->log("$keyword disabled.\n");
return "/msg $nick $ref_from$keyword is currently disabled."; return "/msg $nick $ref_from$keyword is currently disabled.";
} }
elsif($self->factoids->hash->{$channel}->{$keyword}->{type} eq 'module') { elsif($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'module') {
$self->{pbot}->logger->log("Found module\n"); $self->{pbot}->{logger}->log("Found module\n");
$self->factoids->hash->{$channel}->{$keyword}->{ref_count}++; $self->{factoids}->hash->{$channel}->{$keyword}->{ref_count}++;
$self->factoids->hash->{$channel}->{$keyword}->{ref_user} = "$nick!$user\@$host"; $self->{factoids}->hash->{$channel}->{$keyword}->{ref_user} = "$nick!$user\@$host";
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday; $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday;
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in} = $from || "stdin"; $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_in} = $from || "stdin";
my $preserve_whitespace = $self->factoids->hash->{$channel}->{$keyword}->{preserve_whitespace}; my $preserve_whitespace = $self->{factoids}->hash->{$channel}->{$keyword}->{preserve_whitespace};
$preserve_whitespace = 0 if not defined $preserve_whitespace; $preserve_whitespace = 0 if not defined $preserve_whitespace;
return $ref_from . $self->{factoidmodulelauncher}->execute_module($from, $tonick, $nick, $user, $host, "$keyword $arguments", $keyword, $arguments, $preserve_whitespace); return $ref_from . $self->{factoidmodulelauncher}->execute_module($from, $tonick, $nick, $user, $host, "$keyword $arguments", $keyword, $arguments, $preserve_whitespace);
} }
elsif($self->factoids->hash->{$channel}->{$keyword}->{type} eq 'text') { elsif($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'text') {
$self->{pbot}->logger->log("Found factoid\n"); $self->{pbot}->{logger}->log("Found factoid\n");
# Don't allow user-custom /msg factoids, unless factoid triggered by admin # Don't allow user-custom /msg factoids, unless factoid triggered by admin
if(($self->factoids->hash->{$channel}->{$keyword}->{action} =~ m/^\/msg/i) and (not $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host"))) { if(($self->{factoids}->hash->{$channel}->{$keyword}->{action} =~ m/^\/msg/i) and (not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host"))) {
$self->{pbot}->logger->log("[ABUSE] Bad factoid (contains /msg): " . $self->factoids->hash->{$channel}->{$keyword}->{action} . "\n"); $self->{pbot}->{logger}->log("[ABUSE] Bad factoid (contains /msg): " . $self->{factoids}->hash->{$channel}->{$keyword}->{action} . "\n");
return "You must login to use this command." return "You must login to use this command."
} }
$self->factoids->hash->{$channel}->{$keyword}->{ref_count}++; $self->{factoids}->hash->{$channel}->{$keyword}->{ref_count}++;
$self->factoids->hash->{$channel}->{$keyword}->{ref_user} = "$nick!$user\@$host"; $self->{factoids}->hash->{$channel}->{$keyword}->{ref_user} = "$nick!$user\@$host";
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday; $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday;
$self->factoids->hash->{$channel}->{$keyword}->{last_referenced_in} = $from || "stdin"; $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_in} = $from || "stdin";
$result = $self->factoids->hash->{$channel}->{$keyword}->{action}; $result = $self->{factoids}->hash->{$channel}->{$keyword}->{action};
if(length $arguments) { if(length $arguments) {
if(exists $self->factoids->hash->{$channel}->{$keyword}->{action_with_args}) { if(exists $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args}) {
$result = $self->factoids->hash->{$channel}->{$keyword}->{action_with_args}; $result = $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args};
} }
if(not $result =~ s/\$args/$arguments/gi and not exists $self->factoids->hash->{$channel}->{$keyword}->{action_with_args}) { if(not $result =~ s/\$args/$arguments/gi and not exists $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args}) {
# factoid doesn't take an argument, so assume argument is a nick if it is a single-word 20 characters or less # factoid doesn't take an argument, so assume argument is a nick if it is a single-word 20 characters or less
# TODO - maintain list of channel nicks and compare against this list to ensure nick exists # TODO - maintain list of channel nicks and compare against this list to ensure nick exists
if($arguments =~ /^[^.+-, ]{1,20}$/) { if($arguments =~ /^[^.+-, ]{1,20}$/) {
@ -456,7 +456,7 @@ sub interpreter {
} }
if(defined $tonick) { # !tell foo about bar if(defined $tonick) { # !tell foo about bar
$self->{pbot}->logger->log("($from): $nick!$user\@$host) sent to $tonick\n"); $self->{pbot}->{logger}->log("($from): $nick!$user\@$host) sent to $tonick\n");
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
# get rid of original caller's nick # get rid of original caller's nick
@ -470,35 +470,35 @@ sub interpreter {
$result = "/say $tonick: $keyword is $result"; $result = "/say $tonick: $keyword is $result";
} }
$self->{pbot}->logger->log("result set to [$result]\n"); $self->{pbot}->{logger}->log("result set to [$result]\n");
} }
$self->{pbot}->logger->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host: $keyword: Displaying text \"" . $result . "\"\n"); $self->{pbot}->{logger}->log("(" . (defined $from ? $from : "(undef)") . "): $nick!$user\@$host: $keyword: Displaying text \"" . $result . "\"\n");
$result =~ s/\$nick/$nick/g; $result =~ s/\$nick/$nick/g;
$result =~ s/\$channel/$from/g; $result =~ s/\$channel/$from/g;
while ($result =~ /[^\\]\$([a-zA-Z0-9_\-]+)/g) { while ($result =~ /[^\\]\$([a-zA-Z0-9_\-]+)/g) {
#$self->{pbot}->logger->log("adlib: looking for [$1]\n"); #$self->{pbot}->{logger}->log("adlib: looking for [$1]\n");
#$self->{pbot}->logger->log("calling find_factoid in Factoids.pm, interpreter() to look for adlib"); #$self->{pbot}->{logger}->log("calling find_factoid in Factoids.pm, interpreter() to look for adlib");
my ($var_chan, $var) = $self->find_factoid($from, $1, undef, 0, 1); my ($var_chan, $var) = $self->find_factoid($from, $1, undef, 0, 1);
if(defined $var && $self->factoids->hash->{$var_chan}->{$var}->{type} eq 'text') { if(defined $var && $self->{factoids}->hash->{$var_chan}->{$var}->{type} eq 'text') {
my $change = $self->factoids->hash->{$var_chan}->{$var}->{action}; my $change = $self->{factoids}->hash->{$var_chan}->{$var}->{action};
my @list = split(/\s|(".*?")/, $change); my @list = split(/\s|(".*?")/, $change);
my @mylist; my @mylist;
#$self->{pbot}->logger->log("adlib: list [". join(':', @mylist) ."]\n"); #$self->{pbot}->{logger}->log("adlib: list [". join(':', @mylist) ."]\n");
for(my $i = 0; $i <= $#list; $i++) { for(my $i = 0; $i <= $#list; $i++) {
#$self->{pbot}->logger->log("adlib: pushing $i $list[$i]\n"); #$self->{pbot}->{logger}->log("adlib: pushing $i $list[$i]\n");
push @mylist, $list[$i] if $list[$i]; push @mylist, $list[$i] if $list[$i];
} }
my $line = int(rand($#mylist + 1)); my $line = int(rand($#mylist + 1));
$mylist[$line] =~ s/"//g; $mylist[$line] =~ s/"//g;
$result =~ s/\$$var/$mylist[$line]/; $result =~ s/\$$var/$mylist[$line]/;
#$self->{pbot}->logger->log("adlib: found: change: $result\n"); #$self->{pbot}->{logger}->log("adlib: found: change: $result\n");
} else { } else {
$result =~ s/\$$var/$var/g; $result =~ s/\$$var/$var/g;
#$self->{pbot}->logger->log("adlib: not found: change: $result\n"); #$self->{pbot}->{logger}->log("adlib: not found: change: $result\n");
} }
} }
@ -518,13 +518,13 @@ sub interpreter {
return "$keyword is $result"; return "$keyword is $result";
} }
} }
} elsif($self->factoids->hash->{$channel}->{$keyword}->{type} eq 'regex') { } elsif($self->{factoids}->hash->{$channel}->{$keyword}->{type} eq 'regex') {
$result = eval { $result = eval {
my $string = "$original_keyword" . (defined $arguments ? " $arguments" : ""); my $string = "$original_keyword" . (defined $arguments ? " $arguments" : "");
my $cmd; my $cmd;
if($string =~ m/$keyword/i) { if($string =~ m/$keyword/i) {
$self->{pbot}->logger->log("[$string] matches [$keyword] - calling [" . $self->factoids->hash->{$channel}->{$keyword}->{action} . "$']\n"); $self->{pbot}->{logger}->log("[$string] matches [$keyword] - calling [" . $self->{factoids}->hash->{$channel}->{$keyword}->{action} . "$']\n");
$cmd = $self->factoids->hash->{$channel}->{$keyword}->{action} . $'; $cmd = $self->{factoids}->hash->{$channel}->{$keyword}->{action} . $';
my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $before, $after) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $`, $'); my ($a, $b, $c, $d, $e, $f, $g, $h, $i, $before, $after) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $`, $');
$cmd =~ s/\$1/$a/g; $cmd =~ s/\$1/$a/g;
$cmd =~ s/\$2/$b/g; $cmd =~ s/\$2/$b/g;
@ -540,21 +540,21 @@ sub interpreter {
$cmd =~ s/^\s+//; $cmd =~ s/^\s+//;
$cmd =~ s/\s+$//; $cmd =~ s/\s+$//;
} else { } else {
$cmd = $self->factoids->hash->{$channel}->{$keyword}->{action}; $cmd = $self->{factoids}->hash->{$channel}->{$keyword}->{action};
} }
$result = $pbot->interpreter->interpret($from, $nick, $user, $host, $count, $cmd, $tonick); $result = $pbot->{interpreter}->interpret($from, $nick, $user, $host, $count, $cmd, $tonick);
return $result; return $result;
}; };
if($@) { if($@) {
$self->{pbot}->logger->log("Regex fail: $@\n"); $self->{pbot}->{logger}->log("Regex fail: $@\n");
return "/msg $nick $ref_from" . "Fail."; return "/msg $nick $ref_from" . "Fail.";
} }
return $ref_from . $result; return $ref_from . $result;
} else { } else {
$self->{pbot}->logger->log("($from): $nick!$user\@$host): Unknown command type for '$keyword'\n"); $self->{pbot}->{logger}->log("($from): $nick!$user\@$host): Unknown command type for '$keyword'\n");
return "/me blinks." . " $ref_from"; return "/me blinks." . " $ref_from";
} }

View File

@ -64,7 +64,7 @@ sub load_hash {
return; return;
} }
$self->{pbot}->logger->log("Loading $self->{name} objects from $filename ...\n"); $self->{pbot}->{logger}->log("Loading $self->{name} objects from $filename ...\n");
if(not open(FILE, "< $filename")) { if(not open(FILE, "< $filename")) {
Carp::carp "Couldn't open $filename: $!\n"; Carp::carp "Couldn't open $filename: $!\n";
@ -111,7 +111,7 @@ sub load_hash {
close(FILE); close(FILE);
$self->{pbot}->logger->log("Done.\n"); $self->{pbot}->{logger}->log("Done.\n");
} }
sub save_hash { sub save_hash {
@ -154,7 +154,7 @@ sub find_hash {
}; };
if($@) { if($@) {
$self->{pbot}->logger->log("find_hash: bad regex: $@\n"); $self->{pbot}->{logger}->log("find_hash: bad regex: $@\n");
return undef; return undef;
} }

View File

@ -71,7 +71,7 @@ sub schedulequeue {
sub addconn { sub addconn {
my ($self, $conn) = @_; my ($self, $conn) = @_;
$self->addfh( $conn->socket, $conn->can('parse'), ($_[2] || 'r'), $conn); $self->addfh( ${conn}->socket, ${conn}->can('parse'), ($_[2] || 'r'), $conn);
} }
# Adds a filehandle to the select loop. Tasty and flavorful. # Adds a filehandle to the select loop. Tasty and flavorful.
@ -171,11 +171,11 @@ sub do_one_loop {
my $conn = $self->{_connhash}->{$sock}; my $conn = $self->{_connhash}->{$sock};
$conn or next; $conn or next;
# $conn->[0] is a code reference to a handler sub. # ${conn}->[0] is a code reference to a handler sub.
# $conn->[1] is optionally an object which the # ${conn}->[1] is optionally an object which the
# handler sub may be a method of. # handler sub may be a method of.
$conn->[0]->($conn->[1] ? ($conn->[1], $sock) : $sock); ${conn}->[0]->(${conn}->[1] ? (${conn}->[1], $sock) : $sock);
} }
} }
} }
@ -194,7 +194,7 @@ sub newconn {
my $self = shift; my $self = shift;
my $conn = PBot::IRC::Connection->new($self, @_); # pragma_ 2011/01/21 my $conn = PBot::IRC::Connection->new($self, @_); # pragma_ 2011/01/21
return if $conn->error; return if ${conn}->error;
return $conn; return $conn;
} }
@ -237,7 +237,7 @@ sub dequeue_output_event {
sub removeconn { sub removeconn {
my ($self, $conn) = @_; my ($self, $conn) = @_;
$self->removefh( $conn->socket ); $self->removefh( ${conn}->socket );
} }
# Given a filehandle, removes it from all select lists. You get the picture. # Given a filehandle, removes it from all select lists. You get the picture.
@ -295,11 +295,11 @@ and we'll be happy to help you out with bringing your bots into the modern era.
use Net::IRC; use Net::IRC;
$irc = new Net::IRC; $irc = new Net::IRC;
$conn = $irc->newconn(Nick => 'some_nick', $conn = ${irc}->newconn(Nick => 'some_nick',
Server => 'some.irc.server.com', Server => 'some.irc.server.com',
Port => 6667, Port => 6667,
Ircname => 'Some witty comment.'); Ircname => 'Some witty comment.');
$irc->start; ${irc}->start;
=head1 DESCRIPTION =head1 DESCRIPTION
@ -416,7 +416,7 @@ To that end, say something like this:
$irc = new Net::IRC; $irc = new Net::IRC;
$conn = $irc->newconn(Nick => 'some_nick', $conn = ${irc}->newconn(Nick => 'some_nick',
Server => 'some.irc.server.com'); Server => 'some.irc.server.com');
...or something similar. Acceptable parameters to newconn() are: ...or something similar. Acceptable parameters to newconn() are:
@ -531,7 +531,7 @@ When you've set up all your handlers, the following command will put your
program in an infinite loop, grabbing input from all open connections and program in an infinite loop, grabbing input from all open connections and
passing it off to the proper handlers: passing it off to the proper handlers:
$irc->start; ${irc}->start;
Note that new connections can be added and old ones dropped from within your Note that new connections can be added and old ones dropped from within your
handlers even after you call this. Just don't expect any code below the call handlers even after you call this. Just don't expect any code below the call
@ -610,7 +610,7 @@ B<Optional:> A string containing any combination of the letters r, w or e
conditions you're expecting on that filehandle. For example, this line conditions you're expecting on that filehandle. For example, this line
select()s $fh (a filehandle, of course) for both reading and writing: select()s $fh (a filehandle, of course) for both reading and writing:
$irc->addfh( $fh, \&callback, "rw" ); ${irc}->addfh( $fh, \&callback, "rw" );
=back =back

View File

@ -37,15 +37,15 @@ sub initialize {
sub on_connect { sub on_connect {
my ($self, $conn) = @_; my ($self, $conn) = @_;
$self->{pbot}->logger->log("Connected!\n"); $self->{pbot}->{logger}->log("Connected!\n");
$conn->{connected} = 1; ${conn}->{connected} = 1;
} }
sub on_disconnect { sub on_disconnect {
my ($self, $conn, $event) = @_; my ($self, $conn, $event) = @_;
$self->{pbot}->logger->log("Disconnected, attempting to reconnect...\n"); $self->{pbot}->{logger}->log("Disconnected, attempting to reconnect...\n");
$conn->connect(); ${conn}->connect();
if(not $conn->connected) { if(not ${conn}->connected) {
sleep(5); sleep(5);
$self->on_disconnect($self, $conn, $event); $self->on_disconnect($self, $conn, $event);
} }
@ -55,7 +55,7 @@ sub on_init {
my ($self, $conn, $event) = @_; my ($self, $conn, $event) = @_;
my (@args) = ($event->args); my (@args) = ($event->args);
shift (@args); shift (@args);
$self->{pbot}->logger->log("*** @args\n"); $self->{pbot}->{logger}->log("*** @args\n");
} }
sub on_public { sub on_public {
@ -67,7 +67,7 @@ sub on_public {
my $host = $event->host; my $host = $event->host;
my $text = $event->{args}[0]; my $text = $event->{args}[0];
$self->{pbot}->interpreter->process_line($from, $nick, $user, $host, $text); $self->{pbot}->{interpreter}->process_line($from, $nick, $user, $host, $text);
} }
sub on_msg { sub on_msg {
@ -87,18 +87,18 @@ sub on_notice {
my ($nick, $host) = ($event->nick, $event->host); my ($nick, $host) = ($event->nick, $event->host);
my $text = $event->{args}[0]; my $text = $event->{args}[0];
$self->{pbot}->logger->log("Received NOTICE from $nick $host '$text'\n"); $self->{pbot}->{logger}->log("Received NOTICE from $nick $host '$text'\n");
if($nick eq "NickServ" && $text =~ m/This nickname is registered/) { if($nick eq "NickServ" && $text =~ m/This nickname is registered/) {
$self->{pbot}->logger->log("Identifying with NickServ . . .\n"); $self->{pbot}->{logger}->log("Identifying with NickServ . . .\n");
$conn->privmsg("nickserv", "identify " . $self->{pbot}->{registry}->get_value('irc', 'identify_password')); ${conn}->privmsg("nickserv", "identify " . $self->{pbot}->{registry}->get_value('irc', 'identify_password'));
} }
if($nick eq "NickServ" && $text =~ m/You are now identified/) { if($nick eq "NickServ" && $text =~ m/You are now identified/) {
foreach my $chan (keys %{ $self->{pbot}->channels->channels->hash }) { foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) {
if($self->{pbot}->channels->channels->hash->{$chan}{enabled}) { if($self->{pbot}->{channels}->{channels}->hash->{$chan}{enabled}) {
$self->{pbot}->logger->log("Joining channel: $chan\n"); $self->{pbot}->{logger}->log("Joining channel: $chan\n");
$conn->join($chan); ${conn}->join($chan);
} }
} }
$self->{pbot}->{joined_channels} = 1; $self->{pbot}->{joined_channels} = 1;
@ -135,39 +135,39 @@ sub on_mode {
$mode = $modifier . $char; $mode = $modifier . $char;
$target = $event->{args}[++$i]; $target = $event->{args}[++$i];
$self->{pbot}->logger->log("Got mode: source: $nick!$user\@$host, mode: $mode, target: " . (defined $target ? $target : "(undef)") . ", channel: $channel\n"); $self->{pbot}->{logger}->log("Got mode: source: $nick!$user\@$host, mode: $mode, target: " . (defined $target ? $target : "(undef)") . ", channel: $channel\n");
if($mode eq "-b" or $mode eq "+b" or $mode eq "-q" or $mode eq "+q") { if($mode eq "-b" or $mode eq "+b" or $mode eq "-q" or $mode eq "+q") {
$self->{pbot}->bantracker->track_mode("$nick!$user\@$host", $mode, $target, $channel); $self->{pbot}->{bantracker}->track_mode("$nick!$user\@$host", $mode, $target, $channel);
} }
if(defined $target && $target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { # bot targeted if(defined $target && $target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { # bot targeted
if($mode eq "+o") { if($mode eq "+o") {
$self->{pbot}->logger->log("$nick opped me in $channel\n"); $self->{pbot}->{logger}->log("$nick opped me in $channel\n");
$self->{pbot}->chanops->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # 5 minutes $self->{pbot}->{chanops}->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # 5 minutes
$self->{pbot}->chanops->perform_op_commands($channel); $self->{pbot}->{chanops}->perform_op_commands($channel);
} }
elsif($mode eq "-o") { elsif($mode eq "-o") {
$self->{pbot}->logger->log("$nick removed my ops in $channel\n"); $self->{pbot}->{logger}->log("$nick removed my ops in $channel\n");
delete $self->{pbot}->chanops->{is_opped}->{$channel}; delete $self->{pbot}->{chanops}->{is_opped}->{$channel};
} }
elsif($mode eq "+b") { elsif($mode eq "+b") {
$self->{pbot}->logger->log("Got banned in $channel, attempting unban."); $self->{pbot}->{logger}->log("Got banned in $channel, attempting unban.");
$conn->privmsg("chanserv", "unban $channel"); ${conn}->privmsg("chanserv", "unban $channel");
} }
} }
else { # bot not targeted else { # bot not targeted
if($mode eq "+b") { if($mode eq "+b") {
if($nick eq "ChanServ") { if($nick eq "ChanServ") {
$self->{pbot}->chanops->{unban_timeout}->hash->{$channel}->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours $self->{pbot}->{chanops}->{unban_timeout}->hash->{$channel}->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours
$self->{pbot}->chanops->{unban_timeout}->save; $self->{pbot}->{chanops}->{unban_timeout}->save;
} }
} }
elsif($mode eq "+e" && $channel eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { elsif($mode eq "+e" && $channel eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
foreach my $chan (keys %{ $self->{pbot}->channels->channels->hash }) { foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) {
if($self->channels->channels->hash->{$chan}{enabled}) { if($self->{channels}->{channels}->hash->{$chan}{enabled}) {
$self->{pbot}->logger->log("Joining channel: $chan\n"); $self->{pbot}->{logger}->log("Joining channel: $chan\n");
$self->{pbot}->conn->join($chan); $self->{pbot}->{conn}->join($chan);
} }
} }
@ -183,14 +183,14 @@ sub on_join {
my $message_account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host); my $message_account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host);
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, "JOIN", $self->{pbot}->{messagehistory}->{MSG_JOIN}); $self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, "JOIN", $self->{pbot}->{messagehistory}->{MSG_JOIN});
$self->{pbot}->antiflood->check_flood($channel, $nick, $user, $host, "JOIN", $self->{pbot}->{registry}->get_value('antiflood', 'max_join_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_JOIN}); $self->{pbot}->{antiflood}->check_flood($channel, $nick, $user, $host, "JOIN", $self->{pbot}->{registry}->get_value('antiflood', 'max_join_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_JOIN});
} }
sub on_kick { sub on_kick {
my ($self, $conn, $event) = @_; my ($self, $conn, $event) = @_;
my ($nick, $user, $host, $target, $channel, $reason) = ($event->nick, $event->user, $event->host, $event->to, $event->{args}[0], $event->{args}[1]); my ($nick, $user, $host, $target, $channel, $reason) = ($event->nick, $event->user, $event->host, $event->to, $event->{args}[0], $event->{args}[1]);
$self->{pbot}->logger->log("$nick!$user\@$host kicked $target from $channel ($reason)\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host kicked $target from $channel ($reason)\n");
my ($message_account) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($target); my ($message_account) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($target);
@ -201,7 +201,7 @@ sub on_kick {
my $text = "KICKED by $nick!$user\@$host ($reason)"; my $text = "KICKED by $nick!$user\@$host ($reason)";
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, $text, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}); $self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, $text, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
$self->{pbot}->antiflood->check_flood($channel, $target_nick, $target_user, $target_host, $text, $self->{pbot}->{registry}->get_value('antiflood', 'max_join_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}); $self->{pbot}->{antiflood}->check_flood($channel, $target_nick, $target_user, $target_host, $text, $self->{pbot}->{registry}->get_value('antiflood', 'max_join_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
} }
} }
@ -225,12 +225,12 @@ sub on_departure {
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, $text, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}); $self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, $text, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
} }
$self->{pbot}->antiflood->check_flood($channel, $nick, $user, $host, $text, $self->{pbot}->{registry}->get_value('antiflood', 'max_join_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}); $self->{pbot}->{antiflood}->check_flood($channel, $nick, $user, $host, $text, $self->{pbot}->{registry}->get_value('antiflood', 'max_join_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
my $admin = $self->{pbot}->admins->find_admin($channel, "$nick!$user\@$host"); my $admin = $self->{pbot}->{admins}->find_admin($channel, "$nick!$user\@$host");
if(defined $admin and $admin->{loggedin}) { if(defined $admin and $admin->{loggedin}) {
$self->{pbot}->logger->log("Whoops, $nick left while still logged in.\n"); $self->{pbot}->{logger}->log("Whoops, $nick left while still logged in.\n");
$self->{pbot}->logger->log("Logged out $nick.\n"); $self->{pbot}->{logger}->log("Logged out $nick.\n");
delete $admin->{loggedin}; delete $admin->{loggedin};
} }
} }
@ -239,7 +239,7 @@ sub on_nickchange {
my ($self, $conn, $event) = @_; my ($self, $conn, $event) = @_;
my ($nick, $user, $host, $newnick) = ($event->nick, $event->user, $event->host, $event->args); my ($nick, $user, $host, $newnick) = ($event->nick, $event->user, $event->host, $event->args);
$self->{pbot}->logger->log("$nick!$user\@$host changed nick to $newnick\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host changed nick to $newnick\n");
my $message_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host); my $message_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($message_account); $self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($message_account);
@ -253,7 +253,7 @@ sub on_nickchange {
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($newnick_account); $self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($newnick_account);
$self->{pbot}->{messagehistory}->{database}->update_hostmask_data($newnick_account, { last_seen => scalar gettimeofday }); $self->{pbot}->{messagehistory}->{database}->update_hostmask_data($newnick_account, { last_seen => scalar gettimeofday });
$self->{pbot}->antiflood->check_flood("$nick!$user\@$host", $nick, $user, $host, "NICKCHANGE $newnick", $self->{pbot}->{registry}->get_value('antiflood', 'max_nick_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}); $self->{pbot}->{antiflood}->check_flood("$nick!$user\@$host", $nick, $user, $host, "NICKCHANGE $newnick", $self->{pbot}->{registry}->get_value('antiflood', 'max_nick_flood'), 60 * 30, $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE});
} }
1; 1;

View File

@ -37,7 +37,7 @@ sub initialize {
$self->load_ignores; $self->load_ignores;
$self->{pbot}->timer->register(sub { $self->check_ignore_timeouts }, 10); $self->{pbot}->{timer}->register(sub { $self->check_ignore_timeouts }, 10);
} }
sub add { sub add {
@ -72,7 +72,7 @@ sub load_ignores {
return; return;
} }
$self->{pbot}->logger->log("Loading ignorelist from $filename ...\n"); $self->{pbot}->{logger}->log("Loading ignorelist from $filename ...\n");
open(FILE, "< $filename") or Carp::croak "Couldn't open $filename: $!\n"; open(FILE, "< $filename") or Carp::croak "Couldn't open $filename: $!\n";
my @contents = <FILE>; my @contents = <FILE>;
@ -97,8 +97,8 @@ sub load_ignores {
${ $self->{ignore_list} }{$hostmask}{$channel} = $length; ${ $self->{ignore_list} }{$hostmask}{$channel} = $length;
} }
$self->{pbot}->logger->log(" $i entries in ignorelist\n"); $self->{pbot}->{logger}->log(" $i entries in ignorelist\n");
$self->{pbot}->logger->log("Done.\n"); $self->{pbot}->{logger}->log("Done.\n");
} }
sub save_ignores { sub save_ignores {
@ -152,8 +152,8 @@ sub check_ignore {
$self->{commands}->ignore_user("", "floodcontrol", "", "", ".* $channel 300"); $self->{commands}->ignore_user("", "floodcontrol", "", "", ".* $channel 300");
$self->{ignore_flood_counter}->{$channel} = 0; $self->{ignore_flood_counter}->{$channel} = 0;
if($channel =~ /^#/) { if($channel =~ /^#/) {
$pbot->conn->me($channel, "has been overwhelmed."); $pbot->{conn}->me($channel, "has been overwhelmed.");
$pbot->conn->me($channel, "lies down and falls asleep."); $pbot->{conn}->me($channel, "lies down and falls asleep.");
return 1; return 1;
} }
} }
@ -161,7 +161,7 @@ sub check_ignore {
foreach my $ignored (keys %{ $self->{ignore_list} }) { foreach my $ignored (keys %{ $self->{ignore_list} }) {
foreach my $ignored_channel (keys %{ ${ $self->{ignore_list} }{$ignored} }) { foreach my $ignored_channel (keys %{ ${ $self->{ignore_list} }{$ignored} }) {
#$self->{pbot}->logger->log("check_ignore: comparing '$hostmask' against '$ignored' for channel '$channel'\n"); #$self->{pbot}->{logger}->log("check_ignore: comparing '$hostmask' against '$ignored' for channel '$channel'\n");
my $ignored_channel_escaped = quotemeta $ignored_channel; my $ignored_channel_escaped = quotemeta $ignored_channel;
my $ignored_escaped = quotemeta $ignored; my $ignored_escaped = quotemeta $ignored;
@ -169,7 +169,7 @@ sub check_ignore {
$ignored_escaped =~ s/\\(\.|\*)/$1/g; $ignored_escaped =~ s/\\(\.|\*)/$1/g;
if(($channel =~ /$ignored_channel_escaped/i) && ($hostmask =~ /$ignored_escaped/i)) { if(($channel =~ /$ignored_channel_escaped/i) && ($hostmask =~ /$ignored_escaped/i)) {
$self->{pbot}->logger->log("$nick!$user\@$host message ignored in channel $channel (matches [$ignored] host and [$ignored_channel] channel)\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host message ignored in channel $channel (matches [$ignored] host and [$ignored_channel] channel)\n");
return 1; return 1;
} }
} }
@ -188,11 +188,11 @@ sub check_ignore_timeouts {
if($self->{ignore_list}->{$hostmask}{$channel} < $now) { if($self->{ignore_list}->{$hostmask}{$channel} < $now) {
$self->{commands}->unignore_user("", "floodcontrol", "", "", "$hostmask $channel"); $self->{commands}->unignore_user("", "floodcontrol", "", "", "$hostmask $channel");
if($hostmask eq ".*") { if($hostmask eq ".*") {
$self->{pbot}->conn->me($channel, "awakens."); $self->{pbot}->{conn}->me($channel, "awakens.");
} }
} else { } else {
#my $timediff = $ignore_list{$host}{$channel} - $now; #my $timediff = $ignore_list{$host}{$channel} - $now;
#$logger->log "ignore: $host has $timediff seconds remaining\n" #${logger}->log "ignore: $host has $timediff seconds remaining\n"
} }
} }
} }

View File

@ -33,8 +33,8 @@ sub initialize {
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$pbot->commands->register(sub { return $self->ignore_user(@_) }, "ignore", 10); $pbot->{commands}->register(sub { return $self->ignore_user(@_) }, "ignore", 10);
$pbot->commands->register(sub { return $self->unignore_user(@_) }, "unignore", 10); $pbot->{commands}->register(sub { return $self->unignore_user(@_) }, "unignore", 10);
} }
sub ignore_user { sub ignore_user {
@ -53,9 +53,9 @@ sub ignore_user {
my $text = "Ignored: "; my $text = "Ignored: ";
my $sep = ""; my $sep = "";
foreach my $ignored (keys %{ $self->{pbot}->ignorelist->{ignore_list} }) { foreach my $ignored (keys %{ $self->{pbot}->{ignorelist}->{ignore_list} }) {
foreach my $channel (keys %{ ${ $self->{pbot}->ignorelist->{ignore_list} }{$ignored} }) { foreach my $channel (keys %{ ${ $self->{pbot}->{ignorelist}->{ignore_list} }{$ignored} }) {
$text .= $sep . "[$ignored]->[$channel]->[" . (${ $self->{pbot}->ignorelist->{ignore_list} }{$ignored}{$channel} == -1 ? -1 : int(gettimeofday - ${ $self->{pbot}->ignorelist->{ignore_list} }{$ignored}{$channel})) . "]"; $text .= $sep . "[$ignored]->[$channel]->[" . (${ $self->{pbot}->{ignorelist}->{ignore_list} }{$ignored}{$channel} == -1 ? -1 : int(gettimeofday - ${ $self->{pbot}->{ignorelist}->{ignore_list} }{$ignored}{$channel})) . "]";
$sep = ";\n"; $sep = ";\n";
} }
} }
@ -70,8 +70,8 @@ sub ignore_user {
$length = -1; # permanently $length = -1; # permanently
} }
$self->{pbot}->logger->log("$nick added [$target][$channel] to ignore list for $length seconds\n"); $self->{pbot}->{logger}->log("$nick added [$target][$channel] to ignore list for $length seconds\n");
$self->{pbot}->ignorelist->add($target, $channel, $length); $self->{pbot}->{ignorelist}->add($target, $channel, $length);
return "/msg $nick [$target][$channel] added to ignore list for $length seconds"; return "/msg $nick [$target][$channel] added to ignore list for $length seconds";
} }
@ -88,13 +88,13 @@ sub unignore_user {
$channel = ".*"; $channel = ".*";
} }
if(not exists ${ $self->{pbot}->ignorelist->{ignore_list} }{$target}{$channel}) { if(not exists ${ $self->{pbot}->{ignorelist}->{ignore_list} }{$target}{$channel}) {
$self->{pbot}->logger->log("$nick attempt to remove nonexistent [$target][$channel] from ignore list\n"); $self->{pbot}->{logger}->log("$nick attempt to remove nonexistent [$target][$channel] from ignore list\n");
return "/msg $nick [$target][$channel] not found in ignore list (use '!ignore list' to list ignores"; return "/msg $nick [$target][$channel] not found in ignore list (use '!ignore list' to list ignores";
} }
$self->{pbot}->ignorelist->remove($target, $channel); $self->{pbot}->{ignorelist}->remove($target, $channel);
$self->{pbot}->logger->log("$nick removed [$target][$channel] from ignore list\n"); $self->{pbot}->{logger}->log("$nick removed [$target][$channel] from ignore list\n");
return "/msg $nick [$target][$channel] unignored"; return "/msg $nick [$target][$channel] unignored";
} }

View File

@ -97,7 +97,7 @@ sub process_line {
my $message_account = $pbot->{messagehistory}->get_message_account($nick, $user, $host); my $message_account = $pbot->{messagehistory}->get_message_account($nick, $user, $host);
$pbot->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $from, $text, $pbot->{messagehistory}->{MSG_CHAT}); $pbot->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $from, $text, $pbot->{messagehistory}->{MSG_CHAT});
$pbot->antiflood->check_flood($from, $nick, $user, $host, $text, $pbot->{registry}->get_value('antiflood', 'max_chat_flood'), 10, $pbot->{messagehistory}->{MSG_CHAT}) if defined $from; $pbot->{antiflood}->check_flood($from, $nick, $user, $host, $text, $pbot->{registry}->get_value('antiflood', 'max_chat_flood'), 10, $pbot->{messagehistory}->{MSG_CHAT}) if defined $from;
$text =~ s/^\s+//; $text =~ s/^\s+//;
$text =~ s/\s+$//; $text =~ s/\s+$//;
@ -127,17 +127,17 @@ sub process_line {
if(defined $command || defined $has_url || defined $has_code) { if(defined $command || defined $has_url || defined $has_code) {
if((defined $command && $command !~ /^login/i) || defined $has_url || defined $has_code) { if((defined $command && $command !~ /^login/i) || defined $has_url || defined $has_code) {
if(defined $from && $pbot->ignorelist->check_ignore($nick, $user, $host, $from) && not $pbot->admins->loggedin($from, "$nick!$user\@$host")) { if(defined $from && $pbot->{ignorelist}->check_ignore($nick, $user, $host, $from) && not $pbot->{admins}->loggedin($from, "$nick!$user\@$host")) {
# ignored hostmask # ignored hostmask
$pbot->logger->log("ignored text: [$from][$nick!$user\@$host\[$text\]\n"); $pbot->{logger}->log("ignored text: [$from][$nick!$user\@$host\[$text\]\n");
return; return;
} }
} }
if(defined $has_url) { if(defined $has_url) {
$self->{pbot}->factoids->{factoidmodulelauncher}->execute_module($from, undef, $nick, $user, $host, $text, "title", "$nick http://$has_url", $preserve_whitespace); $self->{pbot}->{factoids}->{factoidmodulelauncher}->execute_module($from, undef, $nick, $user, $host, $text, "title", "$nick http://$has_url", $preserve_whitespace);
} elsif(defined $has_code) { } elsif(defined $has_code) {
$self->{pbot}->factoids->{factoidmodulelauncher}->execute_module($from, undef, $nick, $user, $host, $text, "compiler_block", (defined $nick_override ? $nick_override : $nick) . " $from $has_code }", $preserve_whitespace); $self->{pbot}->{factoids}->{factoidmodulelauncher}->execute_module($from, undef, $nick, $user, $host, $text, "compiler_block", (defined $nick_override ? $nick_override : $nick) . " $from $has_code }", $preserve_whitespace);
} else { } else {
$self->handle_result($from, $nick, $user, $host, $text, $command, $self->interpret($from, $nick, $user, $host, 1, $command), 1, $preserve_whitespace); $self->handle_result($from, $nick, $user, $host, $text, $command, $self->interpret($from, $nick, $user, $host, 1, $command), 1, $preserve_whitespace);
} }
@ -157,7 +157,7 @@ sub truncate_result {
} }
my $trunc = "... [truncated; see $link for full text.]"; my $trunc = "... [truncated; see $link for full text.]";
$self->{pbot}->logger->log("Message truncated -- pasted to $link\n") if $paste; $self->{pbot}->{logger}->log("Message truncated -- pasted to $link\n") if $paste;
my $trunc_len = length $result < $max_msg_len ? length $result : $max_msg_len; my $trunc_len = length $result < $max_msg_len ? length $result : $max_msg_len;
$result = substr($result, 0, $trunc_len); $result = substr($result, 0, $trunc_len);
@ -180,45 +180,45 @@ sub handle_result {
if($preserve_whitespace == 0 && defined $command) { if($preserve_whitespace == 0 && defined $command) {
my ($cmd, $args) = split / /, $command, 2; my ($cmd, $args) = split / /, $command, 2;
#$self->{pbot}->logger->log("calling find_factoid in Interpreter.pm, process_line() for preserve_whitespace\n"); #$self->{pbot}->{logger}->log("calling find_factoid in Interpreter.pm, process_line() for preserve_whitespace\n");
my ($chan, $trigger) = $self->{pbot}->factoids->find_factoid($from, $cmd, $args, 0, 1); my ($chan, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $cmd, $args, 0, 1);
if(defined $trigger) { if(defined $trigger) {
$preserve_whitespace = $self->{pbot}->factoids->factoids->hash->{$chan}->{$trigger}->{preserve_whitespace}; $preserve_whitespace = $self->{pbot}->{factoids}->{factoids}->hash->{$chan}->{$trigger}->{preserve_whitespace};
$preserve_whitespace = 0 if not defined $preserve_whitespace; $preserve_whitespace = 0 if not defined $preserve_whitespace;
} }
} }
$result =~ s/\s+/ /g unless $preserve_whitespace; $result =~ s/\s+/ /g unless $preserve_whitespace;
$result = $self->truncate_result($from, $nick, $text, $original_result, $result, 1); $result = $self->truncate_result($from, $nick, $text, $original_result, $result, 1);
$pbot->logger->log("Final result: [$result]\n"); $pbot->{logger}->log("Final result: [$result]\n");
if($result =~ s/^\/say\s+//i) { if($result =~ s/^\/say\s+//i) {
$pbot->conn->privmsg($from, $result) if defined $from && $from !~ /\Q$mynick\E/i; $pbot->{conn}->privmsg($from, $result) if defined $from && $from !~ /\Q$mynick\E/i;
$pbot->antiflood->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood; $pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood;
} elsif($result =~ s/^\/me\s+//i) { } elsif($result =~ s/^\/me\s+//i) {
$pbot->conn->me($from, $result) if defined $from && $from !~ /\Q$mynick\E/i; $pbot->{conn}->me($from, $result) if defined $from && $from !~ /\Q$mynick\E/i;
$pbot->antiflood->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $result, 0, 0, 0) if $checkflood; $pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $result, 0, 0, 0) if $checkflood;
} elsif($result =~ s/^\/msg\s+([^\s]+)\s+//i) { } elsif($result =~ s/^\/msg\s+([^\s]+)\s+//i) {
my $to = $1; my $to = $1;
if($to =~ /,/) { if($to =~ /,/) {
$pbot->logger->log("[HACK] Possible HACK ATTEMPT /msg multiple users: [$nick!$user\@$host] [$command] [$result]\n"); $pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg multiple users: [$nick!$user\@$host] [$command] [$result]\n");
} }
elsif($to =~ /.*serv$/i) { elsif($to =~ /.*serv$/i) {
$pbot->logger->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$nick!$user\@$host] [$command] [$result]\n"); $pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$nick!$user\@$host] [$command] [$result]\n");
} }
elsif($result =~ s/^\/me\s+//i) { elsif($result =~ s/^\/me\s+//i) {
$pbot->conn->me($to, $result) if $to !~ /\Q$mynick\E/i; $pbot->{conn}->me($to, $result) if $to !~ /\Q$mynick\E/i;
$pbot->antiflood->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $result, 0, 0, 0) if $checkflood; $pbot->{antiflood}->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $result, 0, 0, 0) if $checkflood;
} else { } else {
$result =~ s/^\/say\s+//i; $result =~ s/^\/say\s+//i;
$pbot->conn->privmsg($to, $result) if $to !~ /\Q$mynick\E/i; $pbot->{conn}->privmsg($to, $result) if $to !~ /\Q$mynick\E/i;
$pbot->antiflood->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood; $pbot->{antiflood}->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood;
} }
} else { } else {
$pbot->conn->privmsg($from, $result) if defined $from && $from !~ /\Q$mynick\E/i; $pbot->{conn}->privmsg($from, $result) if defined $from && $from !~ /\Q$mynick\E/i;
$pbot->antiflood->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood; $pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood;
} }
$pbot->logger->log("---------------------------------------------\n"); $pbot->{logger}->log("---------------------------------------------\n");
} }
sub interpret { sub interpret {
@ -228,13 +228,13 @@ sub interpret {
my $text; my $text;
my $pbot = $self->pbot; my $pbot = $self->pbot;
$pbot->logger->log("=== Enter interpret_command: [" . (defined $from ? $from : "(undef)") . "][$nick!$user\@$host][$count][$command]\n"); $pbot->{logger}->log("=== Enter interpret_command: [" . (defined $from ? $from : "(undef)") . "][$nick!$user\@$host][$count][$command]\n");
return "Too many levels of recursion, aborted." if(++$count > 5); return "Too many levels of recursion, aborted." if(++$count > 5);
if(not defined $nick || not defined $user || not defined $host || if(not defined $nick || not defined $user || not defined $host ||
not defined $command) { not defined $command) {
$pbot->logger->log("Error 1, bad parameters to interpret_command\n"); $pbot->{logger}->log("Error 1, bad parameters to interpret_command\n");
return undef; return undef;
} }
@ -248,8 +248,8 @@ sub interpret {
} elsif($command =~ /^([^ ]+)\s+is\s+(.*)$/i) { } elsif($command =~ /^([^ ]+)\s+is\s+(.*)$/i) {
my ($k, $a) = ($1, $2); my ($k, $a) = ($1, $2);
$self->{pbot}->logger->log("calling find_factoid in Interpreter.pm, interpret() for factadd\n"); $self->{pbot}->{logger}->log("calling find_factoid in Interpreter.pm, interpret() for factadd\n");
my ($channel, $trigger) = $pbot->factoids->find_factoid($from, $k, $a, 1); my ($channel, $trigger) = $pbot->{factoids}->find_factoid($from, $k, $a, 1);
if(defined $trigger) { if(defined $trigger) {
($keyword, $arguments) = ($k, "is $a"); ($keyword, $arguments) = ($k, "is $a");
@ -278,7 +278,7 @@ sub interpret {
} }
if(not defined $keyword) { if(not defined $keyword) {
$pbot->logger->log("Error 2, no keyword\n"); $pbot->{logger}->log("Error 2, no keyword\n");
return undef; return undef;
} }

View File

@ -46,19 +46,19 @@ sub initialize {
$self->{lag_history} = []; # history of previous PING/PONG timings $self->{lag_history} = []; # history of previous PING/PONG timings
$self->{pong_received} = undef; # tracks pong replies; undef if no ping sent; 0 if ping sent but no pong reply yet; 1 if ping/pong completed $self->{pong_received} = undef; # tracks pong replies; undef if no ping sent; 0 if ping sent but no pong reply yet; 1 if ping/pong completed
$pbot->timer->register(sub { $self->send_ping }, $self->{LAG_HISTORY_INTERVAL}); $pbot->{timer}->register(sub { $self->send_ping }, $self->{LAG_HISTORY_INTERVAL});
$pbot->commands->register(sub { return $self->lagcheck(@_) }, "lagcheck", 0); $pbot->{commands}->register(sub { return $self->lagcheck(@_) }, "lagcheck", 0);
} }
sub send_ping { sub send_ping {
my $self = shift; my $self = shift;
return unless defined $self->{pbot}->conn; return unless defined $self->{pbot}->{conn};
$self->{ping_send_time} = [gettimeofday]; $self->{ping_send_time} = [gettimeofday];
$self->{pong_received} = 0; $self->{pong_received} = 0;
$self->{pbot}->conn->sl("PING :lagcheck"); $self->{pbot}->{conn}->sl("PING :lagcheck");
} }
sub on_pong { sub on_pong {

View File

@ -44,7 +44,9 @@ sub initialize {
$self->{MSG_DEPARTURE} = 2; # PART, QUIT, KICK $self->{MSG_DEPARTURE} = 2; # PART, QUIT, KICK
$self->{MSG_NICKCHANGE} = 3; # CHANGED NICK $self->{MSG_NICKCHANGE} = 3; # CHANGED NICK
$self->{pbot}->commands->register(sub { $self->recall_message(@_) }, "recall", 0); $self->{pbot}->{registry}->add_default('text', 'messagehistory', 'max_messages', $conf{max_messages} // 32);
$self->{pbot}->{commands}->register(sub { $self->recall_message(@_) }, "recall", 0);
$self->{pbot}->{atexit}->register(sub { $self->{database}->end(); return; }); $self->{pbot}->{atexit}->register(sub { $self->{database}->end(); return; });
} }
@ -63,7 +65,7 @@ sub recall_message {
my ($self, $from, $nick, $user, $host, $arguments) = @_; my ($self, $from, $nick, $user, $host, $arguments) = @_;
if(not defined $from) { if(not defined $from) {
$self->{pbot}->logger->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
@ -170,7 +172,7 @@ sub recall_message {
$recall_nick = $found_nick; $recall_nick = $found_nick;
} }
$self->{pbot}->logger->log("$nick ($from) recalled <$recall_nick/$recall_channel> $message->{msg}\n"); $self->{pbot}->{logger}->log("$nick ($from) recalled <$recall_nick/$recall_channel> $message->{msg}\n");
my $text = $message->{msg}; my $text = $message->{msg};
my $ago = ago(gettimeofday - $message->{timestamp}); my $ago = ago(gettimeofday - $message->{timestamp});

View File

@ -29,14 +29,14 @@ sub initialize {
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference in " . __FILE__); $self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference in " . __FILE__);
$self->{filename} = delete $conf{filename} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/message_history.sqlite3'; $self->{filename} = delete $conf{filename} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/message_history.sqlite3';
$self->{pbot}->timer->register(sub { $self->commit_message_history }, 5); $self->{pbot}->{timer}->register(sub { $self->commit_message_history }, 5);
$self->{new_entries} = 0; $self->{new_entries} = 0;
} }
sub begin { sub begin {
my $self = shift; my $self = shift;
$self->{pbot}->logger->log("Opening message history SQLite database: $self->{filename}\n"); $self->{pbot}->{logger}->log("Opening message history SQLite database: $self->{filename}\n");
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=$self->{filename}", "", "", { RaiseError => 1, PrintError => 0, AutoInactiveDestroy => 1 }) or die $DBI::errstr; $self->{dbh} = DBI->connect("dbi:SQLite:dbname=$self->{filename}", "", "", { RaiseError => 1, PrintError => 0, AutoInactiveDestroy => 1 }) or die $DBI::errstr;
@ -93,13 +93,13 @@ SQL
$self->{dbh}->begin_work(); $self->{dbh}->begin_work();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub end { sub end {
my $self = shift; my $self = shift;
$self->{pbot}->logger->log("Closing message history SQLite database\n"); $self->{pbot}->{logger}->log("Closing message history SQLite database\n");
if(exists $self->{dbh} and defined $self->{dbh}) { if(exists $self->{dbh} and defined $self->{dbh}) {
$self->{dbh}->commit() if $self->{new_entries}; $self->{dbh}->commit() if $self->{new_entries};
@ -117,7 +117,7 @@ sub get_nickserv_accounts {
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref(); return $sth->fetchall_arrayref();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return map {$_->[0]} @$nickserv_accounts; return map {$_->[0]} @$nickserv_accounts;
} }
@ -131,7 +131,7 @@ sub set_current_nickserv_account {
$sth->execute(); $sth->execute();
$self->{new_entries}++; $self->{new_entries}++;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub get_current_nickserv_account { sub get_current_nickserv_account {
@ -143,7 +143,7 @@ sub get_current_nickserv_account {
$sth->execute(); $sth->execute();
return $sth->fetchrow_hashref()->{'nickserv'}; return $sth->fetchrow_hashref()->{'nickserv'};
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $nickserv; return $nickserv;
} }
@ -159,13 +159,13 @@ sub create_nickserv {
my $rv = $sth->execute(); my $rv = $sth->execute();
$self->{new_entries}++ if $sth->rows; $self->{new_entries}++ if $sth->rows;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub update_nickserv_account { sub update_nickserv_account {
my ($self, $id, $nickserv, $timestamp) = @_; my ($self, $id, $nickserv, $timestamp) = @_;
#$self->{pbot}->logger->log("Updating nickserv account for id $id to $nickserv with timestamp [$timestamp]\n"); #$self->{pbot}->{logger}->log("Updating nickserv account for id $id to $nickserv with timestamp [$timestamp]\n");
$self->create_nickserv($id, $nickserv); $self->create_nickserv($id, $nickserv);
@ -177,7 +177,7 @@ sub update_nickserv_account {
$sth->execute(); $sth->execute();
$self->{new_entries}++; $self->{new_entries}++;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub add_message_account { sub add_message_account {
@ -207,7 +207,7 @@ sub add_message_account {
} }
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $id; return $id;
} }
@ -222,7 +222,7 @@ sub find_message_account_by_nick {
return ($row->{id}, $row->{hostmask}); return ($row->{id}, $row->{hostmask});
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
$hostmask =~ s/!.*$// if defined $hostmask; $hostmask =~ s/!.*$// if defined $hostmask;
return ($id, $hostmask); return ($id, $hostmask);
} }
@ -236,7 +236,7 @@ sub find_message_accounts_by_nickserv {
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref(); return $sth->fetchall_arrayref();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return map {$_->[0]} @$accounts; return map {$_->[0]} @$accounts;
} }
@ -253,7 +253,7 @@ sub find_message_accounts_by_mask {
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref(); return $sth->fetchall_arrayref();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return map {$_->[0]} @$accounts; return map {$_->[0]} @$accounts;
} }
@ -271,7 +271,7 @@ sub get_message_account {
my $rows = $sth->fetchall_arrayref({}); my $rows = $sth->fetchall_arrayref({});
foreach my $row (@$rows) { foreach my $row (@$rows) {
$self->{pbot}->logger->log("Found matching nick $row->{hostmask} with id $row->{id}\n"); $self->{pbot}->{logger}->log("Found matching nick $row->{hostmask} with id $row->{id}\n");
} }
if(not defined $rows->[0]) { if(not defined $rows->[0]) {
@ -280,26 +280,26 @@ sub get_message_account {
$rows = $sth->fetchall_arrayref({}); $rows = $sth->fetchall_arrayref({});
foreach my $row (@$rows) { foreach my $row (@$rows) {
$self->{pbot}->logger->log("Found matching user\@host mask $row->{hostmask} with id $row->{id}\n"); $self->{pbot}->{logger}->log("Found matching user\@host mask $row->{hostmask} with id $row->{id}\n");
} }
} }
return $rows; return $rows;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
if(defined $rows->[0]) { if(defined $rows->[0]) {
$self->{pbot}->logger->log("message-history: [get-account] $nick!$user\@$host linked to $rows->[0]->{hostmask} with id $rows->[0]->{id}\n"); $self->{pbot}->{logger}->log("message-history: [get-account] $nick!$user\@$host linked to $rows->[0]->{hostmask} with id $rows->[0]->{id}\n");
$self->add_message_account("$nick!$user\@$host", $rows->[0]->{id}); $self->add_message_account("$nick!$user\@$host", $rows->[0]->{id});
$self->devalidate_all_channels($rows->[0]->{id}); $self->devalidate_all_channels($rows->[0]->{id});
my @nickserv_accounts = $self->get_nickserv_accounts($rows->[0]->{id}); my @nickserv_accounts = $self->get_nickserv_accounts($rows->[0]->{id});
foreach my $nickserv_account (@nickserv_accounts) { foreach my $nickserv_account (@nickserv_accounts) {
$self->{pbot}->logger->log("$nick!$user\@$host [$rows->[0]->{id}] seen with nickserv account [$nickserv_account]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host [$rows->[0]->{id}] seen with nickserv account [$nickserv_account]\n");
$self->{pbot}->antiflood->check_nickserv_accounts($nick, $nickserv_account, "$nick!$user\@$host"); $self->{pbot}->{antiflood}->check_nickserv_accounts($nick, $nickserv_account, "$nick!$user\@$host");
} }
return $rows->[0]->{id}; return $rows->[0]->{id};
} }
$self->{pbot}->logger->log("No account found for mask [$mask], adding new account\n"); $self->{pbot}->{logger}->log("No account found for mask [$mask], adding new account\n");
return $self->add_message_account($mask); return $self->add_message_account($mask);
} }
@ -312,7 +312,7 @@ sub find_most_recent_hostmask {
$sth->execute(); $sth->execute();
return $sth->fetchrow_hashref()->{'hostmask'}; return $sth->fetchrow_hashref()->{'hostmask'};
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $hostmask; return $hostmask;
} }
@ -341,7 +341,7 @@ sub update_hostmask_data {
$sth->execute(); $sth->execute();
$self->{new_entries}++; $self->{new_entries}++;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub get_hostmasks_for_channel { sub get_hostmasks_for_channel {
@ -354,14 +354,14 @@ sub get_hostmasks_for_channel {
return $sth->fetchall_arrayref({}); return $sth->fetchall_arrayref({});
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $hostmasks; return $hostmasks;
} }
sub add_message { sub add_message {
my ($self, $id, $mask, $channel, $message) = @_; my ($self, $id, $mask, $channel, $message) = @_;
#$self->{pbot}->logger->log("Adding message [$id][$mask][$channel][$message->{msg}][$message->{timestamp}][$message->{mode}]\n"); #$self->{pbot}->{logger}->log("Adding message [$id][$mask][$channel][$message->{msg}][$message->{timestamp}][$message->{mode}]\n");
eval { eval {
my $sth = $self->{dbh}->prepare('INSERT INTO Messages VALUES (?, ?, ?, ?, ?)'); my $sth = $self->{dbh}->prepare('INSERT INTO Messages VALUES (?, ?, ?, ?, ?)');
@ -373,7 +373,7 @@ sub add_message {
$sth->execute(); $sth->execute();
$self->{new_entries}++; $self->{new_entries}++;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
$self->update_channel_data($id, $channel, { last_seen => $message->{timestamp} }); $self->update_channel_data($id, $channel, { last_seen => $message->{timestamp} });
$self->update_hostmask_data($mask, { last_seen => $message->{timestamp} }); $self->update_hostmask_data($mask, { last_seen => $message->{timestamp} });
} }
@ -402,7 +402,7 @@ SQL
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref({}); return $sth->fetchall_arrayref({});
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $messages; return $messages;
} }
@ -430,7 +430,7 @@ sub recall_message_by_count {
}; };
} }
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
if(defined $ignore_command) { if(defined $ignore_command) {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick'); my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
@ -473,7 +473,7 @@ sub recall_message_by_text {
}; };
} }
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
if(defined $ignore_command) { if(defined $ignore_command) {
my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger'); my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger');
@ -499,7 +499,7 @@ sub get_max_messages {
$sth->finish(); $sth->finish();
return $row->{'COUNT(*)'}; return $row->{'COUNT(*)'};
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
$count = 0 if not defined $count; $count = 0 if not defined $count;
return $count; return $count;
} }
@ -516,7 +516,7 @@ sub create_channel {
my $rv = $sth->execute(); my $rv = $sth->execute();
$self->{new_entries}++ if $sth->rows; $self->{new_entries}++ if $sth->rows;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub get_channels { sub get_channels {
@ -528,7 +528,7 @@ sub get_channels {
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref(); return $sth->fetchall_arrayref();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return map {$_->[0]} @$channels; return map {$_->[0]} @$channels;
} }
@ -557,7 +557,7 @@ sub get_channel_data {
$sth->execute(); $sth->execute();
return $sth->fetchrow_hashref(); return $sth->fetchrow_hashref();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $channel_data; return $channel_data;
} }
@ -589,7 +589,7 @@ sub update_channel_data {
$sth->execute(); $sth->execute();
$self->{new_entries}++; $self->{new_entries}++;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub get_channel_datas_where_last_offense_older_than { sub get_channel_datas_where_last_offense_older_than {
@ -601,7 +601,7 @@ sub get_channel_datas_where_last_offense_older_than {
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref({}); return $sth->fetchall_arrayref({});
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $channel_datas; return $channel_datas;
} }
@ -613,7 +613,7 @@ sub get_channel_datas_with_enter_abuses {
$sth->execute(); $sth->execute();
return $sth->fetchall_arrayref({}); return $sth->fetchall_arrayref({});
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $channel_datas; return $channel_datas;
} }
@ -629,7 +629,7 @@ sub devalidate_all_channels {
$sth->execute(); $sth->execute();
$self->{new_entries}++; $self->{new_entries}++;
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
# End of public API, the remaining are internal support routines for this module # End of public API, the remaining are internal support routines for this module
@ -644,7 +644,7 @@ sub get_new_account_id {
return $row->{id}; return $row->{id};
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return ++$id; return ++$id;
} }
@ -659,8 +659,8 @@ sub get_message_account_id {
return $row->{id}; return $row->{id};
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
#$self->{pbot}->logger->log("get_message_account_id: returning id [". (defined $id ? $id: 'undef') . "] for mask [$mask]\n"); #$self->{pbot}->{logger}->log("get_message_account_id: returning id [". (defined $id ? $id: 'undef') . "] for mask [$mask]\n");
return $id; return $id;
} }
@ -668,12 +668,12 @@ sub commit_message_history {
my $self = shift; my $self = shift;
if($self->{new_entries} > 0) { if($self->{new_entries} > 0) {
#$self->{pbot}->logger->log("Commiting $self->{new_entries} messages to SQLite\n"); #$self->{pbot}->{logger}->log("Commiting $self->{new_entries} messages to SQLite\n");
eval { eval {
$self->{dbh}->commit(); $self->{dbh}->commit();
}; };
$self->{pbot}->logger->log("SQLite error $@ when committing $self->{new_entries} entries.\n") if $@; $self->{pbot}->{logger}->log("SQLite error $@ when committing $self->{new_entries} entries.\n") if $@;
$self->{dbh}->begin_work(); $self->{dbh}->begin_work();
$self->{new_entries} = 0; $self->{new_entries} = 0;

View File

@ -87,38 +87,29 @@ sub initialize {
$self->{registry}->add_default('text', 'irc', 'username', delete $conf{username} // "pbot3"); $self->{registry}->add_default('text', 'irc', 'username', delete $conf{username} // "pbot3");
$self->{registry}->add_default('text', 'irc', 'ircname', delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/"); $self->{registry}->add_default('text', 'irc', 'ircname', delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/");
$self->{registry}->add_default('text', 'irc', 'identify_password', delete $conf{identify_password} // 'none'); $self->{registry}->add_default('text', 'irc', 'identify_password', delete $conf{identify_password} // 'none');
$self->{registry}->set('irc', 'SSL_ca_file', 'private', 1); $self->{registry}->set('irc', 'SSL_ca_file', 'private', 1);
$self->{registry}->set('irc', 'SSL_ca_path', 'private', 1); $self->{registry}->set('irc', 'SSL_ca_path', 'private', 1);
$self->{registry}->set('irc', 'identify_password', 'private', 1); $self->{registry}->set('irc', 'identify_password', 'private', 1);
$self->{registry}->add_trigger('irc', 'botnick', sub { $self->change_botnick_trigger(@_) }); $self->{registry}->add_trigger('irc', 'botnick', sub { $self->change_botnick_trigger(@_) });
$self->{registry}->add_default('text', 'antiflood', 'max_join_flood', delete $conf{max_join_flood} // 4);
$self->{registry}->add_default('text', 'antiflood', 'max_chat_flood', delete $conf{max_chat_flood} // 4);
$self->{registry}->add_default('text', 'antiflood', 'max_enter_flood', delete $conf{max_enter_flood} // 4);
$self->{registry}->add_default('text', 'antiflood', 'max_nick_flood', delete $conf{max_nick_flood} // 3);
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_lines', delete $conf{enter_abuse_max_lines} // 4);
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_seconds', delete $conf{enter_abuse_max_seconds} // 20);
$self->{registry}->add_default('text', 'antiflood', 'enter_abuse_max_offenses', delete $conf{enter_abuse_max_offenses} // 3);
$self->{registry}->add_default('text', 'messagehistory', 'max_messages', delete $conf{max_messages} // 32);
$self->{select_handler} = PBot::SelectHandler->new(pbot => $self); $self->{select_handler} = PBot::SelectHandler->new(pbot => $self);
$self->{stdin_reader} = PBot::StdinReader->new(pbot => $self); $self->{stdin_reader} = PBot::StdinReader->new(pbot => $self);
$self->{admins} = PBot::BotAdmins->new(pbot => $self, filename => delete $conf{admins_file}); $self->{admins} = PBot::BotAdmins->new(pbot => $self, filename => delete $conf{admins_file});
$self->{bantracker} = PBot::BanTracker->new(pbot => $self); $self->{bantracker} = PBot::BanTracker->new(pbot => $self);
$self->{lagchecker} = PBot::LagChecker->new(pbot => $self); $self->{lagchecker} = PBot::LagChecker->new(pbot => $self);
$self->{messagehistory} = PBot::MessageHistory->new(pbot => $self, filename => delete $conf{messagehistory_file}); $self->{messagehistory} = PBot::MessageHistory->new(pbot => $self, filename => delete $conf{messagehistory_file}, %conf);
$self->{antiflood} = PBot::AntiFlood->new(pbot => $self); $self->{antiflood} = PBot::AntiFlood->new(pbot => $self, %conf);
$self->{ignorelist} = PBot::IgnoreList->new(pbot => $self, filename => delete $conf{ignorelist_file}); $self->{ignorelist} = PBot::IgnoreList->new(pbot => $self, filename => delete $conf{ignorelist_file});
$self->{irc} = PBot::IRC->new(); $self->{irc} = PBot::IRC->new();
$self->{irchandlers} = PBot::IRCHandlers->new(pbot => $self); $self->{irchandlers} = PBot::IRCHandlers->new(pbot => $self);
$self->{channels} = PBot::Channels->new(pbot => $self, filename => delete $conf{channels_file}); $self->{channels} = PBot::Channels->new(pbot => $self, filename => delete $conf{channels_file});
$self->{chanops} = PBot::ChanOps->new(pbot => $self); $self->{chanops} = PBot::ChanOps->new(pbot => $self);
$self->interpreter(PBot::Interpreter->new(pbot => $self)); $self->{interpreter} = PBot::Interpreter->new(pbot => $self);
$self->interpreter->register(sub { return $self->commands->interpreter(@_); }); $self->{interpreter}->register(sub { return $self->{commands}->interpreter(@_); });
$self->interpreter->register(sub { return $self->factoids->interpreter(@_); }); $self->{interpreter}->register(sub { return $self->{factoids}->interpreter(@_); });
$self->{factoids} = PBot::Factoids->new( $self->{factoids} = PBot::Factoids->new(
pbot => $self, pbot => $self,
@ -139,11 +130,11 @@ sub initialize {
# create implicit bot-admin account for bot # create implicit bot-admin account for bot
my $botnick = $self->{registry}->get_value('irc', 'botnick'); my $botnick = $self->{registry}->get_value('irc', 'botnick');
$self->admins->add_admin($botnick, '.*', "$botnick!stdin\@localhost", 60, 'admin', 1); $self->{admins}->add_admin($botnick, '.*', "$botnick!stdin\@localhost", 60, 'admin', 1);
$self->admins->login($botnick, "$botnick!stdin\@localhost", 'admin'); $self->{admins}->login($botnick, "$botnick!stdin\@localhost", 'admin');
# start timer # start timer
$self->timer->start(); $self->{timer}->start();
} }
# TODO: add disconnect subroutine # TODO: add disconnect subroutine
@ -157,9 +148,9 @@ sub connect {
$server = $self->{registry}->get_value('irc', 'ircserver') if not defined $server; $server = $self->{registry}->get_value('irc', 'ircserver') if not defined $server;
$self->logger->log("Connecting to $server ...\n"); $self->{logger}->log("Connecting to $server ...\n");
$self->conn($self->irc->newconn( $self->{conn} = $self->{irc}->newconn(
Nick => $self->{registry}->get_value('irc', 'botnick'), Nick => $self->{registry}->get_value('irc', 'botnick'),
Username => $self->{registry}->get_value('irc', 'username'), Username => $self->{registry}->get_value('irc', 'username'),
Ircname => $self->{registry}->get_value('irc', 'ircname'), Ircname => $self->{registry}->get_value('irc', 'ircname'),
@ -167,54 +158,43 @@ sub connect {
SSL => $self->{registry}->get_value('irc', 'SSL'), SSL => $self->{registry}->get_value('irc', 'SSL'),
SSL_ca_file => $self->{registry}->get_value('irc', 'SSL_ca_file'), SSL_ca_file => $self->{registry}->get_value('irc', 'SSL_ca_file'),
SSL_ca_path => $self->{registry}->get_value('irc', 'SSL_ca_path'), SSL_ca_path => $self->{registry}->get_value('irc', 'SSL_ca_path'),
Port => $self->{registry}->get_value('irc', 'port'))) Port => $self->{registry}->get_value('irc', 'port'))
or Carp::croak "$0: Can't connect to IRC server.\n"; or Carp::croak "$0: Can't connect to IRC server.\n";
$self->{connected} = 1; $self->{connected} = 1;
#set up default handlers for the IRC engine #set up default handlers for the IRC engine
$self->conn->add_handler([ 251,252,253,254,302,255 ], sub { $self->irchandlers->on_init(@_) }); $self->{conn}->add_handler([ 251,252,253,254,302,255 ], sub { $self->{irchandlers}->on_init(@_) });
$self->conn->add_handler(376 , sub { $self->irchandlers->on_connect(@_) }); $self->{conn}->add_handler(376 , sub { $self->{irchandlers}->on_connect(@_) });
$self->conn->add_handler('disconnect' , sub { $self->irchandlers->on_disconnect(@_) }); $self->{conn}->add_handler('disconnect' , sub { $self->{irchandlers}->on_disconnect(@_) });
$self->conn->add_handler('notice' , sub { $self->irchandlers->on_notice(@_) }); $self->{conn}->add_handler('notice' , sub { $self->{irchandlers}->on_notice(@_) });
$self->conn->add_handler('caction' , sub { $self->irchandlers->on_action(@_) }); $self->{conn}->add_handler('caction' , sub { $self->{irchandlers}->on_action(@_) });
$self->conn->add_handler('public' , sub { $self->irchandlers->on_public(@_) }); $self->{conn}->add_handler('public' , sub { $self->{irchandlers}->on_public(@_) });
$self->conn->add_handler('msg' , sub { $self->irchandlers->on_msg(@_) }); $self->{conn}->add_handler('msg' , sub { $self->{irchandlers}->on_msg(@_) });
$self->conn->add_handler('mode' , sub { $self->irchandlers->on_mode(@_) }); $self->{conn}->add_handler('mode' , sub { $self->{irchandlers}->on_mode(@_) });
$self->conn->add_handler('part' , sub { $self->irchandlers->on_departure(@_) }); $self->{conn}->add_handler('part' , sub { $self->{irchandlers}->on_departure(@_) });
$self->conn->add_handler('join' , sub { $self->irchandlers->on_join(@_) }); $self->{conn}->add_handler('join' , sub { $self->{irchandlers}->on_join(@_) });
$self->conn->add_handler('kick' , sub { $self->irchandlers->on_kick(@_) }); $self->{conn}->add_handler('kick' , sub { $self->{irchandlers}->on_kick(@_) });
$self->conn->add_handler('quit' , sub { $self->irchandlers->on_departure(@_) }); $self->{conn}->add_handler('quit' , sub { $self->{irchandlers}->on_departure(@_) });
$self->conn->add_handler('nick' , sub { $self->irchandlers->on_nickchange(@_) }); $self->{conn}->add_handler('nick' , sub { $self->{irchandlers}->on_nickchange(@_) });
$self->conn->add_handler('pong' , sub { $self->lagchecker->on_pong(@_) }); $self->{conn}->add_handler('pong' , sub { $self->{lagchecker}->on_pong(@_) });
$self->conn->add_handler('whoisaccount' , sub { $self->antiflood->on_whoisaccount(@_) }); $self->{conn}->add_handler('whoisaccount' , sub { $self->{antiflood}->on_whoisaccount(@_) });
$self->conn->add_handler('banlist' , sub { $self->bantracker->on_banlist_entry(@_) }); $self->{conn}->add_handler('banlist' , sub { $self->{bantracker}->on_banlist_entry(@_) });
$self->conn->add_handler('endofnames' , sub { $self->bantracker->get_banlist(@_) }); $self->{conn}->add_handler('endofnames' , sub { $self->{bantracker}->get_banlist(@_) });
# freenode quietlist $self->{conn}->add_handler(728 , sub { $self->{bantracker}->on_quietlist_entry(@_) });
$self->conn->add_handler(728 , sub { $self->bantracker->on_quietlist_entry(@_) });
} }
#main loop #main loop
sub do_one_loop { sub do_one_loop {
my $self = shift; my $self = shift;
$self->{irc}->do_one_loop();
# process IRC events
$self->irc->do_one_loop();
# process SelectHandler
$self->{select_handler}->do_select(); $self->{select_handler}->do_select();
} }
sub start { sub start {
my $self = shift; my $self = shift;
$self->connect() if not $self->{connected};
if(not $self->{connected}) { while(1) { $self->do_one_loop(); }
$self->connect();
}
while(1) {
$self->do_one_loop();
}
} }
sub register_signal_handlers { sub register_signal_handlers {
@ -229,109 +209,7 @@ sub atexit {
sub change_botnick_trigger { sub change_botnick_trigger {
my ($self, $section, $item, $newvalue) = @_; my ($self, $section, $item, $newvalue) = @_;
$self->{conn}->nick($newvalue) if $self->{connected};
if($self->{connected}) {
$self->conn->nick($newvalue);
}
}
#-----------------------------------------------------------------------------------
# Getters/Setters
#-----------------------------------------------------------------------------------
sub irc {
my $self = shift;
return $self->{irc};
}
sub logger {
my $self = shift;
if(@_) { $self->{logger} = shift; }
return $self->{logger};
}
sub channels {
my $self = shift;
if(@_) { $self->{channels} = shift; }
return $self->{channels};
}
sub factoids {
my $self = shift;
if(@_) { $self->{factoids} = shift; }
return $self->{factoids};
}
sub timer {
my $self = shift;
if(@_) { $self->{timer} = shift; }
return $self->{timer};
}
sub conn {
my $self = shift;
if(@_) { $self->{conn} = shift; }
return $self->{conn};
}
sub irchandlers {
my $self = shift;
if(@_) { $self->{irchandlers} = shift; }
return $self->{irchandlers};
}
sub interpreter {
my $self = shift;
if(@_) { $self->{interpreter} = shift; }
return $self->{interpreter};
}
sub admins {
my $self = shift;
if(@_) { $self->{admins} = shift; }
return $self->{admins};
}
sub commands {
my $self = shift;
if(@_) { $self->{commands} = shift; }
return $self->{commands};
}
sub ignorelist {
my $self = shift;
if(@_) { $self->{ignorelist} = shift; }
return $self->{ignorelist};
}
sub bantracker {
my $self = shift;
if(@_) { $self->{bantracker} = shift; }
return $self->{bantracker};
}
sub lagchecker {
my $self = shift;
if(@_) { $self->{lagchecker} = shift; }
return $self->{lagchecker};
}
sub antiflood {
my $self = shift;
if(@_) { $self->{antiflood} = shift; }
return $self->{antiflood};
}
sub quotegrabs {
my $self = shift;
if(@_) { $self->{quotegrabs} = shift; }
return $self->{quotegrabs};
}
sub chanops {
my $self = shift;
if(@_) { $self->{chanops} = shift; }
return $self->{chanops};
} }
1; 1;

View File

@ -47,10 +47,10 @@ sub initialize {
#------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------
# The following could be in QuotegrabsCommands.pm, or they could be kept in here? # The following could be in QuotegrabsCommands.pm, or they could be kept in here?
#------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------
$self->{pbot}->commands->register(sub { $self->grab_quotegrab(@_) }, "grab", 0); $self->{pbot}->{commands}->register(sub { $self->grab_quotegrab(@_) }, "grab", 0);
$self->{pbot}->commands->register(sub { $self->show_quotegrab(@_) }, "getq", 0); $self->{pbot}->{commands}->register(sub { $self->show_quotegrab(@_) }, "getq", 0);
$self->{pbot}->commands->register(sub { $self->delete_quotegrab(@_) }, "delq", 0); $self->{pbot}->{commands}->register(sub { $self->delete_quotegrab(@_) }, "delq", 0);
$self->{pbot}->commands->register(sub { $self->show_random_quotegrab(@_) }, "rq", 0); $self->{pbot}->{commands}->register(sub { $self->show_random_quotegrab(@_) }, "rq", 0);
} }
sub uniq { my %seen; grep !$seen{$_}++, @_ } sub uniq { my %seen; grep !$seen{$_}++, @_ }
@ -156,7 +156,7 @@ sub grab_quotegrab {
my ($self, $from, $nick, $user, $host, $arguments) = @_; my ($self, $from, $nick, $user, $host, $arguments) = @_;
if(not defined $from) { if(not defined $from) {
$self->{pbot}->logger->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }
@ -209,7 +209,7 @@ sub grab_quotegrab {
} }
} }
$self->{pbot}->logger->log("$nick ($from) grabbed <$grab_nick/$channel> $message->{msg}\n"); $self->{pbot}->{logger}->log("$nick ($from) grabbed <$grab_nick/$channel> $message->{msg}\n");
if(not defined $grab_nicks) { if(not defined $grab_nicks) {
$grab_nicks = $grab_nick; $grab_nicks = $grab_nick;
@ -265,7 +265,7 @@ sub delete_quotegrab {
return "/msg $nick No quotegrab matching id $arguments found."; return "/msg $nick No quotegrab matching id $arguments found.";
} }
if(not $self->{pbot}->admins->loggedin($from, "$nick!$user\@$host") and $quotegrab->{grabbed_by} ne "$nick!$user\@$host") { if(not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host") and $quotegrab->{grabbed_by} ne "$nick!$user\@$host") {
return "You are not the grabber of this quote."; return "You are not the grabber of this quote.";
} }
@ -310,7 +310,7 @@ sub show_random_quotegrab {
my ($nick_search, $channel_search, $text_search); my ($nick_search, $channel_search, $text_search);
if(not defined $from) { if(not defined $from) {
$self->{pbot}->logger->log("Command missing ~from parameter!\n"); $self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return ""; return "";
} }

View File

@ -50,7 +50,7 @@ sub load_quotegrabs {
if(@_) { $filename = shift; } else { $filename = $self->{filename}; } if(@_) { $filename = shift; } else { $filename = $self->{filename}; }
return if not defined $filename; return if not defined $filename;
$self->{pbot}->logger->log("Loading quotegrabs from $filename ...\n"); $self->{pbot}->{logger}->log("Loading quotegrabs from $filename ...\n");
open(FILE, "< $filename") or die "Couldn't open $filename: $!\n"; open(FILE, "< $filename") or die "Couldn't open $filename: $!\n";
my @contents = <FILE>; my @contents = <FILE>;
@ -75,8 +75,8 @@ sub load_quotegrabs {
$quotegrab->{id} = $i + 1; $quotegrab->{id} = $i + 1;
push @{ $self->{quotegrabs} }, $quotegrab; push @{ $self->{quotegrabs} }, $quotegrab;
} }
$self->{pbot}->logger->log(" $i quotegrabs loaded.\n"); $self->{pbot}->{logger}->log(" $i quotegrabs loaded.\n");
$self->{pbot}->logger->log("Done.\n"); $self->{pbot}->{logger}->log("Done.\n");
} }
sub save_quotegrabs { sub save_quotegrabs {
@ -151,7 +151,7 @@ sub get_random_quotegrab {
}; };
if($@) { if($@) {
$self->{pbot}->logger->log("Error in show_random_quotegrab parameters: $@\n"); $self->{pbot}->{logger}->log("Error in show_random_quotegrab parameters: $@\n");
return undef; return undef;
} }

View File

@ -33,7 +33,7 @@ sub initialize {
sub begin { sub begin {
my $self = shift; my $self = shift;
$self->{pbot}->logger->log("Opening quotegrabs SQLite database: $self->{filename}\n"); $self->{pbot}->{logger}->log("Opening quotegrabs SQLite database: $self->{filename}\n");
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=$self->{filename}", "", "", { RaiseError => 1, PrintError => 0 }) or die $DBI::errstr; $self->{dbh} = DBI->connect("dbi:SQLite:dbname=$self->{filename}", "", "", { RaiseError => 1, PrintError => 0 }) or die $DBI::errstr;
@ -50,13 +50,13 @@ CREATE TABLE IF NOT EXISTS Quotegrabs (
SQL SQL
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
sub end { sub end {
my $self = shift; my $self = shift;
$self->{pbot}->logger->log("Closing quotegrabs SQLite database\n"); $self->{pbot}->{logger}->log("Closing quotegrabs SQLite database\n");
if(exists $self->{dbh} and defined $self->{dbh}) { if(exists $self->{dbh} and defined $self->{dbh}) {
$self->{dbh}->disconnect(); $self->{dbh}->disconnect();
@ -80,7 +80,7 @@ sub add_quotegrab {
return $self->{dbh}->sqlite_last_insert_rowid(); return $self->{dbh}->sqlite_last_insert_rowid();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $id; return $id;
} }
@ -94,7 +94,7 @@ sub get_quotegrab {
return $sth->fetchrow_hashref(); return $sth->fetchrow_hashref();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $quotegrab; return $quotegrab;
} }
@ -137,7 +137,7 @@ sub get_random_quotegrab {
return $sth->fetchrow_hashref(); return $sth->fetchrow_hashref();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $quotegrab; return $quotegrab;
} }
@ -150,7 +150,7 @@ sub get_all_quotegrabs {
return $sth->fetchall_arrayref({}); return $sth->fetchall_arrayref({});
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
return $quotegrabs; return $quotegrabs;
} }
@ -163,7 +163,7 @@ sub delete_quotegrab {
$sth->execute(); $sth->execute();
}; };
$self->{pbot}->logger->log($@) if $@; $self->{pbot}->{logger}->log($@) if $@;
} }
1; 1;

View File

@ -43,7 +43,7 @@ sub initialize {
sub load { sub load {
my $self = shift; my $self = shift;
$self->{pbot}->logger->log("Loading registry from " . $self->{registry}->{filename} . " ...\n"); $self->{pbot}->{logger}->log("Loading registry from " . $self->{registry}->{filename} . " ...\n");
$self->{registry}->load; $self->{registry}->load;
@ -53,7 +53,7 @@ sub load {
} }
} }
$self->{pbot}->logger->log("Done.\n"); $self->{pbot}->{logger}->log("Done.\n");
} }
sub save { sub save {

View File

@ -27,13 +27,13 @@ sub initialize {
my $pbot = delete $conf{pbot} // Carp::croak("Missing pbot reference to FactoidCommands"); my $pbot = delete $conf{pbot} // Carp::croak("Missing pbot reference to FactoidCommands");
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$pbot->commands->register(sub { return $self->regadd(@_) }, "regadd", 60); $pbot->{commands}->register(sub { return $self->regadd(@_) }, "regadd", 60);
$pbot->commands->register(sub { return $self->regrem(@_) }, "regrem", 60); $pbot->{commands}->register(sub { return $self->regrem(@_) }, "regrem", 60);
$pbot->commands->register(sub { return $self->regshow(@_) }, "regshow", 0); $pbot->{commands}->register(sub { return $self->regshow(@_) }, "regshow", 0);
$pbot->commands->register(sub { return $self->regset(@_) }, "regset", 60); $pbot->{commands}->register(sub { return $self->regset(@_) }, "regset", 60);
$pbot->commands->register(sub { return $self->regunset(@_) }, "regunset", 60); $pbot->{commands}->register(sub { return $self->regunset(@_) }, "regunset", 60);
$pbot->commands->register(sub { return $self->regchange(@_) }, "regchange", 60); $pbot->{commands}->register(sub { return $self->regchange(@_) }, "regchange", 60);
$pbot->commands->register(sub { return $self->regfind(@_) }, "regfind", 0); $pbot->{commands}->register(sub { return $self->regfind(@_) }, "regfind", 0);
} }
sub regset { sub regset {
@ -74,7 +74,7 @@ sub regadd {
$self->{pbot}->{registry}->add('text', $section, $item, $value); $self->{pbot}->{registry}->add('text', $section, $item, $value);
$self->{pbot}->logger->log("$nick!$user\@$host added registry entry [$section] $item => $value\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host added registry entry [$section] $item => $value\n");
return "/msg $nick [$section] $item set to $value"; return "/msg $nick [$section] $item set to $value";
} }
@ -95,7 +95,7 @@ sub regrem {
return "/msg $nick No such item $item in section $section."; return "/msg $nick No such item $item in section $section.";
} }
$self->{pbot}->logger->log("$nick!$user\@$host removed registry item [$section][$item]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host removed registry item [$section][$item]\n");
$self->{pbot}->{registry}->remove($section, $item); $self->{pbot}->{registry}->remove($section, $item);
return "/msg $nick Registry item $item removed from section $section."; return "/msg $nick Registry item $item removed from section $section.";
} }
@ -224,10 +224,10 @@ sub regchange {
my $ret = eval { my $ret = eval {
use re::engine::RE2 -strict => 1; use re::engine::RE2 -strict => 1;
if(not $registry->{$section}->{$item}->{value} =~ s|$tochange|$changeto|) { if(not $registry->{$section}->{$item}->{value} =~ s|$tochange|$changeto|) {
$self->{pbot}->logger->log("($from) $nick!$user\@$host: failed to change [$section] $item 's$delim$tochange$delim$changeto$delim$modifier\n"); $self->{pbot}->{logger}->log("($from) $nick!$user\@$host: failed to change [$section] $item 's$delim$tochange$delim$changeto$delim$modifier\n");
return "/msg $nick Change [$section] $item failed."; return "/msg $nick Change [$section] $item failed.";
} else { } else {
$self->{pbot}->logger->log("($from) $nick!$user\@$host: changed [$section] $item 's/$tochange/$changeto/\n"); $self->{pbot}->{logger}->log("($from) $nick!$user\@$host: changed [$section] $item 's/$tochange/$changeto/\n");
$self->{pbot}->{registry}->process_trigger($section, $item, 'value', $registry->{$section}->{$item}->{value}); $self->{pbot}->{registry}->process_trigger($section, $item, 'value', $registry->{$section}->{$item}->{value});
$self->{pbot}->{registry}->save; $self->{pbot}->{registry}->save;
return "Changed: [$section] $item set to $registry->{$section}->{$item}->{value}"; return "Changed: [$section] $item set to $registry->{$section}->{$item}->{value}";

View File

@ -45,7 +45,7 @@ sub do_select {
my $ret = sysread($fh, my $buf, 8192); my $ret = sysread($fh, my $buf, 8192);
if(not defined $ret) { if(not defined $ret) {
$self->{pbot}->logger->log("Error with $fh: $!\n"); $self->{pbot}->{logger}->log("Error with $fh: $!\n");
$self->remove_reader($fh); $self->remove_reader($fh);
next; next;
} }
@ -58,7 +58,7 @@ sub do_select {
chomp $buf; chomp $buf;
if(not exists $self->{readers}->{$fh}) { if(not exists $self->{readers}->{$fh}) {
$self->{pbot}->logger->log("Error: no reader for $fh\n"); $self->{pbot}->{logger}->log("Error: no reader for $fh\n");
} else { } else {
$self->{readers}->{$fh}->($buf); $self->{readers}->{$fh}->($buf);
} }

View File

@ -36,8 +36,8 @@ sub stdin_reader {
$self->{foreground} = (tcgetpgrp($self->{tty_fd}) == getpgrp()) ? 1 : 0; $self->{foreground} = (tcgetpgrp($self->{tty_fd}) == getpgrp()) ? 1 : 0;
return if not $self->{foreground}; return if not $self->{foreground};
$self->{pbot}->logger->log("---------------------------------------------\n"); $self->{pbot}->{logger}->log("---------------------------------------------\n");
$self->{pbot}->logger->log("Read '$input' from STDIN\n"); $self->{pbot}->{logger}->log("Read '$input' from STDIN\n");
my ($from, $text); my ($from, $text);
@ -49,7 +49,7 @@ sub stdin_reader {
$text = $self->{pbot}->{registry}->get_value('general', 'trigger') . $input; $text = $self->{pbot}->{registry}->get_value('general', 'trigger') . $input;
} }
return $self->{pbot}->interpreter->process_line($from, $self->{pbot}->{registry}->get_value('irc', 'botnick'), "stdin", "localhost", $text); return $self->{pbot}->{interpreter}->process_line($from, $self->{pbot}->{registry}->get_value('irc', 'botnick'), "stdin", "localhost", $text);
} }
1; 1;

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 584, BUILD_REVISION => 585,
BUILD_DATE => "2014-05-17", BUILD_DATE => "2014-05-18",
}; };
1; 1;

View File

@ -77,9 +77,6 @@ my %config = (
# You shouldn't need to change anything below this line. # You shouldn't need to change anything below this line.
# ----------------------------------------------------- # -----------------------------------------------------
# Maximum messages to remember per nick/hostmask in message history
MAX_MESSAGES => 256,
# Path to data directory # Path to data directory
data_dir => "$bothome/data", data_dir => "$bothome/data",