Last active
September 2, 2024 11:27
-
-
Save kompowiec/9387ea99a27b52a01c4cd1579305c2bf to your computer and use it in GitHub Desktop.
file format for Perl IRC Statistics Generator - https://pisg.github.io/ - matrix protocol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package Pisg::Parser::Format::Matrix; | |
| use strict; | |
| use warnings; | |
| use Carp; | |
| sub new | |
| { | |
| my ($type, %args) = @_; | |
| my $self = { | |
| cfg => $args{cfg}, | |
| normalline => qr/^(\d{1,2}\.\d{1,2}\.\d{4}), (\d{2}:\d{2}:\d{2}) - ([^:]+): (.+)$/, | |
| actionline => qr/^(\d{1,2}\.\d{1,2}\.\d{4}), (\d{2}:\d{2}:\d{2}) - \* ([^ ]+) (.+)$/, | |
| thirdline => qr/^(\d{1,2}\.\d{1,2}\.\d{4}), (\d{2}:\d{2}:\d{2}) - (\S+) (opuścił\(-a\) pokój|dołączył\(-a\) do pokoju|zmienił\(-a\) temat na) ?(?:\[(.+)\])?$/, | |
| }; | |
| bless($self, $type); | |
| return $self; | |
| } | |
| sub normalline | |
| { | |
| my ($self, $line, $lines) = @_; | |
| my %hash; | |
| if ($line =~ $self->{normalline}) { | |
| my ($date, $time, $nick, $saying) = ($1, $2, $3, $4); | |
| my ($hour, $min, $sec) = split(':', $time); | |
| # Ensure all parts are defined before adding to hash | |
| $hash{date} = $date if defined $date; | |
| $hash{hour} = $hour if defined $hour; | |
| $hash{min} = $min if defined $min; | |
| $hash{sec} = $sec if defined $sec; | |
| $hash{nick} = $nick if defined $nick; | |
| $hash{saying} = $saying if defined $saying; | |
| return \%hash; | |
| } else { | |
| return; | |
| } | |
| } | |
| sub actionline | |
| { | |
| my ($self, $line, $lines) = @_; | |
| my %hash; | |
| if ($line =~ $self->{actionline}) { | |
| my ($date, $time, $nick, $saying) = ($1, $2, $3, $4); | |
| my ($hour, $min, $sec) = split(':', $time); | |
| # Ensure all parts are defined before adding to hash | |
| $hash{date} = $date if defined $date; | |
| $hash{hour} = $hour if defined $hour; | |
| $hash{min} = $min if defined $min; | |
| $hash{sec} = $sec if defined $sec; | |
| $hash{nick} = $nick if defined $nick; | |
| $hash{saying} = $saying if defined $saying; | |
| return \%hash; | |
| } else { | |
| return; | |
| } | |
| } | |
| sub thirdline | |
| { | |
| my ($self, $line, $lines) = @_; | |
| my %hash; | |
| if ($line =~ $self->{thirdline}) { | |
| my ($date, $time, $nick, $action, $additional_info) = ($1, $2, $3, $4, $5); | |
| my ($hour, $min, $sec) = split(':', $time); | |
| $hash{date} = $date if defined $date; | |
| $hash{hour} = $hour if defined $hour; | |
| $hash{min} = $min if defined $min; | |
| $hash{sec} = $sec if defined $sec; | |
| $hash{nick} = $nick if defined $nick; | |
| $hash{action} = $action if defined $action; | |
| $hash{info} = $additional_info if defined $additional_info; | |
| return \%hash; | |
| } else { | |
| return; | |
| } | |
| if ($action eq 'zmienił(-a) temat na') { | |
| $hash{action} = 'topic_change'; | |
| $hash{newtopic} = $additional_info if defined $additional_info; | |
| } | |
| } | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment