blib/lib/Bot/Cobalt/Plugin/Games/Roulette.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 15 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 78 SCAR 34.0
CC
5
Cov
0%
execute
20.0
expire
6.0
new
2.0
CRAP 30.0
1 package Bot::Cobalt::Plugin::Games::Roulette;
2 $Bot::Cobalt::Plugin::Games::Roulette::VERSION = '0.021002';
3 use v5.10;
4 use strict; use warnings;
5  
6 use Bot::Cobalt;
7 use Bot::Cobalt::Utils qw/color/;
8  
9 sub new { bless +{}, shift }
10  
11 sub execute {
12 my ($self, $msg, $str) = @_;
13 my $cyls = 6;
14  
15 my $context = $msg->context;
16 my $nick = $msg->src_nick;
17  
18 $self->expire;
19  
20 if ( $str && index(lc($str), 'spin') == 0 ) {
21 ## clear loaded
22 delete $self->{$context}->{$nick};
23 return "Spun cylinders for ${nick}."
24 }
25  
26 my $loaded = $self->{$context}->{$nick}->{Loaded}
27 //= int rand($cyls);
28 $self->{$context}->{$nick}->{TS} //= time;
29  
30 if ($loaded == 0) {
31 delete $self->{$context}->{$nick};
32
33 my $irc = core->get_irc_obj($context);
34 my $bot = $irc->nick_name;
35 my $chan = $msg->channel;
36  
37 if ( $irc->is_channel_operator($chan, $bot)
38 || $irc->is_channel_admin($chan, $bot)
39 || $irc->is_channel_owner($chan, $bot) ) {
40 broadcast( 'kick', $context, $chan, $nick, "BANG!" );
41 return color('bold', "$nick did themselves in!")
42 }
43  
44 return color('bold', 'BANG!')." -- seeya $nick!"
45 }
46  
47  
48 --$self->{$context}->{$nick}->{Loaded};
49 return "${nick}: Click . . ."
50 }
51  
52 sub expire {
53 my ($self) = @_;
54 for my $context (keys %$self) {
55 for my $nick (keys %{ $self->{$context} }) {
56 delete $self->{$context}->{$nick}
57 if (time - $self->{$context}->{$nick}->{TS}) >= 600;
58 }
59 }
60 }
61  
62 1;
63 __END__