Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
55cd6403
W
wechaty
项目概览
.Veneno.
/
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,发现更多精彩内容 >>
提交
55cd6403
编写于
6月 22, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean Wechaty class, add new class WechatyIo
上级
a432951e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
96 addition
and
22 deletion
+96
-22
package.json
package.json
+2
-1
src/wechaty-io.js
src/wechaty-io.js
+50
-0
src/wechaty.js
src/wechaty.js
+44
-21
未找到文件。
package.json
100755 → 100644
浏览文件 @
55cd6403
...
...
@@ -42,7 +42,8 @@
"
ps-tree
"
:
"
^1.1.0
"
,
"
retry-promise
"
:
"
^1.0.0
"
,
"
selenium-webdriver
"
:
"
^2.53.2
"
,
"
socket.io
"
:
"
^1.4.5
"
"
socket.io
"
:
"
^1.4.5
"
,
"
ws
"
:
"
^1.1.0
"
},
"eslintConfig"
:
{
"env"
:
{
...
...
src/wechaty-io.js
0 → 100644
浏览文件 @
55cd6403
/**
*
* wechaty: Wechat for Bot. and for human who talk to bot/robot
*
* Class WechatyIo
*
* Licenst: ISC
* https://github.com/zixia/wechaty
*
*/
const
EventEmitter
=
require
(
'
events
'
)
const
WebSocket
=
require
(
'
ws
'
);
const
co
=
require
(
'
co
'
)
const
log
=
require
(
'
./npmlog-env
'
)
class
WechatyIo
extends
EventEmitter
{
constructor
({
token
=
null
})
{
super
()
this
.
token
=
token
log
.
verbose
(
'
WechatyIo
'
,
'
instantiated with token:
'
+
token
)
}
toString
()
{
return
'
Class WechatyIo(
'
+
this
.
token
+
'
)
'
}
init
()
{
log
.
verbose
(
'
WechatyIo
'
,
'
init()
'
)
const
END_POINT
=
'
ws://api.wechaty.io/v0/websocket
'
var
ws
=
new
WebSocket
(
END_POINT
)
ws
.
on
(
'
open
'
,
function
open
()
{
ws
.
send
(
'
something
'
)
})
ws
.
on
(
'
message
'
,
function
(
data
,
flags
)
{
// flags.binary will be set if a binary data is received.
// flags.masked will be set if the data was masked.
})
return
Promise
.
resolve
(
this
)
}
}
/**
* Expose `Wechaty`.
*/
module
.
exports
=
WechatyIo
.
default
=
WechatyIo
.
WechatyIo
=
WechatyIo
src/wechaty.js
浏览文件 @
55cd6403
...
...
@@ -15,29 +15,34 @@ const log = require('./npmlog-env')
class
Wechaty
extends
EventEmitter
{
constructor
(
options
)
{
constructor
({
puppetType
=
process
.
env
.
WECHATY_PUPPET
||
'
web
'
,
head
=
process
.
env
.
WECHATY_HEAD
||
false
,
port
=
process
.
env
.
WECHATY_PORT
||
8788
// W(87) X(88), ascii char code ;-]
,
session
=
process
.
env
.
WECHATY_SESSION
// no session, no session save/restore
,
token
=
process
.
env
.
WECHATY_TOKEN
// token for wechaty.io auth
})
{
super
()
this
.
options
=
options
||
{}
this
.
options
.
puppet
=
this
.
options
.
puppet
||
process
.
env
.
WECHATY_PUPPET
||
'
web
'
this
.
options
.
head
=
this
.
options
.
head
||
process
.
env
.
WECHATY_HEAD
||
false
this
.
options
.
port
=
this
.
options
.
port
||
process
.
env
.
WECHATY_PORT
||
8788
// W(87) X(88), ascii char code ;-]
this
.
options
.
session
=
this
.
options
.
session
||
process
.
env
.
WECHATY_SESSION
// no session, no session save/restore
this
.
options
.
token
=
this
.
options
.
token
||
process
.
env
.
WECHATY_TOKEN
this
.
puppetType
=
puppetType
this
.
head
=
head
this
.
port
=
port
this
.
session
=
session
this
.
token
=
token
this
.
npmVersion
=
require
(
'
../package.json
'
).
version
this
.
inited
=
false
}
toString
()
{
return
'
Class Wechaty(
'
+
this
.
puppet
+
'
)
'
}
toString
()
{
return
'
Class Wechaty(
'
+
this
.
puppet
Type
+
'
)
'
}
version
()
{
return
this
.
npmVersion
}
init
()
{
log
.
info
(
'
Wechaty
'
,
'
v%s initializing...
'
,
this
.
npmVersion
)
log
.
verbose
(
'
Wechaty
'
,
'
puppet: %s
'
,
this
.
options
.
puppet
)
log
.
verbose
(
'
Wechaty
'
,
'
head: %s
'
,
this
.
options
.
head
)
log
.
verbose
(
'
Wechaty
'
,
'
session: %s
'
,
this
.
options
.
session
)
log
.
verbose
(
'
Wechaty
'
,
'
puppet: %s
'
,
this
.
puppetType
)
log
.
verbose
(
'
Wechaty
'
,
'
head: %s
'
,
this
.
head
)
log
.
verbose
(
'
Wechaty
'
,
'
session: %s
'
,
this
.
session
)
if
(
this
.
inited
)
{
log
.
error
(
'
Wechaty
'
,
'
init() already inited. return and do nothing.
'
)
...
...
@@ -45,19 +50,21 @@ class Wechaty extends EventEmitter {
}
return
co
.
call
(
this
,
function
*
()
{
const
okPort
=
yield
this
.
getPort
(
this
.
options
.
port
)
const
okPort
=
yield
this
.
getPort
(
this
.
port
)
if
(
okPort
!=
this
.
options
.
port
)
{
log
.
info
(
'
Wechaty
'
,
'
port: %d not available, changed to %d
'
,
this
.
options
.
port
,
okPort
)
this
.
options
.
port
=
okPort
if
(
okPort
!=
this
.
port
)
{
log
.
info
(
'
Wechaty
'
,
'
port: %d not available, changed to %d
'
,
this
.
port
,
okPort
)
this
.
port
=
okPort
}
else
{
log
.
verbose
(
'
Wechaty
'
,
'
port: %d
'
,
this
.
options
.
port
)
log
.
verbose
(
'
Wechaty
'
,
'
port: %d
'
,
this
.
port
)
}
yield
this
.
initPuppet
()
yield
this
.
initEventHook
()
yield
this
.
puppet
.
init
()
yield
this
.
initIo
(
this
.
token
)
this
.
inited
=
true
return
this
// for chaining
})
...
...
@@ -67,17 +74,33 @@ class Wechaty extends EventEmitter {
})
}
initIo
(
token
)
{
if
(
!
token
)
{
log
.
verbose
(
'
Wechaty
'
,
'
initIo() skiped for no token set
'
)
return
Promise
.
resolve
(
'
no token
'
)
}
const
WechatyIo
=
require
(
'
./wechaty-io
'
)
this
.
io
=
new
WechatyIo
({
token
:
token
})
return
io
.
init
()
.
catch
(
e
=>
{
log
.
verbose
(
'
Wechaty
'
,
'
Wechaty.IO init fail: %s
'
,
e
.
message
)
throw
e
})
}
initPuppet
()
{
switch
(
this
.
options
.
puppet
)
{
switch
(
this
.
puppetType
)
{
case
'
web
'
:
this
.
puppet
=
new
Puppet
.
Web
({
head
:
this
.
options
.
head
,
port
:
this
.
options
.
port
,
session
:
this
.
options
.
session
head
:
this
.
head
,
port
:
this
.
port
,
session
:
this
.
session
})
break
default
:
throw
new
Error
(
'
Puppet unsupport(yet):
'
+
this
.
options
.
puppet
)
throw
new
Error
(
'
Puppet unsupport(yet):
'
+
this
.
puppetType
)
}
return
Promise
.
resolve
(
this
.
puppet
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录