From b9ec22f502ee343b5efba2624b4ae06d1239881e Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sun, 30 Aug 2015 00:33:49 +0300 Subject: [PATCH] Fix behaviour on privmsg and add tests for privmsg --- lib/POE/Component/IRC/Plugin/Seen.pm | 2 +- t/POE-Component-IRC-Plugin-Seen.t | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) 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; -- 2.39.2