wx2tg-puppet 2.2.1 → 2.2.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 +2 -0
- package/dist/index.js +37 -19
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare class WxBot extends EventEmitter {
|
|
|
36
36
|
private recentMsgIds;
|
|
37
37
|
private syncFailureCount;
|
|
38
38
|
private httpServer;
|
|
39
|
+
private loggingOut;
|
|
40
|
+
private loggingIn;
|
|
39
41
|
constructor({ baseUrl, databasePath, deviceType, mode, callbackPort, ProxyIp, ProxyPassword, ProxyUser }: WxBotOptions);
|
|
40
42
|
qrcode(style?: number): Promise<{
|
|
41
43
|
qrCode: any;
|
package/dist/index.js
CHANGED
|
@@ -41,9 +41,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
41
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
45
|
exports.UrlLink = exports.WeVideo = exports.Voice = exports.Emoji = exports.Message = exports.Room = exports.Contact = exports.WxBot = exports.AppDataSource = void 0;
|
|
49
46
|
require("reflect-metadata");
|
|
@@ -52,7 +49,6 @@ const data_source_1 = require("./database/data-source");
|
|
|
52
49
|
const LoginApi_1 = require("./api/LoginApi");
|
|
53
50
|
const MsgApi_1 = require("./api/MsgApi");
|
|
54
51
|
const FriendApi_1 = require("./api/FriendApi");
|
|
55
|
-
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
56
52
|
const config_service_1 = require("./services/config.service");
|
|
57
53
|
const events_1 = require("events");
|
|
58
54
|
const Message_1 = require("./core/Message");
|
|
@@ -88,6 +84,8 @@ class WxBot extends events_1.EventEmitter {
|
|
|
88
84
|
this.recentMsgIds = []; // Store recent message IDs
|
|
89
85
|
this.syncFailureCount = 0; // Sync failure counter
|
|
90
86
|
this.httpServer = null; // HTTP回调服务器
|
|
87
|
+
this.loggingOut = false; // Flag to prevent concurrent logOut calls
|
|
88
|
+
this.loggingIn = false; // Flag to prevent concurrent login calls
|
|
91
89
|
this.baseUrl = baseUrl;
|
|
92
90
|
this.databasePath = databasePath;
|
|
93
91
|
this.deviceType = deviceType;
|
|
@@ -197,8 +195,6 @@ class WxBot extends events_1.EventEmitter {
|
|
|
197
195
|
const match = data.Data.QrUrl.match(/[?&]data=([^&]+)/);
|
|
198
196
|
if (match && match[1]) {
|
|
199
197
|
const qrLink = decodeURIComponent(match[1]);
|
|
200
|
-
console.log('二维码内容链接:', qrLink);
|
|
201
|
-
qrcode_terminal_1.default.generate(qrLink, { small: true });
|
|
202
198
|
this.emit('scan', {
|
|
203
199
|
content: qrLink
|
|
204
200
|
});
|
|
@@ -242,7 +238,6 @@ class WxBot extends events_1.EventEmitter {
|
|
|
242
238
|
return;
|
|
243
239
|
}
|
|
244
240
|
const statusResp = yield LoginApi_1.loginApi.LoginCheckQR(this.uuid);
|
|
245
|
-
console.log('CheckQR response:', statusResp.data);
|
|
246
241
|
const statusData = statusResp.data;
|
|
247
242
|
if (statusData.Success) {
|
|
248
243
|
if (statusData.Message === '登录成功') {
|
|
@@ -256,9 +251,14 @@ class WxBot extends events_1.EventEmitter {
|
|
|
256
251
|
}
|
|
257
252
|
}
|
|
258
253
|
else if (statusData.Message.includes('数据不存在') || statusData.Message.includes('未知的错误')) {
|
|
259
|
-
console.log('二维码已失效,正在获取新的二维码...');
|
|
260
254
|
yield this.fetchAndShowQRCode();
|
|
261
255
|
}
|
|
256
|
+
else if (statusData.Message.includes('请提交验证码后登录')) {
|
|
257
|
+
yield this.login();
|
|
258
|
+
this.emit('loginFail', {
|
|
259
|
+
msg: statusData.Message
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
262
|
else {
|
|
263
263
|
console.log('登录失败:', (_a = statusData.Data.baseResponse) === null || _a === void 0 ? void 0 : _a.errMsg);
|
|
264
264
|
}
|
|
@@ -441,7 +441,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
441
441
|
checkLoginAfterDelay(userName) {
|
|
442
442
|
return __awaiter(this, void 0, void 0, function* () {
|
|
443
443
|
// 等待20秒
|
|
444
|
-
yield new Promise(resolve => setTimeout(resolve,
|
|
444
|
+
yield new Promise(resolve => setTimeout(resolve, 60000));
|
|
445
445
|
// 再次检查登录状态
|
|
446
446
|
const resp = yield MsgApi_1.msgApi.Sync({
|
|
447
447
|
"Wxid": userName,
|
|
@@ -467,7 +467,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
467
467
|
this.syncFailureCount = 0; // 重置计数器
|
|
468
468
|
// 先尝试二次登录
|
|
469
469
|
yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
|
|
470
|
-
// 等待
|
|
470
|
+
// 等待60秒后再次检查
|
|
471
471
|
if (yield this.checkLoginAfterDelay(userName)) {
|
|
472
472
|
return true;
|
|
473
473
|
}
|
|
@@ -481,7 +481,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
481
481
|
if (data.Message === '用户可能退出') {
|
|
482
482
|
// 先尝试二次登录
|
|
483
483
|
yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
|
|
484
|
-
// 等待
|
|
484
|
+
// 等待60秒后再次检查
|
|
485
485
|
if (yield this.checkLoginAfterDelay(userName)) {
|
|
486
486
|
return true;
|
|
487
487
|
}
|
|
@@ -581,9 +581,18 @@ class WxBot extends events_1.EventEmitter {
|
|
|
581
581
|
}
|
|
582
582
|
logOut() {
|
|
583
583
|
return __awaiter(this, void 0, void 0, function* () {
|
|
584
|
-
this.
|
|
585
|
-
|
|
586
|
-
|
|
584
|
+
if (this.loggingOut) {
|
|
585
|
+
return; // Already logging out, prevent concurrent execution
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
this.loggingOut = true;
|
|
589
|
+
this.clearAllIntervals(); // 确保清理所有定时器
|
|
590
|
+
this.syncFailureCount = 0; // 重置失败计数器
|
|
591
|
+
this.emit('logout');
|
|
592
|
+
}
|
|
593
|
+
finally {
|
|
594
|
+
this.loggingOut = false;
|
|
595
|
+
}
|
|
587
596
|
});
|
|
588
597
|
}
|
|
589
598
|
/**
|
|
@@ -604,11 +613,20 @@ class WxBot extends events_1.EventEmitter {
|
|
|
604
613
|
}
|
|
605
614
|
login() {
|
|
606
615
|
return __awaiter(this, void 0, void 0, function* () {
|
|
607
|
-
this.
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
616
|
+
if (this.loggingIn) {
|
|
617
|
+
return; // Already logging in, prevent concurrent execution
|
|
618
|
+
}
|
|
619
|
+
try {
|
|
620
|
+
this.loggingIn = true;
|
|
621
|
+
this.clearAllIntervals(); // 确保清理所有定时器
|
|
622
|
+
yield this.fetchAndShowQRCode();
|
|
623
|
+
this.interval = setInterval(() => {
|
|
624
|
+
this.checkLoginStatus();
|
|
625
|
+
}, 2000);
|
|
626
|
+
}
|
|
627
|
+
finally {
|
|
628
|
+
this.loggingIn = false;
|
|
629
|
+
}
|
|
612
630
|
});
|
|
613
631
|
}
|
|
614
632
|
start() {
|