Skip to content

Commit a9d0ad2

Browse files
committed
1. Contact.kt添加type,province等一系列方法
2. Message.kt添加date,forward等方法 3. 添加say方法 4. 还未测试
1 parent 9fe61a1 commit a9d0ad2

File tree

6 files changed

+81
-5
lines changed

6 files changed

+81
-5
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package io.github.wechaty;
44
import io.github.wechaty.eventEmitter.Event
55
import io.github.wechaty.eventEmitter.EventEmitter
66
import io.github.wechaty.eventEmitter.Listener
7+
import io.github.wechaty.filebox.FileBox
78
import io.github.wechaty.io.github.wechaty.schemas.EventEnum
89
import io.github.wechaty.listener.*
910
import io.github.wechaty.memorycard.MemoryCard
@@ -13,6 +14,8 @@ import io.github.wechaty.user.*
1314
import io.github.wechaty.user.manager.*
1415
import org.slf4j.LoggerFactory
1516
import java.util.*
17+
import java.util.concurrent.CompletableFuture
18+
import java.util.concurrent.Future
1619
import java.util.concurrent.locks.ReentrantLock
1720

1821
val PUPPET_MEMORY_NAME = "puppet"
@@ -82,6 +85,34 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
8285
return wechatyOptions.name
8386
}
8487

88+
fun say(something: Any): Future<Void> {
89+
90+
val msgId: String?
91+
this.puppet.selfId()?.let {
92+
when (something) {
93+
is String -> {
94+
msgId = puppet.messageSendText(it, something).get()
95+
}
96+
is Contact -> {
97+
msgId = puppet.messageSendContact(it, something.id).get()
98+
}
99+
is FileBox -> {
100+
msgId = puppet.messageSendFile(it, something).get()
101+
}
102+
is UrlLink -> {
103+
msgId = puppet.messageSendUrl(it, something.payload).get()
104+
}
105+
is MiniProgram -> {
106+
msgId = puppet.messageSendMiniProgram(it, something.payload).get()
107+
}
108+
else -> {
109+
throw Exception("unsupported arg:$something")
110+
}
111+
}
112+
return@let
113+
}
114+
return CompletableFuture.completedFuture(null)
115+
}
85116
fun onLogin(listener: LoginListener):Wechaty{
86117
return on(EventEnum.LOGIN,listener)
87118
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ 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
@@ -94,6 +96,29 @@ open class Contact(wechaty: Wechaty,val id:String) : Sayable, Accessory(wechaty)
9496
fun name():String{
9597
return payload?.name ?: ""
9698
}
99+
fun type(): ContactType {
100+
return payload?.type ?: ContactType.Unknown
101+
}
102+
fun gender(): ContactGender {
103+
return payload?.gender ?: ContactGender.Unknown
104+
}
105+
106+
fun province(): String? {
107+
return payload?.province
108+
}
109+
110+
fun city(): String? {
111+
return payload?.city
112+
}
113+
114+
fun self(): Boolean {
115+
val userId = this.puppet.selfId()
116+
117+
if (userId == null) {
118+
return false
119+
}
120+
return this.id === userId
121+
}
97122

98123
fun setAlias(newAlias:String){
99124
if(payload == null){

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class ContactSelf(wechaty: Wechaty,id: String) : Contact(wechaty,id){
1818
puppet.setContactAvatar(super.id, fileBox)
1919
null
2020
}
21-
2221
}
2322

2423
fun qrcode(): Future<String> {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import io.github.wechaty.schemas.MessagePayload
77
import io.github.wechaty.schemas.MessageType
88
import io.github.wechaty.schemas.RoomMemberQueryFilter
99
import io.github.wechaty.type.Sayable
10+
import io.grpc.netty.shaded.io.netty.util.concurrent.CompleteFuture
1011
import org.apache.commons.collections4.CollectionUtils
1112
import org.apache.commons.lang3.StringUtils
1213
import org.slf4j.LoggerFactory
14+
import java.util.*
1315
import java.util.concurrent.CompletableFuture
1416
import java.util.concurrent.Future
1517
import java.util.regex.Pattern
@@ -124,6 +126,28 @@ open class Message(wechaty: Wechaty,val id: String) : Sayable, Accessory(wechaty
124126
return StringUtils.equals(selfId,from?.id)
125127
}
126128

129+
fun date(): Date {
130+
val payload = wechaty.getPuppet().messagePayload(this.id).get()
131+
return Date(payload.timestamp!! * 1000)
132+
}
133+
134+
fun forward(to: Any): Future<Void> {
135+
log.debug("Message, forward({})", to)
136+
when(to) {
137+
is Room -> {
138+
this.puppet.messageForward(to.id, this.id).get()
139+
}
140+
is Contact -> {
141+
this.puppet.messageForward(to.id, this.id).get()
142+
}
143+
else -> {
144+
throw Exception("unkown forward type")
145+
}
146+
}
147+
return CompletableFuture.completedFuture(null)
148+
}
149+
150+
127151
fun mentionList():List<Contact>{
128152
val room = this.room()
129153

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MiniProgram(var payload: MiniProgramPayload) {
3535

3636
companion object{
3737

38-
fun create():MiniProgram{
38+
fun create(): MiniProgram {
3939
val payload = MiniProgramPayload()
4040
return MiniProgram(payload);
4141
}

wechaty/src/main/kotlin/io/github/wechaty/user/manager/ContactManager.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ class ContactManager(wechaty: Wechaty):Accessory(wechaty) {
3030

3131
}
3232

33-
34-
35-
3633
fun find(queryFilter: ContactQueryFilter):Contact?{
3734

3835
val findAll = findAll(queryFilter)

0 commit comments

Comments
 (0)