@@ -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 {
0 commit comments