From 7c00b9fe868dbb89428d0ab4368fb7a779c1b779 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 25 Feb 2017 04:02:11 +0100 Subject: [PATCH] ~trans now properly throws an error if language is invalid --- .../Modules/Searches/Commands/GoogleTranslator.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/GoogleTranslator.cs b/src/NadekoBot/Modules/Searches/Commands/GoogleTranslator.cs index 5604fdd1..9cd0645c 100644 --- a/src/NadekoBot/Modules/Searches/Commands/GoogleTranslator.cs +++ b/src/NadekoBot/Modules/Searches/Commands/GoogleTranslator.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using System; +using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Linq; using System.Net; @@ -155,6 +156,11 @@ namespace NadekoBot.Modules.Searches { string text; + if(!_languageDictionary.ContainsKey(sourceLanguage) || + !_languageDictionary.ContainsKey(targetLanguage)) + throw new ArgumentException(); + + var url = string.Format("https://translate.googleapis.com/translate_a/single?client=gtx&sl={0}&tl={1}&dt=t&q={2}", ConvertToLanguageCode(sourceLanguage), ConvertToLanguageCode(targetLanguage),