aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorObsidian <108832807+Obsidianninja11@users.noreply.github.com>2024-03-16 10:28:24 -0800
committerGitHub <noreply@github.com>2024-03-16 19:28:24 +0100
commit1241b26113c9ac57e77b1f083be318e11846fcb7 (patch)
tree8120a954a659fb153564359d82868b245e438185
parenta5452d3b27e1d09565cf2eac3b7bfaf374f8a251 (diff)
downloadskyhanni-1241b26113c9ac57e77b1f083be318e11846fcb7.tar.gz
skyhanni-1241b26113c9ac57e77b1f083be318e11846fcb7.tar.bz2
skyhanni-1241b26113c9ac57e77b1f083be318e11846fcb7.zip
Improvement: Allow translate commands w/o feature on (#1141)
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt28
3 files changed, 16 insertions, 30 deletions
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 3b1c02bb0..ee480c6f6 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -216,12 +216,14 @@ object Commands {
) { 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."
+ "Copy the English translation of a message in another language to the clipboard.\n" +
+ "Uses a 2 letter language code that can be found at the end of a translation message."
) { Translator.fromEnglish(it) }
registerCommand(
+ "shtranslate",
+ "Translate a message in another language to English."
+ ) { Translator.toEnglish(it) }
+ registerCommand(
"shmouselock",
"Lock/Unlock the mouse so it will no longer rotate the player (for farming)"
) { LockMouseLook.toggleLock() }
@@ -482,10 +484,6 @@ object Commands {
registerCommand("shsendcontests", "") { GardenNextJacobContest.shareContestConfirmed(it) }
registerCommand("shwords", "Opens the config list for modifying visual words") { openVisualWords() }
registerCommand("shstopaccountupgradereminder", "") { AccountUpgradeReminder.disable() }
- registerCommand(
- "shsendtranslation",
- "Respond with a translation of the message that the user clicks"
- ) { Translator.toEnglish(it) }
}
private fun shortenedCommands() {
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java
index 597096db0..b4ad57e75 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/ChatConfig.java
@@ -111,8 +111,8 @@ public class ChatConfig {
@Expose
@ConfigOption(
name = "Translator",
- desc = "Click on a message to translate it into English. " +
- "Use §e/shcopytranslation§7 to get the translation from English. " +
+ desc = "Click on a message to translate it to English. " +
+ "Use §e/shcopytranslation§7 to translate from English. " +
"§cTranslation is not guaranteed to be 100% accurate."
)
@ConfigEditorBoolean
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 01d893467..54e724dd9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt
@@ -43,7 +43,7 @@ class Translator {
style.setChatClickEvent(
ClickEvent(
ClickEvent.Action.RUN_COMMAND,
- "/shsendtranslation ${messageContentRegex.find(message)!!.groupValues[1]}"
+ "/shtranslate ${messageContentRegex.find(message)!!.groupValues[1]}"
)
)
style.setChatHoverEvent(
@@ -82,10 +82,8 @@ class Translator {
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"
- )
+ "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
@@ -114,10 +112,8 @@ class Translator {
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"
- )
+ "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!"
@@ -137,11 +133,7 @@ class Translator {
}
fun toEnglish(args: Array<String>) {
- if (!isEnabled()) return
- var message = ""
- for (i in args) {
- message = "$message$i "
- }
+ val message = args.joinToString(" ")
coroutineScope.launch {
val translation = getTranslationToEnglish(message)
@@ -151,20 +143,16 @@ class Translator {
}
fun fromEnglish(args: Array<String>) {
- if (!isEnabled()) return
if (args.size < 2 || args[0].length != 2) { // args[0] is the language code
ChatUtils.userError("Usage: /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]} "
- }
+ val message = args.drop(1).joinToString(" ")
coroutineScope.launch {
val translation = getTranslationFromEnglish(message, language)
- ChatUtils.chat("Copied translation to clipboard: $translation")
+ ChatUtils.chat("Copied translation to clipboard: §f$translation")
OSUtils.copyToClipboard(translation)
}
}