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

code clean

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