]> jfr.im git - irssi-scripts.git/commitdiff
updates
authorzonidjan <redacted>
Sat, 13 Nov 2021 00:55:41 +0000 (18:55 -0600)
committerzonidjan <redacted>
Sat, 13 Nov 2021 00:55:41 +0000 (18:55 -0600)
autorun/active_notice.pl [deleted symlink]
autorun/nohilight.pl [deleted symlink]
autorun/smshi.pl [deleted symlink]
autorun/smshilight.pl [new symlink]
screen_away.pl
smshilight.pl

diff --git a/autorun/active_notice.pl b/autorun/active_notice.pl
deleted file mode 120000 (symlink)
index 49be9b2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../active_notice.pl
\ No newline at end of file
diff --git a/autorun/nohilight.pl b/autorun/nohilight.pl
deleted file mode 120000 (symlink)
index f24609d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../nohilight.pl
\ No newline at end of file
diff --git a/autorun/smshi.pl b/autorun/smshi.pl
deleted file mode 120000 (symlink)
index 151bbfa..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../smshi.pl
\ No newline at end of file
diff --git a/autorun/smshilight.pl b/autorun/smshilight.pl
new file mode 120000 (symlink)
index 0000000..8d35070
--- /dev/null
@@ -0,0 +1 @@
+../smshilight.pl
\ No newline at end of file
index 86e3087b63d0f265e6c3c8b78597a630616e56d0..90d5d22da6eacb97f5f21659d329ea577076d6d8 100644 (file)
@@ -101,7 +101,8 @@ if ($socket !~ /^No Sockets found/s) {
   # ok, should have only one socket
   $socket_name = $ENV{'STY'};
   $socket_path = $socket;
-  $socket_path =~ s/^.+\d+ Sockets? in ([^\n]+)\.\n.+$/$1/s;
+                    #1 Socket in /run/screen/S-jrunyon.
+  $socket_path =~ s/^.*\d+ Sockets? in ([^\n]+)\.\s.+$/$1/s;
   if (length($socket_path) != length($socket)) {
     # only activate, if string length is different
     # (to make sure, we really got a dir name)
@@ -110,8 +111,7 @@ if ($socket !~ /^No Sockets found/s) {
     Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
       "error reading screen informations from:");
     Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
-      "$socket");
-    return;
+      "$socket_path/$socket");
   }
 }
 
index 658aa5095cd65d6af0c365138234d590fcefe366..4766d6f98e7a9382d69a87dfa655421cc795a363 100644 (file)
@@ -1,6 +1,38 @@
 # smshi - sends highlights via SMS, using Twilio
 # CC0 https://creativecommons.org/publicdomain/zero/1.0/
 
+# settings:
+# (bool)   smshi_active
+#   Master switch. Nothing will be done if this is OFF.
+#
+# (bool)   smshi_away_only
+#   Only send SMS when away.
+#
+# (bool)   smshi_detached_only
+#   Only send SMS when screen is detached.
+#
+# (bool)   smshi_debug
+#   Show debugging info (about communications with Twilio)
+#
+# (string) smshi_sid
+#   Twilio SID
+#
+# (string) smshi_token
+#   Twilio token
+#
+# (string) smshi_from
+#   From number (int'l format, i.e. +12022345678)
+#
+# (string) smshi_to
+#   To number   (int'l format, i.e. +12022345678)
+#
+# N.B. you are recommended to set the following values if using screen and
+# you don't want SMS when attached, even if using screen_away (since it takes
+# multiple seconds to detect, while our detached_only checks at the time of
+# the highlight):
+#   smshi_away_only OFF
+#   smshi_detached_only ON
+
 use strict;
 use warnings;
 
@@ -10,7 +42,7 @@ use vars qw($VERSION %IRSSI);
 use LWP::UserAgent;
 my $ua = LWP::UserAgent->new;
 
