Skip to content

Commit

Permalink
fix: merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Nov 21, 2023
2 parents f246e84 + c99019c commit 2b19302
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 85 deletions.
42 changes: 4 additions & 38 deletions apps/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {solveCaptchaOneShot} from '../utils/bingCaptcha.js'
import {ClaudeAIClient} from '../utils/claude.ai/index.js'
import {getProxy} from '../utils/proxy.js'
import {QwenApi} from '../utils/alibaba/qwen-api.js'
import {getChatHistoryGroup} from '../utils/chat.js'

try {
await import('@azure/openai')
Expand Down Expand Up @@ -1660,28 +1661,7 @@ export class chatgpt extends plugin {
if (master && !e.group) {
opt.masterName = e.bot.getFriendList().get(parseInt(master))?.nickname
}
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
}
}
opt.chats = await getChatHistoryGroup(e, Config.groupContextLength)
} catch (err) {
logger.warn('获取群聊聊天记录失败,本次对话不携带聊天记录', err)
}
Expand Down Expand Up @@ -2162,7 +2142,7 @@ export class chatgpt extends plugin {
opt.groupId = e.group_id
opt.qq = e.sender.user_id
opt.nickname = e.sender.card
opt.groupName = e.group.name
opt.groupName = e.group.name || e.group_name
opt.botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : e.bot.nickname
let master = (await getMasterQQ())[0]
if (master && e.group) {
Expand All @@ -2171,21 +2151,7 @@ export class chatgpt extends plugin {
if (master && !e.group) {
opt.masterName = e.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.reverse())
}
chats = chats.slice(0, Config.groupContextLength)
// 太多可能会干扰AI对自身qq号和用户qq的判断,感觉gpt3.5也处理不了那么多信息
chats = chats > 50 ? 50 : chats
let mm = await e.group.getMemberMap()
chats.forEach(chat => {
let sender = mm.get(chat.sender.user_id)
chat.sender = sender
})
let chats = await getChatHistoryGroup(e, Config.groupContextLength)
opt.chats = chats
const namePlaceholder = '[name]'
const defaultBotName = 'ChatGPT'
Expand Down
58 changes: 56 additions & 2 deletions apps/entertainment.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class Entertainment extends plugin {
reg: '^#(|最新)词云(\\d{1,2}h{0,1}|)$',
fnc: 'wordcloud_latest'
},
{
reg: '^#(我的)?(本月|本周|今日)?词云$',
fnc: 'wordcloud_new'
},
{
reg: '^#((寄批踢|gpt|GPT)?翻.*|chatgpt翻译帮助)',
fnc: 'translate'
Expand Down Expand Up @@ -215,10 +219,10 @@ ${translateLangLabels}

const regExp = /词云(\d{0,2})(|h)/
const match = e.msg.trim().match(regExp)
const duration = !match[1] ? 12 : parseInt(match[1]) // default 12h
const duration = !match[1] ? 12 : parseInt(match[1]) // default 12h

if (duration > 24) {
await e.reply('最多只能统计24小时内的记录哦')
await e.reply('最多只能统计24小时内的记录哦,你可以使用#本周词云和#本月词云获取更长时间的统计~')
return false
}
await e.reply('在统计啦,请稍等...')
Expand All @@ -236,6 +240,56 @@ ${translateLangLabels}
}
}

async wordcloud_new (e) {
if (e.isGroup) {
let groupId = e.group_id
let userId
if (e.msg.includes('我的')) {
userId = e.sender.user_id
}
let at = e.message.find(m => m.type === 'at')
if (at) {
userId = at.qq
}
let lock = await redis.get(`CHATGPT:WORDCLOUD_NEW:${groupId}_${userId}`)
if (lock) {
await e.reply('别着急,上次统计还没完呢')
return true
}
await e.reply('在统计啦,请稍等...')
let duration = 24
if (e.msg.includes('本周')) {
const now = new Date() // Get the current date and time
let day = now.getDay()
let diff = now.getDate() - day + (day === 0 ? -6 : 1)
const startOfWeek = new Date(new Date().setDate(diff))
startOfWeek.setHours(0, 0, 0, 0) // Set the time to midnight (start of the day)
duration = (now - startOfWeek) / 1000 / 60 / 60
} else if (e.msg.includes('本月')) {
const now = new Date() // Get the current date and time
const startOfMonth = new Date(new Date().setDate(0))
startOfMonth.setHours(0, 0, 0, 0) // Set the time to midnight (start of the day)
duration = (now - startOfMonth) / 1000 / 60 / 60
} else {
// 默认今天
const now = new Date()
const startOfToday = new Date() // Get the current date and time
startOfToday.setHours(0, 0, 0, 0) // Set the time to midnight (start of the day)
duration = (now - startOfToday) / 1000 / 60 / 60
}
await redis.set(`CHATGPT:WORDCLOUD_NEW:${groupId}_${userId}`, '1', { EX: 600 })
try {
await makeWordcloud(e, e.group_id, duration, userId)
} catch (err) {
logger.error(err)
await e.reply(err)
}
await redis.del(`CHATGPT:WORDCLOUD_NEW:${groupId}_${userId}`)
} else {
await e.reply('请在群里发送此命令')
}
}

async combineEmoj (e) {
let left = e.msg.codePointAt(0).toString(16).toLowerCase()
let right = e.msg.codePointAt(2).toString(16).toLowerCase()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"js-tiktoken": "^1.0.5",
"keyv": "^4.5.3",
"keyv-file": "^0.2.0",
"microsoft-cognitiveservices-speech-sdk": "^1.30.1",
"microsoft-cognitiveservices-speech-sdk": "1.32.0",
"node-fetch": "^3.3.1",
"openai": "^3.2.1",
"p-timeout": "^6.1.2",
Expand Down
2 changes: 1 addition & 1 deletion utils/SydneyAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export default class SydneyAIClient {
context += chats
.map(chat => {
let sender = chat.sender || chat || {}
if (chat.raw_message.startsWith('建议的回复')) {
if (chat.raw_message?.startsWith('建议的回复')) {
// 建议的回复太容易污染设定导致对话太固定跑偏了
return ''
}
Expand Down
34 changes: 34 additions & 0 deletions utils/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export async function getChatHistoryGroup (e, num) {
// if (e.adapter === 'shamrock') {
// return await e.group.getChatHistory(0, num, false)
// } else {
let latestChats = await e.group.getChatHistory(0, 1)
if (latestChats.length > 0) {
let latestChat = latestChats[0]
if (latestChat) {
let seq = latestChat.seq || latestChat.message_id
let chats = []
while (chats.length < num) {
let chatHistory = await e.group.getChatHistory(seq, 20)
chats.push(...chatHistory)
seq = chatHistory[0].seq || chatHistory[0].message_id
}
chats = chats.slice(0, num)
try {
let mm = await e.group.getMemberMap()
chats.forEach(chat => {
let sender = mm.get(chat.sender.user_id)
if (sender) {
chat.sender = sender
}
})
} catch (err) {
logger.warn(err)
}
// console.log(chats)
return chats
}
}
// }
return []
}
6 changes: 4 additions & 2 deletions utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,10 @@ export function getMaxModelTokens (model = 'gpt-3.5-turbo') {
if (model.startsWith('gpt-3.5-turbo')) {
if (model.includes('16k')) {
return 16000
} else {
} else if (model.includes('0613') || model.includes('0314')) {
return 4000
} else {
return 16000
}
} else {
if (model.includes('32k')) {
Expand Down Expand Up @@ -870,7 +872,7 @@ export async function generateAudio (e, pendingText, speakingEmotion, emotionDeg
if (!Config.ttsSpace && !Config.azureTTSKey && !Config.voicevoxSpace) return false
let wav
const speaker = getUserSpeaker(await getUserReplySetting(e))
let ignoreEncode = getUin(e) === 88888
let ignoreEncode = e.adapter === 'shamrock'
try {
if (Config.ttsMode === 'vits-uma-genshin-honkai' && Config.ttsSpace) {
if (Config.autoJapanese) {
Expand Down
7 changes: 6 additions & 1 deletion utils/tools/SendAudioMessageTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ export class SendAudioMessageTool extends AbstractTool {
return `audio generation failed, error: ${JSON.stringify(err)}`
}
if (sendable) {
let groupList = e.bot.gl || new Map()
let groupList
try {
groupList = await e.bot.getGroupList()
} catch (err) {
groupList = e.bot.gl
}
try {
if (groupList.get(target)) {
let group = await e.bot.pickGroup(target)
Expand Down
8 changes: 6 additions & 2 deletions utils/tools/SendAvatarTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ export class SendAvatarTool extends AbstractTool {
const target = isNaN(targetGroupIdOrQQNumber) || !targetGroupIdOrQQNumber
? defaultTarget
: parseInt(targetGroupIdOrQQNumber) === e.bot.uin ? defaultTarget : parseInt(targetGroupIdOrQQNumber)

let groupList = e.bot.gl || new Map()
let groupList
try {
groupList = await e.bot.getGroupList()
} catch (err) {
groupList = e.bot.gl
}
console.log('sendAvatar', target, pictures)
if (groupList.get(target)) {
let group = await e.bot.pickGroup(target)
Expand Down
7 changes: 6 additions & 1 deletion utils/tools/SendDiceTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export class SendDiceTool extends AbstractTool {
const target = isNaN(targetGroupIdOrQQNumber) || !targetGroupIdOrQQNumber
? defaultTarget
: parseInt(targetGroupIdOrQQNumber) === e.bot.uin ? defaultTarget : parseInt(targetGroupIdOrQQNumber)
let groupList = e.bot.gl || new Map()
let groupList
try {
groupList = await e.bot.getGroupList()
} catch (err) {
groupList = e.bot.gl
}
num = isNaN(num) || !num ? 1 : num > 5 ? 5 : num
if (groupList.get(target)) {
let group = await e.bot.pickGroup(target, true)
Expand Down
7 changes: 6 additions & 1 deletion utils/tools/SendMessageToSpecificGroupOrUserTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export class SendMessageToSpecificGroupOrUserTool extends AbstractTool {
? defaultTarget
: parseInt(targetGroupIdOrQQNumber) === e.bot.uin ? defaultTarget : parseInt(targetGroupIdOrQQNumber)

let groupList = e.bot.gl || new Map()
let groupList
try {
groupList = await e.bot.getGroupList()
} catch (err) {
groupList = e.bot.gl
}
try {
if (groupList.get(target)) {
let group = await e.bot.pickGroup(target)
Expand Down
7 changes: 6 additions & 1 deletion utils/tools/SendPictureTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export class SendPictureTool extends AbstractTool {
let pictures = urlOfPicture.trim().split(' ')
logger.mark('pictures to send: ', pictures)
pictures = pictures.map(img => segment.image(img))
let groupList = e.bot.gl || new Map()
let groupList
try {
groupList = await e.bot.getGroupList()
} catch (err) {
groupList = e.bot.gl
}
try {
if (groupList.get(target)) {
let group = await e.bot.pickGroup(target)
Expand Down
7 changes: 6 additions & 1 deletion utils/tools/SendRPSTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export class SendRPSTool extends AbstractTool {
const target = isNaN(targetGroupIdOrQQNumber) || !targetGroupIdOrQQNumber
? defaultTarget
: parseInt(targetGroupIdOrQQNumber) === e.bot.uin ? defaultTarget : parseInt(targetGroupIdOrQQNumber)
let groupList = await e.bot.getGroupList()
let groupList
try {
groupList = await e.bot.getGroupList()
} catch (err) {
groupList = e.bot.gl
}
if (groupList.get(target)) {
let group = await e.bot.pickGroup(target, true)
await group.sendMsg(segment.rps(num))
Expand Down
Loading

0 comments on commit 2b19302

Please sign in to comment.