Last active
December 16, 2015 13:49
-
-
Save MacoTasu/5444613 to your computer and use it in GitHub Desktop.
script which contributes to irc from a command line
This file contains 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 strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::IRC::Client; | |
# conf | |
my $conf = { | |
irc => { | |
server => '*****',#server | |
channel => '#****',# channel | |
port => ****,#port number | |
ssl => 1, | |
nick => '****',#nickname | |
real => '****',#real name | |
password => '*****',#pass | |
}, | |
}; | |
my $cv = AnyEvent->condvar; | |
# new | |
my $irc = AnyEvent::IRC::Client->new; | |
#ssl enable | |
$irc->enable_ssl if $conf->{irc}{ssl}; | |
$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"; | |
}, | |
); | |
# connect to irc | |
$irc->connect($conf->{irc}{server}, $conf->{irc}{port},{ nick =>$conf->{irc}{nick} , $conf->{irc}{password} ? (password => $conf->{irc}{password}) : (),}); | |
# join to channel | |
$irc->send_srv("JOIN", $conf->{irc}{channel}); | |
# timer | |
my $watcher; | |
$watcher = AnyEvent->timer( | |
after => 10,#10sec | |
cb => sub { | |
# $ARGV[0] = message | |
$irc->send_chan($conf->{irc}{channel}, "NOTICE", $conf->{irc}{channel}, $ARGV[0]); | |
die; | |
} | |
); | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment