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