mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
feat: 进一步适配铃音+shamrock;词云进化
This commit is contained in:
parent
61d3b48781
commit
0bff8c85b0
7 changed files with 209 additions and 65 deletions
40
apps/chat.js
40
apps/chat.js
|
|
@ -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')
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
@ -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('在统计啦,请稍等...')
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue