line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::IRC::Server::Chinese::Channel; |
2
|
1
|
|
|
1
|
|
5
|
use Mojo::IRC::Server::Chinese::Base 'Mojo::IRC::Server::Chinese::Object'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
5
|
use List::Util qw(first); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
982
|
|
4
|
|
|
|
|
|
|
has 'name'; |
5
|
|
|
|
|
|
|
has id => sub {lc $_[0]->name}; |
6
|
|
|
|
|
|
|
has topic => sub {"欢迎来到 " . $_[0]->name}; |
7
|
|
|
|
|
|
|
has ctime => sub {time()}; |
8
|
|
|
|
|
|
|
has mode => 'i'; |
9
|
|
|
|
|
|
|
has pass => undef; |
10
|
|
|
|
|
|
|
has user => sub {[]}; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub count { |
13
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
14
|
0
|
|
|
|
|
|
0+@{$s->user}; |
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
sub add_user{ |
17
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
18
|
0
|
0
|
|
|
|
|
my $uid = ref($_[0]) eq "Mojo::IRC::Server::Chinese::User"?$_[0]->id:$_[0]; |
19
|
0
|
0
|
|
|
|
|
push @{$s->user},$uid if not $s->is_has_user($uid); |
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
sub remove_user{ |
22
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
23
|
0
|
0
|
|
|
|
|
my $uid = ref($_[0]) eq "Mojo::IRC::Server::Chinese::User"?$_[0]->id:$_[0]; |
24
|
0
|
|
|
|
|
|
for(my $i=0;$i<@{$s->user};$i++){ |
|
0
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if($uid eq $s->user->[$i]){ |
26
|
0
|
|
|
|
|
|
splice @{$s->user},$i,1; |
|
0
|
|
|
|
|
|
|
27
|
0
|
0
|
0
|
|
|
|
if(@{$s->user} == 0 and $s->mode !~/P/){ |
|
0
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$s->{_server}->remove_channel($s); |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
sub is_has_user{ |
35
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
36
|
0
|
0
|
|
|
|
|
my $uid = ref($_[0]) eq "Mojo::IRC::Server::Chinese::User"?$_[0]->id:$_[0]; |
37
|
0
|
0
|
|
|
|
|
if(defined $uid){ |
38
|
0
|
0
|
|
0
|
|
|
return (first {$uid eq $_} @{$s->user})?1:0; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else{ |
41
|
0
|
|
|
|
|
|
return 0+@{$s->user}; |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
sub set_topic{ |
46
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
47
|
0
|
|
|
|
|
|
my $user = shift; |
48
|
0
|
|
|
|
|
|
my $topic = shift; |
49
|
0
|
|
|
|
|
|
$s->topic($topic); |
50
|
0
|
|
|
|
|
|
$s->broadcast($user->ident,"TOPIC",$s->name,$topic); |
51
|
0
|
|
|
|
|
|
$s->info($s->name . " 主题设置为: " . $s->topic); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
sub set_mode{ |
54
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
55
|
0
|
|
|
|
|
|
my $user = shift; |
56
|
0
|
|
|
|
|
|
my $mode = shift; |
57
|
0
|
0
|
0
|
|
|
|
$mode = "+" . $mode if (substr($mode,0,1) ne '+' and substr($mode,0,1) ne '-'); |
58
|
0
|
|
|
|
|
|
my %mode = map {$_=>1} split //,$s->mode; |
|
0
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if(substr($mode,0,1) eq "+"){ |
|
|
0
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$mode{$_}=1 for split //,substr($mode,1,); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif(substr($mode,0,1) eq "-"){ |
63
|
0
|
|
|
|
|
|
delete $mode{$_} for split //,substr($mode,1,); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else{ |
66
|
0
|
|
|
|
|
|
%mode = (); |
67
|
0
|
|
|
|
|
|
$mode{$_}=1 for split //,$mode; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
$s->mode(join "",keys %mode); |
70
|
0
|
|
|
|
|
|
$s->broadcast($user->ident,"MODE",$s->name,$mode); |
71
|
0
|
|
|
|
|
|
$s->info("[" . $s->name . "] 模式设置为: " . $s->mode); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub users{ |
75
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
76
|
0
|
|
|
|
|
|
my @users = (); |
77
|
0
|
|
|
|
|
|
for my $uid (@{$s->user}){ |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $user = $s->search_user(id=>$uid); |
79
|
0
|
0
|
|
|
|
|
push @users ,$user if defined $user; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
return @users; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub broadcast { |
85
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
86
|
0
|
|
|
|
|
|
for my $user ($s->users){ |
87
|
0
|
|
|
|
|
|
$user->send(@_); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub forward { |
92
|
0
|
|
|
0
|
0
|
|
my $s = shift; |
93
|
0
|
|
|
|
|
|
my $except_user = shift; |
94
|
0
|
|
|
|
|
|
for my $user ($s->users){ |
95
|
0
|
0
|
|
|
|
|
next if $user->id eq $except_user->id; |
96
|
0
|
|
|
|
|
|
$user->send(@_); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |