From a53e2a6d5f58372a41b4d788e6f57af7cf3d99fb Mon Sep 17 00:00:00 2001 From: NickWang Date: Tue, 21 Nov 2023 01:20:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20aka=20and=20realname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- src/user-modules/contact-self.ts | 34 ++++++++++++++++++++++++++++++++ src/user-modules/contact.ts | 8 ++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b2b0d08b1..fc2b7760b 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ }, "homepage": "https://github.com/wechaty/", "dependencies": { - "@juzi/wechaty-puppet-service": "^1.0.81", + "@juzi/wechaty-puppet-service": "^1.0.82", "clone-class": "^1.1.1", "cmd-ts": "^0.10.0", "cockatiel": "^2.0.2", @@ -132,7 +132,7 @@ "@chatie/eslint-config": "^1.0.4", "@chatie/semver": "^0.4.7", "@chatie/tsconfig": "^4.6.3", - "@juzi/wechaty-puppet": "^1.0.69", + "@juzi/wechaty-puppet": "^1.0.71", "@juzi/wechaty-puppet-mock": "^1.0.1", "@swc/core": "1.3.44", "@swc/helpers": "^0.3.6", diff --git a/src/user-modules/contact-self.ts b/src/user-modules/contact-self.ts index a9a3f7974..62cb136f9 100644 --- a/src/user-modules/contact-self.ts +++ b/src/user-modules/contact-self.ts @@ -175,6 +175,40 @@ class ContactSelfMixin extends MixinBase { return this.wechaty.puppet.contactSelfName(name).then(this.sync.bind(this)) } + public override realName (): string + public override realName (realName: string): Promise + + public override realName (realName?: string): string | Promise { + log.verbose('ContactSelf', 'realName(%s)', realName || '') + + if (typeof realName === 'undefined') { + return super.realName() + } + + if (this.id !== this.wechaty.puppet.currentUserId) { + throw new Error('only can set realName for user self') + } + + return this.wechaty.puppet.contactSelfRealName(realName).then(this.sync.bind(this)) + } + + public override aka (): string + public override aka (aka: string): Promise + + public override aka (aka?: string): string | Promise { + log.verbose('ContactSelf', 'aka(%s)', aka || '') + + if (typeof aka === 'undefined') { + return super.aka() + } + + if (this.id !== this.wechaty.puppet.currentUserId) { + throw new Error('only can set aka for user self') + } + + return this.wechaty.puppet.contactSelfAka(aka).then(this.sync.bind(this)) + } + /** * Change bot signature * diff --git a/src/user-modules/contact.ts b/src/user-modules/contact.ts index 2e5a85e01..f456f8c4b 100644 --- a/src/user-modules/contact.ts +++ b/src/user-modules/contact.ts @@ -396,6 +396,14 @@ class ContactMixin extends MixinBase implements SayableSayer { return (this.payload && this.payload.name) || '' } + aka (): string { + return (this.payload && this.payload.aka) || '' + } + + realName (): string { + return (this.payload && this.payload.realName) || '' + } + async alias () : Promise async alias (newAlias: string) : Promise async alias (empty: null) : Promise