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