From 0f0d4c4209a902a252fc6e764c7bacf158b12954 Mon Sep 17 00:00:00 2001 From: William Heimbigner Date: Thu, 14 Jan 2016 16:11:04 -0700 Subject: Move channel logging hooks into the logging module, rather than calling them from the event module. --- lib/ASM/Event.pm | 13 ------------- lib/ASM/Inspect.pm | 2 +- lib/ASM/Log.pm | 19 ++++++++++++++++--- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'lib/ASM') diff --git a/lib/ASM/Event.pm b/lib/ASM/Event.pm index a5e1083..4f0d547 100644 --- a/lib/ASM/Event.pm +++ b/lib/ASM/Event.pm @@ -221,7 +221,6 @@ sub on_join { $::sn{$nick}->{host} = $event->{host}; $::sn{$nick}->{account} = lc $event->{args}->[0]; $::db->logg($event) if defined $::db; - $::log->logg( $event ); $::inspector->inspect( $conn, $event ) unless $::netsplit; } @@ -230,7 +229,6 @@ sub on_part my ($conn, $event) = @_; my $nick = lc $event->{nick}; my $chan = lc $event->{to}->[0]; - $::log->logg( $event ); $::db->logg( $event ) if defined $::db; # Ignore channels that are +s and not monitored if (defined $::db and $event->{args}->[0] =~ /^requested by/ and (not ((grep { /^s$/ } @{$::sc{$chan}{modes}} ) && ($::channels->{channel}->{$chan}->{monitor} eq "no"))) ) { @@ -277,7 +275,6 @@ sub on_public # alarm 200; my $chan = lc $event->{to}[0]; $chan =~ s/^[+@]//; - $::log->logg( $event ); $::db->logg( $event ) if defined $::db; if ($event->{args}->[0] =~ /(https?:\/\/bitly.com\/\w+|https?:\/\/bit.ly\/\w+|https?:\/\/j.mp\/\w+|https?:\/\/tinyurl.com\/\w+)/i) { my $reqid = $::async->add( HTTP::Request->new( GET => $1 ) ); @@ -315,7 +312,6 @@ sub on_notice { my ($conn, $event) = @_; return if ( $event->{to}->[0] eq '$*' ); # if this is a global notice FUCK THAT SHIT - $::log->logg( $event ); $::db->logg( $event ) if defined $::db; $::inspector->inspect( $conn, $event ); } @@ -351,7 +347,6 @@ sub on_quit $::log->sqlIncident( join(',', @actionlog_channels), $idx ) if $idx; $::db->logg( $event ); } - $::log->logg( $event ); if (($event->{args}->[0] eq "*.net *.split") && (lc $event->{nick} ne 'chanserv')) { #special, netsplit situation if ($::netsplit == 0){ @@ -425,7 +420,6 @@ sub irc_topic { $::sc{$chan}{topic}{time} = time; $::sc{$chan}{topic}{by} = $event->{from}; } - $::log->logg($event); $::db->logg( $event ) if defined $::db; $::inspector->inspect($conn, $event); } @@ -460,11 +454,6 @@ sub on_nick { $::db->logg( $event ) if defined $::db; delete( $::sn{$oldnick}) if ($oldnick ne $newnick); $event->{to} = \@channels; - $::log->logg($event); - # Well, the nick change actually was done from the old nick ... but - # by the time we process it, they already changed nicks. Therefore - # we'll pretend it's the *new* nick that generated the event. - $event->{nick} = $event->{args}[0]; $::inspector->inspect($conn, $event); } @@ -476,7 +465,6 @@ sub on_kick { } my $nick = lc $event->{to}->[0]; my $chan = lc $event->{args}->[0]; - $::log->logg( $event ); if (defined $::db) { $::db->logg( $event ); # Ignore channels that are +s and not monitored @@ -683,7 +671,6 @@ sub on_mode } } } - $::log->logg($event); } } diff --git a/lib/ASM/Inspect.pm b/lib/ASM/Inspect.pm index 9f27100..f351e1f 100644 --- a/lib/ASM/Inspect.pm +++ b/lib/ASM/Inspect.pm @@ -23,7 +23,7 @@ sub inspect { my (@dnsbl, @uniq); my ($match, $txtz, $iaddr); my @override = []; - my $nick = lc $event->{nick}; + my $nick = ($event->{type} eq 'nick') ? $event->{args}->[0] : lc $event->{nick}; my $xresult; return if (index($nick, ".") != -1); if ( $event->{type} eq 'join' ) { diff --git a/lib/ASM/Log.pm b/lib/ASM/Log.pm index e922d88..b05dbf0 100644 --- a/lib/ASM/Log.pm +++ b/lib/ASM/Log.pm @@ -4,17 +4,30 @@ no autovivification; use warnings; use strict; +use ASM::Util; use POSIX qw(strftime); no if $] >= 5.017011, warnings => 'experimental::smartmatch'; sub new { my $module = shift; - my $config = shift; + my ($conn) = @_; my $self = {}; - $self->{CONFIG} = $config; + $self->{CONFIG} = $::settings->{log}; $self->{backlog} = {}; + $self->{CONN} = $conn; bless($self); + mkdir($self->{CONFIG}->{dir}); + $conn->add_handler('public', sub { logg($self, @_); }, "before"); + $conn->add_handler('join', sub { logg($self, @_); }, "before"); + $conn->add_handler('part', sub { logg($self, @_); }, "before"); + $conn->add_handler('caction', sub { logg($self, @_); }, "before"); + $conn->add_handler('nick', sub { logg($self, @_); }, "after"); #allow state tracking to molest this + $conn->add_handler('quit', sub { logg($self, @_); }, "before"); + $conn->add_handler('kick', sub { logg($self, @_); }, "before"); + $conn->add_handler('notice', sub { logg($self, @_); }, "before"); + $conn->add_handler('mode', sub { logg($self, @_); }, "before"); + $conn->add_handler('topic', sub { logg($self, @_); }, "before"); return $self; } @@ -52,7 +65,7 @@ sub sqlIncident sub logg { my $self = shift; - my ($event) = @_; + my ($conn, $event) = @_; my $cfg = $self->{CONFIG}; my @chans = @{$event->{to}}; @chans = ( $event->{args}->[0] ) if ($event->{type} eq 'kick'); -- cgit v1.2.3