
IRC::Bot::Log::Extended - extends IRC::Bot::Log for IRC::Bot

#!/usr/bin/perl -w
package IRC::Bot2;
use Moose;
extends 'IRC::Bot';
use IRC::Bot::Log::Extended;
after 'bot_start' => sub {
my $self = shift;
no warnings;
$IRC::Bot::log = IRC::Bot::Log::Extended->new(
Path => $self->{'LogPath'},
split_channel => 1,
split_day => 1,
);
};
package main;
# Initialize new object
my $bot = IRC::Bot2->new( # check IRC::Bot for more details
Debug => 0,
Nick => 'Fayland',
Server => 'irc.perl.org',
Channels => [ '#moose', '#catalyst', '#dbix-class' ],
LogPath => '/home/fayland/irclog/',
);
# Daemonize process
$bot->daemon();
# Run the bot
$bot->run();
1;

The SYNOPSIS above does two tasks.
$IRC::Bot::log = IRC::Bot::Log::Extended->new(
Path => $self->{'LogPath'},
split_channel => 1,
split_day => 1,
);

IRC::Bot::Log stores all channels all days into one file channel.log. it is not so good to read. IRC::Bot::Log::Extended splits the log into several files by channel AND|OR day.
the place moose_20081009.log stores.
default is 1. Instead store all log into channel.log, we split them into moose.log, catalyst.log and dbix-class.log
default is 1. Instead store all log into channel.log or moose.log, we split them into channel_20081009.log, channel_20081010.log (moose_20081010.log) and etc. daily.

The method pre_insert can be augmented in a subclass to add extra functionality to your control script. here is two examples:
http://fayland.googlecode.com/svn/trunk/CPAN/IRC-Bot-Log-Extended/examples/02b_with_filter.pl
http://fayland.googlecode.com/svn/trunk/CPAN/IRC-Bot-Log-Extended/examples/03advanced.pl
augment pre_insert => sub {
my ($self, $file_ref, $message_ref) = @_;
# change filename
$$file_ref .= '.html';
# HTML-lize
$$message_ref =~ s/\</\<\;/isg;
# find URIs
my $finder = URI::Find->new(
sub {
my ( $uri, $orig_uri ) = @_;
return qq|<a href="$uri">$orig_uri</a>|;
}
);
$finder->find( $message_ref );
$$message_ref .= "</br>";
};
the example above is to make a HTML IRC log by youself.

IRC::Bot, IRC::Bot::Log, Moose

Fayland Lam, <fayland at gmail.com>

Copyright 2008 Fayland Lam, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.