App-RoboBot
view release on metacpan or search on metacpan
lib/App/RoboBot/Plugin/API/Kegerator.pm view on Meta::CPAN
has '+name' => (
default => 'API::Kegerator',
);
has '+description' => (
default => 'Provides functions for monitoring and querying kegerator status. Currently only supports OmniTI Kegerator API.',
);
=head2 ontap
=head3 Description
Invoked with no arguments, displays the list of beers currently on tap. When
invoked with a tap number, displays detailed information on the beer available
on that tap.
=head3 Usage
[<tap number>]
=head3 Examples
:emphasize-lines: 2-5,8
(ontap)
Tap 1: Tasmanian IPA (TIPA) (IPA - American) by Schlafly - The Saint Louis Brewery, Saint Louis, MO - 7.2% ABV, 93% remaining
Tap 2: Resurrection (Brown Ale - Belgian) by The Brewer's Art, Baltimore, MD - 7.0% ABV, 97% remaining
Tap 3: K-9 Cruiser Winter Ale (Winter Ale) by Flying Dog Brewery, Frederick, MD - 7.4% ABV, 84% remaining
Tap 4: Crisp Apple (Cider) by Angry Orchard Cider Company, Cincinnati, OH - 5.0% ABV, 69% remaining
(ontap 3)
Tap 3: K-9 Cruiser Winter Ale (Winter Ale) by Flying Dog Brewery, Frederick, MD - 7.4% ABV, 84% remaining
=cut
has '+commands' => (
default => sub {{
'ontap' => { method => 'show_ontap',
description => 'Displays the list of beers currently on tap.',
usage => '[<tap number>]', },
}},
);
has 'watcher' => (
is => 'rw',
);
has 'ua' => (
is => 'rw',
isa => 'LWP::UserAgent',
default => sub {
my $ua = LWP::UserAgent->new;
$ua->agent('App::RoboBot');
$ua->timeout(5);
return $ua;
},
);
has 'last_check' => (
is => 'rw',
isa => 'DateTime',
default => sub { DateTime->now },
);
has 'beer_cache' => (
is => 'rw',
isa => 'HashRef',
default => sub { {} },
);
has 'valid_config' => (
is => 'rw',
isa => 'Bool',
traits => [qw( SetOnce )],
);
sub init {
my ($self, $bot) = @_;
# Verify we have all the necessary config keys, so we can make a much
# simpler ->valid_config check everywhere else.
if (exists $self->bot->config->plugins->{'kegerator'}{'api_host'}
&& exists $self->bot->config->plugins->{'kegerator'}{'api_path_taps'}
&& exists $self->bot->config->plugins->{'kegerator'}{'api_path_beer'}) {
$self->valid_config(1);
} else {
$self->valid_config(0);
# No need to initialize anything else related to the watcher, since we
# don't have the config keys we'll need for that.
return;
}
# Coerce notification targets into an arrayref from the configuration, in
# case only one was specified (Config::Any will have only treated it as a
# hashref, instead of an arrayref of hashrefs. Simplifies notification
# loop later on.
if (exists $self->bot->config->plugins->{'kegerator'}{'notify'}) {
$self->bot->config->plugins->{'kegerator'}{'notify'} = [
$self->bot->config->plugins->{'kegerator'}{'notify'}
] if ref($self->bot->config->plugins->{'kegerator'}{'notify'}) eq 'HASH';
# Only set the watcher if we have at least one channel to notify.
return unless @{$self->bot->config->plugins->{'kegerator'}{'notify'}} > 0;
$self->watcher(
AnyEvent->timer(
after => 30,
cb => sub { $self->_run_watcher($bot) },
)
);
}
}
sub show_ontap {
my ($self, $message, $command, $rpl, $tap_no) = @_;
if (defined $tap_no && $tap_no !~ m{^\d+$}o) {
$message->response->raise('Optional tap number must be an integer if specified.');
return;
}
( run in 0.816 second using v1.01-cache-2.11-cpan-5a3173703d6 )