Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting channel name(s) in HTTPD.pm #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Github/IRCBot.pm
Expand Up @@ -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);
},
);

Expand Down
15 changes: 12 additions & 3 deletions lib/Github/IRCBot/HTTPD.pm
Expand Up @@ -11,6 +11,11 @@ has port => (
default => sub { 3000 },
);

has irc => (
is => 'rw',
isa => 'Github::IRCBot::IRC'
);

has session => (
is => 'rw',
isa => 'POE::Session',
Expand Down Expand Up @@ -40,6 +45,7 @@ has json => (
handles => [qw/decode/],
);


sub spawn {
my $self = shift;
$self->session;
Expand All @@ -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}" );
}
}
},
},
Expand Down