Skip to content

Commit

Permalink
Add method in ContactSelf to update name and signature (#1526)
Browse files Browse the repository at this point in the history
* update padchat version

* 0.17.119

* prototype for room-invite event

* Revert "prototype for room-invite event"

This reverts commit 33c4321.

* add data-ready event

* add `ready` event and ready() method (wechaty/puppet#7)

* make lint happy

* 0.19.113

* add method on contact-self to update name and signature

* change log and add comments for new method

* code clean

* 0.19.125
  • Loading branch information
windmemory authored and huan committed Aug 6, 2018
1 parent b86321e commit 535c93f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"read-pkg-up": "^4.0.0",
"state-switch": "^0.6.2",
"watchdog": "^0.8.1",
"wechaty-puppet": "^0.9.22",
"wechaty-puppet": "^0.11.3",
"ws": "^6.0.0"
},
"devDependencies": {
Expand Down
61 changes: 59 additions & 2 deletions src/user/contact-self.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,65 @@ export class ContactSelf extends Contact {
throw new Error('only can get qrcode for the login userself')
}

const qrcodeData = await this.puppet.contactQrcode(this.id)
return qrcodeData
const qrcodeValue = await this.puppet.contactSelfQrcode()
return qrcodeValue
}

/**
* Change bot name
*
* @param name The new name that the bot will change to
*
* @example
* bot.on('login', async user => {
* console.log(`user ${user} login`)
* const oldName = user.name()
* try {
* await user.setName(`${oldName}-${new Date().getTime()}`)
* } catch (e) {
* console.error('change name failed', e)
* }
* })
*/
public name (): string
public name (name: string): Promise<void>

public name (name?: string): string | Promise<void> {
log.verbose('ContactSelf', 'name(%s)', name)

if (typeof name === 'undefined') {
return super.name()
}

if (this.id !== this.puppet.selfId()) {
throw new Error('only can set name for user self')
}

return this.puppet.contactSelfName(name)
}

/**
* Change bot signature
*
* @param signature The new signature that the bot will change to
*
* @example
* bot.on('login', async user => {
* console.log(`user ${user} login`)
* try {
* await user.signature(`Signature changed by wechaty on ${new Date()}`)
* } catch (e) {
* console.error('change signature failed', e)
* }
* })
*/
public async signature (signature: string): Promise<void> {
log.verbose('ContactSelf', 'signature()')

if (this.id !== this.puppet.selfId()) {
throw new Error('only can change signature for user self')
}

return this.puppet.contactSelfSignature(signature)
}
}

0 comments on commit 535c93f

Please sign in to comment.