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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines