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