Reformat list of greetings
[poe-component-irc-plugin-hello.git] / lib / POE / Component / IRC / Plugin / Hello.pm
... / ...
CommitLineData
1package POE::Component::IRC::Plugin::Hello;
2
3use 5.014000;
4use strict;
5use warnings;
6our $VERSION = '0.001002';
7
8use List::Util qw/first/;
9
10use IRC::Utils qw/parse_user/;
11use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/;
12
13sub 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
29sub PCI_register {
30 my ($self, $irc) = @_;
31 $irc->plugin_register($self, SERVER => qw/public/);
32 1
33}
34
35sub PCI_unregister { 1 }
36
37sub 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
481;
49__END__
50
51=head1 NAME
52
53POE::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
64POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back
65who greet him or a channel in public. It knows how to say hello in several
66languages, and greets people in a randomly chosen language.
67
68The list of greetings is configurable by the plugin user.
69
70=head1 SEE ALSO
71
72L<POE::Component::IRC::Plugin>
73
74=head1 AUTHOR
75
76Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
77
78=head1 COPYRIGHT AND LICENSE
79
80Copyright (C) 2013 by Marius Gavrilescu
81
82This library is free software; you can redistribute it and/or modify
83it under the same terms as Perl itself, either Perl version 5.14.2 or,
84at your option, any later version of Perl 5 you may have available.
85
86
87=cut
This page took 0.008654 seconds and 4 git commands to generate.