wx2tg-puppet 1.1.3 → 1.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.
package/dist/core/Contact.js
CHANGED
|
@@ -112,17 +112,14 @@ class Contact {
|
|
|
112
112
|
* Get the name from a contact
|
|
113
113
|
*/
|
|
114
114
|
name() {
|
|
115
|
-
|
|
116
|
-
// TODO: Implement name retrieval
|
|
117
|
-
return ((_a = this.contact) === null || _a === void 0 ? void 0 : _a.nickName) || '';
|
|
115
|
+
return this._nickName;
|
|
118
116
|
}
|
|
119
117
|
/**
|
|
120
118
|
* Get the alias for a contact
|
|
121
119
|
*/
|
|
122
120
|
alias() {
|
|
123
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
|
|
125
|
-
return ((_a = this.contact) === null || _a === void 0 ? void 0 : _a.remark) || '';
|
|
122
|
+
return this._alias || '';
|
|
126
123
|
});
|
|
127
124
|
}
|
|
128
125
|
/**
|
|
@@ -187,7 +184,7 @@ class Contact {
|
|
|
187
184
|
}
|
|
188
185
|
const contact = {
|
|
189
186
|
userName: (_e = (_d = detailDataSave.UserName) === null || _d === void 0 ? void 0 : _d.string) !== null && _e !== void 0 ? _e : '',
|
|
190
|
-
nickName: (_g = (_f = detailDataSave.NickName) === null || _f === void 0 ? void 0 : _f.string) !== null && _g !== void 0 ? _g : '',
|
|
187
|
+
nickName: (_g = (_f = detailDataSave.NickName) === null || _f === void 0 ? void 0 : _f.string) !== null && _g !== void 0 ? _g : 'no name',
|
|
191
188
|
pyInitial: (_j = (_h = detailDataSave.Pyinitial) === null || _h === void 0 ? void 0 : _h.string) !== null && _j !== void 0 ? _j : '',
|
|
192
189
|
quanPin: (_l = (_k = detailDataSave.QuanPin) === null || _k === void 0 ? void 0 : _k.string) !== null && _l !== void 0 ? _l : '',
|
|
193
190
|
sex: (_m = detailDataSave.Sex) !== null && _m !== void 0 ? _m : null,
|
package/dist/core/Message.js
CHANGED
|
@@ -60,6 +60,8 @@ const path_1 = __importDefault(require("path"));
|
|
|
60
60
|
const common_2 = require("../action/common");
|
|
61
61
|
const fs = __importStar(require("fs"));
|
|
62
62
|
const FileChunkHelper_1 = require("../utils/FileChunkHelper");
|
|
63
|
+
const GroupApi_1 = require("../api/GroupApi");
|
|
64
|
+
const contact_service_1 = require("../services/contact.service");
|
|
63
65
|
const MAX_RETRIES = 3;
|
|
64
66
|
const RETRY_DELAY = 1000; // 1 second
|
|
65
67
|
// @ts-ignore - Ignore type errors for the entire function since we're dealing with a mix of old and new axios types
|
|
@@ -129,6 +131,41 @@ class Message {
|
|
|
129
131
|
*/
|
|
130
132
|
from() {
|
|
131
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
135
|
+
if (this.msg.RoomId) {
|
|
136
|
+
const contact = yield contact_service_1.contactService.getByUserName(this.msg.FromUserName);
|
|
137
|
+
if (contact) {
|
|
138
|
+
return new Contact_1.Contact(contact);
|
|
139
|
+
}
|
|
140
|
+
const config = yield config_service_1.configService.get();
|
|
141
|
+
const groupMember = yield GroupApi_1.groupApi.GetChatRoomMemberDetail({
|
|
142
|
+
"QID": this.msg.RoomId,
|
|
143
|
+
"Wxid": config === null || config === void 0 ? void 0 : config.wxid
|
|
144
|
+
});
|
|
145
|
+
const member = groupMember.data.Data.NewChatroomData.ChatRoomMember.find((i) => i.UserName === this.msg.FromUserName);
|
|
146
|
+
return new Contact_1.Contact({
|
|
147
|
+
userName: (_a = member.UserName) !== null && _a !== void 0 ? _a : '',
|
|
148
|
+
nickName: (_b = member.NickName) !== null && _b !== void 0 ? _b : '',
|
|
149
|
+
pyInitial: (_c = member.Pyinitial) !== null && _c !== void 0 ? _c : '',
|
|
150
|
+
quanPin: (_d = member.QuanPin) !== null && _d !== void 0 ? _d : '',
|
|
151
|
+
sex: (_e = member.Sex) !== null && _e !== void 0 ? _e : null,
|
|
152
|
+
remark: (_f = member.Remark) !== null && _f !== void 0 ? _f : '',
|
|
153
|
+
remarkPyInitial: (_g = member.RemarkPyinitial) !== null && _g !== void 0 ? _g : '',
|
|
154
|
+
remarkQuanPin: (_h = member.RemarkQuanPin) !== null && _h !== void 0 ? _h : '',
|
|
155
|
+
signature: (_j = member.Signature) !== null && _j !== void 0 ? _j : '',
|
|
156
|
+
alias: (_k = member.Alias) !== null && _k !== void 0 ? _k : '',
|
|
157
|
+
snsBgImg: (_m = (_l = member.SnsUserInfo) === null || _l === void 0 ? void 0 : _l.SnsBgimgId) !== null && _m !== void 0 ? _m : '',
|
|
158
|
+
country: (_o = member.Country) !== null && _o !== void 0 ? _o : '',
|
|
159
|
+
bigHeadImgUrl: (_p = member.BigHeadImgUrl) !== null && _p !== void 0 ? _p : '',
|
|
160
|
+
smallHeadImgUrl: (_q = member.SmallHeadImgUrl) !== null && _q !== void 0 ? _q : '',
|
|
161
|
+
description: '', // 详情数据中没有明确字段
|
|
162
|
+
cardImgUrl: '', // 详情数据中没有明确字段
|
|
163
|
+
labelList: '', // 详情数据中没有明确字段
|
|
164
|
+
province: (_r = member.Province) !== null && _r !== void 0 ? _r : '',
|
|
165
|
+
city: (_s = member.City) !== null && _s !== void 0 ? _s : '',
|
|
166
|
+
phoneNumList: '', // 详情数据中没有明确字段
|
|
167
|
+
});
|
|
168
|
+
}
|
|
132
169
|
return Contact_1.Contact.find({
|
|
133
170
|
id: this.msg.FromUserName
|
|
134
171
|
});
|
package/dist/core/Room.js
CHANGED
|
@@ -23,7 +23,7 @@ class Room {
|
|
|
23
23
|
this.id = room.chatroomId;
|
|
24
24
|
this.room = room;
|
|
25
25
|
this.chatroomId = room.chatroomId;
|
|
26
|
-
this.name = room.nickName;
|
|
26
|
+
this.name = room.nickName || '未命名群聊';
|
|
27
27
|
this.remark = room.remark;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
@@ -68,7 +68,7 @@ class Room {
|
|
|
68
68
|
return null;
|
|
69
69
|
const roomEntity = {
|
|
70
70
|
chatroomId: ((_a = respData.UserName) === null || _a === void 0 ? void 0 : _a.string) || '',
|
|
71
|
-
nickName: ((_b = respData.NickName) === null || _b === void 0 ? void 0 : _b.string) || '',
|
|
71
|
+
nickName: ((_b = respData.NickName) === null || _b === void 0 ? void 0 : _b.string) || '未命名群聊',
|
|
72
72
|
pyInitial: ((_c = respData.Pyinitial) === null || _c === void 0 ? void 0 : _c.string) || '',
|
|
73
73
|
quanPin: ((_d = respData.QuanPin) === null || _d === void 0 ? void 0 : _d.string) || '',
|
|
74
74
|
sex: (_e = respData.Sex) !== null && _e !== void 0 ? _e : 0,
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ const config_service_1 = require("./services/config.service");
|
|
|
24
24
|
const events_1 = require("events");
|
|
25
25
|
const Message_1 = require("./core/Message");
|
|
26
26
|
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return Message_1.Message; } });
|
|
27
|
+
const contact_service_1 = require("./services/contact.service");
|
|
27
28
|
const Contact_1 = require("./core/Contact");
|
|
28
29
|
Object.defineProperty(exports, "Contact", { enumerable: true, get: function () { return Contact_1.Contact; } });
|
|
29
30
|
const Room_1 = require("./core/Room");
|
|
@@ -39,6 +40,7 @@ Object.defineProperty(exports, "UrlLink", { enumerable: true, get: function () {
|
|
|
39
40
|
const MessageType_1 = require("./type/MessageType");
|
|
40
41
|
const Friendship_1 = require("./core/Friendship");
|
|
41
42
|
const UserApi_1 = require("./api/UserApi");
|
|
43
|
+
const ContactEntity_1 = require("./entities/ContactEntity");
|
|
42
44
|
class WxBot extends events_1.EventEmitter {
|
|
43
45
|
constructor({ baseUrl, databasePath }) {
|
|
44
46
|
super();
|
|
@@ -171,6 +173,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
171
173
|
}
|
|
172
174
|
loginSuccess(userName) {
|
|
173
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
contact_service_1.contactService.clearRoom();
|
|
174
177
|
this.clearAllIntervals(); // 确保清理所有定时器
|
|
175
178
|
// 保存联系人信息
|
|
176
179
|
const res = yield FriendApi_1.friendApi.GetContractList({
|
|
@@ -195,7 +198,12 @@ class WxBot extends events_1.EventEmitter {
|
|
|
195
198
|
// 获取详情
|
|
196
199
|
const data = res.data;
|
|
197
200
|
data.Data.ContactUsernameList.forEach((contact) => {
|
|
198
|
-
|
|
201
|
+
if (!contact.endsWith('@chatroom')) {
|
|
202
|
+
Contact_1.Contact.fetchAndUpsertContactDetail(userName, contact);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
Room_1.Room.find({ id: contact });
|
|
206
|
+
}
|
|
199
207
|
});
|
|
200
208
|
// 设置心跳包
|
|
201
209
|
this.setupHeartbeat(userName);
|
|
@@ -206,6 +214,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
206
214
|
}
|
|
207
215
|
// 监听消息,每秒掉一次
|
|
208
216
|
this.msgInterval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
var _a;
|
|
209
218
|
const resp = yield MsgApi_1.msgApi.Sync({
|
|
210
219
|
"wxid": userName,
|
|
211
220
|
"Scene": 0,
|
|
@@ -250,6 +259,18 @@ class WxBot extends events_1.EventEmitter {
|
|
|
250
259
|
IsSelf: msg.FromUserName.string === userName,
|
|
251
260
|
xml: msg.Content.string
|
|
252
261
|
});
|
|
262
|
+
// 处理企业微信
|
|
263
|
+
if ((_a = message.fromId) === null || _a === void 0 ? void 0 : _a.includes('@openim')) {
|
|
264
|
+
let contactE = yield contact_service_1.contactService.getByUserName(message.fromId);
|
|
265
|
+
if (!contactE) {
|
|
266
|
+
contactE = new ContactEntity_1.ContactEntity();
|
|
267
|
+
}
|
|
268
|
+
contactE.nickName = message._pushContent.split(':')[0].slice(0, -1);
|
|
269
|
+
contactE.userName = message.fromId;
|
|
270
|
+
contactE.smallHeadImgUrl = 'https://raw.githubusercontent.com/finalpi/wechat2tg/wx2tg-pad/qywx.jpg';
|
|
271
|
+
contactE.bigHeadImgUrl = 'https://raw.githubusercontent.com/finalpi/wechat2tg/wx2tg-pad/qywx.jpg';
|
|
272
|
+
contact_service_1.contactService.upsertByUsername(contactE.userName, contactE);
|
|
273
|
+
}
|
|
253
274
|
if (message.type() === MessageType_1.MessageType.AddFriend) { // 好友请求
|
|
254
275
|
const obj = Message_1.Message.getXmlToJson(message.text());
|
|
255
276
|
console.log(obj);
|
|
@@ -5,6 +5,7 @@ declare class ContactService {
|
|
|
5
5
|
getAll(): Promise<ContactEntity[]>;
|
|
6
6
|
save(contact: Partial<ContactEntity>): Promise<ContactEntity>;
|
|
7
7
|
update(userName: string, update: Partial<ContactEntity>): Promise<ContactEntity | null>;
|
|
8
|
+
clearRoom(): Promise<void>;
|
|
8
9
|
upsertByUsername(userName: string, data: Partial<ContactEntity>): Promise<ContactEntity>;
|
|
9
10
|
delete(userName: string): Promise<boolean>;
|
|
10
11
|
searchByNickNameOrRemark(keyword: string): Promise<ContactEntity[]>;
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.contactService = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
13
14
|
const data_source_1 = require("../database/data-source");
|
|
14
15
|
const ContactEntity_1 = require("../entities/ContactEntity");
|
|
15
16
|
class ContactService {
|
|
@@ -41,6 +42,13 @@ class ContactService {
|
|
|
41
42
|
return this.repo.save(entity);
|
|
42
43
|
});
|
|
43
44
|
}
|
|
45
|
+
clearRoom() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield this.repo.delete({
|
|
48
|
+
userName: (0, typeorm_1.Like)('%@chatroom')
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
44
52
|
upsertByUsername(userName, data) {
|
|
45
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
54
|
let contact = yield this.getByUserName(userName);
|