Skip to content

Commit

Permalink
Merge branch 'v2' of github.com:ikechan8370/chatgpt-plugin into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Oct 14, 2023
2 parents 83a82cf + 4c16489 commit 1e867c0
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 353 deletions.
14 changes: 7 additions & 7 deletions apps/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1592,13 +1592,13 @@ export class chatgpt extends plugin {
opt.qq = e.sender.user_id
opt.nickname = e.sender.card
opt.groupName = e.group.name
opt.botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : Bot.nickname
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) {
opt.masterName = e.group.pickMember(parseInt(master)).card || e.group.pickMember(parseInt(master)).nickname
}
if (master && !e.group) {
opt.masterName = Bot.getFriendList().get(parseInt(master))?.nickname
opt.masterName = e.bot.getFriendList().get(parseInt(master))?.nickname
}
let latestChats = await e.group.getChatHistory(0, 1)
if (latestChats.length > 0) {
Expand Down Expand Up @@ -2043,13 +2043,13 @@ export class chatgpt extends plugin {
opt.qq = e.sender.user_id
opt.nickname = e.sender.card
opt.groupName = e.group.name
opt.botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : Bot.nickname
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) {
opt.masterName = e.group.pickMember(parseInt(master)).card || e.group.pickMember(parseInt(master)).nickname
}
if (master && !e.group) {
opt.masterName = Bot.getFriendList().get(parseInt(master))?.nickname
opt.masterName = e.bot.getFriendList().get(parseInt(master))?.nickname
}
let latestChat = await e.group.getChatHistory(0, 1)
let seq = latestChat[0].seq
Expand Down Expand Up @@ -2087,7 +2087,7 @@ export class chatgpt extends plugin {
system += chats
.map(chat => {
let sender = chat.sender || {}
// if (sender.user_id === Bot.uin && chat.raw_message.startsWith('建议的回复')) {
// if (sender.user_id === e.bot.uin && chat.raw_message.startsWith('建议的回复')) {
if (chat.raw_message.startsWith('建议的回复')) {
// 建议的回复太容易污染设定导致对话太固定跑偏了
return ''
Expand Down Expand Up @@ -2215,7 +2215,7 @@ export class chatgpt extends plugin {
logger.mark(logger.green('【ChatGPT-Plugin】插件avocado-plugin未安装') + ',安装后可查看最近热映电影与体验可玩性更高的点歌工具。\n可前往 https://github.com/Qz-Sean/avocado-plugin 获取')
}
if (e.isGroup) {
let botInfo = await Bot.getGroupMemberInfo(e.group_id, getUin(e), true)
let botInfo = await e.bot.getGroupMemberInfo(e.group_id, getUin(e), true)
if (botInfo.role !== 'member') {
// 管理员才给这些工具
tools.push(...[new EditCardTool(), new JinyanTool(), new KickOutTool(), new HandleMessageMsgTool(), new SetTitleTool()])
Expand Down Expand Up @@ -2467,7 +2467,7 @@ export class chatgpt extends plugin {
}
if (bots.code === 0) {
if (bots.data.pageList.length > 0) {
this.reply(await makeForwardMsg(this.e, bots.data.pageList.map(msg => `${msg.bot.botId} - ${msg.bot.botName}`)))
this.reply(await makeForwardMsg(this.e, bots.data.pageList.map(msg => `${msg.e.bot.botId} - ${msg.e.bot.botName}`)))
} else {
await e.reply('未查到相关助手', true)
}
Expand Down
12 changes: 6 additions & 6 deletions apps/entertainment.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ ${translateLangLabels}
let groupId = e.msg.replace(/^#chatgpt/, '')
logger.info(groupId)
groupId = parseInt(groupId)
if (groupId && !Bot.getGroupList().get(groupId)) {
if (groupId && !e.bot.getGroupList().get(groupId)) {
await e.reply('机器人不在这个群里!')
return
}
Expand All @@ -310,7 +310,7 @@ ${translateLangLabels}
if (!groupId) {
await e.reply(sendable)
} else {
await Bot.sendGroupMsg(groupId, sendable)
await e.bot.sendGroupMsg(groupId, sendable)
await e.reply('发送成功!')
}
}
Expand All @@ -325,7 +325,7 @@ ${translateLangLabels}
continue
}
let groupId = parseInt(element)
if (Bot.getGroupList().get(groupId)) {
if (this.e.bot.getGroupList().get(groupId)) {
// 打招呼概率
if (Math.floor(Math.random() * 100) < Config.helloProbability) {
let message = await generateHello()
Expand Down Expand Up @@ -381,12 +381,12 @@ ${translateLangLabels}
}
}
if (useSilk) {
await Bot.sendGroupMsg(groupId, await uploadRecord(audio))
await this.e.bot.sendGroupMsg(groupId, await uploadRecord(audio))
} else {
await Bot.sendGroupMsg(groupId, segment.record(audio))
await this.e.bot.sendGroupMsg(groupId, segment.record(audio))
}
} else {
await Bot.sendGroupMsg(groupId, message)
await this.e.bot.sendGroupMsg(groupId, message)
}
} else {
logger.info(`时机未到,这次就不打招呼给群聊${groupId}了`)
Expand Down
14 changes: 7 additions & 7 deletions apps/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export class history extends plugin {
let parentMessageId = previousConversation.parentMessageId
let tmp = {}
const previousCachedMessages = getMessagesForConversation(conversation.messages, parentMessageId)
.map((message) => {
return {
text: message.message,
author: message.role === 'User' ? 'user' : 'bot'
}
})
.map((message) => {
return {
text: message.message,
author: message.role === 'User' ? 'user' : 'bot'
}
})
previousCachedMessages.forEach(m => {
if (m.author === 'user') {
tmp.prompt = m.text
Expand Down Expand Up @@ -100,7 +100,7 @@ export class history extends plugin {
},
bot: {
qq: getUin(e),
name: Bot.nickname
name: e.bot.nickname
},
chat
}, {})
Expand Down
4 changes: 2 additions & 2 deletions apps/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
}
} else if (match) {
const groupId = parseInt(match[1], 10)
if (Bot.getGroupList().get(groupId)) {
if (e.bot.getGroupList().get(groupId)) {
if (await redis.get(`CHATGPT:SHUT_UP:${groupId}`)) {
await redis.del(`CHATGPT:SHUT_UP:${groupId}`)
await redis.set(`CHATGPT:SHUT_UP:${groupId}`, '1', { EX: time })
Expand Down Expand Up @@ -1040,7 +1040,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
return false
}
const groupId = parseInt(match[1], 10)
if (Bot.getGroupList().get(groupId)) {
if (e.bot.getGroupList().get(groupId)) {
if (await redis.get(`CHATGPT:SHUT_UP:${groupId}`)) {
await redis.del(`CHATGPT:SHUT_UP:${groupId}`)
await e.reply(`好的主人,我终于又可以在群${groupId}和大家聊天了`)
Expand Down
1 change: 0 additions & 1 deletion utils/SydneyAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ export default class SydneyAIClient {
context += chats
.map(chat => {
let sender = chat.sender || chat || {}
// if (sender.user_id === Bot.uin && chat.raw_message.startsWith('建议的回复')) {
if (chat.raw_message.startsWith('建议的回复')) {
// 建议的回复太容易污染设定导致对话太固定跑偏了
return ''
Expand Down
21 changes: 14 additions & 7 deletions utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export async function makeForwardMsg (e, msg = [], dec = '') {
if (Version.isTrss) {
return common.makeForwardMsg(e, msg, dec)
}
let nickname = Bot.nickname
let nickname = e.bot.nickname
if (e.isGroup) {
try {
let info = await Bot.getGroupMemberInfo(e.group_id, getUin(e))
let info = await e.bot.getGroupMemberInfo(e.group_id, getUin(e))
nickname = info.card || info.nickname
} catch (err) {
console.error(`Failed to get group member info: ${err}`)
Expand Down Expand Up @@ -792,7 +792,7 @@ export async function getImageOcrText (e) {
let resultArr = []
let eachImgRes = ''
for (let i in img) {
const imgOCR = await Bot.imageOcr(img[i])
const imgOCR = await e.bot.imageOcr(img[i])
for (let text of imgOCR.wordslist) {
eachImgRes += (`${text?.words} \n`)
}
Expand Down Expand Up @@ -828,10 +828,17 @@ export function getMaxModelTokens (model = 'gpt-3.5-turbo') {

export function getUin (e) {
if (e?.bot?.uin) return e.bot.uin
if (Array.isArray(Bot.uin)) {
if (Config.trssBotUin && Bot.uin.indexOf(Config.trssBotUin) > -1) return Config.trssBotUin
else return Bot.uin[0]
} else return Bot.uin
if (e) {
if (Array.isArray(e.bot.uin)) {
if (Config.trssBotUin && e.bot.uin.indexOf(Config.trssBotUin) > -1) return Config.trssBotUin
else return e.bot.uin[0]
} else return e.bot.uin
} else {
if (Array.isArray(Bot.uin)) {
if (Config.trssBotUin && Bot.uin.indexOf(Config.trssBotUin) > -1) return Config.trssBotUin
else return Bot.uin[0]
} else return Bot.uin
}
}

/**
Expand Down
Loading

0 comments on commit 1e867c0

Please sign in to comment.