Created
May 2, 2012 20:24
-
-
Save cpu/2580140 to your computer and use it in GitHub Desktop.
Irssi script to send DM's via Pushover API
This file contains 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
use strict; | |
use vars qw($VERSION %IRSSI); | |
use LWP::UserAgent; | |
use Irssi; | |
$VERSION = '0.0.1'; | |
%IRSSI = ( | |
authors => 'Daniel McCarney', | |
contact => '[email protected]', | |
name => 'pushover', | |
description => 'Send a pushover notification for private messages.', | |
url => 'https://binaryparadox.net', | |
license => 'GNU General Public License', | |
changed => '$Date: 2012-05-02 12:00:00 +0100 (Wed, 2 May 2012) $' | |
); | |
#-------------------------------------------------------------------- | |
# Based almost *entirely* on fnotify from: | |
# http://www.leemhuis.info/files/fnotify | |
#-------------------------------------------------------------------- | |
#-------------------------------------------------------------------- | |
# Private message parsing | |
#-------------------------------------------------------------------- | |
sub priv_msg { | |
my ($server,$msg,$nick,$address,$target) = @_; | |
pushdown($nick." " .$msg); | |
} | |
#-------------------------------------------------------------------- | |
# Send a pushdown notification. You must change $token and $user | |
# values to match your registered app api token and user key. | |
# | |
# Get an app token from: https://pushover.net/apps/build | |
# Get your user token from the Pushover client settings page | |
#-------------------------------------------------------------------- | |
sub pushdown { | |
my ($text) = @_; | |
my $token = "YOUR_APP_TOKEN"; | |
my $user = "YOUR_DEVICE_TOKEN"; | |
my $away_reason = !Irssi::active_server() ? undef : Irssi::active_server()->{away_reason}; | |
if(defined $away_reason && length $away_reason) | |
{ | |
my $resp = LWP::UserAgent->new()->post( | |
"https://api.pushover.net/1/messages", | |
[ | |
"token" => $token, | |
"user" => $user, | |
"message" => "DM: $text", | |
]); | |
} | |
} | |
#-------------------------------------------------------------------- | |
# Irssi::signal_add_last / Irssi::command_bind | |
#-------------------------------------------------------------------- | |
Irssi::signal_add_last("message private", "priv_msg"); | |
#- end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed to only send PushOver messages when there is a defined away message.