4
0
Эх сурвалжийг харах

New parser "weechat3" for weechat >= 0.3.

Christoph Berg 17 жил өмнө
parent
commit
51ed5b1ed3

+ 2 - 0
docs/CREDITS

@@ -154,6 +154,8 @@ Other contributors:
    | Finish translation
  * skiidoo
    | updated French translation
+ * KenjiE20
+   | weechat3 parser
 
 I probably forgot a lot of people here, _PLEASE_ notify me if I left you
 out.. because I have a bad habit of forgetting to maintain this list :)

+ 2 - 0
docs/Changelog

@@ -1,6 +1,8 @@
 pisg (0.73) - ??
     Christoph:
     * Add "listening to" to the default ChartsRegexp.
+    Parsers:
+    * New parser "weechat3" for weechat >= 0.3.
 
 pisg (0.72) - Wed Feb, 13th 2008
     The Not Quite Valentine's Day Release.

+ 5 - 0
docs/FORMATS

@@ -535,3 +535,8 @@ preferences you
 [22-11-2004/15:00] <ace> morning
 [22-11-2004/15:01] * ace is back
   - Parser written by Vianney Lecroart <acemtp@free.fr>
+
+* weechat, weechat3
+  - http://weechat.flashtux.org/
+  - There are two parsers, one for the old log format ("weechat"), and one for
+    the new format starting from version 0.3 ("weechat3").

+ 97 - 0
modules/Pisg/Parser/Format/weechat3.pm

@@ -0,0 +1,97 @@
+package Pisg::Parser::Format::weechat3;
+
+# Documentation for the Pisg::Parser::Format modules is found in Template.pm
+
+use strict;
+$^W = 1;
+
+sub new
+{
+    my ($type, %args) = @_;
+    my $self = {
+        cfg => $args{cfg},
+        normalline => '^\d+-\d+-\d+ (\d+):\d+:\d+\t[@%+~&]?([^ <-]\S+)\t(.*)',
+        actionline => '^\d+-\d+-\d+ (\d+):\d+:\d+\t \*\t(\S+) (.*)',
+        thirdline  => '^\d+-\d+-\d+ (\d+):(\d+):\d+\t(?:--|<--|-->)\t(\S+) (\S+) (\S+) (\S+) (\S+)(.*)',
+    };
+
+    bless($self, $type);
+    return $self;
+}
+
+sub normalline
+{
+    my ($self, $line, $lines) = @_;
+    my %hash;
+
+    if ($line =~ /$self->{normalline}/o) {
+
+        $hash{hour}   = $1;
+        $hash{nick}   = $2;
+        $hash{saying} = $3;
+
+        return \%hash;
+    } else {
+        return;
+    }
+}
+
+sub actionline
+{
+    my ($self, $line, $lines) = @_;
+    my %hash;
+
+    if ($line =~ /$self->{actionline}/o) {
+
+        $hash{hour}   = $1;
+        $hash{nick}   = $2;
+        $hash{saying} = $3;
+
+        return \%hash;
+    } else {
+        return;
+    }
+}
+
+sub thirdline
+{
+    my ($self, $line, $lines) = @_;
+    my %hash;
+
+    if ($line =~ /$self->{thirdline}/o) {
+
+        $hash{hour} = $1;
+        $hash{min}  = $2;
+        $hash{nick} = $3;
+
+        if (($4.$5) eq 'haskicked') {
+            $hash{nick} = $6;
+            $hash{kicker} = $3;
+
+        } elsif ($4.$5.$6 eq 'haschangedtopic') {
+            $hash{newtopic} = $8;
+            $hash{newtopic} =~ m/" to "(.*)"/;
+            $hash{newtopic} = $1;
+
+        } elsif ($3 eq 'Mode') {
+            $hash{newmode} = substr($5, 1);
+            $hash{nick} = $8 || $7;
+            $hash{nick} =~ s/.* (\S+)$/$1/; # Get the last word of the string
+
+        } elsif (($5.$6) eq 'hasjoined') {
+            $hash{newjoin} = $3;
+
+        } elsif (($5.$6) eq 'nowknown') {
+            if ($8 =~ /^\s+(\S+)/) {
+                $hash{newnick} = $1;
+            }
+        }
+
+        return \%hash;
+
+    } else {
+        return;
+    }
+}
+
+1;