ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
Revision: 1.8
Committed: Fri Aug 25 17:08:20 2006 UTC (17 years, 8 months ago) by root
Branch: MAIN
Changes since 1.7: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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