some-usable-scripts/perl/irc_bot.pl

46 lines
829 B
Perl
Raw Normal View History

2012-08-24 04:04:34 +02:00
#!/usr/bin/perl
use Modern::Perl;
use AnyEvent;
use AnyEvent::IRC::Client;
my $c = AnyEvent->condvar;
my $cl = AnyEvent::IRC::Client->new;
2012-08-24 04:24:35 +02:00
my $timer;
2012-08-24 04:04:34 +02:00
$cl->reg_cb (connect => sub {
my ($con, $err) = @_;
if (defined $err) {
warn "connect error: $err\n";
return;
}
});
2012-08-24 04:24:35 +02:00
$cl->reg_cb (registered => sub { say "I'm in!"; });
$cl->reg_cb (disconnect => sub { say "I'm out!"; $c->broadcast });
$cl->reg_cb (
sent => sub {
my ($con) = @_;
if ($_[2] eq 'PRIVMSG') {
print "Sent message!\n";
$timer = AnyEvent->timer (
after => 1,
cb => sub {
undef $timer;
say "on est dans cb";
$con->disconnect ('done')
}
);
}
}
);
2012-08-24 04:04:34 +02:00
$cl->connect ('irc.geeknode.org', 6667, { nick => '[bot]kanette' });
2012-08-24 04:24:35 +02:00
$cl->send_srv ( PRIVMSG => 'karchnu', 'Bot enabled : woot');
2012-08-24 04:04:34 +02:00
$c->wait;
$cl->disconnect;