Fixed catfact thanks to twindragon, closes #1547
This commit is contained in:
parent
1af4679d9e
commit
3de9a40ffd
@ -41,8 +41,7 @@ namespace NadekoBot.Modules.Searches
|
||||
return;
|
||||
|
||||
string response;
|
||||
using (var http = new HttpClient())
|
||||
response = await http.GetStringAsync($"http://api.openweathermap.org/data/2.5/weather?q={query}&appid=42cd627dd60debf25a5739e50a217d74&units=metric").ConfigureAwait(false);
|
||||
response = await _service.Http.GetStringAsync($"http://api.openweathermap.org/data/2.5/weather?q={query}&appid=42cd627dd60debf25a5739e50a217d74&units=metric").ConfigureAwait(false);
|
||||
|
||||
var data = JsonConvert.DeserializeObject<WeatherData>(response);
|
||||
|
||||
@ -67,19 +66,17 @@ namespace NadekoBot.Modules.Searches
|
||||
if (string.IsNullOrWhiteSpace(arg) || string.IsNullOrWhiteSpace(_creds.GoogleApiKey))
|
||||
return;
|
||||
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var res = await http.GetStringAsync($"https://maps.googleapis.com/maps/api/geocode/json?address={arg}&key={_creds.GoogleApiKey}").ConfigureAwait(false);
|
||||
var res = await _service.Http.GetStringAsync($"https://maps.googleapis.com/maps/api/geocode/json?address={arg}&key={_creds.GoogleApiKey}").ConfigureAwait(false);
|
||||
var obj = JsonConvert.DeserializeObject<GeolocationResult>(res);
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@ -114,22 +111,16 @@ namespace NadekoBot.Modules.Searches
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task RandomCat()
|
||||
{
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var res = JObject.Parse(await http.GetStringAsync("http://www.random.cat/meow").ConfigureAwait(false));
|
||||
var res = JObject.Parse(await _service.Http.GetStringAsync("http://www.random.cat/meow").ConfigureAwait(false));
|
||||
await Context.Channel.SendMessageAsync(Uri.EscapeUriString(res["file"].ToString())).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task RandomDog()
|
||||
{
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
await Context.Channel.SendMessageAsync("http://random.dog/" + await http.GetStringAsync("http://random.dog/woof")
|
||||
await Context.Channel.SendMessageAsync("http://random.dog/" + await _service.Http.GetStringAsync("http://random.dog/woof")
|
||||
.ConfigureAwait(false)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Image([Remainder] string terms = null)
|
||||
@ -503,9 +494,7 @@ namespace NadekoBot.Modules.Searches
|
||||
if (string.IsNullOrWhiteSpace(word))
|
||||
return;
|
||||
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var res = await http.GetStringAsync("http://api.pearson.com/v2/dictionaries/entries?headword=" + WebUtility.UrlEncode(word.Trim())).ConfigureAwait(false);
|
||||
var res = await _service.Http.GetStringAsync("http://api.pearson.com/v2/dictionaries/entries?headword=" + WebUtility.UrlEncode(word.Trim())).ConfigureAwait(false);
|
||||
|
||||
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));
|
||||
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@ -577,16 +566,13 @@ namespace NadekoBot.Modules.Searches
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Catfact()
|
||||
{
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var response = await http.GetStringAsync("http://catfacts-api.appspot.com/api/facts").ConfigureAwait(false);
|
||||
var response = await _service.Http.GetStringAsync("https://catfact.ninja/fact").ConfigureAwait(false);
|
||||
if (response == null)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
Loading…
Reference in New Issue
Block a user