mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-16 21:40:46 +01:00
VERSION: add built-in version
command
This commit is contained in:
parent
0308806ac0
commit
64cba56698
@ -7,8 +7,6 @@
|
|||||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
# $Id$
|
|
||||||
|
|
||||||
package PBot::VERSION;
|
package PBot::VERSION;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
@ -22,17 +20,22 @@ BEGIN {
|
|||||||
our @EXPORT_OK = qw(version);
|
our @EXPORT_OK = qw(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use LWP::UserAgent;
|
||||||
|
|
||||||
# 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 => 2827,
|
BUILD_REVISION => 2829,
|
||||||
BUILD_DATE => "2020-01-18",
|
BUILD_DATE => "2020-01-19",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %conf) = @_;
|
my ($class, %conf) = @_;
|
||||||
my $self = bless {}, $class;
|
my $self = bless {}, $class;
|
||||||
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
||||||
|
|
||||||
|
$self->{pbot}->{commands}->register(sub { $self->version_cmd(@_) }, "version", 0);
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,4 +43,31 @@ sub version {
|
|||||||
return BUILD_NAME . " version " . BUILD_REVISION . " " . BUILD_DATE;
|
return BUILD_NAME . " version " . BUILD_REVISION . " " . BUILD_DATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub version_cmd {
|
||||||
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
|
if (length $arguments) {
|
||||||
|
if ($arguments eq '-check') {
|
||||||
|
my $url = $self->{pbot}->{registry}->get_value('version', 'check_url') // 'https://raw.githubusercontent.com/pragma-/pbot/master/PBot/VERSION.pm';
|
||||||
|
my $ua = LWP::UserAgent->new(timeout => 10);
|
||||||
|
my $response = $ua->get($url);
|
||||||
|
return "Unable to get version information: " . $response->status_line if (not $response->is_success);
|
||||||
|
my $text = $response->decoded_content;
|
||||||
|
my ($version, $date) = $text =~ m/^\s+BUILD_REVISION => (\d+).*^\s+BUILD_DATE\s+=> "([^"]+)"/ms;
|
||||||
|
|
||||||
|
if ($version != BUILD_REVISION) {
|
||||||
|
return "/say " . $self->version . "; new version available: $version ($date)!";
|
||||||
|
} else {
|
||||||
|
return "/say " . $self->version . "; you have the latest version.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
my $nick = $self->{pbot}->{nicklist}->is_present_similar($arguments);
|
||||||
|
if ($nick) {
|
||||||
|
return "/say $nick: " . $self->version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "/say " . $self->version;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user