Mercurial > hg > skillbot
comparison skillbot.pl @ 70:999787ab415d
Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
- EVEAPI: http://www.xb95.com/svn/eveapi/trunk/
Not yet stable, crashes with hash related error on second command.
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Thu, 11 Feb 2010 00:10:05 +0000 |
parents | 3455a0ab9264 |
children | ee8acca852f4 |
comparison
equal
deleted
inserted
replaced
69:3455a0ab9264 | 70:999787ab415d |
---|---|
18 =cut | 18 =cut |
19 | 19 |
20 use strict; | 20 use strict; |
21 use warnings; | 21 use warnings; |
22 | 22 |
23 use WebService::EveOnline; | 23 use EVEAPI; |
24 use Data::Dumper; | 24 use Data::Dumper; |
25 use Net::IRC; | 25 use Net::IRC; |
26 use POSIX; | 26 use POSIX; |
27 use Encode; | 27 use Encode; |
28 use DateTime; | 28 use DateTime; |
29 use Time::Local | |
29 | 30 |
30 require 'timers.pl'; | 31 require 'timers.pl'; |
31 | 32 |
32 # Config variables | 33 # Config variables |
33 my %config; | 34 my %config; |
34 | 35 |
35 my %frienduids; | 36 my %frienduids; |
36 my @friends; | 37 my @friends; |
38 | |
39 # Load up the full EVE skill tree and then create a hash of skill IDs to names | |
40 my $skill_api = EVEAPI->new(version => 2)->eve->SkillTree->load; | |
41 my %skilltree; | |
42 | |
43 for my $skill_group (@{$skill_api->skillGroups}) { | |
44 $skilltree{$_->typeID} = $_->typeName foreach (@{$skill_group->skills}); | |
45 } | |
46 | |
47 my $skills_loaded = scalar keys %skilltree; | |
48 printf("Init: Loaded a total of %d entries into the skill tree\n", $skills_loaded); | |
37 | 49 |
38 open(CONFIG, "< skillbot.conf") or die "can't open skillbot.conf for reading: $!"; | 50 open(CONFIG, "< skillbot.conf") or die "can't open skillbot.conf for reading: $!"; |
39 while(<CONFIG>) { | 51 while(<CONFIG>) { |
40 chomp; | 52 chomp; |
41 s/#.*//; | 53 s/#.*//; |
434 irc_debug("Invalid timezone (%s) supplied for friend %s". | 446 irc_debug("Invalid timezone (%s) supplied for friend %s". |
435 ", using UTC", $tz, $nick); | 447 ", using UTC", $tz, $nick); |
436 $tz = 'UTC'; | 448 $tz = 'UTC'; |
437 } | 449 } |
438 | 450 |
439 my $api = WebService::EveOnline->new( { user_id => $uid, | 451 my $api = EVEAPI->new( userID => $uid, apiKey => $key, |
440 api_key => $key } ); | 452 version => 2 ); |
441 | 453 |
454 my $api_chars = $api->account->Characters->load; | |
442 my $loaded = 0; | 455 my $loaded = 0; |
443 foreach my $character ($api->characters) { | 456 foreach my $character (@{$api_chars->characters}) { |
444 next if defined $c && $c ne $character->name; | 457 next if defined $c && $c ne $character->name; |
445 push @friends, { | 458 push @friends, { |
446 char_api => $character, | |
447 char => $character->name, | 459 char => $character->name, |
460 char_id => $character->characterID, | |
448 api => $api, | 461 api => $api, |
449 nick => $nick, | 462 nick => $nick, |
450 tz => $tz | 463 tz => $tz, |
451 }; | 464 }; |
452 $loaded++; | 465 $loaded++; |
453 } | 466 } |
454 | 467 |
455 if (defined $c && $loaded eq 0) | 468 if (defined $c && $loaded eq 0) |
488 my $f = shift; | 501 my $f = shift; |
489 | 502 |
490 # Don't attempt updates during downtime, can cause crash | 503 # Don't attempt updates during downtime, can cause crash |
491 # return if (timestamp_in_downtime(time)); | 504 # return if (timestamp_in_downtime(time)); |
492 | 505 |
493 my $char_skill; | 506 my ($skill, $skill_finish); |
494 eval { $char_skill = $f->{char_api}->skill; }; | 507 eval { $skill = $f->{api}->char->SkillInTraining( |
508 characterID => $f->{char_id} ); }; | |
495 warn $@ if $@; | 509 warn $@ if $@; |
496 | 510 |
497 # Sometimes this is undefined if there's an API error, try later | 511 # Sometimes this is undefined if there's an API error, try later |
498 return unless defined $char_skill; | 512 return unless defined $skill; |
499 | 513 |
500 my $skill = $char_skill->in_training; | |
501 | |
502 # Nothing training | 514 # Nothing training |
503 unless (defined $skill) | 515 unless ($skill->skillInTraining eq '1') |
504 { | 516 { |
505 # If the char was training before and now has stopped then cancel | 517 # If the char was training before and now has stopped then cancel |
506 # the announcement | 518 # the announcement |
507 if (defined $f->{timer}) { | 519 if (defined $f->{timer}) { |
508 del_one_shot_timer($f->{timer}); | 520 del_one_shot_timer($f->{timer}); |
509 delete $f->{timer}; | 521 delete $f->{timer}; |
510 } | 522 } |
511 return; | 523 return; |
512 } | 524 } |
513 | 525 |
526 # Convert EVE's completion timestamp to epoch | |
527 unless ($skill->trainingEndTime =~ /^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$/) { | |
528 irc_debug("Unable to parse skill finish time %s", | |
529 $skill->trainingEndTime); | |
530 return; | |
531 } | |
532 $skill_finish = timegm($6, $5, $4, $3, $2 - 1, $1); | |
533 | |
514 # Check for changes in the skill, skip or cancel announcement | 534 # Check for changes in the skill, skip or cancel announcement |
515 if (defined $f->{skill}) { | 535 if (defined $f->{skill}) { |
516 # If the skill's the same, check the finish time and skip if | 536 # If the skill's the same, check the finish time and skip if |
517 # nothing's changed | 537 # nothing's changed |
518 return if ($skill->id eq $f->{skill} | 538 return if ($skill->trainingTypeID eq $f->{skill} |
519 && $f->{skill_finish} == $skill->finish_time); | 539 && $f->{skill_finish} == $skill_finish); |
520 | 540 |
521 # Skill or finish time has changed, delete previous announcement | 541 # Skill or finish time has changed, delete previous announcement |
522 del_one_shot_timer($f->{timer}); | 542 del_one_shot_timer($f->{timer}); |
523 delete $f->{timer}; | 543 delete $f->{timer}; |
524 } | 544 } |
525 | 545 |
526 my $finish = $skill->finish_time - time(); | 546 my $finish = $skill_finish - time(); |
527 my $prefinish = $finish - 60; | 547 my $prefinish = $finish - 60; |
528 | 548 |
529 irc_debug("Character %s is training %s %d (%s == %d sec)", | 549 irc_debug("Character %s is training %s %d (%s == %d sec)", |
530 $f->{char}, $skill->name, $skill->level, | 550 $f->{char}, $skilltree{$skill->trainingTypeID}, |
531 $skill->time_remaining, $finish); | 551 $skill->trainingToLevel, $skill->trainingEndTime, $finish); |
532 | 552 |
533 # Ignore bad data | 553 # Ignore bad data |
534 if ($finish < 0) | 554 if ($finish < 0) |
535 { | 555 { |
536 irc_debug("Unreasonable finish time given of %s seconds, ignoring", | 556 irc_debug("Unreasonable finish time given of %s seconds, ignoring", |
537 $finish); | 557 $finish); |
538 return; | 558 return; |
539 } | 559 } |
540 | 560 |
541 $f->{skill} = $skill->id; | 561 $f->{skill} = 1; #scalar $skill->trainingTypeID; |
542 $f->{skill_finish} = $skill->finish_time; | 562 irc_debug("Skill was %s", $f->{skill}); |
543 $f->{skill_name} = sprintf("%s %d", $skill->name, $skill->level); | 563 $f->{skill_finish} = $skill_finish; |
564 $f->{skill_name} = sprintf("%s %d", $skilltree{$skill->trainingTypeID}, | |
565 $skill->trainingToLevel); | |
544 | 566 |
545 # Check if the finish time is within scheduled EVE downtime | 567 # Check if the finish time is within scheduled EVE downtime |
546 if (timestamp_in_downtime($f->{skill_finish})) | 568 if (timestamp_in_downtime($f->{skill_finish})) |
547 { | 569 { |
548 $self->privmsg('#' . $config{channel}, sprintf( | 570 $self->privmsg('#' . $config{channel}, sprintf( |