]> iEval git - poe-component-irc-plugin-hello.git/blob - Hello.pm
aff114e0475626db4ac54e866fc55c7ee1117b90
[poe-component-irc-plugin-hello.git] / 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 => [qw/privet hello salut salutari neata neaţa neața neatza hola hey hi bonjour 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', 'こんにちは', '你好', 'ni hao'],
17 @_
18 };
19
20 bless $self, $class
21 }
22
23 sub PCI_register {
24 my ($self, $irc) = @_;
25 $irc->plugin_register($self, SERVER => qw/public/);
26 1
27 }
28
29 sub PCI_unregister { 1 }
30
31 sub S_public{
32 my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_;
33 my $nick = parse_user $$rfullname;
34 my $mynick = $irc->nick_name;
35 my @hello = @{$self->{greetings}};
36
37 my $match = first { $$rmessage =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*[.!]?\s*$/i } @hello;
38 $irc->yield(privmsg => $$rchannels->[0] => $hello[int rand $#hello].", $nick") if $match;
39 PCI_EAT_NONE
40 }
41
42 1;
43 __END__
44
45 =head1 NAME
46
47 POE::Component::IRC::Plugin::Hello - PoCo-IRC plugin that says hello
48
49 =head1 SYNOPSIS
50
51 use POE::Component::IRC::Plugin::Hello;
52
53 my $irc = POE::Component::IRC::State->spawn(...);
54 $irc->plugin_add(Hello => POE::Component::IRC::Plugin::Hello->new);
55
56 =head1 DESCRIPTION
57
58 POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back
59 who greet him or a channel in public. It knows how to say hello in several
60 languages, and greets people in a randomly chosen language.
61
62 The list of greetings is configurable by the plugin user.
63
64 =head1 SEE ALSO
65
66 L<POE::Component::IRC::Plugin>
67
68 =head1 AUTHOR
69
70 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
71
72 =head1 COPYRIGHT AND LICENSE
73
74 Copyright (C) 2013 by Marius Gavrilescu
75
76 This library is free software; you can redistribute it and/or modify
77 it under the same terms as Perl itself, either Perl version 5.14.2 or,
78 at your option, any later version of Perl 5 you may have available.
79
80
81 =cut
This page took 0.044778 seconds and 3 git commands to generate.