Created
          May 21, 2010 07:09 
        
      - 
      
- 
        Save JEEN/408566 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | 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