3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-19 10:29:30 +01:00
pbot/updates/3503_add_version_info.pl

69 lines
1.9 KiB
Perl
Raw Normal View History

2020-04-22 04:44:14 +02:00
#!/usr/bin/env perl
2020-04-23 02:01:28 +02:00
# Adds version metadata to HashObject and DualIndexHashObject JSON files.
2020-04-22 04:44:14 +02:00
use warnings; use strict;
BEGIN {
use File::Basename;
my $location = -l __FILE__ ? dirname readlink __FILE__ : dirname __FILE__;
unshift @INC, $location;
}
use lib3503::HashObject;
use lib3503::DualIndexHashObject;
use lib3503::PBot;
my ($data_dir, $version, $last_update) = @ARGV;
print "Adding version info... version: $version, last_update: $last_update, data_dir: $data_dir\n";
my @hashobjects = qw/channels commands capabilities/;
2020-04-22 04:50:14 +02:00
my @dualindex = qw/unban_timeouts unmute_timeouts ban-exemptions ignorelist registry spam_keywords users/;
2020-04-22 04:44:14 +02:00
my $pbot = lib3503::PBot->new();
foreach my $hashobject (@hashobjects) {
print "Updating $data_dir/$hashobject ...\n";
my $obj = lib3503::HashObject->new(name => $hashobject, filename => "$data_dir/$hashobject", pbot => $pbot);
$obj->load;
my $ver = $obj->get_data('$metadata$', 'update_version');
if (defined $ver) {
print "$hashobject last update version $ver; ";
if ($ver >= 3503) {
print "no update needed\n";
next;
} else {
print "updating...\n";
}
}
print "Adding version info\n";
$obj->add('$metadata$', { update_version => 3503 });
}
foreach my $hashobject (@dualindex) {
print "Updating $data_dir/$hashobject ...\n";
my $obj = lib3503::DualIndexHashObject->new(name => $hashobject, filename => "$data_dir/$hashobject", pbot => $pbot);
$obj->load;
my $ver = $obj->get_data('$metadata$', '$metadata$', 'update_version');
if (defined $ver) {
print "$hashobject last update version $ver; ";
if ($ver >= 3503) {
print "no update needed\n";
next;
} else {
print "updating...\n";
}
}
print "Adding version info\n";
$obj->add('$metadata$', '$metadata$', { update_version => 3503 });
}
exit 0;