ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
Revision: 1.3
Committed: Thu Aug 3 11:15:49 2006 UTC (17 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.2: +8 -4 lines
Log Message:
ignoring ctcps now

File Contents

# Content
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 my $tmsg = $msg->{trailing};
35 $tmsg =~ s/\x01[^\x01]*\x01//g;
36 if ($tmsg =~ m/\S/) {
37 $_->ob->message (
38 "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg",
39 cf::NDI_BLUE
40 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
41 }
42 1;
43 },
44 # registered => sub {
45 # 1;
46 # },
47 disconnect => sub {
48 undef $CON;
49 0;
50 }
51 );
52 }
53
54 my $timer;
55
56 sub new_timer {
57 $timer = AnyEvent->timer (after => 10, cb => sub {
58 check_connection ();
59 &new_timer; # and restart the time
60 });
61 }
62
63 new_timer; # create first timer
64 check_connection ();