]> jfr.im git - irc/pisg.git/blob - pisg/modules/Pisg/Parser/Format/konversation.pm
import from cvs
[irc/pisg.git] / pisg / modules / Pisg / Parser / Format / konversation.pm
1 package Pisg::Parser::Format::konversation;
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+)[^\]]+\]\s+<([^>]+)>\s+(.*)$',
14 actionline => '^\[[^\[]+\[(\d+)[^\]]+\]\s+\*\s(\S+)\s(.*)$',
15 thirdline => '^\[[^\[]+\[(\d+):(\d+)[^\]]+\]\s(\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 $hash{hour} = $1;
29 $hash{nick} = $2;
30 $hash{saying} = $3;
31
32 return \%hash;
33 } else {
34 return;
35 }
36 }
37
38 sub actionline
39 {
40 my ($self, $line, $lines) = @_;
41 my %hash;
42
43 if ($line =~ /$self->{actionline}/o) {
44 $hash{hour} = $1;
45 $hash{nick} = $2;
46 $hash{saying} = $3;
47
48 return \%hash;
49 } else {
50 return;
51 }
52 }
53
54 sub thirdline
55 {
56 my ($self, $line, $lines) = @_;
57 my %hash;
58
59 if ($line =~ /$self->{thirdline}/o) {
60 $hash{hour} = $1;
61 $hash{min} = $2;
62 $hash{nick} = $4;
63
64 if ($4 eq 'You') {
65 # Hack to remove You as a nick
66 $hash{nick} = $self->{cfg}->{maintainer};
67 }
68
69 if ($3 eq 'Mode') {
70 $hash{newmode} = $5;
71 $hash{newmode} =~ s/^[^+-]*//;
72
73 } elsif ($3 eq 'Join') {
74 $hash{newjoin} = $4;
75
76 } elsif ($3 eq 'Nick') {
77 $hash{newnick} = $5;
78 $hash{newnick} =~ s/^.*\s+(\S+)$/$1/;
79
80 } elsif ($3 eq 'Kick') {
81 if ($5 =~ /^have kicked (\S+) from the channel \((.+)\).$/ ) {
82 $hash{kicker} = $hash{nick};
83 $hash{nick} = $1;
84 $hash{kicktext} = $2;
85 } elsif ($5 =~ /^has been kicked from the channel by (\S+) \((.+)\).$/ ) {
86 $hash{kicker} = $1;
87 $hash{kicktext} = $2;
88 } else {
89 return;
90 }
91
92 } elsif ($3 eq 'Topic') {
93 if ($5 =~ /the channel topic to "(.*)"\.$/) {
94 $hash{newtopic} = $1;
95 } else {
96 return;
97 }
98
99 }
100
101 return \%hash;
102
103 } else {
104 return;
105 }
106 }
107
108 1;