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