1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package Crawl::Bot;
use Moose;
use MooseX::NonMoose;
extends 'Bot::BasicBot';
use File::Path;
use Module::Pluggable (
instantiate => 'new',
sub_name => 'create_plugins',
);
has [qw(username name)] => (
# don't need (or want) accessors, just want to initialize the hash slot
# for B::BB to use
is => 'bare',
isa => 'Str',
default => sub { shift->nick },
);
has data_dir => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => 'dat',
);
has update_time => (
is => 'ro',
isa => 'Int',
default => 300,
);
has plugins => (
is => 'ro',
isa => 'ArrayRef[Crawl::Bot::Plugin]',
lazy => 1,
default => sub { [__PACKAGE__->create_plugins(bot => shift)] },
);
sub BUILD {
my $self = shift;
File::Path::mkpath($self->data_dir);
$self->plugins;
}
before say => sub {
my $self = shift;
my %params = @_;
warn "sending '$params{body}' to $params{channel}";
};
sub tick {
my $self = shift;
warn "Checking for updates...";
$_->tick for @{ $self->plugins };
warn "Done";
return $self->update_time;
}
sub say_all {
my $self = shift;
my ($message) = @_;
$self->say(
channel => $_,
body => $message,
) for $self->channels;
}
1;
|