wx2tg-puppet 2.1.2 → 2.1.4

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.
@@ -220,9 +220,9 @@ const say = (content, toWxid, ats) => __awaiter(void 0, void 0, void 0, function
220
220
  // }
221
221
  else if (content instanceof EMOJI_1.Emoji) {
222
222
  const res = yield MsgApi_1.msgApi.SendEmoji({
223
- "Md5": content.emojiMd5,
224
- "TotalLen": content.emojiSize,
225
- "Base64": content.emojiBase64,
223
+ "Md5": content.emojiMd5 || null,
224
+ "TotalLen": content.emojiSize || null,
225
+ "Base64": content.emojiBase64 || null,
226
226
  "ToWxid": toWxid,
227
227
  "Wxid": (config === null || config === void 0 ? void 0 : config.wxid) || ''
228
228
  });
package/dist/index.d.ts CHANGED
@@ -43,6 +43,8 @@ export declare class WxBot extends EventEmitter {
43
43
  private startCallbackServer;
44
44
  private handleCallbackMessage;
45
45
  private startPollingMode;
46
+ private checkLoginAfterDelay;
47
+ private checkSyncLoginStatus;
46
48
  private handleMsg;
47
49
  private logOut;
48
50
  /**
package/dist/index.js CHANGED
@@ -344,37 +344,9 @@ class WxBot extends events_1.EventEmitter {
344
344
  "Scene": 0,
345
345
  "Synckey": ""
346
346
  });
347
- if (resp.data.Code !== 0) {
348
- // Code不为0,增加失败计数
349
- this.syncFailureCount++;
350
- if (this.syncFailureCount >= 10) {
351
- // 连续失败10次,退出登录
352
- this.syncFailureCount = 0; // 重置计数器
353
- // 先尝试二次登录
354
- const loginTwice = yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
355
- if (loginTwice.data.Message === '登录成功') {
356
- return;
357
- }
358
- yield this.logOut();
359
- yield this.login();
360
- return;
361
- }
362
- // 失败次数不足3次,继续等待下次sync
363
- return;
364
- }
365
- if (resp.data.Message === '用户可能退出') {
366
- // 先尝试二次登录
367
- const loginTwice = yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
368
- if (loginTwice.data.Message === '登录成功') {
369
- return;
370
- }
371
- // 用户可能退出,立即退出登录
372
- yield this.logOut();
373
- yield this.login();
347
+ if (!(yield this.checkSyncLoginStatus(resp.data, userName))) {
374
348
  return;
375
349
  }
376
- // 成功情况,重置失败计数器
377
- this.syncFailureCount = 0;
378
350
  if (resp.data.Success) {
379
351
  if (resp.data.Message === '当前未有新消息') {
380
352
  break;
@@ -463,15 +435,27 @@ class WxBot extends events_1.EventEmitter {
463
435
  }), 1000);
464
436
  this.emit('login', userName);
465
437
  }
466
- handleMsg(userName) {
438
+ checkLoginAfterDelay(userName) {
467
439
  return __awaiter(this, void 0, void 0, function* () {
468
- var _a;
440
+ // 等待20秒
441
+ yield new Promise(resolve => setTimeout(resolve, 20000));
442
+ // 再次检查登录状态
469
443
  const resp = yield MsgApi_1.msgApi.Sync({
470
444
  "Wxid": userName,
471
445
  "Scene": 0,
472
446
  "Synckey": ""
473
447
  });
474
- const data = resp.data;
448
+ if (resp.data.Code !== 0) {
449
+ return false;
450
+ }
451
+ if (resp.data.Message === '用户可能退出') {
452
+ return false;
453
+ }
454
+ return true;
455
+ });
456
+ }
457
+ checkSyncLoginStatus(data, userName) {
458
+ return __awaiter(this, void 0, void 0, function* () {
475
459
  if (data.Code !== 0) {
476
460
  // Code不为0,增加失败计数
477
461
  this.syncFailureCount++;
@@ -479,30 +463,47 @@ class WxBot extends events_1.EventEmitter {
479
463
  // 连续失败10次,退出登录
480
464
  this.syncFailureCount = 0; // 重置计数器
481
465
  // 先尝试二次登录
482
- const loginTwice = yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
483
- if (loginTwice.data.Message === '登录成功') {
484
- return;
466
+ yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
467
+ // 等待20秒后再次检查
468
+ if (yield this.checkLoginAfterDelay(userName)) {
469
+ return true;
485
470
  }
486
471
  yield this.logOut();
487
472
  yield this.login();
488
- return;
473
+ return false;
489
474
  }
490
475
  // 失败次数不足3次,继续等待下次sync
491
- return;
476
+ return false;
492
477
  }
493
478
  if (data.Message === '用户可能退出') {
494
479
  // 先尝试二次登录
495
- const loginTwice = yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
496
- if (loginTwice.data.Message === '登录成功') {
497
- return;
480
+ yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
481
+ // 等待20秒后再次检查
482
+ if (yield this.checkLoginAfterDelay(userName)) {
483
+ return true;
498
484
  }
499
485
  // 用户可能退出,立即退出登录
500
486
  yield this.logOut();
501
487
  yield this.login();
502
- return;
488
+ return false;
503
489
  }
504
490
  // 成功情况,重置失败计数器
505
491
  this.syncFailureCount = 0;
492
+ return true;
493
+ });
494
+ }
495
+ handleMsg(userName) {
496
+ return __awaiter(this, void 0, void 0, function* () {
497
+ var _a;
498
+ const resp = yield MsgApi_1.msgApi.Sync({
499
+ "Wxid": userName,
500
+ "Scene": 0,
501
+ "Synckey": ""
502
+ });
503
+ const data = resp.data;
504
+ if (!(yield this.checkSyncLoginStatus(data, userName))) {
505
+ return;
506
+ }
506
507
  if (data.Success) {
507
508
  if (data.Message === '当前未有新消息') {
508
509
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx2tg-puppet",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/dist/test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/test.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const _1 = require(".");
13
- (() => __awaiter(void 0, void 0, void 0, function* () {
14
- const wxBot = new _1.WxBot({
15
- baseUrl: 'http://192.168.56.101:8088/api',
16
- databasePath: './database.sqlite',
17
- deviceType: 'ipad',
18
- mode: 'polling',
19
- callbackPort: 8056
20
- });
21
- yield wxBot.start();
22
- wxBot.on('message', (message) => __awaiter(void 0, void 0, void 0, function* () {
23
- console.log(yield message.mentionSelf());
24
- console.log('收到消息', message.text());
25
- console.log('消息类型', message.type());
26
- if (message.type() === 'image') {
27
- const fileBox = yield message.toFileBox();
28
- yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
29
- }
30
- else if (message.type() === 'video') {
31
- const fileBox = yield message.toFileBox();
32
- yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
33
- }
34
- else if (message.type() === 'voice') {
35
- const fileBox = yield message.toFileBox();
36
- yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
37
- }
38
- else if (message.type() === 'file') {
39
- const fileBox = yield message.toFileBox();
40
- yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
41
- }
42
- else if (message.type() === 'emoji') {
43
- const fileBox = yield message.toFileBox();
44
- yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
45
- }
46
- // const room = await message.room()
47
- // if(room){
48
- // await room.say('你好','@all')
49
- // }
50
- }));
51
- }))();
@@ -1,29 +0,0 @@
1
- export declare const MessageType: {
2
- Unknown: string;
3
- FileStart: string;
4
- File: string;
5
- Voice: string;
6
- Contact: string;
7
- Emoji: string;
8
- Image: string;
9
- Text: string;
10
- Video: string;
11
- Url: string;
12
- RoomInvitation: string;
13
- MiniApp: string;
14
- AppMsg: string;
15
- Link: string;
16
- AddFriend: string;
17
- Quote: string;
18
- Transfer: string;
19
- RedPacket: string;
20
- VideoAccount: string;
21
- Revoke: string;
22
- Pat: string;
23
- Location: string;
24
- FunctionMsg: string;
25
- NewMonmentTimeline: string;
26
- ChatHistroy: string;
27
- Voip: string;
28
- RealTimeLocation: string;
29
- };
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageType = void 0;
4
- exports.MessageType = {
5
- Unknown: 'unknown', // 未知类型
6
- FileStart: 'file_start', // 文件开始
7
- File: 'file', // 文件发送结束
8
- Voice: 'voice', // 语音
9
- Contact: 'contact', // 名片
10
- Emoji: 'emoji', // 表情
11
- Image: 'image', // 图片
12
- Text: 'text', // 文本
13
- Video: 'video', // 视频
14
- Url: 'link', // 链接
15
- RoomInvitation: 'room_invitation', // 群邀请
16
- MiniApp: 'mini_app', // 小程序消息
17
- AppMsg: 'app_msg', // app消息
18
- Link: 'link', // 公众号链接
19
- AddFriend: 'add_friend', // 添加好友通知
20
- Quote: 'quote', // 引用消息
21
- Transfer: 'transfer', //转账
22
- RedPacket: 'red_packet', //红包
23
- VideoAccount: 'video_account', // 视频号消息
24
- Revoke: 'revoke', // 撤回消息
25
- Pat: 'pat', // 拍一拍
26
- Location: 'location', // 位置消息
27
- FunctionMsg: 'function_msg', // 微信团队消息
28
- NewMonmentTimeline: 'new_monment_timeline', // 朋友圈更新
29
- ChatHistroy: 'chat_histroy', // 聊天记录
30
- Voip: 'voip', // voip消息
31
- RealTimeLocation: 'real_time_location', // 实时位置共享
32
- };