Added queryresume.pl

This commit is contained in:
Maff 2014-11-29 03:05:40 +00:00
parent a9491e4b1d
commit 36d607cac0
2 changed files with 77 additions and 1 deletions

76
queryresume-maff.pl Normal file
View File

@ -0,0 +1,76 @@
# QueryResume by Stefan Tomanek <stefan@pico.ruhr.de>
#
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = '2014112900';
%IRSSI = (
authors => 'Stefan \'tommie\' Tomanek, Maff',
contact => 'stefan@pico.ruhr.de, maff+irssi@maff.scot',
name => 'QueryResume',
description => 'restores the last lines of a query on re-creation',
license => 'GPLv2',
modules => 'Date::Format',
changed => $VERSION,
);
use Irssi 20020324;
use Date::Format;
# Modified to remove unnecessary footer, replace actual "box" with greyed-out text
sub draw_box ($$$) {
my ($title, $text, $colour) = @_;
my $box = '%K%U« '.$title.' »%U%n'."\n";
foreach (split(/\n/, $text)) {
$box .= '%K'.$_."%n\n";
}
$box =~ s/%.//g unless $colour;
return $box;
}
# Heavily modified. Stylistic changes, reordering, added some intelligence so it loads the last non-tiny log if possible
sub sig_window_item_new ($$) {
my ($win, $witem) = @_;
return unless (ref $witem && $witem->{type} eq 'QUERY');
my $lines = Irssi::settings_get_int('queryresume_lines');
my $autolog = Irssi::settings_get_str('autolog_path');
my $name = lc $witem->{name};
my @t=localtime;
$autolog =~ s/(\$tag|\$1)/$witem->{server}->{tag}/g;
$autolog =~ s/\$\{?0\}?/$name/g;
$autolog = strftime($autolog, @t, undef);
$autolog =~ s/([\]\[])/\\$1/g;
$autolog =~ s/\/[\{\}a-zA-Z0-9_\-\.]*$//;
my @files = get_sorted_files($autolog);
my $filename;
foreach(@files) {
$filename=$_ and last if -s $_ >= 300;
}
$filename=$files[0] unless $filename or !scalar @files;
open(F, "<$filename");
my @data;
foreach (<F>) {
next if /^(--- Log|[0-9:]{5} -!-|$)/;
s/%/%%/g;
shift(@data) if (@data >= $lines);
push(@data, $_);
}
my $text = join '', @data;
$lines = scalar @data;
$witem->print(draw_box("Last $lines lines from log $filename", $text, 1), MSGLEVEL_CLIENTCRAP & MSGLEVEL_NEVER) if $text;
}
# Added: sort a list of files in a directory by date.
sub get_sorted_files ($) {
my $path = shift; $path =~ s/~/$ENV{HOME}/;
opendir my($dirh), $path or die "can't opendir $path: $!";
my @flist = sort { -M $a <=> -M $b }
map { "$path/$_" }
grep { !/^\.{1,2}$/ }
readdir $dirh;
closedir $dirh;
return @flist;
}
Irssi::settings_add_int($IRSSI{name}, 'queryresume_lines', 10);
Irssi::signal_add('window item new', 'sig_window_item_new');

View File

@ -20,5 +20,5 @@ This readme contains an up to date list of all scripts in the repo + their descr
- ifls: Perl - Script to collect all interfaces on the system and provide an easily-viewed list of their IPs
- mailview: Perl - Script to parse HTML email and format it in a text-reader-friendly way.
- nscheck: Bash - DNS diagnosis script
- pscrot & pscrot.rc: Perl - OSX-oriented but likely easily ported daemon for uploading screenshots and such. pscrot.rc is the configuration file, and should be stored at ~/.pscrotrc
- queryresume-maff.pl: Perl - Irssi script to autoload chat history in query windows. Heavily modified from https://github.com/irssi/scripts.irssi.org/blob/gh-pages/scripts/queryresume.pl
- watchd & watchd.conf: Bash - Script designed to run as a cronjob, alerting the user to any events.