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

code clean

上级 2725f1a4
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* vvvvvvvvv * vvvvvvvvv
* vvvvvvvvv * vvvvvvvvv
*/ */
const HELPER_CONTACT_NAME = 'Huan LI' const HELPER_CONTACT_NAME = '李佳芮'
/** /**
* ^^^^^^^^^ * ^^^^^^^^^
...@@ -162,6 +162,11 @@ bot ...@@ -162,6 +162,11 @@ bot
* Global Event: message * Global Event: message
*/ */
.on('message', async function(msg) { .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 room = msg.room()
const from = msg.from() const from = msg.from()
const text = msg.text() const text = msg.text()
......
...@@ -72,8 +72,8 @@ export class Contact extends Accessory implements Sayable { ...@@ -72,8 +72,8 @@ export class Contact extends Accessory implements Sayable {
* About the Generic: https://stackoverflow.com/q/43003970/1123955 * About the Generic: https://stackoverflow.com/q/43003970/1123955
*/ */
public static load<T extends typeof Contact>( public static load<T extends typeof Contact>(
this : T, this : T,
id : string, id : string,
): T['prototype'] { ): T['prototype'] {
if (!this.pool) { if (!this.pool) {
log.verbose('Contact', 'load(%s) init pool', id) log.verbose('Contact', 'load(%s) init pool', id)
......
...@@ -290,9 +290,11 @@ export class Message extends Accessory implements Sayable { ...@@ -290,9 +290,11 @@ export class Message extends Accessory implements Sayable {
textOrContactOrFile : string | Contact | FileBox, textOrContactOrFile : string | Contact | FileBox,
mention? : Contact | Contact[], mention? : Contact | Contact[],
): Promise<void> { ): Promise<void> {
log.verbose('Message', 'say(%s, %s)', log.verbose('Message', 'say(%s%s)',
textOrContactOrFile.toString(), textOrContactOrFile.toString(),
mention, mention
? ', ' + mention
: '',
) )
// const user = this.puppet.userSelf() // const user = this.puppet.userSelf()
...@@ -416,8 +418,8 @@ export class Message extends Accessory implements Sayable { ...@@ -416,8 +418,8 @@ export class Message extends Accessory implements Sayable {
* const contactList = message.mentioned() * const contactList = message.mentioned()
* console.log(contactList) * console.log(contactList)
*/ */
public async mentioned(): Promise<Contact[]> { public async mention(): Promise<Contact[]> {
log.verbose('Message', 'mentioned()') log.verbose('Message', 'mention()')
const room = this.room() const room = this.room()
if (this.type() !== MessageType.Text || !room ) { if (this.type() !== MessageType.Text || !room ) {
...@@ -432,7 +434,7 @@ export class Message extends Accessory implements Sayable { ...@@ -432,7 +434,7 @@ export class Message extends Accessory implements Sayable {
if (atList.length === 0) return [] if (atList.length === 0) return []
// Using `filter(e => e.indexOf('@') > -1)` to filter the string without `@` // Using `filter(e => e.indexOf('@') > -1)` to filter the string without `@`
const rawMentionedList = atList const rawMentionList = atList
.filter(str => str.includes('@')) .filter(str => str.includes('@'))
.map(str => multipleAt(str)) .map(str => multipleAt(str))
...@@ -455,11 +457,11 @@ export class Message extends Accessory implements Sayable { ...@@ -455,11 +457,11 @@ export class Message extends Accessory implements Sayable {
let mentionNameList: string[] = [] let mentionNameList: string[] = []
// Flatten Array // Flatten Array
// see http://stackoverflow.com/a/10865042/1123955 // see http://stackoverflow.com/a/10865042/1123955
mentionNameList = mentionNameList.concat.apply([], rawMentionedList) mentionNameList = mentionNameList.concat.apply([], rawMentionList)
// filter blank string // filter blank string
mentionNameList = mentionNameList.filter(s => !!s) mentionNameList = mentionNameList.filter(s => !!s)
log.verbose('Message', 'mentioned() text = "%s", mentionNameList = "%s"', log.verbose('Message', 'mention() text = "%s", mentionNameList = "%s"',
this.text(), this.text(),
JSON.stringify(mentionNameList), JSON.stringify(mentionNameList),
) )
...@@ -474,11 +476,19 @@ export class Message extends Accessory implements Sayable { ...@@ -474,11 +476,19 @@ export class Message extends Accessory implements Sayable {
contactList = contactList.concat.apply([], contactListNested) contactList = contactList.concat.apply([], contactListNested)
if (contactList.length === 0) { 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 return contactList
} }
/**
* @deprecated: use mention() instead
*/
public async mentioned(): Promise<Contact[]> {
log.warn('Message', 'mentioned() DEPRECATED. use mention() instead.')
return this.mention()
}
/** /**
* @private * @private
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册