diff --git a/Plugins/Translator/Translator.plugin.js b/Plugins/Translator/Translator.plugin.js index 75a8799556..ea870538ca 100644 --- a/Plugins/Translator/Translator.plugin.js +++ b/Plugins/Translator/Translator.plugin.js @@ -2,7 +2,7 @@ * @name Translator * @author DevilBro * @authorId 278543574059057154 - * @version 2.4.1 + * @version 2.4.2 * @description Allows you to translate Messages and your outgoing Messages within Discord * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -14,11 +14,7 @@ module.exports = (_ => { const changeLog = { - "added": { - "Translated Labels": "Translated the Config Popout to all Discord Languages", - "Server Specific Translation": "Same as the Channel Specific Translations just for Servers", - "Remember Enable State": "Saves the enable State for Translation States" - } + }; return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class { @@ -390,19 +386,19 @@ module.exports = (_ => { }; for (let m in messageTypes) this.defaults.choices[messageTypes[m]] = {value: Object.keys(languageTypes).reduce((newObj, l) => (newObj[languageTypes[l]] = defaultLanguages[l], newObj), {})}; - this.patchedModules = { - before: { - ChannelTextAreaForm: "render", - ChannelEditorContainer: "render", - Embed: "render" - }, - after: { - ChannelTextAreaButtons: "type", - Messages: "type", - MessageReply: "default", - MessageContent: "type", - Embed: "render" - } + this.modulePatches = { + before: [ + "ChannelTextAreaContainer", + "ChannelTextAreaEditor", + "Embed", + "MessageReply", + "Messages" + ], + after: [ + "ChannelTextAreaButtons", + "Embed", + "MessageContent" + ] }; this.css = ` @@ -654,8 +650,9 @@ module.exports = (_ => { } } - processChannelTextAreaForm (e) { - BDFDB.PatchUtils.patch(this, e.instance, "handleSendMessage", {instead: e2 => { + processChannelTextAreaContainer (e) { + if (e.instance.props.type != BDFDB.DiscordConstants.ChannelTextAreaTypes.NORMAL && e.instance.props.type != BDFDB.DiscordConstants.ChannelTextAreaTypes.NORMAL_WITH_ACTIVITY) return; + BDFDB.PatchUtils.patch(this, e.instance.props, "onSubmit", {instead: e2 => { if (this.isTranslationEnabled(e.instance.props.channel.id) && e2.methodArguments[0].value) { e2.stopOriginalMethodCall(); this.translateText(e2.methodArguments[0].value, messageTypes.SENT, (translation, input, output) => { @@ -671,7 +668,7 @@ module.exports = (_ => { }}, {force: true, noCache: true}); } - processChannelEditorContainer (e) { + processChannelTextAreaEditor (e) { if (this.isTranslationEnabled(e.instance.props.channel.id) && isTranslating) e.instance.props.disabled = true; } @@ -685,11 +682,11 @@ module.exports = (_ => { } processMessages (e) { - e.returnvalue.props.children.props.channelStream = [].concat(e.returnvalue.props.children.props.channelStream); - for (let i in e.returnvalue.props.children.props.channelStream) { - let message = e.returnvalue.props.children.props.channelStream[i].content; + e.instance.props.channelStream = [].concat(e.instance.props.channelStream); + for (let i in e.instance.props.channelStream) { + let message = e.instance.props.channelStream[i].content; if (message) { - if (BDFDB.ArrayUtils.is(message.attachments)) this.checkMessage(e.returnvalue.props.children.props.channelStream[i], message); + if (BDFDB.ArrayUtils.is(message.attachments)) this.checkMessage(e.instance.props.channelStream[i], message); else if (BDFDB.ArrayUtils.is(message)) for (let j in message) { let childMessage = message[j].content; if (childMessage && BDFDB.ArrayUtils.is(childMessage.attachments)) this.checkMessage(message[j], childMessage); @@ -708,61 +705,55 @@ module.exports = (_ => { } processMessageReply (e) { - if (e.returnvalue && e.returnvalue.props && e.returnvalue.props.children) { - let referencedMessage = BDFDB.ObjectUtils.get(e, "returnvalue.props.children.props.referencedMessage.message"); - if (referencedMessage && translatedMessages[referencedMessage.id]) { - e.returnvalue.props.children.props.referencedMessage = Object.assign({}, e.returnvalue.props.children.props.referencedMessage); - e.returnvalue.props.children.props.referencedMessage.message = new BDFDB.DiscordObjects.Message(e.returnvalue.props.children.props.referencedMessage.message); - e.returnvalue.props.children.props.referencedMessage.message.content = translatedMessages[referencedMessage.id].content; - } - } + if (!e.instance.props.referencedMessage || !translatedMessages[e.instance.props.referencedMessage.message.id]) return; + e.instance.props.referencedMessage = Object.assign({}, e.instance.props.referencedMessage); + e.instance.props.referencedMessage.message = new BDFDB.DiscordObjects.Message(e.instance.props.referencedMessage.message); + e.instance.props.referencedMessage.message.content = translatedMessages[e.instance.props.referencedMessage.message.id].content; } processMessageContent (e) { - if (e.instance.props.message) { - let translation = translatedMessages[e.instance.props.message.id]; - if (translation && translation.content) e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { - text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.LibraryStrings.to} ${BDFDB.LanguageUtils.getName(translation.output)}`, - tooltipConfig: {style: "max-width: 400px"}, + if (!e.instance.props.message) return; + let translation = translatedMessages[e.instance.props.message.id]; + if (translation && translation.content) e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.LibraryStrings.to} ${BDFDB.LanguageUtils.getName(translation.output)}`, + tooltipConfig: {style: "max-width: 400px"}, + children: BDFDB.ReactUtils.createElement("span", { + className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated), children: BDFDB.ReactUtils.createElement("span", { - className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated), - children: BDFDB.ReactUtils.createElement("span", { - className: BDFDB.disCN.messageedited, - children: `(${this.labels.translated_watermark})` - }) + className: BDFDB.disCN.messageedited, + children: `(${this.labels.translated_watermark})` }) - })); - } + }) + })); } processEmbed (e) { - if (e.instance.props.embed && e.instance.props.embed.message_id) { - let translation = translatedMessages[e.instance.props.embed.message_id]; - if (translation && Object.keys(translation.embeds).length) { - if (!e.returnvalue) e.instance.props.embed = Object.assign({}, e.instance.props.embed, { - rawDescription: translation.embeds[e.instance.props.embed.id], - originalDescription: e.instance.props.embed.originalDescription || e.instance.props.embed.rawDescription - }); - else { - let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["className", BDFDB.disCN.embeddescription]]}); - if (index > -1) children[index].props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { - text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.getName(translation.output)}`, - tooltipConfig: {style: "max-width: 400px"}, + if (!e.instance.props.embed || !e.instance.props.embed.message_id) return; + let translation = translatedMessages[e.instance.props.embed.message_id]; + if (translation && Object.keys(translation.embeds).length) { + if (!e.returnvalue) e.instance.props.embed = Object.assign({}, e.instance.props.embed, { + rawDescription: translation.embeds[e.instance.props.embed.id], + originalDescription: e.instance.props.embed.originalDescription || e.instance.props.embed.rawDescription + }); + else { + let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["className", BDFDB.disCN.embeddescription]]}); + if (index > -1) children[index].props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { + text: `${BDFDB.LanguageUtils.getName(translation.input)} ➝ ${BDFDB.LanguageUtils.getName(translation.output)}`, + tooltipConfig: {style: "max-width: 400px"}, + children: BDFDB.ReactUtils.createElement("span", { + className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated), children: BDFDB.ReactUtils.createElement("span", { - className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.messagetimestamp, BDFDB.disCN.messagetimestampinline, BDFDB.disCN._translatortranslated), - children: BDFDB.ReactUtils.createElement("span", { - className: BDFDB.disCN.messageedited, - children: `(${this.labels.translated_watermark})` - }) + className: BDFDB.disCN.messageedited, + children: `(${this.labels.translated_watermark})` }) - })); - } - } - else if (!e.returnvalue && e.instance.props.embed.originalDescription) { - e.instance.props.embed = Object.assign({}, e.instance.props.embed, {rawDescription: e.instance.props.embed.originalDescription}); - delete e.instance.props.embed.originalDescription; + }) + })); } } + else if (!e.returnvalue && e.instance.props.embed.originalDescription) { + e.instance.props.embed = Object.assign({}, e.instance.props.embed, {rawDescription: e.instance.props.embed.originalDescription}); + delete e.instance.props.embed.originalDescription; + } } toggleTranslation (channelId) {