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