Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
2400fd05
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,发现更多精彩内容 >>
提交
2400fd05
编写于
6月 15, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:zixia/wechaty
上级
09c14df5
6109f05c
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
47 addition
and
28 deletion
+47
-28
README.md
README.md
+1
-1
package.json
package.json
+0
-3
src/contact.js
src/contact.js
+2
-6
src/html-util.js
src/html-util.js
+6
-4
src/puppet-web-bridge.js
src/puppet-web-bridge.js
+1
-1
src/puppet-web-injectio.js
src/puppet-web-injectio.js
+6
-0
src/puppet-web.js
src/puppet-web.js
+7
-2
src/room.js
src/room.js
+2
-6
src/wechaty.js
src/wechaty.js
+22
-5
未找到文件。
README.md
浏览文件 @
2400fd05
...
...
@@ -17,7 +17,7 @@ Supports [linux](https://travis-ci.org/zixia/wechaty), [win32](https://ci.appvey
[
![Downloads
][
downloads-image
]
][downloads-url]
# Examples
Wechaty is super easy to use:
10 lines of javascript is enough for your first wechat ro
bot.
Wechaty is super easy to use:
9 lines of javascript is enough for your 1st wechat
bot.
## 1. Basic: 9 lines
The following 9 lines of code implement a bot who reply "roger" for every message received:
...
...
package.json
浏览文件 @
2400fd05
...
...
@@ -18,13 +18,10 @@
"微信"
,
"weixin"
,
"personal"
,
"account"
,
"bot"
,
"robot"
,
"chatbot"
,
"framework"
,
"library"
,
"api"
,
"wechaty"
,
"微信控"
],
...
...
src/contact.js
浏览文件 @
2400fd05
...
...
@@ -19,11 +19,7 @@ class Contact {
this
.
obj
=
{}
}
toString
()
{
return
this
.
obj
.
name
?
htmlUtil
.
plainText
(
this
.
obj
.
name
)
:
this
.
obj
.
id
}
toString
()
{
return
this
.
id
}
toStringEx
()
{
return
`Contact(
${
this
.
obj
.
name
}
[
${
this
.
id
}
])`
}
parse
(
rawObj
)
{
...
...
@@ -45,7 +41,7 @@ class Contact {
}
}
name
()
{
return
this
.
obj
.
name
}
name
()
{
return
htmlUtil
.
plainText
(
this
.
obj
.
name
)
}
remark
()
{
return
this
.
obj
.
remark
}
stranger
()
{
return
this
.
obj
.
stranger
}
star
()
{
return
this
.
obj
.
star
}
...
...
src/html-util.js
浏览文件 @
2400fd05
...
...
@@ -29,10 +29,12 @@ function digestEmoji(html) {
}
function
plainText
(
html
)
{
return
unescapeHtml
(
stripHtml
(
digestEmoji
(
html
return
stripHtml
(
unescapeHtml
(
stripHtml
(
digestEmoji
(
html
)
)
)
)
...
...
src/puppet-web-bridge.js
浏览文件 @
2400fd05
...
...
@@ -145,7 +145,7 @@ class Bridge {
.
catch
(
e
=>
{
log
.
warn
(
'
PuppetWebBridge
'
,
'
inject() exception: %s
'
,
e
.
message
)
attempt
=
attempt
||
0
if
(
attempt
++
<
3
)
{
if
(
attempt
++
<
9
)
{
// if init fail, retry 9 times
log
.
warn
(
'
PuppetWebBridge
'
,
'
inject(%d) retry after 1 second: %s
'
,
attempt
,
e
.
message
)
setTimeout
(()
=>
this
.
inject
(
attempt
),
1000
)
return
...
...
src/puppet-web-injectio.js
浏览文件 @
2400fd05
...
...
@@ -343,6 +343,12 @@ return (function(port) {
var
d
=
new
Date
()
s
=
d
.
getHours
()
+
'
:
'
+
d
.
getMinutes
()
+
'
:
'
+
d
.
getSeconds
()
+
'
<Wechaty>
'
+
s
/**
* FIXME: WARN PuppetWebBridge inject() exception: {"errorMessage":"null is not an object (evaluating 'document.body.appendChild')"
* when will document.createElement('iframe') return null?
* this will cause the bridge init fail, and retry.
* should it be ignored? or keep this exception to retry is better?
*/
var
i
=
document
.
createElement
(
'
iframe
'
)
i
.
style
.
display
=
'
none
'
document
.
body
.
appendChild
(
i
)
...
...
src/puppet-web.js
浏览文件 @
2400fd05
...
...
@@ -457,8 +457,13 @@ class PuppetWeb extends Puppet {
.
set
(
'
from
'
,
message
.
obj
.
to
)
.
set
(
'
to
'
,
message
.
obj
.
from
)
.
set
(
'
room
'
,
message
.
obj
.
room
)
// FIXME: find a alternate way to check a message create by `self`
.
set
(
'
self
'
,
this
.
user
.
id
)
if
(
this
.
user
)
{
// FIXME: find a alternate way to check a message create by `self`
m
.
set
(
'
self
'
,
this
.
user
.
id
)
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
reply() too early before logined user be set
'
)
}
// log.verbose('PuppetWeb', 'reply() by message: %s', util.inspect(m))
return
this
.
send
(
m
)
...
...
src/room.js
浏览文件 @
2400fd05
...
...
@@ -19,11 +19,7 @@ class Room {
}
}
toString
()
{
return
this
.
obj
.
name
?
htmlUtil
.
plainText
(
this
.
obj
.
name
)
:
this
.
obj
.
id
}
toString
()
{
return
this
.
id
}
toStringEx
()
{
return
`Room(
${
this
.
obj
.
name
}
[
${
this
.
id
}
])`
}
ready
(
contactGetter
)
{
...
...
@@ -50,7 +46,7 @@ class Room {
})
}
name
()
{
return
this
.
obj
.
name
}
name
()
{
return
htmlUtil
.
plainText
(
this
.
obj
.
name
)
}
get
(
prop
)
{
return
this
.
obj
[
prop
]
}
parse
(
rawObj
)
{
...
...
src/wechaty.js
浏览文件 @
2400fd05
...
...
@@ -30,14 +30,22 @@ class Wechaty extends EventEmitter {
this
.
options
.
session
=
this
.
options
.
session
||
process
.
env
.
WECHATY_SESSION
// no session, no session save/restore
this
.
VERSION
=
require
(
'
../package.json
'
).
version
this
.
inited
=
false
}
toString
()
{
return
'
Class Wechaty(
'
+
this
.
puppet
+
'
)
'
}
init
()
{
log
.
info
(
'
Wechaty
'
,
'
v%s initializing...
'
,
this
.
VERSION
)
log
.
verbose
(
'
Wechaty
'
,
'
puppet: %s
'
,
this
.
options
.
puppet
)
log
.
verbose
(
'
Wechaty
'
,
'
head: %s
'
,
this
.
options
.
head
)
log
.
verbose
(
'
Wechaty
'
,
'
session: %s
'
,
this
.
options
.
session
)
if
(
this
.
inited
)
{
log
.
error
(
'
Wechaty
'
,
'
init() already inited. return and do nothing.
'
)
return
Promise
.
resolve
(
this
)
}
return
co
.
call
(
this
,
function
*
()
{
const
okPort
=
yield
this
.
getPort
(
this
.
options
.
port
)
...
...
@@ -52,9 +60,11 @@ class Wechaty extends EventEmitter {
yield
this
.
initEventHook
()
yield
this
.
puppet
.
init
()
this
.
inited
=
true
return
this
// for chaining
}).
catch
(
e
=>
{
})
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
init() exception: %s
'
,
e
.
message
)
throw
e
})
...
...
@@ -99,8 +109,12 @@ class Wechaty extends EventEmitter {
return
Promise
.
resolve
()
}
quit
()
{
return
this
.
puppet
.
quit
()
quit
()
{
const
puppetBeforeDie
=
this
.
puppet
this
.
puppet
=
null
this
.
inited
=
false
return
puppetBeforeDie
.
quit
()
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
quit() exception: %s
'
,
e
.
message
)
throw
e
...
...
@@ -112,7 +126,6 @@ class Wechaty extends EventEmitter {
log
.
error
(
'
Wechaty
'
,
'
logout() exception: %s
'
,
e
.
message
)
throw
e
})
}
send
(
message
)
{
...
...
@@ -129,7 +142,11 @@ class Wechaty extends EventEmitter {
throw
e
})
}
ding
(
data
)
{
ding
(
data
)
{
if
(
!
this
.
puppet
)
{
return
Promise
.
reject
(
new
Error
(
'
wechaty cant ding coz no puppet
'
))
}
return
this
.
puppet
.
ding
(
data
)
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
ding() exception: %s
'
,
e
.
message
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录