annotate skillbot.pl @ 74:a2fd98163675 default tip

Removing debug
author Dominic Cleal <dominic@computerkb.co.uk>
date Thu, 11 Feb 2010 00:26:16 +0000
parents ee8acca852f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
1 #!/usr/bin/perl
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
2
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
3 # vim:set ts=4 shiftwidth=4 cindent:
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
4
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
5 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
6
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
7 skillbot
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
8
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
9 Provides notifications of EVE Online skill completions over IRC.
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
10
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
11 Based on Andy Smith's twitfolk bot:
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
12 $Id: twitfolk.pl 802 2008-11-29 00:07:38Z andy $
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
13
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
14 Copyright ©2008 Andy Smith <andy+twitfolk.pl@bitfolk.com>
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
15 Portions copyright ©2008 Dominic Cleal <dominic@computerkb.co.uk>
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
16
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
17 Artistic license same as Perl.
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
18 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
19
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
20 use strict;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
21 use warnings;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
22
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
23 use EVEAPI;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
24 use Data::Dumper;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
25 use Net::IRC;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
26 use POSIX;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
27 use Encode;
45
1d349044c860 Add finish day and time to !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 44
diff changeset
28 use DateTime;
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
29 use Time::Local
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
30
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
31 require 'timers.pl';
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
32
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
33 # Config variables
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
34 my %config;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
35
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
36 my %frienduids;
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
37 my @friends;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
38
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
39 # Load up the full EVE skill tree and then create a hash of skill IDs to names
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
40 my $skill_api = EVEAPI->new(version => 2)->eve->SkillTree->load;
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
41 my %skilltree;
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
42
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
43 for my $skill_group (@{$skill_api->skillGroups}) {
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
44 $skilltree{$_->typeID} = $_->typeName foreach (@{$skill_group->skills});
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
45 }
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
46
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
47 my $skills_loaded = scalar keys %skilltree;
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
48 printf("Init: Loaded a total of %d entries into the skill tree\n", $skills_loaded);
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
49
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
50 open(CONFIG, "< skillbot.conf") or die "can't open skillbot.conf for reading: $!";
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
51 while(<CONFIG>) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
52 chomp;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
53 s/#.*//;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
54 s/^\s+//;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
55 s/\s+$//;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
56 next unless length;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
57 my ($var, $value) = split(/\s*=\s*/, $_, 2);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
58 $config{$var} = $value;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
59 }
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
60 close(CONFIG) or die "can't close skillbot.conf: $!";
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
61
71
8764194b1bc4 Release of v0.03
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
62 my $version = '0.03';
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
63 my $ircname = "skillbot v$version";
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
64
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
65 my $DEBUG = $ENV{'IRC_DEBUG'} || 0;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
66 my $time_to_die = 0;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
67
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
68 justme();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
69 daemonize();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
70
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
71 open(PIDFILE, "> $config{'pidfile'}") or die "can't write $config{'pidfile'}: $!";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
72 print PIDFILE "$$\n";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
73 close(PIDFILE) or die "can't close $config{'pidfile'}: $!";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
74
61
2328f73e25a8 Fixing undefined variable on init
Dominic Cleal <dominic@computerkb.co.uk>
parents: 60
diff changeset
75 my $irc = new Net::IRC;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
76
62
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
77 update_friends(undef);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
78
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
79 my $conn = $irc->newconn(Server => $config{'target_server'},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
80 Port => $config{'target_port'},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
81 Nick => $config{'nick'},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
82 Ircname => $ircname,
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
83 Username => $config{'username'},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
84 Password => $config{'target_pass'})
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
85 or die "can't connect to $config{'target_server'}:$config{'target_port'}: $@\n";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
86
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
87 binmode $conn->{_socket}, ":bytes";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
88
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
89 init_handlers($conn);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
90 init_timers();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
91
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
92 until ($time_to_die) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
93 $irc->do_one_loop();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
94 do_timers_once($conn);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
95 do_timers_repeat($conn);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
96 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
97
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
98 if ($conn) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
99 $conn->quit("Caught SIGINT, bye.");
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
100 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
101
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
102 cleanup_and_die();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
103
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
104 sub cleanup_and_die {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
105 unlink($config{'pidfile'});
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
106 exit();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
107 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
108
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
109 sub init_handlers
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
110 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
111 my ($self) = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
112
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
113 $self->add_handler('notice', \&on_notice);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
114 $self->add_handler([ 251,252,253,254,302,255 ], \&on_init);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
115 $self->add_handler('disconnect', \&on_disconnect);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
116 $self->add_handler(376, \&on_connect);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
117 $self->add_handler(433, \&on_nick_taken);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
118 $self->add_handler('cversion', \&on_cversion);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
119 $self->add_handler('cping', \&on_ping);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
120 $self->add_handler('join', \&on_join);
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
121 $self->add_handler('public', \&on_public);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
122 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
123
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
124 sub irc_debug
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
125 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
126 my ($fmt, @args) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
127
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
128 return unless $DEBUG;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
129
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
130 $fmt = '%s| *** ' . $fmt . "\n";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
131
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
132 print sprintf($fmt, scalar gmtime(), @args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
133 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
134
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
135 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
136
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
137 Timers to set going when we start.
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
138
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
139 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
140 sub init_timers
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
141 {
22
119c2b763dd2 small textual change, and my first hg commit --- i hate you dom
user@eee-df
parents: 20
diff changeset
142 # Join channels for the first time, ~15 secs after connect
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
143 add_one_shot_timer(15, sub { my ($timer, $self) = @_; join_channels($self); });
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
144
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
145 # Check we are in the right channels every 10 minutes
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
146 add_repeat_timer(600, sub { my ($timer, $self) = @_; join_channels($self); });
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
147
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
148 # Read the "friends" config file every 6 minutes and make sure we have
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
149 # API sessions for them all
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
150 add_repeat_timer(360, sub { my ($timer, $self) = @_; update_friends($self); });
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
151
14
5e35c408cc3c Handles cases where the skills change and aren't seen to completion
Dominic Cleal <dominic@computerkb.co.uk>
parents: 13
diff changeset
152 # Check for new skills every 60 minutes.
5e35c408cc3c Handles cases where the skills change and aren't seen to completion
Dominic Cleal <dominic@computerkb.co.uk>
parents: 13
diff changeset
153 add_repeat_timer(3600, sub { my ($timer, $self) = @_; check_training($self); });
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
154 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
155
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
156 sub nickserv_id_now
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
157 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
158 my ($self) = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
159
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
160 $self->privmsg("NickServ", sprintf("IDENTIFY %s", $config{nick_pass}));
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
161 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
162
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
163 sub nickserv_release
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
164 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
165 my ($self) = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
166
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
167 $self->privmsg("NickServ", sprintf("RELEASE %s %s", $config{nick},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
168 $config{nick_pass}));
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
169 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
170
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
171 sub on_connect
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
172 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
173 my $self = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
174
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
175 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
176 $twit->update(sprintf("Connected to irc://%s/, joining channels", $config{target_server}));
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
177 $twit->http_code == 200 or print sprintf("%s| *** %s\n", scalar gmtime(), $twit->http_message);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
178 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
179
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
180 $self->away($config{away}) if ($config{away});
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
181 join_channels($self);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
182 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
183
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
184 sub join_channels
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
185 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
186 my $self = shift;
10
9cc6dbc803f6 Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents: 9
diff changeset
187 $self->join('#' . $config{channel}, $config{chankey});
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
188 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
189
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
190 sub on_join
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
191 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
192 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
193
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
194 # print Dumper($event);
62
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
195 if ($event->nick eq $config{nick}) {
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
196 =pod
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
197 $twit->update("In channel, checking for tweets");
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
198 $twit->http_code == 200 or print sprintf("%s| *** %s\n", scalar gmtime(), $twit->http_message);
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
199 =cut
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
200
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
201 # Now we're in, check for tweets as a one-off
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
202 add_one_shot_timer(10, sub { my ($timer, $self) = @_; check_training($self); });
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
203 }
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
204 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
205
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
206 sub on_ping
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
207 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
208 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
209 my $their_nick = $event->nick;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
210
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
211 $self->ctcp_reply($their_nick, "PING " . join (' ', ($event->args)));
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
212 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
213
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
214 sub on_init
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
215 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
216 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
217 my (@args) = ($event->args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
218 shift (@args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
219
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
220 # irc_debug(@args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
221 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
222
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
223 sub on_disconnect
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
224 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
225 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
226
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
227 irc_debug("Disconnected from %s (%s). Attempting to reconnect...",
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
228 $event->from, ($event->args())[0]);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
229
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
230 while (! $self->connect()) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
231 irc_debug("%s", $@);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
232 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
233 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
234
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
235 sub on_public
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
236 {
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
237 my ($self, $event) = @_;
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
238 my ($their_nick, $msg) = ($event->nick, $event->args);
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
239
31
ba7303a5f42d Added \!update command
df
parents: 29
diff changeset
240 # lists the current chars in training of the caller
26
bb1f7ab990b1 Adding an optional argument to !eta for a character name
Dominic Cleal <dominic@computerkb.co.uk>
parents: 25
diff changeset
241 if ($msg =~ /^\!eta(\s+(.+))?/i) {
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
242 my $found = 0;
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
243
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
244 my @filtered =
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
245 sort {
54
9ed1e53a8d3e Safety checks in hash sort
Dominic Cleal <dominic@computerkb.co.uk>
parents: 53
diff changeset
246 (defined $a->{skill} && defined $b->{skill})
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
247 ? $a->{skill_finish} <=> $b->{skill_finish}
54
9ed1e53a8d3e Safety checks in hash sort
Dominic Cleal <dominic@computerkb.co.uk>
parents: 53
diff changeset
248 : 0
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
249 }
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
250 grep {
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
251 ((defined $2 && (lc($_->{char}) eq lc($2)
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
252 || lc($2) eq 'all' || lc($2) eq '*'))
69
3455a0ab9264 eta command no longer case sensitive on nickname
Dominic Cleal <dominic@computerkb.co.uk>
parents: 68
diff changeset
253 || (!defined $2 && lc($_->{nick}) eq lc($their_nick)))
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
254 } @friends;
45
1d349044c860 Add finish day and time to !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 44
diff changeset
255
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
256 for my $f (@filtered)
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
257 {
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
258 check_friend($self, $f);
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
259 my $text;
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
260 if (defined $f->{skill}) {
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
261 my $downtime = '';
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
262 if (timestamp_in_downtime($f->{skill_finish})) {
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
263 $downtime = ", coincides with downtime";
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
264 }
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
265
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
266 my $finish = DateTime->from_epoch(
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
267 epoch => $f->{skill_finish},
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
268 time_zone => $f->{tz});
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
269
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
270 $text = sprintf("Currently training %s ".
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
271 "(finish in %s, %s %s%s)",
59
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
272 $f->{skill_name},
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
273 countdown($f->{skill_finish}),
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
274 $finish->strftime("%A %R"),
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
275 $finish->time_zone_short_name(),
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
276 $downtime);
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
277 } else {
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
278 $text = "No skill currently training";
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
279 }
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
280
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
281 $self->privmsg('#' . $config{channel}, sprintf(
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
282 "\002%s:\002 %s", $f->{char},
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
283 encode("utf8", $text)));
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
284 $found++;
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
285 }
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
286
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
287 if ($found == 0) {
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
288 $self->privmsg('#' . $config{channel}, "No characters found");
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
289 }
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
290 }
31
ba7303a5f42d Added \!update command
df
parents: 29
diff changeset
291
32
276658826bc0 Local commit, so dom can help me out. -- love perl
df
parents: 31
diff changeset
292 # lists the chars in order of shortest training time
37
5900a37101eb Bold names in !next
Dominic Cleal <dominic@computerkb.co.uk>
parents: 36
diff changeset
293 elsif ($msg =~ /^\!next/i) {
32
276658826bc0 Local commit, so dom can help me out. -- love perl
df
parents: 31
diff changeset
294 my $nreply = "Training: ";
38
a8b60d2968b2 Small tidy and removing useless skill time check
Dominic Cleal <dominic@computerkb.co.uk>
parents: 37
diff changeset
295
52
0f8275723d81 Update characters on retrieval, remove !update
Dominic Cleal <dominic@computerkb.co.uk>
parents: 50
diff changeset
296 check_training($self);
38
a8b60d2968b2 Small tidy and removing useless skill time check
Dominic Cleal <dominic@computerkb.co.uk>
parents: 37
diff changeset
297 my @training = sort {
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
298 $a->{skill_finish} <=> $b->{skill_finish}
38
a8b60d2968b2 Small tidy and removing useless skill time check
Dominic Cleal <dominic@computerkb.co.uk>
parents: 37
diff changeset
299 } grep { defined $_->{skill} } @friends;
32
276658826bc0 Local commit, so dom can help me out. -- love perl
df
parents: 31
diff changeset
300
38
a8b60d2968b2 Small tidy and removing useless skill time check
Dominic Cleal <dominic@computerkb.co.uk>
parents: 37
diff changeset
301 for my $f (@training) {
37
5900a37101eb Bold names in !next
Dominic Cleal <dominic@computerkb.co.uk>
parents: 36
diff changeset
302 $nreply .= sprintf("\002%s\002 (%s) | ",
59
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
303 $f->{char}, countdown($f->{skill_finish}));
34
8b631d17dfd0 Fixed some stuff after talking to dom -- yeah it could have been done simpler if he told me yesterday :P
df
parents: 33
diff changeset
304 }
33
48df6d55427b Forgot the echo of the result
df
parents: 32
diff changeset
305
36
6baa10b255ae Removing final pipe from next output
Dominic Cleal <dominic@computerkb.co.uk>
parents: 35
diff changeset
306 $self->privmsg('#' . $config{channel}, substr($nreply, 0, -3));
32
276658826bc0 Local commit, so dom can help me out. -- love perl
df
parents: 31
diff changeset
307 }
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
308 }
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
309
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
310 sub on_notice
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
311 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
312 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
313 my ($their_nick) = $event->nick;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
314 my ($notice_txt) = join(' ', $event->args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
315
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
316 $_ = $their_nick;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
317
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
318 irc_debug("Got notice from %s: %s", $_, $notice_txt);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
319
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
320 if (/^NickServ$/i) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
321 do_nickserv_notice($self, $notice_txt);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
322 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
323 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
324
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
325 sub do_nickserv_notice
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
326 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
327 my ($self, $notice) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
328
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
329 $_ = $notice;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
330
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
331 if (/This nick is owned by someone else/ ||
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
332 /This nickname is registered and protected/i) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
333 irc_debug("ID to NickServ at request of NickServ");
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
334 nickserv_id_now($self);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
335 } elsif (/Your nick has been recovered/i) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
336 irc_debug("NickServ told me I recovered my nick, RELEASE'ing now");
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
337 nickserv_release($self);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
338 } elsif (/Your nick has been released from custody/i) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
339 irc_debug("NickServ told me my nick is released, /nick'ing now");
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
340 $self->nick($config{nick});
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
341 } else {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
342 irc_debug("Ignoring NickServ notice: %s", $notice);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
343 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
344 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
345
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
346 sub on_nick_taken
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
347 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
348 my ($self) = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
349
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
350 $self->nick($config{nick} . $$);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
351 nickserv_recover($self);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
352 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
353
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
354 sub on_cversion
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
355 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
356 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
357
24
db2e2a751dd6 Changed the c2cp version reply to match the irc name (any playing a bith with hg)
df
parents: 22
diff changeset
358 my $vstring = sprintf("VERSION %s", $ircname);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
359
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
360 $self->ctcp_reply($event->nick, $vstring);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
361 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
362
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
363 sub justme
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
364 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
365 if (open(PIDFILE, "< $config{pidfile}")) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
366 my $pid;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
367 chop($pid = <PIDFILE>);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
368 close(PIDFILE) or die "couldn't close $config{pidfile}: $1";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
369
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
370 if (kill(0, $pid)) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
371 print "$0 already running (pid $pid), bailing out\n";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
372 cleanup_and_die();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
373 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
374 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
375 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
376
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
377 sub handle_sig_int_term
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
378 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
379 $time_to_die = 1;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
380 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
381
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
382 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
383
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
384 Splurge the perl error to IRC for the amusement of others.
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
385
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
386 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
387 sub handle_perl_death
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
388 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
389 die @_ if $^S;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
390 my $msg = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
391
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
392 if ($conn) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
393 $conn->quit($msg . ", died");
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
394 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
395 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
396
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
397 sub daemonize
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
398 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
399 $SIG{__DIE__} = \&handle_perl_death;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
400 $SIG{INT} = $SIG{TERM} = \&handle_sig_int_term;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
401
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
402 # Only daemonize if not running debug mode
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
403 return if ($DEBUG);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
404
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
405 my $pid = fork();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
406
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
407 exit if $pid;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
408 die "Couldn't fork: $!" unless defined($pid);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
409
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
410 close(STDOUT);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
411 close(STDERR);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
412
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
413 POSIX::setsid() or die "Can't start a new session: $!";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
414 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
415
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
416 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
417
10
9cc6dbc803f6 Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents: 9
diff changeset
418 Read a list of friends from the friends_file. Format is:
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
419
47
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
420 user_id api_key IRC_nick timezone character_name
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
421
10
9cc6dbc803f6 Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents: 9
diff changeset
422 Start a line with # for a comment. Character name is optional, if left
9cc6dbc803f6 Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents: 9
diff changeset
423 out then all characters will be monitored.
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
424
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
425 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
426 sub update_friends
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
427 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
428 my $self = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
429
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
430 open(FF, "< $config{friends_file}") or die "Couldn't open friends_file: $!";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
431
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
432 while (<FF>) {
7
6b73a2781c15 Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents: 5
diff changeset
433 chomp;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
434 next if (/^#/);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
435
60
69d7a89d3adc Timezone is UTC by default if left out of friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 59
diff changeset
436 if (/^([0-9]+)\s+([a-z0-9]{64})\s+(\S+)(\s+(\S+))?(\s+(.+))?/i) {
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
437 my $uid = $1;
12
d9526ab0c6bb Fixing the handling of df's weird API key
Dominic Cleal <dominic@computerkb.co.uk>
parents: 11
diff changeset
438 my $key = $2;
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
439 my $nick = $3;
60
69d7a89d3adc Timezone is UTC by default if left out of friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 59
diff changeset
440 my $tz = $5 || 'UTC';
69d7a89d3adc Timezone is UTC by default if left out of friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 59
diff changeset
441 my $c = $7;
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
442
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
443 if (! $frienduids{$uid}) {
49
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
444 unless (DateTime::TimeZone->is_valid_name($tz))
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
445 {
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
446 irc_debug("Invalid timezone (%s) supplied for friend %s".
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
447 ", using UTC", $tz, $nick);
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
448 $tz = 'UTC';
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
449 }
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
450
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
451 my $api = EVEAPI->new( userID => $uid, apiKey => $key,
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
452 version => 2 );
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
453
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
454 my $api_chars = $api->account->Characters->load;
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
455 my $loaded = 0;
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
456 foreach my $character (@{$api_chars->characters}) {
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
457 next if defined $c && $c ne $character->name;
62
f620582dee33 Reverting changeset c5ce2fff9b85, buggy
Dominic Cleal <dominic@computerkb.co.uk>
parents: 61
diff changeset
458 push @friends, {
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
459 char => $character->name,
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
460 char_id => $character->characterID,
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
461 api => $api,
47
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
462 nick => $nick,
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
463 tz => $tz,
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
464 };
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
465 $loaded++;
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
466 }
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
467
18
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
468 if (defined $c && $loaded eq 0)
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
469 {
20
631123cc735c Removing EVE prefix from log messages
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
470 irc_debug("Unable to find character %s for ID %lu",
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
471 $c, $uid);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
472 next;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
473 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
474
13
d9a9bcd44c2e Fixing re-adding of friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 12
diff changeset
475 $frienduids{$uid} = $loaded;
20
631123cc735c Removing EVE prefix from log messages
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
476 irc_debug("Adding new friend %s (%lu), %lu characters",
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
477 $nick, $uid, $loaded);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
478 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
479 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
480 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
481
22
119c2b763dd2 small textual change, and my first hg commit --- i hate you dom
user@eee-df
parents: 20
diff changeset
482 close(FF) or warn "Something weird occured when closing friends_file: $!";
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
483 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
484
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
485 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
486
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
487 Check for any characters that aren't known to be training, then call the API
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
488 to see if they've started, setting timers.
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
489
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
490 =cut
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
491 sub check_training
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
492 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
493 my $self = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
494
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
495 check_friend($self, $_) foreach (@friends);
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
496 }
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
497
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
498 sub check_friend
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
499 {
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
500 my $self = shift;
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
501 my $f = shift;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
502
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
503 # Don't attempt updates during downtime, can cause crash
66
de14128c1858 Switching to eval for update error handling
Dominic Cleal <dominic@computerkb.co.uk>
parents: 64
diff changeset
504 # return if (timestamp_in_downtime(time));
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
505
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
506 my ($skill, $skill_finish);
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
507 eval { $skill = $f->{api}->char->SkillInTraining(
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
508 characterID => $f->{char_id} ); };
66
de14128c1858 Switching to eval for update error handling
Dominic Cleal <dominic@computerkb.co.uk>
parents: 64
diff changeset
509 warn $@ if $@;
de14128c1858 Switching to eval for update error handling
Dominic Cleal <dominic@computerkb.co.uk>
parents: 64
diff changeset
510
63
27f9196fd610 Adding check for temporary API failures
Dominic Cleal <dominic@computerkb.co.uk>
parents: 62
diff changeset
511 # Sometimes this is undefined if there's an API error, try later
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
512 return unless defined $skill;
63
27f9196fd610 Adding check for temporary API failures
Dominic Cleal <dominic@computerkb.co.uk>
parents: 62
diff changeset
513
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
514 # Nothing training
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
515 unless ($skill->skillInTraining eq '1')
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
516 {
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
517 # If the char was training before and now has stopped then cancel
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
518 # the announcement
40
19cc55690fd7 Missing brackets
Dominic Cleal <dominic@computerkb.co.uk>
parents: 39
diff changeset
519 if (defined $f->{timer}) {
39
4dd6009b0d2a Deleting timer ID if it's already been cancelled
Dominic Cleal <dominic@computerkb.co.uk>
parents: 38
diff changeset
520 del_one_shot_timer($f->{timer});
4dd6009b0d2a Deleting timer ID if it's already been cancelled
Dominic Cleal <dominic@computerkb.co.uk>
parents: 38
diff changeset
521 delete $f->{timer};
4dd6009b0d2a Deleting timer ID if it's already been cancelled
Dominic Cleal <dominic@computerkb.co.uk>
parents: 38
diff changeset
522 }
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
523 return;
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
524 }
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
525
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
526 # Convert EVE's completion timestamp to epoch
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
527 unless ($skill->trainingEndTime =~ /^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$/) {
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
528 irc_debug("Unable to parse skill finish time %s",
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
529 $skill->trainingEndTime);
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
530 return;
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
531 }
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
532 $skill_finish = timegm($6, $5, $4, $3, $2 - 1, $1);
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
533
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
534 # Check for changes in the skill, skip or cancel announcement
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
535 if (defined $f->{skill}) {
64
962dada7587e Reset timer when the finish time has changed for the same skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 63
diff changeset
536 # If the skill's the same, check the finish time and skip if
962dada7587e Reset timer when the finish time has changed for the same skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 63
diff changeset
537 # nothing's changed
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
538 return if ($skill->trainingTypeID eq $f->{skill}
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
539 && $f->{skill_finish} == $skill_finish);
64
962dada7587e Reset timer when the finish time has changed for the same skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 63
diff changeset
540
962dada7587e Reset timer when the finish time has changed for the same skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 63
diff changeset
541 # Skill or finish time has changed, delete previous announcement
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
542 del_one_shot_timer($f->{timer});
39
4dd6009b0d2a Deleting timer ID if it's already been cancelled
Dominic Cleal <dominic@computerkb.co.uk>
parents: 38
diff changeset
543 delete $f->{timer};
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
544 }
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
545
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
546 my $finish = $skill_finish - time();
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
547 my $prefinish = $finish - 60;
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
548
18
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
549 irc_debug("Character %s is training %s %d (%s == %d sec)",
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
550 $f->{char}, $skilltree{$skill->trainingTypeID},
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
551 $skill->trainingToLevel, $skill->trainingEndTime, $finish);
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
552
18
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
553 # Ignore bad data
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
554 if ($finish < 0)
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
555 {
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
556 irc_debug("Unreasonable finish time given of %s seconds, ignoring",
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
557 $finish);
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
558 return;
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
559 }
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
560
74
a2fd98163675 Removing debug
Dominic Cleal <dominic@computerkb.co.uk>
parents: 73
diff changeset
561 $f->{skill} = $skill->trainingTypeID;
70
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
562 $f->{skill_finish} = $skill_finish;
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
563 $f->{skill_name} = sprintf("%s %d", $skilltree{$skill->trainingTypeID},
999787ab415d Replacing WebService::EveOnline with EVEAPI to add skill queue support later.
Dominic Cleal <dominic@computerkb.co.uk>
parents: 69
diff changeset
564 $skill->trainingToLevel);
7
6b73a2781c15 Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents: 5
diff changeset
565
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
566 # Check if the finish time is within scheduled EVE downtime
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
567 if (timestamp_in_downtime($f->{skill_finish}))
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
568 {
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
569 $self->privmsg('#' . $config{channel}, sprintf(
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
570 "\002%s:\002 Completion time of %s's %s " .
44
f7abbe853f5d Adding character name to downtime coincide message
Dominic Cleal <dominic@computerkb.co.uk>
parents: 43
diff changeset
571 "skill will coincide with scheduled downtime at %s",
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
572 $f->{nick}, $f->{char}, $f->{skill_name},
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
573 scalar(gmtime($f->{skill_finish}))));
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
574 }
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
575
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
576 my $text = sprintf("%s has completed training skill %s",
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
577 $f->{char}, $f->{skill_name});
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
578
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
579 if ($text =~ /[\n\r]/) {
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
580 $text =~ s/[\n\r]/ /g;
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
581 }
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
582
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
583 # Add a timer shortly before the end to ensure the user's still training
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
584 if ($prefinish > 0)
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
585 {
16
e238f28f774a No need to save timer
Dominic Cleal <dominic@computerkb.co.uk>
parents: 15
diff changeset
586 add_one_shot_timer($prefinish, sub {
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
587 check_friend($self, $f);
7
6b73a2781c15 Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents: 5
diff changeset
588 });
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
589 }
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
590
60
69d7a89d3adc Timezone is UTC by default if left out of friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 59
diff changeset
591 $f->{timer} = add_one_shot_timer($finish, sub {
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
592 $self->privmsg('#' . $config{channel}, sprintf(
27
708653f624f3 Simplifying bold formatting codes
Dominic Cleal <dominic@computerkb.co.uk>
parents: 26
diff changeset
593 "\002%s:\002 %s", $f->{nick},
708653f624f3 Simplifying bold formatting codes
Dominic Cleal <dominic@computerkb.co.uk>
parents: 26
diff changeset
594 encode("utf8", $text)));
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
595 delete $f->{skill};
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
596 delete $f->{skill_finish};
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
597 delete $f->{skill_name};
15
2ab5ccc01036 Adding a check in shortly before an announcement to double-check the current skill
Dominic Cleal <dominic@computerkb.co.uk>
parents: 14
diff changeset
598 });
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
599 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
600
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
601 =pod
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
602
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
603 Indicate whether the passed timestamp is due to finish during a normal,
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
604 scheduled downtime window.
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
605
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
606 =cut
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
607 sub timestamp_in_downtime
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
608 {
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
609 my $ts = shift;
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
610
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
611 # Check if the finish time is within 11:00-11:59 (EVE downtime)
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
612 return ([gmtime($ts)]->[2] == 11);
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
613 }
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
614
59
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
615 =pod
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
616
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
617 Translate a timestamp to a countdown in terms of days, hours, minutes and
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
618 seconds, EVE style.
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
619
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
620 =cut
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
621 sub countdown
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
622 {
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
623 my $ts = shift;
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
624
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
625 my $tshift = sub {
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
626 my ($a, $b, $max) = @_;
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
627 if ($$a >= $max) {
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
628 $$b = floor($$a / $max);
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
629 $$a = $$a % $max;
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
630 }
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
631 };
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
632
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
633 my ($s, $m, $h, $d) = ($ts - time, 0, 0, 0);
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
634 &$tshift(\$s, \$m, 60);
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
635 &$tshift(\$m, \$h, 60);
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
636 &$tshift(\$h, \$d, 24);
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
637
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
638 return sprintf("%dd %02dh %02dm %02ds", $d, $h, $m, $s);
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
639 }
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
640
74213ea642da Countdown text is now dynamic using the finish timestamp
Dominic Cleal <dominic@computerkb.co.uk>
parents: 58
diff changeset
641
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
642 END {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
643 cleanup_and_die();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
644 }