summaryrefslogtreecommitdiffstats
path: root/lastspoke.pl
blob: 9ccf5d9d921b129ad8675f499573d753c6cc0d57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl

use File::ReadBackwards;

if ($#ARGV ne 3){
   print "not enough arguments\n";
   exit 1;
}

my $folder=$ARGV[0];
my $chan=$ARGV[1];
my $nick=$ARGV[2];
my $printdate=$ARGV[3];

my @files;

push @files, `ls $folder/$chan.* | sort -r`;

foreach $file (@files) {


my $date=0;
my $lastaction;
my $line;

$file=~s/\n$//;
my $log = File::ReadBackwards->new($file) || die $!;

while ($line=$log->readline()){
#   $line=$log->readline();
   if ($date eq 0){
      if ($line =~ m/^\[[0-9]{2}:[0-9]{2}(:[0-9]{2})?\] <$nick> /i && $line !~ m/joined #/ ) {
         $date=1;
         ($lastaction=$line)=~s/\n//;
      }
   } else {
      if ($printdate eq 0){
         print "$nick\'s last action: $lastaction\n";
         exit 0;
      } else {
         if ($line=~m/^\[00:00(:00)?\] --- /){
            ($date=$line)=~s/^\[00:00(:00)?\] --- (.*)\n/$2/;
            print "$nick spoke last time on $date\n";
            print "$nick\'s last action: $lastaction\n";
            exit 0;
         }
      }
   }
}
}

print "I do not remember $nick\n";