Skip to content

Commit

Permalink
Merge 5a7802b into d3aa251
Browse files Browse the repository at this point in the history
  • Loading branch information
lijiarui committed Aug 18, 2017
2 parents d3aa251 + 5a7802b commit 4997f25
Show file tree
Hide file tree
Showing 4 changed files with 796 additions and 56 deletions.
55 changes: 51 additions & 4 deletions src/contact.ts
Expand Up @@ -117,15 +117,24 @@ export class Contact implements Sayable {
}
}

/**
* @private
*/
public toString(): string {
if (!this.obj) {
return this.id
}
return this.obj.alias || this.obj.name || this.id
}

/**
* @private
*/
public toStringEx() { return `Contact(${this.obj && this.obj.name}[${this.id}])` }

/**
* @private
*/
private parse(rawObj: ContactRawObj): ContactObj | null {
if (!rawObj || !rawObj.UserName) {
log.warn('Contact', 'parse() got empty rawObj!')
Expand Down Expand Up @@ -195,7 +204,8 @@ export class Contact implements Sayable {
/**
* Check if contact is stranger
*
* @returns {boolean | null} True for not friend of the bot, False for friend of the bot, null for cannot get the info.
* @returns {boolean | null}
* True for not friend of the bot, False for friend of the bot, null for unknown.
*
* @example
* ```ts
Expand All @@ -210,7 +220,8 @@ export class Contact implements Sayable {
/**
* Check if it's a offical account
*
* @returns {boolean|null} True for official account, Flase for contact is not a official account
* @returns {boolean|null}
* True for official account, Flase for contact is not a official account, null for unknown
*
* @example
* ```ts
Expand Down Expand Up @@ -262,7 +273,8 @@ export class Contact implements Sayable {
/**
* Check if the contact is star contact.
*
* @returns {boolean} True for star friend, False for no star friend, null for cannot get the info.
* @returns {boolean}
* True for star friend, False for no star friend.
*
* @example
* ```ts
Expand Down Expand Up @@ -345,8 +357,14 @@ export class Contact implements Sayable {
}
}

/**
* @private
*/
public get(prop) { return this.obj && this.obj[prop] }

/**
* @private
*/
public isReady(): boolean {
return !!(this.obj && this.obj.id && this.obj.name)
}
Expand Down Expand Up @@ -379,6 +397,9 @@ export class Contact implements Sayable {
// return this.load()
// }

/**
* @private
*/
public async ready(contactGetter?: (id: string) => Promise<ContactRawObj>): Promise<this> {
log.silly('Contact', 'ready(' + (contactGetter ? typeof contactGetter : '') + ')')
if (!this.id) {
Expand Down Expand Up @@ -413,11 +434,17 @@ export class Contact implements Sayable {
}
}

/**
* @private
*/
public dumpRaw() {
console.error('======= dump raw contact =======')
Object.keys(this.rawObj).forEach(k => console.error(`${k}: ${this.rawObj[k]}`))
}

/**
* @private
*/
public dump() {
console.error('======= dump contact =======')
Object.keys(this.obj).forEach(k => console.error(`${k}: ${this.obj && this.obj[k]}`))
Expand Down Expand Up @@ -555,7 +582,8 @@ export class Contact implements Sayable {
* tests show it will failed if set alias too frequently(60 times in one minute).
*
* @param {string} newAlias
* @returns {Promise<boolean>} A promise to the result. true for success, false for failure
* @returns {Promise<boolean>}
* A promise to the result. true for success, false for failure
*
* @example
* ```ts
Expand Down Expand Up @@ -651,6 +679,9 @@ export class Contact implements Sayable {
})
}

/**
* @deprecated
*/
// function should be deprecated
public remark(newRemark?: string|null): Promise<boolean> | string | null {
log.warn('Contact', 'remark(%s) DEPRECATED, use alias(%s) instead.')
Expand Down Expand Up @@ -725,10 +756,26 @@ export class Contact implements Sayable {
*
* @example
* ```ts
* // change 'lijiarui' to any of your contact name in wechat
* const contact = await Contact.find({name: 'lijiarui'})
* await contact.say('welcome to wechaty!')
* ```
*/
public async say(text: string)

/**
* Send Media File to Contact
*
* @param {MediaMessage} mediaMessage
* @returns {Promise<boolean>}
* @example
* ```ts
* // change 'lijiarui' to any of your contact name in wechat
* const contact = await Contact.find({name: 'lijiarui'})
* // put the filePath you want to send here
* await contact.say(new MediaMessage(__dirname + '/wechaty.png')
* ```
*/
public async say(mediaMessage: MediaMessage)

public async say(textOrMedia: string | MediaMessage): Promise<boolean> {
Expand Down

0 comments on commit 4997f25

Please sign in to comment.