line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Plugin::IRCNotice; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34035
|
use 5.008_005; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
34
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1058
|
use Dancer ':syntax'; |
|
1
|
|
|
|
|
340478
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
1344
|
use Dancer::Plugin; |
|
1
|
|
|
|
|
1480
|
|
|
1
|
|
|
|
|
86
|
|
9
|
1
|
|
|
1
|
|
1174
|
use IO::Socket::IP; |
|
1
|
|
|
|
|
36028
|
|
|
1
|
|
|
|
|
9
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
register notify => sub { |
14
|
0
|
|
|
0
|
|
|
my ($message) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
info "Sending notification: $message"; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $config = plugin_setting; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
0
|
|
|
|
$config->{host} ||= 'chat.freenode.net'; |
21
|
0
|
|
0
|
|
|
|
$config->{nick} ||= sprintf('dpin%04u', int(rand() * 10000)); |
22
|
0
|
|
0
|
|
|
|
$config->{name} ||= $config->{nick}; |
23
|
0
|
|
0
|
|
|
|
$config->{channel} ||= '#dpintest'; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
0
|
|
|
|
fork and return if $config->{fork}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Add default port |
28
|
0
|
0
|
|
|
|
|
$config->{host} .= ':6667' unless $config->{host} =~ /:\d+$/; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
0
|
|
|
|
my $socket = IO::Socket::IP->new($config->{host}) |
31
|
|
|
|
|
|
|
or warning "Cannot create socket: $@" and return; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# TODO error handling srsly |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
info "Registering as $config->{nick}"; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$socket->say("NICK $config->{nick}"); |
38
|
0
|
|
|
|
|
|
$socket->say("USER $config->{nick} . . :$config->{name}"); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
while (my $line = $socket->getline) { |
41
|
0
|
|
|
|
|
|
info "Got $line"; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ($line =~ /End of \/MOTD/) { |
44
|
0
|
|
|
|
|
|
info "Sending notice to $config->{channel}"; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$socket->say("NOTICE $config->{channel} :$message"); |
47
|
0
|
|
|
|
|
|
$socket->say("QUIT"); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
info "Notice sent"; |
50
|
0
|
0
|
|
|
|
|
exit if $config->{fork}; |
51
|
0
|
|
|
|
|
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
info "Notice not sent"; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
exit if $config->{fork}; |
58
|
0
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
register_plugin; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |