| 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__ |