IRCのチャンネルのログを取るBOTスクリプト
http://forums.unrealircd.com/viewtopic.php?f=3&t=2938&p=16156&hilit=chat+log#p16156
UnRealIRCDにはチャットのログを取る機能がないっぽいので、BOTつくって対応してみた。
#!/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; my $channel = '#test'; my $logfile = '/tmp/chat_log'; my $nick = 'logbot'; my $server = 'localhost'; my $port = 6667; my $result = GetOptions ( "channel=s" => \$channel, "logfile=s" => \$logfile, "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 => $channel); } sub irc_public { my $poe = sweet_args; my $who = $poe->args->[0] ; my $what = $poe->args->[2] ; my $dt = DateTime->now( time_zone => 'local' ); 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' --logfile /var/log/chat --nick logbot --server localhost --port 6667 =head1 AUTHOR Tomohiro Teranishi <tomohrio.teranishi@gmail.com> =cut
追記
chanel を複数設定できるようにせんとあかんあ