Work internally with UTF-8
[poe-component-irc-plugin-hello.git] / lib / POE / Component / IRC / Plugin / Hello.pm
index aff114e0475626db4ac54e866fc55c7ee1117b90..aa3380609bb82916ca4a87831311b8ac597eef29 100644 (file)
@@ -3,6 +3,9 @@ package POE::Component::IRC::Plugin::Hello;
 use 5.014000;
 use strict;
 use warnings;
+use utf8;
+use Encode qw/encode decode/;
+
 our $VERSION = '0.001002';
 
 use List::Util qw/first/;
@@ -13,7 +16,13 @@ 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 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/, "what's up", 'que tal', 'こんにちは', '你好', 'ni hao'],
+               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/,
+                       "what's up", 'que tal', 'こんにちは', '你好', 'ni hao'],
                @_
        };
 
@@ -32,10 +41,12 @@ sub S_public{
        my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
        my $nick = parse_user $$rfullname;
        my $mynick = $irc->nick_name;
+       my $message = decode 'UTF-8', $$rmessage;
        my @hello = @{$self->{greetings}};
 
-       my $match = first { $$rmessage =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*[.!]?\s*$/i } @hello;
-       $irc->yield(privmsg => $$rchannels->[0] => $hello[int rand $#hello].", $nick") if $match;
+       my $match = first { $message =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*[.!]?\s*$/i } @hello;
+       my $randhello = encode 'UTF-8', $hello[int rand $#hello];
+       $irc->yield(privmsg => $$rchannels->[0] => "$randhello, $nick") if $match;
        PCI_EAT_NONE
 }
 
This page took 0.010307 seconds and 4 git commands to generate.