commit 973234fdfd9995231e7625428e9bbb23fdcbf3d6
Author: l0bsterz <hide4653@gmail.com>
Date: Fri, 9 Oct 2020 23:52:22 -0400
added base
Diffstat:
A | autorun/notifications.pl | | | 2 | ++ |
A | notifications.pl | | | 198 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | notify.pl | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | notify.pl.bak | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 366 insertions(+), 0 deletions(-)
diff --git a/autorun/notifications.pl b/autorun/notifications.pl
@@ -0,0 +1 @@
+/home/l0bster/.irssi/scripts/notifications.pl+
\ No newline at end of file
diff --git a/notifications.pl b/notifications.pl
@@ -0,0 +1,198 @@
+# notifications, an Irssi script to notify the user about incoming messages
+# Copyright (C) 2012, 2013, 2014, 2019 Jaromir Hradilek
+
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABI-
+# LITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+use Encode;
+use Net::DBus;
+use Irssi;
+
+# The character encoding of the Irssi client:
+use constant ENCODING => "UTF-8";
+
+# General script information:
+our $VERSION = '0.9.3';
+our %IRSSI = (
+ name => 'notifications',
+ description => 'Notify the user about incoming messages.',
+ authors => 'Jaromir Hradilek',
+ contact => 'jhradilek@gmail.com',
+ url => 'https://github.com/jhradilek/irssi-notifications',
+ license => 'GNU General Public License, version 3',
+ changed => '2019-06-18',
+);
+
+# Get the session message bus handle:
+our $bus = Net::DBus->session;
+
+# Get the notifications service handle:
+our $service = $bus->get_service('org.freedesktop.Notifications');
+
+# Get the relevant object handle:
+our $object = $service->get_object('/org/freedesktop/Notifications');
+
+# Display a GTK notification:
+sub display_notification {
+ my ($summary, $body) = @_;
+
+ # Convert the strings to Perl's internal representation:
+ $summary = decode(ENCODING, $summary);
+ $body = decode(ENCODING, $body);
+
+ # Display the notification:
+ $object->Notify('irssi-notifications', 0, 'im-message-new',
+ $summary, $body, [], {}, 0);
+}
+
+# Handle incoming public messages:
+sub message_public {
+ my ($server, $message, $nick, $address, $target) = @_;
+
+ # Check whether to notify the user about public messages:
+ return unless (Irssi::settings_get_bool('notifications_public_messages'));
+
+ # Check whether to notify the user about messages in the active window:
+ unless (Irssi::settings_get_bool('notifications_active_window')) {
+ # Get the name of the active window:
+ my $window = Irssi::active_win()->{active}->{name} || '';
+
+ # Ignore messages in the active window:
+ return if ($window eq $target);
+ }
+
+ # Get the user's nick name:
+ my $user = $server->{nick};
+
+ # Check whether to notify the user about indirect messages:
+ unless (Irssi::settings_get_bool('notifications_indirect_messages')) {
+ # Ignore messages that are not explicitly addressed to the user:
+ return if ($message !~ /^$user[\s:,]/);
+ }
+ else {
+ # Ignore messages that do not mention the user:
+ return if ($message !~ /\b$user\b/);
+ }
+
+ # Get the server's tag:
+ my $tag = $server->{tag};
+
+ # Prepare the message body:
+ (my $body = $message) =~ s/^$user[\s:,]\s*//;
+
+ # Notify the user about the incoming public message:
+ display_notification("Message from $nick/$tag on $target:", $body);
+}
+
+# Handle incoming private messages:
+sub message_private {
+ my ($server, $message, $nick, $address) = @_;
+
+ # Check whether to notify the user about public messages:
+ return unless (Irssi::settings_get_bool('notifications_public_messages'));
+
+ # Check whether to notify the user about messages in the active window:
+ unless (Irssi::settings_get_bool('notifications_active_window')) {
+ # Get the name of the active window:
+ my $window = Irssi::active_win()->{active}->{name} || '';
+
+ # Ignore messages in the active window:
+ return if ($window eq $nick);
+ }
+
+ # Get the server's tag:
+ my $tag = $server->{tag};
+
+ # Notify the user about the incoming private message:
+ display_notification("Message from $nick/$tag:", $message);
+}
+
+# Handle incoming DCC requests:
+sub dcc_request {
+ my ($dcc, $sendaddr) = @_;
+
+ # Check whether to notify the user about DCC requests:
+ return unless (Irssi::settings_get_bool('notifications_dcc_messages'));
+
+ # Check whether to notify the user about messages in the active window:
+ unless (Irssi::settings_get_bool('notifications_active_window')) {
+ # Get the name of the active window:
+ my $window = Irssi::active_win()->{active}->{name} || '';
+
+ # Ignore messages in the active window:
+ return unless ($window);
+ }
+
+ # Get the request type:
+ my $type = $dcc->{type};
+
+ # Get the sender's nick:
+ my $nick = $dcc->{nick};
+
+ # Get the server's tag:
+ my $tag = $dcc->{server}->{tag};
+
+ # Check the request type:
+ if ($type eq 'GET') {
+ # Get the file name and size:
+ my $name = $dcc->{arg};
+ my $size = $dcc->{size};
+
+ # Notify the user about the incoming SEND request:
+ display_notification("$nick/$tag offers a file:", "$name ($size B)");
+ }
+ elsif ($type eq 'CHAT') {
+ # Notify the user about the incoming CHAT request:
+ display_notification("$nick/$tag offers a DCC chat.", "");
+ }
+}
+
+# Handle incoming DCC CHAT messages:
+sub dcc_chat_message {
+ my ($dcc, $message) = @_;
+
+ # Check whether to notify the user about DCC requests:
+ return unless (Irssi::settings_get_bool('notifications_dcc_messages'));
+
+ # Get the sender's nick:
+ my $nick = $dcc->{id};
+
+ # Check whether to notify the user about messages in the active window:
+ unless (Irssi::settings_get_bool('notifications_active_window')) {
+ # Get the name of the active window:
+ my $window = Irssi::active_win()->{active}->{name} || '';
+
+ # Ignore messages in the active window:
+ return if ($window eq "=$nick");
+ }
+
+ # Get the server's tag:
+ my $tag = $dcc->{server}->{tag};
+
+ # Notify the user about the incoming CHAT message:
+ display_notification("DCC chat message from $nick/$tag:", $message);
+}
+
+# Register configuration options:
+Irssi::settings_add_bool('notifications', 'notifications_private_messages', 1);
+Irssi::settings_add_bool('notifications', 'notifications_public_messages', 1);
+Irssi::settings_add_bool('notifications', 'notifications_indirect_messages',0);
+Irssi::settings_add_bool('notifications', 'notifications_active_window', 0);
+Irssi::settings_add_bool('notifications', 'notifications_dcc_messages', 1);
+
+# Register signals:
+Irssi::signal_add('message public', 'message_public');
+Irssi::signal_add('message private', 'message_private');
+Irssi::signal_add('dcc request', 'dcc_request');
+Irssi::signal_add('dcc chat message', 'dcc_chat_message');
diff --git a/notify.pl b/notify.pl
@@ -0,0 +1,83 @@
+##
+## Put me in ~/.irssi/scripts, and then execute the following in irssi:
+##
+## /load perl
+## /script load notify
+##
+
+use strict;
+use Irssi;
+use vars qw($VERSION %IRSSI);
+use HTML::Entities;
+
+$VERSION = "0.5";
+%IRSSI = (
+ authors => 'Luke Macken, Paul W. Frields, underd0g, l0bster',
+ contact => 'lewk@csh.rit.edu, stickster@gmail.com, r00t@l0bster.ru, 0x0@underd0g.co',
+ name => 'notify.pl',
+ description => 'Use D-Bus to alert user to hilighted messages',
+ license => 'GNU General Public License',
+ url => 'https://github.com/l0bsterz/notify.git',
+);
+
+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 - " .
+ "notify-send -a irssi -- '" . $summary . "' '". $message . "'";
+ $server->command($cmd);
+
+ my $remote = Irssi::settings_get_str('notify_remote');
+ if ($remote ne '') {
+ my $cmd = "EXEC - ssh -q " . $remote .
+ "notify-send -a irssi -- '" . $summary . "' '". $message . "'";
+ $server->command($cmd);
+ }
+
+}
+
+sub print_text_notify {
+ my ($dest, $text, $stripped) = @_;
+ my $server = $dest->{server};
+ my $channel = $dest->{channel};
+ return if (!$server);
+ my $sender = $stripped;
+ $sender =~ s/^\<?(.+?)\>? .*/\1/ ;
+ $stripped =~ s/^.+? +(.*)/\1/ ;
+ notify($channel, $sender, $stripped);
+}
+
+sub message_private_notify {
+ my ($server, $msg, $nick, $address) = @_;
+
+ return if (!$server);
+ notify($server, "PM from ".$nick, $msg);
+}
+
+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('dcc request', 'dcc_request_notify');
diff --git a/notify.pl.bak b/notify.pl.bak
@@ -0,0 +1,83 @@
+##
+## Put me in ~/.irssi/scripts, and then execute the following in irssi:
+##
+## /load perl
+## /script load notify
+##
+
+use strict;
+use Irssi;
+use vars qw($VERSION %IRSSI);
+use HTML::Entities;
+
+$VERSION = "0.5";
+%IRSSI = (
+ authors => 'Luke Macken, Paul W. Frields',
+ contact => 'lewk@csh.rit.edu, stickster@gmail.com',
+ name => 'notify.pl',
+ description => 'Use D-Bus 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 - " .
+ "notify-send -a irssi -- '" . $summary . "' '". $message . "'";
+ $server->command($cmd);
+
+ my $remote = Irssi::settings_get_str('notify_remote');
+ if ($remote ne '') {
+ my $cmd = "EXEC - ssh -q " . $remote .
+ "notify-send -a irssi -- '" . $summary . "' '". $message . "'";
+ $server->command($cmd);
+ }
+
+}
+
+sub print_text_notify {
+ my ($dest, $text, $stripped) = @_;
+ my $server = $dest->{server};
+ #my $channel = $dest->{channel};
+ return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT));
+ my $sender = $stripped;
+ $sender =~ s/^\<?(.+?)\>? .*/\1/ ;
+ $stripped =~ s/^.+? +(.*)/\1/ ;
+ notify($server, $sender, $stripped);
+}
+
+sub message_private_notify {
+ my ($server, $msg, $nick, $address) = @_;
+
+ return if (!$server);
+ notify($server, "PM from ".$nick, $msg);
+}
+
+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('dcc request', 'dcc_request_notify');