Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for network tags in the push sent to the phone and command /irssinotifier with help info #192

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 88 additions & 14 deletions Irssi/irssinotifier.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
use POSIX;
use Encode;
use vars qw($VERSION %IRSSI);

$VERSION = "21";
$VERSION = "22";
%IRSSI = (
authors => "Lauri \'murgo\' Härsilä",
contact => "murgo\@iki.fi",
name => "IrssiNotifier",
description => "Send notifications about irssi highlights to server",
license => "Apache License, version 2.0",
url => "https://irssinotifier.appspot.com",
changed => "2016-03-26"
changed => "2017-02-22"
);

# Sometimes, for some unknown reason, perl emits warnings like the following:
Expand All @@ -35,6 +34,7 @@
my $lastDcc = 0;
my $notifications_sent = 0;
my @delayQueue = ();
my $lastTag;

my $screen_socket_path;

Expand All @@ -46,6 +46,7 @@ sub private {
$lastTarget = "!PRIVATE";
$lastWindow = $nick;
$lastDcc = 0;
$lastTag = $server->{tag};
}

sub joined {
Expand All @@ -66,6 +67,7 @@ sub public {
$lastTarget = $target;
$lastWindow = $target;
$lastDcc = 0;
$lastTag = $server->{tag};
}

sub dcc {
Expand All @@ -74,7 +76,7 @@ sub dcc {
$lastMsg = $msg;
$lastNick = $dcc->{nick};
$lastTarget = "!PRIVATE";
$lastWindow = $dcc->{target};
$lastWindow = $dcc->{tag};
$lastDcc = 1;
}

Expand Down Expand Up @@ -211,6 +213,7 @@ sub send_notification {
'nick' => $lastNick,
'target' => $lastTarget,
'added' => time,
'tag' => $lastTag,
};
} else {
Irssi::print("IrssiNotifier: previous send is still in progress and queue is full, skipping notification");
Expand Down Expand Up @@ -263,6 +266,10 @@ sub send_to_api {
my $wget_cmd = "wget --tries=2 --timeout=10 --no-check-certificate -qO- /dev/null";
my $api_url;
my $data;

if (Irssi::settings_get_str('irssinotifier_enable_network_tag')) {
$lastNick = "$lastNick on $lastTag"
}

if ($type eq 'notification') {
$lastMsg = Irssi::strip_codes($lastMsg);
Expand Down Expand Up @@ -353,7 +360,7 @@ sub encrypt {
fcntl($r, F_SETFD, $flags & ~FD_CLOEXEC) or die "fcntl F_SETFD: $!";

my $rfn = fileno($r);
my $pid = open2(my $out, my $in, qw(openssl enc -aes-128-cbc -salt -base64 -A -pass), "fd:$rfn");
my $pid = open2(my $out, my $in, qw(openssl enc -aes-128-cbc -salt -base64 -md md5 -A -pass), "fd:$rfn");

print $w "$password";
close $w;
Expand Down Expand Up @@ -466,6 +473,68 @@ sub event_key_pressed {
}
}

sub irssinotifier {
my ($data, $server, $witem) = @_;
my ($args, $rest) = Irssi::command_parse_options('irssinotifier', $data);
ref $args or return 0;

if (!exists $args->{nick}) {
Irssi::print("You need to use -nick and nickname after it");
return 0;
} elsif ( !length $args->{nick}) {
Irssi::print("you need to specify a nickname after -nick");
return 0;
}

if ($args->{nick} and !length $rest ) {
Irssi::print("You need to specify a message");
return 0;
}

$lastNick = $args->{nick};
$lastMsg = $rest;
if ($args->{channel}){
$lastTarget = "$args->{channel}";
} else {
$lastTarget = "!PRIVATE";
}
send_to_api();
}

sub irssinotifier_help {
my ($args) = @_;
if ($args =~ /^irssinotifier *$/i) {
print CLIENTCRAP <<HELP

Syntax:

irssinotifier [-nick <text>] [-channel #<text>] <text>

%U%_Description:%_%U

The command is used to manually send messages using the irssinotifier API

%U%_Parameters:%_%U

-nick The nick name that should be presented in the android application.

-channel The channel name that should be presented in the android application.
# is mandator in the name.

<text> The message you like to send

%U%_Example:%_%U

Send a message as Foo to your phone
/irssinotifier -nick foo I hope you got my message now
Send a message as Foo in #channel
/irssinotifier -nick foo -channel #channel I hope you got this message too
HELP
;
Irssi::signal_stop;
}
}

Irssi::settings_add_str('irssinotifier', 'irssinotifier_encryption_password', 'password');
Irssi::settings_add_str('irssinotifier', 'irssinotifier_api_token', '');
Irssi::settings_add_str('irssinotifier', 'irssinotifier_https_proxy', '');
Expand All @@ -480,17 +549,22 @@ sub event_key_pressed {
Irssi::settings_add_bool('irssinotifier', 'irssinotifier_clear_notifications_when_viewed', 0);
Irssi::settings_add_int('irssinotifier', 'irssinotifier_require_idle_seconds', 0);
Irssi::settings_add_bool('irssinotifier', 'irssinotifier_enable_dcc', 1);
Irssi::settings_add_bool('irssinotifier', 'irssinotifier_enable_network_tag', 0);

# these commands are renamed
Irssi::settings_remove('irssinotifier_ignore_server');
Irssi::settings_remove('irssinotifier_ignore_channel');

Irssi::signal_add('message irc action', 'public');
Irssi::signal_add('message public', 'public');
Irssi::signal_add('message private', 'private');
Irssi::signal_add('message join', 'joined');
Irssi::signal_add('message dcc', 'dcc');
Irssi::signal_add('message dcc action', 'dcc');
Irssi::signal_add('print text', 'print_text');
Irssi::signal_add('setup changed', 'are_settings_valid');
Irssi::signal_add('window changed', 'check_window_activity');
Irssi::signal_add('message irc action', 'public');
Irssi::signal_add('message public', 'public');
Irssi::signal_add('message private', 'private');
Irssi::signal_add('message join', 'joined');
Irssi::signal_add('message dcc', 'dcc');
Irssi::signal_add('message dcc action', 'dcc');
Irssi::signal_add('print text', 'print_text');
Irssi::signal_add('setup changed', 'are_settings_valid');
Irssi::signal_add('window changed', 'check_window_activity');
Irssi::command_bind('irssinotifier', 'irssinotifier');
Irssi::command_bind_first('help', 'irssinotifier_help');
Irssi::command_set_options('irssinotifier', '+nick +channel');

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#IrssiNotifier

Get notifications from IRC hilights and private messages from Irssi to Android.
Get notifications from IRC hilights and private messages from Irssi to Android.

Check it out on [Google Play](https://play.google.com/store/apps/details?id=fi.iki.murgo.irssinotifier)!

Expand Down