Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
14475b02
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,发现更多精彩内容 >>
提交
14475b02
编写于
8月 18, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
half work with electron
上级
ef1fd124
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
59 addition
and
42 deletion
+59
-42
bin/io-bot.js
bin/io-bot.js
+9
-11
index.js
index.js
+28
-1
src/io-bot.js
src/io-bot.js
+8
-4
src/wechaty.js
src/wechaty.js
+9
-23
test/wechaty.spec.js
test/wechaty.spec.js
+5
-3
未找到文件。
bin/io-bot.js
浏览文件 @
14475b02
...
...
@@ -28,8 +28,8 @@ let token = process.env.WECHATY_TOKEN
if
(
!
token
)
{
log
.
error
(
'
Bot
'
,
'
token not found: please set WECHATY_TOKEN in environment before run io-bot
'
)
// process.exit(-1)
log
.
warn
(
'
Bot
'
,
'
set token to "DEMO" for demo purpose
'
)
token
=
'
DEMO
'
log
.
warn
(
'
Bot
'
,
`set token to "
${
token
}
" for demo purpose`
)
}
else
{
console
.
log
(
welcome
)
log
.
info
(
'
Bot
'
,
'
Starting for WECHATY_TOKEN: %s
'
,
token
)
...
...
@@ -42,16 +42,14 @@ const ioBot = new IoBot({
})
ioBot
.
init
()
.
catch
(
e
=>
{
log
.
error
(
'
Bot
'
,
'
init() fail: %s
'
,
e
)
bot
.
quit
()
process
.
exit
(
-
1
)
})
.
catch
(
onError
.
bind
(
ioBot
))
ioBot
.
initWeb
()
.
catch
(
e
=>
{
.
catch
(
onError
.
bind
(
ioBot
))
function
onError
(
e
)
{
log
.
error
(
'
Bot
'
,
'
initWeb() fail: %s
'
,
e
)
bot
.
quit
()
this
.
quit
()
process
.
exit
(
-
1
)
})
}
index.js
浏览文件 @
14475b02
module
.
exports
=
require
(
'
./src/wechaty
'
)
const
Wechaty
=
require
(
'
./src/wechaty
'
)
const
Message
=
require
(
'
./src/message
'
)
const
Contact
=
require
(
'
./src/contact
'
)
const
Room
=
require
(
'
./src/room
'
)
const
Puppet
=
require
(
'
./src/puppet
'
)
const
PuppetWeb
=
require
(
'
./src/puppet-web
'
)
const
IoBot
=
require
(
'
./src/io-bot
'
)
const
log
=
require
(
'
./src/npmlog-env
'
)
Object
.
assign
(
Wechaty
,
{
Message
,
Contact
,
Room
,
Puppet
,
PuppetWeb
,
IoBot
,
version
:
require
(
'
./package.json
'
).
version
,
log
// for convenionce use npmlog with environment variable LEVEL
})
module
.
exports
=
Wechaty
src/io-bot.js
浏览文件 @
14475b02
...
...
@@ -14,6 +14,7 @@ const Wechaty = require('./wechaty')
class
IoBot
{
constructor
({
token
=
'
EPP
'
,
head
=
false
,
profile
=
'
wechaty-epp
'
,
log
=
null
})
{
...
...
@@ -32,17 +33,19 @@ class IoBot {
this
.
token
=
token
this
.
profile
=
profile
this
.
head
=
head
}
init
()
{
this
.
log
.
verbose
(
'
IoBot
'
,
'
init()
'
)
this
.
wechaty
=
new
Wechaty
({
const
wechaty
=
this
.
wechaty
=
new
Wechaty
({
profile
:
this
.
profile
,
token
:
this
.
token
,
head
:
this
.
head
})
this
.
wechaty
wechaty
.
on
(
'
login
'
,
user
=>
this
.
log
.
info
(
'
IoBot
'
,
`
${
user
.
name
}
logined`
))
.
on
(
'
logout
'
,
user
=>
this
.
log
.
info
(
'
IoBot
'
,
`
${
user
}
logouted`
))
.
on
(
'
scan
'
,
({
url
,
code
})
=>
this
.
log
.
info
(
'
IoBot
'
,
`[
${
code
}
]
${
url
}
`
))
...
...
@@ -53,11 +56,12 @@ class IoBot {
})
return
this
.
wechaty
.
init
()
return
wechaty
.
init
()
.
then
(
_
=>
this
)
.
catch
(
e
=>
{
this
.
log
.
error
(
'
IoBot
'
,
'
init() init fail: %s
'
,
e
)
bot
.
quit
()
console
.
log
(
e
)
wechaty
.
quit
()
return
e
})
}
...
...
src/wechaty.js
浏览文件 @
14475b02
...
...
@@ -14,6 +14,8 @@ const co = require('co')
const
log
=
require
(
'
./npmlog-env
'
)
const
Util
=
require
(
'
./util
'
)
const
PuppetWeb
=
require
(
'
./puppet-web
'
)
class
Wechaty
extends
EventEmitter
{
constructor
({
...
...
@@ -23,7 +25,7 @@ class Wechaty extends EventEmitter {
,
endpoint
=
process
.
env
.
WECHATY_ENDPOINT
// wechaty.io api endpoint
,
token
=
process
.
env
.
WECHATY_TOKEN
// token for wechaty.io auth
,
profile
=
process
.
env
.
WECHATY_PROFILE
// no profile, no session save/restore
}
=
{}
)
{
})
{
super
()
this
.
type
=
type
this
.
head
=
head
...
...
@@ -61,6 +63,7 @@ class Wechaty extends EventEmitter {
log
.
info
(
'
Wechaty
'
,
'
v%s initializing...
'
,
this
.
npmVersion
)
log
.
verbose
(
'
Wechaty
'
,
'
puppet: %s
'
,
this
.
type
)
log
.
verbose
(
'
Wechaty
'
,
'
head: %s
'
,
this
.
head
)
console
.
log
(
process
.
env
.
WECHATY_HEAD
)
log
.
verbose
(
'
Wechaty
'
,
'
profile: %s
'
,
this
.
profile
)
if
(
this
.
inited
)
{
...
...
@@ -155,10 +158,15 @@ class Wechaty extends EventEmitter {
}
quit
()
{
log
.
verbose
(
'
Wechaty
'
,
'
quit()
'
)
const
puppetBeforeDie
=
this
.
puppet
this
.
puppet
=
null
this
.
inited
=
false
if
(
!
puppetBeforeDie
)
{
return
Promise
.
resolve
()
}
return
puppetBeforeDie
.
quit
()
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
quit() exception: %s
'
,
e
.
message
)
...
...
@@ -232,28 +240,6 @@ class Wechaty extends EventEmitter {
}
const
Message
=
require
(
'
./message
'
)
const
Contact
=
require
(
'
./contact
'
)
const
Room
=
require
(
'
./room
'
)
// const Puppet = require('./puppet')
const
PuppetWeb
=
require
(
'
./puppet-web
'
)
Object
.
assign
(
Wechaty
,
{
Message
,
Contact
,
Room
// Do not include IoBot here, because it will be a circle dependence
// const IoBot = require('./io-bot')
//, IoBot
,
log
// for convenionce use npmlog with environment variable LEVEL
// Puppet
})
Wechaty
.
version
=
require
(
'
../package.json
'
).
version
/**
* Expose `Wechaty`.
*/
...
...
test/wechaty.spec.js
浏览文件 @
14475b02
const
test
=
require
(
'
tape
'
)
const
log
=
require
(
'
../src/npmlog-env
'
)
test
(
'
Wechaty Framework
'
,
function
(
t
)
{
const
Wechaty
=
require
(
'
../
'
)
...
...
@@ -7,10 +6,13 @@ test('Wechaty Framework', function(t) {
t
.
ok
(
Wechaty
.
Message
,
'
should export Wechaty.Message
'
)
t
.
ok
(
Wechaty
.
Contact
,
'
should export Wechaty.Contact
'
)
t
.
ok
(
Wechaty
.
Room
,
'
should export Wechaty.Room
'
)
t
.
ok
(
Wechaty
.
IoBot
,
'
should export Wechaty.IoBot
'
)
// t.ok(Wechaty.Puppet , 'should export Wechaty.Puppet')
// t.ok(Wechaty.Puppet.Web , 'should export Wechaty.Puppet.Web')
t
.
ok
(
Wechaty
.
log
,
'
should export Wechaty.log
'
)
t
.
ok
(
Wechaty
.
Puppet
,
'
should export Wechaty.Puppet
'
)
t
.
ok
(
Wechaty
.
PuppetWeb
,
'
should export Wechaty.PuppetWeb
'
)
const
bot
=
new
Wechaty
()
t
.
equal
(
bot
.
version
(),
Wechaty
.
version
,
'
should export version in package.json
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录