Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
64f1fc68
W
wechaty
项目概览
.www.
/
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,发现更多精彩内容 >>
提交
64f1fc68
编写于
8月 16, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modulized IoBot
上级
85372df8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
92 addition
and
33 deletion
+92
-33
bin/io-bot.js
bin/io-bot.js
+8
-33
src/io-bot.js
src/io-bot.js
+84
-0
未找到文件。
bin/io-bot.js
浏览文件 @
64f1fc68
#!/usr/bin/env node
#!/usr/bin/env node
const
Wechaty
=
require
(
'
..
'
)
const
log
=
require
(
'
../src/npmlog-env
'
)
const
IoBot
=
require
(
'
../src/io-bot
'
)
const
log
=
Wechaty
.
log
const
welcome
=
`
const
welcome
=
`
| __ __ _ _
| __ __ _ _
...
@@ -35,45 +35,20 @@ if (!token) {
...
@@ -35,45 +35,20 @@ if (!token) {
log
.
info
(
'
Bot
'
,
'
Starting for WECHATY_TOKEN: %s
'
,
token
)
log
.
info
(
'
Bot
'
,
'
Starting for WECHATY_TOKEN: %s
'
,
token
)
}
}
const
bot
=
new
Wechaty
({
const
ioBot
=
new
IoBot
({
profile
profile
,
token
// token for wechaty.io auth
,
token
,
log
})
})
bot
ioBot
.
init
()
.
on
(
'
login
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logined`
))
.
on
(
'
logout
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logouted`
))
.
on
(
'
scan
'
,
({
url
,
code
})
=>
log
.
info
(
'
Bot
'
,
'
[%d] %s <-- Scan QR Code in url to login
'
,
code
,
url
))
.
on
(
'
message
'
,
m
=>
{
m
.
ready
()
.
then
(
onMessage
)
.
catch
(
e
=>
log
.
error
(
'
Bot
'
,
'
ready: %s
'
,
e
))
})
bot
.
init
()
.
catch
(
e
=>
{
.
catch
(
e
=>
{
log
.
error
(
'
Bot
'
,
'
init() fail: %s
'
,
e
)
log
.
error
(
'
Bot
'
,
'
init() fail: %s
'
,
e
)
bot
.
quit
()
bot
.
quit
()
process
.
exit
(
-
1
)
process
.
exit
(
-
1
)
})
})
const
onMessage
=
function
(
m
)
{
const
from
=
m
.
from
()
const
to
=
m
.
to
()
const
content
=
m
.
toString
()
const
room
=
m
.
room
()
// log.info('Bot', '%s<%s>:%s'
// , (room ? '['+room.name()+']' : '')
// , from.name()
// , m.toStringDigest()
// )
if
(
/^wechaty|botie/i
.
test
(
m
.
get
(
'
content
'
))
&&
!
bot
.
self
(
m
))
{
bot
.
reply
(
m
,
'
https://www.wechaty.io
'
)
.
then
(
_
=>
log
.
info
(
'
Bot
'
,
'
REPLIED to magic word "wechaty"
'
))
}
}
/**
/**
*
*
* To make heroku happy
* To make heroku happy
...
...
src/io-bot.js
0 → 100644
浏览文件 @
64f1fc68
/**
*
* wechaty: Wechat for Bot. and for human who talk to bot/robot
*
* Class Io
* http://www.wechaty.io
*
* Licenst: ISC
* https://github.com/zixia/wechaty
*
*/
const
Wechaty
=
require
(
'
./wechaty
'
)
class
IoBot
{
constructor
({
token
=
'
EPP
'
,
profile
=
'
wechaty-epp
'
,
log
=
null
})
{
if
(
!
log
)
{
const
e
=
new
Error
(
'
constructor() log(npmlog/brolog) must be set
'
)
throw
e
}
this
.
log
=
log
this
.
log
.
verbose
(
'
IoBot
'
,
'
constructor() with token:[%s]
'
,
token
)
if
(
!
token
)
{
const
e
=
new
Error
(
'
constructor() token must be set
'
)
this
.
log
.
error
(
'
IoBot
'
,
e
)
throw
e
}
this
.
token
=
token
this
.
profile
=
profile
}
init
()
{
this
.
log
.
verbose
(
'
IoBot
'
,
'
init()
'
)
this
.
wechaty
=
new
Wechaty
({
profile
:
this
.
profile
,
token
:
this
.
token
})
this
.
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
}
`
))
.
on
(
'
message
'
,
message
=>
{
message
.
ready
()
.
then
(
this
.
onMessage
.
bind
(
this
))
.
catch
(
e
=>
this
.
log
.
error
(
'
IoBot
'
,
'
message.ready() %s
'
,
e
))
})
return
this
.
wechaty
.
init
()
.
then
(
_
=>
this
)
.
catch
(
e
=>
{
this
.
log
.
error
(
'
IoBot
'
,
'
init() init fail: %s
'
,
e
)
bot
.
quit
()
return
e
})
}
onMessage
(
m
)
{
const
from
=
m
.
from
()
const
to
=
m
.
to
()
const
content
=
m
.
toString
()
const
room
=
m
.
room
()
// log.info('Bot', '%s<%s>:%s'
// , (room ? '['+room.name()+']' : '')
// , from.name()
// , m.toStringDigest()
// )
if
(
/^wechaty|botie/i
.
test
(
m
.
get
(
'
content
'
))
&&
!
bot
.
self
(
m
))
{
bot
.
reply
(
m
,
'
https://www.wechaty.io
'
)
.
then
(
_
=>
log
.
info
(
'
Bot
'
,
'
REPLIED to magic word "wechaty"
'
))
}
}
}
module
.
exports
=
IoBot
.
default
=
IoBot
.
IoBot
=
IoBot
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录