tardis-bot/modules/mangle/index.js

29 lines
707 B
JavaScript
Raw Normal View History

2021-05-15 20:43:09 +00:00
const gtranslate = require('node-google-translate-skidz');
module.exports = function (bot, api) {
api.registerCommand('mangle', async (args, message) => {
let str = message.content.slice(8).trim();
let langs = process.env.MANGLE_LANGS.split(',');
let lang;
let i = 0;
for (let lang of langs) {
if (i >= langs.length - 1) break;
let translationResult = await translate(str, lang, langs[i + 1]);
str = translationResult.translation;
i++;
}
api.respond(message, str);
});
}
async function translate(text, fromLang, toLang) {
return new Promise((resolve, reject) => {
gtranslate({
text: text,
source: fromLang,
target: toLang
}, (res) => {
resolve(res);
})
})
}