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