Mercurial > hg > skillbot
comparison skillbot.pl @ 15:2ab5ccc01036
Adding a check in shortly before an announcement to double-check the current skill
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Sat, 06 Dec 2008 16:46:10 +0000 |
parents | 5e35c408cc3c |
children | e238f28f774a |
comparison
equal
deleted
inserted
replaced
14:5e35c408cc3c | 15:2ab5ccc01036 |
---|---|
392 =cut | 392 =cut |
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 check_friend($self, $_) foreach (@friends); |
398 my $skill = $f->{char}->skill->in_training; | 398 } |
399 | 399 |
400 # Nothing training | 400 sub check_friend |
401 unless (defined $skill) | 401 { |
402 { | 402 my $self = shift; |
403 # If the char was training before and now has stopped then cancel | 403 my $f = shift; |
404 # the announcement | 404 |
405 del_one_shot_timer($f->{timer}) if defined $f->{timer}; | 405 my $skill = $f->{char}->skill->in_training; |
406 next; | 406 |
407 } | 407 # Nothing training |
408 | 408 unless (defined $skill) |
409 # Check for changes in the skill, skip or cancel announcement | 409 { |
410 if (defined $f->{skill}) { | 410 # If the char was training before and now has stopped then cancel |
411 next if $skill->id == $f->{skill}->id; | 411 # the announcement |
412 del_one_shot_timer($f->{timer}); | 412 del_one_shot_timer($f->{timer}) if defined $f->{timer}; |
413 } | 413 next; |
414 | 414 } |
415 irc_debug("Character %s is training %s %lu (%s == %lu sec)", | 415 |
416 $f->{char}->name, $skill->name, $skill->level, | 416 # Check for changes in the skill, skip or cancel announcement |
417 $skill->time_remaining, ($skill->finish_time - time())); | 417 if (defined $f->{skill}) { |
418 | 418 next if $skill->id == $f->{skill}->id; |
419 $f->{skill} = $skill; | 419 del_one_shot_timer($f->{timer}); |
420 | 420 } |
421 my $text = sprintf("%s has completed training skill %s %s", | 421 |
422 $f->{char}->name, $skill->name, $skill->level); | 422 irc_debug("Character %s is training %s %lu (%s == %lu sec)", |
423 | 423 $f->{char}->name, $skill->name, $skill->level, |
424 if ($text =~ /[\n\r]/) { | 424 $skill->time_remaining, ($skill->finish_time - time())); |
425 $text =~ s/[\n\r]/ /g; | 425 |
426 } | 426 $f->{skill} = $skill; |
427 | 427 |
428 $f->{timer} = add_one_shot_timer($skill->finish_time - time(), sub { | 428 my $text = sprintf("%s has completed training skill %s %s", |
429 $self->privmsg('#' . $config{channel}, sprintf( | 429 $f->{char}->name, $skill->name, $skill->level); |
430 chr(2) . "%s:" . chr(15) . " %s", | 430 |
431 $f->{nick}, encode("utf8", $text))); | 431 if ($text =~ /[\n\r]/) { |
432 delete $f->{skill}; | 432 $text =~ s/[\n\r]/ /g; |
433 } | |
434 | |
435 my $finish = $skill->finish_time - time(); | |
436 my $prefinish = $finish - 60; | |
437 | |
438 # Add a timer shortly before the end to ensure the user's still training | |
439 if ($prefinish > 0) | |
440 { | |
441 $f->{timer} = add_one_shot_timer($prefinish, sub { | |
442 check_friend($self, $f); | |
433 }); | 443 }); |
434 } | 444 } |
445 | |
446 $f->{timer} = add_one_shot_timer($skill->finish_time - time(), sub { | |
447 $self->privmsg('#' . $config{channel}, sprintf( | |
448 chr(2) . "%s:" . chr(15) . " %s", | |
449 $f->{nick}, encode("utf8", $text))); | |
450 delete $f->{skill}; | |
451 }); | |
435 } | 452 } |
436 | 453 |
437 END { | 454 END { |
438 cleanup_and_die(); | 455 cleanup_and_die(); |
439 } | 456 } |