App-RoboBot
view release on metacpan or search on metacpan
doc/config/index.rst view on Meta::CPAN
may contain letters, numbers, and dashes. They are not case-sensitive. The
network name is part of the section opening tag.
Network Type
It is required to specify the type of network being configured, using the
``type`` setting. Valid values are: ``irc``, ``slack``, and ``mattermost``.
Enabled
You may include network configuration sections for networks to which you
don't currently want |RB| to connect. By setting the value of ``enabled``
to ``0``, |RB| will load and validate the network's configuration, but will
not actually connect to the service.
The base minimum settings would result in a configuration section like this:
.. code-block:: aconf
<network my-network-name>
type irc
enabled 0
</network>
lib/App/RoboBot/Config.pm view on Meta::CPAN
$self->config($cfg);
} else {
die "Could not load configuration files: " . join(', ', @{$self->config_paths});
}
}
$self->init_logging;
$logger = $self->bot->logger('core.config');
$self->validate_database;
$logger->debug('Database configuration initialized.');
$self->validate_globals;
$logger->debug('Global settings initialized.');
$self->validate_networks;
$logger->debug('Network configurations initialized.');
$self->validate_plugins;
$logger->debug('Plugin configurations initialized.');
$self->bot->networks([ values %{$self->networks} ]);
} catch {
die "Could not load and validate configuration: $_";
};
$logger->debug('All configuration data loaded.');
}
sub locate_config {
my ($self) = @_;
my $home = File::HomeDir->my_home();
my @exts = qw( conf yml yaml json xml ini );
lib/App/RoboBot/Config.pm view on Meta::CPAN
'log4j.appender.stdout' => 'org.apache.log4j.ConsoleAppender',
'log4j.appender.stdout.layout' => 'org.apache.log4j.PatternLayout',
'log4j.appender.stdout.layout.ConversionPattern' => '%d %5p [%c] %m%n',
};
my $config_str = join("\n", map { sprintf('%s=%s', $_, $log_cfg->{$_}) } sort keys %{$log_cfg});
Log::Log4perl::init( \$config_str );
}
sub validate_globals {
my ($self) = @_;
my $logger = $self->bot->logger('core.config.globals');
my %global = (
nick => 'lispy',
);
$self->config->{'global'} = \%global unless exists $self->config->{'global'};
lib/App/RoboBot/Config.pm view on Meta::CPAN
$logger->debug(sprintf('Global setting %s = %s.', $_, $self->config->{'global'}{$_}))
for sort keys %{$self->config->{'global'}};
$self->config->{'global'}{'nick'} = App::RoboBot::Nick->new(
config => $self,
name => $self->config->{'global'}{'nick'}
);
}
sub validate_database {
my ($self) = @_;
my $logger = $self->bot->logger('core.config.database');
my %database = (
name => 'robobot',
);
$self->config->{'database'} = \%database unless exists $self->config->{'database'};
foreach my $k (keys %database) {
$self->config->{'database'}{$k} = $database{$k} unless exists $self->config->{'database'}{$k};
}
if (exists $self->config->{'database'}{'primary'} && ref($self->config->{'database'}{'primary'}) eq 'HASH') {
$logger->debug('Establishing database connection using explicit configuration hash.');
$self->db(DBIx::DataStore->new({ config => $self->config->{'database'} })) or die "Could not validate explicit database connection!";
} else {
$logger->debug('Establishing database connection using named DataStore definition.');
$self->db(DBIx::DataStore->new($self->config->{'database'}{'name'})) or die "Could not validate named database connection!";
}
$self->bot->migrate_database;
}
sub validate_networks {
my ($self) = @_;
my $logger = $self->bot->logger('core.config.networks');
my @networks;
my @channels;
$logger->debug('Creating network factory.');
my $nfactory = App::RoboBot::NetworkFactory->new(
lib/App/RoboBot/Config.pm view on Meta::CPAN
}
$networks[-1]->channels([@network_channels]);
}
$logger->debug('Assigning networks list to bot.');
$self->networks({ map { $_->name => $_ } @networks });
$self->channels(\@channels);
}
sub validate_plugins {
my ($self) = @_;
my $logger = $self->bot->logger('core.config.plugins');
foreach my $plugin_name (keys %{$self->config->{'plugin'}}) {
$logger->debug(sprintf('Collecting configuration data for %s plugin.', $plugin_name));
$self->plugins->{lc($plugin_name)} = $self->config->{'plugin'}{$plugin_name};
}
}
lib/App/RoboBot/Plugin/API/PagerDuty.pm view on Meta::CPAN
default => sub { { oncall => {} } },
);
sub init {
my ($self, $bot) = @_;
}
sub list_groups {
my ($self, $message, $command, $rpl) = @_;
return unless $self->_validate_config($message);
$message->response->push('The following PagerDuty groups are currently present in the configuration:');
$message->response->push(
sprintf('*%s*: %s',
$_,
($self->bot->config->plugins->{'pagerduty'}{'group'}{$_}{'desc'} // 'no description'),
))
for sort { lc($a) cmp lc($b) } keys %{$self->bot->config->plugins->{'pagerduty'}{'group'}};
return;
}
sub oncall {
my ($self, $message, $command, $rpl, $group, @extras) = @_;
return unless $self->_validate_group_config($message, $group);
my $now = $self->now;
$group = $self->bot->config->plugins->{'pagerduty'}{'group'}{lc($group)};
$message->response->push(sprintf('PagerDuty On-Call for _%s_:', $group->{'desc'}));
foreach my $schedule (sort { $a->{'order'} <=> $b->{'order'} } @{$self->coerce_schedules($group->{'schedule'})}) {
my $data;
lib/App/RoboBot/Plugin/API/PagerDuty.pm view on Meta::CPAN
return if $@;
return $json;
}
sub now {
my ($self) = @_;
return DateTime->now->iso8601 . 'Z';
}
sub _validate_config {
my ($self, $message) = @_;
unless (exists $self->bot->config->plugins->{'pagerduty'}
&& exists $self->bot->config->plugins->{'pagerduty'}{'group'}
&& ref($self->bot->config->plugins->{'pagerduty'}{'group'}) eq 'HASH')
{
$message->response->raise('PagerDuty groups not properly configured. Please contact bot administrator.');
return 0;
}
return 1;
}
sub _validate_group_config {
my ($self, $message, $group) = @_;
return 0 unless $self->_validate_config($message);
my $lgroup = lc($group);
unless (exists $self->bot->config->plugins->{'pagerduty'}{'group'}{$lgroup}
&& exists $self->bot->config->plugins->{'pagerduty'}{'group'}{$lgroup}{'api_key'}
&& exists $self->bot->config->plugins->{'pagerduty'}{'group'}{$lgroup}{'domain'})
{
$message->response->raise('The PagerDuty group %s is not properly configured. Please contact bot administrator.', $group);
return 0;
}
( run in 0.252 second using v1.01-cache-2.11-cpan-4d50c553e7e )