Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
f7b3d5d7
W
wechaty
项目概览
.Veneno.
/
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,发现更多精彩内容 >>
提交
f7b3d5d7
编写于
6月 12, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make tslint happy
上级
8a354c42
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
60 addition
and
39 deletion
+60
-39
examples/friend-bot.ts
examples/friend-bot.ts
+7
-7
examples/gist-bot/index.ts
examples/gist-bot/index.ts
+4
-4
examples/gist-bot/on-friend.ts
examples/gist-bot/on-friend.ts
+1
-1
src/puppet-padchat/puppet-padchat.ts
src/puppet-padchat/puppet-padchat.ts
+1
-1
src/puppet-padchat/pure-function-helpers/friend-request-event-message-parser.ts
...e-function-helpers/friend-request-event-message-parser.ts
+27
-10
src/puppet-puppeteer/event.ts
src/puppet-puppeteer/event.ts
+1
-1
src/puppet-puppeteer/firer.ts
src/puppet-puppeteer/firer.ts
+1
-1
src/puppet-wechat4u/puppet-wechat4u.ts
src/puppet-wechat4u/puppet-wechat4u.ts
+2
-2
src/puppet/puppet.ts
src/puppet/puppet.ts
+2
-2
src/puppet/schemas/puppet.ts
src/puppet/schemas/puppet.ts
+1
-1
src/wechaty.ts
src/wechaty.ts
+13
-9
未找到文件。
examples/friend-bot.ts
浏览文件 @
f7b3d5d7
...
...
@@ -76,16 +76,16 @@ bot
* Wechaty Event: `friend`
*
*/
.
on
(
'
friend
'
,
async
request
=>
{
.
on
(
'
friend
ship
'
,
async
friendship
=>
{
let
logMsg
const
fileHelper
=
bot
.
Contact
.
load
(
'
filehelper
'
)
try
{
logMsg
=
'
received `friend` event from
'
+
request
.
contact
().
name
()
logMsg
=
'
received `friend` event from
'
+
friendship
.
contact
().
name
()
fileHelper
.
say
(
logMsg
)
console
.
log
(
logMsg
)
switch
(
request
.
type
())
{
switch
(
friendship
.
type
())
{
/**
*
* 1. New Friend Request
...
...
@@ -94,14 +94,14 @@ bot
* and accept this request by `request.accept()`
*/
case
Friendship
.
Type
.
Receive
:
if
(
request
.
hello
()
===
'
ding
'
)
{
if
(
friendship
.
hello
()
===
'
ding
'
)
{
logMsg
=
'
accepted automatically because verify messsage is "ding"
'
console
.
log
(
'
before accept
'
)
await
request
.
accept
()
await
friendship
.
accept
()
console
.
log
(
'
after accept
'
)
}
else
{
logMsg
=
'
not auto accepted, because verify message is:
'
+
request
.
hello
()
logMsg
=
'
not auto accepted, because verify message is:
'
+
friendship
.
hello
()
}
break
...
...
@@ -111,7 +111,7 @@ bot
*
*/
case
Friendship
.
Type
.
Confirm
:
logMsg
=
'
friend ship confirmed with
'
+
request
.
contact
().
name
()
logMsg
=
'
friend ship confirmed with
'
+
friendship
.
contact
().
name
()
break
}
}
catch
(
e
)
{
...
...
examples/gist-bot/index.ts
浏览文件 @
f7b3d5d7
...
...
@@ -28,9 +28,9 @@ import {
log
,
}
from
'
../../src/
'
import
{
onMessage
}
from
'
./on-message
'
import
{
onFriend
}
from
'
./on-friend
'
import
{
onRoomJoin
}
from
'
./on-room-join
'
import
{
onMessage
}
from
'
./on-message
'
import
{
onFriend
ship
}
from
'
./on-friend
'
import
{
onRoomJoin
}
from
'
./on-room-join
'
const
welcome
=
`
=============== Powered by Wechaty ===============
...
...
@@ -61,7 +61,7 @@ bot
.
on
(
'
error
'
,
error
=>
log
.
info
(
'
Bot
'
,
'
error: %s
'
,
error
))
.
on
(
'
message
'
,
onMessage
)
.
on
(
'
friend
'
,
onFriend
)
.
on
(
'
friend
ship
'
,
onFriendship
)
.
on
(
'
room-join
'
,
onRoomJoin
)
.
start
()
...
...
examples/gist-bot/on-friend.ts
浏览文件 @
f7b3d5d7
...
...
@@ -28,7 +28,7 @@ import {
// Room,
}
from
'
../../src/
'
export
async
function
onFriend
(
export
async
function
onFriend
ship
(
this
:
Wechaty
,
request
:
Friendship
,
):
Promise
<
void
>
{
...
...
src/puppet-padchat/puppet-padchat.ts
浏览文件 @
f7b3d5d7
...
...
@@ -256,7 +256,7 @@ export class PuppetPadchat extends Puppet {
rawPayload
.
msg_id
,
rawPayload
,
)
this
.
emit
(
'
friend
'
,
rawPayload
.
msg_id
)
this
.
emit
(
'
friend
ship
'
,
rawPayload
.
msg_id
)
break
case
PadchatMessageType
.
Sys
:
...
...
src/puppet-padchat/pure-function-helpers/friend-request-event-message-parser.ts
浏览文件 @
f7b3d5d7
// import {
// YOU,
// } from '../../puppet/'
import
{
PadchatMessagePayload
}
from
'
../padchat-schemas
'
const
FRIENDSHIP_CONFIRM_REGEX_LIST
=
[
/^You have added
(
.+
)
as your WeChat contact. Start chatting!$/
,
/^你已添加了
(
.+
)
,现在可以开始聊天了。$/
,
/^
(
.+
)
just added you to his
\/
her contacts list. Send a message to him
\/
her now!$/
,
/^
(
.+
)
刚刚把你添加到通讯录,现在可以开始聊天了。$/
,
]
export
function
friendRequestEventMessageParser
(
rawPayload
:
PadchatMessagePayload
):
null
|
string
{
return
rawPayload
.
msg_id
// // const reList = regexConfig.friendConfirm
// // let found = false
// // reList.some(re => !!(found = re.test(content)))
// // if (found) {
// // return true
// // } else {
// // return false
// // }
let
matches
:
null
|
RegExpMatchArray
=
null
as
any
const
text
=
rawPayload
.
content
FRIENDSHIP_CONFIRM_REGEX_LIST
.
some
(
regexp
=>
{
matches
=
text
.
match
(
regexp
)
return
!!
matches
},
)
if
(
!
matches
)
{
return
null
}
return
matches
[
0
]
}
src/puppet-puppeteer/event.ts
浏览文件 @
f7b3d5d7
...
...
@@ -199,7 +199,7 @@ async function onMessage(
switch
(
rawPayload
.
MsgType
)
{
case
WebMessageType
.
VERIFYMSG
:
this
.
emit
(
'
friend
'
,
rawPayload
.
MsgId
)
this
.
emit
(
'
friend
ship
'
,
rawPayload
.
MsgId
)
// firer.checkFriendRequest(rawPayload)
break
...
...
src/puppet-puppeteer/firer.ts
浏览文件 @
f7b3d5d7
...
...
@@ -156,7 +156,7 @@ export class Firer {
// this.puppet.cacheFriendRequestPayload.set(id, payloadConfirm)
this
.
puppet
.
emit
(
'
friend
'
,
rawPayload
.
MsgId
)
this
.
puppet
.
emit
(
'
friend
ship
'
,
rawPayload
.
MsgId
)
}
public
async
checkRoomJoin
(
...
...
src/puppet-wechat4u/puppet-wechat4u.ts
浏览文件 @
f7b3d5d7
...
...
@@ -232,12 +232,12 @@ export class PuppetWechat4u extends Puppet {
break
case
WebMessageType
.
VERIFYMSG
:
this
.
emit
(
'
friend
'
,
msg
.
MsgId
)
this
.
emit
(
'
friend
ship
'
,
msg
.
MsgId
)
break
case
WebMessageType
.
SYS
:
if
(
this
.
isFriendConfirm
(
msg
.
Content
))
{
this
.
emit
(
'
friend
'
,
msg
.
MsgId
)
this
.
emit
(
'
friend
ship
'
,
msg
.
MsgId
)
}
this
.
emit
(
'
message
'
,
msg
.
MsgId
)
break
...
...
src/puppet/puppet.ts
浏览文件 @
f7b3d5d7
...
...
@@ -185,7 +185,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*
*/
public
emit
(
event
:
'
error
'
,
error
:
string
)
:
boolean
public
emit
(
event
:
'
friend
'
,
requestId
:
string
)
:
boolean
public
emit
(
event
:
'
friend
ship
'
,
friendshipId
:
string
)
:
boolean
public
emit
(
event
:
'
login
'
,
contactId
:
string
)
:
boolean
public
emit
(
event
:
'
logout
'
,
contactId
:
string
)
:
boolean
public
emit
(
event
:
'
message
'
,
messageId
:
string
)
:
boolean
...
...
@@ -215,7 +215,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*
*/
public
on
(
event
:
'
error
'
,
listener
:
(
error
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
friend
'
,
listener
:
(
requestId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
friend
ship
'
,
listener
:
(
friendshipId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
login
'
,
listener
:
(
contactId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
logout
'
,
listener
:
(
contactId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
message
'
,
listener
:
(
messageId
:
string
)
=>
void
)
:
this
...
...
src/puppet/schemas/puppet.ts
浏览文件 @
f7b3d5d7
...
...
@@ -44,7 +44,7 @@ export interface PuppetRoomTopicEvent {
}
export
const
CHAT_EVENT_DICT
=
{
friend
:
'
document can be writen at here
'
,
friend
ship
:
'
document can be writen at here
'
,
login
:
'
document can be writen at here
'
,
logout
:
'
document can be writen at here
'
,
message
:
'
document can be writen at here
'
,
...
...
src/wechaty.ts
浏览文件 @
f7b3d5d7
...
...
@@ -246,7 +246,7 @@ export class Wechaty extends Accessory implements Sayable {
}
public
emit
(
event
:
'
error
'
,
error
:
Error
)
:
boolean
public
emit
(
event
:
'
friend
'
,
request
:
Friendship
)
:
boolean
public
emit
(
event
:
'
friend
ship
'
,
friendship
:
Friendship
)
:
boolean
public
emit
(
event
:
'
heartbeat
'
,
data
:
any
)
:
boolean
public
emit
(
event
:
'
logout
'
,
user
:
ContactSelf
)
:
boolean
public
emit
(
event
:
'
login
'
,
user
:
ContactSelf
)
:
boolean
...
...
@@ -269,7 +269,7 @@ export class Wechaty extends Accessory implements Sayable {
}
public
on
(
event
:
'
error
'
,
listener
:
string
|
((
this
:
Wechaty
,
error
:
Error
)
=>
void
))
:
this
public
on
(
event
:
'
friend
'
,
listener
:
string
|
((
this
:
Wechaty
,
request
:
Friendship
)
=>
void
))
:
this
public
on
(
event
:
'
friend
ship
'
,
listener
:
string
|
((
this
:
Wechaty
,
friendship
:
Friendship
)
=>
void
))
:
this
public
on
(
event
:
'
heartbeat
'
,
listener
:
string
|
((
this
:
Wechaty
,
data
:
any
)
=>
void
))
:
this
public
on
(
event
:
'
logout
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
ContactSelf
)
=>
void
))
:
this
public
on
(
event
:
'
login
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
ContactSelf
)
=>
void
))
:
this
...
...
@@ -553,13 +553,17 @@ export class Wechaty extends Accessory implements Sayable {
// } )
// break
case
'
friend
'
:
puppet
.
removeAllListeners
(
'
friend
'
)
puppet
.
on
(
'
friend
'
,
async
requestId
=>
{
const
request
=
this
.
Friendship
.
load
(
requestId
)
await
request
.
ready
()
this
.
emit
(
'
friend
'
,
request
)
request
.
contact
().
emit
(
'
friend
'
,
request
)
case
'
friendship
'
:
puppet
.
removeAllListeners
(
'
friendship
'
)
puppet
.
on
(
'
friendship
'
,
async
friendshipId
=>
{
const
friendship
=
this
.
Friendship
.
load
(
friendshipId
)
await
friendship
.
ready
()
this
.
emit
(
'
friendship
'
,
friendship
)
friendship
.
contact
().
emit
(
'
friendship
'
,
friendship
)
// support deprecated event name: friend.
// Huan LI 201806
this
.
emit
(
'
friend
'
as
any
,
friendship
as
any
)
})
break
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录