Translate

- Allows someone to now do `.tr:<lang> <text>` to translate text from some language (auto-detected) to another language (specified as `<lang>`)
This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-18 13:07:53 +02:00
parent 85b6c65ccb
commit c00d83d070
1 changed files with 11 additions and 4 deletions

View File

@ -32,11 +32,18 @@ public final class Translate : Mod
{
import std.string : indexOf, strip, split;
// TODO: Implement custom language (to) support
string[] splits = split(strip(messageBody), " ");
long textIdx = indexOf(messageBody, " ");
// Check for `.tr:<lang>`
string toLang = "en";
long toLangIdx = splits[0].indexOf(":");
if(toLangIdx > -1)
{
toLang = splits[0].split(":")[1];
}
if(textIdx > -1)
{
@ -50,7 +57,7 @@ public final class Translate : Mod
try
{
string translatedText = translate(textToTranslate);
string translatedText = translate(textToTranslate, toLang);
getBot().channelMessage(translatedText, channel);
}
// On network error