diff --git a/example/gist-bot/on-message.ts b/example/gist-bot/on-message.ts index 4c034d4dd5964d215096b8536f1f92bf1f01d2af..86190b3a0852500317f072c2dbdca883d12b08bb 100644 --- a/example/gist-bot/on-message.ts +++ b/example/gist-bot/on-message.ts @@ -6,8 +6,8 @@ * */ import { - Message - , Room + Message, + Room, } from '../../' export async function onMessage(message: Message): Promise { diff --git a/example/tuling123-bot.ts b/example/tuling123-bot.ts index 3bd74ed45a3b93123d0c8b2e023c04db443fb42c..9f82b8bc62dc05b89efb13a5ca05db4777845f70 100644 --- a/example/tuling123-bot.ts +++ b/example/tuling123-bot.ts @@ -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) } diff --git a/src/contact.ts b/src/contact.ts index 91057c5e87ea5b13941cbe748c6eb3d670485cde..b56bec701aad2319cc3eb1980cba74961cb6fa48 100644 --- a/src/contact.ts +++ b/src/contact.ts @@ -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 { 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): Promise { log.silly('Contact', 'ready(' + (contactGetter ? typeof contactGetter : '') + ')') if (!this.id) { diff --git a/src/io-client.ts b/src/io-client.ts index 935ac36cf187954c41765fee5370a255f21939e4..d510f610266e22fab3e193a18c9ea241978ef774 100644 --- a/src/io-client.ts +++ b/src/io-client.ts @@ -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() diff --git a/src/message-media.ts b/src/message-media.ts index 5237b1089b8a3487e9689329ca48abc205c3475d..70ecdc763090838189c10510f3eb9c89e7117f45 100644 --- a/src/message-media.ts +++ b/src/message-media.ts @@ -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 diff --git a/src/message.ts b/src/message.ts index e868d3931bf8c9a3a714945ca14eb85805901bf1..214d75c5bcab1e6209af02d042015a8efd45b69a 100644 --- a/src/message.ts +++ b/src/message.ts @@ -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 { log.silly('Message', 'ready()') diff --git a/src/room.ts b/src/room.ts index 45d6bce55b3717ff7e1519a750beeda52377430b..f47f93ebaf0d7c6785ef4cf96a5c12e4fe1d2ffd 100644 --- a/src/room.ts +++ b/src/room.ts @@ -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 { 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) { + // log.warn('Room', 'ready() DEPRECATED. use load() instad.') + // return this.load(contactGetter) + // } + public async ready(contactGetter?: (id: string) => Promise): Promise { log.silly('Room', 'ready(%s)', contactGetter ? contactGetter.constructor.name : '') if (!this.id) {