diff options
Diffstat (limited to 'modules/log.pl')
| -rw-r--r-- | modules/log.pl | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/modules/log.pl b/modules/log.pl index 8b30eab..bdf4821 100644 --- a/modules/log.pl +++ b/modules/log.pl @@ -12,10 +12,43 @@ sub new my $config = shift; my $self = {}; $self->{CONFIG} = $config; + $self->{backlog} = {}; bless($self); return $self; } +sub incident +{ + my $self = shift; + my ($chan, $header) = @_; + $chan = lc $chan; + open(FH, '>>', 'dctlog.txt'); + print FH $header; + if (defined($self->{backlog}->{$chan})) { + print FH join('', @{$self->{backlog}->{$chan}}); + } + print FH "\n\n"; + close(FH); +} + +#writes out the backlog to a file which correlates to ASM's SQL actionlog table +sub sqlIncident +{ + my $self = shift; + my ($channel, $index) = @_; + $channel = lc $channel; + my @chans = split(/,/, $channel); + open(FH, '>', $self->{CONFIG}->{actiondir} . $index . '.txt'); + foreach my $chan (@chans) { + if (defined($self->{backlog}->{$chan})) { + print FH "$chan\n"; + print FH join('', @{$self->{backlog}->{$chan}}); + print FH "\n"; + } + } + close(FH); +} + sub logg { my $self = shift; @@ -35,10 +68,10 @@ sub logg $_ = ''; $_ = "<$event->{nick}> $event->{args}->[0]" if $event->{type} eq 'public'; $_ = "*** $event->{nick} has joined $chan" if $event->{type} eq 'join'; - $_ = "*** $event->{nick} has left $chan" if $event->{type} eq 'part'; + $_ = "*** $event->{nick} has left $chan ($event->{args}->[0])" if $event->{type} eq 'part'; $_ = "* $event->{nick} $event->{args}->[0]" if $event->{type} eq 'caction'; $_ = "*** $event->{nick} is now known as $event->{args}->[0]" if $event->{type} eq 'nick'; - $_ = "*** $event->{nick} has quit IRC" if $event->{type} eq 'quit'; + $_ = "*** $event->{nick} has quit ($event->{args}->[0])" if $event->{type} eq 'quit'; $_ = "*** $event->{to}->[0] was kicked by $event->{nick}" if $event->{type} eq 'kick'; $_ = "-$event->{nick}- $event->{args}->[0]" if $event->{type} eq 'notice'; $_ = "*** $event->{nick} sets mode: " . join(" ",@{$event->{args}}) if $event->{type} eq 'mode'; @@ -46,8 +79,18 @@ sub logg my $nostamp = $_; $_ = strftime($cfg->{timefmt}, @time) . $_ . "\n"; my $line = $_; + my @backlog = (); + if (defined($self->{backlog}->{$chan})) { + @backlog = @{$self->{backlog}->{$chan}}; + if (scalar @backlog >= 30) { + shift @backlog; + } + } + push @backlog, $line; + $self->{backlog}->{$chan} = \@backlog; if (open(FH, $path)) { # or die "Can't open $path: $!"; print FH $line; + ASM::Util->dprint($line, 'logger'); close(FH); } else { print "COULDN'T PRINT TO $path - $line"; |
