mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
- do not translate non-rich embeds (fixes gifs, other issues)
- add placeholder for unknown languages in translate ops
This commit is contained in:
parent
3f550a4822
commit
d9c2db1510
3 changed files with 24 additions and 7 deletions
|
@ -6,7 +6,9 @@ const { acknowledge } = require('#utils/interactions');
|
||||||
const { icon, stringwrap } = require('#utils/markdown');
|
const { icon, stringwrap } = require('#utils/markdown');
|
||||||
const { editOrReply } = require('#utils/message');
|
const { editOrReply } = require('#utils/message');
|
||||||
|
|
||||||
const { ApplicationCommandTypes, InteractionCallbackTypes, InteractionContextTypes, ApplicationIntegrationTypes } = require("detritus-client/lib/constants");
|
const { ApplicationCommandTypes, InteractionCallbackTypes, InteractionContextTypes, ApplicationIntegrationTypes,
|
||||||
|
MessageEmbedTypes
|
||||||
|
} = require("detritus-client/lib/constants");
|
||||||
const { Components } = require('detritus-client/lib/utils');
|
const { Components } = require('detritus-client/lib/utils');
|
||||||
|
|
||||||
async function translateMessage(context, message, to, from){
|
async function translateMessage(context, message, to, from){
|
||||||
|
@ -19,12 +21,13 @@ async function translateMessage(context, message, to, from){
|
||||||
cnt.shift();
|
cnt.shift();
|
||||||
if(cnt.length >= 1){ mappings.content = cnt.join("\n") }
|
if(cnt.length >= 1){ mappings.content = cnt.join("\n") }
|
||||||
} else mappings.content = message.content
|
} else mappings.content = message.content
|
||||||
};
|
}
|
||||||
if(message.embeds) {
|
if(message.embeds) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
// Message Translation supports Descriptions and Fields
|
// Message Translation supports Descriptions and Fields
|
||||||
for(const e of message.embeds){
|
for(const e of message.embeds){
|
||||||
let emb = e[1]
|
let emb = e[1]
|
||||||
|
if(e[1].type !== MessageEmbedTypes.RICH) continue;
|
||||||
if(emb.description) mappings["embeds/" + i + "/description"] = emb.description;
|
if(emb.description) mappings["embeds/" + i + "/description"] = emb.description;
|
||||||
if(emb.title) mappings["embeds/" + i + "/title"] = emb.title;
|
if(emb.title) mappings["embeds/" + i + "/title"] = emb.title;
|
||||||
if(emb.author?.name) mappings["embeds/" + i + "/author/name"] = emb.author.name;
|
if(emb.author?.name) mappings["embeds/" + i + "/author/name"] = emb.author.name;
|
||||||
|
@ -43,7 +46,7 @@ async function translateMessage(context, message, to, from){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel if we don't have anything that can be translated
|
// Cancel if we don't have anything that can be translated
|
||||||
if(Object.keys(mappings).length == 0) return {};
|
if(Object.keys(mappings).length === 0) return {};
|
||||||
|
|
||||||
// Translate message via multitranslate endpoint on 1p
|
// Translate message via multitranslate endpoint on 1p
|
||||||
try{
|
try{
|
||||||
|
@ -63,6 +66,7 @@ async function translateMessage(context, message, to, from){
|
||||||
// Message Translation supports Descriptions and Fields
|
// Message Translation supports Descriptions and Fields
|
||||||
for(const e of message.embeds){
|
for(const e of message.embeds){
|
||||||
let emb = e[1]
|
let emb = e[1]
|
||||||
|
if(e[1].type !== MessageEmbedTypes.RICH) continue;
|
||||||
let newEmbed = {
|
let newEmbed = {
|
||||||
fields: []
|
fields: []
|
||||||
};
|
};
|
||||||
|
@ -151,7 +155,7 @@ module.exports = {
|
||||||
let toFlag = TRANSLATE_DISPLAY_MAPPINGS[translate.metadata.language.to] || ''
|
let toFlag = TRANSLATE_DISPLAY_MAPPINGS[translate.metadata.language.to] || ''
|
||||||
|
|
||||||
let newMessage = translate.message;
|
let newMessage = translate.message;
|
||||||
let newMessageContent = "";;
|
let newMessageContent = "";
|
||||||
if(newMessage.content) newMessageContent += "\n" + newMessage.content
|
if(newMessage.content) newMessageContent += "\n" + newMessage.content
|
||||||
|
|
||||||
return await ctx.editOrRespond({
|
return await ctx.editOrRespond({
|
||||||
|
@ -185,7 +189,7 @@ module.exports = {
|
||||||
let toFlag = TRANSLATE_DISPLAY_MAPPINGS[translate.metadata.language.to] || ''
|
let toFlag = TRANSLATE_DISPLAY_MAPPINGS[translate.metadata.language.to] || ''
|
||||||
|
|
||||||
let newMessage = translate.message;
|
let newMessage = translate.message;
|
||||||
let newMessageContent = "";;
|
let newMessageContent = "";
|
||||||
if(newMessage.content) newMessageContent += "\n" + newMessage.content
|
if(newMessage.content) newMessageContent += "\n" + newMessage.content
|
||||||
|
|
||||||
return editOrReply(context, createEmbed("default", context, {
|
return editOrReply(context, createEmbed("default", context, {
|
||||||
|
@ -194,7 +198,7 @@ module.exports = {
|
||||||
components
|
components
|
||||||
}))
|
}))
|
||||||
}catch(e){
|
}catch(e){
|
||||||
if(e.response?.body?.status && e.response.body.status == 2) return editOrReply(context, createEmbed("error", context, `Unable to translate text.`))
|
if(e.response?.body?.status && e.response.body.status === 2) return editOrReply(context, createEmbed("error", context, `Unable to translate text.`))
|
||||||
console.log(e)
|
console.log(e)
|
||||||
return editOrReply(context, createEmbed("error", context, `Something went wrong.`))
|
return editOrReply(context, createEmbed("error", context, `Something went wrong.`))
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ const { editOrReply } = require('#utils/message')
|
||||||
const { STATICS } = require('#utils/statics');
|
const { STATICS } = require('#utils/statics');
|
||||||
const { isSupported, getCodeFromAny } = require('#utils/translate');
|
const { isSupported, getCodeFromAny } = require('#utils/translate');
|
||||||
|
|
||||||
|
const {MessageEmbedTypes} = require("detritus-client/lib/constants");
|
||||||
|
|
||||||
// TODO(unity): interaction/context/translate.js
|
// TODO(unity): interaction/context/translate.js
|
||||||
async function translateMessage(context, message, to, from){
|
async function translateMessage(context, message, to, from){
|
||||||
let mappings = {};
|
let mappings = {};
|
||||||
|
@ -24,7 +26,9 @@ async function translateMessage(context, message, to, from){
|
||||||
let i = 0;
|
let i = 0;
|
||||||
// Message Translation supports Descriptions and Fields
|
// Message Translation supports Descriptions and Fields
|
||||||
for(const e of message.embeds){
|
for(const e of message.embeds){
|
||||||
let emb = e[1]
|
let emb = e[1];
|
||||||
|
if(e[1].type !== MessageEmbedTypes.RICH) continue;
|
||||||
|
|
||||||
if(emb.description) mappings["embeds/" + i + "/description"] = emb.description;
|
if(emb.description) mappings["embeds/" + i + "/description"] = emb.description;
|
||||||
if(emb.title) mappings["embeds/" + i + "/title"] = emb.title;
|
if(emb.title) mappings["embeds/" + i + "/title"] = emb.title;
|
||||||
if(emb.author?.name) mappings["embeds/" + i + "/author/name"] = emb.author.name;
|
if(emb.author?.name) mappings["embeds/" + i + "/author/name"] = emb.author.name;
|
||||||
|
@ -63,6 +67,8 @@ async function translateMessage(context, message, to, from){
|
||||||
// Message Translation supports Descriptions and Fields
|
// Message Translation supports Descriptions and Fields
|
||||||
for(const e of message.embeds){
|
for(const e of message.embeds){
|
||||||
let emb = e[1]
|
let emb = e[1]
|
||||||
|
|
||||||
|
if(e[1].type !== MessageEmbedTypes.RICH) continue;
|
||||||
let newEmbed = {
|
let newEmbed = {
|
||||||
fields: []
|
fields: []
|
||||||
};
|
};
|
||||||
|
|
|
@ -103,6 +103,8 @@ module.exports.ICONS_NEXTGEN = Object.freeze({
|
||||||
"button_full_coverage": "<:ico_full_coverage:1341535912017793045>",
|
"button_full_coverage": "<:ico_full_coverage:1341535912017793045>",
|
||||||
"button_wolfram_compute": "<:ico_wolfram_compute:1342276477269577758>",
|
"button_wolfram_compute": "<:ico_wolfram_compute:1342276477269577758>",
|
||||||
|
|
||||||
|
"gs_auto_awesome": "<:ico_gs_auto_awesome:1352186988416995380>",
|
||||||
|
|
||||||
/* Brands */
|
/* Brands */
|
||||||
"brand": "<:nextgen_ico_brand:1336064940670193780>",
|
"brand": "<:nextgen_ico_brand:1336064940670193780>",
|
||||||
"brand_discord": "<:nextgen_ico_brand_discord:1336064953727320256>",
|
"brand_discord": "<:nextgen_ico_brand_discord:1336064953727320256>",
|
||||||
|
@ -1076,6 +1078,8 @@ module.exports.TRANSLATE_LANGUAGE_ALIASES = Object.freeze({
|
||||||
// there are a lot of overlapping flags (specifically in eastern territories),
|
// there are a lot of overlapping flags (specifically in eastern territories),
|
||||||
// we have separata "display" and "resolve" mappings now.
|
// we have separata "display" and "resolve" mappings now.
|
||||||
module.exports.TRANSLATE_DISPLAY_MAPPINGS = Object.freeze({
|
module.exports.TRANSLATE_DISPLAY_MAPPINGS = Object.freeze({
|
||||||
|
"auto": this.ICONS_NEXTGEN.gs_auto_awesome,
|
||||||
|
"und": this.ICONS_NEXTGEN.gs_auto_awesome,
|
||||||
"af": "🇿🇦",
|
"af": "🇿🇦",
|
||||||
"sq": "🇦🇱",
|
"sq": "🇦🇱",
|
||||||
"am": "🇪🇹",
|
"am": "🇪🇹",
|
||||||
|
@ -1460,7 +1464,10 @@ module.exports.TRANSLATE_LANGUAGE_MAPPINGS = Object.freeze({
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports.TRANSLATE_LANGUAGES = Object.freeze({
|
module.exports.TRANSLATE_LANGUAGES = Object.freeze({
|
||||||
|
// 1p auto
|
||||||
"auto": "Automatic",
|
"auto": "Automatic",
|
||||||
|
// Translate API will respond with "und" if the language is unknown
|
||||||
|
"und": "Detected Language",
|
||||||
"ab": "Abkhaz",
|
"ab": "Abkhaz",
|
||||||
"ace": "Acehnese",
|
"ace": "Acehnese",
|
||||||
"ach": "Acholi",
|
"ach": "Acholi",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue