Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
9f8da818
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
305
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9f8da818
编写于
6月 14, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
2725f1a4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
11 deletion
+26
-11
examples/room-bot.ts
examples/room-bot.ts
+6
-1
src/contact.ts
src/contact.ts
+2
-2
src/message.ts
src/message.ts
+18
-8
未找到文件。
examples/room-bot.ts
浏览文件 @
9f8da818
...
...
@@ -34,7 +34,7 @@
* vvvvvvvvv
* vvvvvvvvv
*/
const
HELPER_CONTACT_NAME
=
'
Huan LI
'
const
HELPER_CONTACT_NAME
=
'
李佳芮
'
/**
* ^^^^^^^^^
...
...
@@ -162,6 +162,11 @@ bot
* Global Event: message
*/
.
on
(
'
message
'
,
async
function
(
msg
)
{
if
(
msg
.
age
()
>
3
*
60
)
{
log
.
info
(
'
Bot
'
,
'
on(message) skip age(%d) > 3 * 60 seconds: %s
'
,
msg
.
age
(),
msg
)
return
}
const
room
=
msg
.
room
()
const
from
=
msg
.
from
()
const
text
=
msg
.
text
()
...
...
src/contact.ts
浏览文件 @
9f8da818
...
...
@@ -72,8 +72,8 @@ export class Contact extends Accessory implements Sayable {
* About the Generic: https://stackoverflow.com/q/43003970/1123955
*/
public
static
load
<
T
extends
typeof
Contact
>
(
this
:
T
,
id
:
string
,
this
:
T
,
id
:
string
,
):
T
[
'
prototype
'
]
{
if
(
!
this
.
pool
)
{
log
.
verbose
(
'
Contact
'
,
'
load(%s) init pool
'
,
id
)
...
...
src/message.ts
浏览文件 @
9f8da818
...
...
@@ -290,9 +290,11 @@ export class Message extends Accessory implements Sayable {
textOrContactOrFile
:
string
|
Contact
|
FileBox
,
mention
?
:
Contact
|
Contact
[],
):
Promise
<
void
>
{
log
.
verbose
(
'
Message
'
,
'
say(%s
,
%s)
'
,
log
.
verbose
(
'
Message
'
,
'
say(%s%s)
'
,
textOrContactOrFile
.
toString
(),
mention
,
mention
?
'
,
'
+
mention
:
''
,
)
// const user = this.puppet.userSelf()
...
...
@@ -416,8 +418,8 @@ export class Message extends Accessory implements Sayable {
* const contactList = message.mentioned()
* console.log(contactList)
*/
public
async
mention
ed
():
Promise
<
Contact
[]
>
{
log
.
verbose
(
'
Message
'
,
'
mention
ed
()
'
)
public
async
mention
():
Promise
<
Contact
[]
>
{
log
.
verbose
(
'
Message
'
,
'
mention()
'
)
const
room
=
this
.
room
()
if
(
this
.
type
()
!==
MessageType
.
Text
||
!
room
)
{
...
...
@@ -432,7 +434,7 @@ export class Message extends Accessory implements Sayable {
if
(
atList
.
length
===
0
)
return
[]
// Using `filter(e => e.indexOf('@') > -1)` to filter the string without `@`
const
rawMention
ed
List
=
atList
const
rawMentionList
=
atList
.
filter
(
str
=>
str
.
includes
(
'
@
'
))
.
map
(
str
=>
multipleAt
(
str
))
...
...
@@ -455,11 +457,11 @@ export class Message extends Accessory implements Sayable {
let
mentionNameList
:
string
[]
=
[]
// Flatten Array
// see http://stackoverflow.com/a/10865042/1123955
mentionNameList
=
mentionNameList
.
concat
.
apply
([],
rawMention
ed
List
)
mentionNameList
=
mentionNameList
.
concat
.
apply
([],
rawMentionList
)
// filter blank string
mentionNameList
=
mentionNameList
.
filter
(
s
=>
!!
s
)
log
.
verbose
(
'
Message
'
,
'
mention
ed
() text = "%s", mentionNameList = "%s"
'
,
log
.
verbose
(
'
Message
'
,
'
mention() text = "%s", mentionNameList = "%s"
'
,
this
.
text
(),
JSON
.
stringify
(
mentionNameList
),
)
...
...
@@ -474,11 +476,19 @@ export class Message extends Accessory implements Sayable {
contactList
=
contactList
.
concat
.
apply
([],
contactListNested
)
if
(
contactList
.
length
===
0
)
{
log
.
warn
(
'
Message
'
,
`message.mentioned
() can not found member using room.member() from mentionList, metion string:
${
JSON
.
stringify
(
mentionNameList
)}
`
)
log
.
silly
(
'
Message
'
,
`message.mention
() can not found member using room.member() from mentionList, metion string:
${
JSON
.
stringify
(
mentionNameList
)}
`
)
}
return
contactList
}
/**
* @deprecated: use mention() instead
*/
public
async
mentioned
():
Promise
<
Contact
[]
>
{
log
.
warn
(
'
Message
'
,
'
mentioned() DEPRECATED. use mention() instead.
'
)
return
this
.
mention
()
}
/**
* @private
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录