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

fix puppet.userId to puppet.userSelf().id

上级 fc503e11
...@@ -59,7 +59,10 @@ function onDing( ...@@ -59,7 +59,10 @@ function onDing(
this.emit('watchdog', { data }) this.emit('watchdog', { data })
} }
async function onScan(this: PuppetPuppeteer, data: ScanData): Promise<void> { async function onScan(
this: PuppetPuppeteer,
data: ScanData,
): Promise<void> {
log.verbose('PuppetPuppeteerEvent', 'onScan({code: %d, url: %s})', data.code, data.url) log.verbose('PuppetPuppeteerEvent', 'onScan({code: %d, url: %s})', data.code, data.url)
if (this.state.off()) { if (this.state.off()) {
...@@ -93,7 +96,11 @@ function onLog(data: any): void { ...@@ -93,7 +96,11 @@ function onLog(data: any): void {
log.silly('PuppetPuppeteerEvent', 'onLog(%s)', data) log.silly('PuppetPuppeteerEvent', 'onLog(%s)', data)
} }
async function onLogin(this: PuppetPuppeteer, note: string, ttl = 30): Promise<void> { async function onLogin(
this: PuppetPuppeteer,
note: string,
ttl = 30,
): Promise<void> {
log.verbose('PuppetPuppeteerEvent', 'onLogin(%s, %d)', note, ttl) log.verbose('PuppetPuppeteerEvent', 'onLogin(%s, %d)', note, ttl)
const TTL_WAIT_MILLISECONDS = 1 * 1000 const TTL_WAIT_MILLISECONDS = 1 * 1000
......
...@@ -102,7 +102,10 @@ const regexConfig = { ...@@ -102,7 +102,10 @@ const regexConfig = {
], ],
} }
async function checkFriendRequest(m: PuppeteerMessage) { async function checkFriendRequest(
this: PuppetPuppeteer,
m: PuppeteerMessage,
) {
if (!m.rawObj) { if (!m.rawObj) {
throw new Error('message empty') throw new Error('message empty')
} }
...@@ -129,7 +132,10 @@ async function checkFriendRequest(m: PuppeteerMessage) { ...@@ -129,7 +132,10 @@ async function checkFriendRequest(m: PuppeteerMessage) {
/** /**
* try to find FriendRequest Confirmation Message * try to find FriendRequest Confirmation Message
*/ */
function parseFriendConfirm(content: string): boolean { function parseFriendConfirm(
this: PuppetPuppeteer,
content: string,
): boolean {
const reList = regexConfig.friendConfirm const reList = regexConfig.friendConfirm
let found = false let found = false
...@@ -141,11 +147,14 @@ function parseFriendConfirm(content: string): boolean { ...@@ -141,11 +147,14 @@ function parseFriendConfirm(content: string): boolean {
} }
} }
async function checkFriendConfirm(m: PuppeteerMessage) { async function checkFriendConfirm(
this: PuppetPuppeteer,
m: PuppeteerMessage,
) {
const content = m.text() const content = m.text()
log.silly('PuppetPuppeteerFirer', 'fireFriendConfirm(%s)', content) log.silly('PuppetPuppeteerFirer', 'fireFriendConfirm(%s)', content)
if (!parseFriendConfirm(content)) { if (!parseFriendConfirm.call(this, content)) {
return return
} }
const request = new PuppeteerFriendRequest() const request = new PuppeteerFriendRequest()
...@@ -171,7 +180,10 @@ async function checkFriendConfirm(m: PuppeteerMessage) { ...@@ -171,7 +180,10 @@ async function checkFriendConfirm(m: PuppeteerMessage) {
* 管理员 invited 小桔建群助手 to the group chat * 管理员 invited 小桔建群助手 to the group chat
* 管理员 invited 庆次、小桔妹 to the group chat * 管理员 invited 庆次、小桔妹 to the group chat
*/ */
function parseRoomJoin(content: string): [string[], string] { function parseRoomJoin(
this: PuppetPuppeteer,
content: string,
): [string[], string] {
log.verbose('PuppetPuppeteerFirer', 'checkRoomJoin(%s)', content) log.verbose('PuppetPuppeteerFirer', 'checkRoomJoin(%s)', content)
const reListInvite = regexConfig.roomJoinInvite const reListInvite = regexConfig.roomJoinInvite
...@@ -194,7 +206,10 @@ function parseRoomJoin(content: string): [string[], string] { ...@@ -194,7 +206,10 @@ function parseRoomJoin(content: string): [string[], string] {
return [inviteeList, inviter] // put invitee at first place return [inviteeList, inviter] // put invitee at first place
} }
async function checkRoomJoin(m: PuppeteerMessage): Promise<boolean> { async function checkRoomJoin(
this: PuppetPuppeteer,
m: PuppeteerMessage,
): Promise<boolean> {
const room = m.room() const room = m.room()
if (!room) { if (!room) {
...@@ -206,7 +221,7 @@ async function checkRoomJoin(m: PuppeteerMessage): Promise<boolean> { ...@@ -206,7 +221,7 @@ async function checkRoomJoin(m: PuppeteerMessage): Promise<boolean> {
let inviteeList: string[], inviter: string let inviteeList: string[], inviter: string
try { try {
[inviteeList, inviter] = parseRoomJoin(text) [inviteeList, inviter] = parseRoomJoin.call(this, text)
} catch (e) { } catch (e) {
log.silly('PuppetPuppeteerFirer', 'fireRoomJoin() "%s" is not a join message', text) log.silly('PuppetPuppeteerFirer', 'fireRoomJoin() "%s" is not a join message', text)
return false // not a room join message return false // not a room join message
...@@ -221,8 +236,7 @@ async function checkRoomJoin(m: PuppeteerMessage): Promise<boolean> { ...@@ -221,8 +236,7 @@ async function checkRoomJoin(m: PuppeteerMessage): Promise<boolean> {
try { try {
if (inviter === 'You' || inviter === '' || inviter === 'you') { if (inviter === 'You' || inviter === '' || inviter === 'you') {
inviterContact = PuppeteerContact.load(this.userId) as PuppeteerContact inviterContact = this.userSelf()
inviterContact.puppet = m.puppet
} }
const max = 20 const max = 20
...@@ -321,7 +335,10 @@ async function checkRoomJoin(m: PuppeteerMessage): Promise<boolean> { ...@@ -321,7 +335,10 @@ async function checkRoomJoin(m: PuppeteerMessage): Promise<boolean> {
} }
function parseRoomLeave(content: string): [string, string] { function parseRoomLeave(
this: PuppetPuppeteer,
content: string,
): [string, string] {
const reListByBot = regexConfig.roomLeaveByBot const reListByBot = regexConfig.roomLeaveByBot
const reListByOther = regexConfig.roomLeaveByOther const reListByOther = regexConfig.roomLeaveByOther
let foundByBot: string[]|null = [] let foundByBot: string[]|null = []
...@@ -331,7 +348,7 @@ function parseRoomLeave(content: string): [string, string] { ...@@ -331,7 +348,7 @@ function parseRoomLeave(content: string): [string, string] {
if ((!foundByBot || !foundByBot.length) && (!foundByOther || !foundByOther.length)) { if ((!foundByBot || !foundByBot.length) && (!foundByOther || !foundByOther.length)) {
throw new Error('checkRoomLeave() no matched re for ' + content) throw new Error('checkRoomLeave() no matched re for ' + content)
} }
const [leaver, remover] = foundByBot ? [ foundByBot[1], this.userId ] : [ this.userId, foundByOther[1] ] const [leaver, remover] = foundByBot ? [ foundByBot[1], this.userSelf().id ] : [ this.userSelf().id, foundByOther[1] ]
return [leaver, remover] return [leaver, remover]
} }
...@@ -346,7 +363,7 @@ async function checkRoomLeave( ...@@ -346,7 +363,7 @@ async function checkRoomLeave(
let leaver: string, remover: string let leaver: string, remover: string
try { try {
[leaver, remover] = parseRoomLeave(m.text()) [leaver, remover] = parseRoomLeave.call(this, m.text())
} catch (e) { } catch (e) {
return false return false
} }
...@@ -363,8 +380,7 @@ async function checkRoomLeave( ...@@ -363,8 +380,7 @@ async function checkRoomLeave(
*/ */
let leaverContact: PuppeteerContact | null, removerContact: PuppeteerContact | null let leaverContact: PuppeteerContact | null, removerContact: PuppeteerContact | null
if (leaver === this.userSelf().id) { if (leaver === this.userSelf().id) {
leaverContact = PuppeteerContact.load(this.userSelf().id) leaverContact = this.userSelf()
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})
...@@ -406,7 +422,10 @@ async function checkRoomLeave( ...@@ -406,7 +422,10 @@ async function checkRoomLeave(
return true return true
} }
function parseRoomTopic(content: string): [string, string] { function parseRoomTopic(
this: PuppetPuppeteer,
content: string,
): [string, string] {
const reList = regexConfig.roomTopic const reList = regexConfig.roomTopic
let found: string[]|null = [] let found: string[]|null = []
...@@ -418,10 +437,12 @@ function parseRoomTopic(content: string): [string, string] { ...@@ -418,10 +437,12 @@ function parseRoomTopic(content: string): [string, string] {
return [topic, changer] return [topic, changer]
} }
async function checkRoomTopic(m: PuppeteerMessage): Promise<boolean> { async function checkRoomTopic(
this: PuppetPuppeteer,
m: PuppeteerMessage): Promise<boolean> {
let topic, changer let topic, changer
try { try {
[topic, changer] = parseRoomTopic(m.text()) [topic, changer] = parseRoomTopic.call(this, m.text())
} catch (e) { // not found } catch (e) { // not found
return false return false
} }
...@@ -436,7 +457,7 @@ async function checkRoomTopic(m: PuppeteerMessage): Promise<boolean> { ...@@ -436,7 +457,7 @@ async function checkRoomTopic(m: PuppeteerMessage): Promise<boolean> {
let changerContact: PuppeteerContact | null let changerContact: PuppeteerContact | null
if (/^You$/.test(changer) || /^你$/.test(changer)) { if (/^You$/.test(changer) || /^你$/.test(changer)) {
changerContact = PuppeteerContact.load(this.userId) as PuppeteerContact changerContact = this.userSelf()
changerContact.puppet = m.puppet changerContact.puppet = m.puppet
} else { } else {
changerContact = room.member(changer) changerContact = room.member(changer)
......
...@@ -75,7 +75,7 @@ export class PuppeteerMessage extends Message { ...@@ -75,7 +75,7 @@ export class PuppeteerMessage extends Message {
* @private * @private
*/ */
constructor( constructor(
fileOrObj?: string | MsgRawPayload, fileOrPayload?: string | MsgRawPayload,
) { ) {
super() super()
log.silly('PuppeteerMessage', 'constructor()') log.silly('PuppeteerMessage', 'constructor()')
...@@ -83,14 +83,14 @@ export class PuppeteerMessage extends Message { ...@@ -83,14 +83,14 @@ export class PuppeteerMessage extends Message {
this.obj = {} as MsgPayload this.obj = {} as MsgPayload
// this.rawObj = {} as MsgRawObj // this.rawObj = {} as MsgRawObj
if (!fileOrObj) { if (!fileOrPayload) {
return return
} }
if (typeof fileOrObj === 'string') { if (typeof fileOrPayload === 'string') {
this.parsedPath = path.parse(fileOrObj) this.parsedPath = path.parse(fileOrPayload)
} else if (typeof fileOrObj === 'object') { } else if (typeof fileOrPayload === 'object') {
this.rawObj = fileOrObj this.rawObj = fileOrPayload
this.obj = this.parse(this.rawObj) this.obj = this.parse(this.rawObj)
this.id = this.obj.id this.id = this.obj.id
} else { } else {
...@@ -506,7 +506,7 @@ export class PuppeteerMessage extends Message { ...@@ -506,7 +506,7 @@ export class PuppeteerMessage extends Message {
) )
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(mentionList)}`) log.warn('PuppeteerMessage', `message.mentioned() can not found member using room.member() from mentionList, metion string: ${JSON.stringify(mentionList)}`)
} }
return contactList return contactList
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册