Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created February 28, 2012 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugyan/1930473 to your computer and use it in GitHub Desktop.
Save sugyan/1930473 to your computer and use it in GitHub Desktop.
irssi notification plugin
use strict;
use warnings;
use Irssi;
use AnyEvent::HTTP;
use Growl::GNTP;
use HTTP::Request::Common;
use Try::Tiny;
our $VERSION = '0.1';
our %IRSSI = (
name => 'hilight_notify',
description => 'notify hilight message to Growl via GNTP or IM via im.kayac.com api',
authors => 'sugyan',
);
sub sig_printtext {
my ($dest, $text, $stripped) = @_;
return unless ($dest->{level} & MSGLEVEL_HILIGHT);
my $message = sprintf('%s %s', $dest->{target}, $stripped);
try {
my $growl = Growl::GNTP->new(AppName => 'IRC irssi');
$growl->register([{
Name => 'hilight',
}]);
$growl->notify(
Event => 'hilight',
Title => 'irssi',
Message => $message,
Sticky => 'True',
);
} catch {
my $user = Irssi::settings_get_str('im_kayac_com_username') or return;
my $req = POST "http://im.kayac.com/api/post/$user", [ message => $message ];
my %headers = map { $_ => $req->header($_), } $req->headers->header_field_names;
my $r;
$r = http_post $req->uri, $req->content, headers => \%headers, sub {
undef $r;
};
};
}
Irssi::signal_add('print text' => \&sig_printtext);
Irssi::settings_add_str('im_kayac_com', 'im_kayac_com_username', '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment