提交 3314f4f8 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)
上级 f1f2b2d7
......@@ -44,7 +44,7 @@ __________________________________________________
`
async function main () {
let token = config.token
const token = config.token
if (!token) {
throw new Error('token not found: please set WECHATY_TOKEN in environment before run io-client')
......
......@@ -35,7 +35,7 @@ export class Doctor {
const spawn = require('child_process').spawnSync
let version: string
try {
const cmd = spawn('chromedriver', [ '--version' ])
const cmd = spawn('chromedriver', ['--version'])
version = cmd.error || cmd.stdout.toString() || cmd.stderr.toString()
} catch (e) {
version = e.message
......@@ -49,7 +49,7 @@ export class Doctor {
public testTcp (): Promise<boolean> {
log.verbose('Doctor', 'testTcp()')
return new Promise<boolean>(async (resolve, reject) => {
return new Promise<boolean>((resolve, reject) => {
/**
* Server
*/
......
......@@ -38,6 +38,7 @@ test('stripHtml()', async t => {
test('unescapeHtml()', async t => {
const HTML_BEFORE_UNESCAPE = '&apos;|&quot;|&gt;|&lt;|&amp;'
// eslint-disable-next-line
const HTML_AFTER_UNESCAPE = `'|"|>|<|&`
const unescapedHtml = unescapeHtml(HTML_BEFORE_UNESCAPE)
......
......@@ -256,20 +256,28 @@ export class Io {
switch (ioEvent.name) {
case 'botie':
const payload = ioEvent.payload
if (payload.onMessage) {
const script = payload.script
try {
/* eslint-disable-next-line */
const fn = eval(script)
if (typeof fn === 'function') {
this.onMessage = fn
} else {
log.warn('Io', 'server pushed function is invalid')
{
const payload = ioEvent.payload
if (payload.onMessage) {
const script = payload.script
try {
/**
* https://github.com/Chatie/botie/issues/2
* const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
* const fn = new AsyncFunction('require', 'github', 'context', script)
*/
// eslint-disable-next-line
const fn = eval(script)
if (typeof fn === 'function') {
this.onMessage = fn
} else {
log.warn('Io', 'server pushed function is invalid')
}
} catch (e) {
log.warn('Io', 'server pushed function exception: %s', e)
this.options.wechaty.emit('error', e)
}
} catch (e) {
log.warn('Io', 'server pushed function exception: %s', e)
this.options.wechaty.emit('error', e)
}
}
break
......@@ -287,25 +295,26 @@ export class Io {
case 'update':
log.verbose('Io', 'on(update): %s', ioEvent.payload)
const wechaty = this.options.wechaty
if (wechaty.logonoff()) {
const loginEvent: IoEvent = {
name : 'login',
payload : {
id : wechaty.userSelf().id,
name : wechaty.userSelf().name(),
},
{
const wechaty = this.options.wechaty
if (wechaty.logonoff()) {
const loginEvent: IoEvent = {
name : 'login',
payload : {
id : wechaty.userSelf().id,
name : wechaty.userSelf().name(),
},
}
await this.send(loginEvent)
}
await this.send(loginEvent)
}
if (this.scanPayload) {
const scanEvent: IoEventScan = {
name: 'scan',
payload: this.scanPayload,
if (this.scanPayload) {
const scanEvent: IoEventScan = {
name: 'scan',
payload: this.scanPayload,
}
await this.send(scanEvent)
}
await this.send(scanEvent)
}
break
......
......@@ -192,9 +192,9 @@ export class PuppetManager {
}
// https://github.com/GoogleChrome/puppeteer/issues/1597#issuecomment-351945645
if (gfw && !process.env['PUPPETEER_DOWNLOAD_HOST']) {
if (gfw && !process.env.PUPPETEER_DOWNLOAD_HOST) {
log.info('PuppetManager', 'preInstallPuppeteer() set PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors/')
process.env['PUPPETEER_DOWNLOAD_HOST'] = 'https://npm.taobao.org/mirrors/'
process.env.PUPPETEER_DOWNLOAD_HOST = 'https://npm.taobao.org/mirrors/'
}
}
......
......@@ -63,6 +63,7 @@ export class Contact extends Accessory implements Sayable {
protected static get pool () {
return this[POOL]
}
protected static set pool (newPool: Map<string, Contact>) {
if (this === Contact) {
throw new Error(
......@@ -753,7 +754,7 @@ export class Contact extends Accessory implements Sayable {
// log.silly('Contact', `ready() this.puppet.contactPayload(%s) resolved`, this)
} catch (e) {
log.verbose('Contact', `ready() this.puppet.contactPayload(%s) exception: %s`,
log.verbose('Contact', 'ready() this.puppet.contactPayload(%s) exception: %s',
this.id,
e.message,
)
......
......@@ -78,7 +78,7 @@ test('recalled()', async t => {
sandbox.stub(puppet, 'roomMemberList').callsFake(async () => {
await new Promise((resolve) => setImmediate(resolve))
return [ EXPECTED_FROM_CONTACT_ID, EXPECTED_TO_CONTACT_ID ]
return [EXPECTED_FROM_CONTACT_ID, EXPECTED_TO_CONTACT_ID]
})
sandbox.stub(puppet, 'contactPayload').callsFake(async (id: string) => {
......
......@@ -309,7 +309,7 @@ export class RoomInvitation extends Accessory implements Acceptable {
* .start()
*/
public async toJSON (): Promise<string> {
log.verbose('RoomInvitation', `toJSON()`)
log.verbose('RoomInvitation', 'toJSON()')
const payload = await this.puppet.roomInvitationPayload(this.id)
return JSON.stringify(payload)
}
......
......@@ -614,7 +614,7 @@ export class Room extends Accessory implements Sayable {
const textListLength = textList.length
const varListLength = varList.length
if (textListLength - varListLength !== 1) {
throw new Error(`Can not say message, invalid Templated String Array.`)
throw new Error('Can not say message, invalid Templated String Array.')
}
let finalText = ''
......
......@@ -93,7 +93,7 @@ import {
export const WECHATY_EVENT_DICT = {
...CHAT_EVENT_DICT,
dong : 'Should be emitted after we call `Wechaty.ding()`',
error : `Will be emit when there's an Error occurred.`,
error : "Will be emit when there's an Error occurred.",
heartbeat : 'Will be emited periodly after the Wechaty started. If not, means that the Wechaty had died.',
ready : 'All underlined data source are ready for use.',
start : 'Will be emitted after the Wechaty had been started.',
......@@ -505,11 +505,11 @@ export class Wechaty extends Accessory implements Sayable {
// DEPRECATED for 'friend' event
if (event as any === 'friend') {
log.warn('Wechaty', `on('friend', contact, friendRequest) is DEPRECATED. use on('friendship', friendship) instead`)
log.warn('Wechaty', "on('friend', contact, friendRequest) is DEPRECATED. use on('friendship', friendship) instead")
if (typeof listener === 'function') {
const oldListener = listener
listener = (...args: any[]) => {
log.warn('Wechaty', `on('friend', contact, friendRequest) is DEPRECATED. use on('friendship', friendship) instead`)
log.warn('Wechaty', "on('friend', contact, friendRequest) is DEPRECATED. use on('friendship', friendship) instead")
oldListener.apply(this, args)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册