/var/www/www.irssi.org-old/scripts/html/away_hilight_notice.pl
1 #!/usr/bin/perl -w
2
3 ## Bugreports and Licence disclaimer.
4 #
5 # For bugreports and other improvements contact Geert Hauwaerts <geert@irssi.org>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this script; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #
21 ##
22
23 use strict;
24 use Irssi;
25 use vars qw($VERSION %IRSSI);
26
27 $VERSION = "0.10";
28
29 %IRSSI = (
30 authors => 'Geert Hauwaerts',
31 contact => 'geert@irssi.org',
32 name => 'away_hilight_notice.pl',
33 description => 'This script will notice your away message to the person who just hilighted you.',
34 license => 'GNU General Public License',
35 url => 'http://irssi.hauwaerts.be/away_hilight_notice.pl',
36 changed => 'Wed Dec 31 15:37:24 2003',
37 );
38
39 ## Comments and remarks.
40 #
41 # This script uses settings. The default time between notices sent to the
42 # same person are 3600 seconds or once an hour. Use /SET to change the
43 # timeout value.
44 #
45 # Setting: away_hilight_notice_timeout
46 #
47 ##
48
49 Irssi::theme_register([
50 'away_hilight_notice_loaded', '%R>>%n %_Scriptinfo:%_ Loaded $0 version $1 by $2.'
51 ]);
52
53 my %lasthilight;
54 my $timeout;
55 my $ctimeout;
56
57 sub away_hilight_notice {
58
59 my ($dest, $text, $stripped) = @_;
60 my $server = $dest->{server};
61 my ($hilight) = Irssi::parse_special('$;');
62
63 return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT) || ($dest->{level} & (MSGLEVEL_MSGS|MSGLEVEL_NOTICES|MSGLEVEL_SNOTES|MSGLEVEL_CTCPS|MSGLEVEL_ACTIONS|MSGLEVEL_JOINS|MSGLEVEL_PARTS|MSGLEVEL_QUITS|MSGLEVEL_KICKS|MSGLEVEL_MODES|MSGLEVEL_TOPICS|MSGLEVEL_WALLOPS|MSGLEVEL_INVITES|MSGLEVEL_NICKS|MSGLEVEL_DCC|MSGLEVEL_DCCMSGS|MSGLEVEL_CLIENTNOTICE|MSGLEVEL_CLIENTERROR)));
64
65 if ($server->{usermode_away}) {
66
67 if (!$lasthilight{lc($hilight)}{'last'}) {
68 $lasthilight{lc($hilight)}{'last'} = time();
69 $server->command("^NOTICE $hilight I'm sorry, but I'm away ($server->{away_reason})");
70 return;
71 }
72
73 $timeout = time() - $lasthilight{lc($hilight)}{'last'};
74 $ctimeout = Irssi::settings_get_str('away_hilight_notice_timeout');
75
76 if ($timeout > $ctimeout) {
77 $lasthilight{lc($hilight)}{'last'} = time();
78 $server->command("^NOTICE $hilight I'm sorry, but I'm away ($server->{away_reason})");
79 }
80 }
81 }
82
83 sub clear_associative_array {
84
85 my ($server) = @_;
86
87 if (!$server->{usermode_away}) {
88 %lasthilight = ();
89 }
90 }
91
92 Irssi::signal_add('print text', 'away_hilight_notice');
93 Irssi::signal_add('away mode changed', 'clear_associative_array');
94 Irssi::settings_add_str('away', 'away_hilight_notice_timeout' => 3600);
95 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'away_hilight_notice_loaded', $IRSSI{name}, $VERSION, $IRSSI{authors});