Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
a432951e
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,发现更多精彩内容 >>
提交
a432951e
编写于
6月 21, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code styling & format
上级
b16d0fa0
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
31 addition
and
19 deletion
+31
-19
.gitignore
.gitignore
+3
-1
src/wechaty.js
src/wechaty.js
+28
-18
未找到文件。
.gitignore
浏览文件 @
a432951e
...
...
@@ -39,8 +39,10 @@ node_modules
coverage
.nyc_output
# Wechaty session file
*.wechaty.json
# Other staff
0
t.js
t
*.wechaty.json
src/wechaty.js
浏览文件 @
a432951e
...
...
@@ -13,14 +13,8 @@ const co = require('co')
const
log
=
require
(
'
./npmlog-env
'
)
const
Puppet
=
require
(
'
./puppet
'
)
const
PuppetWeb
=
require
(
'
./puppet-web
'
)
const
Message
=
require
(
'
./message
'
)
const
Contact
=
require
(
'
./contact
'
)
const
Room
=
require
(
'
./room
'
)
class
Wechaty
extends
EventEmitter
{
constructor
(
options
)
{
super
()
this
.
options
=
options
||
{}
...
...
@@ -28,12 +22,15 @@ class Wechaty extends EventEmitter {
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
.
npmVersion
=
require
(
'
../package.json
'
).
version
this
.
inited
=
false
}
toString
()
{
return
'
Class Wechaty(
'
+
this
.
puppet
+
'
)
'
}
version
()
{
return
this
.
npmVersion
}
init
()
{
...
...
@@ -69,6 +66,7 @@ class Wechaty extends EventEmitter {
throw
e
})
}
initPuppet
()
{
switch
(
this
.
options
.
puppet
)
{
case
'
web
'
:
...
...
@@ -83,6 +81,7 @@ class Wechaty extends EventEmitter {
}
return
Promise
.
resolve
(
this
.
puppet
)
}
initEventHook
()
{
this
.
puppet
.
on
(
'
scan
'
,
(
e
)
=>
{
this
.
emit
(
'
scan
'
,
e
)
// Scan QRCode
...
...
@@ -122,6 +121,7 @@ class Wechaty extends EventEmitter {
throw
e
})
}
logout
()
{
return
this
.
puppet
.
logout
()
.
catch
(
e
=>
{
...
...
@@ -133,6 +133,7 @@ class Wechaty extends EventEmitter {
self
(
message
)
{
return
this
.
puppet
.
self
(
message
)
}
send
(
message
)
{
return
this
.
puppet
.
send
(
message
)
.
catch
(
e
=>
{
...
...
@@ -140,6 +141,7 @@ class Wechaty extends EventEmitter {
throw
e
})
}
reply
(
message
,
reply
)
{
return
this
.
puppet
.
reply
(
message
,
reply
)
.
catch
(
e
=>
{
...
...
@@ -147,6 +149,7 @@ class Wechaty extends EventEmitter {
throw
e
})
}
ding
(
data
)
{
if
(
!
this
.
puppet
)
{
return
Promise
.
reject
(
new
Error
(
'
wechaty cant ding coz no puppet
'
))
...
...
@@ -163,17 +166,17 @@ class Wechaty extends EventEmitter {
return
new
Promise
((
resolve
,
reject
)
=>
{
port
=
port
||
8788
// https://gist.github.com/mikeal/1840641
function
getPort
(
cb
)
{
function
getPort
(
cb
)
{
var
tryPort
=
port
port
+=
1
var
server
=
require
(
'
net
'
).
createServer
()
server
.
on
(
'
error
'
,
function
(
err
)
{
server
.
on
(
'
error
'
,
function
(
err
)
{
if
(
err
)
{}
getPort
(
cb
)
})
server
.
listen
(
tryPort
,
function
(
err
)
{
server
.
listen
(
tryPort
,
function
(
err
)
{
if
(
err
)
{}
server
.
once
(
'
close
'
,
function
()
{
server
.
once
(
'
close
'
,
function
()
{
cb
(
tryPort
)
})
server
.
close
()
...
...
@@ -184,17 +187,24 @@ class Wechaty extends EventEmitter {
}
}
Puppet
.
Web
=
PuppetWeb
const
Message
=
require
(
'
./message
'
)
const
Contact
=
require
(
'
./contact
'
)
const
Room
=
require
(
'
./room
'
)
const
Puppet
=
require
(
'
./puppet
'
)
Puppet
.
Web
=
require
(
'
./puppet-web
'
)
Object
.
assign
(
Wechaty
,
{
Puppet
:
Puppet
,
Message
:
Message
,
Contact
:
Contact
,
Room
:
Room
Puppet
,
Message
,
Contact
,
Room
,
log
// for convenionce use npmlog with environment variable LEVEL
})
/**
* Expose `Wechaty`.
*/
Wechaty
.
log
=
log
// for convenionce use npmlog with environment variable LEVEL
module
.
exports
=
Wechaty
.
default
=
Wechaty
.
Wechaty
=
Wechaty
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录