blib/lib/Bot/Cobalt/Plugin/Master.pm

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