-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:sparkling: #8 初步调整支持java调用,因为scala的枚举在java调用产生问题,所以需要调整schemas的代码
- Loading branch information
Showing
5 changed files
with
82 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package wechaty; | ||
|
||
import wechaty.puppet.schemas.Message; | ||
|
||
import static jdk.nashorn.internal.objects.Global.println; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Jun Tsai</a> | ||
* @since 2020-06-04 | ||
*/ | ||
public class JavaDingDongBot { | ||
public static void main(String[] args) throws InterruptedException { | ||
WechatyOptions option = new WechatyOptions(); | ||
Wechaty bot = Wechaty.instance(option); | ||
bot | ||
.onScan(payload -> { | ||
System.out.println(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())); | ||
}) | ||
.onLogin(payload -> { | ||
System.out.println(String.format("User %s logined",payload.id())); | ||
}) | ||
.onMessage(message -> { | ||
System.out.println(message.payload().type()); | ||
// if (message.payload().type() != Message.MessageType.MessageTypeText() || !message.payload().text().equals("#ding")){ | ||
if (!message.payload().text().equals("#ding")){ | ||
System.out.println("Message discarded because it does not match #ding"); | ||
}else{ | ||
System.out.println("send message to "+ message.payload().fromId()); | ||
message.say("dong"); | ||
System.out.println("dong"); | ||
} | ||
}); | ||
|
||
|
||
bot.start(); | ||
|
||
Thread.currentThread().join(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package wechaty.user | ||
|
||
import wechaty.puppet.Puppet | ||
import wechaty.Wechaty.PuppetResolver | ||
import wechaty.puppet.schemas | ||
|
||
/** | ||
* | ||
* @author <a href="mailto:[email protected]">Jun Tsai</a> | ||
* @since 2020-06-03 | ||
*/ | ||
class Contact(contactId:String)(implicit puppet:Puppet) { | ||
lazy val payload: schemas.Contact.ContactPayload = puppet.contactPayload(contactId) | ||
class Contact(contactId:String)(implicit resolver:PuppetResolver) { | ||
lazy val payload: schemas.Contact.ContactPayload = resolver.puppet.contactPayload(contactId) | ||
//delegate method | ||
def id=contactId | ||
def name = payload.name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package wechaty.user | ||
|
||
import wechaty.puppet.Puppet | ||
import wechaty.Wechaty.PuppetResolver | ||
import wechaty.puppet.schemas | ||
import wechaty.puppet.schemas.Puppet | ||
|
||
|
@@ -9,10 +9,10 @@ import wechaty.puppet.schemas.Puppet | |
* @author <a href="mailto:[email protected]">Jun Tsai</a> | ||
* @since 2020-06-02 | ||
*/ | ||
class Message(messageId:String)(implicit puppet:Puppet) { | ||
lazy val payload: schemas.Message.MessagePayload = puppet.messagePayload(messageId) | ||
class Message(messageId:String)(implicit resolver: PuppetResolver) { | ||
lazy val payload: schemas.Message.MessagePayload = resolver.puppet.messagePayload(messageId) | ||
def say(text:String): Unit = { | ||
puppet.messageSendText(sayId(),text) | ||
resolver.puppet.messageSendText(sayId(),text) | ||
} | ||
private def sayId(): String ={ | ||
if(!Puppet.isBlank(payload.roomId)) payload.roomId | ||
|
@@ -21,6 +21,6 @@ class Message(messageId:String)(implicit puppet:Puppet) { | |
} | ||
|
||
override def toString: String = { | ||
payload.text | ||
if(payload!= null ) payload.text else "" | ||
} | ||
} |