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

merge

......@@ -27,6 +27,10 @@ Wechaty is a Bot Framework for Wechat **Personal** Account which can help you cr
> @naishstar: thanks for great SDK [link](https://github.com/wechaty/wechaty/issues/57)
> @shevyan: 简单的接口...和Docker化的封装,结合Docker绝对是一个不错的选择 [link](http://mp.weixin.qq.com/s/o-4VMcAMz0K8yJVdNaUXow)
> @lijiarui: [Chat实录|李佳芮:向前一步的程序媛](http://mp.weixin.qq.com/s/dWHAj8XtiKG-1fIS5Og79g)
# Example
The shortest wechat bot code in the world: 6 lines JavaScript
......@@ -196,11 +200,11 @@ You can directly submit pull requests for documentation changes.
## Join us
Scanning the following QR Code in WeChat, with secret code 'wechaty', you can join our **Wechaty Developers' Home**.
Scan the following QR Code in WeChat, with secret code _wechaty_, you can join our **Wechaty Developers' Home**.
![Wechaty Developers' Home](https://raw.githubusercontent.com/wechaty/wechaty/master/image/BotQrcode.png)
Scan now, then chat with other Wechaty developers!
Scan now, then you can chat with other Wechaty developers!
# See Also
......
......@@ -8,7 +8,8 @@
*/
/* tslint:disable:variable-name */
const QrcodeTerminal = require('qrcode-terminal')
const QrcodeTerminal = require('qrcode-terminal')
const nodeCleanup = require('node-cleanup')
import {
Wechaty
......@@ -71,17 +72,15 @@ bot
})
bot.init()
.then(() => {
bot.say('Wechaty init')
})
.catch(e => {
log.error('Bot', 'init() fail: %s', e)
bot.quit()
process.exit(-1)
})
function logToFile(data) {
require('fs').appendFile('message.log', data + '\n\n#############################\n\n', err => {
if (err) { log.error('LogToFile: %s', err) }
})
}
if (typeof logToFile === 'fasdfsd') {
console.log('disable linting warning')
}
nodeCleanup(() => {
bot.say('Wechaty exit')
})
......@@ -35,26 +35,25 @@ bot
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
})
.on('login' , user => console.log(`${user} logined`))
.on('message', async function(this, m) {
console.log(`RECV: ${m}`)
.on('message', async function(this, msg) {
console.log(`RECV: ${msg}`)
if (m.type() !== MsgType.VOICE) {
if (msg.type() !== MsgType.VOICE) {
return // skip no-VOICE message
}
const mp3File = createWriteStream(m.filename())
const mp3Stream = await (msg as MediaMessage).readyStream()
const mp3Stream = await (m as MediaMessage).readyStream()
mp3Stream.pipe(mp3File)
const file = createWriteStream(msg.filename())
mp3Stream.pipe(file)
const text = await speechToText(mp3Stream)
console.log('VOICE TO TEXT: ' + text)
if (m.self()) {
if (msg.self()) {
this.say(text) // send text to 'filehelper'
} else {
m.say(text) // to original sender
msg.say(text) // to original sender
}
})
......
{
"name": "wechaty",
"version": "0.6.41",
"version": "0.6.42",
"description": "Wechat for Bot(Personal Account)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -35,7 +35,7 @@
"test:chrome:fast": "cross-env LC_ALL=C WECHATY_HEAD=chrome ava --fail-fast --timeout=3m \"dist/{src,test}/**/*.spec.js\"",
"testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --ext ts --serial --verbose --fail-fast --timeout=2m",
"testdist": "cross-env WECHATY_LOG=SILLY WECHATY_HEAD=chrome ava --ext ts --verbose --fail-fast --timeout=2m",
"ava": "cross-env LC_ALL=C WECHATY_LOG=verbose node_modules/.bin/ava",
"ava": "ava --extension ts",
"io-client": "ts-node bin/io-client",
"dev": "ts-node dev.ts",
"demo": "ts-node example/ding-dong-bot.ts",
......@@ -125,6 +125,7 @@
"eslint": "^3.4.0",
"eslint-plugin-ava": "^3.1.1",
"fluent-ffmpeg": "^2.1.0",
"node-cleanup": "^1.0.1",
"nyc": "^8.3.2",
"qrcode-terminal": "^0.10.0",
"request": "^2.79.0",
......
......@@ -186,7 +186,7 @@ export class Contact implements Sayable {
}
log.verbose('Cotnact', 'findAll({ name: %s })', query.name)
const nameFilter = query.name
let nameFilter = query.name
if (!nameFilter) {
throw new Error('nameFilter not found')
......@@ -201,6 +201,7 @@ export class Contact implements Sayable {
if (nameFilter instanceof RegExp) {
filterFunction = `(function (c) { return ${nameFilter.toString()}.test(c) })`
} else if (typeof nameFilter === 'string') {
nameFilter = nameFilter.replace(/'/g, '\\\'')
filterFunction = `(function (c) { return c === '${nameFilter}' })`
} else {
throw new Error('unsupport name type')
......
......@@ -141,6 +141,11 @@ export class BrowserDriver {
}
} catch (e) {
if (/could not be found/.test(e.message)) {
// The ChromeDriver could not be found on the current PATH
log.error('PuppetWebBrowserDriver', 'initChromeDriver() Wechaty require `chrome-driver` to be installed.')
throw e
}
log.warn('PuppetWebBrowserDriver', 'initChromeDriver() exception: %s, retry: %d', e.message, retry)
driverError = e
}
......
......@@ -720,7 +720,7 @@
})
}
function verifyUserOk(UserName, Ticket) {
function verifyUserOkAsync(UserName, Ticket) {
var callback = arguments[arguments.length - 1]
if (typeof callback !== 'function') {
// here we should in sync mode, because there's no callback
......@@ -827,8 +827,8 @@
, roomModTopic: roomModTopic
// for Friend Request
, verifyUserRequest: verifyUserRequest
, verifyUserOk: verifyUserOk
, verifyUserRequestAsync: verifyUserRequestAsync
, verifyUserOkAsync: verifyUserOkAsync
// , friendAdd
// , friendVerify
......
......@@ -415,7 +415,7 @@ export class Room extends EventEmitter implements Sayable {
}
log.verbose('Room', 'findAll({ topic: %s })', query.topic)
const topicFilter = query.topic
let topicFilter = query.topic
if (!topicFilter) {
throw new Error('topicFilter not found')
......@@ -426,6 +426,7 @@ export class Room extends EventEmitter implements Sayable {
if (topicFilter instanceof RegExp) {
filterFunction = `(function (c) { return ${topicFilter.toString()}.test(c) })`
} else if (typeof topicFilter === 'string') {
topicFilter = topicFilter.replace(/'/g, '\\\'')
filterFunction = `(function (c) { return c === '${topicFilter}' })`
} else {
throw new Error('unsupport topic type')
......
......@@ -31,6 +31,5 @@ test('Puppet Web Event smoking test', async t => {
await pw.quit()
} catch (e) {
t.fail('exception: ' + e.message)
throw e
}
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册