html/repeat.pl


   1 use Irssi;
   2 use strict;
   3 
   4 use vars qw($VERSION %IRSSI);
   5 
   6 $VERSION="0.1.3";
   7 %IRSSI = (
   8 	authors=> 'BC-bd',
   9 	contact=> 'bd@bc-bd.org',
  10 	name=> 'repeat',
  11 	description=> 'Hide duplicate lines',
  12 	license=> 'GPL v2',
  13 	url=> 'https://bc-bd.org/svn/repos/irssi/trunk/',
  14 );
  15 
  16 # repeal.pl: ignore repeated messages
  17 # 
  18 # for irssi 0.8.5 by bd@bc-bd.org
  19 #
  20 #########
  21 # USAGE
  22 ###
  23 # 
  24 # This script hides repeated lines from:
  25 #
  26 #   dude> Plz Help me!!!
  27 #   dude> Plz Help me!!!
  28 #   dude> Plz Help me!!!
  29 #   guy> foo
  30 #
  31 # Becomes:
  32 #
  33 #   dude> Plz Help me!!!
  34 #   guy> foo
  35 #
  36 # Or with 'repeat_show' set to ON:
  37 #
  38 #   dude> Plz Help me!!!
  39 # Irssi: Message repeated 3 times
  40 #   guy> foo
  41 #
  42 #########
  43 # OPTIONS
  44 #########
  45 #
  46 # /set repeat_show <ON|OFF>
  47 #   * ON  : show info line: 'Message repeated N times'
  48 #   * OFF : don't show it.
  49 #
  50 # /set repeat_count <N>
  51 #   N : Display a message N times, then ignore it.
  52 #
  53 ###
  54 ################
  55 ###
  56 # Changelog
  57 #
  58 # Version 0.1.3
  59 # - fix: also check before own message (by Wouter Coekaerts)
  60 #
  61 # Version 0.1.2
  62 # - removed stray debug message (duh!)
  63 #
  64 # Version 0.1.1
  65 # - off by one fixed
  66 # - fixed missing '$'
  67 #
  68 # Version 0.1.0
  69 # - initial release
  70 #
  71 my %said;
  72 my %count;
  73 
  74 sub sig_public {
  75   my ($server, $msg, $nick, $address, $target) = @_;
  76 
  77 	my $maxcount = Irssi::settings_get_int('repeat_count');
  78 
  79 	my $window = $server->window_find_item($target);
  80 	my $refnum = $window->{refnum};
  81 
  82 	my $this = $refnum.$nick.$msg;
  83 
  84 	my $last = $said{$refnum};
  85 	my $i = $count{$refnum};
  86 
  87 #	$window->print("'$this' '$last' $i");
  88 	if ($last eq $this and not $nick eq $server->{nick}) {
  89 		$count{$refnum} = $i +1;
  90 	
  91 		if ($i >= $maxcount) {
  92 			Irssi::signal_stop();
  93 		}
  94 	} else {
  95 		if ($i > $maxcount && Irssi::settings_get_bool('repeat_show')) {
  96 			$window->print("Message repeated ".($i-1)." times");
  97 		}
  98 
  99 		$count{$refnum} = 1;
 100 		$said{$refnum} = $this;
 101 	}
 102 }
 103 
 104 sub sig_own_public {
 105 	my ($server, $msg, $target) = @_;	
 106 	sig_public ($server, $msg, $server->{nick}, "", $target);
 107 }
 108 
 109 sub remove_window {
 110 	my ($num) = @_;
 111 
 112 	delete($count{$num});
 113 	delete($said{$num});
 114 }
 115 
 116 sub sig_refnum {
 117 	my ($window,$old) = @_;
 118 	my $refnum = $window->{refnum};
 119 	
 120 	$count{$refnum} = $count{old};
 121 	$said{$refnum} = $count{old};
 122 
 123 	remove_window($old);
 124 }
 125 
 126 sub sig_destroyed {
 127 	my ($window) = @_;
 128 	remove_window($window->{refnum});
 129 }
 130 
 131 Irssi::signal_add('message public', 'sig_public');
 132 Irssi::signal_add('message own_public', 'sig_own_public');
 133 Irssi::signal_add_last('window refnum changed', 'sig_refnum');
 134 Irssi::signal_add_last('window destroyed', 'sig_destroyed');
 135 
 136 Irssi::settings_add_int('misc', 'repeat_count', 1);
 137 Irssi::settings_add_bool('misc', 'repeat_show', 1);
 138