JaBa/commands/General/translate.js

68 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js"),
translate = require("@k3rn31p4nic/google-translate-api");
const langs = ["afrikaans", "albanian", "amharic", "arabic", "armenian", "azerbaijani", "bangla", "basque", "belarusian", "bengali", "bosnian", "bulgarian", "burmese", "catalan", "cebuano", "chichewa", "corsican", "croatian", "czech", "danish", "dutch", "english", "esperanto", "estonian", "filipino", "finnish", "french", "frisian", "galician", "georgian", "german", "greek", "gujarati", "haitian creole", "hausa", "hawaiian", "hebrew", "hindi", "hmong", "hungarian", "icelandic", "igbo", "indonesian", "irish", "italian", "japanese", "javanese", "kannada", "kazakh", "khmer", "korean", "kurdish (kurmanji)", "kyrgyz", "lao", "latin", "latvian", "lithuanian", "luxembourgish", "macedonian", "malagasy", "malay", "malayalam", "maltese", "maori", "marathi", "mongolian", "myanmar (burmese)", "nepali", "norwegian", "nyanja", "pashto", "persian", "polish", "portugese", "punjabi", "romanian", "russian", "samoan", "scottish gaelic", "serbian", "sesotho", "shona", "sindhi", "sinhala", "slovak", "slovenian", "somali", "spanish", "sundanese", "swahili", "swedish", "tajik", "tamil", "telugu", "thai", "turkish", "ukrainian", "urdu", "uzbek", "vietnamese", "welsh", "xhosa", "yiddish", "yoruba", "zulu"];
class Translate extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "translate",
dirname: __dirname,
enabled: true,
guildOnly: false,
2021-12-26 19:29:37 +05:00
aliases: ["traduction", "translation", "trad"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 5000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-11 01:11:50 +05:00
if (args[0] === "langs-list") {
2021-12-26 00:56:47 +05:00
const langsList = "```css\n" + (langs.map((lang, i) => `${i + 1} - ${lang}`).join("\n")) + "```";
2021-12-10 21:39:54 +05:00
message.author.send(langsList).then(() => {
message.success("general/translate:LIST_SENT");
}).catch(() => {
message.error("misc:CANNOT_DM");
});
return;
2021-12-11 01:11:50 +05:00
};
2021-12-26 19:29:37 +05:00
const pWait = await message.sendT("misc:PLEASE_WAIT", null, {
prefixEmoji: "loading"
});
2021-12-11 01:11:50 +05:00
if (!args[0]) return pWait.error("general/translate:MISSING_LANGUAGE", { prefix: data.guild.prefix }, { edit: true });
if (!args[1]) return pWait.error("general/translate:MISSING_CONTENT", null, { edit: true });
2021-12-10 21:39:54 +05:00
// Gets different args
const language = args[0].toLowerCase();
const toTranslate = args.slice(1).join(" ");
2021-12-11 01:11:50 +05:00
2021-12-26 19:29:37 +05:00
if (!langs.includes(language)) return pWait.error("general/translate:INVALID_LANGUAGE", { prefix: data.guild.prefix, search: language }, { edit: true });
2021-12-11 01:11:50 +05:00
2021-12-26 19:29:37 +05:00
const translated = await translate(toTranslate, {
to: language
});
2021-12-10 21:39:54 +05:00
const resEmbed = new Discord.MessageEmbed()
2021-12-26 19:29:37 +05:00
.setAuthor("Translator", this.client.user.displayAvatarURL({
size: 512,
dynamic: true,
format: "png"
}))
2021-12-24 20:52:27 +05:00
.addField(translated.from.language.iso, "```" + toTranslate + "```")
.addField(language, "```" + translated.text + "```")
2021-12-10 21:39:54 +05:00
.setColor(data.config.embed.color)
.setFooter(data.config.embed.footer);
2021-12-26 19:29:37 +05:00
return pWait.edit("", {
embed: resEmbed
});
2021-12-10 21:39:54 +05:00
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
module.exports = Translate;