Bot-Cobalt
view release on metacpan or search on metacpan
lib/Bot/Cobalt/IRC/Role/AdminCmds.pm view on Meta::CPAN
package Bot::Cobalt::IRC::Role::AdminCmds;
$Bot::Cobalt::IRC::Role::AdminCmds::VERSION = '0.021003';
use strictures 2;
use Scalar::Util 'reftype';
use Bot::Cobalt;
use Bot::Cobalt::Common;
use Try::Tiny;
use Moo::Role;
sub Bot_public_cmd_server {
my ($self, $core) = splice @_, 0, 2;
my $msg = ${ $_[0] };
my $context = $msg->context;
my $src_nick = $msg->src_nick;
return PLUGIN_EAT_ALL unless
$core->auth->has_flag($context, $src_nick, 'SUPERUSER');
my $cmd = lc($msg->message_array->[0] || 'list');
my $meth = '_cmd_'.$cmd;
unless ( $self->can($meth) ) {
broadcast message => $msg->context, $msg->channel,
"Unknown command; try one of: list, current, connect, disconnect";
return PLUGIN_EAT_ALL
}
logger->debug("Dispatching $cmd for $src_nick");
$self->$meth($msg)
}
sub _cmd_list {
my ($self, $msg) = @_;
my @contexts = keys %{ core->Servers };
my $pcfg = plugin_cfg($self);
## FIXME look for contexts that are conf'd but not active
broadcast message => $msg->context, $msg->channel,
"Active contexts: " . join ' ', @contexts ;
PLUGIN_EAT_ALL
}
sub _cmd_current {
my ($self, $msg) = @_;
broadcast message => $msg->context, $msg->channel,
"Currently on context ".$msg->context;
PLUGIN_EAT_ALL
}
{ no warnings 'once'; *_cmd_reconnect = *_cmd_connect; }
sub _cmd_connect {
my ($self, $msg) = @_;
my $pcfg = plugin_cfg($self);
unless (ref $pcfg && reftype $pcfg eq 'HASH' && keys %$pcfg) {
broadcast message => $msg->context, $msg->channel,
"Could not locate any network configuration.";
logger->error("_cmd_connect could not find an IRC network cfg");
return PLUGIN_EAT_ALL
}
my $target_ctxt = $msg->message_array->[1];
( run in 0.502 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )