Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
unzazuki bot
#!/usr/bin/env perl
use warnings;
use strict;
use AnyEvent;
use AnyEvent::IRC::Client;
use Data::Dumper;
# 接続設定
my $channel = '#channel';
my %config = (
server => 'SERVER',
port => PORT,
info => {
nick => 'NICK',
real => 'NAME',
password => 'PASS',
},
);
# 状態変数生成
my $condvar = AnyEvent->condvar;
# IRC イベント
my $irc = AnyEvent::IRC::Client->new;
$irc->reg_cb(
# 接続時に呼び出されるイベント
connect => sub {
my ($irc, $err) = @_;
if (defined $err) {
print "connect error: $err\n";
return;
}
print "connected.\n";
},
# 接続成功時に呼び出されるイベント
registered => sub {
print "registered.\n";
},
# 切断時に呼び出されるイベント
disconnect => sub {
print "disconnected.\n";
},
# $channel に発言があったとき _public() を実行
publicmsg => sub {
my ($irc, $chan, $msg) = @_;
my ($nick, $host) = split(/\!/, $msg->{ prefix });
# 発言者がkenjiskywalkerだったら返事するとか
# if ( $msg->{ prefix } =~ /kenjiskywalker/ ) {
if ( $msg->{ command } eq 'PRIVMSG' ) {
if ( $msg->{ params }[1] =~ /unazu_kun/ ){
_public($nick);
}
# }
}
},
);
$irc->enable_ssl();
sub _public {
my $msg = shift;
sleep(5);
$irc->send_chan($channel, "PRIVMSG", $channel, $msg.": うんうん('-'*)");
}
# IRC サーバに接続
$irc->connect($config{server}, $config{port}, $config{info});
# $channel に join
$irc->send_srv("JOIN", $channel);
# $channel に notice メッセージを送る
# $irc->send_chan($channel, "NOTICE", $channel, "Hello, $channel!");
# イベント待ち
$condvar->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.