Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: None  |  size: 1.21 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/home/mash/perl5/perlbrew/perls/perl-5.12.3/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. use Irssi;
  6. use Config::Pit;
  7. use Furl;
  8.  
  9. use vars qw($VERSION %IRSSI);
  10. $VERSION = "0.1";
  11. %IRSSI = (
  12.     authors         => 'Masakazu OHTSUKA (mash)',
  13.     name            => 'hilight2nakamap',
  14.     description     => 'forward hilighted messages to nakamap as shout',
  15.     url             => 'http://maaash.jp/',
  16.     changed         => '2011-09-08',
  17. );
  18. my $config = pit_get( 'nakamap', require => {
  19.     access_token => 'oauth2 access token',
  20.     group_uid    => 'group to post your message to',
  21. });
  22. my $furl = Furl->new( agent => 'hilight2nakamap/1.0', timeout => 10 );
  23.  
  24. sub forward_to_nakamap {
  25.     my ( $dest, $text, $stripped ) = @_;
  26.  
  27.     if ( $dest->{level} & MSGLEVEL_HILIGHT ) {
  28.         my $res = $furl->post( 'https://thanks.nakamap.com/1/group/' . $config->{ group_uid } . '/chats',
  29.                                [ 'Content-Type' => 'application/x-www-form-urlencoded' ],
  30.                                [ token   => $config->{ access_token },
  31.                                  message => 'irc:'.$dest->{target}.' '.$stripped,
  32.                                  type    => 'shout', ] );
  33.     }
  34. }
  35.  
  36. Irssi::signal_add( 'print text' => \&forward_to_nakamap );