@juzi/wechaty 1.0.86 → 1.0.89
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/io.d.ts.map +1 -1
- package/dist/cjs/src/io.js +4 -1
- package/dist/cjs/src/io.js.map +1 -1
- package/dist/cjs/src/package-json.js +4 -4
- package/dist/cjs/src/schemas/wechaty-events.d.ts +1 -1
- package/dist/cjs/src/schemas/wechaty-events.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/room.d.ts +1 -0
- package/dist/cjs/src/user-modules/room.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/room.js +35 -0
- package/dist/cjs/src/user-modules/room.js.map +1 -1
- package/dist/cjs/src/user-modules/wecom.d.ts +4 -0
- package/dist/cjs/src/user-modules/wecom.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/wecom.js +16 -0
- package/dist/cjs/src/user-modules/wecom.js.map +1 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js +2 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/dist/esm/src/io.d.ts.map +1 -1
- package/dist/esm/src/io.js +4 -1
- package/dist/esm/src/io.js.map +1 -1
- package/dist/esm/src/package-json.js +4 -4
- package/dist/esm/src/schemas/wechaty-events.d.ts +1 -1
- package/dist/esm/src/schemas/wechaty-events.d.ts.map +1 -1
- package/dist/esm/src/user-modules/room.d.ts +1 -0
- package/dist/esm/src/user-modules/room.d.ts.map +1 -1
- package/dist/esm/src/user-modules/room.js +35 -0
- package/dist/esm/src/user-modules/room.js.map +1 -1
- package/dist/esm/src/user-modules/wecom.d.ts +4 -0
- package/dist/esm/src/user-modules/wecom.d.ts.map +1 -1
- package/dist/esm/src/user-modules/wecom.js +16 -0
- package/dist/esm/src/user-modules/wecom.js.map +1 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js +2 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/package.json +3 -3
- package/src/io.ts +4 -1
- package/src/package-json.ts +4 -4
- package/src/schemas/wechaty-events.ts +1 -1
- package/src/user-modules/room.ts +40 -0
- package/src/user-modules/wecom.ts +29 -0
- package/src/wechaty-mixins/puppet-mixin.ts +2 -1
package/src/user-modules/room.ts
CHANGED
|
@@ -255,6 +255,46 @@ class RoomMixin extends MixinBase implements SayableSayer {
|
|
|
255
255
|
return undefined
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
static async batchLoadRooms (roomIdList: string[]) {
|
|
259
|
+
let continuousErrorCount = 0
|
|
260
|
+
let totalErrorCount = 0
|
|
261
|
+
const totalErrorThreshold = Math.round(roomIdList.length / 5)
|
|
262
|
+
|
|
263
|
+
const idToRoom = async (id: string) => {
|
|
264
|
+
if (!this.wechaty.isLoggedIn) {
|
|
265
|
+
throw new Error('wechaty not logged in')
|
|
266
|
+
}
|
|
267
|
+
const result = await this.wechaty.Room.find({ id }).catch(e => {
|
|
268
|
+
this.wechaty.emitError(e)
|
|
269
|
+
continuousErrorCount++
|
|
270
|
+
totalErrorCount++
|
|
271
|
+
if (continuousErrorCount > 5) {
|
|
272
|
+
throw new Error('5 continuous errors!')
|
|
273
|
+
}
|
|
274
|
+
if (totalErrorCount > totalErrorThreshold) {
|
|
275
|
+
throw new Error(`${totalErrorThreshold} total errors!`)
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
continuousErrorCount = 0
|
|
279
|
+
return result
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* we need to use concurrencyExecuter to reduce the parallel number of the requests
|
|
284
|
+
*/
|
|
285
|
+
const CONCURRENCY = 17
|
|
286
|
+
const roomIterator = concurrencyExecuter(CONCURRENCY)(idToRoom)(roomIdList)
|
|
287
|
+
|
|
288
|
+
const roomList: RoomInterface[] = []
|
|
289
|
+
|
|
290
|
+
for await (const room of roomIterator) {
|
|
291
|
+
if (room) {
|
|
292
|
+
roomList.push(room)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return roomList
|
|
296
|
+
}
|
|
297
|
+
|
|
258
298
|
/** const roomList: RoomInterface[] = []
|
|
259
299
|
|
|
260
300
|
* @ignore
|
|
@@ -5,6 +5,7 @@ import { validationMixin } from '../user-mixins/validation.js'
|
|
|
5
5
|
import {
|
|
6
6
|
wechatifyMixinBase,
|
|
7
7
|
} from '../user-mixins/wechatify.js'
|
|
8
|
+
import type { RoomAntiSpamStrategy } from '@juzi/wechaty-puppet/types'
|
|
8
9
|
|
|
9
10
|
class WecomMixin extends wechatifyMixinBase() {
|
|
10
11
|
|
|
@@ -18,6 +19,34 @@ class WecomMixin extends wechatifyMixinBase() {
|
|
|
18
19
|
)
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
static async getRoomAntiSpamStrategyList (): Promise<RoomAntiSpamStrategy[]> {
|
|
23
|
+
return this.wechaty.puppet.getRoomAntiSpamStrategyList()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static async getRoomAntiSpamStrategyEffectRoomList (
|
|
27
|
+
strategyId: string,
|
|
28
|
+
): Promise<string[]> {
|
|
29
|
+
return this.wechaty.puppet.getRoomAntiSpamStrategyEffectRoomList(strategyId)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static async applyRoomAntiSpamStrategy (
|
|
33
|
+
strategyId: string,
|
|
34
|
+
roomIds: string[],
|
|
35
|
+
active: boolean,
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
const rawRoomIdSet = new Set(roomIds)
|
|
38
|
+
const rooms = (await this.wechaty.Room.batchLoadRooms(Array.from(rawRoomIdSet))).filter(room => room.owner()?.self())
|
|
39
|
+
|
|
40
|
+
const actualRoomIdSet = new Set(rooms.map(room => room.id))
|
|
41
|
+
const filteredRoomIds = Array.from(rawRoomIdSet).filter(id => !actualRoomIdSet.has(id))
|
|
42
|
+
|
|
43
|
+
if (filteredRoomIds.length) {
|
|
44
|
+
log.warn(`these rooms cannot be applied with anti-spam strategy: ${filteredRoomIds}`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return this.wechaty.puppet.applyRoomAntiSpamStrategy(strategyId, Array.from(actualRoomIdSet), active)
|
|
48
|
+
}
|
|
49
|
+
|
|
21
50
|
/*
|
|
22
51
|
* @hideconstructor
|
|
23
52
|
*/
|
|
@@ -542,7 +542,8 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
542
542
|
case 'scan':
|
|
543
543
|
puppet.on('scan', async payload => {
|
|
544
544
|
this.__readyState.inactive(true)
|
|
545
|
-
|
|
545
|
+
const date = timestampToDate(payload.timestamp || 0)
|
|
546
|
+
this.emit('scan', payload.qrcode || '', payload.status, payload.data || '', payload.type || ScanType.Unknown, date)
|
|
546
547
|
})
|
|
547
548
|
break
|
|
548
549
|
|