mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-16 21:40:46 +01:00
Plugin/Wttr: output options in consistent order
This commit is contained in:
parent
a27a36a05e
commit
12cedcd60e
@ -41,9 +41,9 @@ sub cmd_wttr {
|
|||||||
"cloudcover",
|
"cloudcover",
|
||||||
"wind",
|
"wind",
|
||||||
"sun",
|
"sun",
|
||||||
|
"sunhours",
|
||||||
"moon",
|
"moon",
|
||||||
"chances",
|
"chances",
|
||||||
"sunhours",
|
|
||||||
"snowfall",
|
"snowfall",
|
||||||
"location",
|
"location",
|
||||||
"qlocation",
|
"qlocation",
|
||||||
@ -100,11 +100,13 @@ sub cmd_wttr {
|
|||||||
delete $options{default};
|
delete $options{default};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $self->get_wttr($arguments, sort keys %options);
|
my @opts = keys %options;
|
||||||
|
|
||||||
|
return $self->get_wttr($arguments, \@opts, \@wttr_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_wttr {
|
sub get_wttr {
|
||||||
my ($self, $location, @options) = @_;
|
my ($self, $location, $options, $order) = @_;
|
||||||
|
|
||||||
my %cache_opt = (
|
my %cache_opt = (
|
||||||
'namespace' => 'wttr',
|
'namespace' => 'wttr',
|
||||||
@ -118,8 +120,11 @@ sub get_wttr {
|
|||||||
|
|
||||||
my $json;
|
my $json;
|
||||||
|
|
||||||
if ($response->is_success) { $json = $response->decoded_content; }
|
if ($response->is_success) {
|
||||||
else { return "Failed to fetch weather data: " . $response->status_line; }
|
$json = $response->decoded_content;
|
||||||
|
} else {
|
||||||
|
return "Failed to fetch weather data: " . $response->status_line;
|
||||||
|
}
|
||||||
|
|
||||||
my $wttr = eval { decode_json $json };
|
my $wttr = eval { decode_json $json };
|
||||||
|
|
||||||
@ -153,11 +158,12 @@ sub get_wttr {
|
|||||||
$obsminute =~ s/ AM$//;
|
$obsminute =~ s/ AM$//;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@options == 1 and $options[0] eq 'default') {
|
if (@$options == 1 and $options->[0] eq 'default') {
|
||||||
push @options, 'chances';
|
push @$options, 'chances';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $option (@options) {
|
foreach my $option (@$order) {
|
||||||
|
next if not grep { $_ eq $option } @$options;
|
||||||
given ($option) {
|
given ($option) {
|
||||||
when ('default') {
|
when ('default') {
|
||||||
$result .= "Currently: $c->{'weatherDesc'}->[0]->{'value'}: $c->{'temp_C'}C/$c->{'temp_F'}F";
|
$result .= "Currently: $c->{'weatherDesc'}->[0]->{'value'}: $c->{'temp_C'}C/$c->{'temp_F'}F";
|
||||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4324,
|
BUILD_REVISION => 4325,
|
||||||
BUILD_DATE => "2021-07-28",
|
BUILD_DATE => "2021-07-28",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user