annotate skillbot.pl @ 58:7d43407a9214

Update skill times when skill hasn't changed
author Dominic Cleal <dominic@computerkb.co.uk>
date Sun, 28 Dec 2008 18:36:29 +0000
parents fabae7870b52
children 74213ea642da
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
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
23 use WebService::EveOnline;
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;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
29
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
30 require 'timers.pl';
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
31
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
32 # Config variables
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
33 my %config;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
34
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
35 my %frienduids;
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
36 my @friends;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
37
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
38 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
39 while(<CONFIG>) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
40 chomp;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
41 s/#.*//;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
42 s/^\s+//;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
43 s/\s+$//;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
44 next unless length;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
45 my ($var, $value) = split(/\s*=\s*/, $_, 2);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
46 $config{$var} = $value;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
47 }
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
48 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
49
50
14f0f0b0f83e Release of v0.02
Dominic Cleal <dominic@computerkb.co.uk>
parents: 49
diff changeset
50 my $version = '0.02';
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
51 my $ircname = "skillbot v$version";
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
52
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
53 my $DEBUG = $ENV{'IRC_DEBUG'} || 0;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
54 my $time_to_die = 0;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
55
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
56 justme();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
57 daemonize();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
58
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
59 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
60 print PIDFILE "$$\n";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
61 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
62
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
63 update_friends(undef);
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 $irc = new Net::IRC;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
66
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
67 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
68 Port => $config{'target_port'},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
69 Nick => $config{'nick'},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
70 Ircname => $ircname,
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
71 Username => $config{'username'},
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
72 Password => $config{'target_pass'})
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
73 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
74
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
75 binmode $conn->{_socket}, ":bytes";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
76
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
77 init_handlers($conn);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
78 init_timers();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
79
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
80 until ($time_to_die) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
81 $irc->do_one_loop();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
82 do_timers_once($conn);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
83 do_timers_repeat($conn);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
84 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
85
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
86 if ($conn) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
87 $conn->quit("Caught SIGINT, bye.");
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
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
90 cleanup_and_die();
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 sub cleanup_and_die {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
93 unlink($config{'pidfile'});
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
94 exit();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
95 }
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 sub init_handlers
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
98 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
99 my ($self) = shift;
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 $self->add_handler('notice', \&on_notice);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
102 $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
103 $self->add_handler('disconnect', \&on_disconnect);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
104 $self->add_handler(376, \&on_connect);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
105 $self->add_handler(433, \&on_nick_taken);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
106 $self->add_handler('cversion', \&on_cversion);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
107 $self->add_handler('cping', \&on_ping);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
108 $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
109 $self->add_handler('public', \&on_public);
0
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
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
112 sub irc_debug
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
113 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
114 my ($fmt, @args) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
115
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
116 return unless $DEBUG;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
117
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
118 $fmt = '%s| *** ' . $fmt . "\n";
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
119
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
120 print sprintf($fmt, scalar gmtime(), @args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
121 }
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 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
124
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
125 Timers to set going when we start.
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
126
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
127 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
128 sub init_timers
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
129 {
22
119c2b763dd2 small textual change, and my first hg commit --- i hate you dom
user@eee-df
parents: 20
diff changeset
130 # 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
131 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
132
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
133 # 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
134 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
135
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
136 # 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
137 # API sessions for them all
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
138 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
139
14
5e35c408cc3c Handles cases where the skills change and aren't seen to completion
Dominic Cleal <dominic@computerkb.co.uk>
parents: 13
diff changeset
140 # 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
141 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
142 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
143
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
144 sub nickserv_id_now
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
145 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
146 my ($self) = shift;
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 $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
149 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
150
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
151 sub nickserv_release
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
152 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
153 my ($self) = shift;
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 $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
156 $config{nick_pass}));
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
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
159 sub on_connect
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
160 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
161 my $self = shift;
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 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
164 $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
165 $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
166 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
167
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
168 $self->away($config{away}) if ($config{away});
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
169 join_channels($self);
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
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
172 sub join_channels
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
173 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
174 my $self = shift;
10
9cc6dbc803f6 Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents: 9
diff changeset
175 $self->join('#' . $config{channel}, $config{chankey});
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
176 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
177
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
178 sub on_join
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 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
181
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
182 # print Dumper($event);
55
c5ce2fff9b85 Update friends as they're added, not on channel join
Dominic Cleal <dominic@computerkb.co.uk>
parents: 54
diff changeset
183 # if ($event->nick eq $config{nick}) {
c5ce2fff9b85 Update friends as they're added, not on channel join
Dominic Cleal <dominic@computerkb.co.uk>
parents: 54
diff changeset
184 # }
0
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
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
187 sub on_ping
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 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
190 my $their_nick = $event->nick;
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 $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
193 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
194
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
195 sub on_init
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
196 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
197 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
198 my (@args) = ($event->args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
199 shift (@args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
200
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
201 # irc_debug(@args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
202 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
203
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
204 sub on_disconnect
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 my ($self, $event) = @_;
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 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
209 $event->from, ($event->args())[0]);
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 while (! $self->connect()) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
212 irc_debug("%s", $@);
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 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
215
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
216 sub on_public
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
217 {
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
218 my ($self, $event) = @_;
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
219 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
220
31
ba7303a5f42d Added \!update command
df
parents: 29
diff changeset
221 # 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
222 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
223 my $found = 0;
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
224
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
225 my @filtered =
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
226 sort {
54
9ed1e53a8d3e Safety checks in hash sort
Dominic Cleal <dominic@computerkb.co.uk>
parents: 53
diff changeset
227 (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
228 ? $a->{skill_finish} <=> $b->{skill_finish}
54
9ed1e53a8d3e Safety checks in hash sort
Dominic Cleal <dominic@computerkb.co.uk>
parents: 53
diff changeset
229 : 0
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
230 }
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
231 grep {
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
232 ((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
233 || lc($2) eq 'all' || lc($2) eq '*'))
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
234 || (!defined $2 && $_->{nick} eq $their_nick))
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
235 } @friends;
45
1d349044c860 Add finish day and time to !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 44
diff changeset
236
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
237 for my $f (@filtered)
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
238 {
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
239 check_friend($self, $f);
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
240 my $text;
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
241 if (defined $f->{skill}) {
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
242 my $downtime = '';
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
243 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
244 $downtime = ", coincides with downtime";
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
245 }
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
246
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
247 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
248 epoch => $f->{skill_finish},
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
249 time_zone => $f->{tz});
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
250
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
251 $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
252 "(finish in %s, %s %s%s)",
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
253 $f->{skill_name}, $f->{skill_countdown},
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
254 $finish->strftime("%A %R"),
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
255 $finish->time_zone_short_name(),
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
256 $downtime);
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
257 } else {
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
258 $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
259 }
53
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
260
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
261 $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
262 "\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
263 encode("utf8", $text)));
d5872370102a Sorting !eta output for multiple characters, tidying filtering
Dominic Cleal <dominic@computerkb.co.uk>
parents: 52
diff changeset
264 $found++;
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
265 }
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
266
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
267 if ($found == 0) {
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
268 $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
269 }
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
270 }
31
ba7303a5f42d Added \!update command
df
parents: 29
diff changeset
271
32
276658826bc0 Local commit, so dom can help me out. -- love perl
df
parents: 31
diff changeset
272 # 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
273 elsif ($msg =~ /^\!next/i) {
32
276658826bc0 Local commit, so dom can help me out. -- love perl
df
parents: 31
diff changeset
274 my $nreply = "Training: ";
38
a8b60d2968b2 Small tidy and removing useless skill time check
Dominic Cleal <dominic@computerkb.co.uk>
parents: 37
diff changeset
275
52
0f8275723d81 Update characters on retrieval, remove !update
Dominic Cleal <dominic@computerkb.co.uk>
parents: 50
diff changeset
276 check_training($self);
38
a8b60d2968b2 Small tidy and removing useless skill time check
Dominic Cleal <dominic@computerkb.co.uk>
parents: 37
diff changeset
277 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
278 $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
279 } grep { defined $_->{skill} } @friends;
32
276658826bc0 Local commit, so dom can help me out. -- love perl
df
parents: 31
diff changeset
280
38
a8b60d2968b2 Small tidy and removing useless skill time check
Dominic Cleal <dominic@computerkb.co.uk>
parents: 37
diff changeset
281 for my $f (@training) {
37
5900a37101eb Bold names in !next
Dominic Cleal <dominic@computerkb.co.uk>
parents: 36
diff changeset
282 $nreply .= sprintf("\002%s\002 (%s) | ",
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
283 $f->{char}, $f->{skill_countdown});
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
284 }
33
48df6d55427b Forgot the echo of the result
df
parents: 32
diff changeset
285
36
6baa10b255ae Removing final pipe from next output
Dominic Cleal <dominic@computerkb.co.uk>
parents: 35
diff changeset
286 $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
287 }
21
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
288 }
7bcc70b2121a Adding !eta handler to report current training status
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
289
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
290 sub on_notice
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
291 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
292 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
293 my ($their_nick) = $event->nick;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
294 my ($notice_txt) = join(' ', $event->args);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
295
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
296 $_ = $their_nick;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
297
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
298 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
299
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
300 if (/^NickServ$/i) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
301 do_nickserv_notice($self, $notice_txt);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
302 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
303 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
304
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
305 sub do_nickserv_notice
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
306 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
307 my ($self, $notice) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
308
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
309 $_ = $notice;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
310
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
311 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
312 /This nickname is registered and protected/i) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
313 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
314 nickserv_id_now($self);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
315 } elsif (/Your nick has been recovered/i) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
316 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
317 nickserv_release($self);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
318 } 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
319 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
320 $self->nick($config{nick});
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
321 } else {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
322 irc_debug("Ignoring NickServ notice: %s", $notice);
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
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
326 sub on_nick_taken
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
327 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
328 my ($self) = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
329
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
330 $self->nick($config{nick} . $$);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
331 nickserv_recover($self);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
332 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
333
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
334 sub on_cversion
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
335 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
336 my ($self, $event) = @_;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
337
24
db2e2a751dd6 Changed the c2cp version reply to match the irc name (any playing a bith with hg)
df
parents: 22
diff changeset
338 my $vstring = sprintf("VERSION %s", $ircname);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
339
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
340 $self->ctcp_reply($event->nick, $vstring);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
341 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
342
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
343 sub justme
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 if (open(PIDFILE, "< $config{pidfile}")) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
346 my $pid;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
347 chop($pid = <PIDFILE>);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
348 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
349
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
350 if (kill(0, $pid)) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
351 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
352 cleanup_and_die();
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 }
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
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
357 sub handle_sig_int_term
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
358 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
359 $time_to_die = 1;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
360 }
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 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
363
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
364 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
365
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
366 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
367 sub handle_perl_death
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
368 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
369 die @_ if $^S;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
370 my $msg = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
371
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
372 if ($conn) {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
373 $conn->quit($msg . ", died");
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 daemonize
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 $SIG{__DIE__} = \&handle_perl_death;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
380 $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
381
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
382 # Only daemonize if not running debug mode
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
383 return if ($DEBUG);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
384
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
385 my $pid = fork();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
386
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
387 exit if $pid;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
388 die "Couldn't fork: $!" unless defined($pid);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
389
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
390 close(STDOUT);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
391 close(STDERR);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
392
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
393 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
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 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
397
10
9cc6dbc803f6 Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents: 9
diff changeset
398 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
399
47
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
400 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
401
10
9cc6dbc803f6 Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents: 9
diff changeset
402 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
403 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
404
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
405 =cut
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
406 sub update_friends
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
407 {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
408 my $self = shift;
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 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
411
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
412 while (<FF>) {
7
6b73a2781c15 Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents: 5
diff changeset
413 chomp;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
414 next if (/^#/);
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
415
47
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
416 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
417 my $uid = $1;
12
d9526ab0c6bb Fixing the handling of df's weird API key
Dominic Cleal <dominic@computerkb.co.uk>
parents: 11
diff changeset
418 my $key = $2;
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
419 my $nick = $3;
47
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
420 my $tz = $4;
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
421 my $c = $6;
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
422
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
423 if (! $frienduids{$uid}) {
49
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
424 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
425 {
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
426 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
427 ", using UTC", $tz, $nick);
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
428 $tz = 'UTC';
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
429 }
0fa8fe61aca1 Adding tz to !eta output, use UTC by default
Dominic Cleal <dominic@computerkb.co.uk>
parents: 47
diff changeset
430
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
431 my $api = WebService::EveOnline->new( { user_id => $uid,
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
432 api_key => $key } );
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
433
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
434 my $loaded = 0;
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
435 foreach my $character ($api->characters) {
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
436 next if defined $c && $c ne $character->name;
55
c5ce2fff9b85 Update friends as they're added, not on channel join
Dominic Cleal <dominic@computerkb.co.uk>
parents: 54
diff changeset
437 my $f = {
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
438 char_api => $character,
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
439 char => $character->name,
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
440 api => $api,
47
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
441 nick => $nick,
31a4d4cab76f Adding timezone field to friends file, used for !eta
Dominic Cleal <dominic@computerkb.co.uk>
parents: 46
diff changeset
442 tz => $tz
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
443 };
55
c5ce2fff9b85 Update friends as they're added, not on channel join
Dominic Cleal <dominic@computerkb.co.uk>
parents: 54
diff changeset
444 push @friends, $f;
c5ce2fff9b85 Update friends as they're added, not on channel join
Dominic Cleal <dominic@computerkb.co.uk>
parents: 54
diff changeset
445 check_friend($self, $f);
9
c797330cd371 Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents: 8
diff changeset
446 $loaded++;
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
447 }
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
448
18
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
449 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
450 {
20
631123cc735c Removing EVE prefix from log messages
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
451 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
452 $c, $uid);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
453 next;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
454 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
455
13
d9a9bcd44c2e Fixing re-adding of friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 12
diff changeset
456 $frienduids{$uid} = $loaded;
20
631123cc735c Removing EVE prefix from log messages
Dominic Cleal <dominic@computerkb.co.uk>
parents: 18
diff changeset
457 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
458 $nick, $uid, $loaded);
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
459 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
460 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
461 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
462
22
119c2b763dd2 small textual change, and my first hg commit --- i hate you dom
user@eee-df
parents: 20
diff changeset
463 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
464 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
465
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
466 =pod
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
467
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
468 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
469 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
470
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
471 =cut
5
dddb84241032 Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents: 1
diff changeset
472 sub check_training
0
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 my $self = shift;
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
475
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
476 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
477 }
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
478
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
479 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
480 {
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
481 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
482 my $f = shift;
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
483
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
484 # Don't attempt updates during downtime, can cause crash
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
485 return if (timestamp_in_downtime(time));
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
486
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
487 my $skill = $f->{char_api}->skill->in_training;
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
488
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
489 # Nothing 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
490 unless (defined $skill)
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
491 {
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
492 # 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
493 # the announcement
40
19cc55690fd7 Missing brackets
Dominic Cleal <dominic@computerkb.co.uk>
parents: 39
diff changeset
494 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
495 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
496 delete $f->{timer};
4dd6009b0d2a Deleting timer ID if it's already been cancelled
Dominic Cleal <dominic@computerkb.co.uk>
parents: 38
diff changeset
497 }
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
498 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
499 }
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
500
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
501 # 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
502 if (defined $f->{skill}) {
58
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
503 # If the skill's the same, update the times
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
504 if ($skill->id eq $f->{skill})
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
505 {
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
506 $f->{skill_finish} = $skill->finish_time;
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
507 $f->{skill_countdown} = $skill->time_remaining;
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
508 return;
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
509 }
39
4dd6009b0d2a Deleting timer ID if it's already been cancelled
Dominic Cleal <dominic@computerkb.co.uk>
parents: 38
diff changeset
510
58
7d43407a9214 Update skill times when skill hasn't changed
Dominic Cleal <dominic@computerkb.co.uk>
parents: 57
diff changeset
511 # Skill has changed, delet 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
512 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
513 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
514 }
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
515
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
516 my $finish = $skill->finish_time - time();
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
517 my $prefinish = $finish - 60;
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
518
18
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
519 irc_debug("Character %s is training %s %d (%s == %d sec)",
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
520 $f->{char}, $skill->name, $skill->level,
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
521 $skill->time_remaining, $finish);
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
522
18
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
523 # Ignore bad data
10587dbd634b Ignoring bad data which was actually negative
Dominic Cleal <dominic@computerkb.co.uk>
parents: 17
diff changeset
524 if ($finish < 0)
17
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
525 {
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
526 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
527 $finish);
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
528 return;
bef72aa85f2b Ignoring bad data with 2^32 second finish times
Dominic Cleal <dominic@computerkb.co.uk>
parents: 16
diff changeset
529 }
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
530
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
531 $f->{skill} = $skill->id;
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
532 $f->{skill_finish} = $skill->finish_time;
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
533 $f->{skill_countdown} = $skill->time_remaining;
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
534 $f->{skill_name} = sprintf("%s %d", $skill->name, $skill->level);
7
6b73a2781c15 Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents: 5
diff changeset
535
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
536 # 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
537 if (timestamp_in_downtime($f->{skill_finish}))
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
538 {
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
539 $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
540 "\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
541 "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
542 $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
543 scalar(gmtime($f->{skill_finish}))));
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
544 }
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
545
56
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
546 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
547 $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
548
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
549 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
550 $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
551 }
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
552
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
553 # 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
554 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
555 {
16
e238f28f774a No need to save timer
Dominic Cleal <dominic@computerkb.co.uk>
parents: 15
diff changeset
556 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
557 check_friend($self, $f);
7
6b73a2781c15 Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents: 5
diff changeset
558 });
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
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
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
561 $f->{timer} = add_one_shot_timer($skill->finish_time - time(), sub {
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
562 $self->privmsg('#' . $config{channel}, sprintf(
27
708653f624f3 Simplifying bold formatting codes
Dominic Cleal <dominic@computerkb.co.uk>
parents: 26
diff changeset
563 "\002%s:\002 %s", $f->{nick},
708653f624f3 Simplifying bold formatting codes
Dominic Cleal <dominic@computerkb.co.uk>
parents: 26
diff changeset
564 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
565 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
566 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
567 delete $f->{skill_countdown};
c604d8d6ccc5 Caching skill info in friend hash, instead of calling the API
Dominic Cleal <dominic@computerkb.co.uk>
parents: 55
diff changeset
568 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
569 });
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
570 }
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
571
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
572 =pod
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
573
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
574 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
575 scheduled downtime window.
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
576
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
577 =cut
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
578 sub timestamp_in_downtime
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
579 {
57
fabae7870b52 Avoid updating during downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 56
diff changeset
580 my $ts = shift;
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
581
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
582 # 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
583 return ([gmtime($ts)]->[2] == 11);
42
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
584 }
bf685f1a545f Adding detection of downtime windows
Dominic Cleal <dominic@computerkb.co.uk>
parents: 40
diff changeset
585
0
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
586 END {
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
587 cleanup_and_die();
d6521d5ea884 Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff changeset
588 }