line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Weixin::Group; |
2
|
1
|
|
|
1
|
|
5
|
use Mojo::Weixin::Base 'Mojo::Weixin::Model::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
3
|
1
|
|
|
1
|
|
345
|
use Mojo::Weixin::Group::Member; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has 'id'; |
6
|
|
|
|
|
|
|
has 'uid'; |
7
|
|
|
|
|
|
|
has 'owner_uid'; |
8
|
|
|
|
|
|
|
has name => ''; |
9
|
|
|
|
|
|
|
has member => sub{[]}; |
10
|
|
|
|
|
|
|
has _avatar => ''; |
11
|
|
|
|
|
|
|
has _eid => ''; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub get_avatar{ |
14
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
15
|
0
|
|
|
|
|
|
$self->client->get_avatar($self,@_); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
sub displayname { |
18
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
19
|
0
|
0
|
|
|
|
|
return $self->name if $self->name; |
20
|
0
|
|
|
|
|
|
my $default_name = join "、", map { $_->displayname } grep {defined $_} (grep {$_->id ne $self->client->user->id} @{$self->member})[0..2]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
return $default_name?$default_name:"群名未知"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
sub new { |
24
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
25
|
0
|
|
|
|
|
|
my $self; |
26
|
0
|
0
|
0
|
|
|
|
bless $self=@_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; |
|
0
|
0
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
$self->uid("") if not $self->uid; |
28
|
0
|
0
|
0
|
|
|
|
if(exists $self->{member} and ref $self->{member} eq "ARRAY"){ |
29
|
0
|
|
|
|
|
|
for( @{ $self->{member} } ){ |
|
0
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
$_ = Mojo::Weixin::Group::Member->new($_) if ref $_ ne "Mojo::Weixin::Group::Member"; |
31
|
0
|
|
|
|
|
|
$_->_group_id($self->id); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$self->client->emoji_convert(\$self->{name},$self->client->emoji_to_text); |
36
|
0
|
|
|
|
|
|
$self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
sub is_empty{ |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
0
|
|
|
|
|
return !(ref($self->member) eq "ARRAY"?0+@{$self->member}:0); |
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
sub update { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my $hash = shift; |
45
|
0
|
|
|
|
|
|
for(grep {substr($_,0,1) ne "_"} keys %$hash){ |
|
0
|
|
|
|
|
|
|
46
|
0
|
0
|
0
|
|
|
|
if($_ eq "member" and ref $hash->{member} eq "ARRAY"){ |
47
|
0
|
0
|
|
|
|
|
next if not @{$hash->{member}}; |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my @member = |
49
|
0
|
|
|
|
|
|
map {$_->_group_id($self->id);$_} |
|
0
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
map {ref $_ eq "Mojo::Weixin::Group::Member"?$_:Mojo::Weixin::Group::Member->new($_)} |
51
|
0
|
|
|
|
|
|
@{$hash->{member}}; |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if( $self->is_empty() ){ |
54
|
0
|
|
|
|
|
|
$self->member(\@member); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else{ |
57
|
0
|
|
|
0
|
|
|
my($new_members,$lost_members,$sames)=$self->client->array_diff($self->member, \@member,sub{$_[0]->id}); |
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if(@{$new_members}){ |
|
0
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if(my @m = $self->client->_webwxbatchgetcontact_group_member($self->_eid,map {$_->id} @{$new_members})){ |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$new_members = [ map {$_->_group_id($self->id);$_ } map { Mojo::Weixin::Group::Member->new($_) } @m]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
for(@{$new_members}){ |
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->add_group_member($_); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
for(@{$lost_members}){ |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->remove_group_member($_); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
for(@{$sames}){ |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my($old_member,$new_member) = ($_->[0],$_->[1]); |
71
|
0
|
|
|
|
|
|
$old_member->update($new_member); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else{ |
76
|
0
|
0
|
|
|
|
|
if(exists $hash->{$_}){ |
77
|
0
|
0
|
|
|
|
|
$self->client->emoji_convert(\$hash->{$_},$self->client->emoji_to_text) if $_ eq "name"; |
78
|
0
|
0
|
0
|
|
|
|
if(defined $hash->{$_} and defined $self->{$_}){ |
|
|
0
|
0
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if($hash->{$_} ne $self->{$_}){ |
80
|
0
|
|
|
|
|
|
my $old_property = $self->{$_}; |
81
|
0
|
|
|
|
|
|
my $new_property = $hash->{$_}; |
82
|
0
|
|
|
|
|
|
$self->{$_} = $hash->{$_}; |
83
|
0
|
0
|
|
|
|
|
$self->client->emit("group_property_change"=>$self,$_,$old_property,$new_property) if defined $self->client; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif( ! (!defined $hash->{$_} and !defined $self->{$_}) ){ |
87
|
0
|
|
|
|
|
|
my $old_property = $self->{$_}; |
88
|
0
|
|
|
|
|
|
my $new_property = $hash->{$_}; |
89
|
0
|
|
|
|
|
|
$self->{$_} = $hash->{$_}; |
90
|
0
|
0
|
|
|
|
|
$self->client->emit("group_property_change"=>$self,$_,$old_property,$new_property) if defined $self->client; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
$self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub search_group_member{ |
99
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
100
|
0
|
|
|
|
|
|
my %p = @_; |
101
|
0
|
0
|
|
|
|
|
if($p{_check_remote}){ |
102
|
0
|
0
|
|
|
|
|
if(wantarray){ |
103
|
0
|
|
|
|
|
|
my @g = $self->_search($self->member,@_); |
104
|
0
|
0
|
|
|
|
|
if(@g){return @g} |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
else{ |
106
|
0
|
|
|
|
|
|
$self->client->update_group($self); |
107
|
0
|
|
|
|
|
|
return $self->_search($self->member,@_); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else{ |
111
|
0
|
|
|
|
|
|
my $g = $self->_search($self->member,@_); |
112
|
0
|
0
|
|
|
|
|
if(defined $g){return $g } |
|
0
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
else{ |
114
|
0
|
|
|
|
|
|
$self->client->update_group($self); |
115
|
0
|
|
|
|
|
|
return $self->_search($self->member,@_); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
|
return $self->_search($self->member,@_); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
sub add_group_member{ |
122
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
123
|
0
|
|
|
|
|
|
my $member = shift; |
124
|
0
|
0
|
|
|
|
|
$self->client->die("不支持的数据类型\n") if ref $member ne "Mojo::Weixin::Group::Member"; |
125
|
0
|
0
|
|
|
|
|
$self->client->emit(new_group_member=>$member,$self) if $self->_add($self->member,$member) == 1; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
sub remove_group_member{ |
128
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
129
|
0
|
|
|
|
|
|
my $member = shift; |
130
|
0
|
0
|
|
|
|
|
$self->client->die("不支持的数据类型\n") if ref $member ne "Mojo::Weixin::Group::Member"; |
131
|
0
|
0
|
|
|
|
|
$self->client->emit(lose_group_member=>$member,$self) if $self->_remove($self->member,$member) == 1; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
sub me { |
134
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
135
|
0
|
|
|
|
|
|
return $self->search_group_member(id=>$self->client->user->id); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
sub members { |
138
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
139
|
0
|
|
|
|
|
|
return @{$self->member}; |
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
sub send{ |
142
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
143
|
0
|
|
|
|
|
|
$self->client->send_message($self,@_); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
sub send_media { |
146
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
147
|
0
|
|
|
|
|
|
$self->client->send_media($self,@_); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
sub set_displayname{ |
150
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
151
|
0
|
|
|
|
|
|
my $displayname = shift; |
152
|
0
|
|
|
|
|
|
$self->client->set_group_displayname($self,$displayname); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
sub invite_friend{ |
155
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
156
|
0
|
|
|
|
|
|
$self->client->invite_friend($self,@_) |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
sub kick_group_member{ |
159
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
160
|
0
|
|
|
|
|
|
$self->client->kick_group_member($self,@_); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
sub stick{ |
163
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
164
|
0
|
|
|
|
|
|
$self->client->stick($self,@_); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |