IRCのチャンネルのログを取るBOTスクリプト改良
http://d.hatena.ne.jp/tomyhero/20070911/1189489871
複数のチャンネルをログる用に修正した。ログファイル指定じゃなくて、ディレクトリ指定に変更
#!/usr/bin/perl use strict; use warnings; use POE qw(Sugar::Args Component::IRC); use Class::Inspector; use IO::All; use Getopt::Long; use DateTime; use File::Spec; my @channels = (); my $logdir = '/tmp/'; my $nick = 'logbot'; my $server = 'localhost'; my $port = 6667; my $result = GetOptions ( "channel=s" => \@channels, "logdir=s" => \$logdir, "nick=s" => \$nick, "server=s" => \$server, "port=i" => \$port, ); POE::Component::IRC->spawn( alias => 'bot', nick => $nick, server => $server, port => $port, ); POE::Session->create( package_states => [ main => Class::Inspector->methods('main') ], args => \@ARGV, ); POE::Kernel->sig(INT => sub { POE::Kernel->stop }); POE::Kernel->run; sub _start { my $poe = sweet_args; $poe->kernel->post(bot => register => 'all'); $poe->kernel->post(bot => connect => {}); } sub irc_001 { my $poe = sweet_args; $poe->kernel->post( $poe->sender => join => $_ ) for @channels; } sub irc_public { my $poe = sweet_args; my $who = $poe->args->[0] ; my $channels = $poe->args->[1]; my $what = $poe->args->[2] ; my $dt = DateTime->now( time_zone => 'local' ); for my $channel ( @{ $channels } ) { $channel =~ s/#//g; my $logfile = File::Spec->catfile( $logdir , $channel . '_log' ); my $io = io( $logfile ); $io->append( '[' . $dt->ymd . ' ' . $dt->hms . ']' . $who . ":" . $what . "\n" ) ; $io->close(); } } =head1 NAME irc_logging_bot.pl - IRC BOT for logging a specific irc channel =head1 SYNOPSYS irc_logging_bot.pl --channel '#tomyhero' --channel '#perl' --logdir /var/log/chat --nick logbot --server localhost --port 6667 =head1 AUTHOR Tomohiro Teranishi <tomohrio.teranishi@gmail.com> =cut