Last active
July 31, 2018 10:17
-
-
Save beekhof/c8db70d180e0d4778c7dab2d764f15a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 File::stat; | |
use Irssi; | |
$VERSION = '0.0.3'; | |
%IRSSI = ( | |
authors => 'Andrew Beekhof', | |
contact => '[email protected]', | |
name => 'fnotify', | |
description => 'Write a notification to a file that shows who is talking to you in which channel.', | |
url => 'http://www.leemhuis.info/files/fnotify/', | |
license => 'GNU General Public License', | |
changed => '$Date: 2007-01-13 12:00:00 +0100 (Sat, 13 Jan 2007) $' | |
); | |
#-------------------------------------------------------------------- | |
# In parts based on knotify.pl 0.1.1 by Hugo Haas | |
# http://larve.net/people/hugo/2005/01/knotify.pl | |
# which is based on osd.pl 0.3.3 by Jeroen Coekaerts, Koenraad Heijlen | |
# http://www.irssi.org/scripts/scripts/osd.pl | |
# | |
# Other parts based on notify.pl from Luke Macken | |
# http://fedora.feedjack.org/user/918/ | |
# | |
# ssmtp email notification support added by Joel Bastos | |
# http://kintoandar.blogspot.com | |
# | |
#-------------------------------------------------------------------- | |
# Please set the variables (don't forget to escape "\" the "@" symbol like the example) | |
my $EMAIL = "someone\@example.com"; | |
my $SSMTP = "/sbin/ssmtp"; | |
sub debug { | |
my $text = shift; | |
my @caller = caller(1); | |
#print('Called: From '.$caller[3].': '.$text); | |
return unless Irssi::settings_get_bool('notify_debug'); | |
Irssi::print('From '.$caller[3].': '.$text); | |
} | |
# check our away status & pushsafer_only_if_away. returns 0 if it's ok to send a message. | |
sub check_away { | |
my ($server) = @_; | |
# my $msg_only_if_away = Irssi::settings_get_bool('pushsafer_only_if_away'); | |
# if ($msg_only_if_away && $server->{usermode_away} != '1') { | |
return 0 if ($server->{usermode_away} == '1'); | |
return 0 if Irssi::settings_get_bool('notify_enabled'); | |
debug("Only sending messages if we're marked as away, and we're not"); | |
return 1; | |
} | |
#-------------------------------------------------------------------- | |
# Private message parsing | |
#-------------------------------------------------------------------- | |
sub priv_msg { | |
my ($server,$msg,$nick,$address,$target) = @_; | |
if(check_away($server)) { | |
return; | |
} | |
notify_trigger($server, $nick, $nick." " .$msg ); | |
} | |
#-------------------------------------------------------------------- | |
# Printing hilight's | |
#-------------------------------------------------------------------- | |
sub hilight { | |
my ($dest, $text, $stripped) = @_; | |
my $server = $dest->{server}; | |
my $target = $dest->{target}; | |
return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT)); | |
$stripped =~ s/^\s+|\s+$//g; | |
notify_trigger($server, $target, $target. " " .$stripped ); | |
} | |
#-------------------------------------------------------------------- | |
# The actual printing | |
#-------------------------------------------------------------------- | |
sub notify_send { | |
my ($notify_file, $target) = @_; | |
debug("Sending notification for $target from $notify_file"); | |
my $mail=`echo "Subject: IRSSI-$target" | cat - $notify_file|$SSMTP $EMAIL`; | |
unlink($notify_file); | |
debug("Unlinked $notify_file"); | |
} | |
sub notify_trigger { | |
my ($server, $target, $text) = @_; | |
# FIXME: there is probably a better way to get the irssi-dir... | |
my $date = `date` ; | |
my $notify_file = "$ENV{HOME}/.irssi/notify.$target"; | |
my $delay = Irssi::settings_get_int('notify_interval'); | |
my $stat_epoch = 0; | |
my $now = time(); | |
if(check_away($server)) { | |
return; | |
} | |
if ( -f $notify_file ) { | |
$stat_epoch = stat( $notify_file )->ctime; | |
} | |
if ($stat_epoch + $delay < $now ) { | |
my $tag = Irssi::timeout_add_once($delay * 1000, sub { notify_send($notify_file, $target); }, []); | |
if ( -f $notify_file ) { | |
debug("Re-started timer for $notify_file: $tag"); | |
} elsif ( $tag != "" ) { | |
debug("Started timer for $notify_file: $tag"); | |
} | |
} else { | |
debug("Timer for $target is active"); | |
} | |
open(FILE,">>$notify_file"); | |
print FILE $date . $text . "\n\n"; | |
close (FILE); | |
debug("Content written"); | |
} | |
sub notify_test { | |
my ($data, $server, $witem) = @_; | |
my $notify_file = "$ENV{HOME}/.irssi/notify.test"; | |
debug("testing functionality"); | |
open(FILE,">>$notify_file"); | |
print FILE "old text here\n\n"; | |
close (FILE); | |
# sleep(Irssi::settings_get_int('notify_interval') + 2); | |
notify_trigger($server, "test", "testing functionality" ); | |
notify_trigger($server, "test", "testing flood functionality" ); | |
debug("testing complete"); | |
} | |
sub notify_on { | |
# my ($data, $server, $item) = @_; | |
#return Irssi::print("No hostmask given.", MSGLEVEL_CLIENTCRAP) unless($data ne ""); | |
Irssi::settings_set_bool('notify_enabled', 1); | |
} | |
sub notify_off { | |
# my ($data, $server, $item) = @_; | |
#return Irssi::print("No hostmask given.", MSGLEVEL_CLIENTCRAP) unless($data ne ""); | |
Irssi::settings_set_bool('notify_enabled', 0); | |
} | |
#-------------------------------------------------------------------- | |
# Irssi::signal_add_last / Irssi::command_bind | |
#-------------------------------------------------------------------- | |
Irssi::settings_add_bool($IRSSI{'name'}, 'notify_debug', 1); | |
Irssi::settings_add_bool($IRSSI{'name'}, 'notify_enabled', 1); | |
Irssi::settings_add_int($IRSSI{'name'}, 'notify_interval', 60); | |
Irssi::command_bind('notify-on', \¬ify_on); | |
Irssi::command_bind('notify-off', \¬ify_off); | |
Irssi::command_bind('notify-test', \¬ify_test); | |
Irssi::signal_add_last("message private", "priv_msg"); | |
Irssi::signal_add_last("print text", "hilight"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment