Created
November 18, 2012 13:37
-
-
Save issm/4105302 to your computer and use it in GitHub Desktop.
sample using AnyEvent::IRC::Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.12.0; | |
use warnings; | |
use utf8; | |
use AnyEvent; | |
use AnyEvent::IRC::Client; | |
use Encode; | |
my @server_info = ( | |
'irc.example.com', | |
6667, | |
{ | |
nick => 'foobar', | |
real => 'foobar', | |
password => '********', | |
}, | |
); | |
my @channels = ( | |
'#meganelab', | |
); | |
my $cv = AnyEvent->condvar; | |
my $irc = AnyEvent::IRC::Client->new; | |
$irc->reg_cb( | |
registered => sub { | |
warn 'registered'; | |
}, | |
disconnect => sub { | |
warn 'disconnected'; | |
}, | |
publicmsg => sub { | |
my ($irc, $channel, $ircmsg) = @_; | |
my (undef, $who) = $irc->split_nick_mode($ircmsg->{prefix}); | |
my $msg = decode_utf8( $ircmsg->{params}[1] // '' ); | |
sleep 1; | |
$irc->send_chan( $channel, 'NOTICE', $channel, encode_utf8("Re: $msg") ); | |
}, | |
); | |
$irc->connect(@server_info); | |
for (@channels) { | |
$irc->send_srv('JOIN', $_); | |
} | |
$cv->recv; | |
$irc->disconnect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment