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