AnyEvent::IRC::Clientを使った場合のテンプレ
自分用のメモです。
#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use Data::Dump qw/dump/; use AnyEvent; use AnyEvent::IRC::Client; use Encode; # チャンネル名 my $channel = "#mychannel"; my $c = AnyEvent->condvar; my $irc = new AnyEvent::IRC::Client; # SSLが必須なら $irc->enable_ssl; $irc->connect( "irc.url.com", 6667, { nick => 'botname', password => 'botpassword' } ); $irc->send_srv( "JOIN", $channel ); $irc->reg_cb( connect => sub { print "connected\n" } ); $irc->reg_cb( registered => sub { print "registered\n"; } ); $irc->reg_cb( disconnect => sub { print "disconnet\n"; } ); $irc->reg_cb( publicmsg => sub { my ( $irc, $chan, $msg ) = @_; # $chanにチャンネル名、$msgにメッセージが入ってる # あとは色々できるはず my $message = $msg->{params}->[1]; if ($chan eq $channel and $message) { $irc->send_chan( $channel, "NOTICE", $channel, $message ); } } ); # 定期実行 my $timer; $timer = AnyEvent->timer( after => 1, # 秒間まってからループ開始 interval => 2, # 秒数ごとにやる cb => sub { $irc->send_chan( $channel, "NOTICE", $channel, '完、じゃなくて凛!' ); } ); $c->recv;