@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.
Files changed (44) hide show
  1. package/dist/cjs/src/package-json.js +2 -2
  2. package/dist/cjs/src/user-modules/contact.d.ts.map +1 -1
  3. package/dist/cjs/src/user-modules/contact.js +31 -34
  4. package/dist/cjs/src/user-modules/contact.js.map +1 -1
  5. package/dist/cjs/src/user-modules/message.d.ts.map +1 -1
  6. package/dist/cjs/src/user-modules/message.js +42 -4
  7. package/dist/cjs/src/user-modules/message.js.map +1 -1
  8. package/dist/cjs/src/user-modules/room.d.ts.map +1 -1
  9. package/dist/cjs/src/user-modules/room.js +31 -34
  10. package/dist/cjs/src/user-modules/room.js.map +1 -1
  11. package/dist/cjs/src/user-modules/room.spec.js +25 -0
  12. package/dist/cjs/src/user-modules/room.spec.js.map +1 -1
  13. package/dist/cjs/src/user-modules/tag-group.d.ts.map +1 -1
  14. package/dist/cjs/src/user-modules/tag-group.js +21 -1
  15. package/dist/cjs/src/user-modules/tag-group.js.map +1 -1
  16. package/dist/cjs/src/user-modules/tag.d.ts.map +1 -1
  17. package/dist/cjs/src/user-modules/tag.js +28 -15
  18. package/dist/cjs/src/user-modules/tag.js.map +1 -1
  19. package/dist/esm/src/package-json.js +2 -2
  20. package/dist/esm/src/user-modules/contact.d.ts.map +1 -1
  21. package/dist/esm/src/user-modules/contact.js +31 -34
  22. package/dist/esm/src/user-modules/contact.js.map +1 -1
  23. package/dist/esm/src/user-modules/message.d.ts.map +1 -1
  24. package/dist/esm/src/user-modules/message.js +42 -4
  25. package/dist/esm/src/user-modules/message.js.map +1 -1
  26. package/dist/esm/src/user-modules/room.d.ts.map +1 -1
  27. package/dist/esm/src/user-modules/room.js +31 -34
  28. package/dist/esm/src/user-modules/room.js.map +1 -1
  29. package/dist/esm/src/user-modules/room.spec.js +25 -0
  30. package/dist/esm/src/user-modules/room.spec.js.map +1 -1
  31. package/dist/esm/src/user-modules/tag-group.d.ts.map +1 -1
  32. package/dist/esm/src/user-modules/tag-group.js +21 -1
  33. package/dist/esm/src/user-modules/tag-group.js.map +1 -1
  34. package/dist/esm/src/user-modules/tag.d.ts.map +1 -1
  35. package/dist/esm/src/user-modules/tag.js +28 -15
  36. package/dist/esm/src/user-modules/tag.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/package-json.ts +2 -2
  39. package/src/user-modules/contact.ts +34 -36
  40. package/src/user-modules/message.ts +43 -6
  41. package/src/user-modules/room.spec.ts +33 -0
  42. package/src/user-modules/room.ts +33 -36
  43. package/src/user-modules/tag-group.ts +21 -1
  44. package/src/user-modules/tag.ts +31 -18
@@ -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
- try {
151
- const roomIdList = await this.wechaty.puppet.roomSearch(query)
152
-
153
- let continuousErrorCount = 0
154
- let totalErrorCount = 0
155
- const idToRoom = async (id: string) => {
156
- const result = await this.wechaty.Room.find({ id }).catch(e => {
157
- this.wechaty.emitError(e)
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
- * we need to use concurrencyExecuter to reduce the parallel number of the requests
173
- */
174
- const CONCURRENCY = 17
175
- const roomIterator = concurrencyExecuter(CONCURRENCY)(idToRoom)(roomIdList)
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
- const roomList: RoomInterface[] = []
180
+ const roomList: RoomInterface[] = []
178
181
 
179
- for await (const room of roomIterator) {
180
- if (room) {
181
- roomList.push(room)
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
- const idToTagGroup = async (id: string) => this.find({ id }).catch(e => this.wechaty.emitError(e))
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)
@@ -77,28 +77,41 @@ class TagMixin extends MixinBase {
77
77
  static async list (): Promise<TagInterface[]> {
78
78
  log.verbose('Tag', 'list()')
79
79
 
80
- try {
81
- const tagIdList = await this.wechaty.puppet.tagTagList()
82
-
83
- const idToTag = async (id: string) => this.find({ id }).catch(e => this.wechaty.emitError(e))
84
-
85
- const CONCURRENCY = 17
86
- const tagIterator = concurrencyExecuter(CONCURRENCY)(idToTag)(tagIdList)
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
- return tagList
104
+ const CONCURRENCY = 17
105
+ const tagIterator = concurrencyExecuter(CONCURRENCY)(idToTag)(tagIdList)
96
106
 
97
- } catch (e) {
98
- this.wechaty.emitError(e)
99
- log.error('Tag', 'list() exception: %s', (e as Error).message)
100
- return []
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> {