… | |
… | |
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 | return unless $cf::CFG{irc_server}; |
8 | return unless exists $cf::CFG{irc_server}; |
9 | |
9 | |
10 | my $BOTSERVER = $cf::CFG{irc_server}; |
10 | my $BOTSERVER = $cf::CFG{irc_server}; |
11 | my $BOTPORT = $cf::CFG{irc_port}; |
11 | my $BOTPORT = $cf::CFG{irc_port}; |
12 | my $BOTNAME = $cf::CFG{irc_nick}; |
12 | my $BOTNAME = $cf::CFG{irc_nick}; |
13 | my $BOTCHAN = $cf::CFG{irc_chan}; |
13 | my $BOTCHAN = $cf::CFG{irc_chan}; |
… | |
… | |
21 | |
21 | |
22 | sub do_notice { |
22 | sub do_notice { |
23 | my ($msg) = @_; |
23 | my ($msg) = @_; |
24 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
24 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
25 | if $CON; |
25 | if $CON; |
|
|
26 | } |
|
|
27 | |
|
|
28 | sub users { |
|
|
29 | $CON |
|
|
30 | ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} } |
|
|
31 | : () |
26 | } |
32 | } |
27 | |
33 | |
28 | sub handle_fcmd { |
34 | sub handle_fcmd { |
29 | my ($name, $me, $msg) = @_; |
35 | my ($name, $me, $msg) = @_; |
30 | |
36 | |
… | |
… | |
91 | 0; |
97 | 0; |
92 | } |
98 | } |
93 | ); |
99 | ); |
94 | } |
100 | } |
95 | |
101 | |
96 | my $timer; |
102 | Event->timer (after => 1, interval => 30, data => cf::WF_AUTOCANCEL, cb => \&check_connection); |
97 | |
103 | |
98 | sub new_timer { |
|
|
99 | $timer = AnyEvent->timer (after => 10, cb => sub { |
|
|
100 | check_connection (); |
|
|
101 | &new_timer; # and restart the time |
|
|
102 | }); |
|
|
103 | } |
|
|
104 | |
|
|
105 | new_timer; # create first timer |
|
|
106 | check_connection (); |
|
|