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
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package ASM::Log;
no autovivification;
use warnings;
use strict;
use POSIX qw(strftime);
no if $] >= 5.017011, warnings => 'experimental::smartmatch';
sub new
{
my $module = shift;
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})) {
say FH "$chan";
say FH join('', @{$self->{backlog}->{$chan}});
}
}
close(FH);
}
sub logg
{
my $self = shift;
my ($event) = @_;
my $cfg = $self->{CONFIG};
my @chans = @{$event->{to}};
@chans = ( $event->{args}->[0] ) if ($event->{type} eq 'kick');
my @time = ($cfg->{zone} eq 'local') ? localtime : gmtime;
foreach my $chan ( @chans )
{
$chan = lc $chan;
next if ($chan eq '$$*');
$chan =~ s/^[@+]//;
if ($chan eq '*') {
ASM::Util->dprint("$event->{nick}: $event->{args}->[0]", 'snotice');
next;
}
my $path = ">>$cfg->{dir}${chan}/${chan}" . strftime($cfg->{filefmt}, @time);
$_ = '';
$_ = "<$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 ($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 ($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';
$_ = "*** $event->{nick} changes topic to \"$event->{args}->[0]\"" if $event->{type} eq 'topic';
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";
}
my $spy;
if (defined($::spy{$chan})) {
$spy = $::spy{$chan};
} elsif (defined($::spy{lc $event->{nick}})) {
$spy = $::spy{lc $event->{nick}};
}
if (defined($spy)) {
say $spy "$chan: $nostamp";
}
}
}
1;
|