3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 05:49:27 +01:00

Use Storable to save/load message history hash

Reuse config_dir/data_dir variable in pbot.pl
This commit is contained in:
Pragmatic Software 2014-02-05 01:10:56 +00:00
parent 0f2616a552
commit 5a61f57f3c
5 changed files with 105 additions and 76 deletions

View File

@ -15,6 +15,8 @@ use strict;
use feature 'switch';
use Storable;
use vars qw($VERSION);
$VERSION = $PBot::PBot::VERSION;
@ -50,7 +52,7 @@ sub initialize {
$self->{FLOOD_CHAT} = 0;
$self->{FLOOD_JOIN} = 1;
$self->{message_history} = {};
$self->load_message_history;
my $filename = delete $conf{filename} // $self->{pbot}->{data_dir} . '/ban_whitelist';
$self->{ban_whitelist} = PBot::DualIndexHashObject->new(name => 'BanWhitelist', filename => $filename);
@ -60,6 +62,7 @@ sub initialize {
$pbot->commands->register(sub { return $self->unbanme(@_) }, "unbanme", 0);
$pbot->commands->register(sub { return $self->whitelist(@_) }, "whitelist", 10);
$pbot->commands->register(sub { return $self->save_message_history_cmd(@_) }, "save_message_history", 60);
}
sub ban_whitelisted {
@ -687,4 +690,25 @@ sub on_whoisaccount {
$self->check_nickserv_accounts($nick, $account);
}
sub save_message_history {
my $self = shift;
store($self->{message_history}, $self->{pbot}->{message_history_file});
}
sub load_message_history {
my $self = shift;
if(-e $self->{pbot}->{message_history_file}) {
$self->{message_history} = retrieve($self->{pbot}->{message_history_file});
} else {
$self->{message_history} = {};
}
}
sub save_message_history_cmd {
my ($self, $from, $nick, $user, $host, $arguments) = @_;
$self->save_message_history;
return "Message history saved.";
}
1;

View File

@ -157,8 +157,9 @@ sub ack_die {
my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_;
$self->{pbot}->logger->log("$nick!$user\@$host made me exit.\n");
$self->{pbot}->factoids->save_factoids();
$self->{pbot}->ignorelist->save_ignores();
$self->{pbot}->factoids->save_factoids;
$self->{pbot}->ignorelist->save_ignores;
$self->{pbot}->antiflood->save_message_history;
$self->{pbot}->conn->privmsg($from, "Good-bye.") if defined $from;
$self->{pbot}->conn->quit("Departure requested.");
exit 0;

View File

@ -69,7 +69,7 @@ sub initialize {
my $log_file = delete $conf{log_file};
$self->{conf_dir} = delete $conf{conf_dir} // "$ENV{HOME}/pbot/config";
$self->{config_dir} = delete $conf{config_dir} // "$ENV{HOME}/pbot/config";
$self->{data_dir} = delete $conf{data_dir} // "$ENV{HOME}/pbot/data";
$self->{module_dir} = delete $conf{module_dir} // "$ENV{HOME}/pbot/modules";
@ -83,9 +83,10 @@ sub initialize {
$self->{ircname} = delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/";
$self->{identify_password} = delete $conf{identify_password} // "";
$self->{max_msg_len} = delete $conf{max_msg_len} // 430;
$self->{max_msg_len} = delete $conf{max_msg_len} // 425;
$self->{MAX_FLOOD_MESSAGES} = delete $conf{MAX_FLOOD_MESSAGES} // 4;
$self->{MAX_NICK_MESSAGES} = delete $conf{MAX_NICK_MESSAGES} // 32;
$self->{message_history_file} = delete $conf{message_history_file} // "$ENV{HOME}/pbot/data/message_history";
$self->{trigger} = delete $conf{trigger} // '!';

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 477,
BUILD_DATE => "2013-12-23",
BUILD_REVISION => 478,
BUILD_DATE => "2014-02-04",
};
1;

17
pbot.pl
View File

@ -84,7 +84,7 @@ my %config = (
data_dir => "$bothome/data",
# Path to config directory
conf_dir => "$bothome/config",
config_dir => "$bothome/config",
# Path to directory containing external script-like modules
module_dir => "$bothome/modules",
@ -92,22 +92,25 @@ my %config = (
# Location of file where bot log information will be output (in addition to stdout)
# (if you use pbot.sh and you change log_file, be sure to also change the log path in pbot.sh)
log_file => "$bothome/log/log",
);
# Location of file containing bot admin information
admins_file => "$bothome/config/admins",
$config{admins_file} = "$config{config_dir}/admins";
# Location of file containing channel information
channels_file => "$bothome/config/channels",
$config{channels_file} = "$config{config_dir}/channels";
# Location of file containing ignorelist entries
ignorelist_file => "$bothome/config/ignorelist",
$config{ignorelist_file} = "$config{config_dir}/ignorelist";
# Location of file containing factoids and modules
factoids_file => "$bothome/data/factoids",
$config{factoids_file} = "$config{data_dir}/factoids";
# Location of file containing channel user quotes
quotegrabs_file => "$bothome/data/quotegrabs",
);
$config{quotegrabs_file} = "$config{data_dir}/quotegrabs";
# Location of file containing message history
$config{message_history_file} = "$config{data_dir}/message_history";
# Create and initialize bot object
my $pbot = PBot::PBot->new(%config);