Skip to content

Commit c070fda

Browse files
committed
Merge branch 'master' of github.com:wechaty/java-wechaty
2 parents 20939ce + 47f4c98 commit c070fda

File tree

26 files changed

+1153
-214
lines changed

26 files changed

+1153
-214
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
![Java Wechaty](https://wechaty.github.io/java-wechaty/images/java-wechaty.png)
77

8+
[![Java Wechaty Getting Started](https://img.shields.io/badge/Java%20Wechaty-Getting%20Started-orange)](https://github.com/wechaty/java-wechaty-getting-started)
9+
810
## Connecting Chatbots
911

1012
[![Powered by Wechaty](https://img.shields.io/badge/Powered%20By-Wechaty-brightgreen.svg)](https://github.com/Wechaty/wechaty)
@@ -279,15 +281,14 @@ We decided to use Kotlin to develop the Java Wechaty!
279281
- [Python Wechaty](https://github.com/wechaty/python-wechaty) - Python WeChat Bot SDK for Individual Account.
280282
- [Go Wechaty](https://github.com/wechaty/go-wechaty) - Go WeChat Bot SDK for Individual Account.
281283

282-
## Contributors
284+
## Committers
283285

284286
- [@redmaple1](https://github.com/redmaple1) Xiaoya Ren
285287

286-
## Committers
288+
## Author
287289

288290
- [@diaozxin007](https://github.com/diaozxin007) diaozxin@gmail.com
289291
- Website: [犀利豆的博客](https://xilidou.com/)
290-
- [@huan](https://github.com/huan) - Huan LI ([李卓桓](http://linkedin.com/in/zixia)), Tencent TVP of Chatbot, zixia@zixia.net
291292

292293
## Copyright & License
293294

pom.xml

Lines changed: 36 additions & 25 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>1.0.0-SNAPSHOT</version>
8+
<version>0.1.0-SNAPSHOT</version>
99
<name>kotlin-wechaty</name>
1010

1111
<description>
@@ -172,33 +172,44 @@
172172
<version>0.1.1</version>
173173
</dependency>
174174

175+
<dependency>
176+
<groupId>org.hamcrest</groupId>
177+
<artifactId>hamcrest-core</artifactId>
178+
<version>1.3</version>
179+
</dependency>
180+
<dependency>
181+
<groupId>net.sourceforge.htmlcleaner</groupId>
182+
<artifactId>htmlcleaner</artifactId>
183+
<version>2.16</version>
184+
</dependency>
185+
175186
</dependencies>
176187
</dependencyManagement>
177188

178-
<build>
179-
<plugins>
180-
<plugin>
181-
<groupId>org.apache.maven.plugins</groupId>
182-
<artifactId>maven-gpg-plugin</artifactId>
183-
<version>1.6</version>
184-
<executions>
185-
<execution>
186-
<id>sign-artifacts</id>
187-
<phase>verify</phase>
188-
<goals>
189-
<goal>sign</goal>
190-
</goals>
191-
<configuration>
192-
<gpgArguments>
193-
<arg>--pinentry-mode</arg>
194-
<arg>loopback</arg>
195-
</gpgArguments>
196-
</configuration>
197-
</execution>
198-
</executions>
199-
</plugin>
200-
</plugins>
201-
</build>
189+
<!-- <build>-->
190+
<!-- <plugins>-->
191+
<!-- <plugin>-->
192+
<!-- <groupId>org.apache.maven.plugins</groupId>-->
193+
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
194+
<!-- <version>1.6</version>-->
195+
<!-- <executions>-->
196+
<!-- <execution>-->
197+
<!-- <id>sign-artifacts</id>-->
198+
<!-- <phase>verify</phase>-->
199+
<!-- <goals>-->
200+
<!-- <goal>sign</goal>-->
201+
<!-- </goals>-->
202+
<!-- <configuration>-->
203+
<!-- <gpgArguments>-->
204+
<!-- <arg>&#45;&#45;pinentry-mode</arg>-->
205+
<!-- <arg>loopback</arg>-->
206+
<!-- </gpgArguments>-->
207+
<!-- </configuration>-->
208+
<!-- </execution>-->
209+
<!-- </executions>-->
210+
<!-- </plugin>-->
211+
<!-- </plugins>-->
212+
<!-- </build>-->
202213

203214

204215
<contributors>

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>1.0.0-SNAPSHOT</version>
7+
<version>0.1.0-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: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.grpc.stub.StreamObserver
1313
import okhttp3.OkHttpClient
1414
import okhttp3.Request
1515
import org.apache.commons.lang3.StringUtils
16+
import org.apache.commons.lang3.math.NumberUtils
1617
import org.slf4j.LoggerFactory
1718
import java.util.concurrent.CompletableFuture
1819
import java.util.concurrent.CountDownLatch
@@ -39,7 +40,7 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
3940

4041
// private var finishLatch:CountDownLatch? = null
4142

42-
private fun discoverHostieIpa(): String {
43+
private fun discoverHostieIp():Pair<String,String>{
4344

4445
val token = puppetOptions!!.token
4546

@@ -51,7 +52,11 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
5152
response ->
5253
val string = response.body!!.string()
5354
val readValue = JsonUtils.readValue<Map<String, String>>(string)
54-
return readValue["ip"] ?: error("")
55+
56+
val ip = readValue["ip"] ?: error("cannot get ip by token, check token");
57+
val port = readValue["port"] ?:"8788"
58+
59+
return Pair(ip,port)
5560
}
5661
}
5762

@@ -130,16 +135,26 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
130135
}
131136

132137
private fun startGrpcClient(): Future<Void> {
133-
var endPoint = puppetOptions?.endPoint
134-
if (StringUtils.isEmpty(endPoint)) {
135-
endPoint = discoverHostieIpa()
138+
val endPoint = puppetOptions?.endPoint
139+
val discoverHostieIp:Pair<String,String>
140+
discoverHostieIp = if (StringUtils.isEmpty(endPoint)) {
141+
discoverHostieIp()
142+
}else{
143+
val split = StringUtils.split(endPoint, ":")
144+
if(split.size == 1) {
145+
Pair(split[0],"8788")
146+
}else{
147+
Pair(split[0],split[1])
148+
}
149+
136150
}
137151

138-
if (StringUtils.isEmpty(endPoint) || StringUtils.equals(endPoint, "0.0.0.0")) {
139-
throw Exception()
152+
if (StringUtils.isEmpty(discoverHostieIp.first) || StringUtils.equals(discoverHostieIp.first, "0.0.0.0")) {
153+
log.error("cannot get ip by token, check token")
154+
throw Exception("cannot get ip by token, check token")
140155
}
141156
val newFixedThreadPool = newFixedThreadPool(16)
142-
channel = ManagedChannelBuilder.forAddress(endPoint, GRPC_PROT).usePlaintext().executor(newFixedThreadPool).build()
157+
channel = ManagedChannelBuilder.forAddress(discoverHostieIp.first,NumberUtils.toInt(discoverHostieIp.second)).usePlaintext().executor(newFixedThreadPool).build()
143158

144159
grpcClient = PuppetGrpc.newBlockingStub(channel)
145160
grpcAsyncClient = PuppetGrpc.newStub(channel)
@@ -380,14 +395,13 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
380395

381396
return CompletableFuture.supplyAsync {
382397
val response = grpcClient!!.contactPayload(request)
383-
val payload = ContactPayload()
398+
val payload = ContactPayload(response.id)
384399
payload.address = response.address
385400
payload.alias = response.alias
386401
payload.avatar = response.avatar
387402
payload.city = response.city
388403
payload.friend = response.friend
389404
payload.gender = ContractGender.getByCode(response.gender.number)
390-
payload.id = response.id
391405
payload.name = response.name
392406
payload.province = response.province
393407
payload.signature = response.signature
@@ -835,11 +849,10 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
835849

836850
return CompletableFuture.supplyAsync {
837851
val response = grpcClient!!.roomPayload(request)
838-
val payload = RoomPayload()
852+
val payload = RoomPayload(response.id)
839853

840854
payload.adminIdList = response.adminIdsList
841855
payload.avatar = response.avatar
842-
payload.id = response.id
843856
payload.memberIdList = response.memberIdsList
844857
payload.ownerId = response.ownerId
845858
payload.topic = response.topic

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>1.0.0-SNAPSHOT</version>
7+
<version>0.1.0-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>wechaty-puppet</artifactId>

0 commit comments

Comments
 (0)