This commit is contained in:
zyc404 2024-01-04 10:28:55 +08:00
commit 9229be62cb
9 changed files with 998 additions and 1009 deletions

File diff suppressed because it is too large Load diff

View file

@ -171,17 +171,17 @@ export class ChatgptManagement extends plugin {
fnc: 'versionChatGPTPlugin'
},
{
reg: '^#chatgpt(本群)?(群\\d+)?(关闭|闭嘴|关机|休眠|下班)',
reg: '^#chatgpt(本群)?(群\\d+)?(闭嘴|关机|休眠|下班)',
fnc: 'shutUp',
permission: 'master'
},
{
reg: '^#chatgpt(本群)?(群\\d+)?(开启|启动|激活|张嘴|开口|说话|上班)$',
reg: '^#chatgpt(本群)?(群\\d+)?(张嘴|开口|说话|上班)$',
fnc: 'openMouth',
permission: 'master'
},
{
reg: '^#chatgpt查看?(关闭|闭嘴|关机|休眠|下班|休眠)列表$',
reg: '^#chatgpt查看?(闭嘴|关机|休眠|下班)列表$',
fnc: 'listShutUp',
permission: 'master'
},
@ -327,8 +327,8 @@ export class ChatgptManagement extends plugin {
permission: 'master'
},
{
reg: '^#chatgpt修补Gemini$',
fnc: 'patchGemini',
reg: '^#chatgpt必应(禁用|禁止|关闭|启用|开启)搜索$',
fnc: 'switchBingSearch',
permission: 'master'
}
]
@ -1672,6 +1672,16 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return false
}
async switchBingSearch (e) {
if (e.msg.includes('启用') || e.msg.includes('开启')) {
Config.sydneyEnableSearch = true
await e.reply('已开启必应搜索')
} else {
Config.sydneyEnableSearch = false
await e.reply('已禁用必应搜索')
}
}
async saveXinghuoModel (e) {
if (!this.e.msg) return
let token = this.e.msg

View file

@ -374,6 +374,12 @@ export function supportGuoba () {
]
}
},
{
field: 'sydneyEnableSearch',
label: '是否允许必应进行搜索',
bottomHelpMessage: '关闭后必应将禁用搜索',
component: 'Switch'
},
{
field: 'enableSuggestedResponses',
label: '是否开启建议回复',

View file

@ -11,7 +11,6 @@
"@google/generative-ai": "^0.1.1",
"@slack/bolt": "^3.13.2",
"asn1.js": "^5.0.0",
"delay": "^6.0.0",
"diff": "^5.1.0",
"emoji-strip": "^1.0.1",
"eventsource": "^2.0.2",

View file

@ -8,10 +8,9 @@ import crypto from 'crypto'
import WebSocket from 'ws'
import { Config, pureSydneyInstruction } from './config.js'
import { formatDate, getMasterQQ, isCN, getUserData, limitString } from './common.js'
import delay from 'delay'
import moment from 'moment'
import { getProxy } from './proxy.js'
import Version from './version.js'
import common from '../../../lib/common/common.js'
if (!globalThis.fetch) {
globalThis.fetch = fetch
@ -87,9 +86,12 @@ export default class SydneyAIClient {
// 'x-forwarded-for': '1.1.1.1'
}
}
if (this.opts.cookies || this.opts.userToken) {
let initCk = 'SRCHD=AF=NOFORM; PPLState=1; SRCHHPGUSR=HV=' + new Date().getTime() + ';'
if (this.opts.userToken) {
// 疑似无需token了
fetchOptions.headers.cookie = this.opts.cookies || `_U=${this.opts.userToken}`
fetchOptions.headers.cookie = `${initCk} _U=${this.opts.userToken}`
} else {
fetchOptions.headers.cookie = initCk
}
if (this.opts.proxy) {
fetchOptions.agent = proxy(Config.proxy)
@ -101,12 +103,12 @@ export default class SydneyAIClient {
this.opts.host = 'https://edgeservices.bing.com/edgesvc'
}
logger.mark('使用host' + this.opts.host)
let response = await fetch(`${this.opts.host}/turing/conversation/create?bundleVersion=1.1366.5`, fetchOptions)
let response = await fetch(`${this.opts.host}/turing/conversation/create?bundleVersion=1.1381.12`, fetchOptions)
let text = await response.text()
let retry = 10
while (retry >= 0 && response.status === 200 && !text) {
await delay(400)
response = await fetch(`${this.opts.host}/turing/conversation/create?bundleVersion=1.1366.5`, fetchOptions)
await common.sleep(400)
response = await fetch(`${this.opts.host}/turing/conversation/create?bundleVersion=1.1381.12`, fetchOptions)
text = await response.text()
retry--
}
@ -308,8 +310,7 @@ export default class SydneyAIClient {
const text = (pureSydney ? pureSydneyInstruction : (useCast?.bing || Config.sydney)).replaceAll(namePlaceholder, botName || defaultBotName) +
((Config.enableGroupContext && groupId) ? groupContextTip : '') +
((Config.enforceMaster && master) ? masterTip : '') +
(Config.sydneyMood ? moodTip : '') +
(Config.sydneySystemCode ? '' : '')
(Config.sydneyMood ? moodTip : '')
// logger.info(text)
if (pureSydney) {
previousMessages = invocationId === 0
@ -362,7 +363,7 @@ export default class SydneyAIClient {
// 'dagslnv1',
// 'sportsansgnd',
// 'dl_edge_desc',
'noknowimg',
// 'noknowimg',
// 'dtappid',
// 'cricinfo',
// 'cricinfov2',
@ -370,21 +371,21 @@ export default class SydneyAIClient {
// 'gencontentv3',
'iycapbing',
'iyxapbing',
'revimglnk',
'revimgsrc1',
'revimgur',
// 'revimglnk',
// 'revimgsrc1',
// 'revimgur',
'clgalileo',
'eredirecturl'
]
if (Config.enableGenerateContents) {
optionsSets.push(...['gencontentv3'])
}
if (!Config.sydneyEnableSearch || toSummaryFileContent?.content) {
optionsSets.push(...['nosearchall'])
}
let maxConv = Config.maxNumUserMessagesInConversation
const currentDate = moment().format('YYYY-MM-DDTHH:mm:ssZ')
const imageDate = await this.kblobImage(opts.imageUrl)
if (toSummaryFileContent?.content) {
// message = `请不要进行搜索,用户的问题是:"${message}"`
messageType = 'Chat'
}
let argument0 = {
source: 'cib',
optionsSets,
@ -392,17 +393,17 @@ export default class SydneyAIClient {
// 'InternalSearchQuery', 'InternalSearchResult', 'Disengaged', 'InternalLoaderMessage', 'Progress', 'RenderCardRequest', 'AdsQuery',
'InvokeAction', 'SemanticSerp', 'GenerateContentQuery', 'SearchQuery'],
sliceIds: [
'e2eperf',
'gbacf',
'srchqryfix',
'caccnctacf',
'translref',
'fluxnosearchc',
'fluxnosearch',
'1115rai289s0',
'1130deucs0',
'1116pythons0',
'cacmuidarb'
// 'e2eperf',
// 'gbacf',
// 'srchqryfix',
// 'caccnctacf',
// 'translref',
// 'fluxnosearchc',
// 'fluxnosearch',
// '1115rai289s0',
// '1130deucs0',
// '1116pythons0',
// 'cacmuidarb'
],
requestId: crypto.randomUUID(),
traceId: genRanHex(32),
@ -476,9 +477,9 @@ export default class SydneyAIClient {
conversationId,
previousMessages,
plugins: [
{
id: 'c310c353-b9f0-4d76-ab0d-1dd5e979cf68'
}
// {
// id: 'c310c353-b9f0-4d76-ab0d-1dd5e979cf68'
// }
]
}
if (encryptedconversationsignature) {
@ -799,6 +800,7 @@ export default class SydneyAIClient {
message,
conversationExpiryTime: event?.item?.conversationExpiryTime
})
break
}
default:
}

View file

@ -2,8 +2,8 @@ import lodash from 'lodash'
import { Config } from '../utils/config.js'
import StealthPlugin from 'puppeteer-extra-plugin-stealth'
import { getOpenAIAuth } from './openai-auth.js'
import delay from 'delay'
import { v4 as uuidv4 } from 'uuid'
import common from '../../../lib/common/common.js'
const chatUrl = 'https://chat.openai.com/chat'
let puppeteer = {}
@ -181,7 +181,7 @@ export class ChatGPTPuppeteer extends Puppeteer {
if (Config['2captchaToken']) {
await this._page.solveRecaptchas()
}
await delay(300)
await common.sleep(300)
timeout = timeout - 300
}
} catch (e) {
@ -243,7 +243,7 @@ export class ChatGPTPuppeteer extends Puppeteer {
break
}
await delay(300)
await common.sleep(300)
} while (true)
if (!await this.getIsAuthenticated()) {
@ -405,7 +405,7 @@ export class ChatGPTPuppeteer extends Puppeteer {
if (isAuthenticated) {
while (!this._accessToken) {
// wait for async response hook result
await delay(300)
await common.sleep(300)
timeout = timeout - 300
if (timeout < 0) {
const error = new Error('Not signed in')
@ -493,7 +493,7 @@ export class ChatGPTPuppeteer extends Puppeteer {
// const responseP = new Promise<string>(async (resolve, reject) => {
// try {
// do {
// await delay(1000)
// await common.sleep(1000)
// // TODO: this logic needs some work because we can have repeat messages...
// const newLastMessage = await this.getLastMessage()

View file

@ -42,6 +42,7 @@ const defaultConfig = {
sydneyImageRecognition: false,
sydneyMoodTip: 'Your response should be divided into two parts, namely, the text and your mood. The mood available to you can only include: blandness, happy, shy, frustrated, disgusted, and frightened.All content should be replied in this format {"text": "", "mood": ""}.All content except mood should be placed in text, It is important to ensure that the content you reply to can be parsed by json.',
enableSuggestedResponses: false,
sydneyEnableSearch: false,
api: defaultChatGPTAPI,
apiBaseUrl: 'https://chat3.avocado.wiki/backend-api',
apiForceUseReverse: false,

View file

@ -1,6 +1,6 @@
import { Config } from '../utils/config.js'
import delay from 'delay'
import random from 'random'
import common from '../../../lib/common/common.js'
let hasRecaptchaPlugin = !!Config['2captchaToken']
@ -58,7 +58,7 @@ export async function getOpenAIAuth (opt) {
await waitForConditionOrAtCapacity(page, () =>
page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs / 3 })
)
await delay(500)
await common.sleep(500)
// click login button and wait for navigation to finish
do {
@ -69,7 +69,7 @@ export async function getOpenAIAuth (opt) {
}),
page.click('#__next .btn-primary')
])
await delay(1000)
await common.sleep(1000)
} while (page.url().endsWith('/auth/login'))
logger.mark('进入登录页面')
await checkForChatGPTAtCapacity(page)
@ -90,7 +90,7 @@ export async function getOpenAIAuth (opt) {
} else {
await page.waitForSelector('#username')
await page.type('#username', email, { delay: 20 })
await delay(100)
await common.sleep(100)
if (hasRecaptchaPlugin) {
// console.log('solveRecaptchas()')
@ -114,7 +114,7 @@ export async function getOpenAIAuth (opt) {
submitP()
])
} else {
await delay(2000)
await common.sleep(2000)
await checkForChatGPTAtCapacity(page)
}
@ -183,7 +183,7 @@ async function checkForChatGPTAtCapacity (page, opts = {}) {
timeout: timeoutMs
})
await delay(pollingIntervalMs)
await common.sleep(pollingIntervalMs)
}
} catch (err) {
// ignore errors likely due to navigation
@ -251,29 +251,29 @@ async function solveSimpleCaptchas (page) {
const verifyYouAreHuman = await page.$('text=Verify you are human')
if (verifyYouAreHuman) {
logger.mark('encounter cloudflare simple captcha "Verify you are human"')
await delay(2000)
await common.sleep(2000)
await verifyYouAreHuman.click({
delay: random.int(5, 25)
})
await delay(1000)
await common.sleep(1000)
}
const verifyYouAreHumanCN = await page.$('text=确认您是真人')
if (verifyYouAreHumanCN) {
logger.mark('encounter cloudflare simple captcha "确认您是真人"')
await delay(2000)
await common.sleep(2000)
await verifyYouAreHumanCN.click({
delay: random.int(5, 25)
})
await delay(1000)
await common.sleep(1000)
}
const cloudflareButton = await page.$('.hcaptcha-box')
if (cloudflareButton) {
await delay(2000)
await common.sleep(2000)
await cloudflareButton.click({
delay: random.int(5, 25)
})
await delay(1000)
await common.sleep(1000)
}
} catch (err) {
// ignore errors

View file

@ -1,7 +1,7 @@
import { Config } from '../config.js'
import slack from '@slack/bolt'
import delay from 'delay'
import { limitString } from '../common.js'
import common from '../../../../lib/common/common.js'
let proxy
if (Config.proxy) {
try {
@ -24,7 +24,7 @@ export class SlackClaudeClient {
if (Config.proxy) {
option.agent = proxy(Config.proxy)
}
option.logLevel = Config.debug ? 'debug': 'info'
option.logLevel = Config.debug ? 'debug' : 'info'
this.app = new slack.App(option)
} else {
throw new Error('未配置Slack信息')
@ -61,7 +61,7 @@ export class SlackClaudeClient {
channel: channel.id,
users: Config.slackClaudeUserId
})
await delay(1000)
await common.sleep(1000)
} else {
channel = channel[0]
}
@ -78,7 +78,7 @@ export class SlackClaudeClient {
let response = '_Typing…_'
let tryTimes = 0
// 发完先等3喵
await delay(3000)
await common.sleep(3000)
while (response.trim().endsWith('_Typing…_')) {
let replies = await this.app.client.conversations.replies({
token: this.config.slackUserToken,
@ -106,7 +106,7 @@ export class SlackClaudeClient {
}
}
}
await delay(2000)
await common.sleep(2000)
tryTimes++
if (tryTimes > 3 && response === '_Typing…_') {
// 过了6秒还没任何回复就重新发一下试试
@ -127,7 +127,7 @@ export class SlackClaudeClient {
let response = '_Typing…_'
let tryTimes = 0
// 发完先等3喵
await delay(3000)
await common.sleep(3000)
while (response.trim().endsWith('_Typing…_')) {
let replies = await this.app.client.conversations.replies({
token: this.config.slackUserToken,
@ -156,7 +156,7 @@ export class SlackClaudeClient {
}
}
}
await delay(2000)
await common.sleep(2000)
tryTimes++
if (tryTimes > 3 && response === '_Typing…_') {
// 过了6秒还没任何回复就重新发一下试试