wx2tg-puppet 2.2.1 → 2.2.2

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 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
  });
@@ -256,7 +252,6 @@ class WxBot extends events_1.EventEmitter {
256
252
  }
257
253
  }
258
254
  else if (statusData.Message.includes('数据不存在') || statusData.Message.includes('未知的错误')) {
259
- console.log('二维码已失效,正在获取新的二维码...');
260
255
  yield this.fetchAndShowQRCode();
261
256
  }
262
257
  else {
@@ -441,7 +436,7 @@ class WxBot extends events_1.EventEmitter {
441
436
  checkLoginAfterDelay(userName) {
442
437
  return __awaiter(this, void 0, void 0, function* () {
443
438
  // 等待20秒
444
- yield new Promise(resolve => setTimeout(resolve, 20000));
439
+ yield new Promise(resolve => setTimeout(resolve, 60000));
445
440
  // 再次检查登录状态
446
441
  const resp = yield MsgApi_1.msgApi.Sync({
447
442
  "Wxid": userName,
@@ -467,7 +462,7 @@ class WxBot extends events_1.EventEmitter {
467
462
  this.syncFailureCount = 0; // 重置计数器
468
463
  // 先尝试二次登录
469
464
  yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
470
- // 等待20秒后再次检查
465
+ // 等待60秒后再次检查
471
466
  if (yield this.checkLoginAfterDelay(userName)) {
472
467
  return true;
473
468
  }
@@ -481,7 +476,7 @@ class WxBot extends events_1.EventEmitter {
481
476
  if (data.Message === '用户可能退出') {
482
477
  // 先尝试二次登录
483
478
  yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
484
- // 等待20秒后再次检查
479
+ // 等待60秒后再次检查
485
480
  if (yield this.checkLoginAfterDelay(userName)) {
486
481
  return true;
487
482
  }
@@ -581,9 +576,18 @@ class WxBot extends events_1.EventEmitter {
581
576
  }
582
577
  logOut() {
583
578
  return __awaiter(this, void 0, void 0, function* () {
584
- this.clearAllIntervals(); // 确保清理所有定时器
585
- this.syncFailureCount = 0; // 重置失败计数器
586
- this.emit('logout');
579
+ if (this.loggingOut) {
580
+ return; // Already logging out, prevent concurrent execution
581
+ }
582
+ try {
583
+ this.loggingOut = true;
584
+ this.clearAllIntervals(); // 确保清理所有定时器
585
+ this.syncFailureCount = 0; // 重置失败计数器
586
+ this.emit('logout');
587
+ }
588
+ finally {
589
+ this.loggingOut = false;
590
+ }
587
591
  });
588
592
  }
589
593
  /**
@@ -604,11 +608,20 @@ class WxBot extends events_1.EventEmitter {
604
608
  }
605
609
  login() {
606
610
  return __awaiter(this, void 0, void 0, function* () {
607
- this.clearAllIntervals(); // 确保清理所有定时器
608
- yield this.fetchAndShowQRCode();
609
- this.interval = setInterval(() => {
610
- this.checkLoginStatus();
611
- }, 2000);
611
+ if (this.loggingIn) {
612
+ return; // Already logging in, prevent concurrent execution
613
+ }
614
+ try {
615
+ this.loggingIn = true;
616
+ this.clearAllIntervals(); // 确保清理所有定时器
617
+ yield this.fetchAndShowQRCode();
618
+ this.interval = setInterval(() => {
619
+ this.checkLoginStatus();
620
+ }, 2000);
621
+ }
622
+ finally {
623
+ this.loggingIn = false;
624
+ }
612
625
  });
613
626
  }
614
627
  start() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx2tg-puppet",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [