wx2tg-puppet 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -0
- package/dist/index.js +57 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,13 @@ export declare class WxBot extends EventEmitter {
|
|
|
47
47
|
private checkLoginStatus;
|
|
48
48
|
info(): Promise<Contact | null>;
|
|
49
49
|
private clearAllIntervals;
|
|
50
|
+
/**
|
|
51
|
+
* 递归获取所有联系人(支持分页)
|
|
52
|
+
* @param userName 微信ID
|
|
53
|
+
* @param currentWxSeq 当前微信联系人序列号
|
|
54
|
+
* @param currentChatroomSeq 当前群聊联系人序列号
|
|
55
|
+
*/
|
|
56
|
+
private fetchAllContacts;
|
|
50
57
|
private loginSuccess;
|
|
51
58
|
private startCallbackServer;
|
|
52
59
|
private handleCallbackMessage;
|
package/dist/index.js
CHANGED
|
@@ -300,23 +300,68 @@ class WxBot extends events_1.EventEmitter {
|
|
|
300
300
|
this.httpServer = null;
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* 递归获取所有联系人(支持分页)
|
|
305
|
+
* @param userName 微信ID
|
|
306
|
+
* @param currentWxSeq 当前微信联系人序列号
|
|
307
|
+
* @param currentChatroomSeq 当前群聊联系人序列号
|
|
308
|
+
*/
|
|
309
|
+
fetchAllContacts(userName_1) {
|
|
310
|
+
return __awaiter(this, arguments, void 0, function* (userName, currentWxSeq = 0, currentChatroomSeq = 0) {
|
|
311
|
+
try {
|
|
312
|
+
const res = yield FriendApi_1.friendApi.GetContractList({
|
|
313
|
+
"Wxid": userName,
|
|
314
|
+
"CurrentChatRoomContactSeq": currentChatroomSeq,
|
|
315
|
+
"CurrentWxcontactSeq": currentWxSeq,
|
|
316
|
+
});
|
|
317
|
+
if (res.data.Message === '用户可能退出') {
|
|
318
|
+
yield this.logOut();
|
|
319
|
+
yield this.login();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const data = res.data;
|
|
323
|
+
if (!data.Success) {
|
|
324
|
+
console.error('获取联系人列表失败:', data.Message);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
// 处理当前批次的联系人
|
|
328
|
+
if (data.Data && data.Data.ContactUsernameList) {
|
|
329
|
+
console.log(`获取到 ${data.Data.ContactUsernameList.length} 个联系人`);
|
|
330
|
+
data.Data.ContactUsernameList.forEach((contact) => {
|
|
331
|
+
if (!contact.endsWith('@chatroom')) {
|
|
332
|
+
Contact_1.Contact.fetchAndUpsertContactDetail(userName, contact);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
Room_1.Room.find({ id: contact });
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
// 检查是否还有更多联系人需要获取
|
|
340
|
+
// CountinueFlag 为 1 表示还有更多数据
|
|
341
|
+
if (data.Data && data.Data.CountinueFlag === 1) {
|
|
342
|
+
const nextWxSeq = data.Data.CurrentWxcontactSeq || 0;
|
|
343
|
+
const nextChatroomSeq = data.Data.CurrentChatRoomContactSeq || 0;
|
|
344
|
+
console.log(`还有更多联系人,继续获取... (WxSeq: ${nextWxSeq}, ChatroomSeq: ${nextChatroomSeq})`);
|
|
345
|
+
// 递归获取下一批联系人
|
|
346
|
+
yield this.fetchAllContacts(userName, nextWxSeq, nextChatroomSeq);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
console.log('联系人列表获取完成');
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
console.error('获取联系人列表时发生错误:', error);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
303
357
|
loginSuccess(userName) {
|
|
304
358
|
return __awaiter(this, void 0, void 0, function* () {
|
|
305
359
|
contact_service_1.contactService.clearRoom();
|
|
306
360
|
this.clearAllIntervals(); // 确保清理所有定时器
|
|
307
361
|
this.syncFailureCount = 0; // 重置失败计数器
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
"CurrentChatRoomContactSeq": 0,
|
|
312
|
-
"CurrentWxcontactSeq": 0,
|
|
313
|
-
});
|
|
314
|
-
if (res.data.Message === '用户可能退出') {
|
|
315
|
-
yield this.logOut();
|
|
316
|
-
yield this.login();
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
console.log('好友列表获取成功,开始更新联系人信息');
|
|
362
|
+
// 分页获取所有联系人
|
|
363
|
+
yield this.fetchAllContacts(userName, 0, 0);
|
|
364
|
+
console.log('所有联系人获取完成');
|
|
320
365
|
// 设置设备信息
|
|
321
366
|
const cacheInfo = yield LoginApi_1.loginApi.GetCacheInfo(userName);
|
|
322
367
|
if (cacheInfo.data.Message === '成功') {
|
|
@@ -326,16 +371,6 @@ class WxBot extends events_1.EventEmitter {
|
|
|
326
371
|
DeviceType: this.deviceType,
|
|
327
372
|
});
|
|
328
373
|
}
|
|
329
|
-
// 获取详情
|
|
330
|
-
const data = res.data;
|
|
331
|
-
data.Data.ContactUsernameList.forEach((contact) => {
|
|
332
|
-
if (!contact.endsWith('@chatroom')) {
|
|
333
|
-
Contact_1.Contact.fetchAndUpsertContactDetail(userName, contact);
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
Room_1.Room.find({ id: contact });
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
374
|
// 设置心跳包
|
|
340
375
|
this.setupHeartbeat(userName);
|
|
341
376
|
// 根据模式选择消息监听方式
|