1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | use Time::HiRes; |
|
|
4 | use AnyEvent::IRC::Client; |
3 | use AnyEvent::IRC::Client; |
5 | use AnyEvent::IRC::Util qw/filter_colors/; |
4 | use AnyEvent::IRC::Util qw/filter_colors/; |
6 | |
5 | |
7 | # requires: commands.ext |
6 | # requires: commands.ext |
8 | |
7 | |
9 | return unless exists $cf::CFG{irc_server}; |
8 | return unless exists $cf::CFG{irc_server}; |
10 | |
9 | |
11 | our $BOTSERVER = $cf::CFG{irc_server}; |
10 | CONF BOTSERVER : irc_server = undef; |
12 | our $BOTPORT = $cf::CFG{irc_port}; |
11 | CONF BOTPORT : irc_port = undef; |
13 | our $BOTNAME = $cf::CFG{irc_nick}; |
12 | CONF BOTNAME : irc_nick = undef; |
14 | our $BOTCHAN = $cf::CFG{irc_chan}; |
13 | CONF BOTCHAN : irc_chan = undef; |
15 | |
14 | |
16 | our $CON; # the connection |
15 | our $CON; # the connection |
17 | |
16 | |
18 | sub unload { |
17 | sub unload { |
19 | $CON->disconnect if $CON; |
18 | $CON->disconnect if $CON; |
… | |
… | |
29 | } |
28 | } |
30 | |
29 | |
31 | sub users { |
30 | sub users { |
32 | $CON |
31 | $CON |
33 | ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} } |
32 | ? grep $_ ne $CON->nick, keys %{ $CON->channel_list->{$BOTCHAN} || {} } |
34 | : () |
33 | : () |
35 | } |
34 | } |
|
|
35 | |
|
|
36 | # for nicklist monitoring, #d# should be done event-based |
|
|
37 | our %NICKLIST; |
|
|
38 | our $NICKLIST = AE::timer 20, 59.17, sub { |
|
|
39 | return unless defined &ext::nickmon::NT_OTHER; |
|
|
40 | |
|
|
41 | my %NEXTLIST; |
|
|
42 | for (users) { |
|
|
43 | &ext::nickmon::upd ("irc/$_", &ext::nickmon::NT_OTHER, "irc") |
|
|
44 | unless exists $NICKLIST{$_}; |
|
|
45 | |
|
|
46 | delete $NICKLIST{$_}; |
|
|
47 | undef $NEXTLIST{$_}; |
|
|
48 | } |
|
|
49 | |
|
|
50 | &ext::nickmon::del ("irc/$_") |
|
|
51 | for keys %NICKLIST; |
|
|
52 | |
|
|
53 | %NICKLIST = %NEXTLIST; |
|
|
54 | }; |
36 | |
55 | |
37 | sub handle_fcmd { |
56 | sub handle_fcmd { |
38 | my ($name, $me, $msg) = @_; |
57 | my ($name, $me, $msg) = @_; |
39 | |
58 | |
40 | if ($msg eq "!who") { |
59 | if ($msg eq "!who") { |
… | |
… | |
83 | $CON->reg_cb ( |
102 | $CON->reg_cb ( |
84 | irc_privmsg => sub { |
103 | irc_privmsg => sub { |
85 | my ($con, $msg) = @_; |
104 | my ($con, $msg) = @_; |
86 | my $name = 'irc'; |
105 | my $name = 'irc'; |
87 | my $nick = AnyEvent::IRC::Util::prefix_nick ($msg); |
106 | my $nick = AnyEvent::IRC::Util::prefix_nick ($msg); |
88 | my $NOW = Time::HiRes::time; |
107 | my $NOW = EV::time; |
89 | |
108 | |
90 | my $tmsg = filter_colors ($msg->{params}->[-1]); |
109 | my $tmsg = filter_colors ($msg->{params}->[-1]); |
91 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
110 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
92 | $tmsg =~ s/\015?\012/ /g; |
111 | $tmsg =~ s/\015?\012/ /g; |
93 | |
112 | |