feat: 开放咕咕翻译 & 🐞 fix: 修正部分文字性错误

This commit is contained in:
zhiyu1998 2023-03-24 18:20:55 +08:00
parent 45e5962489
commit 321b974ea4
3 changed files with 18 additions and 10 deletions

View File

@ -131,8 +131,6 @@ export class tools extends plugin {
"📝咕咕翻译:" + (await translateEngine.google(place, language[1]));
} catch (err) {
logger.error("咕咕翻译失败");
} finally {
translateResult = "";
}
// 腾讯交互式进行补充
translateResult += "\n\n🐧翻译" + (await translateEngine.tencent(place, language[1]));
@ -342,7 +340,6 @@ export class tools extends plugin {
};
// 格式化数据
const combineContent =
`标题:${title}\n` +
`点赞:${dataProcessing(like,)} | 硬币:${dataProcessing(coin)} | 收藏:${dataProcessing(favorite)} | 分享:${dataProcessing(share)}\n`+
`总播放量:${dataProcessing(view)} | 弹幕数量:${dataProcessing(danmaku)} | 评论:${dataProcessing(reply)}\n`+
`简介:${desc}`;

View File

@ -1,10 +1,21 @@
/**
* 用于翻译的常量控制
* 用于百度翻译的常量控制
*
* @type {{: string, : string, : string, : string}}
*/
export const transMap = { : "zh", : "jp", : "wyw", : "en", : "ru", : "kr" };
export const transMap2 = { : "zh", : "ja", : "ko", : "en", : "ru" };
/**
* 用于腾讯交互式翻译的常量控制
*
* @type {{: string, : string, : string, : string, : string}}
*/
export const tencentTransMap = { : "zh", : "ja", : "ko", : "en", : "ru" };
/**
* 用于腾讯交互式翻译的常量控制
*
* @type {{: string, : string, : string, : string, : string}}
*/
export const googleTransMap = { : "zh-CN", : "jp", : "ko", : "en", : "ru" };
/**
* 以下为抖音/TikTok类型代码
@ -38,4 +49,4 @@ export const HOT_SEARCH_ACTIONS = {
"哔哩哔哩": HOT_SEARCH_API + "bilihot",
"头条": HOT_SEARCH_API + "toutiaohot",
"头条新闻": HOT_SEARCH_API + "toutiaohotnew"
}
}

View File

@ -1,4 +1,4 @@
import {transMap, transMap2} from "./constant.js";
import {transMap, tencentTransMap, googleTransMap} from "./constant.js";
import md5 from "md5";
import fetch from "node-fetch";
import HttpProxyAgent from "https-proxy-agent";
@ -52,7 +52,7 @@ export default class Translate {
* @returns {Promise<string>}
*/
async google(query, targetLanguage) {
const url = `https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&sl=auto&tl=${transMap2[targetLanguage]}&q=${query}`;
const url = `https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&sl=auto&tl=${googleTransMap[targetLanguage]}&q=${query}`;
return fetch(url, {
method: "GET",
headers: {
@ -119,7 +119,7 @@ export default class Translate {
]
},
"target": {
"lang": transMap2[targetLanguage]
"lang": tencentTransMap[targetLanguage]
}
})
}).then(async resp => {
@ -130,4 +130,4 @@ export default class Translate {
return data.auto_translation?.[1];
})
}
}
}