File Coverage

blib/lib/Bot/Cobalt/Plugin/Silly/AutoOpAll.pm
Criterion Covered Total %
statement 10 51 19.6
branch 0 8 0.0
condition 0 4 0.0
subroutine 4 8 50.0
pod 0 5 0.0
total 14 76 18.4


line stmt bran cond sub pod time code
1             package Bot::Cobalt::Plugin::Silly::AutoOpAll;
2             $Bot::Cobalt::Plugin::Silly::AutoOpAll::VERSION = '0.031001';
3 1     1   29561 use strictures 2;
  1         1697  
  1         50  
4              
5 1     1   1013 use Object::Pluggable::Constants qw/ :ALL /;
  1         653  
  1         168  
6              
7 1     1   583 use IRC::Utils 'lc_irc';
  1         33769  
  1         835  
8              
9 1     1 0 505 sub new { bless {}, shift }
10              
11             sub Cobalt_register {
12 0     0 0   my ($self, $core) = splice @_, 0, 2;
13 0           $self->{AOPChans} = {};
14              
15 0           $core->plugin_register( $self, 'SERVER',
16             'user_joined',
17             'public_cmd_aopall',
18             );
19              
20 0           $core->log->info("Loaded");
21              
22 0           return PLUGIN_EAT_NONE
23             }
24              
25             sub Cobalt_unregister {
26 0     0 0   my ($self, $core) = splice @_, 0, 2;
27              
28 0           $core->log->info("Unloaded");
29              
30 0           return PLUGIN_EAT_NONE
31             }
32              
33              
34             sub Bot_public_cmd_aopall {
35 0     0 0   my ($self, $core) = splice @_, 0, 2;
36 0           my $msg = ${ $_[0] };
  0            
37 0           my $context = $msg->context;
38              
39             ## !aopall #chan
40             ## !aopall -#chan
41              
42 0           my $nick = $msg->src_nick;
43            
44 0           my $lev = $core->auth->level($context, $nick);
45 0 0         return PLUGIN_EAT_ALL unless $lev >= 3;
46              
47 0   0       my $casemap = $core->Servers->{$context}->{CaseMap}
48             // 'rfc1459';
49              
50 0           my $chan = $msg->message_array->[0];
51 0           $chan = lc_irc($chan, $casemap);
52              
53 0 0         unless ( index($chan, '-') == 0 ) {
54 0           $self->{AOPChans}->{$context}->{$chan} = 1;
55 0           $core->send_event( 'notice',
56             $context,
57             $nick,
58             "AutoOpping all on $chan",
59             );
60             } else {
61 0           $chan = substr($chan, 1);
62              
63 0           my $resp;
64 0 0         if (delete $self->{AOPChans}->{$context}->{$chan}) {
65 0           $resp = "Not autoopping on $chan";
66             } else {
67 0           $resp = "No such chan ($chan) found";
68             }
69              
70 0           $core->send_event( 'notice',
71             $context,
72             $nick,
73             $resp
74             );
75             }
76            
77 0           return PLUGIN_EAT_ALL
78             }
79              
80             sub Bot_user_joined {
81 0     0 0   my ($self, $core) = splice @_, 0, 2;
82 0           my $joined = ${ $_[0] };
  0            
83              
84 0           my $context = $joined->context;
85              
86 0           my $chan = $joined->channel;
87 0           my $nick = $joined->src_nick;
88              
89 0   0       my $casemap = $core->get_irc_casemap($context) || 'rfc1459' ;
90              
91 0           $chan = lc_irc($chan, $casemap);
92              
93 0 0         if (grep { $_ eq $chan } keys %{ $self->{AOPChans}->{$context} }) {
  0            
  0            
94 0           $core->send_event( 'mode', $context, $chan, '+o '.$nick );
95             }
96              
97 0           return PLUGIN_EAT_NONE
98             }
99              
100             1;
101             __END__