line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Webqq; |
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
3
|
|
|
|
|
|
|
$Mojo::Webqq::Message::LAST_DISPATCH_TIME = undef; |
4
|
|
|
|
|
|
|
$Mojo::Webqq::Message::SEND_INTERVAL = 3; |
5
|
1
|
|
|
1
|
|
433
|
use Mojo::Webqq::Message; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
677
|
use Mojo::Webqq::Message::Remote::_get_sess_sig; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
7
|
1
|
|
|
1
|
|
714
|
use Mojo::Webqq::Message::Remote::_send_friend_message; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
737
|
use Mojo::Webqq::Message::Remote::_send_group_message; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
9
|
1
|
|
|
1
|
|
737
|
use Mojo::Webqq::Message::Remote::_send_discuss_message; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
10
|
1
|
|
|
1
|
|
863
|
use Mojo::Webqq::Message::Remote::_send_sess_message; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
891
|
use Mojo::Webqq::Message::Queue; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
13
|
1
|
|
|
1
|
|
870
|
use Mojo::Webqq::Message::Face; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
33
|
|
14
|
1
|
|
|
1
|
|
380
|
use Mojo::Webqq::Message::XMLescape; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
15
|
1
|
|
|
1
|
|
819
|
use Mojo::Webqq::Message::Emoji; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
36
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
7
|
use Mojo::Webqq::User; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
18
|
1
|
|
|
1
|
|
6
|
use Mojo::Webqq::Friend; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
19
|
1
|
|
|
1
|
|
6
|
use Mojo::Webqq::Group; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
20
|
1
|
|
|
1
|
|
5
|
use Mojo::Webqq::Group::Member; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
21
|
1
|
|
|
1
|
|
6
|
use Mojo::Webqq::Discuss; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
22
|
1
|
|
|
1
|
|
6
|
use Mojo::Webqq::Discuss::Member; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub gen_message_queue{ |
25
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
26
|
|
|
|
|
|
|
Mojo::Webqq::Message::Queue->new(sub{ |
27
|
0
|
|
|
0
|
|
|
my $msg = shift; |
28
|
0
|
0
|
|
|
|
|
return if $self->is_stop; |
29
|
0
|
0
|
|
|
|
|
if($msg->class eq "recv"){ |
|
|
0
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if($msg->type eq 'friend_message'){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
31
|
0
|
0
|
0
|
|
|
|
if( $self->has_subscribers("receive_pic") |
32
|
|
|
|
|
|
|
or $self->has_subscribers("receive_friend_pic") |
33
|
|
|
|
|
|
|
){ |
34
|
0
|
|
|
|
|
|
for(@{$msg->raw_content}){ |
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if($_->{type} eq 'offpic'){ |
36
|
0
|
|
|
|
|
|
$self->_get_offpic($_->{file_path},$msg->sender); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif($msg->type eq 'sess_message'){ |
42
|
0
|
0
|
0
|
|
|
|
if( $self->has_subscribers("receive_pic") |
43
|
|
|
|
|
|
|
or $self->has_subscribers("receive_sess_pic") |
44
|
|
|
|
|
|
|
){ |
45
|
0
|
|
|
|
|
|
for(@{$msg->raw_content}){ |
|
0
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if($_->{type} eq 'offpic'){ |
47
|
0
|
|
|
|
|
|
$self->_get_offpic($_->{file_path},$msg->sender); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif($msg->type eq 'group_message'){ |
53
|
0
|
0
|
0
|
|
|
|
if($self->has_subscribers("receive_pic") or $self->has_subscribers("receive_group_pic")){ |
54
|
0
|
|
|
|
|
|
for(@{$msg->raw_content}){ |
|
0
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if($_->{type} eq 'cface'){ |
56
|
0
|
0
|
|
|
|
|
return unless exists $_->{server}; |
57
|
0
|
0
|
|
|
|
|
return unless exists $_->{file_id}; |
58
|
0
|
0
|
|
|
|
|
return unless exists $_->{name}; |
59
|
0
|
|
|
|
|
|
my ($ip,$port) = split /:/,$_->{server}; |
60
|
0
|
0
|
|
|
|
|
$port = 80 unless defined $port; |
61
|
0
|
|
|
|
|
|
$self->_get_group_pic($_->{file_id},$_->{name},$ip,$port,$msg->sender); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif($msg->type eq 'discuss_message'){ |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif($msg->type eq 'state_message'){ |
69
|
0
|
|
|
|
|
|
my $friend = $self->search_friend(id=>$msg->id); |
70
|
0
|
0
|
|
|
|
|
if(defined $friend){ |
71
|
0
|
|
|
|
|
|
$friend->state($msg->state); |
72
|
0
|
|
|
|
|
|
$friend->client_type($msg->client_type); |
73
|
0
|
|
|
|
|
|
$self->emit(friend_state_change=>$friend); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#接收队列中接收到消息后,调用相关的消息处理回调,如果未设置回调,消息将丢弃 |
79
|
0
|
|
|
|
|
|
$self->emit(receive_message=>$msg); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif($msg->class eq "send"){ |
82
|
0
|
0
|
|
|
|
|
if($msg->source ne "local"){ |
83
|
0
|
|
|
|
|
|
$msg->send_status(code=>0,msg=>"发送成功",info=>"来自其他设备"); |
84
|
0
|
0
|
|
|
|
|
$msg->cb->($self,$msg) if ref $msg->cb eq 'CODE'; |
85
|
0
|
|
|
|
|
|
$self->emit(send_message=>$msg); |
86
|
0
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#消息的ttl值减少到0则丢弃消息 |
90
|
0
|
0
|
|
|
|
|
if($msg->ttl <= 0){ |
91
|
0
|
|
|
|
|
|
$self->warn("消息[ " . $msg->id. " ]已被消息队列丢弃,当前TTL: ". $msg->ttl); |
92
|
0
|
|
|
|
|
|
$msg->send_status(code=>-5,msg=>"发送失败",info=>"TTL失效"); |
93
|
0
|
0
|
|
|
|
|
if(ref $msg->cb eq 'CODE'){ |
94
|
0
|
|
|
|
|
|
$msg->cb->( |
95
|
|
|
|
|
|
|
$self, |
96
|
|
|
|
|
|
|
$msg, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
$self->emit(send_message=> |
100
|
|
|
|
|
|
|
$msg, |
101
|
|
|
|
|
|
|
); |
102
|
0
|
|
|
|
|
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
my $ttl = $msg->ttl; |
105
|
0
|
|
|
|
|
|
$msg->ttl(--$ttl); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $delay = 0; |
108
|
0
|
|
|
|
|
|
my $now = time; |
109
|
0
|
0
|
|
|
|
|
if(defined $Mojo::Webqq::Message::LAST_DISPATCH_TIME){ |
110
|
0
|
0
|
|
|
|
|
$delay = $now<$Mojo::Webqq::Message::LAST_DISPATCH_TIME+$Mojo::Webqq::Message::SEND_INTERVAL? |
111
|
|
|
|
|
|
|
$Mojo::Webqq::Message::LAST_DISPATCH_TIME+$Mojo::Webqq::Message::SEND_INTERVAL-$now |
112
|
|
|
|
|
|
|
: 0; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
$self->timer($delay,sub{ |
115
|
0
|
|
|
|
|
|
$msg->time(time); |
116
|
0
|
0
|
|
|
|
|
$msg->type eq 'friend_message' ? $self->_send_friend_message($msg) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
117
|
|
|
|
|
|
|
: $msg->type eq 'group_message' ? $self->_send_group_message($msg) |
118
|
|
|
|
|
|
|
: $msg->type eq 'sess_message' ? $self->_send_sess_message($msg) |
119
|
|
|
|
|
|
|
: $msg->type eq 'discuss_message' ? $self->_send_discuss_message($msg) |
120
|
|
|
|
|
|
|
: undef |
121
|
|
|
|
|
|
|
; |
122
|
0
|
|
|
|
|
|
}); |
123
|
0
|
|
|
|
|
|
$Mojo::Webqq::Message::LAST_DISPATCH_TIME = $now+$delay; |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
|
}); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
sub gen_message_id { |
128
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
129
|
0
|
|
|
|
|
|
my $last_send_msg_id = $self->send_msg_id; |
130
|
0
|
|
|
|
|
|
$self->send_msg_id(++$last_send_msg_id); |
131
|
0
|
|
|
|
|
|
return $last_send_msg_id; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub reply_message{ |
135
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
136
|
0
|
|
|
|
|
|
my ($msg,$content,$cb) = @_; |
137
|
0
|
0
|
|
|
|
|
if($msg->type eq "friend_message"){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
$self->send_friend_message($msg->sender,$content,$cb) if $msg->class eq "recv"; |
139
|
0
|
0
|
|
|
|
|
$self->send_friend_message($msg->receiver,$content,$cb) if $msg->class eq "send"; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
elsif($msg->type eq "group_message"){ |
142
|
0
|
|
|
|
|
|
$self->send_group_message($msg->group,$content,$cb); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
elsif($msg->type eq "discuss_message"){ |
145
|
0
|
|
|
|
|
|
$self->send_discuss_message($msg->discuss,$content,$cb); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
elsif($msg->type eq "sess_message"){ |
148
|
0
|
0
|
|
|
|
|
$self->send_sess_message($msg->sender,$content,$cb) if $msg->class eq "recv"; |
149
|
0
|
0
|
|
|
|
|
$self->send_sess_message($msg->receiver,$content,$cb) if $msg->class eq "send"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
sub send_friend_message{ |
153
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
154
|
0
|
0
|
|
|
|
|
if(@_==1){ |
155
|
0
|
|
|
|
|
|
my $msg = shift; |
156
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if ref $msg ne "Mojo::Webqq::Message"; |
157
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if $msg->type ne 'friend_message'; |
158
|
0
|
|
|
|
|
|
my $content = $msg->content; |
159
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
160
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
161
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
162
|
0
|
|
|
|
|
|
return $self; |
163
|
|
|
|
|
|
|
} |
164
|
0
|
|
|
|
|
|
my ($friend,$content,$cb) = @_; |
165
|
0
|
0
|
0
|
|
|
|
if(!defined $content or $content eq ""){ |
166
|
0
|
|
|
|
|
|
$self->warn("发送好友消息,内容不能为空"); |
167
|
0
|
|
|
|
|
|
return; |
168
|
|
|
|
|
|
|
} |
169
|
0
|
0
|
0
|
|
|
|
if(ref $friend eq "Mojo::Webqq::Friend" and defined $friend->id){ |
170
|
0
|
|
|
|
|
|
my $msg = Mojo::Webqq::Message->new({ |
171
|
|
|
|
|
|
|
type => 'friend_message', |
172
|
|
|
|
|
|
|
class => 'send', |
173
|
|
|
|
|
|
|
id => $self->gen_message_id, |
174
|
|
|
|
|
|
|
sender_id => $self->user->id, |
175
|
|
|
|
|
|
|
receiver_id => $friend->id, |
176
|
|
|
|
|
|
|
sender => $self->user, |
177
|
|
|
|
|
|
|
receiver => $friend, |
178
|
|
|
|
|
|
|
content => $content, |
179
|
|
|
|
|
|
|
raw_content => $self->face_parse($content), |
180
|
|
|
|
|
|
|
from => 'code', |
181
|
|
|
|
|
|
|
ttl => $self->msg_ttl, |
182
|
|
|
|
|
|
|
}); |
183
|
0
|
0
|
|
|
|
|
$cb->($self,$msg) if ref $cb eq "CODE"; |
184
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
185
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
186
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
else{ |
189
|
0
|
|
|
|
|
|
$self->die("不支持的数据类型"); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
sub send_group_message{ |
193
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
194
|
0
|
0
|
|
|
|
|
if(@_==1){ |
195
|
0
|
|
|
|
|
|
my $msg = shift; |
196
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if ref $msg ne "Mojo::Webqq::Message"; |
197
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if $msg->type ne 'group_message'; |
198
|
0
|
|
|
|
|
|
my $content = $msg->content; |
199
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
200
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
201
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
202
|
0
|
|
|
|
|
|
return $self; |
203
|
|
|
|
|
|
|
} |
204
|
0
|
|
|
|
|
|
my ($group,$content,$cb) = @_; |
205
|
0
|
0
|
0
|
|
|
|
if(!defined $content or $content eq ""){ |
206
|
0
|
|
|
|
|
|
$self->warn("发送群消息,内容不能为空"); |
207
|
0
|
|
|
|
|
|
return; |
208
|
|
|
|
|
|
|
} |
209
|
0
|
0
|
0
|
|
|
|
if(ref $group eq "Mojo::Webqq::Group" and defined $group->id){ |
210
|
0
|
|
0
|
|
|
|
my $sender = $group->me || $self->user; |
211
|
0
|
|
|
|
|
|
my $msg = Mojo::Webqq::Message->new({ |
212
|
|
|
|
|
|
|
type => 'group_message', |
213
|
|
|
|
|
|
|
class => 'send', |
214
|
|
|
|
|
|
|
id => $self->gen_message_id, |
215
|
|
|
|
|
|
|
sender_id => $sender->id, |
216
|
|
|
|
|
|
|
group_id => $group->id, |
217
|
|
|
|
|
|
|
sender => $sender, |
218
|
|
|
|
|
|
|
group => $group, |
219
|
|
|
|
|
|
|
content => $content, |
220
|
|
|
|
|
|
|
raw_content => $self->face_parse($content), |
221
|
|
|
|
|
|
|
from => 'code', |
222
|
|
|
|
|
|
|
ttl => $self->msg_ttl, |
223
|
|
|
|
|
|
|
}); |
224
|
0
|
0
|
|
|
|
|
$cb->($self,$msg) if ref $cb eq "CODE"; |
225
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
226
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
227
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
else{ |
230
|
0
|
|
|
|
|
|
$self->die("不支持的数据类型"); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
sub send_discuss_message{ |
234
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
235
|
0
|
0
|
|
|
|
|
if(@_==1){ |
236
|
0
|
|
|
|
|
|
my $msg = shift; |
237
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if ref $msg ne "Mojo::Webqq::Message"; |
238
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if $msg->type ne 'discuss_message'; |
239
|
0
|
|
|
|
|
|
my $content = $msg->content; |
240
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
241
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
242
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
243
|
0
|
|
|
|
|
|
return $self; |
244
|
|
|
|
|
|
|
} |
245
|
0
|
|
|
|
|
|
my ($discuss,$content,$cb) = @_; |
246
|
0
|
0
|
0
|
|
|
|
if(!defined $content or $content eq ""){ |
247
|
0
|
|
|
|
|
|
$self->warn("发送讨论组消息,内容不能为空"); |
248
|
0
|
|
|
|
|
|
return; |
249
|
|
|
|
|
|
|
} |
250
|
0
|
0
|
0
|
|
|
|
if(ref $discuss eq "Mojo::Webqq::Discuss" and defined $discuss->id){ |
251
|
0
|
|
0
|
|
|
|
my $sender = $discuss->search_discuss_member(id=>$self->user->id) || $self->user; |
252
|
|
|
|
|
|
|
#my $msg = Mojo::Webqq::Message::Send::DiscussMessage->new({ |
253
|
0
|
|
|
|
|
|
my $msg = Mojo::Webqq::Message->new({ |
254
|
|
|
|
|
|
|
type => 'discuss_message', |
255
|
|
|
|
|
|
|
class => 'send', |
256
|
|
|
|
|
|
|
id => $self->gen_message_id, |
257
|
|
|
|
|
|
|
sender_id => $sender->id, |
258
|
|
|
|
|
|
|
discuss_id => $discuss->id, |
259
|
|
|
|
|
|
|
sender => $sender, |
260
|
|
|
|
|
|
|
discuss => $discuss, |
261
|
|
|
|
|
|
|
content => $content, |
262
|
|
|
|
|
|
|
raw_content => $self->face_parse($content), |
263
|
|
|
|
|
|
|
from => 'code', |
264
|
|
|
|
|
|
|
ttl => $self->msg_ttl, |
265
|
|
|
|
|
|
|
}); |
266
|
0
|
0
|
|
|
|
|
$cb->($self,$msg) if ref $cb eq "CODE"; |
267
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
268
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
269
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
else{ |
272
|
0
|
|
|
|
|
|
$self->die("不支持的数据类型"); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
sub send_sess_message{ |
276
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
277
|
0
|
0
|
|
|
|
|
if(@_==1){ |
278
|
0
|
|
|
|
|
|
my $msg = shift; |
279
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if ref $msg ne "Mojo::Webqq::Message"; |
280
|
0
|
0
|
|
|
|
|
$self->die("不支持的数据类型") if $msg->type ne 'sess_message'; |
281
|
0
|
|
|
|
|
|
my $content = $msg->content; |
282
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
283
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
284
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
285
|
0
|
|
|
|
|
|
return $self; |
286
|
|
|
|
|
|
|
} |
287
|
0
|
|
|
|
|
|
my ($member,$content,$cb) = @_; |
288
|
0
|
0
|
0
|
|
|
|
if(!defined $content or $content eq ""){ |
289
|
0
|
|
|
|
|
|
$self->warn("发送临时消息,内容不能为空"); |
290
|
0
|
|
|
|
|
|
return; |
291
|
|
|
|
|
|
|
} |
292
|
0
|
0
|
0
|
|
|
|
if(ref $member eq "Mojo::Webqq::Group::Member" and defined $member->id and defined $member->id){ |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
293
|
0
|
|
|
|
|
|
my $group = $self->search_group(id=>$member->id); |
294
|
0
|
0
|
|
|
|
|
return unless defined $group; |
295
|
0
|
|
0
|
|
|
|
my $sender = $group->search_group_member(id=>$self->user->id) || $self->user; |
296
|
|
|
|
|
|
|
#my $msg = Mojo::Webqq::Message::Send::SessMessage->new({ |
297
|
0
|
|
|
|
|
|
my $msg = Mojo::Webqq::Message->new({ |
298
|
|
|
|
|
|
|
type => 'sess_message', |
299
|
|
|
|
|
|
|
class => 'send', |
300
|
|
|
|
|
|
|
id => $self->gen_message_id, |
301
|
|
|
|
|
|
|
sender_id => $sender->id, |
302
|
|
|
|
|
|
|
receiver_id => $member->id, |
303
|
|
|
|
|
|
|
group_id => $member->id, |
304
|
|
|
|
|
|
|
sender => $sender, |
305
|
|
|
|
|
|
|
receiver => $member, |
306
|
|
|
|
|
|
|
group => $self->search_group(id=>$member->id), |
307
|
|
|
|
|
|
|
content => $content, |
308
|
|
|
|
|
|
|
raw_content => $self->face_parse($content), |
309
|
|
|
|
|
|
|
via => "group", |
310
|
|
|
|
|
|
|
sess_sig => $self->_get_sess_sig($member->id,$member->id,0), |
311
|
|
|
|
|
|
|
from => 'code', |
312
|
|
|
|
|
|
|
ttl => $self->msg_ttl, |
313
|
|
|
|
|
|
|
}); |
314
|
0
|
0
|
|
|
|
|
$cb->($self,$msg) if ref $cb eq "CODE"; |
315
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
316
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
317
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
elsif(ref $member eq "Mojo::Webqq::Discuss::Member" and defined $member->id and defined $member->id){ |
320
|
0
|
|
|
|
|
|
my $discuss = $self->search_discuss(id=>$member->id); |
321
|
0
|
0
|
|
|
|
|
return unless defined $discuss; |
322
|
0
|
|
0
|
|
|
|
my $sender = $discuss->search_discuss_member(id=>$self->user->id) || $self->user; |
323
|
0
|
|
|
|
|
|
my $msg = Mojo::Webqq::Message->new({ |
324
|
|
|
|
|
|
|
type => 'sess_message', |
325
|
|
|
|
|
|
|
class => 'send', |
326
|
|
|
|
|
|
|
id => $self->gen_message_id, |
327
|
|
|
|
|
|
|
sender_id => $sender->id, |
328
|
|
|
|
|
|
|
receiver_id => $member->id, |
329
|
|
|
|
|
|
|
discuss_id => $member->id, |
330
|
|
|
|
|
|
|
sender => $sender, |
331
|
|
|
|
|
|
|
receiver => $member, |
332
|
|
|
|
|
|
|
discuss => $self->search_discuss(id=>$member->id), |
333
|
|
|
|
|
|
|
content => $content, |
334
|
|
|
|
|
|
|
raw_content => $self->face_parse($content), |
335
|
|
|
|
|
|
|
via => "discuss", |
336
|
|
|
|
|
|
|
sess_sig => $self->_get_sess_sig($member->id,$member->id,1), |
337
|
|
|
|
|
|
|
from => 'code', |
338
|
|
|
|
|
|
|
}); |
339
|
0
|
0
|
|
|
|
|
$cb->($self,$msg) if ref $cb eq "CODE"; |
340
|
0
|
|
|
|
|
|
$self->emit(before_send_message=>$msg); |
341
|
0
|
0
|
|
|
|
|
$msg->raw_content($self->face_parse($msg->content)) if $msg->content ne $content; |
342
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
else{ |
345
|
0
|
|
|
|
|
|
$self->die("不支持的数据类型"); |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub parse_receive_msg { |
350
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
351
|
0
|
|
|
|
|
|
my $json = shift; |
352
|
0
|
0
|
|
|
|
|
return if $self->is_stop; |
353
|
0
|
0
|
|
|
|
|
return unless defined $json; |
354
|
0
|
0
|
0
|
|
|
|
if ( $json->{retcode} == 0 ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
355
|
0
|
|
|
|
|
|
$self->poll_failure_count(0); |
356
|
0
|
|
|
|
|
|
for my $m ( @{ $json->{result} } ) { |
|
0
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
#收到群临时消息 |
358
|
0
|
0
|
|
|
|
|
if ( $m->{poll_type} eq 'sess_message' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
359
|
|
|
|
|
|
|
my $msg = { |
360
|
|
|
|
|
|
|
type => "sess_message", |
361
|
|
|
|
|
|
|
class => "recv", |
362
|
|
|
|
|
|
|
id => $m->{value}{msg_id}, |
363
|
|
|
|
|
|
|
sender_id => $m->{value}{from_uin}, |
364
|
|
|
|
|
|
|
receiver_id => $m->{value}{to_uin}, |
365
|
|
|
|
|
|
|
time => $m->{value}{'time'}, |
366
|
|
|
|
|
|
|
content => $m->{value}{content}, |
367
|
|
|
|
|
|
|
#service_type=> $m->{value}{service_type}, |
368
|
|
|
|
|
|
|
#ruin => $m->{value}{ruin}, |
369
|
0
|
|
|
|
|
|
}; |
370
|
0
|
0
|
|
|
|
|
if($msg->{sender_id} eq $self->user->id){ |
371
|
0
|
|
|
|
|
|
$msg->{class} = 'send'; |
372
|
0
|
|
|
|
|
|
$msg->{source} = 'outer'; |
373
|
0
|
0
|
|
|
|
|
next if not $self->allow_message_sync ; |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
#service_type =0 表示群临时消息,1 表示讨论组临时消息 |
377
|
0
|
0
|
|
|
|
|
if ( $m->{value}{service_type} == 0 ) { |
|
|
0
|
|
|
|
|
|
378
|
0
|
|
|
|
|
|
$msg->{group_id} = $m->{value}{id}; |
379
|
0
|
|
|
|
|
|
$msg->{via} = 'group'; |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
elsif ( $m->{value}{service_type} == 1 ) { |
382
|
0
|
|
|
|
|
|
$msg->{discuss_id} = $m->{value}{id}; |
383
|
0
|
|
|
|
|
|
$msg->{via} = 'discuss'; |
384
|
|
|
|
|
|
|
} |
385
|
0
|
|
|
|
|
|
else { next } |
386
|
0
|
|
|
|
|
|
$self->msg_put($msg); |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
#收到的消息是普通消息 |
390
|
|
|
|
|
|
|
elsif ( $m->{poll_type} eq 'message' ) { |
391
|
|
|
|
|
|
|
my $msg = { |
392
|
|
|
|
|
|
|
type => "friend_message", |
393
|
|
|
|
|
|
|
class => "recv", |
394
|
|
|
|
|
|
|
id => $m->{value}{msg_id}, |
395
|
|
|
|
|
|
|
sender_id => $m->{value}{from_uin}, |
396
|
|
|
|
|
|
|
receiver_id => $m->{value}{to_uin}, |
397
|
|
|
|
|
|
|
time => $m->{value}{'time'}, |
398
|
|
|
|
|
|
|
content => $m->{value}{content}, |
399
|
0
|
|
|
|
|
|
}; |
400
|
0
|
0
|
|
|
|
|
if($msg->{sender_id} eq $self->user->id){ |
401
|
0
|
|
|
|
|
|
$msg->{class} = 'send'; |
402
|
0
|
|
|
|
|
|
$msg->{source} = 'outer'; |
403
|
0
|
0
|
|
|
|
|
next if not $self->allow_message_sync ; |
404
|
|
|
|
|
|
|
} |
405
|
0
|
|
|
|
|
|
$self->msg_put($msg); |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
#收到的消息是群消息 |
409
|
|
|
|
|
|
|
elsif ( $m->{poll_type} eq 'group_message' ) { |
410
|
0
|
0
|
|
|
|
|
next if " \x{0000}\n\x{0000}\x{0000}\x{0000}\x{0000}\x{0002}\x{5B8B}\x{4F53}\r" eq $m->{value}{content}[1]; |
411
|
|
|
|
|
|
|
my $msg = { |
412
|
|
|
|
|
|
|
type => "group_message", |
413
|
|
|
|
|
|
|
class => "recv", |
414
|
|
|
|
|
|
|
id => $m->{value}{msg_id}, |
415
|
|
|
|
|
|
|
group_id => $m->{value}{from_uin}, |
416
|
|
|
|
|
|
|
receiver_id => $m->{value}{to_uin}, |
417
|
|
|
|
|
|
|
time => $m->{value}{'time'}, |
418
|
|
|
|
|
|
|
content => $m->{value}{content}, |
419
|
|
|
|
|
|
|
sender_id => $m->{value}{send_uin}, |
420
|
0
|
|
|
|
|
|
}; |
421
|
|
|
|
|
|
|
#if( $msg->{content}=~/\(\d+\) 被管理员禁言\d+(分钟|小时|天)$/ |
422
|
|
|
|
|
|
|
# or $msg->{content}=~/\(\d+\) 被管理员解除禁言$/ |
423
|
|
|
|
|
|
|
#){ |
424
|
|
|
|
|
|
|
# $msg->{type} = "system_message"; |
425
|
|
|
|
|
|
|
#} |
426
|
0
|
0
|
|
|
|
|
if($msg->{sender_id} eq $self->user->id){ |
427
|
0
|
|
|
|
|
|
$msg->{class} = 'send'; |
428
|
0
|
|
|
|
|
|
$msg->{source} = 'outer'; |
429
|
0
|
0
|
|
|
|
|
next if not $self->allow_message_sync ; |
430
|
|
|
|
|
|
|
} |
431
|
0
|
|
|
|
|
|
$self->msg_put($msg); |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
#收到讨论组消息 |
435
|
|
|
|
|
|
|
elsif ( $m->{poll_type} eq 'discu_message' ) { |
436
|
|
|
|
|
|
|
my $msg = { |
437
|
|
|
|
|
|
|
type => "discuss_message", |
438
|
|
|
|
|
|
|
class => "recv", |
439
|
|
|
|
|
|
|
discuss_id => $m->{value}{did}, |
440
|
|
|
|
|
|
|
id => $m->{value}{msg_id}, |
441
|
|
|
|
|
|
|
sender_id => $m->{value}{send_uin}, |
442
|
|
|
|
|
|
|
time => $m->{value}{'time'}, |
443
|
|
|
|
|
|
|
receiver_id => $m->{value}{'to_uin'}, |
444
|
|
|
|
|
|
|
content => $m->{value}{content}, |
445
|
0
|
|
|
|
|
|
}; |
446
|
0
|
0
|
|
|
|
|
if($msg->{sender_id} eq $self->user->id){ |
447
|
0
|
|
|
|
|
|
$msg->{class} = 'send'; |
448
|
0
|
|
|
|
|
|
$msg->{source} = 'outer'; |
449
|
0
|
0
|
|
|
|
|
next if not $self->allow_message_sync ; |
450
|
|
|
|
|
|
|
} |
451
|
0
|
|
|
|
|
|
$self->msg_put($msg); |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
elsif ( $m->{poll_type} eq 'buddies_status_change' ) { |
454
|
|
|
|
|
|
|
my $msg = { |
455
|
|
|
|
|
|
|
type => 'state_message', |
456
|
|
|
|
|
|
|
class => 'recv', |
457
|
|
|
|
|
|
|
id => $m->{value}{uin}, |
458
|
|
|
|
|
|
|
state => $m->{value}{status}, |
459
|
0
|
|
|
|
|
|
client_type => $self->code2client( $m->{value}{client_type} ), |
460
|
|
|
|
|
|
|
}; |
461
|
0
|
|
|
|
|
|
$self->msg_put($msg); |
462
|
|
|
|
|
|
|
} |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
#收到系统消息 |
465
|
|
|
|
|
|
|
#elsif ( $m->{poll_type} eq 'sys_g_msg' ) { |
466
|
|
|
|
|
|
|
# my $msg = { |
467
|
|
|
|
|
|
|
# type => 'system_message', |
468
|
|
|
|
|
|
|
# id => $m->{value}{msg_id}, |
469
|
|
|
|
|
|
|
# sender_id => $m->{value}{from_uin}, |
470
|
|
|
|
|
|
|
# receiver_id => $m->{value}{to_uin}, |
471
|
|
|
|
|
|
|
# |
472
|
|
|
|
|
|
|
# }; |
473
|
|
|
|
|
|
|
# $self->msg_put($msg); |
474
|
|
|
|
|
|
|
#} |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
#收到强制下线消息 |
477
|
|
|
|
|
|
|
elsif ( $m->{poll_type} eq 'kick_message' ) { |
478
|
0
|
0
|
|
|
|
|
if ( $m->{value}{show_reason} == 1 ) { |
479
|
0
|
|
|
|
|
|
my $reason = $m->{value}{reason}; |
480
|
0
|
|
|
|
|
|
$self->fatal("$reason\n"); |
481
|
0
|
|
|
|
|
|
$self->stop(); |
482
|
|
|
|
|
|
|
} |
483
|
|
|
|
|
|
|
else { |
484
|
0
|
|
|
|
|
|
$self->fatal("您已被迫下线\n"); |
485
|
0
|
|
|
|
|
|
$self->stop(); |
486
|
|
|
|
|
|
|
} |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
elsif( $m->{poll_type} eq 'group_web_message' ){ |
490
|
0
|
0
|
|
|
|
|
if(exists $m->{value}{xml}){ |
491
|
0
|
|
|
|
|
|
my %info; |
492
|
0
|
|
|
|
|
|
eval{ |
493
|
0
|
|
|
|
|
|
require Mojo::DOM; |
494
|
|
|
|
|
|
|
Mojo::DOM->new($m->{value}{xml})->find('d > n')->each(sub{ |
495
|
0
|
|
|
0
|
|
|
my ($e, $num) = @_; |
496
|
0
|
0
|
|
|
|
|
if($e->attr("t") eq "h" ){ |
|
|
0
|
|
|
|
|
|
497
|
0
|
|
|
|
|
|
$info{qq} = $e->attr("u"); |
498
|
|
|
|
|
|
|
} |
499
|
|
|
|
|
|
|
elsif($e->attr("t") eq "t" ){ |
500
|
0
|
0
|
|
|
|
|
if($e->attr("s") eq "共享文件"){ |
501
|
0
|
|
|
|
|
|
$info{type} = 'share-file'; |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
else{ |
504
|
0
|
|
|
|
|
|
$info{file} = $e->attr("s"); |
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
} |
507
|
0
|
|
|
|
|
|
}); |
508
|
|
|
|
|
|
|
}; |
509
|
0
|
0
|
0
|
|
|
|
if(defined $info{type} and $info{type} eq 'share-file'){ |
510
|
|
|
|
|
|
|
my $msg = { |
511
|
|
|
|
|
|
|
type => "group_message", |
512
|
|
|
|
|
|
|
class => "recv", |
513
|
|
|
|
|
|
|
id => $m->{value}{msg_id}, |
514
|
|
|
|
|
|
|
group_id => $m->{value}{from_uin}, |
515
|
|
|
|
|
|
|
time => time, |
516
|
|
|
|
|
|
|
content => [[],"共享文件 [$info{file}]"], |
517
|
|
|
|
|
|
|
sender_id => $m->{value}{send_uin}, |
518
|
|
|
|
|
|
|
|
519
|
0
|
|
|
|
|
|
}; |
520
|
0
|
0
|
|
|
|
|
if($msg->{sender_id} eq $self->user->id){ |
521
|
0
|
|
|
|
|
|
$msg->{class} = 'send'; |
522
|
0
|
|
|
|
|
|
$msg->{source} = 'outer'; |
523
|
0
|
0
|
|
|
|
|
next if not $self->allow_message_sync ; |
524
|
|
|
|
|
|
|
} |
525
|
0
|
|
|
|
|
|
$self->msg_put($msg); |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
#还未识别和处理的消息 |
531
|
|
|
|
|
|
|
else { |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
#更新客户端ptwebqq值 |
538
|
|
|
|
|
|
|
elsif ( $json->{retcode} == 116 ) { |
539
|
0
|
|
|
|
|
|
$self->debug("更新ptwebqq的值[ $json->{p} ]"); |
540
|
0
|
|
|
|
|
|
$self->ptwebqq($json->{p}); |
541
|
|
|
|
|
|
|
$self->ua->cookie_jar->add( |
542
|
0
|
|
|
|
|
|
Mojo::Cookie::Response->new(name=>"ptwebqq",value=>$json->{p},path=>"/",domain=>"qq.com",), |
543
|
|
|
|
|
|
|
); |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
#未重新登录 |
547
|
|
|
|
|
|
|
elsif ( $json->{retcode} == 100 or $json->{retcode} == 103) { |
548
|
0
|
|
|
|
|
|
$self->warn("因网络或其他原因与服务器失去联系,客户端需要重新登录...\n"); |
549
|
0
|
|
|
|
|
|
$self->relogin(); |
550
|
|
|
|
|
|
|
} |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
#重新连接失败 |
553
|
|
|
|
|
|
|
elsif ( $json->{retcode} == 120 or $json->{retcode} == 121 ) { |
554
|
0
|
|
|
|
|
|
$self->warn("因网络或其他原因与服务器失去联系,客户端需要重新连接...\n"); |
555
|
0
|
|
|
|
|
|
$self->_relink(); |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
elsif ($json->{retcode} == 100000){ |
559
|
0
|
|
|
|
|
|
$self->info("检测到登录状态失效(2),尝试重新登录"); |
560
|
0
|
|
|
|
|
|
$self->relogin(); |
561
|
|
|
|
|
|
|
} |
562
|
|
|
|
|
|
|
#可以忽略的消息,暂时不做任何处理 |
563
|
|
|
|
|
|
|
#elsif ($json->{retcode} == 102 |
564
|
|
|
|
|
|
|
# or $json->{retcode} == 109 |
565
|
|
|
|
|
|
|
# or $json->{retcode} == 110 |
566
|
|
|
|
|
|
|
# or $json->{retcode} == 100012 |
567
|
|
|
|
|
|
|
# or $json->{retcode} == 1202 ) |
568
|
|
|
|
|
|
|
#{ |
569
|
|
|
|
|
|
|
# $self->poll_failure_count(0); |
570
|
|
|
|
|
|
|
#} |
571
|
|
|
|
|
|
|
|
572
|
0
|
|
|
|
|
|
elsif( ref $self->ignore_poll_retcode eq "ARRAY" and grep { $json->{retcode} == $_} @{$self->ignore_poll_retcode}){ |
|
0
|
|
|
|
|
|
|
573
|
0
|
|
|
|
|
|
$self->debug("忽略接收消息中的异常状态码[ $json->{retcode} ]"); |
574
|
0
|
|
|
|
|
|
$self->poll_failure_count(0); |
575
|
|
|
|
|
|
|
} |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
#其他未知消息 |
578
|
|
|
|
|
|
|
else { |
579
|
0
|
|
|
|
|
|
$self->warn("接收消息返回未知状态码[ $json->{retcode} ]"); |
580
|
0
|
|
|
|
|
|
my $poll_failure_count = $self->poll_failure_count; |
581
|
0
|
|
|
|
|
|
$self->poll_failure_count( ++$poll_failure_count); |
582
|
0
|
|
|
|
|
|
$self->warn( "获取消息失败,当前失败次数: ". $self->poll_failure_count. "\n" ); |
583
|
0
|
0
|
|
|
|
|
if ( $self->poll_failure_count > $self->poll_failure_count_max ) { |
584
|
0
|
|
|
|
|
|
$self->poll_failure_count(0); |
585
|
|
|
|
|
|
|
#$self->warn("接收消息失败次数超过最大值,尝试进行重新连接...\n"); |
586
|
|
|
|
|
|
|
#$self->_relink(); |
587
|
0
|
|
|
|
|
|
$self->warn("接收消息失败次数超过最大值,尝试进行重新登录...\n"); |
588
|
0
|
|
|
|
|
|
$self->relogin(); |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
} |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
} |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
sub msg_put{ |
595
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
596
|
0
|
|
|
|
|
|
my $msg = shift; |
597
|
0
|
0
|
0
|
|
|
|
if( $msg->{type} eq "friend_message" |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
598
|
|
|
|
|
|
|
or $msg->{type} eq "group_message" |
599
|
|
|
|
|
|
|
or $msg->{type} eq "sess_message" |
600
|
|
|
|
|
|
|
or $msg->{type} eq "discuss_message" |
601
|
|
|
|
|
|
|
){ |
602
|
0
|
|
|
|
|
|
$msg->{raw_content} = []; |
603
|
0
|
0
|
0
|
|
|
|
if(@{ $msg->{content} } == 1 and ref $msg->{content}[0] eq "ARRAY" and $msg->{content}[0][0] eq 'font'){ |
|
0
|
|
0
|
|
|
|
|
604
|
0
|
|
|
|
|
|
push @{$msg->{raw_content}},{ |
|
0
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
type => 'txt', |
606
|
|
|
|
|
|
|
content => '[图片]', |
607
|
|
|
|
|
|
|
}; |
608
|
0
|
|
|
|
|
|
$msg->{content} = '[图片]'; |
609
|
|
|
|
|
|
|
} |
610
|
|
|
|
|
|
|
else{ |
611
|
0
|
|
|
|
|
|
my $msg_content; |
612
|
0
|
|
|
|
|
|
shift @{ $msg->{content} }; |
|
0
|
|
|
|
|
|
|
613
|
0
|
|
|
|
|
|
for my $c (@{ $msg->{content} }){ |
|
0
|
|
|
|
|
|
|
614
|
0
|
0
|
|
|
|
|
if(ref $c eq 'ARRAY'){ |
615
|
0
|
0
|
|
|
|
|
if($c->[0] eq 'cface'){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
616
|
0
|
|
|
|
|
|
push @{$msg->{raw_content}},{ |
617
|
|
|
|
|
|
|
type => 'cface', |
618
|
|
|
|
|
|
|
content => '[图片]', |
619
|
|
|
|
|
|
|
name => $c->[1]{name}, |
620
|
|
|
|
|
|
|
file_id => $c->[1]{file_id}, |
621
|
|
|
|
|
|
|
key => $c->[1]{key}, |
622
|
|
|
|
|
|
|
server => $c->[1]{server}, |
623
|
0
|
|
|
|
|
|
}; |
624
|
0
|
|
|
|
|
|
$c="[图片]"; |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
elsif($c->[0] eq 'offpic'){ |
627
|
0
|
|
|
|
|
|
push @{$msg->{raw_content}},{ |
628
|
|
|
|
|
|
|
type => 'offpic', |
629
|
|
|
|
|
|
|
content => '[图片]', |
630
|
|
|
|
|
|
|
file_path => $c->[1]{file_path}, |
631
|
0
|
|
|
|
|
|
}; |
632
|
0
|
|
|
|
|
|
$c="[图片]"; |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
elsif($c->[0] eq 'face'){ |
635
|
0
|
|
|
|
|
|
push @{$msg->{raw_content}},{ |
|
0
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
type => 'face', |
637
|
|
|
|
|
|
|
content => $self->face_to_txt($c), |
638
|
|
|
|
|
|
|
id => $c->[1], |
639
|
|
|
|
|
|
|
}; |
640
|
0
|
|
|
|
|
|
$c=$self->face_to_txt($c); |
641
|
|
|
|
|
|
|
} |
642
|
|
|
|
|
|
|
else{ |
643
|
0
|
|
|
|
|
|
push @{$msg->{raw_content}},{ |
|
0
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
type => 'unknown', |
645
|
|
|
|
|
|
|
content => '[未识别内容]', |
646
|
|
|
|
|
|
|
}; |
647
|
0
|
|
|
|
|
|
$c = "[未识别内容]"; |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
#elsif($c eq " "){ |
651
|
|
|
|
|
|
|
# next; |
652
|
|
|
|
|
|
|
#} |
653
|
|
|
|
|
|
|
else{ |
654
|
0
|
|
|
|
|
|
$c=$self->xmlescape_parse($c); |
655
|
|
|
|
|
|
|
#$c=~s/ $//; |
656
|
0
|
|
|
|
|
|
$c=~s/\r\n/\n/g; |
657
|
0
|
|
|
|
|
|
my $res = $self->emoji_parse($c); |
658
|
0
|
|
|
|
|
|
push @{$msg->{raw_content}},@$res; |
|
0
|
|
|
|
|
|
|
659
|
0
|
|
|
|
|
|
$c = join "",map{$_->{content}} @$res; |
|
0
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
#push @{$msg->{raw_content}},{ |
661
|
|
|
|
|
|
|
# type => 'txt', |
662
|
|
|
|
|
|
|
# content => $c, |
663
|
|
|
|
|
|
|
#}; |
664
|
|
|
|
|
|
|
} |
665
|
0
|
|
|
|
|
|
$msg_content .= $c; |
666
|
|
|
|
|
|
|
} |
667
|
0
|
|
|
|
|
|
$msg->{content} = $msg_content; |
668
|
|
|
|
|
|
|
} |
669
|
|
|
|
|
|
|
} |
670
|
0
|
0
|
|
|
|
|
if($msg->{type} eq "friend_message"){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
671
|
0
|
|
|
|
|
|
my $sender = $self->search_friend(id=>$msg->{sender_id}); |
672
|
0
|
|
|
|
|
|
my $receiver = $self->user; |
673
|
0
|
0
|
|
|
|
|
unless(defined $sender){#new friend |
674
|
0
|
|
|
|
|
|
$self->update_friend(); |
675
|
0
|
|
|
|
|
|
$sender = $self->search_friend(id=>$msg->{sender_id}); |
676
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
677
|
|
|
|
|
|
|
$sender = Mojo::Webqq::Friend->new( |
678
|
|
|
|
|
|
|
id => $msg->{sender_id}, |
679
|
0
|
|
|
|
|
|
name => "昵称未知", |
680
|
|
|
|
|
|
|
category => "陌生人", |
681
|
|
|
|
|
|
|
_flag => 1, |
682
|
|
|
|
|
|
|
); |
683
|
0
|
|
|
|
|
|
$self->add_friend($sender,1); |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
} |
686
|
0
|
|
|
|
|
|
$msg->{sender} = $sender; |
687
|
0
|
|
|
|
|
|
$msg->{receiver} = $receiver; |
688
|
0
|
|
|
|
|
|
$msg = Mojo::Webqq::Message->new($msg); |
689
|
|
|
|
|
|
|
} |
690
|
|
|
|
|
|
|
elsif($msg->{type} eq "group_message"){ |
691
|
0
|
|
|
|
|
|
my $sender; |
692
|
|
|
|
|
|
|
my $receiver; |
693
|
0
|
|
|
|
|
|
my $group; |
694
|
0
|
|
|
|
|
|
$group = $self->search_group(id=>$msg->{group_id}); |
695
|
0
|
0
|
|
|
|
|
if(defined $group){ |
696
|
0
|
|
|
|
|
|
$sender = $group->search_group_member(id=>$msg->{sender_id}); |
697
|
0
|
|
0
|
|
|
|
$receiver = $group->search_group_member(id=>$msg->{receiver_id}) || $self->user; |
698
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
699
|
0
|
|
|
|
|
|
$self->update_group($group); |
700
|
0
|
|
|
|
|
|
$sender = $group->search_group_member(id=>$msg->{sender_id}); |
701
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
702
|
|
|
|
|
|
|
$sender = Mojo::Webqq::Group::Member->new( |
703
|
|
|
|
|
|
|
id=>$msg->{sender_id}, |
704
|
0
|
|
|
|
|
|
name=>"昵称未知", |
705
|
|
|
|
|
|
|
_group_id=>$group->id, |
706
|
|
|
|
|
|
|
_flag=>1, |
707
|
|
|
|
|
|
|
); |
708
|
0
|
|
|
|
|
|
$group->add_group_member($sender,1); |
709
|
|
|
|
|
|
|
} |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
else{ |
713
|
0
|
|
|
|
|
|
$self->update_group(); |
714
|
0
|
|
|
|
|
|
$group = $self->search_group(id=>$msg->{group_id}); |
715
|
0
|
0
|
|
|
|
|
return unless defined $group; |
716
|
0
|
|
|
|
|
|
$sender = $group->search_group_member(id=>$msg->{sender_id}); |
717
|
0
|
|
0
|
|
|
|
$receiver = $group->search_group_member(id=>$msg->{receiver_id}) || $self->user; |
718
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
719
|
|
|
|
|
|
|
$sender = Mojo::Webqq::Group::Member->new( |
720
|
|
|
|
|
|
|
id => $msg->{sender_id}, |
721
|
0
|
|
|
|
|
|
name=>"昵称未知", |
722
|
|
|
|
|
|
|
_group_id => $group->id, |
723
|
|
|
|
|
|
|
_flag=>1, |
724
|
|
|
|
|
|
|
); |
725
|
0
|
|
|
|
|
|
$group->add_group_member($sender,1); |
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
} |
728
|
0
|
|
|
|
|
|
$msg->{sender} = $sender; |
729
|
0
|
|
|
|
|
|
$msg->{receiver} = $receiver; |
730
|
0
|
|
|
|
|
|
$msg->{group} = $group; |
731
|
|
|
|
|
|
|
#$msg = Mojo::Webqq::Message::Recv::GroupMessage->new($msg); |
732
|
0
|
|
|
|
|
|
$msg = Mojo::Webqq::Message->new($msg); |
733
|
|
|
|
|
|
|
} |
734
|
|
|
|
|
|
|
elsif($msg->{type} eq "sess_message"){ |
735
|
0
|
0
|
|
|
|
|
if($msg->{via} eq "group"){ |
|
|
0
|
|
|
|
|
|
736
|
0
|
|
|
|
|
|
my $sender; |
737
|
|
|
|
|
|
|
my $receiver; |
738
|
0
|
|
|
|
|
|
my $group; |
739
|
0
|
|
|
|
|
|
$group = $self->search_group(id=>$msg->{group_id}); |
740
|
0
|
0
|
|
|
|
|
if(defined $group){ |
741
|
0
|
|
|
|
|
|
$sender = $group->search_group_member(id=>$msg->{sender_id}); |
742
|
0
|
|
0
|
|
|
|
$receiver = $group->search_group_member(id=>$msg->{receiver_id}) || $self->user; |
743
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
744
|
0
|
|
|
|
|
|
$self->update_group($group); |
745
|
0
|
|
|
|
|
|
$sender = $group->search_group_member(id=>$msg->{sender_id}); |
746
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
747
|
|
|
|
|
|
|
$sender = Mojo::Webqq::Group::Member->new( |
748
|
|
|
|
|
|
|
_group_id=>$msg->{group_id}, |
749
|
|
|
|
|
|
|
id=>$msg->{sender_id}, |
750
|
0
|
|
|
|
|
|
name=>"昵称未知", |
751
|
|
|
|
|
|
|
_flag=>1, |
752
|
|
|
|
|
|
|
); |
753
|
0
|
|
|
|
|
|
$group->add_group_member($sender,1); |
754
|
|
|
|
|
|
|
} |
755
|
|
|
|
|
|
|
} |
756
|
|
|
|
|
|
|
} |
757
|
|
|
|
|
|
|
else{ |
758
|
0
|
|
|
|
|
|
$self->update_group(); |
759
|
0
|
|
|
|
|
|
$group = $self->search_group(id=>$msg->{group_id}); |
760
|
0
|
0
|
|
|
|
|
return unless defined $group; |
761
|
0
|
|
|
|
|
|
$sender = $group->search_group_member(id=>$msg->{sender_id}); |
762
|
0
|
|
0
|
|
|
|
$receiver = $group->search_group_member(id=>$msg->{receiver_id}) || $self->user; |
763
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
764
|
|
|
|
|
|
|
$sender = Mojo::Webqq::Group::Member->new( |
765
|
|
|
|
|
|
|
_group_id=>$msg->{group_id}, |
766
|
|
|
|
|
|
|
id=>$msg->{sender_id}, |
767
|
0
|
|
|
|
|
|
name=>"昵称未知", |
768
|
|
|
|
|
|
|
_flag=>1, |
769
|
|
|
|
|
|
|
); |
770
|
0
|
|
|
|
|
|
$group->add_group_member($sender,1); |
771
|
|
|
|
|
|
|
} |
772
|
|
|
|
|
|
|
} |
773
|
0
|
|
|
|
|
|
$msg->{sender} = $sender; |
774
|
0
|
|
|
|
|
|
$msg->{receiver} = $receiver; |
775
|
0
|
|
|
|
|
|
$msg->{group} = $group; |
776
|
|
|
|
|
|
|
} |
777
|
|
|
|
|
|
|
elsif($msg->{via} eq "discuss"){ |
778
|
0
|
|
|
|
|
|
my $sender; |
779
|
|
|
|
|
|
|
my $receiver; |
780
|
0
|
|
|
|
|
|
my $discuss; |
781
|
0
|
|
|
|
|
|
$discuss = $self->search_discuss(id=>$msg->{discuss_id}); |
782
|
0
|
0
|
|
|
|
|
if(defined $discuss){ |
783
|
0
|
|
|
|
|
|
$sender = $discuss->search_discuss_member(id=>$msg->{sender_id}); |
784
|
0
|
|
0
|
|
|
|
$receiver = $discuss->search_discuss_member(id=>$msg->{receiver_id}) || $self->user; |
785
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
786
|
0
|
|
|
|
|
|
$self->update_discuss($discuss); |
787
|
0
|
|
|
|
|
|
$sender = $discuss->search_discuss_member(id=>$msg->{sender_id}); |
788
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
789
|
|
|
|
|
|
|
$sender = Mojo::Webqq::Discuss::Member->new( |
790
|
|
|
|
|
|
|
_discuss_id=>$msg->{discuss_id}, |
791
|
|
|
|
|
|
|
id=>$msg->{sender_id}, |
792
|
0
|
|
|
|
|
|
name=>"昵称未知", |
793
|
|
|
|
|
|
|
_flag=>1, |
794
|
|
|
|
|
|
|
); |
795
|
0
|
|
|
|
|
|
$discuss->add_discuss_member($sender,1); |
796
|
|
|
|
|
|
|
} |
797
|
|
|
|
|
|
|
} |
798
|
|
|
|
|
|
|
} |
799
|
|
|
|
|
|
|
else{ |
800
|
0
|
|
|
|
|
|
$self->update_discuss(); |
801
|
0
|
|
|
|
|
|
$discuss = $self->search_discuss(id=>$msg->{discuss_id}); |
802
|
0
|
0
|
|
|
|
|
return unless defined $discuss; |
803
|
0
|
|
|
|
|
|
$sender = $discuss->search_discuss_member(id=>$msg->{sender_id}); |
804
|
0
|
|
0
|
|
|
|
$receiver = $discuss->search_discuss_member(id=>$msg->{receiver_id}) || $self->user; |
805
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
806
|
|
|
|
|
|
|
$sender = Mojo::Webqq::Discuss::Member->new( |
807
|
|
|
|
|
|
|
_discuss_id=>$msg->{discuss_id}, |
808
|
|
|
|
|
|
|
id=>$msg->{sender_id}, |
809
|
0
|
|
|
|
|
|
name=>"昵称未知", |
810
|
|
|
|
|
|
|
_flag=>1, |
811
|
|
|
|
|
|
|
); |
812
|
0
|
|
|
|
|
|
$discuss->add_discuss_member($sender,1); |
813
|
|
|
|
|
|
|
} |
814
|
|
|
|
|
|
|
} |
815
|
0
|
|
|
|
|
|
$msg->{sender} = $sender; |
816
|
0
|
|
|
|
|
|
$msg->{receiver} = $receiver; |
817
|
0
|
|
|
|
|
|
$msg->{discuss} = $discuss; |
818
|
|
|
|
|
|
|
} |
819
|
|
|
|
|
|
|
#$msg = Mojo::Webqq::Message::Recv::SessMessage->new($msg); |
820
|
0
|
|
|
|
|
|
$msg = Mojo::Webqq::Message->new($msg); |
821
|
|
|
|
|
|
|
} |
822
|
|
|
|
|
|
|
elsif($msg->{type} eq "discuss_message"){ |
823
|
0
|
|
|
|
|
|
my $sender; |
824
|
|
|
|
|
|
|
my $receiver; |
825
|
0
|
|
|
|
|
|
my $discuss; |
826
|
0
|
|
|
|
|
|
$discuss = $self->search_discuss(id=>$msg->{discuss_id}); |
827
|
0
|
0
|
|
|
|
|
if(defined $discuss){ |
828
|
0
|
|
|
|
|
|
$sender = $discuss->search_discuss_member(id=>$msg->{sender_id}); |
829
|
0
|
|
0
|
|
|
|
$receiver = $discuss->search_discuss_member(id=>$msg->{receiver_id}) || $self->user; |
830
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
831
|
0
|
|
|
|
|
|
$self->update_discuss($discuss); |
832
|
0
|
|
|
|
|
|
$sender = $discuss->search_discuss_member(id=>$msg->{sender_id}); |
833
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
834
|
0
|
|
|
|
|
|
$sender = Mojo::Webqq::Discuss::Member->new(_discuss_id=>$msg->{discuss_id},id=>$msg->{sender_id},name=>"昵称未知",_flag=>1); |
835
|
0
|
|
|
|
|
|
$discuss->add_discuss_member($sender,1); |
836
|
|
|
|
|
|
|
} |
837
|
|
|
|
|
|
|
} |
838
|
|
|
|
|
|
|
} |
839
|
|
|
|
|
|
|
else{ |
840
|
0
|
|
|
|
|
|
$self->update_discuss(); |
841
|
0
|
|
|
|
|
|
$discuss = $self->search_discuss(id=>$msg->{discuss_id}); |
842
|
0
|
0
|
|
|
|
|
return unless defined $discuss; |
843
|
0
|
|
|
|
|
|
$sender = $discuss->search_discuss_member(id=>$msg->{sender_id}); |
844
|
0
|
|
0
|
|
|
|
$receiver = $discuss->search_discuss_member(id=>$msg->{receiver_id}) || $self->user; |
845
|
0
|
0
|
|
|
|
|
unless(defined $sender){ |
846
|
0
|
|
|
|
|
|
$sender = Mojo::Webqq::Discuss::Member->new(_discuss_id=>$msg->{discuss_id},id=>$msg->{sender_id},name=>"昵称未知",_flag=>1); |
847
|
0
|
|
|
|
|
|
$discuss->add_discuss_member($sender,1); |
848
|
|
|
|
|
|
|
} |
849
|
|
|
|
|
|
|
} |
850
|
0
|
|
|
|
|
|
$msg->{sender} = $sender; |
851
|
0
|
|
|
|
|
|
$msg->{discuss} = $discuss; |
852
|
0
|
|
|
|
|
|
$msg->{receiver} = $receiver; |
853
|
|
|
|
|
|
|
#$msg = Mojo::Webqq::Message::Recv::DiscussMessage->new($msg); |
854
|
0
|
|
|
|
|
|
$msg = Mojo::Webqq::Message->new($msg); |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
elsif($msg->{type} eq "state_message"){ |
857
|
0
|
|
|
|
|
|
$msg = Mojo::Webqq::Message->new($msg); |
858
|
|
|
|
|
|
|
} |
859
|
|
|
|
|
|
|
elsif($msg->{type} eq "system_message"){ |
860
|
0
|
|
|
|
|
|
return; |
861
|
|
|
|
|
|
|
#$msg = Mojo::Webqq::Message::Recv::SystemMessage->new($msg); |
862
|
|
|
|
|
|
|
} |
863
|
|
|
|
|
|
|
else{ |
864
|
0
|
|
|
|
|
|
return; |
865
|
|
|
|
|
|
|
} |
866
|
0
|
0
|
|
|
|
|
if($self->ignore_unknown_id){ |
867
|
0
|
0
|
|
|
|
|
$self->message_queue->put($msg) if $msg->sender->_flag != 1; |
868
|
|
|
|
|
|
|
} |
869
|
|
|
|
|
|
|
else{ |
870
|
0
|
|
|
|
|
|
$self->message_queue->put($msg); |
871
|
|
|
|
|
|
|
} |
872
|
|
|
|
|
|
|
} |
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
sub format_msg{ |
875
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
876
|
0
|
|
|
|
|
|
my $msg_header = shift; |
877
|
0
|
|
|
|
|
|
my $msg_content = shift; |
878
|
0
|
|
|
|
|
|
my @msg_content = split /\n/,$msg_content; |
879
|
0
|
|
|
|
|
|
$msg_header = $self->decode("utf8",$msg_header); |
880
|
0
|
|
|
|
|
|
my $chinese_count=()=$msg_header=~/\p{Han}/g ; |
881
|
0
|
|
|
|
|
|
my $total_count = length($msg_header); |
882
|
0
|
|
|
|
|
|
$msg_header=$self->encode("utf8",$msg_header); |
883
|
|
|
|
|
|
|
|
884
|
0
|
|
|
|
|
|
my @msg_header = ($msg_header,(' ' x ($total_count-$chinese_count+$chinese_count*2)) x $#msg_content ); |
885
|
0
|
|
|
|
|
|
while(@msg_content){ |
886
|
0
|
|
|
|
|
|
my $lh = shift @msg_header; |
887
|
0
|
|
|
|
|
|
my $lc = shift @msg_content; |
888
|
|
|
|
|
|
|
#你的终端可能不是UTF8编码,为了防止乱码,做下编码自适应转换 |
889
|
0
|
|
|
|
|
|
$self->info($lh, $lc,"\n"); |
890
|
|
|
|
|
|
|
} |
891
|
|
|
|
|
|
|
} |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
1; |