html/mass_hilight_blocker.pl


   1 # disable hilighting of mass-hilights
   2 # (messages which contain a lot of nicknames)
   3 #
   4 # DESCRIPTION
   5 # sometimes a jester annoys a channel with a message
   6 # containing a lot of nicks that are in that channel. 
   7 # this script prevents hilighting of a window in this
   8 # case. number of nicks in the message is user
   9 # configurable in the variable mass_highlight_threshold.
  10 # 
  11 # CHANGELOG
  12 # * 01.05.2004
  13 # fixed problems with nicks containing brackets
  14 # added comments, description and this changelog :)
  15 # * 30.05.2004
  16 # first version of the script
  17 
  18 use Irssi;
  19 use vars qw($VERSION %IRSSI); 
  20 $VERSION = "0.2";
  21 %IRSSI = (
  22         authors         => "Uli Baumann",
  23 	contact         => "f-zappa\@irc-muenster.de",
  24 	name            => "mass_hilight_blocker",
  25 	description     => "Disables hilighting for messages containing a lot of nicknames",
  26 	license         => "GPL",
  27 	changed	        => "Tue Jun  1 13:32:20 CEST 2004",
  28 );
  29 
  30 
  31 sub sig_printtext {
  32   my ($dest, $text, $stripped) = @_;	# our parameters
  33   my $window = $dest->{window};		# where irssi wants to output
  34   my $num_nicks=-1;			# don't count target's nick
  35   my $max_num_nicks=Irssi::settings_get_int('mass_hilight_threshold');
  36 
  37   if ($dest->{level} & MSGLEVEL_HILIGHT)# we solely look at hilighted messages
  38     {
  39       my $server  =  $dest->{server};	# get server and channel for target
  40       my $channel =  $server->channel_find($dest->{target});
  41       
  42       foreach $nick ($channel->nicks()) # walk through nicks
  43         {
  44           $nick = $nick->{nick};
  45           $nick =~ s/([\]\[])/\\$1/g;	# ']' and '[' need masking
  46           if ($text =~ /$nick/)		# does line contain this nick?
  47             {$num_nicks++;}		# then increase counter
  48         }
  49       
  50       if ($num_nicks>=($max_num_nicks)) # all criteria match?
  51         {
  52           $window->print($text, MSGLEVEL_PUBLIC);	# inform user
  53           $window->print('mass-hilighting in above message ('.$num_nicks.' nicks)',MSGLEVEL_CLIENTCRAP);
  54           Irssi::signal_stop();		# don't process any further
  55         }
  56     }
  57 }
  58 
  59 # tell irssi to use this and initialize variable if necessary
  60 
  61 Irssi::signal_add_first('print text', 'sig_printtext');
  62 Irssi::settings_add_int('misc','mass_hilight_threshold',3);
  63