Skip to content

Commit

Permalink
添加bing第三方绘图 (#580)
Browse files Browse the repository at this point in the history
* fix: 修复星火api上下文

* 将无星火ck的情况降低为warn

* feat: 添加星火设定自定义代码功能

* 修复星火api模式的一些问题

* 修复导出配置问题

* feat:添加工具箱快捷登录接口

* 添加工具箱快捷登录指令

* 阻止群聊使用快捷登录

* 添加Azure配置支持,修复重复的配置项冲突

* 移除旧版本渲染和新版本帮助

* 添加工具箱

* 更新工具箱替换原有后台

* 更新工具箱适配代码

* 后台适配Trss

* 修复trss不支持sendPrivateMsg的问题

* 优化路由

* 修复路由

* 适配其他uin

* 添加bing第三方绘图

* 修复bing绘图第三方调用错误

* 添加bing第三方绘图采样配置

* 修复错误

* 添加bing第三方绘图图片大小配置

* 修复视图错误

* 使用ap替换第三方绘图

* 适配trss
  • Loading branch information
HalcyonAlcedo authored Oct 13, 2023
1 parent 0f310a8 commit ae58a20
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
50 changes: 29 additions & 21 deletions apps/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ export class chatgpt extends plugin {
await this.reply('本功能当前仅支持API3模式', true)
return false
}
if (ats.length === 0 || (ats.length === 1 && e.atme)) {
if (ats.length === 0 || (ats.length === 1 && (e.atme || e.atBot))) {
let conversationId = _.trimStart(e.msg, '#chatgpt删除对话').trim()
if (!conversationId) {
await this.reply('指令格式错误,请同时加上对话id或@某人以删除他当前进行的对话', true)
Expand Down Expand Up @@ -761,14 +761,14 @@ export class chatgpt extends plugin {
if (!e.raw_message || e.msg?.startsWith('#')) {
return false
}
if (e.isGroup && !e.atme) {
if (e.isGroup && !(e.atme || e.atBot)) {
return false
}
if (e.user_id == getUin(e)) return false
prompt = e.raw_message.trim()
if (e.isGroup && typeof this.e.group.getMemberMap === 'function') {
let mm = await this.e.group.getMemberMap()
let me = mm.get(getUin(e))
let me = mm.get(getUin(e)) || {}
let card = me.card
let nickname = me.nickname
if (nickname && card) {
Expand Down Expand Up @@ -797,7 +797,7 @@ export class chatgpt extends plugin {
}
} else {
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#chat')
}
Expand Down Expand Up @@ -1324,7 +1324,7 @@ export class chatgpt extends plugin {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#chat1')
}
Expand All @@ -1343,7 +1343,7 @@ export class chatgpt extends plugin {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#chat3')
}
Expand All @@ -1362,7 +1362,7 @@ export class chatgpt extends plugin {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#chatglm')
}
Expand All @@ -1381,7 +1381,7 @@ export class chatgpt extends plugin {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#bing')
}
Expand All @@ -1400,7 +1400,7 @@ export class chatgpt extends plugin {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#claude2')
}
Expand All @@ -1419,7 +1419,7 @@ export class chatgpt extends plugin {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#claude')
}
Expand All @@ -1438,7 +1438,7 @@ export class chatgpt extends plugin {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (!(e.atme || e.atBot) && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#xh')
}
Expand Down Expand Up @@ -1665,16 +1665,24 @@ export class chatgpt extends plugin {
if (Config.debug) {
logger.mark(`开始生成内容:${response.details.imageTag}`)
}
let client = new BingDrawClient({
baseUrl: Config.sydneyReverseProxy,
userToken: bingToken
})
await redis.set(`CHATGPT:DRAW:${e.sender.user_id}`, 'c', { EX: 30 })
try {
await client.getImages(response.details.imageTag, e)
} catch (err) {
await redis.del(`CHATGPT:DRAW:${e.sender.user_id}`)
await e.reply('绘图失败:' + err)
if (Config.bingAPDraw) {
// 调用第三方API进行绘图
let apDraw = new APTool()
apDraw.func({
prompt: response.details.imageTag
}, e)
} else {
let client = new BingDrawClient({
baseUrl: Config.sydneyReverseProxy,
userToken: bingToken
})
await redis.set(`CHATGPT:DRAW:${e.sender.user_id}`, 'c', { EX: 30 })
try {
await client.getImages(response.details.imageTag, e)
} catch (err) {
await redis.del(`CHATGPT:DRAW:${e.sender.user_id}`)
await e.reply('绘图失败:' + err)
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions resources/view/setting_view.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@
"label": "必应验证码pass服务",
"placeholder": "必应出验证码会自动用该服务绕过",
"data": "bingCaptchaOneShotUrl"
},
{
"type": "check",
"label": "第三方绘图",
"placeholder": "使用AP插件代替Bing进行绘图",
"data": "bingAPDraw"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const defaultConfig = {
maxNumUserMessagesInConversation: 20,
sydneyApologyIgnored: true,
enforceMaster: false,
bingAPDraw: false,
serverPort: 3321,
serverHost: '',
viewHost: '',
Expand Down

0 comments on commit ae58a20

Please sign in to comment.