diff --git a/bin/io-client.ts b/bin/io-client.ts index ae4e53ae676e9235855a9761fc746d5febcd491f..b7087edbeeb7cdbcabf1e46535b716873557fee6 100644 --- a/bin/io-client.ts +++ b/bin/io-client.ts @@ -43,22 +43,26 @@ __________________________________________________ ` -let token = config.token +async function main () { + let token = config.token -if (!token) { - throw new Error('token not found: please set WECHATY_TOKEN in environment before run io-client') -} + if (!token) { + throw new Error('token not found: please set WECHATY_TOKEN in environment before run io-client') + } + + console.info(welcome) + log.info('Client', 'Starting for WECHATY_TOKEN: %s', token) -console.info(welcome) -log.info('Client', 'Starting for WECHATY_TOKEN: %s', token) + const wechaty = new Wechaty({ name: token }) -const client = new IoClient({ - token, - wechaty: new Wechaty({ name: token }), -}) + const client = new IoClient({ + token, + wechaty, + }) -client.start() - .catch(onError.bind(client)) + client.start() + .catch(onError.bind(client)) +} async function onError ( this : IoClient, @@ -68,3 +72,6 @@ async function onError ( await this.quit() process.exit(-1) } + +main() + .catch(console.error) diff --git a/package.json b/package.json index 034304c8037f28a2f9e4e07e0cca1eb8596bd41c..eab04204972f674ab2c9379b61a021b05e77bb21 100644 --- a/package.json +++ b/package.json @@ -97,8 +97,8 @@ "read-pkg-up": "^7.0.0", "state-switch": "^0.6.2", "watchdog": "^0.8.1", - "wechaty-puppet": "^0.19.6", - "wechaty-puppet-hostie": "^0.3.8", + "wechaty-puppet": "^0.19.12", + "wechaty-puppet-hostie": "^0.3.13", "ws": "^7.0.0" }, "devDependencies": { diff --git a/src/io-client.ts b/src/io-client.ts index 4c6c9d5b74ed87dc25ac1e03e1dbd4b56f463607..2ae6b98e691de0643fb2d11141d9d315db6f3af7 100644 --- a/src/io-client.ts +++ b/src/io-client.ts @@ -52,7 +52,9 @@ export class IoClient { constructor ( public options: IoClientOptions, ) { - log.verbose('IoClient', 'constructor(%s)', JSON.stringify(options)) + log.verbose('IoClient', 'constructor({token: %s})', + options.token + ) this.state = new StateSwitch('IoClient', log) } @@ -85,7 +87,7 @@ export class IoClient { } public async start (): Promise { - log.verbose('IoClient', 'init()') + log.verbose('IoClient', 'start()') if (this.state.pending()) { log.warn('IoClient', 'start() with a pending state, not the time') @@ -99,12 +101,14 @@ export class IoClient { await this.hookWechaty(this.options.wechaty) await this.startIo() + + await this.options.wechaty.start() await this.startHostie() this.state.on(true) } catch (e) { - log.error('IoClient', 'init() exception: %s', e.message) + log.error('IoClient', 'start() exception: %s', e.message) this.state.off(true) throw e } @@ -191,6 +195,7 @@ export class IoClient { await this.stopIo() await this.stopHostie() + await this.options.wechaty.stop() this.state.off(true) diff --git a/src/io.ts b/src/io.ts index 07f61196a1abe59f39827a4ff5ad9a3e2b1a7136..37fc7ec2256ade05c76a6fed9ddc0b6e38a3dc0b 100644 --- a/src/io.ts +++ b/src/io.ts @@ -24,8 +24,8 @@ import { } from './user' import { - PuppetQrcodeScanEvent, -} from 'wechaty-puppet' + PuppetQRCodeScanEvent, +} from 'wechaty-puppet' import { config, @@ -64,7 +64,7 @@ type IoEventName = keyof typeof IO_EVENT_DICT interface IoEventScan { name : 'scan', - payload : PuppetQrcodeScanEvent, + payload : PuppetQRCodeScanEvent, } interface IoEventAny { @@ -90,7 +90,7 @@ export class Io { private onMessage: undefined | AnyFunction - private scanPayload?: PuppetQrcodeScanEvent + private scanPayload?: PuppetQRCodeScanEvent constructor ( private options: IoOptions, diff --git a/src/puppet-config.ts b/src/puppet-config.ts index 76bed2f27d25154fd4c293b688125825f244d8e6..c78b8a1efe06f2674cccd18b206ad2a5554439da 100644 --- a/src/puppet-config.ts +++ b/src/puppet-config.ts @@ -14,7 +14,7 @@ export const PUPPET_DEPENDENCIES = { // 'wechaty-puppet-hostie' : '^0.0.1', // 'wechaty-puppet-dll' : '^0.3.1', // https://www.npmjs.com/package/wechaty-puppet-dll - 'wechaty-puppet-hostie' : '^0.3.8', // https://www.npmjs.com/package/wechaty-puppet-hostie + 'wechaty-puppet-hostie' : '^0.3.13', // https://www.npmjs.com/package/wechaty-puppet-hostie // 'wechaty-puppet-ioscat' : '^0.5.22', // https://www.npmjs.com/package/wechaty-puppet-ioscat 'wechaty-puppet-mock' : '^0.16.1', // https://www.npmjs.com/package/wechaty-puppet-mock // 'wechaty-puppet-padchat' : '^0.19.3', // https://www.npmjs.com/package/wechaty-puppet-padchat diff --git a/src/puppet-manager.ts b/src/puppet-manager.ts index 13cbee6879d59dd06d9fa2db78d73e327c1d5afe..e5557fba460517c4d130644f8fc65f9267a46b0a 100644 --- a/src/puppet-manager.ts +++ b/src/puppet-manager.ts @@ -65,7 +65,9 @@ export class PuppetManager { return puppetInstance } - protected static async resolveName (puppetName: PuppetModuleName): Promise { + protected static async resolveName ( + puppetName: PuppetModuleName, + ): Promise { log.verbose('PuppetManager', 'resolveName(%s)', puppetName) if (!puppetName) {