Skip to content

Instantly share code, notes, and snippets.

@cpu
Created May 2, 2012 20:24
Show Gist options
  • Save cpu/2580140 to your computer and use it in GitHub Desktop.
Save cpu/2580140 to your computer and use it in GitHub Desktop.
Irssi script to send DM's via Pushover API
use strict;
use vars qw($VERSION %IRSSI);
use LWP::UserAgent;
use Irssi;
$VERSION = '0.0.1';
%IRSSI = (
authors => 'Daniel McCarney',
contact => 'daniel@binaryparadox.net',
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
@cpu
Copy link
Author

cpu commented May 3, 2012

Changed to only send PushOver messages when there is a defined away message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment