ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/schmorp-irc.ext
(Generate patch)

Comparing deliantra/maps/perl/schmorp-irc.ext (file contents):
Revision 1.1 by elmex, Wed Aug 2 16:59:47 2006 UTC vs.
Revision 1.19 by root, Sun Nov 26 02:37:53 2006 UTC

1#! perl 1#! perl
2
2use Time::HiRes; 3use Time::HiRes;
3use Net::IRC3::Client::Connection; 4use Net::IRC3::Client::Connection;
4 5
5my $BOTSERVER = 'irc.plan9.de'; 6# requires: commands.ext
6my $BOTPORT = '6667'; 7
7my $BOTNAME = 'cfbot'; 8return unless exists $cf::CFG{irc_server};
8my $BOTCHAN = '#cf'; 9
10my $BOTSERVER = $cf::CFG{irc_server};
11my $BOTPORT = $cf::CFG{irc_port};
12my $BOTNAME = $cf::CFG{irc_nick};
13my $BOTCHAN = $cf::CFG{irc_chan};
9 14
10my $CON; # the connection 15my $CON; # the connection
11 16
12sub on_unload { 17sub unload {
13 $CON->disconnect; 18 $CON->disconnect if $CON;
14 undef $CON; 19 undef $CON;
15} 20}
16 21
17sub do_notice { 22sub do_notice {
18 my ($msg) = @_; 23 my ($msg) = @_;
19 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN); 24 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN)
25 if $CON;
26}
27
28sub users {
29 $CON
30 ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} }
31 : ()
32}
33
34sub handle_fcmd {
35 my ($name, $me, $msg) = @_;
36
37 if ($msg eq "!who") {
38 $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN)
39 for ext::commands::who_listing ();
40
41 } elsif ($msg =~ /^\!tell/) {
42 my (undef, $target, $tmsg) = split / /, $msg, 3;
43
44 if (my $other = cf::player::find $target) {
45
46 if ($tmsg) {
47 if ($me eq $target) {
48 $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN);
49 } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) {
50 $CON->send_chan ($BOTCHAN, NOTICE => "$me: $target ignores what you say. Give up on it.", $BOTCHAN);
51 } else {
52 utf8::encode $tmsg; # ->message not yet utf8-ified
53 cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg;
54
55 $other->ob->message ("$name/$me tells you: $tmsg");
56 $other->ob->{ext_last_tell} = "$name/$me";
57 }
58 } else {
59 $CON->send_chan ($BOTCHAN, NOTICE => "$me: What do you want to tell $target?", cf::NDI_UNIQUE);
60 }
61
62 }
63 }
20} 64}
21 65
22sub check_connection { 66sub check_connection {
23 return if $CON; 67 return if $CON;
68
24 $CON = Net::IRC3::Client::Connection->new; 69 $CON = Net::IRC3::Client::Connection->new;
25 $CON->connect ($BOTSERVER, $BOTPORT); 70 $CON->connect ($BOTSERVER, $BOTPORT);
26 $CON->send_srv (JOIN => undef, $BOTCHAN); 71 $CON->send_srv (JOIN => undef, $BOTCHAN);
27 $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); 72 $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection');
28 $CON->reg_cb ( 73 $CON->reg_cb (
29 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, 74 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
30 irc_privmsg => sub { 75 irc_privmsg => sub {
31 my ($con, $msg) = @_; 76 my ($con, $msg) = @_;
32 my $name = 'irc'; 77 my $name = 'irc';
78 my $nick = Net::IRC3::Util::prefix_nick ($msg);
33 my $NOW = Time::HiRes::time; 79 my $NOW = Time::HiRes::time;
80 my $tmsg = $msg->{trailing};
81 $tmsg =~ s/\x01[^\x01]*\x01//g;
82 $tmsg =~ s/\015?\012/ /g;
83 if ($tmsg =~ /^\!/) {
84 handle_fcmd ($name, $nick, $tmsg);
85 } elsif ($tmsg =~ m/\S/) {
34 $_->ob->message ( 86 $_->ob->message (
35 "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $msg->{trailing}", 87 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
36 cf::NDI_BLUE
37 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 88 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
89 }
38 1; 90 1;
39 }, 91 },
40 registered => sub { 92# registered => sub {
41 warn "BOP\n";
42 1; 93# 1;
43 }, 94# },
44 disconnect => sub { 95 disconnect => sub {
45 undef $CON; 96 undef $CON;
46 0; 97 0;
47 } 98 }
48 ); 99 );
49} 100}
50 101
51my $timer; 102Event->timer (after => 1, interval => 30, cb => \&check_connection);
52 103
53sub new_timer {
54 $timer = AnyEvent->timer (after => 10, cb => sub {
55 check_connection ();
56 &new_timer; # and restart the time
57 });
58}
59
60new_timer; # create first timer
61check_connection ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines