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

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 91 CC 5 SCAR 21.0
CC
5
Cov
0%
execute
20.0
expire
6.0
new
2.0
CRAP 8.2
1 package Bot::Cobalt::Plugin::Games::Roulette;
2 $Bot::Cobalt::Plugin::Games::Roulette::VERSION = '0.021003';
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 _suicide {
12 my ($nick) = @_;
13 my @ded = (
14 "$nick did themselves in!",
15 "$nick ended it all!",
16 "$nick splattered the wall!",
17 "$nick bit the big one!",
18 );
19 $ded[rand @ded]
20 }
21  
22 sub execute {
23 my ($self, $msg, $str) = @_;
24 my $cyls = 6;
25  
26 my $context = $msg->context;
27 my $nick = $msg->src_nick;
28  
29 $self->expire;
30  
31 if ( $str && index(lc($str), 'spin') == 0 ) {
32 ## clear loaded
33 delete $self->{$context}->{$nick};
34 return "Spun cylinders for ${nick}."
35 }
36  
37 my $loaded = $self->{$context}->{$nick}->{Loaded}
38 //= int rand($cyls);
39 $self->{$context}->{$nick}->{TS} //= time;
40  
41 if ($loaded == 0) {
42 delete $self->{$context}->{$nick};
43
44 my $irc = core->get_irc_obj($context);
45 my $bot = $irc->nick_name;
46 my $chan = $msg->channel;
47  
48 if ( $irc->is_channel_operator($chan, $bot)
49 || $irc->is_channel_admin($chan, $bot)
50 || $irc->is_channel_owner($chan, $bot) ) {
51 broadcast( 'kick', $context, $chan, $nick, "BANG!" );
52 }
53  
54 return color bold => 'BANG! ' . _suicide($nick)
55 }
56  
57  
58 --$self->{$context}->{$nick}->{Loaded};
59 return "${nick}: Click . . ."
60 }
61  
62 sub expire {
63 my ($self) = @_;
64 for my $context (keys %$self) {
65 for my $nick (keys %{ $self->{$context} }) {
66 delete $self->{$context}->{$nick}
67 if (time - $self->{$context}->{$nick}->{TS}) >= 600;
68 }
69 }
70 }
71  
72 1;
73 __END__