-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d8d129
commit a67d145
Showing
1 changed file
with
28 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,38 @@ | ||
// import translate from '@vitalets/google-translate-api' | ||
|
||
// let handler = async (m, { args, usedPrefix, command }) => { | ||
// let lang, text | ||
// if (args.length >= 2) { | ||
// lang = args[0] ? args[0] : 'id', text = args.slice(1).join(' ') | ||
// } else if (m.quoted && m.quoted.text) { | ||
// lang = args[0] ? args[0] : 'id', text = m.quoted.text | ||
// } else throw `Ex: ${usedPrefix + command} id hello i am robot` | ||
// let res = await translate(text, { to: lang, autoCorrect: true }).catch(_ => null) | ||
// if (!res) throw `Error : Bahasa"${lang}" Tidak Support` | ||
// m.reply(`*Terdeteksi Bahasa:* ${res.from.language.iso}\n*Ke Bahasa:* ${lang}\n\n*Terjemahan:* ${res.text}`.trim()) | ||
// } | ||
// handler.help = ['translate'].map(v => v + ' <bahasa> <teks>') | ||
// handler.tags = ['tools'] | ||
// handler.command = /^(tr(anslate)?)$/i | ||
import {translate} from '@vitalets/google-translate-api' | ||
const defaultLang = 'en' | ||
const tld = 'cn' | ||
|
||
// export default handler | ||
let handler = async (m, { args, usedPrefix, command }) => { | ||
let err = ` | ||
📌 *Example:* | ||
///////////////////// ATAS BUAT BACKUP AJA ////////////////////////// | ||
*${usedPrefix + command}* <id> [text] | ||
*${usedPrefix + command}* en Hello World | ||
// fix by Xnuvers007, penggunaan .tr dari|ke teksnya apa | ||
≡ *List of supported languages:* | ||
import fetch from 'node-fetch'; | ||
https://cloud.google.com/translate/docs/languages | ||
`.trim() | ||
|
||
let handler = async (m, { args, usedPrefix, command }) => { | ||
let lang, text; | ||
if (args.length >= 2) { | ||
lang = args[0]; | ||
text = args.slice(1).join(' '); | ||
} else { | ||
throw `Ex: ${usedPrefix + command} dariBahasa|keBahasa Apa kabar?`; | ||
} | ||
|
||
let [from_lang, to_lang] = lang.split('|'); | ||
let url = `https://tr.deployers.repl.co/translate?from=${from_lang}&to=${to_lang}&text=${encodeURIComponent(text)}`; | ||
let response = await fetch(url); | ||
let result = await response.json(); | ||
|
||
if (response.status !== 200) { | ||
url = `https://tr-xnuvers007.vercel.app/translate?from=${from_lang}&to=${to_lang}&text=${encodeURIComponent(text)}`; | ||
response = await fetch(url); | ||
result = await response.json(); | ||
|
||
if (response.status !== 200) { | ||
throw `Terjadi kesalahan saat melakukan request: ${response.statusText}`; | ||
let lang = args[0] | ||
let text = args.slice(1).join(' ') | ||
if ((args[0] || '').length !== 2) { | ||
lang = defaultLang | ||
text = args.join(' ') | ||
} | ||
} | ||
if (!text && m.quoted && m.quoted.text) text = m.quoted.text | ||
|
||
let { "code/status": status, credits, from, text: original_text, to, translated_text } = result; | ||
m.reply(`*Terdeteksi Bahasa:* ${from}\n*Ke Bahasa:* ${to}\n\n*Original Text:* ${original_text}\n*Terjemahan:* ${translated_text}\n\n*Kredit:* ${credits}`); | ||
}; | ||
try { | ||
let result = await translate(text, { to: lang, autoCorrect: true }).catch(_ => null) | ||
m.reply(result.text) | ||
} catch (e) { | ||
throw err | ||
} | ||
|
||
handler.help = ['translate'].map(v => v + ' <from_lang>|<to_lang> <teks>'); | ||
handler.tags = ['tools']; | ||
handler.command = /^(translate|tr|terjemahan|terjemah|trjmh)$/i; | ||
} | ||
handler.help = ['translate <lang> <text>'] | ||
handler.tags = ['tools'] | ||
handler.command = ['translate', 'tl', 'trad', 'tr'] | ||
|
||
export default handler; | ||
export default handler |