changeset 7:6b73a2781c15

Skill completion notifications done
author Dominic Cleal <dominic@computerkb.co.uk>
date Sat, 06 Dec 2008 15:09:54 +0000
parents f0f55a4999b7
children cb6e21f2d514
files skillbot.pl
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/skillbot.pl	Sat Dec 06 15:09:42 2008 +0000
+++ b/skillbot.pl	Sat Dec 06 15:09:54 2008 +0000
@@ -342,6 +342,7 @@
 	open(FF, "< $config{friends_file}") or die "Couldn't open friends_file: $!";
 
 	while (<FF>) {
+		chomp;
 		next if (/^#/);
 
 		if (/^([^\t]+)\t+([0-9]+)\t+([A-F0-9]{64})\t+([^\t]+)/i) {
@@ -369,7 +370,7 @@
 						
 				$friends{$c}->{api} = $api;
 
-				irc_debug("EVE: Adding new friend '%s' =~ %s", $c, $nick);
+				irc_debug("EVE: Adding new friend '%s', nick %s", $c, $nick);
 			}
 
 			$friends{$c}->{nick} = $nick;
@@ -401,13 +402,21 @@
 				  $friends{$f}->{char}->name, $skill->name,
 				  $skill->time_remaining);
 
-		my $text = $skill->name;
+		$friends{$f}->{skill} = $skill;
+
+		my $text = sprintf("%s has completed training skill %s %s",
+						   $friends{$f}->{char}->name,
+						   $skill->name, $skill->level);
+		
 		if ($text =~ /[\n\r]/) {
 			$text =~ s/[\n\r]/ /g;
 		}
 
-		$self->notice('#' . $config{channel}, sprintf("[%s] %s", $friends{$f}->{nick},
-				encode("utf8", $text)));
+		irc_debug("In %lu seconds, announcing: %s", $skill->finish_time - time(), $text);
+		add_one_shot_timer($skill->finish_time - time(), sub {
+			$self->notice('#' . $config{channel}, sprintf("[%s] %s",
+					$friends{$f}->{nick}, encode("utf8", $text)));
+		});
 	}
 }