package Pisg::Parser::Format::hydra2;

use strict;
$^W = 1;

sub new
{
    my ($type, %args) = @_;
    my $self = {
        cfg => $args{cfg},
        normalline => '^\[\d+\.\d+\.\d+ (\d+):\d+:\d+\] <([^>\s]+)> (.*)',
        actionline => '^\[\d+\.\d+\.\d+ (\d+):\d+:\d+\] \* (\S+) (.+)',
        thirdline  => '^\[\d+\.\d+\.\d+ (\d+):(\d+):\d+\] \*{3} (.+)',
    };

    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;

        # Format-specific stuff goes here.

        if ($3 =~ /^(\S+) izbacio korisnika (\S+) uz razlog (\S+) (.+)/) {
            $hash{nick} = $1;
            $hash{kicker} = $3;
            $hash{kicktext} = $4;

        } elsif ($3 =~ /^(\S+) promenio temu u (.+)/) {
             $hash{nick} = $1;
             $hash{newtopic} = $2;
             
        } elsif ($3 =~ /^(\S+) sets channel \S+ mode (\S+) (.+)/) {
             $hash{nick} = $1;
             $hash{newmode} = $2;
             $hash{modechanges} = $3;

        } elsif ($3 =~ /^(\S+) Ušao \S+ u \S+/) {
            $hash{nick} = $1;
            $hash{newjoin} = $1;

        } elsif ($3 =~ /^(\S+) promenio nadimak u (\S+)/) {
            $hash{nick} = $1;
            $hash{newnick} = $2;

        } elsif ($3 =~ /^(\S+) dao voice: (\S+)$/) { 
			$hash{nick} = $1;
			$hash{newmode} = "+v $2";

        } elsif ($3 =~ /^(\S+) oduzeo voice: (\S+)$/) { 
			$hash{nick} = $1;
			$hash{newmode} = "-v $2";

        } elsif ($3 =~ /^(\S+) dao op: (\S+)$/) { 
			$hash{nick} = $1;
			$hash{newmode} = "+o $2";

        } elsif ($3 =~ /^(\S+) oduzeo op: (\S+)$/) { 
			$hash{nick} = $1;
			$hash{newmode} = "-o $2";

        } elsif ($3 =~ /^(\S+) banovao: (\S+)$/) { 
			$hash{nick} = $1;
			$hash{newmode} = "+b $2";

        } elsif ($3 =~ /^(\S+) skinuo ban za: (\S+)$/) { 
			$hash{nick} = $1;
			$hash{newmode} = "-b $2";

        } elsif ($3 =~ /^(\S+) promenio mod: (\S+)$/) { 
			$hash{nick} = $1;
			$hash{newmode} = $2;
		}

        return \%hash;

    } else {
        return;
    }
}

1;

