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.6 by root, Fri Aug 18 04:06:31 2006 UTC vs.
Revision 1.16 by root, Fri Sep 29 19:21:25 2006 UTC

1#! perl 1#! perl
2 2
3use Time::HiRes; 3use Time::HiRes;
4use Net::IRC3::Client::Connection; 4use Net::IRC3::Client::Connection;
5
6# requires: commands.ext
5 7
6my $BOTSERVER = 'localhost'; 8my $BOTSERVER = 'localhost';
7my $BOTPORT = '6667'; 9my $BOTPORT = '6667';
8my $BOTNAME = 'cfbot'; 10my $BOTNAME = 'cfbot';
9my $BOTCHAN = '#cf'; 11my $BOTCHAN = '#cf';
10 12
11my $CON; # the connection 13my $CON; # the connection
12 14
13sub on_unload { 15sub unload {
14 $CON->disconnect if $CON; 16 $CON->disconnect if $CON;
15 undef $CON; 17 undef $CON;
16} 18}
17 19
18sub do_notice { 20sub do_notice {
19 my ($msg) = @_; 21 my ($msg) = @_;
20 $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 }
21} 56}
22 57
23sub check_connection { 58sub check_connection {
24 return if $CON; 59 return if $CON;
25 60
30 $CON->reg_cb ( 65 $CON->reg_cb (
31 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, 66 #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 },
32 irc_privmsg => sub { 67 irc_privmsg => sub {
33 my ($con, $msg) = @_; 68 my ($con, $msg) = @_;
34 my $name = 'irc'; 69 my $name = 'irc';
70 my $nick = Net::IRC3::Util::prefix_nick ($msg);
35 my $NOW = Time::HiRes::time; 71 my $NOW = Time::HiRes::time;
36 my $tmsg = $msg->{trailing}; 72 my $tmsg = $msg->{trailing};
37 $tmsg =~ s/\x01[^\x01]*\x01//g; 73 $tmsg =~ s/\x01[^\x01]*\x01//g;
74 $tmsg =~ s/\015?\012/ /g;
38 if ($tmsg =~ m/\S/) { 75 if ($tmsg =~ /^\!/) {
76 handle_fcmd ($name, $nick, $tmsg);
77 } elsif ($tmsg =~ m/\S/) {
39 $_->ob->message ( 78 $_->ob->message (
40 "$name/".Net::IRC3::Util::prefix_nick ($msg)." chats: $tmsg", 79 "$name/".$nick." chats: $tmsg", cf::NDI_BLUE
41 cf::NDI_BLUE
42 ) 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;
43 } 81 }
44 1; 82 1;
45 }, 83 },
46# registered => sub { 84# registered => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines