diff --git a/lib/Github/IRCBot.pm b/lib/Github/IRCBot.pm index 08186d1..4400281 100644 --- a/lib/Github/IRCBot.pm +++ b/lib/Github/IRCBot.pm @@ -29,7 +29,9 @@ has httpd => ( lazy => 1, default => sub { my $self = shift; - Github::IRCBot::HTTPD->new( $self->config->{httpd} ); + my $settings = $self->config->{httpd}; + $settings->{irc} = $self->irc; + Github::IRCBot::HTTPD->new($settings); }, ); diff --git a/lib/Github/IRCBot/HTTPD.pm b/lib/Github/IRCBot/HTTPD.pm index 87a09b7..e358e8f 100644 --- a/lib/Github/IRCBot/HTTPD.pm +++ b/lib/Github/IRCBot/HTTPD.pm @@ -11,6 +11,11 @@ has port => ( default => sub { 3000 }, ); +has irc => ( + is => 'rw', + isa => 'Github::IRCBot::IRC' +); + has session => ( is => 'rw', isa => 'POE::Session', @@ -40,6 +45,7 @@ has json => ( handles => [qw/decode/], ); + sub spawn { my $self = shift; $self->session; @@ -56,12 +62,15 @@ sub poe__start { '/' => sub { my ($req, $res) = @_; my $p = CGI::Simple->new( $req->content ); - my $channel = '#' . $p->param('name'); my $info = $self->decode( $p->param('payload') ); + my $channels = $self->irc->channels; for my $commit (@{ $info->{commits} || [] }) { - $kernel->post( irc => say => $channel => - "commit: (03$commit->{author}{name}) $commit->{message} - 14$commit->{url}" ); + for(@$channels){ + $kernel->post( irc => say => $_ => + "commit: (03$commit->{author}{name}) ". + "$commit->{message} - 14$commit->{url}" ); + } } }, },