switched from st to lingva

This commit is contained in:
Joonas 2023-02-11 21:13:41 +02:00
parent 08d93cb867
commit 5a2dce2773
1 changed files with 8 additions and 6 deletions

View File

@ -7,20 +7,22 @@ const command = {
if (!splitted[2] || !splitted[3]) { if (!splitted[2] || !splitted[3]) {
await client.say( await client.say(
msg.channelName, msg.channelName,
`${msg.displayName}, needed <country code> <text to be translated>` `${msg.displayName}, needed <source country code> <target country code> <text to be translated>`
); );
return; return;
} }
const data = await fetch( const data = await fetch(
`https://simplytranslate.pussthecat.org/api/translate/?engine=google&to=${encodeURIComponent( `https://lingva.ml/api/v1/${encodeURIComponent(
splitted[2] splitted[2]
)}&text=${encodeURIComponent(splitted.slice(3).join(" "))}` )}/${encodeURIComponent(splitted[3])}/${encodeURIComponent(
splitted.slice(4).join(" ")
)}`
) )
.then((res) => res.json()) .then((res) => res.json())
.catch((err) => console.error("Error with translating: " + err.message)); .catch((err) => console.error("Error with translating: " + err.message));
if (!data) { if ("error" in data) {
await client.say( await client.say(
msg.channelName, msg.channelName,
`${msg.displayName}, invalid country code or text` `${msg.displayName}, invalid country code or text`
@ -32,8 +34,8 @@ const command = {
await client.say( await client.say(
msg.channelName, msg.channelName,
`${msg.displayName}, Translation of ${splitted `${msg.displayName}, Translation of ${splitted
.slice(3) .slice(4)
.join(" ")} to lang ${splitted[2]}: '${data["translated-text"]}'` .join(" ")} to lang ${splitted[3]}: '${data.translation}'`
); );
}, },
}; };