Last active
March 4, 2020 19:06
-
-
Save Goggot/7d65e41c4cc2f91c48efd2af68999f3e to your computer and use it in GitHub Desktop.
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
## | |
## Put me in ~/.irssi/scripts, and then execute the following in irssi: | |
## | |
## /load perl | |
## /script load notify | |
## | |
## Or, put me in ~/.irssi/scripts/autorun/, I'll be loading automatically when IRSSI start | |
## | |
use strict; | |
use Irssi; | |
use vars qw($VERSION %IRSSI); | |
use HTML::Entities; | |
$VERSION = "0.5"; | |
%IRSSI = ( | |
authors => 'Bob', | |
contact => '', | |
name => 'bobthenotifier.pl', | |
description => 'Use notify-send to alert user to hilighted messages', | |
license => 'GNU General Public License', | |
url => 'http://code.google.com/p/irssi-libnotify', | |
); | |
Irssi::settings_add_str('notify', 'notify_remote', ''); | |
sub sanitize { | |
my ($text) = @_; | |
encode_entities($text,'\'<>&'); | |
my $apos = "'"; | |
my $aposenc = "\'"; | |
$text =~ s/$apos/$aposenc/g; | |
$text =~ s/"/\\"/g; | |
return $text; | |
} | |
sub notify { | |
my ($server, $summary, $message) = @_; | |
# Make the message entity-safe | |
$summary = sanitize($summary); | |
$message = sanitize($message); | |
# my $cmd = "EXEC - " . | |
# "dbus-send --session /org/irssi/Irssi org.irssi.Irssi.IrssiNotify" . | |
# " string:'" . $summary . "'" . | |
# " string:'" . $message . "'"; | |
my $cmd = "EXEC - " . "notify-send '" . $summary . "' '" . $message . "'"; | |
$server->command($cmd); | |
my $remote = Irssi::settings_get_str('notify_remote'); | |
if ($remote ne '') { | |
my $cmd = "EXEC - ssh -q " . $remote . | |
" \"dbus-send --session /org/irssi/Irssi org.irssi.Irssi.IrssiNotify" . | |
" string:'" . $summary . "'" . | |
" string:'" . $message . "'\""; | |
$server->command($cmd); | |
} | |
} | |
sub print_text_notify { | |
my ($dest, $text, $stripped) = @_; | |
my $server = $dest->{server}; | |
return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT)); | |
my $sender = $stripped; | |
$sender =~ s/^\<.([^\>]+)\>.+/\1/ ; | |
$stripped =~ s/^\<.[^\>]+\>.// ; | |
my $summary = $dest->{target} . ": " . $sender; | |
notify($server, $summary, $stripped); | |
} | |
sub message_private_notify { | |
my ($server, $msg, $nick, $address) = @_; | |
return if (!$server); | |
notify($server, "PM from " . $nick . ": ", $msg); | |
} | |
sub message_join { | |
my ($server, $channel, $nick) = @_; | |
return if (!$server); | |
notify($server, $nick . " joined", $channel); | |
} | |
sub message_notify { | |
my ($server, $msg, $nick, $address, $target) = @_; | |
return if (!$server); | |
notify($server, $target . " - " . $nick . ":", $msg); | |
} | |
sub message_invite { | |
my ($server, $channel, $nick, $address) = @_; | |
return if (!$server); | |
notify($server, $nick . " invited you to", $channel); | |
} | |
sub dcc_request_notify { | |
my ($dcc, $sendaddr) = @_; | |
my $server = $dcc->{server}; | |
return if (!$dcc); | |
notify($server, "DCC ".$dcc->{type}." request", $dcc->{nick}); | |
} | |
Irssi::signal_add('print text', 'print_text_notify'); | |
Irssi::signal_add('message private', 'message_private_notify'); | |
Irssi::signal_add('message public', 'message_notify'); | |
Irssi::signal_add('message join', 'message_join'); | |
Irssi::signal_add('message invite', 'message_invite'); | |
Irssi::signal_add('dcc request', 'dcc_request_notify'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment