Skip to content

Commit

Permalink
fix: 某些特殊情况群聊记录
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Oct 13, 2023
1 parent 4066f17 commit 0a3c95d
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions apps/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,6 @@ export class chatgpt extends plugin {
// opt.messageType = allThrottled ? 'Chat' : 'SearchQuery'
if (Config.enableGroupContext && e.isGroup && typeof e.group.getMemberMap === 'function') {
try {
let memberMap = await e.group.getMemberMap()
opt.groupId = e.group_id
opt.qq = e.sender.user_id
opt.nickname = e.sender.card
Expand All @@ -1601,23 +1600,28 @@ export class chatgpt extends plugin {
if (master && !e.group) {
opt.masterName = Bot.getFriendList().get(parseInt(master))?.nickname
}
let latestChat = await e.group.getChatHistory(0, 1)
let seq = latestChat[0].seq
let chats = []
while (chats.length < Config.groupContextLength) {
let chatHistory = await e.group.getChatHistory(seq, 20)
chats.push(...chatHistory)
}
chats = chats.slice(0, Config.groupContextLength)
let mm = await e.group.getMemberMap()
chats.forEach(chat => {
let sender = mm.get(chat.sender.user_id)
if (sender) {
chat.sender = sender
let latestChats = await e.group.getChatHistory(0, 1)
if (latestChats.length > 0) {
let latestChat = latestChats[0]
if (latestChat) {
let seq = latestChat.seq
let chats = []
while (chats.length < Config.groupContextLength) {
let chatHistory = await e.group.getChatHistory(seq, 20)
chats.push(...chatHistory)
}
chats = chats.slice(0, Config.groupContextLength)
let mm = await e.group.getMemberMap()
chats.forEach(chat => {
let sender = mm.get(chat.sender.user_id)
if (sender) {
chat.sender = sender
}
})
// console.log(chats)
opt.chats = chats
}
})
// console.log(chats)
opt.chats = chats
}
} catch (err) {
logger.warn('获取群聊聊天记录失败,本次对话不携带聊天记录', err)
}
Expand Down

0 comments on commit 0a3c95d

Please sign in to comment.