wx2tg-puppet 2.0.0 → 2.0.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.
@@ -4,4 +4,5 @@ export declare class Config {
4
4
  wxid: string;
5
5
  deviceId: string;
6
6
  DeviceName: string;
7
+ DeviceType: string;
7
8
  }
@@ -34,6 +34,10 @@ __decorate([
34
34
  (0, typeorm_1.Column)({ nullable: true }),
35
35
  __metadata("design:type", String)
36
36
  ], Config.prototype, "DeviceName", void 0);
37
+ __decorate([
38
+ (0, typeorm_1.Column)({ nullable: true }),
39
+ __metadata("design:type", String)
40
+ ], Config.prototype, "DeviceType", void 0);
37
41
  exports.Config = Config = __decorate([
38
42
  (0, typeorm_1.Entity)()
39
43
  ], Config);
package/dist/index.d.ts CHANGED
@@ -32,8 +32,12 @@ export declare class WxBot extends EventEmitter {
32
32
  private checkLoginStatus;
33
33
  info(): Promise<Contact | null>;
34
34
  private clearAllIntervals;
35
- loginSuccess(userName: string): Promise<void>;
35
+ private loginSuccess;
36
36
  private logOut;
37
+ /**
38
+ * 清空登录信息
39
+ */
40
+ clearCache(): Promise<void>;
37
41
  login(): Promise<void>;
38
42
  start(): Promise<void>;
39
43
  static get Contact(): typeof Contact;
package/dist/index.js CHANGED
@@ -41,6 +41,8 @@ const MessageType_1 = require("./type/MessageType");
41
41
  const Friendship_1 = require("./core/Friendship");
42
42
  const UserApi_1 = require("./api/UserApi");
43
43
  const ContactEntity_1 = require("./entities/ContactEntity");
44
+ const room_service_1 = require("./services/room.service");
45
+ const message_service_1 = require("./services/message.service");
44
46
  class WxBot extends events_1.EventEmitter {
45
47
  constructor({ baseUrl, databasePath, deviceType = 'ipad' }) {
46
48
  super();
@@ -70,6 +72,11 @@ class WxBot extends events_1.EventEmitter {
70
72
  return __awaiter(this, void 0, void 0, function* () {
71
73
  try {
72
74
  const config = yield config_service_1.configService.get();
75
+ if (config && config.DeviceType !== this.deviceType) {
76
+ yield this.clearCache();
77
+ config.deviceId = "";
78
+ config.DeviceName = "";
79
+ }
73
80
  let response;
74
81
  // 根据 deviceType 调用不同接口
75
82
  switch (this.deviceType) {
@@ -253,6 +260,7 @@ class WxBot extends events_1.EventEmitter {
253
260
  yield config_service_1.configService.save({
254
261
  deviceId: cacheInfo.data.Data.Deviceid_str,
255
262
  DeviceName: cacheInfo.data.Data.DeviceName,
263
+ DeviceType: this.deviceType,
256
264
  });
257
265
  }
258
266
  // 获取详情
@@ -325,7 +333,7 @@ class WxBot extends events_1.EventEmitter {
325
333
  if (!contactE) {
326
334
  contactE = new ContactEntity_1.ContactEntity();
327
335
  }
328
- contactE.nickName = message._pushContent.split(':')[0].slice(0, -1);
336
+ contactE.nickName = msg.PushContent.split(':')[0].slice(0, -1);
329
337
  contactE.userName = message.fromId;
330
338
  contactE.smallHeadImgUrl = 'https://raw.githubusercontent.com/finalpi/wechat2tg/wx2tg-pad/qywx.jpg';
331
339
  contactE.bigHeadImgUrl = 'https://raw.githubusercontent.com/finalpi/wechat2tg/wx2tg-pad/qywx.jpg';
@@ -365,6 +373,22 @@ class WxBot extends events_1.EventEmitter {
365
373
  this.emit('logout');
366
374
  });
367
375
  }
376
+ /**
377
+ * 清空登录信息
378
+ */
379
+ clearCache() {
380
+ return __awaiter(this, void 0, void 0, function* () {
381
+ this.logOut();
382
+ const config = yield config_service_1.configService.get();
383
+ if (config) {
384
+ const res = yield LoginApi_1.loginApi.LogOut(config.wxid);
385
+ }
386
+ config_service_1.configService.delete();
387
+ room_service_1.roomService.clear();
388
+ contact_service_1.contactService.clear();
389
+ message_service_1.messageService.clear();
390
+ });
391
+ }
368
392
  login() {
369
393
  return __awaiter(this, void 0, void 0, function* () {
370
394
  this.clearAllIntervals(); // 确保清理所有定时器
@@ -3,6 +3,7 @@ declare class ConfigService {
3
3
  private get repo();
4
4
  get(): Promise<Config | null>;
5
5
  save(config: Partial<Config>): Promise<Config>;
6
+ delete(): Promise<void>;
6
7
  }
7
8
  export declare const configService: ConfigService;
8
9
  export {};
@@ -34,5 +34,13 @@ class ConfigService {
34
34
  }
35
35
  });
36
36
  }
37
+ delete() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const config = yield this.get();
40
+ if (config) {
41
+ yield this.repo.delete(config);
42
+ }
43
+ });
44
+ }
37
45
  }
38
46
  exports.configService = new ConfigService();
@@ -6,6 +6,7 @@ declare class ContactService {
6
6
  save(contact: Partial<ContactEntity>): Promise<ContactEntity>;
7
7
  update(userName: string, update: Partial<ContactEntity>): Promise<ContactEntity | null>;
8
8
  clearRoom(): Promise<void>;
9
+ clear(): Promise<void>;
9
10
  upsertByUsername(userName: string, data: Partial<ContactEntity>): Promise<ContactEntity>;
10
11
  delete(userName: string): Promise<boolean>;
11
12
  searchByNickNameOrRemark(keyword: string): Promise<ContactEntity[]>;
@@ -49,6 +49,11 @@ class ContactService {
49
49
  });
50
50
  });
51
51
  }
