# HG changeset patch # User Dominic Cleal # Date 1228581055 0 # Node ID 5e35c408cc3cf20fe9a1ca332e69281b768234cd # Parent d9a9bcd44c2e447d59b5d39e91560956c57e6129 Handles cases where the skills change and aren't seen to completion diff -r d9a9bcd44c2e -r 5e35c408cc3c skillbot.pl --- 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)));