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

make tslint happy

上级 8a354c42
......@@ -76,16 +76,16 @@ bot
* Wechaty Event: `friend`
*
*/
.on('friend', async request => {
.on('friendship', 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) {
......
......@@ -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 { onFriendship } 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('friendship', onFriendship)
.on('room-join', onRoomJoin)
.start()
......
......@@ -28,7 +28,7 @@ import {
// Room,
} from '../../src/'
export async function onFriend(
export async function onFriendship(
this: Wechaty,
request: Friendship,
): Promise<void> {
......
......@@ -256,7 +256,7 @@ export class PuppetPadchat extends Puppet {
rawPayload.msg_id,
rawPayload,
)
this.emit('friend', rawPayload.msg_id)
this.emit('friendship', rawPayload.msg_id)
break
case PadchatMessageType.Sys:
......
// 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]
}
......@@ -199,7 +199,7 @@ async function onMessage(
switch (rawPayload.MsgType) {
case WebMessageType.VERIFYMSG:
this.emit('friend', rawPayload.MsgId)
this.emit('friendship', rawPayload.MsgId)
// firer.checkFriendRequest(rawPayload)
break
......
......@@ -156,7 +156,7 @@ export class Firer {
// this.puppet.cacheFriendRequestPayload.set(id, payloadConfirm)
this.puppet.emit('friend', rawPayload.MsgId)
this.puppet.emit('friendship', rawPayload.MsgId)
}
public async checkRoomJoin(
......
......@@ -232,12 +232,12 @@ export class PuppetWechat4u extends Puppet {
break
case WebMessageType.VERIFYMSG:
this.emit('friend', msg.MsgId)
this.emit('friendship', msg.MsgId)
break
case WebMessageType.SYS:
if (this.isFriendConfirm(msg.Content)) {
this.emit('friend', msg.MsgId)
this.emit('friendship', msg.MsgId)
}
this.emit('message', msg.MsgId)
break
......
......@@ -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: 'friendship', 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: 'friendship', 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
......
......@@ -44,7 +44,7 @@ export interface PuppetRoomTopicEvent {
}
export const CHAT_EVENT_DICT = {
friend : 'document can be writen at here',
friendship : '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',
......
......@@ -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: 'friendship' , 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: 'friendship' , 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.
先完成此消息的编辑!
想要评论请 注册