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.3 by elmex, Thu Aug 3 11:15:49 2006 UTC vs.
Revision 1.16 by root, Fri Sep 29 19:21:25 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
7
8my $BOTSERVER = 'localhost';
6my $BOTPORT = '6667'; 9my $BOTPORT = '6667';
7my $BOTNAME = 'cfbot'; 10my $BOTNAME = 'cfbot';
8my $BOTCHAN = '#cf'; 11my $BOTCHAN = '#cf';
9 12
10my $CON; # the connection 13my $CON; # the connection
11 14
12sub on_unload { 15sub unload {
13 $CON->disconnect; 16 $CON->disconnect if $CON;
14 undef $CON; 17 undef $CON;
15} 18}
16 19
17sub do_notice { 20sub do_notice {
18 my ($msg) = @_; 21 my ($msg) = @_;
19 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN); 22 $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN)
23 if $CON;
24}
25
26sub handle_fcmd {
27 my ($name, $me, $msg) = @_;
28
29 if ($msg eq "!who") {
30 $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN)
31 for ext::commands::who_listing ();
32
33 } elsif ($msg =~ /^\!tell/) {
34 my (undef, $target, $tmsg) = split / /, $msg, 3;
35
36 if (my $other = cf::player::find $target) {
37
38 if ($tmsg) {
39 if ($me eq $target) {
40 $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN);
41 } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) {
42 $CON->send_chan ($BOTCHAN, NOTICE => "$me: $target ignores what you say. Give up on it.", $BOTCHAN);
43 } else {
44 utf8::encode $tmsg; # ->message not yet utf8-ified
45 cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg;
46
47 $other->ob->message ("$name/$me tells you: $tmsg");
48 $other->ob->{ext_last_tell} = "$name/$me";
49 }
50 } else {
51 $CON->send_chan ($BOTCHAN, NOTICE => "$me: What do you want to tell $target?", cf::NDI_UNIQUE);
52 }
53
54 }
55 }
20} 56}
21 57
22sub check_connection { 58sub check_connection {
23 return if $CON; 59 return if $CON;
60
24 $CON = Net::IRC3::Client::Connection->new; 61 $CON = Net::IRC3::Client::Connection->new;
25 $CON->connect ($BOTSERVER, $BOTPORT); 62 $CON->connect ($BOTSERVER, $BOTPORT);
26 $CON->send_srv (JOIN => undef, $BOTCHAN); 63 $CON->send_srv (JOIN => undef, $BOTCHAN);
27 $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); 64 $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection');
28 $CON->reg_cb ( 65 $CON->reg_cb (
29 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, 66 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
30 irc_privmsg => sub { 67 irc_privmsg => sub {
31 my ($con, $msg) = @_; 68 my ($con, $msg) = @_;
32 my $name = 'irc'; 69 my $name = 'irc';
70 my $nick = Net::IRC3::Util::prefix_nick ($msg);
33 my $NOW = Time::HiRes::time; 71 my $NOW = Time::HiRes::time;
34 my $tmsg = $msg->{trailing}; 72 my $tmsg = $msg->{trailing};
35 $tmsg =~ s/\x01[^\x01]*\x01//g; 73 $tmsg =~ s/\x01[^\x01]*\x01//g;
74 $tmsg =~ s/\015?\012/ /g;
36 if ($tmsg =~ m/\S/) { 75 if ($tmsg =~ /^\!/) {
76 handle_fcmd ($name, $nick, $tmsg);
77 } elsif ($tmsg =~ m/\S/) {
37 $_->ob->message ( 78 $_->ob->message (
38 "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg", 79 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
39 cf::NDI_BLUE
40 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 80 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
41 } 81 }
42 1; 82 1;
43 }, 83 },
44# registered => sub { 84# registered => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines