Commit 7473c5fbf64977eee6f043d25cc71443f186cb69

Authored by Caesar Ahlenhed
0 parents

first commit

Showing 1 changed file with 138 additions and 0 deletions   Show diff stats
pushover.pl 0 → 100644
  1 +++ a/pushover.pl
... ... @@ -0,0 +1,138 @@
  1 +use strict;
  2 +use warnings;
  3 +
  4 +#####################################################################
  5 +# This script sends notifications to your
  6 +# iPhone using the Notify My Android API when you are away.
  7 +#
  8 +#
  9 +# Commands:
  10 +# /set pushover_api_key API_KEY
  11 +# /set pushover_general_hilight on/off
  12 +# /set pushover_priority_channel -2 up to 2
  13 +# /set pushover_priority_pm -2 up to 2
  14 +# /set pushover_priority_general -2 up to 2
  15 +# /set pushover_ignore_nettag NETWORKS # Networks in this case is a
  16 +# comma separated list of
  17 +# network tags that should
  18 +# be ignored.
  19 +#
  20 +# "General hilight" basically referrs to ALL the hilights you have
  21 +# added manually in irssi, if many, it can get really bloated if
  22 +# turned on. Default is Off.
  23 +#
  24 +# You will need the following packages:
  25 +# LWP::UserAgent (You can install this using cpan -i LWP::UserAgent)
  26 +# Crypt::SSLeay (You can install this using cpan -i Crypt::SSLeay)
  27 +#
  28 +# Or if you're using Debian GNU/Linux:
  29 +# apt-get update;apt-get install libwww-perl libcrypt-ssleay-perl
  30 +#
  31 +# Creds to Kayjay for beta testing, this wouldn't have been
  32 +# possible otherwise since I don't own an Android device.
  33 +#
  34 +# eth0 will prevail. || irc.eth0.info
  35 +#
  36 +#####################################################################
  37 +
  38 +
  39 +use Irssi;
  40 +use Irssi::Irc;
  41 +use vars qw($VERSION %IRSSI);
  42 +
  43 +use LWP::UserAgent;
  44 +use HTTP::Request::Common;
  45 +
  46 +$VERSION = "0.2";
  47 +
  48 +%IRSSI = (
  49 + authors => "Caesar 'sniker' Ahlenhed",
  50 + contact => "sniker\@codebase.nu",
  51 + name => "PushoverIrssi",
  52 + description => "Sends notifonotifications when away",
  53 + license => "GPLv2",
  54 + url => "http://sniker.codebase.nu",
  55 + changed => "Sun Jan 25 16:44:25 CET 2015",
  56 +);
  57 +
  58 +# Configuration settings and default values.
  59 +Irssi::settings_add_str("PushoverIrssi", "pushover_token", "");
  60 +Irssi::settings_add_str("PushoverIrssi", "pushover_user", "");
  61 +Irssi::settings_add_str("PushoverIrssi", "pushover_device", "");
  62 +Irssi::settings_add_bool("PushoverIrssi", "pushover_general_hilight", 0);
  63 +Irssi::settings_add_str("PushoverIrssi", "pushover_priority_channel", 0);
  64 +Irssi::settings_add_str("PushoverIrssi", "pushover_priority_pm", 0);
  65 +Irssi::settings_add_str("PushoverIrssi", "pushover_priority_general", 0);
  66 +Irssi::settings_add_str("PushoverIrssi", "pushover_ignore_nettag", "");
  67 +
  68 +sub send_noti {
  69 + my ($title, $text, $priority) = @_;
  70 +
  71 + my %options = ();
  72 +
  73 + $options{'title'} = $title;
  74 + $options{'msg'} = $text;
  75 + $options{'priority'} = $priority;
  76 + $options{'token'} = Irssi::settings_get_str("pushover_user");
  77 + $options{'user'} = Irssi::settings_get_str("pushover_user");
  78 + $options{'device'} = Irssi::settings_get_str("pushover_device");
  79 +
  80 + my ($userAgent, $req, $response);
  81 + $userAgent = LWP::UserAgent->new;
  82 + $userAgent->agent("PushoverIrssi/0.1");
  83 +
  84 + $req = POST("https://api.pushover.net/1/messages.json",
  85 + [
  86 + token => $options{'token'},
  87 + user => $options{'token'},
  88 + if(defined($options{'device'})){
  89 + device => $options{'device'},
  90 + }
  91 + title => $options{'title'},
  92 + message => $options{'msg'},
  93 + priority => $options{'priority'},
  94 + ]
  95 + );
  96 +
  97 + $response = $userAgent->request($req);
  98 +
  99 + if ($response->is_success) {
  100 + # I guess it worked, eh?
  101 + } else {
  102 + Irssi::print("Notification not posted: " . $response->content);
  103 + }
  104 +}
  105 +
  106 +sub pubmsg {
  107 + my ($server, $data, $nick, $nick_addr, $target) = @_;
  108 +
  109 + if(!Irssi::settings_get_bool("pushover_general_hilight")){
  110 + if($server->{usermode_away} == 1 && $data =~ /$server->{nick}/i && index(Irssi::settings_get_str("pushover_ignore_nettag"), $server->{tag}) == -1){
  111 + send_noti("Hilighted " . $server->{tag} . "/" . $target, $nick . ': ' . $data, Irssi::settings_get_str("pushover_priority_channel"));
  112 + }
  113 + }
  114 +}
  115 +
  116 +sub privmsg {
  117 + my ($server, $data, $nick) = @_;
  118 + if($server->{usermode_away} == 1 && index(Irssi::settings_get_str("pushover_ignore_nettag"), $server->{tag}) == -1){
  119 + send_noti("PM @ " . $server->{tag}, $nick . ': ' . $data, Irssi::settings_get_str("pushover_priority_pm"));
  120 + }
  121 +}
  122 +
  123 +sub genhilight {
  124 + my($dest, $text, $stripped) = @_;
  125 + my $server = $dest->{server};
  126 +
  127 + if($dest->{level} & MSGLEVEL_HILIGHT) {
  128 + if($server->{usermode_away} == 1 && index(Irssi::settings_get_str("pushover_ignore_nettag"), $server->{tag}) == -1){
  129 + if(Irssi::settings_get_bool("pushover_general_hilight")){
  130 + send_noti("General Hilight " . $server->{tag} . "/" . $dest->{target}, $stripped, Irssi::settings_get_str("pushover_priority_general"));
  131 + }
  132 + }
  133 + }
  134 +}
  135 +
  136 +Irssi::signal_add_last('message public', 'pubmsg');
  137 +Irssi::signal_add_last('message private', 'privmsg');
  138 +Irssi::signal_add_last('print text', 'genhilight');
... ...