3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-04 10:28:45 +02:00

Properly update version factoid on refresh

This commit is contained in:
Pragmatic Software 2018-01-22 23:48:25 -08:00
parent b7ec6b68dd
commit f8960d79b5
4 changed files with 33 additions and 23 deletions

View File

@ -26,7 +26,7 @@ use JSON;
use PPI;
use Safe;
use PBot::PBot qw($VERSION);
use PBot::VERSION qw/version/;
use PBot::FactoidCommands;
use PBot::FactoidModuleLauncher;
use PBot::DualIndexHashObject;
@ -82,6 +82,7 @@ sub load_factoids {
foreach my $channel (keys %{ $self->{factoids}->hash }) {
foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) {
$self->{pbot}->{logger}->log("Missing type for $channel->$trigger\n") if not $self->{factoids}->hash->{$channel}->{$trigger}->{type};
$text++ if $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'text';
$regex++ if $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'regex';
$modules++ if $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'module';
@ -96,7 +97,8 @@ sub load_factoids {
sub add_default_factoids {
my $self = shift;
$self->add_factoid('text', '.*', $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'version', "/say $VERSION", 1);
my $version = version();
$self->add_factoid('text', '.*', $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'version', "/say $version", 1);
}
sub save_factoids {

View File

@ -14,22 +14,12 @@ package PBot::PBot;
use strict;
use warnings;
use PBot::VERSION;
BEGIN {
use Exporter;
our @ISA = 'Exporter';
our @EXPORT = qw($VERSION);
our $VERSION = PBot::VERSION::BUILD_NAME . " revision " . PBot::VERSION::BUILD_REVISION . " " . PBot::VERSION::BUILD_DATE;
print "$VERSION\n";
}
# unbuffer stdout
STDOUT->autoflush(1);
use Carp ();
use PBot::Logger;
use PBot::VERSION;
use PBot::Registry;
use PBot::SelectHandler;
use PBot::StdinReader;
@ -72,6 +62,9 @@ sub initialize {
# logger created first to allow other modules to log things
$self->{logger} = PBot::Logger->new(log_file => $conf{log_file}, %conf);
$self->{version} = PBot::VERSION->new(pbot => $self, %conf);
$self->{logger}->log($self->{version}->version . "\n");
$self->{atexit} = PBot::Registerable->new(%conf);
$self->{timer} = PBot::Timer->new(timeout => 10, %conf);
$self->{commands} = PBot::Commands->new(pbot => $self, %conf);

View File

@ -49,13 +49,9 @@ sub refresh {
return "Refreshed all modified modules.\n";
} else {
$self->{pbot}->{logger}->log("Refreshing module $arguments\n");
if ($self->{refresher}->refresh_module_if_modified($arguments)) {
$self->{pbot}->{logger}->log("Refreshed module.\n");
return "Refreshed module.\n";
} else {
$self->{pbot}->{logger}->log("Module had no changes; not refreshed.\n");
return "Module had no changes; not refreshed.\n";
}
$self->{refresher}->refresh_module($arguments);
$self->{pbot}->{logger}->log("Refreshed module.\n");
return "Refreshed module.\n";
}
};
@ -65,9 +61,11 @@ sub refresh {
}
# update version factoid
use PBot::VERSION;
my $version = PBot::VERSION::BUILD_NAME . " revision " . PBot::VERSION::BUILD_REVISION . " " . PBot::VERSION::BUILD_DATE;
$self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{'version'}->{'action'} = "/say $version";
my $version = $self->{pbot}->{version}->version();
if ($self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{'version'}->{'action'} ne "/say $version") {
$self->{pbot}->{factoids}->{factoids}->hash->{'.*'}->{'version'}->{'action'} = "/say $version";
$self->{pbot}->{logger}->log("New version: $version\n");
}
return $result;
}

View File

@ -14,6 +14,12 @@ package PBot::VERSION;
use strict;
use warnings;
BEGIN {
use Exporter;
our @ISA = 'Exporter';
our @EXPORT_OK = qw(version);
}
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
@ -21,4 +27,15 @@ use constant {
BUILD_DATE => "2018-01-22",
};
sub new {
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
return $self;
}
sub version {
return BUILD_NAME . " revision " . BUILD_REVISION . " " . BUILD_DATE;
}
1;