use strict; use warnings; ##################################################################### # This script sends notifications to your # Android using the Notify My Android API when you are away. # Based on irssinotifo.pl by Caesar 'sniker' Ahlenhed. # # Commands: # /set irssinma_API API_KEY (Default NULL) # /set irssinma_general_hilight on/off (Default OFF) # # "General hilight" basically referrs to ALL the hilights you have # added manually in irssi, if many, it can get really bloated if # turned on. Default is Off. # # You will need the following packages: # LWP::UserAgent (You can install this using cpan -i LWP::UserAgent) # Crypt::SSLeay (You can install this using cpan -i Crypt::SSLeay) # # Or if you're using Debian GNU/Linux: # apt-get update;apt-get install libwww-perl libcrypt-ssleay-perl # ##################################################################### use Irssi; use Irssi::Irc; use vars qw($VERSION %IRSSI); use LWP::UserAgent; use HTTP::Request::Common; use URI::Escape; use Getopt::Long; $VERSION = "0.1"; %IRSSI = ( authors => "Roni 'rolle' Laukkarinen", contact => "roni\@laukkarinen.info", name => "irssinma", description => "Sends notifications to Notify My Android when away", license => "GPLv2", url => "http://roni.laukkarinen.info", changed => "Thu Oct 27 19:50:50 CET 2011", ); # Configuration settings and default values. Irssi::settings_add_bool("irssinma", "irssinma_general_hilight", 0); Irssi::settings_add_str("irssinma", "irssinma_API", ""); sub send_noti { my ($title, $text) = @_; my %options = (); $options{'application'} = $title; $options{'apikey'} = Irssi::settings_get_str("irssinma_API"); $options{'event'} = uri_escape($text); $options{'notification'} = ""; # Generate our HTTP request. my ($userAgent, $request, $response, $requestURL); $userAgent = LWP::UserAgent->new; $userAgent->agent("Irssinma/1.0"); $userAgent->env_proxy(); $requestURL = sprintf("https://nma.usk.bz/publicapi/notify?apikey=%s&application=%s&event=%s&description=%s&priority=0", $options{'apikey'}, $options{'application'}, $options{'event'}, $options{'notification'}); $request = HTTP::Request->new(GET => $requestURL); $response = $userAgent->request($request); if ($response->is_success) { # No info needed if working, right? #Irssi::print("Notification successfully posted to Notify My Android app.\n"); } else { Irssi::print("Notification not posted: " . $response->content); } } sub pubmsg { my ($server, $data, $nick) = @_; if($server->{usermode_away} == 1 && $data =~ /$server->{nick}/i){ send_noti("Hilight received in Irssi", $nick . ': ' . $data); } } sub privmsg { my ($server, $data, $nick) = @_; if($server->{usermode_away} == 1){ send_noti("Private Message received in Irssi ", $nick . ': ' . $data); } } sub genhilight { my($dest, $text, $stripped) = @_; my $server = $dest->{server}; if($dest->{level} & MSGLEVEL_HILIGHT) { if($server->{usermode_away} == 1){ if(Irssi::settings_get_bool("irssinma_general_hilight")){ send_noti("General Hilight received in Irssi ", $stripped); } } } } Irssi::signal_add_last('message public', 'pubmsg'); Irssi::signal_add_last('message private', 'privmsg'); Irssi::signal_add_last('print text', 'genhilight');