… | |
… | |
19 | undef $CON; |
19 | undef $CON; |
20 | } |
20 | } |
21 | |
21 | |
22 | sub do_notice { |
22 | sub do_notice { |
23 | my ($msg) = @_; |
23 | my ($msg) = @_; |
|
|
24 | |
|
|
25 | utf8::encode $msg; |
24 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
26 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
25 | if $CON; |
27 | if $CON; |
26 | } |
28 | } |
27 | |
29 | |
28 | sub users { |
30 | sub users { |
… | |
… | |
32 | } |
34 | } |
33 | |
35 | |
34 | sub handle_fcmd { |
36 | sub handle_fcmd { |
35 | my ($name, $me, $msg) = @_; |
37 | my ($name, $me, $msg) = @_; |
36 | |
38 | |
|
|
39 | utf8::decode $msg; |
|
|
40 | |
37 | if ($msg eq "!who") { |
41 | if ($msg eq "!who") { |
38 | $CON->send_chan ($BOTCHAN, NOTICE => $_, $BOTCHAN) |
42 | do_notice $_ |
39 | for ext::commands::who_listing (); |
43 | for ext::commands::who_listing (); |
40 | |
44 | |
41 | } elsif ($msg =~ /^\!tell/) { |
45 | } elsif ($msg =~ /^\!tell/) { |
42 | my (undef, $target, $tmsg) = split / /, $msg, 3; |
46 | my (undef, $target, $tmsg) = split / /, $msg, 3; |
43 | |
47 | |
44 | if (my $other = cf::player::find $target) { |
48 | if (my $other = cf::player::find_active $target) { |
45 | |
49 | |
46 | if ($tmsg) { |
50 | if ($tmsg) { |
47 | if ($me eq $target) { |
51 | if ($me eq $target) { |
48 | $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN); |
52 | $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN); |
49 | } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) { |
53 | } 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); |
54 | $CON->send_chan ($BOTCHAN, NOTICE => "$me: $target ignores what you say. Give up on it.", $BOTCHAN); |
51 | } else { |
55 | } 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; |
56 | cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg; |
54 | |
57 | |
55 | $other->ob->message ("$name/$me tells you: $tmsg"); |
58 | $other->ob->message ("$name/$me tells you: $tmsg"); |
56 | $other->ob->{ext_last_tell} = "$name/$me"; |
59 | $other->ob->{ext_last_tell} = "$name/$me"; |
57 | } |
60 | } |
58 | } else { |
61 | } else { |
59 | $CON->send_chan ($BOTCHAN, NOTICE => "$me: What do you want to tell $target?", cf::NDI_UNIQUE); |
62 | do_notice "$me: What do you want to tell $target?"; |
60 | } |
63 | } |
61 | |
64 | |
62 | } |
65 | } |
63 | } |
66 | } |
64 | } |
67 | } |
… | |
… | |
78 | my $nick = Net::IRC3::Util::prefix_nick ($msg); |
81 | my $nick = Net::IRC3::Util::prefix_nick ($msg); |
79 | my $NOW = Time::HiRes::time; |
82 | my $NOW = Time::HiRes::time; |
80 | my $tmsg = $msg->{trailing}; |
83 | my $tmsg = $msg->{trailing}; |
81 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
84 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
82 | $tmsg =~ s/\015?\012/ /g; |
85 | $tmsg =~ s/\015?\012/ /g; |
|
|
86 | utf8::encode $tmsg; # ->message not yet utf8-ified |
83 | if ($tmsg =~ /^\!/) { |
87 | if ($tmsg =~ /^\!/) { |
84 | handle_fcmd ($name, $nick, $tmsg); |
88 | handle_fcmd ($name, $nick, $tmsg); |
85 | } elsif ($tmsg =~ m/\S/) { |
89 | } elsif ($tmsg =~ m/\S/) { |
86 | $_->ob->message ( |
90 | $_->ob->message ( |
87 | "$name/".$nick." chats: $tmsg", cf::NDI_BLUE |
91 | "$name/".$nick." chats: $tmsg", cf::NDI_BLUE |
… | |
… | |
91 | }, |
95 | }, |
92 | # registered => sub { |
96 | # registered => sub { |
93 | # 1; |
97 | # 1; |
94 | # }, |
98 | # }, |
95 | disconnect => sub { |
99 | disconnect => sub { |
|
|
100 | my ($con, $reason) = @_; |
|
|
101 | warn "CFBOT: disconnect: $reason\n"; |
96 | undef $CON; |
102 | undef $CON; |
97 | 0; |
103 | 0; |
98 | } |
104 | } |
99 | ); |
105 | ); |
100 | } |
106 | } |
101 | |
107 | |
102 | Event->timer (after => 1, interval => 30, data => cf::WF_AUTOCANCEL, cb => \&check_connection); |
108 | Event->timer ( |
|
|
109 | reentrant => 0, |
|
|
110 | after => 1, |
|
|
111 | interval => 30, |
|
|
112 | data => cf::WF_AUTOCANCEL, |
|
|
113 | cb => Coro::unblock_sub { check_connection }, |
|
|
114 | ); |
103 | |
115 | |