Work internally with UTF-8
[poe-component-irc-plugin-hello.git] / lib / POE / Component / IRC / Plugin / Hello.pm
CommitLineData
d4df4450 1package POE::Component::IRC::Plugin::Hello;
29280d6c
MG
2
3use 5.014000;
4use strict;
5use warnings;
128b9459
MG
6use utf8;
7use Encode qw/encode decode/;
8
7dc26b47 9our $VERSION = '0.001002';
29280d6c
MG
10
11use List::Util qw/first/;
12
13use IRC::Utils qw/parse_user/;
14use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
15
16sub new {
9e1acbcb
MG
17 my $class = shift;
18 my $self = {
7ca2bb7c
MG
19 greetings => [
20 qw/privet hello salut salutari neata neaţa neața neatza
21 hola hey hi bonjour wassup sup hallo chikmaa
22 tungjatjeta parev salam namaskaar mingalarba ahoy
23 saluton allo moin aloha namaste shalom ciào ciao servus
24 salve ave merhaba witaj hei hola selam sawubona/,
25 "what's up", 'que tal', 'こんにちは', '你好', 'ni hao'],
9e1acbcb
MG
26 @_
27 };
29280d6c 28
9e1acbcb 29 bless $self, $class
29280d6c
MG
30}
31
32sub PCI_register {
9e1acbcb
MG
33 my ($self, $irc) = @_;
34 $irc->plugin_register($self, SERVER => qw/public/);
35 1
29280d6c
MG
36}
37
38sub PCI_unregister { 1 }
39
40sub S_public{
9e1acbcb
MG
41 my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
42 my $nick = parse_user $$rfullname;
43 my $mynick = $irc->nick_name;
128b9459 44 my $message = decode 'UTF-8', $$rmessage;
9e1acbcb
MG
45 my @hello = @{$self->{greetings}};
46
128b9459
MG
47 my $match = first { $message =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*[.!]?\s*$/i } @hello;
48 my $randhello = encode 'UTF-8', $hello[int rand $#hello];
49 $irc->yield(privmsg => $$rchannels->[0] => "$randhello, $nick") if $match;
9e1acbcb 50 PCI_EAT_NONE
29280d6c
MG
51}
52
531;
54__END__
55
56=head1 NAME
57
58POE::Component::IRC::Plugin::Hello - PoCo-IRC plugin that says hello
59
60=head1 SYNOPSIS
61
62 use POE::Component::IRC::Plugin::Hello;
63
64 my $irc = POE::Component::IRC::State->spawn(...);
65 $irc->plugin_add(Hello => POE::Component::IRC::Plugin::Hello->new);
66
67=head1 DESCRIPTION
68
69POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back
70who greet him or a channel in public. It knows how to say hello in several
71languages, and greets people in a randomly chosen language.
72
73The list of greetings is configurable by the plugin user.
74
75=head1 SEE ALSO
76
77L<POE::Component::IRC::Plugin>
78
79=head1 AUTHOR
80
81Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
82
83=head1 COPYRIGHT AND LICENSE
84
85Copyright (C) 2013 by Marius Gavrilescu
86
87This library is free software; you can redistribute it and/or modify
88it under the same terms as Perl itself, either Perl version 5.14.2 or,
89at your option, any later version of Perl 5 you may have available.
90
91
92=cut
This page took 0.017803 seconds and 4 git commands to generate.