line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::IPMessenger::Bot::EventHandler; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
14
|
use base qw/Net::IPMessenger::RecvEventHandler/; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
110
|
|
7
|
1
|
|
|
1
|
|
938
|
use Encode qw(); |
|
1
|
|
|
|
|
19641
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
9
|
use IO::Socket; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
9
|
1
|
|
|
1
|
|
1732
|
use Term::ANSIColor qw(:constants); |
|
1
|
|
|
|
|
7873
|
|
|
1
|
|
|
|
|
1487
|
|
10
|
|
|
|
|
|
|
$Term::ANSIColor::AUTORESET = 1; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
3
|
|
|
3
|
1
|
11
|
my ($class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
17
|
my $self = shift->SUPER::new(); |
16
|
|
|
|
|
|
|
|
17
|
3
|
100
|
|
|
|
44
|
$self->{handler} |
18
|
|
|
|
|
|
|
= ( ref $args{handler} eq 'ARRAY' ) |
19
|
|
|
|
|
|
|
? $args{handler} |
20
|
|
|
|
|
|
|
: [ qr// => $args{handler} ]; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
10
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub debug { |
26
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $them, $user ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
my $peeraddr = inet_ntoa( $them->socket->peeraddr ); |
29
|
0
|
|
|
|
|
0
|
my $peerport = $them->socket->peerport; |
30
|
0
|
|
|
|
|
0
|
my $command = $them->messagecommand( $user->command ); |
31
|
0
|
|
|
|
|
0
|
my $modename = $command->modename; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
print CYAN "Received $modename from [$peeraddr:$peerport]"; |
34
|
0
|
|
|
|
|
0
|
print RESET "\n"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub handle { |
38
|
5
|
|
|
5
|
0
|
12
|
my ( $self, $user ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
5
|
50
|
|
|
|
21
|
return unless ( $self->{handler} ); |
41
|
|
|
|
|
|
|
|
42
|
5
|
|
|
|
|
19
|
my $msg = Encode::decode( 'shiftjis', $user->get_message ); |
43
|
5
|
|
|
|
|
13581
|
my $res; |
44
|
|
|
|
|
|
|
|
45
|
5
|
|
|
|
|
12
|
for ( my $i = 0; $i < @{ $self->{handler} }; $i += 2 ) { |
|
8
|
|
|
|
|
34
|
|
46
|
8
|
|
|
|
|
17
|
my $regex = $self->{handler}->[$i]; |
47
|
8
|
|
|
|
|
19
|
my $handler = $self->{handler}->[ $i + 1 ]; |
48
|
|
|
|
|
|
|
|
49
|
8
|
100
|
|
|
|
83
|
if ( $msg =~ $regex ) { |
50
|
5
|
|
|
|
|
20
|
$res = $handler->($user); |
51
|
5
|
|
|
|
|
122
|
last; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
25
|
return $res; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub SENDMSG { |
59
|
5
|
|
|
5
|
1
|
13216
|
my ($self, $ipmsg, $user ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
19
|
$ipmsg->message([]); # clear cached-messages |
62
|
5
|
|
|
|
|
47
|
$self->SUPER::SENDMSG($ipmsg, $user); |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
470
|
my $command = $ipmsg->messagecommand( $user->command ); |
65
|
5
|
100
|
|
|
|
112
|
if ( $command->get_readcheck() ) { |
66
|
1
|
|
|
|
|
47
|
$ipmsg->send( |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
command => $ipmsg->messagecommand('READMSG'), |
69
|
|
|
|
|
|
|
option => $user->packet_num, |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
5
|
100
|
|
|
|
323
|
if ( my $res = $self->handle($user) ) { |
75
|
4
|
|
|
|
|
28
|
$ipmsg->send( |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
command => $ipmsg->messagecommand('SENDMSG'), |
78
|
|
|
|
|
|
|
option => Encode::encode( 'shiftjis', $res ), |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |