From 5e686f222f51c6b40035ed5ccb268f0cb7d0bff4 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 6 Nov 2017 13:58:33 +0000 Subject: [PATCH] Google Translate, remove some aliases --- assets/json/translate.json | 110 +++++++----------- .../history.js => events/today-in-history.js} | 10 +- commands/other/shorten-url.js | 2 +- commands/search/dictionary.js | 2 +- commands/search/jisho.js | 2 +- commands/search/thesaurus.js | 2 +- commands/search/urban-dictionary.js | 2 +- commands/text-edit/translate.js | 33 +++--- package.json | 2 +- 9 files changed, 69 insertions(+), 96 deletions(-) rename commands/{random-res/history.js => events/today-in-history.js} (87%) diff --git a/assets/json/translate.json b/assets/json/translate.json index 8cedc0da..ed02209e 100644 --- a/assets/json/translate.json +++ b/assets/json/translate.json @@ -1,95 +1,67 @@ { - "az": "Azerbaijan", - "sq": "Albanian", - "am": "Amharic", - "en": "English", - "ar": "Arabic", - "hy": "Armenian", + "auto": "Automatic", "af": "Afrikaans", + "sq": "Albanian", + "ar": "Arabic", + "az": "Azerbaijani", "eu": "Basque", - "ba": "Bashkir", - "be": "Belarusian", "bn": "Bengali", - "my": "Burmese", + "be": "Belarusian", "bg": "Bulgarian", - "bs": "Bosnian", - "cy": "Welsh", - "hu": "Hungarian", - "vi": "Vietnamese", - "ht": "Haitian (Creole)", - "gl": "Galician", - "nl": "Dutch", - "mrj": "Hill Mari", - "el": "Greek", - "ka": "Georgian", - "gu": "Gujarati", + "ca": "Catalan", + "zh-cn": "Chinese Simplified", + "zh-tw": "Chinese Traditional", + "hr": "Croatian", + "cs": "Czech", "da": "Danish", - "he": "Hebrew", - "yi": "Yiddish", + "nl": "Dutch", + "en": "English", + "eo": "Esperanto", + "et": "Estonian", + "tl": "Filipino", + "fi": "Finnish", + "fr": "French", + "gl": "Galician", + "ka": "Georgian", + "de": "German", + "el": "Greek", + "gu": "Gujarati", + "ht": "Haitian Creole", + "iw": "Hebrew", + "hi": "Hindi", + "hu": "Hungarian", + "is": "Icelandic", "id": "Indonesian", "ga": "Irish", "it": "Italian", - "is": "Icelandic", - "es": "Spanish", - "kk": "Kazakh", + "ja": "Japanese", "kn": "Kannada", - "ca": "Catalan", - "ky": "Kyrgyz", - "zh": "Chinese", "ko": "Korean", - "xh": "Xhosa", - "km": "Khmer", - "lo": "Laotian", "la": "Latin", "lv": "Latvian", "lt": "Lithuanian", - "lb": "Luxembourgish", - "mg": "Malagasy", - "ms": "Malay", - "ml": "Malayalam", - "mt": "Maltese", "mk": "Macedonian", - "mi": "Maori", - "mr": "Marathi", - "mhr": "Mari", - "mn": "Mongolian", - "de": "German", - "ne": "Nepali", + "ms": "Malay", + "mt": "Maltese", "no": "Norwegian", - "pa": "Punjabi", - "pap": "Papiamento", "fa": "Persian", "pl": "Polish", "pt": "Portuguese", "ro": "Romanian", "ru": "Russian", - "ceb": "Cebuano", "sr": "Serbian", - "si": "Sinhala", - "sk": "Slovakian", + "sk": "Slovak", "sl": "Slovenian", + "es": "Spanish", "sw": "Swahili", - "su": "Sundanese", - "tg": "Tajik", - "th": "Thai", - "tl": "Tagalog", - "ta": "Tamil", - "tt": "Tatar", - "te": "Telugu", - "tr": "Turkish", - "udm": "Udmurt", - "uz": "Uzbek", - "uk": "Ukranian", - "ur": "Urdu", - "fi": "Finnish", - "fr": "French", - "hi": "Hindi", - "hr": "Croatian", - "cs": "Czech", "sv": "Swedish", - "gd": "Scottish", - "et": "Estonian", - "eo": "Esperanto", - "jv": "Javanese", - "ja": "Japanese" + "ta": "Tamil", + "te": "Telugu", + "th": "Thai", + "tr": "Turkish", + "uk": "Ukrainian", + "ur": "Urdu", + "vi": "Vietnamese", + "cy": "Welsh", + "yi": "Yiddish" } diff --git a/commands/random-res/history.js b/commands/events/today-in-history.js similarity index 87% rename from commands/random-res/history.js rename to commands/events/today-in-history.js index 460646c1..b1a61d9e 100644 --- a/commands/random-res/history.js +++ b/commands/events/today-in-history.js @@ -2,13 +2,13 @@ const { Command } = require('discord.js-commando'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); -module.exports = class HistoryCommand extends Command { +module.exports = class TodayInHistoryCommand extends Command { constructor(client) { super(client, { - name: 'history', - aliases: ['event', 'today', 'today-in-history'], - group: 'random-res', - memberName: 'history', + name: 'today-in-history', + aliases: ['event', 'today', 'history'], + group: 'events', + memberName: 'today-in-history', description: 'Responds with an event that occurred today in history, or on a specific day.', clientPermissions: ['EMBED_LINKS'], args: [ diff --git a/commands/other/shorten-url.js b/commands/other/shorten-url.js index e5073936..ca1e61be 100644 --- a/commands/other/shorten-url.js +++ b/commands/other/shorten-url.js @@ -6,7 +6,7 @@ module.exports = class ShortenURLCommand extends Command { constructor(client) { super(client, { name: 'shorten-url', - aliases: ['short-url', 'url-shorten', 'url-short'], + aliases: ['short-url', 'url-shorten'], group: 'other', memberName: 'shorten-url', description: 'Creates a goo.gl short URL from another URL.', diff --git a/commands/search/dictionary.js b/commands/search/dictionary.js index f567500e..5c67c282 100644 --- a/commands/search/dictionary.js +++ b/commands/search/dictionary.js @@ -7,7 +7,7 @@ module.exports = class DictionaryCommand extends Command { constructor(client) { super(client, { name: 'dictionary', - aliases: ['define', 'wordnik', 'define-wordnik', 'wordnik-define'], + aliases: ['define', 'wordnik', 'define-wordnik', 'wordnik-define', 'wordnik-dictionary'], group: 'search', memberName: 'dictionary', description: 'Defines a word.', diff --git a/commands/search/jisho.js b/commands/search/jisho.js index 92c1cf10..93ca645d 100644 --- a/commands/search/jisho.js +++ b/commands/search/jisho.js @@ -6,7 +6,7 @@ module.exports = class JishoCommand extends Command { constructor(client) { super(client, { name: 'jisho', - aliases: ['japanese-dictionary', 'define-japanese', 'define-jpn', 'jpn-define', 'japanese-define'], + aliases: ['japanese-dictionary', 'define-japanese', 'define-jpn'], group: 'search', memberName: 'jisho', description: 'Defines a word, but with Japanese.', diff --git a/commands/search/thesaurus.js b/commands/search/thesaurus.js index 2ab5441c..9f857871 100644 --- a/commands/search/thesaurus.js +++ b/commands/search/thesaurus.js @@ -7,7 +7,7 @@ module.exports = class ThesaurusCommand extends Command { constructor(client) { super(client, { name: 'thesaurus', - aliases: ['synonym', 'antonym', 'thesaurus-wordnik', 'wordnik-thesaurus'], + aliases: ['synonym', 'antonym', 'wordnik-thesaurus'], group: 'search', memberName: 'thesaurus', description: 'Gets the synonyms and antonyms of a word.', diff --git a/commands/search/urban-dictionary.js b/commands/search/urban-dictionary.js index 51569c11..73cc430a 100644 --- a/commands/search/urban-dictionary.js +++ b/commands/search/urban-dictionary.js @@ -7,7 +7,7 @@ module.exports = class UrbanDictionaryCommand extends Command { constructor(client) { super(client, { name: 'urban-dictionary', - aliases: ['urban', 'urban-define', 'define-urban'], + aliases: ['urban', 'define-urban'], group: 'search', memberName: 'urban-dictionary', description: 'Searches Urban Dictionary for your query.', diff --git a/commands/text-edit/translate.js b/commands/text-edit/translate.js index e49f9017..21312abc 100644 --- a/commands/text-edit/translate.js +++ b/commands/text-edit/translate.js @@ -3,13 +3,12 @@ const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { list } = require('../../util/Util'); const codes = require('../../assets/json/translate'); -const { YANDEX_KEY } = process.env; module.exports = class TranslateCommand extends Command { constructor(client) { super(client, { name: 'translate', - aliases: ['yandex', 'yandex-translate', 'translate-yandex'], + aliases: ['google-translate'], group: 'text-edit', memberName: 'translate', description: 'Translates text to a specified language.', @@ -17,7 +16,8 @@ module.exports = class TranslateCommand extends Command { clientPermissions: ['EMBED_LINKS'], args: [ { - key: 'text', + key: 'content', + label: 'text', prompt: 'What text would you like to translate?', type: 'string', max: 500 @@ -41,7 +41,7 @@ module.exports = class TranslateCommand extends Command { key: 'base', prompt: `Which language would you like to use as the base? Either ${list(Object.keys(codes), 'or')}.`, type: 'string', - default: '', + default: 'auto', validate: base => { const value = base.toLowerCase(); if (codes[value] || Object.keys(codes).find(key => codes[key].toLowerCase() === value)) return true; @@ -57,23 +57,24 @@ module.exports = class TranslateCommand extends Command { }); } - async run(msg, { text, target, base }) { + async run(msg, { content, target, base }) { try { - const { body } = await snekfetch - .get('https://translate.yandex.net/api/v1.5/tr.json/translate') + const { text } = await snekfetch + .get('https://translate.googleapis.com/translate_a/single') .query({ - key: YANDEX_KEY, - text, - lang: base ? `${base}-${target}` : target + client: 'gtx', + sl: base, + tl: target, + dt: 't', + q: content }); - const lang = body.lang.split('-'); + const body = JSON.parse(text); const embed = new MessageEmbed() - .setColor(0xFF0000) - .setFooter('Powered by Yandex.Translate', 'https://i.imgur.com/HMpH9sq.png') - .addField(`❯ From: ${codes[lang[0]]}`, + .setColor(0x3174F1) + .addField(`❯ From: ${codes[body[2]]}`, text) - .addField(`❯ To: ${codes[lang[1]]}`, - body.text[0]); + .addField(`❯ To: ${codes[target]}`, + body[0][0][0]); return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/package.json b/package.json index 24571ef4..ac4486b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "51.6.2", + "version": "52.0.0", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": {