1## Usage: /RELM [-l || index] [target] 2## to list last 15 messages: 3## /RELM -l 4## to redirect msg #4, 7, 8, 9, 10, 13 to current channel/query: 5## /RELM 4,7-10,13 6## to redirect last message to current channel/query: 7## /RELM 8 9use strict; 10use Irssi; 11 12use vars qw($VERSION %IRSSI); 13$VERSION = "1.0"; 14%IRSSI = ( 15 authors => "Maciek \'fahren\' Freudenheim", 16 contact => "fahren\@bochnia.pl", 17 name => "REdirect Last Message", 18 description => "Keeps last 15 messages in cache", 19 license => "GNU GPLv2 or later", 20 changed => "Fri Mar 15 15:09:42 CET 2002" 21); 22 23my %relm; 24 25sub cmd_relm { 26 my ($args, $server, $winit) = @_; 27 my $ircnet = lc($server->{tag}); 28 my ($which, $where) = split(/ +/, $args, 2); 29 30 $where = $which unless $which =~ /[0-9]/; 31 32 $which = scalar(@{$relm{lc($ircnet)}}) unless ($which); 33 34 unless ($relm{$ircnet}) { 35 Irssi::print("%R>>%n Nothing in relm buffer on $ircnet.", MSGLEVEL_CRAP); 36 return; 37 } 38 39 if ($where eq "-l") { 40 my $numspace; 41 Irssi::print(">> ---- Context ------------------------", MSGLEVEL_CRAP); 42 for (my $i = 0; $i < scalar(@{$relm{$ircnet}}); $i++) { 43 $numspace = sprintf("%.2d", $i+1); 44 Irssi::print("[%W$numspace%n] $relm{$ircnet}[$i]", MSGLEVEL_CRAP); 45 } 46 return; 47 } 48 49 unless ($where) { 50 unless ($winit && ($winit->{type} eq "CHANNEL" || $winit->{type} eq "QUERY")) { 51 Irssi::print("%R>>%n You have to join channel first", MSGLEVEL_CRAP); 52 return; 53 } 54 $where = $winit->{name}; 55 } 56 57 $which =~ s/,/ /g; 58 my @nums; 59 for my $num (split(/ /, $which)) { 60 if ($num =~ /-/) { 61 my ($start, $end) = $num =~ /([0-9]+)-([0-9]*)/; 62 for (;$start <= $end; $start++) { 63 push(@nums, $start - 1); 64 } 65 } else { 66 push(@nums, $num - 1); 67 } 68 } 69 70 for my $num (@nums) { 71 unless ($relm{$ircnet}[$num]) { 72 Irssi::print("%R>>%n No such message in relm buffer /" . ($num + 1). "/", MSGLEVEL_CRAP); 73 } else { 74 Irssi::active_server()->command("msg $where $relm{$ircnet}[$num]"); 75 } 76 } 77} 78 79sub event_privmsg { 80 my ($server, $data, $nick, $address) = @_; 81 my ($target, $text) = split(/ :/, $data, 2); 82 my $ircnet = lc($server->{tag}); 83 84 return if ($server->{nick} ne $target); 85 my $relm = "\00312[ \00310$nick!$address \00312]\003 $text"; 86 shift(@{$relm{$ircnet}}) if scalar(@{$relm{$ircnet}}) > 14; 87 push(@{$relm{$ircnet}}, $relm); 88} 89 90Irssi::command_bind("relm", "cmd_relm"); 91Irssi::signal_add("event privmsg", "event_privmsg"); 92