ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
Revision: 1.7
Committed: Mon Aug 21 01:58:24 2006 UTC (17 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.6: +2 -1 lines
Log Message:
added if

File Contents

# User Rev Content
1 elmex 1.1 #! perl
2 root 1.4
3 elmex 1.1 use Time::HiRes;
4     use Net::IRC3::Client::Connection;
5    
6 root 1.6 my $BOTSERVER = 'localhost';
7 elmex 1.1 my $BOTPORT = '6667';
8     my $BOTNAME = 'cfbot';
9     my $BOTCHAN = '#cf';
10    
11     my $CON; # the connection
12    
13     sub on_unload {
14 elmex 1.5 $CON->disconnect if $CON;
15 elmex 1.1 undef $CON;
16     }
17    
18     sub do_notice {
19     my ($msg) = @_;
20 elmex 1.7 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN)
21     if $CON;
22 elmex 1.1 }
23    
24     sub check_connection {
25     return if $CON;
26 root 1.4
27 elmex 1.1 $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 elmex 1.3 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 elmex 1.1 1;
46     },
47 elmex 1.2 # registered => sub {
48     # 1;
49     # },
50 elmex 1.1 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 ();