提交 9f8da818 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 2725f1a4
......@@ -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()
......
......@@ -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)
......
......@@ -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 mentioned(): Promise<Contact[]> {
log.verbose('Message', 'mentioned()')
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 rawMentionedList = 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([], rawMentionedList)
mentionNameList = mentionNameList.concat.apply([], rawMentionList)
// filter blank string
mentionNameList = mentionNameList.filter(s => !!s)
log.verbose('Message', 'mentioned() 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.
先完成此消息的编辑!
想要评论请 注册