Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
e27182b4
W
wechaty
项目概览
weixin_46011646
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e27182b4
编写于
6月 14, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:zixia/wechaty
上级
7c6dd67d
574341c0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
19 deletion
+39
-19
README.md
README.md
+1
-1
src/message.js
src/message.js
+5
-0
src/puppet-web-browser.js
src/puppet-web-browser.js
+24
-15
src/puppet-web-injectio.js
src/puppet-web-injectio.js
+9
-3
未找到文件。
README.md
浏览文件 @
e27182b4
...
...
@@ -3,7 +3,7 @@
Connecting ChatBots.
Wechaty is a Bot
Library
for Wechat
**Personal**
Account.
Wechaty is a Bot
Framework
for Wechat
**Personal**
Account.
> Easy creating personal account wechat robot in 9 lines of code.
...
...
src/message.js
浏览文件 @
e27182b4
...
...
@@ -37,6 +37,8 @@ class Message {
,
self
:
undefined
// to store the logined user id
}
// FIXME: has ther any better method to know the room ID?
if
(
rawObj
.
MMIsChatRoom
)
{
if
(
/^@@/
.
test
(
rawObj
.
FromUserName
))
{
obj
.
room
=
rawObj
.
FromUserName
// MMPeerUserName always eq FromUserName ?
...
...
@@ -52,6 +54,9 @@ class Message {
return
obj
}
toString
()
{
return
htmlUtil
.
plainText
(
this
.
obj
.
content
)
}
toStringDigest
()
{
const
text
=
htmlUtil
.
digestEmoji
(
this
.
obj
.
digest
)
return
'
{
'
+
this
.
type
()
+
'
}
'
+
text
}
...
...
src/puppet-web-browser.js
浏览文件 @
e27182b4
...
...
@@ -97,22 +97,27 @@ class Browser extends EventEmitter {
}
getPhantomJsDriver
()
{
// https://github.com/SeleniumHQ/selenium/issues/2069
// setup custom phantomJS capability
// setup custom phantomJS capability https://github.com/SeleniumHQ/selenium/issues/2069
const
phantomjsExe
=
require
(
'
phantomjs-prebuilt
'
).
path
// const phantomjsExe = require('phantomjs2').path
const
customPhantom
=
WebDriver
.
Capabilities
.
phantomjs
()
.
setAlertBehavior
(
'
ignore
'
)
.
set
(
'
phantomjs.binary.path
'
,
phantomjsExe
)
.
set
(
'
phantomjs.cli.args
'
,
[
const
phantomjsArgs
=
[
'
--ignore-ssl-errors=true
'
// this help socket.io connect with localhost
,
'
--load-images=false
'
,
'
--remote-debugger-port=8080
'
// , '--webdriver-logfile=/tmp/wd.log'
// , '--webdriver-loglevel=DEBUG'
])
]
if
(
/silly|verbose/i
.
test
(
process
.
env
.
WECHATY_DEBUG
))
{
phantomjsArgs
.
push
(
'
--remote-debugger-port=8080
'
)
// XXX: be careful when in production usage.
}
const
customPhantom
=
WebDriver
.
Capabilities
.
phantomjs
()
.
setAlertBehavior
(
'
ignore
'
)
.
set
(
'
phantomjs.binary.path
'
,
phantomjsExe
)
.
set
(
'
phantomjs.cli.args
'
,
phantomjsArgs
)
log
.
silly
(
'
PuppetWebBrowser
'
,
'
phantomjs binary:
'
+
phantomjsExe
)
log
.
silly
(
'
PuppetWebBrowser
'
,
'
phantomjs args:
'
+
phantomjsArgs
.
join
(
'
'
))
return
new
WebDriver
.
Builder
()
.
withCapabilities
(
customPhantom
)
...
...
@@ -156,9 +161,11 @@ class Browser extends EventEmitter {
const
max
=
15
const
backoff
=
100
// max = (2*totalTime/backoff) ^ (1/2)
// timeout = 11250 for {max: 15, backoff: 100}
// timeout = 45000 for {max: 30, backoff: 100}
/**
* max = (2*totalTime/backoff) ^ (1/2)
* timeout = 11250 for {max: 15, backoff: 100}
* timeout = 45000 for {max: 30, backoff: 100}
*/
const
timeout
=
max
*
(
backoff
*
max
)
/
2
return
retryPromise
({
max
:
max
,
backoff
:
backoff
},
attempt
=>
{
...
...
@@ -213,10 +220,12 @@ class Browser extends EventEmitter {
return
this
.
addCookies
(
c
)
})
}
// convert expiry from seconds to milliseconds. https://github.com/SeleniumHQ/selenium/issues/2245
// with selenium-webdriver v2.53.2
// NOTICE: the lastest branch of selenium-webdriver for js has changed the interface of addCookie:
// https://github.com/SeleniumHQ/selenium/commit/02f407976ca1d516826990f11aca7de3c16ba576
/**
* convert expiry from seconds to milliseconds. https://github.com/SeleniumHQ/selenium/issues/2245
* with selenium-webdriver v2.53.2
* NOTICE: the lastest branch of selenium-webdriver for js has changed the interface of addCookie:
* https://github.com/SeleniumHQ/selenium/commit/02f407976ca1d516826990f11aca7de3c16ba576
*/
if
(
cookie
.
expiry
)
{
cookie
.
expiry
=
cookie
.
expiry
*
1000
/* XXX: be aware of new version of webdriver */
}
log
.
silly
(
'
PuppetWebBrowser
'
,
'
addCookies("%s", "%s", "%s", "%s", "%s", "%s")
'
...
...
src/puppet-web-injectio.js
浏览文件 @
e27182b4
...
...
@@ -39,6 +39,7 @@ return (function(port) {
,
socket
:
null
,
eventsBuf
:
[]
,
scanCode
:
null
,
heartBeatTimmer
:
null
}
// funcs
...
...
@@ -109,17 +110,22 @@ return (function(port) {
checkScan
()
heartBeat
()
heartBeat
(
true
)
clog
(
'
inited!. ;-D
'
)
Wechaty
.
vars
.
inited
=
true
return
'
init: success
'
}
function
heartBeat
()
{
function
heartBeat
(
firstTime
)
{
var
TIMEOUT
=
15000
// 15s
if
(
firstTime
&&
Wechaty
.
vars
.
heartBeatTimmer
)
{
Wechaty
.
log
(
'
heartBeat timer exist when 1st time is true? return for do nothing
'
)
return
}
Wechaty
.
emit
(
'
ding
'
,
'
heartbeat@browser
'
)
setTimeout
(
heartBeat
,
TIMEOUT
)
Wechaty
.
vars
.
heartBeatTimmer
=
setTimeout
(
heartBeat
,
TIMEOUT
)
return
TIMEOUT
}
function
glueAngular
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录