Mercurial > hg > skillbot
comparison skillbot.pl @ 42:bf685f1a545f
Adding detection of downtime windows
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Thu, 11 Dec 2008 00:04:38 +0000 |
parents | 19cc55690fd7 |
children | edb68779265b |
comparison
equal
deleted
inserted
replaced
41:2f9832b6dede | 42:bf685f1a545f |
---|---|
229 if ($msg =~ /^\!eta(\s+(.+))?/i) { | 229 if ($msg =~ /^\!eta(\s+(.+))?/i) { |
230 my $found = 0; | 230 my $found = 0; |
231 for my $f (@friends) { | 231 for my $f (@friends) { |
232 if ((defined $2 && lc($f->{char}->name) eq lc($2)) | 232 if ((defined $2 && lc($f->{char}->name) eq lc($2)) |
233 || (!defined $2 && $f->{nick} eq $their_nick)) { | 233 || (!defined $2 && $f->{nick} eq $their_nick)) { |
234 my $text = (defined $f->{skill} | 234 my $text; |
235 ? sprintf("Currently training %s %s (finish in %s)", | 235 if (defined $f->{skill}) { |
236 my $downtime = undef; | |
237 if (skill_finish_in_downtime($f->{skill})) { | |
238 $downtime = ", coincides with downtime"; | |
239 } | |
240 | |
241 $text = sprintf("Currently training %s %s (finish in %s%s)", | |
236 $f->{skill}->name, $f->{skill}->level, | 242 $f->{skill}->name, $f->{skill}->level, |
237 $f->{skill}->time_remaining) | 243 $f->{skill}->time_remaining, $downtime) |
238 : "No skill currently training"); | 244 } else { |
245 $text = "No skill currently training"; | |
246 } | |
239 | 247 |
240 $self->privmsg('#' . $config{channel}, sprintf( | 248 $self->privmsg('#' . $config{channel}, sprintf( |
241 "\002%s:\002 %s", $f->{char}->name, | 249 "\002%s:\002 %s", $f->{char}->name, |
242 encode("utf8", $text))); | 250 encode("utf8", $text))); |
243 $found++; | 251 $found++; |
492 return; | 500 return; |
493 } | 501 } |
494 | 502 |
495 $f->{skill} = $skill; | 503 $f->{skill} = $skill; |
496 | 504 |
505 # Check if the finish time is within scheduled EVE downtime | |
506 if (skill_finish_in_downtime($f->{skill})) | |
507 { | |
508 $self->privmsg('#' . $config{channel}, sprintf( | |
509 "\002%s:\002 Training completion time of %s %lu will " . | |
510 "coincide with scheduled downtime at %s", | |
511 $f->{nick}, $f->{skill}->name, $f->{skill}->level, | |
512 scalar(gmtime($f->{skill}->finish_time)))); | |
513 } | |
514 | |
497 my $text = sprintf("%s has completed training skill %s %s", | 515 my $text = sprintf("%s has completed training skill %s %s", |
498 $f->{char}->name, $skill->name, $skill->level); | 516 $f->{char}->name, $skill->name, $skill->level); |
499 | 517 |
500 if ($text =~ /[\n\r]/) { | 518 if ($text =~ /[\n\r]/) { |
501 $text =~ s/[\n\r]/ /g; | 519 $text =~ s/[\n\r]/ /g; |
515 encode("utf8", $text))); | 533 encode("utf8", $text))); |
516 delete $f->{skill}; | 534 delete $f->{skill}; |
517 }); | 535 }); |
518 } | 536 } |
519 | 537 |
538 =pod | |
539 | |
540 Indicate whether the passed skill object is due to finish during a normal, | |
541 scheduled downtime window. | |
542 | |
543 =cut | |
544 sub skill_finish_in_downtime | |
545 { | |
546 my $skill = shift; | |
547 | |
548 # Check if the finish time is within 11:00-11:59 (EVE downtime) | |
549 return ([gmtime($skill->finish_time)]->[2] == 11); | |
550 } | |
551 | |
520 END { | 552 END { |
521 cleanup_and_die(); | 553 cleanup_and_die(); |
522 } | 554 } |