From 29280d6c20a4abbb4a2f2efc421e21c88b3cb9ca Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 11 Jul 2013 23:30:37 +0300 Subject: [PATCH] Initial release --- Changes | 2 + MANIFEST | 6 ++ Makefile.PL | 20 +++++++ README | 31 +++++++++++ lib/POE/Component/IRC/Plugin/Hello.pm | 80 +++++++++++++++++++++++++++ t/POE-Component-IRC-Plugin-Hello.t | 45 +++++++++++++++ 6 files changed, 184 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/POE/Component/IRC/Plugin/Hello.pm create mode 100644 t/POE-Component-IRC-Plugin-Hello.t diff --git a/Changes b/Changes new file mode 100644 index 0000000..48e3ab4 --- /dev/null +++ b/Changes @@ -0,0 +1,2 @@ +POE::Component::IRC::Plugin::Hello (0.001) 11 Jul 2013 + * Initial release \ No newline at end of file diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..ce246a4 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,6 @@ +Changes +Makefile.PL +MANIFEST +README +t/POE-Component-IRC-Plugin-Hello.t +lib/POE/Component/IRC/Plugin/Hello.pm diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..19cc118 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,20 @@ +use 5.014000; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'POE::Component::IRC::Plugin::Hello', + VERSION_FROM => 'lib/POE/Component/IRC/Plugin/Hello.pm', + ABSTRACT_FROM => 'lib/POE/Component/IRC/Plugin/Hello.pm', + AUTHOR => 'Marius Gavrilescu ', + MIN_PERL_VERSION => 5.014000, + LICENSE => 'perl', + SIGN => 1, + PREREQ_PM => { + 'List::Util' => 0, + 'IRC::Utils' => 0, + 'POE::Component::IRC::Plugin' => 0, + }, + BUILD_REQUIRES => { + 'Test::MockObject' => 1.09, + }, +); diff --git a/README b/README new file mode 100644 index 0000000..b35cfa4 --- /dev/null +++ b/README @@ -0,0 +1,31 @@ +POE-Component-IRC-Plugin-Hello version 0.001 +============================================ + +POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back +who greet him or a channel in public. It knows how to say hello in several +languages, and greets people in a randomly chosen language. + +INSTALLATION + +To install this module type the following: + + perl Makefile.PL + make + make test + make install + +DEPENDENCIES + +This module requires these other modules and libraries: + +* List::Util +* IRC::Utils +* POE::Component::IRC::Plugin + +COPYRIGHT AND LICENCE + +Copyright (C) 2013 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.14.2 or, +at your option, any later version of Perl 5 you may have available. diff --git a/lib/POE/Component/IRC/Plugin/Hello.pm b/lib/POE/Component/IRC/Plugin/Hello.pm new file mode 100644 index 0000000..1820f84 --- /dev/null +++ b/lib/POE/Component/IRC/Plugin/Hello.pm @@ -0,0 +1,80 @@ +package POE::Component::IRC::Plugin::Hello 0.001; + +use 5.014000; +use strict; +use warnings; + +use List::Util qw/first/; + +use IRC::Utils qw/parse_user/; +use POE::Component::IRC::Plugin qw/PCI_EAT_NONE/; + +sub new { + my $class = shift; + my $self = { + 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', 'こんにちは', '你好'], + @_ + }; + + bless $self, $class +} + +sub PCI_register { + my ($self, $irc) = @_; + $irc->plugin_register($self, SERVER => qw/public/); + 1 +} + +sub PCI_unregister { 1 } + +sub S_public{ + my ($self, $irc, $rfullname, $rchannels, $rmessage) = @_; + my $nick = parse_user $$rfullname; + my $mynick = $irc->nick_name; + my @hello = @{$self->{greetings}}; + + my $match = first { $$rmessage =~ /^\s*(?:$mynick(?:)[:,])?\s*$_\s*$/i } @hello; + $irc->yield(privmsg => $$rchannels->[0] => $hello[int rand $#hello].", $nick") if $match; + PCI_EAT_NONE +} + +1; +__END__ + +=head1 NAME + +POE::Component::IRC::Plugin::Hello - PoCo-IRC plugin that says hello + +=head1 SYNOPSIS + + use POE::Component::IRC::Plugin::Hello; + + my $irc = POE::Component::IRC::State->spawn(...); + $irc->plugin_add(Hello => POE::Component::IRC::Plugin::Hello->new); + +=head1 DESCRIPTION + +POE::Component::IRC::Plugin::Hello is a PoCo-IRC plugin that greets back +who greet him or a channel in public. It knows how to say hello in several +languages, and greets people in a randomly chosen language. + +The list of greetings is configurable by the plugin user. + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2013 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.14.2 or, +at your option, any later version of Perl 5 you may have available. + + +=cut diff --git a/t/POE-Component-IRC-Plugin-Hello.t b/t/POE-Component-IRC-Plugin-Hello.t new file mode 100644 index 0000000..ebb2ef5 --- /dev/null +++ b/t/POE-Component-IRC-Plugin-Hello.t @@ -0,0 +1,45 @@ +use v5.14; +use strict; +use warnings; + +use Test::More tests => 15; +use Test::MockObject; + +BEGIN { use_ok('POE::Component::IRC::Plugin::Hello') }; + +# Variable setup +my $hello_sent; + +my $mockirc = Test::MockObject->new; +$mockirc->mock(yield => sub { $hello_sent = 1 })->set_always(nick_name => 'hellobot'); + +my $self = POE::Component::IRC::Plugin::Hello->new; +my $channels = [ '#chan' ]; + +# Sub setup +sub runtest{ + my ($message, $expect, $comment) = @_; + $hello_sent=0; + $self->S_public($mockirc, \'mgv!marius@ieval.ro', \$channels, \$message); + ok($hello_sent == $expect, $comment) +} + +#Tests +runtest 'privet', 1, 'simple privet'; +runtest 'PrIvEt', 1, 'privet in mixed case'; +runtest ' privet ', 1, 'privet with spaces'; +runtest 'hellobot: privet', 1, 'addressed privet'; +runtest 'hellobot: privet ', 1, 'addressed privet with spaces'; +runtest 'ahoy', 1, 'ahoy'; +runtest 'namaste', 1, 'namaste'; +runtest 'neaţa', 1, 'neaţa (UTF-8 test)'; +runtest 'こんにちは', 1, 'こんにちは (another UTF-8 test)'; + +runtest 'salu', 0, 'salu (misspelling)'; +runtest 'hii', 0, 'hii (misspelling)'; +runtest 'neaţa mgv', 0, 'neaţa mgv (valid greeting with garbage after it)'; + +$self = POE::Component::IRC::Plugin::Hello->new(greetings => ['sayonara']); + +runtest 'privet', 0, 'custom greetings - privet'; +runtest ' sayonara ', 1, 'custom greetings - sayonara'; -- 2.39.2