IRC/Seen.pm

filter: Statementstmt 70.3% 19 / 27 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 1 totaltotal 64.8% 24 / 37 CC 2 SCAR 8.8
CC
2
Cov
66%
__ANON__
6.0
__ANON__
2.0
init
1.2
CRAP 2.4
« IRC/Math.pm ↑ Summary IRC/Convert.pm »
1 package Bot::IRC::Seen;
2 # ABSTRACT: Bot::IRC track when and where users were last seen
3  
4 2 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use exact;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use DateTime::Format::Human::Duration;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '1.49'; # VERSION
11  
12 1 ▶sub init {
Subroutine init: called CC=1 SCAR=2.2
Pod undocumented
13 1 my ($bot) = @_;
14 1 $bot->load('Store');
15  
16 $bot->hook(
17 {
18 private => 0,
19 command => 'PRIVMSG',
20 },
21 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 my ( $bot, $in ) = @_;
23 0 $in->{time} = time;
24 0 $bot->store->set( lc( $in->{nick} ) => $in );
25 0 return;
26 },
27 1 );
28  
29 1 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 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
36 0 my ( $bot, $in, $m ) = @_;
37 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 map { DateTime->from_epoch( epoch => $_ ) } $seen->{time}, time
45 0 ▶ ) .
Branch: 1 branch
BranchTrueFalseTotal
$seen ? : 0 0 0
46 " ago saying: \"$seen->{text}\""
47 :
48 "Sorry. I haven't seen $m->{nick}."
49 );
50 },
51 1 );
52  
53 1 $bot->helps( seen => 'Tracks when and where people were last seen. Usage: seen <nick>.' );
54 }
55  
56 2 1;
57  
58 __END__
« IRC/Math.pm ↑ Summary IRC/Convert.pm »