Add several greetings suggested by Joost van Baal-Ilić
[poe-component-irc-plugin-hello.git] / lib / POE / Component / IRC / Plugin / Hello.pm
1 package POE::Component::IRC::Plugin::Hello;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6 use utf8;
7 use Encode qw/encode decode/;
8
9 our $VERSION = '0.001002';
10
11 use List::Util qw/first/;
12
13 use IRC::Utils qw/parse_user/;
14 use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
15
16 sub new {
17 my $class = shift;
18 my $self = {
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 geodemorgen hoi καλημέρα/,
26 "what's up", 'que tal', 'こんにちは', '你好', 'ni hao',
27 'добро јутро', 'γεια σας', 'bom dia', 'hyvää huomenta'],
28 @_
29 };
30
31 bless $self, $class
32 }
33
34 sub PCI_register {
35 my ($self, $irc) = @_;
36 $irc->plugin_register($self, SERVER => qw/public/);
37 1
38 }
39
40 sub PCI_unregister { 1 }
41
42 sub S_public{
43 my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
44 my $nick = parse_user $$rfullname;
45 my $mynick = $irc->nick_name;
46 my $message = decode 'UTF-8', $$rmessage;
47 my @hello = @{$self->{greetings}};
48
49 my $match = first { $message =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*[.!]?\s*$/i } @hello;
50 my $randhello = encode 'UTF-8', $hello[int rand $#hello];
51 $irc->yield(privmsg => $$rchannels->[0] => "$randhello, $nick") if $match;
52 PCI_EAT_NONE
53 }
54
55 1;
56 __END__
57
58 =head1 NAME
59
60 POE::Component::IRC::Plugin::Hello - PoCo-IRC plugin that says hello
61
62 =head1 SYNOPSIS
63
64 use POE::Component::IRC::Plugin::Hello;
65
66 my $irc = POE::Component::IRC::State->spawn(...);
67 $irc->plugin_add(Hello => POE::Component::IRC::Plugin::Hello->new);
68
69 =head1 DESCRIPTION
70
71 POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back
72 who greet him or a channel in public. It knows how to say hello in several
73 languages, and greets people in a randomly chosen language.
74
75 The list of greetings is configurable by the plugin user.
76
77 =head1 SEE ALSO
78
79 L<POE::Component::IRC::Plugin>
80
81 =head1 AUTHOR
82
83 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
84
85 =head1 COPYRIGHT AND LICENSE
86
87 Copyright (C) 2013 by Marius Gavrilescu
88
89 This library is free software; you can redistribute it and/or modify
90 it under the same terms as Perl itself, either Perl version 5.14.2 or,
91 at your option, any later version of Perl 5 you may have available.
92
93
94 =cut
This page took 0.024614 seconds and 4 git commands to generate.