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

make pircbot log format recognize data written by the bot.... is there a better way to do this? I dislike my way

sbingner 24 лет назад
Родитель
Сommit
82c80e86b7
1 измененных файлов с 59 добавлено и 26 удалено
  1. 59 26
      modules/Pisg/Parser/Format/pircbot.pm

+ 59 - 26
modules/Pisg/Parser/Format/pircbot.pm

@@ -21,9 +21,15 @@ sub new
 
 
     my $self = {
     my $self = {
         cfg => $args{cfg},
         cfg => $args{cfg},
-        normalline => '^(\d+)\s:([^!]+)!([^@]+)@(\S+)\sPRIVMSG\s(#\S+)\s:([^' . $ctcpchr . '].*)$',
-        actionline => '^(\d+)\s:([^!]+)!([^@]+)@(\S+)\sPRIVMSG\s(#\S+)\s:' . $ctcpchr . 'ACTION (.+)' . $ctcpchr . '\s*$',
-	thirdline  => '^(\d+)\s:([^!]+)!([^@]+)@(\S+)\s(.+)$',
+        normalline => '^(\d+)\s:([^!]+)![^@]+@\S+\sPRIVMSG\s(#\S+)\s:([^' . $ctcpchr . '].*)$'
+                      . '|' .
+                      '^(\d+)\s(>>>)PRIVMSG\s(#\S+)\s:([^' . $ctcpchr . '].*)$',
+        actionline => '^(\d+)\s:([^!]+)!([^@]+)@(\S+)\sPRIVMSG\s(#\S+)\s:' . $ctcpchr . 'ACTION (.+)' . $ctcpchr . '\s*$'
+                      . '|' . 
+                      '^(\d+)\s(>>>)PRIVMSG\s(#\S+)\s:' . $ctcpchr . 'ACTION (.+)' . $ctcpchr . '\s*$',
+	thirdline  => '^(\d+)\s:([^!]+)![^@]+@\S+\s(.+)$'
+                      . '|' .
+                      '^(\d+)\s(>>>)([^P]\S+)\s+(.+)$',
     };
     };
 
 
     bless($self, $type);
     bless($self, $type);
@@ -37,15 +43,24 @@ sub normalline
     my %hash;
     my %hash;
 
 
     if ($line =~ /$self->{normalline}/o) {
     if ($line =~ /$self->{normalline}/o) {
-        return unless (lc($5) eq lc($self->{cfg}->{channel}));
-
-        # Most log formats are regular enough that you can just match the
-        # appropriate things with parentheses in the regular expression.
+        if (defined($8)) {
+            return unless (lc($7) eq lc($self->{cfg}->{channel}));
+
+            my @time = localtime($5 / 1000);
+            $hash{hour}   = $time[2];
+            $hash{nick}   = $6;
+            $hash{saying} = $8;
+        } else {
+            return unless (lc($3) eq lc($self->{cfg}->{channel}));
+
+            my @time = localtime($1 / 1000);
+            $hash{hour}   = $time[2];
+            $hash{nick}   = $2;
+            $hash{saying} = $4;
+        }
 
 
-        my @time = localtime($1 / 1000);
-        $hash{hour}   = $time[2];
-        $hash{nick}   = $2;
-        $hash{saying} = $6;
+        $hash{nick}   = $self->{cfg}->{maintainer}
+          if ($hash{nick} eq '>>>');
 
 
         return \%hash;
         return \%hash;
     } else {
     } else {
@@ -60,15 +75,24 @@ sub actionline
     my %hash;
     my %hash;
 
 
     if ($line =~ /$self->{actionline}/o) {
     if ($line =~ /$self->{actionline}/o) {
-        return unless (lc($5) eq lc($self->{cfg}->{channel}));
-
-        # Most log formats are regular enough that you can just match the
-        # appropriate things with parentheses in the regular expression.
+        if (defined($8)) {
+            return unless (lc($7) eq lc($self->{cfg}->{channel}));
+
+            my @time = localtime($5 / 1000);
+            $hash{hour}   = $time[2];
+            $hash{nick}   = $6;
+            $hash{saying} = $8;
+        } else {
+            return unless (lc($3) eq lc($self->{cfg}->{channel}));
+
+            my @time = localtime($1 / 1000);
+            $hash{hour}   = $time[2];
+            $hash{nick}   = $2;
+            $hash{saying} = $4;
+        }
 
 
-        my @time = localtime($1 / 1000);
-        $hash{hour}   = $time[2];
-        $hash{nick}   = $2;
-        $hash{saying} = $6;
+        $hash{nick}   = $self->{cfg}->{maintainer}
+          if ($hash{nick} eq '>>>');
 
 
         return \%hash;
         return \%hash;
     } else {
     } else {
@@ -97,13 +121,22 @@ sub thirdline
     my %hash;
     my %hash;
 
 
     if ($line =~ /$self->{thirdline}/o) {
     if ($line =~ /$self->{thirdline}/o) {
-
-        my @time = localtime($1 / 1000);
-        $hash{hour}   = $time[2];
-        $hash{min}  = $time[1];
-        $hash{nick} = $2;
-
-        my @line = split(/\s+/, "$5");
+        my ($time, @line);
+        if (defined($6)) {
+            my @time = localtime($4 / 1000);
+            $hash{hour}   = $time[2];
+            $hash{min}  = $time[1];
+            $hash{nick} = $self->{cfg}->{maintainer};
+
+            @line = split(/\s+/, $6);
+        } else {
+            my @time = localtime($1 / 1000);
+            $hash{hour}   = $time[2];
+            $hash{min}  = $time[1];
+            $hash{nick} = $2;
+
+            @line = split(/\s+/, $3);
+        }
 
 
         if ($line[0] eq 'KICK') {
         if ($line[0] eq 'KICK') {
             return unless (lc($line[1]) eq lc($self->{cfg}->{channel}));
             return unless (lc($line[1]) eq lc($self->{cfg}->{channel}));