line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Webqq::Qun; |
2
|
1
|
|
|
1
|
|
416
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
547
|
use JSON; |
|
1
|
|
|
|
|
10091
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
645
|
use Storable qw(dclone); |
|
1
|
|
|
|
|
2153
|
|
|
1
|
|
|
|
|
62
|
|
5
|
1
|
|
|
1
|
|
4
|
use Scalar::Util qw(blessed reftype); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
102
|
|
6
|
1
|
|
|
1
|
|
5
|
use base qw(Webqq::Qun::Authorize Webqq::Qun::Operate Webqq::Qun::Base); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
431
|
|
7
|
|
|
|
|
|
|
use HTTP::Cookies; |
8
|
|
|
|
|
|
|
use LWP::UserAgent; |
9
|
|
|
|
|
|
|
use LWP::Protocol::https; |
10
|
|
|
|
|
|
|
use Webqq::Qun::One; |
11
|
|
|
|
|
|
|
use Webqq::Qun::Member; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = "1.5"; |
14
|
|
|
|
|
|
|
sub new { |
15
|
|
|
|
|
|
|
my $class = shift; |
16
|
|
|
|
|
|
|
my %p = @_; |
17
|
|
|
|
|
|
|
my $agent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062'; |
18
|
|
|
|
|
|
|
my $self = { |
19
|
|
|
|
|
|
|
cookie_jar => HTTP::Cookies->new(hide_cookie2=>1), |
20
|
|
|
|
|
|
|
debug => $p{debug} || 0, |
21
|
|
|
|
|
|
|
qq => $p{qq}, |
22
|
|
|
|
|
|
|
pwd => $p{pwd}, |
23
|
|
|
|
|
|
|
referer => "http://qun.qq.com/member.html", |
24
|
|
|
|
|
|
|
token => undef, |
25
|
|
|
|
|
|
|
_authorize => {}, |
26
|
|
|
|
|
|
|
data => [], |
27
|
|
|
|
|
|
|
self => {}, |
28
|
|
|
|
|
|
|
friend => [], |
29
|
|
|
|
|
|
|
is_load_data => 0, |
30
|
|
|
|
|
|
|
is_authorize => 0, |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
$self->{ua} = LWP::UserAgent->new( |
34
|
|
|
|
|
|
|
cookie_jar => $self->{cookie_jar}, |
35
|
|
|
|
|
|
|
agent => $agent, |
36
|
|
|
|
|
|
|
timeout => 300, |
37
|
|
|
|
|
|
|
ssl_opts => {verify_hostname => 0}, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
if($self->{debug}){ |
40
|
|
|
|
|
|
|
$self->{ua}->add_handler(request_send => sub { |
41
|
|
|
|
|
|
|
my($request, $ua, $h) = @_; |
42
|
|
|
|
|
|
|
print $request->as_string; |
43
|
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
}); |
45
|
|
|
|
|
|
|
$self->{ua}->add_handler( |
46
|
|
|
|
|
|
|
response_header => sub { my($response, $ua, $h) = @_; |
47
|
|
|
|
|
|
|
print $response->as_string; |
48
|
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
}); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
bless $self,$class; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub each_qun { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
$self->get_qun(); |
57
|
|
|
|
|
|
|
my $callback = shift; |
58
|
|
|
|
|
|
|
$self->SUPER::each($self->{data},sub{ |
59
|
|
|
|
|
|
|
my $q = shift; |
60
|
|
|
|
|
|
|
$callback->(bless $q,__PACKAGE__."::One"); |
61
|
|
|
|
|
|
|
}); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
sub find_qun{ |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
$self->get_qun(); |
66
|
|
|
|
|
|
|
my %p = @_; |
67
|
|
|
|
|
|
|
my ($qun_type,$qun_number,$qun_name) = @p{qw(qun_type qun_number qun_name)}; |
68
|
|
|
|
|
|
|
my @qun; |
69
|
|
|
|
|
|
|
$self->SUPER::each($self->{data},sub{ |
70
|
|
|
|
|
|
|
my $q = shift; |
71
|
|
|
|
|
|
|
return if defined $qun_type and $q->{qun_type} ne $qun_type; |
72
|
|
|
|
|
|
|
return if defined $qun_number and $q->{qun_number} ne $qun_number; |
73
|
|
|
|
|
|
|
return if defined $qun_name and $q->{qun_name} ne $qun_name; |
74
|
|
|
|
|
|
|
push @qun,bless dclone($q),__PACKAGE__ ."::One"; |
75
|
|
|
|
|
|
|
}); |
76
|
|
|
|
|
|
|
return wantarray?@qun:$qun[0]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub find_member { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
$self->get_qun(); |
82
|
|
|
|
|
|
|
my %p = @_; |
83
|
|
|
|
|
|
|
my @member; |
84
|
|
|
|
|
|
|
my %filter = ( |
85
|
|
|
|
|
|
|
sex => 1, |
86
|
|
|
|
|
|
|
card => 1, |
87
|
|
|
|
|
|
|
qq => 1, |
88
|
|
|
|
|
|
|
nick => 1, |
89
|
|
|
|
|
|
|
role => 1, |
90
|
|
|
|
|
|
|
bad_record => 1, |
91
|
|
|
|
|
|
|
qun_name => 1, |
92
|
|
|
|
|
|
|
qun_number => 1, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
for my $k (keys %p){ |
95
|
|
|
|
|
|
|
unless(exists $filter{$k}){ |
96
|
|
|
|
|
|
|
delete $p{$k} ; |
97
|
|
|
|
|
|
|
next; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
delete $p{$k} unless defined $p{$k}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
my @tmp; |
102
|
|
|
|
|
|
|
push @tmp,@{$_->{members}} for @{$self->{data}}; |
103
|
|
|
|
|
|
|
$self->SUPER::each(@tmp,sub{ |
104
|
|
|
|
|
|
|
my $m = shift; |
105
|
|
|
|
|
|
|
for my $k (keys %p){ |
106
|
|
|
|
|
|
|
return if $m->{$k} ne $p{$k}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
push @member,bless dclone($m),"Webqq::Qun::Member"; |
109
|
|
|
|
|
|
|
}); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return wantarray?@member:$member[0]; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub each_member { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
$self->get_qun(); |
117
|
|
|
|
|
|
|
my $callback = shift; |
118
|
|
|
|
|
|
|
$self->SUPER::each($self->{data},sub{ |
119
|
|
|
|
|
|
|
my $q = shift; |
120
|
|
|
|
|
|
|
for (@{$q->{members}}){ |
121
|
|
|
|
|
|
|
my $m = dclone($_); |
122
|
|
|
|
|
|
|
bless $m,"Webqq::Qun::Member"; |
123
|
|
|
|
|
|
|
$callback->($m); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
}); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub del_member { |
129
|
|
|
|
|
|
|
my $self = shift; |
130
|
|
|
|
|
|
|
my %opt; |
131
|
|
|
|
|
|
|
for my $p (@_){ |
132
|
|
|
|
|
|
|
my ($qq,$qun_number); |
133
|
|
|
|
|
|
|
if(blessed($p) eq "Webqq::Qun::Member"){ |
134
|
|
|
|
|
|
|
$qq = $p->{qq}; |
135
|
|
|
|
|
|
|
$qun_number = $p->{qun_number}; |
136
|
|
|
|
|
|
|
push @{ $opt{$qun_number} },$qq; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
for my $qun_number (keys %opt){ |
140
|
|
|
|
|
|
|
$self->SUPER::del_member($qun_number,@{$opt{$qun_number}}); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub add_member { |
145
|
|
|
|
|
|
|
my $self = shift; |
146
|
|
|
|
|
|
|
my %opt; |
147
|
|
|
|
|
|
|
for my $p (@_){ |
148
|
|
|
|
|
|
|
my ($qq,$qun_number); |
149
|
|
|
|
|
|
|
if(blessed($p) eq "Webqq::Qun::Member"){ |
150
|
|
|
|
|
|
|
$qq = $p->{qq}; |
151
|
|
|
|
|
|
|
$qun_number = $p->{qun_number}; |
152
|
|
|
|
|
|
|
push @{ $opt{$qun_number} },$qq; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
for my $qun_number (keys %opt){ |
156
|
|
|
|
|
|
|
$self->SUPER::add_member($qun_number,@{$opt{$qun_number}}); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub set_admin { |
162
|
|
|
|
|
|
|
my $self = shift; |
163
|
|
|
|
|
|
|
my %opt; |
164
|
|
|
|
|
|
|
for my $p (@_){ |
165
|
|
|
|
|
|
|
my ($qq,$qun_number); |
166
|
|
|
|
|
|
|
if(blessed($p) eq "Webqq::Qun::Member"){ |
167
|
|
|
|
|
|
|
$qq = $p->{qq}; |
168
|
|
|
|
|
|
|
$qun_number = $p->{qun_number}; |
169
|
|
|
|
|
|
|
push @{ $opt{$qun_number} },$qq; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
for my $qun_number (keys %opt){ |
173
|
|
|
|
|
|
|
$self->SUPER::set_admin($qun_number,@{$opt{$qun_number}}); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub del_admin { |
178
|
|
|
|
|
|
|
my $self = shift; |
179
|
|
|
|
|
|
|
for my $p (@_){ |
180
|
|
|
|
|
|
|
my ($qq,$qun_number); |
181
|
|
|
|
|
|
|
if(blessed($p) eq "Webqq::Qun::Member"){ |
182
|
|
|
|
|
|
|
$qq = $p->{qq}; |
183
|
|
|
|
|
|
|
$qun_number = $p->{qun_number}; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
$self->SUPER::del_admin($qun_number,$qq); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub set_card{ |
191
|
|
|
|
|
|
|
my $self = shift; |
192
|
|
|
|
|
|
|
my $m = shift; |
193
|
|
|
|
|
|
|
my $card = shift; |
194
|
|
|
|
|
|
|
my %opt; |
195
|
|
|
|
|
|
|
my ($qq,$qun_number); |
196
|
|
|
|
|
|
|
if(blessed($m) eq "Webqq::Qun::Member"){ |
197
|
|
|
|
|
|
|
$qq = $m->{qq}; |
198
|
|
|
|
|
|
|
$qun_number = $m->{qun_number}; |
199
|
|
|
|
|
|
|
push @{ $opt{$qun_number} },$qq; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
for my $qun_number (keys %opt){ |
202
|
|
|
|
|
|
|
$self->SUPER::set_card($qun_number,$qq,$card); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
1; |