52
+ clear() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ yield this.repo.clear();
55
+ });
56
+ }
52
57
  upsertByUsername(userName, data) {
53
58
  return __awaiter(this, void 0, void 0, function* () {
54
59
  let contact = yield this.getByUserName(userName);
@@ -7,6 +7,7 @@ declare class MessageService {
7
7
  update(MsgId: number, update: Partial<MessageEntity>): Promise<MessageEntity | null>;
8
8
  upsertByMsgId(MsgId: number, data: Partial<MessageEntity>): Promise<MessageEntity>;
9
9
  delete(MsgId: number): Promise<boolean>;
10
+ clear(): Promise<void>;
10
11
  }
11
12
  export declare const messageService: MessageService;
12
13
  export {};
@@ -59,5 +59,10 @@ class MessageService {
59
59
  return result.affected !== 0;
60
60
  });
61
61
  }
62
+ clear() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ yield this.repo.clear();
65
+ });
66
+ }
62
67
  }
63
68
  exports.messageService = new MessageService();
@@ -7,6 +7,7 @@ declare class RoomService {
7
7
  update(chatroomId: string, update: Partial<RoomEntity>): Promise<RoomEntity | null>;
8
8
  upsertByChatroomId(chatroomId: string, data: Partial<RoomEntity>): Promise<RoomEntity>;
9
9
  delete(chatroomId: string): Promise<boolean>;
10
+ clear(): Promise<void>;
10
11
  }
11
12
  export declare const roomService: RoomService;
12
13
  export {};
@@ -59,5 +59,10 @@ class RoomService {
59
59
  return result.affected !== 0;
60
60
  });
61
61
  }
62
+ clear() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ yield this.repo.clear();
65
+ });
66
+ }
62
67
  }
63
68
  exports.roomService = new RoomService();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx2tg-puppet",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [