diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-10-01 11:19:30 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-10-01 11:19:30 +0200 |
commit | 4693214cc65b2565976e1233b2f58152126d2e52 (patch) | |
tree | f194fb490c725f1160c05e2f4040356303c5eb5d /src/main/java/at | |
parent | 9202db955f10e38cf037d209c133468aa6d3b2e7 (diff) | |
download | skyhanni-4693214cc65b2565976e1233b2f58152126d2e52.tar.gz skyhanni-4693214cc65b2565976e1233b2f58152126d2e52.tar.bz2 skyhanni-4693214cc65b2565976e1233b2f58152126d2e52.zip |
Disabled the Translator
Diffstat (limited to 'src/main/java/at')
4 files changed, 195 insertions, 198 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 294a3b8cc..979b0fe3e 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -52,7 +52,6 @@ import at.hannibal2.skyhanni.features.chat.ArachneChatMessageHider import at.hannibal2.skyhanni.features.chat.ChatFilter import at.hannibal2.skyhanni.features.chat.CompactBestiaryChatMessage import at.hannibal2.skyhanni.features.chat.PlayerDeathMessages -import at.hannibal2.skyhanni.features.chat.Translator import at.hannibal2.skyhanni.features.chat.WatchdogHider import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatModifier @@ -563,7 +562,7 @@ class SkyHanniMod { loadModule(WatchdogHider()) loadModule(AccountUpgradeReminder()) loadModule(PetExpTooltip()) - loadModule(Translator()) +// loadModule(Translator()) loadModule(GardenPlotBorders()) loadModule(CosmeticFollowingLine()) loadModule(SuperpairsClicksAlert()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 30164d8b1..e633f0c29 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -8,7 +8,6 @@ import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper -import at.hannibal2.skyhanni.features.chat.Translator import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import at.hannibal2.skyhanni.features.event.diana.InquisitorWaypointShare import at.hannibal2.skyhanni.features.fame.AccountUpgradeReminder @@ -156,13 +155,13 @@ object Commands { "shfarmingprofile", "Look up the farming profile from yourself or another player on elitebot.dev" ) { FarmingWeightDisplay.lookUpCommand(it) } - registerCommand( - "shcopytranslation", - "<language code (2 letters)> <messsage to translate>\n" + - "Requires the Chat > Translator feature to be enabled.\n" + - "Copies the translation for a given message to your clipboard. " + - "Language codes are at the end of the translation when you click on a message." - ) { Translator.fromEnglish(it) } +// registerCommand( +// "shcopytranslation", +// "<language code (2 letters)> <messsage to translate>\n" + +// "Requires the Chat > Translator feature to be enabled.\n" + +// "Copies the translation for a given message to your clipboard. " + +// "Language codes are at the end of the translation when you click on a message." +// ) { Translator.fromEnglish(it) } } private fun usersBugFix() { @@ -270,10 +269,10 @@ object Commands { registerCommand("shstopcityprojectreminder", "") { CityProjectFeatures.disable() } registerCommand("shsendcontests", "") { GardenNextJacobContest.shareContestConfirmed(it) } registerCommand("shstopaccountupgradereminder", "") { AccountUpgradeReminder.disable() } - registerCommand( - "shsendtranslation", - "Respond with a translation of the message that the user clicks" - ) { Translator.toEnglish(it) } +// registerCommand( +// "shsendtranslation", +// "Respond with a translation of the message that the user clicks" +// ) { Translator.toEnglish(it) } } private fun commandHelp(args: Array<String>) { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java index b855eabd4..e23246580 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/ChatConfig.java @@ -175,14 +175,14 @@ public class ChatConfig { @FeatureToggle public boolean hideSacksChange = false; - @Expose - @ConfigOption( - name = "Translator", - desc = "Click on a message to translate it into English. " + - "Use §e/shcopytranslation§7 to get the translation from English. " + - "§cTranslation is not guaranteed to be 100% accurate." - ) - @ConfigEditorBoolean - @FeatureToggle - public boolean translator = false; +// @Expose +// @ConfigOption( +// name = "Translator", +// desc = "Click on a message to translate it into English. " + +// "Use §e/shcopytranslation§7 to get the translation from English. " + +// "§cTranslation is not guaranteed to be 100% accurate." +// ) +// @ConfigEditorBoolean +// @FeatureToggle +// public boolean translator = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt index 6d238b8b3..8974a0cbc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt @@ -1,174 +1,173 @@ -package at.hannibal2.skyhanni.features.chat - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.SkyHanniMod.Companion.coroutineScope -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.utils.APIUtil -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.transformIf -import at.hannibal2.skyhanni.utils.OSUtils -import at.hannibal2.skyhanni.utils.StringUtils.getPlayerName -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import com.google.gson.JsonArray -import kotlinx.coroutines.launch -import net.minecraft.event.ClickEvent -import net.minecraft.event.HoverEvent -import net.minecraft.util.ChatComponentText -import net.minecraft.util.ChatStyle -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.net.URLDecoder -import java.net.URLEncoder - -class Translator { - private val messageContentRegex = Regex(".*: (.*)") - - // Logic for listening for a user click on a chat message is from NotEnoughUpdates - - @SubscribeEvent(priority = EventPriority.LOWEST) - fun onGuiChat(event: LorenzChatEvent) { - if (!isEnabled()) return - - val message = event.message - if (message.getPlayerName() == "-") return - - val editedComponent = event.chatComponent.transformIf({ siblings.isNotEmpty() }) { siblings.last() } - - val clickStyle = createClickStyle(message.removeColor(), editedComponent.chatStyle) - editedComponent.setChatStyle(clickStyle) - } - - private fun createClickStyle(message: String, style: ChatStyle): ChatStyle { - style.setChatClickEvent( - ClickEvent( - ClickEvent.Action.RUN_COMMAND, - "/shsendtranslation ${messageContentRegex.find(message.removeColor())!!.groupValues[1]}" - ) - ) - style.setChatHoverEvent( - HoverEvent( - HoverEvent.Action.SHOW_TEXT, - ChatComponentText("§bClick to translate!") - ) - ) - return style - } - - - companion object { - private val config get() = SkyHanniMod.feature.chat - - /* - * Simplified version of the JSON response: - * [ - * [ - * [ - * 'translated sentence one with a space after the punctuation. ' - * 'original sentence one without a space after the punctuation.' - * ], - * [ - * 'translated sentence two without punctuation bc it's last' - * 'original sentence two without punctuation' - * ] - * ], - * null, - * '"target language as a two-letter code following ISO 639-1"', - * ] - */ - - private fun getJSONResponse(urlString: String) = - APIUtil.getJSONResponseAsElement(urlString, false, "Google Translate API") - - private fun getTranslationToEnglish(message: String): String { - val url = - "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=" + URLEncoder.encode( - message, - "UTF-8" - ) - - var messageToSend = "" - val layer1 = getJSONResponse(url).asJsonArray - if (layer1.size() <= 2) return "Error!" - - val language = layer1[2].toString() - if (language == "\"en\"") return "Unable to translate!" - if (language.length != 4) return "Error!" - - val layer2 = try { - layer1[0] as JsonArray - } catch (_: Exception) { - return "Error!" - } - - for (layer3 in layer2) { - val arrayLayer3 = layer3 as? JsonArray ?: continue - val sentence = arrayLayer3[0].toString() - val sentenceWithoutQuotes = sentence.substring(1, sentence.length - 1) - messageToSend = "$messageToSend$sentenceWithoutQuotes" - } - messageToSend = "$messageToSend §7(Language: $language)" - - return URLDecoder.decode(messageToSend, "UTF-8").replace("\\", "") - } - - private fun getTranslationFromEnglish(message: String, lang: String): String { - val url = - "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=$lang&dt=t&q=" + URLEncoder.encode( - message, - "UTF-8" - ) - - val layer1 = getJSONResponse(url).asJsonArray - if (layer1.size() < 1) return "Error!" - val layer2 = layer1[0] as? JsonArray - - val firstSentence = (layer2?.get(0) as? JsonArray)?.get(0).toString() - var messageToSend = firstSentence.substring(0, firstSentence.length - 1) - if (layer2 != null) { - for (sentenceIndex in 1..<layer2.size()) { - val sentence = (layer2.get(sentenceIndex) as JsonArray).get(0).toString() - val sentenceWithoutQuotes = sentence.substring(1, sentence.length - 1) - messageToSend = "$messageToSend$sentenceWithoutQuotes" - } - } // The first translated sentence only has 1 extra char at the end, but sentences after it need 1 at the front and 1 at the end removed in the substring - messageToSend = messageToSend.substring(1, messageToSend.length) - return URLDecoder.decode(messageToSend, "UTF-8").replace("\\", "") - } - - fun toEnglish(args: Array<String>) { - if (!isEnabled()) return - var message = "" - for (i in args) { - message = "$message$i " - } - - coroutineScope.launch { - val translation = getTranslationToEnglish(message) - if (translation == "Unable to translate!") LorenzUtils.chat("§c[SkyHanni] Unable to translate message :( (is it in English?)") - else LorenzUtils.chat("§e[SkyHanni] Found translation: §f$translation") - } - } - - fun fromEnglish(args: Array<String>) { - if (!isEnabled()) return - if (args.size < 2 || args[0].length != 2) { // args[0] is the language code - LorenzUtils.chat("§cUsage: /shcopytranslation <two letter language code (at the end of a translation)> <message>") - return - } - val language = args[0] - var message = "" - for (i in 1..<args.size) { - message = "$message${args[i]} " - } - - coroutineScope.launch { - val translation = getTranslationFromEnglish(message, language) - LorenzUtils.chat("§e[SkyHanni] Copied translation to clipboard: $translation") - OSUtils.copyToClipboard(translation) - } - } - - - fun isEnabled() = config.translator - } -}
\ No newline at end of file +//package at.hannibal2.skyhanni.features.chat +// +//import at.hannibal2.skyhanni.SkyHanniMod +//import at.hannibal2.skyhanni.SkyHanniMod.Companion.coroutineScope +//import at.hannibal2.skyhanni.events.LorenzChatEvent +//import at.hannibal2.skyhanni.utils.APIUtil +//import at.hannibal2.skyhanni.utils.LorenzUtils +//import at.hannibal2.skyhanni.utils.LorenzUtils.transformIf +//import at.hannibal2.skyhanni.utils.OSUtils +//import at.hannibal2.skyhanni.utils.StringUtils.getPlayerName +//import at.hannibal2.skyhanni.utils.StringUtils.removeColor +//import com.google.gson.JsonArray +//import kotlinx.coroutines.launch +//import net.minecraft.event.ClickEvent +//import net.minecraft.event.HoverEvent +//import net.minecraft.util.ChatComponentText +//import net.minecraft.util.ChatStyle +//import net.minecraftforge.fml.common.eventhandler.EventPriority +//import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +//import java.net.URLDecoder +//import java.net.URLEncoder +// +//class Translator { +// private val messageContentRegex = Regex(".*: (.*)") +// +// // Logic for listening for a user click on a chat message is from NotEnoughUpdates +// +// @SubscribeEvent(priority = EventPriority.LOWEST) +// fun onGuiChat(event: LorenzChatEvent) { +// if (!isEnabled()) return +// +// val message = event.message +// if (message.getPlayerName() == "-") return +// +// val editedComponent = event.chatComponent.transformIf({ siblings.isNotEmpty() }) { siblings.last() } +// +// val clickStyle = createClickStyle(message.removeColor(), editedComponent.chatStyle) +// editedComponent.setChatStyle(clickStyle) +// } +// +// private fun createClickStyle(message: String, style: ChatStyle): ChatStyle { +// style.setChatClickEvent( +// ClickEvent( +// ClickEvent.Action.RUN_COMMAND, +// "/shsendtranslation ${messageContentRegex.find(message.removeColor())!!.groupValues[1]}" +// ) +// ) +// style.setChatHoverEvent( +// HoverEvent( +// HoverEvent.Action.SHOW_TEXT, +// ChatComponentText("§bClick to translate!") +// ) +// ) +// return style +// } +// +// +// companion object { +// private val config get() = SkyHanniMod.feature.chat +// +// /* +// * Simplified version of the JSON response: +// * [ +// * [ +// * [ +// * 'translated sentence one with a space after the punctuation. ' +// * 'original sentence one without a space after the punctuation.' +// * ], +// * [ +// * 'translated sentence two without punctuation bc it's last' +// * 'original sentence two without punctuation' +// * ] +// * ], +// * null, +// * '"target language as a two-letter code following ISO 639-1"', +// * ] +// */ +// +// private fun getJSONResponse(urlString: String) = +// APIUtil.getJSONResponseAsElement(urlString, false, "Google Translate API") +// +// private fun getTranslationToEnglish(message: String): String { +// val url = +// "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=" + URLEncoder.encode( +// message, +// "UTF-8" +// ) +// +// var messageToSend = "" +// val layer1 = getJSONResponse(url).asJsonArray +// if (layer1.size() <= 2) return "Error!" +// +// val language = layer1[2].toString() +// if (language == "\"en\"") return "Unable to translate!" +// if (language.length != 4) return "Error!" +// +// val layer2 = try { +// layer1[0] as JsonArray +// } catch (_: Exception) { +// return "Error!" +// } +// +// for (layer3 in layer2) { +// val arrayLayer3 = layer3 as? JsonArray ?: continue +// val sentence = arrayLayer3[0].toString() +// val sentenceWithoutQuotes = sentence.substring(1, sentence.length - 1) +// messageToSend = "$messageToSend$sentenceWithoutQuotes" +// } +// messageToSend = "$messageToSend §7(Language: $language)" +// +// return URLDecoder.decode(messageToSend, "UTF-8").replace("\\", "") +// } +// +// private fun getTranslationFromEnglish(message: String, lang: String): String { +// val url = +// "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=$lang&dt=t&q=" + URLEncoder.encode( +// message, +// "UTF-8" +// ) +// +// val layer1 = getJSONResponse(url).asJsonArray +// if (layer1.size() < 1) return "Error!" +// val layer2 = layer1[0] as? JsonArray +// +// val firstSentence = (layer2?.get(0) as? JsonArray)?.get(0).toString() +// var messageToSend = firstSentence.substring(0, firstSentence.length - 1) +// if (layer2 != null) { +// for (sentenceIndex in 1..<layer2.size()) { +// val sentence = (layer2.get(sentenceIndex) as JsonArray).get(0).toString() +// val sentenceWithoutQuotes = sentence.substring(1, sentence.length - 1) +// messageToSend = "$messageToSend$sentenceWithoutQuotes" +// } +// } // The first translated sentence only has 1 extra char at the end, but sentences after it need 1 at the front and 1 at the end removed in the substring +// messageToSend = messageToSend.substring(1, messageToSend.length) +// return URLDecoder.decode(messageToSend, "UTF-8").replace("\\", "") +// } +// +// fun toEnglish(args: Array<String>) { +// if (!isEnabled()) return +// var message = "" +// for (i in args) { +// message = "$message$i " +// } +// +// coroutineScope.launch { +// val translation = getTranslationToEnglish(message) +// if (translation == "Unable to translate!") LorenzUtils.chat("§c[SkyHanni] Unable to translate message :( (is it in English?)") +// else LorenzUtils.chat("§e[SkyHanni] Found translation: §f$translation") +// } +// } +// +// fun fromEnglish(args: Array<String>) { +// if (!isEnabled()) return +// if (args.size < 2 || args[0].length != 2) { // args[0] is the language code +// LorenzUtils.chat("§cUsage: /shcopytranslation <two letter language code (at the end of a translation)> <message>") +// return +// } +// val language = args[0] +// var message = "" +// for (i in 1..<args.size) { +// message = "$message${args[i]} " +// } +// +// coroutineScope.launch { +// val translation = getTranslationFromEnglish(message, language) +// LorenzUtils.chat("§e[SkyHanni] Copied translation to clipboard: $translation") +// OSUtils.copyToClipboard(translation) +// } +// } +// +// fun isEnabled() = config.translator +// } +//}
\ No newline at end of file |