Procházet zdrojové kódy

dancer bot format support by Elmar Hoffmann

Morten Brix Pedersen před 24 roky
rodič
revize
2c2a061398
2 změnil soubory, kde provedl 102 přidání a 0 odebrání
  1. 8 0
      docs/FORMATS
  2. 94 0
      modules/Pisg/Parser/Format/dancer.pm

+ 8 - 0
docs/FORMATS

@@ -224,3 +224,11 @@ link to the logfile)
   Example:
         [00:02] <Jenny> Hello world
 	[00:04] Joins: vjaway (vector@p5086F6EF.dip.t-dialin.net)
+
+* Dancer:
+  - Bot written in C (http://dancer.sourceforge.net/)
+
+  - In order to use this, format must be set to 'dancer'
+
+  Example:
+  15.57.40 # <elho> hello world! 

+ 94 - 0
modules/Pisg/Parser/Format/dancer.pm

@@ -0,0 +1,94 @@
+package Pisg::Parser::Format::dancer;
+
+# 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+)\.\S+ \# \s+ <([^>]+)> (.*)',
+        actionline => '^(\d+)\.\S+ \# \s+ \* (\S+) (.*)',
+        thirdline  => '^(\d+)\.(\d+)\.\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;
+
+	if($3 eq 'Kick') {
+	    $4 =~ /\(\S+ (\S+) .*?\) by (\S+)\!/o;
+	    $hash{nick} = $1;
+	    $hash{kicker} = $2;
+	} elsif($3 eq 'Topic') {
+	    $4 =~ /\"(.*)\" by (\S+) /o;
+	    $hash{newtopic} = $1;
+	    $hash{nick} = $2;
+	} elsif($3 eq 'Mode') {
+	    $4 =~ /\S+ (\S+) .*\" by (\S+) /o;
+	    $hash{newmode} = $1;
+	    $hash{nick} = $2;
+	} elsif($3 eq 'Join') {
+	    $4 =~ /(\S+) (\S+) /o;
+	    $hash{nick} = $1;
+	    $hash{newjoin} = $1;
+	} elsif($3 eq 'Nick') {
+	    $4 =~ /(\S+) is now known as (\S+) /o;
+	    $hash{nick} = $1;
+	    $hash{newnick} = $2;
+	}
+        return \%hash;
+
+    } else {
+        return;
+    }
+}
+
+1;