summaryrefslogtreecommitdiffstats
path: root/lastseen.pl
diff options
context:
space:
mode:
authorStefan Ritter <xeno@thehappy.de>2011-08-16 10:51:41 +0200
committerStefan Ritter <xeno@thehappy.de>2011-08-16 10:51:41 +0200
commitba46c304bdffdce0b6019a47f6759ce6abbeef90 (patch)
tree40a5b204637cb65c5bb91bd4f26a248ea498e019 /lastseen.pl
Initial commit
Diffstat (limited to 'lastseen.pl')
-rw-r--r--lastseen.pl64
1 files changed, 64 insertions, 0 deletions
diff --git a/lastseen.pl b/lastseen.pl
new file mode 100644
index 0000000..c70d1d0
--- /dev/null
+++ b/lastseen.pl
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+use File::ReadBackwards;
+
+if ($#ARGV ne 2){
+ print "not enough arguments\n";
+ exit 1;
+}
+
+my $chan=$ARGV[1];
+my $folder=$ARGV[0];
+my $nick=$ARGV[2];
+
+
+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;
+ }
+ } else {
+ if ($line =~ m/^\[00:00(:00)?\] --- /){
+ ($date=$line)=~s/^\[00:00(:00)?\] --- (.*)\n/$2/;
+ ($time=$lastaction)=~s/(.*)\[([0-9]{2}:[0-9]{2}(:[0-9]{2})?)\](.*)\n/$2/;
+ $l=9+length($nick);
+ if ($lastaction=~m/^.{$l}kicked/){
+ ($by=$lastaction)=~s/^\[[0-9]{2}:[0-9]{2}(:[0-9]{2})?\] $nick kicked from #.* by //i;
+ ($reason=$by)=~s/.*: (.*)\n/$1/;
+ $by=~s/:.*\n//i;
+
+ print "$nick kicked by $by on $date at $time reason: $reason\n";
+ } elsif ($lastaction=~m/$nick \(.*\) left irc: /i){
+ ($message=$lastaction)=~s/^.* $nick \(.*\) left irc: (.*)\n/$1/i;
+ print "$nick quits on $date at $time saying: $message\n";
+ } else {
+ if ($lastaction=~m/\)\.$/) {
+ ($message=$lastaction)=~s/^.* $nick \(.*\) left #[a-zA-Z0-9]* \((.*)\)\.\n/$1/i;
+ print "$nick parts on $date at $time saying: $message\n";
+ } else {
+ print "$nick parts on $date at $time\n";
+ }
+ }
+ exit 0;
+ }
+ }
+}
+}
+
+print "I do not remember $nick\n";