Просмотр исходного кода

Support for muh-bouncer logs (thanks, Sebastian Erlhofer & Bastian
Friedrich)

Morten Brix Pedersen 24 лет назад
Родитель
Сommit
c4c04c2487
1 измененных файлов с 112 добавлено и 0 удалено
  1. 112 0
      modules/Pisg/Parser/Format/muh.pm

+ 112 - 0
modules/Pisg/Parser/Format/muh.pm

@@ -0,0 +1,112 @@
+package Pisg::Parser::Format::muh;
+
+# This is a Parser vor the well-known "muh-bouncer"
+# by Bastian Friedrichs and Sebastian Erlhofer
+# parser@boitl.org
+
+use strict;
+$^W = 1;
+
+sub new
+{
+    my ($type, %args) = @_;
+    my $self = {
+        cfg => $args{cfg},
+        normalline => '^\[\w\w\w \d\d \w\w\w (\d+):\d+:\d+\] <([^>\s]+)>\s+(.*)',
+        actionline => '^\[\w\w\w \d\d \w\w\w (\d+):\d+:\d+\] \*\s+(\S+) (.*)',
+        #thirdline  => '^\[\w\w\w \d\d \w\w\w (\d+):(\d+):\d+\] \*\*\*\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)',
+        thirdline  => '^\[\w\w\w \d\d \w\w\w (\d+):(\d+):\d+\] \*\*\*\s+(\S+) (\S+) (\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;
+
+        # Format-specific stuff goes here.
+
+        if (($3.$6) eq 'Kickby') {
+            $hash{kicker} = $7;
+            $hash{nick} = $5;
+
+        } elsif (($3.$4) eq 'Topicchange') {
+            $hash{newtopic} = $10;
+            #$hash{newtopic} = $9.$10;
+            #$hash{newtopic} =~ s/^.* \):(.*)/$9$10/;
+            $hash{nick}     = $8;
+
+
+        } elsif ($3 eq 'Mode') {
+            my $nm;
+            $nm = substr($5, 1);
+            if (($nm eq "+o") || ($nm eq "-o")) {
+                $hash{nick} = $8;
+                $hash{newmode} = $nm;
+            }
+            elsif (($nm eq "+oo") || ($nm eq "-oo")) {
+                $hash{nick} = $9;
+                $hash{newmode} = $nm;
+            }
+            elsif (($nm eq "+ooo") || ($nm eq "-ooo")) {
+                $hash{nick} = substr($10, 1, index($10, ' ', 1)-1);
+                $hash{newmode} = $nm;
+            }
+
+
+        } elsif (($2.$3) eq '\*\*\*Join') {
+            $hash{newjoin} = $5;
+        }
+
+
+        return \%hash;
+
+    } else {
+        return;
+    }
+}
+
+1;