Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
2718ba98
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,体验更适合开发者的 AI 搜索 >>
提交
2718ba98
编写于
5月 10, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
contact class worked!
上级
c97d65a5
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
109 addition
and
31 deletion
+109
-31
src/contact.js
src/contact.js
+55
-0
src/group.js
src/group.js
+9
-0
src/message.js
src/message.js
+20
-16
src/puppet-web-injectio.js
src/puppet-web-injectio.js
+10
-9
src/puppet-web.js
src/puppet-web.js
+3
-6
src/puppet.js
src/puppet.js
+2
-0
src/wechaty.js
src/wechaty.js
+10
-0
未找到文件。
src/contact.js
浏览文件 @
2718ba98
/**
*
* wechaty: Wechat for Bot. and for human who talk to bot/robot
*
* Licenst: ISC
* https://github.com/zixia/wechaty
*
*/
class
Contact
{
constructor
(
id
)
{
if
(
!
Contact
.
puppet
)
throw
new
Error
(
'
no puppet attached to Contact
'
);
this
.
id
=
id
this
.
obj
=
{}
Contact
.
puppet
.
getContact
(
id
)
.
then
(
data
=>
{
this
.
rawObj
=
data
this
.
obj
=
this
.
parse
(
this
.
rawObj
)
}).
catch
(
e
=>
{
throw
new
Error
(
'
getContact:
'
+
e
)
})
}
parse
(
rawObj
)
{
return
!
rawObj
?
{}
:
{
id
:
rawObj
.
UserName
,
weixin
:
rawObj
.
Alias
,
name
:
rawObj
.
NickName
,
remark
:
rawObj
.
RemarkName
,
sex
:
rawObj
.
Sex
,
province
:
rawObj
.
Province
,
city
:
rawObj
.
City
,
signature
:
rawObj
.
Signature
}
}
dumpRaw
()
{
console
.
error
(
'
======= dump raw contact =======
'
)
Object
.
keys
(
this
.
rawObj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
rawObj
[
k
]}
`
))
}
dump
()
{
console
.
error
(
'
======= dump contact =======
'
)
Object
.
keys
(
this
.
obj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
obj
[
k
]}
`
))
}
toString
()
{
return
`Contact({id:
${
this
.
id
}
)`
}
getId
()
{
return
this
.
id
}
get
(
prop
)
{
return
this
.
obj
[
prop
]
}
send
(
message
)
{
}
...
...
@@ -21,4 +66,14 @@ class Contact {
}
}
Contact
.
pool
=
{}
Contact
.
load
=
function
(
id
)
{
if
(
id
in
Contact
.
pool
)
{
return
Contact
.
pool
[
id
]
}
return
Contact
.
pool
[
id
]
=
new
Contact
(
id
)
}
Contact
.
attach
=
function
(
puppet
)
{
Contact
.
puppet
=
puppet
}
module
.
exports
=
Contact
src/group.js
浏览文件 @
2718ba98
/**
*
* wechaty: Wechat for Bot. and for human who talk to bot/robot
*
* Licenst: ISC
* https://github.com/zixia/wechaty
*
*/
class
Group
{
constructor
(
id
)
{
this
.
id
=
id
...
...
src/message.js
浏览文件 @
2718ba98
//const EventEmitter = require('events')
/**
*
* wechaty: Wechat for Bot. and for human who talk to bot/robot
*
* Licenst: ISC
* https://github.com/zixia/wechaty
*
*/
const
Contact
=
require
(
'
./contact
'
)
const
Group
=
require
(
'
./group
'
)
...
...
@@ -7,11 +15,11 @@ class Message {
this
.
rawObj
=
rawObj
=
rawObj
||
{}
// Transform rawObj to local m
this
.
m
=
{
this
.
obj
=
{
id
:
rawObj
.
MsgId
,
type
:
rawObj
.
MsgType
,
from
:
new
Contact
(
rawObj
.
MMActualSender
)
,
to
:
new
Contact
(
rawObj
.
MMPeerUserName
)
,
from
:
Contact
.
load
(
rawObj
.
MMActualSender
)
,
to
:
Contact
.
load
(
rawObj
.
MMPeerUserName
)
,
group
:
rawObj
.
MMIsChatRoom
?
new
Group
(
rawObj
.
FromUserName
)
:
null
,
content
:
rawObj
.
MMActualContent
,
status
:
rawObj
.
Status
...
...
@@ -23,31 +31,27 @@ class Message {
}
toString
()
{
const
id
=
this
.
m
.
id
// Contact
const
from
=
this
.
m
.
from
.
getId
()
const
to
=
this
.
m
.
to
.
getId
()
//return `Message({id:${id}, from:${from}, to:${to})`
let
content
=
this
.
m
.
content
const
name
=
this
.
obj
.
from
.
get
(
'
name
'
)
let
content
=
this
.
obj
.
content
if
(
content
.
length
>
20
)
content
=
content
.
substring
(
0
,
17
)
+
'
...
'
;
return
`Message("
${
content
}
")`
return
`Message("
${
name
}
:
${
content
}
")`
}
get
(
prop
)
{
if
(
!
prop
||
!
(
prop
in
this
.
m
))
{
const
s
=
'
[
'
+
Object
.
keys
(
this
.
m
).
join
(
'
,
'
)
+
'
]
'
if
(
!
prop
||
!
(
prop
in
this
.
obj
))
{
const
s
=
'
[
'
+
Object
.
keys
(
this
.
obj
).
join
(
'
,
'
)
+
'
]
'
throw
new
Error
(
`Message.get(
${
prop
}
) must be in:
${
s
}
`
)
}
return
this
.
m
[
prop
]
return
this
.
obj
[
prop
]
}
set
(
prop
,
value
)
{
this
.
m
[
prop
]
=
value
this
.
obj
[
prop
]
=
value
}
dump
()
{
console
.
error
(
'
======= dump message =======
'
)
Object
.
keys
(
this
.
m
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
m
[
k
]}
`
))
Object
.
keys
(
this
.
obj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
obj
[
k
]}
`
))
}
dumpRaw
()
{
console
.
error
(
'
======= dump raw message =======
'
)
...
...
src/puppet-web-injectio.js
浏览文件 @
2718ba98
...
...
@@ -57,16 +57,14 @@ if (typeof Wechaty!=='undefined') return 'Wechaty already injected?';
,
slog
:
slog
// log throw Socket IO
,
ding
:
ding
,
quit
:
quit
,
getContact
:
getContact
}
function
isReady
()
{
return
!!
((
typeof
angular
)
!==
'
undefined
'
&&
angular
.
element
&&
angular
.
element
(
"
body
"
))
}
function
init
()
{
// XXX
// return 'init skiped in browser'
if
(
!
isReady
())
{
clog
(
'
angular not ready. wait 500ms...
'
)
setTimeout
(
init
,
500
)
...
...
@@ -87,8 +85,9 @@ if (typeof Wechaty!=='undefined') return 'Wechaty already injected?';
var
injector
=
angular
.
element
(
document
).
injector
()
var
rootScope
=
injector
.
get
(
"
$rootScope
"
)
var
http
=
injector
.
get
(
"
$http
"
)
var
chatFactory
=
injector
.
get
(
"
chatFactory
"
)
var
confFactory
=
injector
.
get
(
"
confFactory
"
)
var
chatFactory
=
injector
.
get
(
"
chatFactory
"
)
var
confFactory
=
injector
.
get
(
"
confFactory
"
)
var
contactFactory
=
injector
.
get
(
'
contactFactory
'
)
var
loginScope
=
angular
.
element
(
"
.login_box
"
).
scope
()
// get all we need from wx in browser(angularjs)
...
...
@@ -96,8 +95,9 @@ if (typeof Wechaty!=='undefined') return 'Wechaty already injected?';
injector
:
injector
,
rootScope
:
rootScope
,
http
:
http
,
chatFactory
:
chatFactory
,
confFactory
:
confFactory
,
chatFactory
:
chatFactory
,
confFactory
:
confFactory
,
contactFactory
:
contactFactory
,
loginScope
:
loginScope
}
}
...
...
@@ -122,6 +122,7 @@ if (typeof Wechaty!=='undefined') return 'Wechaty already injected?';
chat
.
appendMessage
(
m
)
return
chat
.
sendMessage
(
m
)
}
function
getContact
(
id
)
{
return
Wechaty
.
glue
.
contactFactory
.
getContact
(
id
)
}
function
hookMessage
()
{
var
rootScope
=
Wechaty
.
glue
.
rootScope
rootScope
.
$on
(
"
message:add:success
"
,
function
(
event
,
data
)
{
...
...
@@ -174,7 +175,7 @@ if (typeof Wechaty!=='undefined') return 'Wechaty already injected?';
var
callback
=
arguments
[
arguments
.
length
-
1
]
if
(
typeof
callback
===
'
function
'
)
callback
(
'
Wechaty
'
)
return
callback
(
'
Wechaty
'
)
return
'
Wechaty
'
...
...
src/puppet-web.js
浏览文件 @
2718ba98
...
...
@@ -96,12 +96,9 @@ class PuppetWeb extends Puppet {
* Public Methods
*
*/
getLoginQrImgUrl
()
{
return
this
.
server
.
proxyWechaty
(
'
getLoginQrImgUrl
'
)
}
getLoginStatusCode
()
{
return
this
.
server
.
proxyWechaty
(
'
getLoginStatusCode
'
)
}
getLoginQrImgUrl
()
{
return
this
.
server
.
proxyWechaty
(
'
getLoginQrImgUrl
'
)
}
getLoginStatusCode
()
{
return
this
.
server
.
proxyWechaty
(
'
getLoginStatusCode
'
)
}
getContact
(
id
)
{
return
this
.
server
.
proxyWechaty
(
'
getContact
'
,
id
)
}
}
module
.
exports
=
PuppetWeb
src/puppet.js
浏览文件 @
2718ba98
...
...
@@ -32,6 +32,8 @@ class Puppet extends EventEmitter {
logout
()
{
throw
new
Error
(
'
To Be Implementsd
'
)
}
alive
()
{
throw
new
Error
(
'
To Be Implementsd
'
)
}
getContact
()
{
throw
new
Error
(
'
To Be Implementsd
'
)
}
// () { throw new Error('To Be Implemented') }
/**
...
...
src/wechaty.js
浏览文件 @
2718ba98
/**
*
* wechaty: Wechat for Bot. and for human who talk to bot/robot
*
* Licenst: ISC
* https://github.com/zixia/wechaty
*
*/
const
EventEmitter
=
require
(
'
events
'
)
//const Util = require('util');
...
...
@@ -23,6 +32,7 @@ class Wechaty extends EventEmitter {
throw
new
Error
(
'
Puppet unknown:
'
+
puppet
)
break
}
Contact
.
attach
(
this
.
puppet
)
this
.
puppet
.
on
(
'
message
'
,
(
e
)
=>
{
this
.
emit
(
'
message
'
,
e
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录