fix: bing绘图(beta)

This commit is contained in:
ikechan8370 2023-04-01 21:58:04 +08:00
parent da5adc0d10
commit 98943bee9a
2 changed files with 150 additions and 0 deletions

View file

@ -3,6 +3,7 @@ import { createImage, editImage, imageVariation } from '../utils/dalle.js'
import { makeForwardMsg } from '../utils/common.js'
import _ from 'lodash'
import { Config } from '../utils/config.js'
import BingDrawClient from '../utils/BingDraw.js'
export class dalle extends plugin {
constructor (e) {
@ -27,6 +28,10 @@ export class dalle extends plugin {
{
reg: '^#(chatgpt|dalle)编辑图片',
fnc: 'edit'
},
{
reg: '^#bing(画图|绘图)',
fnc: 'bingDraw'
}
]
})
@ -222,4 +227,28 @@ export class dalle extends plugin {
await redis.del(`CHATGPT:EDIT:${e.sender.user_id}`)
}
}
async bingDraw (e) {
let prompt = e.msg.replace(/^#bing(画图|绘图)/, '')
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
if (!bingToken) {
throw new Error('未绑定Bing Cookie请使用#chatgpt设置必应token命令绑定Bing Cookie')
}
const bingTokens = bingToken.split('|')
// 负载均衡
if (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') {
// sydney下不需要保证同一token
const select = Math.floor(Math.random() * bingTokens.length)
bingToken = bingTokens[select]
}
let client = new BingDrawClient({
baseUrl: 'https://bing.ikechan8370.com',
userToken: bingToken
})
try {
await client.getImages(prompt, e)
} catch (e) {
await e.reply('绘图失败:' + e)
}
}
}