wx2tg-puppet 3.0.7 → 3.0.8

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.
@@ -1,4 +1,4 @@
1
1
  import { ResponseMsg } from "../core/Message";
2
2
  export declare const say: (content: any, toWxid: string, ats: any) => Promise<ResponseMsg | null | undefined>;
3
3
  export declare const quote: (obj: any, toWxid: string) => Promise<ResponseMsg | null>;
4
- export declare const revoke: (content: any) => Promise<import("axios").AxiosResponse<import("../types/ApiResponse").ApiResponse, any, {}>>;
4
+ export declare const revoke: (content: any) => Promise<import("axios").AxiosResponse<import("../types/ApiResponse").ApiResponse, any>>;
@@ -67,7 +67,7 @@ export declare class Message {
67
67
  * Get the room from the message. Returns null if not in a room.
68
68
  */
69
69
  room(): Promise<Room | null>;
70
- static revoke(obj: any): Promise<Axios.AxiosResponse<import("../types/ApiResponse").ApiResponse, any, {}>>;
70
+ static revoke(obj: any): Promise<Axios.AxiosResponse<import("../types/ApiResponse").ApiResponse, any>>;
71
71
  static forwardTo(text: any, to: any, type: any): void;
72
72
  /**
73
73
  * Get the text content of the message.
package/dist/index.d.ts CHANGED
@@ -38,6 +38,8 @@ export declare class WxBot extends EventEmitter {
38
38
  private httpServer;
39
39
  private loggingOut;
40
40
  private loggingIn;
41
+ private syncInProgress;
42
+ private loginRecoveryInProgress;
41
43
  constructor({ baseUrl, databasePath, deviceType, mode, callbackPort, ProxyIp, ProxyPassword, ProxyUser }: WxBotOptions);
42
44
  qrcode(style?: number): Promise<{
43
45
  qrCode: any;
@@ -59,8 +61,10 @@ export declare class WxBot extends EventEmitter {
59
61
  private handleCallbackMessage;
60
62
  private startPollingMode;
61
63
  private checkLoginAfterDelay;
64
+ private recoverLogin;
62
65
  private checkSyncLoginStatus;
63
66
  private handleMsg;
67
+ private handleMsgOnce;
64
68
  private logOut;
65
69
  /**
66
70
  * 清空登录信息
package/dist/index.js CHANGED
@@ -86,6 +86,8 @@ class WxBot extends events_1.EventEmitter {
86
86
  this.httpServer = null; // HTTP回调服务器
87
87
  this.loggingOut = false; // Flag to prevent concurrent logOut calls
88
88
  this.loggingIn = false; // Flag to prevent concurrent login calls
89
+ this.syncInProgress = false; // Prevent overlapping message sync calls
90
+ this.loginRecoveryInProgress = false; // Allow only one login recovery flow
89
91
  this.baseUrl = baseUrl;
90
92
  this.databasePath = databasePath;
91
93
  this.deviceType = deviceType;
@@ -502,6 +504,27 @@ class WxBot extends events_1.EventEmitter {
502
504
  return true;
503
505
  });
504
506
  }
507
+ recoverLogin(userName) {
508
+ return __awaiter(this, void 0, void 0, function* () {
509
+ if (this.loginRecoveryInProgress) {
510
+ return false;
511
+ }
512
+ this.loginRecoveryInProgress = true;
513
+ try {
514
+ yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
515
+ if (yield this.checkLoginAfterDelay(userName)) {
516
+ this.syncFailureCount = 0;
517
+ return true;
518
+ }
519
+ yield this.logOut();
520
+ yield this.login();
521
+ return false;
522
+ }
523
+ finally {
524
+ this.loginRecoveryInProgress = false;
525
+ }
526
+ });
527
+ }
505
528
  checkSyncLoginStatus(data, userName) {
506
529
  return __awaiter(this, void 0, void 0, function* () {
507
530
  if (data.Code !== 0) {
@@ -511,30 +534,13 @@ class WxBot extends events_1.EventEmitter {
511
534
  if (this.syncFailureCount >= 10) {
512
535
  // 连续失败10次,退出登录
513
536
  this.syncFailureCount = 0; // 重置计数器
514
- // 先尝试二次登录
515
- yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
516
- // 等待60秒后再次检查
517
- if (yield this.checkLoginAfterDelay(userName)) {
518
- return true;
519
- }
520
- yield this.logOut();
521
- yield this.login();
522
- return false;
537
+ return yield this.recoverLogin(userName);
523
538
  }
524
539
  // 失败次数不足3次,继续等待下次sync
525
540
  return false;
526
541
  }
527
542
  if (data.Message === '用户可能退出') {
528
- // 先尝试二次登录
529
- yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
530
- // 等待60秒后再次检查
531
- if (yield this.checkLoginAfterDelay(userName)) {
532
- return true;
533
- }
534
- // 用户可能退出,立即退出登录
535
- yield this.logOut();
536
- yield this.login();
537
- return false;
543
+ return yield this.recoverLogin(userName);
538
544
  }
539
545
  // 成功情况,重置失败计数器
540
546
  this.syncFailureCount = 0;
@@ -542,6 +548,20 @@ class WxBot extends events_1.EventEmitter {
542
548
  });
543
549
  }
544
550
  handleMsg(userName) {
551
+ return __awaiter(this, void 0, void 0, function* () {
552
+ if (this.syncInProgress) {
553
+ return;
554
+ }
555
+ this.syncInProgress = true;
556
+ try {
557
+ yield this.handleMsgOnce(userName);
558
+ }
559
+ finally {
560
+ this.syncInProgress = false;
561
+ }
562
+ });
563
+ }
564
+ handleMsgOnce(userName) {
545
565
  return __awaiter(this, void 0, void 0, function* () {
546
566
  var _a;
547
567
  const resp = yield MsgApi_1.msgApi.Sync({
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "wx2tg-puppet",
3
- "version": "3.0.7",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "files": [
7
- "dist",
8
- "README.md"
9
- ],
10
- "scripts": {
11
- "build": "tsc",
12
- "start": "node dist/index.js",
13
- "dev": "ts-node src/index.ts",
14
- "test": "ts-node src/test.ts",
15
- "prepublishOnly": "npm run build"
16
- },
17
- "keywords": [
18
- "wechat",
19
- "bot",
20
- "puppet"
21
- ],
22
- "author": "",
23
- "license": "ISC",
24
- "description": "微信机器人核心库,可作为依赖被其他项目引入。",
25
- "devDependencies": {
26
- "@types/json-bigint": "^1.0.4",
27
- "@types/qrcode-terminal": "^0.12.2",
28
- "ts-node": "^10.9.2",
29
- "typescript": "^5.8.3"
30
- },
31
- "dependencies": {
32
- "axios": "^1.9.0",
33
- "fast-xml-parser": "^5.2.3",
34
- "file-box": "^1.4.15",
35
- "json-bigint": "^1.0.0",
36
- "qrcode-terminal": "^0.12.0",
37
- "reflect-metadata": "^0.2.2",
38
- "sqlite3": "^5.1.7",
39
- "typeorm": "^0.3.23",
40
- "wx-voice": "^0.2.1"
41
- }
42
- }
1
+ {
2
+ "name": "wx2tg-puppet",
3
+ "version": "3.0.8",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist",
8
+ "README.md"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "start": "node dist/index.js",
13
+ "dev": "ts-node src/index.ts",
14
+ "test": "ts-node src/test.ts",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "keywords": [
18
+ "wechat",
19
+ "bot",
20
+ "puppet"
21
+ ],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "description": "微信机器人核心库,可作为依赖被其他项目引入。",
25
+ "devDependencies": {
26
+ "@types/json-bigint": "^1.0.4",
27
+ "@types/qrcode-terminal": "^0.12.2",
28
+ "ts-node": "^10.9.2",
29
+ "typescript": "^5.8.3"
30
+ },
31
+ "dependencies": {
32
+ "axios": "^1.9.0",
33
+ "fast-xml-parser": "^5.2.3",
34
+ "file-box": "^1.4.15",
35
+ "json-bigint": "^1.0.0",
36
+ "qrcode-terminal": "^0.12.0",
37
+ "reflect-metadata": "^0.2.2",
38
+ "sqlite3": "^5.1.7",
39
+ "typeorm": "^0.3.23",
40
+ "wx-voice": "^0.2.1"
41
+ }
42
+ }