Skip to content

Commit d371406

Browse files
authored
Merge pull request #30 from diaozxin007/master
update 0.1.2
2 parents 9d6b684 + dd062d0 commit d371406

File tree

20 files changed

+301
-223
lines changed

20 files changed

+301
-223
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ Scan now, because other Wechaty Java developers want to talk with you too! (secr
5252
```java
5353
class Bot{
5454
public static void main(String args[]){
55-
bot = Wechaty.instance()
56-
.on('scan', (qrcode, status, string) -> System.out.println('Scan QR Code to login: %s\nhttps://api.qrserver.com/v1/create-qr-code/?data=%s', status, encodeURIComponent(qrcode)))
57-
.on('login', user -> System.out.println('User %s logined', user))
58-
.on('message', message -> System.out.println('Message: %s', message))
59-
.start();
55+
Wechaty bot = Wechaty.instance()
56+
.onScan((qrcode, statusScanStatus, data) -> System.out.println(QrcodeUtils.getQr(qrcode)))
57+
.onLogin(user -> System.out.println("User logined :" + user))
58+
.onMessage(message -> System.out.println("Message:" + message))
59+
.start(true);
6060
}
6161
}
6262
```
@@ -264,9 +264,11 @@ mvn install wechaty
264264

265265
### master
266266

267-
### v0.1.1 (June 6 2020)
268-
1. update wechaty grpc to 0.16.1
269-
2. move examples from wechaty to independent module. Make example easy to use.
267+
### v0.1.2 (June 6 2020)
268+
1. change method `on(Event:String,Listener:listener)` to `onEvent(Listener:listener)`. See examples
269+
2. update version to 0.1.2
270+
3. update wechaty grpc to 0.16.1
271+
4. move examples from wechaty to independent module. Make example easy to use.
270272

271273
### v0.1.1 (May 31 2020)
272274

examples/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
7-
<version>0.1.1-SNAPSHOT</version>
7+
<version>1.0.0-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>wechaty-example</artifactId>
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>io.github.wechaty</groupId>
2626
<artifactId>wechaty</artifactId>
27-
<version>0.1.1-SNAPSHOT</version>
27+
<version>0.1.2-SNAPSHOT</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>org.apache.logging.log4j</groupId>

examples/src/main/java/io/github/wechaty/example/Main.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.github.wechaty.example;
22

33

4+
import io.github.wechaty.LoginListener;
45
import io.github.wechaty.MessageListener;
56
import io.github.wechaty.Wechaty;
67
import io.github.wechaty.filebox.FileBox;
8+
import io.github.wechaty.io.github.wechaty.schemas.EventEnum;
79
import io.github.wechaty.user.Contact;
810
import io.github.wechaty.user.Room;
911
import io.github.wechaty.utils.QrcodeUtils;
@@ -16,29 +18,21 @@
1618

1719
public class Main {
1820

19-
public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
20-
21-
Wechaty bot = Wechaty.instance("your_token");
22-
23-
bot.on("scan", (qrcode, statusScanStatus, data) -> {
24-
System.out.println(QrcodeUtils.getQr(qrcode));
25-
});
26-
27-
bot.on("message", (MessageListener) message -> {
28-
29-
Contact from = message.from();
30-
Room room = message.room();
31-
32-
String text = message.text();
33-
34-
if (StringUtils.equals(text, "#ding")) {
35-
if (room != null) {
36-
room.say("dong");
21+
public static void main(String[] args){
22+
23+
Wechaty bot = Wechaty.instance("your_token")
24+
.onScan((qrcode, statusScanStatus, data) -> System.out.println(QrcodeUtils.getQr(qrcode)))
25+
.onLogin(user -> System.out.println(user))
26+
.onMessage(message -> {
27+
Room room = message.room();
28+
String text = message.text();
29+
if (StringUtils.equals(text, "#ding")) {
30+
if (room != null) {
31+
room.say("dong");
32+
}
3733
}
38-
}
39-
});
34+
}).start(true);
4035

41-
bot.start(true);
4236
// }
4337

4438
// Room room = bot.room();

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
77
<packaging>pom</packaging>
8-
<version>0.1.1-SNAPSHOT</version>
8+
<version>0.1.2-SNAPSHOT</version>
99
<name>kotlin-wechaty</name>
1010

1111
<description>
@@ -147,12 +147,6 @@
147147
<artifactId>okhttp</artifactId>
148148
<version>4.6.0</version>
149149
</dependency>
150-
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/io.grpc/grpc-kotlin-stub &ndash;&gt;-->
151-
<!-- <dependency>-->
152-
<!-- <groupId>io.grpc</groupId>-->
153-
<!-- <artifactId>grpc-kotlin-stub</artifactId>-->
154-
<!-- <version>0.1.1</version>-->
155-
<!-- </dependency>-->
156150

157151
<dependency>
158152
<groupId>org.hamcrest</groupId>

wechaty-puppet-hostie/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
7-
<version>0.1.1-SNAPSHOT</version>
7+
<version>0.1.2-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>wechaty-puppet-hostie</artifactId>

wechaty-puppet-hostie/src/main/kotlin/io/github/wechaty/grpc/GrpcPuppet.kt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.github.wechaty.Puppet
55
import io.github.wechaty.StateEnum
66
import io.github.wechaty.filebox.FileBox
77
import io.github.wechaty.grpc.puppet.*
8+
import io.github.wechaty.io.github.wechaty.schemas.EventEnum
89
import io.github.wechaty.schemas.*
910
import io.github.wechaty.utils.JsonUtils
1011
import io.grpc.ManagedChannel
@@ -19,6 +20,7 @@ import java.util.concurrent.CompletableFuture
1920
import java.util.concurrent.Executors.newFixedThreadPool
2021
import java.util.concurrent.Future
2122
import java.util.concurrent.TimeUnit
23+
import kotlin.system.exitProcess
2224

2325
/**
2426
* puppet
@@ -97,7 +99,7 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
9799

98100
try {
99101
if (logonoff()) {
100-
emit("logout",EventLogoutPayload(getId()!!,"logout"))
102+
emit(EventEnum.LOGOUT,EventLogoutPayload(getId()!!,"logout"))
101103

102104
this.setId(null)
103105
}
@@ -148,7 +150,7 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
148150

149151
if (StringUtils.isEmpty(discoverHostieIp.first) || StringUtils.equals(discoverHostieIp.first, "0.0.0.0")) {
150152
log.error("cannot get ip by token, check token")
151-
throw Exception("cannot get ip by token, check token")
153+
exitProcess(1)
152154
}
153155
val newFixedThreadPool = newFixedThreadPool(16)
154156
channel = ManagedChannelBuilder.forAddress(discoverHostieIp.first,NumberUtils.toInt(discoverHostieIp.second)).usePlaintext().executor(newFixedThreadPool).build()
@@ -167,7 +169,7 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
167169
override fun onError(t: Throwable?) {
168170
log.error("error of grpc",t)
169171
val payload = EventResetPayload(t?.message ?:"")
170-
emit("reset",payload)
172+
emit(EventEnum.RESET,payload)
171173
}
172174

173175
override fun onCompleted() {
@@ -200,7 +202,7 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
200202
} catch (e: Exception) {
201203
log.error("logout() rejection: %s", e)
202204
} finally {
203-
emit("logout",EventLogoutPayload(getId()!!,"logout"))
205+
emit(EventEnum.LOGOUT,EventLogoutPayload(getId()!!,"logout"))
204206
}
205207
return CompletableFuture.completedFuture(null)
206208
}
@@ -942,67 +944,67 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
942944
log.debug("PuppetHostie $type payload $payload")
943945

944946
if (type != Event.EventType.EVENT_TYPE_HEARTBEAT) {
945-
emit("heartbeat", EventHeartbeatPayload("heartbeat"))
947+
emit(EventEnum.HEART_BEAT, EventHeartbeatPayload("heartbeat"))
946948
}
947949

948950
when (type) {
949-
Event.EventType.EVENT_TYPE_DONG -> emit("dong", JsonUtils.readValue<EventDongPayload>(payload))
951+
Event.EventType.EVENT_TYPE_DONG -> emit(EventEnum.DONG, JsonUtils.readValue<EventDongPayload>(payload))
950952

951953
Event.EventType.EVENT_TYPE_ERROR -> {
952-
emit("error", JsonUtils.readValue<EventErrorPayload>(payload))
954+
emit(EventEnum.ERROR, JsonUtils.readValue<EventErrorPayload>(payload))
953955
}
954956

955957
Event.EventType.EVENT_TYPE_HEARTBEAT -> {
956958
val heartbeatPayload = JsonUtils.readValue<EventHeartbeatPayload>(payload)
957-
emit("heartbeat", heartbeatPayload)
959+
emit(EventEnum.HEART_BEAT, heartbeatPayload)
958960
}
959961

960962
Event.EventType.EVENT_TYPE_FRIENDSHIP -> {
961963
val friendshipPayload = JsonUtils.readValue<EventFriendshipPayload>(payload)
962-
emit("friendship", friendshipPayload)
964+
emit(EventEnum.FRIENDSHIP, friendshipPayload)
963965
}
964966

965967
Event.EventType.EVENT_TYPE_LOGIN -> {
966968
val loginPayload = JsonUtils.readValue<EventLoginPayload>(payload)
967969
setId(loginPayload.contactId)
968-
emit("login", loginPayload)
970+
emit(EventEnum.LOGIN, loginPayload)
969971
}
970972

971973
Event.EventType.EVENT_TYPE_LOGOUT -> {
972974
this.setId("")
973-
emit("logout", JsonUtils.readValue<EventLogoutPayload>(payload))
975+
emit(EventEnum.LOGOUT, JsonUtils.readValue<EventLogoutPayload>(payload))
974976
}
975977

976978

977979
Event.EventType.EVENT_TYPE_MESSAGE -> {
978980
val eventMessagePayload = JsonUtils.readValue<EventMessagePayload>(payload)
979-
emit("message", eventMessagePayload)
981+
emit(EventEnum.MESSAGE, eventMessagePayload)
980982
}
981983

982984
Event.EventType.EVENT_TYPE_READY -> {
983-
emit("ready", JsonUtils.readValue<EventReadyPayload>(payload))
985+
emit(EventEnum.READY, JsonUtils.readValue<EventReadyPayload>(payload))
984986
}
985987

986988
Event.EventType.EVENT_TYPE_ROOM_INVITE -> {
987-
emit("room-invite", JsonUtils.readValue<EventRoomInvitePayload>(payload))
989+
emit(EventEnum.ROOM_INVITE, JsonUtils.readValue<EventRoomInvitePayload>(payload))
988990
}
989991

990992
Event.EventType.EVENT_TYPE_ROOM_JOIN -> {
991-
emit("room-join", JsonUtils.readValue<EventRoomJoinPayload>(payload))
993+
emit(EventEnum.ROOM_JOIN, JsonUtils.readValue<EventRoomJoinPayload>(payload))
992994
}
993995

994996
Event.EventType.EVENT_TYPE_ROOM_LEAVE -> {
995-
emit("room-leave", JsonUtils.readValue<EventRoomLeavePayload>(payload))
997+
emit(EventEnum.ROOM_LEAVE, JsonUtils.readValue<EventRoomLeavePayload>(payload))
996998
}
997999

9981000
Event.EventType.EVENT_TYPE_ROOM_TOPIC -> {
999-
emit("room-topic", JsonUtils.readValue<EventRoomTopicPayload>(payload))
1001+
emit(EventEnum.ROOM_TOPIC, JsonUtils.readValue<EventRoomTopicPayload>(payload))
10001002
}
10011003

10021004
Event.EventType.EVENT_TYPE_SCAN -> {
10031005
val eventScanPayload = JsonUtils.readValue<EventScanPayload>(payload)
10041006
log.debug("scan pay load is {}", eventScanPayload)
1005-
emit("scan", eventScanPayload)
1007+
emit(EventEnum.SCAN, eventScanPayload)
10061008
}
10071009

10081010
Event.EventType.EVENT_TYPE_RESET -> {

wechaty-puppet-mock/pom.xml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>wechaty-parent</artifactId>
77
<groupId>io.github.wechaty</groupId>
8-
<version>0.1.1-SNAPSHOT</version>
8+
<version>0.1.2-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -21,24 +21,6 @@
2121
<artifactId>wechaty-puppet</artifactId>
2222
<version>${project.version}</version>
2323
</dependency>
24-
25-
<!-- <dependency>-->
26-
<!-- <groupId>org.apache.logging.log4j</groupId>-->
27-
<!-- <artifactId>log4j-api</artifactId>-->
28-
<!-- </dependency>-->
29-
<!-- <dependency>-->
30-
<!-- <groupId>org.apache.logging.log4j</groupId>-->
31-
<!-- <artifactId>log4j-core</artifactId>-->
32-
<!-- </dependency>-->
33-
<!-- <dependency>-->
34-
<!-- <groupId>org.apache.logging.log4j</groupId>-->
35-
<!-- <artifactId>log4j-slf4j-impl</artifactId>-->
36-
<!-- </dependency>-->
37-
<!-- <dependency>-->
38-
<!-- <groupId>org.slf4j</groupId>-->
39-
<!-- <artifactId>slf4j-api</artifactId>-->
40-
<!-- </dependency>-->
41-
4224
<dependency>
4325
<groupId>org.mockito</groupId>
4426
<artifactId>mockito-core</artifactId>

wechaty-puppet-mock/src/main/kotlin/io/github/wechaty/MockPuppet.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.wechaty
22

33
import io.github.wechaty.filebox.FileBox
4+
import io.github.wechaty.io.github.wechaty.schemas.EventEnum
45
import io.github.wechaty.schemas.*
56
import org.slf4j.LoggerFactory
67
import java.util.*
@@ -30,15 +31,15 @@ class MockPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
3031
*/
3132
val eventScanPayload = EventScanPayload(ScanStatus.Cancel)
3233
eventScanPayload.qrcode = "https://github.com/wechaty/java-wechaty/wechaty-puppet-mock"
33-
emit("scan", eventScanPayload)
34+
emit(EventEnum.SCAN, eventScanPayload)
3435

3536

3637
val userPayload = MockData.getFakeContactPayload()
3738
cacheContactPayload.put(userPayload.id, userPayload)
3839

3940
setId(userPayload.id)
4041

41-
emit("login", EventLoginPayload(userPayload.id))
42+
emit(EventEnum.LOGIN, EventLoginPayload(userPayload.id))
4243

4344
timer.scheduleAtFixedRate(0, 5000) {
4445
val fromContactPayload = MockData.getFakeContactPayload()
@@ -47,7 +48,7 @@ class MockPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
4748

4849
cacheMessagePayload.put(messagePayload.id, messagePayload)
4950
log.info("MockPuppet start() schedule pretending received a new message:${messagePayload.id}")
50-
emit("message", EventMessagePayload(messagePayload.id))
51+
emit(EventEnum.MESSAGE, EventMessagePayload(messagePayload.id))
5152
}
5253
return CompletableFuture.completedFuture(null)
5354
}
@@ -74,15 +75,15 @@ class MockPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
7475
log.info("MockPuppet logout()")
7576
val id = getId() ?: throw Exception("logout before login?")
7677

77-
emit("logout", EventLogoutPayload(id, "test"))
78+
emit(EventEnum.LOGOUT, EventLogoutPayload(id, "test"))
7879
setId(null)
7980

8081
return CompletableFuture.completedFuture(null)
8182
}
8283

8384
override fun ding(data: String?) {
8485
log.info("MockPuppet ding(${data ?: ""})")
85-
emit("dong", EventDongPayload(data ?: ""))
86+
emit(EventEnum.DONG, EventDongPayload(data ?: ""))
8687
}
8788

8889
override fun contactSelfName(name: String): Future<Void> {

wechaty-puppet/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
7-
<version>0.1.1-SNAPSHOT</version>
7+
<version>0.1.2-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>wechaty-puppet</artifactId>

0 commit comments

Comments
 (0)