Skip to content

Instantly share code, notes, and snippets.

@schmiatz
Created May 6, 2018 13:51
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 schmiatz/0d7a8b11178a88a227e65a35459318eb to your computer and use it in GitHub Desktop.
Save schmiatz/0d7a8b11178a88a227e65a35459318eb to your computer and use it in GitHub Desktop.
Send a notification to Simplepush.io when you receive a new private message and are not attached to screen.
use strict;
use warnings;
use Irssi;
use vars qw($VERSION %IRSSI);
$VERSION = "1.0";
%IRSSI = (
authors => 'x70b1',
name => 'simplepush.pl',
description =>
'Send a notification to Simplepush.io when you receive a new private message and are not attached to screen.',
url => 'https://gist.github.com/x70b1/9ee8b1ce067e3d31d626f6a3af99955d',
changed => '2017-11-16',
);
my $username = "username";
my $silence = 30;
my $timestamp = time() - $silence;
sub simplepush {
my ( $title, $message ) = @_;
my $screen = system("screen -ls | grep -q Detached");
if ( !$screen ) {
if ( ( $timestamp + $silence ) < time() ) {
system("bash ~/.irssi/scripts/send-encrypted.sh -k xxxx -p xxxx -s xxxx -e irssi -t '$title' -m '$message'");
$timestamp = time();
} else {
$timestamp = time();
}
}
}
sub push_message {
my ( $server, $msg, $nick, $address, $target ) = @_;
simplepush( "$nick", "Ping!" );
}
sub push_mention {
my ( $server, $msg, $nick, $address, $target ) = @_;
if ( index( $msg, $username ) != -1 ) {
simplepush( "$target", "$nick: $msg" );
}
}
Irssi::signal_add_last( 'message private', 'push_message' );
Irssi::signal_add_last( 'message public', 'push_mention' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment