| 1 | package Horris::Connection::Plugin::Kspell; | ||||||||||
| 2 | # ABSTRACT: KoreanSpeller Plugin on Horris | ||||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Encode qw/encode decode/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use WebService::KoreanSpeller; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | extends 'Horris::Connection::Plugin'; | |||||||||
| 9 | 1 | with 'MooseX::Role::Pluggable::Plugin'; | |||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub irc_privmsg { | ||||||||
|
Subroutine
irc_privmsg: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 12 | 0 | my ($self, $message) = @_; | |||||||||
| 13 | 0 | my @msg = $self->_kspell($message); | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | return unless @msg; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | for (@msg) { | |||||||||
| 18 | 0 | $self->connection->irc_privmsg({ | |||||||||
| 19 | channel => $message->channel, | ||||||||||
| 20 | message => $_ | ||||||||||
| 21 | }); | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 0 | return $self->pass; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | sub _kspell { | ||||||||
|
Subroutine
_kspell: not called CC=3 SCAR=24.8
| |||||||||||
| 28 | 0 | my ($self, $message) = @_; | |||||||||
| 29 | 0 | my $raw = $message->message; | |||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | unless ($raw =~ m/^kspell/i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | return undef; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | $raw =~ s/^kspell[\S]*\s+//i; | |||||||||
| 36 | 0 | $raw = decode('utf8', $raw); | |||||||||
| 37 | 0 | my $checker = WebService::KoreanSpeller->new( text=> $raw ); | |||||||||
| 38 | 0 | my @results = $checker->spellcheck; | |||||||||
| 39 | 0 | my @correct; | |||||||||
| 40 | 0 | for my $item (@results) { | |||||||||
| 41 | 0 | push @correct, encode('utf8', $item->{incorrect} . ' -> ' . $item->{correct}); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | return @correct; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 48 | |||||||||||
| 49 | 1 | 1; | |||||||||
| 50 | |||||||||||
| 51 | __END__ | ||||||||||