Skip to content

Commit b66436b

Browse files
committed
#8 采用简化lamda方式
1 parent 4b80f07 commit b66436b

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed
Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
11
package wechaty;
22

3-
import wechaty.puppet.schemas.Message;
4-
5-
import static jdk.nashorn.internal.objects.Global.println;
6-
73
/**
84
* @author <a href="mailto:[email protected]">Jun Tsai</a>
95
* @since 2020-06-04
106
*/
117
public class JavaDingDongBot {
12-
public static void main(String[] args) throws InterruptedException {
13-
WechatyOptions option = new WechatyOptions();
14-
Wechaty bot = Wechaty.instance(option);
15-
bot
16-
.onScan(payload -> {
17-
System.out.println(payload);
18-
System.out.println(String.format("Scan QR Code to login: %s\nhttps://api.qrserver.com/v1/create-qr-code/?data=%s\n",payload.status().toString(), payload.qrcode()));
19-
})
20-
.onLogin(payload -> {
21-
System.out.println(String.format("User %s logined",payload.id()));
22-
})
23-
.onMessage(message -> {
24-
System.out.println(message.payload().type());
8+
public static void main(String[] args) throws InterruptedException {
9+
WechatyOptions option = new WechatyOptions();
10+
Wechaty bot = Wechaty.instance(option);
11+
bot
12+
.onScan(payload -> System.out.println(String.format("Scan QR Code to login: %s\nhttps://api.qrserver.com/v1/create-qr-code/?data=%s\n", payload.status().toString(), payload.qrcode())))
13+
.onLogin(payload -> System.out.println(String.format("User %s logined", payload.id())))
14+
.onMessage(message -> {
2515
// if (message.payload().type() != Message.MessageType.MessageTypeText() || !message.payload().text().equals("#ding")){
26-
if (!message.payload().text().equals("#ding")){
27-
System.out.println("Message discarded because it does not match #ding");
28-
}else{
29-
System.out.println("send message to "+ message.payload().fromId());
30-
message.say("dong");
31-
System.out.println("dong");
32-
}
33-
});
16+
if (!message.payload().text().equals("#ding")) {
17+
System.out.println("Message discarded because it does not match #ding");
18+
} else {
19+
System.out.println("send message to " + message.payload().fromId());
20+
message.say("dong");
21+
System.out.println("dong");
22+
}
23+
});
3424

3525

36-
bot.start();
26+
bot.start();
3727

38-
Thread.currentThread().join();
39-
}
28+
Thread.currentThread().join();
29+
}
4030
}

0 commit comments

Comments
 (0)