File Coverage

blib/lib/Bot/Cobalt/Plugin/Master.pm
Criterion Covered Total %
statement 10 126 7.9
branch 0 18 0.0
condition 0 31 0.0
subroutine 4 14 28.5
pod 0 11 0.0
total 14 200 7.0


line stmt bran cond sub pod time code
1             package Bot::Cobalt::Plugin::Master;
2             $Bot::Cobalt::Plugin::Master::VERSION = '0.021002';
3 1     1   1250 use strictures 2;
  1         5  
  1         29  
4              
5 1     1   130 use Bot::Cobalt;
  1         1  
  1         4  
6 1     1   540 use Bot::Cobalt::Common;
  1         2  
  1         4  
7              
8              
9 1     1 0 1051 sub new { bless {}, shift }
10              
11             sub Cobalt_register {
12 0     0 0   my ($self, $core) = splice @_, 0, 2;
13              
14 0           register( $self, 'SERVER',
15             qw/
16             public_cmd_join
17             public_cmd_part
18             public_cmd_cycle
19              
20             public_cmd_die
21              
22             public_cmd_op
23             public_cmd_deop
24             public_cmd_voice
25             public_cmd_devoice
26             /
27             );
28              
29 0           logger->info("Loaded");
30              
31 0           return PLUGIN_EAT_NONE
32             }
33              
34             sub Cobalt_unregister {
35 0     0 0   my ($self, $core) = splice @_, 0, 2;
36              
37 0           logger->info("Unloaded");
38              
39 0           return PLUGIN_EAT_NONE
40             }
41              
42              
43             sub Bot_public_cmd_cycle {
44 0     0 0   my ($self, $core) = splice @_, 0, 2;
45 0           my $msg = ${ $_[0] };
  0            
46              
47 0           my $context = $msg->context;
48 0           my $src_nick = $msg->src_nick;
49              
50 0           my $pcfg = plugin_cfg($self);
51              
52 0   0       my $requiredlev = $pcfg->{Level_joinpart} // 3;
53              
54 0           my $authed_lev = $core->auth->level($context, $src_nick);
55              
56             ## fail quietly for unauthed users
57 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
58              
59 0           logger->info("CYCLE issued by $src_nick");
60              
61 0           my $channel = $msg->channel;
62              
63 0           broadcast( 'part', $context, $channel, "Cycling $channel" );
64 0           broadcast( 'join', $context, $channel );
65              
66 0           return PLUGIN_EAT_ALL
67             }
68              
69             sub Bot_public_cmd_join {
70 0     0 0   my ($self, $core) = splice @_, 0, 2;
71 0           my $msg = ${ $_[0] };
  0            
72              
73 0           my $context = $msg->context;
74 0           my $src_nick = $msg->src_nick;
75              
76 0           my $pcfg = plugin_cfg($self);
77              
78 0   0       my $requiredlev = $pcfg->{Level_joinpart} // 3;
79              
80 0           my $authed_lev = $core->auth->level($context, $src_nick);
81              
82 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
83              
84 0           my $channel = $msg->message_array->[0];
85              
86 0 0         unless ($channel) {
87 0           broadcast( 'message', $context, $msg->channel,
88             "No channel specified."
89             );
90              
91 0           return PLUGIN_EAT_ALL
92             }
93              
94 0           logger->info("JOIN ($channel) issued by $src_nick");
95              
96 0           broadcast( 'message', $context, $msg->channel,
97             "Joining $channel"
98             );
99              
100 0           broadcast( 'join', $context, $channel );
101              
102 0           return PLUGIN_EAT_ALL
103             }
104              
105             sub Bot_public_cmd_part {
106 0     0 0   my ($self, $core) = splice @_, 0, 2;
107 0           my $msg = ${ $_[0] };
  0            
108              
109 0           my $context = $msg->context;
110 0           my $src_nick = $msg->src_nick;
111              
112 0           my $pcfg = plugin_cfg($self);
113              
114 0   0       my $requiredlev = $pcfg->{Level_joinpart} // 3;
115 0           my $authed_lev = $core->auth->level($context, $src_nick);
116              
117 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
118              
119 0   0       my $channel = $msg->message_array->[0] // $msg->channel;
120              
121 0           logger->info("PART ($channel) issued by $src_nick");
122              
123 0           broadcast( 'message', $context, $msg->channel,
124             "Leaving $channel"
125             );
126              
127 0           broadcast( 'part', $context, $channel, "Requested by $src_nick" );
128              
129 0           return PLUGIN_EAT_ALL
130             }
131              
132             sub Bot_public_cmd_op {
133 0     0 0   my ($self, $core) = splice @_, 0, 2;
134 0           my $msg = ${ $_[0] };
  0            
135              
136 0           my $context = $msg->context;
137 0           my $src_nick = $msg->src_nick;
138              
139 0           my $pcfg = plugin_cfg($self);
140              
141 0   0       my $requiredlev = $pcfg->{Level_op} // 3;
142 0           my $authed_lev = $core->auth->level($context, $src_nick);
143              
144 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
145              
146 0   0       my $target_usr = $msg->message_array->[0] // $msg->src_nick;
147              
148 0           my $channel = $msg->channel;
149              
150 0           broadcast( 'mode', $context, $channel, "+o $target_usr" );
151              
152 0           return PLUGIN_EAT_ALL
153             }
154              
155             sub Bot_public_cmd_deop {
156 0     0 0   my ($self, $core) = splice @_, 0, 2;
157 0           my $msg = ${ $_[0] };
  0            
158              
159 0           my $context = $msg->context;
160 0           my $src_nick = $msg->src_nick;
161              
162 0           my $pcfg = plugin_cfg($self);
163              
164 0   0       my $requiredlev = $pcfg->{Level_op} // 3;
165 0           my $authed_lev = $core->auth->level($context, $src_nick);
166              
167 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
168              
169 0   0       my $target_usr = $msg->message_array->[0] // $msg->src_nick;
170 0           my $channel = $msg->channel;
171              
172 0           broadcast( 'mode', $context, $channel, "-o $target_usr" );
173              
174 0           return PLUGIN_EAT_ALL
175             }
176              
177             sub Bot_public_cmd_voice {
178 0     0 0   my ($self, $core) = splice @_, 0, 2;
179 0           my $msg = ${ $_[0] };
  0            
180              
181 0           my $context = $msg->context;
182 0           my $src_nick = $msg->src_nick;
183              
184 0           my $pcfg = plugin_cfg($self);
185              
186 0   0       my $requiredlev = $pcfg->{Level_voice} // 2;
187 0           my $authed_lev = $core->auth->level($context, $src_nick);
188              
189 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
190              
191 0   0       my $target_usr = $msg->message_array->[0] // $msg->src_nick;
192              
193 0           my $channel = $msg->channel;
194              
195 0           broadcast( 'mode', $context, $channel, "+v $target_usr" );
196              
197 0           return PLUGIN_EAT_ALL
198             }
199              
200             sub Bot_public_cmd_devoice {
201 0     0 0   my ($self, $core) = splice @_, 0, 2;
202 0           my $msg = ${ $_[0] };
  0            
203              
204 0           my $context = $msg->context;
205 0           my $src_nick = $msg->src_nick;
206              
207 0           my $pcfg = plugin_cfg($self);
208              
209 0   0       my $requiredlev = $pcfg->{Level_voice} // 2;
210 0           my $authed_lev = $core->auth->level($context, $src_nick);
211              
212 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
213              
214 0   0       my $target_usr = $msg->message_array->[0] // $msg->src_nick;
215              
216 0           my $channel = $msg->channel;
217              
218 0           broadcast( 'mode', $context, $channel, "-v $target_usr" );
219              
220 0           return PLUGIN_EAT_ALL
221             }
222              
223             sub Bot_public_cmd_die {
224 0     0 0   my ($self, $core) = splice @_, 0, 2;
225 0           my $msg = ${ $_[0] };
  0            
226              
227 0           my $context = $msg->context;
228 0           my $src_nick = $msg->src_nick;
229              
230 0           my $pcfg = plugin_cfg($self);
231              
232 0   0       my $requiredlev = $pcfg->{Level_die} || 9999;
233 0           my $authed_lev = $core->auth->level($context, $src_nick);
234              
235 0 0         return PLUGIN_EAT_ALL unless $authed_lev >= $requiredlev;
236              
237 0           my $auth_usr = $core->auth->username($context, $src_nick);
238              
239 0           logger->warn("Shutdown requested; $src_nick ($auth_usr)");
240              
241 0           $core->shutdown
242             }
243              
244             1;
245             __END__