1 |
elmex |
1.1 |
#! perl |
2 |
|
|
use Time::HiRes; |
3 |
|
|
use Net::IRC3::Client::Connection; |
4 |
|
|
|
5 |
|
|
my $BOTSERVER = 'irc.plan9.de'; |
6 |
|
|
my $BOTPORT = '6667'; |
7 |
|
|
my $BOTNAME = 'cfbot'; |
8 |
|
|
my $BOTCHAN = '#cf'; |
9 |
|
|
|
10 |
|
|
my $CON; # the connection |
11 |
|
|
|
12 |
|
|
sub on_unload { |
13 |
|
|
$CON->disconnect; |
14 |
|
|
undef $CON; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
sub do_notice { |
18 |
|
|
my ($msg) = @_; |
19 |
|
|
$CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
sub check_connection { |
23 |
|
|
return if $CON; |
24 |
|
|
$CON = Net::IRC3::Client::Connection->new; |
25 |
|
|
$CON->connect ($BOTSERVER, $BOTPORT); |
26 |
|
|
$CON->send_srv (JOIN => undef, $BOTCHAN); |
27 |
|
|
$CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); |
28 |
|
|
$CON->reg_cb ( |
29 |
|
|
#d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, |
30 |
|
|
irc_privmsg => sub { |
31 |
|
|
my ($con, $msg) = @_; |
32 |
|
|
my $name = 'irc'; |
33 |
|
|
my $NOW = Time::HiRes::time; |
34 |
|
|
$_->ob->message ( |
35 |
|
|
"$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $msg->{trailing}", |
36 |
|
|
cf::NDI_BLUE |
37 |
|
|
) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
38 |
|
|
1; |
39 |
|
|
}, |
40 |
|
|
registered => sub { |
41 |
|
|
warn "BOP\n"; |
42 |
|
|
1; |
43 |
|
|
}, |
44 |
|
|
disconnect => sub { |
45 |
|
|
undef $CON; |
46 |
|
|
0; |
47 |
|
|
} |
48 |
|
|
); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
my $timer; |
52 |
|
|
|
53 |
|
|
sub new_timer { |
54 |
|
|
$timer = AnyEvent->timer (after => 10, cb => sub { |
55 |
|
|
check_connection (); |
56 |
|
|
&new_timer; # and restart the time |
57 |
|
|
}); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
new_timer; # create first timer |
61 |
|
|
check_connection (); |