html/active_notify.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 ## Comments and remarks.
  24 #
  25 # This script uses settings, by default the broadcast will be set off.
  26 # If you  want the notify message to be shown in all the windows use
  27 # /SET or /TOGGLE to switch it on or off.
  28 #
  29 #    Setting: notify_broadcast
  30 #
  31 ##
  32 
  33 use strict;
  34 use Irssi;
  35 use vars qw($VERSION %IRSSI);
  36 
  37 $VERSION = "0.07";
  38 
  39 %IRSSI = (
  40     authors     => 'Geert Hauwaerts',
  41     contact     => 'geert@irssi.org',
  42     name        => 'active_notify.pl',
  43     description => 'This script will display notify messages into the active window or broadcast it so all the windows.',
  44     license     => 'GNU General Public License',
  45     url         => 'http://irssi.hauwaerts.be/active_notify.pl',
  46     changed     => 'Wed Sep 17 23:00:11 CEST 2003',
  47 );
  48 
  49 Irssi::theme_register([
  50     'notify_joined', '%_Notify%_: %R>>%n %_$0%_ [$1@$2] [$3] has joined /$4/.',
  51     'notify_left', '%_Notify%_: %R>>%n %_$0%_ [$1@$2] [$3] has parted /$4/.',
  52     'notify_new', '%_Notify%_: %R>>%n Added %_$0%_ to the notify list.',
  53     'notify_del', '%_Notify%_: %R>>%n Removed %_$0%_ from the notify list.',
  54     'active_notify_loaded', '%R>>%n %_Scriptinfo:%_ Loaded $0 version $1 by $2.'
  55 ]);
  56 
  57 sub notify_joined {
  58     
  59     my ($server, $nick, $user, $host, $realname, $awaymsg) = @_;
  60     my $broadcast = Irssi::settings_get_bool('notify_broadcast');
  61     my $window = Irssi::active_win();
  62 
  63     if ($broadcast) {
  64         foreach my $bwin (Irssi::windows) {
  65             $bwin->printformat(MSGLEVEL_CLIENTCRAP, 'notify_joined', $nick, $user, $host, $realname, $server->{tag});
  66         }
  67     } else {
  68         $window->printformat(MSGLEVEL_CLIENTCRAP, 'notify_joined', $nick, $user, $host, $realname, $server->{tag});
  69     }
  70 
  71     Irssi::signal_stop();
  72 }
  73 
  74 sub notify_left {
  75     
  76     my ($server, $nick, $user, $host, $realname, $awaymsg) = @_;
  77     my $broadcast = Irssi::settings_get_bool('notify_broadcast');
  78     my $window = Irssi::active_win();
  79 
  80     if ($broadcast) {
  81         foreach my $bwin (Irssi::windows) {
  82             $bwin->printformat(MSGLEVEL_CLIENTCRAP, 'notify_left', $nick, $user, $host, $realname, $server->{tag});
  83         }
  84     } else {
  85         $window->printformat(MSGLEVEL_CLIENTCRAP, 'notify_left', $nick, $user, $host, $realname, $server->{tag});
  86     }
  87 
  88     Irssi::signal_stop();
  89 }
  90 
  91 sub notify_new {
  92     
  93     my ($nick) = @_;
  94     my $broadcast = Irssi::settings_get_bool('notify_broadcast');
  95     my $window = Irssi::active_win();
  96     my ($aw_ch, $ircnet, $mask, $ict);
  97     
  98     if ($broadcast) {
  99         foreach my $bwin (Irssi::windows) {
 100             $bwin->printformat(MSGLEVEL_CLIENTCRAP, 'notify_new', $nick->{mask});
 101         }
 102     } else {
 103         $window->printformat(MSGLEVEL_CLIENTCRAP, 'notify_new', $nick->{mask});
 104     }
 105 
 106     Irssi::signal_stop();
 107 }
 108 
 109 sub notify_del {
 110     
 111     my ($nick) = @_;
 112     my $broadcast = Irssi::settings_get_bool('notify_broadcast');
 113     my $window = Irssi::active_win();
 114     
 115     if ($broadcast) {
 116         foreach my $bwin (Irssi::windows) {
 117             $bwin->printformat(MSGLEVEL_CLIENTCRAP, 'notify_del', $nick->{mask});
 118         }
 119     } else {
 120         $window->printformat(MSGLEVEL_CLIENTCRAP, 'notify_del', $nick->{mask});
 121     }
 122 
 123     Irssi::signal_stop();
 124 }
 125 
 126 Irssi::signal_add_first('notifylist joined', 'notify_joined');
 127 Irssi::signal_add_first('notifylist left', 'notify_left');
 128 
 129 ## BUG, BUG, BUG! Warning!
 130 #
 131 # [16:02] [-] Irssi: Starting query in Freenode with cras
 132 # [16:04] :cras: it crashes every time it gets into 'notifylist remove' signal?
 133 # [16:04] :Geert: yes
 134 # [16:05] :Geert: the notifylist new too
 135 # [16:06] :cras: even if they didn't do anything?
 136 # [16:06] :Geert: indeed
 137 # [16:06] :Geert: Try for yourself :)
 138 # [16:06] :Geert: joined & remove signals are working great
 139 # [16:07] :cras: i guess it doesn't like the notifylist_rec ..
 140 # [16:08] :Geert: So, what should I do now? :)
 141 # [16:10] :cras: try cvs update?
 142 # [16:10] :cras: i fixed one possible cause for it
 143 # [16:10] :cras: and can't see another one :)
 144 # [16:11] :Geert: Well, It's a scriptrequest from someone. So I'll just comment that feature
 145 # [16:11] :Geert: Are you sure it works in the cvs?
 146 # [16:11] :cras: well, 70% sure :)
 147 # [16:12] :Geert: Let's hope so :P
 148 #
 149 # Uncomment the next two lines. ONLY if you have the CVS version.
 150 #
 151 #Irssi::signal_add_first('notifylist new', 'notify_new');
 152 #Irssi::signal_add_first('notifylist remove', 'notify_del');
 153 #
 154 ##
 155 
 156 Irssi::settings_add_bool('notify', 'notify_broadcast' => 0);
 157 Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'active_notify_loaded', $IRSSI{name}, $VERSION, $IRSSI{authors});