提交 8a6d0b14 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 d0558592
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
* *
*/ */
import { import {
Message Message,
, Room Room,
} from '../../' } from '../../'
export async function onMessage(message: Message): Promise<void> { export async function onMessage(message: Message): Promise<void> {
......
...@@ -57,16 +57,16 @@ bot ...@@ -57,16 +57,16 @@ bot
} }
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `) console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
}) })
.on('message', async m => { .on('message', async msg => {
if (m.self()) return if (msg.self()) return
try { try {
const msg = await m.ready() // const msg = await m.load()
const room = m.room() const room = msg.room()
if (room && /Wechaty/i.test(room.topic())) { if (room && /Wechaty/i.test(room.topic())) {
log.info('Bot', 'talk: %s' , msg) log.info('Bot', 'talk: %s' , msg)
talk(m) talk(msg)
} else { } else {
log.info('Bot', 'recv: %s' , msg) log.info('Bot', 'recv: %s' , msg)
} }
......
...@@ -107,6 +107,11 @@ export class Contact implements Sayable { ...@@ -107,6 +107,11 @@ export class Contact implements Sayable {
return !!(this.obj && this.obj.id && this.obj.name !== undefined) return !!(this.obj && this.obj.id && this.obj.name !== undefined)
} }
// public refresh() {
// log.warn('Contact', 'refresh() DEPRECATED. use reload() instead.')
// return this.reload()
// }
public async refresh(): Promise<this> { public async refresh(): Promise<this> {
if (this.isReady()) { if (this.isReady()) {
this.dirtyObj = this.obj this.dirtyObj = this.obj
...@@ -115,6 +120,11 @@ export class Contact implements Sayable { ...@@ -115,6 +120,11 @@ export class Contact implements Sayable {
return this.ready() return this.ready()
} }
// public ready() {
// log.warn('Contact', 'ready() DEPRECATED. use load() instead.')
// return this.load()
// }
public async ready(contactGetter?: (id: string) => Promise<ContactRawObj>): Promise<this> { public async ready(contactGetter?: (id: string) => Promise<ContactRawObj>): Promise<this> {
log.silly('Contact', 'ready(' + (contactGetter ? typeof contactGetter : '') + ')') log.silly('Contact', 'ready(' + (contactGetter ? typeof contactGetter : '') + ')')
if (!this.id) { if (!this.id) {
......
...@@ -99,11 +99,7 @@ export class IoClient { ...@@ -99,11 +99,7 @@ export class IoClient {
.on('login' , user => this.log.info('IoClient', `${user.name()} logined`)) .on('login' , user => this.log.info('IoClient', `${user.name()} logined`))
.on('logout' , user => this.log.info('IoClient', `${user.name()} logouted`)) .on('logout' , user => this.log.info('IoClient', `${user.name()} logouted`))
.on('scan', (url, code) => this.log.info('IoClient', `[${code}] ${url}`)) .on('scan', (url, code) => this.log.info('IoClient', `[${code}] ${url}`))
.on('message' , message => { .on('message' , msg => this.onMessage(msg))
message.ready()
.then(this.onMessage.bind(this))
.catch(e => this.log.error('IoClient', 'message.ready() %s' , e))
})
try { try {
await wechaty.init() await wechaty.init()
......
...@@ -74,6 +74,7 @@ export class MediaMessage extends Message { ...@@ -74,6 +74,7 @@ export class MediaMessage extends Message {
default: default:
const e = new Error('ready() unsupported typeApp(): ' + this.typeApp()) const e = new Error('ready() unsupported typeApp(): ' + this.typeApp())
log.warn('MediaMessage', e.message) log.warn('MediaMessage', e.message)
this.dumpRaw()
throw e throw e
} }
break break
......
...@@ -404,6 +404,11 @@ export class Message implements Sayable { ...@@ -404,6 +404,11 @@ export class Message implements Sayable {
return fromId === userId return fromId === userId
} }
// public ready() {
// log.warn('Message', 'ready() DEPRECATED. use load() instead.')
// return this.ready()
// }
public async ready(): Promise<void> { public async ready(): Promise<void> {
log.silly('Message', 'ready()') log.silly('Message', 'ready()')
......
...@@ -71,6 +71,11 @@ export class Room extends EventEmitter implements Sayable { ...@@ -71,6 +71,11 @@ export class Room extends EventEmitter implements Sayable {
return !!(this.obj && this.obj.memberList && this.obj.memberList.length) return !!(this.obj && this.obj.memberList && this.obj.memberList.length)
} }
// public refresh() {
// log.warn('Room', 'refresh() DEPRECATED. use reload() instead.')
// return this.reload()
// }
public async refresh(): Promise<void> { public async refresh(): Promise<void> {
if (this.isReady()) { if (this.isReady()) {
this.dirtyObj = this.obj this.dirtyObj = this.obj
...@@ -80,6 +85,11 @@ export class Room extends EventEmitter implements Sayable { ...@@ -80,6 +85,11 @@ export class Room extends EventEmitter implements Sayable {
return return
} }
// public ready(contactGetter?: (id: string) => Promise<any>) {
// log.warn('Room', 'ready() DEPRECATED. use load() instad.')
// return this.load(contactGetter)
// }
public async ready(contactGetter?: (id: string) => Promise<any>): Promise<void> { public async ready(contactGetter?: (id: string) => Promise<any>): Promise<void> {
log.silly('Room', 'ready(%s)', contactGetter ? contactGetter.constructor.name : '') log.silly('Room', 'ready(%s)', contactGetter ? contactGetter.constructor.name : '')
if (!this.id) { if (!this.id) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册