File Coverage

blib/lib/Bot/IRC/Seen.pm
Criterion Covered Total %
statement 17 25 68.0
branch 0 2 0.0
condition n/a
subroutine 5 7 71.4
pod 0 1 0.0
total 22 35 62.8


line stmt bran cond sub pod time code
1             # ABSTRACT: Bot::IRC track when and where users were last seen
2              
3             use 5.014;
4 1     1   1823 use exact;
  1         4  
5 1     1   19  
  1         2  
  1         5  
6             use DateTime;
7 1     1   1288 use DateTime::Format::Human::Duration;
  1         353109  
  1         45  
8 1     1   495  
  1         1548  
  1         296  
9             our $VERSION = '1.39'; # VERSION
10              
11             my ($bot) = @_;
12             $bot->load('Store');
13 1     1 0 5106  
14 1         5 $bot->hook(
15             {
16             private => 0,
17             command => 'PRIVMSG',
18             },
19             sub {
20             my ( $bot, $in ) = @_;
21             $in->{time} = time;
22 0     0   0 $bot->store->set( lc( $in->{nick} ) => $in );
23 0         0 return;
24 0         0 },
25 0         0 );
26              
27 1         9 my $duration = DateTime::Format::Human::Duration->new;
28             $bot->hook(
29 1         21 {
30             to_me => 1,
31             text => qr/^seen\s+(?<nick>\S+)/i,
32             },
33             sub {
34             my ( $bot, $in, $m ) = @_;
35             my $seen = $bot->store->get( lc( $m->{nick} ) );
36 0     0   0  
37 0         0 $bot->reply_to(
38             ($seen)
39             ?
40             "$seen->{nick} was last seen in $seen->{forum} " .
41             $duration->format_duration_between(
42             map { DateTime->from_epoch( epoch => $_ ) } $seen->{time}, time
43             ) .
44 0         0 " ago saying: \"$seen->{text}\""
45 0 0       0 :
46             "Sorry. I haven't seen $m->{nick}."
47             );
48             },
49             );
50              
51 1         15 $bot->helps( seen => 'Tracks when and where people were last seen. Usage: seen <nick>.' );
52             }
53 1         14  
54             1;
55              
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =head1 NAME
62              
63             Bot::IRC::Seen - Bot::IRC track when and where users were last seen
64              
65             =head1 VERSION
66              
67             version 1.39
68              
69             =head1 SYNOPSIS
70              
71             use Bot::IRC;
72              
73             Bot::IRC->new(
74             connect => { server => 'irc.perl.org' },
75             plugins => ['Seen'],
76             )->run;
77              
78             =head1 DESCRIPTION
79              
80             This L<Bot::IRC> plugin instructs the bot to remember when and where users
81             were last seen and to report on this when asked. Commands include:
82              
83             =head2 seen <nick>
84              
85             Display last seen information for a given nick.
86              
87             =head2 SEE ALSO
88              
89             L<Bot::IRC>
90              
91             =for Pod::Coverage init
92              
93             =head1 AUTHOR
94              
95             Gryphon Shafer <gryphon@cpan.org>
96              
97             =head1 COPYRIGHT AND LICENSE
98              
99             This software is Copyright (c) 2016-2050 by Gryphon Shafer.
100              
101             This is free software, licensed under:
102              
103             The Artistic License 2.0 (GPL Compatible)
104              
105             =cut