annotate .irssi/scripts/screen_away.pl @ 445:b0264224e2ec

compilation tweaks: tried and failed to fix hg compilation stuff I can't figure out why it's not working, but it's at least a little more hackable now.
author Augie Fackler <raf@durin42.com>
date Sat, 30 Sep 2017 06:47:10 -0400
parents a4734cd2ba01
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 use Irssi;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 use strict;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 use FileHandle;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 use vars qw($VERSION %IRSSI);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 $VERSION = "0.9.7.1";
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 %IRSSI = (
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9 authors => 'Andreas \'ads\' Scherbaum <ads@wars-nicht.de>',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 name => 'screen_away',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
11 description => 'set (un)away, if screen is attached/detached',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12 license => 'GPL v2',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 url => 'none',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14 );
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 # screen_away irssi module
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 # written by Andreas 'ads' Scherbaum <ads@ufp.de>
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 # changes:
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 # 07.02.2004 fix error with away mode
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 # thanks to Michael Schiansky for reporting and fixing this one
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 # 07.08.2004 new function for changing nick on away
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 # 24.08.2004 fixing bug where the away nick was not storedcorrectly
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 # thanks for Harald Wurpts for help debugging this one
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 # 17.09.2004 rewrote init part to use $ENV{'STY'}
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 # 05.12.2004 add patch for remember away state
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 # thanks to Jilles Tjoelker <jilles@stack.nl>
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 # change "chatnet" to "tag"
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 # 18.05.2007 fix '-one' for SILC networks
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 # usage:
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 # put this script into your autorun directory and/or load it with
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 # /SCRIPT LOAD <name>
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 # there are 5 settings available:
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 # /set screen_away_active ON/OFF/TOGGLE
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
41 # /set screen_away_repeat <integer>
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 # /set screen_away_message <string>
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
43 # /set screen_away_window <string>
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44 # /set screen_away_nick <string>
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 # active means, that you will be only set away/unaway, if this
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 # flag is set, default is ON
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 # repeat is the number of seconds, after the script will check the
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
49 # screen status again, default is 5 seconds
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 # message is the away message sent to the server, default: not here ...
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51 # window is a window number or name, if set, the script will switch
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 # to this window, if it sets you away, default is '1'
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53 # nick is the new nick, if the script goes away
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54 # will only be used it not empty
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56 # normal you should be able to rename the script to something other
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 # than 'screen_away' (as example, if you dont like the name) by simple
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 # changing the 'name' parameter in the %IRSSI hash at the top of this script
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 # variables
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62 my $timer_name = undef;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 my $away_status = 0;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 my %old_nicks = ();
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 my %away = ();
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 # Register formats
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 Irssi::theme_register(
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 [
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 'screen_away_crap',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 '{line_start}{hilight ' . $IRSSI{'name'} . ':} $0'
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72 ]);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 # if we are running
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 my $screen_away_used = 0;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 # try to find out, if we are running in a screen
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 # (see, if $ENV{STY} is set
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 if (!defined($ENV{STY})) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 # just return, we will never be called again
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 "could not open status file for parent process (pid: " . getppid() . "): $!");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 return;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 my ($socket_name, $socket_path);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 # search for socket
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 # normal we could search the socket file, ... if we know the path
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
90 # but so we have to call one time the screen executable
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91 # disable locale
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 # the quotes around C force perl 5.005_03 to use the shell
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 # thanks to Jilles Tjoelker <jilles@stack.nl> for pointing this out
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
94 my $socket = `LC_ALL="C" screen -ls`;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
96
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
97
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
98 my $running_in_screen = 0;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99 # locale doesnt seems to be an problem (yet)
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100 if ($socket !~ /^No Sockets found/s) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 # ok, should have only one socket
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 $socket_name = $ENV{'STY'};
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 $socket_path = $socket;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104 $socket_path =~ s/^.+\d+ Sockets? in ([^\n]+)\.\n.+$/$1/s;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
105 if (length($socket_path) != length($socket)) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106 # only activate, if string length is different
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
107 # (to make sure, we really got a dir name)
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
108 $screen_away_used = 1;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
109 } else {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
110 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
111 "error reading screen informations from:");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
113 "$socket");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
114 return;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
115 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 # last check
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119 if ($screen_away_used == 0) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
120 # we will never be called again
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
121 return;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
123
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124 # build complete socket name
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 $socket = $socket_path . "/" . $socket_name;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 # register config variables
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128 Irssi::settings_add_bool('misc', $IRSSI{'name'} . '_active', 1);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129 Irssi::settings_add_int('misc', $IRSSI{'name'} . '_repeat', 5);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 Irssi::settings_add_str('misc', $IRSSI{'name'} . '_message', "not here ...");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
131 Irssi::settings_add_str('misc', $IRSSI{'name'} . '_window', "1");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132 Irssi::settings_add_str('misc', $IRSSI{'name'} . '_nick', "");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
133
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
134 # init process
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
135 screen_away();
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137 # screen_away()
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139 # check, set or reset the away status
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
140 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141 # parameter:
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
142 # none
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
143 # return:
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
144 # 0 (OK)
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 sub screen_away {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 my ($away, @screen, $screen);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 # only run, if activated
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 if (Irssi::settings_get_bool($IRSSI{'name'} . '_active') == 1) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
150 if ($away_status == 0) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 # display init message at first time
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 "activating $IRSSI{'name'} (interval: " . Irssi::settings_get_int($IRSSI{'name'} . '_repeat') . " seconds)");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155 # get actual screen status
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
156 my @screen = stat($socket);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157 # 00100 is the mode for "user has execute permissions", see stat.h
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
158 if (($screen[2] & 00100) == 0) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
159 # no execute permissions, Detached
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
160 $away = 1;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 } else {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 # execute permissions, Attached
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163 $away = 2;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
165
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
166 # check if status has changed
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
167 if ($away == 1 and $away_status != 1) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 # set away
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
169 if (length(Irssi::settings_get_str($IRSSI{'name'} . '_window')) > 0) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
170 # if length of window is greater then 0, make this window active
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
171 Irssi::command('window goto ' . Irssi::settings_get_str($IRSSI{'name'} . '_window'));
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
172 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
173 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
174 "Set away");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
175 my $message = Irssi::settings_get_str($IRSSI{'name'} . '_message');
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
176 if (length($message) == 0) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
177 # we have to set a message or we wouldnt go away
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178 $message = "not here ...";
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
179 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
180 my ($server);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
181 foreach $server (Irssi::servers()) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
182 if (!$server->{usermode_away}) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
183 # user isnt yet away
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184 $away{$server->{'tag'}} = 0;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
185 $server->command("AWAY " . (($server->{chat_type} ne 'SILC') ? "-one " : "") . "$message") if (!$server->{usermode_away});
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
186 if (length(Irssi::settings_get_str($IRSSI{'name'} . '_nick')) > 0) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
187 # only change, if actual nick isnt already the away nick
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
188 if (Irssi::settings_get_str($IRSSI{'name'} . '_nick') ne $server->{nick}) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
189 # keep old nick
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
190 $old_nicks{$server->{'tag'}} = $server->{nick};
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
191 # set new nick
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
192 $server->command("NICK " . Irssi::settings_get_str($IRSSI{'name'} . '_nick'));
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
193 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
194 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
195 } else {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
196 # user is already away, remember this
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
197 $away{$server->{'tag'}} = 1;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
198 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
199 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
200 $away_status = $away;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
201 } elsif ($away == 2 and $away_status != 2) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
202 # unset away
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
203 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'screen_away_crap',
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
204 "Reset away");
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
205 my ($server);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
206 foreach $server (Irssi::servers()) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
207 if ($away{$server->{'tag'}} == 1) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
208 # user was already away, dont reset away
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
209 $away{$server->{'tag'}} = 0;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
210 next;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
211 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
212 $server->command("AWAY" . (($server->{chat_type} ne 'SILC') ? " -one" : "")) if ($server->{usermode_away});
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
213 if (defined($old_nicks{$server->{'tag'}}) and length($old_nicks{$server->{'tag'}}) > 0) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
214 # set old nick
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
215 $server->command("NICK " . $old_nicks{$server->{'tag'}});
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
216 $old_nicks{$server->{'tag'}} = "";
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
217 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
218 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
219 $away_status = $away;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
220 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
221 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
222 # but everytimes install a new timer
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
223 register_screen_away_timer();
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
224 return 0;
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
225 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
226
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
227 # register_screen_away_timer()
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
228 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
229 # remove old timer and install a new one
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
230 #
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
231 # parameter:
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
232 # none
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
233 # return:
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
234 # none
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
235 sub register_screen_away_timer {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
236 if (defined($timer_name)) {
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
237 # remove old timer, if defined
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
238 Irssi::timeout_remove($timer_name);
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
239 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
240 # add new timer with new timeout (maybe the timeout has been changed)
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
241 $timer_name = Irssi::timeout_add(Irssi::settings_get_int($IRSSI{'name'} . '_repeat') * 1000, 'screen_away', '');
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
242 }
a4734cd2ba01 Add screen_away irssi script.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
243