From 39ee73f0b8a8b317edcceac42c7af26420acc072 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 27 Jul 2021 22:38:19 -0700 Subject: [PATCH] Fix version not updating after `refresh` --- lib/PBot/Core.pm | 3 ++- lib/PBot/Core/Commands/Version.pm | 16 ++++++++-------- lib/PBot/VERSION.pm | 17 +++++++++++++++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/PBot/Core.pm b/lib/PBot/Core.pm index a7b8a9f1..d42b709e 100644 --- a/lib/PBot/Core.pm +++ b/lib/PBot/Core.pm @@ -135,7 +135,8 @@ sub initialize { $self->{logger} = PBot::Core::Logger->new(pbot => $self, filename => "$conf{data_dir}/log/log", %conf); # log the version - $self->{logger}->log(PBot::VERSION::BUILD_NAME . ' version ' . PBot::VERSION::BUILD_REVISION . ' ' . PBot::VERSION::BUILD_DATE . "\n"); + $self->{version} = PBot::VERSION->new(pbot => $self); + $self->{logger}->log($self->{version}->version . "\n"); # log command-line arguments $self->{logger}->log("Args: @ARGV\n") if @ARGV; diff --git a/lib/PBot/Core/Commands/Version.pm b/lib/PBot/Core/Commands/Version.pm index 55777748..0486863a 100644 --- a/lib/PBot/Core/Commands/Version.pm +++ b/lib/PBot/Core/Commands/Version.pm @@ -19,10 +19,10 @@ sub initialize { # register `version` command $self->{pbot}->{commands}->register(sub { $self->cmd_version(@_) }, 'version'); - # initialize last_check version data + # initialize last_check version data using compile-time constants $self->{last_check} = { timestamp => 0, - version => PBot::VERSION::BUILD_REVISION, + revision => PBot::VERSION::BUILD_REVISION, date => PBot::VERSION::BUILD_DATE, }; } @@ -47,13 +47,13 @@ sub cmd_version { } my $text = $response->decoded_content; - my ($version, $date) = $text =~ m/^\s+BUILD_REVISION => (\d+).*^\s+BUILD_DATE\s+=> "([^"]+)"/ms; + my ($revision, $date) = $text =~ m/^\s+BUILD_REVISION => (\d+).*^\s+BUILD_DATE\s+=> "([^"]+)"/ms; - if (not defined $version or not defined $date) { + if (not defined $revision or not defined $date) { return "Unable to get version information: data did not match expected format"; } - $self->{last_check} = {timestamp => time, version => $version, date => $date}; + $self->{last_check} = { timestamp => time, revision => $revision, date => $date }; } my $target_nick; @@ -63,10 +63,10 @@ sub cmd_version { my $result = '/say '; $result .= "$target_nick: " if $target_nick; - $result .= PBot::VERSION::BUILD_NAME . ' version ' . PBot::VERSION::BUILD_REVISION . ' ' . PBot::VERSION::BUILD_DATE; + $result .= $self->{pbot}->{version}->version; - if ($self->{last_check}->{version} > PBot::VERSION::BUILD_REVISION) { - $result .= "; new version available: $self->{last_check}->{version} $self->{last_check}->{date}!"; + if ($self->{last_check}->{revision} > $self->{pbot}->{version}->revision) { + $result .= "; new version available: $self->{last_check}->{revision} $self->{last_check}->{date}!"; } return $result; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index d311cc10..9e827f1e 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -1,6 +1,6 @@ # File: VERSION.pm # -# Purpose: Keeps track of bot version constants. +# Purpose: Sets the PBot version constants. # # Rather than each PBot::Core package having its own version identifier, all # of PBot is considered a single package. The BUILD_REVSION constant is the @@ -18,12 +18,25 @@ # SPDX-License-Identifier: MIT package PBot::VERSION; +use parent 'PBot::Core::Class'; + +use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4319, + BUILD_REVISION => 4320, BUILD_DATE => "2021-07-27", }; +sub initialize {} + +sub version { + return BUILD_NAME . ' version ' . BUILD_REVISION . ' ' . BUILD_DATE; +} + +sub revision { + return BUILD_REVISION; +} + 1;