| 1 | package Bot::Cobalt::IRC::Role::AdminCmds; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $Bot::Cobalt::IRC::Role::AdminCmds::VERSION = '0.021003'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Scalar::Util 'reftype'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Bot::Cobalt; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Bot::Cobalt::Common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub Bot_public_cmd_server { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Bot_public_cmd_server: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my ($self, $core) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $msg = ${ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $context = $msg->context; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $src_nick = $msg->src_nick; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return PLUGIN_EAT_ALL unless | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | $core->auth->has_flag($context, $src_nick, 'SUPERUSER'); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $cmd = lc($msg->message_array->[0] || 'list'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$msg->message_array->[0] || 'list'
MC/DC0%0/1
$msg->message_array->[0] || 'list'
$msg->message_array->[0]
Truth table0%0/2
A
A= $msg->message_array->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $meth = '_cmd_'.$cmd; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | unless ( $self->can($meth) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 27 | "Unknown command; try one of: list, current, connect, disconnect"; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | logger->debug("Dispatching $cmd for $src_nick"); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $self->$meth($msg) | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub _cmd_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmd_list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my @contexts = keys %{ core->Servers }; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $pcfg = plugin_cfg($self); | |||||||||||||||||||||||||||||||||||||||||
| 39 | ## FIXME look for contexts that are conf'd but not active | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 42 | "Active contexts: " . join ' ', @contexts ; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub _cmd_current { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmd_current: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 51 | "Currently on context ".$msg->context; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | { no warnings 'once'; *_cmd_reconnect = *_cmd_connect; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub _cmd_connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmd_connect: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $pcfg = plugin_cfg($self); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | unless (ref $pcfg && reftype $pcfg eq 'HASH' && keys %$pcfg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $pcfg and builtin::reftype($pcfg) eq "HASH" and keys %$pcfg
ref $pcfg and builtin::reftype($pcfg) eq "HASH"
MC/DC0%0/3
ref $pcfg and builtin::reftype($pcfg) eq "HASH" and keys %$pcfg
ref $pcfg
builtin::reftype($pcfg) eq "HASH"
keys %$pcfg
Truth table0%0/4
A and B and C
A= ref $pcfgB= builtin::reftype($pcfg) eq "HASH"C= keys %$pcfg
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 64 | "Could not locate any network configuration."; | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | logger->error("_cmd_connect could not find an IRC network cfg"); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $target_ctxt = $msg->message_array->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | unless (defined $target_ctxt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 72 | "No context specified."; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | unless ($pcfg->{Networks}->{$target_ctxt}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 78 | "Could not locate configuration for context $target_ctxt"; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | ## Do we already have this context? | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (my $ctxt_obj = irc_context($target_ctxt) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($ctxt_obj->connected) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 86 | "Attempting reconnect for context $target_ctxt"; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | logger->info("Attempting reconnect for context $target_ctxt"); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | broadcast ircplug_disconnect => $target_ctxt; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | broadcast ircplug_connect => $target_ctxt; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | broadcast ircplug_timer_serv_retry => | |||||||||||||||||||||||||||||||||||||||||
| 92 | +{ context => $target_ctxt, delay => 300 } ; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 97 | "Issuing connect for context $target_ctxt"; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $src_nick = $msg->src_nick; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $auth_usr = core->auth->username($msg->context, $src_nick); | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | logger->info( | |||||||||||||||||||||||||||||||||||||||||
| 103 | "Issuing connect for context $target_ctxt", | ||||||||||||||||||||||||||||||||||||||||||
| 104 | "(Issued by $src_nick [$auth_usr])" | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | broadcast ircplug_connect => $target_ctxt; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub _cmd_disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmd_disconnect: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $target_ctxt = $msg->message_array->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless (defined $target_ctxt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 118 | "No context specified."; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $ctxt_obj; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | unless ($ctxt_obj = irc_context($target_ctxt) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 125 | "Could not find context object for $target_ctxt"; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | unless (keys %{ core->Servers } > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 131 | "Refusing disconnect; have no other active contexts."; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | broadcast message => $msg->context, $msg->channel, | |||||||||||||||||||||||||||||||||||||||||
| 136 | "Attempting to disconnect from $target_ctxt"; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $src_nick = $msg->src_nick; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $auth_usr = core->auth->username($msg->context, $src_nick); | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | logger->info( | |||||||||||||||||||||||||||||||||||||||||
| 142 | "Issuing disconnect for context $target_ctxt", | ||||||||||||||||||||||||||||||||||||||||||
| 143 | "(Issued by $src_nick [$auth_usr])" | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | broadcast ircplug_disconnect => $target_ctxt; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub Bot_ircplug_timer_serv_retry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Bot_ircplug_timer_serv_retry: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my ($self, $core) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $hints = ${ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $context = $hints->{context}; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my $delay = $hints->{delay} || 300; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hints->{'delay'} || 300
MC/DC0%0/1
$hints->{'delay'} || 300
$hints->{'delay'}
Truth table0%0/2
A
A= $hints->{'delay'}
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | logger->debug("ircplug_timer_serv_retry called for $context"); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $ctxt_obj; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | unless ($ctxt_obj = irc_context($context) && $ctxt_obj->connected) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&irc_context($context) && $ctxt_obj->connected
MC/DC0%0/2
&irc_context($context) && $ctxt_obj->connected
&irc_context($context)
$ctxt_obj->connected
Truth table0%0/3
A && B
A= &irc_context($context)B= $ctxt_obj->connected
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | logger->info("Attempting reconnect to $context . . ."); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | broadcast ircplug_connect => $context; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | core->timer_set( $delay, | |||||||||||||||||||||||||||||||||||||||||
| 165 | +{ | ||||||||||||||||||||||||||||||||||||||||||
| 166 | Event => 'ircplug_timer_serv_retry', | ||||||||||||||||||||||||||||||||||||||||||
| 167 | Args => [ +{ context => $context, delay => $delay } ], | ||||||||||||||||||||||||||||||||||||||||||
| 168 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | __END__ | ||||||||||||||||||||||||||||||||||||||||||