Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
0064056c
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,发现更多精彩内容 >>
提交
0064056c
编写于
6月 18, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add: Wechaty.self() to test if a message is from self. del: Message.self()
上级
d6110329
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
33 addition
and
26 deletion
+33
-26
example/api-ai-bot.js
example/api-ai-bot.js
+1
-1
example/ding-dong-bot.js
example/ding-dong-bot.js
+2
-2
example/roger-bot.js
example/roger-bot.js
+1
-1
example/tuling123-bot.js
example/tuling123-bot.js
+1
-1
src/message.js
src/message.js
+0
-10
src/puppet-web-event.js
src/puppet-web-event.js
+6
-6
src/puppet-web.js
src/puppet-web.js
+14
-4
src/wechaty.js
src/wechaty.js
+8
-1
未找到文件。
example/api-ai-bot.js
浏览文件 @
0064056c
...
@@ -46,7 +46,7 @@ bot
...
@@ -46,7 +46,7 @@ bot
.
on
(
'
login
'
,
user
=>
log
.
info
(
'
Bot
'
,
`bot login:
${
user
}
`
))
.
on
(
'
login
'
,
user
=>
log
.
info
(
'
Bot
'
,
`bot login:
${
user
}
`
))
.
on
(
'
logout
'
,
e
=>
log
.
info
(
'
Bot
'
,
'
bot logout.
'
))
.
on
(
'
logout
'
,
e
=>
log
.
info
(
'
Bot
'
,
'
bot logout.
'
))
.
on
(
'
message
'
,
m
=>
{
.
on
(
'
message
'
,
m
=>
{
if
(
m
.
self
(
))
{
return
}
if
(
bot
.
self
(
m
))
{
return
}
co
(
function
*
()
{
co
(
function
*
()
{
const
msg
=
yield
m
.
ready
()
const
msg
=
yield
m
.
ready
()
...
...
example/ding-dong-bot.js
浏览文件 @
0064056c
...
@@ -32,11 +32,11 @@ bot
...
@@ -32,11 +32,11 @@ bot
.
on
(
'
login
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logined`
))
.
on
(
'
login
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logined`
))
.
on
(
'
logout
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logouted`
))
.
on
(
'
logout
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logouted`
))
.
on
(
'
scan
'
,
({
url
,
code
})
=>
{
.
on
(
'
scan
'
,
({
url
,
code
})
=>
{
console
.
log
(
`Scan QR Code in url to login:
${
code
}
\n
${
url
}
`
)
if
(
!
/201|200/
.
test
(
code
))
{
if
(
!
/201|200/
.
test
(
code
))
{
let
loginUrl
=
url
.
replace
(
/
\/
qrcode
\/
/
,
'
/l/
'
)
let
loginUrl
=
url
.
replace
(
/
\/
qrcode
\/
/
,
'
/l/
'
)
require
(
'
qrcode-terminal
'
).
generate
(
loginUrl
)
require
(
'
qrcode-terminal
'
).
generate
(
loginUrl
)
}
}
console
.
log
(
`
${
url
}
\n[
${
code
}
] Scan QR Code in above url to login: `
)
})
})
.
on
(
'
message
'
,
m
=>
{
.
on
(
'
message
'
,
m
=>
{
m
.
ready
()
m
.
ready
()
...
@@ -44,7 +44,7 @@ bot
...
@@ -44,7 +44,7 @@ bot
log
.
info
(
'
Bot
'
,
'
recv: %s
'
,
msg
.
toStringEx
())
log
.
info
(
'
Bot
'
,
'
recv: %s
'
,
msg
.
toStringEx
())
// logToFile(JSON.stringify(msg.rawObj))
// logToFile(JSON.stringify(msg.rawObj))
if
(
/^
(
ding|ping|bing
)
$/i
.
test
(
m
.
get
(
'
content
'
))
&&
!
m
.
self
(
))
{
if
(
/^
(
ding|ping|bing
)
$/i
.
test
(
m
.
get
(
'
content
'
))
&&
!
bot
.
self
(
m
))
{
bot
.
reply
(
m
,
'
dong
'
)
bot
.
reply
(
m
,
'
dong
'
)
.
then
(()
=>
{
log
.
warn
(
'
Bot
'
,
'
REPLY: dong
'
)
})
.
then
(()
=>
{
log
.
warn
(
'
Bot
'
,
'
REPLY: dong
'
)
})
}
}
...
...
example/roger-bot.js
浏览文件 @
0064056c
...
@@ -6,7 +6,7 @@ bot
...
@@ -6,7 +6,7 @@ bot
console
.
log
(
`Use Wechat to Scan QR Code in url to login:
${
code
}
\n
${
url
}
`
)
console
.
log
(
`Use Wechat to Scan QR Code in url to login:
${
code
}
\n
${
url
}
`
)
})
})
.
on
(
'
message
'
,
m
=>
{
.
on
(
'
message
'
,
m
=>
{
(
!
m
.
self
(
))
&&
bot
.
reply
(
m
,
'
roger
'
)
// 1. reply others' msg
(
!
bot
.
self
(
m
))
&&
bot
.
reply
(
m
,
'
roger
'
)
// 1. reply others' msg
.
then
(()
=>
console
.
log
(
`RECV:
${
m
}
, REPLY: "roger"`
))
// 2. log message
.
then
(()
=>
console
.
log
(
`RECV:
${
m
}
, REPLY: "roger"`
))
// 2. log message
.
catch
(
e
=>
console
.
error
(
e
))
// 3. catch exception
.
catch
(
e
=>
console
.
error
(
e
))
// 3. catch exception
})
})
...
...
example/tuling123-bot.js
浏览文件 @
0064056c
...
@@ -47,7 +47,7 @@ bot
...
@@ -47,7 +47,7 @@ bot
console
.
log
(
`Scan QR Code in url to login: w
${
code
}
\n
${
url
}
`
)
console
.
log
(
`Scan QR Code in url to login: w
${
code
}
\n
${
url
}
`
)
})
})
.
on
(
'
message
'
,
m
=>
{
.
on
(
'
message
'
,
m
=>
{
if
(
m
.
self
(
))
return
if
(
bot
.
self
(
m
))
return
co
(
function
*
()
{
co
(
function
*
()
{
const
msg
=
yield
m
.
ready
()
const
msg
=
yield
m
.
ready
()
...
...
src/message.js
浏览文件 @
0064056c
...
@@ -34,8 +34,6 @@ class Message {
...
@@ -34,8 +34,6 @@ class Message {
,
status
:
rawObj
.
Status
,
status
:
rawObj
.
Status
,
digest
:
rawObj
.
MMDigest
,
digest
:
rawObj
.
MMDigest
,
date
:
rawObj
.
MMDisplayTime
// Javascript timestamp of milliseconds
,
date
:
rawObj
.
MMDisplayTime
// Javascript timestamp of milliseconds
,
self
:
undefined
// to store the logined user id
}
}
// FIXME: has ther any better method to know the room ID?
// FIXME: has ther any better method to know the room ID?
...
@@ -87,14 +85,6 @@ class Message {
...
@@ -87,14 +85,6 @@ class Message {
typeEx
()
{
return
Message
.
Type
[
this
.
obj
.
type
]
}
typeEx
()
{
return
Message
.
Type
[
this
.
obj
.
type
]
}
count
()
{
return
Message
.
counter
}
count
()
{
return
Message
.
counter
}
self
()
{
if
(
!
this
.
obj
.
self
)
{
log
.
warn
(
'
Message
'
,
'
self not set
'
)
return
false
}
return
this
.
obj
.
self
===
this
.
obj
.
from
}
ready
()
{
ready
()
{
log
.
silly
(
'
Message
'
,
'
ready()
'
)
log
.
silly
(
'
Message
'
,
'
ready()
'
)
...
...
src/puppet-web-event.js
浏览文件 @
0064056c
...
@@ -210,16 +210,16 @@ function onServerLogin(data) {
...
@@ -210,16 +210,16 @@ function onServerLogin(data) {
/**
/**
* save login user id to this.userId
* save login user id to this.userId
*/
*/
const
userName
=
this
.
userId
=
yield
this
.
bridge
.
getUserName
()
this
.
userId
=
yield
this
.
bridge
.
getUserName
()
if
(
!
userName
)
{
if
(
!
this
.
userId
)
{
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onServerLogin: browser not full loaded, retry later.
'
)
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onServerLogin: browser not full loaded, retry later.
'
)
setTimeout
(
onServerLogin
.
bind
(
this
),
500
)
setTimeout
(
onServerLogin
.
bind
(
this
),
500
)
return
return
}
}
log
.
verbose
(
'
PuppetWebEvent
'
,
'
bridge.getUserName: %s
'
,
userName
)
log
.
verbose
(
'
PuppetWebEvent
'
,
'
bridge.getUserName: %s
'
,
this
.
userId
)
this
.
user
=
yield
Contact
.
load
(
userName
).
ready
()
this
.
user
=
yield
Contact
.
load
(
this
.
userId
).
ready
()
log
.
verbose
(
'
PuppetWebEvent
'
,
`onServerLogin() user
${
this
.
user
.
name
()}
logined`
)
log
.
verbose
(
'
PuppetWebEvent
'
,
`onServerLogin() user
${
this
.
user
.
name
()}
logined`
)
this
.
emit
(
'
login
'
,
this
.
user
)
this
.
emit
(
'
login
'
,
this
.
user
)
...
@@ -263,8 +263,8 @@ function onServerMessage(data) {
...
@@ -263,8 +263,8 @@ function onServerMessage(data) {
break
;
break
;
}
}
if
(
this
.
user
)
{
if
(
this
.
user
Id
)
{
m
.
set
(
'
self
'
,
this
.
user
.
i
d
)
m
.
set
(
'
self
'
,
this
.
user
I
d
)
}
else
{
}
else
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onServerMessage() without this.user
'
)
log
.
warn
(
'
PuppetWebEvent
'
,
'
onServerMessage() without this.user
'
)
}
}
...
...
src/puppet-web.js
浏览文件 @
0064056c
...
@@ -42,7 +42,8 @@ class PuppetWeb extends Puppet {
...
@@ -42,7 +42,8 @@ class PuppetWeb extends Puppet {
this
.
head
=
options
.
head
this
.
head
=
options
.
head
this
.
session
=
options
.
session
// if not set session, then dont store session.
this
.
session
=
options
.
session
// if not set session, then dont store session.
this
.
user
=
null
// <Contact> of user self
this
.
userId
=
null
// user id
this
.
user
=
null
// <Contact> of user self
}
}
toString
()
{
return
`Class PuppetWeb({browser:
${
this
.
browser
}
,port:
${
this
.
port
}
})`
}
toString
()
{
return
`Class PuppetWeb({browser:
${
this
.
browser
}
,port:
${
this
.
port
}
})`
}
...
@@ -235,6 +236,17 @@ class PuppetWeb extends Puppet {
...
@@ -235,6 +236,17 @@ class PuppetWeb extends Puppet {
return
Event
.
onBrowserDead
.
call
(
this
,
e
)
return
Event
.
onBrowserDead
.
call
(
this
,
e
)
}
}
self
(
message
)
{
if
(
!
this
.
userId
)
{
log
.
verbose
(
'
PuppetWeb
'
,
'
self() got no this.userId
'
)
return
false
}
if
(
!
message
||
!
message
.
id
)
{
log
.
verbose
(
'
PuppetWeb
'
,
'
self() got no message
'
)
return
false
}
return
this
.
userId
==
message
.
get
(
'
from
'
)
}
send
(
message
)
{
send
(
message
)
{
const
to
=
message
.
get
(
'
to
'
)
const
to
=
message
.
get
(
'
to
'
)
const
room
=
message
.
get
(
'
room
'
)
const
room
=
message
.
get
(
'
room
'
)
...
@@ -268,10 +280,8 @@ class PuppetWeb extends Puppet {
...
@@ -268,10 +280,8 @@ class PuppetWeb extends Puppet {
.
set
(
'
to
'
,
message
.
obj
.
from
)
.
set
(
'
to
'
,
message
.
obj
.
from
)
.
set
(
'
room
'
,
message
.
obj
.
room
)
.
set
(
'
room
'
,
message
.
obj
.
room
)
if
(
this
.
user
)
{
if
(
this
.
user
Id
)
{
// FIXME: find a alternate way to check a message create by `self`
// FIXME: find a alternate way to check a message create by `self`
m
.
set
(
'
self
'
,
this
.
user
.
id
)
}
else
if
(
this
.
userId
)
{
m
.
set
(
'
self
'
,
this
.
userId
)
m
.
set
(
'
self
'
,
this
.
userId
)
}
}
else
{
else
{
...
...
src/wechaty.js
浏览文件 @
0064056c
...
@@ -129,7 +129,14 @@ class Wechaty extends EventEmitter {
...
@@ -129,7 +129,14 @@ class Wechaty extends EventEmitter {
})
})
}
}
send
(
message
)
{
self
(
message
)
{
return
this
.
puppet
.
self
(
message
)
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
self() exception: %s
'
,
e
.
message
)
throw
e
})
}
send
(
message
)
{
return
this
.
puppet
.
send
(
message
)
return
this
.
puppet
.
send
(
message
)
.
catch
(
e
=>
{
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
send() exception: %s
'
,
e
.
message
)
log
.
error
(
'
Wechaty
'
,
'
send() exception: %s
'
,
e
.
message
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录