-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
80 lines (72 loc) · 2.28 KB
/
Copy pathinit.js
File metadata and controls
80 lines (72 loc) · 2.28 KB
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
let text = require("text");
let command = require("command");
let toggle = require("toggle");
let translate = module.require("./");
toggle.register({
name: "Translater",
clientModifyReceiveGameMessageEvent(msg) {
let content = msg.getString().replaceAll(/§./g, "");
if (content.trim().length == 0) return;
let words = content.split(" ");
let isPlayer = /<.*>|.*:/.test(words[0]);
if (isPlayer) content = words.slice(1).join(" ");
return text.createText([
msg,
" ",
{
content: "[T]",
color: isPlayer ? "#cba6f7" : "#6c7086",
hover: `Translate "${content}"`,
click: `/translate auto ${content}`,
},
]);
},
});
function autoTranslate(content) {
let options = getOptions();
console.print("\u00A78Translating...");
fetch(`https://${options.instance}/translate`, {
method: "POST",
body: JSON.stringify({
q: content,
source: options.source,
target: options.target,
format: "text",
alternatives: 1,
api_key: "",
}),
headers: { "Content-Type": "application/json" },
})
.then((res) => {
let json = res.json();
if (json.error) {
console.error(`Could not translate message: ${json.error}`);
return;
}
console.print(`\u00A77Translated: ${json.translatedText}`);
})
.catch((e) => console.error(`Could not translate message: ${e}`));
}
command.register({
name: "translate",
subcommands: {
auto: {
args: {
content: {
type: "greedy",
execute: (content) => {
translate(content)
.then((msg) =>
console.print(`\u00A77Translated: ${msg}`),
)
.catch((e) =>
console.error(
`Could not translate message: ${e}`,
),
);
},
},
},
},
},
});