From: Marius Gavrilescu Date: Sat, 29 Aug 2015 21:33:49 +0000 (+0300) Subject: Fix behaviour on privmsg and add tests for privmsg X-Git-Tag: 0.001002~2 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=b9ec22f502ee343b5efba2624b4ae06d1239881e;p=poe-component-irc-plugin-seen.git Fix behaviour on privmsg and add tests for privmsg --- diff --git a/lib/POE/Component/IRC/Plugin/Seen.pm b/lib/POE/Component/IRC/Plugin/Seen.pm index cc2f76d..a8f7d80 100644 --- a/lib/POE/Component/IRC/Plugin/Seen.pm +++ b/lib/POE/Component/IRC/Plugin/Seen.pm @@ -83,7 +83,7 @@ sub S_msg { my ($self, $irc, $rfullname, $rtargets, $rmessage) = @_; my $nick = parse_user $$rfullname; - seen $self, $irc, $$rmessage, $$rtargets->[0], $nick if $$rmessage =~ /^\s*!?seen\s+([^ ]+)/ + seen $self, $irc, $1, $$rtargets->[0], $nick if $$rmessage =~ /^\s*!?seen\s+([^ ]+)/ } 1; diff --git a/t/POE-Component-IRC-Plugin-Seen.t b/t/POE-Component-IRC-Plugin-Seen.t index fdf55ae..607e5f6 100644 --- a/t/POE-Component-IRC-Plugin-Seen.t +++ b/t/POE-Component-IRC-Plugin-Seen.t @@ -2,7 +2,7 @@ use v5.14; use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 10; use Test::MockObject; BEGIN { *CORE::GLOBAL::localtime = sub { 'now' } } @@ -21,9 +21,10 @@ my $rmgv = \'mgv!marius@ieval.ro'; # Sub setup sub runtest{ - my ($message, $expect, $comment) = @_; + my ($message, $expect, $comment, $privmsg) = @_; undef $last_msg; - $self->S_public($mockirc, $rmgv, \$channels, \$message); + $self->S_public($mockirc, $rmgv, \$channels, \$message) unless $privmsg; + $self->S_msg($mockirc, $rmgv, \$channels, \$message) if $privmsg; is($last_msg, $expect, $comment) } @@ -43,3 +44,7 @@ $self->S_part($mockirc, $rmgv, \'#chan', \'buh-bye'); runtest 'bot: seen mgv', "I last saw mgv now parting #chan with message 'buh-bye'", 'part with message'; runtest 'bot: seen asd', "I haven't seen asd", "haven't seen"; + +# Private messages +runtest 'seen asd', "I haven't seen asd", "haven't seen", 1; +runtest ' !seen asd', "I haven't seen asd", "haven't seen", 1;