Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
0ecd31c1
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,发现更多精彩内容 >>
提交
0ecd31c1
编写于
10月 22, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
46faeb9a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
48 addition
and
28 deletion
+48
-28
example/gist/on-friend.ts
example/gist/on-friend.ts
+16
-11
example/gist/on-room-join.ts
example/gist/on-room-join.ts
+12
-4
index.ts
index.ts
+5
-1
src/friend-request.ts
src/friend-request.ts
+2
-2
src/puppet-web/friend-request.ts
src/puppet-web/friend-request.ts
+5
-4
src/room.ts
src/room.ts
+8
-6
未找到文件。
example/gist/on-friend.ts
浏览文件 @
0ecd31c1
...
...
@@ -4,25 +4,30 @@ import {
,
Room
}
from
'
../../
'
export
default
async
function
onFriend
(
contact
:
Contact
,
request
:
FriendRequest
):
Promise
<
void
>
{
export
default
async
function
onFriend
(
contact
:
Contact
,
request
?
:
FriendRequest
):
Promise
<
void
>
{
try
{
if
(
!
request
)
{
console
.
log
(
'
New friend
'
+
contact
.
name
()
+
'
relationship confirmed!
'
)
return
}
/********************************************
*
* 从这里开始修改 vvvvvvvvvvvv
*
*/
await
request
.
accept
()
if
(
request
.
hello
!==
'
上课
'
)
{
return
}
request
.
accept
()
request
.
contact
.
say
(
'
thanks for coming for
'
+
request
.
hello
)
setTimeout
(
function
()
{
contact
.
say
(
'
thank you for adding me
'
)
},
3000
)
const
myRoom
=
await
Room
.
find
({
topic
:
'
ding
'
})
myRoom
.
add
(
request
.
contact
)
if
(
request
.
hello
===
'
ding
'
)
{
const
myRoom
=
await
Room
.
find
({
topic
:
'
ding
'
})
setTimeout
(
function
()
{
myRoom
.
add
(
contact
)
myRoom
.
say
(
'
welcome
'
+
contact
.
name
())
},
3000
)
}
/**
*
...
...
example/gist/on-room-join.ts
浏览文件 @
0ecd31c1
import
{
Contact
,
Room
,
Sayable
}
from
'
../../
'
const
arrify
=
require
(
'
arrify
'
)
export
default
async
function
onRoomJoin
(
room
:
Room
this
:
Sayable
,
room
:
Room
,
invitee
:
Contact
|
Contact
[]
,
inviter
:
Contact
):
Promise
<
void
>
{
try
{
const
inviteeName
=
arrify
(
invitee
).
map
(
c
=>
c
.
name
()).
join
(
'
,
'
)
/********************************************
*
* 从这里开始修改 vvvvvvvvvvvv
...
...
@@ -19,11 +21,17 @@ export default async function onRoomJoin(
*/
if
(
room
.
topic
()
!==
'
ding
'
)
{
this
.
say
(
'
Room
'
+
room
.
topic
()
+
'
got new memeber
'
+
inviteeName
+
'
invited by
'
+
inviter
.
name
()
)
return
}
if
(
inviter
.
self
())
{
room
.
say
(
'
Welcome to my room:
'
+
arrify
(
invitee
).
join
(
'
,
'
))
const
inviterIsMyself
=
inviter
.
self
()
if
(
inviterIsMyself
)
{
room
.
say
(
'
Welcome to my room:
'
+
inviteeName
)
return
}
...
...
index.ts
浏览文件 @
0ecd31c1
import
Config
from
'
./src/config
'
import
{
Config
,
Sayable
}
from
'
./src/config
'
import
Contact
from
'
./src/contact
'
import
FriendRequest
from
'
./src/friend-request
'
import
IoClient
from
'
./src/io-client
'
...
...
@@ -23,6 +26,7 @@ export {
,
Puppet
,
PuppetWeb
,
Room
,
Sayable
,
UtilLib
,
Wechaty
,
log
// for convenionce use npmlog with environment variable LEVEL
...
...
src/friend-request.ts
浏览文件 @
0ecd31c1
...
...
@@ -25,8 +25,8 @@ abstract class FriendRequest {
}
}
public
abstract
send
(
contact
:
Contact
,
hello
:
string
):
void
public
abstract
a
ccept
():
void
public
abstract
async
send
(
contact
:
Contact
,
hello
:
string
):
Promise
<
void
>
public
abstract
a
sync
accept
():
Promise
<
void
>
}
...
...
src/puppet-web/friend-request.ts
浏览文件 @
0ecd31c1
...
...
@@ -76,7 +76,7 @@ class PuppetWebFriendRequest extends FriendRequest {
this
.
type
=
'
confirm
'
}
public
send
(
contact
:
Contact
,
hello
=
'
Hi
'
):
Promise
<
any
>
{
public
async
send
(
contact
:
Contact
,
hello
=
'
Hi
'
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebFriendRequest
'
,
'
send(%s)
'
,
contact
)
if
(
!
contact
)
{
...
...
@@ -89,11 +89,12 @@ class PuppetWebFriendRequest extends FriendRequest {
this
.
hello
=
hello
}
return
Config
.
puppetInstance
()
.
friendRequestSend
(
contact
,
hello
)
await
Config
.
puppetInstance
()
.
friendRequestSend
(
contact
,
hello
)
return
}
public
async
accept
():
Promise
<
any
>
{
public
async
accept
():
Promise
<
void
>
{
log
.
verbose
(
'
FriendRequest
'
,
'
accept() %s
'
,
this
.
contact
)
if
(
this
.
type
!==
'
receive
'
)
{
...
...
src/room.ts
浏览文件 @
0ecd31c1
...
...
@@ -220,26 +220,28 @@ export class Room extends EventEmitter implements Sayable {
Object
.
keys
(
this
.
obj
).
forEach
(
k
=>
console
.
error
(
`
${
k
}
:
${
this
.
obj
&&
this
.
obj
[
k
]}
`
))
}
public
add
(
contact
:
Contact
):
Promise
<
any
>
{
public
a
sync
a
dd
(
contact
:
Contact
):
Promise
<
any
>
{
log
.
verbose
(
'
Room
'
,
'
add(%s)
'
,
contact
)
if
(
!
contact
)
{
throw
new
Error
(
'
contact not found
'
)
}
return
Config
.
puppetInstance
()
.
roomAdd
(
this
,
contact
)
await
Config
.
puppetInstance
()
.
roomAdd
(
this
,
contact
)
return
}
public
del
(
contact
:
Contact
):
Promise
<
number
>
{
public
async
del
(
contact
:
Contact
):
Promise
<
number
>
{
log
.
verbose
(
'
Room
'
,
'
del(%s)
'
,
contact
.
name
())
if
(
!
contact
)
{
throw
new
Error
(
'
contact not found
'
)
}
return
Config
.
puppetInstance
()
const
n
=
await
Config
.
puppetInstance
()
.
roomDel
(
this
,
contact
)
.
then
(
_
=>
this
.
delLocal
(
contact
))
return
n
}
// @private
...
...
@@ -404,7 +406,7 @@ export class Room extends EventEmitter implements Sayable {
if
(
!
roomList
||
roomList
.
length
<
1
)
{
throw
new
Error
(
'
no room found
'
)
}
return
roomList
[
0
]
return
roomList
[
0
]
.
ready
()
}
public
static
load
(
id
:
string
):
Room
|
null
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录