diff --git a/Irssi/irssinotifier.pl b/Irssi/irssinotifier.pl index e717cf2..a6689f0 100644 --- a/Irssi/irssinotifier.pl +++ b/Irssi/irssinotifier.pl @@ -8,8 +8,7 @@ use POSIX; use Encode; use vars qw($VERSION %IRSSI); - -$VERSION = "21"; +$VERSION = "22"; %IRSSI = ( authors => "Lauri \'murgo\' Härsilä", contact => "murgo\@iki.fi", @@ -17,7 +16,7 @@ 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: @@ -35,6 +34,7 @@ my $lastDcc = 0; my $notifications_sent = 0; my @delayQueue = (); +my $lastTag; my $screen_socket_path; @@ -46,6 +46,7 @@ sub private { $lastTarget = "!PRIVATE"; $lastWindow = $nick; $lastDcc = 0; + $lastTag = $server->{tag}; } sub joined { @@ -66,6 +67,7 @@ sub public { $lastTarget = $target; $lastWindow = $target; $lastDcc = 0; + $lastTag = $server->{tag}; } sub dcc { @@ -74,7 +76,7 @@ sub dcc { $lastMsg = $msg; $lastNick = $dcc->{nick}; $lastTarget = "!PRIVATE"; - $lastWindow = $dcc->{target}; + $lastWindow = $dcc->{tag}; $lastDcc = 1; } @@ -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"); @@ -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); @@ -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; @@ -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 <] [-channel #] + +%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. + + 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', ''); @@ -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'); + diff --git a/README.md b/README.md index f83baba..169ff3f 100644 --- a/README.md +++ b/README.md @@ -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)!