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

code clean

上级 46faeb9a
......@@ -4,25 +4,30 @@ import {
, Room
} from '../../'
export default async function onFriend(contact: Contact, request: FriendRequest): Promise<void> {
export default async function onFriend(contact: Contact, request?: FriendRequest): Promise<void> {
try {
if (!request) {
console.log('New friend ' + contact.name() + ' relationship confirmed!')
return
}
/********************************************
*
* 从这里开始修改 vvvvvvvvvvvv
*
*/
await request.accept()
if (request.hello !== '上课') {
return
}
request.accept()
request.contact.say('thanks for coming for ' + request.hello)
setTimeout(function() {
contact.say('thank you for adding me')
}, 3000)
const myRoom = await Room.find({
topic: 'ding'
})
myRoom.add(request.contact)
if (request.hello === 'ding') {
const myRoom = await Room.find({ topic: 'ding' })
setTimeout(function() {
myRoom.add(contact)
myRoom.say('welcome ' + contact.name())
}, 3000)
}
/**
*
......
import {
Contact
, Room
, Sayable
} from '../../'
const arrify = require('arrify')
export default async function onRoomJoin(
room: Room
this: Sayable
, room: Room
, invitee: Contact|Contact[]
, inviter: Contact
): Promise<void> {
try {
const inviteeName = arrify(invitee).map(c => c.name()).join(', ')
/********************************************
*
* 从这里开始修改 vvvvvvvvvvvv
......@@ -19,11 +21,17 @@ export default async function onRoomJoin(
*/
if (room.topic() !== 'ding') {
this.say('Room ' + room.topic()
+ ' got new memeber ' + inviteeName
+ ' invited by ' + inviter.name()
)
return
}
if (inviter.self()) {
room.say('Welcome to my room: ' + arrify(invitee).join(', '))
const inviterIsMyself = inviter.self()
if (inviterIsMyself) {
room.say('Welcome to my room: ' + inviteeName)
return
}
......
import Config from './src/config'
import {
Config
, Sayable
} from './src/config'
import Contact from './src/contact'
import FriendRequest from './src/friend-request'
import IoClient from './src/io-client'
......@@ -23,6 +26,7 @@ export {
, Puppet
, PuppetWeb
, Room
, Sayable
, UtilLib
, Wechaty
, log // for convenionce use npmlog with environment variable LEVEL
......
......@@ -25,8 +25,8 @@ abstract class FriendRequest {
}
}
public abstract send(contact: Contact, hello: string): void
public abstract accept(): void
public abstract async send(contact: Contact, hello: string): Promise<void>
public abstract async accept(): Promise<void>
}
......
......@@ -76,7 +76,7 @@ class PuppetWebFriendRequest extends FriendRequest {
this.type = 'confirm'
}
public send(contact: Contact, hello = 'Hi'): Promise<any> {
public async send(contact: Contact, hello = 'Hi'): Promise<void> {
log.verbose('PuppetWebFriendRequest', 'send(%s)', contact)
if (!contact) {
......@@ -89,11 +89,12 @@ class PuppetWebFriendRequest extends FriendRequest {
this.hello = hello
}
return Config.puppetInstance()
.friendRequestSend(contact, hello)
await Config.puppetInstance()
.friendRequestSend(contact, hello)
return
}
public async accept(): Promise<any> {
public async accept(): Promise<void> {
log.verbose('FriendRequest', 'accept() %s', this.contact)
if (this.type !== 'receive') {
......
......@@ -220,26 +220,28 @@ export class Room extends EventEmitter implements Sayable {
Object.keys(this.obj).forEach(k => console.error(`${k}: ${this.obj && this.obj[k]}`))
}
public add(contact: Contact): Promise<any> {
public async add(contact: Contact): Promise<any> {
log.verbose('Room', 'add(%s)', contact)
if (!contact) {
throw new Error('contact not found')
}
return Config.puppetInstance()
.roomAdd(this, contact)
await Config.puppetInstance()
.roomAdd(this, contact)
return
}
public del(contact: Contact): Promise<number> {
public async del(contact: Contact): Promise<number> {
log.verbose('Room', 'del(%s)', contact.name())
if (!contact) {
throw new Error('contact not found')
}
return Config.puppetInstance()
const n = await Config.puppetInstance()
.roomDel(this, contact)
.then(_ => this.delLocal(contact))
return n
}
// @private
......@@ -404,7 +406,7 @@ export class Room extends EventEmitter implements Sayable {
if (!roomList || roomList.length < 1) {
throw new Error('no room found')
}
return roomList[0]
return roomList[0].ready()
}
public static load(id: string): Room | null {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册