wx2tg-puppet 2.0.8 → 2.1.0
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/core/Contact.js +3 -5
- package/dist/index.js +16 -2
- package/package.json +1 -1
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -48
package/dist/core/Contact.js
CHANGED
|
@@ -75,11 +75,9 @@ class Contact {
|
|
|
75
75
|
*/
|
|
76
76
|
sync() {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
config_service_1.configService.get()
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
});
|
|
78
|
+
const config = yield config_service_1.configService.get();
|
|
79
|
+
const contact = yield Contact.fetchAndUpsertContactDetail((config === null || config === void 0 ? void 0 : config.wxid) || '', this.id);
|
|
80
|
+
this.contact = contact;
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
83
|
/**
|
package/dist/index.js
CHANGED
|
@@ -196,6 +196,10 @@ class WxBot extends events_1.EventEmitter {
|
|
|
196
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
197
197
|
var _a;
|
|
198
198
|
try {
|
|
199
|
+
if (!this.uuid) {
|
|
200
|
+
yield this.fetchAndShowQRCode();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
199
203
|
const statusResp = yield LoginApi_1.loginApi.LoginCheckQR(this.uuid);
|
|
200
204
|
console.log('CheckQR response:', statusResp.data);
|
|
201
205
|
const statusData = statusResp.data;
|
|
@@ -302,9 +306,14 @@ class WxBot extends events_1.EventEmitter {
|
|
|
302
306
|
if (data.Code !== 0) {
|
|
303
307
|
// Code不为0,增加失败计数
|
|
304
308
|
this.syncFailureCount++;
|
|
305
|
-
if (this.syncFailureCount >=
|
|
306
|
-
// 连续失败
|
|
309
|
+
if (this.syncFailureCount >= 10) {
|
|
310
|
+
// 连续失败10次,退出登录
|
|
307
311
|
this.syncFailureCount = 0; // 重置计数器
|
|
312
|
+
// 先尝试二次登录
|
|
313
|
+
const loginTwice = yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
|
|
314
|
+
if (loginTwice.data.Message === '登录成功') {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
308
317
|
yield this.logOut();
|
|
309
318
|
yield this.login();
|
|
310
319
|
return;
|
|
@@ -313,6 +322,11 @@ class WxBot extends events_1.EventEmitter {
|
|
|
313
322
|
return;
|
|
314
323
|
}
|
|
315
324
|
if (data.Message === '用户可能退出') {
|
|
325
|
+
// 先尝试二次登录
|
|
326
|
+
const loginTwice = yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
|
|
327
|
+
if (loginTwice.data.Message === '登录成功') {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
316
330
|
// 用户可能退出,立即退出登录
|
|
317
331
|
yield this.logOut();
|
|
318
332
|
yield this.login();
|
package/package.json
CHANGED
package/dist/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test.js
DELETED
|
@@ -1,48 +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://127.0.0.1:8059/api',
|
|
16
|
-
databasePath: './database.sqlite',
|
|
17
|
-
deviceType: 'ipadX'
|
|
18
|
-
});
|
|
19
|
-
yield wxBot.start();
|
|
20
|
-
wxBot.on('message', (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
console.log('收到消息', message.text());
|
|
22
|
-
console.log('消息类型', message.type());
|
|
23
|
-
if (message.type() === 'image') {
|
|
24
|
-
const fileBox = yield message.toFileBox();
|
|
25
|
-
yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
|
|
26
|
-
}
|
|
27
|
-
else if (message.type() === 'video') {
|
|
28
|
-
const fileBox = yield message.toFileBox();
|
|
29
|
-
yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
|
|
30
|
-
}
|
|
31
|
-
else if (message.type() === 'voice') {
|
|
32
|
-
const fileBox = yield message.toFileBox();
|
|
33
|
-
yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
|
|
34
|
-
}
|
|
35
|
-
else if (message.type() === 'file') {
|
|
36
|
-
const fileBox = yield message.toFileBox();
|
|
37
|
-
yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
|
|
38
|
-
}
|
|
39
|
-
else if (message.type() === 'emoji') {
|
|
40
|
-
const fileBox = yield message.toFileBox();
|
|
41
|
-
yield (fileBox === null || fileBox === void 0 ? void 0 : fileBox.toFile(fileBox.name));
|
|
42
|
-
}
|
|
43
|
-
// const room = await message.room()
|
|
44
|
-
// if(room){
|
|
45
|
-
// await room.say('你好','@all')
|
|
46
|
-
// }
|
|
47
|
-
}));
|
|
48
|
-
}))();
|