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

code clean

上级 df268dd9
......@@ -52,7 +52,7 @@ bot
const msg = yield m.ready()
const room = Wechaty.Room.load(m.room())
if (room && /Wechaty/i.test(room.name())) {
if (room && /Wechaty/i.test(room.topic())) {
log.info('Bot', 'talk: %s' , msg)
talk(m)
} else {
......
......@@ -48,7 +48,7 @@ bot
const room = m.room()
const from = m.from()
console.log((room ? '['+room.name()+']' : '')
console.log((room ? '['+room.topic()+']' : '')
+ '<'+from.name()+'>'
+ ':' + m.toStringDigest()
)
......
......@@ -26,7 +26,7 @@ class Contact {
parse(rawObj) {
return !rawObj ? {} : {
id: rawObj.UserName
, uin: rawObj.Uin // stable id? 4763975 || getCookie("wxuin")
, uin: rawObj.Uin // stable id: 4763975 || getCookie("wxuin")
, weixin: rawObj.Alias // Wechat ID
, name: rawObj.NickName
, remark: rawObj.RemarkName
......@@ -105,7 +105,7 @@ Contact.init()
Contact.load = function(id) {
if (!id || typeof id !== 'string') {
throw new Error('id must be string')
return null
}
if (!(id in Contact.pool)) {
......
......@@ -135,7 +135,7 @@ class IoClient {
}
const wechaty = this.wechaty
const io = new Io({
wechaty
, token: this.token()
......@@ -174,7 +174,7 @@ class IoClient {
const room = m.room()
// this.log.info('Bot', '%s<%s>:%s'
// , (room ? '['+room.name()+']' : '')
// , (room ? '['+room.topic()+']' : '')
// , from.name()
// , m.toStringDigest()
// )
......@@ -196,10 +196,10 @@ class IoClient {
this.log.warn('IoClient', 'start() with a pending state, not the time')
return Promise.reject('pending')
}
this.targetState('connected')
this.currentState('connecting')
return this.initIo(this.wechaty)
.then(io => {
this.io = io
......@@ -252,7 +252,7 @@ class IoClient {
quit() {
this.log.verbose('IoClient', 'quit()')
if (this.currentState() === 'disconnecting') {
this.log.warn('IoClient', 'quit() with currentState() = `disconnecting`, skipped')
return Promise.reject('quit() with currentState = `disconnecting`')
......@@ -270,13 +270,13 @@ class IoClient {
if (this.io) {
yield this.io.quit()
this.io = null
this.io = null
} else { this.log.warn('IoClient', 'quit() no this.io') }
this.currentState('disconnected')
}).catch(e => {
this.log.error('IoClient', 'exception: %s', e.message)
// XXX fail safe?
this.currentState('disconnected')
......
......@@ -83,9 +83,9 @@ class Message {
}
from() { return Contact.load(this.obj.from) }
to() { return Contact.load(this.obj.to) }
to() { return this.obj.to ? Contact.load(this.obj.to) : null }
content() { return this.obj.content }
room() { return Room.load(this.obj.room) }
room() { return this.obj.room ? Room.load(this.obj.room) : null }
type() { return this.obj.type }
typeEx() { return Message.Type[this.obj.type] }
......
......@@ -346,8 +346,7 @@ function onServerMessage(data) {
const request = new FriendRequest()
request.receive(data.RecommendInfo)
const contact = Contact.load(request.contactId)
this.emit('friend', contact, request)
this.emit('friend', request.contact, request)
break
case Message.Type.SYS:
......@@ -358,7 +357,7 @@ function onServerMessage(data) {
/**
* try to find FriendRequest Confirmation Message
*/
if (/^You have added (.+) as your WeChat contact. Start chatting!$/.test(m.get('content'))) {
if (/^You have added(.+)as your WeChat contact. Start chatting!$/.test(m.get('content'))) {
const request = new FriendRequest()
const contact = Contact.load(m.get('from'))
request.confirm(contact)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册