Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lijiarui authored and huan committed Jul 23, 2018
1 parent 2d3f57d commit 79df809
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/generate-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ else
echo "Generating docs ..."
npm run dist
echo -e '# Wechaty v'$(jq -r .version package.json)' Documentation\n\n* <https://blog.chatie.io>\n\n' > docs/index.md
jsdoc2md dist/src/wechaty.js dist/src/user/{room,contact,friendship,message}.js >> docs/index.md
jsdoc2md dist/src/wechaty.js dist/src/user/{room,contact,contact-self,friendship,message}.js >> docs/index.md
fi
52 changes: 52 additions & 0 deletions src/user/contact-self.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ import {
Contact,
} from './contact'

/**
* Bot itself will be encapsulated as a ContactSelf.
*
* > Tips: this class is extends Contact
* @example
* const bot = new Wechaty()
* await bot.start()
* bot.on('login', (user: ContactSelf) => {
* console.log(`user ${user} login`)
* })
*/
export class ContactSelf extends Contact {
constructor (
id: string,
Expand All @@ -37,6 +48,33 @@ export class ContactSelf extends Contact {
public async avatar () : Promise<FileBox>
public async avatar (file: FileBox) : Promise<void>

/**
* GET / SET bot avatar
*
* @param {FileBox} [file]
* @returns {(Promise<void | FileBox>)}
*
* @example <caption> GET the avatar for bot, return {Promise<FileBox>}</caption>
* // Save avatar to local file like `1-name.jpg`
*
* bot.on('login', (user: ContactSelf) => {
* console.log(`user ${user} login`)
* const file = await user.avatar()
* const name = file.name
* await file.toFile(name, true)
* console.log(`Save bot avatar: ${contact.name()} with avatar file: ${name}`)
* })
*
* @example <caption>SET the avatar for a bot</caption>
* import { FileBox } from 'file-box'
* bot.on('login', (user: ContactSelf) => {
* console.log(`user ${user} login`)
* const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
* await user.avatar(fileBox)
* console.log(`Change bot avatar successfully!`)
* })
*
*/
public async avatar (file?: FileBox): Promise<void | FileBox> {
log.verbose('Contact', 'avatar(%s)', file ? file.name : '')

Expand All @@ -52,6 +90,20 @@ export class ContactSelf extends Contact {
await this.puppet.contactAvatar(this.id, file)
}

/**
* Get bot qrcode
*
* @returns {Promise<string>}
*
* @example
* import { generate } from 'qrcode-terminal'
* bot.on('login', (user: ContactSelf) => {
* console.log(`user ${user} login`)
* const qrcode = await user.qrcode()
* console.log(`Following is the bot qrcode!`)
* generate(qrcode, { small: true })
* })
*/
public async qrcode (): Promise<string> {
log.verbose('Contact', 'qrcode()')

Expand Down

0 comments on commit 79df809

Please sign in to comment.