ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
Revision: 1.2
Committed: Wed Aug 2 17:11:53 2006 UTC (17 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.1: +3 -4 lines
Log Message:
removed forgotten debugging output

File Contents

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