Skip to content

Commit e77c5fa

Browse files
authored
Merge branch 'master' into master
2 parents 5c48ff3 + 2594e01 commit e77c5fa

File tree

7 files changed

+161
-108
lines changed

7 files changed

+161
-108
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# https://help.github.com/articles/about-codeowners/
3+
#
4+
5+
* @wechaty/java

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
![Java Wechaty](https://wechaty.github.io/java-wechaty/images/java-wechaty.png)
77

8+
[![Java Wechaty Getting Started](https://img.shields.io/badge/Java%20Wechaty-Getting%20Started-orange)](https://github.com/wechaty/java-wechaty-getting-started)
9+
810
## Connecting Chatbots
911

1012
[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://github.com/Wechaty/wechaty)
@@ -279,20 +281,18 @@ We decided to use Kotlin to develop the Java Wechaty!
279281
- [Python Wechaty](https://github.com/wechaty/python-wechaty) - Python WeChat Bot SDK for Individual Account.
280282
- [Go Wechaty](https://github.com/wechaty/go-wechaty) - Go WeChat Bot SDK for Individual Account.
281283

282-
## Authors
283-
284-
- [@diaozxin007](https://github.com/diaozxin007) diaozxin@gmail.com
285-
- Website: [犀利豆的博客](https://xilidou.com/)
286-
- [@huan](https://github.com/huan) ([李卓桓](http://linkedin.com/in/zixia)), Tencent TVP of Chatbot, zixia@zixia.net
287-
288-
## Maintainers
284+
## Contributors
289285

290286
- [@redmaple1](https://github.com/redmaple1) Xiaoya Ren
291287

292-
See [MAINTAINERS](MAINTAINERS)
288+
## Committers
289+
290+
- [@diaozxin007](https://github.com/diaozxin007) diaozxin@gmail.com
291+
- Website: [犀利豆的博客](https://xilidou.com/)
292+
- [@huan](https://github.com/huan) - Huan LI ([李卓桓](http://linkedin.com/in/zixia)), Tencent TVP of Chatbot, zixia@zixia.net
293293

294294
## Copyright & License
295295

296-
- Code & Docs © 2020 Wechaty
296+
- Code & Docs © 2020 Wechaty Contributors <https://github.com/wechaty>
297297
- Code released under the Apache-2.0 License
298298
- Docs released under Creative Commons

wechaty-puppet/src/main/kotlin/Puppet.kt

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ val PUPPET_COUNT = AtomicLong()
3333
* puppet
3434
* @author zhengxin
3535
*/
36-
abstract class Puppet: EventEmitter{
36+
abstract class Puppet : EventEmitter {
3737

3838
@Volatile
3939
protected var state = StateEnum.OFF
@@ -54,7 +54,7 @@ abstract class Puppet: EventEmitter{
5454
private var id: String? = null
5555
protected var puppetOptions: PuppetOptions? = null
5656

57-
private val watchDog:WatchDog
57+
private val watchDog: WatchDog
5858

5959
/**
6060
*
@@ -65,10 +65,10 @@ abstract class Puppet: EventEmitter{
6565
count.addAndGet(1)
6666
this.puppetOptions = puppetOptions
6767

68-
val timeOut = puppetOptions.timeout ?:DEFAULT_WATCHDOG_TIMEOUT
69-
watchDog = WatchDog(1000 * timeOut,"puppet")
68+
val timeOut = puppetOptions.timeout ?: DEFAULT_WATCHDOG_TIMEOUT
69+
watchDog = WatchDog(1000 * timeOut, "puppet")
7070

71-
on("heartbeat",object :PuppetHeartbeatListener{
71+
on("heartbeat", object : PuppetHeartbeatListener {
7272
override fun handler(payload: EventHeartbeatPayload) {
7373
log.debug("heartbeat -> ${payload.data}")
7474
val watchdogFood = WatchdogFood(1000 * timeOut)
@@ -79,20 +79,22 @@ abstract class Puppet: EventEmitter{
7979

8080

8181

82-
this.watchDog.on("reset",object : WatchdogListener{
82+
this.watchDog.on("reset", object : WatchdogListener {
8383
override fun handler(event: WatchdogFood) {
8484
val payload = EventResetPayload(JsonUtils.write(event))
85-
emit("reset",payload)
85+
emit("reset", payload)
8686
}
8787
})
8888

8989
// 一秒只有一次
9090
val rateLimiter = RateLimiter.create(1.0)
9191

92-
on("reset",object :PuppetResetListener{
92+
on("reset", object : PuppetResetListener {
9393
override fun handler(payload: EventResetPayload) {
94-
log.debug("get a reset message")
95-
if(rateLimiter.tryAcquire()){
94+
95+
log.debug("get a reset message")
96+
if(rateLimiter.tryAcquire()){
97+
9698
reset(payload.data)
9799
}
98100
}
@@ -117,15 +119,15 @@ abstract class Puppet: EventEmitter{
117119
cacheMessagePayload = Caffeine.newBuilder().build()
118120
}
119121

120-
private fun initHeart(){
122+
private fun initHeart() {
121123

122124
executorService.scheduleAtFixedRate({
123-
if(state == StateEnum.ON) {
125+
if (state == StateEnum.ON) {
124126
val incrementAndGet = HEARTBEAT_COUNTER.incrementAndGet()
125127
log.debug("HEARTBEAT_COUNTER #{}", incrementAndGet)
126128
ding("`recover CPR #${incrementAndGet}")
127129
}
128-
},HOSTIE_KEEPALIVE_TIMEOUT,HOSTIE_KEEPALIVE_TIMEOUT,TimeUnit.MILLISECONDS)
130+
}, HOSTIE_KEEPALIVE_TIMEOUT, HOSTIE_KEEPALIVE_TIMEOUT, TimeUnit.MILLISECONDS)
129131

130132
// heartbeatTimerId = vertx.setPeriodic(HOSTIE_KEEPALIVE_TIMEOUT) { id ->
131133
// if(state == StateEnum.ON) {
@@ -143,18 +145,20 @@ abstract class Puppet: EventEmitter{
143145

144146
//dong
145147
fun on(event: String, listener: PuppetDongListener) {
146-
super.on(event,object:Listener{
148+
super.on(event, object : Listener {
147149
override fun handler(vararg any: Any) {
148150

151+
149152
log.debug("class Type is {}",any[0].javaClass.name)
150153

154+
151155
listener.handler(any[0] as EventDongPayload)
152156
}
153157
})
154158
}
155159

156160
fun on(event: String, listener: PuppetFriendshipListener) {
157-
super.on(event,object:Listener{
161+
super.on(event, object : Listener {
158162
override fun handler(vararg any: Any) {
159163
listener.handler(any[0] as EventFriendshipPayload)
160164
}
@@ -163,95 +167,115 @@ abstract class Puppet: EventEmitter{
163167

164168
//dong
165169
fun on(event: String, listener: PuppetLogoutListener) {
166-
super.on(event,object:Listener{
170+
super.on(event, object : Listener {
167171
override fun handler(vararg any: Any) {
168172
listener.handler(any[0] as EventLogoutPayload)
169173
}
170174
})
171175
}
172176

173-
fun on(event: String,listener: PuppetRoomInviteListener){
174-
super.on(event,object:Listener{
177+
fun on(event: String, listener: PuppetRoomInviteListener) {
178+
super.on(event, object : Listener {
175179
override fun handler(vararg any: Any) {
176180
listener.handler(any[0] as EventRoomInvitePayload)
177181
}
178182
})
179183

180184
}
181185

182-
fun on(event: String,listener: PuppetRoomJoinListerner){
183-
super.on(event,object :Listener{
186+
fun on(event: String, listener: PuppetRoomJoinListener) {
187+
super.on(event, object : Listener {
184188
override fun handler(vararg any: Any) {
185189
listener.handler(any[0] as EventRoomJoinPayload)
186190
}
187191
})
188192
}
189193

190-
fun on(event: String,listener: PuppetErrorListener){
191-
super.on(event,object:Listener{
194+
fun on(event: String, listener: PuppetRoomLeaveListener) {
195+
super.on(event, object : Listener {
196+
override fun handler(vararg any: Any) {
197+
listener.handler(any[0] as EventRoomLeavePayload)
198+
}
199+
})
200+
}
201+
202+
fun on(event: String, listener: PuppetRoomTopicListener) {
203+
super.on(event, object : Listener {
204+
override fun handler(vararg any: Any) {
205+
listener.handler(any[0] as EventRoomTopicPayload)
206+
}
207+
})
208+
}
209+
210+
fun on(event: String, listener: PuppetErrorListener) {
211+
super.on(event, object : Listener {
192212
override fun handler(vararg any: Any) {
193213
listener.handler(any[0] as EventErrorPayload)
194214
}
195215
})
196216
}
197217

198218
fun on(event: String, listener: PuppetScanListener) {
199-
super.on(event,object:Listener{
219+
super.on(event, object : Listener {
200220
override fun handler(vararg any: Any) {
201221

222+
202223
log.debug("class Type is {}",any[0].javaClass.name)
203224

225+
204226
listener.handler(any[0] as EventScanPayload)
205227
}
206228
})
207229

208230
}
209231

210232
fun on(event: String, listener: PuppetLoginListener) {
211-
super.on(event,object:Listener{
233+
super.on(event, object : Listener {
212234
override fun handler(vararg any: Any) {
213235
listener.handler(any[0] as EventLoginPayload)
214236
}
215237
})
216238
}
217239

218240
fun on(event: String, listener: PuppetReadyListener) {
219-
super.on(event,object:Listener{
241+
super.on(event, object : Listener {
220242
override fun handler(vararg any: Any) {
221243
listener.handler(any[0] as EventReadyPayload)
222244
}
223245
})
224246
}
225247

226248
fun on(event: String, listener: PuppetMessageListener) {
227-
super.on(event,object:Listener{
249+
super.on(event, object : Listener {
228250
override fun handler(vararg any: Any) {
229251
listener.handler(any[0] as EventMessagePayload)
230252
}
231253
})
232254
}
233255

234-
fun on(event:String,listener: PuppetHeartbeatListener){
235-
super.on(event,object:Listener{
256+
fun on(event: String, listener: PuppetHeartbeatListener) {
257+
super.on(event, object : Listener {
236258
override fun handler(vararg any: Any) {
237259

260+
238261
log.debug("class Type is {}",any[0].javaClass.name)
239262

263+
240264
listener.handler(any[0] as EventHeartbeatPayload)
241265
}
242266
})
243267
}
244268

245-
fun on(event:String,listener: PuppetResetListener){
246-
super.on(event,object:Listener{
269+
fun on(event: String, listener: PuppetResetListener) {
270+
super.on(event, object : Listener {
247271
override fun handler(vararg any: Any) {
248272
listener.handler(any[0] as EventResetPayload)
249273
}
250274
})
251275
}
252276

253-
fun on(event: String,listener: WatchdogListener){
254-
super.on(event,object :Listener{
277+
fun on(event: String, listener: WatchdogListener) {
278+
super.on(event, object : Listener {
255279
override fun handler(vararg any: Any) {
256280
listener.handler(any[0] as WatchdogFood)
257281
}
@@ -261,7 +285,7 @@ abstract class Puppet: EventEmitter{
261285

262286
abstract fun start(): Future<Void>
263287
abstract fun stop(): Future<Void>
264-
open fun unref(){
288+
open fun unref() {
265289

266290
}
267291

@@ -354,20 +378,20 @@ abstract class Puppet: EventEmitter{
354378
log.debug("contractId is {}", contactId)
355379
val roomList = roomList().get()
356380
val roomPayloadFuture: List<CompletableFuture<RoomPayload>> = roomList
357-
.map { roomId: String ->
358-
roomPayload(
359-
roomId
360-
)
361-
}
362-
.map(FutureUtils::toCompletable)
381+
.map { roomId: String ->
382+
roomPayload(
383+
roomId
384+
)
385+
}
386+
.map(FutureUtils::toCompletable)
363387
val resultRoomIdList =
364-
FutureUtils.sequence(roomPayloadFuture)
388+
FutureUtils.sequence(roomPayloadFuture)
365389
val roomPayloadList = resultRoomIdList.get()
366390
val result =
367-
roomPayloadList.filter { t: RoomPayload ->
368-
val memberIdList = t.memberIdList
369-
contactId in memberIdList
370-
}.map(RoomPayload::id)
391+
roomPayloadList.filter { t: RoomPayload ->
392+
val memberIdList = t.memberIdList
393+
contactId in memberIdList
394+
}.map(RoomPayload::id)
371395
return CompletableFuture.completedFuture(result)
372396
}
373397

@@ -467,6 +491,7 @@ abstract class Puppet: EventEmitter{
467491
val contactPayload = cacheContactPayload.getIfPresent(contactId)
468492

469493
log.debug("contactPayload is {} by id {}", contactPayload,contactId)
494+
470495
return contactPayload
471496
}
472497

@@ -564,7 +589,7 @@ abstract class Puppet: EventEmitter{
564589

565590
abstract fun messageContact(messageId: String): Future<String>
566591
abstract fun messageFile(messageId: String): Future<FileBox>
567-
abstract fun messageImage(messageId: String,imageType:ImageType): Future<FileBox>
592+
abstract fun messageImage(messageId: String, imageType: ImageType): Future<FileBox>
568593
abstract fun messageMiniProgram(messageId: String): Future<MiniProgramPayload>
569594
abstract fun messageUrl(messageId: String): Future<UrlLinkPayload>
570595

wechaty-puppet/src/main/kotlin/io/github/wechaty/listener/Listener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ interface PuppetResetListener{
6161
}
6262

6363
@FunctionalInterface
64-
interface PuppetRoomJoinListerner{
64+
interface PuppetRoomJoinListener{
6565
fun handler(payload: EventRoomJoinPayload)
6666
// override fun handler0(vararg any: Any) {
6767
// handler(any[0] as EventRoomJoinPayload)
6868
// }
6969
}
7070

7171
@FunctionalInterface
72-
interface PuppetRoomLeaveListerner{
72+
interface PuppetRoomLeaveListener{
7373
fun handler(payload: EventRoomLeavePayload)
7474
// override fun handler0(vararg any: Any) {
7575
// handler(any[0] as EventRoomLeavePayload)

0 commit comments

Comments
 (0)