changeset 14:5e35c408cc3c

Handles cases where the skills change and aren't seen to completion
author Dominic Cleal <dominic@computerkb.co.uk>
date Sat, 06 Dec 2008 16:30:55 +0000
parents d9a9bcd44c2e
children 2ab5ccc01036
files skillbot.pl
diffstat 1 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/skillbot.pl	Sat Dec 06 16:02:59 2008 +0000
+++ b/skillbot.pl	Sat Dec 06 16:30:55 2008 +0000
@@ -136,8 +136,8 @@
 	# API sessions for them all
 	add_repeat_timer(360, sub { my ($timer, $self) = @_; update_friends($self); });
 
-	# Check for new skills every 30 minutes.
-	add_repeat_timer(1800, sub { my ($timer, $self) = @_; check_training($self); });
+	# Check for new skills every 60 minutes.
+	add_repeat_timer(3600, sub { my ($timer, $self) = @_; check_training($self); });
 }
 
 sub nickserv_id_now
@@ -395,12 +395,22 @@
 	my $self = shift;
 
 	foreach my $f (@friends) {
-		# Skip skills training that we've learnt about
-		next if defined $f->{skill};
+		my $skill = $f->{char}->skill->in_training;
+		
+		# Nothing training
+		unless (defined $skill)
+		{
+			# If the char was training before and now has stopped then cancel
+			# the announcement
+			del_one_shot_timer($f->{timer}) if defined $f->{timer};
+			next;
+		}
 
-		my $skill = $f->{char}->skill->in_training;
-		# Nothing training
-		next unless $skill;
+		# Check for changes in the skill, skip or cancel announcement
+		if (defined $f->{skill}) {
+			next if $skill->id == $f->{skill}->id;
+			del_one_shot_timer($f->{timer});
+		}
 
 		irc_debug("Character %s is training %s %lu (%s == %lu sec)",
 				  $f->{char}->name, $skill->name, $skill->level,
@@ -415,7 +425,7 @@
 			$text =~ s/[\n\r]/ /g;
 		}
 
-		add_one_shot_timer($skill->finish_time - time(), sub {
+		$f->{timer} = add_one_shot_timer($skill->finish_time - time(), sub {
 			$self->privmsg('#' . $config{channel}, sprintf(
 					chr(2) . "%s:" . chr(15) . " %s",
 					$f->{nick}, encode("utf8", $text)));