mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-08 00:47:15 +08:00
fix auto reminder cannot work due to chat ui modified
This commit is contained in:
@@ -181,9 +181,14 @@ const attachRequestsListener = async (target: Target) => {
|
|||||||
const url = new URL(request)
|
const url = new URL(request)
|
||||||
const encryptBossIdInAddFriendUrl = url.searchParams.get('bossId')
|
const encryptBossIdInAddFriendUrl = url.searchParams.get('bossId')
|
||||||
|
|
||||||
const bossInfo: any = await page.evaluate(
|
const bossInfo =
|
||||||
'document.querySelector(".chat-conversation").__vue__.bossInfo$'
|
(await page.evaluate(
|
||||||
)
|
'document.querySelector(".chat-conversation .chat-record")?.__vue__?.boss'
|
||||||
|
)) ?? null
|
||||||
|
if (!bossInfo) {
|
||||||
|
console.warn('cannot find boss info on page.')
|
||||||
|
return
|
||||||
|
}
|
||||||
const ds = await dbInitPromise
|
const ds = await dbInitPromise
|
||||||
// save boss info
|
// save boss info
|
||||||
const bossInfoRepository = ds.getRepository(BossInfo)
|
const bossInfoRepository = ds.getRepository(BossInfo)
|
||||||
@@ -206,15 +211,24 @@ const attachRequestsListener = async (target: Target) => {
|
|||||||
const rawChatRecordList =
|
const rawChatRecordList =
|
||||||
(
|
(
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
'document.querySelector(".message-content .chat-record").__vue__.records$'
|
'document.querySelector(".message-content .chat-record").__vue__.list$'
|
||||||
)
|
)
|
||||||
)?.filter((msg) => ['received', 'sent'].includes(msg.style)) ?? []
|
)?.filter((it) => {
|
||||||
|
return (
|
||||||
|
it.status !== 3 && // filter system notification out
|
||||||
|
it.templateId === 1 && // filter system notification out
|
||||||
|
(
|
||||||
|
(['text', 'sticker', 'image', 'sound', 'comDesc'].includes(it.messageType) && !it.extend?.greetingQuestionAnswer) // include those message, filter out auto ask
|
||||||
|
|| (it.messageType === 'dialog' && [0, 1, 2, 8, 11, 12, 14, 17, 33].includes(it?.dialog?.type)) // include message like resume, phone, map, etc., filter out auto ask
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}) ?? []
|
||||||
|
|
||||||
const chatRecordList = rawChatRecordList.map(it => {
|
const chatRecordList = rawChatRecordList.map(it => {
|
||||||
const mappedItem = {} as InstanceType<typeof ChatMessageRecord>
|
const mappedItem = {} as InstanceType<typeof ChatMessageRecord>
|
||||||
mappedItem.mid = it.mid
|
mappedItem.mid = it.mid
|
||||||
mappedItem.encryptFromUserId = it.style === 'sent' ? currentUserInfo.encryptUserId : it.style === 'received' ? bossInfo.encryptBossId : ''
|
mappedItem.encryptFromUserId = it.isSelf ? currentUserInfo.encryptUserId : bossInfo.encryptBossId
|
||||||
mappedItem.encryptToUserId = it.style === 'sent' ? bossInfo.encryptBossId: it.style === 'received' ? currentUserInfo.encryptUserId : ''
|
mappedItem.encryptToUserId = it.isSelf ? bossInfo.encryptBossId : currentUserInfo.encryptUserId
|
||||||
mappedItem.style = it.style
|
mappedItem.style = it.style
|
||||||
mappedItem.type = it.type
|
mappedItem.type = it.type
|
||||||
mappedItem.time = it.time ? new Date(it.time) : null
|
mappedItem.time = it.time ? new Date(it.time) : null
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ async function saveCurrentChatRecord(page) {
|
|||||||
'document.querySelector(".main-wrap").__vue__.$store.state.userInfo'
|
'document.querySelector(".main-wrap").__vue__.$store.state.userInfo'
|
||||||
)
|
)
|
||||||
const bossInfo = await page.evaluate(
|
const bossInfo = await page.evaluate(
|
||||||
'document.querySelector(".chat-conversation").__vue__.bossInfo$'
|
'document.querySelector(".chat-conversation .chat-record")?.__vue__?.boss'
|
||||||
)
|
)
|
||||||
|
|
||||||
const ds = await dbInitPromise
|
const ds = await dbInitPromise
|
||||||
@@ -252,27 +252,34 @@ const mainLoop = async () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
await sleepWithRandomDelay(1500)
|
await sleepWithRandomDelay(1500)
|
||||||
const bossInfo = await pageMapByName.boss?.evaluate(() => {
|
const bossInfo = await pageMapByName.boss?.evaluate(
|
||||||
return document.querySelector('.chat-conversation')?.__vue__['bossInfo$']
|
'document.querySelector(".chat-conversation .chat-record")?.__vue__?.boss'
|
||||||
})
|
)
|
||||||
|
|
||||||
const historyMessageList =
|
const historyMessageList =
|
||||||
(
|
(
|
||||||
await pageMapByName.boss?.evaluate(() => {
|
await pageMapByName.boss?.evaluate(() => {
|
||||||
return (
|
return document.querySelector('.message-content .chat-record')?.__vue__?.list$ ?? []
|
||||||
document.querySelector('.main-wrap .chat-conversation .chat-record')?.__vue__
|
|
||||||
?.records$ ?? []
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
)?.filter((msg) => ['received', 'sent'].includes(msg.style)) ?? []
|
)?.filter((it) => {
|
||||||
|
return (
|
||||||
|
it.status !== 3 && // filter system notification out
|
||||||
|
it.templateId === 1 && // filter system notification out
|
||||||
|
((['text', 'sticker', 'image', 'sound', 'comDesc'].includes(it.messageType) &&
|
||||||
|
!it.extend?.greetingQuestionAnswer) || // include those message, filter out auto ask
|
||||||
|
(it.messageType === 'dialog' &&
|
||||||
|
[0, 1, 2, 8, 11, 12, 14, 17, 33].includes(it?.dialog?.type))) // include message like resume, phone, map, etc., filter out auto ask
|
||||||
|
)
|
||||||
|
}) ?? []
|
||||||
|
|
||||||
const lastGeekMessageSendTime =
|
const lastGeekMessageSendTime = historyMessageList.findLast((it) => it.isSelf)?.time ?? 0
|
||||||
historyMessageList.findLast((it) => it.style === 'sent')?.time ?? 0
|
|
||||||
if (
|
if (
|
||||||
historyMessageList[historyMessageList.length - 1].style === 'sent' &&
|
historyMessageList[historyMessageList.length - 1].isSelf &&
|
||||||
historyMessageList[historyMessageList.length - 1].status === MsgStatus.HAS_READ &&
|
historyMessageList[historyMessageList.length - 1].status === MsgStatus.HAS_READ &&
|
||||||
(!bossInfo.bothTalked ||
|
((bossInfo && !bossInfo.bothTalked) ||
|
||||||
!historyMessageList.filter((it) => it.style === 'received').length) &&
|
!historyMessageList.filter(
|
||||||
|
(it) => !it.isSelf // not sent by me
|
||||||
|
).length) &&
|
||||||
// don't disturb too much
|
// don't disturb too much
|
||||||
Date.now() - lastGeekMessageSendTime >=
|
Date.now() - lastGeekMessageSendTime >=
|
||||||
(throttleIntervalMinutes + 4 * Math.random()) * 60 * 1000
|
(throttleIntervalMinutes + 4 * Math.random()) * 60 * 1000
|
||||||
|
|||||||
Reference in New Issue
Block a user