]> iEval git - poe-component-irc-plugin-hello.git/blobdiff - lib/POE/Component/IRC/Plugin/Hello.pm
Add perlcritic tests and make code comply
[poe-component-irc-plugin-hello.git] / lib / POE / Component / IRC / Plugin / Hello.pm
index 1820f841773566d67faee8abba35797e5d62bf02..9b03e4713061d343b320b863887c80bfe2322e2e 100644 (file)
@@ -1,8 +1,13 @@
-package POE::Component::IRC::Plugin::Hello 0.001;
+package POE::Component::IRC::Plugin::Hello;
 
 use 5.014000;
 use strict;
 use warnings;
+use utf8;
+use Encode qw/encode decode/;
+use Unicode::Normalize qw/NFC/;
+
+our $VERSION = '0.001002';
 
 use List::Util qw/first/;
 
@@ -10,32 +15,42 @@ use IRC::Utils qw/parse_user/;
 use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
 
 sub new {
-  my $class = shift;
-  my $self = {
-       greetings => [qw/privet hello salut salutari neata neaţa hola hey hi bonjour niihau wassup sup hallo chikmaa tungjatjeta parev salam namaskaar mingalarba ahoy saluton allo moin aloha namaste shalom ciào ciao servus salve ave merhaba witaj hei hola selam sawubona/, "what's up", 'que tal', 'こんにちは', '你好'],
-       @_
-  };
-
-  bless $self, $class
+       my $class = shift;
+       my $self = {
+               greetings => [
+                       qw/privet hello salut salutari neata neaţa neața neatza
+                          hola hey hi bonjour wassup sup hallo chikmaa
+                          tungjatjeta parev salam namaskaar mingalarba ahoy
+                          saluton allo moin aloha namaste shalom ciào ciao servus
+                          salve ave merhaba witaj hei hola selam sawubona
+                          geodemorgen hoi καλημέρα/,
+                       'what\'s up', 'que tal', 'こんにちは', '你好', 'ni hao',
+                       'добро јутро', 'γεια σας', 'bom dia', 'hyvää huomenta'],
+               @_
+       };
+
+       bless $self, $class
 }
 
 sub PCI_register {
-  my ($self, $irc) = @_;
-  $irc->plugin_register($self, SERVER => qw/public/);
-  1
+       my ($self, $irc) = @_;
+       $irc->plugin_register($self, SERVER => qw/public/);
+       1
 }
 
 sub PCI_unregister { 1 }
 
 sub S_public{
-  my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
-  my $nick = parse_user $$rfullname;
-  my $mynick = $irc->nick_name;
-  my @hello = @{$self->{greetings}};
-
-  my $match = first { $$rmessage =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*$/i } @hello;
-  $irc->yield(privmsg => $$rchannels->[0] => $hello[int rand $#hello].", $nick") if $match;
-  PCI_EAT_NONE
+       my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
+       my $nick = parse_user $$rfullname;
+       my $mynick = $irc->nick_name;
+       my $message = NFC decode 'UTF-8', $$rmessage;
+       my @hello = @{$self->{greetings}};
+
+       my $match = first { $message =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*[.!]?\s*$/is } @hello;
+       my $randhello = encode 'UTF-8', $hello[int rand $#hello];
+       $irc->yield(privmsg => $$rchannels->[0] => "$randhello, $nick") if $match;
+       PCI_EAT_NONE
 }
 
 1;
This page took 0.01973 seconds and 4 git commands to generate.