3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-25 12:12:34 +01:00

Plugins/Wttr: now shows forecast/condition changes only for times > $now

This commit is contained in:
Pragmatic Software 2020-02-18 15:06:07 -08:00
parent ec99b205e8
commit b924443f80

View File

@ -53,6 +53,7 @@ sub wttrcmd {
"sunhours", "sunhours",
"snowfall", "snowfall",
"location", "location",
"time",
"default", "default",
"all", "all",
); );
@ -132,6 +133,14 @@ sub get_wttr {
my $w = $wttr->{'weather'}->[0]; my $w = $wttr->{'weather'}->[0];
my $h = $w->{'hourly'}->[0]; my $h = $w->{'hourly'}->[0];
my ($obsdate, $obstime) = split / /, $c->{'localObsDateTime'}, 2;
my ($obshour, $obsminute) = split /:/, $obstime;
if ($obsminute =~ s/ PM$//) {
$obshour += 12;
} else {
$obsminute =~ s/ AM$//;
}
foreach my $option (sort keys %options) { foreach my $option (sort keys %options) {
given ($option) { given ($option) {
when ('default') { when ('default') {
@ -149,13 +158,16 @@ sub get_wttr {
$time =~ s/(\d{2})$/:$1/; $time =~ s/(\d{2})$/:$1/;
if ($condition ne $last_condition) { if ($condition ne $last_condition) {
my ($hour, $minute) = split /:/, $time;
if (($hour > $obshour) or ($hour == $obshour and $minute >= $obsminute)) {
$result .= "$sep$time: $condition ($temp)"; $result .= "$sep$time: $condition ($temp)";
$sep = '-> '; $sep = '-> ';
$last_condition = $condition; $last_condition = $condition;
} }
} }
}
if ($sep eq '') { $result .= $last_condition; } if ($sep eq '') { $result .= "none"; }
$result .= "; "; $result .= "; ";
} }
@ -181,17 +193,20 @@ sub get_wttr {
if ($condition ne $last_condition) { if ($condition ne $last_condition) {
$text .= ' ' if length $text; $text .= ' ' if length $text;
$text .= $condition; $text .= "($condition)";
$last_condition = $condition; $last_condition = $condition;
} }
if (length $text) { if (length $text) {
my $time = sprintf "%04d", $hour->{'time'}; my $time = sprintf "%04d", $hour->{'time'};
$time =~ s/(\d{2})$/:$1/; $time =~ s/(\d{2})$/:$1/;
my ($hour, $minute) = split /:/, $time;
if (($hour > $obshour) or ($hour == $obshour and $minute >= $obsminute)) {
$result .= "$sep $time: $text"; $result .= "$sep $time: $text";
$sep = ', '; $sep = ', ';
} }
} }
}
$result .= "; "; $result .= "; ";
} }
@ -246,6 +261,8 @@ sub get_wttr {
when ('cloudcover') { $result .= "Cloud cover: $c->{'cloudcover'}%; "; } when ('cloudcover') { $result .= "Cloud cover: $c->{'cloudcover'}%; "; }
when ('time') { $result .= "Observation Time: $c->{'localObsDateTime'}; "; }
default { $result .= "Option $_ coming soon; " unless lc $_ eq 'u'; } default { $result .= "Option $_ coming soon; " unless lc $_ eq 'u'; }
} }
} }