mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-23 04:19:27 +01:00
Plugins/Wttr.pm: show nearest_area only when -location is requested
This commit is contained in:
parent
f6c870539d
commit
6bc9e9cf88
@ -142,21 +142,9 @@ sub get_wttr {
|
||||
return $error;
|
||||
}
|
||||
|
||||
if (exists $wttr->{nearest_area}) {
|
||||
my $areaName = $wttr->{nearest_area}->[0]->{areaName}->[0]->{value};
|
||||
my $region = $wttr->{nearest_area}->[0]->{region}->[0]->{value};
|
||||
my $country = $wttr->{nearest_area}->[0]->{country}->[0]->{value};
|
||||
|
||||
$location = '';
|
||||
$location .= "$areaName, " if length $areaName;
|
||||
$location .= "$region, " if length $region and $region ne $areaName;
|
||||
$location .= "$country, " if length $country;
|
||||
$location =~ s/, $//;
|
||||
} else {
|
||||
# title-case location
|
||||
$location = ucfirst lc $location;
|
||||
$location =~ s/( |\.)(\w)/$1 . uc $2/ge;
|
||||
}
|
||||
# title-case location
|
||||
$location = ucfirst lc $location;
|
||||
$location =~ s/( |\.)(\w)/$1 . uc $2/ge;
|
||||
|
||||
$location =~ s/United States of America/USA/;
|
||||
|
||||
@ -321,7 +309,21 @@ sub get_wttr {
|
||||
when ('time') { $result .= "Observation time: $c->{'localObsDateTime'}; "; }
|
||||
|
||||
when ('location') {
|
||||
$result .= "Observation location: $location";
|
||||
if (exists $wttr->{nearest_area}) {
|
||||
my $areaName = $wttr->{nearest_area}->[0]->{areaName}->[0]->{value};
|
||||
my $region = $wttr->{nearest_area}->[0]->{region}->[0]->{value};
|
||||
my $country = $wttr->{nearest_area}->[0]->{country}->[0]->{value};
|
||||
|
||||
my $location = '';
|
||||
$location .= "$areaName, " if length $areaName;
|
||||
$location .= "$region, " if length $region and $region ne $areaName;
|
||||
$location .= "$country, " if length $country;
|
||||
$location =~ s/, $//;
|
||||
|
||||
$result .= "Observation location: $location";
|
||||
} else {
|
||||
$result .= "Query location: $location";
|
||||
}
|
||||
}
|
||||
|
||||
when ('population') {
|
||||
|
Loading…
Reference in New Issue
Block a user