Skip to content

Commit af61622

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 1d8ea6a + afa375d commit af61622

File tree

17 files changed

+292
-81
lines changed

17 files changed

+292
-81
lines changed

examples/pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33

4+
45
<parent>
56
<groupId>io.github.wechaty</groupId>
67
<artifactId>wechaty-parent</artifactId>
7-
<version>1.0.0-SNAPSHOT</version>
8+
<version>0.1.5-SNAPSHOT</version>
89
</parent>
10+
911
<modelVersion>4.0.0</modelVersion>
1012
<artifactId>wechaty-example</artifactId>
13+
14+
<name>wechaty/example</name>
15+
1116
<packaging>jar</packaging>
17+
<version>1.0.0-SNAPSHOT</version>
1218

1319
<properties>
1420
<kotlin.version>1.3.72</kotlin.version>
@@ -17,7 +23,7 @@
1723
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1824
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
1925
<dokka.version>0.10.1</dokka.version>
20-
<wechaty.version>0.1.4-SNAPSHOT</wechaty.version>
26+
<wechaty.version>0.1.5-SNAPSHOT</wechaty.version>
2127
</properties>
2228

2329
<dependencies>
@@ -64,7 +70,6 @@
6470
<dependency>
6571
<groupId>org.apache.commons</groupId>
6672
<artifactId>commons-lang3</artifactId>
67-
<version>3.10</version>
6873
</dependency>
6974

7075
<dependency>

pom.xml

Lines changed: 2 additions & 1 deletion
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>0.1.4-SNAPSHOT</version>
8+
<version>0.1.5-SNAPSHOT</version>
99
<name>kotlin-wechaty</name>
1010

1111
<description>
@@ -31,6 +31,7 @@
3131
<module>wechaty-puppet</module>
3232
<module>wechaty-puppet-hostie</module>
3333
<module>wechaty-puppet-mock</module>
34+
<!-- <module>examples</module>-->
3435
</modules>
3536

