blib/lib/Horris/Connection/Plugin/Hit.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 57 CC 7 SCAR 28.9
CC
7
Cov
0%
irc_privmsg
20.0
on_privatemsg
20.0
BEGIN
2.0
CRAP 18.0
1 package Horris::Connection::Plugin::Hit;
2 # ABSTRACT: Dis(디스) Plugin on Horris
3  
4  
5 use Moose;
6 extends 'Horris::Connection::Plugin';
7 with 'MooseX::Role::Pluggable::Plugin';
8  
9 has texts => (
10 is => 'ro',
11 isa => 'ArrayRef',
12 );
13  
14 sub irc_privmsg {
15 my ($self, $message) = @_;
16 my $msg = $message->message;
17 my $botname = $self->connection->nickname;
18  
19 my ($output, $nick, $typed);
20 if (($nick, $typed) = $msg =~ m/^(\w+)\S*\s+껒$/i) {
21 $output = $message->nickname . ': ';
22 $output .= sprintf("%s - %s", 'ㅁㅁ?', 'http://tinyurl.com/5t3ew8t');
23 } elsif (($nick, $typed) = $msg =~ m/^$botname\S*\s+[(:?dis|hit)]+\s+(\w+)\s*(.*)$/i) {
24 $output = $nick . ': ';
25 $output .= $typed eq '' ? $self->texts->[int(rand(scalar @{ $self->texts }))] : $typed;
26 } else {
27 return $self->pass;
28 }
29  
30 $self->connection->irc_privmsg({
31 channel => $message->channel,
32 message => $output
33 });
34  
35 return $self->pass;
36 }
37  
38 sub on_privatemsg {
39 my ($self, $nick, $message) = @_;
40 my $msg = $message->message;
41 if (my ($nick, $typed) = $msg =~ m/^[(:?dis|hit)]+\s+(\w+)\s*(.*)$/i) {
42 my $output = $nick . ': ';
43 $output .= $typed eq '' ? $self->texts->[int(rand(scalar @{ $self->texts }))] : $typed;
44 my %channel_list = %{ $self->connection->irc->channel_list };
45 for my $channel (keys %channel_list) {
46 if (grep { m/$nick/ } keys %{ $channel_list{$channel} }) {
47 $self->connection->irc_privmsg({
48 channel => $channel,
49 message => $output
50 });
51 }
52 }
53 }
54 return $self->pass;
55 }
56  
57 __PACKAGE__->meta->make_immutable;
58  
59 1;
60  
61 __END__