Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/room anti spam #70

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@juzi/wechaty-puppet-service",
"version": "1.0.87",
"version": "1.0.88",
"description": "Puppet Service for Wechaty",
"type": "module",
"exports": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"@chatie/eslint-config": "^1.0.4",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^4.6.3",
"@juzi/wechaty-puppet": "^1.0.74",
"@juzi/wechaty-puppet": "^1.0.79",
"@juzi/wechaty-puppet-mock": "^1.0.1",
"@swc/core": "1.3.39",
"@types/google-protobuf": "^3.15.5",
Expand All @@ -65,13 +65,15 @@
"temp": "^0.9.4",
"typed-emitter": "^1.5.0-from-event",
"utility-types": "^3.10.0",
"why-is-node-running": "^2.2.1"
"why-is-node-running": "^2.2.1",
"ts-node": "10.9.1",
"typescript": "4.7.4"
},
"peerDependencies": {
"@juzi/wechaty-puppet": "^1.0.72"
},
"dependencies": {
"@juzi/wechaty-grpc": "^1.0.73",
"@juzi/wechaty-grpc": "^1.0.75",
"clone-class": "^1.1.1",
"ducks": "^1.0.2",
"file-box": "^1.5.5",
Expand Down
62 changes: 62 additions & 0 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,18 @@ class PuppetService extends PUPPET.Puppet {
)(request)
}

override async roomDismiss (roomId: string): Promise<void> {
log.verbose('PuppetService', 'roomDelAdmins(%s)', roomId)

const request = new grpcPuppet.RoomDismissRequest()
request.setId(roomId)

await util.promisify(
this.grpcManager.client.roomDismiss
.bind(this.grpcManager.client),
)(request)
}

/**
*
* Friendship
Expand Down Expand Up @@ -2734,6 +2746,56 @@ class PuppetService extends PUPPET.Puppet {
return result
}

override async getRoomAntiSpamStrategyList (): Promise<PUPPET.types.RoomAntiSpamStrategy[]> {
log.verbose('PuppetService', 'getRoomAntiSpamStrategyList()')

const request = new grpcPuppet.GetRoomAntiSpamStrategyListRequest()

const response = await util.promisify(
this.grpcManager.client.getRoomAntiSpamStrategyList.bind(this.grpcManager.client),
)(request)

const result: PUPPET.types.RoomAntiSpamStrategy[] = []
const strategies = response.getStrategiesList()

for (const strategy of strategies) {
result.push({
id: strategy.getId(),
name: strategy.getName(),
})
}

return result
}

override async getRoomAntiSpamStrategyEffectRoomList (strategyId: string): Promise<string[]> {
log.verbose('PuppetService', 'getRoomAntiSpamStrategyEffectRoomList(%s)', strategyId)

const request = new grpcPuppet.GetRoomAntiSpamStrategyEffectRoomListRequest()
request.setStrategyId(strategyId)

const response = await util.promisify(
this.grpcManager.client.getRoomAntiSpamStrategyEffectRoomList.bind(this.grpcManager.client),
)(request)

const result = response.getRoomIdsList()

return result
}

override async applyRoomAntiSpamStrategy (strategyId: string, roomIds: string[], active: boolean): Promise<void> {
log.verbose('PuppetService', 'applyRoomAntiSpamStrategy(%s, %s, %s)', strategyId, roomIds, active)

const request = new grpcPuppet.ApplyRoomAntiSpamStrategyRequest()
request.setStrategyId(strategyId)
request.setRoomIdsList(roomIds)
request.setActive(active)

await util.promisify(
this.grpcManager.client.applyRoomAntiSpamStrategy.bind(this.grpcManager.client),
)(request)
}

healthCheckInterval?: NodeJS.Timeout
startHealthCheck () {
this.healthCheckInterval = setInterval(() => {
Expand Down
78 changes: 77 additions & 1 deletion src/server/puppet-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,20 @@ function puppetImplementation (
}
},

roomDismiss: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'roomDismiss()')

try {
const roomId = call.request.getId()

await puppet.roomDismiss(roomId)

return callback(null, new grpcPuppet.RoomDismissResponse())
} catch (e) {
return grpcError('roomDelAdmins', e, callback)
}
},

start: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'start()')
void call
Expand Down Expand Up @@ -2300,7 +2314,69 @@ function puppetImplementation (
return callback(null, response)

} catch (e) {
return grpcError('momentVisibleList', e, callback)
return grpcError('getContactExternalUserId', e, callback)
}
},

getRoomAntiSpamStrategyList: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'getRoomAntiSpamStrategyList()')

try {
void call

const strategies = await puppet.getRoomAntiSpamStrategyList()

const response = new grpcPuppet.GetRoomAntiSpamStrategyListResponse()
const strategyPbList: grpcPuppet.RoomAntiSpamStrategy[] = []

for (const strategy of strategies) {
const strategyPb = new grpcPuppet.RoomAntiSpamStrategy()
strategyPb.setId(strategy.id)
strategyPb.setName(strategy.name)
strategyPbList.push(strategyPb)
}

response.setStrategiesList(strategyPbList)

return callback(null, response)
} catch (e) {
return grpcError('getRoomAntiSpamStrategyList', e, callback)
}
},

getRoomAntiSpamStrategyEffectRoomList: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'getRoomAntiSpamStrategyEffectRoomList()')

try {
const strategyId = call.request.getStrategyId()

const roomIds = await puppet.getRoomAntiSpamStrategyEffectRoomList(strategyId)

const response = new grpcPuppet.GetRoomAntiSpamStrategyEffectRoomListResponse()

response.setRoomIdsList(roomIds)

return callback(null, response)
} catch (e) {
return grpcError('getRoomAntiSpamStrategyEffectRoomList', e, callback)
}
},

applyRoomAntiSpamStrategy: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'applyRoomAntiSpamStrategy()')

try {
const strategyId = call.request.getStrategyId()
const roomIds = call.request.getRoomIdsList()
const active = call.request.getActive()

await puppet.applyRoomAntiSpamStrategy(strategyId, roomIds, active)

const response = new grpcPuppet.ApplyRoomAntiSpamStrategyResponse()

return callback(null, response)
} catch (e) {
return grpcError('applyRoomAntiSpamStrategy', e, callback)
}
},

Expand Down
Loading