#! perl use Time::HiRes; use Net::IRC3::Client::Connection; my $BOTSERVER = 'irc.plan9.de'; my $BOTPORT = '6667'; my $BOTNAME = 'cfbot'; my $BOTCHAN = '#cf'; my $CON; # the connection sub on_unload { $CON->disconnect if $CON; undef $CON; } sub do_notice { my ($msg) = @_; $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN); } sub check_connection { return if $CON; $CON = Net::IRC3::Client::Connection->new; $CON->connect ($BOTSERVER, $BOTPORT); $CON->send_srv (JOIN => undef, $BOTCHAN); $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); $CON->reg_cb ( #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, irc_privmsg => sub { my ($con, $msg) = @_; my $name = 'irc'; my $NOW = Time::HiRes::time; my $tmsg = $msg->{trailing}; $tmsg =~ s/\x01[^\x01]*\x01//g; if ($tmsg =~ m/\S/) { $_->ob->message ( "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg", cf::NDI_BLUE ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; } 1; }, # registered => sub { # 1; # }, disconnect => sub { undef $CON; 0; } ); } my $timer; sub new_timer { $timer = AnyEvent->timer (after => 10, cb => sub { check_connection (); &new_timer; # and restart the time }); } new_timer; # create first timer check_connection ();