This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cmd_Tozhja.java
95 lines (85 loc) · 3.65 KB
/
Cmd_Tozhja.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.jaoafa.Javajaotan.Command;
import com.jaoafa.Javajaotan.CommandPremise;
import com.jaoafa.Javajaotan.Lib.Library;
import com.jaoafa.Javajaotan.Main;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Cmd_Tozhja implements CommandPremise {
@Override
public void onCommand(JDA jda, Guild guild, MessageChannel channel, Member member,
Message message, String[] args) {
List<String> froms = Arrays.stream(args).filter(
arg -> arg != null && arg.startsWith("from:")).collect(Collectors.toList());
String from = "auto";
if (froms.size() != 0) {
from = froms.get(0).substring("from:".length());
}
String to = "zh-CN";
List<String> texts = Arrays.stream(args).filter(
arg -> arg != null && !arg.startsWith("from:") && !arg.startsWith("to:")).collect(Collectors.toList());
if (texts.size() == 0) {
message.reply("引数が適切ではありません。").queue();
return;
}
if (froms.size() == 0) {
try {
from = Library.getLang(String.join(" ", texts)); // 日本語・英語・簡体字中国語・フランス語・ドイツ語・スペイン語・タイ語
if (from == null) {
from = Library.getRefineLang(String.join(" ", texts));
}
if (from == null) {
from = "auto";
}
if (from.equals("zh")) {
from = "auto";
}
} catch (IOException e) {
Main.ExceptionReporter(message, e);
from = "auto";
}
}
/*String res = Library.GoogleTranslateWeb(String.join(" ", texts), from, to);
String source = "GoogleTranslateWeb";*/
String res = null;
String source = null;
if (res == null) {
res = Library.GoogleTranslateGAS(String.join(" ", texts), from, to);
source = "GoogleTranslateGAS";
}
if (res == null) {
message.reply("翻訳に失敗しました。").queue();
return;
}
/*String res2 = Library.GoogleTranslateWeb(res, to, "ja");
String source2 = "GoogleTranslateWeb";*/
String res2 = null;
String source2 = null;
if (res2 == null) {
res2 = Library.GoogleTranslateGAS(res, to, "ja");
source2 = "GoogleTranslateGAS";
}
message.reply("```" + String.join(" ", texts) + "```↓```" + res + "```↓```"
+ res2 + "```(`" + from + "` -> `" + to + "` -> `ja` | SOURCE: `" + source + " | " + source2
+ "`)").queue();
}
@Override
public String getDescription() {
return "指定されたテキストを中国語(zh-CN)に翻訳したあと、さらに日本語(ja)に翻訳します。「from:<LANG>」を指定すると元言語を設定できます。指定しないと自動で判定します。\n"
+ "明示的にfrom:autoを指定すると、翻訳サービス側での言語判定がなされます。明示指定しないと、Javajaotan側で判定しその結果を元言語として判定します。";
}
@Override
public String getUsage() {
return "/tozhja <Text...> [from:LANG]";
}
@Override
public boolean isjMSOnly() {
return false;
}
}