Skip to content

Instantly share code, notes, and snippets.

@JEEN
Created May 21, 2010 07:09
Show Gist options
  • Save JEEN/408566 to your computer and use it in GitHub Desktop.
Save JEEN/408566 to your computer and use it in GitHub Desktop.
package Morris::Plugin::Pusher;
use Moose;
use namespace::autoclean;
use WWW::Pusher;
use JSON;
extends 'Morris::Plugin';
after register => sub {
my ($self, $conn) = @_;
$conn->register_hook( 'chat.privmsg', sub { $self->handle_message(@_) } );
};
sub handle_message {
my ($self, $msg) = @_;
my $channel = $msg->channel;
my $message = $msg->message;
my $nickname = $msg->nickname;
$nickname =~ s/_*$//g;
my $row = {
channel => $channel,
message => $message,
nickname => $nickname,
time => time(),
};
my $pusher = WWW::Pusher->new( auth_key => 'your auth_key', secret => 'your secret', app_id => 'your app_id', channel => 'your channel');
my $response = $pusher->trigger( event => 'event_name', data => JSON->new->encode($row) );
}
__PACKAGE__->meta->make_immutable();
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment