1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | use Time::HiRes; |
3 | use Time::HiRes; |
4 | use Net::IRC3::Client::Connection; |
4 | use Net::IRC3::Client::Connection; |
5 | |
5 | |
6 | my $BOTSERVER = 'localhost'; |
6 | # requires: commands.ext |
7 | my $BOTPORT = '6667'; |
7 | |
8 | my $BOTNAME = 'cfbot'; |
8 | return unless exists $cf::CFG{irc_server}; |
9 | my $BOTCHAN = '#cf'; |
9 | |
|
|
10 | my $BOTSERVER = $cf::CFG{irc_server}; |
|
|
11 | my $BOTPORT = $cf::CFG{irc_port}; |
|
|
12 | my $BOTNAME = $cf::CFG{irc_nick}; |
|
|
13 | my $BOTCHAN = $cf::CFG{irc_chan}; |
10 | |
14 | |
11 | my $CON; # the connection |
15 | my $CON; # the connection |
12 | |
16 | |
13 | sub unload { |
17 | sub unload { |
14 | $CON->disconnect if $CON; |
18 | $CON->disconnect if $CON; |
… | |
… | |
19 | my ($msg) = @_; |
23 | my ($msg) = @_; |
20 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
24 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
21 | if $CON; |
25 | if $CON; |
22 | } |
26 | } |
23 | |
27 | |
|
|
28 | sub users { |
|
|
29 | $CON |
|
|
30 | ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} } |
|
|
31 | : () |
|
|
32 | } |
|
|
33 | |
24 | sub handle_fcmd { |
34 | sub handle_fcmd { |
25 | my ($name, $me, $msg) = @_; |
35 | my ($name, $me, $msg) = @_; |
26 | |
36 | |
27 | if ($msg eq "!who") { |
37 | if ($msg eq "!who") { |
28 | my ($numplayers, $numwiz, @plist) = (0, 0); |
38 | $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN) |
|
|
39 | for ext::commands::who_listing (); |
29 | |
40 | |
30 | foreach my $pl (cf::player::list) { |
|
|
31 | $numplayers++; |
|
|
32 | $numwiz++ |
|
|
33 | if ($pl->ob->flag (cf::FLAG_WIZ)); |
|
|
34 | push (@plist, $pl); |
|
|
35 | } |
|
|
36 | |
|
|
37 | $CON->send_chan ($BOTCHAN, NOTICE => "Total Players in The World. ($numplayers) -- WIZ($numwiz)", $BOTCHAN); |
|
|
38 | |
|
|
39 | if ($numplayers > 0) { |
|
|
40 | foreach my $pl (@plist) { |
|
|
41 | $CON->send_chan ($BOTCHAN, NOTICE => |
|
|
42 | "* " . $pl->ob->name . "/" . $pl->ob->level . " " . ( length $pl->own_title ? $pl->own_title : "the " . $pl->title ) . " " |
|
|
43 | .($pl->ob->flag (cf::FLAG_WIZ) ? " [WIZ] " : "") |
|
|
44 | ." [" . ($pl->ob->map ? $pl->ob->map->path : "NULL") . "]", $BOTCHAN); |
|
|
45 | } |
|
|
46 | } |
|
|
47 | } elsif ($msg =~ /^\!tell/) { |
41 | } elsif ($msg =~ /^\!tell/) { |
48 | my (undef, $target, $tmsg) = split / /, $msg, 3; |
42 | my (undef, $target, $tmsg) = split / /, $msg, 3; |
49 | |
43 | |
50 | if (my $other = cf::player::find $target) { |
44 | if (my $other = cf::player::find $target) { |
51 | |
45 | |
… | |
… | |
103 | 0; |
97 | 0; |
104 | } |
98 | } |
105 | ); |
99 | ); |
106 | } |
100 | } |
107 | |
101 | |
108 | my $timer; |
102 | Event->timer (after => 1, interval => 30, cb => \&check_connection); |
109 | |
103 | |
110 | sub new_timer { |
|
|
111 | $timer = AnyEvent->timer (after => 10, cb => sub { |
|
|
112 | check_connection (); |
|
|
113 | &new_timer; # and restart the time |
|
|
114 | }); |
|
|
115 | } |
|
|
116 | |
|
|
117 | new_timer; # create first timer |
|
|
118 | check_connection (); |
|
|