-$VERSION = "1.0";
+$VERSION = "2.0";
 $ua->agent("irssi+SMSHi/$VERSION ");
 %IRSSI = (
        authors     => "John Runyon",
@@ -27,27 +59,34 @@ sub got_print {
        my ($dest, $text, $stripped) = @_;
        my $server = $dest->{server};
        my $mynick = $server->{nick};
-       return unless ($dest->{level} & MSGLEVEL_HILIGHT) # continue if hilight...
-                  or ($dest->{level} & MSGLEVEL_MSGS && index($stripped, $mynick) != -1); # or if it's a PM containing my nick
-       return if $stripped =~ /<.?\Q$mynick\E>/; # avoid people quoting me
-       return if (!$server->{usermode_away} && Irssi::settings_get_bool('smshi_away_only')); # and obey away_only
-
-       my $msg = '';
-       for my $c (split //, $stripped) {
-               if (ord($c) > 31 && ord($c) < 127) {
-                       $msg .= $c;
-               } else {
-                       $msg .= '\\x'.sprintf("%02x", ord($c));
-               }
-       }
+       return unless ($dest->{level} & MSGLEVEL_HILIGHT # continue if hilight...
+                   || $dest->{level} & MSGLEVEL_MSGS && index($stripped, $mynick) != -1); # or if it's a PM containing my nick
+       return if $stripped =~ /<[ +%@&~!]?\Q$mynick\E>/; # avoid people quoting me
+       return if (Irssi::settings_get_bool('smshi_away_only') && !$server->{usermode_away}); # and obey away_only
+       print _is_attached() if Irssi::settings_get_bool('smshi_debug');
+       return if (Irssi::settings_get_bool('smshi_detached_only') && _is_attached()); # and obey detached_only
 
        my $chname = $dest->{window}->get_active_name();
-       my $sms = $server->{tag}."/".$chname.$msg;
+       my $sms = $server->{tag}."/".$chname.$stripped;
        _send_sms($sms);
 }
+
+sub _is_attached {
+       return 0 if !defined($ENV{HOME});
+       return 0 if !defined($ENV{USER});
+       return 0 if !defined($ENV{STY});
+       my @dirs = ("/run/screen/S-$ENV{USER}/$ENV{STY}", "/usr/tmp/screens/S-$ENV{USER}/$ENV{STY}", "$ENV{HOME}/.screen/$ENV{STY}", "/tmp/screens/S-$ENV{USER}/$ENV{STY}");
+       push(@dirs, "$ENV{SCREENDIR}/$ENV{STY}") if defined($ENV{SCREENDIR});
+       for (@dirs) {
+               return 1 if -x;
+       }
+       return 0;
+}
+
 sub test_sms {
        _send_sms("This is an SMS test.");
 }
+
 sub _send_sms {
        my $sms = shift;
 
@@ -74,13 +113,14 @@ sub _send_sms {
        }
 }
 
-Irssi::settings_add_bool('smshi', 'smshi_active', 0);    # master switch
-Irssi::settings_add_bool('smshi', 'smshi_away_only', 1); # send only when away?
-Irssi::settings_add_bool('smshi', 'smshi_debug', 0);     # show debugging info
-Irssi::settings_add_str('smshi', 'smshi_sid', '');       # Twilio SID
-Irssi::settings_add_str('smshi', 'smshi_token', '');     # Twilio token
-Irssi::settings_add_str('smshi', 'smshi_from', '');      # From number (+12022345678)
-Irssi::settings_add_str('smshi', 'smshi_to', '');        # To number (+12022345678)
+Irssi::settings_add_bool('smshi', 'smshi_active', 0);        # master switch
+Irssi::settings_add_bool('smshi', 'smshi_away_only', 1);     # send only when away?
+Irssi::settings_add_bool('smshi', 'smshi_detached_only', 0); # send only when screen detached?
+Irssi::settings_add_bool('smshi', 'smshi_debug', 0);         # show debugging info
+Irssi::settings_add_str('smshi', 'smshi_sid', '');           # Twilio SID
+Irssi::settings_add_str('smshi', 'smshi_token', '');         # Twilio token
+Irssi::settings_add_str('smshi', 'smshi_from', '');          # From number (+12022345678)
+Irssi::settings_add_str('smshi', 'smshi_to', '');            # To number (+12022345678)
 
 Irssi::signal_add('print text', 'got_print');
 Irssi::command_bind('testsms', 'test_sms');