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

WIP: hostie

上级 a6943178
......@@ -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)
......@@ -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<void> {
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)
......
......@@ -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,
......
......@@ -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
......
......@@ -65,7 +65,9 @@ export class PuppetManager {
return puppetInstance
}
protected static async resolveName (puppetName: PuppetModuleName): Promise<PuppetImplementation> {
protected static async resolveName (
puppetName: PuppetModuleName,
): Promise<PuppetImplementation> {
log.verbose('PuppetManager', 'resolveName(%s)', puppetName)
if (!puppetName) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册