-
Notifications
You must be signed in to change notification settings - Fork 1
Add build.sbt #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YipZong
wants to merge
5
commits into
wechaty:master
Choose a base branch
from
YipZong:add-build.sbt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
name := "scala-sbt-wechaty-getting-started" | ||
|
||
version := "0.1" | ||
|
||
scalaVersion := "2.12.14" | ||
|
||
val wechaty = "io.github.wechaty" %% "wechaty" % "0.0.15" | ||
val apacheCommons = "org.apache.commons" % "commons-text" % "1.9" | ||
|
||
libraryDependencies ++= Seq(wechaty, apacheCommons) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,68 @@ | ||
import org.apache.commons.lang3.StringUtils | ||
import wechaty.{Wechaty, WechatyOptions} | ||
|
||
/** | ||
* | ||
* @author <a href="mailto:[email protected]">Jun Tsai</a> | ||
* @since 2020-06-02 | ||
*/ | ||
object DingDongBot { | ||
def main(args: Array[String]): Unit = { | ||
val token: String = sys.props.getOrElse("WECHATY_PUPPET_HOSTIE_TOKEN", | ||
throw new Exception(s"Error: WECHATY_PUPPET_HOSTIE_TOKEN is not found in the environment variable!" + | ||
s"You need a TOKEN to run the Scala Wechaty." + | ||
s"Please goto our README for details https://wechaty.js.org/docs/puppet-services/padlocal/")) | ||
TokenValidator.isValidToken(token) | ||
|
||
val option = new WechatyOptions | ||
|
||
try { | ||
val bot = Wechaty.instance(option) | ||
|
||
bot | ||
.onScan(payload => { | ||
println("Scan QR Code to login: %s\nhttps://api.qrserver.com/v1/create-qr-code/?data=%s\n".format(payload.status, payload.qrcode)) | ||
}) | ||
.onLogin(payload => { | ||
println("User %s logined\n".format(payload.id)) | ||
}) | ||
.onMessage(message => { | ||
println(message) | ||
if (message.payload.`type` != wechaty.puppet.schemas.Message.MessageType || message.payload.text != "ding") { | ||
println("Message discarded because it does not match ding") | ||
} else { | ||
message.say("dong") | ||
println("dong") | ||
} | ||
}) | ||
|
||
|
||
bot.start() | ||
|
||
Thread.currentThread().join() | ||
|
||
|
||
} catch { | ||
case _: java.io.FileNotFoundException => | ||
System.out.println(s"TOKEN is NOT registered successfully, please refer to https://wechaty.js.org/docs/puppet-services/diy/") | ||
} | ||
|
||
} | ||
} | ||
|
||
object TokenValidator { | ||
def isValidToken(token: String): Unit = { | ||
import java.util.regex.Pattern | ||
val p = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") | ||
val valid = p.matcher(token).matches() | ||
|
||
|
||
if (valid) { | ||
System.out.println("token format correct, creating Wechaty instance...") | ||
} else { | ||
throw new Exception(s"Error: Wrong token format, WECHATY_PUPPET_HOSTIE_TOKEN should be in UUID v4 format!") | ||
} | ||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please help us to change the
WECHATY_PUPPET_HOSTIE
toWECHATY_PUPPET_SERVICE
because we have renamed it for more than 6 months in our ecosystem.