changeset 42:bf685f1a545f

Adding detection of downtime windows
author Dominic Cleal <dominic@computerkb.co.uk>
date Thu, 11 Dec 2008 00:04:38 +0000
parents 2f9832b6dede
children edb68779265b
files skillbot.pl
diffstat 1 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/skillbot.pl	Wed Dec 10 22:35:48 2008 +0000
+++ b/skillbot.pl	Thu Dec 11 00:04:38 2008 +0000
@@ -231,11 +231,19 @@
 		for my $f (@friends) {
 			if ((defined $2 && lc($f->{char}->name) eq lc($2))
 					|| (!defined $2 && $f->{nick} eq $their_nick)) {
-				my $text = (defined $f->{skill}
-						? sprintf("Currently training %s %s (finish in %s)",
+				my $text;
+				if (defined $f->{skill}) {
+					my $downtime = undef;
+					if (skill_finish_in_downtime($f->{skill})) {
+						$downtime = ", coincides with downtime";
+					}
+
+					$text = sprintf("Currently training %s %s (finish in %s%s)",
 								  $f->{skill}->name, $f->{skill}->level,
-								  $f->{skill}->time_remaining)
-						: "No skill currently training");
+								  $f->{skill}->time_remaining, $downtime)
+				} else {
+					$text = "No skill currently training";
+				}
 
 				$self->privmsg('#' . $config{channel}, sprintf(
 							   "\002%s:\002 %s", $f->{char}->name,
@@ -494,6 +502,16 @@
 
 	$f->{skill} = $skill;
 
+	# Check if the finish time is within scheduled EVE downtime
+	if (skill_finish_in_downtime($f->{skill}))
+	{
+		$self->privmsg('#' . $config{channel}, sprintf(
+					   "\002%s:\002 Training completion time of %s %lu will " .
+					   "coincide with scheduled downtime at %s",
+					   $f->{nick}, $f->{skill}->name, $f->{skill}->level,
+					   scalar(gmtime($f->{skill}->finish_time))));
+	}
+
 	my $text = sprintf("%s has completed training skill %s %s",
 					   $f->{char}->name, $skill->name, $skill->level);
 	
@@ -517,6 +535,20 @@
 	});
 }
 
+=pod
+
+Indicate whether the passed skill object is due to finish during a normal,
+scheduled downtime window.
+
+=cut
+sub skill_finish_in_downtime
+{
+	my $skill = shift;
+
+	# Check if the finish time is within 11:00-11:59 (EVE downtime)
+	return ([gmtime($skill->finish_time)]->[2] == 11);
+}
+
 END {
 	cleanup_and_die();
 }