Jelajahi Sumber

Support for irssi logfiles

Morten Brix Pedersen 25 tahun lalu
induk
melakukan
23cdd97be5
2 mengubah file dengan 110 tambahan dan 0 penghapusan
  1. 1 0
      Makefile
  2. 109 0
      modules/Pisg/Parser/Format/irssi.pm

+ 1 - 0
Makefile

@@ -44,6 +44,7 @@ PARSER_MODULES = $(MODULESDIR)/Pisg/Parser/Logfile.pm
 FORMAT_MODULES = $(MODULESDIR)/Pisg/Parser/Format/bxlog.pm \
 		 $(MODULESDIR)/Pisg/Parser/Format/eggdrop.pm \
 		 $(MODULESDIR)/Pisg/Parser/Format/grufti.pm \
+		 $(MODULESDIR)/Pisg/Parser/Format/irssi.pm \
 		 $(MODULESDIR)/Pisg/Parser/Format/mbot.pm \
 		 $(MODULESDIR)/Pisg/Parser/Format/mIRC.pm \
 		 $(MODULESDIR)/Pisg/Parser/Format/Template.pm \

+ 109 - 0
modules/Pisg/Parser/Format/irssi.pm

@@ -0,0 +1,109 @@
+package Pisg::Parser::Format::irssi;
+
+use strict;
+$^W = 1;
+
+my $normalline = '^(\d+):\d+ <.([^>]+)> (.*)';
+my $actionline = '^(\d+):\d+  \* (\S+) (.*)';
+my $thirdline  = '^(\d+):(\d+) -\!- (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
+
+my ($debug);
+
+
+sub new
+{
+    my $self = shift;
+    $debug = shift;
+    return bless {};
+}
+
+sub normalline
+{
+    # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
+    my ($self, $line, $lines) = @_;
+    my %hash;
+
+    if ($line =~ /$normalline/) {
+	$debug->("[$lines] Normal: $1 $2 $3");
+
+	$hash{hour}   = $1;
+	$hash{nick}   = $2;
+	$hash{saying} = $3;
+
+	return \%hash;
+    } else {
+	return;
+    }
+}
+
+sub actionline
+{
+    # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
+    my ($self, $line, $lines) = @_;
+    my %hash;
+
+    if ($line =~ /$actionline/) {
+	$debug->("[$lines] Action: $1 $2 $3");
+
+	$hash{hour}   = $1;
+	$hash{nick}   = $2;
+	$hash{saying} = $3;
+
+	return \%hash;
+    } else {
+	return;
+    }
+}
+
+sub thirdline
+{
+    # Parses the 'third' line - (the third line is everything else, like
+    # topic changes, mode changes, kicks, etc.)
+    # thirdline() have to return a hash with the following keys, for
+    # every format:
+    #   hour            - the hour we're in (for timestamp loggin)
+    #   min             - the minute we're in (for timestamp loggin)
+    #   nick            - the nick
+    #   kicker          - the nick which were kicked (if any)
+    #   newtopic        - the new topic (if any)
+    #   newmode         - deops or ops, must be '+o' or '-o', or '+ooo'
+    #   newjoin         - a new nick which has joined the channel
+    #   newnick         - a person has changed nick and this is the new nick
+    my ($self, $line, $lines) = @_;
+    my %hash;
+
+    if ($line =~ /$thirdline/) {
+	if (defined $8) {
+	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
+	} else {
+	    $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
+	}
+
+	$hash{hour} = $1;
+	$hash{min}  = $2;
+	$hash{nick} = $3;
+
+	if (($4.$5) eq 'waskicked') {
+	    $hash{kicker} = $7;
+
+	} elsif ($4 eq 'changed') {
+	    $hash{newtopic} = "$7 $8";
+
+	} elsif (substr($3, 0, 4) eq 'mode') {
+	    $hash{newmode} = substr($4, 1);
+
+	} elsif (($5.$6) eq 'hasjoined') {
+	    $hash{newjoin} = $3;
+
+	} elsif (($4.$5) eq 'nowknown') {
+	    $hash{newnick} = $8;
+	}
+
+	return \%hash;
+
+    } else {
+	return;
+    }
+}
+
+1;