line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::IRC::Plugin::OutputToPastebin; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1338020
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
78
|
|
9
|
1
|
|
|
1
|
|
6
|
use POE::Component::IRC::Plugin qw(:ALL); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
199
|
|
10
|
1
|
|
|
1
|
|
6
|
use POE qw(Component::WWW::Pastebin::Bot::Pastebot::Create); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
14
|
0
|
0
|
|
|
|
|
croak "Must have even number of arguments to new()" |
15
|
|
|
|
|
|
|
if @_ & 1; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my %args = @_; |
18
|
0
|
|
|
|
|
|
$args{ +lc } = delete $args{ $_ } for keys %args; |
19
|
0
|
|
|
|
|
|
%args = ( |
20
|
|
|
|
|
|
|
max_tries => 3, |
21
|
|
|
|
|
|
|
trigger => '[irc_to_pastebin]', |
22
|
|
|
|
|
|
|
pastebins => [ qw(http://p3m.org/pfn) ], |
23
|
|
|
|
|
|
|
timeout => 20, |
24
|
|
|
|
|
|
|
debug => 0, |
25
|
|
|
|
|
|
|
%args, |
26
|
|
|
|
|
|
|
); |
27
|
0
|
|
|
|
|
|
$args{_site_iterator} = 0; |
28
|
0
|
|
|
|
|
|
return bless \%args, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub PCI_register { |
32
|
0
|
|
|
0
|
0
|
|
my ( $self, $irc ) = @_; |
33
|
0
|
|
|
|
|
|
$self->{irc} = $irc; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$irc->plugin_register( $self, 'USER', qw(privmsg notice) ); |
36
|
0
|
|
|
|
|
|
$irc->{session_id} = POE::Session->create( |
37
|
|
|
|
|
|
|
object_states => [ |
38
|
|
|
|
|
|
|
$self => [ qw(_start _shutdown _paste_it _pasted) ], |
39
|
|
|
|
|
|
|
], |
40
|
|
|
|
|
|
|
)->ID; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _start { |
46
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[KERNEL, OBJECT]; |
47
|
0
|
|
|
|
|
|
$self->{session_id} = $_[SESSION]->ID; |
48
|
0
|
|
|
|
|
|
$kernel->refcount_increment( $self->{session_id} => __PACKAGE__ ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->{poco} |
51
|
|
|
|
|
|
|
= POE::Component::WWW::Pastebin::Bot::Pastebot::Create->spawn( |
52
|
|
|
|
|
|
|
obj_args => { timeout => $self->{timeout} }, |
53
|
|
|
|
|
|
|
debug => $self->{debug}, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
0
|
|
sub U_privmsg { shift->_process( @_ ); } |
58
|
0
|
|
|
0
|
0
|
|
sub U_notice { shift->_process( @_ ); } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _process { |
61
|
0
|
|
|
0
|
|
|
my ( $self, $irc, $out_ref ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my ( $pre_text, $to_paste ) = split /\Q$self->{trigger}/, $$out_ref, 2; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
0
|
|
|
|
if ( defined $to_paste and length $to_paste ) { |
66
|
0
|
|
|
|
|
|
$poe_kernel->post( |
67
|
|
|
|
|
|
|
$self->{session_id} => _paste_it => $pre_text, $to_paste, 0 |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return PCI_EAT_ALL; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return PCI_EAT_NONE; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _paste_it { |
77
|
0
|
|
|
0
|
|
|
my ( $self, $pre_text, $to_paste, $try ) = @_[ OBJECT, ARG0..$#_]; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$self->{_site_iterator} = 0 |
80
|
0
|
0
|
|
|
|
|
if $#{ $self->{pastebins} } < ++$self->{_site_iterator}; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->{poco}->paste( { |
83
|
|
|
|
|
|
|
site => $self->{pastebins}[ $self->{_site_iterator} ], |
84
|
|
|
|
|
|
|
event => '_pasted', |
85
|
|
|
|
|
|
|
content => $to_paste, |
86
|
|
|
|
|
|
|
_pre => $pre_text, |
87
|
|
|
|
|
|
|
_try => $try, |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _post_irc_message { |
93
|
0
|
|
|
0
|
|
|
my ( $self, $message ) = @_; |
94
|
0
|
|
|
|
|
|
$poe_kernel->post( $self->{irc} => quote => $message ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _pasted { |
98
|
0
|
|
|
0
|
|
|
my ( $self, $in_ref ) = @_[OBJECT, ARG0]; |
99
|
0
|
0
|
|
|
|
|
if ( $in_ref->{error} ) { |
100
|
0
|
0
|
|
|
|
|
$self->{debug} and carp "Paster error: $in_ref->{error}"; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if ( ++$in_ref->{_try} > $self->{max_tries} ) { |
103
|
0
|
|
|
|
|
|
$self->_post_irc_message("$in_ref->{_pre} [paster error]"); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
0
|
|
|
|
|
|
$poe_kernel->post( |
107
|
|
|
|
|
|
|
$self->{session_id} => _paste_it => |
108
|
|
|
|
|
|
|
@$in_ref{ qw(_pre content _try) } |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else { |
113
|
0
|
0
|
|
|
|
|
$self->{debug} and carp "Pasted, got uri $in_ref->{uri}"; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$self->_post_irc_message( "$in_ref->{_pre}$in_ref->{uri}" ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub PCI_unregister { |
120
|
0
|
|
|
0
|
0
|
|
my ( $self, $irc ) = @_; |
121
|
0
|
|
|
|
|
|
$poe_kernel->call( $self->{session_id} => '_shutdown' ); |
122
|
0
|
|
|
|
|
|
delete $self->{irc}; |
123
|
0
|
|
|
|
|
|
return 1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _shutdown { |
127
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[KERNEL, OBJECT]; |
128
|
0
|
|
|
|
|
|
$self->{poco}->shutdown; |
129
|
0
|
|
|
|
|
|
$kernel->alarm_remove_all; |
130
|
0
|
|
|
|
|
|
$kernel->refcount_decremenet( $self->{session_id} => __PACKAGE__ ); |
131
|
0
|
|
|
|
|
|
return; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
__END__ |