-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirssiben.pm
99 lines (76 loc) · 2.06 KB
/
irssiben.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Pisg::Parser::Format::irssiben;
# 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+-\d+-\d+ (\d+):\d+[^<*^!]+<[@%+~& ]?([^>]+)> (.*)',
actionline => '^\[\d+-\d+-\d+ (\d+):\d+[^ ]+ +\* (\S+) (.*)',
thirdline => '^\[\d+-\d+-\d+ (\d+):(\d+)[^-]+-\!- (\S+) (\S+) (\S+) (\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;
$hash{nick} = $3;
if (($4.$5) eq 'waskicked') {
$hash{kicker} = $8;
$hash{kicker} =~ m/by (\S+)/;
$hash{kicker} = $1;
} elsif ($4 eq 'changed') {
$hash{newtopic} = $8;
$hash{newtopic} =~ m/to:(.*)/;
$hash{newtopic} = $1;
} elsif (substr($3, 0, 5) eq 'mode/') {
$hash{newmode} = substr($4, 1);
$hash{nick} = $8 || $7;
$hash{nick} =~ s/.* (\S+)$/$1/; # Get the last word of the string
# when autorealname.pl is loaded, "has joined" moves to $6 $7
} elsif (($5.$6) eq 'hasjoined' or ($6.$7) eq 'hasjoined') {
$hash{newjoin} = $3;
} elsif (($5.$6) eq 'nowknown') {
if ($8 =~ /^\s+(\S+)/) {
$hash{newnick} = $1;
}
}
return \%hash;
} else {
return;
}
}
1;