|
1 | 1 | package wechaty;
|
2 | 2 |
|
3 |
| -import wechaty.puppet.schemas.Message; |
4 |
| - |
5 |
| -import static jdk.nashorn.internal.objects.Global.println; |
6 |
| - |
7 | 3 | /**
|
8 | 4 | * @author <a href="mailto:[email protected]">Jun Tsai</a>
|
9 | 5 | * @since 2020-06-04
|
10 | 6 | */
|
11 | 7 | 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 -> { |
25 | 15 | // 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 | + }); |
34 | 24 |
|
35 | 25 |
|
36 |
| - bot.start(); |
| 26 | + bot.start(); |
37 | 27 |
|
38 |
| - Thread.currentThread().join(); |
39 |
| - } |
| 28 | + Thread.currentThread().join(); |
| 29 | + } |
40 | 30 | }
|
0 commit comments