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

fix all static puppet bugs (#518)

上级 d60b9ce2
...@@ -18,32 +18,33 @@ cache: ...@@ -18,32 +18,33 @@ cache:
directories: directories:
- node_modules - node_modules
before_install:
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew update; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew cleanup; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew cask cleanup; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew install jq; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew install moreutils; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew install shellcheck; fi
script:
- echo $TRAVIS_OS_NAME
- node --version
- npm --version
- npm test
after_success:
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then npm run coverage; fi
stages: stages:
- test - test
- pack - pack
- name: deploy - name: deploy
if: branch =~ ^(master|v\d+\.\d+) if: branch =~ ^(master|v\d+\.\d+)$
AND (type NOT IN (cron, pull_request)) AND (type NOT IN (cron, pull_request))
jobs: jobs:
include: include:
- stage: test
before_install:
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew update; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew cleanup; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew cask cleanup; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew install jq; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew install moreutils; fi
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then brew install shellcheck; fi
script:
- echo $TRAVIS_OS_NAME
- node --version
- npm --version
- npm test
after_success:
- if [ "$TRAVIS_OS_NAME" == 'osx' ]; then npm run coverage; fi
- stage: pack - stage: pack
script: script:
- npm run test:pack && echo 'Npm pack testing is passed' - npm run test:pack && echo 'Npm pack testing is passed'
...@@ -60,6 +61,8 @@ jobs: ...@@ -60,6 +61,8 @@ jobs:
email: zixia@zixia.net email: zixia@zixia.net
api_key: "$NPM_TOKEN" api_key: "$NPM_TOKEN"
skip_cleanup: true skip_cleanup: true
on:
all_branches: true
notifications: notifications:
webhooks: webhooks:
......
...@@ -29,7 +29,7 @@ const QrcodeTerminal = require('qrcode-terminal') ...@@ -29,7 +29,7 @@ const QrcodeTerminal = require('qrcode-terminal')
*/ */
import { import {
config, config,
Contact, // Contact,
Wechaty, Wechaty,
log, log,
} from '../' } from '../'
...@@ -88,7 +88,7 @@ bot.start() ...@@ -88,7 +88,7 @@ bot.start()
* Main Contact Bot * Main Contact Bot
*/ */
async function onLogin() { async function onLogin() {
const contactList = await Contact.findAll() const contactList = await bot.Contact.findAll()
log.info('Bot', '#######################') log.info('Bot', '#######################')
log.info('Bot', 'Contact number: %d\n', contactList.length) log.info('Bot', 'Contact number: %d\n', contactList.length)
......
...@@ -27,7 +27,7 @@ const QrcodeTerminal = require('qrcode-terminal') ...@@ -27,7 +27,7 @@ const QrcodeTerminal = require('qrcode-terminal')
*/ */
import { import {
config, config,
Contact, // Contact,
log, log,
Wechaty, Wechaty,
} from '../' } from '../'
...@@ -77,7 +77,7 @@ bot ...@@ -77,7 +77,7 @@ bot
*/ */
.on('friend', async (contact, request) => { .on('friend', async (contact, request) => {
let logMsg let logMsg
const fileHelper = Contact.load('filehelper') const fileHelper = bot.Contact.load('filehelper')
try { try {
logMsg = 'received `friend` event from ' + contact.get('name') logMsg = 'received `friend` event from ' + contact.get('name')
......
...@@ -41,8 +41,9 @@ Please wait... I'm trying to login in... ...@@ -41,8 +41,9 @@ Please wait... I'm trying to login in...
` `
console.log(welcome) console.log(welcome)
Wechaty.instance({ profile: config.default.DEFAULT_PROFILE }) const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })
bot
.on('scan', (url, code) => { .on('scan', (url, code) => {
if (!/201|200/.test(String(code))) { if (!/201|200/.test(String(code))) {
const loginUrl = url.replace(/\/qrcode\//, '/l/') const loginUrl = url.replace(/\/qrcode\//, '/l/')
......
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
import { import {
Contact, Contact,
FriendRequest, FriendRequest,
Room, Wechaty,
// Room,
} from '../../' } from '../../'
export async function onFriend(contact: Contact, request?: FriendRequest): Promise<void> { export async function onFriend(this: Wechaty, contact: Contact, request?: FriendRequest): Promise<void> {
try { try {
if (!request) { if (!request) {
console.log('New friend ' + contact.name() + ' relationship confirmed!') console.log('New friend ' + contact.name() + ' relationship confirmed!')
...@@ -49,7 +50,7 @@ export async function onFriend(contact: Contact, request?: FriendRequest): Promi ...@@ -49,7 +50,7 @@ export async function onFriend(contact: Contact, request?: FriendRequest): Promi
) )
if (request.hello === 'ding') { if (request.hello === 'ding') {
const myRoom = await Room.find({ topic: 'ding' }) const myRoom = await this.Room.find({ topic: 'ding' })
if (!myRoom) return if (!myRoom) return
setTimeout( setTimeout(
async _ => { async _ => {
......
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
*/ */
import { import {
Message, Message,
Room, Wechaty,
} from '../../' } from '../../'
export async function onMessage(message: Message): Promise<void> { export async function onMessage(this: Wechaty, message: Message): Promise<void> {
try { try {
const room = message.room() const room = message.room()
const sender = message.from() const sender = message.from()
...@@ -52,7 +52,7 @@ export async function onMessage(message: Message): Promise<void> { ...@@ -52,7 +52,7 @@ export async function onMessage(message: Message): Promise<void> {
if (content === 'ding') { if (content === 'ding') {
await message.say('thanks for ding me') await message.say('thanks for ding me')
const myRoom = await Room.find({ topic: 'ding' }) const myRoom = await this.Room.find({ topic: 'ding' })
if (!myRoom) return if (!myRoom) return
if (myRoom.has(sender)) { if (myRoom.has(sender)) {
......
...@@ -157,7 +157,7 @@ bot ...@@ -157,7 +157,7 @@ bot
/** /**
* Global Event: message * Global Event: message
*/ */
.on('message', async function(this, message) { .on('message', async function(this: Wechaty, message) {
const room = message.room() const room = message.room()
const sender = message.from() const sender = message.from()
const content = message.content() const content = message.content()
...@@ -197,7 +197,7 @@ bot ...@@ -197,7 +197,7 @@ bot
* find room name start with "ding" * find room name start with "ding"
*/ */
try { try {
const dingRoom = await Room.find({ topic: /^ding/i }) const dingRoom = await this.Room.find({ topic: /^ding/i })
if (dingRoom) { if (dingRoom) {
/** /**
* room found * room found
...@@ -254,7 +254,7 @@ async function manageDingRoom() { ...@@ -254,7 +254,7 @@ async function manageDingRoom() {
* Find Room * Find Room
*/ */
try { try {
const room = await Room.find({ topic: /^ding/i }) const room = await bot.Room.find({ topic: /^ding/i })
if (!room) { if (!room) {
log.warn('Bot', 'there is no room topic ding(yet)') log.warn('Bot', 'there is no room topic ding(yet)')
return return
......
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
"rx-queue": "^0.3.1", "rx-queue": "^0.3.1",
"rxjs": "^5.5.0", "rxjs": "^5.5.0",
"state-switch": "^0.4.5", "state-switch": "^0.4.5",
"watchdog": "^0.3.0", "watchdog": "^0.5.1",
"wechat4u": "^0.7.6", "wechat4u": "^0.7.6",
"ws": "^5.1.0", "ws": "^5.1.0",
"xml2js": "^0.4.0" "xml2js": "^0.4.0"
......
...@@ -344,6 +344,8 @@ export class Contact extends PuppetAccessory implements Sayable { ...@@ -344,6 +344,8 @@ export class Contact extends PuppetAccessory implements Sayable {
let m let m
if (typeof textOrMedia === 'string') { if (typeof textOrMedia === 'string') {
m = new Message() m = new Message()
m.puppet = this.puppet
m.content(textOrMedia) m.content(textOrMedia)
} else if (textOrMedia instanceof MediaMessage) { } else if (textOrMedia instanceof MediaMessage) {
m = textOrMedia m = textOrMedia
......
...@@ -166,7 +166,10 @@ export class Message extends PuppetAccessory implements Sayable { ...@@ -166,7 +166,10 @@ export class Message extends PuppetAccessory implements Sayable {
* @private * @private
*/ */
public getSenderString() { public getSenderString() {
const fromName = Contact.load(this.obj.from).name() const from = Contact.load(this.obj.from)
from.puppet = this.puppet
const fromName = from.name()
const roomTopic = this.obj.room const roomTopic = this.obj.room
? (':' + Room.load(this.obj.room).topic()) ? (':' + Room.load(this.obj.room).topic())
: '' : ''
...@@ -213,6 +216,8 @@ export class Message extends PuppetAccessory implements Sayable { ...@@ -213,6 +216,8 @@ export class Message extends PuppetAccessory implements Sayable {
let m let m
if (typeof textOrMedia === 'string') { if (typeof textOrMedia === 'string') {
m = new Message() m = new Message()
m.puppet = this.puppet
const room = this.room() const room = this.room()
if (room) { if (room) {
m.room(room) m.room(room)
...@@ -279,9 +284,8 @@ export class Message extends PuppetAccessory implements Sayable { ...@@ -279,9 +284,8 @@ export class Message extends PuppetAccessory implements Sayable {
} }
const loadedContact = Contact.load(this.obj.from) const loadedContact = Contact.load(this.obj.from)
if (!loadedContact) { loadedContact.puppet = this.puppet
throw new Error('no from')
}
return loadedContact return loadedContact
} }
...@@ -315,7 +319,9 @@ export class Message extends PuppetAccessory implements Sayable { ...@@ -315,7 +319,9 @@ export class Message extends PuppetAccessory implements Sayable {
return return
} }
if (this.obj.room) { if (this.obj.room) {
return Room.load(this.obj.room) const r = Room.load(this.obj.room)
r.puppet = this.puppet
return r
} }
return null return null
} }
...@@ -494,15 +500,20 @@ export class Message extends PuppetAccessory implements Sayable { ...@@ -494,15 +500,20 @@ export class Message extends PuppetAccessory implements Sayable {
try { try {
const from = Contact.load(this.obj.from) const from = Contact.load(this.obj.from)
from.puppet = this.puppet
await from.ready() // Contact from await from.ready() // Contact from
if (this.obj.to) { if (this.obj.to) {
const to = Contact.load(this.obj.to) const to = Contact.load(this.obj.to)
to.puppet = this.puppet
await to.ready() await to.ready()
} }
if (this.obj.room) { if (this.obj.room) {
const room = Room.load(this.obj.room) const room = Room.load(this.obj.room)
room.puppet = this.puppet
await room.ready() // Room member list await room.ready() // Room member list
} }
...@@ -616,7 +627,10 @@ export class Message extends PuppetAccessory implements Sayable { ...@@ -616,7 +627,10 @@ export class Message extends PuppetAccessory implements Sayable {
if (!this.obj.to) { if (!this.obj.to) {
return null return null
} }
return Contact.load(this.obj.to) const to = Contact.load(this.obj.to)
to.puppet = this.puppet
return to
} }
/** /**
...@@ -691,10 +705,6 @@ export class MediaMessage extends Message { ...@@ -691,10 +705,6 @@ export class MediaMessage extends Message {
} else { } else {
throw new Error('not supported construct param') throw new Error('not supported construct param')
} }
// FIXME: decoupling needed
this.bridge = (/* config.puppetInstance() */ this.puppet as PuppetWeb)
.bridge
} }
/** /**
...@@ -710,6 +720,11 @@ export class MediaMessage extends Message { ...@@ -710,6 +720,11 @@ export class MediaMessage extends Message {
public async ready(): Promise<void> { public async ready(): Promise<void> {
log.silly('MediaMessage', 'ready()') log.silly('MediaMessage', 'ready()')
// FIXME: decoupling needed
if (!this.bridge) {
this.bridge = (this.puppet as PuppetWeb).bridge
}
try { try {
await super.ready() await super.ready()
......
...@@ -135,6 +135,8 @@ async function onLogin(this: PuppetWeb, memo: string, ttl = 30): Promise<void> { ...@@ -135,6 +135,8 @@ async function onLogin(this: PuppetWeb, memo: string, ttl = 30): Promise<void> {
log.silly('PuppetWebEvent', 'bridge.getUserName: %s', this.userId) log.silly('PuppetWebEvent', 'bridge.getUserName: %s', this.userId)
this.user = Contact.load(this.userId) this.user = Contact.load(this.userId)
this.user.puppet = this
await this.user.ready() await this.user.ready()
log.silly('PuppetWebEvent', `onLogin() user ${this.user.name()} logined`) log.silly('PuppetWebEvent', `onLogin() user ${this.user.name()} logined`)
...@@ -180,6 +182,7 @@ async function onMessage( ...@@ -180,6 +182,7 @@ async function onMessage(
obj: MsgRawObj, obj: MsgRawObj,
): Promise<void> { ): Promise<void> {
let m = new Message(obj) let m = new Message(obj)
m.puppet = this
try { try {
await m.ready() await m.ready()
...@@ -222,6 +225,7 @@ async function onMessage( ...@@ -222,6 +225,7 @@ async function onMessage(
case MsgType.APP: case MsgType.APP:
log.verbose('PuppetWebEvent', 'onMessage() EMOTICON/IMAGE/VIDEO/VOICE/MICROVIDEO message') log.verbose('PuppetWebEvent', 'onMessage() EMOTICON/IMAGE/VIDEO/VOICE/MICROVIDEO message')
m = new MediaMessage(obj) m = new MediaMessage(obj)
m.puppet = this
break break
case MsgType.TEXT: case MsgType.TEXT:
......
...@@ -112,6 +112,8 @@ async function checkFriendRequest(m: Message) { ...@@ -112,6 +112,8 @@ async function checkFriendRequest(m: Message) {
} }
const request = new FriendRequest() const request = new FriendRequest()
request.puppet = m.puppet
request.receive(info) request.receive(info)
await request.contact.ready() await request.contact.ready()
...@@ -145,6 +147,8 @@ async function checkFriendConfirm(m: Message) { ...@@ -145,6 +147,8 @@ async function checkFriendConfirm(m: Message) {
return return
} }
const request = new FriendRequest() const request = new FriendRequest()
request.puppet = m.puppet
const contact = m.from() const contact = m.from()
request.confirm(contact) request.confirm(contact)
...@@ -216,6 +220,7 @@ async function checkRoomJoin(m: Message): Promise<boolean> { ...@@ -216,6 +220,7 @@ async function checkRoomJoin(m: Message): Promise<boolean> {
try { try {
if (inviter === 'You' || inviter === '' || inviter === 'you') { if (inviter === 'You' || inviter === '' || inviter === 'you') {
inviterContact = Contact.load(this.userId) inviterContact = Contact.load(this.userId)
inviterContact.puppet = m.puppet
} }
const max = 20 const max = 20
...@@ -354,6 +359,8 @@ async function checkRoomLeave(m: Message): Promise<boolean> { ...@@ -354,6 +359,8 @@ async function checkRoomLeave(m: Message): Promise<boolean> {
let leaverContact: Contact | null, removerContact: Contact | null let leaverContact: Contact | null, removerContact: Contact | null
if (leaver === this.userId) { if (leaver === this.userId) {
leaverContact = Contact.load(this.userId) leaverContact = Contact.load(this.userId)
leaverContact.puppet = m.puppet
// not sure which is better // not sure which is better
// removerContact = room.member({contactAlias: remover}) || room.member({name: remover}) // removerContact = room.member({contactAlias: remover}) || room.member({name: remover})
removerContact = room.member(remover) removerContact = room.member(remover)
...@@ -361,8 +368,11 @@ async function checkRoomLeave(m: Message): Promise<boolean> { ...@@ -361,8 +368,11 @@ async function checkRoomLeave(m: Message): Promise<boolean> {
log.error('PuppetWebFirer', 'fireRoomLeave() bot is removed from the room, but remover %s not found, event `room-leave` & `leave` will not be fired', remover) log.error('PuppetWebFirer', 'fireRoomLeave() bot is removed from the room, but remover %s not found, event `room-leave` & `leave` will not be fired', remover)
return false return false
} }
} else { } else {
removerContact = Contact.load(this.userId) removerContact = Contact.load(this.userId)
removerContact.puppet = m.puppet
// not sure which is better // not sure which is better
// leaverContact = room.member({contactAlias: remover}) || room.member({name: leaver}) // leaverContact = room.member({contactAlias: remover}) || room.member({name: leaver})
leaverContact = room.member(remover) leaverContact = room.member(remover)
...@@ -418,6 +428,7 @@ async function checkRoomTopic(m: Message): Promise<boolean> { ...@@ -418,6 +428,7 @@ async function checkRoomTopic(m: Message): Promise<boolean> {
let changerContact: Contact | null let changerContact: Contact | null
if (/^You$/.test(changer) || /^你$/.test(changer)) { if (/^You$/.test(changer) || /^你$/.test(changer)) {
changerContact = Contact.load(this.userId) changerContact = Contact.load(this.userId)
changerContact.puppet = m.puppet
} else { } else {
changerContact = room.member(changer) changerContact = room.member(changer)
} }
......
...@@ -59,6 +59,7 @@ test('PuppetWebFriendRequest.confirm smoke testing', async t => { ...@@ -59,6 +59,7 @@ test('PuppetWebFriendRequest.confirm smoke testing', async t => {
` `
const rawObj = JSON.parse(rawMessageData) const rawObj = JSON.parse(rawMessageData)
const m = new Message(rawObj) const m = new Message(rawObj)
m.puppet = this.puppet
t.true(/^You have added (.+) as your WeChat contact. Start chatting!$/.test(m.content()), 'should match confirm message') t.true(/^You have added (.+) as your WeChat contact. Start chatting!$/.test(m.content()), 'should match confirm message')
......
...@@ -63,10 +63,8 @@ export class PuppetWebFriendRequest extends FriendRequest { ...@@ -63,10 +63,8 @@ export class PuppetWebFriendRequest extends FriendRequest {
this.info = info this.info = info
const contact = Contact.load(info.UserName) const contact = Contact.load(info.UserName)
if (!contact) { contact.puppet = this.puppet
log.warn('PuppetWebFriendRequest', 'receive() no contact found for "%s"', info.UserName)
throw new Error('no contact')
}
this.contact = contact this.contact = contact
this.hello = info.Content this.hello = info.Content
this.ticket = info.Ticket this.ticket = info.Ticket
......
...@@ -22,8 +22,9 @@ import { ...@@ -22,8 +22,9 @@ import {
} from 'watchdog' } from 'watchdog'
import { import {
ThrottleQueue, ThrottleQueue,
} from 'rx-queue' } from 'rx-queue'
import cloneClass from '../clone-class'
import { import {
config, config,
log, log,
...@@ -39,15 +40,14 @@ import { ...@@ -39,15 +40,14 @@ import {
Puppet, Puppet,
PuppetOptions, PuppetOptions,
ScanData, ScanData,
} from '../puppet' } from '../puppet'
import Room from '../room' import Room from '../room'
import Misc from '../misc' import Misc from '../misc'
import { import {
Bridge, Bridge,
Cookie, Cookie,
} from './bridge' } from './bridge'
import Event from './event' import Event from './event'
import { import {
MediaData, MediaData,
...@@ -794,7 +794,11 @@ export class PuppetWeb extends Puppet { ...@@ -794,7 +794,11 @@ export class PuppetWeb extends Puppet {
public async contactFind(filterFunc: string): Promise<Contact[]> { public async contactFind(filterFunc: string): Promise<Contact[]> {
try { try {
const idList = await this.bridge.contactFind(filterFunc) const idList = await this.bridge.contactFind(filterFunc)
return idList.map(id => Contact.load(id)) return idList.map(id => {
const c = Contact.load(id)
c.puppet = this
return c
})
} catch (e) { } catch (e) {
log.warn('PuppetWeb', 'contactFind(%s) rejected: %s', filterFunc, e.message) log.warn('PuppetWeb', 'contactFind(%s) rejected: %s', filterFunc, e.message)
Raven.captureException(e) Raven.captureException(e)
...@@ -805,7 +809,11 @@ export class PuppetWeb extends Puppet { ...@@ -805,7 +809,11 @@ export class PuppetWeb extends Puppet {
public async roomFind(filterFunc: string): Promise<Room[]> { public async roomFind(filterFunc: string): Promise<Room[]> {
try { try {
const idList = await this.bridge.roomFind(filterFunc) const idList = await this.bridge.roomFind(filterFunc)
return idList.map(id => Room.load(id)) return idList.map(id => {
const r = Room.load(id)
r.puppet = this
return r
})
} catch (e) { } catch (e) {
log.warn('PuppetWeb', 'roomFind(%s) rejected: %s', filterFunc, e.message) log.warn('PuppetWeb', 'roomFind(%s) rejected: %s', filterFunc, e.message)
Raven.captureException(e) Raven.captureException(e)
...@@ -864,7 +872,9 @@ export class PuppetWeb extends Puppet { ...@@ -864,7 +872,9 @@ export class PuppetWeb extends Puppet {
if (!roomId) { if (!roomId) {
throw new Error('PuppetWeb.roomCreate() roomId "' + roomId + '" not found') throw new Error('PuppetWeb.roomCreate() roomId "' + roomId + '" not found')
} }
return Room.load(roomId) const r = Room.load(roomId)
r.puppet = this
return r
} catch (e) { } catch (e) {
log.warn('PuppetWeb', 'roomCreate(%s, %s) rejected: %s', contactIdList.join(','), topic, e.message) log.warn('PuppetWeb', 'roomCreate(%s, %s) rejected: %s', contactIdList.join(','), topic, e.message)
...@@ -912,9 +922,14 @@ export class PuppetWeb extends Puppet { ...@@ -912,9 +922,14 @@ export class PuppetWeb extends Puppet {
log.verbose('PuppetWeb', 'readyStable()') log.verbose('PuppetWeb', 'readyStable()')
let counter = -1 let counter = -1
// tslint:disable-next-line:variable-name
const MyContact = cloneClass(Contact)
MyContact.puppet = this
async function stable(done: Function): Promise<void> { async function stable(done: Function): Promise<void> {
log.silly('PuppetWeb', 'readyStable() stable() counter=%d', counter) log.silly('PuppetWeb', 'readyStable() stable() counter=%d', counter)
const contactList = await Contact.findAll()
const contactList = await MyContact.findAll()
if (counter === contactList.length) { if (counter === contactList.length) {
log.verbose('PuppetWeb', 'readyStable() stable() READY counter=%d', counter) log.verbose('PuppetWeb', 'readyStable() stable() READY counter=%d', counter)
return done() return done()
......
...@@ -119,6 +119,7 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -119,6 +119,7 @@ export class Room extends PuppetAccessory implements Sayable {
private async readyAllMembers(memberList: RoomRawMember[]): Promise<void> { private async readyAllMembers(memberList: RoomRawMember[]): Promise<void> {
for (const member of memberList) { for (const member of memberList) {
const contact = Contact.load(member.UserName) const contact = Contact.load(member.UserName)
contact.puppet = this.puppet
await contact.ready() await contact.ready()
} }
return return
...@@ -230,6 +231,7 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -230,6 +231,7 @@ export class Room extends PuppetAccessory implements Sayable {
let m let m
if (typeof textOrMedia === 'string') { if (typeof textOrMedia === 'string') {
m = new Message() m = new Message()
m.puppet = this.puppet
const replyToList: Contact[] = [].concat(replyTo as any || []) const replyToList: Contact[] = [].concat(replyTo as any || [])
...@@ -330,7 +332,11 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -330,7 +332,11 @@ export class Room extends PuppetAccessory implements Sayable {
} }
const memberList = (rawObj.MemberList || []) const memberList = (rawObj.MemberList || [])
.map(m => Contact.load(m.UserName)) .map(m => {
const c = Contact.load(m.UserName)
c.puppet = this.puppet
return c
})
const nameMap = this.parseMap('name', rawObj.MemberList) const nameMap = this.parseMap('name', rawObj.MemberList)
const roomAliasMap = this.parseMap('roomAlias', rawObj.MemberList) const roomAliasMap = this.parseMap('roomAlias', rawObj.MemberList)
...@@ -357,6 +363,8 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -357,6 +363,8 @@ export class Room extends PuppetAccessory implements Sayable {
memberList.forEach(member => { memberList.forEach(member => {
let tmpName: string let tmpName: string
const contact = Contact.load(member.UserName) const contact = Contact.load(member.UserName)
contact.puppet = this.puppet
switch (parseContent) { switch (parseContent) {
case 'name': case 'name':
tmpName = contact.name() tmpName = contact.name()
...@@ -716,7 +724,11 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -716,7 +724,11 @@ export class Room extends PuppetAccessory implements Sayable {
log.silly('Room', 'memberAll() check %s from %s: %s', filterValue, filterKey, JSON.stringify(filterMap)) log.silly('Room', 'memberAll() check %s from %s: %s', filterValue, filterKey, JSON.stringify(filterMap))
if (idList.length) { if (idList.length) {
return idList.map(id => Contact.load(id)) return idList.map(id => {
const c = Contact.load(id)
c.puppet = this.puppet
return c
})
} else { } else {
return [] return []
} }
...@@ -926,7 +938,9 @@ export class Room extends PuppetAccessory implements Sayable { ...@@ -926,7 +938,9 @@ export class Room extends PuppetAccessory implements Sayable {
} }
if (this.rawObj.ChatRoomOwner) { if (this.rawObj.ChatRoomOwner) {
return Contact.load(this.rawObj.ChatRoomOwner) const c = Contact.load(this.rawObj.ChatRoomOwner)
c.puppet = this.puppet
return c
} }
log.info('Room', 'owner() is limited by Tencent API, sometimes work sometimes not') log.info('Room', 'owner() is limited by Tencent API, sometimes work sometimes not')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册