Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method in ContactSelf to update name and signature #1526

Merged
merged 31 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e9f000a
Merge pull request #1 from Chatie/master
windmemory Jun 28, 2018
49cf076
Merge remote-tracking branch 'upstream/master'
windmemory Jun 29, 2018
6eea213
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 2, 2018
0643d7d
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 3, 2018
0fed2d5
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 5, 2018
b4cf253
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 8, 2018
967c4bb
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 10, 2018
d2a3327
update padchat version
windmemory Jul 10, 2018
08aabbb
0.17.119
windmemory Jul 10, 2018
1a2bf23
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 12, 2018
c0e042e
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 18, 2018
c475857
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 20, 2018
33c4321
prototype for room-invite event
windmemory Jul 20, 2018
a35d958
Revert "prototype for room-invite event"
windmemory Jul 23, 2018
adafa89
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 23, 2018
f3f8111
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 24, 2018
c3e3046
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 24, 2018
6a86e1b
add data-ready event
windmemory Jul 24, 2018
396d866
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 26, 2018
7776bfa
add `ready` event and ready() method (https://github.com/Chatie/wecha…
huan Jul 26, 2018
26e85b7
make lint happy
huan Jul 26, 2018
889ded1
0.19.113
huan Jul 26, 2018
723c960
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Jul 26, 2018
910123e
Merge branch 'master' of https://github.com/botorange/wechaty
windmemory Jul 26, 2018
c7afcfc
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Aug 4, 2018
7562528
Merge branch 'master' of https://github.com/Chatie/wechaty
windmemory Aug 5, 2018
109060b
add method on contact-self to update name and signature
windmemory Aug 5, 2018
b46db18
change log and add comments for new method
windmemory Aug 6, 2018
ae80dc0
code clean
huan Aug 6, 2018
b982573
0.19.125
huan Aug 6, 2018
62cf890
Merge branch 'master' into master
huan Aug 6, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}
}