# National Center for Ecological Analysis and Synthesis (NCEAS)
# University of California Santa Barbara
#
# This package creates an XML log file of the messages sent to IRC channels
# which mozbot has joined. The content that is logged can be selected using
# regular expression filters, although by default all messages are logged
package BotModules::XMLLogger;
use vars qw(@ISA);
@ISA = qw(BotModules);
1;
sub Help {
my $self = shift;
my ($event) = @_;
my $help = {
'' => 'This module keeps an XML log of channels.',
};
if ($self->isAdmin($event)) {
$help->{''} .= ' It can be configured to only accept messages matching certain patterns. The \'acceptedPatterns\' module variable is a list of regular expressions to use when determining what to log. The \'blockedPatterns\' list is the opposite.';
$help->{'rotatelogs'} = 'Creates a new log file for each channel and moves the old one to a date-stamped version, making sure that the XML is valid. Syntax: \'rotatelogs\'.';
}
return $help;
}
# RegisterConfig - Called when initialised, should call registerVariables
sub RegisterConfig {
my $self = shift;
$self->SUPER::RegisterConfig(@_);
$self->registerVariables(
# [ name, save?, settable? ]
['acceptedPatterns', 1, 1, ['']], # by default match everything
['blockedPatterns', 1, 1, []], # by default block nothing
);
}
sub Told {
my $self = shift;
my ($event, $message) = @_;
if ($self->isAdmin($event)) {
if ($message =~ /^\s*rotate\s*logs?\s*$/osi) {
$self->RotateLogs($event);
} else {
return $self->SUPER::Told(@_);
}
} else {
return $self->SUPER::Told(@_);
}
return 0; # we've dealt with it, no need to do anything else.
}
sub Log {
my $self = shift;
my ($event) = @_;
if (($event->{'firsttype'} eq 'Told') or
($event->{'firsttype'} eq 'Heard')) {
$self->DoLog($event, 'msg');
} elsif (($event->{'firsttype'} eq 'Felt') or
($event->{'firsttype'} eq 'Saw')) {
$self->DoLog($event, 'emote');
} elsif (($event->{'firsttype'} eq 'SpottedKick') or