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

Merge branch 'master' of github.com:zixia/wechaty

......@@ -16,17 +16,6 @@ Supports [linux](https://travis-ci.org/zixia/wechaty), [win32](https://ci.appvey
[![npm version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty)
[![Downloads][downloads-image]][downloads-url]
# Why
My daily life/work depends on too much chat on wechat.
* I almost have 14,000 wechat friends till May 2014, before wechat restricts a total number of friends to 5,000.
* I almost have 400 wechat rooms that most of them have more than 400 members.
Can you image that? I'm dying...
So a tireless bot working for me 24x7 on wechat, moniting/filtering the most important message is badly needed. For example: highlights discusstion which contains the KEYWORDS I want to follow up(especially in a noisy room). ;-)
At last, It's built for my personal study purpose of Automatically Testing.
# Examples
Wechaty is super easy to use: 10 lines of javascript is enough for your first wechat robot.
......@@ -163,6 +152,12 @@ Win32:
set WECHATY_DEBUG=verbose
```
Tips: You would love to have more scroll buffer size in your CMD window in windows.
```shell
mode con lines=32766
```
> http://stackoverflow.com/a/8775884/1123955
# Requirement
ECMAScript2015(ES6). I develop and test wechaty with Node.js v6.0.
......@@ -473,6 +468,18 @@ Github Issue - https://github.com/zixia/wechaty/issues
## Framework
1. [Bot Framework](https://dev.botframework.com/) Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services. from Microsoft
Why
----------------
My daily life/work depends on too much chat on wechat.
* I almost have 14,000 wechat friends till May 2014, before wechat restricts a total number of friends to 5,000.
* I almost have 400 wechat rooms that most of them have more than 400 members.
Can you image that? I'm dying...
So a tireless bot working for me 24x7 on wechat, moniting/filtering the most important message is badly needed. For example: highlights discusstion which contains the KEYWORDS I want to follow up(especially in a noisy room). ;-)
At last, It's built for my personal study purpose of Automatically Testing.
Author
-----------------
Zhuohuan LI <zixia@zixia.net> (http://linkedin.com/in/zixia)
......
......@@ -21,10 +21,12 @@
"account",
"bot",
"robot",
"chatbot",
"framework",
"library",
"api",
"sdk"
"wechaty",
"微信控"
],
"author": "Zhuohuan LI <zixia@zixia.net>",
"license": "ISC",
......
......@@ -99,6 +99,16 @@ Contact.load = function(id) {
}
return Contact.pool[id] = new Contact(id)
}
// Contact.search = function(options) {
// if (options.name) {
// const regex = new RegExp(options.name)
// return Object.keys(Contact.pool)
// .filter(k => regex.test(Contact.pool[k].name()))
// .map(k => Contact.pool[k])
// }
// return []
// }
Contact.attach = function(puppet) { Contact.puppet = puppet }
......
......@@ -25,12 +25,11 @@ class Message {
// Transform rawObj to local m
parse(rawObj) {
return {
const obj = {
id: rawObj.MsgId
, type: rawObj.MsgType
, from: rawObj.MMActualSender
, to: rawObj.ToUserName
, room: rawObj.MMIsChatRoom ? rawObj.FromUserName : null // MMPeerUserName always eq FromUserName ?
, content: rawObj.MMActualContent // Content has @id prefix added by wx
, status: rawObj.Status
, digest: rawObj.MMDigest
......@@ -38,6 +37,19 @@ class Message {
, self: undefined // to store the logined user id
}
if (rawObj.MMIsChatRoom) {
if (/^@@/.test(rawObj.FromUserName)) {
obj.room = rawObj.FromUserName // MMPeerUserName always eq FromUserName ?
} else if (/^@@/.test(rawObj.ToUserName)) {
obj.room = rawObj.ToUserName
} else {
log.error('Message', 'parse found a room message, but neither FromUserName nor ToUserName is a room(/^@@/)')
obj.room = null // bug compatible
}
} else {
obj.room = null
}
return obj
}
toString() {
const text = htmlUtil.digestEmoji(this.obj.digest)
......
......@@ -208,7 +208,7 @@ return (function(port) {
}
function log(s) { clog(s); slog(s) }
function slog(msg) { return Wechaty.vars.socket && Wechaty.vars.socket.emit('log', msg) }
function ding() { return 'dong' }
function ding() { log('recv ding'); return 'dong' }
function send(ToUserName, Content) {
var chat = Wechaty.glue.chatFactory
var m = chat.createMessage({
......
......@@ -30,7 +30,7 @@ class Server extends EventEmitter {
toString() { return `Server({port:${this.port}})` }
init() {
log.verbose('PuppetwebServer', 'init()')
log.verbose('PuppetWebServer', 'init()')
return new Promise((resolve, reject) => {
// this.initEventsToClient()
......@@ -64,7 +64,7 @@ class Server extends EventEmitter {
}
return
}
log.verbose('PuppetwebServer', `createHttpsServer() listen on port ${this.port}`)
log.verbose('PuppetWebServer', `createHttpsServer() listen on port ${this.port}`)
if (typeof resolve === 'function') {
resolve(this)
}
......@@ -83,7 +83,7 @@ class Server extends EventEmitter {
next()
})
e.get('/ding', function(req, res) {
log.silly('PuppetwebServer', 'createExpress() %s GET /ding', new Date())
log.silly('PuppetWebServer', 'createExpress() %s GET /ding', new Date())
res.end('dong')
})
return e
......@@ -111,14 +111,14 @@ class Server extends EventEmitter {
this.emit('connection', client)
client.on('disconnect', e => {
log.verbose('PuppetwebServer', 'socket.io disconnect: %s', e)
log.verbose('PuppetWebServer', 'socket.io disconnect: %s', e)
// 1. Browser reload / 2. Lost connection(Bad network)
this.socketClient = null
this.emit('disconnect', e)
})
client.on('error' , e => log.error('PuppetwebServer', 'initEventsFromClient() client on error: %s', e.message))
// client.on('ding' , e => log.silly('PuppetwebServer', 'initEventsFromClient() client on ding: %s', e))
client.on('error' , e => log.error('PuppetWebServer', 'initEventsFromClient() client on error: %s', e.message))
// client.on('ding' , e => log.silly('PuppetWebServer', 'initEventsFromClient() client on ding: %s', e))
// Events from Wechaty@Broswer --to--> Server
;[
......@@ -131,34 +131,34 @@ class Server extends EventEmitter {
, 'ding'
].map(e => {
client.on(e, data => {
log.silly('PuppetwebServer', `initEventsFromClient() client on event[${e}](${data}) from browser, emit it`)
log.silly('PuppetWebServer', `initEventsFromClient() client on event[${e}](${data}) from browser, emit it`)
this.emit(e, data)
})
})
}
// initEventsToClient() {
// log.verbose('PuppetwebServer', 'initEventToClient()')
// log.verbose('PuppetWebServer', 'initEventToClient()')
// this.on('ding', data => {
// log.silly('PuppetwebServer', `recv event[ding](${data}), sending to client`)
// log.silly('PuppetWebServer', `recv event[ding](${data}), sending to client`)
// if (this.socketClient) { this.socketClient.emit('ding', data) }
// else { log.warn('PuppetwebServer', 'this.socketClient not exist')}
// else { log.warn('PuppetWebServer', 'this.socketClient not exist')}
// })
// }
quit() {
log.verbose('PuppetwebServer', 'quit()')
log.verbose('PuppetWebServer', 'quit()')
if (this.socketServer) {
log.verbose('PuppetwebServer', 'closing socketServer')
log.verbose('PuppetWebServer', 'closing socketServer')
this.socketServer.close()
this.socketServer = null
}
if (this.socketClient) {
log.verbose('PuppetwebServer', 'closing socketClient')
log.verbose('PuppetWebServer', 'closing socketClient')
this.socketClient = null
}
if (this.httpsServer) {
log.verbose('PuppetwebServer', 'closing httpsServer')
log.verbose('PuppetWebServer', 'closing httpsServer')
this.httpsServer.close()
this.httpsServer = null
}
......
......@@ -465,6 +465,9 @@ class PuppetWeb extends Puppet {
}
logined() { return !!(this.user) }
ding(data) {
if (!this.bridge) {
return Promise.reject(new Error('ding fail: no bridge(yet)!'))
}
return this.bridge.proxyWechaty('ding', data)
.catch(e => {
log.warn('PuppetWeb', 'ding(%s) rejected: %s', data, e.message || e)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册