-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
313 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ inc | |
pm_to_blib | ||
MANIFEST | ||
Makefile.old | ||
myprivate.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env perl | ||
use BiLingr; | ||
my $bilingr = BiLingr->new_with_config(configfile => $ARGV[0]); | ||
$bilingr->run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
'lingr': { | ||
'api_key': 'API_KEY', | ||
'room' : 'ROOM', | ||
'nick' : 'NICK' | ||
}, | ||
'irc': { | ||
'server' : 'IRC_SERVER', | ||
'channel': 'IRC_CHANNEL', | ||
'nick' : 'IRC_NICK' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package BiLingr::Bot; | ||
|
||
use MooseX::POE; | ||
use BiLingr::Lingr; | ||
use BiLingr::IRC; | ||
|
||
has parent => ( | ||
isa => 'BiLingr', | ||
is => 'ro', | ||
required => 1, | ||
); | ||
|
||
# POE events ---------------------------------------------- | ||
sub START { | ||
my ( $self ) = @_[OBJECT, ARG0 .. $#_]; | ||
my $lingr = BiLingr::Lingr->new( %{ $self->parent->lingr } ); | ||
my $irc = BiLingr::IRC->new( %{ $self->parent->irc } ); | ||
|
||
$lingr->irc( $irc->get_session_id ); | ||
$irc->lingr( $lingr->get_session_id ); | ||
} | ||
|
||
|
||
no MooseX::POE; | ||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package BiLingr::IRC; | ||
use MooseX::POE; | ||
use POE qw(Component::IRC); | ||
|
||
has server => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
required => 1, | ||
); | ||
|
||
has nick => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
default => 'bilingr_irc', | ||
); | ||
|
||
has channel => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
required => 1, | ||
); | ||
|
||
has lingr => ( | ||
isa => 'Int', | ||
is => 'rw', | ||
); | ||
|
||
has _irc => ( | ||
isa => 'POE::Component::IRC', | ||
is => 'rw', | ||
); | ||
|
||
|
||
# POE events ---------------------------------------------- | ||
sub START { | ||
my ( $self ) = @_[OBJECT, ARG0 .. $#_]; | ||
my $irc = POE::Component::IRC->spawn( | ||
nick => $self->nick, | ||
# ircname => $self->nick, | ||
server => $self->server, | ||
); | ||
|
||
$irc->yield( register => 'all' ); | ||
$irc->yield( connect => {} ); | ||
|
||
$self->_irc( $irc ); | ||
} | ||
|
||
event irc_001 => sub { | ||
my ( $self ) = @_[OBJECT, ARG0 .. $#_]; | ||
$self->_irc->yield( join => $self->channel ); | ||
}; | ||
|
||
event irc_public => sub { | ||
my ( $self, $who, $where, $what ) = @_[OBJECT, ARG0 .. $#_]; | ||
|
||
$poe_kernel->post( | ||
$self->lingr => said => | ||
$who, $what, | ||
); | ||
}; | ||
|
||
event said => sub { | ||
my ( $self, $who, $what ) = @_[OBJECT, ARG0 .. $#_]; | ||
|
||
$self->_irc->yield( | ||
privmsg => $self->channel, "$who: $what", | ||
); | ||
}; | ||
|
||
|
||
no MooseX::POE; | ||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package BiLingr::Lingr; | ||
use MooseX::POE; | ||
use POE qw(Component::Client::Lingr); | ||
|
||
has api_key => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
required => 1, | ||
); | ||
|
||
has room => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
required => 1, | ||
); | ||
|
||
has nick => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
default => __PACKAGE__, | ||
); | ||
|
||
has irc => ( | ||
isa => 'Int', | ||
is => 'rw', | ||
); | ||
|
||
has _lingr => ( | ||
isa => 'Str', | ||
is => 'ro', | ||
lazy_build => 1, | ||
); | ||
|
||
sub _build__lingr{ | ||
my $self = shift; | ||
return 'lingr' . ($self + 0); | ||
} | ||
|
||
|
||
# POE events ---------------------------------------------- | ||
sub START { | ||
my ( $self ) = @_[OBJECT, ARG0 .. $#_]; | ||
POE::Component::Client::Lingr->spawn(alias => $self->_lingr); | ||
$poe_kernel->post( $self->_lingr => 'register' ); | ||
$poe_kernel->post( | ||
$self->_lingr => call => | ||
'session.create', { api_key => $self->api_key } | ||
); | ||
} | ||
|
||
event 'lingr.session.create' => sub { | ||
my ( $self, $event ) = @_[OBJECT, ARG0 .. $#_]; | ||
$poe_kernel->call( | ||
$self->_lingr => call => | ||
'room.enter', { id => $self->room, nickname => $self->nick }); | ||
}; | ||
|
||
event 'lingr.room.enter' => sub { | ||
my ( $self, $event ) = @_[OBJECT, ARG0 .. $#_]; | ||
}; | ||
|
||
event 'lingr.room.observe' => sub { | ||
my ( $self, $event ) = @_[OBJECT, ARG0 .. $#_]; | ||
for my $msg (@{ $event->{messages} || []}){ | ||
next unless $msg->{client_type} eq 'human'; | ||
$poe_kernel->post( | ||
$self->irc => said => | ||
$msg->{nickname}, $msg->{text}, | ||
); | ||
} | ||
}; | ||
|
||
event said => sub { | ||
my ( $self, $who, $what ) = @_[OBJECT, ARG0 .. $#_]; | ||
|
||
$poe_kernel->post( | ||
$self->_lingr => call => | ||
'room.say', { message => "$who: $what" } | ||
); | ||
}; | ||
|
||
# for DEBUG ================== | ||
use Data::Dumper; | ||
event 'lingr.error.http' => sub { | ||
my ( $self, $event ) = @_[OBJECT, ARG0 .. $#_]; | ||
die Dumper($event); | ||
}; | ||
|
||
event 'lingr.error.response' => sub { | ||
my ( $self, $event ) = @_[OBJECT, ARG0 .. $#_]; | ||
die Dumper($event); | ||
}; | ||
|
||
no MooseX::POE; | ||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
use strict; | ||
use Test::More tests => 1; | ||
|
||
BEGIN { use_ok 'BiLingr' } | ||
BEGIN { | ||
use_ok qw/BiLingr BiLingr::Bot BiLingr::Lingr/; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use strict; | ||
use warnings; | ||
use BiLingr; | ||
use Test::More tests => 6; | ||
|
||
|
||
# default config file is 'bilingr.[ANY]'. | ||
my $b1 = BiLingr->new_with_config(); | ||
|
||
is $b1->lingr->{api_key}, 'API_KEY'; | ||
is $b1->lingr->{room}, 'ROOM'; | ||
is $b1->lingr->{nick}, 'NICK'; | ||
|
||
|
||
# set config file explicitly | ||
my $b2 = BiLingr->new_with_config( configfile => 't/test.yaml' ); | ||
|
||
is $b2->lingr->{api_key}, 'api_key'; | ||
is $b2->lingr->{room}, 'room'; | ||
is $b2->lingr->{nick}, 'nick'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
lingr: | ||
api_key: api_key | ||
room: room | ||
nick: nick | ||
irc: | ||
server: irc_server | ||
channel: irc_channel | ||
nick: irc_nick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
[TestingAndDebugging::ProhibitNoStrict] | ||
allow=refs | ||
|
||
[TestingAndDebugging::RequireUseStrict] | ||
equivalent_modules = MooseX::POE |