diff --git a/apps/chat.js b/apps/chat.js index cad7c7a..c2ec19a 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -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) { @@ -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 @@ -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 '' @@ -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()]) @@ -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) } diff --git a/apps/entertainment.js b/apps/entertainment.js index 870c578..fb8ff7f 100644 --- a/apps/entertainment.js +++ b/apps/entertainment.js @@ -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 } @@ -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('发送成功!') } } @@ -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() @@ -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}了`) diff --git a/apps/history.js b/apps/history.js index 5f6d5f2..c76b8e1 100644 --- a/apps/history.js +++ b/apps/history.js @@ -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 @@ -100,7 +100,7 @@ export class history extends plugin { }, bot: { qq: getUin(e), - name: Bot.nickname + name: e.bot.nickname }, chat }, {}) diff --git a/apps/management.js b/apps/management.js index 40b48b8..5837afe 100644 --- a/apps/management.js +++ b/apps/management.js @@ -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 }) @@ -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}和大家聊天了`) diff --git a/utils/SydneyAIClient.js b/utils/SydneyAIClient.js index cefc4bd..f24a4fb 100644 --- a/utils/SydneyAIClient.js +++ b/utils/SydneyAIClient.js @@ -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 '' diff --git a/utils/common.js b/utils/common.js index 3e43fd1..f298ac5 100644 --- a/utils/common.js +++ b/utils/common.js @@ -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}`) @@ -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`) } @@ -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 + } } /** diff --git a/utils/poe/index 2.js b/utils/poe/index 2.js deleted file mode 100644 index a01189a..0000000 --- a/utils/poe/index 2.js +++ /dev/null @@ -1,278 +0,0 @@ -import { readFileSync } from 'fs' -import { scrape } from './credential.js' -import fetch from 'node-fetch' -import crypto from 'crypto' -// used when test as a single file -// const _path = process.cwd() -const _path = process.cwd() + '/plugins/chatgpt-plugin/utils/poe' -const gqlDir = `${_path}/graphql` -const queries = { - // chatViewQuery: readFileSync(gqlDir + '/ChatViewQuery.graphql', 'utf8'), - addMessageBreakMutation: readFileSync(gqlDir + '/AddMessageBreakMutation.graphql', 'utf8'), - chatPaginationQuery: readFileSync(gqlDir + '/ChatPaginationQuery.graphql', 'utf8'), - addHumanMessageMutation: readFileSync(gqlDir + '/AddHumanMessageMutation.graphql', 'utf8'), - loginMutation: readFileSync(gqlDir + '/LoginWithVerificationCodeMutation.graphql', 'utf8'), - signUpWithVerificationCodeMutation: readFileSync(gqlDir + '/SignupWithVerificationCodeMutation.graphql', 'utf8'), - sendVerificationCodeMutation: readFileSync(gqlDir + '/SendVerificationCodeForLoginMutation.graphql', 'utf8') -} -const optionMap = [ - { title: 'Claude (Powered by Anthropic)', value: 'a2' }, - { title: 'Sage (Powered by OpenAI - logical)', value: 'capybara' }, - { title: 'Dragonfly (Powered by OpenAI - simpler)', value: 'nutria' }, - { title: 'ChatGPT (Powered by OpenAI - current)', value: 'chinchilla' }, - { title: 'Claude+', value: 'a2_2' }, - { title: 'GPT-4', value: 'beaver' } -] -export class PoeClient { - constructor (props) { - this.config = props - } - - headers = { - 'Content-Type': 'application/json', - Referrer: 'https://poe.com/', - Origin: 'https://poe.com', - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36' - } - - chatId = 0 - bot = '' - - reConnectWs = false - - async setCredentials () { - let result = await scrape(this.config.quora_cookie) - console.log(result) - this.config.quora_formkey = result.appSettings.formkey - this.config.channel_name = result.channelName - this.config.app_settings = result.appSettings - - // set value - this.headers['poe-formkey'] = this.config.quora_formkey - this.headers['poe-tchannel'] = this.config.channel_name - this.headers.Cookie = this.config.quora_cookie - console.log(this.headers) - } - - async subscribe () { - const query = { - queryName: 'subscriptionsMutation', - variables: { - subscriptions: [ - { - subscriptionName: 'messageAdded', - query: 'subscription subscriptions_messageAdded_Subscription(\n $chatId: BigInt!\n) {\n messageAdded(chatId: $chatId) {\n id\n messageId\n creationTime\n state\n ...ChatMessage_message\n ...chatHelpers_isBotMessage\n }\n}\n\nfragment ChatMessageDownvotedButton_message on Message {\n ...MessageFeedbackReasonModal_message\n ...MessageFeedbackOtherModal_message\n}\n\nfragment ChatMessageDropdownMenu_message on Message {\n id\n messageId\n vote\n text\n ...chatHelpers_isBotMessage\n}\n\nfragment ChatMessageFeedbackButtons_message on Message {\n id\n messageId\n vote\n voteReason\n ...ChatMessageDownvotedButton_message\n}\n\nfragment ChatMessageOverflowButton_message on Message {\n text\n ...ChatMessageDropdownMenu_message\n ...chatHelpers_isBotMessage\n}\n\nfragment ChatMessageSuggestedReplies_SuggestedReplyButton_message on Message {\n messageId\n}\n\nfragment ChatMessageSuggestedReplies_message on Message {\n suggestedReplies\n ...ChatMessageSuggestedReplies_SuggestedReplyButton_message\n}\n\nfragment ChatMessage_message on Message {\n id\n messageId\n text\n author\n linkifiedText\n state\n ...ChatMessageSuggestedReplies_message\n ...ChatMessageFeedbackButtons_message\n ...ChatMessageOverflowButton_message\n ...chatHelpers_isHumanMessage\n ...chatHelpers_isBotMessage\n ...chatHelpers_isChatBreak\n ...chatHelpers_useTimeoutLevel\n ...MarkdownLinkInner_message\n}\n\nfragment MarkdownLinkInner_message on Message {\n messageId\n}\n\nfragment MessageFeedbackOtherModal_message on Message {\n id\n messageId\n}\n\nfragment MessageFeedbackReasonModal_message on Message {\n id\n messageId\n}\n\nfragment chatHelpers_isBotMessage on Message {\n ...chatHelpers_isHumanMessage\n ...chatHelpers_isChatBreak\n}\n\nfragment chatHelpers_isChatBreak on Message {\n author\n}\n\nfragment chatHelpers_isHumanMessage on Message {\n author\n}\n\nfragment chatHelpers_useTimeoutLevel on Message {\n id\n state\n text\n messageId\n}\n' - }, - { - subscriptionName: 'viewerStateUpdated', - query: 'subscription subscriptions_viewerStateUpdated_Subscription {\n viewerStateUpdated {\n id\n ...ChatPageBotSwitcher_viewer\n }\n}\n\nfragment BotHeader_bot on Bot {\n displayName\n ...BotImage_bot\n}\n\nfragment BotImage_bot on Bot {\n profilePicture\n displayName\n}\n\nfragment BotLink_bot on Bot {\n displayName\n}\n\nfragment ChatPageBotSwitcher_viewer on Viewer {\n availableBots {\n id\n ...BotLink_bot\n ...BotHeader_bot\n }\n}\n' - } - ] - }, - query: 'mutation subscriptionsMutation(\n $subscriptions: [AutoSubscriptionQuery!]!\n) {\n autoSubscribe(subscriptions: $subscriptions) {\n viewer {\n id\n }\n }\n}\n' - } - - await this.makeRequest(query) - } - - async makeRequest (request) { - let payload = JSON.stringify(request) - let baseString = payload + this.headers['poe-formkey'] + 'WpuLMiXEKKE98j56k' - const md5 = crypto.createHash('md5').update(baseString).digest('hex') - const response = await fetch('https://poe.com/api/gql_POST', { - method: 'POST', - headers: Object.assign(this.headers, { - 'poe-tag-id': md5, - 'content-type': 'application/json' - }), - body: payload - }) - let text = await response.text() - try { - let result = JSON.parse(text) - console.log({ result }) - return result - } catch (e) { - console.error(text) - throw e - } - } - - async getBot (displayName) { - let r - let retry = 10 - while (retry >= 0) { - let url = `https://poe.com/_next/data/${this.nextData.buildId}/${displayName}.json` - let r = await fetch(url, { - headers: this.headers - }) - let res = await r.text() - try { - let chatData = (JSON.parse(res)).pageProps.payload.chatOfBotDisplayName - return chatData - } catch (e) { - r = res - retry-- - } - } - throw new Error(r) - } - - async getChatId () { - let r = await fetch('https://poe.com', { - headers: this.headers - }) - let text = await r.text() - const jsonRegex = /