@juzi/wechaty 1.0.58 → 1.0.59
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/cjs/src/package-json.js +2 -2
- package/dist/cjs/src/user-modules/contact.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/contact.js +31 -34
- package/dist/cjs/src/user-modules/contact.js.map +1 -1
- package/dist/cjs/src/user-modules/message.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/message.js +42 -4
- package/dist/cjs/src/user-modules/message.js.map +1 -1
- package/dist/cjs/src/user-modules/room.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/room.js +31 -34
- package/dist/cjs/src/user-modules/room.js.map +1 -1
- package/dist/cjs/src/user-modules/room.spec.js +25 -0
- package/dist/cjs/src/user-modules/room.spec.js.map +1 -1
- package/dist/cjs/src/user-modules/tag-group.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/tag-group.js +21 -1
- package/dist/cjs/src/user-modules/tag-group.js.map +1 -1
- package/dist/cjs/src/user-modules/tag.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/tag.js +28 -15
- package/dist/cjs/src/user-modules/tag.js.map +1 -1
- package/dist/esm/src/package-json.js +2 -2
- package/dist/esm/src/user-modules/contact.d.ts.map +1 -1
- package/dist/esm/src/user-modules/contact.js +31 -34
- package/dist/esm/src/user-modules/contact.js.map +1 -1
- package/dist/esm/src/user-modules/message.d.ts.map +1 -1
- package/dist/esm/src/user-modules/message.js +42 -4
- package/dist/esm/src/user-modules/message.js.map +1 -1
- package/dist/esm/src/user-modules/room.d.ts.map +1 -1
- package/dist/esm/src/user-modules/room.js +31 -34
- package/dist/esm/src/user-modules/room.js.map +1 -1
- package/dist/esm/src/user-modules/room.spec.js +25 -0
- package/dist/esm/src/user-modules/room.spec.js.map +1 -1
- package/dist/esm/src/user-modules/tag-group.d.ts.map +1 -1
- package/dist/esm/src/user-modules/tag-group.js +21 -1
- package/dist/esm/src/user-modules/tag-group.js.map +1 -1
- package/dist/esm/src/user-modules/tag.d.ts.map +1 -1
- package/dist/esm/src/user-modules/tag.js +28 -15
- package/dist/esm/src/user-modules/tag.js.map +1 -1
- package/package.json +1 -1
- package/src/package-json.ts +2 -2
- package/src/user-modules/contact.ts +34 -36
- package/src/user-modules/message.ts +43 -6
- package/src/user-modules/room.spec.ts +33 -0
- package/src/user-modules/room.ts +33 -36
- package/src/user-modules/tag-group.ts +21 -1
- package/src/user-modules/tag.ts +31 -18
package/src/user-modules/room.ts
CHANGED
|
@@ -147,48 +147,45 @@ class RoomMixin extends MixinBase implements SayableSayer {
|
|
|
147
147
|
): Promise<RoomInterface[]> {
|
|
148
148
|
log.verbose('Room', 'findAll(%s)', JSON.stringify(query, stringifyFilter) || '')
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
continuousErrorCount++
|
|
159
|
-
totalErrorCount++
|
|
160
|
-
if (continuousErrorCount > 5) {
|
|
161
|
-
throw new Error('5 continuous errors!')
|
|
162
|
-
}
|
|
163
|
-
if (totalErrorCount > 100) {
|
|
164
|
-
throw new Error('100 total errors!')
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
continuousErrorCount = 0
|
|
168
|
-
return result
|
|
150
|
+
const roomIdList = await this.wechaty.puppet.roomSearch(query)
|
|
151
|
+
|
|
152
|
+
let continuousErrorCount = 0
|
|
153
|
+
let totalErrorCount = 0
|
|
154
|
+
const totalErrorThreshold = Math.round(roomIdList.length / 5)
|
|
155
|
+
const idToRoom = async (id: string) => {
|
|
156
|
+
if (!this.wechaty.isLoggedIn) {
|
|
157
|
+
throw new Error('wechaty not logged in')
|
|
169
158
|
}
|
|
159
|
+
const result = await this.wechaty.Room.find({ id }).catch(e => {
|
|
160
|
+
this.wechaty.emitError(e)
|
|
161
|
+
continuousErrorCount++
|
|
162
|
+
totalErrorCount++
|
|
163
|
+
if (continuousErrorCount > 5) {
|
|
164
|
+
throw new Error('5 continuous errors!')
|
|
165
|
+
}
|
|
166
|
+
if (totalErrorCount > totalErrorThreshold) {
|
|
167
|
+
throw new Error(`${totalErrorThreshold} total errors!`)
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
continuousErrorCount = 0
|
|
171
|
+
return result
|
|
172
|
+
}
|
|
170
173
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
/**
|
|
175
|
+
* we need to use concurrencyExecuter to reduce the parallel number of the requests
|
|
176
|
+
*/
|
|
177
|
+
const CONCURRENCY = 17
|
|
178
|
+
const roomIterator = concurrencyExecuter(CONCURRENCY)(idToRoom)(roomIdList)
|
|
176
179
|
|
|
177
|
-
|
|
180
|
+
const roomList: RoomInterface[] = []
|
|
178
181
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
182
|
+
for await (const room of roomIterator) {
|
|
183
|
+
if (room) {
|
|
184
|
+
roomList.push(room)
|
|
183
185
|
}
|
|
184
|
-
|
|
185
|
-
return roomList
|
|
186
|
-
|
|
187
|
-
} catch (e) {
|
|
188
|
-
this.wechaty.emitError(e)
|
|
189
|
-
log.verbose('Room', 'findAll() rejected: %s', (e as Error).message)
|
|
190
|
-
return [] as RoomInterface[] // fail safe
|
|
191
186
|
}
|
|
187
|
+
|
|
188
|
+
return roomList
|
|
192
189
|
}
|
|
193
190
|
|
|
194
191
|
/**
|
|
@@ -67,7 +67,27 @@ class TagGroupMixin extends MixinBase {
|
|
|
67
67
|
try {
|
|
68
68
|
const tagGroupIds = await this.wechaty.puppet.tagGroupList()
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
let continuousErrorCount = 0
|
|
71
|
+
let totalErrorCount = 0
|
|
72
|
+
const totalErrorThreshold = Math.round(tagGroupIds.length / 5)
|
|
73
|
+
const idToTagGroup = async (id: string) => {
|
|
74
|
+
if (!this.wechaty.isLoggedIn) {
|
|
75
|
+
throw new Error('wechaty not logged in')
|
|
76
|
+
}
|
|
77
|
+
const result = this.find({ id }).catch(e => {
|
|
78
|
+
this.wechaty.emitError(e)
|
|
79
|
+
continuousErrorCount++
|
|
80
|
+
totalErrorCount++
|
|
81
|
+
if (continuousErrorCount > 5) {
|
|
82
|
+
throw new Error('5 continuous errors!')
|
|
83
|
+
}
|
|
84
|
+
if (totalErrorCount > totalErrorThreshold) {
|
|
85
|
+
throw new Error(`${totalErrorThreshold} total errors!`)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
continuousErrorCount = 0
|
|
89
|
+
return result
|
|
90
|
+
}
|
|
71
91
|
|
|
72
92
|
const CONCURRENCY = 17
|
|
73
93
|
const tagGroupIterator = concurrencyExecuter(CONCURRENCY)(idToTagGroup)(tagGroupIds)
|
package/src/user-modules/tag.ts
CHANGED
|
@@ -77,28 +77,41 @@ class TagMixin extends MixinBase {
|
|
|
77
77
|
static async list (): Promise<TagInterface[]> {
|
|
78
78
|
log.verbose('Tag', 'list()')
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const tagList: TagInterface[] = []
|
|
89
|
-
for await (const tag of tagIterator) {
|
|
90
|
-
if (tag) {
|
|
91
|
-
tagList.push(tag)
|
|
92
|
-
}
|
|
80
|
+
const tagIdList = await this.wechaty.puppet.tagTagList()
|
|
81
|
+
|
|
82
|
+
let continuousErrorCount = 0
|
|
83
|
+
let totalErrorCount = 0
|
|
84
|
+
const totalErrorThreshold = Math.round(tagIdList.length / 5)
|
|
85
|
+
const idToTag = async (id: string) => {
|
|
86
|
+
if (!this.wechaty.isLoggedIn) {
|
|
87
|
+
throw new Error('wechaty not logged in')
|
|
93
88
|
}
|
|
89
|
+
const result = this.find({ id }).catch(e => {
|
|
90
|
+
this.wechaty.emitError(e)
|
|
91
|
+
continuousErrorCount++
|
|
92
|
+
totalErrorCount++
|
|
93
|
+
if (continuousErrorCount > 5) {
|
|
94
|
+
throw new Error('5 continuous errors!')
|
|
95
|
+
}
|
|
96
|
+
if (totalErrorCount > totalErrorThreshold) {
|
|
97
|
+
throw new Error(`${totalErrorThreshold} total errors!`)
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
continuousErrorCount = 0
|
|
101
|
+
return result
|
|
102
|
+
}
|
|
94
103
|
|
|
95
|
-
|
|
104
|
+
const CONCURRENCY = 17
|
|
105
|
+
const tagIterator = concurrencyExecuter(CONCURRENCY)(idToTag)(tagIdList)
|
|
96
106
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
const tagList: TagInterface[] = []
|
|
108
|
+
for await (const tag of tagIterator) {
|
|
109
|
+
if (tag) {
|
|
110
|
+
tagList.push(tag)
|
|
111
|
+
}
|
|
101
112
|
}
|
|
113
|
+
|
|
114
|
+
return tagList
|
|
102
115
|
}
|
|
103
116
|
|
|
104
117
|
static async find (filter: TagQueryFilter): Promise<TagInterface | undefined> {
|