mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
移除axios依赖,替换百度翻译为有道翻译。指令表支持关键词筛选。 (#434)
* feat: add support for ‘greeting’ and ‘global reply mode’ commands, improve variable naming and remove unnecessary backend output. * feat: Add support for black and white lists, global reply mode and voice role settings, private chat switch, and active greeting configuration. Refactor some variable names and comment out redundant code for better readability and reduced backend output. * feat: 为新功能完善了帮助面板 * docs: 完善了‘打招呼’的帮助说明 * Commit Type: feat, bugfix Add functionality to view plugin command table, fix bug in blacklist/whitelist, and fix bug where chat mode can still be used in private messaging when disabled. * Commit Type: feat, bugfix Add functionality to view plugin command table, fix bug in blacklist/whitelist, and fix bug where chat mode can still be used in private messaging when disabled. * refactor: Remove redundant log output. * Refactor: optimize code logic * Fix: 修复绘图指令表被抢指令的bug。 * Refactor:1. Add support for automatically translating replies to Japanese and generating voice messages in VITS voice mode (please monitor remaining quota after enabling). 2. Add translation function. 3. Add emotion configuration for Azure voice mode, allowing the robot to select appropriate emotional styles for replies. * Refactor:Handle the issue of exceeding character setting limit caused by adding emotion configuration. * Fix: fix bugs * Refactor: Added error feedback to translation service * Refactor: Added support for viewing the list of supported roles for each language mode, and fixed some bugs in the emotion switching feature of the auzre mode. * Refactor: Optimized some command feedback and added owner restriction to chat record export function. * Refactor: Optimized feedback when viewing role list to avoid excessive messages. * Refactor: Optimized feedback when configuring multi-emotion mode. * Feature: Added help instructions for translation feature. * chore: Adjust help instructions for mood settings * Fix: Fixed issue where only first line of multi-line replies were being read and Azure voice was pronouncing punctuation marks. * Fix: Fixed bug where switching to Azure voice mode prompted for missing key and restricted ability to view voice role list to only when in voice mode. * Refactor: Add image OCR function and support translation for both quoted text and image. * fix: Fix issue with error caused by non-image input. * Refactor: Optimize code to filter emojis that cannot be displayed properly in claude mode. * Refactor: Optimize some code structures. * fix: Fix the bug of returning only one result when entering multiple lines of text on Windows system. * Refactor: Optimize code logic for better user experience * Refactor: Fix the conflict issue with other plugin translation commands * Refactor: Replace Baidu Translation with Youdao Translation to eliminate configuration steps; optimize translation experience; add missing dependency prompts instead of causing program errors.Optimize the experience of switching between voice mode and setting global reply mode. * Refactor: Remove unused files and dependencies in the project. * Feature: Add Youdao translation service to provide more comprehensive translation support. * Refactor: Optimize translation experience * Refactor: Optimize translation experience * Feature: Add functionality of keyword search command * Feature: Add functionality of keyword search command. * Refactor: Remove redundant code --------- Co-authored-by: Sean <1519059137@qq.com> Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
82b83bf015
commit
f20248a805
8 changed files with 363 additions and 260 deletions
80
apps/chat.js
80
apps/chat.js
|
|
@ -9,7 +9,9 @@ import SydneyAIClient from '../utils/SydneyAIClient.js'
|
|||
import { PoeClient } from '../utils/poe/index.js'
|
||||
import AzureTTS from '../utils/tts/microsoft-azure.js'
|
||||
import VoiceVoxTTS from '../utils/tts/voicevox.js'
|
||||
import { translate } from '../utils/translate.js'
|
||||
import fs from 'fs'
|
||||
import { getImg, getImageOcrText } from './entertainment.js'
|
||||
import {
|
||||
render, renderUrl,
|
||||
getMessageById,
|
||||
|
|
@ -33,10 +35,13 @@ import uploadRecord from '../utils/uploadRecord.js'
|
|||
import { SlackClaudeClient } from '../utils/slack/slackClient.js'
|
||||
import { ChatgptManagement } from './management.js'
|
||||
import { getPromptByName } from '../utils/prompts.js'
|
||||
import Translate from '../utils/baiduTranslate.js'
|
||||
import BingDrawClient from '../utils/BingDraw.js'
|
||||
import emojiStrip from 'emoji-strip'
|
||||
import XinghuoClient from "../utils/xinghuo/xinghuo.js";
|
||||
import XinghuoClient from '../utils/xinghuo/xinghuo.js'
|
||||
try {
|
||||
await import('emoji-strip')
|
||||
} catch (err) {
|
||||
logger.warn('【ChatGPT-Plugin】依赖emoji-strip未安装,会导致azure语音模式下朗读emoji的问题,建议执行pnpm install emoji-strip安装')
|
||||
}
|
||||
try {
|
||||
await import('keyv')
|
||||
} catch (err) {
|
||||
|
|
@ -801,40 +806,15 @@ export class chatgpt extends plugin {
|
|||
speaker = convertSpeaker(trySplit[0])
|
||||
prompt = trySplit[1]
|
||||
}
|
||||
if (Config.imgOcr) {
|
||||
// 取消息中的图片、at的头像、回复的图片,放入e.img
|
||||
if (e.at && !e.source) {
|
||||
e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`]
|
||||
}
|
||||
if (e.source) {
|
||||
let reply
|
||||
if (e.isGroup) {
|
||||
reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message
|
||||
} else {
|
||||
reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message
|
||||
const isImg = await getImg(e)
|
||||
if (Config.imgOcr && !!isImg) {
|
||||
let imgOcrText = await getImageOcrText(e)
|
||||
if (imgOcrText) {
|
||||
prompt = prompt + '"'
|
||||
for (let imgOcrTextKey in imgOcrText) {
|
||||
prompt += imgOcrText[imgOcrTextKey]
|
||||
}
|
||||
if (reply) {
|
||||
for (let val of reply) {
|
||||
if (val.type === 'image') {
|
||||
e.img = [val.url]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.img) {
|
||||
try {
|
||||
let imgOcrText = ''
|
||||
for (let i in e.img) {
|
||||
const imgorc = await Bot.imageOcr(e.img[i])
|
||||
// if (imgorc.language === 'zh' || imgorc.language === 'en') {
|
||||
for (let text of imgorc.wordslist) {
|
||||
imgOcrText += `${text.words} \n`
|
||||
}
|
||||
// }
|
||||
}
|
||||
prompt = imgOcrText + prompt
|
||||
} catch (err) { }
|
||||
prompt = prompt + ' "'
|
||||
}
|
||||
}
|
||||
// 检索是否有屏蔽词
|
||||
|
|
@ -1016,6 +996,8 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
let response = chatMessage?.text
|
||||
// 过滤无法正常显示的emoji
|
||||
if (use === 'claude') response = response.replace(/:[a-zA-Z_]+:/g, '')
|
||||
let mood = 'blandness'
|
||||
if (!response) {
|
||||
await e.reply('没有任何回复', true)
|
||||
|
|
@ -1141,7 +1123,14 @@ export class chatgpt extends plugin {
|
|||
ttsRegex = ''
|
||||
}
|
||||
ttsResponse = response.replace(ttsRegex, '')
|
||||
ttsResponse = emojiStrip(ttsResponse)
|
||||
// 处理azure语音会读出emoji的问题
|
||||
try {
|
||||
let emojiStrip
|
||||
emojiStrip = (await import('emoji-strip')).default
|
||||
ttsResponse = emojiStrip(ttsResponse)
|
||||
} catch (error) {
|
||||
await this.reply('依赖emoji-strip未安装,请执行pnpm install emoji-strip安装依赖', true)
|
||||
}
|
||||
// 处理多行回复有时候只会读第一行和azure语音会读出一些标点符号的问题
|
||||
ttsResponse = ttsResponse.replace(/[-:_;*;\n]/g, ',')
|
||||
// 先把文字回复发出去,避免过久等待合成语音
|
||||
|
|
@ -1158,17 +1147,9 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
let wav
|
||||
if (Config.ttsMode === 'vits-uma-genshin-honkai' && Config.ttsSpace && ttsResponse.length <= Config.ttsAutoFallbackThreshold) {
|
||||
if (Config.autoJapanese && (_.isEmpty(Config.baiduTranslateAppId) || _.isEmpty(Config.baiduTranslateSecret))) {
|
||||
await this.reply('请检查翻译配置是否正确。')
|
||||
return false
|
||||
}
|
||||
if (Config.ttsMode === 'vits-uma-genshin-honkai' && Config.ttsSpace) {
|
||||
if (Config.autoJapanese) {
|
||||
try {
|
||||
const translate = new Translate({
|
||||
appid: Config.baiduTranslateAppId,
|
||||
secret: Config.baiduTranslateSecret
|
||||
})
|
||||
ttsResponse = await translate(ttsResponse, '日')
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
|
|
@ -1182,6 +1163,11 @@ export class chatgpt extends plugin {
|
|||
await this.reply('合成语音发生错误~')
|
||||
}
|
||||
} else if (Config.ttsMode === 'azure' && Config.azureTTSKey) {
|
||||
const ttsRoleAzure = userReplySetting.ttsRoleAzure
|
||||
const isEn = AzureTTS.supportConfigurations.find(config => config.code === ttsRoleAzure)?.language.includes('en')
|
||||
if (isEn) {
|
||||
ttsResponse = (await translate(ttsResponse, '英')).replace('\n', '')
|
||||
}
|
||||
let ssml = AzureTTS.generateSsml(ttsResponse, {
|
||||
speaker,
|
||||
emotion,
|
||||
|
|
@ -1671,7 +1657,7 @@ export class chatgpt extends plugin {
|
|||
await e.reply('绘图失败:' + err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 如果token曾经有异常,则清除异常
|
||||
let Tokens = JSON.parse(await redis.get('CHATGPT:BING_TOKENS'))
|
||||
const TokenIndex = Tokens.findIndex(element => element.Token === abtrs.bingToken)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue