Przeglądaj źródła

infobot module by Nicholas Frampton <whyrl@avians.net>

Morten Brix Pedersen 24 lat temu
rodzic
commit
7ca32eca9b
2 zmienionych plików z 116 dodań i 0 usunięć
  1. 6 0
      docs/FORMATS
  2. 110 0
      modules/Pisg/Parser/Format/infobot.pm

+ 6 - 0
docs/FORMATS

@@ -109,6 +109,7 @@ link to the logfile)
 
   Example:
   12/11/01 22:05:42 :Keitaro!KOala_v5@EVYRV4A4.ipt.aol.com PRIVMSG #alsa-station :Re all :-)
+
 * ircle:
   - IRC client for Mac OS X
 
@@ -118,3 +119,8 @@ link to the logfile)
 
   Example:
   6:35 PM:   Sinnikal: thats gross
+
+* infobot:
+  - bot written in Perl (http://www.infobot.org)
+
+  - In order to use this, format must be set to 'infobot'

+ 110 - 0
modules/Pisg/Parser/Format/infobot.pm

@@ -0,0 +1,110 @@
+package Pisg::Parser::Format::infobot;
+
+# Documentation for the Pisg::Parser::Format modules is found in Template.pm
+
+# Note that infobot log files do not distinguish between action lines and
+# normal lines. This parser assumes that people in your channel use correct
+# sentence case for normal lines. YMMV.
+
+use strict;
+$^W = 1;
+
+sub new
+{
+    my ($type, %args) = @_;
+    my $self = {
+        cfg => $args{cfg},
+        debug => $args{debug},
+        normalline => '^(\d+) \[\d+\] <([^\/]+)\/[^>]+> ([^a-z].*)',
+        actionline => '^(\d+) \[\d+\] <([^\/]+)\/[^>]+> ([a-z].*)',
+        thirdline  => '^(\d+) \[\d+\] >>> (.*)',
+    };
+
+    bless($self, $type);
+    return $self;
+}
+
+sub normalline
+{
+    my ($self, $line, $lines) = @_;
+    my %hash;
+    my $sec; my $min; my $hour; my $mday; my $mon; my $year;
+    my $wday; my $yday; my $isdst;
+
+    if ($line =~ /$self->{normalline}/) {
+        $self->{debug}->("[$lines] Normal: $1 $2 $3");
+
+        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
+        $hash{hour}   = $hour;
+        $hash{nick}   = $2;
+        $hash{saying} = $3;
+
+        return \%hash;
+    } else {
+        return;
+    }
+}
+
+sub actionline
+{
+    my ($self, $line, $lines) = @_;
+    my %hash;
+    my $sec; my $min; my $hour; my $mday; my $mon; my $year; 
+    my $wday; my $yday; my $isdst;
+
+    if ($line =~ /$self->{actionline}/) {
+        $self->{debug}->("[$lines] Action: $1 $2 $3");
+
+        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
+        $hash{hour}   = $hour;
+        $hash{nick}   = $2;
+        $hash{saying} = $3;
+
+        return \%hash;
+    } else {
+        return;
+    }
+}
+
+sub thirdline
+{
+    my ($self, $line, $lines) = @_;
+    my %hash;
+    my $sec; my $min; my $hour; my $mday; my $mon; my $year; 
+    my $wday; my $yday; my $isdst;
+
+    if ($line =~ /$self->{thirdline}/) {
+        $self->{debug}->("[$lines] ***: $1 $2");
+
+        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
+        $hash{hour} = $hour;
+        $hash{min}  = $min;
+
+        if ($2 =~ /^\[1m([^(\[0m)]*)\[0m was kicked off \[1m[^\[]*\[0m by \[1m([^(\[0m)]*)\[0m .*/) {
+            $hash{nick} = $1;
+            $hash{kicker} = $2;
+
+        } elsif ($2 =~ /^([^(\[1m)]*)\[1m\S* (:?)(.*)\[1m\]\[0m set the topic: (.*)/) {
+            $hash{nick} = $1;
+            $hash{newtopic} = "$3$2$4";
+        
+        } elsif ($2 =~ /^mode\/\S* \[\[1m([\+\-]o+) .* by \[1m(\S*)\[0m/) {
+            $hash{newmode} = $1;
+            $hash{nick} = $2;
+            
+        } elsif ($2 =~ /^(\S*) \(\S*\) has joined \#\S*/) {
+            $hash{newjoin} = $1;
+        
+        } elsif ($2 =~ /^\[1;32m([^(\[0m)]*)\[0m materializes into \[1;32m([^(\[0m)]*)\[0m/) {
+            $hash{nick} = $1;
+            $hash{newnick} = $2;
+        }
+
+        return \%hash;
+
+    } else {
+        return;
+    }
+}
+
+1;