Mercurial > hg > skillbot
annotate skillbot.pl @ 10:9cc6dbc803f6
Fixing docs, allowing chankey
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Sat, 06 Dec 2008 15:47:34 +0000 |
parents | c797330cd371 |
children | 277d818f5496 |
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 HTML::Entities; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
27 use POSIX; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
28 use Encode; |
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 |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
50 my $version = '0.01'; |
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); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
109 } |
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 sub irc_debug |
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 my ($fmt, @args) = @_; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
114 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
115 return unless $DEBUG; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
116 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
117 $fmt = '%s| *** ' . $fmt . "\n"; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
118 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
119 print sprintf($fmt, scalar gmtime(), @args); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
120 } |
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 =pod |
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 Timers to set going when we start. |
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 =cut |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
127 sub init_timers |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
128 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
129 # Join channels fort eh first time, ~15 secs after connect |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
130 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
|
131 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
132 # 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
|
133 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
|
134 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
135 # 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
|
136 # API sessions for them all |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
137 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
|
138 |
8
cb6e21f2d514
Fixing re-check after skill completion
Dominic Cleal <dominic@computerkb.co.uk>
parents:
7
diff
changeset
|
139 # Check for new skills every 30 minutes. |
cb6e21f2d514
Fixing re-check after skill completion
Dominic Cleal <dominic@computerkb.co.uk>
parents:
7
diff
changeset
|
140 add_repeat_timer(1800, 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
|
141 } |
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 sub nickserv_id_now |
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 my ($self) = shift; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
146 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
147 $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
|
148 } |
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 sub nickserv_release |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
151 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
152 my ($self) = shift; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
153 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
154 $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
|
155 $config{nick_pass})); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
156 } |
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 sub on_connect |
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 my $self = shift; |
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 =pod |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
163 $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
|
164 $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
|
165 =cut |
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->away($config{away}) if ($config{away}); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
168 join_channels($self); |
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 join_channels |
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; |
10
9cc6dbc803f6
Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents:
9
diff
changeset
|
174 $self->join('#' . $config{channel}, $config{chankey}); |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
175 } |
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 sub on_join |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
178 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
179 my ($self, $event) = @_; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
180 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
181 # print Dumper($event); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
182 if ($event->nick eq $config{nick}) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
183 =pod |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
184 $twit->update("In channel, checking for tweets"); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
185 $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
|
186 =cut |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
187 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
188 # Now we're in, check for tweets as a one-off |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
189 add_one_shot_timer(10, 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
|
190 } |
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 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
193 sub on_ping |
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 my ($self, $event) = @_; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
196 my $their_nick = $event->nick; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
197 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
198 $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
|
199 } |
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 sub on_init |
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 my ($self, $event) = @_; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
204 my (@args) = ($event->args); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
205 shift (@args); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
206 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
207 # irc_debug(@args); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
208 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
209 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
210 sub on_disconnect |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
211 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
212 my ($self, $event) = @_; |
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 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
|
215 $event->from, ($event->args())[0]); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
216 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
217 while (! $self->connect()) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
218 irc_debug("%s", $@); |
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 } |
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 sub on_notice |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
223 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
224 my ($self, $event) = @_; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
225 my ($their_nick) = $event->nick; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
226 my ($notice_txt) = join(' ', $event->args); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
227 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
228 $_ = $their_nick; |
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 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
|
231 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
232 if (/^NickServ$/i) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
233 do_nickserv_notice($self, $notice_txt); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
234 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
235 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
236 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
237 sub do_nickserv_notice |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
238 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
239 my ($self, $notice) = @_; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
240 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
241 $_ = $notice; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
242 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
243 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
|
244 /This nickname is registered and protected/i) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
245 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
|
246 nickserv_id_now($self); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
247 } elsif (/Your nick has been recovered/i) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
248 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
|
249 nickserv_release($self); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
250 } 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
|
251 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
|
252 $self->nick($config{nick}); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
253 } else { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
254 irc_debug("Ignoring NickServ notice: %s", $notice); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
255 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
256 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
257 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
258 sub on_nick_taken |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
259 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
260 my ($self) = shift; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
261 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
262 $self->nick($config{nick} . $$); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
263 nickserv_recover($self); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
264 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
265 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
266 sub on_cversion |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
267 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
268 my ($self, $event) = @_; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
269 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
270 my $vstring = sprintf("VERSION twitfolk v%s " . |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
271 "(\002grifferz\002 is responsible for this atrocity)", $version); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
272 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
273 $self->ctcp_reply($event->nick, $vstring); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
274 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
275 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
276 sub justme |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
277 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
278 if (open(PIDFILE, "< $config{pidfile}")) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
279 my $pid; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
280 chop($pid = <PIDFILE>); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
281 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
|
282 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
283 if (kill(0, $pid)) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
284 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
|
285 cleanup_and_die(); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
286 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
287 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
288 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
289 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
290 sub handle_sig_int_term |
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 $time_to_die = 1; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
293 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
294 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
295 =pod |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
296 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
297 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
|
298 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
299 =cut |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
300 sub handle_perl_death |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
301 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
302 die @_ if $^S; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
303 my $msg = shift; |
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 if ($conn) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
306 $conn->quit($msg . ", died"); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
307 } |
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 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
310 sub daemonize |
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 $SIG{__DIE__} = \&handle_perl_death; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
313 $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
|
314 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
315 # Only daemonize if not running debug mode |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
316 return if ($DEBUG); |
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 my $pid = fork(); |
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 exit if $pid; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
321 die "Couldn't fork: $!" unless defined($pid); |
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 close(STDOUT); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
324 close(STDERR); |
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 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
|
327 } |
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 =pod |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
330 |
10
9cc6dbc803f6
Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents:
9
diff
changeset
|
331 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
|
332 |
10
9cc6dbc803f6
Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents:
9
diff
changeset
|
333 user_id api_key IRC_nick character_name |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
334 |
10
9cc6dbc803f6
Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents:
9
diff
changeset
|
335 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
|
336 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
|
337 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
338 =cut |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
339 sub update_friends |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
340 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
341 my $self = shift; |
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 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
|
344 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
345 while (<FF>) { |
7
6b73a2781c15
Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents:
5
diff
changeset
|
346 chomp; |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
347 next if (/^#/); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
348 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
349 if (/^([0-9]+)\s+([a-f0-9]{64})\s+(\S+)(\s+(.+))?/i) { |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
350 my $uid = $1; |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
351 my $key = uc($2); |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
352 my $nick = $3; |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
353 my $c = $5; |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
354 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
355 if (! $frienduids{$uid}) { |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
356 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
|
357 api_key => $key } ); |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
358 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
359 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
|
360 foreach my $character ($api->characters) { |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
361 next if defined $c && $c ne $character->name; |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
362 push @friends, { |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
363 char => $character, |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
364 api => $api, |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
365 nick => $nick |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
366 }; |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
367 $loaded++; |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
368 } |
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
369 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
370 if (defined $c && $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
|
371 { |
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
372 irc_debug("EVE: Unable to find character %s for ID %lu", |
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
373 $c, $uid); |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
374 next; |
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 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
377 irc_debug("EVE: Adding new friend %s (%lu), %lu characters", |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
378 $nick, $uid, $loaded); |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
379 } |
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 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
383 close(FF) or warn "Something weird when closing friends_file: $!"; |
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 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
386 =pod |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
387 |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
388 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
|
389 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
|
390 |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
391 =cut |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
392 sub check_training |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
393 { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
394 my $self = shift; |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
395 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
396 foreach my $f (@friends) { |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
397 # Skip skills training that we've learnt about |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
398 next if defined $f->{skill}; |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
399 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
400 my $skill = $f->{char}->skill->in_training; |
5
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
401 # Nothing training |
dddb84241032
Bot can now read skills from the API for its friends
Dominic Cleal <dominic@computerkb.co.uk>
parents:
1
diff
changeset
|
402 next unless $skill; |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
403 |
10
9cc6dbc803f6
Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents:
9
diff
changeset
|
404 irc_debug("Character %s is training %s %lu (%s == %lu sec)", |
9cc6dbc803f6
Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents:
9
diff
changeset
|
405 $f->{char}->name, $skill->name, $skill->level, |
9cc6dbc803f6
Fixing docs, allowing chankey
Dominic Cleal <dominic@computerkb.co.uk>
parents:
9
diff
changeset
|
406 $skill->time_remaining, ($skill->finish_time - time())); |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
407 |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
408 $f->{skill} = $skill; |
7
6b73a2781c15
Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents:
5
diff
changeset
|
409 |
6b73a2781c15
Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents:
5
diff
changeset
|
410 my $text = sprintf("%s has completed training skill %s %s", |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
411 $f->{char}->name, $skill->name, $skill->level); |
7
6b73a2781c15
Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents:
5
diff
changeset
|
412 |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
413 if ($text =~ /[\n\r]/) { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
414 $text =~ s/[\n\r]/ /g; |
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 |
7
6b73a2781c15
Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents:
5
diff
changeset
|
417 add_one_shot_timer($skill->finish_time - time(), sub { |
6b73a2781c15
Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents:
5
diff
changeset
|
418 $self->notice('#' . $config{channel}, sprintf("[%s] %s", |
9
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
419 $f->{nick}, encode("utf8", $text))); |
c797330cd371
Handles multiple characters on one account
Dominic Cleal <dominic@computerkb.co.uk>
parents:
8
diff
changeset
|
420 delete $f->{skill}; |
7
6b73a2781c15
Skill completion notifications done
Dominic Cleal <dominic@computerkb.co.uk>
parents:
5
diff
changeset
|
421 }); |
0
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
422 } |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
423 } |
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 END { |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
426 cleanup_and_die(); |
d6521d5ea884
Import of Andy Smith's twitfolk bot
Dominic Cleal <dominic@computerkb.co.uk>
parents:
diff
changeset
|
427 } |