1use Irssi; 2use strict; 3 4use vars qw($VERSION %IRSSI); 5 6$VERSION="0.2.0"; 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=> 'http://bc-bd.org/blog/irssi/', 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.2.0 59# - addes support for /me 60# 61# Version master 62# - updated url 63# 64# Version 0.1.3 65# - fix: also check before own message (by Wouter Coekaerts) 66# 67# Version 0.1.2 68# - removed stray debug message (duh!) 69# 70# Version 0.1.1 71# - off by one fixed 72# - fixed missing '$' 73# 74# Version 0.1.0 75# - initial release 76# 77my %said; 78my %count; 79 80sub sig_public { 81 my ($server, $msg, $nick, $address, $target) = @_; 82 83 my $maxcount = Irssi::settings_get_int('repeat_count'); 84 85 my $window = $server->window_find_item($target); 86 my $refnum = $window->{refnum}; 87 88 my $this = $refnum.$nick.$msg; 89 90 my $last = $said{$refnum}; 91 my $i = $count{$refnum}; 92 93 if ($last eq $this and not $nick eq $server->{nick}) { 94 $count{$refnum} = $i +1; 95 96 if ($i >= $maxcount) { 97 Irssi::signal_stop(); 98 } 99 } else { 100 if ($i > $maxcount && Irssi::settings_get_bool('repeat_show')) { 101 $window->print("Message repeated ".($i-1)." times"); 102 } 103 104 $count{$refnum} = 1; 105 $said{$refnum} = $this; 106 } 107} 108 109sub sig_own_public { 110 my ($server, $msg, $target) = @_; 111 sig_public ($server, $msg, $server->{nick}, "", $target); 112} 113 114sub remove_window { 115 my ($num) = @_; 116 117 delete($count{$num}); 118 delete($said{$num}); 119} 120 121sub sig_refnum { 122 my ($window,$old) = @_; 123 my $refnum = $window->{refnum}; 124 125 $count{$refnum} = $count{old}; 126 $said{$refnum} = $count{old}; 127 128 remove_window($old); 129} 130 131sub sig_destroyed { 132 my ($window) = @_; 133 remove_window($window->{refnum}); 134} 135 136Irssi::signal_add('message public', 'sig_public'); 137Irssi::signal_add('message own_public', 'sig_own_public'); 138Irssi::signal_add('message irc action', 'sig_public'); 139Irssi::signal_add_last('window refnum changed', 'sig_refnum'); 140Irssi::signal_add_last('window destroyed', 'sig_destroyed'); 141 142Irssi::settings_add_int('misc', 'repeat_count', 1); 143Irssi::settings_add_bool('misc', 'repeat_show', 1); 144 145