3637
<dependencyManagement>

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>0.1.4-SNAPSHOT</version>
7+
<version>0.1.5-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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ class GrpcPuppet(puppetOptions: PuppetOptions) : Puppet(puppetOptions) {
946946
log.debug("PuppetHostie $type payload $payload")
947947

948948
if (type != Event.EventType.EVENT_TYPE_HEARTBEAT) {
949-
emit(EventEnum.HEART_BEAT, EventHeartbeatPayload("heartbeat"))
949+
emit(EventEnum.HEART_BEAT, EventHeartbeatPayload("heartbeat",6000))
950950
}
951951

952952
when (type) {

wechaty-puppet-mock/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>wechaty-parent</artifactId>
77
<groupId>io.github.wechaty</groupId>
8-
<version>0.1.4-SNAPSHOT</version>
8+
<version>0.1.5-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

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

wechaty-puppet/src/main/kotlin/io/github/wechaty/schemas/Event.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ data class EventResetPayload(
135135
}
136136

137137
data class EventHeartbeatPayload(
138-
var data:String
138+
var data:String,
139+
var timeout:Long
139140
) {
140141
override fun toString(): String {
141142
return "EventHeartbeatPayload(data='$data')"

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

wechaty/src/main/kotlin/io/github/wechaty/Wechaty.kt

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
3939
val roomManager = RoomManager(this)
4040
val roomInvitationManager = RoomInvitationManager(this)
4141
val imageManager = ImageManager(this)
42+
val friendshipManager = FriendshipManager(this)
4243

4344
init {
4445
// this.memory = wechatyOptions.memory
4546
installGlobalPlugin()
4647
}
4748

48-
4949
fun start(await: Boolean = false):Wechaty {
5050

5151
initPuppet()
@@ -72,6 +72,25 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
7272
puppet.stop()
7373
}
7474

75+
fun logout(){
76+
log.debug("Wechaty logout()")
77+
try {
78+
puppet.logout()
79+
} catch (e: Exception) {
80+
log.error("logout error",e)
81+
throw e
82+
}
83+
}
84+
85+
fun logonoff():Boolean{
86+
return try {
87+
puppet.logonoff()
88+
} catch (e: Exception) {
89+
false
90+
}
91+
}
92+
93+
7594
fun name(): String {
7695
return wechatyOptions.name
7796
}
@@ -172,16 +191,10 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
172191
}
173192

174193
private fun initPuppet() {
175-
// this.puppet = GrpcPuppet(puppetOptions)
176194
this.puppet = PuppetManager.resolveInstance(wechatyOptions).get()
177195
initPuppetEventBridge(puppet)
178196
}
179197

180-
fun friendship(): Friendship {
181-
return Friendship(this);
182-
}
183-
184-
185198
fun getPuppet(): Puppet {
186199
return puppet
187200
}
@@ -192,6 +205,13 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
192205
return user
193206
}
194207

208+
fun say(any: Any):Message?{
209+
return userSelf().say(any)
210+
}
211+
212+
fun ding(data:String?){
213+
this.puppet.ding(data)
214+
}
195215

196216
private fun initPuppetEventBridge(puppet: Puppet) {
197217

@@ -227,7 +247,7 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
227247
EventEnum.FRIENDSHIP -> {
228248
puppet.on(it, object : PuppetFriendshipListener {
229249
override fun handler(payload: EventFriendshipPayload) {
230-
val friendship = friendship().load(payload.friendshipId)
250+
val friendship = friendshipManager.load(payload.friendshipId)
231251
friendship.ready()
232252
emit(EventEnum.FRIENDSHIP, friendship)
233253
}
@@ -356,6 +376,11 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
356376
}
357377
}
358378

379+
380+
override fun toString():String{
381+
return "wechaty"
382+
}
383+
359384
companion object Factory {
360385
@JvmStatic
361386
fun instance(token: String): Wechaty {

wechaty/src/main/kotlin/io/github/wechaty/user/Contact.kt

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import io.github.wechaty.Accessory
44
import io.github.wechaty.Puppet
55
import io.github.wechaty.Wechaty
66
import io.github.wechaty.filebox.FileBox
7+
import io.github.wechaty.schemas.ContactGender
78
import io.github.wechaty.schemas.ContactPayload
89
import io.github.wechaty.schemas.ContactQueryFilter
10+
import io.github.wechaty.schemas.ContactType
911
import io.github.wechaty.type.Sayable
1012
import io.github.wechaty.utils.FutureUtils
1113
import org.apache.commons.lang3.StringUtils
1214
import org.slf4j.LoggerFactory
1315
import java.util.concurrent.CompletableFuture
1416
import java.util.concurrent.Future
17+
import kotlin.math.E
1518

1619
open class Contact(wechaty: Wechaty,val id:String) : Sayable, Accessory(wechaty) {
1720

@@ -114,8 +117,61 @@ open class Contact(wechaty: Wechaty,val id:String) : Sayable, Accessory(wechaty)
114117
return payload?.alias ?:null
115118
}
116119

117-
open fun avatar(): Future<FileBox> {
118-
TODO()
120+
fun stranger():Boolean?{
121+
return if(friend() == null){
122+
null
123+
}else{
124+
!friend()!!
125+
}
126+
}
127+
128+
fun friend():Boolean?{
129+
return payload?.friend
130+
}
131+
132+
fun type():ContactType{
133+
return payload?.type ?: throw Exception("no payload")
134+
}
135+
136+
fun gender():ContactGender{
137+
return payload?.gender ?: ContactGender.Unknown
138+
}
139+
140+
fun province():String?{
141+
return payload?.province
142+
}
143+
144+
fun city():String?{
145+
return payload?.city
146+
}
147+
148+
open fun avatar(): FileBox {
149+
try {
150+
return wechaty.getPuppet().getContactAvatar(this.id).get()
151+
} catch (e: Exception) {
152+
log.error("error",e)
153+
TODO()
154+
}
155+
}
156+
157+
fun tags():List<Tag>{
158+
val tagIdList = wechaty.getPuppet().tagContactList(this.id).get()
159+
return try {
160+
tagIdList.map {
161+
wechaty.tagManager.load(it)
162+
}
163+
} catch (e: Exception) {
164+
log.error("error",e)
165+
listOf()
166+
}
167+
}
168+
169+
fun self():Boolean{
170+
val userId = puppet.selfId()
171+
if(StringUtils.isEmpty(userId)){
172+
return false
173+
}
174+
return StringUtils.equals(id,userId)
119175
}
120176

121177

wechaty/src/main/kotlin/io/github/wechaty/user/ContactSelf.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,27 @@ import io.github.wechaty.filebox.FileBox
55
import java.util.concurrent.CompletableFuture
66
import java.util.concurrent.Future
77

8-
class ContactSelf(wechaty: Wechaty,id: String) : Contact(wechaty,id){
8+
class ContactSelf(wechaty: Wechaty, id: String) : Contact(wechaty, id) {
99

10-
override fun avatar(): Future<FileBox> {
11-
return super.avatar()
10+
fun avatar(fileBox: FileBox) {
11+
puppet.setContactAvatar(super.id, fileBox)
1212
}
1313

14-
fun avatar(fileBox:FileBox):Future<Void>{
15-
return CompletableFuture.supplyAsync {
16-
puppet.setContactAvatar(super.id, fileBox)
17-
null
14+
fun setName(name:String){
15+
puppet.contactSelfName(name).get()
16+
sync()
17+
}
18+
19+
fun signature(signature:String){
20+
21+
var puppetId:String? = puppet.selfId()
22+
23+
let{
24+
puppetId != null
25+
}.run {
26+
puppet.contactSelfSignature(signature).get()
27+
sync()
1828
}
1929

2030
}
21-
2231
}

wechaty/src/main/kotlin/io/github/wechaty/user/Friendship.kt

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,15 @@ import io.github.wechaty.Wechaty
55
import io.github.wechaty.schemas.FriendshipPayload
66
import io.github.wechaty.schemas.FriendshipSearchCondition
77
import io.github.wechaty.schemas.FriendshipType
8+
import io.github.wechaty.utils.JsonUtils
89
import org.apache.commons.lang3.StringUtils
910
import org.slf4j.LoggerFactory
1011

11-
class Friendship (wechaty: Wechaty):Accessory(wechaty){
12+
class Friendship (wechaty: Wechaty,val id:String):Accessory(wechaty){
1213

13-
constructor(wechaty: Wechaty,id: String):this(wechaty){
14-
this.id = id
15-
}
16-
17-
private var id:String? = null
1814

1915
private var payload:FriendshipPayload? = null
2016

21-
fun load(id:String):Friendship{
22-
this.id = id
23-
return this
24-
}
25-
26-
fun search(queryFilter: FriendshipSearchCondition):Contact?{
27-
val contactId = wechaty.getPuppet().friendshipSearch(queryFilter).get();
28-
if(StringUtils.isEmpty(contactId)){
29-
return null
30-
}
31-
val contact = wechaty.contactManager.load(contactId!!)
32-
contact.ready()
33-
return contact
34-
}
35-
36-
37-
fun add(contact: Contact, hello:String){
38-
log.debug("add contact: {} hello: {}",contact,hello)
39-
wechaty.getPuppet().friendshipAdd(contact.id!!,hello).get()
40-
}
41-
4217
fun isReady():Boolean{
4318
return payload != null
4419
}
@@ -67,17 +42,29 @@ class Friendship (wechaty: Wechaty):Accessory(wechaty){
6742
if(payload!!.type != FriendshipType.Receive){
6843
throw Exception("accept() need type to be FriendshipType.Receive, but it got a ${payload!!.type}")
6944
}
70-
71-
wechaty.getPuppet().friendshipAccept(this.id!!).get()
72-
45+
wechaty.getPuppet().friendshipAccept(this.id).get()
7346
val contact = contact()
74-
7547
contact.ready()
76-
7748
contact.sync()
49+
}
7850

51+
fun hello():String{
52+
if(payload==null){
53+
throw Exception("ne payload")
54+
}
55+
return this.payload?.hello ?: "";
56+
}
57+
58+
fun type():FriendshipType{
59+
return this.payload?.type ?:FriendshipType.Unknown
7960
}
8061

62+
fun toJson():String{
63+
if(payload==null){
64+
throw Exception("ne payload")
65+
}
66+
return JsonUtils.write(payload!!);
67+
}
8168

8269
companion object{
8370
private val log = LoggerFactory.getLogger(Friendship::class.java)

0 commit comments

Comments
 (0)