Mercurial > hg > skillbot
comparison skillbot.pl @ 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 |
comparison
equal
deleted
inserted
replaced
13:d9a9bcd44c2e | 14:5e35c408cc3c |
---|---|
134 | 134 |
135 # Read the "friends" config file every 6 minutes and make sure we have | 135 # Read the "friends" config file every 6 minutes and make sure we have |
136 # API sessions for them all | 136 # API sessions for them all |
137 add_repeat_timer(360, sub { my ($timer, $self) = @_; update_friends($self); }); | 137 add_repeat_timer(360, sub { my ($timer, $self) = @_; update_friends($self); }); |
138 | 138 |
139 # Check for new skills every 30 minutes. | 139 # Check for new skills every 60 minutes. |
140 add_repeat_timer(1800, sub { my ($timer, $self) = @_; check_training($self); }); | 140 add_repeat_timer(3600, sub { my ($timer, $self) = @_; check_training($self); }); |
141 } | 141 } |
142 | 142 |
143 sub nickserv_id_now | 143 sub nickserv_id_now |
144 { | 144 { |
145 my ($self) = shift; | 145 my ($self) = shift; |
393 sub check_training | 393 sub check_training |
394 { | 394 { |
395 my $self = shift; | 395 my $self = shift; |
396 | 396 |
397 foreach my $f (@friends) { | 397 foreach my $f (@friends) { |
398 # Skip skills training that we've learnt about | |
399 next if defined $f->{skill}; | |
400 | |
401 my $skill = $f->{char}->skill->in_training; | 398 my $skill = $f->{char}->skill->in_training; |
399 | |
402 # Nothing training | 400 # Nothing training |
403 next unless $skill; | 401 unless (defined $skill) |
402 { | |
403 # If the char was training before and now has stopped then cancel | |
404 # the announcement | |
405 del_one_shot_timer($f->{timer}) if defined $f->{timer}; | |
406 next; | |
407 } | |
408 | |
409 # Check for changes in the skill, skip or cancel announcement | |
410 if (defined $f->{skill}) { | |
411 next if $skill->id == $f->{skill}->id; | |
412 del_one_shot_timer($f->{timer}); | |
413 } | |
404 | 414 |
405 irc_debug("Character %s is training %s %lu (%s == %lu sec)", | 415 irc_debug("Character %s is training %s %lu (%s == %lu sec)", |
406 $f->{char}->name, $skill->name, $skill->level, | 416 $f->{char}->name, $skill->name, $skill->level, |
407 $skill->time_remaining, ($skill->finish_time - time())); | 417 $skill->time_remaining, ($skill->finish_time - time())); |
408 | 418 |
413 | 423 |
414 if ($text =~ /[\n\r]/) { | 424 if ($text =~ /[\n\r]/) { |
415 $text =~ s/[\n\r]/ /g; | 425 $text =~ s/[\n\r]/ /g; |
416 } | 426 } |
417 | 427 |
418 add_one_shot_timer($skill->finish_time - time(), sub { | 428 $f->{timer} = add_one_shot_timer($skill->finish_time - time(), sub { |
419 $self->privmsg('#' . $config{channel}, sprintf( | 429 $self->privmsg('#' . $config{channel}, sprintf( |
420 chr(2) . "%s:" . chr(15) . " %s", | 430 chr(2) . "%s:" . chr(15) . " %s", |
421 $f->{nick}, encode("utf8", $text))); | 431 $f->{nick}, encode("utf8", $text))); |
422 delete $f->{skill}; | 432 delete $f->{skill}; |
423 }); | 433 }); |