Fixed catfact thanks to twindragon, closes #1547
This commit is contained in:
		| @@ -41,8 +41,7 @@ namespace NadekoBot.Modules.Searches | |||||||
|                 return; |                 return; | ||||||
|  |  | ||||||
|             string response; |             string response; | ||||||
|             using (var http = new HttpClient()) |             response = await _service.Http.GetStringAsync($"http://api.openweathermap.org/data/2.5/weather?q={query}&appid=42cd627dd60debf25a5739e50a217d74&units=metric").ConfigureAwait(false); | ||||||
|                 response = await http.GetStringAsync($"http://api.openweathermap.org/data/2.5/weather?q={query}&appid=42cd627dd60debf25a5739e50a217d74&units=metric").ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|             var data = JsonConvert.DeserializeObject<WeatherData>(response); |             var data = JsonConvert.DeserializeObject<WeatherData>(response); | ||||||
|  |  | ||||||
| @@ -67,19 +66,17 @@ namespace NadekoBot.Modules.Searches | |||||||
|             if (string.IsNullOrWhiteSpace(arg) || string.IsNullOrWhiteSpace(_creds.GoogleApiKey)) |             if (string.IsNullOrWhiteSpace(arg) || string.IsNullOrWhiteSpace(_creds.GoogleApiKey)) | ||||||
|                 return; |                 return; | ||||||
|  |  | ||||||
|             using (var http = new HttpClient()) |             var res = await _service.Http.GetStringAsync($"https://maps.googleapis.com/maps/api/geocode/json?address={arg}&key={_creds.GoogleApiKey}").ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var res = await http.GetStringAsync($"https://maps.googleapis.com/maps/api/geocode/json?address={arg}&key={_creds.GoogleApiKey}").ConfigureAwait(false); |  | ||||||
|             var obj = JsonConvert.DeserializeObject<GeolocationResult>(res); |             var obj = JsonConvert.DeserializeObject<GeolocationResult>(res); | ||||||
|  |  | ||||||
|             var currentSeconds = DateTime.UtcNow.UnixTimestamp(); |             var currentSeconds = DateTime.UtcNow.UnixTimestamp(); | ||||||
|                 var timeRes = await http.GetStringAsync($"https://maps.googleapis.com/maps/api/timezone/json?location={obj.results[0].Geometry.Location.Lat},{obj.results[0].Geometry.Location.Lng}×tamp={currentSeconds}&key={_creds.GoogleApiKey}").ConfigureAwait(false); |             var timeRes = await _service.Http.GetStringAsync($"https://maps.googleapis.com/maps/api/timezone/json?location={obj.results[0].Geometry.Location.Lat},{obj.results[0].Geometry.Location.Lng}×tamp={currentSeconds}&key={_creds.GoogleApiKey}").ConfigureAwait(false); | ||||||
|             var timeObj = JsonConvert.DeserializeObject<TimeZoneResult>(timeRes); |             var timeObj = JsonConvert.DeserializeObject<TimeZoneResult>(timeRes); | ||||||
|  |  | ||||||
|             var time = DateTime.UtcNow.AddSeconds(timeObj.DstOffset + timeObj.RawOffset); |             var time = DateTime.UtcNow.AddSeconds(timeObj.DstOffset + timeObj.RawOffset); | ||||||
|  |  | ||||||
|             await ReplyConfirmLocalized("time", Format.Bold(obj.results[0].FormattedAddress), Format.Code(time.ToString("HH:mm")), timeObj.TimeZoneName).ConfigureAwait(false); |             await ReplyConfirmLocalized("time", Format.Bold(obj.results[0].FormattedAddress), Format.Code(time.ToString("HH:mm")), timeObj.TimeZoneName).ConfigureAwait(false); | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         [NadekoCommand, Usage, Description, Aliases] |         [NadekoCommand, Usage, Description, Aliases] | ||||||
| @@ -114,22 +111,16 @@ namespace NadekoBot.Modules.Searches | |||||||
|         [NadekoCommand, Usage, Description, Aliases] |         [NadekoCommand, Usage, Description, Aliases] | ||||||
|         public async Task RandomCat() |         public async Task RandomCat() | ||||||
|         { |         { | ||||||
|             using (var http = new HttpClient()) |             var res = JObject.Parse(await _service.Http.GetStringAsync("http://www.random.cat/meow").ConfigureAwait(false)); | ||||||
|             { |  | ||||||
|                 var res = JObject.Parse(await http.GetStringAsync("http://www.random.cat/meow").ConfigureAwait(false)); |  | ||||||
|             await Context.Channel.SendMessageAsync(Uri.EscapeUriString(res["file"].ToString())).ConfigureAwait(false); |             await Context.Channel.SendMessageAsync(Uri.EscapeUriString(res["file"].ToString())).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|  |  | ||||||
|         [NadekoCommand, Usage, Description, Aliases] |         [NadekoCommand, Usage, Description, Aliases] | ||||||
|         public async Task RandomDog() |         public async Task RandomDog() | ||||||
|         { |         { | ||||||
|             using (var http = new HttpClient()) |             await Context.Channel.SendMessageAsync("http://random.dog/" + await _service.Http.GetStringAsync("http://random.dog/woof") | ||||||
|             { |  | ||||||
|                 await Context.Channel.SendMessageAsync("http://random.dog/" + await http.GetStringAsync("http://random.dog/woof") |  | ||||||
|                             .ConfigureAwait(false)).ConfigureAwait(false); |                             .ConfigureAwait(false)).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|  |  | ||||||
|         [NadekoCommand, Usage, Description, Aliases] |         [NadekoCommand, Usage, Description, Aliases] | ||||||
|         public async Task Image([Remainder] string terms = null) |         public async Task Image([Remainder] string terms = null) | ||||||
| @@ -503,9 +494,7 @@ namespace NadekoBot.Modules.Searches | |||||||
|             if (string.IsNullOrWhiteSpace(word)) |             if (string.IsNullOrWhiteSpace(word)) | ||||||
|                 return; |                 return; | ||||||
|  |  | ||||||
|             using (var http = new HttpClient()) |             var res = await _service.Http.GetStringAsync("http://api.pearson.com/v2/dictionaries/entries?headword=" + WebUtility.UrlEncode(word.Trim())).ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var res = await http.GetStringAsync("http://api.pearson.com/v2/dictionaries/entries?headword=" + WebUtility.UrlEncode(word.Trim())).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|             var data = JsonConvert.DeserializeObject<DefineModel>(res); |             var data = JsonConvert.DeserializeObject<DefineModel>(res); | ||||||
|  |  | ||||||
| @@ -530,7 +519,7 @@ namespace NadekoBot.Modules.Searches | |||||||
|                 embed.AddField(efb => efb.WithName(GetText("example")).WithValue(sense.Examples.First().text)); |                 embed.AddField(efb => efb.WithName(GetText("example")).WithValue(sense.Examples.First().text)); | ||||||
|  |  | ||||||
|             await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); |             await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         [NadekoCommand, Usage, Description, Aliases] |         [NadekoCommand, Usage, Description, Aliases] | ||||||
| @@ -577,16 +566,13 @@ namespace NadekoBot.Modules.Searches | |||||||
|         [NadekoCommand, Usage, Description, Aliases] |         [NadekoCommand, Usage, Description, Aliases] | ||||||
|         public async Task Catfact() |         public async Task Catfact() | ||||||
|         { |         { | ||||||
|             using (var http = new HttpClient()) |             var response = await _service.Http.GetStringAsync("https://catfact.ninja/fact").ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var response = await http.GetStringAsync("http://catfacts-api.appspot.com/api/facts").ConfigureAwait(false); |  | ||||||
|             if (response == null) |             if (response == null) | ||||||
|                 return; |                 return; | ||||||
|  |  | ||||||
|                 var fact = JObject.Parse(response)["facts"][0].ToString(); |             var fact = JObject.Parse(response)["fact"].ToString(); | ||||||
|             await Context.Channel.SendConfirmAsync("🐈" + GetText("catfact"), fact).ConfigureAwait(false); |             await Context.Channel.SendConfirmAsync("🐈" + GetText("catfact"), fact).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|  |  | ||||||
|         [NadekoCommand, Usage, Description, Aliases] |         [NadekoCommand, Usage, Description, Aliases] | ||||||
|         [RequireContext(ContextType.Guild)] |         [RequireContext(ContextType.Guild)] | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user