… | |
… | |
3 | use Time::HiRes; |
3 | use Time::HiRes; |
4 | use Net::IRC3::Client::Connection; |
4 | use Net::IRC3::Client::Connection; |
5 | |
5 | |
6 | # requires: commands.ext |
6 | # requires: commands.ext |
7 | |
7 | |
8 | my $BOTSERVER = 'localhost'; |
8 | return unless exists $cf::CFG{irc_server}; |
9 | my $BOTPORT = '6667'; |
9 | |
10 | my $BOTNAME = 'cfbot'; |
10 | my $BOTSERVER = $cf::CFG{irc_server}; |
11 | my $BOTCHAN = '#cf'; |
11 | my $BOTPORT = $cf::CFG{irc_port}; |
|
|
12 | my $BOTNAME = $cf::CFG{irc_nick}; |
|
|
13 | my $BOTCHAN = $cf::CFG{irc_chan}; |
12 | |
14 | |
13 | my $CON; # the connection |
15 | my $CON; # the connection |
14 | |
16 | |
15 | sub unload { |
17 | sub unload { |
16 | $CON->disconnect if $CON; |
18 | $CON->disconnect if $CON; |
… | |
… | |
19 | |
21 | |
20 | sub do_notice { |
22 | sub do_notice { |
21 | my ($msg) = @_; |
23 | my ($msg) = @_; |
22 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
24 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
23 | if $CON; |
25 | if $CON; |
|
|
26 | } |
|
|
27 | |
|
|
28 | sub users { |
|
|
29 | $CON |
|
|
30 | ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} } |
|
|
31 | : () |
24 | } |
32 | } |
25 | |
33 | |
26 | sub handle_fcmd { |
34 | sub handle_fcmd { |
27 | my ($name, $me, $msg) = @_; |
35 | my ($name, $me, $msg) = @_; |
28 | |
36 | |
… | |
… | |
89 | 0; |
97 | 0; |
90 | } |
98 | } |
91 | ); |
99 | ); |
92 | } |
100 | } |
93 | |
101 | |
94 | my $timer; |
102 | Event->timer (after => 1, interval => 30, cb => \&check_connection); |
95 | |
103 | |
96 | sub new_timer { |
|
|
97 | $timer = AnyEvent->timer (after => 10, cb => sub { |
|
|
98 | check_connection (); |
|
|
99 | &new_timer; # and restart the time |
|
|
100 | }); |
|
|
101 | } |
|
|
102 | |
|
|
103 | new_timer; # create first timer |
|
|
104 | check_connection (); |
|
|