]> jfr.im git - irc/pisg.git/blob - pisg/modules/Pisg/Parser/Format/eggdrop.pm
import from cvs
[irc/pisg.git] / pisg / modules / Pisg / Parser / Format / eggdrop.pm
1 package Pisg::Parser::Format::eggdrop;
2
3 # Documentation for the Pisg::Parser::Format modules is found in Template.pm
4
5 use strict;
6 $^W = 1;
7
8 sub new
9 {
10 my ($type, %args) = @_;
11 my $self = {
12 cfg => $args{cfg},
13 normalline => '^\[(\d+):\d+(?:\:\d+)?\] <([^>]+)> (.*)$',
14 actionline => '^\[(\d+):\d+(?:\:\d+)?\] Action: (\S+) (.*)$',
15 thirdline => '^\[(\d+):(\d+)(?:\:\d+)?\] (\S+) (\S+) (\S+) (\S+)(.*)$',
16 };
17
18 bless($self, $type);
19 return $self;
20 }
21
22 sub normalline
23 {
24 my ($self, $line, $lines) = @_;
25 my %hash;
26
27 if ($line =~ /$self->{normalline}/o) {
28
29 $hash{hour} = $1;
30 $hash{nick} = $2;
31 $hash{saying} = $3;
32
33 return \%hash;
34 } else {
35 return;
36 }
37 }
38
39 sub actionline
40 {
41 my ($self, $line, $lines) = @_;
42 my %hash;
43
44 if ($line =~ /$self->{actionline}/o) {
45
46 $hash{hour} = $1;
47 $hash{nick} = $2;
48 $hash{saying} = $3;
49
50 return \%hash;
51 } else {
52 return;
53 }
54 }
55
56 sub thirdline
57 {
58 my ($self, $line, $lines) = @_;
59 my %hash;
60
61 if ($line =~ /$self->{thirdline}/o) {
62
63 $hash{hour} = $1;
64 $hash{min} = $2;
65 $hash{nick} = $3;
66
67 if (($4.$5) eq 'kickedfrom') {
68 $7 =~ /^ by ([\S]+):\s*(.*)/;
69 $hash{kicktext} = $2;
70 $1 =~ /([^!]+)/; # Remove anything after the !
71 $hash{kicker} = $1;
72
73 } elsif ($3 eq 'Topic') {
74 $7 =~ /^ by (\S*)!(\S+): (.*)/;
75 $hash{nick} = $1 || $2; # $1 might be empty if topic is reset by server
76 $hash{newtopic} = $3;
77
78 } elsif (($4.$5) eq 'modechange') {
79 my $newmode = $6;
80 if ($7 =~ /^ (.+) by ([\S]+)!.*/) {
81 $hash{modechanges} = $2;
82 $hash{nick} = $2;
83 $newmode =~ s/^\'//;
84 $hash{newmode} = $newmode;
85 }
86
87 } elsif ($5 eq 'joined') {
88 $hash{newjoin} = $3;
89
90 } elsif (($3.$4) eq 'Nickchange:') {
91 $hash{nick} = $5;
92 $7 =~ /([\S]+)/;
93 $hash{newnick} = $1;
94
95 } elsif (($3.$4.$5) eq 'Lastmessagerepeated') {
96 $hash{repeated} = $6;
97 }
98
99 $hash{nick} =~ /([^!]+)/;
100 $hash{nick} = $1;
101 return \%hash;
102
103 } else {
104 return;
105 }
106 }
107
108 1;